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 ();
42 int mark_addressable ();
43 static tree
convert_for_assignment ();
44 /* static */ tree
convert_for_initialization ();
45 extern tree
shorten_compare ();
46 extern void binary_op_error ();
47 static tree
pointer_int_sum ();
48 static tree
pointer_diff ();
49 static tree
convert_sequence ();
50 /* static */ tree
unary_complex_lvalue ();
51 static tree get_delta_difference
PROTO((tree
, tree
, int));
53 extern rtx original_result_rtx
;
54 extern int warn_synth
;
56 /* Return the target type of TYPE, which meas return T for:
57 T*, T&, T[], T (...), and otherwise, just T. */
63 if (TREE_CODE (type
) == REFERENCE_TYPE
)
64 type
= TREE_TYPE (type
);
65 while (TREE_CODE (type
) == POINTER_TYPE
66 || TREE_CODE (type
) == ARRAY_TYPE
67 || TREE_CODE (type
) == FUNCTION_TYPE
68 || TREE_CODE (type
) == METHOD_TYPE
69 || TREE_CODE (type
) == OFFSET_TYPE
)
70 type
= TREE_TYPE (type
);
74 /* Do `exp = require_complete_type (exp);' to make sure exp
75 does not have an incomplete type. (That includes void types.) */
78 require_complete_type (value
)
81 tree type
= TREE_TYPE (value
);
83 /* First, detect a valid value with a complete type. */
84 if (TYPE_SIZE (type
) != 0
85 && type
!= void_type_node
86 && ! (TYPE_LANG_SPECIFIC (type
)
87 && (IS_SIGNATURE_POINTER (type
) || IS_SIGNATURE_REFERENCE (type
))
88 && TYPE_SIZE (SIGNATURE_TYPE (type
)) == 0))
91 /* If we see X::Y, we build an OFFSET_TYPE which has
92 not been laid out. Try to avoid an error by interpreting
93 it as this->X::Y, if reasonable. */
94 if (TREE_CODE (value
) == OFFSET_REF
96 && TREE_OPERAND (value
, 0) == C_C_D
)
98 tree base
, member
= TREE_OPERAND (value
, 1);
99 tree basetype
= TYPE_OFFSET_BASETYPE (type
);
100 my_friendly_assert (TREE_CODE (member
) == FIELD_DECL
, 305);
101 base
= convert_pointer_to (basetype
, current_class_decl
);
102 value
= build (COMPONENT_REF
, TREE_TYPE (member
),
103 build_indirect_ref (base
, NULL_PTR
), member
);
104 return require_complete_type (value
);
107 incomplete_type_error (value
, type
);
108 return error_mark_node
;
111 /* Return truthvalue of whether type of EXP is instantiated. */
116 return (TREE_CODE (exp
) == TREE_LIST
117 || TREE_TYPE (exp
) == unknown_type_node
118 || (TREE_CODE (TREE_TYPE (exp
)) == OFFSET_TYPE
119 && TREE_TYPE (TREE_TYPE (exp
)) == unknown_type_node
));
122 /* Return truthvalue of whether T is function (or pfn) type. */
127 return (TREE_CODE (t
) == FUNCTION_TYPE
|| TREE_CODE (t
) == METHOD_TYPE
128 || (TREE_CODE (t
) == POINTER_TYPE
129 && (TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
130 || TREE_CODE (TREE_TYPE (t
)) == METHOD_TYPE
)));
133 /* Do `exp = require_instantiated_type (type, exp);' to make sure EXP
134 does not have an uninstantiated type.
135 TYPE is type to instantiate with, if uninstantiated. */
137 require_instantiated_type (type
, exp
, errval
)
138 tree type
, exp
, errval
;
140 if (TREE_TYPE (exp
) == NULL_TREE
)
142 error ("argument list may not have an initializer list");
146 if (TREE_TYPE (exp
) == unknown_type_node
147 || (TREE_CODE (TREE_TYPE (exp
)) == OFFSET_TYPE
148 && TREE_TYPE (TREE_TYPE (exp
)) == unknown_type_node
))
150 exp
= instantiate_type (type
, exp
, 1);
151 if (TREE_TYPE (exp
) == error_mark_node
)
157 /* Return a variant of TYPE which has all the type qualifiers of LIKE
158 as well as those of TYPE. */
161 qualify_type (type
, like
)
164 int constflag
= TYPE_READONLY (type
) || TYPE_READONLY (like
);
165 int volflag
= TYPE_VOLATILE (type
) || TYPE_VOLATILE (like
);
166 /* @@ Must do member pointers here. */
167 return cp_build_type_variant (type
, constflag
, volflag
);
170 /* Return the common type of two parameter lists.
171 We assume that comptypes has already been done and returned 1;
172 if that isn't so, this may crash.
174 As an optimization, free the space we allocate if the parameter
175 lists are already common. */
181 tree oldargs
= p1
, newargs
, n
;
184 char *first_obj
= (char *) oballoc (0);
186 len
= list_length (p1
);
187 newargs
= tree_last (p1
);
189 if (newargs
== void_list_node
)
198 newargs
= tree_cons (NULL_TREE
, NULL_TREE
, newargs
);
203 p1
= TREE_CHAIN (p1
), p2
= TREE_CHAIN (p2
), n
= TREE_CHAIN (n
), i
++)
205 if (TREE_PURPOSE (p1
) && !TREE_PURPOSE (p2
))
207 TREE_PURPOSE (n
) = TREE_PURPOSE (p1
);
210 else if (! TREE_PURPOSE (p1
))
212 if (TREE_PURPOSE (p2
))
214 TREE_PURPOSE (n
) = TREE_PURPOSE (p2
);
220 int cmp
= simple_cst_equal (TREE_PURPOSE (p1
), TREE_PURPOSE (p2
));
222 my_friendly_abort (111);
225 TREE_PURPOSE (n
) = TREE_PURPOSE (p2
);
227 if (TREE_VALUE (p1
) != TREE_VALUE (p2
))
230 TREE_VALUE (n
) = common_type (TREE_VALUE (p1
), TREE_VALUE (p2
));
233 TREE_VALUE (n
) = TREE_VALUE (p1
);
244 /* Return the common type of two types.
245 We assume that comptypes has already been done and returned 1;
246 if that isn't so, this may crash.
248 This is the type for the result of most arithmetic operations
249 if the operands have the given two types.
251 We do not deal with enumeral types here because they have already been
252 converted to integer types. */
258 register enum tree_code code1
;
259 register enum tree_code code2
;
262 /* Save time if the two types are the same. */
264 if (t1
== t2
) return t1
;
266 /* If one type is nonsense, use the other. */
267 if (t1
== error_mark_node
)
269 if (t2
== error_mark_node
)
272 /* Merge the attributes */
274 { register tree a1
, a2
;
275 a1
= TYPE_ATTRIBUTES (t1
);
276 a2
= TYPE_ATTRIBUTES (t2
);
278 /* Either one unset? Take the set one. */
280 if (!(attributes
= a1
))
283 /* One that completely contains the other? Take it. */
285 else if (a2
&& !attribute_list_contained (a1
, a2
))
286 if (attribute_list_contained (a2
, a1
))
290 /* Pick the longest list, and hang on the other list. */
291 /* ??? For the moment we punt on the issue of attrs with args. */
293 if (list_length (a1
) < list_length (a2
))
294 attributes
= a2
, a2
= a1
;
296 for (; a2
; a2
= TREE_CHAIN (a2
))
297 if (lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2
)),
298 attributes
) == NULL_TREE
)
301 TREE_CHAIN (a1
) = attributes
;
307 /* Treat an enum type as the unsigned integer type of the same width. */
309 if (TREE_CODE (t1
) == ENUMERAL_TYPE
)
310 t1
= type_for_size (TYPE_PRECISION (t1
), 1);
311 if (TREE_CODE (t2
) == ENUMERAL_TYPE
)
312 t2
= type_for_size (TYPE_PRECISION (t2
), 1);
314 code1
= TREE_CODE (t1
);
315 code2
= TREE_CODE (t2
);
321 /* If only one is real, use it as the result. */
323 if (code1
== REAL_TYPE
&& code2
!= REAL_TYPE
)
324 return build_type_attribute_variant (t1
, attributes
);
326 if (code2
== REAL_TYPE
&& code1
!= REAL_TYPE
)
327 return build_type_attribute_variant (t2
, attributes
);
329 /* Both real or both integers; use the one with greater precision. */
331 if (TYPE_PRECISION (t1
) > TYPE_PRECISION (t2
))
332 return build_type_attribute_variant (t1
, attributes
);
333 else if (TYPE_PRECISION (t2
) > TYPE_PRECISION (t1
))
334 return build_type_attribute_variant (t2
, attributes
);
336 /* Same precision. Prefer longs to ints even when same size. */
338 if (TYPE_MAIN_VARIANT (t1
) == long_unsigned_type_node
339 || TYPE_MAIN_VARIANT (t2
) == long_unsigned_type_node
)
340 return build_type_attribute_variant (long_unsigned_type_node
,
343 if (TYPE_MAIN_VARIANT (t1
) == long_integer_type_node
344 || TYPE_MAIN_VARIANT (t2
) == long_integer_type_node
)
346 /* But preserve unsignedness from the other type,
347 since long cannot hold all the values of an unsigned int. */
348 if (TREE_UNSIGNED (t1
) || TREE_UNSIGNED (t2
))
349 t1
= long_unsigned_type_node
;
351 t1
= long_integer_type_node
;
352 return build_type_attribute_variant (t1
, attributes
);
355 if (TYPE_MAIN_VARIANT (t1
) == long_double_type_node
356 || TYPE_MAIN_VARIANT (t2
) == long_double_type_node
)
357 return build_type_attribute_variant (long_double_type_node
,
360 /* Otherwise prefer the unsigned one. */
362 if (TREE_UNSIGNED (t1
))
363 return build_type_attribute_variant (t1
, attributes
);
365 return build_type_attribute_variant (t2
, attributes
);
369 /* For two pointers, do this recursively on the target type,
370 and combine the qualifiers of the two types' targets. */
371 /* This code was turned off; I don't know why.
372 But ANSI C++ specifies doing this with the qualifiers.
373 So I turned it on again. */
375 tree tt1
= TYPE_MAIN_VARIANT (TREE_TYPE (t1
));
376 tree tt2
= TYPE_MAIN_VARIANT (TREE_TYPE (t2
));
378 = TYPE_READONLY (TREE_TYPE (t1
)) || TYPE_READONLY (TREE_TYPE (t2
));
380 = TYPE_VOLATILE (TREE_TYPE (t1
)) || TYPE_VOLATILE (TREE_TYPE (t2
));
385 else if (tt1
== void_type_node
|| tt2
== void_type_node
)
386 target
= void_type_node
;
388 target
= common_type (tt1
, tt2
);
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 t1
= build_type_attribute_variant (t1
, attributes
);
397 if (TREE_CODE (target
) == METHOD_TYPE
)
398 t1
= build_ptrmemfunc_type (t1
);
404 t1
= build_pointer_type (common_type (TREE_TYPE (t1
), TREE_TYPE (t2
)));
405 return build_type_attribute_variant (t1
, attributes
);
408 t1
= build_reference_type (common_type (TREE_TYPE (t1
), TREE_TYPE (t2
)));
409 return build_type_attribute_variant (t1
, attributes
);
414 tree elt
= common_type (TREE_TYPE (t1
), TREE_TYPE (t2
));
415 /* Save space: see if the result is identical to one of the args. */
416 if (elt
== TREE_TYPE (t1
) && TYPE_DOMAIN (t1
))
417 return build_type_attribute_variant (t1
, attributes
);
418 if (elt
== TREE_TYPE (t2
) && TYPE_DOMAIN (t2
))
419 return build_type_attribute_variant (t2
, attributes
);
420 /* Merge the element types, and have a size if either arg has one. */
421 t1
= build_array_type (elt
, TYPE_DOMAIN (TYPE_DOMAIN (t1
) ? t1
: t2
));
422 return build_type_attribute_variant (t1
, attributes
);
426 /* Function types: prefer the one that specified arg types.
427 If both do, merge the arg types. Also merge the return types. */
429 tree valtype
= common_type (TREE_TYPE (t1
), TREE_TYPE (t2
));
430 tree p1
= TYPE_ARG_TYPES (t1
);
431 tree p2
= TYPE_ARG_TYPES (t2
);
434 /* Save space: see if the result is identical to one of the args. */
435 if (valtype
== TREE_TYPE (t1
) && ! p2
)
436 return build_type_attribute_variant (t1
, attributes
);
437 if (valtype
== TREE_TYPE (t2
) && ! p1
)
438 return build_type_attribute_variant (t2
, attributes
);
440 /* Simple way if one arg fails to specify argument types. */
441 if (p1
== NULL_TREE
|| TREE_VALUE (p1
) == void_type_node
)
443 rval
= build_function_type (valtype
, p2
);
444 if ((raises
= TYPE_RAISES_EXCEPTIONS (t2
)))
445 rval
= build_exception_variant (NULL_TREE
, rval
, raises
);
446 return build_type_attribute_variant (rval
, attributes
);
448 raises
= TYPE_RAISES_EXCEPTIONS (t1
);
449 if (p2
== NULL_TREE
|| TREE_VALUE (p2
) == void_type_node
)
451 rval
= build_function_type (valtype
, p1
);
453 rval
= build_exception_variant (NULL_TREE
, rval
, raises
);
454 return build_type_attribute_variant (rval
, attributes
);
457 rval
= build_function_type (valtype
, commonparms (p1
, p2
));
458 rval
= build_exception_variant (NULL_TREE
, rval
, raises
);
459 return build_type_attribute_variant (rval
, attributes
);
464 my_friendly_assert (TYPE_MAIN_VARIANT (t1
) == t1
465 && TYPE_MAIN_VARIANT (t2
) == t2
, 306);
467 if (DERIVED_FROM_P (t1
, t2
) && binfo_or_else (t1
, t2
))
468 return build_type_attribute_variant (t1
, attributes
);
469 else if (binfo_or_else (t2
, t1
))
470 return build_type_attribute_variant (t2
, attributes
);
472 compiler_error ("common_type called with uncommon aggregate types");
475 if (TREE_CODE (TREE_TYPE (t1
)) == TREE_CODE (TREE_TYPE (t2
)))
477 /* Get this value the long way, since TYPE_METHOD_BASETYPE
478 is just the main variant of this. */
482 tree b1
= TYPE_OFFSET_BASETYPE (t1
);
483 tree b2
= TYPE_OFFSET_BASETYPE (t2
);
485 if (DERIVED_FROM_P (b1
, b2
) && binfo_or_else (b1
, b2
))
486 basetype
= TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t2
)));
489 if (binfo_or_else (b2
, b1
) == NULL_TREE
)
490 compiler_error ("common_type called with uncommon method types");
491 basetype
= TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t1
)));
494 raises
= TYPE_RAISES_EXCEPTIONS (t1
);
496 /* If this was a member function type, get back to the
497 original type of type member function (i.e., without
498 the class instance variable up front. */
499 t1
= build_function_type (TREE_TYPE (t1
), TREE_CHAIN (TYPE_ARG_TYPES (t1
)));
500 t2
= build_function_type (TREE_TYPE (t2
), TREE_CHAIN (TYPE_ARG_TYPES (t2
)));
501 t3
= common_type (t1
, t2
);
502 t3
= build_cplus_method_type (basetype
, TREE_TYPE (t3
), TYPE_ARG_TYPES (t3
));
503 t1
= build_exception_variant (basetype
, t3
, raises
);
506 compiler_error ("common_type called with uncommon method types");
508 return build_type_attribute_variant (t1
, attributes
);
511 if (TREE_TYPE (t1
) == TREE_TYPE (t2
))
513 tree b1
= TYPE_OFFSET_BASETYPE (t1
);
514 tree b2
= TYPE_OFFSET_BASETYPE (t2
);
516 if (DERIVED_FROM_P (b1
, b2
) && binfo_or_else (b1
, b2
))
517 return build_type_attribute_variant (t2
, attributes
);
518 else if (binfo_or_else (b2
, b1
))
519 return build_type_attribute_variant (t1
, attributes
);
521 compiler_error ("common_type called with uncommon member types");
524 return build_type_attribute_variant (t1
, attributes
);
528 /* Return 1 if TYPE1 and TYPE2 raise the same exceptions. */
530 compexcepttypes (t1
, t2
, strict
)
534 return TYPE_RAISES_EXCEPTIONS (t1
) == TYPE_RAISES_EXCEPTIONS (t2
);
538 comp_array_types (cmp
, t1
, t2
, strict
)
539 register int (*cmp
)();
543 tree d1
= TYPE_DOMAIN (t1
);
544 tree d2
= TYPE_DOMAIN (t2
);
546 /* Target types must match incl. qualifiers. */
547 if (!(TREE_TYPE (t1
) == TREE_TYPE (t2
)
548 || (*cmp
) (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
)))
551 /* Sizes must match unless one is missing or variable. */
552 if (d1
== 0 || d2
== 0 || d1
== d2
553 || TREE_CODE (TYPE_MIN_VALUE (d1
)) != INTEGER_CST
554 || TREE_CODE (TYPE_MIN_VALUE (d2
)) != INTEGER_CST
555 || TREE_CODE (TYPE_MAX_VALUE (d1
)) != INTEGER_CST
556 || TREE_CODE (TYPE_MAX_VALUE (d2
)) != INTEGER_CST
)
559 return ((TREE_INT_CST_LOW (TYPE_MIN_VALUE (d1
))
560 == TREE_INT_CST_LOW (TYPE_MIN_VALUE (d2
)))
561 && (TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d1
))
562 == TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d2
)))
563 && (TREE_INT_CST_LOW (TYPE_MAX_VALUE (d1
))
564 == TREE_INT_CST_LOW (TYPE_MAX_VALUE (d2
)))
565 && (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d1
))
566 == TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d2
))));
569 /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
570 or various other operations. This is what ANSI C++ speaks of as
573 For C++: argument STRICT says we should be strict about this
576 2 : strict, except that if one type is a reference and
577 the other is not, compare the target type of the
578 reference to the type that's not a reference (ARM, p308).
579 This is used for checking for invalid overloading.
580 1 : strict (compared according to ANSI C)
581 This is used for checking whether two function decls match.
582 0 : <= (compared according to C++)
583 -1: <= or >= (relaxed)
585 Otherwise, pointers involving base classes and derived classes
586 can be mixed as valid: i.e. a pointer to a base class may be assigned
587 to a pointer to one of its derived classes, as per C++. A pointer to
588 a derived class may be passed as a parameter to a function expecting a
589 pointer to a base classes. These allowances do not commute. In this
590 case, TYPE1 is assumed to be the base class, and TYPE2 is assumed to
591 be the derived class. */
593 comptypes (type1
, type2
, strict
)
597 register tree t1
= type1
;
598 register tree t2
= type2
;
601 /* Suppress errors caused by previously reported errors */
606 /* This should never happen. */
607 my_friendly_assert (t1
!= error_mark_node
, 307);
609 if (t2
== error_mark_node
)
614 /* Treat an enum type as the unsigned integer type of the same width. */
616 if (TREE_CODE (t1
) == ENUMERAL_TYPE
)
617 t1
= type_for_size (TYPE_PRECISION (t1
), 1);
618 if (TREE_CODE (t2
) == ENUMERAL_TYPE
)
619 t2
= type_for_size (TYPE_PRECISION (t2
), 1);
625 /* Different classes of types can't be compatible. */
627 if (TREE_CODE (t1
) != TREE_CODE (t2
))
630 && ((TREE_CODE (t1
) == REFERENCE_TYPE
)
631 ^ (TREE_CODE (t2
) == REFERENCE_TYPE
)))
633 if (TREE_CODE (t1
) == REFERENCE_TYPE
)
634 return comptypes (TREE_TYPE (t1
), t2
, 1);
635 return comptypes (t1
, TREE_TYPE (t2
), 1);
643 /* Qualifiers must match. */
645 if (TYPE_READONLY (t1
) != TYPE_READONLY (t2
))
647 if (TYPE_VOLATILE (t1
) != TYPE_VOLATILE (t2
))
650 /* Allow for two different type nodes which have essentially the same
651 definition. Note that we already checked for equality of the type
652 type qualifiers (just above). */
654 if (TYPE_MAIN_VARIANT (t1
) == TYPE_MAIN_VARIANT (t2
))
657 #ifdef COMP_TYPE_ATTRIBUTES
658 if (! (attrval
= COMP_TYPE_ATTRIBUTES (t1
, t2
)))
661 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
665 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
668 switch (TREE_CODE (t1
))
677 val
= (comptypes (TYPE_POINTER_TO (TYPE_OFFSET_BASETYPE (t1
)),
678 TYPE_POINTER_TO (TYPE_OFFSET_BASETYPE (t2
)), strict
)
679 && comptypes (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
));
683 if (! compexcepttypes (t1
, t2
, strict
))
686 /* This case is anti-symmetrical!
687 One can pass a base member (or member function)
688 to something expecting a derived member (or member function),
689 but not vice-versa! */
691 val
= (comptypes (TYPE_POINTER_TO (TYPE_METHOD_BASETYPE (t2
)),
692 TYPE_POINTER_TO (TYPE_METHOD_BASETYPE (t1
)), strict
)
693 && comptypes (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
)
694 && compparms (TREE_CHAIN (TYPE_ARG_TYPES (t1
)),
695 TREE_CHAIN (TYPE_ARG_TYPES (t2
)), strict
));
709 if (TREE_CODE (t1
) == RECORD_TYPE
&& TREE_CODE (t2
) == RECORD_TYPE
)
713 rval
= t1
== t2
|| UNIQUELY_DERIVED_FROM_P (t1
, t2
);
722 val
= UNIQUELY_DERIVED_FROM_P (t2
, t1
);
729 val
= comptypes (t1
, t2
, strict
);
733 if (! compexcepttypes (t1
, t2
, strict
))
736 val
= ((TREE_TYPE (t1
) == TREE_TYPE (t2
)
737 || comptypes (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
))
738 && compparms (TYPE_ARG_TYPES (t1
), TYPE_ARG_TYPES (t2
), strict
));
742 /* Target types must match incl. qualifiers. */
743 val
= comp_array_types (comptypes
, t1
, t2
, strict
);
746 case TEMPLATE_TYPE_PARM
:
749 case UNINSTANTIATED_P_TYPE
:
750 if (UPT_TEMPLATE (t1
) != UPT_TEMPLATE (t2
))
753 int i
= TREE_VEC_LENGTH (UPT_PARMS (t1
));
754 tree
*p1
= &TREE_VEC_ELT (UPT_PARMS (t1
), 0);
755 tree
*p2
= &TREE_VEC_ELT (UPT_PARMS (t2
), 0);
759 if (TREE_CODE_CLASS (TREE_CODE (p1
[i
])) == 't')
761 if (! comptypes (p1
[i
], p2
[i
], 1))
766 if (simple_cst_equal (p1
[i
], p2
[i
]) <= 0)
773 return attrval
== 2 && val
== 1 ? 2 : val
;
776 /* Return 1 if TTL and TTR are pointers to types that are equivalent,
777 ignoring their qualifiers.
779 NPTRS is the number of pointers we can strip off and keep cool.
780 This is used to permit (for aggr A, aggr B) A, B* to convert to A*,
781 but to not permit B** to convert to A**. */
784 comp_target_types (ttl
, ttr
, nptrs
)
788 ttl
= TYPE_MAIN_VARIANT (ttl
);
789 ttr
= TYPE_MAIN_VARIANT (ttr
);
793 if (TREE_CODE (ttr
) != TREE_CODE (ttl
))
796 if (TREE_CODE (ttr
) == POINTER_TYPE
)
798 ttl
= TREE_TYPE (ttl
);
799 ttr
= TREE_TYPE (ttr
);
803 if (TREE_CODE (ttl
) == VOID_TYPE
804 && TREE_CODE (ttr
) != FUNCTION_TYPE
805 && TREE_CODE (ttr
) != METHOD_TYPE
806 && TREE_CODE (ttr
) != OFFSET_TYPE
)
808 else if (TREE_CODE (ttr
) == VOID_TYPE
809 && TREE_CODE (ttl
) != FUNCTION_TYPE
810 && TREE_CODE (ttl
) != METHOD_TYPE
811 && TREE_CODE (ttl
) != OFFSET_TYPE
)
813 else if (TREE_CODE (ttl
) == POINTER_TYPE
814 || TREE_CODE (ttl
) == ARRAY_TYPE
)
815 return comp_ptr_ttypes (ttl
, ttr
);
818 return comp_target_types (ttl
, ttr
, nptrs
- 1);
821 if (TREE_CODE (ttr
) == REFERENCE_TYPE
)
822 return comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), nptrs
);
823 if (TREE_CODE (ttr
) == ARRAY_TYPE
)
824 return comp_array_types (comp_target_types
, ttl
, ttr
, 0);
825 else if (TREE_CODE (ttr
) == FUNCTION_TYPE
|| TREE_CODE (ttr
) == METHOD_TYPE
)
826 if (comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), nptrs
))
827 switch (comp_target_parms (TYPE_ARG_TYPES (ttl
), TYPE_ARG_TYPES (ttr
), 1))
836 my_friendly_abort (112);
842 else if (TREE_CODE (ttr
) == OFFSET_TYPE
)
844 /* Contravariance: we can assign a pointer to base member to a pointer
845 to derived member. Note difference from simple pointer case, where
846 we can pass a pointer to derived to a pointer to base. */
847 if (comptypes (TYPE_OFFSET_BASETYPE (ttr
), TYPE_OFFSET_BASETYPE (ttl
), 0))
848 return comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), nptrs
);
849 else if (comptypes (TYPE_OFFSET_BASETYPE (ttl
), TYPE_OFFSET_BASETYPE (ttr
), 0)
850 && comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), nptrs
))
853 else if (IS_AGGR_TYPE (ttl
))
857 if (comptypes (TYPE_POINTER_TO (ttl
), TYPE_POINTER_TO (ttr
), 0))
859 if (comptypes (TYPE_POINTER_TO (ttr
), TYPE_POINTER_TO (ttl
), 0))
867 /* If two types share a common base type, return that basetype.
868 If there is not a unique most-derived base type, this function
869 returns ERROR_MARK_NODE. */
871 common_base_type (tt1
, tt2
)
874 tree best
= NULL_TREE
, tmp
;
877 /* If one is a baseclass of another, that's good enough. */
878 if (UNIQUELY_DERIVED_FROM_P (tt1
, tt2
))
880 if (UNIQUELY_DERIVED_FROM_P (tt2
, tt1
))
884 /* If they share a virtual baseclass, that's good enough. */
885 for (tmp
= CLASSTYPE_VBASECLASSES (tt1
); tmp
; tmp
= TREE_CHAIN (tmp
))
887 if (binfo_member (BINFO_TYPE (tmp
), CLASSTYPE_VBASECLASSES (tt2
)))
888 return BINFO_TYPE (tmp
);
892 /* Otherwise, try to find a unique baseclass of TT1
893 that is shared by TT2, and follow that down. */
894 for (i
= CLASSTYPE_N_BASECLASSES (tt1
)-1; i
>= 0; i
--)
896 tree basetype
= TYPE_BINFO_BASETYPE (tt1
, i
);
897 tree trial
= common_base_type (basetype
, tt2
);
900 if (trial
== error_mark_node
)
902 if (best
== NULL_TREE
)
904 else if (best
!= trial
)
905 return error_mark_node
;
910 for (i
= CLASSTYPE_N_BASECLASSES (tt2
)-1; i
>= 0; i
--)
912 tree basetype
= TYPE_BINFO_BASETYPE (tt2
, i
);
913 tree trial
= common_base_type (tt1
, basetype
);
916 if (trial
== error_mark_node
)
918 if (best
== NULL_TREE
)
920 else if (best
!= trial
)
921 return error_mark_node
;
927 /* Subroutines of `comptypes'. */
929 /* Return 1 if two parameter type lists PARMS1 and PARMS2
930 are equivalent in the sense that functions with those parameter types
931 can have equivalent types.
932 If either list is empty, we win.
933 Otherwise, the two lists must be equivalent, element by element.
935 C++: See comment above about TYPE1, TYPE2, STRICT.
936 If STRICT == 3, it means checking is strict, but do not compare
937 default parameter values. */
939 compparms (parms1
, parms2
, strict
)
943 register tree t1
= parms1
, t2
= parms2
;
945 /* An unspecified parmlist matches any specified parmlist
946 whose argument types don't need default promotions. */
948 if (strict
<= 0 && t1
== 0)
949 return self_promoting_args_p (t2
);
950 if (strict
< 0 && t2
== 0)
951 return self_promoting_args_p (t1
);
955 if (t1
== 0 && t2
== 0)
957 /* If one parmlist is shorter than the other,
958 they fail to match, unless STRICT is <= 0. */
959 if (t1
== 0 || t2
== 0)
966 return t1
&& TREE_PURPOSE (t1
);
968 if (! comptypes (TREE_VALUE (t2
), TREE_VALUE (t1
), strict
))
973 return t2
== void_list_node
&& TREE_PURPOSE (t1
);
974 return TREE_PURPOSE (t1
) || TREE_PURPOSE (t2
);
977 /* Default parms are not part of the type of a function. */
978 if (strict
!= 3 && TREE_PURPOSE (t1
) && TREE_PURPOSE (t2
))
980 int cmp
= simple_cst_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
));
982 my_friendly_abort (113);
988 t1
= TREE_CHAIN (t1
);
989 t2
= TREE_CHAIN (t2
);
993 /* This really wants return whether or not parameter type lists
994 would make their owning functions assignment compatible or not. */
996 comp_target_parms (parms1
, parms2
, strict
)
1000 register tree t1
= parms1
, t2
= parms2
;
1001 int warn_contravariance
= 0;
1003 /* An unspecified parmlist matches any specified parmlist
1004 whose argument types don't need default promotions.
1005 @@@ see 13.3.3 for a counterexample... */
1007 if (t1
== 0 && t2
!= 0)
1009 cp_pedwarn ("ANSI C++ prohibits conversion from `(%#T)' to `(...)'",
1011 return self_promoting_args_p (t2
);
1014 return self_promoting_args_p (t1
);
1016 for (; t1
|| t2
; t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
))
1020 /* If one parmlist is shorter than the other,
1021 they fail to match, unless STRICT is <= 0. */
1022 if (t1
== 0 || t2
== 0)
1027 return 1 + warn_contravariance
;
1028 return ((t1
&& TREE_PURPOSE (t1
)) + warn_contravariance
);
1030 p1
= TREE_VALUE (t1
);
1031 p2
= TREE_VALUE (t2
);
1035 if ((TREE_CODE (p1
) == POINTER_TYPE
&& TREE_CODE (p2
) == POINTER_TYPE
)
1036 || (TREE_CODE (p1
) == REFERENCE_TYPE
&& TREE_CODE (p2
) == REFERENCE_TYPE
))
1039 && (TYPE_MAIN_VARIANT (TREE_TYPE (p1
))
1040 == TYPE_MAIN_VARIANT (TREE_TYPE (p2
))))
1043 /* The following is wrong for contravariance,
1044 but many programs depend on it. */
1045 if (TREE_TYPE (p1
) == void_type_node
)
1047 if (TREE_TYPE (p2
) == void_type_node
)
1049 warn_contravariance
= 1;
1052 if (IS_AGGR_TYPE (TREE_TYPE (p1
)))
1054 if (comptypes (p2
, p1
, 0) == 0)
1056 if (comptypes (p1
, p2
, 0) != 0)
1057 warn_contravariance
= 1;
1064 /* Note backwards order due to contravariance. */
1065 if (comp_target_types (p2
, p1
, 1) == 0)
1067 if (comp_target_types (p1
, p2
, 1))
1069 warn_contravariance
= 1;
1075 /* What good do these cases do? */
1077 return p2
== void_type_node
&& TREE_PURPOSE (t1
);
1078 return TREE_PURPOSE (t1
) || TREE_PURPOSE (t2
);
1081 /* Target types are compatible--just make sure that if
1082 we use parameter lists, that they are ok as well. */
1083 if (TREE_CODE (p1
) == FUNCTION_TYPE
|| TREE_CODE (p1
) == METHOD_TYPE
)
1084 switch (comp_target_parms (TYPE_ARG_TYPES (p1
),
1085 TYPE_ARG_TYPES (p2
),
1093 warn_contravariance
= 1;
1096 if (TREE_PURPOSE (t1
) && TREE_PURPOSE (t2
))
1098 int cmp
= simple_cst_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
));
1100 my_friendly_abort (114);
1105 return 1 + warn_contravariance
;
1108 /* Return 1 if PARMS specifies a fixed number of parameters
1109 and none of their types is affected by default promotions. */
1112 self_promoting_args_p (parms
)
1116 for (t
= parms
; t
; t
= TREE_CHAIN (t
))
1118 register tree type
= TREE_VALUE (t
);
1120 if (TREE_CHAIN (t
) == 0 && type
!= void_type_node
)
1123 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
1129 if (C_PROMOTING_INTEGER_TYPE_P (type
))
1135 /* Return an unsigned type the same as TYPE in other respects.
1137 C++: must make these work for type variants as well. */
1140 unsigned_type (type
)
1143 tree type1
= TYPE_MAIN_VARIANT (type
);
1144 if (type1
== signed_char_type_node
|| type1
== char_type_node
)
1145 return unsigned_char_type_node
;
1146 if (type1
== integer_type_node
)
1147 return unsigned_type_node
;
1148 if (type1
== short_integer_type_node
)
1149 return short_unsigned_type_node
;
1150 if (type1
== long_integer_type_node
)
1151 return long_unsigned_type_node
;
1152 if (type1
== long_long_integer_type_node
)
1153 return long_long_unsigned_type_node
;
1157 /* Return a signed type the same as TYPE in other respects. */
1163 tree type1
= TYPE_MAIN_VARIANT (type
);
1164 if (type1
== unsigned_char_type_node
|| type1
== char_type_node
)
1165 return signed_char_type_node
;
1166 if (type1
== unsigned_type_node
)
1167 return integer_type_node
;
1168 if (type1
== short_unsigned_type_node
)
1169 return short_integer_type_node
;
1170 if (type1
== long_unsigned_type_node
)
1171 return long_integer_type_node
;
1172 if (type1
== long_long_unsigned_type_node
)
1173 return long_long_integer_type_node
;
1177 /* Return a type the same as TYPE except unsigned or
1178 signed according to UNSIGNEDP. */
1181 signed_or_unsigned_type (unsignedp
, type
)
1185 if (! INTEGRAL_TYPE_P (type
))
1187 if (TYPE_PRECISION (type
) == TYPE_PRECISION (signed_char_type_node
))
1188 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
1189 if (TYPE_PRECISION (type
) == TYPE_PRECISION (integer_type_node
))
1190 return unsignedp
? unsigned_type_node
: integer_type_node
;
1191 if (TYPE_PRECISION (type
) == TYPE_PRECISION (short_integer_type_node
))
1192 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
1193 if (TYPE_PRECISION (type
) == TYPE_PRECISION (long_integer_type_node
))
1194 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
1195 if (TYPE_PRECISION (type
) == TYPE_PRECISION (long_long_integer_type_node
))
1196 return (unsignedp
? long_long_unsigned_type_node
1197 : long_long_integer_type_node
);
1205 enum tree_code code
= TREE_CODE (type
);
1208 if (code
== FUNCTION_TYPE
)
1210 if (pedantic
|| warn_pointer_arith
)
1211 pedwarn ("ANSI C++ forbids taking the sizeof a function type");
1212 return size_int (1);
1214 if (code
== METHOD_TYPE
)
1216 if (pedantic
|| warn_pointer_arith
)
1217 pedwarn ("ANSI C++ forbids taking the sizeof a method type");
1218 return size_int (1);
1220 if (code
== VOID_TYPE
)
1222 if (pedantic
|| warn_pointer_arith
)
1223 pedwarn ("ANSI C++ forbids taking the sizeof a void type");
1224 return size_int (1);
1226 if (code
== ERROR_MARK
)
1227 return size_int (1);
1229 /* ARM $5.3.2: ``When applied to a reference, the result is the size of the
1230 referenced object.'' */
1231 if (code
== REFERENCE_TYPE
)
1232 type
= TREE_TYPE (type
);
1234 /* We couldn't find anything in the ARM or the draft standard that says,
1235 one way or the other, if doing sizeof on something that doesn't have
1236 an object associated with it is correct or incorrect. For example, if
1237 you declare `struct S { char str[16]; };', and in your program do
1238 a `sizeof (S::str)', should we flag that as an error or should we give
1239 the size of it? Since it seems like a reasonable thing to do, we'll go
1240 with giving the value. */
1241 if (code
== OFFSET_TYPE
)
1242 type
= TREE_TYPE (type
);
1244 /* @@ This also produces an error for a signature ref.
1245 In that case we should be able to do better. */
1246 if (IS_SIGNATURE (type
))
1248 error ("`sizeof' applied to a signature type");
1249 return size_int (0);
1252 if (TYPE_SIZE (type
) == 0)
1254 error ("`sizeof' applied to an incomplete type");
1255 return size_int (0);
1258 /* Convert in case a char is more than one unit. */
1259 t
= size_binop (CEIL_DIV_EXPR
, TYPE_SIZE (type
),
1260 size_int (TYPE_PRECISION (char_type_node
)));
1261 /* size_binop does not put the constant in range, so do it now. */
1262 if (TREE_CODE (t
) == INTEGER_CST
&& force_fit_type (t
, 0))
1263 TREE_CONSTANT_OVERFLOW (t
) = TREE_OVERFLOW (t
) = 1;
1268 c_sizeof_nowarn (type
)
1271 enum tree_code code
= TREE_CODE (type
);
1274 if (code
== FUNCTION_TYPE
1275 || code
== METHOD_TYPE
1276 || code
== VOID_TYPE
1277 || code
== ERROR_MARK
)
1278 return size_int (1);
1279 if (code
== REFERENCE_TYPE
)
1280 type
= TREE_TYPE (type
);
1282 if (TYPE_SIZE (type
) == 0)
1285 /* ??? Tiemann, why have any diagnostic here?
1286 There is none in the corresponding function for C. */
1287 warning ("sizeof applied to an incomplete type");
1289 return size_int (0);
1292 /* Convert in case a char is more than one unit. */
1293 t
= size_binop (CEIL_DIV_EXPR
, TYPE_SIZE (type
),
1294 size_int (TYPE_PRECISION (char_type_node
)));
1295 force_fit_type (t
, 0);
1299 /* Implement the __alignof keyword: Return the minimum required
1300 alignment of TYPE, measured in bytes. */
1306 enum tree_code code
= TREE_CODE (type
);
1309 if (code
== FUNCTION_TYPE
|| code
== METHOD_TYPE
)
1310 return size_int (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
1312 if (code
== VOID_TYPE
|| code
== ERROR_MARK
)
1313 return size_int (1);
1315 /* C++: this is really correct! */
1316 if (code
== REFERENCE_TYPE
)
1317 type
= TREE_TYPE (type
);
1319 /* @@ This also produces an error for a signature ref.
1320 In that case we should be able to do better. */
1321 if (IS_SIGNATURE (type
))
1323 error ("`__alignof' applied to a signature type");
1324 return size_int (1);
1327 t
= size_int (TYPE_ALIGN (type
) / BITS_PER_UNIT
);
1328 force_fit_type (t
, 0);
1332 /* Perform default promotions for C data used in expressions.
1333 Arrays and functions are converted to pointers;
1334 enumeral types or short or char, to int.
1335 In addition, manifest constants symbols are replaced by their values.
1337 C++: this will automatically bash references to their target type. */
1340 default_conversion (exp
)
1343 register tree type
= TREE_TYPE (exp
);
1344 register enum tree_code code
= TREE_CODE (type
);
1346 if (code
== OFFSET_TYPE
/* || TREE_CODE (exp) == OFFSET_REF */ )
1348 if (TREE_CODE (exp
) == OFFSET_REF
)
1349 return default_conversion (resolve_offset_ref (exp
));
1351 type
= TREE_TYPE (type
);
1352 code
= TREE_CODE (type
);
1355 if (code
== REFERENCE_TYPE
)
1357 exp
= convert_from_reference (exp
);
1358 type
= TREE_TYPE (exp
);
1359 code
= TREE_CODE (type
);
1362 /* Constants can be used directly unless they're not loadable. */
1363 if (TREE_CODE (exp
) == CONST_DECL
)
1364 exp
= DECL_INITIAL (exp
);
1365 /* Replace a nonvolatile const static variable with its value. */
1366 else if (TREE_READONLY_DECL_P (exp
) && DECL_MODE (exp
) != BLKmode
)
1368 exp
= decl_constant_value (exp
);
1369 type
= TREE_TYPE (exp
);
1372 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
1373 Leave such NOP_EXPRs, since RHS is being used in non-lvalue context. */
1375 if (INTEGRAL_CODE_P (code
))
1377 tree t
= type_promotes_to (type
);
1379 return convert (t
, exp
);
1381 if (flag_traditional
1382 && TYPE_MAIN_VARIANT (type
) == float_type_node
)
1383 return convert (double_type_node
, exp
);
1384 if (code
== VOID_TYPE
)
1386 error ("void value not ignored as it ought to be");
1387 return error_mark_node
;
1389 if (code
== FUNCTION_TYPE
)
1391 return build_unary_op (ADDR_EXPR
, exp
, 0);
1393 if (code
== METHOD_TYPE
)
1395 if (TREE_CODE (exp
) == OFFSET_REF
)
1397 my_friendly_assert (TREE_CODE (TREE_OPERAND (exp
, 1)) == FUNCTION_DECL
,
1399 return build_unary_op (ADDR_EXPR
, TREE_OPERAND (exp
, 1), 0);
1401 return build_unary_op (ADDR_EXPR
, exp
, 0);
1403 if (code
== ARRAY_TYPE
)
1408 int constp
, volatilep
;
1410 if (TREE_CODE (exp
) == INDIRECT_REF
)
1412 /* Stripping away the INDIRECT_REF is not the right
1413 thing to do for references... */
1414 tree inner
= TREE_OPERAND (exp
, 0);
1415 if (TREE_CODE (TREE_TYPE (inner
)) == REFERENCE_TYPE
)
1417 inner
= build1 (CONVERT_EXPR
,
1418 build_pointer_type (TREE_TYPE (TREE_TYPE (inner
))),
1420 TREE_REFERENCE_EXPR (inner
) = 1;
1422 return convert (TYPE_POINTER_TO (TREE_TYPE (type
)), inner
);
1425 if (TREE_CODE (exp
) == COMPOUND_EXPR
)
1427 tree op1
= default_conversion (TREE_OPERAND (exp
, 1));
1428 return build (COMPOUND_EXPR
, TREE_TYPE (op1
),
1429 TREE_OPERAND (exp
, 0), op1
);
1433 && ! (TREE_CODE (exp
) == CONSTRUCTOR
&& TREE_STATIC (exp
)))
1435 error ("invalid use of non-lvalue array");
1436 return error_mark_node
;
1439 constp
= volatilep
= 0;
1440 if (TREE_CODE_CLASS (TREE_CODE (exp
)) == 'r'
1441 || TREE_CODE_CLASS (TREE_CODE (exp
)) == 'd')
1443 constp
= TREE_READONLY (exp
);
1444 volatilep
= TREE_THIS_VOLATILE (exp
);
1447 restype
= TREE_TYPE (type
);
1448 if (TYPE_READONLY (type
) || TYPE_VOLATILE (type
)
1449 || constp
|| volatilep
)
1450 restype
= cp_build_type_variant (restype
,
1451 TYPE_READONLY (type
) || constp
,
1452 TYPE_VOLATILE (type
) || volatilep
);
1453 ptrtype
= build_pointer_type (restype
);
1455 if (TREE_CODE (exp
) == VAR_DECL
)
1457 /* ??? This is not really quite correct
1458 in that the type of the operand of ADDR_EXPR
1459 is not the target type of the type of the ADDR_EXPR itself.
1460 Question is, can this lossage be avoided? */
1461 adr
= build1 (ADDR_EXPR
, ptrtype
, exp
);
1462 if (mark_addressable (exp
) == 0)
1463 return error_mark_node
;
1464 TREE_CONSTANT (adr
) = staticp (exp
);
1465 TREE_SIDE_EFFECTS (adr
) = 0; /* Default would be, same as EXP. */
1468 /* This way is better for a COMPONENT_REF since it can
1469 simplify the offset for a component. */
1470 adr
= build_unary_op (ADDR_EXPR
, exp
, 1);
1471 return convert (ptrtype
, adr
);
1477 build_object_ref (datum
, basetype
, field
)
1478 tree datum
, basetype
, field
;
1481 if (datum
== error_mark_node
)
1482 return error_mark_node
;
1484 dtype
= TREE_TYPE (datum
);
1485 if (TREE_CODE (dtype
) == REFERENCE_TYPE
)
1486 dtype
= TREE_TYPE (dtype
);
1487 if (! IS_AGGR_TYPE_CODE (TREE_CODE (dtype
)))
1489 cp_error ("request for member `%T::%D' in expression of non-aggregate type `%T'",
1490 basetype
, field
, dtype
);
1491 return error_mark_node
;
1493 else if (IS_SIGNATURE (IDENTIFIER_TYPE_VALUE (basetype
)))
1495 warning ("signature name in scope resolution ignored");
1496 return build_component_ref (datum
, field
, NULL_TREE
, 1);
1498 else if (is_aggr_typedef (basetype
, 1))
1500 tree real_basetype
= IDENTIFIER_TYPE_VALUE (basetype
);
1501 tree binfo
= binfo_or_else (real_basetype
, TREE_TYPE (datum
));
1503 return build_component_ref (build_scoped_ref (datum
, basetype
),
1506 return error_mark_node
;
1509 /* Like `build_component_ref, but uses an already found field.
1510 Must compute access for C_C_D. Otherwise, ok. */
1512 build_component_ref_1 (datum
, field
, protect
)
1516 register tree basetype
= TREE_TYPE (datum
);
1517 register enum tree_code code
= TREE_CODE (basetype
);
1520 if (code
== REFERENCE_TYPE
)
1522 datum
= convert_from_reference (datum
);
1523 basetype
= TREE_TYPE (datum
);
1524 code
= TREE_CODE (basetype
);
1527 if (! IS_AGGR_TYPE_CODE (code
))
1529 if (code
!= ERROR_MARK
)
1530 cp_error ("request for member `%D' in `%E', which is of non-aggregate type `%T'",
1531 field
, datum
, basetype
);
1532 return error_mark_node
;
1535 if (TYPE_SIZE (basetype
) == 0)
1537 incomplete_type_error (0, basetype
);
1538 return error_mark_node
;
1541 /* Look up component name in the structure type definition. */
1543 if (field
== error_mark_node
)
1544 my_friendly_abort (115);
1546 if (TREE_STATIC (field
))
1551 enum access_type access
1552 = compute_access (TYPE_BINFO (current_class_type
), field
);
1554 if (access
== access_private
)
1556 cp_error ("field `%D' is private", field
);
1557 return error_mark_node
;
1559 else if (access
== access_protected
)
1561 cp_error ("field `%D' is protected", field
);
1562 return error_mark_node
;
1566 ref
= build (COMPONENT_REF
, TREE_TYPE (field
), datum
, field
);
1568 if (TREE_READONLY (datum
) || TREE_READONLY (field
))
1569 TREE_READONLY (ref
) = 1;
1570 if (TREE_THIS_VOLATILE (datum
) || TREE_THIS_VOLATILE (field
))
1571 TREE_THIS_VOLATILE (ref
) = 1;
1572 if (DECL_MUTABLE_P (field
))
1573 TREE_READONLY (ref
) = 0;
1578 /* Given a COND_EXPR in T, return it in a form that we can, for
1579 example, use as an lvalue. This code used to be in unary_complex_lvalue,
1580 but we needed it to deal with `a = (d == c) ? b : c' expressions, where
1581 we're dealing with aggregates. So, we now call this in unary_complex_lvalue,
1582 and in build_modify_expr. The case (in particular) that led to this was
1583 with CODE == ADDR_EXPR, since it's not an lvalue when we'd get it there. */
1585 rationalize_conditional_expr (code
, t
)
1586 enum tree_code code
;
1590 build_conditional_expr (TREE_OPERAND (t
, 0),
1591 build_unary_op (code
, TREE_OPERAND (t
, 1), 0),
1592 build_unary_op (code
, TREE_OPERAND (t
, 2), 0));
1596 build_component_ref (datum
, component
, basetype_path
, protect
)
1597 tree datum
, component
, basetype_path
;
1600 register tree basetype
= TREE_TYPE (datum
);
1601 register enum tree_code code
= TREE_CODE (basetype
);
1602 register tree field
= NULL
;
1605 /* If DATUM is a COMPOUND_EXPR or COND_EXPR, move our reference inside it. */
1606 switch (TREE_CODE (datum
))
1610 tree value
= build_component_ref (TREE_OPERAND (datum
, 1), component
,
1611 basetype_path
, protect
);
1612 return build (COMPOUND_EXPR
, TREE_TYPE (value
),
1613 TREE_OPERAND (datum
, 0), value
);
1616 return build_conditional_expr
1617 (TREE_OPERAND (datum
, 0),
1618 build_component_ref (TREE_OPERAND (datum
, 1), component
,
1619 basetype_path
, protect
),
1620 build_component_ref (TREE_OPERAND (datum
, 2), component
,
1621 basetype_path
, protect
));
1624 if (code
== REFERENCE_TYPE
)
1627 /* TREE_REFERENCE_EXPRs are not converted by `convert_from_reference'.
1628 @@ Maybe that is not right. */
1629 if (TREE_REFERENCE_EXPR (datum
))
1630 datum
= build1 (INDIRECT_REF
, TREE_TYPE (basetype
), datum
);
1633 datum
= convert_from_reference (datum
);
1634 basetype
= TREE_TYPE (datum
);
1635 code
= TREE_CODE (basetype
);
1638 /* First, see if there is a field or component with name COMPONENT. */
1639 if (TREE_CODE (component
) == TREE_LIST
)
1641 my_friendly_assert (!(TREE_CHAIN (component
) == NULL_TREE
1642 && DECL_CHAIN (TREE_VALUE (component
)) == NULL_TREE
), 309);
1643 return build (COMPONENT_REF
, TREE_TYPE (component
), datum
, component
);
1646 if (TREE_CODE (component
) == TYPE_EXPR
)
1647 return build_component_type_expr (datum
, component
, NULL_TREE
, protect
);
1650 if (! IS_AGGR_TYPE_CODE (code
))
1652 if (code
!= ERROR_MARK
)
1653 cp_error ("request for member `%D' in `%E', which is of non-aggregate type `%T'",
1654 component
, datum
, basetype
);
1655 return error_mark_node
;
1658 if (TYPE_SIZE (basetype
) == 0)
1660 incomplete_type_error (0, basetype
);
1661 return error_mark_node
;
1664 if (TREE_CODE (component
) == BIT_NOT_EXPR
)
1666 if (TYPE_IDENTIFIER (basetype
) != TREE_OPERAND (component
, 0))
1668 cp_error ("destructor specifier `%T::~%T' must have matching names",
1669 basetype
, TREE_OPERAND (component
, 0));
1670 return error_mark_node
;
1672 if (! TYPE_HAS_DESTRUCTOR (basetype
))
1674 cp_error ("type `%T' has no destructor", basetype
);
1675 return error_mark_node
;
1677 return TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (basetype
), 0);
1680 /* Look up component name in the structure type definition. */
1681 if (CLASSTYPE_VFIELD (basetype
)
1682 && DECL_NAME (CLASSTYPE_VFIELD (basetype
)) == component
)
1683 /* Special-case this because if we use normal lookups in an ambiguous
1684 hierarchy, the compiler will abort (because vptr lookups are
1685 not supposed to be ambiguous. */
1686 field
= CLASSTYPE_VFIELD (basetype
);
1689 if (basetype_path
== NULL_TREE
)
1690 basetype_path
= TYPE_BINFO (basetype
);
1691 field
= lookup_field (basetype_path
, component
,
1692 protect
&& ! VFIELD_NAME_P (component
), 0);
1693 if (field
== error_mark_node
)
1694 return error_mark_node
;
1696 if (field
== NULL_TREE
)
1698 /* Not found as a data field, look for it as a method. If found,
1699 then if this is the only possible one, return it, else
1700 report ambiguity error. */
1701 tree fndecls
= lookup_fnfields (basetype_path
, component
, 1);
1702 if (fndecls
== error_mark_node
)
1703 return error_mark_node
;
1706 if (TREE_CHAIN (fndecls
) == NULL_TREE
1707 && DECL_CHAIN (TREE_VALUE (fndecls
)) == NULL_TREE
)
1709 enum access_type access
;
1712 /* Unique, so use this one now. */
1713 basetype
= TREE_PURPOSE (fndecls
);
1714 fndecl
= TREE_VALUE (fndecls
);
1715 access
= compute_access (TREE_PURPOSE (fndecls
), fndecl
);
1716 if (access
== access_public
)
1718 if (DECL_VINDEX (fndecl
)
1719 && ! resolves_to_fixed_type_p (datum
, 0))
1721 tree addr
= build_unary_op (ADDR_EXPR
, datum
, 0);
1722 addr
= convert_pointer_to (DECL_CONTEXT (fndecl
), addr
);
1723 datum
= build_indirect_ref (addr
, NULL_PTR
);
1724 my_friendly_assert (datum
!= error_mark_node
, 310);
1725 fndecl
= build_vfn_ref (&addr
, datum
, DECL_VINDEX (fndecl
));
1727 assemble_external (fndecl
);
1730 if (access
== access_protected
)
1731 cp_error ("member function `%D' is protected", fndecl
);
1733 cp_error ("member function `%D' is private", fndecl
);
1734 return error_mark_node
;
1738 /* Just act like build_offset_ref, since the object does
1739 not matter unless we're actually calling the function. */
1742 for (t
= TREE_VALUE (fndecls
); t
; t
= DECL_CHAIN (t
))
1743 assemble_external (t
);
1745 t
= build_tree_list (error_mark_node
, fndecls
);
1746 TREE_TYPE (t
) = build_offset_type (basetype
,
1753 if (component
== ansi_opname
[(int) TYPE_EXPR
])
1754 cp_error ("`%#T' has no such type conversion operator", basetype
);
1757 cp_error ("`%#T' has no member named `%D'", basetype
, component
);
1758 return error_mark_node
;
1760 else if (TREE_TYPE (field
) == error_mark_node
)
1761 return error_mark_node
;
1763 if (TREE_CODE (field
) != FIELD_DECL
)
1765 if (TREE_CODE (field
) == TYPE_DECL
)
1767 cp_error ("invalid use of type decl `%#D' as expression", field
);
1768 return error_mark_node
;
1770 if (DECL_RTL (field
) != 0)
1771 assemble_external (field
);
1772 TREE_USED (field
) = 1;
1777 if (DECL_FIELD_CONTEXT (field
) != basetype
1778 && TYPE_USES_COMPLEX_INHERITANCE (basetype
))
1780 tree addr
= build_unary_op (ADDR_EXPR
, datum
, 0);
1781 if (integer_zerop (addr
))
1783 error ("invalid reference to NULL ptr, use ptr-to-member instead");
1784 return error_mark_node
;
1786 addr
= convert_pointer_to (DECL_FIELD_CONTEXT (field
), addr
);
1787 datum
= build_indirect_ref (addr
, NULL_PTR
);
1788 my_friendly_assert (datum
!= error_mark_node
, 311);
1790 ref
= fold (build (COMPONENT_REF
, TREE_TYPE (field
),
1791 break_out_cleanups (datum
), field
));
1793 if (TREE_READONLY (datum
) || TREE_READONLY (field
))
1794 TREE_READONLY (ref
) = 1;
1795 if (TREE_THIS_VOLATILE (datum
) || TREE_THIS_VOLATILE (field
))
1796 TREE_THIS_VOLATILE (ref
) = 1;
1797 if (DECL_MUTABLE_P (field
))
1798 TREE_READONLY (ref
) = 0;
1803 /* Given an expression PTR for a pointer, return an expression
1804 for the value pointed to.
1805 ERRORSTRING is the name of the operator to appear in error messages.
1807 This function may need to overload OPERATOR_FNNAME.
1808 Must also handle REFERENCE_TYPEs for C++. */
1811 build_x_indirect_ref (ptr
, errorstring
)
1815 tree rval
= build_opfncall (INDIRECT_REF
, LOOKUP_NORMAL
, ptr
, NULL_TREE
, NULL_TREE
);
1818 return build_indirect_ref (ptr
, errorstring
);
1822 build_indirect_ref (ptr
, errorstring
)
1826 register tree pointer
= (TREE_CODE (TREE_TYPE (ptr
)) == REFERENCE_TYPE
?
1827 ptr
: default_conversion (ptr
));
1828 register tree type
= TREE_TYPE (pointer
);
1830 if (ptr
== current_class_decl
)
1833 ptr
= build_expr_type_conversion (WANT_POINTER
, pointer
, 1);
1837 type
= TREE_TYPE (pointer
);
1840 if (TREE_CODE (type
) == POINTER_TYPE
|| TREE_CODE (type
) == REFERENCE_TYPE
)
1842 if (TREE_CODE (pointer
) == ADDR_EXPR
1843 && (TREE_TYPE (TREE_OPERAND (pointer
, 0))
1844 == TREE_TYPE (type
)))
1845 return TREE_OPERAND (pointer
, 0);
1848 tree t
= TREE_TYPE (type
);
1849 register tree ref
= build1 (INDIRECT_REF
,
1850 TYPE_MAIN_VARIANT (t
), pointer
);
1852 TREE_READONLY (ref
) = TYPE_READONLY (t
);
1853 TREE_THIS_VOLATILE (ref
) = TYPE_VOLATILE (t
);
1854 TREE_SIDE_EFFECTS (ref
)
1855 = TYPE_VOLATILE (t
) || TREE_SIDE_EFFECTS (pointer
);
1859 /* `pointer' won't be an error_mark_node if we were given a
1860 pointer to member, so it's cool to check for this here. */
1861 else if (TYPE_PTRMEMFUNC_P (type
))
1862 error ("invalid use of `%s' on pointer to member function", errorstring
);
1863 else if (TREE_CODE (type
) == RECORD_TYPE
1864 && (IS_SIGNATURE_POINTER (type
) || IS_SIGNATURE_REFERENCE (type
)))
1865 error ("cannot dereference signature pointer/reference");
1866 else if (pointer
!= error_mark_node
)
1869 error ("invalid type argument of `%s'", errorstring
);
1871 error ("invalid type argument");
1873 return error_mark_node
;
1876 /* This handles expressions of the form "a[i]", which denotes
1879 This is logically equivalent in C to *(a+i), but we may do it differently.
1880 If A is a variable or a member, we generate a primitive ARRAY_REF.
1881 This avoids forcing the array out of registers, and can work on
1882 arrays that are not lvalues (for example, members of structures returned
1885 If INDEX is of some user-defined type, it must be converted to
1886 integer type. Otherwise, to make a compatible PLUS_EXPR, it
1887 will inherit the type of the array, which will be some pointer type. */
1890 build_x_array_ref (array
, index
)
1893 tree rval
= build_opfncall (ARRAY_REF
, LOOKUP_NORMAL
, array
, index
, NULL_TREE
);
1896 return build_array_ref (array
, index
);
1900 build_array_ref (array
, idx
)
1907 error ("subscript missing in array reference");
1908 return error_mark_node
;
1911 if (TREE_TYPE (array
) == error_mark_node
1912 || TREE_TYPE (idx
) == error_mark_node
)
1913 return error_mark_node
;
1915 itype
= TREE_TYPE (idx
);
1917 if (TREE_CODE (TREE_TYPE (array
)) == ARRAY_TYPE
1918 && TREE_CODE (array
) != INDIRECT_REF
)
1922 /* Subscripting with type char is likely to lose
1923 on a machine where chars are signed.
1924 So warn on any machine, but optionally.
1925 Don't warn for unsigned char since that type is safe.
1926 Don't warn for signed char because anyone who uses that
1927 must have done so deliberately. */
1928 if (warn_char_subscripts
1929 && TYPE_MAIN_VARIANT (TREE_TYPE (idx
)) == char_type_node
)
1930 warning ("array subscript has type `char'");
1932 /* Apply default promotions *after* noticing character types. */
1933 idx
= default_conversion (idx
);
1935 if (TREE_CODE (TREE_TYPE (idx
)) != INTEGER_TYPE
)
1937 error ("array subscript is not an integer");
1938 return error_mark_node
;
1941 /* An array that is indexed by a non-constant
1942 cannot be stored in a register; we must be able to do
1943 address arithmetic on its address.
1944 Likewise an array of elements of variable size. */
1945 if (TREE_CODE (idx
) != INTEGER_CST
1946 || (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array
))) != 0
1947 && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array
)))) != INTEGER_CST
))
1949 if (mark_addressable (array
) == 0)
1950 return error_mark_node
;
1952 /* An array that is indexed by a constant value which is not within
1953 the array bounds cannot be stored in a register either; because we
1954 would get a crash in store_bit_field/extract_bit_field when trying
1955 to access a non-existent part of the register. */
1956 if (TREE_CODE (idx
) == INTEGER_CST
1957 && TYPE_VALUES (TREE_TYPE (array
))
1958 && ! int_fits_type_p (idx
, TYPE_VALUES (TREE_TYPE (array
))))
1960 if (mark_addressable (array
) == 0)
1961 return error_mark_node
;
1964 if (pedantic
&& !lvalue_p (array
))
1965 pedwarn ("ANSI C++ forbids subscripting non-lvalue array");
1967 /* Note in C++ it is valid to subscript a `register' array, since
1968 it is valid to take the address of something with that
1969 storage specification. */
1973 while (TREE_CODE (foo
) == COMPONENT_REF
)
1974 foo
= TREE_OPERAND (foo
, 0);
1975 if (TREE_CODE (foo
) == VAR_DECL
&& DECL_REGISTER (foo
))
1976 warning ("subscripting array declared `register'");
1979 type
= TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (array
)));
1980 rval
= build (ARRAY_REF
, type
, array
, idx
);
1981 /* Array ref is const/volatile if the array elements are
1982 or if the array is.. */
1983 TREE_READONLY (rval
)
1984 |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array
)))
1985 | TREE_READONLY (array
));
1986 TREE_SIDE_EFFECTS (rval
)
1987 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array
)))
1988 | TREE_SIDE_EFFECTS (array
));
1989 TREE_THIS_VOLATILE (rval
)
1990 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array
)))
1991 /* This was added by rms on 16 Nov 91.
1992 It fixes vol struct foo *a; a->elts[1]
1993 in an inline function.
1994 Hope it doesn't break something else. */
1995 | TREE_THIS_VOLATILE (array
));
1996 return require_complete_type (fold (rval
));
2000 tree ar
= default_conversion (array
);
2001 tree ind
= default_conversion (idx
);
2003 /* Put the integer in IND to simplify error checking. */
2004 if (TREE_CODE (TREE_TYPE (ar
)) == INTEGER_TYPE
)
2011 if (ar
== error_mark_node
)
2014 if (TREE_CODE (TREE_TYPE (ar
)) != POINTER_TYPE
)
2016 error ("subscripted value is neither array nor pointer");
2017 return error_mark_node
;
2019 if (TREE_CODE (TREE_TYPE (ind
)) != INTEGER_TYPE
)
2021 error ("array subscript is not an integer");
2022 return error_mark_node
;
2025 return build_indirect_ref (build_binary_op_nodefault (PLUS_EXPR
, ar
, ind
, PLUS_EXPR
),
2030 /* Build a function call to function FUNCTION with parameters PARAMS.
2031 PARAMS is a list--a chain of TREE_LIST nodes--in which the
2032 TREE_VALUE of each node is a parameter-expression.
2033 FUNCTION's data type may be a function type or a pointer-to-function.
2035 For C++: If FUNCTION's data type is a TREE_LIST, then the tree list
2036 is the list of possible methods that FUNCTION could conceivably
2037 be. If the list of methods comes from a class, then it will be
2038 a list of lists (where each element is associated with the class
2039 that produced it), otherwise it will be a simple list (for
2040 functions overloaded in global scope).
2042 In the first case, TREE_VALUE (function) is the head of one of those
2043 lists, and TREE_PURPOSE is the name of the function.
2045 In the second case, TREE_PURPOSE (function) is the function's
2048 DECL is the class instance variable, usually CURRENT_CLASS_DECL. */
2051 * [eichin:19911015.1726EST] actually return a possibly incomplete
2055 build_x_function_call (function
, params
, decl
)
2056 tree function
, params
, decl
;
2061 if (function
== error_mark_node
)
2062 return error_mark_node
;
2064 type
= TREE_TYPE (function
);
2065 is_method
= ((TREE_CODE (function
) == TREE_LIST
2066 && current_class_type
!= NULL_TREE
2067 && IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (function
)) == function
)
2068 || TREE_CODE (function
) == IDENTIFIER_NODE
2069 || TREE_CODE (type
) == METHOD_TYPE
2070 || TYPE_PTRMEMFUNC_P (type
));
2072 /* Handle methods, friends, and overloaded functions, respectively. */
2075 if (TREE_CODE (function
) == FUNCTION_DECL
)
2077 if (DECL_NAME (function
))
2078 function
= DECL_NAME (function
);
2080 function
= TYPE_IDENTIFIER (DECL_CLASS_CONTEXT (function
));
2082 else if (TREE_CODE (function
) == TREE_LIST
)
2085 if (TREE_CODE (TREE_VALUE (function
)) == TREE_LIST
)
2086 function
= TREE_PURPOSE (TREE_VALUE (function
));
2088 function
= TREE_PURPOSE (function
);
2090 my_friendly_assert (TREE_CODE (TREE_VALUE (function
)) == FUNCTION_DECL
, 312);
2091 function
= TREE_PURPOSE (function
);
2094 else if (TREE_CODE (function
) != IDENTIFIER_NODE
)
2096 if (TREE_CODE (function
) == OFFSET_REF
)
2098 if (TREE_OPERAND (function
, 0))
2099 decl
= TREE_OPERAND (function
, 0);
2101 /* Call via a pointer to member function. */
2102 if (decl
== NULL_TREE
)
2104 error ("pointer to member function called, but not in class scope");
2105 return error_mark_node
;
2107 /* What other type of POINTER_TYPE could this be? */
2108 if (TREE_CODE (TREE_TYPE (function
)) != POINTER_TYPE
2109 && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (function
))
2110 && TREE_CODE (function
) != OFFSET_REF
)
2111 function
= build (OFFSET_REF
, TREE_TYPE (type
), NULL_TREE
, function
);
2115 /* this is an abbreviated method call.
2116 must go through here in case it is a virtual function.
2117 @@ Perhaps this could be optimized. */
2119 if (decl
== NULL_TREE
)
2121 if (current_class_type
== NULL_TREE
)
2123 error ("object missing in call to method `%s'",
2124 IDENTIFIER_POINTER (function
));
2125 return error_mark_node
;
2127 /* Yow: call from a static member function. */
2128 decl
= build1 (NOP_EXPR
, TYPE_POINTER_TO (current_class_type
),
2130 decl
= build_indirect_ref (decl
, NULL_PTR
);
2133 return build_method_call (decl
, function
, params
,
2134 NULL_TREE
, LOOKUP_NORMAL
);
2136 else if (TREE_CODE (function
) == COMPONENT_REF
2137 && type
== unknown_type_node
)
2139 /* Should we undo what was done in build_component_ref? */
2140 if (TREE_CODE (TREE_PURPOSE (TREE_OPERAND (function
, 1))) == TREE_VEC
)
2141 /* Get the name that build_component_ref hid. */
2142 function
= DECL_NAME (TREE_VALUE (TREE_OPERAND (function
, 1)));
2144 function
= TREE_PURPOSE (TREE_OPERAND (function
, 1));
2145 return build_method_call (decl
, function
, params
,
2146 NULL_TREE
, LOOKUP_NORMAL
);
2148 else if (TREE_CODE (function
) == TREE_LIST
)
2150 if (TREE_VALUE (function
) == NULL_TREE
)
2152 cp_error ("function `%D' declared overloaded, but no definitions appear with which to resolve it?!?",
2153 TREE_PURPOSE (function
));
2154 return error_mark_node
;
2158 tree val
= TREE_VALUE (function
);
2160 if (TREE_CODE (val
) == TEMPLATE_DECL
)
2161 return build_overload_call_maybe
2162 (function
, params
, LOOKUP_COMPLAIN
, (struct candidate
*)0);
2163 else if (DECL_CHAIN (val
) != NULL_TREE
)
2164 return build_overload_call
2165 (function
, params
, LOOKUP_COMPLAIN
, (struct candidate
*)0);
2167 my_friendly_abort (360);
2172 if (TREE_CODE (function
) == OFFSET_REF
)
2174 /* If the component is a data element (or a virtual function), we play
2175 games here to make things work. */
2178 if (TREE_OPERAND (function
, 0))
2179 decl
= TREE_OPERAND (function
, 0);
2183 decl_addr
= build_unary_op (ADDR_EXPR
, decl
, 0);
2184 function
= get_member_function_from_ptrfunc (&decl_addr
,
2185 TREE_OPERAND (function
, 1));
2186 params
= tree_cons (NULL_TREE
, decl_addr
, params
);
2187 return build_function_call (function
, params
);
2190 type
= TREE_TYPE (function
);
2191 if (type
!= error_mark_node
)
2193 if (TREE_CODE (type
) == REFERENCE_TYPE
)
2194 type
= TREE_TYPE (type
);
2196 if (TYPE_LANG_SPECIFIC (type
) && TYPE_OVERLOADS_CALL_EXPR (type
))
2197 return build_opfncall (CALL_EXPR
, LOOKUP_NORMAL
, function
, params
, NULL_TREE
);
2202 tree fntype
= TREE_TYPE (function
);
2205 /* Explicitly named method? */
2206 if (TREE_CODE (function
) == FUNCTION_DECL
)
2207 ctypeptr
= TYPE_POINTER_TO (DECL_CLASS_CONTEXT (function
));
2208 /* Expression with ptr-to-method type? It could either be a plain
2209 usage, or it might be a case where the ptr-to-method is being
2210 passed in as an argument. */
2211 else if (TYPE_PTRMEMFUNC_P (fntype
))
2213 tree rec
= TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (fntype
)));
2214 ctypeptr
= TYPE_POINTER_TO (rec
);
2216 /* Unexpected node type? */
2218 my_friendly_abort (116);
2219 if (decl
== NULL_TREE
)
2221 if (current_function_decl
2222 && DECL_STATIC_FUNCTION_P (current_function_decl
))
2223 error ("invalid call to member function needing `this' in static member function scope");
2225 error ("pointer to member function called, but not in class scope");
2226 return error_mark_node
;
2228 if (TREE_CODE (TREE_TYPE (decl
)) != POINTER_TYPE
2229 && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (decl
)))
2231 decl
= build_unary_op (ADDR_EXPR
, decl
, 0);
2232 decl
= convert_pointer_to (TREE_TYPE (ctypeptr
), decl
);
2235 decl
= build_c_cast (ctypeptr
, decl
, 0);
2236 params
= tree_cons (NULL_TREE
, decl
, params
);
2239 return build_function_call (function
, params
);
2242 /* Resolve a pointer to member function. INSTANCE is the object
2243 instance to use, if the member points to a virtual member. */
2246 get_member_function_from_ptrfunc (instance_ptrptr
, function
)
2247 tree
*instance_ptrptr
;
2250 if (TREE_CODE (function
) == OFFSET_REF
)
2252 function
= TREE_OPERAND (function
, 1);
2255 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (function
)))
2257 tree fntype
= TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (function
));
2258 tree index
= save_expr (build_component_ref (function
,
2261 tree e1
= build (GT_EXPR
, boolean_type_node
, index
,
2262 convert (delta_type_node
, integer_zero_node
));
2263 tree delta
= convert (ptrdiff_type_node
,
2264 build_component_ref (function
, delta_identifier
, 0, 0));
2265 tree delta2
= DELTA2_FROM_PTRMEMFUNC (function
);
2271 tree instance_ptr
= *instance_ptrptr
;
2273 if (TREE_SIDE_EFFECTS (instance_ptr
))
2274 instance_ptr
= save_expr (instance_ptr
);
2276 /* convert down to the right base, before using the instance. */
2278 = convert_pointer_to_real (TYPE_METHOD_BASETYPE (TREE_TYPE (fntype
)),
2280 if (instance
== error_mark_node
)
2283 vtbl
= convert_pointer_to (ptr_type_node
, instance
);
2286 build_pointer_type (build_pointer_type (vtable_entry_type
)),
2287 vtbl
, convert (ptrdiff_type_node
, delta2
));
2288 vtbl
= build_indirect_ref (vtbl
, NULL_PTR
);
2289 aref
= build_array_ref (vtbl
, build_binary_op (MINUS_EXPR
,
2291 integer_one_node
, 1));
2292 if (! flag_vtable_thunks
)
2294 aref
= save_expr (aref
);
2296 /* Save the intermediate result in a SAVE_EXPR so we don't have to
2297 compute each component of the virtual function pointer twice. */
2298 if (/* !building_cleanup && */ TREE_CODE (aref
) == INDIRECT_REF
)
2299 TREE_OPERAND (aref
, 0) = save_expr (TREE_OPERAND (aref
, 0));
2301 delta
= build_binary_op (PLUS_EXPR
,
2302 build_conditional_expr (e1
, build_component_ref (aref
, delta_identifier
, 0, 0), integer_zero_node
),
2306 *instance_ptrptr
= build (PLUS_EXPR
, TREE_TYPE (instance_ptr
),
2307 instance_ptr
, delta
);
2308 if (flag_vtable_thunks
)
2311 e2
= build_component_ref (aref
, pfn_identifier
, 0, 0);
2313 e3
= PFN_FROM_PTRMEMFUNC (function
);
2314 TREE_TYPE (e2
) = TREE_TYPE (e3
);
2315 function
= build_conditional_expr (e1
, e2
, e3
);
2317 /* Make sure this doesn't get evaluated first inside one of the
2318 branches of the COND_EXPR. */
2319 if (TREE_CODE (instance_ptr
) == SAVE_EXPR
)
2320 function
= build (COMPOUND_EXPR
, TREE_TYPE (function
),
2321 instance_ptr
, function
);
2327 build_function_call_real (function
, params
, require_complete
, flags
)
2328 tree function
, params
;
2329 int require_complete
, flags
;
2331 register tree fntype
, fndecl
;
2332 register tree value_type
;
2333 register tree coerced_params
;
2334 tree name
= NULL_TREE
, assembler_name
= NULL_TREE
;
2337 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
2338 Strip such NOP_EXPRs, since FUNCTION is used in non-lvalue context. */
2339 if (TREE_CODE (function
) == NOP_EXPR
2340 && TREE_TYPE (function
) == TREE_TYPE (TREE_OPERAND (function
, 0)))
2341 function
= TREE_OPERAND (function
, 0);
2343 if (TREE_CODE (function
) == FUNCTION_DECL
)
2345 name
= DECL_NAME (function
);
2346 assembler_name
= DECL_ASSEMBLER_NAME (function
);
2348 GNU_xref_call (current_function_decl
,
2349 IDENTIFIER_POINTER (name
? name
2350 : TYPE_IDENTIFIER (DECL_CLASS_CONTEXT (function
))));
2351 assemble_external (function
);
2354 /* Convert anything with function type to a pointer-to-function. */
2357 && IDENTIFIER_LENGTH (name
) == 4
2358 && ! strcmp (IDENTIFIER_POINTER (name
), "main")
2359 && DECL_CONTEXT (function
) == NULL_TREE
)
2361 pedwarn ("ANSI C++ forbids calling `main' from within program");
2364 if (pedantic
&& DECL_THIS_INLINE (function
) && ! DECL_INITIAL (function
)
2365 && ! DECL_ARTIFICIAL (function
)
2366 && ! DECL_PENDING_INLINE_INFO (function
))
2367 cp_pedwarn ("inline function `%#D' called before definition",
2370 /* Differs from default_conversion by not setting TREE_ADDRESSABLE
2371 (because calling an inline function does not mean the function
2372 needs to be separately compiled). */
2374 if (DECL_INLINE (function
))
2376 fntype
= build_type_variant (TREE_TYPE (function
),
2377 TREE_READONLY (function
),
2378 TREE_THIS_VOLATILE (function
));
2379 function
= build1 (ADDR_EXPR
, build_pointer_type (fntype
), function
);
2383 assemble_external (function
);
2384 TREE_USED (function
) = 1;
2385 function
= default_conversion (function
);
2392 /* Convert anything with function type to a pointer-to-function. */
2393 if (function
== error_mark_node
)
2394 return error_mark_node
;
2395 function
= default_conversion (function
);
2398 fntype
= TREE_TYPE (function
);
2400 if (TYPE_PTRMEMFUNC_P (fntype
))
2402 tree instance_ptr
= build_unary_op (ADDR_EXPR
, C_C_D
, 0);
2403 fntype
= TYPE_PTRMEMFUNC_FN_TYPE (fntype
);
2404 function
= get_member_function_from_ptrfunc (&instance_ptr
, function
);
2407 is_method
= (TREE_CODE (fntype
) == POINTER_TYPE
2408 && TREE_CODE (TREE_TYPE (fntype
)) == METHOD_TYPE
);
2410 if (!((TREE_CODE (fntype
) == POINTER_TYPE
2411 && TREE_CODE (TREE_TYPE (fntype
)) == FUNCTION_TYPE
)
2414 cp_error ("`%E' cannot be used as a function", function
);
2415 return error_mark_node
;
2418 /* fntype now gets the type of function pointed to. */
2419 fntype
= TREE_TYPE (fntype
);
2421 /* Convert the parameters to the types declared in the
2422 function prototype, or apply default promotions. */
2424 if (flags
& LOOKUP_COMPLAIN
)
2425 coerced_params
= convert_arguments (NULL_TREE
, TYPE_ARG_TYPES (fntype
),
2426 params
, fndecl
, LOOKUP_NORMAL
);
2428 coerced_params
= convert_arguments (NULL_TREE
, TYPE_ARG_TYPES (fntype
),
2431 if (coerced_params
== error_mark_node
)
2432 return error_mark_node
;
2434 /* Check for errors in format strings. */
2436 if (warn_format
&& (name
|| assembler_name
))
2437 check_function_format (name
, assembler_name
, coerced_params
);
2439 /* Recognize certain built-in functions so we can make tree-codes
2440 other than CALL_EXPR. We do this when it enables fold-const.c
2441 to do something useful. */
2443 if (TREE_CODE (function
) == ADDR_EXPR
2444 && TREE_CODE (TREE_OPERAND (function
, 0)) == FUNCTION_DECL
2445 && DECL_BUILT_IN (TREE_OPERAND (function
, 0)))
2446 switch (DECL_FUNCTION_CODE (TREE_OPERAND (function
, 0)))
2451 if (coerced_params
== 0)
2452 return integer_zero_node
;
2453 return build_unary_op (ABS_EXPR
, TREE_VALUE (coerced_params
), 0);
2457 value_type
= TREE_TYPE (fntype
) ? TREE_TYPE (fntype
) : void_type_node
;
2459 register tree result
=
2460 build (CALL_EXPR
, value_type
,
2461 function
, coerced_params
, NULL_TREE
);
2463 TREE_SIDE_EFFECTS (result
) = 1;
2465 if (! require_complete
)
2466 return convert_from_reference (result
);
2467 if (value_type
== void_type_node
)
2469 result
= require_complete_type (result
);
2470 return convert_from_reference (result
);
2475 build_function_call (function
, params
)
2476 tree function
, params
;
2478 return build_function_call_real (function
, params
, 1, LOOKUP_NORMAL
);
2482 build_function_call_maybe (function
, params
)
2483 tree function
, params
;
2485 return build_function_call_real (function
, params
, 0, 0);
2489 /* Convert the actual parameter expressions in the list VALUES
2490 to the types in the list TYPELIST.
2491 If parmdecls is exhausted, or when an element has NULL as its type,
2492 perform the default conversions.
2494 RETURN_LOC is the location of the return value, if known, NULL_TREE
2495 otherwise. This is useful in the case where we can avoid creating
2496 a temporary variable in the case where we can initialize the return
2497 value directly. If we are not eliding constructors, then we set this
2498 to NULL_TREE to avoid this avoidance.
2500 NAME is an IDENTIFIER_NODE or 0. It is used only for error messages.
2502 This is also where warnings about wrong number of args are generated.
2504 Return a list of expressions for the parameters as converted.
2506 Both VALUES and the returned value are chains of TREE_LIST nodes
2507 with the elements of the list in the TREE_VALUE slots of those nodes.
2509 In C++, unspecified trailing parameters can be filled in with their
2510 default arguments, if such were specified. Do so here. */
2513 convert_arguments (return_loc
, typelist
, values
, fndecl
, flags
)
2514 tree return_loc
, typelist
, values
, fndecl
;
2517 extern tree gc_protect_fndecl
;
2518 register tree typetail
, valtail
;
2519 register tree result
= NULL_TREE
;
2523 if (! flag_elide_constructors
)
2528 if (TREE_CODE (TREE_TYPE (fndecl
)) == METHOD_TYPE
)
2530 if (DECL_NAME (fndecl
) == NULL_TREE
2531 || IDENTIFIER_HAS_TYPE_VALUE (DECL_NAME (fndecl
)))
2532 called_thing
= "constructor";
2534 called_thing
= "member function";
2537 called_thing
= "function";
2540 for (valtail
= values
, typetail
= typelist
;
2542 valtail
= TREE_CHAIN (valtail
), i
++)
2544 register tree type
= typetail
? TREE_VALUE (typetail
) : 0;
2545 register tree val
= TREE_VALUE (valtail
);
2547 if (val
== error_mark_node
)
2548 return error_mark_node
;
2550 if (type
== void_type_node
)
2554 char *buf
= (char *)alloca (40 + strlen (called_thing
));
2555 sprintf (buf
, "too many arguments to %s `%%s'", called_thing
);
2556 error_with_decl (fndecl
, buf
);
2557 error ("at this point in file");
2560 error ("too many arguments to function");
2561 /* In case anybody wants to know if this argument
2564 TREE_TYPE (tree_last (result
)) = error_mark_node
;
2568 /* The tree type of the parameter being passed may not yet be
2569 known. In this case, its type is TYPE_UNKNOWN, and will
2570 be instantiated by the type given by TYPE. If TYPE
2571 is also NULL, the tree type of VAL is ERROR_MARK_NODE. */
2572 if (type
&& type_unknown_p (val
))
2573 val
= require_instantiated_type (type
, val
, integer_zero_node
);
2574 else if (type_unknown_p (val
))
2576 /* Strip the `&' from an overloaded FUNCTION_DECL. */
2577 if (TREE_CODE (val
) == ADDR_EXPR
)
2578 val
= TREE_OPERAND (val
, 0);
2579 if (TREE_CODE (val
) == TREE_LIST
2580 && TREE_CHAIN (val
) == NULL_TREE
2581 && TREE_TYPE (TREE_VALUE (val
)) != NULL_TREE
2582 && (TREE_TYPE (val
) == unknown_type_node
2583 || DECL_CHAIN (TREE_VALUE (val
)) == NULL_TREE
))
2584 /* Instantiates automatically. */
2585 val
= TREE_VALUE (val
);
2588 error ("insufficient type information in parameter list");
2589 val
= integer_zero_node
;
2592 else if (TREE_CODE (val
) == OFFSET_REF
2593 && TREE_CODE (TREE_TYPE (val
)) == METHOD_TYPE
)
2595 /* This is unclean. Should be handled elsewhere. */
2596 val
= build_unary_op (ADDR_EXPR
, val
, 0);
2598 else if (TREE_CODE (val
) == OFFSET_REF
)
2599 val
= resolve_offset_ref (val
);
2603 /* This code forces the assumption that if we have a ptr-to-func
2604 type in an arglist, that every routine that wants to check
2605 its validity has done so, and thus we need not do any
2606 more conversion. I don't remember why this is necessary. */
2607 else if (TREE_CODE (ttype
) == FUNCTION_TYPE
2609 || TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
2610 || TREE_CODE (TREE_TYPE (type
)) == VOID_TYPE
))
2612 type
= build_pointer_type (ttype
);
2617 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
2618 Strip such NOP_EXPRs, since VAL is used in non-lvalue context. */
2619 if (TREE_CODE (val
) == NOP_EXPR
2620 && TREE_TYPE (val
) == TREE_TYPE (TREE_OPERAND (val
, 0))
2621 && (type
== 0 || TREE_CODE (type
) != REFERENCE_TYPE
))
2622 val
= TREE_OPERAND (val
, 0);
2624 if (type
== 0 || TREE_CODE (type
) != REFERENCE_TYPE
)
2626 if (TREE_CODE (TREE_TYPE (val
)) == ARRAY_TYPE
2627 || TREE_CODE (TREE_TYPE (val
)) == FUNCTION_TYPE
2628 || TREE_CODE (TREE_TYPE (val
)) == METHOD_TYPE
)
2629 val
= default_conversion (val
);
2631 val
= require_complete_type (val
);
2634 if (val
== error_mark_node
)
2635 return error_mark_node
;
2639 /* Formal parm type is specified by a function prototype. */
2642 if (TYPE_SIZE (type
) == 0)
2644 error ("parameter type of called function is incomplete");
2649 #if 0 && defined (PROMOTE_PROTOTYPES)
2650 /* This breaks user-defined conversions. */
2651 /* Rather than truncating and then reextending,
2652 convert directly to int, if that's the type we will want. */
2653 if (! flag_traditional
2654 && (TREE_CODE (type
) == INTEGER_TYPE
2655 || TREE_CODE (type
) == ENUMERAL_TYPE
)
2656 && (TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
)))
2657 type
= integer_type_node
;
2659 parmval
= convert_for_initialization (return_loc
, type
, val
, flags
,
2660 "argument passing", fndecl
, i
);
2661 #ifdef PROMOTE_PROTOTYPES
2662 if ((TREE_CODE (type
) == INTEGER_TYPE
2663 || TREE_CODE (type
) == ENUMERAL_TYPE
)
2664 && (TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
)))
2665 parmval
= default_conversion (parmval
);
2668 result
= tree_cons (NULL_TREE
, parmval
, result
);
2672 if (TREE_CODE (TREE_TYPE (val
)) == REFERENCE_TYPE
)
2673 val
= convert_from_reference (val
);
2675 if (TREE_CODE (TREE_TYPE (val
)) == REAL_TYPE
2676 && (TYPE_PRECISION (TREE_TYPE (val
))
2677 < TYPE_PRECISION (double_type_node
)))
2678 /* Convert `float' to `double'. */
2679 result
= tree_cons (NULL_TREE
, convert (double_type_node
, val
), result
);
2680 else if (TYPE_LANG_SPECIFIC (TREE_TYPE (val
))
2681 && ! TYPE_HAS_TRIVIAL_INIT_REF (TREE_TYPE (val
)))
2683 cp_warning ("cannot pass objects of type `%T' through `...'",
2685 result
= tree_cons (NULL_TREE
, val
, result
);
2688 /* Convert `short' and `char' to full-size `int'. */
2689 result
= tree_cons (NULL_TREE
, default_conversion (val
), result
);
2693 /* There are certain functions for which we don't need
2694 to protect our arguments. GC_PROTECT_FNDECL is one. */
2695 && fndecl
!= gc_protect_fndecl
2696 && type_needs_gc_entry (TREE_TYPE (TREE_VALUE (result
)))
2697 && ! value_safe_from_gc (NULL_TREE
, TREE_VALUE (result
)))
2698 /* This will build a temporary variable whose cleanup is
2699 to clear the obstack entry. */
2700 TREE_VALUE (result
) = protect_value_from_gc (NULL_TREE
,
2701 TREE_VALUE (result
));
2704 typetail
= TREE_CHAIN (typetail
);
2707 if (typetail
!= 0 && typetail
!= void_list_node
)
2709 /* See if there are default arguments that can be used */
2710 if (TREE_PURPOSE (typetail
))
2712 for (; typetail
!= void_list_node
; ++i
)
2714 tree type
= TREE_VALUE (typetail
);
2715 tree val
= TREE_PURPOSE (typetail
);
2718 if (val
== NULL_TREE
)
2719 parmval
= error_mark_node
;
2720 else if (TREE_CODE (val
) == CONSTRUCTOR
)
2722 parmval
= digest_init (type
, val
, (tree
*)0);
2723 parmval
= convert_for_initialization (return_loc
, type
, parmval
, flags
,
2724 "default constructor", fndecl
, i
);
2728 /* This could get clobbered by the following call. */
2729 if (TREE_HAS_CONSTRUCTOR (val
))
2730 val
= copy_node (val
);
2732 parmval
= convert_for_initialization (return_loc
, type
, val
, flags
,
2733 "default argument", fndecl
, i
);
2734 #ifdef PROMOTE_PROTOTYPES
2735 if ((TREE_CODE (type
) == INTEGER_TYPE
2736 || TREE_CODE (type
) == ENUMERAL_TYPE
)
2737 && (TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
)))
2738 parmval
= default_conversion (parmval
);
2743 && type_needs_gc_entry (TREE_TYPE (parmval
))
2744 && ! value_safe_from_gc (NULL_TREE
, parmval
))
2745 parmval
= protect_value_from_gc (NULL_TREE
, parmval
);
2747 result
= tree_cons (0, parmval
, result
);
2748 typetail
= TREE_CHAIN (typetail
);
2749 /* ends with `...'. */
2750 if (typetail
== NULL_TREE
)
2758 char *buf
= (char *)alloca (32 + strlen (called_thing
));
2759 sprintf (buf
, "too few arguments to %s `%%#D'", called_thing
);
2760 cp_error_at (buf
, fndecl
);
2761 error ("at this point in file");
2764 error ("too few arguments to function");
2765 return error_mark_list
;
2769 return nreverse (result
);
2772 /* Build a binary-operation expression, after performing default
2773 conversions on the operands. CODE is the kind of expression to build. */
2776 build_x_binary_op (code
, arg1
, arg2
)
2777 enum tree_code code
;
2780 tree rval
= build_opfncall (code
, LOOKUP_SPECULATIVELY
,
2781 arg1
, arg2
, NULL_TREE
);
2783 return build_opfncall (code
, LOOKUP_NORMAL
, arg1
, arg2
, NULL_TREE
);
2784 if (code
== MEMBER_REF
)
2785 return build_m_component_ref (build_indirect_ref (arg1
, NULL_PTR
),
2787 return build_binary_op (code
, arg1
, arg2
, 1);
2791 build_binary_op (code
, arg1
, arg2
, convert_p
)
2792 enum tree_code code
;
2805 args
[0] = args_save
[0] = default_conversion (args
[0]);
2806 args
[1] = args_save
[1] = default_conversion (args
[1]);
2808 if (args
[0] == error_mark_node
|| args
[1] == error_mark_node
)
2809 return error_mark_node
;
2811 type0
= TREE_TYPE (args
[0]);
2812 type1
= TREE_TYPE (args
[1]);
2814 if (type_unknown_p (args
[0]))
2816 args
[0] = instantiate_type (type1
, args
[0], 1);
2817 args
[0] = default_conversion (args
[0]);
2819 else if (type_unknown_p (args
[1]))
2821 args
[1] = require_instantiated_type (type0
, args
[1],
2823 args
[1] = default_conversion (args
[1]);
2826 if (IS_AGGR_TYPE (type0
) || IS_AGGR_TYPE (type1
))
2828 /* Try to convert this to something reasonable. */
2829 if (! build_default_binary_type_conversion(code
, &args
[0], &args
[1]))
2831 cp_error ("no match for `%O(%#T, %#T)'", code
,
2832 TREE_TYPE (arg1
), TREE_TYPE (arg2
));
2833 return error_mark_node
;
2837 if (args
[0] == args_save
[0])
2839 if (args
[1] == args_save
[1])
2842 return build_binary_op_nodefault (code
, args
[0], args
[1], code
);
2845 /* Build a binary-operation expression without default conversions.
2846 CODE is the kind of expression to build.
2847 This function differs from `build' in several ways:
2848 the data type of the result is computed and recorded in it,
2849 warnings are generated if arg data types are invalid,
2850 special handling for addition and subtraction of pointers is known,
2851 and some optimization is done (operations on narrow ints
2852 are done in the narrower type when that gives the same result).
2853 Constant folding is also done before the result is returned.
2855 ERROR_CODE is the code that determines what to say in error messages.
2856 It is usually, but not always, the same as CODE.
2858 Note that the operands will never have enumeral types
2859 because either they have just had the default conversions performed
2860 or they have both just been converted to some other type in which
2861 the arithmetic is to be done.
2863 C++: must do special pointer arithmetic when implementing
2864 multiple inheritance, and deal with pointer to member functions. */
2867 build_binary_op_nodefault (code
, orig_op0
, orig_op1
, error_code
)
2868 enum tree_code code
;
2869 tree orig_op0
, orig_op1
;
2870 enum tree_code error_code
;
2873 register enum tree_code code0
, code1
;
2876 /* Expression code to give to the expression when it is built.
2877 Normally this is CODE, which is what the caller asked for,
2878 but in some special cases we change it. */
2879 register enum tree_code resultcode
= code
;
2881 /* Data type in which the computation is to be performed.
2882 In the simplest cases this is the common type of the arguments. */
2883 register tree result_type
= NULL
;
2885 /* Nonzero means operands have already been type-converted
2886 in whatever way is necessary.
2887 Zero means they need to be converted to RESULT_TYPE. */
2890 /* Nonzero means create the expression with this type, rather than
2892 tree build_type
= 0;
2894 /* Nonzero means after finally constructing the expression
2895 convert it to this type. */
2896 tree final_type
= 0;
2898 /* Nonzero if this is an operation like MIN or MAX which can
2899 safely be computed in short if both args are promoted shorts.
2900 Also implies COMMON.
2901 -1 indicates a bitwise operation; this makes a difference
2902 in the exact conditions for when it is safe to do the operation
2903 in a narrower mode. */
2906 /* Nonzero if this is a comparison operation;
2907 if both args are promoted shorts, compare the original shorts.
2908 Also implies COMMON. */
2909 int short_compare
= 0;
2911 /* Nonzero if this is a right-shift operation, which can be computed on the
2912 original short and then promoted if the operand is a promoted short. */
2913 int short_shift
= 0;
2915 /* Nonzero means set RESULT_TYPE to the common type of the args. */
2918 /* Apply default conversions. */
2919 op0
= default_conversion (orig_op0
);
2920 op1
= default_conversion (orig_op1
);
2922 type0
= TREE_TYPE (op0
);
2923 type1
= TREE_TYPE (op1
);
2925 /* The expression codes of the data types of the arguments tell us
2926 whether the arguments are integers, floating, pointers, etc. */
2927 code0
= TREE_CODE (type0
);
2928 code1
= TREE_CODE (type1
);
2930 /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
2931 STRIP_TYPE_NOPS (op0
);
2932 STRIP_TYPE_NOPS (op1
);
2934 /* If an error was already reported for one of the arguments,
2935 avoid reporting another error. */
2937 if (code0
== ERROR_MARK
|| code1
== ERROR_MARK
)
2938 return error_mark_node
;
2943 /* Handle the pointer + int case. */
2944 if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
2945 return pointer_int_sum (PLUS_EXPR
, op0
, op1
);
2946 else if (code1
== POINTER_TYPE
&& code0
== INTEGER_TYPE
)
2947 return pointer_int_sum (PLUS_EXPR
, op1
, op0
);
2953 /* Subtraction of two similar pointers.
2954 We must subtract them as integers, then divide by object size. */
2955 if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
2956 && comp_target_types (type0
, type1
, 1))
2957 return pointer_diff (op0
, op1
);
2958 /* Handle pointer minus int. Just like pointer plus int. */
2959 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
2960 return pointer_int_sum (MINUS_EXPR
, op0
, op1
);
2969 case TRUNC_DIV_EXPR
:
2971 case FLOOR_DIV_EXPR
:
2972 case ROUND_DIV_EXPR
:
2973 case EXACT_DIV_EXPR
:
2974 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
2975 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
2977 if (TREE_CODE (op1
) == INTEGER_CST
&& integer_zerop (op1
))
2978 cp_warning ("division by zero in `%E / 0'", op0
);
2979 else if (TREE_CODE (op1
) == REAL_CST
&& real_zerop (op1
))
2980 cp_warning ("division by zero in `%E / 0.'", op0
);
2982 if (!(code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
))
2983 resultcode
= RDIV_EXPR
;
2985 /* When dividing two signed integers, we have to promote to int.
2986 unless we divide by a conatant != -1. Note that default
2987 conversion will have been performed on the operands at this
2988 point, so we have to dig out the original type to find out if
2990 shorten
= ((TREE_CODE (op0
) == NOP_EXPR
2991 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0
, 0))))
2992 || (TREE_CODE (op1
) == INTEGER_CST
2993 && (TREE_INT_CST_LOW (op1
) != -1
2994 || TREE_INT_CST_HIGH (op1
) != -1)));
3000 case BIT_ANDTC_EXPR
:
3003 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3005 /* If one operand is a constant, and the other is a short type
3006 that has been converted to an int,
3007 really do the work in the short type and then convert the
3008 result to int. If we are lucky, the constant will be 0 or 1
3009 in the short type, making the entire operation go away. */
3010 if (TREE_CODE (op0
) == INTEGER_CST
3011 && TREE_CODE (op1
) == NOP_EXPR
3012 && TYPE_PRECISION (type1
) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op1
, 0)))
3013 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op1
, 0))))
3015 final_type
= result_type
;
3016 op1
= TREE_OPERAND (op1
, 0);
3017 result_type
= TREE_TYPE (op1
);
3019 if (TREE_CODE (op1
) == INTEGER_CST
3020 && TREE_CODE (op0
) == NOP_EXPR
3021 && TYPE_PRECISION (type0
) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0
, 0)))
3022 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0
, 0))))
3024 final_type
= result_type
;
3025 op0
= TREE_OPERAND (op0
, 0);
3026 result_type
= TREE_TYPE (op0
);
3030 case TRUNC_MOD_EXPR
:
3031 case FLOOR_MOD_EXPR
:
3032 if (code1
== INTEGER_TYPE
&& integer_zerop (op1
))
3033 cp_warning ("division by zero in `%E % 0'", op0
);
3034 else if (code1
== REAL_TYPE
&& real_zerop (op1
))
3035 cp_warning ("division by zero in `%E % 0.'", op0
);
3037 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3039 /* Although it would be tempting to shorten always here, that loses
3040 on some targets, since the modulo instruction is undefined if the
3041 quotient can't be represented in the computation mode. We shorten
3042 only if unsigned or if dividing by something we know != -1. */
3043 shorten
= ((TREE_CODE (op0
) == NOP_EXPR
3044 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0
, 0))))
3045 || (TREE_CODE (op1
) == INTEGER_CST
3046 && (TREE_INT_CST_LOW (op1
) != -1
3047 || TREE_INT_CST_HIGH (op1
) != -1)));
3052 case TRUTH_ANDIF_EXPR
:
3053 case TRUTH_ORIF_EXPR
:
3054 case TRUTH_AND_EXPR
:
3056 result_type
= boolean_type_node
;
3059 /* Shift operations: result has same type as first operand;
3060 always convert second operand to int.
3061 Also set SHORT_SHIFT if shifting rightward. */
3064 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3066 result_type
= type0
;
3067 if (TREE_CODE (op1
) == INTEGER_CST
)
3069 if (tree_int_cst_lt (op1
, integer_zero_node
))
3070 warning ("right shift count is negative");
3073 if (TREE_INT_CST_LOW (op1
) | TREE_INT_CST_HIGH (op1
))
3075 if (TREE_INT_CST_HIGH (op1
) != 0
3076 || ((unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (op1
)
3077 >= TYPE_PRECISION (type0
)))
3078 warning ("right shift count >= width of type");
3081 /* Convert the shift-count to an integer, regardless of
3082 size of value being shifted. */
3083 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
3084 op1
= convert (integer_type_node
, op1
);
3085 /* Avoid converting op1 to result_type later. */
3091 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3093 result_type
= type0
;
3094 if (TREE_CODE (op1
) == INTEGER_CST
)
3096 if (tree_int_cst_lt (op1
, integer_zero_node
))
3097 warning ("left shift count is negative");
3098 else if (TREE_INT_CST_HIGH (op1
) != 0
3099 || ((unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (op1
)
3100 >= TYPE_PRECISION (type0
)))
3101 warning ("left shift count >= width of type");
3103 /* Convert the shift-count to an integer, regardless of
3104 size of value being shifted. */
3105 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
3106 op1
= convert (integer_type_node
, op1
);
3107 /* Avoid converting op1 to result_type later. */
3114 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3116 result_type
= type0
;
3117 if (TREE_CODE (op1
) == INTEGER_CST
)
3119 if (tree_int_cst_lt (op1
, integer_zero_node
))
3120 warning ("%s rotate count is negative",
3121 (code
== LROTATE_EXPR
) ? "left" : "right");
3122 else if (TREE_INT_CST_HIGH (op1
) != 0
3123 || ((unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (op1
)
3124 >= TYPE_PRECISION (type0
)))
3125 warning ("%s rotate count >= width of type",
3126 (code
== LROTATE_EXPR
) ? "left" : "right");
3128 /* Convert the shift-count to an integer, regardless of
3129 size of value being shifted. */
3130 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
3131 op1
= convert (integer_type_node
, op1
);
3137 build_type
= boolean_type_node
;
3138 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
3139 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
3141 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
3143 register tree tt0
= TYPE_MAIN_VARIANT (TREE_TYPE (type0
));
3144 register tree tt1
= TYPE_MAIN_VARIANT (TREE_TYPE (type1
));
3146 if (comp_target_types (type0
, type1
, 1))
3147 result_type
= common_type (type0
, type1
);
3148 else if (tt0
== void_type_node
)
3150 if (pedantic
&& TREE_CODE (tt1
) == FUNCTION_TYPE
3151 && tree_int_cst_lt (TYPE_SIZE (type0
), TYPE_SIZE (type1
)))
3152 pedwarn ("ANSI C++ forbids comparison of `void *' with function pointer");
3153 else if (TREE_CODE (tt1
) == OFFSET_TYPE
)
3154 pedwarn ("ANSI C++ forbids conversion of a pointer to member to `void *'");
3156 else if (tt1
== void_type_node
)
3158 if (pedantic
&& TREE_CODE (tt0
) == FUNCTION_TYPE
3159 && tree_int_cst_lt (TYPE_SIZE (type1
), TYPE_SIZE (type0
)))
3160 pedwarn ("ANSI C++ forbids comparison of `void *' with function pointer");
3163 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3166 if (result_type
== NULL_TREE
)
3167 result_type
= ptr_type_node
;
3169 else if (code0
== POINTER_TYPE
&& TREE_CODE (op1
) == INTEGER_CST
3170 && integer_zerop (op1
))
3171 result_type
= type0
;
3172 else if (code1
== POINTER_TYPE
&& TREE_CODE (op0
) == INTEGER_CST
3173 && integer_zerop (op0
))
3174 result_type
= type1
;
3175 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
3177 result_type
= type0
;
3178 error ("ANSI C++ forbids comparison between pointer and integer");
3180 else if (code0
== INTEGER_TYPE
&& code1
== POINTER_TYPE
)
3182 result_type
= type1
;
3183 error ("ANSI C++ forbids comparison between pointer and integer");
3185 else if (TYPE_PTRMEMFUNC_P (type0
) && TREE_CODE (op1
) == INTEGER_CST
3186 && integer_zerop (op1
))
3188 op0
= build_component_ref (op0
, index_identifier
, 0, 0);
3189 op1
= integer_zero_node
;
3190 result_type
= TREE_TYPE (op0
);
3192 else if (TYPE_PTRMEMFUNC_P (type1
) && TREE_CODE (op0
) == INTEGER_CST
3193 && integer_zerop (op0
))
3195 op0
= build_component_ref (op1
, index_identifier
, 0, 0);
3196 op1
= integer_zero_node
;
3197 result_type
= TREE_TYPE (op0
);
3199 else if (TYPE_PTRMEMFUNC_P (type0
) && TYPE_PTRMEMFUNC_P (type1
)
3200 && (TYPE_PTRMEMFUNC_FN_TYPE (type0
)
3201 == TYPE_PTRMEMFUNC_FN_TYPE (type1
)))
3203 /* The code we generate for the test is:
3205 (op0.index == op1.index
3206 && ((op1.index != -1 && op0.delta2 == op1.delta2)
3207 || op0.pfn == op1.pfn)) */
3209 tree index0
= build_component_ref (op0
, index_identifier
, 0, 0);
3210 tree index1
= save_expr (build_component_ref (op1
, index_identifier
, 0, 0));
3211 tree pfn0
= PFN_FROM_PTRMEMFUNC (op0
);
3212 tree pfn1
= PFN_FROM_PTRMEMFUNC (op1
);
3213 tree delta20
= DELTA2_FROM_PTRMEMFUNC (op0
);
3214 tree delta21
= DELTA2_FROM_PTRMEMFUNC (op1
);
3216 tree integer_neg_one_node
3217 = build_binary_op (MINUS_EXPR
, integer_zero_node
, integer_one_node
, 1);
3218 e1
= build_binary_op (EQ_EXPR
, index0
, index1
, 1);
3219 e2
= build_binary_op (NE_EXPR
, index1
, integer_neg_one_node
, 1);
3220 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e2
, build_binary_op (EQ_EXPR
, delta20
, delta21
, 1), 1);
3221 e3
= build_binary_op (EQ_EXPR
, pfn0
, pfn1
, 1);
3222 e2
= build_binary_op (TRUTH_ORIF_EXPR
, e2
, e3
, 1);
3223 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e1
, e2
, 1);
3224 if (code
== EQ_EXPR
)
3226 return build_binary_op (EQ_EXPR
, e2
, integer_zero_node
, 1);
3228 else if (TYPE_PTRMEMFUNC_P (type0
)
3229 && TYPE_PTRMEMFUNC_FN_TYPE (type0
) == type1
)
3231 tree index0
= build_component_ref (op0
, index_identifier
, 0, 0);
3233 tree pfn0
= PFN_FROM_PTRMEMFUNC (op0
);
3234 tree delta20
= DELTA2_FROM_PTRMEMFUNC (op0
);
3235 tree delta21
= integer_zero_node
;
3237 tree integer_neg_one_node
3238 = build_binary_op (MINUS_EXPR
, integer_zero_node
, integer_one_node
, 1);
3239 if (TREE_CODE (TREE_OPERAND (op1
, 0)) == FUNCTION_DECL
3240 && DECL_VINDEX (TREE_OPERAND (op1
, 0)))
3242 /* Map everything down one to make room for the null pointer to member. */
3243 index1
= size_binop (PLUS_EXPR
,
3244 DECL_VINDEX (TREE_OPERAND (op1
, 0)),
3246 op1
= integer_zero_node
;
3247 delta21
= CLASSTYPE_VFIELD (TYPE_METHOD_BASETYPE (TREE_TYPE (type1
)));
3248 delta21
= DECL_FIELD_BITPOS (delta21
);
3249 delta21
= size_binop (FLOOR_DIV_EXPR
, delta21
, size_int (BITS_PER_UNIT
));
3252 index1
= integer_neg_one_node
;
3254 tree nop1
= build1 (NOP_EXPR
, TYPE_PTRMEMFUNC_FN_TYPE (type0
), op1
);
3255 TREE_CONSTANT (nop1
) = TREE_CONSTANT (op1
);
3258 e1
= build_binary_op (EQ_EXPR
, index0
, index1
, 1);
3259 e2
= build_binary_op (NE_EXPR
, index1
, integer_neg_one_node
, 1);
3260 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e2
, build_binary_op (EQ_EXPR
, delta20
, delta21
, 1), 1);
3261 e3
= build_binary_op (EQ_EXPR
, pfn0
, op1
, 1);
3262 e2
= build_binary_op (TRUTH_ORIF_EXPR
, e2
, e3
, 1);
3263 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e1
, e2
, 1);
3264 if (code
== EQ_EXPR
)
3266 return build_binary_op (EQ_EXPR
, e2
, integer_zero_node
, 1);
3268 else if (TYPE_PTRMEMFUNC_P (type1
)
3269 && TYPE_PTRMEMFUNC_FN_TYPE (type1
) == type0
)
3271 return build_binary_op (code
, op1
, op0
, 1);
3277 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
3278 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
3280 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
3282 if (comp_target_types (type0
, type1
, 1))
3283 result_type
= common_type (type0
, type1
);
3286 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3288 result_type
= ptr_type_node
;
3297 build_type
= boolean_type_node
;
3298 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
3299 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
3301 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
3303 if (comp_target_types (type0
, type1
, 1))
3304 result_type
= common_type (type0
, type1
);
3307 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3309 result_type
= ptr_type_node
;
3312 else if (code0
== POINTER_TYPE
&& TREE_CODE (op1
) == INTEGER_CST
3313 && integer_zerop (op1
))
3314 result_type
= type0
;
3315 else if (code1
== POINTER_TYPE
&& TREE_CODE (op0
) == INTEGER_CST
3316 && integer_zerop (op0
))
3317 result_type
= type1
;
3318 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
3320 result_type
= type0
;
3322 pedwarn ("ANSI C++ forbids comparison between pointer and integer");
3323 else if (! flag_traditional
)
3324 warning ("comparison between pointer and integer");
3326 else if (code0
== INTEGER_TYPE
&& code1
== POINTER_TYPE
)
3328 result_type
= type1
;
3330 pedwarn ("ANSI C++ forbids comparison between pointer and integer");
3331 else if (! flag_traditional
)
3332 warning ("comparison between pointer and integer");
3337 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
3338 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
3340 if (shorten
|| common
|| short_compare
)
3341 result_type
= common_type (type0
, type1
);
3343 /* For certain operations (which identify themselves by shorten != 0)
3344 if both args were extended from the same smaller type,
3345 do the arithmetic in that type and then extend.
3347 shorten !=0 and !=1 indicates a bitwise operation.
3348 For them, this optimization is safe only if
3349 both args are zero-extended or both are sign-extended.
3350 Otherwise, we might change the result.
3351 Eg, (short)-1 | (unsigned short)-1 is (int)-1
3352 but calculated in (unsigned short) it would be (unsigned short)-1. */
3356 int unsigned0
, unsigned1
;
3357 tree arg0
= get_narrower (op0
, &unsigned0
);
3358 tree arg1
= get_narrower (op1
, &unsigned1
);
3359 /* UNS is 1 if the operation to be done is an unsigned one. */
3360 int uns
= TREE_UNSIGNED (result_type
);
3363 final_type
= result_type
;
3365 /* Handle the case that OP0 does not *contain* a conversion
3366 but it *requires* conversion to FINAL_TYPE. */
3368 if (op0
== arg0
&& TREE_TYPE (op0
) != final_type
)
3369 unsigned0
= TREE_UNSIGNED (TREE_TYPE (op0
));
3370 if (op1
== arg1
&& TREE_TYPE (op1
) != final_type
)
3371 unsigned1
= TREE_UNSIGNED (TREE_TYPE (op1
));
3373 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
3375 /* For bitwise operations, signedness of nominal type
3376 does not matter. Consider only how operands were extended. */
3380 /* Note that in all three cases below we refrain from optimizing
3381 an unsigned operation on sign-extended args.
3382 That would not be valid. */
3384 /* Both args variable: if both extended in same way
3385 from same width, do it in that width.
3386 Do it unsigned if args were zero-extended. */
3387 if ((TYPE_PRECISION (TREE_TYPE (arg0
))
3388 < TYPE_PRECISION (result_type
))
3389 && (TYPE_PRECISION (TREE_TYPE (arg1
))
3390 == TYPE_PRECISION (TREE_TYPE (arg0
)))
3391 && unsigned0
== unsigned1
3392 && (unsigned0
|| !uns
))
3394 = signed_or_unsigned_type (unsigned0
,
3395 common_type (TREE_TYPE (arg0
), TREE_TYPE (arg1
)));
3396 else if (TREE_CODE (arg0
) == INTEGER_CST
3397 && (unsigned1
|| !uns
)
3398 && (TYPE_PRECISION (TREE_TYPE (arg1
))
3399 < TYPE_PRECISION (result_type
))
3400 && (type
= signed_or_unsigned_type (unsigned1
,
3402 int_fits_type_p (arg0
, type
)))
3404 else if (TREE_CODE (arg1
) == INTEGER_CST
3405 && (unsigned0
|| !uns
)
3406 && (TYPE_PRECISION (TREE_TYPE (arg0
))
3407 < TYPE_PRECISION (result_type
))
3408 && (type
= signed_or_unsigned_type (unsigned0
,
3410 int_fits_type_p (arg1
, type
)))
3414 /* Shifts can be shortened if shifting right. */
3419 tree arg0
= get_narrower (op0
, &unsigned_arg
);
3421 final_type
= result_type
;
3423 if (arg0
== op0
&& final_type
== TREE_TYPE (op0
))
3424 unsigned_arg
= TREE_UNSIGNED (TREE_TYPE (op0
));
3426 if (TYPE_PRECISION (TREE_TYPE (arg0
)) < TYPE_PRECISION (result_type
)
3427 /* We can shorten only if the shift count is less than the
3428 number of bits in the smaller type size. */
3429 && TREE_INT_CST_HIGH (op1
) == 0
3430 && TYPE_PRECISION (TREE_TYPE (arg0
)) > TREE_INT_CST_LOW (op1
)
3431 /* If arg is sign-extended and then unsigned-shifted,
3432 we can simulate this with a signed shift in arg's type
3433 only if the extended result is at least twice as wide
3434 as the arg. Otherwise, the shift could use up all the
3435 ones made by sign-extension and bring in zeros.
3436 We can't optimize that case at all, but in most machines
3437 it never happens because available widths are 2**N. */
3438 && (!TREE_UNSIGNED (final_type
)
3440 || ((unsigned) 2 * TYPE_PRECISION (TREE_TYPE (arg0
))
3441 <= TYPE_PRECISION (result_type
))))
3443 /* Do an unsigned shift if the operand was zero-extended. */
3445 = signed_or_unsigned_type (unsigned_arg
,
3447 /* Convert value-to-be-shifted to that type. */
3448 if (TREE_TYPE (op0
) != result_type
)
3449 op0
= convert (result_type
, op0
);
3454 /* Comparison operations are shortened too but differently.
3455 They identify themselves by setting short_compare = 1. */
3459 /* Don't write &op0, etc., because that would prevent op0
3460 from being kept in a register.
3461 Instead, make copies of the our local variables and
3462 pass the copies by reference, then copy them back afterward. */
3463 tree xop0
= op0
, xop1
= op1
, xresult_type
= result_type
;
3464 enum tree_code xresultcode
= resultcode
;
3466 = shorten_compare (&xop0
, &xop1
, &xresult_type
, &xresultcode
);
3468 return convert (boolean_type_node
, val
);
3469 op0
= xop0
, op1
= xop1
;
3471 resultcode
= xresultcode
;
3474 if (short_compare
&& extra_warnings
)
3476 int op0_signed
= ! TREE_UNSIGNED (TREE_TYPE (orig_op0
));
3477 int op1_signed
= ! TREE_UNSIGNED (TREE_TYPE (orig_op1
));
3479 int unsignedp0
, unsignedp1
;
3480 tree primop0
= get_narrower (op0
, &unsignedp0
);
3481 tree primop1
= get_narrower (op1
, &unsignedp1
);
3483 /* Give warnings for comparisons between signed and unsigned
3484 quantities that may fail. */
3485 /* Do the checking based on the original operand trees, so that
3486 casts will be considered, but default promotions won't be. */
3488 /* Do not warn if the comparison is being done in a signed type,
3489 since the signed type will only be chosen if it can represent
3490 all the values of the unsigned type. */
3491 if (! TREE_UNSIGNED (result_type
))
3493 /* Do not warn if both operands are unsigned. */
3494 else if (op0_signed
== op1_signed
)
3496 /* Do not warn if the signed quantity is an unsuffixed
3497 integer literal (or some static constant expression
3498 involving such literals) and it is non-negative. */
3499 else if ((op0_signed
&& TREE_CODE (orig_op0
) == INTEGER_CST
3500 && tree_int_cst_sgn (orig_op0
) >= 0)
3501 || (op1_signed
&& TREE_CODE (orig_op1
) == INTEGER_CST
3502 && tree_int_cst_sgn (orig_op1
) >= 0))
3504 /* Do not warn if the comparison is an equality operation,
3505 the unsigned quantity is an integral constant and it does
3506 not use the most significant bit of result_type. */
3507 else if ((resultcode
== EQ_EXPR
|| resultcode
== NE_EXPR
)
3508 && ((op0_signed
&& TREE_CODE (orig_op1
) == INTEGER_CST
3509 && int_fits_type_p (orig_op1
, signed_type (result_type
))
3510 || (op1_signed
&& TREE_CODE (orig_op0
) == INTEGER_CST
3511 && int_fits_type_p (orig_op0
, signed_type (result_type
))))))
3514 warning ("comparison between signed and unsigned");
3516 /* Warn if two unsigned values are being compared in a size
3517 larger than their original size, and one (and only one) is the
3518 result of a `~' operator. This comparison will always fail.
3520 Also warn if one operand is a constant, and the constant does not
3521 have all bits set that are set in the ~ operand when it is
3524 if (TREE_CODE (primop0
) == BIT_NOT_EXPR
3525 ^ TREE_CODE (primop1
) == BIT_NOT_EXPR
)
3527 if (TREE_CODE (primop0
) == BIT_NOT_EXPR
)
3528 primop0
= get_narrower (TREE_OPERAND (op0
, 0), &unsignedp0
);
3529 if (TREE_CODE (primop1
) == BIT_NOT_EXPR
)
3530 primop1
= get_narrower (TREE_OPERAND (op1
, 0), &unsignedp1
);
3532 if (TREE_CODE (primop0
) == INTEGER_CST
3533 || TREE_CODE (primop1
) == INTEGER_CST
)
3536 HOST_WIDE_INT constant
, mask
;
3540 if (TREE_CODE (primop0
) == INTEGER_CST
)
3543 unsignedp
= unsignedp1
;
3544 constant
= TREE_INT_CST_LOW (primop0
);
3549 unsignedp
= unsignedp0
;
3550 constant
= TREE_INT_CST_LOW (primop1
);
3553 bits
= TYPE_PRECISION (TREE_TYPE (primop
));
3554 if (bits
< TYPE_PRECISION (result_type
)
3555 && bits
< HOST_BITS_PER_LONG
&& unsignedp
)
3557 mask
= (~ (HOST_WIDE_INT
) 0) << bits
;
3558 if ((mask
& constant
) != mask
)
3559 warning ("comparison of promoted ~unsigned with constant");
3562 else if (unsignedp0
&& unsignedp1
3563 && (TYPE_PRECISION (TREE_TYPE (primop0
))
3564 < TYPE_PRECISION (result_type
))
3565 && (TYPE_PRECISION (TREE_TYPE (primop1
))
3566 < TYPE_PRECISION (result_type
)))
3567 warning ("comparison of promoted ~unsigned with unsigned");
3572 /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
3573 If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
3574 Then the expression will be built.
3575 It will be given type FINAL_TYPE if that is nonzero;
3576 otherwise, it will be given type RESULT_TYPE. */
3580 cp_error ("invalid operands `%T' and `%T' to binary `%O'",
3581 TREE_TYPE (orig_op0
), TREE_TYPE (orig_op1
), error_code
);
3582 return error_mark_node
;
3587 if (TREE_TYPE (op0
) != result_type
)
3588 op0
= convert (result_type
, op0
);
3589 if (TREE_TYPE (op1
) != result_type
)
3590 op1
= convert (result_type
, op1
);
3593 if (build_type
== NULL_TREE
)
3594 build_type
= result_type
;
3597 register tree result
= build (resultcode
, build_type
, op0
, op1
);
3598 register tree folded
;
3600 folded
= fold (result
);
3601 if (folded
== result
)
3602 TREE_CONSTANT (folded
) = TREE_CONSTANT (op0
) & TREE_CONSTANT (op1
);
3603 if (final_type
!= 0)
3604 return convert (final_type
, folded
);
3609 /* Return a tree for the sum or difference (RESULTCODE says which)
3610 of pointer PTROP and integer INTOP. */
3613 pointer_int_sum (resultcode
, ptrop
, intop
)
3614 enum tree_code resultcode
;
3615 register tree ptrop
, intop
;
3619 register tree result
;
3620 register tree folded
= fold (intop
);
3622 /* The result is a pointer of the same type that is being added. */
3624 register tree result_type
= TREE_TYPE (ptrop
);
3626 if (TREE_CODE (TREE_TYPE (result_type
)) == VOID_TYPE
)
3628 if (pedantic
|| warn_pointer_arith
)
3629 pedwarn ("ANSI C++ forbids using pointer of type `void *' in arithmetic");
3630 size_exp
= integer_one_node
;
3632 else if (TREE_CODE (TREE_TYPE (result_type
)) == FUNCTION_TYPE
)
3634 if (pedantic
|| warn_pointer_arith
)
3635 pedwarn ("ANSI C++ forbids using pointer to a function in arithmetic");
3636 size_exp
= integer_one_node
;
3638 else if (TREE_CODE (TREE_TYPE (result_type
)) == METHOD_TYPE
)
3640 if (pedantic
|| warn_pointer_arith
)
3641 pedwarn ("ANSI C++ forbids using pointer to a method in arithmetic");
3642 size_exp
= integer_one_node
;
3644 else if (TREE_CODE (TREE_TYPE (result_type
)) == OFFSET_TYPE
)
3647 pedwarn ("ANSI C++ forbids using pointer to a member in arithmetic");
3648 size_exp
= integer_one_node
;
3651 size_exp
= size_in_bytes (TREE_TYPE (result_type
));
3653 /* Needed to make OOPS V2R3 work. */
3655 if (TREE_CODE (intop
) == INTEGER_CST
3656 && TREE_INT_CST_LOW (intop
) == 0
3657 && TREE_INT_CST_HIGH (intop
) == 0)
3660 /* If what we are about to multiply by the size of the elements
3661 contains a constant term, apply distributive law
3662 and multiply that constant term separately.
3663 This helps produce common subexpressions. */
3665 if ((TREE_CODE (intop
) == PLUS_EXPR
|| TREE_CODE (intop
) == MINUS_EXPR
)
3666 && ! TREE_CONSTANT (intop
)
3667 && TREE_CONSTANT (TREE_OPERAND (intop
, 1))
3668 && TREE_CONSTANT (size_exp
))
3670 enum tree_code subcode
= resultcode
;
3671 if (TREE_CODE (intop
) == MINUS_EXPR
)
3672 subcode
= (subcode
== PLUS_EXPR
? MINUS_EXPR
: PLUS_EXPR
);
3673 ptrop
= build_binary_op (subcode
, ptrop
, TREE_OPERAND (intop
, 1), 1);
3674 intop
= TREE_OPERAND (intop
, 0);
3677 /* Convert the integer argument to a type the same size as a pointer
3678 so the multiply won't overflow spuriously. */
3680 if (TYPE_PRECISION (TREE_TYPE (intop
)) != POINTER_SIZE
)
3681 intop
= convert (type_for_size (POINTER_SIZE
, 0), intop
);
3683 /* Replace the integer argument with a suitable product by the object size.
3684 Do this multiplication as signed, then convert to the appropriate
3685 pointer type (actually unsigned integral). */
3687 intop
= convert (result_type
,
3688 build_binary_op (MULT_EXPR
, intop
,
3689 convert (TREE_TYPE (intop
), size_exp
), 1));
3691 /* Create the sum or difference. */
3693 result
= build (resultcode
, result_type
, ptrop
, intop
);
3695 folded
= fold (result
);
3696 if (folded
== result
)
3697 TREE_CONSTANT (folded
) = TREE_CONSTANT (ptrop
) & TREE_CONSTANT (intop
);
3701 /* Return a tree for the difference of pointers OP0 and OP1.
3702 The resulting tree has type int. */
3705 pointer_diff (op0
, op1
)
3706 register tree op0
, op1
;
3708 register tree result
, folded
;
3709 tree restype
= ptrdiff_type_node
;
3710 tree target_type
= TREE_TYPE (TREE_TYPE (op0
));
3714 if (TREE_CODE (target_type
) == VOID_TYPE
)
3715 pedwarn ("ANSI C++ forbids using pointer of type `void *' in subtraction");
3716 if (TREE_CODE (target_type
) == FUNCTION_TYPE
)
3717 pedwarn ("ANSI C++ forbids using pointer to a function in subtraction");
3718 if (TREE_CODE (target_type
) == METHOD_TYPE
)
3719 pedwarn ("ANSI C++ forbids using pointer to a method in subtraction");
3720 if (TREE_CODE (target_type
) == OFFSET_TYPE
)
3721 pedwarn ("ANSI C++ forbids using pointer to a member in subtraction");
3724 /* First do the subtraction as integers;
3725 then drop through to build the divide operator. */
3727 op0
= build_binary_op (MINUS_EXPR
,
3728 convert (restype
, op0
), convert (restype
, op1
), 1);
3730 /* This generates an error if op1 is a pointer to an incomplete type. */
3731 if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (op1
))) == 0)
3732 error ("arithmetic on pointer to an incomplete type");
3734 op1
= ((TREE_CODE (target_type
) == VOID_TYPE
3735 || TREE_CODE (target_type
) == FUNCTION_TYPE
3736 || TREE_CODE (target_type
) == METHOD_TYPE
3737 || TREE_CODE (target_type
) == OFFSET_TYPE
)
3739 : size_in_bytes (target_type
));
3741 /* Do the division. */
3743 result
= build (EXACT_DIV_EXPR
, restype
, op0
, convert (restype
, op1
));
3745 folded
= fold (result
);
3746 if (folded
== result
)
3747 TREE_CONSTANT (folded
) = TREE_CONSTANT (op0
) & TREE_CONSTANT (op1
);
3751 /* Handle the case of taking the address of a COMPONENT_REF.
3752 Called by `build_unary_op' and `build_up_reference'.
3754 ARG is the COMPONENT_REF whose address we want.
3755 ARGTYPE is the pointer type that this address should have.
3756 MSG is an error message to print if this COMPONENT_REF is not
3757 addressable (such as a bitfield). */
3760 build_component_addr (arg
, argtype
, msg
)
3764 tree field
= TREE_OPERAND (arg
, 1);
3765 tree basetype
= decl_type_context (field
);
3766 tree rval
= build_unary_op (ADDR_EXPR
, TREE_OPERAND (arg
, 0), 0);
3768 if (DECL_BIT_FIELD (field
))
3770 error (msg
, IDENTIFIER_POINTER (DECL_NAME (field
)));
3771 return error_mark_node
;
3775 cp_warning ("address of `%T::%D' taken", basetype
, field
);
3777 if (TREE_CODE (field
) == FIELD_DECL
3778 && TYPE_USES_COMPLEX_INHERITANCE (basetype
))
3780 /* Can't convert directly to ARGTYPE, since that
3781 may have the same pointer type as one of our
3783 rval
= build1 (NOP_EXPR
, argtype
,
3784 convert_pointer_to (basetype
, rval
));
3785 TREE_CONSTANT (rval
) = TREE_CONSTANT (TREE_OPERAND (rval
, 0));
3788 /* This conversion is harmless. */
3789 rval
= convert_force (argtype
, rval
, 0);
3791 if (! integer_zerop (DECL_FIELD_BITPOS (field
)))
3793 tree offset
= size_binop (EASY_DIV_EXPR
, DECL_FIELD_BITPOS (field
),
3794 size_int (BITS_PER_UNIT
));
3795 int flag
= TREE_CONSTANT (rval
);
3796 rval
= fold (build (PLUS_EXPR
, argtype
,
3797 rval
, convert (argtype
, offset
)));
3798 TREE_CONSTANT (rval
) = flag
;
3803 /* Construct and perhaps optimize a tree representation
3804 for a unary operation. CODE, a tree_code, specifies the operation
3805 and XARG is the operand. */
3808 build_x_unary_op (code
, xarg
)
3809 enum tree_code code
;
3812 /* & rec, on incomplete RECORD_TYPEs is the simple opr &, not an
3814 if (code
== ADDR_EXPR
3815 && ((IS_AGGR_TYPE_CODE (TREE_CODE (TREE_TYPE (xarg
)))
3816 && TYPE_SIZE (TREE_TYPE (xarg
)) == NULL_TREE
)
3817 || (TREE_CODE (xarg
) == OFFSET_REF
)))
3818 /* don't look for a function */;
3821 tree rval
= build_opfncall (code
, LOOKUP_SPECULATIVELY
, xarg
,
3822 NULL_TREE
, NULL_TREE
);
3824 return build_opfncall (code
, LOOKUP_NORMAL
, xarg
,
3825 NULL_TREE
, NULL_TREE
);
3827 return build_unary_op (code
, xarg
, 0);
3830 /* Just like truthvalue_conversion, but we want a CLEANUP_POINT_EXPR. */
3833 condition_conversion (expr
)
3836 tree t
= convert (boolean_type_node
, expr
);
3837 t
= fold (build1 (CLEANUP_POINT_EXPR
, boolean_type_node
, t
));
3841 /* C++: Must handle pointers to members.
3843 Perhaps type instantiation should be extended to handle conversion
3844 from aggregates to types we don't yet know we want? (Or are those
3845 cases typically errors which should be reported?)
3847 NOCONVERT nonzero suppresses the default promotions
3848 (such as from short to int). */
3850 build_unary_op (code
, xarg
, noconvert
)
3851 enum tree_code code
;
3855 /* No default_conversion here. It causes trouble for ADDR_EXPR. */
3856 register tree arg
= xarg
;
3857 register tree argtype
= 0;
3858 char *errstring
= NULL
;
3861 if (arg
== error_mark_node
)
3862 return error_mark_node
;
3867 /* This is used for unary plus, because a CONVERT_EXPR
3868 is enough to prevent anybody from looking inside for
3869 associativity, but won't generate any code. */
3870 if (!(arg
= build_expr_type_conversion
3871 (WANT_ARITH
| WANT_ENUM
| WANT_POINTER
, arg
, 1)))
3872 errstring
= "wrong type argument to unary plus";
3876 arg
= default_conversion (arg
);
3877 arg
= build1 (NON_LVALUE_EXPR
, TREE_TYPE (arg
), arg
);
3882 if (!(arg
= build_expr_type_conversion (WANT_ARITH
| WANT_ENUM
, arg
, 1)))
3883 errstring
= "wrong type argument to unary minus";
3884 else if (!noconvert
)
3885 arg
= default_conversion (arg
);
3889 if (!(arg
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, arg
, 1)))
3890 errstring
= "wrong type argument to bit-complement";
3891 else if (!noconvert
)
3892 arg
= default_conversion (arg
);
3896 if (!(arg
= build_expr_type_conversion (WANT_ARITH
| WANT_ENUM
, arg
, 1)))
3897 errstring
= "wrong type argument to abs";
3898 else if (!noconvert
)
3899 arg
= default_conversion (arg
);
3902 case TRUTH_NOT_EXPR
:
3903 arg
= convert (boolean_type_node
, arg
);
3904 val
= invert_truthvalue (arg
);
3905 if (arg
!= error_mark_node
)
3907 errstring
= "in argument to unary !";
3913 case PREINCREMENT_EXPR
:
3914 case POSTINCREMENT_EXPR
:
3915 case PREDECREMENT_EXPR
:
3916 case POSTDECREMENT_EXPR
:
3917 /* Handle complex lvalues (when permitted)
3918 by reduction to simpler cases. */
3920 val
= unary_complex_lvalue (code
, arg
);
3924 /* Report invalid types. */
3926 if (!(arg
= build_expr_type_conversion (WANT_ARITH
| WANT_POINTER
,
3929 if (code
== PREINCREMENT_EXPR
)
3930 errstring
="no pre-increment operator for type";
3931 else if (code
== POSTINCREMENT_EXPR
)
3932 errstring
="no post-increment operator for type";
3933 else if (code
== PREDECREMENT_EXPR
)
3934 errstring
="no pre-decrement operator for type";
3936 errstring
="no post-decrement operator for type";
3940 /* Report something read-only. */
3942 if (TYPE_READONLY (TREE_TYPE (arg
))
3943 || TREE_READONLY (arg
))
3944 readonly_error (arg
, ((code
== PREINCREMENT_EXPR
3945 || code
== POSTINCREMENT_EXPR
)
3946 ? "increment" : "decrement"),
3951 tree result_type
= TREE_TYPE (arg
);
3953 arg
= get_unwidened (arg
, 0);
3954 argtype
= TREE_TYPE (arg
);
3956 /* ARM $5.2.5 last annotation says this should be forbidden. */
3957 if (TREE_CODE (argtype
) == ENUMERAL_TYPE
)
3958 pedwarn ("ANSI C++ forbids %sing an enum",
3959 (code
== PREINCREMENT_EXPR
|| code
== POSTINCREMENT_EXPR
)
3960 ? "increment" : "decrement");
3962 /* Compute the increment. */
3964 if (TREE_CODE (argtype
) == POINTER_TYPE
)
3966 enum tree_code tmp
= TREE_CODE (TREE_TYPE (argtype
));
3967 if (TYPE_SIZE (TREE_TYPE (argtype
)) == 0)
3968 cp_error ("cannot %s a pointer to incomplete type `%T'",
3969 ((code
== PREINCREMENT_EXPR
3970 || code
== POSTINCREMENT_EXPR
)
3971 ? "increment" : "decrement"), TREE_TYPE (argtype
));
3972 else if (tmp
== FUNCTION_TYPE
|| tmp
== METHOD_TYPE
3973 || tmp
== VOID_TYPE
|| tmp
== OFFSET_TYPE
)
3974 cp_pedwarn ("ANSI C++ forbids %sing a pointer of type `%T'",
3975 ((code
== PREINCREMENT_EXPR
3976 || code
== POSTINCREMENT_EXPR
)
3977 ? "increment" : "decrement"), argtype
);
3978 inc
= c_sizeof_nowarn (TREE_TYPE (argtype
));
3981 inc
= integer_one_node
;
3983 inc
= convert (argtype
, inc
);
3985 /* Handle incrementing a cast-expression. */
3987 switch (TREE_CODE (arg
))
3992 case FIX_TRUNC_EXPR
:
3993 case FIX_FLOOR_EXPR
:
3994 case FIX_ROUND_EXPR
:
3997 tree incremented
, modify
, value
;
3998 if (! lvalue_p (arg
) && pedantic
)
3999 pedwarn ("cast to non-reference type used as lvalue");
4000 arg
= stabilize_reference (arg
);
4001 if (code
== PREINCREMENT_EXPR
|| code
== PREDECREMENT_EXPR
)
4004 value
= save_expr (arg
);
4005 incremented
= build (((code
== PREINCREMENT_EXPR
4006 || code
== POSTINCREMENT_EXPR
)
4007 ? PLUS_EXPR
: MINUS_EXPR
),
4008 argtype
, value
, inc
);
4009 TREE_SIDE_EFFECTS (incremented
) = 1;
4010 modify
= build_modify_expr (arg
, NOP_EXPR
, incremented
);
4011 return build (COMPOUND_EXPR
, TREE_TYPE (arg
), modify
, value
);
4015 /* Complain about anything else that is not a true lvalue. */
4016 if (!lvalue_or_else (arg
, ((code
== PREINCREMENT_EXPR
4017 || code
== POSTINCREMENT_EXPR
)
4018 ? "increment" : "decrement")))
4019 return error_mark_node
;
4021 /* Forbid using -- on `bool'. */
4022 if (TREE_TYPE (arg
) == boolean_type_node
)
4024 if (code
== POSTDECREMENT_EXPR
|| code
== PREDECREMENT_EXPR
)
4026 cp_error ("invalid use of `--' on bool variable `%D'", arg
);
4027 return error_mark_node
;
4030 /* This will only work if someone can convince Kenner to accept
4031 my patch to expand_increment. (jason) */
4032 val
= build (code
, TREE_TYPE (arg
), arg
, inc
);
4034 if (code
== POSTINCREMENT_EXPR
)
4036 arg
= stabilize_reference (arg
);
4037 val
= build (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
4039 TREE_SIDE_EFFECTS (val
) = 1;
4040 arg
= save_expr (arg
);
4041 val
= build (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
4042 val
= build (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
4045 val
= build (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
4050 val
= build (code
, TREE_TYPE (arg
), arg
, inc
);
4052 TREE_SIDE_EFFECTS (val
) = 1;
4053 return convert (result_type
, val
);
4057 /* Note that this operation never does default_conversion
4058 regardless of NOCONVERT. */
4060 argtype
= TREE_TYPE (arg
);
4061 if (TREE_CODE (argtype
) == REFERENCE_TYPE
)
4063 arg
= build1 (CONVERT_EXPR
, build_pointer_type (TREE_TYPE (TREE_TYPE (arg
))), arg
);
4064 TREE_REFERENCE_EXPR (arg
) = 1;
4068 && TREE_CODE (arg
) == FUNCTION_DECL
4070 && DECL_CONTEXT (arg
) == NULL_TREE
4071 && IDENTIFIER_LENGTH (DECL_NAME (arg
)) == 4
4072 && IDENTIFIER_POINTER (DECL_NAME (arg
))[0] == 'm'
4073 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (arg
)), "main"))
4075 pedwarn ("taking address of function `main'");
4077 /* Let &* cancel out to simplify resulting code. */
4078 if (TREE_CODE (arg
) == INDIRECT_REF
)
4080 /* We don't need to have `current_class_decl' wrapped in a
4081 NON_LVALUE_EXPR node. */
4083 return current_class_decl
;
4085 /* Keep `default_conversion' from converting if
4086 ARG is of REFERENCE_TYPE. */
4087 arg
= TREE_OPERAND (arg
, 0);
4088 if (TREE_CODE (TREE_TYPE (arg
)) == REFERENCE_TYPE
)
4090 if (TREE_CODE (arg
) == VAR_DECL
&& DECL_INITIAL (arg
)
4091 && !TREE_SIDE_EFFECTS (DECL_INITIAL (arg
)))
4092 arg
= DECL_INITIAL (arg
);
4093 arg
= build1 (CONVERT_EXPR
, build_pointer_type (TREE_TYPE (TREE_TYPE (arg
))), arg
);
4094 TREE_REFERENCE_EXPR (arg
) = 1;
4095 TREE_CONSTANT (arg
) = TREE_CONSTANT (TREE_OPERAND (arg
, 0));
4097 else if (lvalue_p (arg
))
4098 /* Don't let this be an lvalue. */
4099 return non_lvalue (arg
);
4103 /* For &x[y], return x+y */
4104 if (TREE_CODE (arg
) == ARRAY_REF
)
4106 if (mark_addressable (TREE_OPERAND (arg
, 0)) == 0)
4107 return error_mark_node
;
4108 return build_binary_op (PLUS_EXPR
, TREE_OPERAND (arg
, 0),
4109 TREE_OPERAND (arg
, 1), 1);
4112 /* Uninstantiated types are all functions. Taking the
4113 address of a function is a no-op, so just return the
4116 if (TREE_CODE (arg
) == IDENTIFIER_NODE
4117 && IDENTIFIER_OPNAME_P (arg
))
4119 my_friendly_abort (117);
4120 /* We don't know the type yet, so just work around the problem.
4121 We know that this will resolve to an lvalue. */
4122 return build1 (ADDR_EXPR
, unknown_type_node
, arg
);
4125 if (TREE_CODE (arg
) == TREE_LIST
)
4127 if (TREE_CODE (TREE_VALUE (arg
)) == FUNCTION_DECL
4128 && DECL_CHAIN (TREE_VALUE (arg
)) == NULL_TREE
)
4129 /* Unique overloaded non-member function. */
4130 return build_unary_op (ADDR_EXPR
, TREE_VALUE (arg
), 0);
4131 if (TREE_CHAIN (arg
) == NULL_TREE
4132 && TREE_CODE (TREE_VALUE (arg
)) == TREE_LIST
4133 && DECL_CHAIN (TREE_VALUE (TREE_VALUE (arg
))) == NULL_TREE
)
4134 /* Unique overloaded member function. */
4135 return build_unary_op (ADDR_EXPR
, TREE_VALUE (TREE_VALUE (arg
)),
4137 return build1 (ADDR_EXPR
, unknown_type_node
, arg
);
4140 /* Handle complex lvalues (when permitted)
4141 by reduction to simpler cases. */
4142 val
= unary_complex_lvalue (code
, arg
);
4146 switch (TREE_CODE (arg
))
4151 case FIX_TRUNC_EXPR
:
4152 case FIX_FLOOR_EXPR
:
4153 case FIX_ROUND_EXPR
:
4155 if (! lvalue_p (arg
) && pedantic
)
4156 pedwarn ("taking the address of a cast to non-reference type");
4159 /* Allow the address of a constructor if all the elements
4161 if (TREE_CODE (arg
) == CONSTRUCTOR
&& TREE_CONSTANT (arg
))
4163 /* Anything not already handled and not a true memory reference
4165 else if (TREE_CODE (argtype
) != FUNCTION_TYPE
4166 && TREE_CODE (argtype
) != METHOD_TYPE
4167 && !lvalue_or_else (arg
, "unary `&'"))
4168 return error_mark_node
;
4170 /* Ordinary case; arg is a COMPONENT_REF or a decl. */
4171 /* If the lvalue is const or volatile,
4172 merge that into the type that the address will point to. */
4173 if (TREE_CODE_CLASS (TREE_CODE (arg
)) == 'd'
4174 || TREE_CODE_CLASS (TREE_CODE (arg
)) == 'r')
4176 if (TREE_READONLY (arg
) || TREE_THIS_VOLATILE (arg
))
4177 argtype
= cp_build_type_variant (argtype
,
4178 TREE_READONLY (arg
),
4179 TREE_THIS_VOLATILE (arg
));
4182 argtype
= build_pointer_type (argtype
);
4184 if (mark_addressable (arg
) == 0)
4185 return error_mark_node
;
4190 if (TREE_CODE (arg
) == COMPONENT_REF
)
4191 addr
= build_component_addr (arg
, argtype
,
4192 "attempt to take address of bit-field structure member `%s'");
4194 addr
= build1 (code
, argtype
, arg
);
4196 /* Address of a static or external variable or
4197 function counts as a constant */
4199 TREE_CONSTANT (addr
) = 1;
4207 argtype
= TREE_TYPE (arg
);
4208 return fold (build1 (code
, argtype
, arg
));
4212 return error_mark_node
;
4215 /* If CONVERSIONS is a conversion expression or a nested sequence of such,
4216 convert ARG with the same conversions in the same order
4217 and return the result. */
4220 convert_sequence (conversions
, arg
)
4224 switch (TREE_CODE (conversions
))
4229 case FIX_TRUNC_EXPR
:
4230 case FIX_FLOOR_EXPR
:
4231 case FIX_ROUND_EXPR
:
4233 return convert (TREE_TYPE (conversions
),
4234 convert_sequence (TREE_OPERAND (conversions
, 0),
4242 /* Apply unary lvalue-demanding operator CODE to the expression ARG
4243 for certain kinds of expressions which are not really lvalues
4244 but which we can accept as lvalues.
4246 If ARG is not a kind of expression we can handle, return zero. */
4249 unary_complex_lvalue (code
, arg
)
4250 enum tree_code code
;
4253 /* Handle (a, b) used as an "lvalue". */
4254 if (TREE_CODE (arg
) == COMPOUND_EXPR
)
4256 tree real_result
= build_unary_op (code
, TREE_OPERAND (arg
, 1), 0);
4257 return build (COMPOUND_EXPR
, TREE_TYPE (real_result
),
4258 TREE_OPERAND (arg
, 0), real_result
);
4261 /* Handle (a ? b : c) used as an "lvalue". */
4262 if (TREE_CODE (arg
) == COND_EXPR
)
4263 return rationalize_conditional_expr (code
, arg
);
4265 if (TREE_CODE (arg
) == MODIFY_EXPR
4266 || TREE_CODE (arg
) == PREINCREMENT_EXPR
4267 || TREE_CODE (arg
) == PREDECREMENT_EXPR
)
4268 return unary_complex_lvalue
4269 (code
, build (COMPOUND_EXPR
, TREE_TYPE (TREE_OPERAND (arg
, 0)),
4270 arg
, TREE_OPERAND (arg
, 0)));
4272 if (code
!= ADDR_EXPR
)
4275 /* Handle (a = b) used as an "lvalue" for `&'. */
4276 if (TREE_CODE (arg
) == MODIFY_EXPR
4277 || TREE_CODE (arg
) == INIT_EXPR
)
4279 tree real_result
= build_unary_op (code
, TREE_OPERAND (arg
, 0), 0);
4280 return build (COMPOUND_EXPR
, TREE_TYPE (real_result
), arg
, real_result
);
4283 if (TREE_CODE (arg
) == WITH_CLEANUP_EXPR
)
4285 tree real_result
= build_unary_op (code
, TREE_OPERAND (arg
, 0), 0);
4286 real_result
= build (WITH_CLEANUP_EXPR
, TREE_TYPE (real_result
),
4287 real_result
, 0, TREE_OPERAND (arg
, 2));
4291 if (TREE_CODE (TREE_TYPE (arg
)) == FUNCTION_TYPE
4292 || TREE_CODE (TREE_TYPE (arg
)) == METHOD_TYPE
4293 || TREE_CODE (TREE_TYPE (arg
)) == OFFSET_TYPE
)
4295 /* The representation of something of type OFFSET_TYPE
4296 is really the representation of a pointer to it.
4297 Here give the representation its true type. */
4301 my_friendly_assert (TREE_CODE (arg
) != SCOPE_REF
, 313);
4303 if (TREE_CODE (arg
) != OFFSET_REF
)
4306 t
= TREE_OPERAND (arg
, 1);
4308 if (TREE_CODE (t
) == FUNCTION_DECL
) /* Check all this code for right semantics. */
4309 return build_unary_op (ADDR_EXPR
, t
, 0);
4310 if (TREE_CODE (t
) == VAR_DECL
)
4311 return build_unary_op (ADDR_EXPR
, t
, 0);
4314 if (TREE_OPERAND (arg
, 0)
4315 && (TREE_CODE (TREE_OPERAND (arg
, 0)) != NOP_EXPR
4316 || TREE_OPERAND (TREE_OPERAND (arg
, 0), 0) != error_mark_node
))
4317 if (TREE_CODE (t
) != FIELD_DECL
)
4319 /* Don't know if this should return address to just
4320 _DECL, or actual address resolved in this expression. */
4321 sorry ("address of bound pointer-to-member expression");
4322 return error_mark_node
;
4325 offset
= get_delta_difference (DECL_FIELD_CONTEXT (t
),
4326 TREE_TYPE (TREE_OPERAND (arg
, 0)),
4328 offset
= size_binop (PLUS_EXPR
, offset
,
4329 size_binop (EASY_DIV_EXPR
,
4330 DECL_FIELD_BITPOS (t
),
4331 size_int (BITS_PER_UNIT
)));
4332 return convert (build_pointer_type (TREE_TYPE (arg
)), offset
);
4336 if (TREE_CODE (arg
) == OFFSET_REF
)
4338 tree left
= TREE_OPERAND (arg
, 0), left_addr
;
4339 tree right_addr
= build_unary_op (ADDR_EXPR
, TREE_OPERAND (arg
, 1), 0);
4342 if (current_class_decl
)
4343 left_addr
= current_class_decl
;
4346 error ("no `this' for pointer to member");
4347 return error_mark_node
;
4350 left_addr
= build_unary_op (ADDR_EXPR
, left
, 0);
4352 return build (PLUS_EXPR
, build_pointer_type (TREE_TYPE (arg
)),
4353 build1 (NOP_EXPR
, integer_type_node
, left_addr
),
4354 build1 (NOP_EXPR
, integer_type_node
, right_addr
));
4357 /* We permit compiler to make function calls returning
4358 objects of aggregate type look like lvalues. */
4362 if (TREE_CODE (targ
) == SAVE_EXPR
)
4363 targ
= TREE_OPERAND (targ
, 0);
4365 if (TREE_CODE (targ
) == CALL_EXPR
&& IS_AGGR_TYPE (TREE_TYPE (targ
)))
4367 if (TREE_CODE (arg
) == SAVE_EXPR
)
4370 targ
= build_cplus_new (TREE_TYPE (arg
), arg
, 1);
4371 return build1 (ADDR_EXPR
, TYPE_POINTER_TO (TREE_TYPE (arg
)), targ
);
4374 if (TREE_CODE (arg
) == SAVE_EXPR
&& TREE_CODE (targ
) == INDIRECT_REF
)
4375 return build (SAVE_EXPR
, TYPE_POINTER_TO (TREE_TYPE (arg
)),
4376 TREE_OPERAND (targ
, 0), current_function_decl
, NULL
);
4378 /* We shouldn't wrap WITH_CLEANUP_EXPRs inside of SAVE_EXPRs, but in case
4379 we do, here's how to handle it. */
4380 if (TREE_CODE (arg
) == SAVE_EXPR
&& TREE_CODE (targ
) == WITH_CLEANUP_EXPR
)
4383 /* Not really a bug, but something to turn on when testing. */
4384 compiler_error ("WITH_CLEANUP_EXPR wrapped in SAVE_EXPR");
4386 return unary_complex_lvalue (ADDR_EXPR
, targ
);
4390 /* Don't let anything else be handled specially. */
4394 /* Mark EXP saying that we need to be able to take the
4395 address of it; it should not be allocated in a register.
4396 Value is 1 if successful.
4398 C++: we do not allow `current_class_decl' to be addressable. */
4401 mark_addressable (exp
)
4404 register tree x
= exp
;
4406 if (TREE_ADDRESSABLE (x
) == 1)
4410 switch (TREE_CODE (x
))
4415 x
= TREE_OPERAND (x
, 0);
4419 if (x
== current_class_decl
)
4421 error ("address of `this' not available");
4422 TREE_ADDRESSABLE (x
) = 1; /* so compiler doesn't die later */
4423 put_var_into_stack (x
);
4428 && TREE_READONLY (x
)
4429 && DECL_RTL (x
) != 0
4430 && ! decl_in_memory_p (x
))
4432 /* We thought this would make a good constant variable,
4433 but we were wrong. */
4434 push_obstacks_nochange ();
4435 end_temporary_allocation ();
4437 TREE_ASM_WRITTEN (x
) = 0;
4439 rest_of_decl_compilation (x
, 0, IDENTIFIER_LOCAL_VALUE (x
) == 0, 0);
4440 TREE_ADDRESSABLE (x
) = 1;
4446 /* Caller should not be trying to mark initialized
4447 constant fields addressable. */
4448 my_friendly_assert (DECL_LANG_SPECIFIC (x
) == 0
4449 || DECL_IN_AGGR_P (x
) == 0
4451 || DECL_EXTERNAL (x
), 314);
4455 /* For C++, we don't warn about taking the address of a register
4456 variable for CONST_DECLs; ARM p97 explicitly says it's okay. */
4457 put_var_into_stack (x
);
4458 TREE_ADDRESSABLE (x
) = 1;
4462 /* We have to test both conditions here. The first may
4463 be non-zero in the case of processing a default function.
4464 The second may be non-zero in the case of a template function. */
4465 x
= DECL_MAIN_VARIANT (x
);
4466 if ((DECL_THIS_INLINE (x
) || DECL_PENDING_INLINE_INFO (x
))
4467 && (DECL_CONTEXT (x
) == NULL_TREE
4468 || TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (x
))) != 't'
4469 || ! CLASSTYPE_INTERFACE_ONLY (DECL_CONTEXT (x
))))
4471 mark_inline_for_output (x
);
4472 if (x
== current_function_decl
)
4473 DECL_EXTERNAL (x
) = 0;
4475 TREE_ADDRESSABLE (x
) = 1;
4477 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (x
)) = 1;
4485 /* Build and return a conditional expression IFEXP ? OP1 : OP2. */
4488 build_x_conditional_expr (ifexp
, op1
, op2
)
4489 tree ifexp
, op1
, op2
;
4491 tree rval
= NULL_TREE
;
4493 /* See comments in `build_x_binary_op'. */
4495 rval
= build_opfncall (COND_EXPR
, LOOKUP_SPECULATIVELY
, ifexp
, op1
, op2
);
4497 return build_opfncall (COND_EXPR
, LOOKUP_NORMAL
, ifexp
, op1
, op2
);
4499 return build_conditional_expr (ifexp
, op1
, op2
);
4503 build_conditional_expr (ifexp
, op1
, op2
)
4504 tree ifexp
, op1
, op2
;
4506 register tree type1
;
4507 register tree type2
;
4508 register enum tree_code code1
;
4509 register enum tree_code code2
;
4510 register tree result_type
= NULL_TREE
;
4511 tree orig_op1
= op1
, orig_op2
= op2
;
4513 /* If second operand is omitted, it is the same as the first one;
4514 make sure it is calculated only once. */
4518 pedwarn ("ANSI C++ forbids omitting the middle term of a ?: expression");
4519 ifexp
= op1
= save_expr (ifexp
);
4522 ifexp
= truthvalue_conversion (ifexp
);
4524 if (TREE_CODE (ifexp
) == ERROR_MARK
)
4525 return error_mark_node
;
4527 op1
= require_instantiated_type (TREE_TYPE (op2
), op1
, error_mark_node
);
4528 if (op1
== error_mark_node
)
4529 return error_mark_node
;
4530 op2
= require_instantiated_type (TREE_TYPE (op1
), op2
, error_mark_node
);
4531 if (op2
== error_mark_node
)
4532 return error_mark_node
;
4534 /* C++: REFERENCE_TYPES must be dereferenced. */
4535 type1
= TREE_TYPE (op1
);
4536 code1
= TREE_CODE (type1
);
4537 type2
= TREE_TYPE (op2
);
4538 code2
= TREE_CODE (type2
);
4540 if (code1
== REFERENCE_TYPE
)
4542 op1
= convert_from_reference (op1
);
4543 type1
= TREE_TYPE (op1
);
4544 code1
= TREE_CODE (type1
);
4546 if (code2
== REFERENCE_TYPE
)
4548 op2
= convert_from_reference (op2
);
4549 type2
= TREE_TYPE (op2
);
4550 code2
= TREE_CODE (type2
);
4553 #if 1 /* Produces wrong result if within sizeof. Sorry. */
4554 /* Don't promote the operands separately if they promote
4555 the same way. Return the unpromoted type and let the combined
4556 value get promoted if necessary. */
4558 if (TYPE_MAIN_VARIANT (type1
) == TYPE_MAIN_VARIANT (type2
)
4559 && code2
!= ARRAY_TYPE
4561 /* For C++, let the enumeral type come through. */
4562 && code2
!= ENUMERAL_TYPE
4564 && code2
!= FUNCTION_TYPE
4565 && code2
!= METHOD_TYPE
)
4569 if (TREE_CONSTANT (ifexp
)
4570 && (TREE_CODE (ifexp
) == INTEGER_CST
4571 || TREE_CODE (ifexp
) == ADDR_EXPR
))
4572 return (integer_zerop (ifexp
) ? op2
: op1
);
4574 if (TREE_CODE (op1
) == CONST_DECL
)
4575 op1
= DECL_INITIAL (op1
);
4576 else if (TREE_READONLY_DECL_P (op1
))
4577 op1
= decl_constant_value (op1
);
4578 if (TREE_CODE (op2
) == CONST_DECL
)
4579 op2
= DECL_INITIAL (op2
);
4580 else if (TREE_READONLY_DECL_P (op2
))
4581 op2
= decl_constant_value (op2
);
4583 type1
= cp_build_type_variant
4585 TREE_READONLY (op1
) || TREE_READONLY (op2
),
4586 TREE_THIS_VOLATILE (op1
) || TREE_THIS_VOLATILE (op2
));
4587 /* ??? This is a kludge to deal with the fact that
4588 we don't sort out integers and enums properly, yet. */
4589 result
= fold (build (COND_EXPR
, type1
, ifexp
, op1
, op2
));
4590 if (TREE_TYPE (result
) != type1
)
4591 result
= build1 (NOP_EXPR
, type1
, result
);
4596 /* They don't match; promote them both and then try to reconcile them.
4597 But don't permit mismatching enum types. */
4598 if (code1
== ENUMERAL_TYPE
)
4600 if (code2
== ENUMERAL_TYPE
)
4602 cp_error ("enumeral mismatch in conditional expression: `%T' vs `%T'", type1
, type2
);
4603 return error_mark_node
;
4605 else if (extra_warnings
&& ! IS_AGGR_TYPE_CODE (code2
)
4606 && type2
!= type_promotes_to (type1
))
4607 warning ("enumeral and non-enumeral type in conditional expression");
4609 else if (extra_warnings
4610 && code2
== ENUMERAL_TYPE
&& ! IS_AGGR_TYPE_CODE (code1
)
4611 && type1
!= type_promotes_to (type2
))
4612 warning ("enumeral and non-enumeral type in conditional expression");
4614 if (code1
!= VOID_TYPE
)
4616 op1
= default_conversion (op1
);
4617 type1
= TREE_TYPE (op1
);
4618 if (TYPE_PTRMEMFUNC_P (type1
))
4619 type1
= TYPE_PTRMEMFUNC_FN_TYPE (type1
);
4620 code1
= TREE_CODE (type1
);
4622 if (code2
!= VOID_TYPE
)
4624 op2
= default_conversion (op2
);
4625 type2
= TREE_TYPE (op2
);
4626 if (TYPE_PTRMEMFUNC_P (type2
))
4627 type2
= TYPE_PTRMEMFUNC_FN_TYPE (type2
);
4628 code2
= TREE_CODE (type2
);
4631 if (code1
== RECORD_TYPE
&& code2
== RECORD_TYPE
4632 && real_lvalue_p (op1
) && real_lvalue_p (op2
)
4633 && comptypes (type1
, type2
, -1))
4635 type1
= build_reference_type (type1
);
4636 type2
= build_reference_type (type2
);
4637 result_type
= common_type (type1
, type2
);
4638 op1
= convert_to_reference (result_type
, op1
, CONV_IMPLICIT
,
4639 LOOKUP_NORMAL
, NULL_TREE
);
4640 op2
= convert_to_reference (result_type
, op2
, CONV_IMPLICIT
,
4641 LOOKUP_NORMAL
, NULL_TREE
);
4643 /* Quickly detect the usual case where op1 and op2 have the same type
4645 else if (TYPE_MAIN_VARIANT (type1
) == TYPE_MAIN_VARIANT (type2
))
4648 result_type
= type1
;
4650 result_type
= cp_build_type_variant
4652 TREE_READONLY (op1
) || TREE_READONLY (op2
),
4653 TREE_THIS_VOLATILE (op1
) || TREE_THIS_VOLATILE (op2
));
4655 else if ((code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
)
4656 && (code2
== INTEGER_TYPE
|| code2
== REAL_TYPE
))
4658 result_type
= common_type (type1
, type2
);
4660 else if (code1
== VOID_TYPE
|| code2
== VOID_TYPE
)
4662 if (pedantic
&& (code1
!= VOID_TYPE
|| code2
!= VOID_TYPE
))
4663 pedwarn ("ANSI C++ forbids conditional expr with only one void side");
4664 result_type
= void_type_node
;
4666 else if (code1
== POINTER_TYPE
&& code2
== POINTER_TYPE
)
4668 if (comp_target_types (type1
, type2
, 1))
4669 result_type
= common_type (type1
, type2
);
4670 else if (integer_zerop (op1
) && TREE_TYPE (type1
) == void_type_node
4671 && TREE_CODE (orig_op1
) != NOP_EXPR
)
4672 result_type
= qualify_type (type2
, type1
);
4673 else if (integer_zerop (op2
) && TREE_TYPE (type2
) == void_type_node
4674 && TREE_CODE (orig_op2
) != NOP_EXPR
)
4675 result_type
= qualify_type (type1
, type2
);
4676 else if (TYPE_MAIN_VARIANT (TREE_TYPE (type1
)) == void_type_node
)
4678 if (pedantic
&& TREE_CODE (type2
) == FUNCTION_TYPE
)
4679 pedwarn ("ANSI C++ forbids conditional expr between `void *' and function pointer");
4680 result_type
= qualify_type (type1
, type2
);
4682 else if (TYPE_MAIN_VARIANT (TREE_TYPE (type2
)) == void_type_node
)
4684 if (pedantic
&& TREE_CODE (type1
) == FUNCTION_TYPE
)
4685 pedwarn ("ANSI C++ forbids conditional expr between `void *' and function pointer");
4686 result_type
= qualify_type (type2
, type1
);
4689 else if (comptypes (type2
, type1
, 0))
4690 result_type
= type2
;
4691 else if (IS_AGGR_TYPE (TREE_TYPE (type1
))
4692 && IS_AGGR_TYPE (TREE_TYPE (type2
))
4693 && (result_type
= common_base_type (TREE_TYPE (type1
), TREE_TYPE (type2
))))
4695 if (result_type
== error_mark_node
)
4697 cp_error ("common base type of types `%T' and `%T' is ambiguous",
4698 TREE_TYPE (type1
), TREE_TYPE (type2
));
4699 result_type
= ptr_type_node
;
4704 && result_type
!= TREE_TYPE (type1
)
4705 && result_type
!= TREE_TYPE (type2
))
4706 cp_pedwarn ("`%T' and `%T' converted to `%T *' in conditional expression",
4707 type1
, type2
, result_type
);
4709 result_type
= TYPE_POINTER_TO (result_type
);
4714 pedwarn ("pointer type mismatch in conditional expression");
4715 result_type
= ptr_type_node
;
4718 else if (code1
== POINTER_TYPE
&& code2
== INTEGER_TYPE
)
4720 if (!integer_zerop (op2
))
4721 pedwarn ("pointer/integer type mismatch in conditional expression");
4724 op2
= null_pointer_node
;
4725 #if 0 /* Sez who? */
4726 if (pedantic
&& TREE_CODE (type1
) == FUNCTION_TYPE
)
4727 pedwarn ("ANSI C++ forbids conditional expr between 0 and function pointer");
4730 result_type
= type1
;
4732 else if (code2
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
4734 if (!integer_zerop (op1
))
4735 pedwarn ("pointer/integer type mismatch in conditional expression");
4738 op1
= null_pointer_node
;
4739 #if 0 /* Sez who? */
4740 if (pedantic
&& TREE_CODE (type2
) == FUNCTION_TYPE
)
4741 pedwarn ("ANSI C++ forbids conditional expr between 0 and function pointer");
4744 result_type
= type2
;
4749 /* The match does not look good. If either is
4750 an aggregate value, try converting to a scalar type. */
4751 if (code1
== RECORD_TYPE
&& code2
== RECORD_TYPE
)
4753 cp_error ("aggregate mismatch in conditional expression: `%T' vs `%T'", type1
, type2
);
4754 return error_mark_node
;
4756 if (code1
== RECORD_TYPE
&& TYPE_HAS_CONVERSION (type1
))
4758 tree tmp
= build_type_conversion (CONVERT_EXPR
, type2
, op1
, 0);
4759 if (tmp
== NULL_TREE
)
4761 cp_error ("aggregate type `%T' could not convert on lhs of `:'", type1
);
4762 return error_mark_node
;
4764 if (tmp
== error_mark_node
)
4765 error ("ambiguous pointer conversion");
4766 result_type
= type2
;
4769 else if (code2
== RECORD_TYPE
&& TYPE_HAS_CONVERSION (type2
))
4771 tree tmp
= build_type_conversion (CONVERT_EXPR
, type1
, op2
, 0);
4772 if (tmp
== NULL_TREE
)
4774 cp_error ("aggregate type `%T' could not convert on rhs of `:'", type2
);
4775 return error_mark_node
;
4777 if (tmp
== error_mark_node
)
4778 error ("ambiguous pointer conversion");
4779 result_type
= type1
;
4782 else if (flag_cond_mismatch
)
4783 result_type
= void_type_node
;
4786 error ("type mismatch in conditional expression");
4787 return error_mark_node
;
4791 if (TREE_CODE (result_type
) == POINTER_TYPE
4792 && TREE_CODE (TREE_TYPE (result_type
)) == METHOD_TYPE
)
4793 result_type
= build_ptrmemfunc_type (result_type
);
4795 if (result_type
!= TREE_TYPE (op1
))
4796 op1
= convert_and_check (result_type
, op1
);
4797 if (result_type
!= TREE_TYPE (op2
))
4798 op2
= convert_and_check (result_type
, op2
);
4801 /* XXX delete me, I've been here for years. */
4802 if (IS_AGGR_TYPE_CODE (code1
))
4804 result_type
= TREE_TYPE (op1
);
4805 if (TREE_CONSTANT (ifexp
))
4806 return (integer_zerop (ifexp
) ? op2
: op1
);
4808 if (TYPE_MODE (result_type
) == BLKmode
)
4810 register tree tempvar
4811 = build_decl (VAR_DECL
, NULL_TREE
, result_type
);
4812 register tree xop1
= build_modify_expr (tempvar
, NOP_EXPR
, op1
);
4813 register tree xop2
= build_modify_expr (tempvar
, NOP_EXPR
, op2
);
4814 register tree result
= fold (build (COND_EXPR
, result_type
,
4815 ifexp
, xop1
, xop2
));
4817 layout_decl (tempvar
, 0);
4818 /* No way to handle variable-sized objects here.
4819 I fear that the entire handling of BLKmode conditional exprs
4820 needs to be redone. */
4821 my_friendly_assert (TREE_CONSTANT (DECL_SIZE (tempvar
)), 315);
4823 = assign_stack_local (DECL_MODE (tempvar
),
4824 (TREE_INT_CST_LOW (DECL_SIZE (tempvar
))
4825 + BITS_PER_UNIT
- 1)
4829 TREE_SIDE_EFFECTS (result
)
4830 = TREE_SIDE_EFFECTS (ifexp
) | TREE_SIDE_EFFECTS (op1
)
4831 | TREE_SIDE_EFFECTS (op2
);
4832 return build (COMPOUND_EXPR
, result_type
, result
, tempvar
);
4837 if (TREE_CONSTANT (ifexp
))
4838 return integer_zerop (ifexp
) ? op2
: op1
;
4840 return convert_from_reference
4841 (fold (build (COND_EXPR
, result_type
, ifexp
, op1
, op2
)));
4844 /* Handle overloading of the ',' operator when needed. Otherwise,
4845 this function just builds an expression list. */
4847 build_x_compound_expr (list
)
4850 tree rest
= TREE_CHAIN (list
);
4853 if (rest
== NULL_TREE
)
4854 return build_compound_expr (list
);
4856 result
= build_opfncall (COMPOUND_EXPR
, LOOKUP_NORMAL
,
4857 TREE_VALUE (list
), TREE_VALUE (rest
), NULL_TREE
);
4859 return build_x_compound_expr (tree_cons (NULL_TREE
, result
, TREE_CHAIN (rest
)));
4861 if (! TREE_SIDE_EFFECTS (TREE_VALUE (list
)))
4863 /* the left-hand operand of a comma expression is like an expression
4864 statement: we should warn if it doesn't have any side-effects,
4865 unless it was explicitly cast to (void). */
4866 if ((extra_warnings
|| warn_unused
)
4867 && !(TREE_CODE (TREE_VALUE(list
)) == CONVERT_EXPR
4868 && TREE_TYPE (TREE_VALUE(list
)) == void_type_node
))
4869 warning("left-hand operand of comma expression has no effect");
4871 #if 0 /* this requires a gcc backend patch to export warn_if_unused_value */
4872 else if (warn_unused
)
4873 warn_if_unused_value (TREE_VALUE(list
));
4876 return build_compound_expr (tree_cons (NULL_TREE
, TREE_VALUE (list
),
4877 build_tree_list (NULL_TREE
, build_x_compound_expr (rest
))));
4880 /* Given a list of expressions, return a compound expression
4881 that performs them all and returns the value of the last of them. */
4884 build_compound_expr (list
)
4889 if (TREE_READONLY_DECL_P (TREE_VALUE (list
)))
4890 TREE_VALUE (list
) = decl_constant_value (TREE_VALUE (list
));
4892 if (TREE_CHAIN (list
) == 0)
4894 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
4895 Strip such NOP_EXPRs, since LIST is used in non-lvalue context. */
4896 if (TREE_CODE (list
) == NOP_EXPR
4897 && TREE_TYPE (list
) == TREE_TYPE (TREE_OPERAND (list
, 0)))
4898 list
= TREE_OPERAND (list
, 0);
4900 /* Convert arrays to pointers. */
4901 if (TREE_CODE (TREE_TYPE (TREE_VALUE (list
))) == ARRAY_TYPE
)
4902 return default_conversion (TREE_VALUE (list
));
4904 return TREE_VALUE (list
);
4907 rest
= build_compound_expr (TREE_CHAIN (list
));
4909 /* When pedantic, a compound expression cannot be a constant expression. */
4910 if (! TREE_SIDE_EFFECTS (TREE_VALUE (list
)) && ! pedantic
)
4913 return build (COMPOUND_EXPR
, TREE_TYPE (rest
),
4914 break_out_cleanups (TREE_VALUE (list
)), rest
);
4924 return (TREE_CODE (t
) == INTEGER_CST
&& integer_zerop (t
));
4927 tree
build_static_cast (type
, expr
)
4930 return build_c_cast (type
, expr
, 0);
4933 tree
build_reinterpret_cast (type
, expr
)
4936 tree intype
= TREE_TYPE (expr
);
4938 if (TYPE_PTRMEMFUNC_P (type
))
4939 type
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
4940 if (TYPE_PTRMEMFUNC_P (intype
))
4941 intype
= TYPE_PTRMEMFUNC_FN_TYPE (intype
);
4943 if (! POINTER_TYPE_P (type
) && ! TREE_CODE (type
) == INTEGER_TYPE
)
4945 cp_error ("reinterpret_cast cannot convert to type `%T'", type
);
4946 return error_mark_node
;
4948 if (! POINTER_TYPE_P (intype
) && ! TREE_CODE (intype
) == INTEGER_TYPE
)
4950 cp_error ("reinterpret_cast cannot convert from type `%T'", type
);
4951 return error_mark_node
;
4953 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_CODE (intype
) != POINTER_TYPE
)
4955 cp_error ("reinterpret_cast cannot convert non-pointer type `%T' to `%T'",
4957 return error_mark_node
;
4959 if (TREE_CODE (intype
) == INTEGER_TYPE
&& TREE_CODE (type
) != POINTER_TYPE
)
4961 cp_error ("reinterpret_cast cannot convert `%T' to non-pointer type `%T'",
4963 return error_mark_node
;
4966 if (TREE_CODE (type
) == POINTER_TYPE
&& TREE_CODE (intype
) == POINTER_TYPE
)
4967 expr
= convert (ptr_type_node
, expr
);
4969 return build_c_cast (type
, expr
, 0);
4972 tree
build_const_cast (type
, expr
)
4975 tree intype
= TREE_TYPE (expr
);
4978 if (TYPE_PTRMEMFUNC_P (type
))
4979 type
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
4980 if (TYPE_PTRMEMFUNC_P (intype
))
4981 intype
= TYPE_PTRMEMFUNC_FN_TYPE (intype
);
4983 if (! POINTER_TYPE_P (type
))
4985 cp_error ("const_cast cannot convert to non-pointer type `%T'", type
);
4986 return error_mark_node
;
4988 if (TREE_CODE (type
) == REFERENCE_TYPE
&& ! real_lvalue_p (expr
))
4990 cp_error ("const_cast cannot convert rvalue to type `%T'", type
);
4991 return error_mark_node
;
4993 if (TREE_CODE (type
) == POINTER_TYPE
&& TREE_CODE (intype
) != POINTER_TYPE
)
4995 cp_error ("const_cast cannot convert non-pointer type `%T' to type `%T'",
4997 return error_mark_node
;
5000 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5002 t1
= TREE_TYPE (type
);
5007 t1
= TREE_TYPE (type
);
5008 t2
= TREE_TYPE (intype
);
5010 for (; TREE_CODE (t1
) == POINTER_TYPE
&& TREE_CODE (t2
) == POINTER_TYPE
;
5011 t1
= TREE_TYPE (t1
), t2
= TREE_TYPE (t2
))
5015 if (TREE_CODE (t1
) == OFFSET_TYPE
&& TREE_CODE (t2
) == OFFSET_TYPE
)
5017 if (TYPE_OFFSET_BASETYPE (t1
) != TYPE_OFFSET_BASETYPE (t2
))
5019 cp_error ("const_cast cannot convert between pointers to members of different types `%T' and `%T'",
5020 TYPE_OFFSET_BASETYPE (t2
), TYPE_OFFSET_BASETYPE (t1
));
5021 return error_mark_node
;
5023 t1
= TREE_TYPE (t1
);
5024 t2
= TREE_TYPE (t2
);
5027 if (TYPE_MAIN_VARIANT (t1
) != TYPE_MAIN_VARIANT (t2
))
5029 cp_error ("const_cast cannot convert unrelated type `%T' to `%T'",
5031 return error_mark_node
;
5034 return build_c_cast (type
, expr
, 0);
5037 /* Build an expression representing a cast to type TYPE of expression EXPR.
5039 ALLOW_NONCONVERTING is true if we should allow non-converting constructors
5040 when doing the cast. */
5043 build_c_cast (type
, expr
, allow_nonconverting
)
5046 int allow_nonconverting
;
5048 register tree value
= expr
;
5050 if (type
== error_mark_node
|| expr
== error_mark_node
)
5051 return error_mark_node
;
5053 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5054 Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */
5055 if (TREE_CODE (type
) != REFERENCE_TYPE
5056 && TREE_CODE (value
) == NOP_EXPR
5057 && TREE_TYPE (value
) == TREE_TYPE (TREE_OPERAND (value
, 0)))
5058 value
= TREE_OPERAND (value
, 0);
5060 if (TREE_TYPE (expr
)
5061 && TREE_CODE (TREE_TYPE (expr
)) == OFFSET_TYPE
5062 && TREE_CODE (type
) != OFFSET_TYPE
)
5063 value
= resolve_offset_ref (value
);
5065 if (TREE_CODE (type
) == ARRAY_TYPE
)
5067 /* Allow casting from T1* to T2[] because Cfront allows it.
5068 NIHCL uses it. It is not valid ANSI C however, and hence, not
5070 if (TREE_CODE (TREE_TYPE (expr
)) == POINTER_TYPE
)
5073 pedwarn ("ANSI C++ forbids casting to an array type");
5074 type
= build_pointer_type (TREE_TYPE (type
));
5078 error ("ANSI C++ forbids casting to an array type");
5079 return error_mark_node
;
5083 if (TREE_CODE (type
) == FUNCTION_TYPE
5084 || TREE_CODE (type
) == METHOD_TYPE
)
5086 cp_error ("casting to function type `%T'", type
);
5087 return error_mark_node
;
5090 if (IS_SIGNATURE (type
))
5092 error ("cast specifies signature type");
5093 return error_mark_node
;
5096 /* If there's only one function in the overloaded space,
5098 if (TREE_CODE (value
) == TREE_LIST
5099 && TREE_CHAIN (value
) == NULL_TREE
)
5100 value
= TREE_VALUE (value
);
5102 if (TREE_CODE (type
) == VOID_TYPE
)
5103 value
= build1 (CONVERT_EXPR
, type
, value
);
5104 else if (TREE_TYPE (value
) == NULL_TREE
5105 || type_unknown_p (value
))
5107 value
= instantiate_type (type
, value
, 1);
5109 if (value
== error_mark_node
)
5110 return error_mark_node
;
5117 /* Convert functions and arrays to pointers and
5118 convert references to their expanded types,
5119 but don't convert any other types. */
5120 if (TREE_CODE (TREE_TYPE (value
)) == FUNCTION_TYPE
5121 || TREE_CODE (TREE_TYPE (value
)) == METHOD_TYPE
5122 || TREE_CODE (TREE_TYPE (value
)) == ARRAY_TYPE
5123 || TREE_CODE (TREE_TYPE (value
)) == REFERENCE_TYPE
)
5124 value
= default_conversion (value
);
5125 otype
= TREE_TYPE (value
);
5127 /* Optionally warn about potentially worrisome casts. */
5130 && TREE_CODE (type
) == POINTER_TYPE
5131 && TREE_CODE (otype
) == POINTER_TYPE
)
5133 /* For C++ we make these regular warnings, rather than
5134 softening them into pedwarns. */
5135 if (TYPE_VOLATILE (TREE_TYPE (otype
))
5136 && ! TYPE_VOLATILE (TREE_TYPE (type
)))
5137 warning ("cast discards `volatile' from pointer target type");
5138 if (TYPE_READONLY (TREE_TYPE (otype
))
5139 && ! TYPE_READONLY (TREE_TYPE (type
)))
5140 warning ("cast discards `const' from pointer target type");
5143 /* Warn about possible alignment problems. */
5144 if (STRICT_ALIGNMENT
&& warn_cast_align
5145 && TREE_CODE (type
) == POINTER_TYPE
5146 && TREE_CODE (otype
) == POINTER_TYPE
5147 && TREE_CODE (TREE_TYPE (otype
)) != VOID_TYPE
5148 && TREE_CODE (TREE_TYPE (otype
)) != FUNCTION_TYPE
5149 && TYPE_ALIGN (TREE_TYPE (type
)) > TYPE_ALIGN (TREE_TYPE (otype
)))
5150 warning ("cast increases required alignment of target type");
5153 if (TREE_CODE (type
) == INTEGER_TYPE
5154 && TREE_CODE (otype
) == POINTER_TYPE
5155 && TYPE_PRECISION (type
) != TYPE_PRECISION (otype
))
5156 warning ("cast from pointer to integer of different size");
5158 if (TREE_CODE (type
) == POINTER_TYPE
5159 && TREE_CODE (otype
) == INTEGER_TYPE
5160 && TYPE_PRECISION (type
) != TYPE_PRECISION (otype
)
5161 /* Don't warn about converting 0 to pointer,
5162 provided the 0 was explicit--not cast or made by folding. */
5163 && !(TREE_CODE (value
) == INTEGER_CST
&& integer_zerop (value
)))
5164 warning ("cast to pointer from integer of different size");
5167 flag
= allow_nonconverting
? CONV_NONCONVERTING
: 0;
5169 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5170 value
= (convert_from_reference
5171 (convert_to_reference (type
, value
, CONV_OLD_CONVERT
|flag
,
5172 LOOKUP_COMPLAIN
, NULL_TREE
)));
5177 if (TREE_READONLY_DECL_P (value
))
5178 value
= decl_constant_value (value
);
5181 value
= convert_force (type
, value
, flag
);
5183 /* Ignore any integer overflow caused by the cast. */
5184 if (TREE_CODE (value
) == INTEGER_CST
)
5186 TREE_OVERFLOW (value
) = TREE_OVERFLOW (ovalue
);
5187 TREE_CONSTANT_OVERFLOW (value
) = TREE_CONSTANT_OVERFLOW (ovalue
);
5192 /* Always produce some operator for an explicit cast,
5193 so we can tell (for -pedantic) that the cast is no lvalue.
5194 Also, pedantically, don't let (void *) (FOO *) 0 be a null
5195 pointer constant. */
5198 && TREE_CODE (value
) == INTEGER_CST
5199 && TREE_CODE (expr
) == INTEGER_CST
5200 && TREE_CODE (TREE_TYPE (expr
)) != INTEGER_TYPE
))
5201 value
= non_lvalue (value
);
5207 /* Build an assignment expression of lvalue LHS from value RHS.
5209 In C++, if the left hand side of the assignment is a REFERENCE_TYPE,
5210 that reference becomes deferenced down to it base type. */
5212 /* Return a reference to the BASE_INDEX part of EXPR. TYPE is
5213 the type to which BASE_INDEX applies. */
5215 get_base_ref (type
, base_index
, expr
)
5220 tree binfos
= TYPE_BINFO_BASETYPES (type
);
5221 tree base_binfo
= TREE_VEC_ELT (binfos
, base_index
);
5224 if (TREE_CODE (expr
) == ARRAY_REF
5225 || ! BINFO_OFFSET_ZEROP (base_binfo
)
5226 || TREE_VIA_VIRTUAL (base_binfo
)
5227 || TYPE_MODE (type
) != TYPE_MODE (BINFO_TYPE (base_binfo
)))
5229 tree addr
= build_unary_op (ADDR_EXPR
, expr
, 0);
5230 ref
= build_indirect_ref (convert_pointer_to (base_binfo
, addr
),
5235 ref
= copy_node (expr
);
5236 TREE_TYPE (ref
) = BINFO_TYPE (base_binfo
);
5241 /* Build an assignment expression of lvalue LHS from value RHS.
5242 MODIFYCODE is the code for a binary operator that we use
5243 to combine the old value of LHS with RHS to get the new value.
5244 Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.
5246 C++: If MODIFYCODE is INIT_EXPR, then leave references unbashed.
5248 `build_modify_expr_1' implements recursive part of memberwise
5249 assignment operation. */
5251 build_modify_expr_1 (lhs
, modifycode
, rhs
, basetype_path
)
5253 enum tree_code modifycode
;
5256 register tree result
;
5258 tree lhstype
= TREE_TYPE (lhs
);
5259 tree olhstype
= lhstype
;
5261 /* Avoid duplicate error messages from operands that had errors. */
5262 if (TREE_CODE (lhs
) == ERROR_MARK
|| TREE_CODE (rhs
) == ERROR_MARK
)
5263 return error_mark_node
;
5265 /* If a binary op has been requested, combine the old LHS value with the RHS
5266 producing the value we should actually store into the LHS. */
5268 if (modifycode
== INIT_EXPR
)
5270 else if (modifycode
== NOP_EXPR
)
5272 /* must deal with overloading of `operator=' here. */
5273 if (TREE_CODE (lhstype
) == REFERENCE_TYPE
)
5274 lhstype
= TREE_TYPE (lhstype
);
5280 lhs
= stabilize_reference (lhs
);
5281 newrhs
= build_binary_op (modifycode
, lhs
, rhs
, 1);
5282 modifycode
= NOP_EXPR
;
5285 /* If storing into a structure or union member,
5286 it has probably been given type `int'.
5287 Compute the type that would go with
5288 the actual amount of storage the member occupies. */
5290 if (TREE_CODE (lhs
) == COMPONENT_REF
5291 && (TREE_CODE (lhstype
) == INTEGER_TYPE
5292 || TREE_CODE (lhstype
) == REAL_TYPE
5293 || TREE_CODE (lhstype
) == ENUMERAL_TYPE
))
5294 lhstype
= TREE_TYPE (get_unwidened (lhs
, 0));
5296 /* C++: The semantics of C++ differ from those of C when an
5297 assignment of an aggregate is desired. Assignment in C++ is
5298 now defined as memberwise assignment of non-static members
5299 and base class objects. This rule applies recursively
5300 until a member of a built-in type is found.
5302 Also, we cannot do a bit-wise copy of aggregates which
5303 contain virtual function table pointers. Those
5304 pointer values must be preserved through the copy.
5305 However, this is handled in expand_expr, and not here.
5306 This is because much better code can be generated at
5307 that stage than this one. */
5308 if (TREE_CODE (lhstype
) == RECORD_TYPE
5309 && TYPE_LANG_SPECIFIC (lhstype
)
5310 && TYPE_MAIN_VARIANT (lhstype
) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs
)))
5315 /* Perform operation on object. */
5316 if (modifycode
== INIT_EXPR
&& TYPE_HAS_INIT_REF (lhstype
))
5318 result
= build_method_call (lhs
, constructor_name_full (lhstype
),
5319 build_tree_list (NULL_TREE
, rhs
),
5320 basetype_path
, LOOKUP_NORMAL
);
5321 return build_indirect_ref (result
, NULL_PTR
);
5323 else if (modifycode
== NOP_EXPR
)
5325 /* `operator=' is not an inheritable operator; see 13.4.3. */
5326 if (TYPE_LANG_SPECIFIC (lhstype
) && TYPE_HAS_ASSIGNMENT (lhstype
))
5328 result
= build_opfncall (MODIFY_EXPR
, LOOKUP_NORMAL
,
5329 lhs
, rhs
, make_node (NOP_EXPR
));
5330 if (result
== NULL_TREE
)
5331 return error_mark_node
;
5336 if (TYPE_USES_VIRTUAL_BASECLASSES (lhstype
)
5337 || (modifycode
== NOP_EXPR
&& TYPE_GETS_ASSIGNMENT (lhstype
))
5338 || (modifycode
== INIT_EXPR
&& TYPE_GETS_INIT_REF (lhstype
)))
5340 tree binfos
= BINFO_BASETYPES (TYPE_BINFO (lhstype
));
5343 if (binfos
!= NULL_TREE
)
5344 /* Perform operation on each member, depth-first, left-right. */
5345 for (i
= 0; i
<= TREE_VEC_LENGTH (binfos
)-1; i
++)
5347 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
5348 tree base_lhs
, base_rhs
;
5351 /* Assignments from virtual baseclasses handled elsewhere. */
5352 if (TREE_VIA_VIRTUAL (base_binfo
))
5355 base_lhs
= get_base_ref (lhstype
, i
, lhs
);
5356 base_rhs
= get_base_ref (lhstype
, i
, newrhs
);
5358 BINFO_INHERITANCE_CHAIN (base_binfo
) = basetype_path
;
5360 = build_modify_expr_1 (base_lhs
, modifycode
, base_rhs
,
5363 /* We either get back a compound stmt, or a simple one. */
5364 if (new_result
&& TREE_CODE (new_result
) == TREE_LIST
)
5365 new_result
= build_compound_expr (new_result
);
5366 result
= tree_cons (NULL_TREE
, new_result
, result
);
5369 for (elt
= TYPE_FIELDS (lhstype
); elt
; elt
= TREE_CHAIN (elt
))
5371 tree vbases
= NULL_TREE
;
5372 tree elt_lhs
, elt_rhs
;
5374 if (TREE_CODE (elt
) != FIELD_DECL
)
5377 && (VFIELD_NAME_P (DECL_NAME (elt
))
5378 || VBASE_NAME_P (DECL_NAME (elt
))))
5381 if (TREE_READONLY (elt
)
5382 || TREE_CODE (TREE_TYPE (elt
)) == REFERENCE_TYPE
)
5384 cp_error ("cannot generate default `%T::operator ='",
5386 if (TREE_CODE (TREE_TYPE (elt
)) == REFERENCE_TYPE
)
5387 cp_error_at ("because member `%#D' is a reference", elt
);
5389 cp_error_at ("because member `%#D' is const", elt
);
5391 return error_mark_node
;
5394 if (IS_AGGR_TYPE (TREE_TYPE (elt
))
5395 && TYPE_LANG_SPECIFIC (TREE_TYPE (elt
)))
5396 vbases
= CLASSTYPE_VBASECLASSES (TREE_TYPE (elt
));
5398 elt_lhs
= build (COMPONENT_REF
, TREE_TYPE (elt
), lhs
, elt
);
5399 elt_rhs
= build (COMPONENT_REF
, TREE_TYPE (elt
), newrhs
, elt
);
5400 /* It is not always safe to go through `build_modify_expr_1'
5401 when performing element-wise copying. This is because
5402 an element may be of ARRAY_TYPE, which will not
5403 be properly copied as a naked element. */
5404 if (TREE_CODE (TREE_TYPE (elt
)) == RECORD_TYPE
5405 && TYPE_LANG_SPECIFIC (TREE_TYPE (elt
)))
5406 basetype_path
= TYPE_BINFO (TREE_TYPE (elt
));
5410 tree elt_lhs_addr
= build_unary_op (ADDR_EXPR
, elt_lhs
, 0);
5411 tree elt_rhs_addr
= build_unary_op (ADDR_EXPR
, elt_rhs
, 0);
5413 elt_lhs_addr
= convert_pointer_to (vbases
, elt_lhs_addr
);
5414 elt_rhs_addr
= convert_pointer_to (vbases
, elt_rhs_addr
);
5416 = tree_cons (NULL_TREE
,
5418 (build_indirect_ref (elt_lhs_addr
, NULL_PTR
),
5420 build_indirect_ref (elt_rhs_addr
, NULL_PTR
),
5423 if (TREE_VALUE (result
) == error_mark_node
)
5424 return error_mark_node
;
5425 vbases
= TREE_CHAIN (vbases
);
5427 elt_lhs
= build_modify_expr_1 (elt_lhs
, modifycode
, elt_rhs
,
5429 result
= tree_cons (NULL_TREE
, elt_lhs
, result
);
5433 return build_compound_expr (result
);
5434 /* No fields to move. */
5435 return integer_zero_node
;
5439 result
= build (modifycode
== NOP_EXPR
? MODIFY_EXPR
: INIT_EXPR
,
5440 void_type_node
, lhs
, rhs
);
5441 TREE_SIDE_EFFECTS (result
) = 1;
5446 result
= build_modify_expr (lhs
, modifycode
, newrhs
);
5447 /* ARRAY_TYPEs cannot be converted to anything meaningful,
5448 and leaving it there screws up `build_compound_expr' when
5449 it tries to defaultly convert everything. */
5450 if (TREE_CODE (TREE_TYPE (result
)) == ARRAY_TYPE
)
5451 TREE_TYPE (result
) = void_type_node
;
5456 /* Taken from expr.c:
5457 Subroutine of expand_expr:
5458 record the non-copied parts (LIST) of an expr (LHS), and return a list
5459 which specifies the initial values of these parts. */
5462 init_noncopied_parts (lhs
, list
)
5469 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
5470 if (TREE_CODE (TREE_VALUE (tail
)) == TREE_LIST
)
5471 parts
= chainon (parts
, init_noncopied_parts (lhs
, TREE_VALUE (tail
)));
5474 tree part
= TREE_VALUE (tail
);
5475 tree part_type
= TREE_TYPE (part
);
5476 tree to_be_initialized
= build (COMPONENT_REF
, part_type
, lhs
, part
);
5477 parts
= tree_cons (TREE_PURPOSE (tail
), to_be_initialized
, parts
);
5483 expand_target_expr (t
)
5486 tree xval
= make_node (RTL_EXPR
);
5489 do_pending_stack_adjust ();
5490 start_sequence_for_rtl_expr (xval
);
5492 rtxval
= expand_expr (t
, NULL
, VOIDmode
, 0);
5493 do_pending_stack_adjust ();
5494 TREE_SIDE_EFFECTS (xval
) = 1;
5495 RTL_EXPR_SEQUENCE (xval
) = get_insns ();
5497 RTL_EXPR_RTL (xval
) = rtxval
;
5498 TREE_TYPE (xval
) = TREE_TYPE (t
);
5502 /* Build an assignment expression of lvalue LHS from value RHS.
5503 MODIFYCODE is the code for a binary operator that we use
5504 to combine the old value of LHS with RHS to get the new value.
5505 Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.
5507 C++: If MODIFYCODE is INIT_EXPR, then leave references unbashed.
5510 build_modify_expr (lhs
, modifycode
, rhs
)
5512 enum tree_code modifycode
;
5515 register tree result
;
5517 tree lhstype
= TREE_TYPE (lhs
);
5518 tree olhstype
= lhstype
;
5521 /* Avoid duplicate error messages from operands that had errors. */
5522 if (TREE_CODE (lhs
) == ERROR_MARK
|| TREE_CODE (rhs
) == ERROR_MARK
)
5523 return error_mark_node
;
5525 /* Types that aren't fully specified cannot be used in assignments. */
5526 lhs
= require_complete_type (lhs
);
5528 /* Decide early if we are going to protect RHS from GC
5529 before assigning it to LHS. */
5530 if (type_needs_gc_entry (TREE_TYPE (rhs
))
5531 && ! value_safe_from_gc (lhs
, rhs
))
5532 rhs
= protect_value_from_gc (lhs
, rhs
);
5536 /* Handle assignment to signature pointers/refs. */
5538 if (TYPE_LANG_SPECIFIC (lhstype
) &&
5539 (IS_SIGNATURE_POINTER (lhstype
) || IS_SIGNATURE_REFERENCE (lhstype
)))
5541 return build_signature_pointer_constructor (lhs
, rhs
);
5544 /* Handle control structure constructs used as "lvalues". */
5546 switch (TREE_CODE (lhs
))
5548 /* Handle --foo = 5; as these are valid constructs in C++ */
5549 case PREDECREMENT_EXPR
:
5550 case PREINCREMENT_EXPR
:
5551 if (TREE_SIDE_EFFECTS (TREE_OPERAND (lhs
, 0)))
5552 lhs
= build (TREE_CODE (lhs
), TREE_TYPE (lhs
),
5553 stabilize_reference (TREE_OPERAND (lhs
, 0)));
5554 return build (COMPOUND_EXPR
, lhstype
,
5556 build_modify_expr (TREE_OPERAND (lhs
, 0),
5559 /* Handle (a, b) used as an "lvalue". */
5561 newrhs
= build_modify_expr (TREE_OPERAND (lhs
, 1),
5563 if (TREE_CODE (newrhs
) == ERROR_MARK
)
5564 return error_mark_node
;
5565 return build (COMPOUND_EXPR
, lhstype
,
5566 TREE_OPERAND (lhs
, 0), newrhs
);
5569 newrhs
= build_modify_expr (TREE_OPERAND (lhs
, 0), modifycode
, rhs
);
5570 if (TREE_CODE (newrhs
) == ERROR_MARK
)
5571 return error_mark_node
;
5572 return build (COMPOUND_EXPR
, lhstype
, lhs
, newrhs
);
5574 /* Handle (a ? b : c) used as an "lvalue". */
5576 rhs
= save_expr (rhs
);
5578 /* Produce (a ? (b = rhs) : (c = rhs))
5579 except that the RHS goes through a save-expr
5580 so the code to compute it is only emitted once. */
5582 = build_conditional_expr (TREE_OPERAND (lhs
, 0),
5583 build_modify_expr (convert (TREE_TYPE (lhs
), TREE_OPERAND (lhs
, 1)),
5585 build_modify_expr (convert (TREE_TYPE (lhs
), TREE_OPERAND (lhs
, 2)),
5587 if (TREE_CODE (cond
) == ERROR_MARK
)
5589 /* Make sure the code to compute the rhs comes out
5590 before the split. */
5591 return build (COMPOUND_EXPR
, TREE_TYPE (lhs
),
5592 /* Case to void to suppress warning
5593 from warn_if_unused_value. */
5594 convert (void_type_node
, rhs
), cond
);
5598 if (TREE_CODE (lhs
) == OFFSET_REF
)
5600 if (TREE_OPERAND (lhs
, 0) == NULL_TREE
)
5602 /* Static class member? */
5603 tree member
= TREE_OPERAND (lhs
, 1);
5604 if (TREE_CODE (member
) == VAR_DECL
)
5608 compiler_error ("invalid static class member");
5609 return error_mark_node
;
5613 lhs
= resolve_offset_ref (lhs
);
5615 olhstype
= lhstype
= TREE_TYPE (lhs
);
5618 if (TREE_CODE (lhstype
) == REFERENCE_TYPE
5619 && modifycode
!= INIT_EXPR
)
5621 lhs
= convert_from_reference (lhs
);
5622 olhstype
= lhstype
= TREE_TYPE (lhs
);
5625 /* If a binary op has been requested, combine the old LHS value with the RHS
5626 producing the value we should actually store into the LHS. */
5628 if (modifycode
== INIT_EXPR
)
5630 if (! IS_AGGR_TYPE (lhstype
))
5631 /* Do the default thing */;
5632 else if (! TYPE_HAS_CONSTRUCTOR (lhstype
))
5633 cp_error ("`%T' has no constructors", lhstype
);
5634 else if (TYPE_HAS_TRIVIAL_INIT_REF (lhstype
)
5635 && TYPE_MAIN_VARIANT (lhstype
) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs
)))
5636 /* Do the default thing */;
5639 result
= build_method_call (lhs
, constructor_name_full (lhstype
),
5640 build_tree_list (NULL_TREE
, rhs
),
5641 NULL_TREE
, LOOKUP_NORMAL
);
5642 if (result
== NULL_TREE
)
5643 return error_mark_node
;
5647 else if (modifycode
== NOP_EXPR
)
5650 /* `operator=' is not an inheritable operator. */
5651 if (! IS_AGGR_TYPE (lhstype
))
5652 /* Do the default thing */;
5653 else if (! TYPE_HAS_ASSIGNMENT (lhstype
))
5654 cp_error ("`%T' does not define operator=", lhstype
);
5655 else if (TYPE_HAS_TRIVIAL_ASSIGN_REF (lhstype
)
5656 && TYPE_MAIN_VARIANT (lhstype
) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs
)))
5659 /* If we care about this, do overload resolution. */
5660 build_opfncall (MODIFY_EXPR
, LOOKUP_NORMAL
,
5661 lhs
, rhs
, make_node (NOP_EXPR
));
5663 /* Do the default thing */;
5667 result
= build_opfncall (MODIFY_EXPR
, LOOKUP_NORMAL
,
5668 lhs
, rhs
, make_node (NOP_EXPR
));
5669 if (result
== NULL_TREE
)
5670 return error_mark_node
;
5674 /* Treat `operator=' as an inheritable operator. */
5675 if (TYPE_LANG_SPECIFIC (lhstype
) && TYPE_GETS_ASSIGNMENT (lhstype
))
5677 tree orig_lhstype
= lhstype
;
5678 while (! TYPE_HAS_ASSIGNMENT (lhstype
))
5680 int i
, n_baseclasses
= CLASSTYPE_N_BASECLASSES (lhstype
);
5681 tree basetype
= NULL_TREE
;
5682 for (i
= 0; i
< n_baseclasses
; i
++)
5683 if (TYPE_GETS_ASSIGNMENT (TYPE_BINFO_BASETYPE (lhstype
, i
)))
5685 if (basetype
!= NULL_TREE
)
5687 message_2_types (error
, "base classes `%s' and `%s' both have operator ='",
5689 TYPE_BINFO_BASETYPE (lhstype
, i
));
5690 return error_mark_node
;
5692 basetype
= TYPE_BINFO_BASETYPE (lhstype
, i
);
5696 if (orig_lhstype
!= lhstype
)
5698 lhs
= build_indirect_ref (convert_pointer_to (lhstype
,
5699 build_unary_op (ADDR_EXPR
, lhs
, 0)), NULL_PTR
);
5700 if (lhs
== error_mark_node
)
5702 cp_error ("conversion to private basetype `%T'", lhstype
);
5703 return error_mark_node
;
5706 result
= build_opfncall (MODIFY_EXPR
, LOOKUP_NORMAL
,
5707 lhs
, rhs
, make_node (NOP_EXPR
));
5708 if (result
== NULL_TREE
)
5709 return error_mark_node
;
5715 else if (PROMOTES_TO_AGGR_TYPE (lhstype
, REFERENCE_TYPE
))
5717 /* This case must convert to some sort of lvalue that
5718 can participate in an op= operation. */
5721 if (build_default_binary_type_conversion (modifycode
, &lhs_tmp
, &rhs_tmp
))
5723 lhs
= stabilize_reference (lhs_tmp
);
5724 /* Forget is was ever anything else. */
5725 olhstype
= lhstype
= TREE_TYPE (lhs
);
5726 newrhs
= build_binary_op (modifycode
, lhs
, rhs_tmp
, 1);
5730 cp_error ("no match for `%O(%#T, %#T)'", modifycode
,
5731 TREE_TYPE (lhs
), TREE_TYPE (rhs
));
5732 return error_mark_node
;
5737 lhs
= stabilize_reference (lhs
);
5738 newrhs
= build_binary_op (modifycode
, lhs
, rhs
, 1);
5741 /* Handle a cast used as an "lvalue".
5742 We have already performed any binary operator using the value as cast.
5743 Now convert the result to the cast type of the lhs,
5744 and then true type of the lhs and store it there;
5745 then convert result back to the cast type to be the value
5746 of the assignment. */
5748 switch (TREE_CODE (lhs
))
5753 case FIX_TRUNC_EXPR
:
5754 case FIX_FLOOR_EXPR
:
5755 case FIX_ROUND_EXPR
:
5757 if (TREE_CODE (TREE_TYPE (newrhs
)) == ARRAY_TYPE
5758 || TREE_CODE (TREE_TYPE (newrhs
)) == FUNCTION_TYPE
5759 || TREE_CODE (TREE_TYPE (newrhs
)) == METHOD_TYPE
5760 || TREE_CODE (TREE_TYPE (newrhs
)) == OFFSET_TYPE
)
5761 newrhs
= default_conversion (newrhs
);
5763 tree inner_lhs
= TREE_OPERAND (lhs
, 0);
5765 if (! lvalue_p (lhs
) && pedantic
)
5766 pedwarn ("cast to non-reference type used as lvalue");
5768 result
= build_modify_expr (inner_lhs
, NOP_EXPR
,
5769 convert (TREE_TYPE (inner_lhs
),
5770 convert (lhstype
, newrhs
)));
5771 if (TREE_CODE (result
) == ERROR_MARK
)
5773 return convert (TREE_TYPE (lhs
), result
);
5777 /* Now we have handled acceptable kinds of LHS that are not truly lvalues.
5778 Reject anything strange now. */
5780 if (!lvalue_or_else (lhs
, "assignment"))
5781 return error_mark_node
;
5783 GNU_xref_assign (lhs
);
5785 /* Warn about storing in something that is `const'. */
5786 /* For C++, don't warn if this is initialization. */
5787 if (modifycode
!= INIT_EXPR
5788 /* For assignment to `const' signature pointer/reference fields,
5789 don't warn either, we already printed a better message before. */
5790 && ! (TREE_CODE (lhs
) == COMPONENT_REF
5791 && (IS_SIGNATURE_POINTER (TREE_TYPE (TREE_OPERAND (lhs
, 0)))
5792 || IS_SIGNATURE_REFERENCE (TREE_TYPE (TREE_OPERAND (lhs
, 0)))))
5793 && (TREE_READONLY (lhs
) || TYPE_READONLY (lhstype
)
5794 || ((TREE_CODE (lhstype
) == RECORD_TYPE
5795 || TREE_CODE (lhstype
) == UNION_TYPE
)
5796 && C_TYPE_FIELDS_READONLY (lhstype
))
5797 || (TREE_CODE (lhstype
) == REFERENCE_TYPE
5798 && TYPE_READONLY (TREE_TYPE (lhstype
)))))
5799 readonly_error (lhs
, "assignment", 0);
5801 /* If storing into a structure or union member,
5802 it has probably been given type `int'.
5803 Compute the type that would go with
5804 the actual amount of storage the member occupies. */
5806 if (TREE_CODE (lhs
) == COMPONENT_REF
5807 && (TREE_CODE (lhstype
) == INTEGER_TYPE
5808 || TREE_CODE (lhstype
) == REAL_TYPE
5809 || TREE_CODE (lhstype
) == ENUMERAL_TYPE
))
5811 lhstype
= TREE_TYPE (get_unwidened (lhs
, 0));
5813 /* If storing in a field that is in actuality a short or narrower
5814 than one, we must store in the field in its actual type. */
5816 if (lhstype
!= TREE_TYPE (lhs
))
5818 lhs
= copy_node (lhs
);
5819 TREE_TYPE (lhs
) = lhstype
;
5823 /* check to see if there is an assignment to `this' */
5824 if (lhs
== current_class_decl
)
5826 if (flag_this_is_variable
> 0
5827 && DECL_NAME (current_function_decl
) != NULL_TREE
5828 && (DECL_NAME (current_function_decl
)
5829 != constructor_name (current_class_type
)))
5830 warning ("assignment to `this' not in constructor or destructor");
5831 current_function_just_assigned_this
= 1;
5834 /* The TREE_TYPE of RHS may be TYPE_UNKNOWN. This can happen
5835 when the type of RHS is not yet known, i.e. its type
5836 is inherited from LHS. */
5837 rhs
= require_instantiated_type (lhstype
, newrhs
, error_mark_node
);
5838 if (rhs
== error_mark_node
)
5839 return error_mark_node
;
5842 if (modifycode
!= INIT_EXPR
)
5844 /* Make modifycode now either a NOP_EXPR or an INIT_EXPR. */
5845 modifycode
= NOP_EXPR
;
5846 /* Reference-bashing */
5847 if (TREE_CODE (lhstype
) == REFERENCE_TYPE
)
5849 tree tmp
= convert_from_reference (lhs
);
5850 lhstype
= TREE_TYPE (tmp
);
5851 if (TYPE_SIZE (lhstype
) == 0)
5853 incomplete_type_error (lhs
, lhstype
);
5854 return error_mark_node
;
5859 if (TREE_CODE (TREE_TYPE (newrhs
)) == REFERENCE_TYPE
)
5861 tree tmp
= convert_from_reference (newrhs
);
5862 if (TYPE_SIZE (TREE_TYPE (tmp
)) == 0)
5864 incomplete_type_error (newrhs
, TREE_TYPE (tmp
));
5865 return error_mark_node
;
5871 if (TREE_SIDE_EFFECTS (lhs
))
5872 lhs
= stabilize_reference (lhs
);
5873 if (TREE_SIDE_EFFECTS (newrhs
))
5874 newrhs
= stabilize_reference (newrhs
);
5877 /* This is now done by generating X(X&) and operator=(X&). */
5878 /* C++: The semantics of C++ differ from those of C when an
5879 assignment of an aggregate is desired. Assignment in C++ is
5880 now defined as memberwise assignment of non-static members
5881 and base class objects. This rule applies recursively
5882 until a member of a built-in type is found.
5884 Also, we cannot do a bit-wise copy of aggregates which
5885 contain virtual function table pointers. Those
5886 pointer values must be preserved through the copy.
5887 However, this is handled in expand_expr, and not here.
5888 This is because much better code can be generated at
5889 that stage than this one. */
5890 if (TREE_CODE (lhstype
) == RECORD_TYPE
5891 && ! TYPE_PTRMEMFUNC_P (lhstype
)
5892 && (TYPE_MAIN_VARIANT (lhstype
) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs
))
5893 || (TREE_CODE (TREE_TYPE (newrhs
)) == RECORD_TYPE
5894 && UNIQUELY_DERIVED_FROM_P (lhstype
, TREE_TYPE (newrhs
)))))
5896 tree vbases
= CLASSTYPE_VBASECLASSES (lhstype
);
5897 tree lhs_addr
= build_unary_op (ADDR_EXPR
, lhs
, 0);
5900 /* Memberwise assignment would cause NEWRHS to be
5901 evaluated for every member that gets assigned.
5902 By wrapping side-effecting exprs in a SAVE_EXPR,
5903 NEWRHS will only be evaluated once. */
5904 if (IS_AGGR_TYPE (TREE_TYPE (newrhs
))
5905 && TREE_SIDE_EFFECTS (newrhs
)
5906 /* This are things we don't have to save. */
5907 && TREE_CODE (newrhs
) != COND_EXPR
5908 && TREE_CODE (newrhs
) != TARGET_EXPR
5909 && TREE_CODE (newrhs
) != WITH_CLEANUP_EXPR
)
5910 /* Call `break_out_cleanups' on NEWRHS in case there are cleanups.
5911 If NEWRHS is a CALL_EXPR that needs a cleanup, failure to do so
5912 will result in expand_expr expanding the call without knowing
5913 that it should run the cleanup. */
5914 newrhs
= save_expr (break_out_cleanups (newrhs
));
5916 if (TREE_CODE (newrhs
) == COND_EXPR
)
5917 rhs_addr
= rationalize_conditional_expr (ADDR_EXPR
, newrhs
);
5919 rhs_addr
= build_unary_op (ADDR_EXPR
, newrhs
, 0);
5921 result
= tree_cons (NULL_TREE
,
5922 convert (build_reference_type (lhstype
), lhs
),
5925 if (! comptypes (TREE_TYPE (lhs_addr
), TREE_TYPE (rhs_addr
), 1))
5926 rhs_addr
= convert_pointer_to (TREE_TYPE (TREE_TYPE (lhs_addr
)), rhs_addr
);
5928 tree noncopied_parts
= NULL_TREE
;
5930 if (TYPE_NONCOPIED_PARTS (lhstype
) != 0)
5931 noncopied_parts
= init_noncopied_parts (lhs
,
5932 TYPE_NONCOPIED_PARTS (lhstype
));
5933 while (noncopied_parts
!= 0)
5935 result
= tree_cons (NULL_TREE
,
5936 build_modify_expr (convert (ptr_type_node
, TREE_VALUE (noncopied_parts
)),
5938 TREE_PURPOSE (noncopied_parts
)),
5940 noncopied_parts
= TREE_CHAIN (noncopied_parts
);
5943 /* Once we have our hands on an address, we must change NEWRHS
5944 to work from there. Otherwise we can get multiple evaluations
5946 if (TREE_CODE (newrhs
) != SAVE_EXPR
)
5947 newrhs
= build_indirect_ref (rhs_addr
, NULL_PTR
);
5951 tree elt_lhs
= convert_pointer_to (vbases
, lhs_addr
);
5952 tree elt_rhs
= convert_pointer_to (vbases
, rhs_addr
);
5954 = tree_cons (NULL_TREE
,
5955 build_modify_expr_1 (build_indirect_ref (elt_lhs
, NULL_PTR
),
5957 build_indirect_ref (elt_rhs
, NULL_PTR
),
5958 TYPE_BINFO (lhstype
)),
5960 if (TREE_VALUE (result
) == error_mark_node
)
5961 return error_mark_node
;
5962 vbases
= TREE_CHAIN (vbases
);
5964 result
= tree_cons (NULL_TREE
,
5965 build_modify_expr_1 (lhs
,
5968 TYPE_BINFO (lhstype
)),
5970 return build_compound_expr (result
);
5974 /* Convert new value to destination type. */
5976 if (TREE_CODE (lhstype
) == ARRAY_TYPE
)
5980 if (! comptypes (lhstype
, TREE_TYPE (rhs
), 0))
5982 cp_error ("incompatible types in assignment of `%T' to `%T'",
5983 TREE_TYPE (rhs
), lhstype
);
5984 return error_mark_node
;
5987 /* Allow array assignment in compiler-generated code. */
5988 if (pedantic
&& ! DECL_ARTIFICIAL (current_function_decl
))
5989 pedwarn ("ANSI C++ forbids assignment of arrays");
5991 /* Have to wrap this in RTL_EXPR for two cases:
5992 in base or member initialization and if we
5993 are a branch of a ?: operator. Since we
5994 can't easily know the latter, just do it always. */
5996 result
= make_node (RTL_EXPR
);
5998 TREE_TYPE (result
) = void_type_node
;
5999 do_pending_stack_adjust ();
6000 start_sequence_for_rtl_expr (result
);
6002 /* As a matter of principle, `start_sequence' should do this. */
6005 from_array
= TREE_CODE (TREE_TYPE (newrhs
)) == ARRAY_TYPE
6006 ? 1 + (modifycode
!= INIT_EXPR
): 0;
6007 expand_vec_init (lhs
, lhs
, array_type_nelts (lhstype
), newrhs
,
6010 do_pending_stack_adjust ();
6012 TREE_SIDE_EFFECTS (result
) = 1;
6013 RTL_EXPR_SEQUENCE (result
) = get_insns ();
6014 RTL_EXPR_RTL (result
) = const0_rtx
;
6019 if (modifycode
== INIT_EXPR
)
6021 newrhs
= convert_for_initialization (lhs
, lhstype
, newrhs
, LOOKUP_NORMAL
,
6022 "assignment", NULL_TREE
, 0);
6023 if (lhs
== DECL_RESULT (current_function_decl
))
6025 if (DECL_INITIAL (lhs
))
6026 warning ("return value from function receives multiple initializations");
6027 DECL_INITIAL (lhs
) = newrhs
;
6033 if (IS_AGGR_TYPE (lhstype
))
6035 if (result
= build_opfncall (MODIFY_EXPR
,
6036 LOOKUP_NORMAL
, lhs
, newrhs
,
6037 make_node (NOP_EXPR
)))
6041 /* Avoid warnings on enum bit fields. */
6042 if (TREE_CODE (olhstype
) == ENUMERAL_TYPE
6043 && TREE_CODE (lhstype
) == INTEGER_TYPE
)
6045 newrhs
= convert_for_assignment (olhstype
, newrhs
, "assignment",
6047 newrhs
= convert_force (lhstype
, newrhs
, 0);
6050 newrhs
= convert_for_assignment (lhstype
, newrhs
, "assignment",
6052 if (TREE_CODE (newrhs
) == CALL_EXPR
6053 && TYPE_NEEDS_CONSTRUCTING (lhstype
))
6054 newrhs
= build_cplus_new (lhstype
, newrhs
, 0);
6056 /* Can't initialize directly from a TARGET_EXPR, since that would
6057 cause the lhs to be constructed twice. So we force the
6058 TARGET_EXPR to be expanded. expand_expr should really do this
6060 if (TREE_CODE (newrhs
) == TARGET_EXPR
)
6061 newrhs
= expand_target_expr (newrhs
);
6064 if (TREE_CODE (newrhs
) == ERROR_MARK
)
6065 return error_mark_node
;
6067 if (TREE_CODE (newrhs
) == COND_EXPR
)
6070 tree cond
= TREE_OPERAND (newrhs
, 0);
6072 if (TREE_SIDE_EFFECTS (lhs
))
6073 cond
= build_compound_expr (tree_cons
6075 build_tree_list (NULL_TREE
, cond
)));
6077 /* Cannot have two identical lhs on this one tree (result) as preexpand
6078 calls will rip them out and fill in RTL for them, but when the
6079 rtl is generated, the calls will only be in the first side of the
6080 condition, not on both, or before the conditional jump! (mrs) */
6081 lhs1
= break_out_calls (lhs
);
6084 /* If there's no change, the COND_EXPR behaves like any other rhs. */
6085 result
= build (modifycode
== NOP_EXPR
? MODIFY_EXPR
: INIT_EXPR
,
6086 lhstype
, lhs
, newrhs
);
6089 tree result_type
= TREE_TYPE (newrhs
);
6090 /* We have to convert each arm to the proper type because the
6091 types may have been munged by constant folding. */
6093 = build (COND_EXPR
, result_type
, cond
,
6094 build_modify_expr (lhs
, modifycode
,
6095 convert (result_type
,
6096 TREE_OPERAND (newrhs
, 1))),
6097 build_modify_expr (lhs1
, modifycode
,
6098 convert (result_type
,
6099 TREE_OPERAND (newrhs
, 2))));
6102 else if (modifycode
!= INIT_EXPR
&& TREE_CODE (newrhs
) == WITH_CLEANUP_EXPR
)
6104 tree cleanup
= TREE_OPERAND (newrhs
, 2);
6107 /* Finish up by running cleanups and having the "value" of the lhs. */
6108 tree exprlist
= tree_cons (NULL_TREE
, cleanup
,
6109 build_tree_list (NULL_TREE
, lhs
));
6110 newrhs
= TREE_OPERAND (newrhs
, 0);
6111 if (TREE_CODE (newrhs
) == TARGET_EXPR
)
6112 slot
= TREE_OPERAND (newrhs
, 0);
6113 else if (TREE_CODE (newrhs
) == ADDR_EXPR
)
6115 /* Bad but valid. */
6117 warning ("address taken of temporary object");
6120 my_friendly_abort (118);
6122 /* Copy the value computed in SLOT into LHS. */
6123 exprlist
= tree_cons (NULL_TREE
,
6124 build_modify_expr (lhs
, modifycode
, slot
),
6126 /* Evaluate the expression that needs CLEANUP. This will
6127 compute the value into SLOT. */
6128 exprlist
= tree_cons (NULL_TREE
, newrhs
, exprlist
);
6129 result
= convert (lhstype
, build_compound_expr (exprlist
));
6132 result
= build (modifycode
== NOP_EXPR
? MODIFY_EXPR
: INIT_EXPR
,
6133 lhstype
, lhs
, newrhs
);
6134 TREE_SIDE_EFFECTS (result
) = 1;
6136 /* If we got the LHS in a different type for storing in,
6137 convert the result back to the nominal type of LHS
6138 so that the value we return always has the same type
6139 as the LHS argument. */
6141 if (olhstype
== TREE_TYPE (result
))
6143 /* Avoid warnings converting integral types back into enums
6144 for enum bit fields. */
6145 if (TREE_CODE (TREE_TYPE (result
)) == INTEGER_TYPE
6146 && TREE_CODE (olhstype
) == ENUMERAL_TYPE
)
6148 result
= build (COMPOUND_EXPR
, olhstype
, result
, olhs
);
6149 TREE_NO_UNUSED_WARNING (result
) = 1;
6152 return convert_for_assignment (olhstype
, result
, "assignment",
6157 /* Return 0 if EXP is not a valid lvalue in this language
6158 even though `lvalue_or_else' would accept it. */
6161 language_lvalue_valid (exp
)
6167 /* Get differnce in deltas for different pointer to member function
6168 types. Return inetger_zero_node, if FROM cannot be converted to a
6169 TO type. If FORCE is true, then allow reverse conversions as well. */
6171 get_delta_difference (from
, to
, force
)
6175 tree delta
= integer_zero_node
;
6181 /* Should get_base_distance here, so we can check if any thing along the
6182 path is virtual, and we need to make sure we stay
6183 inside the real binfos when going through virtual bases.
6184 Maybe we should replace virtual bases with
6185 binfo_member (...CLASSTYPE_VBASECLASSES...)... (mrs) */
6186 binfo
= get_binfo (from
, to
, 1);
6187 if (binfo
== error_mark_node
)
6189 error (" in pointer to member function conversion");
6196 error_not_base_type (from
, to
);
6197 error (" in pointer to member function conversion");
6200 binfo
= get_binfo (to
, from
, 1);
6201 if (binfo
== error_mark_node
)
6203 error (" in pointer to member function conversion");
6208 error ("cannot convert pointer to member of type %T to unrelated pointer to member of type %T", from
, to
);
6211 if (TREE_VIA_VIRTUAL (binfo
))
6213 warning ("pointer to member conversion to virtual base class will only work if you are very careful");
6215 return build_binary_op (MINUS_EXPR
,
6217 BINFO_OFFSET (binfo
), 1);
6219 if (TREE_VIA_VIRTUAL (binfo
))
6221 warning ("pointer to member conversion from virtual base class will only work if you are very careful");
6223 return BINFO_OFFSET (binfo
);
6226 /* Build a constructor for a pointer to member function. It can be
6227 used to initialize global variables, local variable, or used
6228 as a value in expressions. TYPE is the POINTER to METHOD_TYPE we
6231 If FORCE is non-zero, then force this conversion, even if
6232 we would rather not do it. Usually set when using an explicit
6235 Return error_mark_node, if something goes wrong. */
6238 build_ptrmemfunc (type
, pfn
, force
)
6242 tree index
= integer_zero_node
;
6243 tree delta
= integer_zero_node
;
6244 tree delta2
= integer_zero_node
;
6249 /* Handle multiple conversions of pointer to member fucntions. */
6250 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (pfn
)))
6252 tree ndelta
, ndelta2
, nindex
;
6253 /* Is is already the right type? */
6255 /* Sorry, can't do this, the backend is too stupid. */
6256 if (TYPE_METHOD_BASETYPE (TREE_TYPE (type
))
6257 == TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn
)))))
6259 if (type
!= TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn
)))
6261 npfn
= build1 (NOP_EXPR
, TYPE_GET_PTRMEMFUNC_TYPE (type
), pfn
);
6262 TREE_CONSTANT (npfn
) = TREE_CONSTANT (pfn
);
6267 if (type
== TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn
)))
6271 if (TREE_CODE (pfn
) != CONSTRUCTOR
)
6274 ndelta
= convert (ptrdiff_type_node
, build_component_ref (pfn
, delta_identifier
, 0, 0));
6275 ndelta2
= convert (ptrdiff_type_node
, DELTA2_FROM_PTRMEMFUNC (pfn
));
6276 index
= build_component_ref (pfn
, index_identifier
, 0, 0);
6277 delta
= get_delta_difference (TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn
)))),
6278 TYPE_METHOD_BASETYPE (TREE_TYPE (type
)),
6280 delta
= build_binary_op (PLUS_EXPR
, delta
, ndelta
, 1);
6281 delta2
= build_binary_op (PLUS_EXPR
, ndelta2
, delta2
, 1);
6282 e1
= fold (build (GT_EXPR
, boolean_type_node
, index
, integer_zero_node
));
6284 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (delta2_identifier
, delta2
, NULL_TREE
));
6285 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (NULL_TREE
, delta
,
6286 tree_cons (NULL_TREE
, index
,
6287 tree_cons (NULL_TREE
, u
, NULL_TREE
))));
6288 e2
= digest_init (TYPE_GET_PTRMEMFUNC_TYPE (type
), u
, (tree
*)0);
6290 pfn
= PFN_FROM_PTRMEMFUNC (pfn
);
6291 npfn
= build1 (NOP_EXPR
, type
, pfn
);
6292 TREE_CONSTANT (npfn
) = TREE_CONSTANT (pfn
);
6294 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (pfn_identifier
, npfn
, NULL_TREE
));
6295 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (NULL_TREE
, delta
,
6296 tree_cons (NULL_TREE
, index
,
6297 tree_cons (NULL_TREE
, u
, NULL_TREE
))));
6298 e3
= digest_init (TYPE_GET_PTRMEMFUNC_TYPE (type
), u
, (tree
*)0);
6299 return build_conditional_expr (e1
, e2
, e3
);
6302 ndelta
= TREE_VALUE (CONSTRUCTOR_ELTS (pfn
));
6303 nindex
= TREE_VALUE (TREE_CHAIN (CONSTRUCTOR_ELTS (pfn
)));
6304 npfn
= TREE_VALUE (TREE_CHAIN (TREE_CHAIN (CONSTRUCTOR_ELTS (pfn
))));
6305 npfn
= TREE_VALUE (CONSTRUCTOR_ELTS (npfn
));
6306 if (integer_zerop (nindex
))
6307 pfn
= integer_zero_node
;
6310 sorry ("value casting of varible nonnull pointer to member functions not supported");
6311 return error_mark_node
;
6315 /* Handle null pointer to member function conversions. */
6316 if (integer_zerop (pfn
))
6318 pfn
= build_c_cast (type
, integer_zero_node
, 0);
6319 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (pfn_identifier
, pfn
, NULL_TREE
));
6320 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (NULL_TREE
, integer_zero_node
,
6321 tree_cons (NULL_TREE
, integer_zero_node
,
6322 tree_cons (NULL_TREE
, u
, NULL_TREE
))));
6323 return digest_init (TYPE_GET_PTRMEMFUNC_TYPE (type
), u
, (tree
*)0);
6326 if (TREE_CODE (pfn
) == TREE_LIST
6327 || (TREE_CODE (pfn
) == ADDR_EXPR
6328 && TREE_CODE (TREE_OPERAND (pfn
, 0)) == TREE_LIST
))
6330 pfn
= instantiate_type (type
, pfn
, 1);
6331 if (pfn
== error_mark_node
)
6332 return error_mark_node
;
6333 if (TREE_CODE (pfn
) != ADDR_EXPR
)
6334 pfn
= build_unary_op (ADDR_EXPR
, pfn
, 0);
6337 /* Allow pointer to member conversions here. */
6338 delta
= get_delta_difference (TYPE_METHOD_BASETYPE (TREE_TYPE (TREE_TYPE (pfn
))),
6339 TYPE_METHOD_BASETYPE (TREE_TYPE (type
)),
6341 delta2
= build_binary_op (PLUS_EXPR
, delta2
, delta
, 1);
6343 if (TREE_CODE (TREE_OPERAND (pfn
, 0)) != FUNCTION_DECL
)
6344 warning ("assuming pointer to member function is non-virtual");
6346 if (TREE_CODE (TREE_OPERAND (pfn
, 0)) == FUNCTION_DECL
6347 && DECL_VINDEX (TREE_OPERAND (pfn
, 0)))
6349 /* Find the offset to the vfield pointer in the object. */
6350 vfield_offset
= get_binfo (DECL_CONTEXT (TREE_OPERAND (pfn
, 0)),
6351 DECL_CLASS_CONTEXT (TREE_OPERAND (pfn
, 0)),
6353 vfield_offset
= get_vfield_offset (vfield_offset
);
6354 delta2
= size_binop (PLUS_EXPR
, vfield_offset
, delta2
);
6356 /* Map everything down one to make room for the null pointer to member. */
6357 index
= size_binop (PLUS_EXPR
,
6358 DECL_VINDEX (TREE_OPERAND (pfn
, 0)),
6360 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (delta2_identifier
, delta2
, NULL_TREE
));
6364 index
= size_binop (MINUS_EXPR
, integer_zero_node
, integer_one_node
);
6366 npfn
= build1 (NOP_EXPR
, type
, pfn
);
6367 TREE_CONSTANT (npfn
) = TREE_CONSTANT (pfn
);
6369 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (pfn_identifier
, npfn
, NULL_TREE
));
6372 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (NULL_TREE
, delta
,
6373 tree_cons (NULL_TREE
, index
,
6374 tree_cons (NULL_TREE
, u
, NULL_TREE
))));
6375 return digest_init (TYPE_GET_PTRMEMFUNC_TYPE (type
), u
, (tree
*)0);
6378 /* Convert value RHS to type TYPE as preparation for an assignment
6379 to an lvalue of type TYPE.
6380 The real work of conversion is done by `convert'.
6381 The purpose of this function is to generate error messages
6382 for assignments that are not allowed in C.
6383 ERRTYPE is a string to use in error messages:
6384 "assignment", "return", etc.
6386 C++: attempts to allow `convert' to find conversions involving
6387 implicit type conversion between aggregate and scalar types
6388 as per 8.5.6 of C++ manual. Does not randomly dereference
6389 pointers to aggregates! */
6392 convert_for_assignment (type
, rhs
, errtype
, fndecl
, parmnum
)
6398 register enum tree_code codel
= TREE_CODE (type
);
6399 register tree rhstype
;
6400 register enum tree_code coder
= TREE_CODE (TREE_TYPE (rhs
));
6402 if (coder
== UNKNOWN_TYPE
)
6403 rhs
= instantiate_type (type
, rhs
, 1);
6405 if (coder
== ERROR_MARK
)
6406 return error_mark_node
;
6408 if (codel
== OFFSET_TYPE
)
6410 type
= TREE_TYPE (type
);
6411 codel
= TREE_CODE (type
);
6414 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
6415 if (TREE_CODE (rhs
) == NON_LVALUE_EXPR
)
6416 rhs
= TREE_OPERAND (rhs
, 0);
6418 if (rhs
== error_mark_node
)
6419 return error_mark_node
;
6421 if (TREE_VALUE (rhs
) == error_mark_node
)
6422 return error_mark_node
;
6424 if (TREE_CODE (TREE_TYPE (rhs
)) == OFFSET_TYPE
)
6426 rhs
= resolve_offset_ref (rhs
);
6427 if (rhs
== error_mark_node
)
6428 return error_mark_node
;
6429 rhstype
= TREE_TYPE (rhs
);
6430 coder
= TREE_CODE (rhstype
);
6433 if (TREE_CODE (TREE_TYPE (rhs
)) == ARRAY_TYPE
6434 || TREE_CODE (TREE_TYPE (rhs
)) == FUNCTION_TYPE
6435 || TREE_CODE (TREE_TYPE (rhs
)) == METHOD_TYPE
)
6436 rhs
= default_conversion (rhs
);
6437 else if (TREE_CODE (TREE_TYPE (rhs
)) == REFERENCE_TYPE
)
6438 rhs
= convert_from_reference (rhs
);
6440 rhstype
= TREE_TYPE (rhs
);
6441 coder
= TREE_CODE (rhstype
);
6443 /* This should no longer change types on us. */
6444 if (TREE_CODE (rhs
) == CONST_DECL
)
6445 rhs
= DECL_INITIAL (rhs
);
6446 else if (TREE_READONLY_DECL_P (rhs
))
6447 rhs
= decl_constant_value (rhs
);
6449 if (type
== rhstype
)
6451 overflow_warning (rhs
);
6455 if (coder
== VOID_TYPE
)
6457 error ("void value not ignored as it ought to be");
6458 return error_mark_node
;
6460 /* Arithmetic types all interconvert. */
6461 if ((codel
== INTEGER_TYPE
|| codel
== REAL_TYPE
|| codel
== BOOLEAN_TYPE
)
6462 && (coder
== INTEGER_TYPE
|| coder
== REAL_TYPE
|| coder
== BOOLEAN_TYPE
))
6464 /* But we should warn if assigning REAL_TYPE to INTEGER_TYPE. */
6465 if (coder
== REAL_TYPE
&& codel
== INTEGER_TYPE
)
6468 cp_warning ("`%T' used for argument %P of `%D'",
6469 rhstype
, parmnum
, fndecl
);
6471 cp_warning ("%s to `%T' from `%T'", errtype
, type
, rhstype
);
6473 /* And we should warn if assigning a negative value to
6474 an unsigned variable. */
6475 else if (TREE_UNSIGNED (type
) && codel
!= BOOLEAN_TYPE
)
6477 if (TREE_CODE (rhs
) == INTEGER_CST
6478 && TREE_NEGATED_INT (rhs
))
6481 cp_warning ("negative value `%E' passed as argument %P of `%D'",
6482 rhs
, parmnum
, fndecl
);
6484 cp_warning ("%s of negative value `%E' to `%T'",
6485 errtype
, rhs
, type
);
6487 overflow_warning (rhs
);
6488 if (TREE_CONSTANT (rhs
))
6492 return convert_and_check (type
, rhs
);
6494 /* Conversions involving enums. */
6495 else if ((codel
== ENUMERAL_TYPE
6496 && (INTEGRAL_CODE_P (coder
) || coder
== REAL_TYPE
))
6497 || (coder
== ENUMERAL_TYPE
6498 && (INTEGRAL_CODE_P (codel
) || codel
== REAL_TYPE
)))
6500 return cp_convert (type
, rhs
, CONV_IMPLICIT
, 0);
6502 /* Conversions among pointers */
6503 else if (codel
== POINTER_TYPE
6504 && (coder
== POINTER_TYPE
6505 || (coder
== RECORD_TYPE
6506 && (IS_SIGNATURE_POINTER (rhstype
)
6507 || IS_SIGNATURE_REFERENCE (rhstype
)))))
6509 register tree ttl
= TREE_TYPE (type
);
6513 if (coder
== RECORD_TYPE
)
6515 rhs
= build_optr_ref (rhs
);
6516 rhstype
= TREE_TYPE (rhs
);
6518 ttr
= TREE_TYPE (rhstype
);
6520 /* If both pointers are of aggregate type, then we
6521 can give better error messages, and save some work
6523 if (TREE_CODE (ttl
) == RECORD_TYPE
&& TREE_CODE (ttr
) == RECORD_TYPE
)
6527 if (TYPE_MAIN_VARIANT (ttl
) == TYPE_MAIN_VARIANT (ttr
)
6528 || type
== class_star_type_node
6529 || rhstype
== class_star_type_node
)
6530 binfo
= TYPE_BINFO (ttl
);
6532 binfo
= get_binfo (ttl
, ttr
, 1);
6534 if (binfo
== error_mark_node
)
6535 return error_mark_node
;
6537 return error_not_base_type (ttl
, ttr
);
6539 if (! TYPE_READONLY (ttl
) && TYPE_READONLY (ttr
))
6542 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6543 rhstype
, parmnum
, fndecl
);
6545 cp_pedwarn ("%s to `%T' from `%T' discards const",
6546 errtype
, type
, rhstype
);
6548 if (! TYPE_VOLATILE (ttl
) && TYPE_VOLATILE (ttr
))
6551 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6552 rhstype
, parmnum
, fndecl
);
6554 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6555 errtype
, type
, rhstype
);
6559 /* Any non-function converts to a [const][volatile] void *
6560 and vice versa; otherwise, targets must be the same.
6561 Meanwhile, the lhs target must have all the qualifiers of the rhs. */
6562 else if (TYPE_MAIN_VARIANT (ttl
) == void_type_node
6563 || TYPE_MAIN_VARIANT (ttr
) == void_type_node
6564 || (ctt
= comp_target_types (type
, rhstype
, 1))
6565 || (unsigned_type (TYPE_MAIN_VARIANT (ttl
))
6566 == unsigned_type (TYPE_MAIN_VARIANT (ttr
))))
6568 /* ARM $4.8, commentary on p39. */
6569 if (TYPE_MAIN_VARIANT (ttl
) == void_type_node
6570 && TREE_CODE (ttr
) == OFFSET_TYPE
)
6572 cp_error ("no standard conversion from `%T' to `void *'", ttr
);
6573 return error_mark_node
;
6577 cp_pedwarn ("converting `%T' to `%T' is a contravariance violation",
6580 if (TYPE_MAIN_VARIANT (ttl
) != void_type_node
6581 && TYPE_MAIN_VARIANT (ttr
) == void_type_node
6582 && rhs
!= null_pointer_node
)
6584 if (coder
== RECORD_TYPE
)
6585 cp_pedwarn ("implicit conversion of signature pointer to type `%T'",
6588 pedwarn ("ANSI C++ forbids implicit conversion from `void *' in %s",
6591 /* Const and volatile mean something different for function types,
6592 so the usual warnings are not appropriate. */
6593 else if ((TREE_CODE (ttr
) != FUNCTION_TYPE
&& TREE_CODE (ttr
) != METHOD_TYPE
)
6594 || (TREE_CODE (ttl
) != FUNCTION_TYPE
&& TREE_CODE (ttl
) != METHOD_TYPE
))
6596 if (TREE_CODE (ttl
) == OFFSET_TYPE
6597 && binfo_member (TYPE_OFFSET_BASETYPE (ttr
),
6598 CLASSTYPE_VBASECLASSES (TYPE_OFFSET_BASETYPE (ttl
))))
6600 sorry ("%s between pointer to members converting across virtual baseclasses", errtype
);
6601 return error_mark_node
;
6603 else if (! TYPE_READONLY (ttl
) && TYPE_READONLY (ttr
))
6606 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6607 rhstype
, parmnum
, fndecl
);
6609 cp_pedwarn ("%s to `%T' from `%T' discards const",
6610 errtype
, type
, rhstype
);
6612 else if (! TYPE_VOLATILE (ttl
) && TYPE_VOLATILE (ttr
))
6615 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6616 rhstype
, parmnum
, fndecl
);
6618 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6619 errtype
, type
, rhstype
);
6621 else if (TREE_CODE (ttl
) == TREE_CODE (ttr
)
6622 && ! comp_target_types (type
, rhstype
, 1))
6625 cp_pedwarn ("passing `%T' as argument %P of `%D' changes signedness",
6626 rhstype
, parmnum
, fndecl
);
6628 cp_pedwarn ("%s to `%T' from `%T' changes signedness",
6629 errtype
, type
, rhstype
);
6633 else if (TREE_CODE (ttr
) == OFFSET_TYPE
6634 && TREE_CODE (ttl
) != OFFSET_TYPE
)
6636 /* Normally, pointers to different type codes (other
6637 than void) are not compatible, but we perform
6638 some type instantiation if that resolves the
6639 ambiguity of (X Y::*) and (X *). */
6641 if (current_class_decl
)
6643 if (TREE_CODE (rhs
) == INTEGER_CST
)
6645 rhs
= build (PLUS_EXPR
, build_pointer_type (TREE_TYPE (ttr
)),
6646 current_class_decl
, rhs
);
6647 return convert_for_assignment (type
, rhs
,
6648 errtype
, fndecl
, parmnum
);
6651 if (TREE_CODE (ttl
) == METHOD_TYPE
)
6652 error ("%s between pointer-to-method and pointer-to-member types",
6655 error ("%s between pointer and pointer-to-member types", errtype
);
6656 return error_mark_node
;
6660 int add_quals
= 0, const_parity
= 0, volatile_parity
= 0;
6662 int unsigned_parity
;
6665 /* This code is basically a duplicate of comp_ptr_ttypes_real. */
6666 for (; ; ttl
= TREE_TYPE (ttl
), ttr
= TREE_TYPE (ttr
))
6669 const_parity
|= TYPE_READONLY (ttl
) < TYPE_READONLY (ttr
);
6670 volatile_parity
|= TYPE_VOLATILE (ttl
) < TYPE_VOLATILE (ttr
);
6673 && (TYPE_READONLY (ttl
) > TYPE_READONLY (ttr
)
6674 || TYPE_VOLATILE (ttl
) > TYPE_VOLATILE (ttr
)))
6676 left_const
&= TYPE_READONLY (ttl
);
6678 if (TREE_CODE (ttl
) != POINTER_TYPE
6679 || TREE_CODE (ttr
) != POINTER_TYPE
)
6682 unsigned_parity
= TREE_UNSIGNED (ttl
) - TREE_UNSIGNED (ttr
);
6683 if (unsigned_parity
)
6685 if (TREE_UNSIGNED (ttl
))
6686 ttr
= unsigned_type (ttr
);
6688 ttl
= unsigned_type (ttl
);
6691 if (comp_target_types (ttl
, ttr
, nptrs
) > 0)
6696 cp_pedwarn ("passing `%T' as argument %P of `%D' adds cv-quals without intervening `const'",
6697 rhstype
, parmnum
, fndecl
);
6699 cp_pedwarn ("%s to `%T' from `%T' adds cv-quals without intervening `const'",
6700 errtype
, type
, rhstype
);
6705 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6706 rhstype
, parmnum
, fndecl
);
6708 cp_pedwarn ("%s to `%T' from `%T' discards const",
6709 errtype
, type
, rhstype
);
6711 if (volatile_parity
)
6714 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6715 rhstype
, parmnum
, fndecl
);
6717 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6718 errtype
, type
, rhstype
);
6720 if (unsigned_parity
> 0)
6723 cp_pedwarn ("passing `%T' as argument %P of `%D' changes signed to unsigned",
6724 rhstype
, parmnum
, fndecl
);
6726 cp_pedwarn ("%s to `%T' from `%T' changes signed to unsigned",
6727 errtype
, type
, rhstype
);
6729 else if (unsigned_parity
< 0)
6732 cp_pedwarn ("passing `%T' as argument %P of `%D' changes unsigned to signed",
6733 rhstype
, parmnum
, fndecl
);
6735 cp_pedwarn ("%s to `%T' from `%T' changes unsigned to signed",
6736 errtype
, type
, rhstype
);
6739 /* C++ is not so friendly about converting function and
6740 member function pointers as C. Emit warnings here. */
6741 if (TREE_CODE (ttl
) == FUNCTION_TYPE
6742 || TREE_CODE (ttl
) == METHOD_TYPE
)
6743 if (! comptypes (ttl
, ttr
, 0))
6745 warning ("conflicting function types in %s:", errtype
);
6746 cp_warning ("\t`%T' != `%T'", type
, rhstype
);
6749 else if (TREE_CODE (TREE_TYPE (rhs
)) == METHOD_TYPE
)
6751 /* When does this happen? */
6752 my_friendly_abort (119);
6753 /* Conversion of a pointer-to-member type to void *. */
6754 rhs
= build_unary_op (ADDR_EXPR
, rhs
, 0);
6755 TREE_TYPE (rhs
) = type
;
6758 else if (TREE_CODE (TREE_TYPE (rhs
)) == OFFSET_TYPE
)
6760 /* When does this happen? */
6761 my_friendly_abort (120);
6762 /* Conversion of a pointer-to-member type to void *. */
6763 rhs
= build_unary_op (ADDR_EXPR
, rhs
, 0);
6764 TREE_TYPE (rhs
) = type
;
6770 cp_error ("passing `%T' as argument %P of `%D'",
6771 rhstype
, parmnum
, fndecl
);
6773 cp_error ("%s to `%T' from `%T'", errtype
, type
, rhstype
);
6774 return error_mark_node
;
6777 return convert (type
, rhs
);
6779 else if (codel
== POINTER_TYPE
&& coder
== INTEGER_TYPE
)
6781 /* An explicit constant 0 can convert to a pointer,
6782 but not a 0 that results from casting or folding. */
6783 if (! (TREE_CODE (rhs
) == INTEGER_CST
&& integer_zerop (rhs
)))
6786 cp_pedwarn ("passing `%T' to argument %P of `%D' lacks a cast",
6787 rhstype
, parmnum
, fndecl
);
6789 cp_pedwarn ("%s to `%T' from `%T' lacks a cast",
6790 errtype
, type
, rhstype
);
6791 return convert (type
, rhs
);
6793 return null_pointer_node
;
6795 else if (codel
== INTEGER_TYPE
6796 && (coder
== POINTER_TYPE
6797 || (coder
== RECORD_TYPE
6798 && (IS_SIGNATURE_POINTER (rhstype
)
6799 || TYPE_PTRMEMFUNC_FLAG (rhstype
)
6800 || IS_SIGNATURE_REFERENCE (rhstype
)))))
6803 cp_pedwarn ("passing `%T' to argument %P of `%D' lacks a cast",
6804 rhstype
, parmnum
, fndecl
);
6806 cp_pedwarn ("%s to `%T' from `%T' lacks a cast",
6807 errtype
, type
, rhstype
);
6808 return convert (type
, rhs
);
6810 else if (codel
== BOOLEAN_TYPE
6811 && (coder
== POINTER_TYPE
6812 || (coder
== RECORD_TYPE
6813 && (IS_SIGNATURE_POINTER (rhstype
)
6814 || TYPE_PTRMEMFUNC_FLAG (rhstype
)
6815 || IS_SIGNATURE_REFERENCE (rhstype
)))))
6816 return convert (type
, rhs
);
6819 else if (((coder
== POINTER_TYPE
6820 && TREE_CODE (TREE_TYPE (rhstype
)) == METHOD_TYPE
)
6821 || integer_zerop (rhs
)
6822 || TYPE_PTRMEMFUNC_P (rhstype
))
6823 && TYPE_PTRMEMFUNC_P (type
))
6825 tree ttl
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
6826 tree ttr
= (TREE_CODE (rhstype
) == POINTER_TYPE
? rhstype
6827 : TYPE_PTRMEMFUNC_FN_TYPE (type
));
6828 int ctt
= comp_target_types (ttl
, ttr
, 1);
6831 cp_pedwarn ("converting `%T' to `%T' is a contravariance violation",
6834 cp_error ("%s to `%T' from `%T'", errtype
, ttl
, ttr
);
6836 /* compatible pointer to member functions. */
6837 return build_ptrmemfunc (ttl
, rhs
, 0);
6839 else if (codel
== ERROR_MARK
|| coder
== ERROR_MARK
)
6840 return error_mark_node
;
6842 /* This should no longer happen. References are initialized via
6843 `convert_for_initialization'. They should otherwise be
6844 bashed before coming here. */
6845 else if (codel
== REFERENCE_TYPE
)
6846 my_friendly_abort (317);
6847 else if (TYPE_MAIN_VARIANT (type
) == TYPE_MAIN_VARIANT (TREE_TYPE (rhs
)))
6849 tree nrhs
= build1 (NOP_EXPR
, type
, rhs
);
6850 TREE_CONSTANT (nrhs
) = TREE_CONSTANT (rhs
);
6853 else if (TYPE_HAS_CONSTRUCTOR (type
) || IS_AGGR_TYPE (TREE_TYPE (rhs
)))
6854 return convert (type
, rhs
);
6856 cp_error ("%s to `%T' from `%T'", errtype
, type
, rhstype
);
6857 return error_mark_node
;
6860 /* Convert RHS to be of type TYPE. If EXP is non-zero,
6861 it is the target of the initialization.
6862 ERRTYPE is a string to use in error messages.
6864 Two major differences between the behavior of
6865 `convert_for_assignment' and `convert_for_initialization'
6866 are that references are bashed in the former, while
6867 copied in the latter, and aggregates are assigned in
6868 the former (operator=) while initialized in the
6871 If using constructor make sure no conversion operator exists, if one does
6872 exist, an ambiguity exists. */
6874 convert_for_initialization (exp
, type
, rhs
, flags
, errtype
, fndecl
, parmnum
)
6875 tree exp
, type
, rhs
;
6881 register enum tree_code codel
= TREE_CODE (type
);
6882 register tree rhstype
;
6883 register enum tree_code coder
;
6885 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
6886 Strip such NOP_EXPRs, since RHS is used in non-lvalue context. */
6887 if (TREE_CODE (rhs
) == NOP_EXPR
6888 && TREE_TYPE (rhs
) == TREE_TYPE (TREE_OPERAND (rhs
, 0))
6889 && codel
!= REFERENCE_TYPE
)
6890 rhs
= TREE_OPERAND (rhs
, 0);
6892 if (rhs
== error_mark_node
6893 || (TREE_CODE (rhs
) == TREE_LIST
&& TREE_VALUE (rhs
) == error_mark_node
))
6894 return error_mark_node
;
6896 if (TREE_CODE (TREE_TYPE (rhs
)) == OFFSET_TYPE
)
6898 rhs
= resolve_offset_ref (rhs
);
6899 if (rhs
== error_mark_node
)
6900 return error_mark_node
;
6903 if (TREE_CODE (TREE_TYPE (rhs
)) == REFERENCE_TYPE
)
6904 rhs
= convert_from_reference (rhs
);
6906 if ((TREE_CODE (TREE_TYPE (rhs
)) == ARRAY_TYPE
6907 && TREE_CODE (type
) != ARRAY_TYPE
6908 && (TREE_CODE (type
) != REFERENCE_TYPE
6909 || TREE_CODE (TREE_TYPE (type
)) != ARRAY_TYPE
))
6910 || TREE_CODE (TREE_TYPE (rhs
)) == FUNCTION_TYPE
6911 || TREE_CODE (TREE_TYPE (rhs
)) == METHOD_TYPE
)
6912 rhs
= default_conversion (rhs
);
6914 rhstype
= TREE_TYPE (rhs
);
6915 coder
= TREE_CODE (rhstype
);
6917 if (coder
== UNKNOWN_TYPE
)
6919 rhs
= instantiate_type (type
, rhs
, 1);
6920 rhstype
= TREE_TYPE (rhs
);
6921 coder
= TREE_CODE (rhstype
);
6924 if (coder
== ERROR_MARK
)
6925 return error_mark_node
;
6928 /* This is *not* the quick way out! It is the way to disaster. */
6929 if (type
== rhstype
)
6933 /* We accept references to incomplete types, so we can
6934 return here before checking if RHS is of complete type. */
6936 if (codel
== REFERENCE_TYPE
)
6938 /* This should eventually happen in convert_arguments. */
6939 extern int warningcount
, errorcount
;
6943 savew
= warningcount
, savee
= errorcount
;
6944 rhs
= convert_to_reference (type
, rhs
, CONV_IMPLICIT
, flags
,
6945 exp
? exp
: error_mark_node
);
6948 if (warningcount
> savew
)
6949 cp_warning_at ("in passing argument %P of `%+D'", parmnum
, fndecl
);
6950 else if (errorcount
> savee
)
6951 cp_error_at ("in passing argument %P of `%+D'", parmnum
, fndecl
);
6956 rhs
= require_complete_type (rhs
);
6957 if (rhs
== error_mark_node
)
6958 return error_mark_node
;
6960 if (exp
!= 0) exp
= require_complete_type (exp
);
6961 if (exp
== error_mark_node
)
6962 return error_mark_node
;
6964 if (TREE_CODE (rhstype
) == REFERENCE_TYPE
)
6965 rhstype
= TREE_TYPE (rhstype
);
6967 if (TYPE_LANG_SPECIFIC (type
)
6968 && (IS_SIGNATURE_POINTER (type
) || IS_SIGNATURE_REFERENCE (type
)))
6969 return build_signature_pointer_constructor (type
, rhs
);
6971 if (IS_AGGR_TYPE (type
)
6972 && (TYPE_NEEDS_CONSTRUCTING (type
) || TREE_HAS_CONSTRUCTOR (rhs
)))
6974 if (TYPE_MAIN_VARIANT (type
) == TYPE_MAIN_VARIANT (rhstype
))
6976 /* This is sufficient to perform initialization. No need,
6977 apparently, to go through X(X&) to do first-cut
6978 initialization. Return through a TARGET_EXPR so that we get
6979 cleanups if it is used. */
6980 if (TREE_CODE (rhs
) == CALL_EXPR
)
6982 rhs
= build_cplus_new (type
, rhs
, 0);
6985 /* Handle the case of default parameter initialization and
6986 initialization of static variables. */
6987 else if (TREE_CODE (rhs
) == TARGET_EXPR
)
6989 else if (TREE_CODE (rhs
) == INDIRECT_REF
&& TREE_HAS_CONSTRUCTOR (rhs
))
6991 my_friendly_assert (TREE_CODE (TREE_OPERAND (rhs
, 0)) == CALL_EXPR
, 318);
6994 my_friendly_assert (TREE_VALUE (TREE_OPERAND (TREE_OPERAND (rhs
, 0), 1)) == NULL_TREE
, 316);
6995 TREE_VALUE (TREE_OPERAND (TREE_OPERAND (rhs
, 0), 1))
6996 = build_unary_op (ADDR_EXPR
, exp
, 0);
6999 rhs
= build_cplus_new (type
, TREE_OPERAND (rhs
, 0), 0);
7002 else if (TYPE_HAS_TRIVIAL_INIT_REF (type
))
7005 if (TYPE_MAIN_VARIANT (type
) == TYPE_MAIN_VARIANT (rhstype
)
7006 || (IS_AGGR_TYPE (rhstype
) && UNIQUELY_DERIVED_FROM_P (type
, rhstype
)))
7008 if (TYPE_HAS_INIT_REF (type
))
7010 tree init
= build_method_call (exp
, constructor_name_full (type
),
7011 build_tree_list (NULL_TREE
, rhs
),
7012 TYPE_BINFO (type
), LOOKUP_NORMAL
);
7014 if (init
== error_mark_node
)
7015 return error_mark_node
;
7019 exp
= build_cplus_new (type
, init
, 0);
7023 return build (COMPOUND_EXPR
, type
, init
, exp
);
7026 /* ??? The following warnings are turned off because
7027 this is another place where the default X(X&) constructor
7029 if (TYPE_HAS_ASSIGNMENT (type
))
7030 cp_warning ("bitwise copy: `%T' defines operator=", type
);
7032 if (TREE_CODE (TREE_TYPE (rhs
)) == REFERENCE_TYPE
)
7033 rhs
= convert_from_reference (rhs
);
7034 if (type
!= rhstype
)
7036 tree nrhs
= build1 (NOP_EXPR
, type
, rhs
);
7037 TREE_CONSTANT (nrhs
) = TREE_CONSTANT (rhs
);
7043 return convert (type
, rhs
);
7046 if (type
== TREE_TYPE (rhs
))
7048 if (TREE_READONLY_DECL_P (rhs
))
7049 rhs
= decl_constant_value (rhs
);
7053 return convert_for_assignment (type
, rhs
, errtype
, fndecl
, parmnum
);
7056 /* Expand an ASM statement with operands, handling output operands
7057 that are not variables or INDIRECT_REFS by transforming such
7058 cases into cases that expand_asm_operands can handle.
7060 Arguments are same as for expand_asm_operands.
7062 We don't do default conversions on all inputs, because it can screw
7063 up operands that are expected to be in memory. */
7066 c_expand_asm_operands (string
, outputs
, inputs
, clobbers
, vol
, filename
, line
)
7067 tree string
, outputs
, inputs
, clobbers
;
7072 int noutputs
= list_length (outputs
);
7074 /* o[I] is the place that output number I should be written. */
7075 register tree
*o
= (tree
*) alloca (noutputs
* sizeof (tree
));
7078 /* Record the contents of OUTPUTS before it is modified. */
7079 for (i
= 0, tail
= outputs
; tail
; tail
= TREE_CHAIN (tail
), i
++)
7080 o
[i
] = TREE_VALUE (tail
);
7082 /* Generate the ASM_OPERANDS insn;
7083 store into the TREE_VALUEs of OUTPUTS some trees for
7084 where the values were actually stored. */
7085 expand_asm_operands (string
, outputs
, inputs
, clobbers
, vol
, filename
, line
);
7087 /* Copy all the intermediate outputs into the specified outputs. */
7088 for (i
= 0, tail
= outputs
; tail
; tail
= TREE_CHAIN (tail
), i
++)
7090 if (o
[i
] != TREE_VALUE (tail
))
7092 expand_expr (build_modify_expr (o
[i
], NOP_EXPR
, TREE_VALUE (tail
)),
7093 const0_rtx
, VOIDmode
, 0);
7096 /* Detect modification of read-only values.
7097 (Otherwise done by build_modify_expr.) */
7100 tree type
= TREE_TYPE (o
[i
]);
7101 if (TYPE_READONLY (type
)
7102 || ((TREE_CODE (type
) == RECORD_TYPE
7103 || TREE_CODE (type
) == UNION_TYPE
)
7104 && C_TYPE_FIELDS_READONLY (type
)))
7105 readonly_error (o
[i
], "modification by `asm'", 1);
7109 /* Those MODIFY_EXPRs could do autoincrements. */
7113 /* Expand a C `return' statement.
7114 RETVAL is the expression for what to return,
7115 or a null pointer for `return;' with no value.
7117 C++: upon seeing a `return', we must call destructors on all
7118 variables in scope which had constructors called on them.
7119 This means that if in a destructor, the base class destructors
7120 must be called before returning.
7122 The RETURN statement in C++ has initialization semantics. */
7125 c_expand_return (retval
)
7128 extern struct nesting
*cond_stack
, *loop_stack
, *case_stack
;
7129 extern tree dtor_label
, ctor_label
;
7130 tree result
= DECL_RESULT (current_function_decl
);
7131 tree valtype
= TREE_TYPE (result
);
7132 register int use_temp
= 0;
7133 int returns_value
= 1;
7135 if (TREE_THIS_VOLATILE (current_function_decl
))
7136 warning ("function declared `noreturn' has a `return' statement");
7138 if (retval
== error_mark_node
)
7140 current_function_returns_null
= 1;
7144 if (retval
== NULL_TREE
)
7146 /* A non-named return value does not count. */
7148 /* Can't just return from a destructor. */
7151 expand_goto (dtor_label
);
7155 if (DECL_CONSTRUCTOR_P (current_function_decl
))
7156 retval
= current_class_decl
;
7157 else if (DECL_NAME (result
) != NULL_TREE
7158 && TREE_CODE (valtype
) != VOID_TYPE
)
7162 current_function_returns_null
= 1;
7164 if (valtype
!= NULL_TREE
&& TREE_CODE (valtype
) != VOID_TYPE
)
7166 if (DECL_NAME (DECL_RESULT (current_function_decl
)) == NULL_TREE
)
7168 pedwarn ("`return' with no value, in function returning non-void");
7169 /* Clear this, so finish_function won't say that we
7170 reach the end of a non-void function (which we don't,
7171 we gave a return!). */
7172 current_function_returns_null
= 0;
7176 expand_null_return ();
7180 else if (DECL_CONSTRUCTOR_P (current_function_decl
)
7181 && retval
!= current_class_decl
)
7183 error ("return from a constructor: use `this = ...' instead");
7184 retval
= current_class_decl
;
7187 if (valtype
== NULL_TREE
|| TREE_CODE (valtype
) == VOID_TYPE
)
7189 current_function_returns_null
= 1;
7190 /* We do this here so we'll avoid a warning about how the function
7191 "may or may not return a value" in finish_function. */
7195 pedwarn ("`return' with a value, in function returning void");
7196 expand_return (retval
);
7198 /* Add some useful error checking for C++. */
7199 else if (TREE_CODE (valtype
) == REFERENCE_TYPE
)
7201 tree whats_returned
;
7202 tree tmp_result
= result
;
7204 /* Don't initialize directly into a non-BLKmode retval, since that
7205 could lose when being inlined by another caller. (GCC can't
7206 read the function return register in an inline function when
7207 the return value is being ignored). */
7208 if (result
&& TYPE_MODE (TREE_TYPE (tmp_result
)) != BLKmode
)
7211 /* convert to reference now, so we can give error if we
7212 return an reference to a non-lvalue. */
7213 retval
= convert_for_initialization (tmp_result
, valtype
, retval
,
7214 LOOKUP_NORMAL
, "return",
7217 /* Sort through common things to see what it is
7218 we are returning. */
7219 whats_returned
= retval
;
7220 if (TREE_CODE (whats_returned
) == COMPOUND_EXPR
)
7222 whats_returned
= TREE_OPERAND (whats_returned
, 1);
7223 if (TREE_CODE (whats_returned
) == ADDR_EXPR
)
7224 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7226 if (TREE_CODE (whats_returned
) == ADDR_EXPR
)
7228 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7229 while (TREE_CODE (whats_returned
) == NEW_EXPR
7230 || TREE_CODE (whats_returned
) == TARGET_EXPR
7231 || TREE_CODE (whats_returned
) == WITH_CLEANUP_EXPR
)
7233 /* Get the target. */
7234 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7235 warning ("returning reference to temporary");
7239 if (TREE_CODE (whats_returned
) == VAR_DECL
&& DECL_NAME (whats_returned
))
7241 if (TEMP_NAME_P (DECL_NAME (whats_returned
)))
7242 warning ("reference to non-lvalue returned");
7243 else if (! TREE_STATIC (whats_returned
)
7244 && IDENTIFIER_LOCAL_VALUE (DECL_NAME (whats_returned
)))
7245 cp_warning_at ("reference to local variable `%D' returned", whats_returned
);
7248 else if (TREE_CODE (retval
) == ADDR_EXPR
)
7250 tree whats_returned
= TREE_OPERAND (retval
, 0);
7252 if (TREE_CODE (whats_returned
) == VAR_DECL
7253 && DECL_NAME (whats_returned
)
7254 && IDENTIFIER_LOCAL_VALUE (DECL_NAME (whats_returned
))
7255 && !TREE_STATIC (whats_returned
))
7256 cp_warning_at ("address of local variable `%D' returned", whats_returned
);
7259 /* Now deal with possible C++ hair:
7260 (1) Compute the return value.
7261 (2) If there are aggregate values with destructors which
7262 must be cleaned up, clean them (taking care
7263 not to clobber the return value).
7264 (3) If an X(X&) constructor is defined, the return
7265 value must be returned via that. */
7267 /* If we're returning in a register, we can't initialize the
7268 return value from a TARGET_EXPR. */
7269 if (TREE_CODE (retval
) == TARGET_EXPR
7270 && TYPE_MAIN_VARIANT (TREE_TYPE (retval
)) == TYPE_MAIN_VARIANT (valtype
)
7271 && ! current_function_returns_struct
)
7272 retval
= expand_target_expr (retval
);
7274 if (retval
== result
7275 /* Watch out for constructors, which "return" aggregates
7276 via initialization, but which otherwise "return" a pointer. */
7277 || DECL_CONSTRUCTOR_P (current_function_decl
))
7279 /* This is just an error--it's already been reported. */
7280 if (TYPE_SIZE (valtype
) == NULL_TREE
)
7283 if (TYPE_MODE (valtype
) != BLKmode
7284 && any_pending_cleanups (1))
7286 retval
= get_temp_regvar (valtype
, retval
);
7287 use_temp
= obey_regdecls
;
7290 else if (IS_AGGR_TYPE (valtype
) && current_function_returns_struct
)
7292 expand_aggr_init (result
, retval
, 0, LOOKUP_ONLYCONVERTING
);
7293 expand_cleanups_to (NULL_TREE
);
7294 DECL_INITIAL (result
) = NULL_TREE
;
7299 if (TYPE_MODE (valtype
) == VOIDmode
)
7301 if (TYPE_MODE (TREE_TYPE (result
)) != VOIDmode
7302 && warn_return_type
)
7303 warning ("return of void value in function returning non-void");
7304 expand_expr_stmt (retval
);
7308 else if (TYPE_MODE (valtype
) != BLKmode
7309 && any_pending_cleanups (1))
7311 retval
= get_temp_regvar (valtype
, retval
);
7312 expand_cleanups_to (NULL_TREE
);
7313 use_temp
= obey_regdecls
;
7318 retval
= convert_for_initialization (result
, valtype
, retval
,
7320 "return", NULL_TREE
, 0);
7321 DECL_INITIAL (result
) = NULL_TREE
;
7323 if (retval
== error_mark_node
)
7329 if (retval
!= NULL_TREE
7330 && TREE_CODE_CLASS (TREE_CODE (retval
)) == 'd'
7331 && cond_stack
== 0 && loop_stack
== 0 && case_stack
== 0)
7332 current_function_return_value
= retval
;
7336 /* Everything's great--RETVAL is in RESULT. */
7337 if (original_result_rtx
)
7339 store_expr (result
, original_result_rtx
, 0);
7340 expand_cleanups_to (NULL_TREE
);
7342 else if (retval
&& retval
!= result
)
7344 /* Clear this out so the later call to decl_function_context
7345 won't end up bombing on us. */
7346 if (DECL_CONTEXT (result
) == error_mark_node
)
7347 DECL_CONTEXT (result
) = NULL_TREE
;
7348 /* Here is where we finally get RETVAL into RESULT.
7349 `expand_return' does the magic of protecting
7350 RESULT from cleanups. */
7351 retval
= fold (build1 (CLEANUP_POINT_EXPR
, TREE_TYPE (result
),
7353 /* This part _must_ come second, because expand_return looks for
7354 the INIT_EXPR as the toplevel node only. :-( */
7355 retval
= build (INIT_EXPR
, TREE_TYPE (result
), result
, retval
);
7356 TREE_SIDE_EFFECTS (retval
) = 1;
7357 expand_return (retval
);
7360 expand_return (result
);
7362 use_variable (DECL_RTL (result
));
7363 if (ctor_label
&& TREE_CODE (ctor_label
) != ERROR_MARK
)
7364 expand_goto (ctor_label
);
7366 expand_null_return ();
7370 /* We may still need to put RETVAL into RESULT. */
7371 result
= DECL_RESULT (current_function_decl
);
7372 if (original_result_rtx
)
7374 /* Here we have a named return value that went
7375 into memory. We can compute RETVAL into that. */
7377 expand_assignment (result
, retval
, 0, 0);
7379 store_expr (result
, original_result_rtx
, 0);
7380 result
= make_tree (TREE_TYPE (result
), original_result_rtx
);
7382 else if (ctor_label
&& TREE_CODE (ctor_label
) != ERROR_MARK
)
7384 /* Here RETVAL is CURRENT_CLASS_DECL, so there's nothing to do. */
7385 expand_goto (ctor_label
);
7389 /* Here is where we finally get RETVAL into RESULT.
7390 `expand_return' does the magic of protecting
7391 RESULT from cleanups. */
7392 result
= build (INIT_EXPR
, TREE_TYPE (result
), result
, retval
);
7393 TREE_SIDE_EFFECTS (result
) = 1;
7394 expand_return (result
);
7396 else if (TYPE_MODE (TREE_TYPE (result
)) != VOIDmode
)
7397 expand_return (result
);
7400 current_function_returns_value
= returns_value
;
7402 /* These wind up after the BARRIER, which causes problems for
7403 expand_end_binding. What purpose were they supposed to serve? */
7404 if (original_result_rtx
)
7405 use_variable (original_result_rtx
);
7407 use_variable (DECL_RTL (DECL_RESULT (current_function_decl
)));
7410 /* One way to clear out cleanups that EXPR might
7411 generate. Note that this code will really be
7412 dead code, but that is ok--cleanups that were
7413 needed were handled by the magic of `return'. */
7414 expand_cleanups_to (NULL_TREE
);
7417 /* Start a C switch statement, testing expression EXP.
7418 Return EXP if it is valid, an error node otherwise. */
7421 c_expand_start_case (exp
)
7425 register enum tree_code code
;
7427 /* Convert from references, etc. */
7428 exp
= default_conversion (exp
);
7429 type
= TREE_TYPE (exp
);
7430 code
= TREE_CODE (type
);
7432 if (IS_AGGR_TYPE_CODE (code
))
7433 exp
= build_type_conversion (CONVERT_EXPR
, integer_type_node
, exp
, 1);
7435 if (exp
== NULL_TREE
)
7437 error ("switch quantity not an integer");
7438 exp
= error_mark_node
;
7440 type
= TREE_TYPE (exp
);
7441 code
= TREE_CODE (type
);
7443 if (code
!= INTEGER_TYPE
&& code
!= ENUMERAL_TYPE
&& code
!= ERROR_MARK
)
7445 error ("switch quantity not an integer");
7446 exp
= error_mark_node
;
7452 exp
= default_conversion (exp
);
7453 type
= TREE_TYPE (exp
);
7454 index
= get_unwidened (exp
, 0);
7455 /* We can't strip a conversion from a signed type to an unsigned,
7456 because if we did, int_fits_type_p would do the wrong thing
7457 when checking case values for being in range,
7458 and it's too hard to do the right thing. */
7459 if (TREE_UNSIGNED (TREE_TYPE (exp
))
7460 == TREE_UNSIGNED (TREE_TYPE (index
)))
7465 (1, fold (build1 (CLEANUP_POINT_EXPR
, TREE_TYPE (exp
), exp
)),
7466 type
, "switch statement");
7471 /* CONSTP remembers whether or not all the intervening pointers in the `to'
7472 type have been const. */
7474 comp_ptr_ttypes_real (to
, from
, constp
)
7478 for (; ; to
= TREE_TYPE (to
), from
= TREE_TYPE (from
))
7480 if (TREE_CODE (to
) != TREE_CODE (from
))
7483 if (TYPE_READONLY (from
) > TYPE_READONLY (to
)
7484 || TYPE_VOLATILE (from
) > TYPE_VOLATILE (to
))
7488 && (TYPE_READONLY (to
) > TYPE_READONLY (from
)
7489 || TYPE_VOLATILE (to
) > TYPE_READONLY (from
)))
7491 constp
&= TYPE_READONLY (to
);
7493 if (TREE_CODE (to
) != POINTER_TYPE
)
7494 return comptypes (TYPE_MAIN_VARIANT (to
), TYPE_MAIN_VARIANT (from
), 1);
7498 /* When comparing, say, char ** to char const **, this function takes the
7499 'char *' and 'char const *'. Do not pass non-pointer types to this
7502 comp_ptr_ttypes (to
, from
)
7505 return comp_ptr_ttypes_real (to
, from
, 1);