87th Cygnus<->FSF quick merge
[gcc.git] / gcc / cp / typeck.c
1 /* Build expressions with type checking for C++ compiler.
2 Copyright (C) 1987, 88, 89, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
3 Hacked by Michael Tiemann (tiemann@cygnus.com)
4
5 This file is part of GNU CC.
6
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)
10 any later version.
11
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.
16
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. */
21
22
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.
27
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). */
31
32 extern void error ();
33 extern void warning ();
34
35 #include "config.h"
36 #include <stdio.h>
37 #include "tree.h"
38 #include "rtl.h"
39 #include "cp-tree.h"
40 #include "flags.h"
41 #include "output.h"
42
43 int mark_addressable PROTO((tree));
44 static tree convert_for_assignment PROTO((tree, tree, char*, tree, int));
45 /* static */ tree convert_for_initialization PROTO((tree, tree, tree, int, char*, tree, int));
46 extern tree shorten_compare ();
47 extern void binary_op_error ();
48 static tree pointer_int_sum PROTO((enum tree_code, register tree, register tree));
49 static tree pointer_diff PROTO((register tree, register tree));
50 #if 0
51 static tree convert_sequence ();
52 #endif
53 /* static */ tree unary_complex_lvalue PROTO((enum tree_code, tree));
54 static tree get_delta_difference PROTO((tree, tree, int));
55
56 extern rtx original_result_rtx;
57 extern int warn_synth;
58
59 /* Return the target type of TYPE, which meas return T for:
60 T*, T&, T[], T (...), and otherwise, just T. */
61
62 tree
63 target_type (type)
64 tree type;
65 {
66 if (TREE_CODE (type) == REFERENCE_TYPE)
67 type = TREE_TYPE (type);
68 while (TREE_CODE (type) == POINTER_TYPE
69 || TREE_CODE (type) == ARRAY_TYPE
70 || TREE_CODE (type) == FUNCTION_TYPE
71 || TREE_CODE (type) == METHOD_TYPE
72 || TREE_CODE (type) == OFFSET_TYPE)
73 type = TREE_TYPE (type);
74 return type;
75 }
76
77 /* Do `exp = require_complete_type (exp);' to make sure exp
78 does not have an incomplete type. (That includes void types.) */
79
80 tree
81 require_complete_type (value)
82 tree value;
83 {
84 tree type;
85
86 if (current_template_parms)
87 return value;
88
89 type = TREE_TYPE (value);
90
91 /* First, detect a valid value with a complete type. */
92 if (TYPE_SIZE (type) != 0
93 && type != void_type_node
94 && ! (TYPE_LANG_SPECIFIC (type)
95 && (IS_SIGNATURE_POINTER (type) || IS_SIGNATURE_REFERENCE (type))
96 && TYPE_SIZE (SIGNATURE_TYPE (type)) == 0))
97 return value;
98
99 /* If we see X::Y, we build an OFFSET_TYPE which has
100 not been laid out. Try to avoid an error by interpreting
101 it as this->X::Y, if reasonable. */
102 if (TREE_CODE (value) == OFFSET_REF
103 && current_class_ref != 0
104 && TREE_OPERAND (value, 0) == current_class_ref)
105 {
106 tree base, member = TREE_OPERAND (value, 1);
107 tree basetype = TYPE_OFFSET_BASETYPE (type);
108 my_friendly_assert (TREE_CODE (member) == FIELD_DECL, 305);
109 base = convert_pointer_to (basetype, current_class_ptr);
110 value = build (COMPONENT_REF, TREE_TYPE (member),
111 build_indirect_ref (base, NULL_PTR), member);
112 return require_complete_type (value);
113 }
114
115 if (IS_AGGR_TYPE (type) && CLASSTYPE_TEMPLATE_INSTANTIATION (type))
116 {
117 instantiate_class_template (TYPE_MAIN_VARIANT (type));
118 if (TYPE_SIZE (type) != 0)
119 return value;
120 }
121
122 incomplete_type_error (value, type);
123 return error_mark_node;
124 }
125
126 tree
127 complete_type (type)
128 tree type;
129 {
130 if (type == error_mark_node || TYPE_SIZE (type) != NULL_TREE)
131 ;
132 else if (TREE_CODE (type) == ARRAY_TYPE && TYPE_DOMAIN (type))
133 {
134 tree t = complete_type (TREE_TYPE (type));
135 if (TYPE_SIZE (t) != NULL_TREE)
136 type = build_cplus_array_type (t, TYPE_DOMAIN (type));
137 }
138 else if (IS_AGGR_TYPE (type) && CLASSTYPE_TEMPLATE_INSTANTIATION (type))
139 instantiate_class_template (TYPE_MAIN_VARIANT (type));
140
141 return type;
142 }
143
144 /* Return truthvalue of whether type of EXP is instantiated. */
145
146 int
147 type_unknown_p (exp)
148 tree exp;
149 {
150 return (TREE_CODE (exp) == TREE_LIST
151 || TREE_TYPE (exp) == unknown_type_node
152 || (TREE_CODE (TREE_TYPE (exp)) == OFFSET_TYPE
153 && TREE_TYPE (TREE_TYPE (exp)) == unknown_type_node));
154 }
155
156 /* Return truthvalue of whether T is function (or pfn) type. */
157
158 int
159 fntype_p (t)
160 tree t;
161 {
162 return (TREE_CODE (t) == FUNCTION_TYPE || TREE_CODE (t) == METHOD_TYPE
163 || (TREE_CODE (t) == POINTER_TYPE
164 && (TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE
165 || TREE_CODE (TREE_TYPE (t)) == METHOD_TYPE)));
166 }
167
168 /* Do `exp = require_instantiated_type (type, exp);' to make sure EXP
169 does not have an uninstantiated type.
170 TYPE is type to instantiate with, if uninstantiated. */
171
172 tree
173 require_instantiated_type (type, exp, errval)
174 tree type, exp, errval;
175 {
176 if (TREE_TYPE (exp) == NULL_TREE)
177 {
178 error ("argument list may not have an initializer list");
179 return errval;
180 }
181
182 if (TREE_TYPE (exp) == unknown_type_node
183 || (TREE_CODE (TREE_TYPE (exp)) == OFFSET_TYPE
184 && TREE_TYPE (TREE_TYPE (exp)) == unknown_type_node))
185 {
186 exp = instantiate_type (type, exp, 1);
187 if (TREE_TYPE (exp) == error_mark_node)
188 return errval;
189 }
190 return exp;
191 }
192
193 /* Return a variant of TYPE which has all the type qualifiers of LIKE
194 as well as those of TYPE. */
195
196 static tree
197 qualify_type (type, like)
198 tree type, like;
199 {
200 int constflag = TYPE_READONLY (type) || TYPE_READONLY (like);
201 int volflag = TYPE_VOLATILE (type) || TYPE_VOLATILE (like);
202 /* @@ Must do member pointers here. */
203 return cp_build_type_variant (type, constflag, volflag);
204 }
205 \f
206 /* Return the common type of two parameter lists.
207 We assume that comptypes has already been done and returned 1;
208 if that isn't so, this may crash.
209
210 As an optimization, free the space we allocate if the parameter
211 lists are already common. */
212
213 tree
214 commonparms (p1, p2)
215 tree p1, p2;
216 {
217 tree oldargs = p1, newargs, n;
218 int i, len;
219 int any_change = 0;
220 char *first_obj = (char *) oballoc (0);
221
222 len = list_length (p1);
223 newargs = tree_last (p1);
224
225 if (newargs == void_list_node)
226 i = 1;
227 else
228 {
229 i = 0;
230 newargs = 0;
231 }
232
233 for (; i < len; i++)
234 newargs = tree_cons (NULL_TREE, NULL_TREE, newargs);
235
236 n = newargs;
237
238 for (i = 0; p1;
239 p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2), n = TREE_CHAIN (n), i++)
240 {
241 if (TREE_PURPOSE (p1) && !TREE_PURPOSE (p2))
242 {
243 TREE_PURPOSE (n) = TREE_PURPOSE (p1);
244 any_change = 1;
245 }
246 else if (! TREE_PURPOSE (p1))
247 {
248 if (TREE_PURPOSE (p2))
249 {
250 TREE_PURPOSE (n) = TREE_PURPOSE (p2);
251 any_change = 1;
252 }
253 }
254 else
255 {
256 if (1 != simple_cst_equal (TREE_PURPOSE (p1), TREE_PURPOSE (p2)))
257 any_change = 1;
258 TREE_PURPOSE (n) = TREE_PURPOSE (p2);
259 }
260 if (TREE_VALUE (p1) != TREE_VALUE (p2))
261 {
262 any_change = 1;
263 TREE_VALUE (n) = common_type (TREE_VALUE (p1), TREE_VALUE (p2));
264 }
265 else
266 TREE_VALUE (n) = TREE_VALUE (p1);
267 }
268 if (! any_change)
269 {
270 obfree (first_obj);
271 return oldargs;
272 }
273
274 return newargs;
275 }
276
277 /* Return the common type of two types.
278 We assume that comptypes has already been done and returned 1;
279 if that isn't so, this may crash.
280
281 This is the type for the result of most arithmetic operations
282 if the operands have the given two types.
283
284 We do not deal with enumeral types here because they have already been
285 converted to integer types. */
286
287 tree
288 common_type (t1, t2)
289 tree t1, t2;
290 {
291 register enum tree_code code1;
292 register enum tree_code code2;
293 tree attributes;
294
295 /* Save time if the two types are the same. */
296
297 if (t1 == t2) return t1;
298
299 /* If one type is nonsense, use the other. */
300 if (t1 == error_mark_node)
301 return t2;
302 if (t2 == error_mark_node)
303 return t1;
304
305 /* Merge the attributes */
306
307 { register tree a1, a2;
308 a1 = TYPE_ATTRIBUTES (t1);
309 a2 = TYPE_ATTRIBUTES (t2);
310
311 /* Either one unset? Take the set one. */
312
313 if (!(attributes = a1))
314 attributes = a2;
315
316 /* One that completely contains the other? Take it. */
317
318 else if (a2 && !attribute_list_contained (a1, a2))
319 if (attribute_list_contained (a2, a1))
320 attributes = a2;
321 else
322 {
323 /* Pick the longest list, and hang on the other list. */
324 /* ??? For the moment we punt on the issue of attrs with args. */
325
326 if (list_length (a1) < list_length (a2))
327 attributes = a2, a2 = a1;
328
329 for (; a2; a2 = TREE_CHAIN (a2))
330 if (lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2)),
331 attributes) == NULL_TREE)
332 {
333 a1 = copy_node (a2);
334 TREE_CHAIN (a1) = attributes;
335 attributes = a1;
336 }
337 }
338 }
339
340 /* Treat an enum type as the unsigned integer type of the same width. */
341
342 if (TREE_CODE (t1) == ENUMERAL_TYPE)
343 t1 = type_for_size (TYPE_PRECISION (t1), 1);
344 if (TREE_CODE (t2) == ENUMERAL_TYPE)
345 t2 = type_for_size (TYPE_PRECISION (t2), 1);
346
347 if (TYPE_PTRMEMFUNC_P (t1))
348 t1 = TYPE_PTRMEMFUNC_FN_TYPE (t1);
349 if (TYPE_PTRMEMFUNC_P (t2))
350 t2 = TYPE_PTRMEMFUNC_FN_TYPE (t2);
351
352 code1 = TREE_CODE (t1);
353 code2 = TREE_CODE (t2);
354
355 switch (code1)
356 {
357 case INTEGER_TYPE:
358 case REAL_TYPE:
359 /* If only one is real, use it as the result. */
360
361 if (code1 == REAL_TYPE && code2 != REAL_TYPE)
362 return build_type_attribute_variant (t1, attributes);
363
364 if (code2 == REAL_TYPE && code1 != REAL_TYPE)
365 return build_type_attribute_variant (t2, attributes);
366
367 /* Both real or both integers; use the one with greater precision. */
368
369 if (TYPE_PRECISION (t1) > TYPE_PRECISION (t2))
370 return build_type_attribute_variant (t1, attributes);
371 else if (TYPE_PRECISION (t2) > TYPE_PRECISION (t1))
372 return build_type_attribute_variant (t2, attributes);
373
374 /* Same precision. Prefer longs to ints even when same size. */
375
376 if (TYPE_MAIN_VARIANT (t1) == long_unsigned_type_node
377 || TYPE_MAIN_VARIANT (t2) == long_unsigned_type_node)
378 return build_type_attribute_variant (long_unsigned_type_node,
379 attributes);
380
381 if (TYPE_MAIN_VARIANT (t1) == long_integer_type_node
382 || TYPE_MAIN_VARIANT (t2) == long_integer_type_node)
383 {
384 /* But preserve unsignedness from the other type,
385 since long cannot hold all the values of an unsigned int. */
386 if (TREE_UNSIGNED (t1) || TREE_UNSIGNED (t2))
387 t1 = long_unsigned_type_node;
388 else
389 t1 = long_integer_type_node;
390 return build_type_attribute_variant (t1, attributes);
391 }
392
393 if (TYPE_MAIN_VARIANT (t1) == long_double_type_node
394 || TYPE_MAIN_VARIANT (t2) == long_double_type_node)
395 return build_type_attribute_variant (long_double_type_node,
396 attributes);
397
398 /* Otherwise prefer the unsigned one. */
399
400 if (TREE_UNSIGNED (t1))
401 return build_type_attribute_variant (t1, attributes);
402 else
403 return build_type_attribute_variant (t2, attributes);
404
405 case POINTER_TYPE:
406 case REFERENCE_TYPE:
407 /* For two pointers, do this recursively on the target type,
408 and combine the qualifiers of the two types' targets. */
409 /* This code was turned off; I don't know why.
410 But ANSI C++ specifies doing this with the qualifiers.
411 So I turned it on again. */
412 {
413 tree tt1 = TYPE_MAIN_VARIANT (TREE_TYPE (t1));
414 tree tt2 = TYPE_MAIN_VARIANT (TREE_TYPE (t2));
415 int constp
416 = TYPE_READONLY (TREE_TYPE (t1)) || TYPE_READONLY (TREE_TYPE (t2));
417 int volatilep
418 = TYPE_VOLATILE (TREE_TYPE (t1)) || TYPE_VOLATILE (TREE_TYPE (t2));
419 tree target;
420
421 if (tt1 == tt2)
422 target = tt1;
423 else if (tt1 == void_type_node || tt2 == void_type_node)
424 target = void_type_node;
425 else
426 target = common_type (tt1, tt2);
427
428 target = cp_build_type_variant (target, constp, volatilep);
429 if (code1 == POINTER_TYPE)
430 t1 = build_pointer_type (target);
431 else
432 t1 = build_reference_type (target);
433 t1 = build_type_attribute_variant (t1, attributes);
434
435 if (TREE_CODE (target) == METHOD_TYPE)
436 t1 = build_ptrmemfunc_type (t1);
437
438 return t1;
439 }
440
441 case ARRAY_TYPE:
442 {
443 tree elt = common_type (TREE_TYPE (t1), TREE_TYPE (t2));
444 /* Save space: see if the result is identical to one of the args. */
445 if (elt == TREE_TYPE (t1) && TYPE_DOMAIN (t1))
446 return build_type_attribute_variant (t1, attributes);
447 if (elt == TREE_TYPE (t2) && TYPE_DOMAIN (t2))
448 return build_type_attribute_variant (t2, attributes);
449 /* Merge the element types, and have a size if either arg has one. */
450 t1 = build_cplus_array_type
451 (elt, TYPE_DOMAIN (TYPE_DOMAIN (t1) ? t1 : t2));
452 return build_type_attribute_variant (t1, attributes);
453 }
454
455 case FUNCTION_TYPE:
456 /* Function types: prefer the one that specified arg types.
457 If both do, merge the arg types. Also merge the return types. */
458 {
459 tree valtype = common_type (TREE_TYPE (t1), TREE_TYPE (t2));
460 tree p1 = TYPE_ARG_TYPES (t1);
461 tree p2 = TYPE_ARG_TYPES (t2);
462 tree rval, raises;
463
464 /* Save space: see if the result is identical to one of the args. */
465 if (valtype == TREE_TYPE (t1) && ! p2)
466 return build_type_attribute_variant (t1, attributes);
467 if (valtype == TREE_TYPE (t2) && ! p1)
468 return build_type_attribute_variant (t2, attributes);
469
470 /* Simple way if one arg fails to specify argument types. */
471 if (p1 == NULL_TREE || TREE_VALUE (p1) == void_type_node)
472 {
473 rval = build_function_type (valtype, p2);
474 if ((raises = TYPE_RAISES_EXCEPTIONS (t2)))
475 rval = build_exception_variant (rval, raises);
476 return build_type_attribute_variant (rval, attributes);
477 }
478 raises = TYPE_RAISES_EXCEPTIONS (t1);
479 if (p2 == NULL_TREE || TREE_VALUE (p2) == void_type_node)
480 {
481 rval = build_function_type (valtype, p1);
482 if (raises)
483 rval = build_exception_variant (rval, raises);
484 return build_type_attribute_variant (rval, attributes);
485 }
486
487 rval = build_function_type (valtype, commonparms (p1, p2));
488 rval = build_exception_variant (rval, raises);
489 return build_type_attribute_variant (rval, attributes);
490 }
491
492 case RECORD_TYPE:
493 case UNION_TYPE:
494 my_friendly_assert (TYPE_MAIN_VARIANT (t1) == t1
495 && TYPE_MAIN_VARIANT (t2) == t2, 306);
496
497 if (DERIVED_FROM_P (t1, t2) && binfo_or_else (t1, t2))
498 return build_type_attribute_variant (t1, attributes);
499 else if (binfo_or_else (t2, t1))
500 return build_type_attribute_variant (t2, attributes);
501 else
502 compiler_error ("common_type called with uncommon aggregate types");
503
504 case METHOD_TYPE:
505 if (TREE_CODE (TREE_TYPE (t1)) == TREE_CODE (TREE_TYPE (t2)))
506 {
507 /* Get this value the long way, since TYPE_METHOD_BASETYPE
508 is just the main variant of this. */
509 tree basetype;
510 tree raises, t3;
511
512 tree b1 = TYPE_OFFSET_BASETYPE (t1);
513 tree b2 = TYPE_OFFSET_BASETYPE (t2);
514
515 if (comptypes (b1, b2, 1)
516 || (DERIVED_FROM_P (b1, b2) && binfo_or_else (b1, b2)))
517 basetype = TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t2)));
518 else
519 {
520 if (binfo_or_else (b2, b1) == NULL_TREE)
521 compiler_error ("common_type called with uncommon method types");
522 basetype = TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t1)));
523 }
524
525 raises = TYPE_RAISES_EXCEPTIONS (t1);
526
527 /* If this was a member function type, get back to the
528 original type of type member function (i.e., without
529 the class instance variable up front. */
530 t1 = build_function_type (TREE_TYPE (t1), TREE_CHAIN (TYPE_ARG_TYPES (t1)));
531 t2 = build_function_type (TREE_TYPE (t2), TREE_CHAIN (TYPE_ARG_TYPES (t2)));
532 t3 = common_type (t1, t2);
533 t3 = build_cplus_method_type (basetype, TREE_TYPE (t3), TYPE_ARG_TYPES (t3));
534 t1 = build_exception_variant (t3, raises);
535 }
536 else
537 compiler_error ("common_type called with uncommon method types");
538
539 return build_type_attribute_variant (t1, attributes);
540
541 case OFFSET_TYPE:
542 if (TREE_TYPE (t1) == TREE_TYPE (t2))
543 {
544 tree b1 = TYPE_OFFSET_BASETYPE (t1);
545 tree b2 = TYPE_OFFSET_BASETYPE (t2);
546
547 if (comptypes (b1, b2, 1)
548 || (DERIVED_FROM_P (b1, b2) && binfo_or_else (b1, b2)))
549 return build_type_attribute_variant (t2, attributes);
550 else if (binfo_or_else (b2, b1))
551 return build_type_attribute_variant (t1, attributes);
552 }
553 compiler_error ("common_type called with uncommon member types");
554
555 default:
556 return build_type_attribute_variant (t1, attributes);
557 }
558 }
559 \f
560 /* Return 1 if TYPE1 and TYPE2 raise the same exceptions. */
561
562 int
563 compexcepttypes (t1, t2)
564 tree t1, t2;
565 {
566 return TYPE_RAISES_EXCEPTIONS (t1) == TYPE_RAISES_EXCEPTIONS (t2);
567 }
568
569 static int
570 comp_array_types (cmp, t1, t2, strict)
571 register int (*cmp)();
572 tree t1, t2;
573 int strict;
574 {
575 tree d1 = TYPE_DOMAIN (t1);
576 tree d2 = TYPE_DOMAIN (t2);
577
578 /* Target types must match incl. qualifiers. */
579 if (!(TREE_TYPE (t1) == TREE_TYPE (t2)
580 || (*cmp) (TREE_TYPE (t1), TREE_TYPE (t2), strict)))
581 return 0;
582
583 /* Sizes must match unless one is missing or variable. */
584 if (d1 == 0 || d2 == 0 || d1 == d2
585 || TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST
586 || TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST
587 || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST
588 || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST)
589 return 1;
590
591 return ((TREE_INT_CST_LOW (TYPE_MIN_VALUE (d1))
592 == TREE_INT_CST_LOW (TYPE_MIN_VALUE (d2)))
593 && (TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d1))
594 == TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d2)))
595 && (TREE_INT_CST_LOW (TYPE_MAX_VALUE (d1))
596 == TREE_INT_CST_LOW (TYPE_MAX_VALUE (d2)))
597 && (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d1))
598 == TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d2))));
599 }
600
601 /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
602 or various other operations. This is what ANSI C++ speaks of as
603 "being the same".
604
605 For C++: argument STRICT says we should be strict about this
606 comparison:
607
608 2 : strict, except that if one type is a reference and
609 the other is not, compare the target type of the
610 reference to the type that's not a reference (ARM, p308).
611 This is used for checking for invalid overloading.
612 1 : strict (compared according to ANSI C)
613 This is used for checking whether two function decls match.
614 0 : <= (compared according to C++)
615 -1: <= or >= (relaxed)
616
617 Otherwise, pointers involving base classes and derived classes
618 can be mixed as valid: i.e. a pointer to a base class may be assigned
619 to a pointer to one of its derived classes, as per C++. A pointer to
620 a derived class may be passed as a parameter to a function expecting a
621 pointer to a base classes. These allowances do not commute. In this
622 case, TYPE1 is assumed to be the base class, and TYPE2 is assumed to
623 be the derived class. */
624
625 int
626 comptypes (type1, type2, strict)
627 tree type1, type2;
628 int strict;
629 {
630 register tree t1 = type1;
631 register tree t2 = type2;
632 int attrval, val;
633
634 /* Suppress errors caused by previously reported errors */
635
636 if (t1 == t2)
637 return 1;
638
639 /* This should never happen. */
640 my_friendly_assert (t1 != error_mark_node, 307);
641
642 if (t2 == error_mark_node)
643 return 0;
644
645 if (strict < 0)
646 {
647 /* Treat an enum type as the unsigned integer type of the same width. */
648
649 if (TREE_CODE (t1) == ENUMERAL_TYPE)
650 t1 = type_for_size (TYPE_PRECISION (t1), 1);
651 if (TREE_CODE (t2) == ENUMERAL_TYPE)
652 t2 = type_for_size (TYPE_PRECISION (t2), 1);
653
654 if (t1 == t2)
655 return 1;
656 }
657
658 if (TYPE_PTRMEMFUNC_P (t1))
659 t1 = TYPE_PTRMEMFUNC_FN_TYPE (t1);
660 if (TYPE_PTRMEMFUNC_P (t2))
661 t2 = TYPE_PTRMEMFUNC_FN_TYPE (t2);
662
663 /* Different classes of types can't be compatible. */
664
665 if (TREE_CODE (t1) != TREE_CODE (t2))
666 {
667 if (strict == 2
668 && ((TREE_CODE (t1) == REFERENCE_TYPE)
669 ^ (TREE_CODE (t2) == REFERENCE_TYPE)))
670 {
671 if (TREE_CODE (t1) == REFERENCE_TYPE)
672 return comptypes (TREE_TYPE (t1), t2, 1);
673 return comptypes (t1, TREE_TYPE (t2), 1);
674 }
675
676 return 0;
677 }
678 if (strict > 1)
679 strict = 1;
680
681 /* Qualifiers must match. */
682
683 if (TYPE_READONLY (t1) != TYPE_READONLY (t2))
684 return 0;
685 if (TYPE_VOLATILE (t1) != TYPE_VOLATILE (t2))
686 return 0;
687
688 /* Allow for two different type nodes which have essentially the same
689 definition. Note that we already checked for equality of the type
690 type qualifiers (just above). */
691
692 if (TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
693 return 1;
694
695 /* ??? COMP_TYPE_ATTRIBUTES is currently useless for variables as each
696 attribute is its own main variant (`val' will remain 0). */
697 #ifndef COMP_TYPE_ATTRIBUTES
698 #define COMP_TYPE_ATTRIBUTES(t1,t2) 1
699 #endif
700
701 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
702 if (! (attrval = COMP_TYPE_ATTRIBUTES (t1, t2)))
703 return 0;
704
705 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
706 val = 0;
707
708 switch (TREE_CODE (t1))
709 {
710 case RECORD_TYPE:
711 case UNION_TYPE:
712 if (CLASSTYPE_TEMPLATE_INFO (t1) && CLASSTYPE_TEMPLATE_INFO (t2)
713 && CLASSTYPE_TI_TEMPLATE (t1) == CLASSTYPE_TI_TEMPLATE (t2))
714 {
715 int i = TREE_VEC_LENGTH (CLASSTYPE_TI_ARGS (t1));
716 tree *p1 = &TREE_VEC_ELT (CLASSTYPE_TI_ARGS (t1), 0);
717 tree *p2 = &TREE_VEC_ELT (CLASSTYPE_TI_ARGS (t2), 0);
718
719 while (i--)
720 {
721 if (TREE_CODE_CLASS (TREE_CODE (p1[i])) == 't')
722 {
723 if (! comptypes (p1[i], p2[i], 1))
724 return 0;
725 }
726 else
727 {
728 if (simple_cst_equal (p1[i], p2[i]) <= 0)
729 return 0;
730 }
731 }
732 return 1;
733 }
734 if (strict <= 0)
735 goto look_hard;
736 return 0;
737
738 case OFFSET_TYPE:
739 val = (comptypes (build_pointer_type (TYPE_OFFSET_BASETYPE (t1)),
740 build_pointer_type (TYPE_OFFSET_BASETYPE (t2)), strict)
741 && comptypes (TREE_TYPE (t1), TREE_TYPE (t2), strict));
742 break;
743
744 case METHOD_TYPE:
745 if (! compexcepttypes (t1, t2))
746 return 0;
747
748 /* This case is anti-symmetrical!
749 One can pass a base member (or member function)
750 to something expecting a derived member (or member function),
751 but not vice-versa! */
752
753 val = (comptypes (TREE_TYPE (t1), TREE_TYPE (t2), strict)
754 && compparms (TYPE_ARG_TYPES (t1),
755 TYPE_ARG_TYPES (t2), strict));
756 break;
757
758 case POINTER_TYPE:
759 case REFERENCE_TYPE:
760 t1 = TREE_TYPE (t1);
761 t2 = TREE_TYPE (t2);
762 if (t1 == t2)
763 {
764 val = 1;
765 break;
766 }
767 if (strict <= 0)
768 {
769 if (TREE_CODE (t1) == RECORD_TYPE && TREE_CODE (t2) == RECORD_TYPE)
770 {
771 int rval;
772 look_hard:
773 rval = t1 == t2 || UNIQUELY_DERIVED_FROM_P (t1, t2);
774
775 if (rval)
776 {
777 val = 1;
778 break;
779 }
780 if (strict < 0)
781 {
782 val = UNIQUELY_DERIVED_FROM_P (t2, t1);
783 break;
784 }
785 }
786 return 0;
787 }
788 else
789 val = comptypes (t1, t2, strict);
790 break;
791
792 case FUNCTION_TYPE:
793 if (! compexcepttypes (t1, t2))
794 return 0;
795
796 val = ((TREE_TYPE (t1) == TREE_TYPE (t2)
797 || comptypes (TREE_TYPE (t1), TREE_TYPE (t2), strict))
798 && compparms (TYPE_ARG_TYPES (t1), TYPE_ARG_TYPES (t2), strict));
799 break;
800
801 case ARRAY_TYPE:
802 /* Target types must match incl. qualifiers. */
803 val = comp_array_types (comptypes, t1, t2, strict);
804 break;
805
806 case TEMPLATE_TYPE_PARM:
807 return TEMPLATE_TYPE_IDX (t1) == TEMPLATE_TYPE_IDX (t2);
808
809 case TYPENAME_TYPE:
810 if (TYPE_IDENTIFIER (t1) != TYPE_IDENTIFIER (t2))
811 return 0;
812 return comptypes (TYPE_CONTEXT (t1), TYPE_CONTEXT (t2), 1);
813 }
814 return attrval == 2 && val == 1 ? 2 : val;
815 }
816
817 /* Return 1 if TTL and TTR are pointers to types that are equivalent,
818 ignoring their qualifiers.
819
820 NPTRS is the number of pointers we can strip off and keep cool.
821 This is used to permit (for aggr A, aggr B) A, B* to convert to A*,
822 but to not permit B** to convert to A**. */
823
824 int
825 comp_target_types (ttl, ttr, nptrs)
826 tree ttl, ttr;
827 int nptrs;
828 {
829 ttl = TYPE_MAIN_VARIANT (ttl);
830 ttr = TYPE_MAIN_VARIANT (ttr);
831 if (ttl == ttr)
832 return 1;
833
834 if (TREE_CODE (ttr) != TREE_CODE (ttl))
835 return 0;
836
837 if (TREE_CODE (ttr) == POINTER_TYPE)
838 {
839 ttl = TREE_TYPE (ttl);
840 ttr = TREE_TYPE (ttr);
841
842 if (nptrs > 0)
843 {
844 if (TREE_CODE (ttl) == VOID_TYPE
845 && TREE_CODE (ttr) != FUNCTION_TYPE
846 && TREE_CODE (ttr) != METHOD_TYPE
847 && TREE_CODE (ttr) != OFFSET_TYPE)
848 return 1;
849 else if (TREE_CODE (ttr) == VOID_TYPE
850 && TREE_CODE (ttl) != FUNCTION_TYPE
851 && TREE_CODE (ttl) != METHOD_TYPE
852 && TREE_CODE (ttl) != OFFSET_TYPE)
853 return -1;
854 else if (TREE_CODE (ttl) == POINTER_TYPE
855 || TREE_CODE (ttl) == ARRAY_TYPE)
856 {
857 if (comp_ptr_ttypes (ttl, ttr))
858 return 1;
859 else if (comp_ptr_ttypes (ttr, ttl))
860 return -1;
861 return 0;
862 }
863 }
864
865 /* Const and volatile mean something different for function types,
866 so the usual checks are not appropriate. */
867 if (TREE_CODE (ttl) == FUNCTION_TYPE || TREE_CODE (ttl) == METHOD_TYPE)
868 return comp_target_types (ttl, ttr, nptrs - 1);
869
870 /* Make sure that the cv-quals change only in the same direction as
871 the target type. */
872 {
873 int t;
874 int c = TYPE_READONLY (ttl) - TYPE_READONLY (ttr);
875 int v = TYPE_VOLATILE (ttl) - TYPE_VOLATILE (ttr);
876
877 if ((c > 0 && v < 0) || (c < 0 && v > 0))
878 return 0;
879
880 if (TYPE_MAIN_VARIANT (ttl) == TYPE_MAIN_VARIANT (ttr))
881 return (c + v < 0) ? -1 : 1;
882
883 t = comp_target_types (ttl, ttr, nptrs - 1);
884 if ((t == 1 && c + v >= 0) || (t == -1 && c + v <= 0))
885 return t;
886
887 return 0;
888 }
889 }
890
891 if (TREE_CODE (ttr) == REFERENCE_TYPE)
892 return comp_target_types (TREE_TYPE (ttl), TREE_TYPE (ttr), nptrs);
893 if (TREE_CODE (ttr) == ARRAY_TYPE)
894 return comp_array_types (comp_target_types, ttl, ttr, 0);
895 else if (TREE_CODE (ttr) == FUNCTION_TYPE || TREE_CODE (ttr) == METHOD_TYPE)
896 if (comp_target_types (TREE_TYPE (ttl), TREE_TYPE (ttr), nptrs))
897 switch (comp_target_parms (TYPE_ARG_TYPES (ttl), TYPE_ARG_TYPES (ttr), 1))
898 {
899 case 0:
900 return 0;
901 case 1:
902 return 1;
903 case 2:
904 return -1;
905 default:
906 my_friendly_abort (112);
907 }
908 else
909 return 0;
910
911 /* for C++ */
912 else if (TREE_CODE (ttr) == OFFSET_TYPE)
913 {
914 /* Contravariance: we can assign a pointer to base member to a pointer
915 to derived member. Note difference from simple pointer case, where
916 we can pass a pointer to derived to a pointer to base. */
917 if (comptypes (TYPE_OFFSET_BASETYPE (ttr), TYPE_OFFSET_BASETYPE (ttl), 0))
918 return comp_target_types (TREE_TYPE (ttl), TREE_TYPE (ttr), nptrs);
919 else if (comptypes (TYPE_OFFSET_BASETYPE (ttl), TYPE_OFFSET_BASETYPE (ttr), 0)
920 && comp_target_types (TREE_TYPE (ttl), TREE_TYPE (ttr), nptrs))
921 return -1;
922 }
923 else if (IS_AGGR_TYPE (ttl))
924 {
925 if (nptrs < 0)
926 return 0;
927 if (comptypes (build_pointer_type (ttl), build_pointer_type (ttr), 0))
928 return 1;
929 if (comptypes (build_pointer_type (ttr), build_pointer_type (ttl), 0))
930 return -1;
931 return 0;
932 }
933
934 return 0;
935 }
936
937 /* If two types share a common base type, return that basetype.
938 If there is not a unique most-derived base type, this function
939 returns ERROR_MARK_NODE. */
940
941 tree
942 common_base_type (tt1, tt2)
943 tree tt1, tt2;
944 {
945 tree best = NULL_TREE;
946 int i;
947
948 /* If one is a baseclass of another, that's good enough. */
949 if (UNIQUELY_DERIVED_FROM_P (tt1, tt2))
950 return tt1;
951 if (UNIQUELY_DERIVED_FROM_P (tt2, tt1))
952 return tt2;
953
954 /* Otherwise, try to find a unique baseclass of TT1
955 that is shared by TT2, and follow that down. */
956 for (i = CLASSTYPE_N_BASECLASSES (tt1)-1; i >= 0; i--)
957 {
958 tree basetype = TYPE_BINFO_BASETYPE (tt1, i);
959 tree trial = common_base_type (basetype, tt2);
960 if (trial)
961 {
962 if (trial == error_mark_node)
963 return trial;
964 if (best == NULL_TREE)
965 best = trial;
966 else if (best != trial)
967 return error_mark_node;
968 }
969 }
970
971 /* Same for TT2. */
972 for (i = CLASSTYPE_N_BASECLASSES (tt2)-1; i >= 0; i--)
973 {
974 tree basetype = TYPE_BINFO_BASETYPE (tt2, i);
975 tree trial = common_base_type (tt1, basetype);
976 if (trial)
977 {
978 if (trial == error_mark_node)
979 return trial;
980 if (best == NULL_TREE)
981 best = trial;
982 else if (best != trial)
983 return error_mark_node;
984 }
985 }
986 return best;
987 }
988 \f
989 /* Subroutines of `comptypes'. */
990
991 /* Return 1 if two parameter type lists PARMS1 and PARMS2
992 are equivalent in the sense that functions with those parameter types
993 can have equivalent types.
994 If either list is empty, we win.
995 Otherwise, the two lists must be equivalent, element by element.
996
997 C++: See comment above about TYPE1, TYPE2, STRICT.
998 If STRICT == 3, it means checking is strict, but do not compare
999 default parameter values. */
1000
1001 int
1002 compparms (parms1, parms2, strict)
1003 tree parms1, parms2;
1004 int strict;
1005 {
1006 register tree t1 = parms1, t2 = parms2;
1007
1008 /* An unspecified parmlist matches any specified parmlist
1009 whose argument types don't need default promotions. */
1010
1011 if (strict <= 0 && t1 == 0)
1012 return self_promoting_args_p (t2);
1013 if (strict < 0 && t2 == 0)
1014 return self_promoting_args_p (t1);
1015
1016 while (1)
1017 {
1018 if (t1 == 0 && t2 == 0)
1019 return 1;
1020 /* If one parmlist is shorter than the other,
1021 they fail to match, unless STRICT is <= 0. */
1022 if (t1 == 0 || t2 == 0)
1023 {
1024 if (strict > 0)
1025 return 0;
1026 if (strict < 0)
1027 return 1;
1028 if (strict == 0)
1029 return t1 && TREE_PURPOSE (t1);
1030 }
1031 if (! comptypes (TREE_VALUE (t2), TREE_VALUE (t1), strict))
1032 {
1033 if (strict > 0)
1034 return 0;
1035 if (strict == 0)
1036 return t2 == void_list_node && TREE_PURPOSE (t1);
1037 return TREE_PURPOSE (t1) || TREE_PURPOSE (t2);
1038 }
1039
1040 t1 = TREE_CHAIN (t1);
1041 t2 = TREE_CHAIN (t2);
1042 }
1043 }
1044
1045 /* This really wants return whether or not parameter type lists
1046 would make their owning functions assignment compatible or not. */
1047
1048 int
1049 comp_target_parms (parms1, parms2, strict)
1050 tree parms1, parms2;
1051 int strict;
1052 {
1053 register tree t1 = parms1, t2 = parms2;
1054 int warn_contravariance = 0;
1055
1056 /* An unspecified parmlist matches any specified parmlist
1057 whose argument types don't need default promotions.
1058 @@@ see 13.3.3 for a counterexample... */
1059
1060 if (t1 == 0 && t2 != 0)
1061 {
1062 cp_pedwarn ("ANSI C++ prohibits conversion from `(%#T)' to `(...)'",
1063 parms2);
1064 return self_promoting_args_p (t2);
1065 }
1066 if (t2 == 0)
1067 return self_promoting_args_p (t1);
1068
1069 for (; t1 || t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
1070 {
1071 tree p1, p2;
1072
1073 /* If one parmlist is shorter than the other,
1074 they fail to match, unless STRICT is <= 0. */
1075 if (t1 == 0 || t2 == 0)
1076 {
1077 if (strict > 0)
1078 return 0;
1079 if (strict < 0)
1080 return 1 + warn_contravariance;
1081 return ((t1 && TREE_PURPOSE (t1)) + warn_contravariance);
1082 }
1083 p1 = TREE_VALUE (t1);
1084 p2 = TREE_VALUE (t2);
1085 if (p1 == p2)
1086 continue;
1087
1088 if ((TREE_CODE (p1) == POINTER_TYPE && TREE_CODE (p2) == POINTER_TYPE)
1089 || (TREE_CODE (p1) == REFERENCE_TYPE && TREE_CODE (p2) == REFERENCE_TYPE))
1090 {
1091 if (strict <= 0
1092 && (TYPE_MAIN_VARIANT (TREE_TYPE (p1))
1093 == TYPE_MAIN_VARIANT (TREE_TYPE (p2))))
1094 continue;
1095
1096 /* The following is wrong for contravariance,
1097 but many programs depend on it. */
1098 if (TREE_TYPE (p1) == void_type_node)
1099 continue;
1100 if (TREE_TYPE (p2) == void_type_node)
1101 {
1102 warn_contravariance = 1;
1103 continue;
1104 }
1105 if (IS_AGGR_TYPE (TREE_TYPE (p1)))
1106 {
1107 if (comptypes (p2, p1, 0) == 0)
1108 {
1109 if (comptypes (p1, p2, 0) != 0)
1110 warn_contravariance = 1;
1111 else
1112 return 0;
1113 }
1114 continue;
1115 }
1116 }
1117 /* Note backwards order due to contravariance. */
1118 if (comp_target_types (p2, p1, 1) == 0)
1119 {
1120 if (comp_target_types (p1, p2, 1))
1121 {
1122 warn_contravariance = 1;
1123 continue;
1124 }
1125 if (strict != 0)
1126 return 0;
1127 }
1128 /* Target types are compatible--just make sure that if
1129 we use parameter lists, that they are ok as well. */
1130 if (TREE_CODE (p1) == FUNCTION_TYPE || TREE_CODE (p1) == METHOD_TYPE)
1131 switch (comp_target_parms (TYPE_ARG_TYPES (p1),
1132 TYPE_ARG_TYPES (p2),
1133 strict))
1134 {
1135 case 0:
1136 return 0;
1137 case 1:
1138 break;
1139 case 2:
1140 warn_contravariance = 1;
1141 }
1142
1143 if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2))
1144 {
1145 int cmp = simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2));
1146 if (cmp < 0)
1147 my_friendly_abort (114);
1148 if (cmp == 0)
1149 return 0;
1150 }
1151 }
1152 return 1 + warn_contravariance;
1153 }
1154
1155 /* Return 1 if PARMS specifies a fixed number of parameters
1156 and none of their types is affected by default promotions. */
1157
1158 int
1159 self_promoting_args_p (parms)
1160 tree parms;
1161 {
1162 register tree t;
1163 for (t = parms; t; t = TREE_CHAIN (t))
1164 {
1165 register tree type = TREE_VALUE (t);
1166
1167 if (TREE_CHAIN (t) == 0 && type != void_type_node)
1168 return 0;
1169
1170 if (type == 0)
1171 return 0;
1172
1173 if (TYPE_MAIN_VARIANT (type) == float_type_node)
1174 return 0;
1175
1176 if (C_PROMOTING_INTEGER_TYPE_P (type))
1177 return 0;
1178 }
1179 return 1;
1180 }
1181 \f
1182 /* Return an unsigned type the same as TYPE in other respects.
1183
1184 C++: must make these work for type variants as well. */
1185
1186 tree
1187 unsigned_type (type)
1188 tree type;
1189 {
1190 tree type1 = TYPE_MAIN_VARIANT (type);
1191 if (type1 == signed_char_type_node || type1 == char_type_node)
1192 return unsigned_char_type_node;
1193 if (type1 == integer_type_node)
1194 return unsigned_type_node;
1195 if (type1 == short_integer_type_node)
1196 return short_unsigned_type_node;
1197 if (type1 == long_integer_type_node)
1198 return long_unsigned_type_node;
1199 if (type1 == long_long_integer_type_node)
1200 return long_long_unsigned_type_node;
1201 if (type1 == intDI_type_node)
1202 return unsigned_intDI_type_node;
1203 if (type1 == intSI_type_node)
1204 return unsigned_intSI_type_node;
1205 if (type1 == intHI_type_node)
1206 return unsigned_intHI_type_node;
1207 if (type1 == intQI_type_node)
1208 return unsigned_intQI_type_node;
1209 return type;
1210 }
1211
1212 /* Return a signed type the same as TYPE in other respects. */
1213
1214 tree
1215 signed_type (type)
1216 tree type;
1217 {
1218 tree type1 = TYPE_MAIN_VARIANT (type);
1219 if (type1 == unsigned_char_type_node || type1 == char_type_node)
1220 return signed_char_type_node;
1221 if (type1 == unsigned_type_node)
1222 return integer_type_node;
1223 if (type1 == short_unsigned_type_node)
1224 return short_integer_type_node;
1225 if (type1 == long_unsigned_type_node)
1226 return long_integer_type_node;
1227 if (type1 == long_long_unsigned_type_node)
1228 return long_long_integer_type_node;
1229 if (type1 == unsigned_intDI_type_node)
1230 return intDI_type_node;
1231 if (type1 == unsigned_intSI_type_node)
1232 return intSI_type_node;
1233 if (type1 == unsigned_intHI_type_node)
1234 return intHI_type_node;
1235 if (type1 == unsigned_intQI_type_node)
1236 return intQI_type_node;
1237 return type;
1238 }
1239
1240 /* Return a type the same as TYPE except unsigned or
1241 signed according to UNSIGNEDP. */
1242
1243 tree
1244 signed_or_unsigned_type (unsignedp, type)
1245 int unsignedp;
1246 tree type;
1247 {
1248 if (! INTEGRAL_TYPE_P (type))
1249 return type;
1250 if (TYPE_PRECISION (type) == TYPE_PRECISION (signed_char_type_node))
1251 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
1252 if (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
1253 return unsignedp ? unsigned_type_node : integer_type_node;
1254 if (TYPE_PRECISION (type) == TYPE_PRECISION (short_integer_type_node))
1255 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
1256 if (TYPE_PRECISION (type) == TYPE_PRECISION (long_integer_type_node))
1257 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
1258 if (TYPE_PRECISION (type) == TYPE_PRECISION (long_long_integer_type_node))
1259 return (unsignedp ? long_long_unsigned_type_node
1260 : long_long_integer_type_node);
1261 return type;
1262 }
1263
1264 /* Compute the value of the `sizeof' operator. */
1265
1266 tree
1267 c_sizeof (type)
1268 tree type;
1269 {
1270 enum tree_code code = TREE_CODE (type);
1271 tree t;
1272
1273 if (current_template_parms)
1274 return build_min (SIZEOF_EXPR, sizetype, type);
1275
1276 if (code == FUNCTION_TYPE)
1277 {
1278 if (pedantic || warn_pointer_arith)
1279 pedwarn ("ANSI C++ forbids taking the sizeof a function type");
1280 return size_int (1);
1281 }
1282 if (code == METHOD_TYPE)
1283 {
1284 if (pedantic || warn_pointer_arith)
1285 pedwarn ("ANSI C++ forbids taking the sizeof a method type");
1286 return size_int (1);
1287 }
1288 if (code == VOID_TYPE)
1289 {
1290 if (pedantic || warn_pointer_arith)
1291 pedwarn ("ANSI C++ forbids taking the sizeof a void type");
1292 return size_int (1);
1293 }
1294 if (code == ERROR_MARK)
1295 return size_int (1);
1296
1297 /* ARM $5.3.2: ``When applied to a reference, the result is the size of the
1298 referenced object.'' */
1299 if (code == REFERENCE_TYPE)
1300 type = TREE_TYPE (type);
1301
1302 /* We couldn't find anything in the ARM or the draft standard that says,
1303 one way or the other, if doing sizeof on something that doesn't have
1304 an object associated with it is correct or incorrect. For example, if
1305 you declare `struct S { char str[16]; };', and in your program do
1306 a `sizeof (S::str)', should we flag that as an error or should we give
1307 the size of it? Since it seems like a reasonable thing to do, we'll go
1308 with giving the value. */
1309 if (code == OFFSET_TYPE)
1310 type = TREE_TYPE (type);
1311
1312 /* @@ This also produces an error for a signature ref.
1313 In that case we should be able to do better. */
1314 if (IS_SIGNATURE (type))
1315 {
1316 error ("`sizeof' applied to a signature type");
1317 return size_int (0);
1318 }
1319
1320 if (TYPE_SIZE (complete_type (type)) == 0)
1321 {
1322 cp_error ("`sizeof' applied to incomplete type `%T'", type);
1323 return size_int (0);
1324 }
1325
1326 /* Convert in case a char is more than one unit. */
1327 t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type),
1328 size_int (TYPE_PRECISION (char_type_node)));
1329 /* size_binop does not put the constant in range, so do it now. */
1330 if (TREE_CODE (t) == INTEGER_CST && force_fit_type (t, 0))
1331 TREE_CONSTANT_OVERFLOW (t) = TREE_OVERFLOW (t) = 1;
1332 return t;
1333 }
1334
1335 tree
1336 expr_sizeof (e)
1337 tree e;
1338 {
1339 if (current_template_parms)
1340 return build_min (SIZEOF_EXPR, sizetype, e);
1341
1342 if (TREE_CODE (e) == COMPONENT_REF
1343 && DECL_BIT_FIELD (TREE_OPERAND (e, 1)))
1344 error ("sizeof applied to a bit-field");
1345 /* ANSI says arrays and functions are converted inside comma.
1346 But we can't really convert them in build_compound_expr
1347 because that would break commas in lvalues.
1348 So do the conversion here if operand was a comma. */
1349 if (TREE_CODE (e) == COMPOUND_EXPR
1350 && (TREE_CODE (TREE_TYPE (e)) == ARRAY_TYPE
1351 || TREE_CODE (TREE_TYPE (e)) == FUNCTION_TYPE))
1352 e = default_conversion (e);
1353 else if (TREE_CODE (e) == TREE_LIST)
1354 {
1355 tree t = TREE_VALUE (e);
1356 if (t != NULL_TREE
1357 && ((TREE_TYPE (t)
1358 && TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
1359 || is_overloaded_fn (t)))
1360 pedwarn ("ANSI C++ forbids taking the sizeof a function type");
1361 }
1362 return c_sizeof (TREE_TYPE (e));
1363 }
1364
1365 tree
1366 c_sizeof_nowarn (type)
1367 tree type;
1368 {
1369 enum tree_code code = TREE_CODE (type);
1370 tree t;
1371
1372 if (code == FUNCTION_TYPE
1373 || code == METHOD_TYPE
1374 || code == VOID_TYPE
1375 || code == ERROR_MARK)
1376 return size_int (1);
1377 if (code == REFERENCE_TYPE)
1378 type = TREE_TYPE (type);
1379
1380 if (TYPE_SIZE (type) == 0)
1381 return size_int (0);
1382
1383 /* Convert in case a char is more than one unit. */
1384 t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type),
1385 size_int (TYPE_PRECISION (char_type_node)));
1386 force_fit_type (t, 0);
1387 return t;
1388 }
1389
1390 /* Implement the __alignof keyword: Return the minimum required
1391 alignment of TYPE, measured in bytes. */
1392
1393 tree
1394 c_alignof (type)
1395 tree type;
1396 {
1397 enum tree_code code = TREE_CODE (type);
1398 tree t;
1399
1400 if (code == FUNCTION_TYPE || code == METHOD_TYPE)
1401 return size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1402
1403 if (code == VOID_TYPE || code == ERROR_MARK)
1404 return size_int (1);
1405
1406 /* C++: this is really correct! */
1407 if (code == REFERENCE_TYPE)
1408 type = TREE_TYPE (type);
1409
1410 /* @@ This also produces an error for a signature ref.
1411 In that case we should be able to do better. */
1412 if (IS_SIGNATURE (type))
1413 {
1414 error ("`__alignof' applied to a signature type");
1415 return size_int (1);
1416 }
1417
1418 t = size_int (TYPE_ALIGN (type) / BITS_PER_UNIT);
1419 force_fit_type (t, 0);
1420 return t;
1421 }
1422 \f
1423 /* Perform default promotions for C data used in expressions.
1424 Arrays and functions are converted to pointers;
1425 enumeral types or short or char, to int.
1426 In addition, manifest constants symbols are replaced by their values.
1427
1428 C++: this will automatically bash references to their target type. */
1429
1430 tree
1431 decay_conversion (exp)
1432 tree exp;
1433 {
1434 register tree type = TREE_TYPE (exp);
1435 register enum tree_code code = TREE_CODE (type);
1436
1437 if (code == OFFSET_TYPE)
1438 {
1439 if (TREE_CODE (exp) == OFFSET_REF)
1440 return decay_conversion (resolve_offset_ref (exp));
1441
1442 type = TREE_TYPE (type);
1443 code = TREE_CODE (type);
1444 }
1445
1446 if (code == REFERENCE_TYPE)
1447 {
1448 exp = convert_from_reference (exp);
1449 type = TREE_TYPE (exp);
1450 code = TREE_CODE (type);
1451 }
1452
1453 /* Constants can be used directly unless they're not loadable. */
1454 if (TREE_CODE (exp) == CONST_DECL)
1455 exp = DECL_INITIAL (exp);
1456 /* Replace a nonvolatile const static variable with its value. */
1457 else if (TREE_READONLY_DECL_P (exp))
1458 {
1459 exp = decl_constant_value (exp);
1460 type = TREE_TYPE (exp);
1461 }
1462
1463 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
1464 Leave such NOP_EXPRs, since RHS is being used in non-lvalue context. */
1465
1466 if (code == VOID_TYPE)
1467 {
1468 error ("void value not ignored as it ought to be");
1469 return error_mark_node;
1470 }
1471 if (code == FUNCTION_TYPE)
1472 {
1473 return build_unary_op (ADDR_EXPR, exp, 0);
1474 }
1475 if (code == METHOD_TYPE)
1476 {
1477 cp_pedwarn ("assuming & on `%E'", exp);
1478 return build_unary_op (ADDR_EXPR, exp, 0);
1479 }
1480 if (code == ARRAY_TYPE)
1481 {
1482 register tree adr;
1483 tree restype;
1484 tree ptrtype;
1485 int constp, volatilep;
1486
1487 if (TREE_CODE (exp) == INDIRECT_REF)
1488 {
1489 /* Stripping away the INDIRECT_REF is not the right
1490 thing to do for references... */
1491 tree inner = TREE_OPERAND (exp, 0);
1492 if (TREE_CODE (TREE_TYPE (inner)) == REFERENCE_TYPE)
1493 {
1494 inner = build1 (CONVERT_EXPR,
1495 build_pointer_type (TREE_TYPE (TREE_TYPE (inner))),
1496 inner);
1497 TREE_REFERENCE_EXPR (inner) = 1;
1498 }
1499 return convert (build_pointer_type (TREE_TYPE (type)), inner);
1500 }
1501
1502 if (TREE_CODE (exp) == COMPOUND_EXPR)
1503 {
1504 tree op1 = decay_conversion (TREE_OPERAND (exp, 1));
1505 return build (COMPOUND_EXPR, TREE_TYPE (op1),
1506 TREE_OPERAND (exp, 0), op1);
1507 }
1508
1509 if (!lvalue_p (exp)
1510 && ! (TREE_CODE (exp) == CONSTRUCTOR && TREE_STATIC (exp)))
1511 {
1512 error ("invalid use of non-lvalue array");
1513 return error_mark_node;
1514 }
1515
1516 constp = volatilep = 0;
1517 if (TREE_CODE_CLASS (TREE_CODE (exp)) == 'r'
1518 || TREE_CODE_CLASS (TREE_CODE (exp)) == 'd')
1519 {
1520 constp = TREE_READONLY (exp);
1521 volatilep = TREE_THIS_VOLATILE (exp);
1522 }
1523
1524 restype = TREE_TYPE (type);
1525 if (TYPE_READONLY (type) || TYPE_VOLATILE (type)
1526 || constp || volatilep)
1527 restype = cp_build_type_variant (restype,
1528 TYPE_READONLY (type) || constp,
1529 TYPE_VOLATILE (type) || volatilep);
1530 ptrtype = build_pointer_type (restype);
1531
1532 if (TREE_CODE (exp) == VAR_DECL)
1533 {
1534 /* ??? This is not really quite correct
1535 in that the type of the operand of ADDR_EXPR
1536 is not the target type of the type of the ADDR_EXPR itself.
1537 Question is, can this lossage be avoided? */
1538 adr = build1 (ADDR_EXPR, ptrtype, exp);
1539 if (mark_addressable (exp) == 0)
1540 return error_mark_node;
1541 TREE_CONSTANT (adr) = staticp (exp);
1542 TREE_SIDE_EFFECTS (adr) = 0; /* Default would be, same as EXP. */
1543 return adr;
1544 }
1545 /* This way is better for a COMPONENT_REF since it can
1546 simplify the offset for a component. */
1547 adr = build_unary_op (ADDR_EXPR, exp, 1);
1548 return convert (ptrtype, adr);
1549 }
1550
1551 return exp;
1552 }
1553
1554 tree
1555 default_conversion (exp)
1556 tree exp;
1557 {
1558 tree type;
1559 enum tree_code code;
1560
1561 exp = decay_conversion (exp);
1562
1563 type = TREE_TYPE (exp);
1564 code = TREE_CODE (type);
1565
1566 if (INTEGRAL_CODE_P (code))
1567 {
1568 tree t = type_promotes_to (type);
1569 if (t != type)
1570 return convert (t, exp);
1571 }
1572 if (flag_traditional
1573 && TYPE_MAIN_VARIANT (type) == float_type_node)
1574 return convert (double_type_node, exp);
1575
1576 return exp;
1577 }
1578
1579 /* Take the address of an inline function without setting TREE_ADDRESSABLE
1580 or TREE_USED. */
1581
1582 tree
1583 inline_conversion (exp)
1584 tree exp;
1585 {
1586 if (TREE_CODE (exp) == FUNCTION_DECL)
1587 {
1588 tree type = build_type_variant
1589 (TREE_TYPE (exp), TREE_READONLY (exp), TREE_THIS_VOLATILE (exp));
1590 exp = build1 (ADDR_EXPR, build_pointer_type (type), exp);
1591 }
1592 return exp;
1593 }
1594 \f
1595 tree
1596 build_object_ref (datum, basetype, field)
1597 tree datum, basetype, field;
1598 {
1599 tree dtype;
1600 if (datum == error_mark_node)
1601 return error_mark_node;
1602
1603 dtype = TREE_TYPE (datum);
1604 if (TREE_CODE (dtype) == REFERENCE_TYPE)
1605 dtype = TREE_TYPE (dtype);
1606 if (! IS_AGGR_TYPE_CODE (TREE_CODE (dtype)))
1607 {
1608 cp_error ("request for member `%T::%D' in expression of non-aggregate type `%T'",
1609 basetype, field, dtype);
1610 return error_mark_node;
1611 }
1612 else if (IS_SIGNATURE (basetype))
1613 {
1614 warning ("signature name in scope resolution ignored");
1615 return build_component_ref (datum, field, NULL_TREE, 1);
1616 }
1617 else if (is_aggr_type (basetype, 1))
1618 {
1619 tree binfo = binfo_or_else (basetype, dtype);
1620 if (binfo)
1621 return build_component_ref (build_scoped_ref (datum, basetype),
1622 field, binfo, 1);
1623 }
1624 return error_mark_node;
1625 }
1626
1627 /* Like `build_component_ref, but uses an already found field.
1628 Must compute access for current_class_ref. Otherwise, ok. */
1629
1630 tree
1631 build_component_ref_1 (datum, field, protect)
1632 tree datum, field;
1633 int protect;
1634 {
1635 register tree basetype = TREE_TYPE (datum);
1636 register enum tree_code code = TREE_CODE (basetype);
1637 register tree ref;
1638
1639 if (code == REFERENCE_TYPE)
1640 {
1641 datum = convert_from_reference (datum);
1642 basetype = TREE_TYPE (datum);
1643 code = TREE_CODE (basetype);
1644 }
1645
1646 if (! IS_AGGR_TYPE_CODE (code))
1647 {
1648 if (code != ERROR_MARK)
1649 cp_error ("request for member `%D' in `%E', which is of non-aggregate type `%T'",
1650 field, datum, basetype);
1651 return error_mark_node;
1652 }
1653
1654 if (TYPE_SIZE (basetype) == 0)
1655 {
1656 incomplete_type_error (0, basetype);
1657 return error_mark_node;
1658 }
1659
1660 /* Look up component name in the structure type definition. */
1661
1662 if (field == error_mark_node)
1663 my_friendly_abort (115);
1664
1665 if (TREE_STATIC (field))
1666 return field;
1667
1668 if (datum == current_class_ref)
1669 {
1670 tree access = compute_access (TYPE_BINFO (current_class_type), field);
1671
1672 if (access == access_private_node)
1673 {
1674 cp_error ("field `%D' is private", field);
1675 return error_mark_node;
1676 }
1677 else if (access == access_protected_node)
1678 {
1679 cp_error ("field `%D' is protected", field);
1680 return error_mark_node;
1681 }
1682 }
1683
1684 ref = build (COMPONENT_REF, TREE_TYPE (field), datum, field);
1685
1686 if (TREE_READONLY (datum) || TREE_READONLY (field))
1687 TREE_READONLY (ref) = 1;
1688 if (TREE_THIS_VOLATILE (datum) || TREE_THIS_VOLATILE (field))
1689 TREE_THIS_VOLATILE (ref) = 1;
1690 if (DECL_MUTABLE_P (field))
1691 TREE_READONLY (ref) = 0;
1692
1693 return ref;
1694 }
1695
1696 /* Given a COND_EXPR in T, return it in a form that we can, for
1697 example, use as an lvalue. This code used to be in unary_complex_lvalue,
1698 but we needed it to deal with `a = (d == c) ? b : c' expressions, where
1699 we're dealing with aggregates. So, we now call this in unary_complex_lvalue,
1700 and in build_modify_expr. The case (in particular) that led to this was
1701 with CODE == ADDR_EXPR, since it's not an lvalue when we'd get it there. */
1702
1703 static tree
1704 rationalize_conditional_expr (code, t)
1705 enum tree_code code;
1706 tree t;
1707 {
1708 return
1709 build_conditional_expr (TREE_OPERAND (t, 0),
1710 build_unary_op (code, TREE_OPERAND (t, 1), 0),
1711 build_unary_op (code, TREE_OPERAND (t, 2), 0));
1712 }
1713
1714 /* Given the TYPE of an anonymous union field inside T, return the
1715 FIELD_DECL for the field. If not found return NULL_TREE. Because
1716 anonymous unions can nest, we must also search all anonymous unions
1717 that are directly reachable. */
1718
1719 static tree
1720 lookup_anon_field (t, type)
1721 tree t, type;
1722 {
1723 tree field;
1724
1725 for (field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
1726 {
1727 if (TREE_STATIC (field))
1728 continue;
1729 if (TREE_CODE (field) != FIELD_DECL)
1730 continue;
1731
1732 /* If we find it directly, return the field. */
1733 if (DECL_NAME (field) == NULL_TREE
1734 && type == TREE_TYPE (field))
1735 {
1736 return field;
1737 }
1738
1739 /* Otherwise, it could be nested, search harder. */
1740 if (DECL_NAME (field) == NULL_TREE
1741 && TREE_CODE (TREE_TYPE (field)) == UNION_TYPE)
1742 {
1743 tree subfield = lookup_anon_field (TREE_TYPE (field), type);
1744 if (subfield)
1745 return subfield;
1746 }
1747 }
1748 return NULL_TREE;
1749 }
1750
1751 /* Build a COMPONENT_REF for a given DATUM, and it's member COMPONENT.
1752 COMPONENT can be an IDENTIFIER_NODE that is the name of the member
1753 that we are interested in, or it can be a FIELD_DECL. */
1754
1755 tree
1756 build_component_ref (datum, component, basetype_path, protect)
1757 tree datum, component, basetype_path;
1758 int protect;
1759 {
1760 register tree basetype = TREE_TYPE (datum);
1761 register enum tree_code code;
1762 register tree field = NULL;
1763 register tree ref;
1764
1765 if (current_template_parms)
1766 return build_min_nt (COMPONENT_REF, datum, component);
1767
1768 /* If DATUM is a COMPOUND_EXPR or COND_EXPR, move our reference
1769 inside it. */
1770 switch (TREE_CODE (datum))
1771 {
1772 case COMPOUND_EXPR:
1773 {
1774 tree value = build_component_ref (TREE_OPERAND (datum, 1), component,
1775 basetype_path, protect);
1776 return build (COMPOUND_EXPR, TREE_TYPE (value),
1777 TREE_OPERAND (datum, 0), value);
1778 }
1779 case COND_EXPR:
1780 return build_conditional_expr
1781 (TREE_OPERAND (datum, 0),
1782 build_component_ref (TREE_OPERAND (datum, 1), component,
1783 basetype_path, protect),
1784 build_component_ref (TREE_OPERAND (datum, 2), component,
1785 basetype_path, protect));
1786 }
1787
1788 code = TREE_CODE (basetype);
1789
1790 if (code == REFERENCE_TYPE)
1791 {
1792 datum = convert_from_reference (datum);
1793 basetype = TREE_TYPE (datum);
1794 code = TREE_CODE (basetype);
1795 }
1796 if (TREE_CODE (datum) == OFFSET_REF)
1797 {
1798 datum = resolve_offset_ref (datum);
1799 basetype = TREE_TYPE (datum);
1800 code = TREE_CODE (basetype);
1801 }
1802
1803 /* First, see if there is a field or component with name COMPONENT. */
1804 if (TREE_CODE (component) == TREE_LIST)
1805 {
1806 my_friendly_assert (!(TREE_CHAIN (component) == NULL_TREE
1807 && DECL_CHAIN (TREE_VALUE (component)) == NULL_TREE), 309);
1808 return build (COMPONENT_REF, TREE_TYPE (component), datum, component);
1809 }
1810
1811 if (! IS_AGGR_TYPE_CODE (code))
1812 {
1813 if (code != ERROR_MARK)
1814 cp_error ("request for member `%D' in `%E', which is of non-aggregate type `%T'",
1815 component, datum, basetype);
1816 return error_mark_node;
1817 }
1818
1819 if (TYPE_SIZE (complete_type (basetype)) == 0)
1820 {
1821 incomplete_type_error (0, basetype);
1822 return error_mark_node;
1823 }
1824
1825 if (TREE_CODE (component) == BIT_NOT_EXPR)
1826 {
1827 if (TYPE_IDENTIFIER (basetype) != TREE_OPERAND (component, 0))
1828 {
1829 cp_error ("destructor specifier `%T::~%T' must have matching names",
1830 basetype, TREE_OPERAND (component, 0));
1831 return error_mark_node;
1832 }
1833 if (! TYPE_HAS_DESTRUCTOR (basetype))
1834 {
1835 cp_error ("type `%T' has no destructor", basetype);
1836 return error_mark_node;
1837 }
1838 return TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (basetype), 1);
1839 }
1840
1841 /* Look up component name in the structure type definition. */
1842 if (CLASSTYPE_VFIELD (basetype)
1843 && DECL_NAME (CLASSTYPE_VFIELD (basetype)) == component)
1844 /* Special-case this because if we use normal lookups in an ambiguous
1845 hierarchy, the compiler will abort (because vptr lookups are
1846 not supposed to be ambiguous. */
1847 field = CLASSTYPE_VFIELD (basetype);
1848 else if (TREE_CODE (component) == FIELD_DECL)
1849 {
1850 field = component;
1851 }
1852 else
1853 {
1854 if (basetype_path == NULL_TREE)
1855 basetype_path = TYPE_BINFO (basetype);
1856 field = lookup_field (basetype_path, component,
1857 protect && ! VFIELD_NAME_P (component), 0);
1858 if (field == error_mark_node)
1859 return error_mark_node;
1860
1861 if (field == NULL_TREE)
1862 {
1863 /* Not found as a data field, look for it as a method. If found,
1864 then if this is the only possible one, return it, else
1865 report ambiguity error. */
1866 tree fndecls = lookup_fnfields (basetype_path, component, 1);
1867 if (fndecls == error_mark_node)
1868 return error_mark_node;
1869 if (fndecls)
1870 {
1871 if (TREE_CHAIN (fndecls) == NULL_TREE
1872 && DECL_CHAIN (TREE_VALUE (fndecls)) == NULL_TREE)
1873 {
1874 tree access, fndecl;
1875
1876 /* Unique, so use this one now. */
1877 basetype = TREE_PURPOSE (fndecls);
1878 fndecl = TREE_VALUE (fndecls);
1879 access = compute_access (TREE_PURPOSE (fndecls), fndecl);
1880 if (access == access_public_node)
1881 {
1882 if (DECL_VINDEX (fndecl)
1883 && ! resolves_to_fixed_type_p (datum, 0))
1884 {
1885 tree addr = build_unary_op (ADDR_EXPR, datum, 0);
1886 addr = convert_pointer_to (DECL_CONTEXT (fndecl), addr);
1887 datum = build_indirect_ref (addr, NULL_PTR);
1888 my_friendly_assert (datum != error_mark_node, 310);
1889 fndecl = build_vfn_ref (&addr, datum, DECL_VINDEX (fndecl));
1890 }
1891 mark_used (fndecl);
1892 return build (OFFSET_REF, TREE_TYPE (fndecl), datum, fndecl);
1893 }
1894 if (access == access_protected_node)
1895 cp_error ("member function `%D' is protected", fndecl);
1896 else
1897 cp_error ("member function `%D' is private", fndecl);
1898 return error_mark_node;
1899 }
1900 else
1901 {
1902 /* Just act like build_offset_ref, since the object does
1903 not matter unless we're actually calling the function. */
1904 tree t;
1905
1906 t = build_tree_list (error_mark_node, fndecls);
1907 TREE_TYPE (t) = build_offset_type (basetype,
1908 unknown_type_node);
1909 return t;
1910 }
1911 }
1912
1913 cp_error ("`%#T' has no member named `%D'", basetype, component);
1914 return error_mark_node;
1915 }
1916 else if (TREE_TYPE (field) == error_mark_node)
1917 return error_mark_node;
1918
1919 if (TREE_CODE (field) != FIELD_DECL)
1920 {
1921 if (TREE_CODE (field) == TYPE_DECL)
1922 {
1923 cp_error ("invalid use of type decl `%#D' as expression", field);
1924 return error_mark_node;
1925 }
1926 else if (DECL_RTL (field) != 0)
1927 mark_used (field);
1928 else
1929 TREE_USED (field) = 1;
1930 return field;
1931 }
1932 }
1933
1934 /* See if we have to do any conversions so that we pick up the field from the
1935 right context. */
1936 if (DECL_FIELD_CONTEXT (field) != basetype)
1937 {
1938 tree context = DECL_FIELD_CONTEXT (field);
1939 tree base = context;
1940 while (base != basetype && TYPE_NAME (base)
1941 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (base)))
1942 {
1943 base = TYPE_CONTEXT (base);
1944 }
1945
1946 /* Handle base classes here... */
1947 if (base != basetype && TYPE_USES_COMPLEX_INHERITANCE (basetype))
1948 {
1949 tree addr = build_unary_op (ADDR_EXPR, datum, 0);
1950 if (integer_zerop (addr))
1951 {
1952 error ("invalid reference to NULL ptr, use ptr-to-member instead");
1953 return error_mark_node;
1954 }
1955 if (VBASE_NAME_P (DECL_NAME (field)))
1956 {
1957 /* It doesn't matter which vbase pointer we grab, just
1958 find one of them. */
1959 tree binfo = get_binfo (base,
1960 TREE_TYPE (TREE_TYPE (addr)), 0);
1961 addr = convert_pointer_to_real (binfo, addr);
1962 }
1963 else
1964 addr = convert_pointer_to (base, addr);
1965 datum = build_indirect_ref (addr, NULL_PTR);
1966 my_friendly_assert (datum != error_mark_node, 311);
1967 }
1968 basetype = base;
1969
1970 /* Handle things from anon unions here... */
1971 if (TYPE_NAME (context) && ANON_AGGRNAME_P (TYPE_IDENTIFIER (context)))
1972 {
1973 tree subfield = lookup_anon_field (basetype, context);
1974 tree subdatum = build_component_ref (datum, subfield,
1975 basetype_path, protect);
1976 return build_component_ref (subdatum, field, basetype_path, protect);
1977 }
1978 }
1979
1980 ref = fold (build (COMPONENT_REF, TREE_TYPE (field),
1981 break_out_cleanups (datum), field));
1982
1983 if (TREE_READONLY (datum) || TREE_READONLY (field))
1984 TREE_READONLY (ref) = 1;
1985 if (TREE_THIS_VOLATILE (datum) || TREE_THIS_VOLATILE (field))
1986 TREE_THIS_VOLATILE (ref) = 1;
1987 if (DECL_MUTABLE_P (field))
1988 TREE_READONLY (ref) = 0;
1989
1990 return ref;
1991 }
1992 \f
1993 /* Given an expression PTR for a pointer, return an expression
1994 for the value pointed to.
1995 ERRORSTRING is the name of the operator to appear in error messages.
1996
1997 This function may need to overload OPERATOR_FNNAME.
1998 Must also handle REFERENCE_TYPEs for C++. */
1999
2000 tree
2001 build_x_indirect_ref (ptr, errorstring)
2002 tree ptr;
2003 char *errorstring;
2004 {
2005 tree rval;
2006
2007 if (current_template_parms)
2008 return build_min_nt (INDIRECT_REF, ptr);
2009
2010 rval = build_opfncall (INDIRECT_REF, LOOKUP_NORMAL, ptr, NULL_TREE, NULL_TREE);
2011 if (rval)
2012 return rval;
2013 return build_indirect_ref (ptr, errorstring);
2014 }
2015
2016 tree
2017 build_indirect_ref (ptr, errorstring)
2018 tree ptr;
2019 char *errorstring;
2020 {
2021 register tree pointer = (TREE_CODE (TREE_TYPE (ptr)) == REFERENCE_TYPE ?
2022 ptr : default_conversion (ptr));
2023 register tree type = TREE_TYPE (pointer);
2024
2025 if (ptr == current_class_ptr)
2026 return current_class_ref;
2027
2028 if (IS_AGGR_TYPE (type))
2029 {
2030 ptr = build_expr_type_conversion (WANT_POINTER, pointer, 1);
2031
2032 if (ptr)
2033 {
2034 pointer = ptr;
2035 type = TREE_TYPE (pointer);
2036 }
2037 }
2038
2039 if (TREE_CODE (type) == POINTER_TYPE || TREE_CODE (type) == REFERENCE_TYPE)
2040 {
2041 if (TREE_CODE (pointer) == ADDR_EXPR
2042 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (pointer, 0)))
2043 == TYPE_MAIN_VARIANT (TREE_TYPE (type)))
2044 && (TREE_READONLY (TREE_OPERAND (pointer, 0))
2045 == TYPE_READONLY (TREE_TYPE (type)))
2046 && (TREE_THIS_VOLATILE (TREE_OPERAND (pointer, 0))
2047 == TYPE_VOLATILE (TREE_TYPE (type))))
2048 return TREE_OPERAND (pointer, 0);
2049 else
2050 {
2051 tree t = TREE_TYPE (type);
2052 register tree ref = build1 (INDIRECT_REF,
2053 TYPE_MAIN_VARIANT (t), pointer);
2054
2055 TREE_READONLY (ref) = TYPE_READONLY (t);
2056 TREE_THIS_VOLATILE (ref) = TYPE_VOLATILE (t);
2057 TREE_SIDE_EFFECTS (ref)
2058 = TYPE_VOLATILE (t) || TREE_SIDE_EFFECTS (pointer);
2059 return ref;
2060 }
2061 }
2062 /* `pointer' won't be an error_mark_node if we were given a
2063 pointer to member, so it's cool to check for this here. */
2064 else if (TYPE_PTRMEMFUNC_P (type))
2065 error ("invalid use of `%s' on pointer to member function", errorstring);
2066 else if (TREE_CODE (type) == RECORD_TYPE
2067 && (IS_SIGNATURE_POINTER (type) || IS_SIGNATURE_REFERENCE (type)))
2068 error ("cannot dereference signature pointer/reference");
2069 else if (pointer != error_mark_node)
2070 {
2071 if (errorstring)
2072 error ("invalid type argument of `%s'", errorstring);
2073 else
2074 error ("invalid type argument");
2075 }
2076 return error_mark_node;
2077 }
2078
2079 /* This handles expressions of the form "a[i]", which denotes
2080 an array reference.
2081
2082 This is logically equivalent in C to *(a+i), but we may do it differently.
2083 If A is a variable or a member, we generate a primitive ARRAY_REF.
2084 This avoids forcing the array out of registers, and can work on
2085 arrays that are not lvalues (for example, members of structures returned
2086 by functions).
2087
2088 If INDEX is of some user-defined type, it must be converted to
2089 integer type. Otherwise, to make a compatible PLUS_EXPR, it
2090 will inherit the type of the array, which will be some pointer type. */
2091
2092 tree
2093 build_x_array_ref (array, idx)
2094 tree array, idx;
2095 {
2096 tree rval = build_opfncall (ARRAY_REF, LOOKUP_NORMAL, array, idx, NULL_TREE);
2097 if (rval)
2098 return rval;
2099 return build_array_ref (array, idx);
2100 }
2101
2102 tree
2103 build_array_ref (array, idx)
2104 tree array, idx;
2105 {
2106 if (idx == 0)
2107 {
2108 error ("subscript missing in array reference");
2109 return error_mark_node;
2110 }
2111
2112 if (TREE_TYPE (array) == error_mark_node
2113 || TREE_TYPE (idx) == error_mark_node)
2114 return error_mark_node;
2115
2116 if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE
2117 && TREE_CODE (array) != INDIRECT_REF)
2118 {
2119 tree rval, type;
2120
2121 /* Subscripting with type char is likely to lose
2122 on a machine where chars are signed.
2123 So warn on any machine, but optionally.
2124 Don't warn for unsigned char since that type is safe.
2125 Don't warn for signed char because anyone who uses that
2126 must have done so deliberately. */
2127 if (warn_char_subscripts
2128 && TYPE_MAIN_VARIANT (TREE_TYPE (idx)) == char_type_node)
2129 warning ("array subscript has type `char'");
2130
2131 /* Apply default promotions *after* noticing character types. */
2132 idx = default_conversion (idx);
2133
2134 if (TREE_CODE (TREE_TYPE (idx)) != INTEGER_TYPE)
2135 {
2136 error ("array subscript is not an integer");
2137 return error_mark_node;
2138 }
2139
2140 /* An array that is indexed by a non-constant
2141 cannot be stored in a register; we must be able to do
2142 address arithmetic on its address.
2143 Likewise an array of elements of variable size. */
2144 if (TREE_CODE (idx) != INTEGER_CST
2145 || (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array))) != 0
2146 && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array)))) != INTEGER_CST))
2147 {
2148 if (mark_addressable (array) == 0)
2149 return error_mark_node;
2150 }
2151 /* An array that is indexed by a constant value which is not within
2152 the array bounds cannot be stored in a register either; because we
2153 would get a crash in store_bit_field/extract_bit_field when trying
2154 to access a non-existent part of the register. */
2155 if (TREE_CODE (idx) == INTEGER_CST
2156 && TYPE_VALUES (TREE_TYPE (array))
2157 && ! int_fits_type_p (idx, TYPE_VALUES (TREE_TYPE (array))))
2158 {
2159 if (mark_addressable (array) == 0)
2160 return error_mark_node;
2161 }
2162
2163 if (pedantic && !lvalue_p (array))
2164 pedwarn ("ANSI C++ forbids subscripting non-lvalue array");
2165
2166 /* Note in C++ it is valid to subscript a `register' array, since
2167 it is valid to take the address of something with that
2168 storage specification. */
2169 if (extra_warnings)
2170 {
2171 tree foo = array;
2172 while (TREE_CODE (foo) == COMPONENT_REF)
2173 foo = TREE_OPERAND (foo, 0);
2174 if (TREE_CODE (foo) == VAR_DECL && DECL_REGISTER (foo))
2175 warning ("subscripting array declared `register'");
2176 }
2177
2178 type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (array)));
2179 rval = build (ARRAY_REF, type, array, idx);
2180 /* Array ref is const/volatile if the array elements are
2181 or if the array is.. */
2182 TREE_READONLY (rval)
2183 |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array)))
2184 | TREE_READONLY (array));
2185 TREE_SIDE_EFFECTS (rval)
2186 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
2187 | TREE_SIDE_EFFECTS (array));
2188 TREE_THIS_VOLATILE (rval)
2189 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
2190 /* This was added by rms on 16 Nov 91.
2191 It fixes vol struct foo *a; a->elts[1]
2192 in an inline function.
2193 Hope it doesn't break something else. */
2194 | TREE_THIS_VOLATILE (array));
2195 return require_complete_type (fold (rval));
2196 }
2197
2198 {
2199 tree ar = default_conversion (array);
2200 tree ind = default_conversion (idx);
2201
2202 /* Put the integer in IND to simplify error checking. */
2203 if (TREE_CODE (TREE_TYPE (ar)) == INTEGER_TYPE)
2204 {
2205 tree temp = ar;
2206 ar = ind;
2207 ind = temp;
2208 }
2209
2210 if (ar == error_mark_node)
2211 return ar;
2212
2213 if (TREE_CODE (TREE_TYPE (ar)) != POINTER_TYPE)
2214 {
2215 error ("subscripted value is neither array nor pointer");
2216 return error_mark_node;
2217 }
2218 if (TREE_CODE (TREE_TYPE (ind)) != INTEGER_TYPE)
2219 {
2220 error ("array subscript is not an integer");
2221 return error_mark_node;
2222 }
2223
2224 return build_indirect_ref (build_binary_op_nodefault (PLUS_EXPR, ar, ind, PLUS_EXPR),
2225 "array indexing");
2226 }
2227 }
2228 \f
2229 /* Build a function call to function FUNCTION with parameters PARAMS.
2230 PARAMS is a list--a chain of TREE_LIST nodes--in which the
2231 TREE_VALUE of each node is a parameter-expression. The PARAMS do
2232 not include any object pointer that may be required. FUNCTION's
2233 data type may be a function type or a pointer-to-function.
2234
2235 For C++: If FUNCTION's data type is a TREE_LIST, then the tree list
2236 is the list of possible methods that FUNCTION could conceivably
2237 be. If the list of methods comes from a class, then it will be
2238 a list of lists (where each element is associated with the class
2239 that produced it), otherwise it will be a simple list (for
2240 functions overloaded in global scope).
2241
2242 In the first case, TREE_VALUE (function) is the head of one of those
2243 lists, and TREE_PURPOSE is the name of the function.
2244
2245 In the second case, TREE_PURPOSE (function) is the function's
2246 name directly.
2247
2248 DECL is the class instance variable, usually CURRENT_CLASS_REF.
2249
2250 When calling a TEMPLATE_DECL, we don't require a complete return
2251 type. */
2252
2253 tree
2254 build_x_function_call (function, params, decl)
2255 tree function, params, decl;
2256 {
2257 tree type;
2258 int is_method;
2259
2260 if (function == error_mark_node)
2261 return error_mark_node;
2262
2263 if (current_template_parms)
2264 return build_min_nt (CALL_EXPR, function, params, NULL_TREE);
2265
2266 type = TREE_TYPE (function);
2267
2268 if (TREE_CODE (type) == OFFSET_TYPE
2269 && TREE_TYPE (type) == unknown_type_node
2270 && TREE_CODE (function) == TREE_LIST
2271 && TREE_CHAIN (function) == NULL_TREE)
2272 {
2273 /* Undo (Foo:bar)()... */
2274 type = TYPE_OFFSET_BASETYPE (type);
2275 function = TREE_VALUE (function);
2276 my_friendly_assert (TREE_CODE (function) == TREE_LIST, 999);
2277 my_friendly_assert (TREE_CHAIN (function) == NULL_TREE, 999);
2278 function = TREE_VALUE (function);
2279 my_friendly_assert (TREE_CODE (function) == FUNCTION_DECL, 999);
2280 function = DECL_NAME (function);
2281 return build_method_call (decl, function, params, TYPE_BINFO (type), LOOKUP_NORMAL);
2282 }
2283
2284 is_method = ((TREE_CODE (function) == TREE_LIST
2285 && current_class_type != NULL_TREE
2286 && IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (function)) == function)
2287 || TREE_CODE (function) == IDENTIFIER_NODE
2288 || TREE_CODE (type) == METHOD_TYPE
2289 || TYPE_PTRMEMFUNC_P (type));
2290
2291 if (TREE_CODE (function) == FUNCTION_DECL
2292 && DECL_STATIC_FUNCTION_P (function))
2293 return build_member_call
2294 (DECL_CONTEXT (function), DECL_NAME (function), params);
2295
2296 /* Handle methods, friends, and overloaded functions, respectively. */
2297 if (is_method)
2298 {
2299 if (TREE_CODE (function) == FUNCTION_DECL)
2300 {
2301 if (DECL_NAME (function))
2302 function = DECL_NAME (function);
2303 else
2304 function = TYPE_IDENTIFIER (DECL_CLASS_CONTEXT (function));
2305 }
2306 else if (TREE_CODE (function) == TREE_LIST)
2307 {
2308 my_friendly_assert (TREE_CODE (TREE_VALUE (function)) == FUNCTION_DECL, 312);
2309 function = TREE_PURPOSE (function);
2310 }
2311 else if (TREE_CODE (function) != IDENTIFIER_NODE)
2312 {
2313 if (TREE_CODE (function) == OFFSET_REF)
2314 {
2315 if (TREE_OPERAND (function, 0))
2316 decl = TREE_OPERAND (function, 0);
2317 }
2318 /* Call via a pointer to member function. */
2319 if (decl == NULL_TREE)
2320 {
2321 error ("pointer to member function called, but not in class scope");
2322 return error_mark_node;
2323 }
2324 /* What other type of POINTER_TYPE could this be? */
2325 if (TREE_CODE (TREE_TYPE (function)) != POINTER_TYPE
2326 && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (function))
2327 && TREE_CODE (function) != OFFSET_REF)
2328 function = build (OFFSET_REF, TREE_TYPE (type), NULL_TREE, function);
2329 goto do_x_function;
2330 }
2331
2332 /* this is an abbreviated method call.
2333 must go through here in case it is a virtual function.
2334 @@ Perhaps this could be optimized. */
2335
2336 if (decl == NULL_TREE)
2337 {
2338 if (current_class_type == NULL_TREE)
2339 {
2340 error ("object missing in call to method `%s'",
2341 IDENTIFIER_POINTER (function));
2342 return error_mark_node;
2343 }
2344 /* Yow: call from a static member function. */
2345 decl = build1 (NOP_EXPR, build_pointer_type (current_class_type),
2346 error_mark_node);
2347 decl = build_indirect_ref (decl, NULL_PTR);
2348 }
2349
2350 return build_method_call (decl, function, params,
2351 NULL_TREE, LOOKUP_NORMAL);
2352 }
2353 else if (TREE_CODE (function) == COMPONENT_REF
2354 && type == unknown_type_node)
2355 {
2356 /* Should we undo what was done in build_component_ref? */
2357 if (TREE_CODE (TREE_PURPOSE (TREE_OPERAND (function, 1))) == TREE_VEC)
2358 /* Get the name that build_component_ref hid. */
2359 function = DECL_NAME (TREE_VALUE (TREE_OPERAND (function, 1)));
2360 else
2361 function = TREE_PURPOSE (TREE_OPERAND (function, 1));
2362 return build_method_call (decl, function, params,
2363 NULL_TREE, LOOKUP_NORMAL);
2364 }
2365 else if (TREE_CODE (function) == TREE_LIST)
2366 {
2367 if (TREE_VALUE (function) == NULL_TREE)
2368 {
2369 cp_error ("function `%D' declared overloaded, but no definitions appear with which to resolve it?!?",
2370 TREE_PURPOSE (function));
2371 return error_mark_node;
2372 }
2373 else
2374 {
2375 #ifdef NEW_OVER
2376 return build_new_function_call (function, params, NULL_TREE);
2377 #else
2378 tree val = TREE_VALUE (function);
2379
2380 if (TREE_CODE (val) == TEMPLATE_DECL)
2381 return build_overload_call_real
2382 (function, params, LOOKUP_COMPLAIN, (struct candidate *)0, 0);
2383 else if (DECL_CHAIN (val) != NULL_TREE)
2384 return build_overload_call
2385 (function, params, LOOKUP_COMPLAIN);
2386 else
2387 my_friendly_abort (360);
2388 #endif
2389 }
2390 }
2391
2392 do_x_function:
2393 if (TREE_CODE (function) == OFFSET_REF)
2394 {
2395 /* If the component is a data element (or a virtual function), we play
2396 games here to make things work. */
2397 tree decl_addr;
2398
2399 if (TREE_OPERAND (function, 0))
2400 decl = TREE_OPERAND (function, 0);
2401 else
2402 decl = current_class_ref;
2403
2404 decl_addr = build_unary_op (ADDR_EXPR, decl, 0);
2405 function = get_member_function_from_ptrfunc (&decl_addr,
2406 TREE_OPERAND (function, 1));
2407 params = tree_cons (NULL_TREE, decl_addr, params);
2408 return build_function_call (function, params);
2409 }
2410
2411 type = TREE_TYPE (function);
2412 if (type != error_mark_node)
2413 {
2414 if (TREE_CODE (type) == REFERENCE_TYPE)
2415 type = TREE_TYPE (type);
2416
2417 if (TYPE_LANG_SPECIFIC (type)
2418 && TYPE_OVERLOADS_CALL_EXPR (complete_type (type)))
2419 return build_opfncall (CALL_EXPR, LOOKUP_NORMAL, function, params, NULL_TREE);
2420 }
2421
2422 if (is_method)
2423 {
2424 tree fntype = TREE_TYPE (function);
2425 tree ctypeptr;
2426
2427 /* Explicitly named method? */
2428 if (TREE_CODE (function) == FUNCTION_DECL)
2429 ctypeptr = build_pointer_type (DECL_CLASS_CONTEXT (function));
2430 /* Expression with ptr-to-method type? It could either be a plain
2431 usage, or it might be a case where the ptr-to-method is being
2432 passed in as an argument. */
2433 else if (TYPE_PTRMEMFUNC_P (fntype))
2434 {
2435 tree rec = TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (fntype)));
2436 ctypeptr = build_pointer_type (rec);
2437 }
2438 /* Unexpected node type? */
2439 else
2440 my_friendly_abort (116);
2441 if (decl == NULL_TREE)
2442 {
2443 if (current_function_decl
2444 && DECL_STATIC_FUNCTION_P (current_function_decl))
2445 error ("invalid call to member function needing `this' in static member function scope");
2446 else
2447 error ("pointer to member function called, but not in class scope");
2448 return error_mark_node;
2449 }
2450 if (TREE_CODE (TREE_TYPE (decl)) != POINTER_TYPE
2451 && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (decl)))
2452 {
2453 decl = build_unary_op (ADDR_EXPR, decl, 0);
2454 decl = convert_pointer_to (TREE_TYPE (ctypeptr), decl);
2455 }
2456 else
2457 decl = build_c_cast (ctypeptr, decl, 0);
2458 params = tree_cons (NULL_TREE, decl, params);
2459 }
2460
2461 return build_function_call (function, params);
2462 }
2463
2464 /* Resolve a pointer to member function. INSTANCE is the object
2465 instance to use, if the member points to a virtual member. */
2466
2467 tree
2468 get_member_function_from_ptrfunc (instance_ptrptr, function)
2469 tree *instance_ptrptr;
2470 tree function;
2471 {
2472 if (TREE_CODE (function) == OFFSET_REF)
2473 {
2474 function = TREE_OPERAND (function, 1);
2475 }
2476
2477 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (function)))
2478 {
2479 tree fntype, idx, e1, delta, delta2, e2, e3, aref, vtbl;
2480 tree instance;
2481
2482 tree instance_ptr = *instance_ptrptr;
2483
2484 if (TREE_SIDE_EFFECTS (instance_ptr))
2485 instance_ptr = save_expr (instance_ptr);
2486
2487 if (TREE_SIDE_EFFECTS (function))
2488 function = save_expr (function);
2489
2490 fntype = TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (function));
2491 idx = save_expr (build_component_ref (function,
2492 index_identifier,
2493 NULL_TREE, 0));
2494 e1 = build (GT_EXPR, boolean_type_node, idx,
2495 convert (delta_type_node, integer_zero_node));
2496 delta = convert (ptrdiff_type_node,
2497 build_component_ref (function, delta_identifier, NULL_TREE, 0));
2498 delta2 = DELTA2_FROM_PTRMEMFUNC (function);
2499
2500 /* convert down to the right base, before using the instance. */
2501 instance
2502 = convert_pointer_to_real (TYPE_METHOD_BASETYPE (TREE_TYPE (fntype)),
2503 instance_ptr);
2504 if (instance == error_mark_node)
2505 return instance;
2506
2507 vtbl = convert_pointer_to (ptr_type_node, instance);
2508 vtbl
2509 = build (PLUS_EXPR,
2510 build_pointer_type (build_pointer_type (vtable_entry_type)),
2511 vtbl, convert (ptrdiff_type_node, delta2));
2512 vtbl = build_indirect_ref (vtbl, NULL_PTR);
2513 aref = build_array_ref (vtbl, build_binary_op (MINUS_EXPR,
2514 idx,
2515 integer_one_node, 1));
2516 if (! flag_vtable_thunks)
2517 {
2518 aref = save_expr (aref);
2519
2520 delta = build_binary_op (PLUS_EXPR,
2521 build_conditional_expr (e1, build_component_ref (aref, delta_identifier, NULL_TREE, 0), integer_zero_node),
2522 delta, 1);
2523 }
2524
2525 *instance_ptrptr = build (PLUS_EXPR, TREE_TYPE (instance_ptr),
2526 instance_ptr, delta);
2527 if (flag_vtable_thunks)
2528 e2 = aref;
2529 else
2530 e2 = build_component_ref (aref, pfn_identifier, NULL_TREE, 0);
2531
2532 e3 = PFN_FROM_PTRMEMFUNC (function);
2533 TREE_TYPE (e2) = TREE_TYPE (e3);
2534 function = build_conditional_expr (e1, e2, e3);
2535
2536 /* Make sure this doesn't get evaluated first inside one of the
2537 branches of the COND_EXPR. */
2538 if (TREE_CODE (instance_ptr) == SAVE_EXPR)
2539 function = build (COMPOUND_EXPR, TREE_TYPE (function),
2540 instance_ptr, function);
2541 }
2542 return function;
2543 }
2544
2545 tree
2546 build_function_call_real (function, params, require_complete, flags)
2547 tree function, params;
2548 int require_complete, flags;
2549 {
2550 register tree fntype, fndecl;
2551 register tree value_type;
2552 register tree coerced_params;
2553 tree name = NULL_TREE, assembler_name = NULL_TREE;
2554 int is_method;
2555
2556 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
2557 Strip such NOP_EXPRs, since FUNCTION is used in non-lvalue context. */
2558 if (TREE_CODE (function) == NOP_EXPR
2559 && TREE_TYPE (function) == TREE_TYPE (TREE_OPERAND (function, 0)))
2560 function = TREE_OPERAND (function, 0);
2561
2562 if (TREE_CODE (function) == FUNCTION_DECL)
2563 {
2564 name = DECL_NAME (function);
2565 assembler_name = DECL_ASSEMBLER_NAME (function);
2566
2567 GNU_xref_call (current_function_decl,
2568 IDENTIFIER_POINTER (name ? name
2569 : TYPE_IDENTIFIER (DECL_CLASS_CONTEXT (function))));
2570 mark_used (function);
2571 fndecl = function;
2572
2573 /* Convert anything with function type to a pointer-to-function. */
2574 if (pedantic
2575 && name
2576 && IDENTIFIER_LENGTH (name) == 4
2577 && ! strcmp (IDENTIFIER_POINTER (name), "main")
2578 && DECL_CONTEXT (function) == NULL_TREE)
2579 {
2580 pedwarn ("ANSI C++ forbids calling `main' from within program");
2581 }
2582
2583 if (pedantic && DECL_THIS_INLINE (function) && ! DECL_INITIAL (function)
2584 && ! DECL_ARTIFICIAL (function)
2585 && ! DECL_PENDING_INLINE_INFO (function))
2586 cp_pedwarn ("inline function `%#D' called before definition",
2587 function);
2588
2589 /* Differs from default_conversion by not setting TREE_ADDRESSABLE
2590 (because calling an inline function does not mean the function
2591 needs to be separately compiled). */
2592
2593 if (DECL_INLINE (function))
2594 {
2595 /* Is it a synthesized method that needs to be synthesized? */
2596 if (DECL_ARTIFICIAL (function) && ! DECL_INITIAL (function)
2597 /* Kludge: don't synthesize for default args. */
2598 && current_function_decl)
2599 synthesize_method (function);
2600
2601 function = inline_conversion (function);
2602 }
2603 else
2604 function = build_addr_func (function);
2605 }
2606 else
2607 {
2608 fndecl = NULL_TREE;
2609
2610 function = build_addr_func (function);
2611 }
2612
2613 if (function == error_mark_node)
2614 return error_mark_node;
2615
2616 fntype = TREE_TYPE (function);
2617
2618 if (TYPE_PTRMEMFUNC_P (fntype))
2619 {
2620 cp_error ("must use .* or ->* to call pointer-to-member function in `%E (...)'",
2621 function);
2622 return error_mark_node;
2623 }
2624
2625 is_method = (TREE_CODE (fntype) == POINTER_TYPE
2626 && TREE_CODE (TREE_TYPE (fntype)) == METHOD_TYPE);
2627
2628 if (!((TREE_CODE (fntype) == POINTER_TYPE
2629 && TREE_CODE (TREE_TYPE (fntype)) == FUNCTION_TYPE)
2630 || is_method))
2631 {
2632 cp_error ("`%E' cannot be used as a function", function);
2633 return error_mark_node;
2634 }
2635
2636 /* fntype now gets the type of function pointed to. */
2637 fntype = TREE_TYPE (fntype);
2638
2639 /* Convert the parameters to the types declared in the
2640 function prototype, or apply default promotions. */
2641
2642 if (flags & LOOKUP_COMPLAIN)
2643 coerced_params = convert_arguments (NULL_TREE, TYPE_ARG_TYPES (fntype),
2644 params, fndecl, LOOKUP_NORMAL);
2645 else
2646 coerced_params = convert_arguments (NULL_TREE, TYPE_ARG_TYPES (fntype),
2647 params, fndecl, 0);
2648
2649 if (coerced_params == error_mark_node)
2650 if (flags & LOOKUP_SPECULATIVELY)
2651 return NULL_TREE;
2652 else
2653 return error_mark_node;
2654
2655 /* Check for errors in format strings. */
2656
2657 if (warn_format && (name || assembler_name))
2658 check_function_format (name, assembler_name, coerced_params);
2659
2660 /* Recognize certain built-in functions so we can make tree-codes
2661 other than CALL_EXPR. We do this when it enables fold-const.c
2662 to do something useful. */
2663
2664 if (TREE_CODE (function) == ADDR_EXPR
2665 && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL
2666 && DECL_BUILT_IN (TREE_OPERAND (function, 0)))
2667 switch (DECL_FUNCTION_CODE (TREE_OPERAND (function, 0)))
2668 {
2669 case BUILT_IN_ABS:
2670 case BUILT_IN_LABS:
2671 case BUILT_IN_FABS:
2672 if (coerced_params == 0)
2673 return integer_zero_node;
2674 return build_unary_op (ABS_EXPR, TREE_VALUE (coerced_params), 0);
2675 }
2676
2677 /* C++ */
2678 value_type = TREE_TYPE (fntype) ? TREE_TYPE (fntype) : void_type_node;
2679 {
2680 register tree result
2681 = build_call (function, value_type, coerced_params);
2682
2683 if (require_complete)
2684 {
2685 if (value_type == void_type_node)
2686 return result;
2687 result = require_complete_type (result);
2688 }
2689 return convert_from_reference (result);
2690 }
2691 }
2692
2693 tree
2694 build_function_call (function, params)
2695 tree function, params;
2696 {
2697 return build_function_call_real (function, params, 1, LOOKUP_NORMAL);
2698 }
2699 \f
2700 /* Convert the actual parameter expressions in the list VALUES
2701 to the types in the list TYPELIST.
2702 If parmdecls is exhausted, or when an element has NULL as its type,
2703 perform the default conversions.
2704
2705 RETURN_LOC is the location of the return value, if known, NULL_TREE
2706 otherwise. This is useful in the case where we can avoid creating
2707 a temporary variable in the case where we can initialize the return
2708 value directly. If we are not eliding constructors, then we set this
2709 to NULL_TREE to avoid this avoidance.
2710
2711 NAME is an IDENTIFIER_NODE or 0. It is used only for error messages.
2712
2713 This is also where warnings about wrong number of args are generated.
2714
2715 Return a list of expressions for the parameters as converted.
2716
2717 Both VALUES and the returned value are chains of TREE_LIST nodes
2718 with the elements of the list in the TREE_VALUE slots of those nodes.
2719
2720 In C++, unspecified trailing parameters can be filled in with their
2721 default arguments, if such were specified. Do so here. */
2722
2723 tree
2724 convert_arguments (return_loc, typelist, values, fndecl, flags)
2725 tree return_loc, typelist, values, fndecl;
2726 int flags;
2727 {
2728 register tree typetail, valtail;
2729 register tree result = NULL_TREE;
2730 char *called_thing;
2731 int i = 0;
2732
2733 if (! flag_elide_constructors)
2734 return_loc = 0;
2735
2736 if (fndecl)
2737 {
2738 if (TREE_CODE (TREE_TYPE (fndecl)) == METHOD_TYPE)
2739 {
2740 if (DECL_NAME (fndecl) == NULL_TREE
2741 || IDENTIFIER_HAS_TYPE_VALUE (DECL_NAME (fndecl)))
2742 called_thing = "constructor";
2743 else
2744 called_thing = "member function";
2745 }
2746 else
2747 called_thing = "function";
2748 }
2749
2750 for (valtail = values, typetail = typelist;
2751 valtail;
2752 valtail = TREE_CHAIN (valtail), i++)
2753 {
2754 register tree type = typetail ? TREE_VALUE (typetail) : 0;
2755 register tree val = TREE_VALUE (valtail);
2756
2757 if (val == error_mark_node)
2758 return error_mark_node;
2759
2760 if (type == void_type_node)
2761 {
2762 if (fndecl)
2763 {
2764 cp_error_at ("too many arguments to %s `%+D'", called_thing,
2765 fndecl);
2766 error ("at this point in file");
2767 }
2768 else
2769 error ("too many arguments to function");
2770 /* In case anybody wants to know if this argument
2771 list is valid. */
2772 if (result)
2773 TREE_TYPE (tree_last (result)) = error_mark_node;
2774 break;
2775 }
2776
2777 /* The tree type of the parameter being passed may not yet be
2778 known. In this case, its type is TYPE_UNKNOWN, and will
2779 be instantiated by the type given by TYPE. If TYPE
2780 is also NULL, the tree type of VAL is ERROR_MARK_NODE. */
2781 if (type && type_unknown_p (val))
2782 val = require_instantiated_type (type, val, integer_zero_node);
2783 else if (type_unknown_p (val))
2784 {
2785 /* Strip the `&' from an overloaded FUNCTION_DECL. */
2786 if (TREE_CODE (val) == ADDR_EXPR)
2787 val = TREE_OPERAND (val, 0);
2788 if (TREE_CODE (val) == TREE_LIST
2789 && TREE_CHAIN (val) == NULL_TREE
2790 && TREE_TYPE (TREE_VALUE (val)) != NULL_TREE
2791 && (TREE_TYPE (val) == unknown_type_node
2792 || DECL_CHAIN (TREE_VALUE (val)) == NULL_TREE))
2793 /* Instantiates automatically. */
2794 val = TREE_VALUE (val);
2795 else
2796 {
2797 error ("insufficient type information in parameter list");
2798 val = integer_zero_node;
2799 }
2800 }
2801 else if (TREE_CODE (val) == OFFSET_REF
2802 && TREE_CODE (TREE_TYPE (val)) == METHOD_TYPE)
2803 {
2804 /* This is unclean. Should be handled elsewhere. */
2805 val = build_unary_op (ADDR_EXPR, val, 0);
2806 }
2807 else if (TREE_CODE (val) == OFFSET_REF)
2808 val = resolve_offset_ref (val);
2809
2810 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
2811 Strip such NOP_EXPRs, since VAL is used in non-lvalue context. */
2812 if (TREE_CODE (val) == NOP_EXPR
2813 && TREE_TYPE (val) == TREE_TYPE (TREE_OPERAND (val, 0))
2814 && (type == 0 || TREE_CODE (type) != REFERENCE_TYPE))
2815 val = TREE_OPERAND (val, 0);
2816
2817 if (type == 0 || TREE_CODE (type) != REFERENCE_TYPE)
2818 {
2819 if (TREE_CODE (TREE_TYPE (val)) == ARRAY_TYPE
2820 || TREE_CODE (TREE_TYPE (val)) == FUNCTION_TYPE
2821 || TREE_CODE (TREE_TYPE (val)) == METHOD_TYPE)
2822 val = default_conversion (val);
2823
2824 val = require_complete_type (val);
2825 }
2826
2827 if (val == error_mark_node)
2828 return error_mark_node;
2829
2830 if (type != 0)
2831 {
2832 /* Formal parm type is specified by a function prototype. */
2833 tree parmval;
2834
2835 if (TYPE_SIZE (complete_type (type)) == 0)
2836 {
2837 error ("parameter type of called function is incomplete");
2838 parmval = val;
2839 }
2840 else
2841 {
2842 parmval = convert_for_initialization (return_loc, type, val,
2843 flags|INDIRECT_BIND,
2844 "argument passing", fndecl, i);
2845 #ifdef PROMOTE_PROTOTYPES
2846 if ((TREE_CODE (type) == INTEGER_TYPE
2847 || TREE_CODE (type) == ENUMERAL_TYPE)
2848 && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
2849 parmval = default_conversion (parmval);
2850 #endif
2851 }
2852
2853 if (parmval == error_mark_node)
2854 return error_mark_node;
2855
2856 result = tree_cons (NULL_TREE, parmval, result);
2857 }
2858 else
2859 {
2860 if (TREE_CODE (TREE_TYPE (val)) == REFERENCE_TYPE)
2861 val = convert_from_reference (val);
2862
2863 if (TREE_CODE (TREE_TYPE (val)) == REAL_TYPE
2864 && (TYPE_PRECISION (TREE_TYPE (val))
2865 < TYPE_PRECISION (double_type_node)))
2866 /* Convert `float' to `double'. */
2867 result = tree_cons (NULL_TREE, convert (double_type_node, val), result);
2868 else if (TYPE_LANG_SPECIFIC (TREE_TYPE (val))
2869 && ! TYPE_HAS_TRIVIAL_INIT_REF (TREE_TYPE (val)))
2870 {
2871 cp_warning ("cannot pass objects of type `%T' through `...'",
2872 TREE_TYPE (val));
2873 result = tree_cons (NULL_TREE, val, result);
2874 }
2875 else
2876 /* Convert `short' and `char' to full-size `int'. */
2877 result = tree_cons (NULL_TREE, default_conversion (val), result);
2878 }
2879
2880 if (typetail)
2881 typetail = TREE_CHAIN (typetail);
2882 }
2883
2884 if (typetail != 0 && typetail != void_list_node)
2885 {
2886 /* See if there are default arguments that can be used */
2887 if (TREE_PURPOSE (typetail))
2888 {
2889 for (; typetail != void_list_node; ++i)
2890 {
2891 tree type = TREE_VALUE (typetail);
2892 tree val = break_out_target_exprs (TREE_PURPOSE (typetail));
2893 tree parmval;
2894
2895 if (val == NULL_TREE)
2896 parmval = error_mark_node;
2897 else if (TREE_CODE (val) == CONSTRUCTOR)
2898 {
2899 parmval = digest_init (type, val, (tree *)0);
2900 parmval = convert_for_initialization (return_loc, type, parmval, flags,
2901 "default constructor", fndecl, i);
2902 }
2903 else
2904 {
2905 /* This could get clobbered by the following call. */
2906 if (TREE_HAS_CONSTRUCTOR (val))
2907 val = copy_node (val);
2908
2909 parmval = convert_for_initialization (return_loc, type, val, flags,
2910 "default argument", fndecl, i);
2911 #ifdef PROMOTE_PROTOTYPES
2912 if ((TREE_CODE (type) == INTEGER_TYPE
2913 || TREE_CODE (type) == ENUMERAL_TYPE)
2914 && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
2915 parmval = default_conversion (parmval);
2916 #endif
2917 }
2918
2919 if (parmval == error_mark_node)
2920 return error_mark_node;
2921
2922 result = tree_cons (0, parmval, result);
2923 typetail = TREE_CHAIN (typetail);
2924 /* ends with `...'. */
2925 if (typetail == NULL_TREE)
2926 break;
2927 }
2928 }
2929 else
2930 {
2931 if (fndecl)
2932 {
2933 char *buf = (char *)alloca (32 + strlen (called_thing));
2934 sprintf (buf, "too few arguments to %s `%%#D'", called_thing);
2935 cp_error_at (buf, fndecl);
2936 error ("at this point in file");
2937 }
2938 else
2939 error ("too few arguments to function");
2940 return error_mark_list;
2941 }
2942 }
2943
2944 return nreverse (result);
2945 }
2946 \f
2947 /* Build a binary-operation expression, after performing default
2948 conversions on the operands. CODE is the kind of expression to build. */
2949
2950 tree
2951 build_x_binary_op (code, arg1, arg2)
2952 enum tree_code code;
2953 tree arg1, arg2;
2954 {
2955 tree rval;
2956
2957 if (current_template_parms)
2958 return build_min_nt (code, arg1, arg2);
2959
2960 rval = build_opfncall (code, LOOKUP_SPECULATIVELY,
2961 arg1, arg2, NULL_TREE);
2962 if (rval)
2963 return build_opfncall (code, LOOKUP_NORMAL, arg1, arg2, NULL_TREE);
2964 if (code == MEMBER_REF)
2965 return build_m_component_ref (build_indirect_ref (arg1, NULL_PTR),
2966 arg2);
2967 return build_binary_op (code, arg1, arg2, 1);
2968 }
2969
2970 tree
2971 build_binary_op (code, arg1, arg2, convert_p)
2972 enum tree_code code;
2973 tree arg1, arg2;
2974 int convert_p;
2975 {
2976 tree args[2];
2977
2978 args[0] = arg1;
2979 args[1] = arg2;
2980
2981 if (convert_p)
2982 {
2983 tree type0, type1;
2984 args[0] = decay_conversion (args[0]);
2985 args[1] = decay_conversion (args[1]);
2986
2987 if (args[0] == error_mark_node || args[1] == error_mark_node)
2988 return error_mark_node;
2989
2990 type0 = TREE_TYPE (args[0]);
2991 type1 = TREE_TYPE (args[1]);
2992
2993 if (type_unknown_p (args[0]))
2994 {
2995 args[0] = instantiate_type (type1, args[0], 1);
2996 args[0] = decay_conversion (args[0]);
2997 }
2998 else if (type_unknown_p (args[1]))
2999 {
3000 args[1] = require_instantiated_type (type0, args[1],
3001 error_mark_node);
3002 args[1] = decay_conversion (args[1]);
3003 }
3004
3005 if (IS_AGGR_TYPE (type0) || IS_AGGR_TYPE (type1))
3006 {
3007 /* Try to convert this to something reasonable. */
3008 if (! build_default_binary_type_conversion(code, &args[0], &args[1]))
3009 {
3010 cp_error ("no match for `%O(%#T, %#T)'", code,
3011 TREE_TYPE (arg1), TREE_TYPE (arg2));
3012 return error_mark_node;
3013 }
3014 }
3015 }
3016 return build_binary_op_nodefault (code, args[0], args[1], code);
3017 }
3018
3019 /* Build a binary-operation expression without default conversions.
3020 CODE is the kind of expression to build.
3021 This function differs from `build' in several ways:
3022 the data type of the result is computed and recorded in it,
3023 warnings are generated if arg data types are invalid,
3024 special handling for addition and subtraction of pointers is known,
3025 and some optimization is done (operations on narrow ints
3026 are done in the narrower type when that gives the same result).
3027 Constant folding is also done before the result is returned.
3028
3029 ERROR_CODE is the code that determines what to say in error messages.
3030 It is usually, but not always, the same as CODE.
3031
3032 Note that the operands will never have enumeral types
3033 because either they have just had the default conversions performed
3034 or they have both just been converted to some other type in which
3035 the arithmetic is to be done.
3036
3037 C++: must do special pointer arithmetic when implementing
3038 multiple inheritance, and deal with pointer to member functions. */
3039
3040 tree
3041 build_binary_op_nodefault (code, orig_op0, orig_op1, error_code)
3042 enum tree_code code;
3043 tree orig_op0, orig_op1;
3044 enum tree_code error_code;
3045 {
3046 tree op0, op1;
3047 register enum tree_code code0, code1;
3048 tree type0, type1;
3049
3050 /* Expression code to give to the expression when it is built.
3051 Normally this is CODE, which is what the caller asked for,
3052 but in some special cases we change it. */
3053 register enum tree_code resultcode = code;
3054
3055 /* Data type in which the computation is to be performed.
3056 In the simplest cases this is the common type of the arguments. */
3057 register tree result_type = NULL;
3058
3059 /* Nonzero means operands have already been type-converted
3060 in whatever way is necessary.
3061 Zero means they need to be converted to RESULT_TYPE. */
3062 int converted = 0;
3063
3064 /* Nonzero means create the expression with this type, rather than
3065 RESULT_TYPE. */
3066 tree build_type = 0;
3067
3068 /* Nonzero means after finally constructing the expression
3069 convert it to this type. */
3070 tree final_type = 0;
3071
3072 /* Nonzero if this is an operation like MIN or MAX which can
3073 safely be computed in short if both args are promoted shorts.
3074 Also implies COMMON.
3075 -1 indicates a bitwise operation; this makes a difference
3076 in the exact conditions for when it is safe to do the operation
3077 in a narrower mode. */
3078 int shorten = 0;
3079
3080 /* Nonzero if this is a comparison operation;
3081 if both args are promoted shorts, compare the original shorts.
3082 Also implies COMMON. */
3083 int short_compare = 0;
3084
3085 /* Nonzero if this is a right-shift operation, which can be computed on the
3086 original short and then promoted if the operand is a promoted short. */
3087 int short_shift = 0;
3088
3089 /* Nonzero means set RESULT_TYPE to the common type of the args. */
3090 int common = 0;
3091
3092 /* Apply default conversions. */
3093 if (code == TRUTH_AND_EXPR || code == TRUTH_ANDIF_EXPR
3094 || code == TRUTH_OR_EXPR || code == TRUTH_ORIF_EXPR
3095 || code == TRUTH_XOR_EXPR)
3096 {
3097 op0 = decay_conversion (orig_op0);
3098 op1 = decay_conversion (orig_op1);
3099 }
3100 else
3101 {
3102 op0 = default_conversion (orig_op0);
3103 op1 = default_conversion (orig_op1);
3104 }
3105
3106 type0 = TREE_TYPE (op0);
3107 type1 = TREE_TYPE (op1);
3108
3109 /* The expression codes of the data types of the arguments tell us
3110 whether the arguments are integers, floating, pointers, etc. */
3111 code0 = TREE_CODE (type0);
3112 code1 = TREE_CODE (type1);
3113
3114 /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
3115 STRIP_TYPE_NOPS (op0);
3116 STRIP_TYPE_NOPS (op1);
3117
3118 /* If an error was already reported for one of the arguments,
3119 avoid reporting another error. */
3120
3121 if (code0 == ERROR_MARK || code1 == ERROR_MARK)
3122 return error_mark_node;
3123
3124 switch (code)
3125 {
3126 case PLUS_EXPR:
3127 /* Handle the pointer + int case. */
3128 if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
3129 return pointer_int_sum (PLUS_EXPR, op0, op1);
3130 else if (code1 == POINTER_TYPE && code0 == INTEGER_TYPE)
3131 return pointer_int_sum (PLUS_EXPR, op1, op0);
3132 else
3133 common = 1;
3134 break;
3135
3136 case MINUS_EXPR:
3137 /* Subtraction of two similar pointers.
3138 We must subtract them as integers, then divide by object size. */
3139 if (code0 == POINTER_TYPE && code1 == POINTER_TYPE
3140 && comp_target_types (type0, type1, 1))
3141 return pointer_diff (op0, op1);
3142 /* Handle pointer minus int. Just like pointer plus int. */
3143 else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
3144 return pointer_int_sum (MINUS_EXPR, op0, op1);
3145 else
3146 common = 1;
3147 break;
3148
3149 case MULT_EXPR:
3150 common = 1;
3151 break;
3152
3153 case TRUNC_DIV_EXPR:
3154 case CEIL_DIV_EXPR:
3155 case FLOOR_DIV_EXPR:
3156 case ROUND_DIV_EXPR:
3157 case EXACT_DIV_EXPR:
3158 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
3159 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
3160 {
3161 if (TREE_CODE (op1) == INTEGER_CST && integer_zerop (op1))
3162 cp_warning ("division by zero in `%E / 0'", op0);
3163 else if (TREE_CODE (op1) == REAL_CST && real_zerop (op1))
3164 cp_warning ("division by zero in `%E / 0.'", op0);
3165
3166 if (!(code0 == INTEGER_TYPE && code1 == INTEGER_TYPE))
3167 resultcode = RDIV_EXPR;
3168 else
3169 /* When dividing two signed integers, we have to promote to int.
3170 unless we divide by a constant != -1. Note that default
3171 conversion will have been performed on the operands at this
3172 point, so we have to dig out the original type to find out if
3173 it was unsigned. */
3174 shorten = ((TREE_CODE (op0) == NOP_EXPR
3175 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0, 0))))
3176 || (TREE_CODE (op1) == INTEGER_CST
3177 && (TREE_INT_CST_LOW (op1) != -1
3178 || TREE_INT_CST_HIGH (op1) != -1)));
3179 common = 1;
3180 }
3181 break;
3182
3183 case BIT_AND_EXPR:
3184 case BIT_ANDTC_EXPR:
3185 case BIT_IOR_EXPR:
3186 case BIT_XOR_EXPR:
3187 if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
3188 shorten = -1;
3189 /* If one operand is a constant, and the other is a short type
3190 that has been converted to an int,
3191 really do the work in the short type and then convert the
3192 result to int. If we are lucky, the constant will be 0 or 1
3193 in the short type, making the entire operation go away. */
3194 if (TREE_CODE (op0) == INTEGER_CST
3195 && TREE_CODE (op1) == NOP_EXPR
3196 && TYPE_PRECISION (type1) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op1, 0)))
3197 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op1, 0))))
3198 {
3199 final_type = result_type;
3200 op1 = TREE_OPERAND (op1, 0);
3201 result_type = TREE_TYPE (op1);
3202 }
3203 if (TREE_CODE (op1) == INTEGER_CST
3204 && TREE_CODE (op0) == NOP_EXPR
3205 && TYPE_PRECISION (type0) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0, 0)))
3206 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0, 0))))
3207 {
3208 final_type = result_type;
3209 op0 = TREE_OPERAND (op0, 0);
3210 result_type = TREE_TYPE (op0);
3211 }
3212 break;
3213
3214 case TRUNC_MOD_EXPR:
3215 case FLOOR_MOD_EXPR:
3216 if (code1 == INTEGER_TYPE && integer_zerop (op1))
3217 cp_warning ("division by zero in `%E % 0'", op0);
3218 else if (code1 == REAL_TYPE && real_zerop (op1))
3219 cp_warning ("division by zero in `%E % 0.'", op0);
3220
3221 if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
3222 {
3223 /* Although it would be tempting to shorten always here, that loses
3224 on some targets, since the modulo instruction is undefined if the
3225 quotient can't be represented in the computation mode. We shorten
3226 only if unsigned or if dividing by something we know != -1. */
3227 shorten = ((TREE_CODE (op0) == NOP_EXPR
3228 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0, 0))))
3229 || (TREE_CODE (op1) == INTEGER_CST
3230 && (TREE_INT_CST_LOW (op1) != -1
3231 || TREE_INT_CST_HIGH (op1) != -1)));
3232 common = 1;
3233 }
3234 break;
3235
3236 case TRUTH_ANDIF_EXPR:
3237 case TRUTH_ORIF_EXPR:
3238 case TRUTH_AND_EXPR:
3239 case TRUTH_OR_EXPR:
3240 result_type = boolean_type_node;
3241 break;
3242
3243 /* Shift operations: result has same type as first operand;
3244 always convert second operand to int.
3245 Also set SHORT_SHIFT if shifting rightward. */
3246
3247 case RSHIFT_EXPR:
3248 if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
3249 {
3250 result_type = type0;
3251 if (TREE_CODE (op1) == INTEGER_CST)
3252 {
3253 if (tree_int_cst_lt (op1, integer_zero_node))
3254 warning ("right shift count is negative");
3255 else
3256 {
3257 if (TREE_INT_CST_LOW (op1) | TREE_INT_CST_HIGH (op1))
3258 short_shift = 1;
3259 if (TREE_INT_CST_HIGH (op1) != 0
3260 || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1)
3261 >= TYPE_PRECISION (type0)))
3262 warning ("right shift count >= width of type");
3263 }
3264 }
3265 /* Convert the shift-count to an integer, regardless of
3266 size of value being shifted. */
3267 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
3268 op1 = convert (integer_type_node, op1);
3269 /* Avoid converting op1 to result_type later. */
3270 converted = 1;
3271 }
3272 break;
3273
3274 case LSHIFT_EXPR:
3275 if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
3276 {
3277 result_type = type0;
3278 if (TREE_CODE (op1) == INTEGER_CST)
3279 {
3280 if (tree_int_cst_lt (op1, integer_zero_node))
3281 warning ("left shift count is negative");
3282 else if (TREE_INT_CST_HIGH (op1) != 0
3283 || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1)
3284 >= TYPE_PRECISION (type0)))
3285 warning ("left shift count >= width of type");
3286 }
3287 /* Convert the shift-count to an integer, regardless of
3288 size of value being shifted. */
3289 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
3290 op1 = convert (integer_type_node, op1);
3291 /* Avoid converting op1 to result_type later. */
3292 converted = 1;
3293 }
3294 break;
3295
3296 case RROTATE_EXPR:
3297 case LROTATE_EXPR:
3298 if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
3299 {
3300 result_type = type0;
3301 if (TREE_CODE (op1) == INTEGER_CST)
3302 {
3303 if (tree_int_cst_lt (op1, integer_zero_node))
3304 warning ("%s rotate count is negative",
3305 (code == LROTATE_EXPR) ? "left" : "right");
3306 else if (TREE_INT_CST_HIGH (op1) != 0
3307 || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1)
3308 >= TYPE_PRECISION (type0)))
3309 warning ("%s rotate count >= width of type",
3310 (code == LROTATE_EXPR) ? "left" : "right");
3311 }
3312 /* Convert the shift-count to an integer, regardless of
3313 size of value being shifted. */
3314 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
3315 op1 = convert (integer_type_node, op1);
3316 }
3317 break;
3318
3319 case EQ_EXPR:
3320 case NE_EXPR:
3321 build_type = boolean_type_node;
3322 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
3323 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
3324 short_compare = 1;
3325 else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
3326 {
3327 register tree tt0 = TYPE_MAIN_VARIANT (TREE_TYPE (type0));
3328 register tree tt1 = TYPE_MAIN_VARIANT (TREE_TYPE (type1));
3329
3330 if (comp_target_types (type0, type1, 1))
3331 result_type = common_type (type0, type1);
3332 else if (tt0 == void_type_node)
3333 {
3334 if (pedantic && TREE_CODE (tt1) == FUNCTION_TYPE
3335 && tree_int_cst_lt (TYPE_SIZE (type0), TYPE_SIZE (type1)))
3336 pedwarn ("ANSI C++ forbids comparison of `void *' with function pointer");
3337 else if (TREE_CODE (tt1) == OFFSET_TYPE)
3338 pedwarn ("ANSI C++ forbids conversion of a pointer to member to `void *'");
3339 }
3340 else if (tt1 == void_type_node)
3341 {
3342 if (pedantic && TREE_CODE (tt0) == FUNCTION_TYPE
3343 && tree_int_cst_lt (TYPE_SIZE (type1), TYPE_SIZE (type0)))
3344 pedwarn ("ANSI C++ forbids comparison of `void *' with function pointer");
3345 }
3346 else
3347 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3348 type0, type1);
3349
3350 if (result_type == NULL_TREE)
3351 result_type = ptr_type_node;
3352 }
3353 else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST
3354 && integer_zerop (op1))
3355 result_type = type0;
3356 else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST
3357 && integer_zerop (op0))
3358 result_type = type1;
3359 else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
3360 {
3361 result_type = type0;
3362 error ("ANSI C++ forbids comparison between pointer and integer");
3363 }
3364 else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
3365 {
3366 result_type = type1;
3367 error ("ANSI C++ forbids comparison between pointer and integer");
3368 }
3369 else if (TYPE_PTRMEMFUNC_P (type0) && TREE_CODE (op1) == INTEGER_CST
3370 && integer_zerop (op1))
3371 {
3372 op0 = build_component_ref (op0, index_identifier, NULL_TREE, 0);
3373 op1 = integer_zero_node;
3374 result_type = TREE_TYPE (op0);
3375 }
3376 else if (TYPE_PTRMEMFUNC_P (type1) && TREE_CODE (op0) == INTEGER_CST
3377 && integer_zerop (op0))
3378 {
3379 op0 = build_component_ref (op1, index_identifier, NULL_TREE, 0);
3380 op1 = integer_zero_node;
3381 result_type = TREE_TYPE (op0);
3382 }
3383 else if (TYPE_PTRMEMFUNC_P (type0) && TYPE_PTRMEMFUNC_P (type1)
3384 && (TYPE_PTRMEMFUNC_FN_TYPE (type0)
3385 == TYPE_PTRMEMFUNC_FN_TYPE (type1)))
3386 {
3387 /* The code we generate for the test is:
3388
3389 (op0.index == op1.index
3390 && ((op1.index != -1 && op0.delta2 == op1.delta2)
3391 || op0.pfn == op1.pfn)) */
3392
3393 tree index0 = build_component_ref (op0, index_identifier, NULL_TREE, 0);
3394 tree index1 = save_expr (build_component_ref (op1, index_identifier, NULL_TREE, 0));
3395 tree pfn0 = PFN_FROM_PTRMEMFUNC (op0);
3396 tree pfn1 = PFN_FROM_PTRMEMFUNC (op1);
3397 tree delta20 = DELTA2_FROM_PTRMEMFUNC (op0);
3398 tree delta21 = DELTA2_FROM_PTRMEMFUNC (op1);
3399 tree e1, e2, e3;
3400 tree integer_neg_one_node
3401 = build_binary_op (MINUS_EXPR, integer_zero_node, integer_one_node, 1);
3402 e1 = build_binary_op (EQ_EXPR, index0, index1, 1);
3403 e2 = build_binary_op (NE_EXPR, index1, integer_neg_one_node, 1);
3404 e2 = build_binary_op (TRUTH_ANDIF_EXPR, e2, build_binary_op (EQ_EXPR, delta20, delta21, 1), 1);
3405 e3 = build_binary_op (EQ_EXPR, pfn0, pfn1, 1);
3406 e2 = build_binary_op (TRUTH_ORIF_EXPR, e2, e3, 1);
3407 e2 = build_binary_op (TRUTH_ANDIF_EXPR, e1, e2, 1);
3408 if (code == EQ_EXPR)
3409 return e2;
3410 return build_binary_op (EQ_EXPR, e2, integer_zero_node, 1);
3411 }
3412 else if (TYPE_PTRMEMFUNC_P (type0)
3413 && TYPE_PTRMEMFUNC_FN_TYPE (type0) == type1)
3414 {
3415 tree index0 = build_component_ref (op0, index_identifier, NULL_TREE, 0);
3416 tree index1;
3417 tree pfn0 = PFN_FROM_PTRMEMFUNC (op0);
3418 tree delta20 = DELTA2_FROM_PTRMEMFUNC (op0);
3419 tree delta21 = integer_zero_node;
3420 tree e1, e2, e3;
3421 tree integer_neg_one_node
3422 = build_binary_op (MINUS_EXPR, integer_zero_node, integer_one_node, 1);
3423 if (TREE_CODE (TREE_OPERAND (op1, 0)) == FUNCTION_DECL
3424 && DECL_VINDEX (TREE_OPERAND (op1, 0)))
3425 {
3426 /* Map everything down one to make room for the null pointer to member. */
3427 index1 = size_binop (PLUS_EXPR,
3428 DECL_VINDEX (TREE_OPERAND (op1, 0)),
3429 integer_one_node);
3430 op1 = integer_zero_node;
3431 delta21 = CLASSTYPE_VFIELD (TYPE_METHOD_BASETYPE (TREE_TYPE (type1)));
3432 delta21 = DECL_FIELD_BITPOS (delta21);
3433 delta21 = size_binop (FLOOR_DIV_EXPR, delta21, size_int (BITS_PER_UNIT));
3434 }
3435 else
3436 index1 = integer_neg_one_node;
3437 {
3438 tree nop1 = build1 (NOP_EXPR, TYPE_PTRMEMFUNC_FN_TYPE (type0), op1);
3439 TREE_CONSTANT (nop1) = TREE_CONSTANT (op1);
3440 op1 = nop1;
3441 }
3442 e1 = build_binary_op (EQ_EXPR, index0, index1, 1);
3443 e2 = build_binary_op (NE_EXPR, index1, integer_neg_one_node, 1);
3444 e2 = build_binary_op (TRUTH_ANDIF_EXPR, e2, build_binary_op (EQ_EXPR, delta20, delta21, 1), 1);
3445 e3 = build_binary_op (EQ_EXPR, pfn0, op1, 1);
3446 e2 = build_binary_op (TRUTH_ORIF_EXPR, e2, e3, 1);
3447 e2 = build_binary_op (TRUTH_ANDIF_EXPR, e1, e2, 1);
3448 if (code == EQ_EXPR)
3449 return e2;
3450 return build_binary_op (EQ_EXPR, e2, integer_zero_node, 1);
3451 }
3452 else if (TYPE_PTRMEMFUNC_P (type1)
3453 && TYPE_PTRMEMFUNC_FN_TYPE (type1) == type0)
3454 {
3455 return build_binary_op (code, op1, op0, 1);
3456 }
3457 break;
3458
3459 case MAX_EXPR:
3460 case MIN_EXPR:
3461 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
3462 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
3463 shorten = 1;
3464 else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
3465 {
3466 if (comp_target_types (type0, type1, 1))
3467 result_type = common_type (type0, type1);
3468 else
3469 {
3470 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3471 type0, type1);
3472 result_type = ptr_type_node;
3473 }
3474 }
3475 break;
3476
3477 case LE_EXPR:
3478 case GE_EXPR:
3479 case LT_EXPR:
3480 case GT_EXPR:
3481 build_type = boolean_type_node;
3482 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
3483 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
3484 short_compare = 1;
3485 else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
3486 {
3487 if (comp_target_types (type0, type1, 1))
3488 result_type = common_type (type0, type1);
3489 else
3490 {
3491 cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
3492 type0, type1);
3493 result_type = ptr_type_node;
3494 }
3495 }
3496 else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST
3497 && integer_zerop (op1))
3498 result_type = type0;
3499 else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST
3500 && integer_zerop (op0))
3501 result_type = type1;
3502 else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
3503 {
3504 result_type = type0;
3505 if (pedantic)
3506 pedwarn ("ANSI C++ forbids comparison between pointer and integer");
3507 else if (! flag_traditional)
3508 warning ("comparison between pointer and integer");
3509 }
3510 else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
3511 {
3512 result_type = type1;
3513 if (pedantic)
3514 pedwarn ("ANSI C++ forbids comparison between pointer and integer");
3515 else if (! flag_traditional)
3516 warning ("comparison between pointer and integer");
3517 }
3518 break;
3519 }
3520
3521 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
3522 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
3523 {
3524 if (shorten || common || short_compare)
3525 result_type = common_type (type0, type1);
3526
3527 /* For certain operations (which identify themselves by shorten != 0)
3528 if both args were extended from the same smaller type,
3529 do the arithmetic in that type and then extend.
3530
3531 shorten !=0 and !=1 indicates a bitwise operation.
3532 For them, this optimization is safe only if
3533 both args are zero-extended or both are sign-extended.
3534 Otherwise, we might change the result.
3535 Eg, (short)-1 | (unsigned short)-1 is (int)-1
3536 but calculated in (unsigned short) it would be (unsigned short)-1. */
3537
3538 if (shorten)
3539 {
3540 int unsigned0, unsigned1;
3541 tree arg0 = get_narrower (op0, &unsigned0);
3542 tree arg1 = get_narrower (op1, &unsigned1);
3543 /* UNS is 1 if the operation to be done is an unsigned one. */
3544 int uns = TREE_UNSIGNED (result_type);
3545 tree type;
3546
3547 final_type = result_type;
3548
3549 /* Handle the case that OP0 does not *contain* a conversion
3550 but it *requires* conversion to FINAL_TYPE. */
3551
3552 if (op0 == arg0 && TREE_TYPE (op0) != final_type)
3553 unsigned0 = TREE_UNSIGNED (TREE_TYPE (op0));
3554 if (op1 == arg1 && TREE_TYPE (op1) != final_type)
3555 unsigned1 = TREE_UNSIGNED (TREE_TYPE (op1));
3556
3557 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
3558
3559 /* For bitwise operations, signedness of nominal type
3560 does not matter. Consider only how operands were extended. */
3561 if (shorten == -1)
3562 uns = unsigned0;
3563
3564 /* Note that in all three cases below we refrain from optimizing
3565 an unsigned operation on sign-extended args.
3566 That would not be valid. */
3567
3568 /* Both args variable: if both extended in same way
3569 from same width, do it in that width.
3570 Do it unsigned if args were zero-extended. */
3571 if ((TYPE_PRECISION (TREE_TYPE (arg0))
3572 < TYPE_PRECISION (result_type))
3573 && (TYPE_PRECISION (TREE_TYPE (arg1))
3574 == TYPE_PRECISION (TREE_TYPE (arg0)))
3575 && unsigned0 == unsigned1
3576 && (unsigned0 || !uns))
3577 result_type
3578 = signed_or_unsigned_type (unsigned0,
3579 common_type (TREE_TYPE (arg0), TREE_TYPE (arg1)));
3580 else if (TREE_CODE (arg0) == INTEGER_CST
3581 && (unsigned1 || !uns)
3582 && (TYPE_PRECISION (TREE_TYPE (arg1))
3583 < TYPE_PRECISION (result_type))
3584 && (type = signed_or_unsigned_type (unsigned1,
3585 TREE_TYPE (arg1)),
3586 int_fits_type_p (arg0, type)))
3587 result_type = type;
3588 else if (TREE_CODE (arg1) == INTEGER_CST
3589 && (unsigned0 || !uns)
3590 && (TYPE_PRECISION (TREE_TYPE (arg0))
3591 < TYPE_PRECISION (result_type))
3592 && (type = signed_or_unsigned_type (unsigned0,
3593 TREE_TYPE (arg0)),
3594 int_fits_type_p (arg1, type)))
3595 result_type = type;
3596 }
3597
3598 /* Shifts can be shortened if shifting right. */
3599
3600 if (short_shift)
3601 {
3602 int unsigned_arg;
3603 tree arg0 = get_narrower (op0, &unsigned_arg);
3604
3605 final_type = result_type;
3606
3607 if (arg0 == op0 && final_type == TREE_TYPE (op0))
3608 unsigned_arg = TREE_UNSIGNED (TREE_TYPE (op0));
3609
3610 if (TYPE_PRECISION (TREE_TYPE (arg0)) < TYPE_PRECISION (result_type)
3611 /* We can shorten only if the shift count is less than the
3612 number of bits in the smaller type size. */
3613 && TREE_INT_CST_HIGH (op1) == 0
3614 && TYPE_PRECISION (TREE_TYPE (arg0)) > TREE_INT_CST_LOW (op1)
3615 /* If arg is sign-extended and then unsigned-shifted,
3616 we can simulate this with a signed shift in arg's type
3617 only if the extended result is at least twice as wide
3618 as the arg. Otherwise, the shift could use up all the
3619 ones made by sign-extension and bring in zeros.
3620 We can't optimize that case at all, but in most machines
3621 it never happens because available widths are 2**N. */
3622 && (!TREE_UNSIGNED (final_type)
3623 || unsigned_arg
3624 || (((unsigned) 2 * TYPE_PRECISION (TREE_TYPE (arg0)))
3625 <= TYPE_PRECISION (result_type))))
3626 {
3627 /* Do an unsigned shift if the operand was zero-extended. */
3628 result_type
3629 = signed_or_unsigned_type (unsigned_arg,
3630 TREE_TYPE (arg0));
3631 /* Convert value-to-be-shifted to that type. */
3632 if (TREE_TYPE (op0) != result_type)
3633 op0 = convert (result_type, op0);
3634 converted = 1;
3635 }
3636 }
3637
3638 /* Comparison operations are shortened too but differently.
3639 They identify themselves by setting short_compare = 1. */
3640
3641 if (short_compare)
3642 {
3643 /* Don't write &op0, etc., because that would prevent op0
3644 from being kept in a register.
3645 Instead, make copies of the our local variables and
3646 pass the copies by reference, then copy them back afterward. */
3647 tree xop0 = op0, xop1 = op1, xresult_type = result_type;
3648 enum tree_code xresultcode = resultcode;
3649 tree val
3650 = shorten_compare (&xop0, &xop1, &xresult_type, &xresultcode);
3651 if (val != 0)
3652 return convert (boolean_type_node, val);
3653 op0 = xop0, op1 = xop1;
3654 converted = 1;
3655 resultcode = xresultcode;
3656 }
3657
3658 if (short_compare && warn_sign_compare)
3659 {
3660 int op0_signed = ! TREE_UNSIGNED (TREE_TYPE (orig_op0));
3661 int op1_signed = ! TREE_UNSIGNED (TREE_TYPE (orig_op1));
3662
3663 int unsignedp0, unsignedp1;
3664 tree primop0 = get_narrower (op0, &unsignedp0);
3665 tree primop1 = get_narrower (op1, &unsignedp1);
3666
3667 /* Check for comparison of different enum types. */
3668 if (flag_int_enum_equivalence == 0
3669 && TREE_CODE (TREE_TYPE (orig_op0)) == ENUMERAL_TYPE
3670 && TREE_CODE (TREE_TYPE (orig_op1)) == ENUMERAL_TYPE
3671 && TYPE_MAIN_VARIANT (TREE_TYPE (orig_op0))
3672 != TYPE_MAIN_VARIANT (TREE_TYPE (orig_op1)))
3673 {
3674 cp_warning ("comparison between `%#T' and `%#T'",
3675 TREE_TYPE (orig_op0), TREE_TYPE (orig_op1));
3676 }
3677
3678 /* Give warnings for comparisons between signed and unsigned
3679 quantities that may fail. */
3680 /* Do the checking based on the original operand trees, so that
3681 casts will be considered, but default promotions won't be. */
3682
3683 /* Do not warn if the comparison is being done in a signed type,
3684 since the signed type will only be chosen if it can represent
3685 all the values of the unsigned type. */
3686 if (! TREE_UNSIGNED (result_type))
3687 /* OK */;
3688 /* Do not warn if both operands are unsigned. */
3689 else if (op0_signed == op1_signed)
3690 /* OK */;
3691 /* Do not warn if the signed quantity is an unsuffixed
3692 integer literal (or some static constant expression
3693 involving such literals) and it is non-negative. */
3694 else if ((op0_signed && TREE_CODE (orig_op0) == INTEGER_CST
3695 && tree_int_cst_sgn (orig_op0) >= 0)
3696 || (op1_signed && TREE_CODE (orig_op1) == INTEGER_CST
3697 && tree_int_cst_sgn (orig_op1) >= 0))
3698 /* OK */;
3699 /* Do not warn if the comparison is an equality operation,
3700 the unsigned quantity is an integral constant and it does
3701 not use the most significant bit of result_type. */
3702 else if ((resultcode == EQ_EXPR || resultcode == NE_EXPR)
3703 && ((op0_signed && TREE_CODE (orig_op1) == INTEGER_CST
3704 && int_fits_type_p (orig_op1, signed_type (result_type))
3705 || (op1_signed && TREE_CODE (orig_op0) == INTEGER_CST
3706 && int_fits_type_p (orig_op0, signed_type (result_type))))))
3707 /* OK */;
3708 else
3709 warning ("comparison between signed and unsigned");
3710
3711 /* Warn if two unsigned values are being compared in a size
3712 larger than their original size, and one (and only one) is the
3713 result of a `~' operator. This comparison will always fail.
3714
3715 Also warn if one operand is a constant, and the constant does not
3716 have all bits set that are set in the ~ operand when it is
3717 extended. */
3718
3719 if ((TREE_CODE (primop0) == BIT_NOT_EXPR)
3720 ^ (TREE_CODE (primop1) == BIT_NOT_EXPR))
3721 {
3722 if (TREE_CODE (primop0) == BIT_NOT_EXPR)
3723 primop0 = get_narrower (TREE_OPERAND (op0, 0), &unsignedp0);
3724 if (TREE_CODE (primop1) == BIT_NOT_EXPR)
3725 primop1 = get_narrower (TREE_OPERAND (op1, 0), &unsignedp1);
3726
3727 if (TREE_CODE (primop0) == INTEGER_CST
3728 || TREE_CODE (primop1) == INTEGER_CST)
3729 {
3730 tree primop;
3731 HOST_WIDE_INT constant, mask;
3732 int unsignedp;
3733 unsigned bits;
3734
3735 if (TREE_CODE (primop0) == INTEGER_CST)
3736 {
3737 primop = primop1;
3738 unsignedp = unsignedp1;
3739 constant = TREE_INT_CST_LOW (primop0);
3740 }
3741 else
3742 {
3743 primop = primop0;
3744 unsignedp = unsignedp0;
3745 constant = TREE_INT_CST_LOW (primop1);
3746 }
3747
3748 bits = TYPE_PRECISION (TREE_TYPE (primop));
3749 if (bits < TYPE_PRECISION (result_type)
3750 && bits < HOST_BITS_PER_LONG && unsignedp)
3751 {
3752 mask = (~ (HOST_WIDE_INT) 0) << bits;
3753 if ((mask & constant) != mask)
3754 warning ("comparison of promoted ~unsigned with constant");
3755 }
3756 }
3757 else if (unsignedp0 && unsignedp1
3758 && (TYPE_PRECISION (TREE_TYPE (primop0))
3759 < TYPE_PRECISION (result_type))
3760 && (TYPE_PRECISION (TREE_TYPE (primop1))
3761 < TYPE_PRECISION (result_type)))
3762 warning ("comparison of promoted ~unsigned with unsigned");
3763 }
3764 }
3765 }
3766
3767 /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
3768 If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
3769 Then the expression will be built.
3770 It will be given type FINAL_TYPE if that is nonzero;
3771 otherwise, it will be given type RESULT_TYPE. */
3772
3773 if (!result_type)
3774 {
3775 cp_error ("invalid operands `%T' and `%T' to binary `%O'",
3776 TREE_TYPE (orig_op0), TREE_TYPE (orig_op1), error_code);
3777 return error_mark_node;
3778 }
3779
3780 if (! converted)
3781 {
3782 if (TREE_TYPE (op0) != result_type)
3783 op0 = convert (result_type, op0);
3784 if (TREE_TYPE (op1) != result_type)
3785 op1 = convert (result_type, op1);
3786 }
3787
3788 if (build_type == NULL_TREE)
3789 build_type = result_type;
3790
3791 {
3792 register tree result = build (resultcode, build_type, op0, op1);
3793 register tree folded;
3794
3795 folded = fold (result);
3796 if (folded == result)
3797 TREE_CONSTANT (folded) = TREE_CONSTANT (op0) & TREE_CONSTANT (op1);
3798 if (final_type != 0)
3799 return convert (final_type, folded);
3800 return folded;
3801 }
3802 }
3803 \f
3804 /* Return a tree for the sum or difference (RESULTCODE says which)
3805 of pointer PTROP and integer INTOP. */
3806
3807 static tree
3808 pointer_int_sum (resultcode, ptrop, intop)
3809 enum tree_code resultcode;
3810 register tree ptrop, intop;
3811 {
3812 tree size_exp;
3813
3814 register tree result;
3815 register tree folded = fold (intop);
3816
3817 /* The result is a pointer of the same type that is being added. */
3818
3819 register tree result_type = TREE_TYPE (ptrop);
3820
3821 if (TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE)
3822 {
3823 if (pedantic || warn_pointer_arith)
3824 pedwarn ("ANSI C++ forbids using pointer of type `void *' in arithmetic");
3825 size_exp = integer_one_node;
3826 }
3827 else if (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE)
3828 {
3829 if (pedantic || warn_pointer_arith)
3830 pedwarn ("ANSI C++ forbids using pointer to a function in arithmetic");
3831 size_exp = integer_one_node;
3832 }
3833 else if (TREE_CODE (TREE_TYPE (result_type)) == METHOD_TYPE)
3834 {
3835 if (pedantic || warn_pointer_arith)
3836 pedwarn ("ANSI C++ forbids using pointer to a method in arithmetic");
3837 size_exp = integer_one_node;
3838 }
3839 else if (TREE_CODE (TREE_TYPE (result_type)) == OFFSET_TYPE)
3840 {
3841 if (pedantic || warn_pointer_arith)
3842 pedwarn ("ANSI C++ forbids using pointer to a member in arithmetic");
3843 size_exp = integer_one_node;
3844 }
3845 else
3846 size_exp = size_in_bytes (complete_type (TREE_TYPE (result_type)));
3847
3848 /* Needed to make OOPS V2R3 work. */
3849 intop = folded;
3850 if (TREE_CODE (intop) == INTEGER_CST
3851 && TREE_INT_CST_LOW (intop) == 0
3852 && TREE_INT_CST_HIGH (intop) == 0)
3853 return ptrop;
3854
3855 /* If what we are about to multiply by the size of the elements
3856 contains a constant term, apply distributive law
3857 and multiply that constant term separately.
3858 This helps produce common subexpressions. */
3859
3860 if ((TREE_CODE (intop) == PLUS_EXPR || TREE_CODE (intop) == MINUS_EXPR)
3861 && ! TREE_CONSTANT (intop)
3862 && TREE_CONSTANT (TREE_OPERAND (intop, 1))
3863 && TREE_CONSTANT (size_exp))
3864 {
3865 enum tree_code subcode = resultcode;
3866 if (TREE_CODE (intop) == MINUS_EXPR)
3867 subcode = (subcode == PLUS_EXPR ? MINUS_EXPR : PLUS_EXPR);
3868 ptrop = build_binary_op (subcode, ptrop, TREE_OPERAND (intop, 1), 1);
3869 intop = TREE_OPERAND (intop, 0);
3870 }
3871
3872 /* Convert the integer argument to a type the same size as sizetype
3873 so the multiply won't overflow spuriously. */
3874
3875 if (TYPE_PRECISION (TREE_TYPE (intop)) != TYPE_PRECISION (sizetype))
3876 intop = convert (type_for_size (TYPE_PRECISION (sizetype), 0), intop);
3877
3878 /* Replace the integer argument with a suitable product by the object size.
3879 Do this multiplication as signed, then convert to the appropriate
3880 pointer type (actually unsigned integral). */
3881
3882 intop = convert (result_type,
3883 build_binary_op (MULT_EXPR, intop,
3884 convert (TREE_TYPE (intop), size_exp), 1));
3885
3886 /* Create the sum or difference. */
3887
3888 result = build (resultcode, result_type, ptrop, intop);
3889
3890 folded = fold (result);
3891 if (folded == result)
3892 TREE_CONSTANT (folded) = TREE_CONSTANT (ptrop) & TREE_CONSTANT (intop);
3893 return folded;
3894 }
3895
3896 /* Return a tree for the difference of pointers OP0 and OP1.
3897 The resulting tree has type int. */
3898
3899 static tree
3900 pointer_diff (op0, op1)
3901 register tree op0, op1;
3902 {
3903 register tree result, folded;
3904 tree restype = ptrdiff_type_node;
3905 tree target_type = TREE_TYPE (TREE_TYPE (op0));
3906
3907 if (pedantic || warn_pointer_arith)
3908 {
3909 if (TREE_CODE (target_type) == VOID_TYPE)
3910 pedwarn ("ANSI C++ forbids using pointer of type `void *' in subtraction");
3911 if (TREE_CODE (target_type) == FUNCTION_TYPE)
3912 pedwarn ("ANSI C++ forbids using pointer to a function in subtraction");
3913 if (TREE_CODE (target_type) == METHOD_TYPE)
3914 pedwarn ("ANSI C++ forbids using pointer to a method in subtraction");
3915 if (TREE_CODE (target_type) == OFFSET_TYPE)
3916 pedwarn ("ANSI C++ forbids using pointer to a member in subtraction");
3917 }
3918
3919 /* First do the subtraction as integers;
3920 then drop through to build the divide operator. */
3921
3922 op0 = build_binary_op (MINUS_EXPR,
3923 convert (restype, op0), convert (restype, op1), 1);
3924
3925 /* This generates an error if op1 is a pointer to an incomplete type. */
3926 if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (op1))) == 0)
3927 error ("arithmetic on pointer to an incomplete type");
3928
3929 op1 = ((TREE_CODE (target_type) == VOID_TYPE
3930 || TREE_CODE (target_type) == FUNCTION_TYPE
3931 || TREE_CODE (target_type) == METHOD_TYPE
3932 || TREE_CODE (target_type) == OFFSET_TYPE)
3933 ? integer_one_node
3934 : size_in_bytes (target_type));
3935
3936 /* Do the division. */
3937
3938 result = build (EXACT_DIV_EXPR, restype, op0, convert (restype, op1));
3939
3940 folded = fold (result);
3941 if (folded == result)
3942 TREE_CONSTANT (folded) = TREE_CONSTANT (op0) & TREE_CONSTANT (op1);
3943 return folded;
3944 }
3945 \f
3946 /* Handle the case of taking the address of a COMPONENT_REF.
3947 Called by `build_unary_op' and `build_up_reference'.
3948
3949 ARG is the COMPONENT_REF whose address we want.
3950 ARGTYPE is the pointer type that this address should have.
3951 MSG is an error message to print if this COMPONENT_REF is not
3952 addressable (such as a bitfield). */
3953
3954 tree
3955 build_component_addr (arg, argtype, msg)
3956 tree arg, argtype;
3957 char *msg;
3958 {
3959 tree field = TREE_OPERAND (arg, 1);
3960 tree basetype = decl_type_context (field);
3961 tree rval = build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0), 0);
3962
3963 if (DECL_BIT_FIELD (field))
3964 {
3965 error (msg, IDENTIFIER_POINTER (DECL_NAME (field)));
3966 return error_mark_node;
3967 }
3968
3969 if (TREE_CODE (field) == FIELD_DECL
3970 && TYPE_USES_COMPLEX_INHERITANCE (basetype))
3971 {
3972 /* Can't convert directly to ARGTYPE, since that
3973 may have the same pointer type as one of our
3974 baseclasses. */
3975 rval = build1 (NOP_EXPR, argtype,
3976 convert_pointer_to (basetype, rval));
3977 TREE_CONSTANT (rval) = TREE_CONSTANT (TREE_OPERAND (rval, 0));
3978 }
3979 else
3980 /* This conversion is harmless. */
3981 rval = convert_force (argtype, rval, 0);
3982
3983 if (! integer_zerop (DECL_FIELD_BITPOS (field)))
3984 {
3985 tree offset = size_binop (EASY_DIV_EXPR, DECL_FIELD_BITPOS (field),
3986 size_int (BITS_PER_UNIT));
3987 int flag = TREE_CONSTANT (rval);
3988 rval = fold (build (PLUS_EXPR, argtype,
3989 rval, convert (argtype, offset)));
3990 TREE_CONSTANT (rval) = flag;
3991 }
3992 return rval;
3993 }
3994
3995 /* Construct and perhaps optimize a tree representation
3996 for a unary operation. CODE, a tree_code, specifies the operation
3997 and XARG is the operand. */
3998
3999 tree
4000 build_x_unary_op (code, xarg)
4001 enum tree_code code;
4002 tree xarg;
4003 {
4004 if (current_template_parms)
4005 return build_min_nt (code, xarg, NULL_TREE);
4006
4007 /* & rec, on incomplete RECORD_TYPEs is the simple opr &, not an
4008 error message. */
4009 if (code == ADDR_EXPR
4010 && ((IS_AGGR_TYPE_CODE (TREE_CODE (TREE_TYPE (xarg)))
4011 && TYPE_SIZE (TREE_TYPE (xarg)) == NULL_TREE)
4012 || (TREE_CODE (xarg) == OFFSET_REF)))
4013 /* don't look for a function */;
4014 else
4015 {
4016 tree rval = build_opfncall (code, LOOKUP_SPECULATIVELY, xarg,
4017 NULL_TREE, NULL_TREE);
4018 if (rval)
4019 return build_opfncall (code, LOOKUP_NORMAL, xarg,
4020 NULL_TREE, NULL_TREE);
4021 }
4022
4023 if (code == ADDR_EXPR)
4024 {
4025 if (TREE_CODE (xarg) == TARGET_EXPR)
4026 warning ("taking address of temporary");
4027 }
4028
4029 return build_unary_op (code, xarg, 0);
4030 }
4031
4032 /* Just like truthvalue_conversion, but we want a CLEANUP_POINT_EXPR. */
4033
4034 tree
4035 condition_conversion (expr)
4036 tree expr;
4037 {
4038 tree t;
4039 if (current_template_parms)
4040 return expr;
4041 t = convert (boolean_type_node, expr);
4042 t = fold (build1 (CLEANUP_POINT_EXPR, boolean_type_node, t));
4043 return t;
4044 }
4045
4046 /* C++: Must handle pointers to members.
4047
4048 Perhaps type instantiation should be extended to handle conversion
4049 from aggregates to types we don't yet know we want? (Or are those
4050 cases typically errors which should be reported?)
4051
4052 NOCONVERT nonzero suppresses the default promotions
4053 (such as from short to int). */
4054
4055 tree
4056 build_unary_op (code, xarg, noconvert)
4057 enum tree_code code;
4058 tree xarg;
4059 int noconvert;
4060 {
4061 /* No default_conversion here. It causes trouble for ADDR_EXPR. */
4062 register tree arg = xarg;
4063 register tree argtype = 0;
4064 char *errstring = NULL;
4065 tree val;
4066
4067 if (arg == error_mark_node)
4068 return error_mark_node;
4069
4070 switch (code)
4071 {
4072 case CONVERT_EXPR:
4073 /* This is used for unary plus, because a CONVERT_EXPR
4074 is enough to prevent anybody from looking inside for
4075 associativity, but won't generate any code. */
4076 if (!(arg = build_expr_type_conversion
4077 (WANT_ARITH | WANT_ENUM | WANT_POINTER, arg, 1)))
4078 errstring = "wrong type argument to unary plus";
4079 else
4080 {
4081 if (!noconvert)
4082 arg = default_conversion (arg);
4083 arg = build1 (NON_LVALUE_EXPR, TREE_TYPE (arg), arg);
4084 }
4085 break;
4086
4087 case NEGATE_EXPR:
4088 if (!(arg = build_expr_type_conversion (WANT_ARITH | WANT_ENUM, arg, 1)))
4089 errstring = "wrong type argument to unary minus";
4090 else if (!noconvert)
4091 arg = default_conversion (arg);
4092 break;
4093
4094 case BIT_NOT_EXPR:
4095 if (!(arg = build_expr_type_conversion (WANT_INT | WANT_ENUM, arg, 1)))
4096 errstring = "wrong type argument to bit-complement";
4097 else if (!noconvert)
4098 arg = default_conversion (arg);
4099 break;
4100
4101 case ABS_EXPR:
4102 if (!(arg = build_expr_type_conversion (WANT_ARITH | WANT_ENUM, arg, 1)))
4103 errstring = "wrong type argument to abs";
4104 else if (!noconvert)
4105 arg = default_conversion (arg);
4106 break;
4107
4108 case TRUTH_NOT_EXPR:
4109 arg = convert (boolean_type_node, arg);
4110 val = invert_truthvalue (arg);
4111 if (arg != error_mark_node)
4112 return val;
4113 errstring = "in argument to unary !";
4114 break;
4115
4116 case NOP_EXPR:
4117 break;
4118
4119 case PREINCREMENT_EXPR:
4120 case POSTINCREMENT_EXPR:
4121 case PREDECREMENT_EXPR:
4122 case POSTDECREMENT_EXPR:
4123 /* Handle complex lvalues (when permitted)
4124 by reduction to simpler cases. */
4125
4126 val = unary_complex_lvalue (code, arg);
4127 if (val != 0)
4128 return val;
4129
4130 /* Report invalid types. */
4131
4132 if (!(arg = build_expr_type_conversion (WANT_ARITH | WANT_POINTER,
4133 arg, 1)))
4134 {
4135 if (code == PREINCREMENT_EXPR)
4136 errstring ="no pre-increment operator for type";
4137 else if (code == POSTINCREMENT_EXPR)
4138 errstring ="no post-increment operator for type";
4139 else if (code == PREDECREMENT_EXPR)
4140 errstring ="no pre-decrement operator for type";
4141 else
4142 errstring ="no post-decrement operator for type";
4143 break;
4144 }
4145
4146 /* Report something read-only. */
4147
4148 if (TYPE_READONLY (TREE_TYPE (arg))
4149 || TREE_READONLY (arg))
4150 readonly_error (arg, ((code == PREINCREMENT_EXPR
4151 || code == POSTINCREMENT_EXPR)
4152 ? "increment" : "decrement"),
4153 0);
4154
4155 {
4156 register tree inc;
4157 tree result_type = TREE_TYPE (arg);
4158
4159 arg = get_unwidened (arg, 0);
4160 argtype = TREE_TYPE (arg);
4161
4162 /* ARM $5.2.5 last annotation says this should be forbidden. */
4163 if (TREE_CODE (argtype) == ENUMERAL_TYPE)
4164 pedwarn ("ANSI C++ forbids %sing an enum",
4165 (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
4166 ? "increment" : "decrement");
4167
4168 /* Compute the increment. */
4169
4170 if (TREE_CODE (argtype) == POINTER_TYPE)
4171 {
4172 enum tree_code tmp = TREE_CODE (TREE_TYPE (argtype));
4173 if (TYPE_SIZE (complete_type (TREE_TYPE (argtype))) == 0)
4174 cp_error ("cannot %s a pointer to incomplete type `%T'",
4175 ((code == PREINCREMENT_EXPR
4176 || code == POSTINCREMENT_EXPR)
4177 ? "increment" : "decrement"), TREE_TYPE (argtype));
4178 else if (tmp == FUNCTION_TYPE || tmp == METHOD_TYPE
4179 || tmp == VOID_TYPE || tmp == OFFSET_TYPE)
4180 cp_pedwarn ("ANSI C++ forbids %sing a pointer of type `%T'",
4181 ((code == PREINCREMENT_EXPR
4182 || code == POSTINCREMENT_EXPR)
4183 ? "increment" : "decrement"), argtype);
4184 inc = c_sizeof_nowarn (TREE_TYPE (argtype));
4185 }
4186 else
4187 inc = integer_one_node;
4188
4189 inc = convert (argtype, inc);
4190
4191 /* Handle incrementing a cast-expression. */
4192
4193 switch (TREE_CODE (arg))
4194 {
4195 case NOP_EXPR:
4196 case CONVERT_EXPR:
4197 case FLOAT_EXPR:
4198 case FIX_TRUNC_EXPR:
4199 case FIX_FLOOR_EXPR:
4200 case FIX_ROUND_EXPR:
4201 case FIX_CEIL_EXPR:
4202 {
4203 tree incremented, modify, value, compound;
4204 if (! lvalue_p (arg) && pedantic)
4205 pedwarn ("cast to non-reference type used as lvalue");
4206 arg = stabilize_reference (arg);
4207 if (code == PREINCREMENT_EXPR || code == PREDECREMENT_EXPR)
4208 value = arg;
4209 else
4210 value = save_expr (arg);
4211 incremented = build (((code == PREINCREMENT_EXPR
4212 || code == POSTINCREMENT_EXPR)
4213 ? PLUS_EXPR : MINUS_EXPR),
4214 argtype, value, inc);
4215 TREE_SIDE_EFFECTS (incremented) = 1;
4216
4217 modify = build_modify_expr (arg, NOP_EXPR, incremented);
4218 compound = build (COMPOUND_EXPR, TREE_TYPE (arg), modify, value);
4219
4220 /* Eliminate warning about unused result of + or -. */
4221 TREE_NO_UNUSED_WARNING (compound) = 1;
4222 return compound;
4223 }
4224 }
4225
4226 /* Complain about anything else that is not a true lvalue. */
4227 if (!lvalue_or_else (arg, ((code == PREINCREMENT_EXPR
4228 || code == POSTINCREMENT_EXPR)
4229 ? "increment" : "decrement")))
4230 return error_mark_node;
4231
4232 /* Forbid using -- on `bool'. */
4233 if (TREE_TYPE (arg) == boolean_type_node)
4234 {
4235 if (code == POSTDECREMENT_EXPR || code == PREDECREMENT_EXPR)
4236 {
4237 cp_error ("invalid use of `--' on bool variable `%D'", arg);
4238 return error_mark_node;
4239 }
4240 #if 0
4241 /* This will only work if someone can convince Kenner to accept
4242 my patch to expand_increment. (jason) */
4243 val = build (code, TREE_TYPE (arg), arg, inc);
4244 #else
4245 if (code == POSTINCREMENT_EXPR)
4246 {
4247 arg = stabilize_reference (arg);
4248 val = build (MODIFY_EXPR, TREE_TYPE (arg), arg,
4249 boolean_true_node);
4250 TREE_SIDE_EFFECTS (val) = 1;
4251 arg = save_expr (arg);
4252 val = build (COMPOUND_EXPR, TREE_TYPE (arg), val, arg);
4253 val = build (COMPOUND_EXPR, TREE_TYPE (arg), arg, val);
4254 }
4255 else
4256 val = build (MODIFY_EXPR, TREE_TYPE (arg), arg,
4257 boolean_true_node);
4258 #endif
4259 }
4260 else
4261 val = build (code, TREE_TYPE (arg), arg, inc);
4262
4263 TREE_SIDE_EFFECTS (val) = 1;
4264 return convert (result_type, val);
4265 }
4266
4267 case ADDR_EXPR:
4268 /* Note that this operation never does default_conversion
4269 regardless of NOCONVERT. */
4270
4271 argtype = TREE_TYPE (arg);
4272 if (TREE_CODE (argtype) == REFERENCE_TYPE)
4273 {
4274 arg = build1 (CONVERT_EXPR, build_pointer_type (TREE_TYPE (TREE_TYPE (arg))), arg);
4275 TREE_REFERENCE_EXPR (arg) = 1;
4276 return arg;
4277 }
4278 else if (pedantic
4279 && TREE_CODE (arg) == FUNCTION_DECL
4280 && DECL_NAME (arg)
4281 && DECL_CONTEXT (arg) == NULL_TREE
4282 && IDENTIFIER_LENGTH (DECL_NAME (arg)) == 4
4283 && IDENTIFIER_POINTER (DECL_NAME (arg))[0] == 'm'
4284 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (arg)), "main"))
4285 /* ARM $3.4 */
4286 pedwarn ("taking address of function `main'");
4287
4288 /* Let &* cancel out to simplify resulting code. */
4289 if (TREE_CODE (arg) == INDIRECT_REF)
4290 {
4291 /* We don't need to have `current_class_ptr' wrapped in a
4292 NON_LVALUE_EXPR node. */
4293 if (arg == current_class_ref)
4294 return current_class_ptr;
4295
4296 /* Keep `default_conversion' from converting if
4297 ARG is of REFERENCE_TYPE. */
4298 arg = TREE_OPERAND (arg, 0);
4299 if (TREE_CODE (TREE_TYPE (arg)) == REFERENCE_TYPE)
4300 {
4301 if (TREE_CODE (arg) == VAR_DECL && DECL_INITIAL (arg)
4302 && !TREE_SIDE_EFFECTS (DECL_INITIAL (arg)))
4303 arg = DECL_INITIAL (arg);
4304 arg = build1 (CONVERT_EXPR, build_pointer_type (TREE_TYPE (TREE_TYPE (arg))), arg);
4305 TREE_REFERENCE_EXPR (arg) = 1;
4306 TREE_CONSTANT (arg) = TREE_CONSTANT (TREE_OPERAND (arg, 0));
4307 }
4308 else if (lvalue_p (arg))
4309 /* Don't let this be an lvalue. */
4310 return non_lvalue (arg);
4311 return arg;
4312 }
4313
4314 /* For &x[y], return x+y */
4315 if (TREE_CODE (arg) == ARRAY_REF)
4316 {
4317 if (mark_addressable (TREE_OPERAND (arg, 0)) == 0)
4318 return error_mark_node;
4319 return build_binary_op (PLUS_EXPR, TREE_OPERAND (arg, 0),
4320 TREE_OPERAND (arg, 1), 1);
4321 }
4322
4323 /* Uninstantiated types are all functions. Taking the
4324 address of a function is a no-op, so just return the
4325 argument. */
4326
4327 if (TREE_CODE (arg) == IDENTIFIER_NODE
4328 && IDENTIFIER_OPNAME_P (arg))
4329 {
4330 my_friendly_abort (117);
4331 /* We don't know the type yet, so just work around the problem.
4332 We know that this will resolve to an lvalue. */
4333 return build1 (ADDR_EXPR, unknown_type_node, arg);
4334 }
4335
4336 if (TREE_CODE (arg) == TREE_LIST)
4337 {
4338 if (TREE_CODE (TREE_VALUE (arg)) == FUNCTION_DECL
4339 && DECL_CHAIN (TREE_VALUE (arg)) == NULL_TREE)
4340 /* Unique overloaded non-member function. */
4341 return build_unary_op (ADDR_EXPR, TREE_VALUE (arg), 0);
4342 if (TREE_CHAIN (arg) == NULL_TREE
4343 && TREE_CODE (TREE_VALUE (arg)) == TREE_LIST
4344 && DECL_CHAIN (TREE_VALUE (TREE_VALUE (arg))) == NULL_TREE)
4345 /* Unique overloaded member function. */
4346 return build_unary_op (ADDR_EXPR, TREE_VALUE (TREE_VALUE (arg)),
4347 0);
4348 return build1 (ADDR_EXPR, unknown_type_node, arg);
4349 }
4350
4351 /* Handle complex lvalues (when permitted)
4352 by reduction to simpler cases. */
4353 val = unary_complex_lvalue (code, arg);
4354 if (val != 0)
4355 return val;
4356
4357 switch (TREE_CODE (arg))
4358 {
4359 case NOP_EXPR:
4360 case CONVERT_EXPR:
4361 case FLOAT_EXPR:
4362 case FIX_TRUNC_EXPR:
4363 case FIX_FLOOR_EXPR:
4364 case FIX_ROUND_EXPR:
4365 case FIX_CEIL_EXPR:
4366 if (! lvalue_p (arg) && pedantic)
4367 pedwarn ("taking the address of a cast to non-reference type");
4368 }
4369
4370 /* Allow the address of a constructor if all the elements
4371 are constant. */
4372 if (TREE_CODE (arg) == CONSTRUCTOR && TREE_CONSTANT (arg))
4373 ;
4374 /* Anything not already handled and not a true memory reference
4375 is an error. */
4376 else if (TREE_CODE (argtype) != FUNCTION_TYPE
4377 && TREE_CODE (argtype) != METHOD_TYPE
4378 && !lvalue_or_else (arg, "unary `&'"))
4379 return error_mark_node;
4380
4381 /* Ordinary case; arg is a COMPONENT_REF or a decl. */
4382 /* If the lvalue is const or volatile,
4383 merge that into the type that the address will point to. */
4384 if (TREE_CODE_CLASS (TREE_CODE (arg)) == 'd'
4385 || TREE_CODE_CLASS (TREE_CODE (arg)) == 'r')
4386 {
4387 if (TREE_READONLY (arg) || TREE_THIS_VOLATILE (arg))
4388 argtype = cp_build_type_variant (argtype,
4389 TREE_READONLY (arg),
4390 TREE_THIS_VOLATILE (arg));
4391 }
4392
4393 argtype = build_pointer_type (argtype);
4394
4395 if (mark_addressable (arg) == 0)
4396 return error_mark_node;
4397
4398 {
4399 tree addr;
4400
4401 if (TREE_CODE (arg) == COMPONENT_REF)
4402 addr = build_component_addr (arg, argtype,
4403 "attempt to take address of bit-field structure member `%s'");
4404 else
4405 addr = build1 (code, argtype, arg);
4406
4407 /* Address of a static or external variable or
4408 function counts as a constant */
4409 if (staticp (arg))
4410 TREE_CONSTANT (addr) = 1;
4411
4412 if (TREE_CODE (argtype) == POINTER_TYPE &&
4413 TREE_CODE (TREE_TYPE (argtype)) == METHOD_TYPE)
4414 {
4415 build_ptrmemfunc_type (argtype);
4416 addr = build_ptrmemfunc (argtype, addr, 0);
4417 }
4418
4419 return addr;
4420 }
4421 }
4422
4423 if (!errstring)
4424 {
4425 if (argtype == 0)
4426 argtype = TREE_TYPE (arg);
4427 return fold (build1 (code, argtype, arg));
4428 }
4429
4430 error (errstring);
4431 return error_mark_node;
4432 }
4433
4434 #if 0
4435 /* If CONVERSIONS is a conversion expression or a nested sequence of such,
4436 convert ARG with the same conversions in the same order
4437 and return the result. */
4438
4439 static tree
4440 convert_sequence (conversions, arg)
4441 tree conversions;
4442 tree arg;
4443 {
4444 switch (TREE_CODE (conversions))
4445 {
4446 case NOP_EXPR:
4447 case CONVERT_EXPR:
4448 case FLOAT_EXPR:
4449 case FIX_TRUNC_EXPR:
4450 case FIX_FLOOR_EXPR:
4451 case FIX_ROUND_EXPR:
4452 case FIX_CEIL_EXPR:
4453 return convert (TREE_TYPE (conversions),
4454 convert_sequence (TREE_OPERAND (conversions, 0),
4455 arg));
4456
4457 default:
4458 return arg;
4459 }
4460 }
4461 #endif
4462
4463 /* Apply unary lvalue-demanding operator CODE to the expression ARG
4464 for certain kinds of expressions which are not really lvalues
4465 but which we can accept as lvalues.
4466
4467 If ARG is not a kind of expression we can handle, return zero. */
4468
4469 tree
4470 unary_complex_lvalue (code, arg)
4471 enum tree_code code;
4472 tree arg;
4473 {
4474 /* Handle (a, b) used as an "lvalue". */
4475 if (TREE_CODE (arg) == COMPOUND_EXPR)
4476 {
4477 tree real_result = build_unary_op (code, TREE_OPERAND (arg, 1), 0);
4478 return build (COMPOUND_EXPR, TREE_TYPE (real_result),
4479 TREE_OPERAND (arg, 0), real_result);
4480 }
4481
4482 /* Handle (a ? b : c) used as an "lvalue". */
4483 if (TREE_CODE (arg) == COND_EXPR)
4484 return rationalize_conditional_expr (code, arg);
4485
4486 if (TREE_CODE (arg) == MODIFY_EXPR
4487 || TREE_CODE (arg) == PREINCREMENT_EXPR
4488 || TREE_CODE (arg) == PREDECREMENT_EXPR)
4489 return unary_complex_lvalue
4490 (code, build (COMPOUND_EXPR, TREE_TYPE (TREE_OPERAND (arg, 0)),
4491 arg, TREE_OPERAND (arg, 0)));
4492
4493 if (code != ADDR_EXPR)
4494 return 0;
4495
4496 /* Handle (a = b) used as an "lvalue" for `&'. */
4497 if (TREE_CODE (arg) == MODIFY_EXPR
4498 || TREE_CODE (arg) == INIT_EXPR)
4499 {
4500 tree real_result = build_unary_op (code, TREE_OPERAND (arg, 0), 0);
4501 return build (COMPOUND_EXPR, TREE_TYPE (real_result), arg, real_result);
4502 }
4503
4504 if (TREE_CODE (TREE_TYPE (arg)) == FUNCTION_TYPE
4505 || TREE_CODE (TREE_TYPE (arg)) == METHOD_TYPE
4506 || TREE_CODE (TREE_TYPE (arg)) == OFFSET_TYPE)
4507 {
4508 /* The representation of something of type OFFSET_TYPE
4509 is really the representation of a pointer to it.
4510 Here give the representation its true type. */
4511 tree t;
4512 tree offset;
4513
4514 my_friendly_assert (TREE_CODE (arg) != SCOPE_REF, 313);
4515
4516 if (TREE_CODE (arg) != OFFSET_REF)
4517 return 0;
4518
4519 t = TREE_OPERAND (arg, 1);
4520
4521 if (TREE_CODE (t) == FUNCTION_DECL) /* Check all this code for right semantics. */
4522 return build_unary_op (ADDR_EXPR, t, 0);
4523 if (TREE_CODE (t) == VAR_DECL)
4524 return build_unary_op (ADDR_EXPR, t, 0);
4525 else
4526 {
4527 if (TREE_OPERAND (arg, 0)
4528 && (TREE_CODE (TREE_OPERAND (arg, 0)) != NOP_EXPR
4529 || TREE_OPERAND (TREE_OPERAND (arg, 0), 0) != error_mark_node))
4530 if (TREE_CODE (t) != FIELD_DECL)
4531 {
4532 /* Don't know if this should return address to just
4533 _DECL, or actual address resolved in this expression. */
4534 sorry ("address of bound pointer-to-member expression");
4535 return error_mark_node;
4536 }
4537
4538 /* Add in the offset to the right subobject. */
4539 offset = get_delta_difference (DECL_FIELD_CONTEXT (t),
4540 TREE_TYPE (TREE_OPERAND (arg, 0)),
4541 0);
4542
4543 /* Add in the offset to the field. */
4544 offset = size_binop (PLUS_EXPR, offset,
4545 size_binop (EASY_DIV_EXPR,
4546 DECL_FIELD_BITPOS (t),
4547 size_int (BITS_PER_UNIT)));
4548
4549 /* We offset all pointer to data memebers by 1 so that we can
4550 distinguish between a null pointer to data member and the first
4551 data member of a structure. */
4552 offset = size_binop (PLUS_EXPR, offset, size_int (1));
4553
4554 return convert (build_pointer_type (TREE_TYPE (arg)), offset);
4555 }
4556 }
4557
4558
4559 /* We permit compiler to make function calls returning
4560 objects of aggregate type look like lvalues. */
4561 {
4562 tree targ = arg;
4563
4564 if (TREE_CODE (targ) == SAVE_EXPR)
4565 targ = TREE_OPERAND (targ, 0);
4566
4567 if (TREE_CODE (targ) == CALL_EXPR && IS_AGGR_TYPE (TREE_TYPE (targ)))
4568 {
4569 if (TREE_CODE (arg) == SAVE_EXPR)
4570 targ = arg;
4571 else
4572 targ = build_cplus_new (TREE_TYPE (arg), arg);
4573 return build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (arg)), targ);
4574 }
4575
4576 if (TREE_CODE (arg) == SAVE_EXPR && TREE_CODE (targ) == INDIRECT_REF)
4577 return build (SAVE_EXPR, build_pointer_type (TREE_TYPE (arg)),
4578 TREE_OPERAND (targ, 0), current_function_decl, NULL);
4579 }
4580
4581 /* Don't let anything else be handled specially. */
4582 return 0;
4583 }
4584 \f
4585 /* Mark EXP saying that we need to be able to take the
4586 address of it; it should not be allocated in a register.
4587 Value is 1 if successful.
4588
4589 C++: we do not allow `current_class_ptr' to be addressable. */
4590
4591 int
4592 mark_addressable (exp)
4593 tree exp;
4594 {
4595 register tree x = exp;
4596
4597 if (TREE_ADDRESSABLE (x) == 1)
4598 return 1;
4599
4600 while (1)
4601 switch (TREE_CODE (x))
4602 {
4603 case ADDR_EXPR:
4604 case COMPONENT_REF:
4605 case ARRAY_REF:
4606 x = TREE_OPERAND (x, 0);
4607 break;
4608
4609 case PARM_DECL:
4610 if (x == current_class_ptr)
4611 {
4612 error ("address of `this' not available");
4613 TREE_ADDRESSABLE (x) = 1; /* so compiler doesn't die later */
4614 put_var_into_stack (x);
4615 return 1;
4616 }
4617 case VAR_DECL:
4618 if (TREE_STATIC (x) && TREE_READONLY (x)
4619 && DECL_RTL (x) != 0
4620 && ! DECL_IN_MEMORY_P (x))
4621 {
4622 /* We thought this would make a good constant variable,
4623 but we were wrong. */
4624 push_obstacks_nochange ();
4625 end_temporary_allocation ();
4626
4627 TREE_ASM_WRITTEN (x) = 0;
4628 DECL_RTL (x) = 0;
4629 rest_of_decl_compilation (x, 0, IDENTIFIER_LOCAL_VALUE (x) == 0, 0);
4630 TREE_ADDRESSABLE (x) = 1;
4631
4632 pop_obstacks ();
4633
4634 return 1;
4635 }
4636 /* Caller should not be trying to mark initialized
4637 constant fields addressable. */
4638 my_friendly_assert (DECL_LANG_SPECIFIC (x) == 0
4639 || DECL_IN_AGGR_P (x) == 0
4640 || TREE_STATIC (x)
4641 || DECL_EXTERNAL (x), 314);
4642
4643 case CONST_DECL:
4644 case RESULT_DECL:
4645 /* For C++, we don't warn about taking the address of a register
4646 variable for CONST_DECLs; ARM p97 explicitly says it's okay. */
4647 put_var_into_stack (x);
4648 TREE_ADDRESSABLE (x) = 1;
4649 return 1;
4650
4651 case FUNCTION_DECL:
4652 /* We have to test both conditions here. The first may
4653 be non-zero in the case of processing a default function.
4654 The second may be non-zero in the case of a template function. */
4655 x = DECL_MAIN_VARIANT (x);
4656 if ((DECL_THIS_INLINE (x) || DECL_PENDING_INLINE_INFO (x))
4657 && (DECL_CONTEXT (x) == NULL_TREE
4658 || TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (x))) != 't'
4659 || ! CLASSTYPE_INTERFACE_ONLY (DECL_CONTEXT (x))))
4660 {
4661 mark_inline_for_output (x);
4662 if (x == current_function_decl)
4663 DECL_EXTERNAL (x) = 0;
4664 }
4665 TREE_ADDRESSABLE (x) = 1;
4666 TREE_USED (x) = 1;
4667 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (x)) = 1;
4668 return 1;
4669
4670 case CONSTRUCTOR:
4671 TREE_ADDRESSABLE (x) = 1;
4672 return 1;
4673
4674 default:
4675 return 1;
4676 }
4677 }
4678 \f
4679 /* Build and return a conditional expression IFEXP ? OP1 : OP2. */
4680
4681 tree
4682 build_x_conditional_expr (ifexp, op1, op2)
4683 tree ifexp, op1, op2;
4684 {
4685 tree rval = NULL_TREE;
4686
4687 if (current_template_parms)
4688 return build_min_nt (COND_EXPR, ifexp, op1, op2);
4689
4690 /* See comments in `build_x_binary_op'. */
4691 if (op1 != 0)
4692 rval = build_opfncall (COND_EXPR, LOOKUP_SPECULATIVELY, ifexp, op1, op2);
4693 if (rval)
4694 return build_opfncall (COND_EXPR, LOOKUP_NORMAL, ifexp, op1, op2);
4695
4696 return build_conditional_expr (ifexp, op1, op2);
4697 }
4698
4699 tree
4700 build_conditional_expr (ifexp, op1, op2)
4701 tree ifexp, op1, op2;
4702 {
4703 register tree type1;
4704 register tree type2;
4705 register enum tree_code code1;
4706 register enum tree_code code2;
4707 register tree result_type = NULL_TREE;
4708 tree orig_op1 = op1, orig_op2 = op2;
4709
4710 /* If second operand is omitted, it is the same as the first one;
4711 make sure it is calculated only once. */
4712 if (op1 == 0)
4713 {
4714 if (pedantic)
4715 pedwarn ("ANSI C++ forbids omitting the middle term of a ?: expression");
4716 ifexp = op1 = save_expr (ifexp);
4717 }
4718
4719 ifexp = convert (boolean_type_node, ifexp);
4720
4721 if (TREE_CODE (ifexp) == ERROR_MARK)
4722 return error_mark_node;
4723
4724 op1 = require_instantiated_type (TREE_TYPE (op2), op1, error_mark_node);
4725 if (op1 == error_mark_node)
4726 return error_mark_node;
4727 op2 = require_instantiated_type (TREE_TYPE (op1), op2, error_mark_node);
4728 if (op2 == error_mark_node)
4729 return error_mark_node;
4730
4731 /* C++: REFERENCE_TYPES must be dereferenced. */
4732 type1 = TREE_TYPE (op1);
4733 code1 = TREE_CODE (type1);
4734 type2 = TREE_TYPE (op2);
4735 code2 = TREE_CODE (type2);
4736
4737 if (code1 == REFERENCE_TYPE)
4738 {
4739 op1 = convert_from_reference (op1);
4740 type1 = TREE_TYPE (op1);
4741 code1 = TREE_CODE (type1);
4742 }
4743 if (code2 == REFERENCE_TYPE)
4744 {
4745 op2 = convert_from_reference (op2);
4746 type2 = TREE_TYPE (op2);
4747 code2 = TREE_CODE (type2);
4748 }
4749
4750 /* Don't promote the operands separately if they promote
4751 the same way. Return the unpromoted type and let the combined
4752 value get promoted if necessary. */
4753
4754 if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2)
4755 && code2 != ARRAY_TYPE
4756 && code2 != FUNCTION_TYPE
4757 && code2 != METHOD_TYPE)
4758 {
4759 tree result;
4760
4761 if (TREE_CONSTANT (ifexp)
4762 && (TREE_CODE (ifexp) == INTEGER_CST
4763 || TREE_CODE (ifexp) == ADDR_EXPR))
4764 return (integer_zerop (ifexp) ? op2 : op1);
4765
4766 if (TREE_CODE (op1) == CONST_DECL)
4767 op1 = DECL_INITIAL (op1);
4768 else if (TREE_READONLY_DECL_P (op1))
4769 op1 = decl_constant_value (op1);
4770 if (TREE_CODE (op2) == CONST_DECL)
4771 op2 = DECL_INITIAL (op2);
4772 else if (TREE_READONLY_DECL_P (op2))
4773 op2 = decl_constant_value (op2);
4774 if (type1 != type2)
4775 type1 = cp_build_type_variant
4776 (type1,
4777 TREE_READONLY (op1) || TREE_READONLY (op2),
4778 TREE_THIS_VOLATILE (op1) || TREE_THIS_VOLATILE (op2));
4779 /* ??? This is a kludge to deal with the fact that
4780 we don't sort out integers and enums properly, yet. */
4781 result = fold (build (COND_EXPR, type1, ifexp, op1, op2));
4782 if (TREE_TYPE (result) != type1)
4783 result = build1 (NOP_EXPR, type1, result);
4784 return result;
4785 }
4786
4787 /* They don't match; promote them both and then try to reconcile them.
4788 But don't permit mismatching enum types. */
4789 if (code1 == ENUMERAL_TYPE)
4790 {
4791 if (code2 == ENUMERAL_TYPE)
4792 {
4793 cp_error ("enumeral mismatch in conditional expression: `%T' vs `%T'", type1, type2);
4794 return error_mark_node;
4795 }
4796 else if (extra_warnings && ! IS_AGGR_TYPE_CODE (code2)
4797 && type2 != type_promotes_to (type1))
4798 warning ("enumeral and non-enumeral type in conditional expression");
4799 }
4800 else if (extra_warnings
4801 && code2 == ENUMERAL_TYPE && ! IS_AGGR_TYPE_CODE (code1)
4802 && type1 != type_promotes_to (type2))
4803 warning ("enumeral and non-enumeral type in conditional expression");
4804
4805 if (code1 != VOID_TYPE)
4806 {
4807 op1 = default_conversion (op1);
4808 type1 = TREE_TYPE (op1);
4809 if (TYPE_PTRMEMFUNC_P (type1))
4810 type1 = TYPE_PTRMEMFUNC_FN_TYPE (type1);
4811 code1 = TREE_CODE (type1);
4812 }
4813 if (code2 != VOID_TYPE)
4814 {
4815 op2 = default_conversion (op2);
4816 type2 = TREE_TYPE (op2);
4817 if (TYPE_PTRMEMFUNC_P (type2))
4818 type2 = TYPE_PTRMEMFUNC_FN_TYPE (type2);
4819 code2 = TREE_CODE (type2);
4820 }
4821
4822 if (code1 == RECORD_TYPE && code2 == RECORD_TYPE
4823 && real_lvalue_p (op1) && real_lvalue_p (op2)
4824 && comptypes (type1, type2, -1))
4825 {
4826 type1 = build_reference_type (type1);
4827 type2 = build_reference_type (type2);
4828 result_type = common_type (type1, type2);
4829 op1 = convert_to_reference (result_type, op1, CONV_IMPLICIT,
4830 LOOKUP_NORMAL, NULL_TREE);
4831 op2 = convert_to_reference (result_type, op2, CONV_IMPLICIT,
4832 LOOKUP_NORMAL, NULL_TREE);
4833 }
4834 /* Quickly detect the usual case where op1 and op2 have the same type
4835 after promotion. */
4836 else if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2))
4837 {
4838 if (type1 == type2)
4839 result_type = type1;
4840 else
4841 result_type = cp_build_type_variant
4842 (type1,
4843 TREE_READONLY (op1) || TREE_READONLY (op2),
4844 TREE_THIS_VOLATILE (op1) || TREE_THIS_VOLATILE (op2));
4845 }
4846 else if ((code1 == INTEGER_TYPE || code1 == REAL_TYPE)
4847 && (code2 == INTEGER_TYPE || code2 == REAL_TYPE))
4848 {
4849 result_type = common_type (type1, type2);
4850 }
4851 else if (code1 == VOID_TYPE || code2 == VOID_TYPE)
4852 {
4853 if (pedantic && (code1 != VOID_TYPE || code2 != VOID_TYPE))
4854 pedwarn ("ANSI C++ forbids conditional expr with only one void side");
4855 result_type = void_type_node;
4856 }
4857 else if (code1 == POINTER_TYPE && code2 == POINTER_TYPE)
4858 {
4859 if (comp_target_types (type1, type2, 1))
4860 result_type = common_type (type1, type2);
4861 else if (integer_zerop (op1) && TREE_TYPE (type1) == void_type_node
4862 && TREE_CODE (orig_op1) != NOP_EXPR)
4863 result_type = qualify_type (type2, type1);
4864 else if (integer_zerop (op2) && TREE_TYPE (type2) == void_type_node
4865 && TREE_CODE (orig_op2) != NOP_EXPR)
4866 result_type = qualify_type (type1, type2);
4867 else if (TYPE_MAIN_VARIANT (TREE_TYPE (type1)) == void_type_node)
4868 {
4869 if (pedantic && TREE_CODE (type2) == FUNCTION_TYPE)
4870 pedwarn ("ANSI C++ forbids conditional expr between `void *' and function pointer");
4871 result_type = qualify_type (type1, type2);
4872 }
4873 else if (TYPE_MAIN_VARIANT (TREE_TYPE (type2)) == void_type_node)
4874 {
4875 if (pedantic && TREE_CODE (type1) == FUNCTION_TYPE)
4876 pedwarn ("ANSI C++ forbids conditional expr between `void *' and function pointer");
4877 result_type = qualify_type (type2, type1);
4878 }
4879 /* C++ */
4880 else if (comptypes (type2, type1, 0))
4881 result_type = type2;
4882 else if (IS_AGGR_TYPE (TREE_TYPE (type1))
4883 && IS_AGGR_TYPE (TREE_TYPE (type2))
4884 && (result_type = common_base_type (TREE_TYPE (type1), TREE_TYPE (type2))))
4885 {
4886 if (result_type == error_mark_node)
4887 {
4888 cp_error ("common base type of types `%T' and `%T' is ambiguous",
4889 TREE_TYPE (type1), TREE_TYPE (type2));
4890 result_type = ptr_type_node;
4891 }
4892 else
4893 {
4894 if (pedantic
4895 && result_type != TREE_TYPE (type1)
4896 && result_type != TREE_TYPE (type2))
4897 cp_pedwarn ("`%T' and `%T' converted to `%T *' in conditional expression",
4898 type1, type2, result_type);
4899
4900 result_type = build_pointer_type (result_type);
4901 }
4902 }
4903 else
4904 {
4905 pedwarn ("pointer type mismatch in conditional expression");
4906 result_type = ptr_type_node;
4907 }
4908 }
4909 else if (code1 == POINTER_TYPE && code2 == INTEGER_TYPE)
4910 {
4911 if (!integer_zerop (op2))
4912 pedwarn ("pointer/integer type mismatch in conditional expression");
4913 else
4914 op2 = null_pointer_node;
4915
4916 result_type = type1;
4917 }
4918 else if (code2 == POINTER_TYPE && code1 == INTEGER_TYPE)
4919 {
4920 if (!integer_zerop (op1))
4921 pedwarn ("pointer/integer type mismatch in conditional expression");
4922 else
4923 op1 = null_pointer_node;
4924
4925 result_type = type2;
4926 }
4927
4928 if (!result_type)
4929 {
4930 /* The match does not look good. If either is
4931 an aggregate value, try converting to a scalar type. */
4932 if (code1 == RECORD_TYPE && code2 == RECORD_TYPE)
4933 {
4934 cp_error ("aggregate mismatch in conditional expression: `%T' vs `%T'", type1, type2);
4935 return error_mark_node;
4936 }
4937 /* Warning: this code assumes that conversion between cv-variants of
4938 a type is done using NOP_EXPRs. */
4939 if (code1 == RECORD_TYPE && TYPE_HAS_CONVERSION (type1))
4940 {
4941 /* There are other types besides pointers and records. */
4942 tree tmp;
4943 if (code2 == POINTER_TYPE)
4944 tmp = build_pointer_type
4945 (build_type_variant (TREE_TYPE (type2), 1, 1));
4946 else
4947 tmp = type2;
4948 tmp = build_type_conversion (CONVERT_EXPR, tmp, op1, 0);
4949 if (tmp == NULL_TREE)
4950 {
4951 cp_error ("incompatible types `%T' and `%T' in `?:'",
4952 type1, type2);
4953 return error_mark_node;
4954 }
4955 if (tmp == error_mark_node)
4956 error ("ambiguous pointer conversion");
4957 else
4958 STRIP_NOPS (tmp);
4959 result_type = common_type (type2, TREE_TYPE (tmp));
4960 op1 = tmp;
4961 }
4962 else if (code2 == RECORD_TYPE && TYPE_HAS_CONVERSION (type2))
4963 {
4964 tree tmp;
4965 if (code1 == POINTER_TYPE)
4966 tmp = build_pointer_type
4967 (build_type_variant (TREE_TYPE (type1), 1, 1));
4968 else
4969 tmp = type1;
4970
4971 tmp = build_type_conversion (CONVERT_EXPR, tmp, op2, 0);
4972 if (tmp == NULL_TREE)
4973 {
4974 cp_error ("incompatible types `%T' and `%T' in `?:'",
4975 type1, type2);
4976 return error_mark_node;
4977 }
4978 if (tmp == error_mark_node)
4979 error ("ambiguous pointer conversion");
4980 else
4981 STRIP_NOPS (tmp);
4982 result_type = common_type (type1, TREE_TYPE (tmp));
4983 op2 = tmp;
4984 }
4985 else if (flag_cond_mismatch)
4986 result_type = void_type_node;
4987 else
4988 {
4989 error ("type mismatch in conditional expression");
4990 return error_mark_node;
4991 }
4992 }
4993
4994 if (TREE_CODE (result_type) == POINTER_TYPE
4995 && TREE_CODE (TREE_TYPE (result_type)) == METHOD_TYPE)
4996 result_type = build_ptrmemfunc_type (result_type);
4997
4998 if (result_type != TREE_TYPE (op1))
4999 op1 = convert_and_check (result_type, op1);
5000 if (result_type != TREE_TYPE (op2))
5001 op2 = convert_and_check (result_type, op2);
5002
5003 if (TREE_CONSTANT (ifexp))
5004 return integer_zerop (ifexp) ? op2 : op1;
5005
5006 return convert_from_reference
5007 (fold (build (COND_EXPR, result_type, ifexp, op1, op2)));
5008 }
5009 \f
5010 /* Handle overloading of the ',' operator when needed. Otherwise,
5011 this function just builds an expression list. */
5012
5013 tree
5014 build_x_compound_expr (list)
5015 tree list;
5016 {
5017 tree rest = TREE_CHAIN (list);
5018 tree result;
5019
5020 if (current_template_parms)
5021 return build_min_nt (COMPOUND_EXPR, list, NULL_TREE);
5022
5023 if (rest == NULL_TREE)
5024 return build_compound_expr (list);
5025
5026 result = build_opfncall (COMPOUND_EXPR, LOOKUP_NORMAL,
5027 TREE_VALUE (list), TREE_VALUE (rest), NULL_TREE);
5028 if (result)
5029 return build_x_compound_expr (tree_cons (NULL_TREE, result, TREE_CHAIN (rest)));
5030
5031 if (! TREE_SIDE_EFFECTS (TREE_VALUE (list)))
5032 {
5033 /* the left-hand operand of a comma expression is like an expression
5034 statement: we should warn if it doesn't have any side-effects,
5035 unless it was explicitly cast to (void). */
5036 if ((extra_warnings || warn_unused)
5037 && !(TREE_CODE (TREE_VALUE(list)) == CONVERT_EXPR
5038 && TREE_TYPE (TREE_VALUE(list)) == void_type_node))
5039 warning("left-hand operand of comma expression has no effect");
5040 }
5041 #if 0 /* this requires a gcc backend patch to export warn_if_unused_value */
5042 else if (warn_unused)
5043 warn_if_unused_value (TREE_VALUE(list));
5044 #endif
5045
5046 return build_compound_expr (tree_cons (NULL_TREE, TREE_VALUE (list),
5047 build_tree_list (NULL_TREE, build_x_compound_expr (rest))));
5048 }
5049
5050 /* Given a list of expressions, return a compound expression
5051 that performs them all and returns the value of the last of them. */
5052
5053 tree
5054 build_compound_expr (list)
5055 tree list;
5056 {
5057 register tree rest;
5058
5059 if (TREE_READONLY_DECL_P (TREE_VALUE (list)))
5060 TREE_VALUE (list) = decl_constant_value (TREE_VALUE (list));
5061
5062 if (TREE_CHAIN (list) == 0)
5063 {
5064 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5065 Strip such NOP_EXPRs, since LIST is used in non-lvalue context. */
5066 if (TREE_CODE (list) == NOP_EXPR
5067 && TREE_TYPE (list) == TREE_TYPE (TREE_OPERAND (list, 0)))
5068 list = TREE_OPERAND (list, 0);
5069
5070 /* Convert arrays to pointers. */
5071 if (TREE_CODE (TREE_TYPE (TREE_VALUE (list))) == ARRAY_TYPE)
5072 return default_conversion (TREE_VALUE (list));
5073 else
5074 return TREE_VALUE (list);
5075 }
5076
5077 rest = build_compound_expr (TREE_CHAIN (list));
5078
5079 /* When pedantic, a compound expression cannot be a constant expression. */
5080 if (! TREE_SIDE_EFFECTS (TREE_VALUE (list)) && ! pedantic)
5081 return rest;
5082
5083 return build (COMPOUND_EXPR, TREE_TYPE (rest),
5084 break_out_cleanups (TREE_VALUE (list)), rest);
5085 }
5086
5087 tree
5088 build_static_cast (type, expr)
5089 tree type, expr;
5090 {
5091 if (current_template_parms)
5092 {
5093 tree t = build_min (STATIC_CAST_EXPR, type, expr);
5094 return t;
5095 }
5096
5097 return build_c_cast (type, expr, 0);
5098 }
5099
5100 tree
5101 build_reinterpret_cast (type, expr)
5102 tree type, expr;
5103 {
5104 tree intype = TREE_TYPE (expr);
5105
5106 if (current_template_parms)
5107 {
5108 tree t = build_min (REINTERPRET_CAST_EXPR, type, expr);
5109 return t;
5110 }
5111
5112 if (TYPE_PTRMEMFUNC_P (type))
5113 if (TYPE_PTRMEMFUNC_P (intype))
5114 return build1 (NOP_EXPR, type, expr);
5115
5116 if (TYPE_PTRMEMFUNC_P (type))
5117 type = TYPE_PTRMEMFUNC_FN_TYPE (type);
5118
5119 if (TYPE_PTRMEMFUNC_P (intype))
5120 intype = TYPE_PTRMEMFUNC_FN_TYPE (intype);
5121
5122 if (! POINTER_TYPE_P (type) && ! TREE_CODE (type) == INTEGER_TYPE)
5123 {
5124 cp_error ("reinterpret_cast cannot convert to type `%T'", type);
5125 return error_mark_node;
5126 }
5127 if (! POINTER_TYPE_P (intype) && ! TREE_CODE (intype) == INTEGER_TYPE)
5128 {
5129 cp_error ("reinterpret_cast cannot convert from type `%T'", type);
5130 return error_mark_node;
5131 }
5132 if (TREE_CODE (type) == INTEGER_TYPE && TREE_CODE (intype) != POINTER_TYPE)
5133 {
5134 cp_error ("reinterpret_cast cannot convert non-pointer type `%T' to `%T'",
5135 intype, type);
5136 return error_mark_node;
5137 }
5138 if (TREE_CODE (intype) == INTEGER_TYPE && TREE_CODE (type) != POINTER_TYPE)
5139 {
5140 cp_error ("reinterpret_cast cannot convert `%T' to non-pointer type `%T'",
5141 intype, type);
5142 return error_mark_node;
5143 }
5144
5145 if (TREE_CODE (type) == POINTER_TYPE && TREE_CODE (intype) == POINTER_TYPE)
5146 expr = convert (ptr_type_node, expr);
5147
5148 return build_c_cast (type, expr, 0);
5149 }
5150
5151 tree
5152 build_const_cast (type, expr)
5153 tree type, expr;
5154 {
5155 tree intype = TREE_TYPE (expr);
5156 tree t1, t2;
5157
5158 if (type == error_mark_node || expr == error_mark_node)
5159 return error_mark_node;
5160
5161 if (current_template_parms)
5162 {
5163 tree t = build_min (CONST_CAST_EXPR, type, expr);
5164 return t;
5165 }
5166
5167 if (TYPE_PTRMEMFUNC_P (type))
5168 type = TYPE_PTRMEMFUNC_FN_TYPE (type);
5169 if (TYPE_PTRMEMFUNC_P (intype))
5170 intype = TYPE_PTRMEMFUNC_FN_TYPE (intype);
5171
5172 if (! POINTER_TYPE_P (type))
5173 {
5174 cp_error ("const_cast cannot convert to non-pointer type `%T'", type);
5175 return error_mark_node;
5176 }
5177 if (TREE_CODE (type) == REFERENCE_TYPE && ! real_lvalue_p (expr))
5178 {
5179 cp_error ("const_cast cannot convert rvalue to type `%T'", type);
5180 return error_mark_node;
5181 }
5182 if (TREE_CODE (type) == POINTER_TYPE && TREE_CODE (intype) != POINTER_TYPE)
5183 {
5184 cp_error ("const_cast cannot convert non-pointer type `%T' to type `%T'",
5185 intype, type);
5186 return error_mark_node;
5187 }
5188
5189 if (TREE_CODE (type) == REFERENCE_TYPE)
5190 {
5191 t1 = TREE_TYPE (type);
5192 t2 = intype;
5193 }
5194 else
5195 {
5196 t1 = TREE_TYPE (type);
5197 t2 = TREE_TYPE (intype);
5198
5199 for (; TREE_CODE (t1) == POINTER_TYPE && TREE_CODE (t2) == POINTER_TYPE;
5200 t1 = TREE_TYPE (t1), t2 = TREE_TYPE (t2))
5201 ;
5202 }
5203
5204 if (TREE_CODE (t1) == OFFSET_TYPE && TREE_CODE (t2) == OFFSET_TYPE)
5205 {
5206 if (TYPE_OFFSET_BASETYPE (t1) != TYPE_OFFSET_BASETYPE (t2))
5207 {
5208 cp_error ("const_cast cannot convert between pointers to members of different types `%T' and `%T'",
5209 TYPE_OFFSET_BASETYPE (t2), TYPE_OFFSET_BASETYPE (t1));
5210 return error_mark_node;
5211 }
5212 t1 = TREE_TYPE (t1);
5213 t2 = TREE_TYPE (t2);
5214 }
5215
5216 if (TYPE_MAIN_VARIANT (t1) != TYPE_MAIN_VARIANT (t2))
5217 {
5218 cp_error ("const_cast cannot convert unrelated type `%T' to `%T'",
5219 t2, t1);
5220 return error_mark_node;
5221 }
5222
5223 return build_c_cast (type, expr, 0);
5224 }
5225
5226 /* Build an expression representing a cast to type TYPE of expression EXPR.
5227
5228 ALLOW_NONCONVERTING is true if we should allow non-converting constructors
5229 when doing the cast. */
5230
5231 tree
5232 build_c_cast (type, expr, allow_nonconverting)
5233 register tree type;
5234 tree expr;
5235 int allow_nonconverting;
5236 {
5237 register tree value = expr;
5238
5239 if (type == error_mark_node || expr == error_mark_node)
5240 return error_mark_node;
5241
5242 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
5243 Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */
5244 if (TREE_CODE (type) != REFERENCE_TYPE
5245 && TREE_CODE (value) == NOP_EXPR
5246 && TREE_TYPE (value) == TREE_TYPE (TREE_OPERAND (value, 0)))
5247 value = TREE_OPERAND (value, 0);
5248
5249 if (TREE_TYPE (expr)
5250 && TREE_CODE (TREE_TYPE (expr)) == OFFSET_TYPE
5251 && TREE_CODE (type) != OFFSET_TYPE)
5252 value = resolve_offset_ref (value);
5253
5254 if (TREE_CODE (type) == ARRAY_TYPE)
5255 {
5256 /* Allow casting from T1* to T2[] because Cfront allows it.
5257 NIHCL uses it. It is not valid ANSI C however, and hence, not
5258 valid ANSI C++. */
5259 if (TREE_CODE (TREE_TYPE (expr)) == POINTER_TYPE)
5260 {
5261 if (pedantic)
5262 pedwarn ("ANSI C++ forbids casting to an array type");
5263 type = build_pointer_type (TREE_TYPE (type));
5264 }
5265 else
5266 {
5267 error ("ANSI C++ forbids casting to an array type");
5268 return error_mark_node;
5269 }
5270 }
5271
5272 if (TREE_CODE (type) == FUNCTION_TYPE
5273 || TREE_CODE (type) == METHOD_TYPE)
5274 {
5275 cp_error ("casting to function type `%T'", type);
5276 return error_mark_node;
5277 }
5278
5279 if (IS_SIGNATURE (type))
5280 {
5281 error ("cast specifies signature type");
5282 return error_mark_node;
5283 }
5284
5285 if (current_template_parms)
5286 {
5287 tree t = build_min (CAST_EXPR, type,
5288 min_tree_cons (NULL_TREE, value, NULL_TREE));
5289 return t;
5290 }
5291
5292 if (TREE_CODE (type) == VOID_TYPE)
5293 value = build1 (CONVERT_EXPR, type, value);
5294 else if (TREE_TYPE (value) == NULL_TREE
5295 || type_unknown_p (value))
5296 {
5297 value = instantiate_type (type, value, 1);
5298 /* Did we lose? */
5299 if (value == error_mark_node)
5300 return error_mark_node;
5301 }
5302 else
5303 {
5304 tree otype;
5305 int flag;
5306
5307 /* Convert functions and arrays to pointers and
5308 convert references to their expanded types,
5309 but don't convert any other types. */
5310 if (TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE
5311 || TREE_CODE (TREE_TYPE (value)) == METHOD_TYPE
5312 || TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE
5313 || TREE_CODE (TREE_TYPE (value)) == REFERENCE_TYPE)
5314 value = default_conversion (value);
5315 otype = TREE_TYPE (value);
5316
5317 /* Optionally warn about potentially worrisome casts. */
5318
5319 if (warn_cast_qual
5320 && TREE_CODE (type) == POINTER_TYPE
5321 && TREE_CODE (otype) == POINTER_TYPE)
5322 {
5323 /* For C++ we make these regular warnings, rather than
5324 softening them into pedwarns. */
5325 if (TYPE_VOLATILE (TREE_TYPE (otype))
5326 && ! TYPE_VOLATILE (TREE_TYPE (type)))
5327 warning ("cast discards `volatile' from pointer target type");
5328 if (TYPE_READONLY (TREE_TYPE (otype))
5329 && ! TYPE_READONLY (TREE_TYPE (type)))
5330 warning ("cast discards `const' from pointer target type");
5331 }
5332
5333 /* Warn about possible alignment problems. */
5334 if (STRICT_ALIGNMENT && warn_cast_align
5335 && TREE_CODE (type) == POINTER_TYPE
5336 && TREE_CODE (otype) == POINTER_TYPE
5337 && TREE_CODE (TREE_TYPE (otype)) != VOID_TYPE
5338 && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
5339 && TYPE_ALIGN (TREE_TYPE (type)) > TYPE_ALIGN (TREE_TYPE (otype)))
5340 warning ("cast increases required alignment of target type");
5341
5342 #if 0
5343 /* We should see about re-enabling these, they seem useful to
5344 me. */
5345 if (TREE_CODE (type) == INTEGER_TYPE
5346 && TREE_CODE (otype) == POINTER_TYPE
5347 && TYPE_PRECISION (type) != TYPE_PRECISION (otype))
5348 warning ("cast from pointer to integer of different size");
5349
5350 if (TREE_CODE (type) == POINTER_TYPE
5351 && TREE_CODE (otype) == INTEGER_TYPE
5352 && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
5353 /* Don't warn about converting 0 to pointer,
5354 provided the 0 was explicit--not cast or made by folding. */
5355 && !(TREE_CODE (value) == INTEGER_CST && integer_zerop (value)))
5356 warning ("cast to pointer from integer of different size");
5357 #endif
5358
5359 flag = allow_nonconverting ? CONV_NONCONVERTING : 0;
5360
5361 if (TREE_CODE (type) == REFERENCE_TYPE)
5362 value = (convert_from_reference
5363 (convert_to_reference (type, value, CONV_OLD_CONVERT|flag,
5364 LOOKUP_COMPLAIN, NULL_TREE)));
5365 else
5366 {
5367 tree ovalue;
5368
5369 if (TREE_READONLY_DECL_P (value))
5370 value = decl_constant_value (value);
5371
5372 ovalue = value;
5373 value = convert_force (type, value, flag);
5374
5375 /* Ignore any integer overflow caused by the cast. */
5376 if (TREE_CODE (value) == INTEGER_CST)
5377 {
5378 TREE_OVERFLOW (value) = TREE_OVERFLOW (ovalue);
5379 TREE_CONSTANT_OVERFLOW (value) = TREE_CONSTANT_OVERFLOW (ovalue);
5380 }
5381 }
5382 }
5383
5384 /* Always produce some operator for an explicit cast,
5385 so we can tell (for -pedantic) that the cast is no lvalue.
5386 Also, pedantically, don't let (void *) (FOO *) 0 be a null
5387 pointer constant. */
5388 if (TREE_CODE (type) != REFERENCE_TYPE
5389 && (value == expr
5390 || (pedantic
5391 && TREE_CODE (value) == INTEGER_CST
5392 && TREE_CODE (expr) == INTEGER_CST
5393 && TREE_CODE (TREE_TYPE (expr)) != INTEGER_TYPE)))
5394 value = non_lvalue (value);
5395
5396 return value;
5397 }
5398 \f
5399 tree
5400 expand_target_expr (t)
5401 tree t;
5402 {
5403 extern int temp_slot_level;
5404 extern int target_temp_slot_level;
5405 int old_temp_level = target_temp_slot_level;
5406
5407 tree xval = make_node (RTL_EXPR);
5408 rtx rtxval;
5409
5410 /* Any TARGET_EXPR temps live only as long as the outer temp level.
5411 Since they are preserved in this new inner level, we know they
5412 will make it into the outer level. */
5413 push_temp_slots ();
5414 target_temp_slot_level = temp_slot_level;
5415
5416 do_pending_stack_adjust ();
5417 start_sequence_for_rtl_expr (xval);
5418 emit_note (0, -1);
5419 rtxval = expand_expr (t, NULL_RTX, VOIDmode, 0);
5420 do_pending_stack_adjust ();
5421 TREE_SIDE_EFFECTS (xval) = 1;
5422 RTL_EXPR_SEQUENCE (xval) = get_insns ();
5423 end_sequence ();
5424 RTL_EXPR_RTL (xval) = rtxval;
5425 TREE_TYPE (xval) = TREE_TYPE (t);
5426
5427 pop_temp_slots ();
5428 target_temp_slot_level = old_temp_level;
5429
5430 return xval;
5431 }
5432
5433 /* Build an assignment expression of lvalue LHS from value RHS.
5434 MODIFYCODE is the code for a binary operator that we use
5435 to combine the old value of LHS with RHS to get the new value.
5436 Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.
5437
5438 C++: If MODIFYCODE is INIT_EXPR, then leave references unbashed. */
5439
5440 tree
5441 build_modify_expr (lhs, modifycode, rhs)
5442 tree lhs;
5443 enum tree_code modifycode;
5444 tree rhs;
5445 {
5446 register tree result;
5447 tree newrhs = rhs;
5448 tree lhstype = TREE_TYPE (lhs);
5449 tree olhstype = lhstype;
5450 tree olhs = lhs;
5451
5452 /* Avoid duplicate error messages from operands that had errors. */
5453 if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK)
5454 return error_mark_node;
5455
5456 /* Types that aren't fully specified cannot be used in assignments. */
5457 lhs = require_complete_type (lhs);
5458
5459 newrhs = rhs;
5460
5461 /* Handle assignment to signature pointers/refs. */
5462
5463 if (TYPE_LANG_SPECIFIC (lhstype) &&
5464 (IS_SIGNATURE_POINTER (lhstype) || IS_SIGNATURE_REFERENCE (lhstype)))
5465 {
5466 return build_signature_pointer_constructor (lhs, rhs);
5467 }
5468
5469 /* Handle control structure constructs used as "lvalues". */
5470
5471 switch (TREE_CODE (lhs))
5472 {
5473 /* Handle --foo = 5; as these are valid constructs in C++ */
5474 case PREDECREMENT_EXPR:
5475 case PREINCREMENT_EXPR:
5476 if (TREE_SIDE_EFFECTS (TREE_OPERAND (lhs, 0)))
5477 lhs = build (TREE_CODE (lhs), TREE_TYPE (lhs),
5478 stabilize_reference (TREE_OPERAND (lhs, 0)),
5479 TREE_OPERAND (lhs, 1));
5480 return build (COMPOUND_EXPR, lhstype,
5481 lhs,
5482 build_modify_expr (TREE_OPERAND (lhs, 0),
5483 modifycode, rhs));
5484
5485 /* Handle (a, b) used as an "lvalue". */
5486 case COMPOUND_EXPR:
5487 newrhs = build_modify_expr (TREE_OPERAND (lhs, 1),
5488 modifycode, rhs);
5489 if (TREE_CODE (newrhs) == ERROR_MARK)
5490 return error_mark_node;
5491 return build (COMPOUND_EXPR, lhstype,
5492 TREE_OPERAND (lhs, 0), newrhs);
5493
5494 case MODIFY_EXPR:
5495 newrhs = build_modify_expr (TREE_OPERAND (lhs, 0), modifycode, rhs);
5496 if (TREE_CODE (newrhs) == ERROR_MARK)
5497 return error_mark_node;
5498 return build (COMPOUND_EXPR, lhstype, lhs, newrhs);
5499
5500 /* Handle (a ? b : c) used as an "lvalue". */
5501 case COND_EXPR:
5502 rhs = save_expr (rhs);
5503 {
5504 /* Produce (a ? (b = rhs) : (c = rhs))
5505 except that the RHS goes through a save-expr
5506 so the code to compute it is only emitted once. */
5507 tree cond
5508 = build_conditional_expr (TREE_OPERAND (lhs, 0),
5509 build_modify_expr (convert (TREE_TYPE (lhs), TREE_OPERAND (lhs, 1)),
5510 modifycode, rhs),
5511 build_modify_expr (convert (TREE_TYPE (lhs), TREE_OPERAND (lhs, 2)),
5512 modifycode, rhs));
5513 if (TREE_CODE (cond) == ERROR_MARK)
5514 return cond;
5515 /* Make sure the code to compute the rhs comes out
5516 before the split. */
5517 return build (COMPOUND_EXPR, TREE_TYPE (lhs),
5518 /* Case to void to suppress warning
5519 from warn_if_unused_value. */
5520 convert (void_type_node, rhs), cond);
5521 }
5522 }
5523
5524 if (TREE_CODE (lhs) == OFFSET_REF)
5525 {
5526 if (TREE_OPERAND (lhs, 0) == NULL_TREE)
5527 {
5528 /* Static class member? */
5529 tree member = TREE_OPERAND (lhs, 1);
5530 if (TREE_CODE (member) == VAR_DECL)
5531 lhs = member;
5532 else
5533 {
5534 compiler_error ("invalid static class member");
5535 return error_mark_node;
5536 }
5537 }
5538 else
5539 lhs = resolve_offset_ref (lhs);
5540
5541 olhstype = lhstype = TREE_TYPE (lhs);
5542 }
5543
5544 if (TREE_CODE (lhstype) == REFERENCE_TYPE
5545 && modifycode != INIT_EXPR)
5546 {
5547 lhs = convert_from_reference (lhs);
5548 olhstype = lhstype = TREE_TYPE (lhs);
5549 }
5550
5551 /* If a binary op has been requested, combine the old LHS value with the RHS
5552 producing the value we should actually store into the LHS. */
5553
5554 if (modifycode == INIT_EXPR)
5555 {
5556 if (! IS_AGGR_TYPE (lhstype))
5557 /* Do the default thing */;
5558 else if (! TYPE_HAS_CONSTRUCTOR (lhstype))
5559 {
5560 cp_error ("`%T' has no constructors", lhstype);
5561 return error_mark_node;
5562 }
5563 else if (TYPE_HAS_TRIVIAL_INIT_REF (lhstype)
5564 && TYPE_MAIN_VARIANT (lhstype) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs)))
5565 /* Do the default thing */;
5566 else
5567 {
5568 result = build_method_call (lhs, ctor_identifier,
5569 build_tree_list (NULL_TREE, rhs),
5570 TYPE_BINFO (lhstype), LOOKUP_NORMAL);
5571 if (result == NULL_TREE)
5572 return error_mark_node;
5573 return result;
5574 }
5575 }
5576 else if (modifycode == NOP_EXPR)
5577 {
5578 /* `operator=' is not an inheritable operator. */
5579 if (! IS_AGGR_TYPE (lhstype))
5580 /* Do the default thing */;
5581 else if (! TYPE_HAS_ASSIGNMENT (lhstype))
5582 {
5583 cp_error ("`%T' does not define operator=", lhstype);
5584 return error_mark_node;
5585 }
5586 else if (TYPE_HAS_TRIVIAL_ASSIGN_REF (lhstype)
5587 && TYPE_MAIN_VARIANT (lhstype) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs)))
5588 {
5589 if (warn_synth)
5590 /* If we care about this, do overload resolution. */
5591 build_opfncall (MODIFY_EXPR, LOOKUP_NORMAL,
5592 lhs, rhs, make_node (NOP_EXPR));
5593
5594 /* Do the default thing */;
5595 }
5596 else
5597 {
5598 result = build_opfncall (MODIFY_EXPR, LOOKUP_NORMAL,
5599 lhs, rhs, make_node (NOP_EXPR));
5600 if (result == NULL_TREE)
5601 return error_mark_node;
5602 return result;
5603 }
5604 lhstype = olhstype;
5605 }
5606 else if (PROMOTES_TO_AGGR_TYPE (lhstype, REFERENCE_TYPE))
5607 {
5608 /* This case must convert to some sort of lvalue that
5609 can participate in an op= operation. */
5610 tree lhs_tmp = lhs;
5611 tree rhs_tmp = rhs;
5612 if (build_default_binary_type_conversion (modifycode, &lhs_tmp, &rhs_tmp))
5613 {
5614 lhs = stabilize_reference (lhs_tmp);
5615 /* Forget it was ever anything else. */
5616 olhstype = lhstype = TREE_TYPE (lhs);
5617 newrhs = build_binary_op (modifycode, lhs, rhs_tmp, 1);
5618 }
5619 else
5620 {
5621 cp_error ("no match for `%Q(%#T, %#T)'", modifycode,
5622 TREE_TYPE (lhs), TREE_TYPE (rhs));
5623 return error_mark_node;
5624 }
5625 }
5626 else
5627 {
5628 lhs = stabilize_reference (lhs);
5629 newrhs = build_binary_op (modifycode, lhs, rhs, 1);
5630 if (newrhs == error_mark_node)
5631 {
5632 cp_error (" in evaluation of `%Q(%#T, %#T)'", modifycode,
5633 TREE_TYPE (lhs), TREE_TYPE (rhs));
5634 return error_mark_node;
5635 }
5636 }
5637
5638 /* Handle a cast used as an "lvalue".
5639 We have already performed any binary operator using the value as cast.
5640 Now convert the result to the cast type of the lhs,
5641 and then true type of the lhs and store it there;
5642 then convert result back to the cast type to be the value
5643 of the assignment. */
5644
5645 switch (TREE_CODE (lhs))
5646 {
5647 case NOP_EXPR:
5648 case CONVERT_EXPR:
5649 case FLOAT_EXPR:
5650 case FIX_TRUNC_EXPR:
5651 case FIX_FLOOR_EXPR:
5652 case FIX_ROUND_EXPR:
5653 case FIX_CEIL_EXPR:
5654 if (TREE_CODE (TREE_TYPE (newrhs)) == ARRAY_TYPE
5655 || TREE_CODE (TREE_TYPE (newrhs)) == FUNCTION_TYPE
5656 || TREE_CODE (TREE_TYPE (newrhs)) == METHOD_TYPE
5657 || TREE_CODE (TREE_TYPE (newrhs)) == OFFSET_TYPE)
5658 newrhs = default_conversion (newrhs);
5659 {
5660 tree inner_lhs = TREE_OPERAND (lhs, 0);
5661 tree result;
5662 if (! lvalue_p (lhs) && pedantic)
5663 pedwarn ("cast to non-reference type used as lvalue");
5664
5665 result = build_modify_expr (inner_lhs, NOP_EXPR,
5666 convert (TREE_TYPE (inner_lhs),
5667 convert (lhstype, newrhs)));
5668 if (TREE_CODE (result) == ERROR_MARK)
5669 return result;
5670 return convert (TREE_TYPE (lhs), result);
5671 }
5672 }
5673
5674 /* Now we have handled acceptable kinds of LHS that are not truly lvalues.
5675 Reject anything strange now. */
5676
5677 if (!lvalue_or_else (lhs, "assignment"))
5678 return error_mark_node;
5679
5680 GNU_xref_assign (lhs);
5681
5682 /* Warn about storing in something that is `const'. */
5683 /* For C++, don't warn if this is initialization. */
5684 if (modifycode != INIT_EXPR
5685 /* For assignment to `const' signature pointer/reference fields,
5686 don't warn either, we already printed a better message before. */
5687 && ! (TREE_CODE (lhs) == COMPONENT_REF
5688 && (IS_SIGNATURE_POINTER (TREE_TYPE (TREE_OPERAND (lhs, 0)))
5689 || IS_SIGNATURE_REFERENCE (TREE_TYPE (TREE_OPERAND (lhs, 0)))))
5690 && (TREE_READONLY (lhs) || TYPE_READONLY (lhstype)
5691 || ((TREE_CODE (lhstype) == RECORD_TYPE
5692 || TREE_CODE (lhstype) == UNION_TYPE)
5693 && C_TYPE_FIELDS_READONLY (lhstype))
5694 || (TREE_CODE (lhstype) == REFERENCE_TYPE
5695 && TYPE_READONLY (TREE_TYPE (lhstype)))))
5696 readonly_error (lhs, "assignment", 0);
5697
5698 /* If storing into a structure or union member,
5699 it has probably been given type `int'.
5700 Compute the type that would go with
5701 the actual amount of storage the member occupies. */
5702
5703 if (TREE_CODE (lhs) == COMPONENT_REF
5704 && (TREE_CODE (lhstype) == INTEGER_TYPE
5705 || TREE_CODE (lhstype) == REAL_TYPE
5706 || TREE_CODE (lhstype) == ENUMERAL_TYPE))
5707 {
5708 lhstype = TREE_TYPE (get_unwidened (lhs, 0));
5709
5710 /* If storing in a field that is in actuality a short or narrower
5711 than one, we must store in the field in its actual type. */
5712
5713 if (lhstype != TREE_TYPE (lhs))
5714 {
5715 lhs = copy_node (lhs);
5716 TREE_TYPE (lhs) = lhstype;
5717 }
5718 }
5719
5720 /* check to see if there is an assignment to `this' */
5721 if (lhs == current_class_ptr)
5722 {
5723 if (flag_this_is_variable > 0
5724 && DECL_NAME (current_function_decl) != NULL_TREE
5725 && (DECL_NAME (current_function_decl)
5726 != constructor_name (current_class_type)))
5727 warning ("assignment to `this' not in constructor or destructor");
5728 current_function_just_assigned_this = 1;
5729 }
5730
5731 /* The TREE_TYPE of RHS may be TYPE_UNKNOWN. This can happen
5732 when the type of RHS is not yet known, i.e. its type
5733 is inherited from LHS. */
5734 rhs = require_instantiated_type (lhstype, newrhs, error_mark_node);
5735 if (rhs == error_mark_node)
5736 return error_mark_node;
5737 newrhs = rhs;
5738
5739 if (modifycode != INIT_EXPR)
5740 {
5741 /* Make modifycode now either a NOP_EXPR or an INIT_EXPR. */
5742 modifycode = NOP_EXPR;
5743 /* Reference-bashing */
5744 if (TREE_CODE (lhstype) == REFERENCE_TYPE)
5745 {
5746 tree tmp = convert_from_reference (lhs);
5747 lhstype = TREE_TYPE (tmp);
5748 if (TYPE_SIZE (lhstype) == 0)
5749 {
5750 incomplete_type_error (lhs, lhstype);
5751 return error_mark_node;
5752 }
5753 lhs = tmp;
5754 olhstype = lhstype;
5755 }
5756 if (TREE_CODE (TREE_TYPE (newrhs)) == REFERENCE_TYPE)
5757 {
5758 tree tmp = convert_from_reference (newrhs);
5759 if (TYPE_SIZE (TREE_TYPE (tmp)) == 0)
5760 {
5761 incomplete_type_error (newrhs, TREE_TYPE (tmp));
5762 return error_mark_node;
5763 }
5764 newrhs = tmp;
5765 }
5766 }
5767
5768 if (TREE_SIDE_EFFECTS (lhs))
5769 lhs = stabilize_reference (lhs);
5770 if (TREE_SIDE_EFFECTS (newrhs))
5771 newrhs = stabilize_reference (newrhs);
5772
5773 /* Convert new value to destination type. */
5774
5775 if (TREE_CODE (lhstype) == ARRAY_TYPE)
5776 {
5777 int from_array;
5778
5779 if (! comptypes (lhstype, TREE_TYPE (rhs), 0))
5780 {
5781 cp_error ("incompatible types in assignment of `%T' to `%T'",
5782 TREE_TYPE (rhs), lhstype);
5783 return error_mark_node;
5784 }
5785
5786 /* Allow array assignment in compiler-generated code. */
5787 if (pedantic && ! DECL_ARTIFICIAL (current_function_decl))
5788 pedwarn ("ANSI C++ forbids assignment of arrays");
5789
5790 /* Have to wrap this in RTL_EXPR for two cases:
5791 in base or member initialization and if we
5792 are a branch of a ?: operator. Since we
5793 can't easily know the latter, just do it always. */
5794
5795 result = make_node (RTL_EXPR);
5796
5797 TREE_TYPE (result) = void_type_node;
5798 do_pending_stack_adjust ();
5799 start_sequence_for_rtl_expr (result);
5800
5801 /* As a matter of principle, `start_sequence' should do this. */
5802 emit_note (0, -1);
5803
5804 from_array = TREE_CODE (TREE_TYPE (newrhs)) == ARRAY_TYPE
5805 ? 1 + (modifycode != INIT_EXPR): 0;
5806 expand_vec_init (lhs, lhs, array_type_nelts (lhstype), newrhs,
5807 from_array);
5808
5809 do_pending_stack_adjust ();
5810
5811 TREE_SIDE_EFFECTS (result) = 1;
5812 RTL_EXPR_SEQUENCE (result) = get_insns ();
5813 RTL_EXPR_RTL (result) = const0_rtx;
5814 end_sequence ();
5815 return result;
5816 }
5817
5818 if (modifycode == INIT_EXPR)
5819 {
5820 newrhs = convert_for_initialization (lhs, lhstype, newrhs, LOOKUP_NORMAL,
5821 "assignment", NULL_TREE, 0);
5822 if (lhs == DECL_RESULT (current_function_decl))
5823 {
5824 if (DECL_INITIAL (lhs))
5825 warning ("return value from function receives multiple initializations");
5826 DECL_INITIAL (lhs) = newrhs;
5827 }
5828 }
5829 else
5830 {
5831 /* Avoid warnings on enum bit fields. */
5832 if (TREE_CODE (olhstype) == ENUMERAL_TYPE
5833 && TREE_CODE (lhstype) == INTEGER_TYPE)
5834 {
5835 newrhs = convert_for_assignment (olhstype, newrhs, "assignment",
5836 NULL_TREE, 0);
5837 newrhs = convert_force (lhstype, newrhs, 0);
5838 }
5839 else
5840 newrhs = convert_for_assignment (lhstype, newrhs, "assignment",
5841 NULL_TREE, 0);
5842 if (TREE_CODE (newrhs) == CALL_EXPR
5843 && TYPE_NEEDS_CONSTRUCTING (lhstype))
5844 newrhs = build_cplus_new (lhstype, newrhs);
5845
5846 /* Can't initialize directly from a TARGET_EXPR, since that would
5847 cause the lhs to be constructed twice, and possibly result in
5848 accidental self-initialization. So we force the TARGET_EXPR to be
5849 expanded without a target. */
5850 if (TREE_CODE (newrhs) == TARGET_EXPR)
5851 newrhs = build (COMPOUND_EXPR, TREE_TYPE (newrhs), newrhs,
5852 TREE_OPERAND (newrhs, 0));
5853 }
5854
5855 if (TREE_CODE (newrhs) == ERROR_MARK)
5856 return error_mark_node;
5857
5858 if (TREE_CODE (newrhs) == COND_EXPR)
5859 {
5860 tree lhs1;
5861 tree cond = TREE_OPERAND (newrhs, 0);
5862
5863 if (TREE_SIDE_EFFECTS (lhs))
5864 cond = build_compound_expr (tree_cons
5865 (NULL_TREE, lhs,
5866 build_tree_list (NULL_TREE, cond)));
5867
5868 /* Cannot have two identical lhs on this one tree (result) as preexpand
5869 calls will rip them out and fill in RTL for them, but when the
5870 rtl is generated, the calls will only be in the first side of the
5871 condition, not on both, or before the conditional jump! (mrs) */
5872 lhs1 = break_out_calls (lhs);
5873
5874 if (lhs == lhs1)
5875 /* If there's no change, the COND_EXPR behaves like any other rhs. */
5876 result = build (modifycode == NOP_EXPR ? MODIFY_EXPR : INIT_EXPR,
5877 lhstype, lhs, newrhs);
5878 else
5879 {
5880 tree result_type = TREE_TYPE (newrhs);
5881 /* We have to convert each arm to the proper type because the
5882 types may have been munged by constant folding. */
5883 result
5884 = build (COND_EXPR, result_type, cond,
5885 build_modify_expr (lhs, modifycode,
5886 convert (result_type,
5887 TREE_OPERAND (newrhs, 1))),
5888 build_modify_expr (lhs1, modifycode,
5889 convert (result_type,
5890 TREE_OPERAND (newrhs, 2))));
5891 }
5892 }
5893 else
5894 result = build (modifycode == NOP_EXPR ? MODIFY_EXPR : INIT_EXPR,
5895 lhstype, lhs, newrhs);
5896
5897 TREE_SIDE_EFFECTS (result) = 1;
5898
5899 /* If we got the LHS in a different type for storing in,
5900 convert the result back to the nominal type of LHS
5901 so that the value we return always has the same type
5902 as the LHS argument. */
5903
5904 if (olhstype == TREE_TYPE (result))
5905 return result;
5906 /* Avoid warnings converting integral types back into enums
5907 for enum bit fields. */
5908 if (TREE_CODE (TREE_TYPE (result)) == INTEGER_TYPE
5909 && TREE_CODE (olhstype) == ENUMERAL_TYPE)
5910 {
5911 result = build (COMPOUND_EXPR, olhstype, result, olhs);
5912 TREE_NO_UNUSED_WARNING (result) = 1;
5913 return result;
5914 }
5915 return convert_for_assignment (olhstype, result, "assignment",
5916 NULL_TREE, 0);
5917 }
5918
5919 tree
5920 build_x_modify_expr (lhs, modifycode, rhs)
5921 tree lhs;
5922 enum tree_code modifycode;
5923 tree rhs;
5924 {
5925 if (current_template_parms)
5926 return build_min_nt (MODOP_EXPR, lhs,
5927 build_min_nt (modifycode, NULL_TREE, NULL_TREE), rhs);
5928
5929 if (modifycode != NOP_EXPR)
5930 {
5931 tree rval = build_opfncall (MODIFY_EXPR, LOOKUP_NORMAL, lhs, rhs,
5932 make_node (modifycode));
5933 if (rval)
5934 return rval;
5935 }
5936 return build_modify_expr (lhs, modifycode, rhs);
5937 }
5938
5939 /* Return 0 if EXP is not a valid lvalue in this language
5940 even though `lvalue_or_else' would accept it. */
5941
5942 int
5943 language_lvalue_valid (exp)
5944 tree exp;
5945 {
5946 return 1;
5947 }
5948 \f
5949 /* Get difference in deltas for different pointer to member function
5950 types. Return integer_zero_node, if FROM cannot be converted to a
5951 TO type. If FORCE is true, then allow reverse conversions as well. */
5952
5953 static tree
5954 get_delta_difference (from, to, force)
5955 tree from, to;
5956 int force;
5957 {
5958 tree delta = integer_zero_node;
5959 tree binfo;
5960
5961 if (to == from)
5962 return delta;
5963
5964 /* Should get_base_distance here, so we can check if any thing along the
5965 path is virtual, and we need to make sure we stay
5966 inside the real binfos when going through virtual bases.
5967 Maybe we should replace virtual bases with
5968 binfo_member (...CLASSTYPE_VBASECLASSES...)... (mrs) */
5969 binfo = get_binfo (from, to, 1);
5970 if (binfo == error_mark_node)
5971 {
5972 error (" in pointer to member function conversion");
5973 return delta;
5974 }
5975 if (binfo == 0)
5976 {
5977 if (!force)
5978 {
5979 error_not_base_type (from, to);
5980 error (" in pointer to member function conversion");
5981 return delta;
5982 }
5983 binfo = get_binfo (to, from, 1);
5984 if (binfo == error_mark_node)
5985 {
5986 error (" in pointer to member function conversion");
5987 return delta;
5988 }
5989 if (binfo == 0)
5990 {
5991 cp_error ("cannot convert pointer to member of type %T to unrelated pointer to member of type %T", from, to);
5992 return delta;
5993 }
5994 if (TREE_VIA_VIRTUAL (binfo))
5995 {
5996 binfo = binfo_member (BINFO_TYPE (binfo),
5997 CLASSTYPE_VBASECLASSES (from));
5998 warning ("pointer to member conversion to virtual base class will only work if you are very careful");
5999 }
6000 delta = BINFO_OFFSET (binfo);
6001 delta = convert (ptrdiff_type_node, delta);
6002
6003 return build_binary_op (MINUS_EXPR,
6004 integer_zero_node,
6005 delta, 1);
6006 }
6007 if (TREE_VIA_VIRTUAL (binfo))
6008 {
6009 warning ("pointer to member conversion from virtual base class will only work if you are very careful");
6010 }
6011 return BINFO_OFFSET (binfo);
6012 }
6013
6014 static tree
6015 build_ptrmemfunc1 (type, delta, idx, pfn, delta2)
6016 tree type, delta, idx, pfn, delta2;
6017 {
6018 tree u;
6019
6020 #if 0
6021 /* This is the old way we did it. We want to avoid calling
6022 digest_init, so that it can give an error if we use { } when
6023 initializing a pointer to member function. */
6024
6025 if (pfn)
6026 {
6027 u = build_nt (CONSTRUCTOR, NULL_TREE,
6028 tree_cons (pfn_identifier, pfn, NULL_TREE));
6029 }
6030 else
6031 {
6032 u = build_nt (CONSTRUCTOR, NULL_TREE,
6033 tree_cons (delta2_identifier, delta2, NULL_TREE));
6034 }
6035
6036 u = build_nt (CONSTRUCTOR, NULL_TREE,
6037 tree_cons (NULL_TREE, delta,
6038 tree_cons (NULL_TREE, idx,
6039 tree_cons (NULL_TREE, u, NULL_TREE))));
6040
6041 return digest_init (type, u, (tree*)0);
6042 #else
6043 tree delta_field, idx_field, pfn_or_delta2_field, pfn_field, delta2_field;
6044 tree subtype;
6045 int allconstant, allsimple;
6046
6047 delta_field = TYPE_FIELDS (type);
6048 idx_field = TREE_CHAIN (delta_field);
6049 pfn_or_delta2_field = TREE_CHAIN (idx_field);
6050 subtype = TREE_TYPE (pfn_or_delta2_field);
6051 pfn_field = TYPE_FIELDS (subtype);
6052 delta2_field = TREE_CHAIN (pfn_field);
6053
6054 if (pfn)
6055 {
6056 allconstant = TREE_CONSTANT (pfn);
6057 allsimple = initializer_constant_valid_p (pfn, TREE_TYPE (pfn));
6058 u = tree_cons (pfn_field, pfn, NULL_TREE);
6059 }
6060 else
6061 {
6062 delta2 = convert_and_check (delta_type_node, delta2);
6063 allconstant = TREE_CONSTANT (delta2);
6064 allsimple = initializer_constant_valid_p (delta2, TREE_TYPE (delta2));
6065 u = tree_cons (delta2_field, delta2, NULL_TREE);
6066 }
6067
6068 delta = convert_and_check (delta_type_node, delta);
6069 idx = convert_and_check (delta_type_node, idx);
6070
6071 allconstant = allconstant && TREE_CONSTANT (delta) && TREE_CONSTANT (idx);
6072 allsimple = allsimple
6073 && initializer_constant_valid_p (delta, TREE_TYPE (delta))
6074 && initializer_constant_valid_p (idx, TREE_TYPE (idx));
6075
6076 u = build (CONSTRUCTOR, subtype, NULL_TREE, u);
6077 u = tree_cons (delta_field, delta,
6078 tree_cons (idx_field, idx,
6079 tree_cons (pfn_or_delta2_field, u, NULL_TREE)));
6080 u = build (CONSTRUCTOR, type, NULL_TREE, u);
6081 TREE_CONSTANT (u) = allconstant;
6082 TREE_STATIC (u) = allconstant && allsimple;
6083 return u;
6084 #endif
6085 }
6086
6087 /* Build a constructor for a pointer to member function. It can be
6088 used to initialize global variables, local variable, or used
6089 as a value in expressions. TYPE is the POINTER to METHOD_TYPE we
6090 want to be.
6091
6092 If FORCE is non-zero, then force this conversion, even if
6093 we would rather not do it. Usually set when using an explicit
6094 cast.
6095
6096 Return error_mark_node, if something goes wrong. */
6097
6098 tree
6099 build_ptrmemfunc (type, pfn, force)
6100 tree type, pfn;
6101 int force;
6102 {
6103 tree idx = integer_zero_node;
6104 tree delta = integer_zero_node;
6105 tree delta2 = integer_zero_node;
6106 tree vfield_offset;
6107 tree npfn = NULL_TREE;
6108 tree u;
6109
6110 /* Handle multiple conversions of pointer to member functions. */
6111 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (pfn)))
6112 {
6113 tree ndelta, ndelta2, nindex;
6114 tree e1, e2, e3, n;
6115
6116 /* Is is already the right type? */
6117 if (type == TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn)))
6118 return pfn;
6119
6120 ndelta = convert (ptrdiff_type_node, build_component_ref (pfn, delta_identifier, NULL_TREE, 0));
6121 ndelta2 = convert (ptrdiff_type_node, DELTA2_FROM_PTRMEMFUNC (pfn));
6122 idx = build_component_ref (pfn, index_identifier, NULL_TREE, 0);
6123
6124 n = get_delta_difference (TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn)))),
6125 TYPE_METHOD_BASETYPE (TREE_TYPE (type)),
6126 force);
6127
6128 delta = build_binary_op (PLUS_EXPR, ndelta, n, 1);
6129 delta2 = build_binary_op (PLUS_EXPR, ndelta2, n, 1);
6130 e1 = fold (build (GT_EXPR, boolean_type_node, idx, integer_zero_node));
6131
6132 e2 = build_ptrmemfunc1 (TYPE_GET_PTRMEMFUNC_TYPE (type), delta, idx,
6133 NULL_TREE, delta2);
6134
6135 pfn = PFN_FROM_PTRMEMFUNC (pfn);
6136 npfn = build1 (NOP_EXPR, type, pfn);
6137 TREE_CONSTANT (npfn) = TREE_CONSTANT (pfn);
6138
6139 e3 = build_ptrmemfunc1 (TYPE_GET_PTRMEMFUNC_TYPE (type), delta, idx, npfn,
6140 NULL_TREE);
6141 return build_conditional_expr (e1, e2, e3);
6142 }
6143
6144 /* Handle null pointer to member function conversions. */
6145 if (integer_zerop (pfn))
6146 {
6147 pfn = build_c_cast (type, integer_zero_node, 0);
6148 return build_ptrmemfunc1 (TYPE_GET_PTRMEMFUNC_TYPE (type),
6149 integer_zero_node, integer_zero_node,
6150 pfn, NULL_TREE);
6151 }
6152
6153 if (TREE_CODE (pfn) == TREE_LIST
6154 || (TREE_CODE (pfn) == ADDR_EXPR
6155 && TREE_CODE (TREE_OPERAND (pfn, 0)) == TREE_LIST))
6156 {
6157 pfn = instantiate_type (type, pfn, 1);
6158 if (pfn == error_mark_node)
6159 return error_mark_node;
6160 pfn = build_addr_func (pfn);
6161 }
6162
6163 /* Allow pointer to member conversions here. */
6164 delta = get_delta_difference (TYPE_METHOD_BASETYPE (TREE_TYPE (TREE_TYPE (pfn))),
6165 TYPE_METHOD_BASETYPE (TREE_TYPE (type)),
6166 force);
6167 delta2 = build_binary_op (PLUS_EXPR, delta2, delta, 1);
6168
6169 #if 0
6170 /* We need to check the argument types to see if they are compatible
6171 (any const or volatile violations. */
6172 something like this:
6173 comptype (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (type))),
6174 TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (TREE_TYPE (pfn)))), ?);
6175 #endif
6176
6177 if (TREE_CODE (TREE_OPERAND (pfn, 0)) != FUNCTION_DECL)
6178 warning ("assuming pointer to member function is non-virtual");
6179
6180 if (TREE_CODE (TREE_OPERAND (pfn, 0)) == FUNCTION_DECL
6181 && DECL_VINDEX (TREE_OPERAND (pfn, 0)))
6182 {
6183 /* Find the offset to the vfield pointer in the object. */
6184 vfield_offset = get_binfo (DECL_CONTEXT (TREE_OPERAND (pfn, 0)),
6185 DECL_CLASS_CONTEXT (TREE_OPERAND (pfn, 0)),
6186 0);
6187 vfield_offset = get_vfield_offset (vfield_offset);
6188 delta2 = size_binop (PLUS_EXPR, vfield_offset, delta2);
6189
6190 /* Map everything down one to make room for the null pointer to member. */
6191 idx = size_binop (PLUS_EXPR,
6192 DECL_VINDEX (TREE_OPERAND (pfn, 0)),
6193 integer_one_node);
6194 }
6195 else
6196 {
6197 idx = size_binop (MINUS_EXPR, integer_zero_node, integer_one_node);
6198
6199 if (type == TREE_TYPE (pfn))
6200 {
6201 npfn = pfn;
6202 }
6203 else
6204 {
6205 npfn = build1 (NOP_EXPR, type, pfn);
6206 TREE_CONSTANT (npfn) = TREE_CONSTANT (pfn);
6207 }
6208 }
6209
6210 return build_ptrmemfunc1 (TYPE_GET_PTRMEMFUNC_TYPE (type), delta, idx, npfn, delta2);
6211 }
6212
6213 /* Convert value RHS to type TYPE as preparation for an assignment
6214 to an lvalue of type TYPE.
6215 The real work of conversion is done by `convert'.
6216 The purpose of this function is to generate error messages
6217 for assignments that are not allowed in C.
6218 ERRTYPE is a string to use in error messages:
6219 "assignment", "return", etc.
6220
6221 C++: attempts to allow `convert' to find conversions involving
6222 implicit type conversion between aggregate and scalar types
6223 as per 8.5.6 of C++ manual. Does not randomly dereference
6224 pointers to aggregates! */
6225
6226 static tree
6227 convert_for_assignment (type, rhs, errtype, fndecl, parmnum)
6228 tree type, rhs;
6229 char *errtype;
6230 tree fndecl;
6231 int parmnum;
6232 {
6233 register enum tree_code codel = TREE_CODE (type);
6234 register tree rhstype;
6235 register enum tree_code coder = TREE_CODE (TREE_TYPE (rhs));
6236
6237 if (coder == UNKNOWN_TYPE)
6238 rhs = instantiate_type (type, rhs, 1);
6239
6240 if (coder == ERROR_MARK)
6241 return error_mark_node;
6242
6243 if (codel == OFFSET_TYPE)
6244 {
6245 type = TREE_TYPE (type);
6246 codel = TREE_CODE (type);
6247 }
6248
6249 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
6250 if (TREE_CODE (rhs) == NON_LVALUE_EXPR)
6251 rhs = TREE_OPERAND (rhs, 0);
6252
6253 if (rhs == error_mark_node)
6254 return error_mark_node;
6255
6256 if (TREE_VALUE (rhs) == error_mark_node)
6257 return error_mark_node;
6258
6259 if (TREE_CODE (TREE_TYPE (rhs)) == OFFSET_TYPE)
6260 {
6261 rhs = resolve_offset_ref (rhs);
6262 if (rhs == error_mark_node)
6263 return error_mark_node;
6264 rhstype = TREE_TYPE (rhs);
6265 coder = TREE_CODE (rhstype);
6266 }
6267
6268 if (TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE
6269 || TREE_CODE (TREE_TYPE (rhs)) == FUNCTION_TYPE
6270 || TREE_CODE (TREE_TYPE (rhs)) == METHOD_TYPE)
6271 rhs = default_conversion (rhs);
6272 else if (TREE_CODE (TREE_TYPE (rhs)) == REFERENCE_TYPE)
6273 rhs = convert_from_reference (rhs);
6274
6275 rhstype = TREE_TYPE (rhs);
6276 coder = TREE_CODE (rhstype);
6277
6278 /* This should no longer change types on us. */
6279 if (TREE_CODE (rhs) == CONST_DECL)
6280 rhs = DECL_INITIAL (rhs);
6281 else if (TREE_READONLY_DECL_P (rhs))
6282 rhs = decl_constant_value (rhs);
6283
6284 if (type == rhstype)
6285 {
6286 overflow_warning (rhs);
6287 return rhs;
6288 }
6289
6290 if (coder == VOID_TYPE)
6291 {
6292 error ("void value not ignored as it ought to be");
6293 return error_mark_node;
6294 }
6295 /* Arithmetic types all interconvert. */
6296 if ((codel == INTEGER_TYPE || codel == REAL_TYPE || codel == BOOLEAN_TYPE)
6297 && (coder == INTEGER_TYPE || coder == REAL_TYPE || coder == BOOLEAN_TYPE))
6298 {
6299 /* But we should warn if assigning REAL_TYPE to INTEGER_TYPE. */
6300 if (coder == REAL_TYPE && codel == INTEGER_TYPE)
6301 {
6302 if (fndecl)
6303 cp_warning ("`%T' used for argument %P of `%D'",
6304 rhstype, parmnum, fndecl);
6305 else
6306 cp_warning ("%s to `%T' from `%T'", errtype, type, rhstype);
6307 }
6308 /* And we should warn if assigning a negative value to
6309 an unsigned variable. */
6310 else if (TREE_UNSIGNED (type) && codel != BOOLEAN_TYPE)
6311 {
6312 if (TREE_CODE (rhs) == INTEGER_CST
6313 && TREE_NEGATED_INT (rhs))
6314 {
6315 if (fndecl)
6316 cp_warning ("negative value `%E' passed as argument %P of `%D'",
6317 rhs, parmnum, fndecl);
6318 else
6319 cp_warning ("%s of negative value `%E' to `%T'",
6320 errtype, rhs, type);
6321 }
6322 overflow_warning (rhs);
6323 if (TREE_CONSTANT (rhs))
6324 rhs = fold (rhs);
6325 }
6326
6327 return convert_and_check (type, rhs);
6328 }
6329 /* Conversions involving enums. */
6330 else if ((codel == ENUMERAL_TYPE
6331 && (INTEGRAL_CODE_P (coder) || coder == REAL_TYPE))
6332 || (coder == ENUMERAL_TYPE
6333 && (INTEGRAL_CODE_P (codel) || codel == REAL_TYPE)))
6334 {
6335 return cp_convert (type, rhs, CONV_IMPLICIT, LOOKUP_NORMAL);
6336 }
6337 /* Conversions among pointers */
6338 else if (codel == POINTER_TYPE
6339 && (coder == POINTER_TYPE
6340 || (coder == RECORD_TYPE
6341 && (IS_SIGNATURE_POINTER (rhstype)
6342 || IS_SIGNATURE_REFERENCE (rhstype)))))
6343 {
6344 register tree ttl = TREE_TYPE (type);
6345 register tree ttr;
6346 int ctt = 0;
6347
6348 if (coder == RECORD_TYPE)
6349 {
6350 rhs = build_optr_ref (rhs);
6351 rhstype = TREE_TYPE (rhs);
6352 }
6353 ttr = TREE_TYPE (rhstype);
6354
6355 /* If both pointers are of aggregate type, then we
6356 can give better error messages, and save some work
6357 as well. */
6358 if (TREE_CODE (ttl) == RECORD_TYPE && TREE_CODE (ttr) == RECORD_TYPE)
6359 {
6360 tree binfo;
6361
6362 if (TYPE_MAIN_VARIANT (ttl) == TYPE_MAIN_VARIANT (ttr)
6363 || type == class_star_type_node
6364 || rhstype == class_star_type_node)
6365 binfo = TYPE_BINFO (ttl);
6366 else
6367 binfo = get_binfo (ttl, ttr, 1);
6368
6369 if (binfo == error_mark_node)
6370 return error_mark_node;
6371 if (binfo == 0)
6372 return error_not_base_type (ttl, ttr);
6373
6374 if (! TYPE_READONLY (ttl) && TYPE_READONLY (ttr))
6375 {
6376 if (fndecl)
6377 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6378 rhstype, parmnum, fndecl);
6379 else
6380 cp_pedwarn ("%s to `%T' from `%T' discards const",
6381 errtype, type, rhstype);
6382 }
6383 if (! TYPE_VOLATILE (ttl) && TYPE_VOLATILE (ttr))
6384 {
6385 if (fndecl)
6386 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6387 rhstype, parmnum, fndecl);
6388 else
6389 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6390 errtype, type, rhstype);
6391 }
6392 }
6393
6394 /* Any non-function converts to a [const][volatile] void *
6395 and vice versa; otherwise, targets must be the same.
6396 Meanwhile, the lhs target must have all the qualifiers of the rhs. */
6397 else if (TYPE_MAIN_VARIANT (ttl) == void_type_node
6398 || TYPE_MAIN_VARIANT (ttr) == void_type_node
6399 || (ctt = comp_target_types (type, rhstype, 1))
6400 || (unsigned_type (TYPE_MAIN_VARIANT (ttl))
6401 == unsigned_type (TYPE_MAIN_VARIANT (ttr))))
6402 {
6403 /* ARM $4.8, commentary on p39. */
6404 if (TYPE_MAIN_VARIANT (ttl) == void_type_node
6405 && TREE_CODE (ttr) == OFFSET_TYPE)
6406 {
6407 cp_error ("no standard conversion from `%T' to `void *'", ttr);
6408 return error_mark_node;
6409 }
6410
6411 if (ctt < 0)
6412 cp_pedwarn ("converting `%T' to `%T' is a contravariance violation",
6413 rhstype, type);
6414
6415 if (TYPE_MAIN_VARIANT (ttl) != void_type_node
6416 && TYPE_MAIN_VARIANT (ttr) == void_type_node
6417 && rhs != null_pointer_node)
6418 {
6419 if (coder == RECORD_TYPE)
6420 cp_pedwarn ("implicit conversion of signature pointer to type `%T'",
6421 type);
6422 else
6423 pedwarn ("ANSI C++ forbids implicit conversion from `void *' in %s",
6424 errtype);
6425 }
6426 /* Const and volatile mean something different for function types,
6427 so the usual warnings are not appropriate. */
6428 else if ((TREE_CODE (ttr) != FUNCTION_TYPE && TREE_CODE (ttr) != METHOD_TYPE)
6429 || (TREE_CODE (ttl) != FUNCTION_TYPE && TREE_CODE (ttl) != METHOD_TYPE))
6430 {
6431 if (TREE_CODE (ttl) == OFFSET_TYPE
6432 && binfo_member (TYPE_OFFSET_BASETYPE (ttr),
6433 CLASSTYPE_VBASECLASSES (TYPE_OFFSET_BASETYPE (ttl))))
6434 {
6435 sorry ("%s between pointer to members converting across virtual baseclasses", errtype);
6436 return error_mark_node;
6437 }
6438 else if (! TYPE_READONLY (ttl) && TYPE_READONLY (ttr))
6439 {
6440 if (fndecl)
6441 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6442 rhstype, parmnum, fndecl);
6443 else
6444 cp_pedwarn ("%s to `%T' from `%T' discards const",
6445 errtype, type, rhstype);
6446 }
6447 else if (! TYPE_VOLATILE (ttl) && TYPE_VOLATILE (ttr))
6448 {
6449 if (fndecl)
6450 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6451 rhstype, parmnum, fndecl);
6452 else
6453 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6454 errtype, type, rhstype);
6455 }
6456 else if (TREE_CODE (ttl) == TREE_CODE (ttr)
6457 && ! comp_target_types (type, rhstype, 1))
6458 {
6459 if (fndecl)
6460 cp_pedwarn ("passing `%T' as argument %P of `%D' changes signedness",
6461 rhstype, parmnum, fndecl);
6462 else
6463 cp_pedwarn ("%s to `%T' from `%T' changes signedness",
6464 errtype, type, rhstype);
6465 }
6466 }
6467 }
6468 else if (TREE_CODE (ttr) == OFFSET_TYPE
6469 && TREE_CODE (ttl) != OFFSET_TYPE)
6470 {
6471 /* Normally, pointers to different type codes (other
6472 than void) are not compatible, but we perform
6473 some type instantiation if that resolves the
6474 ambiguity of (X Y::*) and (X *). */
6475
6476 if (current_class_ptr)
6477 {
6478 if (TREE_CODE (rhs) == INTEGER_CST)
6479 {
6480 rhs = build (PLUS_EXPR, build_pointer_type (TREE_TYPE (ttr)),
6481 current_class_ptr, rhs);
6482 return convert_for_assignment (type, rhs,
6483 errtype, fndecl, parmnum);
6484 }
6485 }
6486 if (TREE_CODE (ttl) == METHOD_TYPE)
6487 error ("%s between pointer-to-method and pointer-to-member types",
6488 errtype);
6489 else
6490 error ("%s between pointer and pointer-to-member types", errtype);
6491 return error_mark_node;
6492 }
6493 else
6494 {
6495 int add_quals = 0, const_parity = 0, volatile_parity = 0;
6496 int left_const = 1;
6497 int unsigned_parity;
6498 int nptrs = 0;
6499
6500 /* This code is basically a duplicate of comp_ptr_ttypes_real. */
6501 for (; ; ttl = TREE_TYPE (ttl), ttr = TREE_TYPE (ttr))
6502 {
6503 nptrs -= 1;
6504 const_parity |= (TYPE_READONLY (ttl) < TYPE_READONLY (ttr));
6505 volatile_parity |= (TYPE_VOLATILE (ttl) < TYPE_VOLATILE (ttr));
6506
6507 if (! left_const
6508 && (TYPE_READONLY (ttl) > TYPE_READONLY (ttr)
6509 || TYPE_VOLATILE (ttl) > TYPE_VOLATILE (ttr)))
6510 add_quals = 1;
6511 left_const &= TYPE_READONLY (ttl);
6512
6513 if (TREE_CODE (ttl) != POINTER_TYPE
6514 || TREE_CODE (ttr) != POINTER_TYPE)
6515 break;
6516 }
6517 unsigned_parity = TREE_UNSIGNED (ttl) - TREE_UNSIGNED (ttr);
6518 if (unsigned_parity)
6519 {
6520 if (TREE_UNSIGNED (ttl))
6521 ttr = unsigned_type (ttr);
6522 else
6523 ttl = unsigned_type (ttl);
6524 }
6525
6526 if (comp_target_types (ttl, ttr, nptrs) > 0)
6527 {
6528 if (add_quals)
6529 {
6530 if (fndecl)
6531 cp_pedwarn ("passing `%T' as argument %P of `%D' adds cv-quals without intervening `const'",
6532 rhstype, parmnum, fndecl);
6533 else
6534 cp_pedwarn ("%s to `%T' from `%T' adds cv-quals without intervening `const'",
6535 errtype, type, rhstype);
6536 }
6537 if (const_parity)
6538 {
6539 if (fndecl)
6540 cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
6541 rhstype, parmnum, fndecl);
6542 else
6543 cp_pedwarn ("%s to `%T' from `%T' discards const",
6544 errtype, type, rhstype);
6545 }
6546 if (volatile_parity)
6547 {
6548 if (fndecl)
6549 cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
6550 rhstype, parmnum, fndecl);
6551 else
6552 cp_pedwarn ("%s to `%T' from `%T' discards volatile",
6553 errtype, type, rhstype);
6554 }
6555 if (unsigned_parity > 0)
6556 {
6557 if (fndecl)
6558 cp_pedwarn ("passing `%T' as argument %P of `%D' changes signed to unsigned",
6559 rhstype, parmnum, fndecl);
6560 else
6561 cp_pedwarn ("%s to `%T' from `%T' changes signed to unsigned",
6562 errtype, type, rhstype);
6563 }
6564 else if (unsigned_parity < 0)
6565 {
6566 if (fndecl)
6567 cp_pedwarn ("passing `%T' as argument %P of `%D' changes unsigned to signed",
6568 rhstype, parmnum, fndecl);
6569 else
6570 cp_pedwarn ("%s to `%T' from `%T' changes unsigned to signed",
6571 errtype, type, rhstype);
6572 }
6573
6574 /* C++ is not so friendly about converting function and
6575 member function pointers as C. Emit warnings here. */
6576 if (TREE_CODE (ttl) == FUNCTION_TYPE
6577 || TREE_CODE (ttl) == METHOD_TYPE)
6578 if (! comptypes (ttl, ttr, 0))
6579 {
6580 warning ("conflicting function types in %s:", errtype);
6581 cp_warning ("\t`%T' != `%T'", type, rhstype);
6582 }
6583 }
6584 else
6585 {
6586 if (fndecl)
6587 cp_error ("passing `%T' as argument %P of `%D'",
6588 rhstype, parmnum, fndecl);
6589 else
6590 cp_error ("%s to `%T' from `%T'", errtype, type, rhstype);
6591 return error_mark_node;
6592 }
6593 }
6594 return convert (type, rhs);
6595 }
6596 else if (codel == POINTER_TYPE && coder == INTEGER_TYPE)
6597 {
6598 /* An explicit constant 0 can convert to a pointer,
6599 but not a 0 that results from casting or folding. */
6600 if (! (TREE_CODE (rhs) == INTEGER_CST && integer_zerop (rhs)))
6601 {
6602 if (fndecl)
6603 cp_pedwarn ("passing `%T' to argument %P of `%D' lacks a cast",
6604 rhstype, parmnum, fndecl);
6605 else
6606 cp_pedwarn ("%s to `%T' from `%T' lacks a cast",
6607 errtype, type, rhstype);
6608 return convert (type, rhs);
6609 }
6610 return null_pointer_node;
6611 }
6612 else if (codel == INTEGER_TYPE
6613 && (coder == POINTER_TYPE
6614 || (coder == RECORD_TYPE
6615 && (IS_SIGNATURE_POINTER (rhstype)
6616 || TYPE_PTRMEMFUNC_FLAG (rhstype)
6617 || IS_SIGNATURE_REFERENCE (rhstype)))))
6618 {
6619 if (fndecl)
6620 cp_pedwarn ("passing `%T' to argument %P of `%D' lacks a cast",
6621 rhstype, parmnum, fndecl);
6622 else
6623 cp_pedwarn ("%s to `%T' from `%T' lacks a cast",
6624 errtype, type, rhstype);
6625 return convert (type, rhs);
6626 }
6627 else if (codel == BOOLEAN_TYPE
6628 && (coder == POINTER_TYPE
6629 || (coder == RECORD_TYPE
6630 && (IS_SIGNATURE_POINTER (rhstype)
6631 || TYPE_PTRMEMFUNC_FLAG (rhstype)
6632 || IS_SIGNATURE_REFERENCE (rhstype)))))
6633 return convert (type, rhs);
6634
6635 /* C++ */
6636 else if (((coder == POINTER_TYPE
6637 && TREE_CODE (TREE_TYPE (rhstype)) == METHOD_TYPE)
6638 || integer_zerop (rhs)
6639 || TYPE_PTRMEMFUNC_P (rhstype))
6640 && TYPE_PTRMEMFUNC_P (type))
6641 {
6642 tree ttl = TYPE_PTRMEMFUNC_FN_TYPE (type);
6643 tree ttr = (TREE_CODE (rhstype) == POINTER_TYPE ? rhstype
6644 : TYPE_PTRMEMFUNC_FN_TYPE (type));
6645 int ctt = comp_target_types (ttl, ttr, 1);
6646
6647 if (ctt < 0)
6648 cp_pedwarn ("converting `%T' to `%T' is a contravariance violation",
6649 ttr, ttl);
6650 else if (ctt == 0)
6651 cp_error ("%s to `%T' from `%T'", errtype, ttl, ttr);
6652
6653 /* compatible pointer to member functions. */
6654 return build_ptrmemfunc (ttl, rhs, 0);
6655 }
6656 else if (codel == ERROR_MARK || coder == ERROR_MARK)
6657 return error_mark_node;
6658
6659 /* This should no longer happen. References are initialized via
6660 `convert_for_initialization'. They should otherwise be
6661 bashed before coming here. */
6662 else if (codel == REFERENCE_TYPE)
6663 my_friendly_abort (317);
6664 else if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (TREE_TYPE (rhs)))
6665 {
6666 tree nrhs = build1 (NOP_EXPR, type, rhs);
6667 TREE_CONSTANT (nrhs) = TREE_CONSTANT (rhs);
6668 return nrhs;
6669 }
6670 else if (TYPE_HAS_CONSTRUCTOR (type) || IS_AGGR_TYPE (TREE_TYPE (rhs)))
6671 return convert (type, rhs);
6672
6673 cp_error ("%s to `%T' from `%T'", errtype, type, rhstype);
6674 return error_mark_node;
6675 }
6676
6677 /* Convert RHS to be of type TYPE. If EXP is non-zero,
6678 it is the target of the initialization.
6679 ERRTYPE is a string to use in error messages.
6680
6681 Two major differences between the behavior of
6682 `convert_for_assignment' and `convert_for_initialization'
6683 are that references are bashed in the former, while
6684 copied in the latter, and aggregates are assigned in
6685 the former (operator=) while initialized in the
6686 latter (X(X&)).
6687
6688 If using constructor make sure no conversion operator exists, if one does
6689 exist, an ambiguity exists.
6690
6691 If flags doesn't include LOOKUP_COMPLAIN, don't complain about anything. */
6692
6693 tree
6694 convert_for_initialization (exp, type, rhs, flags, errtype, fndecl, parmnum)
6695 tree exp, type, rhs;
6696 int flags;
6697 char *errtype;
6698 tree fndecl;
6699 int parmnum;
6700 {
6701 register enum tree_code codel = TREE_CODE (type);
6702 register tree rhstype;
6703 register enum tree_code coder;
6704
6705 /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
6706 Strip such NOP_EXPRs, since RHS is used in non-lvalue context. */
6707 if (TREE_CODE (rhs) == NOP_EXPR
6708 && TREE_TYPE (rhs) == TREE_TYPE (TREE_OPERAND (rhs, 0))
6709 && codel != REFERENCE_TYPE)
6710 rhs = TREE_OPERAND (rhs, 0);
6711
6712 if (rhs == error_mark_node
6713 || (TREE_CODE (rhs) == TREE_LIST && TREE_VALUE (rhs) == error_mark_node))
6714 return error_mark_node;
6715
6716 if (TREE_CODE (TREE_TYPE (rhs)) == OFFSET_TYPE)
6717 {
6718 rhs = resolve_offset_ref (rhs);
6719 if (rhs == error_mark_node)
6720 return error_mark_node;
6721 }
6722
6723 if (TREE_CODE (TREE_TYPE (rhs)) == REFERENCE_TYPE)
6724 rhs = convert_from_reference (rhs);
6725
6726 if ((TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE
6727 && TREE_CODE (type) != ARRAY_TYPE
6728 && (TREE_CODE (type) != REFERENCE_TYPE
6729 || TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE))
6730 || TREE_CODE (TREE_TYPE (rhs)) == FUNCTION_TYPE
6731 || TREE_CODE (TREE_TYPE (rhs)) == METHOD_TYPE)
6732 rhs = default_conversion (rhs);
6733
6734 rhstype = TREE_TYPE (rhs);
6735 coder = TREE_CODE (rhstype);
6736
6737 if (coder == UNKNOWN_TYPE)
6738 {
6739 rhs = instantiate_type (type, rhs, 1);
6740 rhstype = TREE_TYPE (rhs);
6741 coder = TREE_CODE (rhstype);
6742 }
6743
6744 if (coder == ERROR_MARK)
6745 return error_mark_node;
6746
6747 /* We accept references to incomplete types, so we can
6748 return here before checking if RHS is of complete type. */
6749
6750 if (codel == REFERENCE_TYPE)
6751 {
6752 /* This should eventually happen in convert_arguments. */
6753 extern int warningcount, errorcount;
6754 int savew, savee;
6755
6756 if (fndecl)
6757 savew = warningcount, savee = errorcount;
6758 rhs = convert_to_reference (type, rhs, CONV_IMPLICIT, flags,
6759 exp ? exp : error_mark_node);
6760 if (fndecl)
6761 {
6762 if (warningcount > savew)
6763 cp_warning_at ("in passing argument %P of `%+D'", parmnum, fndecl);
6764 else if (errorcount > savee)
6765 cp_error_at ("in passing argument %P of `%+D'", parmnum, fndecl);
6766 }
6767 return rhs;
6768 }
6769
6770 rhs = require_complete_type (rhs);
6771 if (rhs == error_mark_node)
6772 return error_mark_node;
6773
6774 if (exp != 0) exp = require_complete_type (exp);
6775 if (exp == error_mark_node)
6776 return error_mark_node;
6777
6778 if (TREE_CODE (rhstype) == REFERENCE_TYPE)
6779 rhstype = TREE_TYPE (rhstype);
6780
6781 if (TYPE_LANG_SPECIFIC (type)
6782 && (IS_SIGNATURE_POINTER (type) || IS_SIGNATURE_REFERENCE (type)))
6783 return build_signature_pointer_constructor (type, rhs);
6784
6785 if (IS_AGGR_TYPE (type)
6786 && (TYPE_NEEDS_CONSTRUCTING (type) || TREE_HAS_CONSTRUCTOR (rhs)))
6787 {
6788 if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype))
6789 {
6790 /* This is sufficient to perform initialization. No need,
6791 apparently, to go through X(X&) to do first-cut
6792 initialization. Return through a TARGET_EXPR so that we get
6793 cleanups if it is used. */
6794 if (TREE_CODE (rhs) == CALL_EXPR)
6795 {
6796 rhs = build_cplus_new (type, rhs);
6797 return rhs;
6798 }
6799 /* Handle the case of default parameter initialization and
6800 initialization of static variables. */
6801 else if (TREE_CODE (rhs) == TARGET_EXPR)
6802 return rhs;
6803 else if (TREE_CODE (rhs) == INDIRECT_REF && TREE_HAS_CONSTRUCTOR (rhs))
6804 {
6805 my_friendly_assert (TREE_CODE (TREE_OPERAND (rhs, 0)) == CALL_EXPR, 318);
6806 if (exp)
6807 {
6808 my_friendly_assert (TREE_VALUE (TREE_OPERAND (TREE_OPERAND (rhs, 0), 1)) == NULL_TREE, 316);
6809 TREE_VALUE (TREE_OPERAND (TREE_OPERAND (rhs, 0), 1))
6810 = build_unary_op (ADDR_EXPR, exp, 0);
6811 }
6812 else
6813 rhs = build_cplus_new (type, TREE_OPERAND (rhs, 0));
6814 return rhs;
6815 }
6816 else if (TYPE_HAS_TRIVIAL_INIT_REF (type))
6817 return rhs;
6818 }
6819 if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype)
6820 || (IS_AGGR_TYPE (rhstype) && UNIQUELY_DERIVED_FROM_P (type, rhstype)))
6821 {
6822 if (TYPE_HAS_INIT_REF (type))
6823 {
6824 tree init = build_method_call (exp, ctor_identifier,
6825 build_tree_list (NULL_TREE, rhs),
6826 TYPE_BINFO (type), LOOKUP_NORMAL);
6827
6828 if (init == error_mark_node)
6829 return error_mark_node;
6830
6831 if (exp == 0)
6832 {
6833 exp = build_cplus_new (type, init);
6834 return exp;
6835 }
6836
6837 return build (COMPOUND_EXPR, type, init, exp);
6838 }
6839
6840 /* ??? The following warnings are turned off because
6841 this is another place where the default X(X&) constructor
6842 is implemented. */
6843 if (TYPE_HAS_ASSIGNMENT (type))
6844 cp_warning ("bitwise copy: `%T' defines operator=", type);
6845
6846 if (TREE_CODE (TREE_TYPE (rhs)) == REFERENCE_TYPE)
6847 rhs = convert_from_reference (rhs);
6848 if (type != rhstype)
6849 {
6850 tree nrhs = build1 (NOP_EXPR, type, rhs);
6851 TREE_CONSTANT (nrhs) = TREE_CONSTANT (rhs);
6852 rhs = nrhs;
6853 }
6854 return rhs;
6855 }
6856
6857 return cp_convert (type, rhs, CONV_OLD_CONVERT,
6858 flags | LOOKUP_NO_CONVERSION);
6859 }
6860
6861 if (type == TREE_TYPE (rhs))
6862 {
6863 if (TREE_READONLY_DECL_P (rhs))
6864 rhs = decl_constant_value (rhs);
6865 return rhs;
6866 }
6867
6868 return convert_for_assignment (type, rhs, errtype, fndecl, parmnum);
6869 }
6870 \f
6871 /* Expand an ASM statement with operands, handling output operands
6872 that are not variables or INDIRECT_REFS by transforming such
6873 cases into cases that expand_asm_operands can handle.
6874
6875 Arguments are same as for expand_asm_operands.
6876
6877 We don't do default conversions on all inputs, because it can screw
6878 up operands that are expected to be in memory. */
6879
6880 void
6881 c_expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line)
6882 tree string, outputs, inputs, clobbers;
6883 int vol;
6884 char *filename;
6885 int line;
6886 {
6887 int noutputs = list_length (outputs);
6888 register int i;
6889 /* o[I] is the place that output number I should be written. */
6890 register tree *o = (tree *) alloca (noutputs * sizeof (tree));
6891 register tree tail;
6892
6893 /* Record the contents of OUTPUTS before it is modified. */
6894 for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
6895 o[i] = TREE_VALUE (tail);
6896
6897 /* Generate the ASM_OPERANDS insn;
6898 store into the TREE_VALUEs of OUTPUTS some trees for
6899 where the values were actually stored. */
6900 expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line);
6901
6902 /* Copy all the intermediate outputs into the specified outputs. */
6903 for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
6904 {
6905 if (o[i] != TREE_VALUE (tail))
6906 {
6907 expand_expr (build_modify_expr (o[i], NOP_EXPR, TREE_VALUE (tail)),
6908 const0_rtx, VOIDmode, 0);
6909 free_temp_slots ();
6910 }
6911 /* Detect modification of read-only values.
6912 (Otherwise done by build_modify_expr.) */
6913 else
6914 {
6915 tree type = TREE_TYPE (o[i]);
6916 if (TYPE_READONLY (type)
6917 || ((TREE_CODE (type) == RECORD_TYPE
6918 || TREE_CODE (type) == UNION_TYPE)
6919 && C_TYPE_FIELDS_READONLY (type)))
6920 readonly_error (o[i], "modification by `asm'", 1);
6921 }
6922 }
6923
6924 /* Those MODIFY_EXPRs could do autoincrements. */
6925 emit_queue ();
6926 }
6927 \f
6928 /* Expand a C `return' statement.
6929 RETVAL is the expression for what to return,
6930 or a null pointer for `return;' with no value.
6931
6932 C++: upon seeing a `return', we must call destructors on all
6933 variables in scope which had constructors called on them.
6934 This means that if in a destructor, the base class destructors
6935 must be called before returning.
6936
6937 The RETURN statement in C++ has initialization semantics. */
6938
6939 void
6940 c_expand_return (retval)
6941 tree retval;
6942 {
6943 extern struct nesting *cond_stack, *loop_stack, *case_stack;
6944 extern tree dtor_label, ctor_label;
6945 tree result = DECL_RESULT (current_function_decl);
6946 tree valtype = TREE_TYPE (result);
6947 int returns_value = 1;
6948
6949 if (TREE_THIS_VOLATILE (current_function_decl))
6950 warning ("function declared `noreturn' has a `return' statement");
6951
6952 if (retval == error_mark_node)
6953 {
6954 current_function_returns_null = 1;
6955 return;
6956 }
6957
6958 if (current_template_parms)
6959 {
6960 add_tree (build_min_nt (RETURN_STMT, retval));
6961 return;
6962 }
6963
6964 if (retval == NULL_TREE)
6965 {
6966 /* A non-named return value does not count. */
6967
6968 /* Can't just return from a destructor. */
6969 if (dtor_label)
6970 {
6971 expand_goto (dtor_label);
6972 return;
6973 }
6974
6975 if (DECL_CONSTRUCTOR_P (current_function_decl))
6976 retval = current_class_ptr;
6977 else if (DECL_NAME (result) != NULL_TREE
6978 && TREE_CODE (valtype) != VOID_TYPE)
6979 retval = result;
6980 else
6981 {
6982 current_function_returns_null = 1;
6983
6984 if (valtype != NULL_TREE && TREE_CODE (valtype) != VOID_TYPE)
6985 {
6986 if (DECL_NAME (DECL_RESULT (current_function_decl)) == NULL_TREE)
6987 {
6988 pedwarn ("`return' with no value, in function returning non-void");
6989 /* Clear this, so finish_function won't say that we
6990 reach the end of a non-void function (which we don't,
6991 we gave a return!). */
6992 current_function_returns_null = 0;
6993 }
6994 }
6995
6996 expand_null_return ();
6997 return;
6998 }
6999 }
7000 else if (DECL_CONSTRUCTOR_P (current_function_decl)
7001 && retval != current_class_ptr)
7002 {
7003 error ("return from a constructor: use `this = ...' instead");
7004 retval = current_class_ptr;
7005 }
7006
7007 if (valtype == NULL_TREE || TREE_CODE (valtype) == VOID_TYPE)
7008 {
7009 current_function_returns_null = 1;
7010 /* We do this here so we'll avoid a warning about how the function
7011 "may or may not return a value" in finish_function. */
7012 returns_value = 0;
7013
7014 if (retval)
7015 pedwarn ("`return' with a value, in function returning void");
7016 expand_return (retval);
7017 }
7018 /* Add some useful error checking for C++. */
7019 else if (TREE_CODE (valtype) == REFERENCE_TYPE)
7020 {
7021 tree whats_returned;
7022 tree tmp_result = result;
7023
7024 /* Don't initialize directly into a non-BLKmode retval, since that
7025 could lose when being inlined by another caller. (GCC can't
7026 read the function return register in an inline function when
7027 the return value is being ignored). */
7028 if (result && TYPE_MODE (TREE_TYPE (tmp_result)) != BLKmode)
7029 tmp_result = 0;
7030
7031 /* convert to reference now, so we can give error if we
7032 return an reference to a non-lvalue. */
7033 retval = convert_for_initialization (tmp_result, valtype, retval,
7034 LOOKUP_NORMAL, "return",
7035 NULL_TREE, 0);
7036
7037 /* Sort through common things to see what it is
7038 we are returning. */
7039 whats_returned = retval;
7040 if (TREE_CODE (whats_returned) == COMPOUND_EXPR)
7041 {
7042 whats_returned = TREE_OPERAND (whats_returned, 1);
7043 if (TREE_CODE (whats_returned) == ADDR_EXPR)
7044 whats_returned = TREE_OPERAND (whats_returned, 0);
7045 }
7046 if (TREE_CODE (whats_returned) == ADDR_EXPR)
7047 {
7048 whats_returned = TREE_OPERAND (whats_returned, 0);
7049 while (TREE_CODE (whats_returned) == NEW_EXPR
7050 || TREE_CODE (whats_returned) == TARGET_EXPR)
7051 {
7052 /* Get the target. */
7053 whats_returned = TREE_OPERAND (whats_returned, 0);
7054 warning ("returning reference to temporary");
7055 }
7056 }
7057
7058 if (TREE_CODE (whats_returned) == VAR_DECL && DECL_NAME (whats_returned))
7059 {
7060 if (TEMP_NAME_P (DECL_NAME (whats_returned)))
7061 warning ("reference to non-lvalue returned");
7062 else if (! TREE_STATIC (whats_returned)
7063 && IDENTIFIER_LOCAL_VALUE (DECL_NAME (whats_returned))
7064 && !TREE_PUBLIC (whats_returned))
7065 cp_warning_at ("reference to local variable `%D' returned", whats_returned);
7066 }
7067 }
7068 else if (TREE_CODE (retval) == ADDR_EXPR)
7069 {
7070 tree whats_returned = TREE_OPERAND (retval, 0);
7071
7072 if (TREE_CODE (whats_returned) == VAR_DECL
7073 && DECL_NAME (whats_returned)
7074 && IDENTIFIER_LOCAL_VALUE (DECL_NAME (whats_returned))
7075 && !TREE_STATIC (whats_returned)
7076 && !TREE_PUBLIC (whats_returned))
7077 cp_warning_at ("address of local variable `%D' returned", whats_returned);
7078 }
7079 else if (TREE_CODE (retval) == VAR_DECL)
7080 {
7081 if (TREE_CODE (TREE_TYPE (retval)) == ARRAY_TYPE
7082 && DECL_NAME (retval)
7083 && IDENTIFIER_LOCAL_VALUE (DECL_NAME (retval))
7084 && !TREE_STATIC (retval)
7085 && !TREE_PUBLIC (retval))
7086 cp_warning_at ("address of local array `%D' returned", retval);
7087 }
7088
7089 /* Now deal with possible C++ hair:
7090 (1) Compute the return value.
7091 (2) If there are aggregate values with destructors which
7092 must be cleaned up, clean them (taking care
7093 not to clobber the return value).
7094 (3) If an X(X&) constructor is defined, the return
7095 value must be returned via that. */
7096
7097 /* If we're returning in a register, we can't initialize the
7098 return value from a TARGET_EXPR. */
7099 if (TREE_CODE (retval) == TARGET_EXPR
7100 && TYPE_MAIN_VARIANT (TREE_TYPE (retval)) == TYPE_MAIN_VARIANT (valtype)
7101 && ! current_function_returns_struct)
7102 retval = expand_target_expr (retval);
7103
7104 if (retval == result
7105 /* Watch out for constructors, which "return" aggregates
7106 via initialization, but which otherwise "return" a pointer. */
7107 || DECL_CONSTRUCTOR_P (current_function_decl))
7108 {
7109 /* This is just an error--it's already been reported. */
7110 if (TYPE_SIZE (valtype) == NULL_TREE)
7111 return;
7112
7113 if (TYPE_MODE (valtype) != BLKmode
7114 && any_pending_cleanups (1))
7115 retval = get_temp_regvar (valtype, retval);
7116 }
7117 else if (IS_AGGR_TYPE (valtype) && current_function_returns_struct)
7118 {
7119 expand_aggr_init (result, retval, 0, LOOKUP_ONLYCONVERTING);
7120 expand_cleanups_to (NULL_TREE);
7121 DECL_INITIAL (result) = NULL_TREE;
7122 retval = 0;
7123 }
7124 else
7125 {
7126 if (TYPE_MODE (valtype) == VOIDmode)
7127 {
7128 if (TYPE_MODE (TREE_TYPE (result)) != VOIDmode
7129 && warn_return_type)
7130 warning ("return of void value in function returning non-void");
7131 expand_expr_stmt (retval);
7132 retval = 0;
7133 result = 0;
7134 }
7135 else if (TYPE_MODE (valtype) != BLKmode
7136 && any_pending_cleanups (1))
7137 {
7138 retval = get_temp_regvar (valtype, retval);
7139 expand_cleanups_to (NULL_TREE);
7140 result = 0;
7141 }
7142 else
7143 {
7144 /* We already did this above, don't do it again. */
7145 if (TREE_CODE (valtype) != REFERENCE_TYPE)
7146 retval = convert_for_initialization (result, valtype, retval,
7147 LOOKUP_NORMAL,
7148 "return", NULL_TREE, 0);
7149 DECL_INITIAL (result) = NULL_TREE;
7150 }
7151 if (retval == error_mark_node)
7152 return;
7153 }
7154
7155 emit_queue ();
7156
7157 if (retval != NULL_TREE
7158 && TREE_CODE_CLASS (TREE_CODE (retval)) == 'd'
7159 && cond_stack == 0 && loop_stack == 0 && case_stack == 0)
7160 current_function_return_value = retval;
7161
7162 if (result)
7163 {
7164 /* Everything's great--RETVAL is in RESULT. */
7165 if (original_result_rtx)
7166 {
7167 store_expr (result, original_result_rtx, 0);
7168 expand_cleanups_to (NULL_TREE);
7169 use_variable (DECL_RTL (result));
7170 if (ctor_label && TREE_CODE (ctor_label) != ERROR_MARK)
7171 expand_goto (ctor_label);
7172 else
7173 expand_null_return ();
7174 }
7175 else if (retval && retval != result)
7176 {
7177 /* Clear this out so the later call to decl_function_context
7178 won't end up bombing on us. */
7179 if (DECL_CONTEXT (result) == error_mark_node)
7180 DECL_CONTEXT (result) = NULL_TREE;
7181 /* Here is where we finally get RETVAL into RESULT.
7182 `expand_return' does the magic of protecting
7183 RESULT from cleanups. */
7184 retval = fold (build1 (CLEANUP_POINT_EXPR, TREE_TYPE (result),
7185 retval));
7186 /* This part _must_ come second, because expand_return looks for
7187 the INIT_EXPR as the toplevel node only. :-( */
7188 retval = build (INIT_EXPR, TREE_TYPE (result), result, retval);
7189 TREE_SIDE_EFFECTS (retval) = 1;
7190 expand_return (retval);
7191 }
7192 else
7193 expand_return (result);
7194 }
7195 else
7196 {
7197 /* We may still need to put RETVAL into RESULT. */
7198 result = DECL_RESULT (current_function_decl);
7199 if (original_result_rtx)
7200 {
7201 /* Here we have a named return value that went
7202 into memory. We can compute RETVAL into that. */
7203 if (retval)
7204 expand_assignment (result, retval, 0, 0);
7205 else
7206 store_expr (result, original_result_rtx, 0);
7207 result = make_tree (TREE_TYPE (result), original_result_rtx);
7208 }
7209 else if (ctor_label && TREE_CODE (ctor_label) != ERROR_MARK)
7210 {
7211 /* Here RETVAL is CURRENT_CLASS_PTR, so there's nothing to do. */
7212 expand_goto (ctor_label);
7213 }
7214 else if (retval)
7215 {
7216 /* Here is where we finally get RETVAL into RESULT.
7217 `expand_return' does the magic of protecting
7218 RESULT from cleanups. */
7219 result = build (INIT_EXPR, TREE_TYPE (result), result, retval);
7220 TREE_SIDE_EFFECTS (result) = 1;
7221 expand_return (result);
7222 }
7223 else if (TYPE_MODE (TREE_TYPE (result)) != VOIDmode)
7224 expand_return (result);
7225 }
7226
7227 current_function_returns_value = returns_value;
7228
7229 /* One way to clear out cleanups that EXPR might
7230 generate. Note that this code will really be
7231 dead code, but that is ok--cleanups that were
7232 needed were handled by the magic of `return'. */
7233 expand_cleanups_to (NULL_TREE);
7234 }
7235 \f
7236 /* Start a C switch statement, testing expression EXP.
7237 Return EXP if it is valid, an error node otherwise. */
7238
7239 tree
7240 c_expand_start_case (exp)
7241 tree exp;
7242 {
7243 tree type;
7244 register enum tree_code code;
7245
7246 /* Convert from references, etc. */
7247 exp = default_conversion (exp);
7248 type = TREE_TYPE (exp);
7249 code = TREE_CODE (type);
7250
7251 if (IS_AGGR_TYPE_CODE (code))
7252 exp = build_type_conversion (CONVERT_EXPR, integer_type_node, exp, 1);
7253
7254 if (exp == NULL_TREE)
7255 {
7256 error ("switch quantity not an integer");
7257 exp = error_mark_node;
7258 }
7259 type = TREE_TYPE (exp);
7260 code = TREE_CODE (type);
7261
7262 if (code != INTEGER_TYPE && code != ENUMERAL_TYPE && code != ERROR_MARK)
7263 {
7264 error ("switch quantity not an integer");
7265 exp = error_mark_node;
7266 }
7267 else
7268 {
7269 tree idx;
7270
7271 exp = default_conversion (exp);
7272 type = TREE_TYPE (exp);
7273 idx = get_unwidened (exp, 0);
7274 /* We can't strip a conversion from a signed type to an unsigned,
7275 because if we did, int_fits_type_p would do the wrong thing
7276 when checking case values for being in range,
7277 and it's too hard to do the right thing. */
7278 if (TREE_UNSIGNED (TREE_TYPE (exp))
7279 == TREE_UNSIGNED (TREE_TYPE (idx)))
7280 exp = idx;
7281 }
7282
7283 expand_start_case
7284 (1, fold (build1 (CLEANUP_POINT_EXPR, TREE_TYPE (exp), exp)),
7285 type, "switch statement");
7286
7287 return exp;
7288 }
7289
7290 /* CONSTP remembers whether or not all the intervening pointers in the `to'
7291 type have been const. */
7292
7293 int
7294 comp_ptr_ttypes_real (to, from, constp)
7295 tree to, from;
7296 int constp;
7297 {
7298 for (; ; to = TREE_TYPE (to), from = TREE_TYPE (from))
7299 {
7300 if (TREE_CODE (to) != TREE_CODE (from))
7301 return 0;
7302
7303 /* Const and volatile mean something different for function types,
7304 so the usual checks are not appropriate. */
7305 if (TREE_CODE (to) != FUNCTION_TYPE && TREE_CODE (to) != METHOD_TYPE)
7306 {
7307 if (TYPE_READONLY (from) > TYPE_READONLY (to)
7308 || TYPE_VOLATILE (from) > TYPE_VOLATILE (to))
7309 return 0;
7310
7311 if (! constp
7312 && (TYPE_READONLY (to) > TYPE_READONLY (from)
7313 || TYPE_VOLATILE (to) > TYPE_READONLY (from)))
7314 return 0;
7315 constp &= TYPE_READONLY (to);
7316 }
7317
7318 if (TREE_CODE (to) != POINTER_TYPE)
7319 return comptypes (TYPE_MAIN_VARIANT (to), TYPE_MAIN_VARIANT (from), 1);
7320 }
7321 }
7322
7323 /* When comparing, say, char ** to char const **, this function takes the
7324 'char *' and 'char const *'. Do not pass non-pointer types to this
7325 function. */
7326
7327 int
7328 comp_ptr_ttypes (to, from)
7329 tree to, from;
7330 {
7331 return comp_ptr_ttypes_real (to, from, 1);
7332 }