1 /* Build expressions with type checking for C compiler.
2 Copyright (C) 1987, 1988, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 /* This file is part of the C front end.
24 It contains routines to build C expressions given their operands,
25 including computing the types of the result, C-specific error checks,
26 and some optimization.
28 There are also routines to build RETURN_STMT nodes and CASE_STMT nodes,
29 and to process initializations in declarations (since they work
30 like a strange sort of assignment). */
45 /* Nonzero if we've already printed a "missing braces around initializer"
46 message within this initializer. */
47 static int missing_braces_mentioned;
49 /* 1 if we explained undeclared var errors. */
50 static int undeclared_variable_notice;
52 static tree qualify_type PARAMS ((tree, tree));
53 static int comp_target_types PARAMS ((tree, tree));
54 static int function_types_compatible_p PARAMS ((tree, tree));
55 static int type_lists_compatible_p PARAMS ((tree, tree));
56 static tree decl_constant_value_for_broken_optimization PARAMS ((tree));
57 static tree lookup_field PARAMS ((tree, tree, tree *));
58 static tree convert_arguments PARAMS ((tree, tree, tree, tree));
59 static tree pointer_int_sum PARAMS ((enum tree_code, tree, tree));
60 static tree pointer_diff PARAMS ((tree, tree));
61 static tree unary_complex_lvalue PARAMS ((enum tree_code, tree));
62 static void pedantic_lvalue_warning PARAMS ((enum tree_code));
63 static tree internal_build_compound_expr PARAMS ((tree, int));
64 static tree convert_for_assignment PARAMS ((tree, tree, const char *,
66 static void warn_for_assignment PARAMS ((const char *, const char *,
68 static tree valid_compound_expr_initializer PARAMS ((tree, tree));
69 static void push_string PARAMS ((const char *));
70 static void push_member_name PARAMS ((tree));
71 static void push_array_bounds PARAMS ((int));
72 static int spelling_length PARAMS ((void));
73 static char *print_spelling PARAMS ((char *));
74 static void warning_init PARAMS ((const char *));
75 static tree digest_init PARAMS ((tree, tree, int, int));
76 static void output_init_element PARAMS ((tree, tree, tree, int));
77 static void output_pending_init_elements PARAMS ((int));
78 static int set_designator PARAMS ((int));
79 static void push_range_stack PARAMS ((tree));
80 static void add_pending_init PARAMS ((tree, tree));
81 static void set_nonincremental_init PARAMS ((void));
82 static void set_nonincremental_init_from_string PARAMS ((tree));
83 static tree find_init_member PARAMS ((tree));
85 /* Do `exp = require_complete_type (exp);' to make sure exp
86 does not have an incomplete type. (That includes void types.) */
89 require_complete_type (value)
92 tree type = TREE_TYPE (value);
94 if (TREE_CODE (value) == ERROR_MARK)
95 return error_mark_node;
97 /* First, detect a valid value with a complete type. */
98 if (COMPLETE_TYPE_P (type))
101 incomplete_type_error (value, type);
102 return error_mark_node;
105 /* Print an error message for invalid use of an incomplete type.
106 VALUE is the expression that was used (or 0 if that isn't known)
107 and TYPE is the type that was invalid. */
110 incomplete_type_error (value, type)
114 const char *type_code_string;
116 /* Avoid duplicate error message. */
117 if (TREE_CODE (type) == ERROR_MARK)
120 if (value != 0 && (TREE_CODE (value) == VAR_DECL
121 || TREE_CODE (value) == PARM_DECL))
122 error ("`%s' has an incomplete type",
123 IDENTIFIER_POINTER (DECL_NAME (value)));
127 /* We must print an error message. Be clever about what it says. */
129 switch (TREE_CODE (type))
132 type_code_string = "struct";
136 type_code_string = "union";
140 type_code_string = "enum";
144 error ("invalid use of void expression");
148 if (TYPE_DOMAIN (type))
150 type = TREE_TYPE (type);
153 error ("invalid use of array with unspecified bounds");
160 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
161 error ("invalid use of undefined type `%s %s'",
162 type_code_string, IDENTIFIER_POINTER (TYPE_NAME (type)));
164 /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL. */
165 error ("invalid use of incomplete typedef `%s'",
166 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))));
170 /* Return a variant of TYPE which has all the type qualifiers of LIKE
171 as well as those of TYPE. */
174 qualify_type (type, like)
177 return c_build_qualified_type (type,
178 TYPE_QUALS (type) | TYPE_QUALS (like));
181 /* Return the common type of two types.
182 We assume that comptypes has already been done and returned 1;
183 if that isn't so, this may crash. In particular, we assume that qualifiers
186 This is the type for the result of most arithmetic operations
187 if the operands have the given two types. */
193 register enum tree_code code1;
194 register enum tree_code code2;
197 /* Save time if the two types are the same. */
199 if (t1 == t2) return t1;
201 /* If one type is nonsense, use the other. */
202 if (t1 == error_mark_node)
204 if (t2 == error_mark_node)
207 /* Merge the attributes. */
208 attributes = merge_machine_type_attributes (t1, t2);
210 /* Treat an enum type as the unsigned integer type of the same width. */
212 if (TREE_CODE (t1) == ENUMERAL_TYPE)
213 t1 = type_for_size (TYPE_PRECISION (t1), 1);
214 if (TREE_CODE (t2) == ENUMERAL_TYPE)
215 t2 = type_for_size (TYPE_PRECISION (t2), 1);
217 code1 = TREE_CODE (t1);
218 code2 = TREE_CODE (t2);
220 /* If one type is complex, form the common type of the non-complex
221 components, then make that complex. Use T1 or T2 if it is the
223 if (code1 == COMPLEX_TYPE || code2 == COMPLEX_TYPE)
225 tree subtype1 = code1 == COMPLEX_TYPE ? TREE_TYPE (t1) : t1;
226 tree subtype2 = code2 == COMPLEX_TYPE ? TREE_TYPE (t2) : t2;
227 tree subtype = common_type (subtype1, subtype2);
229 if (code1 == COMPLEX_TYPE && TREE_TYPE (t1) == subtype)
230 return build_type_attribute_variant (t1, attributes);
231 else if (code2 == COMPLEX_TYPE && TREE_TYPE (t2) == subtype)
232 return build_type_attribute_variant (t2, attributes);
234 return build_type_attribute_variant (build_complex_type (subtype),
242 /* If only one is real, use it as the result. */
244 if (code1 == REAL_TYPE && code2 != REAL_TYPE)
245 return build_type_attribute_variant (t1, attributes);
247 if (code2 == REAL_TYPE && code1 != REAL_TYPE)
248 return build_type_attribute_variant (t2, attributes);
250 /* Both real or both integers; use the one with greater precision. */
252 if (TYPE_PRECISION (t1) > TYPE_PRECISION (t2))
253 return build_type_attribute_variant (t1, attributes);
254 else if (TYPE_PRECISION (t2) > TYPE_PRECISION (t1))
255 return build_type_attribute_variant (t2, attributes);
257 /* Same precision. Prefer longs to ints even when same size. */
259 if (TYPE_MAIN_VARIANT (t1) == long_unsigned_type_node
260 || TYPE_MAIN_VARIANT (t2) == long_unsigned_type_node)
261 return build_type_attribute_variant (long_unsigned_type_node,
264 if (TYPE_MAIN_VARIANT (t1) == long_integer_type_node
265 || TYPE_MAIN_VARIANT (t2) == long_integer_type_node)
267 /* But preserve unsignedness from the other type,
268 since long cannot hold all the values of an unsigned int. */
269 if (TREE_UNSIGNED (t1) || TREE_UNSIGNED (t2))
270 t1 = long_unsigned_type_node;
272 t1 = long_integer_type_node;
273 return build_type_attribute_variant (t1, attributes);
276 /* Likewise, prefer long double to double even if same size. */
277 if (TYPE_MAIN_VARIANT (t1) == long_double_type_node
278 || TYPE_MAIN_VARIANT (t2) == long_double_type_node)
279 return build_type_attribute_variant (long_double_type_node,
282 /* Otherwise prefer the unsigned one. */
284 if (TREE_UNSIGNED (t1))
285 return build_type_attribute_variant (t1, attributes);
287 return build_type_attribute_variant (t2, attributes);
290 /* For two pointers, do this recursively on the target type,
291 and combine the qualifiers of the two types' targets. */
292 /* This code was turned off; I don't know why.
293 But ANSI C specifies doing this with the qualifiers.
294 So I turned it on again. */
296 tree pointed_to_1 = TREE_TYPE (t1);
297 tree pointed_to_2 = TREE_TYPE (t2);
298 tree target = common_type (TYPE_MAIN_VARIANT (pointed_to_1),
299 TYPE_MAIN_VARIANT (pointed_to_2));
300 t1 = build_pointer_type (c_build_qualified_type
302 TYPE_QUALS (pointed_to_1) |
303 TYPE_QUALS (pointed_to_2)));
304 return build_type_attribute_variant (t1, attributes);
307 t1 = build_pointer_type (common_type (TREE_TYPE (t1), TREE_TYPE (t2)));
308 return build_type_attribute_variant (t1, attributes);
313 tree elt = common_type (TREE_TYPE (t1), TREE_TYPE (t2));
314 /* Save space: see if the result is identical to one of the args. */
315 if (elt == TREE_TYPE (t1) && TYPE_DOMAIN (t1))
316 return build_type_attribute_variant (t1, attributes);
317 if (elt == TREE_TYPE (t2) && TYPE_DOMAIN (t2))
318 return build_type_attribute_variant (t2, attributes);
319 /* Merge the element types, and have a size if either arg has one. */
320 t1 = build_array_type (elt, TYPE_DOMAIN (TYPE_DOMAIN (t1) ? t1 : t2));
321 return build_type_attribute_variant (t1, attributes);
325 /* Function types: prefer the one that specified arg types.
326 If both do, merge the arg types. Also merge the return types. */
328 tree valtype = common_type (TREE_TYPE (t1), TREE_TYPE (t2));
329 tree p1 = TYPE_ARG_TYPES (t1);
330 tree p2 = TYPE_ARG_TYPES (t2);
335 /* Save space: see if the result is identical to one of the args. */
336 if (valtype == TREE_TYPE (t1) && ! TYPE_ARG_TYPES (t2))
337 return build_type_attribute_variant (t1, attributes);
338 if (valtype == TREE_TYPE (t2) && ! TYPE_ARG_TYPES (t1))
339 return build_type_attribute_variant (t2, attributes);
341 /* Simple way if one arg fails to specify argument types. */
342 if (TYPE_ARG_TYPES (t1) == 0)
344 t1 = build_function_type (valtype, TYPE_ARG_TYPES (t2));
345 return build_type_attribute_variant (t1, attributes);
347 if (TYPE_ARG_TYPES (t2) == 0)
349 t1 = build_function_type (valtype, TYPE_ARG_TYPES (t1));
350 return build_type_attribute_variant (t1, attributes);
353 /* If both args specify argument types, we must merge the two
354 lists, argument by argument. */
357 declare_parm_level (1);
359 len = list_length (p1);
362 for (i = 0; i < len; i++)
363 newargs = tree_cons (NULL_TREE, NULL_TREE, newargs);
368 p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2), n = TREE_CHAIN (n))
370 /* A null type means arg type is not specified.
371 Take whatever the other function type has. */
372 if (TREE_VALUE (p1) == 0)
374 TREE_VALUE (n) = TREE_VALUE (p2);
377 if (TREE_VALUE (p2) == 0)
379 TREE_VALUE (n) = TREE_VALUE (p1);
383 /* Given wait (union {union wait *u; int *i} *)
384 and wait (union wait *),
385 prefer union wait * as type of parm. */
386 if (TREE_CODE (TREE_VALUE (p1)) == UNION_TYPE
387 && TREE_VALUE (p1) != TREE_VALUE (p2))
390 for (memb = TYPE_FIELDS (TREE_VALUE (p1));
391 memb; memb = TREE_CHAIN (memb))
392 if (comptypes (TREE_TYPE (memb), TREE_VALUE (p2)))
394 TREE_VALUE (n) = TREE_VALUE (p2);
396 pedwarn ("function types not truly compatible in ISO C");
400 if (TREE_CODE (TREE_VALUE (p2)) == UNION_TYPE
401 && TREE_VALUE (p2) != TREE_VALUE (p1))
404 for (memb = TYPE_FIELDS (TREE_VALUE (p2));
405 memb; memb = TREE_CHAIN (memb))
406 if (comptypes (TREE_TYPE (memb), TREE_VALUE (p1)))
408 TREE_VALUE (n) = TREE_VALUE (p1);
410 pedwarn ("function types not truly compatible in ISO C");
414 TREE_VALUE (n) = common_type (TREE_VALUE (p1), TREE_VALUE (p2));
420 t1 = build_function_type (valtype, newargs);
421 /* ... falls through ... */
425 return build_type_attribute_variant (t1, attributes);
430 /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
431 or various other operations. Return 2 if they are compatible
432 but a warning may be needed if you use them together. */
435 comptypes (type1, type2)
438 register tree t1 = type1;
439 register tree t2 = type2;
442 /* Suppress errors caused by previously reported errors. */
444 if (t1 == t2 || !t1 || !t2
445 || TREE_CODE (t1) == ERROR_MARK || TREE_CODE (t2) == ERROR_MARK)
448 /* If either type is the internal version of sizetype, return the
450 if (TREE_CODE (t1) == INTEGER_TYPE && TYPE_IS_SIZETYPE (t1)
451 && TYPE_DOMAIN (t1) != 0)
452 t1 = TYPE_DOMAIN (t1);
454 if (TREE_CODE (t2) == INTEGER_TYPE && TYPE_IS_SIZETYPE (t2)
455 && TYPE_DOMAIN (t2) != 0)
456 t2 = TYPE_DOMAIN (t2);
458 /* Treat an enum type as the integer type of the same width and
461 if (TREE_CODE (t1) == ENUMERAL_TYPE)
462 t1 = type_for_size (TYPE_PRECISION (t1), TREE_UNSIGNED (t1));
463 if (TREE_CODE (t2) == ENUMERAL_TYPE)
464 t2 = type_for_size (TYPE_PRECISION (t2), TREE_UNSIGNED (t2));
469 /* Different classes of types can't be compatible. */
471 if (TREE_CODE (t1) != TREE_CODE (t2)) return 0;
473 /* Qualifiers must match. */
475 if (TYPE_QUALS (t1) != TYPE_QUALS (t2))
478 /* Allow for two different type nodes which have essentially the same
479 definition. Note that we already checked for equality of the type
480 qualifiers (just above). */
482 if (TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
485 #ifndef COMP_TYPE_ATTRIBUTES
486 #define COMP_TYPE_ATTRIBUTES(t1,t2) 1
489 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
490 if (! (attrval = COMP_TYPE_ATTRIBUTES (t1, t2)))
493 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
496 switch (TREE_CODE (t1))
499 val = (TREE_TYPE (t1) == TREE_TYPE (t2)
500 ? 1 : comptypes (TREE_TYPE (t1), TREE_TYPE (t2)));
504 val = function_types_compatible_p (t1, t2);
509 tree d1 = TYPE_DOMAIN (t1);
510 tree d2 = TYPE_DOMAIN (t2);
513 /* Target types must match incl. qualifiers. */
514 if (TREE_TYPE (t1) != TREE_TYPE (t2)
515 && 0 == (val = comptypes (TREE_TYPE (t1), TREE_TYPE (t2))))
518 /* Sizes must match unless one is missing or variable. */
519 if (d1 == 0 || d2 == 0 || d1 == d2
520 || TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST
521 || TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST
522 || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST
523 || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST)
526 if (! tree_int_cst_equal (TYPE_MIN_VALUE (d1), TYPE_MIN_VALUE (d2))
527 || ! tree_int_cst_equal (TYPE_MAX_VALUE (d1), TYPE_MAX_VALUE (d2)))
534 if (maybe_objc_comptypes (t1, t2, 0) == 1)
541 return attrval == 2 && val == 1 ? 2 : val;
544 /* Return 1 if TTL and TTR are pointers to types that are equivalent,
545 ignoring their qualifiers. */
548 comp_target_types (ttl, ttr)
553 /* Give maybe_objc_comptypes a crack at letting these types through. */
554 if ((val = maybe_objc_comptypes (ttl, ttr, 1)) >= 0)
557 val = comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (ttl)),
558 TYPE_MAIN_VARIANT (TREE_TYPE (ttr)));
560 if (val == 2 && pedantic)
561 pedwarn ("types are not quite compatible");
565 /* Subroutines of `comptypes'. */
567 /* Return 1 if two function types F1 and F2 are compatible.
568 If either type specifies no argument types,
569 the other must specify a fixed number of self-promoting arg types.
570 Otherwise, if one type specifies only the number of arguments,
571 the other must specify that number of self-promoting arg types.
572 Otherwise, the argument types must match. */
575 function_types_compatible_p (f1, f2)
579 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
583 if (!(TREE_TYPE (f1) == TREE_TYPE (f2)
584 || (val = comptypes (TREE_TYPE (f1), TREE_TYPE (f2)))))
587 args1 = TYPE_ARG_TYPES (f1);
588 args2 = TYPE_ARG_TYPES (f2);
590 /* An unspecified parmlist matches any specified parmlist
591 whose argument types don't need default promotions. */
595 if (!self_promoting_args_p (args2))
597 /* If one of these types comes from a non-prototype fn definition,
598 compare that with the other type's arglist.
599 If they don't match, ask for a warning (but no error). */
600 if (TYPE_ACTUAL_ARG_TYPES (f1)
601 && 1 != type_lists_compatible_p (args2, TYPE_ACTUAL_ARG_TYPES (f1)))
607 if (!self_promoting_args_p (args1))
609 if (TYPE_ACTUAL_ARG_TYPES (f2)
610 && 1 != type_lists_compatible_p (args1, TYPE_ACTUAL_ARG_TYPES (f2)))
615 /* Both types have argument lists: compare them and propagate results. */
616 val1 = type_lists_compatible_p (args1, args2);
617 return val1 != 1 ? val1 : val;
620 /* Check two lists of types for compatibility,
621 returning 0 for incompatible, 1 for compatible,
622 or 2 for compatible with warning. */
625 type_lists_compatible_p (args1, args2)
628 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
634 if (args1 == 0 && args2 == 0)
636 /* If one list is shorter than the other,
637 they fail to match. */
638 if (args1 == 0 || args2 == 0)
640 /* A null pointer instead of a type
641 means there is supposed to be an argument
642 but nothing is specified about what type it has.
643 So match anything that self-promotes. */
644 if (TREE_VALUE (args1) == 0)
646 if (simple_type_promotes_to (TREE_VALUE (args2)) != NULL_TREE)
649 else if (TREE_VALUE (args2) == 0)
651 if (simple_type_promotes_to (TREE_VALUE (args1)) != NULL_TREE)
654 else if (! (newval = comptypes (TREE_VALUE (args1), TREE_VALUE (args2))))
656 /* Allow wait (union {union wait *u; int *i} *)
657 and wait (union wait *) to be compatible. */
658 if (TREE_CODE (TREE_VALUE (args1)) == UNION_TYPE
659 && (TYPE_NAME (TREE_VALUE (args1)) == 0
660 || TYPE_TRANSPARENT_UNION (TREE_VALUE (args1)))
661 && TREE_CODE (TYPE_SIZE (TREE_VALUE (args1))) == INTEGER_CST
662 && tree_int_cst_equal (TYPE_SIZE (TREE_VALUE (args1)),
663 TYPE_SIZE (TREE_VALUE (args2))))
666 for (memb = TYPE_FIELDS (TREE_VALUE (args1));
667 memb; memb = TREE_CHAIN (memb))
668 if (comptypes (TREE_TYPE (memb), TREE_VALUE (args2)))
673 else if (TREE_CODE (TREE_VALUE (args2)) == UNION_TYPE
674 && (TYPE_NAME (TREE_VALUE (args2)) == 0
675 || TYPE_TRANSPARENT_UNION (TREE_VALUE (args2)))
676 && TREE_CODE (TYPE_SIZE (TREE_VALUE (args2))) == INTEGER_CST
677 && tree_int_cst_equal (TYPE_SIZE (TREE_VALUE (args2)),
678 TYPE_SIZE (TREE_VALUE (args1))))
681 for (memb = TYPE_FIELDS (TREE_VALUE (args2));
682 memb; memb = TREE_CHAIN (memb))
683 if (comptypes (TREE_TYPE (memb), TREE_VALUE (args1)))
692 /* comptypes said ok, but record if it said to warn. */
696 args1 = TREE_CHAIN (args1);
697 args2 = TREE_CHAIN (args2);
701 /* Compute the value of the `sizeof' operator. */
707 enum tree_code code = TREE_CODE (type);
710 if (code == FUNCTION_TYPE)
712 if (pedantic || warn_pointer_arith)
713 pedwarn ("sizeof applied to a function type");
714 size = size_one_node;
716 else if (code == VOID_TYPE)
718 if (pedantic || warn_pointer_arith)
719 pedwarn ("sizeof applied to a void type");
720 size = size_one_node;
722 else if (code == ERROR_MARK)
723 size = size_one_node;
724 else if (!COMPLETE_TYPE_P (type))
726 error ("sizeof applied to an incomplete type");
727 size = size_zero_node;
730 /* Convert in case a char is more than one unit. */
731 size = size_binop (CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
732 size_int (TYPE_PRECISION (char_type_node)
735 /* SIZE will have an integer type with TYPE_IS_SIZETYPE set.
736 TYPE_IS_SIZETYPE means that certain things (like overflow) will
737 never happen. However, this node should really have type
738 `size_t', which is just a typedef for an ordinary integer type. */
739 return fold (build1 (NOP_EXPR, c_size_type_node, size));
743 c_sizeof_nowarn (type)
746 enum tree_code code = TREE_CODE (type);
749 if (code == FUNCTION_TYPE || code == VOID_TYPE || code == ERROR_MARK)
750 size = size_one_node;
751 else if (!COMPLETE_TYPE_P (type))
752 size = size_zero_node;
754 /* Convert in case a char is more than one unit. */
755 size = size_binop (CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
756 size_int (TYPE_PRECISION (char_type_node)
759 /* SIZE will have an integer type with TYPE_IS_SIZETYPE set.
760 TYPE_IS_SIZETYPE means that certain things (like overflow) will
761 never happen. However, this node should really have type
762 `size_t', which is just a typedef for an ordinary integer type. */
763 return fold (build1 (NOP_EXPR, c_size_type_node, size));
766 /* Compute the size to increment a pointer by. */
769 c_size_in_bytes (type)
772 enum tree_code code = TREE_CODE (type);
774 if (code == FUNCTION_TYPE || code == VOID_TYPE || code == ERROR_MARK)
775 return size_one_node;
777 if (!COMPLETE_OR_VOID_TYPE_P (type))
779 error ("arithmetic on pointer to an incomplete type");
780 return size_one_node;
783 /* Convert in case a char is more than one unit. */
784 return size_binop (CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
785 size_int (TYPE_PRECISION (char_type_node)
789 /* Implement the __alignof keyword: Return the minimum required
790 alignment of TYPE, measured in bytes. */
796 enum tree_code code = TREE_CODE (type);
799 if (code == FUNCTION_TYPE)
800 t = size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
801 else if (code == VOID_TYPE || code == ERROR_MARK)
803 else if (code == ERROR_MARK)
805 else if (!COMPLETE_TYPE_P (type))
807 error ("__alignof__ applied to an incomplete type");
811 t = size_int (TYPE_ALIGN (type) / BITS_PER_UNIT);
813 return fold (build1 (NOP_EXPR, c_size_type_node, t));
816 /* Implement the __alignof keyword: Return the minimum required
817 alignment of EXPR, measured in bytes. For VAR_DECL's and
818 FIELD_DECL's return DECL_ALIGN (which can be set from an
819 "aligned" __attribute__ specification). */
822 c_alignof_expr (expr)
827 if (TREE_CODE (expr) == VAR_DECL)
828 t = size_int (DECL_ALIGN (expr) / BITS_PER_UNIT);
830 else if (TREE_CODE (expr) == COMPONENT_REF
831 && DECL_C_BIT_FIELD (TREE_OPERAND (expr, 1)))
833 error ("`__alignof' applied to a bit-field");
836 else if (TREE_CODE (expr) == COMPONENT_REF
837 && TREE_CODE (TREE_OPERAND (expr, 1)) == FIELD_DECL)
838 t = size_int (DECL_ALIGN (TREE_OPERAND (expr, 1)) / BITS_PER_UNIT);
840 else if (TREE_CODE (expr) == INDIRECT_REF)
842 tree t = TREE_OPERAND (expr, 0);
844 int bestalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
846 while (TREE_CODE (t) == NOP_EXPR
847 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == POINTER_TYPE)
851 t = TREE_OPERAND (t, 0);
852 thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
853 if (thisalign > bestalign)
854 best = t, bestalign = thisalign;
856 return c_alignof (TREE_TYPE (TREE_TYPE (best)));
859 return c_alignof (TREE_TYPE (expr));
861 return fold (build1 (NOP_EXPR, c_size_type_node, t));
864 /* Return either DECL or its known constant value (if it has one). */
867 decl_constant_value (decl)
870 if (/* Don't change a variable array bound or initial value to a constant
871 in a place where a variable is invalid. */
872 current_function_decl != 0
873 && ! TREE_THIS_VOLATILE (decl)
874 && TREE_READONLY (decl)
875 && DECL_INITIAL (decl) != 0
876 && TREE_CODE (DECL_INITIAL (decl)) != ERROR_MARK
877 /* This is invalid if initial value is not constant.
878 If it has either a function call, a memory reference,
879 or a variable, then re-evaluating it could give different results. */
880 && TREE_CONSTANT (DECL_INITIAL (decl))
881 /* Check for cases where this is sub-optimal, even though valid. */
882 && TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR)
883 return DECL_INITIAL (decl);
887 /* Return either DECL or its known constant value (if it has one), but
888 return DECL if pedantic or DECL has mode BLKmode. This is for
889 bug-compatibility with the old behavior of decl_constant_value
890 (before GCC 3.0); every use of this function is a bug and it should
891 be removed before GCC 3.1. It is not appropriate to use pedantic
892 in a way that affects optimization, and BLKmode is probably not the
893 right test for avoiding misoptimizations either. */
896 decl_constant_value_for_broken_optimization (decl)
899 if (pedantic || DECL_MODE (decl) == BLKmode)
902 return decl_constant_value (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);
921 /* Replace a nonvolatile const static variable with its value unless
922 it is an array, in which case we must be sure that taking the
923 address of the array produces consistent results. */
924 else if (optimize && TREE_CODE (exp) == VAR_DECL && code != ARRAY_TYPE)
926 exp = decl_constant_value_for_broken_optimization (exp);
927 type = TREE_TYPE (exp);
930 /* Strip NON_LVALUE_EXPRs and no-op conversions, since we aren't using as
933 Do not use STRIP_NOPS here! It will remove conversions from pointer
934 to integer and cause infinite recursion. */
935 while (TREE_CODE (exp) == NON_LVALUE_EXPR
936 || (TREE_CODE (exp) == NOP_EXPR
937 && TREE_TYPE (TREE_OPERAND (exp, 0)) == TREE_TYPE (exp)))
938 exp = TREE_OPERAND (exp, 0);
940 /* Normally convert enums to int,
941 but convert wide enums to something wider. */
942 if (code == ENUMERAL_TYPE)
944 type = type_for_size (MAX (TYPE_PRECISION (type),
945 TYPE_PRECISION (integer_type_node)),
947 || (TYPE_PRECISION (type)
948 >= TYPE_PRECISION (integer_type_node)))
949 && TREE_UNSIGNED (type)));
951 return convert (type, exp);
954 if (TREE_CODE (exp) == COMPONENT_REF
955 && DECL_C_BIT_FIELD (TREE_OPERAND (exp, 1))
956 /* If it's thinner than an int, promote it like a
957 C_PROMOTING_INTEGER_TYPE_P, otherwise leave it alone. */
958 && 0 > compare_tree_int (DECL_SIZE (TREE_OPERAND (exp, 1)),
959 TYPE_PRECISION (integer_type_node)))
960 return convert (flag_traditional && TREE_UNSIGNED (type)
961 ? unsigned_type_node : integer_type_node,
964 if (C_PROMOTING_INTEGER_TYPE_P (type))
966 /* Traditionally, unsignedness is preserved in default promotions.
967 Also preserve unsignedness if not really getting any wider. */
968 if (TREE_UNSIGNED (type)
970 || TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)))
971 return convert (unsigned_type_node, exp);
973 return convert (integer_type_node, exp);
976 if (code == BOOLEAN_TYPE)
977 return convert (integer_type_node, exp);
979 if (flag_traditional && !flag_allow_single_precision
980 && TYPE_MAIN_VARIANT (type) == float_type_node)
981 return convert (double_type_node, exp);
983 if (code == VOID_TYPE)
985 error ("void value not ignored as it ought to be");
986 return error_mark_node;
988 if (code == FUNCTION_TYPE)
990 return build_unary_op (ADDR_EXPR, exp, 0);
992 if (code == ARRAY_TYPE)
995 tree restype = TREE_TYPE (type);
1000 if (TREE_CODE_CLASS (TREE_CODE (exp)) == 'r' || DECL_P (exp))
1002 constp = TREE_READONLY (exp);
1003 volatilep = TREE_THIS_VOLATILE (exp);
1006 if (TYPE_QUALS (type) || constp || volatilep)
1008 = c_build_qualified_type (restype,
1010 | (constp * TYPE_QUAL_CONST)
1011 | (volatilep * TYPE_QUAL_VOLATILE));
1013 if (TREE_CODE (exp) == INDIRECT_REF)
1014 return convert (TYPE_POINTER_TO (restype),
1015 TREE_OPERAND (exp, 0));
1017 if (TREE_CODE (exp) == COMPOUND_EXPR)
1019 tree op1 = default_conversion (TREE_OPERAND (exp, 1));
1020 return build (COMPOUND_EXPR, TREE_TYPE (op1),
1021 TREE_OPERAND (exp, 0), op1);
1024 if (! lvalue_p (exp)
1025 && ! (TREE_CODE (exp) == CONSTRUCTOR && TREE_STATIC (exp)))
1027 error ("invalid use of non-lvalue array");
1028 return error_mark_node;
1031 ptrtype = build_pointer_type (restype);
1033 if (TREE_CODE (exp) == VAR_DECL)
1035 /* ??? This is not really quite correct
1036 in that the type of the operand of ADDR_EXPR
1037 is not the target type of the type of the ADDR_EXPR itself.
1038 Question is, can this lossage be avoided? */
1039 adr = build1 (ADDR_EXPR, ptrtype, exp);
1040 if (mark_addressable (exp) == 0)
1041 return error_mark_node;
1042 TREE_CONSTANT (adr) = staticp (exp);
1043 TREE_SIDE_EFFECTS (adr) = 0; /* Default would be, same as EXP. */
1046 /* This way is better for a COMPONENT_REF since it can
1047 simplify the offset for a component. */
1048 adr = build_unary_op (ADDR_EXPR, exp, 1);
1049 return convert (ptrtype, adr);
1054 /* Look up component name in the structure type definition.
1056 If this component name is found indirectly within an anonymous union,
1057 store in *INDIRECT the component which directly contains
1058 that anonymous union. Otherwise, set *INDIRECT to 0. */
1061 lookup_field (type, component, indirect)
1062 tree type, component;
1067 /* If TYPE_LANG_SPECIFIC is set, then it is a sorted array of pointers
1068 to the field elements. Use a binary search on this array to quickly
1069 find the element. Otherwise, do a linear search. TYPE_LANG_SPECIFIC
1070 will always be set for structures which have many elements. */
1072 if (TYPE_LANG_SPECIFIC (type))
1075 tree *field_array = &TYPE_LANG_SPECIFIC (type)->elts[0];
1077 field = TYPE_FIELDS (type);
1079 top = TYPE_LANG_SPECIFIC (type)->len;
1080 while (top - bot > 1)
1082 half = (top - bot + 1) >> 1;
1083 field = field_array[bot+half];
1085 if (DECL_NAME (field) == NULL_TREE)
1087 /* Step through all anon unions in linear fashion. */
1088 while (DECL_NAME (field_array[bot]) == NULL_TREE)
1090 tree anon = 0, junk;
1092 field = field_array[bot++];
1093 if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE
1094 || TREE_CODE (TREE_TYPE (field)) == UNION_TYPE)
1095 anon = lookup_field (TREE_TYPE (field), component, &junk);
1097 if (anon != NULL_TREE)
1104 /* Entire record is only anon unions. */
1108 /* Restart the binary search, with new lower bound. */
1112 if (DECL_NAME (field) == component)
1114 if (DECL_NAME (field) < component)
1120 if (DECL_NAME (field_array[bot]) == component)
1121 field = field_array[bot];
1122 else if (DECL_NAME (field) != component)
1127 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
1129 if (DECL_NAME (field) == NULL_TREE)
1134 if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE
1135 || TREE_CODE (TREE_TYPE (field)) == UNION_TYPE)
1136 anon = lookup_field (TREE_TYPE (field), component, &junk);
1138 if (anon != NULL_TREE)
1145 if (DECL_NAME (field) == component)
1150 *indirect = NULL_TREE;
1154 /* Make an expression to refer to the COMPONENT field of
1155 structure or union value DATUM. COMPONENT is an IDENTIFIER_NODE. */
1158 build_component_ref (datum, component)
1159 tree datum, component;
1161 register tree type = TREE_TYPE (datum);
1162 register enum tree_code code = TREE_CODE (type);
1163 register tree field = NULL;
1166 /* If DATUM is a COMPOUND_EXPR or COND_EXPR, move our reference inside it
1167 unless we are not to support things not strictly ANSI. */
1168 switch (TREE_CODE (datum))
1172 tree value = build_component_ref (TREE_OPERAND (datum, 1), component);
1173 return build (COMPOUND_EXPR, TREE_TYPE (value),
1174 TREE_OPERAND (datum, 0), value);
1177 return build_conditional_expr
1178 (TREE_OPERAND (datum, 0),
1179 build_component_ref (TREE_OPERAND (datum, 1), component),
1180 build_component_ref (TREE_OPERAND (datum, 2), component));
1186 /* See if there is a field or component with name COMPONENT. */
1188 if (code == RECORD_TYPE || code == UNION_TYPE)
1192 if (!COMPLETE_TYPE_P (type))
1194 incomplete_type_error (NULL_TREE, type);
1195 return error_mark_node;
1198 field = lookup_field (type, component, &indirect);
1202 error ("%s has no member named `%s'",
1203 code == RECORD_TYPE ? "structure" : "union",
1204 IDENTIFIER_POINTER (component));
1205 return error_mark_node;
1207 if (TREE_TYPE (field) == error_mark_node)
1208 return error_mark_node;
1210 /* If FIELD was found buried within an anonymous union,
1211 make one COMPONENT_REF to get that anonymous union,
1212 then fall thru to make a second COMPONENT_REF to get FIELD. */
1215 ref = build (COMPONENT_REF, TREE_TYPE (indirect), datum, indirect);
1216 if (TREE_READONLY (datum) || TREE_READONLY (indirect))
1217 TREE_READONLY (ref) = 1;
1218 if (TREE_THIS_VOLATILE (datum) || TREE_THIS_VOLATILE (indirect))
1219 TREE_THIS_VOLATILE (ref) = 1;
1223 ref = build (COMPONENT_REF, TREE_TYPE (field), datum, field);
1225 if (TREE_READONLY (datum) || TREE_READONLY (field))
1226 TREE_READONLY (ref) = 1;
1227 if (TREE_THIS_VOLATILE (datum) || TREE_THIS_VOLATILE (field))
1228 TREE_THIS_VOLATILE (ref) = 1;
1232 else if (code != ERROR_MARK)
1233 error ("request for member `%s' in something not a structure or union",
1234 IDENTIFIER_POINTER (component));
1236 return error_mark_node;
1239 /* Given an expression PTR for a pointer, return an expression
1240 for the value pointed to.
1241 ERRORSTRING is the name of the operator to appear in error messages. */
1244 build_indirect_ref (ptr, errorstring)
1246 const char *errorstring;
1248 register tree pointer = default_conversion (ptr);
1249 register tree type = TREE_TYPE (pointer);
1251 if (TREE_CODE (type) == POINTER_TYPE)
1253 if (TREE_CODE (pointer) == ADDR_EXPR
1255 && (TREE_TYPE (TREE_OPERAND (pointer, 0))
1256 == TREE_TYPE (type)))
1257 return TREE_OPERAND (pointer, 0);
1260 tree t = TREE_TYPE (type);
1261 register tree ref = build1 (INDIRECT_REF,
1262 TYPE_MAIN_VARIANT (t), pointer);
1264 if (!COMPLETE_OR_VOID_TYPE_P (t) && TREE_CODE (t) != ARRAY_TYPE)
1266 error ("dereferencing pointer to incomplete type");
1267 return error_mark_node;
1269 if (VOID_TYPE_P (t) && skip_evaluation == 0)
1270 warning ("dereferencing `void *' pointer");
1272 /* We *must* set TREE_READONLY when dereferencing a pointer to const,
1273 so that we get the proper error message if the result is used
1274 to assign to. Also, &* is supposed to be a no-op.
1275 And ANSI C seems to specify that the type of the result
1276 should be the const type. */
1277 /* A de-reference of a pointer to const is not a const. It is valid
1278 to change it via some other pointer. */
1279 TREE_READONLY (ref) = TYPE_READONLY (t);
1280 TREE_SIDE_EFFECTS (ref)
1281 = TYPE_VOLATILE (t) || TREE_SIDE_EFFECTS (pointer) || flag_volatile;
1282 TREE_THIS_VOLATILE (ref) = TYPE_VOLATILE (t);
1286 else if (TREE_CODE (pointer) != ERROR_MARK)
1287 error ("invalid type argument of `%s'", errorstring);
1288 return error_mark_node;
1291 /* This handles expressions of the form "a[i]", which denotes
1294 This is logically equivalent in C to *(a+i), but we may do it differently.
1295 If A is a variable or a member, we generate a primitive ARRAY_REF.
1296 This avoids forcing the array out of registers, and can work on
1297 arrays that are not lvalues (for example, members of structures returned
1301 build_array_ref (array, index)
1306 error ("subscript missing in array reference");
1307 return error_mark_node;
1310 if (TREE_TYPE (array) == error_mark_node
1311 || TREE_TYPE (index) == error_mark_node)
1312 return error_mark_node;
1314 if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE
1315 && TREE_CODE (array) != INDIRECT_REF)
1319 /* Subscripting with type char is likely to lose
1320 on a machine where chars are signed.
1321 So warn on any machine, but optionally.
1322 Don't warn for unsigned char since that type is safe.
1323 Don't warn for signed char because anyone who uses that
1324 must have done so deliberately. */
1325 if (warn_char_subscripts
1326 && TYPE_MAIN_VARIANT (TREE_TYPE (index)) == char_type_node)
1327 warning ("array subscript has type `char'");
1329 /* Apply default promotions *after* noticing character types. */
1330 index = default_conversion (index);
1332 /* Require integer *after* promotion, for sake of enums. */
1333 if (TREE_CODE (TREE_TYPE (index)) != INTEGER_TYPE)
1335 error ("array subscript is not an integer");
1336 return error_mark_node;
1339 /* An array that is indexed by a non-constant
1340 cannot be stored in a register; we must be able to do
1341 address arithmetic on its address.
1342 Likewise an array of elements of variable size. */
1343 if (TREE_CODE (index) != INTEGER_CST
1344 || (COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (array)))
1345 && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array)))) != INTEGER_CST))
1347 if (mark_addressable (array) == 0)
1348 return error_mark_node;
1350 /* An array that is indexed by a constant value which is not within
1351 the array bounds cannot be stored in a register either; because we
1352 would get a crash in store_bit_field/extract_bit_field when trying
1353 to access a non-existent part of the register. */
1354 if (TREE_CODE (index) == INTEGER_CST
1355 && TYPE_VALUES (TREE_TYPE (array))
1356 && ! int_fits_type_p (index, TYPE_VALUES (TREE_TYPE (array))))
1358 if (mark_addressable (array) == 0)
1359 return error_mark_node;
1365 while (TREE_CODE (foo) == COMPONENT_REF)
1366 foo = TREE_OPERAND (foo, 0);
1367 if (TREE_CODE (foo) == VAR_DECL && DECL_REGISTER (foo))
1368 pedwarn ("ISO C forbids subscripting `register' array");
1369 else if (! flag_isoc99 && ! lvalue_p (foo))
1370 pedwarn ("ISO C89 forbids subscripting non-lvalue array");
1373 type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (array)));
1374 rval = build (ARRAY_REF, type, array, index);
1375 /* Array ref is const/volatile if the array elements are
1376 or if the array is. */
1377 TREE_READONLY (rval)
1378 |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array)))
1379 | TREE_READONLY (array));
1380 TREE_SIDE_EFFECTS (rval)
1381 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
1382 | TREE_SIDE_EFFECTS (array));
1383 TREE_THIS_VOLATILE (rval)
1384 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
1385 /* This was added by rms on 16 Nov 91.
1386 It fixes vol struct foo *a; a->elts[1]
1387 in an inline function.
1388 Hope it doesn't break something else. */
1389 | TREE_THIS_VOLATILE (array));
1390 return require_complete_type (fold (rval));
1394 tree ar = default_conversion (array);
1395 tree ind = default_conversion (index);
1397 /* Do the same warning check as above, but only on the part that's
1398 syntactically the index and only if it is also semantically
1400 if (warn_char_subscripts
1401 && TREE_CODE (TREE_TYPE (index)) == INTEGER_TYPE
1402 && TYPE_MAIN_VARIANT (TREE_TYPE (index)) == char_type_node)
1403 warning ("subscript has type `char'");
1405 /* Put the integer in IND to simplify error checking. */
1406 if (TREE_CODE (TREE_TYPE (ar)) == INTEGER_TYPE)
1413 if (ar == error_mark_node)
1416 if (TREE_CODE (TREE_TYPE (ar)) != POINTER_TYPE
1417 || TREE_CODE (TREE_TYPE (TREE_TYPE (ar))) == FUNCTION_TYPE)
1419 error ("subscripted value is neither array nor pointer");
1420 return error_mark_node;
1422 if (TREE_CODE (TREE_TYPE (ind)) != INTEGER_TYPE)
1424 error ("array subscript is not an integer");
1425 return error_mark_node;
1428 return build_indirect_ref (build_binary_op (PLUS_EXPR, ar, ind, 0),
1433 /* Build an external reference to identifier ID. FUN indicates
1434 whether this will be used for a function call. */
1436 build_external_ref (id, fun)
1441 tree decl = lookup_name (id);
1442 tree objc_ivar = lookup_objc_ivar (id);
1444 if (!decl || decl == error_mark_node || C_DECL_ANTICIPATED (decl))
1450 if (!decl || decl == error_mark_node)
1451 /* Ordinary implicit function declaration. */
1452 ref = implicitly_declare (id);
1455 /* Implicit declaration of built-in function. Don't
1456 change the built-in declaration, but don't let this
1457 go by silently, either. */
1458 implicit_decl_warning (id);
1460 /* only issue this warning once */
1461 C_DECL_ANTICIPATED (decl) = 0;
1467 /* Reference to undeclared variable, including reference to
1468 builtin outside of function-call context. */
1469 if (current_function_decl == 0)
1470 error ("`%s' undeclared here (not in a function)",
1471 IDENTIFIER_POINTER (id));
1474 if (IDENTIFIER_GLOBAL_VALUE (id) != error_mark_node
1475 || IDENTIFIER_ERROR_LOCUS (id) != current_function_decl)
1477 error ("`%s' undeclared (first use in this function)",
1478 IDENTIFIER_POINTER (id));
1480 if (! undeclared_variable_notice)
1482 error ("(Each undeclared identifier is reported only once");
1483 error ("for each function it appears in.)");
1484 undeclared_variable_notice = 1;
1487 IDENTIFIER_GLOBAL_VALUE (id) = error_mark_node;
1488 IDENTIFIER_ERROR_LOCUS (id) = current_function_decl;
1490 return error_mark_node;
1495 /* Properly declared variable or function reference. */
1498 else if (decl != objc_ivar && IDENTIFIER_LOCAL_VALUE (id))
1500 warning ("local declaration of `%s' hides instance variable",
1501 IDENTIFIER_POINTER (id));
1508 if (TREE_TYPE (ref) == error_mark_node)
1509 return error_mark_node;
1511 assemble_external (ref);
1512 TREE_USED (ref) = 1;
1514 if (TREE_CODE (ref) == CONST_DECL)
1516 ref = DECL_INITIAL (ref);
1517 TREE_CONSTANT (ref) = 1;
1523 /* Build a function call to function FUNCTION with parameters PARAMS.
1524 PARAMS is a list--a chain of TREE_LIST nodes--in which the
1525 TREE_VALUE of each node is a parameter-expression.
1526 FUNCTION's data type may be a function type or a pointer-to-function. */
1529 build_function_call (function, params)
1530 tree function, params;
1532 register tree fntype, fundecl = 0;
1533 register tree coerced_params;
1534 tree name = NULL_TREE, assembler_name = NULL_TREE, result;
1536 /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
1537 STRIP_TYPE_NOPS (function);
1539 /* Convert anything with function type to a pointer-to-function. */
1540 if (TREE_CODE (function) == FUNCTION_DECL)
1542 name = DECL_NAME (function);
1543 assembler_name = DECL_ASSEMBLER_NAME (function);
1545 /* Differs from default_conversion by not setting TREE_ADDRESSABLE
1546 (because calling an inline function does not mean the function
1547 needs to be separately compiled). */
1548 fntype = build_type_variant (TREE_TYPE (function),
1549 TREE_READONLY (function),
1550 TREE_THIS_VOLATILE (function));
1552 function = build1 (ADDR_EXPR, build_pointer_type (fntype), function);
1555 function = default_conversion (function);
1557 fntype = TREE_TYPE (function);
1559 if (TREE_CODE (fntype) == ERROR_MARK)
1560 return error_mark_node;
1562 if (!(TREE_CODE (fntype) == POINTER_TYPE
1563 && TREE_CODE (TREE_TYPE (fntype)) == FUNCTION_TYPE))
1565 error ("called object is not a function");
1566 return error_mark_node;
1569 /* fntype now gets the type of function pointed to. */
1570 fntype = TREE_TYPE (fntype);
1572 /* Convert the parameters to the types declared in the
1573 function prototype, or apply default promotions. */
1576 = convert_arguments (TYPE_ARG_TYPES (fntype), params, name, fundecl);
1578 /* Check for errors in format strings. */
1580 if (warn_format && (name || assembler_name))
1581 check_function_format (NULL, name, assembler_name, coerced_params);
1583 /* Recognize certain built-in functions so we can make tree-codes
1584 other than CALL_EXPR. We do this when it enables fold-const.c
1585 to do something useful. */
1587 if (TREE_CODE (function) == ADDR_EXPR
1588 && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL
1589 && DECL_BUILT_IN (TREE_OPERAND (function, 0)))
1591 result = expand_tree_builtin (TREE_OPERAND (function, 0),
1592 params, coerced_params);
1597 result = build (CALL_EXPR, TREE_TYPE (fntype),
1598 function, coerced_params, NULL_TREE);
1599 TREE_SIDE_EFFECTS (result) = 1;
1600 result = fold (result);
1602 if (VOID_TYPE_P (TREE_TYPE (result)))
1604 return require_complete_type (result);
1607 /* Convert the argument expressions in the list VALUES
1608 to the types in the list TYPELIST. The result is a list of converted
1609 argument expressions.
1611 If TYPELIST is exhausted, or when an element has NULL as its type,
1612 perform the default conversions.
1614 PARMLIST is the chain of parm decls for the function being called.
1615 It may be 0, if that info is not available.
1616 It is used only for generating error messages.
1618 NAME is an IDENTIFIER_NODE or 0. It is used only for error messages.
1620 This is also where warnings about wrong number of args are generated.
1622 Both VALUES and the returned value are chains of TREE_LIST nodes
1623 with the elements of the list in the TREE_VALUE slots of those nodes. */
1626 convert_arguments (typelist, values, name, fundecl)
1627 tree typelist, values, name, fundecl;
1629 register tree typetail, valtail;
1630 register tree result = NULL;
1633 /* Scan the given expressions and types, producing individual
1634 converted arguments and pushing them on RESULT in reverse order. */
1636 for (valtail = values, typetail = typelist, parmnum = 0;
1638 valtail = TREE_CHAIN (valtail), parmnum++)
1640 register tree type = typetail ? TREE_VALUE (typetail) : 0;
1641 register tree val = TREE_VALUE (valtail);
1643 if (type == void_type_node)
1646 error ("too many arguments to function `%s'",
1647 IDENTIFIER_POINTER (name));
1649 error ("too many arguments to function");
1653 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
1654 /* Do not use STRIP_NOPS here! We do not want an enumerator with value 0
1655 to convert automatically to a pointer. */
1656 if (TREE_CODE (val) == NON_LVALUE_EXPR)
1657 val = TREE_OPERAND (val, 0);
1659 if (TREE_CODE (TREE_TYPE (val)) == ARRAY_TYPE
1660 || TREE_CODE (TREE_TYPE (val)) == FUNCTION_TYPE)
1661 val = default_conversion (val);
1663 val = require_complete_type (val);
1667 /* Formal parm type is specified by a function prototype. */
1670 if (!COMPLETE_TYPE_P (type))
1672 error ("type of formal parameter %d is incomplete", parmnum + 1);
1677 /* Optionally warn about conversions that
1678 differ from the default conversions. */
1679 if (warn_conversion || warn_traditional)
1681 int formal_prec = TYPE_PRECISION (type);
1683 if (INTEGRAL_TYPE_P (type)
1684 && TREE_CODE (TREE_TYPE (val)) == REAL_TYPE)
1685 warn_for_assignment ("%s as integer rather than floating due to prototype", (char *) 0, name, parmnum + 1);
1686 if (INTEGRAL_TYPE_P (type)
1687 && TREE_CODE (TREE_TYPE (val)) == COMPLEX_TYPE)
1688 warn_for_assignment ("%s as integer rather than complex due to prototype", (char *) 0, name, parmnum + 1);
1689 else if (TREE_CODE (type) == COMPLEX_TYPE
1690 && TREE_CODE (TREE_TYPE (val)) == REAL_TYPE)
1691 warn_for_assignment ("%s as complex rather than floating due to prototype", (char *) 0, name, parmnum + 1);
1692 else if (TREE_CODE (type) == REAL_TYPE
1693 && INTEGRAL_TYPE_P (TREE_TYPE (val)))
1694 warn_for_assignment ("%s as floating rather than integer due to prototype", (char *) 0, name, parmnum + 1);
1695 else if (TREE_CODE (type) == COMPLEX_TYPE
1696 && INTEGRAL_TYPE_P (TREE_TYPE (val)))
1697 warn_for_assignment ("%s as complex rather than integer due to prototype", (char *) 0, name, parmnum + 1);
1698 else if (TREE_CODE (type) == REAL_TYPE
1699 && TREE_CODE (TREE_TYPE (val)) == COMPLEX_TYPE)
1700 warn_for_assignment ("%s as floating rather than complex due to prototype", (char *) 0, name, parmnum + 1);
1701 /* ??? At some point, messages should be written about
1702 conversions between complex types, but that's too messy
1704 else if (TREE_CODE (type) == REAL_TYPE
1705 && TREE_CODE (TREE_TYPE (val)) == REAL_TYPE)
1707 /* Warn if any argument is passed as `float',
1708 since without a prototype it would be `double'. */
1709 if (formal_prec == TYPE_PRECISION (float_type_node))
1710 warn_for_assignment ("%s as `float' rather than `double' due to prototype", (char *) 0, name, parmnum + 1);
1712 /* Detect integer changing in width or signedness.
1713 These warnings are only activated with
1714 -Wconversion, not with -Wtraditional. */
1715 else if (warn_conversion && INTEGRAL_TYPE_P (type)
1716 && INTEGRAL_TYPE_P (TREE_TYPE (val)))
1718 tree would_have_been = default_conversion (val);
1719 tree type1 = TREE_TYPE (would_have_been);
1721 if (TREE_CODE (type) == ENUMERAL_TYPE
1722 && type == TREE_TYPE (val))
1723 /* No warning if function asks for enum
1724 and the actual arg is that enum type. */
1726 else if (formal_prec != TYPE_PRECISION (type1))
1727 warn_for_assignment ("%s with different width due to prototype", (char *) 0, name, parmnum + 1);
1728 else if (TREE_UNSIGNED (type) == TREE_UNSIGNED (type1))
1730 /* Don't complain if the formal parameter type
1731 is an enum, because we can't tell now whether
1732 the value was an enum--even the same enum. */
1733 else if (TREE_CODE (type) == ENUMERAL_TYPE)
1735 else if (TREE_CODE (val) == INTEGER_CST
1736 && int_fits_type_p (val, type))
1737 /* Change in signedness doesn't matter
1738 if a constant value is unaffected. */
1740 /* Likewise for a constant in a NOP_EXPR. */
1741 else if (TREE_CODE (val) == NOP_EXPR
1742 && TREE_CODE (TREE_OPERAND (val, 0)) == INTEGER_CST
1743 && int_fits_type_p (TREE_OPERAND (val, 0), type))
1745 #if 0 /* We never get such tree structure here. */
1746 else if (TREE_CODE (TREE_TYPE (val)) == ENUMERAL_TYPE
1747 && int_fits_type_p (TYPE_MIN_VALUE (TREE_TYPE (val)), type)
1748 && int_fits_type_p (TYPE_MAX_VALUE (TREE_TYPE (val)), type))
1749 /* Change in signedness doesn't matter
1750 if an enum value is unaffected. */
1753 /* If the value is extended from a narrower
1754 unsigned type, it doesn't matter whether we
1755 pass it as signed or unsigned; the value
1756 certainly is the same either way. */
1757 else if (TYPE_PRECISION (TREE_TYPE (val)) < TYPE_PRECISION (type)
1758 && TREE_UNSIGNED (TREE_TYPE (val)))
1760 else if (TREE_UNSIGNED (type))
1761 warn_for_assignment ("%s as unsigned due to prototype", (char *) 0, name, parmnum + 1);
1763 warn_for_assignment ("%s as signed due to prototype", (char *) 0, name, parmnum + 1);
1767 parmval = convert_for_assignment (type, val,
1768 (char *) 0, /* arg passing */
1769 fundecl, name, parmnum + 1);
1771 if (PROMOTE_PROTOTYPES
1772 && (TREE_CODE (type) == INTEGER_TYPE
1773 || TREE_CODE (type) == ENUMERAL_TYPE
1774 || TREE_CODE (type) == BOOLEAN_TYPE)
1775 && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
1776 parmval = default_conversion (parmval);
1778 result = tree_cons (NULL_TREE, parmval, result);
1780 else if (TREE_CODE (TREE_TYPE (val)) == REAL_TYPE
1781 && (TYPE_PRECISION (TREE_TYPE (val))
1782 < TYPE_PRECISION (double_type_node)))
1783 /* Convert `float' to `double'. */
1784 result = tree_cons (NULL_TREE, convert (double_type_node, val), result);
1786 /* Convert `short' and `char' to full-size `int'. */
1787 result = tree_cons (NULL_TREE, default_conversion (val), result);
1790 typetail = TREE_CHAIN (typetail);
1793 if (typetail != 0 && TREE_VALUE (typetail) != void_type_node)
1796 error ("too few arguments to function `%s'",
1797 IDENTIFIER_POINTER (name));
1799 error ("too few arguments to function");
1802 return nreverse (result);
1805 /* This is the entry point used by the parser
1806 for binary operators in the input.
1807 In addition to constructing the expression,
1808 we check for operands that were written with other binary operators
1809 in a way that is likely to confuse the user. */
1812 parser_build_binary_op (code, arg1, arg2)
1813 enum tree_code code;
1816 tree result = build_binary_op (code, arg1, arg2, 1);
1819 char class1 = TREE_CODE_CLASS (TREE_CODE (arg1));
1820 char class2 = TREE_CODE_CLASS (TREE_CODE (arg2));
1821 enum tree_code code1 = ERROR_MARK;
1822 enum tree_code code2 = ERROR_MARK;
1824 if (class1 == 'e' || class1 == '1'
1825 || class1 == '2' || class1 == '<')
1826 code1 = C_EXP_ORIGINAL_CODE (arg1);
1827 if (class2 == 'e' || class2 == '1'
1828 || class2 == '2' || class2 == '<')
1829 code2 = C_EXP_ORIGINAL_CODE (arg2);
1831 /* Check for cases such as x+y<<z which users are likely
1832 to misinterpret. If parens are used, C_EXP_ORIGINAL_CODE
1833 is cleared to prevent these warnings. */
1834 if (warn_parentheses)
1836 if (code == LSHIFT_EXPR || code == RSHIFT_EXPR)
1838 if (code1 == PLUS_EXPR || code1 == MINUS_EXPR
1839 || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
1840 warning ("suggest parentheses around + or - inside shift");
1843 if (code == TRUTH_ORIF_EXPR)
1845 if (code1 == TRUTH_ANDIF_EXPR
1846 || code2 == TRUTH_ANDIF_EXPR)
1847 warning ("suggest parentheses around && within ||");
1850 if (code == BIT_IOR_EXPR)
1852 if (code1 == BIT_AND_EXPR || code1 == BIT_XOR_EXPR
1853 || code1 == PLUS_EXPR || code1 == MINUS_EXPR
1854 || code2 == BIT_AND_EXPR || code2 == BIT_XOR_EXPR
1855 || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
1856 warning ("suggest parentheses around arithmetic in operand of |");
1857 /* Check cases like x|y==z */
1858 if (TREE_CODE_CLASS (code1) == '<' || TREE_CODE_CLASS (code2) == '<')
1859 warning ("suggest parentheses around comparison in operand of |");
1862 if (code == BIT_XOR_EXPR)
1864 if (code1 == BIT_AND_EXPR
1865 || code1 == PLUS_EXPR || code1 == MINUS_EXPR
1866 || code2 == BIT_AND_EXPR
1867 || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
1868 warning ("suggest parentheses around arithmetic in operand of ^");
1869 /* Check cases like x^y==z */
1870 if (TREE_CODE_CLASS (code1) == '<' || TREE_CODE_CLASS (code2) == '<')
1871 warning ("suggest parentheses around comparison in operand of ^");
1874 if (code == BIT_AND_EXPR)
1876 if (code1 == PLUS_EXPR || code1 == MINUS_EXPR
1877 || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
1878 warning ("suggest parentheses around + or - in operand of &");
1879 /* Check cases like x&y==z */
1880 if (TREE_CODE_CLASS (code1) == '<' || TREE_CODE_CLASS (code2) == '<')
1881 warning ("suggest parentheses around comparison in operand of &");
1885 /* Similarly, check for cases like 1<=i<=10 that are probably errors. */
1886 if (TREE_CODE_CLASS (code) == '<' && extra_warnings
1887 && (TREE_CODE_CLASS (code1) == '<' || TREE_CODE_CLASS (code2) == '<'))
1888 warning ("comparisons like X<=Y<=Z do not have their mathematical meaning");
1890 unsigned_conversion_warning (result, arg1);
1891 unsigned_conversion_warning (result, arg2);
1892 overflow_warning (result);
1894 class = TREE_CODE_CLASS (TREE_CODE (result));
1896 /* Record the code that was specified in the source,
1897 for the sake of warnings about confusing nesting. */
1898 if (class == 'e' || class == '1'
1899 || class == '2' || class == '<')
1900 C_SET_EXP_ORIGINAL_CODE (result, code);
1903 int flag = TREE_CONSTANT (result);
1904 /* We used to use NOP_EXPR rather than NON_LVALUE_EXPR
1905 so that convert_for_assignment wouldn't strip it.
1906 That way, we got warnings for things like p = (1 - 1).
1907 But it turns out we should not get those warnings. */
1908 result = build1 (NON_LVALUE_EXPR, TREE_TYPE (result), result);
1909 C_SET_EXP_ORIGINAL_CODE (result, code);
1910 TREE_CONSTANT (result) = flag;
1916 /* Build a binary-operation expression without default conversions.
1917 CODE is the kind of expression to build.
1918 This function differs from `build' in several ways:
1919 the data type of the result is computed and recorded in it,
1920 warnings are generated if arg data types are invalid,
1921 special handling for addition and subtraction of pointers is known,
1922 and some optimization is done (operations on narrow ints
1923 are done in the narrower type when that gives the same result).
1924 Constant folding is also done before the result is returned.
1926 Note that the operands will never have enumeral types, or function
1927 or array types, because either they will have the default conversions
1928 performed or they have both just been converted to some other type in which
1929 the arithmetic is to be done. */
1932 build_binary_op (code, orig_op0, orig_op1, convert_p)
1933 enum tree_code code;
1934 tree orig_op0, orig_op1;
1938 register enum tree_code code0, code1;
1941 /* Expression code to give to the expression when it is built.
1942 Normally this is CODE, which is what the caller asked for,
1943 but in some special cases we change it. */
1944 register enum tree_code resultcode = code;
1946 /* Data type in which the computation is to be performed.
1947 In the simplest cases this is the common type of the arguments. */
1948 register tree result_type = NULL;
1950 /* Nonzero means operands have already been type-converted
1951 in whatever way is necessary.
1952 Zero means they need to be converted to RESULT_TYPE. */
1955 /* Nonzero means create the expression with this type, rather than
1957 tree build_type = 0;
1959 /* Nonzero means after finally constructing the expression
1960 convert it to this type. */
1961 tree final_type = 0;
1963 /* Nonzero if this is an operation like MIN or MAX which can
1964 safely be computed in short if both args are promoted shorts.
1965 Also implies COMMON.
1966 -1 indicates a bitwise operation; this makes a difference
1967 in the exact conditions for when it is safe to do the operation
1968 in a narrower mode. */
1971 /* Nonzero if this is a comparison operation;
1972 if both args are promoted shorts, compare the original shorts.
1973 Also implies COMMON. */
1974 int short_compare = 0;
1976 /* Nonzero if this is a right-shift operation, which can be computed on the
1977 original short and then promoted if the operand is a promoted short. */
1978 int short_shift = 0;
1980 /* Nonzero means set RESULT_TYPE to the common type of the args. */
1985 op0 = default_conversion (orig_op0);
1986 op1 = default_conversion (orig_op1);
1994 type0 = TREE_TYPE (op0);
1995 type1 = TREE_TYPE (op1);
1997 /* The expression codes of the data types of the arguments tell us
1998 whether the arguments are integers, floating, pointers, etc. */
1999 code0 = TREE_CODE (type0);
2000 code1 = TREE_CODE (type1);
2002 /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
2003 STRIP_TYPE_NOPS (op0);
2004 STRIP_TYPE_NOPS (op1);
2006 /* If an error was already reported for one of the arguments,
2007 avoid reporting another error. */
2009 if (code0 == ERROR_MARK || code1 == ERROR_MARK)
2010 return error_mark_node;
2015 /* Handle the pointer + int case. */
2016 if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
2017 return pointer_int_sum (PLUS_EXPR, op0, op1);
2018 else if (code1 == POINTER_TYPE && code0 == INTEGER_TYPE)
2019 return pointer_int_sum (PLUS_EXPR, op1, op0);
2025 /* Subtraction of two similar pointers.
2026 We must subtract them as integers, then divide by object size. */
2027 if (code0 == POINTER_TYPE && code1 == POINTER_TYPE
2028 && comp_target_types (type0, type1))
2029 return pointer_diff (op0, op1);
2030 /* Handle pointer minus int. Just like pointer plus int. */
2031 else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
2032 return pointer_int_sum (MINUS_EXPR, op0, op1);
2041 case TRUNC_DIV_EXPR:
2043 case FLOOR_DIV_EXPR:
2044 case ROUND_DIV_EXPR:
2045 case EXACT_DIV_EXPR:
2046 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
2047 || code0 == COMPLEX_TYPE)
2048 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
2049 || code1 == COMPLEX_TYPE))
2051 if (!(code0 == INTEGER_TYPE && code1 == INTEGER_TYPE))
2052 resultcode = RDIV_EXPR;
2054 /* Although it would be tempting to shorten always here, that
2055 loses on some targets, since the modulo instruction is
2056 undefined if the quotient can't be represented in the
2057 computation mode. We shorten only if unsigned or if
2058 dividing by something we know != -1. */
2059 shorten = (TREE_UNSIGNED (TREE_TYPE (orig_op0))
2060 || (TREE_CODE (op1) == INTEGER_CST
2061 && ! integer_all_onesp (op1)));
2067 case BIT_ANDTC_EXPR:
2070 if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
2072 /* If one operand is a constant, and the other is a short type
2073 that has been converted to an int,
2074 really do the work in the short type and then convert the
2075 result to int. If we are lucky, the constant will be 0 or 1
2076 in the short type, making the entire operation go away. */
2077 if (TREE_CODE (op0) == INTEGER_CST
2078 && TREE_CODE (op1) == NOP_EXPR
2079 && TYPE_PRECISION (type1) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op1, 0)))
2080 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op1, 0))))
2082 final_type = result_type;
2083 op1 = TREE_OPERAND (op1, 0);
2084 result_type = TREE_TYPE (op1);
2086 if (TREE_CODE (op1) == INTEGER_CST
2087 && TREE_CODE (op0) == NOP_EXPR
2088 && TYPE_PRECISION (type0) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0, 0)))
2089 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0, 0))))
2091 final_type = result_type;
2092 op0 = TREE_OPERAND (op0, 0);
2093 result_type = TREE_TYPE (op0);
2097 case TRUNC_MOD_EXPR:
2098 case FLOOR_MOD_EXPR:
2099 if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
2101 /* Although it would be tempting to shorten always here, that loses
2102 on some targets, since the modulo instruction is undefined if the
2103 quotient can't be represented in the computation mode. We shorten
2104 only if unsigned or if dividing by something we know != -1. */
2105 shorten = (TREE_UNSIGNED (TREE_TYPE (orig_op0))
2106 || (TREE_CODE (op1) == INTEGER_CST
2107 && ! integer_all_onesp (op1)));
2112 case TRUTH_ANDIF_EXPR:
2113 case TRUTH_ORIF_EXPR:
2114 case TRUTH_AND_EXPR:
2116 case TRUTH_XOR_EXPR:
2117 if ((code0 == INTEGER_TYPE || code0 == POINTER_TYPE
2118 || code0 == REAL_TYPE || code0 == COMPLEX_TYPE)
2119 && (code1 == INTEGER_TYPE || code1 == POINTER_TYPE
2120 || code1 == REAL_TYPE || code1 == COMPLEX_TYPE))
2122 /* Result of these operations is always an int,
2123 but that does not mean the operands should be
2124 converted to ints! */
2125 result_type = integer_type_node;
2126 op0 = truthvalue_conversion (op0);
2127 op1 = truthvalue_conversion (op1);
2132 /* Shift operations: result has same type as first operand;
2133 always convert second operand to int.
2134 Also set SHORT_SHIFT if shifting rightward. */
2137 if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
2139 if (TREE_CODE (op1) == INTEGER_CST && skip_evaluation == 0)
2141 if (tree_int_cst_sgn (op1) < 0)
2142 warning ("right shift count is negative");
2145 if (! integer_zerop (op1))
2148 if (compare_tree_int (op1, TYPE_PRECISION (type0)) >= 0)
2149 warning ("right shift count >= width of type");
2153 /* Use the type of the value to be shifted.
2154 This is what most traditional C compilers do. */
2155 result_type = type0;
2156 /* Unless traditional, convert the shift-count to an integer,
2157 regardless of size of value being shifted. */
2158 if (! flag_traditional)
2160 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
2161 op1 = convert (integer_type_node, op1);
2162 /* Avoid converting op1 to result_type later. */
2169 if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
2171 if (TREE_CODE (op1) == INTEGER_CST && skip_evaluation == 0)
2173 if (tree_int_cst_sgn (op1) < 0)
2174 warning ("left shift count is negative");
2176 else if (compare_tree_int (op1, TYPE_PRECISION (type0)) >= 0)
2177 warning ("left shift count >= width of type");
2180 /* Use the type of the value to be shifted.
2181 This is what most traditional C compilers do. */
2182 result_type = type0;
2183 /* Unless traditional, convert the shift-count to an integer,
2184 regardless of size of value being shifted. */
2185 if (! flag_traditional)
2187 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
2188 op1 = convert (integer_type_node, op1);
2189 /* Avoid converting op1 to result_type later. */
2197 if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
2199 if (TREE_CODE (op1) == INTEGER_CST && skip_evaluation == 0)
2201 if (tree_int_cst_sgn (op1) < 0)
2202 warning ("shift count is negative");
2203 else if (compare_tree_int (op1, TYPE_PRECISION (type0)) >= 0)
2204 warning ("shift count >= width of type");
2207 /* Use the type of the value to be shifted.
2208 This is what most traditional C compilers do. */
2209 result_type = type0;
2210 /* Unless traditional, convert the shift-count to an integer,
2211 regardless of size of value being shifted. */
2212 if (! flag_traditional)
2214 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
2215 op1 = convert (integer_type_node, op1);
2216 /* Avoid converting op1 to result_type later. */
2224 if (warn_float_equal && (code0 == REAL_TYPE || code1 == REAL_TYPE))
2225 warning ("comparing floating point with == or != is unsafe");
2226 /* Result of comparison is always int,
2227 but don't convert the args to int! */
2228 build_type = integer_type_node;
2229 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
2230 || code0 == COMPLEX_TYPE)
2231 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
2232 || code1 == COMPLEX_TYPE))
2234 else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
2236 register tree tt0 = TREE_TYPE (type0);
2237 register tree tt1 = TREE_TYPE (type1);
2238 /* Anything compares with void *. void * compares with anything.
2239 Otherwise, the targets must be compatible
2240 and both must be object or both incomplete. */
2241 if (comp_target_types (type0, type1))
2242 result_type = common_type (type0, type1);
2243 else if (VOID_TYPE_P (tt0))
2245 /* op0 != orig_op0 detects the case of something
2246 whose value is 0 but which isn't a valid null ptr const. */
2247 if (pedantic && (!integer_zerop (op0) || op0 != orig_op0)
2248 && TREE_CODE (tt1) == FUNCTION_TYPE)
2249 pedwarn ("ISO C forbids comparison of `void *' with function pointer");
2251 else if (VOID_TYPE_P (tt1))
2253 if (pedantic && (!integer_zerop (op1) || op1 != orig_op1)
2254 && TREE_CODE (tt0) == FUNCTION_TYPE)
2255 pedwarn ("ISO C forbids comparison of `void *' with function pointer");
2258 pedwarn ("comparison of distinct pointer types lacks a cast");
2260 if (result_type == NULL_TREE)
2261 result_type = ptr_type_node;
2263 else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST
2264 && integer_zerop (op1))
2265 result_type = type0;
2266 else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST
2267 && integer_zerop (op0))
2268 result_type = type1;
2269 else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
2271 result_type = type0;
2272 if (! flag_traditional)
2273 pedwarn ("comparison between pointer and integer");
2275 else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
2277 result_type = type1;
2278 if (! flag_traditional)
2279 pedwarn ("comparison between pointer and integer");
2285 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
2286 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
2288 else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
2290 if (comp_target_types (type0, type1))
2292 result_type = common_type (type0, type1);
2294 && TREE_CODE (TREE_TYPE (type0)) == FUNCTION_TYPE)
2295 pedwarn ("ISO C forbids ordered comparisons of pointers to functions");
2299 result_type = ptr_type_node;
2300 pedwarn ("comparison of distinct pointer types lacks a cast");
2309 build_type = integer_type_node;
2310 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
2311 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
2313 else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
2315 if (comp_target_types (type0, type1))
2317 result_type = common_type (type0, type1);
2318 if (!COMPLETE_TYPE_P (TREE_TYPE (type0))
2319 != !COMPLETE_TYPE_P (TREE_TYPE (type1)))
2320 pedwarn ("comparison of complete and incomplete pointers");
2322 && TREE_CODE (TREE_TYPE (type0)) == FUNCTION_TYPE)
2323 pedwarn ("ISO C forbids ordered comparisons of pointers to functions");
2327 result_type = ptr_type_node;
2328 pedwarn ("comparison of distinct pointer types lacks a cast");
2331 else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST
2332 && integer_zerop (op1))
2334 result_type = type0;
2335 if (pedantic || extra_warnings)
2336 pedwarn ("ordered comparison of pointer with integer zero");
2338 else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST
2339 && integer_zerop (op0))
2341 result_type = type1;
2343 pedwarn ("ordered comparison of pointer with integer zero");
2345 else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
2347 result_type = type0;
2348 if (! flag_traditional)
2349 pedwarn ("comparison between pointer and integer");
2351 else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
2353 result_type = type1;
2354 if (! flag_traditional)
2355 pedwarn ("comparison between pointer and integer");
2359 case UNORDERED_EXPR:
2366 build_type = integer_type_node;
2367 if (code0 != REAL_TYPE || code1 != REAL_TYPE)
2369 error ("unordered comparison on non-floating point argument");
2370 return error_mark_node;
2379 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == COMPLEX_TYPE)
2381 (code1 == INTEGER_TYPE || code1 == REAL_TYPE || code1 == COMPLEX_TYPE))
2383 int none_complex = (code0 != COMPLEX_TYPE && code1 != COMPLEX_TYPE);
2385 if (shorten || common || short_compare)
2386 result_type = common_type (type0, type1);
2388 /* For certain operations (which identify themselves by shorten != 0)
2389 if both args were extended from the same smaller type,
2390 do the arithmetic in that type and then extend.
2392 shorten !=0 and !=1 indicates a bitwise operation.
2393 For them, this optimization is safe only if
2394 both args are zero-extended or both are sign-extended.
2395 Otherwise, we might change the result.
2396 Eg, (short)-1 | (unsigned short)-1 is (int)-1
2397 but calculated in (unsigned short) it would be (unsigned short)-1. */
2399 if (shorten && none_complex)
2401 int unsigned0, unsigned1;
2402 tree arg0 = get_narrower (op0, &unsigned0);
2403 tree arg1 = get_narrower (op1, &unsigned1);
2404 /* UNS is 1 if the operation to be done is an unsigned one. */
2405 int uns = TREE_UNSIGNED (result_type);
2408 final_type = result_type;
2410 /* Handle the case that OP0 (or OP1) does not *contain* a conversion
2411 but it *requires* conversion to FINAL_TYPE. */
2413 if ((TYPE_PRECISION (TREE_TYPE (op0))
2414 == TYPE_PRECISION (TREE_TYPE (arg0)))
2415 && TREE_TYPE (op0) != final_type)
2416 unsigned0 = TREE_UNSIGNED (TREE_TYPE (op0));
2417 if ((TYPE_PRECISION (TREE_TYPE (op1))
2418 == TYPE_PRECISION (TREE_TYPE (arg1)))
2419 && TREE_TYPE (op1) != final_type)
2420 unsigned1 = TREE_UNSIGNED (TREE_TYPE (op1));
2422 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
2424 /* For bitwise operations, signedness of nominal type
2425 does not matter. Consider only how operands were extended. */
2429 /* Note that in all three cases below we refrain from optimizing
2430 an unsigned operation on sign-extended args.
2431 That would not be valid. */
2433 /* Both args variable: if both extended in same way
2434 from same width, do it in that width.
2435 Do it unsigned if args were zero-extended. */
2436 if ((TYPE_PRECISION (TREE_TYPE (arg0))
2437 < TYPE_PRECISION (result_type))
2438 && (TYPE_PRECISION (TREE_TYPE (arg1))
2439 == TYPE_PRECISION (TREE_TYPE (arg0)))
2440 && unsigned0 == unsigned1
2441 && (unsigned0 || !uns))
2443 = signed_or_unsigned_type (unsigned0,
2444 common_type (TREE_TYPE (arg0), TREE_TYPE (arg1)));
2445 else if (TREE_CODE (arg0) == INTEGER_CST
2446 && (unsigned1 || !uns)
2447 && (TYPE_PRECISION (TREE_TYPE (arg1))
2448 < TYPE_PRECISION (result_type))
2449 && (type = signed_or_unsigned_type (unsigned1,
2451 int_fits_type_p (arg0, type)))
2453 else if (TREE_CODE (arg1) == INTEGER_CST
2454 && (unsigned0 || !uns)
2455 && (TYPE_PRECISION (TREE_TYPE (arg0))
2456 < TYPE_PRECISION (result_type))
2457 && (type = signed_or_unsigned_type (unsigned0,
2459 int_fits_type_p (arg1, type)))
2463 /* Shifts can be shortened if shifting right. */
2468 tree arg0 = get_narrower (op0, &unsigned_arg);
2470 final_type = result_type;
2472 if (arg0 == op0 && final_type == TREE_TYPE (op0))
2473 unsigned_arg = TREE_UNSIGNED (TREE_TYPE (op0));
2475 if (TYPE_PRECISION (TREE_TYPE (arg0)) < TYPE_PRECISION (result_type)
2476 /* We can shorten only if the shift count is less than the
2477 number of bits in the smaller type size. */
2478 && compare_tree_int (op1, TYPE_PRECISION (TREE_TYPE (arg0))) < 0
2479 /* If arg is sign-extended and then unsigned-shifted,
2480 we can simulate this with a signed shift in arg's type
2481 only if the extended result is at least twice as wide
2482 as the arg. Otherwise, the shift could use up all the
2483 ones made by sign-extension and bring in zeros.
2484 We can't optimize that case at all, but in most machines
2485 it never happens because available widths are 2**N. */
2486 && (!TREE_UNSIGNED (final_type)
2488 || (2 * TYPE_PRECISION (TREE_TYPE (arg0))
2489 <= TYPE_PRECISION (result_type))))
2491 /* Do an unsigned shift if the operand was zero-extended. */
2493 = signed_or_unsigned_type (unsigned_arg,
2495 /* Convert value-to-be-shifted to that type. */
2496 if (TREE_TYPE (op0) != result_type)
2497 op0 = convert (result_type, op0);
2502 /* Comparison operations are shortened too but differently.
2503 They identify themselves by setting short_compare = 1. */
2507 /* Don't write &op0, etc., because that would prevent op0
2508 from being kept in a register.
2509 Instead, make copies of the our local variables and
2510 pass the copies by reference, then copy them back afterward. */
2511 tree xop0 = op0, xop1 = op1, xresult_type = result_type;
2512 enum tree_code xresultcode = resultcode;
2514 = shorten_compare (&xop0, &xop1, &xresult_type, &xresultcode);
2519 op0 = xop0, op1 = xop1;
2521 resultcode = xresultcode;
2523 if ((warn_sign_compare < 0 ? extra_warnings : warn_sign_compare != 0)
2524 && skip_evaluation == 0)
2526 int op0_signed = ! TREE_UNSIGNED (TREE_TYPE (orig_op0));
2527 int op1_signed = ! TREE_UNSIGNED (TREE_TYPE (orig_op1));
2528 int unsignedp0, unsignedp1;
2529 tree primop0 = get_narrower (op0, &unsignedp0);
2530 tree primop1 = get_narrower (op1, &unsignedp1);
2534 STRIP_TYPE_NOPS (xop0);
2535 STRIP_TYPE_NOPS (xop1);
2537 /* Give warnings for comparisons between signed and unsigned
2538 quantities that may fail.
2540 Do the checking based on the original operand trees, so that
2541 casts will be considered, but default promotions won't be.
2543 Do not warn if the comparison is being done in a signed type,
2544 since the signed type will only be chosen if it can represent
2545 all the values of the unsigned type. */
2546 if (! TREE_UNSIGNED (result_type))
2548 /* Do not warn if both operands are the same signedness. */
2549 else if (op0_signed == op1_signed)
2556 sop = xop0, uop = xop1;
2558 sop = xop1, uop = xop0;
2560 /* Do not warn if the signed quantity is an
2561 unsuffixed integer literal (or some static
2562 constant expression involving such literals or a
2563 conditional expression involving such literals)
2564 and it is non-negative. */
2565 if (tree_expr_nonnegative_p (sop))
2567 /* Do not warn if the comparison is an equality operation,
2568 the unsigned quantity is an integral constant, and it
2569 would fit in the result if the result were signed. */
2570 else if (TREE_CODE (uop) == INTEGER_CST
2571 && (resultcode == EQ_EXPR || resultcode == NE_EXPR)
2572 && int_fits_type_p (uop, signed_type (result_type)))
2574 /* Do not warn if the unsigned quantity is an enumeration
2575 constant and its maximum value would fit in the result
2576 if the result were signed. */
2577 else if (TREE_CODE (uop) == INTEGER_CST
2578 && TREE_CODE (TREE_TYPE (uop)) == ENUMERAL_TYPE
2579 && int_fits_type_p (TYPE_MAX_VALUE (TREE_TYPE(uop)),
2580 signed_type (result_type)))
2583 warning ("comparison between signed and unsigned");
2586 /* Warn if two unsigned values are being compared in a size
2587 larger than their original size, and one (and only one) is the
2588 result of a `~' operator. This comparison will always fail.
2590 Also warn if one operand is a constant, and the constant
2591 does not have all bits set that are set in the ~ operand
2592 when it is extended. */
2594 if ((TREE_CODE (primop0) == BIT_NOT_EXPR)
2595 != (TREE_CODE (primop1) == BIT_NOT_EXPR))
2597 if (TREE_CODE (primop0) == BIT_NOT_EXPR)
2598 primop0 = get_narrower (TREE_OPERAND (primop0, 0),
2601 primop1 = get_narrower (TREE_OPERAND (primop1, 0),
2604 if (host_integerp (primop0, 0) || host_integerp (primop1, 0))
2607 HOST_WIDE_INT constant, mask;
2608 int unsignedp, bits;
2610 if (host_integerp (primop0, 0))
2613 unsignedp = unsignedp1;
2614 constant = tree_low_cst (primop0, 0);
2619 unsignedp = unsignedp0;
2620 constant = tree_low_cst (primop1, 0);
2623 bits = TYPE_PRECISION (TREE_TYPE (primop));
2624 if (bits < TYPE_PRECISION (result_type)
2625 && bits < HOST_BITS_PER_WIDE_INT && unsignedp)
2627 mask = (~ (HOST_WIDE_INT) 0) << bits;
2628 if ((mask & constant) != mask)
2629 warning ("comparison of promoted ~unsigned with constant");
2632 else if (unsignedp0 && unsignedp1
2633 && (TYPE_PRECISION (TREE_TYPE (primop0))
2634 < TYPE_PRECISION (result_type))
2635 && (TYPE_PRECISION (TREE_TYPE (primop1))
2636 < TYPE_PRECISION (result_type)))
2637 warning ("comparison of promoted ~unsigned with unsigned");
2643 /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
2644 If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
2645 Then the expression will be built.
2646 It will be given type FINAL_TYPE if that is nonzero;
2647 otherwise, it will be given type RESULT_TYPE. */
2651 binary_op_error (code);
2652 return error_mark_node;
2657 if (TREE_TYPE (op0) != result_type)
2658 op0 = convert (result_type, op0);
2659 if (TREE_TYPE (op1) != result_type)
2660 op1 = convert (result_type, op1);
2663 if (build_type == NULL_TREE)
2664 build_type = result_type;
2667 register tree result = build (resultcode, build_type, op0, op1);
2668 register tree folded;
2670 folded = fold (result);
2671 if (folded == result)
2672 TREE_CONSTANT (folded) = TREE_CONSTANT (op0) & TREE_CONSTANT (op1);
2673 if (final_type != 0)
2674 return convert (final_type, folded);
2679 /* Return a tree for the sum or difference (RESULTCODE says which)
2680 of pointer PTROP and integer INTOP. */
2683 pointer_int_sum (resultcode, ptrop, intop)
2684 enum tree_code resultcode;
2685 register tree ptrop, intop;
2689 register tree result;
2690 register tree folded;
2692 /* The result is a pointer of the same type that is being added. */
2694 register tree result_type = TREE_TYPE (ptrop);
2696 if (TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE)
2698 if (pedantic || warn_pointer_arith)
2699 pedwarn ("pointer of type `void *' used in arithmetic");
2700 size_exp = integer_one_node;
2702 else if (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE)
2704 if (pedantic || warn_pointer_arith)
2705 pedwarn ("pointer to a function used in arithmetic");
2706 size_exp = integer_one_node;
2709 size_exp = c_size_in_bytes (TREE_TYPE (result_type));
2711 /* If what we are about to multiply by the size of the elements
2712 contains a constant term, apply distributive law
2713 and multiply that constant term separately.
2714 This helps produce common subexpressions. */
2716 if ((TREE_CODE (intop) == PLUS_EXPR || TREE_CODE (intop) == MINUS_EXPR)
2717 && ! TREE_CONSTANT (intop)
2718 && TREE_CONSTANT (TREE_OPERAND (intop, 1))
2719 && TREE_CONSTANT (size_exp)
2720 /* If the constant comes from pointer subtraction,
2721 skip this optimization--it would cause an error. */
2722 && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop, 0))) == INTEGER_TYPE
2723 /* If the constant is unsigned, and smaller than the pointer size,
2724 then we must skip this optimization. This is because it could cause
2725 an overflow error if the constant is negative but INTOP is not. */
2726 && (! TREE_UNSIGNED (TREE_TYPE (intop))
2727 || (TYPE_PRECISION (TREE_TYPE (intop))
2728 == TYPE_PRECISION (TREE_TYPE (ptrop)))))
2730 enum tree_code subcode = resultcode;
2731 tree int_type = TREE_TYPE (intop);
2732 if (TREE_CODE (intop) == MINUS_EXPR)
2733 subcode = (subcode == PLUS_EXPR ? MINUS_EXPR : PLUS_EXPR);
2734 /* Convert both subexpression types to the type of intop,
2735 because weird cases involving pointer arithmetic
2736 can result in a sum or difference with different type args. */
2737 ptrop = build_binary_op (subcode, ptrop,
2738 convert (int_type, TREE_OPERAND (intop, 1)), 1);
2739 intop = convert (int_type, TREE_OPERAND (intop, 0));
2742 /* Convert the integer argument to a type the same size as sizetype
2743 so the multiply won't overflow spuriously. */
2745 if (TYPE_PRECISION (TREE_TYPE (intop)) != TYPE_PRECISION (sizetype)
2746 || TREE_UNSIGNED (TREE_TYPE (intop)) != TREE_UNSIGNED (sizetype))
2747 intop = convert (type_for_size (TYPE_PRECISION (sizetype),
2748 TREE_UNSIGNED (sizetype)), intop);
2750 /* Replace the integer argument with a suitable product by the object size.
2751 Do this multiplication as signed, then convert to the appropriate
2752 pointer type (actually unsigned integral). */
2754 intop = convert (result_type,
2755 build_binary_op (MULT_EXPR, intop,
2756 convert (TREE_TYPE (intop), size_exp), 1));
2758 /* Create the sum or difference. */
2760 result = build (resultcode, result_type, ptrop, intop);
2762 folded = fold (result);
2763 if (folded == result)
2764 TREE_CONSTANT (folded) = TREE_CONSTANT (ptrop) & TREE_CONSTANT (intop);
2768 /* Return a tree for the difference of pointers OP0 and OP1.
2769 The resulting tree has type int. */
2772 pointer_diff (op0, op1)
2773 register tree op0, op1;
2775 register tree result, folded;
2776 tree restype = ptrdiff_type_node;
2778 tree target_type = TREE_TYPE (TREE_TYPE (op0));
2780 if (pedantic || warn_pointer_arith)
2782 if (TREE_CODE (target_type) == VOID_TYPE)
2783 pedwarn ("pointer of type `void *' used in subtraction");
2784 if (TREE_CODE (target_type) == FUNCTION_TYPE)
2785 pedwarn ("pointer to a function used in subtraction");
2788 /* First do the subtraction as integers;
2789 then drop through to build the divide operator.
2790 Do not do default conversions on the minus operator
2791 in case restype is a short type. */
2793 op0 = build_binary_op (MINUS_EXPR, convert (restype, op0),
2794 convert (restype, op1), 0);
2795 /* This generates an error if op1 is pointer to incomplete type. */
2796 if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (op1))))
2797 error ("arithmetic on pointer to an incomplete type");
2799 /* This generates an error if op0 is pointer to incomplete type. */
2800 op1 = c_size_in_bytes (target_type);
2802 /* Divide by the size, in easiest possible way. */
2804 result = build (EXACT_DIV_EXPR, restype, op0, convert (restype, op1));
2806 folded = fold (result);
2807 if (folded == result)
2808 TREE_CONSTANT (folded) = TREE_CONSTANT (op0) & TREE_CONSTANT (op1);
2812 /* Construct and perhaps optimize a tree representation
2813 for a unary operation. CODE, a tree_code, specifies the operation
2814 and XARG is the operand. NOCONVERT nonzero suppresses
2815 the default promotions (such as from short to int). */
2818 build_unary_op (code, xarg, noconvert)
2819 enum tree_code code;
2823 /* No default_conversion here. It causes trouble for ADDR_EXPR. */
2824 register tree arg = xarg;
2825 register tree argtype = 0;
2826 register enum tree_code typecode = TREE_CODE (TREE_TYPE (arg));
2829 if (typecode == ERROR_MARK)
2830 return error_mark_node;
2831 if (typecode == ENUMERAL_TYPE || typecode == BOOLEAN_TYPE)
2832 typecode = INTEGER_TYPE;
2837 /* This is used for unary plus, because a CONVERT_EXPR
2838 is enough to prevent anybody from looking inside for
2839 associativity, but won't generate any code. */
2840 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
2841 || typecode == COMPLEX_TYPE))
2843 error ("wrong type argument to unary plus");
2844 return error_mark_node;
2846 else if (!noconvert)
2847 arg = default_conversion (arg);
2851 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
2852 || typecode == COMPLEX_TYPE))
2854 error ("wrong type argument to unary minus");
2855 return error_mark_node;
2857 else if (!noconvert)
2858 arg = default_conversion (arg);
2862 if (typecode == COMPLEX_TYPE)
2866 pedwarn ("ISO C does not support `~' for complex conjugation");
2868 arg = default_conversion (arg);
2870 else if (typecode != INTEGER_TYPE)
2872 error ("wrong type argument to bit-complement");
2873 return error_mark_node;
2875 else if (!noconvert)
2876 arg = default_conversion (arg);
2880 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
2881 || typecode == COMPLEX_TYPE))
2883 error ("wrong type argument to abs");
2884 return error_mark_node;
2886 else if (!noconvert)
2887 arg = default_conversion (arg);
2891 /* Conjugating a real value is a no-op, but allow it anyway. */
2892 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
2893 || typecode == COMPLEX_TYPE))
2895 error ("wrong type argument to conjugation");
2896 return error_mark_node;
2898 else if (!noconvert)
2899 arg = default_conversion (arg);
2902 case TRUTH_NOT_EXPR:
2903 if (typecode != INTEGER_TYPE
2904 && typecode != REAL_TYPE && typecode != POINTER_TYPE
2905 && typecode != COMPLEX_TYPE
2906 /* These will convert to a pointer. */
2907 && typecode != ARRAY_TYPE && typecode != FUNCTION_TYPE)
2909 error ("wrong type argument to unary exclamation mark");
2910 return error_mark_node;
2912 arg = truthvalue_conversion (arg);
2913 return invert_truthvalue (arg);
2919 if (TREE_CODE (arg) == COMPLEX_CST)
2920 return TREE_REALPART (arg);
2921 else if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE)
2922 return fold (build1 (REALPART_EXPR, TREE_TYPE (TREE_TYPE (arg)), arg));
2927 if (TREE_CODE (arg) == COMPLEX_CST)
2928 return TREE_IMAGPART (arg);
2929 else if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE)
2930 return fold (build1 (IMAGPART_EXPR, TREE_TYPE (TREE_TYPE (arg)), arg));
2932 return convert (TREE_TYPE (arg), integer_zero_node);
2934 case PREINCREMENT_EXPR:
2935 case POSTINCREMENT_EXPR:
2936 case PREDECREMENT_EXPR:
2937 case POSTDECREMENT_EXPR:
2938 /* Handle complex lvalues (when permitted)
2939 by reduction to simpler cases. */
2941 val = unary_complex_lvalue (code, arg);
2945 /* Increment or decrement the real part of the value,
2946 and don't change the imaginary part. */
2947 if (typecode == COMPLEX_TYPE)
2952 pedwarn ("ISO C does not support `++' and `--' on complex types");
2954 arg = stabilize_reference (arg);
2955 real = build_unary_op (REALPART_EXPR, arg, 1);
2956 imag = build_unary_op (IMAGPART_EXPR, arg, 1);
2957 return build (COMPLEX_EXPR, TREE_TYPE (arg),
2958 build_unary_op (code, real, 1), imag);
2961 /* Report invalid types. */
2963 if (typecode != POINTER_TYPE
2964 && typecode != INTEGER_TYPE && typecode != REAL_TYPE)
2966 error ("wrong type argument to %s",
2967 code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR
2968 ? "increment" : "decrement");
2969 return error_mark_node;
2974 tree result_type = TREE_TYPE (arg);
2976 arg = get_unwidened (arg, 0);
2977 argtype = TREE_TYPE (arg);
2979 /* Compute the increment. */
2981 if (typecode == POINTER_TYPE)
2983 /* If pointer target is an undefined struct,
2984 we just cannot know how to do the arithmetic. */
2985 if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (result_type)))
2986 error ("%s of pointer to unknown structure",
2987 code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR
2988 ? "increment" : "decrement");
2989 else if ((pedantic || warn_pointer_arith)
2990 && (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE
2991 || TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE))
2992 pedwarn ("wrong type argument to %s",
2993 code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR
2994 ? "increment" : "decrement");
2995 inc = c_size_in_bytes (TREE_TYPE (result_type));
2998 inc = integer_one_node;
3000 inc = convert (argtype, inc);
3002 /* Handle incrementing a cast-expression. */
3005 switch (TREE_CODE (arg))
3010 case FIX_TRUNC_EXPR:
3011 case FIX_FLOOR_EXPR:
3012 case FIX_ROUND_EXPR:
3014 pedantic_lvalue_warning (CONVERT_EXPR);
3015 /* If the real type has the same machine representation
3016 as the type it is cast to, we can make better output
3017 by adding directly to the inside of the cast. */
3018 if ((TREE_CODE (TREE_TYPE (arg))
3019 == TREE_CODE (TREE_TYPE (TREE_OPERAND (arg, 0))))
3020 && (TYPE_MODE (TREE_TYPE (arg))
3021 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (arg, 0)))))
3022 arg = TREE_OPERAND (arg, 0);
3025 tree incremented, modify, value;
3026 if (TREE_CODE (TREE_TYPE (arg)) == BOOLEAN_TYPE)
3027 value = boolean_increment (code, arg);
3030 arg = stabilize_reference (arg);
3031 if (code == PREINCREMENT_EXPR || code == PREDECREMENT_EXPR)
3034 value = save_expr (arg);
3035 incremented = build (((code == PREINCREMENT_EXPR
3036 || code == POSTINCREMENT_EXPR)
3037 ? PLUS_EXPR : MINUS_EXPR),
3038 argtype, value, inc);
3039 TREE_SIDE_EFFECTS (incremented) = 1;
3040 modify = build_modify_expr (arg, NOP_EXPR, incremented);
3041 value = build (COMPOUND_EXPR, TREE_TYPE (arg), modify, value);
3043 TREE_USED (value) = 1;
3053 /* Complain about anything else that is not a true lvalue. */
3054 if (!lvalue_or_else (arg, ((code == PREINCREMENT_EXPR
3055 || code == POSTINCREMENT_EXPR)
3056 ? "invalid lvalue in increment"
3057 : "invalid lvalue in decrement")))
3058 return error_mark_node;
3060 /* Report a read-only lvalue. */
3061 if (TREE_READONLY (arg))
3062 readonly_warning (arg,
3063 ((code == PREINCREMENT_EXPR
3064 || code == POSTINCREMENT_EXPR)
3065 ? "increment" : "decrement"));
3067 if (TREE_CODE (TREE_TYPE (arg)) == BOOLEAN_TYPE)
3068 val = boolean_increment (code, arg);
3070 val = build (code, TREE_TYPE (arg), arg, inc);
3071 TREE_SIDE_EFFECTS (val) = 1;
3072 val = convert (result_type, val);
3073 if (TREE_CODE (val) != code)
3074 TREE_NO_UNUSED_WARNING (val) = 1;
3079 /* Note that this operation never does default_conversion
3080 regardless of NOCONVERT. */
3082 /* Let &* cancel out to simplify resulting code. */
3083 if (TREE_CODE (arg) == INDIRECT_REF)
3085 /* Don't let this be an lvalue. */
3086 if (lvalue_p (TREE_OPERAND (arg, 0)))
3087 return non_lvalue (TREE_OPERAND (arg, 0));
3088 return TREE_OPERAND (arg, 0);
3091 /* For &x[y], return x+y */
3092 if (TREE_CODE (arg) == ARRAY_REF)
3094 if (mark_addressable (TREE_OPERAND (arg, 0)) == 0)
3095 return error_mark_node;
3096 return build_binary_op (PLUS_EXPR, TREE_OPERAND (arg, 0),
3097 TREE_OPERAND (arg, 1), 1);
3100 /* Handle complex lvalues (when permitted)
3101 by reduction to simpler cases. */
3102 val = unary_complex_lvalue (code, arg);
3106 #if 0 /* Turned off because inconsistent;
3107 float f; *&(int)f = 3.4 stores in int format
3108 whereas (int)f = 3.4 stores in float format. */
3109 /* Address of a cast is just a cast of the address
3110 of the operand of the cast. */
3111 switch (TREE_CODE (arg))
3116 case FIX_TRUNC_EXPR:
3117 case FIX_FLOOR_EXPR:
3118 case FIX_ROUND_EXPR:
3121 pedwarn ("ISO C forbids the address of a cast expression");
3122 return convert (build_pointer_type (TREE_TYPE (arg)),
3123 build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0),
3128 /* Allow the address of a constructor if all the elements
3130 if (TREE_CODE (arg) == CONSTRUCTOR && TREE_CONSTANT (arg))
3132 /* Anything not already handled and not a true memory reference
3134 else if (typecode != FUNCTION_TYPE
3135 && !lvalue_or_else (arg, "invalid lvalue in unary `&'"))
3136 return error_mark_node;
3138 /* Ordinary case; arg is a COMPONENT_REF or a decl. */
3139 argtype = TREE_TYPE (arg);
3141 /* If the lvalue is const or volatile, merge that into the type
3142 to which the address will point. Note that you can't get a
3143 restricted pointer by taking the address of something, so we
3144 only have to deal with `const' and `volatile' here. */
3145 if ((DECL_P (arg) || TREE_CODE_CLASS (TREE_CODE (arg)) == 'r')
3146 && (TREE_READONLY (arg) || TREE_THIS_VOLATILE (arg)))
3147 argtype = c_build_type_variant (argtype,
3148 TREE_READONLY (arg),
3149 TREE_THIS_VOLATILE (arg));
3151 argtype = build_pointer_type (argtype);
3153 if (mark_addressable (arg) == 0)
3154 return error_mark_node;
3159 if (TREE_CODE (arg) == COMPONENT_REF)
3161 tree field = TREE_OPERAND (arg, 1);
3163 addr = build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0), 0);
3165 if (DECL_C_BIT_FIELD (field))
3167 error ("attempt to take address of bit-field structure member `%s'",
3168 IDENTIFIER_POINTER (DECL_NAME (field)));
3169 return error_mark_node;
3172 addr = fold (build (PLUS_EXPR, argtype,
3173 convert (argtype, addr),
3174 convert (argtype, byte_position (field))));
3177 addr = build1 (code, argtype, arg);
3179 /* Address of a static or external variable or
3180 file-scope function counts as a constant. */
3182 && ! (TREE_CODE (arg) == FUNCTION_DECL
3183 && DECL_CONTEXT (arg) != 0))
3184 TREE_CONSTANT (addr) = 1;
3193 argtype = TREE_TYPE (arg);
3194 return fold (build1 (code, argtype, arg));
3198 /* If CONVERSIONS is a conversion expression or a nested sequence of such,
3199 convert ARG with the same conversions in the same order
3200 and return the result. */
3203 convert_sequence (conversions, arg)
3207 switch (TREE_CODE (conversions))
3212 case FIX_TRUNC_EXPR:
3213 case FIX_FLOOR_EXPR:
3214 case FIX_ROUND_EXPR:
3216 return convert (TREE_TYPE (conversions),
3217 convert_sequence (TREE_OPERAND (conversions, 0),
3226 /* Return nonzero if REF is an lvalue valid for this language.
3227 Lvalues can be assigned, unless their type has TYPE_READONLY.
3228 Lvalues can have their address taken, unless they have DECL_REGISTER. */
3234 register enum tree_code code = TREE_CODE (ref);
3241 return lvalue_p (TREE_OPERAND (ref, 0));
3252 return (TREE_CODE (TREE_TYPE (ref)) != FUNCTION_TYPE
3253 && TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE);
3257 return TREE_CODE (TREE_TYPE (ref)) == ARRAY_TYPE;
3264 /* Return nonzero if REF is an lvalue valid for this language;
3265 otherwise, print an error message and return zero. */
3268 lvalue_or_else (ref, msgid)
3272 int win = lvalue_p (ref);
3275 error ("%s", msgid);
3280 /* Apply unary lvalue-demanding operator CODE to the expression ARG
3281 for certain kinds of expressions which are not really lvalues
3282 but which we can accept as lvalues.
3284 If ARG is not a kind of expression we can handle, return zero. */
3287 unary_complex_lvalue (code, arg)
3288 enum tree_code code;
3291 /* Handle (a, b) used as an "lvalue". */
3292 if (TREE_CODE (arg) == COMPOUND_EXPR)
3294 tree real_result = build_unary_op (code, TREE_OPERAND (arg, 1), 0);
3296 /* If this returns a function type, it isn't really being used as
3297 an lvalue, so don't issue a warning about it. */
3298 if (TREE_CODE (TREE_TYPE (arg)) != FUNCTION_TYPE)
3299 pedantic_lvalue_warning (COMPOUND_EXPR);
3301 return build (COMPOUND_EXPR, TREE_TYPE (real_result),
3302 TREE_OPERAND (arg, 0), real_result);
3305 /* Handle (a ? b : c) used as an "lvalue". */
3306 if (TREE_CODE (arg) == COND_EXPR)
3308 pedantic_lvalue_warning (COND_EXPR);
3309 if (TREE_CODE (TREE_TYPE (arg)) != FUNCTION_TYPE)
3310 pedantic_lvalue_warning (COMPOUND_EXPR);
3312 return (build_conditional_expr
3313 (TREE_OPERAND (arg, 0),
3314 build_unary_op (code, TREE_OPERAND (arg, 1), 0),
3315 build_unary_op (code, TREE_OPERAND (arg, 2), 0)));
3321 /* If pedantic, warn about improper lvalue. CODE is either COND_EXPR
3322 COMPOUND_EXPR, or CONVERT_EXPR (for casts). */
3325 pedantic_lvalue_warning (code)
3326 enum tree_code code;
3332 pedwarn ("ISO C forbids use of conditional expressions as lvalues");
3335 pedwarn ("ISO C forbids use of compound expressions as lvalues");
3338 pedwarn ("ISO C forbids use of cast expressions as lvalues");
3343 /* Warn about storing in something that is `const'. */
3346 readonly_warning (arg, msgid)
3350 if (TREE_CODE (arg) == COMPONENT_REF)
3352 if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg, 0))))
3353 readonly_warning (TREE_OPERAND (arg, 0), msgid);
3355 pedwarn ("%s of read-only member `%s'", _(msgid),
3356 IDENTIFIER_POINTER (DECL_NAME (TREE_OPERAND (arg, 1))));
3358 else if (TREE_CODE (arg) == VAR_DECL)
3359 pedwarn ("%s of read-only variable `%s'", _(msgid),
3360 IDENTIFIER_POINTER (DECL_NAME (arg)));
3362 pedwarn ("%s of read-only location", _(msgid));
3365 /* Mark EXP saying that we need to be able to take the
3366 address of it; it should not be allocated in a register.
3367 Value is 1 if successful. */
3370 mark_addressable (exp)
3373 register tree x = exp;
3375 switch (TREE_CODE (x))
3378 if (DECL_C_BIT_FIELD (TREE_OPERAND (x, 1)))
3380 error ("cannot take address of bitfield `%s'",
3381 IDENTIFIER_POINTER (DECL_NAME (TREE_OPERAND (x, 1))));
3385 /* ... fall through ... */
3391 x = TREE_OPERAND (x, 0);
3395 TREE_ADDRESSABLE (x) = 1;
3402 if (DECL_REGISTER (x) && !TREE_ADDRESSABLE (x)
3403 && DECL_NONLOCAL (x))
3405 if (TREE_PUBLIC (x))
3407 error ("global register variable `%s' used in nested function",
3408 IDENTIFIER_POINTER (DECL_NAME (x)));
3411 pedwarn ("register variable `%s' used in nested function",
3412 IDENTIFIER_POINTER (DECL_NAME (x)));
3414 else if (DECL_REGISTER (x) && !TREE_ADDRESSABLE (x))
3416 if (TREE_PUBLIC (x))
3418 error ("address of global register variable `%s' requested",
3419 IDENTIFIER_POINTER (DECL_NAME (x)));
3423 /* If we are making this addressable due to its having
3424 volatile components, give a different error message. Also
3425 handle the case of an unnamed parameter by not trying
3426 to give the name. */
3428 else if (C_TYPE_FIELDS_VOLATILE (TREE_TYPE (x)))
3430 error ("cannot put object with volatile field into register");
3434 pedwarn ("address of register variable `%s' requested",
3435 IDENTIFIER_POINTER (DECL_NAME (x)));
3437 put_var_into_stack (x);
3441 TREE_ADDRESSABLE (x) = 1;
3442 #if 0 /* poplevel deals with this now. */
3443 if (DECL_CONTEXT (x) == 0)
3444 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (x)) = 1;
3452 /* Build and return a conditional expression IFEXP ? OP1 : OP2. */
3455 build_conditional_expr (ifexp, op1, op2)
3456 tree ifexp, op1, op2;
3458 register tree type1;
3459 register tree type2;
3460 register enum tree_code code1;
3461 register enum tree_code code2;
3462 register tree result_type = NULL;
3463 tree orig_op1 = op1, orig_op2 = op2;
3465 ifexp = truthvalue_conversion (default_conversion (ifexp));
3467 #if 0 /* Produces wrong result if within sizeof. */
3468 /* Don't promote the operands separately if they promote
3469 the same way. Return the unpromoted type and let the combined
3470 value get promoted if necessary. */
3472 if (TREE_TYPE (op1) == TREE_TYPE (op2)
3473 && TREE_CODE (TREE_TYPE (op1)) != ARRAY_TYPE
3474 && TREE_CODE (TREE_TYPE (op1)) != ENUMERAL_TYPE
3475 && TREE_CODE (TREE_TYPE (op1)) != FUNCTION_TYPE)
3477 if (TREE_CODE (ifexp) == INTEGER_CST)
3478 return pedantic_non_lvalue (integer_zerop (ifexp) ? op2 : op1);
3480 return fold (build (COND_EXPR, TREE_TYPE (op1), ifexp, op1, op2));
3484 /* Promote both alternatives. */
3486 if (TREE_CODE (TREE_TYPE (op1)) != VOID_TYPE)
3487 op1 = default_conversion (op1);
3488 if (TREE_CODE (TREE_TYPE (op2)) != VOID_TYPE)
3489 op2 = default_conversion (op2);
3491 if (TREE_CODE (ifexp) == ERROR_MARK
3492 || TREE_CODE (TREE_TYPE (op1)) == ERROR_MARK
3493 || TREE_CODE (TREE_TYPE (op2)) == ERROR_MARK)
3494 return error_mark_node;
3496 type1 = TREE_TYPE (op1);
3497 code1 = TREE_CODE (type1);
3498 type2 = TREE_TYPE (op2);
3499 code2 = TREE_CODE (type2);
3501 /* Quickly detect the usual case where op1 and op2 have the same type
3503 if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2))
3506 result_type = type1;
3508 result_type = TYPE_MAIN_VARIANT (type1);
3510 else if ((code1 == INTEGER_TYPE || code1 == REAL_TYPE
3511 || code1 == COMPLEX_TYPE)
3512 && (code2 == INTEGER_TYPE || code2 == REAL_TYPE
3513 || code2 == COMPLEX_TYPE))
3515 result_type = common_type (type1, type2);
3517 /* If -Wsign-compare, warn here if type1 and type2 have
3518 different signedness. We'll promote the signed to unsigned
3519 and later code won't know it used to be different.
3520 Do this check on the original types, so that explicit casts
3521 will be considered, but default promotions won't. */
3522 if ((warn_sign_compare < 0 ? extra_warnings : warn_sign_compare)
3523 && !skip_evaluation)
3525 int unsigned_op1 = TREE_UNSIGNED (TREE_TYPE (orig_op1));
3526 int unsigned_op2 = TREE_UNSIGNED (TREE_TYPE (orig_op2));
3528 if (unsigned_op1 ^ unsigned_op2)
3530 /* Do not warn if the result type is signed, since the
3531 signed type will only be chosen if it can represent
3532 all the values of the unsigned type. */
3533 if (! TREE_UNSIGNED (result_type))
3535 /* Do not warn if the signed quantity is an unsuffixed
3536 integer literal (or some static constant expression
3537 involving such literals) and it is non-negative. */
3538 else if ((unsigned_op2 && tree_expr_nonnegative_p (op1))
3539 || (unsigned_op1 && tree_expr_nonnegative_p (op2)))
3542 warning ("signed and unsigned type in conditional expression");
3546 else if (code1 == VOID_TYPE || code2 == VOID_TYPE)
3548 if (pedantic && (code1 != VOID_TYPE || code2 != VOID_TYPE))
3549 pedwarn ("ISO C forbids conditional expr with only one void side");
3550 result_type = void_type_node;
3552 else if (code1 == POINTER_TYPE && code2 == POINTER_TYPE)
3554 if (comp_target_types (type1, type2))
3555 result_type = common_type (type1, type2);
3556 else if (integer_zerop (op1) && TREE_TYPE (type1) == void_type_node
3557 && TREE_CODE (orig_op1) != NOP_EXPR)
3558 result_type = qualify_type (type2, type1);
3559 else if (integer_zerop (op2) && TREE_TYPE (type2) == void_type_node
3560 && TREE_CODE (orig_op2) != NOP_EXPR)
3561 result_type = qualify_type (type1, type2);
3562 else if (VOID_TYPE_P (TREE_TYPE (type1)))
3564 if (pedantic && TREE_CODE (TREE_TYPE (type2)) == FUNCTION_TYPE)
3565 pedwarn ("ISO C forbids conditional expr between `void *' and function pointer");
3566 result_type = build_pointer_type (qualify_type (TREE_TYPE (type1),
3567 TREE_TYPE (type2)));
3569 else if (VOID_TYPE_P (TREE_TYPE (type2)))
3571 if (pedantic && TREE_CODE (TREE_TYPE (type1)) == FUNCTION_TYPE)
3572 pedwarn ("ISO C forbids conditional expr between `void *' and function pointer");
3573 result_type = build_pointer_type (qualify_type (TREE_TYPE (type2),
3574 TREE_TYPE (type1)));
3578 pedwarn ("pointer type mismatch in conditional expression");
3579 result_type = build_pointer_type (void_type_node);
3582 else if (code1 == POINTER_TYPE && code2 == INTEGER_TYPE)
3584 if (! integer_zerop (op2))
3585 pedwarn ("pointer/integer type mismatch in conditional expression");
3588 op2 = null_pointer_node;
3590 result_type = type1;
3592 else if (code2 == POINTER_TYPE && code1 == INTEGER_TYPE)
3594 if (!integer_zerop (op1))
3595 pedwarn ("pointer/integer type mismatch in conditional expression");
3598 op1 = null_pointer_node;
3600 result_type = type2;
3605 if (flag_cond_mismatch)
3606 result_type = void_type_node;
3609 error ("type mismatch in conditional expression");
3610 return error_mark_node;
3614 /* Merge const and volatile flags of the incoming types. */
3616 = build_type_variant (result_type,
3617 TREE_READONLY (op1) || TREE_READONLY (op2),
3618 TREE_THIS_VOLATILE (op1) || TREE_THIS_VOLATILE (op2));
3620 if (result_type != TREE_TYPE (op1))
3621 op1 = convert_and_check (result_type, op1);
3622 if (result_type != TREE_TYPE (op2))
3623 op2 = convert_and_check (result_type, op2);
3625 if (TREE_CODE (ifexp) == INTEGER_CST)
3626 return pedantic_non_lvalue (integer_zerop (ifexp) ? op2 : op1);
3628 return fold (build (COND_EXPR, result_type, ifexp, op1, op2));
3631 /* Given a list of expressions, return a compound expression
3632 that performs them all and returns the value of the last of them. */
3635 build_compound_expr (list)
3638 return internal_build_compound_expr (list, TRUE);
3642 internal_build_compound_expr (list, first_p)
3648 if (TREE_CHAIN (list) == 0)
3650 #if 0 /* If something inside inhibited lvalueness, we should not override. */
3651 /* Consider (x, y+0), which is not an lvalue since y+0 is not. */
3653 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
3654 if (TREE_CODE (list) == NON_LVALUE_EXPR)
3655 list = TREE_OPERAND (list, 0);
3658 /* Don't let (0, 0) be null pointer constant. */
3659 if (!first_p && integer_zerop (TREE_VALUE (list)))
3660 return non_lvalue (TREE_VALUE (list));
3661 return TREE_VALUE (list);
3664 if (TREE_CHAIN (list) != 0 && TREE_CHAIN (TREE_CHAIN (list)) == 0)
3666 /* Convert arrays to pointers when there really is a comma operator. */
3667 if (TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (list)))) == ARRAY_TYPE)
3668 TREE_VALUE (TREE_CHAIN (list))
3669 = default_conversion (TREE_VALUE (TREE_CHAIN (list)));
3672 rest = internal_build_compound_expr (TREE_CHAIN (list), FALSE);
3674 if (! TREE_SIDE_EFFECTS (TREE_VALUE (list)))
3676 /* The left-hand operand of a comma expression is like an expression
3677 statement: with -W or -Wunused, we should warn if it doesn't have
3678 any side-effects, unless it was explicitly cast to (void). */
3679 if ((extra_warnings || warn_unused_value)
3680 && ! (TREE_CODE (TREE_VALUE (list)) == CONVERT_EXPR
3681 && VOID_TYPE_P (TREE_TYPE (TREE_VALUE (list)))))
3682 warning ("left-hand operand of comma expression has no effect");
3684 /* When pedantic, a compound expression can be neither an lvalue
3685 nor an integer constant expression. */
3690 /* With -Wunused, we should also warn if the left-hand operand does have
3691 side-effects, but computes a value which is not used. For example, in
3692 `foo() + bar(), baz()' the result of the `+' operator is not used,
3693 so we should issue a warning. */
3694 else if (warn_unused_value)
3695 warn_if_unused_value (TREE_VALUE (list));
3697 return build (COMPOUND_EXPR, TREE_TYPE (rest), TREE_VALUE (list), rest);
3700 /* Build an expression representing a cast to type TYPE of expression EXPR. */
3703 build_c_cast (type, expr)
3707 register tree value = expr;
3709 if (type == error_mark_node || expr == error_mark_node)
3710 return error_mark_node;
3711 type = TYPE_MAIN_VARIANT (type);
3714 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
3715 if (TREE_CODE (value) == NON_LVALUE_EXPR)
3716 value = TREE_OPERAND (value, 0);
3719 if (TREE_CODE (type) == ARRAY_TYPE)
3721 error ("cast specifies array type");
3722 return error_mark_node;
3725 if (TREE_CODE (type) == FUNCTION_TYPE)
3727 error ("cast specifies function type");
3728 return error_mark_node;
3731 if (type == TREE_TYPE (value))
3735 if (TREE_CODE (type) == RECORD_TYPE
3736 || TREE_CODE (type) == UNION_TYPE)
3737 pedwarn ("ISO C forbids casting nonscalar to the same type");
3740 else if (TREE_CODE (type) == UNION_TYPE)
3743 if (TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE
3744 || TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE)
3745 value = default_conversion (value);
3747 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
3748 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (field)),
3749 TYPE_MAIN_VARIANT (TREE_TYPE (value))))
3758 pedwarn ("ISO C forbids casts to union type");
3759 if (TYPE_NAME (type) != 0)
3761 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
3762 name = IDENTIFIER_POINTER (TYPE_NAME (type));
3764 name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
3768 t = digest_init (type, build (CONSTRUCTOR, type, NULL_TREE,
3769 build_tree_list (field, value)),
3771 TREE_CONSTANT (t) = TREE_CONSTANT (value);
3774 error ("cast to union type from type not present in union");
3775 return error_mark_node;
3781 /* If casting to void, avoid the error that would come
3782 from default_conversion in the case of a non-lvalue array. */
3783 if (type == void_type_node)
3784 return build1 (CONVERT_EXPR, type, value);
3786 /* Convert functions and arrays to pointers,
3787 but don't convert any other types. */
3788 if (TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE
3789 || TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE)
3790 value = default_conversion (value);
3791 otype = TREE_TYPE (value);
3793 /* Optionally warn about potentially worrisome casts. */
3796 && TREE_CODE (type) == POINTER_TYPE
3797 && TREE_CODE (otype) == POINTER_TYPE)
3799 tree in_type = type;
3800 tree in_otype = otype;
3803 /* Check that the qualifiers on IN_TYPE are a superset of
3804 the qualifiers of IN_OTYPE. The outermost level of
3805 POINTER_TYPE nodes is uninteresting and we stop as soon
3806 as we hit a non-POINTER_TYPE node on either type. */
3809 in_otype = TREE_TYPE (in_otype);
3810 in_type = TREE_TYPE (in_type);
3811 warn |= (TYPE_QUALS (in_otype) & ~TYPE_QUALS (in_type));
3813 while (TREE_CODE (in_type) == POINTER_TYPE
3814 && TREE_CODE (in_otype) == POINTER_TYPE);
3817 /* There are qualifiers present in IN_OTYPE that are not
3818 present in IN_TYPE. */
3819 warning ("cast discards qualifiers from pointer target type");
3822 /* Warn about possible alignment problems. */
3823 if (STRICT_ALIGNMENT && warn_cast_align
3824 && TREE_CODE (type) == POINTER_TYPE
3825 && TREE_CODE (otype) == POINTER_TYPE
3826 && TREE_CODE (TREE_TYPE (otype)) != VOID_TYPE
3827 && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
3828 /* Don't warn about opaque types, where the actual alignment
3829 restriction is unknown. */
3830 && !((TREE_CODE (TREE_TYPE (otype)) == UNION_TYPE
3831 || TREE_CODE (TREE_TYPE (otype)) == RECORD_TYPE)
3832 && TYPE_MODE (TREE_TYPE (otype)) == VOIDmode)
3833 && TYPE_ALIGN (TREE_TYPE (type)) > TYPE_ALIGN (TREE_TYPE (otype)))
3834 warning ("cast increases required alignment of target type");
3836 if (TREE_CODE (type) == INTEGER_TYPE
3837 && TREE_CODE (otype) == POINTER_TYPE
3838 && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
3839 && !TREE_CONSTANT (value))
3840 warning ("cast from pointer to integer of different size");
3842 if (warn_bad_function_cast
3843 && TREE_CODE (value) == CALL_EXPR
3844 && TREE_CODE (type) != TREE_CODE (otype))
3845 warning ("cast does not match function type");
3847 if (TREE_CODE (type) == POINTER_TYPE
3848 && TREE_CODE (otype) == INTEGER_TYPE
3849 && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
3850 /* Don't warn about converting any constant. */
3851 && !TREE_CONSTANT (value))
3852 warning ("cast to pointer from integer of different size");
3855 value = convert (type, value);
3857 /* Ignore any integer overflow caused by the cast. */
3858 if (TREE_CODE (value) == INTEGER_CST)
3860 TREE_OVERFLOW (value) = TREE_OVERFLOW (ovalue);
3861 TREE_CONSTANT_OVERFLOW (value) = TREE_CONSTANT_OVERFLOW (ovalue);
3865 /* Pedantically, don't ley (void *) (FOO *) 0 be a null pointer constant. */
3866 if (pedantic && TREE_CODE (value) == INTEGER_CST
3867 && TREE_CODE (expr) == INTEGER_CST
3868 && TREE_CODE (TREE_TYPE (expr)) != INTEGER_TYPE)
3869 value = non_lvalue (value);
3871 /* If pedantic, don't let a cast be an lvalue. */
3872 if (value == expr && pedantic)
3873 value = non_lvalue (value);
3878 /* Build an assignment expression of lvalue LHS from value RHS.
3879 MODIFYCODE is the code for a binary operator that we use
3880 to combine the old value of LHS with RHS to get the new value.
3881 Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment. */
3884 build_modify_expr (lhs, modifycode, rhs)
3886 enum tree_code modifycode;
3888 register tree result;
3890 tree lhstype = TREE_TYPE (lhs);
3891 tree olhstype = lhstype;
3893 /* Types that aren't fully specified cannot be used in assignments. */
3894 lhs = require_complete_type (lhs);
3896 /* Avoid duplicate error messages from operands that had errors. */
3897 if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK)
3898 return error_mark_node;
3900 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
3901 /* Do not use STRIP_NOPS here. We do not want an enumerator
3902 whose value is 0 to count as a null pointer constant. */
3903 if (TREE_CODE (rhs) == NON_LVALUE_EXPR)
3904 rhs = TREE_OPERAND (rhs, 0);
3908 /* Handle control structure constructs used as "lvalues". */
3910 switch (TREE_CODE (lhs))
3912 /* Handle (a, b) used as an "lvalue". */
3914 pedantic_lvalue_warning (COMPOUND_EXPR);
3915 newrhs = build_modify_expr (TREE_OPERAND (lhs, 1), modifycode, rhs);
3916 if (TREE_CODE (newrhs) == ERROR_MARK)
3917 return error_mark_node;
3918 return build (COMPOUND_EXPR, lhstype,
3919 TREE_OPERAND (lhs, 0), newrhs);
3921 /* Handle (a ? b : c) used as an "lvalue". */
3923 pedantic_lvalue_warning (COND_EXPR);
3924 rhs = save_expr (rhs);
3926 /* Produce (a ? (b = rhs) : (c = rhs))
3927 except that the RHS goes through a save-expr
3928 so the code to compute it is only emitted once. */
3930 = build_conditional_expr (TREE_OPERAND (lhs, 0),
3931 build_modify_expr (TREE_OPERAND (lhs, 1),
3933 build_modify_expr (TREE_OPERAND (lhs, 2),
3935 if (TREE_CODE (cond) == ERROR_MARK)
3937 /* Make sure the code to compute the rhs comes out
3938 before the split. */
3939 return build (COMPOUND_EXPR, TREE_TYPE (lhs),
3940 /* But cast it to void to avoid an "unused" error. */
3941 convert (void_type_node, rhs), cond);
3947 /* If a binary op has been requested, combine the old LHS value with the RHS
3948 producing the value we should actually store into the LHS. */
3950 if (modifycode != NOP_EXPR)
3952 lhs = stabilize_reference (lhs);
3953 newrhs = build_binary_op (modifycode, lhs, rhs, 1);
3956 /* Handle a cast used as an "lvalue".
3957 We have already performed any binary operator using the value as cast.
3958 Now convert the result to the cast type of the lhs,
3959 and then true type of the lhs and store it there;
3960 then convert result back to the cast type to be the value
3961 of the assignment. */
3963 switch (TREE_CODE (lhs))
3968 case FIX_TRUNC_EXPR:
3969 case FIX_FLOOR_EXPR:
3970 case FIX_ROUND_EXPR:
3972 if (TREE_CODE (TREE_TYPE (newrhs)) == ARRAY_TYPE
3973 || TREE_CODE (TREE_TYPE (newrhs)) == FUNCTION_TYPE)
3974 newrhs = default_conversion (newrhs);
3976 tree inner_lhs = TREE_OPERAND (lhs, 0);
3978 result = build_modify_expr (inner_lhs, NOP_EXPR,
3979 convert (TREE_TYPE (inner_lhs),
3980 convert (lhstype, newrhs)));
3981 if (TREE_CODE (result) == ERROR_MARK)
3983 pedantic_lvalue_warning (CONVERT_EXPR);
3984 return convert (TREE_TYPE (lhs), result);
3991 /* Now we have handled acceptable kinds of LHS that are not truly lvalues.
3992 Reject anything strange now. */
3994 if (!lvalue_or_else (lhs, "invalid lvalue in assignment"))
3995 return error_mark_node;
3997 /* Warn about storing in something that is `const'. */
3999 if (TREE_READONLY (lhs) || TYPE_READONLY (lhstype)
4000 || ((TREE_CODE (lhstype) == RECORD_TYPE
4001 || TREE_CODE (lhstype) == UNION_TYPE)
4002 && C_TYPE_FIELDS_READONLY (lhstype)))
4003 readonly_warning (lhs, "assignment");
4005 /* If storing into a structure or union member,
4006 it has probably been given type `int'.
4007 Compute the type that would go with
4008 the actual amount of storage the member occupies. */
4010 if (TREE_CODE (lhs) == COMPONENT_REF
4011 && (TREE_CODE (lhstype) == INTEGER_TYPE
4012 || TREE_CODE (lhstype) == BOOLEAN_TYPE
4013 || TREE_CODE (lhstype) == REAL_TYPE
4014 || TREE_CODE (lhstype) == ENUMERAL_TYPE))
4015 lhstype = TREE_TYPE (get_unwidened (lhs, 0));
4017 /* If storing in a field that is in actuality a short or narrower than one,
4018 we must store in the field in its actual type. */
4020 if (lhstype != TREE_TYPE (lhs))
4022 lhs = copy_node (lhs);
4023 TREE_TYPE (lhs) = lhstype;
4026 /* Convert new value to destination type. */
4028 newrhs = convert_for_assignment (lhstype, newrhs, _("assignment"),
4029 NULL_TREE, NULL_TREE, 0);
4030 if (TREE_CODE (newrhs) == ERROR_MARK)
4031 return error_mark_node;
4035 result = build (MODIFY_EXPR, lhstype, lhs, newrhs);
4036 TREE_SIDE_EFFECTS (result) = 1;
4038 /* If we got the LHS in a different type for storing in,
4039 convert the result back to the nominal type of LHS
4040 so that the value we return always has the same type
4041 as the LHS argument. */
4043 if (olhstype == TREE_TYPE (result))
4045 return convert_for_assignment (olhstype, result, _("assignment"),
4046 NULL_TREE, NULL_TREE, 0);
4049 /* Convert value RHS to type TYPE as preparation for an assignment
4050 to an lvalue of type TYPE.
4051 The real work of conversion is done by `convert'.
4052 The purpose of this function is to generate error messages
4053 for assignments that are not allowed in C.
4054 ERRTYPE is a string to use in error messages:
4055 "assignment", "return", etc. If it is null, this is parameter passing
4056 for a function call (and different error messages are output).
4058 FUNNAME is the name of the function being called,
4059 as an IDENTIFIER_NODE, or null.
4060 PARMNUM is the number of the argument, for printing in error messages. */
4063 convert_for_assignment (type, rhs, errtype, fundecl, funname, parmnum)
4065 const char *errtype;
4066 tree fundecl, funname;
4069 register enum tree_code codel = TREE_CODE (type);
4070 register tree rhstype;
4071 register enum tree_code coder;
4073 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
4074 /* Do not use STRIP_NOPS here. We do not want an enumerator
4075 whose value is 0 to count as a null pointer constant. */
4076 if (TREE_CODE (rhs) == NON_LVALUE_EXPR)
4077 rhs = TREE_OPERAND (rhs, 0);
4079 if (TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE
4080 || TREE_CODE (TREE_TYPE (rhs)) == FUNCTION_TYPE)
4081 rhs = default_conversion (rhs);
4082 else if (optimize && TREE_CODE (rhs) == VAR_DECL)
4083 rhs = decl_constant_value_for_broken_optimization (rhs);
4085 rhstype = TREE_TYPE (rhs);
4086 coder = TREE_CODE (rhstype);
4088 if (coder == ERROR_MARK)
4089 return error_mark_node;
4091 if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype))
4093 overflow_warning (rhs);
4094 /* Check for Objective-C protocols. This will issue a warning if
4095 there are protocol violations. No need to use the return value. */
4096 maybe_objc_comptypes (type, rhstype, 0);
4100 if (coder == VOID_TYPE)
4102 error ("void value not ignored as it ought to be");
4103 return error_mark_node;
4105 /* A type converts to a reference to it.
4106 This code doesn't fully support references, it's just for the
4107 special case of va_start and va_copy. */
4108 if (codel == REFERENCE_TYPE
4109 && comptypes (TREE_TYPE (type), TREE_TYPE (rhs)) == 1)
4111 if (mark_addressable (rhs) == 0)
4112 return error_mark_node;
4113 rhs = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (rhs)), rhs);
4115 /* We already know that these two types are compatible, but they
4116 may not be exactly identical. In fact, `TREE_TYPE (type)' is
4117 likely to be __builtin_va_list and `TREE_TYPE (rhs)' is
4118 likely to be va_list, a typedef to __builtin_va_list, which
4119 is different enough that it will cause problems later. */
4120 if (TREE_TYPE (TREE_TYPE (rhs)) != TREE_TYPE (type))
4121 rhs = build1 (NOP_EXPR, build_pointer_type (TREE_TYPE (type)), rhs);
4123 rhs = build1 (NOP_EXPR, type, rhs);
4126 /* Arithmetic types all interconvert, and enum is treated like int. */
4127 else if ((codel == INTEGER_TYPE || codel == REAL_TYPE
4128 || codel == ENUMERAL_TYPE || codel == COMPLEX_TYPE
4129 || codel == BOOLEAN_TYPE)
4130 && (coder == INTEGER_TYPE || coder == REAL_TYPE
4131 || coder == ENUMERAL_TYPE || coder == COMPLEX_TYPE
4132 || coder == BOOLEAN_TYPE))
4133 return convert_and_check (type, rhs);
4135 /* Conversion to a transparent union from its member types.
4136 This applies only to function arguments. */
4137 else if (codel == UNION_TYPE && TYPE_TRANSPARENT_UNION (type) && ! errtype)
4140 tree marginal_memb_type = 0;
4142 for (memb_types = TYPE_FIELDS (type); memb_types;
4143 memb_types = TREE_CHAIN (memb_types))
4145 tree memb_type = TREE_TYPE (memb_types);
4147 if (comptypes (TYPE_MAIN_VARIANT (memb_type),
4148 TYPE_MAIN_VARIANT (rhstype)))
4151 if (TREE_CODE (memb_type) != POINTER_TYPE)
4154 if (coder == POINTER_TYPE)
4156 register tree ttl = TREE_TYPE (memb_type);
4157 register tree ttr = TREE_TYPE (rhstype);
4159 /* Any non-function converts to a [const][volatile] void *
4160 and vice versa; otherwise, targets must be the same.
4161 Meanwhile, the lhs target must have all the qualifiers of
4163 if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr)
4164 || comp_target_types (memb_type, rhstype))
4166 /* If this type won't generate any warnings, use it. */
4167 if (TYPE_QUALS (ttl) == TYPE_QUALS (ttr)
4168 || ((TREE_CODE (ttr) == FUNCTION_TYPE
4169 && TREE_CODE (ttl) == FUNCTION_TYPE)
4170 ? ((TYPE_QUALS (ttl) | TYPE_QUALS (ttr))
4171 == TYPE_QUALS (ttr))
4172 : ((TYPE_QUALS (ttl) | TYPE_QUALS (ttr))
4173 == TYPE_QUALS (ttl))))
4176 /* Keep looking for a better type, but remember this one. */
4177 if (! marginal_memb_type)
4178 marginal_memb_type = memb_type;
4182 /* Can convert integer zero to any pointer type. */
4183 if (integer_zerop (rhs)
4184 || (TREE_CODE (rhs) == NOP_EXPR
4185 && integer_zerop (TREE_OPERAND (rhs, 0))))
4187 rhs = null_pointer_node;
4192 if (memb_types || marginal_memb_type)
4196 /* We have only a marginally acceptable member type;
4197 it needs a warning. */
4198 register tree ttl = TREE_TYPE (marginal_memb_type);
4199 register tree ttr = TREE_TYPE (rhstype);
4201 /* Const and volatile mean something different for function
4202 types, so the usual warnings are not appropriate. */
4203 if (TREE_CODE (ttr) == FUNCTION_TYPE
4204 && TREE_CODE (ttl) == FUNCTION_TYPE)
4206 /* Because const and volatile on functions are
4207 restrictions that say the function will not do
4208 certain things, it is okay to use a const or volatile
4209 function where an ordinary one is wanted, but not
4211 if (TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr))
4212 warn_for_assignment ("%s makes qualified function pointer from unqualified",
4213 errtype, funname, parmnum);
4215 else if (TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl))
4216 warn_for_assignment ("%s discards qualifiers from pointer target type",
4221 if (pedantic && ! DECL_IN_SYSTEM_HEADER (fundecl))
4222 pedwarn ("ISO C prohibits argument conversion to union type");
4224 return build1 (NOP_EXPR, type, rhs);
4228 /* Conversions among pointers */
4229 else if ((codel == POINTER_TYPE || codel == REFERENCE_TYPE)
4230 && (coder == POINTER_TYPE || coder == REFERENCE_TYPE))
4232 register tree ttl = TREE_TYPE (type);
4233 register tree ttr = TREE_TYPE (rhstype);
4235 /* Any non-function converts to a [const][volatile] void *
4236 and vice versa; otherwise, targets must be the same.
4237 Meanwhile, the lhs target must have all the qualifiers of the rhs. */
4238 if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr)
4239 || comp_target_types (type, rhstype)
4240 || (unsigned_type (TYPE_MAIN_VARIANT (ttl))
4241 == unsigned_type (TYPE_MAIN_VARIANT (ttr))))
4244 && ((VOID_TYPE_P (ttl) && TREE_CODE (ttr) == FUNCTION_TYPE)
4247 /* Check TREE_CODE to catch cases like (void *) (char *) 0
4248 which are not ANSI null ptr constants. */
4249 && (!integer_zerop (rhs) || TREE_CODE (rhs) == NOP_EXPR)
4250 && TREE_CODE (ttl) == FUNCTION_TYPE)))
4251 warn_for_assignment ("ISO C forbids %s between function pointer and `void *'",
4252 errtype, funname, parmnum);
4253 /* Const and volatile mean something different for function types,
4254 so the usual warnings are not appropriate. */
4255 else if (TREE_CODE (ttr) != FUNCTION_TYPE
4256 && TREE_CODE (ttl) != FUNCTION_TYPE)
4258 if (TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl))
4259 warn_for_assignment ("%s discards qualifiers from pointer target type",
4260 errtype, funname, parmnum);
4261 /* If this is not a case of ignoring a mismatch in signedness,
4263 else if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr)
4264 || comp_target_types (type, rhstype))
4266 /* If there is a mismatch, do warn. */
4268 warn_for_assignment ("pointer targets in %s differ in signedness",
4269 errtype, funname, parmnum);
4271 else if (TREE_CODE (ttl) == FUNCTION_TYPE
4272 && TREE_CODE (ttr) == FUNCTION_TYPE)
4274 /* Because const and volatile on functions are restrictions
4275 that say the function will not do certain things,
4276 it is okay to use a const or volatile function
4277 where an ordinary one is wanted, but not vice-versa. */
4278 if (TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr))
4279 warn_for_assignment ("%s makes qualified function pointer from unqualified",
4280 errtype, funname, parmnum);
4284 warn_for_assignment ("%s from incompatible pointer type",
4285 errtype, funname, parmnum);
4286 return convert (type, rhs);
4288 else if (codel == POINTER_TYPE && coder == INTEGER_TYPE)
4290 /* An explicit constant 0 can convert to a pointer,
4291 or one that results from arithmetic, even including
4292 a cast to integer type. */
4293 if (! (TREE_CODE (rhs) == INTEGER_CST && integer_zerop (rhs))
4295 ! (TREE_CODE (rhs) == NOP_EXPR
4296 && TREE_CODE (TREE_TYPE (rhs)) == INTEGER_TYPE
4297 && TREE_CODE (TREE_OPERAND (rhs, 0)) == INTEGER_CST
4298 && integer_zerop (TREE_OPERAND (rhs, 0))))
4300 warn_for_assignment ("%s makes pointer from integer without a cast",
4301 errtype, funname, parmnum);
4302 return convert (type, rhs);
4304 return null_pointer_node;
4306 else if (codel == INTEGER_TYPE && coder == POINTER_TYPE)
4308 warn_for_assignment ("%s makes integer from pointer without a cast",
4309 errtype, funname, parmnum);
4310 return convert (type, rhs);
4312 else if (codel == BOOLEAN_TYPE && coder == POINTER_TYPE)
4313 return convert (type, rhs);
4319 tree selector = maybe_building_objc_message_expr ();
4321 if (selector && parmnum > 2)
4322 error ("incompatible type for argument %d of `%s'",
4323 parmnum - 2, IDENTIFIER_POINTER (selector));
4325 error ("incompatible type for argument %d of `%s'",
4326 parmnum, IDENTIFIER_POINTER (funname));
4329 error ("incompatible type for argument %d of indirect function call",
4333 error ("incompatible types in %s", errtype);
4335 return error_mark_node;
4338 /* Print a warning using MSGID.
4339 It gets OPNAME as its one parameter.
4340 If OPNAME is null, it is replaced by "passing arg ARGNUM of `FUNCTION'".
4341 FUNCTION and ARGNUM are handled specially if we are building an
4342 Objective-C selector. */
4345 warn_for_assignment (msgid, opname, function, argnum)
4353 tree selector = maybe_building_objc_message_expr ();
4356 if (selector && argnum > 2)
4358 function = selector;
4363 /* Function name is known; supply it. */
4364 const char *argstring = _("passing arg %d of `%s'");
4365 new_opname = (char *) alloca (IDENTIFIER_LENGTH (function)
4366 + strlen (argstring) + 1 + 25
4368 sprintf (new_opname, argstring, argnum,
4369 IDENTIFIER_POINTER (function));
4373 /* Function name unknown (call through ptr); just give arg number.*/
4374 const char *argnofun = _("passing arg %d of pointer to function");
4375 new_opname = (char *) alloca (strlen (argnofun) + 1 + 25 /*%d*/ + 1);
4376 sprintf (new_opname, argnofun, argnum);
4378 opname = new_opname;
4380 pedwarn (msgid, opname);
4383 /* If VALUE is a compound expr all of whose expressions are constant, then
4384 return its value. Otherwise, return error_mark_node.
4386 This is for handling COMPOUND_EXPRs as initializer elements
4387 which is allowed with a warning when -pedantic is specified. */
4390 valid_compound_expr_initializer (value, endtype)
4394 if (TREE_CODE (value) == COMPOUND_EXPR)
4396 if (valid_compound_expr_initializer (TREE_OPERAND (value, 0), endtype)
4398 return error_mark_node;
4399 return valid_compound_expr_initializer (TREE_OPERAND (value, 1),
4402 else if (! TREE_CONSTANT (value)
4403 && ! initializer_constant_valid_p (value, endtype))
4404 return error_mark_node;
4409 /* Perform appropriate conversions on the initial value of a variable,
4410 store it in the declaration DECL,
4411 and print any error messages that are appropriate.
4412 If the init is invalid, store an ERROR_MARK. */
4415 store_init_value (decl, init)
4418 register tree value, type;
4420 /* If variable's type was invalidly declared, just ignore it. */
4422 type = TREE_TYPE (decl);
4423 if (TREE_CODE (type) == ERROR_MARK)
4426 /* Digest the specified initializer into an expression. */
4428 value = digest_init (type, init, TREE_STATIC (decl),
4429 TREE_STATIC (decl) || (pedantic && !flag_isoc99));
4431 /* Store the expression if valid; else report error. */
4434 /* Note that this is the only place we can detect the error
4435 in a case such as struct foo bar = (struct foo) { x, y };
4436 where there is one initial value which is a constructor expression. */
4437 if (value == error_mark_node)
4439 else if (TREE_STATIC (decl) && ! TREE_CONSTANT (value))
4441 error ("initializer for static variable is not constant");
4442 value = error_mark_node;
4444 else if (TREE_STATIC (decl)
4445 && initializer_constant_valid_p (value, TREE_TYPE (value)) == 0)
4447 error ("initializer for static variable uses complicated arithmetic");
4448 value = error_mark_node;
4452 if (pedantic && TREE_CODE (value) == CONSTRUCTOR)
4454 if (! TREE_CONSTANT (value))
4455 pedwarn ("aggregate initializer is not constant");
4456 else if (! TREE_STATIC (value))
4457 pedwarn ("aggregate initializer uses complicated arithmetic");
4462 if (warn_traditional && !in_system_header
4463 && AGGREGATE_TYPE_P (TREE_TYPE (decl)) && ! TREE_STATIC (decl))
4464 warning ("traditional C rejects automatic aggregate initialization");
4466 DECL_INITIAL (decl) = value;
4468 /* ANSI wants warnings about out-of-range constant initializers. */
4469 STRIP_TYPE_NOPS (value);
4470 constant_expression_warning (value);
4473 /* Methods for storing and printing names for error messages. */
4475 /* Implement a spelling stack that allows components of a name to be pushed
4476 and popped. Each element on the stack is this structure. */
4488 #define SPELLING_STRING 1
4489 #define SPELLING_MEMBER 2
4490 #define SPELLING_BOUNDS 3
4492 static struct spelling *spelling; /* Next stack element (unused). */
4493 static struct spelling *spelling_base; /* Spelling stack base. */
4494 static int spelling_size; /* Size of the spelling stack. */
4496 /* Macros to save and restore the spelling stack around push_... functions.
4497 Alternative to SAVE_SPELLING_STACK. */
4499 #define SPELLING_DEPTH() (spelling - spelling_base)
4500 #define RESTORE_SPELLING_DEPTH(depth) (spelling = spelling_base + depth)
4502 /* Save and restore the spelling stack around arbitrary C code. */
4504 #define SAVE_SPELLING_DEPTH(code) \
4506 int __depth = SPELLING_DEPTH (); \
4508 RESTORE_SPELLING_DEPTH (__depth); \
4511 /* Push an element on the spelling stack with type KIND and assign VALUE
4514 #define PUSH_SPELLING(KIND, VALUE, MEMBER) \
4516 int depth = SPELLING_DEPTH (); \
4518 if (depth >= spelling_size) \
4520 spelling_size += 10; \
4521 if (spelling_base == 0) \
4523 = (struct spelling *) xmalloc (spelling_size * sizeof (struct spelling)); \
4526 = (struct spelling *) xrealloc (spelling_base, \
4527 spelling_size * sizeof (struct spelling)); \
4528 RESTORE_SPELLING_DEPTH (depth); \
4531 spelling->kind = (KIND); \
4532 spelling->MEMBER = (VALUE); \
4536 /* Push STRING on the stack. Printed literally. */
4539 push_string (string)
4542 PUSH_SPELLING (SPELLING_STRING, string, u.s);
4545 /* Push a member name on the stack. Printed as '.' STRING. */
4548 push_member_name (decl)
4553 = DECL_NAME (decl) ? IDENTIFIER_POINTER (DECL_NAME (decl)) : "<anonymous>";
4554 PUSH_SPELLING (SPELLING_MEMBER, string, u.s);
4557 /* Push an array bounds on the stack. Printed as [BOUNDS]. */
4560 push_array_bounds (bounds)
4563 PUSH_SPELLING (SPELLING_BOUNDS, bounds, u.i);
4566 /* Compute the maximum size in bytes of the printed spelling. */
4571 register int size = 0;
4572 register struct spelling *p;
4574 for (p = spelling_base; p < spelling; p++)
4576 if (p->kind == SPELLING_BOUNDS)
4579 size += strlen (p->u.s) + 1;
4585 /* Print the spelling to BUFFER and return it. */
4588 print_spelling (buffer)
4589 register char *buffer;
4591 register char *d = buffer;
4592 register struct spelling *p;
4594 for (p = spelling_base; p < spelling; p++)
4595 if (p->kind == SPELLING_BOUNDS)
4597 sprintf (d, "[%d]", p->u.i);
4602 register const char *s;
4603 if (p->kind == SPELLING_MEMBER)
4605 for (s = p->u.s; (*d = *s++); d++)
4612 /* Issue an error message for a bad initializer component.
4613 MSGID identifies the message.
4614 The component name is taken from the spelling stack. */
4622 error ("%s", msgid);
4623 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
4625 error ("(near initialization for `%s')", ofwhat);
4628 /* Issue a pedantic warning for a bad initializer component.
4629 MSGID identifies the message.
4630 The component name is taken from the spelling stack. */
4633 pedwarn_init (msgid)
4638 pedwarn ("%s", msgid);
4639 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
4641 pedwarn ("(near initialization for `%s')", ofwhat);
4644 /* Issue a warning for a bad initializer component.
4645 MSGID identifies the message.
4646 The component name is taken from the spelling stack. */
4649 warning_init (msgid)
4654 warning ("%s", msgid);
4655 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
4657 warning ("(near initialization for `%s')", ofwhat);
4660 /* Digest the parser output INIT as an initializer for type TYPE.
4661 Return a C expression of type TYPE to represent the initial value.
4663 The arguments REQUIRE_CONSTANT and CONSTRUCTOR_CONSTANT request errors
4664 if non-constant initializers or elements are seen. CONSTRUCTOR_CONSTANT
4665 applies only to elements of constructors. */
4668 digest_init (type, init, require_constant, constructor_constant)
4670 int require_constant, constructor_constant;
4672 enum tree_code code = TREE_CODE (type);
4673 tree inside_init = init;
4675 if (type == error_mark_node
4676 || init == error_mark_node
4677 || TREE_TYPE (init) == error_mark_node)
4678 return error_mark_node;
4680 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
4681 /* Do not use STRIP_NOPS here. We do not want an enumerator
4682 whose value is 0 to count as a null pointer constant. */
4683 if (TREE_CODE (init) == NON_LVALUE_EXPR)
4684 inside_init = TREE_OPERAND (init, 0);
4686 inside_init = fold (inside_init);
4688 /* Initialization of an array of chars from a string constant
4689 optionally enclosed in braces. */
4691 if (code == ARRAY_TYPE)
4693 tree typ1 = TYPE_MAIN_VARIANT (TREE_TYPE (type));
4694 if ((typ1 == char_type_node
4695 || typ1 == signed_char_type_node
4696 || typ1 == unsigned_char_type_node
4697 || typ1 == unsigned_wchar_type_node
4698 || typ1 == signed_wchar_type_node)
4699 && ((inside_init && TREE_CODE (inside_init) == STRING_CST)))
4701 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
4702 TYPE_MAIN_VARIANT (type)))
4705 if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init)))
4707 && TYPE_PRECISION (typ1) == TYPE_PRECISION (char_type_node))
4709 error_init ("char-array initialized from wide string");
4710 return error_mark_node;
4712 if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init)))
4714 && TYPE_PRECISION (typ1) != TYPE_PRECISION (char_type_node))
4716 error_init ("int-array initialized from non-wide string");
4717 return error_mark_node;
4720 TREE_TYPE (inside_init) = type;
4721 if (TYPE_DOMAIN (type) != 0
4722 && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
4723 /* Subtract 1 (or sizeof (wchar_t))
4724 because it's ok to ignore the terminating null char
4725 that is counted in the length of the constant. */
4726 && 0 > compare_tree_int (TYPE_SIZE_UNIT (type),
4727 TREE_STRING_LENGTH (inside_init)
4728 - ((TYPE_PRECISION (typ1)
4729 != TYPE_PRECISION (char_type_node))
4730 ? (TYPE_PRECISION (wchar_type_node)
4733 pedwarn_init ("initializer-string for array of chars is too long");
4739 /* Any type can be initialized
4740 from an expression of the same type, optionally with braces. */
4742 if (inside_init && TREE_TYPE (inside_init) != 0
4743 && (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
4744 TYPE_MAIN_VARIANT (type))
4745 || (code == ARRAY_TYPE
4746 && comptypes (TREE_TYPE (inside_init), type))
4747 || (code == POINTER_TYPE
4748 && (TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE
4749 || TREE_CODE (TREE_TYPE (inside_init)) == FUNCTION_TYPE)
4750 && comptypes (TREE_TYPE (TREE_TYPE (inside_init)),
4751 TREE_TYPE (type)))))
4753 if (code == POINTER_TYPE
4754 && (TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE
4755 || TREE_CODE (TREE_TYPE (inside_init)) == FUNCTION_TYPE))
4756 inside_init = default_conversion (inside_init);
4757 else if (code == ARRAY_TYPE && TREE_CODE (inside_init) != STRING_CST
4758 && TREE_CODE (inside_init) != CONSTRUCTOR)
4760 error_init ("array initialized from non-constant array expression");
4761 return error_mark_node;
4764 if (optimize && TREE_CODE (inside_init) == VAR_DECL)
4765 inside_init = decl_constant_value_for_broken_optimization (inside_init);
4767 /* Compound expressions can only occur here if -pedantic or
4768 -pedantic-errors is specified. In the later case, we always want
4769 an error. In the former case, we simply want a warning. */
4770 if (require_constant && pedantic
4771 && TREE_CODE (inside_init) == COMPOUND_EXPR)
4774 = valid_compound_expr_initializer (inside_init,
4775 TREE_TYPE (inside_init));
4776 if (inside_init == error_mark_node)
4777 error_init ("initializer element is not constant");
4779 pedwarn_init ("initializer element is not constant");
4780 if (flag_pedantic_errors)
4781 inside_init = error_mark_node;
4783 else if (require_constant && ! TREE_CONSTANT (inside_init))
4785 error_init ("initializer element is not constant");
4786 inside_init = error_mark_node;
4788 else if (require_constant
4789 && initializer_constant_valid_p (inside_init, TREE_TYPE (inside_init)) == 0)
4790 pedwarn ("initializer element is not computable at load time");
4795 /* Handle scalar types, including conversions. */
4797 if (code == INTEGER_TYPE || code == REAL_TYPE || code == POINTER_TYPE
4798 || code == ENUMERAL_TYPE || code == BOOLEAN_TYPE || code == COMPLEX_TYPE)
4800 /* Note that convert_for_assignment calls default_conversion
4801 for arrays and functions. We must not call it in the
4802 case where inside_init is a null pointer constant. */
4804 = convert_for_assignment (type, init, _("initialization"),
4805 NULL_TREE, NULL_TREE, 0);
4807 if (require_constant && ! TREE_CONSTANT (inside_init))
4809 error_init ("initializer element is not constant");
4810 inside_init = error_mark_node;
4812 else if (require_constant
4813 && initializer_constant_valid_p (inside_init, TREE_TYPE (inside_init)) == 0)
4815 error_init ("initializer element is not computable at load time");
4816 inside_init = error_mark_node;
4822 /* Come here only for records and arrays. */
4824 if (COMPLETE_TYPE_P (type) && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
4826 error_init ("variable-sized object may not be initialized");
4827 return error_mark_node;
4830 /* Traditionally, you can write struct foo x = 0;
4831 and it initializes the first element of x to 0. */
4832 if (flag_traditional)
4834 tree top = 0, prev = 0, otype = type;
4835 while (TREE_CODE (type) == RECORD_TYPE
4836 || TREE_CODE (type) == ARRAY_TYPE
4837 || TREE_CODE (type) == QUAL_UNION_TYPE
4838 || TREE_CODE (type) == UNION_TYPE)
4840 tree temp = build (CONSTRUCTOR, type, NULL_TREE, NULL_TREE);
4844 TREE_OPERAND (prev, 1) = build_tree_list (NULL_TREE, temp);
4846 if (TREE_CODE (type) == ARRAY_TYPE)
4847 type = TREE_TYPE (type);
4848 else if (TYPE_FIELDS (type))
4849 type = TREE_TYPE (TYPE_FIELDS (type));
4852 error_init ("invalid initializer");
4853 return error_mark_node;
4859 TREE_OPERAND (prev, 1)
4860 = build_tree_list (NULL_TREE,
4861 digest_init (type, init, require_constant,
4862 constructor_constant));
4866 return error_mark_node;
4868 error_init ("invalid initializer");
4869 return error_mark_node;
4872 /* Handle initializers that use braces. */
4874 /* Type of object we are accumulating a constructor for.
4875 This type is always a RECORD_TYPE, UNION_TYPE or ARRAY_TYPE. */
4876 static tree constructor_type;
4878 /* For a RECORD_TYPE or UNION_TYPE, this is the chain of fields
4880 static tree constructor_fields;
4882 /* For an ARRAY_TYPE, this is the specified index
4883 at which to store the next element we get. */
4884 static tree constructor_index;
4886 /* For an ARRAY_TYPE, this is the maximum index. */
4887 static tree constructor_max_index;
4889 /* For a RECORD_TYPE, this is the first field not yet written out. */
4890 static tree constructor_unfilled_fields;
4892 /* For an ARRAY_TYPE, this is the index of the first element
4893 not yet written out. */
4894 static tree constructor_unfilled_index;
4896 /* In a RECORD_TYPE, the byte index of the next consecutive field.
4897 This is so we can generate gaps between fields, when appropriate. */
4898 static tree constructor_bit_index;
4900 /* If we are saving up the elements rather than allocating them,
4901 this is the list of elements so far (in reverse order,
4902 most recent first). */
4903 static tree constructor_elements;
4905 /* 1 if constructor should be incrementally stored into a constructor chain,
4906 0 if all the elements should be kept in AVL tree. */
4907 static int constructor_incremental;
4909 /* 1 if so far this constructor's elements are all compile-time constants. */
4910 static int constructor_constant;
4912 /* 1 if so far this constructor's elements are all valid address constants. */
4913 static int constructor_simple;
4915 /* 1 if this constructor is erroneous so far. */
4916 static int constructor_erroneous;
4918 /* 1 if have called defer_addressed_constants. */
4919 static int constructor_subconstants_deferred;
4921 /* Structure for managing pending initializer elements, organized as an
4926 struct init_node *left, *right;
4927 struct init_node *parent;
4933 /* Tree of pending elements at this constructor level.
4934 These are elements encountered out of order
4935 which belong at places we haven't reached yet in actually
4937 Will never hold tree nodes across GC runs. */
4938 static struct init_node *constructor_pending_elts;
4940 /* The SPELLING_DEPTH of this constructor. */
4941 static int constructor_depth;
4943 /* 0 if implicitly pushing constructor levels is allowed. */
4944 int constructor_no_implicit = 0; /* 0 for C; 1 for some other languages. */
4946 static int require_constant_value;
4947 static int require_constant_elements;
4949 /* DECL node for which an initializer is being read.
4950 0 means we are reading a constructor expression
4951 such as (struct foo) {...}. */
4952 static tree constructor_decl;
4954 /* start_init saves the ASMSPEC arg here for really_start_incremental_init. */
4955 static const char *constructor_asmspec;
4957 /* Nonzero if this is an initializer for a top-level decl. */
4958 static int constructor_top_level;
4960 /* Nesting depth of designator list. */
4961 static int designator_depth;
4963 /* Nonzero if there were diagnosed errors in this designator list. */
4964 static int designator_errorneous;
4967 /* This stack has a level for each implicit or explicit level of
4968 structuring in the initializer, including the outermost one. It
4969 saves the values of most of the variables above. */
4971 struct constructor_range_stack;
4973 struct constructor_stack
4975 struct constructor_stack *next;
4980 tree unfilled_index;
4981 tree unfilled_fields;
4984 struct init_node *pending_elts;
4987 /* If nonzero, this value should replace the entire
4988 constructor at this level. */
4989 tree replacement_value;
4990 struct constructor_range_stack *range_stack;
4999 struct constructor_stack *constructor_stack;
5001 /* This stack represents designators from some range designator up to
5002 the last designator in the list. */
5004 struct constructor_range_stack
5006 struct constructor_range_stack *next, *prev;
5007 struct constructor_stack *stack;
5014 struct constructor_range_stack *constructor_range_stack;
5016 /* This stack records separate initializers that are nested.
5017 Nested initializers can't happen in ANSI C, but GNU C allows them
5018 in cases like { ... (struct foo) { ... } ... }. */
5020 struct initializer_stack
5022 struct initializer_stack *next;
5024 const char *asmspec;
5025 struct constructor_stack *constructor_stack;
5026 struct constructor_range_stack *constructor_range_stack;
5028 struct spelling *spelling;
5029 struct spelling *spelling_base;
5032 char require_constant_value;
5033 char require_constant_elements;
5037 struct initializer_stack *initializer_stack;
5039 /* Prepare to parse and output the initializer for variable DECL. */
5042 start_init (decl, asmspec_tree, top_level)
5048 struct initializer_stack *p
5049 = (struct initializer_stack *) xmalloc (sizeof (struct initializer_stack));
5050 const char *asmspec = 0;
5053 asmspec = TREE_STRING_POINTER (asmspec_tree);
5055 p->decl = constructor_decl;
5056 p->asmspec = constructor_asmspec;
5057 p->require_constant_value = require_constant_value;
5058 p->require_constant_elements = require_constant_elements;
5059 p->constructor_stack = constructor_stack;
5060 p->constructor_range_stack = constructor_range_stack;
5061 p->elements = constructor_elements;
5062 p->spelling = spelling;
5063 p->spelling_base = spelling_base;
5064 p->spelling_size = spelling_size;
5065 p->deferred = constructor_subconstants_deferred;
5066 p->top_level = constructor_top_level;
5067 p->next = initializer_stack;
5068 initializer_stack = p;
5070 constructor_decl = decl;
5071 constructor_asmspec = asmspec;
5072 constructor_subconstants_deferred = 0;
5073 constructor_top_level = top_level;
5077 require_constant_value = TREE_STATIC (decl);
5078 require_constant_elements
5079 = ((TREE_STATIC (decl) || (pedantic && !flag_isoc99))
5080 /* For a scalar, you can always use any value to initialize,
5081 even within braces. */
5082 && (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
5083 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
5084 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
5085 || TREE_CODE (TREE_TYPE (decl)) == QUAL_UNION_TYPE));
5086 locus = IDENTIFIER_POINTER (DECL_NAME (decl));
5090 require_constant_value = 0;
5091 require_constant_elements = 0;
5092 locus = "(anonymous)";
5095 constructor_stack = 0;
5096 constructor_range_stack = 0;
5098 missing_braces_mentioned = 0;
5102 RESTORE_SPELLING_DEPTH (0);
5105 push_string (locus);
5111 struct initializer_stack *p = initializer_stack;
5113 /* Output subconstants (string constants, usually)
5114 that were referenced within this initializer and saved up.
5115 Must do this if and only if we called defer_addressed_constants. */
5116 if (constructor_subconstants_deferred)
5117 output_deferred_addressed_constants ();
5119 /* Free the whole constructor stack of this initializer. */
5120 while (constructor_stack)
5122 struct constructor_stack *q = constructor_stack;
5123 constructor_stack = q->next;
5127 if (constructor_range_stack)
5130 /* Pop back to the data of the outer initializer (if any). */
5131 constructor_decl = p->decl;
5132 constructor_asmspec = p->asmspec;
5133 require_constant_value = p->require_constant_value;
5134 require_constant_elements = p->require_constant_elements;
5135 constructor_stack = p->constructor_stack;
5136 constructor_range_stack = p->constructor_range_stack;
5137 constructor_elements = p->elements;
5138 spelling = p->spelling;
5139 spelling_base = p->spelling_base;
5140 spelling_size = p->spelling_size;
5141 constructor_subconstants_deferred = p->deferred;
5142 constructor_top_level = p->top_level;
5143 initializer_stack = p->next;
5147 /* Call here when we see the initializer is surrounded by braces.
5148 This is instead of a call to push_init_level;
5149 it is matched by a call to pop_init_level.
5151 TYPE is the type to initialize, for a constructor expression.
5152 For an initializer for a decl, TYPE is zero. */
5155 really_start_incremental_init (type)
5158 struct constructor_stack *p
5159 = (struct constructor_stack *) xmalloc (sizeof (struct constructor_stack));
5162 type = TREE_TYPE (constructor_decl);
5164 p->type = constructor_type;
5165 p->fields = constructor_fields;
5166 p->index = constructor_index;
5167 p->max_index = constructor_max_index;
5168 p->unfilled_index = constructor_unfilled_index;
5169 p->unfilled_fields = constructor_unfilled_fields;
5170 p->bit_index = constructor_bit_index;
5171 p->elements = constructor_elements;
5172 p->constant = constructor_constant;
5173 p->simple = constructor_simple;
5174 p->erroneous = constructor_erroneous;
5175 p->pending_elts = constructor_pending_elts;
5176 p->depth = constructor_depth;
5177 p->replacement_value = 0;
5181 p->incremental = constructor_incremental;
5183 constructor_stack = p;
5185 constructor_constant = 1;
5186 constructor_simple = 1;
5187 constructor_depth = SPELLING_DEPTH ();
5188 constructor_elements = 0;
5189 constructor_pending_elts = 0;
5190 constructor_type = type;
5191 constructor_incremental = 1;
5192 designator_depth = 0;
5193 designator_errorneous = 0;
5195 if (TREE_CODE (constructor_type) == RECORD_TYPE
5196 || TREE_CODE (constructor_type) == UNION_TYPE)
5198 constructor_fields = TYPE_FIELDS (constructor_type);
5199 /* Skip any nameless bit fields at the beginning. */
5200 while (constructor_fields != 0 && DECL_C_BIT_FIELD (constructor_fields)
5201 && DECL_NAME (constructor_fields) == 0)
5202 constructor_fields = TREE_CHAIN (constructor_fields);
5204 constructor_unfilled_fields = constructor_fields;
5205 constructor_bit_index = bitsize_zero_node;
5207 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5209 if (TYPE_DOMAIN (constructor_type))
5211 constructor_max_index
5212 = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
5214 /* Detect non-empty initializations of zero-length arrays. */
5215 if (constructor_max_index == NULL_TREE)
5216 constructor_max_index = build_int_2 (-1, -1);
5219 = convert (bitsizetype,
5220 TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
5223 constructor_index = bitsize_zero_node;
5225 constructor_unfilled_index = constructor_index;
5229 /* Handle the case of int x = {5}; */
5230 constructor_fields = constructor_type;
5231 constructor_unfilled_fields = constructor_type;
5235 /* Push down into a subobject, for initialization.
5236 If this is for an explicit set of braces, IMPLICIT is 0.
5237 If it is because the next element belongs at a lower level,
5238 IMPLICIT is 1 (or 2 if the push is because of designator list). */
5241 push_init_level (implicit)
5244 struct constructor_stack *p;
5245 tree value = NULL_TREE;
5247 /* If we've exhausted any levels that didn't have braces,
5249 while (constructor_stack->implicit)
5251 if ((TREE_CODE (constructor_type) == RECORD_TYPE
5252 || TREE_CODE (constructor_type) == UNION_TYPE)
5253 && constructor_fields == 0)
5254 process_init_element (pop_init_level (1));
5255 else if (TREE_CODE (constructor_type) == ARRAY_TYPE
5256 && tree_int_cst_lt (constructor_max_index, constructor_index))
5257 process_init_element (pop_init_level (1));
5262 /* Unless this is an explicit brace, we need to preserve previous
5266 if ((TREE_CODE (constructor_type) == RECORD_TYPE
5267 || TREE_CODE (constructor_type) == UNION_TYPE)
5268 && constructor_fields)
5269 value = find_init_member (constructor_fields);
5270 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5271 value = find_init_member (constructor_index);
5274 p = (struct constructor_stack *) xmalloc (sizeof (struct constructor_stack));
5275 p->type = constructor_type;
5276 p->fields = constructor_fields;
5277 p->index = constructor_index;
5278 p->max_index = constructor_max_index;
5279 p->unfilled_index = constructor_unfilled_index;
5280 p->unfilled_fields = constructor_unfilled_fields;
5281 p->bit_index = constructor_bit_index;
5282 p->elements = constructor_elements;
5283 p->constant = constructor_constant;
5284 p->simple = constructor_simple;
5285 p->erroneous = constructor_erroneous;
5286 p->pending_elts = constructor_pending_elts;
5287 p->depth = constructor_depth;
5288 p->replacement_value = 0;
5289 p->implicit = implicit;
5291 p->incremental = constructor_incremental;
5292 p->next = constructor_stack;
5294 constructor_stack = p;
5296 constructor_constant = 1;
5297 constructor_simple = 1;
5298 constructor_depth = SPELLING_DEPTH ();
5299 constructor_elements = 0;
5300 constructor_incremental = 1;
5301 constructor_pending_elts = 0;
5304 p->range_stack = constructor_range_stack;
5305 constructor_range_stack = 0;
5306 designator_depth = 0;
5307 designator_errorneous = 0;
5310 /* Don't die if an entire brace-pair level is superfluous
5311 in the containing level. */
5312 if (constructor_type == 0)
5314 else if (TREE_CODE (constructor_type) == RECORD_TYPE
5315 || TREE_CODE (constructor_type) == UNION_TYPE)
5317 /* Don't die if there are extra init elts at the end. */
5318 if (constructor_fields == 0)
5319 constructor_type = 0;
5322 constructor_type = TREE_TYPE (constructor_fields);
5323 push_member_name (constructor_fields);
5324 constructor_depth++;
5327 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5329 constructor_type = TREE_TYPE (constructor_type);
5330 push_array_bounds (tree_low_cst (constructor_index, 0));
5331 constructor_depth++;
5334 if (constructor_type == 0)
5336 error_init ("extra brace group at end of initializer");
5337 constructor_fields = 0;
5338 constructor_unfilled_fields = 0;
5342 if (value && TREE_CODE (value) == CONSTRUCTOR)
5344 constructor_constant = TREE_CONSTANT (value);
5345 constructor_simple = TREE_STATIC (value);
5346 constructor_elements = TREE_OPERAND (value, 1);
5347 if (constructor_elements
5348 && (TREE_CODE (constructor_type) == RECORD_TYPE
5349 || TREE_CODE (constructor_type) == ARRAY_TYPE))
5350 set_nonincremental_init ();
5353 if (implicit == 1 && warn_missing_braces && !missing_braces_mentioned)
5355 missing_braces_mentioned = 1;
5356 warning_init ("missing braces around initializer");
5359 if (TREE_CODE (constructor_type) == RECORD_TYPE
5360 || TREE_CODE (constructor_type) == UNION_TYPE)
5362 constructor_fields = TYPE_FIELDS (constructor_type);
5363 /* Skip any nameless bit fields at the beginning. */
5364 while (constructor_fields != 0 && DECL_C_BIT_FIELD (constructor_fields)
5365 && DECL_NAME (constructor_fields) == 0)
5366 constructor_fields = TREE_CHAIN (constructor_fields);
5368 constructor_unfilled_fields = constructor_fields;
5369 constructor_bit_index = bitsize_zero_node;
5371 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5373 if (TYPE_DOMAIN (constructor_type))
5375 constructor_max_index
5376 = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
5378 = convert (bitsizetype,
5379 TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
5381 /* ??? For GCC 3.1, remove special case initialization of
5382 zero-length array members from pop_init_level and set
5383 constructor_max_index such that we get the normal
5384 "excess elements" warning. */
5387 constructor_index = bitsize_zero_node;
5389 constructor_unfilled_index = constructor_index;
5390 if (value && TREE_CODE (value) == STRING_CST)
5392 /* We need to split the char/wchar array into individual
5393 characters, so that we don't have to special case it
5395 set_nonincremental_init_from_string (value);
5400 warning_init ("braces around scalar initializer");
5401 constructor_fields = constructor_type;
5402 constructor_unfilled_fields = constructor_type;
5406 /* At the end of an implicit or explicit brace level,
5407 finish up that level of constructor.
5408 If we were outputting the elements as they are read, return 0
5409 from inner levels (process_init_element ignores that),
5410 but return error_mark_node from the outermost level
5411 (that's what we want to put in DECL_INITIAL).
5412 Otherwise, return a CONSTRUCTOR expression. */
5415 pop_init_level (implicit)
5418 struct constructor_stack *p;
5419 HOST_WIDE_INT size = 0;
5420 tree constructor = 0;
5424 /* When we come to an explicit close brace,
5425 pop any inner levels that didn't have explicit braces. */
5426 while (constructor_stack->implicit)
5427 process_init_element (pop_init_level (1));
5429 if (constructor_range_stack)
5433 p = constructor_stack;
5435 if (constructor_type != 0)
5436 size = int_size_in_bytes (constructor_type);
5438 /* Error for initializing a flexible array member, or a zero-length
5439 array member in an inappropriate context. */
5440 if (constructor_type && constructor_fields
5441 && TREE_CODE (constructor_type) == ARRAY_TYPE
5442 && TYPE_DOMAIN (constructor_type)
5443 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type)))
5445 /* Silently discard empty initializations. The parser will
5446 already have pedwarned for empty brackets. */
5447 if (integer_zerop (constructor_unfilled_index))
5448 constructor_type = NULL_TREE;
5449 else if (! TYPE_SIZE (constructor_type))
5451 if (constructor_depth > 2)
5452 error_init ("initialization of flexible array member in a nested context");
5454 pedwarn_init ("initialization of a flexible array member");
5456 /* We have already issued an error message for the existance
5457 of a flexible array member not at the end of the structure.
5458 Discard the initializer so that we do not abort later. */
5459 if (TREE_CHAIN (constructor_fields) != NULL_TREE)
5460 constructor_type = NULL_TREE;
5464 warning_init ("deprecated initialization of zero-length array");
5466 /* We must be initializing the last member of a top-level struct. */
5467 if (TREE_CHAIN (constructor_fields) != NULL_TREE)
5469 error_init ("initialization of zero-length array before end of structure");
5470 /* Discard the initializer so that we do not abort later. */
5471 constructor_type = NULL_TREE;
5473 else if (constructor_depth > 2)
5474 error_init ("initialization of zero-length array inside a nested context");
5478 /* Warn when some struct elements are implicitly initialized to zero. */
5481 && TREE_CODE (constructor_type) == RECORD_TYPE
5482 && constructor_unfilled_fields)
5484 /* Do not warn for flexible array members or zero-length arrays. */
5485 while (constructor_unfilled_fields
5486 && (! DECL_SIZE (constructor_unfilled_fields)
5487 || integer_zerop (DECL_SIZE (constructor_unfilled_fields))))
5488 constructor_unfilled_fields = TREE_CHAIN (constructor_unfilled_fields);
5490 if (constructor_unfilled_fields)
5492 push_member_name (constructor_unfilled_fields);
5493 warning_init ("missing initializer");
5494 RESTORE_SPELLING_DEPTH (constructor_depth);
5498 /* Now output all pending elements. */
5499 constructor_incremental = 1;
5500 output_pending_init_elements (1);
5502 /* Pad out the end of the structure. */
5503 if (p->replacement_value)
5504 /* If this closes a superfluous brace pair,
5505 just pass out the element between them. */
5506 constructor = p->replacement_value;
5507 else if (constructor_type == 0)
5509 else if (TREE_CODE (constructor_type) != RECORD_TYPE
5510 && TREE_CODE (constructor_type) != UNION_TYPE
5511 && TREE_CODE (constructor_type) != ARRAY_TYPE)
5513 /* A nonincremental scalar initializer--just return
5514 the element, after verifying there is just one. */
5515 if (constructor_elements == 0)
5517 if (!constructor_erroneous)
5518 error_init ("empty scalar initializer");
5519 constructor = error_mark_node;
5521 else if (TREE_CHAIN (constructor_elements) != 0)
5523 error_init ("extra elements in scalar initializer");
5524 constructor = TREE_VALUE (constructor_elements);
5527 constructor = TREE_VALUE (constructor_elements);
5531 if (constructor_erroneous)
5532 constructor = error_mark_node;
5535 constructor = build (CONSTRUCTOR, constructor_type, NULL_TREE,
5536 nreverse (constructor_elements));
5537 if (constructor_constant)
5538 TREE_CONSTANT (constructor) = 1;
5539 if (constructor_constant && constructor_simple)
5540 TREE_STATIC (constructor) = 1;
5544 constructor_type = p->type;
5545 constructor_fields = p->fields;
5546 constructor_index = p->index;
5547 constructor_max_index = p->max_index;
5548 constructor_unfilled_index = p->unfilled_index;
5549 constructor_unfilled_fields = p->unfilled_fields;
5550 constructor_bit_index = p->bit_index;
5551 constructor_elements = p->elements;
5552 constructor_constant = p->constant;
5553 constructor_simple = p->simple;
5554 constructor_erroneous = p->erroneous;
5555 constructor_incremental = p->incremental;
5556 constructor_pending_elts = p->pending_elts;
5557 constructor_depth = p->depth;
5559 constructor_range_stack = p->range_stack;
5560 RESTORE_SPELLING_DEPTH (constructor_depth);
5562 constructor_stack = p->next;
5565 if (constructor == 0)
5567 if (constructor_stack == 0)
5568 return error_mark_node;
5574 /* Common handling for both array range and field name designators.
5575 ARRAY argument is non-zero for array ranges. Returns zero for success. */
5578 set_designator (array)
5582 enum tree_code subcode;
5584 /* Don't die if an entire brace-pair level is superfluous
5585 in the containing level. */
5586 if (constructor_type == 0)
5589 /* If there were errors in this designator list already, bail out silently. */
5590 if (designator_errorneous)
5593 if (!designator_depth)
5595 if (constructor_range_stack)
5598 /* Designator list starts at the level of closest explicit
5600 while (constructor_stack->implicit)
5601 process_init_element (pop_init_level (1));
5605 if (constructor_no_implicit)
5607 error_init ("initialization designators may not nest");
5611 if (TREE_CODE (constructor_type) == RECORD_TYPE
5612 || TREE_CODE (constructor_type) == UNION_TYPE)
5614 subtype = TREE_TYPE (constructor_fields);
5615 if (subtype != error_mark_node)
5616 subtype = TYPE_MAIN_VARIANT (subtype);
5618 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5620 subtype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
5625 subcode = TREE_CODE (subtype);
5626 if (array && subcode != ARRAY_TYPE)
5628 error_init ("array index in non-array initializer");
5631 else if (!array && subcode != RECORD_TYPE && subcode != UNION_TYPE)
5633 error_init ("field name not in record or union initializer");
5637 push_init_level (2);
5641 /* If there are range designators in designator list, push a new designator
5642 to constructor_range_stack. RANGE_END is end of such stack range or
5643 NULL_TREE if there is no range designator at this level. */
5646 push_range_stack (range_end)
5649 struct constructor_range_stack *p;
5651 p = (struct constructor_range_stack *)
5652 ggc_alloc (sizeof (struct constructor_range_stack));
5653 p->prev = constructor_range_stack;
5655 p->fields = constructor_fields;
5656 p->range_start = constructor_index;
5657 p->index = constructor_index;
5658 p->stack = constructor_stack;
5659 p->range_end = range_end;
5660 if (constructor_range_stack)
5661 constructor_range_stack->next = p;
5662 constructor_range_stack = p;
5665 /* Within an array initializer, specify the next index to be initialized.
5666 FIRST is that index. If LAST is nonzero, then initialize a range
5667 of indices, running from FIRST through LAST. */
5670 set_init_index (first, last)
5673 if (set_designator (1))
5676 designator_errorneous = 1;
5678 while ((TREE_CODE (first) == NOP_EXPR
5679 || TREE_CODE (first) == CONVERT_EXPR
5680 || TREE_CODE (first) == NON_LVALUE_EXPR)
5681 && (TYPE_MODE (TREE_TYPE (first))
5682 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (first, 0)))))
5683 first = TREE_OPERAND (first, 0);
5686 while ((TREE_CODE (last) == NOP_EXPR
5687 || TREE_CODE (last) == CONVERT_EXPR
5688 || TREE_CODE (last) == NON_LVALUE_EXPR)
5689 && (TYPE_MODE (TREE_TYPE (last))
5690 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (last, 0)))))
5691 last = TREE_OPERAND (last, 0);
5693 if (TREE_CODE (first) != INTEGER_CST)
5694 error_init ("nonconstant array index in initializer");
5695 else if (last != 0 && TREE_CODE (last) != INTEGER_CST)
5696 error_init ("nonconstant array index in initializer");
5697 else if (TREE_CODE (constructor_type) != ARRAY_TYPE)
5698 error_init ("array index in non-array initializer");
5699 else if (constructor_max_index
5700 && tree_int_cst_lt (constructor_max_index, first))
5701 error_init ("array index in initializer exceeds array bounds");
5704 constructor_index = convert (bitsizetype, first);
5708 if (tree_int_cst_equal (first, last))
5710 else if (tree_int_cst_lt (last, first))
5712 error_init ("empty index range in initializer");
5717 last = convert (bitsizetype, last);
5718 if (constructor_max_index != 0
5719 && tree_int_cst_lt (constructor_max_index, last))
5721 error_init ("array index range in initializer exceeds array bounds");
5728 designator_errorneous = 0;
5729 if (constructor_range_stack || last)
5730 push_range_stack (last);
5734 /* Within a struct initializer, specify the next field to be initialized. */
5737 set_init_label (fieldname)
5742 if (set_designator (0))
5745 designator_errorneous = 1;
5747 if (TREE_CODE (constructor_type) != RECORD_TYPE
5748 && TREE_CODE (constructor_type) != UNION_TYPE)
5750 error_init ("field name not in record or union initializer");
5754 for (tail = TYPE_FIELDS (constructor_type); tail;
5755 tail = TREE_CHAIN (tail))
5757 if (DECL_NAME (tail) == fieldname)
5762 error ("unknown field `%s' specified in initializer",
5763 IDENTIFIER_POINTER (fieldname));
5766 constructor_fields = tail;
5768 designator_errorneous = 0;
5769 if (constructor_range_stack)
5770 push_range_stack (NULL_TREE);
5774 /* Add a new initializer to the tree of pending initializers. PURPOSE
5775 indentifies the initializer, either array index or field in a structure.
5776 VALUE is the value of that index or field. */
5779 add_pending_init (purpose, value)
5780 tree purpose, value;
5782 struct init_node *p, **q, *r;
5784 q = &constructor_pending_elts;
5787 if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5792 if (tree_int_cst_lt (purpose, p->purpose))
5794 else if (tree_int_cst_lt (p->purpose, purpose))
5798 if (TREE_SIDE_EFFECTS (p->value))
5799 warning_init ("initialized field with side-effects overwritten");
5809 bitpos = bit_position (purpose);
5813 if (tree_int_cst_lt (bitpos, bit_position (p->purpose)))
5815 else if (p->purpose != purpose)
5819 if (TREE_SIDE_EFFECTS (p->value))
5820 warning_init ("initialized field with side-effects overwritten");
5827 r = (struct init_node *) ggc_alloc (sizeof (struct init_node));
5828 r->purpose = purpose;
5839 struct init_node *s;
5843 if (p->balance == 0)
5845 else if (p->balance < 0)
5852 p->left->parent = p;
5869 constructor_pending_elts = r;
5874 struct init_node *t = r->right;
5878 r->right->parent = r;
5883 p->left->parent = p;
5886 p->balance = t->balance < 0;
5887 r->balance = -(t->balance > 0);
5902 constructor_pending_elts = t;
5908 /* p->balance == +1; growth of left side balances the node. */
5913 else /* r == p->right */
5915 if (p->balance == 0)
5916 /* Growth propagation from right side. */
5918 else if (p->balance > 0)
5925 p->right->parent = p;
5942 constructor_pending_elts = r;
5944 else /* r->balance == -1 */
5947 struct init_node *t = r->left;
5951 r->left->parent = r;
5956 p->right->parent = p;
5959 r->balance = (t->balance < 0);
5960 p->balance = -(t->balance > 0);
5975 constructor_pending_elts = t;
5981 /* p->balance == -1; growth of right side balances the node. */
5992 /* Build AVL tree from a sorted chain. */
5995 set_nonincremental_init ()
5999 if (TREE_CODE (constructor_type) != RECORD_TYPE
6000 && TREE_CODE (constructor_type) != ARRAY_TYPE)
6003 for (chain = constructor_elements; chain; chain = TREE_CHAIN (chain))
6004 add_pending_init (TREE_PURPOSE (chain), TREE_VALUE (chain));
6005 constructor_elements = 0;
6006 if (TREE_CODE (constructor_type) == RECORD_TYPE)
6008 constructor_unfilled_fields = TYPE_FIELDS (constructor_type);
6009 /* Skip any nameless bit fields at the beginning. */
6010 while (constructor_unfilled_fields != 0
6011 && DECL_C_BIT_FIELD (constructor_unfilled_fields)
6012 && DECL_NAME (constructor_unfilled_fields) == 0)
6013 constructor_unfilled_fields = TREE_CHAIN (constructor_unfilled_fields);
6016 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
6018 if (TYPE_DOMAIN (constructor_type))
6019 constructor_unfilled_index
6020 = convert (bitsizetype,
6021 TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
6023 constructor_unfilled_index = bitsize_zero_node;
6025 constructor_incremental = 0;
6028 /* Build AVL tree from a string constant. */
6031 set_nonincremental_init_from_string (str)
6034 tree value, purpose, type;
6035 HOST_WIDE_INT val[2];
6036 const char *p, *end;
6037 int byte, wchar_bytes, charwidth, bitpos;
6039 if (TREE_CODE (constructor_type) != ARRAY_TYPE)
6042 if (TYPE_PRECISION (TREE_TYPE (TREE_TYPE (str)))
6043 == TYPE_PRECISION (char_type_node))
6045 else if (TYPE_PRECISION (TREE_TYPE (TREE_TYPE (str)))
6046 == TYPE_PRECISION (wchar_type_node))
6047 wchar_bytes = TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT;
6051 charwidth = TYPE_PRECISION (char_type_node);
6052 type = TREE_TYPE (constructor_type);
6053 p = TREE_STRING_POINTER (str);
6054 end = p + TREE_STRING_LENGTH (str);
6056 for (purpose = bitsize_zero_node;
6057 p < end && !tree_int_cst_lt (constructor_max_index, purpose);
6058 purpose = size_binop (PLUS_EXPR, purpose, bitsize_one_node))
6060 if (wchar_bytes == 1)
6062 val[1] = (unsigned char) *p++;
6069 for (byte = 0; byte < wchar_bytes; byte++)
6071 if (BYTES_BIG_ENDIAN)
6072 bitpos = (wchar_bytes - byte - 1) * charwidth;
6074 bitpos = byte * charwidth;
6075 val[bitpos < HOST_BITS_PER_WIDE_INT]
6076 |= ((unsigned HOST_WIDE_INT) ((unsigned char) *p++))
6077 << (bitpos % HOST_BITS_PER_WIDE_INT);
6081 if (!TREE_UNSIGNED (type))
6083 bitpos = ((wchar_bytes - 1) * charwidth) + HOST_BITS_PER_CHAR;
6084 if (bitpos < HOST_BITS_PER_WIDE_INT)
6086 if (val[1] & (((HOST_WIDE_INT) 1) << (bitpos - 1)))
6088 val[1] |= ((HOST_WIDE_INT) -1) << bitpos;
6092 else if (bitpos == HOST_BITS_PER_WIDE_INT)
6097 else if (val[0] & (((HOST_WIDE_INT) 1)
6098 << (bitpos - 1 - HOST_BITS_PER_WIDE_INT)))
6099 val[0] |= ((HOST_WIDE_INT) -1)
6100 << (bitpos - HOST_BITS_PER_WIDE_INT);
6103 value = build_int_2 (val[1], val[0]);
6104 TREE_TYPE (value) = type;
6105 add_pending_init (purpose, value);
6108 constructor_incremental = 0;
6111 /* Return value of FIELD in pending initializer or zero if the field was
6112 not initialized yet. */
6115 find_init_member (field)
6118 struct init_node *p;
6120 if (TREE_CODE (constructor_type) == ARRAY_TYPE)
6122 if (constructor_incremental
6123 && tree_int_cst_lt (field, constructor_unfilled_index))
6124 set_nonincremental_init ();
6126 p = constructor_pending_elts;
6129 if (tree_int_cst_lt (field, p->purpose))
6131 else if (tree_int_cst_lt (p->purpose, field))
6137 else if (TREE_CODE (constructor_type) == RECORD_TYPE)
6139 tree bitpos = bit_position (field);
6141 if (constructor_incremental
6142 && (!constructor_unfilled_fields
6143 || tree_int_cst_lt (bitpos,
6144 bit_position (constructor_unfilled_fields))))
6145 set_nonincremental_init ();
6147 p = constructor_pending_elts;
6150 if (field == p->purpose)
6152 else if (tree_int_cst_lt (bitpos, bit_position (p->purpose)))
6158 else if (TREE_CODE (constructor_type) == UNION_TYPE)
6160 if (constructor_elements
6161 && TREE_PURPOSE (constructor_elements) == field)
6162 return TREE_VALUE (constructor_elements);
6167 /* "Output" the next constructor element.
6168 At top level, really output it to assembler code now.
6169 Otherwise, collect it in a list from which we will make a CONSTRUCTOR.
6170 TYPE is the data type that the containing data type wants here.
6171 FIELD is the field (a FIELD_DECL) or the index that this element fills.
6173 PENDING if non-nil means output pending elements that belong
6174 right after this element. (PENDING is normally 1;
6175 it is 0 while outputting pending elements, to avoid recursion.) */
6178 output_init_element (value, type, field, pending)
6179 tree value, type, field;
6182 if (TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE
6183 || (TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE
6184 && !(TREE_CODE (value) == STRING_CST
6185 && TREE_CODE (type) == ARRAY_TYPE
6186 && TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE)
6187 && !comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (value)),
6188 TYPE_MAIN_VARIANT (type))))
6189 value = default_conversion (value);
6191 if (value == error_mark_node)
6192 constructor_erroneous = 1;
6193 else if (!TREE_CONSTANT (value))
6194 constructor_constant = 0;
6195 else if (initializer_constant_valid_p (value, TREE_TYPE (value)) == 0
6196 || ((TREE_CODE (constructor_type) == RECORD_TYPE
6197 || TREE_CODE (constructor_type) == UNION_TYPE)
6198 && DECL_C_BIT_FIELD (field)
6199 && TREE_CODE (value) != INTEGER_CST))
6200 constructor_simple = 0;
6202 if (require_constant_value && ! TREE_CONSTANT (value))
6204 error_init ("initializer element is not constant");
6205 value = error_mark_node;
6207 else if (require_constant_elements
6208 && initializer_constant_valid_p (value, TREE_TYPE (value)) == 0)
6209 pedwarn ("initializer element is not computable at load time");
6211 /* If this field is empty (and not at the end of structure),
6212 don't do anything other than checking the initializer. */
6214 && (TREE_TYPE (field) == error_mark_node
6215 || (COMPLETE_TYPE_P (TREE_TYPE (field))
6216 && integer_zerop (TYPE_SIZE (TREE_TYPE (field)))
6217 && (TREE_CODE (constructor_type) == ARRAY_TYPE
6218 || TREE_CHAIN (field)))))
6221 if (value == error_mark_node)
6223 constructor_erroneous = 1;
6227 /* If this element doesn't come next in sequence,
6228 put it on constructor_pending_elts. */
6229 if (TREE_CODE (constructor_type) == ARRAY_TYPE
6230 && (!constructor_incremental
6231 || !tree_int_cst_equal (field, constructor_unfilled_index)))
6233 if (constructor_incremental
6234 && tree_int_cst_lt (field, constructor_unfilled_index))
6235 set_nonincremental_init ();
6237 add_pending_init (field,
6238 digest_init (type, value, require_constant_value,
6239 require_constant_elements));
6242 else if (TREE_CODE (constructor_type) == RECORD_TYPE
6243 && (!constructor_incremental
6244 || field != constructor_unfilled_fields))
6246 /* We do this for records but not for unions. In a union,
6247 no matter which field is specified, it can be initialized
6248 right away since it starts at the beginning of the union. */
6249 if (constructor_incremental)
6251 if (!constructor_unfilled_fields)
6252 set_nonincremental_init ();
6255 tree bitpos, unfillpos;
6257 bitpos = bit_position (field);
6258 unfillpos = bit_position (constructor_unfilled_fields);
6260 if (tree_int_cst_lt (bitpos, unfillpos))
6261 set_nonincremental_init ();
6265 add_pending_init (field,
6266 digest_init (type, value, require_constant_value,
6267 require_constant_elements));
6270 else if (TREE_CODE (constructor_type) == UNION_TYPE
6271 && constructor_elements)
6273 if (TREE_SIDE_EFFECTS (TREE_VALUE (constructor_elements)))
6274 warning_init ("initialized field with side-effects overwritten");
6276 /* We can have just one union field set. */
6277 constructor_elements = 0;
6280 /* Otherwise, output this element either to
6281 constructor_elements or to the assembler file. */
6283 if (field && TREE_CODE (field) == INTEGER_CST)
6284 field = copy_node (field);
6285 constructor_elements
6286 = tree_cons (field, digest_init (type, value,
6287 require_constant_value,
6288 require_constant_elements),
6289 constructor_elements);
6291 /* Advance the variable that indicates sequential elements output. */
6292 if (TREE_CODE (constructor_type) == ARRAY_TYPE)
6293 constructor_unfilled_index
6294 = size_binop (PLUS_EXPR, constructor_unfilled_index,
6296 else if (TREE_CODE (constructor_type) == RECORD_TYPE)
6298 constructor_unfilled_fields
6299 = TREE_CHAIN (constructor_unfilled_fields);
6301 /* Skip any nameless bit fields. */
6302 while (constructor_unfilled_fields != 0
6303 && DECL_C_BIT_FIELD (constructor_unfilled_fields)
6304 && DECL_NAME (constructor_unfilled_fields) == 0)
6305 constructor_unfilled_fields =
6306 TREE_CHAIN (constructor_unfilled_fields);
6308 else if (TREE_CODE (constructor_type) == UNION_TYPE)
6309 constructor_unfilled_fields = 0;
6311 /* Now output any pending elements which have become next. */
6313 output_pending_init_elements (0);
6316 /* Output any pending elements which have become next.
6317 As we output elements, constructor_unfilled_{fields,index}
6318 advances, which may cause other elements to become next;
6319 if so, they too are output.
6321 If ALL is 0, we return when there are
6322 no more pending elements to output now.
6324 If ALL is 1, we output space as necessary so that
6325 we can output all the pending elements. */
6328 output_pending_init_elements (all)
6331 struct init_node *elt = constructor_pending_elts;
6336 /* Look thru the whole pending tree.
6337 If we find an element that should be output now,
6338 output it. Otherwise, set NEXT to the element
6339 that comes first among those still pending. */
6344 if (TREE_CODE (constructor_type) == ARRAY_TYPE)
6346 if (tree_int_cst_equal (elt->purpose,
6347 constructor_unfilled_index))
6348 output_init_element (elt->value,
6349 TREE_TYPE (constructor_type),
6350 constructor_unfilled_index, 0);
6351 else if (tree_int_cst_lt (constructor_unfilled_index,
6354 /* Advance to the next smaller node. */
6359 /* We have reached the smallest node bigger than the
6360 current unfilled index. Fill the space first. */
6361 next = elt->purpose;
6367 /* Advance to the next bigger node. */
6372 /* We have reached the biggest node in a subtree. Find
6373 the parent of it, which is the next bigger node. */
6374 while (elt->parent && elt->parent->right == elt)
6377 if (elt && tree_int_cst_lt (constructor_unfilled_index,
6380 next = elt->purpose;
6386 else if (TREE_CODE (constructor_type) == RECORD_TYPE
6387 || TREE_CODE (constructor_type) == UNION_TYPE)
6389 tree ctor_unfilled_bitpos, elt_bitpos;
6391 /* If the current record is complete we are done. */
6392 if (constructor_unfilled_fields == 0)
6395 ctor_unfilled_bitpos = bit_position (constructor_unfilled_fields);
6396 elt_bitpos = bit_position (elt->purpose);
6397 /* We can't compare fields here because there might be empty
6398 fields in between. */
6399 if (tree_int_cst_equal (elt_bitpos, ctor_unfilled_bitpos))
6401 constructor_unfilled_fields = elt->purpose;
6402 output_init_element (elt->value, TREE_TYPE (elt->purpose),
6405 else if (tree_int_cst_lt (ctor_unfilled_bitpos, elt_bitpos))
6407 /* Advance to the next smaller node. */
6412 /* We have reached the smallest node bigger than the
6413 current unfilled field. Fill the space first. */
6414 next = elt->purpose;
6420 /* Advance to the next bigger node. */
6425 /* We have reached the biggest node in a subtree. Find
6426 the parent of it, which is the next bigger node. */
6427 while (elt->parent && elt->parent->right == elt)
6431 && (tree_int_cst_lt (ctor_unfilled_bitpos,
6432 bit_position (elt->purpose))))
6434 next = elt->purpose;
6442 /* Ordinarily return, but not if we want to output all
6443 and there are elements left. */
6444 if (! (all && next != 0))
6447 /* If it's not incremental, just skip over the gap, so that after
6448 jumping to retry we will output the next successive element. */
6449 if (TREE_CODE (constructor_type) == RECORD_TYPE
6450 || TREE_CODE (constructor_type) == UNION_TYPE)
6451 constructor_unfilled_fields = next;
6452 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
6453 constructor_unfilled_index = next;
6455 /* ELT now points to the node in the pending tree with the next
6456 initializer to output. */
6460 /* Add one non-braced element to the current constructor level.
6461 This adjusts the current position within the constructor's type.
6462 This may also start or terminate implicit levels
6463 to handle a partly-braced initializer.
6465 Once this has found the correct level for the new element,
6466 it calls output_init_element. */
6469 process_init_element (value)
6472 tree orig_value = value;
6473 int string_flag = value != 0 && TREE_CODE (value) == STRING_CST;
6475 designator_depth = 0;
6476 designator_errorneous = 0;
6478 /* Handle superfluous braces around string cst as in
6479 char x[] = {"foo"}; */
6482 && TREE_CODE (constructor_type) == ARRAY_TYPE
6483 && TREE_CODE (TREE_TYPE (constructor_type)) == INTEGER_TYPE
6484 && integer_zerop (constructor_unfilled_index))
6486 if (constructor_stack->replacement_value)
6487 error_init ("excess elements in char array initializer");
6488 constructor_stack->replacement_value = value;
6492 if (constructor_stack->replacement_value != 0)
6494 error_init ("excess elements in struct initializer");
6498 /* Ignore elements of a brace group if it is entirely superfluous
6499 and has already been diagnosed. */
6500 if (constructor_type == 0)
6503 /* If we've exhausted any levels that didn't have braces,
6505 while (constructor_stack->implicit)
6507 if ((TREE_CODE (constructor_type) == RECORD_TYPE
6508 || TREE_CODE (constructor_type) == UNION_TYPE)
6509 && constructor_fields == 0)
6510 process_init_element (pop_init_level (1));
6511 else if (TREE_CODE (constructor_type) == ARRAY_TYPE
6512 && (constructor_max_index == 0
6513 || tree_int_cst_lt (constructor_max_index,
6514 constructor_index)))
6515 process_init_element (pop_init_level (1));
6520 /* In the case of [LO ... HI] = VALUE, only evaluate VALUE once. */
6521 if (constructor_range_stack)
6522 value = save_expr (value);
6526 if (TREE_CODE (constructor_type) == RECORD_TYPE)
6529 enum tree_code fieldcode;
6531 if (constructor_fields == 0)
6533 pedwarn_init ("excess elements in struct initializer");
6537 fieldtype = TREE_TYPE (constructor_fields);
6538 if (fieldtype != error_mark_node)
6539 fieldtype = TYPE_MAIN_VARIANT (fieldtype);
6540 fieldcode = TREE_CODE (fieldtype);
6542 /* Accept a string constant to initialize a subarray. */
6544 && fieldcode == ARRAY_TYPE
6545 && TREE_CODE (TREE_TYPE (fieldtype)) == INTEGER_TYPE
6548 /* Otherwise, if we have come to a subaggregate,
6549 and we don't have an element of its type, push into it. */
6550 else if (value != 0 && !constructor_no_implicit
6551 && value != error_mark_node
6552 && TYPE_MAIN_VARIANT (TREE_TYPE (value)) != fieldtype
6553 && (fieldcode == RECORD_TYPE || fieldcode == ARRAY_TYPE
6554 || fieldcode == UNION_TYPE))
6556 push_init_level (1);
6562 push_member_name (constructor_fields);
6563 output_init_element (value, fieldtype, constructor_fields, 1);
6564 RESTORE_SPELLING_DEPTH (constructor_depth);
6567 /* Do the bookkeeping for an element that was
6568 directly output as a constructor. */
6570 /* For a record, keep track of end position of last field. */
6571 if (DECL_SIZE (constructor_fields))
6572 constructor_bit_index
6573 = size_binop (PLUS_EXPR,
6574 bit_position (constructor_fields),
6575 DECL_SIZE (constructor_fields));
6577 constructor_unfilled_fields = TREE_CHAIN (constructor_fields);
6578 /* Skip any nameless bit fields. */
6579 while (constructor_unfilled_fields != 0
6580 && DECL_C_BIT_FIELD (constructor_unfilled_fields)
6581 && DECL_NAME (constructor_unfilled_fields) == 0)
6582 constructor_unfilled_fields =
6583 TREE_CHAIN (constructor_unfilled_fields);
6586 constructor_fields = TREE_CHAIN (constructor_fields);
6587 /* Skip any nameless bit fields at the beginning. */
6588 while (constructor_fields != 0
6589 && DECL_C_BIT_FIELD (constructor_fields)
6590 && DECL_NAME (constructor_fields) == 0)
6591 constructor_fields = TREE_CHAIN (constructor_fields);
6593 else if (TREE_CODE (constructor_type) == UNION_TYPE)
6596 enum tree_code fieldcode;
6598 if (constructor_fields == 0)
6600 pedwarn_init ("excess elements in union initializer");
6604 fieldtype = TREE_TYPE (constructor_fields);
6605 if (fieldtype != error_mark_node)
6606 fieldtype = TYPE_MAIN_VARIANT (fieldtype);
6607 fieldcode = TREE_CODE (fieldtype);
6609 /* Warn that traditional C rejects initialization of unions.
6610 We skip the warning if the value is zero. This is done
6611 under the assumption that the zero initializer in user
6612 code appears conditioned on e.g. __STDC__ to avoid
6613 "missing initializer" warnings and relies on default
6614 initialization to zero in the traditional C case. */
6615 if (warn_traditional && !in_system_header
6616 && !(value && (integer_zerop (value) || real_zerop (value))))
6617 warning ("traditional C rejects initialization of unions");
6619 /* Accept a string constant to initialize a subarray. */
6621 && fieldcode == ARRAY_TYPE
6622 && TREE_CODE (TREE_TYPE (fieldtype)) == INTEGER_TYPE
6625 /* Otherwise, if we have come to a subaggregate,
6626 and we don't have an element of its type, push into it. */
6627 else if (value != 0 && !constructor_no_implicit
6628 && value != error_mark_node
6629 && TYPE_MAIN_VARIANT (TREE_TYPE (value)) != fieldtype
6630 && (fieldcode == RECORD_TYPE || fieldcode == ARRAY_TYPE
6631 || fieldcode == UNION_TYPE))
6633 push_init_level (1);
6639 push_member_name (constructor_fields);
6640 output_init_element (value, fieldtype, constructor_fields, 1);
6641 RESTORE_SPELLING_DEPTH (constructor_depth);
6644 /* Do the bookkeeping for an element that was
6645 directly output as a constructor. */
6647 constructor_bit_index = DECL_SIZE (constructor_fields);
6648 constructor_unfilled_fields = TREE_CHAIN (constructor_fields);
6651 constructor_fields = 0;
6653 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
6655 tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
6656 enum tree_code eltcode = TREE_CODE (elttype);
6658 /* Accept a string constant to initialize a subarray. */
6660 && eltcode == ARRAY_TYPE
6661 && TREE_CODE (TREE_TYPE (elttype)) == INTEGER_TYPE
6664 /* Otherwise, if we have come to a subaggregate,
6665 and we don't have an element of its type, push into it. */
6666 else if (value != 0 && !constructor_no_implicit
6667 && value != error_mark_node
6668 && TYPE_MAIN_VARIANT (TREE_TYPE (value)) != elttype
6669 && (eltcode == RECORD_TYPE || eltcode == ARRAY_TYPE
6670 || eltcode == UNION_TYPE))
6672 push_init_level (1);
6676 if (constructor_max_index != 0
6677 && (tree_int_cst_lt (constructor_max_index, constructor_index)
6678 || integer_all_onesp (constructor_max_index)))
6680 pedwarn_init ("excess elements in array initializer");
6684 /* Now output the actual element. */
6687 push_array_bounds (tree_low_cst (constructor_index, 0));
6688 output_init_element (value, elttype, constructor_index, 1);
6689 RESTORE_SPELLING_DEPTH (constructor_depth);
6693 = size_binop (PLUS_EXPR, constructor_index, bitsize_one_node);
6696 /* If we are doing the bookkeeping for an element that was
6697 directly output as a constructor, we must update
6698 constructor_unfilled_index. */
6699 constructor_unfilled_index = constructor_index;
6702 /* Handle the sole element allowed in a braced initializer
6703 for a scalar variable. */
6704 else if (constructor_fields == 0)
6706 pedwarn_init ("excess elements in scalar initializer");
6712 output_init_element (value, constructor_type, NULL_TREE, 1);
6713 constructor_fields = 0;
6716 /* Handle range initializers either at this level or anywhere higher
6717 in the designator stack. */
6718 if (constructor_range_stack)
6720 struct constructor_range_stack *p, *range_stack;
6723 range_stack = constructor_range_stack;
6724 constructor_range_stack = 0;
6725 while (constructor_stack != range_stack->stack)
6727 if (!constructor_stack->implicit)
6729 process_init_element (pop_init_level (1));
6731 for (p = range_stack;
6732 !p->range_end || tree_int_cst_equal (p->index, p->range_end);
6735 if (!constructor_stack->implicit)
6737 process_init_element (pop_init_level (1));
6740 p->index = size_binop (PLUS_EXPR, p->index, bitsize_one_node);
6741 if (tree_int_cst_equal (p->index, p->range_end) && !p->prev)
6746 constructor_index = p->index;
6747 constructor_fields = p->fields;
6748 if (finish && p->range_end && p->index == p->range_start)
6756 push_init_level (2);
6757 p->stack = constructor_stack;
6758 if (p->range_end && tree_int_cst_equal (p->index, p->range_end))
6759 p->index = p->range_start;
6763 constructor_range_stack = range_stack;
6770 constructor_range_stack = 0;
6773 /* Build an asm-statement, whose components are a CV_QUALIFIER, a
6774 STRING, some OUTPUTS, some INPUTS, and some CLOBBERS. */
6777 build_asm_stmt (cv_qualifier, string, outputs, inputs, clobbers)
6786 if (TREE_CHAIN (string))
6787 string = combine_strings (string);
6788 if (TREE_CODE (string) != STRING_CST)
6790 error ("asm template is not a string constant");
6794 if (cv_qualifier != NULL_TREE
6795 && cv_qualifier != ridpointers[(int) RID_VOLATILE])
6797 warning ("%s qualifier ignored on asm",
6798 IDENTIFIER_POINTER (cv_qualifier));
6799 cv_qualifier = NULL_TREE;
6802 /* We can remove output conversions that change the type,
6803 but not the mode. */
6804 for (tail = outputs; tail; tail = TREE_CHAIN (tail))
6806 tree output = TREE_VALUE (tail);
6808 STRIP_NOPS (output);
6809 TREE_VALUE (tail) = output;
6811 /* Allow conversions as LHS here. build_modify_expr as called below
6812 will do the right thing with them. */
6813 while (TREE_CODE (output) == NOP_EXPR
6814 || TREE_CODE (output) == CONVERT_EXPR
6815 || TREE_CODE (output) == FLOAT_EXPR
6816 || TREE_CODE (output) == FIX_TRUNC_EXPR
6817 || TREE_CODE (output) == FIX_FLOOR_EXPR
6818 || TREE_CODE (output) == FIX_ROUND_EXPR
6819 || TREE_CODE (output) == FIX_CEIL_EXPR)
6820 output = TREE_OPERAND (output, 0);
6822 lvalue_or_else (TREE_VALUE (tail), "invalid lvalue in asm statement");
6825 /* Remove output conversions that change the type but not the mode. */
6826 for (tail = outputs; tail; tail = TREE_CHAIN (tail))
6828 tree output = TREE_VALUE (tail);
6829 STRIP_NOPS (output);
6830 TREE_VALUE (tail) = output;
6833 /* Perform default conversions on array and function inputs.
6834 Don't do this for other types as it would screw up operands
6835 expected to be in memory. */
6836 for (tail = inputs; tail; tail = TREE_CHAIN (tail))
6837 if (TREE_CODE (TREE_TYPE (TREE_VALUE (tail))) == ARRAY_TYPE
6838 || TREE_CODE (TREE_TYPE (TREE_VALUE (tail))) == FUNCTION_TYPE)
6839 TREE_VALUE (tail) = default_conversion (TREE_VALUE (tail));
6841 return add_stmt (build_stmt (ASM_STMT, cv_qualifier, string,
6842 outputs, inputs, clobbers));
6845 /* Expand an ASM statement with operands, handling output operands
6846 that are not variables or INDIRECT_REFS by transforming such
6847 cases into cases that expand_asm_operands can handle.
6849 Arguments are same as for expand_asm_operands. */
6852 c_expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line)
6853 tree string, outputs, inputs, clobbers;
6855 const char *filename;
6858 int noutputs = list_length (outputs);
6860 /* o[I] is the place that output number I should be written. */
6861 register tree *o = (tree *) alloca (noutputs * sizeof (tree));
6864 /* Record the contents of OUTPUTS before it is modified. */
6865 for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
6866 o[i] = TREE_VALUE (tail);
6868 /* Generate the ASM_OPERANDS insn; store into the TREE_VALUEs of
6869 OUTPUTS some trees for where the values were actually stored. */
6870 expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line);
6872 /* Copy all the intermediate outputs into the specified outputs. */
6873 for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
6875 if (o[i] != TREE_VALUE (tail))
6877 expand_expr (build_modify_expr (o[i], NOP_EXPR, TREE_VALUE (tail)),
6878 NULL_RTX, VOIDmode, EXPAND_NORMAL);
6881 /* Restore the original value so that it's correct the next
6882 time we expand this function. */
6883 TREE_VALUE (tail) = o[i];
6885 /* Detect modification of read-only values.
6886 (Otherwise done by build_modify_expr.) */
6889 tree type = TREE_TYPE (o[i]);
6890 if (TREE_READONLY (o[i])
6891 || TYPE_READONLY (type)
6892 || ((TREE_CODE (type) == RECORD_TYPE
6893 || TREE_CODE (type) == UNION_TYPE)
6894 && C_TYPE_FIELDS_READONLY (type)))
6895 readonly_warning (o[i], "modification by `asm'");
6899 /* Those MODIFY_EXPRs could do autoincrements. */
6903 /* Expand a C `return' statement.
6904 RETVAL is the expression for what to return,
6905 or a null pointer for `return;' with no value. */
6908 c_expand_return (retval)
6911 tree valtype = TREE_TYPE (TREE_TYPE (current_function_decl));
6913 if (TREE_THIS_VOLATILE (current_function_decl))
6914 warning ("function declared `noreturn' has a `return' statement");
6918 current_function_returns_null = 1;
6919 if ((warn_return_type || flag_isoc99)
6920 && valtype != 0 && TREE_CODE (valtype) != VOID_TYPE)
6921 pedwarn_c99 ("`return' with no value, in function returning non-void");
6923 else if (valtype == 0 || TREE_CODE (valtype) == VOID_TYPE)
6925 current_function_returns_null = 1;
6926 if (pedantic || TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
6927 pedwarn ("`return' with a value, in function returning void");
6931 tree t = convert_for_assignment (valtype, retval, _("return"),
6932 NULL_TREE, NULL_TREE, 0);
6933 tree res = DECL_RESULT (current_function_decl);
6936 if (t == error_mark_node)
6939 inner = t = convert (TREE_TYPE (res), t);
6941 /* Strip any conversions, additions, and subtractions, and see if
6942 we are returning the address of a local variable. Warn if so. */
6945 switch (TREE_CODE (inner))
6947 case NOP_EXPR: case NON_LVALUE_EXPR: case CONVERT_EXPR:
6949 inner = TREE_OPERAND (inner, 0);
6953 /* If the second operand of the MINUS_EXPR has a pointer
6954 type (or is converted from it), this may be valid, so
6955 don't give a warning. */
6957 tree op1 = TREE_OPERAND (inner, 1);
6959 while (! POINTER_TYPE_P (TREE_TYPE (op1))
6960 && (TREE_CODE (op1) == NOP_EXPR
6961 || TREE_CODE (op1) == NON_LVALUE_EXPR
6962 || TREE_CODE (op1) == CONVERT_EXPR))
6963 op1 = TREE_OPERAND (op1, 0);
6965 if (POINTER_TYPE_P (TREE_TYPE (op1)))
6968 inner = TREE_OPERAND (inner, 0);
6973 inner = TREE_OPERAND (inner, 0);
6975 while (TREE_CODE_CLASS (TREE_CODE (inner)) == 'r')
6976 inner = TREE_OPERAND (inner, 0);
6978 if (TREE_CODE (inner) == VAR_DECL
6979 && ! DECL_EXTERNAL (inner)
6980 && ! TREE_STATIC (inner)
6981 && DECL_CONTEXT (inner) == current_function_decl)
6982 warning ("function returns address of local variable");
6992 retval = build (MODIFY_EXPR, TREE_TYPE (res), res, t);
6993 current_function_returns_value = 1;
6996 return add_stmt (build_return_stmt (retval));
7000 /* The SWITCH_STMT being built. */
7002 /* A splay-tree mapping the low element of a case range to the high
7003 element, or NULL_TREE if there is no high element. Used to
7004 determine whether or not a new case label duplicates an old case
7005 label. We need a tree, rather than simply a hash table, because
7006 of the GNU case range extension. */
7008 /* The next node on the stack. */
7009 struct c_switch *next;
7012 /* A stack of the currently active switch statements. The innermost
7013 switch statement is on the top of the stack. There is no need to
7014 mark the stack for garbage collection because it is only active
7015 during the processing of the body of a function, and we never
7016 collect at that point. */
7018 static struct c_switch *switch_stack;
7020 /* Start a C switch statement, testing expression EXP. Return the new
7027 register enum tree_code code;
7029 struct c_switch *cs;
7031 if (exp != error_mark_node)
7033 code = TREE_CODE (TREE_TYPE (exp));
7034 type = TREE_TYPE (exp);
7036 if (code != INTEGER_TYPE
7037 && code != ENUMERAL_TYPE
7038 && code != ERROR_MARK)
7040 error ("switch quantity not an integer");
7041 exp = integer_zero_node;
7046 type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
7048 if (warn_traditional && !in_system_header
7049 && (type == long_integer_type_node
7050 || type == long_unsigned_type_node))
7051 warning ("`long' switch expression not converted to `int' in ISO C");
7053 exp = default_conversion (exp);
7054 type = TREE_TYPE (exp);
7055 index = get_unwidened (exp, NULL_TREE);
7056 /* We can't strip a conversion from a signed type to an
7057 unsigned, because if we did, int_fits_type_p would do the
7058 wrong thing when checking case values for being in range,
7059 and it's too hard to do the right thing. */
7060 if (TREE_UNSIGNED (TREE_TYPE (exp))
7061 == TREE_UNSIGNED (TREE_TYPE (index)))
7066 /* Add this new SWITCH_STMT to the stack. */
7067 cs = (struct c_switch *) xmalloc (sizeof (*cs));
7068 cs->switch_stmt = build_stmt (SWITCH_STMT, exp, NULL_TREE, NULL_TREE);
7069 cs->cases = splay_tree_new (case_compare, NULL, NULL);
7070 cs->next = switch_stack;
7073 return add_stmt (switch_stack->switch_stmt);
7076 /* Process a case label. */
7079 do_case (low_value, high_value)
7083 tree label = NULL_TREE;
7087 label = c_add_case_label (switch_stack->cases,
7088 SWITCH_COND (switch_stack->switch_stmt),
7089 low_value, high_value);
7090 if (label == error_mark_node)
7094 error ("case label not within a switch statement");
7096 error ("`default' label not within a switch statement");
7101 /* Finish the switch statement. */
7106 struct c_switch *cs = switch_stack;
7108 RECHAIN_STMTS (cs->switch_stmt, SWITCH_BODY (cs->switch_stmt));
7110 /* Pop the stack. */
7111 switch_stack = switch_stack->next;
7112 splay_tree_delete (cs->cases);