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 tt1
= TYPE_MAIN_VARIANT (TREE_TYPE (t1
));
373 tree tt2
= 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
));
382 else if ((IS_AGGR_TYPE_CODE (TREE_CODE (tt1
))
383 || TREE_CODE (tt1
) == OFFSET_TYPE
384 || TREE_CODE (tt1
) == METHOD_TYPE
)
385 && TREE_CODE (tt2
) == TREE_CODE (tt1
))
386 target
= common_type (tt1
, tt2
);
388 target
= void_type_node
;
390 target
= cp_build_type_variant (target
, constp
, volatilep
);
391 if (code1
== POINTER_TYPE
)
392 t1
= build_pointer_type (target
);
394 t1
= build_reference_type (target
);
395 return build_type_attribute_variant (t1
, attributes
);
399 t1
= build_pointer_type (common_type (TREE_TYPE (t1
), TREE_TYPE (t2
)));
400 return build_type_attribute_variant (t1
, attributes
);
403 t1
= build_reference_type (common_type (TREE_TYPE (t1
), TREE_TYPE (t2
)));
404 return build_type_attribute_variant (t1
, attributes
);
409 tree elt
= common_type (TREE_TYPE (t1
), TREE_TYPE (t2
));
410 /* Save space: see if the result is identical to one of the args. */
411 if (elt
== TREE_TYPE (t1
) && TYPE_DOMAIN (t1
))
412 return build_type_attribute_variant (t1
, attributes
);
413 if (elt
== TREE_TYPE (t2
) && TYPE_DOMAIN (t2
))
414 return build_type_attribute_variant (t2
, attributes
);
415 /* Merge the element types, and have a size if either arg has one. */
416 t1
= build_array_type (elt
, TYPE_DOMAIN (TYPE_DOMAIN (t1
) ? t1
: t2
));
417 return build_type_attribute_variant (t1
, attributes
);
421 /* Function types: prefer the one that specified arg types.
422 If both do, merge the arg types. Also merge the return types. */
424 tree valtype
= common_type (TREE_TYPE (t1
), TREE_TYPE (t2
));
425 tree p1
= TYPE_ARG_TYPES (t1
);
426 tree p2
= TYPE_ARG_TYPES (t2
);
429 /* Save space: see if the result is identical to one of the args. */
430 if (valtype
== TREE_TYPE (t1
) && ! p2
)
431 return build_type_attribute_variant (t1
, attributes
);
432 if (valtype
== TREE_TYPE (t2
) && ! p1
)
433 return build_type_attribute_variant (t2
, attributes
);
435 /* Simple way if one arg fails to specify argument types. */
436 if (p1
== NULL_TREE
|| TREE_VALUE (p1
) == void_type_node
)
438 rval
= build_function_type (valtype
, p2
);
439 if ((raises
= TYPE_RAISES_EXCEPTIONS (t2
)))
440 rval
= build_exception_variant (NULL_TREE
, rval
, raises
);
441 return build_type_attribute_variant (rval
, attributes
);
443 raises
= TYPE_RAISES_EXCEPTIONS (t1
);
444 if (p2
== NULL_TREE
|| TREE_VALUE (p2
) == void_type_node
)
446 rval
= build_function_type (valtype
, p1
);
448 rval
= build_exception_variant (NULL_TREE
, rval
, raises
);
449 return build_type_attribute_variant (rval
, attributes
);
452 rval
= build_function_type (valtype
, commonparms (p1
, p2
));
453 rval
= build_exception_variant (NULL_TREE
, rval
, raises
);
454 return build_type_attribute_variant (rval
, attributes
);
459 my_friendly_assert (TYPE_MAIN_VARIANT (t1
) == t1
460 && TYPE_MAIN_VARIANT (t2
) == t2
, 306);
462 if (DERIVED_FROM_P (t1
, t2
) && binfo_or_else (t1
, t2
))
463 return build_type_attribute_variant (t1
, attributes
);
464 else if (binfo_or_else (t2
, t1
))
465 return build_type_attribute_variant (t2
, attributes
);
467 compiler_error ("common_type called with uncommon aggregate types");
470 if (comptypes (TYPE_METHOD_BASETYPE (t1
), TYPE_METHOD_BASETYPE (t2
), 1)
471 && TREE_CODE (TREE_TYPE (t1
)) == TREE_CODE (TREE_TYPE (t2
)))
473 /* Get this value the long way, since TYPE_METHOD_BASETYPE
474 is just the main variant of this. */
475 tree basetype
= TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t1
)));
478 raises
= TYPE_RAISES_EXCEPTIONS (t1
);
480 /* If this was a member function type, get back to the
481 original type of type member function (i.e., without
482 the class instance variable up front. */
483 t1
= build_function_type (TREE_TYPE (t1
), TREE_CHAIN (TYPE_ARG_TYPES (t1
)));
484 t2
= build_function_type (TREE_TYPE (t2
), TREE_CHAIN (TYPE_ARG_TYPES (t2
)));
485 t3
= common_type (t1
, t2
);
486 t3
= build_cplus_method_type (basetype
, TREE_TYPE (t3
), TYPE_ARG_TYPES (t3
));
487 t1
= build_exception_variant (basetype
, t3
, raises
);
490 compiler_error ("common_type called with uncommon method types");
492 return build_type_attribute_variant (t1
, attributes
);
495 if (TREE_CODE (TREE_TYPE (t1
)) == TREE_CODE (TREE_TYPE (t2
)))
497 tree b1
= TYPE_OFFSET_BASETYPE (t1
);
498 tree b2
= TYPE_OFFSET_BASETYPE (t2
);
501 if (DERIVED_FROM_P (b1
, b2
) && binfo_or_else (b1
, b2
))
502 return build_type_attribute_variant (t1
, attributes
);
503 else if (binfo_or_else (b2
, b1
))
504 return build_type_attribute_variant (t2
, attributes
);
506 compiler_error ("common_type called with uncommon member types");
509 return build_type_attribute_variant (t1
, attributes
);
513 /* Return 1 if TYPE1 and TYPE2 raise the same exceptions. */
515 compexcepttypes (t1
, t2
, strict
)
519 return TYPE_RAISES_EXCEPTIONS (t1
) == TYPE_RAISES_EXCEPTIONS (t2
);
523 comp_array_types (cmp
, t1
, t2
, strict
)
524 register int (*cmp
)();
528 tree d1
= TYPE_DOMAIN (t1
);
529 tree d2
= TYPE_DOMAIN (t2
);
531 /* Target types must match incl. qualifiers. */
532 if (!(TREE_TYPE (t1
) == TREE_TYPE (t2
)
533 || (*cmp
) (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
)))
536 /* Sizes must match unless one is missing or variable. */
537 if (d1
== 0 || d2
== 0 || d1
== d2
538 || TREE_CODE (TYPE_MIN_VALUE (d1
)) != INTEGER_CST
539 || TREE_CODE (TYPE_MIN_VALUE (d2
)) != INTEGER_CST
540 || TREE_CODE (TYPE_MAX_VALUE (d1
)) != INTEGER_CST
541 || TREE_CODE (TYPE_MAX_VALUE (d2
)) != INTEGER_CST
)
544 return ((TREE_INT_CST_LOW (TYPE_MIN_VALUE (d1
))
545 == TREE_INT_CST_LOW (TYPE_MIN_VALUE (d2
)))
546 && (TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d1
))
547 == TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d2
)))
548 && (TREE_INT_CST_LOW (TYPE_MAX_VALUE (d1
))
549 == TREE_INT_CST_LOW (TYPE_MAX_VALUE (d2
)))
550 && (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d1
))
551 == TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d2
))));
554 /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
555 or various other operations. This is what ANSI C++ speaks of as
558 For C++: argument STRICT says we should be strict about this
561 2 : strict, except that if one type is a reference and
562 the other is not, compare the target type of the
563 reference to the type that's not a reference (ARM, p308).
564 This is used for checking for invalid overloading.
565 1 : strict (compared according to ANSI C)
566 This is used for checking whether two function decls match.
567 0 : <= (compared according to C++)
568 -1: <= or >= (relaxed)
570 Otherwise, pointers involving base classes and derived classes
571 can be mixed as valid: i.e. a pointer to a base class may be assigned
572 to a pointer to one of its derived classes, as per C++. A pointer to
573 a derived class may be passed as a parameter to a function expecting a
574 pointer to a base classes. These allowances do not commute. In this
575 case, TYPE1 is assumed to be the base class, and TYPE2 is assumed to
576 be the derived class. */
578 comptypes (type1
, type2
, strict
)
582 register tree t1
= type1
;
583 register tree t2
= type2
;
586 /* Suppress errors caused by previously reported errors */
591 /* This should never happen. */
592 my_friendly_assert (t1
!= error_mark_node
, 307);
594 if (t2
== error_mark_node
)
599 /* Treat an enum type as the unsigned integer type of the same width. */
601 if (TREE_CODE (t1
) == ENUMERAL_TYPE
)
602 t1
= type_for_size (TYPE_PRECISION (t1
), 1);
603 if (TREE_CODE (t2
) == ENUMERAL_TYPE
)
604 t2
= type_for_size (TYPE_PRECISION (t2
), 1);
610 /* Different classes of types can't be compatible. */
612 if (TREE_CODE (t1
) != TREE_CODE (t2
))
615 && ((TREE_CODE (t1
) == REFERENCE_TYPE
)
616 ^ (TREE_CODE (t2
) == REFERENCE_TYPE
)))
618 if (TREE_CODE (t1
) == REFERENCE_TYPE
)
619 return comptypes (TREE_TYPE (t1
), t2
, 1);
620 return comptypes (t1
, TREE_TYPE (t2
), 1);
628 /* Qualifiers must match. */
630 if (TYPE_READONLY (t1
) != TYPE_READONLY (t2
))
632 if (TYPE_VOLATILE (t1
) != TYPE_VOLATILE (t2
))
635 /* Allow for two different type nodes which have essentially the same
636 definition. Note that we already checked for equality of the type
637 type qualifiers (just above). */
639 if (TYPE_MAIN_VARIANT (t1
) == TYPE_MAIN_VARIANT (t2
))
642 #ifdef COMP_TYPE_ATTRIBUTES
643 if (! (attrval
= COMP_TYPE_ATTRIBUTES (t1
, t2
)))
646 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
650 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
653 switch (TREE_CODE (t1
))
662 val
= (comptypes (TYPE_POINTER_TO (TYPE_OFFSET_BASETYPE (t1
)),
663 TYPE_POINTER_TO (TYPE_OFFSET_BASETYPE (t2
)), strict
)
664 && comptypes (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
));
668 if (! compexcepttypes (t1
, t2
, strict
))
671 /* This case is anti-symmetrical!
672 One can pass a base member (or member function)
673 to something expecting a derived member (or member function),
674 but not vice-versa! */
676 val
= (comptypes (TYPE_POINTER_TO (TYPE_METHOD_BASETYPE (t2
)),
677 TYPE_POINTER_TO (TYPE_METHOD_BASETYPE (t1
)), strict
)
678 && comptypes (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
)
679 && compparms (TREE_CHAIN (TYPE_ARG_TYPES (t1
)),
680 TREE_CHAIN (TYPE_ARG_TYPES (t2
)), strict
));
694 if (TREE_CODE (t1
) == RECORD_TYPE
&& TREE_CODE (t2
) == RECORD_TYPE
)
698 rval
= t1
== t2
|| UNIQUELY_DERIVED_FROM_P (t1
, t2
);
707 val
= UNIQUELY_DERIVED_FROM_P (t2
, t1
);
714 val
= comptypes (t1
, t2
, strict
);
718 if (! compexcepttypes (t1
, t2
, strict
))
721 val
= ((TREE_TYPE (t1
) == TREE_TYPE (t2
)
722 || comptypes (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
))
723 && compparms (TYPE_ARG_TYPES (t1
), TYPE_ARG_TYPES (t2
), strict
));
727 /* Target types must match incl. qualifiers. */
728 val
= comp_array_types (comptypes
, t1
, t2
, strict
);
731 case TEMPLATE_TYPE_PARM
:
734 case UNINSTANTIATED_P_TYPE
:
735 if (UPT_TEMPLATE (t1
) != UPT_TEMPLATE (t2
))
738 int i
= TREE_VEC_LENGTH (UPT_PARMS (t1
));
739 tree
*p1
= &TREE_VEC_ELT (UPT_PARMS (t1
), 0);
740 tree
*p2
= &TREE_VEC_ELT (UPT_PARMS (t2
), 0);
744 if (TREE_CODE_CLASS (TREE_CODE (p1
[i
])) == 't')
746 if (! comptypes (p1
[i
], p2
[i
], 1))
751 if (simple_cst_equal (p1
[i
], p2
[i
]) <= 0)
758 return attrval
== 2 && val
== 1 ? 2 : val
;
761 /* Return 1 if TTL and TTR are pointers to types that are equivalent,
762 ignoring their qualifiers.
764 NPTRS is the number of pointers we can strip off and keep cool.
765 This is used to permit (for aggr A, aggr B) A, B* to convert to A*,
766 but to not permit B** to convert to A**. */
769 comp_target_types (ttl
, ttr
, nptrs
)
773 ttl
= TYPE_MAIN_VARIANT (ttl
);
774 ttr
= TYPE_MAIN_VARIANT (ttr
);
778 if (TREE_CODE (ttl
) == VOID_TYPE
779 && TREE_CODE (ttr
) != FUNCTION_TYPE
780 && TREE_CODE (ttr
) != METHOD_TYPE
781 && TREE_CODE (ttr
) != OFFSET_TYPE
)
783 if (TREE_CODE (ttr
) == VOID_TYPE
784 && TREE_CODE (ttl
) != FUNCTION_TYPE
785 && TREE_CODE (ttl
) != METHOD_TYPE
786 && TREE_CODE (ttl
) != OFFSET_TYPE
)
789 if (TREE_CODE (ttr
) != TREE_CODE (ttl
))
792 if (TREE_CODE (ttr
) == POINTER_TYPE
)
794 if (TREE_CODE (TREE_TYPE (ttl
)) == POINTER_TYPE
795 || TREE_CODE (TREE_TYPE (ttl
)) == ARRAY_TYPE
)
796 return comp_ptr_ttypes (TREE_TYPE (ttl
), TREE_TYPE (ttr
));
798 return comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), nptrs
- 1);
801 if (TREE_CODE (ttr
) == REFERENCE_TYPE
)
802 return comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), nptrs
);
803 if (TREE_CODE (ttr
) == ARRAY_TYPE
)
804 return comp_array_types (comp_target_types
, ttl
, ttr
, 0);
805 else if (TREE_CODE (ttr
) == FUNCTION_TYPE
|| TREE_CODE (ttr
) == METHOD_TYPE
)
806 if (comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), nptrs
))
807 switch (comp_target_parms (TYPE_ARG_TYPES (ttl
), TYPE_ARG_TYPES (ttr
), 1))
816 my_friendly_abort (112);
822 else if (TREE_CODE (ttr
) == OFFSET_TYPE
)
824 /* Contravariance: we can assign a pointer to base member to a pointer
825 to derived member. Note difference from simple pointer case, where
826 we can pass a pointer to derived to a pointer to base. */
827 if (comptypes (TYPE_OFFSET_BASETYPE (ttr
), TYPE_OFFSET_BASETYPE (ttl
), 0))
828 return comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), nptrs
);
829 else if (comptypes (TYPE_OFFSET_BASETYPE (ttl
), TYPE_OFFSET_BASETYPE (ttr
), 0)
830 && comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), nptrs
))
833 else if (IS_AGGR_TYPE (ttl
))
837 if (comptypes (TYPE_POINTER_TO (ttl
), TYPE_POINTER_TO (ttr
), 0))
839 if (comptypes (TYPE_POINTER_TO (ttr
), TYPE_POINTER_TO (ttl
), 0))
847 /* If two types share a common base type, return that basetype.
848 If there is not a unique most-derived base type, this function
849 returns ERROR_MARK_NODE. */
851 common_base_type (tt1
, tt2
)
854 tree best
= NULL_TREE
, tmp
;
857 /* If one is a baseclass of another, that's good enough. */
858 if (UNIQUELY_DERIVED_FROM_P (tt1
, tt2
))
860 if (UNIQUELY_DERIVED_FROM_P (tt2
, tt1
))
864 /* If they share a virtual baseclass, that's good enough. */
865 for (tmp
= CLASSTYPE_VBASECLASSES (tt1
); tmp
; tmp
= TREE_CHAIN (tmp
))
867 if (binfo_member (BINFO_TYPE (tmp
), CLASSTYPE_VBASECLASSES (tt2
)))
868 return BINFO_TYPE (tmp
);
872 /* Otherwise, try to find a unique baseclass of TT1
873 that is shared by TT2, and follow that down. */
874 for (i
= CLASSTYPE_N_BASECLASSES (tt1
)-1; i
>= 0; i
--)
876 tree basetype
= TYPE_BINFO_BASETYPE (tt1
, i
);
877 tree trial
= common_base_type (basetype
, tt2
);
880 if (trial
== error_mark_node
)
882 if (best
== NULL_TREE
)
884 else if (best
!= trial
)
885 return error_mark_node
;
890 for (i
= CLASSTYPE_N_BASECLASSES (tt2
)-1; i
>= 0; i
--)
892 tree basetype
= TYPE_BINFO_BASETYPE (tt2
, i
);
893 tree trial
= common_base_type (tt1
, basetype
);
896 if (trial
== error_mark_node
)
898 if (best
== NULL_TREE
)
900 else if (best
!= trial
)
901 return error_mark_node
;
907 /* Subroutines of `comptypes'. */
909 /* Return 1 if two parameter type lists PARMS1 and PARMS2
910 are equivalent in the sense that functions with those parameter types
911 can have equivalent types.
912 If either list is empty, we win.
913 Otherwise, the two lists must be equivalent, element by element.
915 C++: See comment above about TYPE1, TYPE2, STRICT.
916 If STRICT == 3, it means checking is strict, but do not compare
917 default parameter values. */
919 compparms (parms1
, parms2
, strict
)
923 register tree t1
= parms1
, t2
= parms2
;
925 /* An unspecified parmlist matches any specified parmlist
926 whose argument types don't need default promotions. */
928 if (strict
<= 0 && t1
== 0)
929 return self_promoting_args_p (t2
);
930 if (strict
< 0 && t2
== 0)
931 return self_promoting_args_p (t1
);
935 if (t1
== 0 && t2
== 0)
937 /* If one parmlist is shorter than the other,
938 they fail to match, unless STRICT is <= 0. */
939 if (t1
== 0 || t2
== 0)
946 return t1
&& TREE_PURPOSE (t1
);
948 if (! comptypes (TREE_VALUE (t2
), TREE_VALUE (t1
), strict
))
953 return t2
== void_list_node
&& TREE_PURPOSE (t1
);
954 return TREE_PURPOSE (t1
) || TREE_PURPOSE (t2
);
957 /* Default parms are not part of the type of a function. */
958 if (strict
!= 3 && TREE_PURPOSE (t1
) && TREE_PURPOSE (t2
))
960 int cmp
= simple_cst_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
));
962 my_friendly_abort (113);
968 t1
= TREE_CHAIN (t1
);
969 t2
= TREE_CHAIN (t2
);
973 /* This really wants return whether or not parameter type lists
974 would make their owning functions assignment compatible or not. */
976 comp_target_parms (parms1
, parms2
, strict
)
980 register tree t1
= parms1
, t2
= parms2
;
981 int warn_contravariance
= 0;
983 /* An unspecified parmlist matches any specified parmlist
984 whose argument types don't need default promotions.
985 @@@ see 13.3.3 for a counterexample... */
987 if (t1
== 0 && t2
!= 0)
989 cp_pedwarn ("ANSI C++ prohibits conversion from `(%#T)' to `(...)'",
991 return self_promoting_args_p (t2
);
994 return self_promoting_args_p (t1
);
996 for (; t1
|| t2
; t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
))
1000 /* If one parmlist is shorter than the other,
1001 they fail to match, unless STRICT is <= 0. */
1002 if (t1
== 0 || t2
== 0)
1007 return 1 + warn_contravariance
;
1008 return ((t1
&& TREE_PURPOSE (t1
)) + warn_contravariance
);
1010 p1
= TREE_VALUE (t1
);
1011 p2
= TREE_VALUE (t2
);
1015 if ((TREE_CODE (p1
) == POINTER_TYPE
&& TREE_CODE (p2
) == POINTER_TYPE
)
1016 || (TREE_CODE (p1
) == REFERENCE_TYPE
&& TREE_CODE (p2
) == REFERENCE_TYPE
))
1019 && (TYPE_MAIN_VARIANT (TREE_TYPE (p1
))
1020 == TYPE_MAIN_VARIANT (TREE_TYPE (p2
))))
1023 /* The following is wrong for contravariance,
1024 but many programs depend on it. */
1025 if (TREE_TYPE (p1
) == void_type_node
)
1027 if (TREE_TYPE (p2
) == void_type_node
)
1029 warn_contravariance
= 1;
1032 if (IS_AGGR_TYPE (TREE_TYPE (p1
)))
1034 if (comptypes (p2
, p1
, 0) == 0)
1036 if (comptypes (p1
, p2
, 0) != 0)
1037 warn_contravariance
= 1;
1044 /* Note backwards order due to contravariance. */
1045 if (comp_target_types (p2
, p1
, 1) == 0)
1047 if (comp_target_types (p1
, p2
, 1))
1049 warn_contravariance
= 1;
1055 /* What good do these cases do? */
1057 return p2
== void_type_node
&& TREE_PURPOSE (t1
);
1058 return TREE_PURPOSE (t1
) || TREE_PURPOSE (t2
);
1061 /* Target types are compatible--just make sure that if
1062 we use parameter lists, that they are ok as well. */
1063 if (TREE_CODE (p1
) == FUNCTION_TYPE
|| TREE_CODE (p1
) == METHOD_TYPE
)
1064 switch (comp_target_parms (TYPE_ARG_TYPES (p1
),
1065 TYPE_ARG_TYPES (p2
),
1073 warn_contravariance
= 1;
1076 if (TREE_PURPOSE (t1
) && TREE_PURPOSE (t2
))
1078 int cmp
= simple_cst_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
));
1080 my_friendly_abort (114);
1085 return 1 + warn_contravariance
;
1088 /* Return 1 if PARMS specifies a fixed number of parameters
1089 and none of their types is affected by default promotions. */
1092 self_promoting_args_p (parms
)
1096 for (t
= parms
; t
; t
= TREE_CHAIN (t
))
1098 register tree type
= TREE_VALUE (t
);
1100 if (TREE_CHAIN (t
) == 0 && type
!= void_type_node
)
1103 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
1109 if (C_PROMOTING_INTEGER_TYPE_P (type
))
1115 /* Return an unsigned type the same as TYPE in other respects.
1117 C++: must make these work for type variants as well. */
1120 unsigned_type (type
)
1123 tree type1
= TYPE_MAIN_VARIANT (type
);
1124 if (type1
== signed_char_type_node
|| type1
== char_type_node
)
1125 return unsigned_char_type_node
;
1126 if (type1
== integer_type_node
)
1127 return unsigned_type_node
;
1128 if (type1
== short_integer_type_node
)
1129 return short_unsigned_type_node
;
1130 if (type1
== long_integer_type_node
)
1131 return long_unsigned_type_node
;
1132 if (type1
== long_long_integer_type_node
)
1133 return long_long_unsigned_type_node
;
1137 /* Return a signed type the same as TYPE in other respects. */
1143 tree type1
= TYPE_MAIN_VARIANT (type
);
1144 if (type1
== unsigned_char_type_node
|| type1
== char_type_node
)
1145 return signed_char_type_node
;
1146 if (type1
== unsigned_type_node
)
1147 return integer_type_node
;
1148 if (type1
== short_unsigned_type_node
)
1149 return short_integer_type_node
;
1150 if (type1
== long_unsigned_type_node
)
1151 return long_integer_type_node
;
1152 if (type1
== long_long_unsigned_type_node
)
1153 return long_long_integer_type_node
;
1157 /* Return a type the same as TYPE except unsigned or
1158 signed according to UNSIGNEDP. */
1161 signed_or_unsigned_type (unsignedp
, type
)
1165 if (! INTEGRAL_TYPE_P (type
))
1167 if (TYPE_PRECISION (type
) == TYPE_PRECISION (signed_char_type_node
))
1168 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
1169 if (TYPE_PRECISION (type
) == TYPE_PRECISION (integer_type_node
))
1170 return unsignedp
? unsigned_type_node
: integer_type_node
;
1171 if (TYPE_PRECISION (type
) == TYPE_PRECISION (short_integer_type_node
))
1172 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
1173 if (TYPE_PRECISION (type
) == TYPE_PRECISION (long_integer_type_node
))
1174 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
1175 if (TYPE_PRECISION (type
) == TYPE_PRECISION (long_long_integer_type_node
))
1176 return (unsignedp
? long_long_unsigned_type_node
1177 : long_long_integer_type_node
);
1185 enum tree_code code
= TREE_CODE (type
);
1188 if (code
== FUNCTION_TYPE
)
1190 if (pedantic
|| warn_pointer_arith
)
1191 pedwarn ("ANSI C++ forbids taking the sizeof a function type");
1192 return size_int (1);
1194 if (code
== METHOD_TYPE
)
1196 if (pedantic
|| warn_pointer_arith
)
1197 pedwarn ("ANSI C++ forbids taking the sizeof a method type");
1198 return size_int (1);
1200 if (code
== VOID_TYPE
)
1202 if (pedantic
|| warn_pointer_arith
)
1203 pedwarn ("ANSI C++ forbids taking the sizeof a void type");
1204 return size_int (1);
1206 if (code
== ERROR_MARK
)
1207 return size_int (1);
1209 /* ARM $5.3.2: ``When applied to a reference, the result is the size of the
1210 referenced object.'' */
1211 if (code
== REFERENCE_TYPE
)
1212 type
= TREE_TYPE (type
);
1214 /* We couldn't find anything in the ARM or the draft standard that says,
1215 one way or the other, if doing sizeof on something that doesn't have
1216 an object associated with it is correct or incorrect. For example, if
1217 you declare `struct S { char str[16]; };', and in your program do
1218 a `sizeof (S::str)', should we flag that as an error or should we give
1219 the size of it? Since it seems like a reasonable thing to do, we'll go
1220 with giving the value. */
1221 if (code
== OFFSET_TYPE
)
1222 type
= TREE_TYPE (type
);
1224 /* @@ This also produces an error for a signature ref.
1225 In that case we should be able to do better. */
1226 if (IS_SIGNATURE (type
))
1228 error ("`sizeof' applied to a signature type");
1229 return size_int (0);
1232 if (TYPE_SIZE (type
) == 0)
1234 error ("`sizeof' applied to an incomplete type");
1235 return size_int (0);
1238 /* Convert in case a char is more than one unit. */
1239 t
= size_binop (CEIL_DIV_EXPR
, TYPE_SIZE (type
),
1240 size_int (TYPE_PRECISION (char_type_node
)));
1241 /* size_binop does not put the constant in range, so do it now. */
1242 if (TREE_CODE (t
) == INTEGER_CST
&& force_fit_type (t
, 0))
1243 TREE_CONSTANT_OVERFLOW (t
) = TREE_OVERFLOW (t
) = 1;
1248 c_sizeof_nowarn (type
)
1251 enum tree_code code
= TREE_CODE (type
);
1254 if (code
== FUNCTION_TYPE
1255 || code
== METHOD_TYPE
1256 || code
== VOID_TYPE
1257 || code
== ERROR_MARK
)
1258 return size_int (1);
1259 if (code
== REFERENCE_TYPE
)
1260 type
= TREE_TYPE (type
);
1262 if (TYPE_SIZE (type
) == 0)
1265 /* ??? Tiemann, why have any diagnostic here?
1266 There is none in the corresponding function for C. */
1267 warning ("sizeof applied to an incomplete type");
1269 return size_int (0);
1272 /* Convert in case a char is more than one unit. */
1273 t
= size_binop (CEIL_DIV_EXPR
, TYPE_SIZE (type
),
1274 size_int (TYPE_PRECISION (char_type_node
)));
1275 force_fit_type (t
, 0);
1279 /* Implement the __alignof keyword: Return the minimum required
1280 alignment of TYPE, measured in bytes. */
1286 enum tree_code code
= TREE_CODE (type
);
1289 if (code
== FUNCTION_TYPE
|| code
== METHOD_TYPE
)
1290 return size_int (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
1292 if (code
== VOID_TYPE
|| code
== ERROR_MARK
)
1293 return size_int (1);
1295 /* C++: this is really correct! */
1296 if (code
== REFERENCE_TYPE
)
1297 type
= TREE_TYPE (type
);
1299 /* @@ This also produces an error for a signature ref.
1300 In that case we should be able to do better. */
1301 if (IS_SIGNATURE (type
))
1303 error ("`__alignof' applied to a signature type");
1304 return size_int (1);
1307 t
= size_int (TYPE_ALIGN (type
) / BITS_PER_UNIT
);
1308 force_fit_type (t
, 0);
1312 /* Perform default promotions for C data used in expressions.
1313 Arrays and functions are converted to pointers;
1314 enumeral types or short or char, to int.
1315 In addition, manifest constants symbols are replaced by their values.
1317 C++: this will automatically bash references to their target type. */
1320 default_conversion (exp
)
1323 register tree type
= TREE_TYPE (exp
);
1324 register enum tree_code code
= TREE_CODE (type
);
1326 if (code
== OFFSET_TYPE
/* || TREE_CODE (exp) == OFFSET_REF */ )
1328 if (TREE_CODE (exp
) == OFFSET_REF
)
1329 return default_conversion (resolve_offset_ref (exp
));
1331 type
= TREE_TYPE (type
);
1332 code
= TREE_CODE (type
);
1335 if (code
== REFERENCE_TYPE
)
1337 exp
= convert_from_reference (exp
);
1338 type
= TREE_TYPE (exp
);
1339 code
= TREE_CODE (type
);
1342 /* Constants can be used directly unless they're not loadable. */
1343 if (TREE_CODE (exp
) == CONST_DECL
)
1344 exp
= DECL_INITIAL (exp
);
1345 /* Replace a nonvolatile const static variable with its value. */
1346 else if (TREE_READONLY_DECL_P (exp
) && DECL_MODE (exp
) != BLKmode
)
1348 exp
= decl_constant_value (exp
);
1349 type
= TREE_TYPE (exp
);
1352 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
1353 Leave such NOP_EXPRs, since RHS is being used in non-lvalue context. */
1355 if (INTEGRAL_CODE_P (code
))
1357 tree t
= type_promotes_to (type
);
1359 return convert (t
, exp
);
1361 if (flag_traditional
1362 && TYPE_MAIN_VARIANT (type
) == float_type_node
)
1363 return convert (double_type_node
, exp
);
1364 if (code
== VOID_TYPE
)
1366 error ("void value not ignored as it ought to be");
1367 return error_mark_node
;
1369 if (code
== FUNCTION_TYPE
)
1371 return build_unary_op (ADDR_EXPR
, exp
, 0);
1373 if (code
== METHOD_TYPE
)
1375 if (TREE_CODE (exp
) == OFFSET_REF
)
1377 my_friendly_assert (TREE_CODE (TREE_OPERAND (exp
, 1)) == FUNCTION_DECL
,
1379 return build_unary_op (ADDR_EXPR
, TREE_OPERAND (exp
, 1), 0);
1381 return build_unary_op (ADDR_EXPR
, exp
, 0);
1383 if (code
== ARRAY_TYPE
)
1388 int constp
, volatilep
;
1390 if (TREE_CODE (exp
) == INDIRECT_REF
)
1392 /* Stripping away the INDIRECT_REF is not the right
1393 thing to do for references... */
1394 tree inner
= TREE_OPERAND (exp
, 0);
1395 if (TREE_CODE (TREE_TYPE (inner
)) == REFERENCE_TYPE
)
1397 inner
= build1 (CONVERT_EXPR
,
1398 build_pointer_type (TREE_TYPE (TREE_TYPE (inner
))),
1400 TREE_REFERENCE_EXPR (inner
) = 1;
1402 return convert (TYPE_POINTER_TO (TREE_TYPE (type
)), inner
);
1405 if (TREE_CODE (exp
) == COMPOUND_EXPR
)
1407 tree op1
= default_conversion (TREE_OPERAND (exp
, 1));
1408 return build (COMPOUND_EXPR
, TREE_TYPE (op1
),
1409 TREE_OPERAND (exp
, 0), op1
);
1413 && ! (TREE_CODE (exp
) == CONSTRUCTOR
&& TREE_STATIC (exp
)))
1415 error ("invalid use of non-lvalue array");
1416 return error_mark_node
;
1419 constp
= volatilep
= 0;
1420 if (TREE_CODE_CLASS (TREE_CODE (exp
)) == 'r'
1421 || TREE_CODE_CLASS (TREE_CODE (exp
)) == 'd')
1423 constp
= TREE_READONLY (exp
);
1424 volatilep
= TREE_THIS_VOLATILE (exp
);
1427 restype
= TREE_TYPE (type
);
1428 if (TYPE_READONLY (type
) || TYPE_VOLATILE (type
)
1429 || constp
|| volatilep
)
1430 restype
= cp_build_type_variant (restype
,
1431 TYPE_READONLY (type
) || constp
,
1432 TYPE_VOLATILE (type
) || volatilep
);
1433 ptrtype
= build_pointer_type (restype
);
1435 if (TREE_CODE (exp
) == VAR_DECL
)
1437 /* ??? This is not really quite correct
1438 in that the type of the operand of ADDR_EXPR
1439 is not the target type of the type of the ADDR_EXPR itself.
1440 Question is, can this lossage be avoided? */
1441 adr
= build1 (ADDR_EXPR
, ptrtype
, exp
);
1442 if (mark_addressable (exp
) == 0)
1443 return error_mark_node
;
1444 TREE_CONSTANT (adr
) = staticp (exp
);
1445 TREE_SIDE_EFFECTS (adr
) = 0; /* Default would be, same as EXP. */
1448 /* This way is better for a COMPONENT_REF since it can
1449 simplify the offset for a component. */
1450 adr
= build_unary_op (ADDR_EXPR
, exp
, 1);
1451 return convert (ptrtype
, adr
);
1457 build_object_ref (datum
, basetype
, field
)
1458 tree datum
, basetype
, field
;
1461 if (datum
== error_mark_node
)
1462 return error_mark_node
;
1464 dtype
= TREE_TYPE (datum
);
1465 if (TREE_CODE (dtype
) == REFERENCE_TYPE
)
1466 dtype
= TREE_TYPE (dtype
);
1467 if (! IS_AGGR_TYPE_CODE (TREE_CODE (dtype
)))
1469 cp_error ("request for member `%T::%D' in expression of non-aggregate type `%T'",
1470 basetype
, field
, dtype
);
1471 return error_mark_node
;
1473 else if (IS_SIGNATURE (IDENTIFIER_TYPE_VALUE (basetype
)))
1475 warning ("signature name in scope resolution ignored");
1476 return build_component_ref (datum
, field
, NULL_TREE
, 1);
1478 else if (is_aggr_typedef (basetype
, 1))
1480 tree real_basetype
= IDENTIFIER_TYPE_VALUE (basetype
);
1481 tree binfo
= binfo_or_else (real_basetype
, TREE_TYPE (datum
));
1483 return build_component_ref (build_scoped_ref (datum
, basetype
),
1486 return error_mark_node
;
1489 /* Like `build_component_ref, but uses an already found field.
1490 Must compute access for C_C_D. Otherwise, ok. */
1492 build_component_ref_1 (datum
, field
, protect
)
1496 register tree basetype
= TREE_TYPE (datum
);
1497 register enum tree_code code
= TREE_CODE (basetype
);
1500 if (code
== REFERENCE_TYPE
)
1502 datum
= convert_from_reference (datum
);
1503 basetype
= TREE_TYPE (datum
);
1504 code
= TREE_CODE (basetype
);
1507 if (! IS_AGGR_TYPE_CODE (code
))
1509 if (code
!= ERROR_MARK
)
1510 cp_error ("request for member `%D' in `%E', which is of non-aggregate type `%T'",
1511 field
, datum
, basetype
);
1512 return error_mark_node
;
1515 if (TYPE_SIZE (basetype
) == 0)
1517 incomplete_type_error (0, basetype
);
1518 return error_mark_node
;
1521 /* Look up component name in the structure type definition. */
1523 if (field
== error_mark_node
)
1524 my_friendly_abort (115);
1526 if (TREE_STATIC (field
))
1531 enum access_type access
1532 = compute_access (TYPE_BINFO (current_class_type
), field
);
1534 if (access
== access_private
)
1536 cp_error ("field `%D' is private", field
);
1537 return error_mark_node
;
1539 else if (access
== access_protected
)
1541 cp_error ("field `%D' is protected", field
);
1542 return error_mark_node
;
1546 ref
= build (COMPONENT_REF
, TREE_TYPE (field
), datum
, field
);
1548 if (TREE_READONLY (datum
) || TREE_READONLY (field
))
1549 TREE_READONLY (ref
) = 1;
1550 if (TREE_THIS_VOLATILE (datum
) || TREE_THIS_VOLATILE (field
))
1551 TREE_THIS_VOLATILE (ref
) = 1;
1552 if (DECL_MUTABLE_P (field
))
1553 TREE_READONLY (ref
) = 0;
1558 /* Given a COND_EXPR in T, return it in a form that we can, for
1559 example, use as an lvalue. This code used to be in unary_complex_lvalue,
1560 but we needed it to deal with `a = (d == c) ? b : c' expressions, where
1561 we're dealing with aggregates. So, we now call this in unary_complex_lvalue,
1562 and in build_modify_expr. The case (in particular) that led to this was
1563 with CODE == ADDR_EXPR, since it's not an lvalue when we'd get it there. */
1565 rationalize_conditional_expr (code
, t
)
1566 enum tree_code code
;
1570 build_conditional_expr (TREE_OPERAND (t
, 0),
1571 build_unary_op (code
, TREE_OPERAND (t
, 1), 0),
1572 build_unary_op (code
, TREE_OPERAND (t
, 2), 0));
1576 build_component_ref (datum
, component
, basetype_path
, protect
)
1577 tree datum
, component
, basetype_path
;
1580 register tree basetype
= TREE_TYPE (datum
);
1581 register enum tree_code code
= TREE_CODE (basetype
);
1582 register tree field
= NULL
;
1585 /* If DATUM is a COMPOUND_EXPR or COND_EXPR, move our reference inside it. */
1586 switch (TREE_CODE (datum
))
1590 tree value
= build_component_ref (TREE_OPERAND (datum
, 1), component
,
1591 basetype_path
, protect
);
1592 return build (COMPOUND_EXPR
, TREE_TYPE (value
),
1593 TREE_OPERAND (datum
, 0), value
);
1596 return build_conditional_expr
1597 (TREE_OPERAND (datum
, 0),
1598 build_component_ref (TREE_OPERAND (datum
, 1), component
,
1599 basetype_path
, protect
),
1600 build_component_ref (TREE_OPERAND (datum
, 2), component
,
1601 basetype_path
, protect
));
1604 if (code
== REFERENCE_TYPE
)
1607 /* TREE_REFERENCE_EXPRs are not converted by `convert_from_reference'.
1608 @@ Maybe that is not right. */
1609 if (TREE_REFERENCE_EXPR (datum
))
1610 datum
= build1 (INDIRECT_REF
, TREE_TYPE (basetype
), datum
);
1613 datum
= convert_from_reference (datum
);
1614 basetype
= TREE_TYPE (datum
);
1615 code
= TREE_CODE (basetype
);
1618 /* First, see if there is a field or component with name COMPONENT. */
1619 if (TREE_CODE (component
) == TREE_LIST
)
1621 my_friendly_assert (!(TREE_CHAIN (component
) == NULL_TREE
1622 && DECL_CHAIN (TREE_VALUE (component
)) == NULL_TREE
), 309);
1623 return build (COMPONENT_REF
, TREE_TYPE (component
), datum
, component
);
1626 if (TREE_CODE (component
) == TYPE_EXPR
)
1627 return build_component_type_expr (datum
, component
, NULL_TREE
, protect
);
1630 if (! IS_AGGR_TYPE_CODE (code
))
1632 if (code
!= ERROR_MARK
)
1633 cp_error ("request for member `%D' in `%E', which is of non-aggregate type `%T'",
1634 component
, datum
, basetype
);
1635 return error_mark_node
;
1638 if (TYPE_SIZE (basetype
) == 0)
1640 incomplete_type_error (0, basetype
);
1641 return error_mark_node
;
1644 if (TREE_CODE (component
) == BIT_NOT_EXPR
)
1646 if (TYPE_IDENTIFIER (basetype
) != TREE_OPERAND (component
, 0))
1648 cp_error ("destructor specifier `%T::~%T' must have matching names",
1649 basetype
, TREE_OPERAND (component
, 0));
1650 return error_mark_node
;
1652 if (! TYPE_HAS_DESTRUCTOR (basetype
))
1654 cp_error ("type `%T' has no destructor", basetype
);
1655 return error_mark_node
;
1657 return TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (basetype
), 0);
1660 /* Look up component name in the structure type definition. */
1661 if (CLASSTYPE_VFIELD (basetype
)
1662 && DECL_NAME (CLASSTYPE_VFIELD (basetype
)) == component
)
1663 /* Special-case this because if we use normal lookups in an ambiguous
1664 hierarchy, the compiler will abort (because vptr lookups are
1665 not supposed to be ambiguous. */
1666 field
= CLASSTYPE_VFIELD (basetype
);
1669 if (basetype_path
== NULL_TREE
)
1670 basetype_path
= TYPE_BINFO (basetype
);
1671 field
= lookup_field (basetype_path
, component
,
1672 protect
&& ! VFIELD_NAME_P (component
), 0);
1673 if (field
== error_mark_node
)
1674 return error_mark_node
;
1676 if (field
== NULL_TREE
)
1678 /* Not found as a data field, look for it as a method. If found,
1679 then if this is the only possible one, return it, else
1680 report ambiguity error. */
1681 tree fndecls
= lookup_fnfields (basetype_path
, component
, 1);
1682 if (fndecls
== error_mark_node
)
1683 return error_mark_node
;
1686 if (TREE_CHAIN (fndecls
) == NULL_TREE
1687 && DECL_CHAIN (TREE_VALUE (fndecls
)) == NULL_TREE
)
1689 enum access_type access
;
1692 /* Unique, so use this one now. */
1693 basetype
= TREE_PURPOSE (fndecls
);
1694 fndecl
= TREE_VALUE (fndecls
);
1695 access
= compute_access (TREE_PURPOSE (fndecls
), fndecl
);
1696 if (access
== access_public
)
1698 if (DECL_VINDEX (fndecl
)
1699 && ! resolves_to_fixed_type_p (datum
, 0))
1701 tree addr
= build_unary_op (ADDR_EXPR
, datum
, 0);
1702 addr
= convert_pointer_to (DECL_CONTEXT (fndecl
), addr
);
1703 datum
= build_indirect_ref (addr
, NULL_PTR
);
1704 my_friendly_assert (datum
!= error_mark_node
, 310);
1705 fndecl
= build_vfn_ref (&addr
, datum
, DECL_VINDEX (fndecl
));
1707 assemble_external (fndecl
);
1710 if (access
== access_protected
)
1711 cp_error ("member function `%D' is protected", fndecl
);
1713 cp_error ("member function `%D' is private", fndecl
);
1714 return error_mark_node
;
1718 /* Just act like build_offset_ref, since the object does
1719 not matter unless we're actually calling the function. */
1722 for (t
= TREE_VALUE (fndecls
); t
; t
= DECL_CHAIN (t
))
1723 assemble_external (t
);
1725 t
= build_tree_list (error_mark_node
, fndecls
);
1726 TREE_TYPE (t
) = build_offset_type (basetype
,
1733 if (component
== ansi_opname
[(int) TYPE_EXPR
])
1734 cp_error ("`%#T' has no such type conversion operator", basetype
);
1737 cp_error ("`%#T' has no member named `%D'", basetype
, component
);
1738 return error_mark_node
;
1740 else if (TREE_TYPE (field
) == error_mark_node
)
1741 return error_mark_node
;
1743 if (TREE_CODE (field
) != FIELD_DECL
)
1745 if (TREE_CODE (field
) == TYPE_DECL
)
1747 cp_error ("invalid use of type decl `%#D' as expression", field
);
1748 return error_mark_node
;
1750 if (DECL_RTL (field
) != 0)
1751 assemble_external (field
);
1752 TREE_USED (field
) = 1;
1757 if (DECL_FIELD_CONTEXT (field
) != basetype
1758 && TYPE_USES_COMPLEX_INHERITANCE (basetype
))
1760 tree addr
= build_unary_op (ADDR_EXPR
, datum
, 0);
1761 if (integer_zerop (addr
))
1763 error ("invalid reference to NULL ptr, use ptr-to-member instead");
1764 return error_mark_node
;
1766 addr
= convert_pointer_to (DECL_FIELD_CONTEXT (field
), addr
);
1767 datum
= build_indirect_ref (addr
, NULL_PTR
);
1768 my_friendly_assert (datum
!= error_mark_node
, 311);
1770 ref
= fold (build (COMPONENT_REF
, TREE_TYPE (field
),
1771 break_out_cleanups (datum
), field
));
1773 if (TREE_READONLY (datum
) || TREE_READONLY (field
))
1774 TREE_READONLY (ref
) = 1;
1775 if (TREE_THIS_VOLATILE (datum
) || TREE_THIS_VOLATILE (field
))
1776 TREE_THIS_VOLATILE (ref
) = 1;
1777 if (DECL_MUTABLE_P (field
))
1778 TREE_READONLY (ref
) = 0;
1783 /* Given an expression PTR for a pointer, return an expression
1784 for the value pointed to.
1785 ERRORSTRING is the name of the operator to appear in error messages.
1787 This function may need to overload OPERATOR_FNNAME.
1788 Must also handle REFERENCE_TYPEs for C++. */
1791 build_x_indirect_ref (ptr
, errorstring
)
1795 tree rval
= build_opfncall (INDIRECT_REF
, LOOKUP_NORMAL
, ptr
, NULL_TREE
, NULL_TREE
);
1798 return build_indirect_ref (ptr
, errorstring
);
1802 build_indirect_ref (ptr
, errorstring
)
1806 register tree pointer
= default_conversion (ptr
);
1807 register tree type
= TREE_TYPE (pointer
);
1809 if (ptr
== current_class_decl
)
1812 ptr
= build_expr_type_conversion (WANT_POINTER
, pointer
, 1);
1816 type
= TREE_TYPE (pointer
);
1819 if (TREE_CODE (type
) == POINTER_TYPE
|| TREE_CODE (type
) == REFERENCE_TYPE
)
1821 if (TREE_CODE (pointer
) == ADDR_EXPR
1822 && (TREE_TYPE (TREE_OPERAND (pointer
, 0))
1823 == TREE_TYPE (type
)))
1824 return TREE_OPERAND (pointer
, 0);
1827 tree t
= TREE_TYPE (type
);
1828 register tree ref
= build1 (INDIRECT_REF
,
1829 TYPE_MAIN_VARIANT (t
), pointer
);
1831 TREE_READONLY (ref
) = TYPE_READONLY (t
);
1832 TREE_THIS_VOLATILE (ref
) = TYPE_VOLATILE (t
);
1833 TREE_SIDE_EFFECTS (ref
)
1834 = TYPE_VOLATILE (t
) || TREE_SIDE_EFFECTS (pointer
);
1838 /* `pointer' won't be an error_mark_node if we were given a
1839 pointer to member, so it's cool to check for this here. */
1840 else if (TYPE_PTRMEMFUNC_P (type
))
1841 error ("invalid use of `%s' on pointer to member function", errorstring
);
1842 else if (TREE_CODE (type
) == RECORD_TYPE
1843 && (IS_SIGNATURE_POINTER (type
) || IS_SIGNATURE_REFERENCE (type
)))
1844 error ("cannot dereference signature pointer/reference");
1845 else if (pointer
!= error_mark_node
)
1848 error ("invalid type argument of `%s'", errorstring
);
1850 error ("invalid type argument");
1852 return error_mark_node
;
1855 /* This handles expressions of the form "a[i]", which denotes
1858 This is logically equivalent in C to *(a+i), but we may do it differently.
1859 If A is a variable or a member, we generate a primitive ARRAY_REF.
1860 This avoids forcing the array out of registers, and can work on
1861 arrays that are not lvalues (for example, members of structures returned
1864 If INDEX is of some user-defined type, it must be converted to
1865 integer type. Otherwise, to make a compatible PLUS_EXPR, it
1866 will inherit the type of the array, which will be some pointer type. */
1869 build_x_array_ref (array
, index
)
1872 tree rval
= build_opfncall (ARRAY_REF
, LOOKUP_NORMAL
, array
, index
, NULL_TREE
);
1875 return build_array_ref (array
, index
);
1879 build_array_ref (array
, idx
)
1886 error ("subscript missing in array reference");
1887 return error_mark_node
;
1890 if (TREE_TYPE (array
) == error_mark_node
1891 || TREE_TYPE (idx
) == error_mark_node
)
1892 return error_mark_node
;
1894 itype
= TREE_TYPE (idx
);
1896 if (TREE_CODE (TREE_TYPE (array
)) == ARRAY_TYPE
1897 && TREE_CODE (array
) != INDIRECT_REF
)
1901 /* Subscripting with type char is likely to lose
1902 on a machine where chars are signed.
1903 So warn on any machine, but optionally.
1904 Don't warn for unsigned char since that type is safe.
1905 Don't warn for signed char because anyone who uses that
1906 must have done so deliberately. */
1907 if (warn_char_subscripts
1908 && TYPE_MAIN_VARIANT (TREE_TYPE (idx
)) == char_type_node
)
1909 warning ("array subscript has type `char'");
1911 /* Apply default promotions *after* noticing character types. */
1912 idx
= default_conversion (idx
);
1914 if (TREE_CODE (TREE_TYPE (idx
)) != INTEGER_TYPE
)
1916 error ("array subscript is not an integer");
1917 return error_mark_node
;
1920 /* An array that is indexed by a non-constant
1921 cannot be stored in a register; we must be able to do
1922 address arithmetic on its address.
1923 Likewise an array of elements of variable size. */
1924 if (TREE_CODE (idx
) != INTEGER_CST
1925 || (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array
))) != 0
1926 && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array
)))) != INTEGER_CST
))
1928 if (mark_addressable (array
) == 0)
1929 return error_mark_node
;
1931 /* An array that is indexed by a constant value which is not within
1932 the array bounds cannot be stored in a register either; because we
1933 would get a crash in store_bit_field/extract_bit_field when trying
1934 to access a non-existent part of the register. */
1935 if (TREE_CODE (idx
) == INTEGER_CST
1936 && TYPE_VALUES (TREE_TYPE (array
))
1937 && ! int_fits_type_p (idx
, TYPE_VALUES (TREE_TYPE (array
))))
1939 if (mark_addressable (array
) == 0)
1940 return error_mark_node
;
1943 if (pedantic
&& !lvalue_p (array
))
1944 pedwarn ("ANSI C++ forbids subscripting non-lvalue array");
1946 /* Note in C++ it is valid to subscript a `register' array, since
1947 it is valid to take the address of something with that
1948 storage specification. */
1952 while (TREE_CODE (foo
) == COMPONENT_REF
)
1953 foo
= TREE_OPERAND (foo
, 0);
1954 if (TREE_CODE (foo
) == VAR_DECL
&& DECL_REGISTER (foo
))
1955 warning ("subscripting array declared `register'");
1958 type
= TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (array
)));
1959 rval
= build (ARRAY_REF
, type
, array
, idx
);
1960 /* Array ref is const/volatile if the array elements are
1961 or if the array is.. */
1962 TREE_READONLY (rval
)
1963 |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array
)))
1964 | TREE_READONLY (array
));
1965 TREE_SIDE_EFFECTS (rval
)
1966 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array
)))
1967 | TREE_SIDE_EFFECTS (array
));
1968 TREE_THIS_VOLATILE (rval
)
1969 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array
)))
1970 /* This was added by rms on 16 Nov 91.
1971 It fixes vol struct foo *a; a->elts[1]
1972 in an inline function.
1973 Hope it doesn't break something else. */
1974 | TREE_THIS_VOLATILE (array
));
1975 return require_complete_type (fold (rval
));
1979 tree ar
= default_conversion (array
);
1980 tree ind
= default_conversion (idx
);
1982 /* Put the integer in IND to simplify error checking. */
1983 if (TREE_CODE (TREE_TYPE (ar
)) == INTEGER_TYPE
)
1990 if (ar
== error_mark_node
)
1993 if (TREE_CODE (TREE_TYPE (ar
)) != POINTER_TYPE
)
1995 error ("subscripted value is neither array nor pointer");
1996 return error_mark_node
;
1998 if (TREE_CODE (TREE_TYPE (ind
)) != INTEGER_TYPE
)
2000 error ("array subscript is not an integer");
2001 return error_mark_node
;
2004 return build_indirect_ref (build_binary_op_nodefault (PLUS_EXPR
, ar
, ind
, PLUS_EXPR
),
2009 /* Build a function call to function FUNCTION with parameters PARAMS.
2010 PARAMS is a list--a chain of TREE_LIST nodes--in which the
2011 TREE_VALUE of each node is a parameter-expression.
2012 FUNCTION's data type may be a function type or a pointer-to-function.
2014 For C++: If FUNCTION's data type is a TREE_LIST, then the tree list
2015 is the list of possible methods that FUNCTION could conceivably
2016 be. If the list of methods comes from a class, then it will be
2017 a list of lists (where each element is associated with the class
2018 that produced it), otherwise it will be a simple list (for
2019 functions overloaded in global scope).
2021 In the first case, TREE_VALUE (function) is the head of one of those
2022 lists, and TREE_PURPOSE is the name of the function.
2024 In the second case, TREE_PURPOSE (function) is the function's
2027 DECL is the class instance variable, usually CURRENT_CLASS_DECL. */
2030 * [eichin:19911015.1726EST] actually return a possibly incomplete
2034 build_x_function_call (function
, params
, decl
)
2035 tree function
, params
, decl
;
2040 if (function
== error_mark_node
)
2041 return error_mark_node
;
2043 type
= TREE_TYPE (function
);
2044 is_method
= ((TREE_CODE (function
) == TREE_LIST
2045 && current_class_type
!= NULL_TREE
2046 && IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (function
)) == function
)
2047 || TREE_CODE (function
) == IDENTIFIER_NODE
2048 || TREE_CODE (type
) == METHOD_TYPE
2049 || TYPE_PTRMEMFUNC_P (type
));
2051 /* Handle methods, friends, and overloaded functions, respectively. */
2054 if (TREE_CODE (function
) == FUNCTION_DECL
)
2056 if (DECL_NAME (function
))
2057 function
= DECL_NAME (function
);
2059 function
= TYPE_IDENTIFIER (DECL_CLASS_CONTEXT (function
));
2061 else if (TREE_CODE (function
) == TREE_LIST
)
2064 if (TREE_CODE (TREE_VALUE (function
)) == TREE_LIST
)
2065 function
= TREE_PURPOSE (TREE_VALUE (function
));
2067 function
= TREE_PURPOSE (function
);
2069 my_friendly_assert (TREE_CODE (TREE_VALUE (function
)) == FUNCTION_DECL
, 312);
2070 function
= TREE_PURPOSE (function
);
2073 else if (TREE_CODE (function
) != IDENTIFIER_NODE
)
2075 if (TREE_CODE (function
) == OFFSET_REF
)
2077 if (TREE_OPERAND (function
, 0))
2078 decl
= TREE_OPERAND (function
, 0);
2080 /* Call via a pointer to member function. */
2081 if (decl
== NULL_TREE
)
2083 error ("pointer to member function called, but not in class scope");
2084 return error_mark_node
;
2086 /* What other type of POINTER_TYPE could this be? */
2087 if (TREE_CODE (TREE_TYPE (function
)) != POINTER_TYPE
2088 && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (function
))
2089 && TREE_CODE (function
) != OFFSET_REF
)
2090 function
= build (OFFSET_REF
, TREE_TYPE (type
), NULL_TREE
, function
);
2094 /* this is an abbreviated method call.
2095 must go through here in case it is a virtual function.
2096 @@ Perhaps this could be optimized. */
2098 if (decl
== NULL_TREE
)
2100 if (current_class_type
== NULL_TREE
)
2102 error ("object missing in call to method `%s'",
2103 IDENTIFIER_POINTER (function
));
2104 return error_mark_node
;
2106 /* Yow: call from a static member function. */
2107 decl
= build1 (NOP_EXPR
, TYPE_POINTER_TO (current_class_type
),
2109 decl
= build_indirect_ref (decl
, NULL_PTR
);
2112 return build_method_call (decl
, function
, params
,
2113 NULL_TREE
, LOOKUP_NORMAL
);
2115 else if (TREE_CODE (function
) == COMPONENT_REF
2116 && type
== unknown_type_node
)
2118 /* Should we undo what was done in build_component_ref? */
2119 if (TREE_CODE (TREE_PURPOSE (TREE_OPERAND (function
, 1))) == TREE_VEC
)
2120 /* Get the name that build_component_ref hid. */
2121 function
= DECL_NAME (TREE_VALUE (TREE_OPERAND (function
, 1)));
2123 function
= TREE_PURPOSE (TREE_OPERAND (function
, 1));
2124 return build_method_call (decl
, function
, params
,
2125 NULL_TREE
, LOOKUP_NORMAL
);
2127 else if (TREE_CODE (function
) == TREE_LIST
)
2129 if (TREE_VALUE (function
) == NULL_TREE
)
2131 cp_error ("function `%D' declared overloaded, but no definitions appear with which to resolve it?!?",
2132 TREE_PURPOSE (function
));
2133 return error_mark_node
;
2137 tree val
= TREE_VALUE (function
);
2139 if (TREE_CODE (val
) == TEMPLATE_DECL
)
2140 return build_overload_call_maybe
2141 (function
, params
, LOOKUP_COMPLAIN
, (struct candidate
*)0);
2142 else if (DECL_CHAIN (val
) != NULL_TREE
)
2143 return build_overload_call
2144 (function
, params
, LOOKUP_COMPLAIN
, (struct candidate
*)0);
2146 my_friendly_abort (360);
2151 if (TREE_CODE (function
) == OFFSET_REF
)
2153 /* If the component is a data element (or a virtual function), we play
2154 games here to make things work. */
2157 if (TREE_OPERAND (function
, 0))
2158 decl
= TREE_OPERAND (function
, 0);
2162 decl_addr
= build_unary_op (ADDR_EXPR
, decl
, 0);
2163 function
= get_member_function_from_ptrfunc (&decl_addr
,
2164 TREE_OPERAND (function
, 1));
2165 params
= tree_cons (NULL_TREE
, decl_addr
, params
);
2166 return build_function_call (function
, params
);
2169 type
= TREE_TYPE (function
);
2170 if (type
!= error_mark_node
)
2172 if (TREE_CODE (type
) == REFERENCE_TYPE
)
2173 type
= TREE_TYPE (type
);
2175 if (TYPE_LANG_SPECIFIC (type
) && TYPE_OVERLOADS_CALL_EXPR (type
))
2176 return build_opfncall (CALL_EXPR
, LOOKUP_NORMAL
, function
, params
, NULL_TREE
);
2181 tree fntype
= TREE_TYPE (function
);
2184 /* Explicitly named method? */
2185 if (TREE_CODE (function
) == FUNCTION_DECL
)
2186 ctypeptr
= TYPE_POINTER_TO (DECL_CLASS_CONTEXT (function
));
2187 /* Expression with ptr-to-method type? It could either be a plain
2188 usage, or it might be a case where the ptr-to-method is being
2189 passed in as an argument. */
2190 else if (TYPE_PTRMEMFUNC_P (fntype
))
2192 tree rec
= TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (fntype
)));
2193 ctypeptr
= TYPE_POINTER_TO (rec
);
2195 /* Unexpected node type? */
2197 my_friendly_abort (116);
2198 if (decl
== NULL_TREE
)
2200 if (current_function_decl
2201 && DECL_STATIC_FUNCTION_P (current_function_decl
))
2202 error ("invalid call to member function needing `this' in static member function scope");
2204 error ("pointer to member function called, but not in class scope");
2205 return error_mark_node
;
2207 if (TREE_CODE (TREE_TYPE (decl
)) != POINTER_TYPE
2208 && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (decl
)))
2210 decl
= build_unary_op (ADDR_EXPR
, decl
, 0);
2211 decl
= convert_pointer_to (TREE_TYPE (ctypeptr
), decl
);
2214 decl
= build_c_cast (ctypeptr
, decl
, 0);
2215 params
= tree_cons (NULL_TREE
, decl
, params
);
2218 return build_function_call (function
, params
);
2221 /* Resolve a pointer to member function. INSTANCE is the object
2222 instance to use, if the member points to a virtual member. */
2225 get_member_function_from_ptrfunc (instance_ptrptr
, function
)
2226 tree
*instance_ptrptr
;
2229 if (TREE_CODE (function
) == OFFSET_REF
)
2231 function
= TREE_OPERAND (function
, 1);
2234 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (function
)))
2236 tree fntype
= TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (function
));
2237 tree index
= save_expr (build_component_ref (function
,
2240 tree e1
= build (GT_EXPR
, boolean_type_node
, index
,
2241 convert (delta_type_node
, integer_zero_node
));
2242 tree delta
= convert (ptrdiff_type_node
,
2243 build_component_ref (function
, delta_identifier
, 0, 0));
2244 tree delta2
= DELTA2_FROM_PTRMEMFUNC (function
);
2250 tree instance_ptr
= *instance_ptrptr
;
2252 if (TREE_SIDE_EFFECTS (instance_ptr
))
2253 instance_ptr
= save_expr (instance_ptr
);
2255 /* convert down to the right base, before using the instance. */
2257 = convert_pointer_to_real (TYPE_METHOD_BASETYPE (TREE_TYPE (fntype
)),
2259 if (instance
== error_mark_node
)
2262 vtbl
= convert_pointer_to (ptr_type_node
, instance
);
2265 build_pointer_type (build_pointer_type (vtable_entry_type
)),
2266 vtbl
, convert (ptrdiff_type_node
, delta2
));
2267 vtbl
= build_indirect_ref (vtbl
, NULL_PTR
);
2268 aref
= build_array_ref (vtbl
, build_binary_op (MINUS_EXPR
,
2270 integer_one_node
, 1));
2271 if (! flag_vtable_thunks
)
2273 aref
= save_expr (aref
);
2275 /* Save the intermediate result in a SAVE_EXPR so we don't have to
2276 compute each component of the virtual function pointer twice. */
2277 if (/* !building_cleanup && */ TREE_CODE (aref
) == INDIRECT_REF
)
2278 TREE_OPERAND (aref
, 0) = save_expr (TREE_OPERAND (aref
, 0));
2280 delta
= build_binary_op (PLUS_EXPR
,
2281 build_conditional_expr (e1
, build_component_ref (aref
, delta_identifier
, 0, 0), integer_zero_node
),
2285 *instance_ptrptr
= build (PLUS_EXPR
, TREE_TYPE (instance_ptr
),
2286 instance_ptr
, delta
);
2287 if (flag_vtable_thunks
)
2290 e2
= build_component_ref (aref
, pfn_identifier
, 0, 0);
2292 e3
= PFN_FROM_PTRMEMFUNC (function
);
2293 TREE_TYPE (e2
) = TREE_TYPE (e3
);
2294 function
= build_conditional_expr (e1
, e2
, e3
);
2296 /* Make sure this doesn't get evaluated first inside one of the
2297 branches of the COND_EXPR. */
2298 if (TREE_CODE (instance_ptr
) == SAVE_EXPR
)
2299 function
= build (COMPOUND_EXPR
, TREE_TYPE (function
),
2300 instance_ptr
, function
);
2306 build_function_call_real (function
, params
, require_complete
, flags
)
2307 tree function
, params
;
2308 int require_complete
, flags
;
2310 register tree fntype
, fndecl
;
2311 register tree value_type
;
2312 register tree coerced_params
;
2313 tree name
= NULL_TREE
, assembler_name
= NULL_TREE
;
2316 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
2317 Strip such NOP_EXPRs, since FUNCTION is used in non-lvalue context. */
2318 if (TREE_CODE (function
) == NOP_EXPR
2319 && TREE_TYPE (function
) == TREE_TYPE (TREE_OPERAND (function
, 0)))
2320 function
= TREE_OPERAND (function
, 0);
2322 if (TREE_CODE (function
) == FUNCTION_DECL
)
2324 name
= DECL_NAME (function
);
2325 assembler_name
= DECL_ASSEMBLER_NAME (function
);
2327 GNU_xref_call (current_function_decl
,
2328 IDENTIFIER_POINTER (name
? name
2329 : TYPE_IDENTIFIER (DECL_CLASS_CONTEXT (function
))));
2330 assemble_external (function
);
2333 /* Convert anything with function type to a pointer-to-function. */
2336 && IDENTIFIER_LENGTH (name
) == 4
2337 && ! strcmp (IDENTIFIER_POINTER (name
), "main")
2338 && DECL_CONTEXT (function
) == NULL_TREE
)
2340 pedwarn ("ANSI C++ forbids calling `main' from within program");
2343 /* Differs from default_conversion by not setting TREE_ADDRESSABLE
2344 (because calling an inline function does not mean the function
2345 needs to be separately compiled). */
2347 if (DECL_INLINE (function
))
2349 fntype
= build_type_variant (TREE_TYPE (function
),
2350 TREE_READONLY (function
),
2351 TREE_THIS_VOLATILE (function
));
2352 function
= build1 (ADDR_EXPR
, build_pointer_type (fntype
), function
);
2356 assemble_external (function
);
2357 TREE_USED (function
) = 1;
2358 function
= default_conversion (function
);
2365 /* Convert anything with function type to a pointer-to-function. */
2366 if (function
== error_mark_node
)
2367 return error_mark_node
;
2368 function
= default_conversion (function
);
2371 fntype
= TREE_TYPE (function
);
2373 if (TYPE_PTRMEMFUNC_P (fntype
))
2375 tree instance_ptr
= build_unary_op (ADDR_EXPR
, C_C_D
, 0);
2376 fntype
= TYPE_PTRMEMFUNC_FN_TYPE (fntype
);
2377 function
= get_member_function_from_ptrfunc (&instance_ptr
, function
);
2380 is_method
= (TREE_CODE (fntype
) == POINTER_TYPE
2381 && TREE_CODE (TREE_TYPE (fntype
)) == METHOD_TYPE
);
2383 if (!((TREE_CODE (fntype
) == POINTER_TYPE
2384 && TREE_CODE (TREE_TYPE (fntype
)) == FUNCTION_TYPE
)
2387 error ("called object is not a function");
2388 return error_mark_node
;
2391 /* fntype now gets the type of function pointed to. */
2392 fntype
= TREE_TYPE (fntype
);
2394 /* Convert the parameters to the types declared in the
2395 function prototype, or apply default promotions. */
2397 if (flags
& LOOKUP_COMPLAIN
)
2398 coerced_params
= convert_arguments (NULL_TREE
, TYPE_ARG_TYPES (fntype
),
2399 params
, fndecl
, LOOKUP_NORMAL
);
2401 coerced_params
= convert_arguments (NULL_TREE
, TYPE_ARG_TYPES (fntype
),
2404 /* Check for errors in format strings. */
2406 if (warn_format
&& (name
|| assembler_name
))
2407 check_function_format (name
, assembler_name
, coerced_params
);
2409 /* Recognize certain built-in functions so we can make tree-codes
2410 other than CALL_EXPR. We do this when it enables fold-const.c
2411 to do something useful. */
2413 if (TREE_CODE (function
) == ADDR_EXPR
2414 && TREE_CODE (TREE_OPERAND (function
, 0)) == FUNCTION_DECL
2415 && DECL_BUILT_IN (TREE_OPERAND (function
, 0)))
2416 switch (DECL_FUNCTION_CODE (TREE_OPERAND (function
, 0)))
2421 if (coerced_params
== 0)
2422 return integer_zero_node
;
2423 return build_unary_op (ABS_EXPR
, TREE_VALUE (coerced_params
), 0);
2427 value_type
= TREE_TYPE (fntype
) ? TREE_TYPE (fntype
) : void_type_node
;
2429 register tree result
=
2430 build (CALL_EXPR
, value_type
,
2431 function
, coerced_params
, NULL_TREE
);
2433 TREE_SIDE_EFFECTS (result
) = 1;
2435 if (! require_complete
)
2436 return convert_from_reference (result
);
2437 if (value_type
== void_type_node
)
2439 result
= require_complete_type (result
);
2440 return convert_from_reference (result
);
2445 build_function_call (function
, params
)
2446 tree function
, params
;
2448 return build_function_call_real (function
, params
, 1, LOOKUP_NORMAL
);
2452 build_function_call_maybe (function
, params
)
2453 tree function
, params
;
2455 return build_function_call_real (function
, params
, 0, 0);
2459 /* Convert the actual parameter expressions in the list VALUES
2460 to the types in the list TYPELIST.
2461 If parmdecls is exhausted, or when an element has NULL as its type,
2462 perform the default conversions.
2464 RETURN_LOC is the location of the return value, if known, NULL_TREE
2465 otherwise. This is useful in the case where we can avoid creating
2466 a temporary variable in the case where we can initialize the return
2467 value directly. If we are not eliding constructors, then we set this
2468 to NULL_TREE to avoid this avoidance.
2470 NAME is an IDENTIFIER_NODE or 0. It is used only for error messages.
2472 This is also where warnings about wrong number of args are generated.
2474 Return a list of expressions for the parameters as converted.
2476 Both VALUES and the returned value are chains of TREE_LIST nodes
2477 with the elements of the list in the TREE_VALUE slots of those nodes.
2479 In C++, unspecified trailing parameters can be filled in with their
2480 default arguments, if such were specified. Do so here. */
2483 convert_arguments (return_loc
, typelist
, values
, fndecl
, flags
)
2484 tree return_loc
, typelist
, values
, fndecl
;
2487 extern tree gc_protect_fndecl
;
2488 register tree typetail
, valtail
;
2489 register tree result
= NULL_TREE
;
2493 if (! flag_elide_constructors
)
2498 if (TREE_CODE (TREE_TYPE (fndecl
)) == METHOD_TYPE
)
2500 if (DECL_NAME (fndecl
) == NULL_TREE
2501 || IDENTIFIER_HAS_TYPE_VALUE (DECL_NAME (fndecl
)))
2502 called_thing
= "constructor";
2504 called_thing
= "member function";
2507 called_thing
= "function";
2510 for (valtail
= values
, typetail
= typelist
;
2512 valtail
= TREE_CHAIN (valtail
), i
++)
2514 register tree type
= typetail
? TREE_VALUE (typetail
) : 0;
2515 register tree val
= TREE_VALUE (valtail
);
2517 if (val
== error_mark_node
)
2520 if (type
== void_type_node
)
2524 char *buf
= (char *)alloca (40 + strlen (called_thing
));
2525 sprintf (buf
, "too many arguments to %s `%%s'", called_thing
);
2526 error_with_decl (fndecl
, buf
);
2527 error ("at this point in file");
2530 error ("too many arguments to function");
2531 /* In case anybody wants to know if this argument
2534 TREE_TYPE (tree_last (result
)) = error_mark_node
;
2538 /* The tree type of the parameter being passed may not yet be
2539 known. In this case, its type is TYPE_UNKNOWN, and will
2540 be instantiated by the type given by TYPE. If TYPE
2541 is also NULL, the tree type of VAL is ERROR_MARK_NODE. */
2542 if (type
&& type_unknown_p (val
))
2543 val
= require_instantiated_type (type
, val
, integer_zero_node
);
2544 else if (type_unknown_p (val
))
2546 /* Strip the `&' from an overloaded FUNCTION_DECL. */
2547 if (TREE_CODE (val
) == ADDR_EXPR
)
2548 val
= TREE_OPERAND (val
, 0);
2549 if (TREE_CODE (val
) == TREE_LIST
2550 && TREE_CHAIN (val
) == NULL_TREE
2551 && TREE_TYPE (TREE_VALUE (val
)) != NULL_TREE
2552 && (TREE_TYPE (val
) == unknown_type_node
2553 || DECL_CHAIN (TREE_VALUE (val
)) == NULL_TREE
))
2554 /* Instantiates automatically. */
2555 val
= TREE_VALUE (val
);
2558 error ("insufficient type information in parameter list");
2559 val
= integer_zero_node
;
2562 else if (TREE_CODE (val
) == OFFSET_REF
2563 && TREE_CODE (TREE_TYPE (val
)) == METHOD_TYPE
)
2565 /* This is unclean. Should be handled elsewhere. */
2566 val
= build_unary_op (ADDR_EXPR
, val
, 0);
2568 else if (TREE_CODE (val
) == OFFSET_REF
)
2569 val
= resolve_offset_ref (val
);
2573 /* This code forces the assumption that if we have a ptr-to-func
2574 type in an arglist, that every routine that wants to check
2575 its validity has done so, and thus we need not do any
2576 more conversion. I don't remember why this is necessary. */
2577 else if (TREE_CODE (ttype
) == FUNCTION_TYPE
2579 || TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
2580 || TREE_CODE (TREE_TYPE (type
)) == VOID_TYPE
))
2582 type
= build_pointer_type (ttype
);
2587 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
2588 Strip such NOP_EXPRs, since VAL is used in non-lvalue context. */
2589 if (TREE_CODE (val
) == NOP_EXPR
2590 && TREE_TYPE (val
) == TREE_TYPE (TREE_OPERAND (val
, 0))
2591 && (type
== 0 || TREE_CODE (type
) != REFERENCE_TYPE
))
2592 val
= TREE_OPERAND (val
, 0);
2594 if (type
== 0 || TREE_CODE (type
) != REFERENCE_TYPE
)
2596 if (TREE_CODE (TREE_TYPE (val
)) == ARRAY_TYPE
2597 || TREE_CODE (TREE_TYPE (val
)) == FUNCTION_TYPE
2598 || TREE_CODE (TREE_TYPE (val
)) == METHOD_TYPE
)
2599 val
= default_conversion (val
);
2601 val
= require_complete_type (val
);
2604 if (val
== error_mark_node
)
2609 /* Formal parm type is specified by a function prototype. */
2612 if (TYPE_SIZE (type
) == 0)
2614 error ("parameter type of called function is incomplete");
2619 #if 0 && defined (PROMOTE_PROTOTYPES)
2620 /* This breaks user-defined conversions. */
2621 /* Rather than truncating and then reextending,
2622 convert directly to int, if that's the type we will want. */
2623 if (! flag_traditional
2624 && (TREE_CODE (type
) == INTEGER_TYPE
2625 || TREE_CODE (type
) == ENUMERAL_TYPE
)
2626 && (TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
)))
2627 type
= integer_type_node
;
2629 parmval
= convert_for_initialization (return_loc
, type
, val
, flags
,
2630 "argument passing", fndecl
, i
);
2631 #ifdef PROMOTE_PROTOTYPES
2632 if ((TREE_CODE (type
) == INTEGER_TYPE
2633 || TREE_CODE (type
) == ENUMERAL_TYPE
)
2634 && (TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
)))
2635 parmval
= default_conversion (parmval
);
2638 result
= tree_cons (NULL_TREE
, parmval
, result
);
2642 if (TREE_CODE (TREE_TYPE (val
)) == REFERENCE_TYPE
)
2643 val
= convert_from_reference (val
);
2645 if (TREE_CODE (TREE_TYPE (val
)) == REAL_TYPE
2646 && (TYPE_PRECISION (TREE_TYPE (val
))
2647 < TYPE_PRECISION (double_type_node
)))
2648 /* Convert `float' to `double'. */
2649 result
= tree_cons (NULL_TREE
, convert (double_type_node
, val
), result
);
2650 else if (TYPE_LANG_SPECIFIC (TREE_TYPE (val
))
2651 && (TYPE_HAS_INIT_REF (TREE_TYPE (val
))
2652 || TYPE_HAS_ASSIGN_REF (TREE_TYPE (val
))))
2654 cp_warning ("cannot pass objects of type `%T' through `...'",
2656 result
= tree_cons (NULL_TREE
, val
, result
);
2659 /* Convert `short' and `char' to full-size `int'. */
2660 result
= tree_cons (NULL_TREE
, default_conversion (val
), result
);
2664 /* There are certain functions for which we don't need
2665 to protect our arguments. GC_PROTECT_FNDECL is one. */
2666 && fndecl
!= gc_protect_fndecl
2667 && type_needs_gc_entry (TREE_TYPE (TREE_VALUE (result
)))
2668 && ! value_safe_from_gc (NULL_TREE
, TREE_VALUE (result
)))
2669 /* This will build a temporary variable whose cleanup is
2670 to clear the obstack entry. */
2671 TREE_VALUE (result
) = protect_value_from_gc (NULL_TREE
,
2672 TREE_VALUE (result
));
2675 typetail
= TREE_CHAIN (typetail
);
2678 if (typetail
!= 0 && typetail
!= void_list_node
)
2680 /* See if there are default arguments that can be used */
2681 if (TREE_PURPOSE (typetail
))
2683 for (; typetail
!= void_list_node
; ++i
)
2685 tree type
= TREE_VALUE (typetail
);
2686 tree val
= TREE_PURPOSE (typetail
);
2689 if (val
== NULL_TREE
)
2690 parmval
= error_mark_node
;
2691 else if (TREE_CODE (val
) == CONSTRUCTOR
)
2693 parmval
= digest_init (type
, val
, (tree
*)0);
2694 parmval
= convert_for_initialization (return_loc
, type
, parmval
, flags
,
2695 "default constructor", fndecl
, i
);
2699 /* This could get clobbered by the following call. */
2700 if (TREE_HAS_CONSTRUCTOR (val
))
2701 val
= copy_node (val
);
2703 parmval
= convert_for_initialization (return_loc
, type
, val
, flags
,
2704 "default argument", fndecl
, i
);
2705 #ifdef PROMOTE_PROTOTYPES
2706 if ((TREE_CODE (type
) == INTEGER_TYPE
2707 || TREE_CODE (type
) == ENUMERAL_TYPE
)
2708 && (TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
)))
2709 parmval
= default_conversion (parmval
);
2714 && type_needs_gc_entry (TREE_TYPE (parmval
))
2715 && ! value_safe_from_gc (NULL_TREE
, parmval
))
2716 parmval
= protect_value_from_gc (NULL_TREE
, parmval
);
2718 result
= tree_cons (0, parmval
, result
);
2719 typetail
= TREE_CHAIN (typetail
);
2720 /* ends with `...'. */
2721 if (typetail
== NULL_TREE
)
2729 char *buf
= (char *)alloca (32 + strlen (called_thing
));
2730 sprintf (buf
, "too few arguments to %s `%%#D'", called_thing
);
2731 cp_error_at (buf
, fndecl
);
2732 error ("at this point in file");
2735 error ("too few arguments to function");
2736 return error_mark_list
;
2740 return nreverse (result
);
2743 /* Build a binary-operation expression, after performing default
2744 conversions on the operands. CODE is the kind of expression to build. */
2747 build_x_binary_op (code
, arg1
, arg2
)
2748 enum tree_code code
;
2751 tree rval
= build_opfncall (code
, LOOKUP_SPECULATIVELY
,
2752 arg1
, arg2
, NULL_TREE
);
2754 return build_opfncall (code
, LOOKUP_NORMAL
, arg1
, arg2
, NULL_TREE
);
2755 if (code
== MEMBER_REF
)
2756 return build_m_component_ref (build_indirect_ref (arg1
, NULL_PTR
),
2758 return build_binary_op (code
, arg1
, arg2
, 1);
2762 build_binary_op (code
, arg1
, arg2
, convert_p
)
2763 enum tree_code code
;
2776 args
[0] = args_save
[0] = default_conversion (args
[0]);
2777 args
[1] = args_save
[1] = default_conversion (args
[1]);
2779 if (args
[0] == error_mark_node
|| args
[1] == error_mark_node
)
2780 return error_mark_node
;
2782 type0
= TREE_TYPE (args
[0]);
2783 type1
= TREE_TYPE (args
[1]);
2785 if (type_unknown_p (args
[0]))
2787 args
[0] = instantiate_type (type1
, args
[0], 1);
2788 args
[0] = default_conversion (args
[0]);
2790 else if (type_unknown_p (args
[1]))
2792 args
[1] = require_instantiated_type (type0
, args
[1],
2794 args
[1] = default_conversion (args
[1]);
2797 if (IS_AGGR_TYPE (type0
) || IS_AGGR_TYPE (type1
))
2799 /* Try to convert this to something reasonable. */
2800 if (! build_default_binary_type_conversion(code
, &args
[0], &args
[1]))
2802 cp_error ("no match for `%O(%#T, %#T)'", code
,
2803 TREE_TYPE (arg1
), TREE_TYPE (arg2
));
2804 return error_mark_node
;
2808 if (args
[0] == args_save
[0])
2810 if (args
[1] == args_save
[1])
2813 return build_binary_op_nodefault (code
, args
[0], args
[1], code
);
2816 /* Build a binary-operation expression without default conversions.
2817 CODE is the kind of expression to build.
2818 This function differs from `build' in several ways:
2819 the data type of the result is computed and recorded in it,
2820 warnings are generated if arg data types are invalid,
2821 special handling for addition and subtraction of pointers is known,
2822 and some optimization is done (operations on narrow ints
2823 are done in the narrower type when that gives the same result).
2824 Constant folding is also done before the result is returned.
2826 ERROR_CODE is the code that determines what to say in error messages.
2827 It is usually, but not always, the same as CODE.
2829 Note that the operands will never have enumeral types
2830 because either they have just had the default conversions performed
2831 or they have both just been converted to some other type in which
2832 the arithmetic is to be done.
2834 C++: must do special pointer arithmetic when implementing
2835 multiple inheritance, and deal with pointer to member functions. */
2838 build_binary_op_nodefault (code
, orig_op0
, orig_op1
, error_code
)
2839 enum tree_code code
;
2840 tree orig_op0
, orig_op1
;
2841 enum tree_code error_code
;
2844 register enum tree_code code0
, code1
;
2847 /* Expression code to give to the expression when it is built.
2848 Normally this is CODE, which is what the caller asked for,
2849 but in some special cases we change it. */
2850 register enum tree_code resultcode
= code
;
2852 /* Data type in which the computation is to be performed.
2853 In the simplest cases this is the common type of the arguments. */
2854 register tree result_type
= NULL
;
2856 /* Nonzero means operands have already been type-converted
2857 in whatever way is necessary.
2858 Zero means they need to be converted to RESULT_TYPE. */
2861 /* Nonzero means create the expression with this type, rather than
2863 tree build_type
= 0;
2865 /* Nonzero means after finally constructing the expression
2866 give it this type. Otherwise, give it type RESULT_TYPE. */
2867 tree final_type
= 0;
2869 /* Nonzero if this is an operation like MIN or MAX which can
2870 safely be computed in short if both args are promoted shorts.
2871 Also implies COMMON.
2872 -1 indicates a bitwise operation; this makes a difference
2873 in the exact conditions for when it is safe to do the operation
2874 in a narrower mode. */
2877 /* Nonzero if this is a comparison operation;
2878 if both args are promoted shorts, compare the original shorts.
2879 Also implies COMMON. */
2880 int short_compare
= 0;
2882 /* Nonzero if this is a right-shift operation, which can be computed on the
2883 original short and then promoted if the operand is a promoted short. */
2884 int short_shift
= 0;
2886 /* Nonzero means set RESULT_TYPE to the common type of the args. */
2889 /* Apply default conversions. */
2890 op0
= default_conversion (orig_op0
);
2891 op1
= default_conversion (orig_op1
);
2893 type0
= TREE_TYPE (op0
);
2894 type1
= TREE_TYPE (op1
);
2896 /* The expression codes of the data types of the arguments tell us
2897 whether the arguments are integers, floating, pointers, etc. */
2898 code0
= TREE_CODE (type0
);
2899 code1
= TREE_CODE (type1
);
2901 /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
2902 STRIP_TYPE_NOPS (op0
);
2903 STRIP_TYPE_NOPS (op1
);
2905 /* If an error was already reported for one of the arguments,
2906 avoid reporting another error. */
2908 if (code0
== ERROR_MARK
|| code1
== ERROR_MARK
)
2909 return error_mark_node
;
2914 /* Handle the pointer + int case. */
2915 if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
2916 return pointer_int_sum (PLUS_EXPR
, op0
, op1
);
2917 else if (code1
== POINTER_TYPE
&& code0
== INTEGER_TYPE
)
2918 return pointer_int_sum (PLUS_EXPR
, op1
, op0
);
2924 /* Subtraction of two similar pointers.
2925 We must subtract them as integers, then divide by object size. */
2926 if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
2927 && comp_target_types (type0
, type1
, 1))
2928 return pointer_diff (op0
, op1
);
2929 /* Handle pointer minus int. Just like pointer plus int. */
2930 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
2931 return pointer_int_sum (MINUS_EXPR
, op0
, op1
);
2940 case TRUNC_DIV_EXPR
:
2942 case FLOOR_DIV_EXPR
:
2943 case ROUND_DIV_EXPR
:
2944 case EXACT_DIV_EXPR
:
2945 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
2946 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
2948 if (TREE_CODE (op1
) == INTEGER_CST
&& integer_zerop (op1
))
2949 cp_warning ("division by zero in `%E / 0'", op0
);
2950 else if (TREE_CODE (op1
) == REAL_CST
&& real_zerop (op1
))
2951 cp_warning ("division by zero in `%E / 0.'", op0
);
2953 if (!(code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
))
2954 resultcode
= RDIV_EXPR
;
2956 /* When dividing two signed integers, we have to promote to int.
2957 unless we divide by a conatant != -1. Note that default
2958 conversion will have been performed on the operands at this
2959 point, so we have to dig out the original type to find out if
2961 shorten
= ((TREE_CODE (op0
) == NOP_EXPR
2962 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0
, 0))))
2963 || (TREE_CODE (op1
) == INTEGER_CST
2964 && (TREE_INT_CST_LOW (op1
) != -1
2965 || TREE_INT_CST_HIGH (op1
) != -1)));
2971 case BIT_ANDTC_EXPR
:
2974 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
2976 /* If one operand is a constant, and the other is a short type
2977 that has been converted to an int,
2978 really do the work in the short type and then convert the
2979 result to int. If we are lucky, the constant will be 0 or 1
2980 in the short type, making the entire operation go away. */
2981 if (TREE_CODE (op0
) == INTEGER_CST
2982 && TREE_CODE (op1
) == NOP_EXPR
2983 && TYPE_PRECISION (type1
) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op1
, 0)))
2984 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op1
, 0))))
2986 final_type
= result_type
;
2987 op1
= TREE_OPERAND (op1
, 0);
2988 result_type
= TREE_TYPE (op1
);
2990 if (TREE_CODE (op1
) == INTEGER_CST
2991 && TREE_CODE (op0
) == NOP_EXPR
2992 && TYPE_PRECISION (type0
) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0
, 0)))
2993 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0
, 0))))
2995 final_type
= result_type
;
2996 op0
= TREE_OPERAND (op0
, 0);
2997 result_type
= TREE_TYPE (op0
);
3001 case TRUNC_MOD_EXPR
:
3002 case FLOOR_MOD_EXPR
:
3003 if (code1
== INTEGER_TYPE
&& integer_zerop (op1
))
3004 cp_warning ("division by zero in `%E % 0'", op0
);
3005 else if (code1
== REAL_TYPE
&& real_zerop (op1
))
3006 cp_warning ("division by zero in `%E % 0.'", op0
);
3008 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3010 /* Although it would be tempting to shorten always here, that loses
3011 on some targets, since the modulo instruction is undefined if the
3012 quotient can't be represented in the computation mode. We shorten
3013 only if unsigned or if dividing by something we know != -1. */
3014 shorten
= ((TREE_CODE (op0
) == NOP_EXPR
3015 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0
, 0))))
3016 || (TREE_CODE (op1
) == INTEGER_CST
3017 && (TREE_INT_CST_LOW (op1
) != -1
3018 || TREE_INT_CST_HIGH (op1
) != -1)));
3023 case TRUTH_ANDIF_EXPR
:
3024 case TRUTH_ORIF_EXPR
:
3025 case TRUTH_AND_EXPR
:
3027 result_type
= boolean_type_node
;
3030 /* Shift operations: result has same type as first operand;
3031 always convert second operand to int.
3032 Also set SHORT_SHIFT if shifting rightward. */
3035 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3037 result_type
= type0
;
3038 if (TREE_CODE (op1
) == INTEGER_CST
)
3040 if (tree_int_cst_lt (op1
, integer_zero_node
))
3041 warning ("right shift count is negative");
3044 if (TREE_INT_CST_LOW (op1
) | TREE_INT_CST_HIGH (op1
))
3046 if (TREE_INT_CST_HIGH (op1
) != 0
3047 || ((unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (op1
)
3048 >= TYPE_PRECISION (type0
)))
3049 warning ("right shift count >= width of type");
3052 /* Convert the shift-count to an integer, regardless of
3053 size of value being shifted. */
3054 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
3055 op1
= convert (integer_type_node
, op1
);
3056 /* Avoid converting op1 to result_type later. */
3062 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3064 result_type
= type0
;
3065 if (TREE_CODE (op1
) == INTEGER_CST
)
3067 if (tree_int_cst_lt (op1
, integer_zero_node
))
3068 warning ("left shift count is negative");
3069 else if (TREE_INT_CST_HIGH (op1
) != 0
3070 || ((unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (op1
)
3071 >= TYPE_PRECISION (type0
)))
3072 warning ("left shift count >= width of type");
3074 /* Convert the shift-count to an integer, regardless of
3075 size of value being shifted. */
3076 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
3077 op1
= convert (integer_type_node
, op1
);
3078 /* Avoid converting op1 to result_type later. */
3085 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3087 result_type
= type0
;
3088 if (TREE_CODE (op1
) == INTEGER_CST
)
3090 if (tree_int_cst_lt (op1
, integer_zero_node
))
3091 warning ("%s rotate count is negative",
3092 (code
== LROTATE_EXPR
) ? "left" : "right");
3093 else if (TREE_INT_CST_HIGH (op1
) != 0
3094 || ((unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (op1
)
3095 >= TYPE_PRECISION (type0
)))
3096 warning ("%s rotate count >= width of type",
3097 (code
== LROTATE_EXPR
) ? "left" : "right");
3099 /* Convert the shift-count to an integer, regardless of
3100 size of value being shifted. */
3101 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
3102 op1
= convert (integer_type_node
, op1
);
3108 build_type
= boolean_type_node
;
3109 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
3110 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
3112 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
3114 register tree tt0
= TYPE_MAIN_VARIANT (TREE_TYPE (type0
));
3115 register tree tt1
= TYPE_MAIN_VARIANT (TREE_TYPE (type1
));
3117 if (comp_target_types (type0
, type1
, 1))
3118 result_type
= common_type (type0
, type1
);
3119 else if (tt0
== void_type_node
)
3121 if (pedantic
&& TREE_CODE (tt1
) == FUNCTION_TYPE
3122 && tree_int_cst_lt (TYPE_SIZE (type0
), TYPE_SIZE (type1
)))
3123 pedwarn ("ANSI C++ forbids comparison of `void *' with function pointer");
3124 else if (TREE_CODE (tt1
) == OFFSET_TYPE
)
3125 pedwarn ("ANSI C++ forbids conversion of a pointer to member to `void *'");
3127 else if (tt1
== void_type_node
)
3129 if (pedantic
&& TREE_CODE (tt0
) == FUNCTION_TYPE
3130 && tree_int_cst_lt (TYPE_SIZE (type1
), TYPE_SIZE (type0
)))
3131 pedwarn ("ANSI C++ forbids comparison of `void *' with function pointer");
3133 else if ((TYPE_SIZE (tt0
) != 0) != (TYPE_SIZE (tt1
) != 0))
3134 cp_pedwarn ("comparison of %scomplete and %scomplete pointers `%T' and `%T'",
3135 TYPE_SIZE (tt0
) == 0 ? "in" : "",
3136 TYPE_SIZE (tt1
) == 0 ? "in" : "",
3139 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3142 else if (code0
== POINTER_TYPE
&& TREE_CODE (op1
) == INTEGER_CST
3143 && integer_zerop (op1
))
3144 op1
= null_pointer_node
;
3145 else if (code1
== POINTER_TYPE
&& TREE_CODE (op0
) == INTEGER_CST
3146 && integer_zerop (op0
))
3147 op0
= null_pointer_node
;
3148 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
3150 error ("ANSI C++ forbids comparison between pointer and integer");
3151 op1
= convert (TREE_TYPE (op0
), op1
);
3153 else if (code0
== INTEGER_TYPE
&& code1
== POINTER_TYPE
)
3155 error ("ANSI C++ forbids comparison between pointer and integer");
3156 op0
= convert (TREE_TYPE (op1
), op0
);
3158 else if (TYPE_PTRMEMFUNC_P (type0
) && TREE_CODE (op1
) == INTEGER_CST
3159 && integer_zerop (op1
))
3161 op0
= build_component_ref (op0
, index_identifier
, 0, 0);
3162 op1
= integer_zero_node
;
3164 else if (TYPE_PTRMEMFUNC_P (type1
) && TREE_CODE (op0
) == INTEGER_CST
3165 && integer_zerop (op0
))
3167 op0
= build_component_ref (op1
, index_identifier
, 0, 0);
3168 op1
= integer_zero_node
;
3170 else if (TYPE_PTRMEMFUNC_P (type0
) && TYPE_PTRMEMFUNC_P (type1
)
3171 && (TYPE_PTRMEMFUNC_FN_TYPE (type0
)
3172 == TYPE_PTRMEMFUNC_FN_TYPE (type1
)))
3174 /* The code we generate for the test is:
3176 (op0.index == op1.index
3177 && ((op1.index != -1 && op0.delta2 == op1.delta2)
3178 || op0.pfn == op1.pfn)) */
3180 tree index0
= build_component_ref (op0
, index_identifier
, 0, 0);
3181 tree index1
= save_expr (build_component_ref (op1
, index_identifier
, 0, 0));
3182 tree pfn0
= PFN_FROM_PTRMEMFUNC (op0
);
3183 tree pfn1
= PFN_FROM_PTRMEMFUNC (op1
);
3184 tree delta20
= DELTA2_FROM_PTRMEMFUNC (op0
);
3185 tree delta21
= DELTA2_FROM_PTRMEMFUNC (op1
);
3187 tree integer_neg_one_node
3188 = build_binary_op (MINUS_EXPR
, integer_zero_node
, integer_one_node
, 1);
3189 e1
= build_binary_op (EQ_EXPR
, index0
, index1
, 1);
3190 e2
= build_binary_op (NE_EXPR
, index1
, integer_neg_one_node
, 1);
3191 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e2
, build_binary_op (EQ_EXPR
, delta20
, delta21
, 1), 1);
3192 e3
= build_binary_op (EQ_EXPR
, pfn0
, pfn1
, 1);
3193 e2
= build_binary_op (TRUTH_ORIF_EXPR
, e2
, e3
, 1);
3194 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e1
, e2
, 1);
3195 if (code
== EQ_EXPR
)
3197 return build_binary_op (EQ_EXPR
, e2
, integer_zero_node
, 1);
3199 else if (TYPE_PTRMEMFUNC_P (type0
)
3200 && TYPE_PTRMEMFUNC_FN_TYPE (type0
) == type1
)
3202 tree index0
= build_component_ref (op0
, index_identifier
, 0, 0);
3204 tree pfn0
= PFN_FROM_PTRMEMFUNC (op0
);
3205 tree delta20
= DELTA2_FROM_PTRMEMFUNC (op0
);
3206 tree delta21
= integer_zero_node
;
3208 tree integer_neg_one_node
3209 = build_binary_op (MINUS_EXPR
, integer_zero_node
, integer_one_node
, 1);
3210 if (TREE_CODE (TREE_OPERAND (op1
, 0)) == FUNCTION_DECL
3211 && DECL_VINDEX (TREE_OPERAND (op1
, 0)))
3213 /* Map everything down one to make room for the null pointer to member. */
3214 index1
= size_binop (PLUS_EXPR
,
3215 DECL_VINDEX (TREE_OPERAND (op1
, 0)),
3217 op1
= integer_zero_node
;
3218 delta21
= CLASSTYPE_VFIELD (TYPE_METHOD_BASETYPE (TREE_TYPE (type1
)));
3219 delta21
= DECL_FIELD_BITPOS (delta21
);
3220 delta21
= size_binop (FLOOR_DIV_EXPR
, delta21
, size_int (BITS_PER_UNIT
));
3223 index1
= integer_neg_one_node
;
3225 tree nop1
= build1 (NOP_EXPR
, TYPE_PTRMEMFUNC_FN_TYPE (type0
), op1
);
3226 TREE_CONSTANT (nop1
) = TREE_CONSTANT (op1
);
3229 e1
= build_binary_op (EQ_EXPR
, index0
, index1
, 1);
3230 e2
= build_binary_op (NE_EXPR
, index1
, integer_neg_one_node
, 1);
3231 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e2
, build_binary_op (EQ_EXPR
, delta20
, delta21
, 1), 1);
3232 e3
= build_binary_op (EQ_EXPR
, pfn0
, op1
, 1);
3233 e2
= build_binary_op (TRUTH_ORIF_EXPR
, e2
, e3
, 1);
3234 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e1
, e2
, 1);
3235 if (code
== EQ_EXPR
)
3237 return build_binary_op (EQ_EXPR
, e2
, integer_zero_node
, 1);
3239 else if (TYPE_PTRMEMFUNC_P (type1
)
3240 && TYPE_PTRMEMFUNC_FN_TYPE (type1
) == type0
)
3242 return build_binary_op (code
, op1
, op0
, 1);
3245 type0
= TREE_TYPE (op0
);
3246 type1
= TREE_TYPE (op1
);
3247 if (result_type
== NULL_TREE
)
3248 result_type
= type0
;
3253 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
3254 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
3256 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
3258 if (! comp_target_types (type0
, type1
, 1))
3260 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3262 result_type
= ptr_type_node
;
3265 else if ((TYPE_SIZE (TREE_TYPE (type0
)) != 0)
3266 != (TYPE_SIZE (TREE_TYPE (type1
)) != 0))
3267 cp_pedwarn ("comparison of %scomplete and %scomplete pointers",
3268 TYPE_SIZE (TREE_TYPE (type0
)) == 0 ? "in" : "",
3269 TYPE_SIZE (TREE_TYPE (type1
)) == 0 ? "in" : "",
3272 && TREE_CODE (TREE_TYPE (type0
)) == FUNCTION_TYPE
)
3273 pedwarn ("ANSI C++ forbids ordered comparisons of pointers to functions");
3276 result_type
= common_type (type0
, type1
);
3279 if (result_type
== NULL_TREE
)
3280 result_type
= type0
;
3287 build_type
= boolean_type_node
;
3288 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
3289 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
3291 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
3293 if (! comp_target_types (type0
, type1
, 1))
3294 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3297 else if ((TYPE_SIZE (TREE_TYPE (type0
)) != 0)
3298 != (TYPE_SIZE (TREE_TYPE (type1
)) != 0))
3299 cp_pedwarn ("comparison of %scomplete and %scomplete pointers",
3300 TYPE_SIZE (TREE_TYPE (type0
)) == 0 ? "in" : "",
3301 TYPE_SIZE (TREE_TYPE (type1
)) == 0 ? "in" : "",
3304 && TREE_CODE (TREE_TYPE (type0
)) == FUNCTION_TYPE
)
3305 pedwarn ("ANSI C++ forbids ordered comparisons of pointers to functions");
3308 result_type
= common_type (type0
, type1
);
3310 else if (code0
== POINTER_TYPE
&& TREE_CODE (op1
) == INTEGER_CST
3311 && integer_zerop (op1
))
3312 op1
= null_pointer_node
;
3313 else if (code1
== POINTER_TYPE
&& TREE_CODE (op0
) == INTEGER_CST
3314 && integer_zerop (op0
))
3315 op0
= null_pointer_node
;
3316 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
3319 pedwarn ("ANSI C++ forbids comparison between pointer and integer");
3320 else if (! flag_traditional
)
3321 warning ("comparison between pointer and integer");
3322 op1
= convert (TREE_TYPE (op0
), op1
);
3324 else if (code0
== INTEGER_TYPE
&& code1
== POINTER_TYPE
)
3327 pedwarn ("ANSI C++ forbids comparison between pointer and integer");
3328 else if (! flag_traditional
)
3329 warning ("comparison between pointer and integer");
3330 op0
= convert (TREE_TYPE (op1
), op0
);
3333 type0
= TREE_TYPE (op0
);
3334 type1
= TREE_TYPE (op1
);
3335 if (result_type
== NULL_TREE
)
3336 result_type
= type0
;
3340 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
3341 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
3343 if (shorten
|| common
|| short_compare
)
3344 result_type
= common_type (type0
, type1
);
3346 /* For certain operations (which identify themselves by shorten != 0)
3347 if both args were extended from the same smaller type,
3348 do the arithmetic in that type and then extend.
3350 shorten !=0 and !=1 indicates a bitwise operation.
3351 For them, this optimization is safe only if
3352 both args are zero-extended or both are sign-extended.
3353 Otherwise, we might change the result.
3354 Eg, (short)-1 | (unsigned short)-1 is (int)-1
3355 but calculated in (unsigned short) it would be (unsigned short)-1. */
3359 int unsigned0
, unsigned1
;
3360 tree arg0
= get_narrower (op0
, &unsigned0
);
3361 tree arg1
= get_narrower (op1
, &unsigned1
);
3362 /* UNS is 1 if the operation to be done is an unsigned one. */
3363 int uns
= TREE_UNSIGNED (result_type
);
3366 final_type
= result_type
;
3368 /* Handle the case that OP0 does not *contain* a conversion
3369 but it *requires* conversion to FINAL_TYPE. */
3371 if (op0
== arg0
&& TREE_TYPE (op0
) != final_type
)
3372 unsigned0
= TREE_UNSIGNED (TREE_TYPE (op0
));
3373 if (op1
== arg1
&& TREE_TYPE (op1
) != final_type
)
3374 unsigned1
= TREE_UNSIGNED (TREE_TYPE (op1
));
3376 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
3378 /* For bitwise operations, signedness of nominal type
3379 does not matter. Consider only how operands were extended. */
3383 /* Note that in all three cases below we refrain from optimizing
3384 an unsigned operation on sign-extended args.
3385 That would not be valid. */
3387 /* Both args variable: if both extended in same way
3388 from same width, do it in that width.
3389 Do it unsigned if args were zero-extended. */
3390 if ((TYPE_PRECISION (TREE_TYPE (arg0
))
3391 < TYPE_PRECISION (result_type
))
3392 && (TYPE_PRECISION (TREE_TYPE (arg1
))
3393 == TYPE_PRECISION (TREE_TYPE (arg0
)))
3394 && unsigned0
== unsigned1
3395 && (unsigned0
|| !uns
))
3397 = signed_or_unsigned_type (unsigned0
,
3398 common_type (TREE_TYPE (arg0
), TREE_TYPE (arg1
)));
3399 else if (TREE_CODE (arg0
) == INTEGER_CST
3400 && (unsigned1
|| !uns
)
3401 && (TYPE_PRECISION (TREE_TYPE (arg1
))
3402 < TYPE_PRECISION (result_type
))
3403 && (type
= signed_or_unsigned_type (unsigned1
,
3405 int_fits_type_p (arg0
, type
)))
3407 else if (TREE_CODE (arg1
) == INTEGER_CST
3408 && (unsigned0
|| !uns
)
3409 && (TYPE_PRECISION (TREE_TYPE (arg0
))
3410 < TYPE_PRECISION (result_type
))
3411 && (type
= signed_or_unsigned_type (unsigned0
,
3413 int_fits_type_p (arg1
, type
)))
3417 /* Shifts can be shortened if shifting right. */
3422 tree arg0
= get_narrower (op0
, &unsigned_arg
);
3424 final_type
= result_type
;
3426 if (arg0
== op0
&& final_type
== TREE_TYPE (op0
))
3427 unsigned_arg
= TREE_UNSIGNED (TREE_TYPE (op0
));
3429 if (TYPE_PRECISION (TREE_TYPE (arg0
)) < TYPE_PRECISION (result_type
)
3430 /* We can shorten only if the shift count is less than the
3431 number of bits in the smaller type size. */
3432 && TREE_INT_CST_HIGH (op1
) == 0
3433 && TYPE_PRECISION (TREE_TYPE (arg0
)) > TREE_INT_CST_LOW (op1
)
3434 /* If arg is sign-extended and then unsigned-shifted,
3435 we can simulate this with a signed shift in arg's type
3436 only if the extended result is at least twice as wide
3437 as the arg. Otherwise, the shift could use up all the
3438 ones made by sign-extension and bring in zeros.
3439 We can't optimize that case at all, but in most machines
3440 it never happens because available widths are 2**N. */
3441 && (!TREE_UNSIGNED (final_type
)
3443 || ((unsigned) 2 * TYPE_PRECISION (TREE_TYPE (arg0
))
3444 <= TYPE_PRECISION (result_type
))))
3446 /* Do an unsigned shift if the operand was zero-extended. */
3448 = signed_or_unsigned_type (unsigned_arg
,
3450 /* Convert value-to-be-shifted to that type. */
3451 if (TREE_TYPE (op0
) != result_type
)
3452 op0
= convert (result_type
, op0
);
3457 /* Comparison operations are shortened too but differently.
3458 They identify themselves by setting short_compare = 1. */
3462 /* Don't write &op0, etc., because that would prevent op0
3463 from being kept in a register.
3464 Instead, make copies of the our local variables and
3465 pass the copies by reference, then copy them back afterward. */
3466 tree xop0
= op0
, xop1
= op1
, xresult_type
= result_type
;
3467 enum tree_code xresultcode
= resultcode
;
3469 = shorten_compare (&xop0
, &xop1
, &xresult_type
, &xresultcode
);
3471 return convert (boolean_type_node
, val
);
3472 op0
= xop0
, op1
= xop1
;
3474 resultcode
= xresultcode
;
3477 if (short_compare
&& extra_warnings
)
3479 int op0_signed
= ! TREE_UNSIGNED (TREE_TYPE (orig_op0
));
3480 int op1_signed
= ! TREE_UNSIGNED (TREE_TYPE (orig_op1
));
3482 tree comp_type
= TREE_TYPE (op0
);
3484 int unsignedp0
, unsignedp1
;
3485 tree primop0
= get_narrower (op0
, &unsignedp0
);
3486 tree primop1
= get_narrower (op1
, &unsignedp1
);
3488 /* Give warnings for comparisons between signed and unsigned
3489 quantities that may fail. Do not warn if the signed quantity
3490 is an unsuffixed integer literal (or some static constant
3491 expression involving such literals) and it is positive.
3492 Do not warn if the comparison is being done in a signed type,
3493 since the signed type will only be chosen if it can represent
3494 all the values of the unsigned type. */
3495 /* Do the checking based on the original operand trees, so that
3496 casts will be considered, but default promotions won't be. */
3497 if (TREE_UNSIGNED (comp_type
)
3498 && ((op0_signed
&& (TREE_CODE (orig_op0
) != INTEGER_CST
3499 || tree_int_cst_sgn (orig_op0
) == -1))
3500 || (op1_signed
&& (TREE_CODE (orig_op1
) != INTEGER_CST
3501 || tree_int_cst_sgn (orig_op1
) == -1))))
3502 warning ("comparison between signed and unsigned");
3504 /* Warn if two unsigned values are being compared in a size
3505 larger than their original size, and one (and only one) is the
3506 result of a `~' operator. This comparison will always fail.
3508 Also warn if one operand is a constant, and the constant does not
3509 have all bits set that are set in the ~ operand when it is
3512 else if (TREE_CODE (primop0
) == BIT_NOT_EXPR
3513 ^ TREE_CODE (primop1
) == BIT_NOT_EXPR
)
3515 if (TREE_CODE (primop0
) == BIT_NOT_EXPR
)
3516 primop0
= get_narrower (TREE_OPERAND (op0
, 0), &unsignedp0
);
3517 if (TREE_CODE (primop1
) == BIT_NOT_EXPR
)
3518 primop1
= get_narrower (TREE_OPERAND (op1
, 0), &unsignedp1
);
3520 if (TREE_CODE (primop0
) == INTEGER_CST
3521 || TREE_CODE (primop1
) == INTEGER_CST
)
3524 HOST_WIDE_INT constant
, mask
;
3528 if (TREE_CODE (primop0
) == INTEGER_CST
)
3531 unsignedp
= unsignedp1
;
3532 constant
= TREE_INT_CST_LOW (primop0
);
3537 unsignedp
= unsignedp0
;
3538 constant
= TREE_INT_CST_LOW (primop1
);
3541 bits
= TYPE_PRECISION (TREE_TYPE (primop
));
3542 if (bits
< TYPE_PRECISION (comp_type
)
3543 && bits
< HOST_BITS_PER_LONG
&& unsignedp
)
3545 mask
= (~ (HOST_WIDE_INT
) 0) << bits
;
3546 if ((mask
& constant
) != mask
)
3547 warning ("comparison of promoted ~unsigned with constant");
3550 else if (unsignedp0
&& unsignedp1
3551 && (TYPE_PRECISION (TREE_TYPE (primop0
))
3552 < TYPE_PRECISION (comp_type
))
3553 && (TYPE_PRECISION (TREE_TYPE (primop1
))
3554 < TYPE_PRECISION (comp_type
)))
3555 warning ("comparison of promoted ~unsigned with unsigned");
3560 /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
3561 If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
3562 Then the expression will be built.
3563 It will be given type FINAL_TYPE if that is nonzero;
3564 otherwise, it will be given type RESULT_TYPE. */
3568 binary_op_error (error_code
);
3569 return error_mark_node
;
3574 if (TREE_TYPE (op0
) != result_type
)
3575 op0
= convert (result_type
, op0
);
3576 if (TREE_TYPE (op1
) != result_type
)
3577 op1
= convert (result_type
, op1
);
3580 if (build_type
== NULL_TREE
)
3581 build_type
= result_type
;
3584 register tree result
= build (resultcode
, build_type
, op0
, op1
);
3585 register tree folded
;
3587 folded
= fold (result
);
3588 if (folded
== result
)
3589 TREE_CONSTANT (folded
) = TREE_CONSTANT (op0
) & TREE_CONSTANT (op1
);
3590 if (final_type
!= 0)
3591 return convert (final_type
, folded
);
3596 /* Return a tree for the sum or difference (RESULTCODE says which)
3597 of pointer PTROP and integer INTOP. */
3600 pointer_int_sum (resultcode
, ptrop
, intop
)
3601 enum tree_code resultcode
;
3602 register tree ptrop
, intop
;
3606 register tree result
;
3607 register tree folded
= fold (intop
);
3609 /* The result is a pointer of the same type that is being added. */
3611 register tree result_type
= TREE_TYPE (ptrop
);
3613 if (TREE_CODE (TREE_TYPE (result_type
)) == VOID_TYPE
)
3615 if (pedantic
|| warn_pointer_arith
)
3616 pedwarn ("ANSI C++ forbids using pointer of type `void *' in arithmetic");
3617 size_exp
= integer_one_node
;
3619 else if (TREE_CODE (TREE_TYPE (result_type
)) == FUNCTION_TYPE
)
3621 if (pedantic
|| warn_pointer_arith
)
3622 pedwarn ("ANSI C++ forbids using pointer to a function in arithmetic");
3623 size_exp
= integer_one_node
;
3625 else if (TREE_CODE (TREE_TYPE (result_type
)) == METHOD_TYPE
)
3627 if (pedantic
|| warn_pointer_arith
)
3628 pedwarn ("ANSI C++ forbids using pointer to a method in arithmetic");
3629 size_exp
= integer_one_node
;
3631 else if (TREE_CODE (TREE_TYPE (result_type
)) == OFFSET_TYPE
)
3634 pedwarn ("ANSI C++ forbids using pointer to a member in arithmetic");
3635 size_exp
= integer_one_node
;
3638 size_exp
= size_in_bytes (TREE_TYPE (result_type
));
3640 /* Needed to make OOPS V2R3 work. */
3642 if (TREE_CODE (intop
) == INTEGER_CST
3643 && TREE_INT_CST_LOW (intop
) == 0
3644 && TREE_INT_CST_HIGH (intop
) == 0)
3647 /* If what we are about to multiply by the size of the elements
3648 contains a constant term, apply distributive law
3649 and multiply that constant term separately.
3650 This helps produce common subexpressions. */
3652 if ((TREE_CODE (intop
) == PLUS_EXPR
|| TREE_CODE (intop
) == MINUS_EXPR
)
3653 && ! TREE_CONSTANT (intop
)
3654 && TREE_CONSTANT (TREE_OPERAND (intop
, 1))
3655 && TREE_CONSTANT (size_exp
))
3657 enum tree_code subcode
= resultcode
;
3658 if (TREE_CODE (intop
) == MINUS_EXPR
)
3659 subcode
= (subcode
== PLUS_EXPR
? MINUS_EXPR
: PLUS_EXPR
);
3660 ptrop
= build_binary_op (subcode
, ptrop
, TREE_OPERAND (intop
, 1), 1);
3661 intop
= TREE_OPERAND (intop
, 0);
3664 /* Convert the integer argument to a type the same size as a pointer
3665 so the multiply won't overflow spuriously. */
3667 if (TYPE_PRECISION (TREE_TYPE (intop
)) != POINTER_SIZE
)
3668 intop
= convert (type_for_size (POINTER_SIZE
, 0), intop
);
3670 /* Replace the integer argument with a suitable product by the object size.
3671 Do this multiplication as signed, then convert to the appropriate
3672 pointer type (actually unsigned integral). */
3674 intop
= convert (result_type
,
3675 build_binary_op (MULT_EXPR
, intop
,
3676 convert (TREE_TYPE (intop
), size_exp
), 1));
3678 /* Create the sum or difference. */
3680 result
= build (resultcode
, result_type
, ptrop
, intop
);
3682 folded
= fold (result
);
3683 if (folded
== result
)
3684 TREE_CONSTANT (folded
) = TREE_CONSTANT (ptrop
) & TREE_CONSTANT (intop
);
3688 /* Return a tree for the difference of pointers OP0 and OP1.
3689 The resulting tree has type int. */
3692 pointer_diff (op0
, op1
)
3693 register tree op0
, op1
;
3695 register tree result
, folded
;
3696 tree restype
= ptrdiff_type_node
;
3697 tree target_type
= TREE_TYPE (TREE_TYPE (op0
));
3701 if (TREE_CODE (target_type
) == VOID_TYPE
)
3702 pedwarn ("ANSI C++ forbids using pointer of type `void *' in subtraction");
3703 if (TREE_CODE (target_type
) == FUNCTION_TYPE
)
3704 pedwarn ("ANSI C++ forbids using pointer to a function in subtraction");
3705 if (TREE_CODE (target_type
) == METHOD_TYPE
)
3706 pedwarn ("ANSI C++ forbids using pointer to a method in subtraction");
3707 if (TREE_CODE (target_type
) == OFFSET_TYPE
)
3708 pedwarn ("ANSI C++ forbids using pointer to a member in subtraction");
3711 /* First do the subtraction as integers;
3712 then drop through to build the divide operator. */
3714 op0
= build_binary_op (MINUS_EXPR
,
3715 convert (restype
, op0
), convert (restype
, op1
), 1);
3717 /* This generates an error if op1 is a pointer to an incomplete type. */
3718 if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (op1
))) == 0)
3719 error ("arithmetic on pointer to an incomplete type");
3721 op1
= ((TREE_CODE (target_type
) == VOID_TYPE
3722 || TREE_CODE (target_type
) == FUNCTION_TYPE
3723 || TREE_CODE (target_type
) == METHOD_TYPE
3724 || TREE_CODE (target_type
) == OFFSET_TYPE
)
3726 : size_in_bytes (target_type
));
3728 /* Do the division. */
3730 result
= build (EXACT_DIV_EXPR
, restype
, op0
, convert (restype
, op1
));
3732 folded
= fold (result
);
3733 if (folded
== result
)
3734 TREE_CONSTANT (folded
) = TREE_CONSTANT (op0
) & TREE_CONSTANT (op1
);
3738 /* Handle the case of taking the address of a COMPONENT_REF.
3739 Called by `build_unary_op' and `build_up_reference'.
3741 ARG is the COMPONENT_REF whose address we want.
3742 ARGTYPE is the pointer type that this address should have.
3743 MSG is an error message to print if this COMPONENT_REF is not
3744 addressable (such as a bitfield). */
3747 build_component_addr (arg
, argtype
, msg
)
3751 tree field
= TREE_OPERAND (arg
, 1);
3752 tree basetype
= decl_type_context (field
);
3753 tree rval
= build_unary_op (ADDR_EXPR
, TREE_OPERAND (arg
, 0), 0);
3755 if (DECL_BIT_FIELD (field
))
3757 error (msg
, IDENTIFIER_POINTER (DECL_NAME (field
)));
3758 return error_mark_node
;
3762 cp_warning ("address of `%T::%D' taken", basetype
, field
);
3764 if (TREE_CODE (field
) == FIELD_DECL
3765 && TYPE_USES_COMPLEX_INHERITANCE (basetype
))
3767 /* Can't convert directly to ARGTYPE, since that
3768 may have the same pointer type as one of our
3770 rval
= build1 (NOP_EXPR
, argtype
,
3771 convert_pointer_to (basetype
, rval
));
3772 TREE_CONSTANT (rval
) = TREE_CONSTANT (TREE_OPERAND (rval
, 0));
3775 /* This conversion is harmless. */
3776 rval
= convert_force (argtype
, rval
, 0);
3778 if (! integer_zerop (DECL_FIELD_BITPOS (field
)))
3780 tree offset
= size_binop (EASY_DIV_EXPR
, DECL_FIELD_BITPOS (field
),
3781 size_int (BITS_PER_UNIT
));
3782 int flag
= TREE_CONSTANT (rval
);
3783 rval
= fold (build (PLUS_EXPR
, argtype
,
3784 rval
, convert (argtype
, offset
)));
3785 TREE_CONSTANT (rval
) = flag
;
3790 /* Construct and perhaps optimize a tree representation
3791 for a unary operation. CODE, a tree_code, specifies the operation
3792 and XARG is the operand. */
3795 build_x_unary_op (code
, xarg
)
3796 enum tree_code code
;
3799 /* & rec, on incomplete RECORD_TYPEs is the simple opr &, not an
3801 if (code
== ADDR_EXPR
3802 && ((IS_AGGR_TYPE_CODE (TREE_CODE (TREE_TYPE (xarg
)))
3803 && TYPE_SIZE (TREE_TYPE (xarg
)) == NULL_TREE
)
3804 || (TREE_CODE (xarg
) == OFFSET_REF
)))
3805 /* don't look for a function */;
3808 tree rval
= build_opfncall (code
, LOOKUP_SPECULATIVELY
, xarg
,
3809 NULL_TREE
, NULL_TREE
);
3811 return build_opfncall (code
, LOOKUP_NORMAL
, xarg
,
3812 NULL_TREE
, NULL_TREE
);
3814 return build_unary_op (code
, xarg
, 0);
3817 /* Just like truthvalue_conversion, but we want a CLEANUP_POINT_EXPR. */
3820 condition_conversion (expr
)
3823 tree t
= convert (boolean_type_node
, expr
);
3824 t
= fold (build1 (CLEANUP_POINT_EXPR
, boolean_type_node
, t
));
3828 /* C++: Must handle pointers to members.
3830 Perhaps type instantiation should be extended to handle conversion
3831 from aggregates to types we don't yet know we want? (Or are those
3832 cases typically errors which should be reported?)
3834 NOCONVERT nonzero suppresses the default promotions
3835 (such as from short to int). */
3837 build_unary_op (code
, xarg
, noconvert
)
3838 enum tree_code code
;
3842 /* No default_conversion here. It causes trouble for ADDR_EXPR. */
3843 register tree arg
= xarg
;
3844 register tree argtype
= 0;
3845 char *errstring
= NULL
;
3848 if (arg
== error_mark_node
)
3849 return error_mark_node
;
3854 /* This is used for unary plus, because a CONVERT_EXPR
3855 is enough to prevent anybody from looking inside for
3856 associativity, but won't generate any code. */
3857 if (!(arg
= build_expr_type_conversion
3858 (WANT_ARITH
| WANT_ENUM
| WANT_POINTER
, arg
, 1)))
3859 errstring
= "wrong type argument to unary plus";
3863 arg
= default_conversion (arg
);
3864 arg
= build1 (NON_LVALUE_EXPR
, TREE_TYPE (arg
), arg
);
3869 if (!(arg
= build_expr_type_conversion (WANT_ARITH
| WANT_ENUM
, arg
, 1)))
3870 errstring
= "wrong type argument to unary minus";
3871 else if (!noconvert
)
3872 arg
= default_conversion (arg
);
3876 if (!(arg
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, arg
, 1)))
3877 errstring
= "wrong type argument to bit-complement";
3878 else if (!noconvert
)
3879 arg
= default_conversion (arg
);
3883 if (!(arg
= build_expr_type_conversion (WANT_ARITH
| WANT_ENUM
, arg
, 1)))
3884 errstring
= "wrong type argument to abs";
3885 else if (!noconvert
)
3886 arg
= default_conversion (arg
);
3889 case TRUTH_NOT_EXPR
:
3890 arg
= convert (boolean_type_node
, arg
);
3891 val
= invert_truthvalue (arg
);
3892 if (arg
!= error_mark_node
)
3894 errstring
= "in argument to unary !";
3900 case PREINCREMENT_EXPR
:
3901 case POSTINCREMENT_EXPR
:
3902 case PREDECREMENT_EXPR
:
3903 case POSTDECREMENT_EXPR
:
3904 /* Handle complex lvalues (when permitted)
3905 by reduction to simpler cases. */
3907 val
= unary_complex_lvalue (code
, arg
);
3911 /* Report invalid types. */
3913 if (!(arg
= build_expr_type_conversion (WANT_ARITH
| WANT_POINTER
,
3916 if (code
== PREINCREMENT_EXPR
)
3917 errstring
="no pre-increment operator for type";
3918 else if (code
== POSTINCREMENT_EXPR
)
3919 errstring
="no post-increment operator for type";
3920 else if (code
== PREDECREMENT_EXPR
)
3921 errstring
="no pre-decrement operator for type";
3923 errstring
="no post-decrement operator for type";
3927 /* Report something read-only. */
3929 if (TYPE_READONLY (TREE_TYPE (arg
))
3930 || TREE_READONLY (arg
))
3931 readonly_error (arg
, ((code
== PREINCREMENT_EXPR
3932 || code
== POSTINCREMENT_EXPR
)
3933 ? "increment" : "decrement"),
3938 tree result_type
= TREE_TYPE (arg
);
3940 arg
= get_unwidened (arg
, 0);
3941 argtype
= TREE_TYPE (arg
);
3943 /* ARM $5.2.5 last annotation says this should be forbidden. */
3944 if (TREE_CODE (argtype
) == ENUMERAL_TYPE
)
3945 pedwarn ("ANSI C++ forbids %sing an enum",
3946 (code
== PREINCREMENT_EXPR
|| code
== POSTINCREMENT_EXPR
)
3947 ? "increment" : "decrement");
3949 /* Compute the increment. */
3951 if (TREE_CODE (argtype
) == POINTER_TYPE
)
3953 enum tree_code tmp
= TREE_CODE (TREE_TYPE (argtype
));
3954 if (TYPE_SIZE (TREE_TYPE (argtype
)) == 0)
3955 cp_error ("cannot %s a pointer to incomplete type `%T'",
3956 ((code
== PREINCREMENT_EXPR
3957 || code
== POSTINCREMENT_EXPR
)
3958 ? "increment" : "decrement"), TREE_TYPE (argtype
));
3959 else if (tmp
== FUNCTION_TYPE
|| tmp
== METHOD_TYPE
3960 || tmp
== VOID_TYPE
|| tmp
== OFFSET_TYPE
)
3961 cp_pedwarn ("ANSI C++ forbids %sing a pointer of type `%T'",
3962 ((code
== PREINCREMENT_EXPR
3963 || code
== POSTINCREMENT_EXPR
)
3964 ? "increment" : "decrement"), argtype
);
3965 inc
= c_sizeof_nowarn (TREE_TYPE (argtype
));
3968 inc
= integer_one_node
;
3970 inc
= convert (argtype
, inc
);
3972 /* Handle incrementing a cast-expression. */
3974 switch (TREE_CODE (arg
))
3979 case FIX_TRUNC_EXPR
:
3980 case FIX_FLOOR_EXPR
:
3981 case FIX_ROUND_EXPR
:
3984 tree incremented
, modify
, value
;
3985 if (! lvalue_p (arg
) && pedantic
)
3986 pedwarn ("cast to non-reference type used as lvalue");
3987 arg
= stabilize_reference (arg
);
3988 if (code
== PREINCREMENT_EXPR
|| code
== PREDECREMENT_EXPR
)
3991 value
= save_expr (arg
);
3992 incremented
= build (((code
== PREINCREMENT_EXPR
3993 || code
== POSTINCREMENT_EXPR
)
3994 ? PLUS_EXPR
: MINUS_EXPR
),
3995 argtype
, value
, inc
);
3996 TREE_SIDE_EFFECTS (incremented
) = 1;
3997 modify
= build_modify_expr (arg
, NOP_EXPR
, incremented
);
3998 return build (COMPOUND_EXPR
, TREE_TYPE (arg
), modify
, value
);
4002 /* Complain about anything else that is not a true lvalue. */
4003 if (!lvalue_or_else (arg
, ((code
== PREINCREMENT_EXPR
4004 || code
== POSTINCREMENT_EXPR
)
4005 ? "increment" : "decrement")))
4006 return error_mark_node
;
4008 /* Forbid using -- on `bool'. */
4009 if (TREE_TYPE (arg
) == boolean_type_node
)
4011 if (code
== POSTDECREMENT_EXPR
|| code
== PREDECREMENT_EXPR
)
4013 cp_error ("invalid use of `--' on bool variable `%D'", arg
);
4014 return error_mark_node
;
4017 /* This will only work if someone can convince Kenner to accept
4018 my patch to expand_increment. (jason) */
4019 val
= build (code
, TREE_TYPE (arg
), arg
, inc
);
4021 if (code
== POSTINCREMENT_EXPR
)
4023 arg
= stabilize_reference (arg
);
4024 val
= build (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
4026 TREE_SIDE_EFFECTS (val
) = 1;
4027 arg
= save_expr (arg
);
4028 val
= build (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
4029 val
= build (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
4032 val
= build (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
4037 val
= build (code
, TREE_TYPE (arg
), arg
, inc
);
4039 TREE_SIDE_EFFECTS (val
) = 1;
4040 return convert (result_type
, val
);
4044 /* Note that this operation never does default_conversion
4045 regardless of NOCONVERT. */
4047 argtype
= TREE_TYPE (arg
);
4048 if (TREE_CODE (argtype
) == REFERENCE_TYPE
)
4050 arg
= build1 (CONVERT_EXPR
, build_pointer_type (TREE_TYPE (TREE_TYPE (arg
))), arg
);
4051 TREE_REFERENCE_EXPR (arg
) = 1;
4055 && TREE_CODE (arg
) == FUNCTION_DECL
4057 && DECL_CONTEXT (arg
) == NULL_TREE
4058 && IDENTIFIER_LENGTH (DECL_NAME (arg
)) == 4
4059 && IDENTIFIER_POINTER (DECL_NAME (arg
))[0] == 'm'
4060 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (arg
)), "main"))
4062 pedwarn ("taking address of function `main'");
4064 /* Let &* cancel out to simplify resulting code. */
4065 if (TREE_CODE (arg
) == INDIRECT_REF
)
4067 /* We don't need to have `current_class_decl' wrapped in a
4068 NON_LVALUE_EXPR node. */
4070 return current_class_decl
;
4072 /* Keep `default_conversion' from converting if
4073 ARG is of REFERENCE_TYPE. */
4074 arg
= TREE_OPERAND (arg
, 0);
4075 if (TREE_CODE (TREE_TYPE (arg
)) == REFERENCE_TYPE
)
4077 if (TREE_CODE (arg
) == VAR_DECL
&& DECL_INITIAL (arg
)
4078 && !TREE_SIDE_EFFECTS (DECL_INITIAL (arg
)))
4079 arg
= DECL_INITIAL (arg
);
4080 arg
= build1 (CONVERT_EXPR
, build_pointer_type (TREE_TYPE (TREE_TYPE (arg
))), arg
);
4081 TREE_REFERENCE_EXPR (arg
) = 1;
4082 TREE_CONSTANT (arg
) = TREE_CONSTANT (TREE_OPERAND (arg
, 0));
4084 else if (lvalue_p (arg
))
4085 /* Don't let this be an lvalue. */
4086 return non_lvalue (arg
);
4090 /* For &x[y], return x+y */
4091 if (TREE_CODE (arg
) == ARRAY_REF
)
4093 if (mark_addressable (TREE_OPERAND (arg
, 0)) == 0)
4094 return error_mark_node
;
4095 return build_binary_op (PLUS_EXPR
, TREE_OPERAND (arg
, 0),
4096 TREE_OPERAND (arg
, 1), 1);
4099 /* Uninstantiated types are all functions. Taking the
4100 address of a function is a no-op, so just return the
4103 if (TREE_CODE (arg
) == IDENTIFIER_NODE
4104 && IDENTIFIER_OPNAME_P (arg
))
4106 my_friendly_abort (117);
4107 /* We don't know the type yet, so just work around the problem.
4108 We know that this will resolve to an lvalue. */
4109 return build1 (ADDR_EXPR
, unknown_type_node
, arg
);
4112 if (TREE_CODE (arg
) == TREE_LIST
)
4114 if (TREE_CODE (TREE_VALUE (arg
)) == FUNCTION_DECL
4115 && DECL_CHAIN (TREE_VALUE (arg
)) == NULL_TREE
)
4116 /* Unique overloaded non-member function. */
4117 return build_unary_op (ADDR_EXPR
, TREE_VALUE (arg
), 0);
4118 if (TREE_CHAIN (arg
) == NULL_TREE
4119 && TREE_CODE (TREE_VALUE (arg
)) == TREE_LIST
4120 && DECL_CHAIN (TREE_VALUE (TREE_VALUE (arg
))) == NULL_TREE
)
4121 /* Unique overloaded member function. */
4122 return build_unary_op (ADDR_EXPR
, TREE_VALUE (TREE_VALUE (arg
)),
4124 return build1 (ADDR_EXPR
, unknown_type_node
, arg
);
4127 /* Handle complex lvalues (when permitted)
4128 by reduction to simpler cases. */
4129 val
= unary_complex_lvalue (code
, arg
);
4133 switch (TREE_CODE (arg
))
4138 case FIX_TRUNC_EXPR
:
4139 case FIX_FLOOR_EXPR
:
4140 case FIX_ROUND_EXPR
:
4142 if (! lvalue_p (arg
) && pedantic
)
4143 pedwarn ("taking the address of a cast to non-reference type");
4146 /* Allow the address of a constructor if all the elements
4148 if (TREE_CODE (arg
) == CONSTRUCTOR
&& TREE_CONSTANT (arg
))
4150 /* Anything not already handled and not a true memory reference
4152 else if (TREE_CODE (argtype
) != FUNCTION_TYPE
4153 && TREE_CODE (argtype
) != METHOD_TYPE
4154 && !lvalue_or_else (arg
, "unary `&'"))
4155 return error_mark_node
;
4157 /* Ordinary case; arg is a COMPONENT_REF or a decl. */
4158 /* If the lvalue is const or volatile,
4159 merge that into the type that the address will point to. */
4160 if (TREE_CODE_CLASS (TREE_CODE (arg
)) == 'd'
4161 || TREE_CODE_CLASS (TREE_CODE (arg
)) == 'r')
4163 if (TREE_READONLY (arg
) || TREE_THIS_VOLATILE (arg
))
4164 argtype
= cp_build_type_variant (argtype
,
4165 TREE_READONLY (arg
),
4166 TREE_THIS_VOLATILE (arg
));
4169 argtype
= build_pointer_type (argtype
);
4171 if (mark_addressable (arg
) == 0)
4172 return error_mark_node
;
4177 if (TREE_CODE (arg
) == COMPONENT_REF
)
4178 addr
= build_component_addr (arg
, argtype
,
4179 "attempt to take address of bit-field structure member `%s'");
4181 addr
= build1 (code
, argtype
, arg
);
4183 /* Address of a static or external variable or
4184 function counts as a constant */
4186 TREE_CONSTANT (addr
) = 1;
4194 argtype
= TREE_TYPE (arg
);
4195 return fold (build1 (code
, argtype
, arg
));
4199 return error_mark_node
;
4202 /* If CONVERSIONS is a conversion expression or a nested sequence of such,
4203 convert ARG with the same conversions in the same order
4204 and return the result. */
4207 convert_sequence (conversions
, arg
)
4211 switch (TREE_CODE (conversions
))
4216 case FIX_TRUNC_EXPR
:
4217 case FIX_FLOOR_EXPR
:
4218 case FIX_ROUND_EXPR
:
4220 return convert (TREE_TYPE (conversions
),
4221 convert_sequence (TREE_OPERAND (conversions
, 0),
4229 /* Apply unary lvalue-demanding operator CODE to the expression ARG
4230 for certain kinds of expressions which are not really lvalues
4231 but which we can accept as lvalues.
4233 If ARG is not a kind of expression we can handle, return zero. */
4236 unary_complex_lvalue (code
, arg
)
4237 enum tree_code code
;
4240 /* Handle (a, b) used as an "lvalue". */
4241 if (TREE_CODE (arg
) == COMPOUND_EXPR
)
4243 tree real_result
= build_unary_op (code
, TREE_OPERAND (arg
, 1), 0);
4244 return build (COMPOUND_EXPR
, TREE_TYPE (real_result
),
4245 TREE_OPERAND (arg
, 0), real_result
);
4248 /* Handle (a ? b : c) used as an "lvalue". */
4249 if (TREE_CODE (arg
) == COND_EXPR
)
4250 return rationalize_conditional_expr (code
, arg
);
4252 if (TREE_CODE (arg
) == MODIFY_EXPR
4253 || TREE_CODE (arg
) == PREINCREMENT_EXPR
4254 || TREE_CODE (arg
) == PREDECREMENT_EXPR
)
4255 return unary_complex_lvalue
4256 (code
, build (COMPOUND_EXPR
, TREE_TYPE (TREE_OPERAND (arg
, 0)),
4257 arg
, TREE_OPERAND (arg
, 0)));
4259 if (code
!= ADDR_EXPR
)
4262 /* Handle (a = b) used as an "lvalue" for `&'. */
4263 if (TREE_CODE (arg
) == MODIFY_EXPR
4264 || TREE_CODE (arg
) == INIT_EXPR
)
4266 tree real_result
= build_unary_op (code
, TREE_OPERAND (arg
, 0), 0);
4267 return build (COMPOUND_EXPR
, TREE_TYPE (real_result
), arg
, real_result
);
4270 if (TREE_CODE (arg
) == WITH_CLEANUP_EXPR
)
4272 tree real_result
= build_unary_op (code
, TREE_OPERAND (arg
, 0), 0);
4273 real_result
= build (WITH_CLEANUP_EXPR
, TREE_TYPE (real_result
),
4274 real_result
, 0, TREE_OPERAND (arg
, 2));
4278 if (TREE_CODE (TREE_TYPE (arg
)) == FUNCTION_TYPE
4279 || TREE_CODE (TREE_TYPE (arg
)) == METHOD_TYPE
4280 || TREE_CODE (TREE_TYPE (arg
)) == OFFSET_TYPE
)
4282 /* The representation of something of type OFFSET_TYPE
4283 is really the representation of a pointer to it.
4284 Here give the representation its true type. */
4288 my_friendly_assert (TREE_CODE (arg
) != SCOPE_REF
, 313);
4290 if (TREE_CODE (arg
) != OFFSET_REF
)
4293 t
= TREE_OPERAND (arg
, 1);
4295 if (TREE_CODE (t
) == FUNCTION_DECL
) /* Check all this code for right semantics. */
4296 return build_unary_op (ADDR_EXPR
, t
, 0);
4297 if (TREE_CODE (t
) == VAR_DECL
)
4298 return build_unary_op (ADDR_EXPR
, t
, 0);
4301 if (TREE_OPERAND (arg
, 0)
4302 && (TREE_CODE (TREE_OPERAND (arg
, 0)) != NOP_EXPR
4303 || TREE_OPERAND (TREE_OPERAND (arg
, 0), 0) != error_mark_node
))
4304 if (TREE_CODE (t
) != FIELD_DECL
)
4306 /* Don't know if this should return address to just
4307 _DECL, or actual address resolved in this expression. */
4308 sorry ("address of bound pointer-to-member expression");
4309 return error_mark_node
;
4312 offset
= get_delta_difference (DECL_FIELD_CONTEXT (t
),
4313 TREE_TYPE (TREE_OPERAND (arg
, 0)),
4315 offset
= size_binop (PLUS_EXPR
, offset
,
4316 size_binop (EASY_DIV_EXPR
,
4317 DECL_FIELD_BITPOS (t
),
4318 size_int (BITS_PER_UNIT
)));
4319 return convert (build_pointer_type (TREE_TYPE (arg
)), offset
);
4323 if (TREE_CODE (arg
) == OFFSET_REF
)
4325 tree left
= TREE_OPERAND (arg
, 0), left_addr
;
4326 tree right_addr
= build_unary_op (ADDR_EXPR
, TREE_OPERAND (arg
, 1), 0);
4329 if (current_class_decl
)
4330 left_addr
= current_class_decl
;
4333 error ("no `this' for pointer to member");
4334 return error_mark_node
;
4337 left_addr
= build_unary_op (ADDR_EXPR
, left
, 0);
4339 return build (PLUS_EXPR
, build_pointer_type (TREE_TYPE (arg
)),
4340 build1 (NOP_EXPR
, integer_type_node
, left_addr
),
4341 build1 (NOP_EXPR
, integer_type_node
, right_addr
));
4344 /* We permit compiler to make function calls returning
4345 objects of aggregate type look like lvalues. */
4349 if (TREE_CODE (targ
) == SAVE_EXPR
)
4350 targ
= TREE_OPERAND (targ
, 0);
4352 if (TREE_CODE (targ
) == CALL_EXPR
&& IS_AGGR_TYPE (TREE_TYPE (targ
)))
4354 if (TREE_CODE (arg
) == SAVE_EXPR
)
4357 targ
= build_cplus_new (TREE_TYPE (arg
), arg
, 1);
4358 return build1 (ADDR_EXPR
, TYPE_POINTER_TO (TREE_TYPE (arg
)), targ
);
4361 if (TREE_CODE (arg
) == SAVE_EXPR
&& TREE_CODE (targ
) == INDIRECT_REF
)
4362 return build (SAVE_EXPR
, TYPE_POINTER_TO (TREE_TYPE (arg
)),
4363 TREE_OPERAND (targ
, 0), current_function_decl
, NULL
);
4365 /* We shouldn't wrap WITH_CLEANUP_EXPRs inside of SAVE_EXPRs, but in case
4366 we do, here's how to handle it. */
4367 if (TREE_CODE (arg
) == SAVE_EXPR
&& TREE_CODE (targ
) == WITH_CLEANUP_EXPR
)
4370 /* Not really a bug, but something to turn on when testing. */
4371 compiler_error ("WITH_CLEANUP_EXPR wrapped in SAVE_EXPR");
4373 return unary_complex_lvalue (ADDR_EXPR
, targ
);
4377 /* Don't let anything else be handled specially. */
4381 /* Mark EXP saying that we need to be able to take the
4382 address of it; it should not be allocated in a register.
4383 Value is 1 if successful.
4385 C++: we do not allow `current_class_decl' to be addressable. */
4388 mark_addressable (exp
)
4391 register tree x
= exp
;
4393 if (TREE_ADDRESSABLE (x
) == 1)
4397 switch (TREE_CODE (x
))
4402 x
= TREE_OPERAND (x
, 0);
4406 if (x
== current_class_decl
)
4408 error ("address of `this' not available");
4409 TREE_ADDRESSABLE (x
) = 1; /* so compiler doesn't die later */
4410 put_var_into_stack (x
);
4415 && TREE_READONLY (x
)
4416 && DECL_RTL (x
) != 0
4417 && ! decl_in_memory_p (x
))
4419 /* We thought this would make a good constant variable,
4420 but we were wrong. */
4421 push_obstacks_nochange ();
4422 end_temporary_allocation ();
4424 TREE_ASM_WRITTEN (x
) = 0;
4426 rest_of_decl_compilation (x
, 0, IDENTIFIER_LOCAL_VALUE (x
) == 0, 0);
4427 TREE_ADDRESSABLE (x
) = 1;
4433 /* Caller should not be trying to mark initialized
4434 constant fields addressable. */
4435 my_friendly_assert (DECL_LANG_SPECIFIC (x
) == 0
4436 || DECL_IN_AGGR_P (x
) == 0
4438 || DECL_EXTERNAL (x
), 314);
4442 /* For C++, we don't warn about taking the address of a register
4443 variable for CONST_DECLs; ARM p97 explicitly says it's okay. */
4444 put_var_into_stack (x
);
4445 TREE_ADDRESSABLE (x
) = 1;
4449 /* We have to test both conditions here. The first may
4450 be non-zero in the case of processing a default function.
4451 The second may be non-zero in the case of a template function. */
4452 x
= DECL_MAIN_VARIANT (x
);
4453 if ((DECL_INLINE (x
) || DECL_PENDING_INLINE_INFO (x
))
4454 && (DECL_CONTEXT (x
) == NULL_TREE
4455 || TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (x
))) != 't'
4456 || ! CLASSTYPE_INTERFACE_ONLY (DECL_CONTEXT (x
))))
4458 mark_inline_for_output (x
);
4459 if (x
== current_function_decl
)
4460 DECL_EXTERNAL (x
) = 0;
4462 TREE_ADDRESSABLE (x
) = 1;
4464 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (x
)) = 1;
4472 /* Build and return a conditional expression IFEXP ? OP1 : OP2. */
4475 build_x_conditional_expr (ifexp
, op1
, op2
)
4476 tree ifexp
, op1
, op2
;
4478 tree rval
= NULL_TREE
;
4480 /* See comments in `build_x_binary_op'. */
4482 rval
= build_opfncall (COND_EXPR
, LOOKUP_SPECULATIVELY
, ifexp
, op1
, op2
);
4484 return build_opfncall (COND_EXPR
, LOOKUP_NORMAL
, ifexp
, op1
, op2
);
4486 return build_conditional_expr (ifexp
, op1
, op2
);
4490 build_conditional_expr (ifexp
, op1
, op2
)
4491 tree ifexp
, op1
, op2
;
4493 register tree type1
;
4494 register tree type2
;
4495 register enum tree_code code1
;
4496 register enum tree_code code2
;
4497 register tree result_type
= NULL_TREE
;
4498 tree orig_op1
= op1
, orig_op2
= op2
;
4500 /* If second operand is omitted, it is the same as the first one;
4501 make sure it is calculated only once. */
4505 pedwarn ("ANSI C++ forbids omitting the middle term of a ?: expression");
4506 ifexp
= op1
= save_expr (ifexp
);
4509 ifexp
= truthvalue_conversion (ifexp
);
4511 if (TREE_CODE (ifexp
) == ERROR_MARK
)
4512 return error_mark_node
;
4514 op1
= require_instantiated_type (TREE_TYPE (op2
), op1
, error_mark_node
);
4515 if (op1
== error_mark_node
)
4516 return error_mark_node
;
4517 op2
= require_instantiated_type (TREE_TYPE (op1
), op2
, error_mark_node
);
4518 if (op2
== error_mark_node
)
4519 return error_mark_node
;
4521 /* C++: REFERENCE_TYPES must be dereferenced. */
4522 type1
= TREE_TYPE (op1
);
4523 code1
= TREE_CODE (type1
);
4524 type2
= TREE_TYPE (op2
);
4525 code2
= TREE_CODE (type2
);
4527 if (code1
== REFERENCE_TYPE
)
4529 op1
= convert_from_reference (op1
);
4530 type1
= TREE_TYPE (op1
);
4531 code1
= TREE_CODE (type1
);
4533 if (code2
== REFERENCE_TYPE
)
4535 op2
= convert_from_reference (op2
);
4536 type2
= TREE_TYPE (op2
);
4537 code2
= TREE_CODE (type2
);
4540 #if 1 /* Produces wrong result if within sizeof. Sorry. */
4541 /* Don't promote the operands separately if they promote
4542 the same way. Return the unpromoted type and let the combined
4543 value get promoted if necessary. */
4545 if (TYPE_MAIN_VARIANT (type1
) == TYPE_MAIN_VARIANT (type2
)
4546 && code2
!= ARRAY_TYPE
4548 /* For C++, let the enumeral type come through. */
4549 && code2
!= ENUMERAL_TYPE
4551 && code2
!= FUNCTION_TYPE
4552 && code2
!= METHOD_TYPE
)
4556 if (TREE_CONSTANT (ifexp
)
4557 && (TREE_CODE (ifexp
) == INTEGER_CST
4558 || TREE_CODE (ifexp
) == ADDR_EXPR
))
4559 return (integer_zerop (ifexp
) ? op2
: op1
);
4561 if (TREE_CODE (op1
) == CONST_DECL
)
4562 op1
= DECL_INITIAL (op1
);
4563 else if (TREE_READONLY_DECL_P (op1
))
4564 op1
= decl_constant_value (op1
);
4565 if (TREE_CODE (op2
) == CONST_DECL
)
4566 op2
= DECL_INITIAL (op2
);
4567 else if (TREE_READONLY_DECL_P (op2
))
4568 op2
= decl_constant_value (op2
);
4570 type1
= cp_build_type_variant
4572 TREE_READONLY (op1
) || TREE_READONLY (op2
),
4573 TREE_THIS_VOLATILE (op1
) || TREE_THIS_VOLATILE (op2
));
4574 /* ??? This is a kludge to deal with the fact that
4575 we don't sort out integers and enums properly, yet. */
4576 result
= fold (build (COND_EXPR
, type1
, ifexp
, op1
, op2
));
4577 if (TREE_TYPE (result
) != type1
)
4578 result
= build1 (NOP_EXPR
, type1
, result
);
4583 /* They don't match; promote them both and then try to reconcile them.
4584 But don't permit mismatching enum types. */
4585 if (code1
== ENUMERAL_TYPE
)
4587 if (code2
== ENUMERAL_TYPE
)
4589 message_2_types (error
, "enumeral mismatch in conditional expression: `%s' vs `%s'", type1
, type2
);
4590 return error_mark_node
;
4592 else if (extra_warnings
&& ! IS_AGGR_TYPE_CODE (code2
))
4593 warning ("enumeral and non-enumeral type in conditional expression");
4595 else if (extra_warnings
4596 && code2
== ENUMERAL_TYPE
&& ! IS_AGGR_TYPE_CODE (code1
))
4597 warning ("enumeral and non-enumeral type in conditional expression");
4599 if (code1
!= VOID_TYPE
)
4601 op1
= default_conversion (op1
);
4602 type1
= TREE_TYPE (op1
);
4603 code1
= TREE_CODE (type1
);
4605 if (code2
!= VOID_TYPE
)
4607 op2
= default_conversion (op2
);
4608 type2
= TREE_TYPE (op2
);
4609 code2
= TREE_CODE (type2
);
4612 /* Quickly detect the usual case where op1 and op2 have the same type
4614 if (TYPE_MAIN_VARIANT (type1
) == TYPE_MAIN_VARIANT (type2
))
4617 result_type
= type1
;
4619 result_type
= cp_build_type_variant
4621 TREE_READONLY (op1
) || TREE_READONLY (op2
),
4622 TREE_THIS_VOLATILE (op1
) || TREE_THIS_VOLATILE (op2
));
4624 else if ((code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
)
4625 && (code2
== INTEGER_TYPE
|| code2
== REAL_TYPE
))
4627 result_type
= common_type (type1
, type2
);
4629 else if (code1
== VOID_TYPE
|| code2
== VOID_TYPE
)
4631 if (pedantic
&& (code1
!= VOID_TYPE
|| code2
!= VOID_TYPE
))
4632 pedwarn ("ANSI C++ forbids conditional expr with only one void side");
4633 result_type
= void_type_node
;
4635 else if (code1
== POINTER_TYPE
&& code2
== POINTER_TYPE
)
4637 if (comp_target_types (type1
, type2
, 1))
4638 result_type
= common_type (type1
, type2
);
4639 else if (integer_zerop (op1
) && TREE_TYPE (type1
) == void_type_node
4640 && TREE_CODE (orig_op1
) != NOP_EXPR
)
4641 result_type
= qualify_type (type2
, type1
);
4642 else if (integer_zerop (op2
) && TREE_TYPE (type2
) == void_type_node
4643 && TREE_CODE (orig_op2
) != NOP_EXPR
)
4644 result_type
= qualify_type (type1
, type2
);
4645 else if (TYPE_MAIN_VARIANT (TREE_TYPE (type1
)) == void_type_node
)
4647 if (pedantic
&& TREE_CODE (type2
) == FUNCTION_TYPE
)
4648 pedwarn ("ANSI C++ forbids conditional expr between `void *' and function pointer");
4649 result_type
= qualify_type (type1
, type2
);
4651 else if (TYPE_MAIN_VARIANT (TREE_TYPE (type2
)) == void_type_node
)
4653 if (pedantic
&& TREE_CODE (type1
) == FUNCTION_TYPE
)
4654 pedwarn ("ANSI C++ forbids conditional expr between `void *' and function pointer");
4655 result_type
= qualify_type (type2
, type1
);
4658 else if (comptypes (type2
, type1
, 0))
4659 result_type
= type2
;
4660 else if (IS_AGGR_TYPE (TREE_TYPE (type1
))
4661 && IS_AGGR_TYPE (TREE_TYPE (type2
))
4662 && (result_type
= common_base_type (TREE_TYPE (type1
), TREE_TYPE (type2
))))
4664 if (result_type
== error_mark_node
)
4666 cp_error ("common base type of types `%T' and `%T' is ambiguous",
4667 TREE_TYPE (type1
), TREE_TYPE (type2
));
4668 result_type
= ptr_type_node
;
4673 && result_type
!= TREE_TYPE (type1
)
4674 && result_type
!= TREE_TYPE (type2
))
4675 cp_pedwarn ("`%T' and `%T' converted to `%T *' in conditional expression",
4676 type1
, type2
, result_type
);
4678 result_type
= TYPE_POINTER_TO (result_type
);
4683 pedwarn ("pointer type mismatch in conditional expression");
4684 result_type
= ptr_type_node
;
4687 else if (code1
== POINTER_TYPE
&& code2
== INTEGER_TYPE
)
4689 if (!integer_zerop (op2
))
4690 pedwarn ("pointer/integer type mismatch in conditional expression");
4693 op2
= null_pointer_node
;
4694 #if 0 /* Sez who? */
4695 if (pedantic
&& TREE_CODE (type1
) == FUNCTION_TYPE
)
4696 pedwarn ("ANSI C++ forbids conditional expr between 0 and function pointer");
4699 result_type
= type1
;
4701 else if (code2
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
4703 if (!integer_zerop (op1
))
4704 pedwarn ("pointer/integer type mismatch in conditional expression");
4707 op1
= null_pointer_node
;
4708 #if 0 /* Sez who? */
4709 if (pedantic
&& TREE_CODE (type2
) == FUNCTION_TYPE
)
4710 pedwarn ("ANSI C++ forbids conditional expr between 0 and function pointer");
4713 result_type
= type2
;
4718 /* The match does not look good. If either is
4719 an aggregate value, try converting to a scalar type. */
4720 if (code1
== RECORD_TYPE
&& code2
== RECORD_TYPE
)
4722 message_2_types (error
, "aggregate mismatch in conditional expression: `%s' vs `%s'", type1
, type2
);
4723 return error_mark_node
;
4725 if (code1
== RECORD_TYPE
&& TYPE_HAS_CONVERSION (type1
))
4727 tree tmp
= build_type_conversion (CONVERT_EXPR
, type2
, op1
, 0);
4728 if (tmp
== NULL_TREE
)
4730 cp_error ("aggregate type `%T' could not convert on lhs of `:'", type1
);
4731 return error_mark_node
;
4733 if (tmp
== error_mark_node
)
4734 error ("ambiguous pointer conversion");
4735 result_type
= type2
;
4738 else if (code2
== RECORD_TYPE
&& TYPE_HAS_CONVERSION (type2
))
4740 tree tmp
= build_type_conversion (CONVERT_EXPR
, type1
, op2
, 0);
4741 if (tmp
== NULL_TREE
)
4743 cp_error ("aggregate type `%T' could not convert on rhs of `:'", type2
);
4744 return error_mark_node
;
4746 if (tmp
== error_mark_node
)
4747 error ("ambiguous pointer conversion");
4748 result_type
= type1
;
4751 else if (flag_cond_mismatch
)
4752 result_type
= void_type_node
;
4755 error ("type mismatch in conditional expression");
4756 return error_mark_node
;
4760 if (result_type
!= TREE_TYPE (op1
))
4761 op1
= convert_and_check (result_type
, op1
);
4762 if (result_type
!= TREE_TYPE (op2
))
4763 op2
= convert_and_check (result_type
, op2
);
4766 /* XXX delete me, I've been here for years. */
4767 if (IS_AGGR_TYPE_CODE (code1
))
4769 result_type
= TREE_TYPE (op1
);
4770 if (TREE_CONSTANT (ifexp
))
4771 return (integer_zerop (ifexp
) ? op2
: op1
);
4773 if (TYPE_MODE (result_type
) == BLKmode
)
4775 register tree tempvar
4776 = build_decl (VAR_DECL
, NULL_TREE
, result_type
);
4777 register tree xop1
= build_modify_expr (tempvar
, NOP_EXPR
, op1
);
4778 register tree xop2
= build_modify_expr (tempvar
, NOP_EXPR
, op2
);
4779 register tree result
= fold (build (COND_EXPR
, result_type
,
4780 ifexp
, xop1
, xop2
));
4782 layout_decl (tempvar
, 0);
4783 /* No way to handle variable-sized objects here.
4784 I fear that the entire handling of BLKmode conditional exprs
4785 needs to be redone. */
4786 my_friendly_assert (TREE_CONSTANT (DECL_SIZE (tempvar
)), 315);
4788 = assign_stack_local (DECL_MODE (tempvar
),
4789 (TREE_INT_CST_LOW (DECL_SIZE (tempvar
))
4790 + BITS_PER_UNIT
- 1)
4794 TREE_SIDE_EFFECTS (result
)
4795 = TREE_SIDE_EFFECTS (ifexp
) | TREE_SIDE_EFFECTS (op1
)
4796 | TREE_SIDE_EFFECTS (op2
);
4797 return build (COMPOUND_EXPR
, result_type
, result
, tempvar
);
4802 if (TREE_CONSTANT (ifexp
))
4803 return integer_zerop (ifexp
) ? op2
: op1
;
4805 return fold (build (COND_EXPR
, result_type
, ifexp
, op1
, op2
));
4808 /* Handle overloading of the ',' operator when needed. Otherwise,
4809 this function just builds an expression list. */
4811 build_x_compound_expr (list
)
4814 tree rest
= TREE_CHAIN (list
);
4817 if (rest
== NULL_TREE
)
4818 return build_compound_expr (list
);
4820 result
= build_opfncall (COMPOUND_EXPR
, LOOKUP_NORMAL
,
4821 TREE_VALUE (list
), TREE_VALUE (rest
), NULL_TREE
);
4823 return build_x_compound_expr (tree_cons (NULL_TREE
, result
, TREE_CHAIN (rest
)));
4824 return build_compound_expr (tree_cons (NULL_TREE
, TREE_VALUE (list
),
4825 build_tree_list (NULL_TREE
, build_x_compound_expr (rest
))));
4828 /* Given a list of expressions, return a compound expression
4829 that performs them all and returns the value of the last of them. */
4832 build_compound_expr (list
)
4837 if (TREE_READONLY_DECL_P (TREE_VALUE (list
)))
4838 TREE_VALUE (list
) = decl_constant_value (TREE_VALUE (list
));
4840 if (TREE_CHAIN (list
) == 0)
4842 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
4843 Strip such NOP_EXPRs, since LIST is used in non-lvalue context. */
4844 if (TREE_CODE (list
) == NOP_EXPR
4845 && TREE_TYPE (list
) == TREE_TYPE (TREE_OPERAND (list
, 0)))
4846 list
= TREE_OPERAND (list
, 0);
4848 /* Convert arrays to pointers. */
4849 if (TREE_CODE (TREE_TYPE (TREE_VALUE (list
))) == ARRAY_TYPE
)
4850 return default_conversion (TREE_VALUE (list
));
4852 return TREE_VALUE (list
);
4855 rest
= build_compound_expr (TREE_CHAIN (list
));
4857 if (! TREE_SIDE_EFFECTS (TREE_VALUE (list
)))
4859 /* the left-hand operand of a comma expression is like an expression
4860 statement: we should warn if it doesn't have any side-effects,
4861 unless it was explicitly cast to (void). */
4862 if ((extra_warnings
|| warn_unused
)
4863 && !(TREE_CODE (TREE_VALUE(list
)) == CONVERT_EXPR
4864 && TREE_TYPE (TREE_VALUE(list
)) == void_type_node
))
4865 warning("left-hand operand of comma expression has no effect");
4867 /* When pedantic, a compound expression can be neither an lvalue
4868 nor an integer constant expression. */
4872 #if 0 /* this requires a gcc backend patch to export warn_if_unused_value */
4873 else if (warn_unused
)
4874 warn_if_unused_value (TREE_VALUE(list
));
4877 return build (COMPOUND_EXPR
, TREE_TYPE (rest
),
4878 break_out_cleanups (TREE_VALUE (list
)), rest
);
4888 return (TREE_CODE (t
) == INTEGER_CST
&& integer_zerop (t
));
4891 tree
build_static_cast (type
, expr
)
4894 return build_c_cast (type
, expr
, 0);
4897 tree
build_reinterpret_cast (type
, expr
)
4900 tree intype
= TREE_TYPE (expr
);
4902 if (TYPE_PTRMEMFUNC_P (type
))
4903 type
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
4904 if (TYPE_PTRMEMFUNC_P (intype
))
4905 intype
= TYPE_PTRMEMFUNC_FN_TYPE (intype
);
4907 if (! POINTER_TYPE_P (type
) && ! TREE_CODE (type
) == INTEGER_TYPE
)
4909 cp_error ("reinterpret_cast cannot convert to type `%T'", type
);
4910 return error_mark_node
;
4912 if (! POINTER_TYPE_P (intype
) && ! TREE_CODE (intype
) == INTEGER_TYPE
)
4914 cp_error ("reinterpret_cast cannot convert from type `%T'", type
);
4915 return error_mark_node
;
4917 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_CODE (intype
) != POINTER_TYPE
)
4919 cp_error ("reinterpret_cast cannot convert non-pointer type `%T' to `%T'",
4921 return error_mark_node
;
4923 if (TREE_CODE (intype
) == INTEGER_TYPE
&& TREE_CODE (type
) != POINTER_TYPE
)
4925 cp_error ("reinterpret_cast cannot convert `%T' to non-pointer type `%T'",
4927 return error_mark_node
;
4930 if (TREE_CODE (type
) == POINTER_TYPE
&& TREE_CODE (intype
) == POINTER_TYPE
)
4931 expr
= convert (ptr_type_node
, expr
);
4933 return build_c_cast (type
, expr
, 0);
4936 tree
build_const_cast (type
, expr
)
4939 tree intype
= TREE_TYPE (expr
);
4942 if (TYPE_PTRMEMFUNC_P (type
))
4943 type
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
4944 if (TYPE_PTRMEMFUNC_P (intype
))
4945 intype
= TYPE_PTRMEMFUNC_FN_TYPE (intype
);
4947 if (! POINTER_TYPE_P (type
))
4949 cp_error ("const_cast cannot convert to non-pointer type `%T'", type
);
4950 return error_mark_node
;
4952 if (TREE_CODE (type
) == REFERENCE_TYPE
&& ! real_lvalue_p (expr
))
4954 cp_error ("const_cast cannot convert rvalue to type `%T'", type
);
4955 return error_mark_node
;
4957 if (TREE_CODE (type
) == POINTER_TYPE
&& TREE_CODE (intype
) != POINTER_TYPE
)
4959 cp_error ("const_cast cannot convert non-pointer type `%T' to type `%T'",
4961 return error_mark_node
;
4964 if (TREE_CODE (type
) == REFERENCE_TYPE
)
4966 t1
= TREE_TYPE (type
);
4971 t1
= TREE_TYPE (type
);
4972 t2
= TREE_TYPE (intype
);
4974 for (; TREE_CODE (t1
) == POINTER_TYPE
&& TREE_CODE (t2
) == POINTER_TYPE
;
4975 t1
= TREE_TYPE (t1
), t2
= TREE_TYPE (t2
))
4979 if (TREE_CODE (t1
) == OFFSET_TYPE
&& TREE_CODE (t2
) == OFFSET_TYPE
)
4981 if (TYPE_OFFSET_BASETYPE (t1
) != TYPE_OFFSET_BASETYPE (t2
))
4983 cp_error ("const_cast cannot convert between pointers to members of different types `%T' and `%T'",
4984 TYPE_OFFSET_BASETYPE (t2
), TYPE_OFFSET_BASETYPE (t1
));
4985 return error_mark_node
;
4987 t1
= TREE_TYPE (t1
);
4988 t2
= TREE_TYPE (t2
);
4991 if (TYPE_MAIN_VARIANT (t1
) != TYPE_MAIN_VARIANT (t2
))
4993 cp_error ("const_cast cannot convert unrelated type `%T' to `%T'",
4995 return error_mark_node
;
4998 return build_c_cast (type
, expr
, 0);
5001 /* Build an expression representing a cast to type TYPE of expression EXPR.
5003 ALLOW_NONCONVERTING is true if we should allow non-converting constructors
5004 when doing the cast. */
5007 build_c_cast (type
, expr
, allow_nonconverting
)
5010 int allow_nonconverting
;
5012 register tree value
= expr
;
5014 if (type
== error_mark_node
|| expr
== error_mark_node
)
5015 return error_mark_node
;
5017 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5018 Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */
5019 if (TREE_CODE (type
) != REFERENCE_TYPE
5020 && TREE_CODE (value
) == NOP_EXPR
5021 && TREE_TYPE (value
) == TREE_TYPE (TREE_OPERAND (value
, 0)))
5022 value
= TREE_OPERAND (value
, 0);
5024 if (TREE_TYPE (expr
)
5025 && TREE_CODE (TREE_TYPE (expr
)) == OFFSET_TYPE
5026 && TREE_CODE (type
) != OFFSET_TYPE
)
5027 value
= resolve_offset_ref (value
);
5029 if (TREE_CODE (type
) == ARRAY_TYPE
)
5031 /* Allow casting from T1* to T2[] because Cfront allows it.
5032 NIHCL uses it. It is not valid ANSI C however, and hence, not
5034 if (TREE_CODE (TREE_TYPE (expr
)) == POINTER_TYPE
)
5037 pedwarn ("ANSI C++ forbids casting to an array type");
5038 type
= build_pointer_type (TREE_TYPE (type
));
5042 error ("ANSI C++ forbids casting to an array type");
5043 return error_mark_node
;
5047 if (TREE_CODE (type
) == FUNCTION_TYPE
5048 || TREE_CODE (type
) == METHOD_TYPE
)
5050 cp_error ("casting to function type `%T'", type
);
5051 return error_mark_node
;
5054 if (IS_SIGNATURE (type
))
5056 error ("cast specifies signature type");
5057 return error_mark_node
;
5060 /* If there's only one function in the overloaded space,
5062 if (TREE_CODE (value
) == TREE_LIST
5063 && TREE_CHAIN (value
) == NULL_TREE
)
5064 value
= TREE_VALUE (value
);
5066 if (TREE_CODE (type
) == VOID_TYPE
)
5067 value
= build1 (CONVERT_EXPR
, type
, value
);
5068 else if (TREE_TYPE (value
) == NULL_TREE
5069 || type_unknown_p (value
))
5071 value
= instantiate_type (type
, value
, 1);
5073 if (value
== error_mark_node
)
5074 return error_mark_node
;
5081 /* Convert functions and arrays to pointers and
5082 convert references to their expanded types,
5083 but don't convert any other types. */
5084 if (TREE_CODE (TREE_TYPE (value
)) == FUNCTION_TYPE
5085 || TREE_CODE (TREE_TYPE (value
)) == METHOD_TYPE
5086 || TREE_CODE (TREE_TYPE (value
)) == ARRAY_TYPE
5087 || TREE_CODE (TREE_TYPE (value
)) == REFERENCE_TYPE
)
5088 value
= default_conversion (value
);
5089 otype
= TREE_TYPE (value
);
5091 /* Optionally warn about potentially worrisome casts. */
5094 && TREE_CODE (type
) == POINTER_TYPE
5095 && TREE_CODE (otype
) == POINTER_TYPE
)
5097 /* For C++ we make these regular warnings, rather than
5098 softening them into pedwarns. */
5099 if (TYPE_VOLATILE (TREE_TYPE (otype
))
5100 && ! TYPE_VOLATILE (TREE_TYPE (type
)))
5101 warning ("cast discards `volatile' from pointer target type");
5102 if (TYPE_READONLY (TREE_TYPE (otype
))
5103 && ! TYPE_READONLY (TREE_TYPE (type
)))
5104 warning ("cast discards `const' from pointer target type");
5107 /* Warn about possible alignment problems. */
5108 if (STRICT_ALIGNMENT
&& warn_cast_align
5109 && TREE_CODE (type
) == POINTER_TYPE
5110 && TREE_CODE (otype
) == POINTER_TYPE
5111 && TREE_CODE (TREE_TYPE (otype
)) != VOID_TYPE
5112 && TREE_CODE (TREE_TYPE (otype
)) != FUNCTION_TYPE
5113 && TYPE_ALIGN (TREE_TYPE (type
)) > TYPE_ALIGN (TREE_TYPE (otype
)))
5114 warning ("cast increases required alignment of target type");
5117 if (TREE_CODE (type
) == INTEGER_TYPE
5118 && TREE_CODE (otype
) == POINTER_TYPE
5119 && TYPE_PRECISION (type
) != TYPE_PRECISION (otype
))
5120 warning ("cast from pointer to integer of different size");
5122 if (TREE_CODE (type
) == POINTER_TYPE
5123 && TREE_CODE (otype
) == INTEGER_TYPE
5124 && TYPE_PRECISION (type
) != TYPE_PRECISION (otype
)
5125 /* Don't warn about converting 0 to pointer,
5126 provided the 0 was explicit--not cast or made by folding. */
5127 && !(TREE_CODE (value
) == INTEGER_CST
&& integer_zerop (value
)))
5128 warning ("cast to pointer from integer of different size");
5131 flag
= allow_nonconverting
? CONV_NONCONVERTING
: 0;
5133 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5134 value
= (convert_from_reference
5135 (convert_to_reference (type
, value
, CONV_OLD_CONVERT
|flag
,
5136 LOOKUP_COMPLAIN
, NULL_TREE
)));
5141 if (TREE_READONLY_DECL_P (value
))
5142 value
= decl_constant_value (value
);
5145 value
= convert_force (type
, value
, flag
);
5147 /* Ignore any integer overflow caused by the cast. */
5148 if (TREE_CODE (value
) == INTEGER_CST
)
5150 TREE_OVERFLOW (value
) = TREE_OVERFLOW (ovalue
);
5151 TREE_CONSTANT_OVERFLOW (value
) = TREE_CONSTANT_OVERFLOW (ovalue
);
5156 /* Always produce some operator for an explicit cast,
5157 so we can tell (for -pedantic) that the cast is no lvalue.
5158 Also, pedantically, don't let (void *) (FOO *) 0 be a null
5159 pointer constant. */
5162 && TREE_CODE (value
) == INTEGER_CST
5163 && TREE_CODE (expr
) == INTEGER_CST
5164 && TREE_CODE (TREE_TYPE (expr
)) != INTEGER_TYPE
))
5165 value
= non_lvalue (value
);
5171 /* Build an assignment expression of lvalue LHS from value RHS.
5173 In C++, if the left hand side of the assignment is a REFERENCE_TYPE,
5174 that reference becomes deferenced down to it base type. */
5176 /* Return a reference to the BASE_INDEX part of EXPR. TYPE is
5177 the type to which BASE_INDEX applies. */
5179 get_base_ref (type
, base_index
, expr
)
5184 tree binfos
= TYPE_BINFO_BASETYPES (type
);
5185 tree base_binfo
= TREE_VEC_ELT (binfos
, base_index
);
5188 if (TREE_CODE (expr
) == ARRAY_REF
5189 || ! BINFO_OFFSET_ZEROP (base_binfo
)
5190 || TREE_VIA_VIRTUAL (base_binfo
)
5191 || TYPE_MODE (type
) != TYPE_MODE (BINFO_TYPE (base_binfo
)))
5193 tree addr
= build_unary_op (ADDR_EXPR
, expr
, 0);
5194 ref
= build_indirect_ref (convert_pointer_to (base_binfo
, addr
),
5199 ref
= copy_node (expr
);
5200 TREE_TYPE (ref
) = BINFO_TYPE (base_binfo
);
5205 /* Build an assignment expression of lvalue LHS from value RHS.
5206 MODIFYCODE is the code for a binary operator that we use
5207 to combine the old value of LHS with RHS to get the new value.
5208 Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.
5210 C++: If MODIFYCODE is INIT_EXPR, then leave references unbashed.
5212 `build_modify_expr_1' implements recursive part of memberwise
5213 assignment operation. */
5215 build_modify_expr_1 (lhs
, modifycode
, rhs
, basetype_path
)
5217 enum tree_code modifycode
;
5220 register tree result
;
5222 tree lhstype
= TREE_TYPE (lhs
);
5223 tree olhstype
= lhstype
;
5225 /* Avoid duplicate error messages from operands that had errors. */
5226 if (TREE_CODE (lhs
) == ERROR_MARK
|| TREE_CODE (rhs
) == ERROR_MARK
)
5227 return error_mark_node
;
5229 /* If a binary op has been requested, combine the old LHS value with the RHS
5230 producing the value we should actually store into the LHS. */
5232 if (modifycode
== INIT_EXPR
)
5234 else if (modifycode
== NOP_EXPR
)
5236 /* must deal with overloading of `operator=' here. */
5237 if (TREE_CODE (lhstype
) == REFERENCE_TYPE
)
5238 lhstype
= TREE_TYPE (lhstype
);
5244 lhs
= stabilize_reference (lhs
);
5245 newrhs
= build_binary_op (modifycode
, lhs
, rhs
, 1);
5246 modifycode
= NOP_EXPR
;
5249 /* If storing into a structure or union member,
5250 it has probably been given type `int'.
5251 Compute the type that would go with
5252 the actual amount of storage the member occupies. */
5254 if (TREE_CODE (lhs
) == COMPONENT_REF
5255 && (TREE_CODE (lhstype
) == INTEGER_TYPE
5256 || TREE_CODE (lhstype
) == REAL_TYPE
5257 || TREE_CODE (lhstype
) == ENUMERAL_TYPE
))
5258 lhstype
= TREE_TYPE (get_unwidened (lhs
, 0));
5260 /* C++: The semantics of C++ differ from those of C when an
5261 assignment of an aggregate is desired. Assignment in C++ is
5262 now defined as memberwise assignment of non-static members
5263 and base class objects. This rule applies recursively
5264 until a member of a built-in type is found.
5266 Also, we cannot do a bit-wise copy of aggregates which
5267 contain virtual function table pointers. Those
5268 pointer values must be preserved through the copy.
5269 However, this is handled in expand_expr, and not here.
5270 This is because much better code can be generated at
5271 that stage than this one. */
5272 if (TREE_CODE (lhstype
) == RECORD_TYPE
5273 && TYPE_LANG_SPECIFIC (lhstype
)
5274 && TYPE_MAIN_VARIANT (lhstype
) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs
)))
5279 /* Perform operation on object. */
5280 if (modifycode
== INIT_EXPR
&& TYPE_HAS_INIT_REF (lhstype
))
5282 result
= build_method_call (lhs
, constructor_name_full (lhstype
),
5283 build_tree_list (NULL_TREE
, rhs
),
5284 basetype_path
, LOOKUP_NORMAL
);
5285 return build_indirect_ref (result
, NULL_PTR
);
5287 else if (modifycode
== NOP_EXPR
)
5289 /* `operator=' is not an inheritable operator; see 13.4.3. */
5290 if (TYPE_LANG_SPECIFIC (lhstype
) && TYPE_HAS_ASSIGNMENT (lhstype
))
5292 result
= build_opfncall (MODIFY_EXPR
, LOOKUP_NORMAL
,
5293 lhs
, rhs
, make_node (NOP_EXPR
));
5294 if (result
== NULL_TREE
)
5295 return error_mark_node
;
5300 if (TYPE_USES_VIRTUAL_BASECLASSES (lhstype
)
5301 || (modifycode
== NOP_EXPR
&& TYPE_GETS_ASSIGNMENT (lhstype
))
5302 || (modifycode
== INIT_EXPR
&& TYPE_GETS_INIT_REF (lhstype
)))
5304 tree binfos
= BINFO_BASETYPES (TYPE_BINFO (lhstype
));
5307 if (binfos
!= NULL_TREE
)
5308 /* Perform operation on each member, depth-first, left-right. */
5309 for (i
= 0; i
<= TREE_VEC_LENGTH (binfos
)-1; i
++)
5311 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
5312 tree base_lhs
, base_rhs
;
5315 /* Assignments from virtual baseclasses handled elsewhere. */
5316 if (TREE_VIA_VIRTUAL (base_binfo
))
5319 base_lhs
= get_base_ref (lhstype
, i
, lhs
);
5320 base_rhs
= get_base_ref (lhstype
, i
, newrhs
);
5322 BINFO_INHERITANCE_CHAIN (base_binfo
) = basetype_path
;
5324 = build_modify_expr_1 (base_lhs
, modifycode
, base_rhs
,
5327 /* We either get back a compound stmt, or a simple one. */
5328 if (new_result
&& TREE_CODE (new_result
) == TREE_LIST
)
5329 new_result
= build_compound_expr (new_result
);
5330 result
= tree_cons (NULL_TREE
, new_result
, result
);
5333 for (elt
= TYPE_FIELDS (lhstype
); elt
; elt
= TREE_CHAIN (elt
))
5335 tree vbases
= NULL_TREE
;
5336 tree elt_lhs
, elt_rhs
;
5338 if (TREE_CODE (elt
) != FIELD_DECL
)
5341 && (VFIELD_NAME_P (DECL_NAME (elt
))
5342 || VBASE_NAME_P (DECL_NAME (elt
))))
5345 if (TREE_READONLY (elt
)
5346 || TREE_CODE (TREE_TYPE (elt
)) == REFERENCE_TYPE
)
5348 cp_error ("cannot generate default `%T::operator ='",
5350 if (TREE_CODE (TREE_TYPE (elt
)) == REFERENCE_TYPE
)
5351 cp_error_at ("because member `%#D' is a reference", elt
);
5353 cp_error_at ("because member `%#D' is const", elt
);
5355 return error_mark_node
;
5358 if (IS_AGGR_TYPE (TREE_TYPE (elt
))
5359 && TYPE_LANG_SPECIFIC (TREE_TYPE (elt
)))
5360 vbases
= CLASSTYPE_VBASECLASSES (TREE_TYPE (elt
));
5362 elt_lhs
= build (COMPONENT_REF
, TREE_TYPE (elt
), lhs
, elt
);
5363 elt_rhs
= build (COMPONENT_REF
, TREE_TYPE (elt
), newrhs
, elt
);
5364 /* It is not always safe to go through `build_modify_expr_1'
5365 when performing element-wise copying. This is because
5366 an element may be of ARRAY_TYPE, which will not
5367 be properly copied as a naked element. */
5368 if (TREE_CODE (TREE_TYPE (elt
)) == RECORD_TYPE
5369 && TYPE_LANG_SPECIFIC (TREE_TYPE (elt
)))
5370 basetype_path
= TYPE_BINFO (TREE_TYPE (elt
));
5374 tree elt_lhs_addr
= build_unary_op (ADDR_EXPR
, elt_lhs
, 0);
5375 tree elt_rhs_addr
= build_unary_op (ADDR_EXPR
, elt_rhs
, 0);
5377 elt_lhs_addr
= convert_pointer_to (vbases
, elt_lhs_addr
);
5378 elt_rhs_addr
= convert_pointer_to (vbases
, elt_rhs_addr
);
5380 = tree_cons (NULL_TREE
,
5382 (build_indirect_ref (elt_lhs_addr
, NULL_PTR
),
5384 build_indirect_ref (elt_rhs_addr
, NULL_PTR
),
5387 if (TREE_VALUE (result
) == error_mark_node
)
5388 return error_mark_node
;
5389 vbases
= TREE_CHAIN (vbases
);
5391 elt_lhs
= build_modify_expr_1 (elt_lhs
, modifycode
, elt_rhs
,
5393 result
= tree_cons (NULL_TREE
, elt_lhs
, result
);
5397 return build_compound_expr (result
);
5398 /* No fields to move. */
5399 return integer_zero_node
;
5403 result
= build (modifycode
== NOP_EXPR
? MODIFY_EXPR
: INIT_EXPR
,
5404 void_type_node
, lhs
, rhs
);
5405 TREE_SIDE_EFFECTS (result
) = 1;
5410 result
= build_modify_expr (lhs
, modifycode
, newrhs
);
5411 /* ARRAY_TYPEs cannot be converted to anything meaningful,
5412 and leaving it there screws up `build_compound_expr' when
5413 it tries to defaultly convert everything. */
5414 if (TREE_CODE (TREE_TYPE (result
)) == ARRAY_TYPE
)
5415 TREE_TYPE (result
) = void_type_node
;
5420 /* Taken from expr.c:
5421 Subroutine of expand_expr:
5422 record the non-copied parts (LIST) of an expr (LHS), and return a list
5423 which specifies the initial values of these parts. */
5426 init_noncopied_parts (lhs
, list
)
5433 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
5434 if (TREE_CODE (TREE_VALUE (tail
)) == TREE_LIST
)
5435 parts
= chainon (parts
, init_noncopied_parts (lhs
, TREE_VALUE (tail
)));
5438 tree part
= TREE_VALUE (tail
);
5439 tree part_type
= TREE_TYPE (part
);
5440 tree to_be_initialized
= build (COMPONENT_REF
, part_type
, lhs
, part
);
5441 parts
= tree_cons (TREE_PURPOSE (tail
), to_be_initialized
, parts
);
5446 /* Build an assignment expression of lvalue LHS from value RHS.
5447 MODIFYCODE is the code for a binary operator that we use
5448 to combine the old value of LHS with RHS to get the new value.
5449 Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.
5451 C++: If MODIFYCODE is INIT_EXPR, then leave references unbashed.
5454 build_modify_expr (lhs
, modifycode
, rhs
)
5456 enum tree_code modifycode
;
5459 register tree result
;
5461 tree lhstype
= TREE_TYPE (lhs
);
5462 tree olhstype
= lhstype
;
5465 /* Avoid duplicate error messages from operands that had errors. */
5466 if (TREE_CODE (lhs
) == ERROR_MARK
|| TREE_CODE (rhs
) == ERROR_MARK
)
5467 return error_mark_node
;
5469 /* Types that aren't fully specified cannot be used in assignments. */
5470 lhs
= require_complete_type (lhs
);
5472 /* Decide early if we are going to protect RHS from GC
5473 before assigning it to LHS. */
5474 if (type_needs_gc_entry (TREE_TYPE (rhs
))
5475 && ! value_safe_from_gc (lhs
, rhs
))
5476 rhs
= protect_value_from_gc (lhs
, rhs
);
5480 /* Handle assignment to signature pointers/refs. */
5482 if (TYPE_LANG_SPECIFIC (lhstype
) &&
5483 (IS_SIGNATURE_POINTER (lhstype
) || IS_SIGNATURE_REFERENCE (lhstype
)))
5485 return build_signature_pointer_constructor (lhs
, rhs
);
5488 /* Handle control structure constructs used as "lvalues". */
5490 switch (TREE_CODE (lhs
))
5492 /* Handle --foo = 5; as these are valid constructs in C++ */
5493 case PREDECREMENT_EXPR
:
5494 case PREINCREMENT_EXPR
:
5495 if (TREE_SIDE_EFFECTS (TREE_OPERAND (lhs
, 0)))
5496 lhs
= build (TREE_CODE (lhs
), TREE_TYPE (lhs
),
5497 stabilize_reference (TREE_OPERAND (lhs
, 0)));
5498 return build (COMPOUND_EXPR
, lhstype
,
5500 build_modify_expr (TREE_OPERAND (lhs
, 0),
5503 /* Handle (a, b) used as an "lvalue". */
5505 newrhs
= build_modify_expr (TREE_OPERAND (lhs
, 1),
5507 if (TREE_CODE (newrhs
) == ERROR_MARK
)
5508 return error_mark_node
;
5509 return build (COMPOUND_EXPR
, lhstype
,
5510 TREE_OPERAND (lhs
, 0), newrhs
);
5513 newrhs
= build_modify_expr (TREE_OPERAND (lhs
, 0), modifycode
, rhs
);
5514 if (TREE_CODE (newrhs
) == ERROR_MARK
)
5515 return error_mark_node
;
5516 return build (COMPOUND_EXPR
, lhstype
, lhs
, newrhs
);
5518 /* Handle (a ? b : c) used as an "lvalue". */
5520 rhs
= save_expr (rhs
);
5522 /* Produce (a ? (b = rhs) : (c = rhs))
5523 except that the RHS goes through a save-expr
5524 so the code to compute it is only emitted once. */
5526 = build_conditional_expr (TREE_OPERAND (lhs
, 0),
5527 build_modify_expr (convert (TREE_TYPE (lhs
), TREE_OPERAND (lhs
, 1)),
5529 build_modify_expr (convert (TREE_TYPE (lhs
), TREE_OPERAND (lhs
, 2)),
5531 if (TREE_CODE (cond
) == ERROR_MARK
)
5533 /* Make sure the code to compute the rhs comes out
5534 before the split. */
5535 return build (COMPOUND_EXPR
, TREE_TYPE (lhs
),
5536 /* Case to void to suppress warning
5537 from warn_if_unused_value. */
5538 convert (void_type_node
, rhs
), cond
);
5542 if (TREE_CODE (lhs
) == OFFSET_REF
)
5544 if (TREE_OPERAND (lhs
, 0) == NULL_TREE
)
5546 /* Static class member? */
5547 tree member
= TREE_OPERAND (lhs
, 1);
5548 if (TREE_CODE (member
) == VAR_DECL
)
5552 compiler_error ("invalid static class member");
5553 return error_mark_node
;
5557 lhs
= resolve_offset_ref (lhs
);
5559 olhstype
= lhstype
= TREE_TYPE (lhs
);
5562 if (TREE_CODE (lhstype
) == REFERENCE_TYPE
5563 && modifycode
!= INIT_EXPR
)
5565 lhs
= convert_from_reference (lhs
);
5566 olhstype
= lhstype
= TREE_TYPE (lhs
);
5569 /* If a binary op has been requested, combine the old LHS value with the RHS
5570 producing the value we should actually store into the LHS. */
5572 if (modifycode
== INIT_EXPR
)
5574 if (! IS_AGGR_TYPE (lhstype
))
5575 /* Do the default thing */;
5576 else if (! TYPE_HAS_CONSTRUCTOR (lhstype
))
5577 cp_error ("`%T' has no constructors", lhstype
);
5578 else if (! TYPE_NEEDS_CONSTRUCTING (lhstype
)
5579 && TYPE_MAIN_VARIANT (lhstype
) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs
)))
5580 /* Do the default thing */;
5583 result
= build_method_call (lhs
, constructor_name_full (lhstype
),
5584 build_tree_list (NULL_TREE
, rhs
),
5585 NULL_TREE
, LOOKUP_NORMAL
);
5586 if (result
== NULL_TREE
)
5587 return error_mark_node
;
5591 else if (modifycode
== NOP_EXPR
)
5594 /* `operator=' is not an inheritable operator. */
5595 if (! IS_AGGR_TYPE (lhstype
))
5596 /* Do the default thing */;
5597 else if (! TYPE_HAS_ASSIGNMENT (lhstype
))
5598 cp_error ("`%T' does not define operator=", lhstype
);
5599 else if (! TYPE_HAS_REAL_ASSIGNMENT (lhstype
)
5600 && ! TYPE_HAS_COMPLEX_ASSIGN_REF (lhstype
)
5601 && TYPE_MAIN_VARIANT (lhstype
) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs
)))
5602 /* Do the default thing */;
5605 result
= build_opfncall (MODIFY_EXPR
, LOOKUP_NORMAL
,
5606 lhs
, rhs
, make_node (NOP_EXPR
));
5607 if (result
== NULL_TREE
)
5608 return error_mark_node
;
5612 /* Treat `operator=' as an inheritable operator. */
5613 if (TYPE_LANG_SPECIFIC (lhstype
) && TYPE_GETS_ASSIGNMENT (lhstype
))
5615 tree orig_lhstype
= lhstype
;
5616 while (! TYPE_HAS_ASSIGNMENT (lhstype
))
5618 int i
, n_baseclasses
= CLASSTYPE_N_BASECLASSES (lhstype
);
5619 tree basetype
= NULL_TREE
;
5620 for (i
= 0; i
< n_baseclasses
; i
++)
5621 if (TYPE_GETS_ASSIGNMENT (TYPE_BINFO_BASETYPE (lhstype
, i
)))
5623 if (basetype
!= NULL_TREE
)
5625 message_2_types (error
, "base classes `%s' and `%s' both have operator ='",
5627 TYPE_BINFO_BASETYPE (lhstype
, i
));
5628 return error_mark_node
;
5630 basetype
= TYPE_BINFO_BASETYPE (lhstype
, i
);
5634 if (orig_lhstype
!= lhstype
)
5636 lhs
= build_indirect_ref (convert_pointer_to (lhstype
,
5637 build_unary_op (ADDR_EXPR
, lhs
, 0)), NULL_PTR
);
5638 if (lhs
== error_mark_node
)
5640 cp_error ("conversion to private basetype `%T'", lhstype
);
5641 return error_mark_node
;
5644 result
= build_opfncall (MODIFY_EXPR
, LOOKUP_NORMAL
,
5645 lhs
, rhs
, make_node (NOP_EXPR
));
5646 if (result
== NULL_TREE
)
5647 return error_mark_node
;
5653 else if (PROMOTES_TO_AGGR_TYPE (lhstype
, REFERENCE_TYPE
))
5655 /* This case must convert to some sort of lvalue that
5656 can participate in an op= operation. */
5659 if (build_default_binary_type_conversion (modifycode
, &lhs_tmp
, &rhs_tmp
))
5661 lhs
= stabilize_reference (lhs_tmp
);
5662 /* Forget is was ever anything else. */
5663 olhstype
= lhstype
= TREE_TYPE (lhs
);
5664 newrhs
= build_binary_op (modifycode
, lhs
, rhs_tmp
, 1);
5668 cp_error ("no match for `%O(%#T, %#T)'", modifycode
,
5669 TREE_TYPE (lhs
), TREE_TYPE (rhs
));
5670 return error_mark_node
;
5675 lhs
= stabilize_reference (lhs
);
5676 newrhs
= build_binary_op (modifycode
, lhs
, rhs
, 1);
5679 /* Handle a cast used as an "lvalue".
5680 We have already performed any binary operator using the value as cast.
5681 Now convert the result to the cast type of the lhs,
5682 and then true type of the lhs and store it there;
5683 then convert result back to the cast type to be the value
5684 of the assignment. */
5686 switch (TREE_CODE (lhs
))
5691 case FIX_TRUNC_EXPR
:
5692 case FIX_FLOOR_EXPR
:
5693 case FIX_ROUND_EXPR
:
5695 if (TREE_CODE (TREE_TYPE (newrhs
)) == ARRAY_TYPE
5696 || TREE_CODE (TREE_TYPE (newrhs
)) == FUNCTION_TYPE
5697 || TREE_CODE (TREE_TYPE (newrhs
)) == METHOD_TYPE
5698 || TREE_CODE (TREE_TYPE (newrhs
)) == OFFSET_TYPE
)
5699 newrhs
= default_conversion (newrhs
);
5701 tree inner_lhs
= TREE_OPERAND (lhs
, 0);
5703 if (! lvalue_p (lhs
) && pedantic
)
5704 pedwarn ("cast to non-reference type used as lvalue");
5706 result
= build_modify_expr (inner_lhs
, NOP_EXPR
,
5707 convert (TREE_TYPE (inner_lhs
),
5708 convert (lhstype
, newrhs
)));
5709 if (TREE_CODE (result
) == ERROR_MARK
)
5711 return convert (TREE_TYPE (lhs
), result
);
5715 /* Now we have handled acceptable kinds of LHS that are not truly lvalues.
5716 Reject anything strange now. */
5718 if (!lvalue_or_else (lhs
, "assignment"))
5719 return error_mark_node
;
5721 GNU_xref_assign (lhs
);
5723 /* Warn about storing in something that is `const'. */
5724 /* For C++, don't warn if this is initialization. */
5725 if (modifycode
!= INIT_EXPR
5726 /* For assignment to `const' signature pointer/reference fields,
5727 don't warn either, we already printed a better message before. */
5728 && ! (TREE_CODE (lhs
) == COMPONENT_REF
5729 && (IS_SIGNATURE_POINTER (TREE_TYPE (TREE_OPERAND (lhs
, 0)))
5730 || IS_SIGNATURE_REFERENCE (TREE_TYPE (TREE_OPERAND (lhs
, 0)))))
5731 && (TREE_READONLY (lhs
) || TYPE_READONLY (lhstype
)
5732 || ((TREE_CODE (lhstype
) == RECORD_TYPE
5733 || TREE_CODE (lhstype
) == UNION_TYPE
)
5734 && C_TYPE_FIELDS_READONLY (lhstype
))
5735 || (TREE_CODE (lhstype
) == REFERENCE_TYPE
5736 && TYPE_READONLY (TREE_TYPE (lhstype
)))))
5737 readonly_error (lhs
, "assignment", 0);
5739 /* If storing into a structure or union member,
5740 it has probably been given type `int'.
5741 Compute the type that would go with
5742 the actual amount of storage the member occupies. */
5744 if (TREE_CODE (lhs
) == COMPONENT_REF
5745 && (TREE_CODE (lhstype
) == INTEGER_TYPE
5746 || TREE_CODE (lhstype
) == REAL_TYPE
5747 || TREE_CODE (lhstype
) == ENUMERAL_TYPE
))
5749 lhstype
= TREE_TYPE (get_unwidened (lhs
, 0));
5751 /* If storing in a field that is in actuality a short or narrower
5752 than one, we must store in the field in its actual type. */
5754 if (lhstype
!= TREE_TYPE (lhs
))
5756 lhs
= copy_node (lhs
);
5757 TREE_TYPE (lhs
) = lhstype
;
5761 /* check to see if there is an assignment to `this' */
5762 if (lhs
== current_class_decl
)
5764 if (flag_this_is_variable
> 0
5765 && DECL_NAME (current_function_decl
) != NULL_TREE
5766 && (DECL_NAME (current_function_decl
)
5767 != constructor_name (current_class_type
)))
5768 warning ("assignment to `this' not in constructor or destructor");
5769 current_function_just_assigned_this
= 1;
5772 /* The TREE_TYPE of RHS may be TYPE_UNKNOWN. This can happen
5773 when the type of RHS is not yet known, i.e. its type
5774 is inherited from LHS. */
5775 rhs
= require_instantiated_type (lhstype
, newrhs
, error_mark_node
);
5776 if (rhs
== error_mark_node
)
5777 return error_mark_node
;
5780 if (modifycode
!= INIT_EXPR
)
5782 /* Make modifycode now either a NOP_EXPR or an INIT_EXPR. */
5783 modifycode
= NOP_EXPR
;
5784 /* Reference-bashing */
5785 if (TREE_CODE (lhstype
) == REFERENCE_TYPE
)
5787 tree tmp
= convert_from_reference (lhs
);
5788 lhstype
= TREE_TYPE (tmp
);
5789 if (TYPE_SIZE (lhstype
) == 0)
5791 incomplete_type_error (lhs
, lhstype
);
5792 return error_mark_node
;
5797 if (TREE_CODE (TREE_TYPE (newrhs
)) == REFERENCE_TYPE
)
5799 tree tmp
= convert_from_reference (newrhs
);
5800 if (TYPE_SIZE (TREE_TYPE (tmp
)) == 0)
5802 incomplete_type_error (newrhs
, TREE_TYPE (tmp
));
5803 return error_mark_node
;
5809 if (TREE_SIDE_EFFECTS (lhs
))
5810 lhs
= stabilize_reference (lhs
);
5811 if (TREE_SIDE_EFFECTS (newrhs
))
5812 newrhs
= stabilize_reference (newrhs
);
5815 /* This is now done by generating X(X&) and operator=(X&). */
5816 /* C++: The semantics of C++ differ from those of C when an
5817 assignment of an aggregate is desired. Assignment in C++ is
5818 now defined as memberwise assignment of non-static members
5819 and base class objects. This rule applies recursively
5820 until a member of a built-in type is found.
5822 Also, we cannot do a bit-wise copy of aggregates which
5823 contain virtual function table pointers. Those
5824 pointer values must be preserved through the copy.
5825 However, this is handled in expand_expr, and not here.
5826 This is because much better code can be generated at
5827 that stage than this one. */
5828 if (TREE_CODE (lhstype
) == RECORD_TYPE
5829 && ! TYPE_PTRMEMFUNC_P (lhstype
)
5830 && (TYPE_MAIN_VARIANT (lhstype
) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs
))
5831 || (TREE_CODE (TREE_TYPE (newrhs
)) == RECORD_TYPE
5832 && UNIQUELY_DERIVED_FROM_P (lhstype
, TREE_TYPE (newrhs
)))))
5834 tree vbases
= CLASSTYPE_VBASECLASSES (lhstype
);
5835 tree lhs_addr
= build_unary_op (ADDR_EXPR
, lhs
, 0);
5838 /* Memberwise assignment would cause NEWRHS to be
5839 evaluated for every member that gets assigned.
5840 By wrapping side-effecting exprs in a SAVE_EXPR,
5841 NEWRHS will only be evaluated once. */
5842 if (IS_AGGR_TYPE (TREE_TYPE (newrhs
))
5843 && TREE_SIDE_EFFECTS (newrhs
)
5844 /* This are things we don't have to save. */
5845 && TREE_CODE (newrhs
) != COND_EXPR
5846 && TREE_CODE (newrhs
) != TARGET_EXPR
5847 && TREE_CODE (newrhs
) != WITH_CLEANUP_EXPR
)
5848 /* Call `break_out_cleanups' on NEWRHS in case there are cleanups.
5849 If NEWRHS is a CALL_EXPR that needs a cleanup, failure to do so
5850 will result in expand_expr expanding the call without knowing
5851 that it should run the cleanup. */
5852 newrhs
= save_expr (break_out_cleanups (newrhs
));
5854 if (TREE_CODE (newrhs
) == COND_EXPR
)
5855 rhs_addr
= rationalize_conditional_expr (ADDR_EXPR
, newrhs
);
5857 rhs_addr
= build_unary_op (ADDR_EXPR
, newrhs
, 0);
5859 result
= tree_cons (NULL_TREE
,
5860 convert (build_reference_type (lhstype
), lhs
),
5863 if (! comptypes (TREE_TYPE (lhs_addr
), TREE_TYPE (rhs_addr
), 1))
5864 rhs_addr
= convert_pointer_to (TREE_TYPE (TREE_TYPE (lhs_addr
)), rhs_addr
);
5866 tree noncopied_parts
= NULL_TREE
;
5868 if (TYPE_NONCOPIED_PARTS (lhstype
) != 0)
5869 noncopied_parts
= init_noncopied_parts (lhs
,
5870 TYPE_NONCOPIED_PARTS (lhstype
));
5871 while (noncopied_parts
!= 0)
5873 result
= tree_cons (NULL_TREE
,
5874 build_modify_expr (convert (ptr_type_node
, TREE_VALUE (noncopied_parts
)),
5876 TREE_PURPOSE (noncopied_parts
)),
5878 noncopied_parts
= TREE_CHAIN (noncopied_parts
);
5881 /* Once we have our hands on an address, we must change NEWRHS
5882 to work from there. Otherwise we can get multiple evaluations
5884 if (TREE_CODE (newrhs
) != SAVE_EXPR
)
5885 newrhs
= build_indirect_ref (rhs_addr
, NULL_PTR
);
5889 tree elt_lhs
= convert_pointer_to (vbases
, lhs_addr
);
5890 tree elt_rhs
= convert_pointer_to (vbases
, rhs_addr
);
5892 = tree_cons (NULL_TREE
,
5893 build_modify_expr_1 (build_indirect_ref (elt_lhs
, NULL_PTR
),
5895 build_indirect_ref (elt_rhs
, NULL_PTR
),
5896 TYPE_BINFO (lhstype
)),
5898 if (TREE_VALUE (result
) == error_mark_node
)
5899 return error_mark_node
;
5900 vbases
= TREE_CHAIN (vbases
);
5902 result
= tree_cons (NULL_TREE
,
5903 build_modify_expr_1 (lhs
,
5906 TYPE_BINFO (lhstype
)),
5908 return build_compound_expr (result
);
5912 /* Convert new value to destination type. */
5914 if (TREE_CODE (lhstype
) == ARRAY_TYPE
)
5918 /* Allow array assignment in compiler-generated code. */
5919 if (pedantic
&& ! DECL_ARTIFICIAL (current_function_decl
))
5920 pedwarn ("ANSI C++ forbids assignment of arrays");
5922 /* Have to wrap this in RTL_EXPR for two cases:
5923 in base or member initialization and if we
5924 are a branch of a ?: operator. Since we
5925 can't easily know the latter, just do it always. */
5927 result
= make_node (RTL_EXPR
);
5929 TREE_TYPE (result
) = void_type_node
;
5930 do_pending_stack_adjust ();
5931 start_sequence_for_rtl_expr (result
);
5933 /* As a matter of principle, `start_sequence' should do this. */
5936 from_array
= TREE_CODE (TREE_TYPE (newrhs
)) == ARRAY_TYPE
5937 ? 1 + (modifycode
!= INIT_EXPR
): 0;
5938 expand_vec_init (lhs
, lhs
, array_type_nelts (lhstype
), newrhs
,
5941 do_pending_stack_adjust ();
5943 TREE_SIDE_EFFECTS (result
) = 1;
5944 RTL_EXPR_SEQUENCE (result
) = get_insns ();
5945 RTL_EXPR_RTL (result
) = const0_rtx
;
5950 if (modifycode
== INIT_EXPR
)
5952 newrhs
= convert_for_initialization (lhs
, lhstype
, newrhs
, LOOKUP_NORMAL
,
5953 "assignment", NULL_TREE
, 0);
5954 if (lhs
== DECL_RESULT (current_function_decl
))
5956 if (DECL_INITIAL (lhs
))
5957 warning ("return value from function receives multiple initializations");
5958 DECL_INITIAL (lhs
) = newrhs
;
5964 if (IS_AGGR_TYPE (lhstype
))
5966 if (result
= build_opfncall (MODIFY_EXPR
,
5967 LOOKUP_NORMAL
, lhs
, newrhs
,
5968 make_node (NOP_EXPR
)))
5972 /* Avoid warnings on enum bit fields. */
5973 if (TREE_CODE (olhstype
) == ENUMERAL_TYPE
5974 && TREE_CODE (lhstype
) == INTEGER_TYPE
)
5976 newrhs
= convert_for_assignment (olhstype
, newrhs
, "assignment",
5978 newrhs
= convert_force (lhstype
, newrhs
, 0);
5981 newrhs
= convert_for_assignment (lhstype
, newrhs
, "assignment",
5983 if (TREE_CODE (newrhs
) == CALL_EXPR
5984 && TYPE_NEEDS_CONSTRUCTING (lhstype
))
5985 newrhs
= build_cplus_new (lhstype
, newrhs
, 0);
5987 if (TREE_CODE (newrhs
) == TARGET_EXPR
)
5989 /* Can't initialize directly from a TARGET_EXPR, since that would
5990 cause the lhs to be constructed twice. So we force the
5991 TARGET_EXPR to be expanded. expand_expr should really do this
5994 tree xval
= make_node (RTL_EXPR
);
5997 do_pending_stack_adjust ();
5998 start_sequence_for_rtl_expr (xval
);
6000 rtxval
= expand_expr (newrhs
, NULL
, VOIDmode
, 0);
6001 do_pending_stack_adjust ();
6002 TREE_SIDE_EFFECTS (xval
) = 1;
6003 RTL_EXPR_SEQUENCE (xval
) = get_insns ();
6005 RTL_EXPR_RTL (xval
) = rtxval
;
6006 TREE_TYPE (xval
) = lhstype
;
6011 if (TREE_CODE (newrhs
) == ERROR_MARK
)
6012 return error_mark_node
;
6014 if (TREE_CODE (newrhs
) == COND_EXPR
)
6017 tree cond
= TREE_OPERAND (newrhs
, 0);
6019 if (TREE_SIDE_EFFECTS (lhs
))
6020 cond
= build_compound_expr (tree_cons
6022 build_tree_list (NULL_TREE
, cond
)));
6024 /* Cannot have two identical lhs on this one tree (result) as preexpand
6025 calls will rip them out and fill in RTL for them, but when the
6026 rtl is generated, the calls will only be in the first side of the
6027 condition, not on both, or before the conditional jump! (mrs) */
6028 lhs1
= break_out_calls (lhs
);
6031 /* If there's no change, the COND_EXPR behaves like any other rhs. */
6032 result
= build (modifycode
== NOP_EXPR
? MODIFY_EXPR
: INIT_EXPR
,
6033 lhstype
, lhs
, newrhs
);
6036 tree result_type
= TREE_TYPE (newrhs
);
6037 /* We have to convert each arm to the proper type because the
6038 types may have been munged by constant folding. */
6040 = build (COND_EXPR
, result_type
, cond
,
6041 build_modify_expr (lhs
, modifycode
,
6042 convert (result_type
,
6043 TREE_OPERAND (newrhs
, 1))),
6044 build_modify_expr (lhs1
, modifycode
,
6045 convert (result_type
,
6046 TREE_OPERAND (newrhs
, 2))));
6049 else if (modifycode
!= INIT_EXPR
&& TREE_CODE (newrhs
) == WITH_CLEANUP_EXPR
)
6051 tree cleanup
= TREE_OPERAND (newrhs
, 2);
6054 /* Finish up by running cleanups and having the "value" of the lhs. */
6055 tree exprlist
= tree_cons (NULL_TREE
, cleanup
,
6056 build_tree_list (NULL_TREE
, lhs
));
6057 newrhs
= TREE_OPERAND (newrhs
, 0);
6058 if (TREE_CODE (newrhs
) == TARGET_EXPR
)
6059 slot
= TREE_OPERAND (newrhs
, 0);
6060 else if (TREE_CODE (newrhs
) == ADDR_EXPR
)
6062 /* Bad but valid. */
6064 warning ("address taken of temporary object");
6067 my_friendly_abort (118);
6069 /* Copy the value computed in SLOT into LHS. */
6070 exprlist
= tree_cons (NULL_TREE
,
6071 build_modify_expr (lhs
, modifycode
, slot
),
6073 /* Evaluate the expression that needs CLEANUP. This will
6074 compute the value into SLOT. */
6075 exprlist
= tree_cons (NULL_TREE
, newrhs
, exprlist
);
6076 result
= convert (lhstype
, build_compound_expr (exprlist
));
6079 result
= build (modifycode
== NOP_EXPR
? MODIFY_EXPR
: INIT_EXPR
,
6080 lhstype
, lhs
, newrhs
);
6081 TREE_SIDE_EFFECTS (result
) = 1;
6083 /* If we got the LHS in a different type for storing in,
6084 convert the result back to the nominal type of LHS
6085 so that the value we return always has the same type
6086 as the LHS argument. */
6088 if (olhstype
== TREE_TYPE (result
))
6090 /* Avoid warnings converting integral types back into enums
6091 for enum bit fields. */
6092 if (TREE_CODE (TREE_TYPE (result
)) == INTEGER_TYPE
6093 && TREE_CODE (olhstype
) == ENUMERAL_TYPE
)
6095 result
= build (COMPOUND_EXPR
, olhstype
, result
, olhs
);
6096 TREE_NO_UNUSED_WARNING (result
) = 1;
6099 return convert_for_assignment (olhstype
, result
, "assignment",
6104 /* Return 0 if EXP is not a valid lvalue in this language
6105 even though `lvalue_or_else' would accept it. */
6108 language_lvalue_valid (exp
)
6114 /* Get differnce in deltas for different pointer to member function
6115 types. Return inetger_zero_node, if FROM cannot be converted to a
6116 TO type. If FORCE is true, then allow reverse conversions as well. */
6118 get_delta_difference (from
, to
, force
)
6122 tree delta
= integer_zero_node
;
6128 /* Should get_base_distance here, so we can check if any thing along the
6129 path is virtual, and we need to make sure we stay
6130 inside the real binfos when going through virtual bases.
6131 Maybe we should replace virtual bases with
6132 binfo_member (...CLASSTYPE_VBASECLASSES...)... (mrs) */
6133 binfo
= get_binfo (from
, to
, 1);
6134 if (binfo
== error_mark_node
)
6136 error (" in pointer to member function conversion");
6143 error_not_base_type (from
, to
);
6144 error (" in pointer to member function conversion");
6147 binfo
= get_binfo (to
, from
, 1);
6148 if (binfo
== error_mark_node
)
6150 error (" in pointer to member function conversion");
6155 error ("cannot convert pointer to member of type %T to unrelated pointer to member of type %T", from
, to
);
6158 if (TREE_VIA_VIRTUAL (binfo
))
6160 warning ("pointer to member conversion to virtual base class will only work if you are very careful");
6162 return build_binary_op (MINUS_EXPR
,
6164 BINFO_OFFSET (binfo
), 1);
6166 if (TREE_VIA_VIRTUAL (binfo
))
6168 warning ("pointer to member conversion from virtual base class will only work if you are very careful");
6170 return BINFO_OFFSET (binfo
);
6173 /* Build a constructor for a pointer to member function. It can be
6174 used to initialize global variables, local variable, or used
6175 as a value in expressions. TYPE is the POINTER to METHOD_TYPE we
6178 If FORCE is non-zero, then force this conversion, even if
6179 we would rather not do it. Usually set when using an explicit
6182 Return error_mark_node, if something goes wrong. */
6185 build_ptrmemfunc (type
, pfn
, force
)
6189 tree index
= integer_zero_node
;
6190 tree delta
= integer_zero_node
;
6191 tree delta2
= integer_zero_node
;
6196 /* Handle multiple conversions of pointer to member fucntions. */
6197 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (pfn
)))
6199 tree ndelta
, ndelta2
, nindex
;
6200 /* Is is already the right type? */
6202 /* Sorry, can't do this, the backend is too stupid. */
6203 if (TYPE_METHOD_BASETYPE (TREE_TYPE (type
))
6204 == TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn
)))))
6206 if (type
!= TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn
)))
6208 npfn
= build1 (NOP_EXPR
, TYPE_GET_PTRMEMFUNC_TYPE (type
), pfn
);
6209 TREE_CONSTANT (npfn
) = TREE_CONSTANT (pfn
);
6214 if (type
== TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn
)))
6218 if (TREE_CODE (pfn
) != CONSTRUCTOR
)
6221 ndelta
= convert (ptrdiff_type_node
, build_component_ref (pfn
, delta_identifier
, 0, 0));
6222 ndelta2
= convert (ptrdiff_type_node
, DELTA2_FROM_PTRMEMFUNC (pfn
));
6223 index
= build_component_ref (pfn
, index_identifier
, 0, 0);
6224 delta
= get_delta_difference (TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn
)))),
6225 TYPE_METHOD_BASETYPE (TREE_TYPE (type
)),
6227 delta
= build_binary_op (PLUS_EXPR
, delta
, ndelta
, 1);
6228 delta2
= build_binary_op (PLUS_EXPR
, ndelta2
, delta2
, 1);
6229 e1
= fold (build (GT_EXPR
, boolean_type_node
, index
, integer_zero_node
));
6231 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (delta2_identifier
, delta2
, NULL_TREE
));
6232 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (NULL_TREE
, delta
,
6233 tree_cons (NULL_TREE
, index
,
6234 tree_cons (NULL_TREE
, u
, NULL_TREE
))));
6235 e2
= digest_init (TYPE_GET_PTRMEMFUNC_TYPE (type
), u
, (tree
*)0);
6237 pfn
= PFN_FROM_PTRMEMFUNC (pfn
);
6238 npfn
= build1 (NOP_EXPR
, type
, pfn
);
6239 TREE_CONSTANT (npfn
) = TREE_CONSTANT (pfn
);
6241 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (pfn_identifier
, npfn
, NULL_TREE
));
6242 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (NULL_TREE
, delta
,
6243 tree_cons (NULL_TREE
, index
,
6244 tree_cons (NULL_TREE
, u
, NULL_TREE
))));
6245 e3
= digest_init (TYPE_GET_PTRMEMFUNC_TYPE (type
), u
, (tree
*)0);
6246 return build_conditional_expr (e1
, e2
, e3
);
6249 ndelta
= TREE_VALUE (CONSTRUCTOR_ELTS (pfn
));
6250 nindex
= TREE_VALUE (TREE_CHAIN (CONSTRUCTOR_ELTS (pfn
)));
6251 npfn
= TREE_VALUE (TREE_CHAIN (TREE_CHAIN (CONSTRUCTOR_ELTS (pfn
))));
6252 npfn
= TREE_VALUE (CONSTRUCTOR_ELTS (npfn
));
6253 if (integer_zerop (nindex
))
6254 pfn
= integer_zero_node
;
6257 sorry ("value casting of varible nonnull pointer to member functions not supported");
6258 return error_mark_node
;
6262 /* Handle null pointer to member function conversions. */
6263 if (integer_zerop (pfn
))
6265 pfn
= build_c_cast (type
, integer_zero_node
, 0);
6266 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (pfn_identifier
, pfn
, NULL_TREE
));
6267 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (NULL_TREE
, integer_zero_node
,
6268 tree_cons (NULL_TREE
, integer_zero_node
,
6269 tree_cons (NULL_TREE
, u
, NULL_TREE
))));
6270 return digest_init (TYPE_GET_PTRMEMFUNC_TYPE (type
), u
, (tree
*)0);
6273 if (TREE_CODE (pfn
) == TREE_LIST
6274 || (TREE_CODE (pfn
) == ADDR_EXPR
6275 && TREE_CODE (TREE_OPERAND (pfn
, 0)) == TREE_LIST
))
6277 pfn
= instantiate_type (type
, pfn
, 1);
6278 if (pfn
== error_mark_node
)
6279 return error_mark_node
;
6280 if (TREE_CODE (pfn
) != ADDR_EXPR
)
6281 pfn
= build_unary_op (ADDR_EXPR
, pfn
, 0);
6284 /* Allow pointer to member conversions here. */
6285 delta
= get_delta_difference (TYPE_METHOD_BASETYPE (TREE_TYPE (TREE_TYPE (pfn
))),
6286 TYPE_METHOD_BASETYPE (TREE_TYPE (type
)),
6288 delta2
= build_binary_op (PLUS_EXPR
, delta2
, delta
, 1);
6290 if (TREE_CODE (TREE_OPERAND (pfn
, 0)) != FUNCTION_DECL
)
6291 warning ("assuming pointer to member function is non-virtual");
6293 if (TREE_CODE (TREE_OPERAND (pfn
, 0)) == FUNCTION_DECL
6294 && DECL_VINDEX (TREE_OPERAND (pfn
, 0)))
6296 /* Find the offset to the vfield pointer in the object. */
6297 vfield_offset
= get_binfo (DECL_CONTEXT (TREE_OPERAND (pfn
, 0)),
6298 DECL_CLASS_CONTEXT (TREE_OPERAND (pfn
, 0)),
6300 vfield_offset
= get_vfield_offset (vfield_offset
);
6301 delta2
= size_binop (PLUS_EXPR
, vfield_offset
, delta2
);
6303 /* Map everything down one to make room for the null pointer to member. */
6304 index
= size_binop (PLUS_EXPR
,
6305 DECL_VINDEX (TREE_OPERAND (pfn
, 0)),
6307 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (delta2_identifier
, delta2
, NULL_TREE
));
6311 index
= size_binop (MINUS_EXPR
, integer_zero_node
, integer_one_node
);
6313 npfn
= build1 (NOP_EXPR
, type
, pfn
);
6314 TREE_CONSTANT (npfn
) = TREE_CONSTANT (pfn
);
6316 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (pfn_identifier
, npfn
, NULL_TREE
));
6319 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (NULL_TREE
, delta
,
6320 tree_cons (NULL_TREE
, index
,
6321 tree_cons (NULL_TREE
, u
, NULL_TREE
))));
6322 return digest_init (TYPE_GET_PTRMEMFUNC_TYPE (type
), u
, (tree
*)0);
6325 /* Convert value RHS to type TYPE as preparation for an assignment
6326 to an lvalue of type TYPE.
6327 The real work of conversion is done by `convert'.
6328 The purpose of this function is to generate error messages
6329 for assignments that are not allowed in C.
6330 ERRTYPE is a string to use in error messages:
6331 "assignment", "return", etc.
6333 C++: attempts to allow `convert' to find conversions involving
6334 implicit type conversion between aggregate and scalar types
6335 as per 8.5.6 of C++ manual. Does not randomly dereference
6336 pointers to aggregates! */
6339 convert_for_assignment (type
, rhs
, errtype
, fndecl
, parmnum
)
6345 register enum tree_code codel
= TREE_CODE (type
);
6346 register tree rhstype
;
6347 register enum tree_code coder
= TREE_CODE (TREE_TYPE (rhs
));
6349 if (coder
== UNKNOWN_TYPE
)
6350 rhs
= instantiate_type (type
, rhs
, 1);
6352 if (coder
== ERROR_MARK
)
6353 return error_mark_node
;
6355 if (codel
== OFFSET_TYPE
)
6357 type
= TREE_TYPE (type
);
6358 codel
= TREE_CODE (type
);
6361 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
6362 if (TREE_CODE (rhs
) == NON_LVALUE_EXPR
)
6363 rhs
= TREE_OPERAND (rhs
, 0);
6365 if (rhs
== error_mark_node
)
6366 return error_mark_node
;
6368 if (TREE_VALUE (rhs
) == error_mark_node
)
6369 return error_mark_node
;
6371 if (TREE_CODE (TREE_TYPE (rhs
)) == OFFSET_TYPE
)
6373 rhs
= resolve_offset_ref (rhs
);
6374 if (rhs
== error_mark_node
)
6375 return error_mark_node
;
6376 rhstype
= TREE_TYPE (rhs
);
6377 coder
= TREE_CODE (rhstype
);
6380 if (TREE_CODE (TREE_TYPE (rhs
)) == ARRAY_TYPE
6381 || TREE_CODE (TREE_TYPE (rhs
)) == FUNCTION_TYPE
6382 || TREE_CODE (TREE_TYPE (rhs
)) == METHOD_TYPE
)
6383 rhs
= default_conversion (rhs
);
6384 else if (TREE_CODE (TREE_TYPE (rhs
)) == REFERENCE_TYPE
)
6385 rhs
= convert_from_reference (rhs
);
6387 rhstype
= TREE_TYPE (rhs
);
6388 coder
= TREE_CODE (rhstype
);
6390 /* This should no longer change types on us. */
6391 if (TREE_CODE (rhs
) == CONST_DECL
)
6392 rhs
= DECL_INITIAL (rhs
);
6393 else if (TREE_READONLY_DECL_P (rhs
))
6394 rhs
= decl_constant_value (rhs
);
6396 if (type
== rhstype
)
6398 overflow_warning (rhs
);
6402 if (coder
== VOID_TYPE
)
6404 error ("void value not ignored as it ought to be");
6405 return error_mark_node
;
6407 /* Arithmetic types all interconvert. */
6408 if ((codel
== INTEGER_TYPE
|| codel
== REAL_TYPE
|| codel
== BOOLEAN_TYPE
)
6409 && (coder
== INTEGER_TYPE
|| coder
== REAL_TYPE
|| coder
== BOOLEAN_TYPE
))
6411 /* But we should warn if assigning REAL_TYPE to INTEGER_TYPE. */
6412 if (coder
== REAL_TYPE
&& codel
== INTEGER_TYPE
)
6415 cp_warning ("`%T' used for argument %P of `%D'",
6416 rhstype
, parmnum
, fndecl
);
6418 cp_warning ("%s to `%T' from `%T'", errtype
, type
, rhstype
);
6420 /* And we should warn if assigning a negative value to
6421 an unsigned variable. */
6422 else if (TREE_UNSIGNED (type
) && codel
!= BOOLEAN_TYPE
)
6424 if (TREE_CODE (rhs
) == INTEGER_CST
6425 && TREE_NEGATED_INT (rhs
))
6428 cp_warning ("negative value `%E' passed as argument %P of `%D'",
6429 rhs
, parmnum
, fndecl
);
6431 cp_warning ("%s of negative value `%E' to `%T'",
6432 errtype
, rhs
, type
);
6434 overflow_warning (rhs
);
6435 if (TREE_CONSTANT (rhs
))
6439 return convert_and_check (type
, rhs
);
6441 /* Conversions involving enums. */
6442 else if ((codel
== ENUMERAL_TYPE
6443 && (INTEGRAL_CODE_P (coder
) || coder
== REAL_TYPE
))
6444 || (coder
== ENUMERAL_TYPE
6445 && (INTEGRAL_CODE_P (codel
) || codel
== REAL_TYPE
)))
6447 return cp_convert (type
, rhs
, CONV_IMPLICIT
, 0);
6449 /* Conversions among pointers */
6450 else if (codel
== POINTER_TYPE
6451 && (coder
== POINTER_TYPE
6452 || (coder
== RECORD_TYPE
6453 && (IS_SIGNATURE_POINTER (rhstype
)
6454 || IS_SIGNATURE_REFERENCE (rhstype
)))))
6456 register tree ttl
= TREE_TYPE (type
);
6460 if (coder
== RECORD_TYPE
)
6462 rhs
= build_optr_ref (rhs
);
6463 rhstype
= TREE_TYPE (rhs
);
6465 ttr
= TREE_TYPE (rhstype
);
6467 /* If both pointers are of aggregate type, then we
6468 can give better error messages, and save some work
6470 if (TREE_CODE (ttl
) == RECORD_TYPE
&& TREE_CODE (ttr
) == RECORD_TYPE
)
6474 if (TYPE_MAIN_VARIANT (ttl
) == TYPE_MAIN_VARIANT (ttr
)
6475 || type
== class_star_type_node
6476 || rhstype
== class_star_type_node
)
6477 binfo
= TYPE_BINFO (ttl
);
6479 binfo
= get_binfo (ttl
, ttr
, 1);
6481 if (binfo
== error_mark_node
)
6482 return error_mark_node
;
6484 return error_not_base_type (ttl
, ttr
);
6486 if (! TYPE_READONLY (ttl
) && TYPE_READONLY (ttr
))
6489 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6490 rhstype
, parmnum
, fndecl
);
6492 cp_pedwarn ("%s to `%T' from `%T' discards const",
6493 errtype
, type
, rhstype
);
6495 if (! TYPE_VOLATILE (ttl
) && TYPE_VOLATILE (ttr
))
6498 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6499 rhstype
, parmnum
, fndecl
);
6501 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6502 errtype
, type
, rhstype
);
6506 /* Any non-function converts to a [const][volatile] void *
6507 and vice versa; otherwise, targets must be the same.
6508 Meanwhile, the lhs target must have all the qualifiers of the rhs. */
6509 else if (TYPE_MAIN_VARIANT (ttl
) == void_type_node
6510 || TYPE_MAIN_VARIANT (ttr
) == void_type_node
6511 || (ctt
= comp_target_types (type
, rhstype
, 1))
6512 || (unsigned_type (TYPE_MAIN_VARIANT (ttl
))
6513 == unsigned_type (TYPE_MAIN_VARIANT (ttr
))))
6515 /* ARM $4.8, commentary on p39. */
6516 if (TYPE_MAIN_VARIANT (ttl
) == void_type_node
6517 && TREE_CODE (ttr
) == OFFSET_TYPE
)
6519 cp_error ("no standard conversion from `%T' to `void *'", ttr
);
6520 return error_mark_node
;
6524 cp_pedwarn ("converting `%T' to `%T' is a contravariance violation",
6527 if (TYPE_MAIN_VARIANT (ttl
) != void_type_node
6528 && TYPE_MAIN_VARIANT (ttr
) == void_type_node
6529 && rhs
!= null_pointer_node
)
6531 if (coder
== RECORD_TYPE
)
6532 cp_pedwarn ("implicit conversion of signature pointer to type `%T'",
6535 pedwarn ("ANSI C++ forbids implicit conversion from `void *' in %s",
6538 /* Const and volatile mean something different for function types,
6539 so the usual warnings are not appropriate. */
6540 else if ((TREE_CODE (ttr
) != FUNCTION_TYPE
&& TREE_CODE (ttr
) != METHOD_TYPE
)
6541 || (TREE_CODE (ttl
) != FUNCTION_TYPE
&& TREE_CODE (ttl
) != METHOD_TYPE
))
6543 if (TREE_CODE (ttl
) == OFFSET_TYPE
6544 && binfo_member (TYPE_OFFSET_BASETYPE (ttr
),
6545 CLASSTYPE_VBASECLASSES (TYPE_OFFSET_BASETYPE (ttl
))))
6547 sorry ("%s between pointer to members converting across virtual baseclasses", errtype
);
6548 return error_mark_node
;
6550 else if (! TYPE_READONLY (ttl
) && TYPE_READONLY (ttr
))
6553 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6554 rhstype
, parmnum
, fndecl
);
6556 cp_pedwarn ("%s to `%T' from `%T' discards const",
6557 errtype
, type
, rhstype
);
6559 else if (! TYPE_VOLATILE (ttl
) && TYPE_VOLATILE (ttr
))
6562 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6563 rhstype
, parmnum
, fndecl
);
6565 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6566 errtype
, type
, rhstype
);
6568 else if (TREE_CODE (ttl
) == TREE_CODE (ttr
)
6569 && ! comp_target_types (type
, rhstype
, 1))
6572 cp_pedwarn ("passing `%T' as argument %P of `%D' changes signedness",
6573 rhstype
, parmnum
, fndecl
);
6575 cp_pedwarn ("%s to `%T' from `%T' changes signedness",
6576 errtype
, type
, rhstype
);
6580 else if (TREE_CODE (ttr
) == OFFSET_TYPE
6581 && TREE_CODE (ttl
) != OFFSET_TYPE
)
6583 /* Normally, pointers to different type codes (other
6584 than void) are not compatible, but we perform
6585 some type instantiation if that resolves the
6586 ambiguity of (X Y::*) and (X *). */
6588 if (current_class_decl
)
6590 if (TREE_CODE (rhs
) == INTEGER_CST
)
6592 rhs
= build (PLUS_EXPR
, build_pointer_type (TREE_TYPE (ttr
)),
6593 current_class_decl
, rhs
);
6594 return convert_for_assignment (type
, rhs
,
6595 errtype
, fndecl
, parmnum
);
6598 if (TREE_CODE (ttl
) == METHOD_TYPE
)
6599 error ("%s between pointer-to-method and pointer-to-member types",
6602 error ("%s between pointer and pointer-to-member types", errtype
);
6603 return error_mark_node
;
6607 int add_quals
= 0, const_parity
= 0, volatile_parity
= 0;
6609 int unsigned_parity
;
6612 /* This code is basically a duplicate of comp_ptr_ttypes_real. */
6613 for (; ; ttl
= TREE_TYPE (ttl
), ttr
= TREE_TYPE (ttr
))
6616 const_parity
|= TYPE_READONLY (ttl
) < TYPE_READONLY (ttr
);
6617 volatile_parity
|= TYPE_VOLATILE (ttl
) < TYPE_VOLATILE (ttr
);
6620 && (TYPE_READONLY (ttl
) > TYPE_READONLY (ttr
)
6621 || TYPE_VOLATILE (ttl
) > TYPE_VOLATILE (ttr
)))
6623 left_const
&= TYPE_READONLY (ttl
);
6625 if (TREE_CODE (ttl
) != POINTER_TYPE
6626 || TREE_CODE (ttr
) != POINTER_TYPE
)
6629 unsigned_parity
= TREE_UNSIGNED (ttl
) - TREE_UNSIGNED (ttr
);
6630 if (unsigned_parity
)
6632 if (TREE_UNSIGNED (ttl
))
6633 ttr
= unsigned_type (ttr
);
6635 ttl
= unsigned_type (ttl
);
6638 if (comp_target_types (ttl
, ttr
, nptrs
) > 0)
6643 cp_pedwarn ("passing `%T' as argument %P of `%D' adds cv-quals without intervening `const'",
6644 rhstype
, parmnum
, fndecl
);
6646 cp_pedwarn ("%s to `%T' from `%T' adds cv-quals without intervening `const'",
6647 errtype
, type
, rhstype
);
6652 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6653 rhstype
, parmnum
, fndecl
);
6655 cp_pedwarn ("%s to `%T' from `%T' discards const",
6656 errtype
, type
, rhstype
);
6658 if (volatile_parity
)
6661 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6662 rhstype
, parmnum
, fndecl
);
6664 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6665 errtype
, type
, rhstype
);
6667 if (unsigned_parity
> 0)
6670 cp_pedwarn ("passing `%T' as argument %P of `%D' changes signed to unsigned",
6671 rhstype
, parmnum
, fndecl
);
6673 cp_pedwarn ("%s to `%T' from `%T' changes signed to unsigned",
6674 errtype
, type
, rhstype
);
6676 else if (unsigned_parity
< 0)
6679 cp_pedwarn ("passing `%T' as argument %P of `%D' changes unsigned to signed",
6680 rhstype
, parmnum
, fndecl
);
6682 cp_pedwarn ("%s to `%T' from `%T' changes unsigned to signed",
6683 errtype
, type
, rhstype
);
6686 /* C++ is not so friendly about converting function and
6687 member function pointers as C. Emit warnings here. */
6688 if (TREE_CODE (ttl
) == FUNCTION_TYPE
6689 || TREE_CODE (ttl
) == METHOD_TYPE
)
6690 if (! comptypes (ttl
, ttr
, 0))
6692 warning ("conflicting function types in %s:", errtype
);
6693 cp_warning ("\t`%T' != `%T'", type
, rhstype
);
6696 else if (TREE_CODE (TREE_TYPE (rhs
)) == METHOD_TYPE
)
6698 /* When does this happen? */
6699 my_friendly_abort (119);
6700 /* Conversion of a pointer-to-member type to void *. */
6701 rhs
= build_unary_op (ADDR_EXPR
, rhs
, 0);
6702 TREE_TYPE (rhs
) = type
;
6705 else if (TREE_CODE (TREE_TYPE (rhs
)) == OFFSET_TYPE
)
6707 /* When does this happen? */
6708 my_friendly_abort (120);
6709 /* Conversion of a pointer-to-member type to void *. */
6710 rhs
= build_unary_op (ADDR_EXPR
, rhs
, 0);
6711 TREE_TYPE (rhs
) = type
;
6717 cp_error ("passing `%T' as argument %P of `%D'",
6718 rhstype
, parmnum
, fndecl
);
6720 cp_error ("%s to `%T' from `%T'", errtype
, type
, rhstype
);
6721 return error_mark_node
;
6724 return convert (type
, rhs
);
6726 else if (codel
== POINTER_TYPE
&& coder
== INTEGER_TYPE
)
6728 /* An explicit constant 0 can convert to a pointer,
6729 but not a 0 that results from casting or folding. */
6730 if (! (TREE_CODE (rhs
) == INTEGER_CST
&& integer_zerop (rhs
)))
6733 cp_pedwarn ("passing `%T' to argument %P of `%D' lacks a cast",
6734 rhstype
, parmnum
, fndecl
);
6736 cp_pedwarn ("%s to `%T' from `%T' lacks a cast",
6737 errtype
, type
, rhstype
);
6738 return convert (type
, rhs
);
6740 return null_pointer_node
;
6742 else if (codel
== INTEGER_TYPE
6743 && (coder
== POINTER_TYPE
6744 || (coder
== RECORD_TYPE
6745 && (IS_SIGNATURE_POINTER (rhstype
)
6746 || TYPE_PTRMEMFUNC_FLAG (rhstype
)
6747 || IS_SIGNATURE_REFERENCE (rhstype
)))))
6750 cp_pedwarn ("passing `%T' to argument %P of `%D' lacks a cast",
6751 rhstype
, parmnum
, fndecl
);
6753 cp_pedwarn ("%s to `%T' from `%T' lacks a cast",
6754 errtype
, type
, rhstype
);
6755 return convert (type
, rhs
);
6757 else if (codel
== BOOLEAN_TYPE
6758 && (coder
== POINTER_TYPE
6759 || (coder
== RECORD_TYPE
6760 && (IS_SIGNATURE_POINTER (rhstype
)
6761 || TYPE_PTRMEMFUNC_FLAG (rhstype
)
6762 || IS_SIGNATURE_REFERENCE (rhstype
)))))
6763 return convert (type
, rhs
);
6766 else if (((coder
== POINTER_TYPE
&& TREE_CODE (rhs
) == ADDR_EXPR
6767 && TREE_CODE (rhstype
) == POINTER_TYPE
6768 && TREE_CODE (TREE_TYPE (rhstype
)) == METHOD_TYPE
)
6769 || integer_zerop (rhs
)
6770 || TYPE_PTRMEMFUNC_P (rhstype
))
6771 && TYPE_PTRMEMFUNC_P (type
))
6773 tree ttl
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
6774 tree ttr
= (TREE_CODE (rhstype
) == POINTER_TYPE
? rhstype
6775 : TYPE_PTRMEMFUNC_FN_TYPE (type
));
6776 int ctt
= comp_target_types (ttl
, ttr
, 1);
6779 cp_pedwarn ("converting `%T' to `%T' is a contravariance violation",
6782 cp_error ("%s to `%T' from `%T'", errtype
, ttl
, ttr
);
6784 /* compatible pointer to member functions. */
6785 return build_ptrmemfunc (ttl
, rhs
, 0);
6787 else if (codel
== ERROR_MARK
|| coder
== ERROR_MARK
)
6788 return error_mark_node
;
6790 /* This should no longer happen. References are initialized via
6791 `convert_for_initialization'. They should otherwise be
6792 bashed before coming here. */
6793 else if (codel
== REFERENCE_TYPE
)
6794 my_friendly_abort (317);
6795 else if (TYPE_MAIN_VARIANT (type
) == TYPE_MAIN_VARIANT (TREE_TYPE (rhs
)))
6797 tree nrhs
= build1 (NOP_EXPR
, type
, rhs
);
6798 TREE_CONSTANT (nrhs
) = TREE_CONSTANT (rhs
);
6801 else if (TYPE_HAS_CONSTRUCTOR (type
) || IS_AGGR_TYPE (TREE_TYPE (rhs
)))
6802 return convert (type
, rhs
);
6804 cp_error ("%s to `%T' from `%T'", errtype
, type
, rhstype
);
6805 return error_mark_node
;
6808 /* Convert RHS to be of type TYPE. If EXP is non-zero,
6809 it is the target of the initialization.
6810 ERRTYPE is a string to use in error messages.
6812 Two major differences between the behavior of
6813 `convert_for_assignment' and `convert_for_initialization'
6814 are that references are bashed in the former, while
6815 copied in the latter, and aggregates are assigned in
6816 the former (operator=) while initialized in the
6819 If using constructor make sure no conversion operator exists, if one does
6820 exist, an ambiguity exists. */
6822 convert_for_initialization (exp
, type
, rhs
, flags
, errtype
, fndecl
, parmnum
)
6823 tree exp
, type
, rhs
;
6829 register enum tree_code codel
= TREE_CODE (type
);
6830 register tree rhstype
;
6831 register enum tree_code coder
;
6833 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
6834 Strip such NOP_EXPRs, since RHS is used in non-lvalue context. */
6835 if (TREE_CODE (rhs
) == NOP_EXPR
6836 && TREE_TYPE (rhs
) == TREE_TYPE (TREE_OPERAND (rhs
, 0))
6837 && codel
!= REFERENCE_TYPE
)
6838 rhs
= TREE_OPERAND (rhs
, 0);
6840 if (rhs
== error_mark_node
6841 || (TREE_CODE (rhs
) == TREE_LIST
&& TREE_VALUE (rhs
) == error_mark_node
))
6842 return error_mark_node
;
6844 if (TREE_CODE (TREE_TYPE (rhs
)) == OFFSET_TYPE
)
6846 rhs
= resolve_offset_ref (rhs
);
6847 if (rhs
== error_mark_node
)
6848 return error_mark_node
;
6851 if (TREE_CODE (TREE_TYPE (rhs
)) == REFERENCE_TYPE
)
6852 rhs
= convert_from_reference (rhs
);
6854 if ((TREE_CODE (TREE_TYPE (rhs
)) == ARRAY_TYPE
6855 && TREE_CODE (type
) != ARRAY_TYPE
6856 && (TREE_CODE (type
) != REFERENCE_TYPE
6857 || TREE_CODE (TREE_TYPE (type
)) != ARRAY_TYPE
))
6858 || TREE_CODE (TREE_TYPE (rhs
)) == FUNCTION_TYPE
6859 || TREE_CODE (TREE_TYPE (rhs
)) == METHOD_TYPE
)
6860 rhs
= default_conversion (rhs
);
6862 rhstype
= TREE_TYPE (rhs
);
6863 coder
= TREE_CODE (rhstype
);
6865 if (coder
== UNKNOWN_TYPE
)
6867 rhs
= instantiate_type (type
, rhs
, 1);
6868 rhstype
= TREE_TYPE (rhs
);
6869 coder
= TREE_CODE (rhstype
);
6872 if (coder
== ERROR_MARK
)
6873 return error_mark_node
;
6876 /* This is *not* the quick way out! It is the way to disaster. */
6877 if (type
== rhstype
)
6881 /* We accept references to incomplete types, so we can
6882 return here before checking if RHS is of complete type. */
6884 if (codel
== REFERENCE_TYPE
)
6886 /* This should eventually happen in convert_arguments. */
6887 extern int warningcount
, errorcount
;
6891 savew
= warningcount
, savee
= errorcount
;
6892 rhs
= convert_to_reference (type
, rhs
, CONV_IMPLICIT
, flags
,
6893 exp
? exp
: error_mark_node
);
6896 if (warningcount
> savew
)
6897 cp_warning_at ("in passing argument %P of `%+D'", parmnum
, fndecl
);
6898 else if (errorcount
> savee
)
6899 cp_error_at ("in passing argument %P of `%+D'", parmnum
, fndecl
);
6904 rhs
= require_complete_type (rhs
);
6905 if (rhs
== error_mark_node
)
6906 return error_mark_node
;
6908 if (exp
!= 0) exp
= require_complete_type (exp
);
6909 if (exp
== error_mark_node
)
6910 return error_mark_node
;
6912 if (TREE_CODE (rhstype
) == REFERENCE_TYPE
)
6913 rhstype
= TREE_TYPE (rhstype
);
6915 if (TYPE_LANG_SPECIFIC (type
)
6916 && (IS_SIGNATURE_POINTER (type
) || IS_SIGNATURE_REFERENCE (type
)))
6917 return build_signature_pointer_constructor (type
, rhs
);
6919 if (IS_AGGR_TYPE (type
)
6920 && (TYPE_NEEDS_CONSTRUCTING (type
) || TREE_HAS_CONSTRUCTOR (rhs
)))
6922 if (TYPE_MAIN_VARIANT (type
) == TYPE_MAIN_VARIANT (rhstype
))
6924 /* This is sufficient to perform initialization. No need,
6925 apparently, to go through X(X&) to do first-cut
6926 initialization. Return through a TARGET_EXPR so that we get
6927 cleanups if it is used. */
6928 if (TREE_CODE (rhs
) == CALL_EXPR
)
6930 rhs
= build_cplus_new (type
, rhs
, 0);
6933 /* Handle the case of default parameter initialization and
6934 initialization of static variables. */
6935 else if (TREE_CODE (rhs
) == TARGET_EXPR
)
6937 else if (TREE_CODE (rhs
) == INDIRECT_REF
&& TREE_HAS_CONSTRUCTOR (rhs
))
6939 my_friendly_assert (TREE_CODE (TREE_OPERAND (rhs
, 0)) == CALL_EXPR
, 318);
6942 my_friendly_assert (TREE_VALUE (TREE_OPERAND (TREE_OPERAND (rhs
, 0), 1)) == NULL_TREE
, 316);
6943 TREE_VALUE (TREE_OPERAND (TREE_OPERAND (rhs
, 0), 1))
6944 = build_unary_op (ADDR_EXPR
, exp
, 0);
6947 rhs
= build_cplus_new (type
, TREE_OPERAND (rhs
, 0), 0);
6951 if (TYPE_MAIN_VARIANT (type
) == TYPE_MAIN_VARIANT (rhstype
)
6952 || (IS_AGGR_TYPE (rhstype
) && UNIQUELY_DERIVED_FROM_P (type
, rhstype
)))
6954 if (TYPE_HAS_INIT_REF (type
))
6956 tree init
= build_method_call (exp
, constructor_name_full (type
),
6957 build_tree_list (NULL_TREE
, rhs
),
6958 TYPE_BINFO (type
), LOOKUP_NORMAL
);
6960 if (init
== error_mark_node
)
6961 return error_mark_node
;
6965 exp
= build_cplus_new (type
, init
, 0);
6969 return build (COMPOUND_EXPR
, type
, init
, exp
);
6972 /* ??? The following warnings are turned off because
6973 this is another place where the default X(X&) constructor
6975 if (TYPE_HAS_ASSIGNMENT (type
))
6976 cp_warning ("bitwise copy: `%T' defines operator=", type
);
6978 if (TREE_CODE (TREE_TYPE (rhs
)) == REFERENCE_TYPE
)
6979 rhs
= convert_from_reference (rhs
);
6980 if (type
!= rhstype
)
6982 tree nrhs
= build1 (NOP_EXPR
, type
, rhs
);
6983 TREE_CONSTANT (nrhs
) = TREE_CONSTANT (rhs
);
6989 return convert (type
, rhs
);
6992 if (type
== TREE_TYPE (rhs
))
6994 if (TREE_READONLY_DECL_P (rhs
))
6995 rhs
= decl_constant_value (rhs
);
6999 return convert_for_assignment (type
, rhs
, errtype
, fndecl
, parmnum
);
7002 /* Expand an ASM statement with operands, handling output operands
7003 that are not variables or INDIRECT_REFS by transforming such
7004 cases into cases that expand_asm_operands can handle.
7006 Arguments are same as for expand_asm_operands.
7008 We don't do default conversions on all inputs, because it can screw
7009 up operands that are expected to be in memory. */
7012 c_expand_asm_operands (string
, outputs
, inputs
, clobbers
, vol
, filename
, line
)
7013 tree string
, outputs
, inputs
, clobbers
;
7018 int noutputs
= list_length (outputs
);
7020 /* o[I] is the place that output number I should be written. */
7021 register tree
*o
= (tree
*) alloca (noutputs
* sizeof (tree
));
7024 /* Record the contents of OUTPUTS before it is modified. */
7025 for (i
= 0, tail
= outputs
; tail
; tail
= TREE_CHAIN (tail
), i
++)
7026 o
[i
] = TREE_VALUE (tail
);
7028 /* Generate the ASM_OPERANDS insn;
7029 store into the TREE_VALUEs of OUTPUTS some trees for
7030 where the values were actually stored. */
7031 expand_asm_operands (string
, outputs
, inputs
, clobbers
, vol
, filename
, line
);
7033 /* Copy all the intermediate outputs into the specified outputs. */
7034 for (i
= 0, tail
= outputs
; tail
; tail
= TREE_CHAIN (tail
), i
++)
7036 if (o
[i
] != TREE_VALUE (tail
))
7038 expand_expr (build_modify_expr (o
[i
], NOP_EXPR
, TREE_VALUE (tail
)),
7039 const0_rtx
, VOIDmode
, 0);
7042 /* Detect modification of read-only values.
7043 (Otherwise done by build_modify_expr.) */
7046 tree type
= TREE_TYPE (o
[i
]);
7047 if (TYPE_READONLY (type
)
7048 || ((TREE_CODE (type
) == RECORD_TYPE
7049 || TREE_CODE (type
) == UNION_TYPE
)
7050 && C_TYPE_FIELDS_READONLY (type
)))
7051 readonly_error (o
[i
], "modification by `asm'", 1);
7055 /* Those MODIFY_EXPRs could do autoincrements. */
7059 /* Expand a C `return' statement.
7060 RETVAL is the expression for what to return,
7061 or a null pointer for `return;' with no value.
7063 C++: upon seeing a `return', we must call destructors on all
7064 variables in scope which had constructors called on them.
7065 This means that if in a destructor, the base class destructors
7066 must be called before returning.
7068 The RETURN statement in C++ has initialization semantics. */
7071 c_expand_return (retval
)
7074 extern struct nesting
*cond_stack
, *loop_stack
, *case_stack
;
7075 extern tree dtor_label
, ctor_label
;
7076 tree result
= DECL_RESULT (current_function_decl
);
7077 tree valtype
= TREE_TYPE (result
);
7078 register int use_temp
= 0;
7079 int returns_value
= 1;
7081 if (TREE_THIS_VOLATILE (current_function_decl
))
7082 warning ("function declared `noreturn' has a `return' statement");
7084 if (retval
== error_mark_node
)
7086 current_function_returns_null
= 1;
7090 if (retval
== NULL_TREE
)
7092 /* A non-named return value does not count. */
7094 /* Can't just return from a destructor. */
7097 expand_goto (dtor_label
);
7101 if (DECL_CONSTRUCTOR_P (current_function_decl
))
7102 retval
= current_class_decl
;
7103 else if (DECL_NAME (result
) != NULL_TREE
7104 && TREE_CODE (valtype
) != VOID_TYPE
)
7108 current_function_returns_null
= 1;
7110 if (valtype
!= NULL_TREE
&& TREE_CODE (valtype
) != VOID_TYPE
)
7112 if (DECL_NAME (DECL_RESULT (current_function_decl
)) == NULL_TREE
)
7114 pedwarn ("`return' with no value, in function returning non-void");
7115 /* Clear this, so finish_function won't say that we
7116 reach the end of a non-void function (which we don't,
7117 we gave a return!). */
7118 current_function_returns_null
= 0;
7122 expand_null_return ();
7126 else if (DECL_CONSTRUCTOR_P (current_function_decl
)
7127 && retval
!= current_class_decl
)
7129 error ("return from a constructor: use `this = ...' instead");
7130 retval
= current_class_decl
;
7133 if (valtype
== NULL_TREE
|| TREE_CODE (valtype
) == VOID_TYPE
)
7135 current_function_returns_null
= 1;
7136 /* We do this here so we'll avoid a warning about how the function
7137 "may or may not return a value" in finish_function. */
7141 pedwarn ("`return' with a value, in function returning void");
7142 expand_return (retval
);
7144 /* Add some useful error checking for C++. */
7145 else if (TREE_CODE (valtype
) == REFERENCE_TYPE
)
7147 tree whats_returned
;
7148 tree tmp_result
= result
;
7150 /* Don't initialize directly into a non-BLKmode retval, since that
7151 could lose when being inlined by another caller. (GCC can't
7152 read the function return register in an inline function when
7153 the return value is being ignored). */
7154 if (result
&& TYPE_MODE (TREE_TYPE (tmp_result
)) != BLKmode
)
7157 /* convert to reference now, so we can give error if we
7158 return an reference to a non-lvalue. */
7159 retval
= convert_for_initialization (tmp_result
, valtype
, retval
,
7160 LOOKUP_NORMAL
, "return",
7163 /* Sort through common things to see what it is
7164 we are returning. */
7165 whats_returned
= retval
;
7166 if (TREE_CODE (whats_returned
) == COMPOUND_EXPR
)
7168 whats_returned
= TREE_OPERAND (whats_returned
, 1);
7169 if (TREE_CODE (whats_returned
) == ADDR_EXPR
)
7170 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7172 if (TREE_CODE (whats_returned
) == ADDR_EXPR
)
7174 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7175 while (TREE_CODE (whats_returned
) == NEW_EXPR
7176 || TREE_CODE (whats_returned
) == TARGET_EXPR
7177 || TREE_CODE (whats_returned
) == WITH_CLEANUP_EXPR
)
7179 /* Get the target. */
7180 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7181 warning ("returning reference to temporary");
7185 if (TREE_CODE (whats_returned
) == VAR_DECL
&& DECL_NAME (whats_returned
))
7187 if (TEMP_NAME_P (DECL_NAME (whats_returned
)))
7188 warning ("reference to non-lvalue returned");
7189 else if (! TREE_STATIC (whats_returned
)
7190 && IDENTIFIER_LOCAL_VALUE (DECL_NAME (whats_returned
)))
7191 cp_warning_at ("reference to local variable `%D' returned", whats_returned
);
7194 else if (TREE_CODE (retval
) == ADDR_EXPR
)
7196 tree whats_returned
= TREE_OPERAND (retval
, 0);
7198 if (TREE_CODE (whats_returned
) == VAR_DECL
7199 && DECL_NAME (whats_returned
)
7200 && IDENTIFIER_LOCAL_VALUE (DECL_NAME (whats_returned
))
7201 && !TREE_STATIC (whats_returned
))
7202 cp_warning_at ("address of local variable `%D' returned", whats_returned
);
7205 /* Now deal with possible C++ hair:
7206 (1) Compute the return value.
7207 (2) If there are aggregate values with destructors which
7208 must be cleaned up, clean them (taking care
7209 not to clobber the return value).
7210 (3) If an X(X&) constructor is defined, the return
7211 value must be returned via that. */
7213 if (retval
== result
7214 /* Watch out for constructors, which "return" aggregates
7215 via initialization, but which otherwise "return" a pointer. */
7216 || DECL_CONSTRUCTOR_P (current_function_decl
))
7218 /* This is just an error--it's already been reported. */
7219 if (TYPE_SIZE (valtype
) == NULL_TREE
)
7222 if (TYPE_MODE (valtype
) != BLKmode
7223 && any_pending_cleanups (1))
7225 retval
= get_temp_regvar (valtype
, retval
);
7226 use_temp
= obey_regdecls
;
7229 else if (IS_AGGR_TYPE (valtype
) && TYPE_NEEDS_CONSTRUCTING (valtype
))
7231 /* Throw away the cleanup that `build_functional_cast' gave us. */
7232 if (TREE_CODE (retval
) == WITH_CLEANUP_EXPR
7233 && TREE_CODE (TREE_OPERAND (retval
, 0)) == TARGET_EXPR
)
7234 retval
= TREE_OPERAND (retval
, 0);
7235 expand_aggr_init (result
, retval
, 0, LOOKUP_ONLYCONVERTING
);
7236 expand_cleanups_to (NULL_TREE
);
7237 DECL_INITIAL (result
) = NULL_TREE
;
7242 if (TYPE_MODE (valtype
) == VOIDmode
)
7244 if (TYPE_MODE (TREE_TYPE (result
)) != VOIDmode
7245 && warn_return_type
)
7246 warning ("return of void value in function returning non-void");
7247 expand_expr_stmt (retval
);
7251 else if (TYPE_MODE (valtype
) != BLKmode
7252 && any_pending_cleanups (1))
7254 retval
= get_temp_regvar (valtype
, retval
);
7255 expand_cleanups_to (NULL_TREE
);
7256 use_temp
= obey_regdecls
;
7261 retval
= convert_for_initialization (result
, valtype
, retval
,
7263 "return", NULL_TREE
, 0);
7264 DECL_INITIAL (result
) = NULL_TREE
;
7266 if (retval
== error_mark_node
)
7272 if (retval
!= NULL_TREE
7273 && TREE_CODE_CLASS (TREE_CODE (retval
)) == 'd'
7274 && cond_stack
== 0 && loop_stack
== 0 && case_stack
== 0)
7275 current_function_return_value
= retval
;
7279 /* Everything's great--RETVAL is in RESULT. */
7280 if (original_result_rtx
)
7282 store_expr (result
, original_result_rtx
, 0);
7283 expand_cleanups_to (NULL_TREE
);
7285 else if (retval
&& retval
!= result
)
7287 /* Clear this out so the later call to decl_function_context
7288 won't end up bombing on us. */
7289 if (DECL_CONTEXT (result
) == error_mark_node
)
7290 DECL_CONTEXT (result
) = NULL_TREE
;
7291 /* Here is where we finally get RETVAL into RESULT.
7292 `expand_return' does the magic of protecting
7293 RESULT from cleanups. */
7294 retval
= fold (build1 (CLEANUP_POINT_EXPR
, TREE_TYPE (result
),
7296 /* This part _must_ come second, because expand_return looks for
7297 the INIT_EXPR as the toplevel node only. :-( */
7298 retval
= build (INIT_EXPR
, TREE_TYPE (result
), result
, retval
);
7299 TREE_SIDE_EFFECTS (retval
) = 1;
7300 expand_return (retval
);
7303 expand_return (result
);
7305 use_variable (DECL_RTL (result
));
7306 if (ctor_label
&& TREE_CODE (ctor_label
) != ERROR_MARK
)
7307 expand_goto (ctor_label
);
7309 expand_null_return ();
7313 /* We may still need to put RETVAL into RESULT. */
7314 result
= DECL_RESULT (current_function_decl
);
7315 if (original_result_rtx
)
7317 /* Here we have a named return value that went
7318 into memory. We can compute RETVAL into that. */
7320 expand_assignment (result
, retval
, 0, 0);
7322 store_expr (result
, original_result_rtx
, 0);
7323 result
= make_tree (TREE_TYPE (result
), original_result_rtx
);
7325 else if (ctor_label
&& TREE_CODE (ctor_label
) != ERROR_MARK
)
7327 /* Here RETVAL is CURRENT_CLASS_DECL, so there's nothing to do. */
7328 expand_goto (ctor_label
);
7332 /* Here is where we finally get RETVAL into RESULT.
7333 `expand_return' does the magic of protecting
7334 RESULT from cleanups. */
7335 result
= build (INIT_EXPR
, TREE_TYPE (result
), result
, retval
);
7336 TREE_SIDE_EFFECTS (result
) = 1;
7337 expand_return (result
);
7339 else if (TYPE_MODE (TREE_TYPE (result
)) != VOIDmode
)
7340 expand_return (result
);
7343 current_function_returns_value
= returns_value
;
7345 /* These wind up after the BARRIER, which causes problems for
7346 expand_end_binding. What purpose were they supposed to serve? */
7347 if (original_result_rtx
)
7348 use_variable (original_result_rtx
);
7350 use_variable (DECL_RTL (DECL_RESULT (current_function_decl
)));
7353 /* One way to clear out cleanups that EXPR might
7354 generate. Note that this code will really be
7355 dead code, but that is ok--cleanups that were
7356 needed were handled by the magic of `return'. */
7357 expand_cleanups_to (NULL_TREE
);
7360 /* Start a C switch statement, testing expression EXP.
7361 Return EXP if it is valid, an error node otherwise. */
7364 c_expand_start_case (exp
)
7368 register enum tree_code code
;
7370 /* Convert from references, etc. */
7371 exp
= default_conversion (exp
);
7372 type
= TREE_TYPE (exp
);
7373 code
= TREE_CODE (type
);
7375 if (IS_AGGR_TYPE_CODE (code
))
7376 exp
= build_type_conversion (CONVERT_EXPR
, integer_type_node
, exp
, 1);
7378 if (exp
== NULL_TREE
)
7380 error ("switch quantity not an integer");
7381 exp
= error_mark_node
;
7383 type
= TREE_TYPE (exp
);
7384 code
= TREE_CODE (type
);
7386 if (code
!= INTEGER_TYPE
&& code
!= ENUMERAL_TYPE
&& code
!= ERROR_MARK
)
7388 error ("switch quantity not an integer");
7389 exp
= error_mark_node
;
7395 exp
= default_conversion (exp
);
7396 type
= TREE_TYPE (exp
);
7397 index
= get_unwidened (exp
, 0);
7398 /* We can't strip a conversion from a signed type to an unsigned,
7399 because if we did, int_fits_type_p would do the wrong thing
7400 when checking case values for being in range,
7401 and it's too hard to do the right thing. */
7402 if (TREE_UNSIGNED (TREE_TYPE (exp
))
7403 == TREE_UNSIGNED (TREE_TYPE (index
)))
7408 (1, fold (build1 (CLEANUP_POINT_EXPR
, TREE_TYPE (exp
), exp
)),
7409 type
, "switch statement");
7414 /* CONSTP remembers whether or not all the intervening pointers in the `to'
7415 type have been const. */
7417 comp_ptr_ttypes_real (to
, from
, constp
)
7421 for (; ; to
= TREE_TYPE (to
), from
= TREE_TYPE (from
))
7423 if (TREE_CODE (to
) != TREE_CODE (from
))
7426 if (TYPE_READONLY (from
) > TYPE_READONLY (to
)
7427 || TYPE_VOLATILE (from
) > TYPE_VOLATILE (to
))
7431 && (TYPE_READONLY (to
) > TYPE_READONLY (from
)
7432 || TYPE_VOLATILE (to
) > TYPE_READONLY (from
)))
7434 constp
&= TYPE_READONLY (to
);
7436 if (TREE_CODE (to
) != POINTER_TYPE
)
7437 return comptypes (TYPE_MAIN_VARIANT (to
), TYPE_MAIN_VARIANT (from
), 1);
7441 /* When comparing, say, char ** to char const **, this function takes the
7442 'char *' and 'char const *'. Do not pass non-pointer types to this
7445 comp_ptr_ttypes (to
, from
)
7448 return comp_ptr_ttypes_real (to
, from
, 1);