1 /* Build expressions with type checking for C++ compiler.
2 Copyright (C) 1987, 88, 89, 92, 93, 94, 1995 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). */
33 extern void warning ();
43 int mark_addressable ();
44 static tree convert_for_assignment ();
45 /* static */ tree convert_for_initialization ();
46 extern tree shorten_compare ();
47 extern void binary_op_error ();
48 static tree pointer_int_sum ();
49 static tree pointer_diff ();
50 static tree convert_sequence ();
51 /* static */ tree unary_complex_lvalue ();
52 static tree get_delta_difference PROTO((tree, tree, int));
54 extern rtx original_result_rtx;
55 extern int warn_synth;
57 /* Return the target type of TYPE, which meas return T for:
58 T*, T&, T[], T (...), and otherwise, just T. */
64 if (TREE_CODE (type) == REFERENCE_TYPE)
65 type = TREE_TYPE (type);
66 while (TREE_CODE (type) == POINTER_TYPE
67 || TREE_CODE (type) == ARRAY_TYPE
68 || TREE_CODE (type) == FUNCTION_TYPE
69 || TREE_CODE (type) == METHOD_TYPE
70 || TREE_CODE (type) == OFFSET_TYPE)
71 type = TREE_TYPE (type);
75 /* Do `exp = require_complete_type (exp);' to make sure exp
76 does not have an incomplete type. (That includes void types.) */
79 require_complete_type (value)
84 if (current_template_parms)
87 type = TREE_TYPE (value);
89 /* First, detect a valid value with a complete type. */
90 if (TYPE_SIZE (type) != 0
91 && type != void_type_node
92 && ! (TYPE_LANG_SPECIFIC (type)
93 && (IS_SIGNATURE_POINTER (type) || IS_SIGNATURE_REFERENCE (type))
94 && TYPE_SIZE (SIGNATURE_TYPE (type)) == 0))
97 /* If we see X::Y, we build an OFFSET_TYPE which has
98 not been laid out. Try to avoid an error by interpreting
99 it as this->X::Y, if reasonable. */
100 if (TREE_CODE (value) == OFFSET_REF
102 && TREE_OPERAND (value, 0) == C_C_D)
104 tree base, member = TREE_OPERAND (value, 1);
105 tree basetype = TYPE_OFFSET_BASETYPE (type);
106 my_friendly_assert (TREE_CODE (member) == FIELD_DECL, 305);
107 base = convert_pointer_to (basetype, current_class_decl);
108 value = build (COMPONENT_REF, TREE_TYPE (member),
109 build_indirect_ref (base, NULL_PTR), member);
110 return require_complete_type (value);
113 if (IS_AGGR_TYPE (type) && CLASSTYPE_TEMPLATE_INSTANTIATION (type))
115 instantiate_class_template (type);
116 if (TYPE_SIZE (type) != 0)
120 incomplete_type_error (value, type);
121 return error_mark_node;
128 if (TYPE_SIZE (type) != NULL_TREE)
130 else if (TREE_CODE (type) == ARRAY_TYPE)
132 tree t = complete_type (TREE_TYPE (type));
133 if (TYPE_SIZE (t) != NULL_TREE)
134 type = build_cplus_array_type (t, TYPE_DOMAIN (type));
136 else if (IS_AGGR_TYPE (type) && CLASSTYPE_TEMPLATE_INSTANTIATION (type))
137 instantiate_class_template (TYPE_MAIN_VARIANT (type));
142 /* Return truthvalue of whether type of EXP is instantiated. */
147 return (TREE_CODE (exp) == TREE_LIST
148 || TREE_TYPE (exp) == unknown_type_node
149 || (TREE_CODE (TREE_TYPE (exp)) == OFFSET_TYPE
150 && TREE_TYPE (TREE_TYPE (exp)) == unknown_type_node));
153 /* Return truthvalue of whether T is function (or pfn) type. */
158 return (TREE_CODE (t) == FUNCTION_TYPE || TREE_CODE (t) == METHOD_TYPE
159 || (TREE_CODE (t) == POINTER_TYPE
160 && (TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE
161 || TREE_CODE (TREE_TYPE (t)) == METHOD_TYPE)));
164 /* Do `exp = require_instantiated_type (type, exp);' to make sure EXP
165 does not have an uninstantiated type.
166 TYPE is type to instantiate with, if uninstantiated. */
168 require_instantiated_type (type, exp, errval)
169 tree type, exp, errval;
171 if (TREE_TYPE (exp) == NULL_TREE)
173 error ("argument list may not have an initializer list");
177 if (TREE_TYPE (exp) == unknown_type_node
178 || (TREE_CODE (TREE_TYPE (exp)) == OFFSET_TYPE
179 && TREE_TYPE (TREE_TYPE (exp)) == unknown_type_node))
181 exp = instantiate_type (type, exp, 1);
182 if (TREE_TYPE (exp) == error_mark_node)
188 /* Return a variant of TYPE which has all the type qualifiers of LIKE
189 as well as those of TYPE. */
192 qualify_type (type, like)
195 int constflag = TYPE_READONLY (type) || TYPE_READONLY (like);
196 int volflag = TYPE_VOLATILE (type) || TYPE_VOLATILE (like);
197 /* @@ Must do member pointers here. */
198 return cp_build_type_variant (type, constflag, volflag);
201 /* Return the common type of two parameter lists.
202 We assume that comptypes has already been done and returned 1;
203 if that isn't so, this may crash.
205 As an optimization, free the space we allocate if the parameter
206 lists are already common. */
212 tree oldargs = p1, newargs, n;
215 char *first_obj = (char *) oballoc (0);
217 len = list_length (p1);
218 newargs = tree_last (p1);
220 if (newargs == void_list_node)
229 newargs = tree_cons (NULL_TREE, NULL_TREE, newargs);
234 p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2), n = TREE_CHAIN (n), i++)
236 if (TREE_PURPOSE (p1) && !TREE_PURPOSE (p2))
238 TREE_PURPOSE (n) = TREE_PURPOSE (p1);
241 else if (! TREE_PURPOSE (p1))
243 if (TREE_PURPOSE (p2))
245 TREE_PURPOSE (n) = TREE_PURPOSE (p2);
251 if (1 != simple_cst_equal (TREE_PURPOSE (p1), TREE_PURPOSE (p2)))
253 TREE_PURPOSE (n) = TREE_PURPOSE (p2);
255 if (TREE_VALUE (p1) != TREE_VALUE (p2))
258 TREE_VALUE (n) = common_type (TREE_VALUE (p1), TREE_VALUE (p2));
261 TREE_VALUE (n) = TREE_VALUE (p1);
272 /* Return the common type of two types.
273 We assume that comptypes has already been done and returned 1;
274 if that isn't so, this may crash.
276 This is the type for the result of most arithmetic operations
277 if the operands have the given two types.
279 We do not deal with enumeral types here because they have already been
280 converted to integer types. */
286 register enum tree_code code1;
287 register enum tree_code code2;
290 /* Save time if the two types are the same. */
292 if (t1 == t2) return t1;
294 /* If one type is nonsense, use the other. */
295 if (t1 == error_mark_node)
297 if (t2 == error_mark_node)
300 /* Merge the attributes */
302 { register tree a1, a2;
303 a1 = TYPE_ATTRIBUTES (t1);
304 a2 = TYPE_ATTRIBUTES (t2);
306 /* Either one unset? Take the set one. */
308 if (!(attributes = a1))
311 /* One that completely contains the other? Take it. */
313 else if (a2 && !attribute_list_contained (a1, a2))
314 if (attribute_list_contained (a2, a1))
318 /* Pick the longest list, and hang on the other list. */
319 /* ??? For the moment we punt on the issue of attrs with args. */
321 if (list_length (a1) < list_length (a2))
322 attributes = a2, a2 = a1;
324 for (; a2; a2 = TREE_CHAIN (a2))
325 if (lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2)),
326 attributes) == NULL_TREE)
329 TREE_CHAIN (a1) = attributes;
335 /* Treat an enum type as the unsigned integer type of the same width. */
337 if (TREE_CODE (t1) == ENUMERAL_TYPE)
338 t1 = type_for_size (TYPE_PRECISION (t1), 1);
339 if (TREE_CODE (t2) == ENUMERAL_TYPE)
340 t2 = type_for_size (TYPE_PRECISION (t2), 1);
342 if (TYPE_PTRMEMFUNC_P (t1))
343 t1 = TYPE_PTRMEMFUNC_FN_TYPE (t1);
344 if (TYPE_PTRMEMFUNC_P (t2))
345 t2 = TYPE_PTRMEMFUNC_FN_TYPE (t2);
347 code1 = TREE_CODE (t1);
348 code2 = TREE_CODE (t2);
354 /* If only one is real, use it as the result. */
356 if (code1 == REAL_TYPE && code2 != REAL_TYPE)
357 return build_type_attribute_variant (t1, attributes);
359 if (code2 == REAL_TYPE && code1 != REAL_TYPE)
360 return build_type_attribute_variant (t2, attributes);
362 /* Both real or both integers; use the one with greater precision. */
364 if (TYPE_PRECISION (t1) > TYPE_PRECISION (t2))
365 return build_type_attribute_variant (t1, attributes);
366 else if (TYPE_PRECISION (t2) > TYPE_PRECISION (t1))
367 return build_type_attribute_variant (t2, attributes);
369 /* Same precision. Prefer longs to ints even when same size. */
371 if (TYPE_MAIN_VARIANT (t1) == long_unsigned_type_node
372 || TYPE_MAIN_VARIANT (t2) == long_unsigned_type_node)
373 return build_type_attribute_variant (long_unsigned_type_node,
376 if (TYPE_MAIN_VARIANT (t1) == long_integer_type_node
377 || TYPE_MAIN_VARIANT (t2) == long_integer_type_node)
379 /* But preserve unsignedness from the other type,
380 since long cannot hold all the values of an unsigned int. */
381 if (TREE_UNSIGNED (t1) || TREE_UNSIGNED (t2))
382 t1 = long_unsigned_type_node;
384 t1 = long_integer_type_node;
385 return build_type_attribute_variant (t1, attributes);
388 if (TYPE_MAIN_VARIANT (t1) == long_double_type_node
389 || TYPE_MAIN_VARIANT (t2) == long_double_type_node)
390 return build_type_attribute_variant (long_double_type_node,
393 /* Otherwise prefer the unsigned one. */
395 if (TREE_UNSIGNED (t1))
396 return build_type_attribute_variant (t1, attributes);
398 return build_type_attribute_variant (t2, attributes);
402 /* For two pointers, do this recursively on the target type,
403 and combine the qualifiers of the two types' targets. */
404 /* This code was turned off; I don't know why.
405 But ANSI C++ specifies doing this with the qualifiers.
406 So I turned it on again. */
408 tree tt1 = TYPE_MAIN_VARIANT (TREE_TYPE (t1));
409 tree tt2 = TYPE_MAIN_VARIANT (TREE_TYPE (t2));
411 = TYPE_READONLY (TREE_TYPE (t1)) || TYPE_READONLY (TREE_TYPE (t2));
413 = TYPE_VOLATILE (TREE_TYPE (t1)) || TYPE_VOLATILE (TREE_TYPE (t2));
418 else if (tt1 == void_type_node || tt2 == void_type_node)
419 target = void_type_node;
421 target = common_type (tt1, tt2);
423 target = cp_build_type_variant (target, constp, volatilep);
424 if (code1 == POINTER_TYPE)
425 t1 = build_pointer_type (target);
427 t1 = build_reference_type (target);
428 t1 = build_type_attribute_variant (t1, attributes);
430 if (TREE_CODE (target) == METHOD_TYPE)
431 t1 = build_ptrmemfunc_type (t1);
438 tree elt = common_type (TREE_TYPE (t1), TREE_TYPE (t2));
439 /* Save space: see if the result is identical to one of the args. */
440 if (elt == TREE_TYPE (t1) && TYPE_DOMAIN (t1))
441 return build_type_attribute_variant (t1, attributes);
442 if (elt == TREE_TYPE (t2) && TYPE_DOMAIN (t2))
443 return build_type_attribute_variant (t2, attributes);
444 /* Merge the element types, and have a size if either arg has one. */
445 t1 = build_cplus_array_type (elt, TYPE_DOMAIN (TYPE_DOMAIN (t1) ? t1 : t2));
446 return build_type_attribute_variant (t1, attributes);
450 /* Function types: prefer the one that specified arg types.
451 If both do, merge the arg types. Also merge the return types. */
453 tree valtype = common_type (TREE_TYPE (t1), TREE_TYPE (t2));
454 tree p1 = TYPE_ARG_TYPES (t1);
455 tree p2 = TYPE_ARG_TYPES (t2);
458 /* Save space: see if the result is identical to one of the args. */
459 if (valtype == TREE_TYPE (t1) && ! p2)
460 return build_type_attribute_variant (t1, attributes);
461 if (valtype == TREE_TYPE (t2) && ! p1)
462 return build_type_attribute_variant (t2, attributes);
464 /* Simple way if one arg fails to specify argument types. */
465 if (p1 == NULL_TREE || TREE_VALUE (p1) == void_type_node)
467 rval = build_function_type (valtype, p2);
468 if ((raises = TYPE_RAISES_EXCEPTIONS (t2)))
469 rval = build_exception_variant (rval, raises);
470 return build_type_attribute_variant (rval, attributes);
472 raises = TYPE_RAISES_EXCEPTIONS (t1);
473 if (p2 == NULL_TREE || TREE_VALUE (p2) == void_type_node)
475 rval = build_function_type (valtype, p1);
477 rval = build_exception_variant (rval, raises);
478 return build_type_attribute_variant (rval, attributes);
481 rval = build_function_type (valtype, commonparms (p1, p2));
482 rval = build_exception_variant (rval, raises);
483 return build_type_attribute_variant (rval, attributes);
488 my_friendly_assert (TYPE_MAIN_VARIANT (t1) == t1
489 && TYPE_MAIN_VARIANT (t2) == t2, 306);
491 if (DERIVED_FROM_P (t1, t2) && binfo_or_else (t1, t2))
492 return build_type_attribute_variant (t1, attributes);
493 else if (binfo_or_else (t2, t1))
494 return build_type_attribute_variant (t2, attributes);
496 compiler_error ("common_type called with uncommon aggregate types");
499 if (TREE_CODE (TREE_TYPE (t1)) == TREE_CODE (TREE_TYPE (t2)))
501 /* Get this value the long way, since TYPE_METHOD_BASETYPE
502 is just the main variant of this. */
506 tree b1 = TYPE_OFFSET_BASETYPE (t1);
507 tree b2 = TYPE_OFFSET_BASETYPE (t2);
509 if (comptypes (b1, b2, 1)
510 || (DERIVED_FROM_P (b1, b2) && binfo_or_else (b1, b2)))
511 basetype = TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t2)));
514 if (binfo_or_else (b2, b1) == NULL_TREE)
515 compiler_error ("common_type called with uncommon method types");
516 basetype = TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t1)));
519 raises = TYPE_RAISES_EXCEPTIONS (t1);
521 /* If this was a member function type, get back to the
522 original type of type member function (i.e., without
523 the class instance variable up front. */
524 t1 = build_function_type (TREE_TYPE (t1), TREE_CHAIN (TYPE_ARG_TYPES (t1)));
525 t2 = build_function_type (TREE_TYPE (t2), TREE_CHAIN (TYPE_ARG_TYPES (t2)));
526 t3 = common_type (t1, t2);
527 t3 = build_cplus_method_type (basetype, TREE_TYPE (t3), TYPE_ARG_TYPES (t3));
528 t1 = build_exception_variant (t3, raises);
531 compiler_error ("common_type called with uncommon method types");
533 return build_type_attribute_variant (t1, attributes);
536 if (TREE_TYPE (t1) == TREE_TYPE (t2))
538 tree b1 = TYPE_OFFSET_BASETYPE (t1);
539 tree b2 = TYPE_OFFSET_BASETYPE (t2);
541 if (DERIVED_FROM_P (b1, b2) && binfo_or_else (b1, b2))
542 return build_type_attribute_variant (t2, attributes);
543 else if (binfo_or_else (b2, b1))
544 return build_type_attribute_variant (t1, attributes);
546 compiler_error ("common_type called with uncommon member types");
549 return build_type_attribute_variant (t1, attributes);
553 /* Return 1 if TYPE1 and TYPE2 raise the same exceptions. */
555 compexcepttypes (t1, t2)
558 return TYPE_RAISES_EXCEPTIONS (t1) == TYPE_RAISES_EXCEPTIONS (t2);
562 comp_array_types (cmp, t1, t2, strict)
563 register int (*cmp)();
567 tree d1 = TYPE_DOMAIN (t1);
568 tree d2 = TYPE_DOMAIN (t2);
570 /* Target types must match incl. qualifiers. */
571 if (!(TREE_TYPE (t1) == TREE_TYPE (t2)
572 || (*cmp) (TREE_TYPE (t1), TREE_TYPE (t2), strict)))
575 /* Sizes must match unless one is missing or variable. */
576 if (d1 == 0 || d2 == 0 || d1 == d2
577 || TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST
578 || TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST
579 || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST
580 || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST)
583 return ((TREE_INT_CST_LOW (TYPE_MIN_VALUE (d1))
584 == TREE_INT_CST_LOW (TYPE_MIN_VALUE (d2)))
585 && (TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d1))
586 == TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d2)))
587 && (TREE_INT_CST_LOW (TYPE_MAX_VALUE (d1))
588 == TREE_INT_CST_LOW (TYPE_MAX_VALUE (d2)))
589 && (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d1))
590 == TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d2))));
593 /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
594 or various other operations. This is what ANSI C++ speaks of as
597 For C++: argument STRICT says we should be strict about this
600 2 : strict, except that if one type is a reference and
601 the other is not, compare the target type of the
602 reference to the type that's not a reference (ARM, p308).
603 This is used for checking for invalid overloading.
604 1 : strict (compared according to ANSI C)
605 This is used for checking whether two function decls match.
606 0 : <= (compared according to C++)
607 -1: <= or >= (relaxed)
609 Otherwise, pointers involving base classes and derived classes
610 can be mixed as valid: i.e. a pointer to a base class may be assigned
611 to a pointer to one of its derived classes, as per C++. A pointer to
612 a derived class may be passed as a parameter to a function expecting a
613 pointer to a base classes. These allowances do not commute. In this
614 case, TYPE1 is assumed to be the base class, and TYPE2 is assumed to
615 be the derived class. */
617 comptypes (type1, type2, strict)
621 register tree t1 = type1;
622 register tree t2 = type2;
625 /* Suppress errors caused by previously reported errors */
630 /* This should never happen. */
631 my_friendly_assert (t1 != error_mark_node, 307);
633 if (t2 == error_mark_node)
638 /* Treat an enum type as the unsigned integer type of the same width. */
640 if (TREE_CODE (t1) == ENUMERAL_TYPE)
641 t1 = type_for_size (TYPE_PRECISION (t1), 1);
642 if (TREE_CODE (t2) == ENUMERAL_TYPE)
643 t2 = type_for_size (TYPE_PRECISION (t2), 1);
649 if (TYPE_PTRMEMFUNC_P (t1))
650 t1 = TYPE_PTRMEMFUNC_FN_TYPE (t1);
651 if (TYPE_PTRMEMFUNC_P (t2))
652 t2 = TYPE_PTRMEMFUNC_FN_TYPE (t2);
654 /* Different classes of types can't be compatible. */
656 if (TREE_CODE (t1) != TREE_CODE (t2))
659 && ((TREE_CODE (t1) == REFERENCE_TYPE)
660 ^ (TREE_CODE (t2) == REFERENCE_TYPE)))
662 if (TREE_CODE (t1) == REFERENCE_TYPE)
663 return comptypes (TREE_TYPE (t1), t2, 1);
664 return comptypes (t1, TREE_TYPE (t2), 1);
672 /* Qualifiers must match. */
674 if (TYPE_READONLY (t1) != TYPE_READONLY (t2))
676 if (TYPE_VOLATILE (t1) != TYPE_VOLATILE (t2))
679 /* Allow for two different type nodes which have essentially the same
680 definition. Note that we already checked for equality of the type
681 type qualifiers (just above). */
683 if (TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
686 /* ??? COMP_TYPE_ATTRIBUTES is currently useless for variables as each
687 attribute is its own main variant (`val' will remain 0). */
688 #ifndef COMP_TYPE_ATTRIBUTES
689 #define COMP_TYPE_ATTRIBUTES(t1,t2) 1
692 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
693 if (! (attrval = COMP_TYPE_ATTRIBUTES (t1, t2)))
696 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
699 switch (TREE_CODE (t1))
703 if (CLASSTYPE_TEMPLATE_INFO (t1) && CLASSTYPE_TEMPLATE_INFO (t2)
704 && CLASSTYPE_TI_TEMPLATE (t1) == CLASSTYPE_TI_TEMPLATE (t2))
706 int i = TREE_VEC_LENGTH (CLASSTYPE_TI_ARGS (t1));
707 tree *p1 = &TREE_VEC_ELT (CLASSTYPE_TI_ARGS (t1), 0);
708 tree *p2 = &TREE_VEC_ELT (CLASSTYPE_TI_ARGS (t2), 0);
712 if (TREE_CODE_CLASS (TREE_CODE (p1[i])) == 't')
714 if (! comptypes (p1[i], p2[i], 1))
719 if (simple_cst_equal (p1[i], p2[i]) <= 0)
730 val = (comptypes (build_pointer_type (TYPE_OFFSET_BASETYPE (t1)),
731 build_pointer_type (TYPE_OFFSET_BASETYPE (t2)), strict)
732 && comptypes (TREE_TYPE (t1), TREE_TYPE (t2), strict));
736 if (! compexcepttypes (t1, t2))
739 /* This case is anti-symmetrical!
740 One can pass a base member (or member function)
741 to something expecting a derived member (or member function),
742 but not vice-versa! */
744 val = (comptypes (TREE_TYPE (t1), TREE_TYPE (t2), strict)
745 && compparms (TYPE_ARG_TYPES (t1),
746 TYPE_ARG_TYPES (t2), strict));
760 if (TREE_CODE (t1) == RECORD_TYPE && TREE_CODE (t2) == RECORD_TYPE)
764 rval = t1 == t2 || UNIQUELY_DERIVED_FROM_P (t1, t2);
773 val = UNIQUELY_DERIVED_FROM_P (t2, t1);
780 val = comptypes (t1, t2, strict);
784 if (! compexcepttypes (t1, t2))
787 val = ((TREE_TYPE (t1) == TREE_TYPE (t2)
788 || comptypes (TREE_TYPE (t1), TREE_TYPE (t2), strict))
789 && compparms (TYPE_ARG_TYPES (t1), TYPE_ARG_TYPES (t2), strict));
793 /* Target types must match incl. qualifiers. */
794 val = comp_array_types (comptypes, t1, t2, strict);
797 case TEMPLATE_TYPE_PARM:
798 return TEMPLATE_TYPE_IDX (t1) == TEMPLATE_TYPE_IDX (t2);
801 if (TYPE_IDENTIFIER (t1) != TYPE_IDENTIFIER (t2))
803 return comptypes (TYPE_CONTEXT (t1), TYPE_CONTEXT (t2), 1);
805 return attrval == 2 && val == 1 ? 2 : val;
808 /* Return 1 if TTL and TTR are pointers to types that are equivalent,
809 ignoring their qualifiers.
811 NPTRS is the number of pointers we can strip off and keep cool.
812 This is used to permit (for aggr A, aggr B) A, B* to convert to A*,
813 but to not permit B** to convert to A**. */
816 comp_target_types (ttl, ttr, nptrs)
820 ttl = TYPE_MAIN_VARIANT (ttl);
821 ttr = TYPE_MAIN_VARIANT (ttr);
825 if (TREE_CODE (ttr) != TREE_CODE (ttl))
828 if (TREE_CODE (ttr) == POINTER_TYPE)
830 ttl = TREE_TYPE (ttl);
831 ttr = TREE_TYPE (ttr);
835 if (TREE_CODE (ttl) == VOID_TYPE
836 && TREE_CODE (ttr) != FUNCTION_TYPE
837 && TREE_CODE (ttr) != METHOD_TYPE
838 && TREE_CODE (ttr) != OFFSET_TYPE)
840 else if (TREE_CODE (ttr) == VOID_TYPE
841 && TREE_CODE (ttl) != FUNCTION_TYPE
842 && TREE_CODE (ttl) != METHOD_TYPE
843 && TREE_CODE (ttl) != OFFSET_TYPE)
845 else if (TREE_CODE (ttl) == POINTER_TYPE
846 || TREE_CODE (ttl) == ARRAY_TYPE)
848 if (comp_ptr_ttypes (ttl, ttr))
850 else if (comp_ptr_ttypes (ttr, ttl))
856 /* Const and volatile mean something different for function types,
857 so the usual checks are not appropriate. */
858 if (TREE_CODE (ttl) == FUNCTION_TYPE || TREE_CODE (ttl) == METHOD_TYPE)
859 return comp_target_types (ttl, ttr, nptrs - 1);
861 /* Make sure that the cv-quals change only in the same direction as
865 int c = TYPE_READONLY (ttl) - TYPE_READONLY (ttr);
866 int v = TYPE_VOLATILE (ttl) - TYPE_VOLATILE (ttr);
868 if ((c > 0 && v < 0) || (c < 0 && v > 0))
871 if (TYPE_MAIN_VARIANT (ttl) == TYPE_MAIN_VARIANT (ttr))
872 return (c + v < 0) ? -1 : 1;
874 t = comp_target_types (ttl, ttr, nptrs - 1);
875 if ((t == 1 && c + v >= 0) || (t == -1 && c + v <= 0))
882 if (TREE_CODE (ttr) == REFERENCE_TYPE)
883 return comp_target_types (TREE_TYPE (ttl), TREE_TYPE (ttr), nptrs);
884 if (TREE_CODE (ttr) == ARRAY_TYPE)
885 return comp_array_types (comp_target_types, ttl, ttr, 0);
886 else if (TREE_CODE (ttr) == FUNCTION_TYPE || TREE_CODE (ttr) == METHOD_TYPE)
887 if (comp_target_types (TREE_TYPE (ttl), TREE_TYPE (ttr), nptrs))
888 switch (comp_target_parms (TYPE_ARG_TYPES (ttl), TYPE_ARG_TYPES (ttr), 1))
897 my_friendly_abort (112);
903 else if (TREE_CODE (ttr) == OFFSET_TYPE)
905 /* Contravariance: we can assign a pointer to base member to a pointer
906 to derived member. Note difference from simple pointer case, where
907 we can pass a pointer to derived to a pointer to base. */
908 if (comptypes (TYPE_OFFSET_BASETYPE (ttr), TYPE_OFFSET_BASETYPE (ttl), 0))
909 return comp_target_types (TREE_TYPE (ttl), TREE_TYPE (ttr), nptrs);
910 else if (comptypes (TYPE_OFFSET_BASETYPE (ttl), TYPE_OFFSET_BASETYPE (ttr), 0)
911 && comp_target_types (TREE_TYPE (ttl), TREE_TYPE (ttr), nptrs))
914 else if (IS_AGGR_TYPE (ttl))
918 if (comptypes (build_pointer_type (ttl), build_pointer_type (ttr), 0))
920 if (comptypes (build_pointer_type (ttr), build_pointer_type (ttl), 0))
928 /* If two types share a common base type, return that basetype.
929 If there is not a unique most-derived base type, this function
930 returns ERROR_MARK_NODE. */
932 common_base_type (tt1, tt2)
935 tree best = NULL_TREE;
938 /* If one is a baseclass of another, that's good enough. */
939 if (UNIQUELY_DERIVED_FROM_P (tt1, tt2))
941 if (UNIQUELY_DERIVED_FROM_P (tt2, tt1))
944 /* Otherwise, try to find a unique baseclass of TT1
945 that is shared by TT2, and follow that down. */
946 for (i = CLASSTYPE_N_BASECLASSES (tt1)-1; i >= 0; i--)
948 tree basetype = TYPE_BINFO_BASETYPE (tt1, i);
949 tree trial = common_base_type (basetype, tt2);
952 if (trial == error_mark_node)
954 if (best == NULL_TREE)
956 else if (best != trial)
957 return error_mark_node;
962 for (i = CLASSTYPE_N_BASECLASSES (tt2)-1; i >= 0; i--)
964 tree basetype = TYPE_BINFO_BASETYPE (tt2, i);
965 tree trial = common_base_type (tt1, basetype);
968 if (trial == error_mark_node)
970 if (best == NULL_TREE)
972 else if (best != trial)
973 return error_mark_node;
979 /* Subroutines of `comptypes'. */
981 /* Return 1 if two parameter type lists PARMS1 and PARMS2
982 are equivalent in the sense that functions with those parameter types
983 can have equivalent types.
984 If either list is empty, we win.
985 Otherwise, the two lists must be equivalent, element by element.
987 C++: See comment above about TYPE1, TYPE2, STRICT.
988 If STRICT == 3, it means checking is strict, but do not compare
989 default parameter values. */
991 compparms (parms1, parms2, strict)
995 register tree t1 = parms1, t2 = parms2;
997 /* An unspecified parmlist matches any specified parmlist
998 whose argument types don't need default promotions. */
1000 if (strict <= 0 && t1 == 0)
1001 return self_promoting_args_p (t2);
1002 if (strict < 0 && t2 == 0)
1003 return self_promoting_args_p (t1);
1007 if (t1 == 0 && t2 == 0)
1009 /* If one parmlist is shorter than the other,
1010 they fail to match, unless STRICT is <= 0. */
1011 if (t1 == 0 || t2 == 0)
1018 return t1 && TREE_PURPOSE (t1);
1020 if (! comptypes (TREE_VALUE (t2), TREE_VALUE (t1), strict))
1025 return t2 == void_list_node && TREE_PURPOSE (t1);
1026 return TREE_PURPOSE (t1) || TREE_PURPOSE (t2);
1029 t1 = TREE_CHAIN (t1);
1030 t2 = TREE_CHAIN (t2);
1034 /* This really wants return whether or not parameter type lists
1035 would make their owning functions assignment compatible or not. */
1037 comp_target_parms (parms1, parms2, strict)
1038 tree parms1, parms2;
1041 register tree t1 = parms1, t2 = parms2;
1042 int warn_contravariance = 0;
1044 /* An unspecified parmlist matches any specified parmlist
1045 whose argument types don't need default promotions.
1046 @@@ see 13.3.3 for a counterexample... */
1048 if (t1 == 0 && t2 != 0)
1050 cp_pedwarn ("ANSI C++ prohibits conversion from `(%#T)' to `(...)'",
1052 return self_promoting_args_p (t2);
1055 return self_promoting_args_p (t1);
1057 for (; t1 || t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
1061 /* If one parmlist is shorter than the other,
1062 they fail to match, unless STRICT is <= 0. */
1063 if (t1 == 0 || t2 == 0)
1068 return 1 + warn_contravariance;
1069 return ((t1 && TREE_PURPOSE (t1)) + warn_contravariance);
1071 p1 = TREE_VALUE (t1);
1072 p2 = TREE_VALUE (t2);
1076 if ((TREE_CODE (p1) == POINTER_TYPE && TREE_CODE (p2) == POINTER_TYPE)
1077 || (TREE_CODE (p1) == REFERENCE_TYPE && TREE_CODE (p2) == REFERENCE_TYPE))
1080 && (TYPE_MAIN_VARIANT (TREE_TYPE (p1))
1081 == TYPE_MAIN_VARIANT (TREE_TYPE (p2))))
1084 /* The following is wrong for contravariance,
1085 but many programs depend on it. */
1086 if (TREE_TYPE (p1) == void_type_node)
1088 if (TREE_TYPE (p2) == void_type_node)
1090 warn_contravariance = 1;
1093 if (IS_AGGR_TYPE (TREE_TYPE (p1)))
1095 if (comptypes (p2, p1, 0) == 0)
1097 if (comptypes (p1, p2, 0) != 0)
1098 warn_contravariance = 1;
1105 /* Note backwards order due to contravariance. */
1106 if (comp_target_types (p2, p1, 1) == 0)
1108 if (comp_target_types (p1, p2, 1))
1110 warn_contravariance = 1;
1116 /* Target types are compatible--just make sure that if
1117 we use parameter lists, that they are ok as well. */
1118 if (TREE_CODE (p1) == FUNCTION_TYPE || TREE_CODE (p1) == METHOD_TYPE)
1119 switch (comp_target_parms (TYPE_ARG_TYPES (p1),
1120 TYPE_ARG_TYPES (p2),
1128 warn_contravariance = 1;
1131 if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2))
1133 int cmp = simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2));
1135 my_friendly_abort (114);
1140 return 1 + warn_contravariance;
1143 /* Return 1 if PARMS specifies a fixed number of parameters
1144 and none of their types is affected by default promotions. */
1147 self_promoting_args_p (parms)
1151 for (t = parms; t; t = TREE_CHAIN (t))
1153 register tree type = TREE_VALUE (t);
1155 if (TREE_CHAIN (t) == 0 && type != void_type_node)
1161 if (TYPE_MAIN_VARIANT (type) == float_type_node)
1164 if (C_PROMOTING_INTEGER_TYPE_P (type))
1170 /* Return an unsigned type the same as TYPE in other respects.
1172 C++: must make these work for type variants as well. */
1175 unsigned_type (type)
1178 tree type1 = TYPE_MAIN_VARIANT (type);
1179 if (type1 == signed_char_type_node || type1 == char_type_node)
1180 return unsigned_char_type_node;
1181 if (type1 == integer_type_node)
1182 return unsigned_type_node;
1183 if (type1 == short_integer_type_node)
1184 return short_unsigned_type_node;
1185 if (type1 == long_integer_type_node)
1186 return long_unsigned_type_node;
1187 if (type1 == long_long_integer_type_node)
1188 return long_long_unsigned_type_node;
1189 if (type1 == intDI_type_node)
1190 return unsigned_intDI_type_node;
1191 if (type1 == intSI_type_node)
1192 return unsigned_intSI_type_node;
1193 if (type1 == intHI_type_node)
1194 return unsigned_intHI_type_node;
1195 if (type1 == intQI_type_node)
1196 return unsigned_intQI_type_node;
1200 /* Return a signed type the same as TYPE in other respects. */
1206 tree type1 = TYPE_MAIN_VARIANT (type);
1207 if (type1 == unsigned_char_type_node || type1 == char_type_node)
1208 return signed_char_type_node;
1209 if (type1 == unsigned_type_node)
1210 return integer_type_node;
1211 if (type1 == short_unsigned_type_node)
1212 return short_integer_type_node;
1213 if (type1 == long_unsigned_type_node)
1214 return long_integer_type_node;
1215 if (type1 == long_long_unsigned_type_node)
1216 return long_long_integer_type_node;
1217 if (type1 == unsigned_intDI_type_node)
1218 return intDI_type_node;
1219 if (type1 == unsigned_intSI_type_node)
1220 return intSI_type_node;
1221 if (type1 == unsigned_intHI_type_node)
1222 return intHI_type_node;
1223 if (type1 == unsigned_intQI_type_node)
1224 return intQI_type_node;
1228 /* Return a type the same as TYPE except unsigned or
1229 signed according to UNSIGNEDP. */
1232 signed_or_unsigned_type (unsignedp, type)
1236 if (! INTEGRAL_TYPE_P (type))
1238 if (TYPE_PRECISION (type) == TYPE_PRECISION (signed_char_type_node))
1239 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
1240 if (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
1241 return unsignedp ? unsigned_type_node : integer_type_node;
1242 if (TYPE_PRECISION (type) == TYPE_PRECISION (short_integer_type_node))
1243 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
1244 if (TYPE_PRECISION (type) == TYPE_PRECISION (long_integer_type_node))
1245 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
1246 if (TYPE_PRECISION (type) == TYPE_PRECISION (long_long_integer_type_node))
1247 return (unsignedp ? long_long_unsigned_type_node
1248 : long_long_integer_type_node);
1252 /* Compute the value of the `sizeof' operator. */
1258 enum tree_code code = TREE_CODE (type);
1261 if (current_template_parms)
1262 return build_min (SIZEOF_EXPR, sizetype, type);
1264 if (code == FUNCTION_TYPE)
1266 if (pedantic || warn_pointer_arith)
1267 pedwarn ("ANSI C++ forbids taking the sizeof a function type");
1268 return size_int (1);
1270 if (code == METHOD_TYPE)
1272 if (pedantic || warn_pointer_arith)
1273 pedwarn ("ANSI C++ forbids taking the sizeof a method type");
1274 return size_int (1);
1276 if (code == VOID_TYPE)
1278 if (pedantic || warn_pointer_arith)
1279 pedwarn ("ANSI C++ forbids taking the sizeof a void type");
1280 return size_int (1);
1282 if (code == ERROR_MARK)
1283 return size_int (1);
1285 /* ARM $5.3.2: ``When applied to a reference, the result is the size of the
1286 referenced object.'' */
1287 if (code == REFERENCE_TYPE)
1288 type = TREE_TYPE (type);
1290 /* We couldn't find anything in the ARM or the draft standard that says,
1291 one way or the other, if doing sizeof on something that doesn't have
1292 an object associated with it is correct or incorrect. For example, if
1293 you declare `struct S { char str[16]; };', and in your program do
1294 a `sizeof (S::str)', should we flag that as an error or should we give
1295 the size of it? Since it seems like a reasonable thing to do, we'll go
1296 with giving the value. */
1297 if (code == OFFSET_TYPE)
1298 type = TREE_TYPE (type);
1300 /* @@ This also produces an error for a signature ref.
1301 In that case we should be able to do better. */
1302 if (IS_SIGNATURE (type))
1304 error ("`sizeof' applied to a signature type");
1305 return size_int (0);
1308 if (TYPE_SIZE (complete_type (type)) == 0)
1310 cp_error ("`sizeof' applied to incomplete type `%T'", type);
1311 return size_int (0);
1314 /* Convert in case a char is more than one unit. */
1315 t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type),
1316 size_int (TYPE_PRECISION (char_type_node)));
1317 /* size_binop does not put the constant in range, so do it now. */
1318 if (TREE_CODE (t) == INTEGER_CST && force_fit_type (t, 0))
1319 TREE_CONSTANT_OVERFLOW (t) = TREE_OVERFLOW (t) = 1;
1327 if (current_template_parms)
1328 return build_min (SIZEOF_EXPR, sizetype, e);
1330 if (TREE_CODE (e) == COMPONENT_REF
1331 && DECL_BIT_FIELD (TREE_OPERAND (e, 1)))
1332 error ("sizeof applied to a bit-field");
1333 /* ANSI says arrays and functions are converted inside comma.
1334 But we can't really convert them in build_compound_expr
1335 because that would break commas in lvalues.
1336 So do the conversion here if operand was a comma. */
1337 if (TREE_CODE (e) == COMPOUND_EXPR
1338 && (TREE_CODE (TREE_TYPE (e)) == ARRAY_TYPE
1339 || TREE_CODE (TREE_TYPE (e)) == FUNCTION_TYPE))
1340 e = default_conversion (e);
1341 else if (TREE_CODE (e) == TREE_LIST)
1343 tree t = TREE_VALUE (e);
1346 && TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
1347 || is_overloaded_fn (t)))
1348 pedwarn ("ANSI C++ forbids taking the sizeof a function type");
1350 return c_sizeof (TREE_TYPE (e));
1354 c_sizeof_nowarn (type)
1357 enum tree_code code = TREE_CODE (type);
1360 if (code == FUNCTION_TYPE
1361 || code == METHOD_TYPE
1362 || code == VOID_TYPE
1363 || code == ERROR_MARK)
1364 return size_int (1);
1365 if (code == REFERENCE_TYPE)
1366 type = TREE_TYPE (type);
1368 if (TYPE_SIZE (type) == 0)
1369 return size_int (0);
1371 /* Convert in case a char is more than one unit. */
1372 t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type),
1373 size_int (TYPE_PRECISION (char_type_node)));
1374 force_fit_type (t, 0);
1378 /* Implement the __alignof keyword: Return the minimum required
1379 alignment of TYPE, measured in bytes. */
1385 enum tree_code code = TREE_CODE (type);
1388 if (code == FUNCTION_TYPE || code == METHOD_TYPE)
1389 return size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1391 if (code == VOID_TYPE || code == ERROR_MARK)
1392 return size_int (1);
1394 /* C++: this is really correct! */
1395 if (code == REFERENCE_TYPE)
1396 type = TREE_TYPE (type);
1398 /* @@ This also produces an error for a signature ref.
1399 In that case we should be able to do better. */
1400 if (IS_SIGNATURE (type))
1402 error ("`__alignof' applied to a signature type");
1403 return size_int (1);
1406 t = size_int (TYPE_ALIGN (type) / BITS_PER_UNIT);
1407 force_fit_type (t, 0);
1411 /* Perform default promotions for C data used in expressions.
1412 Arrays and functions are converted to pointers;
1413 enumeral types or short or char, to int.
1414 In addition, manifest constants symbols are replaced by their values.
1416 C++: this will automatically bash references to their target type. */
1419 decay_conversion (exp)
1422 register tree type = TREE_TYPE (exp);
1423 register enum tree_code code = TREE_CODE (type);
1425 if (code == OFFSET_TYPE /* || TREE_CODE (exp) == OFFSET_REF */ )
1427 if (TREE_CODE (exp) == OFFSET_REF)
1428 return decay_conversion (resolve_offset_ref (exp));
1430 type = TREE_TYPE (type);
1431 code = TREE_CODE (type);
1434 if (code == REFERENCE_TYPE)
1436 exp = convert_from_reference (exp);
1437 type = TREE_TYPE (exp);
1438 code = TREE_CODE (type);
1441 /* Constants can be used directly unless they're not loadable. */
1442 if (TREE_CODE (exp) == CONST_DECL)
1443 exp = DECL_INITIAL (exp);
1444 /* Replace a nonvolatile const static variable with its value. */
1445 else if (TREE_READONLY_DECL_P (exp))
1447 exp = decl_constant_value (exp);
1448 type = TREE_TYPE (exp);
1451 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
1452 Leave such NOP_EXPRs, since RHS is being used in non-lvalue context. */
1454 if (code == VOID_TYPE)
1456 error ("void value not ignored as it ought to be");
1457 return error_mark_node;
1459 if (code == FUNCTION_TYPE)
1461 return build_unary_op (ADDR_EXPR, exp, 0);
1463 if (code == METHOD_TYPE)
1465 if (TREE_CODE (exp) == OFFSET_REF)
1467 /* FIXME: We should emit an error here about using a ptrmemfunc
1468 for something other than a function call. */
1469 my_friendly_assert (TREE_CODE (TREE_OPERAND (exp, 1)) == FUNCTION_DECL,
1471 return build_unary_op (ADDR_EXPR, TREE_OPERAND (exp, 1), 0);
1473 return build_unary_op (ADDR_EXPR, exp, 0);
1475 if (code == ARRAY_TYPE)
1480 int constp, volatilep;
1482 if (TREE_CODE (exp) == INDIRECT_REF)
1484 /* Stripping away the INDIRECT_REF is not the right
1485 thing to do for references... */
1486 tree inner = TREE_OPERAND (exp, 0);
1487 if (TREE_CODE (TREE_TYPE (inner)) == REFERENCE_TYPE)
1489 inner = build1 (CONVERT_EXPR,
1490 build_pointer_type (TREE_TYPE (TREE_TYPE (inner))),
1492 TREE_REFERENCE_EXPR (inner) = 1;
1494 return convert (build_pointer_type (TREE_TYPE (type)), inner);
1497 if (TREE_CODE (exp) == COMPOUND_EXPR)
1499 tree op1 = decay_conversion (TREE_OPERAND (exp, 1));
1500 return build (COMPOUND_EXPR, TREE_TYPE (op1),
1501 TREE_OPERAND (exp, 0), op1);
1505 && ! (TREE_CODE (exp) == CONSTRUCTOR && TREE_STATIC (exp)))
1507 error ("invalid use of non-lvalue array");
1508 return error_mark_node;
1511 constp = volatilep = 0;
1512 if (TREE_CODE_CLASS (TREE_CODE (exp)) == 'r'
1513 || TREE_CODE_CLASS (TREE_CODE (exp)) == 'd')
1515 constp = TREE_READONLY (exp);
1516 volatilep = TREE_THIS_VOLATILE (exp);
1519 restype = TREE_TYPE (type);
1520 if (TYPE_READONLY (type) || TYPE_VOLATILE (type)
1521 || constp || volatilep)
1522 restype = cp_build_type_variant (restype,
1523 TYPE_READONLY (type) || constp,
1524 TYPE_VOLATILE (type) || volatilep);
1525 ptrtype = build_pointer_type (restype);
1527 if (TREE_CODE (exp) == VAR_DECL)
1529 /* ??? This is not really quite correct
1530 in that the type of the operand of ADDR_EXPR
1531 is not the target type of the type of the ADDR_EXPR itself.
1532 Question is, can this lossage be avoided? */
1533 adr = build1 (ADDR_EXPR, ptrtype, exp);
1534 if (mark_addressable (exp) == 0)
1535 return error_mark_node;
1536 TREE_CONSTANT (adr) = staticp (exp);
1537 TREE_SIDE_EFFECTS (adr) = 0; /* Default would be, same as EXP. */
1540 /* This way is better for a COMPONENT_REF since it can
1541 simplify the offset for a component. */
1542 adr = build_unary_op (ADDR_EXPR, exp, 1);
1543 return convert (ptrtype, adr);
1550 default_conversion (exp)
1554 enum tree_code code;
1556 exp = decay_conversion (exp);
1558 type = TREE_TYPE (exp);
1559 code = TREE_CODE (type);
1561 if (INTEGRAL_CODE_P (code))
1563 tree t = type_promotes_to (type);
1565 return convert (t, exp);
1567 if (flag_traditional
1568 && TYPE_MAIN_VARIANT (type) == float_type_node)
1569 return convert (double_type_node, exp);
1575 build_object_ref (datum, basetype, field)
1576 tree datum, basetype, field;
1579 if (datum == error_mark_node)
1580 return error_mark_node;
1582 dtype = TREE_TYPE (datum);
1583 if (TREE_CODE (dtype) == REFERENCE_TYPE)
1584 dtype = TREE_TYPE (dtype);
1585 if (! IS_AGGR_TYPE_CODE (TREE_CODE (dtype)))
1587 cp_error ("request for member `%T::%D' in expression of non-aggregate type `%T'",
1588 basetype, field, dtype);
1589 return error_mark_node;
1591 else if (IS_SIGNATURE (basetype))
1593 warning ("signature name in scope resolution ignored");
1594 return build_component_ref (datum, field, NULL_TREE, 1);
1596 else if (is_aggr_type (basetype, 1))
1598 tree binfo = binfo_or_else (basetype, dtype);
1600 return build_component_ref (build_scoped_ref (datum, basetype),
1603 return error_mark_node;
1606 /* Like `build_component_ref, but uses an already found field.
1607 Must compute access for C_C_D. Otherwise, ok. */
1609 build_component_ref_1 (datum, field, protect)
1613 register tree basetype = TREE_TYPE (datum);
1614 register enum tree_code code = TREE_CODE (basetype);
1617 if (code == REFERENCE_TYPE)
1619 datum = convert_from_reference (datum);
1620 basetype = TREE_TYPE (datum);
1621 code = TREE_CODE (basetype);
1624 if (! IS_AGGR_TYPE_CODE (code))
1626 if (code != ERROR_MARK)
1627 cp_error ("request for member `%D' in `%E', which is of non-aggregate type `%T'",
1628 field, datum, basetype);
1629 return error_mark_node;
1632 if (TYPE_SIZE (basetype) == 0)
1634 incomplete_type_error (0, basetype);
1635 return error_mark_node;
1638 /* Look up component name in the structure type definition. */
1640 if (field == error_mark_node)
1641 my_friendly_abort (115);
1643 if (TREE_STATIC (field))
1648 tree access = compute_access (TYPE_BINFO (current_class_type), field);
1650 if (access == access_private_node)
1652 cp_error ("field `%D' is private", field);
1653 return error_mark_node;
1655 else if (access == access_protected_node)
1657 cp_error ("field `%D' is protected", field);
1658 return error_mark_node;
1662 ref = build (COMPONENT_REF, TREE_TYPE (field), datum, field);
1664 if (TREE_READONLY (datum) || TREE_READONLY (field))
1665 TREE_READONLY (ref) = 1;
1666 if (TREE_THIS_VOLATILE (datum) || TREE_THIS_VOLATILE (field))
1667 TREE_THIS_VOLATILE (ref) = 1;
1668 if (DECL_MUTABLE_P (field))
1669 TREE_READONLY (ref) = 0;
1674 /* Given a COND_EXPR in T, return it in a form that we can, for
1675 example, use as an lvalue. This code used to be in unary_complex_lvalue,
1676 but we needed it to deal with `a = (d == c) ? b : c' expressions, where
1677 we're dealing with aggregates. So, we now call this in unary_complex_lvalue,
1678 and in build_modify_expr. The case (in particular) that led to this was
1679 with CODE == ADDR_EXPR, since it's not an lvalue when we'd get it there. */
1681 rationalize_conditional_expr (code, t)
1682 enum tree_code code;
1686 build_conditional_expr (TREE_OPERAND (t, 0),
1687 build_unary_op (code, TREE_OPERAND (t, 1), 0),
1688 build_unary_op (code, TREE_OPERAND (t, 2), 0));
1691 /* Given the TYPE of an anonymous union field inside T, return the
1692 FIELD_DECL for the field. If not found return NULL_TREE. Because
1693 anonymous unions can nest, we must also search all anonymous unions
1694 that are directly reachable. */
1696 lookup_anon_field (t, type)
1701 for (field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
1703 if (TREE_STATIC (field))
1705 if (TREE_CODE (field) != FIELD_DECL)
1708 /* If we find it directly, return the field. */
1709 if (DECL_NAME (field) == NULL_TREE
1710 && type == TREE_TYPE (field))
1715 /* Otherwise, it could be nested, search harder. */
1716 if (DECL_NAME (field) == NULL_TREE
1717 && TREE_CODE (TREE_TYPE (field)) == UNION_TYPE)
1719 tree subfield = lookup_anon_field (TREE_TYPE (field), type);
1727 /* Build a COMPONENT_REF for a given DATUM, and it's member COMPONENT.
1728 COMPONENT can be an IDENTIFIER_NODE that is the name of the member
1729 that we are interested in, or it can be a FIELD_DECL. */
1731 build_component_ref (datum, component, basetype_path, protect)
1732 tree datum, component, basetype_path;
1735 register tree basetype = TREE_TYPE (datum);
1736 register enum tree_code code;
1737 register tree field = NULL;
1740 if (current_template_parms)
1741 return build_min_nt (COMPONENT_REF, datum, component);
1743 /* If DATUM is a COMPOUND_EXPR or COND_EXPR, move our reference inside it. */
1744 switch (TREE_CODE (datum))
1748 tree value = build_component_ref (TREE_OPERAND (datum, 1), component,
1749 basetype_path, protect);
1750 return build (COMPOUND_EXPR, TREE_TYPE (value),
1751 TREE_OPERAND (datum, 0), value);
1754 return build_conditional_expr
1755 (TREE_OPERAND (datum, 0),
1756 build_component_ref (TREE_OPERAND (datum, 1), component,
1757 basetype_path, protect),
1758 build_component_ref (TREE_OPERAND (datum, 2), component,
1759 basetype_path, protect));
1762 code = TREE_CODE (basetype);
1764 if (code == REFERENCE_TYPE)
1766 datum = convert_from_reference (datum);
1767 basetype = TREE_TYPE (datum);
1768 code = TREE_CODE (basetype);
1771 /* First, see if there is a field or component with name COMPONENT. */
1772 if (TREE_CODE (component) == TREE_LIST)
1774 my_friendly_assert (!(TREE_CHAIN (component) == NULL_TREE
1775 && DECL_CHAIN (TREE_VALUE (component)) == NULL_TREE), 309);
1776 return build (COMPONENT_REF, TREE_TYPE (component), datum, component);
1779 if (! IS_AGGR_TYPE_CODE (code))
1781 if (code != ERROR_MARK)
1782 cp_error ("request for member `%D' in `%E', which is of non-aggregate type `%T'",
1783 component, datum, basetype);
1784 return error_mark_node;
1787 if (TYPE_SIZE (complete_type (basetype)) == 0)
1789 incomplete_type_error (0, basetype);
1790 return error_mark_node;
1793 if (TREE_CODE (component) == BIT_NOT_EXPR)
1795 if (TYPE_IDENTIFIER (basetype) != TREE_OPERAND (component, 0))
1797 cp_error ("destructor specifier `%T::~%T' must have matching names",
1798 basetype, TREE_OPERAND (component, 0));
1799 return error_mark_node;
1801 if (! TYPE_HAS_DESTRUCTOR (basetype))
1803 cp_error ("type `%T' has no destructor", basetype);
1804 return error_mark_node;
1806 return TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (basetype), 0);
1809 /* Look up component name in the structure type definition. */
1810 if (CLASSTYPE_VFIELD (basetype)
1811 && DECL_NAME (CLASSTYPE_VFIELD (basetype)) == component)
1812 /* Special-case this because if we use normal lookups in an ambiguous
1813 hierarchy, the compiler will abort (because vptr lookups are
1814 not supposed to be ambiguous. */
1815 field = CLASSTYPE_VFIELD (basetype);
1816 else if (TREE_CODE (component) == FIELD_DECL)
1822 if (basetype_path == NULL_TREE)
1823 basetype_path = TYPE_BINFO (basetype);
1824 field = lookup_field (basetype_path, component,
1825 protect && ! VFIELD_NAME_P (component), 0);
1826 if (field == error_mark_node)
1827 return error_mark_node;
1829 if (field == NULL_TREE)
1831 /* Not found as a data field, look for it as a method. If found,
1832 then if this is the only possible one, return it, else
1833 report ambiguity error. */
1834 tree fndecls = lookup_fnfields (basetype_path, component, 1);
1835 if (fndecls == error_mark_node)
1836 return error_mark_node;
1839 if (TREE_CHAIN (fndecls) == NULL_TREE
1840 && DECL_CHAIN (TREE_VALUE (fndecls)) == NULL_TREE)
1842 tree access, fndecl;
1844 /* Unique, so use this one now. */
1845 basetype = TREE_PURPOSE (fndecls);
1846 fndecl = TREE_VALUE (fndecls);
1847 access = compute_access (TREE_PURPOSE (fndecls), fndecl);
1848 if (access == access_public_node)
1850 if (DECL_VINDEX (fndecl)
1851 && ! resolves_to_fixed_type_p (datum, 0))
1853 tree addr = build_unary_op (ADDR_EXPR, datum, 0);
1854 addr = convert_pointer_to (DECL_CONTEXT (fndecl), addr);
1855 datum = build_indirect_ref (addr, NULL_PTR);
1856 my_friendly_assert (datum != error_mark_node, 310);
1857 fndecl = build_vfn_ref (&addr, datum, DECL_VINDEX (fndecl));
1862 if (access == access_protected_node)
1863 cp_error ("member function `%D' is protected", fndecl);
1865 cp_error ("member function `%D' is private", fndecl);
1866 return error_mark_node;
1870 /* Just act like build_offset_ref, since the object does
1871 not matter unless we're actually calling the function. */
1874 t = build_tree_list (error_mark_node, fndecls);
1875 TREE_TYPE (t) = build_offset_type (basetype,
1881 cp_error ("`%#T' has no member named `%D'", basetype, component);
1882 return error_mark_node;
1884 else if (TREE_TYPE (field) == error_mark_node)
1885 return error_mark_node;
1887 if (TREE_CODE (field) != FIELD_DECL)
1889 if (TREE_CODE (field) == TYPE_DECL)
1891 cp_error ("invalid use of type decl `%#D' as expression", field);
1892 return error_mark_node;
1894 else if (DECL_RTL (field) != 0)
1897 TREE_USED (field) = 1;
1902 /* See if we have to do any conversions so that we pick up the field from the
1904 if (DECL_FIELD_CONTEXT (field) != basetype)
1906 tree context = DECL_FIELD_CONTEXT (field);
1907 tree base = context;
1908 while (base != basetype && ANON_AGGRNAME_P (TYPE_IDENTIFIER (base)))
1910 base = TYPE_CONTEXT (base);
1913 /* Handle base classes here... */
1914 if (base != basetype && TYPE_USES_COMPLEX_INHERITANCE (basetype))
1916 tree addr = build_unary_op (ADDR_EXPR, datum, 0);
1917 if (integer_zerop (addr))
1919 error ("invalid reference to NULL ptr, use ptr-to-member instead");
1920 return error_mark_node;
1922 if (VBASE_NAME_P (DECL_NAME (field)))
1924 /* It doesn't matter which vbase pointer we grab, just
1925 find one of them. */
1926 tree binfo = get_binfo (base,
1927 TREE_TYPE (TREE_TYPE (addr)), 0);
1928 addr = convert_pointer_to_real (binfo, addr);
1931 addr = convert_pointer_to (base, addr);
1932 datum = build_indirect_ref (addr, NULL_PTR);
1933 my_friendly_assert (datum != error_mark_node, 311);
1937 /* Handle things from anon unions here... */
1938 if (ANON_AGGRNAME_P (TYPE_IDENTIFIER (context)))
1940 tree subfield = lookup_anon_field (basetype, context);
1941 tree subdatum = build_component_ref (datum, subfield,
1942 basetype_path, protect);
1943 return build_component_ref (subdatum, field, basetype_path, protect);
1947 ref = fold (build (COMPONENT_REF, TREE_TYPE (field),
1948 break_out_cleanups (datum), field));
1950 if (TREE_READONLY (datum) || TREE_READONLY (field))
1951 TREE_READONLY (ref) = 1;
1952 if (TREE_THIS_VOLATILE (datum) || TREE_THIS_VOLATILE (field))
1953 TREE_THIS_VOLATILE (ref) = 1;
1954 if (DECL_MUTABLE_P (field))
1955 TREE_READONLY (ref) = 0;
1960 /* Given an expression PTR for a pointer, return an expression
1961 for the value pointed to.
1962 ERRORSTRING is the name of the operator to appear in error messages.
1964 This function may need to overload OPERATOR_FNNAME.
1965 Must also handle REFERENCE_TYPEs for C++. */
1968 build_x_indirect_ref (ptr, errorstring)
1974 if (current_template_parms)
1975 return build_min_nt (INDIRECT_REF, ptr);
1977 rval = build_opfncall (INDIRECT_REF, LOOKUP_NORMAL, ptr, NULL_TREE, NULL_TREE);
1980 return build_indirect_ref (ptr, errorstring);
1984 build_indirect_ref (ptr, errorstring)
1988 register tree pointer = (TREE_CODE (TREE_TYPE (ptr)) == REFERENCE_TYPE ?
1989 ptr : default_conversion (ptr));
1990 register tree type = TREE_TYPE (pointer);
1992 if (ptr == current_class_decl)
1995 if (IS_AGGR_TYPE (type))
1997 ptr = build_expr_type_conversion (WANT_POINTER, pointer, 1);
2002 type = TREE_TYPE (pointer);
2006 if (TREE_CODE (type) == POINTER_TYPE || TREE_CODE (type) == REFERENCE_TYPE)
2008 if (TREE_CODE (pointer) == ADDR_EXPR
2009 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (pointer, 0)))
2010 == TYPE_MAIN_VARIANT (TREE_TYPE (type)))
2011 && (TREE_READONLY (TREE_OPERAND (pointer, 0))
2012 == TYPE_READONLY (TREE_TYPE (type)))
2013 && (TREE_THIS_VOLATILE (TREE_OPERAND (pointer, 0))
2014 == TYPE_VOLATILE (TREE_TYPE (type))))
2015 return TREE_OPERAND (pointer, 0);
2018 tree t = TREE_TYPE (type);
2019 register tree ref = build1 (INDIRECT_REF,
2020 TYPE_MAIN_VARIANT (t), pointer);
2022 TREE_READONLY (ref) = TYPE_READONLY (t);
2023 TREE_THIS_VOLATILE (ref) = TYPE_VOLATILE (t);
2024 TREE_SIDE_EFFECTS (ref)
2025 = TYPE_VOLATILE (t) || TREE_SIDE_EFFECTS (pointer);
2029 /* `pointer' won't be an error_mark_node if we were given a
2030 pointer to member, so it's cool to check for this here. */
2031 else if (TYPE_PTRMEMFUNC_P (type))
2032 error ("invalid use of `%s' on pointer to member function", errorstring);
2033 else if (TREE_CODE (type) == RECORD_TYPE
2034 && (IS_SIGNATURE_POINTER (type) || IS_SIGNATURE_REFERENCE (type)))
2035 error ("cannot dereference signature pointer/reference");
2036 else if (pointer != error_mark_node)
2039 error ("invalid type argument of `%s'", errorstring);
2041 error ("invalid type argument");
2043 return error_mark_node;
2046 /* This handles expressions of the form "a[i]", which denotes
2049 This is logically equivalent in C to *(a+i), but we may do it differently.
2050 If A is a variable or a member, we generate a primitive ARRAY_REF.
2051 This avoids forcing the array out of registers, and can work on
2052 arrays that are not lvalues (for example, members of structures returned
2055 If INDEX is of some user-defined type, it must be converted to
2056 integer type. Otherwise, to make a compatible PLUS_EXPR, it
2057 will inherit the type of the array, which will be some pointer type. */
2060 build_x_array_ref (array, index)
2063 tree rval = build_opfncall (ARRAY_REF, LOOKUP_NORMAL, array, index, NULL_TREE);
2066 return build_array_ref (array, index);
2070 build_array_ref (array, idx)
2075 error ("subscript missing in array reference");
2076 return error_mark_node;
2079 if (TREE_TYPE (array) == error_mark_node
2080 || TREE_TYPE (idx) == error_mark_node)
2081 return error_mark_node;
2083 if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE
2084 && TREE_CODE (array) != INDIRECT_REF)
2088 /* Subscripting with type char is likely to lose
2089 on a machine where chars are signed.
2090 So warn on any machine, but optionally.
2091 Don't warn for unsigned char since that type is safe.
2092 Don't warn for signed char because anyone who uses that
2093 must have done so deliberately. */
2094 if (warn_char_subscripts
2095 && TYPE_MAIN_VARIANT (TREE_TYPE (idx)) == char_type_node)
2096 warning ("array subscript has type `char'");
2098 /* Apply default promotions *after* noticing character types. */
2099 idx = default_conversion (idx);
2101 if (TREE_CODE (TREE_TYPE (idx)) != INTEGER_TYPE)
2103 error ("array subscript is not an integer");
2104 return error_mark_node;
2107 /* An array that is indexed by a non-constant
2108 cannot be stored in a register; we must be able to do
2109 address arithmetic on its address.
2110 Likewise an array of elements of variable size. */
2111 if (TREE_CODE (idx) != INTEGER_CST
2112 || (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array))) != 0
2113 && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array)))) != INTEGER_CST))
2115 if (mark_addressable (array) == 0)
2116 return error_mark_node;
2118 /* An array that is indexed by a constant value which is not within
2119 the array bounds cannot be stored in a register either; because we
2120 would get a crash in store_bit_field/extract_bit_field when trying
2121 to access a non-existent part of the register. */
2122 if (TREE_CODE (idx) == INTEGER_CST
2123 && TYPE_VALUES (TREE_TYPE (array))
2124 && ! int_fits_type_p (idx, TYPE_VALUES (TREE_TYPE (array))))
2126 if (mark_addressable (array) == 0)
2127 return error_mark_node;
2130 if (pedantic && !lvalue_p (array))
2131 pedwarn ("ANSI C++ forbids subscripting non-lvalue array");
2133 /* Note in C++ it is valid to subscript a `register' array, since
2134 it is valid to take the address of something with that
2135 storage specification. */
2139 while (TREE_CODE (foo) == COMPONENT_REF)
2140 foo = TREE_OPERAND (foo, 0);
2141 if (TREE_CODE (foo) == VAR_DECL && DECL_REGISTER (foo))
2142 warning ("subscripting array declared `register'");
2145 type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (array)));
2146 rval = build (ARRAY_REF, type, array, idx);
2147 /* Array ref is const/volatile if the array elements are
2148 or if the array is.. */
2149 TREE_READONLY (rval)
2150 |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array)))
2151 | TREE_READONLY (array));
2152 TREE_SIDE_EFFECTS (rval)
2153 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
2154 | TREE_SIDE_EFFECTS (array));
2155 TREE_THIS_VOLATILE (rval)
2156 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
2157 /* This was added by rms on 16 Nov 91.
2158 It fixes vol struct foo *a; a->elts[1]
2159 in an inline function.
2160 Hope it doesn't break something else. */
2161 | TREE_THIS_VOLATILE (array));
2162 return require_complete_type (fold (rval));
2166 tree ar = default_conversion (array);
2167 tree ind = default_conversion (idx);
2169 /* Put the integer in IND to simplify error checking. */
2170 if (TREE_CODE (TREE_TYPE (ar)) == INTEGER_TYPE)
2177 if (ar == error_mark_node)
2180 if (TREE_CODE (TREE_TYPE (ar)) != POINTER_TYPE)
2182 error ("subscripted value is neither array nor pointer");
2183 return error_mark_node;
2185 if (TREE_CODE (TREE_TYPE (ind)) != INTEGER_TYPE)
2187 error ("array subscript is not an integer");
2188 return error_mark_node;
2191 return build_indirect_ref (build_binary_op_nodefault (PLUS_EXPR, ar, ind, PLUS_EXPR),
2196 /* Build a function call to function FUNCTION with parameters PARAMS.
2197 PARAMS is a list--a chain of TREE_LIST nodes--in which the
2198 TREE_VALUE of each node is a parameter-expression.
2199 FUNCTION's data type may be a function type or a pointer-to-function.
2201 For C++: If FUNCTION's data type is a TREE_LIST, then the tree list
2202 is the list of possible methods that FUNCTION could conceivably
2203 be. If the list of methods comes from a class, then it will be
2204 a list of lists (where each element is associated with the class
2205 that produced it), otherwise it will be a simple list (for
2206 functions overloaded in global scope).
2208 In the first case, TREE_VALUE (function) is the head of one of those
2209 lists, and TREE_PURPOSE is the name of the function.
2211 In the second case, TREE_PURPOSE (function) is the function's
2214 DECL is the class instance variable, usually CURRENT_CLASS_DECL. */
2217 * [eichin:19911015.1726EST] actually return a possibly incomplete
2221 build_x_function_call (function, params, decl)
2222 tree function, params, decl;
2227 if (function == error_mark_node)
2228 return error_mark_node;
2230 if (current_template_parms)
2231 return build_min_nt (CALL_EXPR, function, params, 0);
2233 type = TREE_TYPE (function);
2234 is_method = ((TREE_CODE (function) == TREE_LIST
2235 && current_class_type != NULL_TREE
2236 && IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (function)) == function)
2237 || TREE_CODE (function) == IDENTIFIER_NODE
2238 || TREE_CODE (type) == METHOD_TYPE
2239 || TYPE_PTRMEMFUNC_P (type));
2241 /* Handle methods, friends, and overloaded functions, respectively. */
2244 if (TREE_CODE (function) == FUNCTION_DECL)
2246 if (DECL_NAME (function))
2247 function = DECL_NAME (function);
2249 function = TYPE_IDENTIFIER (DECL_CLASS_CONTEXT (function));
2251 else if (TREE_CODE (function) == TREE_LIST)
2253 my_friendly_assert (TREE_CODE (TREE_VALUE (function)) == FUNCTION_DECL, 312);
2254 function = TREE_PURPOSE (function);
2256 else if (TREE_CODE (function) != IDENTIFIER_NODE)
2258 if (TREE_CODE (function) == OFFSET_REF)
2260 if (TREE_OPERAND (function, 0))
2261 decl = TREE_OPERAND (function, 0);
2263 /* Call via a pointer to member function. */
2264 if (decl == NULL_TREE)
2266 error ("pointer to member function called, but not in class scope");
2267 return error_mark_node;
2269 /* What other type of POINTER_TYPE could this be? */
2270 if (TREE_CODE (TREE_TYPE (function)) != POINTER_TYPE
2271 && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (function))
2272 && TREE_CODE (function) != OFFSET_REF)
2273 function = build (OFFSET_REF, TREE_TYPE (type), NULL_TREE, function);
2277 /* this is an abbreviated method call.
2278 must go through here in case it is a virtual function.
2279 @@ Perhaps this could be optimized. */
2281 if (decl == NULL_TREE)
2283 if (current_class_type == NULL_TREE)
2285 error ("object missing in call to method `%s'",
2286 IDENTIFIER_POINTER (function));
2287 return error_mark_node;
2289 /* Yow: call from a static member function. */
2290 decl = build1 (NOP_EXPR, build_pointer_type (current_class_type),
2292 decl = build_indirect_ref (decl, NULL_PTR);
2295 return build_method_call (decl, function, params,
2296 NULL_TREE, LOOKUP_NORMAL);
2298 else if (TREE_CODE (function) == COMPONENT_REF
2299 && type == unknown_type_node)
2301 /* Should we undo what was done in build_component_ref? */
2302 if (TREE_CODE (TREE_PURPOSE (TREE_OPERAND (function, 1))) == TREE_VEC)
2303 /* Get the name that build_component_ref hid. */
2304 function = DECL_NAME (TREE_VALUE (TREE_OPERAND (function, 1)));
2306 function = TREE_PURPOSE (TREE_OPERAND (function, 1));
2307 return build_method_call (decl, function, params,
2308 NULL_TREE, LOOKUP_NORMAL);
2310 else if (TREE_CODE (function) == TREE_LIST)
2312 if (TREE_VALUE (function) == NULL_TREE)
2314 cp_error ("function `%D' declared overloaded, but no definitions appear with which to resolve it?!?",
2315 TREE_PURPOSE (function));
2316 return error_mark_node;
2320 tree val = TREE_VALUE (function);
2322 if (TREE_CODE (val) == TEMPLATE_DECL)
2323 return build_overload_call_maybe
2324 (function, params, LOOKUP_COMPLAIN, (struct candidate *)0);
2325 else if (DECL_CHAIN (val) != NULL_TREE)
2326 return build_overload_call
2327 (function, params, LOOKUP_COMPLAIN, (struct candidate *)0);
2329 my_friendly_abort (360);
2334 if (TREE_CODE (function) == OFFSET_REF)
2336 /* If the component is a data element (or a virtual function), we play
2337 games here to make things work. */
2340 if (TREE_OPERAND (function, 0))
2341 decl = TREE_OPERAND (function, 0);
2345 decl_addr = build_unary_op (ADDR_EXPR, decl, 0);
2346 function = get_member_function_from_ptrfunc (&decl_addr,
2347 TREE_OPERAND (function, 1));
2348 params = tree_cons (NULL_TREE, decl_addr, params);
2349 return build_function_call (function, params);
2352 type = TREE_TYPE (function);
2353 if (type != error_mark_node)
2355 if (TREE_CODE (type) == REFERENCE_TYPE)
2356 type = TREE_TYPE (type);
2358 if (TYPE_LANG_SPECIFIC (type)
2359 && TYPE_OVERLOADS_CALL_EXPR (complete_type (type)))
2360 return build_opfncall (CALL_EXPR, LOOKUP_NORMAL, function, params, NULL_TREE);
2365 tree fntype = TREE_TYPE (function);
2368 /* Explicitly named method? */
2369 if (TREE_CODE (function) == FUNCTION_DECL)
2370 ctypeptr = build_pointer_type (DECL_CLASS_CONTEXT (function));
2371 /* Expression with ptr-to-method type? It could either be a plain
2372 usage, or it might be a case where the ptr-to-method is being
2373 passed in as an argument. */
2374 else if (TYPE_PTRMEMFUNC_P (fntype))
2376 tree rec = TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (fntype)));
2377 ctypeptr = build_pointer_type (rec);
2379 /* Unexpected node type? */
2381 my_friendly_abort (116);
2382 if (decl == NULL_TREE)
2384 if (current_function_decl
2385 && DECL_STATIC_FUNCTION_P (current_function_decl))
2386 error ("invalid call to member function needing `this' in static member function scope");
2388 error ("pointer to member function called, but not in class scope");
2389 return error_mark_node;
2391 if (TREE_CODE (TREE_TYPE (decl)) != POINTER_TYPE
2392 && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (decl)))
2394 decl = build_unary_op (ADDR_EXPR, decl, 0);
2395 decl = convert_pointer_to (TREE_TYPE (ctypeptr), decl);
2398 decl = build_c_cast (ctypeptr, decl, 0);
2399 params = tree_cons (NULL_TREE, decl, params);
2402 return build_function_call (function, params);
2405 /* Resolve a pointer to member function. INSTANCE is the object
2406 instance to use, if the member points to a virtual member. */
2409 get_member_function_from_ptrfunc (instance_ptrptr, function)
2410 tree *instance_ptrptr;
2413 if (TREE_CODE (function) == OFFSET_REF)
2415 function = TREE_OPERAND (function, 1);
2418 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (function)))
2420 tree fntype, index, e1, delta, delta2, e2, e3, aref, vtbl;
2423 tree instance_ptr = *instance_ptrptr;
2425 if (TREE_SIDE_EFFECTS (instance_ptr))
2426 instance_ptr = save_expr (instance_ptr);
2428 if (TREE_SIDE_EFFECTS (function))
2429 function = save_expr (function);
2431 fntype = TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (function));
2432 index = save_expr (build_component_ref (function,
2435 e1 = build (GT_EXPR, boolean_type_node, index,
2436 convert (delta_type_node, integer_zero_node));
2437 delta = convert (ptrdiff_type_node,
2438 build_component_ref (function, delta_identifier, 0, 0));
2439 delta2 = DELTA2_FROM_PTRMEMFUNC (function);
2441 /* convert down to the right base, before using the instance. */
2443 = convert_pointer_to_real (TYPE_METHOD_BASETYPE (TREE_TYPE (fntype)),
2445 if (instance == error_mark_node)
2448 vtbl = convert_pointer_to (ptr_type_node, instance);
2451 build_pointer_type (build_pointer_type (vtable_entry_type)),
2452 vtbl, convert (ptrdiff_type_node, delta2));
2453 vtbl = build_indirect_ref (vtbl, NULL_PTR);
2454 aref = build_array_ref (vtbl, build_binary_op (MINUS_EXPR,
2456 integer_one_node, 1));
2457 if (! flag_vtable_thunks)
2459 aref = save_expr (aref);
2461 /* Save the intermediate result in a SAVE_EXPR so we don't have to
2462 compute each component of the virtual function pointer twice. */
2463 if (TREE_CODE (aref) == INDIRECT_REF)
2464 TREE_OPERAND (aref, 0) = save_expr (TREE_OPERAND (aref, 0));
2466 delta = build_binary_op (PLUS_EXPR,
2467 build_conditional_expr (e1, build_component_ref (aref, delta_identifier, 0, 0), integer_zero_node),
2471 *instance_ptrptr = build (PLUS_EXPR, TREE_TYPE (instance_ptr),
2472 instance_ptr, delta);
2473 if (flag_vtable_thunks)
2476 e2 = build_component_ref (aref, pfn_identifier, 0, 0);
2478 e3 = PFN_FROM_PTRMEMFUNC (function);
2479 TREE_TYPE (e2) = TREE_TYPE (e3);
2480 function = build_conditional_expr (e1, e2, e3);
2482 /* Make sure this doesn't get evaluated first inside one of the
2483 branches of the COND_EXPR. */
2484 if (TREE_CODE (instance_ptr) == SAVE_EXPR)
2485 function = build (COMPOUND_EXPR, TREE_TYPE (function),
2486 instance_ptr, function);
2492 build_function_call_real (function, params, require_complete, flags)
2493 tree function, params;
2494 int require_complete, flags;
2496 register tree fntype, fndecl;
2497 register tree value_type;
2498 register tree coerced_params;
2499 tree name = NULL_TREE, assembler_name = NULL_TREE;
2502 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
2503 Strip such NOP_EXPRs, since FUNCTION is used in non-lvalue context. */
2504 if (TREE_CODE (function) == NOP_EXPR
2505 && TREE_TYPE (function) == TREE_TYPE (TREE_OPERAND (function, 0)))
2506 function = TREE_OPERAND (function, 0);
2508 if (TREE_CODE (function) == FUNCTION_DECL)
2510 name = DECL_NAME (function);
2511 assembler_name = DECL_ASSEMBLER_NAME (function);
2513 GNU_xref_call (current_function_decl,
2514 IDENTIFIER_POINTER (name ? name
2515 : TYPE_IDENTIFIER (DECL_CLASS_CONTEXT (function))));
2516 mark_used (function);
2519 /* Convert anything with function type to a pointer-to-function. */
2522 && IDENTIFIER_LENGTH (name) == 4
2523 && ! strcmp (IDENTIFIER_POINTER (name), "main")
2524 && DECL_CONTEXT (function) == NULL_TREE)
2526 pedwarn ("ANSI C++ forbids calling `main' from within program");
2529 if (pedantic && DECL_THIS_INLINE (function) && ! DECL_INITIAL (function)
2530 && ! DECL_ARTIFICIAL (function)
2531 && ! DECL_PENDING_INLINE_INFO (function))
2532 cp_pedwarn ("inline function `%#D' called before definition",
2535 /* Differs from default_conversion by not setting TREE_ADDRESSABLE
2536 (because calling an inline function does not mean the function
2537 needs to be separately compiled). */
2539 if (DECL_INLINE (function))
2541 /* Is it a synthesized method that needs to be synthesized? */
2542 if (DECL_ARTIFICIAL (function) && ! DECL_INITIAL (function)
2543 /* Kludge: don't synthesize for default args. */
2544 && current_function_decl)
2545 synthesize_method (function);
2547 fntype = build_type_variant (TREE_TYPE (function),
2548 TREE_READONLY (function),
2549 TREE_THIS_VOLATILE (function));
2550 function = build1 (ADDR_EXPR, build_pointer_type (fntype), function);
2553 function = default_conversion (function);
2559 /* Convert anything with function type to a pointer-to-function. */
2560 if (function == error_mark_node)
2561 return error_mark_node;
2562 function = default_conversion (function);
2565 fntype = TREE_TYPE (function);
2567 if (TYPE_PTRMEMFUNC_P (fntype))
2569 tree instance_ptr = build_unary_op (ADDR_EXPR, C_C_D, 0);
2570 fntype = TYPE_PTRMEMFUNC_FN_TYPE (fntype);
2571 function = get_member_function_from_ptrfunc (&instance_ptr, function);
2574 is_method = (TREE_CODE (fntype) == POINTER_TYPE
2575 && TREE_CODE (TREE_TYPE (fntype)) == METHOD_TYPE);
2577 if (!((TREE_CODE (fntype) == POINTER_TYPE
2578 && TREE_CODE (TREE_TYPE (fntype)) == FUNCTION_TYPE)
2581 cp_error ("`%E' cannot be used as a function", function);
2582 return error_mark_node;
2585 /* fntype now gets the type of function pointed to. */
2586 fntype = TREE_TYPE (fntype);
2588 /* Convert the parameters to the types declared in the
2589 function prototype, or apply default promotions. */
2591 if (flags & LOOKUP_COMPLAIN)
2592 coerced_params = convert_arguments (NULL_TREE, TYPE_ARG_TYPES (fntype),
2593 params, fndecl, LOOKUP_NORMAL);
2595 coerced_params = convert_arguments (NULL_TREE, TYPE_ARG_TYPES (fntype),
2598 if (coerced_params == error_mark_node)
2599 if (flags & LOOKUP_SPECULATIVELY)
2602 return error_mark_node;
2604 /* Check for errors in format strings. */
2606 if (warn_format && (name || assembler_name))
2607 check_function_format (name, assembler_name, coerced_params);
2609 /* Recognize certain built-in functions so we can make tree-codes
2610 other than CALL_EXPR. We do this when it enables fold-const.c
2611 to do something useful. */
2613 if (TREE_CODE (function) == ADDR_EXPR
2614 && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL
2615 && DECL_BUILT_IN (TREE_OPERAND (function, 0)))
2616 switch (DECL_FUNCTION_CODE (TREE_OPERAND (function, 0)))
2621 if (coerced_params == 0)
2622 return integer_zero_node;
2623 return build_unary_op (ABS_EXPR, TREE_VALUE (coerced_params), 0);
2627 value_type = TREE_TYPE (fntype) ? TREE_TYPE (fntype) : void_type_node;
2629 register tree result =
2630 build (CALL_EXPR, value_type,
2631 function, coerced_params, NULL_TREE);
2633 TREE_SIDE_EFFECTS (result) = 1;
2635 if (! require_complete)
2636 return convert_from_reference (result);
2637 if (value_type == void_type_node)
2639 result = require_complete_type (result);
2640 return convert_from_reference (result);
2645 build_function_call (function, params)
2646 tree function, params;
2648 return build_function_call_real (function, params, 1, LOOKUP_NORMAL);
2651 /* Convert the actual parameter expressions in the list VALUES
2652 to the types in the list TYPELIST.
2653 If parmdecls is exhausted, or when an element has NULL as its type,
2654 perform the default conversions.
2656 RETURN_LOC is the location of the return value, if known, NULL_TREE
2657 otherwise. This is useful in the case where we can avoid creating
2658 a temporary variable in the case where we can initialize the return
2659 value directly. If we are not eliding constructors, then we set this
2660 to NULL_TREE to avoid this avoidance.
2662 NAME is an IDENTIFIER_NODE or 0. It is used only for error messages.
2664 This is also where warnings about wrong number of args are generated.
2666 Return a list of expressions for the parameters as converted.
2668 Both VALUES and the returned value are chains of TREE_LIST nodes
2669 with the elements of the list in the TREE_VALUE slots of those nodes.
2671 In C++, unspecified trailing parameters can be filled in with their
2672 default arguments, if such were specified. Do so here. */
2675 convert_arguments (return_loc, typelist, values, fndecl, flags)
2676 tree return_loc, typelist, values, fndecl;
2679 register tree typetail, valtail;
2680 register tree result = NULL_TREE;
2684 if (! flag_elide_constructors)
2689 if (TREE_CODE (TREE_TYPE (fndecl)) == METHOD_TYPE)
2691 if (DECL_NAME (fndecl) == NULL_TREE
2692 || IDENTIFIER_HAS_TYPE_VALUE (DECL_NAME (fndecl)))
2693 called_thing = "constructor";
2695 called_thing = "member function";
2698 called_thing = "function";
2701 for (valtail = values, typetail = typelist;
2703 valtail = TREE_CHAIN (valtail), i++)
2705 register tree type = typetail ? TREE_VALUE (typetail) : 0;
2706 register tree val = TREE_VALUE (valtail);
2708 if (val == error_mark_node)
2709 return error_mark_node;
2711 if (type == void_type_node)
2715 char *buf = (char *)alloca (40 + strlen (called_thing));
2716 sprintf (buf, "too many arguments to %s `%%s'", called_thing);
2717 error_with_decl (fndecl, buf);
2718 error ("at this point in file");
2721 error ("too many arguments to function");
2722 /* In case anybody wants to know if this argument
2725 TREE_TYPE (tree_last (result)) = error_mark_node;
2729 /* The tree type of the parameter being passed may not yet be
2730 known. In this case, its type is TYPE_UNKNOWN, and will
2731 be instantiated by the type given by TYPE. If TYPE
2732 is also NULL, the tree type of VAL is ERROR_MARK_NODE. */
2733 if (type && type_unknown_p (val))
2734 val = require_instantiated_type (type, val, integer_zero_node);
2735 else if (type_unknown_p (val))
2737 /* Strip the `&' from an overloaded FUNCTION_DECL. */
2738 if (TREE_CODE (val) == ADDR_EXPR)
2739 val = TREE_OPERAND (val, 0);
2740 if (TREE_CODE (val) == TREE_LIST
2741 && TREE_CHAIN (val) == NULL_TREE
2742 && TREE_TYPE (TREE_VALUE (val)) != NULL_TREE
2743 && (TREE_TYPE (val) == unknown_type_node
2744 || DECL_CHAIN (TREE_VALUE (val)) == NULL_TREE))
2745 /* Instantiates automatically. */
2746 val = TREE_VALUE (val);
2749 error ("insufficient type information in parameter list");
2750 val = integer_zero_node;
2753 else if (TREE_CODE (val) == OFFSET_REF
2754 && TREE_CODE (TREE_TYPE (val)) == METHOD_TYPE)
2756 /* This is unclean. Should be handled elsewhere. */
2757 val = build_unary_op (ADDR_EXPR, val, 0);
2759 else if (TREE_CODE (val) == OFFSET_REF)
2760 val = resolve_offset_ref (val);
2762 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
2763 Strip such NOP_EXPRs, since VAL is used in non-lvalue context. */
2764 if (TREE_CODE (val) == NOP_EXPR
2765 && TREE_TYPE (val) == TREE_TYPE (TREE_OPERAND (val, 0))
2766 && (type == 0 || TREE_CODE (type) != REFERENCE_TYPE))
2767 val = TREE_OPERAND (val, 0);
2769 if (type == 0 || TREE_CODE (type) != REFERENCE_TYPE)
2771 if (TREE_CODE (TREE_TYPE (val)) == ARRAY_TYPE
2772 || TREE_CODE (TREE_TYPE (val)) == FUNCTION_TYPE
2773 || TREE_CODE (TREE_TYPE (val)) == METHOD_TYPE)
2774 val = default_conversion (val);
2776 val = require_complete_type (val);
2779 if (val == error_mark_node)
2780 return error_mark_node;
2784 /* Formal parm type is specified by a function prototype. */
2787 if (TYPE_SIZE (complete_type (type)) == 0)
2789 error ("parameter type of called function is incomplete");
2794 parmval = convert_for_initialization (return_loc, type, val,
2795 flags|INDIRECT_BIND,
2796 "argument passing", fndecl, i);
2797 #ifdef PROMOTE_PROTOTYPES
2798 if ((TREE_CODE (type) == INTEGER_TYPE
2799 || TREE_CODE (type) == ENUMERAL_TYPE)
2800 && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
2801 parmval = default_conversion (parmval);
2805 if (parmval == error_mark_node)
2806 return error_mark_node;
2808 result = tree_cons (NULL_TREE, parmval, result);
2812 if (TREE_CODE (TREE_TYPE (val)) == REFERENCE_TYPE)
2813 val = convert_from_reference (val);
2815 if (TREE_CODE (TREE_TYPE (val)) == REAL_TYPE
2816 && (TYPE_PRECISION (TREE_TYPE (val))
2817 < TYPE_PRECISION (double_type_node)))
2818 /* Convert `float' to `double'. */
2819 result = tree_cons (NULL_TREE, convert (double_type_node, val), result);
2820 else if (TYPE_LANG_SPECIFIC (TREE_TYPE (val))
2821 && ! TYPE_HAS_TRIVIAL_INIT_REF (TREE_TYPE (val)))
2823 cp_warning ("cannot pass objects of type `%T' through `...'",
2825 result = tree_cons (NULL_TREE, val, result);
2828 /* Convert `short' and `char' to full-size `int'. */
2829 result = tree_cons (NULL_TREE, default_conversion (val), result);
2833 typetail = TREE_CHAIN (typetail);
2836 if (typetail != 0 && typetail != void_list_node)
2838 /* See if there are default arguments that can be used */
2839 if (TREE_PURPOSE (typetail))
2841 for (; typetail != void_list_node; ++i)
2843 tree type = TREE_VALUE (typetail);
2844 tree val = break_out_target_exprs (TREE_PURPOSE (typetail));
2847 if (val == NULL_TREE)
2848 parmval = error_mark_node;
2849 else if (TREE_CODE (val) == CONSTRUCTOR)
2851 parmval = digest_init (type, val, (tree *)0);
2852 parmval = convert_for_initialization (return_loc, type, parmval, flags,
2853 "default constructor", fndecl, i);
2857 /* This could get clobbered by the following call. */
2858 if (TREE_HAS_CONSTRUCTOR (val))
2859 val = copy_node (val);
2861 parmval = convert_for_initialization (return_loc, type, val, flags,
2862 "default argument", fndecl, i);
2863 #ifdef PROMOTE_PROTOTYPES
2864 if ((TREE_CODE (type) == INTEGER_TYPE
2865 || TREE_CODE (type) == ENUMERAL_TYPE)
2866 && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
2867 parmval = default_conversion (parmval);
2871 if (parmval == error_mark_node)
2872 return error_mark_node;
2874 result = tree_cons (0, parmval, result);
2875 typetail = TREE_CHAIN (typetail);
2876 /* ends with `...'. */
2877 if (typetail == NULL_TREE)
2885 char *buf = (char *)alloca (32 + strlen (called_thing));
2886 sprintf (buf, "too few arguments to %s `%%#D'", called_thing);
2887 cp_error_at (buf, fndecl);
2888 error ("at this point in file");
2891 error ("too few arguments to function");
2892 return error_mark_list;
2896 return nreverse (result);
2899 /* Build a binary-operation expression, after performing default
2900 conversions on the operands. CODE is the kind of expression to build. */
2903 build_x_binary_op (code, arg1, arg2)
2904 enum tree_code code;
2909 if (current_template_parms)
2910 return build_min_nt (code, arg1, arg2);
2912 rval = build_opfncall (code, LOOKUP_SPECULATIVELY,
2913 arg1, arg2, NULL_TREE);
2915 return build_opfncall (code, LOOKUP_NORMAL, arg1, arg2, NULL_TREE);
2916 if (code == MEMBER_REF)
2917 return build_m_component_ref (build_indirect_ref (arg1, NULL_PTR),
2919 return build_binary_op (code, arg1, arg2, 1);
2923 build_binary_op (code, arg1, arg2, convert_p)
2924 enum tree_code code;
2936 args[0] = decay_conversion (args[0]);
2937 args[1] = decay_conversion (args[1]);
2939 if (args[0] == error_mark_node || args[1] == error_mark_node)
2940 return error_mark_node;
2942 type0 = TREE_TYPE (args[0]);
2943 type1 = TREE_TYPE (args[1]);
2945 if (type_unknown_p (args[0]))
2947 args[0] = instantiate_type (type1, args[0], 1);
2948 args[0] = decay_conversion (args[0]);
2950 else if (type_unknown_p (args[1]))
2952 args[1] = require_instantiated_type (type0, args[1],
2954 args[1] = decay_conversion (args[1]);
2957 if (IS_AGGR_TYPE (type0) || IS_AGGR_TYPE (type1))
2959 /* Try to convert this to something reasonable. */
2960 if (! build_default_binary_type_conversion(code, &args[0], &args[1]))
2962 cp_error ("no match for `%O(%#T, %#T)'", code,
2963 TREE_TYPE (arg1), TREE_TYPE (arg2));
2964 return error_mark_node;
2968 return build_binary_op_nodefault (code, args[0], args[1], code);
2971 /* Build a binary-operation expression without default conversions.
2972 CODE is the kind of expression to build.
2973 This function differs from `build' in several ways:
2974 the data type of the result is computed and recorded in it,
2975 warnings are generated if arg data types are invalid,
2976 special handling for addition and subtraction of pointers is known,
2977 and some optimization is done (operations on narrow ints
2978 are done in the narrower type when that gives the same result).
2979 Constant folding is also done before the result is returned.
2981 ERROR_CODE is the code that determines what to say in error messages.
2982 It is usually, but not always, the same as CODE.
2984 Note that the operands will never have enumeral types
2985 because either they have just had the default conversions performed
2986 or they have both just been converted to some other type in which
2987 the arithmetic is to be done.
2989 C++: must do special pointer arithmetic when implementing
2990 multiple inheritance, and deal with pointer to member functions. */
2993 build_binary_op_nodefault (code, orig_op0, orig_op1, error_code)
2994 enum tree_code code;
2995 tree orig_op0, orig_op1;
2996 enum tree_code error_code;
2999 register enum tree_code code0, code1;
3002 /* Expression code to give to the expression when it is built.
3003 Normally this is CODE, which is what the caller asked for,
3004 but in some special cases we change it. */
3005 register enum tree_code resultcode = code;
3007 /* Data type in which the computation is to be performed.
3008 In the simplest cases this is the common type of the arguments. */
3009 register tree result_type = NULL;
3011 /* Nonzero means operands have already been type-converted
3012 in whatever way is necessary.
3013 Zero means they need to be converted to RESULT_TYPE. */
3016 /* Nonzero means create the expression with this type, rather than
3018 tree build_type = 0;
3020 /* Nonzero means after finally constructing the expression
3021 convert it to this type. */
3022 tree final_type = 0;
3024 /* Nonzero if this is an operation like MIN or MAX which can
3025 safely be computed in short if both args are promoted shorts.
3026 Also implies COMMON.
3027 -1 indicates a bitwise operation; this makes a difference
3028 in the exact conditions for when it is safe to do the operation
3029 in a narrower mode. */
3032 /* Nonzero if this is a comparison operation;
3033 if both args are promoted shorts, compare the original shorts.
3034 Also implies COMMON. */
3035 int short_compare = 0;
3037 /* Nonzero if this is a right-shift operation, which can be computed on the
3038 original short and then promoted if the operand is a promoted short. */
3039 int short_shift = 0;
3041 /* Nonzero means set RESULT_TYPE to the common type of the args. */
3044 /* Apply default conversions. */
3045 if (code == TRUTH_AND_EXPR || code == TRUTH_ANDIF_EXPR
3046 || code == TRUTH_OR_EXPR || code == TRUTH_ORIF_EXPR
3047 || code == TRUTH_XOR_EXPR)
3049 op0 = decay_conversion (orig_op0);
3050 op1 = decay_conversion (orig_op1);
3054 op0 = default_conversion (orig_op0);
3055 op1 = default_conversion (orig_op1);
3058 type0 = TREE_TYPE (op0);
3059 type1 = TREE_TYPE (op1);
3061 /* The expression codes of the data types of the arguments tell us
3062 whether the arguments are integers, floating, pointers, etc. */
3063 code0 = TREE_CODE (type0);
3064 code1 = TREE_CODE (type1);
3066 /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
3067 STRIP_TYPE_NOPS (op0);
3068 STRIP_TYPE_NOPS (op1);
3070 /* If an error was already reported for one of the arguments,
3071 avoid reporting another error. */
3073 if (code0 == ERROR_MARK || code1 == ERROR_MARK)
3074 return error_mark_node;
3079 /* Handle the pointer + int case. */
3080 if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
3081 return pointer_int_sum (PLUS_EXPR, op0, op1);
3082 else if (code1 == POINTER_TYPE && code0 == INTEGER_TYPE)
3083 return pointer_int_sum (PLUS_EXPR, op1, op0);
3089 /* Subtraction of two similar pointers.
3090 We must subtract them as integers, then divide by object size. */
3091 if (code0 == POINTER_TYPE && code1 == POINTER_TYPE
3092 && comp_target_types (type0, type1, 1))
3093 return pointer_diff (op0, op1);
3094 /* Handle pointer minus int. Just like pointer plus int. */
3095 else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
3096 return pointer_int_sum (MINUS_EXPR, op0, op1);
3105 case TRUNC_DIV_EXPR:
3107 case FLOOR_DIV_EXPR:
3108 case ROUND_DIV_EXPR:
3109 case EXACT_DIV_EXPR:
3110 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
3111 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
3113 if (TREE_CODE (op1) == INTEGER_CST && integer_zerop (op1))
3114 cp_warning ("division by zero in `%E / 0'", op0);
3115 else if (TREE_CODE (op1) == REAL_CST && real_zerop (op1))
3116 cp_warning ("division by zero in `%E / 0.'", op0);
3118 if (!(code0 == INTEGER_TYPE && code1 == INTEGER_TYPE))
3119 resultcode = RDIV_EXPR;
3121 /* When dividing two signed integers, we have to promote to int.
3122 unless we divide by a constant != -1. Note that default
3123 conversion will have been performed on the operands at this
3124 point, so we have to dig out the original type to find out if
3126 shorten = ((TREE_CODE (op0) == NOP_EXPR
3127 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0, 0))))
3128 || (TREE_CODE (op1) == INTEGER_CST
3129 && (TREE_INT_CST_LOW (op1) != -1
3130 || TREE_INT_CST_HIGH (op1) != -1)));
3136 case BIT_ANDTC_EXPR:
3139 if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
3141 /* If one operand is a constant, and the other is a short type
3142 that has been converted to an int,
3143 really do the work in the short type and then convert the
3144 result to int. If we are lucky, the constant will be 0 or 1
3145 in the short type, making the entire operation go away. */
3146 if (TREE_CODE (op0) == INTEGER_CST
3147 && TREE_CODE (op1) == NOP_EXPR
3148 && TYPE_PRECISION (type1) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op1, 0)))
3149 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op1, 0))))
3151 final_type = result_type;
3152 op1 = TREE_OPERAND (op1, 0);
3153 result_type = TREE_TYPE (op1);
3155 if (TREE_CODE (op1) == INTEGER_CST
3156 && TREE_CODE (op0) == NOP_EXPR
3157 && TYPE_PRECISION (type0) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0, 0)))
3158 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0, 0))))
3160 final_type = result_type;
3161 op0 = TREE_OPERAND (op0, 0);
3162 result_type = TREE_TYPE (op0);
3166 case TRUNC_MOD_EXPR:
3167 case FLOOR_MOD_EXPR:
3168 if (code1 == INTEGER_TYPE && integer_zerop (op1))
3169 cp_warning ("division by zero in `%E % 0'", op0);
3170 else if (code1 == REAL_TYPE && real_zerop (op1))
3171 cp_warning ("division by zero in `%E % 0.'", op0);
3173 if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
3175 /* Although it would be tempting to shorten always here, that loses
3176 on some targets, since the modulo instruction is undefined if the
3177 quotient can't be represented in the computation mode. We shorten
3178 only if unsigned or if dividing by something we know != -1. */
3179 shorten = ((TREE_CODE (op0) == NOP_EXPR
3180 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0, 0))))
3181 || (TREE_CODE (op1) == INTEGER_CST
3182 && (TREE_INT_CST_LOW (op1) != -1
3183 || TREE_INT_CST_HIGH (op1) != -1)));
3188 case TRUTH_ANDIF_EXPR:
3189 case TRUTH_ORIF_EXPR:
3190 case TRUTH_AND_EXPR:
3192 result_type = boolean_type_node;
3195 /* Shift operations: result has same type as first operand;
3196 always convert second operand to int.
3197 Also set SHORT_SHIFT if shifting rightward. */
3200 if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
3202 result_type = type0;
3203 if (TREE_CODE (op1) == INTEGER_CST)
3205 if (tree_int_cst_lt (op1, integer_zero_node))
3206 warning ("right shift count is negative");
3209 if (TREE_INT_CST_LOW (op1) | TREE_INT_CST_HIGH (op1))
3211 if (TREE_INT_CST_HIGH (op1) != 0
3212 || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1)
3213 >= TYPE_PRECISION (type0)))
3214 warning ("right shift count >= width of type");
3217 /* Convert the shift-count to an integer, regardless of
3218 size of value being shifted. */
3219 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
3220 op1 = convert (integer_type_node, op1);
3221 /* Avoid converting op1 to result_type later. */
3227 if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
3229 result_type = type0;
3230 if (TREE_CODE (op1) == INTEGER_CST)
3232 if (tree_int_cst_lt (op1, integer_zero_node))
3233 warning ("left shift count is negative");
3234 else if (TREE_INT_CST_HIGH (op1) != 0
3235 || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1)
3236 >= TYPE_PRECISION (type0)))
3237 warning ("left shift count >= width of type");
3239 /* Convert the shift-count to an integer, regardless of
3240 size of value being shifted. */
3241 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
3242 op1 = convert (integer_type_node, op1);
3243 /* Avoid converting op1 to result_type later. */
3250 if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
3252 result_type = type0;
3253 if (TREE_CODE (op1) == INTEGER_CST)
3255 if (tree_int_cst_lt (op1, integer_zero_node))
3256 warning ("%s rotate count is negative",
3257 (code == LROTATE_EXPR) ? "left" : "right");
3258 else if (TREE_INT_CST_HIGH (op1) != 0
3259 || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1)
3260 >= TYPE_PRECISION (type0)))
3261 warning ("%s rotate count >= width of type",
3262 (code == LROTATE_EXPR) ? "left" : "right");
3264 /* Convert the shift-count to an integer, regardless of
3265 size of value being shifted. */
3266 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
3267 op1 = convert (integer_type_node, op1);
3273 build_type = boolean_type_node;
3274 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
3275 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
3277 else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
3279 register tree tt0 = TYPE_MAIN_VARIANT (TREE_TYPE (type0));
3280 register tree tt1 = TYPE_MAIN_VARIANT (TREE_TYPE (type1));
3282 if (comp_target_types (type0, type1, 1))
3283 result_type = common_type (type0, type1);
3284 else if (tt0 == void_type_node)
3286 if (pedantic && TREE_CODE (tt1) == FUNCTION_TYPE
3287 && tree_int_cst_lt (TYPE_SIZE (type0), TYPE_SIZE (type1)))
3288 pedwarn ("ANSI C++ forbids comparison of `void *' with function pointer");
3289 else if (TREE_CODE (tt1) == OFFSET_TYPE)
3290 pedwarn ("ANSI C++ forbids conversion of a pointer to member to `void *'");
3292 else if (tt1 == void_type_node)
3294 if (pedantic && TREE_CODE (tt0) == FUNCTION_TYPE
3295 && tree_int_cst_lt (TYPE_SIZE (type1), TYPE_SIZE (type0)))
3296 pedwarn ("ANSI C++ forbids comparison of `void *' with function pointer");
3299 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3302 if (result_type == NULL_TREE)
3303 result_type = ptr_type_node;
3305 else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST
3306 && integer_zerop (op1))
3307 result_type = type0;
3308 else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST
3309 && integer_zerop (op0))
3310 result_type = type1;
3311 else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
3313 result_type = type0;
3314 error ("ANSI C++ forbids comparison between pointer and integer");
3316 else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
3318 result_type = type1;
3319 error ("ANSI C++ forbids comparison between pointer and integer");
3321 else if (TYPE_PTRMEMFUNC_P (type0) && TREE_CODE (op1) == INTEGER_CST
3322 && integer_zerop (op1))
3324 op0 = build_component_ref (op0, index_identifier, 0, 0);
3325 op1 = integer_zero_node;
3326 result_type = TREE_TYPE (op0);
3328 else if (TYPE_PTRMEMFUNC_P (type1) && TREE_CODE (op0) == INTEGER_CST
3329 && integer_zerop (op0))
3331 op0 = build_component_ref (op1, index_identifier, 0, 0);
3332 op1 = integer_zero_node;
3333 result_type = TREE_TYPE (op0);
3335 else if (TYPE_PTRMEMFUNC_P (type0) && TYPE_PTRMEMFUNC_P (type1)
3336 && (TYPE_PTRMEMFUNC_FN_TYPE (type0)
3337 == TYPE_PTRMEMFUNC_FN_TYPE (type1)))
3339 /* The code we generate for the test is:
3341 (op0.index == op1.index
3342 && ((op1.index != -1 && op0.delta2 == op1.delta2)
3343 || op0.pfn == op1.pfn)) */
3345 tree index0 = build_component_ref (op0, index_identifier, 0, 0);
3346 tree index1 = save_expr (build_component_ref (op1, index_identifier, 0, 0));
3347 tree pfn0 = PFN_FROM_PTRMEMFUNC (op0);
3348 tree pfn1 = PFN_FROM_PTRMEMFUNC (op1);
3349 tree delta20 = DELTA2_FROM_PTRMEMFUNC (op0);
3350 tree delta21 = DELTA2_FROM_PTRMEMFUNC (op1);
3352 tree integer_neg_one_node
3353 = build_binary_op (MINUS_EXPR, integer_zero_node, integer_one_node, 1);
3354 e1 = build_binary_op (EQ_EXPR, index0, index1, 1);
3355 e2 = build_binary_op (NE_EXPR, index1, integer_neg_one_node, 1);
3356 e2 = build_binary_op (TRUTH_ANDIF_EXPR, e2, build_binary_op (EQ_EXPR, delta20, delta21, 1), 1);
3357 e3 = build_binary_op (EQ_EXPR, pfn0, pfn1, 1);
3358 e2 = build_binary_op (TRUTH_ORIF_EXPR, e2, e3, 1);
3359 e2 = build_binary_op (TRUTH_ANDIF_EXPR, e1, e2, 1);
3360 if (code == EQ_EXPR)
3362 return build_binary_op (EQ_EXPR, e2, integer_zero_node, 1);
3364 else if (TYPE_PTRMEMFUNC_P (type0)
3365 && TYPE_PTRMEMFUNC_FN_TYPE (type0) == type1)
3367 tree index0 = build_component_ref (op0, index_identifier, 0, 0);
3369 tree pfn0 = PFN_FROM_PTRMEMFUNC (op0);
3370 tree delta20 = DELTA2_FROM_PTRMEMFUNC (op0);
3371 tree delta21 = integer_zero_node;
3373 tree integer_neg_one_node
3374 = build_binary_op (MINUS_EXPR, integer_zero_node, integer_one_node, 1);
3375 if (TREE_CODE (TREE_OPERAND (op1, 0)) == FUNCTION_DECL
3376 && DECL_VINDEX (TREE_OPERAND (op1, 0)))
3378 /* Map everything down one to make room for the null pointer to member. */
3379 index1 = size_binop (PLUS_EXPR,
3380 DECL_VINDEX (TREE_OPERAND (op1, 0)),
3382 op1 = integer_zero_node;
3383 delta21 = CLASSTYPE_VFIELD (TYPE_METHOD_BASETYPE (TREE_TYPE (type1)));
3384 delta21 = DECL_FIELD_BITPOS (delta21);
3385 delta21 = size_binop (FLOOR_DIV_EXPR, delta21, size_int (BITS_PER_UNIT));
3388 index1 = integer_neg_one_node;
3390 tree nop1 = build1 (NOP_EXPR, TYPE_PTRMEMFUNC_FN_TYPE (type0), op1);
3391 TREE_CONSTANT (nop1) = TREE_CONSTANT (op1);
3394 e1 = build_binary_op (EQ_EXPR, index0, index1, 1);
3395 e2 = build_binary_op (NE_EXPR, index1, integer_neg_one_node, 1);
3396 e2 = build_binary_op (TRUTH_ANDIF_EXPR, e2, build_binary_op (EQ_EXPR, delta20, delta21, 1), 1);
3397 e3 = build_binary_op (EQ_EXPR, pfn0, op1, 1);
3398 e2 = build_binary_op (TRUTH_ORIF_EXPR, e2, e3, 1);
3399 e2 = build_binary_op (TRUTH_ANDIF_EXPR, e1, e2, 1);
3400 if (code == EQ_EXPR)
3402 return build_binary_op (EQ_EXPR, e2, integer_zero_node, 1);
3404 else if (TYPE_PTRMEMFUNC_P (type1)
3405 && TYPE_PTRMEMFUNC_FN_TYPE (type1) == type0)
3407 return build_binary_op (code, op1, op0, 1);
3413 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
3414 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
3416 else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
3418 if (comp_target_types (type0, type1, 1))
3419 result_type = common_type (type0, type1);
3422 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3424 result_type = ptr_type_node;
3433 build_type = boolean_type_node;
3434 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
3435 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
3437 else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
3439 if (comp_target_types (type0, type1, 1))
3440 result_type = common_type (type0, type1);
3443 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3445 result_type = ptr_type_node;
3448 else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST
3449 && integer_zerop (op1))
3450 result_type = type0;
3451 else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST
3452 && integer_zerop (op0))
3453 result_type = type1;
3454 else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
3456 result_type = type0;
3458 pedwarn ("ANSI C++ forbids comparison between pointer and integer");
3459 else if (! flag_traditional)
3460 warning ("comparison between pointer and integer");
3462 else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
3464 result_type = type1;
3466 pedwarn ("ANSI C++ forbids comparison between pointer and integer");
3467 else if (! flag_traditional)
3468 warning ("comparison between pointer and integer");
3473 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
3474 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
3476 if (shorten || common || short_compare)
3477 result_type = common_type (type0, type1);
3479 /* For certain operations (which identify themselves by shorten != 0)
3480 if both args were extended from the same smaller type,
3481 do the arithmetic in that type and then extend.
3483 shorten !=0 and !=1 indicates a bitwise operation.
3484 For them, this optimization is safe only if
3485 both args are zero-extended or both are sign-extended.
3486 Otherwise, we might change the result.
3487 Eg, (short)-1 | (unsigned short)-1 is (int)-1
3488 but calculated in (unsigned short) it would be (unsigned short)-1. */
3492 int unsigned0, unsigned1;
3493 tree arg0 = get_narrower (op0, &unsigned0);
3494 tree arg1 = get_narrower (op1, &unsigned1);
3495 /* UNS is 1 if the operation to be done is an unsigned one. */
3496 int uns = TREE_UNSIGNED (result_type);
3499 final_type = result_type;
3501 /* Handle the case that OP0 does not *contain* a conversion
3502 but it *requires* conversion to FINAL_TYPE. */
3504 if (op0 == arg0 && TREE_TYPE (op0) != final_type)
3505 unsigned0 = TREE_UNSIGNED (TREE_TYPE (op0));
3506 if (op1 == arg1 && TREE_TYPE (op1) != final_type)
3507 unsigned1 = TREE_UNSIGNED (TREE_TYPE (op1));
3509 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
3511 /* For bitwise operations, signedness of nominal type
3512 does not matter. Consider only how operands were extended. */
3516 /* Note that in all three cases below we refrain from optimizing
3517 an unsigned operation on sign-extended args.
3518 That would not be valid. */
3520 /* Both args variable: if both extended in same way
3521 from same width, do it in that width.
3522 Do it unsigned if args were zero-extended. */
3523 if ((TYPE_PRECISION (TREE_TYPE (arg0))
3524 < TYPE_PRECISION (result_type))
3525 && (TYPE_PRECISION (TREE_TYPE (arg1))
3526 == TYPE_PRECISION (TREE_TYPE (arg0)))
3527 && unsigned0 == unsigned1
3528 && (unsigned0 || !uns))
3530 = signed_or_unsigned_type (unsigned0,
3531 common_type (TREE_TYPE (arg0), TREE_TYPE (arg1)));
3532 else if (TREE_CODE (arg0) == INTEGER_CST
3533 && (unsigned1 || !uns)
3534 && (TYPE_PRECISION (TREE_TYPE (arg1))
3535 < TYPE_PRECISION (result_type))
3536 && (type = signed_or_unsigned_type (unsigned1,
3538 int_fits_type_p (arg0, type)))
3540 else if (TREE_CODE (arg1) == INTEGER_CST
3541 && (unsigned0 || !uns)
3542 && (TYPE_PRECISION (TREE_TYPE (arg0))
3543 < TYPE_PRECISION (result_type))
3544 && (type = signed_or_unsigned_type (unsigned0,
3546 int_fits_type_p (arg1, type)))
3550 /* Shifts can be shortened if shifting right. */
3555 tree arg0 = get_narrower (op0, &unsigned_arg);
3557 final_type = result_type;
3559 if (arg0 == op0 && final_type == TREE_TYPE (op0))
3560 unsigned_arg = TREE_UNSIGNED (TREE_TYPE (op0));
3562 if (TYPE_PRECISION (TREE_TYPE (arg0)) < TYPE_PRECISION (result_type)
3563 /* We can shorten only if the shift count is less than the
3564 number of bits in the smaller type size. */
3565 && TREE_INT_CST_HIGH (op1) == 0
3566 && TYPE_PRECISION (TREE_TYPE (arg0)) > TREE_INT_CST_LOW (op1)
3567 /* If arg is sign-extended and then unsigned-shifted,
3568 we can simulate this with a signed shift in arg's type
3569 only if the extended result is at least twice as wide
3570 as the arg. Otherwise, the shift could use up all the
3571 ones made by sign-extension and bring in zeros.
3572 We can't optimize that case at all, but in most machines
3573 it never happens because available widths are 2**N. */
3574 && (!TREE_UNSIGNED (final_type)
3576 || (((unsigned) 2 * TYPE_PRECISION (TREE_TYPE (arg0)))
3577 <= TYPE_PRECISION (result_type))))
3579 /* Do an unsigned shift if the operand was zero-extended. */
3581 = signed_or_unsigned_type (unsigned_arg,
3583 /* Convert value-to-be-shifted to that type. */
3584 if (TREE_TYPE (op0) != result_type)
3585 op0 = convert (result_type, op0);
3590 /* Comparison operations are shortened too but differently.
3591 They identify themselves by setting short_compare = 1. */
3595 /* Don't write &op0, etc., because that would prevent op0
3596 from being kept in a register.
3597 Instead, make copies of the our local variables and
3598 pass the copies by reference, then copy them back afterward. */
3599 tree xop0 = op0, xop1 = op1, xresult_type = result_type;
3600 enum tree_code xresultcode = resultcode;
3602 = shorten_compare (&xop0, &xop1, &xresult_type, &xresultcode);
3604 return convert (boolean_type_node, val);
3605 op0 = xop0, op1 = xop1;
3607 resultcode = xresultcode;
3610 if (short_compare && warn_sign_compare)
3612 int op0_signed = ! TREE_UNSIGNED (TREE_TYPE (orig_op0));
3613 int op1_signed = ! TREE_UNSIGNED (TREE_TYPE (orig_op1));
3615 int unsignedp0, unsignedp1;
3616 tree primop0 = get_narrower (op0, &unsignedp0);
3617 tree primop1 = get_narrower (op1, &unsignedp1);
3619 /* Check for comparison of different enum types. */
3620 if (flag_int_enum_equivalence == 0
3621 && TREE_CODE (TREE_TYPE (orig_op0)) == ENUMERAL_TYPE
3622 && TREE_CODE (TREE_TYPE (orig_op1)) == ENUMERAL_TYPE
3623 && TYPE_MAIN_VARIANT (TREE_TYPE (orig_op0))
3624 != TYPE_MAIN_VARIANT (TREE_TYPE (orig_op1)))
3626 cp_warning ("comparison between `%#T' and `%#T'",
3627 TREE_TYPE (orig_op0), TREE_TYPE (orig_op1));
3630 /* Give warnings for comparisons between signed and unsigned
3631 quantities that may fail. */
3632 /* Do the checking based on the original operand trees, so that
3633 casts will be considered, but default promotions won't be. */
3635 /* Do not warn if the comparison is being done in a signed type,
3636 since the signed type will only be chosen if it can represent
3637 all the values of the unsigned type. */
3638 if (! TREE_UNSIGNED (result_type))
3640 /* Do not warn if both operands are unsigned. */
3641 else if (op0_signed == op1_signed)
3643 /* Do not warn if the signed quantity is an unsuffixed
3644 integer literal (or some static constant expression
3645 involving such literals) and it is non-negative. */
3646 else if ((op0_signed && TREE_CODE (orig_op0) == INTEGER_CST
3647 && tree_int_cst_sgn (orig_op0) >= 0)
3648 || (op1_signed && TREE_CODE (orig_op1) == INTEGER_CST
3649 && tree_int_cst_sgn (orig_op1) >= 0))
3651 /* Do not warn if the comparison is an equality operation,
3652 the unsigned quantity is an integral constant and it does
3653 not use the most significant bit of result_type. */
3654 else if ((resultcode == EQ_EXPR || resultcode == NE_EXPR)
3655 && ((op0_signed && TREE_CODE (orig_op1) == INTEGER_CST
3656 && int_fits_type_p (orig_op1, signed_type (result_type))
3657 || (op1_signed && TREE_CODE (orig_op0) == INTEGER_CST
3658 && int_fits_type_p (orig_op0, signed_type (result_type))))))
3661 warning ("comparison between signed and unsigned");
3663 /* Warn if two unsigned values are being compared in a size
3664 larger than their original size, and one (and only one) is the
3665 result of a `~' operator. This comparison will always fail.
3667 Also warn if one operand is a constant, and the constant does not
3668 have all bits set that are set in the ~ operand when it is
3671 if ((TREE_CODE (primop0) == BIT_NOT_EXPR)
3672 ^ (TREE_CODE (primop1) == BIT_NOT_EXPR))
3674 if (TREE_CODE (primop0) == BIT_NOT_EXPR)
3675 primop0 = get_narrower (TREE_OPERAND (op0, 0), &unsignedp0);
3676 if (TREE_CODE (primop1) == BIT_NOT_EXPR)
3677 primop1 = get_narrower (TREE_OPERAND (op1, 0), &unsignedp1);
3679 if (TREE_CODE (primop0) == INTEGER_CST
3680 || TREE_CODE (primop1) == INTEGER_CST)
3683 HOST_WIDE_INT constant, mask;
3687 if (TREE_CODE (primop0) == INTEGER_CST)
3690 unsignedp = unsignedp1;
3691 constant = TREE_INT_CST_LOW (primop0);
3696 unsignedp = unsignedp0;
3697 constant = TREE_INT_CST_LOW (primop1);
3700 bits = TYPE_PRECISION (TREE_TYPE (primop));
3701 if (bits < TYPE_PRECISION (result_type)
3702 && bits < HOST_BITS_PER_LONG && unsignedp)
3704 mask = (~ (HOST_WIDE_INT) 0) << bits;
3705 if ((mask & constant) != mask)
3706 warning ("comparison of promoted ~unsigned with constant");
3709 else if (unsignedp0 && unsignedp1
3710 && (TYPE_PRECISION (TREE_TYPE (primop0))
3711 < TYPE_PRECISION (result_type))
3712 && (TYPE_PRECISION (TREE_TYPE (primop1))
3713 < TYPE_PRECISION (result_type)))
3714 warning ("comparison of promoted ~unsigned with unsigned");
3719 /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
3720 If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
3721 Then the expression will be built.
3722 It will be given type FINAL_TYPE if that is nonzero;
3723 otherwise, it will be given type RESULT_TYPE. */
3727 cp_error ("invalid operands `%T' and `%T' to binary `%O'",
3728 TREE_TYPE (orig_op0), TREE_TYPE (orig_op1), error_code);
3729 return error_mark_node;
3734 if (TREE_TYPE (op0) != result_type)
3735 op0 = convert (result_type, op0);
3736 if (TREE_TYPE (op1) != result_type)
3737 op1 = convert (result_type, op1);
3740 if (build_type == NULL_TREE)
3741 build_type = result_type;
3744 register tree result = build (resultcode, build_type, op0, op1);
3745 register tree folded;
3747 folded = fold (result);
3748 if (folded == result)
3749 TREE_CONSTANT (folded) = TREE_CONSTANT (op0) & TREE_CONSTANT (op1);
3750 if (final_type != 0)
3751 return convert (final_type, folded);
3756 /* Return a tree for the sum or difference (RESULTCODE says which)
3757 of pointer PTROP and integer INTOP. */
3760 pointer_int_sum (resultcode, ptrop, intop)
3761 enum tree_code resultcode;
3762 register tree ptrop, intop;
3766 register tree result;
3767 register tree folded = fold (intop);
3769 /* The result is a pointer of the same type that is being added. */
3771 register tree result_type = TREE_TYPE (ptrop);
3773 if (TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE)
3775 if (pedantic || warn_pointer_arith)
3776 pedwarn ("ANSI C++ forbids using pointer of type `void *' in arithmetic");
3777 size_exp = integer_one_node;
3779 else if (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE)
3781 if (pedantic || warn_pointer_arith)
3782 pedwarn ("ANSI C++ forbids using pointer to a function in arithmetic");
3783 size_exp = integer_one_node;
3785 else if (TREE_CODE (TREE_TYPE (result_type)) == METHOD_TYPE)
3787 if (pedantic || warn_pointer_arith)
3788 pedwarn ("ANSI C++ forbids using pointer to a method in arithmetic");
3789 size_exp = integer_one_node;
3791 else if (TREE_CODE (TREE_TYPE (result_type)) == OFFSET_TYPE)
3793 if (pedantic || warn_pointer_arith)
3794 pedwarn ("ANSI C++ forbids using pointer to a member in arithmetic");
3795 size_exp = integer_one_node;
3798 size_exp = size_in_bytes (complete_type (TREE_TYPE (result_type)));
3800 /* Needed to make OOPS V2R3 work. */
3802 if (TREE_CODE (intop) == INTEGER_CST
3803 && TREE_INT_CST_LOW (intop) == 0
3804 && TREE_INT_CST_HIGH (intop) == 0)
3807 /* If what we are about to multiply by the size of the elements
3808 contains a constant term, apply distributive law
3809 and multiply that constant term separately.
3810 This helps produce common subexpressions. */
3812 if ((TREE_CODE (intop) == PLUS_EXPR || TREE_CODE (intop) == MINUS_EXPR)
3813 && ! TREE_CONSTANT (intop)
3814 && TREE_CONSTANT (TREE_OPERAND (intop, 1))
3815 && TREE_CONSTANT (size_exp))
3817 enum tree_code subcode = resultcode;
3818 if (TREE_CODE (intop) == MINUS_EXPR)
3819 subcode = (subcode == PLUS_EXPR ? MINUS_EXPR : PLUS_EXPR);
3820 ptrop = build_binary_op (subcode, ptrop, TREE_OPERAND (intop, 1), 1);
3821 intop = TREE_OPERAND (intop, 0);
3824 /* Convert the integer argument to a type the same size as sizetype
3825 so the multiply won't overflow spuriously. */
3827 if (TYPE_PRECISION (TREE_TYPE (intop)) != TYPE_PRECISION (sizetype))
3828 intop = convert (type_for_size (TYPE_PRECISION (sizetype), 0), intop);
3830 /* Replace the integer argument with a suitable product by the object size.
3831 Do this multiplication as signed, then convert to the appropriate
3832 pointer type (actually unsigned integral). */
3834 intop = convert (result_type,
3835 build_binary_op (MULT_EXPR, intop,
3836 convert (TREE_TYPE (intop), size_exp), 1));
3838 /* Create the sum or difference. */
3840 result = build (resultcode, result_type, ptrop, intop);
3842 folded = fold (result);
3843 if (folded == result)
3844 TREE_CONSTANT (folded) = TREE_CONSTANT (ptrop) & TREE_CONSTANT (intop);
3848 /* Return a tree for the difference of pointers OP0 and OP1.
3849 The resulting tree has type int. */
3852 pointer_diff (op0, op1)
3853 register tree op0, op1;
3855 register tree result, folded;
3856 tree restype = ptrdiff_type_node;
3857 tree target_type = TREE_TYPE (TREE_TYPE (op0));
3859 if (pedantic || warn_pointer_arith)
3861 if (TREE_CODE (target_type) == VOID_TYPE)
3862 pedwarn ("ANSI C++ forbids using pointer of type `void *' in subtraction");
3863 if (TREE_CODE (target_type) == FUNCTION_TYPE)
3864 pedwarn ("ANSI C++ forbids using pointer to a function in subtraction");
3865 if (TREE_CODE (target_type) == METHOD_TYPE)
3866 pedwarn ("ANSI C++ forbids using pointer to a method in subtraction");
3867 if (TREE_CODE (target_type) == OFFSET_TYPE)
3868 pedwarn ("ANSI C++ forbids using pointer to a member in subtraction");
3871 /* First do the subtraction as integers;
3872 then drop through to build the divide operator. */
3874 op0 = build_binary_op (MINUS_EXPR,
3875 convert (restype, op0), convert (restype, op1), 1);
3877 /* This generates an error if op1 is a pointer to an incomplete type. */
3878 if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (op1))) == 0)
3879 error ("arithmetic on pointer to an incomplete type");
3881 op1 = ((TREE_CODE (target_type) == VOID_TYPE
3882 || TREE_CODE (target_type) == FUNCTION_TYPE
3883 || TREE_CODE (target_type) == METHOD_TYPE
3884 || TREE_CODE (target_type) == OFFSET_TYPE)
3886 : size_in_bytes (target_type));
3888 /* Do the division. */
3890 result = build (EXACT_DIV_EXPR, restype, op0, convert (restype, op1));
3892 folded = fold (result);
3893 if (folded == result)
3894 TREE_CONSTANT (folded) = TREE_CONSTANT (op0) & TREE_CONSTANT (op1);
3898 /* Handle the case of taking the address of a COMPONENT_REF.
3899 Called by `build_unary_op' and `build_up_reference'.
3901 ARG is the COMPONENT_REF whose address we want.
3902 ARGTYPE is the pointer type that this address should have.
3903 MSG is an error message to print if this COMPONENT_REF is not
3904 addressable (such as a bitfield). */
3907 build_component_addr (arg, argtype, msg)
3911 tree field = TREE_OPERAND (arg, 1);
3912 tree basetype = decl_type_context (field);
3913 tree rval = build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0), 0);
3915 if (DECL_BIT_FIELD (field))
3917 error (msg, IDENTIFIER_POINTER (DECL_NAME (field)));
3918 return error_mark_node;
3921 if (TREE_CODE (field) == FIELD_DECL
3922 && TYPE_USES_COMPLEX_INHERITANCE (basetype))
3924 /* Can't convert directly to ARGTYPE, since that
3925 may have the same pointer type as one of our
3927 rval = build1 (NOP_EXPR, argtype,
3928 convert_pointer_to (basetype, rval));
3929 TREE_CONSTANT (rval) = TREE_CONSTANT (TREE_OPERAND (rval, 0));
3932 /* This conversion is harmless. */
3933 rval = convert_force (argtype, rval, 0);
3935 if (! integer_zerop (DECL_FIELD_BITPOS (field)))
3937 tree offset = size_binop (EASY_DIV_EXPR, DECL_FIELD_BITPOS (field),
3938 size_int (BITS_PER_UNIT));
3939 int flag = TREE_CONSTANT (rval);
3940 rval = fold (build (PLUS_EXPR, argtype,
3941 rval, convert (argtype, offset)));
3942 TREE_CONSTANT (rval) = flag;
3947 /* Construct and perhaps optimize a tree representation
3948 for a unary operation. CODE, a tree_code, specifies the operation
3949 and XARG is the operand. */
3952 build_x_unary_op (code, xarg)
3953 enum tree_code code;
3956 if (current_template_parms)
3957 return build_min_nt (code, xarg, NULL_TREE);
3959 /* & rec, on incomplete RECORD_TYPEs is the simple opr &, not an
3961 if (code == ADDR_EXPR
3962 && ((IS_AGGR_TYPE_CODE (TREE_CODE (TREE_TYPE (xarg)))
3963 && TYPE_SIZE (TREE_TYPE (xarg)) == NULL_TREE)
3964 || (TREE_CODE (xarg) == OFFSET_REF)))
3965 /* don't look for a function */;
3968 tree rval = build_opfncall (code, LOOKUP_SPECULATIVELY, xarg,
3969 NULL_TREE, NULL_TREE);
3971 return build_opfncall (code, LOOKUP_NORMAL, xarg,
3972 NULL_TREE, NULL_TREE);
3974 return build_unary_op (code, xarg, 0);
3977 /* Just like truthvalue_conversion, but we want a CLEANUP_POINT_EXPR. */
3980 condition_conversion (expr)
3984 if (current_template_parms)
3986 t = convert (boolean_type_node, expr);
3987 t = fold (build1 (CLEANUP_POINT_EXPR, boolean_type_node, t));
3991 /* C++: Must handle pointers to members.
3993 Perhaps type instantiation should be extended to handle conversion
3994 from aggregates to types we don't yet know we want? (Or are those
3995 cases typically errors which should be reported?)
3997 NOCONVERT nonzero suppresses the default promotions
3998 (such as from short to int). */
4000 build_unary_op (code, xarg, noconvert)
4001 enum tree_code code;
4005 /* No default_conversion here. It causes trouble for ADDR_EXPR. */
4006 register tree arg = xarg;
4007 register tree argtype = 0;
4008 char *errstring = NULL;
4011 if (arg == error_mark_node)
4012 return error_mark_node;
4017 /* This is used for unary plus, because a CONVERT_EXPR
4018 is enough to prevent anybody from looking inside for
4019 associativity, but won't generate any code. */
4020 if (!(arg = build_expr_type_conversion
4021 (WANT_ARITH | WANT_ENUM | WANT_POINTER, arg, 1)))
4022 errstring = "wrong type argument to unary plus";
4026 arg = default_conversion (arg);
4027 arg = build1 (NON_LVALUE_EXPR, TREE_TYPE (arg), arg);
4032 if (!(arg = build_expr_type_conversion (WANT_ARITH | WANT_ENUM, arg, 1)))
4033 errstring = "wrong type argument to unary minus";
4034 else if (!noconvert)
4035 arg = default_conversion (arg);
4039 if (!(arg = build_expr_type_conversion (WANT_INT | WANT_ENUM, arg, 1)))
4040 errstring = "wrong type argument to bit-complement";
4041 else if (!noconvert)
4042 arg = default_conversion (arg);
4046 if (!(arg = build_expr_type_conversion (WANT_ARITH | WANT_ENUM, arg, 1)))
4047 errstring = "wrong type argument to abs";
4048 else if (!noconvert)
4049 arg = default_conversion (arg);
4052 case TRUTH_NOT_EXPR:
4053 arg = convert (boolean_type_node, arg);
4054 val = invert_truthvalue (arg);
4055 if (arg != error_mark_node)
4057 errstring = "in argument to unary !";
4063 case PREINCREMENT_EXPR:
4064 case POSTINCREMENT_EXPR:
4065 case PREDECREMENT_EXPR:
4066 case POSTDECREMENT_EXPR:
4067 /* Handle complex lvalues (when permitted)
4068 by reduction to simpler cases. */
4070 val = unary_complex_lvalue (code, arg);
4074 /* Report invalid types. */
4076 if (!(arg = build_expr_type_conversion (WANT_ARITH | WANT_POINTER,
4079 if (code == PREINCREMENT_EXPR)
4080 errstring ="no pre-increment operator for type";
4081 else if (code == POSTINCREMENT_EXPR)
4082 errstring ="no post-increment operator for type";
4083 else if (code == PREDECREMENT_EXPR)
4084 errstring ="no pre-decrement operator for type";
4086 errstring ="no post-decrement operator for type";
4090 /* Report something read-only. */
4092 if (TYPE_READONLY (TREE_TYPE (arg))
4093 || TREE_READONLY (arg))
4094 readonly_error (arg, ((code == PREINCREMENT_EXPR
4095 || code == POSTINCREMENT_EXPR)
4096 ? "increment" : "decrement"),
4101 tree result_type = TREE_TYPE (arg);
4103 arg = get_unwidened (arg, 0);
4104 argtype = TREE_TYPE (arg);
4106 /* ARM $5.2.5 last annotation says this should be forbidden. */
4107 if (TREE_CODE (argtype) == ENUMERAL_TYPE)
4108 pedwarn ("ANSI C++ forbids %sing an enum",
4109 (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
4110 ? "increment" : "decrement");
4112 /* Compute the increment. */
4114 if (TREE_CODE (argtype) == POINTER_TYPE)
4116 enum tree_code tmp = TREE_CODE (TREE_TYPE (argtype));
4117 if (TYPE_SIZE (complete_type (TREE_TYPE (argtype))) == 0)
4118 cp_error ("cannot %s a pointer to incomplete type `%T'",
4119 ((code == PREINCREMENT_EXPR
4120 || code == POSTINCREMENT_EXPR)
4121 ? "increment" : "decrement"), TREE_TYPE (argtype));
4122 else if (tmp == FUNCTION_TYPE || tmp == METHOD_TYPE
4123 || tmp == VOID_TYPE || tmp == OFFSET_TYPE)
4124 cp_pedwarn ("ANSI C++ forbids %sing a pointer of type `%T'",
4125 ((code == PREINCREMENT_EXPR
4126 || code == POSTINCREMENT_EXPR)
4127 ? "increment" : "decrement"), argtype);
4128 inc = c_sizeof_nowarn (TREE_TYPE (argtype));
4131 inc = integer_one_node;
4133 inc = convert (argtype, inc);
4135 /* Handle incrementing a cast-expression. */
4137 switch (TREE_CODE (arg))
4142 case FIX_TRUNC_EXPR:
4143 case FIX_FLOOR_EXPR:
4144 case FIX_ROUND_EXPR:
4147 tree incremented, modify, value, compound;
4148 if (! lvalue_p (arg) && pedantic)
4149 pedwarn ("cast to non-reference type used as lvalue");
4150 arg = stabilize_reference (arg);
4151 if (code == PREINCREMENT_EXPR || code == PREDECREMENT_EXPR)
4154 value = save_expr (arg);
4155 incremented = build (((code == PREINCREMENT_EXPR
4156 || code == POSTINCREMENT_EXPR)
4157 ? PLUS_EXPR : MINUS_EXPR),
4158 argtype, value, inc);
4159 TREE_SIDE_EFFECTS (incremented) = 1;
4161 modify = build_modify_expr (arg, NOP_EXPR, incremented);
4162 compound = build (COMPOUND_EXPR, TREE_TYPE (arg), modify, value);
4164 /* Eliminate warning about unused result of + or -. */
4165 TREE_NO_UNUSED_WARNING (compound) = 1;
4170 /* Complain about anything else that is not a true lvalue. */
4171 if (!lvalue_or_else (arg, ((code == PREINCREMENT_EXPR
4172 || code == POSTINCREMENT_EXPR)
4173 ? "increment" : "decrement")))
4174 return error_mark_node;
4176 /* Forbid using -- on `bool'. */
4177 if (TREE_TYPE (arg) == boolean_type_node)
4179 if (code == POSTDECREMENT_EXPR || code == PREDECREMENT_EXPR)
4181 cp_error ("invalid use of `--' on bool variable `%D'", arg);
4182 return error_mark_node;
4185 /* This will only work if someone can convince Kenner to accept
4186 my patch to expand_increment. (jason) */
4187 val = build (code, TREE_TYPE (arg), arg, inc);
4189 if (code == POSTINCREMENT_EXPR)
4191 arg = stabilize_reference (arg);
4192 val = build (MODIFY_EXPR, TREE_TYPE (arg), arg,
4194 TREE_SIDE_EFFECTS (val) = 1;
4195 arg = save_expr (arg);
4196 val = build (COMPOUND_EXPR, TREE_TYPE (arg), val, arg);
4197 val = build (COMPOUND_EXPR, TREE_TYPE (arg), arg, val);
4200 val = build (MODIFY_EXPR, TREE_TYPE (arg), arg,
4205 val = build (code, TREE_TYPE (arg), arg, inc);
4207 TREE_SIDE_EFFECTS (val) = 1;
4208 return convert (result_type, val);
4212 /* Note that this operation never does default_conversion
4213 regardless of NOCONVERT. */
4215 argtype = TREE_TYPE (arg);
4216 if (TREE_CODE (argtype) == REFERENCE_TYPE)
4218 arg = build1 (CONVERT_EXPR, build_pointer_type (TREE_TYPE (TREE_TYPE (arg))), arg);
4219 TREE_REFERENCE_EXPR (arg) = 1;
4223 && TREE_CODE (arg) == FUNCTION_DECL
4225 && DECL_CONTEXT (arg) == NULL_TREE
4226 && IDENTIFIER_LENGTH (DECL_NAME (arg)) == 4
4227 && IDENTIFIER_POINTER (DECL_NAME (arg))[0] == 'm'
4228 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (arg)), "main"))
4230 pedwarn ("taking address of function `main'");
4232 /* Let &* cancel out to simplify resulting code. */
4233 if (TREE_CODE (arg) == INDIRECT_REF)
4235 /* We don't need to have `current_class_decl' wrapped in a
4236 NON_LVALUE_EXPR node. */
4238 return current_class_decl;
4240 /* Keep `default_conversion' from converting if
4241 ARG is of REFERENCE_TYPE. */
4242 arg = TREE_OPERAND (arg, 0);
4243 if (TREE_CODE (TREE_TYPE (arg)) == REFERENCE_TYPE)
4245 if (TREE_CODE (arg) == VAR_DECL && DECL_INITIAL (arg)
4246 && !TREE_SIDE_EFFECTS (DECL_INITIAL (arg)))
4247 arg = DECL_INITIAL (arg);
4248 arg = build1 (CONVERT_EXPR, build_pointer_type (TREE_TYPE (TREE_TYPE (arg))), arg);
4249 TREE_REFERENCE_EXPR (arg) = 1;
4250 TREE_CONSTANT (arg) = TREE_CONSTANT (TREE_OPERAND (arg, 0));
4252 else if (lvalue_p (arg))
4253 /* Don't let this be an lvalue. */
4254 return non_lvalue (arg);
4258 /* For &x[y], return x+y */
4259 if (TREE_CODE (arg) == ARRAY_REF)
4261 if (mark_addressable (TREE_OPERAND (arg, 0)) == 0)
4262 return error_mark_node;
4263 return build_binary_op (PLUS_EXPR, TREE_OPERAND (arg, 0),
4264 TREE_OPERAND (arg, 1), 1);
4267 /* Uninstantiated types are all functions. Taking the
4268 address of a function is a no-op, so just return the
4271 if (TREE_CODE (arg) == IDENTIFIER_NODE
4272 && IDENTIFIER_OPNAME_P (arg))
4274 my_friendly_abort (117);
4275 /* We don't know the type yet, so just work around the problem.
4276 We know that this will resolve to an lvalue. */
4277 return build1 (ADDR_EXPR, unknown_type_node, arg);
4280 if (TREE_CODE (arg) == TREE_LIST)
4282 if (TREE_CODE (TREE_VALUE (arg)) == FUNCTION_DECL
4283 && DECL_CHAIN (TREE_VALUE (arg)) == NULL_TREE)
4284 /* Unique overloaded non-member function. */
4285 return build_unary_op (ADDR_EXPR, TREE_VALUE (arg), 0);
4286 if (TREE_CHAIN (arg) == NULL_TREE
4287 && TREE_CODE (TREE_VALUE (arg)) == TREE_LIST
4288 && DECL_CHAIN (TREE_VALUE (TREE_VALUE (arg))) == NULL_TREE)
4289 /* Unique overloaded member function. */
4290 return build_unary_op (ADDR_EXPR, TREE_VALUE (TREE_VALUE (arg)),
4292 return build1 (ADDR_EXPR, unknown_type_node, arg);
4295 /* Handle complex lvalues (when permitted)
4296 by reduction to simpler cases. */
4297 val = unary_complex_lvalue (code, arg);
4301 switch (TREE_CODE (arg))
4306 case FIX_TRUNC_EXPR:
4307 case FIX_FLOOR_EXPR:
4308 case FIX_ROUND_EXPR:
4310 if (! lvalue_p (arg) && pedantic)
4311 pedwarn ("taking the address of a cast to non-reference type");
4314 /* Allow the address of a constructor if all the elements
4316 if (TREE_CODE (arg) == CONSTRUCTOR && TREE_CONSTANT (arg))
4318 /* Anything not already handled and not a true memory reference
4320 else if (TREE_CODE (argtype) != FUNCTION_TYPE
4321 && TREE_CODE (argtype) != METHOD_TYPE
4322 && !lvalue_or_else (arg, "unary `&'"))
4323 return error_mark_node;
4325 /* Ordinary case; arg is a COMPONENT_REF or a decl. */
4326 /* If the lvalue is const or volatile,
4327 merge that into the type that the address will point to. */
4328 if (TREE_CODE_CLASS (TREE_CODE (arg)) == 'd'
4329 || TREE_CODE_CLASS (TREE_CODE (arg)) == 'r')
4331 if (TREE_READONLY (arg) || TREE_THIS_VOLATILE (arg))
4332 argtype = cp_build_type_variant (argtype,
4333 TREE_READONLY (arg),
4334 TREE_THIS_VOLATILE (arg));
4337 argtype = build_pointer_type (argtype);
4339 if (mark_addressable (arg) == 0)
4340 return error_mark_node;
4345 if (TREE_CODE (arg) == COMPONENT_REF)
4346 addr = build_component_addr (arg, argtype,
4347 "attempt to take address of bit-field structure member `%s'");
4349 addr = build1 (code, argtype, arg);
4351 /* Address of a static or external variable or
4352 function counts as a constant */
4354 TREE_CONSTANT (addr) = 1;
4362 argtype = TREE_TYPE (arg);
4363 return fold (build1 (code, argtype, arg));
4367 return error_mark_node;
4371 /* If CONVERSIONS is a conversion expression or a nested sequence of such,
4372 convert ARG with the same conversions in the same order
4373 and return the result. */
4376 convert_sequence (conversions, arg)
4380 switch (TREE_CODE (conversions))
4385 case FIX_TRUNC_EXPR:
4386 case FIX_FLOOR_EXPR:
4387 case FIX_ROUND_EXPR:
4389 return convert (TREE_TYPE (conversions),
4390 convert_sequence (TREE_OPERAND (conversions, 0),
4399 /* Apply unary lvalue-demanding operator CODE to the expression ARG
4400 for certain kinds of expressions which are not really lvalues
4401 but which we can accept as lvalues.
4403 If ARG is not a kind of expression we can handle, return zero. */
4406 unary_complex_lvalue (code, arg)
4407 enum tree_code code;
4410 /* Handle (a, b) used as an "lvalue". */
4411 if (TREE_CODE (arg) == COMPOUND_EXPR)
4413 tree real_result = build_unary_op (code, TREE_OPERAND (arg, 1), 0);
4414 return build (COMPOUND_EXPR, TREE_TYPE (real_result),
4415 TREE_OPERAND (arg, 0), real_result);
4418 /* Handle (a ? b : c) used as an "lvalue". */
4419 if (TREE_CODE (arg) == COND_EXPR)
4420 return rationalize_conditional_expr (code, arg);
4422 if (TREE_CODE (arg) == MODIFY_EXPR
4423 || TREE_CODE (arg) == PREINCREMENT_EXPR
4424 || TREE_CODE (arg) == PREDECREMENT_EXPR)
4425 return unary_complex_lvalue
4426 (code, build (COMPOUND_EXPR, TREE_TYPE (TREE_OPERAND (arg, 0)),
4427 arg, TREE_OPERAND (arg, 0)));
4429 if (code != ADDR_EXPR)
4432 /* Handle (a = b) used as an "lvalue" for `&'. */
4433 if (TREE_CODE (arg) == MODIFY_EXPR
4434 || TREE_CODE (arg) == INIT_EXPR)
4436 tree real_result = build_unary_op (code, TREE_OPERAND (arg, 0), 0);
4437 return build (COMPOUND_EXPR, TREE_TYPE (real_result), arg, real_result);
4440 if (TREE_CODE (TREE_TYPE (arg)) == FUNCTION_TYPE
4441 || TREE_CODE (TREE_TYPE (arg)) == METHOD_TYPE
4442 || TREE_CODE (TREE_TYPE (arg)) == OFFSET_TYPE)
4444 /* The representation of something of type OFFSET_TYPE
4445 is really the representation of a pointer to it.
4446 Here give the representation its true type. */
4450 my_friendly_assert (TREE_CODE (arg) != SCOPE_REF, 313);
4452 if (TREE_CODE (arg) != OFFSET_REF)
4455 t = TREE_OPERAND (arg, 1);
4457 if (TREE_CODE (t) == FUNCTION_DECL) /* Check all this code for right semantics. */
4458 return build_unary_op (ADDR_EXPR, t, 0);
4459 if (TREE_CODE (t) == VAR_DECL)
4460 return build_unary_op (ADDR_EXPR, t, 0);
4463 if (TREE_OPERAND (arg, 0)
4464 && (TREE_CODE (TREE_OPERAND (arg, 0)) != NOP_EXPR
4465 || TREE_OPERAND (TREE_OPERAND (arg, 0), 0) != error_mark_node))
4466 if (TREE_CODE (t) != FIELD_DECL)
4468 /* Don't know if this should return address to just
4469 _DECL, or actual address resolved in this expression. */
4470 sorry ("address of bound pointer-to-member expression");
4471 return error_mark_node;
4474 offset = get_delta_difference (DECL_FIELD_CONTEXT (t),
4475 TREE_TYPE (TREE_OPERAND (arg, 0)),
4477 offset = size_binop (PLUS_EXPR, offset,
4478 size_binop (EASY_DIV_EXPR,
4479 DECL_FIELD_BITPOS (t),
4480 size_int (BITS_PER_UNIT)));
4481 return convert (build_pointer_type (TREE_TYPE (arg)), offset);
4485 if (TREE_CODE (arg) == OFFSET_REF)
4487 tree left = TREE_OPERAND (arg, 0), left_addr;
4488 tree right_addr = build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 1), 0);
4491 if (current_class_decl)
4492 left_addr = current_class_decl;
4495 error ("no `this' for pointer to member");
4496 return error_mark_node;
4499 left_addr = build_unary_op (ADDR_EXPR, left, 0);
4501 return build (PLUS_EXPR, build_pointer_type (TREE_TYPE (arg)),
4502 build1 (NOP_EXPR, integer_type_node, left_addr),
4503 build1 (NOP_EXPR, integer_type_node, right_addr));
4506 /* We permit compiler to make function calls returning
4507 objects of aggregate type look like lvalues. */
4511 if (TREE_CODE (targ) == SAVE_EXPR)
4512 targ = TREE_OPERAND (targ, 0);
4514 if (TREE_CODE (targ) == CALL_EXPR && IS_AGGR_TYPE (TREE_TYPE (targ)))
4516 if (TREE_CODE (arg) == SAVE_EXPR)
4519 targ = build_cplus_new (TREE_TYPE (arg), arg);
4520 return build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (arg)), targ);
4523 if (TREE_CODE (arg) == SAVE_EXPR && TREE_CODE (targ) == INDIRECT_REF)
4524 return build (SAVE_EXPR, build_pointer_type (TREE_TYPE (arg)),
4525 TREE_OPERAND (targ, 0), current_function_decl, NULL);
4528 /* Don't let anything else be handled specially. */
4532 /* Mark EXP saying that we need to be able to take the
4533 address of it; it should not be allocated in a register.
4534 Value is 1 if successful.
4536 C++: we do not allow `current_class_decl' to be addressable. */
4539 mark_addressable (exp)
4542 register tree x = exp;
4544 if (TREE_ADDRESSABLE (x) == 1)
4548 switch (TREE_CODE (x))
4553 x = TREE_OPERAND (x, 0);
4557 if (x == current_class_decl)
4559 error ("address of `this' not available");
4560 TREE_ADDRESSABLE (x) = 1; /* so compiler doesn't die later */
4561 put_var_into_stack (x);
4565 if (TREE_STATIC (x) && TREE_READONLY (x)
4566 && DECL_RTL (x) != 0
4567 && ! DECL_IN_MEMORY_P (x))
4569 /* We thought this would make a good constant variable,
4570 but we were wrong. */
4571 push_obstacks_nochange ();
4572 end_temporary_allocation ();
4574 TREE_ASM_WRITTEN (x) = 0;
4576 rest_of_decl_compilation (x, 0, IDENTIFIER_LOCAL_VALUE (x) == 0, 0);
4577 TREE_ADDRESSABLE (x) = 1;
4583 /* Caller should not be trying to mark initialized
4584 constant fields addressable. */
4585 my_friendly_assert (DECL_LANG_SPECIFIC (x) == 0
4586 || DECL_IN_AGGR_P (x) == 0
4588 || DECL_EXTERNAL (x), 314);
4592 /* For C++, we don't warn about taking the address of a register
4593 variable for CONST_DECLs; ARM p97 explicitly says it's okay. */
4594 put_var_into_stack (x);
4595 TREE_ADDRESSABLE (x) = 1;
4599 /* We have to test both conditions here. The first may
4600 be non-zero in the case of processing a default function.
4601 The second may be non-zero in the case of a template function. */
4602 x = DECL_MAIN_VARIANT (x);
4603 if ((DECL_THIS_INLINE (x) || DECL_PENDING_INLINE_INFO (x))
4604 && (DECL_CONTEXT (x) == NULL_TREE
4605 || TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (x))) != 't'
4606 || ! CLASSTYPE_INTERFACE_ONLY (DECL_CONTEXT (x))))
4608 mark_inline_for_output (x);
4609 if (x == current_function_decl)
4610 DECL_EXTERNAL (x) = 0;
4612 TREE_ADDRESSABLE (x) = 1;
4614 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (x)) = 1;
4622 /* Build and return a conditional expression IFEXP ? OP1 : OP2. */
4625 build_x_conditional_expr (ifexp, op1, op2)
4626 tree ifexp, op1, op2;
4628 tree rval = NULL_TREE;
4630 if (current_template_parms)
4631 return build_min_nt (COND_EXPR, ifexp, op1, op2);
4633 /* See comments in `build_x_binary_op'. */
4635 rval = build_opfncall (COND_EXPR, LOOKUP_SPECULATIVELY, ifexp, op1, op2);
4637 return build_opfncall (COND_EXPR, LOOKUP_NORMAL, ifexp, op1, op2);
4639 return build_conditional_expr (ifexp, op1, op2);
4643 build_conditional_expr (ifexp, op1, op2)
4644 tree ifexp, op1, op2;
4646 register tree type1;
4647 register tree type2;
4648 register enum tree_code code1;
4649 register enum tree_code code2;
4650 register tree result_type = NULL_TREE;
4651 tree orig_op1 = op1, orig_op2 = op2;
4653 /* If second operand is omitted, it is the same as the first one;
4654 make sure it is calculated only once. */
4658 pedwarn ("ANSI C++ forbids omitting the middle term of a ?: expression");
4659 ifexp = op1 = save_expr (ifexp);
4662 ifexp = convert (boolean_type_node, ifexp);
4664 if (TREE_CODE (ifexp) == ERROR_MARK)
4665 return error_mark_node;
4667 op1 = require_instantiated_type (TREE_TYPE (op2), op1, error_mark_node);
4668 if (op1 == error_mark_node)
4669 return error_mark_node;
4670 op2 = require_instantiated_type (TREE_TYPE (op1), op2, error_mark_node);
4671 if (op2 == error_mark_node)
4672 return error_mark_node;
4674 /* C++: REFERENCE_TYPES must be dereferenced. */
4675 type1 = TREE_TYPE (op1);
4676 code1 = TREE_CODE (type1);
4677 type2 = TREE_TYPE (op2);
4678 code2 = TREE_CODE (type2);
4680 if (code1 == REFERENCE_TYPE)
4682 op1 = convert_from_reference (op1);
4683 type1 = TREE_TYPE (op1);
4684 code1 = TREE_CODE (type1);
4686 if (code2 == REFERENCE_TYPE)
4688 op2 = convert_from_reference (op2);
4689 type2 = TREE_TYPE (op2);
4690 code2 = TREE_CODE (type2);
4693 /* Don't promote the operands separately if they promote
4694 the same way. Return the unpromoted type and let the combined
4695 value get promoted if necessary. */
4697 if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2)
4698 && code2 != ARRAY_TYPE
4699 && code2 != FUNCTION_TYPE
4700 && code2 != METHOD_TYPE)
4704 if (TREE_CONSTANT (ifexp)
4705 && (TREE_CODE (ifexp) == INTEGER_CST
4706 || TREE_CODE (ifexp) == ADDR_EXPR))
4707 return (integer_zerop (ifexp) ? op2 : op1);
4709 if (TREE_CODE (op1) == CONST_DECL)
4710 op1 = DECL_INITIAL (op1);
4711 else if (TREE_READONLY_DECL_P (op1))
4712 op1 = decl_constant_value (op1);
4713 if (TREE_CODE (op2) == CONST_DECL)
4714 op2 = DECL_INITIAL (op2);
4715 else if (TREE_READONLY_DECL_P (op2))
4716 op2 = decl_constant_value (op2);
4718 type1 = cp_build_type_variant
4720 TREE_READONLY (op1) || TREE_READONLY (op2),
4721 TREE_THIS_VOLATILE (op1) || TREE_THIS_VOLATILE (op2));
4722 /* ??? This is a kludge to deal with the fact that
4723 we don't sort out integers and enums properly, yet. */
4724 result = fold (build (COND_EXPR, type1, ifexp, op1, op2));
4725 if (TREE_TYPE (result) != type1)
4726 result = build1 (NOP_EXPR, type1, result);
4730 /* They don't match; promote them both and then try to reconcile them.
4731 But don't permit mismatching enum types. */
4732 if (code1 == ENUMERAL_TYPE)
4734 if (code2 == ENUMERAL_TYPE)
4736 cp_error ("enumeral mismatch in conditional expression: `%T' vs `%T'", type1, type2);
4737 return error_mark_node;
4739 else if (extra_warnings && ! IS_AGGR_TYPE_CODE (code2)
4740 && type2 != type_promotes_to (type1))
4741 warning ("enumeral and non-enumeral type in conditional expression");
4743 else if (extra_warnings
4744 && code2 == ENUMERAL_TYPE && ! IS_AGGR_TYPE_CODE (code1)
4745 && type1 != type_promotes_to (type2))
4746 warning ("enumeral and non-enumeral type in conditional expression");
4748 if (code1 != VOID_TYPE)
4750 op1 = default_conversion (op1);
4751 type1 = TREE_TYPE (op1);
4752 if (TYPE_PTRMEMFUNC_P (type1))
4753 type1 = TYPE_PTRMEMFUNC_FN_TYPE (type1);
4754 code1 = TREE_CODE (type1);
4756 if (code2 != VOID_TYPE)
4758 op2 = default_conversion (op2);
4759 type2 = TREE_TYPE (op2);
4760 if (TYPE_PTRMEMFUNC_P (type2))
4761 type2 = TYPE_PTRMEMFUNC_FN_TYPE (type2);
4762 code2 = TREE_CODE (type2);
4765 if (code1 == RECORD_TYPE && code2 == RECORD_TYPE
4766 && real_lvalue_p (op1) && real_lvalue_p (op2)
4767 && comptypes (type1, type2, -1))
4769 type1 = build_reference_type (type1);
4770 type2 = build_reference_type (type2);
4771 result_type = common_type (type1, type2);
4772 op1 = convert_to_reference (result_type, op1, CONV_IMPLICIT,
4773 LOOKUP_NORMAL, NULL_TREE);
4774 op2 = convert_to_reference (result_type, op2, CONV_IMPLICIT,
4775 LOOKUP_NORMAL, NULL_TREE);
4777 /* Quickly detect the usual case where op1 and op2 have the same type
4779 else if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2))
4782 result_type = type1;
4784 result_type = cp_build_type_variant
4786 TREE_READONLY (op1) || TREE_READONLY (op2),
4787 TREE_THIS_VOLATILE (op1) || TREE_THIS_VOLATILE (op2));
4789 else if ((code1 == INTEGER_TYPE || code1 == REAL_TYPE)
4790 && (code2 == INTEGER_TYPE || code2 == REAL_TYPE))
4792 result_type = common_type (type1, type2);
4794 else if (code1 == VOID_TYPE || code2 == VOID_TYPE)
4796 if (pedantic && (code1 != VOID_TYPE || code2 != VOID_TYPE))
4797 pedwarn ("ANSI C++ forbids conditional expr with only one void side");
4798 result_type = void_type_node;
4800 else if (code1 == POINTER_TYPE && code2 == POINTER_TYPE)
4802 if (comp_target_types (type1, type2, 1))
4803 result_type = common_type (type1, type2);
4804 else if (integer_zerop (op1) && TREE_TYPE (type1) == void_type_node
4805 && TREE_CODE (orig_op1) != NOP_EXPR)
4806 result_type = qualify_type (type2, type1);
4807 else if (integer_zerop (op2) && TREE_TYPE (type2) == void_type_node
4808 && TREE_CODE (orig_op2) != NOP_EXPR)
4809 result_type = qualify_type (type1, type2);
4810 else if (TYPE_MAIN_VARIANT (TREE_TYPE (type1)) == void_type_node)
4812 if (pedantic && TREE_CODE (type2) == FUNCTION_TYPE)
4813 pedwarn ("ANSI C++ forbids conditional expr between `void *' and function pointer");
4814 result_type = qualify_type (type1, type2);
4816 else if (TYPE_MAIN_VARIANT (TREE_TYPE (type2)) == void_type_node)
4818 if (pedantic && TREE_CODE (type1) == FUNCTION_TYPE)
4819 pedwarn ("ANSI C++ forbids conditional expr between `void *' and function pointer");
4820 result_type = qualify_type (type2, type1);
4823 else if (comptypes (type2, type1, 0))
4824 result_type = type2;
4825 else if (IS_AGGR_TYPE (TREE_TYPE (type1))
4826 && IS_AGGR_TYPE (TREE_TYPE (type2))
4827 && (result_type = common_base_type (TREE_TYPE (type1), TREE_TYPE (type2))))
4829 if (result_type == error_mark_node)
4831 cp_error ("common base type of types `%T' and `%T' is ambiguous",
4832 TREE_TYPE (type1), TREE_TYPE (type2));
4833 result_type = ptr_type_node;
4838 && result_type != TREE_TYPE (type1)
4839 && result_type != TREE_TYPE (type2))
4840 cp_pedwarn ("`%T' and `%T' converted to `%T *' in conditional expression",
4841 type1, type2, result_type);
4843 result_type = build_pointer_type (result_type);
4848 pedwarn ("pointer type mismatch in conditional expression");
4849 result_type = ptr_type_node;
4852 else if (code1 == POINTER_TYPE && code2 == INTEGER_TYPE)
4854 if (!integer_zerop (op2))
4855 pedwarn ("pointer/integer type mismatch in conditional expression");
4857 op2 = null_pointer_node;
4859 result_type = type1;
4861 else if (code2 == POINTER_TYPE && code1 == INTEGER_TYPE)
4863 if (!integer_zerop (op1))
4864 pedwarn ("pointer/integer type mismatch in conditional expression");
4866 op1 = null_pointer_node;
4868 result_type = type2;
4873 /* The match does not look good. If either is
4874 an aggregate value, try converting to a scalar type. */
4875 if (code1 == RECORD_TYPE && code2 == RECORD_TYPE)
4877 cp_error ("aggregate mismatch in conditional expression: `%T' vs `%T'", type1, type2);
4878 return error_mark_node;
4880 if (code1 == RECORD_TYPE && TYPE_HAS_CONVERSION (type1))
4882 tree tmp = build_type_conversion (CONVERT_EXPR, type2, op1, 0);
4883 if (tmp == NULL_TREE)
4885 cp_error ("aggregate type `%T' could not convert on lhs of `:'", type1);
4886 return error_mark_node;
4888 if (tmp == error_mark_node)
4889 error ("ambiguous pointer conversion");
4890 result_type = type2;
4893 else if (code2 == RECORD_TYPE && TYPE_HAS_CONVERSION (type2))
4895 tree tmp = build_type_conversion (CONVERT_EXPR, type1, op2, 0);
4896 if (tmp == NULL_TREE)
4898 cp_error ("aggregate type `%T' could not convert on rhs of `:'", type2);
4899 return error_mark_node;
4901 if (tmp == error_mark_node)
4902 error ("ambiguous pointer conversion");
4903 result_type = type1;
4906 else if (flag_cond_mismatch)
4907 result_type = void_type_node;
4910 error ("type mismatch in conditional expression");
4911 return error_mark_node;
4915 if (TREE_CODE (result_type) == POINTER_TYPE
4916 && TREE_CODE (TREE_TYPE (result_type)) == METHOD_TYPE)
4917 result_type = build_ptrmemfunc_type (result_type);
4919 if (result_type != TREE_TYPE (op1))
4920 op1 = convert_and_check (result_type, op1);
4921 if (result_type != TREE_TYPE (op2))
4922 op2 = convert_and_check (result_type, op2);
4924 if (TREE_CONSTANT (ifexp))
4925 return integer_zerop (ifexp) ? op2 : op1;
4927 return convert_from_reference
4928 (fold (build (COND_EXPR, result_type, ifexp, op1, op2)));
4931 /* Handle overloading of the ',' operator when needed. Otherwise,
4932 this function just builds an expression list. */
4934 build_x_compound_expr (list)
4937 tree rest = TREE_CHAIN (list);
4940 if (current_template_parms)
4941 return build_min_nt (COMPOUND_EXPR, list, NULL_TREE);
4943 if (rest == NULL_TREE)
4944 return build_compound_expr (list);
4946 result = build_opfncall (COMPOUND_EXPR, LOOKUP_NORMAL,
4947 TREE_VALUE (list), TREE_VALUE (rest), NULL_TREE);
4949 return build_x_compound_expr (tree_cons (NULL_TREE, result, TREE_CHAIN (rest)));
4951 if (! TREE_SIDE_EFFECTS (TREE_VALUE (list)))
4953 /* the left-hand operand of a comma expression is like an expression
4954 statement: we should warn if it doesn't have any side-effects,
4955 unless it was explicitly cast to (void). */
4956 if ((extra_warnings || warn_unused)
4957 && !(TREE_CODE (TREE_VALUE(list)) == CONVERT_EXPR
4958 && TREE_TYPE (TREE_VALUE(list)) == void_type_node))
4959 warning("left-hand operand of comma expression has no effect");
4961 #if 0 /* this requires a gcc backend patch to export warn_if_unused_value */
4962 else if (warn_unused)
4963 warn_if_unused_value (TREE_VALUE(list));
4966 return build_compound_expr (tree_cons (NULL_TREE, TREE_VALUE (list),
4967 build_tree_list (NULL_TREE, build_x_compound_expr (rest))));
4970 /* Given a list of expressions, return a compound expression
4971 that performs them all and returns the value of the last of them. */
4974 build_compound_expr (list)
4979 if (TREE_READONLY_DECL_P (TREE_VALUE (list)))
4980 TREE_VALUE (list) = decl_constant_value (TREE_VALUE (list));
4982 if (TREE_CHAIN (list) == 0)
4984 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
4985 Strip such NOP_EXPRs, since LIST is used in non-lvalue context. */
4986 if (TREE_CODE (list) == NOP_EXPR
4987 && TREE_TYPE (list) == TREE_TYPE (TREE_OPERAND (list, 0)))
4988 list = TREE_OPERAND (list, 0);
4990 /* Convert arrays to pointers. */
4991 if (TREE_CODE (TREE_TYPE (TREE_VALUE (list))) == ARRAY_TYPE)
4992 return default_conversion (TREE_VALUE (list));
4994 return TREE_VALUE (list);
4997 rest = build_compound_expr (TREE_CHAIN (list));
4999 /* When pedantic, a compound expression cannot be a constant expression. */
5000 if (! TREE_SIDE_EFFECTS (TREE_VALUE (list)) && ! pedantic)
5003 return build (COMPOUND_EXPR, TREE_TYPE (rest),
5004 break_out_cleanups (TREE_VALUE (list)), rest);
5007 tree build_static_cast (type, expr)
5010 return build_c_cast (type, expr, 0);
5013 tree build_reinterpret_cast (type, expr)
5016 tree intype = TREE_TYPE (expr);
5018 if (TYPE_PTRMEMFUNC_P (type))
5019 type = TYPE_PTRMEMFUNC_FN_TYPE (type);
5021 if (current_template_parms)
5023 tree t = build_min (REINTERPRET_CAST_EXPR, type, expr);
5027 if (TYPE_PTRMEMFUNC_P (intype))
5028 intype = TYPE_PTRMEMFUNC_FN_TYPE (intype);
5030 if (! POINTER_TYPE_P (type) && ! TREE_CODE (type) == INTEGER_TYPE)
5032 cp_error ("reinterpret_cast cannot convert to type `%T'", type);
5033 return error_mark_node;
5035 if (! POINTER_TYPE_P (intype) && ! TREE_CODE (intype) == INTEGER_TYPE)
5037 cp_error ("reinterpret_cast cannot convert from type `%T'", type);
5038 return error_mark_node;
5040 if (TREE_CODE (type) == INTEGER_TYPE && TREE_CODE (intype) != POINTER_TYPE)
5042 cp_error ("reinterpret_cast cannot convert non-pointer type `%T' to `%T'",
5044 return error_mark_node;
5046 if (TREE_CODE (intype) == INTEGER_TYPE && TREE_CODE (type) != POINTER_TYPE)
5048 cp_error ("reinterpret_cast cannot convert `%T' to non-pointer type `%T'",
5050 return error_mark_node;
5053 if (TREE_CODE (type) == POINTER_TYPE && TREE_CODE (intype) == POINTER_TYPE)
5054 expr = convert (ptr_type_node, expr);
5056 return build_c_cast (type, expr, 0);
5059 tree build_const_cast (type, expr)
5062 tree intype = TREE_TYPE (expr);
5065 if (type == error_mark_node || expr == error_mark_node)
5066 return error_mark_node;
5068 if (TYPE_PTRMEMFUNC_P (type))
5069 type = TYPE_PTRMEMFUNC_FN_TYPE (type);
5070 if (TYPE_PTRMEMFUNC_P (intype))
5071 intype = TYPE_PTRMEMFUNC_FN_TYPE (intype);
5073 if (! POINTER_TYPE_P (type))
5075 cp_error ("const_cast cannot convert to non-pointer type `%T'", type);
5076 return error_mark_node;
5078 if (TREE_CODE (type) == REFERENCE_TYPE && ! real_lvalue_p (expr))
5080 cp_error ("const_cast cannot convert rvalue to type `%T'", type);
5081 return error_mark_node;
5083 if (TREE_CODE (type) == POINTER_TYPE && TREE_CODE (intype) != POINTER_TYPE)
5085 cp_error ("const_cast cannot convert non-pointer type `%T' to type `%T'",
5087 return error_mark_node;
5090 if (TREE_CODE (type) == REFERENCE_TYPE)
5092 t1 = TREE_TYPE (type);
5097 t1 = TREE_TYPE (type);
5098 t2 = TREE_TYPE (intype);
5100 for (; TREE_CODE (t1) == POINTER_TYPE && TREE_CODE (t2) == POINTER_TYPE;
5101 t1 = TREE_TYPE (t1), t2 = TREE_TYPE (t2))
5105 if (TREE_CODE (t1) == OFFSET_TYPE && TREE_CODE (t2) == OFFSET_TYPE)
5107 if (TYPE_OFFSET_BASETYPE (t1) != TYPE_OFFSET_BASETYPE (t2))
5109 cp_error ("const_cast cannot convert between pointers to members of different types `%T' and `%T'",
5110 TYPE_OFFSET_BASETYPE (t2), TYPE_OFFSET_BASETYPE (t1));
5111 return error_mark_node;
5113 t1 = TREE_TYPE (t1);
5114 t2 = TREE_TYPE (t2);
5117 if (TYPE_MAIN_VARIANT (t1) != TYPE_MAIN_VARIANT (t2))
5119 cp_error ("const_cast cannot convert unrelated type `%T' to `%T'",
5121 return error_mark_node;
5124 return build_c_cast (type, expr, 0);
5127 /* Build an expression representing a cast to type TYPE of expression EXPR.
5129 ALLOW_NONCONVERTING is true if we should allow non-converting constructors
5130 when doing the cast. */
5133 build_c_cast (type, expr, allow_nonconverting)
5136 int allow_nonconverting;
5138 register tree value = expr;
5140 if (type == error_mark_node || expr == error_mark_node)
5141 return error_mark_node;
5143 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5144 Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */
5145 if (TREE_CODE (type) != REFERENCE_TYPE
5146 && TREE_CODE (value) == NOP_EXPR
5147 && TREE_TYPE (value) == TREE_TYPE (TREE_OPERAND (value, 0)))
5148 value = TREE_OPERAND (value, 0);
5150 if (TREE_TYPE (expr)
5151 && TREE_CODE (TREE_TYPE (expr)) == OFFSET_TYPE
5152 && TREE_CODE (type) != OFFSET_TYPE)
5153 value = resolve_offset_ref (value);
5155 if (TREE_CODE (type) == ARRAY_TYPE)
5157 /* Allow casting from T1* to T2[] because Cfront allows it.
5158 NIHCL uses it. It is not valid ANSI C however, and hence, not
5160 if (TREE_CODE (TREE_TYPE (expr)) == POINTER_TYPE)
5163 pedwarn ("ANSI C++ forbids casting to an array type");
5164 type = build_pointer_type (TREE_TYPE (type));
5168 error ("ANSI C++ forbids casting to an array type");
5169 return error_mark_node;
5173 if (TREE_CODE (type) == FUNCTION_TYPE
5174 || TREE_CODE (type) == METHOD_TYPE)
5176 cp_error ("casting to function type `%T'", type);
5177 return error_mark_node;
5180 if (IS_SIGNATURE (type))
5182 error ("cast specifies signature type");
5183 return error_mark_node;
5186 /* If there's only one function in the overloaded space,
5188 if (TREE_CODE (value) == TREE_LIST
5189 && TREE_CHAIN (value) == NULL_TREE)
5190 value = TREE_VALUE (value);
5192 if (current_template_parms)
5194 tree t = build_min (CAST_EXPR, type,
5195 min_tree_cons (NULL_TREE, value, NULL_TREE));
5199 if (TREE_CODE (type) == VOID_TYPE)
5200 value = build1 (CONVERT_EXPR, type, value);
5201 else if (TREE_TYPE (value) == NULL_TREE
5202 || type_unknown_p (value))
5204 value = instantiate_type (type, value, 1);
5206 if (value == error_mark_node)
5207 return error_mark_node;
5214 /* Convert functions and arrays to pointers and
5215 convert references to their expanded types,
5216 but don't convert any other types. */
5217 if (TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE
5218 || TREE_CODE (TREE_TYPE (value)) == METHOD_TYPE
5219 || TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE
5220 || TREE_CODE (TREE_TYPE (value)) == REFERENCE_TYPE)
5221 value = default_conversion (value);
5222 otype = TREE_TYPE (value);
5224 /* Optionally warn about potentially worrisome casts. */
5227 && TREE_CODE (type) == POINTER_TYPE
5228 && TREE_CODE (otype) == POINTER_TYPE)
5230 /* For C++ we make these regular warnings, rather than
5231 softening them into pedwarns. */
5232 if (TYPE_VOLATILE (TREE_TYPE (otype))
5233 && ! TYPE_VOLATILE (TREE_TYPE (type)))
5234 warning ("cast discards `volatile' from pointer target type");
5235 if (TYPE_READONLY (TREE_TYPE (otype))
5236 && ! TYPE_READONLY (TREE_TYPE (type)))
5237 warning ("cast discards `const' from pointer target type");
5240 /* Warn about possible alignment problems. */
5241 if (STRICT_ALIGNMENT && warn_cast_align
5242 && TREE_CODE (type) == POINTER_TYPE
5243 && TREE_CODE (otype) == POINTER_TYPE
5244 && TREE_CODE (TREE_TYPE (otype)) != VOID_TYPE
5245 && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
5246 && TYPE_ALIGN (TREE_TYPE (type)) > TYPE_ALIGN (TREE_TYPE (otype)))
5247 warning ("cast increases required alignment of target type");
5250 /* We should see about re-enabling these, they seem useful to
5252 if (TREE_CODE (type) == INTEGER_TYPE
5253 && TREE_CODE (otype) == POINTER_TYPE
5254 && TYPE_PRECISION (type) != TYPE_PRECISION (otype))
5255 warning ("cast from pointer to integer of different size");
5257 if (TREE_CODE (type) == POINTER_TYPE
5258 && TREE_CODE (otype) == INTEGER_TYPE
5259 && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
5260 /* Don't warn about converting 0 to pointer,
5261 provided the 0 was explicit--not cast or made by folding. */
5262 && !(TREE_CODE (value) == INTEGER_CST && integer_zerop (value)))
5263 warning ("cast to pointer from integer of different size");
5266 flag = allow_nonconverting ? CONV_NONCONVERTING : 0;
5268 if (TREE_CODE (type) == REFERENCE_TYPE)
5269 value = (convert_from_reference
5270 (convert_to_reference (type, value, CONV_OLD_CONVERT|flag,
5271 LOOKUP_COMPLAIN, NULL_TREE)));
5276 if (TREE_READONLY_DECL_P (value))
5277 value = decl_constant_value (value);
5280 value = convert_force (type, value, flag);
5282 /* Ignore any integer overflow caused by the cast. */
5283 if (TREE_CODE (value) == INTEGER_CST)
5285 TREE_OVERFLOW (value) = TREE_OVERFLOW (ovalue);
5286 TREE_CONSTANT_OVERFLOW (value) = TREE_CONSTANT_OVERFLOW (ovalue);
5291 /* Always produce some operator for an explicit cast,
5292 so we can tell (for -pedantic) that the cast is no lvalue.
5293 Also, pedantically, don't let (void *) (FOO *) 0 be a null
5294 pointer constant. */
5295 if (TREE_CODE (type) != REFERENCE_TYPE
5298 && TREE_CODE (value) == INTEGER_CST
5299 && TREE_CODE (expr) == INTEGER_CST
5300 && TREE_CODE (TREE_TYPE (expr)) != INTEGER_TYPE)))
5301 value = non_lvalue (value);
5307 expand_target_expr (t)
5310 extern int temp_slot_level;
5311 extern int target_temp_slot_level;
5312 int old_temp_level = target_temp_slot_level;
5314 tree xval = make_node (RTL_EXPR);
5317 /* Any TARGET_EXPR temps live only as long as the outer temp level.
5318 Since they are preserved in this new inner level, we know they
5319 will make it into the outer level. */
5321 target_temp_slot_level = temp_slot_level;
5323 do_pending_stack_adjust ();
5324 start_sequence_for_rtl_expr (xval);
5326 rtxval = expand_expr (t, NULL, VOIDmode, 0);
5327 do_pending_stack_adjust ();
5328 TREE_SIDE_EFFECTS (xval) = 1;
5329 RTL_EXPR_SEQUENCE (xval) = get_insns ();
5331 RTL_EXPR_RTL (xval) = rtxval;
5332 TREE_TYPE (xval) = TREE_TYPE (t);
5335 target_temp_slot_level = old_temp_level;
5340 /* Build an assignment expression of lvalue LHS from value RHS.
5341 MODIFYCODE is the code for a binary operator that we use
5342 to combine the old value of LHS with RHS to get the new value.
5343 Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.
5345 C++: If MODIFYCODE is INIT_EXPR, then leave references unbashed.
5348 build_modify_expr (lhs, modifycode, rhs)
5350 enum tree_code modifycode;
5353 register tree result;
5355 tree lhstype = TREE_TYPE (lhs);
5356 tree olhstype = lhstype;
5359 /* Avoid duplicate error messages from operands that had errors. */
5360 if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK)
5361 return error_mark_node;
5363 /* Types that aren't fully specified cannot be used in assignments. */
5364 lhs = require_complete_type (lhs);
5368 /* Handle assignment to signature pointers/refs. */
5370 if (TYPE_LANG_SPECIFIC (lhstype) &&
5371 (IS_SIGNATURE_POINTER (lhstype) || IS_SIGNATURE_REFERENCE (lhstype)))
5373 return build_signature_pointer_constructor (lhs, rhs);
5376 /* Handle control structure constructs used as "lvalues". */
5378 switch (TREE_CODE (lhs))
5380 /* Handle --foo = 5; as these are valid constructs in C++ */
5381 case PREDECREMENT_EXPR:
5382 case PREINCREMENT_EXPR:
5383 if (TREE_SIDE_EFFECTS (TREE_OPERAND (lhs, 0)))
5384 lhs = build (TREE_CODE (lhs), TREE_TYPE (lhs),
5385 stabilize_reference (TREE_OPERAND (lhs, 0)));
5386 return build (COMPOUND_EXPR, lhstype,
5388 build_modify_expr (TREE_OPERAND (lhs, 0),
5391 /* Handle (a, b) used as an "lvalue". */
5393 newrhs = build_modify_expr (TREE_OPERAND (lhs, 1),
5395 if (TREE_CODE (newrhs) == ERROR_MARK)
5396 return error_mark_node;
5397 return build (COMPOUND_EXPR, lhstype,
5398 TREE_OPERAND (lhs, 0), newrhs);
5401 newrhs = build_modify_expr (TREE_OPERAND (lhs, 0), modifycode, rhs);
5402 if (TREE_CODE (newrhs) == ERROR_MARK)
5403 return error_mark_node;
5404 return build (COMPOUND_EXPR, lhstype, lhs, newrhs);
5406 /* Handle (a ? b : c) used as an "lvalue". */
5408 rhs = save_expr (rhs);
5410 /* Produce (a ? (b = rhs) : (c = rhs))
5411 except that the RHS goes through a save-expr
5412 so the code to compute it is only emitted once. */
5414 = build_conditional_expr (TREE_OPERAND (lhs, 0),
5415 build_modify_expr (convert (TREE_TYPE (lhs), TREE_OPERAND (lhs, 1)),
5417 build_modify_expr (convert (TREE_TYPE (lhs), TREE_OPERAND (lhs, 2)),
5419 if (TREE_CODE (cond) == ERROR_MARK)
5421 /* Make sure the code to compute the rhs comes out
5422 before the split. */
5423 return build (COMPOUND_EXPR, TREE_TYPE (lhs),
5424 /* Case to void to suppress warning
5425 from warn_if_unused_value. */
5426 convert (void_type_node, rhs), cond);
5430 if (TREE_CODE (lhs) == OFFSET_REF)
5432 if (TREE_OPERAND (lhs, 0) == NULL_TREE)
5434 /* Static class member? */
5435 tree member = TREE_OPERAND (lhs, 1);
5436 if (TREE_CODE (member) == VAR_DECL)
5440 compiler_error ("invalid static class member");
5441 return error_mark_node;
5445 lhs = resolve_offset_ref (lhs);
5447 olhstype = lhstype = TREE_TYPE (lhs);
5450 if (TREE_CODE (lhstype) == REFERENCE_TYPE
5451 && modifycode != INIT_EXPR)
5453 lhs = convert_from_reference (lhs);
5454 olhstype = lhstype = TREE_TYPE (lhs);
5457 /* If a binary op has been requested, combine the old LHS value with the RHS
5458 producing the value we should actually store into the LHS. */
5460 if (modifycode == INIT_EXPR)
5462 if (! IS_AGGR_TYPE (lhstype))
5463 /* Do the default thing */;
5464 else if (! TYPE_HAS_CONSTRUCTOR (lhstype))
5466 cp_error ("`%T' has no constructors", lhstype);
5467 return error_mark_node;
5469 else if (TYPE_HAS_TRIVIAL_INIT_REF (lhstype)
5470 && TYPE_MAIN_VARIANT (lhstype) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs)))
5471 /* Do the default thing */;
5474 result = build_method_call (lhs, constructor_name_full (lhstype),
5475 build_tree_list (NULL_TREE, rhs),
5476 NULL_TREE, LOOKUP_NORMAL);
5477 if (result == NULL_TREE)
5478 return error_mark_node;
5482 else if (modifycode == NOP_EXPR)
5484 /* `operator=' is not an inheritable operator. */
5485 if (! IS_AGGR_TYPE (lhstype))
5486 /* Do the default thing */;
5487 else if (! TYPE_HAS_ASSIGNMENT (lhstype))
5489 cp_error ("`%T' does not define operator=", lhstype);
5490 return error_mark_node;
5492 else if (TYPE_HAS_TRIVIAL_ASSIGN_REF (lhstype)
5493 && TYPE_MAIN_VARIANT (lhstype) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs)))
5496 /* If we care about this, do overload resolution. */
5497 build_opfncall (MODIFY_EXPR, LOOKUP_NORMAL,
5498 lhs, rhs, make_node (NOP_EXPR));
5500 /* Do the default thing */;
5504 result = build_opfncall (MODIFY_EXPR, LOOKUP_NORMAL,
5505 lhs, rhs, make_node (NOP_EXPR));
5506 if (result == NULL_TREE)
5507 return error_mark_node;
5512 else if (PROMOTES_TO_AGGR_TYPE (lhstype, REFERENCE_TYPE))
5514 /* This case must convert to some sort of lvalue that
5515 can participate in an op= operation. */
5518 if (build_default_binary_type_conversion (modifycode, &lhs_tmp, &rhs_tmp))
5520 lhs = stabilize_reference (lhs_tmp);
5521 /* Forget it was ever anything else. */
5522 olhstype = lhstype = TREE_TYPE (lhs);
5523 newrhs = build_binary_op (modifycode, lhs, rhs_tmp, 1);
5527 cp_error ("no match for `%O(%#T, %#T)'", modifycode,
5528 TREE_TYPE (lhs), TREE_TYPE (rhs));
5529 return error_mark_node;
5534 lhs = stabilize_reference (lhs);
5535 newrhs = build_binary_op (modifycode, lhs, rhs, 1);
5538 /* Handle a cast used as an "lvalue".
5539 We have already performed any binary operator using the value as cast.
5540 Now convert the result to the cast type of the lhs,
5541 and then true type of the lhs and store it there;
5542 then convert result back to the cast type to be the value
5543 of the assignment. */
5545 switch (TREE_CODE (lhs))
5550 case FIX_TRUNC_EXPR:
5551 case FIX_FLOOR_EXPR:
5552 case FIX_ROUND_EXPR:
5554 if (TREE_CODE (TREE_TYPE (newrhs)) == ARRAY_TYPE
5555 || TREE_CODE (TREE_TYPE (newrhs)) == FUNCTION_TYPE
5556 || TREE_CODE (TREE_TYPE (newrhs)) == METHOD_TYPE
5557 || TREE_CODE (TREE_TYPE (newrhs)) == OFFSET_TYPE)
5558 newrhs = default_conversion (newrhs);
5560 tree inner_lhs = TREE_OPERAND (lhs, 0);
5562 if (! lvalue_p (lhs) && pedantic)
5563 pedwarn ("cast to non-reference type used as lvalue");
5565 result = build_modify_expr (inner_lhs, NOP_EXPR,
5566 convert (TREE_TYPE (inner_lhs),
5567 convert (lhstype, newrhs)));
5568 if (TREE_CODE (result) == ERROR_MARK)
5570 return convert (TREE_TYPE (lhs), result);
5574 /* Now we have handled acceptable kinds of LHS that are not truly lvalues.
5575 Reject anything strange now. */
5577 if (!lvalue_or_else (lhs, "assignment"))
5578 return error_mark_node;
5580 GNU_xref_assign (lhs);
5582 /* Warn about storing in something that is `const'. */
5583 /* For C++, don't warn if this is initialization. */
5584 if (modifycode != INIT_EXPR
5585 /* For assignment to `const' signature pointer/reference fields,
5586 don't warn either, we already printed a better message before. */
5587 && ! (TREE_CODE (lhs) == COMPONENT_REF
5588 && (IS_SIGNATURE_POINTER (TREE_TYPE (TREE_OPERAND (lhs, 0)))
5589 || IS_SIGNATURE_REFERENCE (TREE_TYPE (TREE_OPERAND (lhs, 0)))))
5590 && (TREE_READONLY (lhs) || TYPE_READONLY (lhstype)
5591 || ((TREE_CODE (lhstype) == RECORD_TYPE
5592 || TREE_CODE (lhstype) == UNION_TYPE)
5593 && C_TYPE_FIELDS_READONLY (lhstype))
5594 || (TREE_CODE (lhstype) == REFERENCE_TYPE
5595 && TYPE_READONLY (TREE_TYPE (lhstype)))))
5596 readonly_error (lhs, "assignment", 0);
5598 /* If storing into a structure or union member,
5599 it has probably been given type `int'.
5600 Compute the type that would go with
5601 the actual amount of storage the member occupies. */
5603 if (TREE_CODE (lhs) == COMPONENT_REF
5604 && (TREE_CODE (lhstype) == INTEGER_TYPE
5605 || TREE_CODE (lhstype) == REAL_TYPE
5606 || TREE_CODE (lhstype) == ENUMERAL_TYPE))
5608 lhstype = TREE_TYPE (get_unwidened (lhs, 0));
5610 /* If storing in a field that is in actuality a short or narrower
5611 than one, we must store in the field in its actual type. */
5613 if (lhstype != TREE_TYPE (lhs))
5615 lhs = copy_node (lhs);
5616 TREE_TYPE (lhs) = lhstype;
5620 /* check to see if there is an assignment to `this' */
5621 if (lhs == current_class_decl)
5623 if (flag_this_is_variable > 0
5624 && DECL_NAME (current_function_decl) != NULL_TREE
5625 && (DECL_NAME (current_function_decl)
5626 != constructor_name (current_class_type)))
5627 warning ("assignment to `this' not in constructor or destructor");
5628 current_function_just_assigned_this = 1;
5631 /* The TREE_TYPE of RHS may be TYPE_UNKNOWN. This can happen
5632 when the type of RHS is not yet known, i.e. its type
5633 is inherited from LHS. */
5634 rhs = require_instantiated_type (lhstype, newrhs, error_mark_node);
5635 if (rhs == error_mark_node)
5636 return error_mark_node;
5639 if (modifycode != INIT_EXPR)
5641 /* Make modifycode now either a NOP_EXPR or an INIT_EXPR. */
5642 modifycode = NOP_EXPR;
5643 /* Reference-bashing */
5644 if (TREE_CODE (lhstype) == REFERENCE_TYPE)
5646 tree tmp = convert_from_reference (lhs);
5647 lhstype = TREE_TYPE (tmp);
5648 if (TYPE_SIZE (lhstype) == 0)
5650 incomplete_type_error (lhs, lhstype);
5651 return error_mark_node;
5656 if (TREE_CODE (TREE_TYPE (newrhs)) == REFERENCE_TYPE)
5658 tree tmp = convert_from_reference (newrhs);
5659 if (TYPE_SIZE (TREE_TYPE (tmp)) == 0)
5661 incomplete_type_error (newrhs, TREE_TYPE (tmp));
5662 return error_mark_node;
5668 if (TREE_SIDE_EFFECTS (lhs))
5669 lhs = stabilize_reference (lhs);
5670 if (TREE_SIDE_EFFECTS (newrhs))
5671 newrhs = stabilize_reference (newrhs);
5673 /* Convert new value to destination type. */
5675 if (TREE_CODE (lhstype) == ARRAY_TYPE)
5679 if (! comptypes (lhstype, TREE_TYPE (rhs), 0))
5681 cp_error ("incompatible types in assignment of `%T' to `%T'",
5682 TREE_TYPE (rhs), lhstype);
5683 return error_mark_node;
5686 /* Allow array assignment in compiler-generated code. */
5687 if (pedantic && ! DECL_ARTIFICIAL (current_function_decl))
5688 pedwarn ("ANSI C++ forbids assignment of arrays");
5690 /* Have to wrap this in RTL_EXPR for two cases:
5691 in base or member initialization and if we
5692 are a branch of a ?: operator. Since we
5693 can't easily know the latter, just do it always. */
5695 result = make_node (RTL_EXPR);
5697 TREE_TYPE (result) = void_type_node;
5698 do_pending_stack_adjust ();
5699 start_sequence_for_rtl_expr (result);
5701 /* As a matter of principle, `start_sequence' should do this. */
5704 from_array = TREE_CODE (TREE_TYPE (newrhs)) == ARRAY_TYPE
5705 ? 1 + (modifycode != INIT_EXPR): 0;
5706 expand_vec_init (lhs, lhs, array_type_nelts (lhstype), newrhs,
5709 do_pending_stack_adjust ();
5711 TREE_SIDE_EFFECTS (result) = 1;
5712 RTL_EXPR_SEQUENCE (result) = get_insns ();
5713 RTL_EXPR_RTL (result) = const0_rtx;
5718 if (modifycode == INIT_EXPR)
5720 newrhs = convert_for_initialization (lhs, lhstype, newrhs, LOOKUP_NORMAL,
5721 "assignment", NULL_TREE, 0);
5722 if (lhs == DECL_RESULT (current_function_decl))
5724 if (DECL_INITIAL (lhs))
5725 warning ("return value from function receives multiple initializations");
5726 DECL_INITIAL (lhs) = newrhs;
5731 /* Avoid warnings on enum bit fields. */
5732 if (TREE_CODE (olhstype) == ENUMERAL_TYPE
5733 && TREE_CODE (lhstype) == INTEGER_TYPE)
5735 newrhs = convert_for_assignment (olhstype, newrhs, "assignment",
5737 newrhs = convert_force (lhstype, newrhs, 0);
5740 newrhs = convert_for_assignment (lhstype, newrhs, "assignment",
5742 if (TREE_CODE (newrhs) == CALL_EXPR
5743 && TYPE_NEEDS_CONSTRUCTING (lhstype))
5744 newrhs = build_cplus_new (lhstype, newrhs);
5746 /* Can't initialize directly from a TARGET_EXPR, since that would
5747 cause the lhs to be constructed twice, and possibly result in
5748 accidental self-initialization. So we force the TARGET_EXPR to be
5749 expanded without a target. */
5750 if (TREE_CODE (newrhs) == TARGET_EXPR)
5751 newrhs = build (COMPOUND_EXPR, TREE_TYPE (newrhs), newrhs,
5752 TREE_VALUE (newrhs));
5755 if (TREE_CODE (newrhs) == ERROR_MARK)
5756 return error_mark_node;
5758 if (TREE_CODE (newrhs) == COND_EXPR)
5761 tree cond = TREE_OPERAND (newrhs, 0);
5763 if (TREE_SIDE_EFFECTS (lhs))
5764 cond = build_compound_expr (tree_cons
5766 build_tree_list (NULL_TREE, cond)));
5768 /* Cannot have two identical lhs on this one tree (result) as preexpand
5769 calls will rip them out and fill in RTL for them, but when the
5770 rtl is generated, the calls will only be in the first side of the
5771 condition, not on both, or before the conditional jump! (mrs) */
5772 lhs1 = break_out_calls (lhs);
5775 /* If there's no change, the COND_EXPR behaves like any other rhs. */
5776 result = build (modifycode == NOP_EXPR ? MODIFY_EXPR : INIT_EXPR,
5777 lhstype, lhs, newrhs);
5780 tree result_type = TREE_TYPE (newrhs);
5781 /* We have to convert each arm to the proper type because the
5782 types may have been munged by constant folding. */
5784 = build (COND_EXPR, result_type, cond,
5785 build_modify_expr (lhs, modifycode,
5786 convert (result_type,
5787 TREE_OPERAND (newrhs, 1))),
5788 build_modify_expr (lhs1, modifycode,
5789 convert (result_type,
5790 TREE_OPERAND (newrhs, 2))));
5794 result = build (modifycode == NOP_EXPR ? MODIFY_EXPR : INIT_EXPR,
5795 lhstype, lhs, newrhs);
5797 TREE_SIDE_EFFECTS (result) = 1;
5799 /* If we got the LHS in a different type for storing in,
5800 convert the result back to the nominal type of LHS
5801 so that the value we return always has the same type
5802 as the LHS argument. */
5804 if (olhstype == TREE_TYPE (result))
5806 /* Avoid warnings converting integral types back into enums
5807 for enum bit fields. */
5808 if (TREE_CODE (TREE_TYPE (result)) == INTEGER_TYPE
5809 && TREE_CODE (olhstype) == ENUMERAL_TYPE)
5811 result = build (COMPOUND_EXPR, olhstype, result, olhs);
5812 TREE_NO_UNUSED_WARNING (result) = 1;
5815 return convert_for_assignment (olhstype, result, "assignment",
5820 build_x_modify_expr (lhs, modifycode, rhs)
5822 enum tree_code modifycode;
5825 if (current_template_parms)
5826 return build_min_nt (MODOP_EXPR, lhs,
5827 build_min_nt (modifycode, 0, 0), rhs);
5829 if (modifycode != NOP_EXPR)
5831 tree rval = build_opfncall (MODIFY_EXPR, LOOKUP_NORMAL, lhs, rhs,
5832 make_node (modifycode));
5836 return build_modify_expr (lhs, modifycode, rhs);
5839 /* Return 0 if EXP is not a valid lvalue in this language
5840 even though `lvalue_or_else' would accept it. */
5843 language_lvalue_valid (exp)
5849 /* Get difference in deltas for different pointer to member function
5850 types. Return integer_zero_node, if FROM cannot be converted to a
5851 TO type. If FORCE is true, then allow reverse conversions as well. */
5853 get_delta_difference (from, to, force)
5857 tree delta = integer_zero_node;
5863 /* Should get_base_distance here, so we can check if any thing along the
5864 path is virtual, and we need to make sure we stay
5865 inside the real binfos when going through virtual bases.
5866 Maybe we should replace virtual bases with
5867 binfo_member (...CLASSTYPE_VBASECLASSES...)... (mrs) */
5868 binfo = get_binfo (from, to, 1);
5869 if (binfo == error_mark_node)
5871 error (" in pointer to member function conversion");
5878 error_not_base_type (from, to);
5879 error (" in pointer to member function conversion");
5882 binfo = get_binfo (to, from, 1);
5883 if (binfo == error_mark_node)
5885 error (" in pointer to member function conversion");
5890 error ("cannot convert pointer to member of type %T to unrelated pointer to member of type %T", from, to);
5893 if (TREE_VIA_VIRTUAL (binfo))
5895 warning ("pointer to member conversion to virtual base class will only work if you are very careful");
5897 return build_binary_op (MINUS_EXPR,
5899 BINFO_OFFSET (binfo), 1);
5901 if (TREE_VIA_VIRTUAL (binfo))
5903 warning ("pointer to member conversion from virtual base class will only work if you are very careful");
5905 return BINFO_OFFSET (binfo);
5908 /* Build a constructor for a pointer to member function. It can be
5909 used to initialize global variables, local variable, or used
5910 as a value in expressions. TYPE is the POINTER to METHOD_TYPE we
5913 If FORCE is non-zero, then force this conversion, even if
5914 we would rather not do it. Usually set when using an explicit
5917 Return error_mark_node, if something goes wrong. */
5920 build_ptrmemfunc (type, pfn, force)
5924 tree index = integer_zero_node;
5925 tree delta = integer_zero_node;
5926 tree delta2 = integer_zero_node;
5931 /* Handle multiple conversions of pointer to member functions. */
5932 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (pfn)))
5934 tree ndelta, ndelta2, nindex;
5935 /* Is is already the right type? */
5936 if (type == TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn)))
5939 if (TREE_CODE (pfn) != CONSTRUCTOR)
5942 ndelta = convert (ptrdiff_type_node, build_component_ref (pfn, delta_identifier, 0, 0));
5943 ndelta2 = convert (ptrdiff_type_node, DELTA2_FROM_PTRMEMFUNC (pfn));
5944 index = build_component_ref (pfn, index_identifier, 0, 0);
5945 delta = get_delta_difference (TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn)))),
5946 TYPE_METHOD_BASETYPE (TREE_TYPE (type)),
5948 delta = build_binary_op (PLUS_EXPR, delta, ndelta, 1);
5949 delta2 = build_binary_op (PLUS_EXPR, ndelta2, delta2, 1);
5950 e1 = fold (build (GT_EXPR, boolean_type_node, index, integer_zero_node));
5952 u = build_nt (CONSTRUCTOR, 0, tree_cons (delta2_identifier, delta2, NULL_TREE));
5953 u = build_nt (CONSTRUCTOR, 0, tree_cons (NULL_TREE, delta,
5954 tree_cons (NULL_TREE, index,
5955 tree_cons (NULL_TREE, u, NULL_TREE))));
5956 e2 = digest_init (TYPE_GET_PTRMEMFUNC_TYPE (type), u, (tree*)0);
5958 pfn = PFN_FROM_PTRMEMFUNC (pfn);
5959 npfn = build1 (NOP_EXPR, type, pfn);
5960 TREE_CONSTANT (npfn) = TREE_CONSTANT (pfn);
5962 u = build_nt (CONSTRUCTOR, 0, tree_cons (pfn_identifier, npfn, NULL_TREE));
5963 u = build_nt (CONSTRUCTOR, 0, tree_cons (NULL_TREE, delta,
5964 tree_cons (NULL_TREE, index,
5965 tree_cons (NULL_TREE, u, NULL_TREE))));
5966 e3 = digest_init (TYPE_GET_PTRMEMFUNC_TYPE (type), u, (tree*)0);
5967 return build_conditional_expr (e1, e2, e3);
5970 ndelta = TREE_VALUE (CONSTRUCTOR_ELTS (pfn));
5971 nindex = TREE_VALUE (TREE_CHAIN (CONSTRUCTOR_ELTS (pfn)));
5972 npfn = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (CONSTRUCTOR_ELTS (pfn))));
5973 npfn = TREE_VALUE (CONSTRUCTOR_ELTS (npfn));
5974 if (integer_zerop (nindex))
5975 pfn = integer_zero_node;
5976 else if (integer_zerop (fold (size_binop (PLUS_EXPR, nindex, integer_one_node))))
5979 delta = get_delta_difference (TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn)))),
5980 TYPE_METHOD_BASETYPE (TREE_TYPE (type)),
5982 delta = build_binary_op (PLUS_EXPR, delta, ndelta, 1);
5983 pfn = build1 (NOP_EXPR, type, npfn);
5984 TREE_CONSTANT (pfn) = TREE_CONSTANT (npfn);
5986 u = build_nt (CONSTRUCTOR, 0, tree_cons (pfn_identifier, pfn, NULL_TREE));
5987 u = build_nt (CONSTRUCTOR, 0, tree_cons (NULL_TREE, delta,
5988 tree_cons (NULL_TREE, nindex,
5989 tree_cons (NULL_TREE, u, NULL_TREE))));
5990 e3 = digest_init (TYPE_GET_PTRMEMFUNC_TYPE (type), u, (tree*)0);
5995 sorry ("value casting of variable nonnull pointer to member functions not supported");
5996 return error_mark_node;
6000 /* Handle null pointer to member function conversions. */
6001 if (integer_zerop (pfn))
6003 pfn = build_c_cast (type, integer_zero_node, 0);
6004 u = build_nt (CONSTRUCTOR, 0, tree_cons (pfn_identifier, pfn, NULL_TREE));
6005 u = build_nt (CONSTRUCTOR, 0, tree_cons (NULL_TREE, integer_zero_node,
6006 tree_cons (NULL_TREE, integer_zero_node,
6007 tree_cons (NULL_TREE, u, NULL_TREE))));
6008 return digest_init (TYPE_GET_PTRMEMFUNC_TYPE (type), u, (tree*)0);
6011 if (TREE_CODE (pfn) == TREE_LIST
6012 || (TREE_CODE (pfn) == ADDR_EXPR
6013 && TREE_CODE (TREE_OPERAND (pfn, 0)) == TREE_LIST))
6015 pfn = instantiate_type (type, pfn, 1);
6016 if (pfn == error_mark_node)
6017 return error_mark_node;
6018 if (TREE_CODE (pfn) != ADDR_EXPR)
6019 pfn = build_unary_op (ADDR_EXPR, pfn, 0);
6022 /* Allow pointer to member conversions here. */
6023 delta = get_delta_difference (TYPE_METHOD_BASETYPE (TREE_TYPE (TREE_TYPE (pfn))),
6024 TYPE_METHOD_BASETYPE (TREE_TYPE (type)),
6026 delta2 = build_binary_op (PLUS_EXPR, delta2, delta, 1);
6028 if (TREE_CODE (TREE_OPERAND (pfn, 0)) != FUNCTION_DECL)
6029 warning ("assuming pointer to member function is non-virtual");
6031 if (TREE_CODE (TREE_OPERAND (pfn, 0)) == FUNCTION_DECL
6032 && DECL_VINDEX (TREE_OPERAND (pfn, 0)))
6034 /* Find the offset to the vfield pointer in the object. */
6035 vfield_offset = get_binfo (DECL_CONTEXT (TREE_OPERAND (pfn, 0)),
6036 DECL_CLASS_CONTEXT (TREE_OPERAND (pfn, 0)),
6038 vfield_offset = get_vfield_offset (vfield_offset);
6039 delta2 = size_binop (PLUS_EXPR, vfield_offset, delta2);
6041 /* Map everything down one to make room for the null pointer to member. */
6042 index = size_binop (PLUS_EXPR,
6043 DECL_VINDEX (TREE_OPERAND (pfn, 0)),
6045 u = build_nt (CONSTRUCTOR, 0, tree_cons (delta2_identifier, delta2, NULL_TREE));
6049 index = size_binop (MINUS_EXPR, integer_zero_node, integer_one_node);
6051 npfn = build1 (NOP_EXPR, type, pfn);
6052 TREE_CONSTANT (npfn) = TREE_CONSTANT (pfn);
6054 u = build_nt (CONSTRUCTOR, 0, tree_cons (pfn_identifier, npfn, NULL_TREE));
6057 u = build_nt (CONSTRUCTOR, 0, tree_cons (NULL_TREE, delta,
6058 tree_cons (NULL_TREE, index,
6059 tree_cons (NULL_TREE, u, NULL_TREE))));
6060 return digest_init (TYPE_GET_PTRMEMFUNC_TYPE (type), u, (tree*)0);
6063 /* Convert value RHS to type TYPE as preparation for an assignment
6064 to an lvalue of type TYPE.
6065 The real work of conversion is done by `convert'.
6066 The purpose of this function is to generate error messages
6067 for assignments that are not allowed in C.
6068 ERRTYPE is a string to use in error messages:
6069 "assignment", "return", etc.
6071 C++: attempts to allow `convert' to find conversions involving
6072 implicit type conversion between aggregate and scalar types
6073 as per 8.5.6 of C++ manual. Does not randomly dereference
6074 pointers to aggregates! */
6077 convert_for_assignment (type, rhs, errtype, fndecl, parmnum)
6083 register enum tree_code codel = TREE_CODE (type);
6084 register tree rhstype;
6085 register enum tree_code coder = TREE_CODE (TREE_TYPE (rhs));
6087 if (coder == UNKNOWN_TYPE)
6088 rhs = instantiate_type (type, rhs, 1);
6090 if (coder == ERROR_MARK)
6091 return error_mark_node;
6093 if (codel == OFFSET_TYPE)
6095 type = TREE_TYPE (type);
6096 codel = TREE_CODE (type);
6099 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
6100 if (TREE_CODE (rhs) == NON_LVALUE_EXPR)
6101 rhs = TREE_OPERAND (rhs, 0);
6103 if (rhs == error_mark_node)
6104 return error_mark_node;
6106 if (TREE_VALUE (rhs) == error_mark_node)
6107 return error_mark_node;
6109 if (TREE_CODE (TREE_TYPE (rhs)) == OFFSET_TYPE)
6111 rhs = resolve_offset_ref (rhs);
6112 if (rhs == error_mark_node)
6113 return error_mark_node;
6114 rhstype = TREE_TYPE (rhs);
6115 coder = TREE_CODE (rhstype);
6118 if (TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE
6119 || TREE_CODE (TREE_TYPE (rhs)) == FUNCTION_TYPE
6120 || TREE_CODE (TREE_TYPE (rhs)) == METHOD_TYPE)
6121 rhs = default_conversion (rhs);
6122 else if (TREE_CODE (TREE_TYPE (rhs)) == REFERENCE_TYPE)
6123 rhs = convert_from_reference (rhs);
6125 rhstype = TREE_TYPE (rhs);
6126 coder = TREE_CODE (rhstype);
6128 /* This should no longer change types on us. */
6129 if (TREE_CODE (rhs) == CONST_DECL)
6130 rhs = DECL_INITIAL (rhs);
6131 else if (TREE_READONLY_DECL_P (rhs))
6132 rhs = decl_constant_value (rhs);
6134 if (type == rhstype)
6136 overflow_warning (rhs);
6140 if (coder == VOID_TYPE)
6142 error ("void value not ignored as it ought to be");
6143 return error_mark_node;
6145 /* Arithmetic types all interconvert. */
6146 if ((codel == INTEGER_TYPE || codel == REAL_TYPE || codel == BOOLEAN_TYPE)
6147 && (coder == INTEGER_TYPE || coder == REAL_TYPE || coder == BOOLEAN_TYPE))
6149 /* But we should warn if assigning REAL_TYPE to INTEGER_TYPE. */
6150 if (coder == REAL_TYPE && codel == INTEGER_TYPE)
6153 cp_warning ("`%T' used for argument %P of `%D'",
6154 rhstype, parmnum, fndecl);
6156 cp_warning ("%s to `%T' from `%T'", errtype, type, rhstype);
6158 /* And we should warn if assigning a negative value to
6159 an unsigned variable. */
6160 else if (TREE_UNSIGNED (type) && codel != BOOLEAN_TYPE)
6162 if (TREE_CODE (rhs) == INTEGER_CST
6163 && TREE_NEGATED_INT (rhs))
6166 cp_warning ("negative value `%E' passed as argument %P of `%D'",
6167 rhs, parmnum, fndecl);
6169 cp_warning ("%s of negative value `%E' to `%T'",
6170 errtype, rhs, type);
6172 overflow_warning (rhs);
6173 if (TREE_CONSTANT (rhs))
6177 return convert_and_check (type, rhs);
6179 /* Conversions involving enums. */
6180 else if ((codel == ENUMERAL_TYPE
6181 && (INTEGRAL_CODE_P (coder) || coder == REAL_TYPE))
6182 || (coder == ENUMERAL_TYPE
6183 && (INTEGRAL_CODE_P (codel) || codel == REAL_TYPE)))
6185 return cp_convert (type, rhs, CONV_IMPLICIT, LOOKUP_NORMAL);
6187 /* Conversions among pointers */
6188 else if (codel == POINTER_TYPE
6189 && (coder == POINTER_TYPE
6190 || (coder == RECORD_TYPE
6191 && (IS_SIGNATURE_POINTER (rhstype)
6192 || IS_SIGNATURE_REFERENCE (rhstype)))))
6194 register tree ttl = TREE_TYPE (type);
6198 if (coder == RECORD_TYPE)
6200 rhs = build_optr_ref (rhs);
6201 rhstype = TREE_TYPE (rhs);
6203 ttr = TREE_TYPE (rhstype);
6205 /* If both pointers are of aggregate type, then we
6206 can give better error messages, and save some work
6208 if (TREE_CODE (ttl) == RECORD_TYPE && TREE_CODE (ttr) == RECORD_TYPE)
6212 if (TYPE_MAIN_VARIANT (ttl) == TYPE_MAIN_VARIANT (ttr)
6213 || type == class_star_type_node
6214 || rhstype == class_star_type_node)
6215 binfo = TYPE_BINFO (ttl);
6217 binfo = get_binfo (ttl, ttr, 1);
6219 if (binfo == error_mark_node)
6220 return error_mark_node;
6222 return error_not_base_type (ttl, ttr);
6224 if (! TYPE_READONLY (ttl) && TYPE_READONLY (ttr))
6227 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6228 rhstype, parmnum, fndecl);
6230 cp_pedwarn ("%s to `%T' from `%T' discards const",
6231 errtype, type, rhstype);
6233 if (! TYPE_VOLATILE (ttl) && TYPE_VOLATILE (ttr))
6236 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6237 rhstype, parmnum, fndecl);
6239 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6240 errtype, type, rhstype);
6244 /* Any non-function converts to a [const][volatile] void *
6245 and vice versa; otherwise, targets must be the same.
6246 Meanwhile, the lhs target must have all the qualifiers of the rhs. */
6247 else if (TYPE_MAIN_VARIANT (ttl) == void_type_node
6248 || TYPE_MAIN_VARIANT (ttr) == void_type_node
6249 || (ctt = comp_target_types (type, rhstype, 1))
6250 || (unsigned_type (TYPE_MAIN_VARIANT (ttl))
6251 == unsigned_type (TYPE_MAIN_VARIANT (ttr))))
6253 /* ARM $4.8, commentary on p39. */
6254 if (TYPE_MAIN_VARIANT (ttl) == void_type_node
6255 && TREE_CODE (ttr) == OFFSET_TYPE)
6257 cp_error ("no standard conversion from `%T' to `void *'", ttr);
6258 return error_mark_node;
6262 cp_pedwarn ("converting `%T' to `%T' is a contravariance violation",
6265 if (TYPE_MAIN_VARIANT (ttl) != void_type_node
6266 && TYPE_MAIN_VARIANT (ttr) == void_type_node
6267 && rhs != null_pointer_node)
6269 if (coder == RECORD_TYPE)
6270 cp_pedwarn ("implicit conversion of signature pointer to type `%T'",
6273 pedwarn ("ANSI C++ forbids implicit conversion from `void *' in %s",
6276 /* Const and volatile mean something different for function types,
6277 so the usual warnings are not appropriate. */
6278 else if ((TREE_CODE (ttr) != FUNCTION_TYPE && TREE_CODE (ttr) != METHOD_TYPE)
6279 || (TREE_CODE (ttl) != FUNCTION_TYPE && TREE_CODE (ttl) != METHOD_TYPE))
6281 if (TREE_CODE (ttl) == OFFSET_TYPE
6282 && binfo_member (TYPE_OFFSET_BASETYPE (ttr),
6283 CLASSTYPE_VBASECLASSES (TYPE_OFFSET_BASETYPE (ttl))))
6285 sorry ("%s between pointer to members converting across virtual baseclasses", errtype);
6286 return error_mark_node;
6288 else if (! TYPE_READONLY (ttl) && TYPE_READONLY (ttr))
6291 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6292 rhstype, parmnum, fndecl);
6294 cp_pedwarn ("%s to `%T' from `%T' discards const",
6295 errtype, type, rhstype);
6297 else if (! TYPE_VOLATILE (ttl) && TYPE_VOLATILE (ttr))
6300 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6301 rhstype, parmnum, fndecl);
6303 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6304 errtype, type, rhstype);
6306 else if (TREE_CODE (ttl) == TREE_CODE (ttr)
6307 && ! comp_target_types (type, rhstype, 1))
6310 cp_pedwarn ("passing `%T' as argument %P of `%D' changes signedness",
6311 rhstype, parmnum, fndecl);
6313 cp_pedwarn ("%s to `%T' from `%T' changes signedness",
6314 errtype, type, rhstype);
6318 else if (TREE_CODE (ttr) == OFFSET_TYPE
6319 && TREE_CODE (ttl) != OFFSET_TYPE)
6321 /* Normally, pointers to different type codes (other
6322 than void) are not compatible, but we perform
6323 some type instantiation if that resolves the
6324 ambiguity of (X Y::*) and (X *). */
6326 if (current_class_decl)
6328 if (TREE_CODE (rhs) == INTEGER_CST)
6330 rhs = build (PLUS_EXPR, build_pointer_type (TREE_TYPE (ttr)),
6331 current_class_decl, rhs);
6332 return convert_for_assignment (type, rhs,
6333 errtype, fndecl, parmnum);
6336 if (TREE_CODE (ttl) == METHOD_TYPE)
6337 error ("%s between pointer-to-method and pointer-to-member types",
6340 error ("%s between pointer and pointer-to-member types", errtype);
6341 return error_mark_node;
6345 int add_quals = 0, const_parity = 0, volatile_parity = 0;
6347 int unsigned_parity;
6350 /* This code is basically a duplicate of comp_ptr_ttypes_real. */
6351 for (; ; ttl = TREE_TYPE (ttl), ttr = TREE_TYPE (ttr))
6354 const_parity |= (TYPE_READONLY (ttl) < TYPE_READONLY (ttr));
6355 volatile_parity |= (TYPE_VOLATILE (ttl) < TYPE_VOLATILE (ttr));
6358 && (TYPE_READONLY (ttl) > TYPE_READONLY (ttr)
6359 || TYPE_VOLATILE (ttl) > TYPE_VOLATILE (ttr)))
6361 left_const &= TYPE_READONLY (ttl);
6363 if (TREE_CODE (ttl) != POINTER_TYPE
6364 || TREE_CODE (ttr) != POINTER_TYPE)
6367 unsigned_parity = TREE_UNSIGNED (ttl) - TREE_UNSIGNED (ttr);
6368 if (unsigned_parity)
6370 if (TREE_UNSIGNED (ttl))
6371 ttr = unsigned_type (ttr);
6373 ttl = unsigned_type (ttl);
6376 if (comp_target_types (ttl, ttr, nptrs) > 0)
6381 cp_pedwarn ("passing `%T' as argument %P of `%D' adds cv-quals without intervening `const'",
6382 rhstype, parmnum, fndecl);
6384 cp_pedwarn ("%s to `%T' from `%T' adds cv-quals without intervening `const'",
6385 errtype, type, rhstype);
6390 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6391 rhstype, parmnum, fndecl);
6393 cp_pedwarn ("%s to `%T' from `%T' discards const",
6394 errtype, type, rhstype);
6396 if (volatile_parity)
6399 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6400 rhstype, parmnum, fndecl);
6402 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6403 errtype, type, rhstype);
6405 if (unsigned_parity > 0)
6408 cp_pedwarn ("passing `%T' as argument %P of `%D' changes signed to unsigned",
6409 rhstype, parmnum, fndecl);
6411 cp_pedwarn ("%s to `%T' from `%T' changes signed to unsigned",
6412 errtype, type, rhstype);
6414 else if (unsigned_parity < 0)
6417 cp_pedwarn ("passing `%T' as argument %P of `%D' changes unsigned to signed",
6418 rhstype, parmnum, fndecl);
6420 cp_pedwarn ("%s to `%T' from `%T' changes unsigned to signed",
6421 errtype, type, rhstype);
6424 /* C++ is not so friendly about converting function and
6425 member function pointers as C. Emit warnings here. */
6426 if (TREE_CODE (ttl) == FUNCTION_TYPE
6427 || TREE_CODE (ttl) == METHOD_TYPE)
6428 if (! comptypes (ttl, ttr, 0))
6430 warning ("conflicting function types in %s:", errtype);
6431 cp_warning ("\t`%T' != `%T'", type, rhstype);
6434 else if (TREE_CODE (TREE_TYPE (rhs)) == METHOD_TYPE)
6436 /* When does this happen? */
6437 my_friendly_abort (119);
6438 /* Conversion of a pointer-to-member type to void *. */
6439 rhs = build_unary_op (ADDR_EXPR, rhs, 0);
6440 TREE_TYPE (rhs) = type;
6443 else if (TREE_CODE (TREE_TYPE (rhs)) == OFFSET_TYPE)
6445 /* When does this happen? */
6446 my_friendly_abort (120);
6447 /* Conversion of a pointer-to-member type to void *. */
6448 rhs = build_unary_op (ADDR_EXPR, rhs, 0);
6449 TREE_TYPE (rhs) = type;
6455 cp_error ("passing `%T' as argument %P of `%D'",
6456 rhstype, parmnum, fndecl);
6458 cp_error ("%s to `%T' from `%T'", errtype, type, rhstype);
6459 return error_mark_node;
6462 return convert (type, rhs);
6464 else if (codel == POINTER_TYPE && coder == INTEGER_TYPE)
6466 /* An explicit constant 0 can convert to a pointer,
6467 but not a 0 that results from casting or folding. */
6468 if (! (TREE_CODE (rhs) == INTEGER_CST && integer_zerop (rhs)))
6471 cp_pedwarn ("passing `%T' to argument %P of `%D' lacks a cast",
6472 rhstype, parmnum, fndecl);
6474 cp_pedwarn ("%s to `%T' from `%T' lacks a cast",
6475 errtype, type, rhstype);
6476 return convert (type, rhs);
6478 return null_pointer_node;
6480 else if (codel == INTEGER_TYPE
6481 && (coder == POINTER_TYPE
6482 || (coder == RECORD_TYPE
6483 && (IS_SIGNATURE_POINTER (rhstype)
6484 || TYPE_PTRMEMFUNC_FLAG (rhstype)
6485 || IS_SIGNATURE_REFERENCE (rhstype)))))
6488 cp_pedwarn ("passing `%T' to argument %P of `%D' lacks a cast",
6489 rhstype, parmnum, fndecl);
6491 cp_pedwarn ("%s to `%T' from `%T' lacks a cast",
6492 errtype, type, rhstype);
6493 return convert (type, rhs);
6495 else if (codel == BOOLEAN_TYPE
6496 && (coder == POINTER_TYPE
6497 || (coder == RECORD_TYPE
6498 && (IS_SIGNATURE_POINTER (rhstype)
6499 || TYPE_PTRMEMFUNC_FLAG (rhstype)
6500 || IS_SIGNATURE_REFERENCE (rhstype)))))
6501 return convert (type, rhs);
6504 else if (((coder == POINTER_TYPE
6505 && TREE_CODE (TREE_TYPE (rhstype)) == METHOD_TYPE)
6506 || integer_zerop (rhs)
6507 || TYPE_PTRMEMFUNC_P (rhstype))
6508 && TYPE_PTRMEMFUNC_P (type))
6510 tree ttl = TYPE_PTRMEMFUNC_FN_TYPE (type);
6511 tree ttr = (TREE_CODE (rhstype) == POINTER_TYPE ? rhstype
6512 : TYPE_PTRMEMFUNC_FN_TYPE (type));
6513 int ctt = comp_target_types (ttl, ttr, 1);
6516 cp_pedwarn ("converting `%T' to `%T' is a contravariance violation",
6519 cp_error ("%s to `%T' from `%T'", errtype, ttl, ttr);
6521 /* compatible pointer to member functions. */
6522 return build_ptrmemfunc (ttl, rhs, 0);
6524 else if (codel == ERROR_MARK || coder == ERROR_MARK)
6525 return error_mark_node;
6527 /* This should no longer happen. References are initialized via
6528 `convert_for_initialization'. They should otherwise be
6529 bashed before coming here. */
6530 else if (codel == REFERENCE_TYPE)
6531 my_friendly_abort (317);
6532 else if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (TREE_TYPE (rhs)))
6534 tree nrhs = build1 (NOP_EXPR, type, rhs);
6535 TREE_CONSTANT (nrhs) = TREE_CONSTANT (rhs);
6538 else if (TYPE_HAS_CONSTRUCTOR (type) || IS_AGGR_TYPE (TREE_TYPE (rhs)))
6539 return convert (type, rhs);
6541 cp_error ("%s to `%T' from `%T'", errtype, type, rhstype);
6542 return error_mark_node;
6545 /* Convert RHS to be of type TYPE. If EXP is non-zero,
6546 it is the target of the initialization.
6547 ERRTYPE is a string to use in error messages.
6549 Two major differences between the behavior of
6550 `convert_for_assignment' and `convert_for_initialization'
6551 are that references are bashed in the former, while
6552 copied in the latter, and aggregates are assigned in
6553 the former (operator=) while initialized in the
6556 If using constructor make sure no conversion operator exists, if one does
6557 exist, an ambiguity exists.
6559 If flags doesn't include LOOKUP_COMPLAIN, don't complain about anything. */
6561 convert_for_initialization (exp, type, rhs, flags, errtype, fndecl, parmnum)
6562 tree exp, type, rhs;
6568 register enum tree_code codel = TREE_CODE (type);
6569 register tree rhstype;
6570 register enum tree_code coder;
6572 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
6573 Strip such NOP_EXPRs, since RHS is used in non-lvalue context. */
6574 if (TREE_CODE (rhs) == NOP_EXPR
6575 && TREE_TYPE (rhs) == TREE_TYPE (TREE_OPERAND (rhs, 0))
6576 && codel != REFERENCE_TYPE)
6577 rhs = TREE_OPERAND (rhs, 0);
6579 if (rhs == error_mark_node
6580 || (TREE_CODE (rhs) == TREE_LIST && TREE_VALUE (rhs) == error_mark_node))
6581 return error_mark_node;
6583 if (TREE_CODE (TREE_TYPE (rhs)) == OFFSET_TYPE)
6585 rhs = resolve_offset_ref (rhs);
6586 if (rhs == error_mark_node)
6587 return error_mark_node;
6590 if (TREE_CODE (TREE_TYPE (rhs)) == REFERENCE_TYPE)
6591 rhs = convert_from_reference (rhs);
6593 if ((TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE
6594 && TREE_CODE (type) != ARRAY_TYPE
6595 && (TREE_CODE (type) != REFERENCE_TYPE
6596 || TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE))
6597 || TREE_CODE (TREE_TYPE (rhs)) == FUNCTION_TYPE
6598 || TREE_CODE (TREE_TYPE (rhs)) == METHOD_TYPE)
6599 rhs = default_conversion (rhs);
6601 rhstype = TREE_TYPE (rhs);
6602 coder = TREE_CODE (rhstype);
6604 if (coder == UNKNOWN_TYPE)
6606 rhs = instantiate_type (type, rhs, 1);
6607 rhstype = TREE_TYPE (rhs);
6608 coder = TREE_CODE (rhstype);
6611 if (coder == ERROR_MARK)
6612 return error_mark_node;
6614 /* We accept references to incomplete types, so we can
6615 return here before checking if RHS is of complete type. */
6617 if (codel == REFERENCE_TYPE)
6619 /* This should eventually happen in convert_arguments. */
6620 extern int warningcount, errorcount;
6624 savew = warningcount, savee = errorcount;
6625 rhs = convert_to_reference (type, rhs, CONV_IMPLICIT, flags,
6626 exp ? exp : error_mark_node);
6629 if (warningcount > savew)
6630 cp_warning_at ("in passing argument %P of `%+D'", parmnum, fndecl);
6631 else if (errorcount > savee)
6632 cp_error_at ("in passing argument %P of `%+D'", parmnum, fndecl);
6637 rhs = require_complete_type (rhs);
6638 if (rhs == error_mark_node)
6639 return error_mark_node;
6641 if (exp != 0) exp = require_complete_type (exp);
6642 if (exp == error_mark_node)
6643 return error_mark_node;
6645 if (TREE_CODE (rhstype) == REFERENCE_TYPE)
6646 rhstype = TREE_TYPE (rhstype);
6648 if (TYPE_LANG_SPECIFIC (type)
6649 && (IS_SIGNATURE_POINTER (type) || IS_SIGNATURE_REFERENCE (type)))
6650 return build_signature_pointer_constructor (type, rhs);
6652 if (IS_AGGR_TYPE (type)
6653 && (TYPE_NEEDS_CONSTRUCTING (type) || TREE_HAS_CONSTRUCTOR (rhs)))
6655 if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype))
6657 /* This is sufficient to perform initialization. No need,
6658 apparently, to go through X(X&) to do first-cut
6659 initialization. Return through a TARGET_EXPR so that we get
6660 cleanups if it is used. */
6661 if (TREE_CODE (rhs) == CALL_EXPR)
6663 rhs = build_cplus_new (type, rhs);
6666 /* Handle the case of default parameter initialization and
6667 initialization of static variables. */
6668 else if (TREE_CODE (rhs) == TARGET_EXPR)
6670 else if (TREE_CODE (rhs) == INDIRECT_REF && TREE_HAS_CONSTRUCTOR (rhs))
6672 my_friendly_assert (TREE_CODE (TREE_OPERAND (rhs, 0)) == CALL_EXPR, 318);
6675 my_friendly_assert (TREE_VALUE (TREE_OPERAND (TREE_OPERAND (rhs, 0), 1)) == NULL_TREE, 316);
6676 TREE_VALUE (TREE_OPERAND (TREE_OPERAND (rhs, 0), 1))
6677 = build_unary_op (ADDR_EXPR, exp, 0);
6680 rhs = build_cplus_new (type, TREE_OPERAND (rhs, 0));
6683 else if (TYPE_HAS_TRIVIAL_INIT_REF (type))
6686 if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype)
6687 || (IS_AGGR_TYPE (rhstype) && UNIQUELY_DERIVED_FROM_P (type, rhstype)))
6689 if (TYPE_HAS_INIT_REF (type))
6691 tree init = build_method_call (exp, constructor_name_full (type),
6692 build_tree_list (NULL_TREE, rhs),
6693 TYPE_BINFO (type), LOOKUP_NORMAL);
6695 if (init == error_mark_node)
6696 return error_mark_node;
6700 exp = build_cplus_new (type, init);
6704 return build (COMPOUND_EXPR, type, init, exp);
6707 /* ??? The following warnings are turned off because
6708 this is another place where the default X(X&) constructor
6710 if (TYPE_HAS_ASSIGNMENT (type))
6711 cp_warning ("bitwise copy: `%T' defines operator=", type);
6713 if (TREE_CODE (TREE_TYPE (rhs)) == REFERENCE_TYPE)
6714 rhs = convert_from_reference (rhs);
6715 if (type != rhstype)
6717 tree nrhs = build1 (NOP_EXPR, type, rhs);
6718 TREE_CONSTANT (nrhs) = TREE_CONSTANT (rhs);
6724 return cp_convert (type, rhs, CONV_OLD_CONVERT, flags);
6727 if (type == TREE_TYPE (rhs))
6729 if (TREE_READONLY_DECL_P (rhs))
6730 rhs = decl_constant_value (rhs);
6734 return convert_for_assignment (type, rhs, errtype, fndecl, parmnum);
6737 /* Expand an ASM statement with operands, handling output operands
6738 that are not variables or INDIRECT_REFS by transforming such
6739 cases into cases that expand_asm_operands can handle.
6741 Arguments are same as for expand_asm_operands.
6743 We don't do default conversions on all inputs, because it can screw
6744 up operands that are expected to be in memory. */
6747 c_expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line)
6748 tree string, outputs, inputs, clobbers;
6753 int noutputs = list_length (outputs);
6755 /* o[I] is the place that output number I should be written. */
6756 register tree *o = (tree *) alloca (noutputs * sizeof (tree));
6759 /* Record the contents of OUTPUTS before it is modified. */
6760 for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
6761 o[i] = TREE_VALUE (tail);
6763 /* Generate the ASM_OPERANDS insn;
6764 store into the TREE_VALUEs of OUTPUTS some trees for
6765 where the values were actually stored. */
6766 expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line);
6768 /* Copy all the intermediate outputs into the specified outputs. */
6769 for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
6771 if (o[i] != TREE_VALUE (tail))
6773 expand_expr (build_modify_expr (o[i], NOP_EXPR, TREE_VALUE (tail)),
6774 const0_rtx, VOIDmode, 0);
6777 /* Detect modification of read-only values.
6778 (Otherwise done by build_modify_expr.) */
6781 tree type = TREE_TYPE (o[i]);
6782 if (TYPE_READONLY (type)
6783 || ((TREE_CODE (type) == RECORD_TYPE
6784 || TREE_CODE (type) == UNION_TYPE)
6785 && C_TYPE_FIELDS_READONLY (type)))
6786 readonly_error (o[i], "modification by `asm'", 1);
6790 /* Those MODIFY_EXPRs could do autoincrements. */
6794 /* Expand a C `return' statement.
6795 RETVAL is the expression for what to return,
6796 or a null pointer for `return;' with no value.
6798 C++: upon seeing a `return', we must call destructors on all
6799 variables in scope which had constructors called on them.
6800 This means that if in a destructor, the base class destructors
6801 must be called before returning.
6803 The RETURN statement in C++ has initialization semantics. */
6806 c_expand_return (retval)
6809 extern struct nesting *cond_stack, *loop_stack, *case_stack;
6810 extern tree dtor_label, ctor_label;
6811 tree result = DECL_RESULT (current_function_decl);
6812 tree valtype = TREE_TYPE (result);
6813 int returns_value = 1;
6815 if (TREE_THIS_VOLATILE (current_function_decl))
6816 warning ("function declared `noreturn' has a `return' statement");
6818 if (retval == error_mark_node)
6820 current_function_returns_null = 1;
6824 if (current_template_parms)
6826 add_tree (build_min_nt (RETURN_STMT, retval));
6830 if (retval == NULL_TREE)
6832 /* A non-named return value does not count. */
6834 /* Can't just return from a destructor. */
6837 expand_goto (dtor_label);
6841 if (DECL_CONSTRUCTOR_P (current_function_decl))
6842 retval = current_class_decl;
6843 else if (DECL_NAME (result) != NULL_TREE
6844 && TREE_CODE (valtype) != VOID_TYPE)
6848 current_function_returns_null = 1;
6850 if (valtype != NULL_TREE && TREE_CODE (valtype) != VOID_TYPE)
6852 if (DECL_NAME (DECL_RESULT (current_function_decl)) == NULL_TREE)
6854 pedwarn ("`return' with no value, in function returning non-void");
6855 /* Clear this, so finish_function won't say that we
6856 reach the end of a non-void function (which we don't,
6857 we gave a return!). */
6858 current_function_returns_null = 0;
6862 expand_null_return ();
6866 else if (DECL_CONSTRUCTOR_P (current_function_decl)
6867 && retval != current_class_decl)
6869 error ("return from a constructor: use `this = ...' instead");
6870 retval = current_class_decl;
6873 if (valtype == NULL_TREE || TREE_CODE (valtype) == VOID_TYPE)
6875 current_function_returns_null = 1;
6876 /* We do this here so we'll avoid a warning about how the function
6877 "may or may not return a value" in finish_function. */
6881 pedwarn ("`return' with a value, in function returning void");
6882 expand_return (retval);
6884 /* Add some useful error checking for C++. */
6885 else if (TREE_CODE (valtype) == REFERENCE_TYPE)
6887 tree whats_returned;
6888 tree tmp_result = result;
6890 /* Don't initialize directly into a non-BLKmode retval, since that
6891 could lose when being inlined by another caller. (GCC can't
6892 read the function return register in an inline function when
6893 the return value is being ignored). */
6894 if (result && TYPE_MODE (TREE_TYPE (tmp_result)) != BLKmode)
6897 /* convert to reference now, so we can give error if we
6898 return an reference to a non-lvalue. */
6899 retval = convert_for_initialization (tmp_result, valtype, retval,
6900 LOOKUP_NORMAL, "return",
6903 /* Sort through common things to see what it is
6904 we are returning. */
6905 whats_returned = retval;
6906 if (TREE_CODE (whats_returned) == COMPOUND_EXPR)
6908 whats_returned = TREE_OPERAND (whats_returned, 1);
6909 if (TREE_CODE (whats_returned) == ADDR_EXPR)
6910 whats_returned = TREE_OPERAND (whats_returned, 0);
6912 if (TREE_CODE (whats_returned) == ADDR_EXPR)
6914 whats_returned = TREE_OPERAND (whats_returned, 0);
6915 while (TREE_CODE (whats_returned) == NEW_EXPR
6916 || TREE_CODE (whats_returned) == TARGET_EXPR)
6918 /* Get the target. */
6919 whats_returned = TREE_OPERAND (whats_returned, 0);
6920 warning ("returning reference to temporary");
6924 if (TREE_CODE (whats_returned) == VAR_DECL && DECL_NAME (whats_returned))
6926 if (TEMP_NAME_P (DECL_NAME (whats_returned)))
6927 warning ("reference to non-lvalue returned");
6928 else if (! TREE_STATIC (whats_returned)
6929 && IDENTIFIER_LOCAL_VALUE (DECL_NAME (whats_returned))
6930 && !TREE_PUBLIC (whats_returned))
6931 cp_warning_at ("reference to local variable `%D' returned", whats_returned);
6934 else if (TREE_CODE (retval) == ADDR_EXPR)
6936 tree whats_returned = TREE_OPERAND (retval, 0);
6938 if (TREE_CODE (whats_returned) == VAR_DECL
6939 && DECL_NAME (whats_returned)
6940 && IDENTIFIER_LOCAL_VALUE (DECL_NAME (whats_returned))
6941 && !TREE_STATIC (whats_returned)
6942 && !TREE_PUBLIC (whats_returned))
6943 cp_warning_at ("address of local variable `%D' returned", whats_returned);
6946 /* Now deal with possible C++ hair:
6947 (1) Compute the return value.
6948 (2) If there are aggregate values with destructors which
6949 must be cleaned up, clean them (taking care
6950 not to clobber the return value).
6951 (3) If an X(X&) constructor is defined, the return
6952 value must be returned via that. */
6954 /* If we're returning in a register, we can't initialize the
6955 return value from a TARGET_EXPR. */
6956 if (TREE_CODE (retval) == TARGET_EXPR
6957 && TYPE_MAIN_VARIANT (TREE_TYPE (retval)) == TYPE_MAIN_VARIANT (valtype)
6958 && ! current_function_returns_struct)
6959 retval = expand_target_expr (retval);
6961 if (retval == result
6962 /* Watch out for constructors, which "return" aggregates
6963 via initialization, but which otherwise "return" a pointer. */
6964 || DECL_CONSTRUCTOR_P (current_function_decl))
6966 /* This is just an error--it's already been reported. */
6967 if (TYPE_SIZE (valtype) == NULL_TREE)
6970 if (TYPE_MODE (valtype) != BLKmode
6971 && any_pending_cleanups (1))
6972 retval = get_temp_regvar (valtype, retval);
6974 else if (IS_AGGR_TYPE (valtype) && current_function_returns_struct)
6976 expand_aggr_init (result, retval, 0, LOOKUP_ONLYCONVERTING);
6977 expand_cleanups_to (NULL_TREE);
6978 DECL_INITIAL (result) = NULL_TREE;
6983 if (TYPE_MODE (valtype) == VOIDmode)
6985 if (TYPE_MODE (TREE_TYPE (result)) != VOIDmode
6986 && warn_return_type)
6987 warning ("return of void value in function returning non-void");
6988 expand_expr_stmt (retval);
6992 else if (TYPE_MODE (valtype) != BLKmode
6993 && any_pending_cleanups (1))
6995 retval = get_temp_regvar (valtype, retval);
6996 expand_cleanups_to (NULL_TREE);
7001 retval = convert_for_initialization (result, valtype, retval,
7003 "return", NULL_TREE, 0);
7004 DECL_INITIAL (result) = NULL_TREE;
7006 if (retval == error_mark_node)
7012 if (retval != NULL_TREE
7013 && TREE_CODE_CLASS (TREE_CODE (retval)) == 'd'
7014 && cond_stack == 0 && loop_stack == 0 && case_stack == 0)
7015 current_function_return_value = retval;
7019 /* Everything's great--RETVAL is in RESULT. */
7020 if (original_result_rtx)
7022 store_expr (result, original_result_rtx, 0);
7023 expand_cleanups_to (NULL_TREE);
7024 use_variable (DECL_RTL (result));
7025 if (ctor_label && TREE_CODE (ctor_label) != ERROR_MARK)
7026 expand_goto (ctor_label);
7028 expand_null_return ();
7030 else if (retval && retval != result)
7032 /* Clear this out so the later call to decl_function_context
7033 won't end up bombing on us. */
7034 if (DECL_CONTEXT (result) == error_mark_node)
7035 DECL_CONTEXT (result) = NULL_TREE;
7036 /* Here is where we finally get RETVAL into RESULT.
7037 `expand_return' does the magic of protecting
7038 RESULT from cleanups. */
7039 retval = fold (build1 (CLEANUP_POINT_EXPR, TREE_TYPE (result),
7041 /* This part _must_ come second, because expand_return looks for
7042 the INIT_EXPR as the toplevel node only. :-( */
7043 retval = build (INIT_EXPR, TREE_TYPE (result), result, retval);
7044 TREE_SIDE_EFFECTS (retval) = 1;
7045 expand_return (retval);
7048 expand_return (result);
7052 /* We may still need to put RETVAL into RESULT. */
7053 result = DECL_RESULT (current_function_decl);
7054 if (original_result_rtx)
7056 /* Here we have a named return value that went
7057 into memory. We can compute RETVAL into that. */
7059 expand_assignment (result, retval, 0, 0);
7061 store_expr (result, original_result_rtx, 0);
7062 result = make_tree (TREE_TYPE (result), original_result_rtx);
7064 else if (ctor_label && TREE_CODE (ctor_label) != ERROR_MARK)
7066 /* Here RETVAL is CURRENT_CLASS_DECL, so there's nothing to do. */
7067 expand_goto (ctor_label);
7071 /* Here is where we finally get RETVAL into RESULT.
7072 `expand_return' does the magic of protecting
7073 RESULT from cleanups. */
7074 result = build (INIT_EXPR, TREE_TYPE (result), result, retval);
7075 TREE_SIDE_EFFECTS (result) = 1;
7076 expand_return (result);
7078 else if (TYPE_MODE (TREE_TYPE (result)) != VOIDmode)
7079 expand_return (result);
7082 current_function_returns_value = returns_value;
7084 /* One way to clear out cleanups that EXPR might
7085 generate. Note that this code will really be
7086 dead code, but that is ok--cleanups that were
7087 needed were handled by the magic of `return'. */
7088 expand_cleanups_to (NULL_TREE);
7091 /* Start a C switch statement, testing expression EXP.
7092 Return EXP if it is valid, an error node otherwise. */
7095 c_expand_start_case (exp)
7099 register enum tree_code code;
7101 /* Convert from references, etc. */
7102 exp = default_conversion (exp);
7103 type = TREE_TYPE (exp);
7104 code = TREE_CODE (type);
7106 if (IS_AGGR_TYPE_CODE (code))
7107 exp = build_type_conversion (CONVERT_EXPR, integer_type_node, exp, 1);
7109 if (exp == NULL_TREE)
7111 error ("switch quantity not an integer");
7112 exp = error_mark_node;
7114 type = TREE_TYPE (exp);
7115 code = TREE_CODE (type);
7117 if (code != INTEGER_TYPE && code != ENUMERAL_TYPE && code != ERROR_MARK)
7119 error ("switch quantity not an integer");
7120 exp = error_mark_node;
7126 exp = default_conversion (exp);
7127 type = TREE_TYPE (exp);
7128 index = get_unwidened (exp, 0);
7129 /* We can't strip a conversion from a signed type to an unsigned,
7130 because if we did, int_fits_type_p would do the wrong thing
7131 when checking case values for being in range,
7132 and it's too hard to do the right thing. */
7133 if (TREE_UNSIGNED (TREE_TYPE (exp))
7134 == TREE_UNSIGNED (TREE_TYPE (index)))
7139 (1, fold (build1 (CLEANUP_POINT_EXPR, TREE_TYPE (exp), exp)),
7140 type, "switch statement");
7145 /* CONSTP remembers whether or not all the intervening pointers in the `to'
7146 type have been const. */
7148 comp_ptr_ttypes_real (to, from, constp)
7152 for (; ; to = TREE_TYPE (to), from = TREE_TYPE (from))
7154 if (TREE_CODE (to) != TREE_CODE (from))
7157 /* Const and volatile mean something different for function types,
7158 so the usual checks are not appropriate. */
7159 if (TREE_CODE (to) != FUNCTION_TYPE && TREE_CODE (to) != METHOD_TYPE)
7161 if (TYPE_READONLY (from) > TYPE_READONLY (to)
7162 || TYPE_VOLATILE (from) > TYPE_VOLATILE (to))
7166 && (TYPE_READONLY (to) > TYPE_READONLY (from)
7167 || TYPE_VOLATILE (to) > TYPE_READONLY (from)))
7169 constp &= TYPE_READONLY (to);
7172 if (TREE_CODE (to) != POINTER_TYPE)
7173 return comptypes (TYPE_MAIN_VARIANT (to), TYPE_MAIN_VARIANT (from), 1);
7177 /* When comparing, say, char ** to char const **, this function takes the
7178 'char *' and 'char const *'. Do not pass non-pointer types to this
7181 comp_ptr_ttypes (to, from)
7184 return comp_ptr_ttypes_real (to, from, 1);