1 /* Build expressions with type checking for C++ compiler.
2 Copyright (C) 1987, 88, 89, 92, 93, 94, 1995 Free Software Foundation, Inc.
3 Hacked by Michael Tiemann (tiemann@cygnus.com)
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 /* This file is part of the C++ front end.
24 It contains routines to build C++ expressions given their operands,
25 including computing the types of the result, C and C++ specific error
26 checks, and some optimization.
28 There are also routines to build RETURN_STMT nodes and CASE_STMT nodes,
29 and to process initializations in declarations (since they work
30 like a strange sort of assignment). */
33 extern void warning ();
43 int mark_addressable ();
44 static tree
convert_for_assignment ();
45 /* static */ tree
convert_for_initialization ();
46 extern tree
shorten_compare ();
47 extern void binary_op_error ();
48 static tree
pointer_int_sum ();
49 static tree
pointer_diff ();
50 static tree
convert_sequence ();
51 /* static */ tree
unary_complex_lvalue ();
52 static tree get_delta_difference
PROTO((tree
, tree
, int));
54 extern rtx original_result_rtx
;
55 extern int warn_synth
;
57 /* Return the target type of TYPE, which meas return T for:
58 T*, T&, T[], T (...), and otherwise, just T. */
64 if (TREE_CODE (type
) == REFERENCE_TYPE
)
65 type
= TREE_TYPE (type
);
66 while (TREE_CODE (type
) == POINTER_TYPE
67 || TREE_CODE (type
) == ARRAY_TYPE
68 || TREE_CODE (type
) == FUNCTION_TYPE
69 || TREE_CODE (type
) == METHOD_TYPE
70 || TREE_CODE (type
) == OFFSET_TYPE
)
71 type
= TREE_TYPE (type
);
75 /* Do `exp = require_complete_type (exp);' to make sure exp
76 does not have an incomplete type. (That includes void types.) */
79 require_complete_type (value
)
82 tree type
= TREE_TYPE (value
);
84 /* First, detect a valid value with a complete type. */
85 if (TYPE_SIZE (type
) != 0
86 && type
!= void_type_node
87 && ! (TYPE_LANG_SPECIFIC (type
)
88 && (IS_SIGNATURE_POINTER (type
) || IS_SIGNATURE_REFERENCE (type
))
89 && TYPE_SIZE (SIGNATURE_TYPE (type
)) == 0))
92 /* If we see X::Y, we build an OFFSET_TYPE which has
93 not been laid out. Try to avoid an error by interpreting
94 it as this->X::Y, if reasonable. */
95 if (TREE_CODE (value
) == OFFSET_REF
97 && TREE_OPERAND (value
, 0) == C_C_D
)
99 tree base
, member
= TREE_OPERAND (value
, 1);
100 tree basetype
= TYPE_OFFSET_BASETYPE (type
);
101 my_friendly_assert (TREE_CODE (member
) == FIELD_DECL
, 305);
102 base
= convert_pointer_to (basetype
, current_class_decl
);
103 value
= build (COMPONENT_REF
, TREE_TYPE (member
),
104 build_indirect_ref (base
, NULL_PTR
), member
);
105 return require_complete_type (value
);
108 incomplete_type_error (value
, type
);
109 return error_mark_node
;
112 /* Return truthvalue of whether type of EXP is instantiated. */
117 return (TREE_CODE (exp
) == TREE_LIST
118 || TREE_TYPE (exp
) == unknown_type_node
119 || (TREE_CODE (TREE_TYPE (exp
)) == OFFSET_TYPE
120 && TREE_TYPE (TREE_TYPE (exp
)) == unknown_type_node
));
123 /* Return truthvalue of whether T is function (or pfn) type. */
128 return (TREE_CODE (t
) == FUNCTION_TYPE
|| TREE_CODE (t
) == METHOD_TYPE
129 || (TREE_CODE (t
) == POINTER_TYPE
130 && (TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
131 || TREE_CODE (TREE_TYPE (t
)) == METHOD_TYPE
)));
134 /* Do `exp = require_instantiated_type (type, exp);' to make sure EXP
135 does not have an uninstantiated type.
136 TYPE is type to instantiate with, if uninstantiated. */
138 require_instantiated_type (type
, exp
, errval
)
139 tree type
, exp
, errval
;
141 if (TREE_TYPE (exp
) == NULL_TREE
)
143 error ("argument list may not have an initializer list");
147 if (TREE_TYPE (exp
) == unknown_type_node
148 || (TREE_CODE (TREE_TYPE (exp
)) == OFFSET_TYPE
149 && TREE_TYPE (TREE_TYPE (exp
)) == unknown_type_node
))
151 exp
= instantiate_type (type
, exp
, 1);
152 if (TREE_TYPE (exp
) == error_mark_node
)
158 /* Return a variant of TYPE which has all the type qualifiers of LIKE
159 as well as those of TYPE. */
162 qualify_type (type
, like
)
165 int constflag
= TYPE_READONLY (type
) || TYPE_READONLY (like
);
166 int volflag
= TYPE_VOLATILE (type
) || TYPE_VOLATILE (like
);
167 /* @@ Must do member pointers here. */
168 return cp_build_type_variant (type
, constflag
, volflag
);
171 /* Return the common type of two parameter lists.
172 We assume that comptypes has already been done and returned 1;
173 if that isn't so, this may crash.
175 As an optimization, free the space we allocate if the parameter
176 lists are already common. */
182 tree oldargs
= p1
, newargs
, n
;
185 char *first_obj
= (char *) oballoc (0);
187 len
= list_length (p1
);
188 newargs
= tree_last (p1
);
190 if (newargs
== void_list_node
)
199 newargs
= tree_cons (NULL_TREE
, NULL_TREE
, newargs
);
204 p1
= TREE_CHAIN (p1
), p2
= TREE_CHAIN (p2
), n
= TREE_CHAIN (n
), i
++)
206 if (TREE_PURPOSE (p1
) && !TREE_PURPOSE (p2
))
208 TREE_PURPOSE (n
) = TREE_PURPOSE (p1
);
211 else if (! TREE_PURPOSE (p1
))
213 if (TREE_PURPOSE (p2
))
215 TREE_PURPOSE (n
) = TREE_PURPOSE (p2
);
221 if (1 != simple_cst_equal (TREE_PURPOSE (p1
), TREE_PURPOSE (p2
)))
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 list. */
289 /* ??? For the moment we punt on the issue of attrs with args. */
291 if (list_length (a1
) < list_length (a2
))
292 attributes
= a2
, a2
= a1
;
294 for (; a2
; a2
= TREE_CHAIN (a2
))
295 if (lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2
)),
296 attributes
) == NULL_TREE
)
299 TREE_CHAIN (a1
) = attributes
;
305 /* Treat an enum type as the unsigned integer type of the same width. */
307 if (TREE_CODE (t1
) == ENUMERAL_TYPE
)
308 t1
= type_for_size (TYPE_PRECISION (t1
), 1);
309 if (TREE_CODE (t2
) == ENUMERAL_TYPE
)
310 t2
= type_for_size (TYPE_PRECISION (t2
), 1);
312 code1
= TREE_CODE (t1
);
313 code2
= TREE_CODE (t2
);
319 /* If only one is real, use it as the result. */
321 if (code1
== REAL_TYPE
&& code2
!= REAL_TYPE
)
322 return build_type_attribute_variant (t1
, attributes
);
324 if (code2
== REAL_TYPE
&& code1
!= REAL_TYPE
)
325 return build_type_attribute_variant (t2
, attributes
);
327 /* Both real or both integers; use the one with greater precision. */
329 if (TYPE_PRECISION (t1
) > TYPE_PRECISION (t2
))
330 return build_type_attribute_variant (t1
, attributes
);
331 else if (TYPE_PRECISION (t2
) > TYPE_PRECISION (t1
))
332 return build_type_attribute_variant (t2
, attributes
);
334 /* Same precision. Prefer longs to ints even when same size. */
336 if (TYPE_MAIN_VARIANT (t1
) == long_unsigned_type_node
337 || TYPE_MAIN_VARIANT (t2
) == long_unsigned_type_node
)
338 return build_type_attribute_variant (long_unsigned_type_node
,
341 if (TYPE_MAIN_VARIANT (t1
) == long_integer_type_node
342 || TYPE_MAIN_VARIANT (t2
) == long_integer_type_node
)
344 /* But preserve unsignedness from the other type,
345 since long cannot hold all the values of an unsigned int. */
346 if (TREE_UNSIGNED (t1
) || TREE_UNSIGNED (t2
))
347 t1
= long_unsigned_type_node
;
349 t1
= long_integer_type_node
;
350 return build_type_attribute_variant (t1
, attributes
);
353 if (TYPE_MAIN_VARIANT (t1
) == long_double_type_node
354 || TYPE_MAIN_VARIANT (t2
) == long_double_type_node
)
355 return build_type_attribute_variant (long_double_type_node
,
358 /* Otherwise prefer the unsigned one. */
360 if (TREE_UNSIGNED (t1
))
361 return build_type_attribute_variant (t1
, attributes
);
363 return build_type_attribute_variant (t2
, attributes
);
367 /* For two pointers, do this recursively on the target type,
368 and combine the qualifiers of the two types' targets. */
369 /* This code was turned off; I don't know why.
370 But ANSI C++ specifies doing this with the qualifiers.
371 So I turned it on again. */
373 tree tt1
= TYPE_MAIN_VARIANT (TREE_TYPE (t1
));
374 tree tt2
= TYPE_MAIN_VARIANT (TREE_TYPE (t2
));
376 = TYPE_READONLY (TREE_TYPE (t1
)) || TYPE_READONLY (TREE_TYPE (t2
));
378 = TYPE_VOLATILE (TREE_TYPE (t1
)) || TYPE_VOLATILE (TREE_TYPE (t2
));
383 else if (tt1
== void_type_node
|| tt2
== void_type_node
)
384 target
= void_type_node
;
386 target
= common_type (tt1
, tt2
);
388 target
= cp_build_type_variant (target
, constp
, volatilep
);
389 if (code1
== POINTER_TYPE
)
390 t1
= build_pointer_type (target
);
392 t1
= build_reference_type (target
);
393 t1
= build_type_attribute_variant (t1
, attributes
);
395 if (TREE_CODE (target
) == METHOD_TYPE
)
396 t1
= build_ptrmemfunc_type (t1
);
402 t1
= build_pointer_type (common_type (TREE_TYPE (t1
), TREE_TYPE (t2
)));
403 return build_type_attribute_variant (t1
, attributes
);
406 t1
= build_reference_type (common_type (TREE_TYPE (t1
), TREE_TYPE (t2
)));
407 return build_type_attribute_variant (t1
, attributes
);
412 tree elt
= common_type (TREE_TYPE (t1
), TREE_TYPE (t2
));
413 /* Save space: see if the result is identical to one of the args. */
414 if (elt
== TREE_TYPE (t1
) && TYPE_DOMAIN (t1
))
415 return build_type_attribute_variant (t1
, attributes
);
416 if (elt
== TREE_TYPE (t2
) && TYPE_DOMAIN (t2
))
417 return build_type_attribute_variant (t2
, attributes
);
418 /* Merge the element types, and have a size if either arg has one. */
419 t1
= build_cplus_array_type (elt
, TYPE_DOMAIN (TYPE_DOMAIN (t1
) ? t1
: t2
));
420 return build_type_attribute_variant (t1
, attributes
);
424 /* Function types: prefer the one that specified arg types.
425 If both do, merge the arg types. Also merge the return types. */
427 tree valtype
= common_type (TREE_TYPE (t1
), TREE_TYPE (t2
));
428 tree p1
= TYPE_ARG_TYPES (t1
);
429 tree p2
= TYPE_ARG_TYPES (t2
);
432 /* Save space: see if the result is identical to one of the args. */
433 if (valtype
== TREE_TYPE (t1
) && ! p2
)
434 return build_type_attribute_variant (t1
, attributes
);
435 if (valtype
== TREE_TYPE (t2
) && ! p1
)
436 return build_type_attribute_variant (t2
, attributes
);
438 /* Simple way if one arg fails to specify argument types. */
439 if (p1
== NULL_TREE
|| TREE_VALUE (p1
) == void_type_node
)
441 rval
= build_function_type (valtype
, p2
);
442 if ((raises
= TYPE_RAISES_EXCEPTIONS (t2
)))
443 rval
= build_exception_variant (rval
, raises
);
444 return build_type_attribute_variant (rval
, attributes
);
446 raises
= TYPE_RAISES_EXCEPTIONS (t1
);
447 if (p2
== NULL_TREE
|| TREE_VALUE (p2
) == void_type_node
)
449 rval
= build_function_type (valtype
, p1
);
451 rval
= build_exception_variant (rval
, raises
);
452 return build_type_attribute_variant (rval
, attributes
);
455 rval
= build_function_type (valtype
, commonparms (p1
, p2
));
456 rval
= build_exception_variant (rval
, raises
);
457 return build_type_attribute_variant (rval
, attributes
);
462 my_friendly_assert (TYPE_MAIN_VARIANT (t1
) == t1
463 && TYPE_MAIN_VARIANT (t2
) == t2
, 306);
465 if (DERIVED_FROM_P (t1
, t2
) && binfo_or_else (t1
, t2
))
466 return build_type_attribute_variant (t1
, attributes
);
467 else if (binfo_or_else (t2
, t1
))
468 return build_type_attribute_variant (t2
, attributes
);
470 compiler_error ("common_type called with uncommon aggregate types");
473 if (TREE_CODE (TREE_TYPE (t1
)) == TREE_CODE (TREE_TYPE (t2
)))
475 /* Get this value the long way, since TYPE_METHOD_BASETYPE
476 is just the main variant of this. */
480 tree b1
= TYPE_OFFSET_BASETYPE (t1
);
481 tree b2
= TYPE_OFFSET_BASETYPE (t2
);
483 if (DERIVED_FROM_P (b1
, b2
) && binfo_or_else (b1
, b2
))
484 basetype
= TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t2
)));
487 if (binfo_or_else (b2
, b1
) == NULL_TREE
)
488 compiler_error ("common_type called with uncommon method types");
489 basetype
= TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t1
)));
492 raises
= TYPE_RAISES_EXCEPTIONS (t1
);
494 /* If this was a member function type, get back to the
495 original type of type member function (i.e., without
496 the class instance variable up front. */
497 t1
= build_function_type (TREE_TYPE (t1
), TREE_CHAIN (TYPE_ARG_TYPES (t1
)));
498 t2
= build_function_type (TREE_TYPE (t2
), TREE_CHAIN (TYPE_ARG_TYPES (t2
)));
499 t3
= common_type (t1
, t2
);
500 t3
= build_cplus_method_type (basetype
, TREE_TYPE (t3
), TYPE_ARG_TYPES (t3
));
501 t1
= build_exception_variant (t3
, raises
);
504 compiler_error ("common_type called with uncommon method types");
506 return build_type_attribute_variant (t1
, attributes
);
509 if (TREE_TYPE (t1
) == TREE_TYPE (t2
))
511 tree b1
= TYPE_OFFSET_BASETYPE (t1
);
512 tree b2
= TYPE_OFFSET_BASETYPE (t2
);
514 if (DERIVED_FROM_P (b1
, b2
) && binfo_or_else (b1
, b2
))
515 return build_type_attribute_variant (t2
, attributes
);
516 else if (binfo_or_else (b2
, b1
))
517 return build_type_attribute_variant (t1
, attributes
);
519 compiler_error ("common_type called with uncommon member types");
522 return build_type_attribute_variant (t1
, attributes
);
526 /* Return 1 if TYPE1 and TYPE2 raise the same exceptions. */
528 compexcepttypes (t1
, t2
, strict
)
532 return TYPE_RAISES_EXCEPTIONS (t1
) == TYPE_RAISES_EXCEPTIONS (t2
);
536 comp_array_types (cmp
, t1
, t2
, strict
)
537 register int (*cmp
)();
541 tree d1
= TYPE_DOMAIN (t1
);
542 tree d2
= TYPE_DOMAIN (t2
);
544 /* Target types must match incl. qualifiers. */
545 if (!(TREE_TYPE (t1
) == TREE_TYPE (t2
)
546 || (*cmp
) (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
)))
549 /* Sizes must match unless one is missing or variable. */
550 if (d1
== 0 || d2
== 0 || d1
== d2
551 || TREE_CODE (TYPE_MIN_VALUE (d1
)) != INTEGER_CST
552 || TREE_CODE (TYPE_MIN_VALUE (d2
)) != INTEGER_CST
553 || TREE_CODE (TYPE_MAX_VALUE (d1
)) != INTEGER_CST
554 || TREE_CODE (TYPE_MAX_VALUE (d2
)) != INTEGER_CST
)
557 return ((TREE_INT_CST_LOW (TYPE_MIN_VALUE (d1
))
558 == TREE_INT_CST_LOW (TYPE_MIN_VALUE (d2
)))
559 && (TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d1
))
560 == TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d2
)))
561 && (TREE_INT_CST_LOW (TYPE_MAX_VALUE (d1
))
562 == TREE_INT_CST_LOW (TYPE_MAX_VALUE (d2
)))
563 && (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d1
))
564 == TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d2
))));
567 /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
568 or various other operations. This is what ANSI C++ speaks of as
571 For C++: argument STRICT says we should be strict about this
574 2 : strict, except that if one type is a reference and
575 the other is not, compare the target type of the
576 reference to the type that's not a reference (ARM, p308).
577 This is used for checking for invalid overloading.
578 1 : strict (compared according to ANSI C)
579 This is used for checking whether two function decls match.
580 0 : <= (compared according to C++)
581 -1: <= or >= (relaxed)
583 Otherwise, pointers involving base classes and derived classes
584 can be mixed as valid: i.e. a pointer to a base class may be assigned
585 to a pointer to one of its derived classes, as per C++. A pointer to
586 a derived class may be passed as a parameter to a function expecting a
587 pointer to a base classes. These allowances do not commute. In this
588 case, TYPE1 is assumed to be the base class, and TYPE2 is assumed to
589 be the derived class. */
591 comptypes (type1
, type2
, strict
)
595 register tree t1
= type1
;
596 register tree t2
= type2
;
599 /* Suppress errors caused by previously reported errors */
604 /* This should never happen. */
605 my_friendly_assert (t1
!= error_mark_node
, 307);
607 if (t2
== error_mark_node
)
612 /* Treat an enum type as the unsigned integer type of the same width. */
614 if (TREE_CODE (t1
) == ENUMERAL_TYPE
)
615 t1
= type_for_size (TYPE_PRECISION (t1
), 1);
616 if (TREE_CODE (t2
) == ENUMERAL_TYPE
)
617 t2
= type_for_size (TYPE_PRECISION (t2
), 1);
623 /* Different classes of types can't be compatible. */
625 if (TREE_CODE (t1
) != TREE_CODE (t2
))
628 && ((TREE_CODE (t1
) == REFERENCE_TYPE
)
629 ^ (TREE_CODE (t2
) == REFERENCE_TYPE
)))
631 if (TREE_CODE (t1
) == REFERENCE_TYPE
)
632 return comptypes (TREE_TYPE (t1
), t2
, 1);
633 return comptypes (t1
, TREE_TYPE (t2
), 1);
641 /* Qualifiers must match. */
643 if (TYPE_READONLY (t1
) != TYPE_READONLY (t2
))
645 if (TYPE_VOLATILE (t1
) != TYPE_VOLATILE (t2
))
648 /* Allow for two different type nodes which have essentially the same
649 definition. Note that we already checked for equality of the type
650 type qualifiers (just above). */
652 if (TYPE_MAIN_VARIANT (t1
) == TYPE_MAIN_VARIANT (t2
))
655 #ifdef COMP_TYPE_ATTRIBUTES
656 if (! (attrval
= COMP_TYPE_ATTRIBUTES (t1
, t2
)))
659 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
663 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
666 switch (TREE_CODE (t1
))
675 val
= (comptypes (build_pointer_type (TYPE_OFFSET_BASETYPE (t1
)),
676 build_pointer_type (TYPE_OFFSET_BASETYPE (t2
)), strict
)
677 && comptypes (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
));
681 if (! compexcepttypes (t1
, t2
, strict
))
684 /* This case is anti-symmetrical!
685 One can pass a base member (or member function)
686 to something expecting a derived member (or member function),
687 but not vice-versa! */
689 val
= (comptypes (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
)
690 && compparms (TYPE_ARG_TYPES (t1
),
691 TYPE_ARG_TYPES (t2
), strict
));
705 if (TREE_CODE (t1
) == RECORD_TYPE
&& TREE_CODE (t2
) == RECORD_TYPE
)
709 rval
= t1
== t2
|| UNIQUELY_DERIVED_FROM_P (t1
, t2
);
718 val
= UNIQUELY_DERIVED_FROM_P (t2
, t1
);
725 val
= comptypes (t1
, t2
, strict
);
729 if (! compexcepttypes (t1
, t2
, strict
))
732 val
= ((TREE_TYPE (t1
) == TREE_TYPE (t2
)
733 || comptypes (TREE_TYPE (t1
), TREE_TYPE (t2
), strict
))
734 && compparms (TYPE_ARG_TYPES (t1
), TYPE_ARG_TYPES (t2
), strict
));
738 /* Target types must match incl. qualifiers. */
739 val
= comp_array_types (comptypes
, t1
, t2
, strict
);
742 case TEMPLATE_TYPE_PARM
:
743 return TEMPLATE_TYPE_IDX (t1
) == TEMPLATE_TYPE_IDX (t2
);
745 case UNINSTANTIATED_P_TYPE
:
746 if (UPT_TEMPLATE (t1
) != UPT_TEMPLATE (t2
))
749 int i
= TREE_VEC_LENGTH (UPT_PARMS (t1
));
750 tree
*p1
= &TREE_VEC_ELT (UPT_PARMS (t1
), 0);
751 tree
*p2
= &TREE_VEC_ELT (UPT_PARMS (t2
), 0);
755 if (TREE_CODE_CLASS (TREE_CODE (p1
[i
])) == 't')
757 if (! comptypes (p1
[i
], p2
[i
], 1))
762 if (simple_cst_equal (p1
[i
], p2
[i
]) <= 0)
769 return attrval
== 2 && val
== 1 ? 2 : val
;
772 /* Return 1 if TTL and TTR are pointers to types that are equivalent,
773 ignoring their qualifiers.
775 NPTRS is the number of pointers we can strip off and keep cool.
776 This is used to permit (for aggr A, aggr B) A, B* to convert to A*,
777 but to not permit B** to convert to A**. */
780 comp_target_types (ttl
, ttr
, nptrs
)
784 ttl
= TYPE_MAIN_VARIANT (ttl
);
785 ttr
= TYPE_MAIN_VARIANT (ttr
);
789 if (TREE_CODE (ttr
) != TREE_CODE (ttl
))
792 if (TREE_CODE (ttr
) == POINTER_TYPE
)
794 ttl
= TREE_TYPE (ttl
);
795 ttr
= TREE_TYPE (ttr
);
799 if (TREE_CODE (ttl
) == VOID_TYPE
800 && TREE_CODE (ttr
) != FUNCTION_TYPE
801 && TREE_CODE (ttr
) != METHOD_TYPE
802 && TREE_CODE (ttr
) != OFFSET_TYPE
)
804 else if (TREE_CODE (ttr
) == VOID_TYPE
805 && TREE_CODE (ttl
) != FUNCTION_TYPE
806 && TREE_CODE (ttl
) != METHOD_TYPE
807 && TREE_CODE (ttl
) != OFFSET_TYPE
)
809 else if (TREE_CODE (ttl
) == POINTER_TYPE
810 || TREE_CODE (ttl
) == ARRAY_TYPE
)
812 if (comp_ptr_ttypes (ttl
, ttr
))
814 else if (comp_ptr_ttypes (ttr
, ttl
))
820 /* Const and volatile mean something different for function types,
821 so the usual checks are not appropriate. */
822 if (TREE_CODE (ttl
) == FUNCTION_TYPE
|| TREE_CODE (ttl
) == METHOD_TYPE
)
823 return comp_target_types (ttl
, ttr
, nptrs
- 1);
825 /* Make sure that the cv-quals change only in the same direction as
829 int c
= TYPE_READONLY (ttl
) - TYPE_READONLY (ttr
);
830 int v
= TYPE_VOLATILE (ttl
) - TYPE_VOLATILE (ttr
);
832 if ((c
> 0 && v
< 0) || (c
< 0 && v
> 0))
835 if (TYPE_MAIN_VARIANT (ttl
) == TYPE_MAIN_VARIANT (ttr
))
836 return (c
+ v
< 0) ? -1 : 1;
838 t
= comp_target_types (ttl
, ttr
, nptrs
- 1);
839 if ((t
== 1 && c
+ v
>= 0) || (t
== -1 && c
+ v
<= 0))
846 if (TREE_CODE (ttr
) == REFERENCE_TYPE
)
847 return comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), nptrs
);
848 if (TREE_CODE (ttr
) == ARRAY_TYPE
)
849 return comp_array_types (comp_target_types
, ttl
, ttr
, 0);
850 else if (TREE_CODE (ttr
) == FUNCTION_TYPE
|| TREE_CODE (ttr
) == METHOD_TYPE
)
851 if (comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), nptrs
))
852 switch (comp_target_parms (TYPE_ARG_TYPES (ttl
), TYPE_ARG_TYPES (ttr
), 1))
861 my_friendly_abort (112);
867 else if (TREE_CODE (ttr
) == OFFSET_TYPE
)
869 /* Contravariance: we can assign a pointer to base member to a pointer
870 to derived member. Note difference from simple pointer case, where
871 we can pass a pointer to derived to a pointer to base. */
872 if (comptypes (TYPE_OFFSET_BASETYPE (ttr
), TYPE_OFFSET_BASETYPE (ttl
), 0))
873 return comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), nptrs
);
874 else if (comptypes (TYPE_OFFSET_BASETYPE (ttl
), TYPE_OFFSET_BASETYPE (ttr
), 0)
875 && comp_target_types (TREE_TYPE (ttl
), TREE_TYPE (ttr
), nptrs
))
878 else if (IS_AGGR_TYPE (ttl
))
882 if (comptypes (build_pointer_type (ttl
), build_pointer_type (ttr
), 0))
884 if (comptypes (build_pointer_type (ttr
), build_pointer_type (ttl
), 0))
892 /* If two types share a common base type, return that basetype.
893 If there is not a unique most-derived base type, this function
894 returns ERROR_MARK_NODE. */
896 common_base_type (tt1
, tt2
)
899 tree best
= NULL_TREE
, tmp
;
902 /* If one is a baseclass of another, that's good enough. */
903 if (UNIQUELY_DERIVED_FROM_P (tt1
, tt2
))
905 if (UNIQUELY_DERIVED_FROM_P (tt2
, tt1
))
909 /* If they share a virtual baseclass, that's good enough. */
910 for (tmp
= CLASSTYPE_VBASECLASSES (tt1
); tmp
; tmp
= TREE_CHAIN (tmp
))
912 if (binfo_member (BINFO_TYPE (tmp
), CLASSTYPE_VBASECLASSES (tt2
)))
913 return BINFO_TYPE (tmp
);
917 /* Otherwise, try to find a unique baseclass of TT1
918 that is shared by TT2, and follow that down. */
919 for (i
= CLASSTYPE_N_BASECLASSES (tt1
)-1; i
>= 0; i
--)
921 tree basetype
= TYPE_BINFO_BASETYPE (tt1
, i
);
922 tree trial
= common_base_type (basetype
, tt2
);
925 if (trial
== error_mark_node
)
927 if (best
== NULL_TREE
)
929 else if (best
!= trial
)
930 return error_mark_node
;
935 for (i
= CLASSTYPE_N_BASECLASSES (tt2
)-1; i
>= 0; i
--)
937 tree basetype
= TYPE_BINFO_BASETYPE (tt2
, i
);
938 tree trial
= common_base_type (tt1
, basetype
);
941 if (trial
== error_mark_node
)
943 if (best
== NULL_TREE
)
945 else if (best
!= trial
)
946 return error_mark_node
;
952 /* Subroutines of `comptypes'. */
954 /* Return 1 if two parameter type lists PARMS1 and PARMS2
955 are equivalent in the sense that functions with those parameter types
956 can have equivalent types.
957 If either list is empty, we win.
958 Otherwise, the two lists must be equivalent, element by element.
960 C++: See comment above about TYPE1, TYPE2, STRICT.
961 If STRICT == 3, it means checking is strict, but do not compare
962 default parameter values. */
964 compparms (parms1
, parms2
, strict
)
968 register tree t1
= parms1
, t2
= parms2
;
970 /* An unspecified parmlist matches any specified parmlist
971 whose argument types don't need default promotions. */
973 if (strict
<= 0 && t1
== 0)
974 return self_promoting_args_p (t2
);
975 if (strict
< 0 && t2
== 0)
976 return self_promoting_args_p (t1
);
980 if (t1
== 0 && t2
== 0)
982 /* If one parmlist is shorter than the other,
983 they fail to match, unless STRICT is <= 0. */
984 if (t1
== 0 || t2
== 0)
991 return t1
&& TREE_PURPOSE (t1
);
993 if (! comptypes (TREE_VALUE (t2
), TREE_VALUE (t1
), strict
))
998 return t2
== void_list_node
&& TREE_PURPOSE (t1
);
999 return TREE_PURPOSE (t1
) || TREE_PURPOSE (t2
);
1002 /* Default parms are not part of the type of a function. */
1003 if (strict
!= 3 && TREE_PURPOSE (t1
) && TREE_PURPOSE (t2
))
1005 int cmp
= simple_cst_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
));
1007 my_friendly_abort (113);
1013 t1
= TREE_CHAIN (t1
);
1014 t2
= TREE_CHAIN (t2
);
1018 /* This really wants return whether or not parameter type lists
1019 would make their owning functions assignment compatible or not. */
1021 comp_target_parms (parms1
, parms2
, strict
)
1022 tree parms1
, parms2
;
1025 register tree t1
= parms1
, t2
= parms2
;
1026 int warn_contravariance
= 0;
1028 /* An unspecified parmlist matches any specified parmlist
1029 whose argument types don't need default promotions.
1030 @@@ see 13.3.3 for a counterexample... */
1032 if (t1
== 0 && t2
!= 0)
1034 cp_pedwarn ("ANSI C++ prohibits conversion from `(%#T)' to `(...)'",
1036 return self_promoting_args_p (t2
);
1039 return self_promoting_args_p (t1
);
1041 for (; t1
|| t2
; t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
))
1045 /* If one parmlist is shorter than the other,
1046 they fail to match, unless STRICT is <= 0. */
1047 if (t1
== 0 || t2
== 0)
1052 return 1 + warn_contravariance
;
1053 return ((t1
&& TREE_PURPOSE (t1
)) + warn_contravariance
);
1055 p1
= TREE_VALUE (t1
);
1056 p2
= TREE_VALUE (t2
);
1060 if ((TREE_CODE (p1
) == POINTER_TYPE
&& TREE_CODE (p2
) == POINTER_TYPE
)
1061 || (TREE_CODE (p1
) == REFERENCE_TYPE
&& TREE_CODE (p2
) == REFERENCE_TYPE
))
1064 && (TYPE_MAIN_VARIANT (TREE_TYPE (p1
))
1065 == TYPE_MAIN_VARIANT (TREE_TYPE (p2
))))
1068 /* The following is wrong for contravariance,
1069 but many programs depend on it. */
1070 if (TREE_TYPE (p1
) == void_type_node
)
1072 if (TREE_TYPE (p2
) == void_type_node
)
1074 warn_contravariance
= 1;
1077 if (IS_AGGR_TYPE (TREE_TYPE (p1
)))
1079 if (comptypes (p2
, p1
, 0) == 0)
1081 if (comptypes (p1
, p2
, 0) != 0)
1082 warn_contravariance
= 1;
1089 /* Note backwards order due to contravariance. */
1090 if (comp_target_types (p2
, p1
, 1) == 0)
1092 if (comp_target_types (p1
, p2
, 1))
1094 warn_contravariance
= 1;
1100 /* What good do these cases do? */
1102 return p2
== void_type_node
&& TREE_PURPOSE (t1
);
1103 return TREE_PURPOSE (t1
) || TREE_PURPOSE (t2
);
1106 /* Target types are compatible--just make sure that if
1107 we use parameter lists, that they are ok as well. */
1108 if (TREE_CODE (p1
) == FUNCTION_TYPE
|| TREE_CODE (p1
) == METHOD_TYPE
)
1109 switch (comp_target_parms (TYPE_ARG_TYPES (p1
),
1110 TYPE_ARG_TYPES (p2
),
1118 warn_contravariance
= 1;
1121 if (TREE_PURPOSE (t1
) && TREE_PURPOSE (t2
))
1123 int cmp
= simple_cst_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
));
1125 my_friendly_abort (114);
1130 return 1 + warn_contravariance
;
1133 /* Return 1 if PARMS specifies a fixed number of parameters
1134 and none of their types is affected by default promotions. */
1137 self_promoting_args_p (parms
)
1141 for (t
= parms
; t
; t
= TREE_CHAIN (t
))
1143 register tree type
= TREE_VALUE (t
);
1145 if (TREE_CHAIN (t
) == 0 && type
!= void_type_node
)
1148 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
1154 if (C_PROMOTING_INTEGER_TYPE_P (type
))
1160 /* Return an unsigned type the same as TYPE in other respects.
1162 C++: must make these work for type variants as well. */
1165 unsigned_type (type
)
1168 tree type1
= TYPE_MAIN_VARIANT (type
);
1169 if (type1
== signed_char_type_node
|| type1
== char_type_node
)
1170 return unsigned_char_type_node
;
1171 if (type1
== integer_type_node
)
1172 return unsigned_type_node
;
1173 if (type1
== short_integer_type_node
)
1174 return short_unsigned_type_node
;
1175 if (type1
== long_integer_type_node
)
1176 return long_unsigned_type_node
;
1177 if (type1
== long_long_integer_type_node
)
1178 return long_long_unsigned_type_node
;
1182 /* Return a signed type the same as TYPE in other respects. */
1188 tree type1
= TYPE_MAIN_VARIANT (type
);
1189 if (type1
== unsigned_char_type_node
|| type1
== char_type_node
)
1190 return signed_char_type_node
;
1191 if (type1
== unsigned_type_node
)
1192 return integer_type_node
;
1193 if (type1
== short_unsigned_type_node
)
1194 return short_integer_type_node
;
1195 if (type1
== long_unsigned_type_node
)
1196 return long_integer_type_node
;
1197 if (type1
== long_long_unsigned_type_node
)
1198 return long_long_integer_type_node
;
1202 /* Return a type the same as TYPE except unsigned or
1203 signed according to UNSIGNEDP. */
1206 signed_or_unsigned_type (unsignedp
, type
)
1210 if (! INTEGRAL_TYPE_P (type
))
1212 if (TYPE_PRECISION (type
) == TYPE_PRECISION (signed_char_type_node
))
1213 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
1214 if (TYPE_PRECISION (type
) == TYPE_PRECISION (integer_type_node
))
1215 return unsignedp
? unsigned_type_node
: integer_type_node
;
1216 if (TYPE_PRECISION (type
) == TYPE_PRECISION (short_integer_type_node
))
1217 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
1218 if (TYPE_PRECISION (type
) == TYPE_PRECISION (long_integer_type_node
))
1219 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
1220 if (TYPE_PRECISION (type
) == TYPE_PRECISION (long_long_integer_type_node
))
1221 return (unsignedp
? long_long_unsigned_type_node
1222 : long_long_integer_type_node
);
1230 enum tree_code code
= TREE_CODE (type
);
1233 if (code
== FUNCTION_TYPE
)
1235 if (pedantic
|| warn_pointer_arith
)
1236 pedwarn ("ANSI C++ forbids taking the sizeof a function type");
1237 return size_int (1);
1239 if (code
== METHOD_TYPE
)
1241 if (pedantic
|| warn_pointer_arith
)
1242 pedwarn ("ANSI C++ forbids taking the sizeof a method type");
1243 return size_int (1);
1245 if (code
== VOID_TYPE
)
1247 if (pedantic
|| warn_pointer_arith
)
1248 pedwarn ("ANSI C++ forbids taking the sizeof a void type");
1249 return size_int (1);
1251 if (code
== ERROR_MARK
)
1252 return size_int (1);
1254 /* ARM $5.3.2: ``When applied to a reference, the result is the size of the
1255 referenced object.'' */
1256 if (code
== REFERENCE_TYPE
)
1257 type
= TREE_TYPE (type
);
1259 /* We couldn't find anything in the ARM or the draft standard that says,
1260 one way or the other, if doing sizeof on something that doesn't have
1261 an object associated with it is correct or incorrect. For example, if
1262 you declare `struct S { char str[16]; };', and in your program do
1263 a `sizeof (S::str)', should we flag that as an error or should we give
1264 the size of it? Since it seems like a reasonable thing to do, we'll go
1265 with giving the value. */
1266 if (code
== OFFSET_TYPE
)
1267 type
= TREE_TYPE (type
);
1269 /* @@ This also produces an error for a signature ref.
1270 In that case we should be able to do better. */
1271 if (IS_SIGNATURE (type
))
1273 error ("`sizeof' applied to a signature type");
1274 return size_int (0);
1277 if (TYPE_SIZE (type
) == 0)
1279 error ("`sizeof' applied to an incomplete type");
1280 return size_int (0);
1283 /* Convert in case a char is more than one unit. */
1284 t
= size_binop (CEIL_DIV_EXPR
, TYPE_SIZE (type
),
1285 size_int (TYPE_PRECISION (char_type_node
)));
1286 /* size_binop does not put the constant in range, so do it now. */
1287 if (TREE_CODE (t
) == INTEGER_CST
&& force_fit_type (t
, 0))
1288 TREE_CONSTANT_OVERFLOW (t
) = TREE_OVERFLOW (t
) = 1;
1293 c_sizeof_nowarn (type
)
1296 enum tree_code code
= TREE_CODE (type
);
1299 if (code
== FUNCTION_TYPE
1300 || code
== METHOD_TYPE
1301 || code
== VOID_TYPE
1302 || code
== ERROR_MARK
)
1303 return size_int (1);
1304 if (code
== REFERENCE_TYPE
)
1305 type
= TREE_TYPE (type
);
1307 if (TYPE_SIZE (type
) == 0)
1310 /* ??? Tiemann, why have any diagnostic here?
1311 There is none in the corresponding function for C. */
1312 warning ("sizeof applied to an incomplete type");
1314 return size_int (0);
1317 /* Convert in case a char is more than one unit. */
1318 t
= size_binop (CEIL_DIV_EXPR
, TYPE_SIZE (type
),
1319 size_int (TYPE_PRECISION (char_type_node
)));
1320 force_fit_type (t
, 0);
1324 /* Implement the __alignof keyword: Return the minimum required
1325 alignment of TYPE, measured in bytes. */
1331 enum tree_code code
= TREE_CODE (type
);
1334 if (code
== FUNCTION_TYPE
|| code
== METHOD_TYPE
)
1335 return size_int (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
1337 if (code
== VOID_TYPE
|| code
== ERROR_MARK
)
1338 return size_int (1);
1340 /* C++: this is really correct! */
1341 if (code
== REFERENCE_TYPE
)
1342 type
= TREE_TYPE (type
);
1344 /* @@ This also produces an error for a signature ref.
1345 In that case we should be able to do better. */
1346 if (IS_SIGNATURE (type
))
1348 error ("`__alignof' applied to a signature type");
1349 return size_int (1);
1352 t
= size_int (TYPE_ALIGN (type
) / BITS_PER_UNIT
);
1353 force_fit_type (t
, 0);
1357 /* Perform default promotions for C data used in expressions.
1358 Arrays and functions are converted to pointers;
1359 enumeral types or short or char, to int.
1360 In addition, manifest constants symbols are replaced by their values.
1362 C++: this will automatically bash references to their target type. */
1365 decay_conversion (exp
)
1368 register tree type
= TREE_TYPE (exp
);
1369 register enum tree_code code
= TREE_CODE (type
);
1371 if (code
== OFFSET_TYPE
/* || TREE_CODE (exp) == OFFSET_REF */ )
1373 if (TREE_CODE (exp
) == OFFSET_REF
)
1374 return decay_conversion (resolve_offset_ref (exp
));
1376 type
= TREE_TYPE (type
);
1377 code
= TREE_CODE (type
);
1380 if (code
== REFERENCE_TYPE
)
1382 exp
= convert_from_reference (exp
);
1383 type
= TREE_TYPE (exp
);
1384 code
= TREE_CODE (type
);
1387 /* Constants can be used directly unless they're not loadable. */
1388 if (TREE_CODE (exp
) == CONST_DECL
)
1389 exp
= DECL_INITIAL (exp
);
1390 /* Replace a nonvolatile const static variable with its value. */
1391 else if (TREE_READONLY_DECL_P (exp
))
1393 exp
= decl_constant_value (exp
);
1394 type
= TREE_TYPE (exp
);
1397 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
1398 Leave such NOP_EXPRs, since RHS is being used in non-lvalue context. */
1400 if (code
== VOID_TYPE
)
1402 error ("void value not ignored as it ought to be");
1403 return error_mark_node
;
1405 if (code
== FUNCTION_TYPE
)
1407 return build_unary_op (ADDR_EXPR
, exp
, 0);
1409 if (code
== METHOD_TYPE
)
1411 if (TREE_CODE (exp
) == OFFSET_REF
)
1413 my_friendly_assert (TREE_CODE (TREE_OPERAND (exp
, 1)) == FUNCTION_DECL
,
1415 return build_unary_op (ADDR_EXPR
, TREE_OPERAND (exp
, 1), 0);
1417 return build_unary_op (ADDR_EXPR
, exp
, 0);
1419 if (code
== ARRAY_TYPE
)
1424 int constp
, volatilep
;
1426 if (TREE_CODE (exp
) == INDIRECT_REF
)
1428 /* Stripping away the INDIRECT_REF is not the right
1429 thing to do for references... */
1430 tree inner
= TREE_OPERAND (exp
, 0);
1431 if (TREE_CODE (TREE_TYPE (inner
)) == REFERENCE_TYPE
)
1433 inner
= build1 (CONVERT_EXPR
,
1434 build_pointer_type (TREE_TYPE (TREE_TYPE (inner
))),
1436 TREE_REFERENCE_EXPR (inner
) = 1;
1438 return convert (build_pointer_type (TREE_TYPE (type
)), inner
);
1441 if (TREE_CODE (exp
) == COMPOUND_EXPR
)
1443 tree op1
= decay_conversion (TREE_OPERAND (exp
, 1));
1444 return build (COMPOUND_EXPR
, TREE_TYPE (op1
),
1445 TREE_OPERAND (exp
, 0), op1
);
1449 && ! (TREE_CODE (exp
) == CONSTRUCTOR
&& TREE_STATIC (exp
)))
1451 error ("invalid use of non-lvalue array");
1452 return error_mark_node
;
1455 constp
= volatilep
= 0;
1456 if (TREE_CODE_CLASS (TREE_CODE (exp
)) == 'r'
1457 || TREE_CODE_CLASS (TREE_CODE (exp
)) == 'd')
1459 constp
= TREE_READONLY (exp
);
1460 volatilep
= TREE_THIS_VOLATILE (exp
);
1463 restype
= TREE_TYPE (type
);
1464 if (TYPE_READONLY (type
) || TYPE_VOLATILE (type
)
1465 || constp
|| volatilep
)
1466 restype
= cp_build_type_variant (restype
,
1467 TYPE_READONLY (type
) || constp
,
1468 TYPE_VOLATILE (type
) || volatilep
);
1469 ptrtype
= build_pointer_type (restype
);
1471 if (TREE_CODE (exp
) == VAR_DECL
)
1473 /* ??? This is not really quite correct
1474 in that the type of the operand of ADDR_EXPR
1475 is not the target type of the type of the ADDR_EXPR itself.
1476 Question is, can this lossage be avoided? */
1477 adr
= build1 (ADDR_EXPR
, ptrtype
, exp
);
1478 if (mark_addressable (exp
) == 0)
1479 return error_mark_node
;
1480 TREE_CONSTANT (adr
) = staticp (exp
);
1481 TREE_SIDE_EFFECTS (adr
) = 0; /* Default would be, same as EXP. */
1484 /* This way is better for a COMPONENT_REF since it can
1485 simplify the offset for a component. */
1486 adr
= build_unary_op (ADDR_EXPR
, exp
, 1);
1487 return convert (ptrtype
, adr
);
1494 default_conversion (exp
)
1498 enum tree_code code
;
1500 exp
= decay_conversion (exp
);
1502 type
= TREE_TYPE (exp
);
1503 code
= TREE_CODE (type
);
1505 if (INTEGRAL_CODE_P (code
))
1507 tree t
= type_promotes_to (type
);
1509 return convert (t
, exp
);
1511 if (flag_traditional
1512 && TYPE_MAIN_VARIANT (type
) == float_type_node
)
1513 return convert (double_type_node
, exp
);
1519 build_object_ref (datum
, basetype
, field
)
1520 tree datum
, basetype
, field
;
1523 if (datum
== error_mark_node
)
1524 return error_mark_node
;
1526 dtype
= TREE_TYPE (datum
);
1527 if (TREE_CODE (dtype
) == REFERENCE_TYPE
)
1528 dtype
= TREE_TYPE (dtype
);
1529 if (! IS_AGGR_TYPE_CODE (TREE_CODE (dtype
)))
1531 cp_error ("request for member `%T::%D' in expression of non-aggregate type `%T'",
1532 basetype
, field
, dtype
);
1533 return error_mark_node
;
1535 else if (IS_SIGNATURE (IDENTIFIER_TYPE_VALUE (basetype
)))
1537 warning ("signature name in scope resolution ignored");
1538 return build_component_ref (datum
, field
, NULL_TREE
, 1);
1540 else if (is_aggr_typedef (basetype
, 1))
1542 tree real_basetype
= IDENTIFIER_TYPE_VALUE (basetype
);
1543 tree binfo
= binfo_or_else (real_basetype
, TREE_TYPE (datum
));
1545 return build_component_ref (build_scoped_ref (datum
, basetype
),
1548 return error_mark_node
;
1551 /* Like `build_component_ref, but uses an already found field.
1552 Must compute access for C_C_D. Otherwise, ok. */
1554 build_component_ref_1 (datum
, field
, protect
)
1558 register tree basetype
= TREE_TYPE (datum
);
1559 register enum tree_code code
= TREE_CODE (basetype
);
1562 if (code
== REFERENCE_TYPE
)
1564 datum
= convert_from_reference (datum
);
1565 basetype
= TREE_TYPE (datum
);
1566 code
= TREE_CODE (basetype
);
1569 if (! IS_AGGR_TYPE_CODE (code
))
1571 if (code
!= ERROR_MARK
)
1572 cp_error ("request for member `%D' in `%E', which is of non-aggregate type `%T'",
1573 field
, datum
, basetype
);
1574 return error_mark_node
;
1577 if (TYPE_SIZE (basetype
) == 0)
1579 incomplete_type_error (0, basetype
);
1580 return error_mark_node
;
1583 /* Look up component name in the structure type definition. */
1585 if (field
== error_mark_node
)
1586 my_friendly_abort (115);
1588 if (TREE_STATIC (field
))
1593 enum access_type access
1594 = compute_access (TYPE_BINFO (current_class_type
), field
);
1596 if (access
== access_private
)
1598 cp_error ("field `%D' is private", field
);
1599 return error_mark_node
;
1601 else if (access
== access_protected
)
1603 cp_error ("field `%D' is protected", field
);
1604 return error_mark_node
;
1608 ref
= build (COMPONENT_REF
, TREE_TYPE (field
), datum
, field
);
1610 if (TREE_READONLY (datum
) || TREE_READONLY (field
))
1611 TREE_READONLY (ref
) = 1;
1612 if (TREE_THIS_VOLATILE (datum
) || TREE_THIS_VOLATILE (field
))
1613 TREE_THIS_VOLATILE (ref
) = 1;
1614 if (DECL_MUTABLE_P (field
))
1615 TREE_READONLY (ref
) = 0;
1620 /* Given a COND_EXPR in T, return it in a form that we can, for
1621 example, use as an lvalue. This code used to be in unary_complex_lvalue,
1622 but we needed it to deal with `a = (d == c) ? b : c' expressions, where
1623 we're dealing with aggregates. So, we now call this in unary_complex_lvalue,
1624 and in build_modify_expr. The case (in particular) that led to this was
1625 with CODE == ADDR_EXPR, since it's not an lvalue when we'd get it there. */
1627 rationalize_conditional_expr (code
, t
)
1628 enum tree_code code
;
1632 build_conditional_expr (TREE_OPERAND (t
, 0),
1633 build_unary_op (code
, TREE_OPERAND (t
, 1), 0),
1634 build_unary_op (code
, TREE_OPERAND (t
, 2), 0));
1638 build_component_ref (datum
, component
, basetype_path
, protect
)
1639 tree datum
, component
, basetype_path
;
1642 register tree basetype
= TREE_TYPE (datum
);
1643 register enum tree_code code
= TREE_CODE (basetype
);
1644 register tree field
= NULL
;
1647 /* If DATUM is a COMPOUND_EXPR or COND_EXPR, move our reference inside it. */
1648 switch (TREE_CODE (datum
))
1652 tree value
= build_component_ref (TREE_OPERAND (datum
, 1), component
,
1653 basetype_path
, protect
);
1654 return build (COMPOUND_EXPR
, TREE_TYPE (value
),
1655 TREE_OPERAND (datum
, 0), value
);
1658 return build_conditional_expr
1659 (TREE_OPERAND (datum
, 0),
1660 build_component_ref (TREE_OPERAND (datum
, 1), component
,
1661 basetype_path
, protect
),
1662 build_component_ref (TREE_OPERAND (datum
, 2), component
,
1663 basetype_path
, protect
));
1666 if (code
== REFERENCE_TYPE
)
1669 /* TREE_REFERENCE_EXPRs are not converted by `convert_from_reference'.
1670 @@ Maybe that is not right. */
1671 if (TREE_REFERENCE_EXPR (datum
))
1672 datum
= build1 (INDIRECT_REF
, TREE_TYPE (basetype
), datum
);
1675 datum
= convert_from_reference (datum
);
1676 basetype
= TREE_TYPE (datum
);
1677 code
= TREE_CODE (basetype
);
1680 /* First, see if there is a field or component with name COMPONENT. */
1681 if (TREE_CODE (component
) == TREE_LIST
)
1683 my_friendly_assert (!(TREE_CHAIN (component
) == NULL_TREE
1684 && DECL_CHAIN (TREE_VALUE (component
)) == NULL_TREE
), 309);
1685 return build (COMPONENT_REF
, TREE_TYPE (component
), datum
, component
);
1688 if (TREE_CODE (component
) == TYPE_EXPR
)
1689 return build_component_type_expr (datum
, component
, NULL_TREE
, protect
);
1692 if (! IS_AGGR_TYPE_CODE (code
))
1694 if (code
!= ERROR_MARK
)
1695 cp_error ("request for member `%D' in `%E', which is of non-aggregate type `%T'",
1696 component
, datum
, basetype
);
1697 return error_mark_node
;
1700 if (TYPE_SIZE (basetype
) == 0)
1702 incomplete_type_error (0, basetype
);
1703 return error_mark_node
;
1706 if (TREE_CODE (component
) == BIT_NOT_EXPR
)
1708 if (TYPE_IDENTIFIER (basetype
) != TREE_OPERAND (component
, 0))
1710 cp_error ("destructor specifier `%T::~%T' must have matching names",
1711 basetype
, TREE_OPERAND (component
, 0));
1712 return error_mark_node
;
1714 if (! TYPE_HAS_DESTRUCTOR (basetype
))
1716 cp_error ("type `%T' has no destructor", basetype
);
1717 return error_mark_node
;
1719 return TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (basetype
), 0);
1722 /* Look up component name in the structure type definition. */
1723 if (CLASSTYPE_VFIELD (basetype
)
1724 && DECL_NAME (CLASSTYPE_VFIELD (basetype
)) == component
)
1725 /* Special-case this because if we use normal lookups in an ambiguous
1726 hierarchy, the compiler will abort (because vptr lookups are
1727 not supposed to be ambiguous. */
1728 field
= CLASSTYPE_VFIELD (basetype
);
1731 if (basetype_path
== NULL_TREE
)
1732 basetype_path
= TYPE_BINFO (basetype
);
1733 field
= lookup_field (basetype_path
, component
,
1734 protect
&& ! VFIELD_NAME_P (component
), 0);
1735 if (field
== error_mark_node
)
1736 return error_mark_node
;
1738 if (field
== NULL_TREE
)
1740 /* Not found as a data field, look for it as a method. If found,
1741 then if this is the only possible one, return it, else
1742 report ambiguity error. */
1743 tree fndecls
= lookup_fnfields (basetype_path
, component
, 1);
1744 if (fndecls
== error_mark_node
)
1745 return error_mark_node
;
1748 if (TREE_CHAIN (fndecls
) == NULL_TREE
1749 && DECL_CHAIN (TREE_VALUE (fndecls
)) == NULL_TREE
)
1751 enum access_type access
;
1754 /* Unique, so use this one now. */
1755 basetype
= TREE_PURPOSE (fndecls
);
1756 fndecl
= TREE_VALUE (fndecls
);
1757 access
= compute_access (TREE_PURPOSE (fndecls
), fndecl
);
1758 if (access
== access_public
)
1760 if (DECL_VINDEX (fndecl
)
1761 && ! resolves_to_fixed_type_p (datum
, 0))
1763 tree addr
= build_unary_op (ADDR_EXPR
, datum
, 0);
1764 addr
= convert_pointer_to (DECL_CONTEXT (fndecl
), addr
);
1765 datum
= build_indirect_ref (addr
, NULL_PTR
);
1766 my_friendly_assert (datum
!= error_mark_node
, 310);
1767 fndecl
= build_vfn_ref (&addr
, datum
, DECL_VINDEX (fndecl
));
1769 assemble_external (fndecl
);
1772 if (access
== access_protected
)
1773 cp_error ("member function `%D' is protected", fndecl
);
1775 cp_error ("member function `%D' is private", fndecl
);
1776 return error_mark_node
;
1780 /* Just act like build_offset_ref, since the object does
1781 not matter unless we're actually calling the function. */
1784 for (t
= TREE_VALUE (fndecls
); t
; t
= DECL_CHAIN (t
))
1785 assemble_external (t
);
1787 t
= build_tree_list (error_mark_node
, fndecls
);
1788 TREE_TYPE (t
) = build_offset_type (basetype
,
1795 if (component
== ansi_opname
[(int) TYPE_EXPR
])
1796 cp_error ("`%#T' has no such type conversion operator", basetype
);
1799 cp_error ("`%#T' has no member named `%D'", basetype
, component
);
1800 return error_mark_node
;
1802 else if (TREE_TYPE (field
) == error_mark_node
)
1803 return error_mark_node
;
1805 if (TREE_CODE (field
) != FIELD_DECL
)
1807 if (TREE_CODE (field
) == TYPE_DECL
)
1809 cp_error ("invalid use of type decl `%#D' as expression", field
);
1810 return error_mark_node
;
1812 if (DECL_RTL (field
) != 0)
1813 assemble_external (field
);
1814 TREE_USED (field
) = 1;
1819 if (DECL_FIELD_CONTEXT (field
) != basetype
1820 && TYPE_USES_COMPLEX_INHERITANCE (basetype
))
1822 tree addr
= build_unary_op (ADDR_EXPR
, datum
, 0);
1823 if (integer_zerop (addr
))
1825 error ("invalid reference to NULL ptr, use ptr-to-member instead");
1826 return error_mark_node
;
1828 addr
= convert_pointer_to (DECL_FIELD_CONTEXT (field
), addr
);
1829 datum
= build_indirect_ref (addr
, NULL_PTR
);
1830 my_friendly_assert (datum
!= error_mark_node
, 311);
1832 ref
= fold (build (COMPONENT_REF
, TREE_TYPE (field
),
1833 break_out_cleanups (datum
), field
));
1835 if (TREE_READONLY (datum
) || TREE_READONLY (field
))
1836 TREE_READONLY (ref
) = 1;
1837 if (TREE_THIS_VOLATILE (datum
) || TREE_THIS_VOLATILE (field
))
1838 TREE_THIS_VOLATILE (ref
) = 1;
1839 if (DECL_MUTABLE_P (field
))
1840 TREE_READONLY (ref
) = 0;
1845 /* Given an expression PTR for a pointer, return an expression
1846 for the value pointed to.
1847 ERRORSTRING is the name of the operator to appear in error messages.
1849 This function may need to overload OPERATOR_FNNAME.
1850 Must also handle REFERENCE_TYPEs for C++. */
1853 build_x_indirect_ref (ptr
, errorstring
)
1857 tree rval
= build_opfncall (INDIRECT_REF
, LOOKUP_NORMAL
, ptr
, NULL_TREE
, NULL_TREE
);
1860 return build_indirect_ref (ptr
, errorstring
);
1864 build_indirect_ref (ptr
, errorstring
)
1868 register tree pointer
= (TREE_CODE (TREE_TYPE (ptr
)) == REFERENCE_TYPE
?
1869 ptr
: default_conversion (ptr
));
1870 register tree type
= TREE_TYPE (pointer
);
1872 if (ptr
== current_class_decl
)
1875 if (IS_AGGR_TYPE (type
))
1877 ptr
= build_expr_type_conversion (WANT_POINTER
, pointer
, 1);
1882 type
= TREE_TYPE (pointer
);
1886 if (TREE_CODE (type
) == POINTER_TYPE
|| TREE_CODE (type
) == REFERENCE_TYPE
)
1888 if (TREE_CODE (pointer
) == ADDR_EXPR
1889 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (pointer
, 0)))
1890 == TYPE_MAIN_VARIANT (TREE_TYPE (type
)))
1891 && (TREE_READONLY (TREE_OPERAND (pointer
, 0))
1892 == TYPE_READONLY (TREE_TYPE (type
)))
1893 && (TREE_THIS_VOLATILE (TREE_OPERAND (pointer
, 0))
1894 == TYPE_VOLATILE (TREE_TYPE (type
))))
1895 return TREE_OPERAND (pointer
, 0);
1898 tree t
= TREE_TYPE (type
);
1899 register tree ref
= build1 (INDIRECT_REF
,
1900 TYPE_MAIN_VARIANT (t
), pointer
);
1902 TREE_READONLY (ref
) = TYPE_READONLY (t
);
1903 TREE_THIS_VOLATILE (ref
) = TYPE_VOLATILE (t
);
1904 TREE_SIDE_EFFECTS (ref
)
1905 = TYPE_VOLATILE (t
) || TREE_SIDE_EFFECTS (pointer
);
1909 /* `pointer' won't be an error_mark_node if we were given a
1910 pointer to member, so it's cool to check for this here. */
1911 else if (TYPE_PTRMEMFUNC_P (type
))
1912 error ("invalid use of `%s' on pointer to member function", errorstring
);
1913 else if (TREE_CODE (type
) == RECORD_TYPE
1914 && (IS_SIGNATURE_POINTER (type
) || IS_SIGNATURE_REFERENCE (type
)))
1915 error ("cannot dereference signature pointer/reference");
1916 else if (pointer
!= error_mark_node
)
1919 error ("invalid type argument of `%s'", errorstring
);
1921 error ("invalid type argument");
1923 return error_mark_node
;
1926 /* This handles expressions of the form "a[i]", which denotes
1929 This is logically equivalent in C to *(a+i), but we may do it differently.
1930 If A is a variable or a member, we generate a primitive ARRAY_REF.
1931 This avoids forcing the array out of registers, and can work on
1932 arrays that are not lvalues (for example, members of structures returned
1935 If INDEX is of some user-defined type, it must be converted to
1936 integer type. Otherwise, to make a compatible PLUS_EXPR, it
1937 will inherit the type of the array, which will be some pointer type. */
1940 build_x_array_ref (array
, index
)
1943 tree rval
= build_opfncall (ARRAY_REF
, LOOKUP_NORMAL
, array
, index
, NULL_TREE
);
1946 return build_array_ref (array
, index
);
1950 build_array_ref (array
, idx
)
1957 error ("subscript missing in array reference");
1958 return error_mark_node
;
1961 if (TREE_TYPE (array
) == error_mark_node
1962 || TREE_TYPE (idx
) == error_mark_node
)
1963 return error_mark_node
;
1965 itype
= TREE_TYPE (idx
);
1967 if (TREE_CODE (TREE_TYPE (array
)) == ARRAY_TYPE
1968 && TREE_CODE (array
) != INDIRECT_REF
)
1972 /* Subscripting with type char is likely to lose
1973 on a machine where chars are signed.
1974 So warn on any machine, but optionally.
1975 Don't warn for unsigned char since that type is safe.
1976 Don't warn for signed char because anyone who uses that
1977 must have done so deliberately. */
1978 if (warn_char_subscripts
1979 && TYPE_MAIN_VARIANT (TREE_TYPE (idx
)) == char_type_node
)
1980 warning ("array subscript has type `char'");
1982 /* Apply default promotions *after* noticing character types. */
1983 idx
= default_conversion (idx
);
1985 if (TREE_CODE (TREE_TYPE (idx
)) != INTEGER_TYPE
)
1987 error ("array subscript is not an integer");
1988 return error_mark_node
;
1991 /* An array that is indexed by a non-constant
1992 cannot be stored in a register; we must be able to do
1993 address arithmetic on its address.
1994 Likewise an array of elements of variable size. */
1995 if (TREE_CODE (idx
) != INTEGER_CST
1996 || (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array
))) != 0
1997 && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array
)))) != INTEGER_CST
))
1999 if (mark_addressable (array
) == 0)
2000 return error_mark_node
;
2002 /* An array that is indexed by a constant value which is not within
2003 the array bounds cannot be stored in a register either; because we
2004 would get a crash in store_bit_field/extract_bit_field when trying
2005 to access a non-existent part of the register. */
2006 if (TREE_CODE (idx
) == INTEGER_CST
2007 && TYPE_VALUES (TREE_TYPE (array
))
2008 && ! int_fits_type_p (idx
, TYPE_VALUES (TREE_TYPE (array
))))
2010 if (mark_addressable (array
) == 0)
2011 return error_mark_node
;
2014 if (pedantic
&& !lvalue_p (array
))
2015 pedwarn ("ANSI C++ forbids subscripting non-lvalue array");
2017 /* Note in C++ it is valid to subscript a `register' array, since
2018 it is valid to take the address of something with that
2019 storage specification. */
2023 while (TREE_CODE (foo
) == COMPONENT_REF
)
2024 foo
= TREE_OPERAND (foo
, 0);
2025 if (TREE_CODE (foo
) == VAR_DECL
&& DECL_REGISTER (foo
))
2026 warning ("subscripting array declared `register'");
2029 type
= TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (array
)));
2030 rval
= build (ARRAY_REF
, type
, array
, idx
);
2031 /* Array ref is const/volatile if the array elements are
2032 or if the array is.. */
2033 TREE_READONLY (rval
)
2034 |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array
)))
2035 | TREE_READONLY (array
));
2036 TREE_SIDE_EFFECTS (rval
)
2037 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array
)))
2038 | TREE_SIDE_EFFECTS (array
));
2039 TREE_THIS_VOLATILE (rval
)
2040 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array
)))
2041 /* This was added by rms on 16 Nov 91.
2042 It fixes vol struct foo *a; a->elts[1]
2043 in an inline function.
2044 Hope it doesn't break something else. */
2045 | TREE_THIS_VOLATILE (array
));
2046 return require_complete_type (fold (rval
));
2050 tree ar
= default_conversion (array
);
2051 tree ind
= default_conversion (idx
);
2053 /* Put the integer in IND to simplify error checking. */
2054 if (TREE_CODE (TREE_TYPE (ar
)) == INTEGER_TYPE
)
2061 if (ar
== error_mark_node
)
2064 if (TREE_CODE (TREE_TYPE (ar
)) != POINTER_TYPE
)
2066 error ("subscripted value is neither array nor pointer");
2067 return error_mark_node
;
2069 if (TREE_CODE (TREE_TYPE (ind
)) != INTEGER_TYPE
)
2071 error ("array subscript is not an integer");
2072 return error_mark_node
;
2075 return build_indirect_ref (build_binary_op_nodefault (PLUS_EXPR
, ar
, ind
, PLUS_EXPR
),
2080 /* Build a function call to function FUNCTION with parameters PARAMS.
2081 PARAMS is a list--a chain of TREE_LIST nodes--in which the
2082 TREE_VALUE of each node is a parameter-expression.
2083 FUNCTION's data type may be a function type or a pointer-to-function.
2085 For C++: If FUNCTION's data type is a TREE_LIST, then the tree list
2086 is the list of possible methods that FUNCTION could conceivably
2087 be. If the list of methods comes from a class, then it will be
2088 a list of lists (where each element is associated with the class
2089 that produced it), otherwise it will be a simple list (for
2090 functions overloaded in global scope).
2092 In the first case, TREE_VALUE (function) is the head of one of those
2093 lists, and TREE_PURPOSE is the name of the function.
2095 In the second case, TREE_PURPOSE (function) is the function's
2098 DECL is the class instance variable, usually CURRENT_CLASS_DECL. */
2101 * [eichin:19911015.1726EST] actually return a possibly incomplete
2105 build_x_function_call (function
, params
, decl
)
2106 tree function
, params
, decl
;
2111 if (function
== error_mark_node
)
2112 return error_mark_node
;
2114 type
= TREE_TYPE (function
);
2115 is_method
= ((TREE_CODE (function
) == TREE_LIST
2116 && current_class_type
!= NULL_TREE
2117 && IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (function
)) == function
)
2118 || TREE_CODE (function
) == IDENTIFIER_NODE
2119 || TREE_CODE (type
) == METHOD_TYPE
2120 || TYPE_PTRMEMFUNC_P (type
));
2122 /* Handle methods, friends, and overloaded functions, respectively. */
2125 if (TREE_CODE (function
) == FUNCTION_DECL
)
2127 if (DECL_NAME (function
))
2128 function
= DECL_NAME (function
);
2130 function
= TYPE_IDENTIFIER (DECL_CLASS_CONTEXT (function
));
2132 else if (TREE_CODE (function
) == TREE_LIST
)
2135 if (TREE_CODE (TREE_VALUE (function
)) == TREE_LIST
)
2136 function
= TREE_PURPOSE (TREE_VALUE (function
));
2138 function
= TREE_PURPOSE (function
);
2140 my_friendly_assert (TREE_CODE (TREE_VALUE (function
)) == FUNCTION_DECL
, 312);
2141 function
= TREE_PURPOSE (function
);
2144 else if (TREE_CODE (function
) != IDENTIFIER_NODE
)
2146 if (TREE_CODE (function
) == OFFSET_REF
)
2148 if (TREE_OPERAND (function
, 0))
2149 decl
= TREE_OPERAND (function
, 0);
2151 /* Call via a pointer to member function. */
2152 if (decl
== NULL_TREE
)
2154 error ("pointer to member function called, but not in class scope");
2155 return error_mark_node
;
2157 /* What other type of POINTER_TYPE could this be? */
2158 if (TREE_CODE (TREE_TYPE (function
)) != POINTER_TYPE
2159 && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (function
))
2160 && TREE_CODE (function
) != OFFSET_REF
)
2161 function
= build (OFFSET_REF
, TREE_TYPE (type
), NULL_TREE
, function
);
2165 /* this is an abbreviated method call.
2166 must go through here in case it is a virtual function.
2167 @@ Perhaps this could be optimized. */
2169 if (decl
== NULL_TREE
)
2171 if (current_class_type
== NULL_TREE
)
2173 error ("object missing in call to method `%s'",
2174 IDENTIFIER_POINTER (function
));
2175 return error_mark_node
;
2177 /* Yow: call from a static member function. */
2178 decl
= build1 (NOP_EXPR
, build_pointer_type (current_class_type
),
2180 decl
= build_indirect_ref (decl
, NULL_PTR
);
2183 return build_method_call (decl
, function
, params
,
2184 NULL_TREE
, LOOKUP_NORMAL
);
2186 else if (TREE_CODE (function
) == COMPONENT_REF
2187 && type
== unknown_type_node
)
2189 /* Should we undo what was done in build_component_ref? */
2190 if (TREE_CODE (TREE_PURPOSE (TREE_OPERAND (function
, 1))) == TREE_VEC
)
2191 /* Get the name that build_component_ref hid. */
2192 function
= DECL_NAME (TREE_VALUE (TREE_OPERAND (function
, 1)));
2194 function
= TREE_PURPOSE (TREE_OPERAND (function
, 1));
2195 return build_method_call (decl
, function
, params
,
2196 NULL_TREE
, LOOKUP_NORMAL
);
2198 else if (TREE_CODE (function
) == TREE_LIST
)
2200 if (TREE_VALUE (function
) == NULL_TREE
)
2202 cp_error ("function `%D' declared overloaded, but no definitions appear with which to resolve it?!?",
2203 TREE_PURPOSE (function
));
2204 return error_mark_node
;
2208 tree val
= TREE_VALUE (function
);
2210 if (TREE_CODE (val
) == TEMPLATE_DECL
)
2211 return build_overload_call_maybe
2212 (function
, params
, LOOKUP_COMPLAIN
, (struct candidate
*)0);
2213 else if (DECL_CHAIN (val
) != NULL_TREE
)
2214 return build_overload_call
2215 (function
, params
, LOOKUP_COMPLAIN
, (struct candidate
*)0);
2217 my_friendly_abort (360);
2222 if (TREE_CODE (function
) == OFFSET_REF
)
2224 /* If the component is a data element (or a virtual function), we play
2225 games here to make things work. */
2228 if (TREE_OPERAND (function
, 0))
2229 decl
= TREE_OPERAND (function
, 0);
2233 decl_addr
= build_unary_op (ADDR_EXPR
, decl
, 0);
2234 function
= get_member_function_from_ptrfunc (&decl_addr
,
2235 TREE_OPERAND (function
, 1));
2236 params
= tree_cons (NULL_TREE
, decl_addr
, params
);
2237 return build_function_call (function
, params
);
2240 type
= TREE_TYPE (function
);
2241 if (type
!= error_mark_node
)
2243 if (TREE_CODE (type
) == REFERENCE_TYPE
)
2244 type
= TREE_TYPE (type
);
2246 if (TYPE_LANG_SPECIFIC (type
) && TYPE_OVERLOADS_CALL_EXPR (type
))
2247 return build_opfncall (CALL_EXPR
, LOOKUP_NORMAL
, function
, params
, NULL_TREE
);
2252 tree fntype
= TREE_TYPE (function
);
2255 /* Explicitly named method? */
2256 if (TREE_CODE (function
) == FUNCTION_DECL
)
2257 ctypeptr
= build_pointer_type (DECL_CLASS_CONTEXT (function
));
2258 /* Expression with ptr-to-method type? It could either be a plain
2259 usage, or it might be a case where the ptr-to-method is being
2260 passed in as an argument. */
2261 else if (TYPE_PTRMEMFUNC_P (fntype
))
2263 tree rec
= TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (fntype
)));
2264 ctypeptr
= build_pointer_type (rec
);
2266 /* Unexpected node type? */
2268 my_friendly_abort (116);
2269 if (decl
== NULL_TREE
)
2271 if (current_function_decl
2272 && DECL_STATIC_FUNCTION_P (current_function_decl
))
2273 error ("invalid call to member function needing `this' in static member function scope");
2275 error ("pointer to member function called, but not in class scope");
2276 return error_mark_node
;
2278 if (TREE_CODE (TREE_TYPE (decl
)) != POINTER_TYPE
2279 && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (decl
)))
2281 decl
= build_unary_op (ADDR_EXPR
, decl
, 0);
2282 decl
= convert_pointer_to (TREE_TYPE (ctypeptr
), decl
);
2285 decl
= build_c_cast (ctypeptr
, decl
, 0);
2286 params
= tree_cons (NULL_TREE
, decl
, params
);
2289 return build_function_call (function
, params
);
2292 /* Resolve a pointer to member function. INSTANCE is the object
2293 instance to use, if the member points to a virtual member. */
2296 get_member_function_from_ptrfunc (instance_ptrptr
, function
)
2297 tree
*instance_ptrptr
;
2300 if (TREE_CODE (function
) == OFFSET_REF
)
2302 function
= TREE_OPERAND (function
, 1);
2305 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (function
)))
2307 tree fntype
, index
, e1
, delta
, delta2
, e2
, e3
, aref
, vtbl
;
2310 tree instance_ptr
= *instance_ptrptr
;
2312 if (TREE_SIDE_EFFECTS (instance_ptr
))
2313 instance_ptr
= save_expr (instance_ptr
);
2315 if (TREE_SIDE_EFFECTS (function
))
2316 function
= save_expr (function
);
2318 fntype
= TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (function
));
2319 index
= save_expr (build_component_ref (function
,
2322 e1
= build (GT_EXPR
, boolean_type_node
, index
,
2323 convert (delta_type_node
, integer_zero_node
));
2324 delta
= convert (ptrdiff_type_node
,
2325 build_component_ref (function
, delta_identifier
, 0, 0));
2326 delta2
= DELTA2_FROM_PTRMEMFUNC (function
);
2328 /* convert down to the right base, before using the instance. */
2330 = convert_pointer_to_real (TYPE_METHOD_BASETYPE (TREE_TYPE (fntype
)),
2332 if (instance
== error_mark_node
)
2335 vtbl
= convert_pointer_to (ptr_type_node
, instance
);
2338 build_pointer_type (build_pointer_type (vtable_entry_type
)),
2339 vtbl
, convert (ptrdiff_type_node
, delta2
));
2340 vtbl
= build_indirect_ref (vtbl
, NULL_PTR
);
2341 aref
= build_array_ref (vtbl
, build_binary_op (MINUS_EXPR
,
2343 integer_one_node
, 1));
2344 if (! flag_vtable_thunks
)
2346 aref
= save_expr (aref
);
2348 /* Save the intermediate result in a SAVE_EXPR so we don't have to
2349 compute each component of the virtual function pointer twice. */
2350 if (/* !building_cleanup && */ TREE_CODE (aref
) == INDIRECT_REF
)
2351 TREE_OPERAND (aref
, 0) = save_expr (TREE_OPERAND (aref
, 0));
2353 delta
= build_binary_op (PLUS_EXPR
,
2354 build_conditional_expr (e1
, build_component_ref (aref
, delta_identifier
, 0, 0), integer_zero_node
),
2358 *instance_ptrptr
= build (PLUS_EXPR
, TREE_TYPE (instance_ptr
),
2359 instance_ptr
, delta
);
2360 if (flag_vtable_thunks
)
2363 e2
= build_component_ref (aref
, pfn_identifier
, 0, 0);
2365 e3
= PFN_FROM_PTRMEMFUNC (function
);
2366 TREE_TYPE (e2
) = TREE_TYPE (e3
);
2367 function
= build_conditional_expr (e1
, e2
, e3
);
2369 /* Make sure this doesn't get evaluated first inside one of the
2370 branches of the COND_EXPR. */
2371 if (TREE_CODE (instance_ptr
) == SAVE_EXPR
)
2372 function
= build (COMPOUND_EXPR
, TREE_TYPE (function
),
2373 instance_ptr
, function
);
2379 build_function_call_real (function
, params
, require_complete
, flags
)
2380 tree function
, params
;
2381 int require_complete
, flags
;
2383 register tree fntype
, fndecl
;
2384 register tree value_type
;
2385 register tree coerced_params
;
2386 tree name
= NULL_TREE
, assembler_name
= NULL_TREE
;
2389 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
2390 Strip such NOP_EXPRs, since FUNCTION is used in non-lvalue context. */
2391 if (TREE_CODE (function
) == NOP_EXPR
2392 && TREE_TYPE (function
) == TREE_TYPE (TREE_OPERAND (function
, 0)))
2393 function
= TREE_OPERAND (function
, 0);
2395 if (TREE_CODE (function
) == FUNCTION_DECL
)
2397 name
= DECL_NAME (function
);
2398 assembler_name
= DECL_ASSEMBLER_NAME (function
);
2400 GNU_xref_call (current_function_decl
,
2401 IDENTIFIER_POINTER (name
? name
2402 : TYPE_IDENTIFIER (DECL_CLASS_CONTEXT (function
))));
2403 assemble_external (function
);
2406 /* Convert anything with function type to a pointer-to-function. */
2409 && IDENTIFIER_LENGTH (name
) == 4
2410 && ! strcmp (IDENTIFIER_POINTER (name
), "main")
2411 && DECL_CONTEXT (function
) == NULL_TREE
)
2413 pedwarn ("ANSI C++ forbids calling `main' from within program");
2416 if (pedantic
&& DECL_THIS_INLINE (function
) && ! DECL_INITIAL (function
)
2417 && ! DECL_ARTIFICIAL (function
)
2418 && ! DECL_PENDING_INLINE_INFO (function
))
2419 cp_pedwarn ("inline function `%#D' called before definition",
2422 /* Differs from default_conversion by not setting TREE_ADDRESSABLE
2423 (because calling an inline function does not mean the function
2424 needs to be separately compiled). */
2426 if (DECL_INLINE (function
))
2428 /* Is it a synthesized method that needs to be synthesized? */
2429 if (DECL_ARTIFICIAL (function
) && ! flag_no_inline
2430 && ! DECL_INITIAL (function
)
2431 /* Kludge: don't synthesize for default args. */
2432 && current_function_decl
)
2433 synthesize_method (function
);
2435 fntype
= build_type_variant (TREE_TYPE (function
),
2436 TREE_READONLY (function
),
2437 TREE_THIS_VOLATILE (function
));
2438 function
= build1 (ADDR_EXPR
, build_pointer_type (fntype
), function
);
2442 assemble_external (function
);
2443 TREE_USED (function
) = 1;
2444 function
= default_conversion (function
);
2451 /* Convert anything with function type to a pointer-to-function. */
2452 if (function
== error_mark_node
)
2453 return error_mark_node
;
2454 function
= default_conversion (function
);
2457 fntype
= TREE_TYPE (function
);
2459 if (TYPE_PTRMEMFUNC_P (fntype
))
2461 tree instance_ptr
= build_unary_op (ADDR_EXPR
, C_C_D
, 0);
2462 fntype
= TYPE_PTRMEMFUNC_FN_TYPE (fntype
);
2463 function
= get_member_function_from_ptrfunc (&instance_ptr
, function
);
2466 is_method
= (TREE_CODE (fntype
) == POINTER_TYPE
2467 && TREE_CODE (TREE_TYPE (fntype
)) == METHOD_TYPE
);
2469 if (!((TREE_CODE (fntype
) == POINTER_TYPE
2470 && TREE_CODE (TREE_TYPE (fntype
)) == FUNCTION_TYPE
)
2473 cp_error ("`%E' cannot be used as a function", function
);
2474 return error_mark_node
;
2477 /* fntype now gets the type of function pointed to. */
2478 fntype
= TREE_TYPE (fntype
);
2480 /* Convert the parameters to the types declared in the
2481 function prototype, or apply default promotions. */
2483 if (flags
& LOOKUP_COMPLAIN
)
2484 coerced_params
= convert_arguments (NULL_TREE
, TYPE_ARG_TYPES (fntype
),
2485 params
, fndecl
, LOOKUP_NORMAL
);
2487 coerced_params
= convert_arguments (NULL_TREE
, TYPE_ARG_TYPES (fntype
),
2490 if (coerced_params
== error_mark_node
)
2491 if (flags
& LOOKUP_SPECULATIVELY
)
2494 return error_mark_node
;
2496 /* Check for errors in format strings. */
2498 if (warn_format
&& (name
|| assembler_name
))
2499 check_function_format (name
, assembler_name
, coerced_params
);
2501 /* Recognize certain built-in functions so we can make tree-codes
2502 other than CALL_EXPR. We do this when it enables fold-const.c
2503 to do something useful. */
2505 if (TREE_CODE (function
) == ADDR_EXPR
2506 && TREE_CODE (TREE_OPERAND (function
, 0)) == FUNCTION_DECL
2507 && DECL_BUILT_IN (TREE_OPERAND (function
, 0)))
2508 switch (DECL_FUNCTION_CODE (TREE_OPERAND (function
, 0)))
2513 if (coerced_params
== 0)
2514 return integer_zero_node
;
2515 return build_unary_op (ABS_EXPR
, TREE_VALUE (coerced_params
), 0);
2519 value_type
= TREE_TYPE (fntype
) ? TREE_TYPE (fntype
) : void_type_node
;
2521 register tree result
=
2522 build (CALL_EXPR
, value_type
,
2523 function
, coerced_params
, NULL_TREE
);
2525 TREE_SIDE_EFFECTS (result
) = 1;
2527 if (! require_complete
)
2528 return convert_from_reference (result
);
2529 if (value_type
== void_type_node
)
2531 result
= require_complete_type (result
);
2532 return convert_from_reference (result
);
2537 build_function_call (function
, params
)
2538 tree function
, params
;
2540 return build_function_call_real (function
, params
, 1, LOOKUP_NORMAL
);
2544 build_function_call_maybe (function
, params
)
2545 tree function
, params
;
2547 return build_function_call_real (function
, params
, 0, 0);
2551 /* Convert the actual parameter expressions in the list VALUES
2552 to the types in the list TYPELIST.
2553 If parmdecls is exhausted, or when an element has NULL as its type,
2554 perform the default conversions.
2556 RETURN_LOC is the location of the return value, if known, NULL_TREE
2557 otherwise. This is useful in the case where we can avoid creating
2558 a temporary variable in the case where we can initialize the return
2559 value directly. If we are not eliding constructors, then we set this
2560 to NULL_TREE to avoid this avoidance.
2562 NAME is an IDENTIFIER_NODE or 0. It is used only for error messages.
2564 This is also where warnings about wrong number of args are generated.
2566 Return a list of expressions for the parameters as converted.
2568 Both VALUES and the returned value are chains of TREE_LIST nodes
2569 with the elements of the list in the TREE_VALUE slots of those nodes.
2571 In C++, unspecified trailing parameters can be filled in with their
2572 default arguments, if such were specified. Do so here. */
2575 convert_arguments (return_loc
, typelist
, values
, fndecl
, flags
)
2576 tree return_loc
, typelist
, values
, fndecl
;
2579 extern tree gc_protect_fndecl
;
2580 register tree typetail
, valtail
;
2581 register tree result
= NULL_TREE
;
2585 if (! flag_elide_constructors
)
2590 if (TREE_CODE (TREE_TYPE (fndecl
)) == METHOD_TYPE
)
2592 if (DECL_NAME (fndecl
) == NULL_TREE
2593 || IDENTIFIER_HAS_TYPE_VALUE (DECL_NAME (fndecl
)))
2594 called_thing
= "constructor";
2596 called_thing
= "member function";
2599 called_thing
= "function";
2602 for (valtail
= values
, typetail
= typelist
;
2604 valtail
= TREE_CHAIN (valtail
), i
++)
2606 register tree type
= typetail
? TREE_VALUE (typetail
) : 0;
2607 register tree val
= TREE_VALUE (valtail
);
2609 if (val
== error_mark_node
)
2610 return error_mark_node
;
2612 if (type
== void_type_node
)
2616 char *buf
= (char *)alloca (40 + strlen (called_thing
));
2617 sprintf (buf
, "too many arguments to %s `%%s'", called_thing
);
2618 error_with_decl (fndecl
, buf
);
2619 error ("at this point in file");
2622 error ("too many arguments to function");
2623 /* In case anybody wants to know if this argument
2626 TREE_TYPE (tree_last (result
)) = error_mark_node
;
2630 /* The tree type of the parameter being passed may not yet be
2631 known. In this case, its type is TYPE_UNKNOWN, and will
2632 be instantiated by the type given by TYPE. If TYPE
2633 is also NULL, the tree type of VAL is ERROR_MARK_NODE. */
2634 if (type
&& type_unknown_p (val
))
2635 val
= require_instantiated_type (type
, val
, integer_zero_node
);
2636 else if (type_unknown_p (val
))
2638 /* Strip the `&' from an overloaded FUNCTION_DECL. */
2639 if (TREE_CODE (val
) == ADDR_EXPR
)
2640 val
= TREE_OPERAND (val
, 0);
2641 if (TREE_CODE (val
) == TREE_LIST
2642 && TREE_CHAIN (val
) == NULL_TREE
2643 && TREE_TYPE (TREE_VALUE (val
)) != NULL_TREE
2644 && (TREE_TYPE (val
) == unknown_type_node
2645 || DECL_CHAIN (TREE_VALUE (val
)) == NULL_TREE
))
2646 /* Instantiates automatically. */
2647 val
= TREE_VALUE (val
);
2650 error ("insufficient type information in parameter list");
2651 val
= integer_zero_node
;
2654 else if (TREE_CODE (val
) == OFFSET_REF
2655 && TREE_CODE (TREE_TYPE (val
)) == METHOD_TYPE
)
2657 /* This is unclean. Should be handled elsewhere. */
2658 val
= build_unary_op (ADDR_EXPR
, val
, 0);
2660 else if (TREE_CODE (val
) == OFFSET_REF
)
2661 val
= resolve_offset_ref (val
);
2665 /* This code forces the assumption that if we have a ptr-to-func
2666 type in an arglist, that every routine that wants to check
2667 its validity has done so, and thus we need not do any
2668 more conversion. I don't remember why this is necessary. */
2669 else if (TREE_CODE (ttype
) == FUNCTION_TYPE
2671 || TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
2672 || TREE_CODE (TREE_TYPE (type
)) == VOID_TYPE
))
2674 type
= build_pointer_type (ttype
);
2679 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
2680 Strip such NOP_EXPRs, since VAL is used in non-lvalue context. */
2681 if (TREE_CODE (val
) == NOP_EXPR
2682 && TREE_TYPE (val
) == TREE_TYPE (TREE_OPERAND (val
, 0))
2683 && (type
== 0 || TREE_CODE (type
) != REFERENCE_TYPE
))
2684 val
= TREE_OPERAND (val
, 0);
2686 if (type
== 0 || TREE_CODE (type
) != REFERENCE_TYPE
)
2688 if (TREE_CODE (TREE_TYPE (val
)) == ARRAY_TYPE
2689 || TREE_CODE (TREE_TYPE (val
)) == FUNCTION_TYPE
2690 || TREE_CODE (TREE_TYPE (val
)) == METHOD_TYPE
)
2691 val
= default_conversion (val
);
2693 val
= require_complete_type (val
);
2696 if (val
== error_mark_node
)
2697 return error_mark_node
;
2701 /* Formal parm type is specified by a function prototype. */
2704 if (TYPE_SIZE (type
) == 0)
2706 error ("parameter type of called function is incomplete");
2711 #if 0 && defined (PROMOTE_PROTOTYPES)
2712 /* This breaks user-defined conversions. */
2713 /* Rather than truncating and then reextending,
2714 convert directly to int, if that's the type we will want. */
2715 if (! flag_traditional
2716 && (TREE_CODE (type
) == INTEGER_TYPE
2717 || TREE_CODE (type
) == ENUMERAL_TYPE
)
2718 && (TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
)))
2719 type
= integer_type_node
;
2721 parmval
= convert_for_initialization (return_loc
, type
, val
, flags
,
2722 "argument passing", fndecl
, i
);
2723 #ifdef PROMOTE_PROTOTYPES
2724 if ((TREE_CODE (type
) == INTEGER_TYPE
2725 || TREE_CODE (type
) == ENUMERAL_TYPE
)
2726 && (TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
)))
2727 parmval
= default_conversion (parmval
);
2731 if (parmval
== error_mark_node
)
2732 return error_mark_node
;
2734 result
= tree_cons (NULL_TREE
, parmval
, result
);
2738 if (TREE_CODE (TREE_TYPE (val
)) == REFERENCE_TYPE
)
2739 val
= convert_from_reference (val
);
2741 if (TREE_CODE (TREE_TYPE (val
)) == REAL_TYPE
2742 && (TYPE_PRECISION (TREE_TYPE (val
))
2743 < TYPE_PRECISION (double_type_node
)))
2744 /* Convert `float' to `double'. */
2745 result
= tree_cons (NULL_TREE
, convert (double_type_node
, val
), result
);
2746 else if (TYPE_LANG_SPECIFIC (TREE_TYPE (val
))
2747 && ! TYPE_HAS_TRIVIAL_INIT_REF (TREE_TYPE (val
)))
2749 cp_warning ("cannot pass objects of type `%T' through `...'",
2751 result
= tree_cons (NULL_TREE
, val
, result
);
2754 /* Convert `short' and `char' to full-size `int'. */
2755 result
= tree_cons (NULL_TREE
, default_conversion (val
), result
);
2759 /* There are certain functions for which we don't need
2760 to protect our arguments. GC_PROTECT_FNDECL is one. */
2761 && fndecl
!= gc_protect_fndecl
2762 && type_needs_gc_entry (TREE_TYPE (TREE_VALUE (result
)))
2763 && ! value_safe_from_gc (NULL_TREE
, TREE_VALUE (result
)))
2764 /* This will build a temporary variable whose cleanup is
2765 to clear the obstack entry. */
2766 TREE_VALUE (result
) = protect_value_from_gc (NULL_TREE
,
2767 TREE_VALUE (result
));
2770 typetail
= TREE_CHAIN (typetail
);
2773 if (typetail
!= 0 && typetail
!= void_list_node
)
2775 /* See if there are default arguments that can be used */
2776 if (TREE_PURPOSE (typetail
))
2778 for (; typetail
!= void_list_node
; ++i
)
2780 tree type
= TREE_VALUE (typetail
);
2781 tree val
= break_out_target_exprs (TREE_PURPOSE (typetail
));
2784 if (val
== NULL_TREE
)
2785 parmval
= error_mark_node
;
2786 else if (TREE_CODE (val
) == CONSTRUCTOR
)
2788 parmval
= digest_init (type
, val
, (tree
*)0);
2789 parmval
= convert_for_initialization (return_loc
, type
, parmval
, flags
,
2790 "default constructor", fndecl
, i
);
2794 /* This could get clobbered by the following call. */
2795 if (TREE_HAS_CONSTRUCTOR (val
))
2796 val
= copy_node (val
);
2798 parmval
= convert_for_initialization (return_loc
, type
, val
, flags
,
2799 "default argument", fndecl
, i
);
2800 #ifdef PROMOTE_PROTOTYPES
2801 if ((TREE_CODE (type
) == INTEGER_TYPE
2802 || TREE_CODE (type
) == ENUMERAL_TYPE
)
2803 && (TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
)))
2804 parmval
= default_conversion (parmval
);
2808 if (parmval
== error_mark_node
)
2809 return error_mark_node
;
2812 && type_needs_gc_entry (TREE_TYPE (parmval
))
2813 && ! value_safe_from_gc (NULL_TREE
, parmval
))
2814 parmval
= protect_value_from_gc (NULL_TREE
, parmval
);
2816 result
= tree_cons (0, parmval
, result
);
2817 typetail
= TREE_CHAIN (typetail
);
2818 /* ends with `...'. */
2819 if (typetail
== NULL_TREE
)
2827 char *buf
= (char *)alloca (32 + strlen (called_thing
));
2828 sprintf (buf
, "too few arguments to %s `%%#D'", called_thing
);
2829 cp_error_at (buf
, fndecl
);
2830 error ("at this point in file");
2833 error ("too few arguments to function");
2834 return error_mark_list
;
2838 return nreverse (result
);
2841 /* Build a binary-operation expression, after performing default
2842 conversions on the operands. CODE is the kind of expression to build. */
2845 build_x_binary_op (code
, arg1
, arg2
)
2846 enum tree_code code
;
2849 tree rval
= build_opfncall (code
, LOOKUP_SPECULATIVELY
,
2850 arg1
, arg2
, NULL_TREE
);
2852 return build_opfncall (code
, LOOKUP_NORMAL
, arg1
, arg2
, NULL_TREE
);
2853 if (code
== MEMBER_REF
)
2854 return build_m_component_ref (build_indirect_ref (arg1
, NULL_PTR
),
2856 return build_binary_op (code
, arg1
, arg2
, 1);
2860 build_binary_op (code
, arg1
, arg2
, convert_p
)
2861 enum tree_code code
;
2874 args
[0] = decay_conversion (args
[0]);
2875 args
[1] = decay_conversion (args
[1]);
2877 if (args
[0] == error_mark_node
|| args
[1] == error_mark_node
)
2878 return error_mark_node
;
2880 type0
= TREE_TYPE (args
[0]);
2881 type1
= TREE_TYPE (args
[1]);
2883 if (type_unknown_p (args
[0]))
2885 args
[0] = instantiate_type (type1
, args
[0], 1);
2886 args
[0] = decay_conversion (args
[0]);
2888 else if (type_unknown_p (args
[1]))
2890 args
[1] = require_instantiated_type (type0
, args
[1],
2892 args
[1] = decay_conversion (args
[1]);
2895 if (IS_AGGR_TYPE (type0
) || IS_AGGR_TYPE (type1
))
2897 /* Try to convert this to something reasonable. */
2898 if (! build_default_binary_type_conversion(code
, &args
[0], &args
[1]))
2900 cp_error ("no match for `%O(%#T, %#T)'", code
,
2901 TREE_TYPE (arg1
), TREE_TYPE (arg2
));
2902 return error_mark_node
;
2906 return build_binary_op_nodefault (code
, args
[0], args
[1], code
);
2909 /* Build a binary-operation expression without default conversions.
2910 CODE is the kind of expression to build.
2911 This function differs from `build' in several ways:
2912 the data type of the result is computed and recorded in it,
2913 warnings are generated if arg data types are invalid,
2914 special handling for addition and subtraction of pointers is known,
2915 and some optimization is done (operations on narrow ints
2916 are done in the narrower type when that gives the same result).
2917 Constant folding is also done before the result is returned.
2919 ERROR_CODE is the code that determines what to say in error messages.
2920 It is usually, but not always, the same as CODE.
2922 Note that the operands will never have enumeral types
2923 because either they have just had the default conversions performed
2924 or they have both just been converted to some other type in which
2925 the arithmetic is to be done.
2927 C++: must do special pointer arithmetic when implementing
2928 multiple inheritance, and deal with pointer to member functions. */
2931 build_binary_op_nodefault (code
, orig_op0
, orig_op1
, error_code
)
2932 enum tree_code code
;
2933 tree orig_op0
, orig_op1
;
2934 enum tree_code error_code
;
2937 register enum tree_code code0
, code1
;
2940 /* Expression code to give to the expression when it is built.
2941 Normally this is CODE, which is what the caller asked for,
2942 but in some special cases we change it. */
2943 register enum tree_code resultcode
= code
;
2945 /* Data type in which the computation is to be performed.
2946 In the simplest cases this is the common type of the arguments. */
2947 register tree result_type
= NULL
;
2949 /* Nonzero means operands have already been type-converted
2950 in whatever way is necessary.
2951 Zero means they need to be converted to RESULT_TYPE. */
2954 /* Nonzero means create the expression with this type, rather than
2956 tree build_type
= 0;
2958 /* Nonzero means after finally constructing the expression
2959 convert it to this type. */
2960 tree final_type
= 0;
2962 /* Nonzero if this is an operation like MIN or MAX which can
2963 safely be computed in short if both args are promoted shorts.
2964 Also implies COMMON.
2965 -1 indicates a bitwise operation; this makes a difference
2966 in the exact conditions for when it is safe to do the operation
2967 in a narrower mode. */
2970 /* Nonzero if this is a comparison operation;
2971 if both args are promoted shorts, compare the original shorts.
2972 Also implies COMMON. */
2973 int short_compare
= 0;
2975 /* Nonzero if this is a right-shift operation, which can be computed on the
2976 original short and then promoted if the operand is a promoted short. */
2977 int short_shift
= 0;
2979 /* Nonzero means set RESULT_TYPE to the common type of the args. */
2982 /* Apply default conversions. */
2983 if (code
== TRUTH_AND_EXPR
|| code
== TRUTH_ANDIF_EXPR
2984 || code
== TRUTH_OR_EXPR
|| code
== TRUTH_ORIF_EXPR
2985 || code
== TRUTH_XOR_EXPR
)
2987 op0
= decay_conversion (orig_op0
);
2988 op1
= decay_conversion (orig_op1
);
2992 op0
= default_conversion (orig_op0
);
2993 op1
= default_conversion (orig_op1
);
2996 type0
= TREE_TYPE (op0
);
2997 type1
= TREE_TYPE (op1
);
2999 /* The expression codes of the data types of the arguments tell us
3000 whether the arguments are integers, floating, pointers, etc. */
3001 code0
= TREE_CODE (type0
);
3002 code1
= TREE_CODE (type1
);
3004 /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
3005 STRIP_TYPE_NOPS (op0
);
3006 STRIP_TYPE_NOPS (op1
);
3008 /* If an error was already reported for one of the arguments,
3009 avoid reporting another error. */
3011 if (code0
== ERROR_MARK
|| code1
== ERROR_MARK
)
3012 return error_mark_node
;
3017 /* Handle the pointer + int case. */
3018 if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
3019 return pointer_int_sum (PLUS_EXPR
, op0
, op1
);
3020 else if (code1
== POINTER_TYPE
&& code0
== INTEGER_TYPE
)
3021 return pointer_int_sum (PLUS_EXPR
, op1
, op0
);
3027 /* Subtraction of two similar pointers.
3028 We must subtract them as integers, then divide by object size. */
3029 if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
3030 && comp_target_types (type0
, type1
, 1))
3031 return pointer_diff (op0
, op1
);
3032 /* Handle pointer minus int. Just like pointer plus int. */
3033 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
3034 return pointer_int_sum (MINUS_EXPR
, op0
, op1
);
3043 case TRUNC_DIV_EXPR
:
3045 case FLOOR_DIV_EXPR
:
3046 case ROUND_DIV_EXPR
:
3047 case EXACT_DIV_EXPR
:
3048 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
3049 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
3051 if (TREE_CODE (op1
) == INTEGER_CST
&& integer_zerop (op1
))
3052 cp_warning ("division by zero in `%E / 0'", op0
);
3053 else if (TREE_CODE (op1
) == REAL_CST
&& real_zerop (op1
))
3054 cp_warning ("division by zero in `%E / 0.'", op0
);
3056 if (!(code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
))
3057 resultcode
= RDIV_EXPR
;
3059 /* When dividing two signed integers, we have to promote to int.
3060 unless we divide by a constant != -1. Note that default
3061 conversion will have been performed on the operands at this
3062 point, so we have to dig out the original type to find out if
3064 shorten
= ((TREE_CODE (op0
) == NOP_EXPR
3065 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0
, 0))))
3066 || (TREE_CODE (op1
) == INTEGER_CST
3067 && (TREE_INT_CST_LOW (op1
) != -1
3068 || TREE_INT_CST_HIGH (op1
) != -1)));
3074 case BIT_ANDTC_EXPR
:
3077 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3079 /* If one operand is a constant, and the other is a short type
3080 that has been converted to an int,
3081 really do the work in the short type and then convert the
3082 result to int. If we are lucky, the constant will be 0 or 1
3083 in the short type, making the entire operation go away. */
3084 if (TREE_CODE (op0
) == INTEGER_CST
3085 && TREE_CODE (op1
) == NOP_EXPR
3086 && TYPE_PRECISION (type1
) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op1
, 0)))
3087 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op1
, 0))))
3089 final_type
= result_type
;
3090 op1
= TREE_OPERAND (op1
, 0);
3091 result_type
= TREE_TYPE (op1
);
3093 if (TREE_CODE (op1
) == INTEGER_CST
3094 && TREE_CODE (op0
) == NOP_EXPR
3095 && TYPE_PRECISION (type0
) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0
, 0)))
3096 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0
, 0))))
3098 final_type
= result_type
;
3099 op0
= TREE_OPERAND (op0
, 0);
3100 result_type
= TREE_TYPE (op0
);
3104 case TRUNC_MOD_EXPR
:
3105 case FLOOR_MOD_EXPR
:
3106 if (code1
== INTEGER_TYPE
&& integer_zerop (op1
))
3107 cp_warning ("division by zero in `%E % 0'", op0
);
3108 else if (code1
== REAL_TYPE
&& real_zerop (op1
))
3109 cp_warning ("division by zero in `%E % 0.'", op0
);
3111 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3113 /* Although it would be tempting to shorten always here, that loses
3114 on some targets, since the modulo instruction is undefined if the
3115 quotient can't be represented in the computation mode. We shorten
3116 only if unsigned or if dividing by something we know != -1. */
3117 shorten
= ((TREE_CODE (op0
) == NOP_EXPR
3118 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0
, 0))))
3119 || (TREE_CODE (op1
) == INTEGER_CST
3120 && (TREE_INT_CST_LOW (op1
) != -1
3121 || TREE_INT_CST_HIGH (op1
) != -1)));
3126 case TRUTH_ANDIF_EXPR
:
3127 case TRUTH_ORIF_EXPR
:
3128 case TRUTH_AND_EXPR
:
3130 result_type
= boolean_type_node
;
3133 /* Shift operations: result has same type as first operand;
3134 always convert second operand to int.
3135 Also set SHORT_SHIFT if shifting rightward. */
3138 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3140 result_type
= type0
;
3141 if (TREE_CODE (op1
) == INTEGER_CST
)
3143 if (tree_int_cst_lt (op1
, integer_zero_node
))
3144 warning ("right shift count is negative");
3147 if (TREE_INT_CST_LOW (op1
) | TREE_INT_CST_HIGH (op1
))
3149 if (TREE_INT_CST_HIGH (op1
) != 0
3150 || ((unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (op1
)
3151 >= TYPE_PRECISION (type0
)))
3152 warning ("right shift count >= width of type");
3155 /* Convert the shift-count to an integer, regardless of
3156 size of value being shifted. */
3157 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
3158 op1
= convert (integer_type_node
, op1
);
3159 /* Avoid converting op1 to result_type later. */
3165 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3167 result_type
= type0
;
3168 if (TREE_CODE (op1
) == INTEGER_CST
)
3170 if (tree_int_cst_lt (op1
, integer_zero_node
))
3171 warning ("left shift count is negative");
3172 else if (TREE_INT_CST_HIGH (op1
) != 0
3173 || ((unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (op1
)
3174 >= TYPE_PRECISION (type0
)))
3175 warning ("left shift count >= width of type");
3177 /* Convert the shift-count to an integer, regardless of
3178 size of value being shifted. */
3179 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
3180 op1
= convert (integer_type_node
, op1
);
3181 /* Avoid converting op1 to result_type later. */
3188 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
3190 result_type
= type0
;
3191 if (TREE_CODE (op1
) == INTEGER_CST
)
3193 if (tree_int_cst_lt (op1
, integer_zero_node
))
3194 warning ("%s rotate count is negative",
3195 (code
== LROTATE_EXPR
) ? "left" : "right");
3196 else if (TREE_INT_CST_HIGH (op1
) != 0
3197 || ((unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (op1
)
3198 >= TYPE_PRECISION (type0
)))
3199 warning ("%s rotate count >= width of type",
3200 (code
== LROTATE_EXPR
) ? "left" : "right");
3202 /* Convert the shift-count to an integer, regardless of
3203 size of value being shifted. */
3204 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
3205 op1
= convert (integer_type_node
, op1
);
3211 build_type
= boolean_type_node
;
3212 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
3213 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
3215 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
3217 register tree tt0
= TYPE_MAIN_VARIANT (TREE_TYPE (type0
));
3218 register tree tt1
= TYPE_MAIN_VARIANT (TREE_TYPE (type1
));
3220 if (comp_target_types (type0
, type1
, 1))
3221 result_type
= common_type (type0
, type1
);
3222 else if (tt0
== void_type_node
)
3224 if (pedantic
&& TREE_CODE (tt1
) == FUNCTION_TYPE
3225 && tree_int_cst_lt (TYPE_SIZE (type0
), TYPE_SIZE (type1
)))
3226 pedwarn ("ANSI C++ forbids comparison of `void *' with function pointer");
3227 else if (TREE_CODE (tt1
) == OFFSET_TYPE
)
3228 pedwarn ("ANSI C++ forbids conversion of a pointer to member to `void *'");
3230 else if (tt1
== void_type_node
)
3232 if (pedantic
&& TREE_CODE (tt0
) == FUNCTION_TYPE
3233 && tree_int_cst_lt (TYPE_SIZE (type1
), TYPE_SIZE (type0
)))
3234 pedwarn ("ANSI C++ forbids comparison of `void *' with function pointer");
3237 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3240 if (result_type
== NULL_TREE
)
3241 result_type
= ptr_type_node
;
3243 else if (code0
== POINTER_TYPE
&& TREE_CODE (op1
) == INTEGER_CST
3244 && integer_zerop (op1
))
3245 result_type
= type0
;
3246 else if (code1
== POINTER_TYPE
&& TREE_CODE (op0
) == INTEGER_CST
3247 && integer_zerop (op0
))
3248 result_type
= type1
;
3249 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
3251 result_type
= type0
;
3252 error ("ANSI C++ forbids comparison between pointer and integer");
3254 else if (code0
== INTEGER_TYPE
&& code1
== POINTER_TYPE
)
3256 result_type
= type1
;
3257 error ("ANSI C++ forbids comparison between pointer and integer");
3259 else if (TYPE_PTRMEMFUNC_P (type0
) && TREE_CODE (op1
) == INTEGER_CST
3260 && integer_zerop (op1
))
3262 op0
= build_component_ref (op0
, index_identifier
, 0, 0);
3263 op1
= integer_zero_node
;
3264 result_type
= TREE_TYPE (op0
);
3266 else if (TYPE_PTRMEMFUNC_P (type1
) && TREE_CODE (op0
) == INTEGER_CST
3267 && integer_zerop (op0
))
3269 op0
= build_component_ref (op1
, index_identifier
, 0, 0);
3270 op1
= integer_zero_node
;
3271 result_type
= TREE_TYPE (op0
);
3273 else if (TYPE_PTRMEMFUNC_P (type0
) && TYPE_PTRMEMFUNC_P (type1
)
3274 && (TYPE_PTRMEMFUNC_FN_TYPE (type0
)
3275 == TYPE_PTRMEMFUNC_FN_TYPE (type1
)))
3277 /* The code we generate for the test is:
3279 (op0.index == op1.index
3280 && ((op1.index != -1 && op0.delta2 == op1.delta2)
3281 || op0.pfn == op1.pfn)) */
3283 tree index0
= build_component_ref (op0
, index_identifier
, 0, 0);
3284 tree index1
= save_expr (build_component_ref (op1
, index_identifier
, 0, 0));
3285 tree pfn0
= PFN_FROM_PTRMEMFUNC (op0
);
3286 tree pfn1
= PFN_FROM_PTRMEMFUNC (op1
);
3287 tree delta20
= DELTA2_FROM_PTRMEMFUNC (op0
);
3288 tree delta21
= DELTA2_FROM_PTRMEMFUNC (op1
);
3290 tree integer_neg_one_node
3291 = build_binary_op (MINUS_EXPR
, integer_zero_node
, integer_one_node
, 1);
3292 e1
= build_binary_op (EQ_EXPR
, index0
, index1
, 1);
3293 e2
= build_binary_op (NE_EXPR
, index1
, integer_neg_one_node
, 1);
3294 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e2
, build_binary_op (EQ_EXPR
, delta20
, delta21
, 1), 1);
3295 e3
= build_binary_op (EQ_EXPR
, pfn0
, pfn1
, 1);
3296 e2
= build_binary_op (TRUTH_ORIF_EXPR
, e2
, e3
, 1);
3297 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e1
, e2
, 1);
3298 if (code
== EQ_EXPR
)
3300 return build_binary_op (EQ_EXPR
, e2
, integer_zero_node
, 1);
3302 else if (TYPE_PTRMEMFUNC_P (type0
)
3303 && TYPE_PTRMEMFUNC_FN_TYPE (type0
) == type1
)
3305 tree index0
= build_component_ref (op0
, index_identifier
, 0, 0);
3307 tree pfn0
= PFN_FROM_PTRMEMFUNC (op0
);
3308 tree delta20
= DELTA2_FROM_PTRMEMFUNC (op0
);
3309 tree delta21
= integer_zero_node
;
3311 tree integer_neg_one_node
3312 = build_binary_op (MINUS_EXPR
, integer_zero_node
, integer_one_node
, 1);
3313 if (TREE_CODE (TREE_OPERAND (op1
, 0)) == FUNCTION_DECL
3314 && DECL_VINDEX (TREE_OPERAND (op1
, 0)))
3316 /* Map everything down one to make room for the null pointer to member. */
3317 index1
= size_binop (PLUS_EXPR
,
3318 DECL_VINDEX (TREE_OPERAND (op1
, 0)),
3320 op1
= integer_zero_node
;
3321 delta21
= CLASSTYPE_VFIELD (TYPE_METHOD_BASETYPE (TREE_TYPE (type1
)));
3322 delta21
= DECL_FIELD_BITPOS (delta21
);
3323 delta21
= size_binop (FLOOR_DIV_EXPR
, delta21
, size_int (BITS_PER_UNIT
));
3326 index1
= integer_neg_one_node
;
3328 tree nop1
= build1 (NOP_EXPR
, TYPE_PTRMEMFUNC_FN_TYPE (type0
), op1
);
3329 TREE_CONSTANT (nop1
) = TREE_CONSTANT (op1
);
3332 e1
= build_binary_op (EQ_EXPR
, index0
, index1
, 1);
3333 e2
= build_binary_op (NE_EXPR
, index1
, integer_neg_one_node
, 1);
3334 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e2
, build_binary_op (EQ_EXPR
, delta20
, delta21
, 1), 1);
3335 e3
= build_binary_op (EQ_EXPR
, pfn0
, op1
, 1);
3336 e2
= build_binary_op (TRUTH_ORIF_EXPR
, e2
, e3
, 1);
3337 e2
= build_binary_op (TRUTH_ANDIF_EXPR
, e1
, e2
, 1);
3338 if (code
== EQ_EXPR
)
3340 return build_binary_op (EQ_EXPR
, e2
, integer_zero_node
, 1);
3342 else if (TYPE_PTRMEMFUNC_P (type1
)
3343 && TYPE_PTRMEMFUNC_FN_TYPE (type1
) == type0
)
3345 return build_binary_op (code
, op1
, op0
, 1);
3351 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
3352 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
3354 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
3356 if (comp_target_types (type0
, type1
, 1))
3357 result_type
= common_type (type0
, type1
);
3360 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3362 result_type
= ptr_type_node
;
3371 build_type
= boolean_type_node
;
3372 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
3373 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
3375 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
3377 if (comp_target_types (type0
, type1
, 1))
3378 result_type
= common_type (type0
, type1
);
3381 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3383 result_type
= ptr_type_node
;
3386 else if (code0
== POINTER_TYPE
&& TREE_CODE (op1
) == INTEGER_CST
3387 && integer_zerop (op1
))
3388 result_type
= type0
;
3389 else if (code1
== POINTER_TYPE
&& TREE_CODE (op0
) == INTEGER_CST
3390 && integer_zerop (op0
))
3391 result_type
= type1
;
3392 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
3394 result_type
= type0
;
3396 pedwarn ("ANSI C++ forbids comparison between pointer and integer");
3397 else if (! flag_traditional
)
3398 warning ("comparison between pointer and integer");
3400 else if (code0
== INTEGER_TYPE
&& code1
== POINTER_TYPE
)
3402 result_type
= type1
;
3404 pedwarn ("ANSI C++ forbids comparison between pointer and integer");
3405 else if (! flag_traditional
)
3406 warning ("comparison between pointer and integer");
3411 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
3412 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
3414 if (shorten
|| common
|| short_compare
)
3415 result_type
= common_type (type0
, type1
);
3417 /* For certain operations (which identify themselves by shorten != 0)
3418 if both args were extended from the same smaller type,
3419 do the arithmetic in that type and then extend.
3421 shorten !=0 and !=1 indicates a bitwise operation.
3422 For them, this optimization is safe only if
3423 both args are zero-extended or both are sign-extended.
3424 Otherwise, we might change the result.
3425 Eg, (short)-1 | (unsigned short)-1 is (int)-1
3426 but calculated in (unsigned short) it would be (unsigned short)-1. */
3430 int unsigned0
, unsigned1
;
3431 tree arg0
= get_narrower (op0
, &unsigned0
);
3432 tree arg1
= get_narrower (op1
, &unsigned1
);
3433 /* UNS is 1 if the operation to be done is an unsigned one. */
3434 int uns
= TREE_UNSIGNED (result_type
);
3437 final_type
= result_type
;
3439 /* Handle the case that OP0 does not *contain* a conversion
3440 but it *requires* conversion to FINAL_TYPE. */
3442 if (op0
== arg0
&& TREE_TYPE (op0
) != final_type
)
3443 unsigned0
= TREE_UNSIGNED (TREE_TYPE (op0
));
3444 if (op1
== arg1
&& TREE_TYPE (op1
) != final_type
)
3445 unsigned1
= TREE_UNSIGNED (TREE_TYPE (op1
));
3447 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
3449 /* For bitwise operations, signedness of nominal type
3450 does not matter. Consider only how operands were extended. */
3454 /* Note that in all three cases below we refrain from optimizing
3455 an unsigned operation on sign-extended args.
3456 That would not be valid. */
3458 /* Both args variable: if both extended in same way
3459 from same width, do it in that width.
3460 Do it unsigned if args were zero-extended. */
3461 if ((TYPE_PRECISION (TREE_TYPE (arg0
))
3462 < TYPE_PRECISION (result_type
))
3463 && (TYPE_PRECISION (TREE_TYPE (arg1
))
3464 == TYPE_PRECISION (TREE_TYPE (arg0
)))
3465 && unsigned0
== unsigned1
3466 && (unsigned0
|| !uns
))
3468 = signed_or_unsigned_type (unsigned0
,
3469 common_type (TREE_TYPE (arg0
), TREE_TYPE (arg1
)));
3470 else if (TREE_CODE (arg0
) == INTEGER_CST
3471 && (unsigned1
|| !uns
)
3472 && (TYPE_PRECISION (TREE_TYPE (arg1
))
3473 < TYPE_PRECISION (result_type
))
3474 && (type
= signed_or_unsigned_type (unsigned1
,
3476 int_fits_type_p (arg0
, type
)))
3478 else if (TREE_CODE (arg1
) == INTEGER_CST
3479 && (unsigned0
|| !uns
)
3480 && (TYPE_PRECISION (TREE_TYPE (arg0
))
3481 < TYPE_PRECISION (result_type
))
3482 && (type
= signed_or_unsigned_type (unsigned0
,
3484 int_fits_type_p (arg1
, type
)))
3488 /* Shifts can be shortened if shifting right. */
3493 tree arg0
= get_narrower (op0
, &unsigned_arg
);
3495 final_type
= result_type
;
3497 if (arg0
== op0
&& final_type
== TREE_TYPE (op0
))
3498 unsigned_arg
= TREE_UNSIGNED (TREE_TYPE (op0
));
3500 if (TYPE_PRECISION (TREE_TYPE (arg0
)) < TYPE_PRECISION (result_type
)
3501 /* We can shorten only if the shift count is less than the
3502 number of bits in the smaller type size. */
3503 && TREE_INT_CST_HIGH (op1
) == 0
3504 && TYPE_PRECISION (TREE_TYPE (arg0
)) > TREE_INT_CST_LOW (op1
)
3505 /* If arg is sign-extended and then unsigned-shifted,
3506 we can simulate this with a signed shift in arg's type
3507 only if the extended result is at least twice as wide
3508 as the arg. Otherwise, the shift could use up all the
3509 ones made by sign-extension and bring in zeros.
3510 We can't optimize that case at all, but in most machines
3511 it never happens because available widths are 2**N. */
3512 && (!TREE_UNSIGNED (final_type
)
3514 || ((unsigned) 2 * TYPE_PRECISION (TREE_TYPE (arg0
))
3515 <= TYPE_PRECISION (result_type
))))
3517 /* Do an unsigned shift if the operand was zero-extended. */
3519 = signed_or_unsigned_type (unsigned_arg
,
3521 /* Convert value-to-be-shifted to that type. */
3522 if (TREE_TYPE (op0
) != result_type
)
3523 op0
= convert (result_type
, op0
);
3528 /* Comparison operations are shortened too but differently.
3529 They identify themselves by setting short_compare = 1. */
3533 /* Don't write &op0, etc., because that would prevent op0
3534 from being kept in a register.
3535 Instead, make copies of the our local variables and
3536 pass the copies by reference, then copy them back afterward. */
3537 tree xop0
= op0
, xop1
= op1
, xresult_type
= result_type
;
3538 enum tree_code xresultcode
= resultcode
;
3540 = shorten_compare (&xop0
, &xop1
, &xresult_type
, &xresultcode
);
3542 return convert (boolean_type_node
, val
);
3543 op0
= xop0
, op1
= xop1
;
3545 resultcode
= xresultcode
;
3548 if (short_compare
&& extra_warnings
)
3550 int op0_signed
= ! TREE_UNSIGNED (TREE_TYPE (orig_op0
));
3551 int op1_signed
= ! TREE_UNSIGNED (TREE_TYPE (orig_op1
));
3553 int unsignedp0
, unsignedp1
;
3554 tree primop0
= get_narrower (op0
, &unsignedp0
);
3555 tree primop1
= get_narrower (op1
, &unsignedp1
);
3557 /* Give warnings for comparisons between signed and unsigned
3558 quantities that may fail. */
3559 /* Do the checking based on the original operand trees, so that
3560 casts will be considered, but default promotions won't be. */
3562 /* Do not warn if the comparison is being done in a signed type,
3563 since the signed type will only be chosen if it can represent
3564 all the values of the unsigned type. */
3565 if (! TREE_UNSIGNED (result_type
))
3567 /* Do not warn if both operands are unsigned. */
3568 else if (op0_signed
== op1_signed
)
3570 /* Do not warn if the signed quantity is an unsuffixed
3571 integer literal (or some static constant expression
3572 involving such literals) and it is non-negative. */
3573 else if ((op0_signed
&& TREE_CODE (orig_op0
) == INTEGER_CST
3574 && tree_int_cst_sgn (orig_op0
) >= 0)
3575 || (op1_signed
&& TREE_CODE (orig_op1
) == INTEGER_CST
3576 && tree_int_cst_sgn (orig_op1
) >= 0))
3578 /* Do not warn if the comparison is an equality operation,
3579 the unsigned quantity is an integral constant and it does
3580 not use the most significant bit of result_type. */
3581 else if ((resultcode
== EQ_EXPR
|| resultcode
== NE_EXPR
)
3582 && ((op0_signed
&& TREE_CODE (orig_op1
) == INTEGER_CST
3583 && int_fits_type_p (orig_op1
, signed_type (result_type
))
3584 || (op1_signed
&& TREE_CODE (orig_op0
) == INTEGER_CST
3585 && int_fits_type_p (orig_op0
, signed_type (result_type
))))))
3588 warning ("comparison between signed and unsigned");
3590 /* Warn if two unsigned values are being compared in a size
3591 larger than their original size, and one (and only one) is the
3592 result of a `~' operator. This comparison will always fail.
3594 Also warn if one operand is a constant, and the constant does not
3595 have all bits set that are set in the ~ operand when it is
3598 if (TREE_CODE (primop0
) == BIT_NOT_EXPR
3599 ^ TREE_CODE (primop1
) == BIT_NOT_EXPR
)
3601 if (TREE_CODE (primop0
) == BIT_NOT_EXPR
)
3602 primop0
= get_narrower (TREE_OPERAND (op0
, 0), &unsignedp0
);
3603 if (TREE_CODE (primop1
) == BIT_NOT_EXPR
)
3604 primop1
= get_narrower (TREE_OPERAND (op1
, 0), &unsignedp1
);
3606 if (TREE_CODE (primop0
) == INTEGER_CST
3607 || TREE_CODE (primop1
) == INTEGER_CST
)
3610 HOST_WIDE_INT constant
, mask
;
3614 if (TREE_CODE (primop0
) == INTEGER_CST
)
3617 unsignedp
= unsignedp1
;
3618 constant
= TREE_INT_CST_LOW (primop0
);
3623 unsignedp
= unsignedp0
;
3624 constant
= TREE_INT_CST_LOW (primop1
);
3627 bits
= TYPE_PRECISION (TREE_TYPE (primop
));
3628 if (bits
< TYPE_PRECISION (result_type
)
3629 && bits
< HOST_BITS_PER_LONG
&& unsignedp
)
3631 mask
= (~ (HOST_WIDE_INT
) 0) << bits
;
3632 if ((mask
& constant
) != mask
)
3633 warning ("comparison of promoted ~unsigned with constant");
3636 else if (unsignedp0
&& unsignedp1
3637 && (TYPE_PRECISION (TREE_TYPE (primop0
))
3638 < TYPE_PRECISION (result_type
))
3639 && (TYPE_PRECISION (TREE_TYPE (primop1
))
3640 < TYPE_PRECISION (result_type
)))
3641 warning ("comparison of promoted ~unsigned with unsigned");
3646 /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
3647 If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
3648 Then the expression will be built.
3649 It will be given type FINAL_TYPE if that is nonzero;
3650 otherwise, it will be given type RESULT_TYPE. */
3654 cp_error ("invalid operands `%T' and `%T' to binary `%O'",
3655 TREE_TYPE (orig_op0
), TREE_TYPE (orig_op1
), error_code
);
3656 return error_mark_node
;
3661 if (TREE_TYPE (op0
) != result_type
)
3662 op0
= convert (result_type
, op0
);
3663 if (TREE_TYPE (op1
) != result_type
)
3664 op1
= convert (result_type
, op1
);
3667 if (build_type
== NULL_TREE
)
3668 build_type
= result_type
;
3671 register tree result
= build (resultcode
, build_type
, op0
, op1
);
3672 register tree folded
;
3674 folded
= fold (result
);
3675 if (folded
== result
)
3676 TREE_CONSTANT (folded
) = TREE_CONSTANT (op0
) & TREE_CONSTANT (op1
);
3677 if (final_type
!= 0)
3678 return convert (final_type
, folded
);
3683 /* Return a tree for the sum or difference (RESULTCODE says which)
3684 of pointer PTROP and integer INTOP. */
3687 pointer_int_sum (resultcode
, ptrop
, intop
)
3688 enum tree_code resultcode
;
3689 register tree ptrop
, intop
;
3693 register tree result
;
3694 register tree folded
= fold (intop
);
3696 /* The result is a pointer of the same type that is being added. */
3698 register tree result_type
= TREE_TYPE (ptrop
);
3700 if (TREE_CODE (TREE_TYPE (result_type
)) == VOID_TYPE
)
3702 if (pedantic
|| warn_pointer_arith
)
3703 pedwarn ("ANSI C++ forbids using pointer of type `void *' in arithmetic");
3704 size_exp
= integer_one_node
;
3706 else if (TREE_CODE (TREE_TYPE (result_type
)) == FUNCTION_TYPE
)
3708 if (pedantic
|| warn_pointer_arith
)
3709 pedwarn ("ANSI C++ forbids using pointer to a function in arithmetic");
3710 size_exp
= integer_one_node
;
3712 else if (TREE_CODE (TREE_TYPE (result_type
)) == METHOD_TYPE
)
3714 if (pedantic
|| warn_pointer_arith
)
3715 pedwarn ("ANSI C++ forbids using pointer to a method in arithmetic");
3716 size_exp
= integer_one_node
;
3718 else if (TREE_CODE (TREE_TYPE (result_type
)) == OFFSET_TYPE
)
3721 pedwarn ("ANSI C++ forbids using pointer to a member in arithmetic");
3722 size_exp
= integer_one_node
;
3725 size_exp
= size_in_bytes (TREE_TYPE (result_type
));
3727 /* Needed to make OOPS V2R3 work. */
3729 if (TREE_CODE (intop
) == INTEGER_CST
3730 && TREE_INT_CST_LOW (intop
) == 0
3731 && TREE_INT_CST_HIGH (intop
) == 0)
3734 /* If what we are about to multiply by the size of the elements
3735 contains a constant term, apply distributive law
3736 and multiply that constant term separately.
3737 This helps produce common subexpressions. */
3739 if ((TREE_CODE (intop
) == PLUS_EXPR
|| TREE_CODE (intop
) == MINUS_EXPR
)
3740 && ! TREE_CONSTANT (intop
)
3741 && TREE_CONSTANT (TREE_OPERAND (intop
, 1))
3742 && TREE_CONSTANT (size_exp
))
3744 enum tree_code subcode
= resultcode
;
3745 if (TREE_CODE (intop
) == MINUS_EXPR
)
3746 subcode
= (subcode
== PLUS_EXPR
? MINUS_EXPR
: PLUS_EXPR
);
3747 ptrop
= build_binary_op (subcode
, ptrop
, TREE_OPERAND (intop
, 1), 1);
3748 intop
= TREE_OPERAND (intop
, 0);
3751 /* Convert the integer argument to a type the same size as a pointer
3752 so the multiply won't overflow spuriously. */
3754 if (TYPE_PRECISION (TREE_TYPE (intop
)) != POINTER_SIZE
)
3755 intop
= convert (type_for_size (POINTER_SIZE
, 0), intop
);
3757 /* Replace the integer argument with a suitable product by the object size.
3758 Do this multiplication as signed, then convert to the appropriate
3759 pointer type (actually unsigned integral). */
3761 intop
= convert (result_type
,
3762 build_binary_op (MULT_EXPR
, intop
,
3763 convert (TREE_TYPE (intop
), size_exp
), 1));
3765 /* Create the sum or difference. */
3767 result
= build (resultcode
, result_type
, ptrop
, intop
);
3769 folded
= fold (result
);
3770 if (folded
== result
)
3771 TREE_CONSTANT (folded
) = TREE_CONSTANT (ptrop
) & TREE_CONSTANT (intop
);
3775 /* Return a tree for the difference of pointers OP0 and OP1.
3776 The resulting tree has type int. */
3779 pointer_diff (op0
, op1
)
3780 register tree op0
, op1
;
3782 register tree result
, folded
;
3783 tree restype
= ptrdiff_type_node
;
3784 tree target_type
= TREE_TYPE (TREE_TYPE (op0
));
3788 if (TREE_CODE (target_type
) == VOID_TYPE
)
3789 pedwarn ("ANSI C++ forbids using pointer of type `void *' in subtraction");
3790 if (TREE_CODE (target_type
) == FUNCTION_TYPE
)
3791 pedwarn ("ANSI C++ forbids using pointer to a function in subtraction");
3792 if (TREE_CODE (target_type
) == METHOD_TYPE
)
3793 pedwarn ("ANSI C++ forbids using pointer to a method in subtraction");
3794 if (TREE_CODE (target_type
) == OFFSET_TYPE
)
3795 pedwarn ("ANSI C++ forbids using pointer to a member in subtraction");
3798 /* First do the subtraction as integers;
3799 then drop through to build the divide operator. */
3801 op0
= build_binary_op (MINUS_EXPR
,
3802 convert (restype
, op0
), convert (restype
, op1
), 1);
3804 /* This generates an error if op1 is a pointer to an incomplete type. */
3805 if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (op1
))) == 0)
3806 error ("arithmetic on pointer to an incomplete type");
3808 op1
= ((TREE_CODE (target_type
) == VOID_TYPE
3809 || TREE_CODE (target_type
) == FUNCTION_TYPE
3810 || TREE_CODE (target_type
) == METHOD_TYPE
3811 || TREE_CODE (target_type
) == OFFSET_TYPE
)
3813 : size_in_bytes (target_type
));
3815 /* Do the division. */
3817 result
= build (EXACT_DIV_EXPR
, restype
, op0
, convert (restype
, op1
));
3819 folded
= fold (result
);
3820 if (folded
== result
)
3821 TREE_CONSTANT (folded
) = TREE_CONSTANT (op0
) & TREE_CONSTANT (op1
);
3825 /* Handle the case of taking the address of a COMPONENT_REF.
3826 Called by `build_unary_op' and `build_up_reference'.
3828 ARG is the COMPONENT_REF whose address we want.
3829 ARGTYPE is the pointer type that this address should have.
3830 MSG is an error message to print if this COMPONENT_REF is not
3831 addressable (such as a bitfield). */
3834 build_component_addr (arg
, argtype
, msg
)
3838 tree field
= TREE_OPERAND (arg
, 1);
3839 tree basetype
= decl_type_context (field
);
3840 tree rval
= build_unary_op (ADDR_EXPR
, TREE_OPERAND (arg
, 0), 0);
3842 if (DECL_BIT_FIELD (field
))
3844 error (msg
, IDENTIFIER_POINTER (DECL_NAME (field
)));
3845 return error_mark_node
;
3849 cp_warning ("address of `%T::%D' taken", basetype
, field
);
3851 if (TREE_CODE (field
) == FIELD_DECL
3852 && TYPE_USES_COMPLEX_INHERITANCE (basetype
))
3854 /* Can't convert directly to ARGTYPE, since that
3855 may have the same pointer type as one of our
3857 rval
= build1 (NOP_EXPR
, argtype
,
3858 convert_pointer_to (basetype
, rval
));
3859 TREE_CONSTANT (rval
) = TREE_CONSTANT (TREE_OPERAND (rval
, 0));
3862 /* This conversion is harmless. */
3863 rval
= convert_force (argtype
, rval
, 0);
3865 if (! integer_zerop (DECL_FIELD_BITPOS (field
)))
3867 tree offset
= size_binop (EASY_DIV_EXPR
, DECL_FIELD_BITPOS (field
),
3868 size_int (BITS_PER_UNIT
));
3869 int flag
= TREE_CONSTANT (rval
);
3870 rval
= fold (build (PLUS_EXPR
, argtype
,
3871 rval
, convert (argtype
, offset
)));
3872 TREE_CONSTANT (rval
) = flag
;
3877 /* Construct and perhaps optimize a tree representation
3878 for a unary operation. CODE, a tree_code, specifies the operation
3879 and XARG is the operand. */
3882 build_x_unary_op (code
, xarg
)
3883 enum tree_code code
;
3886 /* & rec, on incomplete RECORD_TYPEs is the simple opr &, not an
3888 if (code
== ADDR_EXPR
3889 && ((IS_AGGR_TYPE_CODE (TREE_CODE (TREE_TYPE (xarg
)))
3890 && TYPE_SIZE (TREE_TYPE (xarg
)) == NULL_TREE
)
3891 || (TREE_CODE (xarg
) == OFFSET_REF
)))
3892 /* don't look for a function */;
3895 tree rval
= build_opfncall (code
, LOOKUP_SPECULATIVELY
, xarg
,
3896 NULL_TREE
, NULL_TREE
);
3898 return build_opfncall (code
, LOOKUP_NORMAL
, xarg
,
3899 NULL_TREE
, NULL_TREE
);
3901 return build_unary_op (code
, xarg
, 0);
3904 /* Just like truthvalue_conversion, but we want a CLEANUP_POINT_EXPR. */
3907 condition_conversion (expr
)
3910 tree t
= convert (boolean_type_node
, expr
);
3911 t
= fold (build1 (CLEANUP_POINT_EXPR
, boolean_type_node
, t
));
3915 /* C++: Must handle pointers to members.
3917 Perhaps type instantiation should be extended to handle conversion
3918 from aggregates to types we don't yet know we want? (Or are those
3919 cases typically errors which should be reported?)
3921 NOCONVERT nonzero suppresses the default promotions
3922 (such as from short to int). */
3924 build_unary_op (code
, xarg
, noconvert
)
3925 enum tree_code code
;
3929 /* No default_conversion here. It causes trouble for ADDR_EXPR. */
3930 register tree arg
= xarg
;
3931 register tree argtype
= 0;
3932 char *errstring
= NULL
;
3935 if (arg
== error_mark_node
)
3936 return error_mark_node
;
3941 /* This is used for unary plus, because a CONVERT_EXPR
3942 is enough to prevent anybody from looking inside for
3943 associativity, but won't generate any code. */
3944 if (!(arg
= build_expr_type_conversion
3945 (WANT_ARITH
| WANT_ENUM
| WANT_POINTER
, arg
, 1)))
3946 errstring
= "wrong type argument to unary plus";
3950 arg
= default_conversion (arg
);
3951 arg
= build1 (NON_LVALUE_EXPR
, TREE_TYPE (arg
), arg
);
3956 if (!(arg
= build_expr_type_conversion (WANT_ARITH
| WANT_ENUM
, arg
, 1)))
3957 errstring
= "wrong type argument to unary minus";
3958 else if (!noconvert
)
3959 arg
= default_conversion (arg
);
3963 if (!(arg
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, arg
, 1)))
3964 errstring
= "wrong type argument to bit-complement";
3965 else if (!noconvert
)
3966 arg
= default_conversion (arg
);
3970 if (!(arg
= build_expr_type_conversion (WANT_ARITH
| WANT_ENUM
, arg
, 1)))
3971 errstring
= "wrong type argument to abs";
3972 else if (!noconvert
)
3973 arg
= default_conversion (arg
);
3976 case TRUTH_NOT_EXPR
:
3977 arg
= convert (boolean_type_node
, arg
);
3978 val
= invert_truthvalue (arg
);
3979 if (arg
!= error_mark_node
)
3981 errstring
= "in argument to unary !";
3987 case PREINCREMENT_EXPR
:
3988 case POSTINCREMENT_EXPR
:
3989 case PREDECREMENT_EXPR
:
3990 case POSTDECREMENT_EXPR
:
3991 /* Handle complex lvalues (when permitted)
3992 by reduction to simpler cases. */
3994 val
= unary_complex_lvalue (code
, arg
);
3998 /* Report invalid types. */
4000 if (!(arg
= build_expr_type_conversion (WANT_ARITH
| WANT_POINTER
,
4003 if (code
== PREINCREMENT_EXPR
)
4004 errstring
="no pre-increment operator for type";
4005 else if (code
== POSTINCREMENT_EXPR
)
4006 errstring
="no post-increment operator for type";
4007 else if (code
== PREDECREMENT_EXPR
)
4008 errstring
="no pre-decrement operator for type";
4010 errstring
="no post-decrement operator for type";
4014 /* Report something read-only. */
4016 if (TYPE_READONLY (TREE_TYPE (arg
))
4017 || TREE_READONLY (arg
))
4018 readonly_error (arg
, ((code
== PREINCREMENT_EXPR
4019 || code
== POSTINCREMENT_EXPR
)
4020 ? "increment" : "decrement"),
4025 tree result_type
= TREE_TYPE (arg
);
4027 arg
= get_unwidened (arg
, 0);
4028 argtype
= TREE_TYPE (arg
);
4030 /* ARM $5.2.5 last annotation says this should be forbidden. */
4031 if (TREE_CODE (argtype
) == ENUMERAL_TYPE
)
4032 pedwarn ("ANSI C++ forbids %sing an enum",
4033 (code
== PREINCREMENT_EXPR
|| code
== POSTINCREMENT_EXPR
)
4034 ? "increment" : "decrement");
4036 /* Compute the increment. */
4038 if (TREE_CODE (argtype
) == POINTER_TYPE
)
4040 enum tree_code tmp
= TREE_CODE (TREE_TYPE (argtype
));
4041 if (TYPE_SIZE (TREE_TYPE (argtype
)) == 0)
4042 cp_error ("cannot %s a pointer to incomplete type `%T'",
4043 ((code
== PREINCREMENT_EXPR
4044 || code
== POSTINCREMENT_EXPR
)
4045 ? "increment" : "decrement"), TREE_TYPE (argtype
));
4046 else if (tmp
== FUNCTION_TYPE
|| tmp
== METHOD_TYPE
4047 || tmp
== VOID_TYPE
|| tmp
== OFFSET_TYPE
)
4048 cp_pedwarn ("ANSI C++ forbids %sing a pointer of type `%T'",
4049 ((code
== PREINCREMENT_EXPR
4050 || code
== POSTINCREMENT_EXPR
)
4051 ? "increment" : "decrement"), argtype
);
4052 inc
= c_sizeof_nowarn (TREE_TYPE (argtype
));
4055 inc
= integer_one_node
;
4057 inc
= convert (argtype
, inc
);
4059 /* Handle incrementing a cast-expression. */
4061 switch (TREE_CODE (arg
))
4066 case FIX_TRUNC_EXPR
:
4067 case FIX_FLOOR_EXPR
:
4068 case FIX_ROUND_EXPR
:
4071 tree incremented
, modify
, value
;
4072 if (! lvalue_p (arg
) && pedantic
)
4073 pedwarn ("cast to non-reference type used as lvalue");
4074 arg
= stabilize_reference (arg
);
4075 if (code
== PREINCREMENT_EXPR
|| code
== PREDECREMENT_EXPR
)
4078 value
= save_expr (arg
);
4079 incremented
= build (((code
== PREINCREMENT_EXPR
4080 || code
== POSTINCREMENT_EXPR
)
4081 ? PLUS_EXPR
: MINUS_EXPR
),
4082 argtype
, value
, inc
);
4083 TREE_SIDE_EFFECTS (incremented
) = 1;
4084 modify
= build_modify_expr (arg
, NOP_EXPR
, incremented
);
4085 return build (COMPOUND_EXPR
, TREE_TYPE (arg
), modify
, value
);
4089 /* Complain about anything else that is not a true lvalue. */
4090 if (!lvalue_or_else (arg
, ((code
== PREINCREMENT_EXPR
4091 || code
== POSTINCREMENT_EXPR
)
4092 ? "increment" : "decrement")))
4093 return error_mark_node
;
4095 /* Forbid using -- on `bool'. */
4096 if (TREE_TYPE (arg
) == boolean_type_node
)
4098 if (code
== POSTDECREMENT_EXPR
|| code
== PREDECREMENT_EXPR
)
4100 cp_error ("invalid use of `--' on bool variable `%D'", arg
);
4101 return error_mark_node
;
4104 /* This will only work if someone can convince Kenner to accept
4105 my patch to expand_increment. (jason) */
4106 val
= build (code
, TREE_TYPE (arg
), arg
, inc
);
4108 if (code
== POSTINCREMENT_EXPR
)
4110 arg
= stabilize_reference (arg
);
4111 val
= build (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
4113 TREE_SIDE_EFFECTS (val
) = 1;
4114 arg
= save_expr (arg
);
4115 val
= build (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
4116 val
= build (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
4119 val
= build (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
4124 val
= build (code
, TREE_TYPE (arg
), arg
, inc
);
4126 TREE_SIDE_EFFECTS (val
) = 1;
4127 return convert (result_type
, val
);
4131 /* Note that this operation never does default_conversion
4132 regardless of NOCONVERT. */
4134 argtype
= TREE_TYPE (arg
);
4135 if (TREE_CODE (argtype
) == REFERENCE_TYPE
)
4137 arg
= build1 (CONVERT_EXPR
, build_pointer_type (TREE_TYPE (TREE_TYPE (arg
))), arg
);
4138 TREE_REFERENCE_EXPR (arg
) = 1;
4142 && TREE_CODE (arg
) == FUNCTION_DECL
4144 && DECL_CONTEXT (arg
) == NULL_TREE
4145 && IDENTIFIER_LENGTH (DECL_NAME (arg
)) == 4
4146 && IDENTIFIER_POINTER (DECL_NAME (arg
))[0] == 'm'
4147 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (arg
)), "main"))
4149 pedwarn ("taking address of function `main'");
4151 /* Let &* cancel out to simplify resulting code. */
4152 if (TREE_CODE (arg
) == INDIRECT_REF
)
4154 /* We don't need to have `current_class_decl' wrapped in a
4155 NON_LVALUE_EXPR node. */
4157 return current_class_decl
;
4159 /* Keep `default_conversion' from converting if
4160 ARG is of REFERENCE_TYPE. */
4161 arg
= TREE_OPERAND (arg
, 0);
4162 if (TREE_CODE (TREE_TYPE (arg
)) == REFERENCE_TYPE
)
4164 if (TREE_CODE (arg
) == VAR_DECL
&& DECL_INITIAL (arg
)
4165 && !TREE_SIDE_EFFECTS (DECL_INITIAL (arg
)))
4166 arg
= DECL_INITIAL (arg
);
4167 arg
= build1 (CONVERT_EXPR
, build_pointer_type (TREE_TYPE (TREE_TYPE (arg
))), arg
);
4168 TREE_REFERENCE_EXPR (arg
) = 1;
4169 TREE_CONSTANT (arg
) = TREE_CONSTANT (TREE_OPERAND (arg
, 0));
4171 else if (lvalue_p (arg
))
4172 /* Don't let this be an lvalue. */
4173 return non_lvalue (arg
);
4177 /* For &x[y], return x+y */
4178 if (TREE_CODE (arg
) == ARRAY_REF
)
4180 if (mark_addressable (TREE_OPERAND (arg
, 0)) == 0)
4181 return error_mark_node
;
4182 return build_binary_op (PLUS_EXPR
, TREE_OPERAND (arg
, 0),
4183 TREE_OPERAND (arg
, 1), 1);
4186 /* Uninstantiated types are all functions. Taking the
4187 address of a function is a no-op, so just return the
4190 if (TREE_CODE (arg
) == IDENTIFIER_NODE
4191 && IDENTIFIER_OPNAME_P (arg
))
4193 my_friendly_abort (117);
4194 /* We don't know the type yet, so just work around the problem.
4195 We know that this will resolve to an lvalue. */
4196 return build1 (ADDR_EXPR
, unknown_type_node
, arg
);
4199 if (TREE_CODE (arg
) == TREE_LIST
)
4201 if (TREE_CODE (TREE_VALUE (arg
)) == FUNCTION_DECL
4202 && DECL_CHAIN (TREE_VALUE (arg
)) == NULL_TREE
)
4203 /* Unique overloaded non-member function. */
4204 return build_unary_op (ADDR_EXPR
, TREE_VALUE (arg
), 0);
4205 if (TREE_CHAIN (arg
) == NULL_TREE
4206 && TREE_CODE (TREE_VALUE (arg
)) == TREE_LIST
4207 && DECL_CHAIN (TREE_VALUE (TREE_VALUE (arg
))) == NULL_TREE
)
4208 /* Unique overloaded member function. */
4209 return build_unary_op (ADDR_EXPR
, TREE_VALUE (TREE_VALUE (arg
)),
4211 return build1 (ADDR_EXPR
, unknown_type_node
, arg
);
4214 /* Handle complex lvalues (when permitted)
4215 by reduction to simpler cases. */
4216 val
= unary_complex_lvalue (code
, arg
);
4220 switch (TREE_CODE (arg
))
4225 case FIX_TRUNC_EXPR
:
4226 case FIX_FLOOR_EXPR
:
4227 case FIX_ROUND_EXPR
:
4229 if (! lvalue_p (arg
) && pedantic
)
4230 pedwarn ("taking the address of a cast to non-reference type");
4233 /* Allow the address of a constructor if all the elements
4235 if (TREE_CODE (arg
) == CONSTRUCTOR
&& TREE_CONSTANT (arg
))
4237 /* Anything not already handled and not a true memory reference
4239 else if (TREE_CODE (argtype
) != FUNCTION_TYPE
4240 && TREE_CODE (argtype
) != METHOD_TYPE
4241 && !lvalue_or_else (arg
, "unary `&'"))
4242 return error_mark_node
;
4244 /* Ordinary case; arg is a COMPONENT_REF or a decl. */
4245 /* If the lvalue is const or volatile,
4246 merge that into the type that the address will point to. */
4247 if (TREE_CODE_CLASS (TREE_CODE (arg
)) == 'd'
4248 || TREE_CODE_CLASS (TREE_CODE (arg
)) == 'r')
4250 if (TREE_READONLY (arg
) || TREE_THIS_VOLATILE (arg
))
4251 argtype
= cp_build_type_variant (argtype
,
4252 TREE_READONLY (arg
),
4253 TREE_THIS_VOLATILE (arg
));
4256 argtype
= build_pointer_type (argtype
);
4258 if (mark_addressable (arg
) == 0)
4259 return error_mark_node
;
4264 if (TREE_CODE (arg
) == COMPONENT_REF
)
4265 addr
= build_component_addr (arg
, argtype
,
4266 "attempt to take address of bit-field structure member `%s'");
4268 addr
= build1 (code
, argtype
, arg
);
4270 /* Address of a static or external variable or
4271 function counts as a constant */
4273 TREE_CONSTANT (addr
) = 1;
4281 argtype
= TREE_TYPE (arg
);
4282 return fold (build1 (code
, argtype
, arg
));
4286 return error_mark_node
;
4289 /* If CONVERSIONS is a conversion expression or a nested sequence of such,
4290 convert ARG with the same conversions in the same order
4291 and return the result. */
4294 convert_sequence (conversions
, arg
)
4298 switch (TREE_CODE (conversions
))
4303 case FIX_TRUNC_EXPR
:
4304 case FIX_FLOOR_EXPR
:
4305 case FIX_ROUND_EXPR
:
4307 return convert (TREE_TYPE (conversions
),
4308 convert_sequence (TREE_OPERAND (conversions
, 0),
4316 /* Apply unary lvalue-demanding operator CODE to the expression ARG
4317 for certain kinds of expressions which are not really lvalues
4318 but which we can accept as lvalues.
4320 If ARG is not a kind of expression we can handle, return zero. */
4323 unary_complex_lvalue (code
, arg
)
4324 enum tree_code code
;
4327 /* Handle (a, b) used as an "lvalue". */
4328 if (TREE_CODE (arg
) == COMPOUND_EXPR
)
4330 tree real_result
= build_unary_op (code
, TREE_OPERAND (arg
, 1), 0);
4331 return build (COMPOUND_EXPR
, TREE_TYPE (real_result
),
4332 TREE_OPERAND (arg
, 0), real_result
);
4335 /* Handle (a ? b : c) used as an "lvalue". */
4336 if (TREE_CODE (arg
) == COND_EXPR
)
4337 return rationalize_conditional_expr (code
, arg
);
4339 if (TREE_CODE (arg
) == MODIFY_EXPR
4340 || TREE_CODE (arg
) == PREINCREMENT_EXPR
4341 || TREE_CODE (arg
) == PREDECREMENT_EXPR
)
4342 return unary_complex_lvalue
4343 (code
, build (COMPOUND_EXPR
, TREE_TYPE (TREE_OPERAND (arg
, 0)),
4344 arg
, TREE_OPERAND (arg
, 0)));
4346 if (code
!= ADDR_EXPR
)
4349 /* Handle (a = b) used as an "lvalue" for `&'. */
4350 if (TREE_CODE (arg
) == MODIFY_EXPR
4351 || TREE_CODE (arg
) == INIT_EXPR
)
4353 tree real_result
= build_unary_op (code
, TREE_OPERAND (arg
, 0), 0);
4354 return build (COMPOUND_EXPR
, TREE_TYPE (real_result
), arg
, real_result
);
4357 if (TREE_CODE (arg
) == WITH_CLEANUP_EXPR
)
4359 tree real_result
= build_unary_op (code
, TREE_OPERAND (arg
, 0), 0);
4360 real_result
= build (WITH_CLEANUP_EXPR
, TREE_TYPE (real_result
),
4361 real_result
, 0, TREE_OPERAND (arg
, 2));
4365 if (TREE_CODE (TREE_TYPE (arg
)) == FUNCTION_TYPE
4366 || TREE_CODE (TREE_TYPE (arg
)) == METHOD_TYPE
4367 || TREE_CODE (TREE_TYPE (arg
)) == OFFSET_TYPE
)
4369 /* The representation of something of type OFFSET_TYPE
4370 is really the representation of a pointer to it.
4371 Here give the representation its true type. */
4375 my_friendly_assert (TREE_CODE (arg
) != SCOPE_REF
, 313);
4377 if (TREE_CODE (arg
) != OFFSET_REF
)
4380 t
= TREE_OPERAND (arg
, 1);
4382 if (TREE_CODE (t
) == FUNCTION_DECL
) /* Check all this code for right semantics. */
4383 return build_unary_op (ADDR_EXPR
, t
, 0);
4384 if (TREE_CODE (t
) == VAR_DECL
)
4385 return build_unary_op (ADDR_EXPR
, t
, 0);
4388 if (TREE_OPERAND (arg
, 0)
4389 && (TREE_CODE (TREE_OPERAND (arg
, 0)) != NOP_EXPR
4390 || TREE_OPERAND (TREE_OPERAND (arg
, 0), 0) != error_mark_node
))
4391 if (TREE_CODE (t
) != FIELD_DECL
)
4393 /* Don't know if this should return address to just
4394 _DECL, or actual address resolved in this expression. */
4395 sorry ("address of bound pointer-to-member expression");
4396 return error_mark_node
;
4399 offset
= get_delta_difference (DECL_FIELD_CONTEXT (t
),
4400 TREE_TYPE (TREE_OPERAND (arg
, 0)),
4402 offset
= size_binop (PLUS_EXPR
, offset
,
4403 size_binop (EASY_DIV_EXPR
,
4404 DECL_FIELD_BITPOS (t
),
4405 size_int (BITS_PER_UNIT
)));
4406 return convert (build_pointer_type (TREE_TYPE (arg
)), offset
);
4410 if (TREE_CODE (arg
) == OFFSET_REF
)
4412 tree left
= TREE_OPERAND (arg
, 0), left_addr
;
4413 tree right_addr
= build_unary_op (ADDR_EXPR
, TREE_OPERAND (arg
, 1), 0);
4416 if (current_class_decl
)
4417 left_addr
= current_class_decl
;
4420 error ("no `this' for pointer to member");
4421 return error_mark_node
;
4424 left_addr
= build_unary_op (ADDR_EXPR
, left
, 0);
4426 return build (PLUS_EXPR
, build_pointer_type (TREE_TYPE (arg
)),
4427 build1 (NOP_EXPR
, integer_type_node
, left_addr
),
4428 build1 (NOP_EXPR
, integer_type_node
, right_addr
));
4431 /* We permit compiler to make function calls returning
4432 objects of aggregate type look like lvalues. */
4436 if (TREE_CODE (targ
) == SAVE_EXPR
)
4437 targ
= TREE_OPERAND (targ
, 0);
4439 if (TREE_CODE (targ
) == CALL_EXPR
&& IS_AGGR_TYPE (TREE_TYPE (targ
)))
4441 if (TREE_CODE (arg
) == SAVE_EXPR
)
4444 targ
= build_cplus_new (TREE_TYPE (arg
), arg
, 1);
4445 return build1 (ADDR_EXPR
, build_pointer_type (TREE_TYPE (arg
)), targ
);
4448 if (TREE_CODE (arg
) == SAVE_EXPR
&& TREE_CODE (targ
) == INDIRECT_REF
)
4449 return build (SAVE_EXPR
, build_pointer_type (TREE_TYPE (arg
)),
4450 TREE_OPERAND (targ
, 0), current_function_decl
, NULL
);
4452 /* We shouldn't wrap WITH_CLEANUP_EXPRs inside of SAVE_EXPRs, but in case
4453 we do, here's how to handle it. */
4454 if (TREE_CODE (arg
) == SAVE_EXPR
&& TREE_CODE (targ
) == WITH_CLEANUP_EXPR
)
4457 /* Not really a bug, but something to turn on when testing. */
4458 compiler_error ("WITH_CLEANUP_EXPR wrapped in SAVE_EXPR");
4460 return unary_complex_lvalue (ADDR_EXPR
, targ
);
4464 /* Don't let anything else be handled specially. */
4468 /* Mark EXP saying that we need to be able to take the
4469 address of it; it should not be allocated in a register.
4470 Value is 1 if successful.
4472 C++: we do not allow `current_class_decl' to be addressable. */
4475 mark_addressable (exp
)
4478 register tree x
= exp
;
4480 if (TREE_ADDRESSABLE (x
) == 1)
4484 switch (TREE_CODE (x
))
4489 x
= TREE_OPERAND (x
, 0);
4493 if (x
== current_class_decl
)
4495 error ("address of `this' not available");
4496 TREE_ADDRESSABLE (x
) = 1; /* so compiler doesn't die later */
4497 put_var_into_stack (x
);
4502 && TREE_READONLY (x
)
4503 && DECL_RTL (x
) != 0
4504 && ! decl_in_memory_p (x
))
4506 /* We thought this would make a good constant variable,
4507 but we were wrong. */
4508 push_obstacks_nochange ();
4509 end_temporary_allocation ();
4511 TREE_ASM_WRITTEN (x
) = 0;
4513 rest_of_decl_compilation (x
, 0, IDENTIFIER_LOCAL_VALUE (x
) == 0, 0);
4514 TREE_ADDRESSABLE (x
) = 1;
4520 /* Caller should not be trying to mark initialized
4521 constant fields addressable. */
4522 my_friendly_assert (DECL_LANG_SPECIFIC (x
) == 0
4523 || DECL_IN_AGGR_P (x
) == 0
4525 || DECL_EXTERNAL (x
), 314);
4529 /* For C++, we don't warn about taking the address of a register
4530 variable for CONST_DECLs; ARM p97 explicitly says it's okay. */
4531 put_var_into_stack (x
);
4532 TREE_ADDRESSABLE (x
) = 1;
4536 /* We have to test both conditions here. The first may
4537 be non-zero in the case of processing a default function.
4538 The second may be non-zero in the case of a template function. */
4539 x
= DECL_MAIN_VARIANT (x
);
4540 if ((DECL_THIS_INLINE (x
) || DECL_PENDING_INLINE_INFO (x
))
4541 && (DECL_CONTEXT (x
) == NULL_TREE
4542 || TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (x
))) != 't'
4543 || ! CLASSTYPE_INTERFACE_ONLY (DECL_CONTEXT (x
))))
4545 mark_inline_for_output (x
);
4546 if (x
== current_function_decl
)
4547 DECL_EXTERNAL (x
) = 0;
4549 TREE_ADDRESSABLE (x
) = 1;
4551 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (x
)) = 1;
4553 assemble_external (x
);
4561 /* Build and return a conditional expression IFEXP ? OP1 : OP2. */
4564 build_x_conditional_expr (ifexp
, op1
, op2
)
4565 tree ifexp
, op1
, op2
;
4567 tree rval
= NULL_TREE
;
4569 /* See comments in `build_x_binary_op'. */
4571 rval
= build_opfncall (COND_EXPR
, LOOKUP_SPECULATIVELY
, ifexp
, op1
, op2
);
4573 return build_opfncall (COND_EXPR
, LOOKUP_NORMAL
, ifexp
, op1
, op2
);
4575 return build_conditional_expr (ifexp
, op1
, op2
);
4579 build_conditional_expr (ifexp
, op1
, op2
)
4580 tree ifexp
, op1
, op2
;
4582 register tree type1
;
4583 register tree type2
;
4584 register enum tree_code code1
;
4585 register enum tree_code code2
;
4586 register tree result_type
= NULL_TREE
;
4587 tree orig_op1
= op1
, orig_op2
= op2
;
4589 /* If second operand is omitted, it is the same as the first one;
4590 make sure it is calculated only once. */
4594 pedwarn ("ANSI C++ forbids omitting the middle term of a ?: expression");
4595 ifexp
= op1
= save_expr (ifexp
);
4598 ifexp
= convert (boolean_type_node
, ifexp
);
4600 if (TREE_CODE (ifexp
) == ERROR_MARK
)
4601 return error_mark_node
;
4603 op1
= require_instantiated_type (TREE_TYPE (op2
), op1
, error_mark_node
);
4604 if (op1
== error_mark_node
)
4605 return error_mark_node
;
4606 op2
= require_instantiated_type (TREE_TYPE (op1
), op2
, error_mark_node
);
4607 if (op2
== error_mark_node
)
4608 return error_mark_node
;
4610 /* C++: REFERENCE_TYPES must be dereferenced. */
4611 type1
= TREE_TYPE (op1
);
4612 code1
= TREE_CODE (type1
);
4613 type2
= TREE_TYPE (op2
);
4614 code2
= TREE_CODE (type2
);
4616 if (code1
== REFERENCE_TYPE
)
4618 op1
= convert_from_reference (op1
);
4619 type1
= TREE_TYPE (op1
);
4620 code1
= TREE_CODE (type1
);
4622 if (code2
== REFERENCE_TYPE
)
4624 op2
= convert_from_reference (op2
);
4625 type2
= TREE_TYPE (op2
);
4626 code2
= TREE_CODE (type2
);
4629 #if 1 /* Produces wrong result if within sizeof. Sorry. */
4630 /* Don't promote the operands separately if they promote
4631 the same way. Return the unpromoted type and let the combined
4632 value get promoted if necessary. */
4634 if (TYPE_MAIN_VARIANT (type1
) == TYPE_MAIN_VARIANT (type2
)
4635 && code2
!= ARRAY_TYPE
4637 /* For C++, let the enumeral type come through. */
4638 && code2
!= ENUMERAL_TYPE
4640 && code2
!= FUNCTION_TYPE
4641 && code2
!= METHOD_TYPE
)
4645 if (TREE_CONSTANT (ifexp
)
4646 && (TREE_CODE (ifexp
) == INTEGER_CST
4647 || TREE_CODE (ifexp
) == ADDR_EXPR
))
4648 return (integer_zerop (ifexp
) ? op2
: op1
);
4650 if (TREE_CODE (op1
) == CONST_DECL
)
4651 op1
= DECL_INITIAL (op1
);
4652 else if (TREE_READONLY_DECL_P (op1
))
4653 op1
= decl_constant_value (op1
);
4654 if (TREE_CODE (op2
) == CONST_DECL
)
4655 op2
= DECL_INITIAL (op2
);
4656 else if (TREE_READONLY_DECL_P (op2
))
4657 op2
= decl_constant_value (op2
);
4659 type1
= cp_build_type_variant
4661 TREE_READONLY (op1
) || TREE_READONLY (op2
),
4662 TREE_THIS_VOLATILE (op1
) || TREE_THIS_VOLATILE (op2
));
4663 /* ??? This is a kludge to deal with the fact that
4664 we don't sort out integers and enums properly, yet. */
4665 result
= fold (build (COND_EXPR
, type1
, ifexp
, op1
, op2
));
4666 if (TREE_TYPE (result
) != type1
)
4667 result
= build1 (NOP_EXPR
, type1
, result
);
4672 /* They don't match; promote them both and then try to reconcile them.
4673 But don't permit mismatching enum types. */
4674 if (code1
== ENUMERAL_TYPE
)
4676 if (code2
== ENUMERAL_TYPE
)
4678 cp_error ("enumeral mismatch in conditional expression: `%T' vs `%T'", type1
, type2
);
4679 return error_mark_node
;
4681 else if (extra_warnings
&& ! IS_AGGR_TYPE_CODE (code2
)
4682 && type2
!= type_promotes_to (type1
))
4683 warning ("enumeral and non-enumeral type in conditional expression");
4685 else if (extra_warnings
4686 && code2
== ENUMERAL_TYPE
&& ! IS_AGGR_TYPE_CODE (code1
)
4687 && type1
!= type_promotes_to (type2
))
4688 warning ("enumeral and non-enumeral type in conditional expression");
4690 if (code1
!= VOID_TYPE
)
4692 op1
= default_conversion (op1
);
4693 type1
= TREE_TYPE (op1
);
4694 if (TYPE_PTRMEMFUNC_P (type1
))
4695 type1
= TYPE_PTRMEMFUNC_FN_TYPE (type1
);
4696 code1
= TREE_CODE (type1
);
4698 if (code2
!= VOID_TYPE
)
4700 op2
= default_conversion (op2
);
4701 type2
= TREE_TYPE (op2
);
4702 if (TYPE_PTRMEMFUNC_P (type2
))
4703 type2
= TYPE_PTRMEMFUNC_FN_TYPE (type2
);
4704 code2
= TREE_CODE (type2
);
4707 if (code1
== RECORD_TYPE
&& code2
== RECORD_TYPE
4708 && real_lvalue_p (op1
) && real_lvalue_p (op2
)
4709 && comptypes (type1
, type2
, -1))
4711 type1
= build_reference_type (type1
);
4712 type2
= build_reference_type (type2
);
4713 result_type
= common_type (type1
, type2
);
4714 op1
= convert_to_reference (result_type
, op1
, CONV_IMPLICIT
,
4715 LOOKUP_NORMAL
, NULL_TREE
);
4716 op2
= convert_to_reference (result_type
, op2
, CONV_IMPLICIT
,
4717 LOOKUP_NORMAL
, NULL_TREE
);
4719 /* Quickly detect the usual case where op1 and op2 have the same type
4721 else if (TYPE_MAIN_VARIANT (type1
) == TYPE_MAIN_VARIANT (type2
))
4724 result_type
= type1
;
4726 result_type
= cp_build_type_variant
4728 TREE_READONLY (op1
) || TREE_READONLY (op2
),
4729 TREE_THIS_VOLATILE (op1
) || TREE_THIS_VOLATILE (op2
));
4731 else if ((code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
)
4732 && (code2
== INTEGER_TYPE
|| code2
== REAL_TYPE
))
4734 result_type
= common_type (type1
, type2
);
4736 else if (code1
== VOID_TYPE
|| code2
== VOID_TYPE
)
4738 if (pedantic
&& (code1
!= VOID_TYPE
|| code2
!= VOID_TYPE
))
4739 pedwarn ("ANSI C++ forbids conditional expr with only one void side");
4740 result_type
= void_type_node
;
4742 else if (code1
== POINTER_TYPE
&& code2
== POINTER_TYPE
)
4744 if (comp_target_types (type1
, type2
, 1))
4745 result_type
= common_type (type1
, type2
);
4746 else if (integer_zerop (op1
) && TREE_TYPE (type1
) == void_type_node
4747 && TREE_CODE (orig_op1
) != NOP_EXPR
)
4748 result_type
= qualify_type (type2
, type1
);
4749 else if (integer_zerop (op2
) && TREE_TYPE (type2
) == void_type_node
4750 && TREE_CODE (orig_op2
) != NOP_EXPR
)
4751 result_type
= qualify_type (type1
, type2
);
4752 else if (TYPE_MAIN_VARIANT (TREE_TYPE (type1
)) == void_type_node
)
4754 if (pedantic
&& TREE_CODE (type2
) == FUNCTION_TYPE
)
4755 pedwarn ("ANSI C++ forbids conditional expr between `void *' and function pointer");
4756 result_type
= qualify_type (type1
, type2
);
4758 else if (TYPE_MAIN_VARIANT (TREE_TYPE (type2
)) == void_type_node
)
4760 if (pedantic
&& TREE_CODE (type1
) == FUNCTION_TYPE
)
4761 pedwarn ("ANSI C++ forbids conditional expr between `void *' and function pointer");
4762 result_type
= qualify_type (type2
, type1
);
4765 else if (comptypes (type2
, type1
, 0))
4766 result_type
= type2
;
4767 else if (IS_AGGR_TYPE (TREE_TYPE (type1
))
4768 && IS_AGGR_TYPE (TREE_TYPE (type2
))
4769 && (result_type
= common_base_type (TREE_TYPE (type1
), TREE_TYPE (type2
))))
4771 if (result_type
== error_mark_node
)
4773 cp_error ("common base type of types `%T' and `%T' is ambiguous",
4774 TREE_TYPE (type1
), TREE_TYPE (type2
));
4775 result_type
= ptr_type_node
;
4780 && result_type
!= TREE_TYPE (type1
)
4781 && result_type
!= TREE_TYPE (type2
))
4782 cp_pedwarn ("`%T' and `%T' converted to `%T *' in conditional expression",
4783 type1
, type2
, result_type
);
4785 result_type
= build_pointer_type (result_type
);
4790 pedwarn ("pointer type mismatch in conditional expression");
4791 result_type
= ptr_type_node
;
4794 else if (code1
== POINTER_TYPE
&& code2
== INTEGER_TYPE
)
4796 if (!integer_zerop (op2
))
4797 pedwarn ("pointer/integer type mismatch in conditional expression");
4800 op2
= null_pointer_node
;
4801 #if 0 /* Sez who? */
4802 if (pedantic
&& TREE_CODE (type1
) == FUNCTION_TYPE
)
4803 pedwarn ("ANSI C++ forbids conditional expr between 0 and function pointer");
4806 result_type
= type1
;
4808 else if (code2
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
4810 if (!integer_zerop (op1
))
4811 pedwarn ("pointer/integer type mismatch in conditional expression");
4814 op1
= null_pointer_node
;
4815 #if 0 /* Sez who? */
4816 if (pedantic
&& TREE_CODE (type2
) == FUNCTION_TYPE
)
4817 pedwarn ("ANSI C++ forbids conditional expr between 0 and function pointer");
4820 result_type
= type2
;
4825 /* The match does not look good. If either is
4826 an aggregate value, try converting to a scalar type. */
4827 if (code1
== RECORD_TYPE
&& code2
== RECORD_TYPE
)
4829 cp_error ("aggregate mismatch in conditional expression: `%T' vs `%T'", type1
, type2
);
4830 return error_mark_node
;
4832 if (code1
== RECORD_TYPE
&& TYPE_HAS_CONVERSION (type1
))
4834 tree tmp
= build_type_conversion (CONVERT_EXPR
, type2
, op1
, 0);
4835 if (tmp
== NULL_TREE
)
4837 cp_error ("aggregate type `%T' could not convert on lhs of `:'", type1
);
4838 return error_mark_node
;
4840 if (tmp
== error_mark_node
)
4841 error ("ambiguous pointer conversion");
4842 result_type
= type2
;
4845 else if (code2
== RECORD_TYPE
&& TYPE_HAS_CONVERSION (type2
))
4847 tree tmp
= build_type_conversion (CONVERT_EXPR
, type1
, op2
, 0);
4848 if (tmp
== NULL_TREE
)
4850 cp_error ("aggregate type `%T' could not convert on rhs of `:'", type2
);
4851 return error_mark_node
;
4853 if (tmp
== error_mark_node
)
4854 error ("ambiguous pointer conversion");
4855 result_type
= type1
;
4858 else if (flag_cond_mismatch
)
4859 result_type
= void_type_node
;
4862 error ("type mismatch in conditional expression");
4863 return error_mark_node
;
4867 if (TREE_CODE (result_type
) == POINTER_TYPE
4868 && TREE_CODE (TREE_TYPE (result_type
)) == METHOD_TYPE
)
4869 result_type
= build_ptrmemfunc_type (result_type
);
4871 if (result_type
!= TREE_TYPE (op1
))
4872 op1
= convert_and_check (result_type
, op1
);
4873 if (result_type
!= TREE_TYPE (op2
))
4874 op2
= convert_and_check (result_type
, op2
);
4877 /* XXX delete me, I've been here for years. */
4878 if (IS_AGGR_TYPE_CODE (code1
))
4880 result_type
= TREE_TYPE (op1
);
4881 if (TREE_CONSTANT (ifexp
))
4882 return (integer_zerop (ifexp
) ? op2
: op1
);
4884 if (TYPE_MODE (result_type
) == BLKmode
)
4886 register tree tempvar
4887 = build_decl (VAR_DECL
, NULL_TREE
, result_type
);
4888 register tree xop1
= build_modify_expr (tempvar
, NOP_EXPR
, op1
);
4889 register tree xop2
= build_modify_expr (tempvar
, NOP_EXPR
, op2
);
4890 register tree result
= fold (build (COND_EXPR
, result_type
,
4891 ifexp
, xop1
, xop2
));
4893 layout_decl (tempvar
, 0);
4894 /* No way to handle variable-sized objects here.
4895 I fear that the entire handling of BLKmode conditional exprs
4896 needs to be redone. */
4897 my_friendly_assert (TREE_CONSTANT (DECL_SIZE (tempvar
)), 315);
4899 = assign_stack_local (DECL_MODE (tempvar
),
4900 (TREE_INT_CST_LOW (DECL_SIZE (tempvar
))
4901 + BITS_PER_UNIT
- 1)
4905 TREE_SIDE_EFFECTS (result
)
4906 = TREE_SIDE_EFFECTS (ifexp
) | TREE_SIDE_EFFECTS (op1
)
4907 | TREE_SIDE_EFFECTS (op2
);
4908 return build (COMPOUND_EXPR
, result_type
, result
, tempvar
);
4913 if (TREE_CONSTANT (ifexp
))
4914 return integer_zerop (ifexp
) ? op2
: op1
;
4916 return convert_from_reference
4917 (fold (build (COND_EXPR
, result_type
, ifexp
, op1
, op2
)));
4920 /* Handle overloading of the ',' operator when needed. Otherwise,
4921 this function just builds an expression list. */
4923 build_x_compound_expr (list
)
4926 tree rest
= TREE_CHAIN (list
);
4929 if (rest
== NULL_TREE
)
4930 return build_compound_expr (list
);
4932 result
= build_opfncall (COMPOUND_EXPR
, LOOKUP_NORMAL
,
4933 TREE_VALUE (list
), TREE_VALUE (rest
), NULL_TREE
);
4935 return build_x_compound_expr (tree_cons (NULL_TREE
, result
, TREE_CHAIN (rest
)));
4937 if (! TREE_SIDE_EFFECTS (TREE_VALUE (list
)))
4939 /* the left-hand operand of a comma expression is like an expression
4940 statement: we should warn if it doesn't have any side-effects,
4941 unless it was explicitly cast to (void). */
4942 if ((extra_warnings
|| warn_unused
)
4943 && !(TREE_CODE (TREE_VALUE(list
)) == CONVERT_EXPR
4944 && TREE_TYPE (TREE_VALUE(list
)) == void_type_node
))
4945 warning("left-hand operand of comma expression has no effect");
4947 #if 0 /* this requires a gcc backend patch to export warn_if_unused_value */
4948 else if (warn_unused
)
4949 warn_if_unused_value (TREE_VALUE(list
));
4952 return build_compound_expr (tree_cons (NULL_TREE
, TREE_VALUE (list
),
4953 build_tree_list (NULL_TREE
, build_x_compound_expr (rest
))));
4956 /* Given a list of expressions, return a compound expression
4957 that performs them all and returns the value of the last of them. */
4960 build_compound_expr (list
)
4965 if (TREE_READONLY_DECL_P (TREE_VALUE (list
)))
4966 TREE_VALUE (list
) = decl_constant_value (TREE_VALUE (list
));
4968 if (TREE_CHAIN (list
) == 0)
4970 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
4971 Strip such NOP_EXPRs, since LIST is used in non-lvalue context. */
4972 if (TREE_CODE (list
) == NOP_EXPR
4973 && TREE_TYPE (list
) == TREE_TYPE (TREE_OPERAND (list
, 0)))
4974 list
= TREE_OPERAND (list
, 0);
4976 /* Convert arrays to pointers. */
4977 if (TREE_CODE (TREE_TYPE (TREE_VALUE (list
))) == ARRAY_TYPE
)
4978 return default_conversion (TREE_VALUE (list
));
4980 return TREE_VALUE (list
);
4983 rest
= build_compound_expr (TREE_CHAIN (list
));
4985 /* When pedantic, a compound expression cannot be a constant expression. */
4986 if (! TREE_SIDE_EFFECTS (TREE_VALUE (list
)) && ! pedantic
)
4989 return build (COMPOUND_EXPR
, TREE_TYPE (rest
),
4990 break_out_cleanups (TREE_VALUE (list
)), rest
);
5000 return (TREE_CODE (t
) == INTEGER_CST
&& integer_zerop (t
));
5003 tree
build_static_cast (type
, expr
)
5006 return build_c_cast (type
, expr
, 0);
5009 tree
build_reinterpret_cast (type
, expr
)
5012 tree intype
= TREE_TYPE (expr
);
5014 if (TYPE_PTRMEMFUNC_P (type
))
5015 type
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
5016 if (TYPE_PTRMEMFUNC_P (intype
))
5017 intype
= TYPE_PTRMEMFUNC_FN_TYPE (intype
);
5019 if (! POINTER_TYPE_P (type
) && ! TREE_CODE (type
) == INTEGER_TYPE
)
5021 cp_error ("reinterpret_cast cannot convert to type `%T'", type
);
5022 return error_mark_node
;
5024 if (! POINTER_TYPE_P (intype
) && ! TREE_CODE (intype
) == INTEGER_TYPE
)
5026 cp_error ("reinterpret_cast cannot convert from type `%T'", type
);
5027 return error_mark_node
;
5029 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_CODE (intype
) != POINTER_TYPE
)
5031 cp_error ("reinterpret_cast cannot convert non-pointer type `%T' to `%T'",
5033 return error_mark_node
;
5035 if (TREE_CODE (intype
) == INTEGER_TYPE
&& TREE_CODE (type
) != POINTER_TYPE
)
5037 cp_error ("reinterpret_cast cannot convert `%T' to non-pointer type `%T'",
5039 return error_mark_node
;
5042 if (TREE_CODE (type
) == POINTER_TYPE
&& TREE_CODE (intype
) == POINTER_TYPE
)
5043 expr
= convert (ptr_type_node
, expr
);
5045 return build_c_cast (type
, expr
, 0);
5048 tree
build_const_cast (type
, expr
)
5051 tree intype
= TREE_TYPE (expr
);
5054 if (type
== error_mark_node
|| expr
== error_mark_node
)
5055 return error_mark_node
;
5057 if (TYPE_PTRMEMFUNC_P (type
))
5058 type
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
5059 if (TYPE_PTRMEMFUNC_P (intype
))
5060 intype
= TYPE_PTRMEMFUNC_FN_TYPE (intype
);
5062 if (! POINTER_TYPE_P (type
))
5064 cp_error ("const_cast cannot convert to non-pointer type `%T'", type
);
5065 return error_mark_node
;
5067 if (TREE_CODE (type
) == REFERENCE_TYPE
&& ! real_lvalue_p (expr
))
5069 cp_error ("const_cast cannot convert rvalue to type `%T'", type
);
5070 return error_mark_node
;
5072 if (TREE_CODE (type
) == POINTER_TYPE
&& TREE_CODE (intype
) != POINTER_TYPE
)
5074 cp_error ("const_cast cannot convert non-pointer type `%T' to type `%T'",
5076 return error_mark_node
;
5079 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5081 t1
= TREE_TYPE (type
);
5086 t1
= TREE_TYPE (type
);
5087 t2
= TREE_TYPE (intype
);
5089 for (; TREE_CODE (t1
) == POINTER_TYPE
&& TREE_CODE (t2
) == POINTER_TYPE
;
5090 t1
= TREE_TYPE (t1
), t2
= TREE_TYPE (t2
))
5094 if (TREE_CODE (t1
) == OFFSET_TYPE
&& TREE_CODE (t2
) == OFFSET_TYPE
)
5096 if (TYPE_OFFSET_BASETYPE (t1
) != TYPE_OFFSET_BASETYPE (t2
))
5098 cp_error ("const_cast cannot convert between pointers to members of different types `%T' and `%T'",
5099 TYPE_OFFSET_BASETYPE (t2
), TYPE_OFFSET_BASETYPE (t1
));
5100 return error_mark_node
;
5102 t1
= TREE_TYPE (t1
);
5103 t2
= TREE_TYPE (t2
);
5106 if (TYPE_MAIN_VARIANT (t1
) != TYPE_MAIN_VARIANT (t2
))
5108 cp_error ("const_cast cannot convert unrelated type `%T' to `%T'",
5110 return error_mark_node
;
5113 return build_c_cast (type
, expr
, 0);
5116 /* Build an expression representing a cast to type TYPE of expression EXPR.
5118 ALLOW_NONCONVERTING is true if we should allow non-converting constructors
5119 when doing the cast. */
5122 build_c_cast (type
, expr
, allow_nonconverting
)
5125 int allow_nonconverting
;
5127 register tree value
= expr
;
5129 if (type
== error_mark_node
|| expr
== error_mark_node
)
5130 return error_mark_node
;
5132 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5133 Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */
5134 if (TREE_CODE (type
) != REFERENCE_TYPE
5135 && TREE_CODE (value
) == NOP_EXPR
5136 && TREE_TYPE (value
) == TREE_TYPE (TREE_OPERAND (value
, 0)))
5137 value
= TREE_OPERAND (value
, 0);
5139 if (TREE_TYPE (expr
)
5140 && TREE_CODE (TREE_TYPE (expr
)) == OFFSET_TYPE
5141 && TREE_CODE (type
) != OFFSET_TYPE
)
5142 value
= resolve_offset_ref (value
);
5144 if (TREE_CODE (type
) == ARRAY_TYPE
)
5146 /* Allow casting from T1* to T2[] because Cfront allows it.
5147 NIHCL uses it. It is not valid ANSI C however, and hence, not
5149 if (TREE_CODE (TREE_TYPE (expr
)) == POINTER_TYPE
)
5152 pedwarn ("ANSI C++ forbids casting to an array type");
5153 type
= build_pointer_type (TREE_TYPE (type
));
5157 error ("ANSI C++ forbids casting to an array type");
5158 return error_mark_node
;
5162 if (TREE_CODE (type
) == FUNCTION_TYPE
5163 || TREE_CODE (type
) == METHOD_TYPE
)
5165 cp_error ("casting to function type `%T'", type
);
5166 return error_mark_node
;
5169 if (IS_SIGNATURE (type
))
5171 error ("cast specifies signature type");
5172 return error_mark_node
;
5175 /* If there's only one function in the overloaded space,
5177 if (TREE_CODE (value
) == TREE_LIST
5178 && TREE_CHAIN (value
) == NULL_TREE
)
5179 value
= TREE_VALUE (value
);
5181 if (TREE_CODE (type
) == VOID_TYPE
)
5182 value
= build1 (CONVERT_EXPR
, type
, value
);
5183 else if (TREE_TYPE (value
) == NULL_TREE
5184 || type_unknown_p (value
))
5186 value
= instantiate_type (type
, value
, 1);
5188 if (value
== error_mark_node
)
5189 return error_mark_node
;
5196 /* Convert functions and arrays to pointers and
5197 convert references to their expanded types,
5198 but don't convert any other types. */
5199 if (TREE_CODE (TREE_TYPE (value
)) == FUNCTION_TYPE
5200 || TREE_CODE (TREE_TYPE (value
)) == METHOD_TYPE
5201 || TREE_CODE (TREE_TYPE (value
)) == ARRAY_TYPE
5202 || TREE_CODE (TREE_TYPE (value
)) == REFERENCE_TYPE
)
5203 value
= default_conversion (value
);
5204 otype
= TREE_TYPE (value
);
5206 /* Optionally warn about potentially worrisome casts. */
5209 && TREE_CODE (type
) == POINTER_TYPE
5210 && TREE_CODE (otype
) == POINTER_TYPE
)
5212 /* For C++ we make these regular warnings, rather than
5213 softening them into pedwarns. */
5214 if (TYPE_VOLATILE (TREE_TYPE (otype
))
5215 && ! TYPE_VOLATILE (TREE_TYPE (type
)))
5216 warning ("cast discards `volatile' from pointer target type");
5217 if (TYPE_READONLY (TREE_TYPE (otype
))
5218 && ! TYPE_READONLY (TREE_TYPE (type
)))
5219 warning ("cast discards `const' from pointer target type");
5222 /* Warn about possible alignment problems. */
5223 if (STRICT_ALIGNMENT
&& warn_cast_align
5224 && TREE_CODE (type
) == POINTER_TYPE
5225 && TREE_CODE (otype
) == POINTER_TYPE
5226 && TREE_CODE (TREE_TYPE (otype
)) != VOID_TYPE
5227 && TREE_CODE (TREE_TYPE (otype
)) != FUNCTION_TYPE
5228 && TYPE_ALIGN (TREE_TYPE (type
)) > TYPE_ALIGN (TREE_TYPE (otype
)))
5229 warning ("cast increases required alignment of target type");
5232 if (TREE_CODE (type
) == INTEGER_TYPE
5233 && TREE_CODE (otype
) == POINTER_TYPE
5234 && TYPE_PRECISION (type
) != TYPE_PRECISION (otype
))
5235 warning ("cast from pointer to integer of different size");
5237 if (TREE_CODE (type
) == POINTER_TYPE
5238 && TREE_CODE (otype
) == INTEGER_TYPE
5239 && TYPE_PRECISION (type
) != TYPE_PRECISION (otype
)
5240 /* Don't warn about converting 0 to pointer,
5241 provided the 0 was explicit--not cast or made by folding. */
5242 && !(TREE_CODE (value
) == INTEGER_CST
&& integer_zerop (value
)))
5243 warning ("cast to pointer from integer of different size");
5246 flag
= allow_nonconverting
? CONV_NONCONVERTING
: 0;
5248 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5249 value
= (convert_from_reference
5250 (convert_to_reference (type
, value
, CONV_OLD_CONVERT
|flag
,
5251 LOOKUP_COMPLAIN
, NULL_TREE
)));
5256 if (TREE_READONLY_DECL_P (value
))
5257 value
= decl_constant_value (value
);
5260 value
= convert_force (type
, value
, flag
);
5262 /* Ignore any integer overflow caused by the cast. */
5263 if (TREE_CODE (value
) == INTEGER_CST
)
5265 TREE_OVERFLOW (value
) = TREE_OVERFLOW (ovalue
);
5266 TREE_CONSTANT_OVERFLOW (value
) = TREE_CONSTANT_OVERFLOW (ovalue
);
5271 /* Always produce some operator for an explicit cast,
5272 so we can tell (for -pedantic) that the cast is no lvalue.
5273 Also, pedantically, don't let (void *) (FOO *) 0 be a null
5274 pointer constant. */
5275 if (TREE_CODE (type
) != REFERENCE_TYPE
5278 && TREE_CODE (value
) == INTEGER_CST
5279 && TREE_CODE (expr
) == INTEGER_CST
5280 && TREE_CODE (TREE_TYPE (expr
)) != INTEGER_TYPE
)))
5281 value
= non_lvalue (value
);
5287 /* Build an assignment expression of lvalue LHS from value RHS.
5289 In C++, if the left hand side of the assignment is a REFERENCE_TYPE,
5290 that reference becomes deferenced down to it base type. */
5292 /* Return a reference to the BASE_INDEX part of EXPR. TYPE is
5293 the type to which BASE_INDEX applies. */
5295 get_base_ref (type
, base_index
, expr
)
5300 tree binfos
= TYPE_BINFO_BASETYPES (type
);
5301 tree base_binfo
= TREE_VEC_ELT (binfos
, base_index
);
5304 if (TREE_CODE (expr
) == ARRAY_REF
5305 || ! BINFO_OFFSET_ZEROP (base_binfo
)
5306 || TREE_VIA_VIRTUAL (base_binfo
)
5307 || TYPE_MODE (type
) != TYPE_MODE (BINFO_TYPE (base_binfo
)))
5309 tree addr
= build_unary_op (ADDR_EXPR
, expr
, 0);
5310 ref
= build_indirect_ref (convert_pointer_to (base_binfo
, addr
),
5315 ref
= copy_node (expr
);
5316 TREE_TYPE (ref
) = BINFO_TYPE (base_binfo
);
5321 /* Build an assignment expression of lvalue LHS from value RHS.
5322 MODIFYCODE is the code for a binary operator that we use
5323 to combine the old value of LHS with RHS to get the new value.
5324 Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.
5326 C++: If MODIFYCODE is INIT_EXPR, then leave references unbashed.
5328 `build_modify_expr_1' implements recursive part of memberwise
5329 assignment operation. */
5331 build_modify_expr_1 (lhs
, modifycode
, rhs
, basetype_path
)
5333 enum tree_code modifycode
;
5336 register tree result
;
5338 tree lhstype
= TREE_TYPE (lhs
);
5339 tree olhstype
= lhstype
;
5341 /* Avoid duplicate error messages from operands that had errors. */
5342 if (TREE_CODE (lhs
) == ERROR_MARK
|| TREE_CODE (rhs
) == ERROR_MARK
)
5343 return error_mark_node
;
5345 /* If a binary op has been requested, combine the old LHS value with the RHS
5346 producing the value we should actually store into the LHS. */
5348 if (modifycode
== INIT_EXPR
)
5350 else if (modifycode
== NOP_EXPR
)
5352 /* must deal with overloading of `operator=' here. */
5353 if (TREE_CODE (lhstype
) == REFERENCE_TYPE
)
5354 lhstype
= TREE_TYPE (lhstype
);
5360 lhs
= stabilize_reference (lhs
);
5361 newrhs
= build_binary_op (modifycode
, lhs
, rhs
, 1);
5362 modifycode
= NOP_EXPR
;
5365 /* If storing into a structure or union member,
5366 it has probably been given type `int'.
5367 Compute the type that would go with
5368 the actual amount of storage the member occupies. */
5370 if (TREE_CODE (lhs
) == COMPONENT_REF
5371 && (TREE_CODE (lhstype
) == INTEGER_TYPE
5372 || TREE_CODE (lhstype
) == REAL_TYPE
5373 || TREE_CODE (lhstype
) == ENUMERAL_TYPE
))
5374 lhstype
= TREE_TYPE (get_unwidened (lhs
, 0));
5376 /* C++: The semantics of C++ differ from those of C when an
5377 assignment of an aggregate is desired. Assignment in C++ is
5378 now defined as memberwise assignment of non-static members
5379 and base class objects. This rule applies recursively
5380 until a member of a built-in type is found.
5382 Also, we cannot do a bit-wise copy of aggregates which
5383 contain virtual function table pointers. Those
5384 pointer values must be preserved through the copy.
5385 However, this is handled in expand_expr, and not here.
5386 This is because much better code can be generated at
5387 that stage than this one. */
5388 if (TREE_CODE (lhstype
) == RECORD_TYPE
5389 && TYPE_LANG_SPECIFIC (lhstype
)
5390 && TYPE_MAIN_VARIANT (lhstype
) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs
)))
5395 /* Perform operation on object. */
5396 if (modifycode
== INIT_EXPR
&& TYPE_HAS_INIT_REF (lhstype
))
5398 result
= build_method_call (lhs
, constructor_name_full (lhstype
),
5399 build_tree_list (NULL_TREE
, rhs
),
5400 basetype_path
, LOOKUP_NORMAL
);
5401 return build_indirect_ref (result
, NULL_PTR
);
5403 else if (modifycode
== NOP_EXPR
)
5405 /* `operator=' is not an inheritable operator; see 13.4.3. */
5406 if (TYPE_LANG_SPECIFIC (lhstype
) && TYPE_HAS_ASSIGNMENT (lhstype
))
5408 result
= build_opfncall (MODIFY_EXPR
, LOOKUP_NORMAL
,
5409 lhs
, rhs
, make_node (NOP_EXPR
));
5410 if (result
== NULL_TREE
)
5411 return error_mark_node
;
5416 if (TYPE_USES_VIRTUAL_BASECLASSES (lhstype
)
5417 || (modifycode
== NOP_EXPR
&& TYPE_GETS_ASSIGNMENT (lhstype
))
5418 || (modifycode
== INIT_EXPR
&& TYPE_GETS_INIT_REF (lhstype
)))
5420 tree binfos
= BINFO_BASETYPES (TYPE_BINFO (lhstype
));
5423 if (binfos
!= NULL_TREE
)
5424 /* Perform operation on each member, depth-first, left-right. */
5425 for (i
= 0; i
<= TREE_VEC_LENGTH (binfos
)-1; i
++)
5427 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
5428 tree base_lhs
, base_rhs
;
5431 /* Assignments from virtual baseclasses handled elsewhere. */
5432 if (TREE_VIA_VIRTUAL (base_binfo
))
5435 base_lhs
= get_base_ref (lhstype
, i
, lhs
);
5436 base_rhs
= get_base_ref (lhstype
, i
, newrhs
);
5438 BINFO_INHERITANCE_CHAIN (base_binfo
) = basetype_path
;
5440 = build_modify_expr_1 (base_lhs
, modifycode
, base_rhs
,
5443 /* We either get back a compound stmt, or a simple one. */
5444 if (new_result
&& TREE_CODE (new_result
) == TREE_LIST
)
5445 new_result
= build_compound_expr (new_result
);
5446 result
= tree_cons (NULL_TREE
, new_result
, result
);
5449 for (elt
= TYPE_FIELDS (lhstype
); elt
; elt
= TREE_CHAIN (elt
))
5451 tree vbases
= NULL_TREE
;
5452 tree elt_lhs
, elt_rhs
;
5454 if (TREE_CODE (elt
) != FIELD_DECL
)
5457 && (VFIELD_NAME_P (DECL_NAME (elt
))
5458 || VBASE_NAME_P (DECL_NAME (elt
))))
5461 if (TREE_READONLY (elt
)
5462 || TREE_CODE (TREE_TYPE (elt
)) == REFERENCE_TYPE
)
5464 cp_error ("cannot generate default `%T::operator ='",
5466 if (TREE_CODE (TREE_TYPE (elt
)) == REFERENCE_TYPE
)
5467 cp_error_at ("because member `%#D' is a reference", elt
);
5469 cp_error_at ("because member `%#D' is const", elt
);
5471 return error_mark_node
;
5474 if (IS_AGGR_TYPE (TREE_TYPE (elt
))
5475 && TYPE_LANG_SPECIFIC (TREE_TYPE (elt
)))
5476 vbases
= CLASSTYPE_VBASECLASSES (TREE_TYPE (elt
));
5478 elt_lhs
= build (COMPONENT_REF
, TREE_TYPE (elt
), lhs
, elt
);
5479 elt_rhs
= build (COMPONENT_REF
, TREE_TYPE (elt
), newrhs
, elt
);
5480 /* It is not always safe to go through `build_modify_expr_1'
5481 when performing element-wise copying. This is because
5482 an element may be of ARRAY_TYPE, which will not
5483 be properly copied as a naked element. */
5484 if (TREE_CODE (TREE_TYPE (elt
)) == RECORD_TYPE
5485 && TYPE_LANG_SPECIFIC (TREE_TYPE (elt
)))
5486 basetype_path
= TYPE_BINFO (TREE_TYPE (elt
));
5490 tree elt_lhs_addr
= build_unary_op (ADDR_EXPR
, elt_lhs
, 0);
5491 tree elt_rhs_addr
= build_unary_op (ADDR_EXPR
, elt_rhs
, 0);
5493 elt_lhs_addr
= convert_pointer_to (vbases
, elt_lhs_addr
);
5494 elt_rhs_addr
= convert_pointer_to (vbases
, elt_rhs_addr
);
5496 = tree_cons (NULL_TREE
,
5498 (build_indirect_ref (elt_lhs_addr
, NULL_PTR
),
5500 build_indirect_ref (elt_rhs_addr
, NULL_PTR
),
5503 if (TREE_VALUE (result
) == error_mark_node
)
5504 return error_mark_node
;
5505 vbases
= TREE_CHAIN (vbases
);
5507 elt_lhs
= build_modify_expr_1 (elt_lhs
, modifycode
, elt_rhs
,
5509 result
= tree_cons (NULL_TREE
, elt_lhs
, result
);
5513 return build_compound_expr (result
);
5514 /* No fields to move. */
5515 return integer_zero_node
;
5519 result
= build (modifycode
== NOP_EXPR
? MODIFY_EXPR
: INIT_EXPR
,
5520 void_type_node
, lhs
, rhs
);
5521 TREE_SIDE_EFFECTS (result
) = 1;
5526 result
= build_modify_expr (lhs
, modifycode
, newrhs
);
5527 /* ARRAY_TYPEs cannot be converted to anything meaningful,
5528 and leaving it there screws up `build_compound_expr' when
5529 it tries to defaultly convert everything. */
5530 if (TREE_CODE (TREE_TYPE (result
)) == ARRAY_TYPE
)
5531 TREE_TYPE (result
) = void_type_node
;
5536 /* Taken from expr.c:
5537 Subroutine of expand_expr:
5538 record the non-copied parts (LIST) of an expr (LHS), and return a list
5539 which specifies the initial values of these parts. */
5542 init_noncopied_parts (lhs
, list
)
5549 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
5550 if (TREE_CODE (TREE_VALUE (tail
)) == TREE_LIST
)
5551 parts
= chainon (parts
, init_noncopied_parts (lhs
, TREE_VALUE (tail
)));
5554 tree part
= TREE_VALUE (tail
);
5555 tree part_type
= TREE_TYPE (part
);
5556 tree to_be_initialized
= build (COMPONENT_REF
, part_type
, lhs
, part
);
5557 parts
= tree_cons (TREE_PURPOSE (tail
), to_be_initialized
, parts
);
5563 expand_target_expr (t
)
5566 tree xval
= make_node (RTL_EXPR
);
5569 do_pending_stack_adjust ();
5570 start_sequence_for_rtl_expr (xval
);
5572 rtxval
= expand_expr (t
, NULL
, VOIDmode
, 0);
5573 do_pending_stack_adjust ();
5574 TREE_SIDE_EFFECTS (xval
) = 1;
5575 RTL_EXPR_SEQUENCE (xval
) = get_insns ();
5577 RTL_EXPR_RTL (xval
) = rtxval
;
5578 TREE_TYPE (xval
) = TREE_TYPE (t
);
5582 /* Build an assignment expression of lvalue LHS from value RHS.
5583 MODIFYCODE is the code for a binary operator that we use
5584 to combine the old value of LHS with RHS to get the new value.
5585 Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.
5587 C++: If MODIFYCODE is INIT_EXPR, then leave references unbashed.
5590 build_modify_expr (lhs
, modifycode
, rhs
)
5592 enum tree_code modifycode
;
5595 register tree result
;
5597 tree lhstype
= TREE_TYPE (lhs
);
5598 tree olhstype
= lhstype
;
5601 /* Avoid duplicate error messages from operands that had errors. */
5602 if (TREE_CODE (lhs
) == ERROR_MARK
|| TREE_CODE (rhs
) == ERROR_MARK
)
5603 return error_mark_node
;
5605 /* Types that aren't fully specified cannot be used in assignments. */
5606 lhs
= require_complete_type (lhs
);
5608 /* Decide early if we are going to protect RHS from GC
5609 before assigning it to LHS. */
5610 if (type_needs_gc_entry (TREE_TYPE (rhs
))
5611 && ! value_safe_from_gc (lhs
, rhs
))
5612 rhs
= protect_value_from_gc (lhs
, rhs
);
5616 /* Handle assignment to signature pointers/refs. */
5618 if (TYPE_LANG_SPECIFIC (lhstype
) &&
5619 (IS_SIGNATURE_POINTER (lhstype
) || IS_SIGNATURE_REFERENCE (lhstype
)))
5621 return build_signature_pointer_constructor (lhs
, rhs
);
5624 /* Handle control structure constructs used as "lvalues". */
5626 switch (TREE_CODE (lhs
))
5628 /* Handle --foo = 5; as these are valid constructs in C++ */
5629 case PREDECREMENT_EXPR
:
5630 case PREINCREMENT_EXPR
:
5631 if (TREE_SIDE_EFFECTS (TREE_OPERAND (lhs
, 0)))
5632 lhs
= build (TREE_CODE (lhs
), TREE_TYPE (lhs
),
5633 stabilize_reference (TREE_OPERAND (lhs
, 0)));
5634 return build (COMPOUND_EXPR
, lhstype
,
5636 build_modify_expr (TREE_OPERAND (lhs
, 0),
5639 /* Handle (a, b) used as an "lvalue". */
5641 newrhs
= build_modify_expr (TREE_OPERAND (lhs
, 1),
5643 if (TREE_CODE (newrhs
) == ERROR_MARK
)
5644 return error_mark_node
;
5645 return build (COMPOUND_EXPR
, lhstype
,
5646 TREE_OPERAND (lhs
, 0), newrhs
);
5649 newrhs
= build_modify_expr (TREE_OPERAND (lhs
, 0), modifycode
, rhs
);
5650 if (TREE_CODE (newrhs
) == ERROR_MARK
)
5651 return error_mark_node
;
5652 return build (COMPOUND_EXPR
, lhstype
, lhs
, newrhs
);
5654 /* Handle (a ? b : c) used as an "lvalue". */
5656 rhs
= save_expr (rhs
);
5658 /* Produce (a ? (b = rhs) : (c = rhs))
5659 except that the RHS goes through a save-expr
5660 so the code to compute it is only emitted once. */
5662 = build_conditional_expr (TREE_OPERAND (lhs
, 0),
5663 build_modify_expr (convert (TREE_TYPE (lhs
), TREE_OPERAND (lhs
, 1)),
5665 build_modify_expr (convert (TREE_TYPE (lhs
), TREE_OPERAND (lhs
, 2)),
5667 if (TREE_CODE (cond
) == ERROR_MARK
)
5669 /* Make sure the code to compute the rhs comes out
5670 before the split. */
5671 return build (COMPOUND_EXPR
, TREE_TYPE (lhs
),
5672 /* Case to void to suppress warning
5673 from warn_if_unused_value. */
5674 convert (void_type_node
, rhs
), cond
);
5678 if (TREE_CODE (lhs
) == OFFSET_REF
)
5680 if (TREE_OPERAND (lhs
, 0) == NULL_TREE
)
5682 /* Static class member? */
5683 tree member
= TREE_OPERAND (lhs
, 1);
5684 if (TREE_CODE (member
) == VAR_DECL
)
5688 compiler_error ("invalid static class member");
5689 return error_mark_node
;
5693 lhs
= resolve_offset_ref (lhs
);
5695 olhstype
= lhstype
= TREE_TYPE (lhs
);
5698 if (TREE_CODE (lhstype
) == REFERENCE_TYPE
5699 && modifycode
!= INIT_EXPR
)
5701 lhs
= convert_from_reference (lhs
);
5702 olhstype
= lhstype
= TREE_TYPE (lhs
);
5705 /* If a binary op has been requested, combine the old LHS value with the RHS
5706 producing the value we should actually store into the LHS. */
5708 if (modifycode
== INIT_EXPR
)
5710 if (! IS_AGGR_TYPE (lhstype
))
5711 /* Do the default thing */;
5712 else if (! TYPE_HAS_CONSTRUCTOR (lhstype
))
5714 cp_error ("`%T' has no constructors", lhstype
);
5715 return error_mark_node
;
5717 else if (TYPE_HAS_TRIVIAL_INIT_REF (lhstype
)
5718 && TYPE_MAIN_VARIANT (lhstype
) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs
)))
5719 /* Do the default thing */;
5722 result
= build_method_call (lhs
, constructor_name_full (lhstype
),
5723 build_tree_list (NULL_TREE
, rhs
),
5724 NULL_TREE
, LOOKUP_NORMAL
);
5725 if (result
== NULL_TREE
)
5726 return error_mark_node
;
5730 else if (modifycode
== NOP_EXPR
)
5733 /* `operator=' is not an inheritable operator. */
5734 if (! IS_AGGR_TYPE (lhstype
))
5735 /* Do the default thing */;
5736 else if (! TYPE_HAS_ASSIGNMENT (lhstype
))
5738 cp_error ("`%T' does not define operator=", lhstype
);
5739 return error_mark_node
;
5741 else if (TYPE_HAS_TRIVIAL_ASSIGN_REF (lhstype
)
5742 && TYPE_MAIN_VARIANT (lhstype
) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs
)))
5745 /* If we care about this, do overload resolution. */
5746 build_opfncall (MODIFY_EXPR
, LOOKUP_NORMAL
,
5747 lhs
, rhs
, make_node (NOP_EXPR
));
5749 /* Do the default thing */;
5753 result
= build_opfncall (MODIFY_EXPR
, LOOKUP_NORMAL
,
5754 lhs
, rhs
, make_node (NOP_EXPR
));
5755 if (result
== NULL_TREE
)
5756 return error_mark_node
;
5760 /* Treat `operator=' as an inheritable operator. */
5761 if (TYPE_LANG_SPECIFIC (lhstype
) && TYPE_GETS_ASSIGNMENT (lhstype
))
5763 tree orig_lhstype
= lhstype
;
5764 while (! TYPE_HAS_ASSIGNMENT (lhstype
))
5766 int i
, n_baseclasses
= CLASSTYPE_N_BASECLASSES (lhstype
);
5767 tree basetype
= NULL_TREE
;
5768 for (i
= 0; i
< n_baseclasses
; i
++)
5769 if (TYPE_GETS_ASSIGNMENT (TYPE_BINFO_BASETYPE (lhstype
, i
)))
5771 if (basetype
!= NULL_TREE
)
5773 message_2_types (error
, "base classes `%s' and `%s' both have operator ='",
5775 TYPE_BINFO_BASETYPE (lhstype
, i
));
5776 return error_mark_node
;
5778 basetype
= TYPE_BINFO_BASETYPE (lhstype
, i
);
5782 if (orig_lhstype
!= lhstype
)
5784 lhs
= build_indirect_ref (convert_pointer_to (lhstype
,
5785 build_unary_op (ADDR_EXPR
, lhs
, 0)), NULL_PTR
);
5786 if (lhs
== error_mark_node
)
5788 cp_error ("conversion to private basetype `%T'", lhstype
);
5789 return error_mark_node
;
5792 result
= build_opfncall (MODIFY_EXPR
, LOOKUP_NORMAL
,
5793 lhs
, rhs
, make_node (NOP_EXPR
));
5794 if (result
== NULL_TREE
)
5795 return error_mark_node
;
5801 else if (PROMOTES_TO_AGGR_TYPE (lhstype
, REFERENCE_TYPE
))
5803 /* This case must convert to some sort of lvalue that
5804 can participate in an op= operation. */
5807 if (build_default_binary_type_conversion (modifycode
, &lhs_tmp
, &rhs_tmp
))
5809 lhs
= stabilize_reference (lhs_tmp
);
5810 /* Forget is was ever anything else. */
5811 olhstype
= lhstype
= TREE_TYPE (lhs
);
5812 newrhs
= build_binary_op (modifycode
, lhs
, rhs_tmp
, 1);
5816 cp_error ("no match for `%O(%#T, %#T)'", modifycode
,
5817 TREE_TYPE (lhs
), TREE_TYPE (rhs
));
5818 return error_mark_node
;
5823 lhs
= stabilize_reference (lhs
);
5824 newrhs
= build_binary_op (modifycode
, lhs
, rhs
, 1);
5827 /* Handle a cast used as an "lvalue".
5828 We have already performed any binary operator using the value as cast.
5829 Now convert the result to the cast type of the lhs,
5830 and then true type of the lhs and store it there;
5831 then convert result back to the cast type to be the value
5832 of the assignment. */
5834 switch (TREE_CODE (lhs
))
5839 case FIX_TRUNC_EXPR
:
5840 case FIX_FLOOR_EXPR
:
5841 case FIX_ROUND_EXPR
:
5843 if (TREE_CODE (TREE_TYPE (newrhs
)) == ARRAY_TYPE
5844 || TREE_CODE (TREE_TYPE (newrhs
)) == FUNCTION_TYPE
5845 || TREE_CODE (TREE_TYPE (newrhs
)) == METHOD_TYPE
5846 || TREE_CODE (TREE_TYPE (newrhs
)) == OFFSET_TYPE
)
5847 newrhs
= default_conversion (newrhs
);
5849 tree inner_lhs
= TREE_OPERAND (lhs
, 0);
5851 if (! lvalue_p (lhs
) && pedantic
)
5852 pedwarn ("cast to non-reference type used as lvalue");
5854 result
= build_modify_expr (inner_lhs
, NOP_EXPR
,
5855 convert (TREE_TYPE (inner_lhs
),
5856 convert (lhstype
, newrhs
)));
5857 if (TREE_CODE (result
) == ERROR_MARK
)
5859 return convert (TREE_TYPE (lhs
), result
);
5863 /* Now we have handled acceptable kinds of LHS that are not truly lvalues.
5864 Reject anything strange now. */
5866 if (!lvalue_or_else (lhs
, "assignment"))
5867 return error_mark_node
;
5869 GNU_xref_assign (lhs
);
5871 /* Warn about storing in something that is `const'. */
5872 /* For C++, don't warn if this is initialization. */
5873 if (modifycode
!= INIT_EXPR
5874 /* For assignment to `const' signature pointer/reference fields,
5875 don't warn either, we already printed a better message before. */
5876 && ! (TREE_CODE (lhs
) == COMPONENT_REF
5877 && (IS_SIGNATURE_POINTER (TREE_TYPE (TREE_OPERAND (lhs
, 0)))
5878 || IS_SIGNATURE_REFERENCE (TREE_TYPE (TREE_OPERAND (lhs
, 0)))))
5879 && (TREE_READONLY (lhs
) || TYPE_READONLY (lhstype
)
5880 || ((TREE_CODE (lhstype
) == RECORD_TYPE
5881 || TREE_CODE (lhstype
) == UNION_TYPE
)
5882 && C_TYPE_FIELDS_READONLY (lhstype
))
5883 || (TREE_CODE (lhstype
) == REFERENCE_TYPE
5884 && TYPE_READONLY (TREE_TYPE (lhstype
)))))
5885 readonly_error (lhs
, "assignment", 0);
5887 /* If storing into a structure or union member,
5888 it has probably been given type `int'.
5889 Compute the type that would go with
5890 the actual amount of storage the member occupies. */
5892 if (TREE_CODE (lhs
) == COMPONENT_REF
5893 && (TREE_CODE (lhstype
) == INTEGER_TYPE
5894 || TREE_CODE (lhstype
) == REAL_TYPE
5895 || TREE_CODE (lhstype
) == ENUMERAL_TYPE
))
5897 lhstype
= TREE_TYPE (get_unwidened (lhs
, 0));
5899 /* If storing in a field that is in actuality a short or narrower
5900 than one, we must store in the field in its actual type. */
5902 if (lhstype
!= TREE_TYPE (lhs
))
5904 lhs
= copy_node (lhs
);
5905 TREE_TYPE (lhs
) = lhstype
;
5909 /* check to see if there is an assignment to `this' */
5910 if (lhs
== current_class_decl
)
5912 if (flag_this_is_variable
> 0
5913 && DECL_NAME (current_function_decl
) != NULL_TREE
5914 && (DECL_NAME (current_function_decl
)
5915 != constructor_name (current_class_type
)))
5916 warning ("assignment to `this' not in constructor or destructor");
5917 current_function_just_assigned_this
= 1;
5920 /* The TREE_TYPE of RHS may be TYPE_UNKNOWN. This can happen
5921 when the type of RHS is not yet known, i.e. its type
5922 is inherited from LHS. */
5923 rhs
= require_instantiated_type (lhstype
, newrhs
, error_mark_node
);
5924 if (rhs
== error_mark_node
)
5925 return error_mark_node
;
5928 if (modifycode
!= INIT_EXPR
)
5930 /* Make modifycode now either a NOP_EXPR or an INIT_EXPR. */
5931 modifycode
= NOP_EXPR
;
5932 /* Reference-bashing */
5933 if (TREE_CODE (lhstype
) == REFERENCE_TYPE
)
5935 tree tmp
= convert_from_reference (lhs
);
5936 lhstype
= TREE_TYPE (tmp
);
5937 if (TYPE_SIZE (lhstype
) == 0)
5939 incomplete_type_error (lhs
, lhstype
);
5940 return error_mark_node
;
5945 if (TREE_CODE (TREE_TYPE (newrhs
)) == REFERENCE_TYPE
)
5947 tree tmp
= convert_from_reference (newrhs
);
5948 if (TYPE_SIZE (TREE_TYPE (tmp
)) == 0)
5950 incomplete_type_error (newrhs
, TREE_TYPE (tmp
));
5951 return error_mark_node
;
5957 if (TREE_SIDE_EFFECTS (lhs
))
5958 lhs
= stabilize_reference (lhs
);
5959 if (TREE_SIDE_EFFECTS (newrhs
))
5960 newrhs
= stabilize_reference (newrhs
);
5963 /* This is now done by generating X(X&) and operator=(X&). */
5964 /* C++: The semantics of C++ differ from those of C when an
5965 assignment of an aggregate is desired. Assignment in C++ is
5966 now defined as memberwise assignment of non-static members
5967 and base class objects. This rule applies recursively
5968 until a member of a built-in type is found.
5970 Also, we cannot do a bit-wise copy of aggregates which
5971 contain virtual function table pointers. Those
5972 pointer values must be preserved through the copy.
5973 However, this is handled in expand_expr, and not here.
5974 This is because much better code can be generated at
5975 that stage than this one. */
5976 if (TREE_CODE (lhstype
) == RECORD_TYPE
5977 && ! TYPE_PTRMEMFUNC_P (lhstype
)
5978 && (TYPE_MAIN_VARIANT (lhstype
) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs
))
5979 || (TREE_CODE (TREE_TYPE (newrhs
)) == RECORD_TYPE
5980 && UNIQUELY_DERIVED_FROM_P (lhstype
, TREE_TYPE (newrhs
)))))
5982 tree vbases
= CLASSTYPE_VBASECLASSES (lhstype
);
5983 tree lhs_addr
= build_unary_op (ADDR_EXPR
, lhs
, 0);
5986 /* Memberwise assignment would cause NEWRHS to be
5987 evaluated for every member that gets assigned.
5988 By wrapping side-effecting exprs in a SAVE_EXPR,
5989 NEWRHS will only be evaluated once. */
5990 if (IS_AGGR_TYPE (TREE_TYPE (newrhs
))
5991 && TREE_SIDE_EFFECTS (newrhs
)
5992 /* This are things we don't have to save. */
5993 && TREE_CODE (newrhs
) != COND_EXPR
5994 && TREE_CODE (newrhs
) != TARGET_EXPR
5995 && TREE_CODE (newrhs
) != WITH_CLEANUP_EXPR
)
5996 /* Call `break_out_cleanups' on NEWRHS in case there are cleanups.
5997 If NEWRHS is a CALL_EXPR that needs a cleanup, failure to do so
5998 will result in expand_expr expanding the call without knowing
5999 that it should run the cleanup. */
6000 newrhs
= save_expr (break_out_cleanups (newrhs
));
6002 if (TREE_CODE (newrhs
) == COND_EXPR
)
6003 rhs_addr
= rationalize_conditional_expr (ADDR_EXPR
, newrhs
);
6005 rhs_addr
= build_unary_op (ADDR_EXPR
, newrhs
, 0);
6007 result
= tree_cons (NULL_TREE
,
6008 convert (build_reference_type (lhstype
), lhs
),
6011 if (! comptypes (TREE_TYPE (lhs_addr
), TREE_TYPE (rhs_addr
), 1))
6012 rhs_addr
= convert_pointer_to (TREE_TYPE (TREE_TYPE (lhs_addr
)), rhs_addr
);
6014 tree noncopied_parts
= NULL_TREE
;
6016 if (TYPE_NONCOPIED_PARTS (lhstype
) != 0)
6017 noncopied_parts
= init_noncopied_parts (lhs
,
6018 TYPE_NONCOPIED_PARTS (lhstype
));
6019 while (noncopied_parts
!= 0)
6021 result
= tree_cons (NULL_TREE
,
6022 build_modify_expr (convert (ptr_type_node
, TREE_VALUE (noncopied_parts
)),
6024 TREE_PURPOSE (noncopied_parts
)),
6026 noncopied_parts
= TREE_CHAIN (noncopied_parts
);
6029 /* Once we have our hands on an address, we must change NEWRHS
6030 to work from there. Otherwise we can get multiple evaluations
6032 if (TREE_CODE (newrhs
) != SAVE_EXPR
)
6033 newrhs
= build_indirect_ref (rhs_addr
, NULL_PTR
);
6037 tree elt_lhs
= convert_pointer_to (vbases
, lhs_addr
);
6038 tree elt_rhs
= convert_pointer_to (vbases
, rhs_addr
);
6040 = tree_cons (NULL_TREE
,
6041 build_modify_expr_1 (build_indirect_ref (elt_lhs
, NULL_PTR
),
6043 build_indirect_ref (elt_rhs
, NULL_PTR
),
6044 TYPE_BINFO (lhstype
)),
6046 if (TREE_VALUE (result
) == error_mark_node
)
6047 return error_mark_node
;
6048 vbases
= TREE_CHAIN (vbases
);
6050 result
= tree_cons (NULL_TREE
,
6051 build_modify_expr_1 (lhs
,
6054 TYPE_BINFO (lhstype
)),
6056 return build_compound_expr (result
);
6060 /* Convert new value to destination type. */
6062 if (TREE_CODE (lhstype
) == ARRAY_TYPE
)
6066 if (! comptypes (lhstype
, TREE_TYPE (rhs
), 0))
6068 cp_error ("incompatible types in assignment of `%T' to `%T'",
6069 TREE_TYPE (rhs
), lhstype
);
6070 return error_mark_node
;
6073 /* Allow array assignment in compiler-generated code. */
6074 if (pedantic
&& ! DECL_ARTIFICIAL (current_function_decl
))
6075 pedwarn ("ANSI C++ forbids assignment of arrays");
6077 /* Have to wrap this in RTL_EXPR for two cases:
6078 in base or member initialization and if we
6079 are a branch of a ?: operator. Since we
6080 can't easily know the latter, just do it always. */
6082 result
= make_node (RTL_EXPR
);
6084 TREE_TYPE (result
) = void_type_node
;
6085 do_pending_stack_adjust ();
6086 start_sequence_for_rtl_expr (result
);
6088 /* As a matter of principle, `start_sequence' should do this. */
6091 from_array
= TREE_CODE (TREE_TYPE (newrhs
)) == ARRAY_TYPE
6092 ? 1 + (modifycode
!= INIT_EXPR
): 0;
6093 expand_vec_init (lhs
, lhs
, array_type_nelts (lhstype
), newrhs
,
6096 do_pending_stack_adjust ();
6098 TREE_SIDE_EFFECTS (result
) = 1;
6099 RTL_EXPR_SEQUENCE (result
) = get_insns ();
6100 RTL_EXPR_RTL (result
) = const0_rtx
;
6105 if (modifycode
== INIT_EXPR
)
6107 newrhs
= convert_for_initialization (lhs
, lhstype
, newrhs
, LOOKUP_NORMAL
,
6108 "assignment", NULL_TREE
, 0);
6109 if (lhs
== DECL_RESULT (current_function_decl
))
6111 if (DECL_INITIAL (lhs
))
6112 warning ("return value from function receives multiple initializations");
6113 DECL_INITIAL (lhs
) = newrhs
;
6119 if (IS_AGGR_TYPE (lhstype
))
6121 if (result
= build_opfncall (MODIFY_EXPR
,
6122 LOOKUP_NORMAL
, lhs
, newrhs
,
6123 make_node (NOP_EXPR
)))
6127 /* Avoid warnings on enum bit fields. */
6128 if (TREE_CODE (olhstype
) == ENUMERAL_TYPE
6129 && TREE_CODE (lhstype
) == INTEGER_TYPE
)
6131 newrhs
= convert_for_assignment (olhstype
, newrhs
, "assignment",
6133 newrhs
= convert_force (lhstype
, newrhs
, 0);
6136 newrhs
= convert_for_assignment (lhstype
, newrhs
, "assignment",
6138 if (TREE_CODE (newrhs
) == CALL_EXPR
6139 && TYPE_NEEDS_CONSTRUCTING (lhstype
))
6140 newrhs
= build_cplus_new (lhstype
, newrhs
, 0);
6142 /* Can't initialize directly from a TARGET_EXPR, since that would
6143 cause the lhs to be constructed twice, and possibly result in
6144 accidental self-initialization. So we force the TARGET_EXPR to be
6145 expanded. expand_expr should really do this by itself. */
6146 if (TREE_CODE (newrhs
) == TARGET_EXPR
)
6147 newrhs
= expand_target_expr (newrhs
);
6150 if (TREE_CODE (newrhs
) == ERROR_MARK
)
6151 return error_mark_node
;
6153 if (TREE_CODE (newrhs
) == COND_EXPR
)
6156 tree cond
= TREE_OPERAND (newrhs
, 0);
6158 if (TREE_SIDE_EFFECTS (lhs
))
6159 cond
= build_compound_expr (tree_cons
6161 build_tree_list (NULL_TREE
, cond
)));
6163 /* Cannot have two identical lhs on this one tree (result) as preexpand
6164 calls will rip them out and fill in RTL for them, but when the
6165 rtl is generated, the calls will only be in the first side of the
6166 condition, not on both, or before the conditional jump! (mrs) */
6167 lhs1
= break_out_calls (lhs
);
6170 /* If there's no change, the COND_EXPR behaves like any other rhs. */
6171 result
= build (modifycode
== NOP_EXPR
? MODIFY_EXPR
: INIT_EXPR
,
6172 lhstype
, lhs
, newrhs
);
6175 tree result_type
= TREE_TYPE (newrhs
);
6176 /* We have to convert each arm to the proper type because the
6177 types may have been munged by constant folding. */
6179 = build (COND_EXPR
, result_type
, cond
,
6180 build_modify_expr (lhs
, modifycode
,
6181 convert (result_type
,
6182 TREE_OPERAND (newrhs
, 1))),
6183 build_modify_expr (lhs1
, modifycode
,
6184 convert (result_type
,
6185 TREE_OPERAND (newrhs
, 2))));
6188 else if (modifycode
!= INIT_EXPR
&& TREE_CODE (newrhs
) == WITH_CLEANUP_EXPR
)
6190 tree cleanup
= TREE_OPERAND (newrhs
, 2);
6193 /* Finish up by running cleanups and having the "value" of the lhs. */
6194 tree exprlist
= tree_cons (NULL_TREE
, cleanup
,
6195 build_tree_list (NULL_TREE
, lhs
));
6196 newrhs
= TREE_OPERAND (newrhs
, 0);
6197 if (TREE_CODE (newrhs
) == TARGET_EXPR
)
6198 slot
= TREE_OPERAND (newrhs
, 0);
6199 else if (TREE_CODE (newrhs
) == ADDR_EXPR
)
6201 /* Bad but valid. */
6203 warning ("address taken of temporary object");
6206 my_friendly_abort (118);
6208 /* Copy the value computed in SLOT into LHS. */
6209 exprlist
= tree_cons (NULL_TREE
,
6210 build_modify_expr (lhs
, modifycode
, slot
),
6212 /* Evaluate the expression that needs CLEANUP. This will
6213 compute the value into SLOT. */
6214 exprlist
= tree_cons (NULL_TREE
, newrhs
, exprlist
);
6215 result
= convert (lhstype
, build_compound_expr (exprlist
));
6218 result
= build (modifycode
== NOP_EXPR
? MODIFY_EXPR
: INIT_EXPR
,
6219 lhstype
, lhs
, newrhs
);
6220 TREE_SIDE_EFFECTS (result
) = 1;
6222 /* If we got the LHS in a different type for storing in,
6223 convert the result back to the nominal type of LHS
6224 so that the value we return always has the same type
6225 as the LHS argument. */
6227 if (olhstype
== TREE_TYPE (result
))
6229 /* Avoid warnings converting integral types back into enums
6230 for enum bit fields. */
6231 if (TREE_CODE (TREE_TYPE (result
)) == INTEGER_TYPE
6232 && TREE_CODE (olhstype
) == ENUMERAL_TYPE
)
6234 result
= build (COMPOUND_EXPR
, olhstype
, result
, olhs
);
6235 TREE_NO_UNUSED_WARNING (result
) = 1;
6238 return convert_for_assignment (olhstype
, result
, "assignment",
6243 /* Return 0 if EXP is not a valid lvalue in this language
6244 even though `lvalue_or_else' would accept it. */
6247 language_lvalue_valid (exp
)
6253 /* Get difference in deltas for different pointer to member function
6254 types. Return integer_zero_node, if FROM cannot be converted to a
6255 TO type. If FORCE is true, then allow reverse conversions as well. */
6257 get_delta_difference (from
, to
, force
)
6261 tree delta
= integer_zero_node
;
6267 /* Should get_base_distance here, so we can check if any thing along the
6268 path is virtual, and we need to make sure we stay
6269 inside the real binfos when going through virtual bases.
6270 Maybe we should replace virtual bases with
6271 binfo_member (...CLASSTYPE_VBASECLASSES...)... (mrs) */
6272 binfo
= get_binfo (from
, to
, 1);
6273 if (binfo
== error_mark_node
)
6275 error (" in pointer to member function conversion");
6282 error_not_base_type (from
, to
);
6283 error (" in pointer to member function conversion");
6286 binfo
= get_binfo (to
, from
, 1);
6287 if (binfo
== error_mark_node
)
6289 error (" in pointer to member function conversion");
6294 error ("cannot convert pointer to member of type %T to unrelated pointer to member of type %T", from
, to
);
6297 if (TREE_VIA_VIRTUAL (binfo
))
6299 warning ("pointer to member conversion to virtual base class will only work if you are very careful");
6301 return build_binary_op (MINUS_EXPR
,
6303 BINFO_OFFSET (binfo
), 1);
6305 if (TREE_VIA_VIRTUAL (binfo
))
6307 warning ("pointer to member conversion from virtual base class will only work if you are very careful");
6309 return BINFO_OFFSET (binfo
);
6312 /* Build a constructor for a pointer to member function. It can be
6313 used to initialize global variables, local variable, or used
6314 as a value in expressions. TYPE is the POINTER to METHOD_TYPE we
6317 If FORCE is non-zero, then force this conversion, even if
6318 we would rather not do it. Usually set when using an explicit
6321 Return error_mark_node, if something goes wrong. */
6324 build_ptrmemfunc (type
, pfn
, force
)
6328 tree index
= integer_zero_node
;
6329 tree delta
= integer_zero_node
;
6330 tree delta2
= integer_zero_node
;
6335 /* Handle multiple conversions of pointer to member functions. */
6336 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (pfn
)))
6338 tree ndelta
, ndelta2
, nindex
;
6339 /* Is is already the right type? */
6341 /* Sorry, can't do this, the backend is too stupid. */
6342 if (TYPE_METHOD_BASETYPE (TREE_TYPE (type
))
6343 == TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn
)))))
6345 if (type
!= TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn
)))
6347 npfn
= build1 (NOP_EXPR
, TYPE_GET_PTRMEMFUNC_TYPE (type
), pfn
);
6348 TREE_CONSTANT (npfn
) = TREE_CONSTANT (pfn
);
6353 if (type
== TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn
)))
6357 if (TREE_CODE (pfn
) != CONSTRUCTOR
)
6360 ndelta
= convert (ptrdiff_type_node
, build_component_ref (pfn
, delta_identifier
, 0, 0));
6361 ndelta2
= convert (ptrdiff_type_node
, DELTA2_FROM_PTRMEMFUNC (pfn
));
6362 index
= build_component_ref (pfn
, index_identifier
, 0, 0);
6363 delta
= get_delta_difference (TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn
)))),
6364 TYPE_METHOD_BASETYPE (TREE_TYPE (type
)),
6366 delta
= build_binary_op (PLUS_EXPR
, delta
, ndelta
, 1);
6367 delta2
= build_binary_op (PLUS_EXPR
, ndelta2
, delta2
, 1);
6368 e1
= fold (build (GT_EXPR
, boolean_type_node
, index
, integer_zero_node
));
6370 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (delta2_identifier
, delta2
, NULL_TREE
));
6371 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (NULL_TREE
, delta
,
6372 tree_cons (NULL_TREE
, index
,
6373 tree_cons (NULL_TREE
, u
, NULL_TREE
))));
6374 e2
= digest_init (TYPE_GET_PTRMEMFUNC_TYPE (type
), u
, (tree
*)0);
6376 pfn
= PFN_FROM_PTRMEMFUNC (pfn
);
6377 npfn
= build1 (NOP_EXPR
, type
, pfn
);
6378 TREE_CONSTANT (npfn
) = TREE_CONSTANT (pfn
);
6380 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (pfn_identifier
, npfn
, NULL_TREE
));
6381 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (NULL_TREE
, delta
,
6382 tree_cons (NULL_TREE
, index
,
6383 tree_cons (NULL_TREE
, u
, NULL_TREE
))));
6384 e3
= digest_init (TYPE_GET_PTRMEMFUNC_TYPE (type
), u
, (tree
*)0);
6385 return build_conditional_expr (e1
, e2
, e3
);
6388 ndelta
= TREE_VALUE (CONSTRUCTOR_ELTS (pfn
));
6389 nindex
= TREE_VALUE (TREE_CHAIN (CONSTRUCTOR_ELTS (pfn
)));
6390 npfn
= TREE_VALUE (TREE_CHAIN (TREE_CHAIN (CONSTRUCTOR_ELTS (pfn
))));
6391 npfn
= TREE_VALUE (CONSTRUCTOR_ELTS (npfn
));
6392 if (integer_zerop (nindex
))
6393 pfn
= integer_zero_node
;
6394 else if (integer_zerop (fold (size_binop (PLUS_EXPR
, nindex
, integer_one_node
))))
6397 delta
= get_delta_difference (TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn
)))),
6398 TYPE_METHOD_BASETYPE (TREE_TYPE (type
)),
6400 delta
= build_binary_op (PLUS_EXPR
, delta
, ndelta
, 1);
6401 pfn
= build1 (NOP_EXPR
, type
, npfn
);
6402 TREE_CONSTANT (pfn
) = TREE_CONSTANT (npfn
);
6404 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (pfn_identifier
, pfn
, NULL_TREE
));
6405 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (NULL_TREE
, delta
,
6406 tree_cons (NULL_TREE
, nindex
,
6407 tree_cons (NULL_TREE
, u
, NULL_TREE
))));
6408 e3
= digest_init (TYPE_GET_PTRMEMFUNC_TYPE (type
), u
, (tree
*)0);
6413 sorry ("value casting of variable nonnull pointer to member functions not supported");
6414 return error_mark_node
;
6418 /* Handle null pointer to member function conversions. */
6419 if (integer_zerop (pfn
))
6421 pfn
= build_c_cast (type
, integer_zero_node
, 0);
6422 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (pfn_identifier
, pfn
, NULL_TREE
));
6423 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (NULL_TREE
, integer_zero_node
,
6424 tree_cons (NULL_TREE
, integer_zero_node
,
6425 tree_cons (NULL_TREE
, u
, NULL_TREE
))));
6426 return digest_init (TYPE_GET_PTRMEMFUNC_TYPE (type
), u
, (tree
*)0);
6429 if (TREE_CODE (pfn
) == TREE_LIST
6430 || (TREE_CODE (pfn
) == ADDR_EXPR
6431 && TREE_CODE (TREE_OPERAND (pfn
, 0)) == TREE_LIST
))
6433 pfn
= instantiate_type (type
, pfn
, 1);
6434 if (pfn
== error_mark_node
)
6435 return error_mark_node
;
6436 if (TREE_CODE (pfn
) != ADDR_EXPR
)
6437 pfn
= build_unary_op (ADDR_EXPR
, pfn
, 0);
6440 /* Allow pointer to member conversions here. */
6441 delta
= get_delta_difference (TYPE_METHOD_BASETYPE (TREE_TYPE (TREE_TYPE (pfn
))),
6442 TYPE_METHOD_BASETYPE (TREE_TYPE (type
)),
6444 delta2
= build_binary_op (PLUS_EXPR
, delta2
, delta
, 1);
6446 if (TREE_CODE (TREE_OPERAND (pfn
, 0)) != FUNCTION_DECL
)
6447 warning ("assuming pointer to member function is non-virtual");
6449 if (TREE_CODE (TREE_OPERAND (pfn
, 0)) == FUNCTION_DECL
6450 && DECL_VINDEX (TREE_OPERAND (pfn
, 0)))
6452 /* Find the offset to the vfield pointer in the object. */
6453 vfield_offset
= get_binfo (DECL_CONTEXT (TREE_OPERAND (pfn
, 0)),
6454 DECL_CLASS_CONTEXT (TREE_OPERAND (pfn
, 0)),
6456 vfield_offset
= get_vfield_offset (vfield_offset
);
6457 delta2
= size_binop (PLUS_EXPR
, vfield_offset
, delta2
);
6459 /* Map everything down one to make room for the null pointer to member. */
6460 index
= size_binop (PLUS_EXPR
,
6461 DECL_VINDEX (TREE_OPERAND (pfn
, 0)),
6463 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (delta2_identifier
, delta2
, NULL_TREE
));
6467 index
= size_binop (MINUS_EXPR
, integer_zero_node
, integer_one_node
);
6469 npfn
= build1 (NOP_EXPR
, type
, pfn
);
6470 TREE_CONSTANT (npfn
) = TREE_CONSTANT (pfn
);
6472 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (pfn_identifier
, npfn
, NULL_TREE
));
6475 u
= build_nt (CONSTRUCTOR
, 0, tree_cons (NULL_TREE
, delta
,
6476 tree_cons (NULL_TREE
, index
,
6477 tree_cons (NULL_TREE
, u
, NULL_TREE
))));
6478 return digest_init (TYPE_GET_PTRMEMFUNC_TYPE (type
), u
, (tree
*)0);
6481 /* Convert value RHS to type TYPE as preparation for an assignment
6482 to an lvalue of type TYPE.
6483 The real work of conversion is done by `convert'.
6484 The purpose of this function is to generate error messages
6485 for assignments that are not allowed in C.
6486 ERRTYPE is a string to use in error messages:
6487 "assignment", "return", etc.
6489 C++: attempts to allow `convert' to find conversions involving
6490 implicit type conversion between aggregate and scalar types
6491 as per 8.5.6 of C++ manual. Does not randomly dereference
6492 pointers to aggregates! */
6495 convert_for_assignment (type
, rhs
, errtype
, fndecl
, parmnum
)
6501 register enum tree_code codel
= TREE_CODE (type
);
6502 register tree rhstype
;
6503 register enum tree_code coder
= TREE_CODE (TREE_TYPE (rhs
));
6505 if (coder
== UNKNOWN_TYPE
)
6506 rhs
= instantiate_type (type
, rhs
, 1);
6508 if (coder
== ERROR_MARK
)
6509 return error_mark_node
;
6511 if (codel
== OFFSET_TYPE
)
6513 type
= TREE_TYPE (type
);
6514 codel
= TREE_CODE (type
);
6517 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
6518 if (TREE_CODE (rhs
) == NON_LVALUE_EXPR
)
6519 rhs
= TREE_OPERAND (rhs
, 0);
6521 if (rhs
== error_mark_node
)
6522 return error_mark_node
;
6524 if (TREE_VALUE (rhs
) == error_mark_node
)
6525 return error_mark_node
;
6527 if (TREE_CODE (TREE_TYPE (rhs
)) == OFFSET_TYPE
)
6529 rhs
= resolve_offset_ref (rhs
);
6530 if (rhs
== error_mark_node
)
6531 return error_mark_node
;
6532 rhstype
= TREE_TYPE (rhs
);
6533 coder
= TREE_CODE (rhstype
);
6536 if (TREE_CODE (TREE_TYPE (rhs
)) == ARRAY_TYPE
6537 || TREE_CODE (TREE_TYPE (rhs
)) == FUNCTION_TYPE
6538 || TREE_CODE (TREE_TYPE (rhs
)) == METHOD_TYPE
)
6539 rhs
= default_conversion (rhs
);
6540 else if (TREE_CODE (TREE_TYPE (rhs
)) == REFERENCE_TYPE
)
6541 rhs
= convert_from_reference (rhs
);
6543 rhstype
= TREE_TYPE (rhs
);
6544 coder
= TREE_CODE (rhstype
);
6546 /* This should no longer change types on us. */
6547 if (TREE_CODE (rhs
) == CONST_DECL
)
6548 rhs
= DECL_INITIAL (rhs
);
6549 else if (TREE_READONLY_DECL_P (rhs
))
6550 rhs
= decl_constant_value (rhs
);
6552 if (type
== rhstype
)
6554 overflow_warning (rhs
);
6558 if (coder
== VOID_TYPE
)
6560 error ("void value not ignored as it ought to be");
6561 return error_mark_node
;
6563 /* Arithmetic types all interconvert. */
6564 if ((codel
== INTEGER_TYPE
|| codel
== REAL_TYPE
|| codel
== BOOLEAN_TYPE
)
6565 && (coder
== INTEGER_TYPE
|| coder
== REAL_TYPE
|| coder
== BOOLEAN_TYPE
))
6567 /* But we should warn if assigning REAL_TYPE to INTEGER_TYPE. */
6568 if (coder
== REAL_TYPE
&& codel
== INTEGER_TYPE
)
6571 cp_warning ("`%T' used for argument %P of `%D'",
6572 rhstype
, parmnum
, fndecl
);
6574 cp_warning ("%s to `%T' from `%T'", errtype
, type
, rhstype
);
6576 /* And we should warn if assigning a negative value to
6577 an unsigned variable. */
6578 else if (TREE_UNSIGNED (type
) && codel
!= BOOLEAN_TYPE
)
6580 if (TREE_CODE (rhs
) == INTEGER_CST
6581 && TREE_NEGATED_INT (rhs
))
6584 cp_warning ("negative value `%E' passed as argument %P of `%D'",
6585 rhs
, parmnum
, fndecl
);
6587 cp_warning ("%s of negative value `%E' to `%T'",
6588 errtype
, rhs
, type
);
6590 overflow_warning (rhs
);
6591 if (TREE_CONSTANT (rhs
))
6595 return convert_and_check (type
, rhs
);
6597 /* Conversions involving enums. */
6598 else if ((codel
== ENUMERAL_TYPE
6599 && (INTEGRAL_CODE_P (coder
) || coder
== REAL_TYPE
))
6600 || (coder
== ENUMERAL_TYPE
6601 && (INTEGRAL_CODE_P (codel
) || codel
== REAL_TYPE
)))
6603 return cp_convert (type
, rhs
, CONV_IMPLICIT
, LOOKUP_NORMAL
);
6605 /* Conversions among pointers */
6606 else if (codel
== POINTER_TYPE
6607 && (coder
== POINTER_TYPE
6608 || (coder
== RECORD_TYPE
6609 && (IS_SIGNATURE_POINTER (rhstype
)
6610 || IS_SIGNATURE_REFERENCE (rhstype
)))))
6612 register tree ttl
= TREE_TYPE (type
);
6616 if (coder
== RECORD_TYPE
)
6618 rhs
= build_optr_ref (rhs
);
6619 rhstype
= TREE_TYPE (rhs
);
6621 ttr
= TREE_TYPE (rhstype
);
6623 /* If both pointers are of aggregate type, then we
6624 can give better error messages, and save some work
6626 if (TREE_CODE (ttl
) == RECORD_TYPE
&& TREE_CODE (ttr
) == RECORD_TYPE
)
6630 if (TYPE_MAIN_VARIANT (ttl
) == TYPE_MAIN_VARIANT (ttr
)
6631 || type
== class_star_type_node
6632 || rhstype
== class_star_type_node
)
6633 binfo
= TYPE_BINFO (ttl
);
6635 binfo
= get_binfo (ttl
, ttr
, 1);
6637 if (binfo
== error_mark_node
)
6638 return error_mark_node
;
6640 return error_not_base_type (ttl
, ttr
);
6642 if (! TYPE_READONLY (ttl
) && TYPE_READONLY (ttr
))
6645 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6646 rhstype
, parmnum
, fndecl
);
6648 cp_pedwarn ("%s to `%T' from `%T' discards const",
6649 errtype
, type
, rhstype
);
6651 if (! TYPE_VOLATILE (ttl
) && TYPE_VOLATILE (ttr
))
6654 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6655 rhstype
, parmnum
, fndecl
);
6657 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6658 errtype
, type
, rhstype
);
6662 /* Any non-function converts to a [const][volatile] void *
6663 and vice versa; otherwise, targets must be the same.
6664 Meanwhile, the lhs target must have all the qualifiers of the rhs. */
6665 else if (TYPE_MAIN_VARIANT (ttl
) == void_type_node
6666 || TYPE_MAIN_VARIANT (ttr
) == void_type_node
6667 || (ctt
= comp_target_types (type
, rhstype
, 1))
6668 || (unsigned_type (TYPE_MAIN_VARIANT (ttl
))
6669 == unsigned_type (TYPE_MAIN_VARIANT (ttr
))))
6671 /* ARM $4.8, commentary on p39. */
6672 if (TYPE_MAIN_VARIANT (ttl
) == void_type_node
6673 && TREE_CODE (ttr
) == OFFSET_TYPE
)
6675 cp_error ("no standard conversion from `%T' to `void *'", ttr
);
6676 return error_mark_node
;
6680 cp_pedwarn ("converting `%T' to `%T' is a contravariance violation",
6683 if (TYPE_MAIN_VARIANT (ttl
) != void_type_node
6684 && TYPE_MAIN_VARIANT (ttr
) == void_type_node
6685 && rhs
!= null_pointer_node
)
6687 if (coder
== RECORD_TYPE
)
6688 cp_pedwarn ("implicit conversion of signature pointer to type `%T'",
6691 pedwarn ("ANSI C++ forbids implicit conversion from `void *' in %s",
6694 /* Const and volatile mean something different for function types,
6695 so the usual warnings are not appropriate. */
6696 else if ((TREE_CODE (ttr
) != FUNCTION_TYPE
&& TREE_CODE (ttr
) != METHOD_TYPE
)
6697 || (TREE_CODE (ttl
) != FUNCTION_TYPE
&& TREE_CODE (ttl
) != METHOD_TYPE
))
6699 if (TREE_CODE (ttl
) == OFFSET_TYPE
6700 && binfo_member (TYPE_OFFSET_BASETYPE (ttr
),
6701 CLASSTYPE_VBASECLASSES (TYPE_OFFSET_BASETYPE (ttl
))))
6703 sorry ("%s between pointer to members converting across virtual baseclasses", errtype
);
6704 return error_mark_node
;
6706 else if (! TYPE_READONLY (ttl
) && TYPE_READONLY (ttr
))
6709 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6710 rhstype
, parmnum
, fndecl
);
6712 cp_pedwarn ("%s to `%T' from `%T' discards const",
6713 errtype
, type
, rhstype
);
6715 else if (! TYPE_VOLATILE (ttl
) && TYPE_VOLATILE (ttr
))
6718 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6719 rhstype
, parmnum
, fndecl
);
6721 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6722 errtype
, type
, rhstype
);
6724 else if (TREE_CODE (ttl
) == TREE_CODE (ttr
)
6725 && ! comp_target_types (type
, rhstype
, 1))
6728 cp_pedwarn ("passing `%T' as argument %P of `%D' changes signedness",
6729 rhstype
, parmnum
, fndecl
);
6731 cp_pedwarn ("%s to `%T' from `%T' changes signedness",
6732 errtype
, type
, rhstype
);
6736 else if (TREE_CODE (ttr
) == OFFSET_TYPE
6737 && TREE_CODE (ttl
) != OFFSET_TYPE
)
6739 /* Normally, pointers to different type codes (other
6740 than void) are not compatible, but we perform
6741 some type instantiation if that resolves the
6742 ambiguity of (X Y::*) and (X *). */
6744 if (current_class_decl
)
6746 if (TREE_CODE (rhs
) == INTEGER_CST
)
6748 rhs
= build (PLUS_EXPR
, build_pointer_type (TREE_TYPE (ttr
)),
6749 current_class_decl
, rhs
);
6750 return convert_for_assignment (type
, rhs
,
6751 errtype
, fndecl
, parmnum
);
6754 if (TREE_CODE (ttl
) == METHOD_TYPE
)
6755 error ("%s between pointer-to-method and pointer-to-member types",
6758 error ("%s between pointer and pointer-to-member types", errtype
);
6759 return error_mark_node
;
6763 int add_quals
= 0, const_parity
= 0, volatile_parity
= 0;
6765 int unsigned_parity
;
6768 /* This code is basically a duplicate of comp_ptr_ttypes_real. */
6769 for (; ; ttl
= TREE_TYPE (ttl
), ttr
= TREE_TYPE (ttr
))
6772 const_parity
|= TYPE_READONLY (ttl
) < TYPE_READONLY (ttr
);
6773 volatile_parity
|= TYPE_VOLATILE (ttl
) < TYPE_VOLATILE (ttr
);
6776 && (TYPE_READONLY (ttl
) > TYPE_READONLY (ttr
)
6777 || TYPE_VOLATILE (ttl
) > TYPE_VOLATILE (ttr
)))
6779 left_const
&= TYPE_READONLY (ttl
);
6781 if (TREE_CODE (ttl
) != POINTER_TYPE
6782 || TREE_CODE (ttr
) != POINTER_TYPE
)
6785 unsigned_parity
= TREE_UNSIGNED (ttl
) - TREE_UNSIGNED (ttr
);
6786 if (unsigned_parity
)
6788 if (TREE_UNSIGNED (ttl
))
6789 ttr
= unsigned_type (ttr
);
6791 ttl
= unsigned_type (ttl
);
6794 if (comp_target_types (ttl
, ttr
, nptrs
) > 0)
6799 cp_pedwarn ("passing `%T' as argument %P of `%D' adds cv-quals without intervening `const'",
6800 rhstype
, parmnum
, fndecl
);
6802 cp_pedwarn ("%s to `%T' from `%T' adds cv-quals without intervening `const'",
6803 errtype
, type
, rhstype
);
6808 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6809 rhstype
, parmnum
, fndecl
);
6811 cp_pedwarn ("%s to `%T' from `%T' discards const",
6812 errtype
, type
, rhstype
);
6814 if (volatile_parity
)
6817 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6818 rhstype
, parmnum
, fndecl
);
6820 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6821 errtype
, type
, rhstype
);
6823 if (unsigned_parity
> 0)
6826 cp_pedwarn ("passing `%T' as argument %P of `%D' changes signed to unsigned",
6827 rhstype
, parmnum
, fndecl
);
6829 cp_pedwarn ("%s to `%T' from `%T' changes signed to unsigned",
6830 errtype
, type
, rhstype
);
6832 else if (unsigned_parity
< 0)
6835 cp_pedwarn ("passing `%T' as argument %P of `%D' changes unsigned to signed",
6836 rhstype
, parmnum
, fndecl
);
6838 cp_pedwarn ("%s to `%T' from `%T' changes unsigned to signed",
6839 errtype
, type
, rhstype
);
6842 /* C++ is not so friendly about converting function and
6843 member function pointers as C. Emit warnings here. */
6844 if (TREE_CODE (ttl
) == FUNCTION_TYPE
6845 || TREE_CODE (ttl
) == METHOD_TYPE
)
6846 if (! comptypes (ttl
, ttr
, 0))
6848 warning ("conflicting function types in %s:", errtype
);
6849 cp_warning ("\t`%T' != `%T'", type
, rhstype
);
6852 else if (TREE_CODE (TREE_TYPE (rhs
)) == METHOD_TYPE
)
6854 /* When does this happen? */
6855 my_friendly_abort (119);
6856 /* Conversion of a pointer-to-member type to void *. */
6857 rhs
= build_unary_op (ADDR_EXPR
, rhs
, 0);
6858 TREE_TYPE (rhs
) = type
;
6861 else if (TREE_CODE (TREE_TYPE (rhs
)) == OFFSET_TYPE
)
6863 /* When does this happen? */
6864 my_friendly_abort (120);
6865 /* Conversion of a pointer-to-member type to void *. */
6866 rhs
= build_unary_op (ADDR_EXPR
, rhs
, 0);
6867 TREE_TYPE (rhs
) = type
;
6873 cp_error ("passing `%T' as argument %P of `%D'",
6874 rhstype
, parmnum
, fndecl
);
6876 cp_error ("%s to `%T' from `%T'", errtype
, type
, rhstype
);
6877 return error_mark_node
;
6880 return convert (type
, rhs
);
6882 else if (codel
== POINTER_TYPE
&& coder
== INTEGER_TYPE
)
6884 /* An explicit constant 0 can convert to a pointer,
6885 but not a 0 that results from casting or folding. */
6886 if (! (TREE_CODE (rhs
) == INTEGER_CST
&& integer_zerop (rhs
)))
6889 cp_pedwarn ("passing `%T' to argument %P of `%D' lacks a cast",
6890 rhstype
, parmnum
, fndecl
);
6892 cp_pedwarn ("%s to `%T' from `%T' lacks a cast",
6893 errtype
, type
, rhstype
);
6894 return convert (type
, rhs
);
6896 return null_pointer_node
;
6898 else if (codel
== INTEGER_TYPE
6899 && (coder
== POINTER_TYPE
6900 || (coder
== RECORD_TYPE
6901 && (IS_SIGNATURE_POINTER (rhstype
)
6902 || TYPE_PTRMEMFUNC_FLAG (rhstype
)
6903 || IS_SIGNATURE_REFERENCE (rhstype
)))))
6906 cp_pedwarn ("passing `%T' to argument %P of `%D' lacks a cast",
6907 rhstype
, parmnum
, fndecl
);
6909 cp_pedwarn ("%s to `%T' from `%T' lacks a cast",
6910 errtype
, type
, rhstype
);
6911 return convert (type
, rhs
);
6913 else if (codel
== BOOLEAN_TYPE
6914 && (coder
== POINTER_TYPE
6915 || (coder
== RECORD_TYPE
6916 && (IS_SIGNATURE_POINTER (rhstype
)
6917 || TYPE_PTRMEMFUNC_FLAG (rhstype
)
6918 || IS_SIGNATURE_REFERENCE (rhstype
)))))
6919 return convert (type
, rhs
);
6922 else if (((coder
== POINTER_TYPE
6923 && TREE_CODE (TREE_TYPE (rhstype
)) == METHOD_TYPE
)
6924 || integer_zerop (rhs
)
6925 || TYPE_PTRMEMFUNC_P (rhstype
))
6926 && TYPE_PTRMEMFUNC_P (type
))
6928 tree ttl
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
6929 tree ttr
= (TREE_CODE (rhstype
) == POINTER_TYPE
? rhstype
6930 : TYPE_PTRMEMFUNC_FN_TYPE (type
));
6931 int ctt
= comp_target_types (ttl
, ttr
, 1);
6934 cp_pedwarn ("converting `%T' to `%T' is a contravariance violation",
6937 cp_error ("%s to `%T' from `%T'", errtype
, ttl
, ttr
);
6939 /* compatible pointer to member functions. */
6940 return build_ptrmemfunc (ttl
, rhs
, 0);
6942 else if (codel
== ERROR_MARK
|| coder
== ERROR_MARK
)
6943 return error_mark_node
;
6945 /* This should no longer happen. References are initialized via
6946 `convert_for_initialization'. They should otherwise be
6947 bashed before coming here. */
6948 else if (codel
== REFERENCE_TYPE
)
6949 my_friendly_abort (317);
6950 else if (TYPE_MAIN_VARIANT (type
) == TYPE_MAIN_VARIANT (TREE_TYPE (rhs
)))
6952 tree nrhs
= build1 (NOP_EXPR
, type
, rhs
);
6953 TREE_CONSTANT (nrhs
) = TREE_CONSTANT (rhs
);
6956 else if (TYPE_HAS_CONSTRUCTOR (type
) || IS_AGGR_TYPE (TREE_TYPE (rhs
)))
6957 return convert (type
, rhs
);
6959 cp_error ("%s to `%T' from `%T'", errtype
, type
, rhstype
);
6960 return error_mark_node
;
6963 /* Convert RHS to be of type TYPE. If EXP is non-zero,
6964 it is the target of the initialization.
6965 ERRTYPE is a string to use in error messages.
6967 Two major differences between the behavior of
6968 `convert_for_assignment' and `convert_for_initialization'
6969 are that references are bashed in the former, while
6970 copied in the latter, and aggregates are assigned in
6971 the former (operator=) while initialized in the
6974 If using constructor make sure no conversion operator exists, if one does
6975 exist, an ambiguity exists.
6977 If flags doesn't include LOOKUP_COMPLAIN, don't complain about anything. */
6979 convert_for_initialization (exp
, type
, rhs
, flags
, errtype
, fndecl
, parmnum
)
6980 tree exp
, type
, rhs
;
6986 register enum tree_code codel
= TREE_CODE (type
);
6987 register tree rhstype
;
6988 register enum tree_code coder
;
6990 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
6991 Strip such NOP_EXPRs, since RHS is used in non-lvalue context. */
6992 if (TREE_CODE (rhs
) == NOP_EXPR
6993 && TREE_TYPE (rhs
) == TREE_TYPE (TREE_OPERAND (rhs
, 0))
6994 && codel
!= REFERENCE_TYPE
)
6995 rhs
= TREE_OPERAND (rhs
, 0);
6997 if (rhs
== error_mark_node
6998 || (TREE_CODE (rhs
) == TREE_LIST
&& TREE_VALUE (rhs
) == error_mark_node
))
6999 return error_mark_node
;
7001 if (TREE_CODE (TREE_TYPE (rhs
)) == OFFSET_TYPE
)
7003 rhs
= resolve_offset_ref (rhs
);
7004 if (rhs
== error_mark_node
)
7005 return error_mark_node
;
7008 if (TREE_CODE (TREE_TYPE (rhs
)) == REFERENCE_TYPE
)
7009 rhs
= convert_from_reference (rhs
);
7011 if ((TREE_CODE (TREE_TYPE (rhs
)) == ARRAY_TYPE
7012 && TREE_CODE (type
) != ARRAY_TYPE
7013 && (TREE_CODE (type
) != REFERENCE_TYPE
7014 || TREE_CODE (TREE_TYPE (type
)) != ARRAY_TYPE
))
7015 || TREE_CODE (TREE_TYPE (rhs
)) == FUNCTION_TYPE
7016 || TREE_CODE (TREE_TYPE (rhs
)) == METHOD_TYPE
)
7017 rhs
= default_conversion (rhs
);
7019 rhstype
= TREE_TYPE (rhs
);
7020 coder
= TREE_CODE (rhstype
);
7022 if (coder
== UNKNOWN_TYPE
)
7024 rhs
= instantiate_type (type
, rhs
, 1);
7025 rhstype
= TREE_TYPE (rhs
);
7026 coder
= TREE_CODE (rhstype
);
7029 if (coder
== ERROR_MARK
)
7030 return error_mark_node
;
7033 /* This is *not* the quick way out! It is the way to disaster. */
7034 if (type
== rhstype
)
7038 /* We accept references to incomplete types, so we can
7039 return here before checking if RHS is of complete type. */
7041 if (codel
== REFERENCE_TYPE
)
7043 /* This should eventually happen in convert_arguments. */
7044 extern int warningcount
, errorcount
;
7048 savew
= warningcount
, savee
= errorcount
;
7049 rhs
= convert_to_reference (type
, rhs
, CONV_IMPLICIT
, flags
,
7050 exp
? exp
: error_mark_node
);
7053 if (warningcount
> savew
)
7054 cp_warning_at ("in passing argument %P of `%+D'", parmnum
, fndecl
);
7055 else if (errorcount
> savee
)
7056 cp_error_at ("in passing argument %P of `%+D'", parmnum
, fndecl
);
7061 rhs
= require_complete_type (rhs
);
7062 if (rhs
== error_mark_node
)
7063 return error_mark_node
;
7065 if (exp
!= 0) exp
= require_complete_type (exp
);
7066 if (exp
== error_mark_node
)
7067 return error_mark_node
;
7069 if (TREE_CODE (rhstype
) == REFERENCE_TYPE
)
7070 rhstype
= TREE_TYPE (rhstype
);
7072 if (TYPE_LANG_SPECIFIC (type
)
7073 && (IS_SIGNATURE_POINTER (type
) || IS_SIGNATURE_REFERENCE (type
)))
7074 return build_signature_pointer_constructor (type
, rhs
);
7076 if (IS_AGGR_TYPE (type
)
7077 && (TYPE_NEEDS_CONSTRUCTING (type
) || TREE_HAS_CONSTRUCTOR (rhs
)))
7079 if (TYPE_MAIN_VARIANT (type
) == TYPE_MAIN_VARIANT (rhstype
))
7081 /* This is sufficient to perform initialization. No need,
7082 apparently, to go through X(X&) to do first-cut
7083 initialization. Return through a TARGET_EXPR so that we get
7084 cleanups if it is used. */
7085 if (TREE_CODE (rhs
) == CALL_EXPR
)
7087 rhs
= build_cplus_new (type
, rhs
, 0);
7090 /* Handle the case of default parameter initialization and
7091 initialization of static variables. */
7092 else if (TREE_CODE (rhs
) == TARGET_EXPR
)
7094 else if (TREE_CODE (rhs
) == INDIRECT_REF
&& TREE_HAS_CONSTRUCTOR (rhs
))
7096 my_friendly_assert (TREE_CODE (TREE_OPERAND (rhs
, 0)) == CALL_EXPR
, 318);
7099 my_friendly_assert (TREE_VALUE (TREE_OPERAND (TREE_OPERAND (rhs
, 0), 1)) == NULL_TREE
, 316);
7100 TREE_VALUE (TREE_OPERAND (TREE_OPERAND (rhs
, 0), 1))
7101 = build_unary_op (ADDR_EXPR
, exp
, 0);
7104 rhs
= build_cplus_new (type
, TREE_OPERAND (rhs
, 0), 0);
7107 else if (TYPE_HAS_TRIVIAL_INIT_REF (type
))
7110 if (TYPE_MAIN_VARIANT (type
) == TYPE_MAIN_VARIANT (rhstype
)
7111 || (IS_AGGR_TYPE (rhstype
) && UNIQUELY_DERIVED_FROM_P (type
, rhstype
)))
7113 if (TYPE_HAS_INIT_REF (type
))
7115 tree init
= build_method_call (exp
, constructor_name_full (type
),
7116 build_tree_list (NULL_TREE
, rhs
),
7117 TYPE_BINFO (type
), LOOKUP_NORMAL
);
7119 if (init
== error_mark_node
)
7120 return error_mark_node
;
7124 exp
= build_cplus_new (type
, init
, 0);
7128 return build (COMPOUND_EXPR
, type
, init
, exp
);
7131 /* ??? The following warnings are turned off because
7132 this is another place where the default X(X&) constructor
7134 if (TYPE_HAS_ASSIGNMENT (type
))
7135 cp_warning ("bitwise copy: `%T' defines operator=", type
);
7137 if (TREE_CODE (TREE_TYPE (rhs
)) == REFERENCE_TYPE
)
7138 rhs
= convert_from_reference (rhs
);
7139 if (type
!= rhstype
)
7141 tree nrhs
= build1 (NOP_EXPR
, type
, rhs
);
7142 TREE_CONSTANT (nrhs
) = TREE_CONSTANT (rhs
);
7148 return cp_convert (type
, rhs
, CONV_OLD_CONVERT
, flags
);
7151 if (type
== TREE_TYPE (rhs
))
7153 if (TREE_READONLY_DECL_P (rhs
))
7154 rhs
= decl_constant_value (rhs
);
7158 return convert_for_assignment (type
, rhs
, errtype
, fndecl
, parmnum
);
7161 /* Expand an ASM statement with operands, handling output operands
7162 that are not variables or INDIRECT_REFS by transforming such
7163 cases into cases that expand_asm_operands can handle.
7165 Arguments are same as for expand_asm_operands.
7167 We don't do default conversions on all inputs, because it can screw
7168 up operands that are expected to be in memory. */
7171 c_expand_asm_operands (string
, outputs
, inputs
, clobbers
, vol
, filename
, line
)
7172 tree string
, outputs
, inputs
, clobbers
;
7177 int noutputs
= list_length (outputs
);
7179 /* o[I] is the place that output number I should be written. */
7180 register tree
*o
= (tree
*) alloca (noutputs
* sizeof (tree
));
7183 /* Record the contents of OUTPUTS before it is modified. */
7184 for (i
= 0, tail
= outputs
; tail
; tail
= TREE_CHAIN (tail
), i
++)
7185 o
[i
] = TREE_VALUE (tail
);
7187 /* Generate the ASM_OPERANDS insn;
7188 store into the TREE_VALUEs of OUTPUTS some trees for
7189 where the values were actually stored. */
7190 expand_asm_operands (string
, outputs
, inputs
, clobbers
, vol
, filename
, line
);
7192 /* Copy all the intermediate outputs into the specified outputs. */
7193 for (i
= 0, tail
= outputs
; tail
; tail
= TREE_CHAIN (tail
), i
++)
7195 if (o
[i
] != TREE_VALUE (tail
))
7197 expand_expr (build_modify_expr (o
[i
], NOP_EXPR
, TREE_VALUE (tail
)),
7198 const0_rtx
, VOIDmode
, 0);
7201 /* Detect modification of read-only values.
7202 (Otherwise done by build_modify_expr.) */
7205 tree type
= TREE_TYPE (o
[i
]);
7206 if (TYPE_READONLY (type
)
7207 || ((TREE_CODE (type
) == RECORD_TYPE
7208 || TREE_CODE (type
) == UNION_TYPE
)
7209 && C_TYPE_FIELDS_READONLY (type
)))
7210 readonly_error (o
[i
], "modification by `asm'", 1);
7214 /* Those MODIFY_EXPRs could do autoincrements. */
7218 /* Expand a C `return' statement.
7219 RETVAL is the expression for what to return,
7220 or a null pointer for `return;' with no value.
7222 C++: upon seeing a `return', we must call destructors on all
7223 variables in scope which had constructors called on them.
7224 This means that if in a destructor, the base class destructors
7225 must be called before returning.
7227 The RETURN statement in C++ has initialization semantics. */
7230 c_expand_return (retval
)
7233 extern struct nesting
*cond_stack
, *loop_stack
, *case_stack
;
7234 extern tree dtor_label
, ctor_label
;
7235 tree result
= DECL_RESULT (current_function_decl
);
7236 tree valtype
= TREE_TYPE (result
);
7237 register int use_temp
= 0;
7238 int returns_value
= 1;
7240 if (TREE_THIS_VOLATILE (current_function_decl
))
7241 warning ("function declared `noreturn' has a `return' statement");
7243 if (retval
== error_mark_node
)
7245 current_function_returns_null
= 1;
7249 if (retval
== NULL_TREE
)
7251 /* A non-named return value does not count. */
7253 /* Can't just return from a destructor. */
7256 expand_goto (dtor_label
);
7260 if (DECL_CONSTRUCTOR_P (current_function_decl
))
7261 retval
= current_class_decl
;
7262 else if (DECL_NAME (result
) != NULL_TREE
7263 && TREE_CODE (valtype
) != VOID_TYPE
)
7267 current_function_returns_null
= 1;
7269 if (valtype
!= NULL_TREE
&& TREE_CODE (valtype
) != VOID_TYPE
)
7271 if (DECL_NAME (DECL_RESULT (current_function_decl
)) == NULL_TREE
)
7273 pedwarn ("`return' with no value, in function returning non-void");
7274 /* Clear this, so finish_function won't say that we
7275 reach the end of a non-void function (which we don't,
7276 we gave a return!). */
7277 current_function_returns_null
= 0;
7281 expand_null_return ();
7285 else if (DECL_CONSTRUCTOR_P (current_function_decl
)
7286 && retval
!= current_class_decl
)
7288 error ("return from a constructor: use `this = ...' instead");
7289 retval
= current_class_decl
;
7292 if (valtype
== NULL_TREE
|| TREE_CODE (valtype
) == VOID_TYPE
)
7294 current_function_returns_null
= 1;
7295 /* We do this here so we'll avoid a warning about how the function
7296 "may or may not return a value" in finish_function. */
7300 pedwarn ("`return' with a value, in function returning void");
7301 expand_return (retval
);
7303 /* Add some useful error checking for C++. */
7304 else if (TREE_CODE (valtype
) == REFERENCE_TYPE
)
7306 tree whats_returned
;
7307 tree tmp_result
= result
;
7309 /* Don't initialize directly into a non-BLKmode retval, since that
7310 could lose when being inlined by another caller. (GCC can't
7311 read the function return register in an inline function when
7312 the return value is being ignored). */
7313 if (result
&& TYPE_MODE (TREE_TYPE (tmp_result
)) != BLKmode
)
7316 /* convert to reference now, so we can give error if we
7317 return an reference to a non-lvalue. */
7318 retval
= convert_for_initialization (tmp_result
, valtype
, retval
,
7319 LOOKUP_NORMAL
, "return",
7322 /* Sort through common things to see what it is
7323 we are returning. */
7324 whats_returned
= retval
;
7325 if (TREE_CODE (whats_returned
) == COMPOUND_EXPR
)
7327 whats_returned
= TREE_OPERAND (whats_returned
, 1);
7328 if (TREE_CODE (whats_returned
) == ADDR_EXPR
)
7329 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7331 if (TREE_CODE (whats_returned
) == ADDR_EXPR
)
7333 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7334 while (TREE_CODE (whats_returned
) == NEW_EXPR
7335 || TREE_CODE (whats_returned
) == TARGET_EXPR
7336 || TREE_CODE (whats_returned
) == WITH_CLEANUP_EXPR
)
7338 /* Get the target. */
7339 whats_returned
= TREE_OPERAND (whats_returned
, 0);
7340 warning ("returning reference to temporary");
7344 if (TREE_CODE (whats_returned
) == VAR_DECL
&& DECL_NAME (whats_returned
))
7346 if (TEMP_NAME_P (DECL_NAME (whats_returned
)))
7347 warning ("reference to non-lvalue returned");
7348 else if (! TREE_STATIC (whats_returned
)
7349 && IDENTIFIER_LOCAL_VALUE (DECL_NAME (whats_returned
)))
7350 cp_warning_at ("reference to local variable `%D' returned", whats_returned
);
7353 else if (TREE_CODE (retval
) == ADDR_EXPR
)
7355 tree whats_returned
= TREE_OPERAND (retval
, 0);
7357 if (TREE_CODE (whats_returned
) == VAR_DECL
7358 && DECL_NAME (whats_returned
)
7359 && IDENTIFIER_LOCAL_VALUE (DECL_NAME (whats_returned
))
7360 && !TREE_STATIC (whats_returned
))
7361 cp_warning_at ("address of local variable `%D' returned", whats_returned
);
7364 /* Now deal with possible C++ hair:
7365 (1) Compute the return value.
7366 (2) If there are aggregate values with destructors which
7367 must be cleaned up, clean them (taking care
7368 not to clobber the return value).
7369 (3) If an X(X&) constructor is defined, the return
7370 value must be returned via that. */
7372 /* If we're returning in a register, we can't initialize the
7373 return value from a TARGET_EXPR. */
7374 if (TREE_CODE (retval
) == TARGET_EXPR
7375 && TYPE_MAIN_VARIANT (TREE_TYPE (retval
)) == TYPE_MAIN_VARIANT (valtype
)
7376 && ! current_function_returns_struct
)
7377 retval
= expand_target_expr (retval
);
7379 if (retval
== result
7380 /* Watch out for constructors, which "return" aggregates
7381 via initialization, but which otherwise "return" a pointer. */
7382 || DECL_CONSTRUCTOR_P (current_function_decl
))
7384 /* This is just an error--it's already been reported. */
7385 if (TYPE_SIZE (valtype
) == NULL_TREE
)
7388 if (TYPE_MODE (valtype
) != BLKmode
7389 && any_pending_cleanups (1))
7391 retval
= get_temp_regvar (valtype
, retval
);
7392 use_temp
= obey_regdecls
;
7395 else if (IS_AGGR_TYPE (valtype
) && current_function_returns_struct
)
7397 expand_aggr_init (result
, retval
, 0, LOOKUP_ONLYCONVERTING
);
7398 expand_cleanups_to (NULL_TREE
);
7399 DECL_INITIAL (result
) = NULL_TREE
;
7404 if (TYPE_MODE (valtype
) == VOIDmode
)
7406 if (TYPE_MODE (TREE_TYPE (result
)) != VOIDmode
7407 && warn_return_type
)
7408 warning ("return of void value in function returning non-void");
7409 expand_expr_stmt (retval
);
7413 else if (TYPE_MODE (valtype
) != BLKmode
7414 && any_pending_cleanups (1))
7416 retval
= get_temp_regvar (valtype
, retval
);
7417 expand_cleanups_to (NULL_TREE
);
7418 use_temp
= obey_regdecls
;
7423 retval
= convert_for_initialization (result
, valtype
, retval
,
7425 "return", NULL_TREE
, 0);
7426 DECL_INITIAL (result
) = NULL_TREE
;
7428 if (retval
== error_mark_node
)
7434 if (retval
!= NULL_TREE
7435 && TREE_CODE_CLASS (TREE_CODE (retval
)) == 'd'
7436 && cond_stack
== 0 && loop_stack
== 0 && case_stack
== 0)
7437 current_function_return_value
= retval
;
7441 /* Everything's great--RETVAL is in RESULT. */
7442 if (original_result_rtx
)
7444 store_expr (result
, original_result_rtx
, 0);
7445 expand_cleanups_to (NULL_TREE
);
7446 use_variable (DECL_RTL (result
));
7447 if (ctor_label
&& TREE_CODE (ctor_label
) != ERROR_MARK
)
7448 expand_goto (ctor_label
);
7450 expand_null_return ();
7452 else if (retval
&& retval
!= result
)
7454 /* Clear this out so the later call to decl_function_context
7455 won't end up bombing on us. */
7456 if (DECL_CONTEXT (result
) == error_mark_node
)
7457 DECL_CONTEXT (result
) = NULL_TREE
;
7458 /* Here is where we finally get RETVAL into RESULT.
7459 `expand_return' does the magic of protecting
7460 RESULT from cleanups. */
7461 retval
= fold (build1 (CLEANUP_POINT_EXPR
, TREE_TYPE (result
),
7463 /* This part _must_ come second, because expand_return looks for
7464 the INIT_EXPR as the toplevel node only. :-( */
7465 retval
= build (INIT_EXPR
, TREE_TYPE (result
), result
, retval
);
7466 TREE_SIDE_EFFECTS (retval
) = 1;
7467 expand_return (retval
);
7470 expand_return (result
);
7474 /* We may still need to put RETVAL into RESULT. */
7475 result
= DECL_RESULT (current_function_decl
);
7476 if (original_result_rtx
)
7478 /* Here we have a named return value that went
7479 into memory. We can compute RETVAL into that. */
7481 expand_assignment (result
, retval
, 0, 0);
7483 store_expr (result
, original_result_rtx
, 0);
7484 result
= make_tree (TREE_TYPE (result
), original_result_rtx
);
7486 else if (ctor_label
&& TREE_CODE (ctor_label
) != ERROR_MARK
)
7488 /* Here RETVAL is CURRENT_CLASS_DECL, so there's nothing to do. */
7489 expand_goto (ctor_label
);
7493 /* Here is where we finally get RETVAL into RESULT.
7494 `expand_return' does the magic of protecting
7495 RESULT from cleanups. */
7496 result
= build (INIT_EXPR
, TREE_TYPE (result
), result
, retval
);
7497 TREE_SIDE_EFFECTS (result
) = 1;
7498 expand_return (result
);
7500 else if (TYPE_MODE (TREE_TYPE (result
)) != VOIDmode
)
7501 expand_return (result
);
7504 current_function_returns_value
= returns_value
;
7506 /* These wind up after the BARRIER, which causes problems for
7507 expand_end_binding. What purpose were they supposed to serve? */
7508 if (original_result_rtx
)
7509 use_variable (original_result_rtx
);
7511 use_variable (DECL_RTL (DECL_RESULT (current_function_decl
)));
7514 /* One way to clear out cleanups that EXPR might
7515 generate. Note that this code will really be
7516 dead code, but that is ok--cleanups that were
7517 needed were handled by the magic of `return'. */
7518 expand_cleanups_to (NULL_TREE
);
7521 /* Start a C switch statement, testing expression EXP.
7522 Return EXP if it is valid, an error node otherwise. */
7525 c_expand_start_case (exp
)
7529 register enum tree_code code
;
7531 /* Convert from references, etc. */
7532 exp
= default_conversion (exp
);
7533 type
= TREE_TYPE (exp
);
7534 code
= TREE_CODE (type
);
7536 if (IS_AGGR_TYPE_CODE (code
))
7537 exp
= build_type_conversion (CONVERT_EXPR
, integer_type_node
, exp
, 1);
7539 if (exp
== NULL_TREE
)
7541 error ("switch quantity not an integer");
7542 exp
= error_mark_node
;
7544 type
= TREE_TYPE (exp
);
7545 code
= TREE_CODE (type
);
7547 if (code
!= INTEGER_TYPE
&& code
!= ENUMERAL_TYPE
&& code
!= ERROR_MARK
)
7549 error ("switch quantity not an integer");
7550 exp
= error_mark_node
;
7556 exp
= default_conversion (exp
);
7557 type
= TREE_TYPE (exp
);
7558 index
= get_unwidened (exp
, 0);
7559 /* We can't strip a conversion from a signed type to an unsigned,
7560 because if we did, int_fits_type_p would do the wrong thing
7561 when checking case values for being in range,
7562 and it's too hard to do the right thing. */
7563 if (TREE_UNSIGNED (TREE_TYPE (exp
))
7564 == TREE_UNSIGNED (TREE_TYPE (index
)))
7569 (1, fold (build1 (CLEANUP_POINT_EXPR
, TREE_TYPE (exp
), exp
)),
7570 type
, "switch statement");
7575 /* CONSTP remembers whether or not all the intervening pointers in the `to'
7576 type have been const. */
7578 comp_ptr_ttypes_real (to
, from
, constp
)
7582 for (; ; to
= TREE_TYPE (to
), from
= TREE_TYPE (from
))
7584 if (TREE_CODE (to
) != TREE_CODE (from
))
7587 /* Const and volatile mean something different for function types,
7588 so the usual checks are not appropriate. */
7589 if (TREE_CODE (to
) != FUNCTION_TYPE
&& TREE_CODE (to
) != METHOD_TYPE
)
7591 if (TYPE_READONLY (from
) > TYPE_READONLY (to
)
7592 || TYPE_VOLATILE (from
) > TYPE_VOLATILE (to
))
7596 && (TYPE_READONLY (to
) > TYPE_READONLY (from
)
7597 || TYPE_VOLATILE (to
) > TYPE_READONLY (from
)))
7599 constp
&= TYPE_READONLY (to
);
7602 if (TREE_CODE (to
) != POINTER_TYPE
)
7603 return comptypes (TYPE_MAIN_VARIANT (to
), TYPE_MAIN_VARIANT (from
), 1);
7607 /* When comparing, say, char ** to char const **, this function takes the
7608 'char *' and 'char const *'. Do not pass non-pointer types to this
7611 comp_ptr_ttypes (to
, from
)
7614 return comp_ptr_ttypes_real (to
, from
, 1);