1 /* Build expressions with type checking for C compiler.
2 Copyright (C) 1987, 1988, 1989, 1992 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 "partly bracketed initializer"
37 message within this initializer. */
38 static int partial_bracket_mentioned = 0;
40 extern char *index ();
41 extern char *rindex ();
43 int mark_addressable ();
44 static tree convert_for_assignment ();
45 static void warn_for_assignment ();
46 static int function_types_compatible_p ();
47 static int type_lists_compatible_p ();
48 int self_promoting_args_p ();
49 static int self_promoting_type_p ();
50 static int comp_target_types ();
51 static tree pointer_int_sum ();
52 static tree pointer_diff ();
53 static tree convert_sequence ();
54 static tree unary_complex_lvalue ();
55 static tree process_init_constructor ();
56 static tree convert_arguments ();
57 static char *get_spelling ();
58 static tree digest_init ();
59 static void pedantic_lvalue_warning ();
60 tree truthvalue_conversion ();
61 void incomplete_type_error ();
62 void readonly_warning ();
63 static tree internal_build_compound_expr ();
65 void process_init_element ();
67 /* Do `exp = require_complete_type (exp);' to make sure exp
68 does not have an incomplete type. (That includes void types.) */
71 require_complete_type (value)
74 tree type = TREE_TYPE (value);
76 /* First, detect a valid value with a complete type. */
77 if (TYPE_SIZE (type) != 0
78 && type != void_type_node)
81 incomplete_type_error (value, type);
82 return error_mark_node;
85 /* Print an error message for invalid use of an incomplete type.
86 VALUE is the expression that was used (or 0 if that isn't known)
87 and TYPE is the type that was invalid. */
90 incomplete_type_error (value, type)
96 /* Avoid duplicate error message. */
97 if (TREE_CODE (type) == ERROR_MARK)
100 if (value != 0 && (TREE_CODE (value) == VAR_DECL
101 || TREE_CODE (value) == PARM_DECL))
102 error ("`%s' has an incomplete type",
103 IDENTIFIER_POINTER (DECL_NAME (value)));
107 /* We must print an error message. Be clever about what it says. */
109 switch (TREE_CODE (type))
112 errmsg = "invalid use of undefined type `struct %s'";
116 errmsg = "invalid use of undefined type `union %s'";
120 errmsg = "invalid use of undefined type `enum %s'";
124 error ("invalid use of void expression");
128 if (TYPE_DOMAIN (type))
130 type = TREE_TYPE (type);
133 error ("invalid use of array with unspecified bounds");
140 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
141 error (errmsg, IDENTIFIER_POINTER (TYPE_NAME (type)));
143 /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL. */
144 error ("invalid use of incomplete typedef `%s'",
145 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))));
149 /* Return a variant of TYPE which has all the type qualifiers of LIKE
150 as well as those of TYPE. */
153 qualify_type (type, like)
156 int constflag = TYPE_READONLY (type) || TYPE_READONLY (like);
157 int volflag = TYPE_VOLATILE (type) || TYPE_VOLATILE (like);
158 return c_build_type_variant (type, constflag, volflag);
161 /* Return the common type of two types.
162 We assume that comptypes has already been done and returned 1;
163 if that isn't so, this may crash. In particular, we assume that qualifiers
166 This is the type for the result of most arithmetic operations
167 if the operands have the given two types. */
173 register enum tree_code code1;
174 register enum tree_code code2;
176 /* Save time if the two types are the same. */
178 if (t1 == t2) return t1;
180 /* If one type is nonsense, use the other. */
181 if (t1 == error_mark_node)
183 if (t2 == error_mark_node)
186 /* Treat an enum type as the unsigned integer type of the same width. */
188 if (TREE_CODE (t1) == ENUMERAL_TYPE)
189 t1 = type_for_size (TYPE_PRECISION (t1), 1);
190 if (TREE_CODE (t2) == ENUMERAL_TYPE)
191 t2 = type_for_size (TYPE_PRECISION (t2), 1);
193 code1 = TREE_CODE (t1);
194 code2 = TREE_CODE (t2);
196 /* If one type is complex, form the common type
197 of the non-complex components,
198 then make that complex. */
199 if (code1 == COMPLEX_TYPE || code2 == COMPLEX_TYPE)
201 tree subtype1, subtype2, subtype;
202 if (code1 == COMPLEX_TYPE)
203 subtype1 = TREE_TYPE (t1);
206 if (code2 == COMPLEX_TYPE)
207 subtype2 = TREE_TYPE (t2);
210 subtype = common_type (subtype1, subtype2);
211 return build_complex_type (subtype);
218 /* If only one is real, use it as the result. */
220 if (code1 == REAL_TYPE && code2 != REAL_TYPE)
223 if (code2 == REAL_TYPE && code1 != REAL_TYPE)
226 /* Both real or both integers; use the one with greater precision. */
228 if (TYPE_PRECISION (t1) > TYPE_PRECISION (t2))
230 else if (TYPE_PRECISION (t2) > TYPE_PRECISION (t1))
233 /* Same precision. Prefer longs to ints even when same size. */
235 if (TYPE_MAIN_VARIANT (t1) == long_unsigned_type_node
236 || TYPE_MAIN_VARIANT (t2) == long_unsigned_type_node)
237 return long_unsigned_type_node;
239 if (TYPE_MAIN_VARIANT (t1) == long_integer_type_node
240 || TYPE_MAIN_VARIANT (t2) == long_integer_type_node)
242 /* But preserve unsignedness from the other type,
243 since long cannot hold all the values of an unsigned int. */
244 if (TREE_UNSIGNED (t1) || TREE_UNSIGNED (t2))
245 return long_unsigned_type_node;
246 return long_integer_type_node;
249 /* Otherwise prefer the unsigned one. */
251 if (TREE_UNSIGNED (t1))
256 /* For two pointers, do this recursively on the target type,
257 and combine the qualifiers of the two types' targets. */
258 /* This code was turned off; I don't know why.
259 But ANSI C specifies doing this with the qualifiers.
260 So I turned it on again. */
262 tree target = common_type (TYPE_MAIN_VARIANT (TREE_TYPE (t1)),
263 TYPE_MAIN_VARIANT (TREE_TYPE (t2)));
265 = TYPE_READONLY (TREE_TYPE (t1)) || TYPE_READONLY (TREE_TYPE (t2));
267 = TYPE_VOLATILE (TREE_TYPE (t1)) || TYPE_VOLATILE (TREE_TYPE (t2));
268 return build_pointer_type (c_build_type_variant (target, constp, volatilep));
271 return build_pointer_type (common_type (TREE_TYPE (t1), TREE_TYPE (t2)));
276 tree elt = common_type (TREE_TYPE (t1), TREE_TYPE (t2));
277 /* Save space: see if the result is identical to one of the args. */
278 if (elt == TREE_TYPE (t1) && TYPE_DOMAIN (t1))
280 if (elt == TREE_TYPE (t2) && TYPE_DOMAIN (t2))
282 /* Merge the element types, and have a size if either arg has one. */
283 return build_array_type (elt, TYPE_DOMAIN (TYPE_DOMAIN (t1) ? t1 : t2));
287 /* Function types: prefer the one that specified arg types.
288 If both do, merge the arg types. Also merge the return types. */
290 tree valtype = common_type (TREE_TYPE (t1), TREE_TYPE (t2));
291 tree p1 = TYPE_ARG_TYPES (t1);
292 tree p2 = TYPE_ARG_TYPES (t2);
297 /* Save space: see if the result is identical to one of the args. */
298 if (valtype == TREE_TYPE (t1) && ! TYPE_ARG_TYPES (t2))
300 if (valtype == TREE_TYPE (t2) && ! TYPE_ARG_TYPES (t1))
303 /* Simple way if one arg fails to specify argument types. */
304 if (TYPE_ARG_TYPES (t1) == 0)
305 return build_function_type (valtype, TYPE_ARG_TYPES (t2));
306 if (TYPE_ARG_TYPES (t2) == 0)
307 return build_function_type (valtype, TYPE_ARG_TYPES (t1));
309 /* If both args specify argument types, we must merge the two
310 lists, argument by argument. */
312 len = list_length (p1);
315 for (i = 0; i < len; i++)
316 newargs = tree_cons (NULL_TREE, NULL_TREE, newargs);
321 p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2), n = TREE_CHAIN (n))
323 /* A null type means arg type is not specified.
324 Take whatever the other function type has. */
325 if (TREE_VALUE (p1) == 0)
327 TREE_VALUE (n) = TREE_VALUE (p2);
330 if (TREE_VALUE (p2) == 0)
332 TREE_VALUE (n) = TREE_VALUE (p1);
336 /* Given wait (union {union wait *u; int *i} *)
337 and wait (union wait *),
338 prefer union wait * as type of parm. */
339 if (TREE_CODE (TREE_VALUE (p1)) == UNION_TYPE
340 && TREE_VALUE (p1) != TREE_VALUE (p2))
343 for (memb = TYPE_FIELDS (TREE_VALUE (p1));
344 memb; memb = TREE_CHAIN (memb))
345 if (comptypes (TREE_TYPE (memb), TREE_VALUE (p2)))
347 TREE_VALUE (n) = TREE_VALUE (p2);
349 pedwarn ("function types not truly compatible in ANSI C");
353 if (TREE_CODE (TREE_VALUE (p2)) == UNION_TYPE
354 && TREE_VALUE (p2) != TREE_VALUE (p1))
357 for (memb = TYPE_FIELDS (TREE_VALUE (p2));
358 memb; memb = TREE_CHAIN (memb))
359 if (comptypes (TREE_TYPE (memb), TREE_VALUE (p1)))
361 TREE_VALUE (n) = TREE_VALUE (p1);
363 pedwarn ("function types not truly compatible in ANSI C");
367 TREE_VALUE (n) = common_type (TREE_VALUE (p1), TREE_VALUE (p2));
371 return build_function_type (valtype, newargs);
380 /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
381 or various other operations. Return 2 if they are compatible
382 but a warning may be needed if you use them together. */
385 comptypes (type1, type2)
388 register tree t1 = type1;
389 register tree t2 = type2;
391 /* Suppress errors caused by previously reported errors. */
393 if (t1 == t2 || TREE_CODE (t1) == ERROR_MARK || TREE_CODE (t2) == ERROR_MARK)
396 /* Treat an enum type as the unsigned integer type of the same width. */
398 if (TREE_CODE (t1) == ENUMERAL_TYPE)
399 t1 = type_for_size (TYPE_PRECISION (t1), 1);
400 if (TREE_CODE (t2) == ENUMERAL_TYPE)
401 t2 = type_for_size (TYPE_PRECISION (t2), 1);
406 /* Different classes of types can't be compatible. */
408 if (TREE_CODE (t1) != TREE_CODE (t2)) return 0;
410 /* Qualifiers must match. */
412 if (TYPE_READONLY (t1) != TYPE_READONLY (t2))
414 if (TYPE_VOLATILE (t1) != TYPE_VOLATILE (t2))
417 /* Allow for two different type nodes which have essentially the same
418 definition. Note that we already checked for equality of the type
419 type qualifiers (just above). */
421 if (TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
424 switch (TREE_CODE (t1))
427 return (TREE_TYPE (t1) == TREE_TYPE (t2)
428 ? 1 : comptypes (TREE_TYPE (t1), TREE_TYPE (t2)));
431 return function_types_compatible_p (t1, t2);
435 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
437 tree d1 = TYPE_DOMAIN (t1);
438 tree d2 = TYPE_DOMAIN (t2);
440 /* Target types must match incl. qualifiers. */
441 if (TREE_TYPE (t1) != TREE_TYPE (t2)
442 && 0 == (val = comptypes (TREE_TYPE (t1), TREE_TYPE (t2))))
445 /* Sizes must match unless one is missing or variable. */
446 if (d1 == 0 || d2 == 0 || d1 == d2
447 || TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST
448 || TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST
449 || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST
450 || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST)
453 return (((TREE_INT_CST_LOW (TYPE_MIN_VALUE (d1))
454 == TREE_INT_CST_LOW (TYPE_MIN_VALUE (d2)))
455 && (TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d1))
456 == TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d2)))
457 && (TREE_INT_CST_LOW (TYPE_MAX_VALUE (d1))
458 == TREE_INT_CST_LOW (TYPE_MAX_VALUE (d2)))
459 && (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d1))
460 == TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d2))))
465 if (maybe_objc_comptypes (t1, t2, 0) == 1)
471 /* Return 1 if TTL and TTR are pointers to types that are equivalent,
472 ignoring their qualifiers. */
475 comp_target_types (ttl, ttr)
480 /* Give maybe_objc_comptypes a crack at letting these types through. */
481 if (val = maybe_objc_comptypes (ttl, ttr, 1) >= 0)
484 val = comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (ttl)),
485 TYPE_MAIN_VARIANT (TREE_TYPE (ttr)));
487 if (val == 2 && pedantic)
488 pedwarn ("types are not quite compatible");
492 /* Subroutines of `comptypes'. */
494 /* Return 1 if two function types F1 and F2 are compatible.
495 If either type specifies no argument types,
496 the other must specify a fixed number of self-promoting arg types.
497 Otherwise, if one type specifies only the number of arguments,
498 the other must specify that number of self-promoting arg types.
499 Otherwise, the argument types must match. */
502 function_types_compatible_p (f1, f2)
506 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
510 if (!(TREE_TYPE (f1) == TREE_TYPE (f2)
511 || (val = comptypes (TREE_TYPE (f1), TREE_TYPE (f2)))))
514 args1 = TYPE_ARG_TYPES (f1);
515 args2 = TYPE_ARG_TYPES (f2);
517 /* An unspecified parmlist matches any specified parmlist
518 whose argument types don't need default promotions. */
522 if (!self_promoting_args_p (args2))
524 /* If one of these types comes from a non-prototype fn definition,
525 compare that with the other type's arglist.
526 If they don't match, ask for a warning (but no error). */
527 if (TYPE_ACTUAL_ARG_TYPES (f1)
528 && 1 != type_lists_compatible_p (args2, TYPE_ACTUAL_ARG_TYPES (f1)))
534 if (!self_promoting_args_p (args1))
536 if (TYPE_ACTUAL_ARG_TYPES (f2)
537 && 1 != type_lists_compatible_p (args1, TYPE_ACTUAL_ARG_TYPES (f2)))
542 /* Both types have argument lists: compare them and propagate results. */
543 val1 = type_lists_compatible_p (args1, args2);
544 return val1 != 1 ? val1 : val;
547 /* Check two lists of types for compatibility,
548 returning 0 for incompatible, 1 for compatible,
549 or 2 for compatible with warning. */
552 type_lists_compatible_p (args1, args2)
555 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
561 if (args1 == 0 && args2 == 0)
563 /* If one list is shorter than the other,
564 they fail to match. */
565 if (args1 == 0 || args2 == 0)
567 /* A null pointer instead of a type
568 means there is supposed to be an argument
569 but nothing is specified about what type it has.
570 So match anything that self-promotes. */
571 if (TREE_VALUE (args1) == 0)
573 if (! self_promoting_type_p (TREE_VALUE (args2)))
576 else if (TREE_VALUE (args2) == 0)
578 if (! self_promoting_type_p (TREE_VALUE (args1)))
581 else if (! (newval = comptypes (TREE_VALUE (args1), TREE_VALUE (args2))))
583 /* Allow wait (union {union wait *u; int *i} *)
584 and wait (union wait *) to be compatible. */
585 if (TREE_CODE (TREE_VALUE (args1)) == UNION_TYPE
586 && TYPE_NAME (TREE_VALUE (args1)) == 0
587 && TREE_CODE (TYPE_SIZE (TREE_VALUE (args1))) == INTEGER_CST
588 && tree_int_cst_equal (TYPE_SIZE (TREE_VALUE (args1)),
589 TYPE_SIZE (TREE_VALUE (args2))))
592 for (memb = TYPE_FIELDS (TREE_VALUE (args1));
593 memb; memb = TREE_CHAIN (memb))
594 if (comptypes (TREE_TYPE (memb), TREE_VALUE (args2)))
599 else if (TREE_CODE (TREE_VALUE (args2)) == UNION_TYPE
600 && TYPE_NAME (TREE_VALUE (args2)) == 0
601 && TREE_CODE (TYPE_SIZE (TREE_VALUE (args2))) == INTEGER_CST
602 && tree_int_cst_equal (TYPE_SIZE (TREE_VALUE (args2)),
603 TYPE_SIZE (TREE_VALUE (args1))))
606 for (memb = TYPE_FIELDS (TREE_VALUE (args2));
607 memb; memb = TREE_CHAIN (memb))
608 if (comptypes (TREE_TYPE (memb), TREE_VALUE (args1)))
617 /* comptypes said ok, but record if it said to warn. */
621 args1 = TREE_CHAIN (args1);
622 args2 = TREE_CHAIN (args2);
626 /* Return 1 if PARMS specifies a fixed number of parameters
627 and none of their types is affected by default promotions. */
630 self_promoting_args_p (parms)
634 for (t = parms; t; t = TREE_CHAIN (t))
636 register tree type = TREE_VALUE (t);
638 if (TREE_CHAIN (t) == 0 && type != void_type_node)
644 if (TYPE_MAIN_VARIANT (type) == float_type_node)
647 if (C_PROMOTING_INTEGER_TYPE_P (type))
653 /* Return 1 if TYPE is not affected by default promotions. */
656 self_promoting_type_p (type)
659 if (TYPE_MAIN_VARIANT (type) == float_type_node)
662 if (C_PROMOTING_INTEGER_TYPE_P (type))
668 /* Return an unsigned type the same as TYPE in other respects. */
674 tree type1 = TYPE_MAIN_VARIANT (type);
675 if (type1 == signed_char_type_node || type1 == char_type_node)
676 return unsigned_char_type_node;
677 if (type1 == integer_type_node)
678 return unsigned_type_node;
679 if (type1 == short_integer_type_node)
680 return short_unsigned_type_node;
681 if (type1 == long_integer_type_node)
682 return long_unsigned_type_node;
683 if (type1 == long_long_integer_type_node)
684 return long_long_unsigned_type_node;
688 /* Return a signed type the same as TYPE in other respects. */
694 tree type1 = TYPE_MAIN_VARIANT (type);
695 if (type1 == unsigned_char_type_node || type1 == char_type_node)
696 return signed_char_type_node;
697 if (type1 == unsigned_type_node)
698 return integer_type_node;
699 if (type1 == short_unsigned_type_node)
700 return short_integer_type_node;
701 if (type1 == long_unsigned_type_node)
702 return long_integer_type_node;
703 if (type1 == long_long_unsigned_type_node)
704 return long_long_integer_type_node;
708 /* Return a type the same as TYPE except unsigned or
709 signed according to UNSIGNEDP. */
712 signed_or_unsigned_type (unsignedp, type)
716 if (TREE_CODE (type) != INTEGER_TYPE)
718 if (TYPE_PRECISION (type) == TYPE_PRECISION (signed_char_type_node))
719 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
720 if (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
721 return unsignedp ? unsigned_type_node : integer_type_node;
722 if (TYPE_PRECISION (type) == TYPE_PRECISION (short_integer_type_node))
723 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
724 if (TYPE_PRECISION (type) == TYPE_PRECISION (long_integer_type_node))
725 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
726 if (TYPE_PRECISION (type) == TYPE_PRECISION (long_long_integer_type_node))
727 return (unsignedp ? long_long_unsigned_type_node
728 : long_long_integer_type_node);
732 /* Compute the value of the `sizeof' operator. */
738 enum tree_code code = TREE_CODE (type);
741 if (code == FUNCTION_TYPE)
743 if (pedantic || warn_pointer_arith)
744 pedwarn ("sizeof applied to a function type");
747 if (code == VOID_TYPE)
749 if (pedantic || warn_pointer_arith)
750 pedwarn ("sizeof applied to a void type");
753 if (code == ERROR_MARK)
755 if (TYPE_SIZE (type) == 0)
757 error ("sizeof applied to an incomplete type");
761 /* Convert in case a char is more than one unit. */
762 t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type),
763 size_int (TYPE_PRECISION (char_type_node)));
764 /* size_binop does not put the constant in range, so do it now. */
765 if (TREE_CODE (t) == INTEGER_CST && force_fit_type (t, 0))
766 TREE_CONSTANT_OVERFLOW (t) = TREE_OVERFLOW (t) = 1;
771 c_sizeof_nowarn (type)
774 enum tree_code code = TREE_CODE (type);
777 if (code == FUNCTION_TYPE
779 || code == ERROR_MARK)
781 if (TYPE_SIZE (type) == 0)
784 /* Convert in case a char is more than one unit. */
785 t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type),
786 size_int (TYPE_PRECISION (char_type_node)));
787 force_fit_type (t, 0);
791 /* Compute the size to increment a pointer by. */
794 c_size_in_bytes (type)
797 enum tree_code code = TREE_CODE (type);
800 if (code == FUNCTION_TYPE)
802 if (code == VOID_TYPE)
804 if (code == ERROR_MARK)
806 if (TYPE_SIZE (type) == 0)
808 error ("arithmetic on pointer to an incomplete type");
812 /* Convert in case a char is more than one unit. */
813 t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type),
814 size_int (BITS_PER_UNIT));
815 force_fit_type (t, 0);
819 /* Implement the __alignof keyword: Return the minimum required
820 alignment of TYPE, measured in bytes. */
826 enum tree_code code = TREE_CODE (type);
828 if (code == FUNCTION_TYPE)
829 return size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
831 if (code == VOID_TYPE || code == ERROR_MARK)
834 return size_int (TYPE_ALIGN (type) / BITS_PER_UNIT);
837 /* Implement the __alignof keyword: Return the minimum required
838 alignment of EXPR, measured in bytes. For VAR_DECL's and
839 FIELD_DECL's return DECL_ALIGN (which can be set from an
840 "aligned" __attribute__ specification). */
843 c_alignof_expr (expr)
846 if (TREE_CODE (expr) == VAR_DECL)
847 return size_int (DECL_ALIGN (expr) / BITS_PER_UNIT);
849 if (TREE_CODE (expr) == COMPONENT_REF
850 && DECL_BIT_FIELD (TREE_OPERAND (expr, 1)))
852 error ("`__alignof' applied to a bit-field");
855 else if (TREE_CODE (expr) == COMPONENT_REF
856 && TREE_CODE (TREE_OPERAND (expr, 1)) == FIELD_DECL)
857 return size_int (DECL_ALIGN (TREE_OPERAND (expr, 1)) / BITS_PER_UNIT);
859 if (TREE_CODE (expr) == INDIRECT_REF)
861 tree t = TREE_OPERAND (expr, 0);
863 int bestalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
865 while (TREE_CODE (t) == NOP_EXPR
866 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == POINTER_TYPE)
870 t = TREE_OPERAND (t, 0);
871 thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
872 if (thisalign > bestalign)
873 best = t, bestalign = thisalign;
875 return c_alignof (TREE_TYPE (TREE_TYPE (best)));
878 return c_alignof (TREE_TYPE (expr));
880 /* Return either DECL or its known constant value (if it has one). */
883 decl_constant_value (decl)
886 if (! TREE_PUBLIC (decl)
887 /* Don't change a variable array bound or initial value to a constant
888 in a place where a variable is invalid. */
889 && current_function_decl != 0
891 && ! TREE_THIS_VOLATILE (decl)
892 && DECL_INITIAL (decl) != 0
893 && TREE_CODE (DECL_INITIAL (decl)) != ERROR_MARK
894 /* This is invalid if initial value is not constant.
895 If it has either a function call, a memory reference,
896 or a variable, then re-evaluating it could give different results. */
897 && TREE_CONSTANT (DECL_INITIAL (decl))
898 /* Check for cases where this is sub-optimal, even though valid. */
899 && TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR
900 && DECL_MODE (decl) != BLKmode)
901 return DECL_INITIAL (decl);
905 /* Perform default promotions for C data used in expressions.
906 Arrays and functions are converted to pointers;
907 enumeral types or short or char, to int.
908 In addition, manifest constants symbols are replaced by their values. */
911 default_conversion (exp)
914 register tree type = TREE_TYPE (exp);
915 register enum tree_code code = TREE_CODE (type);
917 /* Constants can be used directly unless they're not loadable. */
918 if (TREE_CODE (exp) == CONST_DECL)
919 exp = DECL_INITIAL (exp);
920 /* Replace a nonvolatile const static variable with its value. */
922 && TREE_CODE (exp) == VAR_DECL
923 && TREE_READONLY (exp)
924 /* But not for iterators! */
926 && DECL_MODE (exp) != BLKmode)
928 exp = decl_constant_value (exp);
929 type = TREE_TYPE (exp);
932 /* Strip NON_LVALUE_EXPRs and no-op conversions, since we aren't using as
934 /* Do not use STRIP_NOPS here! It will remove conversions from pointer
935 to integer and cause infinite recursion. */
936 while (TREE_CODE (exp) == NON_LVALUE_EXPR
937 || (TREE_CODE (exp) == NOP_EXPR
938 && TREE_TYPE (TREE_OPERAND (exp, 0)) == TREE_TYPE (exp)))
939 exp = TREE_OPERAND (exp, 0);
941 /* Normally convert enums to int,
942 but convert wide enums to something wider. */
943 if (code == ENUMERAL_TYPE)
945 type = type_for_size (MAX (TYPE_PRECISION (type),
946 TYPE_PRECISION (integer_type_node)),
947 (flag_traditional && TREE_UNSIGNED (type)));
948 return convert (type, exp);
951 if (C_PROMOTING_INTEGER_TYPE_P (type))
953 /* Traditionally, unsignedness is preserved in default promotions.
954 Also preserve unsignedness if not really getting any wider. */
955 if (TREE_UNSIGNED (type)
957 || TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)))
958 return convert (unsigned_type_node, exp);
959 return convert (integer_type_node, exp);
961 if (flag_traditional && TYPE_MAIN_VARIANT (type) == float_type_node)
962 return convert (double_type_node, exp);
963 if (code == VOID_TYPE)
965 error ("void value not ignored as it ought to be");
966 return error_mark_node;
968 if (code == FUNCTION_TYPE)
970 return build_unary_op (ADDR_EXPR, exp, 0);
972 if (code == ARRAY_TYPE)
975 tree restype = TREE_TYPE (type);
980 if (TREE_CODE_CLASS (TREE_CODE (exp)) == 'r'
981 || TREE_CODE_CLASS (TREE_CODE (exp)) == 'd')
983 constp = TREE_READONLY (exp);
984 volatilep = TREE_THIS_VOLATILE (exp);
987 if (TYPE_READONLY (type) || TYPE_VOLATILE (type)
988 || constp || volatilep)
989 restype = c_build_type_variant (restype,
990 TYPE_READONLY (type) || constp,
991 TYPE_VOLATILE (type) || volatilep);
993 if (TREE_CODE (exp) == INDIRECT_REF)
994 return convert (TYPE_POINTER_TO (restype),
995 TREE_OPERAND (exp, 0));
997 if (TREE_CODE (exp) == COMPOUND_EXPR)
999 tree op1 = default_conversion (TREE_OPERAND (exp, 1));
1000 return build (COMPOUND_EXPR, TREE_TYPE (op1),
1001 TREE_OPERAND (exp, 0), op1);
1005 && ! (TREE_CODE (exp) == CONSTRUCTOR && TREE_STATIC (exp)))
1007 error ("invalid use of non-lvalue array");
1008 return error_mark_node;
1011 ptrtype = build_pointer_type (restype);
1013 if (TREE_CODE (exp) == VAR_DECL)
1015 /* ??? This is not really quite correct
1016 in that the type of the operand of ADDR_EXPR
1017 is not the target type of the type of the ADDR_EXPR itself.
1018 Question is, can this lossage be avoided? */
1019 adr = build1 (ADDR_EXPR, ptrtype, exp);
1020 if (mark_addressable (exp) == 0)
1021 return error_mark_node;
1022 TREE_CONSTANT (adr) = staticp (exp);
1023 TREE_SIDE_EFFECTS (adr) = 0; /* Default would be, same as EXP. */
1026 /* This way is better for a COMPONENT_REF since it can
1027 simplify the offset for a component. */
1028 adr = build_unary_op (ADDR_EXPR, exp, 1);
1029 return convert (ptrtype, adr);
1034 /* Make an expression to refer to the COMPONENT field of
1035 structure or union value DATUM. COMPONENT is an IDENTIFIER_NODE. */
1038 build_component_ref (datum, component)
1039 tree datum, component;
1041 register tree type = TREE_TYPE (datum);
1042 register enum tree_code code = TREE_CODE (type);
1043 register tree field = NULL;
1046 /* If DATUM is a COMPOUND_EXPR or COND_EXPR, move our reference inside it
1047 unless we are not to support things not strictly ANSI. */
1048 switch (TREE_CODE (datum))
1052 tree value = build_component_ref (TREE_OPERAND (datum, 1), component);
1053 return build (COMPOUND_EXPR, TREE_TYPE (value),
1054 TREE_OPERAND (datum, 0), value);
1057 return build_conditional_expr
1058 (TREE_OPERAND (datum, 0),
1059 build_component_ref (TREE_OPERAND (datum, 1), component),
1060 build_component_ref (TREE_OPERAND (datum, 2), component));
1063 /* See if there is a field or component with name COMPONENT. */
1065 if (code == RECORD_TYPE || code == UNION_TYPE)
1067 if (TYPE_SIZE (type) == 0)
1069 incomplete_type_error (NULL_TREE, type);
1070 return error_mark_node;
1073 /* Look up component name in the structure type definition.
1075 If TYPE_LANG_SPECIFIC is set, then it is a sorted array of pointers
1076 to the field elements. Use a binary search on this array to quickly
1077 find the element. Otherwise, do a linear search. TYPE_LANG_SPECIFIC
1078 will always be set for structures which have many elements. */
1080 if (TYPE_LANG_SPECIFIC (type))
1083 tree *field_array = &TYPE_LANG_SPECIFIC (type)->elts[0];
1085 field = TYPE_FIELDS (type);
1087 top = TYPE_LANG_SPECIFIC (type)->len;
1088 while (top - bot > 1)
1092 half = (top - bot + 1) >> 1;
1093 field = field_array[bot+half];
1094 cmp = (long)DECL_NAME (field) - (long)component;
1103 if (DECL_NAME (field_array[bot]) == component)
1104 field = field_array[bot];
1105 else if (DECL_NAME (field) != component)
1110 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
1112 if (DECL_NAME (field) == component)
1119 error (code == RECORD_TYPE
1120 ? "structure has no member named `%s'"
1121 : "union has no member named `%s'",
1122 IDENTIFIER_POINTER (component));
1123 return error_mark_node;
1125 if (TREE_TYPE (field) == error_mark_node)
1126 return error_mark_node;
1128 ref = build (COMPONENT_REF, TREE_TYPE (field), datum, field);
1130 if (TREE_READONLY (datum) || TREE_READONLY (field))
1131 TREE_READONLY (ref) = 1;
1132 if (TREE_THIS_VOLATILE (datum) || TREE_THIS_VOLATILE (field))
1133 TREE_THIS_VOLATILE (ref) = 1;
1137 else if (code != ERROR_MARK)
1138 error ("request for member `%s' in something not a structure or union",
1139 IDENTIFIER_POINTER (component));
1141 return error_mark_node;
1144 /* Given an expression PTR for a pointer, return an expression
1145 for the value pointed to.
1146 ERRORSTRING is the name of the operator to appear in error messages. */
1149 build_indirect_ref (ptr, errorstring)
1153 register tree pointer = default_conversion (ptr);
1154 register tree type = TREE_TYPE (pointer);
1156 if (TREE_CODE (type) == POINTER_TYPE)
1158 if (TREE_CODE (pointer) == ADDR_EXPR
1160 && (TREE_TYPE (TREE_OPERAND (pointer, 0))
1161 == TREE_TYPE (type)))
1162 return TREE_OPERAND (pointer, 0);
1165 tree t = TREE_TYPE (type);
1166 register tree ref = build1 (INDIRECT_REF,
1167 TYPE_MAIN_VARIANT (t), pointer);
1169 if (TYPE_SIZE (t) == 0 && TREE_CODE (t) != ARRAY_TYPE)
1171 error ("dereferencing pointer to incomplete type");
1172 return error_mark_node;
1174 if (TREE_CODE (t) == VOID_TYPE)
1175 warning ("dereferencing `void *' pointer");
1177 /* We *must* set TREE_READONLY when dereferencing a pointer to const,
1178 so that we get the proper error message if the result is used
1179 to assign to. Also, &* is supposed to be a no-op.
1180 And ANSI C seems to specify that the type of the result
1181 should be the const type. */
1182 /* A de-reference of a pointer to const is not a const. It is valid
1183 to change it via some other pointer. */
1184 TREE_READONLY (ref) = TYPE_READONLY (t);
1185 TREE_SIDE_EFFECTS (ref)
1186 = TYPE_VOLATILE (t) || TREE_SIDE_EFFECTS (pointer) || flag_volatile;
1187 TREE_THIS_VOLATILE (ref) = TYPE_VOLATILE (t) || flag_volatile;
1191 else if (TREE_CODE (pointer) != ERROR_MARK)
1192 error ("invalid type argument of `%s'", errorstring);
1193 return error_mark_node;
1196 /* This handles expressions of the form "a[i]", which denotes
1199 This is logically equivalent in C to *(a+i), but we may do it differently.
1200 If A is a variable or a member, we generate a primitive ARRAY_REF.
1201 This avoids forcing the array out of registers, and can work on
1202 arrays that are not lvalues (for example, members of structures returned
1206 build_array_ref (array, index)
1211 error ("subscript missing in array reference");
1212 return error_mark_node;
1215 if (TREE_TYPE (array) == error_mark_node
1216 || TREE_TYPE (index) == error_mark_node)
1217 return error_mark_node;
1219 if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE
1220 && TREE_CODE (array) != INDIRECT_REF)
1224 /* Subscripting with type char is likely to lose
1225 on a machine where chars are signed.
1226 So warn on any machine, but optionally.
1227 Don't warn for unsigned char since that type is safe.
1228 Don't warn for signed char because anyone who uses that
1229 must have done so deliberately. */
1230 if (warn_char_subscripts
1231 && TYPE_MAIN_VARIANT (TREE_TYPE (index)) == char_type_node)
1232 warning ("array subscript has type `char'");
1234 /* Apply default promotions *after* noticing character types. */
1235 index = default_conversion (index);
1237 /* Require integer *after* promotion, for sake of enums. */
1238 if (TREE_CODE (TREE_TYPE (index)) != INTEGER_TYPE)
1240 error ("array subscript is not an integer");
1241 return error_mark_node;
1244 /* An array that is indexed by a non-constant
1245 cannot be stored in a register; we must be able to do
1246 address arithmetic on its address.
1247 Likewise an array of elements of variable size. */
1248 if (TREE_CODE (index) != INTEGER_CST
1249 || (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array))) != 0
1250 && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array)))) != INTEGER_CST))
1252 if (mark_addressable (array) == 0)
1253 return error_mark_node;
1255 /* An array that is indexed by a constant value which is not within
1256 the array bounds cannot be stored in a register either; because we
1257 would get a crash in store_bit_field/extract_bit_field when trying
1258 to access a non-existent part of the register. */
1259 if (TREE_CODE (index) == INTEGER_CST
1260 && TYPE_VALUES (TREE_TYPE (array))
1261 && ! int_fits_type_p (index, TYPE_VALUES (TREE_TYPE (array))))
1263 if (mark_addressable (array) == 0)
1264 return error_mark_node;
1267 if (pedantic && !lvalue_p (array))
1269 if (DECL_REGISTER (array))
1270 pedwarn ("ANSI C forbids subscripting `register' array");
1272 pedwarn ("ANSI C forbids subscripting non-lvalue array");
1278 while (TREE_CODE (foo) == COMPONENT_REF)
1279 foo = TREE_OPERAND (foo, 0);
1280 if (TREE_CODE (foo) == VAR_DECL && DECL_REGISTER (foo))
1281 pedwarn ("ANSI C forbids subscripting non-lvalue array");
1284 type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (array)));
1285 rval = build (ARRAY_REF, type, array, index);
1286 /* Array ref is const/volatile if the array elements are
1287 or if the array is. */
1288 TREE_READONLY (rval)
1289 |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array)))
1290 | TREE_READONLY (array));
1291 TREE_SIDE_EFFECTS (rval)
1292 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
1293 | TREE_SIDE_EFFECTS (array));
1294 TREE_THIS_VOLATILE (rval)
1295 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
1296 /* This was added by rms on 16 Nov 91.
1297 It fixes vol struct foo *a; a->elts[1]
1298 in an inline function.
1299 Hope it doesn't break something else. */
1300 | TREE_THIS_VOLATILE (array));
1301 return require_complete_type (fold (rval));
1305 tree ar = default_conversion (array);
1306 tree ind = default_conversion (index);
1308 /* Put the integer in IND to simplify error checking. */
1309 if (TREE_CODE (TREE_TYPE (ar)) == INTEGER_TYPE)
1316 if (ar == error_mark_node)
1319 if (TREE_CODE (TREE_TYPE (ar)) != POINTER_TYPE)
1321 error ("subscripted value is neither array nor pointer");
1322 return error_mark_node;
1324 if (TREE_CODE (TREE_TYPE (ind)) != INTEGER_TYPE)
1326 error ("array subscript is not an integer");
1327 return error_mark_node;
1330 return build_indirect_ref (build_binary_op (PLUS_EXPR, ar, ind, 0),
1335 /* Check a printf/fprintf/sprintf/scanf/fscanf/sscanf format against PARAMS. */
1337 #define ISDIGIT(c) ((c) >= '0' && (c) <= '9')
1339 #define T_I &integer_type_node
1340 #define T_L &long_integer_type_node
1341 #define T_S &short_integer_type_node
1342 #define T_UI &unsigned_type_node
1343 #define T_UL &long_unsigned_type_node
1344 #define T_US &short_unsigned_type_node
1345 #define T_F &float_type_node
1346 #define T_D &double_type_node
1347 #define T_LD &long_double_type_node
1348 #define T_C &char_type_node
1349 #define T_V &void_type_node
1350 #define T_W &wchar_type_node
1356 /* Type of argument if no length modifier is used. */
1358 /* Type of argument if length modifier for shortening is used.
1359 If NULL, then this modifier is not allowed. */
1361 /* Type of argument if length modifier `l' is used.
1362 If NULL, then this modifier is not allowed. */
1364 /* Type of argument if length modifier `L' is used.
1365 If NULL, then this modifier is not allowed. */
1367 /* List of other modifier characters allowed with these options. */
1371 static format_char_info print_table[]
1373 { "di", 0, T_I, T_I, T_L, NULL, "-wp0 +" },
1374 { "oxX", 0, T_UI, T_UI, T_UL, NULL, "-wp0#" },
1375 { "u", 0, T_UI, T_UI, T_UL, NULL, "-wp0" },
1376 { "feEgG", 0, T_D, NULL, NULL, T_LD, "-wp0 +#" },
1377 { "c", 0, T_I, NULL, T_W, NULL, "-w" },
1378 { "C", 0, T_W, NULL, NULL, NULL, "-w" },
1379 { "s", 1, T_C, NULL, T_W, NULL, "-wp" },
1380 { "S", 1, T_W, NULL, NULL, NULL, "-wp" },
1381 { "p", 1, T_V, NULL, NULL, NULL, "-" },
1382 { "n", 1, T_I, T_S, T_L, NULL, "" },
1386 static format_char_info scan_table[]
1388 { "di", 1, T_I, T_S, T_L, NULL, "*" },
1389 { "ouxX", 1, T_UI, T_US, T_UL, NULL, "*" },
1390 { "efgEG", 1, T_F, NULL, T_D, T_LD, "*" },
1391 { "sc", 1, T_C, NULL, T_W, NULL, "*" },
1392 { "[", 1, T_C, NULL, NULL, NULL, "*" },
1393 { "C", 1, T_W, NULL, NULL, NULL, "*" },
1394 { "S", 1, T_W, NULL, NULL, NULL, "*" },
1395 { "p", 2, T_V, NULL, NULL, NULL, "*" },
1396 { "n", 1, T_I, T_S, T_L, NULL, "" },
1402 tree function_ident; /* identifier such as "printf" */
1403 int is_scan; /* TRUE if *scanf */
1404 int format_num; /* number of format argument */
1405 int first_arg_num; /* number of first arg (zero for varargs) */
1408 static unsigned int function_info_entries = 0;
1409 static function_info *function_info_table = NULL;
1411 /* Record information for argument format checking. FUNCTION_IDENT is
1412 the identifier node for the name of the function to check (its decl
1413 need not exist yet). IS_SCAN is true for scanf-type format checking;
1414 false indicates printf-style format checking. FORMAT_NUM is the number
1415 of the argument which is the format control string (starting from 1).
1416 FIRST_ARG_NUM is the number of the first actual argument to check
1417 against teh format string, or zero if no checking is not be done
1418 (e.g. for varargs such as vfprintf). */
1421 record_format_info (function_ident, is_scan, format_num, first_arg_num)
1422 tree function_ident;
1427 function_info *info;
1429 function_info_entries++;
1430 if (function_info_table)
1432 = (function_info *) xrealloc (function_info_table,
1433 function_info_entries * sizeof (function_info));
1435 function_info_table = (function_info *) xmalloc (sizeof (function_info));
1437 info = &function_info_table[function_info_entries - 1];
1439 info->function_ident = function_ident;
1440 info->is_scan = is_scan;
1441 info->format_num = format_num;
1442 info->first_arg_num = first_arg_num;
1445 /* Initialize the table of functions to perform format checking on.
1446 The ANSI functions are always checked (whether <stdio.h> is
1447 included or not), since it is common to call printf without
1448 including <stdio.h>. There shouldn't be a problem with this,
1449 since ANSI reserves these function names whether you include the
1450 header file or not. In any case, the checking is harmless. */
1453 init_format_info_table ()
1455 record_format_info (get_identifier ("printf"), 0, 1, 2);
1456 record_format_info (get_identifier ("fprintf"), 0, 2, 3);
1457 record_format_info (get_identifier ("sprintf"), 0, 2, 3);
1458 record_format_info (get_identifier ("scanf"), 1, 1, 2);
1459 record_format_info (get_identifier ("fscanf"), 1, 2, 3);
1460 record_format_info (get_identifier ("sscanf"), 1, 2, 3);
1461 record_format_info (get_identifier ("vprintf"), 0, 1, 0);
1462 record_format_info (get_identifier ("vfprintf"), 0, 2, 0);
1463 record_format_info (get_identifier ("vsprintf"), 0, 2, 0);
1466 static char tfaff[] = "too few arguments for format";
1468 /* Check the argument list of a call to printf, scanf, etc.
1469 INFO points to the element of function_info_table.
1470 PARAMS is the list of argument values. */
1473 check_format (info, params)
1474 function_info *info;
1479 int suppressed, wide, precise;
1488 format_char_info *fci;
1489 static char message[132];
1492 /* Skip to format argument. If the argument isn't available, there's
1493 no work for us to do; prototype checking will catch the problem. */
1494 for (arg_num = 1; ; ++arg_num)
1498 if (arg_num == info->format_num)
1500 params = TREE_CHAIN (params);
1502 format_tree = TREE_VALUE (params);
1503 params = TREE_CHAIN (params);
1504 if (format_tree == 0)
1506 /* We can only check the format if it's a string constant. */
1507 while (TREE_CODE (format_tree) == NOP_EXPR)
1508 format_tree = TREE_OPERAND (format_tree, 0); /* strip coercion */
1509 if (format_tree == null_pointer_node)
1511 warning ("null format string");
1514 if (TREE_CODE (format_tree) != ADDR_EXPR)
1516 format_tree = TREE_OPERAND (format_tree, 0);
1517 if (TREE_CODE (format_tree) != STRING_CST)
1519 format_chars = TREE_STRING_POINTER (format_tree);
1520 format_length = TREE_STRING_LENGTH (format_tree);
1521 if (format_length <= 1)
1522 warning ("zero-length format string");
1523 if (format_chars[--format_length] != 0)
1525 warning ("unterminated format string");
1528 /* Skip to first argument to check. */
1529 while (arg_num + 1 < info->first_arg_num)
1533 params = TREE_CHAIN (params);
1538 if (*format_chars == 0)
1540 if (format_chars - TREE_STRING_POINTER (format_tree) != format_length)
1541 warning ("embedded `\\0' in format");
1542 if (info->first_arg_num != 0 && params != 0)
1543 warning ("too many arguments for format");
1546 if (*format_chars++ != '%')
1548 if (*format_chars == 0)
1550 warning ("spurious trailing `%%' in format");
1553 if (*format_chars == '%')
1559 suppressed = wide = precise = FALSE;
1562 suppressed = *format_chars == '*';
1565 while (ISDIGIT (*format_chars))
1570 while (*format_chars != 0 && index (" +#0-", *format_chars) != 0)
1572 if (index (flag_chars, *format_chars) != 0)
1574 sprintf (message, "repeated `%c' flag in format",
1578 i = strlen (flag_chars);
1579 flag_chars[i++] = *format_chars++;
1582 /* "If the space and + flags both appear,
1583 the space flag will be ignored." */
1584 if (index (flag_chars, ' ') != 0
1585 && index (flag_chars, '+') != 0)
1586 warning ("use of both ` ' and `+' flags in format");
1587 /* "If the 0 and - flags both appear,
1588 the 0 flag will be ignored." */
1589 if (index (flag_chars, '0') != 0
1590 && index (flag_chars, '-') != 0)
1591 warning ("use of both `0' and `-' flags in format");
1592 if (*format_chars == '*')
1595 /* "...a field width...may be indicated by an asterisk.
1596 In this case, an int argument supplies the field width..." */
1603 if (info->first_arg_num != 0)
1605 cur_param = TREE_VALUE (params);
1606 params = TREE_CHAIN (params);
1608 /* size_t is generally not valid here.
1609 It will work on most machines, because size_t and int
1610 have the same mode. But might as well warn anyway,
1611 since it will fail on other machines. */
1612 if (TYPE_MAIN_VARIANT (TREE_TYPE (cur_param))
1613 != integer_type_node)
1616 "field width is not type int (arg %d)",
1624 while (ISDIGIT (*format_chars))
1630 if (*format_chars == '.')
1634 if (*format_chars != '*' && !ISDIGIT (*format_chars))
1635 warning ("`.' not followed by `*' or digit in format");
1636 /* "...a...precision...may be indicated by an asterisk.
1637 In this case, an int argument supplies the...precision." */
1638 if (*format_chars == '*')
1640 if (info->first_arg_num != 0)
1648 cur_param = TREE_VALUE (params);
1649 params = TREE_CHAIN (params);
1651 if (TYPE_MAIN_VARIANT (TREE_TYPE (cur_param))
1652 != integer_type_node)
1655 "field width is not type int (arg %d)",
1663 while (ISDIGIT (*format_chars))
1668 if (*format_chars == 'h' || *format_chars == 'l' || *format_chars == 'L')
1669 length_char = *format_chars++;
1672 if (suppressed && length_char != 0)
1675 "use of `*' and `%c' together in format",
1679 format_char = *format_chars;
1680 if (format_char == 0)
1682 warning ("conversion lacks type at end of format");
1686 fci = info->is_scan ? scan_table : print_table;
1689 if (fci->format_chars == 0
1690 || index (fci->format_chars, format_char) != 0)
1694 if (fci->format_chars == 0)
1696 if (format_char >= 040 && format_char < 0177)
1698 "unknown conversion type character `%c' in format",
1702 "unknown conversion type character 0x%x in format",
1707 if (wide && index (fci->flag_chars, 'w') == 0)
1709 sprintf (message, "width used with `%c' format",
1713 if (precise && index (fci->flag_chars, 'p') == 0)
1715 sprintf (message, "precision used with `%c' format",
1721 if (index (fci->flag_chars, '*') == 0)
1724 "suppression of `%c' conversion in format",
1730 for (i = 0; flag_chars[i] != 0; ++i)
1732 if (index (fci->flag_chars, flag_chars[i]) == 0)
1734 sprintf (message, "flag `%c' used with type `%c'",
1735 flag_chars[i], format_char);
1739 if (precise && index (flag_chars, '0') != 0
1740 && (format_char == 'd' || format_char == 'i'
1741 || format_char == 'o' || format_char == 'u'
1742 || format_char == 'x' || format_char == 'x'))
1745 "precision and `0' flag not both allowed with `%c' format",
1749 switch (length_char)
1751 default: wanted_type = fci->nolen ? *(fci->nolen) : 0; break;
1752 case 'h': wanted_type = fci->hlen ? *(fci->hlen) : 0; break;
1753 case 'l': wanted_type = fci->llen ? *(fci->llen) : 0; break;
1754 case 'L': wanted_type = fci->bigllen ? *(fci->bigllen) : 0; break;
1756 if (wanted_type == 0)
1759 "use of `%c' length character with `%c' type character",
1760 length_char, format_char);
1765 ** XXX -- should kvetch about stuff such as
1769 ** scanf ("%d", &i);
1773 /* Finally. . .check type of argument against desired type! */
1774 if (info->first_arg_num == 0)
1781 cur_param = TREE_VALUE (params);
1782 params = TREE_CHAIN (params);
1784 cur_type = TREE_TYPE (cur_param);
1786 /* Check the types of any additional pointer arguments
1787 that precede the "real" argument. */
1788 for (i = 0; i < fci->pointer_count; ++i)
1790 if (TREE_CODE (cur_type) == POINTER_TYPE)
1792 cur_type = TREE_TYPE (cur_type);
1796 "format argument is not a %s (arg %d)",
1797 ((fci->pointer_count == 1) ? "pointer" : "pointer to a pointer"),
1803 /* Check the type of the "real" argument, if there's a type we want. */
1804 if (i == fci->pointer_count && wanted_type != 0
1805 && wanted_type != TYPE_MAIN_VARIANT (cur_type)
1806 /* If we want `void *', allow any pointer type.
1807 (Anything else would already have got a warning.) */
1808 && ! (wanted_type == void_type_node
1809 && fci->pointer_count > 0)
1810 /* Don't warn about differences merely in signedness. */
1811 && !(TREE_CODE (wanted_type) == INTEGER_TYPE
1812 && TREE_CODE (cur_type) == INTEGER_TYPE
1813 && (wanted_type == (TREE_UNSIGNED (wanted_type)
1814 ? unsigned_type : signed_type) (cur_type))))
1816 register char *this;
1817 register char *that;
1819 this = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (wanted_type)));
1821 if (TREE_CODE (cur_type) != ERROR_MARK
1822 && TYPE_NAME (cur_type) != 0
1823 && TREE_CODE (cur_type) != INTEGER_TYPE
1824 && !(TREE_CODE (cur_type) == POINTER_TYPE
1825 && TREE_CODE (TREE_TYPE (cur_type)) == INTEGER_TYPE))
1827 if (TREE_CODE (TYPE_NAME (cur_type)) == TYPE_DECL
1828 && DECL_NAME (TYPE_NAME (cur_type)) != 0)
1829 that = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (cur_type)));
1831 that = IDENTIFIER_POINTER (TYPE_NAME (cur_type));
1834 /* A nameless type can't possibly match what the format wants.
1835 So there will be a warning for it.
1836 Make up a string to describe vaguely what it is. */
1839 if (TREE_CODE (cur_type) == POINTER_TYPE)
1842 that = "different type";
1845 if (strcmp (this, that) != 0)
1847 sprintf (message, "%s format, %s arg (arg %d)",
1848 this, that, arg_num);
1855 /* Build a function call to function FUNCTION with parameters PARAMS.
1856 PARAMS is a list--a chain of TREE_LIST nodes--in which the
1857 TREE_VALUE of each node is a parameter-expression.
1858 FUNCTION's data type may be a function type or a pointer-to-function. */
1861 build_function_call (function, params)
1862 tree function, params;
1864 register tree fntype, fundecl;
1865 register tree coerced_params;
1866 tree name = NULL_TREE;
1868 /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
1869 STRIP_TYPE_NOPS (function);
1871 /* Convert anything with function type to a pointer-to-function. */
1872 if (TREE_CODE (function) == FUNCTION_DECL)
1874 name = DECL_NAME (function);
1875 /* Differs from default_conversion by not setting TREE_ADDRESSABLE
1876 (because calling an inline function does not mean the function
1877 needs to be separately compiled). */
1878 fntype = build_type_variant (TREE_TYPE (function),
1879 TREE_READONLY (function),
1880 TREE_THIS_VOLATILE (function));
1882 function = build1 (ADDR_EXPR, build_pointer_type (fntype), function);
1885 function = default_conversion (function);
1887 fntype = TREE_TYPE (function);
1889 if (TREE_CODE (fntype) == ERROR_MARK)
1890 return error_mark_node;
1892 if (!(TREE_CODE (fntype) == POINTER_TYPE
1893 && TREE_CODE (TREE_TYPE (fntype)) == FUNCTION_TYPE))
1895 error ("called object is not a function");
1896 return error_mark_node;
1899 /* fntype now gets the type of function pointed to. */
1900 fntype = TREE_TYPE (fntype);
1902 /* Convert the parameters to the types declared in the
1903 function prototype, or apply default promotions. */
1906 = convert_arguments (TYPE_ARG_TYPES (fntype), params, name, fundecl);
1908 /* Check for errors in format strings. */
1909 if (warn_format && name != 0)
1913 /* See if this function is a format function. */
1914 for (i = 0; i < function_info_entries; i++)
1915 if (function_info_table[i].function_ident == name)
1917 register char *message;
1919 /* If so, check it. */
1920 check_format (&function_info_table[i], coerced_params);
1925 /* Recognize certain built-in functions so we can make tree-codes
1926 other than CALL_EXPR. We do this when it enables fold-const.c
1927 to do something useful. */
1929 if (TREE_CODE (function) == ADDR_EXPR
1930 && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL
1931 && DECL_BUILT_IN (TREE_OPERAND (function, 0)))
1932 switch (DECL_FUNCTION_CODE (TREE_OPERAND (function, 0)))
1937 if (coerced_params == 0)
1938 return integer_zero_node;
1939 return build_unary_op (ABS_EXPR, TREE_VALUE (coerced_params), 0);
1943 register tree result
1944 = build (CALL_EXPR, TREE_TYPE (fntype),
1945 function, coerced_params, NULL_TREE);
1947 TREE_SIDE_EFFECTS (result) = 1;
1948 if (TREE_TYPE (result) == void_type_node)
1950 return require_complete_type (result);
1954 /* Convert the argument expressions in the list VALUES
1955 to the types in the list TYPELIST. The result is a list of converted
1956 argument expressions.
1958 If TYPELIST is exhausted, or when an element has NULL as its type,
1959 perform the default conversions.
1961 PARMLIST is the chain of parm decls for the function being called.
1962 It may be 0, if that info is not available.
1963 It is used only for generating error messages.
1965 NAME is an IDENTIFIER_NODE or 0. It is used only for error messages.
1967 This is also where warnings about wrong number of args are generated.
1969 Both VALUES and the returned value are chains of TREE_LIST nodes
1970 with the elements of the list in the TREE_VALUE slots of those nodes. */
1973 convert_arguments (typelist, values, name, fundecl)
1974 tree typelist, values, name, fundecl;
1976 register tree typetail, valtail;
1977 register tree result = NULL;
1980 /* Scan the given expressions and types, producing individual
1981 converted arguments and pushing them on RESULT in reverse order. */
1983 for (valtail = values, typetail = typelist, parmnum = 0;
1985 valtail = TREE_CHAIN (valtail), parmnum++)
1987 register tree type = typetail ? TREE_VALUE (typetail) : 0;
1988 register tree val = TREE_VALUE (valtail);
1990 if (type == void_type_node)
1993 error ("too many arguments to function `%s'",
1994 IDENTIFIER_POINTER (name));
1996 error ("too many arguments to function");
2000 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
2001 /* Do not use STRIP_NOPS here! We do not want an enumerator with value 0
2002 to convert automatically to a pointer. */
2003 if (TREE_CODE (val) == NON_LVALUE_EXPR)
2004 val = TREE_OPERAND (val, 0);
2006 if (TREE_CODE (TREE_TYPE (val)) == ARRAY_TYPE
2007 || TREE_CODE (TREE_TYPE (val)) == FUNCTION_TYPE)
2008 val = default_conversion (val);
2010 val = require_complete_type (val);
2014 /* Formal parm type is specified by a function prototype. */
2017 if (TYPE_SIZE (type) == 0)
2019 error ("type of formal parameter %d is incomplete", parmnum + 1);
2026 #ifdef PROMOTE_PROTOTYPES
2027 /* Rather than truncating and then reextending,
2028 convert directly to int, if that's the type we will want. */
2029 if (! flag_traditional
2030 && TREE_CODE (type) == INTEGER_TYPE
2031 && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
2032 type = integer_type_node;
2035 #if 0 /* This turns out not to win--there's no way to write a prototype
2036 for a function whose arg type is a union with no tag. */
2037 /* Nameless union automatically casts the types it contains. */
2038 if (TREE_CODE (type) == UNION_TYPE && TYPE_NAME (type) == 0)
2042 for (field = TYPE_FIELDS (type); field;
2043 field = TREE_CHAIN (field))
2044 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (field)),
2045 TYPE_MAIN_VARIANT (TREE_TYPE (val))))
2049 val = build1 (CONVERT_EXPR, type, val);
2053 /* Optionally warn about conversions that
2054 differ from the default conversions. */
2055 if (warn_conversion)
2057 int formal_prec = TYPE_PRECISION (type);
2059 if (TREE_CODE (type) != REAL_TYPE
2060 && TREE_CODE (TREE_TYPE (val)) == REAL_TYPE)
2061 warn_for_assignment ("%s as integer rather than floating due to prototype", (char *) 0, name, parmnum + 1);
2062 else if (TREE_CODE (type) == REAL_TYPE
2063 && TREE_CODE (TREE_TYPE (val)) != REAL_TYPE)
2064 warn_for_assignment ("%s as floating rather than integer due to prototype", (char *) 0, name, parmnum + 1);
2065 else if (TREE_CODE (type) == REAL_TYPE
2066 && TREE_CODE (TREE_TYPE (val)) == REAL_TYPE)
2068 /* Warn if any argument is passed as `float',
2069 since without a prototype it would be `double'. */
2070 if (formal_prec == TYPE_PRECISION (float_type_node))
2071 warn_for_assignment ("%s as `float' rather than `double' due to prototype", (char *) 0, name, parmnum + 1);
2073 /* Detect integer changing in width or signedness. */
2074 else if ((TREE_CODE (type) == INTEGER_TYPE
2075 || TREE_CODE (type) == ENUMERAL_TYPE)
2076 && (TREE_CODE (TREE_TYPE (val)) == INTEGER_TYPE
2077 || TREE_CODE (TREE_TYPE (val)) == ENUMERAL_TYPE))
2079 tree would_have_been = default_conversion (val);
2080 tree type1 = TREE_TYPE (would_have_been);
2082 if (TREE_CODE (type) == ENUMERAL_TYPE
2083 && type == TREE_TYPE (val))
2084 /* No warning if function asks for enum
2085 and the actual arg is that enum type. */
2087 else if (formal_prec != TYPE_PRECISION (type1))
2088 warn_for_assignment ("%s with different width due to prototype", (char *) 0, name, parmnum + 1);
2089 else if (TREE_UNSIGNED (type) == TREE_UNSIGNED (type1))
2091 /* Don't complain if the formal parameter type
2092 is an enum, because we can't tell now whether
2093 the value was an enum--even the same enum. */
2094 else if (TREE_CODE (type) == ENUMERAL_TYPE)
2096 else if (TREE_CODE (val) == INTEGER_CST
2097 && int_fits_type_p (val, type))
2098 /* Change in signedness doesn't matter
2099 if a constant value is unaffected. */
2101 /* Likewise for a constant in a NOP_EXPR. */
2102 else if (TREE_CODE (val) == NOP_EXPR
2103 && TREE_CODE (TREE_OPERAND (val, 0)) == INTEGER_CST
2104 && int_fits_type_p (TREE_OPERAND (val, 0), type))
2106 #if 0 /* We never get such tree structure here. */
2107 else if (TREE_CODE (TREE_TYPE (val)) == ENUMERAL_TYPE
2108 && int_fits_type_p (TYPE_MIN_VALUE (TREE_TYPE (val)), type)
2109 && int_fits_type_p (TYPE_MAX_VALUE (TREE_TYPE (val)), type))
2110 /* Change in signedness doesn't matter
2111 if an enum value is unaffected. */
2114 /* If the value is extended from a narrower
2115 unsigned type, it doesn't matter whether we
2116 pass it as signed or unsigned; the value
2117 certainly is the same either way. */
2118 else if (TYPE_PRECISION (TREE_TYPE (val)) < TYPE_PRECISION (type)
2119 && TREE_UNSIGNED (TREE_TYPE (val)))
2121 else if (TREE_UNSIGNED (type))
2122 warn_for_assignment ("%s as unsigned due to prototype", (char *) 0, name, parmnum + 1);
2124 warn_for_assignment ("%s as signed due to prototype", (char *) 0, name, parmnum + 1);
2128 parmval = convert_for_assignment (type, val,
2129 (char *)0, /* arg passing */
2130 fundecl, name, parmnum + 1);
2132 #ifdef PROMOTE_PROTOTYPES
2133 if (TREE_CODE (type) == INTEGER_TYPE
2134 && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
2135 parmval = default_conversion (parmval);
2138 result = tree_cons (NULL_TREE, parmval, result);
2140 else if (TREE_CODE (TREE_TYPE (val)) == REAL_TYPE
2141 && (TYPE_PRECISION (TREE_TYPE (val))
2142 < TYPE_PRECISION (double_type_node)))
2143 /* Convert `float' to `double'. */
2144 result = tree_cons (NULL_TREE, convert (double_type_node, val), result);
2146 /* Convert `short' and `char' to full-size `int'. */
2147 result = tree_cons (NULL_TREE, default_conversion (val), result);
2150 typetail = TREE_CHAIN (typetail);
2153 if (typetail != 0 && TREE_VALUE (typetail) != void_type_node)
2156 error ("too few arguments to function `%s'",
2157 IDENTIFIER_POINTER (name));
2159 error ("too few arguments to function");
2162 return nreverse (result);
2165 /* This is the entry point used by the parser
2166 for binary operators in the input.
2167 In addition to constructing the expression,
2168 we check for operands that were written with other binary operators
2169 in a way that is likely to confuse the user. */
2172 parser_build_binary_op (code, arg1, arg2)
2173 enum tree_code code;
2176 tree result = build_binary_op (code, arg1, arg2, 1);
2179 char class1 = TREE_CODE_CLASS (TREE_CODE (arg1));
2180 char class2 = TREE_CODE_CLASS (TREE_CODE (arg2));
2181 enum tree_code code1 = ERROR_MARK;
2182 enum tree_code code2 = ERROR_MARK;
2184 if (class1 == 'e' || class1 == '1'
2185 || class1 == '2' || class1 == '<')
2186 code1 = C_EXP_ORIGINAL_CODE (arg1);
2187 if (class2 == 'e' || class2 == '1'
2188 || class2 == '2' || class2 == '<')
2189 code2 = C_EXP_ORIGINAL_CODE (arg2);
2191 /* Check for cases such as x+y<<z which users are likely
2192 to misinterpret. If parens are used, C_EXP_ORIGINAL_CODE
2193 is cleared to prevent these warnings. */
2194 if (warn_parentheses)
2196 if (code == LSHIFT_EXPR || code == RSHIFT_EXPR)
2198 if (code1 == PLUS_EXPR || code1 == MINUS_EXPR
2199 || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
2200 warning ("suggest parentheses around + or - inside shift");
2203 if (code == TRUTH_ORIF_EXPR)
2205 if (code1 == TRUTH_ANDIF_EXPR
2206 || code2 == TRUTH_ANDIF_EXPR)
2207 warning ("suggest parentheses around && within ||");
2210 if (code == BIT_IOR_EXPR)
2212 if (code1 == BIT_AND_EXPR || code1 == BIT_XOR_EXPR
2213 || code1 == PLUS_EXPR || code1 == MINUS_EXPR
2214 || code2 == BIT_AND_EXPR || code2 == BIT_XOR_EXPR
2215 || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
2216 warning ("suggest parentheses around arithmetic in operand of |");
2219 if (code == BIT_XOR_EXPR)
2221 if (code1 == BIT_AND_EXPR
2222 || code1 == PLUS_EXPR || code1 == MINUS_EXPR
2223 || code2 == BIT_AND_EXPR
2224 || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
2225 warning ("suggest parentheses around arithmetic in operand of ^");
2228 if (code == BIT_AND_EXPR)
2230 if (code1 == PLUS_EXPR || code1 == MINUS_EXPR
2231 || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
2232 warning ("suggest parentheses around + or - in operand of &");
2236 /* Similarly, check for cases like 1<=i<=10 that are probably errors. */
2237 if (TREE_CODE_CLASS (code) == '<' && extra_warnings
2238 && (TREE_CODE_CLASS (code1) == '<' || TREE_CODE_CLASS (code2) == '<'))
2239 warning ("comparisons like X<=Y<=Z do not have their mathematical meaning");
2241 unsigned_conversion_warning (result, arg1);
2242 unsigned_conversion_warning (result, arg2);
2243 overflow_warning (result);
2245 class = TREE_CODE_CLASS (TREE_CODE (result));
2247 /* Record the code that was specified in the source,
2248 for the sake of warnings about confusing nesting. */
2249 if (class == 'e' || class == '1'
2250 || class == '2' || class == '<')
2251 C_SET_EXP_ORIGINAL_CODE (result, code);
2254 int flag = TREE_CONSTANT (result);
2255 /* We used to use NOP_EXPR rather than NON_LVALUE_EXPR
2256 so that convert_for_assignment wouldn't strip it.
2257 That way, we got warnings for things like p = (1 - 1).
2258 But it turns out we should not get those warnings. */
2259 result = build1 (NON_LVALUE_EXPR, TREE_TYPE (result), result);
2260 C_SET_EXP_ORIGINAL_CODE (result, code);
2261 TREE_CONSTANT (result) = flag;
2267 /* Build a binary-operation expression without default conversions.
2268 CODE is the kind of expression to build.
2269 This function differs from `build' in several ways:
2270 the data type of the result is computed and recorded in it,
2271 warnings are generated if arg data types are invalid,
2272 special handling for addition and subtraction of pointers is known,
2273 and some optimization is done (operations on narrow ints
2274 are done in the narrower type when that gives the same result).
2275 Constant folding is also done before the result is returned.
2277 Note that the operands will never have enumeral types, or function
2278 or array types, because either they will have the default conversions
2279 performed or they have both just been converted to some other type in which
2280 the arithmetic is to be done. */
2283 build_binary_op (code, orig_op0, orig_op1, convert_p)
2284 enum tree_code code;
2285 tree orig_op0, orig_op1;
2289 register enum tree_code code0, code1;
2292 /* Expression code to give to the expression when it is built.
2293 Normally this is CODE, which is what the caller asked for,
2294 but in some special cases we change it. */
2295 register enum tree_code resultcode = code;
2297 /* Data type in which the computation is to be performed.
2298 In the simplest cases this is the common type of the arguments. */
2299 register tree result_type = NULL;
2301 /* Nonzero means operands have already been type-converted
2302 in whatever way is necessary.
2303 Zero means they need to be converted to RESULT_TYPE. */
2306 /* Nonzero means after finally constructing the expression
2307 give it this type. Otherwise, give it type RESULT_TYPE. */
2308 tree final_type = 0;
2310 /* Nonzero if this is an operation like MIN or MAX which can
2311 safely be computed in short if both args are promoted shorts.
2312 Also implies COMMON.
2313 -1 indicates a bitwise operation; this makes a difference
2314 in the exact conditions for when it is safe to do the operation
2315 in a narrower mode. */
2318 /* Nonzero if this is a comparison operation;
2319 if both args are promoted shorts, compare the original shorts.
2320 Also implies COMMON. */
2321 int short_compare = 0;
2323 /* Nonzero if this is a right-shift operation, which can be computed on the
2324 original short and then promoted if the operand is a promoted short. */
2325 int short_shift = 0;
2327 /* Nonzero means set RESULT_TYPE to the common type of the args. */
2332 op0 = default_conversion (orig_op0);
2333 op1 = default_conversion (orig_op1);
2341 type0 = TREE_TYPE (op0);
2342 type1 = TREE_TYPE (op1);
2344 /* The expression codes of the data types of the arguments tell us
2345 whether the arguments are integers, floating, pointers, etc. */
2346 code0 = TREE_CODE (type0);
2347 code1 = TREE_CODE (type1);
2349 /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
2350 STRIP_TYPE_NOPS (op0);
2351 STRIP_TYPE_NOPS (op1);
2353 /* If an error was already reported for one of the arguments,
2354 avoid reporting another error. */
2356 if (code0 == ERROR_MARK || code1 == ERROR_MARK)
2357 return error_mark_node;
2362 /* Handle the pointer + int case. */
2363 if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
2364 return pointer_int_sum (PLUS_EXPR, op0, op1);
2365 else if (code1 == POINTER_TYPE && code0 == INTEGER_TYPE)
2366 return pointer_int_sum (PLUS_EXPR, op1, op0);
2372 /* Subtraction of two similar pointers.
2373 We must subtract them as integers, then divide by object size. */
2374 if (code0 == POINTER_TYPE && code1 == POINTER_TYPE
2375 && comp_target_types (type0, type1))
2376 return pointer_diff (op0, op1);
2377 /* Handle pointer minus int. Just like pointer plus int. */
2378 else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
2379 return pointer_int_sum (MINUS_EXPR, op0, op1);
2388 case TRUNC_DIV_EXPR:
2390 case FLOOR_DIV_EXPR:
2391 case ROUND_DIV_EXPR:
2392 case EXACT_DIV_EXPR:
2393 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
2394 || code0 == COMPLEX_TYPE)
2395 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
2396 || code1 == COMPLEX_TYPE))
2398 if (!(code0 == INTEGER_TYPE && code1 == INTEGER_TYPE))
2399 resultcode = RDIV_EXPR;
2401 /* When dividing two signed integers, you have to promote to int.
2402 E.g. (short) -32868 / (short) -1 doesn't fit in a short. */
2403 shorten = TREE_UNSIGNED (op0);
2409 case BIT_ANDTC_EXPR:
2412 if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
2414 /* If one operand is a constant, and the other is a short type
2415 that has been converted to an int,
2416 really do the work in the short type and then convert the
2417 result to int. If we are lucky, the constant will be 0 or 1
2418 in the short type, making the entire operation go away. */
2419 if (TREE_CODE (op0) == INTEGER_CST
2420 && TREE_CODE (op1) == NOP_EXPR
2421 && TYPE_PRECISION (type1) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op1, 0)))
2422 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op1, 0))))
2424 final_type = result_type;
2425 op1 = TREE_OPERAND (op1, 0);
2426 result_type = TREE_TYPE (op1);
2428 if (TREE_CODE (op1) == INTEGER_CST
2429 && TREE_CODE (op0) == NOP_EXPR
2430 && TYPE_PRECISION (type0) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0, 0)))
2431 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0, 0))))
2433 final_type = result_type;
2434 op0 = TREE_OPERAND (op0, 0);
2435 result_type = TREE_TYPE (op0);
2439 case TRUNC_MOD_EXPR:
2440 case FLOOR_MOD_EXPR:
2441 if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
2445 case TRUTH_ANDIF_EXPR:
2446 case TRUTH_ORIF_EXPR:
2447 case TRUTH_AND_EXPR:
2449 case TRUTH_XOR_EXPR:
2450 if ((code0 == INTEGER_TYPE || code0 == POINTER_TYPE
2451 || code0 == REAL_TYPE || code0 == COMPLEX_TYPE)
2452 && (code1 == INTEGER_TYPE || code1 == POINTER_TYPE
2453 || code1 == REAL_TYPE || code1 == COMPLEX_TYPE))
2455 /* Result of these operations is always an int,
2456 but that does not mean the operands should be
2457 converted to ints! */
2458 result_type = integer_type_node;
2459 op0 = truthvalue_conversion (op0);
2460 op1 = truthvalue_conversion (op1);
2465 /* Shift operations: result has same type as first operand;
2466 always convert second operand to int.
2467 Also set SHORT_SHIFT if shifting rightward. */
2470 if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
2472 if (TREE_CODE (op1) == INTEGER_CST)
2474 if (tree_int_cst_lt (op1, integer_zero_node))
2475 warning ("right shift count is negative");
2478 if (TREE_INT_CST_LOW (op1) | TREE_INT_CST_HIGH (op1))
2480 if (TREE_INT_CST_HIGH (op1) != 0
2481 || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1)
2482 >= TYPE_PRECISION (type0)))
2483 warning ("right shift count >= width of type");
2486 /* Use the type of the value to be shifted.
2487 This is what most traditional C compilers do. */
2488 result_type = type0;
2489 /* Unless traditional, convert the shift-count to an integer,
2490 regardless of size of value being shifted. */
2491 if (! flag_traditional)
2493 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
2494 op1 = convert (integer_type_node, op1);
2495 /* Avoid converting op1 to result_type later. */
2502 if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
2504 if (TREE_CODE (op1) == INTEGER_CST)
2506 if (tree_int_cst_lt (op1, integer_zero_node))
2507 warning ("left shift count is negative");
2508 else if (TREE_INT_CST_HIGH (op1) != 0
2509 || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1)
2510 >= TYPE_PRECISION (type0)))
2511 warning ("left shift count >= width of type");
2513 /* Use the type of the value to be shifted.
2514 This is what most traditional C compilers do. */
2515 result_type = type0;
2516 /* Unless traditional, convert the shift-count to an integer,
2517 regardless of size of value being shifted. */
2518 if (! flag_traditional)
2520 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
2521 op1 = convert (integer_type_node, op1);
2522 /* Avoid converting op1 to result_type later. */
2530 if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
2532 if (TREE_CODE (op1) == INTEGER_CST)
2534 if (tree_int_cst_lt (op1, integer_zero_node))
2535 warning ("shift count is negative");
2536 else if (TREE_INT_CST_HIGH (op1) != 0
2537 || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1)
2538 >= TYPE_PRECISION (type0)))
2539 warning ("shift count >= width of type");
2541 /* Use the type of the value to be shifted.
2542 This is what most traditional C compilers do. */
2543 result_type = type0;
2544 /* Unless traditional, convert the shift-count to an integer,
2545 regardless of size of value being shifted. */
2546 if (! flag_traditional)
2548 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
2549 op1 = convert (integer_type_node, op1);
2550 /* Avoid converting op1 to result_type later. */
2558 /* Result of comparison is always int,
2559 but don't convert the args to int! */
2560 result_type = integer_type_node;
2562 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
2563 || code0 == COMPLEX_TYPE)
2564 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
2565 || code1 == COMPLEX_TYPE))
2567 else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
2569 register tree tt0 = TREE_TYPE (type0);
2570 register tree tt1 = TREE_TYPE (type1);
2571 /* Anything compares with void *. void * compares with anything.
2572 Otherwise, the targets must be compatible
2573 and both must be object or both incomplete. */
2574 if (comp_target_types (type0, type1))
2576 else if (TYPE_MAIN_VARIANT (tt0) == void_type_node)
2578 if (pedantic && !integer_zerop (op0)
2579 && TREE_CODE (tt1) == FUNCTION_TYPE)
2580 pedwarn ("ANSI C forbids comparison of `void *' with function pointer");
2582 else if (TYPE_MAIN_VARIANT (tt1) == void_type_node)
2584 if (pedantic && !integer_zerop (op1)
2585 && TREE_CODE (tt0) == FUNCTION_TYPE)
2586 pedwarn ("ANSI C forbids comparison of `void *' with function pointer");
2589 pedwarn ("comparison of distinct pointer types lacks a cast");
2591 else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST
2592 && integer_zerop (op1))
2593 op1 = null_pointer_node;
2594 else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST
2595 && integer_zerop (op0))
2596 op0 = null_pointer_node;
2597 else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
2599 if (! flag_traditional)
2600 pedwarn ("comparison between pointer and integer");
2601 op1 = convert (TREE_TYPE (op0), op1);
2603 else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
2605 if (! flag_traditional)
2606 pedwarn ("comparison between pointer and integer");
2607 op0 = convert (TREE_TYPE (op1), op0);
2610 /* If args are not valid, clear out RESULT_TYPE
2611 to cause an error message later. */
2617 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
2618 || code0 == COMPLEX_TYPE)
2619 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
2620 || code1 == COMPLEX_TYPE))
2622 else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
2624 if (! comp_target_types (type0, type1))
2625 pedwarn ("comparison of distinct pointer types lacks a cast");
2627 && TREE_CODE (TREE_TYPE (type0)) == FUNCTION_TYPE)
2628 pedwarn ("ANSI C forbids ordered comparisons of pointers to functions");
2629 result_type = common_type (type0, type1);
2637 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
2638 || code0 == COMPLEX_TYPE)
2639 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
2640 || code1 == COMPLEX_TYPE))
2642 else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
2644 if (! comp_target_types (type0, type1))
2645 pedwarn ("comparison of distinct pointer types lacks a cast");
2646 else if ((TYPE_SIZE (TREE_TYPE (type0)) != 0)
2647 != (TYPE_SIZE (TREE_TYPE (type1)) != 0))
2648 pedwarn ("comparison of complete and incomplete pointers");
2650 && TREE_CODE (TREE_TYPE (type0)) == FUNCTION_TYPE)
2651 pedwarn ("ANSI C forbids ordered comparisons of pointers to functions");
2652 result_type = integer_type_node;
2654 else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST
2655 && integer_zerop (op1))
2657 result_type = integer_type_node;
2658 op1 = null_pointer_node;
2659 if (! flag_traditional)
2660 pedwarn ("ordered comparison of pointer with integer zero");
2662 else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST
2663 && integer_zerop (op0))
2665 result_type = integer_type_node;
2666 op0 = null_pointer_node;
2668 pedwarn ("ordered comparison of pointer with integer zero");
2670 else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
2672 result_type = integer_type_node;
2673 if (! flag_traditional)
2674 pedwarn ("comparison between pointer and integer");
2675 op1 = convert (TREE_TYPE (op0), op1);
2677 else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
2679 result_type = integer_type_node;
2680 if (! flag_traditional)
2681 pedwarn ("comparison between pointer and integer");
2682 op0 = convert (TREE_TYPE (op1), op0);
2688 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == COMPLEX_TYPE)
2690 (code1 == INTEGER_TYPE || code1 == REAL_TYPE || code1 == COMPLEX_TYPE))
2692 int none_complex = (code0 != COMPLEX_TYPE && code1 != COMPLEX_TYPE);
2694 if (shorten || common || short_compare)
2695 result_type = common_type (type0, type1);
2697 /* For certain operations (which identify themselves by shorten != 0)
2698 if both args were extended from the same smaller type,
2699 do the arithmetic in that type and then extend.
2701 shorten !=0 and !=1 indicates a bitwise operation.
2702 For them, this optimization is safe only if
2703 both args are zero-extended or both are sign-extended.
2704 Otherwise, we might change the result.
2705 Eg, (short)-1 | (unsigned short)-1 is (int)-1
2706 but calculated in (unsigned short) it would be (unsigned short)-1. */
2708 if (shorten && none_complex)
2710 int unsigned0, unsigned1;
2711 tree arg0 = get_narrower (op0, &unsigned0);
2712 tree arg1 = get_narrower (op1, &unsigned1);
2713 /* UNS is 1 if the operation to be done is an unsigned one. */
2714 int uns = TREE_UNSIGNED (result_type);
2717 final_type = result_type;
2719 /* Handle the case that OP0 (or OP1) does not *contain* a conversion
2720 but it *requires* conversion to FINAL_TYPE. */
2722 if ((TYPE_PRECISION (TREE_TYPE (op0))
2723 == TYPE_PRECISION (TREE_TYPE (arg0)))
2724 && TREE_TYPE (op0) != final_type)
2725 unsigned0 = TREE_UNSIGNED (TREE_TYPE (op0));
2726 if ((TYPE_PRECISION (TREE_TYPE (op1))
2727 == TYPE_PRECISION (TREE_TYPE (arg1)))
2728 && TREE_TYPE (op1) != final_type)
2729 unsigned1 = TREE_UNSIGNED (TREE_TYPE (op1));
2731 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
2733 /* For bitwise operations, signedness of nominal type
2734 does not matter. Consider only how operands were extended. */
2738 /* Note that in all three cases below we refrain from optimizing
2739 an unsigned operation on sign-extended args.
2740 That would not be valid. */
2742 /* Both args variable: if both extended in same way
2743 from same width, do it in that width.
2744 Do it unsigned if args were zero-extended. */
2745 if ((TYPE_PRECISION (TREE_TYPE (arg0))
2746 < TYPE_PRECISION (result_type))
2747 && (TYPE_PRECISION (TREE_TYPE (arg1))
2748 == TYPE_PRECISION (TREE_TYPE (arg0)))
2749 && unsigned0 == unsigned1
2750 && (unsigned0 || !uns))
2752 = signed_or_unsigned_type (unsigned0,
2753 common_type (TREE_TYPE (arg0), TREE_TYPE (arg1)));
2754 else if (TREE_CODE (arg0) == INTEGER_CST
2755 && (unsigned1 || !uns)
2756 && (TYPE_PRECISION (TREE_TYPE (arg1))
2757 < TYPE_PRECISION (result_type))
2758 && (type = signed_or_unsigned_type (unsigned1,
2760 int_fits_type_p (arg0, type)))
2762 else if (TREE_CODE (arg1) == INTEGER_CST
2763 && (unsigned0 || !uns)
2764 && (TYPE_PRECISION (TREE_TYPE (arg0))
2765 < TYPE_PRECISION (result_type))
2766 && (type = signed_or_unsigned_type (unsigned0,
2768 int_fits_type_p (arg1, type)))
2772 /* Shifts can be shortened if shifting right. */
2777 tree arg0 = get_narrower (op0, &unsigned_arg);
2779 final_type = result_type;
2781 if (arg0 == op0 && final_type == TREE_TYPE (op0))
2782 unsigned_arg = TREE_UNSIGNED (TREE_TYPE (op0));
2784 if (TYPE_PRECISION (TREE_TYPE (arg0)) < TYPE_PRECISION (result_type)
2785 /* If arg is sign-extended and then unsigned-shifted,
2786 we can simulate this with a signed shift in arg's type
2787 only if the extended result is at least twice as wide
2788 as the arg. Otherwise, the shift could use up all the
2789 ones made by sign-extension and bring in zeros.
2790 We can't optimize that case at all, but in most machines
2791 it never happens because available widths are 2**N. */
2792 && (!TREE_UNSIGNED (final_type)
2794 || 2 * TYPE_PRECISION (TREE_TYPE (arg0)) <= TYPE_PRECISION (result_type)))
2796 /* Do an unsigned shift if the operand was zero-extended. */
2798 = signed_or_unsigned_type (unsigned_arg,
2800 /* Convert value-to-be-shifted to that type. */
2801 if (TREE_TYPE (op0) != result_type)
2802 op0 = convert (result_type, op0);
2807 /* Comparison operations are shortened too but differently.
2808 They identify themselves by setting short_compare = 1. */
2810 if (short_compare && none_complex)
2812 /* Don't write &op0, etc., because that would prevent op0
2813 from being kept in a register.
2814 Instead, make copies of the our local variables and
2815 pass the copies by reference, then copy them back afterward. */
2816 tree xop0 = op0, xop1 = op1, xresult_type = result_type;
2817 enum tree_code xresultcode = resultcode;
2819 = shorten_compare (&xop0, &xop1, &xresult_type, &xresultcode);
2822 op0 = xop0, op1 = xop1, result_type = xresult_type;
2823 resultcode = xresultcode;
2827 tree op0_type = TREE_TYPE (orig_op0);
2828 tree op1_type = TREE_TYPE (orig_op1);
2829 int op0_unsigned = TREE_UNSIGNED (op0_type);
2830 int op1_unsigned = TREE_UNSIGNED (op1_type);
2832 /* Give warnings for comparisons between signed and unsigned
2833 quantities that will fail. Do not warn if the signed quantity
2834 is an unsuffixed integer literal (or some static constant
2835 expression involving such literals) and it is positive.
2836 Do not warn if the width of the unsigned quantity is less
2837 than that of the signed quantity, since in this case all
2838 values of the unsigned quantity fit in the signed quantity.
2839 Do not warn if the signed type is the same size as the
2840 result_type since sign extension does not cause trouble in
2842 /* Do the checking based on the original operand trees, so that
2843 casts will be considered, but default promotions won't be. */
2844 if (op0_unsigned != op1_unsigned
2846 && TYPE_PRECISION (op0_type) >= TYPE_PRECISION (op1_type)
2847 && TYPE_PRECISION (op0_type) < TYPE_PRECISION (result_type)
2848 && (TREE_CODE (op1) != INTEGER_CST
2849 || (TREE_CODE (op1) == INTEGER_CST
2850 && INT_CST_LT (op1, integer_zero_node))))
2853 && TYPE_PRECISION (op1_type) >= TYPE_PRECISION (op0_type)
2854 && TYPE_PRECISION (op1_type) < TYPE_PRECISION (result_type)
2855 && (TREE_CODE (op0) != INTEGER_CST
2856 || (TREE_CODE (op0) == INTEGER_CST
2857 && INT_CST_LT (op0, integer_zero_node))))))
2858 warning ("comparison between signed and unsigned");
2863 /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
2864 If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
2865 Then the expression will be built.
2866 It will be given type FINAL_TYPE if that is nonzero;
2867 otherwise, it will be given type RESULT_TYPE. */
2871 binary_op_error (code);
2872 return error_mark_node;
2877 if (TREE_TYPE (op0) != result_type)
2878 op0 = convert (result_type, op0);
2879 if (TREE_TYPE (op1) != result_type)
2880 op1 = convert (result_type, op1);
2884 register tree result = build (resultcode, result_type, op0, op1);
2885 register tree folded;
2887 folded = fold (result);
2888 if (folded == result)
2889 TREE_CONSTANT (folded) = TREE_CONSTANT (op0) & TREE_CONSTANT (op1);
2890 if (final_type != 0)
2891 return convert (final_type, folded);
2896 /* Return a tree for the sum or difference (RESULTCODE says which)
2897 of pointer PTROP and integer INTOP. */
2900 pointer_int_sum (resultcode, ptrop, intop)
2901 enum tree_code resultcode;
2902 register tree ptrop, intop;
2906 register tree result;
2907 register tree folded;
2909 /* The result is a pointer of the same type that is being added. */
2911 register tree result_type = TREE_TYPE (ptrop);
2913 if (TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE)
2915 if (pedantic || warn_pointer_arith)
2916 pedwarn ("pointer of type `void *' used in arithmetic");
2917 size_exp = integer_one_node;
2919 else if (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE)
2921 if (pedantic || warn_pointer_arith)
2922 pedwarn ("pointer to a function used in arithmetic");
2923 size_exp = integer_one_node;
2926 size_exp = c_size_in_bytes (TREE_TYPE (result_type));
2928 /* If what we are about to multiply by the size of the elements
2929 contains a constant term, apply distributive law
2930 and multiply that constant term separately.
2931 This helps produce common subexpressions. */
2933 if ((TREE_CODE (intop) == PLUS_EXPR || TREE_CODE (intop) == MINUS_EXPR)
2934 && ! TREE_CONSTANT (intop)
2935 && TREE_CONSTANT (TREE_OPERAND (intop, 1))
2936 && TREE_CONSTANT (size_exp)
2937 /* If the constant comes from pointer subtraction,
2938 skip this optimization--it would cause an error. */
2939 && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop, 0))) == INTEGER_TYPE)
2941 enum tree_code subcode = resultcode;
2942 tree int_type = TREE_TYPE (intop);
2943 if (TREE_CODE (intop) == MINUS_EXPR)
2944 subcode = (subcode == PLUS_EXPR ? MINUS_EXPR : PLUS_EXPR);
2945 /* Convert both subexpression types to the type of intop,
2946 because weird cases involving pointer arithmetic
2947 can result in a sum or difference with different type args. */
2948 ptrop = build_binary_op (subcode, ptrop,
2949 convert (int_type, TREE_OPERAND (intop, 1)), 1);
2950 intop = convert (int_type, TREE_OPERAND (intop, 0));
2953 /* Convert the integer argument to a type the same size as a pointer
2954 so the multiply won't overflow spuriously. */
2956 if (TYPE_PRECISION (TREE_TYPE (intop)) != POINTER_SIZE)
2957 intop = convert (type_for_size (POINTER_SIZE, 0), intop);
2959 /* Replace the integer argument
2960 with a suitable product by the object size. */
2962 intop = build_binary_op (MULT_EXPR, intop, size_exp, 1);
2964 /* Create the sum or difference. */
2966 result = build (resultcode, result_type, ptrop, intop);
2968 folded = fold (result);
2969 if (folded == result)
2970 TREE_CONSTANT (folded) = TREE_CONSTANT (ptrop) & TREE_CONSTANT (intop);
2974 /* Return a tree for the difference of pointers OP0 and OP1.
2975 The resulting tree has type int. */
2978 pointer_diff (op0, op1)
2979 register tree op0, op1;
2981 register tree result, folded;
2982 tree restype = ptrdiff_type_node;
2984 tree target_type = TREE_TYPE (TREE_TYPE (op0));
2986 if (pedantic || warn_pointer_arith)
2988 if (TREE_CODE (target_type) == VOID_TYPE)
2989 pedwarn ("pointer of type `void *' used in subtraction");
2990 if (TREE_CODE (target_type) == FUNCTION_TYPE)
2991 pedwarn ("pointer to a function used in subtraction");
2994 /* First do the subtraction as integers;
2995 then drop through to build the divide operator. */
2997 op0 = build_binary_op (MINUS_EXPR, convert (restype, op0),
2998 convert (restype, op1), 1);
2999 /* This generates an error if op1 is pointer to incomplete type. */
3000 if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (op1))) == 0)
3001 error ("arithmetic on pointer to an incomplete type");
3002 /* This generates an error if op0 is pointer to incomplete type. */
3003 op1 = c_size_in_bytes (target_type);
3005 /* Divide by the size, in easiest possible way. */
3007 result = build (EXACT_DIV_EXPR, restype, op0, op1);
3009 folded = fold (result);
3010 if (folded == result)
3011 TREE_CONSTANT (folded) = TREE_CONSTANT (op0) & TREE_CONSTANT (op1);
3015 /* Construct and perhaps optimize a tree representation
3016 for a unary operation. CODE, a tree_code, specifies the operation
3017 and XARG is the operand. NOCONVERT nonzero suppresses
3018 the default promotions (such as from short to int). */
3021 build_unary_op (code, xarg, noconvert)
3022 enum tree_code code;
3026 /* No default_conversion here. It causes trouble for ADDR_EXPR. */
3027 register tree arg = xarg;
3028 register tree argtype = 0;
3029 register enum tree_code typecode = TREE_CODE (TREE_TYPE (arg));
3030 char *errstring = NULL;
3033 if (typecode == ERROR_MARK)
3034 return error_mark_node;
3035 if (typecode == ENUMERAL_TYPE)
3036 typecode = INTEGER_TYPE;
3041 /* This is used for unary plus, because a CONVERT_EXPR
3042 is enough to prevent anybody from looking inside for
3043 associativity, but won't generate any code. */
3044 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
3045 || typecode == COMPLEX_TYPE))
3046 errstring = "wrong type argument to unary plus";
3047 else if (!noconvert)
3048 arg = default_conversion (arg);
3052 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
3053 || typecode == COMPLEX_TYPE))
3054 errstring = "wrong type argument to unary minus";
3055 else if (!noconvert)
3056 arg = default_conversion (arg);
3060 if (typecode == COMPLEX_TYPE)
3064 arg = default_conversion (arg);
3066 else if (typecode != INTEGER_TYPE)
3067 errstring = "wrong type argument to bit-complement";
3068 else if (!noconvert)
3069 arg = default_conversion (arg);
3073 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
3074 || typecode == COMPLEX_TYPE))
3075 errstring = "wrong type argument to abs";
3076 else if (!noconvert)
3077 arg = default_conversion (arg);
3081 /* Conjugating a real value is a no-op, but allow it anyway. */
3082 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
3083 || typecode == COMPLEX_TYPE))
3084 errstring = "wrong type argument to conjugation";
3085 else if (!noconvert)
3086 arg = default_conversion (arg);
3089 case TRUTH_NOT_EXPR:
3090 if (typecode != INTEGER_TYPE
3091 && typecode != REAL_TYPE && typecode != POINTER_TYPE
3092 && typecode != COMPLEX_TYPE
3093 /* These will convert to a pointer. */
3094 && typecode != ARRAY_TYPE && typecode != FUNCTION_TYPE)
3096 errstring = "wrong type argument to unary exclamation mark";
3099 arg = truthvalue_conversion (arg);
3100 return invert_truthvalue (arg);
3106 if (TREE_CODE (arg) == COMPLEX_CST)
3107 return TREE_REALPART (arg);
3108 else if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE)
3109 return fold (build1 (REALPART_EXPR, TREE_TYPE (TREE_TYPE (arg)), arg));
3114 if (TREE_CODE (arg) == COMPLEX_CST)
3115 return TREE_IMAGPART (arg);
3116 else if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE)
3117 return fold (build1 (IMAGPART_EXPR, TREE_TYPE (TREE_TYPE (arg)), arg));
3119 return convert (TREE_TYPE (arg), integer_zero_node);
3121 case PREINCREMENT_EXPR:
3122 case POSTINCREMENT_EXPR:
3123 case PREDECREMENT_EXPR:
3124 case POSTDECREMENT_EXPR:
3125 /* Handle complex lvalues (when permitted)
3126 by reduction to simpler cases. */
3128 val = unary_complex_lvalue (code, arg);
3132 /* Increment or decrement the real part of the value,
3133 and don't change the imaginary part. */
3134 if (typecode == COMPLEX_TYPE)
3138 arg = stabilize_reference (arg);
3139 real = build_unary_op (REALPART_EXPR, arg, 1);
3140 imag = build_unary_op (IMAGPART_EXPR, arg, 1);
3141 return build (COMPLEX_EXPR, TREE_TYPE (arg),
3142 build_unary_op (code, real, 1), imag);
3145 /* Report invalid types. */
3147 if (typecode != POINTER_TYPE
3148 && typecode != INTEGER_TYPE && typecode != REAL_TYPE)
3150 if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
3151 errstring ="wrong type argument to increment";
3153 errstring ="wrong type argument to decrement";
3159 tree result_type = TREE_TYPE (arg);
3161 arg = get_unwidened (arg, 0);
3162 argtype = TREE_TYPE (arg);
3164 /* Compute the increment. */
3166 if (typecode == POINTER_TYPE)
3168 /* If pointer target is an undefined struct,
3169 we just cannot know how to do the arithmetic. */
3170 if (TYPE_SIZE (TREE_TYPE (result_type)) == 0)
3171 error ("%s of pointer to unknown structure",
3172 ((code == PREINCREMENT_EXPR
3173 || code == POSTINCREMENT_EXPR)
3174 ? "increment" : "decrement"));
3175 else if ((pedantic || warn_pointer_arith)
3176 && (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE
3177 || TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE))
3178 pedwarn ("wrong type argument to %s",
3179 ((code == PREINCREMENT_EXPR
3180 || code == POSTINCREMENT_EXPR)
3181 ? "increment" : "decrement"));
3182 inc = c_sizeof_nowarn (TREE_TYPE (result_type));
3185 inc = integer_one_node;
3187 inc = convert (argtype, inc);
3189 /* Handle incrementing a cast-expression. */
3192 switch (TREE_CODE (arg))
3197 case FIX_TRUNC_EXPR:
3198 case FIX_FLOOR_EXPR:
3199 case FIX_ROUND_EXPR:
3201 pedantic_lvalue_warning (CONVERT_EXPR);
3202 /* If the real type has the same machine representation
3203 as the type it is cast to, we can make better output
3204 by adding directly to the inside of the cast. */
3205 if ((TREE_CODE (TREE_TYPE (arg))
3206 == TREE_CODE (TREE_TYPE (TREE_OPERAND (arg, 0))))
3207 && (TYPE_MODE (TREE_TYPE (arg))
3208 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (arg, 0)))))
3209 arg = TREE_OPERAND (arg, 0);
3212 tree incremented, modify, value;
3213 arg = stabilize_reference (arg);
3214 if (code == PREINCREMENT_EXPR || code == PREDECREMENT_EXPR)
3217 value = save_expr (arg);
3218 incremented = build (((code == PREINCREMENT_EXPR
3219 || code == POSTINCREMENT_EXPR)
3220 ? PLUS_EXPR : MINUS_EXPR),
3221 argtype, value, inc);
3222 TREE_SIDE_EFFECTS (incremented) = 1;
3223 modify = build_modify_expr (arg, NOP_EXPR, incremented);
3224 value = build (COMPOUND_EXPR, TREE_TYPE (arg), modify, value);
3225 TREE_USED (value) = 1;
3235 /* Complain about anything else that is not a true lvalue. */
3236 if (!lvalue_or_else (arg, ((code == PREINCREMENT_EXPR
3237 || code == POSTINCREMENT_EXPR)
3238 ? "increment" : "decrement")))
3239 return error_mark_node;
3241 /* Report a read-only lvalue. */
3242 if (TREE_READONLY (arg))
3243 readonly_warning (arg,
3244 ((code == PREINCREMENT_EXPR
3245 || code == POSTINCREMENT_EXPR)
3246 ? "increment" : "decrement"));
3248 val = build (code, TREE_TYPE (arg), arg, inc);
3249 TREE_SIDE_EFFECTS (val) = 1;
3250 val = convert (result_type, val);
3251 if (TREE_CODE (val) != code)
3252 TREE_NO_UNUSED_WARNING (val) = 1;
3257 /* Note that this operation never does default_conversion
3258 regardless of NOCONVERT. */
3260 /* Let &* cancel out to simplify resulting code. */
3261 if (TREE_CODE (arg) == INDIRECT_REF)
3263 /* Don't let this be an lvalue. */
3264 if (lvalue_p (TREE_OPERAND (arg, 0)))
3265 return non_lvalue (TREE_OPERAND (arg, 0));
3266 return TREE_OPERAND (arg, 0);
3269 /* For &x[y], return x+y */
3270 if (TREE_CODE (arg) == ARRAY_REF)
3272 if (mark_addressable (TREE_OPERAND (arg, 0)) == 0)
3273 return error_mark_node;
3274 return build_binary_op (PLUS_EXPR, TREE_OPERAND (arg, 0),
3275 TREE_OPERAND (arg, 1), 1);
3278 /* Handle complex lvalues (when permitted)
3279 by reduction to simpler cases. */
3280 val = unary_complex_lvalue (code, arg);
3284 #if 0 /* Turned off because inconsistent;
3285 float f; *&(int)f = 3.4 stores in int format
3286 whereas (int)f = 3.4 stores in float format. */
3287 /* Address of a cast is just a cast of the address
3288 of the operand of the cast. */
3289 switch (TREE_CODE (arg))
3294 case FIX_TRUNC_EXPR:
3295 case FIX_FLOOR_EXPR:
3296 case FIX_ROUND_EXPR:
3299 pedwarn ("ANSI C forbids the address of a cast expression");
3300 return convert (build_pointer_type (TREE_TYPE (arg)),
3301 build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0),
3306 /* Allow the address of a constructor if all the elements
3308 if (TREE_CODE (arg) == CONSTRUCTOR && TREE_CONSTANT (arg))
3310 /* Anything not already handled and not a true memory reference
3312 else if (typecode != FUNCTION_TYPE && !lvalue_or_else (arg, "unary `&'"))
3313 return error_mark_node;
3315 /* Ordinary case; arg is a COMPONENT_REF or a decl. */
3316 argtype = TREE_TYPE (arg);
3317 /* If the lvalue is const or volatile,
3318 merge that into the type that the address will point to. */
3319 if (TREE_CODE_CLASS (TREE_CODE (arg)) == 'd'
3320 || TREE_CODE_CLASS (TREE_CODE (arg)) == 'r')
3322 if (TREE_READONLY (arg) || TREE_THIS_VOLATILE (arg))
3323 argtype = c_build_type_variant (argtype,
3324 TREE_READONLY (arg),
3325 TREE_THIS_VOLATILE (arg));
3328 argtype = build_pointer_type (argtype);
3330 if (mark_addressable (arg) == 0)
3331 return error_mark_node;
3336 if (TREE_CODE (arg) == COMPONENT_REF)
3338 tree field = TREE_OPERAND (arg, 1);
3340 addr = build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0), 0);
3342 if (DECL_BIT_FIELD (field))
3344 error ("attempt to take address of bit-field structure member `%s'",
3345 IDENTIFIER_POINTER (DECL_NAME (field)));
3346 return error_mark_node;
3349 addr = convert (argtype, addr);
3351 if (! integer_zerop (DECL_FIELD_BITPOS (field)))
3354 = size_binop (EASY_DIV_EXPR, DECL_FIELD_BITPOS (field),
3355 size_int (BITS_PER_UNIT));
3356 int flag = TREE_CONSTANT (addr);
3357 addr = fold (build (PLUS_EXPR, argtype,
3358 addr, convert (argtype, offset)));
3359 TREE_CONSTANT (addr) = flag;
3363 addr = build1 (code, argtype, arg);
3365 /* Address of a static or external variable or
3366 file-scope function counts as a constant. */
3368 && ! (TREE_CODE (arg) == FUNCTION_DECL
3369 && DECL_CONTEXT (arg) != 0))
3370 TREE_CONSTANT (addr) = 1;
3378 argtype = TREE_TYPE (arg);
3379 return fold (build1 (code, argtype, arg));
3383 return error_mark_node;
3387 /* If CONVERSIONS is a conversion expression or a nested sequence of such,
3388 convert ARG with the same conversions in the same order
3389 and return the result. */
3392 convert_sequence (conversions, arg)
3396 switch (TREE_CODE (conversions))
3401 case FIX_TRUNC_EXPR:
3402 case FIX_FLOOR_EXPR:
3403 case FIX_ROUND_EXPR:
3405 return convert (TREE_TYPE (conversions),
3406 convert_sequence (TREE_OPERAND (conversions, 0),
3415 /* Return nonzero if REF is an lvalue valid for this language.
3416 Lvalues can be assigned, unless their type has TYPE_READONLY.
3417 Lvalues can have their address taken, unless they have DECL_REGISTER. */
3423 register enum tree_code code = TREE_CODE (ref);
3430 return lvalue_p (TREE_OPERAND (ref, 0));
3441 if (TREE_CODE (TREE_TYPE (ref)) != FUNCTION_TYPE
3442 && TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE)
3449 /* Return nonzero if REF is an lvalue valid for this language;
3450 otherwise, print an error message and return zero. */
3453 lvalue_or_else (ref, string)
3457 int win = lvalue_p (ref);
3459 error ("invalid lvalue in %s", string);
3463 /* Apply unary lvalue-demanding operator CODE to the expression ARG
3464 for certain kinds of expressions which are not really lvalues
3465 but which we can accept as lvalues.
3467 If ARG is not a kind of expression we can handle, return zero. */
3470 unary_complex_lvalue (code, arg)
3471 enum tree_code code;
3474 /* Handle (a, b) used as an "lvalue". */
3475 if (TREE_CODE (arg) == COMPOUND_EXPR)
3477 tree real_result = build_unary_op (code, TREE_OPERAND (arg, 1), 0);
3478 pedantic_lvalue_warning (COMPOUND_EXPR);
3479 return build (COMPOUND_EXPR, TREE_TYPE (real_result),
3480 TREE_OPERAND (arg, 0), real_result);
3483 /* Handle (a ? b : c) used as an "lvalue". */
3484 if (TREE_CODE (arg) == COND_EXPR)
3486 pedantic_lvalue_warning (COND_EXPR);
3487 return (build_conditional_expr
3488 (TREE_OPERAND (arg, 0),
3489 build_unary_op (code, TREE_OPERAND (arg, 1), 0),
3490 build_unary_op (code, TREE_OPERAND (arg, 2), 0)));
3496 /* If pedantic, warn about improper lvalue. CODE is either COND_EXPR
3497 COMPOUND_EXPR, or CONVERT_EXPR (for casts). */
3500 pedantic_lvalue_warning (code)
3501 enum tree_code code;
3504 pedwarn ("ANSI C forbids use of %s expressions as lvalues",
3505 code == COND_EXPR ? "conditional"
3506 : code == COMPOUND_EXPR ? "compound" : "cast");
3509 /* Warn about storing in something that is `const'. */
3512 readonly_warning (arg, string)
3517 strcpy (buf, string);
3519 /* Forbid assignments to iterators. */
3520 if (TREE_CODE (arg) == VAR_DECL && ITERATOR_P (arg))
3522 strcat (buf, " of iterator `%s'");
3523 pedwarn (buf, IDENTIFIER_POINTER (DECL_NAME (arg)));
3526 if (TREE_CODE (arg) == COMPONENT_REF)
3528 if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg, 0))))
3529 readonly_warning (TREE_OPERAND (arg, 0), string);
3532 strcat (buf, " of read-only member `%s'");
3533 pedwarn (buf, IDENTIFIER_POINTER (DECL_NAME (TREE_OPERAND (arg, 1))));
3536 else if (TREE_CODE (arg) == VAR_DECL)
3538 strcat (buf, " of read-only variable `%s'");
3539 pedwarn (buf, IDENTIFIER_POINTER (DECL_NAME (arg)));
3543 pedwarn ("%s of read-only location", buf);
3547 /* Mark EXP saying that we need to be able to take the
3548 address of it; it should not be allocated in a register.
3549 Value is 1 if successful. */
3552 mark_addressable (exp)
3555 register tree x = exp;
3557 switch (TREE_CODE (x))
3562 x = TREE_OPERAND (x, 0);
3566 TREE_ADDRESSABLE (x) = 1;
3573 if (DECL_REGISTER (x) && !TREE_ADDRESSABLE (x)
3574 && DECL_NONLOCAL (x))
3576 if (TREE_PUBLIC (x))
3578 error ("global register variable `%s' used in nested function",
3579 IDENTIFIER_POINTER (DECL_NAME (x)));
3582 pedwarn ("register variable `%s' used in nested function",
3583 IDENTIFIER_POINTER (DECL_NAME (x)));
3585 else if (DECL_REGISTER (x) && !TREE_ADDRESSABLE (x))
3587 if (TREE_PUBLIC (x))
3589 error ("address of global register variable `%s' requested",
3590 IDENTIFIER_POINTER (DECL_NAME (x)));
3593 pedwarn ("address of register variable `%s' requested",
3594 IDENTIFIER_POINTER (DECL_NAME (x)));
3596 put_var_into_stack (x);
3600 TREE_ADDRESSABLE (x) = 1;
3601 #if 0 /* poplevel deals with this now. */
3602 if (DECL_CONTEXT (x) == 0)
3603 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (x)) = 1;
3611 /* Build and return a conditional expression IFEXP ? OP1 : OP2. */
3614 build_conditional_expr (ifexp, op1, op2)
3615 tree ifexp, op1, op2;
3617 register tree type1;
3618 register tree type2;
3619 register enum tree_code code1;
3620 register enum tree_code code2;
3621 register tree result_type = NULL;
3623 /* If second operand is omitted, it is the same as the first one;
3624 make sure it is calculated only once. */
3628 pedwarn ("ANSI C forbids omitting the middle term of a ?: expression");
3629 ifexp = op1 = save_expr (ifexp);
3632 ifexp = truthvalue_conversion (default_conversion (ifexp));
3634 #if 0 /* Produces wrong result if within sizeof. */
3635 /* Don't promote the operands separately if they promote
3636 the same way. Return the unpromoted type and let the combined
3637 value get promoted if necessary. */
3639 if (TREE_TYPE (op1) == TREE_TYPE (op2)
3640 && TREE_CODE (TREE_TYPE (op1)) != ARRAY_TYPE
3641 && TREE_CODE (TREE_TYPE (op1)) != ENUMERAL_TYPE
3642 && TREE_CODE (TREE_TYPE (op1)) != FUNCTION_TYPE)
3644 if (TREE_CODE (ifexp) == INTEGER_CST)
3645 return pedantic_non_lvalue (integer_zerop (ifexp) ? op2 : op1);
3647 return fold (build (COND_EXPR, TREE_TYPE (op1), ifexp, op1, op2));
3651 /* Promote both alternatives. */
3653 if (TREE_CODE (TREE_TYPE (op1)) != VOID_TYPE)
3654 op1 = default_conversion (op1);
3655 if (TREE_CODE (TREE_TYPE (op2)) != VOID_TYPE)
3656 op2 = default_conversion (op2);
3658 if (TREE_CODE (ifexp) == ERROR_MARK
3659 || TREE_CODE (TREE_TYPE (op1)) == ERROR_MARK
3660 || TREE_CODE (TREE_TYPE (op2)) == ERROR_MARK)
3661 return error_mark_node;
3663 type1 = TREE_TYPE (op1);
3664 code1 = TREE_CODE (type1);
3665 type2 = TREE_TYPE (op2);
3666 code2 = TREE_CODE (type2);
3668 /* Quickly detect the usual case where op1 and op2 have the same type
3670 if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2))
3673 result_type = type1;
3675 result_type = TYPE_MAIN_VARIANT (type1);
3677 else if ((code1 == INTEGER_TYPE || code1 == REAL_TYPE)
3678 && (code2 == INTEGER_TYPE || code2 == REAL_TYPE))
3680 result_type = common_type (type1, type2);
3682 else if (code1 == VOID_TYPE || code2 == VOID_TYPE)
3684 if (pedantic && (code1 != VOID_TYPE || code2 != VOID_TYPE))
3685 pedwarn ("ANSI C forbids conditional expr with only one void side");
3686 result_type = void_type_node;
3688 else if (code1 == POINTER_TYPE && code2 == POINTER_TYPE)
3690 if (comp_target_types (type1, type2))
3691 result_type = common_type (type1, type2);
3692 else if (integer_zerop (op1) && TREE_TYPE (type1) == void_type_node)
3693 result_type = qualify_type (type2, type1);
3694 else if (integer_zerop (op2) && TREE_TYPE (type2) == void_type_node)
3695 result_type = qualify_type (type1, type2);
3696 else if (TYPE_MAIN_VARIANT (TREE_TYPE (type1)) == void_type_node)
3698 if (pedantic && TREE_CODE (TREE_TYPE (type2)) == FUNCTION_TYPE)
3699 pedwarn ("ANSI C forbids conditional expr between `void *' and function pointer");
3700 result_type = qualify_type (type1, type2);
3702 else if (TYPE_MAIN_VARIANT (TREE_TYPE (type2)) == void_type_node)
3704 if (pedantic && TREE_CODE (TREE_TYPE (type1)) == FUNCTION_TYPE)
3705 pedwarn ("ANSI C forbids conditional expr between `void *' and function pointer");
3706 result_type = qualify_type (type2, type1);
3710 pedwarn ("pointer type mismatch in conditional expression");
3711 result_type = build_pointer_type (void_type_node);
3714 else if (code1 == POINTER_TYPE && code2 == INTEGER_TYPE)
3716 if (! integer_zerop (op2))
3717 pedwarn ("pointer/integer type mismatch in conditional expression");
3720 op2 = null_pointer_node;
3721 #if 0 /* The spec seems to say this is permitted. */
3722 if (pedantic && TREE_CODE (type1) == FUNCTION_TYPE)
3723 pedwarn ("ANSI C forbids conditional expr between 0 and function pointer");
3726 result_type = type1;
3728 else if (code2 == POINTER_TYPE && code1 == INTEGER_TYPE)
3730 if (!integer_zerop (op1))
3731 pedwarn ("pointer/integer type mismatch in conditional expression");
3734 op1 = null_pointer_node;
3735 #if 0 /* The spec seems to say this is permitted. */
3736 if (pedantic && TREE_CODE (type2) == FUNCTION_TYPE)
3737 pedwarn ("ANSI C forbids conditional expr between 0 and function pointer");
3740 result_type = type2;
3745 if (flag_cond_mismatch)
3746 result_type = void_type_node;
3749 error ("type mismatch in conditional expression");
3750 return error_mark_node;
3754 /* Merge const and volatile flags of the incoming types. */
3756 = build_type_variant (result_type,
3757 TREE_READONLY (op1) || TREE_READONLY (op2),
3758 TREE_THIS_VOLATILE (op1) || TREE_THIS_VOLATILE (op2));
3760 if (result_type != TREE_TYPE (op1))
3761 op1 = convert_and_check (result_type, op1);
3762 if (result_type != TREE_TYPE (op2))
3763 op2 = convert_and_check (result_type, op2);
3766 if (code1 == RECORD_TYPE || code1 == UNION_TYPE)
3768 result_type = TREE_TYPE (op1);
3769 if (TREE_CONSTANT (ifexp))
3770 return pedantic_non_lvalue (integer_zerop (ifexp) ? op2 : op1);
3772 if (TYPE_MODE (result_type) == BLKmode)
3774 register tree tempvar
3775 = build_decl (VAR_DECL, NULL_TREE, result_type);
3776 register tree xop1 = build_modify_expr (tempvar, op1);
3777 register tree xop2 = build_modify_expr (tempvar, op2);
3778 register tree result = fold (build (COND_EXPR, result_type,
3779 ifexp, xop1, xop2));
3781 layout_decl (tempvar, TYPE_ALIGN (result_type));
3782 /* No way to handle variable-sized objects here.
3783 I fear that the entire handling of BLKmode conditional exprs
3784 needs to be redone. */
3785 if (TREE_CODE (DECL_SIZE (tempvar)) != INTEGER_CST)
3788 = assign_stack_local (DECL_MODE (tempvar),
3789 (TREE_INT_CST_LOW (DECL_SIZE (tempvar))
3790 + BITS_PER_UNIT - 1)
3794 TREE_SIDE_EFFECTS (result)
3795 = TREE_SIDE_EFFECTS (ifexp) | TREE_SIDE_EFFECTS (op1)
3796 | TREE_SIDE_EFFECTS (op2);
3797 return build (COMPOUND_EXPR, result_type, result, tempvar);
3802 if (TREE_CODE (ifexp) == INTEGER_CST)
3803 return pedantic_non_lvalue (integer_zerop (ifexp) ? op2 : op1);
3805 return fold (build (COND_EXPR, result_type, ifexp, op1, op2));
3808 /* Given a list of expressions, return a compound expression
3809 that performs them all and returns the value of the last of them. */
3812 build_compound_expr (list)
3815 return internal_build_compound_expr (list, TRUE);
3819 internal_build_compound_expr (list, first_p)
3825 if (TREE_CHAIN (list) == 0)
3827 #if 0 /* If something inside inhibited lvalueness, we should not override. */
3828 /* Consider (x, y+0), which is not an lvalue since y+0 is not. */
3830 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
3831 if (TREE_CODE (list) == NON_LVALUE_EXPR)
3832 list = TREE_OPERAND (list, 0);
3835 /* Don't let (0, 0) be null pointer constant. */
3836 if (!first_p && integer_zerop (TREE_VALUE (list)))
3837 return non_lvalue (TREE_VALUE (list));
3838 return TREE_VALUE (list);
3841 if (TREE_CHAIN (list) != 0 && TREE_CHAIN (TREE_CHAIN (list)) == 0)
3843 /* Convert arrays to pointers when there really is a comma operator. */
3844 if (TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (list)))) == ARRAY_TYPE)
3845 TREE_VALUE (TREE_CHAIN (list))
3846 = default_conversion (TREE_VALUE (TREE_CHAIN (list)));
3849 rest = internal_build_compound_expr (TREE_CHAIN (list), FALSE);
3851 /* When pedantic, a compound expression can be neither an lvalue
3852 nor an integer constant expression. */
3853 if (! TREE_SIDE_EFFECTS (TREE_VALUE (list)) && ! pedantic)
3856 return build (COMPOUND_EXPR, TREE_TYPE (rest), TREE_VALUE (list), rest);
3859 /* Build an expression representing a cast to type TYPE of expression EXPR. */
3862 build_c_cast (type, expr)
3866 register tree value = expr;
3868 if (type == error_mark_node || expr == error_mark_node)
3869 return error_mark_node;
3870 type = TYPE_MAIN_VARIANT (type);
3873 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
3874 if (TREE_CODE (value) == NON_LVALUE_EXPR)
3875 value = TREE_OPERAND (value, 0);
3878 if (TREE_CODE (type) == ARRAY_TYPE)
3880 error ("cast specifies array type");
3881 return error_mark_node;
3884 if (TREE_CODE (type) == FUNCTION_TYPE)
3886 error ("cast specifies function type");
3887 return error_mark_node;
3890 if (type == TREE_TYPE (value))
3894 if (TREE_CODE (type) == RECORD_TYPE
3895 || TREE_CODE (type) == UNION_TYPE)
3896 pedwarn ("ANSI C forbids casting nonscalar to the same type");
3899 else if (TREE_CODE (type) == UNION_TYPE)
3902 if (TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE
3903 || TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE)
3904 value = default_conversion (value);
3906 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
3907 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (field)),
3908 TYPE_MAIN_VARIANT (TREE_TYPE (value))))
3917 pedwarn ("ANSI C forbids casts to union type");
3918 if (TYPE_NAME (type) != 0)
3920 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
3921 name = IDENTIFIER_POINTER (TYPE_NAME (type));
3923 name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
3927 return digest_init (type, build_nt (CONSTRUCTOR, NULL_TREE,
3928 build_tree_list (field, value)),
3931 error ("cast to union type from type not present in union");
3932 return error_mark_node;
3938 /* If casting to void, avoid the error that would come
3939 from default_conversion in the case of a non-lvalue array. */
3940 if (type == void_type_node)
3941 return build1 (CONVERT_EXPR, type, value);
3943 /* Convert functions and arrays to pointers,
3944 but don't convert any other types. */
3945 if (TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE
3946 || TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE)
3947 value = default_conversion (value);
3948 otype = TREE_TYPE (value);
3950 /* Optionally warn about potentially worrisome casts. */
3953 && TREE_CODE (type) == POINTER_TYPE
3954 && TREE_CODE (otype) == POINTER_TYPE)
3956 if (TYPE_VOLATILE (TREE_TYPE (otype))
3957 && ! TYPE_VOLATILE (TREE_TYPE (type)))
3958 pedwarn ("cast discards `volatile' from pointer target type");
3959 if (TYPE_READONLY (TREE_TYPE (otype))
3960 && ! TYPE_READONLY (TREE_TYPE (type)))
3961 pedwarn ("cast discards `const' from pointer target type");
3964 /* Warn about possible alignment problems. */
3965 if (STRICT_ALIGNMENT && warn_cast_align
3966 && TREE_CODE (type) == POINTER_TYPE
3967 && TREE_CODE (otype) == POINTER_TYPE
3968 && TREE_CODE (TREE_TYPE (otype)) != VOID_TYPE
3969 && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
3970 && TYPE_ALIGN (TREE_TYPE (type)) > TYPE_ALIGN (TREE_TYPE (otype)))
3971 warning ("cast increases required alignment of target type");
3973 if (TREE_CODE (type) == INTEGER_TYPE
3974 && TREE_CODE (otype) == POINTER_TYPE
3975 && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
3976 && !TREE_CONSTANT (value))
3977 warning ("cast from pointer to integer of different size");
3979 if (TREE_CODE (type) == POINTER_TYPE
3980 && TREE_CODE (otype) == INTEGER_TYPE
3981 && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
3983 /* Don't warn about converting 0 to pointer,
3984 provided the 0 was explicit--not cast or made by folding. */
3985 && !(TREE_CODE (value) == INTEGER_CST && integer_zerop (value))
3987 /* Don't warn about converting any constant. */
3988 && !TREE_CONSTANT (value))
3989 warning ("cast to pointer from integer of different size");
3992 value = convert (type, value);
3994 /* Ignore any integer overflow caused by the cast. */
3995 if (TREE_CODE (value) == INTEGER_CST)
3997 TREE_OVERFLOW (value) = TREE_OVERFLOW (ovalue);
3998 TREE_CONSTANT_OVERFLOW (value) = TREE_CONSTANT_OVERFLOW (ovalue);
4002 if (value == expr && pedantic)
4004 /* If pedantic, don't let a cast be an lvalue. */
4005 return non_lvalue (value);
4010 /* Build an assignment expression of lvalue LHS from value RHS.
4011 MODIFYCODE is the code for a binary operator that we use
4012 to combine the old value of LHS with RHS to get the new value.
4013 Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment. */
4016 build_modify_expr (lhs, modifycode, rhs)
4018 enum tree_code modifycode;
4020 register tree result;
4022 tree lhstype = TREE_TYPE (lhs);
4023 tree olhstype = lhstype;
4025 /* Types that aren't fully specified cannot be used in assignments. */
4026 lhs = require_complete_type (lhs);
4028 /* Avoid duplicate error messages from operands that had errors. */
4029 if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK)
4030 return error_mark_node;
4032 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
4033 /* Do not use STRIP_NOPS here. We do not want an enumerator
4034 whose value is 0 to count as a null pointer constant. */
4035 if (TREE_CODE (rhs) == NON_LVALUE_EXPR)
4036 rhs = TREE_OPERAND (rhs, 0);
4040 /* Handle control structure constructs used as "lvalues". */
4042 switch (TREE_CODE (lhs))
4044 /* Handle (a, b) used as an "lvalue". */
4046 pedantic_lvalue_warning (COMPOUND_EXPR);
4047 return build (COMPOUND_EXPR, lhstype,
4048 TREE_OPERAND (lhs, 0),
4049 build_modify_expr (TREE_OPERAND (lhs, 1),
4052 /* Handle (a ? b : c) used as an "lvalue". */
4054 pedantic_lvalue_warning (COND_EXPR);
4055 rhs = save_expr (rhs);
4057 /* Produce (a ? (b = rhs) : (c = rhs))
4058 except that the RHS goes through a save-expr
4059 so the code to compute it is only emitted once. */
4061 = build_conditional_expr (TREE_OPERAND (lhs, 0),
4062 build_modify_expr (TREE_OPERAND (lhs, 1),
4064 build_modify_expr (TREE_OPERAND (lhs, 2),
4066 /* Make sure the code to compute the rhs comes out
4067 before the split. */
4068 return build (COMPOUND_EXPR, TREE_TYPE (lhs),
4069 /* But cast it to void to avoid an "unused" error. */
4070 convert (void_type_node, rhs), cond);
4074 /* If a binary op has been requested, combine the old LHS value with the RHS
4075 producing the value we should actually store into the LHS. */
4077 if (modifycode != NOP_EXPR)
4079 lhs = stabilize_reference (lhs);
4080 newrhs = build_binary_op (modifycode, lhs, rhs, 1);
4083 /* Handle a cast used as an "lvalue".
4084 We have already performed any binary operator using the value as cast.
4085 Now convert the result to the cast type of the lhs,
4086 and then true type of the lhs and store it there;
4087 then convert result back to the cast type to be the value
4088 of the assignment. */
4090 switch (TREE_CODE (lhs))
4095 case FIX_TRUNC_EXPR:
4096 case FIX_FLOOR_EXPR:
4097 case FIX_ROUND_EXPR:
4099 if (TREE_CODE (TREE_TYPE (newrhs)) == ARRAY_TYPE
4100 || TREE_CODE (TREE_TYPE (newrhs)) == FUNCTION_TYPE)
4101 newrhs = default_conversion (newrhs);
4103 tree inner_lhs = TREE_OPERAND (lhs, 0);
4105 result = build_modify_expr (inner_lhs, NOP_EXPR,
4106 convert (TREE_TYPE (inner_lhs),
4107 convert (lhstype, newrhs)));
4108 pedantic_lvalue_warning (CONVERT_EXPR);
4109 return convert (TREE_TYPE (lhs), result);
4113 /* Now we have handled acceptable kinds of LHS that are not truly lvalues.
4114 Reject anything strange now. */
4116 if (!lvalue_or_else (lhs, "assignment"))
4117 return error_mark_node;
4119 /* Warn about storing in something that is `const'. */
4121 if (TREE_READONLY (lhs) || TYPE_READONLY (lhstype)
4122 || ((TREE_CODE (lhstype) == RECORD_TYPE
4123 || TREE_CODE (lhstype) == UNION_TYPE)
4124 && C_TYPE_FIELDS_READONLY (lhstype)))
4125 readonly_warning (lhs, "assignment");
4127 /* If storing into a structure or union member,
4128 it has probably been given type `int'.
4129 Compute the type that would go with
4130 the actual amount of storage the member occupies. */
4132 if (TREE_CODE (lhs) == COMPONENT_REF
4133 && (TREE_CODE (lhstype) == INTEGER_TYPE
4134 || TREE_CODE (lhstype) == REAL_TYPE
4135 || TREE_CODE (lhstype) == ENUMERAL_TYPE))
4136 lhstype = TREE_TYPE (get_unwidened (lhs, 0));
4138 /* If storing in a field that is in actuality a short or narrower than one,
4139 we must store in the field in its actual type. */
4141 if (lhstype != TREE_TYPE (lhs))
4143 lhs = copy_node (lhs);
4144 TREE_TYPE (lhs) = lhstype;
4147 /* Convert new value to destination type. */
4149 newrhs = convert_for_assignment (lhstype, newrhs, "assignment",
4150 NULL_TREE, NULL_TREE, 0);
4151 if (TREE_CODE (newrhs) == ERROR_MARK)
4152 return error_mark_node;
4154 result = build (MODIFY_EXPR, lhstype, lhs, newrhs);
4155 TREE_SIDE_EFFECTS (result) = 1;
4157 /* If we got the LHS in a different type for storing in,
4158 convert the result back to the nominal type of LHS
4159 so that the value we return always has the same type
4160 as the LHS argument. */
4162 if (olhstype == TREE_TYPE (result))
4164 return convert_for_assignment (olhstype, result, "assignment",
4165 NULL_TREE, NULL_TREE, 0);
4168 /* Convert value RHS to type TYPE as preparation for an assignment
4169 to an lvalue of type TYPE.
4170 The real work of conversion is done by `convert'.
4171 The purpose of this function is to generate error messages
4172 for assignments that are not allowed in C.
4173 ERRTYPE is a string to use in error messages:
4174 "assignment", "return", etc. If it is null, this is parameter passing
4175 for a function call (and different error messages are output). Otherwise,
4176 it may be a name stored in the spelling stack and interpreted by
4179 FUNNAME is the name of the function being called,
4180 as an IDENTIFIER_NODE, or null.
4181 PARMNUM is the number of the argument, for printing in error messages. */
4184 convert_for_assignment (type, rhs, errtype, fundecl, funname, parmnum)
4187 tree fundecl, funname;
4190 register enum tree_code codel = TREE_CODE (type);
4191 register tree rhstype;
4192 register enum tree_code coder;
4194 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
4195 /* Do not use STRIP_NOPS here. We do not want an enumerator
4196 whose value is 0 to count as a null pointer constant. */
4197 if (TREE_CODE (rhs) == NON_LVALUE_EXPR)
4198 rhs = TREE_OPERAND (rhs, 0);
4200 if (TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE
4201 || TREE_CODE (TREE_TYPE (rhs)) == FUNCTION_TYPE)
4202 rhs = default_conversion (rhs);
4204 rhstype = TREE_TYPE (rhs);
4205 coder = TREE_CODE (rhstype);
4207 if (coder == ERROR_MARK)
4208 return error_mark_node;
4210 if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype))
4212 overflow_warning (rhs);
4213 /* Check for Objective-C protocols. This will issue a warning if
4214 there are protocol violations. No need to use the return value. */
4215 maybe_objc_comptypes (type, rhstype, 0);
4219 if (coder == VOID_TYPE)
4221 error ("void value not ignored as it ought to be");
4222 return error_mark_node;
4224 /* Arithmetic types all interconvert, and enum is treated like int. */
4225 if ((codel == INTEGER_TYPE || codel == REAL_TYPE || codel == ENUMERAL_TYPE
4226 || codel == COMPLEX_TYPE)
4228 (coder == INTEGER_TYPE || coder == REAL_TYPE || coder == ENUMERAL_TYPE
4229 || codel == COMPLEX_TYPE))
4230 return convert_and_check (type, rhs);
4231 /* Conversion to a union from its member types. */
4232 else if (codel == UNION_TYPE)
4235 for (memb_types = TYPE_FIELDS (type); memb_types;
4236 memb_types = TREE_CHAIN (memb_types))
4238 if (comptypes (TREE_TYPE (memb_types), TREE_TYPE (rhs)))
4241 && !(fundecl != 0 && DECL_IN_SYSTEM_HEADER (fundecl)))
4242 pedwarn ("ANSI C prohibits argument conversion to union type");
4243 return build1 (NOP_EXPR, type, rhs);
4245 else if (coder == POINTER_TYPE
4246 && TREE_CODE (TREE_TYPE (memb_types)) == POINTER_TYPE)
4248 tree memb_type = TREE_TYPE (memb_types);
4249 register tree ttl = TREE_TYPE (memb_type);
4250 register tree ttr = TREE_TYPE (rhstype);
4252 /* Any non-function converts to a [const][volatile] void *
4253 and vice versa; otherwise, targets must be the same.
4254 Meanwhile, the lhs target must have all the qualifiers of the rhs. */
4255 if (TYPE_MAIN_VARIANT (ttl) == void_type_node
4256 || TYPE_MAIN_VARIANT (ttr) == void_type_node
4257 || comp_target_types (memb_type, rhstype))
4259 /* Const and volatile mean something different for function types,
4260 so the usual warnings are not appropriate. */
4261 if (TREE_CODE (ttr) != FUNCTION_TYPE
4262 || TREE_CODE (ttl) != FUNCTION_TYPE)
4264 if (! TYPE_READONLY (ttl) && TYPE_READONLY (ttr))
4265 warn_for_assignment ("%s discards `const' from pointer target type",
4266 get_spelling (errtype), funname, parmnum);
4267 if (! TYPE_VOLATILE (ttl) && TYPE_VOLATILE (ttr))
4268 warn_for_assignment ("%s discards `volatile' from pointer target type",
4269 get_spelling (errtype), funname, parmnum);
4273 /* Because const and volatile on functions are restrictions
4274 that say the function will not do certain things,
4275 it is okay to use a const or volatile function
4276 where an ordinary one is wanted, but not vice-versa. */
4277 if (TYPE_READONLY (ttl) && ! TYPE_READONLY (ttr))
4278 warn_for_assignment ("%s makes `const *' function pointer from non-const",
4279 get_spelling (errtype), funname, parmnum);
4280 if (TYPE_VOLATILE (ttl) && ! TYPE_VOLATILE (ttr))
4281 warn_for_assignment ("%s makes `volatile *' function pointer from non-volatile",
4282 get_spelling (errtype), funname, parmnum);
4285 && !(fundecl != 0 && DECL_IN_SYSTEM_HEADER (fundecl)))
4286 pedwarn ("ANSI C prohibits argument conversion to union type");
4287 return build1 (NOP_EXPR, type, rhs);
4292 /* Conversions among pointers */
4293 else if (codel == POINTER_TYPE && coder == POINTER_TYPE)
4295 register tree ttl = TREE_TYPE (type);
4296 register tree ttr = TREE_TYPE (rhstype);
4298 /* Any non-function converts to a [const][volatile] void *
4299 and vice versa; otherwise, targets must be the same.
4300 Meanwhile, the lhs target must have all the qualifiers of the rhs. */
4301 if (TYPE_MAIN_VARIANT (ttl) == void_type_node
4302 || TYPE_MAIN_VARIANT (ttr) == void_type_node
4303 || comp_target_types (type, rhstype)
4304 || (unsigned_type (TYPE_MAIN_VARIANT (ttl))
4305 == unsigned_type (TYPE_MAIN_VARIANT (ttr))))
4308 && ((TYPE_MAIN_VARIANT (ttl) == void_type_node
4309 && TREE_CODE (ttr) == FUNCTION_TYPE)
4311 (TYPE_MAIN_VARIANT (ttr) == void_type_node
4312 && !integer_zerop (rhs)
4313 && TREE_CODE (ttl) == FUNCTION_TYPE)))
4314 warn_for_assignment ("ANSI forbids %s between function pointer and `void *'",
4315 get_spelling (errtype), funname, parmnum);
4316 /* Const and volatile mean something different for function types,
4317 so the usual warnings are not appropriate. */
4318 else if (TREE_CODE (ttr) != FUNCTION_TYPE
4319 || TREE_CODE (ttl) != FUNCTION_TYPE)
4321 if (! TYPE_READONLY (ttl) && TYPE_READONLY (ttr))
4322 warn_for_assignment ("%s discards `const' from pointer target type",
4323 get_spelling (errtype), funname, parmnum);
4324 else if (! TYPE_VOLATILE (ttl) && TYPE_VOLATILE (ttr))
4325 warn_for_assignment ("%s discards `volatile' from pointer target type",
4326 get_spelling (errtype), funname, parmnum);
4327 /* If this is not a case of ignoring a mismatch in signedness,
4329 else if (TYPE_MAIN_VARIANT (ttl) == void_type_node
4330 || TYPE_MAIN_VARIANT (ttr) == void_type_node
4331 || comp_target_types (type, rhstype))
4333 /* If there is a mismatch, do warn. */
4335 warn_for_assignment ("pointer targets in %s differ in signedness",
4336 get_spelling (errtype), funname, parmnum);
4340 /* Because const and volatile on functions are restrictions
4341 that say the function will not do certain things,
4342 it is okay to use a const or volatile function
4343 where an ordinary one is wanted, but not vice-versa. */
4344 if (TYPE_READONLY (ttl) && ! TYPE_READONLY (ttr))
4345 warn_for_assignment ("%s makes `const *' function pointer from non-const",
4346 get_spelling (errtype), funname, parmnum);
4347 if (TYPE_VOLATILE (ttl) && ! TYPE_VOLATILE (ttr))
4348 warn_for_assignment ("%s makes `volatile *' function pointer from non-volatile",
4349 get_spelling (errtype), funname, parmnum);
4353 warn_for_assignment ("%s from incompatible pointer type",
4354 get_spelling (errtype), funname, parmnum);
4355 return convert (type, rhs);
4357 else if (codel == POINTER_TYPE && coder == INTEGER_TYPE)
4359 /* An explicit constant 0 can convert to a pointer,
4360 but not a 0 that results from casting or folding. */
4361 if (! (TREE_CODE (rhs) == INTEGER_CST && integer_zerop (rhs)))
4363 warn_for_assignment ("%s makes pointer from integer without a cast",
4364 get_spelling (errtype), funname, parmnum);
4365 return convert (type, rhs);
4367 return null_pointer_node;
4369 else if (codel == INTEGER_TYPE && coder == POINTER_TYPE)
4371 warn_for_assignment ("%s makes integer from pointer without a cast",
4372 get_spelling (errtype), funname, parmnum);
4373 return convert (type, rhs);
4380 tree selector = maybe_building_objc_message_expr ();
4382 if (selector && parmnum > 2)
4383 error ("incompatible type for argument %d of `%s'",
4384 parmnum - 2, IDENTIFIER_POINTER (selector));
4386 error ("incompatible type for argument %d of `%s'",
4387 parmnum, IDENTIFIER_POINTER (funname));
4390 error ("incompatible type for argument %d of indirect function call",
4394 error ("incompatible types in %s", get_spelling (errtype));
4396 return error_mark_node;
4399 /* Print a warning using MSG.
4400 It gets OPNAME as its one parameter.
4401 If OPNAME is null, it is replaced by "passing arg ARGNUM of `FUNCTION'".
4402 FUNCTION and ARGNUM are handled specially if we are building an
4403 Objective-C selector. */
4406 warn_for_assignment (msg, opname, function, argnum)
4412 static char argstring[] = "passing arg %d of `%s'";
4413 static char argnofun[] = "passing arg %d";
4417 tree selector = maybe_building_objc_message_expr ();
4419 if (selector && argnum > 2)
4421 function = selector;
4426 /* Function name is known; supply it. */
4427 opname = (char *) alloca (IDENTIFIER_LENGTH (function)
4428 + sizeof (argstring) + 25 /*%d*/ + 1);
4429 sprintf (opname, argstring, argnum, IDENTIFIER_POINTER (function));
4433 /* Function name unknown (call through ptr); just give arg number. */
4434 opname = (char *) alloca (sizeof (argnofun) + 25 /*%d*/ + 1);
4435 sprintf (opname, argnofun, argnum);
4438 pedwarn (msg, opname);
4441 /* Return nonzero if VALUE is a valid constant-valued expression
4442 for use in initializing a static variable; one that can be an
4443 element of a "constant" initializer.
4445 Return null_pointer_node if the value is absolute;
4446 if it is relocatable, return the variable that determines the relocation.
4447 We assume that VALUE has been folded as much as possible;
4448 therefore, we do not need to check for such things as
4449 arithmetic-combinations of integers. */
4452 initializer_constant_valid_p (value, endtype)
4456 switch (TREE_CODE (value))
4459 return TREE_STATIC (value) ? null_pointer_node : 0;
4465 return null_pointer_node;
4468 return TREE_OPERAND (value, 0);
4470 case NON_LVALUE_EXPR:
4471 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4475 /* Allow conversions between pointer types. */
4476 if (TREE_CODE (TREE_TYPE (value)) == POINTER_TYPE
4477 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == POINTER_TYPE)
4478 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4479 /* Allow conversions between real types. */
4480 if (TREE_CODE (TREE_TYPE (value)) == REAL_TYPE
4481 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == REAL_TYPE)
4482 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4483 /* Allow length-preserving conversions between integer types. */
4484 if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE
4485 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == INTEGER_TYPE
4486 && tree_int_cst_equal (TYPE_SIZE (TREE_TYPE (value)),
4487 TYPE_SIZE (TREE_TYPE (TREE_OPERAND (value, 0)))))
4488 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4489 /* Allow conversions between integer types only if explicit value. */
4490 if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE
4491 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == INTEGER_TYPE)
4493 tree inner = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4495 if (inner == null_pointer_node)
4496 return null_pointer_node;
4499 /* Allow (int) &foo provided int is as wide as a pointer. */
4500 if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE
4501 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == POINTER_TYPE
4502 && ! tree_int_cst_lt (TYPE_SIZE (TREE_TYPE (value)),
4503 TYPE_SIZE (TREE_TYPE (TREE_OPERAND (value, 0)))))
4504 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4506 /* Allow conversions to union types if the value inside is okay. */
4507 if (TREE_CODE (TREE_TYPE (value)) == UNION_TYPE)
4508 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4513 if (TREE_CODE (endtype) == INTEGER_TYPE
4514 && TYPE_PRECISION (endtype) < POINTER_SIZE)
4517 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4519 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
4521 /* If either term is absolute, use the other terms relocation. */
4522 if (valid0 == null_pointer_node)
4524 if (valid1 == null_pointer_node)
4530 if (TREE_CODE (endtype) == INTEGER_TYPE
4531 && TYPE_PRECISION (endtype) < POINTER_SIZE)
4534 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4536 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
4538 /* Win if second argument is absolute. */
4539 if (valid1 == null_pointer_node)
4541 /* Win if both arguments have the same relocation.
4542 Then the value is absolute. */
4543 if (valid0 == valid1)
4544 return null_pointer_node;
4552 /* Perform appropriate conversions on the initial value of a variable,
4553 store it in the declaration DECL,
4554 and print any error messages that are appropriate.
4555 If the init is invalid, store an ERROR_MARK. */
4558 store_init_value (decl, init)
4561 register tree value, type;
4563 /* If variable's type was invalidly declared, just ignore it. */
4565 type = TREE_TYPE (decl);
4566 if (TREE_CODE (type) == ERROR_MARK)
4569 /* Digest the specified initializer into an expression. */
4571 value = digest_init (type, init, TREE_STATIC (decl),
4572 TREE_STATIC (decl) || pedantic);
4574 /* Store the expression if valid; else report error. */
4577 /* Note that this is the only place we can detect the error
4578 in a case such as struct foo bar = (struct foo) { x, y };
4579 where there is one initial value which is a constructor expression. */
4580 if (value == error_mark_node)
4582 else if (TREE_STATIC (decl) && ! TREE_CONSTANT (value))
4584 error ("initializer for static variable is not constant");
4585 value = error_mark_node;
4587 else if (TREE_STATIC (decl)
4588 && initializer_constant_valid_p (value, TREE_TYPE (value)) == 0)
4590 error ("initializer for static variable uses complicated arithmetic");
4591 value = error_mark_node;
4595 if (pedantic && TREE_CODE (value) == CONSTRUCTOR)
4597 if (! TREE_CONSTANT (value))
4598 pedwarn ("aggregate initializer is not constant");
4599 else if (! TREE_STATIC (value))
4600 pedwarn ("aggregate initializer uses complicated arithmetic");
4605 DECL_INITIAL (decl) = value;
4607 /* ANSI wants warnings about out-of-range constant initializers. */
4608 STRIP_TYPE_NOPS (value);
4609 constant_expression_warning (value);
4612 /* Methods for storing and printing names for error messages. */
4614 /* Implement a spelling stack that allows components of a name to be pushed
4615 and popped. Each element on the stack is this structure. */
4627 #define SPELLING_STRING 1
4628 #define SPELLING_MEMBER 2
4629 #define SPELLING_BOUNDS 3
4631 static struct spelling *spelling; /* Next stack element (unused). */
4632 static struct spelling *spelling_base; /* Spelling stack base. */
4633 static int spelling_size; /* Size of the spelling stack. */
4635 /* Macros to save and restore the spelling stack around push_... functions.
4636 Alternative to SAVE_SPELLING_STACK. */
4638 #define SPELLING_DEPTH() (spelling - spelling_base)
4639 #define RESTORE_SPELLING_DEPTH(depth) (spelling = spelling_base + depth)
4641 /* Save and restore the spelling stack around arbitrary C code. */
4643 #define SAVE_SPELLING_DEPTH(code) \
4645 int __depth = SPELLING_DEPTH (); \
4647 RESTORE_SPELLING_DEPTH (__depth); \
4650 /* Push an element on the spelling stack with type KIND and assign VALUE
4653 #define PUSH_SPELLING(KIND, VALUE, MEMBER) \
4655 int depth = SPELLING_DEPTH (); \
4657 if (depth >= spelling_size) \
4659 spelling_size += 10; \
4660 if (spelling_base == 0) \
4662 = (struct spelling *) xmalloc (spelling_size * sizeof (struct spelling)); \
4665 = (struct spelling *) xrealloc (spelling_base, \
4666 spelling_size * sizeof (struct spelling)); \
4667 RESTORE_SPELLING_DEPTH (depth); \
4670 spelling->kind = (KIND); \
4671 spelling->MEMBER = (VALUE); \
4675 /* Push STRING on the stack. Printed literally. */
4678 push_string (string)
4681 PUSH_SPELLING (SPELLING_STRING, string, u.s);
4684 /* Push a member name on the stack. Printed as '.' STRING. */
4687 push_member_name (string)
4690 PUSH_SPELLING (SPELLING_MEMBER, string, u.s);
4693 /* Push an array bounds on the stack. Printed as [BOUNDS]. */
4696 push_array_bounds (bounds)
4699 PUSH_SPELLING (SPELLING_BOUNDS, bounds, u.i);
4702 /* Compute the maximum size in bytes of the printed spelling. */
4707 register int size = 0;
4708 register struct spelling *p;
4710 for (p = spelling_base; p < spelling; p++)
4712 if (p->kind == SPELLING_BOUNDS)
4715 size += strlen (p->u.s) + 1;
4721 /* Print the spelling to BUFFER and return it. */
4724 print_spelling (buffer)
4725 register char *buffer;
4727 register char *d = buffer;
4729 register struct spelling *p;
4731 for (p = spelling_base; p < spelling; p++)
4732 if (p->kind == SPELLING_BOUNDS)
4734 sprintf (d, "[%d]", p->u.i);
4739 if (p->kind == SPELLING_MEMBER)
4741 for (s = p->u.s; *d = *s++; d++)
4748 /* Provide a means to pass component names derived from the spelling stack. */
4750 char initialization_message;
4752 /* Interpret the spelling of the given ERRTYPE message. */
4755 get_spelling (errtype)
4758 static char *buffer;
4759 static int size = -1;
4761 if (errtype == &initialization_message)
4763 /* Avoid counting chars */
4764 static char message[] = "initialization of `%s'";
4765 register int needed = sizeof (message) + spelling_length () + 1;
4769 buffer = (char *) xmalloc (size = needed);
4771 buffer = (char *) xrealloc (buffer, size = needed);
4773 temp = (char *) alloca (needed);
4774 sprintf (buffer, message, print_spelling (temp));
4781 /* Issue an error message for a bad initializer component.
4782 FORMAT describes the message. OFWHAT is the name for the component.
4783 LOCAL is a format string for formatting the insertion of the name
4786 If OFWHAT is null, the component name is stored on the spelling stack.
4787 If the component name is a null string, then LOCAL is omitted entirely. */
4790 error_init (format, local, ofwhat)
4791 char *format, *local, *ofwhat;
4796 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
4797 buffer = (char *) alloca (strlen (local) + strlen (ofwhat) + 2);
4800 sprintf (buffer, local, ofwhat);
4804 error (format, buffer);
4807 /* Issue a pedantic warning for a bad initializer component.
4808 FORMAT describes the message. OFWHAT is the name for the component.
4809 LOCAL is a format string for formatting the insertion of the name
4812 If OFWHAT is null, the component name is stored on the spelling stack.
4813 If the component name is a null string, then LOCAL is omitted entirely. */
4816 pedwarn_init (format, local, ofwhat)
4817 char *format, *local, *ofwhat;
4822 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
4823 buffer = (char *) alloca (strlen (local) + strlen (ofwhat) + 2);
4826 sprintf (buffer, local, ofwhat);
4830 pedwarn (format, buffer);
4833 /* Digest the parser output INIT as an initializer for type TYPE.
4834 Return a C expression of type TYPE to represent the initial value.
4836 If TAIL is nonzero, it points to a variable holding a list of elements
4837 of which INIT is the first. We update the list stored there by
4838 removing from the head all the elements that we use.
4839 Normally this is only one; we use more than one element only if
4840 TYPE is an aggregate and INIT is not a constructor.
4842 The arguments REQUIRE_CONSTANT and CONSTRUCTOR_CONSTANT request errors
4843 if non-constant initializers or elements are seen. CONSTRUCTOR_CONSTANT
4844 applies only to elements of constructors.
4846 If OFWHAT is nonnull, it specifies what we are initializing, for error
4847 messages. Examples: variable name, variable.member, array[44].
4848 If OFWHAT is null, the component name is stored on the spelling stack.
4849 (That is true for all nested calls to digest_init.) */
4852 digest_init (type, init, require_constant, constructor_constant)
4854 int require_constant, constructor_constant;
4856 enum tree_code code = TREE_CODE (type);
4858 tree inside_init = init;
4860 if (init == error_mark_node)
4863 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
4864 /* Do not use STRIP_NOPS here. We do not want an enumerator
4865 whose value is 0 to count as a null pointer constant. */
4866 if (TREE_CODE (init) == NON_LVALUE_EXPR)
4867 inside_init = TREE_OPERAND (init, 0);
4869 /* Initialization of an array of chars from a string constant
4870 optionally enclosed in braces. */
4872 if (code == ARRAY_TYPE)
4874 tree typ1 = TYPE_MAIN_VARIANT (TREE_TYPE (type));
4875 if ((typ1 == char_type_node
4876 || typ1 == signed_char_type_node
4877 || typ1 == unsigned_char_type_node
4878 || typ1 == unsigned_wchar_type_node
4879 || typ1 == signed_wchar_type_node)
4880 && ((inside_init && TREE_CODE (inside_init) == STRING_CST)
4881 || (element && TREE_CODE (element) == STRING_CST)))
4883 tree string = element ? element : inside_init;
4885 if (TREE_TYPE (string) == type)
4888 if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (string)))
4890 && TYPE_PRECISION (typ1) == TYPE_PRECISION (char_type_node))
4892 error_init ("char-array%s initialized from wide string",
4894 return error_mark_node;
4896 if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (string)))
4898 && TYPE_PRECISION (typ1) != TYPE_PRECISION (char_type_node))
4900 error_init ("int-array%s initialized from non-wide string",
4902 return error_mark_node;
4905 TREE_TYPE (string) = type;
4906 if (TYPE_DOMAIN (type) != 0
4907 && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
4909 register int size = TREE_INT_CST_LOW (TYPE_SIZE (type));
4910 size = (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
4911 /* Subtract 1 (or sizeof (wchar_t))
4912 because it's ok to ignore the terminating null char
4913 that is counted in the length of the constant. */
4914 if (size < TREE_STRING_LENGTH (string)
4915 - (TYPE_PRECISION (typ1) != TYPE_PRECISION (char_type_node)
4916 ? TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT
4919 "initializer-string for array of chars%s is too long",
4926 /* Any type can be initialized
4927 from an expression of the same type, optionally with braces. */
4929 if (inside_init && TREE_TYPE (inside_init) != 0
4930 && ((TYPE_MAIN_VARIANT (TREE_TYPE (inside_init))
4931 == TYPE_MAIN_VARIANT (type))
4932 || (code == ARRAY_TYPE
4933 && comptypes (TREE_TYPE (inside_init), type))
4934 || (code == POINTER_TYPE
4935 && (TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE
4936 || TREE_CODE (TREE_TYPE (inside_init)) == FUNCTION_TYPE)
4937 && comptypes (TREE_TYPE (TREE_TYPE (inside_init)),
4938 TREE_TYPE (type)))))
4940 if (code == POINTER_TYPE
4941 && (TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE
4942 || TREE_CODE (TREE_TYPE (inside_init)) == FUNCTION_TYPE))
4943 inside_init = default_conversion (inside_init);
4944 else if (code == ARRAY_TYPE && TREE_CODE (inside_init) != STRING_CST
4945 && TREE_CODE (inside_init) != CONSTRUCTOR)
4947 error_init ("array%s initialized from non-constant array expression",
4949 return error_mark_node;
4952 if (optimize && TREE_READONLY (inside_init)
4953 && TREE_CODE (inside_init) == VAR_DECL)
4954 inside_init = decl_constant_value (inside_init);
4956 if (require_constant && ! TREE_CONSTANT (inside_init))
4958 error_init ("initializer element%s is not constant",
4960 inside_init = error_mark_node;
4962 else if (require_constant
4963 && initializer_constant_valid_p (inside_init, TREE_TYPE (inside_init)) == 0)
4965 error_init ("initializer element%s is not computable at load time",
4967 inside_init = error_mark_node;
4973 if (element && (TREE_TYPE (element) == type
4974 || (code == ARRAY_TYPE && TREE_TYPE (element)
4975 && comptypes (TREE_TYPE (element), type))))
4977 if (code == ARRAY_TYPE)
4979 error_init ("array%s initialized from non-constant array expression",
4981 return error_mark_node;
4983 if (pedantic && (code == RECORD_TYPE || code == UNION_TYPE))
4984 pedwarn ("single-expression nonscalar initializer has braces");
4985 if (optimize && TREE_READONLY (element) && TREE_CODE (element) == VAR_DECL)
4986 element = decl_constant_value (element);
4988 if (require_constant && ! TREE_CONSTANT (element))
4990 error_init ("initializer element%s is not constant",
4992 element = error_mark_node;
4994 else if (require_constant
4995 && initializer_constant_valid_p (element, TREE_TYPE (element)) == 0)
4997 error_init ("initializer element%s is not computable at load time",
4999 element = error_mark_node;
5005 /* Handle scalar types, including conversions. */
5007 if (code == INTEGER_TYPE || code == REAL_TYPE || code == POINTER_TYPE
5008 || code == ENUMERAL_TYPE || code == COMPLEX_TYPE)
5012 /* Note that convert_for_assignment calls default_conversion
5013 for arrays and functions. We must not call it in the
5014 case where inside_init is a null pointer constant. */
5016 = convert_for_assignment (type, init,
5017 &initialization_message,
5018 NULL_TREE, NULL_TREE, 0);
5021 if (require_constant && ! TREE_CONSTANT (inside_init))
5023 error_init ("initializer element%s is not constant",
5025 inside_init = error_mark_node;
5027 else if (require_constant
5028 && initializer_constant_valid_p (inside_init, TREE_TYPE (inside_init)) == 0)
5030 error_init ("initializer element%s is not computable at load time",
5032 inside_init = error_mark_node;
5038 /* Come here only for records and arrays. */
5040 if (TYPE_SIZE (type) && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
5042 error_init ("variable-sized object%s may not be initialized",
5044 return error_mark_node;
5047 error_init ("invalid initializer%s", " for `%s'", NULL);
5048 return error_mark_node;
5051 /* Handle initializers that use braces. */
5053 static void output_init_element ();
5054 static void output_pending_init_elements ();
5055 static void check_init_type_bitfields ();
5057 /* Type of object we are accumulating a constructor for.
5058 This type is always a RECORD_TYPE, UNION_TYPE or ARRAY_TYPE. */
5059 static tree constructor_type;
5061 /* For a RECORD_TYPE or UNION_TYPE, this is the chain of fields
5063 static tree constructor_fields;
5065 /* For an ARRAY_TYPE, this is the specified index
5066 at which to store the next element we get.
5067 This is a special INTEGER_CST node that we modify in place. */
5068 static tree constructor_index;
5070 /* For an ARRAY_TYPE, this is the end index of the range
5071 to intitialize with the next element, or NULL in the ordinary case
5072 where the element is used just once. */
5073 static tree constructor_range_end;
5075 /* For an ARRAY_TYPE, this is the maximum index. */
5076 static tree constructor_max_index;
5078 /* For a RECORD_TYPE, this is the first field not yet written out. */
5079 static tree constructor_unfilled_fields;
5081 /* For an ARRAY_TYPE, this is the index of the first element
5082 not yet written out.
5083 This is a special INTEGER_CST node that we modify in place. */
5084 static tree constructor_unfilled_index;
5086 /* In a RECORD_TYPE, the byte index of the next consecutive field.
5087 This is so we can generate gaps between fields, when appropriate.
5088 This is a special INTEGER_CST node that we modify in place. */
5089 static tree constructor_bit_index;
5091 /* If we are saving up the elements rather than allocating them,
5092 this is the list of elements so far (in reverse order,
5093 most recent first). */
5094 static tree constructor_elements;
5096 /* 1 if so far this constructor's elements are all compile-time constants. */
5097 static int constructor_constant;
5099 /* 1 if so far this constructor's elements are all valid address constants. */
5100 static int constructor_simple;
5102 /* 1 if this constructor is erroneous so far. */
5103 static int constructor_erroneous;
5105 /* 1 if have called defer_addressed_constants. */
5106 static int constructor_subconstants_deferred;
5108 /* List of pending elements at this constructor level.
5109 These are elements encountered out of order
5110 which belong at places we haven't reached yet in actually
5111 writing the output. */
5112 static tree constructor_pending_elts;
5114 /* The SPELLING_DEPTH of this constructor. */
5115 static int constructor_depth;
5117 /* 1 if this constructor level was entered implicitly. */
5118 static int constructor_implicit;
5120 static int require_constant_value;
5121 static int require_constant_elements;
5123 /* 1 if it is ok to output this constructor as we read it.
5124 0 means must accumulate a CONSTRUCTOR expression. */
5125 static int constructor_incremental;
5127 /* DECL node for which an initializer is being read.
5128 0 means we are reading a constructor expression
5129 such as (struct foo) {...}. */
5130 static tree constructor_decl;
5132 /* start_init saves the ASMSPEC arg here for really_start_incremental_init. */
5133 static char *constructor_asmspec;
5135 /* Nonzero if this is an initializer for a top-level decl. */
5136 static int constructor_top_level;
5138 /* When we finish reading a constructor expression
5139 (constructor_decl is 0), the CONSTRUCTOR goes here. */
5140 static tree constructor_result;
5142 /* This stack has a level for each implicit or explicit level of
5143 structuring in the initializer, including the outermost one. It
5144 saves the values of most of the variables above. */
5146 struct constructor_stack
5148 struct constructor_stack *next;
5154 tree unfilled_index;
5155 tree unfilled_fields;
5161 /* If nonzero, this value should replace the entire
5162 constructor at this level. */
5163 tree replacement_value;
5172 struct constructor_stack *constructor_stack;
5174 /* This stack records separate initializers that are nested.
5175 Nested initializers can't happen in ANSI C, but GNU C allows them
5176 in cases like { ... (struct foo) { ... } ... }. */
5178 struct initializer_stack
5180 struct initializer_stack *next;
5183 struct constructor_stack *constructor_stack;
5184 struct spelling *spelling;
5185 struct spelling *spelling_base;
5189 char require_constant_value;
5190 char require_constant_elements;
5194 struct initializer_stack *initializer_stack;
5196 /* Prepare to parse and output the initializer for variable DECL. */
5199 start_init (decl, asmspec_tree, top_level)
5205 struct initializer_stack *p
5206 = (struct initializer_stack *) xmalloc (sizeof (struct initializer_stack));
5210 asmspec = TREE_STRING_POINTER (asmspec_tree);
5212 p->decl = constructor_decl;
5213 p->asmspec = constructor_asmspec;
5214 p->incremental = constructor_incremental;
5215 p->require_constant_value = require_constant_value;
5216 p->require_constant_elements = require_constant_elements;
5217 p->constructor_stack = constructor_stack;
5218 p->spelling = spelling;
5219 p->spelling_base = spelling_base;
5220 p->spelling_size = spelling_size;
5221 p->deferred = constructor_subconstants_deferred;
5222 p->top_level = constructor_top_level;
5223 p->next = initializer_stack;
5224 initializer_stack = p;
5226 constructor_decl = decl;
5227 constructor_incremental = top_level;
5228 constructor_asmspec = asmspec;
5229 constructor_subconstants_deferred = 0;
5230 constructor_top_level = top_level;
5234 require_constant_value = TREE_STATIC (decl);
5235 require_constant_elements = TREE_STATIC (decl) || pedantic;
5236 locus = IDENTIFIER_POINTER (DECL_NAME (decl));
5237 constructor_incremental |= TREE_STATIC (decl);
5241 require_constant_value = 0;
5242 require_constant_elements = 0;
5243 locus = "(anonymous)";
5246 constructor_stack = 0;
5250 RESTORE_SPELLING_DEPTH (0);
5253 push_string (locus);
5259 struct initializer_stack *p = initializer_stack;
5261 /* Output subconstants (string constants, usually)
5262 that were referenced within this initializer and saved up.
5263 Must do this if and only if we called defer_addressed_constants. */
5264 if (constructor_subconstants_deferred)
5265 output_deferred_addressed_constants ();
5267 /* Free the whole constructor stack of this initializer. */
5268 while (constructor_stack)
5270 struct constructor_stack *q = constructor_stack;
5271 constructor_stack = q->next;
5275 /* Pop back to the data of the outer initializer (if any). */
5276 constructor_decl = p->decl;
5277 constructor_asmspec = p->asmspec;
5278 constructor_incremental = p->incremental;
5279 require_constant_value = p->require_constant_value;
5280 require_constant_elements = p->require_constant_elements;
5281 constructor_stack = p->constructor_stack;
5282 spelling = p->spelling;
5283 spelling_base = p->spelling_base;
5284 spelling_size = p->spelling_size;
5285 constructor_subconstants_deferred = p->deferred;
5286 constructor_top_level = p->top_level;
5287 initializer_stack = p->next;
5291 /* Call here when we see the initializer is surrounded by braces.
5292 This is instead of a call to push_init_level;
5293 it is matched by a call to pop_init_level.
5295 TYPE is the type to initialize, for a constructor expression.
5296 For an initializer for a decl, TYPE is zero. */
5299 really_start_incremental_init (type)
5302 struct constructor_stack *p
5303 = (struct constructor_stack *) xmalloc (sizeof (struct constructor_stack));
5306 type = TREE_TYPE (constructor_decl);
5308 /* Turn off constructor_incremental if type is a struct with bitfields.
5309 Do this before the first push, so that the corrected value
5310 is available in finish_init. */
5311 check_init_type_bitfields (type);
5313 p->type = constructor_type;
5314 p->fields = constructor_fields;
5315 p->index = constructor_index;
5316 p->range_end = constructor_range_end;
5317 p->max_index = constructor_max_index;
5318 p->unfilled_index = constructor_unfilled_index;
5319 p->unfilled_fields = constructor_unfilled_fields;
5320 p->bit_index = constructor_bit_index;
5322 p->constant = constructor_constant;
5323 p->simple = constructor_simple;
5324 p->erroneous = constructor_erroneous;
5325 p->pending_elts = constructor_pending_elts;
5326 p->depth = constructor_depth;
5327 p->replacement_value = 0;
5329 p->incremental = constructor_incremental;
5332 constructor_stack = p;
5334 constructor_constant = 1;
5335 constructor_simple = 1;
5336 constructor_depth = SPELLING_DEPTH ();
5337 constructor_elements = 0;
5338 constructor_pending_elts = 0;
5339 constructor_type = type;
5341 if (TREE_CODE (constructor_type) == RECORD_TYPE
5342 || TREE_CODE (constructor_type) == UNION_TYPE)
5344 constructor_fields = TYPE_FIELDS (constructor_type);
5345 constructor_unfilled_fields = constructor_fields;
5346 constructor_bit_index = copy_node (integer_zero_node);
5348 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5350 constructor_index = copy_node (integer_zero_node);
5351 constructor_range_end = 0;
5352 constructor_unfilled_index = copy_node (integer_zero_node);
5353 if (TYPE_DOMAIN (constructor_type))
5354 constructor_max_index
5355 = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
5359 /* Handle the case of int x = {5}; */
5360 constructor_fields = constructor_type;
5361 constructor_unfilled_fields = constructor_type;
5364 if (constructor_incremental)
5366 int momentary = suspend_momentary ();
5367 push_obstacks_nochange ();
5368 if (TREE_PERMANENT (constructor_decl))
5369 end_temporary_allocation ();
5370 make_decl_rtl (constructor_decl, constructor_asmspec,
5371 constructor_top_level);
5372 assemble_variable (constructor_decl, constructor_top_level, 0, 1);
5374 resume_momentary (momentary);
5377 if (constructor_incremental)
5379 defer_addressed_constants ();
5380 constructor_subconstants_deferred = 1;
5384 /* Push down into a subobject, for initialization.
5385 If this is for an explicit set of braces, IMPLICIT is 0.
5386 If it is because the next element belongs at a lower level,
5390 push_init_level (implicit)
5393 struct constructor_stack *p
5394 = (struct constructor_stack *) xmalloc (sizeof (struct constructor_stack));
5395 p->type = constructor_type;
5396 p->fields = constructor_fields;
5397 p->index = constructor_index;
5398 p->range_end = constructor_range_end;
5399 p->max_index = constructor_max_index;
5400 p->unfilled_index = constructor_unfilled_index;
5401 p->unfilled_fields = constructor_unfilled_fields;
5402 p->bit_index = constructor_bit_index;
5403 p->elements = constructor_elements;
5404 p->constant = constructor_constant;
5405 p->simple = constructor_simple;
5406 p->erroneous = constructor_erroneous;
5407 p->pending_elts = constructor_pending_elts;
5408 p->depth = constructor_depth;
5409 p->replacement_value = 0;
5410 p->implicit = implicit;
5411 p->incremental = constructor_incremental;
5413 p->next = constructor_stack;
5414 constructor_stack = p;
5416 constructor_constant = 1;
5417 constructor_simple = 1;
5418 constructor_depth = SPELLING_DEPTH ();
5419 constructor_elements = 0;
5420 constructor_pending_elts = 0;
5422 if (TREE_CODE (constructor_type) == RECORD_TYPE
5423 || TREE_CODE (constructor_type) == UNION_TYPE)
5425 constructor_type = TREE_TYPE (constructor_fields);
5426 push_member_name (IDENTIFIER_POINTER (DECL_NAME (constructor_fields)));
5428 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5430 constructor_type = TREE_TYPE (constructor_type);
5431 push_array_bounds (TREE_INT_CST_LOW (constructor_index));
5434 /* Turn off constructor_incremental if type is a struct with bitfields. */
5435 check_init_type_bitfields (constructor_type);
5437 if (TREE_CODE (constructor_type) == RECORD_TYPE
5438 || TREE_CODE (constructor_type) == UNION_TYPE)
5440 constructor_fields = TYPE_FIELDS (constructor_type);
5441 constructor_unfilled_fields = constructor_fields;
5442 constructor_bit_index = copy_node (integer_zero_node);
5444 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5446 constructor_index = copy_node (integer_zero_node);
5447 constructor_range_end = 0;
5448 constructor_unfilled_index = copy_node (integer_zero_node);
5449 if (TYPE_DOMAIN (constructor_type))
5450 constructor_max_index
5451 = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
5455 warning ("braces around scalar initializer");
5456 constructor_fields = constructor_type;
5457 constructor_unfilled_fields = constructor_type;
5461 /* Don't read a struct incrementally if it has any bitfields,
5462 because the incremental reading code doesn't know how to
5463 handle bitfields yet. */
5466 check_init_type_bitfields (type)
5469 if (TREE_CODE (type) == RECORD_TYPE)
5472 for (tail = TYPE_FIELDS (type); tail;
5473 tail = TREE_CHAIN (tail))
5474 if (DECL_BIT_FIELD (tail))
5476 constructor_incremental = 0;
5482 /* At the end of an implicit or explicit brace level,
5483 finish up that level of constructor.
5484 If we were outputting the elements as they are read, return 0
5485 from inner levels (process_init_element ignores that),
5486 but return error_mark_node from the outermost level
5487 (that's what we want to put in DECL_INITIAL).
5488 Otherwise, return a CONSTRUCTOR expression. */
5491 pop_init_level (implicit)
5494 struct constructor_stack *p;
5496 tree constructor = 0;
5500 /* When we come to an explicit close brace,
5501 pop any inner levels that didn't have explicit braces. */
5502 while (constructor_stack->implicit)
5503 process_init_element (pop_init_level (1));
5506 p = constructor_stack;
5507 size = int_size_in_bytes (constructor_type);
5509 /* Now output all pending elements. */
5510 output_pending_init_elements (1);
5512 #if 0 /* c-parse.in warns about {}. */
5513 /* In ANSI, each brace level must have at least one element. */
5514 if (! implicit && pedantic
5515 && (TREE_CODE (constructor_type) == ARRAY_TYPE
5516 ? integer_zerop (constructor_unfilled_index)
5517 : constructor_unfilled_fields == TYPE_FIELDS (constructor_type)))
5518 pedwarn_init ("empty braces in initializer%s", " for `%s'", NULL);
5521 /* Pad out the end of the structure. */
5523 if (p->replacement_value)
5525 /* If this closes a superfluous brace pair,
5526 just pass out the element between them. */
5527 constructor = p->replacement_value;
5528 /* If this is the top level thing within the initializer,
5529 and it's for a variable, then since we already called
5530 assemble_variable, we must output the value now. */
5531 if (p->next == 0 && constructor_decl != 0
5532 && constructor_incremental)
5534 constructor = digest_init (constructor_type, constructor,
5537 /* If initializing an array of unknown size,
5538 determine the size now. */
5539 if (TREE_CODE (constructor_type) == ARRAY_TYPE
5540 && TYPE_DOMAIN (constructor_type) == 0)
5544 push_obstacks_nochange ();
5545 if (TREE_PERMANENT (constructor_type))
5546 end_temporary_allocation ();
5548 /* We shouldn't have an incomplete array type within
5550 if (constructor_stack->next)
5554 = complete_array_type (constructor_type,
5559 size = int_size_in_bytes (constructor_type);
5563 output_constant (constructor, size);
5566 else if (! constructor_incremental)
5568 if (constructor_erroneous)
5569 constructor = error_mark_node;
5572 int momentary = suspend_momentary ();
5574 constructor = build (CONSTRUCTOR, constructor_type, NULL_TREE,
5575 nreverse (constructor_elements));
5576 if (constructor_constant)
5577 TREE_CONSTANT (constructor) = 1;
5578 if (constructor_constant && constructor_simple)
5579 TREE_STATIC (constructor) = 1;
5580 resume_momentary (momentary);
5586 int momentary = suspend_momentary ();
5588 if (TREE_CODE (constructor_type) == RECORD_TYPE
5589 || TREE_CODE (constructor_type) == UNION_TYPE)
5591 /* Find the offset of the end of that field. */
5592 filled = size_binop (CEIL_DIV_EXPR,
5593 constructor_bit_index,
5594 size_int (BITS_PER_UNIT));
5596 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5598 /* If initializing an array of unknown size,
5599 determine the size now. */
5600 if (TREE_CODE (constructor_type) == ARRAY_TYPE
5601 && TYPE_DOMAIN (constructor_type) == 0)
5604 = size_binop (MINUS_EXPR,
5605 constructor_unfilled_index,
5608 push_obstacks_nochange ();
5609 if (TREE_PERMANENT (constructor_type))
5610 end_temporary_allocation ();
5611 maxindex = copy_node (maxindex);
5612 TYPE_DOMAIN (constructor_type) = build_index_type (maxindex);
5613 TREE_TYPE (maxindex) = TYPE_DOMAIN (constructor_type);
5615 /* We shouldn't have an incomplete array type within
5617 if (constructor_stack->next)
5621 && tree_int_cst_lt (TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type)),
5623 error_with_decl (constructor_decl, "zero-size array `%s'");
5624 layout_type (constructor_type);
5625 size = int_size_in_bytes (constructor_type);
5629 filled = size_binop (MULT_EXPR, constructor_unfilled_index,
5630 size_in_bytes (TREE_TYPE (constructor_type)));
5636 assemble_zeros (size - TREE_INT_CST_LOW (filled));
5638 resume_momentary (momentary);
5642 constructor_type = p->type;
5643 constructor_fields = p->fields;
5644 constructor_index = p->index;
5645 constructor_range_end = p->range_end;
5646 constructor_max_index = p->max_index;
5647 constructor_unfilled_index = p->unfilled_index;
5648 constructor_unfilled_fields = p->unfilled_fields;
5649 constructor_bit_index = p->bit_index;
5650 constructor_elements = p->elements;
5651 constructor_constant = p->constant;
5652 constructor_simple = p->simple;
5653 constructor_erroneous = p->erroneous;
5654 constructor_pending_elts = p->pending_elts;
5655 constructor_depth = p->depth;
5656 constructor_incremental = p->incremental;
5657 RESTORE_SPELLING_DEPTH (constructor_depth);
5659 constructor_stack = p->next;
5662 if (constructor == 0)
5664 if (constructor_stack == 0)
5665 return error_mark_node;
5671 /* Within an array initializer, specify the next index to be initialized.
5672 FIRST is that index. If LAST is nonzero, then initialize a range
5673 of indices, running from FIRST through LAST. */
5676 set_init_index (first, last)
5679 if (tree_int_cst_lt (first, constructor_unfilled_index))
5680 error_init ("duplicate array index in initializer%s", " for `%s'", NULL);
5683 TREE_INT_CST_LOW (constructor_index)
5684 = TREE_INT_CST_LOW (first);
5685 TREE_INT_CST_HIGH (constructor_index)
5686 = TREE_INT_CST_HIGH (first);
5688 if (last != 0 && tree_int_cst_lt (last, first))
5689 error_init ("empty index range in initializer%s", " for `%s'", NULL);
5693 pedwarn ("ANSI C forbids specifying element to initialize");
5694 constructor_range_end = last;
5699 /* Within a struct initializer, specify the next field to be initialized. */
5702 set_init_label (fieldname)
5708 for (tail = TYPE_FIELDS (constructor_type); tail;
5709 tail = TREE_CHAIN (tail))
5711 if (tail == constructor_unfilled_fields)
5713 if (DECL_NAME (tail) == fieldname)
5718 error ("unknown field `%s' specified in initializer",
5719 IDENTIFIER_POINTER (fieldname));
5721 error ("field `%s' already initialized",
5722 IDENTIFIER_POINTER (fieldname));
5725 constructor_fields = tail;
5727 pedwarn ("ANSI C forbids specifying structure member to initialize");
5731 /* "Output" the next constructor element.
5732 At top level, really output it to assembler code now.
5733 Otherwise, collect it in a list from which we will make a CONSTRUCTOR.
5734 TYPE is the data type that the containing data type wants here.
5735 FIELD is the field (a FIELD_DECL) or the index that this element fills.
5737 PENDING if non-nil means output pending elements that belong
5738 right after this element. (PENDING is normally 1;
5739 it is 0 while outputting pending elements, to avoid recursion.) */
5742 output_init_element (value, type, field, pending)
5743 tree value, type, field;
5748 if (TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE
5749 || (TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE
5750 && !comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (value)),
5751 TYPE_MAIN_VARIANT (type))))
5752 value = default_conversion (value);
5754 if (value == error_mark_node)
5755 constructor_erroneous = 1;
5756 else if (!TREE_CONSTANT (value))
5757 constructor_constant = 0;
5758 else if (initializer_constant_valid_p (value, TREE_TYPE (value)) == 0)
5759 constructor_simple = 0;
5761 if (require_constant_value && ! TREE_CONSTANT (value))
5763 error_init ("initializer element%s is not constant",
5765 value = error_mark_node;
5767 else if (require_constant_elements
5768 && initializer_constant_valid_p (value, TREE_TYPE (value)) == 0)
5770 error_init ("initializer element%s is not computable at load time",
5772 value = error_mark_node;
5775 /* If this element duplicates one on constructor_pending_elts,
5776 print a message and ignore it. Don't do this when we're
5777 processing elements taken off constructor_pending_elts,
5778 because we'd always get spurious errors. */
5781 if (TREE_CODE (constructor_type) == RECORD_TYPE
5782 || TREE_CODE (constructor_type) == UNION_TYPE)
5784 if (purpose_member (field, constructor_pending_elts))
5786 error_init ("duplicate initializer%s", " for `%s'", NULL);
5790 if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5793 for (tail = constructor_pending_elts; tail;
5794 tail = TREE_CHAIN (tail))
5795 if (TREE_PURPOSE (tail) != 0
5796 && TREE_CODE (TREE_PURPOSE (tail)) == INTEGER_CST
5797 && tree_int_cst_equal (TREE_PURPOSE (tail), constructor_index))
5802 error_init ("duplicate initializer%s", " for `%s'", NULL);
5808 /* If this element doesn't come next in sequence,
5809 put it on constructor_pending_elts. */
5810 if (TREE_CODE (constructor_type) == ARRAY_TYPE
5811 && !tree_int_cst_equal (field, constructor_unfilled_index))
5814 constructor_pending_elts
5816 digest_init (type, value, 0, 0),
5817 constructor_pending_elts);
5819 else if ((TREE_CODE (constructor_type) == RECORD_TYPE
5820 || TREE_CODE (constructor_type) == UNION_TYPE)
5821 && field != constructor_unfilled_fields)
5824 constructor_pending_elts
5826 digest_init (type, value, 0, 0),
5827 constructor_pending_elts);
5831 /* Otherwise, output this element either to
5832 constructor_elements or to the assembler file. */
5836 if (! constructor_incremental)
5837 constructor_elements
5838 = tree_cons ((TREE_CODE (constructor_type) != ARRAY_TYPE
5840 digest_init (type, value, 0, 0),
5841 constructor_elements);
5844 /* Structure elements may require alignment.
5845 Do this, if necessary. */
5846 if (TREE_CODE (constructor_type) == RECORD_TYPE)
5848 /* Advance to offset of this element. */
5849 if (! tree_int_cst_equal (constructor_bit_index,
5850 DECL_FIELD_BITPOS (constructor_fields)))
5852 int next = (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
5854 int here = (TREE_INT_CST_LOW (constructor_bit_index)
5857 assemble_zeros (next - here);
5860 output_constant (digest_init (type, value, 0, 0),
5861 int_size_in_bytes (type));
5863 /* For a record, keep track of end position of last field. */
5864 if (TREE_CODE (constructor_type) == RECORD_TYPE)
5866 tree temp = size_binop (PLUS_EXPR,
5867 DECL_FIELD_BITPOS (constructor_fields),
5868 DECL_SIZE (constructor_fields));
5869 TREE_INT_CST_LOW (constructor_bit_index)
5870 = TREE_INT_CST_LOW (temp);
5871 TREE_INT_CST_HIGH (constructor_bit_index)
5872 = TREE_INT_CST_HIGH (temp);
5877 /* Advance the variable that indicates sequential elements output. */
5878 if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5880 tree tem = size_binop (PLUS_EXPR, constructor_unfilled_index,
5882 TREE_INT_CST_LOW (constructor_unfilled_index)
5883 = TREE_INT_CST_LOW (tem);
5884 TREE_INT_CST_HIGH (constructor_unfilled_index)
5885 = TREE_INT_CST_HIGH (tem);
5887 else if (TREE_CODE (constructor_type) == RECORD_TYPE)
5888 constructor_unfilled_fields = TREE_CHAIN (constructor_unfilled_fields);
5889 else if (TREE_CODE (constructor_type) == UNION_TYPE)
5890 constructor_unfilled_fields = 0;
5892 /* Now output any pending elements which have become next. */
5894 output_pending_init_elements (0);
5898 /* Output any pending elements which have become next.
5899 As we output elements, constructor_unfilled_{fields,index}
5900 advances, which may cause other elements to become next;
5901 if so, they too are output.
5903 If ALL is 0, we return when there are
5904 no more pending elements to output now.
5906 If ALL is 1, we output space as necessary so that
5907 we can output all the pending elements. */
5910 output_pending_init_elements (all)
5918 /* Look thru the whole pending list.
5919 If we find an element that should be output now,
5920 output it. Otherwise, set NEXT to the element
5921 that comes first among those still pending. */
5924 for (tail = constructor_pending_elts; tail;
5925 tail = TREE_CHAIN (tail))
5927 if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5929 if (tree_int_cst_equal (TREE_PURPOSE (tail),
5930 constructor_unfilled_index))
5932 output_init_element (TREE_VALUE (tail), TREE_TYPE (constructor_type),
5933 constructor_unfilled_index, 0);
5936 else if (tree_int_cst_lt (TREE_PURPOSE (tail),
5937 constructor_unfilled_index))
5940 || tree_int_cst_lt (TREE_PURPOSE (tail),
5942 next = TREE_PURPOSE (tail);
5944 else if (TREE_CODE (constructor_type) == RECORD_TYPE
5945 || TREE_CODE (constructor_type) == UNION_TYPE)
5947 if (TREE_PURPOSE (tail) == constructor_unfilled_fields)
5949 output_init_element (TREE_VALUE (tail),
5950 TREE_TYPE (constructor_unfilled_fields),
5951 constructor_unfilled_fields,
5955 else if (tree_int_cst_lt (DECL_FIELD_BITPOS (TREE_PURPOSE (tail)),
5956 DECL_FIELD_BITPOS (constructor_unfilled_fields)))
5959 || tree_int_cst_lt (DECL_FIELD_BITPOS (TREE_PURPOSE (tail)),
5960 DECL_FIELD_BITPOS (next)))
5961 next = TREE_PURPOSE (tail);
5965 /* Ordinarily return, but not if we want to output all
5966 and there are elements left. */
5967 if (! (all && next != 0))
5970 /* Generate space up to the position of NEXT. */
5971 if (constructor_incremental)
5976 if (TREE_CODE (constructor_type) == RECORD_TYPE
5977 || TREE_CODE (constructor_type) == UNION_TYPE)
5979 /* Find the last field written out. */
5980 for (tail = TYPE_FIELDS (constructor_type); tail;
5981 tail = TREE_CHAIN (tail))
5982 if (TREE_CHAIN (tail) == constructor_unfilled_fields)
5984 /* Find the offset of the end of that field. */
5985 filled = size_binop (CEIL_DIV_EXPR,
5986 size_binop (PLUS_EXPR,
5987 DECL_FIELD_BITPOS (tail),
5989 size_int (BITS_PER_UNIT));
5990 nextpos_tree = size_binop (CEIL_DIV_EXPR,
5991 DECL_FIELD_BITPOS (next),
5992 size_int (BITS_PER_UNIT));
5993 constructor_unfilled_fields = next;
5995 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5997 filled = size_binop (MULT_EXPR, constructor_unfilled_index,
5998 size_in_bytes (TREE_TYPE (constructor_type)));
6000 = size_binop (MULT_EXPR, next,
6001 size_in_bytes (TREE_TYPE (constructor_type)));
6002 TREE_INT_CST_LOW (constructor_unfilled_index)
6003 = TREE_INT_CST_LOW (next);
6004 TREE_INT_CST_HIGH (constructor_unfilled_index)
6005 = TREE_INT_CST_HIGH (next);
6012 int nextpos = TREE_INT_CST_LOW (nextpos_tree);
6014 assemble_zeros (nextpos - TREE_INT_CST_LOW (filled));
6021 /* Add one non-braced element to the current constructor level.
6022 This adjusts the current position within the constructor's type.
6023 This may also start or terminate implicit levels
6024 to handle a partly-braced initializer.
6026 Once this has found the correct level for the new element,
6027 it calls output_init_element.
6029 Note: if we are incrementally outputting this constructor,
6030 this function may be called with a null argument
6031 representing a sub-constructor that was already incrementally output.
6032 When that happens, we output nothing, but we do the bookkeeping
6033 to skip past that element of the current constructor. */
6036 process_init_element (value)
6039 tree orig_value = value;
6040 int string_flag = value != 0 && TREE_CODE (value) == STRING_CST;
6042 /* Handle superfluous braces around string cst as in
6043 char x[] = {"foo"}; */
6045 && TREE_CODE (constructor_type) == ARRAY_TYPE
6046 && TREE_CODE (TREE_TYPE (constructor_type)) == INTEGER_TYPE
6047 && integer_zerop (constructor_unfilled_index))
6049 constructor_stack->replacement_value = value;
6053 if (constructor_stack->replacement_value != 0)
6055 error_init ("excess elements in struct initializer%s",
6056 " after `%s'", NULL_PTR);
6060 /* If we've exhausted any levels that didn't have braces,
6062 while (constructor_stack->implicit)
6064 if ((TREE_CODE (constructor_type) == RECORD_TYPE
6065 || TREE_CODE (constructor_type) == UNION_TYPE)
6066 && constructor_fields == 0)
6067 process_init_element (pop_init_level (1));
6068 else if (TREE_CODE (constructor_type) == ARRAY_TYPE
6069 && tree_int_cst_lt (constructor_max_index, constructor_index))
6070 process_init_element (pop_init_level (1));
6077 if (TREE_CODE (constructor_type) == RECORD_TYPE)
6080 enum tree_code fieldcode;
6082 if (constructor_fields == 0)
6084 pedwarn_init ("excess elements in struct initializer%s",
6085 " after `%s'", NULL_PTR);
6089 fieldtype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_fields));
6090 fieldcode = TREE_CODE (fieldtype);
6092 /* Accept a string constant to initialize a subarray. */
6094 && fieldcode == ARRAY_TYPE
6095 && TREE_CODE (TREE_TYPE (fieldtype)) == INTEGER_TYPE
6098 /* Otherwise, if we have come to a subaggregate,
6099 and we don't have an element of its type, push into it. */
6101 && TYPE_MAIN_VARIANT (TREE_TYPE (value)) != fieldtype
6102 && (fieldcode == RECORD_TYPE || fieldcode == ARRAY_TYPE
6103 || fieldcode == UNION_TYPE))
6105 push_init_level (1);
6111 push_member_name (IDENTIFIER_POINTER (DECL_NAME (constructor_fields)));
6112 output_init_element (value, fieldtype, constructor_fields, 1);
6113 RESTORE_SPELLING_DEPTH (constructor_depth);
6116 /* Do the bookkeeping for an element that was
6117 directly output as a constructor. */
6119 /* For a record, keep track of end position of last field. */
6120 tree temp = size_binop (PLUS_EXPR,
6121 DECL_FIELD_BITPOS (constructor_fields),
6122 DECL_SIZE (constructor_fields));
6123 TREE_INT_CST_LOW (constructor_bit_index)
6124 = TREE_INT_CST_LOW (temp);
6125 TREE_INT_CST_HIGH (constructor_bit_index)
6126 = TREE_INT_CST_HIGH (temp);
6128 constructor_unfilled_fields = TREE_CHAIN (constructor_fields);
6131 constructor_fields = TREE_CHAIN (constructor_fields);
6134 if (TREE_CODE (constructor_type) == UNION_TYPE)
6137 enum tree_code fieldcode;
6139 if (constructor_fields == 0)
6141 pedwarn_init ("excess elements in union initializer%s",
6142 " after `%s'", NULL_PTR);
6146 fieldtype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_fields));
6147 fieldcode = TREE_CODE (fieldtype);
6149 /* Accept a string constant to initialize a subarray. */
6151 && fieldcode == ARRAY_TYPE
6152 && TREE_CODE (TREE_TYPE (fieldtype)) == INTEGER_TYPE
6155 /* Otherwise, if we have come to a subaggregate,
6156 and we don't have an element of its type, push into it. */
6158 && TYPE_MAIN_VARIANT (TREE_TYPE (value)) != fieldtype
6159 && (fieldcode == RECORD_TYPE || fieldcode == ARRAY_TYPE
6160 || fieldcode == UNION_TYPE))
6162 push_init_level (1);
6168 push_member_name (IDENTIFIER_POINTER (DECL_NAME (constructor_fields)));
6169 output_init_element (value, fieldtype, constructor_fields, 1);
6170 RESTORE_SPELLING_DEPTH (constructor_depth);
6173 /* If we are doing the bookkeeping for an element that was
6174 directly output as a constructor,
6175 we must update constructor_unfilled_fields. */
6176 constructor_unfilled_fields = 0;
6178 constructor_fields = 0;
6181 if (TREE_CODE (constructor_type) == ARRAY_TYPE)
6183 tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
6184 enum tree_code eltcode = TREE_CODE (elttype);
6186 /* Accept a string constant to initialize a subarray. */
6188 && eltcode == ARRAY_TYPE
6189 && TREE_CODE (TREE_TYPE (elttype)) == INTEGER_TYPE
6192 /* Otherwise, if we have come to a subaggregate,
6193 and we don't have an element of its type, push into it. */
6195 && TYPE_MAIN_VARIANT (TREE_TYPE (value)) != elttype
6196 && (eltcode == RECORD_TYPE || eltcode == ARRAY_TYPE
6197 || eltcode == UNION_TYPE))
6199 push_init_level (1);
6203 if (constructor_max_index != 0
6204 && tree_int_cst_lt (constructor_max_index, constructor_index))
6206 pedwarn_init ("excess elements in array initializer%s",
6207 " after `%s'", NULL_PTR);
6211 /* Now output the actual element.
6212 Ordinarily, output once.
6213 If there is a range, repeat it till we advance past the range. */
6220 push_array_bounds (TREE_INT_CST_LOW (constructor_index));
6221 output_init_element (value, elttype, constructor_index, 1);
6222 RESTORE_SPELLING_DEPTH (constructor_depth);
6225 tem = size_binop (PLUS_EXPR, constructor_index,
6227 TREE_INT_CST_LOW (constructor_index)
6228 = TREE_INT_CST_LOW (tem);
6229 TREE_INT_CST_HIGH (constructor_index)
6230 = TREE_INT_CST_HIGH (tem);
6233 /* If we are doing the bookkeeping for an element that was
6234 directly output as a constructor,
6235 we must update constructor_unfilled_index. */
6237 TREE_INT_CST_LOW (constructor_unfilled_index)
6238 = TREE_INT_CST_LOW (constructor_index);
6239 TREE_INT_CST_HIGH (constructor_unfilled_index)
6240 = TREE_INT_CST_HIGH (constructor_index);
6243 while (! (constructor_range_end == 0
6244 || tree_int_cst_lt (constructor_range_end,
6245 constructor_index)));
6250 /* Handle the sole element allowed in a braced initializer
6251 for a scalar variable. */
6252 if (constructor_fields == 0)
6254 pedwarn_init ("excess elements in scalar initializer%s",
6255 " after `%s'", NULL_PTR);
6260 output_init_element (value, constructor_type, NULL_TREE, 1);
6261 constructor_fields = 0;
6265 /* If the (lexically) previous elments are not now saved,
6266 we can discard the storage for them. */
6267 if (constructor_incremental && constructor_pending_elts == 0 && value != 0)
6271 /* Expand an ASM statement with operands, handling output operands
6272 that are not variables or INDIRECT_REFS by transforming such
6273 cases into cases that expand_asm_operands can handle.
6275 Arguments are same as for expand_asm_operands. */
6278 c_expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line)
6279 tree string, outputs, inputs, clobbers;
6284 int noutputs = list_length (outputs);
6286 /* o[I] is the place that output number I should be written. */
6287 register tree *o = (tree *) alloca (noutputs * sizeof (tree));
6290 if (TREE_CODE (string) == ADDR_EXPR)
6291 string = TREE_OPERAND (string, 0);
6292 if (TREE_CODE (string) != STRING_CST)
6294 error ("asm template is not a string constant");
6298 /* Record the contents of OUTPUTS before it is modified. */
6299 for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
6300 o[i] = TREE_VALUE (tail);
6302 /* Perform default conversions on array and function inputs. */
6303 /* Don't do this for other types--
6304 it would screw up operands expected to be in memory. */
6305 for (i = 0, tail = inputs; tail; tail = TREE_CHAIN (tail), i++)
6306 if (TREE_CODE (TREE_TYPE (TREE_VALUE (tail))) == ARRAY_TYPE
6307 || TREE_CODE (TREE_TYPE (TREE_VALUE (tail))) == FUNCTION_TYPE)
6308 TREE_VALUE (tail) = default_conversion (TREE_VALUE (tail));
6310 /* Generate the ASM_OPERANDS insn;
6311 store into the TREE_VALUEs of OUTPUTS some trees for
6312 where the values were actually stored. */
6313 expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line);
6315 /* Copy all the intermediate outputs into the specified outputs. */
6316 for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
6318 if (o[i] != TREE_VALUE (tail))
6320 expand_expr (build_modify_expr (o[i], NOP_EXPR, TREE_VALUE (tail)),
6324 /* Detect modification of read-only values.
6325 (Otherwise done by build_modify_expr.) */
6328 tree type = TREE_TYPE (o[i]);
6329 if (TYPE_READONLY (type)
6330 || ((TREE_CODE (type) == RECORD_TYPE
6331 || TREE_CODE (type) == UNION_TYPE)
6332 && C_TYPE_FIELDS_READONLY (type)))
6333 readonly_warning (o[i], "modification by `asm'");
6337 /* Those MODIFY_EXPRs could do autoincrements. */
6341 /* Expand a C `return' statement.
6342 RETVAL is the expression for what to return,
6343 or a null pointer for `return;' with no value. */
6346 c_expand_return (retval)
6349 tree valtype = TREE_TYPE (TREE_TYPE (current_function_decl));
6351 if (TREE_THIS_VOLATILE (current_function_decl))
6352 warning ("function declared `volatile' has a `return' statement");
6356 current_function_returns_null = 1;
6357 if (warn_return_type && valtype != 0 && TREE_CODE (valtype) != VOID_TYPE)
6358 warning ("`return' with no value, in function returning non-void");
6359 expand_null_return ();
6361 else if (valtype == 0 || TREE_CODE (valtype) == VOID_TYPE)
6363 current_function_returns_null = 1;
6364 if (pedantic || TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
6365 pedwarn ("`return' with a value, in function returning void");
6366 expand_return (retval);
6370 tree t = convert_for_assignment (valtype, retval, "return",
6371 NULL_TREE, NULL_TREE, 0);
6372 tree res = DECL_RESULT (current_function_decl);
6373 t = build (MODIFY_EXPR, TREE_TYPE (res),
6374 res, convert (TREE_TYPE (res), t));
6375 TREE_SIDE_EFFECTS (t) = 1;
6377 current_function_returns_value = 1;
6381 /* Start a C switch statement, testing expression EXP.
6382 Return EXP if it is valid, an error node otherwise. */
6385 c_expand_start_case (exp)
6388 register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
6389 tree type = TREE_TYPE (exp);
6391 if (code != INTEGER_TYPE && code != ENUMERAL_TYPE && code != ERROR_MARK)
6393 error ("switch quantity not an integer");
6394 exp = error_mark_node;
6399 type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
6401 if (warn_traditional
6402 && (type == long_integer_type_node
6403 || type == long_unsigned_type_node))
6404 pedwarn ("`long' switch expression not converted to `int' in ANSI C");
6406 exp = default_conversion (exp);
6407 type = TREE_TYPE (exp);
6408 index = get_unwidened (exp, NULL_TREE);
6409 /* We can't strip a conversion from a signed type to an unsigned,
6410 because if we did, int_fits_type_p would do the wrong thing
6411 when checking case values for being in range,
6412 and it's too hard to do the right thing. */
6413 if (TREE_UNSIGNED (TREE_TYPE (exp))
6414 == TREE_UNSIGNED (TREE_TYPE (index)))
6418 expand_start_case (1, exp, type, "switch statement");