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, 675 Mass Ave, Cambridge, MA 02139, USA. */
22 /* This file is part of the C++ front end.
23 It contains routines to build C++ expressions given their operands,
24 including computing the types of the result, C and C++ specific error
25 checks, and some optimization.
27 There are also routines to build RETURN_STMT nodes and CASE_STMT nodes,
28 and to process initializations in declarations (since they work
29 like a strange sort of assignment). */
32 extern void warning ();
41 int mark_addressable ();
42 static tree
convert_for_assignment ();
43 /* static */ tree
convert_for_initialization ();
44 extern tree
shorten_compare ();
45 extern void binary_op_error ();
46 static tree
pointer_int_sum ();
47 static tree
pointer_diff ();
48 static tree
convert_sequence ();
49 /* static */ tree
unary_complex_lvalue ();
50 static tree get_delta_difference
PROTO((tree
, tree
, int));
52 extern rtx original_result_rtx
;
54 /* Return the target type of TYPE, which meas return T for:
55 T*, T&, T[], T (...), and otherwise, just T. */
61 if (TREE_CODE (type
) == REFERENCE_TYPE
)
62 type
= TREE_TYPE (type
);
63 while (TREE_CODE (type
) == POINTER_TYPE
64 || TREE_CODE (type
) == ARRAY_TYPE
65 || TREE_CODE (type
) == FUNCTION_TYPE
66 || TREE_CODE (type
) == METHOD_TYPE
67 || TREE_CODE (type
) == OFFSET_TYPE
)
68 type
= TREE_TYPE (type
);
72 /* Do `exp = require_complete_type (exp);' to make sure exp
73 does not have an incomplete type. (That includes void types.) */
76 require_complete_type (value
)
79 tree type
= TREE_TYPE (value
);
81 /* First, detect a valid value with a complete type. */
82 if (TYPE_SIZE (type
) != 0
83 && type
!= void_type_node
84 && ! (TYPE_LANG_SPECIFIC (type
)
85 && (IS_SIGNATURE_POINTER (type
) || IS_SIGNATURE_REFERENCE (type
))
86 && TYPE_SIZE (SIGNATURE_TYPE (type
)) == 0))
89 /* If we see X::Y, we build an OFFSET_TYPE which has
90 not been laid out. Try to avoid an error by interpreting
91 it as this->X::Y, if reasonable. */
92 if (TREE_CODE (value
) == OFFSET_REF
94 && TREE_OPERAND (value
, 0) == C_C_D
)
96 tree base
, member
= TREE_OPERAND (value
, 1);
97 tree basetype
= TYPE_OFFSET_BASETYPE (type
);
98 my_friendly_assert (TREE_CODE (member
) == FIELD_DECL
, 305);
99 base
= convert_pointer_to (basetype
, current_class_decl
);
100 value
= build (COMPONENT_REF
, TREE_TYPE (member
),
101 build_indirect_ref (base
, NULL_PTR
), member
);
102 return require_complete_type (value
);
105 incomplete_type_error (value
, type
);
106 return error_mark_node
;
109 /* Return truthvalue of whether type of EXP is instantiated. */
114 return (TREE_CODE (exp
) == TREE_LIST
115 || TREE_TYPE (exp
) == unknown_type_node
116 || (TREE_CODE (TREE_TYPE (exp
)) == OFFSET_TYPE
117 && TREE_TYPE (TREE_TYPE (exp
)) == unknown_type_node
));
120 /* Return truthvalue of whether T is function (or pfn) type. */
125 return (TREE_CODE (t
) == FUNCTION_TYPE
|| TREE_CODE (t
) == METHOD_TYPE
126 || (TREE_CODE (t
) == POINTER_TYPE
127 && (TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
128 || TREE_CODE (TREE_TYPE (t
)) == METHOD_TYPE
)));
131 /* Do `exp = require_instantiated_type (type, exp);' to make sure EXP
132 does not have an uninstantiated type.
133 TYPE is type to instantiate with, if uninstantiated. */
135 require_instantiated_type (type
, exp
, errval
)
136 tree type
, exp
, errval
;
138 if (TREE_TYPE (exp
) == NULL_TREE
)
140 error ("argument list may not have an initializer list");
144 if (TREE_TYPE (exp
) == unknown_type_node
145 || (TREE_CODE (TREE_TYPE (exp
)) == OFFSET_TYPE
146 && TREE_TYPE (TREE_TYPE (exp
)) == unknown_type_node
))
148 exp
= instantiate_type (type
, exp
, 1);
149 if (TREE_TYPE (exp
) == error_mark_node
)
155 /* Return a variant of TYPE which has all the type qualifiers of LIKE
156 as well as those of TYPE. */
159 qualify_type (type
, like
)
162 int constflag
= TYPE_READONLY (type
) || TYPE_READONLY (like
);
163 int volflag
= TYPE_VOLATILE (type
) || TYPE_VOLATILE (like
);
164 /* @@ Must do member pointers here. */
165 return cp_build_type_variant (type
, constflag
, volflag
);
168 /* Return the common type of two parameter lists.
169 We assume that comptypes has already been done and returned 1;
170 if that isn't so, this may crash.
172 As an optimization, free the space we allocate if the parameter
173 lists are already common. */
179 tree oldargs
= p1
, newargs
, n
;
182 char *first_obj
= (char *) oballoc (0);
184 len
= list_length (p1
);
185 newargs
= tree_last (p1
);
187 if (newargs
== void_list_node
)
196 newargs
= tree_cons (NULL_TREE
, NULL_TREE
, newargs
);
201 p1
= TREE_CHAIN (p1
), p2
= TREE_CHAIN (p2
), n
= TREE_CHAIN (n
), i
++)
203 if (TREE_PURPOSE (p1
) && !TREE_PURPOSE (p2
))
205 TREE_PURPOSE (n
) = TREE_PURPOSE (p1
);
208 else if (! TREE_PURPOSE (p1
))
210 if (TREE_PURPOSE (p2
))
212 TREE_PURPOSE (n
) = TREE_PURPOSE (p2
);
218 int cmp
= simple_cst_equal (TREE_PURPOSE (p1
), TREE_PURPOSE (p2
));
220 my_friendly_abort (111);
223 TREE_PURPOSE (n
) = TREE_PURPOSE (p2
);
225 if (TREE_VALUE (p1
) != TREE_VALUE (p2
))
228 TREE_VALUE (n
) = common_type (TREE_VALUE (p1
), TREE_VALUE (p2
));
231 TREE_VALUE (n
) = TREE_VALUE (p1
);
242 /* Return the common type of two types.
243 We assume that comptypes has already been done and returned 1;
244 if that isn't so, this may crash.
246 This is the type for the result of most arithmetic operations
247 if the operands have the given two types.
249 We do not deal with enumeral types here because they have already been
250 converted to integer types. */
256 register enum tree_code code1
;
257 register enum tree_code code2
;
260 /* Save time if the two types are the same. */
262 if (t1
== t2
) return t1
;
264 /* If one type is nonsense, use the other. */
265 if (t1
== error_mark_node
)
267 if (t2
== error_mark_node
)
270 /* Merge the attributes */
272 { register tree a1
, a2
;
273 a1
= TYPE_ATTRIBUTES (t1
);
274 a2
= TYPE_ATTRIBUTES (t2
);
276 /* Either one unset? Take the set one. */
278 if (!(attributes
= a1
))
281 /* One that completely contains the other? Take it. */
283 else if (a2
&& !attribute_list_contained (a1
, a2
))
284 if (attribute_list_contained (a2
, a1
))
288 /* Pick the longest list, and hang on the other
291 if (list_length (a1
) < list_length (a2
))
292 attributes
= a2
, a2
= a1
;
294 for (; a2
; a2
= TREE_CHAIN (a2
))
295 if (!value_member (attributes
, a2
))
298 TREE_CHAIN (a1
) = attributes
;
304 /* Treat an enum type as the unsigned integer type of the same width. */
306 if (TREE_CODE (t1
) == ENUMERAL_TYPE
)
307 t1
= type_for_size (TYPE_PRECISION (t1
), 1);
308 if (TREE_CODE (t2
) == ENUMERAL_TYPE
)
309 t2
= type_for_size (TYPE_PRECISION (t2
), 1);
311 code1
= TREE_CODE (t1
);
312 code2
= TREE_CODE (t2
);
318 /* If only one is real, use it as the result. */
320 if (code1
== REAL_TYPE
&& code2
!= REAL_TYPE
)
321 return build_type_attribute_variant (t1
, attributes
);
323 if (code2
== REAL_TYPE
&& code1
!= REAL_TYPE
)
324 return build_type_attribute_variant (t2
, attributes
);
326 /* Both real or both integers; use the one with greater precision. */
328 if (TYPE_PRECISION (t1
) > TYPE_PRECISION (t2
))
329 return build_type_attribute_variant (t1
, attributes
);
330 else if (TYPE_PRECISION (t2
) > TYPE_PRECISION (t1
))
331 return build_type_attribute_variant (t2
, attributes
);
333 /* Same precision. Prefer longs to ints even when same size. */
335 if (TYPE_MAIN_VARIANT (t1
) == long_unsigned_type_node
336 || TYPE_MAIN_VARIANT (t2
) == long_unsigned_type_node
)
337 return build_type_attribute_variant (long_unsigned_type_node
,
340 if (TYPE_MAIN_VARIANT (t1
) == long_integer_type_node
341 || TYPE_MAIN_VARIANT (t2
) == long_integer_type_node
)
343 /* But preserve unsignedness from the other type,
344 since long cannot hold all the values of an unsigned int. */
345 if (TREE_UNSIGNED (t1
) || TREE_UNSIGNED (t2
))
346 t1
= long_unsigned_type_node
;
348 t1
= long_integer_type_node
;
349 return build_type_attribute_variant (t1
, attributes
);
352 if (TYPE_MAIN_VARIANT (t1
) == long_double_type_node
353 || TYPE_MAIN_VARIANT (t2
) == long_double_type_node
)
354 return build_type_attribute_variant (long_double_type_node
,
357 /* Otherwise prefer the unsigned one. */
359 if (TREE_UNSIGNED (t1
))
360 return build_type_attribute_variant (t1
, attributes
);
362 return build_type_attribute_variant (t2
, attributes
);
366 /* For two pointers, do this recursively on the target type,
367 and combine the qualifiers of the two types' targets. */
368 /* This code was turned off; I don't know why.
369 But ANSI C++ specifies doing this with the qualifiers.
370 So I turned it on again. */
372 tree target
= common_type (TYPE_MAIN_VARIANT (TREE_TYPE (t1
)),
373 TYPE_MAIN_VARIANT (TREE_TYPE (t2
)));
375 = TYPE_READONLY (TREE_TYPE (t1
)) || TYPE_READONLY (TREE_TYPE (t2
));
377 = TYPE_VOLATILE (TREE_TYPE (t1
)) || TYPE_VOLATILE (TREE_TYPE (t2
));
378 target
= cp_build_type_variant (target
, constp
, volatilep
);
379 if (code1
== POINTER_TYPE
)
380 t1
= build_pointer_type (target
);
382 t1
= build_reference_type (target
);
383 return build_type_attribute_variant (t1
, attributes
);
387 t1
= build_pointer_type (common_type (TREE_TYPE (t1
), TREE_TYPE (t2
)));
388 return build_type_attribute_variant (t1
, attributes
);
391 t1
= build_reference_type (common_type (TREE_TYPE (t1
), TREE_TYPE (t2
)));
392 return build_type_attribute_variant (t1
, attributes
);
397 tree elt
= common_type (TREE_TYPE (t1
), TREE_TYPE (t2
));
398 /* Save space: see if the result is identical to one of the args. */
399 if (elt
== TREE_TYPE (t1
) && TYPE_DOMAIN (t1
))
400 return build_type_attribute_variant (t1
, attributes
);
401 if (elt
== TREE_TYPE (t2
) && TYPE_DOMAIN (t2
))
402 return build_type_attribute_variant (t2
, attributes
);
403 /* Merge the element types, and have a size if either arg has one. */
404 t1
= build_array_type (elt
, TYPE_DOMAIN (TYPE_DOMAIN (t1
) ? t1
: t2
));
405 return build_type_attribute_variant (t1
, attributes
);
409 /* Function types: prefer the one that specified arg types.
410 If both do, merge the arg types. Also merge the return types. */
412 tree valtype
= common_type (TREE_TYPE (t1
), TREE_TYPE (t2
));
413 tree p1
= TYPE_ARG_TYPES (t1
);
414 tree p2
= TYPE_ARG_TYPES (t2
);
417 /* Save space: see if the result is identical to one of the args. */
418 if (valtype
== TREE_TYPE (t1
) && ! p2
)
419 return build_type_attribute_variant (t1
, attributes
);
420 if (valtype
== TREE_TYPE (t2
) && ! p1
)
421 return build_type_attribute_variant (t2
, attributes
);
423 /* Simple way if one arg fails to specify argument types. */
424 if (p1
== NULL_TREE
|| TREE_VALUE (p1
) == void_type_node
)
426 rval
= build_function_type (valtype
, p2
);
427 if ((raises
= TYPE_RAISES_EXCEPTIONS (t2
)))
428 rval
= build_exception_variant (NULL_TREE
, rval
, raises
);
429 return build_type_attribute_variant (rval
, attributes
);
431 raises
= TYPE_RAISES_EXCEPTIONS (t1
);
432 if (p2
== NULL_TREE
|| TREE_VALUE (p2
) == void_type_node
)
434 rval
= build_function_type (valtype
, p1
);
436 rval
= build_exception_variant (NULL_TREE
, rval
, raises
);
437 return build_type_attribute_variant (rval
, attributes
);
440 rval
= build_function_type (valtype
, commonparms (p1
, p2
));
441 rval
= build_exception_variant (NULL_TREE
, rval
, raises
);
442 return build_type_attribute_variant (rval
, attributes
);
447 my_friendly_assert (TYPE_MAIN_VARIANT (t1
) == t1
448 && TYPE_MAIN_VARIANT (t2
) == t2
, 306);
450 if (DERIVED_FROM_P (t1
, t2
) && binfo_or_else (t1
, t2
))
451 return build_type_attribute_variant (t1
, attributes
);
452 else if (binfo_or_else (t2
, t1
))
453 return build_type_attribute_variant (t2
, attributes
);
455 compiler_error ("common_type called with uncommon aggregate types");
458 if (comptypes (TYPE_METHOD_BASETYPE (t1
), TYPE_METHOD_BASETYPE (t2
), 1)
459 && TREE_CODE (TREE_TYPE (t1
)) == TREE_CODE (TREE_TYPE (t2
)))
461 /* Get this value the long way, since TYPE_METHOD_BASETYPE
462 is just the main variant of this. */
463 tree basetype
= TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t1
)));
466 raises
= TYPE_RAISES_EXCEPTIONS (t1
);
468 /* If this was a member function type, get back to the
469 original type of type member function (i.e., without
470 the class instance variable up front. */
471 t1
= build_function_type (TREE_TYPE (t1
), TREE_CHAIN (TYPE_ARG_TYPES (t1
)));
472 t2
= build_function_type (TREE_TYPE (t2
), TREE_CHAIN (TYPE_ARG_TYPES (t2
)));
473 t3
= common_type (t1
, t2
);
474 t3
= build_cplus_method_type (basetype
, TREE_TYPE (t3
), TYPE_ARG_TYPES (t3
));
475 t1
= build_exception_variant (basetype
, t3
, raises
);
478 compiler_error ("common_type called with uncommon method types");
480 return build_type_attribute_variant (t1
, attributes
);
483 if (TYPE_OFFSET_BASETYPE (t1
) == TYPE_OFFSET_BASETYPE (t2
)
484 && TREE_CODE (TREE_TYPE (t1
)) == TREE_CODE (TREE_TYPE (t2
)))
486 tree basetype
= TYPE_OFFSET_BASETYPE (t1
);
487 t1
= build_offset_type (basetype
,
488 common_type (TREE_TYPE (t1
), TREE_TYPE (t2
)));
491 compiler_error ("common_type called with uncommon member types");
493 /* ... falls through ... */
496 return build_type_attribute_variant (t1
, attributes
);
500 /* Return 1 if TYPE1 and TYPE2 raise the same exceptions. */
502 compexcepttypes (t1
, t2
, strict
)
506 return TYPE_RAISES_EXCEPTIONS (t1
) == TYPE_RAISES_EXCEPTIONS (t2
);
510 comp_array_types (cmp
, t1
, t2
, strict
)
511 register int (*cmp
)();
515 tree d1
= TYPE_DOMAIN (t1
);
516 tree d2
= TYPE_DOMAIN (t2
);
518 /* Target types must match incl. qualifiers. */
519 if (!(TREE_TYPE (t1
) == TREE_TYPE (t2
)
520 || (*cmp
) (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
)))
523 /* Sizes must match unless one is missing or variable. */
524 if (d1
== 0 || d2
== 0 || d1
== d2
525 || TREE_CODE (TYPE_MIN_VALUE (d1
)) != INTEGER_CST
526 || TREE_CODE (TYPE_MIN_VALUE (d2
)) != INTEGER_CST
527 || TREE_CODE (TYPE_MAX_VALUE (d1
)) != INTEGER_CST
528 || TREE_CODE (TYPE_MAX_VALUE (d2
)) != INTEGER_CST
)
531 return ((TREE_INT_CST_LOW (TYPE_MIN_VALUE (d1
))
532 == TREE_INT_CST_LOW (TYPE_MIN_VALUE (d2
)))
533 && (TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d1
))
534 == TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d2
)))
535 && (TREE_INT_CST_LOW (TYPE_MAX_VALUE (d1
))
536 == TREE_INT_CST_LOW (TYPE_MAX_VALUE (d2
)))
537 && (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d1
))
538 == TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d2
))));
541 /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
542 or various other operations. This is what ANSI C++ speaks of as
545 For C++: argument STRICT says we should be strict about this
548 2 : strict, except that if one type is a reference and
549 the other is not, compare the target type of the
550 reference to the type that's not a reference (ARM, p308).
551 This is used for checking for invalid overloading.
552 1 : strict (compared according to ANSI C)
553 This is used for checking whether two function decls match.
554 0 : <= (compared according to C++)
555 -1: <= or >= (relaxed)
557 Otherwise, pointers involving base classes and derived classes
558 can be mixed as valid: i.e. a pointer to a base class may be assigned
559 to a pointer to one of its derived classes, as per C++. A pointer to
560 a derived class may be passed as a parameter to a function expecting a
561 pointer to a base classes. These allowances do not commute. In this
562 case, TYPE1 is assumed to be the base class, and TYPE2 is assumed to
563 be the derived class. */
565 comptypes (type1
, type2
, strict
)
569 register tree t1
= type1
;
570 register tree t2
= type2
;
573 /* Suppress errors caused by previously reported errors */
578 /* This should never happen. */
579 my_friendly_assert (t1
!= error_mark_node
, 307);
581 if (t2
== error_mark_node
)
586 /* Treat an enum type as the unsigned integer type of the same width. */
588 if (TREE_CODE (t1
) == ENUMERAL_TYPE
)
589 t1
= type_for_size (TYPE_PRECISION (t1
), 1);
590 if (TREE_CODE (t2
) == ENUMERAL_TYPE
)
591 t2
= type_for_size (TYPE_PRECISION (t2
), 1);
597 /* Different classes of types can't be compatible. */
599 if (TREE_CODE (t1
) != TREE_CODE (t2
))
602 && ((TREE_CODE (t1
) == REFERENCE_TYPE
)
603 ^ (TREE_CODE (t2
) == REFERENCE_TYPE
)))
605 if (TREE_CODE (t1
) == REFERENCE_TYPE
)
606 return comptypes (TREE_TYPE (t1
), t2
, 1);
607 return comptypes (t1
, TREE_TYPE (t2
), 1);
615 /* Qualifiers must match. */
617 if (TYPE_READONLY (t1
) != TYPE_READONLY (t2
))
619 if (TYPE_VOLATILE (t1
) != TYPE_VOLATILE (t2
))
622 /* Allow for two different type nodes which have essentially the same
623 definition. Note that we already checked for equality of the type
624 type qualifiers (just above). */
626 if (TYPE_MAIN_VARIANT (t1
) == TYPE_MAIN_VARIANT (t2
))
629 #ifdef COMP_TYPE_ATTRIBUTES
630 if (! (attrval
= COMP_TYPE_ATTRIBUTES (t1
, t2
)))
633 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
637 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
640 switch (TREE_CODE (t1
))
649 val
= (comptypes (TYPE_POINTER_TO (TYPE_OFFSET_BASETYPE (t1
)),
650 TYPE_POINTER_TO (TYPE_OFFSET_BASETYPE (t2
)), strict
)
651 && comptypes (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
));
655 if (! compexcepttypes (t1
, t2
, strict
))
658 /* This case is anti-symmetrical!
659 One can pass a base member (or member function)
660 to something expecting a derived member (or member function),
661 but not vice-versa! */
663 val
= (comptypes (TYPE_POINTER_TO (TYPE_METHOD_BASETYPE (t2
)),
664 TYPE_POINTER_TO (TYPE_METHOD_BASETYPE (t1
)), strict
)
665 && comptypes (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
)
666 && compparms (TREE_CHAIN (TYPE_ARG_TYPES (t1
)),
667 TREE_CHAIN (TYPE_ARG_TYPES (t2
)), strict
));
681 if (TREE_CODE (t1
) == RECORD_TYPE
&& TREE_CODE (t2
) == RECORD_TYPE
)
685 rval
= t1
== t2
|| UNIQUELY_DERIVED_FROM_P (t1
, t2
);
694 val
= UNIQUELY_DERIVED_FROM_P (t2
, t1
);
701 val
= comptypes (t1
, t2
, strict
);
705 if (! compexcepttypes (t1
, t2
, strict
))
708 val
= ((TREE_TYPE (t1
) == TREE_TYPE (t2
)
709 || comptypes (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
))
710 && compparms (TYPE_ARG_TYPES (t1
), TYPE_ARG_TYPES (t2
), strict
));
714 /* Target types must match incl. qualifiers. */
715 val
= comp_array_types (comptypes
, t1
, t2
, strict
);
718 case TEMPLATE_TYPE_PARM
:
721 case UNINSTANTIATED_P_TYPE
:
722 return UPT_TEMPLATE (t1
) == UPT_TEMPLATE (t2
);
724 return attrval
== 2 && val
== 1 ? 2 : val
;
727 /* Return 1 if TTL and TTR are pointers to types that are equivalent,
728 ignoring their qualifiers.
730 NPTRS is the number of pointers we can strip off and keep cool.
731 This is used to permit (for aggr A, aggr B) A, B* to convert to A*,
732 but to not permit B** to convert to A**. */
735 comp_target_types (ttl
, ttr
, nptrs
)
739 ttl
= TYPE_MAIN_VARIANT (ttl
);
740 ttr
= TYPE_MAIN_VARIANT (ttr
);
744 if (TREE_CODE (ttr
) != TREE_CODE (ttl
))
747 if (TREE_CODE (ttr
) == POINTER_TYPE
)
749 if (TREE_CODE (TREE_TYPE (ttl
)) == POINTER_TYPE
750 || TREE_CODE (TREE_TYPE (ttl
)) == ARRAY_TYPE
)
751 return comp_ptr_ttypes (TREE_TYPE (ttl
), TREE_TYPE (ttr
));
753 return comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), nptrs
- 1);
756 if (TREE_CODE (ttr
) == REFERENCE_TYPE
)
757 return comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), nptrs
);
758 if (TREE_CODE (ttr
) == ARRAY_TYPE
)
759 return comp_array_types (comp_target_types
, ttl
, ttr
, 0);
760 else if (TREE_CODE (ttr
) == FUNCTION_TYPE
|| TREE_CODE (ttr
) == METHOD_TYPE
)
761 if (comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), nptrs
))
762 switch (comp_target_parms (TYPE_ARG_TYPES (ttl
), TYPE_ARG_TYPES (ttr
), 1))
771 my_friendly_abort (112);
777 else if (TREE_CODE (ttr
) == OFFSET_TYPE
)
779 /* Contravariance: we can assign a pointer to base member to a pointer
780 to derived member. Note difference from simple pointer case, where
781 we can pass a pointer to derived to a pointer to base. */
782 if (comptypes (TYPE_OFFSET_BASETYPE (ttr
), TYPE_OFFSET_BASETYPE (ttl
), 0))
783 return comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), nptrs
);
784 else if (comptypes (TYPE_OFFSET_BASETYPE (ttl
), TYPE_OFFSET_BASETYPE (ttr
), 0)
785 && comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), nptrs
))
788 else if (IS_AGGR_TYPE (ttl
))
792 if (comptypes (TYPE_POINTER_TO (ttl
), TYPE_POINTER_TO (ttr
), 0))
794 if (comptypes (TYPE_POINTER_TO (ttr
), TYPE_POINTER_TO (ttl
), 0))
802 /* If two types share a common base type, return that basetype.
803 If there is not a unique most-derived base type, this function
804 returns ERROR_MARK_NODE. */
806 common_base_type (tt1
, tt2
)
809 tree best
= NULL_TREE
, tmp
;
812 /* If one is a baseclass of another, that's good enough. */
813 if (UNIQUELY_DERIVED_FROM_P (tt1
, tt2
))
815 if (UNIQUELY_DERIVED_FROM_P (tt2
, tt1
))
819 /* If they share a virtual baseclass, that's good enough. */
820 for (tmp
= CLASSTYPE_VBASECLASSES (tt1
); tmp
; tmp
= TREE_CHAIN (tmp
))
822 if (binfo_member (BINFO_TYPE (tmp
), CLASSTYPE_VBASECLASSES (tt2
)))
823 return BINFO_TYPE (tmp
);
827 /* Otherwise, try to find a unique baseclass of TT1
828 that is shared by TT2, and follow that down. */
829 for (i
= CLASSTYPE_N_BASECLASSES (tt1
)-1; i
>= 0; i
--)
831 tree basetype
= TYPE_BINFO_BASETYPE (tt1
, i
);
832 tree trial
= common_base_type (basetype
, tt2
);
835 if (trial
== error_mark_node
)
837 if (best
== NULL_TREE
)
839 else if (best
!= trial
)
840 return error_mark_node
;
845 for (i
= CLASSTYPE_N_BASECLASSES (tt2
)-1; i
>= 0; i
--)
847 tree basetype
= TYPE_BINFO_BASETYPE (tt2
, i
);
848 tree trial
= common_base_type (tt1
, basetype
);
851 if (trial
== error_mark_node
)
853 if (best
== NULL_TREE
)
855 else if (best
!= trial
)
856 return error_mark_node
;
862 /* Subroutines of `comptypes'. */
864 /* Return 1 if two parameter type lists PARMS1 and PARMS2
865 are equivalent in the sense that functions with those parameter types
866 can have equivalent types.
867 If either list is empty, we win.
868 Otherwise, the two lists must be equivalent, element by element.
870 C++: See comment above about TYPE1, TYPE2, STRICT.
871 If STRICT == 3, it means checking is strict, but do not compare
872 default parameter values. */
874 compparms (parms1
, parms2
, strict
)
878 register tree t1
= parms1
, t2
= parms2
;
880 /* An unspecified parmlist matches any specified parmlist
881 whose argument types don't need default promotions. */
883 if (strict
<= 0 && t1
== 0)
884 return self_promoting_args_p (t2
);
885 if (strict
< 0 && t2
== 0)
886 return self_promoting_args_p (t1
);
890 if (t1
== 0 && t2
== 0)
892 /* If one parmlist is shorter than the other,
893 they fail to match, unless STRICT is <= 0. */
894 if (t1
== 0 || t2
== 0)
901 return t1
&& TREE_PURPOSE (t1
);
903 if (! comptypes (TREE_VALUE (t2
), TREE_VALUE (t1
), strict
))
908 return t2
== void_list_node
&& TREE_PURPOSE (t1
);
909 return TREE_PURPOSE (t1
) || TREE_PURPOSE (t2
);
912 /* Default parms are not part of the type of a function. */
913 if (strict
!= 3 && TREE_PURPOSE (t1
) && TREE_PURPOSE (t2
))
915 int cmp
= simple_cst_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
));
917 my_friendly_abort (113);
923 t1
= TREE_CHAIN (t1
);
924 t2
= TREE_CHAIN (t2
);
928 /* This really wants return whether or not parameter type lists
929 would make their owning functions assignment compatible or not. */
931 comp_target_parms (parms1
, parms2
, strict
)
935 register tree t1
= parms1
, t2
= parms2
;
936 int warn_contravariance
= 0;
938 /* An unspecified parmlist matches any specified parmlist
939 whose argument types don't need default promotions.
940 @@@ see 13.3.3 for a counterexample... */
942 if (t1
== 0 && t2
!= 0)
944 cp_pedwarn ("ANSI C++ prohibits conversion from `(%#T)' to `(...)'",
946 return self_promoting_args_p (t2
);
949 return self_promoting_args_p (t1
);
951 for (; t1
|| t2
; t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
))
955 /* If one parmlist is shorter than the other,
956 they fail to match, unless STRICT is <= 0. */
957 if (t1
== 0 || t2
== 0)
962 return 1 + warn_contravariance
;
963 return ((t1
&& TREE_PURPOSE (t1
)) + warn_contravariance
);
965 p1
= TREE_VALUE (t1
);
966 p2
= TREE_VALUE (t2
);
970 if ((TREE_CODE (p1
) == POINTER_TYPE
&& TREE_CODE (p2
) == POINTER_TYPE
)
971 || (TREE_CODE (p1
) == REFERENCE_TYPE
&& TREE_CODE (p2
) == REFERENCE_TYPE
))
974 && (TYPE_MAIN_VARIANT (TREE_TYPE (p1
))
975 == TYPE_MAIN_VARIANT (TREE_TYPE (p2
))))
978 /* The following is wrong for contravariance,
979 but many programs depend on it. */
980 if (TREE_TYPE (p1
) == void_type_node
)
982 if (TREE_TYPE (p2
) == void_type_node
)
984 warn_contravariance
= 1;
987 if (IS_AGGR_TYPE (TREE_TYPE (p1
)))
989 if (comptypes (p2
, p1
, 0) == 0)
991 if (comptypes (p1
, p2
, 0) != 0)
992 warn_contravariance
= 1;
999 /* Note backwards order due to contravariance. */
1000 if (comp_target_types (p2
, p1
, 1) == 0)
1002 if (comp_target_types (p1
, p2
, 1))
1004 warn_contravariance
= 1;
1010 /* What good do these cases do? */
1012 return p2
== void_type_node
&& TREE_PURPOSE (t1
);
1013 return TREE_PURPOSE (t1
) || TREE_PURPOSE (t2
);
1016 /* Target types are compatible--just make sure that if
1017 we use parameter lists, that they are ok as well. */
1018 if (TREE_CODE (p1
) == FUNCTION_TYPE
|| TREE_CODE (p1
) == METHOD_TYPE
)
1019 switch (comp_target_parms (TYPE_ARG_TYPES (p1
),
1020 TYPE_ARG_TYPES (p2
),
1028 warn_contravariance
= 1;
1031 if (TREE_PURPOSE (t1
) && TREE_PURPOSE (t2
))
1033 int cmp
= simple_cst_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
));
1035 my_friendly_abort (114);
1040 return 1 + warn_contravariance
;
1043 /* Return 1 if PARMS specifies a fixed number of parameters
1044 and none of their types is affected by default promotions. */
1047 self_promoting_args_p (parms
)
1051 for (t
= parms
; t
; t
= TREE_CHAIN (t
))
1053 register tree type
= TREE_VALUE (t
);
1055 if (TREE_CHAIN (t
) == 0 && type
!= void_type_node
)
1058 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
1064 if (C_PROMOTING_INTEGER_TYPE_P (type
))
1070 /* Return an unsigned type the same as TYPE in other respects.
1072 C++: must make these work for type variants as well. */
1075 unsigned_type (type
)
1078 tree type1
= TYPE_MAIN_VARIANT (type
);
1079 if (type1
== signed_char_type_node
|| type1
== char_type_node
)
1080 return unsigned_char_type_node
;
1081 if (type1
== integer_type_node
)
1082 return unsigned_type_node
;
1083 if (type1
== short_integer_type_node
)
1084 return short_unsigned_type_node
;
1085 if (type1
== long_integer_type_node
)
1086 return long_unsigned_type_node
;
1087 if (type1
== long_long_integer_type_node
)
1088 return long_long_unsigned_type_node
;
1092 /* Return a signed type the same as TYPE in other respects. */
1098 tree type1
= TYPE_MAIN_VARIANT (type
);
1099 if (type1
== unsigned_char_type_node
|| type1
== char_type_node
)
1100 return signed_char_type_node
;
1101 if (type1
== unsigned_type_node
)
1102 return integer_type_node
;
1103 if (type1
== short_unsigned_type_node
)
1104 return short_integer_type_node
;
1105 if (type1
== long_unsigned_type_node
)
1106 return long_integer_type_node
;
1107 if (type1
== long_long_unsigned_type_node
)
1108 return long_long_integer_type_node
;
1112 /* Return a type the same as TYPE except unsigned or
1113 signed according to UNSIGNEDP. */
1116 signed_or_unsigned_type (unsignedp
, type
)
1120 if (! INTEGRAL_TYPE_P (type
))
1122 if (TYPE_PRECISION (type
) == TYPE_PRECISION (signed_char_type_node
))
1123 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
1124 if (TYPE_PRECISION (type
) == TYPE_PRECISION (integer_type_node
))
1125 return unsignedp
? unsigned_type_node
: integer_type_node
;
1126 if (TYPE_PRECISION (type
) == TYPE_PRECISION (short_integer_type_node
))
1127 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
1128 if (TYPE_PRECISION (type
) == TYPE_PRECISION (long_integer_type_node
))
1129 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
1130 if (TYPE_PRECISION (type
) == TYPE_PRECISION (long_long_integer_type_node
))
1131 return (unsignedp
? long_long_unsigned_type_node
1132 : long_long_integer_type_node
);
1140 enum tree_code code
= TREE_CODE (type
);
1143 if (code
== FUNCTION_TYPE
)
1145 if (pedantic
|| warn_pointer_arith
)
1146 pedwarn ("ANSI C++ forbids taking the sizeof a function type");
1147 return size_int (1);
1149 if (code
== METHOD_TYPE
)
1151 if (pedantic
|| warn_pointer_arith
)
1152 pedwarn ("ANSI C++ forbids taking the sizeof a method type");
1153 return size_int (1);
1155 if (code
== VOID_TYPE
)
1157 if (pedantic
|| warn_pointer_arith
)
1158 pedwarn ("ANSI C++ forbids taking the sizeof a void type");
1159 return size_int (1);
1161 if (code
== ERROR_MARK
)
1162 return size_int (1);
1164 /* ARM $5.3.2: ``When applied to a reference, the result is the size of the
1165 referenced object.'' */
1166 if (code
== REFERENCE_TYPE
)
1167 type
= TREE_TYPE (type
);
1169 /* We couldn't find anything in the ARM or the draft standard that says,
1170 one way or the other, if doing sizeof on something that doesn't have
1171 an object associated with it is correct or incorrect. For example, if
1172 you declare `struct S { char str[16]; };', and in your program do
1173 a `sizeof (S::str)', should we flag that as an error or should we give
1174 the size of it? Since it seems like a reasonable thing to do, we'll go
1175 with giving the value. */
1176 if (code
== OFFSET_TYPE
)
1177 type
= TREE_TYPE (type
);
1179 /* @@ This also produces an error for a signature ref.
1180 In that case we should be able to do better. */
1181 if (IS_SIGNATURE (type
))
1183 error ("`sizeof' applied to a signature type");
1184 return size_int (0);
1187 if (TYPE_SIZE (type
) == 0)
1189 error ("`sizeof' applied to an incomplete type");
1190 return size_int (0);
1193 /* Convert in case a char is more than one unit. */
1194 t
= size_binop (CEIL_DIV_EXPR
, TYPE_SIZE (type
),
1195 size_int (TYPE_PRECISION (char_type_node
)));
1196 /* size_binop does not put the constant in range, so do it now. */
1197 if (TREE_CODE (t
) == INTEGER_CST
&& force_fit_type (t
, 0))
1198 TREE_CONSTANT_OVERFLOW (t
) = TREE_OVERFLOW (t
) = 1;
1203 c_sizeof_nowarn (type
)
1206 enum tree_code code
= TREE_CODE (type
);
1209 if (code
== FUNCTION_TYPE
1210 || code
== METHOD_TYPE
1211 || code
== VOID_TYPE
1212 || code
== ERROR_MARK
)
1213 return size_int (1);
1214 if (code
== REFERENCE_TYPE
)
1215 type
= TREE_TYPE (type
);
1217 if (TYPE_SIZE (type
) == 0)
1220 /* ??? Tiemann, why have any diagnostic here?
1221 There is none in the corresponding function for C. */
1222 warning ("sizeof applied to an incomplete type");
1224 return size_int (0);
1227 /* Convert in case a char is more than one unit. */
1228 t
= size_binop (CEIL_DIV_EXPR
, TYPE_SIZE (type
),
1229 size_int (TYPE_PRECISION (char_type_node
)));
1230 force_fit_type (t
, 0);
1234 /* Implement the __alignof keyword: Return the minimum required
1235 alignment of TYPE, measured in bytes. */
1241 enum tree_code code
= TREE_CODE (type
);
1244 if (code
== FUNCTION_TYPE
|| code
== METHOD_TYPE
)
1245 return size_int (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
1247 if (code
== VOID_TYPE
|| code
== ERROR_MARK
)
1248 return size_int (1);
1250 /* C++: this is really correct! */
1251 if (code
== REFERENCE_TYPE
)
1252 type
= TREE_TYPE (type
);
1254 /* @@ This also produces an error for a signature ref.
1255 In that case we should be able to do better. */
1256 if (IS_SIGNATURE (type
))
1258 error ("`__alignof' applied to a signature type");
1259 return size_int (1);
1262 t
= size_int (TYPE_ALIGN (type
) / BITS_PER_UNIT
);
1263 force_fit_type (t
, 0);
1267 /* Perform default promotions for C data used in expressions.
1268 Arrays and functions are converted to pointers;
1269 enumeral types or short or char, to int.
1270 In addition, manifest constants symbols are replaced by their values.
1272 C++: this will automatically bash references to their target type. */
1275 default_conversion (exp
)
1278 register tree type
= TREE_TYPE (exp
);
1279 register enum tree_code code
= TREE_CODE (type
);
1281 if (code
== OFFSET_TYPE
/* || TREE_CODE (exp) == OFFSET_REF */ )
1283 if (TREE_CODE (exp
) == OFFSET_REF
)
1284 return default_conversion (resolve_offset_ref (exp
));
1286 type
= TREE_TYPE (type
);
1287 code
= TREE_CODE (type
);
1290 if (code
== REFERENCE_TYPE
)
1292 exp
= convert_from_reference (exp
);
1293 type
= TREE_TYPE (exp
);
1294 code
= TREE_CODE (type
);
1297 /* Constants can be used directly unless they're not loadable. */
1298 if (TREE_CODE (exp
) == CONST_DECL
)
1299 exp
= DECL_INITIAL (exp
);
1300 /* Replace a nonvolatile const static variable with its value. */
1301 else if (TREE_READONLY_DECL_P (exp
) && DECL_MODE (exp
) != BLKmode
)
1303 exp
= decl_constant_value (exp
);
1304 type
= TREE_TYPE (exp
);
1307 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
1308 Leave such NOP_EXPRs, since RHS is being used in non-lvalue context. */
1310 if (INTEGRAL_CODE_P (code
))
1312 tree t
= type_promotes_to (type
);
1314 return convert (t
, exp
);
1316 if (flag_traditional
1317 && TYPE_MAIN_VARIANT (type
) == float_type_node
)
1318 return convert (double_type_node
, exp
);
1319 if (code
== VOID_TYPE
)
1321 error ("void value not ignored as it ought to be");
1322 return error_mark_node
;
1324 if (code
== FUNCTION_TYPE
)
1326 return build_unary_op (ADDR_EXPR
, exp
, 0);
1328 if (code
== METHOD_TYPE
)
1330 if (TREE_CODE (exp
) == OFFSET_REF
)
1332 my_friendly_assert (TREE_CODE (TREE_OPERAND (exp
, 1)) == FUNCTION_DECL
,
1334 return build_unary_op (ADDR_EXPR
, TREE_OPERAND (exp
, 1), 0);
1336 return build_unary_op (ADDR_EXPR
, exp
, 0);
1338 if (code
== ARRAY_TYPE
)
1343 int constp
, volatilep
;
1345 if (TREE_CODE (exp
) == INDIRECT_REF
)
1347 /* Stripping away the INDIRECT_REF is not the right
1348 thing to do for references... */
1349 tree inner
= TREE_OPERAND (exp
, 0);
1350 if (TREE_CODE (TREE_TYPE (inner
)) == REFERENCE_TYPE
)
1352 inner
= build1 (CONVERT_EXPR
,
1353 build_pointer_type (TREE_TYPE (TREE_TYPE (inner
))),
1355 TREE_REFERENCE_EXPR (inner
) = 1;
1357 return convert (TYPE_POINTER_TO (TREE_TYPE (type
)), inner
);
1360 if (TREE_CODE (exp
) == COMPOUND_EXPR
)
1362 tree op1
= default_conversion (TREE_OPERAND (exp
, 1));
1363 return build (COMPOUND_EXPR
, TREE_TYPE (op1
),
1364 TREE_OPERAND (exp
, 0), op1
);
1368 && ! (TREE_CODE (exp
) == CONSTRUCTOR
&& TREE_STATIC (exp
)))
1370 error ("invalid use of non-lvalue array");
1371 return error_mark_node
;
1374 constp
= volatilep
= 0;
1375 if (TREE_CODE_CLASS (TREE_CODE (exp
)) == 'r'
1376 || TREE_CODE_CLASS (TREE_CODE (exp
)) == 'd')
1378 constp
= TREE_READONLY (exp
);
1379 volatilep
= TREE_THIS_VOLATILE (exp
);
1382 restype
= TREE_TYPE (type
);
1383 if (TYPE_READONLY (type
) || TYPE_VOLATILE (type
)
1384 || constp
|| volatilep
)
1385 restype
= cp_build_type_variant (restype
,
1386 TYPE_READONLY (type
) || constp
,
1387 TYPE_VOLATILE (type
) || volatilep
);
1388 ptrtype
= build_pointer_type (restype
);
1390 if (TREE_CODE (exp
) == VAR_DECL
)
1392 /* ??? This is not really quite correct
1393 in that the type of the operand of ADDR_EXPR
1394 is not the target type of the type of the ADDR_EXPR itself.
1395 Question is, can this lossage be avoided? */
1396 adr
= build1 (ADDR_EXPR
, ptrtype
, exp
);
1397 if (mark_addressable (exp
) == 0)
1398 return error_mark_node
;
1399 TREE_CONSTANT (adr
) = staticp (exp
);
1400 TREE_SIDE_EFFECTS (adr
) = 0; /* Default would be, same as EXP. */
1403 /* This way is better for a COMPONENT_REF since it can
1404 simplify the offset for a component. */
1405 adr
= build_unary_op (ADDR_EXPR
, exp
, 1);
1406 return convert (ptrtype
, adr
);
1412 build_object_ref (datum
, basetype
, field
)
1413 tree datum
, basetype
, field
;
1416 if (datum
== error_mark_node
)
1417 return error_mark_node
;
1419 dtype
= TREE_TYPE (datum
);
1420 if (TREE_CODE (dtype
) == REFERENCE_TYPE
)
1421 dtype
= TREE_TYPE (dtype
);
1422 if (! IS_AGGR_TYPE_CODE (TREE_CODE (dtype
)))
1424 cp_error ("request for member `%T::%D' in expression of non-aggregate type `%T'",
1425 basetype
, field
, dtype
);
1426 return error_mark_node
;
1428 else if (IS_SIGNATURE (IDENTIFIER_TYPE_VALUE (basetype
)))
1430 warning ("signature name in scope resolution ignored");
1431 return build_component_ref (datum
, field
, NULL_TREE
, 1);
1433 else if (is_aggr_typedef (basetype
, 1))
1435 tree real_basetype
= IDENTIFIER_TYPE_VALUE (basetype
);
1436 tree binfo
= binfo_or_else (real_basetype
, TREE_TYPE (datum
));
1438 return build_component_ref (build_scoped_ref (datum
, basetype
),
1441 return error_mark_node
;
1444 /* Like `build_component_ref, but uses an already found field.
1445 Must compute access for C_C_D. Otherwise, ok. */
1447 build_component_ref_1 (datum
, field
, protect
)
1451 register tree basetype
= TREE_TYPE (datum
);
1452 register enum tree_code code
= TREE_CODE (basetype
);
1455 if (code
== REFERENCE_TYPE
)
1457 datum
= convert_from_reference (datum
);
1458 basetype
= TREE_TYPE (datum
);
1459 code
= TREE_CODE (basetype
);
1462 if (! IS_AGGR_TYPE_CODE (code
))
1464 if (code
!= ERROR_MARK
)
1465 cp_error ("request for member `%D' in `%E', which is of non-aggregate type `%T'",
1466 field
, datum
, basetype
);
1467 return error_mark_node
;
1470 if (TYPE_SIZE (basetype
) == 0)
1472 incomplete_type_error (0, basetype
);
1473 return error_mark_node
;
1476 /* Look up component name in the structure type definition. */
1478 if (field
== error_mark_node
)
1479 my_friendly_abort (115);
1481 if (TREE_STATIC (field
))
1486 enum access_type access
1487 = compute_access (TYPE_BINFO (current_class_type
), field
);
1489 if (access
== access_private
)
1491 cp_error ("field `%D' is private", field
);
1492 return error_mark_node
;
1494 else if (access
== access_protected
)
1496 cp_error ("field `%D' is protected", field
);
1497 return error_mark_node
;
1501 ref
= build (COMPONENT_REF
, TREE_TYPE (field
), datum
, field
);
1503 if (TREE_READONLY (datum
) || TREE_READONLY (field
))
1504 TREE_READONLY (ref
) = 1;
1505 if (TREE_THIS_VOLATILE (datum
) || TREE_THIS_VOLATILE (field
))
1506 TREE_THIS_VOLATILE (ref
) = 1;
1507 if (DECL_MUTABLE_P (field
))
1508 TREE_READONLY (ref
) = 0;
1513 /* Given a COND_EXPR in T, return it in a form that we can, for
1514 example, use as an lvalue. This code used to be in unary_complex_lvalue,
1515 but we needed it to deal with `a = (d == c) ? b : c' expressions, where
1516 we're dealing with aggregates. So, we now call this in unary_complex_lvalue,
1517 and in build_modify_expr. The case (in particular) that led to this was
1518 with CODE == ADDR_EXPR, since it's not an lvalue when we'd get it there. */
1520 rationalize_conditional_expr (code
, t
)
1521 enum tree_code code
;
1525 build_conditional_expr (TREE_OPERAND (t
, 0),
1526 build_unary_op (code
, TREE_OPERAND (t
, 1), 0),
1527 build_unary_op (code
, TREE_OPERAND (t
, 2), 0));
1531 build_component_ref (datum
, component
, basetype_path
, protect
)
1532 tree datum
, component
, basetype_path
;
1535 register tree basetype
= TREE_TYPE (datum
);
1536 register enum tree_code code
= TREE_CODE (basetype
);
1537 register tree field
= NULL
;
1540 /* If DATUM is a COMPOUND_EXPR or COND_EXPR, move our reference inside it. */
1541 switch (TREE_CODE (datum
))
1545 tree value
= build_component_ref (TREE_OPERAND (datum
, 1), component
,
1546 basetype_path
, protect
);
1547 return build (COMPOUND_EXPR
, TREE_TYPE (value
),
1548 TREE_OPERAND (datum
, 0), value
);
1551 return build_conditional_expr
1552 (TREE_OPERAND (datum
, 0),
1553 build_component_ref (TREE_OPERAND (datum
, 1), component
,
1554 basetype_path
, protect
),
1555 build_component_ref (TREE_OPERAND (datum
, 2), component
,
1556 basetype_path
, protect
));
1559 if (code
== REFERENCE_TYPE
)
1562 /* TREE_REFERENCE_EXPRs are not converted by `convert_from_reference'.
1563 @@ Maybe that is not right. */
1564 if (TREE_REFERENCE_EXPR (datum
))
1565 datum
= build1 (INDIRECT_REF
, TREE_TYPE (basetype
), datum
);
1568 datum
= convert_from_reference (datum
);
1569 basetype
= TREE_TYPE (datum
);
1570 code
= TREE_CODE (basetype
);
1573 /* First, see if there is a field or component with name COMPONENT. */
1574 if (TREE_CODE (component
) == TREE_LIST
)
1576 my_friendly_assert (!(TREE_CHAIN (component
) == NULL_TREE
1577 && DECL_CHAIN (TREE_VALUE (component
)) == NULL_TREE
), 309);
1578 return build (COMPONENT_REF
, TREE_TYPE (component
), datum
, component
);
1581 if (TREE_CODE (component
) == TYPE_EXPR
)
1582 return build_component_type_expr (datum
, component
, NULL_TREE
, protect
);
1585 if (! IS_AGGR_TYPE_CODE (code
))
1587 if (code
!= ERROR_MARK
)
1588 cp_error ("request for member `%D' in `%E', which is of non-aggregate type `%T'",
1589 component
, datum
, basetype
);
1590 return error_mark_node
;
1593 if (TYPE_SIZE (basetype
) == 0)
1595 incomplete_type_error (0, basetype
);
1596 return error_mark_node
;
1599 if (TREE_CODE (component
) == BIT_NOT_EXPR
)
1601 if (TYPE_IDENTIFIER (basetype
) != TREE_OPERAND (component
, 0))
1603 cp_error ("destructor specifier `%T::~%T' must have matching names",
1604 basetype
, TREE_OPERAND (component
, 0));
1605 return error_mark_node
;
1607 if (! TYPE_HAS_DESTRUCTOR (basetype
))
1609 cp_error ("type `%T' has no destructor", basetype
);
1610 return error_mark_node
;
1612 return TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (basetype
), 0);
1615 /* Look up component name in the structure type definition. */
1616 if (CLASSTYPE_VFIELD (basetype
)
1617 && DECL_NAME (CLASSTYPE_VFIELD (basetype
)) == component
)
1618 /* Special-case this because if we use normal lookups in an ambiguous
1619 hierarchy, the compiler will abort (because vptr lookups are
1620 not supposed to be ambiguous. */
1621 field
= CLASSTYPE_VFIELD (basetype
);
1624 if (basetype_path
== NULL_TREE
)
1625 basetype_path
= TYPE_BINFO (basetype
);
1626 field
= lookup_field (basetype_path
, component
,
1627 protect
&& ! VFIELD_NAME_P (component
), 0);
1628 if (field
== error_mark_node
)
1629 return error_mark_node
;
1631 if (field
== NULL_TREE
)
1633 /* Not found as a data field, look for it as a method. If found,
1634 then if this is the only possible one, return it, else
1635 report ambiguity error. */
1636 tree fndecls
= lookup_fnfields (basetype_path
, component
, 1);
1637 if (fndecls
== error_mark_node
)
1638 return error_mark_node
;
1641 if (TREE_CHAIN (fndecls
) == NULL_TREE
1642 && DECL_CHAIN (TREE_VALUE (fndecls
)) == NULL_TREE
)
1644 enum access_type access
;
1647 /* Unique, so use this one now. */
1648 basetype
= TREE_PURPOSE (fndecls
);
1649 fndecl
= TREE_VALUE (fndecls
);
1650 access
= compute_access (TREE_PURPOSE (fndecls
), fndecl
);
1651 if (access
== access_public
)
1653 if (DECL_VINDEX (fndecl
)
1654 && ! resolves_to_fixed_type_p (datum
, 0))
1656 tree addr
= build_unary_op (ADDR_EXPR
, datum
, 0);
1657 addr
= convert_pointer_to (DECL_CONTEXT (fndecl
), addr
);
1658 datum
= build_indirect_ref (addr
, NULL_PTR
);
1659 my_friendly_assert (datum
!= error_mark_node
, 310);
1660 fndecl
= build_vfn_ref (&addr
, datum
, DECL_VINDEX (fndecl
));
1664 if (access
== access_protected
)
1665 cp_error ("member function `%D' is protected", fndecl
);
1667 cp_error ("member function `%D' is private", fndecl
);
1668 return error_mark_node
;
1672 /* Just act like build_offset_ref, since the object does
1673 not matter unless we're actually calling the function. */
1674 tree t
= build_tree_list (error_mark_node
, fndecls
);
1675 TREE_TYPE (t
) = build_offset_type (basetype
,
1682 if (component
== ansi_opname
[(int) TYPE_EXPR
])
1683 cp_error ("`%#T' has no such type conversion operator", basetype
);
1686 cp_error ("`%#T' has no member named `%D'", basetype
, component
);
1687 return error_mark_node
;
1689 else if (TREE_TYPE (field
) == error_mark_node
)
1690 return error_mark_node
;
1692 if (TREE_CODE (field
) != FIELD_DECL
)
1694 if (TREE_CODE (field
) == TYPE_DECL
)
1696 cp_error ("invalid use of type decl `%#D' as expression", field
);
1697 return error_mark_node
;
1699 if (DECL_RTL (field
) != 0)
1700 assemble_external (field
);
1701 TREE_USED (field
) = 1;
1706 if (DECL_FIELD_CONTEXT (field
) != basetype
1707 && TYPE_USES_COMPLEX_INHERITANCE (basetype
))
1709 tree addr
= build_unary_op (ADDR_EXPR
, datum
, 0);
1710 if (integer_zerop (addr
))
1712 error ("invalid reference to NULL ptr, use ptr-to-member instead");
1713 return error_mark_node
;
1715 addr
= convert_pointer_to (DECL_FIELD_CONTEXT (field
), addr
);
1716 datum
= build_indirect_ref (addr
, NULL_PTR
);
1717 my_friendly_assert (datum
!= error_mark_node
, 311);
1719 ref
= fold (build (COMPONENT_REF
, TREE_TYPE (field
),
1720 break_out_cleanups (datum
), field
));
1722 if (TREE_READONLY (datum
) || TREE_READONLY (field
))
1723 TREE_READONLY (ref
) = 1;
1724 if (TREE_THIS_VOLATILE (datum
) || TREE_THIS_VOLATILE (field
))
1725 TREE_THIS_VOLATILE (ref
) = 1;
1726 if (DECL_MUTABLE_P (field
))
1727 TREE_READONLY (ref
) = 0;
1732 /* Given an expression PTR for a pointer, return an expression
1733 for the value pointed to.
1734 ERRORSTRING is the name of the operator to appear in error messages.
1736 This function may need to overload OPERATOR_FNNAME.
1737 Must also handle REFERENCE_TYPEs for C++. */
1740 build_x_indirect_ref (ptr
, errorstring
)
1744 tree rval
= build_opfncall (INDIRECT_REF
, LOOKUP_NORMAL
, ptr
, NULL_TREE
, NULL_TREE
);
1747 return build_indirect_ref (ptr
, errorstring
);
1751 build_indirect_ref (ptr
, errorstring
)
1755 register tree pointer
= default_conversion (ptr
);
1756 register tree type
= TREE_TYPE (pointer
);
1758 if (ptr
== current_class_decl
)
1761 if (TREE_CODE (type
) == POINTER_TYPE
|| TREE_CODE (type
) == REFERENCE_TYPE
)
1763 if (TREE_CODE (pointer
) == ADDR_EXPR
1764 && (TREE_TYPE (TREE_OPERAND (pointer
, 0))
1765 == TREE_TYPE (type
)))
1766 return TREE_OPERAND (pointer
, 0);
1769 tree t
= TREE_TYPE (type
);
1770 register tree ref
= build1 (INDIRECT_REF
,
1771 TYPE_MAIN_VARIANT (t
), pointer
);
1773 TREE_READONLY (ref
) = TYPE_READONLY (t
);
1774 TREE_THIS_VOLATILE (ref
) = TYPE_VOLATILE (t
);
1775 TREE_SIDE_EFFECTS (ref
)
1776 = TYPE_VOLATILE (t
) || TREE_SIDE_EFFECTS (pointer
);
1780 /* `pointer' won't be an error_mark_node if we were given a
1781 pointer to member, so it's cool to check for this here. */
1782 else if (TYPE_PTRMEMFUNC_P (type
))
1783 error ("invalid use of `%s' on pointer to member function", errorstring
);
1784 else if (TREE_CODE (type
) == RECORD_TYPE
1785 && (IS_SIGNATURE_POINTER (type
) || IS_SIGNATURE_REFERENCE (type
)))
1786 error ("cannot dereference signature pointer/reference");
1787 else if (pointer
!= error_mark_node
)
1790 error ("invalid type argument of `%s'", errorstring
);
1792 error ("invalid type argument");
1794 return error_mark_node
;
1797 /* This handles expressions of the form "a[i]", which denotes
1800 This is logically equivalent in C to *(a+i), but we may do it differently.
1801 If A is a variable or a member, we generate a primitive ARRAY_REF.
1802 This avoids forcing the array out of registers, and can work on
1803 arrays that are not lvalues (for example, members of structures returned
1806 If INDEX is of some user-defined type, it must be converted to
1807 integer type. Otherwise, to make a compatible PLUS_EXPR, it
1808 will inherit the type of the array, which will be some pointer type. */
1811 build_x_array_ref (array
, index
)
1814 tree rval
= build_opfncall (ARRAY_REF
, LOOKUP_NORMAL
, array
, index
, NULL_TREE
);
1817 return build_array_ref (array
, index
);
1821 build_array_ref (array
, idx
)
1828 error ("subscript missing in array reference");
1829 return error_mark_node
;
1832 if (TREE_TYPE (array
) == error_mark_node
1833 || TREE_TYPE (idx
) == error_mark_node
)
1834 return error_mark_node
;
1836 itype
= TREE_TYPE (idx
);
1837 /* We must check here for the reference, so we can do the possible
1838 conversions immediately afterwards. */
1839 if (TREE_CODE (itype
) == REFERENCE_TYPE
)
1841 idx
= convert_from_reference (idx
);
1842 itype
= TREE_TYPE (idx
);
1845 if (IS_AGGR_TYPE (itype
))
1847 if (TYPE_HAS_INT_CONVERSION (itype
))
1848 idx
= build_type_conversion (CONVERT_EXPR
,
1849 integer_type_node
, idx
, 1);
1852 error_with_aggr_type (itype
,
1853 "type `%s' requires integer conversion for array indexing");
1854 return error_mark_node
;
1858 if (TREE_CODE (TREE_TYPE (array
)) == ARRAY_TYPE
1859 && TREE_CODE (array
) != INDIRECT_REF
)
1863 /* Subscripting with type char is likely to lose
1864 on a machine where chars are signed.
1865 So warn on any machine, but optionally.
1866 Don't warn for unsigned char since that type is safe.
1867 Don't warn for signed char because anyone who uses that
1868 must have done so deliberately. */
1869 if (warn_char_subscripts
1870 && TYPE_MAIN_VARIANT (TREE_TYPE (idx
)) == char_type_node
)
1871 warning ("array subscript has type `char'");
1873 /* Apply default promotions *after* noticing character types. */
1874 idx
= default_conversion (idx
);
1876 if (TREE_CODE (TREE_TYPE (idx
)) != INTEGER_TYPE
)
1878 error ("array subscript is not an integer");
1879 return error_mark_node
;
1882 /* An array that is indexed by a non-constant
1883 cannot be stored in a register; we must be able to do
1884 address arithmetic on its address.
1885 Likewise an array of elements of variable size. */
1886 if (TREE_CODE (idx
) != INTEGER_CST
1887 || (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array
))) != 0
1888 && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array
)))) != INTEGER_CST
))
1890 if (mark_addressable (array
) == 0)
1891 return error_mark_node
;
1893 /* An array that is indexed by a constant value which is not within
1894 the array bounds cannot be stored in a register either; because we
1895 would get a crash in store_bit_field/extract_bit_field when trying
1896 to access a non-existent part of the register. */
1897 if (TREE_CODE (idx
) == INTEGER_CST
1898 && TYPE_VALUES (TREE_TYPE (array
))
1899 && ! int_fits_type_p (idx
, TYPE_VALUES (TREE_TYPE (array
))))
1901 if (mark_addressable (array
) == 0)
1902 return error_mark_node
;
1905 /* Note in C++ we don't bother warning about subscripting a
1906 `register' array, since it's valid in C++ to take the address
1907 of something with that storage specification. */
1908 if (pedantic
&& !lvalue_p (array
))
1909 pedwarn ("ANSI C++ forbids subscripting non-lvalue array");
1914 while (TREE_CODE (foo
) == COMPONENT_REF
)
1915 foo
= TREE_OPERAND (foo
, 0);
1916 if (TREE_CODE (foo
) == VAR_DECL
&& DECL_REGISTER (foo
))
1917 pedwarn ("ANSI C++ forbids subscripting non-lvalue array");
1920 type
= TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (array
)));
1921 rval
= build (ARRAY_REF
, type
, array
, idx
);
1922 /* Array ref is const/volatile if the array elements are
1923 or if the array is.. */
1924 TREE_READONLY (rval
)
1925 |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array
)))
1926 | TREE_READONLY (array
));
1927 TREE_SIDE_EFFECTS (rval
)
1928 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array
)))
1929 | TREE_SIDE_EFFECTS (array
));
1930 TREE_THIS_VOLATILE (rval
)
1931 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array
)))
1932 /* This was added by rms on 16 Nov 91.
1933 It fixes vol struct foo *a; a->elts[1]
1934 in an inline function.
1935 Hope it doesn't break something else. */
1936 | TREE_THIS_VOLATILE (array
));
1937 return require_complete_type (fold (rval
));
1941 tree ar
= default_conversion (array
);
1942 tree ind
= default_conversion (idx
);
1944 /* Put the integer in IND to simplify error checking. */
1945 if (TREE_CODE (TREE_TYPE (ar
)) == INTEGER_TYPE
)
1952 if (ar
== error_mark_node
)
1955 if (TREE_CODE (TREE_TYPE (ar
)) != POINTER_TYPE
)
1957 error ("subscripted value is neither array nor pointer");
1958 return error_mark_node
;
1960 if (TREE_CODE (TREE_TYPE (ind
)) != INTEGER_TYPE
)
1962 error ("array subscript is not an integer");
1963 return error_mark_node
;
1966 return build_indirect_ref (build_binary_op_nodefault (PLUS_EXPR
, ar
, ind
, PLUS_EXPR
),
1971 /* Build a function call to function FUNCTION with parameters PARAMS.
1972 PARAMS is a list--a chain of TREE_LIST nodes--in which the
1973 TREE_VALUE of each node is a parameter-expression.
1974 FUNCTION's data type may be a function type or a pointer-to-function.
1976 For C++: If FUNCTION's data type is a TREE_LIST, then the tree list
1977 is the list of possible methods that FUNCTION could conceivably
1978 be. If the list of methods comes from a class, then it will be
1979 a list of lists (where each element is associated with the class
1980 that produced it), otherwise it will be a simple list (for
1981 functions overloaded in global scope).
1983 In the first case, TREE_VALUE (function) is the head of one of those
1984 lists, and TREE_PURPOSE is the name of the function.
1986 In the second case, TREE_PURPOSE (function) is the function's
1989 DECL is the class instance variable, usually CURRENT_CLASS_DECL. */
1992 * [eichin:19911015.1726EST] actually return a possibly incomplete
1996 build_x_function_call (function
, params
, decl
)
1997 tree function
, params
, decl
;
2002 if (function
== error_mark_node
)
2003 return error_mark_node
;
2005 type
= TREE_TYPE (function
);
2006 is_method
= ((TREE_CODE (function
) == TREE_LIST
2007 && current_class_type
!= NULL_TREE
2008 && IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (function
)) == function
)
2009 || TREE_CODE (function
) == IDENTIFIER_NODE
2010 || TREE_CODE (type
) == METHOD_TYPE
2011 || TYPE_PTRMEMFUNC_P (type
));
2013 /* Handle methods, friends, and overloaded functions, respectively. */
2016 if (TREE_CODE (function
) == FUNCTION_DECL
)
2018 if (DECL_NAME (function
))
2019 function
= DECL_NAME (function
);
2021 function
= TYPE_IDENTIFIER (DECL_CLASS_CONTEXT (function
));
2023 else if (TREE_CODE (function
) == TREE_LIST
)
2026 if (TREE_CODE (TREE_VALUE (function
)) == TREE_LIST
)
2027 function
= TREE_PURPOSE (TREE_VALUE (function
));
2029 function
= TREE_PURPOSE (function
);
2031 my_friendly_assert (TREE_CODE (TREE_VALUE (function
)) == FUNCTION_DECL
, 312);
2032 function
= TREE_PURPOSE (function
);
2035 else if (TREE_CODE (function
) != IDENTIFIER_NODE
)
2037 if (TREE_CODE (function
) == OFFSET_REF
)
2039 if (TREE_OPERAND (function
, 0))
2040 decl
= TREE_OPERAND (function
, 0);
2042 /* Call via a pointer to member function. */
2043 if (decl
== NULL_TREE
)
2045 error ("pointer to member function called, but not in class scope");
2046 return error_mark_node
;
2048 /* What other type of POINTER_TYPE could this be? */
2049 if (TREE_CODE (TREE_TYPE (function
)) != POINTER_TYPE
2050 && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (function
))
2051 && TREE_CODE (function
) != OFFSET_REF
)
2052 function
= build (OFFSET_REF
, TREE_TYPE (type
), NULL_TREE
, function
);
2056 /* this is an abbreviated method call.
2057 must go through here in case it is a virtual function.
2058 @@ Perhaps this could be optimized. */
2060 if (decl
== NULL_TREE
)
2062 if (current_class_type
== NULL_TREE
)
2064 error ("object missing in call to method `%s'",
2065 IDENTIFIER_POINTER (function
));
2066 return error_mark_node
;
2068 /* Yow: call from a static member function. */
2069 decl
= build1 (NOP_EXPR
, TYPE_POINTER_TO (current_class_type
),
2071 decl
= build_indirect_ref (decl
, NULL_PTR
);
2074 return build_method_call (decl
, function
, params
,
2075 NULL_TREE
, LOOKUP_NORMAL
);
2077 else if (TREE_CODE (function
) == COMPONENT_REF
2078 && type
== unknown_type_node
)
2080 /* Should we undo what was done in build_component_ref? */
2081 if (TREE_CODE (TREE_PURPOSE (TREE_OPERAND (function
, 1))) == TREE_VEC
)
2082 /* Get the name that build_component_ref hid. */
2083 function
= DECL_NAME (TREE_VALUE (TREE_OPERAND (function
, 1)));
2085 function
= TREE_PURPOSE (TREE_OPERAND (function
, 1));
2086 return build_method_call (decl
, function
, params
,
2087 NULL_TREE
, LOOKUP_NORMAL
);
2089 else if (TREE_CODE (function
) == TREE_LIST
)
2091 if (TREE_VALUE (function
) == NULL_TREE
)
2093 cp_error ("function `%D' declared overloaded, but no definitions appear with which to resolve it?!?",
2094 TREE_PURPOSE (function
));
2095 return error_mark_node
;
2099 tree val
= TREE_VALUE (function
);
2101 if (TREE_CODE (val
) == TEMPLATE_DECL
)
2102 return build_overload_call_maybe
2103 (function
, params
, LOOKUP_COMPLAIN
, (struct candidate
*)0);
2104 else if (DECL_CHAIN (val
) != NULL_TREE
)
2105 return build_overload_call
2106 (function
, params
, LOOKUP_COMPLAIN
, (struct candidate
*)0);
2108 my_friendly_abort (360);
2113 if (TREE_CODE (function
) == OFFSET_REF
)
2115 /* If the component is a data element (or a virtual function), we play
2116 games here to make things work. */
2119 if (TREE_OPERAND (function
, 0))
2120 decl
= TREE_OPERAND (function
, 0);
2124 decl_addr
= build_unary_op (ADDR_EXPR
, decl
, 0);
2125 function
= get_member_function_from_ptrfunc (&decl_addr
, decl
,
2126 TREE_OPERAND (function
, 1));
2127 params
= tree_cons (NULL_TREE
, decl_addr
, params
);
2128 return build_function_call (function
, params
);
2131 type
= TREE_TYPE (function
);
2132 if (type
!= error_mark_node
)
2134 if (TREE_CODE (type
) == REFERENCE_TYPE
)
2135 type
= TREE_TYPE (type
);
2137 if (TYPE_LANG_SPECIFIC (type
) && TYPE_OVERLOADS_CALL_EXPR (type
))
2138 return build_opfncall (CALL_EXPR
, LOOKUP_NORMAL
, function
, params
, NULL_TREE
);
2143 tree fntype
= TREE_TYPE (function
);
2146 /* Explicitly named method? */
2147 if (TREE_CODE (function
) == FUNCTION_DECL
)
2148 ctypeptr
= TYPE_POINTER_TO (DECL_CLASS_CONTEXT (function
));
2149 /* Expression with ptr-to-method type? It could either be a plain
2150 usage, or it might be a case where the ptr-to-method is being
2151 passed in as an argument. */
2152 else if (TYPE_PTRMEMFUNC_P (fntype
))
2154 tree rec
= TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (fntype
)));
2155 ctypeptr
= TYPE_POINTER_TO (rec
);
2157 /* Unexpected node type? */
2159 my_friendly_abort (116);
2160 if (decl
== NULL_TREE
)
2162 if (current_function_decl
2163 && DECL_STATIC_FUNCTION_P (current_function_decl
))
2164 error ("invalid call to member function needing `this' in static member function scope");
2166 error ("pointer to member function called, but not in class scope");
2167 return error_mark_node
;
2169 if (TREE_CODE (TREE_TYPE (decl
)) != POINTER_TYPE
2170 && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (decl
)))
2172 decl
= build_unary_op (ADDR_EXPR
, decl
, 0);
2173 decl
= convert_pointer_to (TREE_TYPE (ctypeptr
), decl
);
2176 decl
= build_c_cast (ctypeptr
, decl
, 0);
2177 params
= tree_cons (NULL_TREE
, decl
, params
);
2180 return build_function_call (function
, params
);
2183 /* Resolve a pointer to member function. INSTANCE is the object
2184 instance to use, if the member points to a virtual member. */
2187 get_member_function_from_ptrfunc (instance_ptrptr
, instance
, function
)
2188 tree
*instance_ptrptr
;
2192 if (TREE_CODE (function
) == OFFSET_REF
)
2194 function
= TREE_OPERAND (function
, 1);
2197 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (function
)))
2199 tree fntype
= TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (function
));
2200 tree index
= save_expr (build_component_ref (function
,
2203 tree e1
= build (GT_EXPR
, delta_type_node
, index
,
2204 convert (delta_type_node
, integer_zero_node
));
2205 tree delta
= convert (ptrdiff_type_node
,
2206 build_component_ref (function
, delta_identifier
, 0, 0));
2207 tree delta2
= DELTA2_FROM_PTRMEMFUNC (function
);
2212 /* convert down to the right base, before using the instance. */
2213 instance
= convert_pointer_to_real (TYPE_METHOD_BASETYPE (TREE_TYPE (fntype
)),
2214 build_unary_op (ADDR_EXPR
, instance
, 0));
2215 if (instance
== error_mark_node
)
2218 vtbl
= convert_pointer_to (ptr_type_node
, instance
);
2221 build_pointer_type (build_pointer_type (vtable_entry_type
)),
2222 vtbl
, convert (ptrdiff_type_node
, delta2
));
2223 vtbl
= build_indirect_ref (vtbl
, NULL_PTR
);
2224 aref
= build_array_ref (vtbl
, build_binary_op (MINUS_EXPR
,
2226 integer_one_node
, 1));
2227 if (! flag_vtable_thunks
)
2229 aref
= save_expr (aref
);
2231 /* Save the intermediate result in a SAVE_EXPR so we don't have to
2232 compute each component of the virtual function pointer twice. */
2233 if (/* !building_cleanup && */ TREE_CODE (aref
) == INDIRECT_REF
)
2234 TREE_OPERAND (aref
, 0) = save_expr (TREE_OPERAND (aref
, 0));
2236 delta
= build_binary_op (PLUS_EXPR
,
2237 build_conditional_expr (e1
, build_component_ref (aref
, delta_identifier
, 0, 0), integer_zero_node
),
2241 *instance_ptrptr
= build (PLUS_EXPR
, TREE_TYPE (*instance_ptrptr
),
2244 if (flag_vtable_thunks
)
2247 e2
= build_component_ref (aref
, pfn_identifier
, 0, 0);
2249 e3
= PFN_FROM_PTRMEMFUNC (function
);
2250 TREE_TYPE (e2
) = TREE_TYPE (e3
);
2251 function
= build_conditional_expr (e1
, e2
, e3
);
2257 build_function_call_real (function
, params
, require_complete
, flags
)
2258 tree function
, params
;
2259 int require_complete
, flags
;
2261 register tree fntype
, fndecl
;
2262 register tree value_type
;
2263 register tree coerced_params
;
2264 tree name
= NULL_TREE
, assembler_name
= NULL_TREE
;
2267 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
2268 Strip such NOP_EXPRs, since FUNCTION is used in non-lvalue context. */
2269 if (TREE_CODE (function
) == NOP_EXPR
2270 && TREE_TYPE (function
) == TREE_TYPE (TREE_OPERAND (function
, 0)))
2271 function
= TREE_OPERAND (function
, 0);
2273 if (TREE_CODE (function
) == FUNCTION_DECL
)
2275 name
= DECL_NAME (function
);
2276 assembler_name
= DECL_ASSEMBLER_NAME (function
);
2278 GNU_xref_call (current_function_decl
,
2279 IDENTIFIER_POINTER (name
? name
2280 : TYPE_IDENTIFIER (DECL_CLASS_CONTEXT (function
))));
2281 assemble_external (function
);
2284 /* Convert anything with function type to a pointer-to-function. */
2287 && IDENTIFIER_LENGTH (name
) == 4
2288 && ! strcmp (IDENTIFIER_POINTER (name
), "main")
2289 && DECL_CONTEXT (function
) == NULL_TREE
)
2291 pedwarn ("ANSI C++ forbids calling `main' from within program");
2294 /* Differs from default_conversion by not setting TREE_ADDRESSABLE
2295 (because calling an inline function does not mean the function
2296 needs to be separately compiled). */
2298 if (DECL_INLINE (function
))
2300 fntype
= build_type_variant (TREE_TYPE (function
),
2301 TREE_READONLY (function
),
2302 TREE_THIS_VOLATILE (function
));
2303 function
= build1 (ADDR_EXPR
, build_pointer_type (fntype
), function
);
2307 assemble_external (function
);
2308 TREE_USED (function
) = 1;
2309 function
= default_conversion (function
);
2316 /* Convert anything with function type to a pointer-to-function. */
2317 if (function
== error_mark_node
)
2318 return error_mark_node
;
2319 function
= default_conversion (function
);
2322 fntype
= TREE_TYPE (function
);
2324 if (TYPE_PTRMEMFUNC_P (fntype
))
2326 tree instance_ptr
= build_unary_op (ADDR_EXPR
, C_C_D
, 0);
2327 fntype
= TYPE_PTRMEMFUNC_FN_TYPE (fntype
);
2328 function
= get_member_function_from_ptrfunc (&instance_ptr
, C_C_D
, function
);
2331 is_method
= (TREE_CODE (fntype
) == POINTER_TYPE
2332 && TREE_CODE (TREE_TYPE (fntype
)) == METHOD_TYPE
);
2334 if (!((TREE_CODE (fntype
) == POINTER_TYPE
2335 && TREE_CODE (TREE_TYPE (fntype
)) == FUNCTION_TYPE
)
2338 error ("called object is not a function");
2339 return error_mark_node
;
2342 /* fntype now gets the type of function pointed to. */
2343 fntype
= TREE_TYPE (fntype
);
2345 /* Convert the parameters to the types declared in the
2346 function prototype, or apply default promotions. */
2348 if (flags
& LOOKUP_COMPLAIN
)
2349 coerced_params
= convert_arguments (NULL_TREE
, TYPE_ARG_TYPES (fntype
),
2350 params
, fndecl
, LOOKUP_NORMAL
);
2352 coerced_params
= convert_arguments (NULL_TREE
, TYPE_ARG_TYPES (fntype
),
2355 /* Check for errors in format strings. */
2357 if (warn_format
&& (name
|| assembler_name
))
2358 check_function_format (name
, assembler_name
, coerced_params
);
2360 /* Recognize certain built-in functions so we can make tree-codes
2361 other than CALL_EXPR. We do this when it enables fold-const.c
2362 to do something useful. */
2364 if (TREE_CODE (function
) == ADDR_EXPR
2365 && TREE_CODE (TREE_OPERAND (function
, 0)) == FUNCTION_DECL
2366 && DECL_BUILT_IN (TREE_OPERAND (function
, 0)))
2367 switch (DECL_FUNCTION_CODE (TREE_OPERAND (function
, 0)))
2372 if (coerced_params
== 0)
2373 return integer_zero_node
;
2374 return build_unary_op (ABS_EXPR
, TREE_VALUE (coerced_params
), 0);
2378 value_type
= TREE_TYPE (fntype
) ? TREE_TYPE (fntype
) : void_type_node
;
2380 register tree result
=
2381 build (CALL_EXPR
, value_type
,
2382 function
, coerced_params
, NULL_TREE
);
2384 TREE_SIDE_EFFECTS (result
) = 1;
2386 if (! require_complete
)
2387 return convert_from_reference (result
);
2388 if (value_type
== void_type_node
)
2390 result
= require_complete_type (result
);
2391 return convert_from_reference (result
);
2396 build_function_call (function
, params
)
2397 tree function
, params
;
2399 return build_function_call_real (function
, params
, 1, LOOKUP_NORMAL
);
2403 build_function_call_maybe (function
, params
)
2404 tree function
, params
;
2406 return build_function_call_real (function
, params
, 0, 0);
2410 /* Convert the actual parameter expressions in the list VALUES
2411 to the types in the list TYPELIST.
2412 If parmdecls is exhausted, or when an element has NULL as its type,
2413 perform the default conversions.
2415 RETURN_LOC is the location of the return value, if known, NULL_TREE
2416 otherwise. This is useful in the case where we can avoid creating
2417 a temporary variable in the case where we can initialize the return
2418 value directly. If we are not eliding constructors, then we set this
2419 to NULL_TREE to avoid this avoidance.
2421 NAME is an IDENTIFIER_NODE or 0. It is used only for error messages.
2423 This is also where warnings about wrong number of args are generated.
2425 Return a list of expressions for the parameters as converted.
2427 Both VALUES and the returned value are chains of TREE_LIST nodes
2428 with the elements of the list in the TREE_VALUE slots of those nodes.
2430 In C++, unspecified trailing parameters can be filled in with their
2431 default arguments, if such were specified. Do so here. */
2434 convert_arguments (return_loc
, typelist
, values
, fndecl
, flags
)
2435 tree return_loc
, typelist
, values
, fndecl
;
2438 extern tree gc_protect_fndecl
;
2439 register tree typetail
, valtail
;
2440 register tree result
= NULL_TREE
;
2444 if (! flag_elide_constructors
)
2449 if (TREE_CODE (TREE_TYPE (fndecl
)) == METHOD_TYPE
)
2451 if (DECL_NAME (fndecl
) == NULL_TREE
2452 || IDENTIFIER_HAS_TYPE_VALUE (DECL_NAME (fndecl
)))
2453 called_thing
= "constructor";
2455 called_thing
= "member function";
2458 called_thing
= "function";
2461 for (valtail
= values
, typetail
= typelist
;
2463 valtail
= TREE_CHAIN (valtail
), i
++)
2465 register tree type
= typetail
? TREE_VALUE (typetail
) : 0;
2466 register tree val
= TREE_VALUE (valtail
);
2468 if (val
== error_mark_node
)
2471 if (type
== void_type_node
)
2475 char *buf
= (char *)alloca (40 + strlen (called_thing
));
2476 sprintf (buf
, "too many arguments to %s `%%s'", called_thing
);
2477 error_with_decl (fndecl
, buf
);
2478 error ("at this point in file");
2481 error ("too many arguments to function");
2482 /* In case anybody wants to know if this argument
2485 TREE_TYPE (tree_last (result
)) = error_mark_node
;
2489 /* The tree type of the parameter being passed may not yet be
2490 known. In this case, its type is TYPE_UNKNOWN, and will
2491 be instantiated by the type given by TYPE. If TYPE
2492 is also NULL, the tree type of VAL is ERROR_MARK_NODE. */
2493 if (type
&& type_unknown_p (val
))
2494 val
= require_instantiated_type (type
, val
, integer_zero_node
);
2495 else if (type_unknown_p (val
))
2497 /* Strip the `&' from an overloaded FUNCTION_DECL. */
2498 if (TREE_CODE (val
) == ADDR_EXPR
)
2499 val
= TREE_OPERAND (val
, 0);
2500 if (TREE_CODE (val
) == TREE_LIST
2501 && TREE_CHAIN (val
) == NULL_TREE
2502 && TREE_TYPE (TREE_VALUE (val
)) != NULL_TREE
2503 && (TREE_TYPE (val
) == unknown_type_node
2504 || DECL_CHAIN (TREE_VALUE (val
)) == NULL_TREE
))
2505 /* Instantiates automatically. */
2506 val
= TREE_VALUE (val
);
2509 error ("insufficient type information in parameter list");
2510 val
= integer_zero_node
;
2513 else if (TREE_CODE (val
) == OFFSET_REF
2514 && TREE_CODE (TREE_TYPE (val
)) == METHOD_TYPE
)
2516 /* This is unclean. Should be handled elsewhere. */
2517 val
= build_unary_op (ADDR_EXPR
, val
, 0);
2519 else if (TREE_CODE (val
) == OFFSET_REF
)
2520 val
= resolve_offset_ref (val
);
2524 /* This code forces the assumption that if we have a ptr-to-func
2525 type in an arglist, that every routine that wants to check
2526 its validity has done so, and thus we need not do any
2527 more conversion. I don't remember why this is necessary. */
2528 else if (TREE_CODE (ttype
) == FUNCTION_TYPE
2530 || TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
2531 || TREE_CODE (TREE_TYPE (type
)) == VOID_TYPE
))
2533 type
= build_pointer_type (ttype
);
2538 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
2539 Strip such NOP_EXPRs, since VAL is used in non-lvalue context. */
2540 if (TREE_CODE (val
) == NOP_EXPR
2541 && TREE_TYPE (val
) == TREE_TYPE (TREE_OPERAND (val
, 0))
2542 && (type
== 0 || TREE_CODE (type
) != REFERENCE_TYPE
))
2543 val
= TREE_OPERAND (val
, 0);
2545 if (type
== 0 || TREE_CODE (type
) != REFERENCE_TYPE
)
2547 if (TREE_CODE (TREE_TYPE (val
)) == ARRAY_TYPE
2548 || TREE_CODE (TREE_TYPE (val
)) == FUNCTION_TYPE
2549 || TREE_CODE (TREE_TYPE (val
)) == METHOD_TYPE
)
2550 val
= default_conversion (val
);
2552 val
= require_complete_type (val
);
2555 if (val
== error_mark_node
)
2560 /* Formal parm type is specified by a function prototype. */
2563 if (TYPE_SIZE (type
) == 0)
2565 error ("parameter type of called function is incomplete");
2570 #if 0 && defined (PROMOTE_PROTOTYPES)
2571 /* This breaks user-defined conversions. */
2572 /* Rather than truncating and then reextending,
2573 convert directly to int, if that's the type we will want. */
2574 if (! flag_traditional
2575 && (TREE_CODE (type
) == INTEGER_TYPE
2576 || TREE_CODE (type
) == ENUMERAL_TYPE
)
2577 && (TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
)))
2578 type
= integer_type_node
;
2580 parmval
= convert_for_initialization (return_loc
, type
, val
, flags
,
2581 "argument passing", fndecl
, i
);
2582 #ifdef PROMOTE_PROTOTYPES
2583 if ((TREE_CODE (type
) == INTEGER_TYPE
2584 || TREE_CODE (type
) == ENUMERAL_TYPE
)
2585 && (TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
)))
2586 parmval
= default_conversion (parmval
);
2589 result
= tree_cons (NULL_TREE
, parmval
, result
);
2593 if (TREE_CODE (TREE_TYPE (val
)) == REFERENCE_TYPE
)
2594 val
= convert_from_reference (val
);
2596 if (TREE_CODE (TREE_TYPE (val
)) == REAL_TYPE
2597 && (TYPE_PRECISION (TREE_TYPE (val
))
2598 < TYPE_PRECISION (double_type_node
)))
2599 /* Convert `float' to `double'. */
2600 result
= tree_cons (NULL_TREE
, convert (double_type_node
, val
), result
);
2601 else if (TYPE_LANG_SPECIFIC (TREE_TYPE (val
))
2602 && (TYPE_HAS_INIT_REF (TREE_TYPE (val
))
2603 || TYPE_HAS_ASSIGN_REF (TREE_TYPE (val
))))
2605 cp_warning ("cannot pass objects of type `%T' through `...'",
2607 result
= tree_cons (NULL_TREE
, val
, result
);
2610 /* Convert `short' and `char' to full-size `int'. */
2611 result
= tree_cons (NULL_TREE
, default_conversion (val
), result
);
2615 /* There are certain functions for which we don't need
2616 to protect our arguments. GC_PROTECT_FNDECL is one. */
2617 && fndecl
!= gc_protect_fndecl
2618 && type_needs_gc_entry (TREE_TYPE (TREE_VALUE (result
)))
2619 && ! value_safe_from_gc (NULL_TREE
, TREE_VALUE (result
)))
2620 /* This will build a temporary variable whose cleanup is
2621 to clear the obstack entry. */
2622 TREE_VALUE (result
) = protect_value_from_gc (NULL_TREE
,
2623 TREE_VALUE (result
));
2626 typetail
= TREE_CHAIN (typetail
);
2629 if (typetail
!= 0 && typetail
!= void_list_node
)
2631 /* See if there are default arguments that can be used */
2632 if (TREE_PURPOSE (typetail
))
2634 for (; typetail
!= void_list_node
; ++i
)
2636 tree type
= TREE_VALUE (typetail
);
2637 tree val
= TREE_PURPOSE (typetail
);
2640 if (val
== NULL_TREE
)
2641 parmval
= error_mark_node
;
2642 else if (TREE_CODE (val
) == CONSTRUCTOR
)
2644 parmval
= digest_init (type
, val
, (tree
*)0);
2645 parmval
= convert_for_initialization (return_loc
, type
, parmval
, flags
,
2646 "default constructor", fndecl
, i
);
2650 /* This could get clobbered by the following call. */
2651 if (TREE_HAS_CONSTRUCTOR (val
))
2652 val
= copy_node (val
);
2654 parmval
= convert_for_initialization (return_loc
, type
, val
, flags
,
2655 "default argument", fndecl
, i
);
2656 #ifdef PROMOTE_PROTOTYPES
2657 if ((TREE_CODE (type
) == INTEGER_TYPE
2658 || TREE_CODE (type
) == ENUMERAL_TYPE
)
2659 && (TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
)))
2660 parmval
= default_conversion (parmval
);
2665 && type_needs_gc_entry (TREE_TYPE (parmval
))
2666 && ! value_safe_from_gc (NULL_TREE
, parmval
))
2667 parmval
= protect_value_from_gc (NULL_TREE
, parmval
);
2669 result
= tree_cons (0, parmval
, result
);
2670 typetail
= TREE_CHAIN (typetail
);
2671 /* ends with `...'. */
2672 if (typetail
== NULL_TREE
)
2680 char *buf
= (char *)alloca (32 + strlen (called_thing
));
2681 sprintf (buf
, "too few arguments to %s `%%#D'", called_thing
);
2682 cp_error_at (buf
, fndecl
);
2683 error ("at this point in file");
2686 error ("too few arguments to function");
2687 return error_mark_list
;
2691 return nreverse (result
);
2694 /* Build a binary-operation expression, after performing default
2695 conversions on the operands. CODE is the kind of expression to build. */
2698 build_x_binary_op (code
, arg1
, arg2
)
2699 enum tree_code code
;
2702 tree rval
= build_opfncall (code
, LOOKUP_SPECULATIVELY
,
2703 arg1
, arg2
, NULL_TREE
);
2705 return build_opfncall (code
, LOOKUP_NORMAL
, arg1
, arg2
, NULL_TREE
);
2706 if (code
== MEMBER_REF
)
2707 return build_m_component_ref (build_indirect_ref (arg1
, NULL_PTR
),
2709 return build_binary_op (code
, arg1
, arg2
, 1);
2713 build_binary_op (code
, arg1
, arg2
, convert_p
)
2714 enum tree_code code
;
2726 args
[0] = default_conversion (args
[0]);
2727 args
[1] = default_conversion (args
[1]);
2729 if (type_unknown_p (args
[0]))
2731 args
[0] = instantiate_type (TREE_TYPE (args
[1]), args
[0], 1);
2732 args
[0] = default_conversion (args
[0]);
2734 else if (type_unknown_p (args
[1]))
2736 args
[1] = require_instantiated_type (TREE_TYPE (args
[0]),
2739 args
[1] = default_conversion (args
[1]);
2742 type1
= TREE_TYPE (args
[0]);
2743 type2
= TREE_TYPE (args
[1]);
2745 if (IS_AGGR_TYPE_2 (type1
, type2
))
2747 /* Try to convert this to something reasonable. */
2748 if (! build_default_binary_type_conversion(code
, &args
[0], &args
[1]))
2749 return error_mark_node
;
2751 else if (IS_AGGR_TYPE (type1
) || IS_AGGR_TYPE (type2
))
2753 int convert_index
= IS_AGGR_TYPE (type2
);
2754 /* Avoid being tripped up by things like (ARG1 != 0). */
2757 types
[0] = type1
; types
[1] = type2
;
2758 if (code
== TRUTH_ANDIF_EXPR
|| code
== TRUTH_ORIF_EXPR
)
2759 try = build_type_conversion (code
, boolean_type_node
,
2760 args
[convert_index
], 1);
2763 try = build_type_conversion (code
, types
[convert_index
^ 1],
2764 args
[convert_index
], 1);
2767 && args
[1] == integer_zero_node
2768 && (code
== NE_EXPR
|| code
== EQ_EXPR
))
2769 try = build_type_conversion (code
, ptr_type_node
,
2770 args
[convert_index
], 1);
2775 cp_error ("no match for `%O(%#T, %#T)'", code
,
2776 TREE_TYPE (arg1
), TREE_TYPE (arg2
));
2777 return error_mark_node
;
2779 if (try == error_mark_node
)
2780 error ("ambiguous pointer conversion");
2781 args
[convert_index
] = try;
2784 return build_binary_op_nodefault (code
, args
[0], args
[1], code
);
2787 /* Build a binary-operation expression without default conversions.
2788 CODE is the kind of expression to build.
2789 This function differs from `build' in several ways:
2790 the data type of the result is computed and recorded in it,
2791 warnings are generated if arg data types are invalid,
2792 special handling for addition and subtraction of pointers is known,
2793 and some optimization is done (operations on narrow ints
2794 are done in the narrower type when that gives the same result).
2795 Constant folding is also done before the result is returned.
2797 ERROR_CODE is the code that determines what to say in error messages.
2798 It is usually, but not always, the same as CODE.
2800 Note that the operands will never have enumeral types
2801 because either they have just had the default conversions performed
2802 or they have both just been converted to some other type in which
2803 the arithmetic is to be done.
2805 C++: must do special pointer arithmetic when implementing
2806 multiple inheritance, and deal with pointer to member functions. */
2809 build_binary_op_nodefault (code
, orig_op0
, orig_op1
, error_code
)
2810 enum tree_code code
;
2811 tree orig_op0
, orig_op1
;
2812 enum tree_code error_code
;
2815 register enum tree_code code0
, code1
;
2818 /* Expression code to give to the expression when it is built.
2819 Normally this is CODE, which is what the caller asked for,
2820 but in some special cases we change it. */
2821 register enum tree_code resultcode
= code
;
2823 /* Data type in which the computation is to be performed.
2824 In the simplest cases this is the common type of the arguments. */
2825 register tree result_type
= NULL
;
2827 /* Nonzero means operands have already been type-converted
2828 in whatever way is necessary.
2829 Zero means they need to be converted to RESULT_TYPE. */
2832 /* Nonzero means after finally constructing the expression
2833 give it this type. Otherwise, give it type RESULT_TYPE. */
2834 tree final_type
= 0;
2836 /* Nonzero if this is an operation like MIN or MAX which can
2837 safely be computed in short if both args are promoted shorts.
2838 Also implies COMMON.
2839 -1 indicates a bitwise operation; this makes a difference
2840 in the exact conditions for when it is safe to do the operation
2841 in a narrower mode. */
2844 /* Nonzero if this is a comparison operation;
2845 if both args are promoted shorts, compare the original shorts.
2846 Also implies COMMON. */
2847 int short_compare
= 0;
2849 /* Nonzero if this is a right-shift operation, which can be computed on the
2850 original short and then promoted if the operand is a promoted short. */
2851 int short_shift
= 0;
2853 /* Nonzero means set RESULT_TYPE to the common type of the args. */
2856 /* Apply default conversions. */
2857 op0
= default_conversion (orig_op0
);
2858 op1
= default_conversion (orig_op1
);
2860 type0
= TREE_TYPE (op0
);
2861 type1
= TREE_TYPE (op1
);
2863 /* The expression codes of the data types of the arguments tell us
2864 whether the arguments are integers, floating, pointers, etc. */
2865 code0
= TREE_CODE (type0
);
2866 code1
= TREE_CODE (type1
);
2868 /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
2869 STRIP_TYPE_NOPS (op0
);
2870 STRIP_TYPE_NOPS (op1
);
2872 /* If an error was already reported for one of the arguments,
2873 avoid reporting another error. */
2875 if (code0
== ERROR_MARK
|| code1
== ERROR_MARK
)
2876 return error_mark_node
;
2881 /* Handle the pointer + int case. */
2882 if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
2883 return pointer_int_sum (PLUS_EXPR
, op0
, op1
);
2884 else if (code1
== POINTER_TYPE
&& code0
== INTEGER_TYPE
)
2885 return pointer_int_sum (PLUS_EXPR
, op1
, op0
);
2891 /* Subtraction of two similar pointers.
2892 We must subtract them as integers, then divide by object size. */
2893 if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
2894 && comp_target_types (type0
, type1
, 1))
2895 return pointer_diff (op0
, op1
);
2896 /* Handle pointer minus int. Just like pointer plus int. */
2897 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
2898 return pointer_int_sum (MINUS_EXPR
, op0
, op1
);
2907 case TRUNC_DIV_EXPR
:
2909 case FLOOR_DIV_EXPR
:
2910 case ROUND_DIV_EXPR
:
2911 case EXACT_DIV_EXPR
:
2912 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
2913 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
2915 if (TREE_CODE (op1
) == INTEGER_CST
&& integer_zerop (op1
))
2916 cp_warning ("division by zero in `%E / 0'", op0
);
2917 else if (TREE_CODE (op1
) == REAL_CST
&& real_zerop (op1
))
2918 cp_warning ("division by zero in `%E / 0.'", op0
);
2920 if (!(code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
))
2921 resultcode
= RDIV_EXPR
;
2923 /* When dividing two signed integers, we have to promote to int.
2924 unless we divide by a conatant != -1. Note that default
2925 conversion will have been performed on the operands at this
2926 point, so we have to dig out the original type to find out if
2928 shorten
= ((TREE_CODE (op0
) == NOP_EXPR
2929 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0
, 0))))
2930 || (TREE_CODE (op1
) == INTEGER_CST
2931 && (TREE_INT_CST_LOW (op1
) != -1
2932 || TREE_INT_CST_HIGH (op1
) != -1)));
2938 case BIT_ANDTC_EXPR
:
2941 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
2943 /* If one operand is a constant, and the other is a short type
2944 that has been converted to an int,
2945 really do the work in the short type and then convert the
2946 result to int. If we are lucky, the constant will be 0 or 1
2947 in the short type, making the entire operation go away. */
2948 if (TREE_CODE (op0
) == INTEGER_CST
2949 && TREE_CODE (op1
) == NOP_EXPR
2950 && TYPE_PRECISION (type1
) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op1
, 0)))
2951 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op1
, 0))))
2953 final_type
= result_type
;
2954 op1
= TREE_OPERAND (op1
, 0);
2955 result_type
= TREE_TYPE (op1
);
2957 if (TREE_CODE (op1
) == INTEGER_CST
2958 && TREE_CODE (op0
) == NOP_EXPR
2959 && TYPE_PRECISION (type0
) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0
, 0)))
2960 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0
, 0))))
2962 final_type
= result_type
;
2963 op0
= TREE_OPERAND (op0
, 0);
2964 result_type
= TREE_TYPE (op0
);
2968 case TRUNC_MOD_EXPR
:
2969 case FLOOR_MOD_EXPR
:
2970 if (code1
== INTEGER_TYPE
&& integer_zerop (op1
))
2971 cp_warning ("division by zero in `%E % 0'", op0
);
2972 else if (code1
== REAL_TYPE
&& real_zerop (op1
))
2973 cp_warning ("division by zero in `%E % 0.'", op0
);
2975 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
2977 /* Although it would be tempting to shorten always here, that loses
2978 on some targets, since the modulo instruction is undefined if the
2979 quotient can't be represented in the computation mode. We shorten
2980 only if unsigned or if dividing by something we know != -1. */
2981 shorten
= ((TREE_CODE (op0
) == NOP_EXPR
2982 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0
, 0))))
2983 || (TREE_CODE (op1
) == INTEGER_CST
2984 && (TREE_INT_CST_LOW (op1
) != -1
2985 || TREE_INT_CST_HIGH (op1
) != -1)));
2990 case TRUTH_ANDIF_EXPR
:
2991 case TRUTH_ORIF_EXPR
:
2992 case TRUTH_AND_EXPR
:
2994 result_type
= boolean_type_node
;
2997 /* Shift operations: result has same type as first operand;
2998 always convert second operand to int.
2999 Also set SHORT_SHIFT if shifting rightward. */
3002 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3004 result_type
= type0
;
3005 if (TREE_CODE (op1
) == INTEGER_CST
)
3007 if (tree_int_cst_lt (op1
, integer_zero_node
))
3008 warning ("right shift count is negative");
3011 if (TREE_INT_CST_LOW (op1
) | TREE_INT_CST_HIGH (op1
))
3013 if (TREE_INT_CST_HIGH (op1
) != 0
3014 || ((unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (op1
)
3015 >= TYPE_PRECISION (type0
)))
3016 warning ("right shift count >= width of type");
3019 /* Convert the shift-count to an integer, regardless of
3020 size of value being shifted. */
3021 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
3022 op1
= convert (integer_type_node
, op1
);
3023 /* Avoid converting op1 to result_type later. */
3029 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3031 result_type
= type0
;
3032 if (TREE_CODE (op1
) == INTEGER_CST
)
3034 if (tree_int_cst_lt (op1
, integer_zero_node
))
3035 warning ("left shift count is negative");
3036 else if (TREE_INT_CST_HIGH (op1
) != 0
3037 || ((unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (op1
)
3038 >= TYPE_PRECISION (type0
)))
3039 warning ("left shift count >= width of type");
3041 /* Convert the shift-count to an integer, regardless of
3042 size of value being shifted. */
3043 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
3044 op1
= convert (integer_type_node
, op1
);
3045 /* Avoid converting op1 to result_type later. */
3052 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3054 result_type
= type0
;
3055 if (TREE_CODE (op1
) == INTEGER_CST
)
3057 if (tree_int_cst_lt (op1
, integer_zero_node
))
3058 warning ("%s rotate count is negative",
3059 (code
== LROTATE_EXPR
) ? "left" : "right");
3060 else if (TREE_INT_CST_HIGH (op1
) != 0
3061 || ((unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (op1
)
3062 >= TYPE_PRECISION (type0
)))
3063 warning ("%s rotate count >= width of type",
3064 (code
== LROTATE_EXPR
) ? "left" : "right");
3066 /* Convert the shift-count to an integer, regardless of
3067 size of value being shifted. */
3068 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
3069 op1
= convert (integer_type_node
, op1
);
3075 result_type
= boolean_type_node
;
3077 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
3078 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
3080 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
3082 register tree tt0
= TYPE_MAIN_VARIANT (TREE_TYPE (type0
));
3083 register tree tt1
= TYPE_MAIN_VARIANT (TREE_TYPE (type1
));
3084 /* Anything compares with void *. void * compares with anything.
3085 Otherwise, the targets must be the same. */
3086 if (tt0
!= tt1
&& TREE_CODE (tt0
) == RECORD_TYPE
3087 && TREE_CODE (tt1
) == RECORD_TYPE
)
3089 tree base
= common_base_type (tt0
, tt1
);
3090 if (base
== NULL_TREE
)
3091 cp_warning ("comparison of distinct object pointer types `%T' and `%T'", type0
, type1
);
3092 else if (base
== error_mark_node
)
3094 cp_error ("comparison of pointer types `%T' and `%T' requires conversion to ambiguous supertype", type0
, type1
);
3095 return error_mark_node
;
3099 if (integer_zerop (op0
))
3100 op0
= null_pointer_node
;
3102 op0
= convert_pointer_to (base
, op0
);
3103 if (integer_zerop (op1
))
3104 op1
= null_pointer_node
;
3106 op1
= convert_pointer_to (base
, op1
);
3109 else if (comp_target_types (type0
, type1
, 1))
3111 else if (tt0
== void_type_node
)
3113 if (pedantic
&& TREE_CODE (tt1
) == FUNCTION_TYPE
3114 && tree_int_cst_lt (TYPE_SIZE (type0
), TYPE_SIZE (type1
)))
3115 pedwarn ("ANSI C++ forbids comparison of `void *' with function pointer");
3117 else if (tt1
== void_type_node
)
3119 if (pedantic
&& TREE_CODE (tt0
) == FUNCTION_TYPE
3120 && tree_int_cst_lt (TYPE_SIZE (type1
), TYPE_SIZE (type0
)))
3121 pedwarn ("ANSI C++ forbids comparison of `void *' with function pointer");
3123 else if ((TYPE_SIZE (tt0
) != 0) != (TYPE_SIZE (tt1
) != 0))
3124 cp_pedwarn ("comparison of %scomplete and %scomplete pointers `%T' and `%T'",
3125 TYPE_SIZE (tt0
) == 0 ? "in" : "",
3126 TYPE_SIZE (tt1
) == 0 ? "in" : "",
3129 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3132 else if (code0
== POINTER_TYPE
&& TREE_CODE (op1
) == INTEGER_CST
3133 && integer_zerop (op1
))
3134 op1
= null_pointer_node
;
3135 else if (code1
== POINTER_TYPE
&& TREE_CODE (op0
) == INTEGER_CST
3136 && integer_zerop (op0
))
3137 op0
= null_pointer_node
;
3138 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
3140 error ("ANSI C++ forbids comparison between pointer and integer");
3141 op1
= convert (TREE_TYPE (op0
), op1
);
3143 else if (code0
== INTEGER_TYPE
&& code1
== POINTER_TYPE
)
3145 error ("ANSI C++ forbids comparison between pointer and integer");
3146 op0
= convert (TREE_TYPE (op1
), op0
);
3148 else if (TYPE_PTRMEMFUNC_P (type0
) && TREE_CODE (op1
) == INTEGER_CST
3149 && integer_zerop (op1
))
3151 op0
= build_component_ref (op0
, index_identifier
, 0, 0);
3152 op1
= integer_zero_node
;
3154 else if (TYPE_PTRMEMFUNC_P (type1
) && TREE_CODE (op0
) == INTEGER_CST
3155 && integer_zerop (op0
))
3157 op0
= build_component_ref (op1
, index_identifier
, 0, 0);
3158 op1
= integer_zero_node
;
3160 else if (TYPE_PTRMEMFUNC_P (type0
) && TYPE_PTRMEMFUNC_P (type1
)
3161 && (TYPE_PTRMEMFUNC_FN_TYPE (type0
)
3162 == TYPE_PTRMEMFUNC_FN_TYPE (type1
)))
3164 /* The code we generate for the test is:
3166 (op0.index == op1.index
3167 && ((op1.index != -1 && op0.delta2 == op1.delta2)
3168 || op0.pfn == op1.pfn)) */
3170 tree index0
= build_component_ref (op0
, index_identifier
, 0, 0);
3171 tree index1
= save_expr (build_component_ref (op1
, index_identifier
, 0, 0));
3172 tree pfn0
= PFN_FROM_PTRMEMFUNC (op0
);
3173 tree pfn1
= PFN_FROM_PTRMEMFUNC (op1
);
3174 tree delta20
= DELTA2_FROM_PTRMEMFUNC (op0
);
3175 tree delta21
= DELTA2_FROM_PTRMEMFUNC (op1
);
3177 tree integer_neg_one_node
3178 = build_binary_op (MINUS_EXPR
, integer_zero_node
, integer_one_node
, 1);
3179 e1
= build_binary_op (EQ_EXPR
, index0
, index1
, 1);
3180 e2
= build_binary_op (NE_EXPR
, index1
, integer_neg_one_node
, 1);
3181 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e2
, build_binary_op (EQ_EXPR
, delta20
, delta21
, 1), 1);
3182 e3
= build_binary_op (EQ_EXPR
, pfn0
, pfn1
, 1);
3183 e2
= build_binary_op (TRUTH_ORIF_EXPR
, e2
, e3
, 1);
3184 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e1
, e2
, 1);
3185 if (code
== EQ_EXPR
)
3187 return build_binary_op (EQ_EXPR
, e2
, integer_zero_node
, 1);
3189 else if (TYPE_PTRMEMFUNC_P (type0
)
3190 && TYPE_PTRMEMFUNC_FN_TYPE (type0
) == type1
)
3192 tree index0
= build_component_ref (op0
, index_identifier
, 0, 0);
3194 tree pfn0
= PFN_FROM_PTRMEMFUNC (op0
);
3195 tree delta20
= DELTA2_FROM_PTRMEMFUNC (op0
);
3196 tree delta21
= integer_zero_node
;
3198 tree integer_neg_one_node
3199 = build_binary_op (MINUS_EXPR
, integer_zero_node
, integer_one_node
, 1);
3200 if (TREE_CODE (TREE_OPERAND (op1
, 0)) == FUNCTION_DECL
3201 && DECL_VINDEX (TREE_OPERAND (op1
, 0)))
3203 /* Map everything down one to make room for the null pointer to member. */
3204 index1
= size_binop (PLUS_EXPR
,
3205 DECL_VINDEX (TREE_OPERAND (op1
, 0)),
3207 op1
= integer_zero_node
;
3208 delta21
= CLASSTYPE_VFIELD (TYPE_METHOD_BASETYPE (TREE_TYPE (type1
)));
3209 delta21
= DECL_FIELD_BITPOS (delta21
);
3210 delta21
= size_binop (FLOOR_DIV_EXPR
, delta21
, size_int (BITS_PER_UNIT
));
3213 index1
= integer_neg_one_node
;
3215 tree nop1
= build1 (NOP_EXPR
, TYPE_PTRMEMFUNC_FN_TYPE (type0
), op1
);
3216 TREE_CONSTANT (nop1
) = TREE_CONSTANT (op1
);
3219 e1
= build_binary_op (EQ_EXPR
, index0
, index1
, 1);
3220 e2
= build_binary_op (NE_EXPR
, index1
, integer_neg_one_node
, 1);
3221 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e2
, build_binary_op (EQ_EXPR
, delta20
, delta21
, 1), 1);
3222 e3
= build_binary_op (EQ_EXPR
, pfn0
, op1
, 1);
3223 e2
= build_binary_op (TRUTH_ORIF_EXPR
, e2
, e3
, 1);
3224 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e1
, e2
, 1);
3225 if (code
== EQ_EXPR
)
3227 return build_binary_op (EQ_EXPR
, e2
, integer_zero_node
, 1);
3229 else if (TYPE_PTRMEMFUNC_P (type1
)
3230 && TYPE_PTRMEMFUNC_FN_TYPE (type1
) == type0
)
3232 return build_binary_op (code
, op1
, op0
, 1);
3235 /* If args are not valid, clear out RESULT_TYPE
3236 to cause an error message later. */
3242 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
3243 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
3245 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
3247 if (! comp_target_types (type0
, type1
, 1))
3248 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3250 else if ((TYPE_SIZE (TREE_TYPE (type0
)) != 0)
3251 != (TYPE_SIZE (TREE_TYPE (type1
)) != 0))
3252 cp_pedwarn ("comparison of %scomplete and %scomplete pointers",
3253 TYPE_SIZE (TREE_TYPE (type0
)) == 0 ? "in" : "",
3254 TYPE_SIZE (TREE_TYPE (type1
)) == 0 ? "in" : "",
3257 && TREE_CODE (TREE_TYPE (type0
)) == FUNCTION_TYPE
)
3258 pedwarn ("ANSI C++ forbids ordered comparisons of pointers to functions");
3259 result_type
= common_type (type0
, type1
);
3267 result_type
= boolean_type_node
;
3268 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
3269 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
3271 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
3273 if (! comp_target_types (type0
, type1
, 1))
3274 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3276 else if ((TYPE_SIZE (TREE_TYPE (type0
)) != 0)
3277 != (TYPE_SIZE (TREE_TYPE (type1
)) != 0))
3278 cp_pedwarn ("comparison of %scomplete and %scomplete pointers",
3279 TYPE_SIZE (TREE_TYPE (type0
)) == 0 ? "in" : "",
3280 TYPE_SIZE (TREE_TYPE (type1
)) == 0 ? "in" : "",
3283 && TREE_CODE (TREE_TYPE (type0
)) == FUNCTION_TYPE
)
3284 pedwarn ("ANSI C++ forbids ordered comparisons of pointers to functions");
3286 else if (code0
== POINTER_TYPE
&& TREE_CODE (op1
) == INTEGER_CST
3287 && integer_zerop (op1
))
3289 op1
= null_pointer_node
;
3291 pedwarn ("ordered comparison of pointer with integer zero");
3293 else if (code1
== POINTER_TYPE
&& TREE_CODE (op0
) == INTEGER_CST
3294 && integer_zerop (op0
))
3296 op0
= null_pointer_node
;
3298 pedwarn ("ANSI C++ forbids ordered comparison of pointer with integer zero");
3300 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
3303 pedwarn ("ANSI C++ forbids comparison between pointer and integer");
3304 else if (! flag_traditional
)
3305 warning ("comparison between pointer and integer");
3306 op1
= convert (TREE_TYPE (op0
), op1
);
3308 else if (code0
== INTEGER_TYPE
&& code1
== POINTER_TYPE
)
3311 pedwarn ("ANSI C++ forbids comparison between pointer and integer");
3312 else if (! flag_traditional
)
3313 warning ("comparison between pointer and integer");
3314 op0
= convert (TREE_TYPE (op1
), op0
);
3322 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
3323 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
3325 if (shorten
|| common
|| short_compare
)
3326 result_type
= common_type (type0
, type1
);
3328 /* For certain operations (which identify themselves by shorten != 0)
3329 if both args were extended from the same smaller type,
3330 do the arithmetic in that type and then extend.
3332 shorten !=0 and !=1 indicates a bitwise operation.
3333 For them, this optimization is safe only if
3334 both args are zero-extended or both are sign-extended.
3335 Otherwise, we might change the result.
3336 Eg, (short)-1 | (unsigned short)-1 is (int)-1
3337 but calculated in (unsigned short) it would be (unsigned short)-1. */
3341 int unsigned0
, unsigned1
;
3342 tree arg0
= get_narrower (op0
, &unsigned0
);
3343 tree arg1
= get_narrower (op1
, &unsigned1
);
3344 /* UNS is 1 if the operation to be done is an unsigned one. */
3345 int uns
= TREE_UNSIGNED (result_type
);
3348 final_type
= result_type
;
3350 /* Handle the case that OP0 does not *contain* a conversion
3351 but it *requires* conversion to FINAL_TYPE. */
3353 if (op0
== arg0
&& TREE_TYPE (op0
) != final_type
)
3354 unsigned0
= TREE_UNSIGNED (TREE_TYPE (op0
));
3355 if (op1
== arg1
&& TREE_TYPE (op1
) != final_type
)
3356 unsigned1
= TREE_UNSIGNED (TREE_TYPE (op1
));
3358 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
3360 /* For bitwise operations, signedness of nominal type
3361 does not matter. Consider only how operands were extended. */
3365 /* Note that in all three cases below we refrain from optimizing
3366 an unsigned operation on sign-extended args.
3367 That would not be valid. */
3369 /* Both args variable: if both extended in same way
3370 from same width, do it in that width.
3371 Do it unsigned if args were zero-extended. */
3372 if ((TYPE_PRECISION (TREE_TYPE (arg0
))
3373 < TYPE_PRECISION (result_type
))
3374 && (TYPE_PRECISION (TREE_TYPE (arg1
))
3375 == TYPE_PRECISION (TREE_TYPE (arg0
)))
3376 && unsigned0
== unsigned1
3377 && (unsigned0
|| !uns
))
3379 = signed_or_unsigned_type (unsigned0
,
3380 common_type (TREE_TYPE (arg0
), TREE_TYPE (arg1
)));
3381 else if (TREE_CODE (arg0
) == INTEGER_CST
3382 && (unsigned1
|| !uns
)
3383 && (TYPE_PRECISION (TREE_TYPE (arg1
))
3384 < TYPE_PRECISION (result_type
))
3385 && (type
= signed_or_unsigned_type (unsigned1
,
3387 int_fits_type_p (arg0
, type
)))
3389 else if (TREE_CODE (arg1
) == INTEGER_CST
3390 && (unsigned0
|| !uns
)
3391 && (TYPE_PRECISION (TREE_TYPE (arg0
))
3392 < TYPE_PRECISION (result_type
))
3393 && (type
= signed_or_unsigned_type (unsigned0
,
3395 int_fits_type_p (arg1
, type
)))
3399 /* Shifts can be shortened if shifting right. */
3404 tree arg0
= get_narrower (op0
, &unsigned_arg
);
3406 final_type
= result_type
;
3408 if (arg0
== op0
&& final_type
== TREE_TYPE (op0
))
3409 unsigned_arg
= TREE_UNSIGNED (TREE_TYPE (op0
));
3411 if (TYPE_PRECISION (TREE_TYPE (arg0
)) < TYPE_PRECISION (result_type
)
3412 /* We can shorten only if the shift count is less than the
3413 number of bits in the smaller type size. */
3414 && TREE_INT_CST_HIGH (op1
) == 0
3415 && TYPE_PRECISION (TREE_TYPE (arg0
)) > TREE_INT_CST_LOW (op1
)
3416 /* If arg is sign-extended and then unsigned-shifted,
3417 we can simulate this with a signed shift in arg's type
3418 only if the extended result is at least twice as wide
3419 as the arg. Otherwise, the shift could use up all the
3420 ones made by sign-extension and bring in zeros.
3421 We can't optimize that case at all, but in most machines
3422 it never happens because available widths are 2**N. */
3423 && (!TREE_UNSIGNED (final_type
)
3425 || ((unsigned) 2 * TYPE_PRECISION (TREE_TYPE (arg0
))
3426 <= TYPE_PRECISION (result_type
))))
3428 /* Do an unsigned shift if the operand was zero-extended. */
3430 = signed_or_unsigned_type (unsigned_arg
,
3432 /* Convert value-to-be-shifted to that type. */
3433 if (TREE_TYPE (op0
) != result_type
)
3434 op0
= convert (result_type
, op0
);
3439 /* Comparison operations are shortened too but differently.
3440 They identify themselves by setting short_compare = 1. */
3444 /* Don't write &op0, etc., because that would prevent op0
3445 from being kept in a register.
3446 Instead, make copies of the our local variables and
3447 pass the copies by reference, then copy them back afterward. */
3448 tree xop0
= op0
, xop1
= op1
, xresult_type
= result_type
;
3449 enum tree_code xresultcode
= resultcode
;
3451 = shorten_compare (&xop0
, &xop1
, &xresult_type
, &xresultcode
);
3453 return convert (boolean_type_node
, val
);
3454 op0
= xop0
, op1
= xop1
, result_type
= boolean_type_node
;
3455 resultcode
= xresultcode
;
3458 if (short_compare
&& extra_warnings
)
3460 int unsignedp0
, unsignedp1
;
3461 tree primop0
= get_narrower (op0
, &unsignedp0
);
3462 tree primop1
= get_narrower (op1
, &unsignedp1
);
3464 /* Warn if signed and unsigned are being compared in a size larger
3465 than their original size, as this will always fail. */
3467 if (unsignedp0
!= unsignedp1
3468 && (TYPE_PRECISION (TREE_TYPE (primop0
))
3469 < TYPE_PRECISION (result_type
))
3470 && (TYPE_PRECISION (TREE_TYPE (primop1
))
3471 < TYPE_PRECISION (result_type
)))
3472 warning ("comparison between promoted unsigned and signed");
3474 /* Warn if two unsigned values are being compared in a size
3475 larger than their original size, and one (and only one) is the
3476 result of a `~' operator. This comparison will always fail.
3478 Also warn if one operand is a constant, and the constant does not
3479 have all bits set that are set in the ~ operand when it is
3482 else if (TREE_CODE (primop0
) == BIT_NOT_EXPR
3483 ^ TREE_CODE (primop1
) == BIT_NOT_EXPR
)
3485 if (TREE_CODE (primop0
) == BIT_NOT_EXPR
)
3486 primop0
= get_narrower (TREE_OPERAND (op0
, 0), &unsignedp0
);
3487 if (TREE_CODE (primop1
) == BIT_NOT_EXPR
)
3488 primop1
= get_narrower (TREE_OPERAND (op1
, 0), &unsignedp1
);
3490 if (TREE_CODE (primop0
) == INTEGER_CST
3491 || TREE_CODE (primop1
) == INTEGER_CST
)
3494 HOST_WIDE_INT constant
, mask
;
3498 if (TREE_CODE (primop0
) == INTEGER_CST
)
3501 unsignedp
= unsignedp1
;
3502 constant
= TREE_INT_CST_LOW (primop0
);
3507 unsignedp
= unsignedp0
;
3508 constant
= TREE_INT_CST_LOW (primop1
);
3511 bits
= TYPE_PRECISION (TREE_TYPE (primop
));
3512 if (bits
< TYPE_PRECISION (result_type
)
3513 && bits
< HOST_BITS_PER_LONG
&& unsignedp
)
3515 mask
= (~ (HOST_WIDE_INT
) 0) << bits
;
3516 if ((mask
& constant
) != mask
)
3517 warning ("comparison of promoted ~unsigned with constant");
3520 else if (unsignedp0
&& unsignedp1
3521 && (TYPE_PRECISION (TREE_TYPE (primop0
))
3522 < TYPE_PRECISION (result_type
))
3523 && (TYPE_PRECISION (TREE_TYPE (primop1
))
3524 < TYPE_PRECISION (result_type
)))
3525 warning ("comparison of promoted ~unsigned with unsigned");
3530 /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
3531 If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
3532 Then the expression will be built.
3533 It will be given type FINAL_TYPE if that is nonzero;
3534 otherwise, it will be given type RESULT_TYPE. */
3538 binary_op_error (error_code
);
3539 return error_mark_node
;
3544 if (TREE_TYPE (op0
) != result_type
)
3545 op0
= convert (result_type
, op0
);
3546 if (TREE_TYPE (op1
) != result_type
)
3547 op1
= convert (result_type
, op1
);
3551 register tree result
= build (resultcode
, result_type
, op0
, op1
);
3552 register tree folded
;
3554 folded
= fold (result
);
3555 if (folded
== result
)
3556 TREE_CONSTANT (folded
) = TREE_CONSTANT (op0
) & TREE_CONSTANT (op1
);
3557 if (final_type
!= 0)
3558 return convert (final_type
, folded
);
3563 /* Return a tree for the sum or difference (RESULTCODE says which)
3564 of pointer PTROP and integer INTOP. */
3567 pointer_int_sum (resultcode
, ptrop
, intop
)
3568 enum tree_code resultcode
;
3569 register tree ptrop
, intop
;
3573 register tree result
;
3574 register tree folded
= fold (intop
);
3576 /* The result is a pointer of the same type that is being added. */
3578 register tree result_type
= TREE_TYPE (ptrop
);
3580 if (TREE_CODE (TREE_TYPE (result_type
)) == VOID_TYPE
)
3582 if (pedantic
|| warn_pointer_arith
)
3583 pedwarn ("ANSI C++ forbids using pointer of type `void *' in arithmetic");
3584 size_exp
= integer_one_node
;
3586 else if (TREE_CODE (TREE_TYPE (result_type
)) == FUNCTION_TYPE
)
3588 if (pedantic
|| warn_pointer_arith
)
3589 pedwarn ("ANSI C++ forbids using pointer to a function in arithmetic");
3590 size_exp
= integer_one_node
;
3592 else if (TREE_CODE (TREE_TYPE (result_type
)) == METHOD_TYPE
)
3594 if (pedantic
|| warn_pointer_arith
)
3595 pedwarn ("ANSI C++ forbids using pointer to a method in arithmetic");
3596 size_exp
= integer_one_node
;
3598 else if (TREE_CODE (TREE_TYPE (result_type
)) == OFFSET_TYPE
)
3601 pedwarn ("ANSI C++ forbids using pointer to a member in arithmetic");
3602 size_exp
= integer_one_node
;
3605 size_exp
= size_in_bytes (TREE_TYPE (result_type
));
3607 /* Needed to make OOPS V2R3 work. */
3609 if (TREE_CODE (intop
) == INTEGER_CST
3610 && TREE_INT_CST_LOW (intop
) == 0
3611 && TREE_INT_CST_HIGH (intop
) == 0)
3614 /* If what we are about to multiply by the size of the elements
3615 contains a constant term, apply distributive law
3616 and multiply that constant term separately.
3617 This helps produce common subexpressions. */
3619 if ((TREE_CODE (intop
) == PLUS_EXPR
|| TREE_CODE (intop
) == MINUS_EXPR
)
3620 && ! TREE_CONSTANT (intop
)
3621 && TREE_CONSTANT (TREE_OPERAND (intop
, 1))
3622 && TREE_CONSTANT (size_exp
))
3624 enum tree_code subcode
= resultcode
;
3625 if (TREE_CODE (intop
) == MINUS_EXPR
)
3626 subcode
= (subcode
== PLUS_EXPR
? MINUS_EXPR
: PLUS_EXPR
);
3627 ptrop
= build_binary_op (subcode
, ptrop
, TREE_OPERAND (intop
, 1), 1);
3628 intop
= TREE_OPERAND (intop
, 0);
3631 /* Convert the integer argument to a type the same size as a pointer
3632 so the multiply won't overflow spuriously. */
3634 if (TYPE_PRECISION (TREE_TYPE (intop
)) != POINTER_SIZE
)
3635 intop
= convert (type_for_size (POINTER_SIZE
, 0), intop
);
3637 /* Replace the integer argument with a suitable product by the object size.
3638 Do this multiplication as signed, then convert to the appropriate
3639 pointer type (actually unsigned integral). */
3641 intop
= convert (result_type
,
3642 build_binary_op (MULT_EXPR
, intop
,
3643 convert (TREE_TYPE (intop
), size_exp
), 1));
3645 /* Create the sum or difference. */
3647 result
= build (resultcode
, result_type
, ptrop
, intop
);
3649 folded
= fold (result
);
3650 if (folded
== result
)
3651 TREE_CONSTANT (folded
) = TREE_CONSTANT (ptrop
) & TREE_CONSTANT (intop
);
3655 /* Return a tree for the difference of pointers OP0 and OP1.
3656 The resulting tree has type int. */
3659 pointer_diff (op0
, op1
)
3660 register tree op0
, op1
;
3662 register tree result
, folded
;
3663 tree restype
= ptrdiff_type_node
;
3664 tree target_type
= TREE_TYPE (TREE_TYPE (op0
));
3668 if (TREE_CODE (target_type
) == VOID_TYPE
)
3669 pedwarn ("ANSI C++ forbids using pointer of type `void *' in subtraction");
3670 if (TREE_CODE (target_type
) == FUNCTION_TYPE
)
3671 pedwarn ("ANSI C++ forbids using pointer to a function in subtraction");
3672 if (TREE_CODE (target_type
) == METHOD_TYPE
)
3673 pedwarn ("ANSI C++ forbids using pointer to a method in subtraction");
3674 if (TREE_CODE (target_type
) == OFFSET_TYPE
)
3675 pedwarn ("ANSI C++ forbids using pointer to a member in subtraction");
3678 /* First do the subtraction as integers;
3679 then drop through to build the divide operator. */
3681 op0
= build_binary_op (MINUS_EXPR
,
3682 convert (restype
, op0
), convert (restype
, op1
), 1);
3684 /* This generates an error if op1 is a pointer to an incomplete type. */
3685 if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (op1
))) == 0)
3686 error ("arithmetic on pointer to an incomplete type");
3688 op1
= ((TREE_CODE (target_type
) == VOID_TYPE
3689 || TREE_CODE (target_type
) == FUNCTION_TYPE
3690 || TREE_CODE (target_type
) == METHOD_TYPE
3691 || TREE_CODE (target_type
) == OFFSET_TYPE
)
3693 : size_in_bytes (target_type
));
3695 /* Do the division. */
3697 result
= build (EXACT_DIV_EXPR
, restype
, op0
, convert (restype
, op1
));
3699 folded
= fold (result
);
3700 if (folded
== result
)
3701 TREE_CONSTANT (folded
) = TREE_CONSTANT (op0
) & TREE_CONSTANT (op1
);
3705 /* Handle the case of taking the address of a COMPONENT_REF.
3706 Called by `build_unary_op' and `build_up_reference'.
3708 ARG is the COMPONENT_REF whose address we want.
3709 ARGTYPE is the pointer type that this address should have.
3710 MSG is an error message to print if this COMPONENT_REF is not
3711 addressable (such as a bitfield). */
3714 build_component_addr (arg
, argtype
, msg
)
3718 tree field
= TREE_OPERAND (arg
, 1);
3719 tree basetype
= decl_type_context (field
);
3720 tree rval
= build_unary_op (ADDR_EXPR
, TREE_OPERAND (arg
, 0), 0);
3722 if (DECL_BIT_FIELD (field
))
3724 error (msg
, IDENTIFIER_POINTER (DECL_NAME (field
)));
3725 return error_mark_node
;
3729 cp_warning ("address of `%T::%D' taken", basetype
, field
);
3731 if (TREE_CODE (field
) == FIELD_DECL
3732 && TYPE_USES_COMPLEX_INHERITANCE (basetype
))
3734 /* Can't convert directly to ARGTYPE, since that
3735 may have the same pointer type as one of our
3737 rval
= build1 (NOP_EXPR
, argtype
,
3738 convert_pointer_to (basetype
, rval
));
3739 TREE_CONSTANT (rval
) = TREE_CONSTANT (TREE_OPERAND (rval
, 0));
3742 /* This conversion is harmless. */
3743 rval
= convert_force (argtype
, rval
, 0);
3745 if (! integer_zerop (DECL_FIELD_BITPOS (field
)))
3747 tree offset
= size_binop (EASY_DIV_EXPR
, DECL_FIELD_BITPOS (field
),
3748 size_int (BITS_PER_UNIT
));
3749 int flag
= TREE_CONSTANT (rval
);
3750 rval
= fold (build (PLUS_EXPR
, argtype
,
3751 rval
, convert (argtype
, offset
)));
3752 TREE_CONSTANT (rval
) = flag
;
3757 /* Construct and perhaps optimize a tree representation
3758 for a unary operation. CODE, a tree_code, specifies the operation
3759 and XARG is the operand. */
3762 build_x_unary_op (code
, xarg
)
3763 enum tree_code code
;
3766 /* & rec, on incomplete RECORD_TYPEs is the simple opr &, not an
3768 if (code
== ADDR_EXPR
3769 && ((IS_AGGR_TYPE_CODE (TREE_CODE (TREE_TYPE (xarg
)))
3770 && TYPE_SIZE (TREE_TYPE (xarg
)) == NULL_TREE
)
3771 || (TREE_CODE (xarg
) == OFFSET_REF
)))
3772 /* don't look for a function */;
3775 tree rval
= build_opfncall (code
, LOOKUP_SPECULATIVELY
, xarg
,
3776 NULL_TREE
, NULL_TREE
);
3778 return build_opfncall (code
, LOOKUP_NORMAL
, xarg
,
3779 NULL_TREE
, NULL_TREE
);
3781 return build_unary_op (code
, xarg
, 0);
3784 /* Just like truthvalue_conversion, but we want a CLEANUP_POINT_EXPR. */
3787 condition_conversion (expr
)
3790 tree t
= convert (boolean_type_node
, expr
);
3791 t
= fold (build1 (CLEANUP_POINT_EXPR
, boolean_type_node
, t
));
3795 /* C++: Must handle pointers to members.
3797 Perhaps type instantiation should be extended to handle conversion
3798 from aggregates to types we don't yet know we want? (Or are those
3799 cases typically errors which should be reported?)
3801 NOCONVERT nonzero suppresses the default promotions
3802 (such as from short to int). */
3804 build_unary_op (code
, xarg
, noconvert
)
3805 enum tree_code code
;
3809 /* No default_conversion here. It causes trouble for ADDR_EXPR. */
3810 register tree arg
= xarg
;
3811 register tree argtype
= 0;
3812 register enum tree_code typecode
= TREE_CODE (TREE_TYPE (arg
));
3813 char *errstring
= NULL
;
3817 if (typecode
== ERROR_MARK
)
3818 return error_mark_node
;
3820 if (typecode
== REFERENCE_TYPE
&& code
!= ADDR_EXPR
&& ! noconvert
)
3822 arg
= convert_from_reference (arg
);
3823 typecode
= TREE_CODE (TREE_TYPE (arg
));
3826 if (typecode
== ENUMERAL_TYPE
)
3827 typecode
= INTEGER_TYPE
;
3829 if (typecode
== BOOLEAN_TYPE
&& ! noconvert
)
3830 typecode
= INTEGER_TYPE
;
3832 isaggrtype
= IS_AGGR_TYPE_CODE (typecode
);
3837 /* This is used for unary plus, because a CONVERT_EXPR
3838 is enough to prevent anybody from looking inside for
3839 associativity, but won't generate any code. */
3840 if (!(typecode
== INTEGER_TYPE
|| typecode
== REAL_TYPE
))
3841 errstring
= "wrong type argument to unary plus";
3842 else if (!noconvert
)
3843 arg
= default_conversion (arg
);
3844 arg
= build1 (NON_LVALUE_EXPR
, TREE_TYPE (arg
), arg
);
3848 if (typecode
== OFFSET_TYPE
)
3850 arg
= resolve_offset_ref (arg
);
3851 typecode
= TREE_CODE (TREE_TYPE (arg
));
3852 isaggrtype
= IS_AGGR_TYPE_CODE (typecode
);
3858 arg
= default_conversion (arg
);
3861 cp_error ("type conversion for type `%T' not allowed",
3863 return error_mark_node
;
3865 typecode
= TREE_CODE (TREE_TYPE (arg
));
3869 if (!(typecode
== INTEGER_TYPE
|| typecode
== REAL_TYPE
))
3870 errstring
= "wrong type argument to unary minus";
3871 else if (!noconvert
)
3872 arg
= default_conversion (arg
);
3876 if (typecode
== OFFSET_TYPE
)
3878 arg
= resolve_offset_ref (arg
);
3879 typecode
= TREE_CODE (TREE_TYPE (arg
));
3880 isaggrtype
= IS_AGGR_TYPE_CODE (typecode
);
3886 arg
= default_conversion (arg
);
3889 cp_error ("type conversion for type `%T' not allowed",
3891 return error_mark_node
;
3893 typecode
= TREE_CODE (TREE_TYPE (arg
));
3897 if (typecode
!= INTEGER_TYPE
)
3898 errstring
= "wrong type argument to bit-complement";
3899 else if (!noconvert
)
3900 arg
= default_conversion (arg
);
3904 if (typecode
== OFFSET_TYPE
)
3906 arg
= resolve_offset_ref (arg
);
3907 typecode
= TREE_CODE (TREE_TYPE (arg
));
3908 isaggrtype
= IS_AGGR_TYPE_CODE (typecode
);
3914 arg
= default_conversion (arg
);
3917 cp_error ("type conversion for type `%T' not allowed",
3919 return error_mark_node
;
3921 typecode
= TREE_CODE (TREE_TYPE (arg
));
3925 if (!(typecode
== INTEGER_TYPE
|| typecode
== REAL_TYPE
))
3926 errstring
= "wrong type argument to abs";
3927 else if (!noconvert
)
3928 arg
= default_conversion (arg
);
3931 case TRUTH_NOT_EXPR
:
3932 arg
= convert (boolean_type_node
, arg
);
3933 val
= invert_truthvalue (arg
);
3934 if (arg
!= error_mark_node
)
3936 errstring
= "in argument to unary !";
3942 case PREINCREMENT_EXPR
:
3943 case POSTINCREMENT_EXPR
:
3944 case PREDECREMENT_EXPR
:
3945 case POSTDECREMENT_EXPR
:
3946 /* Handle complex lvalues (when permitted)
3947 by reduction to simpler cases. */
3949 val
= unary_complex_lvalue (code
, arg
);
3953 /* Report invalid types. */
3955 if (typecode
== OFFSET_TYPE
)
3957 arg
= resolve_offset_ref (arg
);
3958 typecode
= TREE_CODE (TREE_TYPE (arg
));
3959 isaggrtype
= IS_AGGR_TYPE_CODE (typecode
);
3964 arg
= default_conversion (arg
);
3965 typecode
= TREE_CODE (TREE_TYPE (arg
));
3968 if (typecode
!= POINTER_TYPE
3969 && typecode
!= INTEGER_TYPE
&& typecode
!= REAL_TYPE
)
3971 if (code
== PREINCREMENT_EXPR
)
3972 errstring
="no pre-increment operator for type";
3973 else if (code
== POSTINCREMENT_EXPR
)
3974 errstring
="no post-increment operator for type";
3975 else if (code
== PREDECREMENT_EXPR
)
3976 errstring
="no pre-decrement operator for type";
3978 errstring
="no post-decrement operator for type";
3982 /* Report something read-only. */
3984 if (TYPE_READONLY (TREE_TYPE (arg
))
3985 || TREE_READONLY (arg
))
3986 readonly_error (arg
, ((code
== PREINCREMENT_EXPR
3987 || code
== POSTINCREMENT_EXPR
)
3988 ? "increment" : "decrement"),
3993 tree result_type
= TREE_TYPE (arg
);
3995 arg
= get_unwidened (arg
, 0);
3996 argtype
= TREE_TYPE (arg
);
3998 /* ARM $5.2.5 last annotation says this should be forbidden. */
3999 if (TREE_CODE (argtype
) == ENUMERAL_TYPE
)
4000 pedwarn ("ANSI C++ forbids %sing an enum",
4001 (code
== PREINCREMENT_EXPR
|| code
== POSTINCREMENT_EXPR
)
4002 ? "increment" : "decrement");
4004 /* Compute the increment. */
4006 if (typecode
== POINTER_TYPE
)
4008 enum tree_code tmp
= TREE_CODE (TREE_TYPE (argtype
));
4009 if (TYPE_SIZE (TREE_TYPE (argtype
)) == 0)
4010 cp_error ("cannot %s a pointer to incomplete type `%T'",
4011 ((code
== PREINCREMENT_EXPR
4012 || code
== POSTINCREMENT_EXPR
)
4013 ? "increment" : "decrement"), TREE_TYPE (argtype
));
4014 else if (tmp
== FUNCTION_TYPE
|| tmp
== METHOD_TYPE
4015 || tmp
== VOID_TYPE
|| tmp
== OFFSET_TYPE
)
4016 cp_pedwarn ("ANSI C++ forbids %sing a pointer of type `%T'",
4017 ((code
== PREINCREMENT_EXPR
4018 || code
== POSTINCREMENT_EXPR
)
4019 ? "increment" : "decrement"), argtype
);
4020 inc
= c_sizeof_nowarn (TREE_TYPE (argtype
));
4023 inc
= integer_one_node
;
4025 inc
= convert (argtype
, inc
);
4027 /* Handle incrementing a cast-expression. */
4029 switch (TREE_CODE (arg
))
4034 case FIX_TRUNC_EXPR
:
4035 case FIX_FLOOR_EXPR
:
4036 case FIX_ROUND_EXPR
:
4039 tree incremented
, modify
, value
;
4040 if (! lvalue_p (arg
) && pedantic
)
4041 pedwarn ("cast to non-reference type used as lvalue");
4042 arg
= stabilize_reference (arg
);
4043 if (code
== PREINCREMENT_EXPR
|| code
== PREDECREMENT_EXPR
)
4046 value
= save_expr (arg
);
4047 incremented
= build (((code
== PREINCREMENT_EXPR
4048 || code
== POSTINCREMENT_EXPR
)
4049 ? PLUS_EXPR
: MINUS_EXPR
),
4050 argtype
, value
, inc
);
4051 TREE_SIDE_EFFECTS (incremented
) = 1;
4052 modify
= build_modify_expr (arg
, NOP_EXPR
, incremented
);
4053 return build (COMPOUND_EXPR
, TREE_TYPE (arg
), modify
, value
);
4057 /* Complain about anything else that is not a true lvalue. */
4058 if (!lvalue_or_else (arg
, ((code
== PREINCREMENT_EXPR
4059 || code
== POSTINCREMENT_EXPR
)
4060 ? "increment" : "decrement")))
4061 return error_mark_node
;
4063 val
= build (code
, TREE_TYPE (arg
), arg
, inc
);
4064 TREE_SIDE_EFFECTS (val
) = 1;
4065 return convert (result_type
, val
);
4069 /* Note that this operation never does default_conversion
4070 regardless of NOCONVERT. */
4072 if (typecode
== REFERENCE_TYPE
)
4074 arg
= build1 (CONVERT_EXPR
, build_pointer_type (TREE_TYPE (TREE_TYPE (arg
))), arg
);
4075 TREE_REFERENCE_EXPR (arg
) = 1;
4079 && TREE_CODE (arg
) == FUNCTION_DECL
4081 && DECL_CONTEXT (arg
) == NULL_TREE
4082 && IDENTIFIER_LENGTH (DECL_NAME (arg
)) == 4
4083 && IDENTIFIER_POINTER (DECL_NAME (arg
))[0] == 'm'
4084 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (arg
)), "main"))
4086 pedwarn ("taking address of function `main'");
4088 /* Let &* cancel out to simplify resulting code. */
4089 if (TREE_CODE (arg
) == INDIRECT_REF
)
4091 /* We don't need to have `current_class_decl' wrapped in a
4092 NON_LVALUE_EXPR node. */
4094 return current_class_decl
;
4096 /* Keep `default_conversion' from converting if
4097 ARG is of REFERENCE_TYPE. */
4098 arg
= TREE_OPERAND (arg
, 0);
4099 if (TREE_CODE (TREE_TYPE (arg
)) == REFERENCE_TYPE
)
4101 if (TREE_CODE (arg
) == VAR_DECL
&& DECL_INITIAL (arg
)
4102 && !TREE_SIDE_EFFECTS (DECL_INITIAL (arg
)))
4103 arg
= DECL_INITIAL (arg
);
4104 arg
= build1 (CONVERT_EXPR
, build_pointer_type (TREE_TYPE (TREE_TYPE (arg
))), arg
);
4105 TREE_REFERENCE_EXPR (arg
) = 1;
4106 TREE_CONSTANT (arg
) = TREE_CONSTANT (TREE_OPERAND (arg
, 0));
4108 else if (lvalue_p (arg
))
4109 /* Don't let this be an lvalue. */
4110 return non_lvalue (arg
);
4114 /* For &x[y], return x+y */
4115 if (TREE_CODE (arg
) == ARRAY_REF
)
4117 if (mark_addressable (TREE_OPERAND (arg
, 0)) == 0)
4118 return error_mark_node
;
4119 return build_binary_op (PLUS_EXPR
, TREE_OPERAND (arg
, 0),
4120 TREE_OPERAND (arg
, 1), 1);
4123 /* For &(++foo), we are really taking the address of the variable
4124 being acted upon by the increment/decrement operator. ARM $5.3.1
4125 However, according to ARM $5.2.5, we don't allow postfix ++ and
4126 --, since the prefix operators return lvalues, but the postfix
4127 operators do not. */
4128 if (TREE_CODE (arg
) == PREINCREMENT_EXPR
4129 || TREE_CODE (arg
) == PREDECREMENT_EXPR
)
4130 arg
= TREE_OPERAND (arg
, 0);
4132 /* Uninstantiated types are all functions. Taking the
4133 address of a function is a no-op, so just return the
4136 if (TREE_CODE (arg
) == IDENTIFIER_NODE
4137 && IDENTIFIER_OPNAME_P (arg
))
4139 my_friendly_abort (117);
4140 /* We don't know the type yet, so just work around the problem.
4141 We know that this will resolve to an lvalue. */
4142 return build1 (ADDR_EXPR
, unknown_type_node
, arg
);
4145 if (TREE_CODE (arg
) == TREE_LIST
)
4147 if (TREE_CODE (TREE_VALUE (arg
)) == FUNCTION_DECL
4148 && DECL_CHAIN (TREE_VALUE (arg
)) == NULL_TREE
)
4149 /* Unique overloaded non-member function. */
4150 return build_unary_op (ADDR_EXPR
, TREE_VALUE (arg
), 0);
4151 if (TREE_CHAIN (arg
) == NULL_TREE
4152 && TREE_CODE (TREE_VALUE (arg
)) == TREE_LIST
4153 && DECL_CHAIN (TREE_VALUE (TREE_VALUE (arg
))) == NULL_TREE
)
4154 /* Unique overloaded member function. */
4155 return build_unary_op (ADDR_EXPR
, TREE_VALUE (TREE_VALUE (arg
)),
4157 return build1 (ADDR_EXPR
, unknown_type_node
, arg
);
4160 /* Handle complex lvalues (when permitted)
4161 by reduction to simpler cases. */
4162 val
= unary_complex_lvalue (code
, arg
);
4166 switch (TREE_CODE (arg
))
4171 case FIX_TRUNC_EXPR
:
4172 case FIX_FLOOR_EXPR
:
4173 case FIX_ROUND_EXPR
:
4175 if (! lvalue_p (arg
) && pedantic
)
4176 pedwarn ("taking the address of a cast to non-reference type");
4179 /* Allow the address of a constructor if all the elements
4181 if (TREE_CODE (arg
) == CONSTRUCTOR
&& TREE_CONSTANT (arg
))
4183 /* Anything not already handled and not a true memory reference
4185 else if (typecode
!= FUNCTION_TYPE
4186 && typecode
!= METHOD_TYPE
4187 && !lvalue_or_else (arg
, "unary `&'"))
4188 return error_mark_node
;
4190 /* Ordinary case; arg is a COMPONENT_REF or a decl. */
4191 argtype
= TREE_TYPE (arg
);
4192 /* If the lvalue is const or volatile,
4193 merge that into the type that the address will point to. */
4194 if (TREE_CODE_CLASS (TREE_CODE (arg
)) == 'd'
4195 || TREE_CODE_CLASS (TREE_CODE (arg
)) == 'r')
4197 if (TREE_READONLY (arg
) || TREE_THIS_VOLATILE (arg
))
4198 argtype
= cp_build_type_variant (argtype
,
4199 TREE_READONLY (arg
),
4200 TREE_THIS_VOLATILE (arg
));
4203 argtype
= build_pointer_type (argtype
);
4205 if (mark_addressable (arg
) == 0)
4206 return error_mark_node
;
4211 if (TREE_CODE (arg
) == COMPONENT_REF
)
4212 addr
= build_component_addr (arg
, argtype
,
4213 "attempt to take address of bit-field structure member `%s'");
4215 addr
= build1 (code
, argtype
, arg
);
4217 /* Address of a static or external variable or
4218 function counts as a constant */
4220 TREE_CONSTANT (addr
) = 1;
4228 argtype
= TREE_TYPE (arg
);
4229 return fold (build1 (code
, argtype
, arg
));
4233 return error_mark_node
;
4236 /* If CONVERSIONS is a conversion expression or a nested sequence of such,
4237 convert ARG with the same conversions in the same order
4238 and return the result. */
4241 convert_sequence (conversions
, arg
)
4245 switch (TREE_CODE (conversions
))
4250 case FIX_TRUNC_EXPR
:
4251 case FIX_FLOOR_EXPR
:
4252 case FIX_ROUND_EXPR
:
4254 return convert (TREE_TYPE (conversions
),
4255 convert_sequence (TREE_OPERAND (conversions
, 0),
4263 /* Apply unary lvalue-demanding operator CODE to the expression ARG
4264 for certain kinds of expressions which are not really lvalues
4265 but which we can accept as lvalues.
4267 If ARG is not a kind of expression we can handle, return zero. */
4270 unary_complex_lvalue (code
, arg
)
4271 enum tree_code code
;
4274 /* Handle (a, b) used as an "lvalue". */
4275 if (TREE_CODE (arg
) == COMPOUND_EXPR
)
4277 tree real_result
= build_unary_op (code
, TREE_OPERAND (arg
, 1), 0);
4278 return build (COMPOUND_EXPR
, TREE_TYPE (real_result
),
4279 TREE_OPERAND (arg
, 0), real_result
);
4282 /* Handle (a ? b : c) used as an "lvalue". */
4283 if (TREE_CODE (arg
) == COND_EXPR
)
4284 return rationalize_conditional_expr (code
, arg
);
4286 if (TREE_CODE (arg
) == MODIFY_EXPR
4287 || TREE_CODE (arg
) == PREINCREMENT_EXPR
4288 || TREE_CODE (arg
) == PREDECREMENT_EXPR
)
4289 return unary_complex_lvalue
4290 (code
, build (COMPOUND_EXPR
, TREE_TYPE (TREE_OPERAND (arg
, 0)),
4291 arg
, TREE_OPERAND (arg
, 0)));
4293 if (code
!= ADDR_EXPR
)
4296 /* Handle (a = b) used as an "lvalue" for `&'. */
4297 if (TREE_CODE (arg
) == MODIFY_EXPR
4298 || TREE_CODE (arg
) == INIT_EXPR
)
4300 tree real_result
= build_unary_op (code
, TREE_OPERAND (arg
, 0), 0);
4301 return build (COMPOUND_EXPR
, TREE_TYPE (real_result
), arg
, real_result
);
4304 if (TREE_CODE (arg
) == WITH_CLEANUP_EXPR
)
4306 tree real_result
= build_unary_op (code
, TREE_OPERAND (arg
, 0), 0);
4307 real_result
= build (WITH_CLEANUP_EXPR
, TREE_TYPE (real_result
),
4308 real_result
, 0, TREE_OPERAND (arg
, 2));
4312 if (TREE_CODE (TREE_TYPE (arg
)) == FUNCTION_TYPE
4313 || TREE_CODE (TREE_TYPE (arg
)) == METHOD_TYPE
4314 || TREE_CODE (TREE_TYPE (arg
)) == OFFSET_TYPE
)
4316 /* The representation of something of type OFFSET_TYPE
4317 is really the representation of a pointer to it.
4318 Here give the representation its true type. */
4322 my_friendly_assert (TREE_CODE (arg
) != SCOPE_REF
, 313);
4324 if (TREE_CODE (arg
) != OFFSET_REF
)
4327 t
= TREE_OPERAND (arg
, 1);
4329 if (TREE_CODE (t
) == FUNCTION_DECL
) /* Check all this code for right semantics. */
4330 return build_unary_op (ADDR_EXPR
, t
, 0);
4331 if (TREE_CODE (t
) == VAR_DECL
)
4332 return build_unary_op (ADDR_EXPR
, t
, 0);
4335 if (TREE_OPERAND (arg
, 0)
4336 && (TREE_CODE (TREE_OPERAND (arg
, 0)) != NOP_EXPR
4337 || TREE_OPERAND (TREE_OPERAND (arg
, 0), 0) != error_mark_node
))
4338 if (TREE_CODE (t
) != FIELD_DECL
)
4340 /* Don't know if this should return address to just
4341 _DECL, or actual address resolved in this expression. */
4342 sorry ("address of bound pointer-to-member expression");
4343 return error_mark_node
;
4346 offset
= get_delta_difference (DECL_FIELD_CONTEXT (t
),
4347 TREE_TYPE (TREE_OPERAND (arg
, 0)),
4349 offset
= size_binop (PLUS_EXPR
, offset
,
4350 size_binop (EASY_DIV_EXPR
,
4351 DECL_FIELD_BITPOS (t
),
4352 size_int (BITS_PER_UNIT
)));
4353 return convert (build_pointer_type (TREE_TYPE (arg
)), offset
);
4357 if (TREE_CODE (arg
) == OFFSET_REF
)
4359 tree left
= TREE_OPERAND (arg
, 0), left_addr
;
4360 tree right_addr
= build_unary_op (ADDR_EXPR
, TREE_OPERAND (arg
, 1), 0);
4363 if (current_class_decl
)
4364 left_addr
= current_class_decl
;
4367 error ("no `this' for pointer to member");
4368 return error_mark_node
;
4371 left_addr
= build_unary_op (ADDR_EXPR
, left
, 0);
4373 return build (PLUS_EXPR
, build_pointer_type (TREE_TYPE (arg
)),
4374 build1 (NOP_EXPR
, integer_type_node
, left_addr
),
4375 build1 (NOP_EXPR
, integer_type_node
, right_addr
));
4378 /* We permit compiler to make function calls returning
4379 objects of aggregate type look like lvalues. */
4383 if (TREE_CODE (targ
) == SAVE_EXPR
)
4384 targ
= TREE_OPERAND (targ
, 0);
4386 if (TREE_CODE (targ
) == CALL_EXPR
&& IS_AGGR_TYPE (TREE_TYPE (targ
)))
4388 if (TREE_CODE (arg
) == SAVE_EXPR
)
4391 targ
= build_cplus_new (TREE_TYPE (arg
), arg
, 1);
4392 return build1 (ADDR_EXPR
, TYPE_POINTER_TO (TREE_TYPE (arg
)), targ
);
4395 if (TREE_CODE (arg
) == SAVE_EXPR
&& TREE_CODE (targ
) == INDIRECT_REF
)
4396 return build (SAVE_EXPR
, TYPE_POINTER_TO (TREE_TYPE (arg
)),
4397 TREE_OPERAND (targ
, 0), current_function_decl
, NULL
);
4399 /* We shouldn't wrap WITH_CLEANUP_EXPRs inside of SAVE_EXPRs, but in case
4400 we do, here's how to handle it. */
4401 if (TREE_CODE (arg
) == SAVE_EXPR
&& TREE_CODE (targ
) == WITH_CLEANUP_EXPR
)
4404 /* Not really a bug, but something to turn on when testing. */
4405 compiler_error ("WITH_CLEANUP_EXPR wrapped in SAVE_EXPR");
4407 return unary_complex_lvalue (ADDR_EXPR
, targ
);
4411 /* Don't let anything else be handled specially. */
4415 /* Mark EXP saying that we need to be able to take the
4416 address of it; it should not be allocated in a register.
4417 Value is 1 if successful.
4419 C++: we do not allow `current_class_decl' to be addressable. */
4422 mark_addressable (exp
)
4425 register tree x
= exp
;
4427 if (TREE_ADDRESSABLE (x
) == 1)
4431 switch (TREE_CODE (x
))
4436 x
= TREE_OPERAND (x
, 0);
4440 if (x
== current_class_decl
)
4442 error ("address of `this' not available");
4443 TREE_ADDRESSABLE (x
) = 1; /* so compiler doesn't die later */
4444 put_var_into_stack (x
);
4449 && TREE_READONLY (x
)
4450 && DECL_RTL (x
) != 0
4451 && ! decl_in_memory_p (x
))
4453 /* We thought this would make a good constant variable,
4454 but we were wrong. */
4455 push_obstacks_nochange ();
4456 end_temporary_allocation ();
4458 TREE_ASM_WRITTEN (x
) = 0;
4460 rest_of_decl_compilation (x
, 0, IDENTIFIER_LOCAL_VALUE (x
) == 0, 0);
4461 TREE_ADDRESSABLE (x
) = 1;
4467 /* Caller should not be trying to mark initialized
4468 constant fields addressable. */
4469 my_friendly_assert (DECL_LANG_SPECIFIC (x
) == 0
4470 || DECL_IN_AGGR_P (x
) == 0
4472 || DECL_EXTERNAL (x
), 314);
4476 /* For C++, we don't warn about taking the address of a register
4477 variable for CONST_DECLs; ARM p97 explicitly says it's okay. */
4478 put_var_into_stack (x
);
4479 TREE_ADDRESSABLE (x
) = 1;
4483 /* We have to test both conditions here. The first may
4484 be non-zero in the case of processing a default function.
4485 The second may be non-zero in the case of a template function. */
4486 x
= DECL_MAIN_VARIANT (x
);
4487 if ((DECL_INLINE (x
) || DECL_PENDING_INLINE_INFO (x
))
4488 && (DECL_CONTEXT (x
) == NULL_TREE
4489 || TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (x
))) != 't'
4490 || ! CLASSTYPE_INTERFACE_ONLY (DECL_CONTEXT (x
))))
4492 mark_inline_for_output (x
);
4493 if (x
== current_function_decl
)
4494 DECL_EXTERNAL (x
) = 0;
4496 TREE_ADDRESSABLE (x
) = 1;
4498 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (x
)) = 1;
4506 /* Build and return a conditional expression IFEXP ? OP1 : OP2. */
4509 build_x_conditional_expr (ifexp
, op1
, op2
)
4510 tree ifexp
, op1
, op2
;
4512 tree rval
= NULL_TREE
;
4514 /* See comments in `build_x_binary_op'. */
4516 rval
= build_opfncall (COND_EXPR
, LOOKUP_SPECULATIVELY
, ifexp
, op1
, op2
);
4518 return build_opfncall (COND_EXPR
, LOOKUP_NORMAL
, ifexp
, op1
, op2
);
4520 return build_conditional_expr (ifexp
, op1
, op2
);
4524 build_conditional_expr (ifexp
, op1
, op2
)
4525 tree ifexp
, op1
, op2
;
4527 register tree type1
;
4528 register tree type2
;
4529 register enum tree_code code1
;
4530 register enum tree_code code2
;
4531 register tree result_type
= NULL_TREE
;
4532 tree orig_op1
= op1
, orig_op2
= op2
;
4534 /* If second operand is omitted, it is the same as the first one;
4535 make sure it is calculated only once. */
4539 pedwarn ("ANSI C++ forbids omitting the middle term of a ?: expression");
4540 ifexp
= op1
= save_expr (ifexp
);
4543 ifexp
= truthvalue_conversion (ifexp
);
4545 if (TREE_CODE (ifexp
) == ERROR_MARK
)
4546 return error_mark_node
;
4548 op1
= require_instantiated_type (TREE_TYPE (op2
), op1
, error_mark_node
);
4549 if (op1
== error_mark_node
)
4550 return error_mark_node
;
4551 op2
= require_instantiated_type (TREE_TYPE (op1
), op2
, error_mark_node
);
4552 if (op2
== error_mark_node
)
4553 return error_mark_node
;
4555 /* C++: REFERENCE_TYPES must be dereferenced. */
4556 type1
= TREE_TYPE (op1
);
4557 code1
= TREE_CODE (type1
);
4558 type2
= TREE_TYPE (op2
);
4559 code2
= TREE_CODE (type2
);
4561 if (code1
== REFERENCE_TYPE
)
4563 op1
= convert_from_reference (op1
);
4564 type1
= TREE_TYPE (op1
);
4565 code1
= TREE_CODE (type1
);
4567 if (code2
== REFERENCE_TYPE
)
4569 op2
= convert_from_reference (op2
);
4570 type2
= TREE_TYPE (op2
);
4571 code2
= TREE_CODE (type2
);
4574 #if 1 /* Produces wrong result if within sizeof. Sorry. */
4575 /* Don't promote the operands separately if they promote
4576 the same way. Return the unpromoted type and let the combined
4577 value get promoted if necessary. */
4579 if (TYPE_MAIN_VARIANT (type1
) == TYPE_MAIN_VARIANT (type2
)
4580 && code2
!= ARRAY_TYPE
4582 /* For C++, let the enumeral type come through. */
4583 && code2
!= ENUMERAL_TYPE
4585 && code2
!= FUNCTION_TYPE
4586 && code2
!= METHOD_TYPE
)
4590 if (TREE_CONSTANT (ifexp
)
4591 && (TREE_CODE (ifexp
) == INTEGER_CST
4592 || TREE_CODE (ifexp
) == ADDR_EXPR
))
4593 return (integer_zerop (ifexp
) ? op2
: op1
);
4595 if (TREE_CODE (op1
) == CONST_DECL
)
4596 op1
= DECL_INITIAL (op1
);
4597 else if (TREE_READONLY_DECL_P (op1
))
4598 op1
= decl_constant_value (op1
);
4599 if (TREE_CODE (op2
) == CONST_DECL
)
4600 op2
= DECL_INITIAL (op2
);
4601 else if (TREE_READONLY_DECL_P (op2
))
4602 op2
= decl_constant_value (op2
);
4604 type1
= cp_build_type_variant
4606 TREE_READONLY (op1
) || TREE_READONLY (op2
),
4607 TREE_THIS_VOLATILE (op1
) || TREE_THIS_VOLATILE (op2
));
4608 /* ??? This is a kludge to deal with the fact that
4609 we don't sort out integers and enums properly, yet. */
4610 result
= fold (build (COND_EXPR
, type1
, ifexp
, op1
, op2
));
4611 if (TREE_TYPE (result
) != type1
)
4612 result
= build1 (NOP_EXPR
, type1
, result
);
4617 /* They don't match; promote them both and then try to reconcile them.
4618 But don't permit mismatching enum types. */
4619 if (code1
== ENUMERAL_TYPE
)
4621 if (code2
== ENUMERAL_TYPE
)
4623 message_2_types (error
, "enumeral mismatch in conditional expression: `%s' vs `%s'", type1
, type2
);
4624 return error_mark_node
;
4626 else if (extra_warnings
&& ! IS_AGGR_TYPE_CODE (code2
))
4627 warning ("enumeral and non-enumeral type in conditional expression");
4629 else if (extra_warnings
4630 && code2
== ENUMERAL_TYPE
&& ! IS_AGGR_TYPE_CODE (code1
))
4631 warning ("enumeral and non-enumeral type in conditional expression");
4633 if (code1
!= VOID_TYPE
)
4635 op1
= default_conversion (op1
);
4636 type1
= TREE_TYPE (op1
);
4637 code1
= TREE_CODE (type1
);
4639 if (code2
!= VOID_TYPE
)
4641 op2
= default_conversion (op2
);
4642 type2
= TREE_TYPE (op2
);
4643 code2
= TREE_CODE (type2
);
4646 /* Quickly detect the usual case where op1 and op2 have the same type
4648 if (TYPE_MAIN_VARIANT (type1
) == TYPE_MAIN_VARIANT (type2
))
4651 result_type
= type1
;
4653 result_type
= cp_build_type_variant
4655 TREE_READONLY (op1
) || TREE_READONLY (op2
),
4656 TREE_THIS_VOLATILE (op1
) || TREE_THIS_VOLATILE (op2
));
4658 else if ((code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
)
4659 && (code2
== INTEGER_TYPE
|| code2
== REAL_TYPE
))
4661 result_type
= common_type (type1
, type2
);
4663 else if (code1
== VOID_TYPE
|| code2
== VOID_TYPE
)
4665 if (pedantic
&& (code1
!= VOID_TYPE
|| code2
!= VOID_TYPE
))
4666 pedwarn ("ANSI C++ forbids conditional expr with only one void side");
4667 result_type
= void_type_node
;
4669 else if (code1
== POINTER_TYPE
&& code2
== POINTER_TYPE
)
4671 if (comp_target_types (type1
, type2
, 1))
4672 result_type
= common_type (type1
, type2
);
4673 else if (integer_zerop (op1
) && TREE_TYPE (type1
) == void_type_node
4674 && TREE_CODE (orig_op1
) != NOP_EXPR
)
4675 result_type
= qualify_type (type2
, type1
);
4676 else if (integer_zerop (op2
) && TREE_TYPE (type2
) == void_type_node
4677 && TREE_CODE (orig_op2
) != NOP_EXPR
)
4678 result_type
= qualify_type (type1
, type2
);
4679 else if (TYPE_MAIN_VARIANT (TREE_TYPE (type1
)) == void_type_node
)
4681 if (pedantic
&& TREE_CODE (type2
) == FUNCTION_TYPE
)
4682 pedwarn ("ANSI C++ forbids conditional expr between `void *' and function pointer");
4683 result_type
= qualify_type (type1
, type2
);
4685 else if (TYPE_MAIN_VARIANT (TREE_TYPE (type2
)) == void_type_node
)
4687 if (pedantic
&& TREE_CODE (type1
) == FUNCTION_TYPE
)
4688 pedwarn ("ANSI C++ forbids conditional expr between `void *' and function pointer");
4689 result_type
= qualify_type (type2
, type1
);
4692 else if (comptypes (type2
, type1
, 0))
4693 result_type
= type2
;
4694 else if (IS_AGGR_TYPE (TREE_TYPE (type1
))
4695 && IS_AGGR_TYPE (TREE_TYPE (type2
))
4696 && (result_type
= common_base_type (TREE_TYPE (type1
), TREE_TYPE (type2
))))
4698 if (result_type
== error_mark_node
)
4700 cp_error ("common base type of types `%T' and `%T' is ambiguous",
4701 TREE_TYPE (type1
), TREE_TYPE (type2
));
4702 result_type
= ptr_type_node
;
4707 && result_type
!= TREE_TYPE (type1
)
4708 && result_type
!= TREE_TYPE (type2
))
4709 cp_pedwarn ("`%T' and `%T' converted to `%T *' in conditional expression",
4710 type1
, type2
, result_type
);
4712 result_type
= TYPE_POINTER_TO (result_type
);
4717 pedwarn ("pointer type mismatch in conditional expression");
4718 result_type
= ptr_type_node
;
4721 else if (code1
== POINTER_TYPE
&& code2
== INTEGER_TYPE
)
4723 if (!integer_zerop (op2
))
4724 pedwarn ("pointer/integer type mismatch in conditional expression");
4727 op2
= null_pointer_node
;
4728 #if 0 /* Sez who? */
4729 if (pedantic
&& TREE_CODE (type1
) == FUNCTION_TYPE
)
4730 pedwarn ("ANSI C++ forbids conditional expr between 0 and function pointer");
4733 result_type
= type1
;
4735 else if (code2
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
4737 if (!integer_zerop (op1
))
4738 pedwarn ("pointer/integer type mismatch in conditional expression");
4741 op1
= null_pointer_node
;
4742 #if 0 /* Sez who? */
4743 if (pedantic
&& TREE_CODE (type2
) == FUNCTION_TYPE
)
4744 pedwarn ("ANSI C++ forbids conditional expr between 0 and function pointer");
4747 result_type
= type2
;
4752 /* The match does not look good. If either is
4753 an aggregate value, try converting to a scalar type. */
4754 if (code1
== RECORD_TYPE
&& code2
== RECORD_TYPE
)
4756 message_2_types (error
, "aggregate mismatch in conditional expression: `%s' vs `%s'", type1
, type2
);
4757 return error_mark_node
;
4759 if (code1
== RECORD_TYPE
&& TYPE_HAS_CONVERSION (type1
))
4761 tree tmp
= build_type_conversion (CONVERT_EXPR
, type2
, op1
, 0);
4762 if (tmp
== NULL_TREE
)
4764 cp_error ("aggregate type `%T' could not convert on lhs of `:'", type1
);
4765 return error_mark_node
;
4767 if (tmp
== error_mark_node
)
4768 error ("ambiguous pointer conversion");
4769 result_type
= type2
;
4772 else if (code2
== RECORD_TYPE
&& TYPE_HAS_CONVERSION (type2
))
4774 tree tmp
= build_type_conversion (CONVERT_EXPR
, type1
, op2
, 0);
4775 if (tmp
== NULL_TREE
)
4777 cp_error ("aggregate type `%T' could not convert on rhs of `:'", type2
);
4778 return error_mark_node
;
4780 if (tmp
== error_mark_node
)
4781 error ("ambiguous pointer conversion");
4782 result_type
= type1
;
4785 else if (flag_cond_mismatch
)
4786 result_type
= void_type_node
;
4789 error ("type mismatch in conditional expression");
4790 return error_mark_node
;
4794 if (result_type
!= TREE_TYPE (op1
))
4795 op1
= convert_and_check (result_type
, op1
);
4796 if (result_type
!= TREE_TYPE (op2
))
4797 op2
= convert_and_check (result_type
, op2
);
4800 /* XXX delete me, I've been here for years. */
4801 if (IS_AGGR_TYPE_CODE (code1
))
4803 result_type
= TREE_TYPE (op1
);
4804 if (TREE_CONSTANT (ifexp
))
4805 return (integer_zerop (ifexp
) ? op2
: op1
);
4807 if (TYPE_MODE (result_type
) == BLKmode
)
4809 register tree tempvar
4810 = build_decl (VAR_DECL
, NULL_TREE
, result_type
);
4811 register tree xop1
= build_modify_expr (tempvar
, NOP_EXPR
, op1
);
4812 register tree xop2
= build_modify_expr (tempvar
, NOP_EXPR
, op2
);
4813 register tree result
= fold (build (COND_EXPR
, result_type
,
4814 ifexp
, xop1
, xop2
));
4816 layout_decl (tempvar
, 0);
4817 /* No way to handle variable-sized objects here.
4818 I fear that the entire handling of BLKmode conditional exprs
4819 needs to be redone. */
4820 my_friendly_assert (TREE_CONSTANT (DECL_SIZE (tempvar
)), 315);
4822 = assign_stack_local (DECL_MODE (tempvar
),
4823 (TREE_INT_CST_LOW (DECL_SIZE (tempvar
))
4824 + BITS_PER_UNIT
- 1)
4828 TREE_SIDE_EFFECTS (result
)
4829 = TREE_SIDE_EFFECTS (ifexp
) | TREE_SIDE_EFFECTS (op1
)
4830 | TREE_SIDE_EFFECTS (op2
);
4831 return build (COMPOUND_EXPR
, result_type
, result
, tempvar
);
4836 if (TREE_CONSTANT (ifexp
))
4837 return integer_zerop (ifexp
) ? op2
: op1
;
4839 return fold (build (COND_EXPR
, result_type
, ifexp
, op1
, op2
));
4842 /* Handle overloading of the ',' operator when needed. Otherwise,
4843 this function just builds an expression list. */
4845 build_x_compound_expr (list
)
4848 tree rest
= TREE_CHAIN (list
);
4851 if (rest
== NULL_TREE
)
4852 return build_compound_expr (list
);
4854 result
= build_opfncall (COMPOUND_EXPR
, LOOKUP_NORMAL
,
4855 TREE_VALUE (list
), TREE_VALUE (rest
), NULL_TREE
);
4857 return build_x_compound_expr (tree_cons (NULL_TREE
, result
, TREE_CHAIN (rest
)));
4858 return build_compound_expr (tree_cons (NULL_TREE
, TREE_VALUE (list
),
4859 build_tree_list (NULL_TREE
, build_x_compound_expr (rest
))));
4862 /* Given a list of expressions, return a compound expression
4863 that performs them all and returns the value of the last of them. */
4866 build_compound_expr (list
)
4871 if (TREE_READONLY_DECL_P (TREE_VALUE (list
)))
4872 TREE_VALUE (list
) = decl_constant_value (TREE_VALUE (list
));
4874 if (TREE_CHAIN (list
) == 0)
4876 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
4877 Strip such NOP_EXPRs, since LIST is used in non-lvalue context. */
4878 if (TREE_CODE (list
) == NOP_EXPR
4879 && TREE_TYPE (list
) == TREE_TYPE (TREE_OPERAND (list
, 0)))
4880 list
= TREE_OPERAND (list
, 0);
4882 /* Convert arrays to pointers. */
4883 if (TREE_CODE (TREE_TYPE (TREE_VALUE (list
))) == ARRAY_TYPE
)
4884 return default_conversion (TREE_VALUE (list
));
4886 return TREE_VALUE (list
);
4889 rest
= build_compound_expr (TREE_CHAIN (list
));
4891 /* When pedantic, a compound expression can be neither an lvalue
4892 nor an integer constant expression. */
4893 if (! TREE_SIDE_EFFECTS (TREE_VALUE (list
)) && ! pedantic
)
4896 return build (COMPOUND_EXPR
, TREE_TYPE (rest
),
4897 break_out_cleanups (TREE_VALUE (list
)), rest
);
4907 return (TREE_CODE (t
) == INTEGER_CST
&& integer_zerop (t
));
4910 tree
build_static_cast (type
, expr
)
4913 return build_c_cast (type
, expr
, 0);
4916 tree
build_reinterpret_cast (type
, expr
)
4919 tree intype
= TREE_TYPE (expr
);
4921 if (TYPE_PTRMEMFUNC_P (type
))
4922 type
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
4923 if (TYPE_PTRMEMFUNC_P (intype
))
4924 intype
= TYPE_PTRMEMFUNC_FN_TYPE (intype
);
4926 if (! POINTER_TYPE_P (type
) && ! TREE_CODE (type
) == INTEGER_TYPE
)
4928 cp_error ("reinterpret_cast cannot convert to type `%T'", type
);
4929 return error_mark_node
;
4931 if (! POINTER_TYPE_P (intype
) && ! TREE_CODE (intype
) == INTEGER_TYPE
)
4933 cp_error ("reinterpret_cast cannot convert from type `%T'", type
);
4934 return error_mark_node
;
4936 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_CODE (intype
) != POINTER_TYPE
)
4938 cp_error ("reinterpret_cast cannot convert non-pointer type `%T' to `%T'",
4940 return error_mark_node
;
4942 if (TREE_CODE (intype
) == INTEGER_TYPE
&& TREE_CODE (type
) != POINTER_TYPE
)
4944 cp_error ("reinterpret_cast cannot convert `%T' to non-pointer type `%T'",
4946 return error_mark_node
;
4949 if (TREE_CODE (type
) == POINTER_TYPE
&& TREE_CODE (intype
) == POINTER_TYPE
)
4950 expr
= convert (ptr_type_node
, expr
);
4952 return build_c_cast (type
, expr
, 0);
4955 tree
build_const_cast (type
, expr
)
4958 tree intype
= TREE_TYPE (expr
);
4961 if (TYPE_PTRMEMFUNC_P (type
))
4962 type
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
4963 if (TYPE_PTRMEMFUNC_P (intype
))
4964 intype
= TYPE_PTRMEMFUNC_FN_TYPE (intype
);
4966 if (! POINTER_TYPE_P (type
))
4968 cp_error ("const_cast cannot convert to non-pointer type `%T'", type
);
4969 return error_mark_node
;
4971 if (TREE_CODE (type
) == REFERENCE_TYPE
&& ! real_lvalue_p (expr
))
4973 cp_error ("const_cast cannot convert rvalue to type `%T'", type
);
4974 return error_mark_node
;
4976 if (TREE_CODE (type
) == POINTER_TYPE
&& TREE_CODE (intype
) != POINTER_TYPE
)
4978 cp_error ("const_cast cannot convert non-pointer type `%T' to type `%T'",
4980 return error_mark_node
;
4983 if (TREE_CODE (type
) == REFERENCE_TYPE
)
4985 t1
= TREE_TYPE (type
);
4990 t1
= TREE_TYPE (type
);
4991 t2
= TREE_TYPE (intype
);
4993 for (; TREE_CODE (t1
) == POINTER_TYPE
&& TREE_CODE (t2
) == POINTER_TYPE
;
4994 t1
= TREE_TYPE (t1
), t2
= TREE_TYPE (t2
))
4998 if (TREE_CODE (t1
) == OFFSET_TYPE
&& TREE_CODE (t2
) == OFFSET_TYPE
)
5000 if (TYPE_OFFSET_BASETYPE (t1
) != TYPE_OFFSET_BASETYPE (t2
))
5002 cp_error ("const_cast cannot convert between pointers to members of different types `%T' and `%T'",
5003 TYPE_OFFSET_BASETYPE (t2
), TYPE_OFFSET_BASETYPE (t1
));
5004 return error_mark_node
;
5006 t1
= TREE_TYPE (t1
);
5007 t2
= TREE_TYPE (t2
);
5010 if (TYPE_MAIN_VARIANT (t1
) != TYPE_MAIN_VARIANT (t2
))
5012 cp_error ("const_cast cannot convert unrelated type `%T' to `%T'",
5014 return error_mark_node
;
5017 return build_c_cast (type
, expr
, 0);
5020 /* Build an expression representing a cast to type TYPE of expression EXPR.
5022 ALLOW_NONCONVERTING is true if we should allow non-converting constructors
5023 when doing the cast. */
5026 build_c_cast (type
, expr
, allow_nonconverting
)
5029 int allow_nonconverting
;
5031 register tree value
= expr
;
5033 if (type
== error_mark_node
|| expr
== error_mark_node
)
5034 return error_mark_node
;
5036 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5037 Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */
5038 if (TREE_CODE (type
) != REFERENCE_TYPE
5039 && TREE_CODE (value
) == NOP_EXPR
5040 && TREE_TYPE (value
) == TREE_TYPE (TREE_OPERAND (value
, 0)))
5041 value
= TREE_OPERAND (value
, 0);
5043 if (TREE_TYPE (expr
)
5044 && TREE_CODE (TREE_TYPE (expr
)) == OFFSET_TYPE
5045 && TREE_CODE (type
) != OFFSET_TYPE
)
5046 value
= resolve_offset_ref (value
);
5048 if (TREE_CODE (type
) == ARRAY_TYPE
)
5050 /* Allow casting from T1* to T2[] because Cfront allows it.
5051 NIHCL uses it. It is not valid ANSI C however, and hence, not
5053 if (TREE_CODE (TREE_TYPE (expr
)) == POINTER_TYPE
)
5056 pedwarn ("ANSI C++ forbids casting to an array type");
5057 type
= build_pointer_type (TREE_TYPE (type
));
5061 error ("ANSI C++ forbids casting to an array type");
5062 return error_mark_node
;
5066 if (TREE_CODE (type
) == FUNCTION_TYPE
5067 || TREE_CODE (type
) == METHOD_TYPE
)
5069 cp_error ("casting to function type `%T'", type
);
5070 return error_mark_node
;
5073 if (IS_SIGNATURE (type
))
5075 error ("cast specifies signature type");
5076 return error_mark_node
;
5079 /* If there's only one function in the overloaded space,
5081 if (TREE_CODE (value
) == TREE_LIST
5082 && TREE_CHAIN (value
) == NULL_TREE
)
5083 value
= TREE_VALUE (value
);
5085 if (TREE_CODE (type
) == VOID_TYPE
)
5086 value
= build1 (CONVERT_EXPR
, type
, value
);
5087 else if (TREE_TYPE (value
) == NULL_TREE
5088 || type_unknown_p (value
))
5090 value
= instantiate_type (type
, value
, 1);
5092 if (value
== error_mark_node
)
5093 return error_mark_node
;
5100 /* Convert functions and arrays to pointers and
5101 convert references to their expanded types,
5102 but don't convert any other types. */
5103 if (TREE_CODE (TREE_TYPE (value
)) == FUNCTION_TYPE
5104 || TREE_CODE (TREE_TYPE (value
)) == METHOD_TYPE
5105 || TREE_CODE (TREE_TYPE (value
)) == ARRAY_TYPE
5106 || TREE_CODE (TREE_TYPE (value
)) == REFERENCE_TYPE
)
5107 value
= default_conversion (value
);
5108 otype
= TREE_TYPE (value
);
5110 /* Optionally warn about potentially worrisome casts. */
5113 && TREE_CODE (type
) == POINTER_TYPE
5114 && TREE_CODE (otype
) == POINTER_TYPE
)
5116 /* For C++ we make these regular warnings, rather than
5117 softening them into pedwarns. */
5118 if (TYPE_VOLATILE (TREE_TYPE (otype
))
5119 && ! TYPE_VOLATILE (TREE_TYPE (type
)))
5120 warning ("cast discards `volatile' from pointer target type");
5121 if (TYPE_READONLY (TREE_TYPE (otype
))
5122 && ! TYPE_READONLY (TREE_TYPE (type
)))
5123 warning ("cast discards `const' from pointer target type");
5126 /* Warn about possible alignment problems. */
5127 if (STRICT_ALIGNMENT
&& warn_cast_align
5128 && TREE_CODE (type
) == POINTER_TYPE
5129 && TREE_CODE (otype
) == POINTER_TYPE
5130 && TREE_CODE (TREE_TYPE (otype
)) != VOID_TYPE
5131 && TREE_CODE (TREE_TYPE (otype
)) != FUNCTION_TYPE
5132 && TYPE_ALIGN (TREE_TYPE (type
)) > TYPE_ALIGN (TREE_TYPE (otype
)))
5133 warning ("cast increases required alignment of target type");
5136 if (TREE_CODE (type
) == INTEGER_TYPE
5137 && TREE_CODE (otype
) == POINTER_TYPE
5138 && TYPE_PRECISION (type
) != TYPE_PRECISION (otype
))
5139 warning ("cast from pointer to integer of different size");
5141 if (TREE_CODE (type
) == POINTER_TYPE
5142 && TREE_CODE (otype
) == INTEGER_TYPE
5143 && TYPE_PRECISION (type
) != TYPE_PRECISION (otype
)
5144 /* Don't warn about converting 0 to pointer,
5145 provided the 0 was explicit--not cast or made by folding. */
5146 && !(TREE_CODE (value
) == INTEGER_CST
&& integer_zerop (value
)))
5147 warning ("cast to pointer from integer of different size");
5150 flag
= allow_nonconverting
? CONV_NONCONVERTING
: 0;
5152 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5153 value
= (convert_from_reference
5154 (convert_to_reference (type
, value
, CONV_OLD_CONVERT
|flag
,
5155 LOOKUP_COMPLAIN
, NULL_TREE
)));
5160 if (TREE_READONLY_DECL_P (value
))
5161 value
= decl_constant_value (value
);
5164 value
= convert_force (type
, value
, flag
);
5166 /* Ignore any integer overflow caused by the cast. */
5167 if (TREE_CODE (value
) == INTEGER_CST
)
5169 TREE_OVERFLOW (value
) = TREE_OVERFLOW (ovalue
);
5170 TREE_CONSTANT_OVERFLOW (value
) = TREE_CONSTANT_OVERFLOW (ovalue
);
5175 /* Always produce some operator for an explicit cast,
5176 so we can tell (for -pedantic) that the cast is no lvalue.
5177 Also, pedantically, don't let (void *) (FOO *) 0 be a null
5178 pointer constant. */
5181 && TREE_CODE (value
) == INTEGER_CST
5182 && TREE_CODE (expr
) == INTEGER_CST
5183 && TREE_CODE (TREE_TYPE (expr
)) != INTEGER_TYPE
))
5184 value
= non_lvalue (value
);
5190 /* Build an assignment expression of lvalue LHS from value RHS.
5192 In C++, if the left hand side of the assignment is a REFERENCE_TYPE,
5193 that reference becomes deferenced down to it base type. */
5195 /* Return a reference to the BASE_INDEX part of EXPR. TYPE is
5196 the type to which BASE_INDEX applies. */
5198 get_base_ref (type
, base_index
, expr
)
5203 tree binfos
= TYPE_BINFO_BASETYPES (type
);
5204 tree base_binfo
= TREE_VEC_ELT (binfos
, base_index
);
5207 if (TREE_CODE (expr
) == ARRAY_REF
5208 || ! BINFO_OFFSET_ZEROP (base_binfo
)
5209 || TREE_VIA_VIRTUAL (base_binfo
)
5210 || TYPE_MODE (type
) != TYPE_MODE (BINFO_TYPE (base_binfo
)))
5212 tree addr
= build_unary_op (ADDR_EXPR
, expr
, 0);
5213 ref
= build_indirect_ref (convert_pointer_to (base_binfo
, addr
),
5218 ref
= copy_node (expr
);
5219 TREE_TYPE (ref
) = BINFO_TYPE (base_binfo
);
5224 /* Build an assignment expression of lvalue LHS from value RHS.
5225 MODIFYCODE is the code for a binary operator that we use
5226 to combine the old value of LHS with RHS to get the new value.
5227 Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.
5229 C++: If MODIFYCODE is INIT_EXPR, then leave references unbashed.
5231 `build_modify_expr_1' implements recursive part of memberwise
5232 assignment operation. */
5234 build_modify_expr_1 (lhs
, modifycode
, rhs
, basetype_path
)
5236 enum tree_code modifycode
;
5239 register tree result
;
5241 tree lhstype
= TREE_TYPE (lhs
);
5242 tree olhstype
= lhstype
;
5244 /* Avoid duplicate error messages from operands that had errors. */
5245 if (TREE_CODE (lhs
) == ERROR_MARK
|| TREE_CODE (rhs
) == ERROR_MARK
)
5246 return error_mark_node
;
5248 /* If a binary op has been requested, combine the old LHS value with the RHS
5249 producing the value we should actually store into the LHS. */
5251 if (modifycode
== INIT_EXPR
)
5253 else if (modifycode
== NOP_EXPR
)
5255 /* must deal with overloading of `operator=' here. */
5256 if (TREE_CODE (lhstype
) == REFERENCE_TYPE
)
5257 lhstype
= TREE_TYPE (lhstype
);
5263 lhs
= stabilize_reference (lhs
);
5264 newrhs
= build_binary_op (modifycode
, lhs
, rhs
, 1);
5265 modifycode
= NOP_EXPR
;
5268 /* If storing into a structure or union member,
5269 it has probably been given type `int'.
5270 Compute the type that would go with
5271 the actual amount of storage the member occupies. */
5273 if (TREE_CODE (lhs
) == COMPONENT_REF
5274 && (TREE_CODE (lhstype
) == INTEGER_TYPE
5275 || TREE_CODE (lhstype
) == REAL_TYPE
5276 || TREE_CODE (lhstype
) == ENUMERAL_TYPE
))
5277 lhstype
= TREE_TYPE (get_unwidened (lhs
, 0));
5279 /* C++: The semantics of C++ differ from those of C when an
5280 assignment of an aggregate is desired. Assignment in C++ is
5281 now defined as memberwise assignment of non-static members
5282 and base class objects. This rule applies recursively
5283 until a member of a built-in type is found.
5285 Also, we cannot do a bit-wise copy of aggregates which
5286 contain virtual function table pointers. Those
5287 pointer values must be preserved through the copy.
5288 However, this is handled in expand_expr, and not here.
5289 This is because much better code can be generated at
5290 that stage than this one. */
5291 if (TREE_CODE (lhstype
) == RECORD_TYPE
5292 && TYPE_LANG_SPECIFIC (lhstype
)
5293 && TYPE_MAIN_VARIANT (lhstype
) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs
)))
5298 /* Perform operation on object. */
5299 if (modifycode
== INIT_EXPR
&& TYPE_HAS_INIT_REF (lhstype
))
5301 result
= build_method_call (lhs
, constructor_name_full (lhstype
),
5302 build_tree_list (NULL_TREE
, rhs
),
5303 basetype_path
, LOOKUP_NORMAL
);
5304 return build_indirect_ref (result
, NULL_PTR
);
5306 else if (modifycode
== NOP_EXPR
)
5308 /* `operator=' is not an inheritable operator; see 13.4.3. */
5309 if (TYPE_LANG_SPECIFIC (lhstype
) && TYPE_HAS_ASSIGNMENT (lhstype
))
5311 result
= build_opfncall (MODIFY_EXPR
, LOOKUP_NORMAL
,
5312 lhs
, rhs
, make_node (NOP_EXPR
));
5313 if (result
== NULL_TREE
)
5314 return error_mark_node
;
5319 if (TYPE_USES_VIRTUAL_BASECLASSES (lhstype
)
5320 || (modifycode
== NOP_EXPR
&& TYPE_GETS_ASSIGNMENT (lhstype
))
5321 || (modifycode
== INIT_EXPR
&& TYPE_GETS_INIT_REF (lhstype
)))
5323 tree binfos
= BINFO_BASETYPES (TYPE_BINFO (lhstype
));
5326 if (binfos
!= NULL_TREE
)
5327 /* Perform operation on each member, depth-first, left-right. */
5328 for (i
= 0; i
<= TREE_VEC_LENGTH (binfos
)-1; i
++)
5330 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
5331 tree base_lhs
, base_rhs
;
5334 /* Assignments from virtual baseclasses handled elsewhere. */
5335 if (TREE_VIA_VIRTUAL (base_binfo
))
5338 base_lhs
= get_base_ref (lhstype
, i
, lhs
);
5339 base_rhs
= get_base_ref (lhstype
, i
, newrhs
);
5341 BINFO_INHERITANCE_CHAIN (base_binfo
) = basetype_path
;
5343 = build_modify_expr_1 (base_lhs
, modifycode
, base_rhs
,
5346 /* We either get back a compound stmt, or a simple one. */
5347 if (new_result
&& TREE_CODE (new_result
) == TREE_LIST
)
5348 new_result
= build_compound_expr (new_result
);
5349 result
= tree_cons (NULL_TREE
, new_result
, result
);
5352 for (elt
= TYPE_FIELDS (lhstype
); elt
; elt
= TREE_CHAIN (elt
))
5354 tree vbases
= NULL_TREE
;
5355 tree elt_lhs
, elt_rhs
;
5357 if (TREE_CODE (elt
) != FIELD_DECL
)
5360 && (VFIELD_NAME_P (DECL_NAME (elt
))
5361 || VBASE_NAME_P (DECL_NAME (elt
))))
5364 if (TREE_READONLY (elt
)
5365 || TREE_CODE (TREE_TYPE (elt
)) == REFERENCE_TYPE
)
5367 cp_error ("cannot generate default `%T::operator ='",
5369 if (TREE_CODE (TREE_TYPE (elt
)) == REFERENCE_TYPE
)
5370 cp_error_at ("because member `%#D' is a reference", elt
);
5372 cp_error_at ("because member `%#D' is const", elt
);
5374 return error_mark_node
;
5377 if (IS_AGGR_TYPE (TREE_TYPE (elt
))
5378 && TYPE_LANG_SPECIFIC (TREE_TYPE (elt
)))
5379 vbases
= CLASSTYPE_VBASECLASSES (TREE_TYPE (elt
));
5381 elt_lhs
= build (COMPONENT_REF
, TREE_TYPE (elt
), lhs
, elt
);
5382 elt_rhs
= build (COMPONENT_REF
, TREE_TYPE (elt
), newrhs
, elt
);
5383 /* It is not always safe to go through `build_modify_expr_1'
5384 when performing element-wise copying. This is because
5385 an element may be of ARRAY_TYPE, which will not
5386 be properly copied as a naked element. */
5387 if (TREE_CODE (TREE_TYPE (elt
)) == RECORD_TYPE
5388 && TYPE_LANG_SPECIFIC (TREE_TYPE (elt
)))
5389 basetype_path
= TYPE_BINFO (TREE_TYPE (elt
));
5393 tree elt_lhs_addr
= build_unary_op (ADDR_EXPR
, elt_lhs
, 0);
5394 tree elt_rhs_addr
= build_unary_op (ADDR_EXPR
, elt_rhs
, 0);
5396 elt_lhs_addr
= convert_pointer_to (vbases
, elt_lhs_addr
);
5397 elt_rhs_addr
= convert_pointer_to (vbases
, elt_rhs_addr
);
5399 = tree_cons (NULL_TREE
,
5401 (build_indirect_ref (elt_lhs_addr
, NULL_PTR
),
5403 build_indirect_ref (elt_rhs_addr
, NULL_PTR
),
5406 if (TREE_VALUE (result
) == error_mark_node
)
5407 return error_mark_node
;
5408 vbases
= TREE_CHAIN (vbases
);
5410 elt_lhs
= build_modify_expr_1 (elt_lhs
, modifycode
, elt_rhs
,
5412 result
= tree_cons (NULL_TREE
, elt_lhs
, result
);
5416 return build_compound_expr (result
);
5417 /* No fields to move. */
5418 return integer_zero_node
;
5422 result
= build (modifycode
== NOP_EXPR
? MODIFY_EXPR
: INIT_EXPR
,
5423 void_type_node
, lhs
, rhs
);
5424 TREE_SIDE_EFFECTS (result
) = 1;
5429 result
= build_modify_expr (lhs
, modifycode
, newrhs
);
5430 /* ARRAY_TYPEs cannot be converted to anything meaningful,
5431 and leaving it there screws up `build_compound_expr' when
5432 it tries to defaultly convert everything. */
5433 if (TREE_CODE (TREE_TYPE (result
)) == ARRAY_TYPE
)
5434 TREE_TYPE (result
) = void_type_node
;
5439 /* Taken from expr.c:
5440 Subroutine of expand_expr:
5441 record the non-copied parts (LIST) of an expr (LHS), and return a list
5442 which specifies the initial values of these parts. */
5445 init_noncopied_parts (lhs
, list
)
5452 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
5453 if (TREE_CODE (TREE_VALUE (tail
)) == TREE_LIST
)
5454 parts
= chainon (parts
, init_noncopied_parts (lhs
, TREE_VALUE (tail
)));
5457 tree part
= TREE_VALUE (tail
);
5458 tree part_type
= TREE_TYPE (part
);
5459 tree to_be_initialized
= build (COMPONENT_REF
, part_type
, lhs
, part
);
5460 parts
= tree_cons (TREE_PURPOSE (tail
), to_be_initialized
, parts
);
5465 /* Build an assignment expression of lvalue LHS from value RHS.
5466 MODIFYCODE is the code for a binary operator that we use
5467 to combine the old value of LHS with RHS to get the new value.
5468 Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.
5470 C++: If MODIFYCODE is INIT_EXPR, then leave references unbashed.
5473 build_modify_expr (lhs
, modifycode
, rhs
)
5475 enum tree_code modifycode
;
5478 register tree result
;
5480 tree lhstype
= TREE_TYPE (lhs
);
5481 tree olhstype
= lhstype
;
5484 /* Avoid duplicate error messages from operands that had errors. */
5485 if (TREE_CODE (lhs
) == ERROR_MARK
|| TREE_CODE (rhs
) == ERROR_MARK
)
5486 return error_mark_node
;
5488 /* Types that aren't fully specified cannot be used in assignments. */
5489 lhs
= require_complete_type (lhs
);
5491 /* Decide early if we are going to protect RHS from GC
5492 before assigning it to LHS. */
5493 if (type_needs_gc_entry (TREE_TYPE (rhs
))
5494 && ! value_safe_from_gc (lhs
, rhs
))
5495 rhs
= protect_value_from_gc (lhs
, rhs
);
5499 /* Handle assignment to signature pointers/refs. */
5501 if (TYPE_LANG_SPECIFIC (lhstype
) &&
5502 (IS_SIGNATURE_POINTER (lhstype
) || IS_SIGNATURE_REFERENCE (lhstype
)))
5504 return build_signature_pointer_constructor (lhs
, rhs
);
5507 /* Handle control structure constructs used as "lvalues". */
5509 switch (TREE_CODE (lhs
))
5511 /* Handle --foo = 5; as these are valid constructs in C++ */
5512 case PREDECREMENT_EXPR
:
5513 case PREINCREMENT_EXPR
:
5514 if (TREE_SIDE_EFFECTS (TREE_OPERAND (lhs
, 0)))
5515 lhs
= build (TREE_CODE (lhs
), TREE_TYPE (lhs
),
5516 stabilize_reference (TREE_OPERAND (lhs
, 0)));
5517 return build (COMPOUND_EXPR
, lhstype
,
5519 build_modify_expr (TREE_OPERAND (lhs
, 0),
5522 /* Handle (a, b) used as an "lvalue". */
5524 newrhs
= build_modify_expr (TREE_OPERAND (lhs
, 1),
5526 if (TREE_CODE (newrhs
) == ERROR_MARK
)
5527 return error_mark_node
;
5528 return build (COMPOUND_EXPR
, lhstype
,
5529 TREE_OPERAND (lhs
, 0), newrhs
);
5532 newrhs
= build_modify_expr (TREE_OPERAND (lhs
, 0), modifycode
, rhs
);
5533 if (TREE_CODE (newrhs
) == ERROR_MARK
)
5534 return error_mark_node
;
5535 return build (COMPOUND_EXPR
, lhstype
, lhs
, newrhs
);
5537 /* Handle (a ? b : c) used as an "lvalue". */
5539 rhs
= save_expr (rhs
);
5541 /* Produce (a ? (b = rhs) : (c = rhs))
5542 except that the RHS goes through a save-expr
5543 so the code to compute it is only emitted once. */
5545 = build_conditional_expr (TREE_OPERAND (lhs
, 0),
5546 build_modify_expr (convert (TREE_TYPE (lhs
), TREE_OPERAND (lhs
, 1)),
5548 build_modify_expr (convert (TREE_TYPE (lhs
), TREE_OPERAND (lhs
, 2)),
5550 if (TREE_CODE (cond
) == ERROR_MARK
)
5552 /* Make sure the code to compute the rhs comes out
5553 before the split. */
5554 return build (COMPOUND_EXPR
, TREE_TYPE (lhs
),
5555 /* Case to void to suppress warning
5556 from warn_if_unused_value. */
5557 convert (void_type_node
, rhs
), cond
);
5561 if (TREE_CODE (lhs
) == OFFSET_REF
)
5563 if (TREE_OPERAND (lhs
, 0) == NULL_TREE
)
5565 /* Static class member? */
5566 tree member
= TREE_OPERAND (lhs
, 1);
5567 if (TREE_CODE (member
) == VAR_DECL
)
5571 compiler_error ("invalid static class member");
5572 return error_mark_node
;
5576 lhs
= resolve_offset_ref (lhs
);
5578 olhstype
= lhstype
= TREE_TYPE (lhs
);
5581 if (TREE_CODE (lhstype
) == REFERENCE_TYPE
5582 && modifycode
!= INIT_EXPR
)
5584 lhs
= convert_from_reference (lhs
);
5585 olhstype
= lhstype
= TREE_TYPE (lhs
);
5588 /* If a binary op has been requested, combine the old LHS value with the RHS
5589 producing the value we should actually store into the LHS. */
5591 if (modifycode
== INIT_EXPR
)
5593 if (! IS_AGGR_TYPE (lhstype
))
5594 /* Do the default thing */;
5595 else if (! TYPE_HAS_CONSTRUCTOR (lhstype
))
5596 cp_error ("`%T' has no constructors", lhstype
);
5597 else if (! TYPE_NEEDS_CONSTRUCTING (lhstype
)
5598 && TYPE_MAIN_VARIANT (lhstype
) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs
)))
5599 /* Do the default thing */;
5602 result
= build_method_call (lhs
, constructor_name_full (lhstype
),
5603 build_tree_list (NULL_TREE
, rhs
),
5604 NULL_TREE
, LOOKUP_NORMAL
);
5605 if (result
== NULL_TREE
)
5606 return error_mark_node
;
5610 else if (modifycode
== NOP_EXPR
)
5613 /* `operator=' is not an inheritable operator. */
5614 if (! IS_AGGR_TYPE (lhstype
))
5615 /* Do the default thing */;
5616 else if (! TYPE_HAS_ASSIGNMENT (lhstype
))
5617 cp_error ("`%T' does not define operator=", lhstype
);
5618 else if (! TYPE_HAS_REAL_ASSIGNMENT (lhstype
)
5619 && ! TYPE_HAS_COMPLEX_ASSIGN_REF (lhstype
)
5620 /* FIXME find some way to deal with TARGET_EXPRs here. */
5621 && TREE_CODE (newrhs
) != TARGET_EXPR
5622 && TYPE_MAIN_VARIANT (lhstype
) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs
)))
5623 /* Do the default thing */;
5626 result
= build_opfncall (MODIFY_EXPR
, LOOKUP_NORMAL
,
5627 lhs
, rhs
, make_node (NOP_EXPR
));
5628 if (result
== NULL_TREE
)
5629 return error_mark_node
;
5633 /* Treat `operator=' as an inheritable operator. */
5634 if (TYPE_LANG_SPECIFIC (lhstype
) && TYPE_GETS_ASSIGNMENT (lhstype
))
5636 tree orig_lhstype
= lhstype
;
5637 while (! TYPE_HAS_ASSIGNMENT (lhstype
))
5639 int i
, n_baseclasses
= CLASSTYPE_N_BASECLASSES (lhstype
);
5640 tree basetype
= NULL_TREE
;
5641 for (i
= 0; i
< n_baseclasses
; i
++)
5642 if (TYPE_GETS_ASSIGNMENT (TYPE_BINFO_BASETYPE (lhstype
, i
)))
5644 if (basetype
!= NULL_TREE
)
5646 message_2_types (error
, "base classes `%s' and `%s' both have operator ='",
5648 TYPE_BINFO_BASETYPE (lhstype
, i
));
5649 return error_mark_node
;
5651 basetype
= TYPE_BINFO_BASETYPE (lhstype
, i
);
5655 if (orig_lhstype
!= lhstype
)
5657 lhs
= build_indirect_ref (convert_pointer_to (lhstype
,
5658 build_unary_op (ADDR_EXPR
, lhs
, 0)), NULL_PTR
);
5659 if (lhs
== error_mark_node
)
5661 cp_error ("conversion to private basetype `%T'", lhstype
);
5662 return error_mark_node
;
5665 result
= build_opfncall (MODIFY_EXPR
, LOOKUP_NORMAL
,
5666 lhs
, rhs
, make_node (NOP_EXPR
));
5667 if (result
== NULL_TREE
)
5668 return error_mark_node
;
5674 else if (PROMOTES_TO_AGGR_TYPE (lhstype
, REFERENCE_TYPE
))
5676 /* This case must convert to some sort of lvalue that
5677 can participate in an op= operation. */
5680 if (build_default_binary_type_conversion (modifycode
, &lhs_tmp
, &rhs_tmp
))
5682 lhs
= stabilize_reference (lhs_tmp
);
5683 /* Forget is was ever anything else. */
5684 olhstype
= lhstype
= TREE_TYPE (lhs
);
5685 newrhs
= build_binary_op (modifycode
, lhs
, rhs_tmp
, 1);
5688 return error_mark_node
;
5692 lhs
= stabilize_reference (lhs
);
5693 newrhs
= build_binary_op (modifycode
, lhs
, rhs
, 1);
5696 /* Handle a cast used as an "lvalue".
5697 We have already performed any binary operator using the value as cast.
5698 Now convert the result to the cast type of the lhs,
5699 and then true type of the lhs and store it there;
5700 then convert result back to the cast type to be the value
5701 of the assignment. */
5703 switch (TREE_CODE (lhs
))
5708 case FIX_TRUNC_EXPR
:
5709 case FIX_FLOOR_EXPR
:
5710 case FIX_ROUND_EXPR
:
5712 if (TREE_CODE (TREE_TYPE (newrhs
)) == ARRAY_TYPE
5713 || TREE_CODE (TREE_TYPE (newrhs
)) == FUNCTION_TYPE
5714 || TREE_CODE (TREE_TYPE (newrhs
)) == METHOD_TYPE
5715 || TREE_CODE (TREE_TYPE (newrhs
)) == OFFSET_TYPE
)
5716 newrhs
= default_conversion (newrhs
);
5718 tree inner_lhs
= TREE_OPERAND (lhs
, 0);
5720 if (! lvalue_p (lhs
) && pedantic
)
5721 pedwarn ("cast to non-reference type used as lvalue");
5723 result
= build_modify_expr (inner_lhs
, NOP_EXPR
,
5724 convert (TREE_TYPE (inner_lhs
),
5725 convert (lhstype
, newrhs
)));
5726 if (TREE_CODE (result
) == ERROR_MARK
)
5728 return convert (TREE_TYPE (lhs
), result
);
5732 /* Now we have handled acceptable kinds of LHS that are not truly lvalues.
5733 Reject anything strange now. */
5735 if (!lvalue_or_else (lhs
, "assignment"))
5736 return error_mark_node
;
5738 GNU_xref_assign (lhs
);
5740 /* Warn about storing in something that is `const'. */
5741 /* For C++, don't warn if this is initialization. */
5742 if (modifycode
!= INIT_EXPR
5743 /* For assignment to `const' signature pointer/reference fields,
5744 don't warn either, we already printed a better message before. */
5745 && ! (TREE_CODE (lhs
) == COMPONENT_REF
5746 && (IS_SIGNATURE_POINTER (TREE_TYPE (TREE_OPERAND (lhs
, 0)))
5747 || IS_SIGNATURE_REFERENCE (TREE_TYPE (TREE_OPERAND (lhs
, 0)))))
5748 && (TREE_READONLY (lhs
) || TYPE_READONLY (lhstype
)
5749 || ((TREE_CODE (lhstype
) == RECORD_TYPE
5750 || TREE_CODE (lhstype
) == UNION_TYPE
)
5751 && C_TYPE_FIELDS_READONLY (lhstype
))
5752 || (TREE_CODE (lhstype
) == REFERENCE_TYPE
5753 && TYPE_READONLY (TREE_TYPE (lhstype
)))))
5754 readonly_error (lhs
, "assignment", 0);
5756 /* If storing into a structure or union member,
5757 it has probably been given type `int'.
5758 Compute the type that would go with
5759 the actual amount of storage the member occupies. */
5761 if (TREE_CODE (lhs
) == COMPONENT_REF
5762 && (TREE_CODE (lhstype
) == INTEGER_TYPE
5763 || TREE_CODE (lhstype
) == REAL_TYPE
5764 || TREE_CODE (lhstype
) == ENUMERAL_TYPE
))
5766 lhstype
= TREE_TYPE (get_unwidened (lhs
, 0));
5768 /* If storing in a field that is in actuality a short or narrower
5769 than one, we must store in the field in its actual type. */
5771 if (lhstype
!= TREE_TYPE (lhs
))
5773 lhs
= copy_node (lhs
);
5774 TREE_TYPE (lhs
) = lhstype
;
5778 /* check to see if there is an assignment to `this' */
5779 if (lhs
== current_class_decl
)
5781 if (flag_this_is_variable
> 0
5782 && DECL_NAME (current_function_decl
) != NULL_TREE
5783 && (DECL_NAME (current_function_decl
)
5784 != constructor_name (current_class_type
)))
5785 warning ("assignment to `this' not in constructor or destructor");
5786 current_function_just_assigned_this
= 1;
5789 /* The TREE_TYPE of RHS may be TYPE_UNKNOWN. This can happen
5790 when the type of RHS is not yet known, i.e. its type
5791 is inherited from LHS. */
5792 rhs
= require_instantiated_type (lhstype
, newrhs
, error_mark_node
);
5793 if (rhs
== error_mark_node
)
5794 return error_mark_node
;
5797 if (modifycode
!= INIT_EXPR
)
5799 /* Make modifycode now either a NOP_EXPR or an INIT_EXPR. */
5800 modifycode
= NOP_EXPR
;
5801 /* Reference-bashing */
5802 if (TREE_CODE (lhstype
) == REFERENCE_TYPE
)
5804 tree tmp
= convert_from_reference (lhs
);
5805 lhstype
= TREE_TYPE (tmp
);
5806 if (TYPE_SIZE (lhstype
) == 0)
5808 incomplete_type_error (lhs
, lhstype
);
5809 return error_mark_node
;
5814 if (TREE_CODE (TREE_TYPE (newrhs
)) == REFERENCE_TYPE
)
5816 tree tmp
= convert_from_reference (newrhs
);
5817 if (TYPE_SIZE (TREE_TYPE (tmp
)) == 0)
5819 incomplete_type_error (newrhs
, TREE_TYPE (tmp
));
5820 return error_mark_node
;
5826 if (TREE_SIDE_EFFECTS (lhs
))
5827 lhs
= stabilize_reference (lhs
);
5828 if (TREE_SIDE_EFFECTS (newrhs
))
5829 newrhs
= stabilize_reference (newrhs
);
5832 /* This is now done by generating X(X&) and operator=(X&). */
5833 /* C++: The semantics of C++ differ from those of C when an
5834 assignment of an aggregate is desired. Assignment in C++ is
5835 now defined as memberwise assignment of non-static members
5836 and base class objects. This rule applies recursively
5837 until a member of a built-in type is found.
5839 Also, we cannot do a bit-wise copy of aggregates which
5840 contain virtual function table pointers. Those
5841 pointer values must be preserved through the copy.
5842 However, this is handled in expand_expr, and not here.
5843 This is because much better code can be generated at
5844 that stage than this one. */
5845 if (TREE_CODE (lhstype
) == RECORD_TYPE
5846 && ! TYPE_PTRMEMFUNC_P (lhstype
)
5847 && (TYPE_MAIN_VARIANT (lhstype
) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs
))
5848 || (TREE_CODE (TREE_TYPE (newrhs
)) == RECORD_TYPE
5849 && UNIQUELY_DERIVED_FROM_P (lhstype
, TREE_TYPE (newrhs
)))))
5851 tree vbases
= CLASSTYPE_VBASECLASSES (lhstype
);
5852 tree lhs_addr
= build_unary_op (ADDR_EXPR
, lhs
, 0);
5855 /* Memberwise assignment would cause NEWRHS to be
5856 evaluated for every member that gets assigned.
5857 By wrapping side-effecting exprs in a SAVE_EXPR,
5858 NEWRHS will only be evaluated once. */
5859 if (IS_AGGR_TYPE (TREE_TYPE (newrhs
))
5860 && TREE_SIDE_EFFECTS (newrhs
)
5861 /* This are things we don't have to save. */
5862 && TREE_CODE (newrhs
) != COND_EXPR
5863 && TREE_CODE (newrhs
) != TARGET_EXPR
5864 && TREE_CODE (newrhs
) != WITH_CLEANUP_EXPR
)
5865 /* Call `break_out_cleanups' on NEWRHS in case there are cleanups.
5866 If NEWRHS is a CALL_EXPR that needs a cleanup, failure to do so
5867 will result in expand_expr expanding the call without knowing
5868 that it should run the cleanup. */
5869 newrhs
= save_expr (break_out_cleanups (newrhs
));
5871 if (TREE_CODE (newrhs
) == COND_EXPR
)
5872 rhs_addr
= rationalize_conditional_expr (ADDR_EXPR
, newrhs
);
5874 rhs_addr
= build_unary_op (ADDR_EXPR
, newrhs
, 0);
5876 result
= tree_cons (NULL_TREE
,
5877 convert (build_reference_type (lhstype
), lhs
),
5880 if (! comptypes (TREE_TYPE (lhs_addr
), TREE_TYPE (rhs_addr
), 1))
5881 rhs_addr
= convert_pointer_to (TREE_TYPE (TREE_TYPE (lhs_addr
)), rhs_addr
);
5883 tree noncopied_parts
= NULL_TREE
;
5885 if (TYPE_NONCOPIED_PARTS (lhstype
) != 0)
5886 noncopied_parts
= init_noncopied_parts (lhs
,
5887 TYPE_NONCOPIED_PARTS (lhstype
));
5888 while (noncopied_parts
!= 0)
5890 result
= tree_cons (NULL_TREE
,
5891 build_modify_expr (convert (ptr_type_node
, TREE_VALUE (noncopied_parts
)),
5893 TREE_PURPOSE (noncopied_parts
)),
5895 noncopied_parts
= TREE_CHAIN (noncopied_parts
);
5898 /* Once we have our hands on an address, we must change NEWRHS
5899 to work from there. Otherwise we can get multiple evaluations
5901 if (TREE_CODE (newrhs
) != SAVE_EXPR
)
5902 newrhs
= build_indirect_ref (rhs_addr
, NULL_PTR
);
5906 tree elt_lhs
= convert_pointer_to (vbases
, lhs_addr
);
5907 tree elt_rhs
= convert_pointer_to (vbases
, rhs_addr
);
5909 = tree_cons (NULL_TREE
,
5910 build_modify_expr_1 (build_indirect_ref (elt_lhs
, NULL_PTR
),
5912 build_indirect_ref (elt_rhs
, NULL_PTR
),
5913 TYPE_BINFO (lhstype
)),
5915 if (TREE_VALUE (result
) == error_mark_node
)
5916 return error_mark_node
;
5917 vbases
= TREE_CHAIN (vbases
);
5919 result
= tree_cons (NULL_TREE
,
5920 build_modify_expr_1 (lhs
,
5923 TYPE_BINFO (lhstype
)),
5925 return build_compound_expr (result
);
5929 /* Convert new value to destination type. */
5931 if (TREE_CODE (lhstype
) == ARRAY_TYPE
)
5935 /* Allow array assignment in compiler-generated code. */
5936 if (pedantic
&& ! DECL_ARTIFICIAL (current_function_decl
))
5937 pedwarn ("ANSI C++ forbids assignment of arrays");
5939 /* Have to wrap this in RTL_EXPR for two cases:
5940 in base or member initialization and if we
5941 are a branch of a ?: operator. Since we
5942 can't easily know the latter, just do it always. */
5944 result
= make_node (RTL_EXPR
);
5946 TREE_TYPE (result
) = void_type_node
;
5947 do_pending_stack_adjust ();
5948 start_sequence_for_rtl_expr (result
);
5950 /* As a matter of principle, `start_sequence' should do this. */
5953 from_array
= TREE_CODE (TREE_TYPE (newrhs
)) == ARRAY_TYPE
5954 ? 1 + (modifycode
!= INIT_EXPR
): 0;
5955 expand_vec_init (lhs
, lhs
, array_type_nelts (lhstype
), newrhs
,
5958 do_pending_stack_adjust ();
5960 TREE_SIDE_EFFECTS (result
) = 1;
5961 RTL_EXPR_SEQUENCE (result
) = get_insns ();
5962 RTL_EXPR_RTL (result
) = const0_rtx
;
5967 if (modifycode
== INIT_EXPR
)
5969 newrhs
= convert_for_initialization (lhs
, lhstype
, newrhs
, LOOKUP_NORMAL
,
5970 "assignment", NULL_TREE
, 0);
5971 if (lhs
== DECL_RESULT (current_function_decl
))
5973 if (DECL_INITIAL (lhs
))
5974 warning ("return value from function receives multiple initializations");
5975 DECL_INITIAL (lhs
) = newrhs
;
5981 if (IS_AGGR_TYPE (lhstype
))
5983 if (result
= build_opfncall (MODIFY_EXPR
,
5984 LOOKUP_NORMAL
, lhs
, newrhs
,
5985 make_node (NOP_EXPR
)))
5989 /* Avoid warnings on enum bit fields. */
5990 if (TREE_CODE (olhstype
) == ENUMERAL_TYPE
5991 && TREE_CODE (lhstype
) == INTEGER_TYPE
)
5993 newrhs
= convert_for_assignment (olhstype
, newrhs
, "assignment",
5995 newrhs
= convert_force (lhstype
, newrhs
, 0);
5998 newrhs
= convert_for_assignment (lhstype
, newrhs
, "assignment",
6000 if (flag_elide_constructors
== 0
6001 && TREE_CODE (newrhs
) == CALL_EXPR
6002 && TREE_ADDRESSABLE (lhstype
))
6004 /* Can't initialized directly from a CALL_EXPR, since
6005 we don't know about what doesn't alias what. */
6007 tree temp
= get_temp_name (lhstype
, 0);
6008 newrhs
= build (COMPOUND_EXPR
, lhstype
,
6009 build_modify_expr (temp
, INIT_EXPR
, newrhs
),
6014 if (TREE_CODE (newrhs
) == ERROR_MARK
)
6015 return error_mark_node
;
6017 if (TREE_CODE (newrhs
) == COND_EXPR
)
6020 tree cond
= TREE_OPERAND (newrhs
, 0);
6022 if (TREE_SIDE_EFFECTS (lhs
))
6023 cond
= build_compound_expr (tree_cons
6025 build_tree_list (NULL_TREE
, cond
)));
6027 /* Cannot have two identical lhs on this one tree (result) as preexpand
6028 calls will rip them out and fill in RTL for them, but when the
6029 rtl is generated, the calls will only be in the first side of the
6030 condition, not on both, or before the conditional jump! (mrs) */
6031 lhs1
= break_out_calls (lhs
);
6034 /* If there's no change, the COND_EXPR behaves like any other rhs. */
6035 result
= build (modifycode
== NOP_EXPR
? MODIFY_EXPR
: INIT_EXPR
,
6036 lhstype
, lhs
, newrhs
);
6039 tree result_type
= TREE_TYPE (newrhs
);
6040 /* We have to convert each arm to the proper type because the
6041 types may have been munged by constant folding. */
6043 = build (COND_EXPR
, result_type
, cond
,
6044 build_modify_expr (lhs
, modifycode
,
6045 convert (result_type
,
6046 TREE_OPERAND (newrhs
, 1))),
6047 build_modify_expr (lhs1
, modifycode
,
6048 convert (result_type
,
6049 TREE_OPERAND (newrhs
, 2))));
6052 else if (modifycode
!= INIT_EXPR
&& TREE_CODE (newrhs
) == WITH_CLEANUP_EXPR
)
6054 tree cleanup
= TREE_OPERAND (newrhs
, 2);
6057 /* Finish up by running cleanups and having the "value" of the lhs. */
6058 tree exprlist
= tree_cons (NULL_TREE
, cleanup
,
6059 build_tree_list (NULL_TREE
, lhs
));
6060 newrhs
= TREE_OPERAND (newrhs
, 0);
6061 if (TREE_CODE (newrhs
) == TARGET_EXPR
)
6062 slot
= TREE_OPERAND (newrhs
, 0);
6063 else if (TREE_CODE (newrhs
) == ADDR_EXPR
)
6065 /* Bad but valid. */
6067 warning ("address taken of temporary object");
6070 my_friendly_abort (118);
6072 /* Copy the value computed in SLOT into LHS. */
6073 exprlist
= tree_cons (NULL_TREE
,
6074 build_modify_expr (lhs
, modifycode
, slot
),
6076 /* Evaluate the expression that needs CLEANUP. This will
6077 compute the value into SLOT. */
6078 exprlist
= tree_cons (NULL_TREE
, newrhs
, exprlist
);
6079 result
= convert (lhstype
, build_compound_expr (exprlist
));
6082 result
= build (modifycode
== NOP_EXPR
? MODIFY_EXPR
: INIT_EXPR
,
6083 lhstype
, lhs
, newrhs
);
6084 TREE_SIDE_EFFECTS (result
) = 1;
6086 /* If we got the LHS in a different type for storing in,
6087 convert the result back to the nominal type of LHS
6088 so that the value we return always has the same type
6089 as the LHS argument. */
6091 if (olhstype
== TREE_TYPE (result
))
6093 /* Avoid warnings converting integral types back into enums
6094 for enum bit fields. */
6095 if (TREE_CODE (TREE_TYPE (result
)) == INTEGER_TYPE
6096 && TREE_CODE (olhstype
) == ENUMERAL_TYPE
)
6098 result
= build (COMPOUND_EXPR
, olhstype
, result
, olhs
);
6099 TREE_NO_UNUSED_WARNING (result
) = 1;
6102 return convert_for_assignment (olhstype
, result
, "assignment",
6107 /* Return 0 if EXP is not a valid lvalue in this language
6108 even though `lvalue_or_else' would accept it. */
6111 language_lvalue_valid (exp
)
6117 /* Get differnce in deltas for different pointer to member function
6118 types. Return inetger_zero_node, if FROM cannot be converted to a
6119 TO type. If FORCE is true, then allow reverse conversions as well. */
6121 get_delta_difference (from
, to
, force
)
6125 tree delta
= integer_zero_node
;
6131 /* Should get_base_distance here, so we can check if any thing along the
6132 path is virtual, and we need to make sure we stay
6133 inside the real binfos when going through virtual bases.
6134 Maybe we should replace virtual bases with
6135 binfo_member (...CLASSTYPE_VBASECLASSES...)... (mrs) */
6136 binfo
= get_binfo (from
, to
, 1);
6137 if (binfo
== error_mark_node
)
6139 error (" in pointer to member function conversion");
6146 error_not_base_type (from
, to
);
6147 error (" in pointer to member function conversion");
6150 binfo
= get_binfo (to
, from
, 1);
6151 if (binfo
== error_mark_node
)
6153 error (" in pointer to member function conversion");
6158 error ("cannot convert pointer to member of type %T to unrelated pointer to member of type %T", from
, to
);
6161 if (TREE_VIA_VIRTUAL (binfo
))
6163 warning ("pointer to member conversion to virtual base class will only work if your very careful");
6165 return build_binary_op (MINUS_EXPR
,
6167 BINFO_OFFSET (binfo
), 1);
6169 if (TREE_VIA_VIRTUAL (binfo
))
6171 warning ("pointer to member conversion from virtual base class will only work if your very careful");
6173 return BINFO_OFFSET (binfo
);
6176 /* Build a constructor for a pointer to member function. It can be
6177 used to initialize global variables, local variable, or used
6178 as a value in expressions. TYPE is the POINTER to METHOD_TYPE we
6181 If FORCE is non-zero, then force this conversion, even if
6182 we would rather not do it. Usually set when using an explicit
6185 Return error_mark_node, if something goes wrong. */
6188 build_ptrmemfunc (type
, pfn
, force
)
6192 tree index
= integer_zero_node
;
6193 tree delta
= integer_zero_node
;
6194 tree delta2
= integer_zero_node
;
6199 /* Handle multiple conversions of pointer to member fucntions. */
6200 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (pfn
)))
6202 tree ndelta
, ndelta2
, nindex
;
6203 /* Is is already the right type? */
6205 /* Sorry, can't do this, the backend is too stupid. */
6206 if (TYPE_METHOD_BASETYPE (TREE_TYPE (type
))
6207 == TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn
)))))
6209 if (type
!= TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn
)))
6211 npfn
= build1 (NOP_EXPR
, TYPE_GET_PTRMEMFUNC_TYPE (type
), pfn
);
6212 TREE_CONSTANT (npfn
) = TREE_CONSTANT (pfn
);
6217 if (type
== TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn
)))
6221 if (TREE_CODE (pfn
) != CONSTRUCTOR
)
6224 ndelta
= convert (ptrdiff_type_node
, build_component_ref (pfn
, delta_identifier
, 0, 0));
6225 ndelta2
= convert (ptrdiff_type_node
, DELTA2_FROM_PTRMEMFUNC (pfn
));
6226 index
= build_component_ref (pfn
, index_identifier
, 0, 0);
6227 delta
= get_delta_difference (TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn
)))),
6228 TYPE_METHOD_BASETYPE (TREE_TYPE (type
)),
6230 delta
= build_binary_op (PLUS_EXPR
, delta
, ndelta
, 1);
6231 delta2
= build_binary_op (PLUS_EXPR
, ndelta2
, delta2
, 1);
6232 e1
= fold (build (GT_EXPR
, integer_type_node
, index
, integer_zero_node
));
6234 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (delta2_identifier
, delta2
, NULL_TREE
));
6235 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (NULL_TREE
, delta
,
6236 tree_cons (NULL_TREE
, index
,
6237 tree_cons (NULL_TREE
, u
, NULL_TREE
))));
6238 e2
= digest_init (TYPE_GET_PTRMEMFUNC_TYPE (type
), u
, (tree
*)0);
6240 pfn
= PFN_FROM_PTRMEMFUNC (pfn
);
6241 npfn
= build1 (NOP_EXPR
, type
, pfn
);
6242 TREE_CONSTANT (npfn
) = TREE_CONSTANT (pfn
);
6244 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (pfn_identifier
, npfn
, NULL_TREE
));
6245 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (NULL_TREE
, delta
,
6246 tree_cons (NULL_TREE
, index
,
6247 tree_cons (NULL_TREE
, u
, NULL_TREE
))));
6248 e3
= digest_init (TYPE_GET_PTRMEMFUNC_TYPE (type
), u
, (tree
*)0);
6249 return build_conditional_expr (e1
, e2
, e3
);
6252 ndelta
= TREE_VALUE (CONSTRUCTOR_ELTS (pfn
));
6253 nindex
= TREE_VALUE (TREE_CHAIN (CONSTRUCTOR_ELTS (pfn
)));
6254 npfn
= TREE_VALUE (TREE_CHAIN (TREE_CHAIN (CONSTRUCTOR_ELTS (pfn
))));
6255 npfn
= TREE_VALUE (CONSTRUCTOR_ELTS (npfn
));
6256 if (integer_zerop (nindex
))
6257 pfn
= integer_zero_node
;
6260 sorry ("value casting of varible nonnull pointer to member functions not supported");
6261 return error_mark_node
;
6265 /* Handle null pointer to member function conversions. */
6266 if (integer_zerop (pfn
))
6268 pfn
= build_c_cast (type
, integer_zero_node
, 0);
6269 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (pfn_identifier
, pfn
, NULL_TREE
));
6270 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (NULL_TREE
, integer_zero_node
,
6271 tree_cons (NULL_TREE
, integer_zero_node
,
6272 tree_cons (NULL_TREE
, u
, NULL_TREE
))));
6273 return digest_init (TYPE_GET_PTRMEMFUNC_TYPE (type
), u
, (tree
*)0);
6276 if (TREE_CODE (pfn
) == TREE_LIST
6277 || (TREE_CODE (pfn
) == ADDR_EXPR
6278 && TREE_CODE (TREE_OPERAND (pfn
, 0)) == TREE_LIST
))
6280 pfn
= instantiate_type (type
, pfn
, 1);
6281 if (pfn
== error_mark_node
)
6282 return error_mark_node
;
6283 if (TREE_CODE (pfn
) != ADDR_EXPR
)
6284 pfn
= build_unary_op (ADDR_EXPR
, pfn
, 0);
6287 /* Allow pointer to member conversions here. */
6288 delta
= get_delta_difference (TYPE_METHOD_BASETYPE (TREE_TYPE (TREE_TYPE (pfn
))),
6289 TYPE_METHOD_BASETYPE (TREE_TYPE (type
)),
6291 delta2
= build_binary_op (PLUS_EXPR
, delta2
, delta
, 1);
6293 if (TREE_CODE (TREE_OPERAND (pfn
, 0)) != FUNCTION_DECL
)
6294 warning ("assuming pointer to member function is non-virtual");
6296 if (TREE_CODE (TREE_OPERAND (pfn
, 0)) == FUNCTION_DECL
6297 && DECL_VINDEX (TREE_OPERAND (pfn
, 0)))
6299 /* Find the offset to the vfield pointer in the object. */
6300 vfield_offset
= get_binfo (DECL_CONTEXT (TREE_OPERAND (pfn
, 0)),
6301 DECL_CLASS_CONTEXT (TREE_OPERAND (pfn
, 0)),
6303 vfield_offset
= get_vfield_offset (vfield_offset
);
6304 delta2
= size_binop (PLUS_EXPR
, vfield_offset
, delta2
);
6306 /* Map everything down one to make room for the null pointer to member. */
6307 index
= size_binop (PLUS_EXPR
,
6308 DECL_VINDEX (TREE_OPERAND (pfn
, 0)),
6310 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (delta2_identifier
, delta2
, NULL_TREE
));
6314 index
= size_binop (MINUS_EXPR
, integer_zero_node
, integer_one_node
);
6316 npfn
= build1 (NOP_EXPR
, type
, pfn
);
6317 TREE_CONSTANT (npfn
) = TREE_CONSTANT (pfn
);
6319 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (pfn_identifier
, npfn
, NULL_TREE
));
6322 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (NULL_TREE
, delta
,
6323 tree_cons (NULL_TREE
, index
,
6324 tree_cons (NULL_TREE
, u
, NULL_TREE
))));
6325 return digest_init (TYPE_GET_PTRMEMFUNC_TYPE (type
), u
, (tree
*)0);
6328 /* Convert value RHS to type TYPE as preparation for an assignment
6329 to an lvalue of type TYPE.
6330 The real work of conversion is done by `convert'.
6331 The purpose of this function is to generate error messages
6332 for assignments that are not allowed in C.
6333 ERRTYPE is a string to use in error messages:
6334 "assignment", "return", etc.
6336 C++: attempts to allow `convert' to find conversions involving
6337 implicit type conversion between aggregate and scalar types
6338 as per 8.5.6 of C++ manual. Does not randomly dereference
6339 pointers to aggregates! */
6342 convert_for_assignment (type
, rhs
, errtype
, fndecl
, parmnum
)
6348 register enum tree_code codel
= TREE_CODE (type
);
6349 register tree rhstype
;
6350 register enum tree_code coder
= TREE_CODE (TREE_TYPE (rhs
));
6352 if (coder
== UNKNOWN_TYPE
)
6353 rhs
= instantiate_type (type
, rhs
, 1);
6355 if (coder
== ERROR_MARK
)
6356 return error_mark_node
;
6358 if (codel
== OFFSET_TYPE
)
6360 type
= TREE_TYPE (type
);
6361 codel
= TREE_CODE (type
);
6364 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
6365 if (TREE_CODE (rhs
) == NON_LVALUE_EXPR
)
6366 rhs
= TREE_OPERAND (rhs
, 0);
6368 if (rhs
== error_mark_node
)
6369 return error_mark_node
;
6371 if (TREE_VALUE (rhs
) == error_mark_node
)
6372 return error_mark_node
;
6374 if (TREE_CODE (TREE_TYPE (rhs
)) == OFFSET_TYPE
)
6376 rhs
= resolve_offset_ref (rhs
);
6377 if (rhs
== error_mark_node
)
6378 return error_mark_node
;
6379 rhstype
= TREE_TYPE (rhs
);
6380 coder
= TREE_CODE (rhstype
);
6383 if (TREE_CODE (TREE_TYPE (rhs
)) == ARRAY_TYPE
6384 || TREE_CODE (TREE_TYPE (rhs
)) == FUNCTION_TYPE
6385 || TREE_CODE (TREE_TYPE (rhs
)) == METHOD_TYPE
)
6386 rhs
= default_conversion (rhs
);
6387 else if (TREE_CODE (TREE_TYPE (rhs
)) == REFERENCE_TYPE
)
6388 rhs
= convert_from_reference (rhs
);
6390 rhstype
= TREE_TYPE (rhs
);
6391 coder
= TREE_CODE (rhstype
);
6393 /* This should no longer change types on us. */
6394 if (TREE_CODE (rhs
) == CONST_DECL
)
6395 rhs
= DECL_INITIAL (rhs
);
6396 else if (TREE_READONLY_DECL_P (rhs
))
6397 rhs
= decl_constant_value (rhs
);
6399 if (type
== rhstype
)
6401 overflow_warning (rhs
);
6405 if (coder
== VOID_TYPE
)
6407 error ("void value not ignored as it ought to be");
6408 return error_mark_node
;
6410 /* Arithmetic types all interconvert. */
6411 if ((codel
== INTEGER_TYPE
|| codel
== REAL_TYPE
|| codel
== BOOLEAN_TYPE
)
6412 && (coder
== INTEGER_TYPE
|| coder
== REAL_TYPE
|| coder
== BOOLEAN_TYPE
))
6414 /* But we should warn if assigning REAL_TYPE to INTEGER_TYPE. */
6415 if (coder
== REAL_TYPE
&& codel
== INTEGER_TYPE
)
6418 cp_warning ("`%T' used for argument %P of `%D'",
6419 rhstype
, parmnum
, fndecl
);
6421 cp_warning ("%s to `%T' from `%T'", errtype
, type
, rhstype
);
6423 /* And we should warn if assigning a negative value to
6424 an unsigned variable. */
6425 else if (TREE_UNSIGNED (type
) && codel
!= BOOLEAN_TYPE
)
6427 if (TREE_CODE (rhs
) == INTEGER_CST
6428 && TREE_NEGATED_INT (rhs
))
6431 cp_warning ("negative value `%E' passed as argument %P of `%D'",
6432 rhs
, parmnum
, fndecl
);
6434 cp_warning ("%s of negative value `%E' to `%T'",
6435 errtype
, rhs
, type
);
6437 overflow_warning (rhs
);
6438 if (TREE_CONSTANT (rhs
))
6442 return convert_and_check (type
, rhs
);
6444 /* Conversions involving enums. */
6445 else if ((codel
== ENUMERAL_TYPE
6446 && (INTEGRAL_CODE_P (coder
) || coder
== REAL_TYPE
))
6447 || (coder
== ENUMERAL_TYPE
6448 && (INTEGRAL_CODE_P (codel
) || codel
== REAL_TYPE
)))
6450 return cp_convert (type
, rhs
, CONV_IMPLICIT
, 0);
6452 /* Conversions among pointers */
6453 else if (codel
== POINTER_TYPE
6454 && (coder
== POINTER_TYPE
6455 || (coder
== RECORD_TYPE
6456 && (IS_SIGNATURE_POINTER (rhstype
)
6457 || IS_SIGNATURE_REFERENCE (rhstype
)))))
6459 register tree ttl
= TREE_TYPE (type
);
6463 if (coder
== RECORD_TYPE
)
6465 rhs
= build_optr_ref (rhs
);
6466 rhstype
= TREE_TYPE (rhs
);
6468 ttr
= TREE_TYPE (rhstype
);
6470 /* If both pointers are of aggregate type, then we
6471 can give better error messages, and save some work
6473 if (TREE_CODE (ttl
) == RECORD_TYPE
&& TREE_CODE (ttr
) == RECORD_TYPE
)
6477 if (TYPE_MAIN_VARIANT (ttl
) == TYPE_MAIN_VARIANT (ttr
)
6478 || type
== class_star_type_node
6479 || rhstype
== class_star_type_node
)
6480 binfo
= TYPE_BINFO (ttl
);
6482 binfo
= get_binfo (ttl
, ttr
, 1);
6484 if (binfo
== error_mark_node
)
6485 return error_mark_node
;
6487 return error_not_base_type (ttl
, ttr
);
6489 if (! TYPE_READONLY (ttl
) && TYPE_READONLY (ttr
))
6492 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6493 rhstype
, parmnum
, fndecl
);
6495 cp_pedwarn ("%s to `%T' from `%T' discards const",
6496 errtype
, type
, rhstype
);
6498 if (! TYPE_VOLATILE (ttl
) && TYPE_VOLATILE (ttr
))
6501 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6502 rhstype
, parmnum
, fndecl
);
6504 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6505 errtype
, type
, rhstype
);
6509 /* Any non-function converts to a [const][volatile] void *
6510 and vice versa; otherwise, targets must be the same.
6511 Meanwhile, the lhs target must have all the qualifiers of the rhs. */
6512 else if (TYPE_MAIN_VARIANT (ttl
) == void_type_node
6513 || TYPE_MAIN_VARIANT (ttr
) == void_type_node
6514 || (ctt
= comp_target_types (type
, rhstype
, 1))
6515 || (unsigned_type (TYPE_MAIN_VARIANT (ttl
))
6516 == unsigned_type (TYPE_MAIN_VARIANT (ttr
))))
6518 /* ARM $4.8, commentary on p39. */
6519 if (TYPE_MAIN_VARIANT (ttl
) == void_type_node
6520 && TREE_CODE (ttr
) == OFFSET_TYPE
)
6522 cp_error ("no standard conversion from `%T' to `void *'", ttr
);
6523 return error_mark_node
;
6527 cp_pedwarn ("converting `%T' to `%T' is a contravariance violation",
6530 if (TYPE_MAIN_VARIANT (ttl
) != void_type_node
6531 && TYPE_MAIN_VARIANT (ttr
) == void_type_node
6532 && rhs
!= null_pointer_node
)
6534 if (coder
== RECORD_TYPE
)
6535 cp_pedwarn ("implicit conversion of signature pointer to type `%T'",
6538 pedwarn ("ANSI C++ forbids implicit conversion from `void *' in %s",
6541 /* Const and volatile mean something different for function types,
6542 so the usual warnings are not appropriate. */
6543 else if ((TREE_CODE (ttr
) != FUNCTION_TYPE
&& TREE_CODE (ttr
) != METHOD_TYPE
)
6544 || (TREE_CODE (ttl
) != FUNCTION_TYPE
&& TREE_CODE (ttl
) != METHOD_TYPE
))
6546 if (TREE_CODE (ttl
) == OFFSET_TYPE
6547 && binfo_member (TYPE_OFFSET_BASETYPE (ttr
),
6548 CLASSTYPE_VBASECLASSES (TYPE_OFFSET_BASETYPE (ttl
))))
6550 sorry ("%s between pointer to members converting across virtual baseclasses", errtype
);
6551 return error_mark_node
;
6553 else if (! TYPE_READONLY (ttl
) && TYPE_READONLY (ttr
))
6556 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6557 rhstype
, parmnum
, fndecl
);
6559 cp_pedwarn ("%s to `%T' from `%T' discards const",
6560 errtype
, type
, rhstype
);
6562 else if (! TYPE_VOLATILE (ttl
) && TYPE_VOLATILE (ttr
))
6565 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6566 rhstype
, parmnum
, fndecl
);
6568 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6569 errtype
, type
, rhstype
);
6571 else if (TREE_CODE (ttl
) == TREE_CODE (ttr
)
6572 && ! comp_target_types (type
, rhstype
, 1))
6575 cp_pedwarn ("passing `%T' as argument %P of `%D' changes signedness",
6576 rhstype
, parmnum
, fndecl
);
6578 cp_pedwarn ("%s to `%T' from `%T' changes signedness",
6579 errtype
, type
, rhstype
);
6583 else if (TREE_CODE (ttr
) == OFFSET_TYPE
6584 && TREE_CODE (ttl
) != OFFSET_TYPE
)
6586 /* Normally, pointers to different type codes (other
6587 than void) are not compatible, but we perform
6588 some type instantiation if that resolves the
6589 ambiguity of (X Y::*) and (X *). */
6591 if (current_class_decl
)
6593 if (TREE_CODE (rhs
) == INTEGER_CST
)
6595 rhs
= build (PLUS_EXPR
, build_pointer_type (TREE_TYPE (ttr
)),
6596 current_class_decl
, rhs
);
6597 return convert_for_assignment (type
, rhs
,
6598 errtype
, fndecl
, parmnum
);
6601 if (TREE_CODE (ttl
) == METHOD_TYPE
)
6602 error ("%s between pointer-to-method and pointer-to-member types",
6605 error ("%s between pointer and pointer-to-member types", errtype
);
6606 return error_mark_node
;
6610 int add_quals
= 0, const_parity
= 0, volatile_parity
= 0;
6612 int unsigned_parity
;
6615 /* This code is basically a duplicate of comp_ptr_ttypes_real. */
6616 for (; ; ttl
= TREE_TYPE (ttl
), ttr
= TREE_TYPE (ttr
))
6619 const_parity
|= TYPE_READONLY (ttl
) < TYPE_READONLY (ttr
);
6620 volatile_parity
|= TYPE_VOLATILE (ttl
) < TYPE_VOLATILE (ttr
);
6623 && (TYPE_READONLY (ttl
) > TYPE_READONLY (ttr
)
6624 || TYPE_VOLATILE (ttl
) > TYPE_VOLATILE (ttr
)))
6626 left_const
&= TYPE_READONLY (ttl
);
6628 if (TREE_CODE (ttl
) != POINTER_TYPE
6629 || TREE_CODE (ttr
) != POINTER_TYPE
)
6632 unsigned_parity
= TREE_UNSIGNED (ttl
) - TREE_UNSIGNED (ttr
);
6633 if (unsigned_parity
)
6635 if (TREE_UNSIGNED (ttl
))
6636 ttr
= unsigned_type (ttr
);
6638 ttl
= unsigned_type (ttl
);
6641 if (comp_target_types (ttl
, ttr
, nptrs
) > 0)
6646 cp_pedwarn ("passing `%T' as argument %P of `%D' adds cv-quals without intervening `const'",
6647 rhstype
, parmnum
, fndecl
);
6649 cp_pedwarn ("%s to `%T' from `%T' adds cv-quals without intervening `const'",
6650 errtype
, type
, rhstype
);
6655 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6656 rhstype
, parmnum
, fndecl
);
6658 cp_pedwarn ("%s to `%T' from `%T' discards const",
6659 errtype
, type
, rhstype
);
6661 if (volatile_parity
)
6664 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6665 rhstype
, parmnum
, fndecl
);
6667 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6668 errtype
, type
, rhstype
);
6670 if (unsigned_parity
> 0)
6673 cp_pedwarn ("passing `%T' as argument %P of `%D' changes signed to unsigned",
6674 rhstype
, parmnum
, fndecl
);
6676 cp_pedwarn ("%s to `%T' from `%T' changes signed to unsigned",
6677 errtype
, type
, rhstype
);
6679 else if (unsigned_parity
< 0)
6682 cp_pedwarn ("passing `%T' as argument %P of `%D' changes unsigned to signed",
6683 rhstype
, parmnum
, fndecl
);
6685 cp_pedwarn ("%s to `%T' from `%T' changes unsigned to signed",
6686 errtype
, type
, rhstype
);
6689 /* C++ is not so friendly about converting function and
6690 member function pointers as C. Emit warnings here. */
6691 if (TREE_CODE (ttl
) == FUNCTION_TYPE
6692 || TREE_CODE (ttl
) == METHOD_TYPE
)
6693 if (! comptypes (ttl
, ttr
, 0))
6695 warning ("conflicting function types in %s:", errtype
);
6696 cp_warning ("\t`%T' != `%T'", type
, rhstype
);
6699 else if (TREE_CODE (TREE_TYPE (rhs
)) == METHOD_TYPE
)
6701 /* When does this happen? */
6702 my_friendly_abort (119);
6703 /* Conversion of a pointer-to-member type to void *. */
6704 rhs
= build_unary_op (ADDR_EXPR
, rhs
, 0);
6705 TREE_TYPE (rhs
) = type
;
6708 else if (TREE_CODE (TREE_TYPE (rhs
)) == OFFSET_TYPE
)
6710 /* When does this happen? */
6711 my_friendly_abort (120);
6712 /* Conversion of a pointer-to-member type to void *. */
6713 rhs
= build_unary_op (ADDR_EXPR
, rhs
, 0);
6714 TREE_TYPE (rhs
) = type
;
6720 cp_error ("passing `%T' as argument %P of `%D'",
6721 rhstype
, parmnum
, fndecl
);
6723 cp_error ("%s to `%T' from `%T'", errtype
, type
, rhstype
);
6724 return error_mark_node
;
6727 return convert (type
, rhs
);
6729 else if (codel
== POINTER_TYPE
&& coder
== INTEGER_TYPE
)
6731 /* An explicit constant 0 can convert to a pointer,
6732 but not a 0 that results from casting or folding. */
6733 if (! (TREE_CODE (rhs
) == INTEGER_CST
&& integer_zerop (rhs
)))
6736 cp_pedwarn ("passing `%T' to argument %P of `%D' lacks a cast",
6737 rhstype
, parmnum
, fndecl
);
6739 cp_pedwarn ("%s to `%T' from `%T' lacks a cast",
6740 errtype
, type
, rhstype
);
6741 return convert (type
, rhs
);
6743 return null_pointer_node
;
6745 else if (codel
== INTEGER_TYPE
6746 && (coder
== POINTER_TYPE
6747 || (coder
== RECORD_TYPE
6748 && (IS_SIGNATURE_POINTER (rhstype
)
6749 || TYPE_PTRMEMFUNC_FLAG (rhstype
)
6750 || IS_SIGNATURE_REFERENCE (rhstype
)))))
6753 cp_pedwarn ("passing `%T' to argument %P of `%D' lacks a cast",
6754 rhstype
, parmnum
, fndecl
);
6756 cp_pedwarn ("%s to `%T' from `%T' lacks a cast",
6757 errtype
, type
, rhstype
);
6758 return convert (type
, rhs
);
6760 else if (codel
== BOOLEAN_TYPE
6761 && (coder
== POINTER_TYPE
6762 || (coder
== RECORD_TYPE
6763 && (IS_SIGNATURE_POINTER (rhstype
)
6764 || TYPE_PTRMEMFUNC_FLAG (rhstype
)
6765 || IS_SIGNATURE_REFERENCE (rhstype
)))))
6766 return convert (type
, rhs
);
6769 else if (((coder
== POINTER_TYPE
&& TREE_CODE (rhs
) == ADDR_EXPR
6770 && TREE_CODE (rhstype
) == POINTER_TYPE
6771 && TREE_CODE (TREE_TYPE (rhstype
)) == METHOD_TYPE
)
6772 || integer_zerop (rhs
)
6773 || TYPE_PTRMEMFUNC_P (TREE_TYPE (rhs
)))
6774 && TYPE_PTRMEMFUNC_P (type
))
6776 /* compatible pointer to member functions. */
6777 return build_ptrmemfunc (TYPE_PTRMEMFUNC_FN_TYPE (type
), rhs
, 0);
6779 else if (codel
== ERROR_MARK
|| coder
== ERROR_MARK
)
6780 return error_mark_node
;
6782 /* This should no longer happen. References are initialized via
6783 `convert_for_initialization'. They should otherwise be
6784 bashed before coming here. */
6785 else if (codel
== REFERENCE_TYPE
)
6786 my_friendly_abort (317);
6787 else if (TYPE_MAIN_VARIANT (type
) == TYPE_MAIN_VARIANT (TREE_TYPE (rhs
)))
6789 tree nrhs
= build1 (NOP_EXPR
, type
, rhs
);
6790 TREE_CONSTANT (nrhs
) = TREE_CONSTANT (rhs
);
6793 else if (TYPE_HAS_CONSTRUCTOR (type
) || IS_AGGR_TYPE (TREE_TYPE (rhs
)))
6794 return convert (type
, rhs
);
6796 cp_error ("%s to `%T' from `%T'", errtype
, type
, rhstype
);
6797 return error_mark_node
;
6800 /* Convert RHS to be of type TYPE. If EXP is non-zero,
6801 it is the target of the initialization.
6802 ERRTYPE is a string to use in error messages.
6804 Two major differences between the behavior of
6805 `convert_for_assignment' and `convert_for_initialization'
6806 are that references are bashed in the former, while
6807 copied in the latter, and aggregates are assigned in
6808 the former (operator=) while initialized in the
6811 If using constructor make sure no conversion operator exists, if one does
6812 exist, an ambiguity exists. */
6814 convert_for_initialization (exp
, type
, rhs
, flags
, errtype
, fndecl
, parmnum
)
6815 tree exp
, type
, rhs
;
6821 register enum tree_code codel
= TREE_CODE (type
);
6822 register tree rhstype
;
6823 register enum tree_code coder
;
6825 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
6826 Strip such NOP_EXPRs, since RHS is used in non-lvalue context. */
6827 if (TREE_CODE (rhs
) == NOP_EXPR
6828 && TREE_TYPE (rhs
) == TREE_TYPE (TREE_OPERAND (rhs
, 0))
6829 && codel
!= REFERENCE_TYPE
)
6830 rhs
= TREE_OPERAND (rhs
, 0);
6832 if (rhs
== error_mark_node
6833 || (TREE_CODE (rhs
) == TREE_LIST
&& TREE_VALUE (rhs
) == error_mark_node
))
6834 return error_mark_node
;
6836 if (TREE_CODE (TREE_TYPE (rhs
)) == OFFSET_TYPE
)
6838 rhs
= resolve_offset_ref (rhs
);
6839 if (rhs
== error_mark_node
)
6840 return error_mark_node
;
6843 if (TREE_CODE (TREE_TYPE (rhs
)) == REFERENCE_TYPE
)
6844 rhs
= convert_from_reference (rhs
);
6846 if ((TREE_CODE (TREE_TYPE (rhs
)) == ARRAY_TYPE
6847 && TREE_CODE (type
) != ARRAY_TYPE
6848 && (TREE_CODE (type
) != REFERENCE_TYPE
6849 || TREE_CODE (TREE_TYPE (type
)) != ARRAY_TYPE
))
6850 || TREE_CODE (TREE_TYPE (rhs
)) == FUNCTION_TYPE
6851 || TREE_CODE (TREE_TYPE (rhs
)) == METHOD_TYPE
)
6852 rhs
= default_conversion (rhs
);
6854 rhstype
= TREE_TYPE (rhs
);
6855 coder
= TREE_CODE (rhstype
);
6857 if (coder
== UNKNOWN_TYPE
)
6859 rhs
= instantiate_type (type
, rhs
, 1);
6860 rhstype
= TREE_TYPE (rhs
);
6861 coder
= TREE_CODE (rhstype
);
6864 if (coder
== ERROR_MARK
)
6865 return error_mark_node
;
6868 /* This is *not* the quick way out! It is the way to disaster. */
6869 if (type
== rhstype
)
6873 /* We accept references to incomplete types, so we can
6874 return here before checking if RHS is of complete type. */
6876 if (codel
== REFERENCE_TYPE
)
6878 /* This should eventually happen in convert_arguments. */
6879 extern int warningcount
, errorcount
;
6883 savew
= warningcount
, savee
= errorcount
;
6884 rhs
= convert_to_reference (type
, rhs
, CONV_IMPLICIT
, flags
,
6885 exp
? exp
: error_mark_node
);
6888 if (warningcount
> savew
)
6889 cp_warning_at ("in passing argument %P of `%+D'", parmnum
, fndecl
);
6890 else if (errorcount
> savee
)
6891 cp_error_at ("in passing argument %P of `%+D'", parmnum
, fndecl
);
6896 rhs
= require_complete_type (rhs
);
6897 if (rhs
== error_mark_node
)
6898 return error_mark_node
;
6900 if (exp
!= 0) exp
= require_complete_type (exp
);
6901 if (exp
== error_mark_node
)
6902 return error_mark_node
;
6904 if (TREE_CODE (rhstype
) == REFERENCE_TYPE
)
6905 rhstype
= TREE_TYPE (rhstype
);
6907 if (TYPE_LANG_SPECIFIC (type
)
6908 && (IS_SIGNATURE_POINTER (type
) || IS_SIGNATURE_REFERENCE (type
)))
6909 return build_signature_pointer_constructor (type
, rhs
);
6911 if (IS_AGGR_TYPE (type
)
6912 && (TYPE_NEEDS_CONSTRUCTING (type
) || TREE_HAS_CONSTRUCTOR (rhs
)))
6914 if (TYPE_MAIN_VARIANT (type
) == TYPE_MAIN_VARIANT (rhstype
))
6916 /* This is sufficient to perform initialization. No need,
6917 apparently, to go through X(X&) to do first-cut
6918 initialization. Return through a TARGET_EXPR so that we get
6919 cleanups if it is used. */
6920 if (TREE_CODE (rhs
) == CALL_EXPR
)
6922 rhs
= build_cplus_new (type
, rhs
, 0);
6925 /* Handle the case of default parameter initialization and
6926 initialization of static variables. */
6927 else if (TREE_CODE (rhs
) == TARGET_EXPR
)
6929 else if (TREE_CODE (rhs
) == INDIRECT_REF
&& TREE_HAS_CONSTRUCTOR (rhs
))
6931 my_friendly_assert (TREE_CODE (TREE_OPERAND (rhs
, 0)) == CALL_EXPR
, 318);
6934 my_friendly_assert (TREE_VALUE (TREE_OPERAND (TREE_OPERAND (rhs
, 0), 1)) == NULL_TREE
, 316);
6935 TREE_VALUE (TREE_OPERAND (TREE_OPERAND (rhs
, 0), 1))
6936 = build_unary_op (ADDR_EXPR
, exp
, 0);
6939 rhs
= build_cplus_new (type
, TREE_OPERAND (rhs
, 0), 0);
6943 if (TYPE_MAIN_VARIANT (type
) == TYPE_MAIN_VARIANT (rhstype
)
6944 || (IS_AGGR_TYPE (rhstype
) && UNIQUELY_DERIVED_FROM_P (type
, rhstype
)))
6946 if (TYPE_HAS_INIT_REF (type
))
6948 tree init
= build_method_call (exp
, constructor_name_full (type
),
6949 build_tree_list (NULL_TREE
, rhs
),
6950 TYPE_BINFO (type
), LOOKUP_NORMAL
);
6952 if (init
== error_mark_node
)
6953 return error_mark_node
;
6957 exp
= build_cplus_new (type
, init
, 0);
6961 return build (COMPOUND_EXPR
, type
, init
, exp
);
6964 /* ??? The following warnings are turned off because
6965 this is another place where the default X(X&) constructor
6967 if (TYPE_HAS_ASSIGNMENT (type
))
6968 cp_warning ("bitwise copy: `%T' defines operator=", type
);
6970 if (TREE_CODE (TREE_TYPE (rhs
)) == REFERENCE_TYPE
)
6971 rhs
= convert_from_reference (rhs
);
6972 if (type
!= rhstype
)
6974 tree nrhs
= build1 (NOP_EXPR
, type
, rhs
);
6975 TREE_CONSTANT (nrhs
) = TREE_CONSTANT (rhs
);
6981 return convert (type
, rhs
);
6984 if (type
== TREE_TYPE (rhs
))
6986 if (TREE_READONLY_DECL_P (rhs
))
6987 rhs
= decl_constant_value (rhs
);
6991 return convert_for_assignment (type
, rhs
, errtype
, fndecl
, parmnum
);
6994 /* Expand an ASM statement with operands, handling output operands
6995 that are not variables or INDIRECT_REFS by transforming such
6996 cases into cases that expand_asm_operands can handle.
6998 Arguments are same as for expand_asm_operands.
7000 We don't do default conversions on all inputs, because it can screw
7001 up operands that are expected to be in memory. */
7004 c_expand_asm_operands (string
, outputs
, inputs
, clobbers
, vol
, filename
, line
)
7005 tree string
, outputs
, inputs
, clobbers
;
7010 int noutputs
= list_length (outputs
);
7012 /* o[I] is the place that output number I should be written. */
7013 register tree
*o
= (tree
*) alloca (noutputs
* sizeof (tree
));
7016 /* Record the contents of OUTPUTS before it is modified. */
7017 for (i
= 0, tail
= outputs
; tail
; tail
= TREE_CHAIN (tail
), i
++)
7018 o
[i
] = TREE_VALUE (tail
);
7020 /* Generate the ASM_OPERANDS insn;
7021 store into the TREE_VALUEs of OUTPUTS some trees for
7022 where the values were actually stored. */
7023 expand_asm_operands (string
, outputs
, inputs
, clobbers
, vol
, filename
, line
);
7025 /* Copy all the intermediate outputs into the specified outputs. */
7026 for (i
= 0, tail
= outputs
; tail
; tail
= TREE_CHAIN (tail
), i
++)
7028 if (o
[i
] != TREE_VALUE (tail
))
7030 expand_expr (build_modify_expr (o
[i
], NOP_EXPR
, TREE_VALUE (tail
)),
7031 const0_rtx
, VOIDmode
, 0);
7034 /* Detect modification of read-only values.
7035 (Otherwise done by build_modify_expr.) */
7038 tree type
= TREE_TYPE (o
[i
]);
7039 if (TYPE_READONLY (type
)
7040 || ((TREE_CODE (type
) == RECORD_TYPE
7041 || TREE_CODE (type
) == UNION_TYPE
)
7042 && C_TYPE_FIELDS_READONLY (type
)))
7043 readonly_error (o
[i
], "modification by `asm'", 1);
7047 /* Those MODIFY_EXPRs could do autoincrements. */
7051 /* Expand a C `return' statement.
7052 RETVAL is the expression for what to return,
7053 or a null pointer for `return;' with no value.
7055 C++: upon seeing a `return', we must call destructors on all
7056 variables in scope which had constructors called on them.
7057 This means that if in a destructor, the base class destructors
7058 must be called before returning.
7060 The RETURN statement in C++ has initialization semantics. */
7063 c_expand_return (retval
)
7066 extern struct nesting
*cond_stack
, *loop_stack
, *case_stack
;
7067 extern tree dtor_label
, ctor_label
;
7068 tree result
= DECL_RESULT (current_function_decl
);
7069 tree valtype
= TREE_TYPE (result
);
7070 register int use_temp
= 0;
7071 int returns_value
= 1;
7073 if (TREE_THIS_VOLATILE (current_function_decl
))
7074 warning ("function declared `noreturn' has a `return' statement");
7076 if (retval
== error_mark_node
)
7078 current_function_returns_null
= 1;
7082 if (retval
== NULL_TREE
)
7084 /* A non-named return value does not count. */
7086 /* Can't just return from a destructor. */
7089 expand_goto (dtor_label
);
7093 if (DECL_CONSTRUCTOR_P (current_function_decl
))
7094 retval
= current_class_decl
;
7095 else if (DECL_NAME (result
) != NULL_TREE
7096 && TREE_CODE (valtype
) != VOID_TYPE
)
7100 current_function_returns_null
= 1;
7102 if (valtype
!= NULL_TREE
&& TREE_CODE (valtype
) != VOID_TYPE
)
7104 if (DECL_NAME (DECL_RESULT (current_function_decl
)) == NULL_TREE
)
7106 pedwarn ("`return' with no value, in function returning non-void");
7107 /* Clear this, so finish_function won't say that we
7108 reach the end of a non-void function (which we don't,
7109 we gave a return!). */
7110 current_function_returns_null
= 0;
7114 expand_null_return ();
7118 else if (DECL_CONSTRUCTOR_P (current_function_decl
)
7119 && retval
!= current_class_decl
)
7121 error ("return from a constructor: use `this = ...' instead");
7122 retval
= current_class_decl
;
7125 if (valtype
== NULL_TREE
|| TREE_CODE (valtype
) == VOID_TYPE
)
7127 current_function_returns_null
= 1;
7128 /* We do this here so we'll avoid a warning about how the function
7129 "may or may not return a value" in finish_function. */
7133 pedwarn ("`return' with a value, in function returning void");
7134 expand_return (retval
);
7136 /* Add some useful error checking for C++. */
7137 else if (TREE_CODE (valtype
) == REFERENCE_TYPE
)
7139 tree whats_returned
;
7140 tree tmp_result
= result
;
7142 /* Don't initialize directly into a non-BLKmode retval, since that
7143 could lose when being inlined by another caller. (GCC can't
7144 read the function return register in an inline function when
7145 the return value is being ignored). */
7146 if (result
&& TYPE_MODE (TREE_TYPE (tmp_result
)) != BLKmode
)
7149 /* convert to reference now, so we can give error if we
7150 return an reference to a non-lvalue. */
7151 retval
= convert_for_initialization (tmp_result
, valtype
, retval
,
7152 LOOKUP_NORMAL
, "return",
7155 /* Sort through common things to see what it is
7156 we are returning. */
7157 whats_returned
= retval
;
7158 if (TREE_CODE (whats_returned
) == COMPOUND_EXPR
)
7160 whats_returned
= TREE_OPERAND (whats_returned
, 1);
7161 if (TREE_CODE (whats_returned
) == ADDR_EXPR
)
7162 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7164 if (TREE_CODE (whats_returned
) == ADDR_EXPR
)
7166 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7167 while (TREE_CODE (whats_returned
) == NEW_EXPR
7168 || TREE_CODE (whats_returned
) == TARGET_EXPR
7169 || TREE_CODE (whats_returned
) == WITH_CLEANUP_EXPR
)
7171 /* Get the target. */
7172 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7173 warning ("returning reference to temporary");
7177 if (TREE_CODE (whats_returned
) == VAR_DECL
&& DECL_NAME (whats_returned
))
7179 if (TEMP_NAME_P (DECL_NAME (whats_returned
)))
7180 warning ("reference to non-lvalue returned");
7181 else if (! TREE_STATIC (whats_returned
)
7182 && IDENTIFIER_LOCAL_VALUE (DECL_NAME (whats_returned
)))
7183 cp_warning_at ("reference to local variable `%D' returned", whats_returned
);
7186 else if (TREE_CODE (retval
) == ADDR_EXPR
)
7188 tree whats_returned
= TREE_OPERAND (retval
, 0);
7190 if (TREE_CODE (whats_returned
) == VAR_DECL
7191 && DECL_NAME (whats_returned
)
7192 && IDENTIFIER_LOCAL_VALUE (DECL_NAME (whats_returned
))
7193 && !TREE_STATIC (whats_returned
))
7194 cp_warning_at ("address of local variable `%D' returned", whats_returned
);
7197 /* Now deal with possible C++ hair:
7198 (1) Compute the return value.
7199 (2) If there are aggregate values with destructors which
7200 must be cleaned up, clean them (taking care
7201 not to clobber the return value).
7202 (3) If an X(X&) constructor is defined, the return
7203 value must be returned via that. */
7205 if (retval
== result
7206 /* Watch out for constructors, which "return" aggregates
7207 via initialization, but which otherwise "return" a pointer. */
7208 || DECL_CONSTRUCTOR_P (current_function_decl
))
7210 /* This is just an error--it's already been reported. */
7211 if (TYPE_SIZE (valtype
) == NULL_TREE
)
7214 if (TYPE_MODE (valtype
) != BLKmode
7215 && any_pending_cleanups (1))
7217 retval
= get_temp_regvar (valtype
, retval
);
7218 use_temp
= obey_regdecls
;
7221 else if (IS_AGGR_TYPE (valtype
) && TYPE_NEEDS_CONSTRUCTING (valtype
))
7223 /* Throw away the cleanup that `build_functional_cast' gave us. */
7224 if (TREE_CODE (retval
) == WITH_CLEANUP_EXPR
7225 && TREE_CODE (TREE_OPERAND (retval
, 0)) == TARGET_EXPR
)
7226 retval
= TREE_OPERAND (retval
, 0);
7227 expand_aggr_init (result
, retval
, 0, LOOKUP_ONLYCONVERTING
);
7228 expand_cleanups_to (NULL_TREE
);
7229 DECL_INITIAL (result
) = NULL_TREE
;
7234 if (TYPE_MODE (valtype
) == VOIDmode
)
7236 if (TYPE_MODE (TREE_TYPE (result
)) != VOIDmode
7237 && warn_return_type
)
7238 warning ("return of void value in function returning non-void");
7239 expand_expr_stmt (retval
);
7243 else if (TYPE_MODE (valtype
) != BLKmode
7244 && any_pending_cleanups (1))
7246 retval
= get_temp_regvar (valtype
, retval
);
7247 expand_cleanups_to (NULL_TREE
);
7248 use_temp
= obey_regdecls
;
7253 retval
= convert_for_initialization (result
, valtype
, retval
,
7255 "return", NULL_TREE
, 0);
7256 DECL_INITIAL (result
) = NULL_TREE
;
7258 if (retval
== error_mark_node
)
7264 if (retval
!= NULL_TREE
7265 && TREE_CODE_CLASS (TREE_CODE (retval
)) == 'd'
7266 && cond_stack
== 0 && loop_stack
== 0 && case_stack
== 0)
7267 current_function_return_value
= retval
;
7271 /* Everything's great--RETVAL is in RESULT. */
7272 if (original_result_rtx
)
7274 store_expr (result
, original_result_rtx
, 0);
7275 expand_cleanups_to (NULL_TREE
);
7277 else if (retval
&& retval
!= result
)
7279 /* Clear this out so the later call to decl_function_context
7280 won't end up bombing on us. */
7281 if (DECL_CONTEXT (result
) == error_mark_node
)
7282 DECL_CONTEXT (result
) = NULL_TREE
;
7283 /* Here is where we finally get RETVAL into RESULT.
7284 `expand_return' does the magic of protecting
7285 RESULT from cleanups. */
7286 retval
= fold (build1 (CLEANUP_POINT_EXPR
, TREE_TYPE (result
),
7288 /* This part _must_ come second, because expand_return looks for
7289 the INIT_EXPR as the toplevel node only. :-( */
7290 retval
= build (INIT_EXPR
, TREE_TYPE (result
), result
, retval
);
7291 TREE_SIDE_EFFECTS (retval
) = 1;
7292 expand_return (retval
);
7295 expand_return (result
);
7297 use_variable (DECL_RTL (result
));
7298 if (ctor_label
&& TREE_CODE (ctor_label
) != ERROR_MARK
)
7299 expand_goto (ctor_label
);
7301 expand_null_return ();
7305 /* We may still need to put RETVAL into RESULT. */
7306 result
= DECL_RESULT (current_function_decl
);
7307 if (original_result_rtx
)
7309 /* Here we have a named return value that went
7310 into memory. We can compute RETVAL into that. */
7312 expand_assignment (result
, retval
, 0, 0);
7314 store_expr (result
, original_result_rtx
, 0);
7315 result
= make_tree (TREE_TYPE (result
), original_result_rtx
);
7317 else if (ctor_label
&& TREE_CODE (ctor_label
) != ERROR_MARK
)
7319 /* Here RETVAL is CURRENT_CLASS_DECL, so there's nothing to do. */
7320 expand_goto (ctor_label
);
7324 /* Here is where we finally get RETVAL into RESULT.
7325 `expand_return' does the magic of protecting
7326 RESULT from cleanups. */
7327 result
= build (INIT_EXPR
, TREE_TYPE (result
), result
, retval
);
7328 TREE_SIDE_EFFECTS (result
) = 1;
7329 expand_return (result
);
7331 else if (TYPE_MODE (TREE_TYPE (result
)) != VOIDmode
)
7332 expand_return (result
);
7335 current_function_returns_value
= returns_value
;
7337 /* These wind up after the BARRIER, which causes problems for
7338 expand_end_binding. What purpose were they supposed to serve? */
7339 if (original_result_rtx
)
7340 use_variable (original_result_rtx
);
7342 use_variable (DECL_RTL (DECL_RESULT (current_function_decl
)));
7345 /* One way to clear out cleanups that EXPR might
7346 generate. Note that this code will really be
7347 dead code, but that is ok--cleanups that were
7348 needed were handled by the magic of `return'. */
7349 expand_cleanups_to (NULL_TREE
);
7352 /* Start a C switch statement, testing expression EXP.
7353 Return EXP if it is valid, an error node otherwise. */
7356 c_expand_start_case (exp
)
7360 register enum tree_code code
;
7362 /* Convert from references, etc. */
7363 exp
= default_conversion (exp
);
7364 type
= TREE_TYPE (exp
);
7365 code
= TREE_CODE (type
);
7367 if (IS_AGGR_TYPE_CODE (code
))
7368 exp
= build_type_conversion (CONVERT_EXPR
, integer_type_node
, exp
, 1);
7370 if (exp
== NULL_TREE
)
7372 error ("switch quantity not an integer");
7373 exp
= error_mark_node
;
7375 type
= TREE_TYPE (exp
);
7376 code
= TREE_CODE (type
);
7378 if (code
!= INTEGER_TYPE
&& code
!= ENUMERAL_TYPE
&& code
!= ERROR_MARK
)
7380 error ("switch quantity not an integer");
7381 exp
= error_mark_node
;
7387 exp
= default_conversion (exp
);
7388 type
= TREE_TYPE (exp
);
7389 index
= get_unwidened (exp
, 0);
7390 /* We can't strip a conversion from a signed type to an unsigned,
7391 because if we did, int_fits_type_p would do the wrong thing
7392 when checking case values for being in range,
7393 and it's too hard to do the right thing. */
7394 if (TREE_UNSIGNED (TREE_TYPE (exp
))
7395 == TREE_UNSIGNED (TREE_TYPE (index
)))
7400 (1, fold (build1 (CLEANUP_POINT_EXPR
, TREE_TYPE (exp
), exp
)),
7401 type
, "switch statement");
7406 /* CONSTP remembers whether or not all the intervening pointers in the `to'
7407 type have been const. */
7409 comp_ptr_ttypes_real (to
, from
, constp
)
7413 for (; ; to
= TREE_TYPE (to
), from
= TREE_TYPE (from
))
7415 if (TREE_CODE (to
) != TREE_CODE (from
))
7418 if (TYPE_READONLY (from
) > TYPE_READONLY (to
)
7419 || TYPE_VOLATILE (from
) > TYPE_VOLATILE (to
))
7423 && (TYPE_READONLY (to
) > TYPE_READONLY (from
)
7424 || TYPE_VOLATILE (to
) > TYPE_READONLY (from
)))
7426 constp
&= TYPE_READONLY (to
);
7428 if (TREE_CODE (to
) != POINTER_TYPE
)
7429 return comptypes (TYPE_MAIN_VARIANT (to
), TYPE_MAIN_VARIANT (from
), 1);
7433 /* When comparing, say, char ** to char const **, this function takes the
7434 'char *' and 'char const *'. Do not pass non-pointer types to this
7437 comp_ptr_ttypes (to
, from
)
7440 return comp_ptr_ttypes_real (to
, from
, 1);