1 /* Build expressions with type checking for C++ compiler.
2 Copyright (C) 1987, 88, 89, 92-97, 1998 Free Software Foundation, Inc.
3 Hacked by Michael Tiemann (tiemann@cygnus.com)
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 /* This file is part of the C++ front end.
24 It contains routines to build C++ expressions given their operands,
25 including computing the types of the result, C and C++ specific error
26 checks, and some optimization.
28 There are also routines to build RETURN_STMT nodes and CASE_STMT nodes,
29 and to process initializations in declarations (since they work
30 like a strange sort of assignment). */
42 extern void compiler_error ();
44 static tree convert_for_assignment
PROTO((tree
, tree
, char*, tree
,
46 static tree pointer_int_sum
PROTO((enum tree_code
, tree
, tree
));
47 static tree rationalize_conditional_expr
PROTO((enum tree_code
, tree
));
48 static int comp_target_parms
PROTO((tree
, tree
, int));
49 static int comp_ptr_ttypes_real
PROTO((tree
, tree
, int));
50 static int comp_ptr_ttypes_const
PROTO((tree
, tree
));
51 static int comp_ptr_ttypes_reinterpret
PROTO((tree
, tree
));
52 static int comp_array_types
PROTO((int (*) (tree
, tree
, int), tree
,
54 static tree build_ptrmemfunc1
PROTO((tree
, tree
, tree
, tree
, tree
));
55 static tree common_base_type
PROTO((tree
, tree
));
57 static tree convert_sequence
PROTO((tree
, tree
));
59 static tree lookup_anon_field
PROTO((tree
, tree
));
60 static tree pointer_diff
PROTO((tree
, tree
, tree
));
61 static tree qualify_type
PROTO((tree
, tree
));
62 static tree get_delta_difference
PROTO((tree
, tree
, int));
64 /* Return the target type of TYPE, which meas return T for:
65 T*, T&, T[], T (...), and otherwise, just T. */
71 if (TREE_CODE (type
) == REFERENCE_TYPE
)
72 type
= TREE_TYPE (type
);
73 while (TREE_CODE (type
) == POINTER_TYPE
74 || TREE_CODE (type
) == ARRAY_TYPE
75 || TREE_CODE (type
) == FUNCTION_TYPE
76 || TREE_CODE (type
) == METHOD_TYPE
77 || TREE_CODE (type
) == OFFSET_TYPE
)
78 type
= TREE_TYPE (type
);
82 /* Do `exp = require_complete_type (exp);' to make sure exp
83 does not have an incomplete type. (That includes void types.) */
86 require_complete_type (value
)
91 if (processing_template_decl
)
94 if (TREE_CODE (value
) == OVERLOAD
)
95 type
= unknown_type_node
;
97 type
= TREE_TYPE (value
);
99 /* First, detect a valid value with a complete type. */
100 if (TYPE_SIZE (type
) != 0
101 && type
!= void_type_node
102 && ! (TYPE_LANG_SPECIFIC (type
)
103 && (IS_SIGNATURE_POINTER (type
) || IS_SIGNATURE_REFERENCE (type
))
104 && TYPE_SIZE (SIGNATURE_TYPE (type
)) == 0))
107 /* If we see X::Y, we build an OFFSET_TYPE which has
108 not been laid out. Try to avoid an error by interpreting
109 it as this->X::Y, if reasonable. */
110 if (TREE_CODE (value
) == OFFSET_REF
111 && current_class_ref
!= 0
112 && TREE_OPERAND (value
, 0) == current_class_ref
)
114 tree base
, member
= TREE_OPERAND (value
, 1);
115 tree basetype
= TYPE_OFFSET_BASETYPE (type
);
116 my_friendly_assert (TREE_CODE (member
) == FIELD_DECL
, 305);
117 base
= convert_pointer_to (basetype
, current_class_ptr
);
118 value
= build (COMPONENT_REF
, TREE_TYPE (member
),
119 build_indirect_ref (base
, NULL_PTR
), member
);
120 return require_complete_type (value
);
123 if (IS_AGGR_TYPE (type
) && CLASSTYPE_TEMPLATE_INSTANTIATION (type
))
125 instantiate_class_template (TYPE_MAIN_VARIANT (type
));
126 if (TYPE_SIZE (type
) != 0)
130 incomplete_type_error (value
, type
);
131 return error_mark_node
;
138 if (type
== NULL_TREE
)
139 /* Rather than crash, we return something sure to cause an error
141 return error_mark_node
;
143 if (type
== error_mark_node
|| TYPE_SIZE (type
) != NULL_TREE
)
145 else if (TREE_CODE (type
) == ARRAY_TYPE
&& TYPE_DOMAIN (type
))
147 tree t
= complete_type (TREE_TYPE (type
));
148 if (TYPE_SIZE (t
) != NULL_TREE
&& ! processing_template_decl
)
150 TYPE_NEEDS_CONSTRUCTING (type
)
151 = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (t
));
152 TYPE_NEEDS_DESTRUCTOR (type
)
153 = TYPE_NEEDS_DESTRUCTOR (TYPE_MAIN_VARIANT (t
));
155 else if (IS_AGGR_TYPE (type
) && CLASSTYPE_TEMPLATE_INSTANTIATION (type
))
156 instantiate_class_template (TYPE_MAIN_VARIANT (type
));
161 /* Return truthvalue of whether type of EXP is instantiated. */
167 return (TREE_CODE (exp
) == OVERLOAD
168 || TREE_CODE (exp
) == TREE_LIST
169 || TREE_TYPE (exp
) == unknown_type_node
170 || (TREE_CODE (TREE_TYPE (exp
)) == OFFSET_TYPE
171 && TREE_TYPE (TREE_TYPE (exp
)) == unknown_type_node
));
174 /* Return truthvalue of whether T is function (or pfn) type. */
180 return (TREE_CODE (t
) == FUNCTION_TYPE
|| TREE_CODE (t
) == METHOD_TYPE
181 || (TREE_CODE (t
) == POINTER_TYPE
182 && (TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
183 || TREE_CODE (TREE_TYPE (t
)) == METHOD_TYPE
)));
186 /* Do `exp = require_instantiated_type (type, exp);' to make sure EXP
187 does not have an uninstantiated type.
188 TYPE is type to instantiate with, if uninstantiated. */
191 require_instantiated_type (type
, exp
, errval
)
192 tree type
, exp
, errval
;
194 if (TREE_TYPE (exp
) == NULL_TREE
)
196 error ("argument list may not have an initializer list");
200 if (TREE_CODE (exp
) == OVERLOAD
201 || TREE_TYPE (exp
) == unknown_type_node
202 || (TREE_CODE (TREE_TYPE (exp
)) == OFFSET_TYPE
203 && TREE_TYPE (TREE_TYPE (exp
)) == unknown_type_node
))
205 exp
= instantiate_type (type
, exp
, 1);
206 if (TREE_TYPE (exp
) == error_mark_node
)
212 /* Return a variant of TYPE which has all the type qualifiers of LIKE
213 as well as those of TYPE. */
216 qualify_type (type
, like
)
219 int constflag
= TYPE_READONLY (type
) || TYPE_READONLY (like
);
220 int volflag
= TYPE_VOLATILE (type
) || TYPE_VOLATILE (like
);
221 /* @@ Must do member pointers here. */
222 return cp_build_type_variant (type
, constflag
, volflag
);
225 /* Return the common type of two parameter lists.
226 We assume that comptypes has already been done and returned 1;
227 if that isn't so, this may crash.
229 As an optimization, free the space we allocate if the parameter
230 lists are already common. */
236 tree oldargs
= p1
, newargs
, n
;
239 char *first_obj
= (char *) oballoc (0);
241 len
= list_length (p1
);
242 newargs
= tree_last (p1
);
244 if (newargs
== void_list_node
)
253 newargs
= tree_cons (NULL_TREE
, NULL_TREE
, newargs
);
258 p1
= TREE_CHAIN (p1
), p2
= TREE_CHAIN (p2
), n
= TREE_CHAIN (n
), i
++)
260 if (TREE_PURPOSE (p1
) && !TREE_PURPOSE (p2
))
262 TREE_PURPOSE (n
) = TREE_PURPOSE (p1
);
265 else if (! TREE_PURPOSE (p1
))
267 if (TREE_PURPOSE (p2
))
269 TREE_PURPOSE (n
) = TREE_PURPOSE (p2
);
275 if (1 != simple_cst_equal (TREE_PURPOSE (p1
), TREE_PURPOSE (p2
)))
277 TREE_PURPOSE (n
) = TREE_PURPOSE (p2
);
279 if (TREE_VALUE (p1
) != TREE_VALUE (p2
))
282 TREE_VALUE (n
) = common_type (TREE_VALUE (p1
), TREE_VALUE (p2
));
285 TREE_VALUE (n
) = TREE_VALUE (p1
);
296 /* Given a type, perhaps copied for a typedef,
297 find the "original" version of it. */
302 while (TYPE_NAME (t
) != NULL_TREE
)
304 tree x
= TYPE_NAME (t
);
305 if (TREE_CODE (x
) != TYPE_DECL
)
307 x
= DECL_ORIGINAL_TYPE (x
);
315 /* Return the common type of two types.
316 We assume that comptypes has already been done and returned 1;
317 if that isn't so, this may crash.
319 This is the type for the result of most arithmetic operations
320 if the operands have the given two types.
322 We do not deal with enumeral types here because they have already been
323 converted to integer types. */
329 register enum tree_code code1
;
330 register enum tree_code code2
;
333 /* Save time if the two types are the same. */
336 t1
= original_type (t1
);
337 t2
= original_type (t2
);
341 /* If one type is nonsense, use the other. */
342 if (t1
== error_mark_node
)
344 if (t2
== error_mark_node
)
347 /* Merge the attributes. */
348 attributes
= merge_machine_type_attributes (t1
, t2
);
350 { register tree a1
, a2
;
351 a1
= TYPE_ATTRIBUTES (t1
);
352 a2
= TYPE_ATTRIBUTES (t2
);
354 /* Either one unset? Take the set one. */
356 if (!(attributes
= a1
))
359 /* One that completely contains the other? Take it. */
361 else if (a2
&& !attribute_list_contained (a1
, a2
))
363 if (attribute_list_contained (a2
, a1
))
367 /* Pick the longest list, and hang on the other list. */
368 /* ??? For the moment we punt on the issue of attrs with args. */
370 if (list_length (a1
) < list_length (a2
))
371 attributes
= a2
, a2
= a1
;
373 for (; a2
; a2
= TREE_CHAIN (a2
))
374 if (lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2
)),
375 attributes
) == NULL_TREE
)
378 TREE_CHAIN (a1
) = attributes
;
385 /* Treat an enum type as the unsigned integer type of the same width. */
387 if (TREE_CODE (t1
) == ENUMERAL_TYPE
)
388 t1
= type_for_size (TYPE_PRECISION (t1
), 1);
389 if (TREE_CODE (t2
) == ENUMERAL_TYPE
)
390 t2
= type_for_size (TYPE_PRECISION (t2
), 1);
392 if (TYPE_PTRMEMFUNC_P (t1
))
393 t1
= TYPE_PTRMEMFUNC_FN_TYPE (t1
);
394 if (TYPE_PTRMEMFUNC_P (t2
))
395 t2
= TYPE_PTRMEMFUNC_FN_TYPE (t2
);
397 code1
= TREE_CODE (t1
);
398 code2
= TREE_CODE (t2
);
400 /* If one type is complex, form the common type of the non-complex
401 components, then make that complex. Use T1 or T2 if it is the
403 if (code1
== COMPLEX_TYPE
|| code2
== COMPLEX_TYPE
)
405 tree subtype1
= code1
== COMPLEX_TYPE
? TREE_TYPE (t1
) : t1
;
406 tree subtype2
= code2
== COMPLEX_TYPE
? TREE_TYPE (t2
) : t2
;
407 tree subtype
= common_type (subtype1
, subtype2
);
409 if (code1
== COMPLEX_TYPE
&& TREE_TYPE (t1
) == subtype
)
410 return build_type_attribute_variant (t1
, attributes
);
411 else if (code2
== COMPLEX_TYPE
&& TREE_TYPE (t2
) == subtype
)
412 return build_type_attribute_variant (t2
, attributes
);
414 return build_type_attribute_variant (build_complex_type (subtype
),
422 /* If only one is real, use it as the result. */
424 if (code1
== REAL_TYPE
&& code2
!= REAL_TYPE
)
425 return build_type_attribute_variant (t1
, attributes
);
427 if (code2
== REAL_TYPE
&& code1
!= REAL_TYPE
)
428 return build_type_attribute_variant (t2
, attributes
);
430 /* Both real or both integers; use the one with greater precision. */
432 if (TYPE_PRECISION (t1
) > TYPE_PRECISION (t2
))
433 return build_type_attribute_variant (t1
, attributes
);
434 else if (TYPE_PRECISION (t2
) > TYPE_PRECISION (t1
))
435 return build_type_attribute_variant (t2
, attributes
);
437 /* Same precision. Prefer longs to ints even when same size. */
439 if (TYPE_MAIN_VARIANT (t1
) == long_unsigned_type_node
440 || TYPE_MAIN_VARIANT (t2
) == long_unsigned_type_node
)
441 return build_type_attribute_variant (long_unsigned_type_node
,
444 if (TYPE_MAIN_VARIANT (t1
) == long_integer_type_node
445 || TYPE_MAIN_VARIANT (t2
) == long_integer_type_node
)
447 /* But preserve unsignedness from the other type,
448 since long cannot hold all the values of an unsigned int. */
449 if (TREE_UNSIGNED (t1
) || TREE_UNSIGNED (t2
))
450 t1
= long_unsigned_type_node
;
452 t1
= long_integer_type_node
;
453 return build_type_attribute_variant (t1
, attributes
);
456 if (TYPE_MAIN_VARIANT (t1
) == long_double_type_node
457 || TYPE_MAIN_VARIANT (t2
) == long_double_type_node
)
458 return build_type_attribute_variant (long_double_type_node
,
461 /* Otherwise prefer the unsigned one. */
463 if (TREE_UNSIGNED (t1
))
464 return build_type_attribute_variant (t1
, attributes
);
466 return build_type_attribute_variant (t2
, attributes
);
470 /* For two pointers, do this recursively on the target type,
471 and combine the qualifiers of the two types' targets. */
472 /* This code was turned off; I don't know why.
473 But ANSI C++ specifies doing this with the qualifiers.
474 So I turned it on again. */
476 tree tt1
= TYPE_MAIN_VARIANT (TREE_TYPE (t1
));
477 tree tt2
= TYPE_MAIN_VARIANT (TREE_TYPE (t2
));
479 = TYPE_READONLY (TREE_TYPE (t1
)) || TYPE_READONLY (TREE_TYPE (t2
));
481 = TYPE_VOLATILE (TREE_TYPE (t1
)) || TYPE_VOLATILE (TREE_TYPE (t2
));
486 else if (tt1
== void_type_node
|| tt2
== void_type_node
)
487 target
= void_type_node
;
488 else if (tt1
== unknown_type_node
)
490 else if (tt2
== unknown_type_node
)
493 target
= common_type (tt1
, tt2
);
495 target
= cp_build_type_variant (target
, constp
, volatilep
);
496 if (code1
== POINTER_TYPE
)
497 t1
= build_pointer_type (target
);
499 t1
= build_reference_type (target
);
500 t1
= build_type_attribute_variant (t1
, attributes
);
502 if (TREE_CODE (target
) == METHOD_TYPE
)
503 t1
= build_ptrmemfunc_type (t1
);
510 tree elt
= common_type (TREE_TYPE (t1
), TREE_TYPE (t2
));
511 /* Save space: see if the result is identical to one of the args. */
512 if (elt
== TREE_TYPE (t1
) && TYPE_DOMAIN (t1
))
513 return build_type_attribute_variant (t1
, attributes
);
514 if (elt
== TREE_TYPE (t2
) && TYPE_DOMAIN (t2
))
515 return build_type_attribute_variant (t2
, attributes
);
516 /* Merge the element types, and have a size if either arg has one. */
517 t1
= build_cplus_array_type
518 (elt
, TYPE_DOMAIN (TYPE_DOMAIN (t1
) ? t1
: t2
));
519 return build_type_attribute_variant (t1
, attributes
);
523 /* Function types: prefer the one that specified arg types.
524 If both do, merge the arg types. Also merge the return types. */
526 tree valtype
= common_type (TREE_TYPE (t1
), TREE_TYPE (t2
));
527 tree p1
= TYPE_ARG_TYPES (t1
);
528 tree p2
= TYPE_ARG_TYPES (t2
);
531 /* Save space: see if the result is identical to one of the args. */
532 if (valtype
== TREE_TYPE (t1
) && ! p2
)
533 return build_type_attribute_variant (t1
, attributes
);
534 if (valtype
== TREE_TYPE (t2
) && ! p1
)
535 return build_type_attribute_variant (t2
, attributes
);
537 /* Simple way if one arg fails to specify argument types. */
538 if (p1
== NULL_TREE
|| TREE_VALUE (p1
) == void_type_node
)
540 rval
= build_function_type (valtype
, p2
);
541 if ((raises
= TYPE_RAISES_EXCEPTIONS (t2
)))
542 rval
= build_exception_variant (rval
, raises
);
543 return build_type_attribute_variant (rval
, attributes
);
545 raises
= TYPE_RAISES_EXCEPTIONS (t1
);
546 if (p2
== NULL_TREE
|| TREE_VALUE (p2
) == void_type_node
)
548 rval
= build_function_type (valtype
, p1
);
550 rval
= build_exception_variant (rval
, raises
);
551 return build_type_attribute_variant (rval
, attributes
);
554 rval
= build_function_type (valtype
, commonparms (p1
, p2
));
555 rval
= build_exception_variant (rval
, raises
);
556 return build_type_attribute_variant (rval
, attributes
);
561 t1
= TYPE_MAIN_VARIANT (t1
);
562 t2
= TYPE_MAIN_VARIANT (t2
);
564 if (DERIVED_FROM_P (t1
, t2
) && binfo_or_else (t1
, t2
))
565 return build_type_attribute_variant (t1
, attributes
);
566 else if (binfo_or_else (t2
, t1
))
567 return build_type_attribute_variant (t2
, attributes
);
569 compiler_error ("common_type called with uncommon aggregate types");
572 if (TREE_CODE (TREE_TYPE (t1
)) == TREE_CODE (TREE_TYPE (t2
)))
574 /* Get this value the long way, since TYPE_METHOD_BASETYPE
575 is just the main variant of this. */
579 tree b1
= TYPE_OFFSET_BASETYPE (t1
);
580 tree b2
= TYPE_OFFSET_BASETYPE (t2
);
582 if (comptypes (b1
, b2
, 1)
583 || (DERIVED_FROM_P (b1
, b2
) && binfo_or_else (b1
, b2
)))
584 basetype
= TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t2
)));
587 if (binfo_or_else (b2
, b1
) == NULL_TREE
)
588 compiler_error ("common_type called with uncommon method types");
589 basetype
= TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t1
)));
592 raises
= TYPE_RAISES_EXCEPTIONS (t1
);
594 /* If this was a member function type, get back to the
595 original type of type member function (i.e., without
596 the class instance variable up front. */
597 t1
= build_function_type (TREE_TYPE (t1
),
598 TREE_CHAIN (TYPE_ARG_TYPES (t1
)));
599 t2
= build_function_type (TREE_TYPE (t2
),
600 TREE_CHAIN (TYPE_ARG_TYPES (t2
)));
601 t3
= common_type (t1
, t2
);
602 t3
= build_cplus_method_type (basetype
, TREE_TYPE (t3
),
603 TYPE_ARG_TYPES (t3
));
604 t1
= build_exception_variant (t3
, raises
);
607 compiler_error ("common_type called with uncommon method types");
609 return build_type_attribute_variant (t1
, attributes
);
612 if (TREE_TYPE (t1
) == TREE_TYPE (t2
))
614 tree b1
= TYPE_OFFSET_BASETYPE (t1
);
615 tree b2
= TYPE_OFFSET_BASETYPE (t2
);
617 if (comptypes (b1
, b2
, 1)
618 || (DERIVED_FROM_P (b1
, b2
) && binfo_or_else (b1
, b2
)))
619 return build_type_attribute_variant (t2
, attributes
);
620 else if (binfo_or_else (b2
, b1
))
621 return build_type_attribute_variant (t1
, attributes
);
623 compiler_error ("common_type called with uncommon member types");
626 return build_type_attribute_variant (t1
, attributes
);
630 /* Return 1 if TYPE1 and TYPE2 raise the same exceptions. */
633 compexcepttypes (t1
, t2
)
636 return TYPE_RAISES_EXCEPTIONS (t1
) == TYPE_RAISES_EXCEPTIONS (t2
);
640 comp_array_types (cmp
, t1
, t2
, strict
)
641 register int (*cmp
) PROTO((tree
, tree
, int));
645 tree d1
= TYPE_DOMAIN (t1
);
646 tree d2
= TYPE_DOMAIN (t2
);
648 /* Target types must match incl. qualifiers. */
649 if (!(TREE_TYPE (t1
) == TREE_TYPE (t2
)
650 || (*cmp
) (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
)))
653 /* Sizes must match unless one is missing or variable. */
654 if (d1
== 0 || d2
== 0 || d1
== d2
655 || TREE_CODE (TYPE_MIN_VALUE (d1
)) != INTEGER_CST
656 || TREE_CODE (TYPE_MIN_VALUE (d2
)) != INTEGER_CST
657 || TREE_CODE (TYPE_MAX_VALUE (d1
)) != INTEGER_CST
658 || TREE_CODE (TYPE_MAX_VALUE (d2
)) != INTEGER_CST
)
661 return ((TREE_INT_CST_LOW (TYPE_MIN_VALUE (d1
))
662 == TREE_INT_CST_LOW (TYPE_MIN_VALUE (d2
)))
663 && (TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d1
))
664 == TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d2
)))
665 && (TREE_INT_CST_LOW (TYPE_MAX_VALUE (d1
))
666 == TREE_INT_CST_LOW (TYPE_MAX_VALUE (d2
)))
667 && (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d1
))
668 == TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d2
))));
671 /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
672 or various other operations. This is what ANSI C++ speaks of as
675 For C++: argument STRICT says we should be strict about this
678 2 : strict, except that if one type is a reference and
679 the other is not, compare the target type of the
680 reference to the type that's not a reference (ARM, p308).
681 This is used for checking for invalid overloading.
682 1 : strict (compared according to ANSI C)
683 This is used for checking whether two function decls match.
684 0 : <= (compared according to C++)
685 -1: <= or >= (relaxed)
687 Otherwise, pointers involving base classes and derived classes can
688 be mixed as valid: i.e. a pointer to a derived class may be converted
689 to a pointer to one of its base classes, as per C++. A pointer to
690 a derived class may be passed as a parameter to a function expecting a
691 pointer to a base classes. These allowances do not commute. In this
692 case, TYPE1 is assumed to be the base class, and TYPE2 is assumed to
693 be the derived class. */
696 comptypes (type1
, type2
, strict
)
700 register tree t1
= type1
;
701 register tree t2
= type2
;
704 /* Suppress errors caused by previously reported errors */
709 /* This should never happen. */
710 my_friendly_assert (t1
!= error_mark_node
, 307);
712 if (t2
== error_mark_node
)
717 /* Treat an enum type as the unsigned integer type of the same width. */
719 if (TREE_CODE (t1
) == ENUMERAL_TYPE
)
720 t1
= type_for_size (TYPE_PRECISION (t1
), 1);
721 if (TREE_CODE (t2
) == ENUMERAL_TYPE
)
722 t2
= type_for_size (TYPE_PRECISION (t2
), 1);
728 if (TYPE_PTRMEMFUNC_P (t1
))
729 t1
= TYPE_PTRMEMFUNC_FN_TYPE (t1
);
730 if (TYPE_PTRMEMFUNC_P (t2
))
731 t2
= TYPE_PTRMEMFUNC_FN_TYPE (t2
);
733 /* Different classes of types can't be compatible. */
735 if (TREE_CODE (t1
) != TREE_CODE (t2
))
738 && ((TREE_CODE (t1
) == REFERENCE_TYPE
)
739 ^ (TREE_CODE (t2
) == REFERENCE_TYPE
)))
741 if (TREE_CODE (t1
) == REFERENCE_TYPE
)
742 return comptypes (TREE_TYPE (t1
), t2
, 1);
743 return comptypes (t1
, TREE_TYPE (t2
), 1);
751 /* Qualifiers must match. */
753 if (TYPE_READONLY (t1
) != TYPE_READONLY (t2
))
755 if (TYPE_VOLATILE (t1
) != TYPE_VOLATILE (t2
))
758 /* Allow for two different type nodes which have essentially the same
759 definition. Note that we already checked for equality of the type
760 qualifiers (just above). */
762 if (TYPE_MAIN_VARIANT (t1
) == TYPE_MAIN_VARIANT (t2
))
765 /* ??? COMP_TYPE_ATTRIBUTES is currently useless for variables as each
766 attribute is its own main variant (`val' will remain 0). */
767 #ifndef COMP_TYPE_ATTRIBUTES
768 #define COMP_TYPE_ATTRIBUTES(t1,t2) 1
771 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
772 if (! (attrval
= COMP_TYPE_ATTRIBUTES (t1
, t2
)))
775 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
778 switch (TREE_CODE (t1
))
780 case TEMPLATE_TEMPLATE_PARM
:
781 if (TEMPLATE_TYPE_IDX (t1
) != TEMPLATE_TYPE_IDX (t2
)
782 || TEMPLATE_TYPE_LEVEL (t1
) != TEMPLATE_TYPE_LEVEL (t2
))
784 if (! CLASSTYPE_TEMPLATE_INFO (t1
) && ! CLASSTYPE_TEMPLATE_INFO (t2
))
786 /* Don't check inheritance. */
792 if (CLASSTYPE_TEMPLATE_INFO (t1
) && CLASSTYPE_TEMPLATE_INFO (t2
)
793 && (CLASSTYPE_TI_TEMPLATE (t1
) == CLASSTYPE_TI_TEMPLATE (t2
)
794 || TREE_CODE (t1
) == TEMPLATE_TEMPLATE_PARM
))
795 return comp_template_args (CLASSTYPE_TI_ARGS (t1
),
796 CLASSTYPE_TI_ARGS (t2
));
802 val
= (comptypes (build_pointer_type (TYPE_OFFSET_BASETYPE (t1
)),
803 build_pointer_type (TYPE_OFFSET_BASETYPE (t2
)), strict
)
804 && comptypes (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
));
808 if (! compexcepttypes (t1
, t2
))
811 /* This case is anti-symmetrical!
812 One can pass a base member (or member function)
813 to something expecting a derived member (or member function),
814 but not vice-versa! */
816 val
= (comptypes (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
)
817 && compparms (TYPE_ARG_TYPES (t1
),
818 TYPE_ARG_TYPES (t2
), strict
));
832 if (TREE_CODE (t1
) == RECORD_TYPE
&& TREE_CODE (t2
) == RECORD_TYPE
)
836 rval
= t1
== t2
|| DERIVED_FROM_P (t1
, t2
);
845 val
= DERIVED_FROM_P (t2
, t1
);
852 val
= comptypes (t1
, t2
, strict
);
856 if (! compexcepttypes (t1
, t2
))
859 val
= ((TREE_TYPE (t1
) == TREE_TYPE (t2
)
860 || comptypes (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
))
861 && compparms (TYPE_ARG_TYPES (t1
), TYPE_ARG_TYPES (t2
), strict
));
865 /* Target types must match incl. qualifiers. */
866 val
= comp_array_types (comptypes
, t1
, t2
, strict
);
869 case TEMPLATE_TYPE_PARM
:
870 return TEMPLATE_TYPE_IDX (t1
) == TEMPLATE_TYPE_IDX (t2
)
871 && TEMPLATE_TYPE_LEVEL (t1
) == TEMPLATE_TYPE_LEVEL (t2
);
874 if (TYPE_IDENTIFIER (t1
) != TYPE_IDENTIFIER (t2
))
876 return comptypes (TYPE_CONTEXT (t1
), TYPE_CONTEXT (t2
), 1);
881 return attrval
== 2 && val
== 1 ? 2 : val
;
884 /* Return 1 or -1 if TTL and TTR are pointers to types that are equivalent,
885 ignoring their qualifiers, 0 if not. Return 1 means that TTR can be
886 converted to TTL. Return -1 means that TTL can be converted to TTR but
889 NPTRS is the number of pointers we can strip off and keep cool.
890 This is used to permit (for aggr A, aggr B) A, B* to convert to A*,
891 but to not permit B** to convert to A**.
893 This should go away. Callers should use can_convert or something
894 similar instead. (jason 17 Apr 1997) */
897 comp_target_types (ttl
, ttr
, nptrs
)
901 ttl
= TYPE_MAIN_VARIANT (ttl
);
902 ttr
= TYPE_MAIN_VARIANT (ttr
);
906 if (TREE_CODE (ttr
) != TREE_CODE (ttl
))
909 if (TREE_CODE (ttr
) == POINTER_TYPE
910 || (TREE_CODE (ttr
) == REFERENCE_TYPE
))
912 int is_ptr
= TREE_CODE (ttr
) == POINTER_TYPE
;
914 ttl
= TREE_TYPE (ttl
);
915 ttr
= TREE_TYPE (ttr
);
917 if (nptrs
> 0 && is_ptr
)
919 if (TREE_CODE (ttl
) == UNKNOWN_TYPE
920 || TREE_CODE (ttr
) == UNKNOWN_TYPE
)
922 else if (TREE_CODE (ttl
) == VOID_TYPE
923 && TREE_CODE (ttr
) != FUNCTION_TYPE
924 && TREE_CODE (ttr
) != METHOD_TYPE
925 && TREE_CODE (ttr
) != OFFSET_TYPE
)
927 else if (TREE_CODE (ttr
) == VOID_TYPE
928 && TREE_CODE (ttl
) != FUNCTION_TYPE
929 && TREE_CODE (ttl
) != METHOD_TYPE
930 && TREE_CODE (ttl
) != OFFSET_TYPE
)
932 else if (TREE_CODE (ttl
) == POINTER_TYPE
933 || TREE_CODE (ttl
) == ARRAY_TYPE
)
935 if (comp_ptr_ttypes (ttl
, ttr
))
937 else if (comp_ptr_ttypes (ttr
, ttl
))
943 /* Const and volatile mean something different for function types,
944 so the usual checks are not appropriate. */
945 if (TREE_CODE (ttl
) == FUNCTION_TYPE
|| TREE_CODE (ttl
) == METHOD_TYPE
)
946 return comp_target_types (ttl
, ttr
, nptrs
- 1);
948 /* Make sure that the cv-quals change only in the same direction as
952 int c
= TYPE_READONLY (ttl
) - TYPE_READONLY (ttr
);
953 int v
= TYPE_VOLATILE (ttl
) - TYPE_VOLATILE (ttr
);
955 if ((c
> 0 && v
< 0) || (c
< 0 && v
> 0))
958 if (TYPE_MAIN_VARIANT (ttl
) == TYPE_MAIN_VARIANT (ttr
))
959 return (c
+ v
< 0) ? -1 : 1;
961 t
= comp_target_types (ttl
, ttr
, nptrs
- 1);
962 if ((t
== 1 && c
+ v
>= 0) || (t
== -1 && c
+ v
<= 0))
969 if (TREE_CODE (ttr
) == ARRAY_TYPE
)
970 return comp_array_types (comp_target_types
, ttl
, ttr
, 0);
971 else if (TREE_CODE (ttr
) == FUNCTION_TYPE
|| TREE_CODE (ttr
) == METHOD_TYPE
)
978 if (comptypes (TREE_TYPE (ttl
), TREE_TYPE (ttr
), 1) == 0)
983 switch (comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), -1))
992 argsl
= TYPE_ARG_TYPES (ttl
);
993 argsr
= TYPE_ARG_TYPES (ttr
);
995 /* Compare 'this' here, not in comp_target_parms. */
996 if (TREE_CODE (ttr
) == METHOD_TYPE
)
998 tree tl
= TYPE_METHOD_BASETYPE (ttl
);
999 tree tr
= TYPE_METHOD_BASETYPE (ttr
);
1001 if (comptypes (tr
, tl
, 0) == 0)
1003 if (comptypes (tl
, tr
, 0))
1009 argsl
= TREE_CHAIN (argsl
);
1010 argsr
= TREE_CHAIN (argsr
);
1013 switch (comp_target_parms (argsl
, argsr
, 1))
1021 return saw_contra
? -1 : 1;
1024 else if (TREE_CODE (ttr
) == OFFSET_TYPE
)
1026 /* Contravariance: we can assign a pointer to base member to a pointer
1027 to derived member. Note difference from simple pointer case, where
1028 we can pass a pointer to derived to a pointer to base. */
1029 if (comptypes (TYPE_OFFSET_BASETYPE (ttr
),
1030 TYPE_OFFSET_BASETYPE (ttl
), 0))
1031 return comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), nptrs
);
1032 else if (comptypes (TYPE_OFFSET_BASETYPE (ttl
),
1033 TYPE_OFFSET_BASETYPE (ttr
), 0)
1034 && comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), nptrs
))
1037 else if (IS_AGGR_TYPE (ttl
))
1041 if (comptypes (build_pointer_type (ttl
), build_pointer_type (ttr
), 0))
1043 if (comptypes (build_pointer_type (ttr
), build_pointer_type (ttl
), 0))
1051 /* Returns 1 if TYPE1 is more cv-qualified than TYPE2, -1 if TYPE2 is
1052 more cv-qualified that TYPE1, and 0 otherwise. */
1055 comp_cv_qualification (type1
, type2
)
1059 if (TYPE_READONLY (type1
) == TYPE_READONLY (type2
)
1060 && TYPE_VOLATILE (type1
) == TYPE_VOLATILE (type2
))
1063 if (TYPE_READONLY (type1
) >= TYPE_READONLY (type2
)
1064 && TYPE_VOLATILE (type1
) >= TYPE_VOLATILE (type2
))
1067 if (TYPE_READONLY (type2
) >= TYPE_READONLY (type1
)
1068 && TYPE_VOLATILE (type2
) >= TYPE_VOLATILE (type1
))
1074 /* Returns 1 if the cv-qualification signature of TYPE1 is a proper
1075 subset of the cv-qualification signature of TYPE2, and the types
1076 are similar. Returns -1 if the other way 'round, and 0 otherwise. */
1079 comp_cv_qual_signature (type1
, type2
)
1083 if (comp_ptr_ttypes_real (type2
, type1
, -1))
1085 else if (comp_ptr_ttypes_real (type1
, type2
, -1))
1091 /* If two types share a common base type, return that basetype.
1092 If there is not a unique most-derived base type, this function
1093 returns ERROR_MARK_NODE. */
1096 common_base_type (tt1
, tt2
)
1099 tree best
= NULL_TREE
;
1102 /* If one is a baseclass of another, that's good enough. */
1103 if (UNIQUELY_DERIVED_FROM_P (tt1
, tt2
))
1105 if (UNIQUELY_DERIVED_FROM_P (tt2
, tt1
))
1108 /* Otherwise, try to find a unique baseclass of TT1
1109 that is shared by TT2, and follow that down. */
1110 for (i
= CLASSTYPE_N_BASECLASSES (tt1
)-1; i
>= 0; i
--)
1112 tree basetype
= TYPE_BINFO_BASETYPE (tt1
, i
);
1113 tree trial
= common_base_type (basetype
, tt2
);
1116 if (trial
== error_mark_node
)
1118 if (best
== NULL_TREE
)
1120 else if (best
!= trial
)
1121 return error_mark_node
;
1126 for (i
= CLASSTYPE_N_BASECLASSES (tt2
)-1; i
>= 0; i
--)
1128 tree basetype
= TYPE_BINFO_BASETYPE (tt2
, i
);
1129 tree trial
= common_base_type (tt1
, basetype
);
1132 if (trial
== error_mark_node
)
1134 if (best
== NULL_TREE
)
1136 else if (best
!= trial
)
1137 return error_mark_node
;
1143 /* Subroutines of `comptypes'. */
1145 /* Return 1 if two parameter type lists PARMS1 and PARMS2
1146 are equivalent in the sense that functions with those parameter types
1147 can have equivalent types.
1148 If either list is empty, we win.
1149 Otherwise, the two lists must be equivalent, element by element.
1151 C++: See comment above about TYPE1, TYPE2.
1153 STRICT is no longer used. */
1156 compparms (parms1
, parms2
, strict
)
1157 tree parms1
, parms2
;
1160 register tree t1
= parms1
, t2
= parms2
;
1162 /* An unspecified parmlist matches any specified parmlist
1163 whose argument types don't need default promotions. */
1167 if (t1
== 0 && t2
== 0)
1169 /* If one parmlist is shorter than the other,
1170 they fail to match. */
1171 if (t1
== 0 || t2
== 0)
1173 if (! comptypes (TREE_VALUE (t2
), TREE_VALUE (t1
), 1))
1176 t1
= TREE_CHAIN (t1
);
1177 t2
= TREE_CHAIN (t2
);
1181 /* This really wants return whether or not parameter type lists
1182 would make their owning functions assignment compatible or not.
1184 The return value is like for comp_target_types.
1186 This should go away, possibly with the exception of the empty parmlist
1187 conversion; there are no conversions between function types in C++.
1188 (jason 17 Apr 1997) */
1191 comp_target_parms (parms1
, parms2
, strict
)
1192 tree parms1
, parms2
;
1195 register tree t1
= parms1
, t2
= parms2
;
1196 int warn_contravariance
= 0;
1198 /* In C, an unspecified parmlist matches any specified parmlist
1199 whose argument types don't need default promotions. This is not
1200 true for C++, but let's do it anyway for unfixed headers. */
1202 if (t1
== 0 && t2
!= 0)
1204 cp_pedwarn ("ANSI C++ prohibits conversion from `(%#T)' to `(...)'",
1206 return self_promoting_args_p (t2
);
1209 return self_promoting_args_p (t1
);
1211 for (; t1
|| t2
; t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
))
1215 /* If one parmlist is shorter than the other,
1216 they fail to match, unless STRICT is <= 0. */
1217 if (t1
== 0 || t2
== 0)
1222 return 1 + warn_contravariance
;
1223 return ((t1
&& TREE_PURPOSE (t1
)) + warn_contravariance
);
1225 p1
= TREE_VALUE (t1
);
1226 p2
= TREE_VALUE (t2
);
1227 if (comptypes (p1
, p2
, 1))
1233 if ((TREE_CODE (p1
) == POINTER_TYPE
&& TREE_CODE (p2
) == POINTER_TYPE
)
1234 || (TREE_CODE (p1
) == REFERENCE_TYPE
1235 && TREE_CODE (p2
) == REFERENCE_TYPE
))
1238 && (TYPE_MAIN_VARIANT (TREE_TYPE (p1
))
1239 == TYPE_MAIN_VARIANT (TREE_TYPE (p2
))))
1242 /* The following is wrong for contravariance,
1243 but many programs depend on it. */
1244 if (TREE_TYPE (p1
) == void_type_node
)
1246 if (TREE_TYPE (p2
) == void_type_node
)
1248 warn_contravariance
= 1;
1251 if (IS_AGGR_TYPE (TREE_TYPE (p1
)))
1253 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (p1
)),
1254 TYPE_MAIN_VARIANT (TREE_TYPE (p2
)), 1) == 0)
1258 /* Note backwards order due to contravariance. */
1259 if (comp_target_types (p2
, p1
, 1) <= 0)
1261 if (comp_target_types (p1
, p2
, 1) > 0)
1263 warn_contravariance
= 1;
1270 return warn_contravariance
? -1 : 1;
1273 /* Return 1 if PARMS specifies a fixed number of parameters
1274 and none of their types is affected by default promotions. */
1277 self_promoting_args_p (parms
)
1281 for (t
= parms
; t
; t
= TREE_CHAIN (t
))
1283 register tree type
= TREE_VALUE (t
);
1285 if (TREE_CHAIN (t
) == 0 && type
!= void_type_node
)
1291 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
1294 if (C_PROMOTING_INTEGER_TYPE_P (type
))
1300 /* Return an unsigned type the same as TYPE in other respects.
1302 C++: must make these work for type variants as well. */
1305 unsigned_type (type
)
1308 tree type1
= TYPE_MAIN_VARIANT (type
);
1309 if (type1
== signed_char_type_node
|| type1
== char_type_node
)
1310 return unsigned_char_type_node
;
1311 if (type1
== integer_type_node
)
1312 return unsigned_type_node
;
1313 if (type1
== short_integer_type_node
)
1314 return short_unsigned_type_node
;
1315 if (type1
== long_integer_type_node
)
1316 return long_unsigned_type_node
;
1317 if (type1
== long_long_integer_type_node
)
1318 return long_long_unsigned_type_node
;
1319 if (type1
== intTI_type_node
)
1320 return unsigned_intTI_type_node
;
1321 if (type1
== intDI_type_node
)
1322 return unsigned_intDI_type_node
;
1323 if (type1
== intSI_type_node
)
1324 return unsigned_intSI_type_node
;
1325 if (type1
== intHI_type_node
)
1326 return unsigned_intHI_type_node
;
1327 if (type1
== intQI_type_node
)
1328 return unsigned_intQI_type_node
;
1330 return signed_or_unsigned_type (1, type
);
1333 /* Return a signed type the same as TYPE in other respects. */
1339 tree type1
= TYPE_MAIN_VARIANT (type
);
1340 if (type1
== unsigned_char_type_node
|| type1
== char_type_node
)
1341 return signed_char_type_node
;
1342 if (type1
== unsigned_type_node
)
1343 return integer_type_node
;
1344 if (type1
== short_unsigned_type_node
)
1345 return short_integer_type_node
;
1346 if (type1
== long_unsigned_type_node
)
1347 return long_integer_type_node
;
1348 if (type1
== long_long_unsigned_type_node
)
1349 return long_long_integer_type_node
;
1350 if (type1
== unsigned_intTI_type_node
)
1351 return intTI_type_node
;
1352 if (type1
== unsigned_intDI_type_node
)
1353 return intDI_type_node
;
1354 if (type1
== unsigned_intSI_type_node
)
1355 return intSI_type_node
;
1356 if (type1
== unsigned_intHI_type_node
)
1357 return intHI_type_node
;
1358 if (type1
== unsigned_intQI_type_node
)
1359 return intQI_type_node
;
1361 return signed_or_unsigned_type (0, type
);
1364 /* Return a type the same as TYPE except unsigned or
1365 signed according to UNSIGNEDP. */
1368 signed_or_unsigned_type (unsignedp
, type
)
1372 if (! INTEGRAL_TYPE_P (type
)
1373 || TREE_UNSIGNED (type
) == unsignedp
)
1376 if (TYPE_PRECISION (type
) == TYPE_PRECISION (signed_char_type_node
))
1377 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
1378 if (TYPE_PRECISION (type
) == TYPE_PRECISION (integer_type_node
))
1379 return unsignedp
? unsigned_type_node
: integer_type_node
;
1380 if (TYPE_PRECISION (type
) == TYPE_PRECISION (short_integer_type_node
))
1381 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
1382 if (TYPE_PRECISION (type
) == TYPE_PRECISION (long_integer_type_node
))
1383 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
1384 if (TYPE_PRECISION (type
) == TYPE_PRECISION (long_long_integer_type_node
))
1385 return (unsignedp
? long_long_unsigned_type_node
1386 : long_long_integer_type_node
);
1390 /* Compute the value of the `sizeof' operator. */
1396 enum tree_code code
= TREE_CODE (type
);
1399 if (processing_template_decl
)
1400 return build_min (SIZEOF_EXPR
, sizetype
, type
);
1402 if (code
== FUNCTION_TYPE
)
1404 if (pedantic
|| warn_pointer_arith
)
1405 pedwarn ("ANSI C++ forbids taking the sizeof a function type");
1406 return size_int (1);
1408 if (code
== METHOD_TYPE
)
1410 if (pedantic
|| warn_pointer_arith
)
1411 pedwarn ("ANSI C++ forbids taking the sizeof a method type");
1412 return size_int (1);
1414 if (code
== VOID_TYPE
)
1416 if (pedantic
|| warn_pointer_arith
)
1417 pedwarn ("ANSI C++ forbids taking the sizeof a void type");
1418 return size_int (1);
1420 if (code
== ERROR_MARK
)
1421 return size_int (1);
1423 /* ARM $5.3.2: ``When applied to a reference, the result is the size of the
1424 referenced object.'' */
1425 if (code
== REFERENCE_TYPE
)
1426 type
= TREE_TYPE (type
);
1428 /* We couldn't find anything in the ARM or the draft standard that says,
1429 one way or the other, if doing sizeof on something that doesn't have
1430 an object associated with it is correct or incorrect. For example, if
1431 you declare `struct S { char str[16]; };', and in your program do
1432 a `sizeof (S::str)', should we flag that as an error or should we give
1433 the size of it? Since it seems like a reasonable thing to do, we'll go
1434 with giving the value. */
1435 if (code
== OFFSET_TYPE
)
1436 type
= TREE_TYPE (type
);
1438 /* @@ This also produces an error for a signature ref.
1439 In that case we should be able to do better. */
1440 if (IS_SIGNATURE (type
))
1442 error ("`sizeof' applied to a signature type");
1443 return size_int (0);
1446 if (TYPE_SIZE (complete_type (type
)) == 0)
1448 cp_error ("`sizeof' applied to incomplete type `%T'", type
);
1449 return size_int (0);
1452 /* Convert in case a char is more than one unit. */
1453 t
= size_binop (CEIL_DIV_EXPR
, TYPE_SIZE (type
),
1454 size_int (TYPE_PRECISION (char_type_node
)));
1455 t
= convert (sizetype
, t
);
1456 /* size_binop does not put the constant in range, so do it now. */
1457 if (TREE_CODE (t
) == INTEGER_CST
&& force_fit_type (t
, 0))
1458 TREE_CONSTANT_OVERFLOW (t
) = TREE_OVERFLOW (t
) = 1;
1466 if (processing_template_decl
)
1467 return build_min (SIZEOF_EXPR
, sizetype
, e
);
1469 if (TREE_CODE (e
) == COMPONENT_REF
1470 && DECL_BIT_FIELD (TREE_OPERAND (e
, 1)))
1471 error ("sizeof applied to a bit-field");
1472 /* ANSI says arrays and functions are converted inside comma.
1473 But we can't really convert them in build_compound_expr
1474 because that would break commas in lvalues.
1475 So do the conversion here if operand was a comma. */
1476 if (TREE_CODE (e
) == COMPOUND_EXPR
1477 && (TREE_CODE (TREE_TYPE (e
)) == ARRAY_TYPE
1478 || TREE_CODE (TREE_TYPE (e
)) == FUNCTION_TYPE
))
1479 e
= default_conversion (e
);
1480 else if (TREE_CODE (e
) == TREE_LIST
)
1482 tree t
= TREE_VALUE (e
);
1485 && TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
1486 || is_overloaded_fn (t
)))
1487 pedwarn ("ANSI C++ forbids taking the sizeof a function type");
1489 return c_sizeof (TREE_TYPE (e
));
1493 c_sizeof_nowarn (type
)
1496 enum tree_code code
= TREE_CODE (type
);
1499 if (code
== FUNCTION_TYPE
1500 || code
== METHOD_TYPE
1501 || code
== VOID_TYPE
1502 || code
== ERROR_MARK
)
1503 return size_int (1);
1504 if (code
== REFERENCE_TYPE
)
1505 type
= TREE_TYPE (type
);
1507 if (TYPE_SIZE (type
) == 0)
1508 return size_int (0);
1510 /* Convert in case a char is more than one unit. */
1511 t
= size_binop (CEIL_DIV_EXPR
, TYPE_SIZE (type
),
1512 size_int (TYPE_PRECISION (char_type_node
)));
1513 t
= convert (sizetype
, t
);
1514 force_fit_type (t
, 0);
1518 /* Implement the __alignof keyword: Return the minimum required
1519 alignment of TYPE, measured in bytes. */
1525 enum tree_code code
= TREE_CODE (type
);
1528 if (processing_template_decl
)
1529 return build_min (ALIGNOF_EXPR
, sizetype
, type
);
1531 if (code
== FUNCTION_TYPE
|| code
== METHOD_TYPE
)
1532 return size_int (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
1534 if (code
== VOID_TYPE
|| code
== ERROR_MARK
)
1535 return size_int (1);
1537 /* C++: this is really correct! */
1538 if (code
== REFERENCE_TYPE
)
1539 type
= TREE_TYPE (type
);
1541 /* @@ This also produces an error for a signature ref.
1542 In that case we should be able to do better. */
1543 if (IS_SIGNATURE (type
))
1545 error ("`__alignof' applied to a signature type");
1546 return size_int (1);
1549 t
= size_int (TYPE_ALIGN (type
) / BITS_PER_UNIT
);
1550 force_fit_type (t
, 0);
1554 /* Perform default promotions for C data used in expressions.
1555 Arrays and functions are converted to pointers;
1556 enumeral types or short or char, to int.
1557 In addition, manifest constants symbols are replaced by their values.
1559 C++: this will automatically bash references to their target type. */
1562 decay_conversion (exp
)
1565 register tree type
= TREE_TYPE (exp
);
1566 register enum tree_code code
= TREE_CODE (type
);
1568 if (code
== OFFSET_TYPE
)
1570 if (TREE_CODE (exp
) == OFFSET_REF
)
1571 return decay_conversion (resolve_offset_ref (exp
));
1573 type
= TREE_TYPE (type
);
1574 code
= TREE_CODE (type
);
1576 if (type
== unknown_type_node
)
1578 cp_pedwarn ("assuming & on overloaded member function");
1579 return build_unary_op (ADDR_EXPR
, exp
, 0);
1583 if (code
== REFERENCE_TYPE
)
1585 exp
= convert_from_reference (exp
);
1586 type
= TREE_TYPE (exp
);
1587 code
= TREE_CODE (type
);
1590 /* Constants can be used directly unless they're not loadable. */
1591 if (TREE_CODE (exp
) == CONST_DECL
)
1592 exp
= DECL_INITIAL (exp
);
1593 /* Replace a nonvolatile const static variable with its value. */
1594 else if (TREE_READONLY_DECL_P (exp
))
1596 exp
= decl_constant_value (exp
);
1597 type
= TREE_TYPE (exp
);
1600 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
1601 Leave such NOP_EXPRs, since RHS is being used in non-lvalue context. */
1603 if (code
== VOID_TYPE
)
1605 error ("void value not ignored as it ought to be");
1606 return error_mark_node
;
1608 if (code
== FUNCTION_TYPE
)
1610 return build_unary_op (ADDR_EXPR
, exp
, 0);
1612 if (code
== METHOD_TYPE
)
1614 cp_pedwarn ("assuming & on `%E'", exp
);
1615 return build_unary_op (ADDR_EXPR
, exp
, 0);
1617 if (code
== ARRAY_TYPE
)
1622 int constp
, volatilep
;
1624 if (TREE_CODE (exp
) == INDIRECT_REF
)
1626 /* Stripping away the INDIRECT_REF is not the right
1627 thing to do for references... */
1628 tree inner
= TREE_OPERAND (exp
, 0);
1629 if (TREE_CODE (TREE_TYPE (inner
)) == REFERENCE_TYPE
)
1631 inner
= build1 (CONVERT_EXPR
,
1632 build_pointer_type (TREE_TYPE
1633 (TREE_TYPE (inner
))),
1635 TREE_CONSTANT (inner
) = TREE_CONSTANT (TREE_OPERAND (inner
, 0));
1637 return cp_convert (build_pointer_type (TREE_TYPE (type
)), inner
);
1640 if (TREE_CODE (exp
) == COMPOUND_EXPR
)
1642 tree op1
= decay_conversion (TREE_OPERAND (exp
, 1));
1643 return build (COMPOUND_EXPR
, TREE_TYPE (op1
),
1644 TREE_OPERAND (exp
, 0), op1
);
1648 && ! (TREE_CODE (exp
) == CONSTRUCTOR
&& TREE_STATIC (exp
)))
1650 error ("invalid use of non-lvalue array");
1651 return error_mark_node
;
1654 constp
= volatilep
= 0;
1655 if (TREE_CODE_CLASS (TREE_CODE (exp
)) == 'r'
1656 || TREE_CODE_CLASS (TREE_CODE (exp
)) == 'd')
1658 constp
= TREE_READONLY (exp
);
1659 volatilep
= TREE_THIS_VOLATILE (exp
);
1662 restype
= TREE_TYPE (type
);
1663 if (TYPE_READONLY (type
) || TYPE_VOLATILE (type
)
1664 || constp
|| volatilep
)
1665 restype
= cp_build_type_variant (restype
,
1666 TYPE_READONLY (type
) || constp
,
1667 TYPE_VOLATILE (type
) || volatilep
);
1668 ptrtype
= build_pointer_type (restype
);
1670 if (TREE_CODE (exp
) == VAR_DECL
)
1672 /* ??? This is not really quite correct
1673 in that the type of the operand of ADDR_EXPR
1674 is not the target type of the type of the ADDR_EXPR itself.
1675 Question is, can this lossage be avoided? */
1676 adr
= build1 (ADDR_EXPR
, ptrtype
, exp
);
1677 if (mark_addressable (exp
) == 0)
1678 return error_mark_node
;
1679 TREE_CONSTANT (adr
) = staticp (exp
);
1680 TREE_SIDE_EFFECTS (adr
) = 0; /* Default would be, same as EXP. */
1683 /* This way is better for a COMPONENT_REF since it can
1684 simplify the offset for a component. */
1685 adr
= build_unary_op (ADDR_EXPR
, exp
, 1);
1686 return cp_convert (ptrtype
, adr
);
1693 default_conversion (exp
)
1697 enum tree_code code
;
1699 exp
= decay_conversion (exp
);
1701 type
= TREE_TYPE (exp
);
1702 code
= TREE_CODE (type
);
1704 if (INTEGRAL_CODE_P (code
))
1706 tree t
= type_promotes_to (type
);
1708 return cp_convert (t
, exp
);
1714 /* Take the address of an inline function without setting TREE_ADDRESSABLE
1718 inline_conversion (exp
)
1721 if (TREE_CODE (exp
) == FUNCTION_DECL
)
1723 tree type
= build_type_variant
1724 (TREE_TYPE (exp
), TREE_READONLY (exp
), TREE_THIS_VOLATILE (exp
));
1725 exp
= build1 (ADDR_EXPR
, build_pointer_type (type
), exp
);
1731 build_object_ref (datum
, basetype
, field
)
1732 tree datum
, basetype
, field
;
1735 if (datum
== error_mark_node
)
1736 return error_mark_node
;
1738 dtype
= TREE_TYPE (datum
);
1739 if (TREE_CODE (dtype
) == REFERENCE_TYPE
)
1740 dtype
= TREE_TYPE (dtype
);
1741 if (! IS_AGGR_TYPE_CODE (TREE_CODE (dtype
)))
1743 cp_error ("request for member `%T::%D' in expression of non-aggregate type `%T'",
1744 basetype
, field
, dtype
);
1745 return error_mark_node
;
1747 else if (IS_SIGNATURE (basetype
))
1749 warning ("signature name in scope resolution ignored");
1750 return build_component_ref (datum
, field
, NULL_TREE
, 1);
1752 else if (is_aggr_type (basetype
, 1))
1754 tree binfo
= binfo_or_else (basetype
, dtype
);
1756 return build_x_component_ref (build_scoped_ref (datum
, basetype
),
1759 return error_mark_node
;
1762 /* Like `build_component_ref, but uses an already found field, and converts
1763 from a reference. Must compute access for current_class_ref.
1767 build_component_ref_1 (datum
, field
, protect
)
1771 return convert_from_reference
1772 (build_component_ref (datum
, field
, NULL_TREE
, protect
));
1775 /* Given a COND_EXPR, MIN_EXPR, or MAX_EXPR in T, return it in a form that we
1776 can, for example, use as an lvalue. This code used to be in
1777 unary_complex_lvalue, but we needed it to deal with `a = (d == c) ? b : c'
1778 expressions, where we're dealing with aggregates. But now it's again only
1779 called from unary_complex_lvalue. The case (in particular) that led to
1780 this was with CODE == ADDR_EXPR, since it's not an lvalue when we'd
1784 rationalize_conditional_expr (code
, t
)
1785 enum tree_code code
;
1788 /* For MIN_EXPR or MAX_EXPR, fold-const.c has arranged things so that
1789 the first operand is always the one to be used if both operands
1790 are equal, so we know what conditional expression this used to be. */
1791 if (TREE_CODE (t
) == MIN_EXPR
|| TREE_CODE (t
) == MAX_EXPR
)
1794 build_conditional_expr (build_x_binary_op ((TREE_CODE (t
) == MIN_EXPR
1795 ? LE_EXPR
: GE_EXPR
),
1796 TREE_OPERAND (t
, 0),
1797 TREE_OPERAND (t
, 1)),
1798 build_unary_op (code
, TREE_OPERAND (t
, 0), 0),
1799 build_unary_op (code
, TREE_OPERAND (t
, 1), 0));
1803 build_conditional_expr (TREE_OPERAND (t
, 0),
1804 build_unary_op (code
, TREE_OPERAND (t
, 1), 0),
1805 build_unary_op (code
, TREE_OPERAND (t
, 2), 0));
1808 /* Given the TYPE of an anonymous union field inside T, return the
1809 FIELD_DECL for the field. If not found return NULL_TREE. Because
1810 anonymous unions can nest, we must also search all anonymous unions
1811 that are directly reachable. */
1814 lookup_anon_field (t
, type
)
1819 for (field
= TYPE_FIELDS (t
); field
; field
= TREE_CHAIN (field
))
1821 if (TREE_STATIC (field
))
1823 if (TREE_CODE (field
) != FIELD_DECL
)
1826 /* If we find it directly, return the field. */
1827 if (DECL_NAME (field
) == NULL_TREE
1828 && type
== TREE_TYPE (field
))
1833 /* Otherwise, it could be nested, search harder. */
1834 if (DECL_NAME (field
) == NULL_TREE
1835 && TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
)
1837 tree subfield
= lookup_anon_field (TREE_TYPE (field
), type
);
1845 /* Build a COMPONENT_REF for a given DATUM, and it's member COMPONENT.
1846 COMPONENT can be an IDENTIFIER_NODE that is the name of the member
1847 that we are interested in, or it can be a FIELD_DECL. */
1850 build_component_ref (datum
, component
, basetype_path
, protect
)
1851 tree datum
, component
, basetype_path
;
1854 register tree basetype
= TREE_TYPE (datum
);
1855 register enum tree_code code
;
1856 register tree field
= NULL
;
1859 if (processing_template_decl
)
1860 return build_min_nt (COMPONENT_REF
, datum
, component
);
1862 /* If DATUM is a COMPOUND_EXPR or COND_EXPR, move our reference
1864 switch (TREE_CODE (datum
))
1868 tree value
= build_component_ref (TREE_OPERAND (datum
, 1), component
,
1869 basetype_path
, protect
);
1870 return build (COMPOUND_EXPR
, TREE_TYPE (value
),
1871 TREE_OPERAND (datum
, 0), value
);
1874 return build_conditional_expr
1875 (TREE_OPERAND (datum
, 0),
1876 build_component_ref (TREE_OPERAND (datum
, 1), component
,
1877 basetype_path
, protect
),
1878 build_component_ref (TREE_OPERAND (datum
, 2), component
,
1879 basetype_path
, protect
));
1882 cp_error ("invalid use of %D", datum
);
1883 datum
= error_mark_node
;
1890 code
= TREE_CODE (basetype
);
1892 if (code
== REFERENCE_TYPE
)
1894 datum
= convert_from_reference (datum
);
1895 basetype
= TREE_TYPE (datum
);
1896 code
= TREE_CODE (basetype
);
1898 if (TREE_CODE (datum
) == OFFSET_REF
)
1900 datum
= resolve_offset_ref (datum
);
1901 basetype
= TREE_TYPE (datum
);
1902 code
= TREE_CODE (basetype
);
1905 /* First, see if there is a field or component with name COMPONENT. */
1906 if (TREE_CODE (component
) == TREE_LIST
)
1908 /* I could not trigger this code. MvL */
1909 my_friendly_abort (980326);
1911 my_friendly_assert (!(TREE_CHAIN (component
) == NULL_TREE
1912 && DECL_CHAIN (TREE_VALUE (component
)) == NULL_TREE
), 309);
1914 return build (COMPONENT_REF
, TREE_TYPE (component
), datum
, component
);
1917 if (! IS_AGGR_TYPE_CODE (code
))
1919 if (code
!= ERROR_MARK
)
1920 cp_error ("request for member `%D' in `%E', which is of non-aggregate type `%T'",
1921 component
, datum
, basetype
);
1922 return error_mark_node
;
1925 if (TYPE_SIZE (complete_type (basetype
)) == 0)
1927 incomplete_type_error (0, basetype
);
1928 return error_mark_node
;
1931 if (TREE_CODE (component
) == BIT_NOT_EXPR
)
1933 if (TYPE_IDENTIFIER (basetype
) != TREE_OPERAND (component
, 0))
1935 cp_error ("destructor specifier `%T::~%T' must have matching names",
1936 basetype
, TREE_OPERAND (component
, 0));
1937 return error_mark_node
;
1939 if (! TYPE_HAS_DESTRUCTOR (basetype
))
1941 cp_error ("type `%T' has no destructor", basetype
);
1942 return error_mark_node
;
1944 return TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (basetype
), 1);
1947 /* Look up component name in the structure type definition. */
1948 if (CLASSTYPE_VFIELD (basetype
)
1949 && DECL_NAME (CLASSTYPE_VFIELD (basetype
)) == component
)
1950 /* Special-case this because if we use normal lookups in an ambiguous
1951 hierarchy, the compiler will abort (because vptr lookups are
1952 not supposed to be ambiguous. */
1953 field
= CLASSTYPE_VFIELD (basetype
);
1954 else if (TREE_CODE (component
) == FIELD_DECL
1955 || TREE_CODE (component
) == TYPE_DECL
)
1961 tree name
= component
;
1962 if (TREE_CODE (component
) == VAR_DECL
)
1963 name
= DECL_NAME (component
);
1964 if (basetype_path
== NULL_TREE
)
1965 basetype_path
= TYPE_BINFO (basetype
);
1966 field
= lookup_field (basetype_path
, name
,
1967 protect
&& !VFIELD_NAME_P (name
), 0);
1968 if (field
== error_mark_node
)
1969 return error_mark_node
;
1971 if (field
== NULL_TREE
)
1973 /* Not found as a data field, look for it as a method. If found,
1974 then if this is the only possible one, return it, else
1975 report ambiguity error. */
1976 tree fndecls
= lookup_fnfields (basetype_path
, name
, 1);
1977 if (fndecls
== error_mark_node
)
1978 return error_mark_node
;
1981 if (TREE_CHAIN (fndecls
) == NULL_TREE
1982 && TREE_CODE (TREE_VALUE (fndecls
)) != OVERLOAD
)
1984 tree access
, fndecl
;
1986 /* Unique, so use this one now. */
1987 basetype
= TREE_PURPOSE (fndecls
);
1988 fndecl
= TREE_VALUE (fndecls
);
1989 access
= compute_access (TREE_PURPOSE (fndecls
), fndecl
);
1990 if (access
== access_public_node
)
1992 if (DECL_VINDEX (fndecl
)
1993 && ! resolves_to_fixed_type_p (datum
, 0))
1995 tree addr
= build_unary_op (ADDR_EXPR
, datum
, 0);
1996 tree fntype
= TREE_TYPE (fndecl
);
1998 addr
= convert_pointer_to (DECL_CONTEXT (fndecl
),
2000 datum
= build_indirect_ref (addr
, NULL_PTR
);
2001 my_friendly_assert (datum
!= error_mark_node
, 310);
2002 fndecl
= build_vfn_ref (&addr
, datum
,
2003 DECL_VINDEX (fndecl
));
2004 /* The type of fndecl is a function type,
2005 not a pointer-to-function type, since
2006 build_vfn_ref returns not the correct
2007 vtable slot, but the indirection of the
2008 correct vtable slot. */
2009 TREE_TYPE (fndecl
) = fntype
;
2013 return build (OFFSET_REF
, TREE_TYPE (fndecl
),
2016 if (access
== access_protected_node
)
2017 cp_error ("member function `%D' is protected", fndecl
);
2019 cp_error ("member function `%D' is private", fndecl
);
2020 return error_mark_node
;
2024 /* Just act like build_offset_ref, since the object does
2025 not matter unless we're actually calling the function. */
2028 t
= build_tree_list (error_mark_node
, fndecls
);
2029 TREE_TYPE (t
) = build_offset_type (basetype
,
2035 cp_error ("`%#T' has no member named `%D'", basetype
, name
);
2036 return error_mark_node
;
2038 else if (TREE_TYPE (field
) == error_mark_node
)
2039 return error_mark_node
;
2041 if (TREE_CODE (field
) != FIELD_DECL
)
2043 if (TREE_CODE (field
) == TYPE_DECL
)
2045 cp_error ("invalid use of type decl `%#D' as expression", field
);
2046 return error_mark_node
;
2048 else if (DECL_RTL (field
) != 0)
2051 TREE_USED (field
) = 1;
2056 /* See if we have to do any conversions so that we pick up the field from the
2058 if (DECL_FIELD_CONTEXT (field
) != basetype
)
2060 tree context
= DECL_FIELD_CONTEXT (field
);
2061 tree base
= context
;
2062 while (base
!= basetype
&& TYPE_NAME (base
)
2063 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (base
)))
2065 base
= TYPE_CONTEXT (base
);
2068 /* Handle base classes here... */
2069 if (base
!= basetype
&& TYPE_USES_COMPLEX_INHERITANCE (basetype
))
2071 tree addr
= build_unary_op (ADDR_EXPR
, datum
, 0);
2072 if (integer_zerop (addr
))
2074 error ("invalid reference to NULL ptr, use ptr-to-member instead");
2075 return error_mark_node
;
2077 if (VBASE_NAME_P (DECL_NAME (field
)))
2079 /* It doesn't matter which vbase pointer we grab, just
2080 find one of them. */
2081 tree binfo
= get_binfo (base
,
2082 TREE_TYPE (TREE_TYPE (addr
)), 0);
2083 addr
= convert_pointer_to_real (binfo
, addr
);
2086 addr
= convert_pointer_to (base
, addr
);
2087 datum
= build_indirect_ref (addr
, NULL_PTR
);
2088 my_friendly_assert (datum
!= error_mark_node
, 311);
2092 /* Handle things from anon unions here... */
2093 if (TYPE_NAME (context
) && ANON_AGGRNAME_P (TYPE_IDENTIFIER (context
)))
2095 tree subfield
= lookup_anon_field (basetype
, context
);
2096 tree subdatum
= build_component_ref (datum
, subfield
,
2097 basetype_path
, protect
);
2098 return build_component_ref (subdatum
, field
, basetype_path
, protect
);
2102 ref
= fold (build (COMPONENT_REF
, TREE_TYPE (field
),
2103 break_out_cleanups (datum
), field
));
2105 if (TREE_READONLY (datum
) || TREE_READONLY (field
))
2106 TREE_READONLY (ref
) = 1;
2107 if (TREE_THIS_VOLATILE (datum
) || TREE_THIS_VOLATILE (field
))
2108 TREE_THIS_VOLATILE (ref
) = 1;
2109 if (DECL_MUTABLE_P (field
))
2110 TREE_READONLY (ref
) = 0;
2115 /* Variant of build_component_ref for use in expressions, which should
2116 never have REFERENCE_TYPE. */
2119 build_x_component_ref (datum
, component
, basetype_path
, protect
)
2120 tree datum
, component
, basetype_path
;
2123 tree t
= build_component_ref (datum
, component
, basetype_path
, protect
);
2125 if (! processing_template_decl
)
2126 t
= convert_from_reference (t
);
2131 /* Given an expression PTR for a pointer, return an expression
2132 for the value pointed to.
2133 ERRORSTRING is the name of the operator to appear in error messages.
2135 This function may need to overload OPERATOR_FNNAME.
2136 Must also handle REFERENCE_TYPEs for C++. */
2139 build_x_indirect_ref (ptr
, errorstring
)
2145 if (processing_template_decl
)
2146 return build_min_nt (INDIRECT_REF
, ptr
);
2148 rval
= build_opfncall (INDIRECT_REF
, LOOKUP_NORMAL
, ptr
, NULL_TREE
,
2152 return build_indirect_ref (ptr
, errorstring
);
2156 build_indirect_ref (ptr
, errorstring
)
2160 register tree pointer
, type
;
2162 if (ptr
== error_mark_node
)
2163 return error_mark_node
;
2165 pointer
= (TREE_CODE (TREE_TYPE (ptr
)) == REFERENCE_TYPE
2166 ? ptr
: default_conversion (ptr
));
2167 type
= TREE_TYPE (pointer
);
2169 if (ptr
== current_class_ptr
)
2170 return current_class_ref
;
2172 if (TREE_CODE (type
) == POINTER_TYPE
|| TREE_CODE (type
) == REFERENCE_TYPE
)
2174 if (TREE_CODE (pointer
) == ADDR_EXPR
2176 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (pointer
, 0)))
2177 == TYPE_MAIN_VARIANT (TREE_TYPE (type
)))
2178 && (TREE_READONLY (TREE_OPERAND (pointer
, 0))
2179 == TYPE_READONLY (TREE_TYPE (type
)))
2180 && (TREE_THIS_VOLATILE (TREE_OPERAND (pointer
, 0))
2181 == TYPE_VOLATILE (TREE_TYPE (type
))))
2182 return TREE_OPERAND (pointer
, 0);
2185 tree t
= TREE_TYPE (type
);
2186 register tree ref
= build1 (INDIRECT_REF
,
2187 TYPE_MAIN_VARIANT (t
), pointer
);
2189 /* We *must* set TREE_READONLY when dereferencing a pointer to const,
2190 so that we get the proper error message if the result is used
2191 to assign to. Also, &* is supposed to be a no-op. */
2192 TREE_READONLY (ref
) = TYPE_READONLY (t
);
2193 TREE_SIDE_EFFECTS (ref
)
2194 = (TYPE_VOLATILE (t
) || TREE_SIDE_EFFECTS (pointer
)
2196 TREE_THIS_VOLATILE (ref
) = TYPE_VOLATILE (t
);
2200 /* `pointer' won't be an error_mark_node if we were given a
2201 pointer to member, so it's cool to check for this here. */
2202 else if (TYPE_PTRMEMFUNC_P (type
))
2203 error ("invalid use of `%s' on pointer to member function", errorstring
);
2204 else if (TREE_CODE (type
) == RECORD_TYPE
2205 && (IS_SIGNATURE_POINTER (type
) || IS_SIGNATURE_REFERENCE (type
)))
2206 error ("cannot dereference signature pointer/reference");
2207 else if (pointer
!= error_mark_node
)
2210 error ("invalid type argument of `%s'", errorstring
);
2212 error ("invalid type argument");
2214 return error_mark_node
;
2217 /* This handles expressions of the form "a[i]", which denotes
2220 This is logically equivalent in C to *(a+i), but we may do it differently.
2221 If A is a variable or a member, we generate a primitive ARRAY_REF.
2222 This avoids forcing the array out of registers, and can work on
2223 arrays that are not lvalues (for example, members of structures returned
2226 If INDEX is of some user-defined type, it must be converted to
2227 integer type. Otherwise, to make a compatible PLUS_EXPR, it
2228 will inherit the type of the array, which will be some pointer type. */
2231 build_array_ref (array
, idx
)
2236 error ("subscript missing in array reference");
2237 return error_mark_node
;
2240 if (TREE_TYPE (array
) == error_mark_node
2241 || TREE_TYPE (idx
) == error_mark_node
)
2242 return error_mark_node
;
2244 if (TREE_CODE (TREE_TYPE (array
)) == ARRAY_TYPE
2245 && TREE_CODE (array
) != INDIRECT_REF
)
2249 /* Subscripting with type char is likely to lose
2250 on a machine where chars are signed.
2251 So warn on any machine, but optionally.
2252 Don't warn for unsigned char since that type is safe.
2253 Don't warn for signed char because anyone who uses that
2254 must have done so deliberately. */
2255 if (warn_char_subscripts
2256 && TYPE_MAIN_VARIANT (TREE_TYPE (idx
)) == char_type_node
)
2257 warning ("array subscript has type `char'");
2259 /* Apply default promotions *after* noticing character types. */
2260 idx
= default_conversion (idx
);
2262 if (TREE_CODE (TREE_TYPE (idx
)) != INTEGER_TYPE
)
2264 error ("array subscript is not an integer");
2265 return error_mark_node
;
2268 /* An array that is indexed by a non-constant
2269 cannot be stored in a register; we must be able to do
2270 address arithmetic on its address.
2271 Likewise an array of elements of variable size. */
2272 if (TREE_CODE (idx
) != INTEGER_CST
2273 || (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array
))) != 0
2274 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array
))))
2277 if (mark_addressable (array
) == 0)
2278 return error_mark_node
;
2280 /* An array that is indexed by a constant value which is not within
2281 the array bounds cannot be stored in a register either; because we
2282 would get a crash in store_bit_field/extract_bit_field when trying
2283 to access a non-existent part of the register. */
2284 if (TREE_CODE (idx
) == INTEGER_CST
2285 && TYPE_VALUES (TREE_TYPE (array
))
2286 && ! int_fits_type_p (idx
, TYPE_VALUES (TREE_TYPE (array
))))
2288 if (mark_addressable (array
) == 0)
2289 return error_mark_node
;
2292 if (pedantic
&& !lvalue_p (array
))
2293 pedwarn ("ANSI C++ forbids subscripting non-lvalue array");
2295 /* Note in C++ it is valid to subscript a `register' array, since
2296 it is valid to take the address of something with that
2297 storage specification. */
2301 while (TREE_CODE (foo
) == COMPONENT_REF
)
2302 foo
= TREE_OPERAND (foo
, 0);
2303 if (TREE_CODE (foo
) == VAR_DECL
&& DECL_REGISTER (foo
))
2304 warning ("subscripting array declared `register'");
2307 type
= TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (array
)));
2308 rval
= build (ARRAY_REF
, type
, array
, idx
);
2309 /* Array ref is const/volatile if the array elements are
2310 or if the array is.. */
2311 TREE_READONLY (rval
)
2312 |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array
)))
2313 | TREE_READONLY (array
));
2314 TREE_SIDE_EFFECTS (rval
)
2315 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array
)))
2316 | TREE_SIDE_EFFECTS (array
));
2317 TREE_THIS_VOLATILE (rval
)
2318 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array
)))
2319 /* This was added by rms on 16 Nov 91.
2320 It fixes vol struct foo *a; a->elts[1]
2321 in an inline function.
2322 Hope it doesn't break something else. */
2323 | TREE_THIS_VOLATILE (array
));
2324 return require_complete_type (fold (rval
));
2328 tree ar
= default_conversion (array
);
2329 tree ind
= default_conversion (idx
);
2331 /* Put the integer in IND to simplify error checking. */
2332 if (TREE_CODE (TREE_TYPE (ar
)) == INTEGER_TYPE
)
2339 if (ar
== error_mark_node
)
2342 if (TREE_CODE (TREE_TYPE (ar
)) != POINTER_TYPE
)
2344 error ("subscripted value is neither array nor pointer");
2345 return error_mark_node
;
2347 if (TREE_CODE (TREE_TYPE (ind
)) != INTEGER_TYPE
)
2349 error ("array subscript is not an integer");
2350 return error_mark_node
;
2353 return build_indirect_ref (build_binary_op_nodefault (PLUS_EXPR
, ar
,
2359 /* Build a function call to function FUNCTION with parameters PARAMS.
2360 PARAMS is a list--a chain of TREE_LIST nodes--in which the
2361 TREE_VALUE of each node is a parameter-expression. The PARAMS do
2362 not include any object pointer that may be required. FUNCTION's
2363 data type may be a function type or a pointer-to-function.
2365 For C++: If FUNCTION's data type is a TREE_LIST, then the tree list
2366 is the list of possible methods that FUNCTION could conceivably
2367 be. If the list of methods comes from a class, then it will be
2368 a list of lists (where each element is associated with the class
2369 that produced it), otherwise it will be a simple list (for
2370 functions overloaded in global scope).
2372 In the first case, TREE_VALUE (function) is the head of one of those
2373 lists, and TREE_PURPOSE is the name of the function.
2375 In the second case, TREE_PURPOSE (function) is the function's
2378 DECL is the class instance variable, usually CURRENT_CLASS_REF.
2380 When calling a TEMPLATE_DECL, we don't require a complete return
2384 build_x_function_call (function
, params
, decl
)
2385 tree function
, params
, decl
;
2388 tree template_id
= NULL_TREE
;
2391 if (function
== error_mark_node
)
2392 return error_mark_node
;
2394 if (processing_template_decl
)
2395 return build_min_nt (CALL_EXPR
, function
, params
, NULL_TREE
);
2397 /* Save explicit template arguments if found */
2398 if (TREE_CODE (function
) == TEMPLATE_ID_EXPR
)
2400 template_id
= function
;
2401 function
= TREE_OPERAND (function
, 0);
2404 type
= TREE_TYPE (function
);
2406 if (TREE_CODE (type
) == OFFSET_TYPE
2407 && TREE_TYPE (type
) == unknown_type_node
2408 && TREE_CODE (function
) == TREE_LIST
2409 && TREE_CHAIN (function
) == NULL_TREE
)
2411 /* Undo (Foo:bar)()... */
2412 type
= TYPE_OFFSET_BASETYPE (type
);
2413 function
= TREE_VALUE (function
);
2414 my_friendly_assert (TREE_CODE (function
) == TREE_LIST
, 999);
2415 my_friendly_assert (TREE_CHAIN (function
) == NULL_TREE
, 999);
2416 function
= TREE_VALUE (function
);
2417 my_friendly_assert (TREE_CODE (function
) == FUNCTION_DECL
, 999);
2418 function
= DECL_NAME (function
);
2419 return build_method_call (decl
, function
, params
,
2420 TYPE_BINFO (type
), LOOKUP_NORMAL
);
2423 is_method
= ((TREE_CODE (function
) == TREE_LIST
2424 && current_class_type
!= NULL_TREE
2425 && (IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (function
))
2427 || TREE_CODE (function
) == IDENTIFIER_NODE
2428 || TREE_CODE (type
) == METHOD_TYPE
2429 || TYPE_PTRMEMFUNC_P (type
));
2431 if ((TREE_CODE (function
) == FUNCTION_DECL
2432 && DECL_STATIC_FUNCTION_P (function
))
2433 || (TREE_CODE (function
) == TEMPLATE_DECL
2434 && DECL_STATIC_FUNCTION_P (DECL_RESULT (function
))))
2435 return build_member_call
2436 (DECL_CONTEXT (function
), DECL_NAME (function
), params
);
2438 /* A friend template. Make it look like a toplevel declaration. */
2439 if (! is_method
&& TREE_CODE (function
) == TEMPLATE_DECL
)
2440 function
= scratch_ovl_cons (function
, NULL_TREE
);
2442 /* Handle methods, friends, and overloaded functions, respectively. */
2445 tree basetype
= NULL_TREE
;
2447 if (TREE_CODE (function
) == FUNCTION_DECL
2448 || DECL_FUNCTION_TEMPLATE_P (function
))
2450 basetype
= DECL_CLASS_CONTEXT (function
);
2452 if (DECL_NAME (function
))
2453 function
= DECL_NAME (function
);
2455 function
= TYPE_IDENTIFIER (DECL_CLASS_CONTEXT (function
));
2457 else if (TREE_CODE (function
) == TREE_LIST
)
2459 my_friendly_assert (TREE_CODE (TREE_VALUE (function
))
2460 == FUNCTION_DECL
, 312);
2461 basetype
= DECL_CLASS_CONTEXT (TREE_VALUE (function
));
2462 function
= TREE_PURPOSE (function
);
2464 else if (TREE_CODE (function
) != IDENTIFIER_NODE
)
2466 if (TREE_CODE (function
) == OFFSET_REF
)
2468 if (TREE_OPERAND (function
, 0))
2469 decl
= TREE_OPERAND (function
, 0);
2471 /* Call via a pointer to member function. */
2472 if (decl
== NULL_TREE
)
2474 error ("pointer to member function called, but not in class scope");
2475 return error_mark_node
;
2477 /* What other type of POINTER_TYPE could this be? */
2478 if (TREE_CODE (TREE_TYPE (function
)) != POINTER_TYPE
2479 && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (function
))
2480 && TREE_CODE (function
) != OFFSET_REF
)
2481 function
= build (OFFSET_REF
, TREE_TYPE (type
), NULL_TREE
,
2486 /* this is an abbreviated method call.
2487 must go through here in case it is a virtual function.
2488 @@ Perhaps this could be optimized. */
2490 if (basetype
&& (! current_class_type
2491 || ! DERIVED_FROM_P (basetype
, current_class_type
)))
2492 return build_member_call (basetype
, function
, params
);
2494 if (decl
== NULL_TREE
)
2496 if (current_class_type
== NULL_TREE
)
2498 error ("object missing in call to method `%s'",
2499 IDENTIFIER_POINTER (function
));
2500 return error_mark_node
;
2502 /* Yow: call from a static member function. */
2503 decl
= build1 (NOP_EXPR
, build_pointer_type (current_class_type
),
2505 decl
= build_indirect_ref (decl
, NULL_PTR
);
2508 /* Put back explicit template arguments, if any. */
2510 function
= template_id
;
2511 return build_method_call (decl
, function
, params
,
2512 NULL_TREE
, LOOKUP_NORMAL
);
2514 else if (TREE_CODE (function
) == COMPONENT_REF
2515 && type
== unknown_type_node
)
2517 /* Should we undo what was done in build_component_ref? */
2518 if (TREE_CODE (TREE_PURPOSE (TREE_OPERAND (function
, 1))) == TREE_VEC
)
2519 /* Get the name that build_component_ref hid. */
2520 function
= DECL_NAME (TREE_VALUE (TREE_OPERAND (function
, 1)));
2522 function
= TREE_PURPOSE (TREE_OPERAND (function
, 1));
2523 return build_method_call (decl
, function
, params
,
2524 NULL_TREE
, LOOKUP_NORMAL
);
2526 else if (really_overloaded_fn (function
))
2528 if (OVL_FUNCTION (function
) == NULL_TREE
)
2530 cp_error ("function `%D' declared overloaded, but no definitions appear with which to resolve it?!?",
2531 TREE_PURPOSE (function
));
2532 return error_mark_node
;
2536 /* Put back explicit template arguments, if any. */
2538 function
= template_id
;
2539 return build_new_function_call (function
, params
);
2543 /* Remove a potential OVERLOAD around it */
2544 function
= OVL_CURRENT (function
);
2547 if (TREE_CODE (function
) == OFFSET_REF
)
2549 /* If the component is a data element (or a virtual function), we play
2550 games here to make things work. */
2553 if (TREE_OPERAND (function
, 0))
2554 decl
= TREE_OPERAND (function
, 0);
2556 decl
= current_class_ref
;
2558 decl_addr
= build_unary_op (ADDR_EXPR
, decl
, 0);
2559 function
= get_member_function_from_ptrfunc (&decl_addr
,
2560 TREE_OPERAND (function
, 1));
2561 params
= expr_tree_cons (NULL_TREE
, decl_addr
, params
);
2562 return build_function_call (function
, params
);
2565 type
= TREE_TYPE (function
);
2566 if (type
!= error_mark_node
)
2568 if (TREE_CODE (type
) == REFERENCE_TYPE
)
2569 type
= TREE_TYPE (type
);
2571 if (IS_AGGR_TYPE (type
))
2572 return build_opfncall (CALL_EXPR
, LOOKUP_NORMAL
, function
, params
, NULL_TREE
);
2577 tree fntype
= TREE_TYPE (function
);
2578 tree ctypeptr
= NULL_TREE
;
2580 /* Explicitly named method? */
2581 if (TREE_CODE (function
) == FUNCTION_DECL
)
2582 ctypeptr
= build_pointer_type (DECL_CLASS_CONTEXT (function
));
2583 /* Expression with ptr-to-method type? It could either be a plain
2584 usage, or it might be a case where the ptr-to-method is being
2585 passed in as an argument. */
2586 else if (TYPE_PTRMEMFUNC_P (fntype
))
2588 tree rec
= TYPE_METHOD_BASETYPE (TREE_TYPE
2589 (TYPE_PTRMEMFUNC_FN_TYPE (fntype
)));
2590 ctypeptr
= build_pointer_type (rec
);
2592 /* Unexpected node type? */
2594 my_friendly_abort (116);
2595 if (decl
== NULL_TREE
)
2597 if (current_function_decl
2598 && DECL_STATIC_FUNCTION_P (current_function_decl
))
2599 error ("invalid call to member function needing `this' in static member function scope");
2601 error ("pointer to member function called, but not in class scope");
2602 return error_mark_node
;
2604 if (TREE_CODE (TREE_TYPE (decl
)) != POINTER_TYPE
2605 && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (decl
)))
2607 decl
= build_unary_op (ADDR_EXPR
, decl
, 0);
2608 decl
= convert_pointer_to (TREE_TYPE (ctypeptr
), decl
);
2611 decl
= build_c_cast (ctypeptr
, decl
);
2612 params
= expr_tree_cons (NULL_TREE
, decl
, params
);
2615 return build_function_call (function
, params
);
2618 /* Resolve a pointer to member function. INSTANCE is the object
2619 instance to use, if the member points to a virtual member. */
2622 get_member_function_from_ptrfunc (instance_ptrptr
, function
)
2623 tree
*instance_ptrptr
;
2626 if (TREE_CODE (function
) == OFFSET_REF
)
2628 function
= TREE_OPERAND (function
, 1);
2631 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (function
)))
2633 tree fntype
, idx
, e1
, delta
, delta2
, e2
, e3
, aref
, vtbl
;
2636 tree instance_ptr
= *instance_ptrptr
;
2638 if (TREE_SIDE_EFFECTS (instance_ptr
))
2639 instance_ptr
= save_expr (instance_ptr
);
2641 if (TREE_SIDE_EFFECTS (function
))
2642 function
= save_expr (function
);
2644 fntype
= TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (function
));
2646 /* Promoting idx before saving it improves performance on RISC
2647 targets. Without promoting, the first compare used
2648 load-with-sign-extend, while the second used normal load then
2649 shift to sign-extend. An optimizer flaw, perhaps, but it's easier
2650 to make this change. */
2651 idx
= save_expr (default_conversion
2652 (build_component_ref (function
,
2655 e1
= build_binary_op (GT_EXPR
, idx
, integer_zero_node
, 1);
2656 delta
= cp_convert (ptrdiff_type_node
,
2657 build_component_ref (function
, delta_identifier
,
2659 delta2
= DELTA2_FROM_PTRMEMFUNC (function
);
2661 /* Convert down to the right base, before using the instance. */
2663 = convert_pointer_to_real (TYPE_METHOD_BASETYPE (TREE_TYPE (fntype
)),
2665 if (instance
== error_mark_node
&& instance_ptr
!= error_mark_node
)
2668 vtbl
= convert_pointer_to (ptr_type_node
, instance
);
2671 build_pointer_type (build_pointer_type (vtable_entry_type
)),
2672 vtbl
, cp_convert (ptrdiff_type_node
, delta2
));
2673 vtbl
= build_indirect_ref (vtbl
, NULL_PTR
);
2674 aref
= build_array_ref (vtbl
, build_binary_op (MINUS_EXPR
,
2676 integer_one_node
, 1));
2677 if (! flag_vtable_thunks
)
2679 aref
= save_expr (aref
);
2681 delta
= build_binary_op
2683 build_conditional_expr (e1
, build_component_ref (aref
,
2690 *instance_ptrptr
= build (PLUS_EXPR
, TREE_TYPE (instance_ptr
),
2691 instance_ptr
, delta
);
2692 if (flag_vtable_thunks
)
2695 e2
= build_component_ref (aref
, pfn_identifier
, NULL_TREE
, 0);
2697 e3
= PFN_FROM_PTRMEMFUNC (function
);
2698 TREE_TYPE (e2
) = TREE_TYPE (e3
);
2699 e1
= build_conditional_expr (e1
, e2
, e3
);
2701 if (instance_ptr
== error_mark_node
2702 && TREE_CODE (e1
) != ADDR_EXPR
2703 && TREE_CODE (TREE_OPERAND (e1
, 0)) != FUNCTION_DECL
)
2704 cp_error ("object missing in `%E'", function
);
2708 /* Make sure this doesn't get evaluated first inside one of the
2709 branches of the COND_EXPR. */
2710 if (TREE_CODE (instance_ptr
) == SAVE_EXPR
)
2711 function
= build (COMPOUND_EXPR
, TREE_TYPE (function
),
2712 instance_ptr
, function
);
2718 build_function_call_real (function
, params
, require_complete
, flags
)
2719 tree function
, params
;
2720 int require_complete
, flags
;
2722 register tree fntype
, fndecl
;
2723 register tree value_type
;
2724 register tree coerced_params
;
2725 tree name
= NULL_TREE
, assembler_name
= NULL_TREE
;
2728 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
2729 Strip such NOP_EXPRs, since FUNCTION is used in non-lvalue context. */
2730 if (TREE_CODE (function
) == NOP_EXPR
2731 && TREE_TYPE (function
) == TREE_TYPE (TREE_OPERAND (function
, 0)))
2732 function
= TREE_OPERAND (function
, 0);
2734 if (TREE_CODE (function
) == FUNCTION_DECL
)
2736 name
= DECL_NAME (function
);
2737 assembler_name
= DECL_ASSEMBLER_NAME (function
);
2739 GNU_xref_call (current_function_decl
,
2740 IDENTIFIER_POINTER (name
? name
2741 : TYPE_IDENTIFIER (DECL_CLASS_CONTEXT
2743 mark_used (function
);
2746 /* Convert anything with function type to a pointer-to-function. */
2747 if (pedantic
&& DECL_MAIN_P (function
))
2748 pedwarn ("ANSI C++ forbids calling `main' from within program");
2750 /* Differs from default_conversion by not setting TREE_ADDRESSABLE
2751 (because calling an inline function does not mean the function
2752 needs to be separately compiled). */
2754 if (DECL_INLINE (function
))
2755 function
= inline_conversion (function
);
2757 function
= build_addr_func (function
);
2763 function
= build_addr_func (function
);
2766 if (function
== error_mark_node
)
2767 return error_mark_node
;
2769 fntype
= TREE_TYPE (function
);
2771 if (TYPE_PTRMEMFUNC_P (fntype
))
2773 cp_error ("must use .* or ->* to call pointer-to-member function in `%E (...)'",
2775 return error_mark_node
;
2778 is_method
= (TREE_CODE (fntype
) == POINTER_TYPE
2779 && TREE_CODE (TREE_TYPE (fntype
)) == METHOD_TYPE
);
2781 if (!((TREE_CODE (fntype
) == POINTER_TYPE
2782 && TREE_CODE (TREE_TYPE (fntype
)) == FUNCTION_TYPE
)
2784 || TREE_CODE (function
) == TEMPLATE_ID_EXPR
))
2786 cp_error ("`%E' cannot be used as a function", function
);
2787 return error_mark_node
;
2790 /* fntype now gets the type of function pointed to. */
2791 fntype
= TREE_TYPE (fntype
);
2793 /* Convert the parameters to the types declared in the
2794 function prototype, or apply default promotions. */
2796 if (flags
& LOOKUP_COMPLAIN
)
2797 coerced_params
= convert_arguments (NULL_TREE
, TYPE_ARG_TYPES (fntype
),
2798 params
, fndecl
, LOOKUP_NORMAL
);
2800 coerced_params
= convert_arguments (NULL_TREE
, TYPE_ARG_TYPES (fntype
),
2803 if (coerced_params
== error_mark_node
)
2805 if (flags
& LOOKUP_SPECULATIVELY
)
2808 return error_mark_node
;
2811 /* Check for errors in format strings. */
2813 if (warn_format
&& (name
|| assembler_name
))
2814 check_function_format (name
, assembler_name
, coerced_params
);
2816 /* Recognize certain built-in functions so we can make tree-codes
2817 other than CALL_EXPR. We do this when it enables fold-const.c
2818 to do something useful. */
2820 if (TREE_CODE (function
) == ADDR_EXPR
2821 && TREE_CODE (TREE_OPERAND (function
, 0)) == FUNCTION_DECL
2822 && DECL_BUILT_IN (TREE_OPERAND (function
, 0)))
2823 switch (DECL_FUNCTION_CODE (TREE_OPERAND (function
, 0)))
2828 if (coerced_params
== 0)
2829 return integer_zero_node
;
2830 return build_unary_op (ABS_EXPR
, TREE_VALUE (coerced_params
), 0);
2837 value_type
= TREE_TYPE (fntype
) ? TREE_TYPE (fntype
) : void_type_node
;
2839 register tree result
2840 = build_call (function
, value_type
, coerced_params
);
2842 if (require_complete
)
2844 if (value_type
== void_type_node
)
2846 result
= require_complete_type (result
);
2848 if (IS_AGGR_TYPE (value_type
))
2849 result
= build_cplus_new (value_type
, result
);
2850 return convert_from_reference (result
);
2855 build_function_call (function
, params
)
2856 tree function
, params
;
2858 return build_function_call_real (function
, params
, 1, LOOKUP_NORMAL
);
2861 /* Convert the actual parameter expressions in the list VALUES
2862 to the types in the list TYPELIST.
2863 If parmdecls is exhausted, or when an element has NULL as its type,
2864 perform the default conversions.
2866 RETURN_LOC is the location of the return value, if known, NULL_TREE
2867 otherwise. This is useful in the case where we can avoid creating
2868 a temporary variable in the case where we can initialize the return
2869 value directly. If we are not eliding constructors, then we set this
2870 to NULL_TREE to avoid this avoidance.
2872 NAME is an IDENTIFIER_NODE or 0. It is used only for error messages.
2874 This is also where warnings about wrong number of args are generated.
2876 Return a list of expressions for the parameters as converted.
2878 Both VALUES and the returned value are chains of TREE_LIST nodes
2879 with the elements of the list in the TREE_VALUE slots of those nodes.
2881 In C++, unspecified trailing parameters can be filled in with their
2882 default arguments, if such were specified. Do so here. */
2885 convert_arguments (return_loc
, typelist
, values
, fndecl
, flags
)
2886 tree return_loc
, typelist
, values
, fndecl
;
2889 register tree typetail
, valtail
;
2890 register tree result
= NULL_TREE
;
2891 char *called_thing
= 0;
2894 if (! flag_elide_constructors
)
2897 /* Argument passing is always copy-initialization. */
2898 flags
|= LOOKUP_ONLYCONVERTING
;
2902 if (TREE_CODE (TREE_TYPE (fndecl
)) == METHOD_TYPE
)
2904 if (DECL_NAME (fndecl
) == NULL_TREE
2905 || IDENTIFIER_HAS_TYPE_VALUE (DECL_NAME (fndecl
)))
2906 called_thing
= "constructor";
2908 called_thing
= "member function";
2911 called_thing
= "function";
2914 for (valtail
= values
, typetail
= typelist
;
2916 valtail
= TREE_CHAIN (valtail
), i
++)
2918 register tree type
= typetail
? TREE_VALUE (typetail
) : 0;
2919 register tree val
= TREE_VALUE (valtail
);
2921 if (val
== error_mark_node
)
2922 return error_mark_node
;
2924 if (type
== void_type_node
)
2928 cp_error_at ("too many arguments to %s `%+D'", called_thing
,
2930 error ("at this point in file");
2933 error ("too many arguments to function");
2934 /* In case anybody wants to know if this argument
2937 TREE_TYPE (tree_last (result
)) = error_mark_node
;
2941 /* The tree type of the parameter being passed may not yet be
2942 known. In this case, its type is TYPE_UNKNOWN, and will
2943 be instantiated by the type given by TYPE. If TYPE
2944 is also NULL, the tree type of VAL is ERROR_MARK_NODE. */
2945 if (type
&& type_unknown_p (val
))
2946 val
= require_instantiated_type (type
, val
, integer_zero_node
);
2947 else if (type_unknown_p (val
))
2949 /* Strip the `&' from an overloaded FUNCTION_DECL. */
2950 if (TREE_CODE (val
) == ADDR_EXPR
)
2951 val
= TREE_OPERAND (val
, 0);
2952 if (really_overloaded_fn (val
))
2953 cp_error ("insufficient type information to resolve address of overloaded function `%D'",
2954 DECL_NAME (get_first_fn (val
)));
2956 error ("insufficient type information in parameter list");
2957 val
= integer_zero_node
;
2959 else if (TREE_CODE (val
) == OFFSET_REF
2960 && TREE_CODE (TREE_TYPE (val
)) == METHOD_TYPE
)
2962 /* This is unclean. Should be handled elsewhere. */
2963 val
= build_unary_op (ADDR_EXPR
, val
, 0);
2965 else if (TREE_CODE (val
) == OFFSET_REF
)
2966 val
= resolve_offset_ref (val
);
2968 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
2969 Strip such NOP_EXPRs, since VAL is used in non-lvalue context. */
2970 if (TREE_CODE (val
) == NOP_EXPR
2971 && TREE_TYPE (val
) == TREE_TYPE (TREE_OPERAND (val
, 0))
2972 && (type
== 0 || TREE_CODE (type
) != REFERENCE_TYPE
))
2973 val
= TREE_OPERAND (val
, 0);
2975 if (type
== 0 || TREE_CODE (type
) != REFERENCE_TYPE
)
2977 if (TREE_CODE (TREE_TYPE (val
)) == ARRAY_TYPE
2978 || TREE_CODE (TREE_TYPE (val
)) == FUNCTION_TYPE
2979 || TREE_CODE (TREE_TYPE (val
)) == METHOD_TYPE
)
2980 val
= default_conversion (val
);
2982 val
= require_complete_type (val
);
2985 if (val
== error_mark_node
)
2986 return error_mark_node
;
2990 /* Formal parm type is specified by a function prototype. */
2993 if (TYPE_SIZE (complete_type (type
)) == 0)
2995 error ("parameter type of called function is incomplete");
3000 parmval
= convert_for_initialization
3001 (return_loc
, type
, val
, flags
,
3002 "argument passing", fndecl
, i
);
3003 #ifdef PROMOTE_PROTOTYPES
3004 if ((TREE_CODE (type
) == INTEGER_TYPE
3005 || TREE_CODE (type
) == ENUMERAL_TYPE
)
3006 && (TYPE_PRECISION (type
)
3007 < TYPE_PRECISION (integer_type_node
)))
3008 parmval
= default_conversion (parmval
);
3012 if (parmval
== error_mark_node
)
3013 return error_mark_node
;
3015 result
= expr_tree_cons (NULL_TREE
, parmval
, result
);
3019 if (TREE_CODE (TREE_TYPE (val
)) == REFERENCE_TYPE
)
3020 val
= convert_from_reference (val
);
3022 if (TREE_CODE (TREE_TYPE (val
)) == REAL_TYPE
3023 && (TYPE_PRECISION (TREE_TYPE (val
))
3024 < TYPE_PRECISION (double_type_node
)))
3025 /* Convert `float' to `double'. */
3026 result
= expr_tree_cons (NULL_TREE
,
3027 cp_convert (double_type_node
, val
),
3029 else if (IS_AGGR_TYPE (TREE_TYPE (val
))
3030 && ! TYPE_HAS_TRIVIAL_INIT_REF (TREE_TYPE (val
)))
3032 cp_warning ("cannot pass objects of type `%T' through `...'",
3034 result
= expr_tree_cons (NULL_TREE
, val
, result
);
3037 /* Convert `short' and `char' to full-size `int'. */
3038 result
= expr_tree_cons (NULL_TREE
, default_conversion (val
),
3043 typetail
= TREE_CHAIN (typetail
);
3046 if (typetail
!= 0 && typetail
!= void_list_node
)
3048 /* See if there are default arguments that can be used */
3049 if (TREE_PURPOSE (typetail
))
3051 for (; typetail
!= void_list_node
; ++i
)
3053 tree type
= TREE_VALUE (typetail
);
3054 tree val
= break_out_target_exprs (TREE_PURPOSE (typetail
));
3057 if (val
== NULL_TREE
)
3058 parmval
= error_mark_node
;
3059 else if (TREE_CODE (val
) == CONSTRUCTOR
)
3061 parmval
= digest_init (type
, val
, (tree
*)0);
3062 parmval
= convert_for_initialization (return_loc
, type
,
3064 "default constructor",
3069 /* This could get clobbered by the following call. */
3070 if (TREE_HAS_CONSTRUCTOR (val
))
3071 val
= copy_node (val
);
3073 parmval
= convert_for_initialization (return_loc
, type
,
3077 #ifdef PROMOTE_PROTOTYPES
3078 if ((TREE_CODE (type
) == INTEGER_TYPE
3079 || TREE_CODE (type
) == ENUMERAL_TYPE
)
3080 && (TYPE_PRECISION (type
)
3081 < TYPE_PRECISION (integer_type_node
)))
3082 parmval
= default_conversion (parmval
);
3086 if (parmval
== error_mark_node
)
3087 return error_mark_node
;
3089 result
= expr_tree_cons (0, parmval
, result
);
3090 typetail
= TREE_CHAIN (typetail
);
3091 /* ends with `...'. */
3092 if (typetail
== NULL_TREE
)
3100 char *buf
= (char *)alloca (32 + strlen (called_thing
));
3101 sprintf (buf
, "too few arguments to %s `%%#D'", called_thing
);
3102 cp_error_at (buf
, fndecl
);
3103 error ("at this point in file");
3106 error ("too few arguments to function");
3107 return error_mark_list
;
3111 return nreverse (result
);
3114 /* Build a binary-operation expression, after performing default
3115 conversions on the operands. CODE is the kind of expression to build. */
3118 build_x_binary_op (code
, arg1
, arg2
)
3119 enum tree_code code
;
3122 if (processing_template_decl
)
3123 return build_min_nt (code
, arg1
, arg2
);
3125 return build_new_op (code
, LOOKUP_NORMAL
, arg1
, arg2
, NULL_TREE
);
3129 build_binary_op (code
, arg1
, arg2
, convert_p
)
3130 enum tree_code code
;
3142 args
[0] = decay_conversion (args
[0]);
3143 args
[1] = decay_conversion (args
[1]);
3145 if (args
[0] == error_mark_node
|| args
[1] == error_mark_node
)
3146 return error_mark_node
;
3148 type0
= TREE_TYPE (args
[0]);
3149 type1
= TREE_TYPE (args
[1]);
3151 if (type_unknown_p (args
[0]))
3153 args
[0] = instantiate_type (type1
, args
[0], 1);
3154 args
[0] = decay_conversion (args
[0]);
3156 else if (type_unknown_p (args
[1]))
3158 args
[1] = require_instantiated_type (type0
, args
[1],
3160 args
[1] = decay_conversion (args
[1]);
3163 if (IS_AGGR_TYPE (type0
) || IS_AGGR_TYPE (type1
))
3164 my_friendly_abort (754867);
3166 return build_binary_op_nodefault (code
, args
[0], args
[1], code
);
3169 /* Build a binary-operation expression without default conversions.
3170 CODE is the kind of expression to build.
3171 This function differs from `build' in several ways:
3172 the data type of the result is computed and recorded in it,
3173 warnings are generated if arg data types are invalid,
3174 special handling for addition and subtraction of pointers is known,
3175 and some optimization is done (operations on narrow ints
3176 are done in the narrower type when that gives the same result).
3177 Constant folding is also done before the result is returned.
3179 ERROR_CODE is the code that determines what to say in error messages.
3180 It is usually, but not always, the same as CODE.
3182 Note that the operands will never have enumeral types
3183 because either they have just had the default conversions performed
3184 or they have both just been converted to some other type in which
3185 the arithmetic is to be done.
3187 C++: must do special pointer arithmetic when implementing
3188 multiple inheritance, and deal with pointer to member functions. */
3191 build_binary_op_nodefault (code
, orig_op0
, orig_op1
, error_code
)
3192 enum tree_code code
;
3193 tree orig_op0
, orig_op1
;
3194 enum tree_code error_code
;
3197 register enum tree_code code0
, code1
;
3200 /* Expression code to give to the expression when it is built.
3201 Normally this is CODE, which is what the caller asked for,
3202 but in some special cases we change it. */
3203 register enum tree_code resultcode
= code
;
3205 /* Data type in which the computation is to be performed.
3206 In the simplest cases this is the common type of the arguments. */
3207 register tree result_type
= NULL
;
3209 /* Nonzero means operands have already been type-converted
3210 in whatever way is necessary.
3211 Zero means they need to be converted to RESULT_TYPE. */
3214 /* Nonzero means create the expression with this type, rather than
3216 tree build_type
= 0;
3218 /* Nonzero means after finally constructing the expression
3219 convert it to this type. */
3220 tree final_type
= 0;
3222 /* Nonzero if this is an operation like MIN or MAX which can
3223 safely be computed in short if both args are promoted shorts.
3224 Also implies COMMON.
3225 -1 indicates a bitwise operation; this makes a difference
3226 in the exact conditions for when it is safe to do the operation
3227 in a narrower mode. */
3230 /* Nonzero if this is a comparison operation;
3231 if both args are promoted shorts, compare the original shorts.
3232 Also implies COMMON. */
3233 int short_compare
= 0;
3235 /* Nonzero if this is a right-shift operation, which can be computed on the
3236 original short and then promoted if the operand is a promoted short. */
3237 int short_shift
= 0;
3239 /* Nonzero means set RESULT_TYPE to the common type of the args. */
3242 /* Apply default conversions. */
3243 if (code
== TRUTH_AND_EXPR
|| code
== TRUTH_ANDIF_EXPR
3244 || code
== TRUTH_OR_EXPR
|| code
== TRUTH_ORIF_EXPR
3245 || code
== TRUTH_XOR_EXPR
)
3247 op0
= decay_conversion (orig_op0
);
3248 op1
= decay_conversion (orig_op1
);
3252 op0
= default_conversion (orig_op0
);
3253 op1
= default_conversion (orig_op1
);
3256 type0
= TREE_TYPE (op0
);
3257 type1
= TREE_TYPE (op1
);
3259 /* The expression codes of the data types of the arguments tell us
3260 whether the arguments are integers, floating, pointers, etc. */
3261 code0
= TREE_CODE (type0
);
3262 code1
= TREE_CODE (type1
);
3264 /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
3265 STRIP_TYPE_NOPS (op0
);
3266 STRIP_TYPE_NOPS (op1
);
3268 /* If an error was already reported for one of the arguments,
3269 avoid reporting another error. */
3271 if (code0
== ERROR_MARK
|| code1
== ERROR_MARK
)
3272 return error_mark_node
;
3277 /* Handle the pointer + int case. */
3278 if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
3279 return pointer_int_sum (PLUS_EXPR
, op0
, op1
);
3280 else if (code1
== POINTER_TYPE
&& code0
== INTEGER_TYPE
)
3281 return pointer_int_sum (PLUS_EXPR
, op1
, op0
);
3287 /* Subtraction of two similar pointers.
3288 We must subtract them as integers, then divide by object size. */
3289 if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
3290 && comp_target_types (type0
, type1
, 1))
3291 return pointer_diff (op0
, op1
, common_type (type0
, type1
));
3292 /* Handle pointer minus int. Just like pointer plus int. */
3293 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
3294 return pointer_int_sum (MINUS_EXPR
, op0
, op1
);
3303 case TRUNC_DIV_EXPR
:
3305 case FLOOR_DIV_EXPR
:
3306 case ROUND_DIV_EXPR
:
3307 case EXACT_DIV_EXPR
:
3308 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
3309 || code0
== COMPLEX_TYPE
)
3310 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
3311 || code1
== COMPLEX_TYPE
))
3313 if (TREE_CODE (op1
) == INTEGER_CST
&& integer_zerop (op1
))
3314 cp_warning ("division by zero in `%E / 0'", op0
);
3315 else if (TREE_CODE (op1
) == REAL_CST
&& real_zerop (op1
))
3316 cp_warning ("division by zero in `%E / 0.'", op0
);
3318 if (!(code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
))
3319 resultcode
= RDIV_EXPR
;
3321 /* When dividing two signed integers, we have to promote to int.
3322 unless we divide by a constant != -1. Note that default
3323 conversion will have been performed on the operands at this
3324 point, so we have to dig out the original type to find out if
3326 shorten
= ((TREE_CODE (op0
) == NOP_EXPR
3327 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0
, 0))))
3328 || (TREE_CODE (op1
) == INTEGER_CST
3329 && (TREE_INT_CST_LOW (op1
) != -1
3330 || TREE_INT_CST_HIGH (op1
) != -1)));
3336 case BIT_ANDTC_EXPR
:
3339 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3341 /* If one operand is a constant, and the other is a short type
3342 that has been converted to an int,
3343 really do the work in the short type and then convert the
3344 result to int. If we are lucky, the constant will be 0 or 1
3345 in the short type, making the entire operation go away. */
3346 if (TREE_CODE (op0
) == INTEGER_CST
3347 && TREE_CODE (op1
) == NOP_EXPR
3348 && (TYPE_PRECISION (type1
)
3349 > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op1
, 0))))
3350 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op1
, 0))))
3352 final_type
= result_type
;
3353 op1
= TREE_OPERAND (op1
, 0);
3354 result_type
= TREE_TYPE (op1
);
3356 if (TREE_CODE (op1
) == INTEGER_CST
3357 && TREE_CODE (op0
) == NOP_EXPR
3358 && (TYPE_PRECISION (type0
)
3359 > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0
, 0))))
3360 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0
, 0))))
3362 final_type
= result_type
;
3363 op0
= TREE_OPERAND (op0
, 0);
3364 result_type
= TREE_TYPE (op0
);
3368 case TRUNC_MOD_EXPR
:
3369 case FLOOR_MOD_EXPR
:
3370 if (code1
== INTEGER_TYPE
&& integer_zerop (op1
))
3371 cp_warning ("division by zero in `%E % 0'", op0
);
3372 else if (code1
== REAL_TYPE
&& real_zerop (op1
))
3373 cp_warning ("division by zero in `%E % 0.'", op0
);
3375 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3377 /* Although it would be tempting to shorten always here, that loses
3378 on some targets, since the modulo instruction is undefined if the
3379 quotient can't be represented in the computation mode. We shorten
3380 only if unsigned or if dividing by something we know != -1. */
3381 shorten
= ((TREE_CODE (op0
) == NOP_EXPR
3382 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0
, 0))))
3383 || (TREE_CODE (op1
) == INTEGER_CST
3384 && (TREE_INT_CST_LOW (op1
) != -1
3385 || TREE_INT_CST_HIGH (op1
) != -1)));
3390 case TRUTH_ANDIF_EXPR
:
3391 case TRUTH_ORIF_EXPR
:
3392 case TRUTH_AND_EXPR
:
3394 result_type
= boolean_type_node
;
3397 /* Shift operations: result has same type as first operand;
3398 always convert second operand to int.
3399 Also set SHORT_SHIFT if shifting rightward. */
3402 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3404 result_type
= type0
;
3405 if (TREE_CODE (op1
) == INTEGER_CST
)
3407 if (tree_int_cst_lt (op1
, integer_zero_node
))
3408 warning ("right shift count is negative");
3411 if (TREE_INT_CST_LOW (op1
) | TREE_INT_CST_HIGH (op1
))
3413 if (TREE_INT_CST_HIGH (op1
) != 0
3414 || ((unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (op1
)
3415 >= TYPE_PRECISION (type0
)))
3416 warning ("right shift count >= width of type");
3419 /* Convert the shift-count to an integer, regardless of
3420 size of value being shifted. */
3421 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
3422 op1
= cp_convert (integer_type_node
, op1
);
3423 /* Avoid converting op1 to result_type later. */
3429 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3431 result_type
= type0
;
3432 if (TREE_CODE (op1
) == INTEGER_CST
)
3434 if (tree_int_cst_lt (op1
, integer_zero_node
))
3435 warning ("left shift count is negative");
3436 else if (TREE_INT_CST_HIGH (op1
) != 0
3437 || ((unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (op1
)
3438 >= TYPE_PRECISION (type0
)))
3439 warning ("left shift count >= width of type");
3441 /* Convert the shift-count to an integer, regardless of
3442 size of value being shifted. */
3443 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
3444 op1
= cp_convert (integer_type_node
, op1
);
3445 /* Avoid converting op1 to result_type later. */
3452 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3454 result_type
= type0
;
3455 if (TREE_CODE (op1
) == INTEGER_CST
)
3457 if (tree_int_cst_lt (op1
, integer_zero_node
))
3458 warning ("%s rotate count is negative",
3459 (code
== LROTATE_EXPR
) ? "left" : "right");
3460 else if (TREE_INT_CST_HIGH (op1
) != 0
3461 || ((unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (op1
)
3462 >= TYPE_PRECISION (type0
)))
3463 warning ("%s rotate count >= width of type",
3464 (code
== LROTATE_EXPR
) ? "left" : "right");
3466 /* Convert the shift-count to an integer, regardless of
3467 size of value being shifted. */
3468 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
3469 op1
= cp_convert (integer_type_node
, op1
);
3475 build_type
= boolean_type_node
;
3476 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
3477 || code0
== COMPLEX_TYPE
)
3478 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
3479 || code1
== COMPLEX_TYPE
))
3481 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
3483 register tree tt0
= TYPE_MAIN_VARIANT (TREE_TYPE (type0
));
3484 register tree tt1
= TYPE_MAIN_VARIANT (TREE_TYPE (type1
));
3486 if (comp_target_types (type0
, type1
, 1))
3487 result_type
= common_type (type0
, type1
);
3488 else if (tt0
== void_type_node
)
3490 if (pedantic
&& TREE_CODE (tt1
) == FUNCTION_TYPE
3491 && tree_int_cst_lt (TYPE_SIZE (type0
), TYPE_SIZE (type1
)))
3492 pedwarn ("ANSI C++ forbids comparison of `void *' with function pointer");
3493 else if (TREE_CODE (tt1
) == OFFSET_TYPE
)
3494 pedwarn ("ANSI C++ forbids conversion of a pointer to member to `void *'");
3496 else if (tt1
== void_type_node
)
3498 if (pedantic
&& TREE_CODE (tt0
) == FUNCTION_TYPE
3499 && tree_int_cst_lt (TYPE_SIZE (type1
), TYPE_SIZE (type0
)))
3500 pedwarn ("ANSI C++ forbids comparison of `void *' with function pointer");
3503 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3506 if (result_type
== NULL_TREE
)
3507 result_type
= ptr_type_node
;
3509 else if (code0
== POINTER_TYPE
&& TREE_CODE (op1
) == INTEGER_CST
3510 && integer_zerop (op1
))
3511 result_type
= type0
;
3512 else if (code1
== POINTER_TYPE
&& TREE_CODE (op0
) == INTEGER_CST
3513 && integer_zerop (op0
))
3514 result_type
= type1
;
3515 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
3517 result_type
= type0
;
3518 error ("ANSI C++ forbids comparison between pointer and integer");
3520 else if (code0
== INTEGER_TYPE
&& code1
== POINTER_TYPE
)
3522 result_type
= type1
;
3523 error ("ANSI C++ forbids comparison between pointer and integer");
3525 else if (TYPE_PTRMEMFUNC_P (type0
) && TREE_CODE (op1
) == INTEGER_CST
3526 && integer_zerop (op1
))
3528 op0
= build_component_ref (op0
, index_identifier
, NULL_TREE
, 0);
3529 op1
= integer_zero_node
;
3530 result_type
= TREE_TYPE (op0
);
3532 else if (TYPE_PTRMEMFUNC_P (type1
) && TREE_CODE (op0
) == INTEGER_CST
3533 && integer_zerop (op0
))
3535 op0
= build_component_ref (op1
, index_identifier
, NULL_TREE
, 0);
3536 op1
= integer_zero_node
;
3537 result_type
= TREE_TYPE (op0
);
3539 else if (TYPE_PTRMEMFUNC_P (type0
) && TYPE_PTRMEMFUNC_P (type1
)
3540 && (TYPE_PTRMEMFUNC_FN_TYPE (type0
)
3541 == TYPE_PTRMEMFUNC_FN_TYPE (type1
)))
3543 /* The code we generate for the test is:
3545 (op0.index == op1.index
3546 && ((op1.index != -1 && op0.delta2 == op1.delta2)
3547 || op0.pfn == op1.pfn)) */
3549 tree index0
= build_component_ref (op0
, index_identifier
,
3551 tree index1
= save_expr (build_component_ref (op1
, index_identifier
,
3553 tree pfn0
= PFN_FROM_PTRMEMFUNC (op0
);
3554 tree pfn1
= PFN_FROM_PTRMEMFUNC (op1
);
3555 tree delta20
= DELTA2_FROM_PTRMEMFUNC (op0
);
3556 tree delta21
= DELTA2_FROM_PTRMEMFUNC (op1
);
3558 tree integer_neg_one_node
3559 = build_binary_op (MINUS_EXPR
, integer_zero_node
,
3560 integer_one_node
, 1);
3561 e1
= build_binary_op (EQ_EXPR
, index0
, index1
, 1);
3562 e2
= build_binary_op (NE_EXPR
, index1
, integer_neg_one_node
, 1);
3563 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e2
,
3564 build_binary_op (EQ_EXPR
, delta20
, delta21
, 1),
3566 e3
= build_binary_op (EQ_EXPR
, pfn0
, pfn1
, 1);
3567 e2
= build_binary_op (TRUTH_ORIF_EXPR
, e2
, e3
, 1);
3568 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e1
, e2
, 1);
3569 if (code
== EQ_EXPR
)
3571 return build_binary_op (EQ_EXPR
, e2
, integer_zero_node
, 1);
3573 else if (TYPE_PTRMEMFUNC_P (type0
)
3574 && TYPE_PTRMEMFUNC_FN_TYPE (type0
) == type1
)
3576 tree index0
= build_component_ref (op0
, index_identifier
,
3579 tree pfn0
= PFN_FROM_PTRMEMFUNC (op0
);
3580 tree delta20
= DELTA2_FROM_PTRMEMFUNC (op0
);
3581 tree delta21
= integer_zero_node
;
3583 tree integer_neg_one_node
3584 = build_binary_op (MINUS_EXPR
, integer_zero_node
, integer_one_node
, 1);
3585 if (TREE_CODE (TREE_OPERAND (op1
, 0)) == FUNCTION_DECL
3586 && DECL_VINDEX (TREE_OPERAND (op1
, 0)))
3588 /* Map everything down one to make room for
3589 the null pointer to member. */
3590 index1
= size_binop (PLUS_EXPR
,
3591 DECL_VINDEX (TREE_OPERAND (op1
, 0)),
3593 op1
= integer_zero_node
;
3594 delta21
= CLASSTYPE_VFIELD (TYPE_METHOD_BASETYPE
3595 (TREE_TYPE (type1
)));
3596 delta21
= DECL_FIELD_BITPOS (delta21
);
3597 delta21
= size_binop (FLOOR_DIV_EXPR
, delta21
,
3598 size_int (BITS_PER_UNIT
));
3599 delta21
= convert (sizetype
, delta21
);
3602 index1
= integer_neg_one_node
;
3604 tree nop1
= build1 (NOP_EXPR
, TYPE_PTRMEMFUNC_FN_TYPE (type0
),
3606 TREE_CONSTANT (nop1
) = TREE_CONSTANT (op1
);
3609 e1
= build_binary_op (EQ_EXPR
, index0
, index1
, 1);
3610 e2
= build_binary_op (NE_EXPR
, index1
, integer_neg_one_node
, 1);
3611 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e2
,
3612 build_binary_op (EQ_EXPR
, delta20
, delta21
, 1),
3614 e3
= build_binary_op (EQ_EXPR
, pfn0
, op1
, 1);
3615 e2
= build_binary_op (TRUTH_ORIF_EXPR
, e2
, e3
, 1);
3616 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e1
, e2
, 1);
3617 if (code
== EQ_EXPR
)
3619 return build_binary_op (EQ_EXPR
, e2
, integer_zero_node
, 1);
3621 else if (TYPE_PTRMEMFUNC_P (type1
)
3622 && TYPE_PTRMEMFUNC_FN_TYPE (type1
) == type0
)
3624 return build_binary_op (code
, op1
, op0
, 1);
3630 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
3631 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
3633 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
3635 if (comp_target_types (type0
, type1
, 1))
3636 result_type
= common_type (type0
, type1
);
3639 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3641 result_type
= ptr_type_node
;
3650 build_type
= boolean_type_node
;
3651 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
3652 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
3654 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
3656 if (comp_target_types (type0
, type1
, 1))
3657 result_type
= common_type (type0
, type1
);
3660 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3662 result_type
= ptr_type_node
;
3665 else if (code0
== POINTER_TYPE
&& TREE_CODE (op1
) == INTEGER_CST
3666 && integer_zerop (op1
))
3667 result_type
= type0
;
3668 else if (code1
== POINTER_TYPE
&& TREE_CODE (op0
) == INTEGER_CST
3669 && integer_zerop (op0
))
3670 result_type
= type1
;
3671 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
3673 result_type
= type0
;
3674 pedwarn ("ANSI C++ forbids comparison between pointer and integer");
3676 else if (code0
== INTEGER_TYPE
&& code1
== POINTER_TYPE
)
3678 result_type
= type1
;
3679 pedwarn ("ANSI C++ forbids comparison between pointer and integer");
3687 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
|| code0
== COMPLEX_TYPE
)
3689 (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
|| code1
== COMPLEX_TYPE
))
3691 int none_complex
= (code0
!= COMPLEX_TYPE
&& code1
!= COMPLEX_TYPE
);
3693 if (shorten
|| common
|| short_compare
)
3694 result_type
= common_type (type0
, type1
);
3696 /* For certain operations (which identify themselves by shorten != 0)
3697 if both args were extended from the same smaller type,
3698 do the arithmetic in that type and then extend.
3700 shorten !=0 and !=1 indicates a bitwise operation.
3701 For them, this optimization is safe only if
3702 both args are zero-extended or both are sign-extended.
3703 Otherwise, we might change the result.
3704 Eg, (short)-1 | (unsigned short)-1 is (int)-1
3705 but calculated in (unsigned short) it would be (unsigned short)-1. */
3707 if (shorten
&& none_complex
)
3709 int unsigned0
, unsigned1
;
3710 tree arg0
= get_narrower (op0
, &unsigned0
);
3711 tree arg1
= get_narrower (op1
, &unsigned1
);
3712 /* UNS is 1 if the operation to be done is an unsigned one. */
3713 int uns
= TREE_UNSIGNED (result_type
);
3716 final_type
= result_type
;
3718 /* Handle the case that OP0 does not *contain* a conversion
3719 but it *requires* conversion to FINAL_TYPE. */
3721 if (op0
== arg0
&& TREE_TYPE (op0
) != final_type
)
3722 unsigned0
= TREE_UNSIGNED (TREE_TYPE (op0
));
3723 if (op1
== arg1
&& TREE_TYPE (op1
) != final_type
)
3724 unsigned1
= TREE_UNSIGNED (TREE_TYPE (op1
));
3726 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
3728 /* For bitwise operations, signedness of nominal type
3729 does not matter. Consider only how operands were extended. */
3733 /* Note that in all three cases below we refrain from optimizing
3734 an unsigned operation on sign-extended args.
3735 That would not be valid. */
3737 /* Both args variable: if both extended in same way
3738 from same width, do it in that width.
3739 Do it unsigned if args were zero-extended. */
3740 if ((TYPE_PRECISION (TREE_TYPE (arg0
))
3741 < TYPE_PRECISION (result_type
))
3742 && (TYPE_PRECISION (TREE_TYPE (arg1
))
3743 == TYPE_PRECISION (TREE_TYPE (arg0
)))
3744 && unsigned0
== unsigned1
3745 && (unsigned0
|| !uns
))
3747 = signed_or_unsigned_type (unsigned0
,
3748 common_type (TREE_TYPE (arg0
),
3750 else if (TREE_CODE (arg0
) == INTEGER_CST
3751 && (unsigned1
|| !uns
)
3752 && (TYPE_PRECISION (TREE_TYPE (arg1
))
3753 < TYPE_PRECISION (result_type
))
3754 && (type
= signed_or_unsigned_type (unsigned1
,
3756 int_fits_type_p (arg0
, type
)))
3758 else if (TREE_CODE (arg1
) == INTEGER_CST
3759 && (unsigned0
|| !uns
)
3760 && (TYPE_PRECISION (TREE_TYPE (arg0
))
3761 < TYPE_PRECISION (result_type
))
3762 && (type
= signed_or_unsigned_type (unsigned0
,
3764 int_fits_type_p (arg1
, type
)))
3768 /* Shifts can be shortened if shifting right. */
3773 tree arg0
= get_narrower (op0
, &unsigned_arg
);
3775 final_type
= result_type
;
3777 if (arg0
== op0
&& final_type
== TREE_TYPE (op0
))
3778 unsigned_arg
= TREE_UNSIGNED (TREE_TYPE (op0
));
3780 if (TYPE_PRECISION (TREE_TYPE (arg0
)) < TYPE_PRECISION (result_type
)
3781 /* We can shorten only if the shift count is less than the
3782 number of bits in the smaller type size. */
3783 && TREE_INT_CST_HIGH (op1
) == 0
3784 && TYPE_PRECISION (TREE_TYPE (arg0
)) > TREE_INT_CST_LOW (op1
)
3785 /* If arg is sign-extended and then unsigned-shifted,
3786 we can simulate this with a signed shift in arg's type
3787 only if the extended result is at least twice as wide
3788 as the arg. Otherwise, the shift could use up all the
3789 ones made by sign-extension and bring in zeros.
3790 We can't optimize that case at all, but in most machines
3791 it never happens because available widths are 2**N. */
3792 && (!TREE_UNSIGNED (final_type
)
3794 || (((unsigned) 2 * TYPE_PRECISION (TREE_TYPE (arg0
)))
3795 <= TYPE_PRECISION (result_type
))))
3797 /* Do an unsigned shift if the operand was zero-extended. */
3799 = signed_or_unsigned_type (unsigned_arg
,
3801 /* Convert value-to-be-shifted to that type. */
3802 if (TREE_TYPE (op0
) != result_type
)
3803 op0
= cp_convert (result_type
, op0
);
3808 /* Comparison operations are shortened too but differently.
3809 They identify themselves by setting short_compare = 1. */
3813 /* Don't write &op0, etc., because that would prevent op0
3814 from being kept in a register.
3815 Instead, make copies of the our local variables and
3816 pass the copies by reference, then copy them back afterward. */
3817 tree xop0
= op0
, xop1
= op1
, xresult_type
= result_type
;
3818 enum tree_code xresultcode
= resultcode
;
3820 = shorten_compare (&xop0
, &xop1
, &xresult_type
, &xresultcode
);
3822 return cp_convert (boolean_type_node
, val
);
3823 op0
= xop0
, op1
= xop1
;
3825 resultcode
= xresultcode
;
3828 if (short_compare
&& warn_sign_compare
)
3830 int op0_signed
= ! TREE_UNSIGNED (TREE_TYPE (orig_op0
));
3831 int op1_signed
= ! TREE_UNSIGNED (TREE_TYPE (orig_op1
));
3833 int unsignedp0
, unsignedp1
;
3834 tree primop0
= get_narrower (op0
, &unsignedp0
);
3835 tree primop1
= get_narrower (op1
, &unsignedp1
);
3837 /* Check for comparison of different enum types. */
3838 if (flag_int_enum_equivalence
== 0
3839 && TREE_CODE (TREE_TYPE (orig_op0
)) == ENUMERAL_TYPE
3840 && TREE_CODE (TREE_TYPE (orig_op1
)) == ENUMERAL_TYPE
3841 && TYPE_MAIN_VARIANT (TREE_TYPE (orig_op0
))
3842 != TYPE_MAIN_VARIANT (TREE_TYPE (orig_op1
)))
3844 cp_warning ("comparison between `%#T' and `%#T'",
3845 TREE_TYPE (orig_op0
), TREE_TYPE (orig_op1
));
3848 /* Give warnings for comparisons between signed and unsigned
3849 quantities that may fail. */
3850 /* Do the checking based on the original operand trees, so that
3851 casts will be considered, but default promotions won't be. */
3853 /* Do not warn if the comparison is being done in a signed type,
3854 since the signed type will only be chosen if it can represent
3855 all the values of the unsigned type. */
3856 if (! TREE_UNSIGNED (result_type
))
3858 /* Do not warn if both operands are unsigned. */
3859 else if (op0_signed
== op1_signed
)
3861 /* Do not warn if the signed quantity is an unsuffixed
3862 integer literal (or some static constant expression
3863 involving such literals) and it is non-negative. */
3864 else if ((op0_signed
&& TREE_CODE (orig_op0
) == INTEGER_CST
3865 && tree_int_cst_sgn (orig_op0
) >= 0)
3866 || (op1_signed
&& TREE_CODE (orig_op1
) == INTEGER_CST
3867 && tree_int_cst_sgn (orig_op1
) >= 0))
3869 /* Do not warn if the comparison is an equality operation,
3870 the unsigned quantity is an integral constant and it does
3871 not use the most significant bit of result_type. */
3872 else if ((resultcode
== EQ_EXPR
|| resultcode
== NE_EXPR
)
3873 && ((op0_signed
&& TREE_CODE (orig_op1
) == INTEGER_CST
3874 && int_fits_type_p (orig_op1
,
3875 signed_type (result_type
)))
3876 || (op1_signed
&& TREE_CODE (orig_op0
) == INTEGER_CST
3877 && int_fits_type_p (orig_op0
,
3878 signed_type (result_type
)))))
3881 warning ("comparison between signed and unsigned");
3883 /* Warn if two unsigned values are being compared in a size
3884 larger than their original size, and one (and only one) is the
3885 result of a `~' operator. This comparison will always fail.
3887 Also warn if one operand is a constant, and the constant does not
3888 have all bits set that are set in the ~ operand when it is
3891 if ((TREE_CODE (primop0
) == BIT_NOT_EXPR
)
3892 ^ (TREE_CODE (primop1
) == BIT_NOT_EXPR
))
3894 if (TREE_CODE (primop0
) == BIT_NOT_EXPR
)
3895 primop0
= get_narrower (TREE_OPERAND (op0
, 0), &unsignedp0
);
3896 if (TREE_CODE (primop1
) == BIT_NOT_EXPR
)
3897 primop1
= get_narrower (TREE_OPERAND (op1
, 0), &unsignedp1
);
3899 if (TREE_CODE (primop0
) == INTEGER_CST
3900 || TREE_CODE (primop1
) == INTEGER_CST
)
3903 HOST_WIDE_INT constant
, mask
;
3907 if (TREE_CODE (primop0
) == INTEGER_CST
)
3910 unsignedp
= unsignedp1
;
3911 constant
= TREE_INT_CST_LOW (primop0
);
3916 unsignedp
= unsignedp0
;
3917 constant
= TREE_INT_CST_LOW (primop1
);
3920 bits
= TYPE_PRECISION (TREE_TYPE (primop
));
3921 if (bits
< TYPE_PRECISION (result_type
)
3922 && bits
< HOST_BITS_PER_LONG
&& unsignedp
)
3924 mask
= (~ (HOST_WIDE_INT
) 0) << bits
;
3925 if ((mask
& constant
) != mask
)
3926 warning ("comparison of promoted ~unsigned with constant");
3929 else if (unsignedp0
&& unsignedp1
3930 && (TYPE_PRECISION (TREE_TYPE (primop0
))
3931 < TYPE_PRECISION (result_type
))
3932 && (TYPE_PRECISION (TREE_TYPE (primop1
))
3933 < TYPE_PRECISION (result_type
)))
3934 warning ("comparison of promoted ~unsigned with unsigned");
3939 /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
3940 If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
3941 Then the expression will be built.
3942 It will be given type FINAL_TYPE if that is nonzero;
3943 otherwise, it will be given type RESULT_TYPE. */
3947 cp_error ("invalid operands `%T' and `%T' to binary `%O'",
3948 TREE_TYPE (orig_op0
), TREE_TYPE (orig_op1
), error_code
);
3949 return error_mark_node
;
3954 if (TREE_TYPE (op0
) != result_type
)
3955 op0
= cp_convert (result_type
, op0
);
3956 if (TREE_TYPE (op1
) != result_type
)
3957 op1
= cp_convert (result_type
, op1
);
3960 if (build_type
== NULL_TREE
)
3961 build_type
= result_type
;
3964 register tree result
= build (resultcode
, build_type
, op0
, op1
);
3965 register tree folded
;
3967 folded
= fold (result
);
3968 if (folded
== result
)
3969 TREE_CONSTANT (folded
) = TREE_CONSTANT (op0
) & TREE_CONSTANT (op1
);
3970 if (final_type
!= 0)
3971 return cp_convert (final_type
, folded
);
3976 /* Return a tree for the sum or difference (RESULTCODE says which)
3977 of pointer PTROP and integer INTOP. */
3980 pointer_int_sum (resultcode
, ptrop
, intop
)
3981 enum tree_code resultcode
;
3982 register tree ptrop
, intop
;
3986 register tree result
;
3987 register tree folded
= fold (intop
);
3989 /* The result is a pointer of the same type that is being added. */
3991 register tree result_type
= TREE_TYPE (ptrop
);
3993 if (TREE_CODE (TREE_TYPE (result_type
)) == VOID_TYPE
)
3995 if (pedantic
|| warn_pointer_arith
)
3996 pedwarn ("ANSI C++ forbids using pointer of type `void *' in arithmetic");
3997 size_exp
= integer_one_node
;
3999 else if (TREE_CODE (TREE_TYPE (result_type
)) == FUNCTION_TYPE
)
4001 if (pedantic
|| warn_pointer_arith
)
4002 pedwarn ("ANSI C++ forbids using pointer to a function in arithmetic");
4003 size_exp
= integer_one_node
;
4005 else if (TREE_CODE (TREE_TYPE (result_type
)) == METHOD_TYPE
)
4007 if (pedantic
|| warn_pointer_arith
)
4008 pedwarn ("ANSI C++ forbids using pointer to a method in arithmetic");
4009 size_exp
= integer_one_node
;
4011 else if (TREE_CODE (TREE_TYPE (result_type
)) == OFFSET_TYPE
)
4013 if (pedantic
|| warn_pointer_arith
)
4014 pedwarn ("ANSI C++ forbids using pointer to a member in arithmetic");
4015 size_exp
= integer_one_node
;
4018 size_exp
= size_in_bytes (complete_type (TREE_TYPE (result_type
)));
4020 /* Needed to make OOPS V2R3 work. */
4022 if (TREE_CODE (intop
) == INTEGER_CST
4023 && TREE_INT_CST_LOW (intop
) == 0
4024 && TREE_INT_CST_HIGH (intop
) == 0)
4027 /* If what we are about to multiply by the size of the elements
4028 contains a constant term, apply distributive law
4029 and multiply that constant term separately.
4030 This helps produce common subexpressions. */
4032 if ((TREE_CODE (intop
) == PLUS_EXPR
|| TREE_CODE (intop
) == MINUS_EXPR
)
4033 && ! TREE_CONSTANT (intop
)
4034 && TREE_CONSTANT (TREE_OPERAND (intop
, 1))
4035 && TREE_CONSTANT (size_exp
))
4037 enum tree_code subcode
= resultcode
;
4038 if (TREE_CODE (intop
) == MINUS_EXPR
)
4039 subcode
= (subcode
== PLUS_EXPR
? MINUS_EXPR
: PLUS_EXPR
);
4040 ptrop
= build_binary_op (subcode
, ptrop
, TREE_OPERAND (intop
, 1), 1);
4041 intop
= TREE_OPERAND (intop
, 0);
4044 /* Convert the integer argument to a type the same size as sizetype
4045 so the multiply won't overflow spuriously. */
4047 if (TYPE_PRECISION (TREE_TYPE (intop
)) != TYPE_PRECISION (sizetype
))
4048 intop
= cp_convert (type_for_size (TYPE_PRECISION (sizetype
), 0), intop
);
4050 /* Replace the integer argument with a suitable product by the object size.
4051 Do this multiplication as signed, then convert to the appropriate
4052 pointer type (actually unsigned integral). */
4054 intop
= cp_convert (result_type
,
4055 build_binary_op (MULT_EXPR
, intop
,
4056 cp_convert (TREE_TYPE (intop
),
4060 /* Create the sum or difference. */
4062 result
= build (resultcode
, result_type
, ptrop
, intop
);
4064 folded
= fold (result
);
4065 if (folded
== result
)
4066 TREE_CONSTANT (folded
) = TREE_CONSTANT (ptrop
) & TREE_CONSTANT (intop
);
4070 /* Return a tree for the difference of pointers OP0 and OP1.
4071 The resulting tree has type int. */
4074 pointer_diff (op0
, op1
, ptrtype
)
4075 register tree op0
, op1
;
4076 register tree ptrtype
;
4078 register tree result
, folded
;
4079 tree restype
= ptrdiff_type_node
;
4080 tree target_type
= TREE_TYPE (ptrtype
);
4082 if (pedantic
|| warn_pointer_arith
)
4084 if (TREE_CODE (target_type
) == VOID_TYPE
)
4085 pedwarn ("ANSI C++ forbids using pointer of type `void *' in subtraction");
4086 if (TREE_CODE (target_type
) == FUNCTION_TYPE
)
4087 pedwarn ("ANSI C++ forbids using pointer to a function in subtraction");
4088 if (TREE_CODE (target_type
) == METHOD_TYPE
)
4089 pedwarn ("ANSI C++ forbids using pointer to a method in subtraction");
4090 if (TREE_CODE (target_type
) == OFFSET_TYPE
)
4091 pedwarn ("ANSI C++ forbids using pointer to a member in subtraction");
4094 /* First do the subtraction as integers;
4095 then drop through to build the divide operator. */
4097 op0
= build_binary_op (MINUS_EXPR
, cp_convert (restype
, op0
),
4098 cp_convert (restype
, op1
), 1);
4100 /* This generates an error if op1 is a pointer to an incomplete type. */
4101 if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (op1
))) == 0)
4102 error ("arithmetic on pointer to an incomplete type");
4104 op1
= ((TREE_CODE (target_type
) == VOID_TYPE
4105 || TREE_CODE (target_type
) == FUNCTION_TYPE
4106 || TREE_CODE (target_type
) == METHOD_TYPE
4107 || TREE_CODE (target_type
) == OFFSET_TYPE
)
4109 : size_in_bytes (target_type
));
4111 /* Do the division. */
4113 result
= build (EXACT_DIV_EXPR
, restype
, op0
, cp_convert (restype
, op1
));
4115 folded
= fold (result
);
4116 if (folded
== result
)
4117 TREE_CONSTANT (folded
) = TREE_CONSTANT (op0
) & TREE_CONSTANT (op1
);
4121 /* Handle the case of taking the address of a COMPONENT_REF.
4122 Called by `build_unary_op' and `build_up_reference'.
4124 ARG is the COMPONENT_REF whose address we want.
4125 ARGTYPE is the pointer type that this address should have.
4126 MSG is an error message to print if this COMPONENT_REF is not
4127 addressable (such as a bitfield). */
4130 build_component_addr (arg
, argtype
, msg
)
4134 tree field
= TREE_OPERAND (arg
, 1);
4135 tree basetype
= decl_type_context (field
);
4136 tree rval
= build_unary_op (ADDR_EXPR
, TREE_OPERAND (arg
, 0), 0);
4138 if (DECL_BIT_FIELD (field
))
4140 error (msg
, IDENTIFIER_POINTER (DECL_NAME (field
)));
4141 return error_mark_node
;
4144 if (TREE_CODE (field
) == FIELD_DECL
4145 && TYPE_USES_COMPLEX_INHERITANCE (basetype
))
4147 /* Can't convert directly to ARGTYPE, since that
4148 may have the same pointer type as one of our
4150 rval
= build1 (NOP_EXPR
, argtype
,
4151 convert_pointer_to (basetype
, rval
));
4152 TREE_CONSTANT (rval
) = TREE_CONSTANT (TREE_OPERAND (rval
, 0));
4155 /* This conversion is harmless. */
4156 rval
= convert_force (argtype
, rval
, 0);
4158 if (! integer_zerop (DECL_FIELD_BITPOS (field
)))
4160 tree offset
= size_binop (EASY_DIV_EXPR
, DECL_FIELD_BITPOS (field
),
4161 size_int (BITS_PER_UNIT
));
4162 int flag
= TREE_CONSTANT (rval
);
4163 offset
= convert (sizetype
, offset
);
4164 rval
= fold (build (PLUS_EXPR
, argtype
,
4165 rval
, cp_convert (argtype
, offset
)));
4166 TREE_CONSTANT (rval
) = flag
;
4171 /* Construct and perhaps optimize a tree representation
4172 for a unary operation. CODE, a tree_code, specifies the operation
4173 and XARG is the operand. */
4176 build_x_unary_op (code
, xarg
)
4177 enum tree_code code
;
4180 if (processing_template_decl
)
4181 return build_min_nt (code
, xarg
, NULL_TREE
);
4183 /* & rec, on incomplete RECORD_TYPEs is the simple opr &, not an
4185 if (code
== ADDR_EXPR
4186 && TREE_CODE (xarg
) != TEMPLATE_ID_EXPR
4187 && ((IS_AGGR_TYPE_CODE (TREE_CODE (TREE_TYPE (xarg
)))
4188 && TYPE_SIZE (TREE_TYPE (xarg
)) == NULL_TREE
)
4189 || (TREE_CODE (xarg
) == OFFSET_REF
)))
4190 /* don't look for a function */;
4195 rval
= build_new_op (code
, LOOKUP_NORMAL
, xarg
,
4196 NULL_TREE
, NULL_TREE
);
4197 if (rval
|| code
!= ADDR_EXPR
)
4201 if (code
== ADDR_EXPR
)
4203 if (TREE_CODE (xarg
) == TARGET_EXPR
)
4204 warning ("taking address of temporary");
4207 return build_unary_op (code
, xarg
, 0);
4210 /* Just like truthvalue_conversion, but we want a CLEANUP_POINT_EXPR. */
4213 condition_conversion (expr
)
4217 if (processing_template_decl
)
4219 t
= cp_convert (boolean_type_node
, expr
);
4220 t
= fold (build1 (CLEANUP_POINT_EXPR
, boolean_type_node
, t
));
4224 /* C++: Must handle pointers to members.
4226 Perhaps type instantiation should be extended to handle conversion
4227 from aggregates to types we don't yet know we want? (Or are those
4228 cases typically errors which should be reported?)
4230 NOCONVERT nonzero suppresses the default promotions
4231 (such as from short to int). */
4234 build_unary_op (code
, xarg
, noconvert
)
4235 enum tree_code code
;
4239 /* No default_conversion here. It causes trouble for ADDR_EXPR. */
4240 register tree arg
= xarg
;
4241 register tree argtype
= 0;
4242 char *errstring
= NULL
;
4245 if (arg
== error_mark_node
)
4246 return error_mark_node
;
4251 /* This is used for unary plus, because a CONVERT_EXPR
4252 is enough to prevent anybody from looking inside for
4253 associativity, but won't generate any code. */
4254 if (!(arg
= build_expr_type_conversion
4255 (WANT_ARITH
| WANT_ENUM
| WANT_POINTER
, arg
, 1)))
4256 errstring
= "wrong type argument to unary plus";
4260 arg
= default_conversion (arg
);
4261 arg
= build1 (NON_LVALUE_EXPR
, TREE_TYPE (arg
), arg
);
4262 TREE_CONSTANT (arg
) = TREE_CONSTANT (TREE_OPERAND (arg
, 0));
4267 if (!(arg
= build_expr_type_conversion (WANT_ARITH
| WANT_ENUM
, arg
, 1)))
4268 errstring
= "wrong type argument to unary minus";
4269 else if (!noconvert
)
4270 arg
= default_conversion (arg
);
4274 if (TREE_CODE (TREE_TYPE (arg
)) == COMPLEX_TYPE
)
4278 arg
= default_conversion (arg
);
4280 else if (!(arg
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
,
4282 errstring
= "wrong type argument to bit-complement";
4283 else if (!noconvert
)
4284 arg
= default_conversion (arg
);
4288 if (!(arg
= build_expr_type_conversion (WANT_ARITH
| WANT_ENUM
, arg
, 1)))
4289 errstring
= "wrong type argument to abs";
4290 else if (!noconvert
)
4291 arg
= default_conversion (arg
);
4295 /* Conjugating a real value is a no-op, but allow it anyway. */
4296 if (!(arg
= build_expr_type_conversion (WANT_ARITH
| WANT_ENUM
, arg
, 1)))
4297 errstring
= "wrong type argument to conjugation";
4298 else if (!noconvert
)
4299 arg
= default_conversion (arg
);
4302 case TRUTH_NOT_EXPR
:
4303 arg
= cp_convert (boolean_type_node
, arg
);
4304 val
= invert_truthvalue (arg
);
4305 if (arg
!= error_mark_node
)
4307 errstring
= "in argument to unary !";
4314 if (TREE_CODE (arg
) == COMPLEX_CST
)
4315 return TREE_REALPART (arg
);
4316 else if (TREE_CODE (TREE_TYPE (arg
)) == COMPLEX_TYPE
)
4317 return fold (build1 (REALPART_EXPR
, TREE_TYPE (TREE_TYPE (arg
)), arg
));
4322 if (TREE_CODE (arg
) == COMPLEX_CST
)
4323 return TREE_IMAGPART (arg
);
4324 else if (TREE_CODE (TREE_TYPE (arg
)) == COMPLEX_TYPE
)
4325 return fold (build1 (IMAGPART_EXPR
, TREE_TYPE (TREE_TYPE (arg
)), arg
));
4327 return cp_convert (TREE_TYPE (arg
), integer_zero_node
);
4329 case PREINCREMENT_EXPR
:
4330 case POSTINCREMENT_EXPR
:
4331 case PREDECREMENT_EXPR
:
4332 case POSTDECREMENT_EXPR
:
4333 /* Handle complex lvalues (when permitted)
4334 by reduction to simpler cases. */
4336 val
= unary_complex_lvalue (code
, arg
);
4340 /* Increment or decrement the real part of the value,
4341 and don't change the imaginary part. */
4342 if (TREE_CODE (TREE_TYPE (arg
)) == COMPLEX_TYPE
)
4346 arg
= stabilize_reference (arg
);
4347 real
= build_unary_op (REALPART_EXPR
, arg
, 1);
4348 imag
= build_unary_op (IMAGPART_EXPR
, arg
, 1);
4349 return build (COMPLEX_EXPR
, TREE_TYPE (arg
),
4350 build_unary_op (code
, real
, 1), imag
);
4353 /* Report invalid types. */
4355 if (!(arg
= build_expr_type_conversion (WANT_ARITH
| WANT_POINTER
,
4358 if (code
== PREINCREMENT_EXPR
)
4359 errstring
="no pre-increment operator for type";
4360 else if (code
== POSTINCREMENT_EXPR
)
4361 errstring
="no post-increment operator for type";
4362 else if (code
== PREDECREMENT_EXPR
)
4363 errstring
="no pre-decrement operator for type";
4365 errstring
="no post-decrement operator for type";
4369 /* Report something read-only. */
4371 if (TYPE_READONLY (TREE_TYPE (arg
))
4372 || TREE_READONLY (arg
))
4373 readonly_error (arg
, ((code
== PREINCREMENT_EXPR
4374 || code
== POSTINCREMENT_EXPR
)
4375 ? "increment" : "decrement"),
4380 tree result_type
= TREE_TYPE (arg
);
4382 arg
= get_unwidened (arg
, 0);
4383 argtype
= TREE_TYPE (arg
);
4385 /* ARM $5.2.5 last annotation says this should be forbidden. */
4386 if (TREE_CODE (argtype
) == ENUMERAL_TYPE
)
4387 pedwarn ("ANSI C++ forbids %sing an enum",
4388 (code
== PREINCREMENT_EXPR
|| code
== POSTINCREMENT_EXPR
)
4389 ? "increment" : "decrement");
4391 /* Compute the increment. */
4393 if (TREE_CODE (argtype
) == POINTER_TYPE
)
4395 enum tree_code tmp
= TREE_CODE (TREE_TYPE (argtype
));
4396 if (TYPE_SIZE (complete_type (TREE_TYPE (argtype
))) == 0)
4397 cp_error ("cannot %s a pointer to incomplete type `%T'",
4398 ((code
== PREINCREMENT_EXPR
4399 || code
== POSTINCREMENT_EXPR
)
4400 ? "increment" : "decrement"), TREE_TYPE (argtype
));
4401 else if ((pedantic
|| warn_pointer_arith
)
4402 && (tmp
== FUNCTION_TYPE
|| tmp
== METHOD_TYPE
4403 || tmp
== VOID_TYPE
|| tmp
== OFFSET_TYPE
))
4404 cp_pedwarn ("ANSI C++ forbids %sing a pointer of type `%T'",
4405 ((code
== PREINCREMENT_EXPR
4406 || code
== POSTINCREMENT_EXPR
)
4407 ? "increment" : "decrement"), argtype
);
4408 inc
= c_sizeof_nowarn (TREE_TYPE (argtype
));
4411 inc
= integer_one_node
;
4413 inc
= cp_convert (argtype
, inc
);
4415 /* Handle incrementing a cast-expression. */
4417 switch (TREE_CODE (arg
))
4422 case FIX_TRUNC_EXPR
:
4423 case FIX_FLOOR_EXPR
:
4424 case FIX_ROUND_EXPR
:
4427 tree incremented
, modify
, value
, compound
;
4428 if (! lvalue_p (arg
) && pedantic
)
4429 pedwarn ("cast to non-reference type used as lvalue");
4430 arg
= stabilize_reference (arg
);
4431 if (code
== PREINCREMENT_EXPR
|| code
== PREDECREMENT_EXPR
)
4434 value
= save_expr (arg
);
4435 incremented
= build (((code
== PREINCREMENT_EXPR
4436 || code
== POSTINCREMENT_EXPR
)
4437 ? PLUS_EXPR
: MINUS_EXPR
),
4438 argtype
, value
, inc
);
4439 TREE_SIDE_EFFECTS (incremented
) = 1;
4441 modify
= build_modify_expr (arg
, NOP_EXPR
, incremented
);
4442 compound
= build (COMPOUND_EXPR
, TREE_TYPE (arg
), modify
, value
);
4444 /* Eliminate warning about unused result of + or -. */
4445 TREE_NO_UNUSED_WARNING (compound
) = 1;
4453 /* Complain about anything else that is not a true lvalue. */
4454 if (!lvalue_or_else (arg
, ((code
== PREINCREMENT_EXPR
4455 || code
== POSTINCREMENT_EXPR
)
4456 ? "increment" : "decrement")))
4457 return error_mark_node
;
4459 /* Forbid using -- on `bool'. */
4460 if (TREE_TYPE (arg
) == boolean_type_node
)
4462 if (code
== POSTDECREMENT_EXPR
|| code
== PREDECREMENT_EXPR
)
4464 cp_error ("invalid use of `--' on bool variable `%D'", arg
);
4465 return error_mark_node
;
4468 /* This will only work if someone can convince Kenner to accept
4469 my patch to expand_increment. (jason) */
4470 val
= build (code
, TREE_TYPE (arg
), arg
, inc
);
4472 if (code
== POSTINCREMENT_EXPR
)
4474 arg
= stabilize_reference (arg
);
4475 val
= build (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
4477 TREE_SIDE_EFFECTS (val
) = 1;
4478 arg
= save_expr (arg
);
4479 val
= build (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
4480 val
= build (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
4483 val
= build (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
4488 val
= build (code
, TREE_TYPE (arg
), arg
, inc
);
4490 TREE_SIDE_EFFECTS (val
) = 1;
4491 return cp_convert (result_type
, val
);
4495 /* Note that this operation never does default_conversion
4496 regardless of NOCONVERT. */
4498 argtype
= TREE_TYPE (arg
);
4499 if (TREE_CODE (argtype
) == REFERENCE_TYPE
)
4503 build_pointer_type (TREE_TYPE (TREE_TYPE (arg
))), arg
);
4504 TREE_CONSTANT (arg
) = TREE_CONSTANT (TREE_OPERAND (arg
, 0));
4507 else if (pedantic
&& DECL_MAIN_P (arg
))
4509 pedwarn ("taking address of function `main'");
4511 /* Let &* cancel out to simplify resulting code. */
4512 if (TREE_CODE (arg
) == INDIRECT_REF
)
4514 /* We don't need to have `current_class_ptr' wrapped in a
4515 NON_LVALUE_EXPR node. */
4516 if (arg
== current_class_ref
)
4517 return current_class_ptr
;
4519 arg
= TREE_OPERAND (arg
, 0);
4520 if (TREE_CODE (TREE_TYPE (arg
)) == REFERENCE_TYPE
)
4524 build_pointer_type (TREE_TYPE (TREE_TYPE (arg
))), arg
);
4525 TREE_CONSTANT (arg
) = TREE_CONSTANT (TREE_OPERAND (arg
, 0));
4527 else if (lvalue_p (arg
))
4528 /* Don't let this be an lvalue. */
4529 return non_lvalue (arg
);
4533 /* For &x[y], return x+y */
4534 if (TREE_CODE (arg
) == ARRAY_REF
)
4536 if (mark_addressable (TREE_OPERAND (arg
, 0)) == 0)
4537 return error_mark_node
;
4538 return build_binary_op (PLUS_EXPR
, TREE_OPERAND (arg
, 0),
4539 TREE_OPERAND (arg
, 1), 1);
4542 /* Uninstantiated types are all functions. Taking the
4543 address of a function is a no-op, so just return the
4546 if (TREE_CODE (arg
) == IDENTIFIER_NODE
4547 && IDENTIFIER_OPNAME_P (arg
))
4549 my_friendly_abort (117);
4550 /* We don't know the type yet, so just work around the problem.
4551 We know that this will resolve to an lvalue. */
4552 return build1 (ADDR_EXPR
, unknown_type_node
, arg
);
4555 if (TREE_CODE (arg
) == OVERLOAD
)
4556 return build1 (ADDR_EXPR
, unknown_type_node
, arg
);
4557 else if (TREE_CODE (arg
) == TREE_LIST
)
4559 if (TREE_CODE (TREE_VALUE (arg
)) == FUNCTION_DECL
)
4560 /* Unique overloaded non-member function. */
4561 return build_unary_op (ADDR_EXPR
, TREE_VALUE (arg
), 0);
4562 if (TREE_CHAIN (arg
) == NULL_TREE
4563 && TREE_CODE (TREE_VALUE (arg
)) == TREE_LIST
4564 && TREE_CODE (TREE_VALUE (TREE_VALUE (arg
))) != OVERLOAD
)
4565 /* Unique overloaded member function. */
4566 return build_unary_op (ADDR_EXPR
, TREE_VALUE (TREE_VALUE (arg
)),
4568 return build1 (ADDR_EXPR
, unknown_type_node
, arg
);
4570 else if (TREE_CODE (arg
) == TEMPLATE_ID_EXPR
)
4575 /* We don't require a match here; it's possible that the
4576 context (like a cast to a particular type) will resolve
4577 the particular choice of template. */
4578 fn
= determine_specialization (arg
,
4586 fn
= instantiate_template (fn
, targs
);
4587 mark_addressable (fn
);
4588 return build_unary_op (ADDR_EXPR
, fn
, 0);
4591 return build1 (ADDR_EXPR
, unknown_type_node
, arg
);
4594 /* Handle complex lvalues (when permitted)
4595 by reduction to simpler cases. */
4596 val
= unary_complex_lvalue (code
, arg
);
4600 switch (TREE_CODE (arg
))
4605 case FIX_TRUNC_EXPR
:
4606 case FIX_FLOOR_EXPR
:
4607 case FIX_ROUND_EXPR
:
4609 if (! lvalue_p (arg
) && pedantic
)
4610 pedwarn ("taking the address of a cast to non-reference type");
4617 /* Allow the address of a constructor if all the elements
4619 if (TREE_CODE (arg
) == CONSTRUCTOR
&& TREE_HAS_CONSTRUCTOR (arg
)
4620 && TREE_CONSTANT (arg
))
4622 /* Anything not already handled and not a true memory reference
4624 else if (TREE_CODE (argtype
) != FUNCTION_TYPE
4625 && TREE_CODE (argtype
) != METHOD_TYPE
4626 && !lvalue_or_else (arg
, "unary `&'"))
4627 return error_mark_node
;
4629 /* Ordinary case; arg is a COMPONENT_REF or a decl. */
4630 /* If the lvalue is const or volatile,
4631 merge that into the type that the address will point to. */
4632 if (TREE_CODE_CLASS (TREE_CODE (arg
)) == 'd'
4633 || TREE_CODE_CLASS (TREE_CODE (arg
)) == 'r')
4635 if (TREE_READONLY (arg
) || TREE_THIS_VOLATILE (arg
))
4636 argtype
= cp_build_type_variant (argtype
,
4637 TREE_READONLY (arg
),
4638 TREE_THIS_VOLATILE (arg
));
4641 argtype
= build_pointer_type (argtype
);
4643 if (mark_addressable (arg
) == 0)
4644 return error_mark_node
;
4649 if (TREE_CODE (arg
) == COMPONENT_REF
)
4650 addr
= build_component_addr
4652 "attempt to take address of bit-field structure member `%s'");
4654 addr
= build1 (code
, argtype
, arg
);
4656 /* Address of a static or external variable or
4657 function counts as a constant */
4659 TREE_CONSTANT (addr
) = 1;
4661 if (TREE_CODE (argtype
) == POINTER_TYPE
4662 && TREE_CODE (TREE_TYPE (argtype
)) == METHOD_TYPE
)
4664 build_ptrmemfunc_type (argtype
);
4665 addr
= build_ptrmemfunc (argtype
, addr
, 0);
4678 argtype
= TREE_TYPE (arg
);
4679 return fold (build1 (code
, argtype
, arg
));
4683 return error_mark_node
;
4687 /* If CONVERSIONS is a conversion expression or a nested sequence of such,
4688 convert ARG with the same conversions in the same order
4689 and return the result. */
4692 convert_sequence (conversions
, arg
)
4696 switch (TREE_CODE (conversions
))
4701 case FIX_TRUNC_EXPR
:
4702 case FIX_FLOOR_EXPR
:
4703 case FIX_ROUND_EXPR
:
4705 return cp_convert (TREE_TYPE (conversions
),
4706 convert_sequence (TREE_OPERAND (conversions
, 0),
4715 /* Apply unary lvalue-demanding operator CODE to the expression ARG
4716 for certain kinds of expressions which are not really lvalues
4717 but which we can accept as lvalues.
4719 If ARG is not a kind of expression we can handle, return zero. */
4722 unary_complex_lvalue (code
, arg
)
4723 enum tree_code code
;
4726 /* Handle (a, b) used as an "lvalue". */
4727 if (TREE_CODE (arg
) == COMPOUND_EXPR
)
4729 tree real_result
= build_unary_op (code
, TREE_OPERAND (arg
, 1), 0);
4730 return build (COMPOUND_EXPR
, TREE_TYPE (real_result
),
4731 TREE_OPERAND (arg
, 0), real_result
);
4734 /* Handle (a ? b : c) used as an "lvalue". */
4735 if (TREE_CODE (arg
) == COND_EXPR
4736 || TREE_CODE (arg
) == MIN_EXPR
|| TREE_CODE (arg
) == MAX_EXPR
)
4737 return rationalize_conditional_expr (code
, arg
);
4739 if (TREE_CODE (arg
) == MODIFY_EXPR
4740 || TREE_CODE (arg
) == PREINCREMENT_EXPR
4741 || TREE_CODE (arg
) == PREDECREMENT_EXPR
)
4742 return unary_complex_lvalue
4743 (code
, build (COMPOUND_EXPR
, TREE_TYPE (TREE_OPERAND (arg
, 0)),
4744 arg
, TREE_OPERAND (arg
, 0)));
4746 if (code
!= ADDR_EXPR
)
4749 /* Handle (a = b) used as an "lvalue" for `&'. */
4750 if (TREE_CODE (arg
) == MODIFY_EXPR
4751 || TREE_CODE (arg
) == INIT_EXPR
)
4753 tree real_result
= build_unary_op (code
, TREE_OPERAND (arg
, 0), 0);
4754 arg
= build (COMPOUND_EXPR
, TREE_TYPE (real_result
), arg
, real_result
);
4755 TREE_NO_UNUSED_WARNING (arg
) = 1;
4759 if (TREE_CODE (TREE_TYPE (arg
)) == FUNCTION_TYPE
4760 || TREE_CODE (TREE_TYPE (arg
)) == METHOD_TYPE
4761 || TREE_CODE (TREE_TYPE (arg
)) == OFFSET_TYPE
)
4763 /* The representation of something of type OFFSET_TYPE
4764 is really the representation of a pointer to it.
4765 Here give the representation its true type. */
4768 my_friendly_assert (TREE_CODE (arg
) != SCOPE_REF
, 313);
4770 if (TREE_CODE (arg
) != OFFSET_REF
)
4773 t
= TREE_OPERAND (arg
, 1);
4775 /* Check all this code for right semantics. */
4776 if (TREE_CODE (t
) == FUNCTION_DECL
)
4777 return build_unary_op (ADDR_EXPR
, t
, 0);
4778 if (TREE_CODE (t
) == VAR_DECL
)
4779 return build_unary_op (ADDR_EXPR
, t
, 0);
4785 if (TREE_OPERAND (arg
, 0)
4786 && (TREE_CODE (TREE_OPERAND (arg
, 0)) != NOP_EXPR
4787 || (TREE_OPERAND (TREE_OPERAND (arg
, 0), 0)
4788 != error_mark_node
)))
4789 if (TREE_CODE (t
) != FIELD_DECL
)
4791 /* Don't know if this should return address to just
4792 _DECL, or actual address resolved in this expression. */
4793 sorry ("address of bound pointer-to-member expression");
4794 return error_mark_node
;
4797 /* Add in the offset to the field. */
4798 offset
= convert (sizetype
,
4799 size_binop (EASY_DIV_EXPR
,
4800 DECL_FIELD_BITPOS (t
),
4801 size_int (BITS_PER_UNIT
)));
4803 /* We offset all pointer to data members by 1 so that we can
4804 distinguish between a null pointer to data member and the first
4805 data member of a structure. */
4806 offset
= size_binop (PLUS_EXPR
, offset
, size_int (1));
4808 type
= build_offset_type (DECL_FIELD_CONTEXT (t
), TREE_TYPE (t
));
4809 type
= build_pointer_type (type
);
4811 return cp_convert (type
, offset
);
4816 /* We permit compiler to make function calls returning
4817 objects of aggregate type look like lvalues. */
4821 if (TREE_CODE (targ
) == SAVE_EXPR
)
4822 targ
= TREE_OPERAND (targ
, 0);
4824 if (TREE_CODE (targ
) == CALL_EXPR
&& IS_AGGR_TYPE (TREE_TYPE (targ
)))
4826 if (TREE_CODE (arg
) == SAVE_EXPR
)
4829 targ
= build_cplus_new (TREE_TYPE (arg
), arg
);
4830 return build1 (ADDR_EXPR
, build_pointer_type (TREE_TYPE (arg
)), targ
);
4833 if (TREE_CODE (arg
) == SAVE_EXPR
&& TREE_CODE (targ
) == INDIRECT_REF
)
4834 return build (SAVE_EXPR
, build_pointer_type (TREE_TYPE (arg
)),
4835 TREE_OPERAND (targ
, 0), current_function_decl
, NULL
);
4838 /* Don't let anything else be handled specially. */
4842 /* Mark EXP saying that we need to be able to take the
4843 address of it; it should not be allocated in a register.
4844 Value is 1 if successful.
4846 C++: we do not allow `current_class_ptr' to be addressable. */
4849 mark_addressable (exp
)
4852 register tree x
= exp
;
4854 if (TREE_ADDRESSABLE (x
) == 1)
4858 switch (TREE_CODE (x
))
4865 x
= TREE_OPERAND (x
, 0);
4869 if (x
== current_class_ptr
)
4871 if (! flag_this_is_variable
)
4872 error ("address of `this' not available");
4873 TREE_ADDRESSABLE (x
) = 1; /* so compiler doesn't die later */
4874 put_var_into_stack (x
);
4878 if (TREE_STATIC (x
) && TREE_READONLY (x
)
4879 && DECL_RTL (x
) != 0
4880 && ! DECL_IN_MEMORY_P (x
))
4882 /* We thought this would make a good constant variable,
4883 but we were wrong. */
4884 push_obstacks_nochange ();
4885 end_temporary_allocation ();
4887 TREE_ASM_WRITTEN (x
) = 0;
4889 rest_of_decl_compilation (x
, 0, IDENTIFIER_LOCAL_VALUE (x
) == 0,
4891 TREE_ADDRESSABLE (x
) = 1;
4897 /* Caller should not be trying to mark initialized
4898 constant fields addressable. */
4899 my_friendly_assert (DECL_LANG_SPECIFIC (x
) == 0
4900 || DECL_IN_AGGR_P (x
) == 0
4902 || DECL_EXTERNAL (x
), 314);
4906 if (DECL_REGISTER (x
) && !TREE_ADDRESSABLE (x
)
4907 && !DECL_ARTIFICIAL (x
) && extra_warnings
)
4908 cp_warning ("address requested for `%D', which is declared `register'",
4910 put_var_into_stack (x
);
4911 TREE_ADDRESSABLE (x
) = 1;
4915 if (DECL_LANG_SPECIFIC (x
) != 0)
4917 x
= DECL_MAIN_VARIANT (x
);
4918 /* We have to test both conditions here. The first may be
4919 non-zero in the case of processing a default function. The
4920 second may be non-zero in the case of a template function. */
4921 if (DECL_TEMPLATE_INFO (x
) && !DECL_TEMPLATE_SPECIALIZATION (x
))
4924 TREE_ADDRESSABLE (x
) = 1;
4926 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (x
)) = 1;
4930 TREE_ADDRESSABLE (x
) = 1;
4934 TREE_ADDRESSABLE (x
) = 1;
4935 mark_addressable (TREE_OPERAND (x
, 0));
4943 /* Build and return a conditional expression IFEXP ? OP1 : OP2. */
4946 build_x_conditional_expr (ifexp
, op1
, op2
)
4947 tree ifexp
, op1
, op2
;
4949 if (processing_template_decl
)
4950 return build_min_nt (COND_EXPR
, ifexp
, op1
, op2
);
4952 return build_new_op (COND_EXPR
, LOOKUP_NORMAL
, ifexp
, op1
, op2
);
4956 build_conditional_expr (ifexp
, op1
, op2
)
4957 tree ifexp
, op1
, op2
;
4959 register tree type1
;
4960 register tree type2
;
4961 register enum tree_code code1
;
4962 register enum tree_code code2
;
4963 register tree result_type
= NULL_TREE
;
4965 /* If second operand is omitted, it is the same as the first one;
4966 make sure it is calculated only once. */
4970 pedwarn ("ANSI C++ forbids omitting the middle term of a ?: expression");
4971 ifexp
= op1
= save_expr (ifexp
);
4974 ifexp
= cp_convert (boolean_type_node
, ifexp
);
4976 if (TREE_CODE (ifexp
) == ERROR_MARK
)
4977 return error_mark_node
;
4979 op1
= require_instantiated_type (TREE_TYPE (op2
), op1
, error_mark_node
);
4980 if (op1
== error_mark_node
)
4981 return error_mark_node
;
4982 op2
= require_instantiated_type (TREE_TYPE (op1
), op2
, error_mark_node
);
4983 if (op2
== error_mark_node
)
4984 return error_mark_node
;
4986 /* C++: REFERENCE_TYPES must be dereferenced. */
4987 type1
= TREE_TYPE (op1
);
4988 code1
= TREE_CODE (type1
);
4989 type2
= TREE_TYPE (op2
);
4990 code2
= TREE_CODE (type2
);
4992 if (code1
== REFERENCE_TYPE
)
4994 op1
= convert_from_reference (op1
);
4995 type1
= TREE_TYPE (op1
);
4996 code1
= TREE_CODE (type1
);
4998 if (code2
== REFERENCE_TYPE
)
5000 op2
= convert_from_reference (op2
);
5001 type2
= TREE_TYPE (op2
);
5002 code2
= TREE_CODE (type2
);
5005 /* Don't promote the operands separately if they promote
5006 the same way. Return the unpromoted type and let the combined
5007 value get promoted if necessary. */
5009 if (TYPE_MAIN_VARIANT (type1
) == TYPE_MAIN_VARIANT (type2
)
5010 && code2
!= ARRAY_TYPE
5011 && code2
!= FUNCTION_TYPE
5012 && code2
!= METHOD_TYPE
)
5016 if (TREE_CONSTANT (ifexp
)
5017 && (TREE_CODE (ifexp
) == INTEGER_CST
5018 || TREE_CODE (ifexp
) == ADDR_EXPR
))
5019 return (integer_zerop (ifexp
) ? op2
: op1
);
5021 if (TREE_CODE (op1
) == CONST_DECL
)
5022 op1
= DECL_INITIAL (op1
);
5023 else if (TREE_READONLY_DECL_P (op1
))
5024 op1
= decl_constant_value (op1
);
5025 if (TREE_CODE (op2
) == CONST_DECL
)
5026 op2
= DECL_INITIAL (op2
);
5027 else if (TREE_READONLY_DECL_P (op2
))
5028 op2
= decl_constant_value (op2
);
5030 type1
= cp_build_type_variant
5032 TREE_READONLY (op1
) || TREE_READONLY (op2
),
5033 TREE_THIS_VOLATILE (op1
) || TREE_THIS_VOLATILE (op2
));
5034 /* ??? This is a kludge to deal with the fact that
5035 we don't sort out integers and enums properly, yet. */
5036 result
= fold (build (COND_EXPR
, type1
, ifexp
, op1
, op2
));
5037 if (TREE_TYPE (result
) != type1
)
5038 result
= build1 (NOP_EXPR
, type1
, result
);
5039 /* Expand both sides into the same slot,
5040 hopefully the target of the ?: expression. */
5041 if (TREE_CODE (op1
) == TARGET_EXPR
&& TREE_CODE (op2
) == TARGET_EXPR
)
5043 tree slot
= build (VAR_DECL
, TREE_TYPE (result
));
5044 layout_decl (slot
, 0);
5045 result
= build (TARGET_EXPR
, TREE_TYPE (result
),
5046 slot
, result
, NULL_TREE
, NULL_TREE
);
5051 /* They don't match; promote them both and then try to reconcile them.
5052 But don't permit mismatching enum types. */
5053 if (code1
== ENUMERAL_TYPE
)
5055 if (code2
== ENUMERAL_TYPE
)
5057 cp_error ("enumeral mismatch in conditional expression: `%T' vs `%T'",
5059 return error_mark_node
;
5061 else if (extra_warnings
&& ! IS_AGGR_TYPE_CODE (code2
)
5062 && type2
!= type_promotes_to (type1
))
5063 warning ("enumeral and non-enumeral type in conditional expression");
5065 else if (extra_warnings
5066 && code2
== ENUMERAL_TYPE
&& ! IS_AGGR_TYPE_CODE (code1
)
5067 && type1
!= type_promotes_to (type2
))
5068 warning ("enumeral and non-enumeral type in conditional expression");
5070 if (code1
!= VOID_TYPE
)
5072 op1
= default_conversion (op1
);
5073 type1
= TREE_TYPE (op1
);
5074 if (TYPE_PTRMEMFUNC_P (type1
))
5075 type1
= TYPE_PTRMEMFUNC_FN_TYPE (type1
);
5076 code1
= TREE_CODE (type1
);
5078 if (code2
!= VOID_TYPE
)
5080 op2
= default_conversion (op2
);
5081 type2
= TREE_TYPE (op2
);
5082 if (TYPE_PTRMEMFUNC_P (type2
))
5083 type2
= TYPE_PTRMEMFUNC_FN_TYPE (type2
);
5084 code2
= TREE_CODE (type2
);
5087 if (code1
== RECORD_TYPE
&& code2
== RECORD_TYPE
5088 && real_lvalue_p (op1
) && real_lvalue_p (op2
)
5089 && comptypes (type1
, type2
, -1))
5091 type1
= build_reference_type (type1
);
5092 type2
= build_reference_type (type2
);
5093 result_type
= common_type (type1
, type2
);
5094 op1
= convert_to_reference (result_type
, op1
, CONV_IMPLICIT
,
5095 LOOKUP_NORMAL
, NULL_TREE
);
5096 op2
= convert_to_reference (result_type
, op2
, CONV_IMPLICIT
,
5097 LOOKUP_NORMAL
, NULL_TREE
);
5099 /* Quickly detect the usual case where op1 and op2 have the same type
5101 else if (TYPE_MAIN_VARIANT (type1
) == TYPE_MAIN_VARIANT (type2
))
5104 result_type
= type1
;
5106 result_type
= cp_build_type_variant
5108 TREE_READONLY (op1
) || TREE_READONLY (op2
),
5109 TREE_THIS_VOLATILE (op1
) || TREE_THIS_VOLATILE (op2
));
5111 else if ((code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
)
5112 && (code2
== INTEGER_TYPE
|| code2
== REAL_TYPE
))
5114 result_type
= common_type (type1
, type2
);
5116 else if (code1
== VOID_TYPE
|| code2
== VOID_TYPE
)
5118 if (pedantic
&& (code1
!= VOID_TYPE
|| code2
!= VOID_TYPE
))
5119 pedwarn ("ANSI C++ forbids conditional expr with only one void side");
5120 result_type
= void_type_node
;
5122 else if (code1
== POINTER_TYPE
&& null_ptr_cst_p (op2
))
5123 result_type
= qualify_type (type1
, type2
);
5124 else if (code2
== POINTER_TYPE
&& null_ptr_cst_p (op1
))
5125 result_type
= qualify_type (type2
, type1
);
5126 else if (code1
== POINTER_TYPE
&& code2
== POINTER_TYPE
)
5128 if (comp_target_types (type1
, type2
, 1))
5129 result_type
= common_type (type1
, type2
);
5130 else if (TYPE_MAIN_VARIANT (TREE_TYPE (type1
)) == void_type_node
)
5132 if (pedantic
&& TREE_CODE (type2
) == FUNCTION_TYPE
)
5133 pedwarn ("ANSI C++ forbids conditional expr between `void *' and function pointer");
5134 result_type
= qualify_type (type1
, type2
);
5136 else if (TYPE_MAIN_VARIANT (TREE_TYPE (type2
)) == void_type_node
)
5138 if (pedantic
&& TREE_CODE (type1
) == FUNCTION_TYPE
)
5139 pedwarn ("ANSI C++ forbids conditional expr between `void *' and function pointer");
5140 result_type
= qualify_type (type2
, type1
);
5143 else if (comptypes (type2
, type1
, 0))
5144 result_type
= type2
;
5145 else if (IS_AGGR_TYPE (TREE_TYPE (type1
))
5146 && IS_AGGR_TYPE (TREE_TYPE (type2
))
5147 && (result_type
= common_base_type (TREE_TYPE (type1
),
5148 TREE_TYPE (type2
))))
5150 if (result_type
== error_mark_node
)
5152 cp_error ("common base type of types `%T' and `%T' is ambiguous",
5153 TREE_TYPE (type1
), TREE_TYPE (type2
));
5154 result_type
= ptr_type_node
;
5159 && result_type
!= TREE_TYPE (type1
)
5160 && result_type
!= TREE_TYPE (type2
))
5161 cp_pedwarn ("`%T' and `%T' converted to `%T *' in conditional expression",
5162 type1
, type2
, result_type
);
5164 result_type
= build_pointer_type (result_type
);
5169 pedwarn ("pointer type mismatch in conditional expression");
5170 result_type
= ptr_type_node
;
5173 else if (code1
== POINTER_TYPE
&& code2
== INTEGER_TYPE
)
5175 pedwarn ("pointer/integer type mismatch in conditional expression");
5176 result_type
= type1
;
5178 else if (code2
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
5180 pedwarn ("pointer/integer type mismatch in conditional expression");
5181 result_type
= type2
;
5186 /* The match does not look good. If either is
5187 an aggregate value, try converting to a scalar type. */
5188 if (code1
== RECORD_TYPE
&& code2
== RECORD_TYPE
)
5190 cp_error ("aggregate mismatch in conditional expression: `%T' vs `%T'",
5192 return error_mark_node
;
5194 /* Warning: this code assumes that conversion between cv-variants of
5195 a type is done using NOP_EXPRs. */
5196 if (code1
== RECORD_TYPE
&& TYPE_HAS_CONVERSION (type1
))
5198 /* There are other types besides pointers and records. */
5200 if (code2
== POINTER_TYPE
)
5201 tmp
= build_pointer_type
5202 (build_type_variant (TREE_TYPE (type2
), 1, 1));
5205 tmp
= build_type_conversion (CONVERT_EXPR
, tmp
, op1
, 0);
5206 if (tmp
== NULL_TREE
)
5208 cp_error ("incompatible types `%T' and `%T' in `?:'",
5210 return error_mark_node
;
5212 if (tmp
== error_mark_node
)
5213 error ("ambiguous pointer conversion");
5216 result_type
= common_type (type2
, TREE_TYPE (tmp
));
5219 else if (code2
== RECORD_TYPE
&& TYPE_HAS_CONVERSION (type2
))
5222 if (code1
== POINTER_TYPE
)
5223 tmp
= build_pointer_type
5224 (build_type_variant (TREE_TYPE (type1
), 1, 1));
5228 tmp
= build_type_conversion (CONVERT_EXPR
, tmp
, op2
, 0);
5229 if (tmp
== NULL_TREE
)
5231 cp_error ("incompatible types `%T' and `%T' in `?:'",
5233 return error_mark_node
;
5235 if (tmp
== error_mark_node
)
5236 error ("ambiguous pointer conversion");
5239 result_type
= common_type (type1
, TREE_TYPE (tmp
));
5242 else if (flag_cond_mismatch
)
5243 result_type
= void_type_node
;
5246 error ("type mismatch in conditional expression");
5247 return error_mark_node
;
5251 if (TREE_CODE (result_type
) == POINTER_TYPE
5252 && TREE_CODE (TREE_TYPE (result_type
)) == METHOD_TYPE
)
5253 result_type
= build_ptrmemfunc_type (result_type
);
5255 if (result_type
!= TREE_TYPE (op1
))
5256 op1
= convert_for_initialization
5257 (NULL_TREE
, result_type
, op1
, LOOKUP_NORMAL
, "converting", NULL_TREE
, 0);
5258 if (result_type
!= TREE_TYPE (op2
))
5259 op2
= convert_for_initialization
5260 (NULL_TREE
, result_type
, op2
, LOOKUP_NORMAL
, "converting", NULL_TREE
, 0);
5262 if (TREE_CONSTANT (ifexp
))
5263 return integer_zerop (ifexp
) ? op2
: op1
;
5265 return convert_from_reference
5266 (fold (build (COND_EXPR
, result_type
, ifexp
, op1
, op2
)));
5269 /* Handle overloading of the ',' operator when needed. Otherwise,
5270 this function just builds an expression list. */
5273 build_x_compound_expr (list
)
5276 tree rest
= TREE_CHAIN (list
);
5279 if (processing_template_decl
)
5280 return build_min_nt (COMPOUND_EXPR
, list
, NULL_TREE
);
5282 if (rest
== NULL_TREE
)
5283 return build_compound_expr (list
);
5285 result
= build_opfncall (COMPOUND_EXPR
, LOOKUP_NORMAL
,
5286 TREE_VALUE (list
), TREE_VALUE (rest
), NULL_TREE
);
5288 return build_x_compound_expr (expr_tree_cons (NULL_TREE
, result
,
5289 TREE_CHAIN (rest
)));
5291 if (! TREE_SIDE_EFFECTS (TREE_VALUE (list
)))
5293 /* the left-hand operand of a comma expression is like an expression
5294 statement: we should warn if it doesn't have any side-effects,
5295 unless it was explicitly cast to (void). */
5296 if ((extra_warnings
|| warn_unused
)
5297 && !(TREE_CODE (TREE_VALUE(list
)) == CONVERT_EXPR
5298 && TREE_TYPE (TREE_VALUE(list
)) == void_type_node
))
5299 warning("left-hand operand of comma expression has no effect");
5301 #if 0 /* this requires a gcc backend patch to export warn_if_unused_value */
5302 else if (warn_unused
)
5303 warn_if_unused_value (TREE_VALUE(list
));
5306 return build_compound_expr
5307 (expr_tree_cons (NULL_TREE
, TREE_VALUE (list
),
5308 build_expr_list (NULL_TREE
,
5309 build_x_compound_expr (rest
))));
5312 /* Given a list of expressions, return a compound expression
5313 that performs them all and returns the value of the last of them. */
5316 build_compound_expr (list
)
5321 if (TREE_READONLY_DECL_P (TREE_VALUE (list
)))
5322 TREE_VALUE (list
) = decl_constant_value (TREE_VALUE (list
));
5324 if (TREE_CHAIN (list
) == 0)
5326 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5327 Strip such NOP_EXPRs, since LIST is used in non-lvalue context. */
5328 if (TREE_CODE (list
) == NOP_EXPR
5329 && TREE_TYPE (list
) == TREE_TYPE (TREE_OPERAND (list
, 0)))
5330 list
= TREE_OPERAND (list
, 0);
5332 /* Convert arrays to pointers. */
5333 if (TREE_CODE (TREE_TYPE (TREE_VALUE (list
))) == ARRAY_TYPE
)
5334 return default_conversion (TREE_VALUE (list
));
5336 return TREE_VALUE (list
);
5339 rest
= build_compound_expr (TREE_CHAIN (list
));
5341 /* When pedantic, a compound expression cannot be a constant expression. */
5342 if (! TREE_SIDE_EFFECTS (TREE_VALUE (list
)) && ! pedantic
)
5345 return build (COMPOUND_EXPR
, TREE_TYPE (rest
),
5346 break_out_cleanups (TREE_VALUE (list
)), rest
);
5350 build_static_cast (type
, expr
)
5356 if (type
== error_mark_node
|| expr
== error_mark_node
)
5357 return error_mark_node
;
5359 if (TREE_CODE (expr
) == OFFSET_REF
)
5360 expr
= resolve_offset_ref (expr
);
5362 if (processing_template_decl
)
5364 tree t
= build_min (STATIC_CAST_EXPR
, copy_to_permanent (type
),
5369 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5370 Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */
5371 if (TREE_CODE (type
) != REFERENCE_TYPE
5372 && TREE_CODE (expr
) == NOP_EXPR
5373 && TREE_TYPE (expr
) == TREE_TYPE (TREE_OPERAND (expr
, 0)))
5374 expr
= TREE_OPERAND (expr
, 0);
5376 if (TREE_CODE (type
) == VOID_TYPE
)
5377 return build1 (CONVERT_EXPR
, type
, expr
);
5379 if (type_unknown_p (expr
))
5381 expr
= instantiate_type (type
, expr
, 1);
5382 if (expr
== error_mark_node
)
5383 return error_mark_node
;
5386 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5387 return (convert_from_reference
5388 (convert_to_reference (type
, expr
, CONV_STATIC
|CONV_IMPLICIT
,
5389 LOOKUP_COMPLAIN
, NULL_TREE
)));
5391 if (IS_AGGR_TYPE (type
))
5392 return build_cplus_new
5393 (type
, (build_method_call
5394 (NULL_TREE
, ctor_identifier
, build_expr_list (NULL_TREE
, expr
),
5395 TYPE_BINFO (type
), LOOKUP_NORMAL
)));
5397 expr
= decay_conversion (expr
);
5398 intype
= TREE_TYPE (expr
);
5400 /* FIXME handle casting to array type. */
5403 if (can_convert_arg (type
, intype
, expr
))
5405 else if (TYPE_PTROB_P (type
) && TYPE_PTROB_P (intype
))
5408 if (IS_AGGR_TYPE (TREE_TYPE (type
)) && IS_AGGR_TYPE (TREE_TYPE (intype
))
5409 && (TYPE_READONLY (TREE_TYPE (type
))
5410 >= TYPE_READONLY (TREE_TYPE (intype
)))
5411 && (TYPE_VOLATILE (TREE_TYPE (type
))
5412 >= TYPE_VOLATILE (TREE_TYPE (intype
)))
5413 && (binfo
= get_binfo (TREE_TYPE (intype
), TREE_TYPE (type
), 0))
5414 && ! TREE_VIA_VIRTUAL (binfo
))
5417 else if (TYPE_PTRMEM_P (type
) && TYPE_PTRMEM_P (intype
))
5419 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
))),
5420 TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (intype
))), 1)
5421 && (TYPE_READONLY (TREE_TYPE (TREE_TYPE (type
)))
5422 >= TYPE_READONLY (TREE_TYPE (TREE_TYPE (intype
))))
5423 && (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (type
)))
5424 >= TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (intype
))))
5425 && (binfo
= get_binfo (TYPE_OFFSET_BASETYPE (intype
),
5426 TYPE_OFFSET_BASETYPE (type
), 0))
5427 && ! TREE_VIA_VIRTUAL (binfo
))
5430 else if (TREE_CODE (intype
) != BOOLEAN_TYPE
5431 && TREE_CODE (type
) != ARRAY_TYPE
5432 && TREE_CODE (type
) != FUNCTION_TYPE
5433 && can_convert (intype
, type
))
5437 return build_c_cast (type
, expr
);
5439 cp_error ("static_cast from `%T' to `%T'", intype
, type
);
5440 return error_mark_node
;
5444 build_reinterpret_cast (type
, expr
)
5449 if (type
== error_mark_node
|| expr
== error_mark_node
)
5450 return error_mark_node
;
5452 if (TREE_CODE (expr
) == OFFSET_REF
)
5453 expr
= resolve_offset_ref (expr
);
5455 if (processing_template_decl
)
5457 tree t
= build_min (REINTERPRET_CAST_EXPR
,
5458 copy_to_permanent (type
), expr
);
5462 if (TREE_CODE (type
) != REFERENCE_TYPE
)
5464 expr
= decay_conversion (expr
);
5466 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5467 Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */
5468 if (TREE_CODE (expr
) == NOP_EXPR
5469 && TREE_TYPE (expr
) == TREE_TYPE (TREE_OPERAND (expr
, 0)))
5470 expr
= TREE_OPERAND (expr
, 0);
5473 if (type_unknown_p (expr
))
5475 expr
= instantiate_type (type
, expr
, 1);
5476 if (expr
== error_mark_node
)
5477 return error_mark_node
;
5480 intype
= TREE_TYPE (expr
);
5482 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5484 if (! real_lvalue_p (expr
))
5486 cp_error ("reinterpret_cast from `%T' rvalue to `%T'", intype
, type
);
5487 return error_mark_node
;
5489 expr
= build_unary_op (ADDR_EXPR
, expr
, 0);
5490 if (expr
!= error_mark_node
)
5491 expr
= build_reinterpret_cast
5492 (build_pointer_type (TREE_TYPE (type
)), expr
);
5493 if (expr
!= error_mark_node
)
5494 expr
= build_indirect_ref (expr
, 0);
5497 else if (comptypes (TYPE_MAIN_VARIANT (intype
), TYPE_MAIN_VARIANT (type
), 1))
5498 return build_static_cast (type
, expr
);
5500 if (TYPE_PTR_P (type
) && (TREE_CODE (intype
) == INTEGER_TYPE
5501 || TREE_CODE (intype
) == ENUMERAL_TYPE
))
5503 else if (TREE_CODE (type
) == INTEGER_TYPE
&& TYPE_PTR_P (intype
))
5505 if (TYPE_PRECISION (type
) < TYPE_PRECISION (intype
))
5506 cp_pedwarn ("reinterpret_cast from `%T' to `%T' loses precision",
5509 else if ((TYPE_PTRFN_P (type
) && TYPE_PTRFN_P (intype
))
5510 || (TYPE_PTRMEMFUNC_P (type
) && TYPE_PTRMEMFUNC_P (intype
)))
5512 if (TREE_READONLY_DECL_P (expr
))
5513 expr
= decl_constant_value (expr
);
5514 return fold (build1 (NOP_EXPR
, type
, expr
));
5516 else if ((TYPE_PTRMEM_P (type
) && TYPE_PTRMEM_P (intype
))
5517 || (TYPE_PTROBV_P (type
) && TYPE_PTROBV_P (intype
)))
5519 if (! comp_ptr_ttypes_reinterpret (TREE_TYPE (type
), TREE_TYPE (intype
)))
5520 cp_pedwarn ("reinterpret_cast from `%T' to `%T' casts away const (or volatile)",
5523 if (TREE_READONLY_DECL_P (expr
))
5524 expr
= decl_constant_value (expr
);
5525 return fold (build1 (NOP_EXPR
, type
, expr
));
5527 else if ((TYPE_PTRFN_P (type
) && TYPE_PTROBV_P (intype
))
5528 || (TYPE_PTRFN_P (type
) && TYPE_PTROBV_P (intype
)))
5530 pedwarn ("ANSI C++ forbids casting between pointers to functions and objects");
5531 if (TREE_READONLY_DECL_P (expr
))
5532 expr
= decl_constant_value (expr
);
5533 return fold (build1 (NOP_EXPR
, type
, expr
));
5537 cp_error ("reinterpret_cast from `%T' to `%T'", intype
, type
);
5538 return error_mark_node
;
5541 return cp_convert (type
, expr
);
5545 build_const_cast (type
, expr
)
5550 if (type
== error_mark_node
|| expr
== error_mark_node
)
5551 return error_mark_node
;
5553 if (TREE_CODE (expr
) == OFFSET_REF
)
5554 expr
= resolve_offset_ref (expr
);
5556 if (processing_template_decl
)
5558 tree t
= build_min (CONST_CAST_EXPR
, copy_to_permanent (type
),
5563 if (TREE_CODE (type
) != REFERENCE_TYPE
)
5565 expr
= decay_conversion (expr
);
5567 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5568 Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */
5569 if (TREE_CODE (expr
) == NOP_EXPR
5570 && TREE_TYPE (expr
) == TREE_TYPE (TREE_OPERAND (expr
, 0)))
5571 expr
= TREE_OPERAND (expr
, 0);
5574 if (type_unknown_p (expr
))
5576 expr
= instantiate_type (type
, expr
, 1);
5577 if (expr
== error_mark_node
)
5578 return error_mark_node
;
5581 intype
= TREE_TYPE (expr
);
5583 if (comptypes (TYPE_MAIN_VARIANT (intype
), TYPE_MAIN_VARIANT (type
), 1))
5584 return build_static_cast (type
, expr
);
5585 else if (TREE_CODE (type
) == REFERENCE_TYPE
)
5587 if (! real_lvalue_p (expr
))
5589 cp_error ("const_cast from `%T' rvalue to `%T'", intype
, type
);
5590 return error_mark_node
;
5593 if (comp_ptr_ttypes_const (TREE_TYPE (type
), intype
))
5595 expr
= build_unary_op (ADDR_EXPR
, expr
, 0);
5596 expr
= build1 (NOP_EXPR
, type
, expr
);
5597 return convert_from_reference (expr
);
5600 else if (TREE_CODE (type
) == POINTER_TYPE
5601 && TREE_CODE (intype
) == POINTER_TYPE
5602 && comp_ptr_ttypes_const (TREE_TYPE (type
), TREE_TYPE (intype
)))
5603 return cp_convert (type
, expr
);
5605 cp_error ("const_cast from `%T' to `%T'", intype
, type
);
5606 return error_mark_node
;
5609 /* Build an expression representing a cast to type TYPE of expression EXPR.
5611 ALLOW_NONCONVERTING is true if we should allow non-converting constructors
5612 when doing the cast. */
5615 build_c_cast (type
, expr
)
5618 register tree value
= expr
;
5620 if (type
== error_mark_node
|| expr
== error_mark_node
)
5621 return error_mark_node
;
5623 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5624 Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */
5625 if (TREE_CODE (type
) != REFERENCE_TYPE
5626 && TREE_CODE (value
) == NOP_EXPR
5627 && TREE_TYPE (value
) == TREE_TYPE (TREE_OPERAND (value
, 0)))
5628 value
= TREE_OPERAND (value
, 0);
5630 if (TREE_TYPE (expr
)
5631 && TREE_CODE (TREE_TYPE (expr
)) == OFFSET_TYPE
5632 && TREE_CODE (type
) != OFFSET_TYPE
)
5633 value
= resolve_offset_ref (value
);
5635 if (TREE_CODE (type
) == ARRAY_TYPE
)
5637 /* Allow casting from T1* to T2[] because Cfront allows it.
5638 NIHCL uses it. It is not valid ANSI C however, and hence, not
5640 if (TREE_CODE (TREE_TYPE (expr
)) == POINTER_TYPE
)
5643 pedwarn ("ANSI C++ forbids casting to an array type");
5644 type
= build_pointer_type (TREE_TYPE (type
));
5648 error ("ANSI C++ forbids casting to an array type");
5649 return error_mark_node
;
5653 if (TREE_CODE (type
) == FUNCTION_TYPE
5654 || TREE_CODE (type
) == METHOD_TYPE
)
5656 cp_error ("casting to function type `%T'", type
);
5657 return error_mark_node
;
5660 if (IS_SIGNATURE (type
))
5662 error ("cast specifies signature type");
5663 return error_mark_node
;
5666 if (processing_template_decl
)
5668 tree t
= build_min (CAST_EXPR
, type
,
5669 min_tree_cons (NULL_TREE
, value
, NULL_TREE
));
5673 if (TREE_CODE (type
) == VOID_TYPE
)
5674 value
= build1 (CONVERT_EXPR
, type
, value
);
5675 else if (TREE_TYPE (value
) == NULL_TREE
5676 || type_unknown_p (value
))
5678 value
= instantiate_type (type
, value
, 1);
5680 if (value
== error_mark_node
)
5681 return error_mark_node
;
5687 /* Convert functions and arrays to pointers and
5688 convert references to their expanded types,
5689 but don't convert any other types. If, however, we are
5690 casting to a class type, there's no reason to do this: the
5691 cast will only succeed if there is a converting constructor,
5692 and the default conversions will be done at that point. In
5693 fact, doing the default conversion here is actually harmful
5697 struct S { S(const A&); };
5699 since we don't want the array-to-pointer conversion done. */
5700 if (!IS_AGGR_TYPE (type
))
5702 if (TREE_CODE (TREE_TYPE (value
)) == FUNCTION_TYPE
5703 || (TREE_CODE (TREE_TYPE (value
)) == METHOD_TYPE
5704 /* Don't do the default conversion if we want a
5705 pointer to a function. */
5706 && ! (TREE_CODE (type
) == POINTER_TYPE
5707 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
))
5708 || TREE_CODE (TREE_TYPE (value
)) == ARRAY_TYPE
5709 || TREE_CODE (TREE_TYPE (value
)) == REFERENCE_TYPE
)
5710 value
= default_conversion (value
);
5712 else if (TREE_CODE (TREE_TYPE (value
)) == REFERENCE_TYPE
)
5713 /* However, even for class types, we still need to strip away
5714 the reference type, since the call to convert_force below
5715 does not expect the input expression to be of reference
5717 value
= convert_from_reference (value
);
5719 otype
= TREE_TYPE (value
);
5721 /* Optionally warn about potentially worrisome casts. */
5724 && TREE_CODE (type
) == POINTER_TYPE
5725 && TREE_CODE (otype
) == POINTER_TYPE
)
5727 /* For C++ we make these regular warnings, rather than
5728 softening them into pedwarns. */
5729 if (TYPE_VOLATILE (TREE_TYPE (otype
))
5730 && ! TYPE_VOLATILE (TREE_TYPE (type
)))
5731 warning ("cast discards `volatile' from pointer target type");
5732 if (TYPE_READONLY (TREE_TYPE (otype
))
5733 && ! TYPE_READONLY (TREE_TYPE (type
)))
5734 warning ("cast discards `const' from pointer target type");
5737 /* Warn about possible alignment problems. */
5738 if (STRICT_ALIGNMENT
&& warn_cast_align
5739 && TREE_CODE (type
) == POINTER_TYPE
5740 && TREE_CODE (otype
) == POINTER_TYPE
5741 && TREE_CODE (TREE_TYPE (otype
)) != VOID_TYPE
5742 && TREE_CODE (TREE_TYPE (otype
)) != FUNCTION_TYPE
5743 && TYPE_ALIGN (TREE_TYPE (type
)) > TYPE_ALIGN (TREE_TYPE (otype
)))
5744 warning ("cast increases required alignment of target type");
5747 /* We should see about re-enabling these, they seem useful to
5749 if (TREE_CODE (type
) == INTEGER_TYPE
5750 && TREE_CODE (otype
) == POINTER_TYPE
5751 && TYPE_PRECISION (type
) != TYPE_PRECISION (otype
))
5752 warning ("cast from pointer to integer of different size");
5754 if (TREE_CODE (type
) == POINTER_TYPE
5755 && TREE_CODE (otype
) == INTEGER_TYPE
5756 && TYPE_PRECISION (type
) != TYPE_PRECISION (otype
)
5757 /* Don't warn about converting 0 to pointer,
5758 provided the 0 was explicit--not cast or made by folding. */
5759 && !(TREE_CODE (value
) == INTEGER_CST
&& integer_zerop (value
)))
5760 warning ("cast to pointer from integer of different size");
5763 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5764 value
= (convert_from_reference
5765 (convert_to_reference (type
, value
, CONV_C_CAST
,
5766 LOOKUP_COMPLAIN
, NULL_TREE
)));
5771 if (TREE_READONLY_DECL_P (value
))
5772 value
= decl_constant_value (value
);
5775 value
= convert_force (type
, value
, CONV_C_CAST
);
5777 /* Ignore any integer overflow caused by the cast. */
5778 if (TREE_CODE (value
) == INTEGER_CST
)
5780 TREE_OVERFLOW (value
) = TREE_OVERFLOW (ovalue
);
5781 TREE_CONSTANT_OVERFLOW (value
) = TREE_CONSTANT_OVERFLOW (ovalue
);
5786 /* Always produce some operator for an explicit cast,
5787 so we can tell (for -pedantic) that the cast is no lvalue. */
5788 if (TREE_CODE (type
) != REFERENCE_TYPE
&& value
== expr
5789 && real_lvalue_p (value
))
5790 value
= non_lvalue (value
);
5795 /* Build an assignment expression of lvalue LHS from value RHS.
5796 MODIFYCODE is the code for a binary operator that we use
5797 to combine the old value of LHS with RHS to get the new value.
5798 Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.
5800 C++: If MODIFYCODE is INIT_EXPR, then leave references unbashed. */
5803 build_modify_expr (lhs
, modifycode
, rhs
)
5805 enum tree_code modifycode
;
5808 register tree result
;
5810 tree lhstype
= TREE_TYPE (lhs
);
5811 tree olhstype
= lhstype
;
5814 /* Avoid duplicate error messages from operands that had errors. */
5815 if (lhs
== error_mark_node
|| rhs
== error_mark_node
)
5816 return error_mark_node
;
5818 /* Types that aren't fully specified cannot be used in assignments. */
5819 lhs
= require_complete_type (lhs
);
5823 /* Handle assignment to signature pointers/refs. */
5825 if (TYPE_LANG_SPECIFIC (lhstype
)
5826 && (IS_SIGNATURE_POINTER (lhstype
) || IS_SIGNATURE_REFERENCE (lhstype
)))
5828 return build_signature_pointer_constructor (lhs
, rhs
);
5831 /* Handle control structure constructs used as "lvalues". */
5833 switch (TREE_CODE (lhs
))
5835 /* Handle --foo = 5; as these are valid constructs in C++ */
5836 case PREDECREMENT_EXPR
:
5837 case PREINCREMENT_EXPR
:
5838 if (TREE_SIDE_EFFECTS (TREE_OPERAND (lhs
, 0)))
5839 lhs
= build (TREE_CODE (lhs
), TREE_TYPE (lhs
),
5840 stabilize_reference (TREE_OPERAND (lhs
, 0)),
5841 TREE_OPERAND (lhs
, 1));
5842 return build (COMPOUND_EXPR
, lhstype
,
5844 build_modify_expr (TREE_OPERAND (lhs
, 0),
5847 /* Handle (a, b) used as an "lvalue". */
5849 newrhs
= build_modify_expr (TREE_OPERAND (lhs
, 1),
5851 if (newrhs
== error_mark_node
)
5852 return error_mark_node
;
5853 return build (COMPOUND_EXPR
, lhstype
,
5854 TREE_OPERAND (lhs
, 0), newrhs
);
5857 newrhs
= build_modify_expr (TREE_OPERAND (lhs
, 0), modifycode
, rhs
);
5858 if (newrhs
== error_mark_node
)
5859 return error_mark_node
;
5860 return build (COMPOUND_EXPR
, lhstype
, lhs
, newrhs
);
5862 /* Handle (a ? b : c) used as an "lvalue". */
5864 rhs
= save_expr (rhs
);
5866 /* Produce (a ? (b = rhs) : (c = rhs))
5867 except that the RHS goes through a save-expr
5868 so the code to compute it is only emitted once. */
5870 = build_conditional_expr (TREE_OPERAND (lhs
, 0),
5871 build_modify_expr (cp_convert (TREE_TYPE (lhs
), TREE_OPERAND (lhs
, 1)),
5873 build_modify_expr (cp_convert (TREE_TYPE (lhs
), TREE_OPERAND (lhs
, 2)),
5875 if (cond
== error_mark_node
)
5877 /* Make sure the code to compute the rhs comes out
5878 before the split. */
5879 return build (COMPOUND_EXPR
, TREE_TYPE (lhs
),
5880 /* Case to void to suppress warning
5881 from warn_if_unused_value. */
5882 cp_convert (void_type_node
, rhs
), cond
);
5889 if (TREE_CODE (lhs
) == OFFSET_REF
)
5891 if (TREE_OPERAND (lhs
, 0) == NULL_TREE
)
5893 /* Static class member? */
5894 tree member
= TREE_OPERAND (lhs
, 1);
5895 if (TREE_CODE (member
) == VAR_DECL
)
5899 compiler_error ("invalid static class member");
5900 return error_mark_node
;
5904 lhs
= resolve_offset_ref (lhs
);
5906 olhstype
= lhstype
= TREE_TYPE (lhs
);
5909 if (TREE_CODE (lhstype
) == REFERENCE_TYPE
5910 && modifycode
!= INIT_EXPR
)
5912 lhs
= convert_from_reference (lhs
);
5913 olhstype
= lhstype
= TREE_TYPE (lhs
);
5916 /* If a binary op has been requested, combine the old LHS value with the RHS
5917 producing the value we should actually store into the LHS. */
5919 if (modifycode
== INIT_EXPR
)
5921 if (! IS_AGGR_TYPE (lhstype
))
5922 /* Do the default thing */;
5925 result
= build_method_call (lhs
, ctor_identifier
,
5926 build_expr_list (NULL_TREE
, rhs
),
5927 TYPE_BINFO (lhstype
), LOOKUP_NORMAL
);
5928 if (result
== NULL_TREE
)
5929 return error_mark_node
;
5933 else if (modifycode
== NOP_EXPR
)
5935 /* `operator=' is not an inheritable operator. */
5936 if (! IS_AGGR_TYPE (lhstype
))
5937 /* Do the default thing */;
5940 result
= build_opfncall (MODIFY_EXPR
, LOOKUP_NORMAL
,
5941 lhs
, rhs
, make_node (NOP_EXPR
));
5942 if (result
== NULL_TREE
)
5943 return error_mark_node
;
5948 else if (PROMOTES_TO_AGGR_TYPE (lhstype
, REFERENCE_TYPE
))
5950 my_friendly_abort (978652);
5954 lhs
= stabilize_reference (lhs
);
5955 newrhs
= build_binary_op (modifycode
, lhs
, rhs
, 1);
5956 if (newrhs
== error_mark_node
)
5958 cp_error (" in evaluation of `%Q(%#T, %#T)'", modifycode
,
5959 TREE_TYPE (lhs
), TREE_TYPE (rhs
));
5960 return error_mark_node
;
5964 /* Handle a cast used as an "lvalue".
5965 We have already performed any binary operator using the value as cast.
5966 Now convert the result to the cast type of the lhs,
5967 and then true type of the lhs and store it there;
5968 then convert result back to the cast type to be the value
5969 of the assignment. */
5971 switch (TREE_CODE (lhs
))
5976 case FIX_TRUNC_EXPR
:
5977 case FIX_FLOOR_EXPR
:
5978 case FIX_ROUND_EXPR
:
5980 if (TREE_CODE (TREE_TYPE (newrhs
)) == ARRAY_TYPE
5981 || TREE_CODE (TREE_TYPE (newrhs
)) == FUNCTION_TYPE
5982 || TREE_CODE (TREE_TYPE (newrhs
)) == METHOD_TYPE
5983 || TREE_CODE (TREE_TYPE (newrhs
)) == OFFSET_TYPE
)
5984 newrhs
= default_conversion (newrhs
);
5986 tree inner_lhs
= TREE_OPERAND (lhs
, 0);
5989 /* WP 5.4.1: The result is an lvalue if T is a reference type,
5990 otherwise the result is an rvalue. */
5991 if (! lvalue_p (lhs
))
5992 pedwarn ("ANSI C++ forbids cast to non-reference type used as lvalue");
5994 result
= build_modify_expr (inner_lhs
, NOP_EXPR
,
5995 cp_convert (TREE_TYPE (inner_lhs
),
5996 cp_convert (lhstype
, newrhs
)));
5997 if (result
== error_mark_node
)
5999 return cp_convert (TREE_TYPE (lhs
), result
);
6006 /* Now we have handled acceptable kinds of LHS that are not truly lvalues.
6007 Reject anything strange now. */
6009 if (!lvalue_or_else (lhs
, "assignment"))
6010 return error_mark_node
;
6012 GNU_xref_assign (lhs
);
6014 /* Warn about storing in something that is `const'. */
6015 /* For C++, don't warn if this is initialization. */
6016 if (modifycode
!= INIT_EXPR
6017 /* For assignment to `const' signature pointer/reference fields,
6018 don't warn either, we already printed a better message before. */
6019 && ! (TREE_CODE (lhs
) == COMPONENT_REF
6020 && (IS_SIGNATURE_POINTER (TREE_TYPE (TREE_OPERAND (lhs
, 0)))
6021 || IS_SIGNATURE_REFERENCE (TREE_TYPE (TREE_OPERAND (lhs
, 0)))))
6022 && (TREE_READONLY (lhs
) || TYPE_READONLY (lhstype
)
6023 || ((TREE_CODE (lhstype
) == RECORD_TYPE
6024 || TREE_CODE (lhstype
) == UNION_TYPE
)
6025 && C_TYPE_FIELDS_READONLY (lhstype
))
6026 || (TREE_CODE (lhstype
) == REFERENCE_TYPE
6027 && TYPE_READONLY (TREE_TYPE (lhstype
)))))
6028 readonly_error (lhs
, "assignment", 0);
6030 /* If storing into a structure or union member,
6031 it has probably been given type `int'.
6032 Compute the type that would go with
6033 the actual amount of storage the member occupies. */
6035 if (TREE_CODE (lhs
) == COMPONENT_REF
6036 && (TREE_CODE (lhstype
) == INTEGER_TYPE
6037 || TREE_CODE (lhstype
) == REAL_TYPE
6038 || TREE_CODE (lhstype
) == ENUMERAL_TYPE
))
6040 lhstype
= TREE_TYPE (get_unwidened (lhs
, 0));
6042 /* If storing in a field that is in actuality a short or narrower
6043 than one, we must store in the field in its actual type. */
6045 if (lhstype
!= TREE_TYPE (lhs
))
6047 lhs
= copy_node (lhs
);
6048 TREE_TYPE (lhs
) = lhstype
;
6052 /* check to see if there is an assignment to `this' */
6053 if (lhs
== current_class_ptr
)
6055 if (flag_this_is_variable
> 0
6056 && DECL_NAME (current_function_decl
) != NULL_TREE
6057 && (DECL_NAME (current_function_decl
)
6058 != constructor_name (current_class_type
)))
6059 warning ("assignment to `this' not in constructor or destructor");
6060 current_function_just_assigned_this
= 1;
6063 /* The TREE_TYPE of RHS may be TYPE_UNKNOWN. This can happen
6064 when the type of RHS is not yet known, i.e. its type
6065 is inherited from LHS. */
6066 rhs
= require_instantiated_type (lhstype
, newrhs
, error_mark_node
);
6067 if (rhs
== error_mark_node
)
6068 return error_mark_node
;
6071 if (modifycode
!= INIT_EXPR
)
6073 /* Make modifycode now either a NOP_EXPR or an INIT_EXPR. */
6074 modifycode
= NOP_EXPR
;
6075 /* Reference-bashing */
6076 if (TREE_CODE (lhstype
) == REFERENCE_TYPE
)
6078 tree tmp
= convert_from_reference (lhs
);
6079 lhstype
= TREE_TYPE (tmp
);
6080 if (TYPE_SIZE (lhstype
) == 0)
6082 incomplete_type_error (lhs
, lhstype
);
6083 return error_mark_node
;
6088 if (TREE_CODE (TREE_TYPE (newrhs
)) == REFERENCE_TYPE
)
6090 tree tmp
= convert_from_reference (newrhs
);
6091 if (TYPE_SIZE (TREE_TYPE (tmp
)) == 0)
6093 incomplete_type_error (newrhs
, TREE_TYPE (tmp
));
6094 return error_mark_node
;
6100 if (TREE_SIDE_EFFECTS (lhs
))
6101 lhs
= stabilize_reference (lhs
);
6102 if (TREE_SIDE_EFFECTS (newrhs
))
6103 newrhs
= stabilize_reference (newrhs
);
6105 /* Convert new value to destination type. */
6107 if (TREE_CODE (lhstype
) == ARRAY_TYPE
)
6111 if (! comptypes (lhstype
, TREE_TYPE (rhs
), 0))
6113 cp_error ("incompatible types in assignment of `%T' to `%T'",
6114 TREE_TYPE (rhs
), lhstype
);
6115 return error_mark_node
;
6118 /* Allow array assignment in compiler-generated code. */
6119 if (pedantic
&& ! DECL_ARTIFICIAL (current_function_decl
))
6120 pedwarn ("ANSI C++ forbids assignment of arrays");
6122 /* Have to wrap this in RTL_EXPR for two cases:
6123 in base or member initialization and if we
6124 are a branch of a ?: operator. Since we
6125 can't easily know the latter, just do it always. */
6127 result
= make_node (RTL_EXPR
);
6129 TREE_TYPE (result
) = void_type_node
;
6130 do_pending_stack_adjust ();
6131 start_sequence_for_rtl_expr (result
);
6133 /* As a matter of principle, `start_sequence' should do this. */
6136 from_array
= TREE_CODE (TREE_TYPE (newrhs
)) == ARRAY_TYPE
6137 ? 1 + (modifycode
!= INIT_EXPR
): 0;
6138 expand_vec_init (lhs
, lhs
, array_type_nelts (lhstype
), newrhs
,
6141 do_pending_stack_adjust ();
6143 TREE_SIDE_EFFECTS (result
) = 1;
6144 RTL_EXPR_SEQUENCE (result
) = get_insns ();
6145 RTL_EXPR_RTL (result
) = const0_rtx
;
6150 if (modifycode
== INIT_EXPR
)
6152 newrhs
= convert_for_initialization (lhs
, lhstype
, newrhs
, LOOKUP_NORMAL
,
6153 "assignment", NULL_TREE
, 0);
6154 if (lhs
== DECL_RESULT (current_function_decl
))
6156 if (DECL_INITIAL (lhs
))
6157 warning ("return value from function receives multiple initializations");
6158 DECL_INITIAL (lhs
) = newrhs
;
6163 /* Avoid warnings on enum bit fields. */
6164 if (TREE_CODE (olhstype
) == ENUMERAL_TYPE
6165 && TREE_CODE (lhstype
) == INTEGER_TYPE
)
6167 newrhs
= convert_for_assignment (olhstype
, newrhs
, "assignment",
6169 newrhs
= convert_force (lhstype
, newrhs
, 0);
6172 newrhs
= convert_for_assignment (lhstype
, newrhs
, "assignment",
6174 if (TREE_CODE (newrhs
) == CALL_EXPR
6175 && TYPE_NEEDS_CONSTRUCTING (lhstype
))
6176 newrhs
= build_cplus_new (lhstype
, newrhs
);
6178 /* Can't initialize directly from a TARGET_EXPR, since that would
6179 cause the lhs to be constructed twice, and possibly result in
6180 accidental self-initialization. So we force the TARGET_EXPR to be
6181 expanded without a target. */
6182 if (TREE_CODE (newrhs
) == TARGET_EXPR
)
6183 newrhs
= build (COMPOUND_EXPR
, TREE_TYPE (newrhs
), newrhs
,
6184 TREE_OPERAND (newrhs
, 0));
6187 if (newrhs
== error_mark_node
)
6188 return error_mark_node
;
6190 if (TREE_CODE (newrhs
) == COND_EXPR
)
6193 tree cond
= TREE_OPERAND (newrhs
, 0);
6195 if (TREE_SIDE_EFFECTS (lhs
))
6196 cond
= build_compound_expr (tree_cons
6198 build_expr_list (NULL_TREE
, cond
)));
6200 /* Cannot have two identical lhs on this one tree (result) as preexpand
6201 calls will rip them out and fill in RTL for them, but when the
6202 rtl is generated, the calls will only be in the first side of the
6203 condition, not on both, or before the conditional jump! (mrs) */
6204 lhs1
= break_out_calls (lhs
);
6207 /* If there's no change, the COND_EXPR behaves like any other rhs. */
6208 result
= build (modifycode
== NOP_EXPR
? MODIFY_EXPR
: INIT_EXPR
,
6209 lhstype
, lhs
, newrhs
);
6212 tree result_type
= TREE_TYPE (newrhs
);
6213 /* We have to convert each arm to the proper type because the
6214 types may have been munged by constant folding. */
6216 = build (COND_EXPR
, result_type
, cond
,
6217 build_modify_expr (lhs
, modifycode
,
6218 cp_convert (result_type
,
6219 TREE_OPERAND (newrhs
, 1))),
6220 build_modify_expr (lhs1
, modifycode
,
6221 cp_convert (result_type
,
6222 TREE_OPERAND (newrhs
, 2))));
6226 result
= build (modifycode
== NOP_EXPR
? MODIFY_EXPR
: INIT_EXPR
,
6227 lhstype
, lhs
, newrhs
);
6229 TREE_SIDE_EFFECTS (result
) = 1;
6231 /* If we got the LHS in a different type for storing in,
6232 convert the result back to the nominal type of LHS
6233 so that the value we return always has the same type
6234 as the LHS argument. */
6236 if (olhstype
== TREE_TYPE (result
))
6238 /* Avoid warnings converting integral types back into enums
6239 for enum bit fields. */
6240 if (TREE_CODE (TREE_TYPE (result
)) == INTEGER_TYPE
6241 && TREE_CODE (olhstype
) == ENUMERAL_TYPE
)
6243 result
= build (COMPOUND_EXPR
, olhstype
, result
, olhs
);
6244 TREE_NO_UNUSED_WARNING (result
) = 1;
6247 return convert_for_assignment (olhstype
, result
, "assignment",
6252 build_x_modify_expr (lhs
, modifycode
, rhs
)
6254 enum tree_code modifycode
;
6257 if (processing_template_decl
)
6258 return build_min_nt (MODOP_EXPR
, lhs
,
6259 build_min_nt (modifycode
, NULL_TREE
, NULL_TREE
), rhs
);
6261 if (modifycode
!= NOP_EXPR
)
6263 tree rval
= build_opfncall (MODIFY_EXPR
, LOOKUP_NORMAL
, lhs
, rhs
,
6264 make_node (modifycode
));
6268 return build_modify_expr (lhs
, modifycode
, rhs
);
6271 /* Return 0 if EXP is not a valid lvalue in this language
6272 even though `lvalue_or_else' would accept it. */
6275 language_lvalue_valid (exp
)
6276 tree exp ATTRIBUTE_UNUSED
;
6281 /* Get difference in deltas for different pointer to member function
6282 types. Return integer_zero_node, if FROM cannot be converted to a
6283 TO type. If FORCE is true, then allow reverse conversions as well. */
6286 get_delta_difference (from
, to
, force
)
6290 tree delta
= integer_zero_node
;
6296 /* Should get_base_distance here, so we can check if any thing along the
6297 path is virtual, and we need to make sure we stay
6298 inside the real binfos when going through virtual bases.
6299 Maybe we should replace virtual bases with
6300 binfo_member (...CLASSTYPE_VBASECLASSES...)... (mrs) */
6301 binfo
= get_binfo (from
, to
, 1);
6302 if (binfo
== error_mark_node
)
6304 error (" in pointer to member function conversion");
6311 error_not_base_type (from
, to
);
6312 error (" in pointer to member conversion");
6315 binfo
= get_binfo (to
, from
, 1);
6316 if (binfo
== 0 || binfo
== error_mark_node
)
6318 if (TREE_VIA_VIRTUAL (binfo
))
6320 binfo
= binfo_member (BINFO_TYPE (binfo
),
6321 CLASSTYPE_VBASECLASSES (from
));
6322 cp_warning ("pointer to member cast to virtual base `%T'",
6323 BINFO_TYPE (binfo
));
6324 warning (" will only work if you are very careful");
6326 delta
= BINFO_OFFSET (binfo
);
6327 delta
= cp_convert (ptrdiff_type_node
, delta
);
6329 return build_binary_op (MINUS_EXPR
,
6334 if (TREE_VIA_VIRTUAL (binfo
))
6338 cp_warning ("pointer to member cast from virtual base `%T'",
6339 BINFO_TYPE (binfo
));
6340 warning (" will only work if you are very careful");
6343 cp_error ("pointer to member conversion from virtual base `%T'",
6344 BINFO_TYPE (binfo
));
6347 return BINFO_OFFSET (binfo
);
6351 build_ptrmemfunc1 (type
, delta
, idx
, pfn
, delta2
)
6352 tree type
, delta
, idx
, pfn
, delta2
;
6357 /* This is the old way we did it. We want to avoid calling
6358 digest_init, so that it can give an error if we use { } when
6359 initializing a pointer to member function. */
6363 u
= build_nt (CONSTRUCTOR
, NULL_TREE
,
6364 expr_tree_cons (pfn_identifier
, pfn
, NULL_TREE
));
6368 u
= build_nt (CONSTRUCTOR
, NULL_TREE
,
6369 expr_tree_cons (delta2_identifier
, delta2
, NULL_TREE
));
6372 u
= build_nt (CONSTRUCTOR
, NULL_TREE
,
6373 expr_tree_cons (NULL_TREE
, delta
,
6374 expr_tree_cons (NULL_TREE
, idx
,
6375 expr_tree_cons (NULL_TREE
, u
, NULL_TREE
))));
6377 return digest_init (type
, u
, (tree
*)0);
6379 tree delta_field
, idx_field
, pfn_or_delta2_field
, pfn_field
, delta2_field
;
6381 int allconstant
, allsimple
;
6383 delta_field
= TYPE_FIELDS (type
);
6384 idx_field
= TREE_CHAIN (delta_field
);
6385 pfn_or_delta2_field
= TREE_CHAIN (idx_field
);
6386 subtype
= TREE_TYPE (pfn_or_delta2_field
);
6387 pfn_field
= TYPE_FIELDS (subtype
);
6388 delta2_field
= TREE_CHAIN (pfn_field
);
6392 allconstant
= TREE_CONSTANT (pfn
);
6393 allsimple
= !! initializer_constant_valid_p (pfn
, TREE_TYPE (pfn
));
6394 u
= expr_tree_cons (pfn_field
, pfn
, NULL_TREE
);
6398 delta2
= convert_and_check (delta_type_node
, delta2
);
6399 allconstant
= TREE_CONSTANT (delta2
);
6400 allsimple
= !! initializer_constant_valid_p (delta2
, TREE_TYPE (delta2
));
6401 u
= expr_tree_cons (delta2_field
, delta2
, NULL_TREE
);
6404 delta
= convert_and_check (delta_type_node
, delta
);
6405 idx
= convert_and_check (delta_type_node
, idx
);
6407 allconstant
= allconstant
&& TREE_CONSTANT (delta
) && TREE_CONSTANT (idx
);
6408 allsimple
= allsimple
6409 && initializer_constant_valid_p (delta
, TREE_TYPE (delta
))
6410 && initializer_constant_valid_p (idx
, TREE_TYPE (idx
));
6412 u
= build (CONSTRUCTOR
, subtype
, NULL_TREE
, u
);
6413 u
= expr_tree_cons (delta_field
, delta
,
6414 expr_tree_cons (idx_field
, idx
,
6415 expr_tree_cons (pfn_or_delta2_field
, u
, NULL_TREE
)));
6416 u
= build (CONSTRUCTOR
, type
, NULL_TREE
, u
);
6417 TREE_CONSTANT (u
) = allconstant
;
6418 TREE_STATIC (u
) = allconstant
&& allsimple
;
6423 /* Build a constructor for a pointer to member function. It can be
6424 used to initialize global variables, local variable, or used
6425 as a value in expressions. TYPE is the POINTER to METHOD_TYPE we
6428 If FORCE is non-zero, then force this conversion, even if
6429 we would rather not do it. Usually set when using an explicit
6432 Return error_mark_node, if something goes wrong. */
6435 build_ptrmemfunc (type
, pfn
, force
)
6439 tree idx
= integer_zero_node
;
6440 tree delta
= integer_zero_node
;
6441 tree delta2
= integer_zero_node
;
6443 tree npfn
= NULL_TREE
;
6445 /* Handle multiple conversions of pointer to member functions. */
6446 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (pfn
)))
6448 tree ndelta
, ndelta2
;
6452 /* Is is already the right type? */
6453 if (type
== TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn
)))
6456 pfn_type
= TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn
));
6458 && comp_target_types (type
, pfn_type
, 0) != 1)
6459 cp_error ("conversion to `%T' from `%T'", type
, pfn_type
);
6461 ndelta
= cp_convert (ptrdiff_type_node
, build_component_ref (pfn
, delta_identifier
, NULL_TREE
, 0));
6462 ndelta2
= cp_convert (ptrdiff_type_node
, DELTA2_FROM_PTRMEMFUNC (pfn
));
6463 idx
= build_component_ref (pfn
, index_identifier
, NULL_TREE
, 0);
6465 n
= get_delta_difference (TYPE_METHOD_BASETYPE (TREE_TYPE (pfn_type
)),
6466 TYPE_METHOD_BASETYPE (TREE_TYPE (type
)),
6469 delta
= build_binary_op (PLUS_EXPR
, ndelta
, n
, 1);
6470 delta2
= build_binary_op (PLUS_EXPR
, ndelta2
, n
, 1);
6471 e1
= fold (build (GT_EXPR
, boolean_type_node
, idx
, integer_zero_node
));
6473 e2
= build_ptrmemfunc1 (TYPE_GET_PTRMEMFUNC_TYPE (type
), delta
, idx
,
6476 pfn
= PFN_FROM_PTRMEMFUNC (pfn
);
6477 npfn
= build1 (NOP_EXPR
, type
, pfn
);
6478 TREE_CONSTANT (npfn
) = TREE_CONSTANT (pfn
);
6480 e3
= build_ptrmemfunc1 (TYPE_GET_PTRMEMFUNC_TYPE (type
), delta
, idx
, npfn
,
6482 return build_conditional_expr (e1
, e2
, e3
);
6485 /* Handle null pointer to member function conversions. */
6486 if (integer_zerop (pfn
))
6488 pfn
= build_c_cast (type
, integer_zero_node
);
6489 return build_ptrmemfunc1 (TYPE_GET_PTRMEMFUNC_TYPE (type
),
6490 integer_zero_node
, integer_zero_node
,
6494 if (TREE_CODE (pfn
) == TREE_LIST
6495 || (TREE_CODE (pfn
) == ADDR_EXPR
6496 && TREE_CODE (TREE_OPERAND (pfn
, 0)) == TREE_LIST
))
6497 return instantiate_type (type
, pfn
, 1);
6500 && comp_target_types (type
, TREE_TYPE (pfn
), 0) != 1)
6501 cp_error ("conversion to `%T' from `%T'", type
, TREE_TYPE (pfn
));
6503 /* Allow pointer to member conversions here. */
6504 delta
= get_delta_difference (TYPE_METHOD_BASETYPE (TREE_TYPE (TREE_TYPE (pfn
))),
6505 TYPE_METHOD_BASETYPE (TREE_TYPE (type
)),
6507 delta2
= build_binary_op (PLUS_EXPR
, delta2
, delta
, 1);
6509 if (TREE_CODE (TREE_OPERAND (pfn
, 0)) != FUNCTION_DECL
)
6510 warning ("assuming pointer to member function is non-virtual");
6512 if (TREE_CODE (TREE_OPERAND (pfn
, 0)) == FUNCTION_DECL
6513 && DECL_VINDEX (TREE_OPERAND (pfn
, 0)))
6515 /* Find the offset to the vfield pointer in the object. */
6516 vfield_offset
= get_binfo (DECL_CONTEXT (TREE_OPERAND (pfn
, 0)),
6517 DECL_CLASS_CONTEXT (TREE_OPERAND (pfn
, 0)),
6519 vfield_offset
= get_vfield_offset (vfield_offset
);
6520 delta2
= size_binop (PLUS_EXPR
, vfield_offset
, delta2
);
6522 /* Map everything down one to make room for the null pointer to member. */
6523 idx
= size_binop (PLUS_EXPR
,
6524 DECL_VINDEX (TREE_OPERAND (pfn
, 0)),
6529 idx
= size_binop (MINUS_EXPR
, integer_zero_node
, integer_one_node
);
6531 if (type
== TREE_TYPE (pfn
))
6537 npfn
= build1 (NOP_EXPR
, type
, pfn
);
6538 TREE_CONSTANT (npfn
) = TREE_CONSTANT (pfn
);
6542 return build_ptrmemfunc1 (TYPE_GET_PTRMEMFUNC_TYPE (type
), delta
, idx
, npfn
, delta2
);
6545 /* Convert value RHS to type TYPE as preparation for an assignment
6546 to an lvalue of type TYPE.
6547 The real work of conversion is done by `convert'.
6548 The purpose of this function is to generate error messages
6549 for assignments that are not allowed in C.
6550 ERRTYPE is a string to use in error messages:
6551 "assignment", "return", etc.
6553 C++: attempts to allow `convert' to find conversions involving
6554 implicit type conversion between aggregate and scalar types
6555 as per 8.5.6 of C++ manual. Does not randomly dereference
6556 pointers to aggregates! */
6559 convert_for_assignment (type
, rhs
, errtype
, fndecl
, parmnum
)
6565 register enum tree_code codel
= TREE_CODE (type
);
6566 register tree rhstype
;
6567 register enum tree_code coder
= TREE_CODE (TREE_TYPE (rhs
));
6569 if (coder
== UNKNOWN_TYPE
)
6570 rhs
= instantiate_type (type
, rhs
, 1);
6572 if (coder
== ERROR_MARK
)
6573 return error_mark_node
;
6575 if (codel
== OFFSET_TYPE
)
6577 type
= TREE_TYPE (type
);
6578 codel
= TREE_CODE (type
);
6581 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
6582 if (TREE_CODE (rhs
) == NON_LVALUE_EXPR
)
6583 rhs
= TREE_OPERAND (rhs
, 0);
6585 if (rhs
== error_mark_node
)
6586 return error_mark_node
;
6588 if (TREE_CODE (rhs
) == TREE_LIST
&& TREE_VALUE (rhs
) == error_mark_node
)
6589 return error_mark_node
;
6591 if (TREE_CODE (TREE_TYPE (rhs
)) == OFFSET_TYPE
)
6593 rhs
= resolve_offset_ref (rhs
);
6594 if (rhs
== error_mark_node
)
6595 return error_mark_node
;
6596 rhstype
= TREE_TYPE (rhs
);
6597 coder
= TREE_CODE (rhstype
);
6600 if (TREE_CODE (TREE_TYPE (rhs
)) == ARRAY_TYPE
6601 || TREE_CODE (TREE_TYPE (rhs
)) == FUNCTION_TYPE
6602 || TREE_CODE (TREE_TYPE (rhs
)) == METHOD_TYPE
)
6603 rhs
= default_conversion (rhs
);
6604 else if (TREE_CODE (TREE_TYPE (rhs
)) == REFERENCE_TYPE
)
6605 rhs
= convert_from_reference (rhs
);
6607 rhstype
= TREE_TYPE (rhs
);
6608 coder
= TREE_CODE (rhstype
);
6610 /* This should no longer change types on us. */
6611 if (TREE_CODE (rhs
) == CONST_DECL
)
6612 rhs
= DECL_INITIAL (rhs
);
6613 else if (TREE_READONLY_DECL_P (rhs
))
6614 rhs
= decl_constant_value (rhs
);
6616 if (type
== rhstype
)
6618 overflow_warning (rhs
);
6622 if (coder
== VOID_TYPE
)
6624 error ("void value not ignored as it ought to be");
6625 return error_mark_node
;
6627 /* Arithmetic types all interconvert. */
6628 if ((codel
== INTEGER_TYPE
|| codel
== REAL_TYPE
|| codel
== BOOLEAN_TYPE
6629 || codel
== COMPLEX_TYPE
)
6630 && (coder
== INTEGER_TYPE
|| coder
== REAL_TYPE
|| coder
== BOOLEAN_TYPE
6631 || coder
== COMPLEX_TYPE
))
6633 /* But we should warn if assigning REAL_TYPE to INTEGER_TYPE. */
6634 if (coder
== REAL_TYPE
&& codel
== INTEGER_TYPE
)
6637 cp_warning ("`%T' used for argument %P of `%D'",
6638 rhstype
, parmnum
, fndecl
);
6640 cp_warning ("%s to `%T' from `%T'", errtype
, type
, rhstype
);
6642 /* And we should warn if assigning a negative value to
6643 an unsigned variable. */
6644 else if (TREE_UNSIGNED (type
) && codel
!= BOOLEAN_TYPE
)
6646 if (TREE_CODE (rhs
) == INTEGER_CST
6647 && TREE_NEGATED_INT (rhs
))
6650 cp_warning ("negative value `%E' passed as argument %P of `%D'",
6651 rhs
, parmnum
, fndecl
);
6653 cp_warning ("%s of negative value `%E' to `%T'",
6654 errtype
, rhs
, type
);
6656 overflow_warning (rhs
);
6657 if (TREE_CONSTANT (rhs
))
6661 return convert_and_check (type
, rhs
);
6663 /* Conversions involving enums. */
6664 else if ((codel
== ENUMERAL_TYPE
6665 && (INTEGRAL_CODE_P (coder
) || coder
== REAL_TYPE
))
6666 || (coder
== ENUMERAL_TYPE
6667 && (INTEGRAL_CODE_P (codel
) || codel
== REAL_TYPE
)))
6669 return ocp_convert (type
, rhs
, CONV_IMPLICIT
, LOOKUP_NORMAL
);
6671 /* Conversions among pointers */
6672 else if (codel
== POINTER_TYPE
6673 && (coder
== POINTER_TYPE
6674 || (coder
== RECORD_TYPE
6675 && (IS_SIGNATURE_POINTER (rhstype
)
6676 || IS_SIGNATURE_REFERENCE (rhstype
)))))
6678 register tree ttl
= TREE_TYPE (type
);
6682 if (coder
== RECORD_TYPE
)
6684 rhs
= build_optr_ref (rhs
);
6685 rhstype
= TREE_TYPE (rhs
);
6687 ttr
= TREE_TYPE (rhstype
);
6689 /* If both pointers are of aggregate type, then we
6690 can give better error messages, and save some work
6692 if (TREE_CODE (ttl
) == RECORD_TYPE
&& TREE_CODE (ttr
) == RECORD_TYPE
)
6696 if (TYPE_MAIN_VARIANT (ttl
) == TYPE_MAIN_VARIANT (ttr
)
6697 || type
== class_star_type_node
6698 || rhstype
== class_star_type_node
)
6699 binfo
= TYPE_BINFO (ttl
);
6701 binfo
= get_binfo (ttl
, ttr
, 1);
6703 if (binfo
== error_mark_node
)
6704 return error_mark_node
;
6706 return error_not_base_type (ttl
, ttr
);
6708 if (! TYPE_READONLY (ttl
) && TYPE_READONLY (ttr
))
6711 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6712 rhstype
, parmnum
, fndecl
);
6714 cp_pedwarn ("%s to `%T' from `%T' discards const",
6715 errtype
, type
, rhstype
);
6717 if (! TYPE_VOLATILE (ttl
) && TYPE_VOLATILE (ttr
))
6720 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6721 rhstype
, parmnum
, fndecl
);
6723 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6724 errtype
, type
, rhstype
);
6728 /* Any non-function converts to a [const][volatile] void *
6729 and vice versa; otherwise, targets must be the same.
6730 Meanwhile, the lhs target must have all the qualifiers of the rhs. */
6731 else if (TYPE_MAIN_VARIANT (ttl
) == void_type_node
6732 || TYPE_MAIN_VARIANT (ttr
) == void_type_node
6733 || (ctt
= comp_target_types (type
, rhstype
, 1))
6734 || (unsigned_type (TYPE_MAIN_VARIANT (ttl
))
6735 == unsigned_type (TYPE_MAIN_VARIANT (ttr
))))
6737 /* ARM $4.8, commentary on p39. */
6738 if (TYPE_MAIN_VARIANT (ttl
) == void_type_node
6739 && TREE_CODE (ttr
) == OFFSET_TYPE
)
6741 cp_error ("no standard conversion from `%T' to `void *'", ttr
);
6742 return error_mark_node
;
6745 if (ctt
< 0 && TYPE_MAIN_VARIANT (ttl
) != TYPE_MAIN_VARIANT (ttr
))
6746 cp_pedwarn ("converting `%T' to `%T' is a contravariance violation",
6749 if (TYPE_MAIN_VARIANT (ttl
) != void_type_node
6750 && TYPE_MAIN_VARIANT (ttr
) == void_type_node
6751 && ! null_ptr_cst_p (rhs
))
6753 if (coder
== RECORD_TYPE
)
6754 cp_pedwarn ("implicit conversion of signature pointer to type `%T'",
6757 pedwarn ("ANSI C++ forbids implicit conversion from `void *' in %s",
6760 /* Const and volatile mean something different for function types,
6761 so the usual warnings are not appropriate. */
6762 else if ((TREE_CODE (ttr
) != FUNCTION_TYPE
&& TREE_CODE (ttr
) != METHOD_TYPE
)
6763 || (TREE_CODE (ttl
) != FUNCTION_TYPE
&& TREE_CODE (ttl
) != METHOD_TYPE
))
6765 if (TREE_CODE (ttl
) == OFFSET_TYPE
6766 && binfo_member (TYPE_OFFSET_BASETYPE (ttr
),
6767 CLASSTYPE_VBASECLASSES (TYPE_OFFSET_BASETYPE (ttl
))))
6769 sorry ("%s between pointer to members converting across virtual baseclasses", errtype
);
6770 return error_mark_node
;
6772 else if (! TYPE_READONLY (ttl
) && TYPE_READONLY (ttr
))
6775 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6776 rhstype
, parmnum
, fndecl
);
6778 cp_pedwarn ("%s to `%T' from `%T' discards const",
6779 errtype
, type
, rhstype
);
6781 else if (! TYPE_VOLATILE (ttl
) && TYPE_VOLATILE (ttr
))
6784 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6785 rhstype
, parmnum
, fndecl
);
6787 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6788 errtype
, type
, rhstype
);
6790 else if (TREE_CODE (ttl
) == TREE_CODE (ttr
)
6791 && ! comp_target_types (type
, rhstype
, 1))
6794 cp_pedwarn ("passing `%T' as argument %P of `%D' changes signedness",
6795 rhstype
, parmnum
, fndecl
);
6797 cp_pedwarn ("%s to `%T' from `%T' changes signedness",
6798 errtype
, type
, rhstype
);
6804 int add_quals
= 0, const_parity
= 0, volatile_parity
= 0;
6806 int unsigned_parity
;
6809 /* This code is basically a duplicate of comp_ptr_ttypes_real. */
6810 for (; ; ttl
= TREE_TYPE (ttl
), ttr
= TREE_TYPE (ttr
))
6813 const_parity
|= (TYPE_READONLY (ttl
) < TYPE_READONLY (ttr
));
6814 volatile_parity
|= (TYPE_VOLATILE (ttl
) < TYPE_VOLATILE (ttr
));
6817 && (TYPE_READONLY (ttl
) > TYPE_READONLY (ttr
)
6818 || TYPE_VOLATILE (ttl
) > TYPE_VOLATILE (ttr
)))
6820 left_const
&= TYPE_READONLY (ttl
);
6822 if (TREE_CODE (ttl
) != POINTER_TYPE
6823 || TREE_CODE (ttr
) != POINTER_TYPE
)
6826 unsigned_parity
= TREE_UNSIGNED (ttl
) - TREE_UNSIGNED (ttr
);
6827 if (unsigned_parity
)
6829 if (TREE_UNSIGNED (ttl
))
6830 ttr
= unsigned_type (ttr
);
6832 ttl
= unsigned_type (ttl
);
6835 if (comp_target_types (ttl
, ttr
, nptrs
) > 0)
6840 cp_pedwarn ("passing `%T' as argument %P of `%D' adds cv-quals without intervening `const'",
6841 rhstype
, parmnum
, fndecl
);
6843 cp_pedwarn ("%s to `%T' from `%T' adds cv-quals without intervening `const'",
6844 errtype
, type
, rhstype
);
6849 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6850 rhstype
, parmnum
, fndecl
);
6852 cp_pedwarn ("%s to `%T' from `%T' discards const",
6853 errtype
, type
, rhstype
);
6855 if (volatile_parity
)
6858 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6859 rhstype
, parmnum
, fndecl
);
6861 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6862 errtype
, type
, rhstype
);
6864 if (unsigned_parity
> 0)
6867 cp_pedwarn ("passing `%T' as argument %P of `%D' changes signed to unsigned",
6868 rhstype
, parmnum
, fndecl
);
6870 cp_pedwarn ("%s to `%T' from `%T' changes signed to unsigned",
6871 errtype
, type
, rhstype
);
6873 else if (unsigned_parity
< 0)
6876 cp_pedwarn ("passing `%T' as argument %P of `%D' changes unsigned to signed",
6877 rhstype
, parmnum
, fndecl
);
6879 cp_pedwarn ("%s to `%T' from `%T' changes unsigned to signed",
6880 errtype
, type
, rhstype
);
6883 /* C++ is not so friendly about converting function and
6884 member function pointers as C. Emit warnings here. */
6885 if (TREE_CODE (ttl
) == FUNCTION_TYPE
6886 || TREE_CODE (ttl
) == METHOD_TYPE
)
6887 if (! comptypes (ttl
, ttr
, 0))
6889 warning ("conflicting function types in %s:", errtype
);
6890 cp_warning ("\t`%T' != `%T'", type
, rhstype
);
6896 cp_error ("passing `%T' as argument %P of `%D'",
6897 rhstype
, parmnum
, fndecl
);
6899 cp_error ("%s to `%T' from `%T'", errtype
, type
, rhstype
);
6900 return error_mark_node
;
6903 return cp_convert (type
, rhs
);
6905 else if (codel
== POINTER_TYPE
&& coder
== INTEGER_TYPE
)
6907 /* An explicit constant 0 can convert to a pointer,
6908 but not a 0 that results from casting or folding. */
6909 if (! (TREE_CODE (rhs
) == INTEGER_CST
&& integer_zerop (rhs
)))
6912 cp_pedwarn ("passing `%T' to argument %P of `%D' lacks a cast",
6913 rhstype
, parmnum
, fndecl
);
6915 cp_pedwarn ("%s to `%T' from `%T' lacks a cast",
6916 errtype
, type
, rhstype
);
6918 return cp_convert (type
, rhs
);
6920 else if (codel
== INTEGER_TYPE
6921 && (coder
== POINTER_TYPE
6922 || (coder
== RECORD_TYPE
6923 && (IS_SIGNATURE_POINTER (rhstype
)
6924 || TYPE_PTRMEMFUNC_FLAG (rhstype
)
6925 || IS_SIGNATURE_REFERENCE (rhstype
)))))
6928 cp_pedwarn ("passing `%T' to argument %P of `%D' lacks a cast",
6929 rhstype
, parmnum
, fndecl
);
6931 cp_pedwarn ("%s to `%T' from `%T' lacks a cast",
6932 errtype
, type
, rhstype
);
6933 return cp_convert (type
, rhs
);
6935 else if (codel
== BOOLEAN_TYPE
6936 && (coder
== POINTER_TYPE
6937 || (coder
== RECORD_TYPE
6938 && (IS_SIGNATURE_POINTER (rhstype
)
6939 || TYPE_PTRMEMFUNC_FLAG (rhstype
)
6940 || IS_SIGNATURE_REFERENCE (rhstype
)))))
6941 return cp_convert (type
, rhs
);
6944 else if (((coder
== POINTER_TYPE
6945 && TREE_CODE (TREE_TYPE (rhstype
)) == METHOD_TYPE
)
6946 || integer_zerop (rhs
)
6947 || TYPE_PTRMEMFUNC_P (rhstype
))
6948 && TYPE_PTRMEMFUNC_P (type
))
6950 tree ttl
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
6951 tree ttr
= (TYPE_PTRMEMFUNC_P (rhstype
)
6952 ? TYPE_PTRMEMFUNC_FN_TYPE (rhstype
)
6954 int ctt
= (TREE_CODE (rhstype
) == INTEGER_TYPE
? 1
6955 : comp_target_types (ttl
, ttr
, 1));
6958 cp_pedwarn ("converting `%T' to `%T' is a contravariance violation",
6961 cp_error ("%s to `%T' from `%T'", errtype
, ttl
, ttr
);
6963 /* compatible pointer to member functions. */
6964 return build_ptrmemfunc (ttl
, rhs
, 0);
6966 else if (codel
== ERROR_MARK
|| coder
== ERROR_MARK
)
6967 return error_mark_node
;
6969 /* This should no longer happen. References are initialized via
6970 `convert_for_initialization'. They should otherwise be
6971 bashed before coming here. */
6972 else if (codel
== REFERENCE_TYPE
)
6973 my_friendly_abort (317);
6974 else if (TYPE_MAIN_VARIANT (type
) == TYPE_MAIN_VARIANT (TREE_TYPE (rhs
)))
6976 tree nrhs
= build1 (NOP_EXPR
, type
, rhs
);
6977 TREE_CONSTANT (nrhs
) = TREE_CONSTANT (rhs
);
6980 else if (TYPE_HAS_CONSTRUCTOR (type
) || IS_AGGR_TYPE (TREE_TYPE (rhs
)))
6981 return cp_convert (type
, rhs
);
6982 /* Handle anachronistic conversions from (::*)() to cv void* or (*)(). */
6983 else if (TREE_CODE (type
) == POINTER_TYPE
6984 && (TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
6985 || TYPE_MAIN_VARIANT (TREE_TYPE (type
)) == void_type_node
)
6987 && TYPE_PTRMEMFUNC_P (TREE_TYPE (rhs
)))
6988 return cp_convert (type
, rhs
);
6990 cp_error ("%s to `%T' from `%T'", errtype
, type
, rhstype
);
6991 return error_mark_node
;
6994 /* Convert RHS to be of type TYPE. If EXP is non-zero,
6995 it is the target of the initialization.
6996 ERRTYPE is a string to use in error messages.
6998 Two major differences between the behavior of
6999 `convert_for_assignment' and `convert_for_initialization'
7000 are that references are bashed in the former, while
7001 copied in the latter, and aggregates are assigned in
7002 the former (operator=) while initialized in the
7005 If using constructor make sure no conversion operator exists, if one does
7006 exist, an ambiguity exists.
7008 If flags doesn't include LOOKUP_COMPLAIN, don't complain about anything. */
7011 convert_for_initialization (exp
, type
, rhs
, flags
, errtype
, fndecl
, parmnum
)
7012 tree exp
, type
, rhs
;
7018 register enum tree_code codel
= TREE_CODE (type
);
7019 register tree rhstype
;
7020 register enum tree_code coder
;
7022 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
7023 Strip such NOP_EXPRs, since RHS is used in non-lvalue context. */
7024 if (TREE_CODE (rhs
) == NOP_EXPR
7025 && TREE_TYPE (rhs
) == TREE_TYPE (TREE_OPERAND (rhs
, 0))
7026 && codel
!= REFERENCE_TYPE
)
7027 rhs
= TREE_OPERAND (rhs
, 0);
7029 if (rhs
== error_mark_node
7030 || (TREE_CODE (rhs
) == TREE_LIST
&& TREE_VALUE (rhs
) == error_mark_node
))
7031 return error_mark_node
;
7033 if (TREE_CODE (TREE_TYPE (rhs
)) == OFFSET_TYPE
)
7035 rhs
= resolve_offset_ref (rhs
);
7036 if (rhs
== error_mark_node
)
7037 return error_mark_node
;
7040 if (TREE_CODE (TREE_TYPE (rhs
)) == REFERENCE_TYPE
)
7041 rhs
= convert_from_reference (rhs
);
7043 if ((TREE_CODE (TREE_TYPE (rhs
)) == ARRAY_TYPE
7044 && TREE_CODE (type
) != ARRAY_TYPE
7045 && (TREE_CODE (type
) != REFERENCE_TYPE
7046 || TREE_CODE (TREE_TYPE (type
)) != ARRAY_TYPE
))
7047 || TREE_CODE (TREE_TYPE (rhs
)) == FUNCTION_TYPE
7048 || TREE_CODE (TREE_TYPE (rhs
)) == METHOD_TYPE
)
7049 rhs
= default_conversion (rhs
);
7051 rhstype
= TREE_TYPE (rhs
);
7052 coder
= TREE_CODE (rhstype
);
7054 if (coder
== UNKNOWN_TYPE
)
7056 rhs
= instantiate_type (type
, rhs
, 1);
7057 rhstype
= TREE_TYPE (rhs
);
7058 coder
= TREE_CODE (rhstype
);
7061 if (coder
== ERROR_MARK
)
7062 return error_mark_node
;
7064 /* We accept references to incomplete types, so we can
7065 return here before checking if RHS is of complete type. */
7067 if (codel
== REFERENCE_TYPE
)
7069 /* This should eventually happen in convert_arguments. */
7070 extern int warningcount
, errorcount
;
7071 int savew
= 0, savee
= 0;
7074 savew
= warningcount
, savee
= errorcount
;
7075 rhs
= convert_to_reference (type
, rhs
, CONV_IMPLICIT
, flags
,
7076 exp
? exp
: error_mark_node
);
7079 if (warningcount
> savew
)
7080 cp_warning_at ("in passing argument %P of `%+D'", parmnum
, fndecl
);
7081 else if (errorcount
> savee
)
7082 cp_error_at ("in passing argument %P of `%+D'", parmnum
, fndecl
);
7087 rhs
= require_complete_type (rhs
);
7088 if (rhs
== error_mark_node
)
7089 return error_mark_node
;
7091 if (exp
!= 0) exp
= require_complete_type (exp
);
7092 if (exp
== error_mark_node
)
7093 return error_mark_node
;
7095 if (TREE_CODE (rhstype
) == REFERENCE_TYPE
)
7096 rhstype
= TREE_TYPE (rhstype
);
7098 type
= complete_type (type
);
7100 if (TYPE_LANG_SPECIFIC (type
)
7101 && (IS_SIGNATURE_POINTER (type
) || IS_SIGNATURE_REFERENCE (type
)))
7102 return build_signature_pointer_constructor (type
, rhs
);
7104 if (IS_AGGR_TYPE (type
))
7105 return ocp_convert (type
, rhs
, CONV_IMPLICIT
|CONV_FORCE_TEMP
, flags
);
7107 if (type
== TREE_TYPE (rhs
))
7109 if (TREE_READONLY_DECL_P (rhs
))
7110 rhs
= decl_constant_value (rhs
);
7114 return convert_for_assignment (type
, rhs
, errtype
, fndecl
, parmnum
);
7117 /* Expand an ASM statement with operands, handling output operands
7118 that are not variables or INDIRECT_REFS by transforming such
7119 cases into cases that expand_asm_operands can handle.
7121 Arguments are same as for expand_asm_operands.
7123 We don't do default conversions on all inputs, because it can screw
7124 up operands that are expected to be in memory. */
7127 c_expand_asm_operands (string
, outputs
, inputs
, clobbers
, vol
, filename
, line
)
7128 tree string
, outputs
, inputs
, clobbers
;
7133 int noutputs
= list_length (outputs
);
7135 /* o[I] is the place that output number I should be written. */
7136 register tree
*o
= (tree
*) alloca (noutputs
* sizeof (tree
));
7139 /* Record the contents of OUTPUTS before it is modified. */
7140 for (i
= 0, tail
= outputs
; tail
; tail
= TREE_CHAIN (tail
), i
++)
7141 o
[i
] = TREE_VALUE (tail
);
7143 /* Generate the ASM_OPERANDS insn;
7144 store into the TREE_VALUEs of OUTPUTS some trees for
7145 where the values were actually stored. */
7146 expand_asm_operands (string
, outputs
, inputs
, clobbers
, vol
, filename
, line
);
7148 /* Copy all the intermediate outputs into the specified outputs. */
7149 for (i
= 0, tail
= outputs
; tail
; tail
= TREE_CHAIN (tail
), i
++)
7151 if (o
[i
] != TREE_VALUE (tail
))
7153 expand_expr (build_modify_expr (o
[i
], NOP_EXPR
, TREE_VALUE (tail
)),
7154 const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
7157 /* Detect modification of read-only values.
7158 (Otherwise done by build_modify_expr.) */
7161 tree type
= TREE_TYPE (o
[i
]);
7162 if (TYPE_READONLY (type
)
7163 || ((TREE_CODE (type
) == RECORD_TYPE
7164 || TREE_CODE (type
) == UNION_TYPE
)
7165 && C_TYPE_FIELDS_READONLY (type
)))
7166 readonly_error (o
[i
], "modification by `asm'", 1);
7170 /* Those MODIFY_EXPRs could do autoincrements. */
7174 /* Expand a C `return' statement.
7175 RETVAL is the expression for what to return,
7176 or a null pointer for `return;' with no value.
7178 C++: upon seeing a `return', we must call destructors on all
7179 variables in scope which had constructors called on them.
7180 This means that if in a destructor, the base class destructors
7181 must be called before returning.
7183 The RETURN statement in C++ has initialization semantics. */
7186 c_expand_return (retval
)
7189 extern struct nesting
*cond_stack
, *loop_stack
, *case_stack
;
7190 extern tree dtor_label
, ctor_label
;
7191 tree result
= DECL_RESULT (current_function_decl
);
7192 tree valtype
= TREE_TYPE (result
);
7194 if (TREE_THIS_VOLATILE (current_function_decl
))
7195 warning ("function declared `noreturn' has a `return' statement");
7197 if (retval
== error_mark_node
)
7199 current_function_returns_null
= 1;
7203 if (processing_template_decl
)
7205 add_tree (build_min_nt (RETURN_STMT
, retval
));
7209 if (retval
== NULL_TREE
)
7211 /* A non-named return value does not count. */
7213 /* Can't just return from a destructor. */
7216 expand_goto (dtor_label
);
7220 if (DECL_CONSTRUCTOR_P (current_function_decl
))
7221 retval
= current_class_ptr
;
7222 else if (DECL_NAME (result
) != NULL_TREE
7223 && TREE_CODE (valtype
) != VOID_TYPE
)
7227 current_function_returns_null
= 1;
7229 if (valtype
!= NULL_TREE
&& TREE_CODE (valtype
) != VOID_TYPE
)
7231 if (DECL_NAME (DECL_RESULT (current_function_decl
)) == NULL_TREE
)
7233 pedwarn ("`return' with no value, in function returning non-void");
7234 /* Clear this, so finish_function won't say that we
7235 reach the end of a non-void function (which we don't,
7236 we gave a return!). */
7237 current_function_returns_null
= 0;
7241 expand_null_return ();
7245 else if (DECL_CONSTRUCTOR_P (current_function_decl
)
7246 && retval
!= current_class_ptr
)
7248 if (flag_this_is_variable
)
7249 error ("return from a constructor: use `this = ...' instead");
7251 error ("return from a constructor");
7252 retval
= current_class_ptr
;
7255 /* Effective C++ rule 15. See also start_function. */
7257 && DECL_NAME (current_function_decl
) == ansi_opname
[(int) MODIFY_EXPR
]
7258 && retval
!= current_class_ref
)
7259 cp_warning ("`operator=' should return a reference to `*this'");
7261 if (valtype
== NULL_TREE
|| TREE_CODE (valtype
) == VOID_TYPE
)
7263 current_function_returns_null
= 1;
7264 if ((pedantic
&& ! DECL_ARTIFICIAL (current_function_decl
))
7265 || TREE_CODE (TREE_TYPE (retval
)) != VOID_TYPE
)
7266 pedwarn ("`return' with a value, in function returning void");
7267 expand_return (retval
);
7271 /* Now deal with possible C++ hair:
7272 (1) Compute the return value.
7273 (2) If there are aggregate values with destructors which
7274 must be cleaned up, clean them (taking care
7275 not to clobber the return value).
7276 (3) If an X(X&) constructor is defined, the return
7277 value must be returned via that. */
7279 if (retval
== result
7280 || DECL_CONSTRUCTOR_P (current_function_decl
))
7281 /* It's already done for us. */;
7282 else if (TREE_TYPE (retval
) == void_type_node
)
7284 pedwarn ("return of void value in function returning non-void");
7285 expand_expr_stmt (retval
);
7290 retval
= convert_for_initialization
7291 (NULL_TREE
, valtype
, retval
, LOOKUP_NORMAL
|LOOKUP_ONLYCONVERTING
,
7292 "return", NULL_TREE
, 0);
7294 if (retval
== error_mark_node
)
7296 /* Avoid warning about control reaching end of function. */
7297 expand_null_return ();
7301 /* We can't initialize a register from a AGGR_INIT_EXPR. */
7302 else if (! current_function_returns_struct
7303 && TREE_CODE (retval
) == TARGET_EXPR
7304 && TREE_CODE (TREE_OPERAND (retval
, 1)) == AGGR_INIT_EXPR
)
7305 retval
= build (COMPOUND_EXPR
, TREE_TYPE (retval
), retval
,
7306 TREE_OPERAND (retval
, 0));
7308 /* Add some useful error checking for C++. */
7309 else if (TREE_CODE (valtype
) == REFERENCE_TYPE
)
7311 tree whats_returned
;
7313 /* Sort through common things to see what it is
7314 we are returning. */
7315 whats_returned
= retval
;
7316 if (TREE_CODE (whats_returned
) == COMPOUND_EXPR
)
7318 whats_returned
= TREE_OPERAND (whats_returned
, 1);
7319 if (TREE_CODE (whats_returned
) == ADDR_EXPR
)
7320 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7322 while (TREE_CODE (whats_returned
) == CONVERT_EXPR
7323 || TREE_CODE (whats_returned
) == NOP_EXPR
)
7324 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7325 if (TREE_CODE (whats_returned
) == ADDR_EXPR
)
7327 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7328 while (TREE_CODE (whats_returned
) == AGGR_INIT_EXPR
7329 || TREE_CODE (whats_returned
) == TARGET_EXPR
)
7331 /* Get the target. */
7332 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7333 warning ("returning reference to temporary");
7337 if (TREE_CODE (whats_returned
) == VAR_DECL
&& DECL_NAME (whats_returned
))
7339 if (TEMP_NAME_P (DECL_NAME (whats_returned
)))
7340 warning ("reference to non-lvalue returned");
7341 else if (TREE_CODE (TREE_TYPE (whats_returned
)) != REFERENCE_TYPE
7342 && ! TREE_STATIC (whats_returned
)
7343 && IDENTIFIER_LOCAL_VALUE (DECL_NAME (whats_returned
))
7344 && !TREE_PUBLIC (whats_returned
))
7345 cp_warning_at ("reference to local variable `%D' returned", whats_returned
);
7348 else if (TREE_CODE (retval
) == ADDR_EXPR
)
7350 tree whats_returned
= TREE_OPERAND (retval
, 0);
7352 if (TREE_CODE (whats_returned
) == VAR_DECL
7353 && DECL_NAME (whats_returned
)
7354 && IDENTIFIER_LOCAL_VALUE (DECL_NAME (whats_returned
))
7355 && !TREE_STATIC (whats_returned
)
7356 && !TREE_PUBLIC (whats_returned
))
7357 cp_warning_at ("address of local variable `%D' returned", whats_returned
);
7361 if (retval
!= NULL_TREE
7362 && TREE_CODE_CLASS (TREE_CODE (retval
)) == 'd'
7363 && cond_stack
== 0 && loop_stack
== 0 && case_stack
== 0)
7364 current_function_return_value
= retval
;
7366 if (ctor_label
&& TREE_CODE (ctor_label
) != ERROR_MARK
)
7368 /* Here RETVAL is CURRENT_CLASS_PTR, so there's nothing to do. */
7369 expand_goto (ctor_label
);
7372 if (retval
&& retval
!= result
)
7374 result
= build (INIT_EXPR
, TREE_TYPE (result
), result
, retval
);
7375 TREE_SIDE_EFFECTS (result
) = 1;
7378 expand_start_target_temps ();
7380 expand_return (result
);
7382 expand_end_target_temps ();
7384 current_function_returns_value
= 1;
7387 /* Start a C switch statement, testing expression EXP.
7388 Return EXP if it is valid, an error node otherwise. */
7391 c_expand_start_case (exp
)
7395 register enum tree_code code
;
7397 /* Convert from references, etc. */
7398 exp
= default_conversion (exp
);
7399 type
= TREE_TYPE (exp
);
7400 code
= TREE_CODE (type
);
7402 if (IS_AGGR_TYPE_CODE (code
))
7403 exp
= build_type_conversion (CONVERT_EXPR
, integer_type_node
, exp
, 1);
7405 if (exp
== NULL_TREE
)
7407 error ("switch quantity not an integer");
7408 exp
= error_mark_node
;
7410 type
= TREE_TYPE (exp
);
7411 code
= TREE_CODE (type
);
7413 if (code
!= INTEGER_TYPE
&& code
!= ENUMERAL_TYPE
&& code
!= ERROR_MARK
)
7415 error ("switch quantity not an integer");
7416 exp
= error_mark_node
;
7422 exp
= default_conversion (exp
);
7423 type
= TREE_TYPE (exp
);
7424 idx
= get_unwidened (exp
, 0);
7425 /* We can't strip a conversion from a signed type to an unsigned,
7426 because if we did, int_fits_type_p would do the wrong thing
7427 when checking case values for being in range,
7428 and it's too hard to do the right thing. */
7429 if (TREE_UNSIGNED (TREE_TYPE (exp
))
7430 == TREE_UNSIGNED (TREE_TYPE (idx
)))
7435 (1, fold (build1 (CLEANUP_POINT_EXPR
, TREE_TYPE (exp
), exp
)),
7436 type
, "switch statement");
7441 /* Returns non-zero if the pointer-type FROM can be converted to the
7442 pointer-type TO via a qualification conversion. If CONSTP is -1,
7443 then we return non-zero if the pointers are similar, and the
7444 cv-qualification signature of FROM is a proper subset of that of TO.
7446 If CONSTP is positive, then all outer pointers have been
7450 comp_ptr_ttypes_real (to
, from
, constp
)
7454 int to_more_cv_qualified
= 0;
7456 for (; ; to
= TREE_TYPE (to
), from
= TREE_TYPE (from
))
7458 if (TREE_CODE (to
) != TREE_CODE (from
))
7461 if (TREE_CODE (from
) == OFFSET_TYPE
7462 && comptypes (TYPE_OFFSET_BASETYPE (from
),
7463 TYPE_OFFSET_BASETYPE (to
), 1))
7466 /* Const and volatile mean something different for function types,
7467 so the usual checks are not appropriate. */
7468 if (TREE_CODE (to
) != FUNCTION_TYPE
&& TREE_CODE (to
) != METHOD_TYPE
)
7470 switch (comp_cv_qualification (from
, to
))
7473 /* FROM is more cv-qualified than TO. */
7477 /* TO is more cv-qualified than FROM. */
7481 ++to_more_cv_qualified
;
7489 constp
&= TYPE_READONLY (to
);
7492 if (TREE_CODE (to
) != POINTER_TYPE
)
7494 comptypes (TYPE_MAIN_VARIANT (to
), TYPE_MAIN_VARIANT (from
), 1)
7495 && (constp
>= 0 || to_more_cv_qualified
);
7499 /* When comparing, say, char ** to char const **, this function takes the
7500 'char *' and 'char const *'. Do not pass non-pointer types to this
7504 comp_ptr_ttypes (to
, from
)
7507 return comp_ptr_ttypes_real (to
, from
, 1);
7510 /* Returns 1 if to and from are (possibly multi-level) pointers to the same
7511 type or inheritance-related types, regardless of cv-quals. */
7514 ptr_reasonably_similar (to
, from
)
7517 for (; ; to
= TREE_TYPE (to
), from
= TREE_TYPE (from
))
7519 if (TREE_CODE (to
) != TREE_CODE (from
))
7522 if (TREE_CODE (from
) == OFFSET_TYPE
7523 && comptypes (TYPE_OFFSET_BASETYPE (to
),
7524 TYPE_OFFSET_BASETYPE (from
), -1))
7527 if (TREE_CODE (to
) != POINTER_TYPE
)
7529 (TYPE_MAIN_VARIANT (to
), TYPE_MAIN_VARIANT (from
), -1);
7533 /* Like comp_ptr_ttypes, for const_cast. */
7536 comp_ptr_ttypes_const (to
, from
)
7539 for (; ; to
= TREE_TYPE (to
), from
= TREE_TYPE (from
))
7541 if (TREE_CODE (to
) != TREE_CODE (from
))
7544 if (TREE_CODE (from
) == OFFSET_TYPE
7545 && comptypes (TYPE_OFFSET_BASETYPE (from
),
7546 TYPE_OFFSET_BASETYPE (to
), 1))
7549 if (TREE_CODE (to
) != POINTER_TYPE
)
7550 return comptypes (TYPE_MAIN_VARIANT (to
), TYPE_MAIN_VARIANT (from
), 1);
7554 /* Like comp_ptr_ttypes, for reinterpret_cast. */
7557 comp_ptr_ttypes_reinterpret (to
, from
)
7562 for (; ; to
= TREE_TYPE (to
), from
= TREE_TYPE (from
))
7564 if (TREE_CODE (from
) == OFFSET_TYPE
)
7565 from
= TREE_TYPE (from
);
7566 if (TREE_CODE (to
) == OFFSET_TYPE
)
7567 to
= TREE_TYPE (to
);
7569 if (TREE_CODE (to
) != TREE_CODE (from
))
7572 /* Const and volatile mean something different for function types,
7573 so the usual checks are not appropriate. */
7574 if (TREE_CODE (to
) != FUNCTION_TYPE
&& TREE_CODE (to
) != METHOD_TYPE
)
7576 if (TYPE_READONLY (from
) > TYPE_READONLY (to
)
7577 || TYPE_VOLATILE (from
) > TYPE_VOLATILE (to
))
7581 && (TYPE_READONLY (to
) > TYPE_READONLY (from
)
7582 || TYPE_VOLATILE (to
) > TYPE_READONLY (from
)))
7584 constp
&= TYPE_READONLY (to
);
7587 if (TREE_CODE (to
) != POINTER_TYPE
)