Daily bump.
[official-gcc.git] / gcc / c-typeck.c
blobd4749cda234b0af8574b5985d84e95a8cde86fdc
1 /* Build expressions with type checking for C compiler.
2 Copyright (C) 1987, 88, 91-97, 1998 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 /* This file is part of the C front end.
23 It contains routines to build C expressions given their operands,
24 including computing the types of the result, C-specific error checks,
25 and some optimization.
27 There are also routines to build RETURN_STMT nodes and CASE_STMT nodes,
28 and to process initializations in declarations (since they work
29 like a strange sort of assignment). */
31 #include "config.h"
32 #include "system.h"
33 #include "tree.h"
34 #include "c-tree.h"
35 #include "flags.h"
36 #include "output.h"
37 #include "rtl.h"
38 #include "expr.h"
39 #include "toplev.h"
40 #include "intl.h"
42 /* Nonzero if we've already printed a "missing braces around initializer"
43 message within this initializer. */
44 static int missing_braces_mentioned;
46 static tree qualify_type PROTO((tree, tree));
47 static int comp_target_types PROTO((tree, tree));
48 static int function_types_compatible_p PROTO((tree, tree));
49 static int type_lists_compatible_p PROTO((tree, tree));
50 static int self_promoting_type_p PROTO((tree));
51 static tree decl_constant_value PROTO((tree));
52 static tree lookup_field PROTO((tree, tree, tree *));
53 static tree convert_arguments PROTO((tree, tree, tree, tree));
54 static tree pointer_int_sum PROTO((enum tree_code, tree, tree));
55 static tree pointer_diff PROTO((tree, tree));
56 static tree unary_complex_lvalue PROTO((enum tree_code, tree));
57 static void pedantic_lvalue_warning PROTO((enum tree_code));
58 static tree internal_build_compound_expr PROTO((tree, int));
59 static tree convert_for_assignment PROTO((tree, tree, const char *, tree,
60 tree, int));
61 static void warn_for_assignment PROTO((const char *, const char *,
62 tree, int));
63 static tree valid_compound_expr_initializer PROTO((tree, tree));
64 static void push_string PROTO((const char *));
65 static void push_member_name PROTO((tree));
66 static void push_array_bounds PROTO((int));
67 static int spelling_length PROTO((void));
68 static char *print_spelling PROTO((char *));
69 static void warning_init PROTO((const char *));
70 static tree digest_init PROTO((tree, tree, int, int));
71 static void check_init_type_bitfields PROTO((tree));
72 static void output_init_element PROTO((tree, tree, tree, int));
73 static void output_pending_init_elements PROTO((int));
74 static void add_pending_init PROTO((tree, tree));
75 static int pending_init_member PROTO((tree));
77 /* Do `exp = require_complete_type (exp);' to make sure exp
78 does not have an incomplete type. (That includes void types.) */
80 tree
81 require_complete_type (value)
82 tree value;
84 tree type = TREE_TYPE (value);
86 if (TREE_CODE (value) == ERROR_MARK)
87 return error_mark_node;
89 /* First, detect a valid value with a complete type. */
90 if (TYPE_SIZE (type) != 0
91 && type != void_type_node)
92 return value;
94 incomplete_type_error (value, type);
95 return error_mark_node;
98 /* Print an error message for invalid use of an incomplete type.
99 VALUE is the expression that was used (or 0 if that isn't known)
100 and TYPE is the type that was invalid. */
102 void
103 incomplete_type_error (value, type)
104 tree value;
105 tree type;
107 const char *type_code_string;
109 /* Avoid duplicate error message. */
110 if (TREE_CODE (type) == ERROR_MARK)
111 return;
113 if (value != 0 && (TREE_CODE (value) == VAR_DECL
114 || TREE_CODE (value) == PARM_DECL))
115 error ("`%s' has an incomplete type",
116 IDENTIFIER_POINTER (DECL_NAME (value)));
117 else
119 retry:
120 /* We must print an error message. Be clever about what it says. */
122 switch (TREE_CODE (type))
124 case RECORD_TYPE:
125 type_code_string = "struct";
126 break;
128 case UNION_TYPE:
129 type_code_string = "union";
130 break;
132 case ENUMERAL_TYPE:
133 type_code_string = "enum";
134 break;
136 case VOID_TYPE:
137 error ("invalid use of void expression");
138 return;
140 case ARRAY_TYPE:
141 if (TYPE_DOMAIN (type))
143 type = TREE_TYPE (type);
144 goto retry;
146 error ("invalid use of array with unspecified bounds");
147 return;
149 default:
150 abort ();
153 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
154 error ("invalid use of undefined type `%s %s'",
155 type_code_string, IDENTIFIER_POINTER (TYPE_NAME (type)));
156 else
157 /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL. */
158 error ("invalid use of incomplete typedef `%s'",
159 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))));
163 /* Return a variant of TYPE which has all the type qualifiers of LIKE
164 as well as those of TYPE. */
166 static tree
167 qualify_type (type, like)
168 tree type, like;
170 return c_build_qualified_type (type, TYPE_QUALS (like));
173 /* Return the common type of two types.
174 We assume that comptypes has already been done and returned 1;
175 if that isn't so, this may crash. In particular, we assume that qualifiers
176 match.
178 This is the type for the result of most arithmetic operations
179 if the operands have the given two types. */
181 tree
182 common_type (t1, t2)
183 tree t1, t2;
185 register enum tree_code code1;
186 register enum tree_code code2;
187 tree attributes;
189 /* Save time if the two types are the same. */
191 if (t1 == t2) return t1;
193 /* If one type is nonsense, use the other. */
194 if (t1 == error_mark_node)
195 return t2;
196 if (t2 == error_mark_node)
197 return t1;
199 /* Merge the attributes. */
200 attributes = merge_machine_type_attributes (t1, t2);
202 /* Treat an enum type as the unsigned integer type of the same width. */
204 if (TREE_CODE (t1) == ENUMERAL_TYPE)
205 t1 = type_for_size (TYPE_PRECISION (t1), 1);
206 if (TREE_CODE (t2) == ENUMERAL_TYPE)
207 t2 = type_for_size (TYPE_PRECISION (t2), 1);
209 code1 = TREE_CODE (t1);
210 code2 = TREE_CODE (t2);
212 /* If one type is complex, form the common type of the non-complex
213 components, then make that complex. Use T1 or T2 if it is the
214 required type. */
215 if (code1 == COMPLEX_TYPE || code2 == COMPLEX_TYPE)
217 tree subtype1 = code1 == COMPLEX_TYPE ? TREE_TYPE (t1) : t1;
218 tree subtype2 = code2 == COMPLEX_TYPE ? TREE_TYPE (t2) : t2;
219 tree subtype = common_type (subtype1, subtype2);
221 if (code1 == COMPLEX_TYPE && TREE_TYPE (t1) == subtype)
222 return build_type_attribute_variant (t1, attributes);
223 else if (code2 == COMPLEX_TYPE && TREE_TYPE (t2) == subtype)
224 return build_type_attribute_variant (t2, attributes);
225 else
226 return build_type_attribute_variant (build_complex_type (subtype),
227 attributes);
230 switch (code1)
232 case INTEGER_TYPE:
233 case REAL_TYPE:
234 /* If only one is real, use it as the result. */
236 if (code1 == REAL_TYPE && code2 != REAL_TYPE)
237 return build_type_attribute_variant (t1, attributes);
239 if (code2 == REAL_TYPE && code1 != REAL_TYPE)
240 return build_type_attribute_variant (t2, attributes);
242 /* Both real or both integers; use the one with greater precision. */
244 if (TYPE_PRECISION (t1) > TYPE_PRECISION (t2))
245 return build_type_attribute_variant (t1, attributes);
246 else if (TYPE_PRECISION (t2) > TYPE_PRECISION (t1))
247 return build_type_attribute_variant (t2, attributes);
249 /* Same precision. Prefer longs to ints even when same size. */
251 if (TYPE_MAIN_VARIANT (t1) == long_unsigned_type_node
252 || TYPE_MAIN_VARIANT (t2) == long_unsigned_type_node)
253 return build_type_attribute_variant (long_unsigned_type_node,
254 attributes);
256 if (TYPE_MAIN_VARIANT (t1) == long_integer_type_node
257 || TYPE_MAIN_VARIANT (t2) == long_integer_type_node)
259 /* But preserve unsignedness from the other type,
260 since long cannot hold all the values of an unsigned int. */
261 if (TREE_UNSIGNED (t1) || TREE_UNSIGNED (t2))
262 t1 = long_unsigned_type_node;
263 else
264 t1 = long_integer_type_node;
265 return build_type_attribute_variant (t1, attributes);
268 /* Likewise, prefer long double to double even if same size. */
269 if (TYPE_MAIN_VARIANT (t1) == long_double_type_node
270 || TYPE_MAIN_VARIANT (t2) == long_double_type_node)
271 return build_type_attribute_variant (long_double_type_node,
272 attributes);
274 /* Otherwise prefer the unsigned one. */
276 if (TREE_UNSIGNED (t1))
277 return build_type_attribute_variant (t1, attributes);
278 else
279 return build_type_attribute_variant (t2, attributes);
281 case POINTER_TYPE:
282 /* For two pointers, do this recursively on the target type,
283 and combine the qualifiers of the two types' targets. */
284 /* This code was turned off; I don't know why.
285 But ANSI C specifies doing this with the qualifiers.
286 So I turned it on again. */
288 tree pointed_to_1 = TREE_TYPE (t1);
289 tree pointed_to_2 = TREE_TYPE (t2);
290 tree target = common_type (TYPE_MAIN_VARIANT (pointed_to_1),
291 TYPE_MAIN_VARIANT (pointed_to_2));
292 t1 = build_pointer_type (c_build_qualified_type
293 (target,
294 TYPE_QUALS (pointed_to_1) |
295 TYPE_QUALS (pointed_to_2)));
296 return build_type_attribute_variant (t1, attributes);
298 #if 0
299 t1 = build_pointer_type (common_type (TREE_TYPE (t1), TREE_TYPE (t2)));
300 return build_type_attribute_variant (t1, attributes);
301 #endif
303 case ARRAY_TYPE:
305 tree elt = common_type (TREE_TYPE (t1), TREE_TYPE (t2));
306 /* Save space: see if the result is identical to one of the args. */
307 if (elt == TREE_TYPE (t1) && TYPE_DOMAIN (t1))
308 return build_type_attribute_variant (t1, attributes);
309 if (elt == TREE_TYPE (t2) && TYPE_DOMAIN (t2))
310 return build_type_attribute_variant (t2, attributes);
311 /* Merge the element types, and have a size if either arg has one. */
312 t1 = build_array_type (elt, TYPE_DOMAIN (TYPE_DOMAIN (t1) ? t1 : t2));
313 return build_type_attribute_variant (t1, attributes);
316 case FUNCTION_TYPE:
317 /* Function types: prefer the one that specified arg types.
318 If both do, merge the arg types. Also merge the return types. */
320 tree valtype = common_type (TREE_TYPE (t1), TREE_TYPE (t2));
321 tree p1 = TYPE_ARG_TYPES (t1);
322 tree p2 = TYPE_ARG_TYPES (t2);
323 int len;
324 tree newargs, n;
325 int i;
327 /* Save space: see if the result is identical to one of the args. */
328 if (valtype == TREE_TYPE (t1) && ! TYPE_ARG_TYPES (t2))
329 return build_type_attribute_variant (t1, attributes);
330 if (valtype == TREE_TYPE (t2) && ! TYPE_ARG_TYPES (t1))
331 return build_type_attribute_variant (t2, attributes);
333 /* Simple way if one arg fails to specify argument types. */
334 if (TYPE_ARG_TYPES (t1) == 0)
336 t1 = build_function_type (valtype, TYPE_ARG_TYPES (t2));
337 return build_type_attribute_variant (t1, attributes);
339 if (TYPE_ARG_TYPES (t2) == 0)
341 t1 = build_function_type (valtype, TYPE_ARG_TYPES (t1));
342 return build_type_attribute_variant (t1, attributes);
345 /* If both args specify argument types, we must merge the two
346 lists, argument by argument. */
348 len = list_length (p1);
349 newargs = 0;
351 for (i = 0; i < len; i++)
352 newargs = tree_cons (NULL_TREE, NULL_TREE, newargs);
354 n = newargs;
356 for (; p1;
357 p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2), n = TREE_CHAIN (n))
359 /* A null type means arg type is not specified.
360 Take whatever the other function type has. */
361 if (TREE_VALUE (p1) == 0)
363 TREE_VALUE (n) = TREE_VALUE (p2);
364 goto parm_done;
366 if (TREE_VALUE (p2) == 0)
368 TREE_VALUE (n) = TREE_VALUE (p1);
369 goto parm_done;
372 /* Given wait (union {union wait *u; int *i} *)
373 and wait (union wait *),
374 prefer union wait * as type of parm. */
375 if (TREE_CODE (TREE_VALUE (p1)) == UNION_TYPE
376 && TREE_VALUE (p1) != TREE_VALUE (p2))
378 tree memb;
379 for (memb = TYPE_FIELDS (TREE_VALUE (p1));
380 memb; memb = TREE_CHAIN (memb))
381 if (comptypes (TREE_TYPE (memb), TREE_VALUE (p2)))
383 TREE_VALUE (n) = TREE_VALUE (p2);
384 if (pedantic)
385 pedwarn ("function types not truly compatible in ANSI C");
386 goto parm_done;
389 if (TREE_CODE (TREE_VALUE (p2)) == UNION_TYPE
390 && TREE_VALUE (p2) != TREE_VALUE (p1))
392 tree memb;
393 for (memb = TYPE_FIELDS (TREE_VALUE (p2));
394 memb; memb = TREE_CHAIN (memb))
395 if (comptypes (TREE_TYPE (memb), TREE_VALUE (p1)))
397 TREE_VALUE (n) = TREE_VALUE (p1);
398 if (pedantic)
399 pedwarn ("function types not truly compatible in ANSI C");
400 goto parm_done;
403 TREE_VALUE (n) = common_type (TREE_VALUE (p1), TREE_VALUE (p2));
404 parm_done: ;
407 t1 = build_function_type (valtype, newargs);
408 /* ... falls through ... */
411 default:
412 return build_type_attribute_variant (t1, attributes);
417 /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
418 or various other operations. Return 2 if they are compatible
419 but a warning may be needed if you use them together. */
422 comptypes (type1, type2)
423 tree type1, type2;
425 register tree t1 = type1;
426 register tree t2 = type2;
427 int attrval, val;
429 /* Suppress errors caused by previously reported errors. */
431 if (t1 == t2 || !t1 || !t2
432 || TREE_CODE (t1) == ERROR_MARK || TREE_CODE (t2) == ERROR_MARK)
433 return 1;
435 /* Treat an enum type as the integer type of the same width and
436 signedness. */
438 if (TREE_CODE (t1) == ENUMERAL_TYPE)
439 t1 = type_for_size (TYPE_PRECISION (t1), TREE_UNSIGNED (t1));
440 if (TREE_CODE (t2) == ENUMERAL_TYPE)
441 t2 = type_for_size (TYPE_PRECISION (t2), TREE_UNSIGNED (t2));
443 if (t1 == t2)
444 return 1;
446 /* Different classes of types can't be compatible. */
448 if (TREE_CODE (t1) != TREE_CODE (t2)) return 0;
450 /* Qualifiers must match. */
452 if (TYPE_QUALS (t1) != TYPE_QUALS (t2))
453 return 0;
455 /* Allow for two different type nodes which have essentially the same
456 definition. Note that we already checked for equality of the type
457 qualifiers (just above). */
459 if (TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
460 return 1;
462 #ifndef COMP_TYPE_ATTRIBUTES
463 #define COMP_TYPE_ATTRIBUTES(t1,t2) 1
464 #endif
466 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
467 if (! (attrval = COMP_TYPE_ATTRIBUTES (t1, t2)))
468 return 0;
470 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
471 val = 0;
473 switch (TREE_CODE (t1))
475 case POINTER_TYPE:
476 val = (TREE_TYPE (t1) == TREE_TYPE (t2)
477 ? 1 : comptypes (TREE_TYPE (t1), TREE_TYPE (t2)));
478 break;
480 case FUNCTION_TYPE:
481 val = function_types_compatible_p (t1, t2);
482 break;
484 case ARRAY_TYPE:
486 tree d1 = TYPE_DOMAIN (t1);
487 tree d2 = TYPE_DOMAIN (t2);
488 val = 1;
490 /* Target types must match incl. qualifiers. */
491 if (TREE_TYPE (t1) != TREE_TYPE (t2)
492 && 0 == (val = comptypes (TREE_TYPE (t1), TREE_TYPE (t2))))
493 return 0;
495 /* Sizes must match unless one is missing or variable. */
496 if (d1 == 0 || d2 == 0 || d1 == d2
497 || TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST
498 || TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST
499 || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST
500 || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST)
501 break;
503 if (! ((TREE_INT_CST_LOW (TYPE_MIN_VALUE (d1))
504 == TREE_INT_CST_LOW (TYPE_MIN_VALUE (d2)))
505 && (TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d1))
506 == TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d2)))
507 && (TREE_INT_CST_LOW (TYPE_MAX_VALUE (d1))
508 == TREE_INT_CST_LOW (TYPE_MAX_VALUE (d2)))
509 && (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d1))
510 == TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d2)))))
511 val = 0;
512 break;
515 case RECORD_TYPE:
516 if (maybe_objc_comptypes (t1, t2, 0) == 1)
517 val = 1;
518 break;
520 default:
521 break;
523 return attrval == 2 && val == 1 ? 2 : val;
526 /* Return 1 if TTL and TTR are pointers to types that are equivalent,
527 ignoring their qualifiers. */
529 static int
530 comp_target_types (ttl, ttr)
531 tree ttl, ttr;
533 int val;
535 /* Give maybe_objc_comptypes a crack at letting these types through. */
536 if ((val = maybe_objc_comptypes (ttl, ttr, 1)) >= 0)
537 return val;
539 val = comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (ttl)),
540 TYPE_MAIN_VARIANT (TREE_TYPE (ttr)));
542 if (val == 2 && pedantic)
543 pedwarn ("types are not quite compatible");
544 return val;
547 /* Subroutines of `comptypes'. */
549 /* Return 1 if two function types F1 and F2 are compatible.
550 If either type specifies no argument types,
551 the other must specify a fixed number of self-promoting arg types.
552 Otherwise, if one type specifies only the number of arguments,
553 the other must specify that number of self-promoting arg types.
554 Otherwise, the argument types must match. */
556 static int
557 function_types_compatible_p (f1, f2)
558 tree f1, f2;
560 tree args1, args2;
561 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
562 int val = 1;
563 int val1;
565 if (!(TREE_TYPE (f1) == TREE_TYPE (f2)
566 || (val = comptypes (TREE_TYPE (f1), TREE_TYPE (f2)))))
567 return 0;
569 args1 = TYPE_ARG_TYPES (f1);
570 args2 = TYPE_ARG_TYPES (f2);
572 /* An unspecified parmlist matches any specified parmlist
573 whose argument types don't need default promotions. */
575 if (args1 == 0)
577 if (!self_promoting_args_p (args2))
578 return 0;
579 /* If one of these types comes from a non-prototype fn definition,
580 compare that with the other type's arglist.
581 If they don't match, ask for a warning (but no error). */
582 if (TYPE_ACTUAL_ARG_TYPES (f1)
583 && 1 != type_lists_compatible_p (args2, TYPE_ACTUAL_ARG_TYPES (f1)))
584 val = 2;
585 return val;
587 if (args2 == 0)
589 if (!self_promoting_args_p (args1))
590 return 0;
591 if (TYPE_ACTUAL_ARG_TYPES (f2)
592 && 1 != type_lists_compatible_p (args1, TYPE_ACTUAL_ARG_TYPES (f2)))
593 val = 2;
594 return val;
597 /* Both types have argument lists: compare them and propagate results. */
598 val1 = type_lists_compatible_p (args1, args2);
599 return val1 != 1 ? val1 : val;
602 /* Check two lists of types for compatibility,
603 returning 0 for incompatible, 1 for compatible,
604 or 2 for compatible with warning. */
606 static int
607 type_lists_compatible_p (args1, args2)
608 tree args1, args2;
610 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
611 int val = 1;
612 int newval = 0;
614 while (1)
616 if (args1 == 0 && args2 == 0)
617 return val;
618 /* If one list is shorter than the other,
619 they fail to match. */
620 if (args1 == 0 || args2 == 0)
621 return 0;
622 /* A null pointer instead of a type
623 means there is supposed to be an argument
624 but nothing is specified about what type it has.
625 So match anything that self-promotes. */
626 if (TREE_VALUE (args1) == 0)
628 if (! self_promoting_type_p (TREE_VALUE (args2)))
629 return 0;
631 else if (TREE_VALUE (args2) == 0)
633 if (! self_promoting_type_p (TREE_VALUE (args1)))
634 return 0;
636 else if (! (newval = comptypes (TREE_VALUE (args1), TREE_VALUE (args2))))
638 /* Allow wait (union {union wait *u; int *i} *)
639 and wait (union wait *) to be compatible. */
640 if (TREE_CODE (TREE_VALUE (args1)) == UNION_TYPE
641 && (TYPE_NAME (TREE_VALUE (args1)) == 0
642 || TYPE_TRANSPARENT_UNION (TREE_VALUE (args1)))
643 && TREE_CODE (TYPE_SIZE (TREE_VALUE (args1))) == INTEGER_CST
644 && tree_int_cst_equal (TYPE_SIZE (TREE_VALUE (args1)),
645 TYPE_SIZE (TREE_VALUE (args2))))
647 tree memb;
648 for (memb = TYPE_FIELDS (TREE_VALUE (args1));
649 memb; memb = TREE_CHAIN (memb))
650 if (comptypes (TREE_TYPE (memb), TREE_VALUE (args2)))
651 break;
652 if (memb == 0)
653 return 0;
655 else if (TREE_CODE (TREE_VALUE (args2)) == UNION_TYPE
656 && (TYPE_NAME (TREE_VALUE (args2)) == 0
657 || TYPE_TRANSPARENT_UNION (TREE_VALUE (args2)))
658 && TREE_CODE (TYPE_SIZE (TREE_VALUE (args2))) == INTEGER_CST
659 && tree_int_cst_equal (TYPE_SIZE (TREE_VALUE (args2)),
660 TYPE_SIZE (TREE_VALUE (args1))))
662 tree memb;
663 for (memb = TYPE_FIELDS (TREE_VALUE (args2));
664 memb; memb = TREE_CHAIN (memb))
665 if (comptypes (TREE_TYPE (memb), TREE_VALUE (args1)))
666 break;
667 if (memb == 0)
668 return 0;
670 else
671 return 0;
674 /* comptypes said ok, but record if it said to warn. */
675 if (newval > val)
676 val = newval;
678 args1 = TREE_CHAIN (args1);
679 args2 = TREE_CHAIN (args2);
683 /* Return 1 if PARMS specifies a fixed number of parameters
684 and none of their types is affected by default promotions. */
687 self_promoting_args_p (parms)
688 tree parms;
690 register tree t;
691 for (t = parms; t; t = TREE_CHAIN (t))
693 register tree type = TREE_VALUE (t);
695 if (TREE_CHAIN (t) == 0 && type != void_type_node)
696 return 0;
698 if (type == 0)
699 return 0;
701 if (TYPE_MAIN_VARIANT (type) == float_type_node)
702 return 0;
704 if (C_PROMOTING_INTEGER_TYPE_P (type))
705 return 0;
707 return 1;
710 /* Return 1 if TYPE is not affected by default promotions. */
712 static int
713 self_promoting_type_p (type)
714 tree type;
716 if (TYPE_MAIN_VARIANT (type) == float_type_node)
717 return 0;
719 if (C_PROMOTING_INTEGER_TYPE_P (type))
720 return 0;
722 return 1;
725 /* Compute the value of the `sizeof' operator. */
727 tree
728 c_sizeof (type)
729 tree type;
731 enum tree_code code = TREE_CODE (type);
732 tree t;
734 if (code == FUNCTION_TYPE)
736 if (pedantic || warn_pointer_arith)
737 pedwarn ("sizeof applied to a function type");
738 return size_int (1);
740 if (code == VOID_TYPE)
742 if (pedantic || warn_pointer_arith)
743 pedwarn ("sizeof applied to a void type");
744 return size_int (1);
746 if (code == ERROR_MARK)
747 return size_int (1);
748 if (TYPE_SIZE (type) == 0)
750 error ("sizeof applied to an incomplete type");
751 return size_int (0);
754 /* Convert in case a char is more than one unit. */
755 t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type),
756 size_int (TYPE_PRECISION (char_type_node)));
757 t = convert (sizetype, t);
758 /* size_binop does not put the constant in range, so do it now. */
759 if (TREE_CODE (t) == INTEGER_CST && force_fit_type (t, 0))
760 TREE_CONSTANT_OVERFLOW (t) = TREE_OVERFLOW (t) = 1;
761 return t;
764 tree
765 c_sizeof_nowarn (type)
766 tree type;
768 enum tree_code code = TREE_CODE (type);
769 tree t;
771 if (code == FUNCTION_TYPE
772 || code == VOID_TYPE
773 || code == ERROR_MARK)
774 return size_int (1);
775 if (TYPE_SIZE (type) == 0)
776 return size_int (0);
778 /* Convert in case a char is more than one unit. */
779 t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type),
780 size_int (TYPE_PRECISION (char_type_node)));
781 t = convert (sizetype, t);
782 force_fit_type (t, 0);
783 return t;
786 /* Compute the size to increment a pointer by. */
788 tree
789 c_size_in_bytes (type)
790 tree type;
792 enum tree_code code = TREE_CODE (type);
793 tree t;
795 if (code == FUNCTION_TYPE)
796 return size_int (1);
797 if (code == VOID_TYPE)
798 return size_int (1);
799 if (code == ERROR_MARK)
800 return size_int (1);
801 if (TYPE_SIZE (type) == 0)
803 error ("arithmetic on pointer to an incomplete type");
804 return size_int (1);
807 /* Convert in case a char is more than one unit. */
808 t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type),
809 size_int (BITS_PER_UNIT));
810 t = convert (sizetype, t);
811 force_fit_type (t, 0);
812 return t;
815 /* Implement the __alignof keyword: Return the minimum required
816 alignment of TYPE, measured in bytes. */
818 tree
819 c_alignof (type)
820 tree type;
822 enum tree_code code = TREE_CODE (type);
824 if (code == FUNCTION_TYPE)
825 return size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
827 if (code == VOID_TYPE || code == ERROR_MARK)
828 return size_int (1);
830 return size_int (TYPE_ALIGN (type) / BITS_PER_UNIT);
833 /* Implement the __alignof keyword: Return the minimum required
834 alignment of EXPR, measured in bytes. For VAR_DECL's and
835 FIELD_DECL's return DECL_ALIGN (which can be set from an
836 "aligned" __attribute__ specification). */
838 tree
839 c_alignof_expr (expr)
840 tree expr;
842 if (TREE_CODE (expr) == VAR_DECL)
843 return size_int (DECL_ALIGN (expr) / BITS_PER_UNIT);
845 if (TREE_CODE (expr) == COMPONENT_REF
846 && DECL_C_BIT_FIELD (TREE_OPERAND (expr, 1)))
848 error ("`__alignof' applied to a bit-field");
849 return size_int (1);
851 else if (TREE_CODE (expr) == COMPONENT_REF
852 && TREE_CODE (TREE_OPERAND (expr, 1)) == FIELD_DECL)
853 return size_int (DECL_ALIGN (TREE_OPERAND (expr, 1)) / BITS_PER_UNIT);
855 if (TREE_CODE (expr) == INDIRECT_REF)
857 tree t = TREE_OPERAND (expr, 0);
858 tree best = t;
859 int bestalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
861 while (TREE_CODE (t) == NOP_EXPR
862 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == POINTER_TYPE)
864 int thisalign;
866 t = TREE_OPERAND (t, 0);
867 thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
868 if (thisalign > bestalign)
869 best = t, bestalign = thisalign;
871 return c_alignof (TREE_TYPE (TREE_TYPE (best)));
873 else
874 return c_alignof (TREE_TYPE (expr));
877 /* Return either DECL or its known constant value (if it has one). */
879 static tree
880 decl_constant_value (decl)
881 tree decl;
883 if (/* Don't change a variable array bound or initial value to a constant
884 in a place where a variable is invalid. */
885 current_function_decl != 0
886 && ! pedantic
887 && ! TREE_THIS_VOLATILE (decl)
888 && TREE_READONLY (decl) && ! ITERATOR_P (decl)
889 && DECL_INITIAL (decl) != 0
890 && TREE_CODE (DECL_INITIAL (decl)) != ERROR_MARK
891 /* This is invalid if initial value is not constant.
892 If it has either a function call, a memory reference,
893 or a variable, then re-evaluating it could give different results. */
894 && TREE_CONSTANT (DECL_INITIAL (decl))
895 /* Check for cases where this is sub-optimal, even though valid. */
896 && TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR
897 && DECL_MODE (decl) != BLKmode)
898 return DECL_INITIAL (decl);
899 return decl;
902 /* Perform default promotions for C data used in expressions.
903 Arrays and functions are converted to pointers;
904 enumeral types or short or char, to int.
905 In addition, manifest constants symbols are replaced by their values. */
907 tree
908 default_conversion (exp)
909 tree exp;
911 register tree type = TREE_TYPE (exp);
912 register enum tree_code code = TREE_CODE (type);
914 /* Constants can be used directly unless they're not loadable. */
915 if (TREE_CODE (exp) == CONST_DECL)
916 exp = DECL_INITIAL (exp);
918 /* Replace a nonvolatile const static variable with its value unless
919 it is an array, in which case we must be sure that taking the
920 address of the array produces consistent results. */
921 else if (optimize && TREE_CODE (exp) == VAR_DECL && code != ARRAY_TYPE)
923 exp = decl_constant_value (exp);
924 type = TREE_TYPE (exp);
927 /* Strip NON_LVALUE_EXPRs and no-op conversions, since we aren't using as
928 an lvalue. */
929 /* Do not use STRIP_NOPS here! It will remove conversions from pointer
930 to integer and cause infinite recursion. */
931 while (TREE_CODE (exp) == NON_LVALUE_EXPR
932 || (TREE_CODE (exp) == NOP_EXPR
933 && TREE_TYPE (TREE_OPERAND (exp, 0)) == TREE_TYPE (exp)))
934 exp = TREE_OPERAND (exp, 0);
936 /* Normally convert enums to int,
937 but convert wide enums to something wider. */
938 if (code == ENUMERAL_TYPE)
940 type = type_for_size (MAX (TYPE_PRECISION (type),
941 TYPE_PRECISION (integer_type_node)),
942 ((flag_traditional
943 || (TYPE_PRECISION (type)
944 >= TYPE_PRECISION (integer_type_node)))
945 && TREE_UNSIGNED (type)));
946 return convert (type, exp);
949 if (TREE_CODE (exp) == COMPONENT_REF
950 && DECL_C_BIT_FIELD (TREE_OPERAND (exp, 1)))
952 tree width = DECL_SIZE (TREE_OPERAND (exp, 1));
953 HOST_WIDE_INT low = TREE_INT_CST_LOW (width);
955 /* If it's thinner than an int, promote it like a
956 C_PROMOTING_INTEGER_TYPE_P, otherwise leave it alone. */
958 if (low < TYPE_PRECISION (integer_type_node))
960 if (flag_traditional && TREE_UNSIGNED (type))
961 return convert (unsigned_type_node, exp);
962 else
963 return convert (integer_type_node, exp);
967 if (C_PROMOTING_INTEGER_TYPE_P (type))
969 /* Traditionally, unsignedness is preserved in default promotions.
970 Also preserve unsignedness if not really getting any wider. */
971 if (TREE_UNSIGNED (type)
972 && (flag_traditional
973 || TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)))
974 return convert (unsigned_type_node, exp);
975 return convert (integer_type_node, exp);
977 if (flag_traditional && !flag_allow_single_precision
978 && TYPE_MAIN_VARIANT (type) == float_type_node)
979 return convert (double_type_node, exp);
980 if (code == VOID_TYPE)
982 error ("void value not ignored as it ought to be");
983 return error_mark_node;
985 if (code == FUNCTION_TYPE)
987 return build_unary_op (ADDR_EXPR, exp, 0);
989 if (code == ARRAY_TYPE)
991 register tree adr;
992 tree restype = TREE_TYPE (type);
993 tree ptrtype;
994 int constp = 0;
995 int volatilep = 0;
997 if (TREE_CODE_CLASS (TREE_CODE (exp)) == 'r'
998 || TREE_CODE_CLASS (TREE_CODE (exp)) == 'd')
1000 constp = TREE_READONLY (exp);
1001 volatilep = TREE_THIS_VOLATILE (exp);
1004 if (TYPE_QUALS (type) || constp || volatilep)
1005 restype
1006 = c_build_qualified_type (restype,
1007 TYPE_QUALS (type)
1008 | (constp * TYPE_QUAL_CONST)
1009 | (volatilep * TYPE_QUAL_VOLATILE));
1011 if (TREE_CODE (exp) == INDIRECT_REF)
1012 return convert (TYPE_POINTER_TO (restype),
1013 TREE_OPERAND (exp, 0));
1015 if (TREE_CODE (exp) == COMPOUND_EXPR)
1017 tree op1 = default_conversion (TREE_OPERAND (exp, 1));
1018 return build (COMPOUND_EXPR, TREE_TYPE (op1),
1019 TREE_OPERAND (exp, 0), op1);
1022 if (! lvalue_p (exp)
1023 && ! (TREE_CODE (exp) == CONSTRUCTOR && TREE_STATIC (exp)))
1025 error ("invalid use of non-lvalue array");
1026 return error_mark_node;
1029 ptrtype = build_pointer_type (restype);
1031 if (TREE_CODE (exp) == VAR_DECL)
1033 /* ??? This is not really quite correct
1034 in that the type of the operand of ADDR_EXPR
1035 is not the target type of the type of the ADDR_EXPR itself.
1036 Question is, can this lossage be avoided? */
1037 adr = build1 (ADDR_EXPR, ptrtype, exp);
1038 if (mark_addressable (exp) == 0)
1039 return error_mark_node;
1040 TREE_CONSTANT (adr) = staticp (exp);
1041 TREE_SIDE_EFFECTS (adr) = 0; /* Default would be, same as EXP. */
1042 return adr;
1044 /* This way is better for a COMPONENT_REF since it can
1045 simplify the offset for a component. */
1046 adr = build_unary_op (ADDR_EXPR, exp, 1);
1047 return convert (ptrtype, adr);
1049 return exp;
1052 /* Look up component name in the structure type definition.
1054 If this component name is found indirectly within an anonymous union,
1055 store in *INDIRECT the component which directly contains
1056 that anonymous union. Otherwise, set *INDIRECT to 0. */
1058 static tree
1059 lookup_field (type, component, indirect)
1060 tree type, component;
1061 tree *indirect;
1063 tree field;
1065 /* If TYPE_LANG_SPECIFIC is set, then it is a sorted array of pointers
1066 to the field elements. Use a binary search on this array to quickly
1067 find the element. Otherwise, do a linear search. TYPE_LANG_SPECIFIC
1068 will always be set for structures which have many elements. */
1070 if (TYPE_LANG_SPECIFIC (type))
1072 int bot, top, half;
1073 tree *field_array = &TYPE_LANG_SPECIFIC (type)->elts[0];
1075 field = TYPE_FIELDS (type);
1076 bot = 0;
1077 top = TYPE_LANG_SPECIFIC (type)->len;
1078 while (top - bot > 1)
1080 half = (top - bot + 1) >> 1;
1081 field = field_array[bot+half];
1083 if (DECL_NAME (field) == NULL_TREE)
1085 /* Step through all anon unions in linear fashion. */
1086 while (DECL_NAME (field_array[bot]) == NULL_TREE)
1088 tree anon = 0, junk;
1090 field = field_array[bot++];
1091 if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE
1092 || TREE_CODE (TREE_TYPE (field)) == UNION_TYPE)
1093 anon = lookup_field (TREE_TYPE (field), component, &junk);
1095 if (anon != NULL_TREE)
1097 *indirect = field;
1098 return anon;
1102 /* Entire record is only anon unions. */
1103 if (bot > top)
1104 return NULL_TREE;
1106 /* Restart the binary search, with new lower bound. */
1107 continue;
1110 if (DECL_NAME (field) == component)
1111 break;
1112 if (DECL_NAME (field) < component)
1113 bot += half;
1114 else
1115 top = bot + half;
1118 if (DECL_NAME (field_array[bot]) == component)
1119 field = field_array[bot];
1120 else if (DECL_NAME (field) != component)
1121 field = 0;
1123 else
1125 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
1127 if (DECL_NAME (field) == NULL_TREE)
1129 tree junk;
1130 tree anon = 0;
1132 if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE
1133 || TREE_CODE (TREE_TYPE (field)) == UNION_TYPE)
1134 anon = lookup_field (TREE_TYPE (field), component, &junk);
1136 if (anon != NULL_TREE)
1138 *indirect = field;
1139 return anon;
1143 if (DECL_NAME (field) == component)
1144 break;
1148 *indirect = NULL_TREE;
1149 return field;
1152 /* Make an expression to refer to the COMPONENT field of
1153 structure or union value DATUM. COMPONENT is an IDENTIFIER_NODE. */
1155 tree
1156 build_component_ref (datum, component)
1157 tree datum, component;
1159 register tree type = TREE_TYPE (datum);
1160 register enum tree_code code = TREE_CODE (type);
1161 register tree field = NULL;
1162 register tree ref;
1164 /* If DATUM is a COMPOUND_EXPR or COND_EXPR, move our reference inside it
1165 unless we are not to support things not strictly ANSI. */
1166 switch (TREE_CODE (datum))
1168 case COMPOUND_EXPR:
1170 tree value = build_component_ref (TREE_OPERAND (datum, 1), component);
1171 return build (COMPOUND_EXPR, TREE_TYPE (value),
1172 TREE_OPERAND (datum, 0), value);
1174 case COND_EXPR:
1175 return build_conditional_expr
1176 (TREE_OPERAND (datum, 0),
1177 build_component_ref (TREE_OPERAND (datum, 1), component),
1178 build_component_ref (TREE_OPERAND (datum, 2), component));
1180 default:
1181 break;
1184 /* See if there is a field or component with name COMPONENT. */
1186 if (code == RECORD_TYPE || code == UNION_TYPE)
1188 tree indirect = 0;
1190 if (TYPE_SIZE (type) == 0)
1192 incomplete_type_error (NULL_TREE, type);
1193 return error_mark_node;
1196 field = lookup_field (type, component, &indirect);
1198 if (!field)
1200 error (code == RECORD_TYPE
1201 ? "structure has no member named `%s'"
1202 : "union has no member named `%s'",
1203 IDENTIFIER_POINTER (component));
1204 return error_mark_node;
1206 if (TREE_TYPE (field) == error_mark_node)
1207 return error_mark_node;
1209 /* If FIELD was found buried within an anonymous union,
1210 make one COMPONENT_REF to get that anonymous union,
1211 then fall thru to make a second COMPONENT_REF to get FIELD. */
1212 if (indirect != 0)
1214 ref = build (COMPONENT_REF, TREE_TYPE (indirect), datum, indirect);
1215 if (TREE_READONLY (datum) || TREE_READONLY (indirect))
1216 TREE_READONLY (ref) = 1;
1217 if (TREE_THIS_VOLATILE (datum) || TREE_THIS_VOLATILE (indirect))
1218 TREE_THIS_VOLATILE (ref) = 1;
1219 datum = ref;
1222 ref = build (COMPONENT_REF, TREE_TYPE (field), datum, field);
1224 if (TREE_READONLY (datum) || TREE_READONLY (field))
1225 TREE_READONLY (ref) = 1;
1226 if (TREE_THIS_VOLATILE (datum) || TREE_THIS_VOLATILE (field))
1227 TREE_THIS_VOLATILE (ref) = 1;
1229 return ref;
1231 else if (code != ERROR_MARK)
1232 error ("request for member `%s' in something not a structure or union",
1233 IDENTIFIER_POINTER (component));
1235 return error_mark_node;
1238 /* Given an expression PTR for a pointer, return an expression
1239 for the value pointed to.
1240 ERRORSTRING is the name of the operator to appear in error messages. */
1242 tree
1243 build_indirect_ref (ptr, errorstring)
1244 tree ptr;
1245 const char *errorstring;
1247 register tree pointer = default_conversion (ptr);
1248 register tree type = TREE_TYPE (pointer);
1250 if (TREE_CODE (type) == POINTER_TYPE)
1252 if (TREE_CODE (pointer) == ADDR_EXPR
1253 && !flag_volatile
1254 && (TREE_TYPE (TREE_OPERAND (pointer, 0))
1255 == TREE_TYPE (type)))
1256 return TREE_OPERAND (pointer, 0);
1257 else
1259 tree t = TREE_TYPE (type);
1260 register tree ref = build1 (INDIRECT_REF,
1261 TYPE_MAIN_VARIANT (t), pointer);
1263 if (TYPE_SIZE (t) == 0 && TREE_CODE (t) != ARRAY_TYPE)
1265 error ("dereferencing pointer to incomplete type");
1266 return error_mark_node;
1268 if (TREE_CODE (t) == VOID_TYPE && skip_evaluation == 0)
1269 warning ("dereferencing `void *' pointer");
1271 /* We *must* set TREE_READONLY when dereferencing a pointer to const,
1272 so that we get the proper error message if the result is used
1273 to assign to. Also, &* is supposed to be a no-op.
1274 And ANSI C seems to specify that the type of the result
1275 should be the const type. */
1276 /* A de-reference of a pointer to const is not a const. It is valid
1277 to change it via some other pointer. */
1278 TREE_READONLY (ref) = TYPE_READONLY (t);
1279 TREE_SIDE_EFFECTS (ref)
1280 = TYPE_VOLATILE (t) || TREE_SIDE_EFFECTS (pointer) || flag_volatile;
1281 TREE_THIS_VOLATILE (ref) = TYPE_VOLATILE (t);
1282 return ref;
1285 else if (TREE_CODE (pointer) != ERROR_MARK)
1286 error ("invalid type argument of `%s'", errorstring);
1287 return error_mark_node;
1290 /* This handles expressions of the form "a[i]", which denotes
1291 an array reference.
1293 This is logically equivalent in C to *(a+i), but we may do it differently.
1294 If A is a variable or a member, we generate a primitive ARRAY_REF.
1295 This avoids forcing the array out of registers, and can work on
1296 arrays that are not lvalues (for example, members of structures returned
1297 by functions). */
1299 tree
1300 build_array_ref (array, index)
1301 tree array, index;
1303 if (index == 0)
1305 error ("subscript missing in array reference");
1306 return error_mark_node;
1309 if (TREE_TYPE (array) == error_mark_node
1310 || TREE_TYPE (index) == error_mark_node)
1311 return error_mark_node;
1313 if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE
1314 && TREE_CODE (array) != INDIRECT_REF)
1316 tree rval, type;
1318 /* Subscripting with type char is likely to lose
1319 on a machine where chars are signed.
1320 So warn on any machine, but optionally.
1321 Don't warn for unsigned char since that type is safe.
1322 Don't warn for signed char because anyone who uses that
1323 must have done so deliberately. */
1324 if (warn_char_subscripts
1325 && TYPE_MAIN_VARIANT (TREE_TYPE (index)) == char_type_node)
1326 warning ("array subscript has type `char'");
1328 /* Apply default promotions *after* noticing character types. */
1329 index = default_conversion (index);
1331 /* Require integer *after* promotion, for sake of enums. */
1332 if (TREE_CODE (TREE_TYPE (index)) != INTEGER_TYPE)
1334 error ("array subscript is not an integer");
1335 return error_mark_node;
1338 /* An array that is indexed by a non-constant
1339 cannot be stored in a register; we must be able to do
1340 address arithmetic on its address.
1341 Likewise an array of elements of variable size. */
1342 if (TREE_CODE (index) != INTEGER_CST
1343 || (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array))) != 0
1344 && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array)))) != INTEGER_CST))
1346 if (mark_addressable (array) == 0)
1347 return error_mark_node;
1349 /* An array that is indexed by a constant value which is not within
1350 the array bounds cannot be stored in a register either; because we
1351 would get a crash in store_bit_field/extract_bit_field when trying
1352 to access a non-existent part of the register. */
1353 if (TREE_CODE (index) == INTEGER_CST
1354 && TYPE_VALUES (TREE_TYPE (array))
1355 && ! int_fits_type_p (index, TYPE_VALUES (TREE_TYPE (array))))
1357 if (mark_addressable (array) == 0)
1358 return error_mark_node;
1361 if (pedantic && !lvalue_p (array))
1363 if (DECL_REGISTER (array))
1364 pedwarn ("ANSI C forbids subscripting `register' array");
1365 else
1366 pedwarn ("ANSI C forbids subscripting non-lvalue array");
1369 if (pedantic)
1371 tree foo = array;
1372 while (TREE_CODE (foo) == COMPONENT_REF)
1373 foo = TREE_OPERAND (foo, 0);
1374 if (TREE_CODE (foo) == VAR_DECL && DECL_REGISTER (foo))
1375 pedwarn ("ANSI C forbids subscripting non-lvalue array");
1378 type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (array)));
1379 rval = build (ARRAY_REF, type, array, index);
1380 /* Array ref is const/volatile if the array elements are
1381 or if the array is. */
1382 TREE_READONLY (rval)
1383 |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array)))
1384 | TREE_READONLY (array));
1385 TREE_SIDE_EFFECTS (rval)
1386 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
1387 | TREE_SIDE_EFFECTS (array));
1388 TREE_THIS_VOLATILE (rval)
1389 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
1390 /* This was added by rms on 16 Nov 91.
1391 It fixes vol struct foo *a; a->elts[1]
1392 in an inline function.
1393 Hope it doesn't break something else. */
1394 | TREE_THIS_VOLATILE (array));
1395 return require_complete_type (fold (rval));
1399 tree ar = default_conversion (array);
1400 tree ind = default_conversion (index);
1402 /* Do the same warning check as above, but only on the part that's
1403 syntactically the index and only if it is also semantically
1404 the index. */
1405 if (warn_char_subscripts
1406 && TREE_CODE (TREE_TYPE (index)) == INTEGER_TYPE
1407 && TYPE_MAIN_VARIANT (TREE_TYPE (index)) == char_type_node)
1408 warning ("subscript has type `char'");
1410 /* Put the integer in IND to simplify error checking. */
1411 if (TREE_CODE (TREE_TYPE (ar)) == INTEGER_TYPE)
1413 tree temp = ar;
1414 ar = ind;
1415 ind = temp;
1418 if (ar == error_mark_node)
1419 return ar;
1421 if (TREE_CODE (TREE_TYPE (ar)) != POINTER_TYPE
1422 || TREE_CODE (TREE_TYPE (TREE_TYPE (ar))) == FUNCTION_TYPE)
1424 error ("subscripted value is neither array nor pointer");
1425 return error_mark_node;
1427 if (TREE_CODE (TREE_TYPE (ind)) != INTEGER_TYPE)
1429 error ("array subscript is not an integer");
1430 return error_mark_node;
1433 return build_indirect_ref (build_binary_op (PLUS_EXPR, ar, ind, 0),
1434 "array indexing");
1438 /* Build a function call to function FUNCTION with parameters PARAMS.
1439 PARAMS is a list--a chain of TREE_LIST nodes--in which the
1440 TREE_VALUE of each node is a parameter-expression.
1441 FUNCTION's data type may be a function type or a pointer-to-function. */
1443 tree
1444 build_function_call (function, params)
1445 tree function, params;
1447 register tree fntype, fundecl = 0;
1448 register tree coerced_params;
1449 tree name = NULL_TREE, assembler_name = NULL_TREE;
1451 /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
1452 STRIP_TYPE_NOPS (function);
1454 /* Convert anything with function type to a pointer-to-function. */
1455 if (TREE_CODE (function) == FUNCTION_DECL)
1457 name = DECL_NAME (function);
1458 assembler_name = DECL_ASSEMBLER_NAME (function);
1460 /* Differs from default_conversion by not setting TREE_ADDRESSABLE
1461 (because calling an inline function does not mean the function
1462 needs to be separately compiled). */
1463 fntype = build_type_variant (TREE_TYPE (function),
1464 TREE_READONLY (function),
1465 TREE_THIS_VOLATILE (function));
1466 fundecl = function;
1467 function = build1 (ADDR_EXPR, build_pointer_type (fntype), function);
1469 else
1470 function = default_conversion (function);
1472 fntype = TREE_TYPE (function);
1474 if (TREE_CODE (fntype) == ERROR_MARK)
1475 return error_mark_node;
1477 if (!(TREE_CODE (fntype) == POINTER_TYPE
1478 && TREE_CODE (TREE_TYPE (fntype)) == FUNCTION_TYPE))
1480 error ("called object is not a function");
1481 return error_mark_node;
1484 /* fntype now gets the type of function pointed to. */
1485 fntype = TREE_TYPE (fntype);
1487 /* Convert the parameters to the types declared in the
1488 function prototype, or apply default promotions. */
1490 coerced_params
1491 = convert_arguments (TYPE_ARG_TYPES (fntype), params, name, fundecl);
1493 /* Check for errors in format strings. */
1495 if (warn_format && (name || assembler_name))
1496 check_function_format (name, assembler_name, coerced_params);
1498 /* Recognize certain built-in functions so we can make tree-codes
1499 other than CALL_EXPR. We do this when it enables fold-const.c
1500 to do something useful. */
1502 if (TREE_CODE (function) == ADDR_EXPR
1503 && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL
1504 && DECL_BUILT_IN (TREE_OPERAND (function, 0)))
1505 switch (DECL_FUNCTION_CODE (TREE_OPERAND (function, 0)))
1507 case BUILT_IN_ABS:
1508 case BUILT_IN_LABS:
1509 case BUILT_IN_FABS:
1510 if (coerced_params == 0)
1511 return integer_zero_node;
1512 return build_unary_op (ABS_EXPR, TREE_VALUE (coerced_params), 0);
1513 default:
1514 break;
1518 register tree result
1519 = build (CALL_EXPR, TREE_TYPE (fntype),
1520 function, coerced_params, NULL_TREE);
1522 TREE_SIDE_EFFECTS (result) = 1;
1523 if (TREE_TYPE (result) == void_type_node)
1524 return result;
1525 return require_complete_type (result);
1529 /* Convert the argument expressions in the list VALUES
1530 to the types in the list TYPELIST. The result is a list of converted
1531 argument expressions.
1533 If TYPELIST is exhausted, or when an element has NULL as its type,
1534 perform the default conversions.
1536 PARMLIST is the chain of parm decls for the function being called.
1537 It may be 0, if that info is not available.
1538 It is used only for generating error messages.
1540 NAME is an IDENTIFIER_NODE or 0. It is used only for error messages.
1542 This is also where warnings about wrong number of args are generated.
1544 Both VALUES and the returned value are chains of TREE_LIST nodes
1545 with the elements of the list in the TREE_VALUE slots of those nodes. */
1547 static tree
1548 convert_arguments (typelist, values, name, fundecl)
1549 tree typelist, values, name, fundecl;
1551 register tree typetail, valtail;
1552 register tree result = NULL;
1553 int parmnum;
1555 /* Scan the given expressions and types, producing individual
1556 converted arguments and pushing them on RESULT in reverse order. */
1558 for (valtail = values, typetail = typelist, parmnum = 0;
1559 valtail;
1560 valtail = TREE_CHAIN (valtail), parmnum++)
1562 register tree type = typetail ? TREE_VALUE (typetail) : 0;
1563 register tree val = TREE_VALUE (valtail);
1565 if (type == void_type_node)
1567 if (name)
1568 error ("too many arguments to function `%s'",
1569 IDENTIFIER_POINTER (name));
1570 else
1571 error ("too many arguments to function");
1572 break;
1575 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
1576 /* Do not use STRIP_NOPS here! We do not want an enumerator with value 0
1577 to convert automatically to a pointer. */
1578 if (TREE_CODE (val) == NON_LVALUE_EXPR)
1579 val = TREE_OPERAND (val, 0);
1581 if (TREE_CODE (TREE_TYPE (val)) == ARRAY_TYPE
1582 || TREE_CODE (TREE_TYPE (val)) == FUNCTION_TYPE)
1583 val = default_conversion (val);
1585 val = require_complete_type (val);
1587 if (type != 0)
1589 /* Formal parm type is specified by a function prototype. */
1590 tree parmval;
1592 if (TYPE_SIZE (type) == 0)
1594 error ("type of formal parameter %d is incomplete", parmnum + 1);
1595 parmval = val;
1597 else
1599 /* Optionally warn about conversions that
1600 differ from the default conversions. */
1601 if (warn_conversion)
1603 int formal_prec = TYPE_PRECISION (type);
1605 if (INTEGRAL_TYPE_P (type)
1606 && TREE_CODE (TREE_TYPE (val)) == REAL_TYPE)
1607 warn_for_assignment ("%s as integer rather than floating due to prototype", (char *) 0, name, parmnum + 1);
1608 else if (TREE_CODE (type) == COMPLEX_TYPE
1609 && TREE_CODE (TREE_TYPE (val)) == REAL_TYPE)
1610 warn_for_assignment ("%s as complex rather than floating due to prototype", (char *) 0, name, parmnum + 1);
1611 else if (TREE_CODE (type) == REAL_TYPE
1612 && INTEGRAL_TYPE_P (TREE_TYPE (val)))
1613 warn_for_assignment ("%s as floating rather than integer due to prototype", (char *) 0, name, parmnum + 1);
1614 else if (TREE_CODE (type) == REAL_TYPE
1615 && TREE_CODE (TREE_TYPE (val)) == COMPLEX_TYPE)
1616 warn_for_assignment ("%s as floating rather than complex due to prototype", (char *) 0, name, parmnum + 1);
1617 /* ??? At some point, messages should be written about
1618 conversions between complex types, but that's too messy
1619 to do now. */
1620 else if (TREE_CODE (type) == REAL_TYPE
1621 && TREE_CODE (TREE_TYPE (val)) == REAL_TYPE)
1623 /* Warn if any argument is passed as `float',
1624 since without a prototype it would be `double'. */
1625 if (formal_prec == TYPE_PRECISION (float_type_node))
1626 warn_for_assignment ("%s as `float' rather than `double' due to prototype", (char *) 0, name, parmnum + 1);
1628 /* Detect integer changing in width or signedness. */
1629 else if (INTEGRAL_TYPE_P (type)
1630 && INTEGRAL_TYPE_P (TREE_TYPE (val)))
1632 tree would_have_been = default_conversion (val);
1633 tree type1 = TREE_TYPE (would_have_been);
1635 if (TREE_CODE (type) == ENUMERAL_TYPE
1636 && type == TREE_TYPE (val))
1637 /* No warning if function asks for enum
1638 and the actual arg is that enum type. */
1640 else if (formal_prec != TYPE_PRECISION (type1))
1641 warn_for_assignment ("%s with different width due to prototype", (char *) 0, name, parmnum + 1);
1642 else if (TREE_UNSIGNED (type) == TREE_UNSIGNED (type1))
1644 /* Don't complain if the formal parameter type
1645 is an enum, because we can't tell now whether
1646 the value was an enum--even the same enum. */
1647 else if (TREE_CODE (type) == ENUMERAL_TYPE)
1649 else if (TREE_CODE (val) == INTEGER_CST
1650 && int_fits_type_p (val, type))
1651 /* Change in signedness doesn't matter
1652 if a constant value is unaffected. */
1654 /* Likewise for a constant in a NOP_EXPR. */
1655 else if (TREE_CODE (val) == NOP_EXPR
1656 && TREE_CODE (TREE_OPERAND (val, 0)) == INTEGER_CST
1657 && int_fits_type_p (TREE_OPERAND (val, 0), type))
1659 #if 0 /* We never get such tree structure here. */
1660 else if (TREE_CODE (TREE_TYPE (val)) == ENUMERAL_TYPE
1661 && int_fits_type_p (TYPE_MIN_VALUE (TREE_TYPE (val)), type)
1662 && int_fits_type_p (TYPE_MAX_VALUE (TREE_TYPE (val)), type))
1663 /* Change in signedness doesn't matter
1664 if an enum value is unaffected. */
1666 #endif
1667 /* If the value is extended from a narrower
1668 unsigned type, it doesn't matter whether we
1669 pass it as signed or unsigned; the value
1670 certainly is the same either way. */
1671 else if (TYPE_PRECISION (TREE_TYPE (val)) < TYPE_PRECISION (type)
1672 && TREE_UNSIGNED (TREE_TYPE (val)))
1674 else if (TREE_UNSIGNED (type))
1675 warn_for_assignment ("%s as unsigned due to prototype", (char *) 0, name, parmnum + 1);
1676 else
1677 warn_for_assignment ("%s as signed due to prototype", (char *) 0, name, parmnum + 1);
1681 parmval = convert_for_assignment (type, val,
1682 (char *) 0, /* arg passing */
1683 fundecl, name, parmnum + 1);
1685 #ifdef PROMOTE_PROTOTYPES
1686 if ((TREE_CODE (type) == INTEGER_TYPE
1687 || TREE_CODE (type) == ENUMERAL_TYPE)
1688 && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
1689 parmval = default_conversion (parmval);
1690 #endif
1692 result = tree_cons (NULL_TREE, parmval, result);
1694 else if (TREE_CODE (TREE_TYPE (val)) == REAL_TYPE
1695 && (TYPE_PRECISION (TREE_TYPE (val))
1696 < TYPE_PRECISION (double_type_node)))
1697 /* Convert `float' to `double'. */
1698 result = tree_cons (NULL_TREE, convert (double_type_node, val), result);
1699 else
1700 /* Convert `short' and `char' to full-size `int'. */
1701 result = tree_cons (NULL_TREE, default_conversion (val), result);
1703 if (typetail)
1704 typetail = TREE_CHAIN (typetail);
1707 if (typetail != 0 && TREE_VALUE (typetail) != void_type_node)
1709 if (name)
1710 error ("too few arguments to function `%s'",
1711 IDENTIFIER_POINTER (name));
1712 else
1713 error ("too few arguments to function");
1716 return nreverse (result);
1719 /* This is the entry point used by the parser
1720 for binary operators in the input.
1721 In addition to constructing the expression,
1722 we check for operands that were written with other binary operators
1723 in a way that is likely to confuse the user. */
1725 tree
1726 parser_build_binary_op (code, arg1, arg2)
1727 enum tree_code code;
1728 tree arg1, arg2;
1730 tree result = build_binary_op (code, arg1, arg2, 1);
1732 char class;
1733 char class1 = TREE_CODE_CLASS (TREE_CODE (arg1));
1734 char class2 = TREE_CODE_CLASS (TREE_CODE (arg2));
1735 enum tree_code code1 = ERROR_MARK;
1736 enum tree_code code2 = ERROR_MARK;
1738 if (class1 == 'e' || class1 == '1'
1739 || class1 == '2' || class1 == '<')
1740 code1 = C_EXP_ORIGINAL_CODE (arg1);
1741 if (class2 == 'e' || class2 == '1'
1742 || class2 == '2' || class2 == '<')
1743 code2 = C_EXP_ORIGINAL_CODE (arg2);
1745 /* Check for cases such as x+y<<z which users are likely
1746 to misinterpret. If parens are used, C_EXP_ORIGINAL_CODE
1747 is cleared to prevent these warnings. */
1748 if (warn_parentheses)
1750 if (code == LSHIFT_EXPR || code == RSHIFT_EXPR)
1752 if (code1 == PLUS_EXPR || code1 == MINUS_EXPR
1753 || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
1754 warning ("suggest parentheses around + or - inside shift");
1757 if (code == TRUTH_ORIF_EXPR)
1759 if (code1 == TRUTH_ANDIF_EXPR
1760 || code2 == TRUTH_ANDIF_EXPR)
1761 warning ("suggest parentheses around && within ||");
1764 if (code == BIT_IOR_EXPR)
1766 if (code1 == BIT_AND_EXPR || code1 == BIT_XOR_EXPR
1767 || code1 == PLUS_EXPR || code1 == MINUS_EXPR
1768 || code2 == BIT_AND_EXPR || code2 == BIT_XOR_EXPR
1769 || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
1770 warning ("suggest parentheses around arithmetic in operand of |");
1771 /* Check cases like x|y==z */
1772 if (TREE_CODE_CLASS (code1) == '<' || TREE_CODE_CLASS (code2) == '<')
1773 warning ("suggest parentheses around comparison in operand of |");
1776 if (code == BIT_XOR_EXPR)
1778 if (code1 == BIT_AND_EXPR
1779 || code1 == PLUS_EXPR || code1 == MINUS_EXPR
1780 || code2 == BIT_AND_EXPR
1781 || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
1782 warning ("suggest parentheses around arithmetic in operand of ^");
1783 /* Check cases like x^y==z */
1784 if (TREE_CODE_CLASS (code1) == '<' || TREE_CODE_CLASS (code2) == '<')
1785 warning ("suggest parentheses around comparison in operand of ^");
1788 if (code == BIT_AND_EXPR)
1790 if (code1 == PLUS_EXPR || code1 == MINUS_EXPR
1791 || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
1792 warning ("suggest parentheses around + or - in operand of &");
1793 /* Check cases like x&y==z */
1794 if (TREE_CODE_CLASS (code1) == '<' || TREE_CODE_CLASS (code2) == '<')
1795 warning ("suggest parentheses around comparison in operand of &");
1799 /* Similarly, check for cases like 1<=i<=10 that are probably errors. */
1800 if (TREE_CODE_CLASS (code) == '<' && extra_warnings
1801 && (TREE_CODE_CLASS (code1) == '<' || TREE_CODE_CLASS (code2) == '<'))
1802 warning ("comparisons like X<=Y<=Z do not have their mathematical meaning");
1804 unsigned_conversion_warning (result, arg1);
1805 unsigned_conversion_warning (result, arg2);
1806 overflow_warning (result);
1808 class = TREE_CODE_CLASS (TREE_CODE (result));
1810 /* Record the code that was specified in the source,
1811 for the sake of warnings about confusing nesting. */
1812 if (class == 'e' || class == '1'
1813 || class == '2' || class == '<')
1814 C_SET_EXP_ORIGINAL_CODE (result, code);
1815 else
1817 int flag = TREE_CONSTANT (result);
1818 /* We used to use NOP_EXPR rather than NON_LVALUE_EXPR
1819 so that convert_for_assignment wouldn't strip it.
1820 That way, we got warnings for things like p = (1 - 1).
1821 But it turns out we should not get those warnings. */
1822 result = build1 (NON_LVALUE_EXPR, TREE_TYPE (result), result);
1823 C_SET_EXP_ORIGINAL_CODE (result, code);
1824 TREE_CONSTANT (result) = flag;
1827 return result;
1830 /* Build a binary-operation expression without default conversions.
1831 CODE is the kind of expression to build.
1832 This function differs from `build' in several ways:
1833 the data type of the result is computed and recorded in it,
1834 warnings are generated if arg data types are invalid,
1835 special handling for addition and subtraction of pointers is known,
1836 and some optimization is done (operations on narrow ints
1837 are done in the narrower type when that gives the same result).
1838 Constant folding is also done before the result is returned.
1840 Note that the operands will never have enumeral types, or function
1841 or array types, because either they will have the default conversions
1842 performed or they have both just been converted to some other type in which
1843 the arithmetic is to be done. */
1845 tree
1846 build_binary_op (code, orig_op0, orig_op1, convert_p)
1847 enum tree_code code;
1848 tree orig_op0, orig_op1;
1849 int convert_p;
1851 tree type0, type1;
1852 register enum tree_code code0, code1;
1853 tree op0, op1;
1855 /* Expression code to give to the expression when it is built.
1856 Normally this is CODE, which is what the caller asked for,
1857 but in some special cases we change it. */
1858 register enum tree_code resultcode = code;
1860 /* Data type in which the computation is to be performed.
1861 In the simplest cases this is the common type of the arguments. */
1862 register tree result_type = NULL;
1864 /* Nonzero means operands have already been type-converted
1865 in whatever way is necessary.
1866 Zero means they need to be converted to RESULT_TYPE. */
1867 int converted = 0;
1869 /* Nonzero means create the expression with this type, rather than
1870 RESULT_TYPE. */
1871 tree build_type = 0;
1873 /* Nonzero means after finally constructing the expression
1874 convert it to this type. */
1875 tree final_type = 0;
1877 /* Nonzero if this is an operation like MIN or MAX which can
1878 safely be computed in short if both args are promoted shorts.
1879 Also implies COMMON.
1880 -1 indicates a bitwise operation; this makes a difference
1881 in the exact conditions for when it is safe to do the operation
1882 in a narrower mode. */
1883 int shorten = 0;
1885 /* Nonzero if this is a comparison operation;
1886 if both args are promoted shorts, compare the original shorts.
1887 Also implies COMMON. */
1888 int short_compare = 0;
1890 /* Nonzero if this is a right-shift operation, which can be computed on the
1891 original short and then promoted if the operand is a promoted short. */
1892 int short_shift = 0;
1894 /* Nonzero means set RESULT_TYPE to the common type of the args. */
1895 int common = 0;
1897 if (convert_p)
1899 op0 = default_conversion (orig_op0);
1900 op1 = default_conversion (orig_op1);
1902 else
1904 op0 = orig_op0;
1905 op1 = orig_op1;
1908 type0 = TREE_TYPE (op0);
1909 type1 = TREE_TYPE (op1);
1911 /* The expression codes of the data types of the arguments tell us
1912 whether the arguments are integers, floating, pointers, etc. */
1913 code0 = TREE_CODE (type0);
1914 code1 = TREE_CODE (type1);
1916 /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
1917 STRIP_TYPE_NOPS (op0);
1918 STRIP_TYPE_NOPS (op1);
1920 /* If an error was already reported for one of the arguments,
1921 avoid reporting another error. */
1923 if (code0 == ERROR_MARK || code1 == ERROR_MARK)
1924 return error_mark_node;
1926 switch (code)
1928 case PLUS_EXPR:
1929 /* Handle the pointer + int case. */
1930 if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
1931 return pointer_int_sum (PLUS_EXPR, op0, op1);
1932 else if (code1 == POINTER_TYPE && code0 == INTEGER_TYPE)
1933 return pointer_int_sum (PLUS_EXPR, op1, op0);
1934 else
1935 common = 1;
1936 break;
1938 case MINUS_EXPR:
1939 /* Subtraction of two similar pointers.
1940 We must subtract them as integers, then divide by object size. */
1941 if (code0 == POINTER_TYPE && code1 == POINTER_TYPE
1942 && comp_target_types (type0, type1))
1943 return pointer_diff (op0, op1);
1944 /* Handle pointer minus int. Just like pointer plus int. */
1945 else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
1946 return pointer_int_sum (MINUS_EXPR, op0, op1);
1947 else
1948 common = 1;
1949 break;
1951 case MULT_EXPR:
1952 common = 1;
1953 break;
1955 case TRUNC_DIV_EXPR:
1956 case CEIL_DIV_EXPR:
1957 case FLOOR_DIV_EXPR:
1958 case ROUND_DIV_EXPR:
1959 case EXACT_DIV_EXPR:
1960 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
1961 || code0 == COMPLEX_TYPE)
1962 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
1963 || code1 == COMPLEX_TYPE))
1965 if (!(code0 == INTEGER_TYPE && code1 == INTEGER_TYPE))
1966 resultcode = RDIV_EXPR;
1967 else
1969 /* Although it would be tempting to shorten always here, that
1970 loses on some targets, since the modulo instruction is
1971 undefined if the quotient can't be represented in the
1972 computation mode. We shorten only if unsigned or if
1973 dividing by something we know != -1. */
1974 shorten = (TREE_UNSIGNED (TREE_TYPE (orig_op0))
1975 || (TREE_CODE (op1) == INTEGER_CST
1976 && (TREE_INT_CST_LOW (op1) != -1
1977 || TREE_INT_CST_HIGH (op1) != -1)));
1979 common = 1;
1981 break;
1983 case BIT_AND_EXPR:
1984 case BIT_ANDTC_EXPR:
1985 case BIT_IOR_EXPR:
1986 case BIT_XOR_EXPR:
1987 if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
1988 shorten = -1;
1989 /* If one operand is a constant, and the other is a short type
1990 that has been converted to an int,
1991 really do the work in the short type and then convert the
1992 result to int. If we are lucky, the constant will be 0 or 1
1993 in the short type, making the entire operation go away. */
1994 if (TREE_CODE (op0) == INTEGER_CST
1995 && TREE_CODE (op1) == NOP_EXPR
1996 && TYPE_PRECISION (type1) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op1, 0)))
1997 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op1, 0))))
1999 final_type = result_type;
2000 op1 = TREE_OPERAND (op1, 0);
2001 result_type = TREE_TYPE (op1);
2003 if (TREE_CODE (op1) == INTEGER_CST
2004 && TREE_CODE (op0) == NOP_EXPR
2005 && TYPE_PRECISION (type0) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0, 0)))
2006 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0, 0))))
2008 final_type = result_type;
2009 op0 = TREE_OPERAND (op0, 0);
2010 result_type = TREE_TYPE (op0);
2012 break;
2014 case TRUNC_MOD_EXPR:
2015 case FLOOR_MOD_EXPR:
2016 if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
2018 /* Although it would be tempting to shorten always here, that loses
2019 on some targets, since the modulo instruction is undefined if the
2020 quotient can't be represented in the computation mode. We shorten
2021 only if unsigned or if dividing by something we know != -1. */
2022 shorten = (TREE_UNSIGNED (TREE_TYPE (orig_op0))
2023 || (TREE_CODE (op1) == INTEGER_CST
2024 && (TREE_INT_CST_LOW (op1) != -1
2025 || TREE_INT_CST_HIGH (op1) != -1)));
2026 common = 1;
2028 break;
2030 case TRUTH_ANDIF_EXPR:
2031 case TRUTH_ORIF_EXPR:
2032 case TRUTH_AND_EXPR:
2033 case TRUTH_OR_EXPR:
2034 case TRUTH_XOR_EXPR:
2035 if ((code0 == INTEGER_TYPE || code0 == POINTER_TYPE
2036 || code0 == REAL_TYPE || code0 == COMPLEX_TYPE)
2037 && (code1 == INTEGER_TYPE || code1 == POINTER_TYPE
2038 || code1 == REAL_TYPE || code1 == COMPLEX_TYPE))
2040 /* Result of these operations is always an int,
2041 but that does not mean the operands should be
2042 converted to ints! */
2043 result_type = integer_type_node;
2044 op0 = truthvalue_conversion (op0);
2045 op1 = truthvalue_conversion (op1);
2046 converted = 1;
2048 break;
2050 /* Shift operations: result has same type as first operand;
2051 always convert second operand to int.
2052 Also set SHORT_SHIFT if shifting rightward. */
2054 case RSHIFT_EXPR:
2055 if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
2057 if (TREE_CODE (op1) == INTEGER_CST && skip_evaluation == 0)
2059 if (tree_int_cst_sgn (op1) < 0)
2060 warning ("right shift count is negative");
2061 else
2063 if (TREE_INT_CST_LOW (op1) | TREE_INT_CST_HIGH (op1))
2064 short_shift = 1;
2065 if (TREE_INT_CST_HIGH (op1) != 0
2066 || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1)
2067 >= TYPE_PRECISION (type0)))
2068 warning ("right shift count >= width of type");
2071 /* Use the type of the value to be shifted.
2072 This is what most traditional C compilers do. */
2073 result_type = type0;
2074 /* Unless traditional, convert the shift-count to an integer,
2075 regardless of size of value being shifted. */
2076 if (! flag_traditional)
2078 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
2079 op1 = convert (integer_type_node, op1);
2080 /* Avoid converting op1 to result_type later. */
2081 converted = 1;
2084 break;
2086 case LSHIFT_EXPR:
2087 if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
2089 if (TREE_CODE (op1) == INTEGER_CST && skip_evaluation == 0)
2091 if (tree_int_cst_sgn (op1) < 0)
2092 warning ("left shift count is negative");
2093 else if (TREE_INT_CST_HIGH (op1) != 0
2094 || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1)
2095 >= TYPE_PRECISION (type0)))
2096 warning ("left shift count >= width of type");
2098 /* Use the type of the value to be shifted.
2099 This is what most traditional C compilers do. */
2100 result_type = type0;
2101 /* Unless traditional, convert the shift-count to an integer,
2102 regardless of size of value being shifted. */
2103 if (! flag_traditional)
2105 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
2106 op1 = convert (integer_type_node, op1);
2107 /* Avoid converting op1 to result_type later. */
2108 converted = 1;
2111 break;
2113 case RROTATE_EXPR:
2114 case LROTATE_EXPR:
2115 if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
2117 if (TREE_CODE (op1) == INTEGER_CST && skip_evaluation == 0)
2119 if (tree_int_cst_sgn (op1) < 0)
2120 warning ("shift count is negative");
2121 else if (TREE_INT_CST_HIGH (op1) != 0
2122 || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1)
2123 >= TYPE_PRECISION (type0)))
2124 warning ("shift count >= width of type");
2126 /* Use the type of the value to be shifted.
2127 This is what most traditional C compilers do. */
2128 result_type = type0;
2129 /* Unless traditional, convert the shift-count to an integer,
2130 regardless of size of value being shifted. */
2131 if (! flag_traditional)
2133 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
2134 op1 = convert (integer_type_node, op1);
2135 /* Avoid converting op1 to result_type later. */
2136 converted = 1;
2139 break;
2141 case EQ_EXPR:
2142 case NE_EXPR:
2143 /* Result of comparison is always int,
2144 but don't convert the args to int! */
2145 build_type = integer_type_node;
2146 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
2147 || code0 == COMPLEX_TYPE)
2148 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
2149 || code1 == COMPLEX_TYPE))
2150 short_compare = 1;
2151 else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
2153 register tree tt0 = TREE_TYPE (type0);
2154 register tree tt1 = TREE_TYPE (type1);
2155 /* Anything compares with void *. void * compares with anything.
2156 Otherwise, the targets must be compatible
2157 and both must be object or both incomplete. */
2158 if (comp_target_types (type0, type1))
2159 result_type = common_type (type0, type1);
2160 else if (TYPE_MAIN_VARIANT (tt0) == void_type_node)
2162 /* op0 != orig_op0 detects the case of something
2163 whose value is 0 but which isn't a valid null ptr const. */
2164 if (pedantic && (!integer_zerop (op0) || op0 != orig_op0)
2165 && TREE_CODE (tt1) == FUNCTION_TYPE)
2166 pedwarn ("ANSI C forbids comparison of `void *' with function pointer");
2168 else if (TYPE_MAIN_VARIANT (tt1) == void_type_node)
2170 if (pedantic && (!integer_zerop (op1) || op1 != orig_op1)
2171 && TREE_CODE (tt0) == FUNCTION_TYPE)
2172 pedwarn ("ANSI C forbids comparison of `void *' with function pointer");
2174 else
2175 pedwarn ("comparison of distinct pointer types lacks a cast");
2177 if (result_type == NULL_TREE)
2178 result_type = ptr_type_node;
2180 else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST
2181 && integer_zerop (op1))
2182 result_type = type0;
2183 else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST
2184 && integer_zerop (op0))
2185 result_type = type1;
2186 else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
2188 result_type = type0;
2189 if (! flag_traditional)
2190 pedwarn ("comparison between pointer and integer");
2192 else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
2194 result_type = type1;
2195 if (! flag_traditional)
2196 pedwarn ("comparison between pointer and integer");
2198 break;
2200 case MAX_EXPR:
2201 case MIN_EXPR:
2202 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
2203 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
2204 shorten = 1;
2205 else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
2207 if (comp_target_types (type0, type1))
2209 result_type = common_type (type0, type1);
2210 if (pedantic
2211 && TREE_CODE (TREE_TYPE (type0)) == FUNCTION_TYPE)
2212 pedwarn ("ANSI C forbids ordered comparisons of pointers to functions");
2214 else
2216 result_type = ptr_type_node;
2217 pedwarn ("comparison of distinct pointer types lacks a cast");
2220 break;
2222 case LE_EXPR:
2223 case GE_EXPR:
2224 case LT_EXPR:
2225 case GT_EXPR:
2226 build_type = integer_type_node;
2227 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
2228 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
2229 short_compare = 1;
2230 else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
2232 if (comp_target_types (type0, type1))
2234 result_type = common_type (type0, type1);
2235 if ((TYPE_SIZE (TREE_TYPE (type0)) != 0)
2236 != (TYPE_SIZE (TREE_TYPE (type1)) != 0))
2237 pedwarn ("comparison of complete and incomplete pointers");
2238 else if (pedantic
2239 && TREE_CODE (TREE_TYPE (type0)) == FUNCTION_TYPE)
2240 pedwarn ("ANSI C forbids ordered comparisons of pointers to functions");
2242 else
2244 result_type = ptr_type_node;
2245 pedwarn ("comparison of distinct pointer types lacks a cast");
2248 else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST
2249 && integer_zerop (op1))
2251 result_type = type0;
2252 if (pedantic || extra_warnings)
2253 pedwarn ("ordered comparison of pointer with integer zero");
2255 else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST
2256 && integer_zerop (op0))
2258 result_type = type1;
2259 if (pedantic)
2260 pedwarn ("ordered comparison of pointer with integer zero");
2262 else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
2264 result_type = type0;
2265 if (! flag_traditional)
2266 pedwarn ("comparison between pointer and integer");
2268 else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
2270 result_type = type1;
2271 if (! flag_traditional)
2272 pedwarn ("comparison between pointer and integer");
2274 break;
2276 default:
2277 break;
2280 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == COMPLEX_TYPE)
2282 (code1 == INTEGER_TYPE || code1 == REAL_TYPE || code1 == COMPLEX_TYPE))
2284 int none_complex = (code0 != COMPLEX_TYPE && code1 != COMPLEX_TYPE);
2286 if (shorten || common || short_compare)
2287 result_type = common_type (type0, type1);
2289 /* For certain operations (which identify themselves by shorten != 0)
2290 if both args were extended from the same smaller type,
2291 do the arithmetic in that type and then extend.
2293 shorten !=0 and !=1 indicates a bitwise operation.
2294 For them, this optimization is safe only if
2295 both args are zero-extended or both are sign-extended.
2296 Otherwise, we might change the result.
2297 Eg, (short)-1 | (unsigned short)-1 is (int)-1
2298 but calculated in (unsigned short) it would be (unsigned short)-1. */
2300 if (shorten && none_complex)
2302 int unsigned0, unsigned1;
2303 tree arg0 = get_narrower (op0, &unsigned0);
2304 tree arg1 = get_narrower (op1, &unsigned1);
2305 /* UNS is 1 if the operation to be done is an unsigned one. */
2306 int uns = TREE_UNSIGNED (result_type);
2307 tree type;
2309 final_type = result_type;
2311 /* Handle the case that OP0 (or OP1) does not *contain* a conversion
2312 but it *requires* conversion to FINAL_TYPE. */
2314 if ((TYPE_PRECISION (TREE_TYPE (op0))
2315 == TYPE_PRECISION (TREE_TYPE (arg0)))
2316 && TREE_TYPE (op0) != final_type)
2317 unsigned0 = TREE_UNSIGNED (TREE_TYPE (op0));
2318 if ((TYPE_PRECISION (TREE_TYPE (op1))
2319 == TYPE_PRECISION (TREE_TYPE (arg1)))
2320 && TREE_TYPE (op1) != final_type)
2321 unsigned1 = TREE_UNSIGNED (TREE_TYPE (op1));
2323 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
2325 /* For bitwise operations, signedness of nominal type
2326 does not matter. Consider only how operands were extended. */
2327 if (shorten == -1)
2328 uns = unsigned0;
2330 /* Note that in all three cases below we refrain from optimizing
2331 an unsigned operation on sign-extended args.
2332 That would not be valid. */
2334 /* Both args variable: if both extended in same way
2335 from same width, do it in that width.
2336 Do it unsigned if args were zero-extended. */
2337 if ((TYPE_PRECISION (TREE_TYPE (arg0))
2338 < TYPE_PRECISION (result_type))
2339 && (TYPE_PRECISION (TREE_TYPE (arg1))
2340 == TYPE_PRECISION (TREE_TYPE (arg0)))
2341 && unsigned0 == unsigned1
2342 && (unsigned0 || !uns))
2343 result_type
2344 = signed_or_unsigned_type (unsigned0,
2345 common_type (TREE_TYPE (arg0), TREE_TYPE (arg1)));
2346 else if (TREE_CODE (arg0) == INTEGER_CST
2347 && (unsigned1 || !uns)
2348 && (TYPE_PRECISION (TREE_TYPE (arg1))
2349 < TYPE_PRECISION (result_type))
2350 && (type = signed_or_unsigned_type (unsigned1,
2351 TREE_TYPE (arg1)),
2352 int_fits_type_p (arg0, type)))
2353 result_type = type;
2354 else if (TREE_CODE (arg1) == INTEGER_CST
2355 && (unsigned0 || !uns)
2356 && (TYPE_PRECISION (TREE_TYPE (arg0))
2357 < TYPE_PRECISION (result_type))
2358 && (type = signed_or_unsigned_type (unsigned0,
2359 TREE_TYPE (arg0)),
2360 int_fits_type_p (arg1, type)))
2361 result_type = type;
2364 /* Shifts can be shortened if shifting right. */
2366 if (short_shift)
2368 int unsigned_arg;
2369 tree arg0 = get_narrower (op0, &unsigned_arg);
2371 final_type = result_type;
2373 if (arg0 == op0 && final_type == TREE_TYPE (op0))
2374 unsigned_arg = TREE_UNSIGNED (TREE_TYPE (op0));
2376 if (TYPE_PRECISION (TREE_TYPE (arg0)) < TYPE_PRECISION (result_type)
2377 /* We can shorten only if the shift count is less than the
2378 number of bits in the smaller type size. */
2379 && TREE_INT_CST_HIGH (op1) == 0
2380 && TYPE_PRECISION (TREE_TYPE (arg0)) > TREE_INT_CST_LOW (op1)
2381 /* If arg is sign-extended and then unsigned-shifted,
2382 we can simulate this with a signed shift in arg's type
2383 only if the extended result is at least twice as wide
2384 as the arg. Otherwise, the shift could use up all the
2385 ones made by sign-extension and bring in zeros.
2386 We can't optimize that case at all, but in most machines
2387 it never happens because available widths are 2**N. */
2388 && (!TREE_UNSIGNED (final_type)
2389 || unsigned_arg
2390 || 2 * TYPE_PRECISION (TREE_TYPE (arg0)) <= TYPE_PRECISION (result_type)))
2392 /* Do an unsigned shift if the operand was zero-extended. */
2393 result_type
2394 = signed_or_unsigned_type (unsigned_arg,
2395 TREE_TYPE (arg0));
2396 /* Convert value-to-be-shifted to that type. */
2397 if (TREE_TYPE (op0) != result_type)
2398 op0 = convert (result_type, op0);
2399 converted = 1;
2403 /* Comparison operations are shortened too but differently.
2404 They identify themselves by setting short_compare = 1. */
2406 if (short_compare)
2408 /* Don't write &op0, etc., because that would prevent op0
2409 from being kept in a register.
2410 Instead, make copies of the our local variables and
2411 pass the copies by reference, then copy them back afterward. */
2412 tree xop0 = op0, xop1 = op1, xresult_type = result_type;
2413 enum tree_code xresultcode = resultcode;
2414 tree val
2415 = shorten_compare (&xop0, &xop1, &xresult_type, &xresultcode);
2416 if (val != 0)
2417 return val;
2418 op0 = xop0, op1 = xop1;
2419 converted = 1;
2420 resultcode = xresultcode;
2422 if ((warn_sign_compare < 0 ? extra_warnings : warn_sign_compare != 0)
2423 && skip_evaluation == 0)
2425 int op0_signed = ! TREE_UNSIGNED (TREE_TYPE (orig_op0));
2426 int op1_signed = ! TREE_UNSIGNED (TREE_TYPE (orig_op1));
2428 int unsignedp0, unsignedp1;
2429 tree primop0 = get_narrower (op0, &unsignedp0);
2430 tree primop1 = get_narrower (op1, &unsignedp1);
2432 /* Avoid spurious warnings for comparison with enumerators. */
2434 xop0 = orig_op0;
2435 xop1 = orig_op1;
2436 STRIP_TYPE_NOPS (xop0);
2437 STRIP_TYPE_NOPS (xop1);
2439 /* Give warnings for comparisons between signed and unsigned
2440 quantities that may fail. */
2441 /* Do the checking based on the original operand trees, so that
2442 casts will be considered, but default promotions won't be. */
2444 /* Do not warn if the comparison is being done in a signed type,
2445 since the signed type will only be chosen if it can represent
2446 all the values of the unsigned type. */
2447 if (! TREE_UNSIGNED (result_type))
2448 /* OK */;
2449 /* Do not warn if both operands are unsigned. */
2450 else if (op0_signed == op1_signed)
2451 /* OK */;
2452 /* Do not warn if the signed quantity is an unsuffixed
2453 integer literal (or some static constant expression
2454 involving such literals) and it is non-negative. */
2455 else if ((op0_signed && TREE_CODE (xop0) == INTEGER_CST
2456 && tree_int_cst_sgn (xop0) >= 0)
2457 || (op1_signed && TREE_CODE (xop1) == INTEGER_CST
2458 && tree_int_cst_sgn (xop1) >= 0))
2459 /* OK */;
2460 /* Do not warn if the comparison is an equality operation,
2461 the unsigned quantity is an integral constant and it does
2462 not use the most significant bit of result_type. */
2463 else if ((resultcode == EQ_EXPR || resultcode == NE_EXPR)
2464 && ((op0_signed && TREE_CODE (xop1) == INTEGER_CST
2465 && int_fits_type_p (xop1, signed_type (result_type)))
2466 || (op1_signed && TREE_CODE (xop0) == INTEGER_CST
2467 && int_fits_type_p (xop0, signed_type (result_type)))))
2468 /* OK */;
2469 else
2470 warning ("comparison between signed and unsigned");
2472 /* Warn if two unsigned values are being compared in a size
2473 larger than their original size, and one (and only one) is the
2474 result of a `~' operator. This comparison will always fail.
2476 Also warn if one operand is a constant, and the constant
2477 does not have all bits set that are set in the ~ operand
2478 when it is extended. */
2480 if ((TREE_CODE (primop0) == BIT_NOT_EXPR)
2481 != (TREE_CODE (primop1) == BIT_NOT_EXPR))
2483 if (TREE_CODE (primop0) == BIT_NOT_EXPR)
2484 primop0 = get_narrower (TREE_OPERAND (primop0, 0),
2485 &unsignedp0);
2486 else
2487 primop1 = get_narrower (TREE_OPERAND (primop1, 0),
2488 &unsignedp1);
2490 if (TREE_CODE (primop0) == INTEGER_CST
2491 || TREE_CODE (primop1) == INTEGER_CST)
2493 tree primop;
2494 long constant, mask;
2495 int unsignedp, bits;
2497 if (TREE_CODE (primop0) == INTEGER_CST)
2499 primop = primop1;
2500 unsignedp = unsignedp1;
2501 constant = TREE_INT_CST_LOW (primop0);
2503 else
2505 primop = primop0;
2506 unsignedp = unsignedp0;
2507 constant = TREE_INT_CST_LOW (primop1);
2510 bits = TYPE_PRECISION (TREE_TYPE (primop));
2511 if (bits < TYPE_PRECISION (result_type)
2512 && bits < HOST_BITS_PER_LONG && unsignedp)
2514 mask = (~0L) << bits;
2515 if ((mask & constant) != mask)
2516 warning ("comparison of promoted ~unsigned with constant");
2519 else if (unsignedp0 && unsignedp1
2520 && (TYPE_PRECISION (TREE_TYPE (primop0))
2521 < TYPE_PRECISION (result_type))
2522 && (TYPE_PRECISION (TREE_TYPE (primop1))
2523 < TYPE_PRECISION (result_type)))
2524 warning ("comparison of promoted ~unsigned with unsigned");
2530 /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
2531 If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
2532 Then the expression will be built.
2533 It will be given type FINAL_TYPE if that is nonzero;
2534 otherwise, it will be given type RESULT_TYPE. */
2536 if (!result_type)
2538 binary_op_error (code);
2539 return error_mark_node;
2542 if (! converted)
2544 if (TREE_TYPE (op0) != result_type)
2545 op0 = convert (result_type, op0);
2546 if (TREE_TYPE (op1) != result_type)
2547 op1 = convert (result_type, op1);
2550 if (build_type == NULL_TREE)
2551 build_type = result_type;
2554 register tree result = build (resultcode, build_type, op0, op1);
2555 register tree folded;
2557 folded = fold (result);
2558 if (folded == result)
2559 TREE_CONSTANT (folded) = TREE_CONSTANT (op0) & TREE_CONSTANT (op1);
2560 if (final_type != 0)
2561 return convert (final_type, folded);
2562 return folded;
2566 /* Return a tree for the sum or difference (RESULTCODE says which)
2567 of pointer PTROP and integer INTOP. */
2569 static tree
2570 pointer_int_sum (resultcode, ptrop, intop)
2571 enum tree_code resultcode;
2572 register tree ptrop, intop;
2574 tree size_exp;
2576 register tree result;
2577 register tree folded;
2579 /* The result is a pointer of the same type that is being added. */
2581 register tree result_type = TREE_TYPE (ptrop);
2583 if (TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE)
2585 if (pedantic || warn_pointer_arith)
2586 pedwarn ("pointer of type `void *' used in arithmetic");
2587 size_exp = integer_one_node;
2589 else if (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE)
2591 if (pedantic || warn_pointer_arith)
2592 pedwarn ("pointer to a function used in arithmetic");
2593 size_exp = integer_one_node;
2595 else
2596 size_exp = c_size_in_bytes (TREE_TYPE (result_type));
2598 /* If what we are about to multiply by the size of the elements
2599 contains a constant term, apply distributive law
2600 and multiply that constant term separately.
2601 This helps produce common subexpressions. */
2603 if ((TREE_CODE (intop) == PLUS_EXPR || TREE_CODE (intop) == MINUS_EXPR)
2604 && ! TREE_CONSTANT (intop)
2605 && TREE_CONSTANT (TREE_OPERAND (intop, 1))
2606 && TREE_CONSTANT (size_exp)
2607 /* If the constant comes from pointer subtraction,
2608 skip this optimization--it would cause an error. */
2609 && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop, 0))) == INTEGER_TYPE
2610 /* If the constant is unsigned, and smaller than the pointer size,
2611 then we must skip this optimization. This is because it could cause
2612 an overflow error if the constant is negative but INTOP is not. */
2613 && (! TREE_UNSIGNED (TREE_TYPE (intop))
2614 || (TYPE_PRECISION (TREE_TYPE (intop))
2615 == TYPE_PRECISION (TREE_TYPE (ptrop)))))
2617 enum tree_code subcode = resultcode;
2618 tree int_type = TREE_TYPE (intop);
2619 if (TREE_CODE (intop) == MINUS_EXPR)
2620 subcode = (subcode == PLUS_EXPR ? MINUS_EXPR : PLUS_EXPR);
2621 /* Convert both subexpression types to the type of intop,
2622 because weird cases involving pointer arithmetic
2623 can result in a sum or difference with different type args. */
2624 ptrop = build_binary_op (subcode, ptrop,
2625 convert (int_type, TREE_OPERAND (intop, 1)), 1);
2626 intop = convert (int_type, TREE_OPERAND (intop, 0));
2629 /* Convert the integer argument to a type the same size as sizetype
2630 so the multiply won't overflow spuriously. */
2632 if (TYPE_PRECISION (TREE_TYPE (intop)) != TYPE_PRECISION (sizetype)
2633 || TREE_UNSIGNED (TREE_TYPE (intop)) != TREE_UNSIGNED (sizetype))
2634 intop = convert (type_for_size (TYPE_PRECISION (sizetype),
2635 TREE_UNSIGNED (sizetype)), intop);
2637 /* Replace the integer argument with a suitable product by the object size.
2638 Do this multiplication as signed, then convert to the appropriate
2639 pointer type (actually unsigned integral). */
2641 intop = convert (result_type,
2642 build_binary_op (MULT_EXPR, intop,
2643 convert (TREE_TYPE (intop), size_exp), 1));
2645 /* Create the sum or difference. */
2647 result = build (resultcode, result_type, ptrop, intop);
2649 folded = fold (result);
2650 if (folded == result)
2651 TREE_CONSTANT (folded) = TREE_CONSTANT (ptrop) & TREE_CONSTANT (intop);
2652 return folded;
2655 /* Return a tree for the difference of pointers OP0 and OP1.
2656 The resulting tree has type int. */
2658 static tree
2659 pointer_diff (op0, op1)
2660 register tree op0, op1;
2662 register tree result, folded;
2663 tree restype = ptrdiff_type_node;
2665 tree target_type = TREE_TYPE (TREE_TYPE (op0));
2667 if (pedantic || warn_pointer_arith)
2669 if (TREE_CODE (target_type) == VOID_TYPE)
2670 pedwarn ("pointer of type `void *' used in subtraction");
2671 if (TREE_CODE (target_type) == FUNCTION_TYPE)
2672 pedwarn ("pointer to a function used in subtraction");
2675 /* First do the subtraction as integers;
2676 then drop through to build the divide operator.
2677 Do not do default conversions on the minus operator
2678 in case restype is a short type. */
2680 op0 = build_binary_op (MINUS_EXPR, convert (restype, op0),
2681 convert (restype, op1), 0);
2682 /* This generates an error if op1 is pointer to incomplete type. */
2683 if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (op1))) == 0)
2684 error ("arithmetic on pointer to an incomplete type");
2686 /* This generates an error if op0 is pointer to incomplete type. */
2687 op1 = c_size_in_bytes (target_type);
2689 /* Divide by the size, in easiest possible way. */
2691 result = build (EXACT_DIV_EXPR, restype, op0, convert (restype, op1));
2693 folded = fold (result);
2694 if (folded == result)
2695 TREE_CONSTANT (folded) = TREE_CONSTANT (op0) & TREE_CONSTANT (op1);
2696 return folded;
2699 /* Construct and perhaps optimize a tree representation
2700 for a unary operation. CODE, a tree_code, specifies the operation
2701 and XARG is the operand. NOCONVERT nonzero suppresses
2702 the default promotions (such as from short to int). */
2704 tree
2705 build_unary_op (code, xarg, noconvert)
2706 enum tree_code code;
2707 tree xarg;
2708 int noconvert;
2710 /* No default_conversion here. It causes trouble for ADDR_EXPR. */
2711 register tree arg = xarg;
2712 register tree argtype = 0;
2713 register enum tree_code typecode = TREE_CODE (TREE_TYPE (arg));
2714 tree val;
2716 if (typecode == ERROR_MARK)
2717 return error_mark_node;
2718 if (typecode == ENUMERAL_TYPE)
2719 typecode = INTEGER_TYPE;
2721 switch (code)
2723 case CONVERT_EXPR:
2724 /* This is used for unary plus, because a CONVERT_EXPR
2725 is enough to prevent anybody from looking inside for
2726 associativity, but won't generate any code. */
2727 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
2728 || typecode == COMPLEX_TYPE))
2730 error ("wrong type argument to unary plus");
2731 return error_mark_node;
2733 else if (!noconvert)
2734 arg = default_conversion (arg);
2735 break;
2737 case NEGATE_EXPR:
2738 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
2739 || typecode == COMPLEX_TYPE))
2741 error ("wrong type argument to unary minus");
2742 return error_mark_node;
2744 else if (!noconvert)
2745 arg = default_conversion (arg);
2746 break;
2748 case BIT_NOT_EXPR:
2749 if (typecode == COMPLEX_TYPE)
2751 code = CONJ_EXPR;
2752 if (!noconvert)
2753 arg = default_conversion (arg);
2755 else if (typecode != INTEGER_TYPE)
2757 error ("wrong type argument to bit-complement");
2758 return error_mark_node;
2760 else if (!noconvert)
2761 arg = default_conversion (arg);
2762 break;
2764 case ABS_EXPR:
2765 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
2766 || typecode == COMPLEX_TYPE))
2768 error ("wrong type argument to abs");
2769 return error_mark_node;
2771 else if (!noconvert)
2772 arg = default_conversion (arg);
2773 break;
2775 case CONJ_EXPR:
2776 /* Conjugating a real value is a no-op, but allow it anyway. */
2777 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
2778 || typecode == COMPLEX_TYPE))
2780 error ("wrong type argument to conjugation");
2781 return error_mark_node;
2783 else if (!noconvert)
2784 arg = default_conversion (arg);
2785 break;
2787 case TRUTH_NOT_EXPR:
2788 if (typecode != INTEGER_TYPE
2789 && typecode != REAL_TYPE && typecode != POINTER_TYPE
2790 && typecode != COMPLEX_TYPE
2791 /* These will convert to a pointer. */
2792 && typecode != ARRAY_TYPE && typecode != FUNCTION_TYPE)
2794 error ("wrong type argument to unary exclamation mark");
2795 return error_mark_node;
2797 arg = truthvalue_conversion (arg);
2798 return invert_truthvalue (arg);
2800 case NOP_EXPR:
2801 break;
2803 case REALPART_EXPR:
2804 if (TREE_CODE (arg) == COMPLEX_CST)
2805 return TREE_REALPART (arg);
2806 else if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE)
2807 return fold (build1 (REALPART_EXPR, TREE_TYPE (TREE_TYPE (arg)), arg));
2808 else
2809 return arg;
2811 case IMAGPART_EXPR:
2812 if (TREE_CODE (arg) == COMPLEX_CST)
2813 return TREE_IMAGPART (arg);
2814 else if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE)
2815 return fold (build1 (IMAGPART_EXPR, TREE_TYPE (TREE_TYPE (arg)), arg));
2816 else
2817 return convert (TREE_TYPE (arg), integer_zero_node);
2819 case PREINCREMENT_EXPR:
2820 case POSTINCREMENT_EXPR:
2821 case PREDECREMENT_EXPR:
2822 case POSTDECREMENT_EXPR:
2823 /* Handle complex lvalues (when permitted)
2824 by reduction to simpler cases. */
2826 val = unary_complex_lvalue (code, arg);
2827 if (val != 0)
2828 return val;
2830 /* Increment or decrement the real part of the value,
2831 and don't change the imaginary part. */
2832 if (typecode == COMPLEX_TYPE)
2834 tree real, imag;
2836 arg = stabilize_reference (arg);
2837 real = build_unary_op (REALPART_EXPR, arg, 1);
2838 imag = build_unary_op (IMAGPART_EXPR, arg, 1);
2839 return build (COMPLEX_EXPR, TREE_TYPE (arg),
2840 build_unary_op (code, real, 1), imag);
2843 /* Report invalid types. */
2845 if (typecode != POINTER_TYPE
2846 && typecode != INTEGER_TYPE && typecode != REAL_TYPE)
2848 error (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR
2849 ? "wrong type argument to increment"
2850 : "wrong type argument to decrement");
2851 return error_mark_node;
2855 register tree inc;
2856 tree result_type = TREE_TYPE (arg);
2858 arg = get_unwidened (arg, 0);
2859 argtype = TREE_TYPE (arg);
2861 /* Compute the increment. */
2863 if (typecode == POINTER_TYPE)
2865 /* If pointer target is an undefined struct,
2866 we just cannot know how to do the arithmetic. */
2867 if (TYPE_SIZE (TREE_TYPE (result_type)) == 0)
2868 error (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR
2869 ? "increment of pointer to unknown structure"
2870 : "decrement of pointer to unknown structure");
2871 else if ((pedantic || warn_pointer_arith)
2872 && (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE
2873 || TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE))
2874 pedwarn (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR
2875 ? "wrong type argument to increment"
2876 : "wrong type argument to decrement");
2877 inc = c_size_in_bytes (TREE_TYPE (result_type));
2879 else
2880 inc = integer_one_node;
2882 inc = convert (argtype, inc);
2884 /* Handle incrementing a cast-expression. */
2886 while (1)
2887 switch (TREE_CODE (arg))
2889 case NOP_EXPR:
2890 case CONVERT_EXPR:
2891 case FLOAT_EXPR:
2892 case FIX_TRUNC_EXPR:
2893 case FIX_FLOOR_EXPR:
2894 case FIX_ROUND_EXPR:
2895 case FIX_CEIL_EXPR:
2896 pedantic_lvalue_warning (CONVERT_EXPR);
2897 /* If the real type has the same machine representation
2898 as the type it is cast to, we can make better output
2899 by adding directly to the inside of the cast. */
2900 if ((TREE_CODE (TREE_TYPE (arg))
2901 == TREE_CODE (TREE_TYPE (TREE_OPERAND (arg, 0))))
2902 && (TYPE_MODE (TREE_TYPE (arg))
2903 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (arg, 0)))))
2904 arg = TREE_OPERAND (arg, 0);
2905 else
2907 tree incremented, modify, value;
2908 arg = stabilize_reference (arg);
2909 if (code == PREINCREMENT_EXPR || code == PREDECREMENT_EXPR)
2910 value = arg;
2911 else
2912 value = save_expr (arg);
2913 incremented = build (((code == PREINCREMENT_EXPR
2914 || code == POSTINCREMENT_EXPR)
2915 ? PLUS_EXPR : MINUS_EXPR),
2916 argtype, value, inc);
2917 TREE_SIDE_EFFECTS (incremented) = 1;
2918 modify = build_modify_expr (arg, NOP_EXPR, incremented);
2919 value = build (COMPOUND_EXPR, TREE_TYPE (arg), modify, value);
2920 TREE_USED (value) = 1;
2921 return value;
2923 break;
2925 default:
2926 goto give_up;
2928 give_up:
2930 /* Complain about anything else that is not a true lvalue. */
2931 if (!lvalue_or_else (arg, ((code == PREINCREMENT_EXPR
2932 || code == POSTINCREMENT_EXPR)
2933 ? "invalid lvalue in increment"
2934 : "invalid lvalue in decrement")))
2935 return error_mark_node;
2937 /* Report a read-only lvalue. */
2938 if (TREE_READONLY (arg))
2939 readonly_warning (arg,
2940 ((code == PREINCREMENT_EXPR
2941 || code == POSTINCREMENT_EXPR)
2942 ? "increment" : "decrement"));
2944 val = build (code, TREE_TYPE (arg), arg, inc);
2945 TREE_SIDE_EFFECTS (val) = 1;
2946 val = convert (result_type, val);
2947 if (TREE_CODE (val) != code)
2948 TREE_NO_UNUSED_WARNING (val) = 1;
2949 return val;
2952 case ADDR_EXPR:
2953 /* Note that this operation never does default_conversion
2954 regardless of NOCONVERT. */
2956 /* Let &* cancel out to simplify resulting code. */
2957 if (TREE_CODE (arg) == INDIRECT_REF)
2959 /* Don't let this be an lvalue. */
2960 if (lvalue_p (TREE_OPERAND (arg, 0)))
2961 return non_lvalue (TREE_OPERAND (arg, 0));
2962 return TREE_OPERAND (arg, 0);
2965 /* For &x[y], return x+y */
2966 if (TREE_CODE (arg) == ARRAY_REF)
2968 if (mark_addressable (TREE_OPERAND (arg, 0)) == 0)
2969 return error_mark_node;
2970 return build_binary_op (PLUS_EXPR, TREE_OPERAND (arg, 0),
2971 TREE_OPERAND (arg, 1), 1);
2974 /* Handle complex lvalues (when permitted)
2975 by reduction to simpler cases. */
2976 val = unary_complex_lvalue (code, arg);
2977 if (val != 0)
2978 return val;
2980 #if 0 /* Turned off because inconsistent;
2981 float f; *&(int)f = 3.4 stores in int format
2982 whereas (int)f = 3.4 stores in float format. */
2983 /* Address of a cast is just a cast of the address
2984 of the operand of the cast. */
2985 switch (TREE_CODE (arg))
2987 case NOP_EXPR:
2988 case CONVERT_EXPR:
2989 case FLOAT_EXPR:
2990 case FIX_TRUNC_EXPR:
2991 case FIX_FLOOR_EXPR:
2992 case FIX_ROUND_EXPR:
2993 case FIX_CEIL_EXPR:
2994 if (pedantic)
2995 pedwarn ("ANSI C forbids the address of a cast expression");
2996 return convert (build_pointer_type (TREE_TYPE (arg)),
2997 build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0),
2998 0));
3000 #endif
3002 /* Allow the address of a constructor if all the elements
3003 are constant. */
3004 if (TREE_CODE (arg) == CONSTRUCTOR && TREE_CONSTANT (arg))
3006 /* Anything not already handled and not a true memory reference
3007 is an error. */
3008 else if (typecode != FUNCTION_TYPE
3009 && !lvalue_or_else (arg, "invalid lvalue in unary `&'"))
3010 return error_mark_node;
3012 /* Ordinary case; arg is a COMPONENT_REF or a decl. */
3013 argtype = TREE_TYPE (arg);
3014 /* If the lvalue is const or volatile, merge that into the type
3015 to which the address will point. Note that you can't get a
3016 restricted pointer by taking the address of something, so we
3017 only have to deal with `const' and `volatile' here. */
3018 if (TREE_CODE_CLASS (TREE_CODE (arg)) == 'd'
3019 || TREE_CODE_CLASS (TREE_CODE (arg)) == 'r')
3021 if (TREE_READONLY (arg) || TREE_THIS_VOLATILE (arg))
3022 argtype = c_build_type_variant (argtype,
3023 TREE_READONLY (arg),
3024 TREE_THIS_VOLATILE (arg));
3027 argtype = build_pointer_type (argtype);
3029 if (mark_addressable (arg) == 0)
3030 return error_mark_node;
3033 tree addr;
3035 if (TREE_CODE (arg) == COMPONENT_REF)
3037 tree field = TREE_OPERAND (arg, 1);
3039 addr = build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0), 0);
3041 if (DECL_C_BIT_FIELD (field))
3043 error ("attempt to take address of bit-field structure member `%s'",
3044 IDENTIFIER_POINTER (DECL_NAME (field)));
3045 return error_mark_node;
3048 addr = convert (argtype, addr);
3050 if (! integer_zerop (DECL_FIELD_BITPOS (field)))
3052 tree offset
3053 = size_binop (EASY_DIV_EXPR, DECL_FIELD_BITPOS (field),
3054 size_int (BITS_PER_UNIT));
3055 int flag = TREE_CONSTANT (addr);
3056 addr = fold (build (PLUS_EXPR, argtype,
3057 addr, convert (argtype, offset)));
3058 TREE_CONSTANT (addr) = flag;
3061 else
3062 addr = build1 (code, argtype, arg);
3064 /* Address of a static or external variable or
3065 file-scope function counts as a constant. */
3066 if (staticp (arg)
3067 && ! (TREE_CODE (arg) == FUNCTION_DECL
3068 && DECL_CONTEXT (arg) != 0))
3069 TREE_CONSTANT (addr) = 1;
3070 return addr;
3073 default:
3074 break;
3077 if (argtype == 0)
3078 argtype = TREE_TYPE (arg);
3079 return fold (build1 (code, argtype, arg));
3082 #if 0
3083 /* If CONVERSIONS is a conversion expression or a nested sequence of such,
3084 convert ARG with the same conversions in the same order
3085 and return the result. */
3087 static tree
3088 convert_sequence (conversions, arg)
3089 tree conversions;
3090 tree arg;
3092 switch (TREE_CODE (conversions))
3094 case NOP_EXPR:
3095 case CONVERT_EXPR:
3096 case FLOAT_EXPR:
3097 case FIX_TRUNC_EXPR:
3098 case FIX_FLOOR_EXPR:
3099 case FIX_ROUND_EXPR:
3100 case FIX_CEIL_EXPR:
3101 return convert (TREE_TYPE (conversions),
3102 convert_sequence (TREE_OPERAND (conversions, 0),
3103 arg));
3105 default:
3106 return arg;
3109 #endif /* 0 */
3111 /* Return nonzero if REF is an lvalue valid for this language.
3112 Lvalues can be assigned, unless their type has TYPE_READONLY.
3113 Lvalues can have their address taken, unless they have DECL_REGISTER. */
3116 lvalue_p (ref)
3117 tree ref;
3119 register enum tree_code code = TREE_CODE (ref);
3121 switch (code)
3123 case REALPART_EXPR:
3124 case IMAGPART_EXPR:
3125 case COMPONENT_REF:
3126 return lvalue_p (TREE_OPERAND (ref, 0));
3128 case STRING_CST:
3129 return 1;
3131 case INDIRECT_REF:
3132 case ARRAY_REF:
3133 case VAR_DECL:
3134 case PARM_DECL:
3135 case RESULT_DECL:
3136 case ERROR_MARK:
3137 return (TREE_CODE (TREE_TYPE (ref)) != FUNCTION_TYPE
3138 && TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE);
3140 case BIND_EXPR:
3141 case RTL_EXPR:
3142 return TREE_CODE (TREE_TYPE (ref)) == ARRAY_TYPE;
3144 default:
3145 return 0;
3149 /* Return nonzero if REF is an lvalue valid for this language;
3150 otherwise, print an error message and return zero. */
3153 lvalue_or_else (ref, msgid)
3154 tree ref;
3155 const char *msgid;
3157 int win = lvalue_p (ref);
3158 if (! win)
3159 error (msgid);
3160 return win;
3163 /* Apply unary lvalue-demanding operator CODE to the expression ARG
3164 for certain kinds of expressions which are not really lvalues
3165 but which we can accept as lvalues.
3167 If ARG is not a kind of expression we can handle, return zero. */
3169 static tree
3170 unary_complex_lvalue (code, arg)
3171 enum tree_code code;
3172 tree arg;
3174 /* Handle (a, b) used as an "lvalue". */
3175 if (TREE_CODE (arg) == COMPOUND_EXPR)
3177 tree real_result = build_unary_op (code, TREE_OPERAND (arg, 1), 0);
3179 /* If this returns a function type, it isn't really being used as
3180 an lvalue, so don't issue a warning about it. */
3181 if (TREE_CODE (TREE_TYPE (arg)) != FUNCTION_TYPE)
3182 pedantic_lvalue_warning (COMPOUND_EXPR);
3184 return build (COMPOUND_EXPR, TREE_TYPE (real_result),
3185 TREE_OPERAND (arg, 0), real_result);
3188 /* Handle (a ? b : c) used as an "lvalue". */
3189 if (TREE_CODE (arg) == COND_EXPR)
3191 pedantic_lvalue_warning (COND_EXPR);
3192 if (TREE_CODE (TREE_TYPE (arg)) != FUNCTION_TYPE)
3193 pedantic_lvalue_warning (COMPOUND_EXPR);
3195 return (build_conditional_expr
3196 (TREE_OPERAND (arg, 0),
3197 build_unary_op (code, TREE_OPERAND (arg, 1), 0),
3198 build_unary_op (code, TREE_OPERAND (arg, 2), 0)));
3201 return 0;
3204 /* If pedantic, warn about improper lvalue. CODE is either COND_EXPR
3205 COMPOUND_EXPR, or CONVERT_EXPR (for casts). */
3207 static void
3208 pedantic_lvalue_warning (code)
3209 enum tree_code code;
3211 if (pedantic)
3212 pedwarn (code == COND_EXPR
3213 ? "ANSI C forbids use of conditional expressions as lvalues"
3214 : code == COMPOUND_EXPR
3215 ? "ANSI C forbids use of compound expressions as lvalues"
3216 : "ANSI C forbids use of cast expressions as lvalues");
3219 /* Warn about storing in something that is `const'. */
3221 void
3222 readonly_warning (arg, msgid)
3223 tree arg;
3224 const char *msgid;
3226 /* Forbid assignments to iterators. */
3227 if (TREE_CODE (arg) == VAR_DECL && ITERATOR_P (arg))
3228 pedwarn ("%s of iterator `%s'", _(msgid),
3229 IDENTIFIER_POINTER (DECL_NAME (arg)));
3231 if (TREE_CODE (arg) == COMPONENT_REF)
3233 if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg, 0))))
3234 readonly_warning (TREE_OPERAND (arg, 0), msgid);
3235 else
3236 pedwarn ("%s of read-only member `%s'", _(msgid),
3237 IDENTIFIER_POINTER (DECL_NAME (TREE_OPERAND (arg, 1))));
3239 else if (TREE_CODE (arg) == VAR_DECL)
3240 pedwarn ("%s of read-only variable `%s'", _(msgid),
3241 IDENTIFIER_POINTER (DECL_NAME (arg)));
3242 else
3243 pedwarn ("%s of read-only location", _(msgid));
3246 /* Mark EXP saying that we need to be able to take the
3247 address of it; it should not be allocated in a register.
3248 Value is 1 if successful. */
3251 mark_addressable (exp)
3252 tree exp;
3254 register tree x = exp;
3255 while (1)
3256 switch (TREE_CODE (x))
3258 case COMPONENT_REF:
3259 if (DECL_C_BIT_FIELD (TREE_OPERAND (x, 1)))
3261 error ("cannot take address of bitfield `%s'",
3262 IDENTIFIER_POINTER (DECL_NAME (TREE_OPERAND (x, 1))));
3263 return 0;
3266 /* ... fall through ... */
3268 case ADDR_EXPR:
3269 case ARRAY_REF:
3270 case REALPART_EXPR:
3271 case IMAGPART_EXPR:
3272 x = TREE_OPERAND (x, 0);
3273 break;
3275 case CONSTRUCTOR:
3276 TREE_ADDRESSABLE (x) = 1;
3277 return 1;
3279 case VAR_DECL:
3280 case CONST_DECL:
3281 case PARM_DECL:
3282 case RESULT_DECL:
3283 if (DECL_REGISTER (x) && !TREE_ADDRESSABLE (x)
3284 && DECL_NONLOCAL (x))
3286 if (TREE_PUBLIC (x))
3288 error ("global register variable `%s' used in nested function",
3289 IDENTIFIER_POINTER (DECL_NAME (x)));
3290 return 0;
3292 pedwarn ("register variable `%s' used in nested function",
3293 IDENTIFIER_POINTER (DECL_NAME (x)));
3295 else if (DECL_REGISTER (x) && !TREE_ADDRESSABLE (x))
3297 if (TREE_PUBLIC (x))
3299 error ("address of global register variable `%s' requested",
3300 IDENTIFIER_POINTER (DECL_NAME (x)));
3301 return 0;
3304 /* If we are making this addressable due to its having
3305 volatile components, give a different error message. Also
3306 handle the case of an unnamed parameter by not trying
3307 to give the name. */
3309 else if (C_TYPE_FIELDS_VOLATILE (TREE_TYPE (x)))
3311 error ("cannot put object with volatile field into register");
3312 return 0;
3315 pedwarn ("address of register variable `%s' requested",
3316 IDENTIFIER_POINTER (DECL_NAME (x)));
3318 put_var_into_stack (x);
3320 /* drops in */
3321 case FUNCTION_DECL:
3322 TREE_ADDRESSABLE (x) = 1;
3323 #if 0 /* poplevel deals with this now. */
3324 if (DECL_CONTEXT (x) == 0)
3325 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (x)) = 1;
3326 #endif
3328 default:
3329 return 1;
3333 /* Build and return a conditional expression IFEXP ? OP1 : OP2. */
3335 tree
3336 build_conditional_expr (ifexp, op1, op2)
3337 tree ifexp, op1, op2;
3339 register tree type1;
3340 register tree type2;
3341 register enum tree_code code1;
3342 register enum tree_code code2;
3343 register tree result_type = NULL;
3344 tree orig_op1 = op1, orig_op2 = op2;
3346 ifexp = truthvalue_conversion (default_conversion (ifexp));
3348 #if 0 /* Produces wrong result if within sizeof. */
3349 /* Don't promote the operands separately if they promote
3350 the same way. Return the unpromoted type and let the combined
3351 value get promoted if necessary. */
3353 if (TREE_TYPE (op1) == TREE_TYPE (op2)
3354 && TREE_CODE (TREE_TYPE (op1)) != ARRAY_TYPE
3355 && TREE_CODE (TREE_TYPE (op1)) != ENUMERAL_TYPE
3356 && TREE_CODE (TREE_TYPE (op1)) != FUNCTION_TYPE)
3358 if (TREE_CODE (ifexp) == INTEGER_CST)
3359 return pedantic_non_lvalue (integer_zerop (ifexp) ? op2 : op1);
3361 return fold (build (COND_EXPR, TREE_TYPE (op1), ifexp, op1, op2));
3363 #endif
3365 /* Promote both alternatives. */
3367 if (TREE_CODE (TREE_TYPE (op1)) != VOID_TYPE)
3368 op1 = default_conversion (op1);
3369 if (TREE_CODE (TREE_TYPE (op2)) != VOID_TYPE)
3370 op2 = default_conversion (op2);
3372 if (TREE_CODE (ifexp) == ERROR_MARK
3373 || TREE_CODE (TREE_TYPE (op1)) == ERROR_MARK
3374 || TREE_CODE (TREE_TYPE (op2)) == ERROR_MARK)
3375 return error_mark_node;
3377 type1 = TREE_TYPE (op1);
3378 code1 = TREE_CODE (type1);
3379 type2 = TREE_TYPE (op2);
3380 code2 = TREE_CODE (type2);
3382 /* Quickly detect the usual case where op1 and op2 have the same type
3383 after promotion. */
3384 if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2))
3386 if (type1 == type2)
3387 result_type = type1;
3388 else
3389 result_type = TYPE_MAIN_VARIANT (type1);
3391 else if ((code1 == INTEGER_TYPE || code1 == REAL_TYPE)
3392 && (code2 == INTEGER_TYPE || code2 == REAL_TYPE))
3394 result_type = common_type (type1, type2);
3396 else if (code1 == VOID_TYPE || code2 == VOID_TYPE)
3398 if (pedantic && (code1 != VOID_TYPE || code2 != VOID_TYPE))
3399 pedwarn ("ANSI C forbids conditional expr with only one void side");
3400 result_type = void_type_node;
3402 else if (code1 == POINTER_TYPE && code2 == POINTER_TYPE)
3404 if (comp_target_types (type1, type2))
3405 result_type = common_type (type1, type2);
3406 else if (integer_zerop (op1) && TREE_TYPE (type1) == void_type_node
3407 && TREE_CODE (orig_op1) != NOP_EXPR)
3408 result_type = qualify_type (type2, type1);
3409 else if (integer_zerop (op2) && TREE_TYPE (type2) == void_type_node
3410 && TREE_CODE (orig_op2) != NOP_EXPR)
3411 result_type = qualify_type (type1, type2);
3412 else if (TYPE_MAIN_VARIANT (TREE_TYPE (type1)) == void_type_node)
3414 if (pedantic && TREE_CODE (TREE_TYPE (type2)) == FUNCTION_TYPE)
3415 pedwarn ("ANSI C forbids conditional expr between `void *' and function pointer");
3416 result_type = qualify_type (type1, type2);
3418 else if (TYPE_MAIN_VARIANT (TREE_TYPE (type2)) == void_type_node)
3420 if (pedantic && TREE_CODE (TREE_TYPE (type1)) == FUNCTION_TYPE)
3421 pedwarn ("ANSI C forbids conditional expr between `void *' and function pointer");
3422 result_type = qualify_type (type2, type1);
3424 else
3426 pedwarn ("pointer type mismatch in conditional expression");
3427 result_type = build_pointer_type (void_type_node);
3430 else if (code1 == POINTER_TYPE && code2 == INTEGER_TYPE)
3432 if (! integer_zerop (op2))
3433 pedwarn ("pointer/integer type mismatch in conditional expression");
3434 else
3436 op2 = null_pointer_node;
3437 #if 0 /* The spec seems to say this is permitted. */
3438 if (pedantic && TREE_CODE (type1) == FUNCTION_TYPE)
3439 pedwarn ("ANSI C forbids conditional expr between 0 and function pointer");
3440 #endif
3442 result_type = type1;
3444 else if (code2 == POINTER_TYPE && code1 == INTEGER_TYPE)
3446 if (!integer_zerop (op1))
3447 pedwarn ("pointer/integer type mismatch in conditional expression");
3448 else
3450 op1 = null_pointer_node;
3451 #if 0 /* The spec seems to say this is permitted. */
3452 if (pedantic && TREE_CODE (type2) == FUNCTION_TYPE)
3453 pedwarn ("ANSI C forbids conditional expr between 0 and function pointer");
3454 #endif
3456 result_type = type2;
3459 if (!result_type)
3461 if (flag_cond_mismatch)
3462 result_type = void_type_node;
3463 else
3465 error ("type mismatch in conditional expression");
3466 return error_mark_node;
3470 /* Merge const and volatile flags of the incoming types. */
3471 result_type
3472 = build_type_variant (result_type,
3473 TREE_READONLY (op1) || TREE_READONLY (op2),
3474 TREE_THIS_VOLATILE (op1) || TREE_THIS_VOLATILE (op2));
3476 if (result_type != TREE_TYPE (op1))
3477 op1 = convert_and_check (result_type, op1);
3478 if (result_type != TREE_TYPE (op2))
3479 op2 = convert_and_check (result_type, op2);
3481 #if 0
3482 if (code1 == RECORD_TYPE || code1 == UNION_TYPE)
3484 result_type = TREE_TYPE (op1);
3485 if (TREE_CONSTANT (ifexp))
3486 return pedantic_non_lvalue (integer_zerop (ifexp) ? op2 : op1);
3488 if (TYPE_MODE (result_type) == BLKmode)
3490 register tree tempvar
3491 = build_decl (VAR_DECL, NULL_TREE, result_type);
3492 register tree xop1 = build_modify_expr (tempvar, op1);
3493 register tree xop2 = build_modify_expr (tempvar, op2);
3494 register tree result = fold (build (COND_EXPR, result_type,
3495 ifexp, xop1, xop2));
3497 layout_decl (tempvar, TYPE_ALIGN (result_type));
3498 /* No way to handle variable-sized objects here.
3499 I fear that the entire handling of BLKmode conditional exprs
3500 needs to be redone. */
3501 if (TREE_CODE (DECL_SIZE (tempvar)) != INTEGER_CST)
3502 abort ();
3503 DECL_RTL (tempvar)
3504 = assign_stack_local (DECL_MODE (tempvar),
3505 (TREE_INT_CST_LOW (DECL_SIZE (tempvar))
3506 + BITS_PER_UNIT - 1)
3507 / BITS_PER_UNIT,
3510 TREE_SIDE_EFFECTS (result)
3511 = TREE_SIDE_EFFECTS (ifexp) | TREE_SIDE_EFFECTS (op1)
3512 | TREE_SIDE_EFFECTS (op2);
3513 return build (COMPOUND_EXPR, result_type, result, tempvar);
3516 #endif /* 0 */
3518 if (TREE_CODE (ifexp) == INTEGER_CST)
3519 return pedantic_non_lvalue (integer_zerop (ifexp) ? op2 : op1);
3521 return fold (build (COND_EXPR, result_type, ifexp, op1, op2));
3524 /* Given a list of expressions, return a compound expression
3525 that performs them all and returns the value of the last of them. */
3527 tree
3528 build_compound_expr (list)
3529 tree list;
3531 return internal_build_compound_expr (list, TRUE);
3534 static tree
3535 internal_build_compound_expr (list, first_p)
3536 tree list;
3537 int first_p;
3539 register tree rest;
3541 if (TREE_CHAIN (list) == 0)
3543 #if 0 /* If something inside inhibited lvalueness, we should not override. */
3544 /* Consider (x, y+0), which is not an lvalue since y+0 is not. */
3546 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
3547 if (TREE_CODE (list) == NON_LVALUE_EXPR)
3548 list = TREE_OPERAND (list, 0);
3549 #endif
3551 /* Don't let (0, 0) be null pointer constant. */
3552 if (!first_p && integer_zerop (TREE_VALUE (list)))
3553 return non_lvalue (TREE_VALUE (list));
3554 return TREE_VALUE (list);
3557 if (TREE_CHAIN (list) != 0 && TREE_CHAIN (TREE_CHAIN (list)) == 0)
3559 /* Convert arrays to pointers when there really is a comma operator. */
3560 if (TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (list)))) == ARRAY_TYPE)
3561 TREE_VALUE (TREE_CHAIN (list))
3562 = default_conversion (TREE_VALUE (TREE_CHAIN (list)));
3565 rest = internal_build_compound_expr (TREE_CHAIN (list), FALSE);
3567 if (! TREE_SIDE_EFFECTS (TREE_VALUE (list)))
3569 /* The left-hand operand of a comma expression is like an expression
3570 statement: with -W or -Wunused, we should warn if it doesn't have
3571 any side-effects, unless it was explicitly cast to (void). */
3572 if ((extra_warnings || warn_unused)
3573 && ! (TREE_CODE (TREE_VALUE (list)) == CONVERT_EXPR
3574 && TREE_TYPE (TREE_VALUE (list)) == void_type_node))
3575 warning ("left-hand operand of comma expression has no effect");
3577 /* When pedantic, a compound expression can be neither an lvalue
3578 nor an integer constant expression. */
3579 if (! pedantic)
3580 return rest;
3583 /* With -Wunused, we should also warn if the left-hand operand does have
3584 side-effects, but computes a value which is not used. For example, in
3585 `foo() + bar(), baz()' the result of the `+' operator is not used,
3586 so we should issue a warning. */
3587 else if (warn_unused)
3588 warn_if_unused_value (TREE_VALUE (list));
3590 return build (COMPOUND_EXPR, TREE_TYPE (rest), TREE_VALUE (list), rest);
3593 /* Build an expression representing a cast to type TYPE of expression EXPR. */
3595 tree
3596 build_c_cast (type, expr)
3597 register tree type;
3598 tree expr;
3600 register tree value = expr;
3602 if (type == error_mark_node || expr == error_mark_node)
3603 return error_mark_node;
3604 type = TYPE_MAIN_VARIANT (type);
3606 #if 0
3607 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
3608 if (TREE_CODE (value) == NON_LVALUE_EXPR)
3609 value = TREE_OPERAND (value, 0);
3610 #endif
3612 if (TREE_CODE (type) == ARRAY_TYPE)
3614 error ("cast specifies array type");
3615 return error_mark_node;
3618 if (TREE_CODE (type) == FUNCTION_TYPE)
3620 error ("cast specifies function type");
3621 return error_mark_node;
3624 if (type == TREE_TYPE (value))
3626 if (pedantic)
3628 if (TREE_CODE (type) == RECORD_TYPE
3629 || TREE_CODE (type) == UNION_TYPE)
3630 pedwarn ("ANSI C forbids casting nonscalar to the same type");
3633 else if (TREE_CODE (type) == UNION_TYPE)
3635 tree field;
3636 if (TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE
3637 || TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE)
3638 value = default_conversion (value);
3640 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
3641 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (field)),
3642 TYPE_MAIN_VARIANT (TREE_TYPE (value))))
3643 break;
3645 if (field)
3647 const char *name;
3648 tree t;
3650 if (pedantic)
3651 pedwarn ("ANSI C forbids casts to union type");
3652 if (TYPE_NAME (type) != 0)
3654 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
3655 name = IDENTIFIER_POINTER (TYPE_NAME (type));
3656 else
3657 name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
3659 else
3660 name = "";
3661 t = digest_init (type, build (CONSTRUCTOR, type, NULL_TREE,
3662 build_tree_list (field, value)),
3663 0, 0);
3664 TREE_CONSTANT (t) = TREE_CONSTANT (value);
3665 return t;
3667 error ("cast to union type from type not present in union");
3668 return error_mark_node;
3670 else
3672 tree otype, ovalue;
3674 /* If casting to void, avoid the error that would come
3675 from default_conversion in the case of a non-lvalue array. */
3676 if (type == void_type_node)
3677 return build1 (CONVERT_EXPR, type, value);
3679 /* Convert functions and arrays to pointers,
3680 but don't convert any other types. */
3681 if (TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE
3682 || TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE)
3683 value = default_conversion (value);
3684 otype = TREE_TYPE (value);
3686 /* Optionally warn about potentially worrisome casts. */
3688 if (warn_cast_qual
3689 && TREE_CODE (type) == POINTER_TYPE
3690 && TREE_CODE (otype) == POINTER_TYPE)
3692 /* Go to the innermost object being pointed to. */
3693 tree in_type = type;
3694 tree in_otype = otype;
3696 while (TREE_CODE (in_type) == POINTER_TYPE)
3697 in_type = TREE_TYPE (in_type);
3698 while (TREE_CODE (in_otype) == POINTER_TYPE)
3699 in_otype = TREE_TYPE (in_otype);
3701 if (TYPE_QUALS (in_otype) & ~TYPE_QUALS (in_type))
3702 /* There are qualifiers present in IN_OTYPE that are not
3703 present in IN_TYPE. */
3704 pedwarn ("cast discards qualifiers from pointer target type");
3707 /* Warn about possible alignment problems. */
3708 if (STRICT_ALIGNMENT && warn_cast_align
3709 && TREE_CODE (type) == POINTER_TYPE
3710 && TREE_CODE (otype) == POINTER_TYPE
3711 && TREE_CODE (TREE_TYPE (otype)) != VOID_TYPE
3712 && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
3713 /* Don't warn about opaque types, where the actual alignment
3714 restriction is unknown. */
3715 && !((TREE_CODE (TREE_TYPE (otype)) == UNION_TYPE
3716 || TREE_CODE (TREE_TYPE (otype)) == RECORD_TYPE)
3717 && TYPE_MODE (TREE_TYPE (otype)) == VOIDmode)
3718 && TYPE_ALIGN (TREE_TYPE (type)) > TYPE_ALIGN (TREE_TYPE (otype)))
3719 warning ("cast increases required alignment of target type");
3721 if (TREE_CODE (type) == INTEGER_TYPE
3722 && TREE_CODE (otype) == POINTER_TYPE
3723 && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
3724 && !TREE_CONSTANT (value))
3725 warning ("cast from pointer to integer of different size");
3727 if (warn_bad_function_cast
3728 && TREE_CODE (value) == CALL_EXPR
3729 && TREE_CODE (type) != TREE_CODE (otype))
3730 warning ("cast does not match function type");
3732 if (TREE_CODE (type) == POINTER_TYPE
3733 && TREE_CODE (otype) == INTEGER_TYPE
3734 && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
3735 #if 0
3736 /* Don't warn about converting 0 to pointer,
3737 provided the 0 was explicit--not cast or made by folding. */
3738 && !(TREE_CODE (value) == INTEGER_CST && integer_zerop (value))
3739 #endif
3740 /* Don't warn about converting any constant. */
3741 && !TREE_CONSTANT (value))
3742 warning ("cast to pointer from integer of different size");
3744 ovalue = value;
3745 value = convert (type, value);
3747 /* Ignore any integer overflow caused by the cast. */
3748 if (TREE_CODE (value) == INTEGER_CST)
3750 TREE_OVERFLOW (value) = TREE_OVERFLOW (ovalue);
3751 TREE_CONSTANT_OVERFLOW (value) = TREE_CONSTANT_OVERFLOW (ovalue);
3755 /* Pedantically, don't ley (void *) (FOO *) 0 be a null pointer constant. */
3756 if (pedantic && TREE_CODE (value) == INTEGER_CST
3757 && TREE_CODE (expr) == INTEGER_CST
3758 && TREE_CODE (TREE_TYPE (expr)) != INTEGER_TYPE)
3759 value = non_lvalue (value);
3761 /* If pedantic, don't let a cast be an lvalue. */
3762 if (value == expr && pedantic)
3763 value = non_lvalue (value);
3765 return value;
3768 /* Build an assignment expression of lvalue LHS from value RHS.
3769 MODIFYCODE is the code for a binary operator that we use
3770 to combine the old value of LHS with RHS to get the new value.
3771 Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment. */
3773 tree
3774 build_modify_expr (lhs, modifycode, rhs)
3775 tree lhs, rhs;
3776 enum tree_code modifycode;
3778 register tree result;
3779 tree newrhs;
3780 tree lhstype = TREE_TYPE (lhs);
3781 tree olhstype = lhstype;
3783 /* Types that aren't fully specified cannot be used in assignments. */
3784 lhs = require_complete_type (lhs);
3786 /* Avoid duplicate error messages from operands that had errors. */
3787 if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK)
3788 return error_mark_node;
3790 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
3791 /* Do not use STRIP_NOPS here. We do not want an enumerator
3792 whose value is 0 to count as a null pointer constant. */
3793 if (TREE_CODE (rhs) == NON_LVALUE_EXPR)
3794 rhs = TREE_OPERAND (rhs, 0);
3796 newrhs = rhs;
3798 /* Handle control structure constructs used as "lvalues". */
3800 switch (TREE_CODE (lhs))
3802 /* Handle (a, b) used as an "lvalue". */
3803 case COMPOUND_EXPR:
3804 pedantic_lvalue_warning (COMPOUND_EXPR);
3805 newrhs = build_modify_expr (TREE_OPERAND (lhs, 1),
3806 modifycode, rhs);
3807 if (TREE_CODE (newrhs) == ERROR_MARK)
3808 return error_mark_node;
3809 return build (COMPOUND_EXPR, lhstype,
3810 TREE_OPERAND (lhs, 0), newrhs);
3812 /* Handle (a ? b : c) used as an "lvalue". */
3813 case COND_EXPR:
3814 pedantic_lvalue_warning (COND_EXPR);
3815 rhs = save_expr (rhs);
3817 /* Produce (a ? (b = rhs) : (c = rhs))
3818 except that the RHS goes through a save-expr
3819 so the code to compute it is only emitted once. */
3820 tree cond
3821 = build_conditional_expr (TREE_OPERAND (lhs, 0),
3822 build_modify_expr (TREE_OPERAND (lhs, 1),
3823 modifycode, rhs),
3824 build_modify_expr (TREE_OPERAND (lhs, 2),
3825 modifycode, rhs));
3826 if (TREE_CODE (cond) == ERROR_MARK)
3827 return cond;
3828 /* Make sure the code to compute the rhs comes out
3829 before the split. */
3830 return build (COMPOUND_EXPR, TREE_TYPE (lhs),
3831 /* But cast it to void to avoid an "unused" error. */
3832 convert (void_type_node, rhs), cond);
3834 default:
3835 break;
3838 /* If a binary op has been requested, combine the old LHS value with the RHS
3839 producing the value we should actually store into the LHS. */
3841 if (modifycode != NOP_EXPR)
3843 lhs = stabilize_reference (lhs);
3844 newrhs = build_binary_op (modifycode, lhs, rhs, 1);
3847 /* Handle a cast used as an "lvalue".
3848 We have already performed any binary operator using the value as cast.
3849 Now convert the result to the cast type of the lhs,
3850 and then true type of the lhs and store it there;
3851 then convert result back to the cast type to be the value
3852 of the assignment. */
3854 switch (TREE_CODE (lhs))
3856 case NOP_EXPR:
3857 case CONVERT_EXPR:
3858 case FLOAT_EXPR:
3859 case FIX_TRUNC_EXPR:
3860 case FIX_FLOOR_EXPR:
3861 case FIX_ROUND_EXPR:
3862 case FIX_CEIL_EXPR:
3863 if (TREE_CODE (TREE_TYPE (newrhs)) == ARRAY_TYPE
3864 || TREE_CODE (TREE_TYPE (newrhs)) == FUNCTION_TYPE)
3865 newrhs = default_conversion (newrhs);
3867 tree inner_lhs = TREE_OPERAND (lhs, 0);
3868 tree result;
3869 result = build_modify_expr (inner_lhs, NOP_EXPR,
3870 convert (TREE_TYPE (inner_lhs),
3871 convert (lhstype, newrhs)));
3872 if (TREE_CODE (result) == ERROR_MARK)
3873 return result;
3874 pedantic_lvalue_warning (CONVERT_EXPR);
3875 return convert (TREE_TYPE (lhs), result);
3878 default:
3879 break;
3882 /* Now we have handled acceptable kinds of LHS that are not truly lvalues.
3883 Reject anything strange now. */
3885 if (!lvalue_or_else (lhs, "invalid lvalue in assignment"))
3886 return error_mark_node;
3888 /* Warn about storing in something that is `const'. */
3890 if (TREE_READONLY (lhs) || TYPE_READONLY (lhstype)
3891 || ((TREE_CODE (lhstype) == RECORD_TYPE
3892 || TREE_CODE (lhstype) == UNION_TYPE)
3893 && C_TYPE_FIELDS_READONLY (lhstype)))
3894 readonly_warning (lhs, "assignment");
3896 /* If storing into a structure or union member,
3897 it has probably been given type `int'.
3898 Compute the type that would go with
3899 the actual amount of storage the member occupies. */
3901 if (TREE_CODE (lhs) == COMPONENT_REF
3902 && (TREE_CODE (lhstype) == INTEGER_TYPE
3903 || TREE_CODE (lhstype) == REAL_TYPE
3904 || TREE_CODE (lhstype) == ENUMERAL_TYPE))
3905 lhstype = TREE_TYPE (get_unwidened (lhs, 0));
3907 /* If storing in a field that is in actuality a short or narrower than one,
3908 we must store in the field in its actual type. */
3910 if (lhstype != TREE_TYPE (lhs))
3912 lhs = copy_node (lhs);
3913 TREE_TYPE (lhs) = lhstype;
3916 /* Convert new value to destination type. */
3918 newrhs = convert_for_assignment (lhstype, newrhs, _("assignment"),
3919 NULL_TREE, NULL_TREE, 0);
3920 if (TREE_CODE (newrhs) == ERROR_MARK)
3921 return error_mark_node;
3923 result = build (MODIFY_EXPR, lhstype, lhs, newrhs);
3924 TREE_SIDE_EFFECTS (result) = 1;
3926 /* If we got the LHS in a different type for storing in,
3927 convert the result back to the nominal type of LHS
3928 so that the value we return always has the same type
3929 as the LHS argument. */
3931 if (olhstype == TREE_TYPE (result))
3932 return result;
3933 return convert_for_assignment (olhstype, result, _("assignment"),
3934 NULL_TREE, NULL_TREE, 0);
3937 /* Convert value RHS to type TYPE as preparation for an assignment
3938 to an lvalue of type TYPE.
3939 The real work of conversion is done by `convert'.
3940 The purpose of this function is to generate error messages
3941 for assignments that are not allowed in C.
3942 ERRTYPE is a string to use in error messages:
3943 "assignment", "return", etc. If it is null, this is parameter passing
3944 for a function call (and different error messages are output).
3946 FUNNAME is the name of the function being called,
3947 as an IDENTIFIER_NODE, or null.
3948 PARMNUM is the number of the argument, for printing in error messages. */
3950 static tree
3951 convert_for_assignment (type, rhs, errtype, fundecl, funname, parmnum)
3952 tree type, rhs;
3953 const char *errtype;
3954 tree fundecl, funname;
3955 int parmnum;
3957 register enum tree_code codel = TREE_CODE (type);
3958 register tree rhstype;
3959 register enum tree_code coder;
3961 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
3962 /* Do not use STRIP_NOPS here. We do not want an enumerator
3963 whose value is 0 to count as a null pointer constant. */
3964 if (TREE_CODE (rhs) == NON_LVALUE_EXPR)
3965 rhs = TREE_OPERAND (rhs, 0);
3967 if (TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE
3968 || TREE_CODE (TREE_TYPE (rhs)) == FUNCTION_TYPE)
3969 rhs = default_conversion (rhs);
3970 else if (optimize && TREE_CODE (rhs) == VAR_DECL)
3971 rhs = decl_constant_value (rhs);
3973 rhstype = TREE_TYPE (rhs);
3974 coder = TREE_CODE (rhstype);
3976 if (coder == ERROR_MARK)
3977 return error_mark_node;
3979 if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype))
3981 overflow_warning (rhs);
3982 /* Check for Objective-C protocols. This will issue a warning if
3983 there are protocol violations. No need to use the return value. */
3984 maybe_objc_comptypes (type, rhstype, 0);
3985 return rhs;
3988 if (coder == VOID_TYPE)
3990 error ("void value not ignored as it ought to be");
3991 return error_mark_node;
3993 /* Arithmetic types all interconvert, and enum is treated like int. */
3994 if ((codel == INTEGER_TYPE || codel == REAL_TYPE || codel == ENUMERAL_TYPE
3995 || codel == COMPLEX_TYPE)
3996 && (coder == INTEGER_TYPE || coder == REAL_TYPE || coder == ENUMERAL_TYPE
3997 || coder == COMPLEX_TYPE))
3998 return convert_and_check (type, rhs);
4000 /* Conversion to a transparent union from its member types.
4001 This applies only to function arguments. */
4002 else if (codel == UNION_TYPE && TYPE_TRANSPARENT_UNION (type) && ! errtype)
4004 tree memb_types;
4005 tree marginal_memb_type = 0;
4007 for (memb_types = TYPE_FIELDS (type); memb_types;
4008 memb_types = TREE_CHAIN (memb_types))
4010 tree memb_type = TREE_TYPE (memb_types);
4012 if (comptypes (TYPE_MAIN_VARIANT (memb_type),
4013 TYPE_MAIN_VARIANT (rhstype)))
4014 break;
4016 if (TREE_CODE (memb_type) != POINTER_TYPE)
4017 continue;
4019 if (coder == POINTER_TYPE)
4021 register tree ttl = TREE_TYPE (memb_type);
4022 register tree ttr = TREE_TYPE (rhstype);
4024 /* Any non-function converts to a [const][volatile] void *
4025 and vice versa; otherwise, targets must be the same.
4026 Meanwhile, the lhs target must have all the qualifiers of
4027 the rhs. */
4028 if (TYPE_MAIN_VARIANT (ttl) == void_type_node
4029 || TYPE_MAIN_VARIANT (ttr) == void_type_node
4030 || comp_target_types (memb_type, rhstype))
4032 /* If this type won't generate any warnings, use it. */
4033 if (TYPE_QUALS (ttl) == TYPE_QUALS (ttr)
4034 || ((TREE_CODE (ttr) == FUNCTION_TYPE
4035 && TREE_CODE (ttl) == FUNCTION_TYPE)
4036 ? ((TYPE_QUALS (ttl) | TYPE_QUALS (ttr))
4037 == TYPE_QUALS (ttr))
4038 : ((TYPE_QUALS (ttl) | TYPE_QUALS (ttr))
4039 == TYPE_QUALS (ttl))))
4040 break;
4042 /* Keep looking for a better type, but remember this one. */
4043 if (! marginal_memb_type)
4044 marginal_memb_type = memb_type;
4048 /* Can convert integer zero to any pointer type. */
4049 if (integer_zerop (rhs)
4050 || (TREE_CODE (rhs) == NOP_EXPR
4051 && integer_zerop (TREE_OPERAND (rhs, 0))))
4053 rhs = null_pointer_node;
4054 break;
4058 if (memb_types || marginal_memb_type)
4060 if (! memb_types)
4062 /* We have only a marginally acceptable member type;
4063 it needs a warning. */
4064 register tree ttl = TREE_TYPE (marginal_memb_type);
4065 register tree ttr = TREE_TYPE (rhstype);
4067 /* Const and volatile mean something different for function
4068 types, so the usual warnings are not appropriate. */
4069 if (TREE_CODE (ttr) == FUNCTION_TYPE
4070 && TREE_CODE (ttl) == FUNCTION_TYPE)
4072 /* Because const and volatile on functions are
4073 restrictions that say the function will not do
4074 certain things, it is okay to use a const or volatile
4075 function where an ordinary one is wanted, but not
4076 vice-versa. */
4077 if (TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr))
4078 warn_for_assignment ("%s makes qualified function pointer from unqualified",
4079 errtype, funname, parmnum);
4081 else if (TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl))
4082 warn_for_assignment ("%s discards qualifiers from pointer target type",
4083 errtype, funname,
4084 parmnum);
4087 if (pedantic && ! DECL_IN_SYSTEM_HEADER (fundecl))
4088 pedwarn ("ANSI C prohibits argument conversion to union type");
4090 return build1 (NOP_EXPR, type, rhs);
4094 /* Conversions among pointers */
4095 else if (codel == POINTER_TYPE && coder == POINTER_TYPE)
4097 register tree ttl = TREE_TYPE (type);
4098 register tree ttr = TREE_TYPE (rhstype);
4100 /* Any non-function converts to a [const][volatile] void *
4101 and vice versa; otherwise, targets must be the same.
4102 Meanwhile, the lhs target must have all the qualifiers of the rhs. */
4103 if (TYPE_MAIN_VARIANT (ttl) == void_type_node
4104 || TYPE_MAIN_VARIANT (ttr) == void_type_node
4105 || comp_target_types (type, rhstype)
4106 || (unsigned_type (TYPE_MAIN_VARIANT (ttl))
4107 == unsigned_type (TYPE_MAIN_VARIANT (ttr))))
4109 if (pedantic
4110 && ((TYPE_MAIN_VARIANT (ttl) == void_type_node
4111 && TREE_CODE (ttr) == FUNCTION_TYPE)
4113 (TYPE_MAIN_VARIANT (ttr) == void_type_node
4114 /* Check TREE_CODE to catch cases like (void *) (char *) 0
4115 which are not ANSI null ptr constants. */
4116 && (!integer_zerop (rhs) || TREE_CODE (rhs) == NOP_EXPR)
4117 && TREE_CODE (ttl) == FUNCTION_TYPE)))
4118 warn_for_assignment ("ANSI forbids %s between function pointer and `void *'",
4119 errtype, funname, parmnum);
4120 /* Const and volatile mean something different for function types,
4121 so the usual warnings are not appropriate. */
4122 else if (TREE_CODE (ttr) != FUNCTION_TYPE
4123 && TREE_CODE (ttl) != FUNCTION_TYPE)
4125 if (TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl))
4126 warn_for_assignment ("%s discards qualifiers from pointer target type",
4127 errtype, funname, parmnum);
4128 /* If this is not a case of ignoring a mismatch in signedness,
4129 no warning. */
4130 else if (TYPE_MAIN_VARIANT (ttl) == void_type_node
4131 || TYPE_MAIN_VARIANT (ttr) == void_type_node
4132 || comp_target_types (type, rhstype))
4134 /* If there is a mismatch, do warn. */
4135 else if (pedantic)
4136 warn_for_assignment ("pointer targets in %s differ in signedness",
4137 errtype, funname, parmnum);
4139 else if (TREE_CODE (ttl) == FUNCTION_TYPE
4140 && TREE_CODE (ttr) == FUNCTION_TYPE)
4142 /* Because const and volatile on functions are restrictions
4143 that say the function will not do certain things,
4144 it is okay to use a const or volatile function
4145 where an ordinary one is wanted, but not vice-versa. */
4146 if (TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr))
4147 warn_for_assignment ("%s makes qualified function pointer from unqualified",
4148 errtype, funname, parmnum);
4151 else
4152 warn_for_assignment ("%s from incompatible pointer type",
4153 errtype, funname, parmnum);
4154 return convert (type, rhs);
4156 else if (codel == POINTER_TYPE && coder == INTEGER_TYPE)
4158 /* An explicit constant 0 can convert to a pointer,
4159 or one that results from arithmetic, even including
4160 a cast to integer type. */
4161 if (! (TREE_CODE (rhs) == INTEGER_CST && integer_zerop (rhs))
4163 ! (TREE_CODE (rhs) == NOP_EXPR
4164 && TREE_CODE (TREE_TYPE (rhs)) == INTEGER_TYPE
4165 && TREE_CODE (TREE_OPERAND (rhs, 0)) == INTEGER_CST
4166 && integer_zerop (TREE_OPERAND (rhs, 0))))
4168 warn_for_assignment ("%s makes pointer from integer without a cast",
4169 errtype, funname, parmnum);
4170 return convert (type, rhs);
4172 return null_pointer_node;
4174 else if (codel == INTEGER_TYPE && coder == POINTER_TYPE)
4176 warn_for_assignment ("%s makes integer from pointer without a cast",
4177 errtype, funname, parmnum);
4178 return convert (type, rhs);
4181 if (!errtype)
4183 if (funname)
4185 tree selector = maybe_building_objc_message_expr ();
4187 if (selector && parmnum > 2)
4188 error ("incompatible type for argument %d of `%s'",
4189 parmnum - 2, IDENTIFIER_POINTER (selector));
4190 else
4191 error ("incompatible type for argument %d of `%s'",
4192 parmnum, IDENTIFIER_POINTER (funname));
4194 else
4195 error ("incompatible type for argument %d of indirect function call",
4196 parmnum);
4198 else
4199 error ("incompatible types in %s", errtype);
4201 return error_mark_node;
4204 /* Print a warning using MSGID.
4205 It gets OPNAME as its one parameter.
4206 If OPNAME is null, it is replaced by "passing arg ARGNUM of `FUNCTION'".
4207 FUNCTION and ARGNUM are handled specially if we are building an
4208 Objective-C selector. */
4210 static void
4211 warn_for_assignment (msgid, opname, function, argnum)
4212 const char *msgid;
4213 const char *opname;
4214 tree function;
4215 int argnum;
4217 if (opname == 0)
4219 tree selector = maybe_building_objc_message_expr ();
4220 char * new_opname;
4222 if (selector && argnum > 2)
4224 function = selector;
4225 argnum -= 2;
4227 if (function)
4229 /* Function name is known; supply it. */
4230 const char *argstring = _("passing arg %d of `%s'");
4231 new_opname = (char *) alloca (IDENTIFIER_LENGTH (function)
4232 + strlen (argstring) + 1 + 25
4233 /*%d*/ + 1);
4234 sprintf (new_opname, argstring, argnum,
4235 IDENTIFIER_POINTER (function));
4237 else
4239 /* Function name unknown (call through ptr); just give arg number.*/
4240 const char *argnofun = _("passing arg %d of pointer to function");
4241 new_opname = (char *) alloca (strlen (argnofun) + 1 + 25 /*%d*/ + 1);
4242 sprintf (new_opname, argnofun, argnum);
4244 opname = new_opname;
4246 pedwarn (msgid, opname);
4249 /* Return nonzero if VALUE is a valid constant-valued expression
4250 for use in initializing a static variable; one that can be an
4251 element of a "constant" initializer.
4253 Return null_pointer_node if the value is absolute;
4254 if it is relocatable, return the variable that determines the relocation.
4255 We assume that VALUE has been folded as much as possible;
4256 therefore, we do not need to check for such things as
4257 arithmetic-combinations of integers. */
4259 tree
4260 initializer_constant_valid_p (value, endtype)
4261 tree value;
4262 tree endtype;
4264 switch (TREE_CODE (value))
4266 case CONSTRUCTOR:
4267 if ((TREE_CODE (TREE_TYPE (value)) == UNION_TYPE
4268 || TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE)
4269 && TREE_CONSTANT (value)
4270 && CONSTRUCTOR_ELTS (value))
4271 return
4272 initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value)),
4273 endtype);
4275 return TREE_STATIC (value) ? null_pointer_node : 0;
4277 case INTEGER_CST:
4278 case REAL_CST:
4279 case STRING_CST:
4280 case COMPLEX_CST:
4281 return null_pointer_node;
4283 case ADDR_EXPR:
4284 return TREE_OPERAND (value, 0);
4286 case NON_LVALUE_EXPR:
4287 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4289 case CONVERT_EXPR:
4290 case NOP_EXPR:
4291 /* Allow conversions between pointer types. */
4292 if (TREE_CODE (TREE_TYPE (value)) == POINTER_TYPE
4293 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == POINTER_TYPE)
4294 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4296 /* Allow conversions between real types. */
4297 if (TREE_CODE (TREE_TYPE (value)) == REAL_TYPE
4298 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == REAL_TYPE)
4299 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4301 /* Allow length-preserving conversions between integer types. */
4302 if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE
4303 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == INTEGER_TYPE
4304 && (TYPE_PRECISION (TREE_TYPE (value))
4305 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
4306 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4308 /* Allow conversions between other integer types only if
4309 explicit value. */
4310 if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE
4311 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == INTEGER_TYPE)
4313 tree inner = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4314 endtype);
4315 if (inner == null_pointer_node)
4316 return null_pointer_node;
4317 return 0;
4320 /* Allow (int) &foo provided int is as wide as a pointer. */
4321 if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE
4322 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == POINTER_TYPE
4323 && (TYPE_PRECISION (TREE_TYPE (value))
4324 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
4325 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4326 endtype);
4328 /* Likewise conversions from int to pointers, but also allow
4329 conversions from 0. */
4330 if (TREE_CODE (TREE_TYPE (value)) == POINTER_TYPE
4331 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == INTEGER_TYPE)
4333 if (integer_zerop (TREE_OPERAND (value, 0)))
4334 return null_pointer_node;
4335 else if (TYPE_PRECISION (TREE_TYPE (value))
4336 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0))))
4337 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4338 endtype);
4341 /* Allow conversions to union types if the value inside is okay. */
4342 if (TREE_CODE (TREE_TYPE (value)) == UNION_TYPE)
4343 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4344 endtype);
4345 return 0;
4347 case PLUS_EXPR:
4348 if (TREE_CODE (endtype) == INTEGER_TYPE
4349 && TYPE_PRECISION (endtype) < POINTER_SIZE)
4350 return 0;
4352 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4353 endtype);
4354 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
4355 endtype);
4356 /* If either term is absolute, use the other terms relocation. */
4357 if (valid0 == null_pointer_node)
4358 return valid1;
4359 if (valid1 == null_pointer_node)
4360 return valid0;
4361 return 0;
4364 case MINUS_EXPR:
4365 if (TREE_CODE (endtype) == INTEGER_TYPE
4366 && TYPE_PRECISION (endtype) < POINTER_SIZE)
4367 return 0;
4369 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4370 endtype);
4371 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
4372 endtype);
4373 /* Win if second argument is absolute. */
4374 if (valid1 == null_pointer_node)
4375 return valid0;
4376 /* Win if both arguments have the same relocation.
4377 Then the value is absolute. */
4378 if (valid0 == valid1)
4379 return null_pointer_node;
4380 return 0;
4383 default:
4384 return 0;
4388 /* If VALUE is a compound expr all of whose expressions are constant, then
4389 return its value. Otherwise, return error_mark_node.
4391 This is for handling COMPOUND_EXPRs as initializer elements
4392 which is allowed with a warning when -pedantic is specified. */
4394 static tree
4395 valid_compound_expr_initializer (value, endtype)
4396 tree value;
4397 tree endtype;
4399 if (TREE_CODE (value) == COMPOUND_EXPR)
4401 if (valid_compound_expr_initializer (TREE_OPERAND (value, 0), endtype)
4402 == error_mark_node)
4403 return error_mark_node;
4404 return valid_compound_expr_initializer (TREE_OPERAND (value, 1),
4405 endtype);
4407 else if (! TREE_CONSTANT (value)
4408 && ! initializer_constant_valid_p (value, endtype))
4409 return error_mark_node;
4410 else
4411 return value;
4414 /* Perform appropriate conversions on the initial value of a variable,
4415 store it in the declaration DECL,
4416 and print any error messages that are appropriate.
4417 If the init is invalid, store an ERROR_MARK. */
4419 void
4420 store_init_value (decl, init)
4421 tree decl, init;
4423 register tree value, type;
4425 /* If variable's type was invalidly declared, just ignore it. */
4427 type = TREE_TYPE (decl);
4428 if (TREE_CODE (type) == ERROR_MARK)
4429 return;
4431 /* Digest the specified initializer into an expression. */
4433 value = digest_init (type, init, TREE_STATIC (decl),
4434 TREE_STATIC (decl) || pedantic);
4436 /* Store the expression if valid; else report error. */
4438 #if 0
4439 /* Note that this is the only place we can detect the error
4440 in a case such as struct foo bar = (struct foo) { x, y };
4441 where there is one initial value which is a constructor expression. */
4442 if (value == error_mark_node)
4444 else if (TREE_STATIC (decl) && ! TREE_CONSTANT (value))
4446 error ("initializer for static variable is not constant");
4447 value = error_mark_node;
4449 else if (TREE_STATIC (decl)
4450 && initializer_constant_valid_p (value, TREE_TYPE (value)) == 0)
4452 error ("initializer for static variable uses complicated arithmetic");
4453 value = error_mark_node;
4455 else
4457 if (pedantic && TREE_CODE (value) == CONSTRUCTOR)
4459 if (! TREE_CONSTANT (value))
4460 pedwarn ("aggregate initializer is not constant");
4461 else if (! TREE_STATIC (value))
4462 pedwarn ("aggregate initializer uses complicated arithmetic");
4465 #endif
4467 DECL_INITIAL (decl) = value;
4469 /* ANSI wants warnings about out-of-range constant initializers. */
4470 STRIP_TYPE_NOPS (value);
4471 constant_expression_warning (value);
4474 /* Methods for storing and printing names for error messages. */
4476 /* Implement a spelling stack that allows components of a name to be pushed
4477 and popped. Each element on the stack is this structure. */
4479 struct spelling
4481 int kind;
4482 union
4484 int i;
4485 const char *s;
4486 } u;
4489 #define SPELLING_STRING 1
4490 #define SPELLING_MEMBER 2
4491 #define SPELLING_BOUNDS 3
4493 static struct spelling *spelling; /* Next stack element (unused). */
4494 static struct spelling *spelling_base; /* Spelling stack base. */
4495 static int spelling_size; /* Size of the spelling stack. */
4497 /* Macros to save and restore the spelling stack around push_... functions.
4498 Alternative to SAVE_SPELLING_STACK. */
4500 #define SPELLING_DEPTH() (spelling - spelling_base)
4501 #define RESTORE_SPELLING_DEPTH(depth) (spelling = spelling_base + depth)
4503 /* Save and restore the spelling stack around arbitrary C code. */
4505 #define SAVE_SPELLING_DEPTH(code) \
4507 int __depth = SPELLING_DEPTH (); \
4508 code; \
4509 RESTORE_SPELLING_DEPTH (__depth); \
4512 /* Push an element on the spelling stack with type KIND and assign VALUE
4513 to MEMBER. */
4515 #define PUSH_SPELLING(KIND, VALUE, MEMBER) \
4517 int depth = SPELLING_DEPTH (); \
4519 if (depth >= spelling_size) \
4521 spelling_size += 10; \
4522 if (spelling_base == 0) \
4523 spelling_base \
4524 = (struct spelling *) xmalloc (spelling_size * sizeof (struct spelling)); \
4525 else \
4526 spelling_base \
4527 = (struct spelling *) xrealloc (spelling_base, \
4528 spelling_size * sizeof (struct spelling)); \
4529 RESTORE_SPELLING_DEPTH (depth); \
4532 spelling->kind = (KIND); \
4533 spelling->MEMBER = (VALUE); \
4534 spelling++; \
4537 /* Push STRING on the stack. Printed literally. */
4539 static void
4540 push_string (string)
4541 const char *string;
4543 PUSH_SPELLING (SPELLING_STRING, string, u.s);
4546 /* Push a member name on the stack. Printed as '.' STRING. */
4548 static void
4549 push_member_name (decl)
4550 tree decl;
4553 const char *string
4554 = DECL_NAME (decl) ? IDENTIFIER_POINTER (DECL_NAME (decl)) : "<anonymous>";
4555 PUSH_SPELLING (SPELLING_MEMBER, string, u.s);
4558 /* Push an array bounds on the stack. Printed as [BOUNDS]. */
4560 static void
4561 push_array_bounds (bounds)
4562 int bounds;
4564 PUSH_SPELLING (SPELLING_BOUNDS, bounds, u.i);
4567 /* Compute the maximum size in bytes of the printed spelling. */
4569 static int
4570 spelling_length ()
4572 register int size = 0;
4573 register struct spelling *p;
4575 for (p = spelling_base; p < spelling; p++)
4577 if (p->kind == SPELLING_BOUNDS)
4578 size += 25;
4579 else
4580 size += strlen (p->u.s) + 1;
4583 return size;
4586 /* Print the spelling to BUFFER and return it. */
4588 static char *
4589 print_spelling (buffer)
4590 register char *buffer;
4592 register char *d = buffer;
4593 register struct spelling *p;
4595 for (p = spelling_base; p < spelling; p++)
4596 if (p->kind == SPELLING_BOUNDS)
4598 sprintf (d, "[%d]", p->u.i);
4599 d += strlen (d);
4601 else
4603 register const char *s;
4604 if (p->kind == SPELLING_MEMBER)
4605 *d++ = '.';
4606 for (s = p->u.s; (*d = *s++); d++)
4609 *d++ = '\0';
4610 return buffer;
4613 /* Issue an error message for a bad initializer component.
4614 MSGID identifies the message.
4615 The component name is taken from the spelling stack. */
4617 void
4618 error_init (msgid)
4619 const char *msgid;
4621 char *ofwhat;
4623 error (msgid);
4624 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
4625 if (*ofwhat)
4626 error ("(near initialization for `%s')", ofwhat);
4629 /* Issue a pedantic warning for a bad initializer component.
4630 MSGID identifies the message.
4631 The component name is taken from the spelling stack. */
4633 void
4634 pedwarn_init (msgid)
4635 const char *msgid;
4637 char *ofwhat;
4639 pedwarn (msgid);
4640 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
4641 if (*ofwhat)
4642 pedwarn ("(near initialization for `%s')", ofwhat);
4645 /* Issue a warning for a bad initializer component.
4646 MSGID identifies the message.
4647 The component name is taken from the spelling stack. */
4649 static void
4650 warning_init (msgid)
4651 const char *msgid;
4653 char *ofwhat;
4655 warning (msgid);
4656 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
4657 if (*ofwhat)
4658 warning ("(near initialization for `%s')", ofwhat);
4661 /* Digest the parser output INIT as an initializer for type TYPE.
4662 Return a C expression of type TYPE to represent the initial value.
4664 The arguments REQUIRE_CONSTANT and CONSTRUCTOR_CONSTANT request errors
4665 if non-constant initializers or elements are seen. CONSTRUCTOR_CONSTANT
4666 applies only to elements of constructors. */
4668 static tree
4669 digest_init (type, init, require_constant, constructor_constant)
4670 tree type, init;
4671 int require_constant, constructor_constant;
4673 enum tree_code code = TREE_CODE (type);
4674 tree inside_init = init;
4676 if (init == error_mark_node)
4677 return init;
4679 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
4680 /* Do not use STRIP_NOPS here. We do not want an enumerator
4681 whose value is 0 to count as a null pointer constant. */
4682 if (TREE_CODE (init) == NON_LVALUE_EXPR)
4683 inside_init = TREE_OPERAND (init, 0);
4685 /* Initialization of an array of chars from a string constant
4686 optionally enclosed in braces. */
4688 if (code == ARRAY_TYPE)
4690 tree typ1 = TYPE_MAIN_VARIANT (TREE_TYPE (type));
4691 if ((typ1 == char_type_node
4692 || typ1 == signed_char_type_node
4693 || typ1 == unsigned_char_type_node
4694 || typ1 == unsigned_wchar_type_node
4695 || typ1 == signed_wchar_type_node)
4696 && ((inside_init && TREE_CODE (inside_init) == STRING_CST)))
4698 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
4699 TYPE_MAIN_VARIANT (type)))
4700 return inside_init;
4702 if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init)))
4703 != char_type_node)
4704 && TYPE_PRECISION (typ1) == TYPE_PRECISION (char_type_node))
4706 error_init ("char-array initialized from wide string");
4707 return error_mark_node;
4709 if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init)))
4710 == char_type_node)
4711 && TYPE_PRECISION (typ1) != TYPE_PRECISION (char_type_node))
4713 error_init ("int-array initialized from non-wide string");
4714 return error_mark_node;
4717 TREE_TYPE (inside_init) = type;
4718 if (TYPE_DOMAIN (type) != 0
4719 && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
4721 register int size = TREE_INT_CST_LOW (TYPE_SIZE (type));
4722 size = (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
4723 /* Subtract 1 (or sizeof (wchar_t))
4724 because it's ok to ignore the terminating null char
4725 that is counted in the length of the constant. */
4726 if (size < TREE_STRING_LENGTH (inside_init)
4727 - (TYPE_PRECISION (typ1) != TYPE_PRECISION (char_type_node)
4728 ? TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT
4729 : 1))
4730 pedwarn_init ("initializer-string for array of chars is too long");
4732 return inside_init;
4736 /* Any type can be initialized
4737 from an expression of the same type, optionally with braces. */
4739 if (inside_init && TREE_TYPE (inside_init) != 0
4740 && (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
4741 TYPE_MAIN_VARIANT (type))
4742 || (code == ARRAY_TYPE
4743 && comptypes (TREE_TYPE (inside_init), type))
4744 || (code == POINTER_TYPE
4745 && (TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE
4746 || TREE_CODE (TREE_TYPE (inside_init)) == FUNCTION_TYPE)
4747 && comptypes (TREE_TYPE (TREE_TYPE (inside_init)),
4748 TREE_TYPE (type)))))
4750 if (code == POINTER_TYPE
4751 && (TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE
4752 || TREE_CODE (TREE_TYPE (inside_init)) == FUNCTION_TYPE))
4753 inside_init = default_conversion (inside_init);
4754 else if (code == ARRAY_TYPE && TREE_CODE (inside_init) != STRING_CST
4755 && TREE_CODE (inside_init) != CONSTRUCTOR)
4757 error_init ("array initialized from non-constant array expression");
4758 return error_mark_node;
4761 if (optimize && TREE_CODE (inside_init) == VAR_DECL)
4762 inside_init = decl_constant_value (inside_init);
4764 /* Compound expressions can only occur here if -pedantic or
4765 -pedantic-errors is specified. In the later case, we always want
4766 an error. In the former case, we simply want a warning. */
4767 if (require_constant && pedantic
4768 && TREE_CODE (inside_init) == COMPOUND_EXPR)
4770 inside_init
4771 = valid_compound_expr_initializer (inside_init,
4772 TREE_TYPE (inside_init));
4773 if (inside_init == error_mark_node)
4774 error_init ("initializer element is not constant");
4775 else
4776 pedwarn_init ("initializer element is not constant");
4777 if (flag_pedantic_errors)
4778 inside_init = error_mark_node;
4780 else if (require_constant && ! TREE_CONSTANT (inside_init))
4782 error_init ("initializer element is not constant");
4783 inside_init = error_mark_node;
4785 else if (require_constant
4786 && initializer_constant_valid_p (inside_init, TREE_TYPE (inside_init)) == 0)
4788 error_init ("initializer element is not computable at load time");
4789 inside_init = error_mark_node;
4792 return inside_init;
4795 /* Handle scalar types, including conversions. */
4797 if (code == INTEGER_TYPE || code == REAL_TYPE || code == POINTER_TYPE
4798 || code == ENUMERAL_TYPE || code == COMPLEX_TYPE)
4800 /* Note that convert_for_assignment calls default_conversion
4801 for arrays and functions. We must not call it in the
4802 case where inside_init is a null pointer constant. */
4803 inside_init
4804 = convert_for_assignment (type, init, _("initialization"),
4805 NULL_TREE, NULL_TREE, 0);
4807 if (require_constant && ! TREE_CONSTANT (inside_init))
4809 error_init ("initializer element is not constant");
4810 inside_init = error_mark_node;
4812 else if (require_constant
4813 && initializer_constant_valid_p (inside_init, TREE_TYPE (inside_init)) == 0)
4815 error_init ("initializer element is not computable at load time");
4816 inside_init = error_mark_node;
4819 return inside_init;
4822 /* Come here only for records and arrays. */
4824 if (TYPE_SIZE (type) && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
4826 error_init ("variable-sized object may not be initialized");
4827 return error_mark_node;
4830 /* Traditionally, you can write struct foo x = 0;
4831 and it initializes the first element of x to 0. */
4832 if (flag_traditional)
4834 tree top = 0, prev = 0, otype = type;
4835 while (TREE_CODE (type) == RECORD_TYPE
4836 || TREE_CODE (type) == ARRAY_TYPE
4837 || TREE_CODE (type) == QUAL_UNION_TYPE
4838 || TREE_CODE (type) == UNION_TYPE)
4840 tree temp = build (CONSTRUCTOR, type, NULL_TREE, NULL_TREE);
4841 if (prev == 0)
4842 top = temp;
4843 else
4844 TREE_OPERAND (prev, 1) = build_tree_list (NULL_TREE, temp);
4845 prev = temp;
4846 if (TREE_CODE (type) == ARRAY_TYPE)
4847 type = TREE_TYPE (type);
4848 else if (TYPE_FIELDS (type))
4849 type = TREE_TYPE (TYPE_FIELDS (type));
4850 else
4852 error_init ("invalid initializer");
4853 return error_mark_node;
4857 if (otype != type)
4859 TREE_OPERAND (prev, 1)
4860 = build_tree_list (NULL_TREE,
4861 digest_init (type, init, require_constant,
4862 constructor_constant));
4863 return top;
4865 else
4866 return error_mark_node;
4868 error_init ("invalid initializer");
4869 return error_mark_node;
4872 /* Handle initializers that use braces. */
4874 /* Type of object we are accumulating a constructor for.
4875 This type is always a RECORD_TYPE, UNION_TYPE or ARRAY_TYPE. */
4876 static tree constructor_type;
4878 /* For a RECORD_TYPE or UNION_TYPE, this is the chain of fields
4879 left to fill. */
4880 static tree constructor_fields;
4882 /* For an ARRAY_TYPE, this is the specified index
4883 at which to store the next element we get.
4884 This is a special INTEGER_CST node that we modify in place. */
4885 static tree constructor_index;
4887 /* For an ARRAY_TYPE, this is the end index of the range
4888 to initialize with the next element, or NULL in the ordinary case
4889 where the element is used just once. */
4890 static tree constructor_range_end;
4892 /* For an ARRAY_TYPE, this is the maximum index. */
4893 static tree constructor_max_index;
4895 /* For a RECORD_TYPE, this is the first field not yet written out. */
4896 static tree constructor_unfilled_fields;
4898 /* For an ARRAY_TYPE, this is the index of the first element
4899 not yet written out.
4900 This is a special INTEGER_CST node that we modify in place. */
4901 static tree constructor_unfilled_index;
4903 /* In a RECORD_TYPE, the byte index of the next consecutive field.
4904 This is so we can generate gaps between fields, when appropriate.
4905 This is a special INTEGER_CST node that we modify in place. */
4906 static tree constructor_bit_index;
4908 /* If we are saving up the elements rather than allocating them,
4909 this is the list of elements so far (in reverse order,
4910 most recent first). */
4911 static tree constructor_elements;
4913 /* 1 if so far this constructor's elements are all compile-time constants. */
4914 static int constructor_constant;
4916 /* 1 if so far this constructor's elements are all valid address constants. */
4917 static int constructor_simple;
4919 /* 1 if this constructor is erroneous so far. */
4920 static int constructor_erroneous;
4922 /* 1 if have called defer_addressed_constants. */
4923 static int constructor_subconstants_deferred;
4925 /* Structure for managing pending initializer elements, organized as an
4926 AVL tree. */
4928 struct init_node
4930 struct init_node *left, *right;
4931 struct init_node *parent;
4932 int balance;
4933 tree purpose;
4934 tree value;
4937 /* Tree of pending elements at this constructor level.
4938 These are elements encountered out of order
4939 which belong at places we haven't reached yet in actually
4940 writing the output. */
4941 static struct init_node *constructor_pending_elts;
4943 /* The SPELLING_DEPTH of this constructor. */
4944 static int constructor_depth;
4946 /* 0 if implicitly pushing constructor levels is allowed. */
4947 int constructor_no_implicit = 0; /* 0 for C; 1 for some other languages. */
4949 static int require_constant_value;
4950 static int require_constant_elements;
4952 /* 1 if it is ok to output this constructor as we read it.
4953 0 means must accumulate a CONSTRUCTOR expression. */
4954 static int constructor_incremental;
4956 /* DECL node for which an initializer is being read.
4957 0 means we are reading a constructor expression
4958 such as (struct foo) {...}. */
4959 static tree constructor_decl;
4961 /* start_init saves the ASMSPEC arg here for really_start_incremental_init. */
4962 static char *constructor_asmspec;
4964 /* Nonzero if this is an initializer for a top-level decl. */
4965 static int constructor_top_level;
4968 /* This stack has a level for each implicit or explicit level of
4969 structuring in the initializer, including the outermost one. It
4970 saves the values of most of the variables above. */
4972 struct constructor_stack
4974 struct constructor_stack *next;
4975 tree type;
4976 tree fields;
4977 tree index;
4978 tree range_end;
4979 tree max_index;
4980 tree unfilled_index;
4981 tree unfilled_fields;
4982 tree bit_index;
4983 tree elements;
4984 int offset;
4985 struct init_node *pending_elts;
4986 int depth;
4987 /* If nonzero, this value should replace the entire
4988 constructor at this level. */
4989 tree replacement_value;
4990 char constant;
4991 char simple;
4992 char implicit;
4993 char incremental;
4994 char erroneous;
4995 char outer;
4998 struct constructor_stack *constructor_stack;
5000 /* This stack records separate initializers that are nested.
5001 Nested initializers can't happen in ANSI C, but GNU C allows them
5002 in cases like { ... (struct foo) { ... } ... }. */
5004 struct initializer_stack
5006 struct initializer_stack *next;
5007 tree decl;
5008 char *asmspec;
5009 struct constructor_stack *constructor_stack;
5010 tree elements;
5011 struct spelling *spelling;
5012 struct spelling *spelling_base;
5013 int spelling_size;
5014 char top_level;
5015 char incremental;
5016 char require_constant_value;
5017 char require_constant_elements;
5018 char deferred;
5021 struct initializer_stack *initializer_stack;
5023 /* Prepare to parse and output the initializer for variable DECL. */
5025 void
5026 start_init (decl, asmspec_tree, top_level)
5027 tree decl;
5028 tree asmspec_tree;
5029 int top_level;
5031 const char *locus;
5032 struct initializer_stack *p
5033 = (struct initializer_stack *) xmalloc (sizeof (struct initializer_stack));
5034 char *asmspec = 0;
5036 if (asmspec_tree)
5037 asmspec = TREE_STRING_POINTER (asmspec_tree);
5039 p->decl = constructor_decl;
5040 p->asmspec = constructor_asmspec;
5041 p->incremental = constructor_incremental;
5042 p->require_constant_value = require_constant_value;
5043 p->require_constant_elements = require_constant_elements;
5044 p->constructor_stack = constructor_stack;
5045 p->elements = constructor_elements;
5046 p->spelling = spelling;
5047 p->spelling_base = spelling_base;
5048 p->spelling_size = spelling_size;
5049 p->deferred = constructor_subconstants_deferred;
5050 p->top_level = constructor_top_level;
5051 p->next = initializer_stack;
5052 initializer_stack = p;
5054 constructor_decl = decl;
5055 constructor_incremental = top_level;
5056 constructor_asmspec = asmspec;
5057 constructor_subconstants_deferred = 0;
5058 constructor_top_level = top_level;
5060 if (decl != 0)
5062 require_constant_value = TREE_STATIC (decl);
5063 require_constant_elements
5064 = ((TREE_STATIC (decl) || pedantic)
5065 /* For a scalar, you can always use any value to initialize,
5066 even within braces. */
5067 && (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
5068 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
5069 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
5070 || TREE_CODE (TREE_TYPE (decl)) == QUAL_UNION_TYPE));
5071 locus = IDENTIFIER_POINTER (DECL_NAME (decl));
5072 constructor_incremental |= TREE_STATIC (decl);
5074 else
5076 require_constant_value = 0;
5077 require_constant_elements = 0;
5078 locus = "(anonymous)";
5081 constructor_stack = 0;
5083 missing_braces_mentioned = 0;
5085 spelling_base = 0;
5086 spelling_size = 0;
5087 RESTORE_SPELLING_DEPTH (0);
5089 if (locus)
5090 push_string (locus);
5093 void
5094 finish_init ()
5096 struct initializer_stack *p = initializer_stack;
5098 /* Output subconstants (string constants, usually)
5099 that were referenced within this initializer and saved up.
5100 Must do this if and only if we called defer_addressed_constants. */
5101 if (constructor_subconstants_deferred)
5102 output_deferred_addressed_constants ();
5104 /* Free the whole constructor stack of this initializer. */
5105 while (constructor_stack)
5107 struct constructor_stack *q = constructor_stack;
5108 constructor_stack = q->next;
5109 free (q);
5112 /* Pop back to the data of the outer initializer (if any). */
5113 constructor_decl = p->decl;
5114 constructor_asmspec = p->asmspec;
5115 constructor_incremental = p->incremental;
5116 require_constant_value = p->require_constant_value;
5117 require_constant_elements = p->require_constant_elements;
5118 constructor_stack = p->constructor_stack;
5119 constructor_elements = p->elements;
5120 spelling = p->spelling;
5121 spelling_base = p->spelling_base;
5122 spelling_size = p->spelling_size;
5123 constructor_subconstants_deferred = p->deferred;
5124 constructor_top_level = p->top_level;
5125 initializer_stack = p->next;
5126 free (p);
5129 /* Call here when we see the initializer is surrounded by braces.
5130 This is instead of a call to push_init_level;
5131 it is matched by a call to pop_init_level.
5133 TYPE is the type to initialize, for a constructor expression.
5134 For an initializer for a decl, TYPE is zero. */
5136 void
5137 really_start_incremental_init (type)
5138 tree type;
5140 struct constructor_stack *p
5141 = (struct constructor_stack *) xmalloc (sizeof (struct constructor_stack));
5143 if (type == 0)
5144 type = TREE_TYPE (constructor_decl);
5146 /* Turn off constructor_incremental if type is a struct with bitfields.
5147 Do this before the first push, so that the corrected value
5148 is available in finish_init. */
5149 check_init_type_bitfields (type);
5151 p->type = constructor_type;
5152 p->fields = constructor_fields;
5153 p->index = constructor_index;
5154 p->range_end = constructor_range_end;
5155 p->max_index = constructor_max_index;
5156 p->unfilled_index = constructor_unfilled_index;
5157 p->unfilled_fields = constructor_unfilled_fields;
5158 p->bit_index = constructor_bit_index;
5159 p->elements = constructor_elements;
5160 p->constant = constructor_constant;
5161 p->simple = constructor_simple;
5162 p->erroneous = constructor_erroneous;
5163 p->pending_elts = constructor_pending_elts;
5164 p->depth = constructor_depth;
5165 p->replacement_value = 0;
5166 p->implicit = 0;
5167 p->incremental = constructor_incremental;
5168 p->outer = 0;
5169 p->next = 0;
5170 constructor_stack = p;
5172 constructor_constant = 1;
5173 constructor_simple = 1;
5174 constructor_depth = SPELLING_DEPTH ();
5175 constructor_elements = 0;
5176 constructor_pending_elts = 0;
5177 constructor_type = type;
5179 if (TREE_CODE (constructor_type) == RECORD_TYPE
5180 || TREE_CODE (constructor_type) == UNION_TYPE)
5182 constructor_fields = TYPE_FIELDS (constructor_type);
5183 /* Skip any nameless bit fields at the beginning. */
5184 while (constructor_fields != 0 && DECL_C_BIT_FIELD (constructor_fields)
5185 && DECL_NAME (constructor_fields) == 0)
5186 constructor_fields = TREE_CHAIN (constructor_fields);
5187 constructor_unfilled_fields = constructor_fields;
5188 constructor_bit_index = copy_node (integer_zero_node);
5189 TREE_TYPE (constructor_bit_index) = sbitsizetype;
5191 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5193 constructor_range_end = 0;
5194 if (TYPE_DOMAIN (constructor_type))
5196 constructor_max_index
5197 = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
5198 constructor_index
5199 = copy_node (TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
5201 else
5202 constructor_index = copy_node (integer_zero_node);
5203 constructor_unfilled_index = copy_node (constructor_index);
5205 else
5207 /* Handle the case of int x = {5}; */
5208 constructor_fields = constructor_type;
5209 constructor_unfilled_fields = constructor_type;
5212 if (constructor_incremental)
5214 int momentary = suspend_momentary ();
5215 push_obstacks_nochange ();
5216 if (TREE_PERMANENT (constructor_decl))
5217 end_temporary_allocation ();
5218 make_decl_rtl (constructor_decl, constructor_asmspec,
5219 constructor_top_level);
5220 assemble_variable (constructor_decl, constructor_top_level, 0, 1);
5221 pop_obstacks ();
5222 resume_momentary (momentary);
5225 if (constructor_incremental)
5227 defer_addressed_constants ();
5228 constructor_subconstants_deferred = 1;
5232 /* Push down into a subobject, for initialization.
5233 If this is for an explicit set of braces, IMPLICIT is 0.
5234 If it is because the next element belongs at a lower level,
5235 IMPLICIT is 1. */
5237 void
5238 push_init_level (implicit)
5239 int implicit;
5241 struct constructor_stack *p;
5243 /* If we've exhausted any levels that didn't have braces,
5244 pop them now. */
5245 while (constructor_stack->implicit)
5247 if ((TREE_CODE (constructor_type) == RECORD_TYPE
5248 || TREE_CODE (constructor_type) == UNION_TYPE)
5249 && constructor_fields == 0)
5250 process_init_element (pop_init_level (1));
5251 else if (TREE_CODE (constructor_type) == ARRAY_TYPE
5252 && tree_int_cst_lt (constructor_max_index, constructor_index))
5253 process_init_element (pop_init_level (1));
5254 else
5255 break;
5258 /* Structure elements may require alignment. Do this now if necessary
5259 for the subaggregate, and if it comes next in sequence. Don't do
5260 this for subaggregates that will go on the pending list. */
5261 if (constructor_incremental && constructor_type != 0
5262 && TREE_CODE (constructor_type) == RECORD_TYPE && constructor_fields
5263 && constructor_fields == constructor_unfilled_fields)
5265 /* Advance to offset of this element. */
5266 if (! tree_int_cst_equal (constructor_bit_index,
5267 DECL_FIELD_BITPOS (constructor_fields)))
5269 /* By using unsigned arithmetic, the result will be correct even
5270 in case of overflows, if BITS_PER_UNIT is a power of two. */
5271 unsigned next = (TREE_INT_CST_LOW
5272 (DECL_FIELD_BITPOS (constructor_fields))
5273 / (unsigned)BITS_PER_UNIT);
5274 unsigned here = (TREE_INT_CST_LOW (constructor_bit_index)
5275 / (unsigned)BITS_PER_UNIT);
5277 assemble_zeros ((next - here)
5278 * (unsigned)BITS_PER_UNIT
5279 / (unsigned)BITS_PER_UNIT);
5281 /* Indicate that we have now filled the structure up to the current
5282 field. */
5283 constructor_unfilled_fields = constructor_fields;
5286 p = (struct constructor_stack *) xmalloc (sizeof (struct constructor_stack));
5287 p->type = constructor_type;
5288 p->fields = constructor_fields;
5289 p->index = constructor_index;
5290 p->range_end = constructor_range_end;
5291 p->max_index = constructor_max_index;
5292 p->unfilled_index = constructor_unfilled_index;
5293 p->unfilled_fields = constructor_unfilled_fields;
5294 p->bit_index = constructor_bit_index;
5295 p->elements = constructor_elements;
5296 p->constant = constructor_constant;
5297 p->simple = constructor_simple;
5298 p->erroneous = constructor_erroneous;
5299 p->pending_elts = constructor_pending_elts;
5300 p->depth = constructor_depth;
5301 p->replacement_value = 0;
5302 p->implicit = implicit;
5303 p->incremental = constructor_incremental;
5304 p->outer = 0;
5305 p->next = constructor_stack;
5306 constructor_stack = p;
5308 constructor_constant = 1;
5309 constructor_simple = 1;
5310 constructor_depth = SPELLING_DEPTH ();
5311 constructor_elements = 0;
5312 constructor_pending_elts = 0;
5314 /* Don't die if an entire brace-pair level is superfluous
5315 in the containing level. */
5316 if (constructor_type == 0)
5318 else if (TREE_CODE (constructor_type) == RECORD_TYPE
5319 || TREE_CODE (constructor_type) == UNION_TYPE)
5321 /* Don't die if there are extra init elts at the end. */
5322 if (constructor_fields == 0)
5323 constructor_type = 0;
5324 else
5326 constructor_type = TREE_TYPE (constructor_fields);
5327 push_member_name (constructor_fields);
5328 constructor_depth++;
5329 if (constructor_fields != constructor_unfilled_fields)
5330 constructor_incremental = 0;
5333 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5335 constructor_type = TREE_TYPE (constructor_type);
5336 push_array_bounds (TREE_INT_CST_LOW (constructor_index));
5337 constructor_depth++;
5338 if (! tree_int_cst_equal (constructor_index, constructor_unfilled_index)
5339 || constructor_range_end != 0)
5340 constructor_incremental = 0;
5343 if (constructor_type == 0)
5345 error_init ("extra brace group at end of initializer");
5346 constructor_fields = 0;
5347 constructor_unfilled_fields = 0;
5348 return;
5351 /* Turn off constructor_incremental if type is a struct with bitfields. */
5352 check_init_type_bitfields (constructor_type);
5354 if (implicit && warn_missing_braces && !missing_braces_mentioned)
5356 missing_braces_mentioned = 1;
5357 warning_init ("missing braces around initializer");
5360 if (TREE_CODE (constructor_type) == RECORD_TYPE
5361 || TREE_CODE (constructor_type) == UNION_TYPE)
5363 constructor_fields = TYPE_FIELDS (constructor_type);
5364 /* Skip any nameless bit fields at the beginning. */
5365 while (constructor_fields != 0 && DECL_C_BIT_FIELD (constructor_fields)
5366 && DECL_NAME (constructor_fields) == 0)
5367 constructor_fields = TREE_CHAIN (constructor_fields);
5368 constructor_unfilled_fields = constructor_fields;
5369 constructor_bit_index = copy_node (integer_zero_node);
5370 TREE_TYPE (constructor_bit_index) = sbitsizetype;
5372 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5374 constructor_range_end = 0;
5375 if (TYPE_DOMAIN (constructor_type))
5377 constructor_max_index
5378 = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
5379 constructor_index
5380 = copy_node (TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
5382 else
5383 constructor_index = copy_node (integer_zero_node);
5384 constructor_unfilled_index = copy_node (constructor_index);
5386 else
5388 warning_init ("braces around scalar initializer");
5389 constructor_fields = constructor_type;
5390 constructor_unfilled_fields = constructor_type;
5394 /* Don't read a struct incrementally if it has any bitfields,
5395 because the incremental reading code doesn't know how to
5396 handle bitfields yet. */
5398 static void
5399 check_init_type_bitfields (type)
5400 tree type;
5402 if (TREE_CODE (type) == RECORD_TYPE)
5404 tree tail;
5405 for (tail = TYPE_FIELDS (type); tail;
5406 tail = TREE_CHAIN (tail))
5408 if (DECL_C_BIT_FIELD (tail))
5410 constructor_incremental = 0;
5411 break;
5414 check_init_type_bitfields (TREE_TYPE (tail));
5418 else if (TREE_CODE (type) == UNION_TYPE)
5420 tree tail = TYPE_FIELDS (type);
5421 if (tail && DECL_C_BIT_FIELD (tail))
5422 /* We also use the nonincremental algorithm for initiliazation
5423 of unions whose first member is a bitfield, becuase the
5424 incremental algorithm has no code for dealing with
5425 bitfields. */
5426 constructor_incremental = 0;
5429 else if (TREE_CODE (type) == ARRAY_TYPE)
5430 check_init_type_bitfields (TREE_TYPE (type));
5433 /* At the end of an implicit or explicit brace level,
5434 finish up that level of constructor.
5435 If we were outputting the elements as they are read, return 0
5436 from inner levels (process_init_element ignores that),
5437 but return error_mark_node from the outermost level
5438 (that's what we want to put in DECL_INITIAL).
5439 Otherwise, return a CONSTRUCTOR expression. */
5441 tree
5442 pop_init_level (implicit)
5443 int implicit;
5445 struct constructor_stack *p;
5446 int size = 0;
5447 tree constructor = 0;
5449 if (implicit == 0)
5451 /* When we come to an explicit close brace,
5452 pop any inner levels that didn't have explicit braces. */
5453 while (constructor_stack->implicit)
5454 process_init_element (pop_init_level (1));
5457 p = constructor_stack;
5459 if (constructor_type != 0)
5460 size = int_size_in_bytes (constructor_type);
5462 /* Warn when some struct elements are implicitly initialized to zero. */
5463 if (extra_warnings
5464 && constructor_type
5465 && TREE_CODE (constructor_type) == RECORD_TYPE
5466 && constructor_unfilled_fields)
5468 push_member_name (constructor_unfilled_fields);
5469 warning_init ("missing initializer");
5470 RESTORE_SPELLING_DEPTH (constructor_depth);
5473 /* Now output all pending elements. */
5474 output_pending_init_elements (1);
5476 #if 0 /* c-parse.in warns about {}. */
5477 /* In ANSI, each brace level must have at least one element. */
5478 if (! implicit && pedantic
5479 && (TREE_CODE (constructor_type) == ARRAY_TYPE
5480 ? integer_zerop (constructor_unfilled_index)
5481 : constructor_unfilled_fields == TYPE_FIELDS (constructor_type)))
5482 pedwarn_init ("empty braces in initializer");
5483 #endif
5485 /* Pad out the end of the structure. */
5487 if (p->replacement_value)
5489 /* If this closes a superfluous brace pair,
5490 just pass out the element between them. */
5491 constructor = p->replacement_value;
5492 /* If this is the top level thing within the initializer,
5493 and it's for a variable, then since we already called
5494 assemble_variable, we must output the value now. */
5495 if (p->next == 0 && constructor_decl != 0
5496 && constructor_incremental)
5498 constructor = digest_init (constructor_type, constructor,
5499 require_constant_value,
5500 require_constant_elements);
5502 /* If initializing an array of unknown size,
5503 determine the size now. */
5504 if (TREE_CODE (constructor_type) == ARRAY_TYPE
5505 && TYPE_DOMAIN (constructor_type) == 0)
5507 int failure;
5508 int momentary_p;
5510 push_obstacks_nochange ();
5511 if (TREE_PERMANENT (constructor_type))
5512 end_temporary_allocation ();
5514 momentary_p = suspend_momentary ();
5516 /* We shouldn't have an incomplete array type within
5517 some other type. */
5518 if (constructor_stack->next)
5519 abort ();
5521 failure
5522 = complete_array_type (constructor_type,
5523 constructor, 0);
5524 if (failure)
5525 abort ();
5527 size = int_size_in_bytes (constructor_type);
5528 resume_momentary (momentary_p);
5529 pop_obstacks ();
5532 output_constant (constructor, size);
5535 else if (constructor_type == 0)
5537 else if (TREE_CODE (constructor_type) != RECORD_TYPE
5538 && TREE_CODE (constructor_type) != UNION_TYPE
5539 && TREE_CODE (constructor_type) != ARRAY_TYPE
5540 && ! constructor_incremental)
5542 /* A nonincremental scalar initializer--just return
5543 the element, after verifying there is just one. */
5544 if (constructor_elements == 0)
5546 error_init ("empty scalar initializer");
5547 constructor = error_mark_node;
5549 else if (TREE_CHAIN (constructor_elements) != 0)
5551 error_init ("extra elements in scalar initializer");
5552 constructor = TREE_VALUE (constructor_elements);
5554 else
5555 constructor = TREE_VALUE (constructor_elements);
5557 else if (! constructor_incremental)
5559 if (constructor_erroneous)
5560 constructor = error_mark_node;
5561 else
5563 int momentary = suspend_momentary ();
5565 constructor = build (CONSTRUCTOR, constructor_type, NULL_TREE,
5566 nreverse (constructor_elements));
5567 if (constructor_constant)
5568 TREE_CONSTANT (constructor) = 1;
5569 if (constructor_constant && constructor_simple)
5570 TREE_STATIC (constructor) = 1;
5572 resume_momentary (momentary);
5575 else
5577 tree filled;
5578 int momentary = suspend_momentary ();
5580 if (TREE_CODE (constructor_type) == RECORD_TYPE
5581 || TREE_CODE (constructor_type) == UNION_TYPE)
5583 /* Find the offset of the end of that field. */
5584 filled = size_binop (CEIL_DIV_EXPR,
5585 constructor_bit_index,
5586 size_int (BITS_PER_UNIT));
5588 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5590 /* If initializing an array of unknown size,
5591 determine the size now. */
5592 if (TREE_CODE (constructor_type) == ARRAY_TYPE
5593 && TYPE_DOMAIN (constructor_type) == 0)
5595 tree maxindex
5596 = size_binop (MINUS_EXPR,
5597 constructor_unfilled_index,
5598 integer_one_node);
5600 push_obstacks_nochange ();
5601 if (TREE_PERMANENT (constructor_type))
5602 end_temporary_allocation ();
5603 maxindex = copy_node (maxindex);
5604 TYPE_DOMAIN (constructor_type) = build_index_type (maxindex);
5605 TREE_TYPE (maxindex) = TYPE_DOMAIN (constructor_type);
5607 /* TYPE_MAX_VALUE is always one less than the number of elements
5608 in the array, because we start counting at zero. Therefore,
5609 warn only if the value is less than zero. */
5610 if (pedantic
5611 && (tree_int_cst_sgn (TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type)))
5612 < 0))
5613 error_with_decl (constructor_decl,
5614 "zero or negative array size `%s'");
5615 layout_type (constructor_type);
5616 size = int_size_in_bytes (constructor_type);
5617 pop_obstacks ();
5620 filled = size_binop (MULT_EXPR, constructor_unfilled_index,
5621 size_in_bytes (TREE_TYPE (constructor_type)));
5623 else
5624 filled = 0;
5626 if (filled != 0)
5627 assemble_zeros (size - TREE_INT_CST_LOW (filled));
5629 resume_momentary (momentary);
5633 constructor_type = p->type;
5634 constructor_fields = p->fields;
5635 constructor_index = p->index;
5636 constructor_range_end = p->range_end;
5637 constructor_max_index = p->max_index;
5638 constructor_unfilled_index = p->unfilled_index;
5639 constructor_unfilled_fields = p->unfilled_fields;
5640 constructor_bit_index = p->bit_index;
5641 constructor_elements = p->elements;
5642 constructor_constant = p->constant;
5643 constructor_simple = p->simple;
5644 constructor_erroneous = p->erroneous;
5645 constructor_pending_elts = p->pending_elts;
5646 constructor_depth = p->depth;
5647 constructor_incremental = p->incremental;
5648 RESTORE_SPELLING_DEPTH (constructor_depth);
5650 constructor_stack = p->next;
5651 free (p);
5653 if (constructor == 0)
5655 if (constructor_stack == 0)
5656 return error_mark_node;
5657 return NULL_TREE;
5659 return constructor;
5662 /* Within an array initializer, specify the next index to be initialized.
5663 FIRST is that index. If LAST is nonzero, then initialize a range
5664 of indices, running from FIRST through LAST. */
5666 void
5667 set_init_index (first, last)
5668 tree first, last;
5670 while ((TREE_CODE (first) == NOP_EXPR
5671 || TREE_CODE (first) == CONVERT_EXPR
5672 || TREE_CODE (first) == NON_LVALUE_EXPR)
5673 && (TYPE_MODE (TREE_TYPE (first))
5674 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (first, 0)))))
5675 (first) = TREE_OPERAND (first, 0);
5676 if (last)
5677 while ((TREE_CODE (last) == NOP_EXPR
5678 || TREE_CODE (last) == CONVERT_EXPR
5679 || TREE_CODE (last) == NON_LVALUE_EXPR)
5680 && (TYPE_MODE (TREE_TYPE (last))
5681 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (last, 0)))))
5682 (last) = TREE_OPERAND (last, 0);
5684 if (TREE_CODE (first) != INTEGER_CST)
5685 error_init ("nonconstant array index in initializer");
5686 else if (last != 0 && TREE_CODE (last) != INTEGER_CST)
5687 error_init ("nonconstant array index in initializer");
5688 else if (! constructor_unfilled_index)
5689 error_init ("array index in non-array initializer");
5690 else if (tree_int_cst_lt (first, constructor_unfilled_index))
5691 error_init ("duplicate array index in initializer");
5692 else
5694 TREE_INT_CST_LOW (constructor_index) = TREE_INT_CST_LOW (first);
5695 TREE_INT_CST_HIGH (constructor_index) = TREE_INT_CST_HIGH (first);
5697 if (last != 0 && tree_int_cst_lt (last, first))
5698 error_init ("empty index range in initializer");
5699 else
5701 if (pedantic)
5702 pedwarn ("ANSI C forbids specifying element to initialize");
5703 constructor_range_end = last;
5708 /* Within a struct initializer, specify the next field to be initialized. */
5710 void
5711 set_init_label (fieldname)
5712 tree fieldname;
5714 tree tail;
5715 int passed = 0;
5717 /* Don't die if an entire brace-pair level is superfluous
5718 in the containing level. */
5719 if (constructor_type == 0)
5720 return;
5722 for (tail = TYPE_FIELDS (constructor_type); tail;
5723 tail = TREE_CHAIN (tail))
5725 if (tail == constructor_unfilled_fields)
5726 passed = 1;
5727 if (DECL_NAME (tail) == fieldname)
5728 break;
5731 if (tail == 0)
5732 error ("unknown field `%s' specified in initializer",
5733 IDENTIFIER_POINTER (fieldname));
5734 else if (!passed)
5735 error ("field `%s' already initialized",
5736 IDENTIFIER_POINTER (fieldname));
5737 else
5739 constructor_fields = tail;
5740 if (pedantic)
5741 pedwarn ("ANSI C forbids specifying structure member to initialize");
5745 /* Add a new initializer to the tree of pending initializers. PURPOSE
5746 indentifies the initializer, either array index or field in a structure.
5747 VALUE is the value of that index or field. */
5749 static void
5750 add_pending_init (purpose, value)
5751 tree purpose, value;
5753 struct init_node *p, **q, *r;
5755 q = &constructor_pending_elts;
5756 p = 0;
5758 if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5760 while (*q != 0)
5762 p = *q;
5763 if (tree_int_cst_lt (purpose, p->purpose))
5764 q = &p->left;
5765 else if (tree_int_cst_lt (p->purpose, purpose))
5766 q = &p->right;
5767 else
5768 abort ();
5771 else
5773 while (*q != NULL)
5775 p = *q;
5776 if (tree_int_cst_lt (DECL_FIELD_BITPOS (purpose),
5777 DECL_FIELD_BITPOS (p->purpose)))
5778 q = &p->left;
5779 else if (tree_int_cst_lt (DECL_FIELD_BITPOS (p->purpose),
5780 DECL_FIELD_BITPOS (purpose)))
5781 q = &p->right;
5782 else
5783 abort ();
5787 r = (struct init_node *) oballoc (sizeof (struct init_node));
5788 r->purpose = purpose;
5789 r->value = value;
5791 *q = r;
5792 r->parent = p;
5793 r->left = 0;
5794 r->right = 0;
5795 r->balance = 0;
5797 while (p)
5799 struct init_node *s;
5801 if (r == p->left)
5803 if (p->balance == 0)
5804 p->balance = -1;
5805 else if (p->balance < 0)
5807 if (r->balance < 0)
5809 /* L rotation. */
5810 p->left = r->right;
5811 if (p->left)
5812 p->left->parent = p;
5813 r->right = p;
5815 p->balance = 0;
5816 r->balance = 0;
5818 s = p->parent;
5819 p->parent = r;
5820 r->parent = s;
5821 if (s)
5823 if (s->left == p)
5824 s->left = r;
5825 else
5826 s->right = r;
5828 else
5829 constructor_pending_elts = r;
5831 else
5833 /* LR rotation. */
5834 struct init_node *t = r->right;
5836 r->right = t->left;
5837 if (r->right)
5838 r->right->parent = r;
5839 t->left = r;
5841 p->left = t->right;
5842 if (p->left)
5843 p->left->parent = p;
5844 t->right = p;
5846 p->balance = t->balance < 0;
5847 r->balance = -(t->balance > 0);
5848 t->balance = 0;
5850 s = p->parent;
5851 p->parent = t;
5852 r->parent = t;
5853 t->parent = s;
5854 if (s)
5856 if (s->left == p)
5857 s->left = t;
5858 else
5859 s->right = t;
5861 else
5862 constructor_pending_elts = t;
5864 break;
5866 else
5868 /* p->balance == +1; growth of left side balances the node. */
5869 p->balance = 0;
5870 break;
5873 else /* r == p->right */
5875 if (p->balance == 0)
5876 /* Growth propagation from right side. */
5877 p->balance++;
5878 else if (p->balance > 0)
5880 if (r->balance > 0)
5882 /* R rotation. */
5883 p->right = r->left;
5884 if (p->right)
5885 p->right->parent = p;
5886 r->left = p;
5888 p->balance = 0;
5889 r->balance = 0;
5891 s = p->parent;
5892 p->parent = r;
5893 r->parent = s;
5894 if (s)
5896 if (s->left == p)
5897 s->left = r;
5898 else
5899 s->right = r;
5901 else
5902 constructor_pending_elts = r;
5904 else /* r->balance == -1 */
5906 /* RL rotation */
5907 struct init_node *t = r->left;
5909 r->left = t->right;
5910 if (r->left)
5911 r->left->parent = r;
5912 t->right = r;
5914 p->right = t->left;
5915 if (p->right)
5916 p->right->parent = p;
5917 t->left = p;
5919 r->balance = (t->balance < 0);
5920 p->balance = -(t->balance > 0);
5921 t->balance = 0;
5923 s = p->parent;
5924 p->parent = t;
5925 r->parent = t;
5926 t->parent = s;
5927 if (s)
5929 if (s->left == p)
5930 s->left = t;
5931 else
5932 s->right = t;
5934 else
5935 constructor_pending_elts = t;
5937 break;
5939 else
5941 /* p->balance == -1; growth of right side balances the node. */
5942 p->balance = 0;
5943 break;
5947 r = p;
5948 p = p->parent;
5952 /* Return nonzero if FIELD is equal to the index of a pending initializer. */
5954 static int
5955 pending_init_member (field)
5956 tree field;
5958 struct init_node *p;
5960 p = constructor_pending_elts;
5961 if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5963 while (p)
5965 if (tree_int_cst_equal (field, p->purpose))
5966 return 1;
5967 else if (tree_int_cst_lt (field, p->purpose))
5968 p = p->left;
5969 else
5970 p = p->right;
5973 else
5975 while (p)
5977 if (field == p->purpose)
5978 return 1;
5979 else if (tree_int_cst_lt (DECL_FIELD_BITPOS (field),
5980 DECL_FIELD_BITPOS (p->purpose)))
5981 p = p->left;
5982 else
5983 p = p->right;
5987 return 0;
5990 /* "Output" the next constructor element.
5991 At top level, really output it to assembler code now.
5992 Otherwise, collect it in a list from which we will make a CONSTRUCTOR.
5993 TYPE is the data type that the containing data type wants here.
5994 FIELD is the field (a FIELD_DECL) or the index that this element fills.
5996 PENDING if non-nil means output pending elements that belong
5997 right after this element. (PENDING is normally 1;
5998 it is 0 while outputting pending elements, to avoid recursion.) */
6000 static void
6001 output_init_element (value, type, field, pending)
6002 tree value, type, field;
6003 int pending;
6005 int duplicate = 0;
6007 if (TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE
6008 || (TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE
6009 && !(TREE_CODE (value) == STRING_CST
6010 && TREE_CODE (type) == ARRAY_TYPE
6011 && TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE)
6012 && !comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (value)),
6013 TYPE_MAIN_VARIANT (type))))
6014 value = default_conversion (value);
6016 if (value == error_mark_node)
6017 constructor_erroneous = 1;
6018 else if (!TREE_CONSTANT (value))
6019 constructor_constant = 0;
6020 else if (initializer_constant_valid_p (value, TREE_TYPE (value)) == 0
6021 || ((TREE_CODE (constructor_type) == RECORD_TYPE
6022 || TREE_CODE (constructor_type) == UNION_TYPE)
6023 && DECL_C_BIT_FIELD (field)
6024 && TREE_CODE (value) != INTEGER_CST))
6025 constructor_simple = 0;
6027 if (require_constant_value && ! TREE_CONSTANT (value))
6029 error_init ("initializer element is not constant");
6030 value = error_mark_node;
6032 else if (require_constant_elements
6033 && initializer_constant_valid_p (value, TREE_TYPE (value)) == 0)
6035 error_init ("initializer element is not computable at load time");
6036 value = error_mark_node;
6039 /* If this element duplicates one on constructor_pending_elts,
6040 print a message and ignore it. Don't do this when we're
6041 processing elements taken off constructor_pending_elts,
6042 because we'd always get spurious errors. */
6043 if (pending)
6045 if (TREE_CODE (constructor_type) == RECORD_TYPE
6046 || TREE_CODE (constructor_type) == UNION_TYPE
6047 || TREE_CODE (constructor_type) == ARRAY_TYPE)
6049 if (pending_init_member (field))
6051 error_init ("duplicate initializer");
6052 duplicate = 1;
6057 /* If this element doesn't come next in sequence,
6058 put it on constructor_pending_elts. */
6059 if (TREE_CODE (constructor_type) == ARRAY_TYPE
6060 && !tree_int_cst_equal (field, constructor_unfilled_index))
6062 if (! duplicate)
6063 /* The copy_node is needed in case field is actually
6064 constructor_index, which is modified in place. */
6065 add_pending_init (copy_node (field),
6066 digest_init (type, value, require_constant_value,
6067 require_constant_elements));
6069 else if (TREE_CODE (constructor_type) == RECORD_TYPE
6070 && field != constructor_unfilled_fields)
6072 /* We do this for records but not for unions. In a union,
6073 no matter which field is specified, it can be initialized
6074 right away since it starts at the beginning of the union. */
6075 if (!duplicate)
6076 add_pending_init (field,
6077 digest_init (type, value, require_constant_value,
6078 require_constant_elements));
6080 else
6082 /* Otherwise, output this element either to
6083 constructor_elements or to the assembler file. */
6085 if (!duplicate)
6087 if (! constructor_incremental)
6089 if (field && TREE_CODE (field) == INTEGER_CST)
6090 field = copy_node (field);
6091 constructor_elements
6092 = tree_cons (field, digest_init (type, value,
6093 require_constant_value,
6094 require_constant_elements),
6095 constructor_elements);
6097 else
6099 /* Structure elements may require alignment.
6100 Do this, if necessary. */
6101 if (TREE_CODE (constructor_type) == RECORD_TYPE)
6103 /* Advance to offset of this element. */
6104 if (! tree_int_cst_equal (constructor_bit_index,
6105 DECL_FIELD_BITPOS (field)))
6107 /* By using unsigned arithmetic, the result will be
6108 correct even in case of overflows, if BITS_PER_UNIT
6109 is a power of two. */
6110 unsigned next = (TREE_INT_CST_LOW
6111 (DECL_FIELD_BITPOS (field))
6112 / (unsigned)BITS_PER_UNIT);
6113 unsigned here = (TREE_INT_CST_LOW
6114 (constructor_bit_index)
6115 / (unsigned)BITS_PER_UNIT);
6117 assemble_zeros ((next - here)
6118 * (unsigned)BITS_PER_UNIT
6119 / (unsigned)BITS_PER_UNIT);
6122 output_constant (digest_init (type, value,
6123 require_constant_value,
6124 require_constant_elements),
6125 int_size_in_bytes (type));
6127 /* For a record or union,
6128 keep track of end position of last field. */
6129 if (TREE_CODE (constructor_type) == RECORD_TYPE
6130 || TREE_CODE (constructor_type) == UNION_TYPE)
6132 tree temp = size_binop (PLUS_EXPR, DECL_FIELD_BITPOS (field),
6133 DECL_SIZE (field));
6134 TREE_INT_CST_LOW (constructor_bit_index)
6135 = TREE_INT_CST_LOW (temp);
6136 TREE_INT_CST_HIGH (constructor_bit_index)
6137 = TREE_INT_CST_HIGH (temp);
6142 /* Advance the variable that indicates sequential elements output. */
6143 if (TREE_CODE (constructor_type) == ARRAY_TYPE)
6145 tree tem = size_binop (PLUS_EXPR, constructor_unfilled_index,
6146 integer_one_node);
6147 TREE_INT_CST_LOW (constructor_unfilled_index)
6148 = TREE_INT_CST_LOW (tem);
6149 TREE_INT_CST_HIGH (constructor_unfilled_index)
6150 = TREE_INT_CST_HIGH (tem);
6152 else if (TREE_CODE (constructor_type) == RECORD_TYPE)
6153 constructor_unfilled_fields = TREE_CHAIN (constructor_unfilled_fields);
6154 else if (TREE_CODE (constructor_type) == UNION_TYPE)
6155 constructor_unfilled_fields = 0;
6157 /* Now output any pending elements which have become next. */
6158 if (pending)
6159 output_pending_init_elements (0);
6163 /* Output any pending elements which have become next.
6164 As we output elements, constructor_unfilled_{fields,index}
6165 advances, which may cause other elements to become next;
6166 if so, they too are output.
6168 If ALL is 0, we return when there are
6169 no more pending elements to output now.
6171 If ALL is 1, we output space as necessary so that
6172 we can output all the pending elements. */
6174 static void
6175 output_pending_init_elements (all)
6176 int all;
6178 struct init_node *elt = constructor_pending_elts;
6179 tree next;
6181 retry:
6183 /* Look thru the whole pending tree.
6184 If we find an element that should be output now,
6185 output it. Otherwise, set NEXT to the element
6186 that comes first among those still pending. */
6188 next = 0;
6189 while (elt)
6191 if (TREE_CODE (constructor_type) == ARRAY_TYPE)
6193 if (tree_int_cst_equal (elt->purpose,
6194 constructor_unfilled_index))
6195 output_init_element (elt->value,
6196 TREE_TYPE (constructor_type),
6197 constructor_unfilled_index, 0);
6198 else if (tree_int_cst_lt (constructor_unfilled_index,
6199 elt->purpose))
6201 /* Advance to the next smaller node. */
6202 if (elt->left)
6203 elt = elt->left;
6204 else
6206 /* We have reached the smallest node bigger than the
6207 current unfilled index. Fill the space first. */
6208 next = elt->purpose;
6209 break;
6212 else
6214 /* Advance to the next bigger node. */
6215 if (elt->right)
6216 elt = elt->right;
6217 else
6219 /* We have reached the biggest node in a subtree. Find
6220 the parent of it, which is the next bigger node. */
6221 while (elt->parent && elt->parent->right == elt)
6222 elt = elt->parent;
6223 elt = elt->parent;
6224 if (elt && tree_int_cst_lt (constructor_unfilled_index,
6225 elt->purpose))
6227 next = elt->purpose;
6228 break;
6233 else if (TREE_CODE (constructor_type) == RECORD_TYPE
6234 || TREE_CODE (constructor_type) == UNION_TYPE)
6236 /* If the current record is complete we are done. */
6237 if (constructor_unfilled_fields == 0)
6238 break;
6239 if (elt->purpose == constructor_unfilled_fields)
6241 output_init_element (elt->value,
6242 TREE_TYPE (constructor_unfilled_fields),
6243 constructor_unfilled_fields,
6246 else if (tree_int_cst_lt (DECL_FIELD_BITPOS (constructor_unfilled_fields),
6247 DECL_FIELD_BITPOS (elt->purpose)))
6249 /* Advance to the next smaller node. */
6250 if (elt->left)
6251 elt = elt->left;
6252 else
6254 /* We have reached the smallest node bigger than the
6255 current unfilled field. Fill the space first. */
6256 next = elt->purpose;
6257 break;
6260 else
6262 /* Advance to the next bigger node. */
6263 if (elt->right)
6264 elt = elt->right;
6265 else
6267 /* We have reached the biggest node in a subtree. Find
6268 the parent of it, which is the next bigger node. */
6269 while (elt->parent && elt->parent->right == elt)
6270 elt = elt->parent;
6271 elt = elt->parent;
6272 if (elt
6273 && tree_int_cst_lt (DECL_FIELD_BITPOS (constructor_unfilled_fields),
6274 DECL_FIELD_BITPOS (elt->purpose)))
6276 next = elt->purpose;
6277 break;
6284 /* Ordinarily return, but not if we want to output all
6285 and there are elements left. */
6286 if (! (all && next != 0))
6287 return;
6289 /* Generate space up to the position of NEXT. */
6290 if (constructor_incremental)
6292 tree filled;
6293 tree nextpos_tree = size_int (0);
6295 if (TREE_CODE (constructor_type) == RECORD_TYPE
6296 || TREE_CODE (constructor_type) == UNION_TYPE)
6298 tree tail;
6299 /* Find the last field written out, if any. */
6300 for (tail = TYPE_FIELDS (constructor_type); tail;
6301 tail = TREE_CHAIN (tail))
6302 if (TREE_CHAIN (tail) == constructor_unfilled_fields)
6303 break;
6305 if (tail)
6306 /* Find the offset of the end of that field. */
6307 filled = size_binop (CEIL_DIV_EXPR,
6308 size_binop (PLUS_EXPR,
6309 DECL_FIELD_BITPOS (tail),
6310 DECL_SIZE (tail)),
6311 size_int (BITS_PER_UNIT));
6312 else
6313 filled = size_int (0);
6315 nextpos_tree = size_binop (CEIL_DIV_EXPR,
6316 DECL_FIELD_BITPOS (next),
6317 size_int (BITS_PER_UNIT));
6319 TREE_INT_CST_HIGH (constructor_bit_index)
6320 = TREE_INT_CST_HIGH (DECL_FIELD_BITPOS (next));
6321 TREE_INT_CST_LOW (constructor_bit_index)
6322 = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (next));
6323 constructor_unfilled_fields = next;
6325 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
6327 filled = size_binop (MULT_EXPR, constructor_unfilled_index,
6328 size_in_bytes (TREE_TYPE (constructor_type)));
6329 nextpos_tree
6330 = size_binop (MULT_EXPR, next,
6331 size_in_bytes (TREE_TYPE (constructor_type)));
6332 TREE_INT_CST_LOW (constructor_unfilled_index)
6333 = TREE_INT_CST_LOW (next);
6334 TREE_INT_CST_HIGH (constructor_unfilled_index)
6335 = TREE_INT_CST_HIGH (next);
6337 else
6338 filled = 0;
6340 if (filled)
6342 int nextpos = TREE_INT_CST_LOW (nextpos_tree);
6344 assemble_zeros (nextpos - TREE_INT_CST_LOW (filled));
6347 else
6349 /* If it's not incremental, just skip over the gap,
6350 so that after jumping to retry we will output the next
6351 successive element. */
6352 if (TREE_CODE (constructor_type) == RECORD_TYPE
6353 || TREE_CODE (constructor_type) == UNION_TYPE)
6354 constructor_unfilled_fields = next;
6355 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
6357 TREE_INT_CST_LOW (constructor_unfilled_index)
6358 = TREE_INT_CST_LOW (next);
6359 TREE_INT_CST_HIGH (constructor_unfilled_index)
6360 = TREE_INT_CST_HIGH (next);
6364 /* ELT now points to the node in the pending tree with the next
6365 initializer to output. */
6366 goto retry;
6369 /* Add one non-braced element to the current constructor level.
6370 This adjusts the current position within the constructor's type.
6371 This may also start or terminate implicit levels
6372 to handle a partly-braced initializer.
6374 Once this has found the correct level for the new element,
6375 it calls output_init_element.
6377 Note: if we are incrementally outputting this constructor,
6378 this function may be called with a null argument
6379 representing a sub-constructor that was already incrementally output.
6380 When that happens, we output nothing, but we do the bookkeeping
6381 to skip past that element of the current constructor. */
6383 void
6384 process_init_element (value)
6385 tree value;
6387 tree orig_value = value;
6388 int string_flag = value != 0 && TREE_CODE (value) == STRING_CST;
6390 /* Handle superfluous braces around string cst as in
6391 char x[] = {"foo"}; */
6392 if (string_flag
6393 && constructor_type
6394 && TREE_CODE (constructor_type) == ARRAY_TYPE
6395 && TREE_CODE (TREE_TYPE (constructor_type)) == INTEGER_TYPE
6396 && integer_zerop (constructor_unfilled_index))
6398 if (constructor_stack->replacement_value)
6399 error_init ("excess elements in char array initializer");
6400 constructor_stack->replacement_value = value;
6401 return;
6404 if (constructor_stack->replacement_value != 0)
6406 error_init ("excess elements in struct initializer");
6407 return;
6410 /* Ignore elements of a brace group if it is entirely superfluous
6411 and has already been diagnosed. */
6412 if (constructor_type == 0)
6413 return;
6415 /* If we've exhausted any levels that didn't have braces,
6416 pop them now. */
6417 while (constructor_stack->implicit)
6419 if ((TREE_CODE (constructor_type) == RECORD_TYPE
6420 || TREE_CODE (constructor_type) == UNION_TYPE)
6421 && constructor_fields == 0)
6422 process_init_element (pop_init_level (1));
6423 else if (TREE_CODE (constructor_type) == ARRAY_TYPE
6424 && (constructor_max_index == 0
6425 || tree_int_cst_lt (constructor_max_index,
6426 constructor_index)))
6427 process_init_element (pop_init_level (1));
6428 else
6429 break;
6432 while (1)
6434 if (TREE_CODE (constructor_type) == RECORD_TYPE)
6436 tree fieldtype;
6437 enum tree_code fieldcode;
6439 if (constructor_fields == 0)
6441 pedwarn_init ("excess elements in struct initializer");
6442 break;
6445 fieldtype = TREE_TYPE (constructor_fields);
6446 if (fieldtype != error_mark_node)
6447 fieldtype = TYPE_MAIN_VARIANT (fieldtype);
6448 fieldcode = TREE_CODE (fieldtype);
6450 /* Accept a string constant to initialize a subarray. */
6451 if (value != 0
6452 && fieldcode == ARRAY_TYPE
6453 && TREE_CODE (TREE_TYPE (fieldtype)) == INTEGER_TYPE
6454 && string_flag)
6455 value = orig_value;
6456 /* Otherwise, if we have come to a subaggregate,
6457 and we don't have an element of its type, push into it. */
6458 else if (value != 0 && !constructor_no_implicit
6459 && value != error_mark_node
6460 && TYPE_MAIN_VARIANT (TREE_TYPE (value)) != fieldtype
6461 && (fieldcode == RECORD_TYPE || fieldcode == ARRAY_TYPE
6462 || fieldcode == UNION_TYPE))
6464 push_init_level (1);
6465 continue;
6468 if (value)
6470 push_member_name (constructor_fields);
6471 output_init_element (value, fieldtype, constructor_fields, 1);
6472 RESTORE_SPELLING_DEPTH (constructor_depth);
6474 else
6475 /* Do the bookkeeping for an element that was
6476 directly output as a constructor. */
6478 /* For a record, keep track of end position of last field. */
6479 tree temp = size_binop (PLUS_EXPR,
6480 DECL_FIELD_BITPOS (constructor_fields),
6481 DECL_SIZE (constructor_fields));
6482 TREE_INT_CST_LOW (constructor_bit_index)
6483 = TREE_INT_CST_LOW (temp);
6484 TREE_INT_CST_HIGH (constructor_bit_index)
6485 = TREE_INT_CST_HIGH (temp);
6487 constructor_unfilled_fields = TREE_CHAIN (constructor_fields);
6490 constructor_fields = TREE_CHAIN (constructor_fields);
6491 /* Skip any nameless bit fields at the beginning. */
6492 while (constructor_fields != 0
6493 && DECL_C_BIT_FIELD (constructor_fields)
6494 && DECL_NAME (constructor_fields) == 0)
6495 constructor_fields = TREE_CHAIN (constructor_fields);
6496 break;
6498 if (TREE_CODE (constructor_type) == UNION_TYPE)
6500 tree fieldtype;
6501 enum tree_code fieldcode;
6503 if (constructor_fields == 0)
6505 pedwarn_init ("excess elements in union initializer");
6506 break;
6509 fieldtype = TREE_TYPE (constructor_fields);
6510 if (fieldtype != error_mark_node)
6511 fieldtype = TYPE_MAIN_VARIANT (fieldtype);
6512 fieldcode = TREE_CODE (fieldtype);
6514 /* Accept a string constant to initialize a subarray. */
6515 if (value != 0
6516 && fieldcode == ARRAY_TYPE
6517 && TREE_CODE (TREE_TYPE (fieldtype)) == INTEGER_TYPE
6518 && string_flag)
6519 value = orig_value;
6520 /* Otherwise, if we have come to a subaggregate,
6521 and we don't have an element of its type, push into it. */
6522 else if (value != 0 && !constructor_no_implicit
6523 && value != error_mark_node
6524 && TYPE_MAIN_VARIANT (TREE_TYPE (value)) != fieldtype
6525 && (fieldcode == RECORD_TYPE || fieldcode == ARRAY_TYPE
6526 || fieldcode == UNION_TYPE))
6528 push_init_level (1);
6529 continue;
6532 if (value)
6534 push_member_name (constructor_fields);
6535 output_init_element (value, fieldtype, constructor_fields, 1);
6536 RESTORE_SPELLING_DEPTH (constructor_depth);
6538 else
6539 /* Do the bookkeeping for an element that was
6540 directly output as a constructor. */
6542 TREE_INT_CST_LOW (constructor_bit_index)
6543 = TREE_INT_CST_LOW (DECL_SIZE (constructor_fields));
6544 TREE_INT_CST_HIGH (constructor_bit_index)
6545 = TREE_INT_CST_HIGH (DECL_SIZE (constructor_fields));
6547 constructor_unfilled_fields = TREE_CHAIN (constructor_fields);
6550 constructor_fields = 0;
6551 break;
6553 if (TREE_CODE (constructor_type) == ARRAY_TYPE)
6555 tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
6556 enum tree_code eltcode = TREE_CODE (elttype);
6558 /* Accept a string constant to initialize a subarray. */
6559 if (value != 0
6560 && eltcode == ARRAY_TYPE
6561 && TREE_CODE (TREE_TYPE (elttype)) == INTEGER_TYPE
6562 && string_flag)
6563 value = orig_value;
6564 /* Otherwise, if we have come to a subaggregate,
6565 and we don't have an element of its type, push into it. */
6566 else if (value != 0 && !constructor_no_implicit
6567 && value != error_mark_node
6568 && TYPE_MAIN_VARIANT (TREE_TYPE (value)) != elttype
6569 && (eltcode == RECORD_TYPE || eltcode == ARRAY_TYPE
6570 || eltcode == UNION_TYPE))
6572 push_init_level (1);
6573 continue;
6576 if (constructor_max_index != 0
6577 && tree_int_cst_lt (constructor_max_index, constructor_index))
6579 pedwarn_init ("excess elements in array initializer");
6580 break;
6583 /* In the case of [LO .. HI] = VALUE, only evaluate VALUE once. */
6584 if (constructor_range_end)
6586 if (constructor_max_index != 0
6587 && tree_int_cst_lt (constructor_max_index,
6588 constructor_range_end))
6590 pedwarn_init ("excess elements in array initializer");
6591 TREE_INT_CST_HIGH (constructor_range_end)
6592 = TREE_INT_CST_HIGH (constructor_max_index);
6593 TREE_INT_CST_LOW (constructor_range_end)
6594 = TREE_INT_CST_LOW (constructor_max_index);
6597 value = save_expr (value);
6600 /* Now output the actual element.
6601 Ordinarily, output once.
6602 If there is a range, repeat it till we advance past the range. */
6605 tree tem;
6607 if (value)
6609 push_array_bounds (TREE_INT_CST_LOW (constructor_index));
6610 output_init_element (value, elttype, constructor_index, 1);
6611 RESTORE_SPELLING_DEPTH (constructor_depth);
6614 tem = size_binop (PLUS_EXPR, constructor_index,
6615 integer_one_node);
6616 TREE_INT_CST_LOW (constructor_index) = TREE_INT_CST_LOW (tem);
6617 TREE_INT_CST_HIGH (constructor_index) = TREE_INT_CST_HIGH (tem);
6619 if (!value)
6620 /* If we are doing the bookkeeping for an element that was
6621 directly output as a constructor,
6622 we must update constructor_unfilled_index. */
6624 TREE_INT_CST_LOW (constructor_unfilled_index)
6625 = TREE_INT_CST_LOW (constructor_index);
6626 TREE_INT_CST_HIGH (constructor_unfilled_index)
6627 = TREE_INT_CST_HIGH (constructor_index);
6630 while (! (constructor_range_end == 0
6631 || tree_int_cst_lt (constructor_range_end,
6632 constructor_index)));
6634 break;
6637 /* Handle the sole element allowed in a braced initializer
6638 for a scalar variable. */
6639 if (constructor_fields == 0)
6641 pedwarn_init ("excess elements in scalar initializer");
6642 break;
6645 if (value)
6646 output_init_element (value, constructor_type, NULL_TREE, 1);
6647 constructor_fields = 0;
6648 break;
6651 /* If the (lexically) previous elments are not now saved,
6652 we can discard the storage for them. */
6653 if (constructor_incremental && constructor_pending_elts == 0 && value != 0
6654 && constructor_stack == 0)
6655 clear_momentary ();
6658 /* Expand an ASM statement with operands, handling output operands
6659 that are not variables or INDIRECT_REFS by transforming such
6660 cases into cases that expand_asm_operands can handle.
6662 Arguments are same as for expand_asm_operands. */
6664 void
6665 c_expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line)
6666 tree string, outputs, inputs, clobbers;
6667 int vol;
6668 char *filename;
6669 int line;
6671 int noutputs = list_length (outputs);
6672 register int i;
6673 /* o[I] is the place that output number I should be written. */
6674 register tree *o = (tree *) alloca (noutputs * sizeof (tree));
6675 register tree tail;
6677 if (TREE_CODE (string) == ADDR_EXPR)
6678 string = TREE_OPERAND (string, 0);
6679 if (TREE_CODE (string) != STRING_CST)
6681 error ("asm template is not a string constant");
6682 return;
6685 /* Record the contents of OUTPUTS before it is modified. */
6686 for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
6687 o[i] = TREE_VALUE (tail);
6689 /* Perform default conversions on array and function inputs. */
6690 /* Don't do this for other types--
6691 it would screw up operands expected to be in memory. */
6692 for (i = 0, tail = inputs; tail; tail = TREE_CHAIN (tail), i++)
6693 if (TREE_CODE (TREE_TYPE (TREE_VALUE (tail))) == ARRAY_TYPE
6694 || TREE_CODE (TREE_TYPE (TREE_VALUE (tail))) == FUNCTION_TYPE)
6695 TREE_VALUE (tail) = default_conversion (TREE_VALUE (tail));
6697 /* Generate the ASM_OPERANDS insn;
6698 store into the TREE_VALUEs of OUTPUTS some trees for
6699 where the values were actually stored. */
6700 expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line);
6702 /* Copy all the intermediate outputs into the specified outputs. */
6703 for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
6705 if (o[i] != TREE_VALUE (tail))
6707 expand_expr (build_modify_expr (o[i], NOP_EXPR, TREE_VALUE (tail)),
6708 NULL_RTX, VOIDmode, EXPAND_NORMAL);
6709 free_temp_slots ();
6711 /* Detect modification of read-only values.
6712 (Otherwise done by build_modify_expr.) */
6713 else
6715 tree type = TREE_TYPE (o[i]);
6716 if (TREE_READONLY (o[i])
6717 || TYPE_READONLY (type)
6718 || ((TREE_CODE (type) == RECORD_TYPE
6719 || TREE_CODE (type) == UNION_TYPE)
6720 && C_TYPE_FIELDS_READONLY (type)))
6721 readonly_warning (o[i], "modification by `asm'");
6725 /* Those MODIFY_EXPRs could do autoincrements. */
6726 emit_queue ();
6729 /* Expand a C `return' statement.
6730 RETVAL is the expression for what to return,
6731 or a null pointer for `return;' with no value. */
6733 void
6734 c_expand_return (retval)
6735 tree retval;
6737 tree valtype = TREE_TYPE (TREE_TYPE (current_function_decl));
6739 if (TREE_THIS_VOLATILE (current_function_decl))
6740 warning ("function declared `noreturn' has a `return' statement");
6742 if (!retval)
6744 current_function_returns_null = 1;
6745 if (warn_return_type && valtype != 0 && TREE_CODE (valtype) != VOID_TYPE)
6746 warning ("`return' with no value, in function returning non-void");
6747 expand_null_return ();
6749 else if (valtype == 0 || TREE_CODE (valtype) == VOID_TYPE)
6751 current_function_returns_null = 1;
6752 if (pedantic || TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
6753 pedwarn ("`return' with a value, in function returning void");
6754 expand_return (retval);
6756 else
6758 tree t = convert_for_assignment (valtype, retval, _("return"),
6759 NULL_TREE, NULL_TREE, 0);
6760 tree res = DECL_RESULT (current_function_decl);
6761 tree inner;
6763 if (t == error_mark_node)
6764 return;
6766 inner = t = convert (TREE_TYPE (res), t);
6768 /* Strip any conversions, additions, and subtractions, and see if
6769 we are returning the address of a local variable. Warn if so. */
6770 while (1)
6772 switch (TREE_CODE (inner))
6774 case NOP_EXPR: case NON_LVALUE_EXPR: case CONVERT_EXPR:
6775 case PLUS_EXPR:
6776 inner = TREE_OPERAND (inner, 0);
6777 continue;
6779 case MINUS_EXPR:
6780 /* If the second operand of the MINUS_EXPR has a pointer
6781 type (or is converted from it), this may be valid, so
6782 don't give a warning. */
6784 tree op1 = TREE_OPERAND (inner, 1);
6786 while (! POINTER_TYPE_P (TREE_TYPE (op1))
6787 && (TREE_CODE (op1) == NOP_EXPR
6788 || TREE_CODE (op1) == NON_LVALUE_EXPR
6789 || TREE_CODE (op1) == CONVERT_EXPR))
6790 op1 = TREE_OPERAND (op1, 0);
6792 if (POINTER_TYPE_P (TREE_TYPE (op1)))
6793 break;
6795 inner = TREE_OPERAND (inner, 0);
6796 continue;
6799 case ADDR_EXPR:
6800 inner = TREE_OPERAND (inner, 0);
6802 while (TREE_CODE_CLASS (TREE_CODE (inner)) == 'r')
6803 inner = TREE_OPERAND (inner, 0);
6805 if (TREE_CODE (inner) == VAR_DECL
6806 && ! DECL_EXTERNAL (inner)
6807 && ! TREE_STATIC (inner)
6808 && DECL_CONTEXT (inner) == current_function_decl)
6809 warning ("function returns address of local variable");
6810 break;
6812 default:
6813 break;
6816 break;
6819 t = build (MODIFY_EXPR, TREE_TYPE (res), res, t);
6820 TREE_SIDE_EFFECTS (t) = 1;
6821 expand_return (t);
6822 current_function_returns_value = 1;
6826 /* Start a C switch statement, testing expression EXP.
6827 Return EXP if it is valid, an error node otherwise. */
6829 tree
6830 c_expand_start_case (exp)
6831 tree exp;
6833 register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
6834 tree type = TREE_TYPE (exp);
6836 if (code != INTEGER_TYPE && code != ENUMERAL_TYPE && code != ERROR_MARK)
6838 error ("switch quantity not an integer");
6839 exp = error_mark_node;
6841 else
6843 tree index;
6844 type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
6846 if (warn_traditional
6847 && (type == long_integer_type_node
6848 || type == long_unsigned_type_node))
6849 pedwarn ("`long' switch expression not converted to `int' in ANSI C");
6851 exp = default_conversion (exp);
6852 type = TREE_TYPE (exp);
6853 index = get_unwidened (exp, NULL_TREE);
6854 /* We can't strip a conversion from a signed type to an unsigned,
6855 because if we did, int_fits_type_p would do the wrong thing
6856 when checking case values for being in range,
6857 and it's too hard to do the right thing. */
6858 if (TREE_UNSIGNED (TREE_TYPE (exp))
6859 == TREE_UNSIGNED (TREE_TYPE (index)))
6860 exp = index;
6863 expand_start_case (1, exp, type, "switch statement");
6865 return exp;