1 /* Build expressions with type checking for C compiler.
2 Copyright (C) 1987, 88, 91, 92, 93, 1994 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)
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, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* This file is part of the C front end.
22 It contains routines to build C expressions given their operands,
23 including computing the types of the result, C-specific error checks,
24 and some optimization.
26 There are also routines to build RETURN_STMT nodes and CASE_STMT nodes,
27 and to process initializations in declarations (since they work
28 like a strange sort of assignment). */
36 /* Nonzero if we've already printed a "missing braces around initializer"
37 message within this initializer. */
38 static int missing_braces_mentioned;
40 extern char *index ();
41 extern char *rindex ();
43 static tree quality_type PROTO((tree, tree));
44 static int comp_target_types PROTO((tree, tree));
45 static int function_types_compatible_p PROTO((tree, tree));
46 static int type_lists_compatible_p PROTO((tree, tree));
47 static int self_promoting_type_p PROTO((tree));
48 static tree decl_constant_value PROTO((tree));
49 static tree lookup_field PROTO((tree, tree, tree *));
50 static tree convert_arguments PROTO((tree, tree, tree, tree));
51 static tree pointer_int_sum PROTO((enum tree_code, tree, tree));
52 static tree pointer_diff PROTO((tree, tree));
53 static tree unary_complex_lvalue PROTO((enum tree_code, tree));
54 static void pedantic_lvalue_warning PROTO((enum tree_code));
55 static tree internal_build_compound_expr PROTO((tree, int));
56 static tree convert_for_assignment PROTO((tree, tree, char *, tree,
58 static void warn_for_assignment PROTO((char *, char *, tree, int));
59 static tree valid_compound_expr_initializer PROTO((tree, tree));
60 static void push_string PROTO((char *));
61 static void push_member_name PROTO((tree));
62 static void push_array_bounds PROTO((int));
63 static int spelling_length PROTO((void));
64 static char *print_spelling PROTO((char *));
65 static char *get_spelling PROTO((char *));
66 static void warning_init PROTO((char *, char *,
68 static tree digest_init PROTO((tree, tree, int, int));
69 static void check_init_type_bitfields PROTO((tree));
70 static void output_init_element PROTO((tree, tree, tree, int));
71 static void output_pending_init_elements PROTO((int));
73 /* Do `exp = require_complete_type (exp);' to make sure exp
74 does not have an incomplete type. (That includes void types.) */
77 require_complete_type (value)
80 tree type = TREE_TYPE (value);
82 /* First, detect a valid value with a complete type. */
83 if (TYPE_SIZE (type) != 0
84 && type != void_type_node)
87 incomplete_type_error (value, type);
88 return error_mark_node;
91 /* Print an error message for invalid use of an incomplete type.
92 VALUE is the expression that was used (or 0 if that isn't known)
93 and TYPE is the type that was invalid. */
96 incomplete_type_error (value, type)
102 /* Avoid duplicate error message. */
103 if (TREE_CODE (type) == ERROR_MARK)
106 if (value != 0 && (TREE_CODE (value) == VAR_DECL
107 || TREE_CODE (value) == PARM_DECL))
108 error ("`%s' has an incomplete type",
109 IDENTIFIER_POINTER (DECL_NAME (value)));
113 /* We must print an error message. Be clever about what it says. */
115 switch (TREE_CODE (type))
118 errmsg = "invalid use of undefined type `struct %s'";
122 errmsg = "invalid use of undefined type `union %s'";
126 errmsg = "invalid use of undefined type `enum %s'";
130 error ("invalid use of void expression");
134 if (TYPE_DOMAIN (type))
136 type = TREE_TYPE (type);
139 error ("invalid use of array with unspecified bounds");
146 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
147 error (errmsg, IDENTIFIER_POINTER (TYPE_NAME (type)));
149 /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL. */
150 error ("invalid use of incomplete typedef `%s'",
151 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))));
155 /* Return a variant of TYPE which has all the type qualifiers of LIKE
156 as well as those of TYPE. */
159 qualify_type (type, like)
162 int constflag = TYPE_READONLY (type) || TYPE_READONLY (like);
163 int volflag = TYPE_VOLATILE (type) || TYPE_VOLATILE (like);
164 return c_build_type_variant (type, constflag, volflag);
167 /* Return the common type of two types.
168 We assume that comptypes has already been done and returned 1;
169 if that isn't so, this may crash. In particular, we assume that qualifiers
172 This is the type for the result of most arithmetic operations
173 if the operands have the given two types. */
179 register enum tree_code code1;
180 register enum tree_code code2;
182 /* Save time if the two types are the same. */
184 if (t1 == t2) return t1;
186 /* If one type is nonsense, use the other. */
187 if (t1 == error_mark_node)
189 if (t2 == error_mark_node)
192 /* Treat an enum type as the unsigned integer type of the same width. */
194 if (TREE_CODE (t1) == ENUMERAL_TYPE)
195 t1 = type_for_size (TYPE_PRECISION (t1), 1);
196 if (TREE_CODE (t2) == ENUMERAL_TYPE)
197 t2 = type_for_size (TYPE_PRECISION (t2), 1);
199 code1 = TREE_CODE (t1);
200 code2 = TREE_CODE (t2);
202 /* If one type is complex, form the common type of the non-complex
203 components, then make that complex. Use T1 or T2 if it is the
205 if (code1 == COMPLEX_TYPE || code2 == COMPLEX_TYPE)
207 tree subtype1 = code1 == COMPLEX_TYPE ? TREE_TYPE (t1) : t1;
208 tree subtype2 = code2 == COMPLEX_TYPE ? TREE_TYPE (t2) : t2;
209 tree subtype = common_type (subtype1, subtype2);
211 if (code1 == COMPLEX_TYPE && TREE_TYPE (t1) == subtype)
213 else if (code2 == COMPLEX_TYPE && TREE_TYPE (t2) == subtype)
216 return build_complex_type (subtype);
223 /* If only one is real, use it as the result. */
225 if (code1 == REAL_TYPE && code2 != REAL_TYPE)
228 if (code2 == REAL_TYPE && code1 != REAL_TYPE)
231 /* Both real or both integers; use the one with greater precision. */
233 if (TYPE_PRECISION (t1) > TYPE_PRECISION (t2))
235 else if (TYPE_PRECISION (t2) > TYPE_PRECISION (t1))
238 /* Same precision. Prefer longs to ints even when same size. */
240 if (TYPE_MAIN_VARIANT (t1) == long_unsigned_type_node
241 || TYPE_MAIN_VARIANT (t2) == long_unsigned_type_node)
242 return long_unsigned_type_node;
244 if (TYPE_MAIN_VARIANT (t1) == long_integer_type_node
245 || TYPE_MAIN_VARIANT (t2) == long_integer_type_node)
247 /* But preserve unsignedness from the other type,
248 since long cannot hold all the values of an unsigned int. */
249 if (TREE_UNSIGNED (t1) || TREE_UNSIGNED (t2))
250 return long_unsigned_type_node;
251 return long_integer_type_node;
254 /* Otherwise prefer the unsigned one. */
256 if (TREE_UNSIGNED (t1))
261 /* For two pointers, do this recursively on the target type,
262 and combine the qualifiers of the two types' targets. */
263 /* This code was turned off; I don't know why.
264 But ANSI C specifies doing this with the qualifiers.
265 So I turned it on again. */
267 tree target = common_type (TYPE_MAIN_VARIANT (TREE_TYPE (t1)),
268 TYPE_MAIN_VARIANT (TREE_TYPE (t2)));
270 = TYPE_READONLY (TREE_TYPE (t1)) || TYPE_READONLY (TREE_TYPE (t2));
272 = TYPE_VOLATILE (TREE_TYPE (t1)) || TYPE_VOLATILE (TREE_TYPE (t2));
273 return build_pointer_type (c_build_type_variant (target, constp, volatilep));
276 return build_pointer_type (common_type (TREE_TYPE (t1), TREE_TYPE (t2)));
281 tree elt = common_type (TREE_TYPE (t1), TREE_TYPE (t2));
282 /* Save space: see if the result is identical to one of the args. */
283 if (elt == TREE_TYPE (t1) && TYPE_DOMAIN (t1))
285 if (elt == TREE_TYPE (t2) && TYPE_DOMAIN (t2))
287 /* Merge the element types, and have a size if either arg has one. */
288 return build_array_type (elt, TYPE_DOMAIN (TYPE_DOMAIN (t1) ? t1 : t2));
292 /* Function types: prefer the one that specified arg types.
293 If both do, merge the arg types. Also merge the return types. */
295 tree valtype = common_type (TREE_TYPE (t1), TREE_TYPE (t2));
296 tree p1 = TYPE_ARG_TYPES (t1);
297 tree p2 = TYPE_ARG_TYPES (t2);
302 /* Save space: see if the result is identical to one of the args. */
303 if (valtype == TREE_TYPE (t1) && ! TYPE_ARG_TYPES (t2))
305 if (valtype == TREE_TYPE (t2) && ! TYPE_ARG_TYPES (t1))
308 /* Simple way if one arg fails to specify argument types. */
309 if (TYPE_ARG_TYPES (t1) == 0)
310 return build_function_type (valtype, TYPE_ARG_TYPES (t2));
311 if (TYPE_ARG_TYPES (t2) == 0)
312 return build_function_type (valtype, TYPE_ARG_TYPES (t1));
314 /* If both args specify argument types, we must merge the two
315 lists, argument by argument. */
317 len = list_length (p1);
320 for (i = 0; i < len; i++)
321 newargs = tree_cons (NULL_TREE, NULL_TREE, newargs);
326 p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2), n = TREE_CHAIN (n))
328 /* A null type means arg type is not specified.
329 Take whatever the other function type has. */
330 if (TREE_VALUE (p1) == 0)
332 TREE_VALUE (n) = TREE_VALUE (p2);
335 if (TREE_VALUE (p2) == 0)
337 TREE_VALUE (n) = TREE_VALUE (p1);
341 /* Given wait (union {union wait *u; int *i} *)
342 and wait (union wait *),
343 prefer union wait * as type of parm. */
344 if (TREE_CODE (TREE_VALUE (p1)) == UNION_TYPE
345 && TREE_VALUE (p1) != TREE_VALUE (p2))
348 for (memb = TYPE_FIELDS (TREE_VALUE (p1));
349 memb; memb = TREE_CHAIN (memb))
350 if (comptypes (TREE_TYPE (memb), TREE_VALUE (p2)))
352 TREE_VALUE (n) = TREE_VALUE (p2);
354 pedwarn ("function types not truly compatible in ANSI C");
358 if (TREE_CODE (TREE_VALUE (p2)) == UNION_TYPE
359 && TREE_VALUE (p2) != TREE_VALUE (p1))
362 for (memb = TYPE_FIELDS (TREE_VALUE (p2));
363 memb; memb = TREE_CHAIN (memb))
364 if (comptypes (TREE_TYPE (memb), TREE_VALUE (p1)))
366 TREE_VALUE (n) = TREE_VALUE (p1);
368 pedwarn ("function types not truly compatible in ANSI C");
372 TREE_VALUE (n) = common_type (TREE_VALUE (p1), TREE_VALUE (p2));
376 return build_function_type (valtype, newargs);
385 /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
386 or various other operations. Return 2 if they are compatible
387 but a warning may be needed if you use them together. */
390 comptypes (type1, type2)
393 register tree t1 = type1;
394 register tree t2 = type2;
396 /* Suppress errors caused by previously reported errors. */
398 if (t1 == t2 || TREE_CODE (t1) == ERROR_MARK || TREE_CODE (t2) == ERROR_MARK)
401 /* Treat an enum type as the unsigned integer type of the same width. */
403 if (TREE_CODE (t1) == ENUMERAL_TYPE)
404 t1 = type_for_size (TYPE_PRECISION (t1), 1);
405 if (TREE_CODE (t2) == ENUMERAL_TYPE)
406 t2 = type_for_size (TYPE_PRECISION (t2), 1);
411 /* Different classes of types can't be compatible. */
413 if (TREE_CODE (t1) != TREE_CODE (t2)) return 0;
415 /* Qualifiers must match. */
417 if (TYPE_READONLY (t1) != TYPE_READONLY (t2))
419 if (TYPE_VOLATILE (t1) != TYPE_VOLATILE (t2))
422 /* Allow for two different type nodes which have essentially the same
423 definition. Note that we already checked for equality of the type
424 type qualifiers (just above). */
426 if (TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
429 switch (TREE_CODE (t1))
432 return (TREE_TYPE (t1) == TREE_TYPE (t2)
433 ? 1 : comptypes (TREE_TYPE (t1), TREE_TYPE (t2)));
436 return function_types_compatible_p (t1, t2);
440 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
442 tree d1 = TYPE_DOMAIN (t1);
443 tree d2 = TYPE_DOMAIN (t2);
445 /* Target types must match incl. qualifiers. */
446 if (TREE_TYPE (t1) != TREE_TYPE (t2)
447 && 0 == (val = comptypes (TREE_TYPE (t1), TREE_TYPE (t2))))
450 /* Sizes must match unless one is missing or variable. */
451 if (d1 == 0 || d2 == 0 || d1 == d2
452 || TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST
453 || TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST
454 || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST
455 || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST)
458 return (((TREE_INT_CST_LOW (TYPE_MIN_VALUE (d1))
459 == TREE_INT_CST_LOW (TYPE_MIN_VALUE (d2)))
460 && (TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d1))
461 == TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d2)))
462 && (TREE_INT_CST_LOW (TYPE_MAX_VALUE (d1))
463 == TREE_INT_CST_LOW (TYPE_MAX_VALUE (d2)))
464 && (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d1))
465 == TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d2))))
470 if (maybe_objc_comptypes (t1, t2, 0) == 1)
476 /* Return 1 if TTL and TTR are pointers to types that are equivalent,
477 ignoring their qualifiers. */
480 comp_target_types (ttl, ttr)
485 /* Give maybe_objc_comptypes a crack at letting these types through. */
486 if (val = maybe_objc_comptypes (ttl, ttr, 1) >= 0)
489 val = comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (ttl)),
490 TYPE_MAIN_VARIANT (TREE_TYPE (ttr)));
492 if (val == 2 && pedantic)
493 pedwarn ("types are not quite compatible");
497 /* Subroutines of `comptypes'. */
499 /* Return 1 if two function types F1 and F2 are compatible.
500 If either type specifies no argument types,
501 the other must specify a fixed number of self-promoting arg types.
502 Otherwise, if one type specifies only the number of arguments,
503 the other must specify that number of self-promoting arg types.
504 Otherwise, the argument types must match. */
507 function_types_compatible_p (f1, f2)
511 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
515 if (!(TREE_TYPE (f1) == TREE_TYPE (f2)
516 || (val = comptypes (TREE_TYPE (f1), TREE_TYPE (f2)))))
519 args1 = TYPE_ARG_TYPES (f1);
520 args2 = TYPE_ARG_TYPES (f2);
522 /* An unspecified parmlist matches any specified parmlist
523 whose argument types don't need default promotions. */
527 if (!self_promoting_args_p (args2))
529 /* If one of these types comes from a non-prototype fn definition,
530 compare that with the other type's arglist.
531 If they don't match, ask for a warning (but no error). */
532 if (TYPE_ACTUAL_ARG_TYPES (f1)
533 && 1 != type_lists_compatible_p (args2, TYPE_ACTUAL_ARG_TYPES (f1)))
539 if (!self_promoting_args_p (args1))
541 if (TYPE_ACTUAL_ARG_TYPES (f2)
542 && 1 != type_lists_compatible_p (args1, TYPE_ACTUAL_ARG_TYPES (f2)))
547 /* Both types have argument lists: compare them and propagate results. */
548 val1 = type_lists_compatible_p (args1, args2);
549 return val1 != 1 ? val1 : val;
552 /* Check two lists of types for compatibility,
553 returning 0 for incompatible, 1 for compatible,
554 or 2 for compatible with warning. */
557 type_lists_compatible_p (args1, args2)
560 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
566 if (args1 == 0 && args2 == 0)
568 /* If one list is shorter than the other,
569 they fail to match. */
570 if (args1 == 0 || args2 == 0)
572 /* A null pointer instead of a type
573 means there is supposed to be an argument
574 but nothing is specified about what type it has.
575 So match anything that self-promotes. */
576 if (TREE_VALUE (args1) == 0)
578 if (! self_promoting_type_p (TREE_VALUE (args2)))
581 else if (TREE_VALUE (args2) == 0)
583 if (! self_promoting_type_p (TREE_VALUE (args1)))
586 else if (! (newval = comptypes (TREE_VALUE (args1), TREE_VALUE (args2))))
588 /* Allow wait (union {union wait *u; int *i} *)
589 and wait (union wait *) to be compatible. */
590 if (TREE_CODE (TREE_VALUE (args1)) == UNION_TYPE
591 && TYPE_NAME (TREE_VALUE (args1)) == 0
592 && TREE_CODE (TYPE_SIZE (TREE_VALUE (args1))) == INTEGER_CST
593 && tree_int_cst_equal (TYPE_SIZE (TREE_VALUE (args1)),
594 TYPE_SIZE (TREE_VALUE (args2))))
597 for (memb = TYPE_FIELDS (TREE_VALUE (args1));
598 memb; memb = TREE_CHAIN (memb))
599 if (comptypes (TREE_TYPE (memb), TREE_VALUE (args2)))
604 else if (TREE_CODE (TREE_VALUE (args2)) == UNION_TYPE
605 && TYPE_NAME (TREE_VALUE (args2)) == 0
606 && TREE_CODE (TYPE_SIZE (TREE_VALUE (args2))) == INTEGER_CST
607 && tree_int_cst_equal (TYPE_SIZE (TREE_VALUE (args2)),
608 TYPE_SIZE (TREE_VALUE (args1))))
611 for (memb = TYPE_FIELDS (TREE_VALUE (args2));
612 memb; memb = TREE_CHAIN (memb))
613 if (comptypes (TREE_TYPE (memb), TREE_VALUE (args1)))
622 /* comptypes said ok, but record if it said to warn. */
626 args1 = TREE_CHAIN (args1);
627 args2 = TREE_CHAIN (args2);
631 /* Return 1 if PARMS specifies a fixed number of parameters
632 and none of their types is affected by default promotions. */
635 self_promoting_args_p (parms)
639 for (t = parms; t; t = TREE_CHAIN (t))
641 register tree type = TREE_VALUE (t);
643 if (TREE_CHAIN (t) == 0 && type != void_type_node)
649 if (TYPE_MAIN_VARIANT (type) == float_type_node)
652 if (C_PROMOTING_INTEGER_TYPE_P (type))
658 /* Return 1 if TYPE is not affected by default promotions. */
661 self_promoting_type_p (type)
664 if (TYPE_MAIN_VARIANT (type) == float_type_node)
667 if (C_PROMOTING_INTEGER_TYPE_P (type))
673 /* Return an unsigned type the same as TYPE in other respects. */
679 tree type1 = TYPE_MAIN_VARIANT (type);
680 if (type1 == signed_char_type_node || type1 == char_type_node)
681 return unsigned_char_type_node;
682 if (type1 == integer_type_node)
683 return unsigned_type_node;
684 if (type1 == short_integer_type_node)
685 return short_unsigned_type_node;
686 if (type1 == long_integer_type_node)
687 return long_unsigned_type_node;
688 if (type1 == long_long_integer_type_node)
689 return long_long_unsigned_type_node;
693 /* Return a signed type the same as TYPE in other respects. */
699 tree type1 = TYPE_MAIN_VARIANT (type);
700 if (type1 == unsigned_char_type_node || type1 == char_type_node)
701 return signed_char_type_node;
702 if (type1 == unsigned_type_node)
703 return integer_type_node;
704 if (type1 == short_unsigned_type_node)
705 return short_integer_type_node;
706 if (type1 == long_unsigned_type_node)
707 return long_integer_type_node;
708 if (type1 == long_long_unsigned_type_node)
709 return long_long_integer_type_node;
713 /* Return a type the same as TYPE except unsigned or
714 signed according to UNSIGNEDP. */
717 signed_or_unsigned_type (unsignedp, type)
721 if (! INTEGRAL_TYPE_P (type))
723 if (TYPE_PRECISION (type) == TYPE_PRECISION (signed_char_type_node))
724 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
725 if (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
726 return unsignedp ? unsigned_type_node : integer_type_node;
727 if (TYPE_PRECISION (type) == TYPE_PRECISION (short_integer_type_node))
728 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
729 if (TYPE_PRECISION (type) == TYPE_PRECISION (long_integer_type_node))
730 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
731 if (TYPE_PRECISION (type) == TYPE_PRECISION (long_long_integer_type_node))
732 return (unsignedp ? long_long_unsigned_type_node
733 : long_long_integer_type_node);
737 /* Compute the value of the `sizeof' operator. */
743 enum tree_code code = TREE_CODE (type);
746 if (code == FUNCTION_TYPE)
748 if (pedantic || warn_pointer_arith)
749 pedwarn ("sizeof applied to a function type");
752 if (code == VOID_TYPE)
754 if (pedantic || warn_pointer_arith)
755 pedwarn ("sizeof applied to a void type");
758 if (code == ERROR_MARK)
760 if (TYPE_SIZE (type) == 0)
762 error ("sizeof applied to an incomplete type");
766 /* Convert in case a char is more than one unit. */
767 t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type),
768 size_int (TYPE_PRECISION (char_type_node)));
769 /* size_binop does not put the constant in range, so do it now. */
770 if (TREE_CODE (t) == INTEGER_CST && force_fit_type (t, 0))
771 TREE_CONSTANT_OVERFLOW (t) = TREE_OVERFLOW (t) = 1;
776 c_sizeof_nowarn (type)
779 enum tree_code code = TREE_CODE (type);
782 if (code == FUNCTION_TYPE
784 || code == ERROR_MARK)
786 if (TYPE_SIZE (type) == 0)
789 /* Convert in case a char is more than one unit. */
790 t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type),
791 size_int (TYPE_PRECISION (char_type_node)));
792 force_fit_type (t, 0);
796 /* Compute the size to increment a pointer by. */
799 c_size_in_bytes (type)
802 enum tree_code code = TREE_CODE (type);
805 if (code == FUNCTION_TYPE)
807 if (code == VOID_TYPE)
809 if (code == ERROR_MARK)
811 if (TYPE_SIZE (type) == 0)
813 error ("arithmetic on pointer to an incomplete type");
817 /* Convert in case a char is more than one unit. */
818 t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type),
819 size_int (BITS_PER_UNIT));
820 force_fit_type (t, 0);
824 /* Implement the __alignof keyword: Return the minimum required
825 alignment of TYPE, measured in bytes. */
831 enum tree_code code = TREE_CODE (type);
833 if (code == FUNCTION_TYPE)
834 return size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
836 if (code == VOID_TYPE || code == ERROR_MARK)
839 return size_int (TYPE_ALIGN (type) / BITS_PER_UNIT);
842 /* Implement the __alignof keyword: Return the minimum required
843 alignment of EXPR, measured in bytes. For VAR_DECL's and
844 FIELD_DECL's return DECL_ALIGN (which can be set from an
845 "aligned" __attribute__ specification). */
848 c_alignof_expr (expr)
851 if (TREE_CODE (expr) == VAR_DECL)
852 return size_int (DECL_ALIGN (expr) / BITS_PER_UNIT);
854 if (TREE_CODE (expr) == COMPONENT_REF
855 && DECL_BIT_FIELD (TREE_OPERAND (expr, 1)))
857 error ("`__alignof' applied to a bit-field");
860 else if (TREE_CODE (expr) == COMPONENT_REF
861 && TREE_CODE (TREE_OPERAND (expr, 1)) == FIELD_DECL)
862 return size_int (DECL_ALIGN (TREE_OPERAND (expr, 1)) / BITS_PER_UNIT);
864 if (TREE_CODE (expr) == INDIRECT_REF)
866 tree t = TREE_OPERAND (expr, 0);
868 int bestalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
870 while (TREE_CODE (t) == NOP_EXPR
871 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == POINTER_TYPE)
875 t = TREE_OPERAND (t, 0);
876 thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
877 if (thisalign > bestalign)
878 best = t, bestalign = thisalign;
880 return c_alignof (TREE_TYPE (TREE_TYPE (best)));
883 return c_alignof (TREE_TYPE (expr));
885 /* Return either DECL or its known constant value (if it has one). */
888 decl_constant_value (decl)
891 if (! TREE_PUBLIC (decl)
892 /* Don't change a variable array bound or initial value to a constant
893 in a place where a variable is invalid. */
894 && current_function_decl != 0
896 && ! TREE_THIS_VOLATILE (decl)
897 && DECL_INITIAL (decl) != 0
898 && TREE_CODE (DECL_INITIAL (decl)) != ERROR_MARK
899 /* This is invalid if initial value is not constant.
900 If it has either a function call, a memory reference,
901 or a variable, then re-evaluating it could give different results. */
902 && TREE_CONSTANT (DECL_INITIAL (decl))
903 /* Check for cases where this is sub-optimal, even though valid. */
904 && TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR
905 && DECL_MODE (decl) != BLKmode)
906 return DECL_INITIAL (decl);
910 /* Perform default promotions for C data used in expressions.
911 Arrays and functions are converted to pointers;
912 enumeral types or short or char, to int.
913 In addition, manifest constants symbols are replaced by their values. */
916 default_conversion (exp)
919 register tree type = TREE_TYPE (exp);
920 register enum tree_code code = TREE_CODE (type);
922 /* Constants can be used directly unless they're not loadable. */
923 if (TREE_CODE (exp) == CONST_DECL)
924 exp = DECL_INITIAL (exp);
925 /* Replace a nonvolatile const static variable with its value. */
927 && TREE_CODE (exp) == VAR_DECL
928 && TREE_READONLY (exp)
929 /* But not for iterators! */
931 && DECL_MODE (exp) != BLKmode)
933 exp = decl_constant_value (exp);
934 type = TREE_TYPE (exp);
937 /* Strip NON_LVALUE_EXPRs and no-op conversions, since we aren't using as
939 /* Do not use STRIP_NOPS here! It will remove conversions from pointer
940 to integer and cause infinite recursion. */
941 while (TREE_CODE (exp) == NON_LVALUE_EXPR
942 || (TREE_CODE (exp) == NOP_EXPR
943 && TREE_TYPE (TREE_OPERAND (exp, 0)) == TREE_TYPE (exp)))
944 exp = TREE_OPERAND (exp, 0);
946 /* Normally convert enums to int,
947 but convert wide enums to something wider. */
948 if (code == ENUMERAL_TYPE)
950 type = type_for_size (MAX (TYPE_PRECISION (type),
951 TYPE_PRECISION (integer_type_node)),
953 || TYPE_PRECISION (type) >= TYPE_PRECISION (integer_type_node))
954 && TREE_UNSIGNED (type)));
955 return convert (type, exp);
958 if (C_PROMOTING_INTEGER_TYPE_P (type))
960 /* Traditionally, unsignedness is preserved in default promotions.
961 Also preserve unsignedness if not really getting any wider. */
962 if (TREE_UNSIGNED (type)
964 || TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)))
965 return convert (unsigned_type_node, exp);
966 return convert (integer_type_node, exp);
968 if (flag_traditional && !flag_allow_single_precision
969 && TYPE_MAIN_VARIANT (type) == float_type_node)
970 return convert (double_type_node, exp);
971 if (code == VOID_TYPE)
973 error ("void value not ignored as it ought to be");
974 return error_mark_node;
976 if (code == FUNCTION_TYPE)
978 return build_unary_op (ADDR_EXPR, exp, 0);
980 if (code == ARRAY_TYPE)
983 tree restype = TREE_TYPE (type);
988 if (TREE_CODE_CLASS (TREE_CODE (exp)) == 'r'
989 || TREE_CODE_CLASS (TREE_CODE (exp)) == 'd')
991 constp = TREE_READONLY (exp);
992 volatilep = TREE_THIS_VOLATILE (exp);
995 if (TYPE_READONLY (type) || TYPE_VOLATILE (type)
996 || constp || volatilep)
997 restype = c_build_type_variant (restype,
998 TYPE_READONLY (type) || constp,
999 TYPE_VOLATILE (type) || volatilep);
1001 if (TREE_CODE (exp) == INDIRECT_REF)
1002 return convert (TYPE_POINTER_TO (restype),
1003 TREE_OPERAND (exp, 0));
1005 if (TREE_CODE (exp) == COMPOUND_EXPR)
1007 tree op1 = default_conversion (TREE_OPERAND (exp, 1));
1008 return build (COMPOUND_EXPR, TREE_TYPE (op1),
1009 TREE_OPERAND (exp, 0), op1);
1013 && ! (TREE_CODE (exp) == CONSTRUCTOR && TREE_STATIC (exp)))
1015 error ("invalid use of non-lvalue array");
1016 return error_mark_node;
1019 ptrtype = build_pointer_type (restype);
1021 if (TREE_CODE (exp) == VAR_DECL)
1023 /* ??? This is not really quite correct
1024 in that the type of the operand of ADDR_EXPR
1025 is not the target type of the type of the ADDR_EXPR itself.
1026 Question is, can this lossage be avoided? */
1027 adr = build1 (ADDR_EXPR, ptrtype, exp);
1028 if (mark_addressable (exp) == 0)
1029 return error_mark_node;
1030 TREE_CONSTANT (adr) = staticp (exp);
1031 TREE_SIDE_EFFECTS (adr) = 0; /* Default would be, same as EXP. */
1034 /* This way is better for a COMPONENT_REF since it can
1035 simplify the offset for a component. */
1036 adr = build_unary_op (ADDR_EXPR, exp, 1);
1037 return convert (ptrtype, adr);
1042 /* Look up component name in the structure type definition.
1044 If this component name is found indirectly within an anonymous union,
1045 store in *INDIRECT the component which directly contains
1046 that anonymous union. Otherwise, set *INDIRECT to 0. */
1049 lookup_field (type, component, indirect)
1050 tree type, component;
1055 /* If TYPE_LANG_SPECIFIC is set, then it is a sorted array of pointers
1056 to the field elements. Use a binary search on this array to quickly
1057 find the element. Otherwise, do a linear search. TYPE_LANG_SPECIFIC
1058 will always be set for structures which have many elements. */
1060 if (TYPE_LANG_SPECIFIC (type))
1063 tree *field_array = &TYPE_LANG_SPECIFIC (type)->elts[0];
1065 field = TYPE_FIELDS (type);
1067 top = TYPE_LANG_SPECIFIC (type)->len;
1068 while (top - bot > 1)
1072 half = (top - bot + 1) >> 1;
1073 field = field_array[bot+half];
1075 if (DECL_NAME (field) == NULL_TREE)
1077 /* Step through all anon unions in linear fashion. */
1078 while (DECL_NAME (field_array[bot]) == NULL_TREE)
1082 field = field_array[bot++];
1083 anon = lookup_field (TREE_TYPE (field), component, &junk);
1084 if (anon != NULL_TREE)
1091 /* Entire record is only anon unions. */
1095 /* Restart the binary search, with new lower bound. */
1099 cmp = (HOST_WIDE_INT) DECL_NAME (field) - (HOST_WIDE_INT) component;
1108 if (DECL_NAME (field_array[bot]) == component)
1109 field = field_array[bot];
1110 else if (DECL_NAME (field) != component)
1115 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
1117 if (DECL_NAME (field) == NULL_TREE)
1120 tree anon = lookup_field (TREE_TYPE (field), component, &junk);
1121 if (anon != NULL_TREE)
1128 if (DECL_NAME (field) == component)
1133 *indirect = NULL_TREE;
1137 /* Make an expression to refer to the COMPONENT field of
1138 structure or union value DATUM. COMPONENT is an IDENTIFIER_NODE. */
1141 build_component_ref (datum, component)
1142 tree datum, component;
1144 register tree type = TREE_TYPE (datum);
1145 register enum tree_code code = TREE_CODE (type);
1146 register tree field = NULL;
1149 /* If DATUM is a COMPOUND_EXPR or COND_EXPR, move our reference inside it
1150 unless we are not to support things not strictly ANSI. */
1151 switch (TREE_CODE (datum))
1155 tree value = build_component_ref (TREE_OPERAND (datum, 1), component);
1156 return build (COMPOUND_EXPR, TREE_TYPE (value),
1157 TREE_OPERAND (datum, 0), value);
1160 return build_conditional_expr
1161 (TREE_OPERAND (datum, 0),
1162 build_component_ref (TREE_OPERAND (datum, 1), component),
1163 build_component_ref (TREE_OPERAND (datum, 2), component));
1166 /* See if there is a field or component with name COMPONENT. */
1168 if (code == RECORD_TYPE || code == UNION_TYPE)
1172 if (TYPE_SIZE (type) == 0)
1174 incomplete_type_error (NULL_TREE, type);
1175 return error_mark_node;
1178 field = lookup_field (type, component, &indirect);
1182 error (code == RECORD_TYPE
1183 ? "structure has no member named `%s'"
1184 : "union has no member named `%s'",
1185 IDENTIFIER_POINTER (component));
1186 return error_mark_node;
1188 if (TREE_TYPE (field) == error_mark_node)
1189 return error_mark_node;
1191 /* If FIELD was found buried within an anonymous union,
1192 make one COMPONENT_REF to get that anonymous union,
1193 then fall thru to make a second COMPONENT_REF to get FIELD. */
1196 ref = build (COMPONENT_REF, TREE_TYPE (indirect), datum, indirect);
1197 if (TREE_READONLY (datum) || TREE_READONLY (indirect))
1198 TREE_READONLY (ref) = 1;
1199 if (TREE_THIS_VOLATILE (datum) || TREE_THIS_VOLATILE (indirect))
1200 TREE_THIS_VOLATILE (ref) = 1;
1204 ref = build (COMPONENT_REF, TREE_TYPE (field), datum, field);
1206 if (TREE_READONLY (datum) || TREE_READONLY (field))
1207 TREE_READONLY (ref) = 1;
1208 if (TREE_THIS_VOLATILE (datum) || TREE_THIS_VOLATILE (field))
1209 TREE_THIS_VOLATILE (ref) = 1;
1213 else if (code != ERROR_MARK)
1214 error ("request for member `%s' in something not a structure or union",
1215 IDENTIFIER_POINTER (component));
1217 return error_mark_node;
1220 /* Given an expression PTR for a pointer, return an expression
1221 for the value pointed to.
1222 ERRORSTRING is the name of the operator to appear in error messages. */
1225 build_indirect_ref (ptr, errorstring)
1229 register tree pointer = default_conversion (ptr);
1230 register tree type = TREE_TYPE (pointer);
1232 if (TREE_CODE (type) == POINTER_TYPE)
1234 if (TREE_CODE (pointer) == ADDR_EXPR
1236 && (TREE_TYPE (TREE_OPERAND (pointer, 0))
1237 == TREE_TYPE (type)))
1238 return TREE_OPERAND (pointer, 0);
1241 tree t = TREE_TYPE (type);
1242 register tree ref = build1 (INDIRECT_REF,
1243 TYPE_MAIN_VARIANT (t), pointer);
1245 if (TYPE_SIZE (t) == 0 && TREE_CODE (t) != ARRAY_TYPE)
1247 error ("dereferencing pointer to incomplete type");
1248 return error_mark_node;
1250 if (TREE_CODE (t) == VOID_TYPE)
1251 warning ("dereferencing `void *' pointer");
1253 /* We *must* set TREE_READONLY when dereferencing a pointer to const,
1254 so that we get the proper error message if the result is used
1255 to assign to. Also, &* is supposed to be a no-op.
1256 And ANSI C seems to specify that the type of the result
1257 should be the const type. */
1258 /* A de-reference of a pointer to const is not a const. It is valid
1259 to change it via some other pointer. */
1260 TREE_READONLY (ref) = TYPE_READONLY (t);
1261 TREE_SIDE_EFFECTS (ref)
1262 = TYPE_VOLATILE (t) || TREE_SIDE_EFFECTS (pointer) || flag_volatile;
1263 TREE_THIS_VOLATILE (ref) = TYPE_VOLATILE (t);
1267 else if (TREE_CODE (pointer) != ERROR_MARK)
1268 error ("invalid type argument of `%s'", errorstring);
1269 return error_mark_node;
1272 /* This handles expressions of the form "a[i]", which denotes
1275 This is logically equivalent in C to *(a+i), but we may do it differently.
1276 If A is a variable or a member, we generate a primitive ARRAY_REF.
1277 This avoids forcing the array out of registers, and can work on
1278 arrays that are not lvalues (for example, members of structures returned
1282 build_array_ref (array, index)
1287 error ("subscript missing in array reference");
1288 return error_mark_node;
1291 if (TREE_TYPE (array) == error_mark_node
1292 || TREE_TYPE (index) == error_mark_node)
1293 return error_mark_node;
1295 if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE
1296 && TREE_CODE (array) != INDIRECT_REF)
1300 /* Subscripting with type char is likely to lose
1301 on a machine where chars are signed.
1302 So warn on any machine, but optionally.
1303 Don't warn for unsigned char since that type is safe.
1304 Don't warn for signed char because anyone who uses that
1305 must have done so deliberately. */
1306 if (warn_char_subscripts
1307 && TYPE_MAIN_VARIANT (TREE_TYPE (index)) == char_type_node)
1308 warning ("array subscript has type `char'");
1310 /* Apply default promotions *after* noticing character types. */
1311 index = default_conversion (index);
1313 /* Require integer *after* promotion, for sake of enums. */
1314 if (TREE_CODE (TREE_TYPE (index)) != INTEGER_TYPE)
1316 error ("array subscript is not an integer");
1317 return error_mark_node;
1320 /* An array that is indexed by a non-constant
1321 cannot be stored in a register; we must be able to do
1322 address arithmetic on its address.
1323 Likewise an array of elements of variable size. */
1324 if (TREE_CODE (index) != INTEGER_CST
1325 || (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array))) != 0
1326 && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array)))) != INTEGER_CST))
1328 if (mark_addressable (array) == 0)
1329 return error_mark_node;
1331 /* An array that is indexed by a constant value which is not within
1332 the array bounds cannot be stored in a register either; because we
1333 would get a crash in store_bit_field/extract_bit_field when trying
1334 to access a non-existent part of the register. */
1335 if (TREE_CODE (index) == INTEGER_CST
1336 && TYPE_VALUES (TREE_TYPE (array))
1337 && ! int_fits_type_p (index, TYPE_VALUES (TREE_TYPE (array))))
1339 if (mark_addressable (array) == 0)
1340 return error_mark_node;
1343 if (pedantic && !lvalue_p (array))
1345 if (DECL_REGISTER (array))
1346 pedwarn ("ANSI C forbids subscripting `register' array");
1348 pedwarn ("ANSI C forbids subscripting non-lvalue array");
1354 while (TREE_CODE (foo) == COMPONENT_REF)
1355 foo = TREE_OPERAND (foo, 0);
1356 if (TREE_CODE (foo) == VAR_DECL && DECL_REGISTER (foo))
1357 pedwarn ("ANSI C forbids subscripting non-lvalue array");
1360 type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (array)));
1361 rval = build (ARRAY_REF, type, array, index);
1362 /* Array ref is const/volatile if the array elements are
1363 or if the array is. */
1364 TREE_READONLY (rval)
1365 |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array)))
1366 | TREE_READONLY (array));
1367 TREE_SIDE_EFFECTS (rval)
1368 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
1369 | TREE_SIDE_EFFECTS (array));
1370 TREE_THIS_VOLATILE (rval)
1371 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
1372 /* This was added by rms on 16 Nov 91.
1373 It fixes vol struct foo *a; a->elts[1]
1374 in an inline function.
1375 Hope it doesn't break something else. */
1376 | TREE_THIS_VOLATILE (array));
1377 return require_complete_type (fold (rval));
1381 tree ar = default_conversion (array);
1382 tree ind = default_conversion (index);
1384 /* Put the integer in IND to simplify error checking. */
1385 if (TREE_CODE (TREE_TYPE (ar)) == INTEGER_TYPE)
1392 if (ar == error_mark_node)
1395 if (TREE_CODE (TREE_TYPE (ar)) != POINTER_TYPE)
1397 error ("subscripted value is neither array nor pointer");
1398 return error_mark_node;
1400 if (TREE_CODE (TREE_TYPE (ind)) != INTEGER_TYPE)
1402 error ("array subscript is not an integer");
1403 return error_mark_node;
1406 return build_indirect_ref (build_binary_op (PLUS_EXPR, ar, ind, 0),
1411 /* Build a function call to function FUNCTION with parameters PARAMS.
1412 PARAMS is a list--a chain of TREE_LIST nodes--in which the
1413 TREE_VALUE of each node is a parameter-expression.
1414 FUNCTION's data type may be a function type or a pointer-to-function. */
1417 build_function_call (function, params)
1418 tree function, params;
1420 register tree fntype, fundecl = 0;
1421 register tree coerced_params;
1422 tree name = NULL_TREE, assembler_name = NULL_TREE;
1424 /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
1425 STRIP_TYPE_NOPS (function);
1427 /* Convert anything with function type to a pointer-to-function. */
1428 if (TREE_CODE (function) == FUNCTION_DECL)
1430 name = DECL_NAME (function);
1431 assembler_name = DECL_ASSEMBLER_NAME (function);
1433 /* Differs from default_conversion by not setting TREE_ADDRESSABLE
1434 (because calling an inline function does not mean the function
1435 needs to be separately compiled). */
1436 fntype = build_type_variant (TREE_TYPE (function),
1437 TREE_READONLY (function),
1438 TREE_THIS_VOLATILE (function));
1440 function = build1 (ADDR_EXPR, build_pointer_type (fntype), function);
1443 function = default_conversion (function);
1445 fntype = TREE_TYPE (function);
1447 if (TREE_CODE (fntype) == ERROR_MARK)
1448 return error_mark_node;
1450 if (!(TREE_CODE (fntype) == POINTER_TYPE
1451 && TREE_CODE (TREE_TYPE (fntype)) == FUNCTION_TYPE))
1453 error ("called object is not a function");
1454 return error_mark_node;
1457 /* fntype now gets the type of function pointed to. */
1458 fntype = TREE_TYPE (fntype);
1460 /* Convert the parameters to the types declared in the
1461 function prototype, or apply default promotions. */
1464 = convert_arguments (TYPE_ARG_TYPES (fntype), params, name, fundecl);
1466 /* Check for errors in format strings. */
1468 if (warn_format && (name || assembler_name))
1469 check_function_format (name, assembler_name, coerced_params);
1471 /* Recognize certain built-in functions so we can make tree-codes
1472 other than CALL_EXPR. We do this when it enables fold-const.c
1473 to do something useful. */
1475 if (TREE_CODE (function) == ADDR_EXPR
1476 && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL
1477 && DECL_BUILT_IN (TREE_OPERAND (function, 0)))
1478 switch (DECL_FUNCTION_CODE (TREE_OPERAND (function, 0)))
1483 if (coerced_params == 0)
1484 return integer_zero_node;
1485 return build_unary_op (ABS_EXPR, TREE_VALUE (coerced_params), 0);
1489 register tree result
1490 = build (CALL_EXPR, TREE_TYPE (fntype),
1491 function, coerced_params, NULL_TREE);
1493 TREE_SIDE_EFFECTS (result) = 1;
1494 if (TREE_TYPE (result) == void_type_node)
1496 return require_complete_type (result);
1500 /* Convert the argument expressions in the list VALUES
1501 to the types in the list TYPELIST. The result is a list of converted
1502 argument expressions.
1504 If TYPELIST is exhausted, or when an element has NULL as its type,
1505 perform the default conversions.
1507 PARMLIST is the chain of parm decls for the function being called.
1508 It may be 0, if that info is not available.
1509 It is used only for generating error messages.
1511 NAME is an IDENTIFIER_NODE or 0. It is used only for error messages.
1513 This is also where warnings about wrong number of args are generated.
1515 Both VALUES and the returned value are chains of TREE_LIST nodes
1516 with the elements of the list in the TREE_VALUE slots of those nodes. */
1519 convert_arguments (typelist, values, name, fundecl)
1520 tree typelist, values, name, fundecl;
1522 register tree typetail, valtail;
1523 register tree result = NULL;
1526 /* Scan the given expressions and types, producing individual
1527 converted arguments and pushing them on RESULT in reverse order. */
1529 for (valtail = values, typetail = typelist, parmnum = 0;
1531 valtail = TREE_CHAIN (valtail), parmnum++)
1533 register tree type = typetail ? TREE_VALUE (typetail) : 0;
1534 register tree val = TREE_VALUE (valtail);
1536 if (type == void_type_node)
1539 error ("too many arguments to function `%s'",
1540 IDENTIFIER_POINTER (name));
1542 error ("too many arguments to function");
1546 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
1547 /* Do not use STRIP_NOPS here! We do not want an enumerator with value 0
1548 to convert automatically to a pointer. */
1549 if (TREE_CODE (val) == NON_LVALUE_EXPR)
1550 val = TREE_OPERAND (val, 0);
1552 if (TREE_CODE (TREE_TYPE (val)) == ARRAY_TYPE
1553 || TREE_CODE (TREE_TYPE (val)) == FUNCTION_TYPE)
1554 val = default_conversion (val);
1556 val = require_complete_type (val);
1560 /* Formal parm type is specified by a function prototype. */
1563 if (TYPE_SIZE (type) == 0)
1565 error ("type of formal parameter %d is incomplete", parmnum + 1);
1572 #ifdef PROMOTE_PROTOTYPES
1573 /* Rather than truncating and then reextending,
1574 convert directly to int, if that's the type we will want. */
1575 if (! flag_traditional
1576 && (TREE_CODE (type) == INTEGER_TYPE
1577 || TREE_CODE (type) == ENUMERAL_TYPE)
1578 && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
1579 type = integer_type_node;
1582 #if 0 /* This turns out not to win--there's no way to write a prototype
1583 for a function whose arg type is a union with no tag. */
1584 /* Nameless union automatically casts the types it contains. */
1585 if (TREE_CODE (type) == UNION_TYPE && TYPE_NAME (type) == 0)
1589 for (field = TYPE_FIELDS (type); field;
1590 field = TREE_CHAIN (field))
1591 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (field)),
1592 TYPE_MAIN_VARIANT (TREE_TYPE (val))))
1596 val = build1 (CONVERT_EXPR, type, val);
1600 /* Optionally warn about conversions that
1601 differ from the default conversions. */
1602 if (warn_conversion)
1604 int formal_prec = TYPE_PRECISION (type);
1606 if (TREE_CODE (type) != REAL_TYPE
1607 && TREE_CODE (TREE_TYPE (val)) == REAL_TYPE)
1608 warn_for_assignment ("%s as integer rather than floating due to prototype", (char *) 0, name, parmnum + 1);
1609 else if (TREE_CODE (type) == REAL_TYPE
1610 && TREE_CODE (TREE_TYPE (val)) != REAL_TYPE)
1611 warn_for_assignment ("%s as floating rather than integer due to prototype", (char *) 0, name, parmnum + 1);
1612 else if (TREE_CODE (type) == REAL_TYPE
1613 && TREE_CODE (TREE_TYPE (val)) == REAL_TYPE)
1615 /* Warn if any argument is passed as `float',
1616 since without a prototype it would be `double'. */
1617 if (formal_prec == TYPE_PRECISION (float_type_node))
1618 warn_for_assignment ("%s as `float' rather than `double' due to prototype", (char *) 0, name, parmnum + 1);
1620 /* Detect integer changing in width or signedness. */
1621 else if ((TREE_CODE (type) == INTEGER_TYPE
1622 || TREE_CODE (type) == ENUMERAL_TYPE)
1623 && (TREE_CODE (TREE_TYPE (val)) == INTEGER_TYPE
1624 || TREE_CODE (TREE_TYPE (val)) == ENUMERAL_TYPE))
1626 tree would_have_been = default_conversion (val);
1627 tree type1 = TREE_TYPE (would_have_been);
1629 if (TREE_CODE (type) == ENUMERAL_TYPE
1630 && type == TREE_TYPE (val))
1631 /* No warning if function asks for enum
1632 and the actual arg is that enum type. */
1634 else if (formal_prec != TYPE_PRECISION (type1))
1635 warn_for_assignment ("%s with different width due to prototype", (char *) 0, name, parmnum + 1);
1636 else if (TREE_UNSIGNED (type) == TREE_UNSIGNED (type1))
1638 /* Don't complain if the formal parameter type
1639 is an enum, because we can't tell now whether
1640 the value was an enum--even the same enum. */
1641 else if (TREE_CODE (type) == ENUMERAL_TYPE)
1643 else if (TREE_CODE (val) == INTEGER_CST
1644 && int_fits_type_p (val, type))
1645 /* Change in signedness doesn't matter
1646 if a constant value is unaffected. */
1648 /* Likewise for a constant in a NOP_EXPR. */
1649 else if (TREE_CODE (val) == NOP_EXPR
1650 && TREE_CODE (TREE_OPERAND (val, 0)) == INTEGER_CST
1651 && int_fits_type_p (TREE_OPERAND (val, 0), type))
1653 #if 0 /* We never get such tree structure here. */
1654 else if (TREE_CODE (TREE_TYPE (val)) == ENUMERAL_TYPE
1655 && int_fits_type_p (TYPE_MIN_VALUE (TREE_TYPE (val)), type)
1656 && int_fits_type_p (TYPE_MAX_VALUE (TREE_TYPE (val)), type))
1657 /* Change in signedness doesn't matter
1658 if an enum value is unaffected. */
1661 /* If the value is extended from a narrower
1662 unsigned type, it doesn't matter whether we
1663 pass it as signed or unsigned; the value
1664 certainly is the same either way. */
1665 else if (TYPE_PRECISION (TREE_TYPE (val)) < TYPE_PRECISION (type)
1666 && TREE_UNSIGNED (TREE_TYPE (val)))
1668 else if (TREE_UNSIGNED (type))
1669 warn_for_assignment ("%s as unsigned due to prototype", (char *) 0, name, parmnum + 1);
1671 warn_for_assignment ("%s as signed due to prototype", (char *) 0, name, parmnum + 1);
1675 parmval = convert_for_assignment (type, val,
1676 (char *)0, /* arg passing */
1677 fundecl, name, parmnum + 1);
1679 #ifdef PROMOTE_PROTOTYPES
1680 if ((TREE_CODE (type) == INTEGER_TYPE
1681 || TREE_CODE (type) == ENUMERAL_TYPE)
1682 && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
1683 parmval = default_conversion (parmval);
1686 result = tree_cons (NULL_TREE, parmval, result);
1688 else if (TREE_CODE (TREE_TYPE (val)) == REAL_TYPE
1689 && (TYPE_PRECISION (TREE_TYPE (val))
1690 < TYPE_PRECISION (double_type_node)))
1691 /* Convert `float' to `double'. */
1692 result = tree_cons (NULL_TREE, convert (double_type_node, val), result);
1694 /* Convert `short' and `char' to full-size `int'. */
1695 result = tree_cons (NULL_TREE, default_conversion (val), result);
1698 typetail = TREE_CHAIN (typetail);
1701 if (typetail != 0 && TREE_VALUE (typetail) != void_type_node)
1704 error ("too few arguments to function `%s'",
1705 IDENTIFIER_POINTER (name));
1707 error ("too few arguments to function");
1710 return nreverse (result);
1713 /* This is the entry point used by the parser
1714 for binary operators in the input.
1715 In addition to constructing the expression,
1716 we check for operands that were written with other binary operators
1717 in a way that is likely to confuse the user. */
1720 parser_build_binary_op (code, arg1, arg2)
1721 enum tree_code code;
1724 tree result = build_binary_op (code, arg1, arg2, 1);
1727 char class1 = TREE_CODE_CLASS (TREE_CODE (arg1));
1728 char class2 = TREE_CODE_CLASS (TREE_CODE (arg2));
1729 enum tree_code code1 = ERROR_MARK;
1730 enum tree_code code2 = ERROR_MARK;
1732 if (class1 == 'e' || class1 == '1'
1733 || class1 == '2' || class1 == '<')
1734 code1 = C_EXP_ORIGINAL_CODE (arg1);
1735 if (class2 == 'e' || class2 == '1'
1736 || class2 == '2' || class2 == '<')
1737 code2 = C_EXP_ORIGINAL_CODE (arg2);
1739 /* Check for cases such as x+y<<z which users are likely
1740 to misinterpret. If parens are used, C_EXP_ORIGINAL_CODE
1741 is cleared to prevent these warnings. */
1742 if (warn_parentheses)
1744 if (code == LSHIFT_EXPR || code == RSHIFT_EXPR)
1746 if (code1 == PLUS_EXPR || code1 == MINUS_EXPR
1747 || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
1748 warning ("suggest parentheses around + or - inside shift");
1751 if (code == TRUTH_ORIF_EXPR)
1753 if (code1 == TRUTH_ANDIF_EXPR
1754 || code2 == TRUTH_ANDIF_EXPR)
1755 warning ("suggest parentheses around && within ||");
1758 if (code == BIT_IOR_EXPR)
1760 if (code1 == BIT_AND_EXPR || code1 == BIT_XOR_EXPR
1761 || code1 == PLUS_EXPR || code1 == MINUS_EXPR
1762 || code2 == BIT_AND_EXPR || code2 == BIT_XOR_EXPR
1763 || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
1764 warning ("suggest parentheses around arithmetic in operand of |");
1767 if (code == BIT_XOR_EXPR)
1769 if (code1 == BIT_AND_EXPR
1770 || code1 == PLUS_EXPR || code1 == MINUS_EXPR
1771 || code2 == BIT_AND_EXPR
1772 || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
1773 warning ("suggest parentheses around arithmetic in operand of ^");
1776 if (code == BIT_AND_EXPR)
1778 if (code1 == PLUS_EXPR || code1 == MINUS_EXPR
1779 || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
1780 warning ("suggest parentheses around + or - in operand of &");
1784 /* Similarly, check for cases like 1<=i<=10 that are probably errors. */
1785 if (TREE_CODE_CLASS (code) == '<' && extra_warnings
1786 && (TREE_CODE_CLASS (code1) == '<' || TREE_CODE_CLASS (code2) == '<'))
1787 warning ("comparisons like X<=Y<=Z do not have their mathematical meaning");
1789 unsigned_conversion_warning (result, arg1);
1790 unsigned_conversion_warning (result, arg2);
1791 overflow_warning (result);
1793 class = TREE_CODE_CLASS (TREE_CODE (result));
1795 /* Record the code that was specified in the source,
1796 for the sake of warnings about confusing nesting. */
1797 if (class == 'e' || class == '1'
1798 || class == '2' || class == '<')
1799 C_SET_EXP_ORIGINAL_CODE (result, code);
1802 int flag = TREE_CONSTANT (result);
1803 /* We used to use NOP_EXPR rather than NON_LVALUE_EXPR
1804 so that convert_for_assignment wouldn't strip it.
1805 That way, we got warnings for things like p = (1 - 1).
1806 But it turns out we should not get those warnings. */
1807 result = build1 (NON_LVALUE_EXPR, TREE_TYPE (result), result);
1808 C_SET_EXP_ORIGINAL_CODE (result, code);
1809 TREE_CONSTANT (result) = flag;
1815 /* Build a binary-operation expression without default conversions.
1816 CODE is the kind of expression to build.
1817 This function differs from `build' in several ways:
1818 the data type of the result is computed and recorded in it,
1819 warnings are generated if arg data types are invalid,
1820 special handling for addition and subtraction of pointers is known,
1821 and some optimization is done (operations on narrow ints
1822 are done in the narrower type when that gives the same result).
1823 Constant folding is also done before the result is returned.
1825 Note that the operands will never have enumeral types, or function
1826 or array types, because either they will have the default conversions
1827 performed or they have both just been converted to some other type in which
1828 the arithmetic is to be done. */
1831 build_binary_op (code, orig_op0, orig_op1, convert_p)
1832 enum tree_code code;
1833 tree orig_op0, orig_op1;
1837 register enum tree_code code0, code1;
1840 /* Expression code to give to the expression when it is built.
1841 Normally this is CODE, which is what the caller asked for,
1842 but in some special cases we change it. */
1843 register enum tree_code resultcode = code;
1845 /* Data type in which the computation is to be performed.
1846 In the simplest cases this is the common type of the arguments. */
1847 register tree result_type = NULL;
1849 /* Nonzero means operands have already been type-converted
1850 in whatever way is necessary.
1851 Zero means they need to be converted to RESULT_TYPE. */
1854 /* Nonzero means after finally constructing the expression
1855 give it this type. Otherwise, give it type RESULT_TYPE. */
1856 tree final_type = 0;
1858 /* Nonzero if this is an operation like MIN or MAX which can
1859 safely be computed in short if both args are promoted shorts.
1860 Also implies COMMON.
1861 -1 indicates a bitwise operation; this makes a difference
1862 in the exact conditions for when it is safe to do the operation
1863 in a narrower mode. */
1866 /* Nonzero if this is a comparison operation;
1867 if both args are promoted shorts, compare the original shorts.
1868 Also implies COMMON. */
1869 int short_compare = 0;
1871 /* Nonzero if this is a right-shift operation, which can be computed on the
1872 original short and then promoted if the operand is a promoted short. */
1873 int short_shift = 0;
1875 /* Nonzero means set RESULT_TYPE to the common type of the args. */
1880 op0 = default_conversion (orig_op0);
1881 op1 = default_conversion (orig_op1);
1889 type0 = TREE_TYPE (op0);
1890 type1 = TREE_TYPE (op1);
1892 /* The expression codes of the data types of the arguments tell us
1893 whether the arguments are integers, floating, pointers, etc. */
1894 code0 = TREE_CODE (type0);
1895 code1 = TREE_CODE (type1);
1897 /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
1898 STRIP_TYPE_NOPS (op0);
1899 STRIP_TYPE_NOPS (op1);
1901 /* If an error was already reported for one of the arguments,
1902 avoid reporting another error. */
1904 if (code0 == ERROR_MARK || code1 == ERROR_MARK)
1905 return error_mark_node;
1910 /* Handle the pointer + int case. */
1911 if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
1912 return pointer_int_sum (PLUS_EXPR, op0, op1);
1913 else if (code1 == POINTER_TYPE && code0 == INTEGER_TYPE)
1914 return pointer_int_sum (PLUS_EXPR, op1, op0);
1920 /* Subtraction of two similar pointers.
1921 We must subtract them as integers, then divide by object size. */
1922 if (code0 == POINTER_TYPE && code1 == POINTER_TYPE
1923 && comp_target_types (type0, type1))
1924 return pointer_diff (op0, op1);
1925 /* Handle pointer minus int. Just like pointer plus int. */
1926 else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
1927 return pointer_int_sum (MINUS_EXPR, op0, op1);
1936 case TRUNC_DIV_EXPR:
1938 case FLOOR_DIV_EXPR:
1939 case ROUND_DIV_EXPR:
1940 case EXACT_DIV_EXPR:
1941 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
1942 || code0 == COMPLEX_TYPE)
1943 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
1944 || code1 == COMPLEX_TYPE))
1946 if (!(code0 == INTEGER_TYPE && code1 == INTEGER_TYPE))
1947 resultcode = RDIV_EXPR;
1950 /* Although it would be tempting to shorten always here, that
1951 loses on some targets, since the modulo instruction is
1952 undefined if the quotient can't be represented in the
1953 computation mode. We shorten only if unsigned or if
1954 dividing by something we know != -1. */
1955 shorten = (TREE_UNSIGNED (TREE_TYPE (orig_op0))
1956 || (TREE_CODE (op1) == INTEGER_CST
1957 && (TREE_INT_CST_LOW (op1) != -1
1958 || TREE_INT_CST_HIGH (op1) != -1)));
1965 case BIT_ANDTC_EXPR:
1968 if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
1970 /* If one operand is a constant, and the other is a short type
1971 that has been converted to an int,
1972 really do the work in the short type and then convert the
1973 result to int. If we are lucky, the constant will be 0 or 1
1974 in the short type, making the entire operation go away. */
1975 if (TREE_CODE (op0) == INTEGER_CST
1976 && TREE_CODE (op1) == NOP_EXPR
1977 && TYPE_PRECISION (type1) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op1, 0)))
1978 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op1, 0))))
1980 final_type = result_type;
1981 op1 = TREE_OPERAND (op1, 0);
1982 result_type = TREE_TYPE (op1);
1984 if (TREE_CODE (op1) == INTEGER_CST
1985 && TREE_CODE (op0) == NOP_EXPR
1986 && TYPE_PRECISION (type0) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0, 0)))
1987 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0, 0))))
1989 final_type = result_type;
1990 op0 = TREE_OPERAND (op0, 0);
1991 result_type = TREE_TYPE (op0);
1995 case TRUNC_MOD_EXPR:
1996 case FLOOR_MOD_EXPR:
1997 if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
1999 /* Although it would be tempting to shorten always here, that loses
2000 on some targets, since the modulo instruction is undefined if the
2001 quotient can't be represented in the computation mode. We shorten
2002 only if unsigned or if dividing by something we know != -1. */
2003 shorten = (TREE_UNSIGNED (TREE_TYPE (orig_op0))
2004 || (TREE_CODE (op1) == INTEGER_CST
2005 && (TREE_INT_CST_LOW (op1) != -1
2006 || TREE_INT_CST_HIGH (op1) != -1)));
2011 case TRUTH_ANDIF_EXPR:
2012 case TRUTH_ORIF_EXPR:
2013 case TRUTH_AND_EXPR:
2015 case TRUTH_XOR_EXPR:
2016 if ((code0 == INTEGER_TYPE || code0 == POINTER_TYPE
2017 || code0 == REAL_TYPE || code0 == COMPLEX_TYPE)
2018 && (code1 == INTEGER_TYPE || code1 == POINTER_TYPE
2019 || code1 == REAL_TYPE || code1 == COMPLEX_TYPE))
2021 /* Result of these operations is always an int,
2022 but that does not mean the operands should be
2023 converted to ints! */
2024 result_type = integer_type_node;
2025 op0 = truthvalue_conversion (op0);
2026 op1 = truthvalue_conversion (op1);
2031 /* Shift operations: result has same type as first operand;
2032 always convert second operand to int.
2033 Also set SHORT_SHIFT if shifting rightward. */
2036 if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
2038 if (TREE_CODE (op1) == INTEGER_CST)
2040 if (tree_int_cst_sgn (op1) < 0)
2041 warning ("right shift count is negative");
2044 if (TREE_INT_CST_LOW (op1) | TREE_INT_CST_HIGH (op1))
2046 if (TREE_INT_CST_HIGH (op1) != 0
2047 || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1)
2048 >= TYPE_PRECISION (type0)))
2049 warning ("right shift count >= width of type");
2052 /* Use the type of the value to be shifted.
2053 This is what most traditional C compilers do. */
2054 result_type = type0;
2055 /* Unless traditional, convert the shift-count to an integer,
2056 regardless of size of value being shifted. */
2057 if (! flag_traditional)
2059 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
2060 op1 = convert (integer_type_node, op1);
2061 /* Avoid converting op1 to result_type later. */
2068 if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
2070 if (TREE_CODE (op1) == INTEGER_CST)
2072 if (tree_int_cst_sgn (op1) < 0)
2073 warning ("left shift count is negative");
2074 else if (TREE_INT_CST_HIGH (op1) != 0
2075 || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1)
2076 >= TYPE_PRECISION (type0)))
2077 warning ("left shift count >= width of type");
2079 /* Use the type of the value to be shifted.
2080 This is what most traditional C compilers do. */
2081 result_type = type0;
2082 /* Unless traditional, convert the shift-count to an integer,
2083 regardless of size of value being shifted. */
2084 if (! flag_traditional)
2086 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
2087 op1 = convert (integer_type_node, op1);
2088 /* Avoid converting op1 to result_type later. */
2096 if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
2098 if (TREE_CODE (op1) == INTEGER_CST)
2100 if (tree_int_cst_sgn (op1) < 0)
2101 warning ("shift count is negative");
2102 else if (TREE_INT_CST_HIGH (op1) != 0
2103 || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1)
2104 >= TYPE_PRECISION (type0)))
2105 warning ("shift count >= width of type");
2107 /* Use the type of the value to be shifted.
2108 This is what most traditional C compilers do. */
2109 result_type = type0;
2110 /* Unless traditional, convert the shift-count to an integer,
2111 regardless of size of value being shifted. */
2112 if (! flag_traditional)
2114 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
2115 op1 = convert (integer_type_node, op1);
2116 /* Avoid converting op1 to result_type later. */
2124 /* Result of comparison is always int,
2125 but don't convert the args to int! */
2126 result_type = integer_type_node;
2128 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
2129 || code0 == COMPLEX_TYPE)
2130 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
2131 || code1 == COMPLEX_TYPE))
2133 else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
2135 register tree tt0 = TREE_TYPE (type0);
2136 register tree tt1 = TREE_TYPE (type1);
2137 /* Anything compares with void *. void * compares with anything.
2138 Otherwise, the targets must be compatible
2139 and both must be object or both incomplete. */
2140 if (comp_target_types (type0, type1))
2142 else if (TYPE_MAIN_VARIANT (tt0) == void_type_node)
2144 /* op0 != orig_op0 detects the case of something
2145 whose value is 0 but which isn't a valid null ptr const. */
2146 if (pedantic && (!integer_zerop (op0) || op0 != orig_op0)
2147 && TREE_CODE (tt1) == FUNCTION_TYPE)
2148 pedwarn ("ANSI C forbids comparison of `void *' with function pointer");
2150 else if (TYPE_MAIN_VARIANT (tt1) == void_type_node)
2152 if (pedantic && (!integer_zerop (op1) || op1 != orig_op1)
2153 && TREE_CODE (tt0) == FUNCTION_TYPE)
2154 pedwarn ("ANSI C forbids comparison of `void *' with function pointer");
2157 pedwarn ("comparison of distinct pointer types lacks a cast");
2159 else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST
2160 && integer_zerop (op1))
2161 op1 = null_pointer_node;
2162 else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST
2163 && integer_zerop (op0))
2164 op0 = null_pointer_node;
2165 else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
2167 if (! flag_traditional)
2168 pedwarn ("comparison between pointer and integer");
2169 op1 = convert (TREE_TYPE (op0), op1);
2171 else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
2173 if (! flag_traditional)
2174 pedwarn ("comparison between pointer and integer");
2175 op0 = convert (TREE_TYPE (op1), op0);
2178 /* If args are not valid, clear out RESULT_TYPE
2179 to cause an error message later. */
2185 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
2186 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
2188 else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
2190 if (! comp_target_types (type0, type1))
2191 pedwarn ("comparison of distinct pointer types lacks a cast");
2193 && TREE_CODE (TREE_TYPE (type0)) == FUNCTION_TYPE)
2194 pedwarn ("ANSI C forbids ordered comparisons of pointers to functions");
2195 result_type = common_type (type0, type1);
2203 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
2204 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
2206 else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
2208 if (! comp_target_types (type0, type1))
2209 pedwarn ("comparison of distinct pointer types lacks a cast");
2210 else if ((TYPE_SIZE (TREE_TYPE (type0)) != 0)
2211 != (TYPE_SIZE (TREE_TYPE (type1)) != 0))
2212 pedwarn ("comparison of complete and incomplete pointers");
2214 && TREE_CODE (TREE_TYPE (type0)) == FUNCTION_TYPE)
2215 pedwarn ("ANSI C forbids ordered comparisons of pointers to functions");
2216 result_type = integer_type_node;
2218 else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST
2219 && integer_zerop (op1))
2221 result_type = integer_type_node;
2222 op1 = null_pointer_node;
2224 pedwarn ("ordered comparison of pointer with integer zero");
2226 else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST
2227 && integer_zerop (op0))
2229 result_type = integer_type_node;
2230 op0 = null_pointer_node;
2232 pedwarn ("ordered comparison of pointer with integer zero");
2234 else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
2236 result_type = integer_type_node;
2237 if (! flag_traditional)
2238 pedwarn ("comparison between pointer and integer");
2239 op1 = convert (TREE_TYPE (op0), op1);
2241 else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
2243 result_type = integer_type_node;
2244 if (! flag_traditional)
2245 pedwarn ("comparison between pointer and integer");
2246 op0 = convert (TREE_TYPE (op1), op0);
2252 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == COMPLEX_TYPE)
2254 (code1 == INTEGER_TYPE || code1 == REAL_TYPE || code1 == COMPLEX_TYPE))
2256 int none_complex = (code0 != COMPLEX_TYPE && code1 != COMPLEX_TYPE);
2258 if (shorten || common || short_compare)
2259 result_type = common_type (type0, type1);
2261 /* For certain operations (which identify themselves by shorten != 0)
2262 if both args were extended from the same smaller type,
2263 do the arithmetic in that type and then extend.
2265 shorten !=0 and !=1 indicates a bitwise operation.
2266 For them, this optimization is safe only if
2267 both args are zero-extended or both are sign-extended.
2268 Otherwise, we might change the result.
2269 Eg, (short)-1 | (unsigned short)-1 is (int)-1
2270 but calculated in (unsigned short) it would be (unsigned short)-1. */
2272 if (shorten && none_complex)
2274 int unsigned0, unsigned1;
2275 tree arg0 = get_narrower (op0, &unsigned0);
2276 tree arg1 = get_narrower (op1, &unsigned1);
2277 /* UNS is 1 if the operation to be done is an unsigned one. */
2278 int uns = TREE_UNSIGNED (result_type);
2281 final_type = result_type;
2283 /* Handle the case that OP0 (or OP1) does not *contain* a conversion
2284 but it *requires* conversion to FINAL_TYPE. */
2286 if ((TYPE_PRECISION (TREE_TYPE (op0))
2287 == TYPE_PRECISION (TREE_TYPE (arg0)))
2288 && TREE_TYPE (op0) != final_type)
2289 unsigned0 = TREE_UNSIGNED (TREE_TYPE (op0));
2290 if ((TYPE_PRECISION (TREE_TYPE (op1))
2291 == TYPE_PRECISION (TREE_TYPE (arg1)))
2292 && TREE_TYPE (op1) != final_type)
2293 unsigned1 = TREE_UNSIGNED (TREE_TYPE (op1));
2295 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
2297 /* For bitwise operations, signedness of nominal type
2298 does not matter. Consider only how operands were extended. */
2302 /* Note that in all three cases below we refrain from optimizing
2303 an unsigned operation on sign-extended args.
2304 That would not be valid. */
2306 /* Both args variable: if both extended in same way
2307 from same width, do it in that width.
2308 Do it unsigned if args were zero-extended. */
2309 if ((TYPE_PRECISION (TREE_TYPE (arg0))
2310 < TYPE_PRECISION (result_type))
2311 && (TYPE_PRECISION (TREE_TYPE (arg1))
2312 == TYPE_PRECISION (TREE_TYPE (arg0)))
2313 && unsigned0 == unsigned1
2314 && (unsigned0 || !uns))
2316 = signed_or_unsigned_type (unsigned0,
2317 common_type (TREE_TYPE (arg0), TREE_TYPE (arg1)));
2318 else if (TREE_CODE (arg0) == INTEGER_CST
2319 && (unsigned1 || !uns)
2320 && (TYPE_PRECISION (TREE_TYPE (arg1))
2321 < TYPE_PRECISION (result_type))
2322 && (type = signed_or_unsigned_type (unsigned1,
2324 int_fits_type_p (arg0, type)))
2326 else if (TREE_CODE (arg1) == INTEGER_CST
2327 && (unsigned0 || !uns)
2328 && (TYPE_PRECISION (TREE_TYPE (arg0))
2329 < TYPE_PRECISION (result_type))
2330 && (type = signed_or_unsigned_type (unsigned0,
2332 int_fits_type_p (arg1, type)))
2336 /* Shifts can be shortened if shifting right. */
2341 tree arg0 = get_narrower (op0, &unsigned_arg);
2343 final_type = result_type;
2345 if (arg0 == op0 && final_type == TREE_TYPE (op0))
2346 unsigned_arg = TREE_UNSIGNED (TREE_TYPE (op0));
2348 if (TYPE_PRECISION (TREE_TYPE (arg0)) < TYPE_PRECISION (result_type)
2349 /* If arg is sign-extended and then unsigned-shifted,
2350 we can simulate this with a signed shift in arg's type
2351 only if the extended result is at least twice as wide
2352 as the arg. Otherwise, the shift could use up all the
2353 ones made by sign-extension and bring in zeros.
2354 We can't optimize that case at all, but in most machines
2355 it never happens because available widths are 2**N. */
2356 && (!TREE_UNSIGNED (final_type)
2358 || 2 * TYPE_PRECISION (TREE_TYPE (arg0)) <= TYPE_PRECISION (result_type)))
2360 /* Do an unsigned shift if the operand was zero-extended. */
2362 = signed_or_unsigned_type (unsigned_arg,
2364 /* Convert value-to-be-shifted to that type. */
2365 if (TREE_TYPE (op0) != result_type)
2366 op0 = convert (result_type, op0);
2371 /* Comparison operations are shortened too but differently.
2372 They identify themselves by setting short_compare = 1. */
2376 /* Don't write &op0, etc., because that would prevent op0
2377 from being kept in a register.
2378 Instead, make copies of the our local variables and
2379 pass the copies by reference, then copy them back afterward. */
2380 tree xop0 = op0, xop1 = op1, xresult_type = result_type;
2381 enum tree_code xresultcode = resultcode;
2383 = shorten_compare (&xop0, &xop1, &xresult_type, &xresultcode);
2386 op0 = xop0, op1 = xop1, result_type = xresult_type;
2387 resultcode = xresultcode;
2391 tree op0_type = TREE_TYPE (orig_op0);
2392 tree op1_type = TREE_TYPE (orig_op1);
2393 int op0_unsigned = TREE_UNSIGNED (op0_type);
2394 int op1_unsigned = TREE_UNSIGNED (op1_type);
2396 /* Give warnings for comparisons between signed and unsigned
2397 quantities that will fail. Do not warn if the signed quantity
2398 is an unsuffixed integer literal (or some static constant
2399 expression involving such literals) and it is positive.
2400 Do not warn if the width of the unsigned quantity is less
2401 than that of the signed quantity, since in this case all
2402 values of the unsigned quantity fit in the signed quantity.
2403 Do not warn if the signed type is the same size as the
2404 result_type since sign extension does not cause trouble in
2406 /* Do the checking based on the original operand trees, so that
2407 casts will be considered, but default promotions won't be. */
2408 if (op0_unsigned != op1_unsigned
2410 && TYPE_PRECISION (op0_type) >= TYPE_PRECISION (op1_type)
2411 && TYPE_PRECISION (op0_type) < TYPE_PRECISION (result_type)
2412 && (TREE_CODE (op1) != INTEGER_CST
2413 || (TREE_CODE (op1) == INTEGER_CST
2414 && INT_CST_LT (op1, integer_zero_node))))
2417 && TYPE_PRECISION (op1_type) >= TYPE_PRECISION (op0_type)
2418 && TYPE_PRECISION (op1_type) < TYPE_PRECISION (result_type)
2419 && (TREE_CODE (op0) != INTEGER_CST
2420 || (TREE_CODE (op0) == INTEGER_CST
2421 && INT_CST_LT (op0, integer_zero_node))))))
2422 warning ("comparison between signed and unsigned");
2427 /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
2428 If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
2429 Then the expression will be built.
2430 It will be given type FINAL_TYPE if that is nonzero;
2431 otherwise, it will be given type RESULT_TYPE. */
2435 binary_op_error (code);
2436 return error_mark_node;
2441 if (TREE_TYPE (op0) != result_type)
2442 op0 = convert (result_type, op0);
2443 if (TREE_TYPE (op1) != result_type)
2444 op1 = convert (result_type, op1);
2448 register tree result = build (resultcode, result_type, op0, op1);
2449 register tree folded;
2451 folded = fold (result);
2452 if (folded == result)
2453 TREE_CONSTANT (folded) = TREE_CONSTANT (op0) & TREE_CONSTANT (op1);
2454 if (final_type != 0)
2455 return convert (final_type, folded);
2460 /* Return a tree for the sum or difference (RESULTCODE says which)
2461 of pointer PTROP and integer INTOP. */
2464 pointer_int_sum (resultcode, ptrop, intop)
2465 enum tree_code resultcode;
2466 register tree ptrop, intop;
2470 register tree result;
2471 register tree folded;
2473 /* The result is a pointer of the same type that is being added. */
2475 register tree result_type = TREE_TYPE (ptrop);
2477 if (TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE)
2479 if (pedantic || warn_pointer_arith)
2480 pedwarn ("pointer of type `void *' used in arithmetic");
2481 size_exp = integer_one_node;
2483 else if (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE)
2485 if (pedantic || warn_pointer_arith)
2486 pedwarn ("pointer to a function used in arithmetic");
2487 size_exp = integer_one_node;
2490 size_exp = c_size_in_bytes (TREE_TYPE (result_type));
2492 /* If what we are about to multiply by the size of the elements
2493 contains a constant term, apply distributive law
2494 and multiply that constant term separately.
2495 This helps produce common subexpressions. */
2497 if ((TREE_CODE (intop) == PLUS_EXPR || TREE_CODE (intop) == MINUS_EXPR)
2498 && ! TREE_CONSTANT (intop)
2499 && TREE_CONSTANT (TREE_OPERAND (intop, 1))
2500 && TREE_CONSTANT (size_exp)
2501 /* If the constant comes from pointer subtraction,
2502 skip this optimization--it would cause an error. */
2503 && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop, 0))) == INTEGER_TYPE)
2505 enum tree_code subcode = resultcode;
2506 tree int_type = TREE_TYPE (intop);
2507 if (TREE_CODE (intop) == MINUS_EXPR)
2508 subcode = (subcode == PLUS_EXPR ? MINUS_EXPR : PLUS_EXPR);
2509 /* Convert both subexpression types to the type of intop,
2510 because weird cases involving pointer arithmetic
2511 can result in a sum or difference with different type args. */
2512 ptrop = build_binary_op (subcode, ptrop,
2513 convert (int_type, TREE_OPERAND (intop, 1)), 1);
2514 intop = convert (int_type, TREE_OPERAND (intop, 0));
2517 /* Convert the integer argument to a type the same size as a pointer
2518 so the multiply won't overflow spuriously. */
2520 if (TYPE_PRECISION (TREE_TYPE (intop)) != POINTER_SIZE)
2521 intop = convert (type_for_size (POINTER_SIZE, 0), intop);
2523 /* Replace the integer argument with a suitable product by the object size.
2524 Do this multiplication as signed, then convert to the appropriate
2525 pointer type (actually unsigned integral). */
2527 intop = convert (result_type,
2528 build_binary_op (MULT_EXPR, intop,
2529 convert (TREE_TYPE (intop), size_exp), 1));
2531 /* Create the sum or difference. */
2533 result = build (resultcode, result_type, ptrop, intop);
2535 folded = fold (result);
2536 if (folded == result)
2537 TREE_CONSTANT (folded) = TREE_CONSTANT (ptrop) & TREE_CONSTANT (intop);
2541 /* Return a tree for the difference of pointers OP0 and OP1.
2542 The resulting tree has type int. */
2545 pointer_diff (op0, op1)
2546 register tree op0, op1;
2548 register tree result, folded;
2549 tree restype = ptrdiff_type_node;
2551 tree target_type = TREE_TYPE (TREE_TYPE (op0));
2553 if (pedantic || warn_pointer_arith)
2555 if (TREE_CODE (target_type) == VOID_TYPE)
2556 pedwarn ("pointer of type `void *' used in subtraction");
2557 if (TREE_CODE (target_type) == FUNCTION_TYPE)
2558 pedwarn ("pointer to a function used in subtraction");
2561 /* First do the subtraction as integers;
2562 then drop through to build the divide operator. */
2564 op0 = build_binary_op (MINUS_EXPR, convert (restype, op0),
2565 convert (restype, op1), 1);
2566 /* This generates an error if op1 is pointer to incomplete type. */
2567 if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (op1))) == 0)
2568 error ("arithmetic on pointer to an incomplete type");
2570 /* This generates an error if op0 is pointer to incomplete type. */
2571 op1 = c_size_in_bytes (target_type);
2573 /* Divide by the size, in easiest possible way. */
2575 result = build (EXACT_DIV_EXPR, restype, op0, convert (restype, op1));
2577 folded = fold (result);
2578 if (folded == result)
2579 TREE_CONSTANT (folded) = TREE_CONSTANT (op0) & TREE_CONSTANT (op1);
2583 /* Construct and perhaps optimize a tree representation
2584 for a unary operation. CODE, a tree_code, specifies the operation
2585 and XARG is the operand. NOCONVERT nonzero suppresses
2586 the default promotions (such as from short to int). */
2589 build_unary_op (code, xarg, noconvert)
2590 enum tree_code code;
2594 /* No default_conversion here. It causes trouble for ADDR_EXPR. */
2595 register tree arg = xarg;
2596 register tree argtype = 0;
2597 register enum tree_code typecode = TREE_CODE (TREE_TYPE (arg));
2598 char *errstring = NULL;
2601 if (typecode == ERROR_MARK)
2602 return error_mark_node;
2603 if (typecode == ENUMERAL_TYPE)
2604 typecode = INTEGER_TYPE;
2609 /* This is used for unary plus, because a CONVERT_EXPR
2610 is enough to prevent anybody from looking inside for
2611 associativity, but won't generate any code. */
2612 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
2613 || typecode == COMPLEX_TYPE))
2614 errstring = "wrong type argument to unary plus";
2615 else if (!noconvert)
2616 arg = default_conversion (arg);
2620 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
2621 || typecode == COMPLEX_TYPE))
2622 errstring = "wrong type argument to unary minus";
2623 else if (!noconvert)
2624 arg = default_conversion (arg);
2628 if (typecode == COMPLEX_TYPE)
2632 arg = default_conversion (arg);
2634 else if (typecode != INTEGER_TYPE)
2635 errstring = "wrong type argument to bit-complement";
2636 else if (!noconvert)
2637 arg = default_conversion (arg);
2641 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
2642 || typecode == COMPLEX_TYPE))
2643 errstring = "wrong type argument to abs";
2644 else if (!noconvert)
2645 arg = default_conversion (arg);
2649 /* Conjugating a real value is a no-op, but allow it anyway. */
2650 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
2651 || typecode == COMPLEX_TYPE))
2652 errstring = "wrong type argument to conjugation";
2653 else if (!noconvert)
2654 arg = default_conversion (arg);
2657 case TRUTH_NOT_EXPR:
2658 if (typecode != INTEGER_TYPE
2659 && typecode != REAL_TYPE && typecode != POINTER_TYPE
2660 && typecode != COMPLEX_TYPE
2661 /* These will convert to a pointer. */
2662 && typecode != ARRAY_TYPE && typecode != FUNCTION_TYPE)
2664 errstring = "wrong type argument to unary exclamation mark";
2667 arg = truthvalue_conversion (arg);
2668 return invert_truthvalue (arg);
2674 if (TREE_CODE (arg) == COMPLEX_CST)
2675 return TREE_REALPART (arg);
2676 else if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE)
2677 return fold (build1 (REALPART_EXPR, TREE_TYPE (TREE_TYPE (arg)), arg));
2682 if (TREE_CODE (arg) == COMPLEX_CST)
2683 return TREE_IMAGPART (arg);
2684 else if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE)
2685 return fold (build1 (IMAGPART_EXPR, TREE_TYPE (TREE_TYPE (arg)), arg));
2687 return convert (TREE_TYPE (arg), integer_zero_node);
2689 case PREINCREMENT_EXPR:
2690 case POSTINCREMENT_EXPR:
2691 case PREDECREMENT_EXPR:
2692 case POSTDECREMENT_EXPR:
2693 /* Handle complex lvalues (when permitted)
2694 by reduction to simpler cases. */
2696 val = unary_complex_lvalue (code, arg);
2700 /* Increment or decrement the real part of the value,
2701 and don't change the imaginary part. */
2702 if (typecode == COMPLEX_TYPE)
2706 arg = stabilize_reference (arg);
2707 real = build_unary_op (REALPART_EXPR, arg, 1);
2708 imag = build_unary_op (IMAGPART_EXPR, arg, 1);
2709 return build (COMPLEX_EXPR, TREE_TYPE (arg),
2710 build_unary_op (code, real, 1), imag);
2713 /* Report invalid types. */
2715 if (typecode != POINTER_TYPE
2716 && typecode != INTEGER_TYPE && typecode != REAL_TYPE)
2718 if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
2719 errstring ="wrong type argument to increment";
2721 errstring ="wrong type argument to decrement";
2727 tree result_type = TREE_TYPE (arg);
2729 arg = get_unwidened (arg, 0);
2730 argtype = TREE_TYPE (arg);
2732 /* Compute the increment. */
2734 if (typecode == POINTER_TYPE)
2736 /* If pointer target is an undefined struct,
2737 we just cannot know how to do the arithmetic. */
2738 if (TYPE_SIZE (TREE_TYPE (result_type)) == 0)
2739 error ("%s of pointer to unknown structure",
2740 ((code == PREINCREMENT_EXPR
2741 || code == POSTINCREMENT_EXPR)
2742 ? "increment" : "decrement"));
2743 else if ((pedantic || warn_pointer_arith)
2744 && (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE
2745 || TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE))
2746 pedwarn ("wrong type argument to %s",
2747 ((code == PREINCREMENT_EXPR
2748 || code == POSTINCREMENT_EXPR)
2749 ? "increment" : "decrement"));
2750 inc = c_sizeof_nowarn (TREE_TYPE (result_type));
2753 inc = integer_one_node;
2755 inc = convert (argtype, inc);
2757 /* Handle incrementing a cast-expression. */
2760 switch (TREE_CODE (arg))
2765 case FIX_TRUNC_EXPR:
2766 case FIX_FLOOR_EXPR:
2767 case FIX_ROUND_EXPR:
2769 pedantic_lvalue_warning (CONVERT_EXPR);
2770 /* If the real type has the same machine representation
2771 as the type it is cast to, we can make better output
2772 by adding directly to the inside of the cast. */
2773 if ((TREE_CODE (TREE_TYPE (arg))
2774 == TREE_CODE (TREE_TYPE (TREE_OPERAND (arg, 0))))
2775 && (TYPE_MODE (TREE_TYPE (arg))
2776 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (arg, 0)))))
2777 arg = TREE_OPERAND (arg, 0);
2780 tree incremented, modify, value;
2781 arg = stabilize_reference (arg);
2782 if (code == PREINCREMENT_EXPR || code == PREDECREMENT_EXPR)
2785 value = save_expr (arg);
2786 incremented = build (((code == PREINCREMENT_EXPR
2787 || code == POSTINCREMENT_EXPR)
2788 ? PLUS_EXPR : MINUS_EXPR),
2789 argtype, value, inc);
2790 TREE_SIDE_EFFECTS (incremented) = 1;
2791 modify = build_modify_expr (arg, NOP_EXPR, incremented);
2792 value = build (COMPOUND_EXPR, TREE_TYPE (arg), modify, value);
2793 TREE_USED (value) = 1;
2803 /* Complain about anything else that is not a true lvalue. */
2804 if (!lvalue_or_else (arg, ((code == PREINCREMENT_EXPR
2805 || code == POSTINCREMENT_EXPR)
2806 ? "increment" : "decrement")))
2807 return error_mark_node;
2809 /* Report a read-only lvalue. */
2810 if (TREE_READONLY (arg))
2811 readonly_warning (arg,
2812 ((code == PREINCREMENT_EXPR
2813 || code == POSTINCREMENT_EXPR)
2814 ? "increment" : "decrement"));
2816 val = build (code, TREE_TYPE (arg), arg, inc);
2817 TREE_SIDE_EFFECTS (val) = 1;
2818 val = convert (result_type, val);
2819 if (TREE_CODE (val) != code)
2820 TREE_NO_UNUSED_WARNING (val) = 1;
2825 /* Note that this operation never does default_conversion
2826 regardless of NOCONVERT. */
2828 /* Let &* cancel out to simplify resulting code. */
2829 if (TREE_CODE (arg) == INDIRECT_REF)
2831 /* Don't let this be an lvalue. */
2832 if (lvalue_p (TREE_OPERAND (arg, 0)))
2833 return non_lvalue (TREE_OPERAND (arg, 0));
2834 return TREE_OPERAND (arg, 0);
2837 /* For &x[y], return x+y */
2838 if (TREE_CODE (arg) == ARRAY_REF)
2840 if (mark_addressable (TREE_OPERAND (arg, 0)) == 0)
2841 return error_mark_node;
2842 return build_binary_op (PLUS_EXPR, TREE_OPERAND (arg, 0),
2843 TREE_OPERAND (arg, 1), 1);
2846 /* Handle complex lvalues (when permitted)
2847 by reduction to simpler cases. */
2848 val = unary_complex_lvalue (code, arg);
2852 #if 0 /* Turned off because inconsistent;
2853 float f; *&(int)f = 3.4 stores in int format
2854 whereas (int)f = 3.4 stores in float format. */
2855 /* Address of a cast is just a cast of the address
2856 of the operand of the cast. */
2857 switch (TREE_CODE (arg))
2862 case FIX_TRUNC_EXPR:
2863 case FIX_FLOOR_EXPR:
2864 case FIX_ROUND_EXPR:
2867 pedwarn ("ANSI C forbids the address of a cast expression");
2868 return convert (build_pointer_type (TREE_TYPE (arg)),
2869 build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0),
2874 /* Allow the address of a constructor if all the elements
2876 if (TREE_CODE (arg) == CONSTRUCTOR && TREE_CONSTANT (arg))
2878 /* Anything not already handled and not a true memory reference
2880 else if (typecode != FUNCTION_TYPE && !lvalue_or_else (arg, "unary `&'"))
2881 return error_mark_node;
2883 /* Ordinary case; arg is a COMPONENT_REF or a decl. */
2884 argtype = TREE_TYPE (arg);
2885 /* If the lvalue is const or volatile,
2886 merge that into the type that the address will point to. */
2887 if (TREE_CODE_CLASS (TREE_CODE (arg)) == 'd'
2888 || TREE_CODE_CLASS (TREE_CODE (arg)) == 'r')
2890 if (TREE_READONLY (arg) || TREE_THIS_VOLATILE (arg))
2891 argtype = c_build_type_variant (argtype,
2892 TREE_READONLY (arg),
2893 TREE_THIS_VOLATILE (arg));
2896 argtype = build_pointer_type (argtype);
2898 if (mark_addressable (arg) == 0)
2899 return error_mark_node;
2904 if (TREE_CODE (arg) == COMPONENT_REF)
2906 tree field = TREE_OPERAND (arg, 1);
2908 addr = build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0), 0);
2910 if (DECL_BIT_FIELD (field))
2912 error ("attempt to take address of bit-field structure member `%s'",
2913 IDENTIFIER_POINTER (DECL_NAME (field)));
2914 return error_mark_node;
2917 addr = convert (argtype, addr);
2919 if (! integer_zerop (DECL_FIELD_BITPOS (field)))
2922 = size_binop (EASY_DIV_EXPR, DECL_FIELD_BITPOS (field),
2923 size_int (BITS_PER_UNIT));
2924 int flag = TREE_CONSTANT (addr);
2925 addr = fold (build (PLUS_EXPR, argtype,
2926 addr, convert (argtype, offset)));
2927 TREE_CONSTANT (addr) = flag;
2931 addr = build1 (code, argtype, arg);
2933 /* Address of a static or external variable or
2934 file-scope function counts as a constant. */
2936 && ! (TREE_CODE (arg) == FUNCTION_DECL
2937 && DECL_CONTEXT (arg) != 0))
2938 TREE_CONSTANT (addr) = 1;
2946 argtype = TREE_TYPE (arg);
2947 return fold (build1 (code, argtype, arg));
2951 return error_mark_node;
2955 /* If CONVERSIONS is a conversion expression or a nested sequence of such,
2956 convert ARG with the same conversions in the same order
2957 and return the result. */
2960 convert_sequence (conversions, arg)
2964 switch (TREE_CODE (conversions))
2969 case FIX_TRUNC_EXPR:
2970 case FIX_FLOOR_EXPR:
2971 case FIX_ROUND_EXPR:
2973 return convert (TREE_TYPE (conversions),
2974 convert_sequence (TREE_OPERAND (conversions, 0),
2983 /* Return nonzero if REF is an lvalue valid for this language.
2984 Lvalues can be assigned, unless their type has TYPE_READONLY.
2985 Lvalues can have their address taken, unless they have DECL_REGISTER. */
2991 register enum tree_code code = TREE_CODE (ref);
2998 return lvalue_p (TREE_OPERAND (ref, 0));
3009 if (TREE_CODE (TREE_TYPE (ref)) != FUNCTION_TYPE
3010 && TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE)
3017 /* Return nonzero if REF is an lvalue valid for this language;
3018 otherwise, print an error message and return zero. */
3021 lvalue_or_else (ref, string)
3025 int win = lvalue_p (ref);
3027 error ("invalid lvalue in %s", string);
3031 /* Apply unary lvalue-demanding operator CODE to the expression ARG
3032 for certain kinds of expressions which are not really lvalues
3033 but which we can accept as lvalues.
3035 If ARG is not a kind of expression we can handle, return zero. */
3038 unary_complex_lvalue (code, arg)
3039 enum tree_code code;
3042 /* Handle (a, b) used as an "lvalue". */
3043 if (TREE_CODE (arg) == COMPOUND_EXPR)
3045 tree real_result = build_unary_op (code, TREE_OPERAND (arg, 1), 0);
3046 pedantic_lvalue_warning (COMPOUND_EXPR);
3047 return build (COMPOUND_EXPR, TREE_TYPE (real_result),
3048 TREE_OPERAND (arg, 0), real_result);
3051 /* Handle (a ? b : c) used as an "lvalue". */
3052 if (TREE_CODE (arg) == COND_EXPR)
3054 pedantic_lvalue_warning (COND_EXPR);
3055 return (build_conditional_expr
3056 (TREE_OPERAND (arg, 0),
3057 build_unary_op (code, TREE_OPERAND (arg, 1), 0),
3058 build_unary_op (code, TREE_OPERAND (arg, 2), 0)));
3064 /* If pedantic, warn about improper lvalue. CODE is either COND_EXPR
3065 COMPOUND_EXPR, or CONVERT_EXPR (for casts). */
3068 pedantic_lvalue_warning (code)
3069 enum tree_code code;
3072 pedwarn ("ANSI C forbids use of %s expressions as lvalues",
3073 code == COND_EXPR ? "conditional"
3074 : code == COMPOUND_EXPR ? "compound" : "cast");
3077 /* Warn about storing in something that is `const'. */
3080 readonly_warning (arg, string)
3085 strcpy (buf, string);
3087 /* Forbid assignments to iterators. */
3088 if (TREE_CODE (arg) == VAR_DECL && ITERATOR_P (arg))
3090 strcat (buf, " of iterator `%s'");
3091 pedwarn (buf, IDENTIFIER_POINTER (DECL_NAME (arg)));
3094 if (TREE_CODE (arg) == COMPONENT_REF)
3096 if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg, 0))))
3097 readonly_warning (TREE_OPERAND (arg, 0), string);
3100 strcat (buf, " of read-only member `%s'");
3101 pedwarn (buf, IDENTIFIER_POINTER (DECL_NAME (TREE_OPERAND (arg, 1))));
3104 else if (TREE_CODE (arg) == VAR_DECL)
3106 strcat (buf, " of read-only variable `%s'");
3107 pedwarn (buf, IDENTIFIER_POINTER (DECL_NAME (arg)));
3111 pedwarn ("%s of read-only location", buf);
3115 /* Mark EXP saying that we need to be able to take the
3116 address of it; it should not be allocated in a register.
3117 Value is 1 if successful. */
3120 mark_addressable (exp)
3123 register tree x = exp;
3125 switch (TREE_CODE (x))
3132 x = TREE_OPERAND (x, 0);
3136 TREE_ADDRESSABLE (x) = 1;
3143 if (DECL_REGISTER (x) && !TREE_ADDRESSABLE (x)
3144 && DECL_NONLOCAL (x))
3146 if (TREE_PUBLIC (x))
3148 error ("global register variable `%s' used in nested function",
3149 IDENTIFIER_POINTER (DECL_NAME (x)));
3152 pedwarn ("register variable `%s' used in nested function",
3153 IDENTIFIER_POINTER (DECL_NAME (x)));
3155 else if (DECL_REGISTER (x) && !TREE_ADDRESSABLE (x))
3157 if (TREE_PUBLIC (x))
3159 error ("address of global register variable `%s' requested",
3160 IDENTIFIER_POINTER (DECL_NAME (x)));
3163 pedwarn ("address of register variable `%s' requested",
3164 IDENTIFIER_POINTER (DECL_NAME (x)));
3166 put_var_into_stack (x);
3170 TREE_ADDRESSABLE (x) = 1;
3171 #if 0 /* poplevel deals with this now. */
3172 if (DECL_CONTEXT (x) == 0)
3173 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (x)) = 1;
3181 /* Build and return a conditional expression IFEXP ? OP1 : OP2. */
3184 build_conditional_expr (ifexp, op1, op2)
3185 tree ifexp, op1, op2;
3187 register tree type1;
3188 register tree type2;
3189 register enum tree_code code1;
3190 register enum tree_code code2;
3191 register tree result_type = NULL;
3192 tree orig_op1 = op1, orig_op2 = op2;
3194 /* If second operand is omitted, it is the same as the first one;
3195 make sure it is calculated only once. */
3199 pedwarn ("ANSI C forbids omitting the middle term of a ?: expression");
3200 ifexp = op1 = save_expr (ifexp);
3203 ifexp = truthvalue_conversion (default_conversion (ifexp));
3205 #if 0 /* Produces wrong result if within sizeof. */
3206 /* Don't promote the operands separately if they promote
3207 the same way. Return the unpromoted type and let the combined
3208 value get promoted if necessary. */
3210 if (TREE_TYPE (op1) == TREE_TYPE (op2)
3211 && TREE_CODE (TREE_TYPE (op1)) != ARRAY_TYPE
3212 && TREE_CODE (TREE_TYPE (op1)) != ENUMERAL_TYPE
3213 && TREE_CODE (TREE_TYPE (op1)) != FUNCTION_TYPE)
3215 if (TREE_CODE (ifexp) == INTEGER_CST)
3216 return pedantic_non_lvalue (integer_zerop (ifexp) ? op2 : op1);
3218 return fold (build (COND_EXPR, TREE_TYPE (op1), ifexp, op1, op2));
3222 /* Promote both alternatives. */
3224 if (TREE_CODE (TREE_TYPE (op1)) != VOID_TYPE)
3225 op1 = default_conversion (op1);
3226 if (TREE_CODE (TREE_TYPE (op2)) != VOID_TYPE)
3227 op2 = default_conversion (op2);
3229 if (TREE_CODE (ifexp) == ERROR_MARK
3230 || TREE_CODE (TREE_TYPE (op1)) == ERROR_MARK
3231 || TREE_CODE (TREE_TYPE (op2)) == ERROR_MARK)
3232 return error_mark_node;
3234 type1 = TREE_TYPE (op1);
3235 code1 = TREE_CODE (type1);
3236 type2 = TREE_TYPE (op2);
3237 code2 = TREE_CODE (type2);
3239 /* Quickly detect the usual case where op1 and op2 have the same type
3241 if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2))
3244 result_type = type1;
3246 result_type = TYPE_MAIN_VARIANT (type1);
3248 else if ((code1 == INTEGER_TYPE || code1 == REAL_TYPE)
3249 && (code2 == INTEGER_TYPE || code2 == REAL_TYPE))
3251 result_type = common_type (type1, type2);
3253 else if (code1 == VOID_TYPE || code2 == VOID_TYPE)
3255 if (pedantic && (code1 != VOID_TYPE || code2 != VOID_TYPE))
3256 pedwarn ("ANSI C forbids conditional expr with only one void side");
3257 result_type = void_type_node;
3259 else if (code1 == POINTER_TYPE && code2 == POINTER_TYPE)
3261 if (comp_target_types (type1, type2))
3262 result_type = common_type (type1, type2);
3263 else if (integer_zerop (op1) && TREE_TYPE (type1) == void_type_node
3264 && TREE_CODE (orig_op1) != NOP_EXPR)
3265 result_type = qualify_type (type2, type1);
3266 else if (integer_zerop (op2) && TREE_TYPE (type2) == void_type_node
3267 && TREE_CODE (orig_op2) != NOP_EXPR)
3268 result_type = qualify_type (type1, type2);
3269 else if (TYPE_MAIN_VARIANT (TREE_TYPE (type1)) == void_type_node)
3271 if (pedantic && TREE_CODE (TREE_TYPE (type2)) == FUNCTION_TYPE)
3272 pedwarn ("ANSI C forbids conditional expr between `void *' and function pointer");
3273 result_type = qualify_type (type1, type2);
3275 else if (TYPE_MAIN_VARIANT (TREE_TYPE (type2)) == void_type_node)
3277 if (pedantic && TREE_CODE (TREE_TYPE (type1)) == FUNCTION_TYPE)
3278 pedwarn ("ANSI C forbids conditional expr between `void *' and function pointer");
3279 result_type = qualify_type (type2, type1);
3283 pedwarn ("pointer type mismatch in conditional expression");
3284 result_type = build_pointer_type (void_type_node);
3287 else if (code1 == POINTER_TYPE && code2 == INTEGER_TYPE)
3289 if (! integer_zerop (op2))
3290 pedwarn ("pointer/integer type mismatch in conditional expression");
3293 op2 = null_pointer_node;
3294 #if 0 /* The spec seems to say this is permitted. */
3295 if (pedantic && TREE_CODE (type1) == FUNCTION_TYPE)
3296 pedwarn ("ANSI C forbids conditional expr between 0 and function pointer");
3299 result_type = type1;
3301 else if (code2 == POINTER_TYPE && code1 == INTEGER_TYPE)
3303 if (!integer_zerop (op1))
3304 pedwarn ("pointer/integer type mismatch in conditional expression");
3307 op1 = null_pointer_node;
3308 #if 0 /* The spec seems to say this is permitted. */
3309 if (pedantic && TREE_CODE (type2) == FUNCTION_TYPE)
3310 pedwarn ("ANSI C forbids conditional expr between 0 and function pointer");
3313 result_type = type2;
3318 if (flag_cond_mismatch)
3319 result_type = void_type_node;
3322 error ("type mismatch in conditional expression");
3323 return error_mark_node;
3327 /* Merge const and volatile flags of the incoming types. */
3329 = build_type_variant (result_type,
3330 TREE_READONLY (op1) || TREE_READONLY (op2),
3331 TREE_THIS_VOLATILE (op1) || TREE_THIS_VOLATILE (op2));
3333 if (result_type != TREE_TYPE (op1))
3334 op1 = convert_and_check (result_type, op1);
3335 if (result_type != TREE_TYPE (op2))
3336 op2 = convert_and_check (result_type, op2);
3339 if (code1 == RECORD_TYPE || code1 == UNION_TYPE)
3341 result_type = TREE_TYPE (op1);
3342 if (TREE_CONSTANT (ifexp))
3343 return pedantic_non_lvalue (integer_zerop (ifexp) ? op2 : op1);
3345 if (TYPE_MODE (result_type) == BLKmode)
3347 register tree tempvar
3348 = build_decl (VAR_DECL, NULL_TREE, result_type);
3349 register tree xop1 = build_modify_expr (tempvar, op1);
3350 register tree xop2 = build_modify_expr (tempvar, op2);
3351 register tree result = fold (build (COND_EXPR, result_type,
3352 ifexp, xop1, xop2));
3354 layout_decl (tempvar, TYPE_ALIGN (result_type));
3355 /* No way to handle variable-sized objects here.
3356 I fear that the entire handling of BLKmode conditional exprs
3357 needs to be redone. */
3358 if (TREE_CODE (DECL_SIZE (tempvar)) != INTEGER_CST)
3361 = assign_stack_local (DECL_MODE (tempvar),
3362 (TREE_INT_CST_LOW (DECL_SIZE (tempvar))
3363 + BITS_PER_UNIT - 1)
3367 TREE_SIDE_EFFECTS (result)
3368 = TREE_SIDE_EFFECTS (ifexp) | TREE_SIDE_EFFECTS (op1)
3369 | TREE_SIDE_EFFECTS (op2);
3370 return build (COMPOUND_EXPR, result_type, result, tempvar);
3375 if (TREE_CODE (ifexp) == INTEGER_CST)
3376 return pedantic_non_lvalue (integer_zerop (ifexp) ? op2 : op1);
3378 return fold (build (COND_EXPR, result_type, ifexp, op1, op2));
3381 /* Given a list of expressions, return a compound expression
3382 that performs them all and returns the value of the last of them. */
3385 build_compound_expr (list)
3388 return internal_build_compound_expr (list, TRUE);
3392 internal_build_compound_expr (list, first_p)
3398 if (TREE_CHAIN (list) == 0)
3400 #if 0 /* If something inside inhibited lvalueness, we should not override. */
3401 /* Consider (x, y+0), which is not an lvalue since y+0 is not. */
3403 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
3404 if (TREE_CODE (list) == NON_LVALUE_EXPR)
3405 list = TREE_OPERAND (list, 0);
3408 /* Don't let (0, 0) be null pointer constant. */
3409 if (!first_p && integer_zerop (TREE_VALUE (list)))
3410 return non_lvalue (TREE_VALUE (list));
3411 return TREE_VALUE (list);
3414 if (TREE_CHAIN (list) != 0 && TREE_CHAIN (TREE_CHAIN (list)) == 0)
3416 /* Convert arrays to pointers when there really is a comma operator. */
3417 if (TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (list)))) == ARRAY_TYPE)
3418 TREE_VALUE (TREE_CHAIN (list))
3419 = default_conversion (TREE_VALUE (TREE_CHAIN (list)));
3422 rest = internal_build_compound_expr (TREE_CHAIN (list), FALSE);
3424 /* When pedantic, a compound expression can be neither an lvalue
3425 nor an integer constant expression. */
3426 if (! TREE_SIDE_EFFECTS (TREE_VALUE (list)) && ! pedantic)
3429 return build (COMPOUND_EXPR, TREE_TYPE (rest), TREE_VALUE (list), rest);
3432 /* Build an expression representing a cast to type TYPE of expression EXPR. */
3435 build_c_cast (type, expr)
3439 register tree value = expr;
3441 if (type == error_mark_node || expr == error_mark_node)
3442 return error_mark_node;
3443 type = TYPE_MAIN_VARIANT (type);
3446 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
3447 if (TREE_CODE (value) == NON_LVALUE_EXPR)
3448 value = TREE_OPERAND (value, 0);
3451 if (TREE_CODE (type) == ARRAY_TYPE)
3453 error ("cast specifies array type");
3454 return error_mark_node;
3457 if (TREE_CODE (type) == FUNCTION_TYPE)
3459 error ("cast specifies function type");
3460 return error_mark_node;
3463 if (type == TREE_TYPE (value))
3467 if (TREE_CODE (type) == RECORD_TYPE
3468 || TREE_CODE (type) == UNION_TYPE)
3469 pedwarn ("ANSI C forbids casting nonscalar to the same type");
3472 else if (TREE_CODE (type) == UNION_TYPE)
3475 if (TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE
3476 || TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE)
3477 value = default_conversion (value);
3479 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
3480 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (field)),
3481 TYPE_MAIN_VARIANT (TREE_TYPE (value))))
3490 pedwarn ("ANSI C forbids casts to union type");
3491 if (TYPE_NAME (type) != 0)
3493 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
3494 name = IDENTIFIER_POINTER (TYPE_NAME (type));
3496 name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
3500 t = digest_init (type, build (CONSTRUCTOR, type, NULL_TREE,
3501 build_tree_list (field, value)),
3503 TREE_CONSTANT (t) = TREE_CONSTANT (value);
3506 error ("cast to union type from type not present in union");
3507 return error_mark_node;
3513 /* If casting to void, avoid the error that would come
3514 from default_conversion in the case of a non-lvalue array. */
3515 if (type == void_type_node)
3516 return build1 (CONVERT_EXPR, type, value);
3518 /* Convert functions and arrays to pointers,
3519 but don't convert any other types. */
3520 if (TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE
3521 || TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE)
3522 value = default_conversion (value);
3523 otype = TREE_TYPE (value);
3525 /* Optionally warn about potentially worrisome casts. */
3528 && TREE_CODE (type) == POINTER_TYPE
3529 && TREE_CODE (otype) == POINTER_TYPE)
3531 if (TYPE_VOLATILE (TREE_TYPE (otype))
3532 && ! TYPE_VOLATILE (TREE_TYPE (type)))
3533 pedwarn ("cast discards `volatile' from pointer target type");
3534 if (TYPE_READONLY (TREE_TYPE (otype))
3535 && ! TYPE_READONLY (TREE_TYPE (type)))
3536 pedwarn ("cast discards `const' from pointer target type");
3539 /* Warn about possible alignment problems. */
3540 if (STRICT_ALIGNMENT && warn_cast_align
3541 && TREE_CODE (type) == POINTER_TYPE
3542 && TREE_CODE (otype) == POINTER_TYPE
3543 && TREE_CODE (TREE_TYPE (otype)) != VOID_TYPE
3544 && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
3545 && TYPE_ALIGN (TREE_TYPE (type)) > TYPE_ALIGN (TREE_TYPE (otype)))
3546 warning ("cast increases required alignment of target type");
3548 if (TREE_CODE (type) == INTEGER_TYPE
3549 && TREE_CODE (otype) == POINTER_TYPE
3550 && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
3551 && !TREE_CONSTANT (value))
3552 warning ("cast from pointer to integer of different size");
3554 if (TREE_CODE (type) == POINTER_TYPE
3555 && TREE_CODE (otype) == INTEGER_TYPE
3556 && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
3558 /* Don't warn about converting 0 to pointer,
3559 provided the 0 was explicit--not cast or made by folding. */
3560 && !(TREE_CODE (value) == INTEGER_CST && integer_zerop (value))
3562 /* Don't warn about converting any constant. */
3563 && !TREE_CONSTANT (value))
3564 warning ("cast to pointer from integer of different size");
3567 value = convert (type, value);
3569 /* Ignore any integer overflow caused by the cast. */
3570 if (TREE_CODE (value) == INTEGER_CST)
3572 TREE_OVERFLOW (value) = TREE_OVERFLOW (ovalue);
3573 TREE_CONSTANT_OVERFLOW (value) = TREE_CONSTANT_OVERFLOW (ovalue);
3577 /* Pedantically, don't ley (void *) (FOO *) 0 be a null pointer constant. */
3578 if (pedantic && TREE_CODE (value) == INTEGER_CST
3579 && TREE_CODE (expr) == INTEGER_CST
3580 && TREE_CODE (TREE_TYPE (expr)) != INTEGER_TYPE)
3581 value = non_lvalue (value);
3583 /* If pedantic, don't let a cast be an lvalue. */
3584 if (value == expr && pedantic)
3585 value = non_lvalue (value);
3590 /* Build an assignment expression of lvalue LHS from value RHS.
3591 MODIFYCODE is the code for a binary operator that we use
3592 to combine the old value of LHS with RHS to get the new value.
3593 Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment. */
3596 build_modify_expr (lhs, modifycode, rhs)
3598 enum tree_code modifycode;
3600 register tree result;
3602 tree lhstype = TREE_TYPE (lhs);
3603 tree olhstype = lhstype;
3605 /* Types that aren't fully specified cannot be used in assignments. */
3606 lhs = require_complete_type (lhs);
3608 /* Avoid duplicate error messages from operands that had errors. */
3609 if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK)
3610 return error_mark_node;
3612 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
3613 /* Do not use STRIP_NOPS here. We do not want an enumerator
3614 whose value is 0 to count as a null pointer constant. */
3615 if (TREE_CODE (rhs) == NON_LVALUE_EXPR)
3616 rhs = TREE_OPERAND (rhs, 0);
3620 /* Handle control structure constructs used as "lvalues". */
3622 switch (TREE_CODE (lhs))
3624 /* Handle (a, b) used as an "lvalue". */
3626 pedantic_lvalue_warning (COMPOUND_EXPR);
3627 newrhs = build_modify_expr (TREE_OPERAND (lhs, 1),
3629 if (TREE_CODE (newrhs) == ERROR_MARK)
3630 return error_mark_node;
3631 return build (COMPOUND_EXPR, lhstype,
3632 TREE_OPERAND (lhs, 0), newrhs);
3634 /* Handle (a ? b : c) used as an "lvalue". */
3636 pedantic_lvalue_warning (COND_EXPR);
3637 rhs = save_expr (rhs);
3639 /* Produce (a ? (b = rhs) : (c = rhs))
3640 except that the RHS goes through a save-expr
3641 so the code to compute it is only emitted once. */
3643 = build_conditional_expr (TREE_OPERAND (lhs, 0),
3644 build_modify_expr (TREE_OPERAND (lhs, 1),
3646 build_modify_expr (TREE_OPERAND (lhs, 2),
3648 if (TREE_CODE (cond) == ERROR_MARK)
3650 /* Make sure the code to compute the rhs comes out
3651 before the split. */
3652 return build (COMPOUND_EXPR, TREE_TYPE (lhs),
3653 /* But cast it to void to avoid an "unused" error. */
3654 convert (void_type_node, rhs), cond);
3658 /* If a binary op has been requested, combine the old LHS value with the RHS
3659 producing the value we should actually store into the LHS. */
3661 if (modifycode != NOP_EXPR)
3663 lhs = stabilize_reference (lhs);
3664 newrhs = build_binary_op (modifycode, lhs, rhs, 1);
3667 /* Handle a cast used as an "lvalue".
3668 We have already performed any binary operator using the value as cast.
3669 Now convert the result to the cast type of the lhs,
3670 and then true type of the lhs and store it there;
3671 then convert result back to the cast type to be the value
3672 of the assignment. */
3674 switch (TREE_CODE (lhs))
3679 case FIX_TRUNC_EXPR:
3680 case FIX_FLOOR_EXPR:
3681 case FIX_ROUND_EXPR:
3683 if (TREE_CODE (TREE_TYPE (newrhs)) == ARRAY_TYPE
3684 || TREE_CODE (TREE_TYPE (newrhs)) == FUNCTION_TYPE)
3685 newrhs = default_conversion (newrhs);
3687 tree inner_lhs = TREE_OPERAND (lhs, 0);
3689 result = build_modify_expr (inner_lhs, NOP_EXPR,
3690 convert (TREE_TYPE (inner_lhs),
3691 convert (lhstype, newrhs)));
3692 if (TREE_CODE (result) == ERROR_MARK)
3694 pedantic_lvalue_warning (CONVERT_EXPR);
3695 return convert (TREE_TYPE (lhs), result);
3699 /* Now we have handled acceptable kinds of LHS that are not truly lvalues.
3700 Reject anything strange now. */
3702 if (!lvalue_or_else (lhs, "assignment"))
3703 return error_mark_node;
3705 /* Warn about storing in something that is `const'. */
3707 if (TREE_READONLY (lhs) || TYPE_READONLY (lhstype)
3708 || ((TREE_CODE (lhstype) == RECORD_TYPE
3709 || TREE_CODE (lhstype) == UNION_TYPE)
3710 && C_TYPE_FIELDS_READONLY (lhstype)))
3711 readonly_warning (lhs, "assignment");
3713 /* If storing into a structure or union member,
3714 it has probably been given type `int'.
3715 Compute the type that would go with
3716 the actual amount of storage the member occupies. */
3718 if (TREE_CODE (lhs) == COMPONENT_REF
3719 && (TREE_CODE (lhstype) == INTEGER_TYPE
3720 || TREE_CODE (lhstype) == REAL_TYPE
3721 || TREE_CODE (lhstype) == ENUMERAL_TYPE))
3722 lhstype = TREE_TYPE (get_unwidened (lhs, 0));
3724 /* If storing in a field that is in actuality a short or narrower than one,
3725 we must store in the field in its actual type. */
3727 if (lhstype != TREE_TYPE (lhs))
3729 lhs = copy_node (lhs);
3730 TREE_TYPE (lhs) = lhstype;
3733 /* Convert new value to destination type. */
3735 newrhs = convert_for_assignment (lhstype, newrhs, "assignment",
3736 NULL_TREE, NULL_TREE, 0);
3737 if (TREE_CODE (newrhs) == ERROR_MARK)
3738 return error_mark_node;
3740 result = build (MODIFY_EXPR, lhstype, lhs, newrhs);
3741 TREE_SIDE_EFFECTS (result) = 1;
3743 /* If we got the LHS in a different type for storing in,
3744 convert the result back to the nominal type of LHS
3745 so that the value we return always has the same type
3746 as the LHS argument. */
3748 if (olhstype == TREE_TYPE (result))
3750 return convert_for_assignment (olhstype, result, "assignment",
3751 NULL_TREE, NULL_TREE, 0);
3754 /* Convert value RHS to type TYPE as preparation for an assignment
3755 to an lvalue of type TYPE.
3756 The real work of conversion is done by `convert'.
3757 The purpose of this function is to generate error messages
3758 for assignments that are not allowed in C.
3759 ERRTYPE is a string to use in error messages:
3760 "assignment", "return", etc. If it is null, this is parameter passing
3761 for a function call (and different error messages are output). Otherwise,
3762 it may be a name stored in the spelling stack and interpreted by
3765 FUNNAME is the name of the function being called,
3766 as an IDENTIFIER_NODE, or null.
3767 PARMNUM is the number of the argument, for printing in error messages. */
3770 convert_for_assignment (type, rhs, errtype, fundecl, funname, parmnum)
3773 tree fundecl, funname;
3776 register enum tree_code codel = TREE_CODE (type);
3777 register tree rhstype;
3778 register enum tree_code coder;
3780 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
3781 /* Do not use STRIP_NOPS here. We do not want an enumerator
3782 whose value is 0 to count as a null pointer constant. */
3783 if (TREE_CODE (rhs) == NON_LVALUE_EXPR)
3784 rhs = TREE_OPERAND (rhs, 0);
3786 if (TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE
3787 || TREE_CODE (TREE_TYPE (rhs)) == FUNCTION_TYPE)
3788 rhs = default_conversion (rhs);
3790 rhstype = TREE_TYPE (rhs);
3791 coder = TREE_CODE (rhstype);
3793 if (coder == ERROR_MARK)
3794 return error_mark_node;
3796 if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype))
3798 overflow_warning (rhs);
3799 /* Check for Objective-C protocols. This will issue a warning if
3800 there are protocol violations. No need to use the return value. */
3801 maybe_objc_comptypes (type, rhstype, 0);
3805 if (coder == VOID_TYPE)
3807 error ("void value not ignored as it ought to be");
3808 return error_mark_node;
3810 /* Arithmetic types all interconvert, and enum is treated like int. */
3811 if ((codel == INTEGER_TYPE || codel == REAL_TYPE || codel == ENUMERAL_TYPE
3812 || codel == COMPLEX_TYPE)
3814 (coder == INTEGER_TYPE || coder == REAL_TYPE || coder == ENUMERAL_TYPE
3815 || coder == COMPLEX_TYPE))
3816 return convert_and_check (type, rhs);
3817 /* Conversion to a union from its member types. */
3818 else if (codel == UNION_TYPE)
3821 for (memb_types = TYPE_FIELDS (type); memb_types;
3822 memb_types = TREE_CHAIN (memb_types))
3824 if (comptypes (TREE_TYPE (memb_types), TREE_TYPE (rhs)))
3827 && !(fundecl != 0 && DECL_IN_SYSTEM_HEADER (fundecl)))
3828 pedwarn ("ANSI C prohibits argument conversion to union type");
3829 return build1 (NOP_EXPR, type, rhs);
3831 else if (coder == POINTER_TYPE
3832 && TREE_CODE (TREE_TYPE (memb_types)) == POINTER_TYPE)
3834 tree memb_type = TREE_TYPE (memb_types);
3835 register tree ttl = TREE_TYPE (memb_type);
3836 register tree ttr = TREE_TYPE (rhstype);
3838 /* Any non-function converts to a [const][volatile] void *
3839 and vice versa; otherwise, targets must be the same.
3840 Meanwhile, the lhs target must have all the qualifiers of the rhs. */
3841 if (TYPE_MAIN_VARIANT (ttl) == void_type_node
3842 || TYPE_MAIN_VARIANT (ttr) == void_type_node
3843 || comp_target_types (memb_type, rhstype))
3845 /* Const and volatile mean something different for function types,
3846 so the usual warnings are not appropriate. */
3847 if (TREE_CODE (ttr) != FUNCTION_TYPE
3848 || TREE_CODE (ttl) != FUNCTION_TYPE)
3850 if (! TYPE_READONLY (ttl) && TYPE_READONLY (ttr))
3851 warn_for_assignment ("%s discards `const' from pointer target type",
3852 get_spelling (errtype), funname, parmnum);
3853 if (! TYPE_VOLATILE (ttl) && TYPE_VOLATILE (ttr))
3854 warn_for_assignment ("%s discards `volatile' from pointer target type",
3855 get_spelling (errtype), funname, parmnum);
3859 /* Because const and volatile on functions are restrictions
3860 that say the function will not do certain things,
3861 it is okay to use a const or volatile function
3862 where an ordinary one is wanted, but not vice-versa. */
3863 if (TYPE_READONLY (ttl) && ! TYPE_READONLY (ttr))
3864 warn_for_assignment ("%s makes `const *' function pointer from non-const",
3865 get_spelling (errtype), funname, parmnum);
3866 if (TYPE_VOLATILE (ttl) && ! TYPE_VOLATILE (ttr))
3867 warn_for_assignment ("%s makes `volatile *' function pointer from non-volatile",
3868 get_spelling (errtype), funname, parmnum);
3871 && !(fundecl != 0 && DECL_IN_SYSTEM_HEADER (fundecl)))
3872 pedwarn ("ANSI C prohibits argument conversion to union type");
3873 return build1 (NOP_EXPR, type, rhs);
3878 /* Conversions among pointers */
3879 else if (codel == POINTER_TYPE && coder == POINTER_TYPE)
3881 register tree ttl = TREE_TYPE (type);
3882 register tree ttr = TREE_TYPE (rhstype);
3884 /* Any non-function converts to a [const][volatile] void *
3885 and vice versa; otherwise, targets must be the same.
3886 Meanwhile, the lhs target must have all the qualifiers of the rhs. */
3887 if (TYPE_MAIN_VARIANT (ttl) == void_type_node
3888 || TYPE_MAIN_VARIANT (ttr) == void_type_node
3889 || comp_target_types (type, rhstype)
3890 || (unsigned_type (TYPE_MAIN_VARIANT (ttl))
3891 == unsigned_type (TYPE_MAIN_VARIANT (ttr))))
3894 && ((TYPE_MAIN_VARIANT (ttl) == void_type_node
3895 && TREE_CODE (ttr) == FUNCTION_TYPE)
3897 (TYPE_MAIN_VARIANT (ttr) == void_type_node
3898 /* Check TREE_CODE to catch cases like (void *) (char *) 0
3899 which are not ANSI null ptr constants. */
3900 && (!integer_zerop (rhs) || TREE_CODE (rhs) == NOP_EXPR)
3901 && TREE_CODE (ttl) == FUNCTION_TYPE)))
3902 warn_for_assignment ("ANSI forbids %s between function pointer and `void *'",
3903 get_spelling (errtype), funname, parmnum);
3904 /* Const and volatile mean something different for function types,
3905 so the usual warnings are not appropriate. */
3906 else if (TREE_CODE (ttr) != FUNCTION_TYPE
3907 || TREE_CODE (ttl) != FUNCTION_TYPE)
3909 if (! TYPE_READONLY (ttl) && TYPE_READONLY (ttr))
3910 warn_for_assignment ("%s discards `const' from pointer target type",
3911 get_spelling (errtype), funname, parmnum);
3912 else if (! TYPE_VOLATILE (ttl) && TYPE_VOLATILE (ttr))
3913 warn_for_assignment ("%s discards `volatile' from pointer target type",
3914 get_spelling (errtype), funname, parmnum);
3915 /* If this is not a case of ignoring a mismatch in signedness,
3917 else if (TYPE_MAIN_VARIANT (ttl) == void_type_node
3918 || TYPE_MAIN_VARIANT (ttr) == void_type_node
3919 || comp_target_types (type, rhstype))
3921 /* If there is a mismatch, do warn. */
3923 warn_for_assignment ("pointer targets in %s differ in signedness",
3924 get_spelling (errtype), funname, parmnum);
3928 /* Because const and volatile on functions are restrictions
3929 that say the function will not do certain things,
3930 it is okay to use a const or volatile function
3931 where an ordinary one is wanted, but not vice-versa. */
3932 if (TYPE_READONLY (ttl) && ! TYPE_READONLY (ttr))
3933 warn_for_assignment ("%s makes `const *' function pointer from non-const",
3934 get_spelling (errtype), funname, parmnum);
3935 if (TYPE_VOLATILE (ttl) && ! TYPE_VOLATILE (ttr))
3936 warn_for_assignment ("%s makes `volatile *' function pointer from non-volatile",
3937 get_spelling (errtype), funname, parmnum);
3941 warn_for_assignment ("%s from incompatible pointer type",
3942 get_spelling (errtype), funname, parmnum);
3943 return convert (type, rhs);
3945 else if (codel == POINTER_TYPE && coder == INTEGER_TYPE)
3947 /* An explicit constant 0 can convert to a pointer,
3948 or one that results from arithmetic, even including
3949 a cast to integer type. */
3950 if (! (TREE_CODE (rhs) == INTEGER_CST && integer_zerop (rhs))
3952 ! (TREE_CODE (rhs) == NOP_EXPR
3953 && TREE_CODE (TREE_TYPE (rhs)) == INTEGER_TYPE
3954 && TREE_CODE (TREE_OPERAND (rhs, 0)) == INTEGER_CST
3955 && integer_zerop (TREE_OPERAND (rhs, 0))))
3957 warn_for_assignment ("%s makes pointer from integer without a cast",
3958 get_spelling (errtype), funname, parmnum);
3959 return convert (type, rhs);
3961 return null_pointer_node;
3963 else if (codel == INTEGER_TYPE && coder == POINTER_TYPE)
3965 warn_for_assignment ("%s makes integer from pointer without a cast",
3966 get_spelling (errtype), funname, parmnum);
3967 return convert (type, rhs);
3974 tree selector = maybe_building_objc_message_expr ();
3976 if (selector && parmnum > 2)
3977 error ("incompatible type for argument %d of `%s'",
3978 parmnum - 2, IDENTIFIER_POINTER (selector));
3980 error ("incompatible type for argument %d of `%s'",
3981 parmnum, IDENTIFIER_POINTER (funname));
3984 error ("incompatible type for argument %d of indirect function call",
3988 error ("incompatible types in %s", get_spelling (errtype));
3990 return error_mark_node;
3993 /* Print a warning using MSG.
3994 It gets OPNAME as its one parameter.
3995 If OPNAME is null, it is replaced by "passing arg ARGNUM of `FUNCTION'".
3996 FUNCTION and ARGNUM are handled specially if we are building an
3997 Objective-C selector. */
4000 warn_for_assignment (msg, opname, function, argnum)
4006 static char argstring[] = "passing arg %d of `%s'";
4007 static char argnofun[] = "passing arg %d";
4011 tree selector = maybe_building_objc_message_expr ();
4013 if (selector && argnum > 2)
4015 function = selector;
4020 /* Function name is known; supply it. */
4021 opname = (char *) alloca (IDENTIFIER_LENGTH (function)
4022 + sizeof (argstring) + 25 /*%d*/ + 1);
4023 sprintf (opname, argstring, argnum, IDENTIFIER_POINTER (function));
4027 /* Function name unknown (call through ptr); just give arg number. */
4028 opname = (char *) alloca (sizeof (argnofun) + 25 /*%d*/ + 1);
4029 sprintf (opname, argnofun, argnum);
4032 pedwarn (msg, opname);
4035 /* Return nonzero if VALUE is a valid constant-valued expression
4036 for use in initializing a static variable; one that can be an
4037 element of a "constant" initializer.
4039 Return null_pointer_node if the value is absolute;
4040 if it is relocatable, return the variable that determines the relocation.
4041 We assume that VALUE has been folded as much as possible;
4042 therefore, we do not need to check for such things as
4043 arithmetic-combinations of integers. */
4046 initializer_constant_valid_p (value, endtype)
4050 switch (TREE_CODE (value))
4053 if (TREE_CODE (TREE_TYPE (value)) == UNION_TYPE
4054 && TREE_CONSTANT (value))
4056 initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value)),
4059 return TREE_STATIC (value) ? null_pointer_node : 0;
4065 return null_pointer_node;
4068 return TREE_OPERAND (value, 0);
4070 case NON_LVALUE_EXPR:
4071 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4075 /* Allow conversions between pointer types. */
4076 if (TREE_CODE (TREE_TYPE (value)) == POINTER_TYPE
4077 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == POINTER_TYPE)
4078 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4079 /* Allow conversions between real types. */
4080 if (TREE_CODE (TREE_TYPE (value)) == REAL_TYPE
4081 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == REAL_TYPE)
4082 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4083 /* Allow length-preserving conversions between integer types. */
4084 if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE
4085 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == INTEGER_TYPE
4086 && tree_int_cst_equal (TYPE_SIZE (TREE_TYPE (value)),
4087 TYPE_SIZE (TREE_TYPE (TREE_OPERAND (value, 0)))))
4088 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4089 /* Allow conversions between integer types only if explicit value. */
4090 if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE
4091 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == INTEGER_TYPE)
4093 tree inner = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4095 if (inner == null_pointer_node)
4096 return null_pointer_node;
4099 /* Allow (int) &foo provided int is as wide as a pointer. */
4100 if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE
4101 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == POINTER_TYPE
4102 && ! tree_int_cst_lt (TYPE_SIZE (TREE_TYPE (value)),
4103 TYPE_SIZE (TREE_TYPE (TREE_OPERAND (value, 0)))))
4104 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4106 /* Allow conversions to union types if the value inside is okay. */
4107 if (TREE_CODE (TREE_TYPE (value)) == UNION_TYPE)
4108 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4113 if (TREE_CODE (endtype) == INTEGER_TYPE
4114 && TYPE_PRECISION (endtype) < POINTER_SIZE)
4117 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4119 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
4121 /* If either term is absolute, use the other terms relocation. */
4122 if (valid0 == null_pointer_node)
4124 if (valid1 == null_pointer_node)
4130 if (TREE_CODE (endtype) == INTEGER_TYPE
4131 && TYPE_PRECISION (endtype) < POINTER_SIZE)
4134 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4136 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
4138 /* Win if second argument is absolute. */
4139 if (valid1 == null_pointer_node)
4141 /* Win if both arguments have the same relocation.
4142 Then the value is absolute. */
4143 if (valid0 == valid1)
4144 return null_pointer_node;
4152 /* If VALUE is a compound expr all of whose expressions are constant, then
4153 return its value. Otherwise, return error_mark_node.
4155 This is for handling COMPOUND_EXPRs as initializer elements
4156 which is allowed with a warning when -pedantic is specified. */
4159 valid_compound_expr_initializer (value, endtype)
4163 if (TREE_CODE (value) == COMPOUND_EXPR)
4165 if (valid_compound_expr_initializer (TREE_OPERAND (value, 0), endtype)
4167 return error_mark_node;
4168 return valid_compound_expr_initializer (TREE_OPERAND (value, 1),
4171 else if (! TREE_CONSTANT (value)
4172 && ! initializer_constant_valid_p (value, endtype))
4173 return error_mark_node;
4178 /* Perform appropriate conversions on the initial value of a variable,
4179 store it in the declaration DECL,
4180 and print any error messages that are appropriate.
4181 If the init is invalid, store an ERROR_MARK. */
4184 store_init_value (decl, init)
4187 register tree value, type;
4189 /* If variable's type was invalidly declared, just ignore it. */
4191 type = TREE_TYPE (decl);
4192 if (TREE_CODE (type) == ERROR_MARK)
4195 /* Digest the specified initializer into an expression. */
4197 value = digest_init (type, init, TREE_STATIC (decl),
4198 TREE_STATIC (decl) || pedantic);
4200 /* Store the expression if valid; else report error. */
4203 /* Note that this is the only place we can detect the error
4204 in a case such as struct foo bar = (struct foo) { x, y };
4205 where there is one initial value which is a constructor expression. */
4206 if (value == error_mark_node)
4208 else if (TREE_STATIC (decl) && ! TREE_CONSTANT (value))
4210 error ("initializer for static variable is not constant");
4211 value = error_mark_node;
4213 else if (TREE_STATIC (decl)
4214 && initializer_constant_valid_p (value, TREE_TYPE (value)) == 0)
4216 error ("initializer for static variable uses complicated arithmetic");
4217 value = error_mark_node;
4221 if (pedantic && TREE_CODE (value) == CONSTRUCTOR)
4223 if (! TREE_CONSTANT (value))
4224 pedwarn ("aggregate initializer is not constant");
4225 else if (! TREE_STATIC (value))
4226 pedwarn ("aggregate initializer uses complicated arithmetic");
4231 DECL_INITIAL (decl) = value;
4233 /* ANSI wants warnings about out-of-range constant initializers. */
4234 STRIP_TYPE_NOPS (value);
4235 constant_expression_warning (value);
4238 /* Methods for storing and printing names for error messages. */
4240 /* Implement a spelling stack that allows components of a name to be pushed
4241 and popped. Each element on the stack is this structure. */
4253 #define SPELLING_STRING 1
4254 #define SPELLING_MEMBER 2
4255 #define SPELLING_BOUNDS 3
4257 static struct spelling *spelling; /* Next stack element (unused). */
4258 static struct spelling *spelling_base; /* Spelling stack base. */
4259 static int spelling_size; /* Size of the spelling stack. */
4261 /* Macros to save and restore the spelling stack around push_... functions.
4262 Alternative to SAVE_SPELLING_STACK. */
4264 #define SPELLING_DEPTH() (spelling - spelling_base)
4265 #define RESTORE_SPELLING_DEPTH(depth) (spelling = spelling_base + depth)
4267 /* Save and restore the spelling stack around arbitrary C code. */
4269 #define SAVE_SPELLING_DEPTH(code) \
4271 int __depth = SPELLING_DEPTH (); \
4273 RESTORE_SPELLING_DEPTH (__depth); \
4276 /* Push an element on the spelling stack with type KIND and assign VALUE
4279 #define PUSH_SPELLING(KIND, VALUE, MEMBER) \
4281 int depth = SPELLING_DEPTH (); \
4283 if (depth >= spelling_size) \
4285 spelling_size += 10; \
4286 if (spelling_base == 0) \
4288 = (struct spelling *) xmalloc (spelling_size * sizeof (struct spelling)); \
4291 = (struct spelling *) xrealloc (spelling_base, \
4292 spelling_size * sizeof (struct spelling)); \
4293 RESTORE_SPELLING_DEPTH (depth); \
4296 spelling->kind = (KIND); \
4297 spelling->MEMBER = (VALUE); \
4301 /* Push STRING on the stack. Printed literally. */
4304 push_string (string)
4307 PUSH_SPELLING (SPELLING_STRING, string, u.s);
4310 /* Push a member name on the stack. Printed as '.' STRING. */
4313 push_member_name (decl)
4318 = DECL_NAME (decl) ? IDENTIFIER_POINTER (DECL_NAME (decl)) : "<anonymous>";
4319 PUSH_SPELLING (SPELLING_MEMBER, string, u.s);
4322 /* Push an array bounds on the stack. Printed as [BOUNDS]. */
4325 push_array_bounds (bounds)
4328 PUSH_SPELLING (SPELLING_BOUNDS, bounds, u.i);
4331 /* Compute the maximum size in bytes of the printed spelling. */
4336 register int size = 0;
4337 register struct spelling *p;
4339 for (p = spelling_base; p < spelling; p++)
4341 if (p->kind == SPELLING_BOUNDS)
4344 size += strlen (p->u.s) + 1;
4350 /* Print the spelling to BUFFER and return it. */
4353 print_spelling (buffer)
4354 register char *buffer;
4356 register char *d = buffer;
4358 register struct spelling *p;
4360 for (p = spelling_base; p < spelling; p++)
4361 if (p->kind == SPELLING_BOUNDS)
4363 sprintf (d, "[%d]", p->u.i);
4368 if (p->kind == SPELLING_MEMBER)
4370 for (s = p->u.s; *d = *s++; d++)
4377 /* Provide a means to pass component names derived from the spelling stack. */
4379 char initialization_message;
4381 /* Interpret the spelling of the given ERRTYPE message. */
4384 get_spelling (errtype)
4387 static char *buffer;
4388 static int size = -1;
4390 if (errtype == &initialization_message)
4392 /* Avoid counting chars */
4393 static char message[] = "initialization of `%s'";
4394 register int needed = sizeof (message) + spelling_length () + 1;
4398 buffer = (char *) xmalloc (size = needed);
4400 buffer = (char *) xrealloc (buffer, size = needed);
4402 temp = (char *) alloca (needed);
4403 sprintf (buffer, message, print_spelling (temp));
4410 /* Issue an error message for a bad initializer component.
4411 FORMAT describes the message. OFWHAT is the name for the component.
4412 LOCAL is a format string for formatting the insertion of the name
4415 If OFWHAT is null, the component name is stored on the spelling stack.
4416 If the component name is a null string, then LOCAL is omitted entirely. */
4419 error_init (format, local, ofwhat)
4420 char *format, *local, *ofwhat;
4425 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
4426 buffer = (char *) alloca (strlen (local) + strlen (ofwhat) + 2);
4429 sprintf (buffer, local, ofwhat);
4433 error (format, buffer);
4436 /* Issue a pedantic warning for a bad initializer component.
4437 FORMAT describes the message. OFWHAT is the name for the component.
4438 LOCAL is a format string for formatting the insertion of the name
4441 If OFWHAT is null, the component name is stored on the spelling stack.
4442 If the component name is a null string, then LOCAL is omitted entirely. */
4445 pedwarn_init (format, local, ofwhat)
4446 char *format, *local, *ofwhat;
4451 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
4452 buffer = (char *) alloca (strlen (local) + strlen (ofwhat) + 2);
4455 sprintf (buffer, local, ofwhat);
4459 pedwarn (format, buffer);
4462 /* Issue a warning for a bad initializer component.
4463 FORMAT describes the message. OFWHAT is the name for the component.
4464 LOCAL is a format string for formatting the insertion of the name
4467 If OFWHAT is null, the component name is stored on the spelling stack.
4468 If the component name is a null string, then LOCAL is omitted entirely. */
4471 warning_init (format, local, ofwhat)
4472 char *format, *local, *ofwhat;
4477 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
4478 buffer = (char *) alloca (strlen (local) + strlen (ofwhat) + 2);
4481 sprintf (buffer, local, ofwhat);
4485 warning (format, buffer);
4488 /* Digest the parser output INIT as an initializer for type TYPE.
4489 Return a C expression of type TYPE to represent the initial value.
4491 The arguments REQUIRE_CONSTANT and CONSTRUCTOR_CONSTANT request errors
4492 if non-constant initializers or elements are seen. CONSTRUCTOR_CONSTANT
4493 applies only to elements of constructors. */
4496 digest_init (type, init, require_constant, constructor_constant)
4498 int require_constant, constructor_constant;
4500 enum tree_code code = TREE_CODE (type);
4501 tree inside_init = init;
4503 if (init == error_mark_node)
4506 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
4507 /* Do not use STRIP_NOPS here. We do not want an enumerator
4508 whose value is 0 to count as a null pointer constant. */
4509 if (TREE_CODE (init) == NON_LVALUE_EXPR)
4510 inside_init = TREE_OPERAND (init, 0);
4512 /* Initialization of an array of chars from a string constant
4513 optionally enclosed in braces. */
4515 if (code == ARRAY_TYPE)
4517 tree typ1 = TYPE_MAIN_VARIANT (TREE_TYPE (type));
4518 if ((typ1 == char_type_node
4519 || typ1 == signed_char_type_node
4520 || typ1 == unsigned_char_type_node
4521 || typ1 == unsigned_wchar_type_node
4522 || typ1 == signed_wchar_type_node)
4523 && ((inside_init && TREE_CODE (inside_init) == STRING_CST)))
4525 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
4526 TYPE_MAIN_VARIANT (type)))
4529 if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init)))
4531 && TYPE_PRECISION (typ1) == TYPE_PRECISION (char_type_node))
4533 error_init ("char-array%s initialized from wide string",
4535 return error_mark_node;
4537 if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init)))
4539 && TYPE_PRECISION (typ1) != TYPE_PRECISION (char_type_node))
4541 error_init ("int-array%s initialized from non-wide string",
4543 return error_mark_node;
4546 TREE_TYPE (inside_init) = type;
4547 if (TYPE_DOMAIN (type) != 0
4548 && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
4550 register int size = TREE_INT_CST_LOW (TYPE_SIZE (type));
4551 size = (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
4552 /* Subtract 1 (or sizeof (wchar_t))
4553 because it's ok to ignore the terminating null char
4554 that is counted in the length of the constant. */
4555 if (size < TREE_STRING_LENGTH (inside_init)
4556 - (TYPE_PRECISION (typ1) != TYPE_PRECISION (char_type_node)
4557 ? TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT
4560 "initializer-string for array of chars%s is too long",
4567 /* Any type can be initialized
4568 from an expression of the same type, optionally with braces. */
4570 if (inside_init && TREE_TYPE (inside_init) != 0
4571 && (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
4572 TYPE_MAIN_VARIANT (type))
4573 || (code == ARRAY_TYPE
4574 && comptypes (TREE_TYPE (inside_init), type))
4575 || (code == POINTER_TYPE
4576 && (TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE
4577 || TREE_CODE (TREE_TYPE (inside_init)) == FUNCTION_TYPE)
4578 && comptypes (TREE_TYPE (TREE_TYPE (inside_init)),
4579 TREE_TYPE (type)))))
4581 if (code == POINTER_TYPE
4582 && (TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE
4583 || TREE_CODE (TREE_TYPE (inside_init)) == FUNCTION_TYPE))
4584 inside_init = default_conversion (inside_init);
4585 else if (code == ARRAY_TYPE && TREE_CODE (inside_init) != STRING_CST
4586 && TREE_CODE (inside_init) != CONSTRUCTOR)
4588 error_init ("array%s initialized from non-constant array expression",
4590 return error_mark_node;
4593 if (optimize && TREE_READONLY (inside_init)
4594 && TREE_CODE (inside_init) == VAR_DECL)
4595 inside_init = decl_constant_value (inside_init);
4597 /* Compound expressions can only occur here if -pedantic or
4598 -pedantic-errors is specified. In the later case, we always want
4599 an error. In the former case, we simply want a warning. */
4600 if (require_constant && pedantic
4601 && TREE_CODE (inside_init) == COMPOUND_EXPR)
4604 = valid_compound_expr_initializer (inside_init,
4605 TREE_TYPE (inside_init));
4606 if (inside_init == error_mark_node)
4607 error_init ("initializer element%s is not constant",
4610 pedwarn_init ("initializer element%s is not constant",
4612 if (flag_pedantic_errors)
4613 inside_init = error_mark_node;
4615 else if (require_constant && ! TREE_CONSTANT (inside_init))
4617 error_init ("initializer element%s is not constant",
4619 inside_init = error_mark_node;
4621 else if (require_constant
4622 && initializer_constant_valid_p (inside_init, TREE_TYPE (inside_init)) == 0)
4624 error_init ("initializer element%s is not computable at load time",
4626 inside_init = error_mark_node;
4632 /* Handle scalar types, including conversions. */
4634 if (code == INTEGER_TYPE || code == REAL_TYPE || code == POINTER_TYPE
4635 || code == ENUMERAL_TYPE || code == COMPLEX_TYPE)
4637 /* Note that convert_for_assignment calls default_conversion
4638 for arrays and functions. We must not call it in the
4639 case where inside_init is a null pointer constant. */
4641 = convert_for_assignment (type, init, "initialization",
4642 NULL_TREE, NULL_TREE, 0);
4644 if (require_constant && ! TREE_CONSTANT (inside_init))
4646 error_init ("initializer element%s is not constant",
4648 inside_init = error_mark_node;
4650 else if (require_constant
4651 && initializer_constant_valid_p (inside_init, TREE_TYPE (inside_init)) == 0)
4653 error_init ("initializer element%s is not computable at load time",
4655 inside_init = error_mark_node;
4661 /* Come here only for records and arrays. */
4663 if (TYPE_SIZE (type) && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
4665 error_init ("variable-sized object%s may not be initialized",
4667 return error_mark_node;
4670 /* Traditionally, you can write struct foo x = 0;
4671 and it initializes the first element of x to 0. */
4672 if (flag_traditional)
4674 tree top = 0, prev = 0;
4675 while (TREE_CODE (type) == RECORD_TYPE
4676 || TREE_CODE (type) == ARRAY_TYPE
4677 || TREE_CODE (type) == QUAL_UNION_TYPE
4678 || TREE_CODE (type) == UNION_TYPE)
4680 tree temp = build (CONSTRUCTOR, type, NULL_TREE, NULL_TREE);
4684 TREE_OPERAND (prev, 1) = build_tree_list (NULL_TREE, temp);
4686 if (TREE_CODE (type) == ARRAY_TYPE)
4687 type = TREE_TYPE (type);
4688 else if (TYPE_FIELDS (type))
4689 type = TREE_TYPE (TYPE_FIELDS (type));
4692 error_init ("invalid initializer%s", " for `%s'", NULL);
4693 return error_mark_node;
4696 TREE_OPERAND (prev, 1)
4697 = build_tree_list (NULL_TREE,
4698 digest_init (type, init, require_constant,
4699 constructor_constant));
4702 error_init ("invalid initializer%s", " for `%s'", NULL);
4703 return error_mark_node;
4706 /* Handle initializers that use braces. */
4708 /* Type of object we are accumulating a constructor for.
4709 This type is always a RECORD_TYPE, UNION_TYPE or ARRAY_TYPE. */
4710 static tree constructor_type;
4712 /* For a RECORD_TYPE or UNION_TYPE, this is the chain of fields
4714 static tree constructor_fields;
4716 /* For an ARRAY_TYPE, this is the specified index
4717 at which to store the next element we get.
4718 This is a special INTEGER_CST node that we modify in place. */
4719 static tree constructor_index;
4721 /* For an ARRAY_TYPE, this is the end index of the range
4722 to intitialize with the next element, or NULL in the ordinary case
4723 where the element is used just once. */
4724 static tree constructor_range_end;
4726 /* For an ARRAY_TYPE, this is the maximum index. */
4727 static tree constructor_max_index;
4729 /* For a RECORD_TYPE, this is the first field not yet written out. */
4730 static tree constructor_unfilled_fields;
4732 /* For an ARRAY_TYPE, this is the index of the first element
4733 not yet written out.
4734 This is a special INTEGER_CST node that we modify in place. */
4735 static tree constructor_unfilled_index;
4737 /* In a RECORD_TYPE, the byte index of the next consecutive field.
4738 This is so we can generate gaps between fields, when appropriate.
4739 This is a special INTEGER_CST node that we modify in place. */
4740 static tree constructor_bit_index;
4742 /* If we are saving up the elements rather than allocating them,
4743 this is the list of elements so far (in reverse order,
4744 most recent first). */
4745 static tree constructor_elements;
4747 /* 1 if so far this constructor's elements are all compile-time constants. */
4748 static int constructor_constant;
4750 /* 1 if so far this constructor's elements are all valid address constants. */
4751 static int constructor_simple;
4753 /* 1 if this constructor is erroneous so far. */
4754 static int constructor_erroneous;
4756 /* 1 if have called defer_addressed_constants. */
4757 static int constructor_subconstants_deferred;
4759 /* List of pending elements at this constructor level.
4760 These are elements encountered out of order
4761 which belong at places we haven't reached yet in actually
4762 writing the output. */
4763 static tree constructor_pending_elts;
4765 /* The SPELLING_DEPTH of this constructor. */
4766 static int constructor_depth;
4768 /* 0 if implicitly pushing constructor levels is allowed. */
4769 int constructor_no_implicit = 0; /* 0 for C; 1 for some other languages. */
4771 /* 1 if this constructor level was entered implicitly. */
4772 static int constructor_implicit;
4774 static int require_constant_value;
4775 static int require_constant_elements;
4777 /* 1 if it is ok to output this constructor as we read it.
4778 0 means must accumulate a CONSTRUCTOR expression. */
4779 static int constructor_incremental;
4781 /* DECL node for which an initializer is being read.
4782 0 means we are reading a constructor expression
4783 such as (struct foo) {...}. */
4784 static tree constructor_decl;
4786 /* start_init saves the ASMSPEC arg here for really_start_incremental_init. */
4787 static char *constructor_asmspec;
4789 /* Nonzero if this is an initializer for a top-level decl. */
4790 static int constructor_top_level;
4792 /* When we finish reading a constructor expression
4793 (constructor_decl is 0), the CONSTRUCTOR goes here. */
4794 static tree constructor_result;
4796 /* This stack has a level for each implicit or explicit level of
4797 structuring in the initializer, including the outermost one. It
4798 saves the values of most of the variables above. */
4800 struct constructor_stack
4802 struct constructor_stack *next;
4808 tree unfilled_index;
4809 tree unfilled_fields;
4815 /* If nonzero, this value should replace the entire
4816 constructor at this level. */
4817 tree replacement_value;
4826 struct constructor_stack *constructor_stack;
4828 /* This stack records separate initializers that are nested.
4829 Nested initializers can't happen in ANSI C, but GNU C allows them
4830 in cases like { ... (struct foo) { ... } ... }. */
4832 struct initializer_stack
4834 struct initializer_stack *next;
4837 struct constructor_stack *constructor_stack;
4839 struct spelling *spelling;
4840 struct spelling *spelling_base;
4844 char require_constant_value;
4845 char require_constant_elements;
4849 struct initializer_stack *initializer_stack;
4851 /* Prepare to parse and output the initializer for variable DECL. */
4854 start_init (decl, asmspec_tree, top_level)
4860 struct initializer_stack *p
4861 = (struct initializer_stack *) xmalloc (sizeof (struct initializer_stack));
4865 asmspec = TREE_STRING_POINTER (asmspec_tree);
4867 p->decl = constructor_decl;
4868 p->asmspec = constructor_asmspec;
4869 p->incremental = constructor_incremental;
4870 p->require_constant_value = require_constant_value;
4871 p->require_constant_elements = require_constant_elements;
4872 p->constructor_stack = constructor_stack;
4873 p->elements = constructor_elements;
4874 p->spelling = spelling;
4875 p->spelling_base = spelling_base;
4876 p->spelling_size = spelling_size;
4877 p->deferred = constructor_subconstants_deferred;
4878 p->top_level = constructor_top_level;
4879 p->next = initializer_stack;
4880 initializer_stack = p;
4882 constructor_decl = decl;
4883 constructor_incremental = top_level;
4884 constructor_asmspec = asmspec;
4885 constructor_subconstants_deferred = 0;
4886 constructor_top_level = top_level;
4890 require_constant_value = TREE_STATIC (decl);
4891 require_constant_elements
4892 = ((TREE_STATIC (decl) || pedantic)
4893 /* For a scalar, you can always use any value to initialize,
4894 even within braces. */
4895 && (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
4896 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
4897 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
4898 || TREE_CODE (TREE_TYPE (decl)) == QUAL_UNION_TYPE));
4899 locus = IDENTIFIER_POINTER (DECL_NAME (decl));
4900 constructor_incremental |= TREE_STATIC (decl);
4904 require_constant_value = 0;
4905 require_constant_elements = 0;
4906 locus = "(anonymous)";
4909 constructor_stack = 0;
4911 missing_braces_mentioned = 0;
4915 RESTORE_SPELLING_DEPTH (0);
4918 push_string (locus);
4924 struct initializer_stack *p = initializer_stack;
4926 /* Output subconstants (string constants, usually)
4927 that were referenced within this initializer and saved up.
4928 Must do this if and only if we called defer_addressed_constants. */
4929 if (constructor_subconstants_deferred)
4930 output_deferred_addressed_constants ();
4932 /* Free the whole constructor stack of this initializer. */
4933 while (constructor_stack)
4935 struct constructor_stack *q = constructor_stack;
4936 constructor_stack = q->next;
4940 /* Pop back to the data of the outer initializer (if any). */
4941 constructor_decl = p->decl;
4942 constructor_asmspec = p->asmspec;
4943 constructor_incremental = p->incremental;
4944 require_constant_value = p->require_constant_value;
4945 require_constant_elements = p->require_constant_elements;
4946 constructor_stack = p->constructor_stack;
4947 constructor_elements = p->elements;
4948 spelling = p->spelling;
4949 spelling_base = p->spelling_base;
4950 spelling_size = p->spelling_size;
4951 constructor_subconstants_deferred = p->deferred;
4952 constructor_top_level = p->top_level;
4953 initializer_stack = p->next;
4957 /* Call here when we see the initializer is surrounded by braces.
4958 This is instead of a call to push_init_level;
4959 it is matched by a call to pop_init_level.
4961 TYPE is the type to initialize, for a constructor expression.
4962 For an initializer for a decl, TYPE is zero. */
4965 really_start_incremental_init (type)
4968 struct constructor_stack *p
4969 = (struct constructor_stack *) xmalloc (sizeof (struct constructor_stack));
4972 type = TREE_TYPE (constructor_decl);
4974 /* Turn off constructor_incremental if type is a struct with bitfields.
4975 Do this before the first push, so that the corrected value
4976 is available in finish_init. */
4977 check_init_type_bitfields (type);
4979 p->type = constructor_type;
4980 p->fields = constructor_fields;
4981 p->index = constructor_index;
4982 p->range_end = constructor_range_end;
4983 p->max_index = constructor_max_index;
4984 p->unfilled_index = constructor_unfilled_index;
4985 p->unfilled_fields = constructor_unfilled_fields;
4986 p->bit_index = constructor_bit_index;
4987 p->elements = constructor_elements;
4988 p->constant = constructor_constant;
4989 p->simple = constructor_simple;
4990 p->erroneous = constructor_erroneous;
4991 p->pending_elts = constructor_pending_elts;
4992 p->depth = constructor_depth;
4993 p->replacement_value = 0;
4995 p->incremental = constructor_incremental;
4998 constructor_stack = p;
5000 constructor_constant = 1;
5001 constructor_simple = 1;
5002 constructor_depth = SPELLING_DEPTH ();
5003 constructor_elements = 0;
5004 constructor_pending_elts = 0;
5005 constructor_type = type;
5007 if (TREE_CODE (constructor_type) == RECORD_TYPE
5008 || TREE_CODE (constructor_type) == UNION_TYPE)
5010 constructor_fields = TYPE_FIELDS (constructor_type);
5011 /* Skip any nameless bit fields atthe beginning. */
5012 while (constructor_fields != 0 && DECL_BIT_FIELD (constructor_fields)
5013 && DECL_NAME (constructor_fields) == 0)
5014 constructor_fields = TREE_CHAIN (constructor_fields);
5015 constructor_unfilled_fields = constructor_fields;
5016 constructor_bit_index = copy_node (integer_zero_node);
5018 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5020 constructor_range_end = 0;
5021 if (TYPE_DOMAIN (constructor_type))
5023 constructor_max_index
5024 = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
5026 = copy_node (TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
5029 constructor_index = copy_node (integer_zero_node);
5030 constructor_unfilled_index = copy_node (constructor_index);
5034 /* Handle the case of int x = {5}; */
5035 constructor_fields = constructor_type;
5036 constructor_unfilled_fields = constructor_type;
5039 if (constructor_incremental)
5041 int momentary = suspend_momentary ();
5042 push_obstacks_nochange ();
5043 if (TREE_PERMANENT (constructor_decl))
5044 end_temporary_allocation ();
5045 make_decl_rtl (constructor_decl, constructor_asmspec,
5046 constructor_top_level);
5047 assemble_variable (constructor_decl, constructor_top_level, 0, 1);
5049 resume_momentary (momentary);
5052 if (constructor_incremental)
5054 defer_addressed_constants ();
5055 constructor_subconstants_deferred = 1;
5059 /* Push down into a subobject, for initialization.
5060 If this is for an explicit set of braces, IMPLICIT is 0.
5061 If it is because the next element belongs at a lower level,
5065 push_init_level (implicit)
5068 struct constructor_stack *p;
5070 /* If we've exhausted any levels that didn't have braces,
5072 while (constructor_stack->implicit)
5074 if ((TREE_CODE (constructor_type) == RECORD_TYPE
5075 || TREE_CODE (constructor_type) == UNION_TYPE)
5076 && constructor_fields == 0)
5077 process_init_element (pop_init_level (1));
5078 else if (TREE_CODE (constructor_type) == ARRAY_TYPE
5079 && tree_int_cst_lt (constructor_max_index, constructor_index))
5080 process_init_element (pop_init_level (1));
5085 /* Structure elements may require alignment. Do this now
5086 if necessary for the subaggregate. */
5087 if (constructor_incremental && TREE_CODE (constructor_type) == RECORD_TYPE
5088 && constructor_fields)
5090 /* Advance to offset of this element. */
5091 if (! tree_int_cst_equal (constructor_bit_index,
5092 DECL_FIELD_BITPOS (constructor_fields)))
5094 int next = (TREE_INT_CST_LOW
5095 (DECL_FIELD_BITPOS (constructor_fields))
5097 int here = (TREE_INT_CST_LOW (constructor_bit_index)
5100 assemble_zeros (next - here);
5104 p = (struct constructor_stack *) xmalloc (sizeof (struct constructor_stack));
5105 p->type = constructor_type;
5106 p->fields = constructor_fields;
5107 p->index = constructor_index;
5108 p->range_end = constructor_range_end;
5109 p->max_index = constructor_max_index;
5110 p->unfilled_index = constructor_unfilled_index;
5111 p->unfilled_fields = constructor_unfilled_fields;
5112 p->bit_index = constructor_bit_index;
5113 p->elements = constructor_elements;
5114 p->constant = constructor_constant;
5115 p->simple = constructor_simple;
5116 p->erroneous = constructor_erroneous;
5117 p->pending_elts = constructor_pending_elts;
5118 p->depth = constructor_depth;
5119 p->replacement_value = 0;
5120 p->implicit = implicit;
5121 p->incremental = constructor_incremental;
5123 p->next = constructor_stack;
5124 constructor_stack = p;
5126 constructor_constant = 1;
5127 constructor_simple = 1;
5128 constructor_depth = SPELLING_DEPTH ();
5129 constructor_elements = 0;
5130 constructor_pending_elts = 0;
5132 /* Don't die if an entire brace-pair level is superfluous
5133 in the containing level. */
5134 if (constructor_type == 0)
5136 else if (TREE_CODE (constructor_type) == RECORD_TYPE
5137 || TREE_CODE (constructor_type) == UNION_TYPE)
5139 /* Don't die if there are extra init elts at the end. */
5140 if (constructor_fields == 0)
5141 constructor_type = 0;
5144 constructor_type = TREE_TYPE (constructor_fields);
5145 push_member_name (constructor_fields);
5148 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5150 constructor_type = TREE_TYPE (constructor_type);
5151 push_array_bounds (TREE_INT_CST_LOW (constructor_index));
5154 if (constructor_type == 0)
5156 error_init ("extra brace group at end of initializer%s",
5158 constructor_fields = 0;
5159 constructor_unfilled_fields = 0;
5163 /* Turn off constructor_incremental if type is a struct with bitfields. */
5164 check_init_type_bitfields (constructor_type);
5166 if (implicit && warn_missing_braces && !missing_braces_mentioned)
5168 missing_braces_mentioned = 1;
5169 warning_init ("missing braces around initializer%s", " for `%s'", NULL);
5172 if (TREE_CODE (constructor_type) == RECORD_TYPE
5173 || TREE_CODE (constructor_type) == UNION_TYPE)
5175 constructor_fields = TYPE_FIELDS (constructor_type);
5176 /* Skip any nameless bit fields atthe beginning. */
5177 while (constructor_fields != 0 && DECL_BIT_FIELD (constructor_fields)
5178 && DECL_NAME (constructor_fields) == 0)
5179 constructor_fields = TREE_CHAIN (constructor_fields);
5180 constructor_unfilled_fields = constructor_fields;
5181 constructor_bit_index = copy_node (integer_zero_node);
5183 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5185 constructor_range_end = 0;
5186 if (TYPE_DOMAIN (constructor_type))
5188 constructor_max_index
5189 = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
5191 = copy_node (TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
5194 constructor_index = copy_node (integer_zero_node);
5195 constructor_unfilled_index = copy_node (constructor_index);
5199 warning_init ("braces around scalar initializer%s", " for `%s'", NULL);
5200 constructor_fields = constructor_type;
5201 constructor_unfilled_fields = constructor_type;
5205 /* Don't read a struct incrementally if it has any bitfields,
5206 because the incremental reading code doesn't know how to
5207 handle bitfields yet. */
5210 check_init_type_bitfields (type)
5213 if (TREE_CODE (type) == RECORD_TYPE)
5216 for (tail = TYPE_FIELDS (type); tail;
5217 tail = TREE_CHAIN (tail))
5219 if (DECL_BIT_FIELD (tail)
5220 /* This catches cases like `int foo : 8;'. */
5221 || DECL_MODE (tail) != TYPE_MODE (TREE_TYPE (tail)))
5223 constructor_incremental = 0;
5227 check_init_type_bitfields (TREE_TYPE (tail));
5231 else if (TREE_CODE (type) == ARRAY_TYPE)
5232 check_init_type_bitfields (TREE_TYPE (type));
5235 /* At the end of an implicit or explicit brace level,
5236 finish up that level of constructor.
5237 If we were outputting the elements as they are read, return 0
5238 from inner levels (process_init_element ignores that),
5239 but return error_mark_node from the outermost level
5240 (that's what we want to put in DECL_INITIAL).
5241 Otherwise, return a CONSTRUCTOR expression. */
5244 pop_init_level (implicit)
5247 struct constructor_stack *p;
5249 tree constructor = 0;
5253 /* When we come to an explicit close brace,
5254 pop any inner levels that didn't have explicit braces. */
5255 while (constructor_stack->implicit)
5256 process_init_element (pop_init_level (1));
5259 p = constructor_stack;
5261 if (constructor_type != 0)
5262 size = int_size_in_bytes (constructor_type);
5264 /* Now output all pending elements. */
5265 output_pending_init_elements (1);
5267 #if 0 /* c-parse.in warns about {}. */
5268 /* In ANSI, each brace level must have at least one element. */
5269 if (! implicit && pedantic
5270 && (TREE_CODE (constructor_type) == ARRAY_TYPE
5271 ? integer_zerop (constructor_unfilled_index)
5272 : constructor_unfilled_fields == TYPE_FIELDS (constructor_type)))
5273 pedwarn_init ("empty braces in initializer%s", " for `%s'", NULL);
5276 /* Pad out the end of the structure. */
5278 if (p->replacement_value)
5280 /* If this closes a superfluous brace pair,
5281 just pass out the element between them. */
5282 constructor = p->replacement_value;
5283 /* If this is the top level thing within the initializer,
5284 and it's for a variable, then since we already called
5285 assemble_variable, we must output the value now. */
5286 if (p->next == 0 && constructor_decl != 0
5287 && constructor_incremental)
5289 constructor = digest_init (constructor_type, constructor,
5292 /* If initializing an array of unknown size,
5293 determine the size now. */
5294 if (TREE_CODE (constructor_type) == ARRAY_TYPE
5295 && TYPE_DOMAIN (constructor_type) == 0)
5300 push_obstacks_nochange ();
5301 if (TREE_PERMANENT (constructor_type))
5302 end_temporary_allocation ();
5304 momentary_p = suspend_momentary ();
5306 /* We shouldn't have an incomplete array type within
5308 if (constructor_stack->next)
5312 = complete_array_type (constructor_type,
5317 size = int_size_in_bytes (constructor_type);
5318 resume_momentary (momentary_p);
5322 output_constant (constructor, size);
5325 else if (constructor_type == 0)
5327 else if (TREE_CODE (constructor_type) != RECORD_TYPE
5328 && TREE_CODE (constructor_type) != UNION_TYPE
5329 && TREE_CODE (constructor_type) != ARRAY_TYPE
5330 && ! constructor_incremental)
5332 /* A nonincremental scalar initializer--just return
5333 the element, after verifying there is just one. */
5334 if (constructor_elements == 0)
5336 error_init ("empty scalar initializer%s",
5338 constructor = error_mark_node;
5340 else if (TREE_CHAIN (constructor_elements) != 0)
5342 error_init ("extra elements in scalar initializer%s",
5344 constructor = TREE_VALUE (constructor_elements);
5347 constructor = TREE_VALUE (constructor_elements);
5349 else if (! constructor_incremental)
5351 if (constructor_erroneous)
5352 constructor = error_mark_node;
5355 int momentary = suspend_momentary ();
5357 constructor = build (CONSTRUCTOR, constructor_type, NULL_TREE,
5358 nreverse (constructor_elements));
5359 if (constructor_constant)
5360 TREE_CONSTANT (constructor) = 1;
5361 if (constructor_constant && constructor_simple)
5362 TREE_STATIC (constructor) = 1;
5364 resume_momentary (momentary);
5370 int momentary = suspend_momentary ();
5372 if (TREE_CODE (constructor_type) == RECORD_TYPE
5373 || TREE_CODE (constructor_type) == UNION_TYPE)
5375 /* Find the offset of the end of that field. */
5376 filled = size_binop (CEIL_DIV_EXPR,
5377 constructor_bit_index,
5378 size_int (BITS_PER_UNIT));
5380 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5382 /* If initializing an array of unknown size,
5383 determine the size now. */
5384 if (TREE_CODE (constructor_type) == ARRAY_TYPE
5385 && TYPE_DOMAIN (constructor_type) == 0)
5388 = size_binop (MINUS_EXPR,
5389 constructor_unfilled_index,
5392 push_obstacks_nochange ();
5393 if (TREE_PERMANENT (constructor_type))
5394 end_temporary_allocation ();
5395 maxindex = copy_node (maxindex);
5396 TYPE_DOMAIN (constructor_type) = build_index_type (maxindex);
5397 TREE_TYPE (maxindex) = TYPE_DOMAIN (constructor_type);
5400 && (tree_int_cst_sgn (TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type)))
5402 error_with_decl (constructor_decl,
5403 "zero or negative array size `%s'");
5404 layout_type (constructor_type);
5405 size = int_size_in_bytes (constructor_type);
5409 filled = size_binop (MULT_EXPR, constructor_unfilled_index,
5410 size_in_bytes (TREE_TYPE (constructor_type)));
5416 assemble_zeros (size - TREE_INT_CST_LOW (filled));
5418 resume_momentary (momentary);
5422 constructor_type = p->type;
5423 constructor_fields = p->fields;
5424 constructor_index = p->index;
5425 constructor_range_end = p->range_end;
5426 constructor_max_index = p->max_index;
5427 constructor_unfilled_index = p->unfilled_index;
5428 constructor_unfilled_fields = p->unfilled_fields;
5429 constructor_bit_index = p->bit_index;
5430 constructor_elements = p->elements;
5431 constructor_constant = p->constant;
5432 constructor_simple = p->simple;
5433 constructor_erroneous = p->erroneous;
5434 constructor_pending_elts = p->pending_elts;
5435 constructor_depth = p->depth;
5436 constructor_incremental = p->incremental;
5437 RESTORE_SPELLING_DEPTH (constructor_depth);
5439 constructor_stack = p->next;
5442 if (constructor == 0)
5444 if (constructor_stack == 0)
5445 return error_mark_node;
5451 /* Within an array initializer, specify the next index to be initialized.
5452 FIRST is that index. If LAST is nonzero, then initialize a range
5453 of indices, running from FIRST through LAST. */
5456 set_init_index (first, last)
5459 while ((TREE_CODE (first) == NOP_EXPR
5460 || TREE_CODE (first) == CONVERT_EXPR
5461 || TREE_CODE (first) == NON_LVALUE_EXPR)
5462 && (TYPE_MODE (TREE_TYPE (first))
5463 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (first, 0)))))
5464 (first) = TREE_OPERAND (first, 0);
5466 while ((TREE_CODE (last) == NOP_EXPR
5467 || TREE_CODE (last) == CONVERT_EXPR
5468 || TREE_CODE (last) == NON_LVALUE_EXPR)
5469 && (TYPE_MODE (TREE_TYPE (last))
5470 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (last, 0)))))
5471 (last) = TREE_OPERAND (last, 0);
5473 if (TREE_CODE (first) != INTEGER_CST)
5474 error_init ("nonconstant array index in initializer%s", " for `%s'", NULL);
5475 else if (last != 0 && TREE_CODE (last) != INTEGER_CST)
5476 error_init ("nonconstant array index in initializer%s", " for `%s'", NULL);
5477 else if (tree_int_cst_lt (first, constructor_unfilled_index))
5478 error_init ("duplicate array index in initializer%s", " for `%s'", NULL);
5481 TREE_INT_CST_LOW (constructor_index)
5482 = TREE_INT_CST_LOW (first);
5483 TREE_INT_CST_HIGH (constructor_index)
5484 = TREE_INT_CST_HIGH (first);
5486 if (last != 0 && tree_int_cst_lt (last, first))
5487 error_init ("empty index range in initializer%s", " for `%s'", NULL);
5491 pedwarn ("ANSI C forbids specifying element to initialize");
5492 constructor_range_end = last;
5497 /* Within a struct initializer, specify the next field to be initialized. */
5500 set_init_label (fieldname)
5506 for (tail = TYPE_FIELDS (constructor_type); tail;
5507 tail = TREE_CHAIN (tail))
5509 if (tail == constructor_unfilled_fields)
5511 if (DECL_NAME (tail) == fieldname)
5516 error ("unknown field `%s' specified in initializer",
5517 IDENTIFIER_POINTER (fieldname));
5519 error ("field `%s' already initialized",
5520 IDENTIFIER_POINTER (fieldname));
5523 constructor_fields = tail;
5525 pedwarn ("ANSI C forbids specifying structure member to initialize");
5529 /* "Output" the next constructor element.
5530 At top level, really output it to assembler code now.
5531 Otherwise, collect it in a list from which we will make a CONSTRUCTOR.
5532 TYPE is the data type that the containing data type wants here.
5533 FIELD is the field (a FIELD_DECL) or the index that this element fills.
5535 PENDING if non-nil means output pending elements that belong
5536 right after this element. (PENDING is normally 1;
5537 it is 0 while outputting pending elements, to avoid recursion.) */
5540 output_init_element (value, type, field, pending)
5541 tree value, type, field;
5546 if (TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE
5547 || (TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE
5548 && !(TREE_CODE (value) == STRING_CST
5549 && TREE_CODE (type) == ARRAY_TYPE
5550 && TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE)
5551 && !comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (value)),
5552 TYPE_MAIN_VARIANT (type))))
5553 value = default_conversion (value);
5555 if (value == error_mark_node)
5556 constructor_erroneous = 1;
5557 else if (!TREE_CONSTANT (value))
5558 constructor_constant = 0;
5559 else if (initializer_constant_valid_p (value, TREE_TYPE (value)) == 0)
5560 constructor_simple = 0;
5562 if (require_constant_value && ! TREE_CONSTANT (value))
5564 error_init ("initializer element%s is not constant",
5566 value = error_mark_node;
5568 else if (require_constant_elements
5569 && initializer_constant_valid_p (value, TREE_TYPE (value)) == 0)
5571 error_init ("initializer element%s is not computable at load time",
5573 value = error_mark_node;
5576 /* If this element duplicates one on constructor_pending_elts,
5577 print a message and ignore it. Don't do this when we're
5578 processing elements taken off constructor_pending_elts,
5579 because we'd always get spurious errors. */
5582 if (TREE_CODE (constructor_type) == RECORD_TYPE
5583 || TREE_CODE (constructor_type) == UNION_TYPE)
5585 if (purpose_member (field, constructor_pending_elts))
5587 error_init ("duplicate initializer%s", " for `%s'", NULL);
5591 if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5594 for (tail = constructor_pending_elts; tail;
5595 tail = TREE_CHAIN (tail))
5596 if (TREE_PURPOSE (tail) != 0
5597 && TREE_CODE (TREE_PURPOSE (tail)) == INTEGER_CST
5598 && tree_int_cst_equal (TREE_PURPOSE (tail), constructor_index))
5603 error_init ("duplicate initializer%s", " for `%s'", NULL);
5609 /* If this element doesn't come next in sequence,
5610 put it on constructor_pending_elts. */
5611 if (TREE_CODE (constructor_type) == ARRAY_TYPE
5612 && !tree_int_cst_equal (field, constructor_unfilled_index))
5615 /* The copy_node is needed in case field is actually
5616 constructor_index, which is modified in place. */
5617 constructor_pending_elts
5618 = tree_cons (copy_node (field),
5619 digest_init (type, value, 0, 0),
5620 constructor_pending_elts);
5622 else if (TREE_CODE (constructor_type) == RECORD_TYPE
5623 && field != constructor_unfilled_fields)
5625 /* We do this for records but not for unions. In a union,
5626 no matter which field is specified, it can be initialized
5627 right away since it starts at the beginning of the union. */
5629 constructor_pending_elts
5631 digest_init (type, value, 0, 0),
5632 constructor_pending_elts);
5636 /* Otherwise, output this element either to
5637 constructor_elements or to the assembler file. */
5641 if (! constructor_incremental)
5643 if (field && TREE_CODE (field) == INTEGER_CST)
5644 field = copy_node (field);
5645 constructor_elements
5646 = tree_cons (field, digest_init (type, value, 0, 0),
5647 constructor_elements);
5651 /* Structure elements may require alignment.
5652 Do this, if necessary. */
5653 if (TREE_CODE (constructor_type) == RECORD_TYPE)
5655 /* Advance to offset of this element. */
5656 if (! tree_int_cst_equal (constructor_bit_index,
5657 DECL_FIELD_BITPOS (field)))
5659 int next = (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
5661 int here = (TREE_INT_CST_LOW (constructor_bit_index)
5664 assemble_zeros (next - here);
5667 output_constant (digest_init (type, value, 0, 0),
5668 int_size_in_bytes (type));
5670 /* For a record or union,
5671 keep track of end position of last field. */
5672 if (TREE_CODE (constructor_type) == RECORD_TYPE
5673 || TREE_CODE (constructor_type) == UNION_TYPE)
5675 tree temp = size_binop (PLUS_EXPR, DECL_FIELD_BITPOS (field),
5677 TREE_INT_CST_LOW (constructor_bit_index)
5678 = TREE_INT_CST_LOW (temp);
5679 TREE_INT_CST_HIGH (constructor_bit_index)
5680 = TREE_INT_CST_HIGH (temp);
5685 /* Advance the variable that indicates sequential elements output. */
5686 if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5688 tree tem = size_binop (PLUS_EXPR, constructor_unfilled_index,
5690 TREE_INT_CST_LOW (constructor_unfilled_index)
5691 = TREE_INT_CST_LOW (tem);
5692 TREE_INT_CST_HIGH (constructor_unfilled_index)
5693 = TREE_INT_CST_HIGH (tem);
5695 else if (TREE_CODE (constructor_type) == RECORD_TYPE)
5696 constructor_unfilled_fields = TREE_CHAIN (constructor_unfilled_fields);
5697 else if (TREE_CODE (constructor_type) == UNION_TYPE)
5698 constructor_unfilled_fields = 0;
5700 /* Now output any pending elements which have become next. */
5702 output_pending_init_elements (0);
5706 /* Output any pending elements which have become next.
5707 As we output elements, constructor_unfilled_{fields,index}
5708 advances, which may cause other elements to become next;
5709 if so, they too are output.
5711 If ALL is 0, we return when there are
5712 no more pending elements to output now.
5714 If ALL is 1, we output space as necessary so that
5715 we can output all the pending elements. */
5718 output_pending_init_elements (all)
5726 /* Look thru the whole pending list.
5727 If we find an element that should be output now,
5728 output it. Otherwise, set NEXT to the element
5729 that comes first among those still pending. */
5732 for (tail = constructor_pending_elts; tail;
5733 tail = TREE_CHAIN (tail))
5735 if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5737 if (tree_int_cst_equal (TREE_PURPOSE (tail),
5738 constructor_unfilled_index))
5740 output_init_element (TREE_VALUE (tail),
5741 TREE_TYPE (constructor_type),
5742 constructor_unfilled_index, 0);
5745 else if (tree_int_cst_lt (TREE_PURPOSE (tail),
5746 constructor_unfilled_index))
5749 || tree_int_cst_lt (TREE_PURPOSE (tail), next))
5750 next = TREE_PURPOSE (tail);
5752 else if (TREE_CODE (constructor_type) == RECORD_TYPE
5753 || TREE_CODE (constructor_type) == UNION_TYPE)
5755 if (TREE_PURPOSE (tail) == constructor_unfilled_fields)
5757 output_init_element (TREE_VALUE (tail),
5758 TREE_TYPE (constructor_unfilled_fields),
5759 constructor_unfilled_fields,
5763 else if (constructor_unfilled_fields == 0
5764 || tree_int_cst_lt (DECL_FIELD_BITPOS (TREE_PURPOSE (tail)),
5765 DECL_FIELD_BITPOS (constructor_unfilled_fields)))
5768 || tree_int_cst_lt (DECL_FIELD_BITPOS (TREE_PURPOSE (tail)),
5769 DECL_FIELD_BITPOS (next)))
5770 next = TREE_PURPOSE (tail);
5774 /* Ordinarily return, but not if we want to output all
5775 and there are elements left. */
5776 if (! (all && next != 0))
5779 /* Generate space up to the position of NEXT. */
5780 if (constructor_incremental)
5783 tree nextpos_tree = size_int (0);
5785 if (TREE_CODE (constructor_type) == RECORD_TYPE
5786 || TREE_CODE (constructor_type) == UNION_TYPE)
5788 /* Find the last field written out, if any. */
5789 for (tail = TYPE_FIELDS (constructor_type); tail;
5790 tail = TREE_CHAIN (tail))
5791 if (TREE_CHAIN (tail) == constructor_unfilled_fields)
5795 /* Find the offset of the end of that field. */
5796 filled = size_binop (CEIL_DIV_EXPR,
5797 size_binop (PLUS_EXPR,
5798 DECL_FIELD_BITPOS (tail),
5800 size_int (BITS_PER_UNIT));
5802 filled = size_int (0);
5804 nextpos_tree = size_binop (CEIL_DIV_EXPR,
5805 DECL_FIELD_BITPOS (next),
5806 size_int (BITS_PER_UNIT));
5808 TREE_INT_CST_HIGH (constructor_bit_index)
5809 = TREE_INT_CST_HIGH (DECL_FIELD_BITPOS (next));
5810 TREE_INT_CST_LOW (constructor_bit_index)
5811 = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (next));
5812 constructor_unfilled_fields = next;
5814 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5816 filled = size_binop (MULT_EXPR, constructor_unfilled_index,
5817 size_in_bytes (TREE_TYPE (constructor_type)));
5819 = size_binop (MULT_EXPR, next,
5820 size_in_bytes (TREE_TYPE (constructor_type)));
5821 TREE_INT_CST_LOW (constructor_unfilled_index)
5822 = TREE_INT_CST_LOW (next);
5823 TREE_INT_CST_HIGH (constructor_unfilled_index)
5824 = TREE_INT_CST_HIGH (next);
5831 int nextpos = TREE_INT_CST_LOW (nextpos_tree);
5833 assemble_zeros (nextpos - TREE_INT_CST_LOW (filled));
5838 /* If it's not incremental, just skip over the gap,
5839 so that after jumping to retry we will output the next
5840 successive element. */
5841 if (TREE_CODE (constructor_type) == RECORD_TYPE
5842 || TREE_CODE (constructor_type) == UNION_TYPE)
5843 constructor_unfilled_fields = next;
5844 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5846 TREE_INT_CST_LOW (constructor_unfilled_index)
5847 = TREE_INT_CST_LOW (next);
5848 TREE_INT_CST_HIGH (constructor_unfilled_index)
5849 = TREE_INT_CST_HIGH (next);
5856 /* Add one non-braced element to the current constructor level.
5857 This adjusts the current position within the constructor's type.
5858 This may also start or terminate implicit levels
5859 to handle a partly-braced initializer.
5861 Once this has found the correct level for the new element,
5862 it calls output_init_element.
5864 Note: if we are incrementally outputting this constructor,
5865 this function may be called with a null argument
5866 representing a sub-constructor that was already incrementally output.
5867 When that happens, we output nothing, but we do the bookkeeping
5868 to skip past that element of the current constructor. */
5871 process_init_element (value)
5874 tree orig_value = value;
5875 int string_flag = value != 0 && TREE_CODE (value) == STRING_CST;
5877 /* Handle superfluous braces around string cst as in
5878 char x[] = {"foo"}; */
5881 && TREE_CODE (constructor_type) == ARRAY_TYPE
5882 && TREE_CODE (TREE_TYPE (constructor_type)) == INTEGER_TYPE
5883 && integer_zerop (constructor_unfilled_index))
5885 constructor_stack->replacement_value = value;
5889 if (constructor_stack->replacement_value != 0)
5891 error_init ("excess elements in struct initializer%s",
5892 " after `%s'", NULL_PTR);
5896 /* Ignore elements of a brace group if it is entirely superfluous
5897 and has already been diagnosed. */
5898 if (constructor_type == 0)
5901 /* If we've exhausted any levels that didn't have braces,
5903 while (constructor_stack->implicit)
5905 if ((TREE_CODE (constructor_type) == RECORD_TYPE
5906 || TREE_CODE (constructor_type) == UNION_TYPE)
5907 && constructor_fields == 0)
5908 process_init_element (pop_init_level (1));
5909 else if (TREE_CODE (constructor_type) == ARRAY_TYPE
5910 && tree_int_cst_lt (constructor_max_index, constructor_index))
5911 process_init_element (pop_init_level (1));
5918 if (TREE_CODE (constructor_type) == RECORD_TYPE)
5921 enum tree_code fieldcode;
5923 if (constructor_fields == 0)
5925 pedwarn_init ("excess elements in struct initializer%s",
5926 " after `%s'", NULL_PTR);
5930 fieldtype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_fields));
5931 fieldcode = TREE_CODE (fieldtype);
5933 /* Accept a string constant to initialize a subarray. */
5935 && fieldcode == ARRAY_TYPE
5936 && TREE_CODE (TREE_TYPE (fieldtype)) == INTEGER_TYPE
5939 /* Otherwise, if we have come to a subaggregate,
5940 and we don't have an element of its type, push into it. */
5941 else if (value != 0 && !constructor_no_implicit
5942 && TYPE_MAIN_VARIANT (TREE_TYPE (value)) != fieldtype
5943 && (fieldcode == RECORD_TYPE || fieldcode == ARRAY_TYPE
5944 || fieldcode == UNION_TYPE))
5946 push_init_level (1);
5952 push_member_name (constructor_fields);
5953 output_init_element (value, fieldtype, constructor_fields, 1);
5954 RESTORE_SPELLING_DEPTH (constructor_depth);
5957 /* Do the bookkeeping for an element that was
5958 directly output as a constructor. */
5960 /* For a record, keep track of end position of last field. */
5961 tree temp = size_binop (PLUS_EXPR,
5962 DECL_FIELD_BITPOS (constructor_fields),
5963 DECL_SIZE (constructor_fields));
5964 TREE_INT_CST_LOW (constructor_bit_index)
5965 = TREE_INT_CST_LOW (temp);
5966 TREE_INT_CST_HIGH (constructor_bit_index)
5967 = TREE_INT_CST_HIGH (temp);
5969 constructor_unfilled_fields = TREE_CHAIN (constructor_fields);
5972 constructor_fields = TREE_CHAIN (constructor_fields);
5973 /* Skip any nameless bit fields atthe beginning. */
5974 while (constructor_fields != 0 && DECL_BIT_FIELD (constructor_fields)
5975 && DECL_NAME (constructor_fields) == 0)
5976 constructor_fields = TREE_CHAIN (constructor_fields);
5979 if (TREE_CODE (constructor_type) == UNION_TYPE)
5982 enum tree_code fieldcode;
5984 if (constructor_fields == 0)
5986 pedwarn_init ("excess elements in union initializer%s",
5987 " after `%s'", NULL_PTR);
5991 fieldtype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_fields));
5992 fieldcode = TREE_CODE (fieldtype);
5994 /* Accept a string constant to initialize a subarray. */
5996 && fieldcode == ARRAY_TYPE
5997 && TREE_CODE (TREE_TYPE (fieldtype)) == INTEGER_TYPE
6000 /* Otherwise, if we have come to a subaggregate,
6001 and we don't have an element of its type, push into it. */
6002 else if (value != 0 && !constructor_no_implicit
6003 && TYPE_MAIN_VARIANT (TREE_TYPE (value)) != fieldtype
6004 && (fieldcode == RECORD_TYPE || fieldcode == ARRAY_TYPE
6005 || fieldcode == UNION_TYPE))
6007 push_init_level (1);
6013 push_member_name (constructor_fields);
6014 output_init_element (value, fieldtype, constructor_fields, 1);
6015 RESTORE_SPELLING_DEPTH (constructor_depth);
6018 /* Do the bookkeeping for an element that was
6019 directly output as a constructor. */
6021 TREE_INT_CST_LOW (constructor_bit_index)
6022 = TREE_INT_CST_LOW (DECL_SIZE (constructor_fields));
6023 TREE_INT_CST_HIGH (constructor_bit_index)
6024 = TREE_INT_CST_HIGH (DECL_SIZE (constructor_fields));
6026 constructor_unfilled_fields = TREE_CHAIN (constructor_fields);
6029 constructor_fields = 0;
6032 if (TREE_CODE (constructor_type) == ARRAY_TYPE)
6034 tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
6035 enum tree_code eltcode = TREE_CODE (elttype);
6037 /* Accept a string constant to initialize a subarray. */
6039 && eltcode == ARRAY_TYPE
6040 && TREE_CODE (TREE_TYPE (elttype)) == INTEGER_TYPE
6043 /* Otherwise, if we have come to a subaggregate,
6044 and we don't have an element of its type, push into it. */
6045 else if (value != 0 && !constructor_no_implicit
6046 && TYPE_MAIN_VARIANT (TREE_TYPE (value)) != elttype
6047 && (eltcode == RECORD_TYPE || eltcode == ARRAY_TYPE
6048 || eltcode == UNION_TYPE))
6050 push_init_level (1);
6054 if (constructor_max_index != 0
6055 && tree_int_cst_lt (constructor_max_index, constructor_index))
6057 pedwarn_init ("excess elements in array initializer%s",
6058 " after `%s'", NULL_PTR);
6062 /* Now output the actual element.
6063 Ordinarily, output once.
6064 If there is a range, repeat it till we advance past the range. */
6071 push_array_bounds (TREE_INT_CST_LOW (constructor_index));
6072 output_init_element (value, elttype, constructor_index, 1);
6073 RESTORE_SPELLING_DEPTH (constructor_depth);
6076 tem = size_binop (PLUS_EXPR, constructor_index,
6078 TREE_INT_CST_LOW (constructor_index)
6079 = TREE_INT_CST_LOW (tem);
6080 TREE_INT_CST_HIGH (constructor_index)
6081 = TREE_INT_CST_HIGH (tem);
6084 /* If we are doing the bookkeeping for an element that was
6085 directly output as a constructor,
6086 we must update constructor_unfilled_index. */
6088 TREE_INT_CST_LOW (constructor_unfilled_index)
6089 = TREE_INT_CST_LOW (constructor_index);
6090 TREE_INT_CST_HIGH (constructor_unfilled_index)
6091 = TREE_INT_CST_HIGH (constructor_index);
6094 while (! (constructor_range_end == 0
6095 || tree_int_cst_lt (constructor_range_end,
6096 constructor_index)));
6101 /* Handle the sole element allowed in a braced initializer
6102 for a scalar variable. */
6103 if (constructor_fields == 0)
6105 pedwarn_init ("excess elements in scalar initializer%s",
6106 " after `%s'", NULL_PTR);
6111 output_init_element (value, constructor_type, NULL_TREE, 1);
6112 constructor_fields = 0;
6116 /* If the (lexically) previous elments are not now saved,
6117 we can discard the storage for them. */
6118 if (constructor_incremental && constructor_pending_elts == 0 && value != 0)
6122 /* Expand an ASM statement with operands, handling output operands
6123 that are not variables or INDIRECT_REFS by transforming such
6124 cases into cases that expand_asm_operands can handle.
6126 Arguments are same as for expand_asm_operands. */
6129 c_expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line)
6130 tree string, outputs, inputs, clobbers;
6135 int noutputs = list_length (outputs);
6137 /* o[I] is the place that output number I should be written. */
6138 register tree *o = (tree *) alloca (noutputs * sizeof (tree));
6141 if (TREE_CODE (string) == ADDR_EXPR)
6142 string = TREE_OPERAND (string, 0);
6143 if (TREE_CODE (string) != STRING_CST)
6145 error ("asm template is not a string constant");
6149 /* Record the contents of OUTPUTS before it is modified. */
6150 for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
6151 o[i] = TREE_VALUE (tail);
6153 /* Perform default conversions on array and function inputs. */
6154 /* Don't do this for other types--
6155 it would screw up operands expected to be in memory. */
6156 for (i = 0, tail = inputs; tail; tail = TREE_CHAIN (tail), i++)
6157 if (TREE_CODE (TREE_TYPE (TREE_VALUE (tail))) == ARRAY_TYPE
6158 || TREE_CODE (TREE_TYPE (TREE_VALUE (tail))) == FUNCTION_TYPE)
6159 TREE_VALUE (tail) = default_conversion (TREE_VALUE (tail));
6161 /* Generate the ASM_OPERANDS insn;
6162 store into the TREE_VALUEs of OUTPUTS some trees for
6163 where the values were actually stored. */
6164 expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line);
6166 /* Copy all the intermediate outputs into the specified outputs. */
6167 for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
6169 if (o[i] != TREE_VALUE (tail))
6171 expand_expr (build_modify_expr (o[i], NOP_EXPR, TREE_VALUE (tail)),
6175 /* Detect modification of read-only values.
6176 (Otherwise done by build_modify_expr.) */
6179 tree type = TREE_TYPE (o[i]);
6180 if (TYPE_READONLY (type)
6181 || ((TREE_CODE (type) == RECORD_TYPE
6182 || TREE_CODE (type) == UNION_TYPE)
6183 && C_TYPE_FIELDS_READONLY (type)))
6184 readonly_warning (o[i], "modification by `asm'");
6188 /* Those MODIFY_EXPRs could do autoincrements. */
6192 /* Expand a C `return' statement.
6193 RETVAL is the expression for what to return,
6194 or a null pointer for `return;' with no value. */
6197 c_expand_return (retval)
6200 tree valtype = TREE_TYPE (TREE_TYPE (current_function_decl));
6202 if (TREE_THIS_VOLATILE (current_function_decl))
6203 warning ("function declared `noreturn' has a `return' statement");
6207 current_function_returns_null = 1;
6208 if (warn_return_type && valtype != 0 && TREE_CODE (valtype) != VOID_TYPE)
6209 warning ("`return' with no value, in function returning non-void");
6210 expand_null_return ();
6212 else if (valtype == 0 || TREE_CODE (valtype) == VOID_TYPE)
6214 current_function_returns_null = 1;
6215 if (pedantic || TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
6216 pedwarn ("`return' with a value, in function returning void");
6217 expand_return (retval);
6221 tree t = convert_for_assignment (valtype, retval, "return",
6222 NULL_TREE, NULL_TREE, 0);
6223 tree res = DECL_RESULT (current_function_decl);
6226 if (t == error_mark_node)
6229 inner = t = convert (TREE_TYPE (res), t);
6231 /* Strip any conversions, additions, and subtractions, and see if
6232 we are returning the address of a local variable. Warn if so. */
6233 while (TREE_CODE (inner) == NOP_EXPR
6234 || TREE_CODE (inner) == NON_LVALUE_EXPR
6235 || TREE_CODE (inner) == CONVERT_EXPR
6236 || TREE_CODE (inner) == PLUS_EXPR
6237 || TREE_CODE (inner) == MINUS_EXPR)
6238 inner = TREE_OPERAND (inner, 0);
6240 if (TREE_CODE (inner) == ADDR_EXPR)
6242 inner = TREE_OPERAND (inner, 0);
6244 while (TREE_CODE_CLASS (TREE_CODE (inner)) == 'r')
6245 inner = TREE_OPERAND (inner, 0);
6247 if (TREE_CODE (inner) == VAR_DECL
6248 && ! DECL_EXTERNAL (inner)
6249 && ! TREE_STATIC (inner)
6250 && DECL_CONTEXT (inner) == current_function_decl)
6251 warning ("function returns address of local variable");
6254 t = build (MODIFY_EXPR, TREE_TYPE (res), res, t);
6255 TREE_SIDE_EFFECTS (t) = 1;
6257 current_function_returns_value = 1;
6261 /* Start a C switch statement, testing expression EXP.
6262 Return EXP if it is valid, an error node otherwise. */
6265 c_expand_start_case (exp)
6268 register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
6269 tree type = TREE_TYPE (exp);
6271 if (code != INTEGER_TYPE && code != ENUMERAL_TYPE && code != ERROR_MARK)
6273 error ("switch quantity not an integer");
6274 exp = error_mark_node;
6279 type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
6281 if (warn_traditional
6282 && (type == long_integer_type_node
6283 || type == long_unsigned_type_node))
6284 pedwarn ("`long' switch expression not converted to `int' in ANSI C");
6286 exp = default_conversion (exp);
6287 type = TREE_TYPE (exp);
6288 index = get_unwidened (exp, NULL_TREE);
6289 /* We can't strip a conversion from a signed type to an unsigned,
6290 because if we did, int_fits_type_p would do the wrong thing
6291 when checking case values for being in range,
6292 and it's too hard to do the right thing. */
6293 if (TREE_UNSIGNED (TREE_TYPE (exp))
6294 == TREE_UNSIGNED (TREE_TYPE (index)))
6298 expand_start_case (1, exp, type, "switch statement");