1 // Copyright (C) 2020-2025 Free Software Foundation, Inc.
3 // This file is part of GCC.
5 // GCC is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation; either version 3, or (at your option) any later
10 // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 // You should have received a copy of the GNU General Public License
16 // along with GCC; see the file COPYING3. If not see
17 // <http://www.gnu.org/licenses/>.
19 #include "rust-tree.h"
20 #include "fold-const.h"
21 #include "stringpool.h"
23 #include "escaped_string.h"
24 #include "libiberty.h"
25 #include "stor-layout.h"
27 #include "diagnostic.h"
30 #include "gimple-expr.h"
33 #include "gcc-rich-location.h"
35 #include "file-prefix-map.h"
41 // forked from gcc/c-family/c-common.cc c_global_trees
42 tree c_global_trees
[CTI_MAX
];
43 // forked from gcc/cp/decl.cc cp_global_trees
44 tree cp_global_trees
[CPTI_MAX
];
46 struct saved_scope
*scope_chain
;
51 mark_exp_read (tree exp
)
54 ASM_GENERATE_INTERNAL_LABEL (tmp_name
, "Lsrc_loc", 1);
59 switch (TREE_CODE (exp
))
64 DECL_READ_P (exp
) = 1;
75 case VIEW_CONVERT_EXPR
:
76 mark_exp_read (TREE_OPERAND (exp
, 0));
79 mark_exp_read (TREE_OPERAND (exp
, 1));
82 if (TREE_OPERAND (exp
, 1))
83 mark_exp_read (TREE_OPERAND (exp
, 1));
84 if (TREE_OPERAND (exp
, 2))
85 mark_exp_read (TREE_OPERAND (exp
, 2));
93 convert_from_reference (tree val
)
95 if (TREE_TYPE (val
) && TYPE_REF_P (TREE_TYPE (val
)))
97 tree t
= TREE_TYPE (TREE_TYPE (val
));
98 tree ref
= build1 (INDIRECT_REF
, t
, val
);
102 TREE_SIDE_EFFECTS (ref
)
103 = (TREE_THIS_VOLATILE (ref
) || TREE_SIDE_EFFECTS (val
));
111 mark_use (tree expr
, bool rvalue_p
, bool read_p
,
112 location_t loc
/* = UNKNOWN_LOCATION */,
113 bool reject_builtin
/* = true */)
115 #define RECUR(t) mark_use ((t), rvalue_p, read_p, loc, reject_builtin)
117 if (expr
== NULL_TREE
|| error_operand_p (expr
))
121 return error_mark_node
;
124 mark_exp_read (expr
);
126 bool recurse_op
[3] = {false, false, false};
127 switch (TREE_CODE (expr
))
130 recurse_op
[0] = true;
133 recurse_op
[1] = true;
136 recurse_op
[2] = true;
137 if (TREE_OPERAND (expr
, 1))
138 recurse_op
[1] = true;
141 if (REFERENCE_REF_P (expr
))
143 /* Try to look through the reference. */
144 tree ref
= TREE_OPERAND (expr
, 0);
145 tree r
= mark_rvalue_use (ref
, loc
, reject_builtin
);
147 expr
= convert_from_reference (r
);
151 case VIEW_CONVERT_EXPR
:
152 if (location_wrapper_p (expr
))
154 loc
= EXPR_LOCATION (expr
);
155 tree op
= TREE_OPERAND (expr
, 0);
156 tree nop
= RECUR (op
);
157 if (nop
== error_mark_node
)
158 return error_mark_node
;
161 else if (DECL_P (nop
) || CONSTANT_CLASS_P (nop
))
163 /* Reuse the location wrapper. */
164 TREE_OPERAND (expr
, 0) = nop
;
165 /* If we're replacing a DECL with a constant, we also need to
166 change the TREE_CODE of the location wrapper. */
168 TREE_SET_CODE (expr
, NON_LVALUE_EXPR
);
172 /* Drop the location wrapper. */
174 protected_set_expr_location (expr
, loc
);
180 recurse_op
[0] = true;
187 for (int i
= 0; i
< 3; ++i
)
190 tree op
= TREE_OPERAND (expr
, i
);
192 if (op
== error_mark_node
)
193 return error_mark_node
;
194 TREE_OPERAND (expr
, i
) = op
;
202 mark_rvalue_use (tree e
, location_t loc
/* = UNKNOWN_LOCATION */,
203 bool reject_builtin
/* = true */)
205 return mark_use (e
, true, true, loc
, reject_builtin
);
209 mark_lvalue_use (tree expr
)
211 return mark_use (expr
, false, true, input_location
, false);
215 mark_lvalue_use_nonread (tree expr
)
217 return mark_use (expr
, false, false, input_location
, false);
221 mark_discarded_use (tree expr
)
223 if (expr
== NULL_TREE
)
226 STRIP_ANY_LOCATION_WRAPPER (expr
);
228 switch (TREE_CODE (expr
))
231 TREE_OPERAND (expr
, 2) = mark_discarded_use (TREE_OPERAND (expr
, 2));
234 TREE_OPERAND (expr
, 1) = mark_discarded_use (TREE_OPERAND (expr
, 1));
249 return mark_use (expr
, true, true, input_location
, false);
253 convert_to_void (tree expr
, impl_conv_void implicit
)
255 location_t loc
= expr_loc_or_input_loc (expr
);
256 if (expr
== error_mark_node
|| TREE_TYPE (expr
) == error_mark_node
)
257 return error_mark_node
;
259 expr
= mark_discarded_use (expr
);
260 if (implicit
== ICV_CAST
)
261 /* An explicit cast to void avoids all -Wunused-but-set* warnings. */
262 mark_exp_read (expr
);
264 if (!TREE_TYPE (expr
))
267 if (VOID_TYPE_P (TREE_TYPE (expr
)))
269 switch (TREE_CODE (expr
))
272 /* The two parts of a cond expr might be separate lvalues. */
273 tree op1
= TREE_OPERAND (expr
, 1);
274 tree op2
= TREE_OPERAND (expr
, 2);
276 = ((op1
&& TREE_SIDE_EFFECTS (op1
)) || TREE_SIDE_EFFECTS (op2
));
277 tree new_op1
, new_op2
;
279 if (implicit
!= ICV_CAST
&& !side_effects
)
282 new_op1
= convert_to_void (op1
, ICV_SECOND_OF_COND
);
283 new_op2
= convert_to_void (op2
, ICV_THIRD_OF_COND
);
288 new_op1
= convert_to_void (op1
, ICV_CAST
);
289 new_op2
= convert_to_void (op2
, ICV_CAST
);
292 expr
= build3_loc (loc
, COND_EXPR
, TREE_TYPE (new_op2
),
293 TREE_OPERAND (expr
, 0), new_op1
, new_op2
);
297 case COMPOUND_EXPR
: {
298 /* The second part of a compound expr contains the value. */
299 tree op1
= TREE_OPERAND (expr
, 1);
301 if (implicit
!= ICV_CAST
302 && !warning_suppressed_p (expr
/* What warning? */))
303 new_op1
= convert_to_void (op1
, ICV_RIGHT_OF_COMMA
);
305 new_op1
= convert_to_void (op1
, ICV_CAST
);
309 tree t
= build2_loc (loc
, COMPOUND_EXPR
, TREE_TYPE (new_op1
),
310 TREE_OPERAND (expr
, 0), new_op1
);
317 case NON_LVALUE_EXPR
:
319 /* These have already decayed to rvalue. */
323 maybe_warn_nodiscard (expr
, implicit
);
327 tree type
= TREE_TYPE (expr
);
328 int is_reference
= TYPE_REF_P (TREE_TYPE (TREE_OPERAND (expr
, 0)));
329 int is_volatile
= TYPE_VOLATILE (type
);
330 int is_complete
= COMPLETE_TYPE_P (type
);
332 /* Can't load the value if we don't know the type. */
333 if (is_volatile
&& !is_complete
)
339 "conversion to void will not access "
340 "object of incomplete type %qT",
343 case ICV_SECOND_OF_COND
:
345 "indirection will not access object of "
346 "incomplete type %qT in second operand "
347 "of conditional expression",
350 case ICV_THIRD_OF_COND
:
352 "indirection will not access object of "
353 "incomplete type %qT in third operand "
354 "of conditional expression",
357 case ICV_RIGHT_OF_COMMA
:
359 "indirection will not access object of "
360 "incomplete type %qT in right operand of "
364 case ICV_LEFT_OF_COMMA
:
366 "indirection will not access object of "
367 "incomplete type %qT in left operand of "
373 "indirection will not access object of "
374 "incomplete type %qT in statement",
377 case ICV_THIRD_IN_FOR
:
379 "indirection will not access object of "
380 "incomplete type %qT in for increment "
388 /* Don't load the value if this is an implicit dereference, or if
389 the type needs to be handled by ctors/dtors. */
390 else if (is_volatile
&& is_reference
)
396 "conversion to void will not access "
397 "object of type %qT",
400 case ICV_SECOND_OF_COND
:
402 "implicit dereference will not access "
403 "object of type %qT in second operand of "
404 "conditional expression",
407 case ICV_THIRD_OF_COND
:
409 "implicit dereference will not access "
410 "object of type %qT in third operand of "
411 "conditional expression",
414 case ICV_RIGHT_OF_COMMA
:
416 "implicit dereference will not access "
417 "object of type %qT in right operand of "
421 case ICV_LEFT_OF_COMMA
:
423 "implicit dereference will not access "
424 "object of type %qT in left operand of comma "
430 "implicit dereference will not access "
431 "object of type %qT in statement",
434 case ICV_THIRD_IN_FOR
:
436 "implicit dereference will not access "
437 "object of type %qT in for increment expression",
444 else if (is_volatile
&& TREE_ADDRESSABLE (type
))
450 "conversion to void will not access "
451 "object of non-trivially-copyable type %qT",
454 case ICV_SECOND_OF_COND
:
456 "indirection will not access object of "
457 "non-trivially-copyable type %qT in second "
458 "operand of conditional expression",
461 case ICV_THIRD_OF_COND
:
463 "indirection will not access object of "
464 "non-trivially-copyable type %qT in third "
465 "operand of conditional expression",
468 case ICV_RIGHT_OF_COMMA
:
470 "indirection will not access object of "
471 "non-trivially-copyable type %qT in right "
472 "operand of comma operator",
475 case ICV_LEFT_OF_COMMA
:
477 "indirection will not access object of "
478 "non-trivially-copyable type %qT in left "
479 "operand of comma operator",
484 "indirection will not access object of "
485 "non-trivially-copyable type %qT in statement",
488 case ICV_THIRD_IN_FOR
:
490 "indirection will not access object of "
491 "non-trivially-copyable type %qT in for "
492 "increment expression",
499 if (is_reference
|| !is_volatile
|| !is_complete
500 || TREE_ADDRESSABLE (type
))
502 /* Emit a warning (if enabled) when the "effect-less" INDIRECT_REF
503 operation is stripped off. Note that we don't warn about
504 - an expression with TREE_NO_WARNING set. (For an example of
505 such expressions, see build_over_call in call.cc.)
506 - automatic dereferencing of references, since the user cannot
507 control it. (See also warn_if_unused_value() in c-common.cc.)
509 if (warn_unused_value
&& implicit
!= ICV_CAST
510 && !warning_suppressed_p (expr
, OPT_Wunused_value
)
512 warning_at (loc
, OPT_Wunused_value
, "value computed is not used");
513 expr
= TREE_OPERAND (expr
, 0);
514 if (TREE_CODE (expr
) == CALL_EXPR
)
515 maybe_warn_nodiscard (expr
, implicit
);
522 /* External variables might be incomplete. */
523 tree type
= TREE_TYPE (expr
);
524 int is_complete
= COMPLETE_TYPE_P (type
);
526 if (TYPE_VOLATILE (type
) && !is_complete
)
531 "conversion to void will not access "
532 "object %qE of incomplete type %qT",
535 case ICV_SECOND_OF_COND
:
537 "variable %qE of incomplete type %qT will "
538 "not be accessed in second operand of "
539 "conditional expression",
542 case ICV_THIRD_OF_COND
:
544 "variable %qE of incomplete type %qT will "
545 "not be accessed in third operand of "
546 "conditional expression",
549 case ICV_RIGHT_OF_COMMA
:
551 "variable %qE of incomplete type %qT will "
552 "not be accessed in right operand of comma operator",
555 case ICV_LEFT_OF_COMMA
:
557 "variable %qE of incomplete type %qT will "
558 "not be accessed in left operand of comma operator",
563 "variable %qE of incomplete type %qT will "
564 "not be accessed in statement",
567 case ICV_THIRD_IN_FOR
:
569 "variable %qE of incomplete type %qT will "
570 "not be accessed in for increment expression",
583 if (!TREE_SIDE_EFFECTS (expr
))
590 maybe_warn_nodiscard (tree expr
, impl_conv_void implicit
)
593 if (TREE_CODE (expr
) == TARGET_EXPR
)
594 call
= TARGET_EXPR_INITIAL (expr
);
596 location_t loc
= expr_loc_or_input_loc (call
);
597 tree callee
= CALL_EXPR_FN (call
);
601 tree type
= TREE_TYPE (callee
);
602 if (INDIRECT_TYPE_P (type
))
603 type
= TREE_TYPE (type
);
605 tree rettype
= TREE_TYPE (type
);
606 tree fn
= get_fndecl_from_callee (callee
);
608 if (implicit
!= ICV_CAST
&& fn
609 && (attr
= lookup_attribute ("nodiscard", DECL_ATTRIBUTES (fn
))))
612 tree args
= TREE_VALUE (attr
);
614 msg
.escape (TREE_STRING_POINTER (TREE_VALUE (args
)));
616 = (msg
? G_ ("ignoring return value of %qD, that must be used: %qs")
617 : G_ ("ignoring return value of %qD, that must be used"));
618 const char *raw_msg
= msg
? (const char *) msg
: "";
619 auto_diagnostic_group d
;
620 if (warning_at (loc
, OPT_Wunused_result
, format
, fn
, raw_msg
))
621 inform (DECL_SOURCE_LOCATION (fn
), "declared here");
623 else if (implicit
!= ICV_CAST
625 = lookup_attribute ("nodiscard", TYPE_ATTRIBUTES (rettype
))))
628 tree args
= TREE_VALUE (attr
);
630 msg
.escape (TREE_STRING_POINTER (TREE_VALUE (args
)));
633 "ignoring returned value of type %qT, that must be used: %qs")
634 : G_ ("ignoring returned value of type %qT, that must be used"));
635 const char *raw_msg
= msg
? (const char *) msg
: "";
636 auto_diagnostic_group d
;
637 if (warning_at (loc
, OPT_Wunused_result
, format
, rettype
, raw_msg
))
640 inform (DECL_SOURCE_LOCATION (fn
), "in call to %qD, declared here",
642 inform (DECL_SOURCE_LOCATION (TYPE_NAME (rettype
)),
643 "%qT declared here", rettype
);
649 expr_loc_or_loc (const_tree t
, location_t or_loc
)
651 location_t loc
= EXPR_LOCATION (t
);
652 if (loc
== UNKNOWN_LOCATION
)
658 expr_loc_or_input_loc (const_tree t
)
660 return expr_loc_or_loc (t
, input_location
);
663 // FN is the callee of a CALL_EXPR or AGGR_INIT_EXPR; return the FUNCTION_DECL
666 get_fndecl_from_callee (tree fn
)
670 if (TREE_CODE (fn
) == FUNCTION_DECL
)
672 tree type
= TREE_TYPE (fn
);
673 if (type
== NULL_TREE
|| !INDIRECT_TYPE_P (type
))
677 if (TREE_CODE (fn
) == ADDR_EXPR
|| TREE_CODE (fn
) == FDESC_EXPR
)
678 fn
= TREE_OPERAND (fn
, 0);
679 if (TREE_CODE (fn
) == FUNCTION_DECL
)
685 pointer_offset_expression (tree base_tree
, tree index_tree
, location_t location
)
687 tree element_type_tree
= TREE_TYPE (TREE_TYPE (base_tree
));
688 if (base_tree
== error_mark_node
|| TREE_TYPE (base_tree
) == error_mark_node
689 || index_tree
== error_mark_node
|| element_type_tree
== error_mark_node
)
690 return error_mark_node
;
692 tree element_size
= TYPE_SIZE_UNIT (element_type_tree
);
693 index_tree
= fold_convert_loc (location
, sizetype
, index_tree
);
695 = fold_build2_loc (location
, MULT_EXPR
, sizetype
, index_tree
, element_size
);
697 return fold_build2_loc (location
, POINTER_PLUS_EXPR
, TREE_TYPE (base_tree
),
701 // forked from gcc/cp/tree.cc cp_walk_subtrees
702 /* Apply FUNC to all language-specific sub-trees of TP in a pre-order
703 traversal. Called from walk_tree. */
706 rs_walk_subtrees (tree
*tp
, int *walk_subtrees_p
, walk_tree_fn func
, void *data
,
707 hash_set
<tree
> *pset
)
709 enum tree_code code
= TREE_CODE (*tp
);
712 #define WALK_SUBTREE(NODE) \
715 result = rs_walk_tree (&(NODE), func, data, pset); \
723 /* If *WALK_SUBTREES_P is 1, we're interested in the syntactic form of
724 the argument, so don't look through typedefs, but do walk into
725 template arguments for alias templates (and non-typedefed classes).
727 If *WALK_SUBTREES_P > 1, we're interested in type identity or
728 equivalence, so look through typedefs, ignoring template arguments for
729 alias templates, and walk into template args of classes.
731 See find_abi_tags_r for an example of setting *WALK_SUBTREES_P to 2
732 when that's the behavior the walk_tree_fn wants. */
733 if (*walk_subtrees_p
== 1 && typedef_variant_p (*tp
))
735 *walk_subtrees_p
= 0;
740 /* Not one of the easy cases. We must explicitly go through the
746 WALK_SUBTREE (TREE_PURPOSE (*tp
));
750 if (TYPE_PTRMEMFUNC_P (*tp
))
751 WALK_SUBTREE (TYPE_PTRMEMFUNC_FN_TYPE_RAW (*tp
));
755 if (COMPOUND_LITERAL_P (*tp
))
756 WALK_SUBTREE (TREE_TYPE (*tp
));
760 /* User variables should be mentioned in BIND_EXPR_VARS
761 and their initializers and sizes walked when walking
762 the containing BIND_EXPR. Compiler temporaries are
763 handled here. And also normal variables in templates,
764 since do_poplevel doesn't build a BIND_EXPR then. */
765 if (VAR_P (TREE_OPERAND (*tp
, 0))
766 && (DECL_ARTIFICIAL (TREE_OPERAND (*tp
, 0))
767 && !TREE_STATIC (TREE_OPERAND (*tp
, 0))))
769 tree decl
= TREE_OPERAND (*tp
, 0);
770 WALK_SUBTREE (DECL_INITIAL (decl
));
771 WALK_SUBTREE (DECL_SIZE (decl
));
772 WALK_SUBTREE (DECL_SIZE_UNIT (decl
));
780 /* We didn't find what we were looking for. */
787 // forked from gcc/cp/tree.cc cp_expr_location
789 /* Like EXPR_LOCATION, but also handle some tcc_exceptional that have
793 rs_expr_location (const_tree t_
)
795 tree t
= CONST_CAST_TREE (t_
);
797 return UNKNOWN_LOCATION
;
799 return EXPR_LOCATION (t
);
802 // forked from gcc/cp/class.cc is_really_empty_class
804 /* Returns true if TYPE contains no actual data, just various
805 possible combinations of empty classes. If IGNORE_VPTR is true,
806 a vptr doesn't prevent the class from being considered empty. Typically
807 we want to ignore the vptr on assignment, and not on initialization. */
810 is_really_empty_class (tree type
, bool ignore_vptr
)
812 if (CLASS_TYPE_P (type
))
819 /* CLASSTYPE_EMPTY_P isn't set properly until the class is actually laid
820 out, but we'd like to be able to check this before then. */
821 if (COMPLETE_TYPE_P (type
) && is_empty_class (type
))
824 if (!ignore_vptr
&& TYPE_CONTAINS_VPTR_P (type
))
827 for (binfo
= TYPE_BINFO (type
), i
= 0;
828 BINFO_BASE_ITERATE (binfo
, i
, base_binfo
); ++i
)
829 if (!is_really_empty_class (BINFO_TYPE (base_binfo
), ignore_vptr
))
831 for (field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
832 if (TREE_CODE (field
) == FIELD_DECL
833 && !DECL_ARTIFICIAL (field
)
834 /* An unnamed bit-field is not a data member. */
835 && !DECL_UNNAMED_BIT_FIELD (field
)
836 && !is_really_empty_class (TREE_TYPE (field
), ignore_vptr
))
840 else if (TREE_CODE (type
) == ARRAY_TYPE
)
841 return (integer_zerop (array_type_nelts_top (type
))
842 || is_really_empty_class (TREE_TYPE (type
), ignore_vptr
));
846 // forked from gcc/cp/class.cc is_empty_class
848 /* Returns 1 if TYPE contains only padding bytes. */
851 is_empty_class (tree type
)
853 if (type
== error_mark_node
)
856 if (!CLASS_TYPE_P (type
))
859 return CLASSTYPE_EMPTY_P (type
);
862 // forked from gcc/cp/tree.cc builtin_valid_in_constant_expr_p
864 /* Test whether DECL is a builtin that may appear in a
865 constant-expression. */
868 builtin_valid_in_constant_expr_p (const_tree decl
)
870 STRIP_ANY_LOCATION_WRAPPER (decl
);
871 if (TREE_CODE (decl
) != FUNCTION_DECL
)
872 /* Not a function. */
874 if (DECL_BUILT_IN_CLASS (decl
) != BUILT_IN_NORMAL
)
876 if (fndecl_built_in_p (decl
, BUILT_IN_FRONTEND
))
877 switch (DECL_FE_FUNCTION_CODE (decl
))
879 case RS_BUILT_IN_IS_CONSTANT_EVALUATED
:
880 case RS_BUILT_IN_SOURCE_LOCATION
:
881 case RS_BUILT_IN_IS_CORRESPONDING_MEMBER
:
882 case RS_BUILT_IN_IS_POINTER_INTERCONVERTIBLE_WITH_CLASS
:
887 /* Not a built-in. */
890 switch (DECL_FUNCTION_CODE (decl
))
892 /* These always have constant results like the corresponding
895 case BUILT_IN_FUNCTION
:
898 /* The following built-ins are valid in constant expressions
899 when their arguments are. */
900 case BUILT_IN_ADD_OVERFLOW_P
:
901 case BUILT_IN_SUB_OVERFLOW_P
:
902 case BUILT_IN_MUL_OVERFLOW_P
:
904 /* These have constant results even if their operands are
906 case BUILT_IN_CONSTANT_P
:
907 case BUILT_IN_ATOMIC_ALWAYS_LOCK_FREE
:
914 // forked from gcc/cp/decl2.cc decl_maybe_constant_var_p
916 /* Returns true if DECL could be a symbolic constant variable, depending on
920 decl_maybe_constant_var_p (tree decl
)
922 tree type
= TREE_TYPE (decl
);
925 if (DECL_DECLARED_CONSTEXPR_P (decl
))
927 if (DECL_HAS_VALUE_EXPR_P (decl
))
928 /* A proxy isn't constant. */
930 if (TYPE_REF_P (type
))
931 /* References can be constant. */;
932 else if (RS_TYPE_CONST_NON_VOLATILE_P (type
)
933 && INTEGRAL_OR_ENUMERATION_TYPE_P (type
))
934 /* And const integers. */;
938 if (DECL_INITIAL (decl
) && !DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl
))
939 /* We know the initializer, and it isn't constant. */
945 // forked from gcc/cp/typeck.cc cp_type_quals
947 /* Returns the type qualifiers for this type, including the qualifiers on the
948 elements for an array type. */
951 rs_type_quals (const_tree type
)
954 /* This CONST_CAST is okay because strip_array_types returns its
955 argument unmodified and we assign it to a const_tree. */
956 type
= strip_array_types (CONST_CAST_TREE (type
));
957 if (type
== error_mark_node
958 /* Quals on a FUNCTION_TYPE are memfn quals. */
959 || TREE_CODE (type
) == FUNCTION_TYPE
)
960 return TYPE_UNQUALIFIED
;
961 quals
= TYPE_QUALS (type
);
962 /* METHOD and REFERENCE_TYPEs should never have quals. */
964 // (TREE_CODE (type) != METHOD_TYPE && !TYPE_REF_P (type))
965 // || ((quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)) ==
966 // TYPE_UNQUALIFIED));
970 // forked from gcc/cp/decl.cc cp_global_trees
972 /* The following symbols are subsumed in the cp_global_trees array, and
973 listed here individually for documentation purposes.
976 tree wchar_decl_node;
978 tree vtable_entry_type;
979 tree delta_type_node;
980 tree __t_desc_type_node;
982 tree class_type_node;
983 tree unknown_type_node;
985 Array type `vtable_entry_type[]'
988 tree vtbl_ptr_type_node;
995 A FUNCTION_DECL which can call `abort'. Not necessarily the
996 one that the user will declare, but sufficient to be called
997 by routines that want to abort the program.
1002 tree type_info_type_node, tinfo_decl_id, tinfo_decl_type;
1003 tree tinfo_var_id; */
1005 /* The following symbols are subsumed in the c_global_trees array, and
1006 listed here individually for documentation purposes.
1008 INTEGER_TYPE and REAL_TYPE nodes for the standard data types.
1010 tree short_integer_type_node;
1011 tree long_integer_type_node;
1012 tree long_long_integer_type_node;
1014 tree short_unsigned_type_node;
1015 tree long_unsigned_type_node;
1016 tree long_long_unsigned_type_node;
1018 tree truthvalue_type_node;
1019 tree truthvalue_false_node;
1020 tree truthvalue_true_node;
1022 tree ptrdiff_type_node;
1024 tree unsigned_char_type_node;
1025 tree signed_char_type_node;
1026 tree wchar_type_node;
1028 tree char8_type_node;
1029 tree char16_type_node;
1030 tree char32_type_node;
1032 tree float_type_node;
1033 tree double_type_node;
1034 tree long_double_type_node;
1036 tree complex_integer_type_node;
1037 tree complex_float_type_node;
1038 tree complex_double_type_node;
1039 tree complex_long_double_type_node;
1041 tree dfloat32_type_node;
1042 tree dfloat64_type_node;
1043 tree_dfloat128_type_node;
1045 tree intQI_type_node;
1046 tree intHI_type_node;
1047 tree intSI_type_node;
1048 tree intDI_type_node;
1049 tree intTI_type_node;
1051 tree unsigned_intQI_type_node;
1052 tree unsigned_intHI_type_node;
1053 tree unsigned_intSI_type_node;
1054 tree unsigned_intDI_type_node;
1055 tree unsigned_intTI_type_node;
1057 tree widest_integer_literal_type_node;
1058 tree widest_unsigned_literal_type_node;
1060 Nodes for types `void *' and `const void *'.
1062 tree ptr_type_node, const_ptr_type_node;
1064 Nodes for types `char *' and `const char *'.
1066 tree string_type_node, const_string_type_node;
1068 Type `char[SOMENUMBER]'.
1069 Used when an array of char is needed and the size is irrelevant.
1071 tree char_array_type_node;
1073 Type `wchar_t[SOMENUMBER]' or something like it.
1074 Used when a wide string literal is created.
1076 tree wchar_array_type_node;
1078 Type `char8_t[SOMENUMBER]' or something like it.
1079 Used when a UTF-8 string literal is created.
1081 tree char8_array_type_node;
1083 Type `char16_t[SOMENUMBER]' or something like it.
1084 Used when a UTF-16 string literal is created.
1086 tree char16_array_type_node;
1088 Type `char32_t[SOMENUMBER]' or something like it.
1089 Used when a UTF-32 string literal is created.
1091 tree char32_array_type_node;
1093 Type `int ()' -- used for implicit declaration of functions.
1095 tree default_function_type;
1097 A VOID_TYPE node, packaged in a TREE_LIST.
1099 tree void_list_node;
1101 The lazily created VAR_DECLs for __FUNCTION__, __PRETTY_FUNCTION__,
1102 and __func__. (C doesn't generate __FUNCTION__ and__PRETTY_FUNCTION__
1103 VAR_DECLS, but C++ does.)
1105 tree function_name_decl_node;
1106 tree pretty_function_name_decl_node;
1107 tree c99_function_name_decl_node;
1109 Stack of nested function name VAR_DECLs.
1111 tree saved_function_name_decls;
1115 // forked from gcc/cp/module.cc fixed_trees
1117 static GTY (()) vec
<tree
, va_gc
> *fixed_trees
;
1119 // forked from gcc/cp/module.cc maybe_add_global
1121 /* VAL is a global tree, add it to the global vec if it is
1122 interesting. Add some of its targets, if they too are
1123 interesting. We do not add identifiers, as they can be re-found
1124 via the identifier hash table. There is a cost to the number of
1128 maybe_add_global (tree val
, unsigned &crc
)
1132 if (val
&& !(TREE_CODE (val
) == IDENTIFIER_NODE
|| TREE_VISITED (val
)))
1134 TREE_VISITED (val
) = true;
1135 crc
= crc32_unsigned (crc
, fixed_trees
->length ());
1136 vec_safe_push (fixed_trees
, val
);
1139 if (CODE_CONTAINS_STRUCT (TREE_CODE (val
), TS_TYPED
))
1140 v
+= maybe_add_global (TREE_TYPE (val
), crc
);
1141 if (CODE_CONTAINS_STRUCT (TREE_CODE (val
), TS_TYPE_COMMON
))
1142 v
+= maybe_add_global (TYPE_NAME (val
), crc
);
1148 // forked from gcc/cp/module.cc global_tree_arys
1151 static const std::pair
<tree
*, unsigned> global_tree_arys
[] = {
1152 std::pair
<tree
*, unsigned> (cp_global_trees
, CPTI_MODULE_HWM
),
1153 std::pair
<tree
*, unsigned> (c_global_trees
, CTI_MODULE_HWM
),
1156 // forked from gcc/cp/module.cc init_modules
1162 vec_alloc (fixed_trees
, 200);
1164 const tree
*ptr
= global_tree_arys
[0].first
;
1165 unsigned limit
= global_tree_arys
[0].second
;
1166 for (unsigned ix
= 0; ix
!= limit
; ix
++, ptr
++)
1168 maybe_add_global (*ptr
, crc
);
1171 ptr
= global_tree_arys
[1].first
;
1172 limit
= global_tree_arys
[1].second
;
1173 for (unsigned ix
= 0; ix
!= limit
; ix
++, ptr
++)
1175 maybe_add_global (*ptr
, crc
);
1179 // forked from gcc/cp/constexpr.cc var_in_constexpr_fn
1181 /* True if T was declared in a function declared to be constexpr, and
1182 therefore potentially constant in C++14. */
1185 var_in_constexpr_fn (tree t
)
1187 tree ctx
= DECL_CONTEXT (t
);
1188 return (ctx
&& TREE_CODE (ctx
) == FUNCTION_DECL
1189 && DECL_DECLARED_CONSTEXPR_P (ctx
));
1192 // forked from gcc/cp/name-lookup.cc member_vec_linear_search
1194 /* Linear search of (unordered) MEMBER_VEC for NAME. */
1197 member_vec_linear_search (vec
<tree
, va_gc
> *member_vec
, tree name
)
1199 for (int ix
= member_vec
->length (); ix
--;)
1200 if (tree binding
= (*member_vec
)[ix
])
1201 if (OVL_NAME (binding
) == name
)
1207 // forked from gcc/cp/name-lookup.cc member_vec_binary_search
1209 /* Binary search of (ordered) MEMBER_VEC for NAME. */
1212 member_vec_binary_search (vec
<tree
, va_gc
> *member_vec
, tree name
)
1214 for (unsigned lo
= 0, hi
= member_vec
->length (); lo
< hi
;)
1216 unsigned mid
= (lo
+ hi
) / 2;
1217 tree binding
= (*member_vec
)[mid
];
1218 tree binding_name
= OVL_NAME (binding
);
1220 if (binding_name
> name
)
1222 else if (binding_name
< name
)
1231 // forked from gcc/cp/tree.cc is_overloaded_fn
1233 /* Returns nonzero if X is an expression for a (possibly overloaded)
1234 function. If "f" is a function or function template, "f", "c->f",
1235 "c.f", "C::f", and "f<int>" will all be considered possibly
1236 overloaded functions. Returns 2 if the function is actually
1237 overloaded, i.e., if it is impossible to know the type of the
1238 function without performing overload resolution. */
1241 is_overloaded_fn (tree x
)
1243 STRIP_ANY_LOCATION_WRAPPER (x
);
1245 if (TREE_CODE (x
) == COMPONENT_REF
)
1246 x
= TREE_OPERAND (x
, 1);
1251 // forked from gcc/cp/tree.cc ovl_make
1253 /* Make a raw overload node containing FN. */
1256 ovl_make (tree fn
, tree next
)
1258 tree result
= make_node (OVERLOAD
);
1260 if (TREE_CODE (fn
) == OVERLOAD
)
1261 OVL_NESTED_P (result
) = true;
1263 TREE_TYPE (result
) = (next
? unknown_type_node
: TREE_TYPE (fn
));
1264 if (next
&& TREE_CODE (next
) == OVERLOAD
&& OVL_DEDUP_P (next
))
1265 OVL_DEDUP_P (result
) = true;
1266 OVL_FUNCTION (result
) = fn
;
1267 OVL_CHAIN (result
) = next
;
1271 // forked from gcc/cp/name-lookup.cc lookup_add
1273 /* Add a set of new FNS into a lookup. */
1276 lookup_add (tree fns
, tree lookup
)
1278 if (fns
== error_mark_node
|| lookup
== error_mark_node
)
1279 return error_mark_node
;
1286 // forked from gcc/cp/typeck.cc type_memfn_quals
1288 /* Returns the function-cv-quals for TYPE, which must be a FUNCTION_TYPE or
1292 type_memfn_quals (const_tree type
)
1294 if (TREE_CODE (type
) == FUNCTION_TYPE
)
1295 return TYPE_QUALS (type
);
1296 else if (TREE_CODE (type
) == METHOD_TYPE
)
1297 return rs_type_quals (class_of_this_parm (type
));
1299 rust_unreachable ();
1302 // forked from gcc/cp/pt.cc find_parameter_pack_data
1304 /* Structure used to track the progress of find_parameter_packs_r. */
1305 struct find_parameter_pack_data
1307 /* TREE_LIST that will contain all of the parameter packs found by
1309 tree
*parameter_packs
;
1311 /* Set of AST nodes that have been visited by the traversal. */
1312 hash_set
<tree
> *visited
;
1314 /* True iff we're making a type pack expansion. */
1315 bool type_pack_expansion_p
;
1317 /* True iff we found a subtree that has the extra args mechanism. */
1318 bool found_extra_args_tree_p
= false;
1321 // forked from gcc/cp/lex.cc conv_type_hasher
1323 /* Hasher for the conversion operator name hash table. */
1324 struct rust_conv_type_hasher
: ggc_ptr_hash
<tree_node
>
1326 /* Hash NODE, an identifier node in the table. TYPE_UID is
1327 suitable, as we're not concerned about matching canonicalness
1329 static hashval_t
hash (tree node
)
1331 return (hashval_t
) TYPE_UID (TREE_TYPE (node
));
1334 /* Compare NODE, an identifier node in the table, against TYPE, an
1335 incoming TYPE being looked up. */
1336 static bool equal (tree node
, tree type
) { return TREE_TYPE (node
) == type
; }
1339 static GTY (()) hash_table
<rust_conv_type_hasher
> *conv_type_names
;
1341 // forked from gcc/cp/lex.cc make_conv_op_name
1343 /* Return an identifier for a conversion operator to TYPE. We can get
1344 from the returned identifier to the type. We store TYPE, which is
1345 not necessarily the canonical type, which allows us to report the
1346 form the user used in error messages. All these identifiers are
1347 not in the identifier hash table, and have the same string name.
1348 These IDENTIFIERS are not in the identifier hash table, and all
1349 have the same IDENTIFIER_STRING. */
1352 make_conv_op_name (tree type
)
1354 if (type
== error_mark_node
)
1355 return error_mark_node
;
1357 if (conv_type_names
== NULL
)
1358 conv_type_names
= hash_table
<rust_conv_type_hasher
>::create_ggc (31);
1361 = conv_type_names
->find_slot_with_hash (type
, (hashval_t
) TYPE_UID (type
),
1363 tree identifier
= *slot
;
1366 /* Create a raw IDENTIFIER outside of the identifier hash
1368 identifier
= copy_node (conv_op_identifier
);
1370 /* Just in case something managed to bind. */
1371 IDENTIFIER_BINDING (identifier
) = NULL
;
1373 /* Hang TYPE off the identifier so it can be found easily later
1374 when performing conversions. */
1375 TREE_TYPE (identifier
) = type
;
1383 // forked from gcc/cp/pt.cc builtin_pack_fn_p
1385 /* True iff FN is a function representing a built-in variadic parameter
1389 builtin_pack_fn_p (tree fn
)
1391 if (!fn
|| TREE_CODE (fn
) != FUNCTION_DECL
1392 || !DECL_IS_UNDECLARED_BUILTIN (fn
))
1395 if (id_equal (DECL_NAME (fn
), "__integer_pack"))
1401 // forked from gcc/cp/pt.cc builtin_pack_call_p
1403 /* True iff CALL is a call to a function representing a built-in variadic
1407 builtin_pack_call_p (tree call
)
1409 if (TREE_CODE (call
) != CALL_EXPR
)
1411 return builtin_pack_fn_p (CALL_EXPR_FN (call
));
1414 //// forked from gcc/cp/pt.cc has_extra_args_mechanism_p
1416 ///* Return true if the tree T has the extra args mechanism for
1417 // avoiding partial instantiation. */
1420 // has_extra_args_mechanism_p (const_tree t)
1425 // forked from gcc/cp/pt.cc find_parameter_packs_r
1427 /* Identifies all of the argument packs that occur in a template
1428 argument and appends them to the TREE_LIST inside DATA, which is a
1429 find_parameter_pack_data structure. This is a subroutine of
1430 make_pack_expansion and uses_parameter_packs. */
1432 find_parameter_packs_r (tree
*tp
, int *walk_subtrees
, void *data
)
1435 struct find_parameter_pack_data
*ppd
1436 = (struct find_parameter_pack_data
*) data
;
1437 bool parameter_pack_p
= false;
1439 #define WALK_SUBTREE(NODE) \
1440 rs_walk_tree (&(NODE), &find_parameter_packs_r, ppd, ppd->visited)
1442 /* Don't look through typedefs; we are interested in whether a
1443 parameter pack is actually written in the expression/type we're
1444 looking at, not the target type. */
1445 if (TYPE_P (t
) && typedef_variant_p (t
))
1451 /* Identify whether this is a parameter pack or not. */
1452 switch (TREE_CODE (t
))
1462 if (builtin_pack_call_p (t
))
1463 parameter_pack_p
= true;
1467 parameter_pack_p
= true;
1470 /* Not a parameter pack. */
1474 if (parameter_pack_p
)
1476 /* Add this parameter pack to the list. */
1477 *ppd
->parameter_packs
= tree_cons (NULL_TREE
, t
, *ppd
->parameter_packs
);
1481 rs_walk_tree (&TYPE_CONTEXT (t
), &find_parameter_packs_r
, ppd
,
1484 /* This switch statement will return immediately if we don't find a
1485 parameter pack. ??? Should some of these be in cp_walk_subtrees? */
1486 switch (TREE_CODE (t
))
1489 tree decl
= DECL_EXPR_DECL (t
);
1490 if (is_typedef_decl (decl
))
1491 /* Since we stop at typedefs above, we need to look through them at
1492 the point of the DECL_EXPR. */
1493 rs_walk_tree (&DECL_ORIGINAL_TYPE (decl
), &find_parameter_packs_r
,
1499 rs_walk_tree (&TYPE_MAX_VALUE (t
), &find_parameter_packs_r
, ppd
,
1504 case IDENTIFIER_NODE
:
1505 rs_walk_tree (&TREE_TYPE (t
), &find_parameter_packs_r
, ppd
, ppd
->visited
);
1509 case DECLTYPE_TYPE
: {
1510 /* When traversing a DECLTYPE_TYPE_EXPR, we need to set
1511 type_pack_expansion_p to false so that any placeholders
1512 within the expression don't get marked as parameter packs. */
1513 bool type_pack_expansion_p
= ppd
->type_pack_expansion_p
;
1514 ppd
->type_pack_expansion_p
= false;
1515 rs_walk_tree (&DECLTYPE_TYPE_EXPR (t
), &find_parameter_packs_r
, ppd
,
1517 ppd
->type_pack_expansion_p
= type_pack_expansion_p
;
1523 rs_walk_tree (&IF_COND (t
), &find_parameter_packs_r
, ppd
, ppd
->visited
);
1524 rs_walk_tree (&THEN_CLAUSE (t
), &find_parameter_packs_r
, ppd
,
1526 rs_walk_tree (&ELSE_CLAUSE (t
), &find_parameter_packs_r
, ppd
,
1528 /* Don't walk into IF_STMT_EXTRA_ARGS. */
1534 WALK_SUBTREE (TYPE_RAISES_EXCEPTIONS (t
));
1546 // forked from gcc/cp/typeck.cc type_memfn_rqual
1548 /* Returns the function-ref-qualifier for TYPE */
1551 type_memfn_rqual (const_tree type
)
1553 gcc_assert (FUNC_OR_METHOD_TYPE_P (type
));
1555 if (!FUNCTION_REF_QUALIFIED (type
))
1556 return REF_QUAL_NONE
;
1557 else if (FUNCTION_RVALUE_QUALIFIED (type
))
1558 return REF_QUAL_RVALUE
;
1560 return REF_QUAL_LVALUE
;
1563 // forked from gcc/cp/lex.cc maybe_add_lang_type_raw
1565 /* Add a raw lang_type to T, a type, should it need one. */
1568 maybe_add_lang_type_raw (tree t
)
1570 if (!RECORD_OR_UNION_CODE_P (TREE_CODE (t
)))
1573 auto *lt
= (struct lang_type
*) (ggc_internal_cleared_alloc (
1574 sizeof (struct lang_type
)));
1575 TYPE_LANG_SPECIFIC (t
) = lt
;
1577 if (GATHER_STATISTICS
)
1579 tree_node_counts
[(int) lang_type
] += 1;
1580 tree_node_sizes
[(int) lang_type
] += sizeof (struct lang_type
);
1586 // forked from gcc/c-family/c-lex.cc get_fileinfo
1588 static splay_tree file_info_tree
;
1591 get_fileinfo (const char *name
)
1594 struct c_fileinfo
*fi
;
1596 if (!file_info_tree
)
1597 file_info_tree
= splay_tree_new (splay_tree_compare_strings
, 0,
1598 splay_tree_delete_pointers
);
1600 n
= splay_tree_lookup (file_info_tree
, (splay_tree_key
) name
);
1602 return (struct c_fileinfo
*) n
->value
;
1604 fi
= XNEW (struct c_fileinfo
);
1606 fi
->interface_only
= 0;
1607 fi
->interface_unknown
= 1;
1608 splay_tree_insert (file_info_tree
, (splay_tree_key
) name
,
1609 (splay_tree_value
) fi
);
1613 // forked from gcc/cp/lex.cc cxx_make_type
1616 cxx_make_type (enum tree_code code MEM_STAT_DECL
)
1618 tree t
= make_node (code PASS_MEM_STAT
);
1620 if (maybe_add_lang_type_raw (t
))
1622 /* Set up some flags that give proper default behavior. */
1623 struct c_fileinfo
*finfo
= get_fileinfo (LOCATION_FILE (input_location
));
1624 SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t
, finfo
->interface_unknown
);
1625 CLASSTYPE_INTERFACE_ONLY (t
) = finfo
->interface_only
;
1628 if (code
== RECORD_TYPE
|| code
== UNION_TYPE
)
1629 TYPE_CXX_ODR_P (t
) = 1;
1634 // forked from gcc/cp/tree.cc build_min_array_type
1636 /* Build an ARRAY_TYPE without laying it out. */
1639 build_min_array_type (tree elt_type
, tree index_type
)
1641 tree t
= cxx_make_type (ARRAY_TYPE
);
1642 TREE_TYPE (t
) = elt_type
;
1643 TYPE_DOMAIN (t
) = index_type
;
1647 // forked from gcc/cp/name-lookup.cc resort_data
1653 gt_pointer_operator new_value
;
1657 // forked from gcc/cp/name-lookup.cc resort_member_name_cmp
1659 /* This routine compares two fields like member_name_cmp but using the
1660 pointer operator in resort_field_decl_data. We don't have to deal
1661 with duplicates here. */
1664 resort_member_name_cmp (const void *a_p
, const void *b_p
)
1666 tree a
= *(const tree
*) a_p
;
1667 tree b
= *(const tree
*) b_p
;
1668 tree name_a
= OVL_NAME (a
);
1669 tree name_b
= OVL_NAME (b
);
1671 resort_data
.new_value (&name_a
, &name_a
, resort_data
.cookie
);
1672 resort_data
.new_value (&name_b
, &name_b
, resort_data
.cookie
);
1674 gcc_checking_assert (name_a
!= name_b
);
1676 return name_a
< name_b
? -1 : +1;
1679 // forked from gcc/cp/name-lookup.cc resort_type_member_vec
1681 /* Resort CLASSTYPE_MEMBER_VEC because pointers have been reordered. */
1684 resort_type_member_vec (void *obj
, void * /*orig_obj*/,
1685 gt_pointer_operator new_value
, void *cookie
)
1687 if (vec
<tree
, va_gc
> *member_vec
= (vec
<tree
, va_gc
> *) obj
)
1689 resort_data
.new_value
= new_value
;
1690 resort_data
.cookie
= cookie
;
1691 member_vec
->qsort (resort_member_name_cmp
);
1697 // forked from gcc/cp/name-lookup.cc fields_linear_search
1699 /* Linear search of (partially ordered) fields of KLASS for NAME. */
1702 fields_linear_search (tree klass
, tree name
, bool want_type
)
1704 for (tree fields
= TYPE_FIELDS (klass
); fields
; fields
= DECL_CHAIN (fields
))
1708 if (DECL_NAME (decl
) != name
)
1711 if (DECL_DECLARES_FUNCTION_P (decl
))
1712 /* Functions are found separately. */
1715 if (!want_type
|| DECL_DECLARES_TYPE_P (decl
))
1722 // forked from gcc/cp/except.cc canonnothrow_spec_pical_eh_spec
1724 /* Return true iff SPEC is throw() or noexcept(true). */
1727 nothrow_spec_p (const_tree spec
)
1729 if (spec
== empty_except_spec
|| spec
== noexcept_true_spec
)
1732 gcc_assert (!spec
|| TREE_VALUE (spec
) || spec
== noexcept_false_spec
1733 || TREE_PURPOSE (spec
) == error_mark_node
);
1738 // forked from gcc/cp/tree.cc may_get_fns
1740 /* Get the overload set FROM refers to. Returns NULL if it's not an
1744 maybe_get_fns (tree from
)
1746 STRIP_ANY_LOCATION_WRAPPER (from
);
1748 /* A baselink is also considered an overloaded function. */
1749 if (TREE_CODE (from
) == COMPONENT_REF
)
1750 from
= TREE_OPERAND (from
, 1);
1758 // forked from gcc/cp/tree.cc get_fns
1760 /* FROM refers to an overload set. Return that set (or die). */
1765 tree res
= maybe_get_fns (from
);
1771 // forked from gcc/cp/tree.cc get_first_fn
1773 /* Return the first function of the overload set FROM refers to. */
1776 get_first_fn (tree from
)
1778 return OVL_FIRST (get_fns (from
));
1781 // forked from gcc/cp/tree.cc dependent_name
1783 /* X is the CALL_EXPR_FN of a CALL_EXPR. If X represents a dependent name
1784 (14.6.2), return the IDENTIFIER_NODE for that name. Otherwise, return
1788 dependent_name (tree x
)
1790 /* FIXME a dependent name must be unqualified, but this function doesn't
1791 distinguish between qualified and unqualified identifiers. */
1792 if (identifier_p (x
))
1796 return OVL_NAME (x
);
1800 // forked from gcc/cp/tree.cc called_fns_equal
1802 /* Subroutine of rs_tree_equal: t1 and t2 are the CALL_EXPR_FNs of two
1803 CALL_EXPRS. Return whether they are equivalent. */
1806 called_fns_equal (tree t1
, tree t2
)
1808 /* Core 1321: dependent names are equivalent even if the overload sets
1809 are different. But do compare explicit template arguments. */
1810 tree name1
= dependent_name (t1
);
1811 tree name2
= dependent_name (t2
);
1814 tree targs1
= NULL_TREE
, targs2
= NULL_TREE
;
1819 /* FIXME dependent_name currently returns an unqualified name regardless
1820 of whether the function was named with a qualified- or unqualified-id.
1821 Until that's fixed, check that we aren't looking at overload sets from
1822 different scopes. */
1823 if (is_overloaded_fn (t1
) && is_overloaded_fn (t2
)
1824 && (DECL_CONTEXT (get_first_fn (t1
))
1825 != DECL_CONTEXT (get_first_fn (t2
))))
1828 return rs_tree_equal (targs1
, targs2
);
1831 return rs_tree_equal (t1
, t2
);
1834 // forked from gcc/cp/tree.cc canonical_eh_spec
1836 /* Return the canonical version of exception-specification RAISES for a C++17
1837 function type, for use in type comparison and building TYPE_CANONICAL. */
1840 canonical_eh_spec (tree raises
)
1842 if (raises
== NULL_TREE
)
1844 else if (nothrow_spec_p (raises
))
1845 /* throw() -> noexcept. */
1846 return noexcept_true_spec
;
1848 /* For C++17 type matching, anything else -> nothing. */
1852 /* Like cp_tree_operand_length, but takes a tree_code CODE. */
1855 rs_tree_code_length (enum tree_code code
)
1857 gcc_assert (TREE_CODE_CLASS (code
) != tcc_vl_exp
);
1861 case PREINCREMENT_EXPR
:
1862 case PREDECREMENT_EXPR
:
1863 case POSTINCREMENT_EXPR
:
1864 case POSTDECREMENT_EXPR
:
1871 return TREE_CODE_LENGTH (code
);
1875 // forked from gcc/cp/tree.cc rs_tree_operand_length
1877 /* Return the number of operands in T that we care about for things like
1881 rs_tree_operand_length (const_tree t
)
1883 enum tree_code code
= TREE_CODE (t
);
1885 if (TREE_CODE_CLASS (code
) == tcc_vl_exp
)
1886 return VL_EXP_OPERAND_LENGTH (t
);
1888 return rs_tree_code_length (code
);
1891 // forked from gcc/cp/tree.cc cp_tree_equal
1893 /* Return truthvalue of whether T1 is the same tree structure as T2.
1894 Return 1 if they are the same. Return 0 if they are different. */
1897 rs_tree_equal (tree t1
, tree t2
)
1899 enum tree_code code1
, code2
;
1906 code1
= TREE_CODE (t1
);
1907 code2
= TREE_CODE (t2
);
1912 if (CONSTANT_CLASS_P (t1
) && !same_type_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
1918 /* There's only a single VOID_CST node, so we should never reach
1920 rust_unreachable ();
1923 return tree_int_cst_equal (t1
, t2
);
1926 return real_identical (&TREE_REAL_CST (t1
), &TREE_REAL_CST (t2
));
1929 return TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
1930 && !memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
1931 TREE_STRING_LENGTH (t1
));
1934 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1
), TREE_FIXED_CST (t2
));
1937 return rs_tree_equal (TREE_REALPART (t1
), TREE_REALPART (t2
))
1938 && rs_tree_equal (TREE_IMAGPART (t1
), TREE_IMAGPART (t2
));
1941 return operand_equal_p (t1
, t2
, OEP_ONLY_CONST
);
1944 /* We need to do this when determining whether or not two
1945 non-type pointer to member function template arguments
1947 if (!same_type_p (TREE_TYPE (t1
), TREE_TYPE (t2
))
1948 || CONSTRUCTOR_NELTS (t1
) != CONSTRUCTOR_NELTS (t2
))
1953 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t1
), i
, field
, value
)
1955 constructor_elt
*elt2
= CONSTRUCTOR_ELT (t2
, i
);
1956 if (!rs_tree_equal (field
, elt2
->index
)
1957 || !rs_tree_equal (value
, elt2
->value
))
1964 if (!rs_tree_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
)))
1966 if (!rs_tree_equal (TREE_VALUE (t1
), TREE_VALUE (t2
)))
1968 return rs_tree_equal (TREE_CHAIN (t1
), TREE_CHAIN (t2
));
1971 return rs_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
1974 if (KOENIG_LOOKUP_P (t1
) != KOENIG_LOOKUP_P (t2
))
1977 if (!called_fns_equal (CALL_EXPR_FN (t1
), CALL_EXPR_FN (t2
)))
1980 call_expr_arg_iterator iter1
, iter2
;
1981 init_call_expr_arg_iterator (t1
, &iter1
);
1982 init_call_expr_arg_iterator (t2
, &iter2
);
1983 if (iter1
.n
!= iter2
.n
)
1986 while (more_call_expr_args_p (&iter1
))
1988 tree arg1
= next_call_expr_arg (&iter1
);
1989 tree arg2
= next_call_expr_arg (&iter2
);
1991 gcc_checking_assert (arg1
&& arg2
);
1992 if (!rs_tree_equal (arg1
, arg2
))
2000 tree o1
= TREE_OPERAND (t1
, 0);
2001 tree o2
= TREE_OPERAND (t2
, 0);
2003 /* Special case: if either target is an unallocated VAR_DECL,
2004 it means that it's going to be unified with whatever the
2005 TARGET_EXPR is really supposed to initialize, so treat it
2006 as being equivalent to anything. */
2007 if (VAR_P (o1
) && DECL_NAME (o1
) == NULL_TREE
&& !DECL_RTL_SET_P (o1
))
2009 else if (VAR_P (o2
) && DECL_NAME (o2
) == NULL_TREE
2010 && !DECL_RTL_SET_P (o2
))
2012 else if (!rs_tree_equal (o1
, o2
))
2015 return rs_tree_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
2019 /* For comparing uses of parameters in late-specified return types
2020 with an out-of-class definition of the function, but can also come
2021 up for expressions that involve 'this' in a member function
2024 if (same_type_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
2026 if (DECL_ARTIFICIAL (t1
) ^ DECL_ARTIFICIAL (t2
))
2028 if (CONSTRAINT_VAR_P (t1
) ^ CONSTRAINT_VAR_P (t2
))
2030 if (DECL_ARTIFICIAL (t1
)
2031 || (DECL_PARM_LEVEL (t1
) == DECL_PARM_LEVEL (t2
)
2032 && DECL_PARM_INDEX (t1
) == DECL_PARM_INDEX (t2
)))
2041 case IDENTIFIER_NODE
:
2048 case NON_LVALUE_EXPR
:
2049 case VIEW_CONVERT_EXPR
:
2050 /* Used for location wrappers with possibly NULL types. */
2051 if (!TREE_TYPE (t1
) || !TREE_TYPE (t2
))
2053 if (TREE_TYPE (t1
) || TREE_TYPE (t2
))
2062 switch (TREE_CODE_CLASS (code1
))
2066 case tcc_comparison
:
2067 case tcc_expression
:
2070 case tcc_statement
: {
2071 int n
= rs_tree_operand_length (t1
);
2072 if (TREE_CODE_CLASS (code1
) == tcc_vl_exp
2073 && n
!= TREE_OPERAND_LENGTH (t2
))
2076 for (int i
= 0; i
< n
; ++i
)
2077 if (!rs_tree_equal (TREE_OPERAND (t1
, i
), TREE_OPERAND (t2
, i
)))
2084 return same_type_p (t1
, t2
);
2087 rust_unreachable ();
2090 /* We can get here with --disable-checking. */
2094 // forked from gcc/cp/class.cc publicly_uniquely_derived_p
2096 /* TRUE iff TYPE is publicly & uniquely derived from PARENT. */
2098 bool publicly_uniquely_derived_p (tree
, tree
) { return false; }
2100 // forked from gcc/cp/typeck.cc comp_except_types
2102 /* Compare two exception specifier types for exactness or subsetness, if
2103 allowed. Returns false for mismatch, true for match (same, or
2104 derived and !exact).
2106 [except.spec] "If a class X ... objects of class X or any class publicly
2107 and unambiguously derived from X. Similarly, if a pointer type Y * ...
2108 exceptions of type Y * or that are pointers to any type publicly and
2109 unambiguously derived from Y. Otherwise a function only allows exceptions
2110 that have the same type ..."
2111 This does not mention cv qualifiers and is different to what throw
2112 [except.throw] and catch [except.catch] will do. They will ignore the
2113 top level cv qualifiers, and allow qualifiers in the pointer to class
2116 We implement the letter of the standard. */
2119 comp_except_types (tree a
, tree b
, bool exact
)
2121 if (same_type_p (a
, b
))
2125 if (rs_type_quals (a
) || rs_type_quals (b
))
2128 if (TYPE_PTR_P (a
) && TYPE_PTR_P (b
))
2132 if (rs_type_quals (a
) || rs_type_quals (b
))
2136 if (TREE_CODE (a
) != RECORD_TYPE
|| TREE_CODE (b
) != RECORD_TYPE
)
2139 if (publicly_uniquely_derived_p (a
, b
))
2145 // forked from gcc/cp/typeck.cc comp_except_specs
2147 /* Return true if TYPE1 and TYPE2 are equivalent exception specifiers.
2148 If EXACT is ce_derived, T2 can be stricter than T1 (according to 15.4/5).
2149 If EXACT is ce_type, the C++17 type compatibility rules apply.
2150 If EXACT is ce_normal, the compatibility rules in 15.4/3 apply.
2151 If EXACT is ce_exact, the specs must be exactly the same. Exception lists
2152 are unordered, but we've already filtered out duplicates. Most lists will
2153 be in order, we should try to make use of that. */
2156 comp_except_specs (const_tree t1
, const_tree t2
, int exact
)
2165 /* First handle noexcept. */
2166 if (exact
< ce_exact
)
2168 if (exact
== ce_type
2169 && (canonical_eh_spec (CONST_CAST_TREE (t1
))
2170 == canonical_eh_spec (CONST_CAST_TREE (t2
))))
2173 /* noexcept(false) is compatible with no exception-specification,
2174 and less strict than any spec. */
2175 if (t1
== noexcept_false_spec
)
2176 return t2
== NULL_TREE
|| exact
== ce_derived
;
2177 /* Even a derived noexcept(false) is compatible with no
2178 exception-specification. */
2179 if (t2
== noexcept_false_spec
)
2180 return t1
== NULL_TREE
;
2182 /* Otherwise, if we aren't looking for an exact match, noexcept is
2183 equivalent to throw(). */
2184 if (t1
== noexcept_true_spec
)
2185 t1
= empty_except_spec
;
2186 if (t2
== noexcept_true_spec
)
2187 t2
= empty_except_spec
;
2190 /* If any noexcept is left, it is only comparable to itself;
2191 either we're looking for an exact match or we're redeclaring a
2192 template with dependent noexcept. */
2193 if ((t1
&& TREE_PURPOSE (t1
)) || (t2
&& TREE_PURPOSE (t2
)))
2194 return (t1
&& t2
&& rs_tree_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
)));
2196 if (t1
== NULL_TREE
) /* T1 is ... */
2197 return t2
== NULL_TREE
|| exact
== ce_derived
;
2198 if (!TREE_VALUE (t1
)) /* t1 is EMPTY */
2199 return t2
!= NULL_TREE
&& !TREE_VALUE (t2
);
2200 if (t2
== NULL_TREE
) /* T2 is ... */
2202 if (TREE_VALUE (t1
) && !TREE_VALUE (t2
)) /* T2 is EMPTY, T1 is not */
2203 return exact
== ce_derived
;
2205 /* Neither set is ... or EMPTY, make sure each part of T2 is in T1.
2206 Count how many we find, to determine exactness. For exact matching and
2207 ordered T1, T2, this is an O(n) operation, otherwise its worst case is
2209 for (base
= t1
; t2
!= NULL_TREE
; t2
= TREE_CHAIN (t2
))
2211 for (probe
= base
; probe
!= NULL_TREE
; probe
= TREE_CHAIN (probe
))
2213 tree a
= TREE_VALUE (probe
);
2214 tree b
= TREE_VALUE (t2
);
2216 if (comp_except_types (a
, b
, exact
))
2218 if (probe
== base
&& exact
> ce_derived
)
2219 base
= TREE_CHAIN (probe
);
2224 if (probe
== NULL_TREE
)
2227 return exact
== ce_derived
|| base
== NULL_TREE
|| length
== list_length (t1
);
2230 // forked from gcc/cp/typeck.cc compparms
2232 /* Subroutines of `comptypes'. */
2234 /* Return true if two parameter type lists PARMS1 and PARMS2 are
2235 equivalent in the sense that functions with those parameter types
2236 can have equivalent types. The two lists must be equivalent,
2237 element by element. */
2240 compparms (const_tree parms1
, const_tree parms2
)
2244 /* An unspecified parmlist matches any specified parmlist
2245 whose argument types don't need default promotions. */
2247 for (t1
= parms1
, t2
= parms2
; t1
|| t2
;
2248 t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
))
2250 /* If one parmlist is shorter than the other,
2251 they fail to match. */
2254 if (!same_type_p (TREE_VALUE (t1
), TREE_VALUE (t2
)))
2260 /* Set TYPE_CANONICAL like build_array_type_1, but using
2261 build_cplus_array_type. */
2264 set_array_type_canon (tree t
, tree elt_type
, tree index_type
, bool dep
)
2266 /* Set the canonical type for this new node. */
2267 if (TYPE_STRUCTURAL_EQUALITY_P (elt_type
)
2268 || (index_type
&& TYPE_STRUCTURAL_EQUALITY_P (index_type
)))
2269 SET_TYPE_STRUCTURAL_EQUALITY (t
);
2270 else if (TYPE_CANONICAL (elt_type
) != elt_type
2271 || (index_type
&& TYPE_CANONICAL (index_type
) != index_type
))
2273 = build_cplus_array_type (TYPE_CANONICAL (elt_type
),
2274 index_type
? TYPE_CANONICAL (index_type
)
2278 TYPE_CANONICAL (t
) = t
;
2281 // forked from gcc/cp/tree.cc cplus_array_info
2283 struct cplus_array_info
2289 // forked from gcc/cp/tree.cc cplus_array_hasher
2291 struct rust_cplus_array_hasher
: ggc_ptr_hash
<tree_node
>
2293 typedef cplus_array_info
*compare_type
;
2295 static hashval_t
hash (tree t
);
2296 static bool equal (tree
, cplus_array_info
*);
2299 /* Hash an ARRAY_TYPE. K is really of type `tree'. */
2302 rust_cplus_array_hasher::hash (tree t
)
2306 hash
= TYPE_UID (TREE_TYPE (t
));
2307 if (TYPE_DOMAIN (t
))
2308 hash
^= TYPE_UID (TYPE_DOMAIN (t
));
2312 /* Compare two ARRAY_TYPEs. K1 is really of type `tree', K2 is really
2313 of type `cplus_array_info*'. */
2316 rust_cplus_array_hasher::equal (tree t1
, cplus_array_info
*t2
)
2318 return (TREE_TYPE (t1
) == t2
->type
&& TYPE_DOMAIN (t1
) == t2
->domain
);
2321 // forked from gcc/cp/tree.cc cplus_array_htab
2323 /* Hash table containing dependent array types, which are unsuitable for
2324 the language-independent type hash table. */
2325 static GTY (()) hash_table
<rust_cplus_array_hasher
> *cplus_array_htab
;
2327 // forked from gcc/cp/tree.cc is_byte_access_type
2329 /* Returns true if TYPE is char, unsigned char, or std::byte. */
2332 is_byte_access_type (tree type
)
2334 type
= TYPE_MAIN_VARIANT (type
);
2335 if (type
== char_type_node
|| type
== unsigned_char_type_node
)
2338 return (TREE_CODE (type
) == ENUMERAL_TYPE
&& TYPE_CONTEXT (type
) == std_node
2339 && !strcmp ("byte", TYPE_NAME_STRING (type
)));
2342 // forked from gcc/cp/tree.cc build_cplus_array_type
2344 /* Like build_array_type, but handle special C++ semantics: an array of a
2345 variant element type is a variant of the array of the main variant of
2346 the element type. IS_DEPENDENT is -ve if we should determine the
2347 dependency. Otherwise its bool value indicates dependency. */
2350 build_cplus_array_type (tree elt_type
, tree index_type
, int dependent
)
2354 if (elt_type
== error_mark_node
|| index_type
== error_mark_node
)
2355 return error_mark_node
;
2360 if (elt_type
!= TYPE_MAIN_VARIANT (elt_type
))
2361 /* Start with an array of the TYPE_MAIN_VARIANT. */
2362 t
= build_cplus_array_type (TYPE_MAIN_VARIANT (elt_type
), index_type
,
2366 /* Since type_hash_canon calls layout_type, we need to use our own
2368 cplus_array_info cai
;
2371 if (cplus_array_htab
== NULL
)
2372 cplus_array_htab
= hash_table
<rust_cplus_array_hasher
>::create_ggc (61);
2374 hash
= TYPE_UID (elt_type
);
2376 hash
^= TYPE_UID (index_type
);
2377 cai
.type
= elt_type
;
2378 cai
.domain
= index_type
;
2380 tree
*e
= cplus_array_htab
->find_slot_with_hash (&cai
, hash
, INSERT
);
2382 /* We have found the type: we're done. */
2386 /* Build a new array type. */
2387 t
= build_min_array_type (elt_type
, index_type
);
2389 /* Store it in the hash table. */
2392 /* Set the canonical type for this new node. */
2393 set_array_type_canon (t
, elt_type
, index_type
, dependent
);
2395 /* Mark it as dependent now, this saves time later. */
2396 TYPE_DEPENDENT_P_VALID (t
) = true;
2397 TYPE_DEPENDENT_P (t
) = true;
2402 bool typeless_storage
= is_byte_access_type (elt_type
);
2403 t
= build_array_type (elt_type
, index_type
, typeless_storage
);
2405 /* Mark as non-dependenty now, this will save time later. */
2406 TYPE_DEPENDENT_P_VALID (t
) = true;
2409 /* Now check whether we already have this array variant. */
2410 if (elt_type
!= TYPE_MAIN_VARIANT (elt_type
))
2413 for (t
= m
; t
; t
= TYPE_NEXT_VARIANT (t
))
2414 if (TREE_TYPE (t
) == elt_type
&& TYPE_NAME (t
) == NULL_TREE
2415 && TYPE_ATTRIBUTES (t
) == NULL_TREE
)
2419 t
= build_min_array_type (elt_type
, index_type
);
2420 /* Mark dependency now, this saves time later. */
2421 TYPE_DEPENDENT_P_VALID (t
) = true;
2422 TYPE_DEPENDENT_P (t
) = dependent
;
2423 set_array_type_canon (t
, elt_type
, index_type
, dependent
);
2427 /* Make sure sizes are shared with the main variant.
2428 layout_type can't be called after setting TYPE_NEXT_VARIANT,
2429 as it will overwrite alignment etc. of all variants. */
2430 TYPE_SIZE (t
) = TYPE_SIZE (m
);
2431 TYPE_SIZE_UNIT (t
) = TYPE_SIZE_UNIT (m
);
2432 TYPE_TYPELESS_STORAGE (t
) = TYPE_TYPELESS_STORAGE (m
);
2435 TYPE_MAIN_VARIANT (t
) = m
;
2436 TYPE_NEXT_VARIANT (t
) = TYPE_NEXT_VARIANT (m
);
2437 TYPE_NEXT_VARIANT (m
) = t
;
2441 /* Avoid spurious warnings with VLAs (c++/54583). */
2442 if (TYPE_SIZE (t
) && EXPR_P (TYPE_SIZE (t
)))
2443 suppress_warning (TYPE_SIZE (t
), OPT_Wunused
);
2445 /* Push these needs up to the ARRAY_TYPE so that initialization takes
2446 place more easily. */
2448 = (TYPE_NEEDS_CONSTRUCTING (t
) = TYPE_NEEDS_CONSTRUCTING (elt_type
));
2449 bool needs_dtor
= (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t
)
2450 = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (elt_type
));
2452 if (!dependent
&& t
== TYPE_MAIN_VARIANT (t
) && !COMPLETE_TYPE_P (t
)
2453 && COMPLETE_TYPE_P (elt_type
))
2455 /* The element type has been completed since the last time we saw
2456 this array type; update the layout and 'tor flags for any variants
2459 for (tree v
= TYPE_NEXT_VARIANT (t
); v
; v
= TYPE_NEXT_VARIANT (v
))
2461 TYPE_NEEDS_CONSTRUCTING (v
) = needs_ctor
;
2462 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (v
) = needs_dtor
;
2469 // forked from gcc/cp/tree.cc cp_build_qualified_type_real
2471 /* Make a variant of TYPE, qualified with the TYPE_QUALS. Handles
2472 arrays correctly. In particular, if TYPE is an array of T's, and
2473 TYPE_QUALS is non-empty, returns an array of qualified T's.
2475 FLAGS determines how to deal with ill-formed qualifications. If
2476 tf_ignore_bad_quals is set, then bad qualifications are dropped
2477 (this is permitted if TYPE was introduced via a typedef or template
2478 type parameter). If bad qualifications are dropped and tf_warning
2479 is set, then a warning is issued for non-const qualifications. If
2480 tf_ignore_bad_quals is not set and tf_error is not set, we
2481 return error_mark_node. Otherwise, we issue an error, and ignore
2484 Qualification of a reference type is valid when the reference came
2485 via a typedef or template type argument. [dcl.ref] No such
2486 dispensation is provided for qualifying a function type. [dcl.fct]
2487 DR 295 queries this and the proposed resolution brings it into line
2488 with qualifying a reference. We implement the DR. We also behave
2489 in a similar manner for restricting non-pointer types. */
2492 rs_build_qualified_type_real (tree type
, int type_quals
,
2493 tsubst_flags_t complain
)
2496 int bad_quals
= TYPE_UNQUALIFIED
;
2498 if (type
== error_mark_node
)
2501 if (type_quals
== rs_type_quals (type
))
2504 if (TREE_CODE (type
) == ARRAY_TYPE
)
2506 /* In C++, the qualification really applies to the array element
2507 type. Obtain the appropriately qualified element type. */
2510 = rs_build_qualified_type_real (TREE_TYPE (type
), type_quals
, complain
);
2512 if (element_type
== error_mark_node
)
2513 return error_mark_node
;
2515 /* See if we already have an identically qualified type. Tests
2516 should be equivalent to those in check_qualified_type. */
2517 for (t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
2518 if (TREE_TYPE (t
) == element_type
&& TYPE_NAME (t
) == TYPE_NAME (type
)
2519 && TYPE_CONTEXT (t
) == TYPE_CONTEXT (type
)
2520 && attribute_list_equal (TYPE_ATTRIBUTES (t
),
2521 TYPE_ATTRIBUTES (type
)))
2526 /* If we already know the dependentness, tell the array type
2527 constructor. This is important for module streaming, as we cannot
2528 dynamically determine that on read in. */
2529 t
= build_cplus_array_type (element_type
, TYPE_DOMAIN (type
),
2530 TYPE_DEPENDENT_P_VALID (type
)
2531 ? int (TYPE_DEPENDENT_P (type
))
2534 /* Keep the typedef name. */
2535 if (TYPE_NAME (t
) != TYPE_NAME (type
))
2537 t
= build_variant_type_copy (t
);
2538 TYPE_NAME (t
) = TYPE_NAME (type
);
2539 SET_TYPE_ALIGN (t
, TYPE_ALIGN (type
));
2540 TYPE_USER_ALIGN (t
) = TYPE_USER_ALIGN (type
);
2544 /* Even if we already had this variant, we update
2545 TYPE_NEEDS_CONSTRUCTING and TYPE_HAS_NONTRIVIAL_DESTRUCTOR in case
2546 they changed since the variant was originally created.
2548 This seems hokey; if there is some way to use a previous
2549 variant *without* coming through here,
2550 TYPE_NEEDS_CONSTRUCTING will never be updated. */
2551 TYPE_NEEDS_CONSTRUCTING (t
)
2552 = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (element_type
));
2553 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t
)
2554 = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (element_type
));
2558 /* A reference or method type shall not be cv-qualified.
2559 [dcl.ref], [dcl.fct]. This used to be an error, but as of DR 295
2560 (in CD1) we always ignore extra cv-quals on functions. */
2562 /* [dcl.ref/1] Cv-qualified references are ill-formed except when
2563 the cv-qualifiers are introduced through the use of a typedef-name
2564 ([dcl.typedef], [temp.param]) or decltype-specifier
2565 ([dcl.type.decltype]),in which case the cv-qualifiers are
2567 if (type_quals
& (TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
)
2568 && (TYPE_REF_P (type
) || FUNC_OR_METHOD_TYPE_P (type
)))
2570 if (TYPE_REF_P (type
)
2571 && (!typedef_variant_p (type
) || FUNC_OR_METHOD_TYPE_P (type
)))
2572 bad_quals
|= type_quals
& (TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
);
2573 type_quals
&= ~(TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
);
2576 /* But preserve any function-cv-quals on a FUNCTION_TYPE. */
2577 if (TREE_CODE (type
) == FUNCTION_TYPE
)
2578 type_quals
|= type_memfn_quals (type
);
2580 /* A restrict-qualified type must be a pointer (or reference)
2581 to object or incomplete type. */
2582 if ((type_quals
& TYPE_QUAL_RESTRICT
) && TREE_CODE (type
) != TYPENAME_TYPE
2583 && !INDIRECT_TYPE_P (type
))
2585 bad_quals
|= TYPE_QUAL_RESTRICT
;
2586 type_quals
&= ~TYPE_QUAL_RESTRICT
;
2589 if (bad_quals
== TYPE_UNQUALIFIED
|| (complain
& tf_ignore_bad_quals
))
2591 else if (!(complain
& tf_error
))
2592 return error_mark_node
;
2595 tree bad_type
= build_qualified_type (ptr_type_node
, bad_quals
);
2596 error ("%qV qualifiers cannot be applied to %qT", bad_type
, type
);
2599 /* Retrieve (or create) the appropriately qualified variant. */
2600 result
= build_qualified_type (type
, type_quals
);
2605 // forked from gcc/cp/c-common.cc vector_targets_convertible_p
2607 /* vector_targets_convertible_p is used for vector pointer types. The
2608 callers perform various checks that the qualifiers are satisfactory,
2609 while OTOH vector_targets_convertible_p ignores the number of elements
2610 in the vectors. That's fine with vector pointers as we can consider,
2611 say, a vector of 8 elements as two consecutive vectors of 4 elements,
2612 and that does not require and conversion of the pointer values.
2613 In contrast, vector_types_convertible_p and
2614 vector_types_compatible_elements_p are used for vector value types. */
2615 /* True if pointers to distinct types T1 and T2 can be converted to
2616 each other without an explicit cast. Only returns true for opaque
2619 vector_targets_convertible_p (const_tree t1
, const_tree t2
)
2621 if (VECTOR_TYPE_P (t1
) && VECTOR_TYPE_P (t2
)
2622 && (TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
))
2623 && tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
)))
2629 // forked from gcc/cp/typeck.cc comp_array_types
2631 /* Compare the array types T1 and T2. CB says how we should behave when
2632 comparing array bounds: bounds_none doesn't allow dimensionless arrays,
2633 bounds_either says than any array can be [], bounds_first means that
2634 onlt T1 can be an array with unknown bounds. STRICT is true if
2635 qualifiers must match when comparing the types of the array elements. */
2638 comp_array_types (const_tree t1
, const_tree t2
, compare_bounds_t cb
,
2648 /* The type of the array elements must be the same. */
2649 if (strict
? !same_type_p (TREE_TYPE (t1
), TREE_TYPE (t2
))
2650 : !similar_type_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
2653 d1
= TYPE_DOMAIN (t1
);
2654 d2
= TYPE_DOMAIN (t2
);
2659 /* If one of the arrays is dimensionless, and the other has a
2660 dimension, they are of different types. However, it is valid to
2668 declarations for an array object can specify
2669 array types that differ by the presence or absence of a major
2670 array bound (_dcl.array_). */
2672 return cb
>= bounds_either
;
2674 return cb
== bounds_either
;
2676 /* Check that the dimensions are the same. */
2678 if (!rs_tree_equal (TYPE_MIN_VALUE (d1
), TYPE_MIN_VALUE (d2
)))
2680 max1
= TYPE_MAX_VALUE (d1
);
2681 max2
= TYPE_MAX_VALUE (d2
);
2683 if (!rs_tree_equal (max1
, max2
))
2689 // forked from gcc/cp/typeck.cc same_type_ignoring_top_level_qualifiers_p
2691 /* Returns nonzero iff TYPE1 and TYPE2 are the same type, ignoring
2692 top-level qualifiers. */
2695 same_type_ignoring_top_level_qualifiers_p (tree type1
, tree type2
)
2697 if (type1
== error_mark_node
|| type2
== error_mark_node
)
2702 type1
= rs_build_qualified_type (type1
, TYPE_UNQUALIFIED
);
2703 type2
= rs_build_qualified_type (type2
, TYPE_UNQUALIFIED
);
2704 return same_type_p (type1
, type2
);
2707 // forked from gcc/cp/typeck.cc comp_ptr_ttypes_const
2709 /* Return true if TO and FROM (both of which are POINTER_TYPEs or
2710 pointer-to-member types) are the same, ignoring cv-qualification at
2711 all levels. CB says how we should behave when comparing array bounds. */
2714 comp_ptr_ttypes_const (tree to
, tree from
, compare_bounds_t cb
)
2716 bool is_opaque_pointer
= false;
2718 for (;; to
= TREE_TYPE (to
), from
= TREE_TYPE (from
))
2720 if (TREE_CODE (to
) != TREE_CODE (from
))
2723 if (TREE_CODE (from
) == OFFSET_TYPE
2724 && same_type_p (TYPE_OFFSET_BASETYPE (from
),
2725 TYPE_OFFSET_BASETYPE (to
)))
2728 if (VECTOR_TYPE_P (to
))
2729 is_opaque_pointer
= vector_targets_convertible_p (to
, from
);
2731 if (TREE_CODE (to
) == ARRAY_TYPE
2732 /* Ignore cv-qualification, but if we see e.g. int[3] and int[4],
2734 && !comp_array_types (to
, from
, cb
, /*strict=*/false))
2737 /* CWG 330 says we need to look through arrays. */
2738 if (!TYPE_PTR_P (to
) && TREE_CODE (to
) != ARRAY_TYPE
)
2739 return (is_opaque_pointer
2740 || same_type_ignoring_top_level_qualifiers_p (to
, from
));
2744 // forked from gcc/cp/typeck.cc similar_type_p
2746 /* Returns nonzero iff TYPE1 and TYPE2 are similar, as per [conv.qual]. */
2749 similar_type_p (tree type1
, tree type2
)
2751 if (type1
== error_mark_node
|| type2
== error_mark_node
)
2754 /* Informally, two types are similar if, ignoring top-level cv-qualification:
2755 * they are the same type; or
2756 * they are both pointers, and the pointed-to types are similar; or
2757 * they are both pointers to member of the same class, and the types of
2758 the pointed-to members are similar; or
2759 * they are both arrays of the same size or both arrays of unknown bound,
2760 and the array element types are similar. */
2762 if (same_type_ignoring_top_level_qualifiers_p (type1
, type2
))
2765 if ((TYPE_PTR_P (type1
) && TYPE_PTR_P (type2
))
2766 || (TYPE_PTRDATAMEM_P (type1
) && TYPE_PTRDATAMEM_P (type2
))
2767 || (TREE_CODE (type1
) == ARRAY_TYPE
&& TREE_CODE (type2
) == ARRAY_TYPE
))
2768 return comp_ptr_ttypes_const (type1
, type2
, bounds_either
);
2773 // forked from gcc/cp/typeck.cc structural_comptypes
2774 // note: this fork only handles strict == COMPARE_STRICT
2775 // if you pass in any other value for strict i.e. COMPARE_BASE,
2776 // COMPARE_DERIVED, COMPARE_REDECLARATION or COMPARE_STRUCTURAL
2777 // see the original function in gcc/cp/typeck.cc and port the required bits
2778 // specifically under case UNION_TYPE.
2780 /* Subroutine in comptypes. */
2783 structural_comptypes (tree t1
, tree t2
, int strict
)
2785 /* Both should be types that are not obviously the same. */
2786 gcc_checking_assert (t1
!= t2
&& TYPE_P (t1
) && TYPE_P (t2
));
2788 if (TYPE_PTRMEMFUNC_P (t1
))
2789 t1
= TYPE_PTRMEMFUNC_FN_TYPE (t1
);
2790 if (TYPE_PTRMEMFUNC_P (t2
))
2791 t2
= TYPE_PTRMEMFUNC_FN_TYPE (t2
);
2793 /* Different classes of types can't be compatible. */
2794 if (TREE_CODE (t1
) != TREE_CODE (t2
))
2797 /* Qualifiers must match. For array types, we will check when we
2798 recur on the array element types. */
2799 if (TREE_CODE (t1
) != ARRAY_TYPE
&& rs_type_quals (t1
) != rs_type_quals (t2
))
2801 if (TREE_CODE (t1
) == FUNCTION_TYPE
2802 && type_memfn_quals (t1
) != type_memfn_quals (t2
))
2804 /* Need to check this before TYPE_MAIN_VARIANT.
2805 FIXME function qualifiers should really change the main variant. */
2806 if (FUNC_OR_METHOD_TYPE_P (t1
))
2808 if (type_memfn_rqual (t1
) != type_memfn_rqual (t2
))
2810 if (/* cxx_dialect >= cxx17 && */
2811 !comp_except_specs (TYPE_RAISES_EXCEPTIONS (t1
),
2812 TYPE_RAISES_EXCEPTIONS (t2
), ce_type
))
2816 /* Allow for two different type nodes which have essentially the same
2817 definition. Note that we already checked for equality of the type
2818 qualifiers (just above). */
2819 if (TREE_CODE (t1
) != ARRAY_TYPE
2820 && TYPE_MAIN_VARIANT (t1
) == TYPE_MAIN_VARIANT (t2
))
2823 /* Compare the types. Return false on known not-same. Break on not
2824 known. Never return true from this switch -- you'll break
2825 specialization comparison. */
2826 switch (TREE_CODE (t1
))
2830 /* All void and bool types are the same. */
2835 case FIXED_POINT_TYPE
:
2837 /* With these nodes, we can't determine type equivalence by
2838 looking at what is stored in the nodes themselves, because
2839 two nodes might have different TYPE_MAIN_VARIANTs but still
2840 represent the same type. For example, wchar_t and int could
2841 have the same properties (TYPE_PRECISION, TYPE_MIN_VALUE,
2842 TYPE_MAX_VALUE, etc.), but have different TYPE_MAIN_VARIANTs
2843 and are distinct types. On the other hand, int and the
2846 typedef int INT __attribute((may_alias));
2848 have identical properties, different TYPE_MAIN_VARIANTs, but
2849 represent the same type. The canonical type system keeps
2850 track of equivalence in this case, so we fall back on it. */
2851 if (TYPE_CANONICAL (t1
) != TYPE_CANONICAL (t2
))
2854 /* We don't need or want the attribute comparison. */
2862 if (!comptypes (TYPE_OFFSET_BASETYPE (t1
), TYPE_OFFSET_BASETYPE (t2
),
2863 strict
& ~COMPARE_REDECLARATION
))
2865 if (!same_type_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
2869 case REFERENCE_TYPE
:
2870 if (TYPE_REF_IS_RVALUE (t1
) != TYPE_REF_IS_RVALUE (t2
))
2872 /* fall through to checks for pointer types */
2876 if (TYPE_MODE (t1
) != TYPE_MODE (t2
)
2877 || !same_type_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
2883 /* Exception specs and memfn_rquals were checked above. */
2884 if (!same_type_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
2886 if (!compparms (TYPE_ARG_TYPES (t1
), TYPE_ARG_TYPES (t2
)))
2891 /* Target types must match incl. qualifiers. */
2892 if (!comp_array_types (t1
, t2
,
2893 ((strict
& COMPARE_REDECLARATION
) ? bounds_either
2900 if (!same_type_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
2905 if (gnu_vector_type_p (t1
) != gnu_vector_type_p (t2
)
2906 || maybe_ne (TYPE_VECTOR_SUBPARTS (t1
), TYPE_VECTOR_SUBPARTS (t2
))
2907 || !same_type_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
2915 /* If we get here, we know that from a target independent POV the
2916 types are the same. Make sure the target attributes are also
2918 if (!comp_type_attributes (t1
, t2
))
2924 // forked from gcc/cp/typeck.cc comptypes
2926 /* Return true if T1 and T2 are related as allowed by STRICT. STRICT
2927 is a bitwise-or of the COMPARE_* flags. */
2930 comptypes (tree t1
, tree t2
, int strict
)
2932 gcc_checking_assert (t1
&& t2
);
2934 /* TYPE_ARGUMENT_PACKS are not really types. */
2935 gcc_checking_assert (TREE_CODE (t1
) != TYPE_ARGUMENT_PACK
2936 && TREE_CODE (t2
) != TYPE_ARGUMENT_PACK
);
2941 /* Suppress errors caused by previously reported errors. */
2942 if (t1
== error_mark_node
|| t2
== error_mark_node
)
2945 if (strict
== COMPARE_STRICT
)
2947 if (TYPE_STRUCTURAL_EQUALITY_P (t1
) || TYPE_STRUCTURAL_EQUALITY_P (t2
))
2948 /* At least one of the types requires structural equality, so
2949 perform a deep check. */
2950 return structural_comptypes (t1
, t2
, strict
);
2953 return TYPE_CANONICAL (t1
) == TYPE_CANONICAL (t2
);
2955 return structural_comptypes (t1
, t2
, strict
);
2957 else if (strict
== COMPARE_STRUCTURAL
)
2958 return structural_comptypes (t1
, t2
, COMPARE_STRICT
);
2960 return structural_comptypes (t1
, t2
, strict
);
2963 // forked from gcc/cp/decl.cc next_initializable_field
2965 /* FIELD is an element of TYPE_FIELDS or NULL. In the former case, the value
2966 returned is the next FIELD_DECL (possibly FIELD itself) that can be
2967 initialized. If there are no more such fields, the return value
2971 next_initializable_field (tree field
)
2974 && (TREE_CODE (field
) != FIELD_DECL
|| DECL_UNNAMED_BIT_FIELD (field
)
2975 || (DECL_ARTIFICIAL (field
)
2976 /* Don't skip vptr fields. We might see them when we're
2977 called from reduced_constant_expression_p. */
2978 && !DECL_VIRTUAL_P (field
))))
2979 field
= DECL_CHAIN (field
);
2984 // forked from gcc/cp/call.cc sufficient_parms_p
2986 /* Returns nonzero if PARMLIST consists of only default parms,
2987 ellipsis, and/or undeduced parameter packs. */
2990 sufficient_parms_p (const_tree parmlist
)
2992 for (; parmlist
&& parmlist
!= void_list_node
;
2993 parmlist
= TREE_CHAIN (parmlist
))
2994 if (!TREE_PURPOSE (parmlist
))
2999 // forked from gcc/cp/class.cc default_ctor_p
3001 /* Returns true if FN is a default constructor. */
3004 default_ctor_p (const_tree fn
)
3006 return (DECL_CONSTRUCTOR_P (fn
)
3007 && sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (fn
)));
3010 // forked from gcc/cp/class.cc user_provided_p
3012 /* Returns true iff FN is a user-provided function, i.e. user-declared
3013 and not defaulted at its first declaration. */
3016 user_provided_p (tree fn
)
3018 return (!DECL_ARTIFICIAL (fn
)
3019 && !(DECL_INITIALIZED_IN_CLASS_P (fn
)
3020 && (DECL_DEFAULTED_FN (fn
) || DECL_DELETED_FN (fn
))));
3023 // forked from gcc/cp/class.cc type_has_non_user_provided_default_constructor
3025 /* Returns true iff class T has a non-user-provided (i.e. implicitly
3026 declared or explicitly defaulted in the class body) default
3030 type_has_non_user_provided_default_constructor (tree t
)
3032 if (!TYPE_HAS_DEFAULT_CONSTRUCTOR (t
))
3034 if (CLASSTYPE_LAZY_DEFAULT_CTOR (t
))
3037 for (ovl_iterator
iter (CLASSTYPE_CONSTRUCTORS (t
)); iter
; ++iter
)
3040 if (TREE_CODE (fn
) == FUNCTION_DECL
&& default_ctor_p (fn
)
3041 && !user_provided_p (fn
))
3048 // forked from gcc/cp/class.cc default_init_uninitialized_part
3050 /* If default-initialization leaves part of TYPE uninitialized, returns
3051 a DECL for the field or TYPE itself (DR 253). */
3054 default_init_uninitialized_part (tree type
)
3059 type
= strip_array_types (type
);
3060 if (!CLASS_TYPE_P (type
))
3062 if (!type_has_non_user_provided_default_constructor (type
))
3064 for (binfo
= TYPE_BINFO (type
), i
= 0; BINFO_BASE_ITERATE (binfo
, i
, t
); ++i
)
3066 r
= default_init_uninitialized_part (BINFO_TYPE (t
));
3070 for (t
= next_initializable_field (TYPE_FIELDS (type
)); t
;
3071 t
= next_initializable_field (DECL_CHAIN (t
)))
3072 if (!DECL_INITIAL (t
) && !DECL_ARTIFICIAL (t
))
3074 r
= default_init_uninitialized_part (TREE_TYPE (t
));
3076 return DECL_P (r
) ? r
: t
;
3082 // forked from gcc/cp/name-lookup.cc extract_conversion_operator
3084 /* FNS is an overload set of conversion functions. Return the
3085 overloads converting to TYPE. */
3088 extract_conversion_operator (tree fns
, tree type
)
3090 tree convs
= NULL_TREE
;
3091 tree tpls
= NULL_TREE
;
3093 for (ovl_iterator
iter (fns
); iter
; ++iter
)
3095 if (same_type_p (DECL_CONV_FN_TYPE (*iter
), type
))
3096 convs
= lookup_add (*iter
, convs
);
3105 // forked from gcc/cp/name-lookup.cc
3107 /* Look for NAME as an immediate member of KLASS (including
3108 anon-members or unscoped enum member). TYPE_OR_FNS is zero for
3109 regular search. >0 to get a type binding (if there is one) and <0
3110 if you want (just) the member function binding.
3112 Use this if you do not want lazy member creation. */
3115 get_class_binding_direct (tree klass
, tree name
, bool want_type
)
3117 gcc_checking_assert (RECORD_OR_UNION_TYPE_P (klass
));
3119 /* Conversion operators can only be found by the marker conversion
3121 bool conv_op
= IDENTIFIER_CONV_OP_P (name
);
3122 tree lookup
= conv_op
? conv_op_identifier
: name
;
3123 tree val
= NULL_TREE
;
3124 vec
<tree
, va_gc
> *member_vec
= CLASSTYPE_MEMBER_VEC (klass
);
3126 if (COMPLETE_TYPE_P (klass
) && member_vec
)
3128 val
= member_vec_binary_search (member_vec
, lookup
);
3131 else if (STAT_HACK_P (val
))
3132 val
= want_type
? STAT_TYPE (val
) : STAT_DECL (val
);
3133 else if (want_type
&& !DECL_DECLARES_TYPE_P (val
))
3138 if (member_vec
&& !want_type
)
3139 val
= member_vec_linear_search (member_vec
, lookup
);
3141 if (!val
|| (TREE_CODE (val
) == OVERLOAD
&& OVL_DEDUP_P (val
)))
3142 /* Dependent using declarations are a 'field', make sure we
3143 return that even if we saw an overload already. */
3144 if (tree field_val
= fields_linear_search (klass
, lookup
, want_type
))
3148 else if (TREE_CODE (field_val
) == USING_DECL
)
3149 val
= ovl_make (field_val
, val
);
3153 /* Extract the conversion operators asked for, unless the general
3154 conversion operator was requested. */
3157 gcc_checking_assert (OVL_FUNCTION (val
) == conv_op_marker
);
3158 val
= OVL_CHAIN (val
);
3159 if (tree type
= TREE_TYPE (name
))
3160 val
= extract_conversion_operator (val
, type
);
3166 #if defined ENABLE_TREE_CHECKING
3168 // forked from gcc/cp/tree.cc lang_check_failed
3170 /* Complain that some language-specific thing hanging off a tree
3171 node has been accessed improperly. */
3174 lang_check_failed (const char *file
, int line
, const char *function
)
3176 internal_error ("%<lang_*%> check: failed in %s, at %s:%d", function
,
3177 trim_filename (file
), line
);
3179 #endif /* ENABLE_TREE_CHECKING */
3181 // forked from gcc/cp/tree.cc skip_artificial_parms_for
3183 /* Given a FUNCTION_DECL FN and a chain LIST, skip as many elements of LIST
3184 as there are artificial parms in FN. */
3187 skip_artificial_parms_for (const_tree fn
, tree list
)
3189 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn
))
3190 list
= TREE_CHAIN (list
);
3194 if (DECL_HAS_IN_CHARGE_PARM_P (fn
))
3195 list
= TREE_CHAIN (list
);
3196 if (DECL_HAS_VTT_PARM_P (fn
))
3197 list
= TREE_CHAIN (list
);
3201 // forked from gcc/cp/class.cc in_class_defaulted_default_constructor
3203 /* Returns the defaulted constructor if T has one. Otherwise, returns
3207 in_class_defaulted_default_constructor (tree t
)
3209 if (!TYPE_HAS_USER_CONSTRUCTOR (t
))
3212 for (ovl_iterator
iter (CLASSTYPE_CONSTRUCTORS (t
)); iter
; ++iter
)
3216 if (DECL_DEFAULTED_IN_CLASS_P (fn
) && default_ctor_p (fn
))
3223 // forked from gcc/cp/constexpr.cc
3225 /* Returns true iff FUN is an instantiation of a constexpr function
3226 template or a defaulted constexpr function. */
3229 is_instantiation_of_constexpr (tree fun
)
3231 return ((DECL_DEFAULTED_FN (fun
) && DECL_DECLARED_CONSTEXPR_P (fun
)));
3234 // forked from gcc/cp/decl.cc check_for_uninitialized_const_var
3236 /* Issue an error message if DECL is an uninitialized const variable.
3237 CONSTEXPR_CONTEXT_P is true when the function is called in a constexpr
3238 context from potential_constant_expression. Returns true if all is well,
3242 check_for_uninitialized_const_var (tree decl
, bool constexpr_context_p
,
3243 tsubst_flags_t complain
)
3245 tree type
= strip_array_types (TREE_TYPE (decl
));
3247 /* ``Unless explicitly declared extern, a const object does not have
3248 external linkage and must be initialized. ($8.4; $12.1)'' ARM
3250 if (VAR_P (decl
) && !TYPE_REF_P (type
) && (RS_TYPE_CONST_P (type
))
3251 && !DECL_NONTRIVIALLY_INITIALIZED_P (decl
))
3253 tree field
= default_init_uninitialized_part (type
);
3257 bool show_notes
= true;
3259 if (!constexpr_context_p
)
3261 if (RS_TYPE_CONST_P (type
))
3263 if (complain
& tf_error
)
3264 show_notes
= permerror (DECL_SOURCE_LOCATION (decl
),
3265 "uninitialized %<const %D%>", decl
);
3269 if (!is_instantiation_of_constexpr (current_function_decl
)
3270 && (complain
& tf_error
))
3271 error_at (DECL_SOURCE_LOCATION (decl
),
3272 "uninitialized variable %qD in %<constexpr%> "
3279 else if (complain
& tf_error
)
3280 error_at (DECL_SOURCE_LOCATION (decl
),
3281 "uninitialized variable %qD in %<constexpr%> context", decl
);
3283 if (show_notes
&& CLASS_TYPE_P (type
) && (complain
& tf_error
))
3285 // tree defaulted_ctor;
3287 // inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type)),
3288 // "%q#T has no user-provided default constructor", type);
3289 // defaulted_ctor = in_class_defaulted_default_constructor (type);
3290 // if (defaulted_ctor)
3291 // inform (DECL_SOURCE_LOCATION (defaulted_ctor),
3292 // "constructor is not user-provided because it is "
3293 // "explicitly defaulted in the class body");
3294 // inform (DECL_SOURCE_LOCATION (field),
3295 // "and the implicitly-defined constructor does not "
3296 // "initialize %q#D",
3306 // forked from gcc/cp/tree.cc cv_unqualified
3308 /* Return TYPE with const and volatile removed. */
3311 cv_unqualified (tree type
)
3315 if (type
== error_mark_node
)
3318 quals
= rs_type_quals (type
);
3319 quals
&= ~(TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
);
3320 return rs_build_qualified_type (type
, quals
);
3323 /* The C and C++ parsers both use vectors to hold function arguments.
3324 For efficiency, we keep a cache of unused vectors. This is the
3327 typedef vec
<tree
, va_gc
> *tree_gc_vec
;
3328 static GTY ((deletable
)) vec
<tree_gc_vec
, va_gc
> *tree_vector_cache
;
3330 // forked from gcc/c-family/c-common.c make_tree_vector
3332 /* Return a new vector from the cache. If the cache is empty,
3333 allocate a new vector. These vectors are GC'ed, so it is OK if the
3334 pointer is not released.. */
3337 make_tree_vector (void)
3339 if (tree_vector_cache
&& !tree_vector_cache
->is_empty ())
3340 return tree_vector_cache
->pop ();
3343 /* Passing 0 to vec::alloc returns NULL, and our callers require
3344 that we always return a non-NULL value. The vector code uses
3345 4 when growing a NULL vector, so we do too. */
3346 vec
<tree
, va_gc
> *v
;
3352 // forked from gcc/c-family/c-common.c release_tree_vector
3354 /* Release a vector of trees back to the cache. */
3357 release_tree_vector (vec
<tree
, va_gc
> *vec
)
3361 if (vec
->allocated () >= 16)
3362 /* Don't cache vecs that have expanded more than once. On a p64
3363 target, vecs double in alloc size with each power of 2 elements, e.g
3364 at 16 elements the alloc increases from 128 to 256 bytes. */
3369 vec_safe_push (tree_vector_cache
, vec
);
3374 // forked from gcc/cp/cvt.cc instantiation_dependent_expression_p
3376 /* As above, but also check value-dependence of the expression as a whole. */
3378 bool instantiation_dependent_expression_p (tree
) { return false; }
3380 // forked from gcc/cp/cvt.cc cp_get_callee
3382 /* If CALL is a call, return the callee; otherwise null. */
3385 cp_get_callee (tree call
)
3387 if (call
== NULL_TREE
)
3389 else if (TREE_CODE (call
) == CALL_EXPR
)
3390 return CALL_EXPR_FN (call
);
3394 // forked from gcc/cp/typeck.cc build_nop
3396 /* Return a NOP_EXPR converting EXPR to TYPE. */
3399 build_nop (tree type
, tree expr
)
3401 if (type
== error_mark_node
|| error_operand_p (expr
))
3403 return build1_loc (EXPR_LOCATION (expr
), NOP_EXPR
, type
, expr
);
3406 // forked from gcc/cp/tree.cc scalarish_type_p
3408 /* Returns 1 iff type T is something we want to treat as a scalar type for
3409 the purpose of deciding whether it is trivial/POD/standard-layout. */
3412 scalarish_type_p (const_tree t
)
3414 if (t
== error_mark_node
)
3417 return (SCALAR_TYPE_P (t
) || VECTOR_TYPE_P (t
));
3420 // forked from gcc/cp/tree.cc type_has_nontrivial_copy_init
3422 /* Returns true iff copying an object of type T (including via move
3423 constructor) is non-trivial. That is, T has no non-trivial copy
3424 constructors and no non-trivial move constructors, and not all copy/move
3425 constructors are deleted. This function implements the ABI notion of
3426 non-trivial copy, which has diverged from the one in the standard. */
3428 bool type_has_nontrivial_copy_init (const_tree
) { return false; }
3430 // forked from gcc/cp/tree.cc build_local_temp
3432 /* Return an undeclared local temporary of type TYPE for use in building a
3436 build_local_temp (tree type
)
3438 tree slot
= build_decl (input_location
, VAR_DECL
, NULL_TREE
, type
);
3439 DECL_ARTIFICIAL (slot
) = 1;
3440 DECL_IGNORED_P (slot
) = 1;
3441 DECL_CONTEXT (slot
) = current_function_decl
;
3442 layout_decl (slot
, 0);
3446 // forked from gcc/cp/lambda.cc is_normal_capture_proxy
3448 /* Returns true iff DECL is a capture proxy for a normal capture
3449 (i.e. without explicit initializer). */
3451 bool is_normal_capture_proxy (tree
) { return false; }
3453 // forked from gcc/cp/c-common.cc reject_gcc_builtin
3455 /* For an EXPR of a FUNCTION_TYPE that references a GCC built-in function
3456 with no library fallback or for an ADDR_EXPR whose operand is such type
3457 issues an error pointing to the location LOC.
3458 Returns true when the expression has been diagnosed and false
3462 reject_gcc_builtin (const_tree expr
, location_t loc
/* = UNKNOWN_LOCATION */)
3464 if (TREE_CODE (expr
) == ADDR_EXPR
)
3465 expr
= TREE_OPERAND (expr
, 0);
3467 STRIP_ANY_LOCATION_WRAPPER (expr
);
3469 if (TREE_TYPE (expr
) && TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
3470 && TREE_CODE (expr
) == FUNCTION_DECL
3471 /* The intersection of DECL_BUILT_IN and DECL_IS_UNDECLARED_BUILTIN avoids
3472 false positives for user-declared built-ins such as abs or
3473 strlen, and for C++ operators new and delete.
3474 The c_decl_implicit() test avoids false positives for implicitly
3475 declared built-ins with library fallbacks (such as abs). */
3476 && fndecl_built_in_p (expr
) && DECL_IS_UNDECLARED_BUILTIN (expr
)
3477 && !DECL_ASSEMBLER_NAME_SET_P (expr
))
3479 if (loc
== UNKNOWN_LOCATION
)
3480 loc
= EXPR_LOC_OR_LOC (expr
, input_location
);
3482 /* Reject arguments that are built-in functions with
3483 no library fallback. */
3484 error_at (loc
, "built-in function %qE must be directly called", expr
);
3492 // forked from gcc/cp/typeck.cc is_bitfield_expr_with_lowered_type
3494 /* If EXP is a reference to a bit-field, and the type of EXP does not
3495 match the declared type of the bit-field, return the declared type
3496 of the bit-field. Otherwise, return NULL_TREE. */
3499 is_bitfield_expr_with_lowered_type (const_tree exp
)
3501 switch (TREE_CODE (exp
))
3504 if (!is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp
, 1)
3505 ? TREE_OPERAND (exp
, 1)
3506 : TREE_OPERAND (exp
, 0)))
3508 return is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp
, 2));
3511 return is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp
, 1));
3515 case UNARY_PLUS_EXPR
:
3516 case PREDECREMENT_EXPR
:
3517 case PREINCREMENT_EXPR
:
3518 case POSTDECREMENT_EXPR
:
3519 case POSTINCREMENT_EXPR
:
3521 case NON_LVALUE_EXPR
:
3523 return is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp
, 0));
3525 case COMPONENT_REF
: {
3528 field
= TREE_OPERAND (exp
, 1);
3529 if (TREE_CODE (field
) != FIELD_DECL
|| !DECL_BIT_FIELD_TYPE (field
))
3531 if (same_type_ignoring_top_level_qualifiers_p (
3532 TREE_TYPE (exp
), DECL_BIT_FIELD_TYPE (field
)))
3534 return DECL_BIT_FIELD_TYPE (field
);
3538 if (DECL_HAS_VALUE_EXPR_P (exp
))
3539 return is_bitfield_expr_with_lowered_type (
3540 DECL_VALUE_EXPR (CONST_CAST_TREE (exp
)));
3543 case VIEW_CONVERT_EXPR
:
3544 if (location_wrapper_p (exp
))
3545 return is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp
, 0));
3554 // forked from gcc/cp/semantics.cc maybe_undo_parenthesized_ref
3556 /* If T is an id-expression obfuscated by force_paren_expr, undo the
3557 obfuscation and return the underlying id-expression. Otherwise
3561 maybe_undo_parenthesized_ref (tree t
)
3563 if ((TREE_CODE (t
) == PAREN_EXPR
|| TREE_CODE (t
) == VIEW_CONVERT_EXPR
)
3564 && REF_PARENTHESIZED_P (t
))
3565 t
= TREE_OPERAND (t
, 0);
3570 // forked from gcc/c-family/c-common.cc fold_offsetof
3572 /* Fold an offsetof-like expression. EXPR is a nested sequence of component
3573 references with an INDIRECT_REF of a constant at the bottom; much like the
3574 traditional rendering of offsetof as a macro. TYPE is the desired type of
3575 the whole expression. Return the folded result. */
3578 fold_offsetof (tree expr
, tree type
, enum tree_code ctx
)
3581 tree_code code
= TREE_CODE (expr
);
3588 error ("cannot apply %<offsetof%> to static data member %qD", expr
);
3589 return error_mark_node
;
3593 error ("cannot apply %<offsetof%> when %<operator[]%> is overloaded");
3594 return error_mark_node
;
3598 if (!TREE_CONSTANT (TREE_OPERAND (expr
, 0)))
3600 error ("cannot apply %<offsetof%> to a non constant address");
3601 return error_mark_node
;
3603 return convert (type
, TREE_OPERAND (expr
, 0));
3606 base
= fold_offsetof (TREE_OPERAND (expr
, 0), type
, code
);
3607 if (base
== error_mark_node
)
3610 t
= TREE_OPERAND (expr
, 1);
3611 if (DECL_C_BIT_FIELD (t
))
3613 error ("attempt to take address of bit-field structure "
3616 return error_mark_node
;
3618 off
= size_binop_loc (input_location
, PLUS_EXPR
, DECL_FIELD_OFFSET (t
),
3619 size_int (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (t
))
3624 base
= fold_offsetof (TREE_OPERAND (expr
, 0), type
, code
);
3625 if (base
== error_mark_node
)
3628 t
= TREE_OPERAND (expr
, 1);
3629 STRIP_ANY_LOCATION_WRAPPER (t
);
3631 /* Check if the offset goes beyond the upper bound of the array. */
3632 if (TREE_CODE (t
) == INTEGER_CST
&& tree_int_cst_sgn (t
) >= 0)
3634 tree upbound
= array_ref_up_bound (expr
);
3635 if (upbound
!= NULL_TREE
&& TREE_CODE (upbound
) == INTEGER_CST
3636 && !tree_int_cst_equal (upbound
,
3637 TYPE_MAX_VALUE (TREE_TYPE (upbound
))))
3639 if (ctx
!= ARRAY_REF
&& ctx
!= COMPONENT_REF
)
3640 upbound
= size_binop (PLUS_EXPR
, upbound
,
3641 build_int_cst (TREE_TYPE (upbound
), 1));
3642 if (tree_int_cst_lt (upbound
, t
))
3646 for (v
= TREE_OPERAND (expr
, 0);
3647 TREE_CODE (v
) == COMPONENT_REF
; v
= TREE_OPERAND (v
, 0))
3648 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v
, 0)))
3651 tree fld_chain
= DECL_CHAIN (TREE_OPERAND (v
, 1));
3652 for (; fld_chain
; fld_chain
= DECL_CHAIN (fld_chain
))
3653 if (TREE_CODE (fld_chain
) == FIELD_DECL
)
3659 /* Don't warn if the array might be considered a poor
3660 man's flexible array member with a very permissive
3661 definition thereof. */
3662 if (TREE_CODE (v
) == ARRAY_REF
3663 || TREE_CODE (v
) == COMPONENT_REF
)
3664 warning (OPT_Warray_bounds_
,
3665 "index %E denotes an offset "
3666 "greater than size of %qT",
3667 t
, TREE_TYPE (TREE_OPERAND (expr
, 0)));
3672 t
= convert (sizetype
, t
);
3673 off
= size_binop (MULT_EXPR
, TYPE_SIZE_UNIT (TREE_TYPE (expr
)), t
);
3677 /* Handle static members of volatile structs. */
3678 t
= TREE_OPERAND (expr
, 1);
3679 gcc_checking_assert (VAR_P (get_base_address (t
)));
3680 return fold_offsetof (t
, type
);
3683 rust_unreachable ();
3686 if (!POINTER_TYPE_P (type
))
3687 return size_binop (PLUS_EXPR
, base
, convert (type
, off
));
3688 return fold_build_pointer_plus (base
, off
);
3691 // forked from gcc/cp/tree.cc char_type_p
3693 /* Returns nonzero if TYPE is a character type, including wchar_t. */
3696 char_type_p (tree type
)
3698 return (same_type_p (type
, char_type_node
)
3699 || same_type_p (type
, unsigned_char_type_node
)
3700 || same_type_p (type
, signed_char_type_node
)
3701 || same_type_p (type
, char8_type_node
)
3702 || same_type_p (type
, char16_type_node
)
3703 || same_type_p (type
, char32_type_node
)
3704 || same_type_p (type
, wchar_type_node
));
3707 // forked from gcc/cp/pt.cc resolve_nondeduced_context
3709 /* Core DR 115: In contexts where deduction is done and fails, or in
3710 contexts where deduction is not done, if a template argument list is
3711 specified and it, along with any default template arguments, identifies
3712 a single function template specialization, then the template-id is an
3713 lvalue for the function template specialization. */
3716 resolve_nondeduced_context (tree orig_expr
, tsubst_flags_t
)
3721 // forked from gcc/cp/pt.cc instantiate_non_dependent_or_null
3723 /* Like instantiate_non_dependent_expr, but return NULL_TREE rather than
3724 an uninstantiated expression. */
3727 instantiate_non_dependent_or_null (tree expr
)
3729 if (expr
== NULL_TREE
)
3735 // forked from gcc/cp/pt.cc resolve_nondeduced_context_or_error
3737 /* As above, but error out if the expression remains overloaded. */
3740 resolve_nondeduced_context_or_error (tree exp
, tsubst_flags_t complain
)
3742 exp
= resolve_nondeduced_context (exp
, complain
);
3743 if (type_unknown_p (exp
))
3745 if (complain
& tf_error
)
3746 cxx_incomplete_type_error (exp
, TREE_TYPE (exp
));
3747 return error_mark_node
;
3752 // forked from gcc/cp/tree.cc really_overloaded_fn
3754 /* Returns true iff X is an expression for an overloaded function
3755 whose type cannot be known without performing overload
3759 really_overloaded_fn (tree x
)
3761 return is_overloaded_fn (x
) == 2;
3764 // forked from gcc/cp/typeck..cc invalid_nonstatic_memfn_p
3766 /* EXPR is being used in a context that is not a function call.
3771 The expression can be used only as the left-hand operand of a
3772 member function call.
3774 [expr.mptr.operator]
3776 If the result of .* or ->* is a function, then that result can be
3777 used only as the operand for the function call operator ().
3779 by issuing an error message if appropriate. Returns true iff EXPR
3780 violates these rules. */
3783 invalid_nonstatic_memfn_p (location_t loc
, tree expr
, tsubst_flags_t complain
)
3785 if (expr
== NULL_TREE
)
3787 /* Don't enforce this in MS mode. */
3788 if (flag_ms_extensions
)
3790 if (is_overloaded_fn (expr
) && !really_overloaded_fn (expr
))
3791 expr
= get_first_fn (expr
);
3792 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (expr
))
3794 if (complain
& tf_error
)
3798 error_at (loc
, "invalid use of non-static member function %qD",
3800 inform (DECL_SOURCE_LOCATION (expr
), "declared here");
3804 "invalid use of non-static member function of "
3813 // forked from gcc/cp/call.cc strip_top_quals
3816 strip_top_quals (tree t
)
3818 if (TREE_CODE (t
) == ARRAY_TYPE
)
3820 return rs_build_qualified_type (t
, 0);
3823 // forked from gcc/cp/typeck2.cc cxx_incomplete_type_inform
3825 /* Print an inform about the declaration of the incomplete type TYPE. */
3828 // cxx_incomplete_type_inform (const_tree type)
3830 // if (!TYPE_MAIN_DECL (type))
3833 // location_t loc = DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type));
3834 // tree ptype = strip_top_quals (CONST_CAST_TREE (type));
3836 // if (current_class_type && TYPE_BEING_DEFINED (current_class_type)
3837 // && same_type_p (ptype, current_class_type))
3839 // "definition of %q#T is not complete until "
3840 // "the closing brace",
3843 // inform (loc, "forward declaration of %q#T", ptype);
3846 // forked from gcc/cp/typeck2.cc cxx_incomplete_type_diagnostic
3848 /* Print an error message for invalid use of an incomplete type.
3849 VALUE is the expression that was used (or 0 if that isn't known)
3850 and TYPE is the type that was invalid. DIAG_KIND indicates the
3851 type of diagnostic (see diagnostic.def). */
3854 cxx_incomplete_type_diagnostic (location_t loc
, const_tree value
,
3855 const_tree type
, diagnostic_t diag_kind
)
3857 // bool is_decl = false, complained = false;
3859 gcc_assert (diag_kind
== DK_WARNING
|| diag_kind
== DK_PEDWARN
3860 || diag_kind
== DK_ERROR
);
3862 /* Avoid duplicate error message. */
3863 if (TREE_CODE (type
) == ERROR_MARK
)
3868 STRIP_ANY_LOCATION_WRAPPER (value
);
3870 if (VAR_P (value
) || TREE_CODE (value
) == PARM_DECL
3871 || TREE_CODE (value
) == FIELD_DECL
)
3873 // complained = emit_diagnostic (diag_kind, DECL_SOURCE_LOCATION
3875 // 0, "%qD has incomplete type", value);
3880 /* We must print an error message. Be clever about what it says. */
3882 switch (TREE_CODE (type
))
3884 // case RECORD_TYPE:
3886 // case ENUMERAL_TYPE:
3889 // = emit_diagnostic (diag_kind, loc, 0,
3890 // "invalid use of incomplete type %q#T", type);
3892 // cxx_incomplete_type_inform (type);
3896 emit_diagnostic (diag_kind
, loc
, 0, "invalid use of %qT", type
);
3900 if (TYPE_DOMAIN (type
))
3902 type
= TREE_TYPE (type
);
3905 emit_diagnostic (diag_kind
, loc
, 0,
3906 "invalid use of array with unspecified bounds");
3911 tree member
= TREE_OPERAND (value
, 1);
3912 if (is_overloaded_fn (member
))
3913 member
= get_first_fn (member
);
3915 if (DECL_FUNCTION_MEMBER_P (member
) && !flag_ms_extensions
)
3917 gcc_rich_location
richloc (loc
);
3918 /* If "member" has no arguments (other than "this"), then
3919 add a fix-it hint. */
3920 if (type_num_arguments (TREE_TYPE (member
)) == 1)
3921 richloc
.add_fixit_insert_after ("()");
3922 emit_diagnostic (diag_kind
, &richloc
, 0,
3923 "invalid use of member function %qD "
3924 "(did you forget the %<()%> ?)",
3928 emit_diagnostic (diag_kind
, loc
, 0,
3929 "invalid use of member %qD "
3930 "(did you forget the %<&%> ?)",
3936 if (type
== init_list_type_node
)
3938 emit_diagnostic (diag_kind
, loc
, 0,
3939 "invalid use of brace-enclosed initializer list");
3942 gcc_assert (type
== unknown_type_node
);
3943 if (value
&& TREE_CODE (value
) == COMPONENT_REF
)
3945 else if (value
&& TREE_CODE (value
) == ADDR_EXPR
)
3946 emit_diagnostic (diag_kind
, loc
, 0,
3947 "address of overloaded function with no contextual "
3948 "type information");
3949 else if (value
&& TREE_CODE (value
) == OVERLOAD
)
3952 "overloaded function with no contextual type information");
3956 "insufficient contextual information to determine type");
3960 rust_unreachable ();
3964 // forked from gcc/cp/decl2.cc decl_constant_var_p
3966 /* Nonzero for a VAR_DECL whose value can be used in a constant expression.
3970 An integral constant-expression can only involve ... const
3971 variables of integral or enumeration types initialized with
3972 constant expressions ...
3974 C++0x also allows constexpr variables and temporaries initialized
3975 with constant expressions. We handle the former here, but the latter
3976 are just folded away in cxx_eval_constant_expression.
3978 The standard does not require that the expression be non-volatile.
3979 G++ implements the proposed correction in DR 457. */
3982 decl_constant_var_p (tree decl
)
3984 if (!decl_maybe_constant_var_p (decl
))
3987 return DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl
);
3990 // forked from gcc/cp/decl.cc undeduced_auto_decl
3992 /* Returns true iff DECL is a variable or function declared with an auto type
3993 that has not yet been deduced to a real type. */
3995 bool undeduced_auto_decl (tree
) { return false; }
3997 // forked from gcc/cp/decl.cc require_deduced_type
3999 /* Complain if DECL has an undeduced return type. */
4001 bool require_deduced_type (tree
, tsubst_flags_t
) { return true; }
4003 /* Return the location of a tree passed to %+ formats. */
4006 location_of (tree t
)
4010 t
= TYPE_MAIN_DECL (t
);
4012 return input_location
;
4014 else if (TREE_CODE (t
) == OVERLOAD
)
4018 return DECL_SOURCE_LOCATION (t
);
4020 return EXPR_LOCATION (t
);
4023 /* For element type ELT_TYPE, return the appropriate type of the heap object
4024 containing such element(s). COOKIE_SIZE is NULL or the size of cookie
4025 in bytes. FULL_SIZE is NULL if it is unknown how big the heap allocation
4026 will be, otherwise size of the heap object. If COOKIE_SIZE is NULL,
4027 return array type ELT_TYPE[FULL_SIZE / sizeof(ELT_TYPE)], otherwise return
4028 struct { size_t[COOKIE_SIZE/sizeof(size_t)]; ELT_TYPE[N]; }
4029 where N is nothing (flexible array member) if FULL_SIZE is NULL, otherwise
4030 it is computed such that the size of the struct fits into FULL_SIZE. */
4033 build_new_constexpr_heap_type (tree elt_type
, tree cookie_size
, tree full_size
)
4035 gcc_assert (cookie_size
== NULL_TREE
|| tree_fits_uhwi_p (cookie_size
));
4036 gcc_assert (full_size
== NULL_TREE
|| tree_fits_uhwi_p (full_size
));
4037 unsigned HOST_WIDE_INT csz
= cookie_size
? tree_to_uhwi (cookie_size
) : 0;
4038 tree itype2
= NULL_TREE
;
4041 unsigned HOST_WIDE_INT fsz
= tree_to_uhwi (full_size
);
4042 gcc_assert (fsz
>= csz
);
4044 fsz
/= int_size_in_bytes (elt_type
);
4045 itype2
= build_index_type (size_int (fsz
- 1));
4047 return build_cplus_array_type (elt_type
, itype2
);
4050 gcc_assert (cookie_size
);
4051 csz
/= int_size_in_bytes (sizetype
);
4052 tree itype1
= build_index_type (size_int (csz
- 1));
4053 tree atype1
= build_cplus_array_type (sizetype
, itype1
);
4054 tree atype2
= build_cplus_array_type (elt_type
, itype2
);
4055 tree rtype
= cxx_make_type (RECORD_TYPE
);
4056 TYPE_NAME (rtype
) = heap_identifier
;
4057 tree fld1
= build_decl (UNKNOWN_LOCATION
, FIELD_DECL
, NULL_TREE
, atype1
);
4058 tree fld2
= build_decl (UNKNOWN_LOCATION
, FIELD_DECL
, NULL_TREE
, atype2
);
4059 DECL_FIELD_CONTEXT (fld1
) = rtype
;
4060 DECL_FIELD_CONTEXT (fld2
) = rtype
;
4061 DECL_ARTIFICIAL (fld1
) = true;
4062 DECL_ARTIFICIAL (fld2
) = true;
4063 TYPE_FIELDS (rtype
) = fld1
;
4064 DECL_CHAIN (fld1
) = fld2
;
4065 layout_type (rtype
);
4069 // forked from gcc/cp/class.cc field_poverlapping_p
4071 /* Return true iff FIELD_DECL DECL is potentially overlapping. */
4074 field_poverlapping_p (tree decl
)
4076 return lookup_attribute ("no_unique_address", DECL_ATTRIBUTES (decl
));
4079 // forked from gcc/cp/class.cc is_empty_field
4081 /* Return true iff DECL is an empty field, either for an empty base or a
4082 [[no_unique_address]] data member. */
4085 is_empty_field (tree decl
)
4087 if (!decl
|| TREE_CODE (decl
) != FIELD_DECL
)
4090 bool r
= (is_empty_class (TREE_TYPE (decl
)) && (field_poverlapping_p (decl
)));
4092 /* Empty fields should have size zero. */
4093 gcc_checking_assert (!r
|| integer_zerop (DECL_SIZE (decl
)));
4098 // forked from gcc/cp/call.cc in_immediate_context
4100 /* Return true if in an immediate function context, or an unevaluated operand,
4101 or a subexpression of an immediate invocation. */
4104 in_immediate_context ()
4109 // forked from gcc/cp/cvt.cc cp_get_fndecl_from_callee
4111 /* FN is the callee of a CALL_EXPR or AGGR_INIT_EXPR; return the FUNCTION_DECL
4115 rs_get_fndecl_from_callee (tree fn
, bool fold
/* = true */)
4117 if (fn
== NULL_TREE
)
4119 if (TREE_CODE (fn
) == FUNCTION_DECL
)
4121 tree type
= TREE_TYPE (fn
);
4122 if (type
== NULL_TREE
|| !INDIRECT_TYPE_P (type
))
4125 fn
= Compile::maybe_constant_init (fn
);
4127 if (TREE_CODE (fn
) == ADDR_EXPR
|| TREE_CODE (fn
) == FDESC_EXPR
)
4128 fn
= TREE_OPERAND (fn
, 0);
4129 if (TREE_CODE (fn
) == FUNCTION_DECL
)
4134 // forked from gcc/cp/cvt.cc cp_get_callee_fndecl_nofold
4136 rs_get_callee_fndecl_nofold (tree call
)
4138 return rs_get_fndecl_from_callee (cp_get_callee (call
), false);
4141 // forked from gcc/cp/init.cc is_class_type
4143 /* Report an error if TYPE is not a user-defined, class type. If
4144 OR_ELSE is nonzero, give an error message. */
4147 is_class_type (tree type
, int or_else
)
4149 if (type
== error_mark_node
)
4152 if (!CLASS_TYPE_P (type
))
4155 error ("%qT is not a class type", type
);
4161 // forked from gcc/cp/decl.cc lookup_enumerator
4163 /* Look for an enumerator with the given NAME within the enumeration
4164 type ENUMTYPE. This routine is used primarily for qualified name
4165 lookup into an enumerator in C++0x, e.g.,
4167 enum class Color { Red, Green, Blue };
4169 Color color = Color::Red;
4171 Returns the value corresponding to the enumerator, or
4172 NULL_TREE if no such enumerator was found. */
4174 lookup_enumerator (tree enumtype
, tree name
)
4177 gcc_assert (enumtype
&& TREE_CODE (enumtype
) == ENUMERAL_TYPE
);
4179 e
= purpose_member (name
, TYPE_VALUES (enumtype
));
4180 return e
? TREE_VALUE (e
) : NULL_TREE
;
4183 // forked from gcc/cp/init.cc constant_value_1
4184 // commented out mark_used
4186 /* If DECL is a scalar enumeration constant or variable with a
4187 constant initializer, return the initializer (or, its initializers,
4188 recursively); otherwise, return DECL. If STRICT_P, the
4189 initializer is only returned if DECL is a
4190 constant-expression. If RETURN_AGGREGATE_CST_OK_P, it is ok to
4191 return an aggregate constant. If UNSHARE_P, return an unshared
4192 copy of the initializer. */
4195 constant_value_1 (tree decl
, bool strict_p
, bool return_aggregate_cst_ok_p
,
4198 while (TREE_CODE (decl
) == CONST_DECL
|| decl_constant_var_p (decl
)
4199 || (!strict_p
&& VAR_P (decl
)
4200 && RS_TYPE_CONST_NON_VOLATILE_P (TREE_TYPE (decl
))))
4203 /* If DECL is a static data member in a template
4204 specialization, we must instantiate it here. The
4205 initializer for the static data member is not processed
4206 until needed; we need it now. */
4207 // mark_used (decl, tf_none);
4208 init
= DECL_INITIAL (decl
);
4209 if (init
== error_mark_node
)
4211 if (TREE_CODE (decl
) == CONST_DECL
4212 || DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl
))
4213 /* Treat the error as a constant to avoid cascading errors on
4214 excessively recursive template instantiation (c++/9335). */
4220 /* Instantiate a non-dependent initializer for user variables. We
4221 mustn't do this for the temporary for an array compound literal;
4222 trying to instatiate the initializer will keep creating new
4223 temporaries until we crash. Probably it's not useful to do it for
4224 other artificial variables, either. */
4225 if (!DECL_ARTIFICIAL (decl
))
4226 init
= instantiate_non_dependent_or_null (init
);
4227 if (!init
|| !TREE_TYPE (init
) || !TREE_CONSTANT (init
)
4228 || (!return_aggregate_cst_ok_p
4229 /* Unless RETURN_AGGREGATE_CST_OK_P is true, do not
4230 return an aggregate constant (of which string
4231 literals are a special case), as we do not want
4232 to make inadvertent copies of such entities, and
4233 we must be sure that their addresses are the
4235 && (TREE_CODE (init
) == CONSTRUCTOR
4236 || TREE_CODE (init
) == STRING_CST
)))
4238 /* Don't return a CONSTRUCTOR for a variable with partial run-time
4239 initialization, since it doesn't represent the entire value.
4240 Similarly for VECTOR_CSTs created by cp_folding those
4242 if ((TREE_CODE (init
) == CONSTRUCTOR
|| TREE_CODE (init
) == VECTOR_CST
)
4243 && !DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl
))
4245 /* If the variable has a dynamic initializer, don't use its
4246 DECL_INITIAL which doesn't reflect the real value. */
4247 if (VAR_P (decl
) && TREE_STATIC (decl
)
4248 && !DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl
)
4249 && DECL_NONTRIVIALLY_INITIALIZED_P (decl
))
4253 return unshare_p
? unshare_expr (decl
) : decl
;
4256 // forked from gcc/cp/init.cc decl_constant_value
4258 /* A more relaxed version of decl_really_constant_value, used by the
4259 common C/C++ code. */
4262 decl_constant_value (tree decl
, bool unshare_p
)
4264 return constant_value_1 (decl
, /*strict_p=*/false,
4265 /*return_aggregate_cst_ok_p=*/true,
4266 /*unshare_p=*/unshare_p
);
4269 // Below is forked from gcc/cp/init.cc decl_constant_value
4272 decl_constant_value (tree decl
)
4274 return decl_constant_value (decl
, /*unshare_p=*/true);
4277 // Below is forked from gcc/cp/cp-gimplify.cc
4279 /* Type for source_location_table hash_set. */
4280 struct GTY ((for_user
)) source_location_table_entry
4287 // exit/reenter namespace to declare some external functions
4292 gt_pch_nx (Rust::source_location_table_entry
&);
4294 gt_pch_nx (Rust::source_location_table_entry
*, gt_pointer_operator
, void *);
4298 /* Traits class for function start hash maps below. */
4300 struct rust_source_location_table_entry_hash
4301 : ggc_remove
<source_location_table_entry
>
4303 typedef source_location_table_entry value_type
;
4304 typedef source_location_table_entry compare_type
;
4306 static hashval_t
hash (const source_location_table_entry
&ref
)
4308 inchash::hash
hstate (0);
4309 hstate
.add_int (ref
.loc
);
4310 hstate
.add_int (ref
.uid
);
4311 return hstate
.end ();
4314 static bool equal (const source_location_table_entry
&ref1
,
4315 const source_location_table_entry
&ref2
)
4317 return ref1
.loc
== ref2
.loc
&& ref1
.uid
== ref2
.uid
;
4320 static void mark_deleted (source_location_table_entry
&ref
)
4322 ref
.loc
= UNKNOWN_LOCATION
;
4324 ref
.var
= NULL_TREE
;
4327 static const bool empty_zero_p
= true;
4329 static void mark_empty (source_location_table_entry
&ref
)
4331 ref
.loc
= UNKNOWN_LOCATION
;
4333 ref
.var
= NULL_TREE
;
4336 static bool is_deleted (const source_location_table_entry
&ref
)
4338 return (ref
.loc
== UNKNOWN_LOCATION
&& ref
.uid
== -1U
4339 && ref
.var
== NULL_TREE
);
4342 static bool is_empty (const source_location_table_entry
&ref
)
4344 return (ref
.loc
== UNKNOWN_LOCATION
&& ref
.uid
== 0
4345 && ref
.var
== NULL_TREE
);
4348 static void pch_nx (source_location_table_entry
&p
) { gt_pch_nx (p
); }
4350 static void pch_nx (source_location_table_entry
&p
, gt_pointer_operator op
,
4353 gt_pch_nx (&p
, op
, cookie
);
4358 hash_table
<rust_source_location_table_entry_hash
> *source_location_table
;
4359 static GTY (()) unsigned int source_location_id
;
4361 // Above is forked from gcc/cp/cp-gimplify.cc
4363 // forked from gcc/cp/tree.cc lvalue_kind
4365 /* If REF is an lvalue, returns the kind of lvalue that REF is.
4366 Otherwise, returns clk_none. */
4369 lvalue_kind (const_tree ref
)
4371 cp_lvalue_kind op1_lvalue_kind
= clk_none
;
4372 cp_lvalue_kind op2_lvalue_kind
= clk_none
;
4374 /* Expressions of reference type are sometimes wrapped in
4375 INDIRECT_REFs. INDIRECT_REFs are just internal compiler
4376 representation, not part of the language, so we have to look
4378 if (REFERENCE_REF_P (ref
))
4379 return lvalue_kind (TREE_OPERAND (ref
, 0));
4381 if (TREE_TYPE (ref
) && TYPE_REF_P (TREE_TYPE (ref
)))
4383 /* unnamed rvalue references are rvalues */
4384 if (TYPE_REF_IS_RVALUE (TREE_TYPE (ref
)) && TREE_CODE (ref
) != PARM_DECL
4386 && TREE_CODE (ref
) != COMPONENT_REF
4387 /* Functions are always lvalues. */
4388 && TREE_CODE (TREE_TYPE (TREE_TYPE (ref
))) != FUNCTION_TYPE
)
4390 op1_lvalue_kind
= clk_rvalueref
;
4391 if (implicit_rvalue_p (ref
))
4392 op1_lvalue_kind
|= clk_implicit_rval
;
4393 return op1_lvalue_kind
;
4396 /* lvalue references and named rvalue references are lvalues. */
4397 return clk_ordinary
;
4400 if (ref
== current_class_ptr
)
4403 /* Expressions with cv void type are prvalues. */
4404 if (TREE_TYPE (ref
) && VOID_TYPE_P (TREE_TYPE (ref
)))
4407 switch (TREE_CODE (ref
))
4412 /* preincrements and predecrements are valid lvals, provided
4413 what they refer to are valid lvals. */
4414 case PREINCREMENT_EXPR
:
4415 case PREDECREMENT_EXPR
:
4416 case TRY_CATCH_EXPR
:
4419 case VIEW_CONVERT_EXPR
:
4420 return lvalue_kind (TREE_OPERAND (ref
, 0));
4423 tree op1
= TREE_OPERAND (ref
, 0);
4424 if (TREE_CODE (TREE_TYPE (op1
)) == ARRAY_TYPE
)
4426 op1_lvalue_kind
= lvalue_kind (op1
);
4427 if (op1_lvalue_kind
== clk_class
)
4428 /* in the case of an array operand, the result is an lvalue if
4429 that operand is an lvalue and an xvalue otherwise */
4430 op1_lvalue_kind
= clk_rvalueref
;
4431 return op1_lvalue_kind
;
4434 return clk_ordinary
;
4439 if (TREE_CODE (ref
) == MEMBER_REF
)
4440 op1_lvalue_kind
= clk_ordinary
;
4442 op1_lvalue_kind
= lvalue_kind (TREE_OPERAND (ref
, 0));
4443 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (TREE_OPERAND (ref
, 1))))
4444 op1_lvalue_kind
= clk_none
;
4445 else if (op1_lvalue_kind
== clk_class
)
4446 /* The result of a .* expression whose second operand is a pointer to a
4447 data member is an lvalue if the first operand is an lvalue and an
4448 xvalue otherwise. */
4449 op1_lvalue_kind
= clk_rvalueref
;
4450 return op1_lvalue_kind
;
4453 op1_lvalue_kind
= lvalue_kind (TREE_OPERAND (ref
, 0));
4454 if (op1_lvalue_kind
== clk_class
)
4455 /* If E1 is an lvalue, then E1.E2 is an lvalue;
4456 otherwise E1.E2 is an xvalue. */
4457 op1_lvalue_kind
= clk_rvalueref
;
4459 /* Look at the member designator. */
4460 if (!op1_lvalue_kind
)
4462 else if (is_overloaded_fn (TREE_OPERAND (ref
, 1)))
4463 /* The "field" can be a FUNCTION_DECL or an OVERLOAD in some
4464 situations. If we're seeing a COMPONENT_REF, it's a non-static
4465 member, so it isn't an lvalue. */
4466 op1_lvalue_kind
= clk_none
;
4467 else if (TREE_CODE (TREE_OPERAND (ref
, 1)) != FIELD_DECL
)
4468 /* This can be IDENTIFIER_NODE in a template. */;
4469 else if (DECL_C_BIT_FIELD (TREE_OPERAND (ref
, 1)))
4471 /* Clear the ordinary bit. If this object was a class
4472 rvalue we want to preserve that information. */
4473 op1_lvalue_kind
&= ~clk_ordinary
;
4474 /* The lvalue is for a bitfield. */
4475 op1_lvalue_kind
|= clk_bitfield
;
4477 else if (DECL_PACKED (TREE_OPERAND (ref
, 1)))
4478 op1_lvalue_kind
|= clk_packed
;
4480 return op1_lvalue_kind
;
4483 case COMPOUND_LITERAL_EXPR
:
4484 return clk_ordinary
;
4487 /* CONST_DECL without TREE_STATIC are enumeration values and
4488 thus not lvalues. With TREE_STATIC they are used by ObjC++
4489 in objc_build_string_object and need to be considered as
4491 if (!TREE_STATIC (ref
))
4495 if (VAR_P (ref
) && DECL_HAS_VALUE_EXPR_P (ref
))
4496 return lvalue_kind (DECL_VALUE_EXPR (CONST_CAST_TREE (ref
)));
4498 if (TREE_READONLY (ref
) && !TREE_STATIC (ref
) && DECL_LANG_SPECIFIC (ref
)
4499 && DECL_IN_AGGR_P (ref
))
4506 case PLACEHOLDER_EXPR
:
4507 return clk_ordinary
;
4511 /* Disallow <? and >? as lvalues if either argument side-effects. */
4512 if (TREE_SIDE_EFFECTS (TREE_OPERAND (ref
, 0))
4513 || TREE_SIDE_EFFECTS (TREE_OPERAND (ref
, 1)))
4515 op1_lvalue_kind
= lvalue_kind (TREE_OPERAND (ref
, 0));
4516 op2_lvalue_kind
= lvalue_kind (TREE_OPERAND (ref
, 1));
4520 tree op1
= TREE_OPERAND (ref
, 1);
4522 op1
= TREE_OPERAND (ref
, 0);
4523 tree op2
= TREE_OPERAND (ref
, 2);
4524 op1_lvalue_kind
= lvalue_kind (op1
);
4525 op2_lvalue_kind
= lvalue_kind (op2
);
4526 if (!op1_lvalue_kind
!= !op2_lvalue_kind
)
4528 /* The second or the third operand (but not both) is a
4529 throw-expression; the result is of the type
4530 and value category of the other. */
4531 if (op1_lvalue_kind
&& TREE_CODE (op2
) == THROW_EXPR
)
4532 op2_lvalue_kind
= op1_lvalue_kind
;
4533 else if (op2_lvalue_kind
&& TREE_CODE (op1
) == THROW_EXPR
)
4534 op1_lvalue_kind
= op2_lvalue_kind
;
4541 return clk_ordinary
;
4544 return lvalue_kind (TREE_OPERAND (ref
, 1));
4550 return (CLASS_TYPE_P (TREE_TYPE (ref
)) ? clk_class
: clk_none
);
4553 /* We can see calls outside of TARGET_EXPR in templates. */
4554 if (CLASS_TYPE_P (TREE_TYPE (ref
)))
4559 /* All functions (except non-static-member functions) are
4561 return (DECL_NONSTATIC_MEMBER_FUNCTION_P (ref
) ? clk_none
: clk_ordinary
);
4564 return lvalue_kind (TREE_OPERAND (ref
, 0));
4566 case TEMPLATE_PARM_INDEX
:
4567 if (CLASS_TYPE_P (TREE_TYPE (ref
)))
4568 /* A template parameter object is an lvalue. */
4569 return clk_ordinary
;
4573 if (!TREE_TYPE (ref
))
4575 if (CLASS_TYPE_P (TREE_TYPE (ref
))
4576 || TREE_CODE (TREE_TYPE (ref
)) == ARRAY_TYPE
)
4581 /* If one operand is not an lvalue at all, then this expression is
4583 if (!op1_lvalue_kind
|| !op2_lvalue_kind
)
4586 /* Otherwise, it's an lvalue, and it has all the odd properties
4587 contributed by either operand. */
4588 op1_lvalue_kind
= op1_lvalue_kind
| op2_lvalue_kind
;
4589 /* It's not an ordinary lvalue if it involves any other kind. */
4590 if ((op1_lvalue_kind
& ~clk_ordinary
) != clk_none
)
4591 op1_lvalue_kind
&= ~clk_ordinary
;
4592 /* It can't be both a pseudo-lvalue and a non-addressable lvalue.
4593 A COND_EXPR of those should be wrapped in a TARGET_EXPR. */
4594 if ((op1_lvalue_kind
& (clk_rvalueref
| clk_class
))
4595 && (op1_lvalue_kind
& (clk_bitfield
| clk_packed
)))
4596 op1_lvalue_kind
= clk_none
;
4597 return op1_lvalue_kind
;
4600 // forked from gcc/cp/tree.cc glvalue_p
4602 /* This differs from lvalue_p in that xvalues are included. */
4605 glvalue_p (const_tree ref
)
4607 cp_lvalue_kind kind
= lvalue_kind (ref
);
4608 if (kind
& clk_class
)
4611 return (kind
!= clk_none
);
4614 // forked from gcc/cp/init.cc cv_qualified_p
4616 /* Returns nonzero if TYPE is const or volatile. */
4619 cv_qualified_p (const_tree type
)
4621 int quals
= rs_type_quals (type
);
4622 return (quals
& (TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
)) != 0;
4625 // forked from gcc/cp/tree.cc rvalue
4627 /* EXPR is being used in an rvalue context. Return a version of EXPR
4628 that is marked as an rvalue. */
4635 if (error_operand_p (expr
))
4638 expr
= mark_rvalue_use (expr
);
4642 Non-class rvalues always have cv-unqualified types. */
4643 type
= TREE_TYPE (expr
);
4644 if (!CLASS_TYPE_P (type
) && cv_qualified_p (type
))
4645 type
= cv_unqualified (type
);
4647 /* We need to do this for rvalue refs as well to get the right answer
4648 from decltype; see c++/36628. */
4649 if (glvalue_p (expr
))
4651 /* But don't use this function for class lvalues; use move (to treat an
4652 lvalue as an xvalue) or force_rvalue (to make a prvalue copy). */
4653 gcc_checking_assert (!CLASS_TYPE_P (type
));
4654 expr
= build1 (NON_LVALUE_EXPR
, type
, expr
);
4656 else if (type
!= TREE_TYPE (expr
))
4657 expr
= build_nop (type
, expr
);
4662 // forked from gcc/cp/tree.cc bitfield_p
4664 /* True if REF is a bit-field. */
4667 bitfield_p (const_tree ref
)
4669 return (lvalue_kind (ref
) & clk_bitfield
);
4672 // forked from gcc/cp/typeck.cc cxx_mark_addressable
4674 /* Mark EXP saying that we need to be able to take the
4675 address of it; it should not be allocated in a register.
4676 Value is true if successful. ARRAY_REF_P is true if this
4677 is for ARRAY_REF construction - in that case we don't want
4678 to look through VIEW_CONVERT_EXPR from VECTOR_TYPE to ARRAY_TYPE,
4679 it is fine to use ARRAY_REFs for vector subscripts on vector
4682 C++: we do not allow `current_class_ptr' to be addressable. */
4685 cxx_mark_addressable (tree exp
, bool array_ref_p
)
4690 switch (TREE_CODE (x
))
4692 case VIEW_CONVERT_EXPR
:
4693 if (array_ref_p
&& TREE_CODE (TREE_TYPE (x
)) == ARRAY_TYPE
4694 && VECTOR_TYPE_P (TREE_TYPE (TREE_OPERAND (x
, 0))))
4696 x
= TREE_OPERAND (x
, 0);
4701 error ("attempt to take address of bit-field");
4707 x
= TREE_OPERAND (x
, 0);
4711 if (x
== current_class_ptr
)
4713 error ("cannot take the address of %<this%>, which is an rvalue "
4715 TREE_ADDRESSABLE (x
) = 1; /* so compiler doesn't die later. */
4721 /* Caller should not be trying to mark initialized
4722 constant fields addressable. */
4723 gcc_assert (DECL_LANG_SPECIFIC (x
) == 0 || DECL_IN_AGGR_P (x
) == 0
4724 || TREE_STATIC (x
) || DECL_EXTERNAL (x
));
4728 if (DECL_REGISTER (x
) && !TREE_ADDRESSABLE (x
) && !DECL_ARTIFICIAL (x
))
4730 if (VAR_P (x
) && DECL_HARD_REGISTER (x
))
4732 error ("address of explicit register variable %qD requested",
4736 else if (extra_warnings
)
4739 "address requested for %qD, which is declared %<register%>", x
);
4741 TREE_ADDRESSABLE (x
) = 1;
4746 TREE_ADDRESSABLE (x
) = 1;
4750 TREE_ADDRESSABLE (x
) = 1;
4754 TREE_ADDRESSABLE (x
) = 1;
4755 cxx_mark_addressable (TREE_OPERAND (x
, 0));
4763 // forked from gcc/cp/typeck.cc build_address
4765 /* Returns the address of T. This function will fold away
4766 ADDR_EXPR of INDIRECT_REF. This is only for low-level usage;
4767 most places should use cp_build_addr_expr instead. */
4770 build_address (tree t
)
4772 if (error_operand_p (t
) || !cxx_mark_addressable (t
))
4773 return error_mark_node
;
4774 gcc_checking_assert (TREE_CODE (t
) != CONSTRUCTOR
);
4775 t
= build_fold_addr_expr_loc (EXPR_LOCATION (t
), t
);
4776 if (TREE_CODE (t
) != ADDR_EXPR
)
4781 // forked from gcc/cp/gp-gimplify.cc fold_builtin_source_location
4783 /* Fold __builtin_source_location () call. LOC is the location
4787 fold_builtin_source_location (location_t loc
)
4789 // if (source_location_impl == NULL_TREE)
4791 // auto_diagnostic_group d;
4792 // source_location_impl = get_source_location_impl_type (loc);
4793 // if (source_location_impl == error_mark_node)
4794 // inform (loc, "evaluating %qs", "__builtin_source_location");
4796 if (source_location_impl
== error_mark_node
)
4797 return build_zero_cst (const_ptr_type_node
);
4798 if (source_location_table
== NULL
)
4799 source_location_table
4800 = hash_table
<rust_source_location_table_entry_hash
>::create_ggc (64);
4801 const line_map_ordinary
*map
;
4802 source_location_table_entry entry
;
4803 entry
.loc
= linemap_resolve_location (line_table
, loc
,
4804 LRK_MACRO_EXPANSION_POINT
, &map
);
4805 entry
.uid
= current_function_decl
? DECL_UID (current_function_decl
) : -1;
4806 entry
.var
= error_mark_node
;
4807 source_location_table_entry
*entryp
4808 = source_location_table
->find_slot (entry
, INSERT
);
4815 ASM_GENERATE_INTERNAL_LABEL (tmp_name
, "Lsrc_loc", source_location_id
++);
4816 var
= build_decl (loc
, VAR_DECL
, get_identifier (tmp_name
),
4817 source_location_impl
);
4818 TREE_STATIC (var
) = 1;
4819 TREE_PUBLIC (var
) = 0;
4820 DECL_ARTIFICIAL (var
) = 1;
4821 DECL_IGNORED_P (var
) = 1;
4822 DECL_EXTERNAL (var
) = 0;
4823 DECL_DECLARED_CONSTEXPR_P (var
) = 1;
4824 DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (var
) = 1;
4825 layout_decl (var
, 0);
4827 vec
<constructor_elt
, va_gc
> *v
= NULL
;
4829 for (tree field
= TYPE_FIELDS (source_location_impl
);
4830 (field
= next_initializable_field (field
)) != NULL_TREE
;
4831 field
= DECL_CHAIN (field
))
4833 const char *n
= IDENTIFIER_POINTER (DECL_NAME (field
));
4834 tree val
= NULL_TREE
;
4835 if (strcmp (n
, "_M_file_name") == 0)
4837 if (const char *fname
= LOCATION_FILE (loc
))
4839 fname
= remap_macro_filename (fname
);
4840 val
= build_string_literal (strlen (fname
) + 1, fname
);
4843 val
= build_string_literal (1, "");
4845 else if (strcmp (n
, "_M_function_name") == 0)
4847 const char *name
= "todo: add funciton name here";
4849 // if (current_function_decl)
4850 // name = cxx_printable_name (current_function_decl, 2);
4852 val
= build_string_literal (strlen (name
) + 1, name
);
4854 else if (strcmp (n
, "_M_line") == 0)
4855 val
= build_int_cst (TREE_TYPE (field
), LOCATION_LINE (loc
));
4856 else if (strcmp (n
, "_M_column") == 0)
4857 val
= build_int_cst (TREE_TYPE (field
), LOCATION_COLUMN (loc
));
4859 rust_unreachable ();
4860 CONSTRUCTOR_APPEND_ELT (v
, field
, val
);
4863 tree ctor
= build_constructor (source_location_impl
, v
);
4864 TREE_CONSTANT (ctor
) = 1;
4865 TREE_STATIC (ctor
) = 1;
4866 DECL_INITIAL (var
) = ctor
;
4867 varpool_node::finalize_decl (var
);
4872 return build_fold_addr_expr_with_type_loc (loc
, var
, const_ptr_type_node
);
4875 // forked from gcc/c-family/c-common.cc braced_lists_to_strings
4877 /* Attempt to convert a braced array initializer list CTOR for array
4878 TYPE into a STRING_CST for convenience and efficiency. Return
4879 the converted string on success or the original ctor on failure. */
4882 braced_list_to_string (tree type
, tree ctor
, bool member
)
4884 /* Ignore non-members with unknown size like arrays with unspecified
4886 tree typesize
= TYPE_SIZE_UNIT (type
);
4887 if (!member
&& !tree_fits_uhwi_p (typesize
))
4890 /* If the target char size differes from the host char size, we'd risk
4891 loosing data and getting object sizes wrong by converting to
4893 if (TYPE_PRECISION (char_type_node
) != CHAR_BIT
)
4896 /* If the array has an explicit bound, use it to constrain the size
4897 of the string. If it doesn't, be sure to create a string that's
4898 as long as implied by the index of the last zero specified via
4899 a designator, as in:
4900 const char a[] = { [7] = 0 }; */
4901 unsigned HOST_WIDE_INT maxelts
;
4904 maxelts
= tree_to_uhwi (typesize
);
4905 maxelts
/= tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (type
)));
4908 maxelts
= HOST_WIDE_INT_M1U
;
4910 /* Avoid converting initializers for zero-length arrays (but do
4911 create them for flexible array members). */
4915 unsigned HOST_WIDE_INT nelts
= CONSTRUCTOR_NELTS (ctor
);
4918 str
.reserve (nelts
+ 1);
4920 unsigned HOST_WIDE_INT i
;
4923 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor
), i
, index
, value
)
4925 unsigned HOST_WIDE_INT idx
= i
;
4928 if (!tree_fits_uhwi_p (index
))
4930 idx
= tree_to_uhwi (index
);
4933 /* auto_vec is limited to UINT_MAX elements. */
4937 /* Avoid non-constant initializers. */
4938 if (!tree_fits_shwi_p (value
))
4941 /* Skip over embedded nuls except the last one (initializer
4942 elements are in ascending order of indices). */
4943 HOST_WIDE_INT val
= tree_to_shwi (value
);
4944 if (!val
&& i
+ 1 < nelts
)
4947 if (idx
< str
.length ())
4950 /* Bail if the CTOR has a block of more than 256 embedded nuls
4951 due to implicitly initialized elements. */
4952 unsigned nchars
= (idx
- str
.length ()) + 1;
4959 str
.quick_grow_cleared (idx
);
4965 str
.safe_insert (idx
, val
);
4968 /* Append a nul string termination. */
4969 if (maxelts
!= HOST_WIDE_INT_M1U
&& str
.length () < maxelts
)
4972 /* Build a STRING_CST with the same type as the array. */
4973 tree res
= build_string (str
.length (), str
.begin ());
4974 TREE_TYPE (res
) = type
;
4978 // forked from gcc/c-family/c-common.cc braced_lists_to_strings
4980 /* Implementation of the two-argument braced_lists_to_string withe
4981 the same arguments plus MEMBER which is set for struct members
4982 to allow initializers for flexible member arrays. */
4985 braced_lists_to_strings (tree type
, tree ctor
, bool member
)
4987 if (TREE_CODE (ctor
) != CONSTRUCTOR
)
4990 tree_code code
= TREE_CODE (type
);
4993 if (code
== ARRAY_TYPE
)
4994 ttp
= TREE_TYPE (type
);
4995 else if (code
== RECORD_TYPE
)
4997 ttp
= TREE_TYPE (ctor
);
4998 if (TREE_CODE (ttp
) == ARRAY_TYPE
)
5001 ttp
= TREE_TYPE (ttp
);
5007 if ((TREE_CODE (ttp
) == ARRAY_TYPE
|| TREE_CODE (ttp
) == INTEGER_TYPE
)
5008 && TYPE_STRING_FLAG (ttp
))
5009 return braced_list_to_string (type
, ctor
, member
);
5011 code
= TREE_CODE (ttp
);
5012 if (code
== ARRAY_TYPE
|| RECORD_OR_UNION_TYPE_P (ttp
))
5014 bool rec
= RECORD_OR_UNION_TYPE_P (ttp
);
5016 /* Handle array of arrays or struct member initializers. */
5018 unsigned HOST_WIDE_INT idx
;
5019 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor
), idx
, val
)
5021 val
= braced_lists_to_strings (ttp
, val
, rec
);
5022 CONSTRUCTOR_ELT (ctor
, idx
)->value
= val
;
5029 // forked from gcc/c-family/c-common.cc braced_lists_to_strings
5031 /* Attempt to convert a CTOR containing braced array initializer lists
5032 for array TYPE into one containing STRING_CSTs, for convenience and
5033 efficiency. Recurse for arrays of arrays and member initializers.
5034 Return the converted CTOR or STRING_CST on success or the original
5038 braced_lists_to_strings (tree type
, tree ctor
)
5040 return braced_lists_to_strings (type
, ctor
, false);
5043 /*---------------------------------------------------------------------------
5044 Constraint satisfaction
5045 ---------------------------------------------------------------------------*/
5047 // forked from gcc/cp/constraint.cc satisfying_constraint
5049 /* True if we are currently satisfying a failed_type_completions. */
5051 static bool satisfying_constraint
;
5053 // forked from gcc/cp/constraint.cc satisfying_constraint
5055 /* A vector of incomplete types (and of declarations with undeduced return
5056 type), appended to by note_failed_type_completion_for_satisfaction. The
5057 satisfaction caches use this in order to keep track of "potentially unstable"
5058 satisfaction results.
5060 Since references to entries in this vector are stored only in the
5061 GC-deletable sat_cache, it's safe to make this deletable as well. */
5063 static GTY ((deletable
)) vec
<tree
, va_gc
> *failed_type_completions
;
5065 // forked from gcc/cp/constraint.cc note_failed_type_completion_for_satisfaction
5067 /* Called whenever a type completion (or return type deduction) failure occurs
5068 that definitely affects the meaning of the program, by e.g. inducing
5069 substitution failure. */
5072 note_failed_type_completion_for_satisfaction (tree t
)
5074 if (satisfying_constraint
)
5076 gcc_checking_assert ((TYPE_P (t
) && !COMPLETE_TYPE_P (t
))
5077 || (DECL_P (t
) && undeduced_auto_decl (t
)));
5078 vec_safe_push (failed_type_completions
, t
);
5082 // forked from gcc/cp/typeck.cc complete_type
5084 /* Try to complete TYPE, if it is incomplete. For example, if TYPE is
5085 a template instantiation, do the instantiation. Returns TYPE,
5086 whether or not it could be completed, unless something goes
5087 horribly wrong, in which case the error_mark_node is returned. */
5090 complete_type (tree type
)
5092 if (type
== NULL_TREE
)
5093 /* Rather than crash, we return something sure to cause an error
5095 return error_mark_node
;
5097 if (type
== error_mark_node
|| COMPLETE_TYPE_P (type
))
5099 else if (TREE_CODE (type
) == ARRAY_TYPE
)
5101 tree t
= complete_type (TREE_TYPE (type
));
5102 unsigned int needs_constructing
, has_nontrivial_dtor
;
5103 if (COMPLETE_TYPE_P (t
))
5105 needs_constructing
= TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (t
));
5107 = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (t
));
5108 for (t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
5110 TYPE_NEEDS_CONSTRUCTING (t
) = needs_constructing
;
5111 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t
) = has_nontrivial_dtor
;
5118 // forked from gcc/cp/typeck.cc complete_type_or_maybe_complain
5120 /* Like complete_type, but issue an error if the TYPE cannot be completed.
5121 VALUE is used for informative diagnostics.
5122 Returns NULL_TREE if the type cannot be made complete. */
5125 complete_type_or_maybe_complain (tree type
, tree value
, tsubst_flags_t complain
)
5127 type
= complete_type (type
);
5128 if (type
== error_mark_node
)
5129 /* We already issued an error. */
5131 else if (!COMPLETE_TYPE_P (type
))
5133 if (complain
& tf_error
)
5134 cxx_incomplete_type_diagnostic (value
, type
, DK_ERROR
);
5135 note_failed_type_completion_for_satisfaction (type
);
5142 // forked from gcc/cp/typeck.cc complete_type_or_else
5145 complete_type_or_else (tree type
, tree value
)
5147 return complete_type_or_maybe_complain (type
, value
, tf_warning_or_error
);
5150 // forked from gcc/cp/tree.cc std_layout_type_p
5152 /* Returns true iff T is a standard-layout type, as defined in
5156 std_layout_type_p (const_tree t
)
5158 t
= strip_array_types (CONST_CAST_TREE (t
));
5160 if (CLASS_TYPE_P (t
))
5161 return !CLASSTYPE_NON_STD_LAYOUT (t
);
5163 return scalarish_type_p (t
);
5166 // forked from /gcc/cp/semantics.cc first_nonstatic_data_member_p
5168 /* Helper function for fold_builtin_is_pointer_inverconvertible_with_class,
5169 return true if MEMBERTYPE is the type of the first non-static data member
5170 of TYPE or for unions of any members. */
5172 first_nonstatic_data_member_p (tree type
, tree membertype
)
5174 for (tree field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
5176 if (TREE_CODE (field
) != FIELD_DECL
)
5178 if (DECL_FIELD_IS_BASE (field
) && is_empty_field (field
))
5180 if (DECL_FIELD_IS_BASE (field
))
5181 return first_nonstatic_data_member_p (TREE_TYPE (field
), membertype
);
5182 if (ANON_AGGR_TYPE_P (TREE_TYPE (field
)))
5184 if ((TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
5185 || std_layout_type_p (TREE_TYPE (field
)))
5186 && first_nonstatic_data_member_p (TREE_TYPE (field
), membertype
))
5189 else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field
),
5192 if (TREE_CODE (type
) != UNION_TYPE
)
5198 // forked from gcc/cp/semantics.cc
5199 // fold_builtin_is_pointer_inverconvertible_with_class
5201 /* Fold __builtin_is_pointer_interconvertible_with_class call. */
5204 fold_builtin_is_pointer_inverconvertible_with_class (location_t loc
, int nargs
,
5207 /* Unless users call the builtin directly, the following 3 checks should be
5208 ensured from std::is_pointer_interconvertible_with_class function
5212 error_at (loc
, "%<__builtin_is_pointer_interconvertible_with_class%> "
5213 "needs a single argument");
5214 return boolean_false_node
;
5217 if (error_operand_p (arg
))
5218 return boolean_false_node
;
5219 if (!TYPE_PTRMEM_P (TREE_TYPE (arg
)))
5221 error_at (loc
, "%<__builtin_is_pointer_interconvertible_with_class%> "
5222 "argument is not pointer to member");
5223 return boolean_false_node
;
5226 if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg
)))
5227 return boolean_false_node
;
5229 tree membertype
= TREE_TYPE (TREE_TYPE (arg
));
5230 tree basetype
= TYPE_OFFSET_BASETYPE (TREE_TYPE (arg
));
5231 if (!complete_type_or_else (basetype
, NULL_TREE
))
5232 return boolean_false_node
;
5234 if (TREE_CODE (basetype
) != UNION_TYPE
&& !std_layout_type_p (basetype
))
5235 return boolean_false_node
;
5237 if (!first_nonstatic_data_member_p (basetype
, membertype
))
5238 return boolean_false_node
;
5240 if (integer_nonzerop (arg
))
5241 return boolean_false_node
;
5242 if (integer_zerop (arg
))
5243 return boolean_true_node
;
5245 return fold_build2 (EQ_EXPR
, boolean_type_node
, arg
,
5246 build_zero_cst (TREE_TYPE (arg
)));
5249 // forked from gcc/c-family/c-common.cc registered_builtin_types
5251 /* Used for communication between c_common_type_for_mode and
5252 c_register_builtin_type. */
5253 tree registered_builtin_types
;
5255 /* Return a data type that has machine mode MODE.
5256 If the mode is an integer,
5257 then UNSIGNEDP selects between signed and unsigned types.
5258 If the mode is a fixed-point mode,
5259 then UNSIGNEDP selects between saturating and nonsaturating types. */
5261 // forked from gcc/c-family/c-common.cc c_common_type_for_mode
5264 c_common_type_for_mode (machine_mode mode
, int unsignedp
)
5269 if (mode
== TYPE_MODE (integer_type_node
))
5270 return unsignedp
? unsigned_type_node
: integer_type_node
;
5272 if (mode
== TYPE_MODE (signed_char_type_node
))
5273 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
5275 if (mode
== TYPE_MODE (short_integer_type_node
))
5276 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
5278 if (mode
== TYPE_MODE (long_integer_type_node
))
5279 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
5281 if (mode
== TYPE_MODE (long_long_integer_type_node
))
5282 return unsignedp
? long_long_unsigned_type_node
5283 : long_long_integer_type_node
;
5285 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
5286 if (int_n_enabled_p
[i
] && mode
== int_n_data
[i
].m
)
5287 return (unsignedp
? int_n_trees
[i
].unsigned_type
5288 : int_n_trees
[i
].signed_type
);
5291 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
5294 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
5297 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
5300 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
5302 #if HOST_BITS_PER_WIDE_INT >= 64
5303 if (mode
== TYPE_MODE (intTI_type_node
))
5304 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
5307 if (mode
== TYPE_MODE (float_type_node
))
5308 return float_type_node
;
5310 if (mode
== TYPE_MODE (double_type_node
))
5311 return double_type_node
;
5313 if (mode
== TYPE_MODE (long_double_type_node
))
5314 return long_double_type_node
;
5316 for (i
= 0; i
< NUM_FLOATN_NX_TYPES
; i
++)
5317 if (FLOATN_NX_TYPE_NODE (i
) != NULL_TREE
5318 && mode
== TYPE_MODE (FLOATN_NX_TYPE_NODE (i
)))
5319 return FLOATN_NX_TYPE_NODE (i
);
5321 if (mode
== TYPE_MODE (void_type_node
))
5322 return void_type_node
;
5324 if (mode
== TYPE_MODE (build_pointer_type (char_type_node
))
5325 || mode
== TYPE_MODE (build_pointer_type (integer_type_node
)))
5327 unsigned int precision
5328 = GET_MODE_PRECISION (as_a
<scalar_int_mode
> (mode
));
5329 return (unsignedp
? make_unsigned_type (precision
)
5330 : make_signed_type (precision
));
5333 if (COMPLEX_MODE_P (mode
))
5335 machine_mode inner_mode
;
5338 if (mode
== TYPE_MODE (complex_float_type_node
))
5339 return complex_float_type_node
;
5340 if (mode
== TYPE_MODE (complex_double_type_node
))
5341 return complex_double_type_node
;
5342 if (mode
== TYPE_MODE (complex_long_double_type_node
))
5343 return complex_long_double_type_node
;
5345 for (i
= 0; i
< NUM_FLOATN_NX_TYPES
; i
++)
5346 if (COMPLEX_FLOATN_NX_TYPE_NODE (i
) != NULL_TREE
5347 && mode
== TYPE_MODE (COMPLEX_FLOATN_NX_TYPE_NODE (i
)))
5348 return COMPLEX_FLOATN_NX_TYPE_NODE (i
);
5350 if (mode
== TYPE_MODE (complex_integer_type_node
) && !unsignedp
)
5351 return complex_integer_type_node
;
5353 inner_mode
= GET_MODE_INNER (mode
);
5354 inner_type
= c_common_type_for_mode (inner_mode
, unsignedp
);
5355 if (inner_type
!= NULL_TREE
)
5356 return build_complex_type (inner_type
);
5358 else if (GET_MODE_CLASS (mode
) == MODE_VECTOR_BOOL
5359 && valid_vector_subparts_p (GET_MODE_NUNITS (mode
)))
5361 unsigned int elem_bits
= vector_element_size (GET_MODE_PRECISION (mode
),
5362 GET_MODE_NUNITS (mode
));
5363 tree bool_type
= build_nonstandard_boolean_type (elem_bits
);
5364 return build_vector_type_for_mode (bool_type
, mode
);
5366 else if (VECTOR_MODE_P (mode
)
5367 && valid_vector_subparts_p (GET_MODE_NUNITS (mode
)))
5369 machine_mode inner_mode
= GET_MODE_INNER (mode
);
5370 tree inner_type
= c_common_type_for_mode (inner_mode
, unsignedp
);
5371 if (inner_type
!= NULL_TREE
)
5372 return build_vector_type_for_mode (inner_type
, mode
);
5375 if (dfloat32_type_node
!= NULL_TREE
&& mode
== TYPE_MODE (dfloat32_type_node
))
5376 return dfloat32_type_node
;
5377 if (dfloat64_type_node
!= NULL_TREE
&& mode
== TYPE_MODE (dfloat64_type_node
))
5378 return dfloat64_type_node
;
5379 if (dfloat128_type_node
!= NULL_TREE
5380 && mode
== TYPE_MODE (dfloat128_type_node
))
5381 return dfloat128_type_node
;
5383 if (ALL_SCALAR_FIXED_POINT_MODE_P (mode
))
5385 if (mode
== TYPE_MODE (short_fract_type_node
))
5386 return unsignedp
? sat_short_fract_type_node
: short_fract_type_node
;
5387 if (mode
== TYPE_MODE (fract_type_node
))
5388 return unsignedp
? sat_fract_type_node
: fract_type_node
;
5389 if (mode
== TYPE_MODE (long_fract_type_node
))
5390 return unsignedp
? sat_long_fract_type_node
: long_fract_type_node
;
5391 if (mode
== TYPE_MODE (long_long_fract_type_node
))
5392 return unsignedp
? sat_long_long_fract_type_node
5393 : long_long_fract_type_node
;
5395 if (mode
== TYPE_MODE (unsigned_short_fract_type_node
))
5396 return unsignedp
? sat_unsigned_short_fract_type_node
5397 : unsigned_short_fract_type_node
;
5398 if (mode
== TYPE_MODE (unsigned_fract_type_node
))
5399 return unsignedp
? sat_unsigned_fract_type_node
5400 : unsigned_fract_type_node
;
5401 if (mode
== TYPE_MODE (unsigned_long_fract_type_node
))
5402 return unsignedp
? sat_unsigned_long_fract_type_node
5403 : unsigned_long_fract_type_node
;
5404 if (mode
== TYPE_MODE (unsigned_long_long_fract_type_node
))
5405 return unsignedp
? sat_unsigned_long_long_fract_type_node
5406 : unsigned_long_long_fract_type_node
;
5408 if (mode
== TYPE_MODE (short_accum_type_node
))
5409 return unsignedp
? sat_short_accum_type_node
: short_accum_type_node
;
5410 if (mode
== TYPE_MODE (accum_type_node
))
5411 return unsignedp
? sat_accum_type_node
: accum_type_node
;
5412 if (mode
== TYPE_MODE (long_accum_type_node
))
5413 return unsignedp
? sat_long_accum_type_node
: long_accum_type_node
;
5414 if (mode
== TYPE_MODE (long_long_accum_type_node
))
5415 return unsignedp
? sat_long_long_accum_type_node
5416 : long_long_accum_type_node
;
5418 if (mode
== TYPE_MODE (unsigned_short_accum_type_node
))
5419 return unsignedp
? sat_unsigned_short_accum_type_node
5420 : unsigned_short_accum_type_node
;
5421 if (mode
== TYPE_MODE (unsigned_accum_type_node
))
5422 return unsignedp
? sat_unsigned_accum_type_node
5423 : unsigned_accum_type_node
;
5424 if (mode
== TYPE_MODE (unsigned_long_accum_type_node
))
5425 return unsignedp
? sat_unsigned_long_accum_type_node
5426 : unsigned_long_accum_type_node
;
5427 if (mode
== TYPE_MODE (unsigned_long_long_accum_type_node
))
5428 return unsignedp
? sat_unsigned_long_long_accum_type_node
5429 : unsigned_long_long_accum_type_node
;
5432 return unsignedp
? sat_qq_type_node
: qq_type_node
;
5434 return unsignedp
? sat_hq_type_node
: hq_type_node
;
5436 return unsignedp
? sat_sq_type_node
: sq_type_node
;
5438 return unsignedp
? sat_dq_type_node
: dq_type_node
;
5440 return unsignedp
? sat_tq_type_node
: tq_type_node
;
5442 if (mode
== UQQmode
)
5443 return unsignedp
? sat_uqq_type_node
: uqq_type_node
;
5444 if (mode
== UHQmode
)
5445 return unsignedp
? sat_uhq_type_node
: uhq_type_node
;
5446 if (mode
== USQmode
)
5447 return unsignedp
? sat_usq_type_node
: usq_type_node
;
5448 if (mode
== UDQmode
)
5449 return unsignedp
? sat_udq_type_node
: udq_type_node
;
5450 if (mode
== UTQmode
)
5451 return unsignedp
? sat_utq_type_node
: utq_type_node
;
5454 return unsignedp
? sat_ha_type_node
: ha_type_node
;
5456 return unsignedp
? sat_sa_type_node
: sa_type_node
;
5458 return unsignedp
? sat_da_type_node
: da_type_node
;
5460 return unsignedp
? sat_ta_type_node
: ta_type_node
;
5462 if (mode
== UHAmode
)
5463 return unsignedp
? sat_uha_type_node
: uha_type_node
;
5464 if (mode
== USAmode
)
5465 return unsignedp
? sat_usa_type_node
: usa_type_node
;
5466 if (mode
== UDAmode
)
5467 return unsignedp
? sat_uda_type_node
: uda_type_node
;
5468 if (mode
== UTAmode
)
5469 return unsignedp
? sat_uta_type_node
: uta_type_node
;
5472 for (t
= registered_builtin_types
; t
; t
= TREE_CHAIN (t
))
5474 tree type
= TREE_VALUE (t
);
5475 if (TYPE_MODE (type
) == mode
5476 && VECTOR_TYPE_P (type
) == VECTOR_MODE_P (mode
)
5477 && !!unsignedp
== !!TYPE_UNSIGNED (type
))
5483 // forked from gcc/cp/semantics.cc finish_underlying_type
5485 /* Implement the __underlying_type keyword: Return the underlying
5486 type of TYPE, suitable for use as a type-specifier. */
5489 finish_underlying_type (tree type
)
5491 tree underlying_type
;
5493 if (!complete_type_or_else (type
, NULL_TREE
))
5494 return error_mark_node
;
5496 if (TREE_CODE (type
) != ENUMERAL_TYPE
)
5498 error ("%qT is not an enumeration type", type
);
5499 return error_mark_node
;
5502 underlying_type
= ENUM_UNDERLYING_TYPE (type
);
5504 /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE
5505 includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information.
5506 See finish_enum_value_list for details. */
5507 if (!ENUM_FIXED_UNDERLYING_TYPE_P (type
))
5508 underlying_type
= c_common_type_for_mode (TYPE_MODE (underlying_type
),
5509 TYPE_UNSIGNED (underlying_type
));
5511 return underlying_type
;
5514 // forked from gcc/cp/typeck.cc layout_compatible_type_p
5516 /* Return true if TYPE1 and TYPE2 are layout-compatible types. */
5519 layout_compatible_type_p (tree type1
, tree type2
)
5521 if (type1
== error_mark_node
|| type2
== error_mark_node
)
5525 if (TREE_CODE (type1
) != TREE_CODE (type2
))
5528 type1
= rs_build_qualified_type (type1
, TYPE_UNQUALIFIED
);
5529 type2
= rs_build_qualified_type (type2
, TYPE_UNQUALIFIED
);
5531 if (TREE_CODE (type1
) == ENUMERAL_TYPE
)
5532 return (TYPE_ALIGN (type1
) == TYPE_ALIGN (type2
)
5533 && tree_int_cst_equal (TYPE_SIZE (type1
), TYPE_SIZE (type2
))
5534 && same_type_p (finish_underlying_type (type1
),
5535 finish_underlying_type (type2
)));
5537 if (CLASS_TYPE_P (type1
) && std_layout_type_p (type1
)
5538 && std_layout_type_p (type2
) && TYPE_ALIGN (type1
) == TYPE_ALIGN (type2
)
5539 && tree_int_cst_equal (TYPE_SIZE (type1
), TYPE_SIZE (type2
)))
5541 tree field1
= TYPE_FIELDS (type1
);
5542 tree field2
= TYPE_FIELDS (type2
);
5543 if (TREE_CODE (type1
) == RECORD_TYPE
)
5547 if (!next_common_initial_seqence (field1
, field2
))
5549 if (field1
== NULL_TREE
)
5551 field1
= DECL_CHAIN (field1
);
5552 field2
= DECL_CHAIN (field2
);
5555 /* Otherwise both types must be union types.
5557 "Two standard-layout unions are layout-compatible if they have
5558 the same number of non-static data members and corresponding
5559 non-static data members (in any order) have layout-compatible
5561 but the code anticipates that bitfield vs. non-bitfield,
5562 different bitfield widths or presence/absence of
5563 [[no_unique_address]] should be checked as well. */
5564 auto_vec
<tree
, 16> vec
;
5565 unsigned int count
= 0;
5566 for (; field1
; field1
= DECL_CHAIN (field1
))
5567 if (TREE_CODE (field1
) == FIELD_DECL
)
5569 for (; field2
; field2
= DECL_CHAIN (field2
))
5570 if (TREE_CODE (field2
) == FIELD_DECL
)
5571 vec
.safe_push (field2
);
5572 /* Discussions on core lean towards treating multiple union fields
5573 of the same type as the same field, so this might need changing
5575 if (count
!= vec
.length ())
5577 for (field1
= TYPE_FIELDS (type1
); field1
; field1
= DECL_CHAIN (field1
))
5579 if (TREE_CODE (field1
) != FIELD_DECL
)
5582 tree t1
= DECL_BIT_FIELD_TYPE (field1
);
5583 if (t1
== NULL_TREE
)
5584 t1
= TREE_TYPE (field1
);
5585 FOR_EACH_VEC_ELT (vec
, j
, field2
)
5587 tree t2
= DECL_BIT_FIELD_TYPE (field2
);
5588 if (t2
== NULL_TREE
)
5589 t2
= TREE_TYPE (field2
);
5590 if (DECL_BIT_FIELD_TYPE (field1
))
5592 if (!DECL_BIT_FIELD_TYPE (field2
))
5594 if (TYPE_PRECISION (TREE_TYPE (field1
))
5595 != TYPE_PRECISION (TREE_TYPE (field2
)))
5598 else if (DECL_BIT_FIELD_TYPE (field2
))
5600 if (!layout_compatible_type_p (t1
, t2
))
5602 if ((!lookup_attribute ("no_unique_address",
5603 DECL_ATTRIBUTES (field1
)))
5604 != !lookup_attribute ("no_unique_address",
5605 DECL_ATTRIBUTES (field2
)))
5609 if (j
== vec
.length ())
5611 vec
.unordered_remove (j
);
5616 return same_type_p (type1
, type2
);
5619 // forked from gcc/cp/semnatics.cc is_corresponding_member_union
5621 /* Helper function for is_corresponding_member_aggr. Return true if
5622 MEMBERTYPE pointer-to-data-member ARG can be found in anonymous
5623 union or structure BASETYPE. */
5626 is_corresponding_member_union (tree basetype
, tree membertype
, tree arg
)
5628 for (tree field
= TYPE_FIELDS (basetype
); field
; field
= DECL_CHAIN (field
))
5629 if (TREE_CODE (field
) != FIELD_DECL
|| DECL_BIT_FIELD_TYPE (field
))
5631 else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field
),
5634 if (TREE_CODE (arg
) != INTEGER_CST
5635 || tree_int_cst_equal (arg
, byte_position (field
)))
5638 else if (ANON_AGGR_TYPE_P (TREE_TYPE (field
)))
5641 if (TREE_CODE (basetype
) != UNION_TYPE
5642 && TREE_CODE (narg
) == INTEGER_CST
)
5643 narg
= size_binop (MINUS_EXPR
, arg
, byte_position (field
));
5644 if (is_corresponding_member_union (TREE_TYPE (field
), membertype
, narg
))
5650 // forked from gcc/cp/typeck.cc next_common_initial_seqence
5652 /* Helper function for layout_compatible_type_p and
5653 is_corresponding_member_aggr. Advance to next members (NULL if
5654 no further ones) and return true if those members are still part of
5655 the common initial sequence. */
5658 next_common_initial_seqence (tree
&memb1
, tree
&memb2
)
5662 if (TREE_CODE (memb1
) != FIELD_DECL
5663 || (DECL_FIELD_IS_BASE (memb1
) && is_empty_field (memb1
)))
5665 memb1
= DECL_CHAIN (memb1
);
5668 if (DECL_FIELD_IS_BASE (memb1
))
5670 memb1
= TYPE_FIELDS (TREE_TYPE (memb1
));
5677 if (TREE_CODE (memb2
) != FIELD_DECL
5678 || (DECL_FIELD_IS_BASE (memb2
) && is_empty_field (memb2
)))
5680 memb2
= DECL_CHAIN (memb2
);
5683 if (DECL_FIELD_IS_BASE (memb2
))
5685 memb2
= TYPE_FIELDS (TREE_TYPE (memb2
));
5690 if (memb1
== NULL_TREE
&& memb2
== NULL_TREE
)
5692 if (memb1
== NULL_TREE
|| memb2
== NULL_TREE
)
5694 if (DECL_BIT_FIELD_TYPE (memb1
))
5696 if (!DECL_BIT_FIELD_TYPE (memb2
))
5698 if (!layout_compatible_type_p (DECL_BIT_FIELD_TYPE (memb1
),
5699 DECL_BIT_FIELD_TYPE (memb2
)))
5701 if (TYPE_PRECISION (TREE_TYPE (memb1
))
5702 != TYPE_PRECISION (TREE_TYPE (memb2
)))
5705 else if (DECL_BIT_FIELD_TYPE (memb2
))
5707 else if (!layout_compatible_type_p (TREE_TYPE (memb1
), TREE_TYPE (memb2
)))
5709 if ((!lookup_attribute ("no_unique_address", DECL_ATTRIBUTES (memb1
)))
5710 != !lookup_attribute ("no_unique_address", DECL_ATTRIBUTES (memb2
)))
5712 if (!tree_int_cst_equal (bit_position (memb1
), bit_position (memb2
)))
5717 // forked from gcc/cp/semantics.cc is_corresponding_member_aggr
5719 /* Helper function for fold_builtin_is_corresponding_member call.
5720 Return boolean_false_node if MEMBERTYPE1 BASETYPE1::*ARG1 and
5721 MEMBERTYPE2 BASETYPE2::*ARG2 aren't corresponding members,
5722 boolean_true_node if they are corresponding members, or for
5723 non-constant ARG2 the highest member offset for corresponding
5727 is_corresponding_member_aggr (location_t loc
, tree basetype1
, tree membertype1
,
5728 tree arg1
, tree basetype2
, tree membertype2
,
5731 tree field1
= TYPE_FIELDS (basetype1
);
5732 tree field2
= TYPE_FIELDS (basetype2
);
5733 tree ret
= boolean_false_node
;
5736 bool r
= next_common_initial_seqence (field1
, field2
);
5737 if (field1
== NULL_TREE
|| field2
== NULL_TREE
)
5740 && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field1
),
5742 && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field2
),
5745 tree pos
= byte_position (field1
);
5746 if (TREE_CODE (arg1
) == INTEGER_CST
&& tree_int_cst_equal (arg1
, pos
))
5748 if (TREE_CODE (arg2
) == INTEGER_CST
)
5749 return boolean_true_node
;
5752 else if (TREE_CODE (arg1
) != INTEGER_CST
)
5755 else if (ANON_AGGR_TYPE_P (TREE_TYPE (field1
))
5756 && ANON_AGGR_TYPE_P (TREE_TYPE (field2
)))
5758 if ((!lookup_attribute ("no_unique_address",
5759 DECL_ATTRIBUTES (field1
)))
5760 != !lookup_attribute ("no_unique_address",
5761 DECL_ATTRIBUTES (field2
)))
5763 if (!tree_int_cst_equal (bit_position (field1
),
5764 bit_position (field2
)))
5766 bool overlap
= true;
5767 tree pos
= byte_position (field1
);
5768 if (TREE_CODE (arg1
) == INTEGER_CST
)
5770 tree off1
= fold_convert (sizetype
, arg1
);
5771 tree sz1
= TYPE_SIZE_UNIT (TREE_TYPE (field1
));
5772 if (tree_int_cst_lt (off1
, pos
)
5773 || tree_int_cst_le (size_binop (PLUS_EXPR
, pos
, sz1
), off1
))
5776 if (TREE_CODE (arg2
) == INTEGER_CST
)
5778 tree off2
= fold_convert (sizetype
, arg2
);
5779 tree sz2
= TYPE_SIZE_UNIT (TREE_TYPE (field2
));
5780 if (tree_int_cst_lt (off2
, pos
)
5781 || tree_int_cst_le (size_binop (PLUS_EXPR
, pos
, sz2
), off2
))
5784 if (overlap
&& NON_UNION_CLASS_TYPE_P (TREE_TYPE (field1
))
5785 && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field2
)))
5788 if (TREE_CODE (arg1
) == INTEGER_CST
)
5790 = size_binop (MINUS_EXPR
, fold_convert (sizetype
, arg1
), pos
);
5792 if (TREE_CODE (arg2
) == INTEGER_CST
)
5794 = size_binop (MINUS_EXPR
, fold_convert (sizetype
, arg2
), pos
);
5795 tree t1
= TREE_TYPE (field1
);
5796 tree t2
= TREE_TYPE (field2
);
5798 = is_corresponding_member_aggr (loc
, t1
, membertype1
, narg1
, t2
,
5799 membertype2
, narg2
);
5800 if (nret
!= boolean_false_node
)
5802 if (nret
== boolean_true_node
)
5804 if (TREE_CODE (arg1
) == INTEGER_CST
)
5805 return size_binop (PLUS_EXPR
, nret
, pos
);
5806 ret
= size_binop (PLUS_EXPR
, nret
, pos
);
5809 else if (overlap
&& TREE_CODE (TREE_TYPE (field1
)) == UNION_TYPE
5810 && TREE_CODE (TREE_TYPE (field2
)) == UNION_TYPE
)
5813 if (TREE_CODE (arg1
) == INTEGER_CST
)
5815 = size_binop (MINUS_EXPR
, fold_convert (sizetype
, arg1
), pos
);
5817 if (TREE_CODE (arg2
) == INTEGER_CST
)
5819 = size_binop (MINUS_EXPR
, fold_convert (sizetype
, arg2
), pos
);
5820 if (is_corresponding_member_union (TREE_TYPE (field1
),
5822 && is_corresponding_member_union (TREE_TYPE (field2
),
5823 membertype2
, narg2
))
5825 sorry_at (loc
, "%<__builtin_is_corresponding_member%> "
5826 "not well defined for anonymous unions");
5827 return boolean_false_node
;
5833 field1
= DECL_CHAIN (field1
);
5834 field2
= DECL_CHAIN (field2
);
5839 // forked from gcc/cp/call.cc null_member_pointer_value_p
5841 /* Returns true iff T is a null member pointer value (4.11). */
5844 null_member_pointer_value_p (tree t
)
5846 tree type
= TREE_TYPE (t
);
5849 else if (TYPE_PTRMEMFUNC_P (type
))
5850 return (TREE_CODE (t
) == CONSTRUCTOR
&& CONSTRUCTOR_NELTS (t
)
5851 && integer_zerop (CONSTRUCTOR_ELT (t
, 0)->value
));
5852 else if (TYPE_PTRDATAMEM_P (type
))
5853 return integer_all_onesp (t
);
5858 // forked from gcc/cp/semantics.cc fold_builtin_is_corresponding_member
5860 /* Fold __builtin_is_corresponding_member call. */
5863 fold_builtin_is_corresponding_member (location_t loc
, int nargs
, tree
*args
)
5865 /* Unless users call the builtin directly, the following 3 checks should be
5866 ensured from std::is_corresponding_member function template. */
5869 error_at (loc
, "%<__builtin_is_corresponding_member%> "
5870 "needs two arguments");
5871 return boolean_false_node
;
5873 tree arg1
= args
[0];
5874 tree arg2
= args
[1];
5875 if (error_operand_p (arg1
) || error_operand_p (arg2
))
5876 return boolean_false_node
;
5877 if (!TYPE_PTRMEM_P (TREE_TYPE (arg1
)) || !TYPE_PTRMEM_P (TREE_TYPE (arg2
)))
5879 error_at (loc
, "%<__builtin_is_corresponding_member%> "
5880 "argument is not pointer to member");
5881 return boolean_false_node
;
5884 if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg1
))
5885 || !TYPE_PTRDATAMEM_P (TREE_TYPE (arg2
)))
5886 return boolean_false_node
;
5888 tree membertype1
= TREE_TYPE (TREE_TYPE (arg1
));
5889 tree basetype1
= TYPE_OFFSET_BASETYPE (TREE_TYPE (arg1
));
5890 if (!complete_type_or_else (basetype1
, NULL_TREE
))
5891 return boolean_false_node
;
5893 tree membertype2
= TREE_TYPE (TREE_TYPE (arg2
));
5894 tree basetype2
= TYPE_OFFSET_BASETYPE (TREE_TYPE (arg2
));
5895 if (!complete_type_or_else (basetype2
, NULL_TREE
))
5896 return boolean_false_node
;
5898 if (!NON_UNION_CLASS_TYPE_P (basetype1
) || !NON_UNION_CLASS_TYPE_P (basetype2
)
5899 || !std_layout_type_p (basetype1
) || !std_layout_type_p (basetype2
))
5900 return boolean_false_node
;
5902 /* If the member types aren't layout compatible, then they
5903 can't be corresponding members. */
5904 if (!layout_compatible_type_p (membertype1
, membertype2
))
5905 return boolean_false_node
;
5907 if (null_member_pointer_value_p (arg1
) || null_member_pointer_value_p (arg2
))
5908 return boolean_false_node
;
5910 if (TREE_CODE (arg1
) == INTEGER_CST
&& TREE_CODE (arg2
) == INTEGER_CST
5911 && !tree_int_cst_equal (arg1
, arg2
))
5912 return boolean_false_node
;
5914 if (TREE_CODE (arg2
) == INTEGER_CST
&& TREE_CODE (arg1
) != INTEGER_CST
)
5916 std::swap (arg1
, arg2
);
5917 std::swap (membertype1
, membertype2
);
5918 std::swap (basetype1
, basetype2
);
5921 tree ret
= is_corresponding_member_aggr (loc
, basetype1
, membertype1
, arg1
,
5922 basetype2
, membertype2
, arg2
);
5923 if (TREE_TYPE (ret
) == boolean_type_node
)
5925 /* If both arg1 and arg2 are INTEGER_CSTs, is_corresponding_member_aggr
5926 already returns boolean_{true,false}_node whether those particular
5927 members are corresponding members or not. Otherwise, if only
5928 one of them is INTEGER_CST (canonicalized to first being INTEGER_CST
5929 above), it returns boolean_false_node if it is certainly not a
5930 corresponding member and otherwise we need to do a runtime check that
5931 those two OFFSET_TYPE offsets are equal.
5932 If neither of the operands is INTEGER_CST, is_corresponding_member_aggr
5933 returns the largest offset at which the members would be corresponding
5934 members, so perform arg1 <= ret && arg1 == arg2 runtime check. */
5935 gcc_assert (TREE_CODE (arg2
) != INTEGER_CST
);
5936 if (TREE_CODE (arg1
) == INTEGER_CST
)
5937 return fold_build2 (EQ_EXPR
, boolean_type_node
, arg1
,
5938 fold_convert (TREE_TYPE (arg1
), arg2
));
5939 ret
= fold_build2 (LE_EXPR
, boolean_type_node
,
5940 fold_convert (pointer_sized_int_node
, arg1
),
5941 fold_convert (pointer_sized_int_node
, ret
));
5942 return fold_build2 (TRUTH_AND_EXPR
, boolean_type_node
, ret
,
5943 fold_build2 (EQ_EXPR
, boolean_type_node
, arg1
,
5944 fold_convert (TREE_TYPE (arg1
), arg2
)));
5947 // forked from gcc/cp/tree.cc lvalue_type
5949 /* The type of ARG when used as an lvalue. */
5952 lvalue_type (tree arg
)
5954 tree type
= TREE_TYPE (arg
);
5958 // forked from gcc/c-family/c-warn.cc lvalue_error
5960 /* Print an error message for an invalid lvalue. USE says
5961 how the lvalue is being used and so selects the error message. LOC
5962 is the location for the error. */
5965 lvalue_error (location_t loc
, enum lvalue_use use
)
5970 error_at (loc
, "lvalue required as left operand of assignment");
5973 error_at (loc
, "lvalue required as increment operand");
5976 error_at (loc
, "lvalue required as decrement operand");
5979 error_at (loc
, "lvalue required as unary %<&%> operand");
5982 error_at (loc
, "lvalue required in %<asm%> statement");
5985 rust_unreachable ();
5989 // forked from gcc/cp/cp--gimplify.cc cp_fold_maybe_rvalue
5991 /* Fold expression X which is used as an rvalue if RVAL is true. */
5994 cp_fold_maybe_rvalue (tree x
, bool rval
)
6000 x
= mark_rvalue_use (x
);
6001 if (rval
&& DECL_P (x
) && !TYPE_REF_P (TREE_TYPE (x
)))
6003 tree v
= decl_constant_value (x
);
6004 if (v
!= x
&& v
!= error_mark_node
)
6015 // forked from gcc/cp/cp--gimplify.cc cp_fold_rvalue
6017 /* Fold expression X which is used as an rvalue. */
6020 cp_fold_rvalue (tree x
)
6022 return cp_fold_maybe_rvalue (x
, true);
6025 /* Returns true iff class T has a constexpr destructor or has an
6026 implicitly declared destructor that we can't tell if it's constexpr
6027 without forcing a lazy declaration (which might cause undesired
6031 type_maybe_constexpr_destructor (tree t
)
6033 /* Until C++20, only trivial destruction is constexpr. */
6034 if (TYPE_HAS_TRIVIAL_DESTRUCTOR (t
))
6037 if (CLASS_TYPE_P (t
) && CLASSTYPE_LAZY_DESTRUCTOR (t
))
6038 /* Assume it's constexpr. */
6040 tree fn
= CLASSTYPE_DESTRUCTOR (t
);
6041 return (fn
&& Compile::maybe_constexpr_fn (fn
));
6044 /* T is a non-literal type used in a context which requires a constant
6045 expression. Explain why it isn't literal. */
6048 explain_non_literal_class (tree t
)
6050 static hash_set
<tree
> *diagnosed
;
6052 if (!CLASS_TYPE_P (t
))
6054 t
= TYPE_MAIN_VARIANT (t
);
6056 if (diagnosed
== NULL
)
6057 diagnosed
= new hash_set
<tree
>;
6058 if (diagnosed
->add (t
))
6059 /* Already explained. */
6062 auto_diagnostic_group d
;
6063 inform (UNKNOWN_LOCATION
, "%q+T is not literal because:", t
);
6064 if (LAMBDA_TYPE_P (t
))
6065 inform (UNKNOWN_LOCATION
,
6066 " %qT is a closure type, which is only literal in "
6069 else if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t
)
6070 && !type_maybe_constexpr_destructor (t
))
6071 inform (UNKNOWN_LOCATION
, " %q+T does not have %<constexpr%> destructor",
6073 else if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t
))
6074 inform (UNKNOWN_LOCATION
, " %q+T has a non-trivial destructor", t
);
6075 else if (CLASSTYPE_NON_AGGREGATE (t
) && !TYPE_HAS_TRIVIAL_DFLT (t
)
6076 && !LAMBDA_TYPE_P (t
) && !TYPE_HAS_CONSTEXPR_CTOR (t
))
6078 inform (UNKNOWN_LOCATION
,
6079 " %q+T is not an aggregate, does not have a trivial "
6080 "default constructor, and has no %<constexpr%> constructor that "
6081 "is not a copy or move constructor",
6083 if (type_has_non_user_provided_default_constructor (t
))
6084 /* Note that we can't simply call locate_ctor because when the
6085 constructor is deleted it just returns NULL_TREE. */
6086 for (ovl_iterator
iter (CLASSTYPE_CONSTRUCTORS (t
)); iter
; ++iter
)
6089 tree parms
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
6091 parms
= skip_artificial_parms_for (fn
, parms
);
6093 if (sufficient_parms_p (parms
))
6095 Compile::explain_invalid_constexpr_fn (fn
);
6102 tree binfo
, base_binfo
, field
;
6104 for (binfo
= TYPE_BINFO (t
), i
= 0;
6105 BINFO_BASE_ITERATE (binfo
, i
, base_binfo
); i
++)
6107 tree basetype
= TREE_TYPE (base_binfo
);
6108 if (!CLASSTYPE_LITERAL_P (basetype
))
6110 inform (UNKNOWN_LOCATION
,
6111 " base class %qT of %q+T is non-literal", basetype
, t
);
6112 explain_non_literal_class (basetype
);
6116 for (field
= TYPE_FIELDS (t
); field
; field
= TREE_CHAIN (field
))
6119 if (TREE_CODE (field
) != FIELD_DECL
)
6121 ftype
= TREE_TYPE (field
);
6122 if (!Compile::literal_type_p (ftype
))
6124 inform (DECL_SOURCE_LOCATION (field
),
6125 " non-static data member %qD has non-literal type",
6127 if (CLASS_TYPE_P (ftype
))
6128 explain_non_literal_class (ftype
);
6130 if (RS_TYPE_VOLATILE_P (ftype
))
6131 inform (DECL_SOURCE_LOCATION (field
),
6132 " non-static data member %qD has volatile type", field
);
6137 // forked from gcc/cp/call.cc reference_related_p
6139 /* Returns nonzero if T1 is reference-related to T2. */
6142 reference_related_p (tree t1
, tree t2
)
6144 if (t1
== error_mark_node
|| t2
== error_mark_node
)
6147 t1
= TYPE_MAIN_VARIANT (t1
);
6148 t2
= TYPE_MAIN_VARIANT (t2
);
6152 Given types "cv1 T1" and "cv2 T2," "cv1 T1" is reference-related
6153 to "cv2 T2" if T1 is similar to T2, or T1 is a base class of T2. */
6154 return (similar_type_p (t1
, t2
)
6155 /*|| (CLASS_TYPE_P (t1) && CLASS_TYPE_P (t2)
6156 && DERIVED_FROM_P (t1, t2))*/);
6159 // forked from gcc/cp/typeck2.cc ordinary_char_type_p
6161 /* True iff TYPE is a C++20 "ordinary" character type. */
6164 ordinary_char_type_p (tree type
)
6166 type
= TYPE_MAIN_VARIANT (type
);
6167 return (type
== char_type_node
|| type
== signed_char_type_node
6168 || type
== unsigned_char_type_node
);
6171 // forked from gcc/cp/typeck2.cc array_string_literal_compatible_p
6173 /* True iff the string literal INIT has a type suitable for initializing array
6177 array_string_literal_compatible_p (tree type
, tree init
)
6179 tree to_char_type
= TYPE_MAIN_VARIANT (TREE_TYPE (type
));
6180 tree from_char_type
= TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (init
)));
6182 if (to_char_type
== from_char_type
)
6184 /* The array element type does not match the initializing string
6185 literal element type; this is only allowed when both types are
6186 ordinary character type. There are no string literals of
6187 signed or unsigned char type in the language, but we can get
6188 them internally from converting braced-init-lists to
6190 if (ordinary_char_type_p (to_char_type
)
6191 && ordinary_char_type_p (from_char_type
))
6198 using namespace Rust
;
6200 #include "gt-rust-rust-tree.h"