1 /* Build expressions with type checking for C++ compiler.
2 Copyright (C) 1987, 88, 89, 92, 93, 94, 1995 Free Software Foundation, Inc.
3 Hacked by Michael Tiemann (tiemann@cygnus.com)
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
22 /* This file is part of the C++ front end.
23 It contains routines to build C++ expressions given their operands,
24 including computing the types of the result, C and C++ specific error
25 checks, and some optimization.
27 There are also routines to build RETURN_STMT nodes and CASE_STMT nodes,
28 and to process initializations in declarations (since they work
29 like a strange sort of assignment). */
32 extern void warning ();
41 int mark_addressable ();
42 static tree
convert_for_assignment ();
43 /* static */ tree
convert_for_initialization ();
44 extern tree
shorten_compare ();
45 extern void binary_op_error ();
46 static tree
pointer_int_sum ();
47 static tree
pointer_diff ();
48 static tree
convert_sequence ();
49 /* static */ tree
unary_complex_lvalue ();
50 static tree get_delta_difference
PROTO((tree
, tree
, int));
52 extern rtx original_result_rtx
;
54 /* Return the target type of TYPE, which meas return T for:
55 T*, T&, T[], T (...), and otherwise, just T. */
61 if (TREE_CODE (type
) == REFERENCE_TYPE
)
62 type
= TREE_TYPE (type
);
63 while (TREE_CODE (type
) == POINTER_TYPE
64 || TREE_CODE (type
) == ARRAY_TYPE
65 || TREE_CODE (type
) == FUNCTION_TYPE
66 || TREE_CODE (type
) == METHOD_TYPE
67 || TREE_CODE (type
) == OFFSET_TYPE
)
68 type
= TREE_TYPE (type
);
72 /* Do `exp = require_complete_type (exp);' to make sure exp
73 does not have an incomplete type. (That includes void types.) */
76 require_complete_type (value
)
79 tree type
= TREE_TYPE (value
);
81 /* First, detect a valid value with a complete type. */
82 if (TYPE_SIZE (type
) != 0
83 && type
!= void_type_node
84 && ! (TYPE_LANG_SPECIFIC (type
)
85 && (IS_SIGNATURE_POINTER (type
) || IS_SIGNATURE_REFERENCE (type
))
86 && TYPE_SIZE (SIGNATURE_TYPE (type
)) == 0))
89 /* If we see X::Y, we build an OFFSET_TYPE which has
90 not been laid out. Try to avoid an error by interpreting
91 it as this->X::Y, if reasonable. */
92 if (TREE_CODE (value
) == OFFSET_REF
94 && TREE_OPERAND (value
, 0) == C_C_D
)
96 tree base
, member
= TREE_OPERAND (value
, 1);
97 tree basetype
= TYPE_OFFSET_BASETYPE (type
);
98 my_friendly_assert (TREE_CODE (member
) == FIELD_DECL
, 305);
99 base
= convert_pointer_to (basetype
, current_class_decl
);
100 value
= build (COMPONENT_REF
, TREE_TYPE (member
),
101 build_indirect_ref (base
, NULL_PTR
), member
);
102 return require_complete_type (value
);
105 incomplete_type_error (value
, type
);
106 return error_mark_node
;
109 /* Return truthvalue of whether type of EXP is instantiated. */
114 return (TREE_CODE (exp
) == TREE_LIST
115 || TREE_TYPE (exp
) == unknown_type_node
116 || (TREE_CODE (TREE_TYPE (exp
)) == OFFSET_TYPE
117 && TREE_TYPE (TREE_TYPE (exp
)) == unknown_type_node
));
120 /* Return truthvalue of whether T is function (or pfn) type. */
125 return (TREE_CODE (t
) == FUNCTION_TYPE
|| TREE_CODE (t
) == METHOD_TYPE
126 || (TREE_CODE (t
) == POINTER_TYPE
127 && (TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
128 || TREE_CODE (TREE_TYPE (t
)) == METHOD_TYPE
)));
131 /* Do `exp = require_instantiated_type (type, exp);' to make sure EXP
132 does not have an uninstantiated type.
133 TYPE is type to instantiate with, if uninstantiated. */
135 require_instantiated_type (type
, exp
, errval
)
136 tree type
, exp
, errval
;
138 if (TREE_TYPE (exp
) == NULL_TREE
)
140 error ("argument list may not have an initializer list");
144 if (TREE_TYPE (exp
) == unknown_type_node
145 || (TREE_CODE (TREE_TYPE (exp
)) == OFFSET_TYPE
146 && TREE_TYPE (TREE_TYPE (exp
)) == unknown_type_node
))
148 exp
= instantiate_type (type
, exp
, 1);
149 if (TREE_TYPE (exp
) == error_mark_node
)
155 /* Return a variant of TYPE which has all the type qualifiers of LIKE
156 as well as those of TYPE. */
159 qualify_type (type
, like
)
162 int constflag
= TYPE_READONLY (type
) || TYPE_READONLY (like
);
163 int volflag
= TYPE_VOLATILE (type
) || TYPE_VOLATILE (like
);
164 /* @@ Must do member pointers here. */
165 return cp_build_type_variant (type
, constflag
, volflag
);
168 /* Return the common type of two parameter lists.
169 We assume that comptypes has already been done and returned 1;
170 if that isn't so, this may crash.
172 As an optimization, free the space we allocate if the parameter
173 lists are already common. */
179 tree oldargs
= p1
, newargs
, n
;
182 char *first_obj
= (char *) oballoc (0);
184 len
= list_length (p1
);
185 newargs
= tree_last (p1
);
187 if (newargs
== void_list_node
)
196 newargs
= tree_cons (NULL_TREE
, NULL_TREE
, newargs
);
201 p1
= TREE_CHAIN (p1
), p2
= TREE_CHAIN (p2
), n
= TREE_CHAIN (n
), i
++)
203 if (TREE_PURPOSE (p1
) && !TREE_PURPOSE (p2
))
205 TREE_PURPOSE (n
) = TREE_PURPOSE (p1
);
208 else if (! TREE_PURPOSE (p1
))
210 if (TREE_PURPOSE (p2
))
212 TREE_PURPOSE (n
) = TREE_PURPOSE (p2
);
218 int cmp
= simple_cst_equal (TREE_PURPOSE (p1
), TREE_PURPOSE (p2
));
220 my_friendly_abort (111);
223 TREE_PURPOSE (n
) = TREE_PURPOSE (p2
);
225 if (TREE_VALUE (p1
) != TREE_VALUE (p2
))
228 TREE_VALUE (n
) = common_type (TREE_VALUE (p1
), TREE_VALUE (p2
));
231 TREE_VALUE (n
) = TREE_VALUE (p1
);
242 /* Return the common type of two types.
243 We assume that comptypes has already been done and returned 1;
244 if that isn't so, this may crash.
246 This is the type for the result of most arithmetic operations
247 if the operands have the given two types.
249 We do not deal with enumeral types here because they have already been
250 converted to integer types. */
256 register enum tree_code code1
;
257 register enum tree_code code2
;
260 /* Save time if the two types are the same. */
262 if (t1
== t2
) return t1
;
264 /* If one type is nonsense, use the other. */
265 if (t1
== error_mark_node
)
267 if (t2
== error_mark_node
)
270 /* Merge the attributes */
272 { register tree a1
, a2
;
273 a1
= TYPE_ATTRIBUTES (t1
);
274 a2
= TYPE_ATTRIBUTES (t2
);
276 /* Either one unset? Take the set one. */
278 if (!(attributes
= a1
))
281 /* One that completely contains the other? Take it. */
283 else if (a2
&& !attribute_list_contained (a1
, a2
))
284 if (attribute_list_contained (a2
, a1
))
288 /* Pick the longest list, and hang on the other
291 if (list_length (a1
) < list_length (a2
))
292 attributes
= a2
, a2
= a1
;
294 for (; a2
; a2
= TREE_CHAIN (a2
))
295 if (!value_member (attributes
, a2
))
298 TREE_CHAIN (a1
) = attributes
;
304 /* Treat an enum type as the unsigned integer type of the same width. */
306 if (TREE_CODE (t1
) == ENUMERAL_TYPE
)
307 t1
= type_for_size (TYPE_PRECISION (t1
), 1);
308 if (TREE_CODE (t2
) == ENUMERAL_TYPE
)
309 t2
= type_for_size (TYPE_PRECISION (t2
), 1);
311 code1
= TREE_CODE (t1
);
312 code2
= TREE_CODE (t2
);
318 /* If only one is real, use it as the result. */
320 if (code1
== REAL_TYPE
&& code2
!= REAL_TYPE
)
321 return build_type_attribute_variant (t1
, attributes
);
323 if (code2
== REAL_TYPE
&& code1
!= REAL_TYPE
)
324 return build_type_attribute_variant (t2
, attributes
);
326 /* Both real or both integers; use the one with greater precision. */
328 if (TYPE_PRECISION (t1
) > TYPE_PRECISION (t2
))
329 return build_type_attribute_variant (t1
, attributes
);
330 else if (TYPE_PRECISION (t2
) > TYPE_PRECISION (t1
))
331 return build_type_attribute_variant (t2
, attributes
);
333 /* Same precision. Prefer longs to ints even when same size. */
335 if (TYPE_MAIN_VARIANT (t1
) == long_unsigned_type_node
336 || TYPE_MAIN_VARIANT (t2
) == long_unsigned_type_node
)
337 return build_type_attribute_variant (long_unsigned_type_node
,
340 if (TYPE_MAIN_VARIANT (t1
) == long_integer_type_node
341 || TYPE_MAIN_VARIANT (t2
) == long_integer_type_node
)
343 /* But preserve unsignedness from the other type,
344 since long cannot hold all the values of an unsigned int. */
345 if (TREE_UNSIGNED (t1
) || TREE_UNSIGNED (t2
))
346 t1
= long_unsigned_type_node
;
348 t1
= long_integer_type_node
;
349 return build_type_attribute_variant (t1
, attributes
);
352 if (TYPE_MAIN_VARIANT (t1
) == long_double_type_node
353 || TYPE_MAIN_VARIANT (t2
) == long_double_type_node
)
354 return build_type_attribute_variant (long_double_type_node
,
357 /* Otherwise prefer the unsigned one. */
359 if (TREE_UNSIGNED (t1
))
360 return build_type_attribute_variant (t1
, attributes
);
362 return build_type_attribute_variant (t2
, attributes
);
366 /* For two pointers, do this recursively on the target type,
367 and combine the qualifiers of the two types' targets. */
368 /* This code was turned off; I don't know why.
369 But ANSI C++ specifies doing this with the qualifiers.
370 So I turned it on again. */
372 tree tt1
= TYPE_MAIN_VARIANT (TREE_TYPE (t1
));
373 tree tt2
= TYPE_MAIN_VARIANT (TREE_TYPE (t2
));
375 = TYPE_READONLY (TREE_TYPE (t1
)) || TYPE_READONLY (TREE_TYPE (t2
));
377 = TYPE_VOLATILE (TREE_TYPE (t1
)) || TYPE_VOLATILE (TREE_TYPE (t2
));
382 else if (tt1
== void_type_node
|| tt2
== void_type_node
)
383 target
= void_type_node
;
385 target
= common_type (tt1
, tt2
);
387 target
= cp_build_type_variant (target
, constp
, volatilep
);
388 if (code1
== POINTER_TYPE
)
389 t1
= build_pointer_type (target
);
391 t1
= build_reference_type (target
);
392 t1
= build_type_attribute_variant (t1
, attributes
);
394 if (TREE_CODE (target
) == METHOD_TYPE
)
395 t1
= build_ptrmemfunc_type (t1
);
401 t1
= build_pointer_type (common_type (TREE_TYPE (t1
), TREE_TYPE (t2
)));
402 return build_type_attribute_variant (t1
, attributes
);
405 t1
= build_reference_type (common_type (TREE_TYPE (t1
), TREE_TYPE (t2
)));
406 return build_type_attribute_variant (t1
, attributes
);
411 tree elt
= common_type (TREE_TYPE (t1
), TREE_TYPE (t2
));
412 /* Save space: see if the result is identical to one of the args. */
413 if (elt
== TREE_TYPE (t1
) && TYPE_DOMAIN (t1
))
414 return build_type_attribute_variant (t1
, attributes
);
415 if (elt
== TREE_TYPE (t2
) && TYPE_DOMAIN (t2
))
416 return build_type_attribute_variant (t2
, attributes
);
417 /* Merge the element types, and have a size if either arg has one. */
418 t1
= build_array_type (elt
, TYPE_DOMAIN (TYPE_DOMAIN (t1
) ? t1
: t2
));
419 return build_type_attribute_variant (t1
, attributes
);
423 /* Function types: prefer the one that specified arg types.
424 If both do, merge the arg types. Also merge the return types. */
426 tree valtype
= common_type (TREE_TYPE (t1
), TREE_TYPE (t2
));
427 tree p1
= TYPE_ARG_TYPES (t1
);
428 tree p2
= TYPE_ARG_TYPES (t2
);
431 /* Save space: see if the result is identical to one of the args. */
432 if (valtype
== TREE_TYPE (t1
) && ! p2
)
433 return build_type_attribute_variant (t1
, attributes
);
434 if (valtype
== TREE_TYPE (t2
) && ! p1
)
435 return build_type_attribute_variant (t2
, attributes
);
437 /* Simple way if one arg fails to specify argument types. */
438 if (p1
== NULL_TREE
|| TREE_VALUE (p1
) == void_type_node
)
440 rval
= build_function_type (valtype
, p2
);
441 if ((raises
= TYPE_RAISES_EXCEPTIONS (t2
)))
442 rval
= build_exception_variant (NULL_TREE
, rval
, raises
);
443 return build_type_attribute_variant (rval
, attributes
);
445 raises
= TYPE_RAISES_EXCEPTIONS (t1
);
446 if (p2
== NULL_TREE
|| TREE_VALUE (p2
) == void_type_node
)
448 rval
= build_function_type (valtype
, p1
);
450 rval
= build_exception_variant (NULL_TREE
, rval
, raises
);
451 return build_type_attribute_variant (rval
, attributes
);
454 rval
= build_function_type (valtype
, commonparms (p1
, p2
));
455 rval
= build_exception_variant (NULL_TREE
, rval
, raises
);
456 return build_type_attribute_variant (rval
, attributes
);
461 my_friendly_assert (TYPE_MAIN_VARIANT (t1
) == t1
462 && TYPE_MAIN_VARIANT (t2
) == t2
, 306);
464 if (DERIVED_FROM_P (t1
, t2
) && binfo_or_else (t1
, t2
))
465 return build_type_attribute_variant (t1
, attributes
);
466 else if (binfo_or_else (t2
, t1
))
467 return build_type_attribute_variant (t2
, attributes
);
469 compiler_error ("common_type called with uncommon aggregate types");
472 if (TREE_CODE (TREE_TYPE (t1
)) == TREE_CODE (TREE_TYPE (t2
)))
474 /* Get this value the long way, since TYPE_METHOD_BASETYPE
475 is just the main variant of this. */
479 tree b1
= TYPE_OFFSET_BASETYPE (t1
);
480 tree b2
= TYPE_OFFSET_BASETYPE (t2
);
482 if (DERIVED_FROM_P (b1
, b2
) && binfo_or_else (b1
, b2
))
483 basetype
= TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t2
)));
486 if (binfo_or_else (b2
, b1
) == NULL_TREE
)
487 compiler_error ("common_type called with uncommon method types");
488 basetype
= TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t1
)));
491 raises
= TYPE_RAISES_EXCEPTIONS (t1
);
493 /* If this was a member function type, get back to the
494 original type of type member function (i.e., without
495 the class instance variable up front. */
496 t1
= build_function_type (TREE_TYPE (t1
), TREE_CHAIN (TYPE_ARG_TYPES (t1
)));
497 t2
= build_function_type (TREE_TYPE (t2
), TREE_CHAIN (TYPE_ARG_TYPES (t2
)));
498 t3
= common_type (t1
, t2
);
499 t3
= build_cplus_method_type (basetype
, TREE_TYPE (t3
), TYPE_ARG_TYPES (t3
));
500 t1
= build_exception_variant (basetype
, t3
, raises
);
503 compiler_error ("common_type called with uncommon method types");
505 return build_type_attribute_variant (t1
, attributes
);
508 if (TREE_TYPE (t1
) == TREE_TYPE (t2
))
510 tree b1
= TYPE_OFFSET_BASETYPE (t1
);
511 tree b2
= TYPE_OFFSET_BASETYPE (t2
);
513 if (DERIVED_FROM_P (b1
, b2
) && binfo_or_else (b1
, b2
))
514 return build_type_attribute_variant (t2
, attributes
);
515 else if (binfo_or_else (b2
, b1
))
516 return build_type_attribute_variant (t1
, attributes
);
518 compiler_error ("common_type called with uncommon member types");
521 return build_type_attribute_variant (t1
, attributes
);
525 /* Return 1 if TYPE1 and TYPE2 raise the same exceptions. */
527 compexcepttypes (t1
, t2
, strict
)
531 return TYPE_RAISES_EXCEPTIONS (t1
) == TYPE_RAISES_EXCEPTIONS (t2
);
535 comp_array_types (cmp
, t1
, t2
, strict
)
536 register int (*cmp
)();
540 tree d1
= TYPE_DOMAIN (t1
);
541 tree d2
= TYPE_DOMAIN (t2
);
543 /* Target types must match incl. qualifiers. */
544 if (!(TREE_TYPE (t1
) == TREE_TYPE (t2
)
545 || (*cmp
) (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
)))
548 /* Sizes must match unless one is missing or variable. */
549 if (d1
== 0 || d2
== 0 || d1
== d2
550 || TREE_CODE (TYPE_MIN_VALUE (d1
)) != INTEGER_CST
551 || TREE_CODE (TYPE_MIN_VALUE (d2
)) != INTEGER_CST
552 || TREE_CODE (TYPE_MAX_VALUE (d1
)) != INTEGER_CST
553 || TREE_CODE (TYPE_MAX_VALUE (d2
)) != INTEGER_CST
)
556 return ((TREE_INT_CST_LOW (TYPE_MIN_VALUE (d1
))
557 == TREE_INT_CST_LOW (TYPE_MIN_VALUE (d2
)))
558 && (TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d1
))
559 == TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d2
)))
560 && (TREE_INT_CST_LOW (TYPE_MAX_VALUE (d1
))
561 == TREE_INT_CST_LOW (TYPE_MAX_VALUE (d2
)))
562 && (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d1
))
563 == TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d2
))));
566 /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
567 or various other operations. This is what ANSI C++ speaks of as
570 For C++: argument STRICT says we should be strict about this
573 2 : strict, except that if one type is a reference and
574 the other is not, compare the target type of the
575 reference to the type that's not a reference (ARM, p308).
576 This is used for checking for invalid overloading.
577 1 : strict (compared according to ANSI C)
578 This is used for checking whether two function decls match.
579 0 : <= (compared according to C++)
580 -1: <= or >= (relaxed)
582 Otherwise, pointers involving base classes and derived classes
583 can be mixed as valid: i.e. a pointer to a base class may be assigned
584 to a pointer to one of its derived classes, as per C++. A pointer to
585 a derived class may be passed as a parameter to a function expecting a
586 pointer to a base classes. These allowances do not commute. In this
587 case, TYPE1 is assumed to be the base class, and TYPE2 is assumed to
588 be the derived class. */
590 comptypes (type1
, type2
, strict
)
594 register tree t1
= type1
;
595 register tree t2
= type2
;
598 /* Suppress errors caused by previously reported errors */
603 /* This should never happen. */
604 my_friendly_assert (t1
!= error_mark_node
, 307);
606 if (t2
== error_mark_node
)
611 /* Treat an enum type as the unsigned integer type of the same width. */
613 if (TREE_CODE (t1
) == ENUMERAL_TYPE
)
614 t1
= type_for_size (TYPE_PRECISION (t1
), 1);
615 if (TREE_CODE (t2
) == ENUMERAL_TYPE
)
616 t2
= type_for_size (TYPE_PRECISION (t2
), 1);
622 /* Different classes of types can't be compatible. */
624 if (TREE_CODE (t1
) != TREE_CODE (t2
))
627 && ((TREE_CODE (t1
) == REFERENCE_TYPE
)
628 ^ (TREE_CODE (t2
) == REFERENCE_TYPE
)))
630 if (TREE_CODE (t1
) == REFERENCE_TYPE
)
631 return comptypes (TREE_TYPE (t1
), t2
, 1);
632 return comptypes (t1
, TREE_TYPE (t2
), 1);
640 /* Qualifiers must match. */
642 if (TYPE_READONLY (t1
) != TYPE_READONLY (t2
))
644 if (TYPE_VOLATILE (t1
) != TYPE_VOLATILE (t2
))
647 /* Allow for two different type nodes which have essentially the same
648 definition. Note that we already checked for equality of the type
649 type qualifiers (just above). */
651 if (TYPE_MAIN_VARIANT (t1
) == TYPE_MAIN_VARIANT (t2
))
654 #ifdef COMP_TYPE_ATTRIBUTES
655 if (! (attrval
= COMP_TYPE_ATTRIBUTES (t1
, t2
)))
658 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
662 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
665 switch (TREE_CODE (t1
))
674 val
= (comptypes (TYPE_POINTER_TO (TYPE_OFFSET_BASETYPE (t1
)),
675 TYPE_POINTER_TO (TYPE_OFFSET_BASETYPE (t2
)), strict
)
676 && comptypes (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
));
680 if (! compexcepttypes (t1
, t2
, strict
))
683 /* This case is anti-symmetrical!
684 One can pass a base member (or member function)
685 to something expecting a derived member (or member function),
686 but not vice-versa! */
688 val
= (comptypes (TYPE_POINTER_TO (TYPE_METHOD_BASETYPE (t2
)),
689 TYPE_POINTER_TO (TYPE_METHOD_BASETYPE (t1
)), strict
)
690 && comptypes (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
)
691 && compparms (TREE_CHAIN (TYPE_ARG_TYPES (t1
)),
692 TREE_CHAIN (TYPE_ARG_TYPES (t2
)), strict
));
706 if (TREE_CODE (t1
) == RECORD_TYPE
&& TREE_CODE (t2
) == RECORD_TYPE
)
710 rval
= t1
== t2
|| UNIQUELY_DERIVED_FROM_P (t1
, t2
);
719 val
= UNIQUELY_DERIVED_FROM_P (t2
, t1
);
726 val
= comptypes (t1
, t2
, strict
);
730 if (! compexcepttypes (t1
, t2
, strict
))
733 val
= ((TREE_TYPE (t1
) == TREE_TYPE (t2
)
734 || comptypes (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
))
735 && compparms (TYPE_ARG_TYPES (t1
), TYPE_ARG_TYPES (t2
), strict
));
739 /* Target types must match incl. qualifiers. */
740 val
= comp_array_types (comptypes
, t1
, t2
, strict
);
743 case TEMPLATE_TYPE_PARM
:
746 case UNINSTANTIATED_P_TYPE
:
747 if (UPT_TEMPLATE (t1
) != UPT_TEMPLATE (t2
))
750 int i
= TREE_VEC_LENGTH (UPT_PARMS (t1
));
751 tree
*p1
= &TREE_VEC_ELT (UPT_PARMS (t1
), 0);
752 tree
*p2
= &TREE_VEC_ELT (UPT_PARMS (t2
), 0);
756 if (TREE_CODE_CLASS (TREE_CODE (p1
[i
])) == 't')
758 if (! comptypes (p1
[i
], p2
[i
], 1))
763 if (simple_cst_equal (p1
[i
], p2
[i
]) <= 0)
770 return attrval
== 2 && val
== 1 ? 2 : val
;
773 /* Return 1 if TTL and TTR are pointers to types that are equivalent,
774 ignoring their qualifiers.
776 NPTRS is the number of pointers we can strip off and keep cool.
777 This is used to permit (for aggr A, aggr B) A, B* to convert to A*,
778 but to not permit B** to convert to A**. */
781 comp_target_types (ttl
, ttr
, nptrs
)
785 ttl
= TYPE_MAIN_VARIANT (ttl
);
786 ttr
= TYPE_MAIN_VARIANT (ttr
);
790 if (TREE_CODE (ttr
) != TREE_CODE (ttl
))
793 if (TREE_CODE (ttr
) == POINTER_TYPE
)
795 ttl
= TREE_TYPE (ttl
);
796 ttr
= TREE_TYPE (ttr
);
800 if (TREE_CODE (ttl
) == VOID_TYPE
801 && TREE_CODE (ttr
) != FUNCTION_TYPE
802 && TREE_CODE (ttr
) != METHOD_TYPE
803 && TREE_CODE (ttr
) != OFFSET_TYPE
)
805 else if (TREE_CODE (ttr
) == VOID_TYPE
806 && TREE_CODE (ttl
) != FUNCTION_TYPE
807 && TREE_CODE (ttl
) != METHOD_TYPE
808 && TREE_CODE (ttl
) != OFFSET_TYPE
)
810 else if (TREE_CODE (ttl
) == POINTER_TYPE
811 || TREE_CODE (ttl
) == ARRAY_TYPE
)
812 return comp_ptr_ttypes (ttl
, ttr
);
815 return comp_target_types (ttl
, ttr
, nptrs
- 1);
818 if (TREE_CODE (ttr
) == REFERENCE_TYPE
)
819 return comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), nptrs
);
820 if (TREE_CODE (ttr
) == ARRAY_TYPE
)
821 return comp_array_types (comp_target_types
, ttl
, ttr
, 0);
822 else if (TREE_CODE (ttr
) == FUNCTION_TYPE
|| TREE_CODE (ttr
) == METHOD_TYPE
)
823 if (comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), nptrs
))
824 switch (comp_target_parms (TYPE_ARG_TYPES (ttl
), TYPE_ARG_TYPES (ttr
), 1))
833 my_friendly_abort (112);
839 else if (TREE_CODE (ttr
) == OFFSET_TYPE
)
841 /* Contravariance: we can assign a pointer to base member to a pointer
842 to derived member. Note difference from simple pointer case, where
843 we can pass a pointer to derived to a pointer to base. */
844 if (comptypes (TYPE_OFFSET_BASETYPE (ttr
), TYPE_OFFSET_BASETYPE (ttl
), 0))
845 return comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), nptrs
);
846 else if (comptypes (TYPE_OFFSET_BASETYPE (ttl
), TYPE_OFFSET_BASETYPE (ttr
), 0)
847 && comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), nptrs
))
850 else if (IS_AGGR_TYPE (ttl
))
854 if (comptypes (TYPE_POINTER_TO (ttl
), TYPE_POINTER_TO (ttr
), 0))
856 if (comptypes (TYPE_POINTER_TO (ttr
), TYPE_POINTER_TO (ttl
), 0))
864 /* If two types share a common base type, return that basetype.
865 If there is not a unique most-derived base type, this function
866 returns ERROR_MARK_NODE. */
868 common_base_type (tt1
, tt2
)
871 tree best
= NULL_TREE
, tmp
;
874 /* If one is a baseclass of another, that's good enough. */
875 if (UNIQUELY_DERIVED_FROM_P (tt1
, tt2
))
877 if (UNIQUELY_DERIVED_FROM_P (tt2
, tt1
))
881 /* If they share a virtual baseclass, that's good enough. */
882 for (tmp
= CLASSTYPE_VBASECLASSES (tt1
); tmp
; tmp
= TREE_CHAIN (tmp
))
884 if (binfo_member (BINFO_TYPE (tmp
), CLASSTYPE_VBASECLASSES (tt2
)))
885 return BINFO_TYPE (tmp
);
889 /* Otherwise, try to find a unique baseclass of TT1
890 that is shared by TT2, and follow that down. */
891 for (i
= CLASSTYPE_N_BASECLASSES (tt1
)-1; i
>= 0; i
--)
893 tree basetype
= TYPE_BINFO_BASETYPE (tt1
, i
);
894 tree trial
= common_base_type (basetype
, tt2
);
897 if (trial
== error_mark_node
)
899 if (best
== NULL_TREE
)
901 else if (best
!= trial
)
902 return error_mark_node
;
907 for (i
= CLASSTYPE_N_BASECLASSES (tt2
)-1; i
>= 0; i
--)
909 tree basetype
= TYPE_BINFO_BASETYPE (tt2
, i
);
910 tree trial
= common_base_type (tt1
, basetype
);
913 if (trial
== error_mark_node
)
915 if (best
== NULL_TREE
)
917 else if (best
!= trial
)
918 return error_mark_node
;
924 /* Subroutines of `comptypes'. */
926 /* Return 1 if two parameter type lists PARMS1 and PARMS2
927 are equivalent in the sense that functions with those parameter types
928 can have equivalent types.
929 If either list is empty, we win.
930 Otherwise, the two lists must be equivalent, element by element.
932 C++: See comment above about TYPE1, TYPE2, STRICT.
933 If STRICT == 3, it means checking is strict, but do not compare
934 default parameter values. */
936 compparms (parms1
, parms2
, strict
)
940 register tree t1
= parms1
, t2
= parms2
;
942 /* An unspecified parmlist matches any specified parmlist
943 whose argument types don't need default promotions. */
945 if (strict
<= 0 && t1
== 0)
946 return self_promoting_args_p (t2
);
947 if (strict
< 0 && t2
== 0)
948 return self_promoting_args_p (t1
);
952 if (t1
== 0 && t2
== 0)
954 /* If one parmlist is shorter than the other,
955 they fail to match, unless STRICT is <= 0. */
956 if (t1
== 0 || t2
== 0)
963 return t1
&& TREE_PURPOSE (t1
);
965 if (! comptypes (TREE_VALUE (t2
), TREE_VALUE (t1
), strict
))
970 return t2
== void_list_node
&& TREE_PURPOSE (t1
);
971 return TREE_PURPOSE (t1
) || TREE_PURPOSE (t2
);
974 /* Default parms are not part of the type of a function. */
975 if (strict
!= 3 && TREE_PURPOSE (t1
) && TREE_PURPOSE (t2
))
977 int cmp
= simple_cst_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
));
979 my_friendly_abort (113);
985 t1
= TREE_CHAIN (t1
);
986 t2
= TREE_CHAIN (t2
);
990 /* This really wants return whether or not parameter type lists
991 would make their owning functions assignment compatible or not. */
993 comp_target_parms (parms1
, parms2
, strict
)
997 register tree t1
= parms1
, t2
= parms2
;
998 int warn_contravariance
= 0;
1000 /* An unspecified parmlist matches any specified parmlist
1001 whose argument types don't need default promotions.
1002 @@@ see 13.3.3 for a counterexample... */
1004 if (t1
== 0 && t2
!= 0)
1006 cp_pedwarn ("ANSI C++ prohibits conversion from `(%#T)' to `(...)'",
1008 return self_promoting_args_p (t2
);
1011 return self_promoting_args_p (t1
);
1013 for (; t1
|| t2
; t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
))
1017 /* If one parmlist is shorter than the other,
1018 they fail to match, unless STRICT is <= 0. */
1019 if (t1
== 0 || t2
== 0)
1024 return 1 + warn_contravariance
;
1025 return ((t1
&& TREE_PURPOSE (t1
)) + warn_contravariance
);
1027 p1
= TREE_VALUE (t1
);
1028 p2
= TREE_VALUE (t2
);
1032 if ((TREE_CODE (p1
) == POINTER_TYPE
&& TREE_CODE (p2
) == POINTER_TYPE
)
1033 || (TREE_CODE (p1
) == REFERENCE_TYPE
&& TREE_CODE (p2
) == REFERENCE_TYPE
))
1036 && (TYPE_MAIN_VARIANT (TREE_TYPE (p1
))
1037 == TYPE_MAIN_VARIANT (TREE_TYPE (p2
))))
1040 /* The following is wrong for contravariance,
1041 but many programs depend on it. */
1042 if (TREE_TYPE (p1
) == void_type_node
)
1044 if (TREE_TYPE (p2
) == void_type_node
)
1046 warn_contravariance
= 1;
1049 if (IS_AGGR_TYPE (TREE_TYPE (p1
)))
1051 if (comptypes (p2
, p1
, 0) == 0)
1053 if (comptypes (p1
, p2
, 0) != 0)
1054 warn_contravariance
= 1;
1061 /* Note backwards order due to contravariance. */
1062 if (comp_target_types (p2
, p1
, 1) == 0)
1064 if (comp_target_types (p1
, p2
, 1))
1066 warn_contravariance
= 1;
1072 /* What good do these cases do? */
1074 return p2
== void_type_node
&& TREE_PURPOSE (t1
);
1075 return TREE_PURPOSE (t1
) || TREE_PURPOSE (t2
);
1078 /* Target types are compatible--just make sure that if
1079 we use parameter lists, that they are ok as well. */
1080 if (TREE_CODE (p1
) == FUNCTION_TYPE
|| TREE_CODE (p1
) == METHOD_TYPE
)
1081 switch (comp_target_parms (TYPE_ARG_TYPES (p1
),
1082 TYPE_ARG_TYPES (p2
),
1090 warn_contravariance
= 1;
1093 if (TREE_PURPOSE (t1
) && TREE_PURPOSE (t2
))
1095 int cmp
= simple_cst_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
));
1097 my_friendly_abort (114);
1102 return 1 + warn_contravariance
;
1105 /* Return 1 if PARMS specifies a fixed number of parameters
1106 and none of their types is affected by default promotions. */
1109 self_promoting_args_p (parms
)
1113 for (t
= parms
; t
; t
= TREE_CHAIN (t
))
1115 register tree type
= TREE_VALUE (t
);
1117 if (TREE_CHAIN (t
) == 0 && type
!= void_type_node
)
1120 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
1126 if (C_PROMOTING_INTEGER_TYPE_P (type
))
1132 /* Return an unsigned type the same as TYPE in other respects.
1134 C++: must make these work for type variants as well. */
1137 unsigned_type (type
)
1140 tree type1
= TYPE_MAIN_VARIANT (type
);
1141 if (type1
== signed_char_type_node
|| type1
== char_type_node
)
1142 return unsigned_char_type_node
;
1143 if (type1
== integer_type_node
)
1144 return unsigned_type_node
;
1145 if (type1
== short_integer_type_node
)
1146 return short_unsigned_type_node
;
1147 if (type1
== long_integer_type_node
)
1148 return long_unsigned_type_node
;
1149 if (type1
== long_long_integer_type_node
)
1150 return long_long_unsigned_type_node
;
1154 /* Return a signed type the same as TYPE in other respects. */
1160 tree type1
= TYPE_MAIN_VARIANT (type
);
1161 if (type1
== unsigned_char_type_node
|| type1
== char_type_node
)
1162 return signed_char_type_node
;
1163 if (type1
== unsigned_type_node
)
1164 return integer_type_node
;
1165 if (type1
== short_unsigned_type_node
)
1166 return short_integer_type_node
;
1167 if (type1
== long_unsigned_type_node
)
1168 return long_integer_type_node
;
1169 if (type1
== long_long_unsigned_type_node
)
1170 return long_long_integer_type_node
;
1174 /* Return a type the same as TYPE except unsigned or
1175 signed according to UNSIGNEDP. */
1178 signed_or_unsigned_type (unsignedp
, type
)
1182 if (! INTEGRAL_TYPE_P (type
))
1184 if (TYPE_PRECISION (type
) == TYPE_PRECISION (signed_char_type_node
))
1185 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
1186 if (TYPE_PRECISION (type
) == TYPE_PRECISION (integer_type_node
))
1187 return unsignedp
? unsigned_type_node
: integer_type_node
;
1188 if (TYPE_PRECISION (type
) == TYPE_PRECISION (short_integer_type_node
))
1189 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
1190 if (TYPE_PRECISION (type
) == TYPE_PRECISION (long_integer_type_node
))
1191 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
1192 if (TYPE_PRECISION (type
) == TYPE_PRECISION (long_long_integer_type_node
))
1193 return (unsignedp
? long_long_unsigned_type_node
1194 : long_long_integer_type_node
);
1202 enum tree_code code
= TREE_CODE (type
);
1205 if (code
== FUNCTION_TYPE
)
1207 if (pedantic
|| warn_pointer_arith
)
1208 pedwarn ("ANSI C++ forbids taking the sizeof a function type");
1209 return size_int (1);
1211 if (code
== METHOD_TYPE
)
1213 if (pedantic
|| warn_pointer_arith
)
1214 pedwarn ("ANSI C++ forbids taking the sizeof a method type");
1215 return size_int (1);
1217 if (code
== VOID_TYPE
)
1219 if (pedantic
|| warn_pointer_arith
)
1220 pedwarn ("ANSI C++ forbids taking the sizeof a void type");
1221 return size_int (1);
1223 if (code
== ERROR_MARK
)
1224 return size_int (1);
1226 /* ARM $5.3.2: ``When applied to a reference, the result is the size of the
1227 referenced object.'' */
1228 if (code
== REFERENCE_TYPE
)
1229 type
= TREE_TYPE (type
);
1231 /* We couldn't find anything in the ARM or the draft standard that says,
1232 one way or the other, if doing sizeof on something that doesn't have
1233 an object associated with it is correct or incorrect. For example, if
1234 you declare `struct S { char str[16]; };', and in your program do
1235 a `sizeof (S::str)', should we flag that as an error or should we give
1236 the size of it? Since it seems like a reasonable thing to do, we'll go
1237 with giving the value. */
1238 if (code
== OFFSET_TYPE
)
1239 type
= TREE_TYPE (type
);
1241 /* @@ This also produces an error for a signature ref.
1242 In that case we should be able to do better. */
1243 if (IS_SIGNATURE (type
))
1245 error ("`sizeof' applied to a signature type");
1246 return size_int (0);
1249 if (TYPE_SIZE (type
) == 0)
1251 error ("`sizeof' applied to an incomplete type");
1252 return size_int (0);
1255 /* Convert in case a char is more than one unit. */
1256 t
= size_binop (CEIL_DIV_EXPR
, TYPE_SIZE (type
),
1257 size_int (TYPE_PRECISION (char_type_node
)));
1258 /* size_binop does not put the constant in range, so do it now. */
1259 if (TREE_CODE (t
) == INTEGER_CST
&& force_fit_type (t
, 0))
1260 TREE_CONSTANT_OVERFLOW (t
) = TREE_OVERFLOW (t
) = 1;
1265 c_sizeof_nowarn (type
)
1268 enum tree_code code
= TREE_CODE (type
);
1271 if (code
== FUNCTION_TYPE
1272 || code
== METHOD_TYPE
1273 || code
== VOID_TYPE
1274 || code
== ERROR_MARK
)
1275 return size_int (1);
1276 if (code
== REFERENCE_TYPE
)
1277 type
= TREE_TYPE (type
);
1279 if (TYPE_SIZE (type
) == 0)
1282 /* ??? Tiemann, why have any diagnostic here?
1283 There is none in the corresponding function for C. */
1284 warning ("sizeof applied to an incomplete type");
1286 return size_int (0);
1289 /* Convert in case a char is more than one unit. */
1290 t
= size_binop (CEIL_DIV_EXPR
, TYPE_SIZE (type
),
1291 size_int (TYPE_PRECISION (char_type_node
)));
1292 force_fit_type (t
, 0);
1296 /* Implement the __alignof keyword: Return the minimum required
1297 alignment of TYPE, measured in bytes. */
1303 enum tree_code code
= TREE_CODE (type
);
1306 if (code
== FUNCTION_TYPE
|| code
== METHOD_TYPE
)
1307 return size_int (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
1309 if (code
== VOID_TYPE
|| code
== ERROR_MARK
)
1310 return size_int (1);
1312 /* C++: this is really correct! */
1313 if (code
== REFERENCE_TYPE
)
1314 type
= TREE_TYPE (type
);
1316 /* @@ This also produces an error for a signature ref.
1317 In that case we should be able to do better. */
1318 if (IS_SIGNATURE (type
))
1320 error ("`__alignof' applied to a signature type");
1321 return size_int (1);
1324 t
= size_int (TYPE_ALIGN (type
) / BITS_PER_UNIT
);
1325 force_fit_type (t
, 0);
1329 /* Perform default promotions for C data used in expressions.
1330 Arrays and functions are converted to pointers;
1331 enumeral types or short or char, to int.
1332 In addition, manifest constants symbols are replaced by their values.
1334 C++: this will automatically bash references to their target type. */
1337 default_conversion (exp
)
1340 register tree type
= TREE_TYPE (exp
);
1341 register enum tree_code code
= TREE_CODE (type
);
1343 if (code
== OFFSET_TYPE
/* || TREE_CODE (exp) == OFFSET_REF */ )
1345 if (TREE_CODE (exp
) == OFFSET_REF
)
1346 return default_conversion (resolve_offset_ref (exp
));
1348 type
= TREE_TYPE (type
);
1349 code
= TREE_CODE (type
);
1352 if (code
== REFERENCE_TYPE
)
1354 exp
= convert_from_reference (exp
);
1355 type
= TREE_TYPE (exp
);
1356 code
= TREE_CODE (type
);
1359 /* Constants can be used directly unless they're not loadable. */
1360 if (TREE_CODE (exp
) == CONST_DECL
)
1361 exp
= DECL_INITIAL (exp
);
1362 /* Replace a nonvolatile const static variable with its value. */
1363 else if (TREE_READONLY_DECL_P (exp
) && DECL_MODE (exp
) != BLKmode
)
1365 exp
= decl_constant_value (exp
);
1366 type
= TREE_TYPE (exp
);
1369 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
1370 Leave such NOP_EXPRs, since RHS is being used in non-lvalue context. */
1372 if (INTEGRAL_CODE_P (code
))
1374 tree t
= type_promotes_to (type
);
1376 return convert (t
, exp
);
1378 if (flag_traditional
1379 && TYPE_MAIN_VARIANT (type
) == float_type_node
)
1380 return convert (double_type_node
, exp
);
1381 if (code
== VOID_TYPE
)
1383 error ("void value not ignored as it ought to be");
1384 return error_mark_node
;
1386 if (code
== FUNCTION_TYPE
)
1388 return build_unary_op (ADDR_EXPR
, exp
, 0);
1390 if (code
== METHOD_TYPE
)
1392 if (TREE_CODE (exp
) == OFFSET_REF
)
1394 my_friendly_assert (TREE_CODE (TREE_OPERAND (exp
, 1)) == FUNCTION_DECL
,
1396 return build_unary_op (ADDR_EXPR
, TREE_OPERAND (exp
, 1), 0);
1398 return build_unary_op (ADDR_EXPR
, exp
, 0);
1400 if (code
== ARRAY_TYPE
)
1405 int constp
, volatilep
;
1407 if (TREE_CODE (exp
) == INDIRECT_REF
)
1409 /* Stripping away the INDIRECT_REF is not the right
1410 thing to do for references... */
1411 tree inner
= TREE_OPERAND (exp
, 0);
1412 if (TREE_CODE (TREE_TYPE (inner
)) == REFERENCE_TYPE
)
1414 inner
= build1 (CONVERT_EXPR
,
1415 build_pointer_type (TREE_TYPE (TREE_TYPE (inner
))),
1417 TREE_REFERENCE_EXPR (inner
) = 1;
1419 return convert (TYPE_POINTER_TO (TREE_TYPE (type
)), inner
);
1422 if (TREE_CODE (exp
) == COMPOUND_EXPR
)
1424 tree op1
= default_conversion (TREE_OPERAND (exp
, 1));
1425 return build (COMPOUND_EXPR
, TREE_TYPE (op1
),
1426 TREE_OPERAND (exp
, 0), op1
);
1430 && ! (TREE_CODE (exp
) == CONSTRUCTOR
&& TREE_STATIC (exp
)))
1432 error ("invalid use of non-lvalue array");
1433 return error_mark_node
;
1436 constp
= volatilep
= 0;
1437 if (TREE_CODE_CLASS (TREE_CODE (exp
)) == 'r'
1438 || TREE_CODE_CLASS (TREE_CODE (exp
)) == 'd')
1440 constp
= TREE_READONLY (exp
);
1441 volatilep
= TREE_THIS_VOLATILE (exp
);
1444 restype
= TREE_TYPE (type
);
1445 if (TYPE_READONLY (type
) || TYPE_VOLATILE (type
)
1446 || constp
|| volatilep
)
1447 restype
= cp_build_type_variant (restype
,
1448 TYPE_READONLY (type
) || constp
,
1449 TYPE_VOLATILE (type
) || volatilep
);
1450 ptrtype
= build_pointer_type (restype
);
1452 if (TREE_CODE (exp
) == VAR_DECL
)
1454 /* ??? This is not really quite correct
1455 in that the type of the operand of ADDR_EXPR
1456 is not the target type of the type of the ADDR_EXPR itself.
1457 Question is, can this lossage be avoided? */
1458 adr
= build1 (ADDR_EXPR
, ptrtype
, exp
);
1459 if (mark_addressable (exp
) == 0)
1460 return error_mark_node
;
1461 TREE_CONSTANT (adr
) = staticp (exp
);
1462 TREE_SIDE_EFFECTS (adr
) = 0; /* Default would be, same as EXP. */
1465 /* This way is better for a COMPONENT_REF since it can
1466 simplify the offset for a component. */
1467 adr
= build_unary_op (ADDR_EXPR
, exp
, 1);
1468 return convert (ptrtype
, adr
);
1474 build_object_ref (datum
, basetype
, field
)
1475 tree datum
, basetype
, field
;
1478 if (datum
== error_mark_node
)
1479 return error_mark_node
;
1481 dtype
= TREE_TYPE (datum
);
1482 if (TREE_CODE (dtype
) == REFERENCE_TYPE
)
1483 dtype
= TREE_TYPE (dtype
);
1484 if (! IS_AGGR_TYPE_CODE (TREE_CODE (dtype
)))
1486 cp_error ("request for member `%T::%D' in expression of non-aggregate type `%T'",
1487 basetype
, field
, dtype
);
1488 return error_mark_node
;
1490 else if (IS_SIGNATURE (IDENTIFIER_TYPE_VALUE (basetype
)))
1492 warning ("signature name in scope resolution ignored");
1493 return build_component_ref (datum
, field
, NULL_TREE
, 1);
1495 else if (is_aggr_typedef (basetype
, 1))
1497 tree real_basetype
= IDENTIFIER_TYPE_VALUE (basetype
);
1498 tree binfo
= binfo_or_else (real_basetype
, TREE_TYPE (datum
));
1500 return build_component_ref (build_scoped_ref (datum
, basetype
),
1503 return error_mark_node
;
1506 /* Like `build_component_ref, but uses an already found field.
1507 Must compute access for C_C_D. Otherwise, ok. */
1509 build_component_ref_1 (datum
, field
, protect
)
1513 register tree basetype
= TREE_TYPE (datum
);
1514 register enum tree_code code
= TREE_CODE (basetype
);
1517 if (code
== REFERENCE_TYPE
)
1519 datum
= convert_from_reference (datum
);
1520 basetype
= TREE_TYPE (datum
);
1521 code
= TREE_CODE (basetype
);
1524 if (! IS_AGGR_TYPE_CODE (code
))
1526 if (code
!= ERROR_MARK
)
1527 cp_error ("request for member `%D' in `%E', which is of non-aggregate type `%T'",
1528 field
, datum
, basetype
);
1529 return error_mark_node
;
1532 if (TYPE_SIZE (basetype
) == 0)
1534 incomplete_type_error (0, basetype
);
1535 return error_mark_node
;
1538 /* Look up component name in the structure type definition. */
1540 if (field
== error_mark_node
)
1541 my_friendly_abort (115);
1543 if (TREE_STATIC (field
))
1548 enum access_type access
1549 = compute_access (TYPE_BINFO (current_class_type
), field
);
1551 if (access
== access_private
)
1553 cp_error ("field `%D' is private", field
);
1554 return error_mark_node
;
1556 else if (access
== access_protected
)
1558 cp_error ("field `%D' is protected", field
);
1559 return error_mark_node
;
1563 ref
= build (COMPONENT_REF
, TREE_TYPE (field
), datum
, field
);
1565 if (TREE_READONLY (datum
) || TREE_READONLY (field
))
1566 TREE_READONLY (ref
) = 1;
1567 if (TREE_THIS_VOLATILE (datum
) || TREE_THIS_VOLATILE (field
))
1568 TREE_THIS_VOLATILE (ref
) = 1;
1569 if (DECL_MUTABLE_P (field
))
1570 TREE_READONLY (ref
) = 0;
1575 /* Given a COND_EXPR in T, return it in a form that we can, for
1576 example, use as an lvalue. This code used to be in unary_complex_lvalue,
1577 but we needed it to deal with `a = (d == c) ? b : c' expressions, where
1578 we're dealing with aggregates. So, we now call this in unary_complex_lvalue,
1579 and in build_modify_expr. The case (in particular) that led to this was
1580 with CODE == ADDR_EXPR, since it's not an lvalue when we'd get it there. */
1582 rationalize_conditional_expr (code
, t
)
1583 enum tree_code code
;
1587 build_conditional_expr (TREE_OPERAND (t
, 0),
1588 build_unary_op (code
, TREE_OPERAND (t
, 1), 0),
1589 build_unary_op (code
, TREE_OPERAND (t
, 2), 0));
1593 build_component_ref (datum
, component
, basetype_path
, protect
)
1594 tree datum
, component
, basetype_path
;
1597 register tree basetype
= TREE_TYPE (datum
);
1598 register enum tree_code code
= TREE_CODE (basetype
);
1599 register tree field
= NULL
;
1602 /* If DATUM is a COMPOUND_EXPR or COND_EXPR, move our reference inside it. */
1603 switch (TREE_CODE (datum
))
1607 tree value
= build_component_ref (TREE_OPERAND (datum
, 1), component
,
1608 basetype_path
, protect
);
1609 return build (COMPOUND_EXPR
, TREE_TYPE (value
),
1610 TREE_OPERAND (datum
, 0), value
);
1613 return build_conditional_expr
1614 (TREE_OPERAND (datum
, 0),
1615 build_component_ref (TREE_OPERAND (datum
, 1), component
,
1616 basetype_path
, protect
),
1617 build_component_ref (TREE_OPERAND (datum
, 2), component
,
1618 basetype_path
, protect
));
1621 if (code
== REFERENCE_TYPE
)
1624 /* TREE_REFERENCE_EXPRs are not converted by `convert_from_reference'.
1625 @@ Maybe that is not right. */
1626 if (TREE_REFERENCE_EXPR (datum
))
1627 datum
= build1 (INDIRECT_REF
, TREE_TYPE (basetype
), datum
);
1630 datum
= convert_from_reference (datum
);
1631 basetype
= TREE_TYPE (datum
);
1632 code
= TREE_CODE (basetype
);
1635 /* First, see if there is a field or component with name COMPONENT. */
1636 if (TREE_CODE (component
) == TREE_LIST
)
1638 my_friendly_assert (!(TREE_CHAIN (component
) == NULL_TREE
1639 && DECL_CHAIN (TREE_VALUE (component
)) == NULL_TREE
), 309);
1640 return build (COMPONENT_REF
, TREE_TYPE (component
), datum
, component
);
1643 if (TREE_CODE (component
) == TYPE_EXPR
)
1644 return build_component_type_expr (datum
, component
, NULL_TREE
, protect
);
1647 if (! IS_AGGR_TYPE_CODE (code
))
1649 if (code
!= ERROR_MARK
)
1650 cp_error ("request for member `%D' in `%E', which is of non-aggregate type `%T'",
1651 component
, datum
, basetype
);
1652 return error_mark_node
;
1655 if (TYPE_SIZE (basetype
) == 0)
1657 incomplete_type_error (0, basetype
);
1658 return error_mark_node
;
1661 if (TREE_CODE (component
) == BIT_NOT_EXPR
)
1663 if (TYPE_IDENTIFIER (basetype
) != TREE_OPERAND (component
, 0))
1665 cp_error ("destructor specifier `%T::~%T' must have matching names",
1666 basetype
, TREE_OPERAND (component
, 0));
1667 return error_mark_node
;
1669 if (! TYPE_HAS_DESTRUCTOR (basetype
))
1671 cp_error ("type `%T' has no destructor", basetype
);
1672 return error_mark_node
;
1674 return TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (basetype
), 0);
1677 /* Look up component name in the structure type definition. */
1678 if (CLASSTYPE_VFIELD (basetype
)
1679 && DECL_NAME (CLASSTYPE_VFIELD (basetype
)) == component
)
1680 /* Special-case this because if we use normal lookups in an ambiguous
1681 hierarchy, the compiler will abort (because vptr lookups are
1682 not supposed to be ambiguous. */
1683 field
= CLASSTYPE_VFIELD (basetype
);
1686 if (basetype_path
== NULL_TREE
)
1687 basetype_path
= TYPE_BINFO (basetype
);
1688 field
= lookup_field (basetype_path
, component
,
1689 protect
&& ! VFIELD_NAME_P (component
), 0);
1690 if (field
== error_mark_node
)
1691 return error_mark_node
;
1693 if (field
== NULL_TREE
)
1695 /* Not found as a data field, look for it as a method. If found,
1696 then if this is the only possible one, return it, else
1697 report ambiguity error. */
1698 tree fndecls
= lookup_fnfields (basetype_path
, component
, 1);
1699 if (fndecls
== error_mark_node
)
1700 return error_mark_node
;
1703 if (TREE_CHAIN (fndecls
) == NULL_TREE
1704 && DECL_CHAIN (TREE_VALUE (fndecls
)) == NULL_TREE
)
1706 enum access_type access
;
1709 /* Unique, so use this one now. */
1710 basetype
= TREE_PURPOSE (fndecls
);
1711 fndecl
= TREE_VALUE (fndecls
);
1712 access
= compute_access (TREE_PURPOSE (fndecls
), fndecl
);
1713 if (access
== access_public
)
1715 if (DECL_VINDEX (fndecl
)
1716 && ! resolves_to_fixed_type_p (datum
, 0))
1718 tree addr
= build_unary_op (ADDR_EXPR
, datum
, 0);
1719 addr
= convert_pointer_to (DECL_CONTEXT (fndecl
), addr
);
1720 datum
= build_indirect_ref (addr
, NULL_PTR
);
1721 my_friendly_assert (datum
!= error_mark_node
, 310);
1722 fndecl
= build_vfn_ref (&addr
, datum
, DECL_VINDEX (fndecl
));
1724 assemble_external (fndecl
);
1727 if (access
== access_protected
)
1728 cp_error ("member function `%D' is protected", fndecl
);
1730 cp_error ("member function `%D' is private", fndecl
);
1731 return error_mark_node
;
1735 /* Just act like build_offset_ref, since the object does
1736 not matter unless we're actually calling the function. */
1739 for (t
= TREE_VALUE (fndecls
); t
; t
= DECL_CHAIN (t
))
1740 assemble_external (t
);
1742 t
= build_tree_list (error_mark_node
, fndecls
);
1743 TREE_TYPE (t
) = build_offset_type (basetype
,
1750 if (component
== ansi_opname
[(int) TYPE_EXPR
])
1751 cp_error ("`%#T' has no such type conversion operator", basetype
);
1754 cp_error ("`%#T' has no member named `%D'", basetype
, component
);
1755 return error_mark_node
;
1757 else if (TREE_TYPE (field
) == error_mark_node
)
1758 return error_mark_node
;
1760 if (TREE_CODE (field
) != FIELD_DECL
)
1762 if (TREE_CODE (field
) == TYPE_DECL
)
1764 cp_error ("invalid use of type decl `%#D' as expression", field
);
1765 return error_mark_node
;
1767 if (DECL_RTL (field
) != 0)
1768 assemble_external (field
);
1769 TREE_USED (field
) = 1;
1774 if (DECL_FIELD_CONTEXT (field
) != basetype
1775 && TYPE_USES_COMPLEX_INHERITANCE (basetype
))
1777 tree addr
= build_unary_op (ADDR_EXPR
, datum
, 0);
1778 if (integer_zerop (addr
))
1780 error ("invalid reference to NULL ptr, use ptr-to-member instead");
1781 return error_mark_node
;
1783 addr
= convert_pointer_to (DECL_FIELD_CONTEXT (field
), addr
);
1784 datum
= build_indirect_ref (addr
, NULL_PTR
);
1785 my_friendly_assert (datum
!= error_mark_node
, 311);
1787 ref
= fold (build (COMPONENT_REF
, TREE_TYPE (field
),
1788 break_out_cleanups (datum
), field
));
1790 if (TREE_READONLY (datum
) || TREE_READONLY (field
))
1791 TREE_READONLY (ref
) = 1;
1792 if (TREE_THIS_VOLATILE (datum
) || TREE_THIS_VOLATILE (field
))
1793 TREE_THIS_VOLATILE (ref
) = 1;
1794 if (DECL_MUTABLE_P (field
))
1795 TREE_READONLY (ref
) = 0;
1800 /* Given an expression PTR for a pointer, return an expression
1801 for the value pointed to.
1802 ERRORSTRING is the name of the operator to appear in error messages.
1804 This function may need to overload OPERATOR_FNNAME.
1805 Must also handle REFERENCE_TYPEs for C++. */
1808 build_x_indirect_ref (ptr
, errorstring
)
1812 tree rval
= build_opfncall (INDIRECT_REF
, LOOKUP_NORMAL
, ptr
, NULL_TREE
, NULL_TREE
);
1815 return build_indirect_ref (ptr
, errorstring
);
1819 build_indirect_ref (ptr
, errorstring
)
1823 register tree pointer
= default_conversion (ptr
);
1824 register tree type
= TREE_TYPE (pointer
);
1826 if (ptr
== current_class_decl
)
1829 ptr
= build_expr_type_conversion (WANT_POINTER
, pointer
, 1);
1833 type
= TREE_TYPE (pointer
);
1836 if (TREE_CODE (type
) == POINTER_TYPE
|| TREE_CODE (type
) == REFERENCE_TYPE
)
1838 if (TREE_CODE (pointer
) == ADDR_EXPR
1839 && (TREE_TYPE (TREE_OPERAND (pointer
, 0))
1840 == TREE_TYPE (type
)))
1841 return TREE_OPERAND (pointer
, 0);
1844 tree t
= TREE_TYPE (type
);
1845 register tree ref
= build1 (INDIRECT_REF
,
1846 TYPE_MAIN_VARIANT (t
), pointer
);
1848 TREE_READONLY (ref
) = TYPE_READONLY (t
);
1849 TREE_THIS_VOLATILE (ref
) = TYPE_VOLATILE (t
);
1850 TREE_SIDE_EFFECTS (ref
)
1851 = TYPE_VOLATILE (t
) || TREE_SIDE_EFFECTS (pointer
);
1855 /* `pointer' won't be an error_mark_node if we were given a
1856 pointer to member, so it's cool to check for this here. */
1857 else if (TYPE_PTRMEMFUNC_P (type
))
1858 error ("invalid use of `%s' on pointer to member function", errorstring
);
1859 else if (TREE_CODE (type
) == RECORD_TYPE
1860 && (IS_SIGNATURE_POINTER (type
) || IS_SIGNATURE_REFERENCE (type
)))
1861 error ("cannot dereference signature pointer/reference");
1862 else if (pointer
!= error_mark_node
)
1865 error ("invalid type argument of `%s'", errorstring
);
1867 error ("invalid type argument");
1869 return error_mark_node
;
1872 /* This handles expressions of the form "a[i]", which denotes
1875 This is logically equivalent in C to *(a+i), but we may do it differently.
1876 If A is a variable or a member, we generate a primitive ARRAY_REF.
1877 This avoids forcing the array out of registers, and can work on
1878 arrays that are not lvalues (for example, members of structures returned
1881 If INDEX is of some user-defined type, it must be converted to
1882 integer type. Otherwise, to make a compatible PLUS_EXPR, it
1883 will inherit the type of the array, which will be some pointer type. */
1886 build_x_array_ref (array
, index
)
1889 tree rval
= build_opfncall (ARRAY_REF
, LOOKUP_NORMAL
, array
, index
, NULL_TREE
);
1892 return build_array_ref (array
, index
);
1896 build_array_ref (array
, idx
)
1903 error ("subscript missing in array reference");
1904 return error_mark_node
;
1907 if (TREE_TYPE (array
) == error_mark_node
1908 || TREE_TYPE (idx
) == error_mark_node
)
1909 return error_mark_node
;
1911 itype
= TREE_TYPE (idx
);
1913 if (TREE_CODE (TREE_TYPE (array
)) == ARRAY_TYPE
1914 && TREE_CODE (array
) != INDIRECT_REF
)
1918 /* Subscripting with type char is likely to lose
1919 on a machine where chars are signed.
1920 So warn on any machine, but optionally.
1921 Don't warn for unsigned char since that type is safe.
1922 Don't warn for signed char because anyone who uses that
1923 must have done so deliberately. */
1924 if (warn_char_subscripts
1925 && TYPE_MAIN_VARIANT (TREE_TYPE (idx
)) == char_type_node
)
1926 warning ("array subscript has type `char'");
1928 /* Apply default promotions *after* noticing character types. */
1929 idx
= default_conversion (idx
);
1931 if (TREE_CODE (TREE_TYPE (idx
)) != INTEGER_TYPE
)
1933 error ("array subscript is not an integer");
1934 return error_mark_node
;
1937 /* An array that is indexed by a non-constant
1938 cannot be stored in a register; we must be able to do
1939 address arithmetic on its address.
1940 Likewise an array of elements of variable size. */
1941 if (TREE_CODE (idx
) != INTEGER_CST
1942 || (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array
))) != 0
1943 && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array
)))) != INTEGER_CST
))
1945 if (mark_addressable (array
) == 0)
1946 return error_mark_node
;
1948 /* An array that is indexed by a constant value which is not within
1949 the array bounds cannot be stored in a register either; because we
1950 would get a crash in store_bit_field/extract_bit_field when trying
1951 to access a non-existent part of the register. */
1952 if (TREE_CODE (idx
) == INTEGER_CST
1953 && TYPE_VALUES (TREE_TYPE (array
))
1954 && ! int_fits_type_p (idx
, TYPE_VALUES (TREE_TYPE (array
))))
1956 if (mark_addressable (array
) == 0)
1957 return error_mark_node
;
1960 if (pedantic
&& !lvalue_p (array
))
1961 pedwarn ("ANSI C++ forbids subscripting non-lvalue array");
1963 /* Note in C++ it is valid to subscript a `register' array, since
1964 it is valid to take the address of something with that
1965 storage specification. */
1969 while (TREE_CODE (foo
) == COMPONENT_REF
)
1970 foo
= TREE_OPERAND (foo
, 0);
1971 if (TREE_CODE (foo
) == VAR_DECL
&& DECL_REGISTER (foo
))
1972 warning ("subscripting array declared `register'");
1975 type
= TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (array
)));
1976 rval
= build (ARRAY_REF
, type
, array
, idx
);
1977 /* Array ref is const/volatile if the array elements are
1978 or if the array is.. */
1979 TREE_READONLY (rval
)
1980 |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array
)))
1981 | TREE_READONLY (array
));
1982 TREE_SIDE_EFFECTS (rval
)
1983 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array
)))
1984 | TREE_SIDE_EFFECTS (array
));
1985 TREE_THIS_VOLATILE (rval
)
1986 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array
)))
1987 /* This was added by rms on 16 Nov 91.
1988 It fixes vol struct foo *a; a->elts[1]
1989 in an inline function.
1990 Hope it doesn't break something else. */
1991 | TREE_THIS_VOLATILE (array
));
1992 return require_complete_type (fold (rval
));
1996 tree ar
= default_conversion (array
);
1997 tree ind
= default_conversion (idx
);
1999 /* Put the integer in IND to simplify error checking. */
2000 if (TREE_CODE (TREE_TYPE (ar
)) == INTEGER_TYPE
)
2007 if (ar
== error_mark_node
)
2010 if (TREE_CODE (TREE_TYPE (ar
)) != POINTER_TYPE
)
2012 error ("subscripted value is neither array nor pointer");
2013 return error_mark_node
;
2015 if (TREE_CODE (TREE_TYPE (ind
)) != INTEGER_TYPE
)
2017 error ("array subscript is not an integer");
2018 return error_mark_node
;
2021 return build_indirect_ref (build_binary_op_nodefault (PLUS_EXPR
, ar
, ind
, PLUS_EXPR
),
2026 /* Build a function call to function FUNCTION with parameters PARAMS.
2027 PARAMS is a list--a chain of TREE_LIST nodes--in which the
2028 TREE_VALUE of each node is a parameter-expression.
2029 FUNCTION's data type may be a function type or a pointer-to-function.
2031 For C++: If FUNCTION's data type is a TREE_LIST, then the tree list
2032 is the list of possible methods that FUNCTION could conceivably
2033 be. If the list of methods comes from a class, then it will be
2034 a list of lists (where each element is associated with the class
2035 that produced it), otherwise it will be a simple list (for
2036 functions overloaded in global scope).
2038 In the first case, TREE_VALUE (function) is the head of one of those
2039 lists, and TREE_PURPOSE is the name of the function.
2041 In the second case, TREE_PURPOSE (function) is the function's
2044 DECL is the class instance variable, usually CURRENT_CLASS_DECL. */
2047 * [eichin:19911015.1726EST] actually return a possibly incomplete
2051 build_x_function_call (function
, params
, decl
)
2052 tree function
, params
, decl
;
2057 if (function
== error_mark_node
)
2058 return error_mark_node
;
2060 type
= TREE_TYPE (function
);
2061 is_method
= ((TREE_CODE (function
) == TREE_LIST
2062 && current_class_type
!= NULL_TREE
2063 && IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (function
)) == function
)
2064 || TREE_CODE (function
) == IDENTIFIER_NODE
2065 || TREE_CODE (type
) == METHOD_TYPE
2066 || TYPE_PTRMEMFUNC_P (type
));
2068 /* Handle methods, friends, and overloaded functions, respectively. */
2071 if (TREE_CODE (function
) == FUNCTION_DECL
)
2073 if (DECL_NAME (function
))
2074 function
= DECL_NAME (function
);
2076 function
= TYPE_IDENTIFIER (DECL_CLASS_CONTEXT (function
));
2078 else if (TREE_CODE (function
) == TREE_LIST
)
2081 if (TREE_CODE (TREE_VALUE (function
)) == TREE_LIST
)
2082 function
= TREE_PURPOSE (TREE_VALUE (function
));
2084 function
= TREE_PURPOSE (function
);
2086 my_friendly_assert (TREE_CODE (TREE_VALUE (function
)) == FUNCTION_DECL
, 312);
2087 function
= TREE_PURPOSE (function
);
2090 else if (TREE_CODE (function
) != IDENTIFIER_NODE
)
2092 if (TREE_CODE (function
) == OFFSET_REF
)
2094 if (TREE_OPERAND (function
, 0))
2095 decl
= TREE_OPERAND (function
, 0);
2097 /* Call via a pointer to member function. */
2098 if (decl
== NULL_TREE
)
2100 error ("pointer to member function called, but not in class scope");
2101 return error_mark_node
;
2103 /* What other type of POINTER_TYPE could this be? */
2104 if (TREE_CODE (TREE_TYPE (function
)) != POINTER_TYPE
2105 && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (function
))
2106 && TREE_CODE (function
) != OFFSET_REF
)
2107 function
= build (OFFSET_REF
, TREE_TYPE (type
), NULL_TREE
, function
);
2111 /* this is an abbreviated method call.
2112 must go through here in case it is a virtual function.
2113 @@ Perhaps this could be optimized. */
2115 if (decl
== NULL_TREE
)
2117 if (current_class_type
== NULL_TREE
)
2119 error ("object missing in call to method `%s'",
2120 IDENTIFIER_POINTER (function
));
2121 return error_mark_node
;
2123 /* Yow: call from a static member function. */
2124 decl
= build1 (NOP_EXPR
, TYPE_POINTER_TO (current_class_type
),
2126 decl
= build_indirect_ref (decl
, NULL_PTR
);
2129 return build_method_call (decl
, function
, params
,
2130 NULL_TREE
, LOOKUP_NORMAL
);
2132 else if (TREE_CODE (function
) == COMPONENT_REF
2133 && type
== unknown_type_node
)
2135 /* Should we undo what was done in build_component_ref? */
2136 if (TREE_CODE (TREE_PURPOSE (TREE_OPERAND (function
, 1))) == TREE_VEC
)
2137 /* Get the name that build_component_ref hid. */
2138 function
= DECL_NAME (TREE_VALUE (TREE_OPERAND (function
, 1)));
2140 function
= TREE_PURPOSE (TREE_OPERAND (function
, 1));
2141 return build_method_call (decl
, function
, params
,
2142 NULL_TREE
, LOOKUP_NORMAL
);
2144 else if (TREE_CODE (function
) == TREE_LIST
)
2146 if (TREE_VALUE (function
) == NULL_TREE
)
2148 cp_error ("function `%D' declared overloaded, but no definitions appear with which to resolve it?!?",
2149 TREE_PURPOSE (function
));
2150 return error_mark_node
;
2154 tree val
= TREE_VALUE (function
);
2156 if (TREE_CODE (val
) == TEMPLATE_DECL
)
2157 return build_overload_call_maybe
2158 (function
, params
, LOOKUP_COMPLAIN
, (struct candidate
*)0);
2159 else if (DECL_CHAIN (val
) != NULL_TREE
)
2160 return build_overload_call
2161 (function
, params
, LOOKUP_COMPLAIN
, (struct candidate
*)0);
2163 my_friendly_abort (360);
2168 if (TREE_CODE (function
) == OFFSET_REF
)
2170 /* If the component is a data element (or a virtual function), we play
2171 games here to make things work. */
2174 if (TREE_OPERAND (function
, 0))
2175 decl
= TREE_OPERAND (function
, 0);
2179 decl_addr
= build_unary_op (ADDR_EXPR
, decl
, 0);
2180 function
= get_member_function_from_ptrfunc (&decl_addr
,
2181 TREE_OPERAND (function
, 1));
2182 params
= tree_cons (NULL_TREE
, decl_addr
, params
);
2183 return build_function_call (function
, params
);
2186 type
= TREE_TYPE (function
);
2187 if (type
!= error_mark_node
)
2189 if (TREE_CODE (type
) == REFERENCE_TYPE
)
2190 type
= TREE_TYPE (type
);
2192 if (TYPE_LANG_SPECIFIC (type
) && TYPE_OVERLOADS_CALL_EXPR (type
))
2193 return build_opfncall (CALL_EXPR
, LOOKUP_NORMAL
, function
, params
, NULL_TREE
);
2198 tree fntype
= TREE_TYPE (function
);
2201 /* Explicitly named method? */
2202 if (TREE_CODE (function
) == FUNCTION_DECL
)
2203 ctypeptr
= TYPE_POINTER_TO (DECL_CLASS_CONTEXT (function
));
2204 /* Expression with ptr-to-method type? It could either be a plain
2205 usage, or it might be a case where the ptr-to-method is being
2206 passed in as an argument. */
2207 else if (TYPE_PTRMEMFUNC_P (fntype
))
2209 tree rec
= TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (fntype
)));
2210 ctypeptr
= TYPE_POINTER_TO (rec
);
2212 /* Unexpected node type? */
2214 my_friendly_abort (116);
2215 if (decl
== NULL_TREE
)
2217 if (current_function_decl
2218 && DECL_STATIC_FUNCTION_P (current_function_decl
))
2219 error ("invalid call to member function needing `this' in static member function scope");
2221 error ("pointer to member function called, but not in class scope");
2222 return error_mark_node
;
2224 if (TREE_CODE (TREE_TYPE (decl
)) != POINTER_TYPE
2225 && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (decl
)))
2227 decl
= build_unary_op (ADDR_EXPR
, decl
, 0);
2228 decl
= convert_pointer_to (TREE_TYPE (ctypeptr
), decl
);
2231 decl
= build_c_cast (ctypeptr
, decl
, 0);
2232 params
= tree_cons (NULL_TREE
, decl
, params
);
2235 return build_function_call (function
, params
);
2238 /* Resolve a pointer to member function. INSTANCE is the object
2239 instance to use, if the member points to a virtual member. */
2242 get_member_function_from_ptrfunc (instance_ptrptr
, function
)
2243 tree
*instance_ptrptr
;
2246 if (TREE_CODE (function
) == OFFSET_REF
)
2248 function
= TREE_OPERAND (function
, 1);
2251 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (function
)))
2253 tree fntype
= TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (function
));
2254 tree index
= save_expr (build_component_ref (function
,
2257 tree e1
= build (GT_EXPR
, boolean_type_node
, index
,
2258 convert (delta_type_node
, integer_zero_node
));
2259 tree delta
= convert (ptrdiff_type_node
,
2260 build_component_ref (function
, delta_identifier
, 0, 0));
2261 tree delta2
= DELTA2_FROM_PTRMEMFUNC (function
);
2267 tree instance_ptr
= *instance_ptrptr
;
2269 if (TREE_SIDE_EFFECTS (instance_ptr
))
2270 instance_ptr
= save_expr (instance_ptr
);
2272 /* convert down to the right base, before using the instance. */
2274 = convert_pointer_to_real (TYPE_METHOD_BASETYPE (TREE_TYPE (fntype
)),
2276 if (instance
== error_mark_node
)
2279 vtbl
= convert_pointer_to (ptr_type_node
, instance
);
2282 build_pointer_type (build_pointer_type (vtable_entry_type
)),
2283 vtbl
, convert (ptrdiff_type_node
, delta2
));
2284 vtbl
= build_indirect_ref (vtbl
, NULL_PTR
);
2285 aref
= build_array_ref (vtbl
, build_binary_op (MINUS_EXPR
,
2287 integer_one_node
, 1));
2288 if (! flag_vtable_thunks
)
2290 aref
= save_expr (aref
);
2292 /* Save the intermediate result in a SAVE_EXPR so we don't have to
2293 compute each component of the virtual function pointer twice. */
2294 if (/* !building_cleanup && */ TREE_CODE (aref
) == INDIRECT_REF
)
2295 TREE_OPERAND (aref
, 0) = save_expr (TREE_OPERAND (aref
, 0));
2297 delta
= build_binary_op (PLUS_EXPR
,
2298 build_conditional_expr (e1
, build_component_ref (aref
, delta_identifier
, 0, 0), integer_zero_node
),
2302 *instance_ptrptr
= build (PLUS_EXPR
, TREE_TYPE (instance_ptr
),
2303 instance_ptr
, delta
);
2304 if (flag_vtable_thunks
)
2307 e2
= build_component_ref (aref
, pfn_identifier
, 0, 0);
2309 e3
= PFN_FROM_PTRMEMFUNC (function
);
2310 TREE_TYPE (e2
) = TREE_TYPE (e3
);
2311 function
= build_conditional_expr (e1
, e2
, e3
);
2313 /* Make sure this doesn't get evaluated first inside one of the
2314 branches of the COND_EXPR. */
2315 if (TREE_CODE (instance_ptr
) == SAVE_EXPR
)
2316 function
= build (COMPOUND_EXPR
, TREE_TYPE (function
),
2317 instance_ptr
, function
);
2323 build_function_call_real (function
, params
, require_complete
, flags
)
2324 tree function
, params
;
2325 int require_complete
, flags
;
2327 register tree fntype
, fndecl
;
2328 register tree value_type
;
2329 register tree coerced_params
;
2330 tree name
= NULL_TREE
, assembler_name
= NULL_TREE
;
2333 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
2334 Strip such NOP_EXPRs, since FUNCTION is used in non-lvalue context. */
2335 if (TREE_CODE (function
) == NOP_EXPR
2336 && TREE_TYPE (function
) == TREE_TYPE (TREE_OPERAND (function
, 0)))
2337 function
= TREE_OPERAND (function
, 0);
2339 if (TREE_CODE (function
) == FUNCTION_DECL
)
2341 name
= DECL_NAME (function
);
2342 assembler_name
= DECL_ASSEMBLER_NAME (function
);
2344 GNU_xref_call (current_function_decl
,
2345 IDENTIFIER_POINTER (name
? name
2346 : TYPE_IDENTIFIER (DECL_CLASS_CONTEXT (function
))));
2347 assemble_external (function
);
2350 /* Convert anything with function type to a pointer-to-function. */
2353 && IDENTIFIER_LENGTH (name
) == 4
2354 && ! strcmp (IDENTIFIER_POINTER (name
), "main")
2355 && DECL_CONTEXT (function
) == NULL_TREE
)
2357 pedwarn ("ANSI C++ forbids calling `main' from within program");
2360 /* Differs from default_conversion by not setting TREE_ADDRESSABLE
2361 (because calling an inline function does not mean the function
2362 needs to be separately compiled). */
2364 if (DECL_INLINE (function
))
2366 fntype
= build_type_variant (TREE_TYPE (function
),
2367 TREE_READONLY (function
),
2368 TREE_THIS_VOLATILE (function
));
2369 function
= build1 (ADDR_EXPR
, build_pointer_type (fntype
), function
);
2373 assemble_external (function
);
2374 TREE_USED (function
) = 1;
2375 function
= default_conversion (function
);
2382 /* Convert anything with function type to a pointer-to-function. */
2383 if (function
== error_mark_node
)
2384 return error_mark_node
;
2385 function
= default_conversion (function
);
2388 fntype
= TREE_TYPE (function
);
2390 if (TYPE_PTRMEMFUNC_P (fntype
))
2392 tree instance_ptr
= build_unary_op (ADDR_EXPR
, C_C_D
, 0);
2393 fntype
= TYPE_PTRMEMFUNC_FN_TYPE (fntype
);
2394 function
= get_member_function_from_ptrfunc (&instance_ptr
, function
);
2397 is_method
= (TREE_CODE (fntype
) == POINTER_TYPE
2398 && TREE_CODE (TREE_TYPE (fntype
)) == METHOD_TYPE
);
2400 if (!((TREE_CODE (fntype
) == POINTER_TYPE
2401 && TREE_CODE (TREE_TYPE (fntype
)) == FUNCTION_TYPE
)
2404 error ("called object is not a function");
2405 return error_mark_node
;
2408 /* fntype now gets the type of function pointed to. */
2409 fntype
= TREE_TYPE (fntype
);
2411 /* Convert the parameters to the types declared in the
2412 function prototype, or apply default promotions. */
2414 if (flags
& LOOKUP_COMPLAIN
)
2415 coerced_params
= convert_arguments (NULL_TREE
, TYPE_ARG_TYPES (fntype
),
2416 params
, fndecl
, LOOKUP_NORMAL
);
2418 coerced_params
= convert_arguments (NULL_TREE
, TYPE_ARG_TYPES (fntype
),
2421 /* Check for errors in format strings. */
2423 if (warn_format
&& (name
|| assembler_name
))
2424 check_function_format (name
, assembler_name
, coerced_params
);
2426 /* Recognize certain built-in functions so we can make tree-codes
2427 other than CALL_EXPR. We do this when it enables fold-const.c
2428 to do something useful. */
2430 if (TREE_CODE (function
) == ADDR_EXPR
2431 && TREE_CODE (TREE_OPERAND (function
, 0)) == FUNCTION_DECL
2432 && DECL_BUILT_IN (TREE_OPERAND (function
, 0)))
2433 switch (DECL_FUNCTION_CODE (TREE_OPERAND (function
, 0)))
2438 if (coerced_params
== 0)
2439 return integer_zero_node
;
2440 return build_unary_op (ABS_EXPR
, TREE_VALUE (coerced_params
), 0);
2444 value_type
= TREE_TYPE (fntype
) ? TREE_TYPE (fntype
) : void_type_node
;
2446 register tree result
=
2447 build (CALL_EXPR
, value_type
,
2448 function
, coerced_params
, NULL_TREE
);
2450 TREE_SIDE_EFFECTS (result
) = 1;
2452 if (! require_complete
)
2453 return convert_from_reference (result
);
2454 if (value_type
== void_type_node
)
2456 result
= require_complete_type (result
);
2457 return convert_from_reference (result
);
2462 build_function_call (function
, params
)
2463 tree function
, params
;
2465 return build_function_call_real (function
, params
, 1, LOOKUP_NORMAL
);
2469 build_function_call_maybe (function
, params
)
2470 tree function
, params
;
2472 return build_function_call_real (function
, params
, 0, 0);
2476 /* Convert the actual parameter expressions in the list VALUES
2477 to the types in the list TYPELIST.
2478 If parmdecls is exhausted, or when an element has NULL as its type,
2479 perform the default conversions.
2481 RETURN_LOC is the location of the return value, if known, NULL_TREE
2482 otherwise. This is useful in the case where we can avoid creating
2483 a temporary variable in the case where we can initialize the return
2484 value directly. If we are not eliding constructors, then we set this
2485 to NULL_TREE to avoid this avoidance.
2487 NAME is an IDENTIFIER_NODE or 0. It is used only for error messages.
2489 This is also where warnings about wrong number of args are generated.
2491 Return a list of expressions for the parameters as converted.
2493 Both VALUES and the returned value are chains of TREE_LIST nodes
2494 with the elements of the list in the TREE_VALUE slots of those nodes.
2496 In C++, unspecified trailing parameters can be filled in with their
2497 default arguments, if such were specified. Do so here. */
2500 convert_arguments (return_loc
, typelist
, values
, fndecl
, flags
)
2501 tree return_loc
, typelist
, values
, fndecl
;
2504 extern tree gc_protect_fndecl
;
2505 register tree typetail
, valtail
;
2506 register tree result
= NULL_TREE
;
2510 if (! flag_elide_constructors
)
2515 if (TREE_CODE (TREE_TYPE (fndecl
)) == METHOD_TYPE
)
2517 if (DECL_NAME (fndecl
) == NULL_TREE
2518 || IDENTIFIER_HAS_TYPE_VALUE (DECL_NAME (fndecl
)))
2519 called_thing
= "constructor";
2521 called_thing
= "member function";
2524 called_thing
= "function";
2527 for (valtail
= values
, typetail
= typelist
;
2529 valtail
= TREE_CHAIN (valtail
), i
++)
2531 register tree type
= typetail
? TREE_VALUE (typetail
) : 0;
2532 register tree val
= TREE_VALUE (valtail
);
2534 if (val
== error_mark_node
)
2537 if (type
== void_type_node
)
2541 char *buf
= (char *)alloca (40 + strlen (called_thing
));
2542 sprintf (buf
, "too many arguments to %s `%%s'", called_thing
);
2543 error_with_decl (fndecl
, buf
);
2544 error ("at this point in file");
2547 error ("too many arguments to function");
2548 /* In case anybody wants to know if this argument
2551 TREE_TYPE (tree_last (result
)) = error_mark_node
;
2555 /* The tree type of the parameter being passed may not yet be
2556 known. In this case, its type is TYPE_UNKNOWN, and will
2557 be instantiated by the type given by TYPE. If TYPE
2558 is also NULL, the tree type of VAL is ERROR_MARK_NODE. */
2559 if (type
&& type_unknown_p (val
))
2560 val
= require_instantiated_type (type
, val
, integer_zero_node
);
2561 else if (type_unknown_p (val
))
2563 /* Strip the `&' from an overloaded FUNCTION_DECL. */
2564 if (TREE_CODE (val
) == ADDR_EXPR
)
2565 val
= TREE_OPERAND (val
, 0);
2566 if (TREE_CODE (val
) == TREE_LIST
2567 && TREE_CHAIN (val
) == NULL_TREE
2568 && TREE_TYPE (TREE_VALUE (val
)) != NULL_TREE
2569 && (TREE_TYPE (val
) == unknown_type_node
2570 || DECL_CHAIN (TREE_VALUE (val
)) == NULL_TREE
))
2571 /* Instantiates automatically. */
2572 val
= TREE_VALUE (val
);
2575 error ("insufficient type information in parameter list");
2576 val
= integer_zero_node
;
2579 else if (TREE_CODE (val
) == OFFSET_REF
2580 && TREE_CODE (TREE_TYPE (val
)) == METHOD_TYPE
)
2582 /* This is unclean. Should be handled elsewhere. */
2583 val
= build_unary_op (ADDR_EXPR
, val
, 0);
2585 else if (TREE_CODE (val
) == OFFSET_REF
)
2586 val
= resolve_offset_ref (val
);
2590 /* This code forces the assumption that if we have a ptr-to-func
2591 type in an arglist, that every routine that wants to check
2592 its validity has done so, and thus we need not do any
2593 more conversion. I don't remember why this is necessary. */
2594 else if (TREE_CODE (ttype
) == FUNCTION_TYPE
2596 || TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
2597 || TREE_CODE (TREE_TYPE (type
)) == VOID_TYPE
))
2599 type
= build_pointer_type (ttype
);
2604 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
2605 Strip such NOP_EXPRs, since VAL is used in non-lvalue context. */
2606 if (TREE_CODE (val
) == NOP_EXPR
2607 && TREE_TYPE (val
) == TREE_TYPE (TREE_OPERAND (val
, 0))
2608 && (type
== 0 || TREE_CODE (type
) != REFERENCE_TYPE
))
2609 val
= TREE_OPERAND (val
, 0);
2611 if (type
== 0 || TREE_CODE (type
) != REFERENCE_TYPE
)
2613 if (TREE_CODE (TREE_TYPE (val
)) == ARRAY_TYPE
2614 || TREE_CODE (TREE_TYPE (val
)) == FUNCTION_TYPE
2615 || TREE_CODE (TREE_TYPE (val
)) == METHOD_TYPE
)
2616 val
= default_conversion (val
);
2618 val
= require_complete_type (val
);
2621 if (val
== error_mark_node
)
2626 /* Formal parm type is specified by a function prototype. */
2629 if (TYPE_SIZE (type
) == 0)
2631 error ("parameter type of called function is incomplete");
2636 #if 0 && defined (PROMOTE_PROTOTYPES)
2637 /* This breaks user-defined conversions. */
2638 /* Rather than truncating and then reextending,
2639 convert directly to int, if that's the type we will want. */
2640 if (! flag_traditional
2641 && (TREE_CODE (type
) == INTEGER_TYPE
2642 || TREE_CODE (type
) == ENUMERAL_TYPE
)
2643 && (TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
)))
2644 type
= integer_type_node
;
2646 parmval
= convert_for_initialization (return_loc
, type
, val
, flags
,
2647 "argument passing", fndecl
, i
);
2648 #ifdef PROMOTE_PROTOTYPES
2649 if ((TREE_CODE (type
) == INTEGER_TYPE
2650 || TREE_CODE (type
) == ENUMERAL_TYPE
)
2651 && (TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
)))
2652 parmval
= default_conversion (parmval
);
2655 result
= tree_cons (NULL_TREE
, parmval
, result
);
2659 if (TREE_CODE (TREE_TYPE (val
)) == REFERENCE_TYPE
)
2660 val
= convert_from_reference (val
);
2662 if (TREE_CODE (TREE_TYPE (val
)) == REAL_TYPE
2663 && (TYPE_PRECISION (TREE_TYPE (val
))
2664 < TYPE_PRECISION (double_type_node
)))
2665 /* Convert `float' to `double'. */
2666 result
= tree_cons (NULL_TREE
, convert (double_type_node
, val
), result
);
2667 else if (TYPE_LANG_SPECIFIC (TREE_TYPE (val
))
2668 && (TYPE_HAS_INIT_REF (TREE_TYPE (val
))
2669 || TYPE_HAS_ASSIGN_REF (TREE_TYPE (val
))))
2671 cp_warning ("cannot pass objects of type `%T' through `...'",
2673 result
= tree_cons (NULL_TREE
, val
, result
);
2676 /* Convert `short' and `char' to full-size `int'. */
2677 result
= tree_cons (NULL_TREE
, default_conversion (val
), result
);
2681 /* There are certain functions for which we don't need
2682 to protect our arguments. GC_PROTECT_FNDECL is one. */
2683 && fndecl
!= gc_protect_fndecl
2684 && type_needs_gc_entry (TREE_TYPE (TREE_VALUE (result
)))
2685 && ! value_safe_from_gc (NULL_TREE
, TREE_VALUE (result
)))
2686 /* This will build a temporary variable whose cleanup is
2687 to clear the obstack entry. */
2688 TREE_VALUE (result
) = protect_value_from_gc (NULL_TREE
,
2689 TREE_VALUE (result
));
2692 typetail
= TREE_CHAIN (typetail
);
2695 if (typetail
!= 0 && typetail
!= void_list_node
)
2697 /* See if there are default arguments that can be used */
2698 if (TREE_PURPOSE (typetail
))
2700 for (; typetail
!= void_list_node
; ++i
)
2702 tree type
= TREE_VALUE (typetail
);
2703 tree val
= TREE_PURPOSE (typetail
);
2706 if (val
== NULL_TREE
)
2707 parmval
= error_mark_node
;
2708 else if (TREE_CODE (val
) == CONSTRUCTOR
)
2710 parmval
= digest_init (type
, val
, (tree
*)0);
2711 parmval
= convert_for_initialization (return_loc
, type
, parmval
, flags
,
2712 "default constructor", fndecl
, i
);
2716 /* This could get clobbered by the following call. */
2717 if (TREE_HAS_CONSTRUCTOR (val
))
2718 val
= copy_node (val
);
2720 parmval
= convert_for_initialization (return_loc
, type
, val
, flags
,
2721 "default argument", fndecl
, i
);
2722 #ifdef PROMOTE_PROTOTYPES
2723 if ((TREE_CODE (type
) == INTEGER_TYPE
2724 || TREE_CODE (type
) == ENUMERAL_TYPE
)
2725 && (TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
)))
2726 parmval
= default_conversion (parmval
);
2731 && type_needs_gc_entry (TREE_TYPE (parmval
))
2732 && ! value_safe_from_gc (NULL_TREE
, parmval
))
2733 parmval
= protect_value_from_gc (NULL_TREE
, parmval
);
2735 result
= tree_cons (0, parmval
, result
);
2736 typetail
= TREE_CHAIN (typetail
);
2737 /* ends with `...'. */
2738 if (typetail
== NULL_TREE
)
2746 char *buf
= (char *)alloca (32 + strlen (called_thing
));
2747 sprintf (buf
, "too few arguments to %s `%%#D'", called_thing
);
2748 cp_error_at (buf
, fndecl
);
2749 error ("at this point in file");
2752 error ("too few arguments to function");
2753 return error_mark_list
;
2757 return nreverse (result
);
2760 /* Build a binary-operation expression, after performing default
2761 conversions on the operands. CODE is the kind of expression to build. */
2764 build_x_binary_op (code
, arg1
, arg2
)
2765 enum tree_code code
;
2768 tree rval
= build_opfncall (code
, LOOKUP_SPECULATIVELY
,
2769 arg1
, arg2
, NULL_TREE
);
2771 return build_opfncall (code
, LOOKUP_NORMAL
, arg1
, arg2
, NULL_TREE
);
2772 if (code
== MEMBER_REF
)
2773 return build_m_component_ref (build_indirect_ref (arg1
, NULL_PTR
),
2775 return build_binary_op (code
, arg1
, arg2
, 1);
2779 build_binary_op (code
, arg1
, arg2
, convert_p
)
2780 enum tree_code code
;
2793 args
[0] = args_save
[0] = default_conversion (args
[0]);
2794 args
[1] = args_save
[1] = default_conversion (args
[1]);
2796 if (args
[0] == error_mark_node
|| args
[1] == error_mark_node
)
2797 return error_mark_node
;
2799 type0
= TREE_TYPE (args
[0]);
2800 type1
= TREE_TYPE (args
[1]);
2802 if (type_unknown_p (args
[0]))
2804 args
[0] = instantiate_type (type1
, args
[0], 1);
2805 args
[0] = default_conversion (args
[0]);
2807 else if (type_unknown_p (args
[1]))
2809 args
[1] = require_instantiated_type (type0
, args
[1],
2811 args
[1] = default_conversion (args
[1]);
2814 if (IS_AGGR_TYPE (type0
) || IS_AGGR_TYPE (type1
))
2816 /* Try to convert this to something reasonable. */
2817 if (! build_default_binary_type_conversion(code
, &args
[0], &args
[1]))
2819 cp_error ("no match for `%O(%#T, %#T)'", code
,
2820 TREE_TYPE (arg1
), TREE_TYPE (arg2
));
2821 return error_mark_node
;
2825 if (args
[0] == args_save
[0])
2827 if (args
[1] == args_save
[1])
2830 return build_binary_op_nodefault (code
, args
[0], args
[1], code
);
2833 /* Build a binary-operation expression without default conversions.
2834 CODE is the kind of expression to build.
2835 This function differs from `build' in several ways:
2836 the data type of the result is computed and recorded in it,
2837 warnings are generated if arg data types are invalid,
2838 special handling for addition and subtraction of pointers is known,
2839 and some optimization is done (operations on narrow ints
2840 are done in the narrower type when that gives the same result).
2841 Constant folding is also done before the result is returned.
2843 ERROR_CODE is the code that determines what to say in error messages.
2844 It is usually, but not always, the same as CODE.
2846 Note that the operands will never have enumeral types
2847 because either they have just had the default conversions performed
2848 or they have both just been converted to some other type in which
2849 the arithmetic is to be done.
2851 C++: must do special pointer arithmetic when implementing
2852 multiple inheritance, and deal with pointer to member functions. */
2855 build_binary_op_nodefault (code
, orig_op0
, orig_op1
, error_code
)
2856 enum tree_code code
;
2857 tree orig_op0
, orig_op1
;
2858 enum tree_code error_code
;
2861 register enum tree_code code0
, code1
;
2864 /* Expression code to give to the expression when it is built.
2865 Normally this is CODE, which is what the caller asked for,
2866 but in some special cases we change it. */
2867 register enum tree_code resultcode
= code
;
2869 /* Data type in which the computation is to be performed.
2870 In the simplest cases this is the common type of the arguments. */
2871 register tree result_type
= NULL
;
2873 /* Nonzero means operands have already been type-converted
2874 in whatever way is necessary.
2875 Zero means they need to be converted to RESULT_TYPE. */
2878 /* Nonzero means create the expression with this type, rather than
2880 tree build_type
= 0;
2882 /* Nonzero means after finally constructing the expression
2883 give it this type. Otherwise, give it type RESULT_TYPE. */
2884 tree final_type
= 0;
2886 /* Nonzero if this is an operation like MIN or MAX which can
2887 safely be computed in short if both args are promoted shorts.
2888 Also implies COMMON.
2889 -1 indicates a bitwise operation; this makes a difference
2890 in the exact conditions for when it is safe to do the operation
2891 in a narrower mode. */
2894 /* Nonzero if this is a comparison operation;
2895 if both args are promoted shorts, compare the original shorts.
2896 Also implies COMMON. */
2897 int short_compare
= 0;
2899 /* Nonzero if this is a right-shift operation, which can be computed on the
2900 original short and then promoted if the operand is a promoted short. */
2901 int short_shift
= 0;
2903 /* Nonzero means set RESULT_TYPE to the common type of the args. */
2906 /* Apply default conversions. */
2907 op0
= default_conversion (orig_op0
);
2908 op1
= default_conversion (orig_op1
);
2910 type0
= TREE_TYPE (op0
);
2911 type1
= TREE_TYPE (op1
);
2913 /* The expression codes of the data types of the arguments tell us
2914 whether the arguments are integers, floating, pointers, etc. */
2915 code0
= TREE_CODE (type0
);
2916 code1
= TREE_CODE (type1
);
2918 /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
2919 STRIP_TYPE_NOPS (op0
);
2920 STRIP_TYPE_NOPS (op1
);
2922 /* If an error was already reported for one of the arguments,
2923 avoid reporting another error. */
2925 if (code0
== ERROR_MARK
|| code1
== ERROR_MARK
)
2926 return error_mark_node
;
2931 /* Handle the pointer + int case. */
2932 if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
2933 return pointer_int_sum (PLUS_EXPR
, op0
, op1
);
2934 else if (code1
== POINTER_TYPE
&& code0
== INTEGER_TYPE
)
2935 return pointer_int_sum (PLUS_EXPR
, op1
, op0
);
2941 /* Subtraction of two similar pointers.
2942 We must subtract them as integers, then divide by object size. */
2943 if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
2944 && comp_target_types (type0
, type1
, 1))
2945 return pointer_diff (op0
, op1
);
2946 /* Handle pointer minus int. Just like pointer plus int. */
2947 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
2948 return pointer_int_sum (MINUS_EXPR
, op0
, op1
);
2957 case TRUNC_DIV_EXPR
:
2959 case FLOOR_DIV_EXPR
:
2960 case ROUND_DIV_EXPR
:
2961 case EXACT_DIV_EXPR
:
2962 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
2963 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
2965 if (TREE_CODE (op1
) == INTEGER_CST
&& integer_zerop (op1
))
2966 cp_warning ("division by zero in `%E / 0'", op0
);
2967 else if (TREE_CODE (op1
) == REAL_CST
&& real_zerop (op1
))
2968 cp_warning ("division by zero in `%E / 0.'", op0
);
2970 if (!(code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
))
2971 resultcode
= RDIV_EXPR
;
2973 /* When dividing two signed integers, we have to promote to int.
2974 unless we divide by a conatant != -1. Note that default
2975 conversion will have been performed on the operands at this
2976 point, so we have to dig out the original type to find out if
2978 shorten
= ((TREE_CODE (op0
) == NOP_EXPR
2979 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0
, 0))))
2980 || (TREE_CODE (op1
) == INTEGER_CST
2981 && (TREE_INT_CST_LOW (op1
) != -1
2982 || TREE_INT_CST_HIGH (op1
) != -1)));
2988 case BIT_ANDTC_EXPR
:
2991 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
2993 /* If one operand is a constant, and the other is a short type
2994 that has been converted to an int,
2995 really do the work in the short type and then convert the
2996 result to int. If we are lucky, the constant will be 0 or 1
2997 in the short type, making the entire operation go away. */
2998 if (TREE_CODE (op0
) == INTEGER_CST
2999 && TREE_CODE (op1
) == NOP_EXPR
3000 && TYPE_PRECISION (type1
) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op1
, 0)))
3001 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op1
, 0))))
3003 final_type
= result_type
;
3004 op1
= TREE_OPERAND (op1
, 0);
3005 result_type
= TREE_TYPE (op1
);
3007 if (TREE_CODE (op1
) == INTEGER_CST
3008 && TREE_CODE (op0
) == NOP_EXPR
3009 && TYPE_PRECISION (type0
) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0
, 0)))
3010 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0
, 0))))
3012 final_type
= result_type
;
3013 op0
= TREE_OPERAND (op0
, 0);
3014 result_type
= TREE_TYPE (op0
);
3018 case TRUNC_MOD_EXPR
:
3019 case FLOOR_MOD_EXPR
:
3020 if (code1
== INTEGER_TYPE
&& integer_zerop (op1
))
3021 cp_warning ("division by zero in `%E % 0'", op0
);
3022 else if (code1
== REAL_TYPE
&& real_zerop (op1
))
3023 cp_warning ("division by zero in `%E % 0.'", op0
);
3025 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3027 /* Although it would be tempting to shorten always here, that loses
3028 on some targets, since the modulo instruction is undefined if the
3029 quotient can't be represented in the computation mode. We shorten
3030 only if unsigned or if dividing by something we know != -1. */
3031 shorten
= ((TREE_CODE (op0
) == NOP_EXPR
3032 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0
, 0))))
3033 || (TREE_CODE (op1
) == INTEGER_CST
3034 && (TREE_INT_CST_LOW (op1
) != -1
3035 || TREE_INT_CST_HIGH (op1
) != -1)));
3040 case TRUTH_ANDIF_EXPR
:
3041 case TRUTH_ORIF_EXPR
:
3042 case TRUTH_AND_EXPR
:
3044 result_type
= boolean_type_node
;
3047 /* Shift operations: result has same type as first operand;
3048 always convert second operand to int.
3049 Also set SHORT_SHIFT if shifting rightward. */
3052 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3054 result_type
= type0
;
3055 if (TREE_CODE (op1
) == INTEGER_CST
)
3057 if (tree_int_cst_lt (op1
, integer_zero_node
))
3058 warning ("right shift count is negative");
3061 if (TREE_INT_CST_LOW (op1
) | TREE_INT_CST_HIGH (op1
))
3063 if (TREE_INT_CST_HIGH (op1
) != 0
3064 || ((unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (op1
)
3065 >= TYPE_PRECISION (type0
)))
3066 warning ("right shift count >= width of type");
3069 /* Convert the shift-count to an integer, regardless of
3070 size of value being shifted. */
3071 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
3072 op1
= convert (integer_type_node
, op1
);
3073 /* Avoid converting op1 to result_type later. */
3079 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3081 result_type
= type0
;
3082 if (TREE_CODE (op1
) == INTEGER_CST
)
3084 if (tree_int_cst_lt (op1
, integer_zero_node
))
3085 warning ("left shift count is negative");
3086 else if (TREE_INT_CST_HIGH (op1
) != 0
3087 || ((unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (op1
)
3088 >= TYPE_PRECISION (type0
)))
3089 warning ("left shift count >= width of type");
3091 /* Convert the shift-count to an integer, regardless of
3092 size of value being shifted. */
3093 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
3094 op1
= convert (integer_type_node
, op1
);
3095 /* Avoid converting op1 to result_type later. */
3102 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3104 result_type
= type0
;
3105 if (TREE_CODE (op1
) == INTEGER_CST
)
3107 if (tree_int_cst_lt (op1
, integer_zero_node
))
3108 warning ("%s rotate count is negative",
3109 (code
== LROTATE_EXPR
) ? "left" : "right");
3110 else if (TREE_INT_CST_HIGH (op1
) != 0
3111 || ((unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (op1
)
3112 >= TYPE_PRECISION (type0
)))
3113 warning ("%s rotate count >= width of type",
3114 (code
== LROTATE_EXPR
) ? "left" : "right");
3116 /* Convert the shift-count to an integer, regardless of
3117 size of value being shifted. */
3118 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
3119 op1
= convert (integer_type_node
, op1
);
3125 build_type
= boolean_type_node
;
3126 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
3127 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
3129 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
3131 register tree tt0
= TYPE_MAIN_VARIANT (TREE_TYPE (type0
));
3132 register tree tt1
= TYPE_MAIN_VARIANT (TREE_TYPE (type1
));
3134 if (comp_target_types (type0
, type1
, 1))
3135 result_type
= common_type (type0
, type1
);
3136 else if (tt0
== void_type_node
)
3138 if (pedantic
&& TREE_CODE (tt1
) == FUNCTION_TYPE
3139 && tree_int_cst_lt (TYPE_SIZE (type0
), TYPE_SIZE (type1
)))
3140 pedwarn ("ANSI C++ forbids comparison of `void *' with function pointer");
3141 else if (TREE_CODE (tt1
) == OFFSET_TYPE
)
3142 pedwarn ("ANSI C++ forbids conversion of a pointer to member to `void *'");
3144 else if (tt1
== void_type_node
)
3146 if (pedantic
&& TREE_CODE (tt0
) == FUNCTION_TYPE
3147 && tree_int_cst_lt (TYPE_SIZE (type1
), TYPE_SIZE (type0
)))
3148 pedwarn ("ANSI C++ forbids comparison of `void *' with function pointer");
3150 else if ((TYPE_SIZE (tt0
) != 0) != (TYPE_SIZE (tt1
) != 0))
3151 cp_pedwarn ("comparison of %scomplete and %scomplete pointers `%T' and `%T'",
3152 TYPE_SIZE (tt0
) == 0 ? "in" : "",
3153 TYPE_SIZE (tt1
) == 0 ? "in" : "",
3156 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3159 else if (code0
== POINTER_TYPE
&& TREE_CODE (op1
) == INTEGER_CST
3160 && integer_zerop (op1
))
3161 op1
= null_pointer_node
;
3162 else if (code1
== POINTER_TYPE
&& TREE_CODE (op0
) == INTEGER_CST
3163 && integer_zerop (op0
))
3164 op0
= null_pointer_node
;
3165 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
3167 error ("ANSI C++ forbids comparison between pointer and integer");
3168 op1
= convert (TREE_TYPE (op0
), op1
);
3170 else if (code0
== INTEGER_TYPE
&& code1
== POINTER_TYPE
)
3172 error ("ANSI C++ forbids comparison between pointer and integer");
3173 op0
= convert (TREE_TYPE (op1
), op0
);
3175 else if (TYPE_PTRMEMFUNC_P (type0
) && TREE_CODE (op1
) == INTEGER_CST
3176 && integer_zerop (op1
))
3178 op0
= build_component_ref (op0
, index_identifier
, 0, 0);
3179 op1
= integer_zero_node
;
3181 else if (TYPE_PTRMEMFUNC_P (type1
) && TREE_CODE (op0
) == INTEGER_CST
3182 && integer_zerop (op0
))
3184 op0
= build_component_ref (op1
, index_identifier
, 0, 0);
3185 op1
= integer_zero_node
;
3187 else if (TYPE_PTRMEMFUNC_P (type0
) && TYPE_PTRMEMFUNC_P (type1
)
3188 && (TYPE_PTRMEMFUNC_FN_TYPE (type0
)
3189 == TYPE_PTRMEMFUNC_FN_TYPE (type1
)))
3191 /* The code we generate for the test is:
3193 (op0.index == op1.index
3194 && ((op1.index != -1 && op0.delta2 == op1.delta2)
3195 || op0.pfn == op1.pfn)) */
3197 tree index0
= build_component_ref (op0
, index_identifier
, 0, 0);
3198 tree index1
= save_expr (build_component_ref (op1
, index_identifier
, 0, 0));
3199 tree pfn0
= PFN_FROM_PTRMEMFUNC (op0
);
3200 tree pfn1
= PFN_FROM_PTRMEMFUNC (op1
);
3201 tree delta20
= DELTA2_FROM_PTRMEMFUNC (op0
);
3202 tree delta21
= DELTA2_FROM_PTRMEMFUNC (op1
);
3204 tree integer_neg_one_node
3205 = build_binary_op (MINUS_EXPR
, integer_zero_node
, integer_one_node
, 1);
3206 e1
= build_binary_op (EQ_EXPR
, index0
, index1
, 1);
3207 e2
= build_binary_op (NE_EXPR
, index1
, integer_neg_one_node
, 1);
3208 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e2
, build_binary_op (EQ_EXPR
, delta20
, delta21
, 1), 1);
3209 e3
= build_binary_op (EQ_EXPR
, pfn0
, pfn1
, 1);
3210 e2
= build_binary_op (TRUTH_ORIF_EXPR
, e2
, e3
, 1);
3211 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e1
, e2
, 1);
3212 if (code
== EQ_EXPR
)
3214 return build_binary_op (EQ_EXPR
, e2
, integer_zero_node
, 1);
3216 else if (TYPE_PTRMEMFUNC_P (type0
)
3217 && TYPE_PTRMEMFUNC_FN_TYPE (type0
) == type1
)
3219 tree index0
= build_component_ref (op0
, index_identifier
, 0, 0);
3221 tree pfn0
= PFN_FROM_PTRMEMFUNC (op0
);
3222 tree delta20
= DELTA2_FROM_PTRMEMFUNC (op0
);
3223 tree delta21
= integer_zero_node
;
3225 tree integer_neg_one_node
3226 = build_binary_op (MINUS_EXPR
, integer_zero_node
, integer_one_node
, 1);
3227 if (TREE_CODE (TREE_OPERAND (op1
, 0)) == FUNCTION_DECL
3228 && DECL_VINDEX (TREE_OPERAND (op1
, 0)))
3230 /* Map everything down one to make room for the null pointer to member. */
3231 index1
= size_binop (PLUS_EXPR
,
3232 DECL_VINDEX (TREE_OPERAND (op1
, 0)),
3234 op1
= integer_zero_node
;
3235 delta21
= CLASSTYPE_VFIELD (TYPE_METHOD_BASETYPE (TREE_TYPE (type1
)));
3236 delta21
= DECL_FIELD_BITPOS (delta21
);
3237 delta21
= size_binop (FLOOR_DIV_EXPR
, delta21
, size_int (BITS_PER_UNIT
));
3240 index1
= integer_neg_one_node
;
3242 tree nop1
= build1 (NOP_EXPR
, TYPE_PTRMEMFUNC_FN_TYPE (type0
), op1
);
3243 TREE_CONSTANT (nop1
) = TREE_CONSTANT (op1
);
3246 e1
= build_binary_op (EQ_EXPR
, index0
, index1
, 1);
3247 e2
= build_binary_op (NE_EXPR
, index1
, integer_neg_one_node
, 1);
3248 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e2
, build_binary_op (EQ_EXPR
, delta20
, delta21
, 1), 1);
3249 e3
= build_binary_op (EQ_EXPR
, pfn0
, op1
, 1);
3250 e2
= build_binary_op (TRUTH_ORIF_EXPR
, e2
, e3
, 1);
3251 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e1
, e2
, 1);
3252 if (code
== EQ_EXPR
)
3254 return build_binary_op (EQ_EXPR
, e2
, integer_zero_node
, 1);
3256 else if (TYPE_PTRMEMFUNC_P (type1
)
3257 && TYPE_PTRMEMFUNC_FN_TYPE (type1
) == type0
)
3259 return build_binary_op (code
, op1
, op0
, 1);
3262 type0
= TREE_TYPE (op0
);
3263 type1
= TREE_TYPE (op1
);
3264 if (result_type
== NULL_TREE
)
3265 result_type
= type0
;
3270 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
3271 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
3273 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
3275 if (! comp_target_types (type0
, type1
, 1))
3277 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3279 result_type
= ptr_type_node
;
3282 else if ((TYPE_SIZE (TREE_TYPE (type0
)) != 0)
3283 != (TYPE_SIZE (TREE_TYPE (type1
)) != 0))
3284 cp_pedwarn ("comparison of %scomplete and %scomplete pointers",
3285 TYPE_SIZE (TREE_TYPE (type0
)) == 0 ? "in" : "",
3286 TYPE_SIZE (TREE_TYPE (type1
)) == 0 ? "in" : "",
3289 && TREE_CODE (TREE_TYPE (type0
)) == FUNCTION_TYPE
)
3290 pedwarn ("ANSI C++ forbids ordered comparisons of pointers to functions");
3293 result_type
= common_type (type0
, type1
);
3296 if (result_type
== NULL_TREE
)
3297 result_type
= type0
;
3304 build_type
= boolean_type_node
;
3305 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
3306 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
3308 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
3310 if (! comp_target_types (type0
, type1
, 1))
3311 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3314 else if ((TYPE_SIZE (TREE_TYPE (type0
)) != 0)
3315 != (TYPE_SIZE (TREE_TYPE (type1
)) != 0))
3316 cp_pedwarn ("comparison of %scomplete and %scomplete pointers",
3317 TYPE_SIZE (TREE_TYPE (type0
)) == 0 ? "in" : "",
3318 TYPE_SIZE (TREE_TYPE (type1
)) == 0 ? "in" : "",
3321 && TREE_CODE (TREE_TYPE (type0
)) == FUNCTION_TYPE
)
3322 pedwarn ("ANSI C++ forbids ordered comparisons of pointers to functions");
3325 result_type
= common_type (type0
, type1
);
3327 else if (code0
== POINTER_TYPE
&& TREE_CODE (op1
) == INTEGER_CST
3328 && integer_zerop (op1
))
3329 op1
= null_pointer_node
;
3330 else if (code1
== POINTER_TYPE
&& TREE_CODE (op0
) == INTEGER_CST
3331 && integer_zerop (op0
))
3332 op0
= null_pointer_node
;
3333 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
3336 pedwarn ("ANSI C++ forbids comparison between pointer and integer");
3337 else if (! flag_traditional
)
3338 warning ("comparison between pointer and integer");
3339 op1
= convert (TREE_TYPE (op0
), op1
);
3341 else if (code0
== INTEGER_TYPE
&& code1
== POINTER_TYPE
)
3344 pedwarn ("ANSI C++ forbids comparison between pointer and integer");
3345 else if (! flag_traditional
)
3346 warning ("comparison between pointer and integer");
3347 op0
= convert (TREE_TYPE (op1
), op0
);
3350 type0
= TREE_TYPE (op0
);
3351 type1
= TREE_TYPE (op1
);
3352 if (result_type
== NULL_TREE
)
3353 result_type
= type0
;
3357 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
3358 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
3360 if (shorten
|| common
|| short_compare
)
3361 result_type
= common_type (type0
, type1
);
3363 /* For certain operations (which identify themselves by shorten != 0)
3364 if both args were extended from the same smaller type,
3365 do the arithmetic in that type and then extend.
3367 shorten !=0 and !=1 indicates a bitwise operation.
3368 For them, this optimization is safe only if
3369 both args are zero-extended or both are sign-extended.
3370 Otherwise, we might change the result.
3371 Eg, (short)-1 | (unsigned short)-1 is (int)-1
3372 but calculated in (unsigned short) it would be (unsigned short)-1. */
3376 int unsigned0
, unsigned1
;
3377 tree arg0
= get_narrower (op0
, &unsigned0
);
3378 tree arg1
= get_narrower (op1
, &unsigned1
);
3379 /* UNS is 1 if the operation to be done is an unsigned one. */
3380 int uns
= TREE_UNSIGNED (result_type
);
3383 final_type
= result_type
;
3385 /* Handle the case that OP0 does not *contain* a conversion
3386 but it *requires* conversion to FINAL_TYPE. */
3388 if (op0
== arg0
&& TREE_TYPE (op0
) != final_type
)
3389 unsigned0
= TREE_UNSIGNED (TREE_TYPE (op0
));
3390 if (op1
== arg1
&& TREE_TYPE (op1
) != final_type
)
3391 unsigned1
= TREE_UNSIGNED (TREE_TYPE (op1
));
3393 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
3395 /* For bitwise operations, signedness of nominal type
3396 does not matter. Consider only how operands were extended. */
3400 /* Note that in all three cases below we refrain from optimizing
3401 an unsigned operation on sign-extended args.
3402 That would not be valid. */
3404 /* Both args variable: if both extended in same way
3405 from same width, do it in that width.
3406 Do it unsigned if args were zero-extended. */
3407 if ((TYPE_PRECISION (TREE_TYPE (arg0
))
3408 < TYPE_PRECISION (result_type
))
3409 && (TYPE_PRECISION (TREE_TYPE (arg1
))
3410 == TYPE_PRECISION (TREE_TYPE (arg0
)))
3411 && unsigned0
== unsigned1
3412 && (unsigned0
|| !uns
))
3414 = signed_or_unsigned_type (unsigned0
,
3415 common_type (TREE_TYPE (arg0
), TREE_TYPE (arg1
)));
3416 else if (TREE_CODE (arg0
) == INTEGER_CST
3417 && (unsigned1
|| !uns
)
3418 && (TYPE_PRECISION (TREE_TYPE (arg1
))
3419 < TYPE_PRECISION (result_type
))
3420 && (type
= signed_or_unsigned_type (unsigned1
,
3422 int_fits_type_p (arg0
, type
)))
3424 else if (TREE_CODE (arg1
) == INTEGER_CST
3425 && (unsigned0
|| !uns
)
3426 && (TYPE_PRECISION (TREE_TYPE (arg0
))
3427 < TYPE_PRECISION (result_type
))
3428 && (type
= signed_or_unsigned_type (unsigned0
,
3430 int_fits_type_p (arg1
, type
)))
3434 /* Shifts can be shortened if shifting right. */
3439 tree arg0
= get_narrower (op0
, &unsigned_arg
);
3441 final_type
= result_type
;
3443 if (arg0
== op0
&& final_type
== TREE_TYPE (op0
))
3444 unsigned_arg
= TREE_UNSIGNED (TREE_TYPE (op0
));
3446 if (TYPE_PRECISION (TREE_TYPE (arg0
)) < TYPE_PRECISION (result_type
)
3447 /* We can shorten only if the shift count is less than the
3448 number of bits in the smaller type size. */
3449 && TREE_INT_CST_HIGH (op1
) == 0
3450 && TYPE_PRECISION (TREE_TYPE (arg0
)) > TREE_INT_CST_LOW (op1
)
3451 /* If arg is sign-extended and then unsigned-shifted,
3452 we can simulate this with a signed shift in arg's type
3453 only if the extended result is at least twice as wide
3454 as the arg. Otherwise, the shift could use up all the
3455 ones made by sign-extension and bring in zeros.
3456 We can't optimize that case at all, but in most machines
3457 it never happens because available widths are 2**N. */
3458 && (!TREE_UNSIGNED (final_type
)
3460 || ((unsigned) 2 * TYPE_PRECISION (TREE_TYPE (arg0
))
3461 <= TYPE_PRECISION (result_type
))))
3463 /* Do an unsigned shift if the operand was zero-extended. */
3465 = signed_or_unsigned_type (unsigned_arg
,
3467 /* Convert value-to-be-shifted to that type. */
3468 if (TREE_TYPE (op0
) != result_type
)
3469 op0
= convert (result_type
, op0
);
3474 /* Comparison operations are shortened too but differently.
3475 They identify themselves by setting short_compare = 1. */
3479 /* Don't write &op0, etc., because that would prevent op0
3480 from being kept in a register.
3481 Instead, make copies of the our local variables and
3482 pass the copies by reference, then copy them back afterward. */
3483 tree xop0
= op0
, xop1
= op1
, xresult_type
= result_type
;
3484 enum tree_code xresultcode
= resultcode
;
3486 = shorten_compare (&xop0
, &xop1
, &xresult_type
, &xresultcode
);
3488 return convert (boolean_type_node
, val
);
3489 op0
= xop0
, op1
= xop1
;
3491 resultcode
= xresultcode
;
3494 if (short_compare
&& extra_warnings
)
3496 int op0_signed
= ! TREE_UNSIGNED (TREE_TYPE (orig_op0
));
3497 int op1_signed
= ! TREE_UNSIGNED (TREE_TYPE (orig_op1
));
3499 tree comp_type
= TREE_TYPE (op0
);
3501 int unsignedp0
, unsignedp1
;
3502 tree primop0
= get_narrower (op0
, &unsignedp0
);
3503 tree primop1
= get_narrower (op1
, &unsignedp1
);
3505 /* Give warnings for comparisons between signed and unsigned
3506 quantities that may fail. Do not warn if the signed quantity
3507 is an unsuffixed integer literal (or some static constant
3508 expression involving such literals) and it is positive.
3509 Do not warn if the comparison is being done in a signed type,
3510 since the signed type will only be chosen if it can represent
3511 all the values of the unsigned type. */
3512 /* Do the checking based on the original operand trees, so that
3513 casts will be considered, but default promotions won't be. */
3514 if (TREE_UNSIGNED (comp_type
)
3515 && ((op0_signed
&& (TREE_CODE (orig_op0
) != INTEGER_CST
3516 || tree_int_cst_sgn (orig_op0
) == -1))
3517 || (op1_signed
&& (TREE_CODE (orig_op1
) != INTEGER_CST
3518 || tree_int_cst_sgn (orig_op1
) == -1))))
3519 warning ("comparison between signed and unsigned");
3521 /* Warn if two unsigned values are being compared in a size
3522 larger than their original size, and one (and only one) is the
3523 result of a `~' operator. This comparison will always fail.
3525 Also warn if one operand is a constant, and the constant does not
3526 have all bits set that are set in the ~ operand when it is
3529 else if (TREE_CODE (primop0
) == BIT_NOT_EXPR
3530 ^ TREE_CODE (primop1
) == BIT_NOT_EXPR
)
3532 if (TREE_CODE (primop0
) == BIT_NOT_EXPR
)
3533 primop0
= get_narrower (TREE_OPERAND (op0
, 0), &unsignedp0
);
3534 if (TREE_CODE (primop1
) == BIT_NOT_EXPR
)
3535 primop1
= get_narrower (TREE_OPERAND (op1
, 0), &unsignedp1
);
3537 if (TREE_CODE (primop0
) == INTEGER_CST
3538 || TREE_CODE (primop1
) == INTEGER_CST
)
3541 HOST_WIDE_INT constant
, mask
;
3545 if (TREE_CODE (primop0
) == INTEGER_CST
)
3548 unsignedp
= unsignedp1
;
3549 constant
= TREE_INT_CST_LOW (primop0
);
3554 unsignedp
= unsignedp0
;
3555 constant
= TREE_INT_CST_LOW (primop1
);
3558 bits
= TYPE_PRECISION (TREE_TYPE (primop
));
3559 if (bits
< TYPE_PRECISION (comp_type
)
3560 && bits
< HOST_BITS_PER_LONG
&& unsignedp
)
3562 mask
= (~ (HOST_WIDE_INT
) 0) << bits
;
3563 if ((mask
& constant
) != mask
)
3564 warning ("comparison of promoted ~unsigned with constant");
3567 else if (unsignedp0
&& unsignedp1
3568 && (TYPE_PRECISION (TREE_TYPE (primop0
))
3569 < TYPE_PRECISION (comp_type
))
3570 && (TYPE_PRECISION (TREE_TYPE (primop1
))
3571 < TYPE_PRECISION (comp_type
)))
3572 warning ("comparison of promoted ~unsigned with unsigned");
3577 /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
3578 If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
3579 Then the expression will be built.
3580 It will be given type FINAL_TYPE if that is nonzero;
3581 otherwise, it will be given type RESULT_TYPE. */
3585 binary_op_error (error_code
);
3586 return error_mark_node
;
3591 if (TREE_TYPE (op0
) != result_type
)
3592 op0
= convert (result_type
, op0
);
3593 if (TREE_TYPE (op1
) != result_type
)
3594 op1
= convert (result_type
, op1
);
3597 if (build_type
== NULL_TREE
)
3598 build_type
= result_type
;
3601 register tree result
= build (resultcode
, build_type
, op0
, op1
);
3602 register tree folded
;
3604 folded
= fold (result
);
3605 if (folded
== result
)
3606 TREE_CONSTANT (folded
) = TREE_CONSTANT (op0
) & TREE_CONSTANT (op1
);
3607 if (final_type
!= 0)
3608 return convert (final_type
, folded
);
3613 /* Return a tree for the sum or difference (RESULTCODE says which)
3614 of pointer PTROP and integer INTOP. */
3617 pointer_int_sum (resultcode
, ptrop
, intop
)
3618 enum tree_code resultcode
;
3619 register tree ptrop
, intop
;
3623 register tree result
;
3624 register tree folded
= fold (intop
);
3626 /* The result is a pointer of the same type that is being added. */
3628 register tree result_type
= TREE_TYPE (ptrop
);
3630 if (TREE_CODE (TREE_TYPE (result_type
)) == VOID_TYPE
)
3632 if (pedantic
|| warn_pointer_arith
)
3633 pedwarn ("ANSI C++ forbids using pointer of type `void *' in arithmetic");
3634 size_exp
= integer_one_node
;
3636 else if (TREE_CODE (TREE_TYPE (result_type
)) == FUNCTION_TYPE
)
3638 if (pedantic
|| warn_pointer_arith
)
3639 pedwarn ("ANSI C++ forbids using pointer to a function in arithmetic");
3640 size_exp
= integer_one_node
;
3642 else if (TREE_CODE (TREE_TYPE (result_type
)) == METHOD_TYPE
)
3644 if (pedantic
|| warn_pointer_arith
)
3645 pedwarn ("ANSI C++ forbids using pointer to a method in arithmetic");
3646 size_exp
= integer_one_node
;
3648 else if (TREE_CODE (TREE_TYPE (result_type
)) == OFFSET_TYPE
)
3651 pedwarn ("ANSI C++ forbids using pointer to a member in arithmetic");
3652 size_exp
= integer_one_node
;
3655 size_exp
= size_in_bytes (TREE_TYPE (result_type
));
3657 /* Needed to make OOPS V2R3 work. */
3659 if (TREE_CODE (intop
) == INTEGER_CST
3660 && TREE_INT_CST_LOW (intop
) == 0
3661 && TREE_INT_CST_HIGH (intop
) == 0)
3664 /* If what we are about to multiply by the size of the elements
3665 contains a constant term, apply distributive law
3666 and multiply that constant term separately.
3667 This helps produce common subexpressions. */
3669 if ((TREE_CODE (intop
) == PLUS_EXPR
|| TREE_CODE (intop
) == MINUS_EXPR
)
3670 && ! TREE_CONSTANT (intop
)
3671 && TREE_CONSTANT (TREE_OPERAND (intop
, 1))
3672 && TREE_CONSTANT (size_exp
))
3674 enum tree_code subcode
= resultcode
;
3675 if (TREE_CODE (intop
) == MINUS_EXPR
)
3676 subcode
= (subcode
== PLUS_EXPR
? MINUS_EXPR
: PLUS_EXPR
);
3677 ptrop
= build_binary_op (subcode
, ptrop
, TREE_OPERAND (intop
, 1), 1);
3678 intop
= TREE_OPERAND (intop
, 0);
3681 /* Convert the integer argument to a type the same size as a pointer
3682 so the multiply won't overflow spuriously. */
3684 if (TYPE_PRECISION (TREE_TYPE (intop
)) != POINTER_SIZE
)
3685 intop
= convert (type_for_size (POINTER_SIZE
, 0), intop
);
3687 /* Replace the integer argument with a suitable product by the object size.
3688 Do this multiplication as signed, then convert to the appropriate
3689 pointer type (actually unsigned integral). */
3691 intop
= convert (result_type
,
3692 build_binary_op (MULT_EXPR
, intop
,
3693 convert (TREE_TYPE (intop
), size_exp
), 1));
3695 /* Create the sum or difference. */
3697 result
= build (resultcode
, result_type
, ptrop
, intop
);
3699 folded
= fold (result
);
3700 if (folded
== result
)
3701 TREE_CONSTANT (folded
) = TREE_CONSTANT (ptrop
) & TREE_CONSTANT (intop
);
3705 /* Return a tree for the difference of pointers OP0 and OP1.
3706 The resulting tree has type int. */
3709 pointer_diff (op0
, op1
)
3710 register tree op0
, op1
;
3712 register tree result
, folded
;
3713 tree restype
= ptrdiff_type_node
;
3714 tree target_type
= TREE_TYPE (TREE_TYPE (op0
));
3718 if (TREE_CODE (target_type
) == VOID_TYPE
)
3719 pedwarn ("ANSI C++ forbids using pointer of type `void *' in subtraction");
3720 if (TREE_CODE (target_type
) == FUNCTION_TYPE
)
3721 pedwarn ("ANSI C++ forbids using pointer to a function in subtraction");
3722 if (TREE_CODE (target_type
) == METHOD_TYPE
)
3723 pedwarn ("ANSI C++ forbids using pointer to a method in subtraction");
3724 if (TREE_CODE (target_type
) == OFFSET_TYPE
)
3725 pedwarn ("ANSI C++ forbids using pointer to a member in subtraction");
3728 /* First do the subtraction as integers;
3729 then drop through to build the divide operator. */
3731 op0
= build_binary_op (MINUS_EXPR
,
3732 convert (restype
, op0
), convert (restype
, op1
), 1);
3734 /* This generates an error if op1 is a pointer to an incomplete type. */
3735 if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (op1
))) == 0)
3736 error ("arithmetic on pointer to an incomplete type");
3738 op1
= ((TREE_CODE (target_type
) == VOID_TYPE
3739 || TREE_CODE (target_type
) == FUNCTION_TYPE
3740 || TREE_CODE (target_type
) == METHOD_TYPE
3741 || TREE_CODE (target_type
) == OFFSET_TYPE
)
3743 : size_in_bytes (target_type
));
3745 /* Do the division. */
3747 result
= build (EXACT_DIV_EXPR
, restype
, op0
, convert (restype
, op1
));
3749 folded
= fold (result
);
3750 if (folded
== result
)
3751 TREE_CONSTANT (folded
) = TREE_CONSTANT (op0
) & TREE_CONSTANT (op1
);
3755 /* Handle the case of taking the address of a COMPONENT_REF.
3756 Called by `build_unary_op' and `build_up_reference'.
3758 ARG is the COMPONENT_REF whose address we want.
3759 ARGTYPE is the pointer type that this address should have.
3760 MSG is an error message to print if this COMPONENT_REF is not
3761 addressable (such as a bitfield). */
3764 build_component_addr (arg
, argtype
, msg
)
3768 tree field
= TREE_OPERAND (arg
, 1);
3769 tree basetype
= decl_type_context (field
);
3770 tree rval
= build_unary_op (ADDR_EXPR
, TREE_OPERAND (arg
, 0), 0);
3772 if (DECL_BIT_FIELD (field
))
3774 error (msg
, IDENTIFIER_POINTER (DECL_NAME (field
)));
3775 return error_mark_node
;
3779 cp_warning ("address of `%T::%D' taken", basetype
, field
);
3781 if (TREE_CODE (field
) == FIELD_DECL
3782 && TYPE_USES_COMPLEX_INHERITANCE (basetype
))
3784 /* Can't convert directly to ARGTYPE, since that
3785 may have the same pointer type as one of our
3787 rval
= build1 (NOP_EXPR
, argtype
,
3788 convert_pointer_to (basetype
, rval
));
3789 TREE_CONSTANT (rval
) = TREE_CONSTANT (TREE_OPERAND (rval
, 0));
3792 /* This conversion is harmless. */
3793 rval
= convert_force (argtype
, rval
, 0);
3795 if (! integer_zerop (DECL_FIELD_BITPOS (field
)))
3797 tree offset
= size_binop (EASY_DIV_EXPR
, DECL_FIELD_BITPOS (field
),
3798 size_int (BITS_PER_UNIT
));
3799 int flag
= TREE_CONSTANT (rval
);
3800 rval
= fold (build (PLUS_EXPR
, argtype
,
3801 rval
, convert (argtype
, offset
)));
3802 TREE_CONSTANT (rval
) = flag
;
3807 /* Construct and perhaps optimize a tree representation
3808 for a unary operation. CODE, a tree_code, specifies the operation
3809 and XARG is the operand. */
3812 build_x_unary_op (code
, xarg
)
3813 enum tree_code code
;
3816 /* & rec, on incomplete RECORD_TYPEs is the simple opr &, not an
3818 if (code
== ADDR_EXPR
3819 && ((IS_AGGR_TYPE_CODE (TREE_CODE (TREE_TYPE (xarg
)))
3820 && TYPE_SIZE (TREE_TYPE (xarg
)) == NULL_TREE
)
3821 || (TREE_CODE (xarg
) == OFFSET_REF
)))
3822 /* don't look for a function */;
3825 tree rval
= build_opfncall (code
, LOOKUP_SPECULATIVELY
, xarg
,
3826 NULL_TREE
, NULL_TREE
);
3828 return build_opfncall (code
, LOOKUP_NORMAL
, xarg
,
3829 NULL_TREE
, NULL_TREE
);
3831 return build_unary_op (code
, xarg
, 0);
3834 /* Just like truthvalue_conversion, but we want a CLEANUP_POINT_EXPR. */
3837 condition_conversion (expr
)
3840 tree t
= convert (boolean_type_node
, expr
);
3841 t
= fold (build1 (CLEANUP_POINT_EXPR
, boolean_type_node
, t
));
3845 /* C++: Must handle pointers to members.
3847 Perhaps type instantiation should be extended to handle conversion
3848 from aggregates to types we don't yet know we want? (Or are those
3849 cases typically errors which should be reported?)
3851 NOCONVERT nonzero suppresses the default promotions
3852 (such as from short to int). */
3854 build_unary_op (code
, xarg
, noconvert
)
3855 enum tree_code code
;
3859 /* No default_conversion here. It causes trouble for ADDR_EXPR. */
3860 register tree arg
= xarg
;
3861 register tree argtype
= 0;
3862 char *errstring
= NULL
;
3865 if (arg
== error_mark_node
)
3866 return error_mark_node
;
3871 /* This is used for unary plus, because a CONVERT_EXPR
3872 is enough to prevent anybody from looking inside for
3873 associativity, but won't generate any code. */
3874 if (!(arg
= build_expr_type_conversion
3875 (WANT_ARITH
| WANT_ENUM
| WANT_POINTER
, arg
, 1)))
3876 errstring
= "wrong type argument to unary plus";
3880 arg
= default_conversion (arg
);
3881 arg
= build1 (NON_LVALUE_EXPR
, TREE_TYPE (arg
), arg
);
3886 if (!(arg
= build_expr_type_conversion (WANT_ARITH
| WANT_ENUM
, arg
, 1)))
3887 errstring
= "wrong type argument to unary minus";
3888 else if (!noconvert
)
3889 arg
= default_conversion (arg
);
3893 if (!(arg
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, arg
, 1)))
3894 errstring
= "wrong type argument to bit-complement";
3895 else if (!noconvert
)
3896 arg
= default_conversion (arg
);
3900 if (!(arg
= build_expr_type_conversion (WANT_ARITH
| WANT_ENUM
, arg
, 1)))
3901 errstring
= "wrong type argument to abs";
3902 else if (!noconvert
)
3903 arg
= default_conversion (arg
);
3906 case TRUTH_NOT_EXPR
:
3907 arg
= convert (boolean_type_node
, arg
);
3908 val
= invert_truthvalue (arg
);
3909 if (arg
!= error_mark_node
)
3911 errstring
= "in argument to unary !";
3917 case PREINCREMENT_EXPR
:
3918 case POSTINCREMENT_EXPR
:
3919 case PREDECREMENT_EXPR
:
3920 case POSTDECREMENT_EXPR
:
3921 /* Handle complex lvalues (when permitted)
3922 by reduction to simpler cases. */
3924 val
= unary_complex_lvalue (code
, arg
);
3928 /* Report invalid types. */
3930 if (!(arg
= build_expr_type_conversion (WANT_ARITH
| WANT_POINTER
,
3933 if (code
== PREINCREMENT_EXPR
)
3934 errstring
="no pre-increment operator for type";
3935 else if (code
== POSTINCREMENT_EXPR
)
3936 errstring
="no post-increment operator for type";
3937 else if (code
== PREDECREMENT_EXPR
)
3938 errstring
="no pre-decrement operator for type";
3940 errstring
="no post-decrement operator for type";
3944 /* Report something read-only. */
3946 if (TYPE_READONLY (TREE_TYPE (arg
))
3947 || TREE_READONLY (arg
))
3948 readonly_error (arg
, ((code
== PREINCREMENT_EXPR
3949 || code
== POSTINCREMENT_EXPR
)
3950 ? "increment" : "decrement"),
3955 tree result_type
= TREE_TYPE (arg
);
3957 arg
= get_unwidened (arg
, 0);
3958 argtype
= TREE_TYPE (arg
);
3960 /* ARM $5.2.5 last annotation says this should be forbidden. */
3961 if (TREE_CODE (argtype
) == ENUMERAL_TYPE
)
3962 pedwarn ("ANSI C++ forbids %sing an enum",
3963 (code
== PREINCREMENT_EXPR
|| code
== POSTINCREMENT_EXPR
)
3964 ? "increment" : "decrement");
3966 /* Compute the increment. */
3968 if (TREE_CODE (argtype
) == POINTER_TYPE
)
3970 enum tree_code tmp
= TREE_CODE (TREE_TYPE (argtype
));
3971 if (TYPE_SIZE (TREE_TYPE (argtype
)) == 0)
3972 cp_error ("cannot %s a pointer to incomplete type `%T'",
3973 ((code
== PREINCREMENT_EXPR
3974 || code
== POSTINCREMENT_EXPR
)
3975 ? "increment" : "decrement"), TREE_TYPE (argtype
));
3976 else if (tmp
== FUNCTION_TYPE
|| tmp
== METHOD_TYPE
3977 || tmp
== VOID_TYPE
|| tmp
== OFFSET_TYPE
)
3978 cp_pedwarn ("ANSI C++ forbids %sing a pointer of type `%T'",
3979 ((code
== PREINCREMENT_EXPR
3980 || code
== POSTINCREMENT_EXPR
)
3981 ? "increment" : "decrement"), argtype
);
3982 inc
= c_sizeof_nowarn (TREE_TYPE (argtype
));
3985 inc
= integer_one_node
;
3987 inc
= convert (argtype
, inc
);
3989 /* Handle incrementing a cast-expression. */
3991 switch (TREE_CODE (arg
))
3996 case FIX_TRUNC_EXPR
:
3997 case FIX_FLOOR_EXPR
:
3998 case FIX_ROUND_EXPR
:
4001 tree incremented
, modify
, value
;
4002 if (! lvalue_p (arg
) && pedantic
)
4003 pedwarn ("cast to non-reference type used as lvalue");
4004 arg
= stabilize_reference (arg
);
4005 if (code
== PREINCREMENT_EXPR
|| code
== PREDECREMENT_EXPR
)
4008 value
= save_expr (arg
);
4009 incremented
= build (((code
== PREINCREMENT_EXPR
4010 || code
== POSTINCREMENT_EXPR
)
4011 ? PLUS_EXPR
: MINUS_EXPR
),
4012 argtype
, value
, inc
);
4013 TREE_SIDE_EFFECTS (incremented
) = 1;
4014 modify
= build_modify_expr (arg
, NOP_EXPR
, incremented
);
4015 return build (COMPOUND_EXPR
, TREE_TYPE (arg
), modify
, value
);
4019 /* Complain about anything else that is not a true lvalue. */
4020 if (!lvalue_or_else (arg
, ((code
== PREINCREMENT_EXPR
4021 || code
== POSTINCREMENT_EXPR
)
4022 ? "increment" : "decrement")))
4023 return error_mark_node
;
4025 /* Forbid using -- on `bool'. */
4026 if (TREE_TYPE (arg
) == boolean_type_node
)
4028 if (code
== POSTDECREMENT_EXPR
|| code
== PREDECREMENT_EXPR
)
4030 cp_error ("invalid use of `--' on bool variable `%D'", arg
);
4031 return error_mark_node
;
4034 /* This will only work if someone can convince Kenner to accept
4035 my patch to expand_increment. (jason) */
4036 val
= build (code
, TREE_TYPE (arg
), arg
, inc
);
4038 if (code
== POSTINCREMENT_EXPR
)
4040 arg
= stabilize_reference (arg
);
4041 val
= build (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
4043 TREE_SIDE_EFFECTS (val
) = 1;
4044 arg
= save_expr (arg
);
4045 val
= build (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
4046 val
= build (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
4049 val
= build (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
4054 val
= build (code
, TREE_TYPE (arg
), arg
, inc
);
4056 TREE_SIDE_EFFECTS (val
) = 1;
4057 return convert (result_type
, val
);
4061 /* Note that this operation never does default_conversion
4062 regardless of NOCONVERT. */
4064 argtype
= TREE_TYPE (arg
);
4065 if (TREE_CODE (argtype
) == REFERENCE_TYPE
)
4067 arg
= build1 (CONVERT_EXPR
, build_pointer_type (TREE_TYPE (TREE_TYPE (arg
))), arg
);
4068 TREE_REFERENCE_EXPR (arg
) = 1;
4072 && TREE_CODE (arg
) == FUNCTION_DECL
4074 && DECL_CONTEXT (arg
) == NULL_TREE
4075 && IDENTIFIER_LENGTH (DECL_NAME (arg
)) == 4
4076 && IDENTIFIER_POINTER (DECL_NAME (arg
))[0] == 'm'
4077 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (arg
)), "main"))
4079 pedwarn ("taking address of function `main'");
4081 /* Let &* cancel out to simplify resulting code. */
4082 if (TREE_CODE (arg
) == INDIRECT_REF
)
4084 /* We don't need to have `current_class_decl' wrapped in a
4085 NON_LVALUE_EXPR node. */
4087 return current_class_decl
;
4089 /* Keep `default_conversion' from converting if
4090 ARG is of REFERENCE_TYPE. */
4091 arg
= TREE_OPERAND (arg
, 0);
4092 if (TREE_CODE (TREE_TYPE (arg
)) == REFERENCE_TYPE
)
4094 if (TREE_CODE (arg
) == VAR_DECL
&& DECL_INITIAL (arg
)
4095 && !TREE_SIDE_EFFECTS (DECL_INITIAL (arg
)))
4096 arg
= DECL_INITIAL (arg
);
4097 arg
= build1 (CONVERT_EXPR
, build_pointer_type (TREE_TYPE (TREE_TYPE (arg
))), arg
);
4098 TREE_REFERENCE_EXPR (arg
) = 1;
4099 TREE_CONSTANT (arg
) = TREE_CONSTANT (TREE_OPERAND (arg
, 0));
4101 else if (lvalue_p (arg
))
4102 /* Don't let this be an lvalue. */
4103 return non_lvalue (arg
);
4107 /* For &x[y], return x+y */
4108 if (TREE_CODE (arg
) == ARRAY_REF
)
4110 if (mark_addressable (TREE_OPERAND (arg
, 0)) == 0)
4111 return error_mark_node
;
4112 return build_binary_op (PLUS_EXPR
, TREE_OPERAND (arg
, 0),
4113 TREE_OPERAND (arg
, 1), 1);
4116 /* Uninstantiated types are all functions. Taking the
4117 address of a function is a no-op, so just return the
4120 if (TREE_CODE (arg
) == IDENTIFIER_NODE
4121 && IDENTIFIER_OPNAME_P (arg
))
4123 my_friendly_abort (117);
4124 /* We don't know the type yet, so just work around the problem.
4125 We know that this will resolve to an lvalue. */
4126 return build1 (ADDR_EXPR
, unknown_type_node
, arg
);
4129 if (TREE_CODE (arg
) == TREE_LIST
)
4131 if (TREE_CODE (TREE_VALUE (arg
)) == FUNCTION_DECL
4132 && DECL_CHAIN (TREE_VALUE (arg
)) == NULL_TREE
)
4133 /* Unique overloaded non-member function. */
4134 return build_unary_op (ADDR_EXPR
, TREE_VALUE (arg
), 0);
4135 if (TREE_CHAIN (arg
) == NULL_TREE
4136 && TREE_CODE (TREE_VALUE (arg
)) == TREE_LIST
4137 && DECL_CHAIN (TREE_VALUE (TREE_VALUE (arg
))) == NULL_TREE
)
4138 /* Unique overloaded member function. */
4139 return build_unary_op (ADDR_EXPR
, TREE_VALUE (TREE_VALUE (arg
)),
4141 return build1 (ADDR_EXPR
, unknown_type_node
, arg
);
4144 /* Handle complex lvalues (when permitted)
4145 by reduction to simpler cases. */
4146 val
= unary_complex_lvalue (code
, arg
);
4150 switch (TREE_CODE (arg
))
4155 case FIX_TRUNC_EXPR
:
4156 case FIX_FLOOR_EXPR
:
4157 case FIX_ROUND_EXPR
:
4159 if (! lvalue_p (arg
) && pedantic
)
4160 pedwarn ("taking the address of a cast to non-reference type");
4163 /* Allow the address of a constructor if all the elements
4165 if (TREE_CODE (arg
) == CONSTRUCTOR
&& TREE_CONSTANT (arg
))
4167 /* Anything not already handled and not a true memory reference
4169 else if (TREE_CODE (argtype
) != FUNCTION_TYPE
4170 && TREE_CODE (argtype
) != METHOD_TYPE
4171 && !lvalue_or_else (arg
, "unary `&'"))
4172 return error_mark_node
;
4174 /* Ordinary case; arg is a COMPONENT_REF or a decl. */
4175 /* If the lvalue is const or volatile,
4176 merge that into the type that the address will point to. */
4177 if (TREE_CODE_CLASS (TREE_CODE (arg
)) == 'd'
4178 || TREE_CODE_CLASS (TREE_CODE (arg
)) == 'r')
4180 if (TREE_READONLY (arg
) || TREE_THIS_VOLATILE (arg
))
4181 argtype
= cp_build_type_variant (argtype
,
4182 TREE_READONLY (arg
),
4183 TREE_THIS_VOLATILE (arg
));
4186 argtype
= build_pointer_type (argtype
);
4188 if (mark_addressable (arg
) == 0)
4189 return error_mark_node
;
4194 if (TREE_CODE (arg
) == COMPONENT_REF
)
4195 addr
= build_component_addr (arg
, argtype
,
4196 "attempt to take address of bit-field structure member `%s'");
4198 addr
= build1 (code
, argtype
, arg
);
4200 /* Address of a static or external variable or
4201 function counts as a constant */
4203 TREE_CONSTANT (addr
) = 1;
4211 argtype
= TREE_TYPE (arg
);
4212 return fold (build1 (code
, argtype
, arg
));
4216 return error_mark_node
;
4219 /* If CONVERSIONS is a conversion expression or a nested sequence of such,
4220 convert ARG with the same conversions in the same order
4221 and return the result. */
4224 convert_sequence (conversions
, arg
)
4228 switch (TREE_CODE (conversions
))
4233 case FIX_TRUNC_EXPR
:
4234 case FIX_FLOOR_EXPR
:
4235 case FIX_ROUND_EXPR
:
4237 return convert (TREE_TYPE (conversions
),
4238 convert_sequence (TREE_OPERAND (conversions
, 0),
4246 /* Apply unary lvalue-demanding operator CODE to the expression ARG
4247 for certain kinds of expressions which are not really lvalues
4248 but which we can accept as lvalues.
4250 If ARG is not a kind of expression we can handle, return zero. */
4253 unary_complex_lvalue (code
, arg
)
4254 enum tree_code code
;
4257 /* Handle (a, b) used as an "lvalue". */
4258 if (TREE_CODE (arg
) == COMPOUND_EXPR
)
4260 tree real_result
= build_unary_op (code
, TREE_OPERAND (arg
, 1), 0);
4261 return build (COMPOUND_EXPR
, TREE_TYPE (real_result
),
4262 TREE_OPERAND (arg
, 0), real_result
);
4265 /* Handle (a ? b : c) used as an "lvalue". */
4266 if (TREE_CODE (arg
) == COND_EXPR
)
4267 return rationalize_conditional_expr (code
, arg
);
4269 if (TREE_CODE (arg
) == MODIFY_EXPR
4270 || TREE_CODE (arg
) == PREINCREMENT_EXPR
4271 || TREE_CODE (arg
) == PREDECREMENT_EXPR
)
4272 return unary_complex_lvalue
4273 (code
, build (COMPOUND_EXPR
, TREE_TYPE (TREE_OPERAND (arg
, 0)),
4274 arg
, TREE_OPERAND (arg
, 0)));
4276 if (code
!= ADDR_EXPR
)
4279 /* Handle (a = b) used as an "lvalue" for `&'. */
4280 if (TREE_CODE (arg
) == MODIFY_EXPR
4281 || TREE_CODE (arg
) == INIT_EXPR
)
4283 tree real_result
= build_unary_op (code
, TREE_OPERAND (arg
, 0), 0);
4284 return build (COMPOUND_EXPR
, TREE_TYPE (real_result
), arg
, real_result
);
4287 if (TREE_CODE (arg
) == WITH_CLEANUP_EXPR
)
4289 tree real_result
= build_unary_op (code
, TREE_OPERAND (arg
, 0), 0);
4290 real_result
= build (WITH_CLEANUP_EXPR
, TREE_TYPE (real_result
),
4291 real_result
, 0, TREE_OPERAND (arg
, 2));
4295 if (TREE_CODE (TREE_TYPE (arg
)) == FUNCTION_TYPE
4296 || TREE_CODE (TREE_TYPE (arg
)) == METHOD_TYPE
4297 || TREE_CODE (TREE_TYPE (arg
)) == OFFSET_TYPE
)
4299 /* The representation of something of type OFFSET_TYPE
4300 is really the representation of a pointer to it.
4301 Here give the representation its true type. */
4305 my_friendly_assert (TREE_CODE (arg
) != SCOPE_REF
, 313);
4307 if (TREE_CODE (arg
) != OFFSET_REF
)
4310 t
= TREE_OPERAND (arg
, 1);
4312 if (TREE_CODE (t
) == FUNCTION_DECL
) /* Check all this code for right semantics. */
4313 return build_unary_op (ADDR_EXPR
, t
, 0);
4314 if (TREE_CODE (t
) == VAR_DECL
)
4315 return build_unary_op (ADDR_EXPR
, t
, 0);
4318 if (TREE_OPERAND (arg
, 0)
4319 && (TREE_CODE (TREE_OPERAND (arg
, 0)) != NOP_EXPR
4320 || TREE_OPERAND (TREE_OPERAND (arg
, 0), 0) != error_mark_node
))
4321 if (TREE_CODE (t
) != FIELD_DECL
)
4323 /* Don't know if this should return address to just
4324 _DECL, or actual address resolved in this expression. */
4325 sorry ("address of bound pointer-to-member expression");
4326 return error_mark_node
;
4329 offset
= get_delta_difference (DECL_FIELD_CONTEXT (t
),
4330 TREE_TYPE (TREE_OPERAND (arg
, 0)),
4332 offset
= size_binop (PLUS_EXPR
, offset
,
4333 size_binop (EASY_DIV_EXPR
,
4334 DECL_FIELD_BITPOS (t
),
4335 size_int (BITS_PER_UNIT
)));
4336 return convert (build_pointer_type (TREE_TYPE (arg
)), offset
);
4340 if (TREE_CODE (arg
) == OFFSET_REF
)
4342 tree left
= TREE_OPERAND (arg
, 0), left_addr
;
4343 tree right_addr
= build_unary_op (ADDR_EXPR
, TREE_OPERAND (arg
, 1), 0);
4346 if (current_class_decl
)
4347 left_addr
= current_class_decl
;
4350 error ("no `this' for pointer to member");
4351 return error_mark_node
;
4354 left_addr
= build_unary_op (ADDR_EXPR
, left
, 0);
4356 return build (PLUS_EXPR
, build_pointer_type (TREE_TYPE (arg
)),
4357 build1 (NOP_EXPR
, integer_type_node
, left_addr
),
4358 build1 (NOP_EXPR
, integer_type_node
, right_addr
));
4361 /* We permit compiler to make function calls returning
4362 objects of aggregate type look like lvalues. */
4366 if (TREE_CODE (targ
) == SAVE_EXPR
)
4367 targ
= TREE_OPERAND (targ
, 0);
4369 if (TREE_CODE (targ
) == CALL_EXPR
&& IS_AGGR_TYPE (TREE_TYPE (targ
)))
4371 if (TREE_CODE (arg
) == SAVE_EXPR
)
4374 targ
= build_cplus_new (TREE_TYPE (arg
), arg
, 1);
4375 return build1 (ADDR_EXPR
, TYPE_POINTER_TO (TREE_TYPE (arg
)), targ
);
4378 if (TREE_CODE (arg
) == SAVE_EXPR
&& TREE_CODE (targ
) == INDIRECT_REF
)
4379 return build (SAVE_EXPR
, TYPE_POINTER_TO (TREE_TYPE (arg
)),
4380 TREE_OPERAND (targ
, 0), current_function_decl
, NULL
);
4382 /* We shouldn't wrap WITH_CLEANUP_EXPRs inside of SAVE_EXPRs, but in case
4383 we do, here's how to handle it. */
4384 if (TREE_CODE (arg
) == SAVE_EXPR
&& TREE_CODE (targ
) == WITH_CLEANUP_EXPR
)
4387 /* Not really a bug, but something to turn on when testing. */
4388 compiler_error ("WITH_CLEANUP_EXPR wrapped in SAVE_EXPR");
4390 return unary_complex_lvalue (ADDR_EXPR
, targ
);
4394 /* Don't let anything else be handled specially. */
4398 /* Mark EXP saying that we need to be able to take the
4399 address of it; it should not be allocated in a register.
4400 Value is 1 if successful.
4402 C++: we do not allow `current_class_decl' to be addressable. */
4405 mark_addressable (exp
)
4408 register tree x
= exp
;
4410 if (TREE_ADDRESSABLE (x
) == 1)
4414 switch (TREE_CODE (x
))
4419 x
= TREE_OPERAND (x
, 0);
4423 if (x
== current_class_decl
)
4425 error ("address of `this' not available");
4426 TREE_ADDRESSABLE (x
) = 1; /* so compiler doesn't die later */
4427 put_var_into_stack (x
);
4432 && TREE_READONLY (x
)
4433 && DECL_RTL (x
) != 0
4434 && ! decl_in_memory_p (x
))
4436 /* We thought this would make a good constant variable,
4437 but we were wrong. */
4438 push_obstacks_nochange ();
4439 end_temporary_allocation ();
4441 TREE_ASM_WRITTEN (x
) = 0;
4443 rest_of_decl_compilation (x
, 0, IDENTIFIER_LOCAL_VALUE (x
) == 0, 0);
4444 TREE_ADDRESSABLE (x
) = 1;
4450 /* Caller should not be trying to mark initialized
4451 constant fields addressable. */
4452 my_friendly_assert (DECL_LANG_SPECIFIC (x
) == 0
4453 || DECL_IN_AGGR_P (x
) == 0
4455 || DECL_EXTERNAL (x
), 314);
4459 /* For C++, we don't warn about taking the address of a register
4460 variable for CONST_DECLs; ARM p97 explicitly says it's okay. */
4461 put_var_into_stack (x
);
4462 TREE_ADDRESSABLE (x
) = 1;
4466 /* We have to test both conditions here. The first may
4467 be non-zero in the case of processing a default function.
4468 The second may be non-zero in the case of a template function. */
4469 x
= DECL_MAIN_VARIANT (x
);
4470 if ((DECL_INLINE (x
) || DECL_PENDING_INLINE_INFO (x
))
4471 && (DECL_CONTEXT (x
) == NULL_TREE
4472 || TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (x
))) != 't'
4473 || ! CLASSTYPE_INTERFACE_ONLY (DECL_CONTEXT (x
))))
4475 mark_inline_for_output (x
);
4476 if (x
== current_function_decl
)
4477 DECL_EXTERNAL (x
) = 0;
4479 TREE_ADDRESSABLE (x
) = 1;
4481 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (x
)) = 1;
4489 /* Build and return a conditional expression IFEXP ? OP1 : OP2. */
4492 build_x_conditional_expr (ifexp
, op1
, op2
)
4493 tree ifexp
, op1
, op2
;
4495 tree rval
= NULL_TREE
;
4497 /* See comments in `build_x_binary_op'. */
4499 rval
= build_opfncall (COND_EXPR
, LOOKUP_SPECULATIVELY
, ifexp
, op1
, op2
);
4501 return build_opfncall (COND_EXPR
, LOOKUP_NORMAL
, ifexp
, op1
, op2
);
4503 return build_conditional_expr (ifexp
, op1
, op2
);
4507 build_conditional_expr (ifexp
, op1
, op2
)
4508 tree ifexp
, op1
, op2
;
4510 register tree type1
;
4511 register tree type2
;
4512 register enum tree_code code1
;
4513 register enum tree_code code2
;
4514 register tree result_type
= NULL_TREE
;
4515 tree orig_op1
= op1
, orig_op2
= op2
;
4517 /* If second operand is omitted, it is the same as the first one;
4518 make sure it is calculated only once. */
4522 pedwarn ("ANSI C++ forbids omitting the middle term of a ?: expression");
4523 ifexp
= op1
= save_expr (ifexp
);
4526 ifexp
= truthvalue_conversion (ifexp
);
4528 if (TREE_CODE (ifexp
) == ERROR_MARK
)
4529 return error_mark_node
;
4531 op1
= require_instantiated_type (TREE_TYPE (op2
), op1
, error_mark_node
);
4532 if (op1
== error_mark_node
)
4533 return error_mark_node
;
4534 op2
= require_instantiated_type (TREE_TYPE (op1
), op2
, error_mark_node
);
4535 if (op2
== error_mark_node
)
4536 return error_mark_node
;
4538 /* C++: REFERENCE_TYPES must be dereferenced. */
4539 type1
= TREE_TYPE (op1
);
4540 code1
= TREE_CODE (type1
);
4541 type2
= TREE_TYPE (op2
);
4542 code2
= TREE_CODE (type2
);
4544 if (code1
== REFERENCE_TYPE
)
4546 op1
= convert_from_reference (op1
);
4547 type1
= TREE_TYPE (op1
);
4548 code1
= TREE_CODE (type1
);
4550 if (code2
== REFERENCE_TYPE
)
4552 op2
= convert_from_reference (op2
);
4553 type2
= TREE_TYPE (op2
);
4554 code2
= TREE_CODE (type2
);
4557 #if 1 /* Produces wrong result if within sizeof. Sorry. */
4558 /* Don't promote the operands separately if they promote
4559 the same way. Return the unpromoted type and let the combined
4560 value get promoted if necessary. */
4562 if (TYPE_MAIN_VARIANT (type1
) == TYPE_MAIN_VARIANT (type2
)
4563 && code2
!= ARRAY_TYPE
4565 /* For C++, let the enumeral type come through. */
4566 && code2
!= ENUMERAL_TYPE
4568 && code2
!= FUNCTION_TYPE
4569 && code2
!= METHOD_TYPE
)
4573 if (TREE_CONSTANT (ifexp
)
4574 && (TREE_CODE (ifexp
) == INTEGER_CST
4575 || TREE_CODE (ifexp
) == ADDR_EXPR
))
4576 return (integer_zerop (ifexp
) ? op2
: op1
);
4578 if (TREE_CODE (op1
) == CONST_DECL
)
4579 op1
= DECL_INITIAL (op1
);
4580 else if (TREE_READONLY_DECL_P (op1
))
4581 op1
= decl_constant_value (op1
);
4582 if (TREE_CODE (op2
) == CONST_DECL
)
4583 op2
= DECL_INITIAL (op2
);
4584 else if (TREE_READONLY_DECL_P (op2
))
4585 op2
= decl_constant_value (op2
);
4587 type1
= cp_build_type_variant
4589 TREE_READONLY (op1
) || TREE_READONLY (op2
),
4590 TREE_THIS_VOLATILE (op1
) || TREE_THIS_VOLATILE (op2
));
4591 /* ??? This is a kludge to deal with the fact that
4592 we don't sort out integers and enums properly, yet. */
4593 result
= fold (build (COND_EXPR
, type1
, ifexp
, op1
, op2
));
4594 if (TREE_TYPE (result
) != type1
)
4595 result
= build1 (NOP_EXPR
, type1
, result
);
4600 /* They don't match; promote them both and then try to reconcile them.
4601 But don't permit mismatching enum types. */
4602 if (code1
== ENUMERAL_TYPE
)
4604 if (code2
== ENUMERAL_TYPE
)
4606 cp_error ("enumeral mismatch in conditional expression: `%T' vs `%T'", type1
, type2
);
4607 return error_mark_node
;
4609 else if (extra_warnings
&& ! IS_AGGR_TYPE_CODE (code2
))
4610 warning ("enumeral and non-enumeral type in conditional expression");
4612 else if (extra_warnings
4613 && code2
== ENUMERAL_TYPE
&& ! IS_AGGR_TYPE_CODE (code1
))
4614 warning ("enumeral and non-enumeral type in conditional expression");
4616 if (code1
!= VOID_TYPE
)
4618 op1
= default_conversion (op1
);
4619 type1
= TREE_TYPE (op1
);
4620 if (TYPE_PTRMEMFUNC_P (type1
))
4621 type1
= TYPE_PTRMEMFUNC_FN_TYPE (type1
);
4622 code1
= TREE_CODE (type1
);
4624 if (code2
!= VOID_TYPE
)
4626 op2
= default_conversion (op2
);
4627 type2
= TREE_TYPE (op2
);
4628 if (TYPE_PTRMEMFUNC_P (type2
))
4629 type2
= TYPE_PTRMEMFUNC_FN_TYPE (type2
);
4630 code2
= TREE_CODE (type2
);
4633 /* Quickly detect the usual case where op1 and op2 have the same type
4635 if (TYPE_MAIN_VARIANT (type1
) == TYPE_MAIN_VARIANT (type2
))
4638 result_type
= type1
;
4640 result_type
= cp_build_type_variant
4642 TREE_READONLY (op1
) || TREE_READONLY (op2
),
4643 TREE_THIS_VOLATILE (op1
) || TREE_THIS_VOLATILE (op2
));
4645 else if ((code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
)
4646 && (code2
== INTEGER_TYPE
|| code2
== REAL_TYPE
))
4648 result_type
= common_type (type1
, type2
);
4650 else if (code1
== VOID_TYPE
|| code2
== VOID_TYPE
)
4652 if (pedantic
&& (code1
!= VOID_TYPE
|| code2
!= VOID_TYPE
))
4653 pedwarn ("ANSI C++ forbids conditional expr with only one void side");
4654 result_type
= void_type_node
;
4656 else if (code1
== POINTER_TYPE
&& code2
== POINTER_TYPE
)
4658 if (comp_target_types (type1
, type2
, 1))
4659 result_type
= common_type (type1
, type2
);
4660 else if (integer_zerop (op1
) && TREE_TYPE (type1
) == void_type_node
4661 && TREE_CODE (orig_op1
) != NOP_EXPR
)
4662 result_type
= qualify_type (type2
, type1
);
4663 else if (integer_zerop (op2
) && TREE_TYPE (type2
) == void_type_node
4664 && TREE_CODE (orig_op2
) != NOP_EXPR
)
4665 result_type
= qualify_type (type1
, type2
);
4666 else if (TYPE_MAIN_VARIANT (TREE_TYPE (type1
)) == void_type_node
)
4668 if (pedantic
&& TREE_CODE (type2
) == FUNCTION_TYPE
)
4669 pedwarn ("ANSI C++ forbids conditional expr between `void *' and function pointer");
4670 result_type
= qualify_type (type1
, type2
);
4672 else if (TYPE_MAIN_VARIANT (TREE_TYPE (type2
)) == void_type_node
)
4674 if (pedantic
&& TREE_CODE (type1
) == FUNCTION_TYPE
)
4675 pedwarn ("ANSI C++ forbids conditional expr between `void *' and function pointer");
4676 result_type
= qualify_type (type2
, type1
);
4679 else if (comptypes (type2
, type1
, 0))
4680 result_type
= type2
;
4681 else if (IS_AGGR_TYPE (TREE_TYPE (type1
))
4682 && IS_AGGR_TYPE (TREE_TYPE (type2
))
4683 && (result_type
= common_base_type (TREE_TYPE (type1
), TREE_TYPE (type2
))))
4685 if (result_type
== error_mark_node
)
4687 cp_error ("common base type of types `%T' and `%T' is ambiguous",
4688 TREE_TYPE (type1
), TREE_TYPE (type2
));
4689 result_type
= ptr_type_node
;
4694 && result_type
!= TREE_TYPE (type1
)
4695 && result_type
!= TREE_TYPE (type2
))
4696 cp_pedwarn ("`%T' and `%T' converted to `%T *' in conditional expression",
4697 type1
, type2
, result_type
);
4699 result_type
= TYPE_POINTER_TO (result_type
);
4704 pedwarn ("pointer type mismatch in conditional expression");
4705 result_type
= ptr_type_node
;
4708 else if (code1
== POINTER_TYPE
&& code2
== INTEGER_TYPE
)
4710 if (!integer_zerop (op2
))
4711 pedwarn ("pointer/integer type mismatch in conditional expression");
4714 op2
= null_pointer_node
;
4715 #if 0 /* Sez who? */
4716 if (pedantic
&& TREE_CODE (type1
) == FUNCTION_TYPE
)
4717 pedwarn ("ANSI C++ forbids conditional expr between 0 and function pointer");
4720 result_type
= type1
;
4722 else if (code2
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
4724 if (!integer_zerop (op1
))
4725 pedwarn ("pointer/integer type mismatch in conditional expression");
4728 op1
= null_pointer_node
;
4729 #if 0 /* Sez who? */
4730 if (pedantic
&& TREE_CODE (type2
) == FUNCTION_TYPE
)
4731 pedwarn ("ANSI C++ forbids conditional expr between 0 and function pointer");
4734 result_type
= type2
;
4739 /* The match does not look good. If either is
4740 an aggregate value, try converting to a scalar type. */
4741 if (code1
== RECORD_TYPE
&& code2
== RECORD_TYPE
)
4743 cp_error ("aggregate mismatch in conditional expression: `%T' vs `%T'", type1
, type2
);
4744 return error_mark_node
;
4746 if (code1
== RECORD_TYPE
&& TYPE_HAS_CONVERSION (type1
))
4748 tree tmp
= build_type_conversion (CONVERT_EXPR
, type2
, op1
, 0);
4749 if (tmp
== NULL_TREE
)
4751 cp_error ("aggregate type `%T' could not convert on lhs of `:'", type1
);
4752 return error_mark_node
;
4754 if (tmp
== error_mark_node
)
4755 error ("ambiguous pointer conversion");
4756 result_type
= type2
;
4759 else if (code2
== RECORD_TYPE
&& TYPE_HAS_CONVERSION (type2
))
4761 tree tmp
= build_type_conversion (CONVERT_EXPR
, type1
, op2
, 0);
4762 if (tmp
== NULL_TREE
)
4764 cp_error ("aggregate type `%T' could not convert on rhs of `:'", type2
);
4765 return error_mark_node
;
4767 if (tmp
== error_mark_node
)
4768 error ("ambiguous pointer conversion");
4769 result_type
= type1
;
4772 else if (flag_cond_mismatch
)
4773 result_type
= void_type_node
;
4776 error ("type mismatch in conditional expression");
4777 return error_mark_node
;
4781 if (result_type
!= TREE_TYPE (op1
))
4782 op1
= convert_and_check (result_type
, op1
);
4783 if (result_type
!= TREE_TYPE (op2
))
4784 op2
= convert_and_check (result_type
, op2
);
4787 /* XXX delete me, I've been here for years. */
4788 if (IS_AGGR_TYPE_CODE (code1
))
4790 result_type
= TREE_TYPE (op1
);
4791 if (TREE_CONSTANT (ifexp
))
4792 return (integer_zerop (ifexp
) ? op2
: op1
);
4794 if (TYPE_MODE (result_type
) == BLKmode
)
4796 register tree tempvar
4797 = build_decl (VAR_DECL
, NULL_TREE
, result_type
);
4798 register tree xop1
= build_modify_expr (tempvar
, NOP_EXPR
, op1
);
4799 register tree xop2
= build_modify_expr (tempvar
, NOP_EXPR
, op2
);
4800 register tree result
= fold (build (COND_EXPR
, result_type
,
4801 ifexp
, xop1
, xop2
));
4803 layout_decl (tempvar
, 0);
4804 /* No way to handle variable-sized objects here.
4805 I fear that the entire handling of BLKmode conditional exprs
4806 needs to be redone. */
4807 my_friendly_assert (TREE_CONSTANT (DECL_SIZE (tempvar
)), 315);
4809 = assign_stack_local (DECL_MODE (tempvar
),
4810 (TREE_INT_CST_LOW (DECL_SIZE (tempvar
))
4811 + BITS_PER_UNIT
- 1)
4815 TREE_SIDE_EFFECTS (result
)
4816 = TREE_SIDE_EFFECTS (ifexp
) | TREE_SIDE_EFFECTS (op1
)
4817 | TREE_SIDE_EFFECTS (op2
);
4818 return build (COMPOUND_EXPR
, result_type
, result
, tempvar
);
4823 if (TREE_CONSTANT (ifexp
))
4824 return integer_zerop (ifexp
) ? op2
: op1
;
4826 return fold (build (COND_EXPR
, result_type
, ifexp
, op1
, op2
));
4829 /* Handle overloading of the ',' operator when needed. Otherwise,
4830 this function just builds an expression list. */
4832 build_x_compound_expr (list
)
4835 tree rest
= TREE_CHAIN (list
);
4838 if (rest
== NULL_TREE
)
4839 return build_compound_expr (list
);
4841 result
= build_opfncall (COMPOUND_EXPR
, LOOKUP_NORMAL
,
4842 TREE_VALUE (list
), TREE_VALUE (rest
), NULL_TREE
);
4844 return build_x_compound_expr (tree_cons (NULL_TREE
, result
, TREE_CHAIN (rest
)));
4845 return build_compound_expr (tree_cons (NULL_TREE
, TREE_VALUE (list
),
4846 build_tree_list (NULL_TREE
, build_x_compound_expr (rest
))));
4849 /* Given a list of expressions, return a compound expression
4850 that performs them all and returns the value of the last of them. */
4853 build_compound_expr (list
)
4858 if (TREE_READONLY_DECL_P (TREE_VALUE (list
)))
4859 TREE_VALUE (list
) = decl_constant_value (TREE_VALUE (list
));
4861 if (TREE_CHAIN (list
) == 0)
4863 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
4864 Strip such NOP_EXPRs, since LIST is used in non-lvalue context. */
4865 if (TREE_CODE (list
) == NOP_EXPR
4866 && TREE_TYPE (list
) == TREE_TYPE (TREE_OPERAND (list
, 0)))
4867 list
= TREE_OPERAND (list
, 0);
4869 /* Convert arrays to pointers. */
4870 if (TREE_CODE (TREE_TYPE (TREE_VALUE (list
))) == ARRAY_TYPE
)
4871 return default_conversion (TREE_VALUE (list
));
4873 return TREE_VALUE (list
);
4876 rest
= build_compound_expr (TREE_CHAIN (list
));
4878 if (! TREE_SIDE_EFFECTS (TREE_VALUE (list
)))
4880 /* the left-hand operand of a comma expression is like an expression
4881 statement: we should warn if it doesn't have any side-effects,
4882 unless it was explicitly cast to (void). */
4883 if ((extra_warnings
|| warn_unused
)
4884 && !(TREE_CODE (TREE_VALUE(list
)) == CONVERT_EXPR
4885 && TREE_TYPE (TREE_VALUE(list
)) == void_type_node
))
4886 warning("left-hand operand of comma expression has no effect");
4888 /* When pedantic, a compound expression can be neither an lvalue
4889 nor an integer constant expression. */
4893 #if 0 /* this requires a gcc backend patch to export warn_if_unused_value */
4894 else if (warn_unused
)
4895 warn_if_unused_value (TREE_VALUE(list
));
4898 return build (COMPOUND_EXPR
, TREE_TYPE (rest
),
4899 break_out_cleanups (TREE_VALUE (list
)), rest
);
4909 return (TREE_CODE (t
) == INTEGER_CST
&& integer_zerop (t
));
4912 tree
build_static_cast (type
, expr
)
4915 return build_c_cast (type
, expr
, 0);
4918 tree
build_reinterpret_cast (type
, expr
)
4921 tree intype
= TREE_TYPE (expr
);
4923 if (TYPE_PTRMEMFUNC_P (type
))
4924 type
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
4925 if (TYPE_PTRMEMFUNC_P (intype
))
4926 intype
= TYPE_PTRMEMFUNC_FN_TYPE (intype
);
4928 if (! POINTER_TYPE_P (type
) && ! TREE_CODE (type
) == INTEGER_TYPE
)
4930 cp_error ("reinterpret_cast cannot convert to type `%T'", type
);
4931 return error_mark_node
;
4933 if (! POINTER_TYPE_P (intype
) && ! TREE_CODE (intype
) == INTEGER_TYPE
)
4935 cp_error ("reinterpret_cast cannot convert from type `%T'", type
);
4936 return error_mark_node
;
4938 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_CODE (intype
) != POINTER_TYPE
)
4940 cp_error ("reinterpret_cast cannot convert non-pointer type `%T' to `%T'",
4942 return error_mark_node
;
4944 if (TREE_CODE (intype
) == INTEGER_TYPE
&& TREE_CODE (type
) != POINTER_TYPE
)
4946 cp_error ("reinterpret_cast cannot convert `%T' to non-pointer type `%T'",
4948 return error_mark_node
;
4951 if (TREE_CODE (type
) == POINTER_TYPE
&& TREE_CODE (intype
) == POINTER_TYPE
)
4952 expr
= convert (ptr_type_node
, expr
);
4954 return build_c_cast (type
, expr
, 0);
4957 tree
build_const_cast (type
, expr
)
4960 tree intype
= TREE_TYPE (expr
);
4963 if (TYPE_PTRMEMFUNC_P (type
))
4964 type
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
4965 if (TYPE_PTRMEMFUNC_P (intype
))
4966 intype
= TYPE_PTRMEMFUNC_FN_TYPE (intype
);
4968 if (! POINTER_TYPE_P (type
))
4970 cp_error ("const_cast cannot convert to non-pointer type `%T'", type
);
4971 return error_mark_node
;
4973 if (TREE_CODE (type
) == REFERENCE_TYPE
&& ! real_lvalue_p (expr
))
4975 cp_error ("const_cast cannot convert rvalue to type `%T'", type
);
4976 return error_mark_node
;
4978 if (TREE_CODE (type
) == POINTER_TYPE
&& TREE_CODE (intype
) != POINTER_TYPE
)
4980 cp_error ("const_cast cannot convert non-pointer type `%T' to type `%T'",
4982 return error_mark_node
;
4985 if (TREE_CODE (type
) == REFERENCE_TYPE
)
4987 t1
= TREE_TYPE (type
);
4992 t1
= TREE_TYPE (type
);
4993 t2
= TREE_TYPE (intype
);
4995 for (; TREE_CODE (t1
) == POINTER_TYPE
&& TREE_CODE (t2
) == POINTER_TYPE
;
4996 t1
= TREE_TYPE (t1
), t2
= TREE_TYPE (t2
))
5000 if (TREE_CODE (t1
) == OFFSET_TYPE
&& TREE_CODE (t2
) == OFFSET_TYPE
)
5002 if (TYPE_OFFSET_BASETYPE (t1
) != TYPE_OFFSET_BASETYPE (t2
))
5004 cp_error ("const_cast cannot convert between pointers to members of different types `%T' and `%T'",
5005 TYPE_OFFSET_BASETYPE (t2
), TYPE_OFFSET_BASETYPE (t1
));
5006 return error_mark_node
;
5008 t1
= TREE_TYPE (t1
);
5009 t2
= TREE_TYPE (t2
);
5012 if (TYPE_MAIN_VARIANT (t1
) != TYPE_MAIN_VARIANT (t2
))
5014 cp_error ("const_cast cannot convert unrelated type `%T' to `%T'",
5016 return error_mark_node
;
5019 return build_c_cast (type
, expr
, 0);
5022 /* Build an expression representing a cast to type TYPE of expression EXPR.
5024 ALLOW_NONCONVERTING is true if we should allow non-converting constructors
5025 when doing the cast. */
5028 build_c_cast (type
, expr
, allow_nonconverting
)
5031 int allow_nonconverting
;
5033 register tree value
= expr
;
5035 if (type
== error_mark_node
|| expr
== error_mark_node
)
5036 return error_mark_node
;
5038 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5039 Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */
5040 if (TREE_CODE (type
) != REFERENCE_TYPE
5041 && TREE_CODE (value
) == NOP_EXPR
5042 && TREE_TYPE (value
) == TREE_TYPE (TREE_OPERAND (value
, 0)))
5043 value
= TREE_OPERAND (value
, 0);
5045 if (TREE_TYPE (expr
)
5046 && TREE_CODE (TREE_TYPE (expr
)) == OFFSET_TYPE
5047 && TREE_CODE (type
) != OFFSET_TYPE
)
5048 value
= resolve_offset_ref (value
);
5050 if (TREE_CODE (type
) == ARRAY_TYPE
)
5052 /* Allow casting from T1* to T2[] because Cfront allows it.
5053 NIHCL uses it. It is not valid ANSI C however, and hence, not
5055 if (TREE_CODE (TREE_TYPE (expr
)) == POINTER_TYPE
)
5058 pedwarn ("ANSI C++ forbids casting to an array type");
5059 type
= build_pointer_type (TREE_TYPE (type
));
5063 error ("ANSI C++ forbids casting to an array type");
5064 return error_mark_node
;
5068 if (TREE_CODE (type
) == FUNCTION_TYPE
5069 || TREE_CODE (type
) == METHOD_TYPE
)
5071 cp_error ("casting to function type `%T'", type
);
5072 return error_mark_node
;
5075 if (IS_SIGNATURE (type
))
5077 error ("cast specifies signature type");
5078 return error_mark_node
;
5081 /* If there's only one function in the overloaded space,
5083 if (TREE_CODE (value
) == TREE_LIST
5084 && TREE_CHAIN (value
) == NULL_TREE
)
5085 value
= TREE_VALUE (value
);
5087 if (TREE_CODE (type
) == VOID_TYPE
)
5088 value
= build1 (CONVERT_EXPR
, type
, value
);
5089 else if (TREE_TYPE (value
) == NULL_TREE
5090 || type_unknown_p (value
))
5092 value
= instantiate_type (type
, value
, 1);
5094 if (value
== error_mark_node
)
5095 return error_mark_node
;
5102 /* Convert functions and arrays to pointers and
5103 convert references to their expanded types,
5104 but don't convert any other types. */
5105 if (TREE_CODE (TREE_TYPE (value
)) == FUNCTION_TYPE
5106 || TREE_CODE (TREE_TYPE (value
)) == METHOD_TYPE
5107 || TREE_CODE (TREE_TYPE (value
)) == ARRAY_TYPE
5108 || TREE_CODE (TREE_TYPE (value
)) == REFERENCE_TYPE
)
5109 value
= default_conversion (value
);
5110 otype
= TREE_TYPE (value
);
5112 /* Optionally warn about potentially worrisome casts. */
5115 && TREE_CODE (type
) == POINTER_TYPE
5116 && TREE_CODE (otype
) == POINTER_TYPE
)
5118 /* For C++ we make these regular warnings, rather than
5119 softening them into pedwarns. */
5120 if (TYPE_VOLATILE (TREE_TYPE (otype
))
5121 && ! TYPE_VOLATILE (TREE_TYPE (type
)))
5122 warning ("cast discards `volatile' from pointer target type");
5123 if (TYPE_READONLY (TREE_TYPE (otype
))
5124 && ! TYPE_READONLY (TREE_TYPE (type
)))
5125 warning ("cast discards `const' from pointer target type");
5128 /* Warn about possible alignment problems. */
5129 if (STRICT_ALIGNMENT
&& warn_cast_align
5130 && TREE_CODE (type
) == POINTER_TYPE
5131 && TREE_CODE (otype
) == POINTER_TYPE
5132 && TREE_CODE (TREE_TYPE (otype
)) != VOID_TYPE
5133 && TREE_CODE (TREE_TYPE (otype
)) != FUNCTION_TYPE
5134 && TYPE_ALIGN (TREE_TYPE (type
)) > TYPE_ALIGN (TREE_TYPE (otype
)))
5135 warning ("cast increases required alignment of target type");
5138 if (TREE_CODE (type
) == INTEGER_TYPE
5139 && TREE_CODE (otype
) == POINTER_TYPE
5140 && TYPE_PRECISION (type
) != TYPE_PRECISION (otype
))
5141 warning ("cast from pointer to integer of different size");
5143 if (TREE_CODE (type
) == POINTER_TYPE
5144 && TREE_CODE (otype
) == INTEGER_TYPE
5145 && TYPE_PRECISION (type
) != TYPE_PRECISION (otype
)
5146 /* Don't warn about converting 0 to pointer,
5147 provided the 0 was explicit--not cast or made by folding. */
5148 && !(TREE_CODE (value
) == INTEGER_CST
&& integer_zerop (value
)))
5149 warning ("cast to pointer from integer of different size");
5152 flag
= allow_nonconverting
? CONV_NONCONVERTING
: 0;
5154 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5155 value
= (convert_from_reference
5156 (convert_to_reference (type
, value
, CONV_OLD_CONVERT
|flag
,
5157 LOOKUP_COMPLAIN
, NULL_TREE
)));
5162 if (TREE_READONLY_DECL_P (value
))
5163 value
= decl_constant_value (value
);
5166 value
= convert_force (type
, value
, flag
);
5168 /* Ignore any integer overflow caused by the cast. */
5169 if (TREE_CODE (value
) == INTEGER_CST
)
5171 TREE_OVERFLOW (value
) = TREE_OVERFLOW (ovalue
);
5172 TREE_CONSTANT_OVERFLOW (value
) = TREE_CONSTANT_OVERFLOW (ovalue
);
5177 /* Always produce some operator for an explicit cast,
5178 so we can tell (for -pedantic) that the cast is no lvalue.
5179 Also, pedantically, don't let (void *) (FOO *) 0 be a null
5180 pointer constant. */
5183 && TREE_CODE (value
) == INTEGER_CST
5184 && TREE_CODE (expr
) == INTEGER_CST
5185 && TREE_CODE (TREE_TYPE (expr
)) != INTEGER_TYPE
))
5186 value
= non_lvalue (value
);
5192 /* Build an assignment expression of lvalue LHS from value RHS.
5194 In C++, if the left hand side of the assignment is a REFERENCE_TYPE,
5195 that reference becomes deferenced down to it base type. */
5197 /* Return a reference to the BASE_INDEX part of EXPR. TYPE is
5198 the type to which BASE_INDEX applies. */
5200 get_base_ref (type
, base_index
, expr
)
5205 tree binfos
= TYPE_BINFO_BASETYPES (type
);
5206 tree base_binfo
= TREE_VEC_ELT (binfos
, base_index
);
5209 if (TREE_CODE (expr
) == ARRAY_REF
5210 || ! BINFO_OFFSET_ZEROP (base_binfo
)
5211 || TREE_VIA_VIRTUAL (base_binfo
)
5212 || TYPE_MODE (type
) != TYPE_MODE (BINFO_TYPE (base_binfo
)))
5214 tree addr
= build_unary_op (ADDR_EXPR
, expr
, 0);
5215 ref
= build_indirect_ref (convert_pointer_to (base_binfo
, addr
),
5220 ref
= copy_node (expr
);
5221 TREE_TYPE (ref
) = BINFO_TYPE (base_binfo
);
5226 /* Build an assignment expression of lvalue LHS from value RHS.
5227 MODIFYCODE is the code for a binary operator that we use
5228 to combine the old value of LHS with RHS to get the new value.
5229 Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.
5231 C++: If MODIFYCODE is INIT_EXPR, then leave references unbashed.
5233 `build_modify_expr_1' implements recursive part of memberwise
5234 assignment operation. */
5236 build_modify_expr_1 (lhs
, modifycode
, rhs
, basetype_path
)
5238 enum tree_code modifycode
;
5241 register tree result
;
5243 tree lhstype
= TREE_TYPE (lhs
);
5244 tree olhstype
= lhstype
;
5246 /* Avoid duplicate error messages from operands that had errors. */
5247 if (TREE_CODE (lhs
) == ERROR_MARK
|| TREE_CODE (rhs
) == ERROR_MARK
)
5248 return error_mark_node
;
5250 /* If a binary op has been requested, combine the old LHS value with the RHS
5251 producing the value we should actually store into the LHS. */
5253 if (modifycode
== INIT_EXPR
)
5255 else if (modifycode
== NOP_EXPR
)
5257 /* must deal with overloading of `operator=' here. */
5258 if (TREE_CODE (lhstype
) == REFERENCE_TYPE
)
5259 lhstype
= TREE_TYPE (lhstype
);
5265 lhs
= stabilize_reference (lhs
);
5266 newrhs
= build_binary_op (modifycode
, lhs
, rhs
, 1);
5267 modifycode
= NOP_EXPR
;
5270 /* If storing into a structure or union member,
5271 it has probably been given type `int'.
5272 Compute the type that would go with
5273 the actual amount of storage the member occupies. */
5275 if (TREE_CODE (lhs
) == COMPONENT_REF
5276 && (TREE_CODE (lhstype
) == INTEGER_TYPE
5277 || TREE_CODE (lhstype
) == REAL_TYPE
5278 || TREE_CODE (lhstype
) == ENUMERAL_TYPE
))
5279 lhstype
= TREE_TYPE (get_unwidened (lhs
, 0));
5281 /* C++: The semantics of C++ differ from those of C when an
5282 assignment of an aggregate is desired. Assignment in C++ is
5283 now defined as memberwise assignment of non-static members
5284 and base class objects. This rule applies recursively
5285 until a member of a built-in type is found.
5287 Also, we cannot do a bit-wise copy of aggregates which
5288 contain virtual function table pointers. Those
5289 pointer values must be preserved through the copy.
5290 However, this is handled in expand_expr, and not here.
5291 This is because much better code can be generated at
5292 that stage than this one. */
5293 if (TREE_CODE (lhstype
) == RECORD_TYPE
5294 && TYPE_LANG_SPECIFIC (lhstype
)
5295 && TYPE_MAIN_VARIANT (lhstype
) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs
)))
5300 /* Perform operation on object. */
5301 if (modifycode
== INIT_EXPR
&& TYPE_HAS_INIT_REF (lhstype
))
5303 result
= build_method_call (lhs
, constructor_name_full (lhstype
),
5304 build_tree_list (NULL_TREE
, rhs
),
5305 basetype_path
, LOOKUP_NORMAL
);
5306 return build_indirect_ref (result
, NULL_PTR
);
5308 else if (modifycode
== NOP_EXPR
)
5310 /* `operator=' is not an inheritable operator; see 13.4.3. */
5311 if (TYPE_LANG_SPECIFIC (lhstype
) && TYPE_HAS_ASSIGNMENT (lhstype
))
5313 result
= build_opfncall (MODIFY_EXPR
, LOOKUP_NORMAL
,
5314 lhs
, rhs
, make_node (NOP_EXPR
));
5315 if (result
== NULL_TREE
)
5316 return error_mark_node
;
5321 if (TYPE_USES_VIRTUAL_BASECLASSES (lhstype
)
5322 || (modifycode
== NOP_EXPR
&& TYPE_GETS_ASSIGNMENT (lhstype
))
5323 || (modifycode
== INIT_EXPR
&& TYPE_GETS_INIT_REF (lhstype
)))
5325 tree binfos
= BINFO_BASETYPES (TYPE_BINFO (lhstype
));
5328 if (binfos
!= NULL_TREE
)
5329 /* Perform operation on each member, depth-first, left-right. */
5330 for (i
= 0; i
<= TREE_VEC_LENGTH (binfos
)-1; i
++)
5332 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
5333 tree base_lhs
, base_rhs
;
5336 /* Assignments from virtual baseclasses handled elsewhere. */
5337 if (TREE_VIA_VIRTUAL (base_binfo
))
5340 base_lhs
= get_base_ref (lhstype
, i
, lhs
);
5341 base_rhs
= get_base_ref (lhstype
, i
, newrhs
);
5343 BINFO_INHERITANCE_CHAIN (base_binfo
) = basetype_path
;
5345 = build_modify_expr_1 (base_lhs
, modifycode
, base_rhs
,
5348 /* We either get back a compound stmt, or a simple one. */
5349 if (new_result
&& TREE_CODE (new_result
) == TREE_LIST
)
5350 new_result
= build_compound_expr (new_result
);
5351 result
= tree_cons (NULL_TREE
, new_result
, result
);
5354 for (elt
= TYPE_FIELDS (lhstype
); elt
; elt
= TREE_CHAIN (elt
))
5356 tree vbases
= NULL_TREE
;
5357 tree elt_lhs
, elt_rhs
;
5359 if (TREE_CODE (elt
) != FIELD_DECL
)
5362 && (VFIELD_NAME_P (DECL_NAME (elt
))
5363 || VBASE_NAME_P (DECL_NAME (elt
))))
5366 if (TREE_READONLY (elt
)
5367 || TREE_CODE (TREE_TYPE (elt
)) == REFERENCE_TYPE
)
5369 cp_error ("cannot generate default `%T::operator ='",
5371 if (TREE_CODE (TREE_TYPE (elt
)) == REFERENCE_TYPE
)
5372 cp_error_at ("because member `%#D' is a reference", elt
);
5374 cp_error_at ("because member `%#D' is const", elt
);
5376 return error_mark_node
;
5379 if (IS_AGGR_TYPE (TREE_TYPE (elt
))
5380 && TYPE_LANG_SPECIFIC (TREE_TYPE (elt
)))
5381 vbases
= CLASSTYPE_VBASECLASSES (TREE_TYPE (elt
));
5383 elt_lhs
= build (COMPONENT_REF
, TREE_TYPE (elt
), lhs
, elt
);
5384 elt_rhs
= build (COMPONENT_REF
, TREE_TYPE (elt
), newrhs
, elt
);
5385 /* It is not always safe to go through `build_modify_expr_1'
5386 when performing element-wise copying. This is because
5387 an element may be of ARRAY_TYPE, which will not
5388 be properly copied as a naked element. */
5389 if (TREE_CODE (TREE_TYPE (elt
)) == RECORD_TYPE
5390 && TYPE_LANG_SPECIFIC (TREE_TYPE (elt
)))
5391 basetype_path
= TYPE_BINFO (TREE_TYPE (elt
));
5395 tree elt_lhs_addr
= build_unary_op (ADDR_EXPR
, elt_lhs
, 0);
5396 tree elt_rhs_addr
= build_unary_op (ADDR_EXPR
, elt_rhs
, 0);
5398 elt_lhs_addr
= convert_pointer_to (vbases
, elt_lhs_addr
);
5399 elt_rhs_addr
= convert_pointer_to (vbases
, elt_rhs_addr
);
5401 = tree_cons (NULL_TREE
,
5403 (build_indirect_ref (elt_lhs_addr
, NULL_PTR
),
5405 build_indirect_ref (elt_rhs_addr
, NULL_PTR
),
5408 if (TREE_VALUE (result
) == error_mark_node
)
5409 return error_mark_node
;
5410 vbases
= TREE_CHAIN (vbases
);
5412 elt_lhs
= build_modify_expr_1 (elt_lhs
, modifycode
, elt_rhs
,
5414 result
= tree_cons (NULL_TREE
, elt_lhs
, result
);
5418 return build_compound_expr (result
);
5419 /* No fields to move. */
5420 return integer_zero_node
;
5424 result
= build (modifycode
== NOP_EXPR
? MODIFY_EXPR
: INIT_EXPR
,
5425 void_type_node
, lhs
, rhs
);
5426 TREE_SIDE_EFFECTS (result
) = 1;
5431 result
= build_modify_expr (lhs
, modifycode
, newrhs
);
5432 /* ARRAY_TYPEs cannot be converted to anything meaningful,
5433 and leaving it there screws up `build_compound_expr' when
5434 it tries to defaultly convert everything. */
5435 if (TREE_CODE (TREE_TYPE (result
)) == ARRAY_TYPE
)
5436 TREE_TYPE (result
) = void_type_node
;
5441 /* Taken from expr.c:
5442 Subroutine of expand_expr:
5443 record the non-copied parts (LIST) of an expr (LHS), and return a list
5444 which specifies the initial values of these parts. */
5447 init_noncopied_parts (lhs
, list
)
5454 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
5455 if (TREE_CODE (TREE_VALUE (tail
)) == TREE_LIST
)
5456 parts
= chainon (parts
, init_noncopied_parts (lhs
, TREE_VALUE (tail
)));
5459 tree part
= TREE_VALUE (tail
);
5460 tree part_type
= TREE_TYPE (part
);
5461 tree to_be_initialized
= build (COMPONENT_REF
, part_type
, lhs
, part
);
5462 parts
= tree_cons (TREE_PURPOSE (tail
), to_be_initialized
, parts
);
5467 /* Build an assignment expression of lvalue LHS from value RHS.
5468 MODIFYCODE is the code for a binary operator that we use
5469 to combine the old value of LHS with RHS to get the new value.
5470 Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.
5472 C++: If MODIFYCODE is INIT_EXPR, then leave references unbashed.
5475 build_modify_expr (lhs
, modifycode
, rhs
)
5477 enum tree_code modifycode
;
5480 register tree result
;
5482 tree lhstype
= TREE_TYPE (lhs
);
5483 tree olhstype
= lhstype
;
5486 /* Avoid duplicate error messages from operands that had errors. */
5487 if (TREE_CODE (lhs
) == ERROR_MARK
|| TREE_CODE (rhs
) == ERROR_MARK
)
5488 return error_mark_node
;
5490 /* Types that aren't fully specified cannot be used in assignments. */
5491 lhs
= require_complete_type (lhs
);
5493 /* Decide early if we are going to protect RHS from GC
5494 before assigning it to LHS. */
5495 if (type_needs_gc_entry (TREE_TYPE (rhs
))
5496 && ! value_safe_from_gc (lhs
, rhs
))
5497 rhs
= protect_value_from_gc (lhs
, rhs
);
5501 /* Handle assignment to signature pointers/refs. */
5503 if (TYPE_LANG_SPECIFIC (lhstype
) &&
5504 (IS_SIGNATURE_POINTER (lhstype
) || IS_SIGNATURE_REFERENCE (lhstype
)))
5506 return build_signature_pointer_constructor (lhs
, rhs
);
5509 /* Handle control structure constructs used as "lvalues". */
5511 switch (TREE_CODE (lhs
))
5513 /* Handle --foo = 5; as these are valid constructs in C++ */
5514 case PREDECREMENT_EXPR
:
5515 case PREINCREMENT_EXPR
:
5516 if (TREE_SIDE_EFFECTS (TREE_OPERAND (lhs
, 0)))
5517 lhs
= build (TREE_CODE (lhs
), TREE_TYPE (lhs
),
5518 stabilize_reference (TREE_OPERAND (lhs
, 0)));
5519 return build (COMPOUND_EXPR
, lhstype
,
5521 build_modify_expr (TREE_OPERAND (lhs
, 0),
5524 /* Handle (a, b) used as an "lvalue". */
5526 newrhs
= build_modify_expr (TREE_OPERAND (lhs
, 1),
5528 if (TREE_CODE (newrhs
) == ERROR_MARK
)
5529 return error_mark_node
;
5530 return build (COMPOUND_EXPR
, lhstype
,
5531 TREE_OPERAND (lhs
, 0), newrhs
);
5534 newrhs
= build_modify_expr (TREE_OPERAND (lhs
, 0), modifycode
, rhs
);
5535 if (TREE_CODE (newrhs
) == ERROR_MARK
)
5536 return error_mark_node
;
5537 return build (COMPOUND_EXPR
, lhstype
, lhs
, newrhs
);
5539 /* Handle (a ? b : c) used as an "lvalue". */
5541 rhs
= save_expr (rhs
);
5543 /* Produce (a ? (b = rhs) : (c = rhs))
5544 except that the RHS goes through a save-expr
5545 so the code to compute it is only emitted once. */
5547 = build_conditional_expr (TREE_OPERAND (lhs
, 0),
5548 build_modify_expr (convert (TREE_TYPE (lhs
), TREE_OPERAND (lhs
, 1)),
5550 build_modify_expr (convert (TREE_TYPE (lhs
), TREE_OPERAND (lhs
, 2)),
5552 if (TREE_CODE (cond
) == ERROR_MARK
)
5554 /* Make sure the code to compute the rhs comes out
5555 before the split. */
5556 return build (COMPOUND_EXPR
, TREE_TYPE (lhs
),
5557 /* Case to void to suppress warning
5558 from warn_if_unused_value. */
5559 convert (void_type_node
, rhs
), cond
);
5563 if (TREE_CODE (lhs
) == OFFSET_REF
)
5565 if (TREE_OPERAND (lhs
, 0) == NULL_TREE
)
5567 /* Static class member? */
5568 tree member
= TREE_OPERAND (lhs
, 1);
5569 if (TREE_CODE (member
) == VAR_DECL
)
5573 compiler_error ("invalid static class member");
5574 return error_mark_node
;
5578 lhs
= resolve_offset_ref (lhs
);
5580 olhstype
= lhstype
= TREE_TYPE (lhs
);
5583 if (TREE_CODE (lhstype
) == REFERENCE_TYPE
5584 && modifycode
!= INIT_EXPR
)
5586 lhs
= convert_from_reference (lhs
);
5587 olhstype
= lhstype
= TREE_TYPE (lhs
);
5590 /* If a binary op has been requested, combine the old LHS value with the RHS
5591 producing the value we should actually store into the LHS. */
5593 if (modifycode
== INIT_EXPR
)
5595 if (! IS_AGGR_TYPE (lhstype
))
5596 /* Do the default thing */;
5597 else if (! TYPE_HAS_CONSTRUCTOR (lhstype
))
5598 cp_error ("`%T' has no constructors", lhstype
);
5599 else if (! TYPE_NEEDS_CONSTRUCTING (lhstype
)
5600 && TYPE_MAIN_VARIANT (lhstype
) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs
)))
5601 /* Do the default thing */;
5604 result
= build_method_call (lhs
, constructor_name_full (lhstype
),
5605 build_tree_list (NULL_TREE
, rhs
),
5606 NULL_TREE
, LOOKUP_NORMAL
);
5607 if (result
== NULL_TREE
)
5608 return error_mark_node
;
5612 else if (modifycode
== NOP_EXPR
)
5615 /* `operator=' is not an inheritable operator. */
5616 if (! IS_AGGR_TYPE (lhstype
))
5617 /* Do the default thing */;
5618 else if (! TYPE_HAS_ASSIGNMENT (lhstype
))
5619 cp_error ("`%T' does not define operator=", lhstype
);
5620 else if (! TYPE_HAS_REAL_ASSIGNMENT (lhstype
)
5621 && ! TYPE_HAS_COMPLEX_ASSIGN_REF (lhstype
)
5622 && TYPE_MAIN_VARIANT (lhstype
) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs
)))
5623 /* Do the default thing */;
5626 result
= build_opfncall (MODIFY_EXPR
, LOOKUP_NORMAL
,
5627 lhs
, rhs
, make_node (NOP_EXPR
));
5628 if (result
== NULL_TREE
)
5629 return error_mark_node
;
5633 /* Treat `operator=' as an inheritable operator. */
5634 if (TYPE_LANG_SPECIFIC (lhstype
) && TYPE_GETS_ASSIGNMENT (lhstype
))
5636 tree orig_lhstype
= lhstype
;
5637 while (! TYPE_HAS_ASSIGNMENT (lhstype
))
5639 int i
, n_baseclasses
= CLASSTYPE_N_BASECLASSES (lhstype
);
5640 tree basetype
= NULL_TREE
;
5641 for (i
= 0; i
< n_baseclasses
; i
++)
5642 if (TYPE_GETS_ASSIGNMENT (TYPE_BINFO_BASETYPE (lhstype
, i
)))
5644 if (basetype
!= NULL_TREE
)
5646 message_2_types (error
, "base classes `%s' and `%s' both have operator ='",
5648 TYPE_BINFO_BASETYPE (lhstype
, i
));
5649 return error_mark_node
;
5651 basetype
= TYPE_BINFO_BASETYPE (lhstype
, i
);
5655 if (orig_lhstype
!= lhstype
)
5657 lhs
= build_indirect_ref (convert_pointer_to (lhstype
,
5658 build_unary_op (ADDR_EXPR
, lhs
, 0)), NULL_PTR
);
5659 if (lhs
== error_mark_node
)
5661 cp_error ("conversion to private basetype `%T'", lhstype
);
5662 return error_mark_node
;
5665 result
= build_opfncall (MODIFY_EXPR
, LOOKUP_NORMAL
,
5666 lhs
, rhs
, make_node (NOP_EXPR
));
5667 if (result
== NULL_TREE
)
5668 return error_mark_node
;
5674 else if (PROMOTES_TO_AGGR_TYPE (lhstype
, REFERENCE_TYPE
))
5676 /* This case must convert to some sort of lvalue that
5677 can participate in an op= operation. */
5680 if (build_default_binary_type_conversion (modifycode
, &lhs_tmp
, &rhs_tmp
))
5682 lhs
= stabilize_reference (lhs_tmp
);
5683 /* Forget is was ever anything else. */
5684 olhstype
= lhstype
= TREE_TYPE (lhs
);
5685 newrhs
= build_binary_op (modifycode
, lhs
, rhs_tmp
, 1);
5689 cp_error ("no match for `%O(%#T, %#T)'", modifycode
,
5690 TREE_TYPE (lhs
), TREE_TYPE (rhs
));
5691 return error_mark_node
;
5696 lhs
= stabilize_reference (lhs
);
5697 newrhs
= build_binary_op (modifycode
, lhs
, rhs
, 1);
5700 /* Handle a cast used as an "lvalue".
5701 We have already performed any binary operator using the value as cast.
5702 Now convert the result to the cast type of the lhs,
5703 and then true type of the lhs and store it there;
5704 then convert result back to the cast type to be the value
5705 of the assignment. */
5707 switch (TREE_CODE (lhs
))
5712 case FIX_TRUNC_EXPR
:
5713 case FIX_FLOOR_EXPR
:
5714 case FIX_ROUND_EXPR
:
5716 if (TREE_CODE (TREE_TYPE (newrhs
)) == ARRAY_TYPE
5717 || TREE_CODE (TREE_TYPE (newrhs
)) == FUNCTION_TYPE
5718 || TREE_CODE (TREE_TYPE (newrhs
)) == METHOD_TYPE
5719 || TREE_CODE (TREE_TYPE (newrhs
)) == OFFSET_TYPE
)
5720 newrhs
= default_conversion (newrhs
);
5722 tree inner_lhs
= TREE_OPERAND (lhs
, 0);
5724 if (! lvalue_p (lhs
) && pedantic
)
5725 pedwarn ("cast to non-reference type used as lvalue");
5727 result
= build_modify_expr (inner_lhs
, NOP_EXPR
,
5728 convert (TREE_TYPE (inner_lhs
),
5729 convert (lhstype
, newrhs
)));
5730 if (TREE_CODE (result
) == ERROR_MARK
)
5732 return convert (TREE_TYPE (lhs
), result
);
5736 /* Now we have handled acceptable kinds of LHS that are not truly lvalues.
5737 Reject anything strange now. */
5739 if (!lvalue_or_else (lhs
, "assignment"))
5740 return error_mark_node
;
5742 GNU_xref_assign (lhs
);
5744 /* Warn about storing in something that is `const'. */
5745 /* For C++, don't warn if this is initialization. */
5746 if (modifycode
!= INIT_EXPR
5747 /* For assignment to `const' signature pointer/reference fields,
5748 don't warn either, we already printed a better message before. */
5749 && ! (TREE_CODE (lhs
) == COMPONENT_REF
5750 && (IS_SIGNATURE_POINTER (TREE_TYPE (TREE_OPERAND (lhs
, 0)))
5751 || IS_SIGNATURE_REFERENCE (TREE_TYPE (TREE_OPERAND (lhs
, 0)))))
5752 && (TREE_READONLY (lhs
) || TYPE_READONLY (lhstype
)
5753 || ((TREE_CODE (lhstype
) == RECORD_TYPE
5754 || TREE_CODE (lhstype
) == UNION_TYPE
)
5755 && C_TYPE_FIELDS_READONLY (lhstype
))
5756 || (TREE_CODE (lhstype
) == REFERENCE_TYPE
5757 && TYPE_READONLY (TREE_TYPE (lhstype
)))))
5758 readonly_error (lhs
, "assignment", 0);
5760 /* If storing into a structure or union member,
5761 it has probably been given type `int'.
5762 Compute the type that would go with
5763 the actual amount of storage the member occupies. */
5765 if (TREE_CODE (lhs
) == COMPONENT_REF
5766 && (TREE_CODE (lhstype
) == INTEGER_TYPE
5767 || TREE_CODE (lhstype
) == REAL_TYPE
5768 || TREE_CODE (lhstype
) == ENUMERAL_TYPE
))
5770 lhstype
= TREE_TYPE (get_unwidened (lhs
, 0));
5772 /* If storing in a field that is in actuality a short or narrower
5773 than one, we must store in the field in its actual type. */
5775 if (lhstype
!= TREE_TYPE (lhs
))
5777 lhs
= copy_node (lhs
);
5778 TREE_TYPE (lhs
) = lhstype
;
5782 /* check to see if there is an assignment to `this' */
5783 if (lhs
== current_class_decl
)
5785 if (flag_this_is_variable
> 0
5786 && DECL_NAME (current_function_decl
) != NULL_TREE
5787 && (DECL_NAME (current_function_decl
)
5788 != constructor_name (current_class_type
)))
5789 warning ("assignment to `this' not in constructor or destructor");
5790 current_function_just_assigned_this
= 1;
5793 /* The TREE_TYPE of RHS may be TYPE_UNKNOWN. This can happen
5794 when the type of RHS is not yet known, i.e. its type
5795 is inherited from LHS. */
5796 rhs
= require_instantiated_type (lhstype
, newrhs
, error_mark_node
);
5797 if (rhs
== error_mark_node
)
5798 return error_mark_node
;
5801 if (modifycode
!= INIT_EXPR
)
5803 /* Make modifycode now either a NOP_EXPR or an INIT_EXPR. */
5804 modifycode
= NOP_EXPR
;
5805 /* Reference-bashing */
5806 if (TREE_CODE (lhstype
) == REFERENCE_TYPE
)
5808 tree tmp
= convert_from_reference (lhs
);
5809 lhstype
= TREE_TYPE (tmp
);
5810 if (TYPE_SIZE (lhstype
) == 0)
5812 incomplete_type_error (lhs
, lhstype
);
5813 return error_mark_node
;
5818 if (TREE_CODE (TREE_TYPE (newrhs
)) == REFERENCE_TYPE
)
5820 tree tmp
= convert_from_reference (newrhs
);
5821 if (TYPE_SIZE (TREE_TYPE (tmp
)) == 0)
5823 incomplete_type_error (newrhs
, TREE_TYPE (tmp
));
5824 return error_mark_node
;
5830 if (TREE_SIDE_EFFECTS (lhs
))
5831 lhs
= stabilize_reference (lhs
);
5832 if (TREE_SIDE_EFFECTS (newrhs
))
5833 newrhs
= stabilize_reference (newrhs
);
5836 /* This is now done by generating X(X&) and operator=(X&). */
5837 /* C++: The semantics of C++ differ from those of C when an
5838 assignment of an aggregate is desired. Assignment in C++ is
5839 now defined as memberwise assignment of non-static members
5840 and base class objects. This rule applies recursively
5841 until a member of a built-in type is found.
5843 Also, we cannot do a bit-wise copy of aggregates which
5844 contain virtual function table pointers. Those
5845 pointer values must be preserved through the copy.
5846 However, this is handled in expand_expr, and not here.
5847 This is because much better code can be generated at
5848 that stage than this one. */
5849 if (TREE_CODE (lhstype
) == RECORD_TYPE
5850 && ! TYPE_PTRMEMFUNC_P (lhstype
)
5851 && (TYPE_MAIN_VARIANT (lhstype
) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs
))
5852 || (TREE_CODE (TREE_TYPE (newrhs
)) == RECORD_TYPE
5853 && UNIQUELY_DERIVED_FROM_P (lhstype
, TREE_TYPE (newrhs
)))))
5855 tree vbases
= CLASSTYPE_VBASECLASSES (lhstype
);
5856 tree lhs_addr
= build_unary_op (ADDR_EXPR
, lhs
, 0);
5859 /* Memberwise assignment would cause NEWRHS to be
5860 evaluated for every member that gets assigned.
5861 By wrapping side-effecting exprs in a SAVE_EXPR,
5862 NEWRHS will only be evaluated once. */
5863 if (IS_AGGR_TYPE (TREE_TYPE (newrhs
))
5864 && TREE_SIDE_EFFECTS (newrhs
)
5865 /* This are things we don't have to save. */
5866 && TREE_CODE (newrhs
) != COND_EXPR
5867 && TREE_CODE (newrhs
) != TARGET_EXPR
5868 && TREE_CODE (newrhs
) != WITH_CLEANUP_EXPR
)
5869 /* Call `break_out_cleanups' on NEWRHS in case there are cleanups.
5870 If NEWRHS is a CALL_EXPR that needs a cleanup, failure to do so
5871 will result in expand_expr expanding the call without knowing
5872 that it should run the cleanup. */
5873 newrhs
= save_expr (break_out_cleanups (newrhs
));
5875 if (TREE_CODE (newrhs
) == COND_EXPR
)
5876 rhs_addr
= rationalize_conditional_expr (ADDR_EXPR
, newrhs
);
5878 rhs_addr
= build_unary_op (ADDR_EXPR
, newrhs
, 0);
5880 result
= tree_cons (NULL_TREE
,
5881 convert (build_reference_type (lhstype
), lhs
),
5884 if (! comptypes (TREE_TYPE (lhs_addr
), TREE_TYPE (rhs_addr
), 1))
5885 rhs_addr
= convert_pointer_to (TREE_TYPE (TREE_TYPE (lhs_addr
)), rhs_addr
);
5887 tree noncopied_parts
= NULL_TREE
;
5889 if (TYPE_NONCOPIED_PARTS (lhstype
) != 0)
5890 noncopied_parts
= init_noncopied_parts (lhs
,
5891 TYPE_NONCOPIED_PARTS (lhstype
));
5892 while (noncopied_parts
!= 0)
5894 result
= tree_cons (NULL_TREE
,
5895 build_modify_expr (convert (ptr_type_node
, TREE_VALUE (noncopied_parts
)),
5897 TREE_PURPOSE (noncopied_parts
)),
5899 noncopied_parts
= TREE_CHAIN (noncopied_parts
);
5902 /* Once we have our hands on an address, we must change NEWRHS
5903 to work from there. Otherwise we can get multiple evaluations
5905 if (TREE_CODE (newrhs
) != SAVE_EXPR
)
5906 newrhs
= build_indirect_ref (rhs_addr
, NULL_PTR
);
5910 tree elt_lhs
= convert_pointer_to (vbases
, lhs_addr
);
5911 tree elt_rhs
= convert_pointer_to (vbases
, rhs_addr
);
5913 = tree_cons (NULL_TREE
,
5914 build_modify_expr_1 (build_indirect_ref (elt_lhs
, NULL_PTR
),
5916 build_indirect_ref (elt_rhs
, NULL_PTR
),
5917 TYPE_BINFO (lhstype
)),
5919 if (TREE_VALUE (result
) == error_mark_node
)
5920 return error_mark_node
;
5921 vbases
= TREE_CHAIN (vbases
);
5923 result
= tree_cons (NULL_TREE
,
5924 build_modify_expr_1 (lhs
,
5927 TYPE_BINFO (lhstype
)),
5929 return build_compound_expr (result
);
5933 /* Convert new value to destination type. */
5935 if (TREE_CODE (lhstype
) == ARRAY_TYPE
)
5939 /* Allow array assignment in compiler-generated code. */
5940 if (pedantic
&& ! DECL_ARTIFICIAL (current_function_decl
))
5941 pedwarn ("ANSI C++ forbids assignment of arrays");
5943 /* Have to wrap this in RTL_EXPR for two cases:
5944 in base or member initialization and if we
5945 are a branch of a ?: operator. Since we
5946 can't easily know the latter, just do it always. */
5948 result
= make_node (RTL_EXPR
);
5950 TREE_TYPE (result
) = void_type_node
;
5951 do_pending_stack_adjust ();
5952 start_sequence_for_rtl_expr (result
);
5954 /* As a matter of principle, `start_sequence' should do this. */
5957 from_array
= TREE_CODE (TREE_TYPE (newrhs
)) == ARRAY_TYPE
5958 ? 1 + (modifycode
!= INIT_EXPR
): 0;
5959 expand_vec_init (lhs
, lhs
, array_type_nelts (lhstype
), newrhs
,
5962 do_pending_stack_adjust ();
5964 TREE_SIDE_EFFECTS (result
) = 1;
5965 RTL_EXPR_SEQUENCE (result
) = get_insns ();
5966 RTL_EXPR_RTL (result
) = const0_rtx
;
5971 if (modifycode
== INIT_EXPR
)
5973 newrhs
= convert_for_initialization (lhs
, lhstype
, newrhs
, LOOKUP_NORMAL
,
5974 "assignment", NULL_TREE
, 0);
5975 if (lhs
== DECL_RESULT (current_function_decl
))
5977 if (DECL_INITIAL (lhs
))
5978 warning ("return value from function receives multiple initializations");
5979 DECL_INITIAL (lhs
) = newrhs
;
5985 if (IS_AGGR_TYPE (lhstype
))
5987 if (result
= build_opfncall (MODIFY_EXPR
,
5988 LOOKUP_NORMAL
, lhs
, newrhs
,
5989 make_node (NOP_EXPR
)))
5993 /* Avoid warnings on enum bit fields. */
5994 if (TREE_CODE (olhstype
) == ENUMERAL_TYPE
5995 && TREE_CODE (lhstype
) == INTEGER_TYPE
)
5997 newrhs
= convert_for_assignment (olhstype
, newrhs
, "assignment",
5999 newrhs
= convert_force (lhstype
, newrhs
, 0);
6002 newrhs
= convert_for_assignment (lhstype
, newrhs
, "assignment",
6004 if (TREE_CODE (newrhs
) == CALL_EXPR
6005 && TYPE_NEEDS_CONSTRUCTING (lhstype
))
6006 newrhs
= build_cplus_new (lhstype
, newrhs
, 0);
6008 if (TREE_CODE (newrhs
) == TARGET_EXPR
)
6010 /* Can't initialize directly from a TARGET_EXPR, since that would
6011 cause the lhs to be constructed twice. So we force the
6012 TARGET_EXPR to be expanded. expand_expr should really do this
6015 tree xval
= make_node (RTL_EXPR
);
6018 do_pending_stack_adjust ();
6019 start_sequence_for_rtl_expr (xval
);
6021 rtxval
= expand_expr (newrhs
, NULL
, VOIDmode
, 0);
6022 do_pending_stack_adjust ();
6023 TREE_SIDE_EFFECTS (xval
) = 1;
6024 RTL_EXPR_SEQUENCE (xval
) = get_insns ();
6026 RTL_EXPR_RTL (xval
) = rtxval
;
6027 TREE_TYPE (xval
) = lhstype
;
6032 if (TREE_CODE (newrhs
) == ERROR_MARK
)
6033 return error_mark_node
;
6035 if (TREE_CODE (newrhs
) == COND_EXPR
)
6038 tree cond
= TREE_OPERAND (newrhs
, 0);
6040 if (TREE_SIDE_EFFECTS (lhs
))
6041 cond
= build_compound_expr (tree_cons
6043 build_tree_list (NULL_TREE
, cond
)));
6045 /* Cannot have two identical lhs on this one tree (result) as preexpand
6046 calls will rip them out and fill in RTL for them, but when the
6047 rtl is generated, the calls will only be in the first side of the
6048 condition, not on both, or before the conditional jump! (mrs) */
6049 lhs1
= break_out_calls (lhs
);
6052 /* If there's no change, the COND_EXPR behaves like any other rhs. */
6053 result
= build (modifycode
== NOP_EXPR
? MODIFY_EXPR
: INIT_EXPR
,
6054 lhstype
, lhs
, newrhs
);
6057 tree result_type
= TREE_TYPE (newrhs
);
6058 /* We have to convert each arm to the proper type because the
6059 types may have been munged by constant folding. */
6061 = build (COND_EXPR
, result_type
, cond
,
6062 build_modify_expr (lhs
, modifycode
,
6063 convert (result_type
,
6064 TREE_OPERAND (newrhs
, 1))),
6065 build_modify_expr (lhs1
, modifycode
,
6066 convert (result_type
,
6067 TREE_OPERAND (newrhs
, 2))));
6070 else if (modifycode
!= INIT_EXPR
&& TREE_CODE (newrhs
) == WITH_CLEANUP_EXPR
)
6072 tree cleanup
= TREE_OPERAND (newrhs
, 2);
6075 /* Finish up by running cleanups and having the "value" of the lhs. */
6076 tree exprlist
= tree_cons (NULL_TREE
, cleanup
,
6077 build_tree_list (NULL_TREE
, lhs
));
6078 newrhs
= TREE_OPERAND (newrhs
, 0);
6079 if (TREE_CODE (newrhs
) == TARGET_EXPR
)
6080 slot
= TREE_OPERAND (newrhs
, 0);
6081 else if (TREE_CODE (newrhs
) == ADDR_EXPR
)
6083 /* Bad but valid. */
6085 warning ("address taken of temporary object");
6088 my_friendly_abort (118);
6090 /* Copy the value computed in SLOT into LHS. */
6091 exprlist
= tree_cons (NULL_TREE
,
6092 build_modify_expr (lhs
, modifycode
, slot
),
6094 /* Evaluate the expression that needs CLEANUP. This will
6095 compute the value into SLOT. */
6096 exprlist
= tree_cons (NULL_TREE
, newrhs
, exprlist
);
6097 result
= convert (lhstype
, build_compound_expr (exprlist
));
6100 result
= build (modifycode
== NOP_EXPR
? MODIFY_EXPR
: INIT_EXPR
,
6101 lhstype
, lhs
, newrhs
);
6102 TREE_SIDE_EFFECTS (result
) = 1;
6104 /* If we got the LHS in a different type for storing in,
6105 convert the result back to the nominal type of LHS
6106 so that the value we return always has the same type
6107 as the LHS argument. */
6109 if (olhstype
== TREE_TYPE (result
))
6111 /* Avoid warnings converting integral types back into enums
6112 for enum bit fields. */
6113 if (TREE_CODE (TREE_TYPE (result
)) == INTEGER_TYPE
6114 && TREE_CODE (olhstype
) == ENUMERAL_TYPE
)
6116 result
= build (COMPOUND_EXPR
, olhstype
, result
, olhs
);
6117 TREE_NO_UNUSED_WARNING (result
) = 1;
6120 return convert_for_assignment (olhstype
, result
, "assignment",
6125 /* Return 0 if EXP is not a valid lvalue in this language
6126 even though `lvalue_or_else' would accept it. */
6129 language_lvalue_valid (exp
)
6135 /* Get differnce in deltas for different pointer to member function
6136 types. Return inetger_zero_node, if FROM cannot be converted to a
6137 TO type. If FORCE is true, then allow reverse conversions as well. */
6139 get_delta_difference (from
, to
, force
)
6143 tree delta
= integer_zero_node
;
6149 /* Should get_base_distance here, so we can check if any thing along the
6150 path is virtual, and we need to make sure we stay
6151 inside the real binfos when going through virtual bases.
6152 Maybe we should replace virtual bases with
6153 binfo_member (...CLASSTYPE_VBASECLASSES...)... (mrs) */
6154 binfo
= get_binfo (from
, to
, 1);
6155 if (binfo
== error_mark_node
)
6157 error (" in pointer to member function conversion");
6164 error_not_base_type (from
, to
);
6165 error (" in pointer to member function conversion");
6168 binfo
= get_binfo (to
, from
, 1);
6169 if (binfo
== error_mark_node
)
6171 error (" in pointer to member function conversion");
6176 error ("cannot convert pointer to member of type %T to unrelated pointer to member of type %T", from
, to
);
6179 if (TREE_VIA_VIRTUAL (binfo
))
6181 warning ("pointer to member conversion to virtual base class will only work if you are very careful");
6183 return build_binary_op (MINUS_EXPR
,
6185 BINFO_OFFSET (binfo
), 1);
6187 if (TREE_VIA_VIRTUAL (binfo
))
6189 warning ("pointer to member conversion from virtual base class will only work if you are very careful");
6191 return BINFO_OFFSET (binfo
);
6194 /* Build a constructor for a pointer to member function. It can be
6195 used to initialize global variables, local variable, or used
6196 as a value in expressions. TYPE is the POINTER to METHOD_TYPE we
6199 If FORCE is non-zero, then force this conversion, even if
6200 we would rather not do it. Usually set when using an explicit
6203 Return error_mark_node, if something goes wrong. */
6206 build_ptrmemfunc (type
, pfn
, force
)
6210 tree index
= integer_zero_node
;
6211 tree delta
= integer_zero_node
;
6212 tree delta2
= integer_zero_node
;
6217 /* Handle multiple conversions of pointer to member fucntions. */
6218 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (pfn
)))
6220 tree ndelta
, ndelta2
, nindex
;
6221 /* Is is already the right type? */
6223 /* Sorry, can't do this, the backend is too stupid. */
6224 if (TYPE_METHOD_BASETYPE (TREE_TYPE (type
))
6225 == TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn
)))))
6227 if (type
!= TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn
)))
6229 npfn
= build1 (NOP_EXPR
, TYPE_GET_PTRMEMFUNC_TYPE (type
), pfn
);
6230 TREE_CONSTANT (npfn
) = TREE_CONSTANT (pfn
);
6235 if (type
== TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn
)))
6239 if (TREE_CODE (pfn
) != CONSTRUCTOR
)
6242 ndelta
= convert (ptrdiff_type_node
, build_component_ref (pfn
, delta_identifier
, 0, 0));
6243 ndelta2
= convert (ptrdiff_type_node
, DELTA2_FROM_PTRMEMFUNC (pfn
));
6244 index
= build_component_ref (pfn
, index_identifier
, 0, 0);
6245 delta
= get_delta_difference (TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn
)))),
6246 TYPE_METHOD_BASETYPE (TREE_TYPE (type
)),
6248 delta
= build_binary_op (PLUS_EXPR
, delta
, ndelta
, 1);
6249 delta2
= build_binary_op (PLUS_EXPR
, ndelta2
, delta2
, 1);
6250 e1
= fold (build (GT_EXPR
, boolean_type_node
, index
, integer_zero_node
));
6252 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (delta2_identifier
, delta2
, NULL_TREE
));
6253 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (NULL_TREE
, delta
,
6254 tree_cons (NULL_TREE
, index
,
6255 tree_cons (NULL_TREE
, u
, NULL_TREE
))));
6256 e2
= digest_init (TYPE_GET_PTRMEMFUNC_TYPE (type
), u
, (tree
*)0);
6258 pfn
= PFN_FROM_PTRMEMFUNC (pfn
);
6259 npfn
= build1 (NOP_EXPR
, type
, pfn
);
6260 TREE_CONSTANT (npfn
) = TREE_CONSTANT (pfn
);
6262 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (pfn_identifier
, npfn
, NULL_TREE
));
6263 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (NULL_TREE
, delta
,
6264 tree_cons (NULL_TREE
, index
,
6265 tree_cons (NULL_TREE
, u
, NULL_TREE
))));
6266 e3
= digest_init (TYPE_GET_PTRMEMFUNC_TYPE (type
), u
, (tree
*)0);
6267 return build_conditional_expr (e1
, e2
, e3
);
6270 ndelta
= TREE_VALUE (CONSTRUCTOR_ELTS (pfn
));
6271 nindex
= TREE_VALUE (TREE_CHAIN (CONSTRUCTOR_ELTS (pfn
)));
6272 npfn
= TREE_VALUE (TREE_CHAIN (TREE_CHAIN (CONSTRUCTOR_ELTS (pfn
))));
6273 npfn
= TREE_VALUE (CONSTRUCTOR_ELTS (npfn
));
6274 if (integer_zerop (nindex
))
6275 pfn
= integer_zero_node
;
6278 sorry ("value casting of varible nonnull pointer to member functions not supported");
6279 return error_mark_node
;
6283 /* Handle null pointer to member function conversions. */
6284 if (integer_zerop (pfn
))
6286 pfn
= build_c_cast (type
, integer_zero_node
, 0);
6287 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (pfn_identifier
, pfn
, NULL_TREE
));
6288 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (NULL_TREE
, integer_zero_node
,
6289 tree_cons (NULL_TREE
, integer_zero_node
,
6290 tree_cons (NULL_TREE
, u
, NULL_TREE
))));
6291 return digest_init (TYPE_GET_PTRMEMFUNC_TYPE (type
), u
, (tree
*)0);
6294 if (TREE_CODE (pfn
) == TREE_LIST
6295 || (TREE_CODE (pfn
) == ADDR_EXPR
6296 && TREE_CODE (TREE_OPERAND (pfn
, 0)) == TREE_LIST
))
6298 pfn
= instantiate_type (type
, pfn
, 1);
6299 if (pfn
== error_mark_node
)
6300 return error_mark_node
;
6301 if (TREE_CODE (pfn
) != ADDR_EXPR
)
6302 pfn
= build_unary_op (ADDR_EXPR
, pfn
, 0);
6305 /* Allow pointer to member conversions here. */
6306 delta
= get_delta_difference (TYPE_METHOD_BASETYPE (TREE_TYPE (TREE_TYPE (pfn
))),
6307 TYPE_METHOD_BASETYPE (TREE_TYPE (type
)),
6309 delta2
= build_binary_op (PLUS_EXPR
, delta2
, delta
, 1);
6311 if (TREE_CODE (TREE_OPERAND (pfn
, 0)) != FUNCTION_DECL
)
6312 warning ("assuming pointer to member function is non-virtual");
6314 if (TREE_CODE (TREE_OPERAND (pfn
, 0)) == FUNCTION_DECL
6315 && DECL_VINDEX (TREE_OPERAND (pfn
, 0)))
6317 /* Find the offset to the vfield pointer in the object. */
6318 vfield_offset
= get_binfo (DECL_CONTEXT (TREE_OPERAND (pfn
, 0)),
6319 DECL_CLASS_CONTEXT (TREE_OPERAND (pfn
, 0)),
6321 vfield_offset
= get_vfield_offset (vfield_offset
);
6322 delta2
= size_binop (PLUS_EXPR
, vfield_offset
, delta2
);
6324 /* Map everything down one to make room for the null pointer to member. */
6325 index
= size_binop (PLUS_EXPR
,
6326 DECL_VINDEX (TREE_OPERAND (pfn
, 0)),
6328 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (delta2_identifier
, delta2
, NULL_TREE
));
6332 index
= size_binop (MINUS_EXPR
, integer_zero_node
, integer_one_node
);
6334 npfn
= build1 (NOP_EXPR
, type
, pfn
);
6335 TREE_CONSTANT (npfn
) = TREE_CONSTANT (pfn
);
6337 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (pfn_identifier
, npfn
, NULL_TREE
));
6340 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (NULL_TREE
, delta
,
6341 tree_cons (NULL_TREE
, index
,
6342 tree_cons (NULL_TREE
, u
, NULL_TREE
))));
6343 return digest_init (TYPE_GET_PTRMEMFUNC_TYPE (type
), u
, (tree
*)0);
6346 /* Convert value RHS to type TYPE as preparation for an assignment
6347 to an lvalue of type TYPE.
6348 The real work of conversion is done by `convert'.
6349 The purpose of this function is to generate error messages
6350 for assignments that are not allowed in C.
6351 ERRTYPE is a string to use in error messages:
6352 "assignment", "return", etc.
6354 C++: attempts to allow `convert' to find conversions involving
6355 implicit type conversion between aggregate and scalar types
6356 as per 8.5.6 of C++ manual. Does not randomly dereference
6357 pointers to aggregates! */
6360 convert_for_assignment (type
, rhs
, errtype
, fndecl
, parmnum
)
6366 register enum tree_code codel
= TREE_CODE (type
);
6367 register tree rhstype
;
6368 register enum tree_code coder
= TREE_CODE (TREE_TYPE (rhs
));
6370 if (coder
== UNKNOWN_TYPE
)
6371 rhs
= instantiate_type (type
, rhs
, 1);
6373 if (coder
== ERROR_MARK
)
6374 return error_mark_node
;
6376 if (codel
== OFFSET_TYPE
)
6378 type
= TREE_TYPE (type
);
6379 codel
= TREE_CODE (type
);
6382 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
6383 if (TREE_CODE (rhs
) == NON_LVALUE_EXPR
)
6384 rhs
= TREE_OPERAND (rhs
, 0);
6386 if (rhs
== error_mark_node
)
6387 return error_mark_node
;
6389 if (TREE_VALUE (rhs
) == error_mark_node
)
6390 return error_mark_node
;
6392 if (TREE_CODE (TREE_TYPE (rhs
)) == OFFSET_TYPE
)
6394 rhs
= resolve_offset_ref (rhs
);
6395 if (rhs
== error_mark_node
)
6396 return error_mark_node
;
6397 rhstype
= TREE_TYPE (rhs
);
6398 coder
= TREE_CODE (rhstype
);
6401 if (TREE_CODE (TREE_TYPE (rhs
)) == ARRAY_TYPE
6402 || TREE_CODE (TREE_TYPE (rhs
)) == FUNCTION_TYPE
6403 || TREE_CODE (TREE_TYPE (rhs
)) == METHOD_TYPE
)
6404 rhs
= default_conversion (rhs
);
6405 else if (TREE_CODE (TREE_TYPE (rhs
)) == REFERENCE_TYPE
)
6406 rhs
= convert_from_reference (rhs
);
6408 rhstype
= TREE_TYPE (rhs
);
6409 coder
= TREE_CODE (rhstype
);
6411 /* This should no longer change types on us. */
6412 if (TREE_CODE (rhs
) == CONST_DECL
)
6413 rhs
= DECL_INITIAL (rhs
);
6414 else if (TREE_READONLY_DECL_P (rhs
))
6415 rhs
= decl_constant_value (rhs
);
6417 if (type
== rhstype
)
6419 overflow_warning (rhs
);
6423 if (coder
== VOID_TYPE
)
6425 error ("void value not ignored as it ought to be");
6426 return error_mark_node
;
6428 /* Arithmetic types all interconvert. */
6429 if ((codel
== INTEGER_TYPE
|| codel
== REAL_TYPE
|| codel
== BOOLEAN_TYPE
)
6430 && (coder
== INTEGER_TYPE
|| coder
== REAL_TYPE
|| coder
== BOOLEAN_TYPE
))
6432 /* But we should warn if assigning REAL_TYPE to INTEGER_TYPE. */
6433 if (coder
== REAL_TYPE
&& codel
== INTEGER_TYPE
)
6436 cp_warning ("`%T' used for argument %P of `%D'",
6437 rhstype
, parmnum
, fndecl
);
6439 cp_warning ("%s to `%T' from `%T'", errtype
, type
, rhstype
);
6441 /* And we should warn if assigning a negative value to
6442 an unsigned variable. */
6443 else if (TREE_UNSIGNED (type
) && codel
!= BOOLEAN_TYPE
)
6445 if (TREE_CODE (rhs
) == INTEGER_CST
6446 && TREE_NEGATED_INT (rhs
))
6449 cp_warning ("negative value `%E' passed as argument %P of `%D'",
6450 rhs
, parmnum
, fndecl
);
6452 cp_warning ("%s of negative value `%E' to `%T'",
6453 errtype
, rhs
, type
);
6455 overflow_warning (rhs
);
6456 if (TREE_CONSTANT (rhs
))
6460 return convert_and_check (type
, rhs
);
6462 /* Conversions involving enums. */
6463 else if ((codel
== ENUMERAL_TYPE
6464 && (INTEGRAL_CODE_P (coder
) || coder
== REAL_TYPE
))
6465 || (coder
== ENUMERAL_TYPE
6466 && (INTEGRAL_CODE_P (codel
) || codel
== REAL_TYPE
)))
6468 return cp_convert (type
, rhs
, CONV_IMPLICIT
, 0);
6470 /* Conversions among pointers */
6471 else if (codel
== POINTER_TYPE
6472 && (coder
== POINTER_TYPE
6473 || (coder
== RECORD_TYPE
6474 && (IS_SIGNATURE_POINTER (rhstype
)
6475 || IS_SIGNATURE_REFERENCE (rhstype
)))))
6477 register tree ttl
= TREE_TYPE (type
);
6481 if (coder
== RECORD_TYPE
)
6483 rhs
= build_optr_ref (rhs
);
6484 rhstype
= TREE_TYPE (rhs
);
6486 ttr
= TREE_TYPE (rhstype
);
6488 /* If both pointers are of aggregate type, then we
6489 can give better error messages, and save some work
6491 if (TREE_CODE (ttl
) == RECORD_TYPE
&& TREE_CODE (ttr
) == RECORD_TYPE
)
6495 if (TYPE_MAIN_VARIANT (ttl
) == TYPE_MAIN_VARIANT (ttr
)
6496 || type
== class_star_type_node
6497 || rhstype
== class_star_type_node
)
6498 binfo
= TYPE_BINFO (ttl
);
6500 binfo
= get_binfo (ttl
, ttr
, 1);
6502 if (binfo
== error_mark_node
)
6503 return error_mark_node
;
6505 return error_not_base_type (ttl
, ttr
);
6507 if (! TYPE_READONLY (ttl
) && TYPE_READONLY (ttr
))
6510 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6511 rhstype
, parmnum
, fndecl
);
6513 cp_pedwarn ("%s to `%T' from `%T' discards const",
6514 errtype
, type
, rhstype
);
6516 if (! TYPE_VOLATILE (ttl
) && TYPE_VOLATILE (ttr
))
6519 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6520 rhstype
, parmnum
, fndecl
);
6522 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6523 errtype
, type
, rhstype
);
6527 /* Any non-function converts to a [const][volatile] void *
6528 and vice versa; otherwise, targets must be the same.
6529 Meanwhile, the lhs target must have all the qualifiers of the rhs. */
6530 else if (TYPE_MAIN_VARIANT (ttl
) == void_type_node
6531 || TYPE_MAIN_VARIANT (ttr
) == void_type_node
6532 || (ctt
= comp_target_types (type
, rhstype
, 1))
6533 || (unsigned_type (TYPE_MAIN_VARIANT (ttl
))
6534 == unsigned_type (TYPE_MAIN_VARIANT (ttr
))))
6536 /* ARM $4.8, commentary on p39. */
6537 if (TYPE_MAIN_VARIANT (ttl
) == void_type_node
6538 && TREE_CODE (ttr
) == OFFSET_TYPE
)
6540 cp_error ("no standard conversion from `%T' to `void *'", ttr
);
6541 return error_mark_node
;
6545 cp_pedwarn ("converting `%T' to `%T' is a contravariance violation",
6548 if (TYPE_MAIN_VARIANT (ttl
) != void_type_node
6549 && TYPE_MAIN_VARIANT (ttr
) == void_type_node
6550 && rhs
!= null_pointer_node
)
6552 if (coder
== RECORD_TYPE
)
6553 cp_pedwarn ("implicit conversion of signature pointer to type `%T'",
6556 pedwarn ("ANSI C++ forbids implicit conversion from `void *' in %s",
6559 /* Const and volatile mean something different for function types,
6560 so the usual warnings are not appropriate. */
6561 else if ((TREE_CODE (ttr
) != FUNCTION_TYPE
&& TREE_CODE (ttr
) != METHOD_TYPE
)
6562 || (TREE_CODE (ttl
) != FUNCTION_TYPE
&& TREE_CODE (ttl
) != METHOD_TYPE
))
6564 if (TREE_CODE (ttl
) == OFFSET_TYPE
6565 && binfo_member (TYPE_OFFSET_BASETYPE (ttr
),
6566 CLASSTYPE_VBASECLASSES (TYPE_OFFSET_BASETYPE (ttl
))))
6568 sorry ("%s between pointer to members converting across virtual baseclasses", errtype
);
6569 return error_mark_node
;
6571 else if (! TYPE_READONLY (ttl
) && TYPE_READONLY (ttr
))
6574 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6575 rhstype
, parmnum
, fndecl
);
6577 cp_pedwarn ("%s to `%T' from `%T' discards const",
6578 errtype
, type
, rhstype
);
6580 else if (! TYPE_VOLATILE (ttl
) && TYPE_VOLATILE (ttr
))
6583 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6584 rhstype
, parmnum
, fndecl
);
6586 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6587 errtype
, type
, rhstype
);
6589 else if (TREE_CODE (ttl
) == TREE_CODE (ttr
)
6590 && ! comp_target_types (type
, rhstype
, 1))
6593 cp_pedwarn ("passing `%T' as argument %P of `%D' changes signedness",
6594 rhstype
, parmnum
, fndecl
);
6596 cp_pedwarn ("%s to `%T' from `%T' changes signedness",
6597 errtype
, type
, rhstype
);
6601 else if (TREE_CODE (ttr
) == OFFSET_TYPE
6602 && TREE_CODE (ttl
) != OFFSET_TYPE
)
6604 /* Normally, pointers to different type codes (other
6605 than void) are not compatible, but we perform
6606 some type instantiation if that resolves the
6607 ambiguity of (X Y::*) and (X *). */
6609 if (current_class_decl
)
6611 if (TREE_CODE (rhs
) == INTEGER_CST
)
6613 rhs
= build (PLUS_EXPR
, build_pointer_type (TREE_TYPE (ttr
)),
6614 current_class_decl
, rhs
);
6615 return convert_for_assignment (type
, rhs
,
6616 errtype
, fndecl
, parmnum
);
6619 if (TREE_CODE (ttl
) == METHOD_TYPE
)
6620 error ("%s between pointer-to-method and pointer-to-member types",
6623 error ("%s between pointer and pointer-to-member types", errtype
);
6624 return error_mark_node
;
6628 int add_quals
= 0, const_parity
= 0, volatile_parity
= 0;
6630 int unsigned_parity
;
6633 /* This code is basically a duplicate of comp_ptr_ttypes_real. */
6634 for (; ; ttl
= TREE_TYPE (ttl
), ttr
= TREE_TYPE (ttr
))
6637 const_parity
|= TYPE_READONLY (ttl
) < TYPE_READONLY (ttr
);
6638 volatile_parity
|= TYPE_VOLATILE (ttl
) < TYPE_VOLATILE (ttr
);
6641 && (TYPE_READONLY (ttl
) > TYPE_READONLY (ttr
)
6642 || TYPE_VOLATILE (ttl
) > TYPE_VOLATILE (ttr
)))
6644 left_const
&= TYPE_READONLY (ttl
);
6646 if (TREE_CODE (ttl
) != POINTER_TYPE
6647 || TREE_CODE (ttr
) != POINTER_TYPE
)
6650 unsigned_parity
= TREE_UNSIGNED (ttl
) - TREE_UNSIGNED (ttr
);
6651 if (unsigned_parity
)
6653 if (TREE_UNSIGNED (ttl
))
6654 ttr
= unsigned_type (ttr
);
6656 ttl
= unsigned_type (ttl
);
6659 if (comp_target_types (ttl
, ttr
, nptrs
) > 0)
6664 cp_pedwarn ("passing `%T' as argument %P of `%D' adds cv-quals without intervening `const'",
6665 rhstype
, parmnum
, fndecl
);
6667 cp_pedwarn ("%s to `%T' from `%T' adds cv-quals without intervening `const'",
6668 errtype
, type
, rhstype
);
6673 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6674 rhstype
, parmnum
, fndecl
);
6676 cp_pedwarn ("%s to `%T' from `%T' discards const",
6677 errtype
, type
, rhstype
);
6679 if (volatile_parity
)
6682 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6683 rhstype
, parmnum
, fndecl
);
6685 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6686 errtype
, type
, rhstype
);
6688 if (unsigned_parity
> 0)
6691 cp_pedwarn ("passing `%T' as argument %P of `%D' changes signed to unsigned",
6692 rhstype
, parmnum
, fndecl
);
6694 cp_pedwarn ("%s to `%T' from `%T' changes signed to unsigned",
6695 errtype
, type
, rhstype
);
6697 else if (unsigned_parity
< 0)
6700 cp_pedwarn ("passing `%T' as argument %P of `%D' changes unsigned to signed",
6701 rhstype
, parmnum
, fndecl
);
6703 cp_pedwarn ("%s to `%T' from `%T' changes unsigned to signed",
6704 errtype
, type
, rhstype
);
6707 /* C++ is not so friendly about converting function and
6708 member function pointers as C. Emit warnings here. */
6709 if (TREE_CODE (ttl
) == FUNCTION_TYPE
6710 || TREE_CODE (ttl
) == METHOD_TYPE
)
6711 if (! comptypes (ttl
, ttr
, 0))
6713 warning ("conflicting function types in %s:", errtype
);
6714 cp_warning ("\t`%T' != `%T'", type
, rhstype
);
6717 else if (TREE_CODE (TREE_TYPE (rhs
)) == METHOD_TYPE
)
6719 /* When does this happen? */
6720 my_friendly_abort (119);
6721 /* Conversion of a pointer-to-member type to void *. */
6722 rhs
= build_unary_op (ADDR_EXPR
, rhs
, 0);
6723 TREE_TYPE (rhs
) = type
;
6726 else if (TREE_CODE (TREE_TYPE (rhs
)) == OFFSET_TYPE
)
6728 /* When does this happen? */
6729 my_friendly_abort (120);
6730 /* Conversion of a pointer-to-member type to void *. */
6731 rhs
= build_unary_op (ADDR_EXPR
, rhs
, 0);
6732 TREE_TYPE (rhs
) = type
;
6738 cp_error ("passing `%T' as argument %P of `%D'",
6739 rhstype
, parmnum
, fndecl
);
6741 cp_error ("%s to `%T' from `%T'", errtype
, type
, rhstype
);
6742 return error_mark_node
;
6745 return convert (type
, rhs
);
6747 else if (codel
== POINTER_TYPE
&& coder
== INTEGER_TYPE
)
6749 /* An explicit constant 0 can convert to a pointer,
6750 but not a 0 that results from casting or folding. */
6751 if (! (TREE_CODE (rhs
) == INTEGER_CST
&& integer_zerop (rhs
)))
6754 cp_pedwarn ("passing `%T' to argument %P of `%D' lacks a cast",
6755 rhstype
, parmnum
, fndecl
);
6757 cp_pedwarn ("%s to `%T' from `%T' lacks a cast",
6758 errtype
, type
, rhstype
);
6759 return convert (type
, rhs
);
6761 return null_pointer_node
;
6763 else if (codel
== INTEGER_TYPE
6764 && (coder
== POINTER_TYPE
6765 || (coder
== RECORD_TYPE
6766 && (IS_SIGNATURE_POINTER (rhstype
)
6767 || TYPE_PTRMEMFUNC_FLAG (rhstype
)
6768 || IS_SIGNATURE_REFERENCE (rhstype
)))))
6771 cp_pedwarn ("passing `%T' to argument %P of `%D' lacks a cast",
6772 rhstype
, parmnum
, fndecl
);
6774 cp_pedwarn ("%s to `%T' from `%T' lacks a cast",
6775 errtype
, type
, rhstype
);
6776 return convert (type
, rhs
);
6778 else if (codel
== BOOLEAN_TYPE
6779 && (coder
== POINTER_TYPE
6780 || (coder
== RECORD_TYPE
6781 && (IS_SIGNATURE_POINTER (rhstype
)
6782 || TYPE_PTRMEMFUNC_FLAG (rhstype
)
6783 || IS_SIGNATURE_REFERENCE (rhstype
)))))
6784 return convert (type
, rhs
);
6787 else if (((coder
== POINTER_TYPE
6788 && TREE_CODE (TREE_TYPE (rhstype
)) == METHOD_TYPE
)
6789 || integer_zerop (rhs
)
6790 || TYPE_PTRMEMFUNC_P (rhstype
))
6791 && TYPE_PTRMEMFUNC_P (type
))
6793 tree ttl
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
6794 tree ttr
= (TREE_CODE (rhstype
) == POINTER_TYPE
? rhstype
6795 : TYPE_PTRMEMFUNC_FN_TYPE (type
));
6796 int ctt
= comp_target_types (ttl
, ttr
, 1);
6799 cp_pedwarn ("converting `%T' to `%T' is a contravariance violation",
6802 cp_error ("%s to `%T' from `%T'", errtype
, ttl
, ttr
);
6804 /* compatible pointer to member functions. */
6805 return build_ptrmemfunc (ttl
, rhs
, 0);
6807 else if (codel
== ERROR_MARK
|| coder
== ERROR_MARK
)
6808 return error_mark_node
;
6810 /* This should no longer happen. References are initialized via
6811 `convert_for_initialization'. They should otherwise be
6812 bashed before coming here. */
6813 else if (codel
== REFERENCE_TYPE
)
6814 my_friendly_abort (317);
6815 else if (TYPE_MAIN_VARIANT (type
) == TYPE_MAIN_VARIANT (TREE_TYPE (rhs
)))
6817 tree nrhs
= build1 (NOP_EXPR
, type
, rhs
);
6818 TREE_CONSTANT (nrhs
) = TREE_CONSTANT (rhs
);
6821 else if (TYPE_HAS_CONSTRUCTOR (type
) || IS_AGGR_TYPE (TREE_TYPE (rhs
)))
6822 return convert (type
, rhs
);
6824 cp_error ("%s to `%T' from `%T'", errtype
, type
, rhstype
);
6825 return error_mark_node
;
6828 /* Convert RHS to be of type TYPE. If EXP is non-zero,
6829 it is the target of the initialization.
6830 ERRTYPE is a string to use in error messages.
6832 Two major differences between the behavior of
6833 `convert_for_assignment' and `convert_for_initialization'
6834 are that references are bashed in the former, while
6835 copied in the latter, and aggregates are assigned in
6836 the former (operator=) while initialized in the
6839 If using constructor make sure no conversion operator exists, if one does
6840 exist, an ambiguity exists. */
6842 convert_for_initialization (exp
, type
, rhs
, flags
, errtype
, fndecl
, parmnum
)
6843 tree exp
, type
, rhs
;
6849 register enum tree_code codel
= TREE_CODE (type
);
6850 register tree rhstype
;
6851 register enum tree_code coder
;
6853 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
6854 Strip such NOP_EXPRs, since RHS is used in non-lvalue context. */
6855 if (TREE_CODE (rhs
) == NOP_EXPR
6856 && TREE_TYPE (rhs
) == TREE_TYPE (TREE_OPERAND (rhs
, 0))
6857 && codel
!= REFERENCE_TYPE
)
6858 rhs
= TREE_OPERAND (rhs
, 0);
6860 if (rhs
== error_mark_node
6861 || (TREE_CODE (rhs
) == TREE_LIST
&& TREE_VALUE (rhs
) == error_mark_node
))
6862 return error_mark_node
;
6864 if (TREE_CODE (TREE_TYPE (rhs
)) == OFFSET_TYPE
)
6866 rhs
= resolve_offset_ref (rhs
);
6867 if (rhs
== error_mark_node
)
6868 return error_mark_node
;
6871 if (TREE_CODE (TREE_TYPE (rhs
)) == REFERENCE_TYPE
)
6872 rhs
= convert_from_reference (rhs
);
6874 if ((TREE_CODE (TREE_TYPE (rhs
)) == ARRAY_TYPE
6875 && TREE_CODE (type
) != ARRAY_TYPE
6876 && (TREE_CODE (type
) != REFERENCE_TYPE
6877 || TREE_CODE (TREE_TYPE (type
)) != ARRAY_TYPE
))
6878 || TREE_CODE (TREE_TYPE (rhs
)) == FUNCTION_TYPE
6879 || TREE_CODE (TREE_TYPE (rhs
)) == METHOD_TYPE
)
6880 rhs
= default_conversion (rhs
);
6882 rhstype
= TREE_TYPE (rhs
);
6883 coder
= TREE_CODE (rhstype
);
6885 if (coder
== UNKNOWN_TYPE
)
6887 rhs
= instantiate_type (type
, rhs
, 1);
6888 rhstype
= TREE_TYPE (rhs
);
6889 coder
= TREE_CODE (rhstype
);
6892 if (coder
== ERROR_MARK
)
6893 return error_mark_node
;
6896 /* This is *not* the quick way out! It is the way to disaster. */
6897 if (type
== rhstype
)
6901 /* We accept references to incomplete types, so we can
6902 return here before checking if RHS is of complete type. */
6904 if (codel
== REFERENCE_TYPE
)
6906 /* This should eventually happen in convert_arguments. */
6907 extern int warningcount
, errorcount
;
6911 savew
= warningcount
, savee
= errorcount
;
6912 rhs
= convert_to_reference (type
, rhs
, CONV_IMPLICIT
, flags
,
6913 exp
? exp
: error_mark_node
);
6916 if (warningcount
> savew
)
6917 cp_warning_at ("in passing argument %P of `%+D'", parmnum
, fndecl
);
6918 else if (errorcount
> savee
)
6919 cp_error_at ("in passing argument %P of `%+D'", parmnum
, fndecl
);
6924 rhs
= require_complete_type (rhs
);
6925 if (rhs
== error_mark_node
)
6926 return error_mark_node
;
6928 if (exp
!= 0) exp
= require_complete_type (exp
);
6929 if (exp
== error_mark_node
)
6930 return error_mark_node
;
6932 if (TREE_CODE (rhstype
) == REFERENCE_TYPE
)
6933 rhstype
= TREE_TYPE (rhstype
);
6935 if (TYPE_LANG_SPECIFIC (type
)
6936 && (IS_SIGNATURE_POINTER (type
) || IS_SIGNATURE_REFERENCE (type
)))
6937 return build_signature_pointer_constructor (type
, rhs
);
6939 if (IS_AGGR_TYPE (type
)
6940 && (TYPE_NEEDS_CONSTRUCTING (type
) || TREE_HAS_CONSTRUCTOR (rhs
)))
6942 if (TYPE_MAIN_VARIANT (type
) == TYPE_MAIN_VARIANT (rhstype
))
6944 /* This is sufficient to perform initialization. No need,
6945 apparently, to go through X(X&) to do first-cut
6946 initialization. Return through a TARGET_EXPR so that we get
6947 cleanups if it is used. */
6948 if (TREE_CODE (rhs
) == CALL_EXPR
)
6950 rhs
= build_cplus_new (type
, rhs
, 0);
6953 /* Handle the case of default parameter initialization and
6954 initialization of static variables. */
6955 else if (TREE_CODE (rhs
) == TARGET_EXPR
)
6957 else if (TREE_CODE (rhs
) == INDIRECT_REF
&& TREE_HAS_CONSTRUCTOR (rhs
))
6959 my_friendly_assert (TREE_CODE (TREE_OPERAND (rhs
, 0)) == CALL_EXPR
, 318);
6962 my_friendly_assert (TREE_VALUE (TREE_OPERAND (TREE_OPERAND (rhs
, 0), 1)) == NULL_TREE
, 316);
6963 TREE_VALUE (TREE_OPERAND (TREE_OPERAND (rhs
, 0), 1))
6964 = build_unary_op (ADDR_EXPR
, exp
, 0);
6967 rhs
= build_cplus_new (type
, TREE_OPERAND (rhs
, 0), 0);
6971 if (TYPE_MAIN_VARIANT (type
) == TYPE_MAIN_VARIANT (rhstype
)
6972 || (IS_AGGR_TYPE (rhstype
) && UNIQUELY_DERIVED_FROM_P (type
, rhstype
)))
6974 if (TYPE_HAS_INIT_REF (type
))
6976 tree init
= build_method_call (exp
, constructor_name_full (type
),
6977 build_tree_list (NULL_TREE
, rhs
),
6978 TYPE_BINFO (type
), LOOKUP_NORMAL
);
6980 if (init
== error_mark_node
)
6981 return error_mark_node
;
6985 exp
= build_cplus_new (type
, init
, 0);
6989 return build (COMPOUND_EXPR
, type
, init
, exp
);
6992 /* ??? The following warnings are turned off because
6993 this is another place where the default X(X&) constructor
6995 if (TYPE_HAS_ASSIGNMENT (type
))
6996 cp_warning ("bitwise copy: `%T' defines operator=", type
);
6998 if (TREE_CODE (TREE_TYPE (rhs
)) == REFERENCE_TYPE
)
6999 rhs
= convert_from_reference (rhs
);
7000 if (type
!= rhstype
)
7002 tree nrhs
= build1 (NOP_EXPR
, type
, rhs
);
7003 TREE_CONSTANT (nrhs
) = TREE_CONSTANT (rhs
);
7009 return convert (type
, rhs
);
7012 if (type
== TREE_TYPE (rhs
))
7014 if (TREE_READONLY_DECL_P (rhs
))
7015 rhs
= decl_constant_value (rhs
);
7019 return convert_for_assignment (type
, rhs
, errtype
, fndecl
, parmnum
);
7022 /* Expand an ASM statement with operands, handling output operands
7023 that are not variables or INDIRECT_REFS by transforming such
7024 cases into cases that expand_asm_operands can handle.
7026 Arguments are same as for expand_asm_operands.
7028 We don't do default conversions on all inputs, because it can screw
7029 up operands that are expected to be in memory. */
7032 c_expand_asm_operands (string
, outputs
, inputs
, clobbers
, vol
, filename
, line
)
7033 tree string
, outputs
, inputs
, clobbers
;
7038 int noutputs
= list_length (outputs
);
7040 /* o[I] is the place that output number I should be written. */
7041 register tree
*o
= (tree
*) alloca (noutputs
* sizeof (tree
));
7044 /* Record the contents of OUTPUTS before it is modified. */
7045 for (i
= 0, tail
= outputs
; tail
; tail
= TREE_CHAIN (tail
), i
++)
7046 o
[i
] = TREE_VALUE (tail
);
7048 /* Generate the ASM_OPERANDS insn;
7049 store into the TREE_VALUEs of OUTPUTS some trees for
7050 where the values were actually stored. */
7051 expand_asm_operands (string
, outputs
, inputs
, clobbers
, vol
, filename
, line
);
7053 /* Copy all the intermediate outputs into the specified outputs. */
7054 for (i
= 0, tail
= outputs
; tail
; tail
= TREE_CHAIN (tail
), i
++)
7056 if (o
[i
] != TREE_VALUE (tail
))
7058 expand_expr (build_modify_expr (o
[i
], NOP_EXPR
, TREE_VALUE (tail
)),
7059 const0_rtx
, VOIDmode
, 0);
7062 /* Detect modification of read-only values.
7063 (Otherwise done by build_modify_expr.) */
7066 tree type
= TREE_TYPE (o
[i
]);
7067 if (TYPE_READONLY (type
)
7068 || ((TREE_CODE (type
) == RECORD_TYPE
7069 || TREE_CODE (type
) == UNION_TYPE
)
7070 && C_TYPE_FIELDS_READONLY (type
)))
7071 readonly_error (o
[i
], "modification by `asm'", 1);
7075 /* Those MODIFY_EXPRs could do autoincrements. */
7079 /* Expand a C `return' statement.
7080 RETVAL is the expression for what to return,
7081 or a null pointer for `return;' with no value.
7083 C++: upon seeing a `return', we must call destructors on all
7084 variables in scope which had constructors called on them.
7085 This means that if in a destructor, the base class destructors
7086 must be called before returning.
7088 The RETURN statement in C++ has initialization semantics. */
7091 c_expand_return (retval
)
7094 extern struct nesting
*cond_stack
, *loop_stack
, *case_stack
;
7095 extern tree dtor_label
, ctor_label
;
7096 tree result
= DECL_RESULT (current_function_decl
);
7097 tree valtype
= TREE_TYPE (result
);
7098 register int use_temp
= 0;
7099 int returns_value
= 1;
7101 if (TREE_THIS_VOLATILE (current_function_decl
))
7102 warning ("function declared `noreturn' has a `return' statement");
7104 if (retval
== error_mark_node
)
7106 current_function_returns_null
= 1;
7110 if (retval
== NULL_TREE
)
7112 /* A non-named return value does not count. */
7114 /* Can't just return from a destructor. */
7117 expand_goto (dtor_label
);
7121 if (DECL_CONSTRUCTOR_P (current_function_decl
))
7122 retval
= current_class_decl
;
7123 else if (DECL_NAME (result
) != NULL_TREE
7124 && TREE_CODE (valtype
) != VOID_TYPE
)
7128 current_function_returns_null
= 1;
7130 if (valtype
!= NULL_TREE
&& TREE_CODE (valtype
) != VOID_TYPE
)
7132 if (DECL_NAME (DECL_RESULT (current_function_decl
)) == NULL_TREE
)
7134 pedwarn ("`return' with no value, in function returning non-void");
7135 /* Clear this, so finish_function won't say that we
7136 reach the end of a non-void function (which we don't,
7137 we gave a return!). */
7138 current_function_returns_null
= 0;
7142 expand_null_return ();
7146 else if (DECL_CONSTRUCTOR_P (current_function_decl
)
7147 && retval
!= current_class_decl
)
7149 error ("return from a constructor: use `this = ...' instead");
7150 retval
= current_class_decl
;
7153 if (valtype
== NULL_TREE
|| TREE_CODE (valtype
) == VOID_TYPE
)
7155 current_function_returns_null
= 1;
7156 /* We do this here so we'll avoid a warning about how the function
7157 "may or may not return a value" in finish_function. */
7161 pedwarn ("`return' with a value, in function returning void");
7162 expand_return (retval
);
7164 /* Add some useful error checking for C++. */
7165 else if (TREE_CODE (valtype
) == REFERENCE_TYPE
)
7167 tree whats_returned
;
7168 tree tmp_result
= result
;
7170 /* Don't initialize directly into a non-BLKmode retval, since that
7171 could lose when being inlined by another caller. (GCC can't
7172 read the function return register in an inline function when
7173 the return value is being ignored). */
7174 if (result
&& TYPE_MODE (TREE_TYPE (tmp_result
)) != BLKmode
)
7177 /* convert to reference now, so we can give error if we
7178 return an reference to a non-lvalue. */
7179 retval
= convert_for_initialization (tmp_result
, valtype
, retval
,
7180 LOOKUP_NORMAL
, "return",
7183 /* Sort through common things to see what it is
7184 we are returning. */
7185 whats_returned
= retval
;
7186 if (TREE_CODE (whats_returned
) == COMPOUND_EXPR
)
7188 whats_returned
= TREE_OPERAND (whats_returned
, 1);
7189 if (TREE_CODE (whats_returned
) == ADDR_EXPR
)
7190 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7192 if (TREE_CODE (whats_returned
) == ADDR_EXPR
)
7194 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7195 while (TREE_CODE (whats_returned
) == NEW_EXPR
7196 || TREE_CODE (whats_returned
) == TARGET_EXPR
7197 || TREE_CODE (whats_returned
) == WITH_CLEANUP_EXPR
)
7199 /* Get the target. */
7200 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7201 warning ("returning reference to temporary");
7205 if (TREE_CODE (whats_returned
) == VAR_DECL
&& DECL_NAME (whats_returned
))
7207 if (TEMP_NAME_P (DECL_NAME (whats_returned
)))
7208 warning ("reference to non-lvalue returned");
7209 else if (! TREE_STATIC (whats_returned
)
7210 && IDENTIFIER_LOCAL_VALUE (DECL_NAME (whats_returned
)))
7211 cp_warning_at ("reference to local variable `%D' returned", whats_returned
);
7214 else if (TREE_CODE (retval
) == ADDR_EXPR
)
7216 tree whats_returned
= TREE_OPERAND (retval
, 0);
7218 if (TREE_CODE (whats_returned
) == VAR_DECL
7219 && DECL_NAME (whats_returned
)
7220 && IDENTIFIER_LOCAL_VALUE (DECL_NAME (whats_returned
))
7221 && !TREE_STATIC (whats_returned
))
7222 cp_warning_at ("address of local variable `%D' returned", whats_returned
);
7225 /* Now deal with possible C++ hair:
7226 (1) Compute the return value.
7227 (2) If there are aggregate values with destructors which
7228 must be cleaned up, clean them (taking care
7229 not to clobber the return value).
7230 (3) If an X(X&) constructor is defined, the return
7231 value must be returned via that. */
7233 if (retval
== result
7234 /* Watch out for constructors, which "return" aggregates
7235 via initialization, but which otherwise "return" a pointer. */
7236 || DECL_CONSTRUCTOR_P (current_function_decl
))
7238 /* This is just an error--it's already been reported. */
7239 if (TYPE_SIZE (valtype
) == NULL_TREE
)
7242 if (TYPE_MODE (valtype
) != BLKmode
7243 && any_pending_cleanups (1))
7245 retval
= get_temp_regvar (valtype
, retval
);
7246 use_temp
= obey_regdecls
;
7249 else if (IS_AGGR_TYPE (valtype
) && TYPE_NEEDS_CONSTRUCTING (valtype
))
7251 /* Throw away the cleanup that `build_functional_cast' gave us. */
7252 if (TREE_CODE (retval
) == WITH_CLEANUP_EXPR
7253 && TREE_CODE (TREE_OPERAND (retval
, 0)) == TARGET_EXPR
)
7254 retval
= TREE_OPERAND (retval
, 0);
7255 expand_aggr_init (result
, retval
, 0, LOOKUP_ONLYCONVERTING
);
7256 expand_cleanups_to (NULL_TREE
);
7257 DECL_INITIAL (result
) = NULL_TREE
;
7262 if (TYPE_MODE (valtype
) == VOIDmode
)
7264 if (TYPE_MODE (TREE_TYPE (result
)) != VOIDmode
7265 && warn_return_type
)
7266 warning ("return of void value in function returning non-void");
7267 expand_expr_stmt (retval
);
7271 else if (TYPE_MODE (valtype
) != BLKmode
7272 && any_pending_cleanups (1))
7274 retval
= get_temp_regvar (valtype
, retval
);
7275 expand_cleanups_to (NULL_TREE
);
7276 use_temp
= obey_regdecls
;
7281 retval
= convert_for_initialization (result
, valtype
, retval
,
7283 "return", NULL_TREE
, 0);
7284 DECL_INITIAL (result
) = NULL_TREE
;
7286 if (retval
== error_mark_node
)
7292 if (retval
!= NULL_TREE
7293 && TREE_CODE_CLASS (TREE_CODE (retval
)) == 'd'
7294 && cond_stack
== 0 && loop_stack
== 0 && case_stack
== 0)
7295 current_function_return_value
= retval
;
7299 /* Everything's great--RETVAL is in RESULT. */
7300 if (original_result_rtx
)
7302 store_expr (result
, original_result_rtx
, 0);
7303 expand_cleanups_to (NULL_TREE
);
7305 else if (retval
&& retval
!= result
)
7307 /* Clear this out so the later call to decl_function_context
7308 won't end up bombing on us. */
7309 if (DECL_CONTEXT (result
) == error_mark_node
)
7310 DECL_CONTEXT (result
) = NULL_TREE
;
7311 /* Here is where we finally get RETVAL into RESULT.
7312 `expand_return' does the magic of protecting
7313 RESULT from cleanups. */
7314 retval
= fold (build1 (CLEANUP_POINT_EXPR
, TREE_TYPE (result
),
7316 /* This part _must_ come second, because expand_return looks for
7317 the INIT_EXPR as the toplevel node only. :-( */
7318 retval
= build (INIT_EXPR
, TREE_TYPE (result
), result
, retval
);
7319 TREE_SIDE_EFFECTS (retval
) = 1;
7320 expand_return (retval
);
7323 expand_return (result
);
7325 use_variable (DECL_RTL (result
));
7326 if (ctor_label
&& TREE_CODE (ctor_label
) != ERROR_MARK
)
7327 expand_goto (ctor_label
);
7329 expand_null_return ();
7333 /* We may still need to put RETVAL into RESULT. */
7334 result
= DECL_RESULT (current_function_decl
);
7335 if (original_result_rtx
)
7337 /* Here we have a named return value that went
7338 into memory. We can compute RETVAL into that. */
7340 expand_assignment (result
, retval
, 0, 0);
7342 store_expr (result
, original_result_rtx
, 0);
7343 result
= make_tree (TREE_TYPE (result
), original_result_rtx
);
7345 else if (ctor_label
&& TREE_CODE (ctor_label
) != ERROR_MARK
)
7347 /* Here RETVAL is CURRENT_CLASS_DECL, so there's nothing to do. */
7348 expand_goto (ctor_label
);
7352 /* Here is where we finally get RETVAL into RESULT.
7353 `expand_return' does the magic of protecting
7354 RESULT from cleanups. */
7355 result
= build (INIT_EXPR
, TREE_TYPE (result
), result
, retval
);
7356 TREE_SIDE_EFFECTS (result
) = 1;
7357 expand_return (result
);
7359 else if (TYPE_MODE (TREE_TYPE (result
)) != VOIDmode
)
7360 expand_return (result
);
7363 current_function_returns_value
= returns_value
;
7365 /* These wind up after the BARRIER, which causes problems for
7366 expand_end_binding. What purpose were they supposed to serve? */
7367 if (original_result_rtx
)
7368 use_variable (original_result_rtx
);
7370 use_variable (DECL_RTL (DECL_RESULT (current_function_decl
)));
7373 /* One way to clear out cleanups that EXPR might
7374 generate. Note that this code will really be
7375 dead code, but that is ok--cleanups that were
7376 needed were handled by the magic of `return'. */
7377 expand_cleanups_to (NULL_TREE
);
7380 /* Start a C switch statement, testing expression EXP.
7381 Return EXP if it is valid, an error node otherwise. */
7384 c_expand_start_case (exp
)
7388 register enum tree_code code
;
7390 /* Convert from references, etc. */
7391 exp
= default_conversion (exp
);
7392 type
= TREE_TYPE (exp
);
7393 code
= TREE_CODE (type
);
7395 if (IS_AGGR_TYPE_CODE (code
))
7396 exp
= build_type_conversion (CONVERT_EXPR
, integer_type_node
, exp
, 1);
7398 if (exp
== NULL_TREE
)
7400 error ("switch quantity not an integer");
7401 exp
= error_mark_node
;
7403 type
= TREE_TYPE (exp
);
7404 code
= TREE_CODE (type
);
7406 if (code
!= INTEGER_TYPE
&& code
!= ENUMERAL_TYPE
&& code
!= ERROR_MARK
)
7408 error ("switch quantity not an integer");
7409 exp
= error_mark_node
;
7415 exp
= default_conversion (exp
);
7416 type
= TREE_TYPE (exp
);
7417 index
= get_unwidened (exp
, 0);
7418 /* We can't strip a conversion from a signed type to an unsigned,
7419 because if we did, int_fits_type_p would do the wrong thing
7420 when checking case values for being in range,
7421 and it's too hard to do the right thing. */
7422 if (TREE_UNSIGNED (TREE_TYPE (exp
))
7423 == TREE_UNSIGNED (TREE_TYPE (index
)))
7428 (1, fold (build1 (CLEANUP_POINT_EXPR
, TREE_TYPE (exp
), exp
)),
7429 type
, "switch statement");
7434 /* CONSTP remembers whether or not all the intervening pointers in the `to'
7435 type have been const. */
7437 comp_ptr_ttypes_real (to
, from
, constp
)
7441 for (; ; to
= TREE_TYPE (to
), from
= TREE_TYPE (from
))
7443 if (TREE_CODE (to
) != TREE_CODE (from
))
7446 if (TYPE_READONLY (from
) > TYPE_READONLY (to
)
7447 || TYPE_VOLATILE (from
) > TYPE_VOLATILE (to
))
7451 && (TYPE_READONLY (to
) > TYPE_READONLY (from
)
7452 || TYPE_VOLATILE (to
) > TYPE_READONLY (from
)))
7454 constp
&= TYPE_READONLY (to
);
7456 if (TREE_CODE (to
) != POINTER_TYPE
)
7457 return comptypes (TYPE_MAIN_VARIANT (to
), TYPE_MAIN_VARIANT (from
), 1);
7461 /* When comparing, say, char ** to char const **, this function takes the
7462 'char *' and 'char const *'. Do not pass non-pointer types to this
7465 comp_ptr_ttypes (to
, from
)
7468 return comp_ptr_ttypes_real (to
, from
, 1);