1 /* Build expressions with type checking for C compiler.
2 Copyright (C) 1987, 88, 91-97, 1998 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 /* This file is part of the C front end.
23 It contains routines to build C expressions given their operands,
24 including computing the types of the result, C-specific error checks,
25 and some optimization.
27 There are also routines to build RETURN_STMT nodes and CASE_STMT nodes,
28 and to process initializations in declarations (since they work
29 like a strange sort of assignment). */
42 /* Nonzero if we've already printed a "missing braces around initializer"
43 message within this initializer. */
44 static int missing_braces_mentioned
;
46 static tree qualify_type
PROTO((tree
, tree
));
47 static int comp_target_types
PROTO((tree
, tree
));
48 static int function_types_compatible_p
PROTO((tree
, tree
));
49 static int type_lists_compatible_p
PROTO((tree
, tree
));
50 static int self_promoting_type_p
PROTO((tree
));
51 static tree decl_constant_value
PROTO((tree
));
52 static tree lookup_field
PROTO((tree
, tree
, tree
*));
53 static tree convert_arguments
PROTO((tree
, tree
, tree
, tree
));
54 static tree pointer_int_sum
PROTO((enum tree_code
, tree
, tree
));
55 static tree pointer_diff
PROTO((tree
, tree
));
56 static tree unary_complex_lvalue
PROTO((enum tree_code
, tree
));
57 static void pedantic_lvalue_warning
PROTO((enum tree_code
));
58 static tree internal_build_compound_expr
PROTO((tree
, int));
59 static tree convert_for_assignment
PROTO((tree
, tree
, const char *, tree
,
61 static void warn_for_assignment
PROTO((const char *, const char *,
63 static tree valid_compound_expr_initializer
PROTO((tree
, tree
));
64 static void push_string
PROTO((const char *));
65 static void push_member_name
PROTO((tree
));
66 static void push_array_bounds
PROTO((int));
67 static int spelling_length
PROTO((void));
68 static char *print_spelling
PROTO((char *));
69 static void warning_init
PROTO((const char *));
70 static tree digest_init
PROTO((tree
, tree
, int, int));
71 static void check_init_type_bitfields
PROTO((tree
));
72 static void output_init_element
PROTO((tree
, tree
, tree
, int));
73 static void output_pending_init_elements
PROTO((int));
74 static void add_pending_init
PROTO((tree
, tree
));
75 static int pending_init_member
PROTO((tree
));
77 /* Do `exp = require_complete_type (exp);' to make sure exp
78 does not have an incomplete type. (That includes void types.) */
81 require_complete_type (value
)
84 tree type
= TREE_TYPE (value
);
86 /* First, detect a valid value with a complete type. */
87 if (TYPE_SIZE (type
) != 0
88 && type
!= void_type_node
)
91 incomplete_type_error (value
, type
);
92 return error_mark_node
;
95 /* Print an error message for invalid use of an incomplete type.
96 VALUE is the expression that was used (or 0 if that isn't known)
97 and TYPE is the type that was invalid. */
100 incomplete_type_error (value
, type
)
104 const char *type_code_string
;
106 /* Avoid duplicate error message. */
107 if (TREE_CODE (type
) == ERROR_MARK
)
110 if (value
!= 0 && (TREE_CODE (value
) == VAR_DECL
111 || TREE_CODE (value
) == PARM_DECL
))
112 error ("`%s' has an incomplete type",
113 IDENTIFIER_POINTER (DECL_NAME (value
)));
117 /* We must print an error message. Be clever about what it says. */
119 switch (TREE_CODE (type
))
122 type_code_string
= "struct";
126 type_code_string
= "union";
130 type_code_string
= "enum";
134 error ("invalid use of void expression");
138 if (TYPE_DOMAIN (type
))
140 type
= TREE_TYPE (type
);
143 error ("invalid use of array with unspecified bounds");
150 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
151 error ("invalid use of undefined type `%s %s'",
152 type_code_string
, IDENTIFIER_POINTER (TYPE_NAME (type
)));
154 /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL. */
155 error ("invalid use of incomplete typedef `%s'",
156 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
))));
160 /* Return a variant of TYPE which has all the type qualifiers of LIKE
161 as well as those of TYPE. */
164 qualify_type (type
, like
)
167 return c_build_qualified_type (type
, TYPE_QUALS (like
));
170 /* Return the common type of two types.
171 We assume that comptypes has already been done and returned 1;
172 if that isn't so, this may crash. In particular, we assume that qualifiers
175 This is the type for the result of most arithmetic operations
176 if the operands have the given two types. */
182 register enum tree_code code1
;
183 register enum tree_code code2
;
186 /* Save time if the two types are the same. */
188 if (t1
== t2
) return t1
;
190 /* If one type is nonsense, use the other. */
191 if (t1
== error_mark_node
)
193 if (t2
== error_mark_node
)
196 /* Merge the attributes. */
197 attributes
= merge_machine_type_attributes (t1
, t2
);
199 /* Treat an enum type as the unsigned integer type of the same width. */
201 if (TREE_CODE (t1
) == ENUMERAL_TYPE
)
202 t1
= type_for_size (TYPE_PRECISION (t1
), 1);
203 if (TREE_CODE (t2
) == ENUMERAL_TYPE
)
204 t2
= type_for_size (TYPE_PRECISION (t2
), 1);
206 code1
= TREE_CODE (t1
);
207 code2
= TREE_CODE (t2
);
209 /* If one type is complex, form the common type of the non-complex
210 components, then make that complex. Use T1 or T2 if it is the
212 if (code1
== COMPLEX_TYPE
|| code2
== COMPLEX_TYPE
)
214 tree subtype1
= code1
== COMPLEX_TYPE
? TREE_TYPE (t1
) : t1
;
215 tree subtype2
= code2
== COMPLEX_TYPE
? TREE_TYPE (t2
) : t2
;
216 tree subtype
= common_type (subtype1
, subtype2
);
218 if (code1
== COMPLEX_TYPE
&& TREE_TYPE (t1
) == subtype
)
219 return build_type_attribute_variant (t1
, attributes
);
220 else if (code2
== COMPLEX_TYPE
&& TREE_TYPE (t2
) == subtype
)
221 return build_type_attribute_variant (t2
, attributes
);
223 return build_type_attribute_variant (build_complex_type (subtype
),
231 /* If only one is real, use it as the result. */
233 if (code1
== REAL_TYPE
&& code2
!= REAL_TYPE
)
234 return build_type_attribute_variant (t1
, attributes
);
236 if (code2
== REAL_TYPE
&& code1
!= REAL_TYPE
)
237 return build_type_attribute_variant (t2
, attributes
);
239 /* Both real or both integers; use the one with greater precision. */
241 if (TYPE_PRECISION (t1
) > TYPE_PRECISION (t2
))
242 return build_type_attribute_variant (t1
, attributes
);
243 else if (TYPE_PRECISION (t2
) > TYPE_PRECISION (t1
))
244 return build_type_attribute_variant (t2
, attributes
);
246 /* Same precision. Prefer longs to ints even when same size. */
248 if (TYPE_MAIN_VARIANT (t1
) == long_unsigned_type_node
249 || TYPE_MAIN_VARIANT (t2
) == long_unsigned_type_node
)
250 return build_type_attribute_variant (long_unsigned_type_node
,
253 if (TYPE_MAIN_VARIANT (t1
) == long_integer_type_node
254 || TYPE_MAIN_VARIANT (t2
) == long_integer_type_node
)
256 /* But preserve unsignedness from the other type,
257 since long cannot hold all the values of an unsigned int. */
258 if (TREE_UNSIGNED (t1
) || TREE_UNSIGNED (t2
))
259 t1
= long_unsigned_type_node
;
261 t1
= long_integer_type_node
;
262 return build_type_attribute_variant (t1
, attributes
);
265 /* Likewise, prefer long double to double even if same size. */
266 if (TYPE_MAIN_VARIANT (t1
) == long_double_type_node
267 || TYPE_MAIN_VARIANT (t2
) == long_double_type_node
)
268 return build_type_attribute_variant (long_double_type_node
,
271 /* Otherwise prefer the unsigned one. */
273 if (TREE_UNSIGNED (t1
))
274 return build_type_attribute_variant (t1
, attributes
);
276 return build_type_attribute_variant (t2
, attributes
);
279 /* For two pointers, do this recursively on the target type,
280 and combine the qualifiers of the two types' targets. */
281 /* This code was turned off; I don't know why.
282 But ANSI C specifies doing this with the qualifiers.
283 So I turned it on again. */
285 tree pointed_to_1
= TREE_TYPE (t1
);
286 tree pointed_to_2
= TREE_TYPE (t2
);
287 tree target
= common_type (TYPE_MAIN_VARIANT (pointed_to_1
),
288 TYPE_MAIN_VARIANT (pointed_to_2
));
289 t1
= build_pointer_type (c_build_qualified_type
291 TYPE_QUALS (pointed_to_1
) |
292 TYPE_QUALS (pointed_to_2
)));
293 return build_type_attribute_variant (t1
, attributes
);
296 t1
= build_pointer_type (common_type (TREE_TYPE (t1
), TREE_TYPE (t2
)));
297 return build_type_attribute_variant (t1
, attributes
);
302 tree elt
= common_type (TREE_TYPE (t1
), TREE_TYPE (t2
));
303 /* Save space: see if the result is identical to one of the args. */
304 if (elt
== TREE_TYPE (t1
) && TYPE_DOMAIN (t1
))
305 return build_type_attribute_variant (t1
, attributes
);
306 if (elt
== TREE_TYPE (t2
) && TYPE_DOMAIN (t2
))
307 return build_type_attribute_variant (t2
, attributes
);
308 /* Merge the element types, and have a size if either arg has one. */
309 t1
= build_array_type (elt
, TYPE_DOMAIN (TYPE_DOMAIN (t1
) ? t1
: t2
));
310 return build_type_attribute_variant (t1
, attributes
);
314 /* Function types: prefer the one that specified arg types.
315 If both do, merge the arg types. Also merge the return types. */
317 tree valtype
= common_type (TREE_TYPE (t1
), TREE_TYPE (t2
));
318 tree p1
= TYPE_ARG_TYPES (t1
);
319 tree p2
= TYPE_ARG_TYPES (t2
);
324 /* Save space: see if the result is identical to one of the args. */
325 if (valtype
== TREE_TYPE (t1
) && ! TYPE_ARG_TYPES (t2
))
326 return build_type_attribute_variant (t1
, attributes
);
327 if (valtype
== TREE_TYPE (t2
) && ! TYPE_ARG_TYPES (t1
))
328 return build_type_attribute_variant (t2
, attributes
);
330 /* Simple way if one arg fails to specify argument types. */
331 if (TYPE_ARG_TYPES (t1
) == 0)
333 t1
= build_function_type (valtype
, TYPE_ARG_TYPES (t2
));
334 return build_type_attribute_variant (t1
, attributes
);
336 if (TYPE_ARG_TYPES (t2
) == 0)
338 t1
= build_function_type (valtype
, TYPE_ARG_TYPES (t1
));
339 return build_type_attribute_variant (t1
, attributes
);
342 /* If both args specify argument types, we must merge the two
343 lists, argument by argument. */
345 len
= list_length (p1
);
348 for (i
= 0; i
< len
; i
++)
349 newargs
= tree_cons (NULL_TREE
, NULL_TREE
, newargs
);
354 p1
= TREE_CHAIN (p1
), p2
= TREE_CHAIN (p2
), n
= TREE_CHAIN (n
))
356 /* A null type means arg type is not specified.
357 Take whatever the other function type has. */
358 if (TREE_VALUE (p1
) == 0)
360 TREE_VALUE (n
) = TREE_VALUE (p2
);
363 if (TREE_VALUE (p2
) == 0)
365 TREE_VALUE (n
) = TREE_VALUE (p1
);
369 /* Given wait (union {union wait *u; int *i} *)
370 and wait (union wait *),
371 prefer union wait * as type of parm. */
372 if (TREE_CODE (TREE_VALUE (p1
)) == UNION_TYPE
373 && TREE_VALUE (p1
) != TREE_VALUE (p2
))
376 for (memb
= TYPE_FIELDS (TREE_VALUE (p1
));
377 memb
; memb
= TREE_CHAIN (memb
))
378 if (comptypes (TREE_TYPE (memb
), TREE_VALUE (p2
)))
380 TREE_VALUE (n
) = TREE_VALUE (p2
);
382 pedwarn ("function types not truly compatible in ANSI C");
386 if (TREE_CODE (TREE_VALUE (p2
)) == UNION_TYPE
387 && TREE_VALUE (p2
) != TREE_VALUE (p1
))
390 for (memb
= TYPE_FIELDS (TREE_VALUE (p2
));
391 memb
; memb
= TREE_CHAIN (memb
))
392 if (comptypes (TREE_TYPE (memb
), TREE_VALUE (p1
)))
394 TREE_VALUE (n
) = TREE_VALUE (p1
);
396 pedwarn ("function types not truly compatible in ANSI C");
400 TREE_VALUE (n
) = common_type (TREE_VALUE (p1
), TREE_VALUE (p2
));
404 t1
= build_function_type (valtype
, newargs
);
405 /* ... falls through ... */
409 return build_type_attribute_variant (t1
, attributes
);
414 /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
415 or various other operations. Return 2 if they are compatible
416 but a warning may be needed if you use them together. */
419 comptypes (type1
, type2
)
422 register tree t1
= type1
;
423 register tree t2
= type2
;
426 /* Suppress errors caused by previously reported errors. */
428 if (t1
== t2
|| !t1
|| !t2
429 || TREE_CODE (t1
) == ERROR_MARK
|| TREE_CODE (t2
) == ERROR_MARK
)
432 /* Treat an enum type as the integer type of the same width and
435 if (TREE_CODE (t1
) == ENUMERAL_TYPE
)
436 t1
= type_for_size (TYPE_PRECISION (t1
), TREE_UNSIGNED (t1
));
437 if (TREE_CODE (t2
) == ENUMERAL_TYPE
)
438 t2
= type_for_size (TYPE_PRECISION (t2
), TREE_UNSIGNED (t2
));
443 /* Different classes of types can't be compatible. */
445 if (TREE_CODE (t1
) != TREE_CODE (t2
)) return 0;
447 /* Qualifiers must match. */
449 if (TYPE_QUALS (t1
) != TYPE_QUALS (t2
))
452 /* Allow for two different type nodes which have essentially the same
453 definition. Note that we already checked for equality of the type
454 qualifiers (just above). */
456 if (TYPE_MAIN_VARIANT (t1
) == TYPE_MAIN_VARIANT (t2
))
459 #ifndef COMP_TYPE_ATTRIBUTES
460 #define COMP_TYPE_ATTRIBUTES(t1,t2) 1
463 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
464 if (! (attrval
= COMP_TYPE_ATTRIBUTES (t1
, t2
)))
467 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
470 switch (TREE_CODE (t1
))
473 val
= (TREE_TYPE (t1
) == TREE_TYPE (t2
)
474 ? 1 : comptypes (TREE_TYPE (t1
), TREE_TYPE (t2
)));
478 val
= function_types_compatible_p (t1
, t2
);
483 tree d1
= TYPE_DOMAIN (t1
);
484 tree d2
= TYPE_DOMAIN (t2
);
487 /* Target types must match incl. qualifiers. */
488 if (TREE_TYPE (t1
) != TREE_TYPE (t2
)
489 && 0 == (val
= comptypes (TREE_TYPE (t1
), TREE_TYPE (t2
))))
492 /* Sizes must match unless one is missing or variable. */
493 if (d1
== 0 || d2
== 0 || d1
== d2
494 || TREE_CODE (TYPE_MIN_VALUE (d1
)) != INTEGER_CST
495 || TREE_CODE (TYPE_MIN_VALUE (d2
)) != INTEGER_CST
496 || TREE_CODE (TYPE_MAX_VALUE (d1
)) != INTEGER_CST
497 || TREE_CODE (TYPE_MAX_VALUE (d2
)) != INTEGER_CST
)
500 if (! ((TREE_INT_CST_LOW (TYPE_MIN_VALUE (d1
))
501 == TREE_INT_CST_LOW (TYPE_MIN_VALUE (d2
)))
502 && (TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d1
))
503 == TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d2
)))
504 && (TREE_INT_CST_LOW (TYPE_MAX_VALUE (d1
))
505 == TREE_INT_CST_LOW (TYPE_MAX_VALUE (d2
)))
506 && (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d1
))
507 == TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d2
)))))
513 if (maybe_objc_comptypes (t1
, t2
, 0) == 1)
520 return attrval
== 2 && val
== 1 ? 2 : val
;
523 /* Return 1 if TTL and TTR are pointers to types that are equivalent,
524 ignoring their qualifiers. */
527 comp_target_types (ttl
, ttr
)
532 /* Give maybe_objc_comptypes a crack at letting these types through. */
533 if ((val
= maybe_objc_comptypes (ttl
, ttr
, 1)) >= 0)
536 val
= comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (ttl
)),
537 TYPE_MAIN_VARIANT (TREE_TYPE (ttr
)));
539 if (val
== 2 && pedantic
)
540 pedwarn ("types are not quite compatible");
544 /* Subroutines of `comptypes'. */
546 /* Return 1 if two function types F1 and F2 are compatible.
547 If either type specifies no argument types,
548 the other must specify a fixed number of self-promoting arg types.
549 Otherwise, if one type specifies only the number of arguments,
550 the other must specify that number of self-promoting arg types.
551 Otherwise, the argument types must match. */
554 function_types_compatible_p (f1
, f2
)
558 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
562 if (!(TREE_TYPE (f1
) == TREE_TYPE (f2
)
563 || (val
= comptypes (TREE_TYPE (f1
), TREE_TYPE (f2
)))))
566 args1
= TYPE_ARG_TYPES (f1
);
567 args2
= TYPE_ARG_TYPES (f2
);
569 /* An unspecified parmlist matches any specified parmlist
570 whose argument types don't need default promotions. */
574 if (!self_promoting_args_p (args2
))
576 /* If one of these types comes from a non-prototype fn definition,
577 compare that with the other type's arglist.
578 If they don't match, ask for a warning (but no error). */
579 if (TYPE_ACTUAL_ARG_TYPES (f1
)
580 && 1 != type_lists_compatible_p (args2
, TYPE_ACTUAL_ARG_TYPES (f1
)))
586 if (!self_promoting_args_p (args1
))
588 if (TYPE_ACTUAL_ARG_TYPES (f2
)
589 && 1 != type_lists_compatible_p (args1
, TYPE_ACTUAL_ARG_TYPES (f2
)))
594 /* Both types have argument lists: compare them and propagate results. */
595 val1
= type_lists_compatible_p (args1
, args2
);
596 return val1
!= 1 ? val1
: val
;
599 /* Check two lists of types for compatibility,
600 returning 0 for incompatible, 1 for compatible,
601 or 2 for compatible with warning. */
604 type_lists_compatible_p (args1
, args2
)
607 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
613 if (args1
== 0 && args2
== 0)
615 /* If one list is shorter than the other,
616 they fail to match. */
617 if (args1
== 0 || args2
== 0)
619 /* A null pointer instead of a type
620 means there is supposed to be an argument
621 but nothing is specified about what type it has.
622 So match anything that self-promotes. */
623 if (TREE_VALUE (args1
) == 0)
625 if (! self_promoting_type_p (TREE_VALUE (args2
)))
628 else if (TREE_VALUE (args2
) == 0)
630 if (! self_promoting_type_p (TREE_VALUE (args1
)))
633 else if (! (newval
= comptypes (TREE_VALUE (args1
), TREE_VALUE (args2
))))
635 /* Allow wait (union {union wait *u; int *i} *)
636 and wait (union wait *) to be compatible. */
637 if (TREE_CODE (TREE_VALUE (args1
)) == UNION_TYPE
638 && (TYPE_NAME (TREE_VALUE (args1
)) == 0
639 || TYPE_TRANSPARENT_UNION (TREE_VALUE (args1
)))
640 && TREE_CODE (TYPE_SIZE (TREE_VALUE (args1
))) == INTEGER_CST
641 && tree_int_cst_equal (TYPE_SIZE (TREE_VALUE (args1
)),
642 TYPE_SIZE (TREE_VALUE (args2
))))
645 for (memb
= TYPE_FIELDS (TREE_VALUE (args1
));
646 memb
; memb
= TREE_CHAIN (memb
))
647 if (comptypes (TREE_TYPE (memb
), TREE_VALUE (args2
)))
652 else if (TREE_CODE (TREE_VALUE (args2
)) == UNION_TYPE
653 && (TYPE_NAME (TREE_VALUE (args2
)) == 0
654 || TYPE_TRANSPARENT_UNION (TREE_VALUE (args2
)))
655 && TREE_CODE (TYPE_SIZE (TREE_VALUE (args2
))) == INTEGER_CST
656 && tree_int_cst_equal (TYPE_SIZE (TREE_VALUE (args2
)),
657 TYPE_SIZE (TREE_VALUE (args1
))))
660 for (memb
= TYPE_FIELDS (TREE_VALUE (args2
));
661 memb
; memb
= TREE_CHAIN (memb
))
662 if (comptypes (TREE_TYPE (memb
), TREE_VALUE (args1
)))
671 /* comptypes said ok, but record if it said to warn. */
675 args1
= TREE_CHAIN (args1
);
676 args2
= TREE_CHAIN (args2
);
680 /* Return 1 if PARMS specifies a fixed number of parameters
681 and none of their types is affected by default promotions. */
684 self_promoting_args_p (parms
)
688 for (t
= parms
; t
; t
= TREE_CHAIN (t
))
690 register tree type
= TREE_VALUE (t
);
692 if (TREE_CHAIN (t
) == 0 && type
!= void_type_node
)
698 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
701 if (C_PROMOTING_INTEGER_TYPE_P (type
))
707 /* Return 1 if TYPE is not affected by default promotions. */
710 self_promoting_type_p (type
)
713 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
716 if (C_PROMOTING_INTEGER_TYPE_P (type
))
722 /* Return an unsigned type the same as TYPE in other respects. */
728 tree type1
= TYPE_MAIN_VARIANT (type
);
729 if (type1
== signed_char_type_node
|| type1
== char_type_node
)
730 return unsigned_char_type_node
;
731 if (type1
== integer_type_node
)
732 return unsigned_type_node
;
733 if (type1
== short_integer_type_node
)
734 return short_unsigned_type_node
;
735 if (type1
== long_integer_type_node
)
736 return long_unsigned_type_node
;
737 if (type1
== long_long_integer_type_node
)
738 return long_long_unsigned_type_node
;
739 if (type1
== intDI_type_node
)
740 return unsigned_intDI_type_node
;
741 if (type1
== intSI_type_node
)
742 return unsigned_intSI_type_node
;
743 if (type1
== intHI_type_node
)
744 return unsigned_intHI_type_node
;
745 if (type1
== intQI_type_node
)
746 return unsigned_intQI_type_node
;
748 return signed_or_unsigned_type (1, type
);
751 /* Return a signed type the same as TYPE in other respects. */
757 tree type1
= TYPE_MAIN_VARIANT (type
);
758 if (type1
== unsigned_char_type_node
|| type1
== char_type_node
)
759 return signed_char_type_node
;
760 if (type1
== unsigned_type_node
)
761 return integer_type_node
;
762 if (type1
== short_unsigned_type_node
)
763 return short_integer_type_node
;
764 if (type1
== long_unsigned_type_node
)
765 return long_integer_type_node
;
766 if (type1
== long_long_unsigned_type_node
)
767 return long_long_integer_type_node
;
768 if (type1
== unsigned_intDI_type_node
)
769 return intDI_type_node
;
770 if (type1
== unsigned_intSI_type_node
)
771 return intSI_type_node
;
772 if (type1
== unsigned_intHI_type_node
)
773 return intHI_type_node
;
774 if (type1
== unsigned_intQI_type_node
)
775 return intQI_type_node
;
777 return signed_or_unsigned_type (0, type
);
780 /* Return a type the same as TYPE except unsigned or
781 signed according to UNSIGNEDP. */
784 signed_or_unsigned_type (unsignedp
, type
)
788 if ((! INTEGRAL_TYPE_P (type
) && ! POINTER_TYPE_P (type
))
789 || TREE_UNSIGNED (type
) == unsignedp
)
791 if (TYPE_PRECISION (type
) == TYPE_PRECISION (signed_char_type_node
))
792 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
793 if (TYPE_PRECISION (type
) == TYPE_PRECISION (integer_type_node
))
794 return unsignedp
? unsigned_type_node
: integer_type_node
;
795 if (TYPE_PRECISION (type
) == TYPE_PRECISION (short_integer_type_node
))
796 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
797 if (TYPE_PRECISION (type
) == TYPE_PRECISION (long_integer_type_node
))
798 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
799 if (TYPE_PRECISION (type
) == TYPE_PRECISION (long_long_integer_type_node
))
800 return (unsignedp
? long_long_unsigned_type_node
801 : long_long_integer_type_node
);
805 /* Compute the value of the `sizeof' operator. */
811 enum tree_code code
= TREE_CODE (type
);
814 if (code
== FUNCTION_TYPE
)
816 if (pedantic
|| warn_pointer_arith
)
817 pedwarn ("sizeof applied to a function type");
820 if (code
== VOID_TYPE
)
822 if (pedantic
|| warn_pointer_arith
)
823 pedwarn ("sizeof applied to a void type");
826 if (code
== ERROR_MARK
)
828 if (TYPE_SIZE (type
) == 0)
830 error ("sizeof applied to an incomplete type");
834 /* Convert in case a char is more than one unit. */
835 t
= size_binop (CEIL_DIV_EXPR
, TYPE_SIZE (type
),
836 size_int (TYPE_PRECISION (char_type_node
)));
837 t
= convert (sizetype
, t
);
838 /* size_binop does not put the constant in range, so do it now. */
839 if (TREE_CODE (t
) == INTEGER_CST
&& force_fit_type (t
, 0))
840 TREE_CONSTANT_OVERFLOW (t
) = TREE_OVERFLOW (t
) = 1;
845 c_sizeof_nowarn (type
)
848 enum tree_code code
= TREE_CODE (type
);
851 if (code
== FUNCTION_TYPE
853 || code
== ERROR_MARK
)
855 if (TYPE_SIZE (type
) == 0)
858 /* Convert in case a char is more than one unit. */
859 t
= size_binop (CEIL_DIV_EXPR
, TYPE_SIZE (type
),
860 size_int (TYPE_PRECISION (char_type_node
)));
861 t
= convert (sizetype
, t
);
862 force_fit_type (t
, 0);
866 /* Compute the size to increment a pointer by. */
869 c_size_in_bytes (type
)
872 enum tree_code code
= TREE_CODE (type
);
875 if (code
== FUNCTION_TYPE
)
877 if (code
== VOID_TYPE
)
879 if (code
== ERROR_MARK
)
881 if (TYPE_SIZE (type
) == 0)
883 error ("arithmetic on pointer to an incomplete type");
887 /* Convert in case a char is more than one unit. */
888 t
= size_binop (CEIL_DIV_EXPR
, TYPE_SIZE (type
),
889 size_int (BITS_PER_UNIT
));
890 t
= convert (sizetype
, t
);
891 force_fit_type (t
, 0);
895 /* Implement the __alignof keyword: Return the minimum required
896 alignment of TYPE, measured in bytes. */
902 enum tree_code code
= TREE_CODE (type
);
904 if (code
== FUNCTION_TYPE
)
905 return size_int (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
907 if (code
== VOID_TYPE
|| code
== ERROR_MARK
)
910 return size_int (TYPE_ALIGN (type
) / BITS_PER_UNIT
);
913 /* Implement the __alignof keyword: Return the minimum required
914 alignment of EXPR, measured in bytes. For VAR_DECL's and
915 FIELD_DECL's return DECL_ALIGN (which can be set from an
916 "aligned" __attribute__ specification). */
919 c_alignof_expr (expr
)
922 if (TREE_CODE (expr
) == VAR_DECL
)
923 return size_int (DECL_ALIGN (expr
) / BITS_PER_UNIT
);
925 if (TREE_CODE (expr
) == COMPONENT_REF
926 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
, 1)))
928 error ("`__alignof' applied to a bit-field");
931 else if (TREE_CODE (expr
) == COMPONENT_REF
932 && TREE_CODE (TREE_OPERAND (expr
, 1)) == FIELD_DECL
)
933 return size_int (DECL_ALIGN (TREE_OPERAND (expr
, 1)) / BITS_PER_UNIT
);
935 if (TREE_CODE (expr
) == INDIRECT_REF
)
937 tree t
= TREE_OPERAND (expr
, 0);
939 int bestalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
941 while (TREE_CODE (t
) == NOP_EXPR
942 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == POINTER_TYPE
)
946 t
= TREE_OPERAND (t
, 0);
947 thisalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
948 if (thisalign
> bestalign
)
949 best
= t
, bestalign
= thisalign
;
951 return c_alignof (TREE_TYPE (TREE_TYPE (best
)));
954 return c_alignof (TREE_TYPE (expr
));
957 /* Return either DECL or its known constant value (if it has one). */
960 decl_constant_value (decl
)
963 if (/* Don't change a variable array bound or initial value to a constant
964 in a place where a variable is invalid. */
965 current_function_decl
!= 0
967 && ! TREE_THIS_VOLATILE (decl
)
968 && TREE_READONLY (decl
) && ! ITERATOR_P (decl
)
969 && DECL_INITIAL (decl
) != 0
970 && TREE_CODE (DECL_INITIAL (decl
)) != ERROR_MARK
971 /* This is invalid if initial value is not constant.
972 If it has either a function call, a memory reference,
973 or a variable, then re-evaluating it could give different results. */
974 && TREE_CONSTANT (DECL_INITIAL (decl
))
975 /* Check for cases where this is sub-optimal, even though valid. */
976 && TREE_CODE (DECL_INITIAL (decl
)) != CONSTRUCTOR
977 && DECL_MODE (decl
) != BLKmode
)
978 return DECL_INITIAL (decl
);
982 /* Perform default promotions for C data used in expressions.
983 Arrays and functions are converted to pointers;
984 enumeral types or short or char, to int.
985 In addition, manifest constants symbols are replaced by their values. */
988 default_conversion (exp
)
991 register tree type
= TREE_TYPE (exp
);
992 register enum tree_code code
= TREE_CODE (type
);
994 /* Constants can be used directly unless they're not loadable. */
995 if (TREE_CODE (exp
) == CONST_DECL
)
996 exp
= DECL_INITIAL (exp
);
998 /* Replace a nonvolatile const static variable with its value unless
999 it is an array, in which case we must be sure that taking the
1000 address of the array produces consistent results. */
1001 else if (optimize
&& TREE_CODE (exp
) == VAR_DECL
&& code
!= ARRAY_TYPE
)
1003 exp
= decl_constant_value (exp
);
1004 type
= TREE_TYPE (exp
);
1007 /* Strip NON_LVALUE_EXPRs and no-op conversions, since we aren't using as
1009 /* Do not use STRIP_NOPS here! It will remove conversions from pointer
1010 to integer and cause infinite recursion. */
1011 while (TREE_CODE (exp
) == NON_LVALUE_EXPR
1012 || (TREE_CODE (exp
) == NOP_EXPR
1013 && TREE_TYPE (TREE_OPERAND (exp
, 0)) == TREE_TYPE (exp
)))
1014 exp
= TREE_OPERAND (exp
, 0);
1016 /* Normally convert enums to int,
1017 but convert wide enums to something wider. */
1018 if (code
== ENUMERAL_TYPE
)
1020 type
= type_for_size (MAX (TYPE_PRECISION (type
),
1021 TYPE_PRECISION (integer_type_node
)),
1023 || (TYPE_PRECISION (type
)
1024 >= TYPE_PRECISION (integer_type_node
)))
1025 && TREE_UNSIGNED (type
)));
1026 return convert (type
, exp
);
1029 if (TREE_CODE (exp
) == COMPONENT_REF
1030 && DECL_C_BIT_FIELD (TREE_OPERAND (exp
, 1)))
1032 tree width
= DECL_SIZE (TREE_OPERAND (exp
, 1));
1033 HOST_WIDE_INT low
= TREE_INT_CST_LOW (width
);
1035 /* If it's thinner than an int, promote it like a
1036 C_PROMOTING_INTEGER_TYPE_P, otherwise leave it alone. */
1038 if (low
< TYPE_PRECISION (integer_type_node
))
1040 if (flag_traditional
&& TREE_UNSIGNED (type
))
1041 return convert (unsigned_type_node
, exp
);
1043 return convert (integer_type_node
, exp
);
1047 if (C_PROMOTING_INTEGER_TYPE_P (type
))
1049 /* Traditionally, unsignedness is preserved in default promotions.
1050 Also preserve unsignedness if not really getting any wider. */
1051 if (TREE_UNSIGNED (type
)
1052 && (flag_traditional
1053 || TYPE_PRECISION (type
) == TYPE_PRECISION (integer_type_node
)))
1054 return convert (unsigned_type_node
, exp
);
1055 return convert (integer_type_node
, exp
);
1057 if (flag_traditional
&& !flag_allow_single_precision
1058 && TYPE_MAIN_VARIANT (type
) == float_type_node
)
1059 return convert (double_type_node
, exp
);
1060 if (code
== VOID_TYPE
)
1062 error ("void value not ignored as it ought to be");
1063 return error_mark_node
;
1065 if (code
== FUNCTION_TYPE
)
1067 return build_unary_op (ADDR_EXPR
, exp
, 0);
1069 if (code
== ARRAY_TYPE
)
1072 tree restype
= TREE_TYPE (type
);
1077 if (TREE_CODE_CLASS (TREE_CODE (exp
)) == 'r'
1078 || TREE_CODE_CLASS (TREE_CODE (exp
)) == 'd')
1080 constp
= TREE_READONLY (exp
);
1081 volatilep
= TREE_THIS_VOLATILE (exp
);
1084 if (TYPE_QUALS (type
) || constp
|| volatilep
)
1086 = c_build_qualified_type (restype
,
1088 | (constp
* TYPE_QUAL_CONST
)
1089 | (volatilep
* TYPE_QUAL_VOLATILE
));
1091 if (TREE_CODE (exp
) == INDIRECT_REF
)
1092 return convert (TYPE_POINTER_TO (restype
),
1093 TREE_OPERAND (exp
, 0));
1095 if (TREE_CODE (exp
) == COMPOUND_EXPR
)
1097 tree op1
= default_conversion (TREE_OPERAND (exp
, 1));
1098 return build (COMPOUND_EXPR
, TREE_TYPE (op1
),
1099 TREE_OPERAND (exp
, 0), op1
);
1102 if (! lvalue_p (exp
)
1103 && ! (TREE_CODE (exp
) == CONSTRUCTOR
&& TREE_STATIC (exp
)))
1105 error ("invalid use of non-lvalue array");
1106 return error_mark_node
;
1109 ptrtype
= build_pointer_type (restype
);
1111 if (TREE_CODE (exp
) == VAR_DECL
)
1113 /* ??? This is not really quite correct
1114 in that the type of the operand of ADDR_EXPR
1115 is not the target type of the type of the ADDR_EXPR itself.
1116 Question is, can this lossage be avoided? */
1117 adr
= build1 (ADDR_EXPR
, ptrtype
, exp
);
1118 if (mark_addressable (exp
) == 0)
1119 return error_mark_node
;
1120 TREE_CONSTANT (adr
) = staticp (exp
);
1121 TREE_SIDE_EFFECTS (adr
) = 0; /* Default would be, same as EXP. */
1124 /* This way is better for a COMPONENT_REF since it can
1125 simplify the offset for a component. */
1126 adr
= build_unary_op (ADDR_EXPR
, exp
, 1);
1127 return convert (ptrtype
, adr
);
1132 /* Look up component name in the structure type definition.
1134 If this component name is found indirectly within an anonymous union,
1135 store in *INDIRECT the component which directly contains
1136 that anonymous union. Otherwise, set *INDIRECT to 0. */
1139 lookup_field (type
, component
, indirect
)
1140 tree type
, component
;
1145 /* If TYPE_LANG_SPECIFIC is set, then it is a sorted array of pointers
1146 to the field elements. Use a binary search on this array to quickly
1147 find the element. Otherwise, do a linear search. TYPE_LANG_SPECIFIC
1148 will always be set for structures which have many elements. */
1150 if (TYPE_LANG_SPECIFIC (type
))
1153 tree
*field_array
= &TYPE_LANG_SPECIFIC (type
)->elts
[0];
1155 field
= TYPE_FIELDS (type
);
1157 top
= TYPE_LANG_SPECIFIC (type
)->len
;
1158 while (top
- bot
> 1)
1160 half
= (top
- bot
+ 1) >> 1;
1161 field
= field_array
[bot
+half
];
1163 if (DECL_NAME (field
) == NULL_TREE
)
1165 /* Step through all anon unions in linear fashion. */
1166 while (DECL_NAME (field_array
[bot
]) == NULL_TREE
)
1168 tree anon
= 0, junk
;
1170 field
= field_array
[bot
++];
1171 if (TREE_CODE (TREE_TYPE (field
)) == RECORD_TYPE
1172 || TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
)
1173 anon
= lookup_field (TREE_TYPE (field
), component
, &junk
);
1175 if (anon
!= NULL_TREE
)
1182 /* Entire record is only anon unions. */
1186 /* Restart the binary search, with new lower bound. */
1190 if (DECL_NAME (field
) == component
)
1192 if (DECL_NAME (field
) < component
)
1198 if (DECL_NAME (field_array
[bot
]) == component
)
1199 field
= field_array
[bot
];
1200 else if (DECL_NAME (field
) != component
)
1205 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
1207 if (DECL_NAME (field
) == NULL_TREE
)
1212 if (TREE_CODE (TREE_TYPE (field
)) == RECORD_TYPE
1213 || TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
)
1214 anon
= lookup_field (TREE_TYPE (field
), component
, &junk
);
1216 if (anon
!= NULL_TREE
)
1223 if (DECL_NAME (field
) == component
)
1228 *indirect
= NULL_TREE
;
1232 /* Make an expression to refer to the COMPONENT field of
1233 structure or union value DATUM. COMPONENT is an IDENTIFIER_NODE. */
1236 build_component_ref (datum
, component
)
1237 tree datum
, component
;
1239 register tree type
= TREE_TYPE (datum
);
1240 register enum tree_code code
= TREE_CODE (type
);
1241 register tree field
= NULL
;
1244 /* If DATUM is a COMPOUND_EXPR or COND_EXPR, move our reference inside it
1245 unless we are not to support things not strictly ANSI. */
1246 switch (TREE_CODE (datum
))
1250 tree value
= build_component_ref (TREE_OPERAND (datum
, 1), component
);
1251 return build (COMPOUND_EXPR
, TREE_TYPE (value
),
1252 TREE_OPERAND (datum
, 0), value
);
1255 return build_conditional_expr
1256 (TREE_OPERAND (datum
, 0),
1257 build_component_ref (TREE_OPERAND (datum
, 1), component
),
1258 build_component_ref (TREE_OPERAND (datum
, 2), component
));
1264 /* See if there is a field or component with name COMPONENT. */
1266 if (code
== RECORD_TYPE
|| code
== UNION_TYPE
)
1270 if (TYPE_SIZE (type
) == 0)
1272 incomplete_type_error (NULL_TREE
, type
);
1273 return error_mark_node
;
1276 field
= lookup_field (type
, component
, &indirect
);
1280 error (code
== RECORD_TYPE
1281 ? "structure has no member named `%s'"
1282 : "union has no member named `%s'",
1283 IDENTIFIER_POINTER (component
));
1284 return error_mark_node
;
1286 if (TREE_TYPE (field
) == error_mark_node
)
1287 return error_mark_node
;
1289 /* If FIELD was found buried within an anonymous union,
1290 make one COMPONENT_REF to get that anonymous union,
1291 then fall thru to make a second COMPONENT_REF to get FIELD. */
1294 ref
= build (COMPONENT_REF
, TREE_TYPE (indirect
), datum
, indirect
);
1295 if (TREE_READONLY (datum
) || TREE_READONLY (indirect
))
1296 TREE_READONLY (ref
) = 1;
1297 if (TREE_THIS_VOLATILE (datum
) || TREE_THIS_VOLATILE (indirect
))
1298 TREE_THIS_VOLATILE (ref
) = 1;
1302 ref
= build (COMPONENT_REF
, TREE_TYPE (field
), datum
, field
);
1304 if (TREE_READONLY (datum
) || TREE_READONLY (field
))
1305 TREE_READONLY (ref
) = 1;
1306 if (TREE_THIS_VOLATILE (datum
) || TREE_THIS_VOLATILE (field
))
1307 TREE_THIS_VOLATILE (ref
) = 1;
1311 else if (code
!= ERROR_MARK
)
1312 error ("request for member `%s' in something not a structure or union",
1313 IDENTIFIER_POINTER (component
));
1315 return error_mark_node
;
1318 /* Given an expression PTR for a pointer, return an expression
1319 for the value pointed to.
1320 ERRORSTRING is the name of the operator to appear in error messages. */
1323 build_indirect_ref (ptr
, errorstring
)
1325 const char *errorstring
;
1327 register tree pointer
= default_conversion (ptr
);
1328 register tree type
= TREE_TYPE (pointer
);
1330 if (TREE_CODE (type
) == POINTER_TYPE
)
1332 if (TREE_CODE (pointer
) == ADDR_EXPR
1334 && (TREE_TYPE (TREE_OPERAND (pointer
, 0))
1335 == TREE_TYPE (type
)))
1336 return TREE_OPERAND (pointer
, 0);
1339 tree t
= TREE_TYPE (type
);
1340 register tree ref
= build1 (INDIRECT_REF
,
1341 TYPE_MAIN_VARIANT (t
), pointer
);
1343 if (TYPE_SIZE (t
) == 0 && TREE_CODE (t
) != ARRAY_TYPE
)
1345 error ("dereferencing pointer to incomplete type");
1346 return error_mark_node
;
1348 if (TREE_CODE (t
) == VOID_TYPE
&& skip_evaluation
== 0)
1349 warning ("dereferencing `void *' pointer");
1351 /* We *must* set TREE_READONLY when dereferencing a pointer to const,
1352 so that we get the proper error message if the result is used
1353 to assign to. Also, &* is supposed to be a no-op.
1354 And ANSI C seems to specify that the type of the result
1355 should be the const type. */
1356 /* A de-reference of a pointer to const is not a const. It is valid
1357 to change it via some other pointer. */
1358 TREE_READONLY (ref
) = TYPE_READONLY (t
);
1359 TREE_SIDE_EFFECTS (ref
)
1360 = TYPE_VOLATILE (t
) || TREE_SIDE_EFFECTS (pointer
) || flag_volatile
;
1361 TREE_THIS_VOLATILE (ref
) = TYPE_VOLATILE (t
);
1365 else if (TREE_CODE (pointer
) != ERROR_MARK
)
1366 error ("invalid type argument of `%s'", errorstring
);
1367 return error_mark_node
;
1370 /* This handles expressions of the form "a[i]", which denotes
1373 This is logically equivalent in C to *(a+i), but we may do it differently.
1374 If A is a variable or a member, we generate a primitive ARRAY_REF.
1375 This avoids forcing the array out of registers, and can work on
1376 arrays that are not lvalues (for example, members of structures returned
1380 build_array_ref (array
, index
)
1385 error ("subscript missing in array reference");
1386 return error_mark_node
;
1389 if (TREE_TYPE (array
) == error_mark_node
1390 || TREE_TYPE (index
) == error_mark_node
)
1391 return error_mark_node
;
1393 if (TREE_CODE (TREE_TYPE (array
)) == ARRAY_TYPE
1394 && TREE_CODE (array
) != INDIRECT_REF
)
1398 /* Subscripting with type char is likely to lose
1399 on a machine where chars are signed.
1400 So warn on any machine, but optionally.
1401 Don't warn for unsigned char since that type is safe.
1402 Don't warn for signed char because anyone who uses that
1403 must have done so deliberately. */
1404 if (warn_char_subscripts
1405 && TYPE_MAIN_VARIANT (TREE_TYPE (index
)) == char_type_node
)
1406 warning ("array subscript has type `char'");
1408 /* Apply default promotions *after* noticing character types. */
1409 index
= default_conversion (index
);
1411 /* Require integer *after* promotion, for sake of enums. */
1412 if (TREE_CODE (TREE_TYPE (index
)) != INTEGER_TYPE
)
1414 error ("array subscript is not an integer");
1415 return error_mark_node
;
1418 /* An array that is indexed by a non-constant
1419 cannot be stored in a register; we must be able to do
1420 address arithmetic on its address.
1421 Likewise an array of elements of variable size. */
1422 if (TREE_CODE (index
) != INTEGER_CST
1423 || (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array
))) != 0
1424 && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array
)))) != INTEGER_CST
))
1426 if (mark_addressable (array
) == 0)
1427 return error_mark_node
;
1429 /* An array that is indexed by a constant value which is not within
1430 the array bounds cannot be stored in a register either; because we
1431 would get a crash in store_bit_field/extract_bit_field when trying
1432 to access a non-existent part of the register. */
1433 if (TREE_CODE (index
) == INTEGER_CST
1434 && TYPE_VALUES (TREE_TYPE (array
))
1435 && ! int_fits_type_p (index
, TYPE_VALUES (TREE_TYPE (array
))))
1437 if (mark_addressable (array
) == 0)
1438 return error_mark_node
;
1441 if (pedantic
&& !lvalue_p (array
))
1443 if (DECL_REGISTER (array
))
1444 pedwarn ("ANSI C forbids subscripting `register' array");
1446 pedwarn ("ANSI C forbids subscripting non-lvalue array");
1452 while (TREE_CODE (foo
) == COMPONENT_REF
)
1453 foo
= TREE_OPERAND (foo
, 0);
1454 if (TREE_CODE (foo
) == VAR_DECL
&& DECL_REGISTER (foo
))
1455 pedwarn ("ANSI C forbids subscripting non-lvalue array");
1458 type
= TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (array
)));
1459 rval
= build (ARRAY_REF
, type
, array
, index
);
1460 /* Array ref is const/volatile if the array elements are
1461 or if the array is. */
1462 TREE_READONLY (rval
)
1463 |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array
)))
1464 | TREE_READONLY (array
));
1465 TREE_SIDE_EFFECTS (rval
)
1466 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array
)))
1467 | TREE_SIDE_EFFECTS (array
));
1468 TREE_THIS_VOLATILE (rval
)
1469 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array
)))
1470 /* This was added by rms on 16 Nov 91.
1471 It fixes vol struct foo *a; a->elts[1]
1472 in an inline function.
1473 Hope it doesn't break something else. */
1474 | TREE_THIS_VOLATILE (array
));
1475 return require_complete_type (fold (rval
));
1479 tree ar
= default_conversion (array
);
1480 tree ind
= default_conversion (index
);
1482 /* Do the same warning check as above, but only on the part that's
1483 syntactically the index and only if it is also semantically
1485 if (warn_char_subscripts
1486 && TREE_CODE (TREE_TYPE (index
)) == INTEGER_TYPE
1487 && TYPE_MAIN_VARIANT (TREE_TYPE (index
)) == char_type_node
)
1488 warning ("subscript has type `char'");
1490 /* Put the integer in IND to simplify error checking. */
1491 if (TREE_CODE (TREE_TYPE (ar
)) == INTEGER_TYPE
)
1498 if (ar
== error_mark_node
)
1501 if (TREE_CODE (TREE_TYPE (ar
)) != POINTER_TYPE
1502 || TREE_CODE (TREE_TYPE (TREE_TYPE (ar
))) == FUNCTION_TYPE
)
1504 error ("subscripted value is neither array nor pointer");
1505 return error_mark_node
;
1507 if (TREE_CODE (TREE_TYPE (ind
)) != INTEGER_TYPE
)
1509 error ("array subscript is not an integer");
1510 return error_mark_node
;
1513 return build_indirect_ref (build_binary_op (PLUS_EXPR
, ar
, ind
, 0),
1518 /* Build a function call to function FUNCTION with parameters PARAMS.
1519 PARAMS is a list--a chain of TREE_LIST nodes--in which the
1520 TREE_VALUE of each node is a parameter-expression.
1521 FUNCTION's data type may be a function type or a pointer-to-function. */
1524 build_function_call (function
, params
)
1525 tree function
, params
;
1527 register tree fntype
, fundecl
= 0;
1528 register tree coerced_params
;
1529 tree name
= NULL_TREE
, assembler_name
= NULL_TREE
;
1531 /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
1532 STRIP_TYPE_NOPS (function
);
1534 /* Convert anything with function type to a pointer-to-function. */
1535 if (TREE_CODE (function
) == FUNCTION_DECL
)
1537 name
= DECL_NAME (function
);
1538 assembler_name
= DECL_ASSEMBLER_NAME (function
);
1540 /* Differs from default_conversion by not setting TREE_ADDRESSABLE
1541 (because calling an inline function does not mean the function
1542 needs to be separately compiled). */
1543 fntype
= build_type_variant (TREE_TYPE (function
),
1544 TREE_READONLY (function
),
1545 TREE_THIS_VOLATILE (function
));
1547 function
= build1 (ADDR_EXPR
, build_pointer_type (fntype
), function
);
1550 function
= default_conversion (function
);
1552 fntype
= TREE_TYPE (function
);
1554 if (TREE_CODE (fntype
) == ERROR_MARK
)
1555 return error_mark_node
;
1557 if (!(TREE_CODE (fntype
) == POINTER_TYPE
1558 && TREE_CODE (TREE_TYPE (fntype
)) == FUNCTION_TYPE
))
1560 error ("called object is not a function");
1561 return error_mark_node
;
1564 /* fntype now gets the type of function pointed to. */
1565 fntype
= TREE_TYPE (fntype
);
1567 /* Convert the parameters to the types declared in the
1568 function prototype, or apply default promotions. */
1571 = convert_arguments (TYPE_ARG_TYPES (fntype
), params
, name
, fundecl
);
1573 /* Check for errors in format strings. */
1575 if (warn_format
&& (name
|| assembler_name
))
1576 check_function_format (name
, assembler_name
, coerced_params
);
1578 /* Recognize certain built-in functions so we can make tree-codes
1579 other than CALL_EXPR. We do this when it enables fold-const.c
1580 to do something useful. */
1582 if (TREE_CODE (function
) == ADDR_EXPR
1583 && TREE_CODE (TREE_OPERAND (function
, 0)) == FUNCTION_DECL
1584 && DECL_BUILT_IN (TREE_OPERAND (function
, 0)))
1585 switch (DECL_FUNCTION_CODE (TREE_OPERAND (function
, 0)))
1590 if (coerced_params
== 0)
1591 return integer_zero_node
;
1592 return build_unary_op (ABS_EXPR
, TREE_VALUE (coerced_params
), 0);
1598 register tree result
1599 = build (CALL_EXPR
, TREE_TYPE (fntype
),
1600 function
, coerced_params
, NULL_TREE
);
1602 TREE_SIDE_EFFECTS (result
) = 1;
1603 if (TREE_TYPE (result
) == void_type_node
)
1605 return require_complete_type (result
);
1609 /* Convert the argument expressions in the list VALUES
1610 to the types in the list TYPELIST. The result is a list of converted
1611 argument expressions.
1613 If TYPELIST is exhausted, or when an element has NULL as its type,
1614 perform the default conversions.
1616 PARMLIST is the chain of parm decls for the function being called.
1617 It may be 0, if that info is not available.
1618 It is used only for generating error messages.
1620 NAME is an IDENTIFIER_NODE or 0. It is used only for error messages.
1622 This is also where warnings about wrong number of args are generated.
1624 Both VALUES and the returned value are chains of TREE_LIST nodes
1625 with the elements of the list in the TREE_VALUE slots of those nodes. */
1628 convert_arguments (typelist
, values
, name
, fundecl
)
1629 tree typelist
, values
, name
, fundecl
;
1631 register tree typetail
, valtail
;
1632 register tree result
= NULL
;
1635 /* Scan the given expressions and types, producing individual
1636 converted arguments and pushing them on RESULT in reverse order. */
1638 for (valtail
= values
, typetail
= typelist
, parmnum
= 0;
1640 valtail
= TREE_CHAIN (valtail
), parmnum
++)
1642 register tree type
= typetail
? TREE_VALUE (typetail
) : 0;
1643 register tree val
= TREE_VALUE (valtail
);
1645 if (type
== void_type_node
)
1648 error ("too many arguments to function `%s'",
1649 IDENTIFIER_POINTER (name
));
1651 error ("too many arguments to function");
1655 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
1656 /* Do not use STRIP_NOPS here! We do not want an enumerator with value 0
1657 to convert automatically to a pointer. */
1658 if (TREE_CODE (val
) == NON_LVALUE_EXPR
)
1659 val
= TREE_OPERAND (val
, 0);
1661 if (TREE_CODE (TREE_TYPE (val
)) == ARRAY_TYPE
1662 || TREE_CODE (TREE_TYPE (val
)) == FUNCTION_TYPE
)
1663 val
= default_conversion (val
);
1665 val
= require_complete_type (val
);
1669 /* Formal parm type is specified by a function prototype. */
1672 if (TYPE_SIZE (type
) == 0)
1674 error ("type of formal parameter %d is incomplete", parmnum
+ 1);
1679 /* Optionally warn about conversions that
1680 differ from the default conversions. */
1681 if (warn_conversion
)
1683 int formal_prec
= TYPE_PRECISION (type
);
1685 if (INTEGRAL_TYPE_P (type
)
1686 && TREE_CODE (TREE_TYPE (val
)) == REAL_TYPE
)
1687 warn_for_assignment ("%s as integer rather than floating due to prototype", (char *) 0, name
, parmnum
+ 1);
1688 else if (TREE_CODE (type
) == COMPLEX_TYPE
1689 && TREE_CODE (TREE_TYPE (val
)) == REAL_TYPE
)
1690 warn_for_assignment ("%s as complex rather than floating due to prototype", (char *) 0, name
, parmnum
+ 1);
1691 else if (TREE_CODE (type
) == REAL_TYPE
1692 && INTEGRAL_TYPE_P (TREE_TYPE (val
)))
1693 warn_for_assignment ("%s as floating rather than integer due to prototype", (char *) 0, name
, parmnum
+ 1);
1694 else if (TREE_CODE (type
) == REAL_TYPE
1695 && TREE_CODE (TREE_TYPE (val
)) == COMPLEX_TYPE
)
1696 warn_for_assignment ("%s as floating rather than complex due to prototype", (char *) 0, name
, parmnum
+ 1);
1697 /* ??? At some point, messages should be written about
1698 conversions between complex types, but that's too messy
1700 else if (TREE_CODE (type
) == REAL_TYPE
1701 && TREE_CODE (TREE_TYPE (val
)) == REAL_TYPE
)
1703 /* Warn if any argument is passed as `float',
1704 since without a prototype it would be `double'. */
1705 if (formal_prec
== TYPE_PRECISION (float_type_node
))
1706 warn_for_assignment ("%s as `float' rather than `double' due to prototype", (char *) 0, name
, parmnum
+ 1);
1708 /* Detect integer changing in width or signedness. */
1709 else if (INTEGRAL_TYPE_P (type
)
1710 && INTEGRAL_TYPE_P (TREE_TYPE (val
)))
1712 tree would_have_been
= default_conversion (val
);
1713 tree type1
= TREE_TYPE (would_have_been
);
1715 if (TREE_CODE (type
) == ENUMERAL_TYPE
1716 && type
== TREE_TYPE (val
))
1717 /* No warning if function asks for enum
1718 and the actual arg is that enum type. */
1720 else if (formal_prec
!= TYPE_PRECISION (type1
))
1721 warn_for_assignment ("%s with different width due to prototype", (char *) 0, name
, parmnum
+ 1);
1722 else if (TREE_UNSIGNED (type
) == TREE_UNSIGNED (type1
))
1724 /* Don't complain if the formal parameter type
1725 is an enum, because we can't tell now whether
1726 the value was an enum--even the same enum. */
1727 else if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1729 else if (TREE_CODE (val
) == INTEGER_CST
1730 && int_fits_type_p (val
, type
))
1731 /* Change in signedness doesn't matter
1732 if a constant value is unaffected. */
1734 /* Likewise for a constant in a NOP_EXPR. */
1735 else if (TREE_CODE (val
) == NOP_EXPR
1736 && TREE_CODE (TREE_OPERAND (val
, 0)) == INTEGER_CST
1737 && int_fits_type_p (TREE_OPERAND (val
, 0), type
))
1739 #if 0 /* We never get such tree structure here. */
1740 else if (TREE_CODE (TREE_TYPE (val
)) == ENUMERAL_TYPE
1741 && int_fits_type_p (TYPE_MIN_VALUE (TREE_TYPE (val
)), type
)
1742 && int_fits_type_p (TYPE_MAX_VALUE (TREE_TYPE (val
)), type
))
1743 /* Change in signedness doesn't matter
1744 if an enum value is unaffected. */
1747 /* If the value is extended from a narrower
1748 unsigned type, it doesn't matter whether we
1749 pass it as signed or unsigned; the value
1750 certainly is the same either way. */
1751 else if (TYPE_PRECISION (TREE_TYPE (val
)) < TYPE_PRECISION (type
)
1752 && TREE_UNSIGNED (TREE_TYPE (val
)))
1754 else if (TREE_UNSIGNED (type
))
1755 warn_for_assignment ("%s as unsigned due to prototype", (char *) 0, name
, parmnum
+ 1);
1757 warn_for_assignment ("%s as signed due to prototype", (char *) 0, name
, parmnum
+ 1);
1761 parmval
= convert_for_assignment (type
, val
,
1762 (char *) 0, /* arg passing */
1763 fundecl
, name
, parmnum
+ 1);
1765 #ifdef PROMOTE_PROTOTYPES
1766 if ((TREE_CODE (type
) == INTEGER_TYPE
1767 || TREE_CODE (type
) == ENUMERAL_TYPE
)
1768 && (TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
)))
1769 parmval
= default_conversion (parmval
);
1772 result
= tree_cons (NULL_TREE
, parmval
, result
);
1774 else if (TREE_CODE (TREE_TYPE (val
)) == REAL_TYPE
1775 && (TYPE_PRECISION (TREE_TYPE (val
))
1776 < TYPE_PRECISION (double_type_node
)))
1777 /* Convert `float' to `double'. */
1778 result
= tree_cons (NULL_TREE
, convert (double_type_node
, val
), result
);
1780 /* Convert `short' and `char' to full-size `int'. */
1781 result
= tree_cons (NULL_TREE
, default_conversion (val
), result
);
1784 typetail
= TREE_CHAIN (typetail
);
1787 if (typetail
!= 0 && TREE_VALUE (typetail
) != void_type_node
)
1790 error ("too few arguments to function `%s'",
1791 IDENTIFIER_POINTER (name
));
1793 error ("too few arguments to function");
1796 return nreverse (result
);
1799 /* This is the entry point used by the parser
1800 for binary operators in the input.
1801 In addition to constructing the expression,
1802 we check for operands that were written with other binary operators
1803 in a way that is likely to confuse the user. */
1806 parser_build_binary_op (code
, arg1
, arg2
)
1807 enum tree_code code
;
1810 tree result
= build_binary_op (code
, arg1
, arg2
, 1);
1813 char class1
= TREE_CODE_CLASS (TREE_CODE (arg1
));
1814 char class2
= TREE_CODE_CLASS (TREE_CODE (arg2
));
1815 enum tree_code code1
= ERROR_MARK
;
1816 enum tree_code code2
= ERROR_MARK
;
1818 if (class1
== 'e' || class1
== '1'
1819 || class1
== '2' || class1
== '<')
1820 code1
= C_EXP_ORIGINAL_CODE (arg1
);
1821 if (class2
== 'e' || class2
== '1'
1822 || class2
== '2' || class2
== '<')
1823 code2
= C_EXP_ORIGINAL_CODE (arg2
);
1825 /* Check for cases such as x+y<<z which users are likely
1826 to misinterpret. If parens are used, C_EXP_ORIGINAL_CODE
1827 is cleared to prevent these warnings. */
1828 if (warn_parentheses
)
1830 if (code
== LSHIFT_EXPR
|| code
== RSHIFT_EXPR
)
1832 if (code1
== PLUS_EXPR
|| code1
== MINUS_EXPR
1833 || code2
== PLUS_EXPR
|| code2
== MINUS_EXPR
)
1834 warning ("suggest parentheses around + or - inside shift");
1837 if (code
== TRUTH_ORIF_EXPR
)
1839 if (code1
== TRUTH_ANDIF_EXPR
1840 || code2
== TRUTH_ANDIF_EXPR
)
1841 warning ("suggest parentheses around && within ||");
1844 if (code
== BIT_IOR_EXPR
)
1846 if (code1
== BIT_AND_EXPR
|| code1
== BIT_XOR_EXPR
1847 || code1
== PLUS_EXPR
|| code1
== MINUS_EXPR
1848 || code2
== BIT_AND_EXPR
|| code2
== BIT_XOR_EXPR
1849 || code2
== PLUS_EXPR
|| code2
== MINUS_EXPR
)
1850 warning ("suggest parentheses around arithmetic in operand of |");
1851 /* Check cases like x|y==z */
1852 if (TREE_CODE_CLASS (code1
) == '<' || TREE_CODE_CLASS (code2
) == '<')
1853 warning ("suggest parentheses around comparison in operand of |");
1856 if (code
== BIT_XOR_EXPR
)
1858 if (code1
== BIT_AND_EXPR
1859 || code1
== PLUS_EXPR
|| code1
== MINUS_EXPR
1860 || code2
== BIT_AND_EXPR
1861 || code2
== PLUS_EXPR
|| code2
== MINUS_EXPR
)
1862 warning ("suggest parentheses around arithmetic in operand of ^");
1863 /* Check cases like x^y==z */
1864 if (TREE_CODE_CLASS (code1
) == '<' || TREE_CODE_CLASS (code2
) == '<')
1865 warning ("suggest parentheses around comparison in operand of ^");
1868 if (code
== BIT_AND_EXPR
)
1870 if (code1
== PLUS_EXPR
|| code1
== MINUS_EXPR
1871 || code2
== PLUS_EXPR
|| code2
== MINUS_EXPR
)
1872 warning ("suggest parentheses around + or - in operand of &");
1873 /* Check cases like x&y==z */
1874 if (TREE_CODE_CLASS (code1
) == '<' || TREE_CODE_CLASS (code2
) == '<')
1875 warning ("suggest parentheses around comparison in operand of &");
1879 /* Similarly, check for cases like 1<=i<=10 that are probably errors. */
1880 if (TREE_CODE_CLASS (code
) == '<' && extra_warnings
1881 && (TREE_CODE_CLASS (code1
) == '<' || TREE_CODE_CLASS (code2
) == '<'))
1882 warning ("comparisons like X<=Y<=Z do not have their mathematical meaning");
1884 unsigned_conversion_warning (result
, arg1
);
1885 unsigned_conversion_warning (result
, arg2
);
1886 overflow_warning (result
);
1888 class = TREE_CODE_CLASS (TREE_CODE (result
));
1890 /* Record the code that was specified in the source,
1891 for the sake of warnings about confusing nesting. */
1892 if (class == 'e' || class == '1'
1893 || class == '2' || class == '<')
1894 C_SET_EXP_ORIGINAL_CODE (result
, code
);
1897 int flag
= TREE_CONSTANT (result
);
1898 /* We used to use NOP_EXPR rather than NON_LVALUE_EXPR
1899 so that convert_for_assignment wouldn't strip it.
1900 That way, we got warnings for things like p = (1 - 1).
1901 But it turns out we should not get those warnings. */
1902 result
= build1 (NON_LVALUE_EXPR
, TREE_TYPE (result
), result
);
1903 C_SET_EXP_ORIGINAL_CODE (result
, code
);
1904 TREE_CONSTANT (result
) = flag
;
1910 /* Build a binary-operation expression without default conversions.
1911 CODE is the kind of expression to build.
1912 This function differs from `build' in several ways:
1913 the data type of the result is computed and recorded in it,
1914 warnings are generated if arg data types are invalid,
1915 special handling for addition and subtraction of pointers is known,
1916 and some optimization is done (operations on narrow ints
1917 are done in the narrower type when that gives the same result).
1918 Constant folding is also done before the result is returned.
1920 Note that the operands will never have enumeral types, or function
1921 or array types, because either they will have the default conversions
1922 performed or they have both just been converted to some other type in which
1923 the arithmetic is to be done. */
1926 build_binary_op (code
, orig_op0
, orig_op1
, convert_p
)
1927 enum tree_code code
;
1928 tree orig_op0
, orig_op1
;
1932 register enum tree_code code0
, code1
;
1935 /* Expression code to give to the expression when it is built.
1936 Normally this is CODE, which is what the caller asked for,
1937 but in some special cases we change it. */
1938 register enum tree_code resultcode
= code
;
1940 /* Data type in which the computation is to be performed.
1941 In the simplest cases this is the common type of the arguments. */
1942 register tree result_type
= NULL
;
1944 /* Nonzero means operands have already been type-converted
1945 in whatever way is necessary.
1946 Zero means they need to be converted to RESULT_TYPE. */
1949 /* Nonzero means create the expression with this type, rather than
1951 tree build_type
= 0;
1953 /* Nonzero means after finally constructing the expression
1954 convert it to this type. */
1955 tree final_type
= 0;
1957 /* Nonzero if this is an operation like MIN or MAX which can
1958 safely be computed in short if both args are promoted shorts.
1959 Also implies COMMON.
1960 -1 indicates a bitwise operation; this makes a difference
1961 in the exact conditions for when it is safe to do the operation
1962 in a narrower mode. */
1965 /* Nonzero if this is a comparison operation;
1966 if both args are promoted shorts, compare the original shorts.
1967 Also implies COMMON. */
1968 int short_compare
= 0;
1970 /* Nonzero if this is a right-shift operation, which can be computed on the
1971 original short and then promoted if the operand is a promoted short. */
1972 int short_shift
= 0;
1974 /* Nonzero means set RESULT_TYPE to the common type of the args. */
1979 op0
= default_conversion (orig_op0
);
1980 op1
= default_conversion (orig_op1
);
1988 type0
= TREE_TYPE (op0
);
1989 type1
= TREE_TYPE (op1
);
1991 /* The expression codes of the data types of the arguments tell us
1992 whether the arguments are integers, floating, pointers, etc. */
1993 code0
= TREE_CODE (type0
);
1994 code1
= TREE_CODE (type1
);
1996 /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
1997 STRIP_TYPE_NOPS (op0
);
1998 STRIP_TYPE_NOPS (op1
);
2000 /* If an error was already reported for one of the arguments,
2001 avoid reporting another error. */
2003 if (code0
== ERROR_MARK
|| code1
== ERROR_MARK
)
2004 return error_mark_node
;
2009 /* Handle the pointer + int case. */
2010 if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
2011 return pointer_int_sum (PLUS_EXPR
, op0
, op1
);
2012 else if (code1
== POINTER_TYPE
&& code0
== INTEGER_TYPE
)
2013 return pointer_int_sum (PLUS_EXPR
, op1
, op0
);
2019 /* Subtraction of two similar pointers.
2020 We must subtract them as integers, then divide by object size. */
2021 if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
2022 && comp_target_types (type0
, type1
))
2023 return pointer_diff (op0
, op1
);
2024 /* Handle pointer minus int. Just like pointer plus int. */
2025 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
2026 return pointer_int_sum (MINUS_EXPR
, op0
, op1
);
2035 case TRUNC_DIV_EXPR
:
2037 case FLOOR_DIV_EXPR
:
2038 case ROUND_DIV_EXPR
:
2039 case EXACT_DIV_EXPR
:
2040 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
2041 || code0
== COMPLEX_TYPE
)
2042 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
2043 || code1
== COMPLEX_TYPE
))
2045 if (!(code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
))
2046 resultcode
= RDIV_EXPR
;
2049 /* Although it would be tempting to shorten always here, that
2050 loses on some targets, since the modulo instruction is
2051 undefined if the quotient can't be represented in the
2052 computation mode. We shorten only if unsigned or if
2053 dividing by something we know != -1. */
2054 shorten
= (TREE_UNSIGNED (TREE_TYPE (orig_op0
))
2055 || (TREE_CODE (op1
) == INTEGER_CST
2056 && (TREE_INT_CST_LOW (op1
) != -1
2057 || TREE_INT_CST_HIGH (op1
) != -1)));
2064 case BIT_ANDTC_EXPR
:
2067 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
2069 /* If one operand is a constant, and the other is a short type
2070 that has been converted to an int,
2071 really do the work in the short type and then convert the
2072 result to int. If we are lucky, the constant will be 0 or 1
2073 in the short type, making the entire operation go away. */
2074 if (TREE_CODE (op0
) == INTEGER_CST
2075 && TREE_CODE (op1
) == NOP_EXPR
2076 && TYPE_PRECISION (type1
) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op1
, 0)))
2077 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op1
, 0))))
2079 final_type
= result_type
;
2080 op1
= TREE_OPERAND (op1
, 0);
2081 result_type
= TREE_TYPE (op1
);
2083 if (TREE_CODE (op1
) == INTEGER_CST
2084 && TREE_CODE (op0
) == NOP_EXPR
2085 && TYPE_PRECISION (type0
) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0
, 0)))
2086 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0
, 0))))
2088 final_type
= result_type
;
2089 op0
= TREE_OPERAND (op0
, 0);
2090 result_type
= TREE_TYPE (op0
);
2094 case TRUNC_MOD_EXPR
:
2095 case FLOOR_MOD_EXPR
:
2096 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
2098 /* Although it would be tempting to shorten always here, that loses
2099 on some targets, since the modulo instruction is undefined if the
2100 quotient can't be represented in the computation mode. We shorten
2101 only if unsigned or if dividing by something we know != -1. */
2102 shorten
= (TREE_UNSIGNED (TREE_TYPE (orig_op0
))
2103 || (TREE_CODE (op1
) == INTEGER_CST
2104 && (TREE_INT_CST_LOW (op1
) != -1
2105 || TREE_INT_CST_HIGH (op1
) != -1)));
2110 case TRUTH_ANDIF_EXPR
:
2111 case TRUTH_ORIF_EXPR
:
2112 case TRUTH_AND_EXPR
:
2114 case TRUTH_XOR_EXPR
:
2115 if ((code0
== INTEGER_TYPE
|| code0
== POINTER_TYPE
2116 || code0
== REAL_TYPE
|| code0
== COMPLEX_TYPE
)
2117 && (code1
== INTEGER_TYPE
|| code1
== POINTER_TYPE
2118 || code1
== REAL_TYPE
|| code1
== COMPLEX_TYPE
))
2120 /* Result of these operations is always an int,
2121 but that does not mean the operands should be
2122 converted to ints! */
2123 result_type
= integer_type_node
;
2124 op0
= truthvalue_conversion (op0
);
2125 op1
= truthvalue_conversion (op1
);
2130 /* Shift operations: result has same type as first operand;
2131 always convert second operand to int.
2132 Also set SHORT_SHIFT if shifting rightward. */
2135 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
2137 if (TREE_CODE (op1
) == INTEGER_CST
&& skip_evaluation
== 0)
2139 if (tree_int_cst_sgn (op1
) < 0)
2140 warning ("right shift count is negative");
2143 if (TREE_INT_CST_LOW (op1
) | TREE_INT_CST_HIGH (op1
))
2145 if (TREE_INT_CST_HIGH (op1
) != 0
2146 || ((unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (op1
)
2147 >= TYPE_PRECISION (type0
)))
2148 warning ("right shift count >= width of type");
2151 /* Use the type of the value to be shifted.
2152 This is what most traditional C compilers do. */
2153 result_type
= type0
;
2154 /* Unless traditional, convert the shift-count to an integer,
2155 regardless of size of value being shifted. */
2156 if (! flag_traditional
)
2158 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
2159 op1
= convert (integer_type_node
, op1
);
2160 /* Avoid converting op1 to result_type later. */
2167 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
2169 if (TREE_CODE (op1
) == INTEGER_CST
&& skip_evaluation
== 0)
2171 if (tree_int_cst_sgn (op1
) < 0)
2172 warning ("left shift count is negative");
2173 else if (TREE_INT_CST_HIGH (op1
) != 0
2174 || ((unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (op1
)
2175 >= TYPE_PRECISION (type0
)))
2176 warning ("left shift count >= width of type");
2178 /* Use the type of the value to be shifted.
2179 This is what most traditional C compilers do. */
2180 result_type
= type0
;
2181 /* Unless traditional, convert the shift-count to an integer,
2182 regardless of size of value being shifted. */
2183 if (! flag_traditional
)
2185 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
2186 op1
= convert (integer_type_node
, op1
);
2187 /* Avoid converting op1 to result_type later. */
2195 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
2197 if (TREE_CODE (op1
) == INTEGER_CST
&& skip_evaluation
== 0)
2199 if (tree_int_cst_sgn (op1
) < 0)
2200 warning ("shift count is negative");
2201 else if (TREE_INT_CST_HIGH (op1
) != 0
2202 || ((unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (op1
)
2203 >= TYPE_PRECISION (type0
)))
2204 warning ("shift count >= width of type");
2206 /* Use the type of the value to be shifted.
2207 This is what most traditional C compilers do. */
2208 result_type
= type0
;
2209 /* Unless traditional, convert the shift-count to an integer,
2210 regardless of size of value being shifted. */
2211 if (! flag_traditional
)
2213 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
2214 op1
= convert (integer_type_node
, op1
);
2215 /* Avoid converting op1 to result_type later. */
2223 /* Result of comparison is always int,
2224 but don't convert the args to int! */
2225 build_type
= integer_type_node
;
2226 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
2227 || code0
== COMPLEX_TYPE
)
2228 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
2229 || code1
== COMPLEX_TYPE
))
2231 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
2233 register tree tt0
= TREE_TYPE (type0
);
2234 register tree tt1
= TREE_TYPE (type1
);
2235 /* Anything compares with void *. void * compares with anything.
2236 Otherwise, the targets must be compatible
2237 and both must be object or both incomplete. */
2238 if (comp_target_types (type0
, type1
))
2239 result_type
= common_type (type0
, type1
);
2240 else if (TYPE_MAIN_VARIANT (tt0
) == void_type_node
)
2242 /* op0 != orig_op0 detects the case of something
2243 whose value is 0 but which isn't a valid null ptr const. */
2244 if (pedantic
&& (!integer_zerop (op0
) || op0
!= orig_op0
)
2245 && TREE_CODE (tt1
) == FUNCTION_TYPE
)
2246 pedwarn ("ANSI C forbids comparison of `void *' with function pointer");
2248 else if (TYPE_MAIN_VARIANT (tt1
) == void_type_node
)
2250 if (pedantic
&& (!integer_zerop (op1
) || op1
!= orig_op1
)
2251 && TREE_CODE (tt0
) == FUNCTION_TYPE
)
2252 pedwarn ("ANSI C forbids comparison of `void *' with function pointer");
2255 pedwarn ("comparison of distinct pointer types lacks a cast");
2257 if (result_type
== NULL_TREE
)
2258 result_type
= ptr_type_node
;
2260 else if (code0
== POINTER_TYPE
&& TREE_CODE (op1
) == INTEGER_CST
2261 && integer_zerop (op1
))
2262 result_type
= type0
;
2263 else if (code1
== POINTER_TYPE
&& TREE_CODE (op0
) == INTEGER_CST
2264 && integer_zerop (op0
))
2265 result_type
= type1
;
2266 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
2268 result_type
= type0
;
2269 if (! flag_traditional
)
2270 pedwarn ("comparison between pointer and integer");
2272 else if (code0
== INTEGER_TYPE
&& code1
== POINTER_TYPE
)
2274 result_type
= type1
;
2275 if (! flag_traditional
)
2276 pedwarn ("comparison between pointer and integer");
2282 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
2283 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
2285 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
2287 if (comp_target_types (type0
, type1
))
2289 result_type
= common_type (type0
, type1
);
2291 && TREE_CODE (TREE_TYPE (type0
)) == FUNCTION_TYPE
)
2292 pedwarn ("ANSI C forbids ordered comparisons of pointers to functions");
2296 result_type
= ptr_type_node
;
2297 pedwarn ("comparison of distinct pointer types lacks a cast");
2306 build_type
= integer_type_node
;
2307 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
2308 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
2310 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
2312 if (comp_target_types (type0
, type1
))
2314 result_type
= common_type (type0
, type1
);
2315 if ((TYPE_SIZE (TREE_TYPE (type0
)) != 0)
2316 != (TYPE_SIZE (TREE_TYPE (type1
)) != 0))
2317 pedwarn ("comparison of complete and incomplete pointers");
2319 && TREE_CODE (TREE_TYPE (type0
)) == FUNCTION_TYPE
)
2320 pedwarn ("ANSI C forbids ordered comparisons of pointers to functions");
2324 result_type
= ptr_type_node
;
2325 pedwarn ("comparison of distinct pointer types lacks a cast");
2328 else if (code0
== POINTER_TYPE
&& TREE_CODE (op1
) == INTEGER_CST
2329 && integer_zerop (op1
))
2331 result_type
= type0
;
2332 if (pedantic
|| extra_warnings
)
2333 pedwarn ("ordered comparison of pointer with integer zero");
2335 else if (code1
== POINTER_TYPE
&& TREE_CODE (op0
) == INTEGER_CST
2336 && integer_zerop (op0
))
2338 result_type
= type1
;
2340 pedwarn ("ordered comparison of pointer with integer zero");
2342 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
2344 result_type
= type0
;
2345 if (! flag_traditional
)
2346 pedwarn ("comparison between pointer and integer");
2348 else if (code0
== INTEGER_TYPE
&& code1
== POINTER_TYPE
)
2350 result_type
= type1
;
2351 if (! flag_traditional
)
2352 pedwarn ("comparison between pointer and integer");
2360 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
|| code0
== COMPLEX_TYPE
)
2362 (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
|| code1
== COMPLEX_TYPE
))
2364 int none_complex
= (code0
!= COMPLEX_TYPE
&& code1
!= COMPLEX_TYPE
);
2366 if (shorten
|| common
|| short_compare
)
2367 result_type
= common_type (type0
, type1
);
2369 /* For certain operations (which identify themselves by shorten != 0)
2370 if both args were extended from the same smaller type,
2371 do the arithmetic in that type and then extend.
2373 shorten !=0 and !=1 indicates a bitwise operation.
2374 For them, this optimization is safe only if
2375 both args are zero-extended or both are sign-extended.
2376 Otherwise, we might change the result.
2377 Eg, (short)-1 | (unsigned short)-1 is (int)-1
2378 but calculated in (unsigned short) it would be (unsigned short)-1. */
2380 if (shorten
&& none_complex
)
2382 int unsigned0
, unsigned1
;
2383 tree arg0
= get_narrower (op0
, &unsigned0
);
2384 tree arg1
= get_narrower (op1
, &unsigned1
);
2385 /* UNS is 1 if the operation to be done is an unsigned one. */
2386 int uns
= TREE_UNSIGNED (result_type
);
2389 final_type
= result_type
;
2391 /* Handle the case that OP0 (or OP1) does not *contain* a conversion
2392 but it *requires* conversion to FINAL_TYPE. */
2394 if ((TYPE_PRECISION (TREE_TYPE (op0
))
2395 == TYPE_PRECISION (TREE_TYPE (arg0
)))
2396 && TREE_TYPE (op0
) != final_type
)
2397 unsigned0
= TREE_UNSIGNED (TREE_TYPE (op0
));
2398 if ((TYPE_PRECISION (TREE_TYPE (op1
))
2399 == TYPE_PRECISION (TREE_TYPE (arg1
)))
2400 && TREE_TYPE (op1
) != final_type
)
2401 unsigned1
= TREE_UNSIGNED (TREE_TYPE (op1
));
2403 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
2405 /* For bitwise operations, signedness of nominal type
2406 does not matter. Consider only how operands were extended. */
2410 /* Note that in all three cases below we refrain from optimizing
2411 an unsigned operation on sign-extended args.
2412 That would not be valid. */
2414 /* Both args variable: if both extended in same way
2415 from same width, do it in that width.
2416 Do it unsigned if args were zero-extended. */
2417 if ((TYPE_PRECISION (TREE_TYPE (arg0
))
2418 < TYPE_PRECISION (result_type
))
2419 && (TYPE_PRECISION (TREE_TYPE (arg1
))
2420 == TYPE_PRECISION (TREE_TYPE (arg0
)))
2421 && unsigned0
== unsigned1
2422 && (unsigned0
|| !uns
))
2424 = signed_or_unsigned_type (unsigned0
,
2425 common_type (TREE_TYPE (arg0
), TREE_TYPE (arg1
)));
2426 else if (TREE_CODE (arg0
) == INTEGER_CST
2427 && (unsigned1
|| !uns
)
2428 && (TYPE_PRECISION (TREE_TYPE (arg1
))
2429 < TYPE_PRECISION (result_type
))
2430 && (type
= signed_or_unsigned_type (unsigned1
,
2432 int_fits_type_p (arg0
, type
)))
2434 else if (TREE_CODE (arg1
) == INTEGER_CST
2435 && (unsigned0
|| !uns
)
2436 && (TYPE_PRECISION (TREE_TYPE (arg0
))
2437 < TYPE_PRECISION (result_type
))
2438 && (type
= signed_or_unsigned_type (unsigned0
,
2440 int_fits_type_p (arg1
, type
)))
2444 /* Shifts can be shortened if shifting right. */
2449 tree arg0
= get_narrower (op0
, &unsigned_arg
);
2451 final_type
= result_type
;
2453 if (arg0
== op0
&& final_type
== TREE_TYPE (op0
))
2454 unsigned_arg
= TREE_UNSIGNED (TREE_TYPE (op0
));
2456 if (TYPE_PRECISION (TREE_TYPE (arg0
)) < TYPE_PRECISION (result_type
)
2457 /* We can shorten only if the shift count is less than the
2458 number of bits in the smaller type size. */
2459 && TREE_INT_CST_HIGH (op1
) == 0
2460 && TYPE_PRECISION (TREE_TYPE (arg0
)) > TREE_INT_CST_LOW (op1
)
2461 /* If arg is sign-extended and then unsigned-shifted,
2462 we can simulate this with a signed shift in arg's type
2463 only if the extended result is at least twice as wide
2464 as the arg. Otherwise, the shift could use up all the
2465 ones made by sign-extension and bring in zeros.
2466 We can't optimize that case at all, but in most machines
2467 it never happens because available widths are 2**N. */
2468 && (!TREE_UNSIGNED (final_type
)
2470 || 2 * TYPE_PRECISION (TREE_TYPE (arg0
)) <= TYPE_PRECISION (result_type
)))
2472 /* Do an unsigned shift if the operand was zero-extended. */
2474 = signed_or_unsigned_type (unsigned_arg
,
2476 /* Convert value-to-be-shifted to that type. */
2477 if (TREE_TYPE (op0
) != result_type
)
2478 op0
= convert (result_type
, op0
);
2483 /* Comparison operations are shortened too but differently.
2484 They identify themselves by setting short_compare = 1. */
2488 /* Don't write &op0, etc., because that would prevent op0
2489 from being kept in a register.
2490 Instead, make copies of the our local variables and
2491 pass the copies by reference, then copy them back afterward. */
2492 tree xop0
= op0
, xop1
= op1
, xresult_type
= result_type
;
2493 enum tree_code xresultcode
= resultcode
;
2495 = shorten_compare (&xop0
, &xop1
, &xresult_type
, &xresultcode
);
2498 op0
= xop0
, op1
= xop1
;
2500 resultcode
= xresultcode
;
2502 if ((warn_sign_compare
< 0 ? extra_warnings
: warn_sign_compare
!= 0)
2503 && skip_evaluation
== 0)
2505 int op0_signed
= ! TREE_UNSIGNED (TREE_TYPE (orig_op0
));
2506 int op1_signed
= ! TREE_UNSIGNED (TREE_TYPE (orig_op1
));
2508 int unsignedp0
, unsignedp1
;
2509 tree primop0
= get_narrower (op0
, &unsignedp0
);
2510 tree primop1
= get_narrower (op1
, &unsignedp1
);
2512 /* Avoid spurious warnings for comparison with enumerators. */
2516 STRIP_TYPE_NOPS (xop0
);
2517 STRIP_TYPE_NOPS (xop1
);
2519 /* Give warnings for comparisons between signed and unsigned
2520 quantities that may fail. */
2521 /* Do the checking based on the original operand trees, so that
2522 casts will be considered, but default promotions won't be. */
2524 /* Do not warn if the comparison is being done in a signed type,
2525 since the signed type will only be chosen if it can represent
2526 all the values of the unsigned type. */
2527 if (! TREE_UNSIGNED (result_type
))
2529 /* Do not warn if both operands are unsigned. */
2530 else if (op0_signed
== op1_signed
)
2532 /* Do not warn if the signed quantity is an unsuffixed
2533 integer literal (or some static constant expression
2534 involving such literals) and it is non-negative. */
2535 else if ((op0_signed
&& TREE_CODE (xop0
) == INTEGER_CST
2536 && tree_int_cst_sgn (xop0
) >= 0)
2537 || (op1_signed
&& TREE_CODE (xop1
) == INTEGER_CST
2538 && tree_int_cst_sgn (xop1
) >= 0))
2540 /* Do not warn if the comparison is an equality operation,
2541 the unsigned quantity is an integral constant and it does
2542 not use the most significant bit of result_type. */
2543 else if ((resultcode
== EQ_EXPR
|| resultcode
== NE_EXPR
)
2544 && ((op0_signed
&& TREE_CODE (xop1
) == INTEGER_CST
2545 && int_fits_type_p (xop1
, signed_type (result_type
)))
2546 || (op1_signed
&& TREE_CODE (xop0
) == INTEGER_CST
2547 && int_fits_type_p (xop0
, signed_type (result_type
)))))
2550 warning ("comparison between signed and unsigned");
2552 /* Warn if two unsigned values are being compared in a size
2553 larger than their original size, and one (and only one) is the
2554 result of a `~' operator. This comparison will always fail.
2556 Also warn if one operand is a constant, and the constant
2557 does not have all bits set that are set in the ~ operand
2558 when it is extended. */
2560 if ((TREE_CODE (primop0
) == BIT_NOT_EXPR
)
2561 != (TREE_CODE (primop1
) == BIT_NOT_EXPR
))
2563 if (TREE_CODE (primop0
) == BIT_NOT_EXPR
)
2564 primop0
= get_narrower (TREE_OPERAND (primop0
, 0),
2567 primop1
= get_narrower (TREE_OPERAND (primop1
, 0),
2570 if (TREE_CODE (primop0
) == INTEGER_CST
2571 || TREE_CODE (primop1
) == INTEGER_CST
)
2574 long constant
, mask
;
2575 int unsignedp
, bits
;
2577 if (TREE_CODE (primop0
) == INTEGER_CST
)
2580 unsignedp
= unsignedp1
;
2581 constant
= TREE_INT_CST_LOW (primop0
);
2586 unsignedp
= unsignedp0
;
2587 constant
= TREE_INT_CST_LOW (primop1
);
2590 bits
= TYPE_PRECISION (TREE_TYPE (primop
));
2591 if (bits
< TYPE_PRECISION (result_type
)
2592 && bits
< HOST_BITS_PER_LONG
&& unsignedp
)
2594 mask
= (~0L) << bits
;
2595 if ((mask
& constant
) != mask
)
2596 warning ("comparison of promoted ~unsigned with constant");
2599 else if (unsignedp0
&& unsignedp1
2600 && (TYPE_PRECISION (TREE_TYPE (primop0
))
2601 < TYPE_PRECISION (result_type
))
2602 && (TYPE_PRECISION (TREE_TYPE (primop1
))
2603 < TYPE_PRECISION (result_type
)))
2604 warning ("comparison of promoted ~unsigned with unsigned");
2610 /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
2611 If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
2612 Then the expression will be built.
2613 It will be given type FINAL_TYPE if that is nonzero;
2614 otherwise, it will be given type RESULT_TYPE. */
2618 binary_op_error (code
);
2619 return error_mark_node
;
2624 if (TREE_TYPE (op0
) != result_type
)
2625 op0
= convert (result_type
, op0
);
2626 if (TREE_TYPE (op1
) != result_type
)
2627 op1
= convert (result_type
, op1
);
2630 if (build_type
== NULL_TREE
)
2631 build_type
= result_type
;
2634 register tree result
= build (resultcode
, build_type
, op0
, op1
);
2635 register tree folded
;
2637 folded
= fold (result
);
2638 if (folded
== result
)
2639 TREE_CONSTANT (folded
) = TREE_CONSTANT (op0
) & TREE_CONSTANT (op1
);
2640 if (final_type
!= 0)
2641 return convert (final_type
, folded
);
2646 /* Return a tree for the sum or difference (RESULTCODE says which)
2647 of pointer PTROP and integer INTOP. */
2650 pointer_int_sum (resultcode
, ptrop
, intop
)
2651 enum tree_code resultcode
;
2652 register tree ptrop
, intop
;
2656 register tree result
;
2657 register tree folded
;
2659 /* The result is a pointer of the same type that is being added. */
2661 register tree result_type
= TREE_TYPE (ptrop
);
2663 if (TREE_CODE (TREE_TYPE (result_type
)) == VOID_TYPE
)
2665 if (pedantic
|| warn_pointer_arith
)
2666 pedwarn ("pointer of type `void *' used in arithmetic");
2667 size_exp
= integer_one_node
;
2669 else if (TREE_CODE (TREE_TYPE (result_type
)) == FUNCTION_TYPE
)
2671 if (pedantic
|| warn_pointer_arith
)
2672 pedwarn ("pointer to a function used in arithmetic");
2673 size_exp
= integer_one_node
;
2676 size_exp
= c_size_in_bytes (TREE_TYPE (result_type
));
2678 /* If what we are about to multiply by the size of the elements
2679 contains a constant term, apply distributive law
2680 and multiply that constant term separately.
2681 This helps produce common subexpressions. */
2683 if ((TREE_CODE (intop
) == PLUS_EXPR
|| TREE_CODE (intop
) == MINUS_EXPR
)
2684 && ! TREE_CONSTANT (intop
)
2685 && TREE_CONSTANT (TREE_OPERAND (intop
, 1))
2686 && TREE_CONSTANT (size_exp
)
2687 /* If the constant comes from pointer subtraction,
2688 skip this optimization--it would cause an error. */
2689 && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop
, 0))) == INTEGER_TYPE
2690 /* If the constant is unsigned, and smaller than the pointer size,
2691 then we must skip this optimization. This is because it could cause
2692 an overflow error if the constant is negative but INTOP is not. */
2693 && (! TREE_UNSIGNED (TREE_TYPE (intop
))
2694 || (TYPE_PRECISION (TREE_TYPE (intop
))
2695 == TYPE_PRECISION (TREE_TYPE (ptrop
)))))
2697 enum tree_code subcode
= resultcode
;
2698 tree int_type
= TREE_TYPE (intop
);
2699 if (TREE_CODE (intop
) == MINUS_EXPR
)
2700 subcode
= (subcode
== PLUS_EXPR
? MINUS_EXPR
: PLUS_EXPR
);
2701 /* Convert both subexpression types to the type of intop,
2702 because weird cases involving pointer arithmetic
2703 can result in a sum or difference with different type args. */
2704 ptrop
= build_binary_op (subcode
, ptrop
,
2705 convert (int_type
, TREE_OPERAND (intop
, 1)), 1);
2706 intop
= convert (int_type
, TREE_OPERAND (intop
, 0));
2709 /* Convert the integer argument to a type the same size as sizetype
2710 so the multiply won't overflow spuriously. */
2712 if (TYPE_PRECISION (TREE_TYPE (intop
)) != TYPE_PRECISION (sizetype
)
2713 || TREE_UNSIGNED (TREE_TYPE (intop
)) != TREE_UNSIGNED (sizetype
))
2714 intop
= convert (type_for_size (TYPE_PRECISION (sizetype
),
2715 TREE_UNSIGNED (sizetype
)), intop
);
2717 /* Replace the integer argument with a suitable product by the object size.
2718 Do this multiplication as signed, then convert to the appropriate
2719 pointer type (actually unsigned integral). */
2721 intop
= convert (result_type
,
2722 build_binary_op (MULT_EXPR
, intop
,
2723 convert (TREE_TYPE (intop
), size_exp
), 1));
2725 /* Create the sum or difference. */
2727 result
= build (resultcode
, result_type
, ptrop
, intop
);
2729 folded
= fold (result
);
2730 if (folded
== result
)
2731 TREE_CONSTANT (folded
) = TREE_CONSTANT (ptrop
) & TREE_CONSTANT (intop
);
2735 /* Return a tree for the difference of pointers OP0 and OP1.
2736 The resulting tree has type int. */
2739 pointer_diff (op0
, op1
)
2740 register tree op0
, op1
;
2742 register tree result
, folded
;
2743 tree restype
= ptrdiff_type_node
;
2745 tree target_type
= TREE_TYPE (TREE_TYPE (op0
));
2747 if (pedantic
|| warn_pointer_arith
)
2749 if (TREE_CODE (target_type
) == VOID_TYPE
)
2750 pedwarn ("pointer of type `void *' used in subtraction");
2751 if (TREE_CODE (target_type
) == FUNCTION_TYPE
)
2752 pedwarn ("pointer to a function used in subtraction");
2755 /* First do the subtraction as integers;
2756 then drop through to build the divide operator.
2757 Do not do default conversions on the minus operator
2758 in case restype is a short type. */
2760 op0
= build_binary_op (MINUS_EXPR
, convert (restype
, op0
),
2761 convert (restype
, op1
), 0);
2762 /* This generates an error if op1 is pointer to incomplete type. */
2763 if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (op1
))) == 0)
2764 error ("arithmetic on pointer to an incomplete type");
2766 /* This generates an error if op0 is pointer to incomplete type. */
2767 op1
= c_size_in_bytes (target_type
);
2769 /* Divide by the size, in easiest possible way. */
2771 result
= build (EXACT_DIV_EXPR
, restype
, op0
, convert (restype
, op1
));
2773 folded
= fold (result
);
2774 if (folded
== result
)
2775 TREE_CONSTANT (folded
) = TREE_CONSTANT (op0
) & TREE_CONSTANT (op1
);
2779 /* Construct and perhaps optimize a tree representation
2780 for a unary operation. CODE, a tree_code, specifies the operation
2781 and XARG is the operand. NOCONVERT nonzero suppresses
2782 the default promotions (such as from short to int). */
2785 build_unary_op (code
, xarg
, noconvert
)
2786 enum tree_code code
;
2790 /* No default_conversion here. It causes trouble for ADDR_EXPR. */
2791 register tree arg
= xarg
;
2792 register tree argtype
= 0;
2793 register enum tree_code typecode
= TREE_CODE (TREE_TYPE (arg
));
2796 if (typecode
== ERROR_MARK
)
2797 return error_mark_node
;
2798 if (typecode
== ENUMERAL_TYPE
)
2799 typecode
= INTEGER_TYPE
;
2804 /* This is used for unary plus, because a CONVERT_EXPR
2805 is enough to prevent anybody from looking inside for
2806 associativity, but won't generate any code. */
2807 if (!(typecode
== INTEGER_TYPE
|| typecode
== REAL_TYPE
2808 || typecode
== COMPLEX_TYPE
))
2810 error ("wrong type argument to unary plus");
2811 return error_mark_node
;
2813 else if (!noconvert
)
2814 arg
= default_conversion (arg
);
2818 if (!(typecode
== INTEGER_TYPE
|| typecode
== REAL_TYPE
2819 || typecode
== COMPLEX_TYPE
))
2821 error ("wrong type argument to unary minus");
2822 return error_mark_node
;
2824 else if (!noconvert
)
2825 arg
= default_conversion (arg
);
2829 if (typecode
== COMPLEX_TYPE
)
2833 arg
= default_conversion (arg
);
2835 else if (typecode
!= INTEGER_TYPE
)
2837 error ("wrong type argument to bit-complement");
2838 return error_mark_node
;
2840 else if (!noconvert
)
2841 arg
= default_conversion (arg
);
2845 if (!(typecode
== INTEGER_TYPE
|| typecode
== REAL_TYPE
2846 || typecode
== COMPLEX_TYPE
))
2848 error ("wrong type argument to abs");
2849 return error_mark_node
;
2851 else if (!noconvert
)
2852 arg
= default_conversion (arg
);
2856 /* Conjugating a real value is a no-op, but allow it anyway. */
2857 if (!(typecode
== INTEGER_TYPE
|| typecode
== REAL_TYPE
2858 || typecode
== COMPLEX_TYPE
))
2860 error ("wrong type argument to conjugation");
2861 return error_mark_node
;
2863 else if (!noconvert
)
2864 arg
= default_conversion (arg
);
2867 case TRUTH_NOT_EXPR
:
2868 if (typecode
!= INTEGER_TYPE
2869 && typecode
!= REAL_TYPE
&& typecode
!= POINTER_TYPE
2870 && typecode
!= COMPLEX_TYPE
2871 /* These will convert to a pointer. */
2872 && typecode
!= ARRAY_TYPE
&& typecode
!= FUNCTION_TYPE
)
2874 error ("wrong type argument to unary exclamation mark");
2875 return error_mark_node
;
2877 arg
= truthvalue_conversion (arg
);
2878 return invert_truthvalue (arg
);
2884 if (TREE_CODE (arg
) == COMPLEX_CST
)
2885 return TREE_REALPART (arg
);
2886 else if (TREE_CODE (TREE_TYPE (arg
)) == COMPLEX_TYPE
)
2887 return fold (build1 (REALPART_EXPR
, TREE_TYPE (TREE_TYPE (arg
)), arg
));
2892 if (TREE_CODE (arg
) == COMPLEX_CST
)
2893 return TREE_IMAGPART (arg
);
2894 else if (TREE_CODE (TREE_TYPE (arg
)) == COMPLEX_TYPE
)
2895 return fold (build1 (IMAGPART_EXPR
, TREE_TYPE (TREE_TYPE (arg
)), arg
));
2897 return convert (TREE_TYPE (arg
), integer_zero_node
);
2899 case PREINCREMENT_EXPR
:
2900 case POSTINCREMENT_EXPR
:
2901 case PREDECREMENT_EXPR
:
2902 case POSTDECREMENT_EXPR
:
2903 /* Handle complex lvalues (when permitted)
2904 by reduction to simpler cases. */
2906 val
= unary_complex_lvalue (code
, arg
);
2910 /* Increment or decrement the real part of the value,
2911 and don't change the imaginary part. */
2912 if (typecode
== COMPLEX_TYPE
)
2916 arg
= stabilize_reference (arg
);
2917 real
= build_unary_op (REALPART_EXPR
, arg
, 1);
2918 imag
= build_unary_op (IMAGPART_EXPR
, arg
, 1);
2919 return build (COMPLEX_EXPR
, TREE_TYPE (arg
),
2920 build_unary_op (code
, real
, 1), imag
);
2923 /* Report invalid types. */
2925 if (typecode
!= POINTER_TYPE
2926 && typecode
!= INTEGER_TYPE
&& typecode
!= REAL_TYPE
)
2928 error (code
== PREINCREMENT_EXPR
|| code
== POSTINCREMENT_EXPR
2929 ? "wrong type argument to increment"
2930 : "wrong type argument to decrement");
2931 return error_mark_node
;
2936 tree result_type
= TREE_TYPE (arg
);
2938 arg
= get_unwidened (arg
, 0);
2939 argtype
= TREE_TYPE (arg
);
2941 /* Compute the increment. */
2943 if (typecode
== POINTER_TYPE
)
2945 /* If pointer target is an undefined struct,
2946 we just cannot know how to do the arithmetic. */
2947 if (TYPE_SIZE (TREE_TYPE (result_type
)) == 0)
2948 error (code
== PREINCREMENT_EXPR
|| code
== POSTINCREMENT_EXPR
2949 ? "increment of pointer to unknown structure"
2950 : "decrement of pointer to unknown structure");
2951 else if ((pedantic
|| warn_pointer_arith
)
2952 && (TREE_CODE (TREE_TYPE (result_type
)) == FUNCTION_TYPE
2953 || TREE_CODE (TREE_TYPE (result_type
)) == VOID_TYPE
))
2954 pedwarn (code
== PREINCREMENT_EXPR
|| code
== POSTINCREMENT_EXPR
2955 ? "wrong type argument to increment"
2956 : "wrong type argument to decrement");
2957 inc
= c_size_in_bytes (TREE_TYPE (result_type
));
2960 inc
= integer_one_node
;
2962 inc
= convert (argtype
, inc
);
2964 /* Handle incrementing a cast-expression. */
2967 switch (TREE_CODE (arg
))
2972 case FIX_TRUNC_EXPR
:
2973 case FIX_FLOOR_EXPR
:
2974 case FIX_ROUND_EXPR
:
2976 pedantic_lvalue_warning (CONVERT_EXPR
);
2977 /* If the real type has the same machine representation
2978 as the type it is cast to, we can make better output
2979 by adding directly to the inside of the cast. */
2980 if ((TREE_CODE (TREE_TYPE (arg
))
2981 == TREE_CODE (TREE_TYPE (TREE_OPERAND (arg
, 0))))
2982 && (TYPE_MODE (TREE_TYPE (arg
))
2983 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (arg
, 0)))))
2984 arg
= TREE_OPERAND (arg
, 0);
2987 tree incremented
, modify
, value
;
2988 arg
= stabilize_reference (arg
);
2989 if (code
== PREINCREMENT_EXPR
|| code
== PREDECREMENT_EXPR
)
2992 value
= save_expr (arg
);
2993 incremented
= build (((code
== PREINCREMENT_EXPR
2994 || code
== POSTINCREMENT_EXPR
)
2995 ? PLUS_EXPR
: MINUS_EXPR
),
2996 argtype
, value
, inc
);
2997 TREE_SIDE_EFFECTS (incremented
) = 1;
2998 modify
= build_modify_expr (arg
, NOP_EXPR
, incremented
);
2999 value
= build (COMPOUND_EXPR
, TREE_TYPE (arg
), modify
, value
);
3000 TREE_USED (value
) = 1;
3010 /* Complain about anything else that is not a true lvalue. */
3011 if (!lvalue_or_else (arg
, ((code
== PREINCREMENT_EXPR
3012 || code
== POSTINCREMENT_EXPR
)
3013 ? "invalid lvalue in increment"
3014 : "invalid lvalue in decrement")))
3015 return error_mark_node
;
3017 /* Report a read-only lvalue. */
3018 if (TREE_READONLY (arg
))
3019 readonly_warning (arg
,
3020 ((code
== PREINCREMENT_EXPR
3021 || code
== POSTINCREMENT_EXPR
)
3022 ? "increment" : "decrement"));
3024 val
= build (code
, TREE_TYPE (arg
), arg
, inc
);
3025 TREE_SIDE_EFFECTS (val
) = 1;
3026 val
= convert (result_type
, val
);
3027 if (TREE_CODE (val
) != code
)
3028 TREE_NO_UNUSED_WARNING (val
) = 1;
3033 /* Note that this operation never does default_conversion
3034 regardless of NOCONVERT. */
3036 /* Let &* cancel out to simplify resulting code. */
3037 if (TREE_CODE (arg
) == INDIRECT_REF
)
3039 /* Don't let this be an lvalue. */
3040 if (lvalue_p (TREE_OPERAND (arg
, 0)))
3041 return non_lvalue (TREE_OPERAND (arg
, 0));
3042 return TREE_OPERAND (arg
, 0);
3045 /* For &x[y], return x+y */
3046 if (TREE_CODE (arg
) == ARRAY_REF
)
3048 if (mark_addressable (TREE_OPERAND (arg
, 0)) == 0)
3049 return error_mark_node
;
3050 return build_binary_op (PLUS_EXPR
, TREE_OPERAND (arg
, 0),
3051 TREE_OPERAND (arg
, 1), 1);
3054 /* Handle complex lvalues (when permitted)
3055 by reduction to simpler cases. */
3056 val
= unary_complex_lvalue (code
, arg
);
3060 #if 0 /* Turned off because inconsistent;
3061 float f; *&(int)f = 3.4 stores in int format
3062 whereas (int)f = 3.4 stores in float format. */
3063 /* Address of a cast is just a cast of the address
3064 of the operand of the cast. */
3065 switch (TREE_CODE (arg
))
3070 case FIX_TRUNC_EXPR
:
3071 case FIX_FLOOR_EXPR
:
3072 case FIX_ROUND_EXPR
:
3075 pedwarn ("ANSI C forbids the address of a cast expression");
3076 return convert (build_pointer_type (TREE_TYPE (arg
)),
3077 build_unary_op (ADDR_EXPR
, TREE_OPERAND (arg
, 0),
3082 /* Allow the address of a constructor if all the elements
3084 if (TREE_CODE (arg
) == CONSTRUCTOR
&& TREE_CONSTANT (arg
))
3086 /* Anything not already handled and not a true memory reference
3088 else if (typecode
!= FUNCTION_TYPE
3089 && !lvalue_or_else (arg
, "invalid lvalue in unary `&'"))
3090 return error_mark_node
;
3092 /* Ordinary case; arg is a COMPONENT_REF or a decl. */
3093 argtype
= TREE_TYPE (arg
);
3094 /* If the lvalue is const or volatile, merge that into the type
3095 to which the address will point. Note that you can't get a
3096 restricted pointer by taking the address of something, so we
3097 only have to deal with `const' and `volatile' here. */
3098 if (TREE_CODE_CLASS (TREE_CODE (arg
)) == 'd'
3099 || TREE_CODE_CLASS (TREE_CODE (arg
)) == 'r')
3101 if (TREE_READONLY (arg
) || TREE_THIS_VOLATILE (arg
))
3102 argtype
= c_build_type_variant (argtype
,
3103 TREE_READONLY (arg
),
3104 TREE_THIS_VOLATILE (arg
));
3107 argtype
= build_pointer_type (argtype
);
3109 if (mark_addressable (arg
) == 0)
3110 return error_mark_node
;
3115 if (TREE_CODE (arg
) == COMPONENT_REF
)
3117 tree field
= TREE_OPERAND (arg
, 1);
3119 addr
= build_unary_op (ADDR_EXPR
, TREE_OPERAND (arg
, 0), 0);
3121 if (DECL_C_BIT_FIELD (field
))
3123 error ("attempt to take address of bit-field structure member `%s'",
3124 IDENTIFIER_POINTER (DECL_NAME (field
)));
3125 return error_mark_node
;
3128 addr
= convert (argtype
, addr
);
3130 if (! integer_zerop (DECL_FIELD_BITPOS (field
)))
3133 = size_binop (EASY_DIV_EXPR
, DECL_FIELD_BITPOS (field
),
3134 size_int (BITS_PER_UNIT
));
3135 int flag
= TREE_CONSTANT (addr
);
3136 addr
= fold (build (PLUS_EXPR
, argtype
,
3137 addr
, convert (argtype
, offset
)));
3138 TREE_CONSTANT (addr
) = flag
;
3142 addr
= build1 (code
, argtype
, arg
);
3144 /* Address of a static or external variable or
3145 file-scope function counts as a constant. */
3147 && ! (TREE_CODE (arg
) == FUNCTION_DECL
3148 && DECL_CONTEXT (arg
) != 0))
3149 TREE_CONSTANT (addr
) = 1;
3158 argtype
= TREE_TYPE (arg
);
3159 return fold (build1 (code
, argtype
, arg
));
3163 /* If CONVERSIONS is a conversion expression or a nested sequence of such,
3164 convert ARG with the same conversions in the same order
3165 and return the result. */
3168 convert_sequence (conversions
, arg
)
3172 switch (TREE_CODE (conversions
))
3177 case FIX_TRUNC_EXPR
:
3178 case FIX_FLOOR_EXPR
:
3179 case FIX_ROUND_EXPR
:
3181 return convert (TREE_TYPE (conversions
),
3182 convert_sequence (TREE_OPERAND (conversions
, 0),
3191 /* Return nonzero if REF is an lvalue valid for this language.
3192 Lvalues can be assigned, unless their type has TYPE_READONLY.
3193 Lvalues can have their address taken, unless they have DECL_REGISTER. */
3199 register enum tree_code code
= TREE_CODE (ref
);
3206 return lvalue_p (TREE_OPERAND (ref
, 0));
3217 return (TREE_CODE (TREE_TYPE (ref
)) != FUNCTION_TYPE
3218 && TREE_CODE (TREE_TYPE (ref
)) != METHOD_TYPE
);
3222 return TREE_CODE (TREE_TYPE (ref
)) == ARRAY_TYPE
;
3229 /* Return nonzero if REF is an lvalue valid for this language;
3230 otherwise, print an error message and return zero. */
3233 lvalue_or_else (ref
, msgid
)
3237 int win
= lvalue_p (ref
);
3243 /* Apply unary lvalue-demanding operator CODE to the expression ARG
3244 for certain kinds of expressions which are not really lvalues
3245 but which we can accept as lvalues.
3247 If ARG is not a kind of expression we can handle, return zero. */
3250 unary_complex_lvalue (code
, arg
)
3251 enum tree_code code
;
3254 /* Handle (a, b) used as an "lvalue". */
3255 if (TREE_CODE (arg
) == COMPOUND_EXPR
)
3257 tree real_result
= build_unary_op (code
, TREE_OPERAND (arg
, 1), 0);
3259 /* If this returns a function type, it isn't really being used as
3260 an lvalue, so don't issue a warning about it. */
3261 if (TREE_CODE (TREE_TYPE (arg
)) != FUNCTION_TYPE
)
3262 pedantic_lvalue_warning (COMPOUND_EXPR
);
3264 return build (COMPOUND_EXPR
, TREE_TYPE (real_result
),
3265 TREE_OPERAND (arg
, 0), real_result
);
3268 /* Handle (a ? b : c) used as an "lvalue". */
3269 if (TREE_CODE (arg
) == COND_EXPR
)
3271 pedantic_lvalue_warning (COND_EXPR
);
3272 if (TREE_CODE (TREE_TYPE (arg
)) != FUNCTION_TYPE
)
3273 pedantic_lvalue_warning (COMPOUND_EXPR
);
3275 return (build_conditional_expr
3276 (TREE_OPERAND (arg
, 0),
3277 build_unary_op (code
, TREE_OPERAND (arg
, 1), 0),
3278 build_unary_op (code
, TREE_OPERAND (arg
, 2), 0)));
3284 /* If pedantic, warn about improper lvalue. CODE is either COND_EXPR
3285 COMPOUND_EXPR, or CONVERT_EXPR (for casts). */
3288 pedantic_lvalue_warning (code
)
3289 enum tree_code code
;
3292 pedwarn (code
== COND_EXPR
3293 ? "ANSI C forbids use of conditional expressions as lvalues"
3294 : code
== COMPOUND_EXPR
3295 ? "ANSI C forbids use of compound expressions as lvalues"
3296 : "ANSI C forbids use of cast expressions as lvalues");
3299 /* Warn about storing in something that is `const'. */
3302 readonly_warning (arg
, msgid
)
3306 /* Forbid assignments to iterators. */
3307 if (TREE_CODE (arg
) == VAR_DECL
&& ITERATOR_P (arg
))
3308 pedwarn ("%s of iterator `%s'", _(msgid
),
3309 IDENTIFIER_POINTER (DECL_NAME (arg
)));
3311 if (TREE_CODE (arg
) == COMPONENT_REF
)
3313 if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg
, 0))))
3314 readonly_warning (TREE_OPERAND (arg
, 0), msgid
);
3316 pedwarn ("%s of read-only member `%s'", _(msgid
),
3317 IDENTIFIER_POINTER (DECL_NAME (TREE_OPERAND (arg
, 1))));
3319 else if (TREE_CODE (arg
) == VAR_DECL
)
3320 pedwarn ("%s of read-only variable `%s'", _(msgid
),
3321 IDENTIFIER_POINTER (DECL_NAME (arg
)));
3323 pedwarn ("%s of read-only location", _(msgid
));
3326 /* Mark EXP saying that we need to be able to take the
3327 address of it; it should not be allocated in a register.
3328 Value is 1 if successful. */
3331 mark_addressable (exp
)
3334 register tree x
= exp
;
3336 switch (TREE_CODE (x
))
3339 if (DECL_C_BIT_FIELD (TREE_OPERAND (x
, 1)))
3341 error ("cannot take address of bitfield `%s'",
3342 IDENTIFIER_POINTER (DECL_NAME (TREE_OPERAND (x
, 1))));
3346 /* ... fall through ... */
3352 x
= TREE_OPERAND (x
, 0);
3356 TREE_ADDRESSABLE (x
) = 1;
3363 if (DECL_REGISTER (x
) && !TREE_ADDRESSABLE (x
)
3364 && DECL_NONLOCAL (x
))
3366 if (TREE_PUBLIC (x
))
3368 error ("global register variable `%s' used in nested function",
3369 IDENTIFIER_POINTER (DECL_NAME (x
)));
3372 pedwarn ("register variable `%s' used in nested function",
3373 IDENTIFIER_POINTER (DECL_NAME (x
)));
3375 else if (DECL_REGISTER (x
) && !TREE_ADDRESSABLE (x
))
3377 if (TREE_PUBLIC (x
))
3379 error ("address of global register variable `%s' requested",
3380 IDENTIFIER_POINTER (DECL_NAME (x
)));
3384 /* If we are making this addressable due to its having
3385 volatile components, give a different error message. Also
3386 handle the case of an unnamed parameter by not trying
3387 to give the name. */
3389 else if (C_TYPE_FIELDS_VOLATILE (TREE_TYPE (x
)))
3391 error ("cannot put object with volatile field into register");
3395 pedwarn ("address of register variable `%s' requested",
3396 IDENTIFIER_POINTER (DECL_NAME (x
)));
3398 put_var_into_stack (x
);
3402 TREE_ADDRESSABLE (x
) = 1;
3403 #if 0 /* poplevel deals with this now. */
3404 if (DECL_CONTEXT (x
) == 0)
3405 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (x
)) = 1;
3413 /* Build and return a conditional expression IFEXP ? OP1 : OP2. */
3416 build_conditional_expr (ifexp
, op1
, op2
)
3417 tree ifexp
, op1
, op2
;
3419 register tree type1
;
3420 register tree type2
;
3421 register enum tree_code code1
;
3422 register enum tree_code code2
;
3423 register tree result_type
= NULL
;
3424 tree orig_op1
= op1
, orig_op2
= op2
;
3426 ifexp
= truthvalue_conversion (default_conversion (ifexp
));
3428 #if 0 /* Produces wrong result if within sizeof. */
3429 /* Don't promote the operands separately if they promote
3430 the same way. Return the unpromoted type and let the combined
3431 value get promoted if necessary. */
3433 if (TREE_TYPE (op1
) == TREE_TYPE (op2
)
3434 && TREE_CODE (TREE_TYPE (op1
)) != ARRAY_TYPE
3435 && TREE_CODE (TREE_TYPE (op1
)) != ENUMERAL_TYPE
3436 && TREE_CODE (TREE_TYPE (op1
)) != FUNCTION_TYPE
)
3438 if (TREE_CODE (ifexp
) == INTEGER_CST
)
3439 return pedantic_non_lvalue (integer_zerop (ifexp
) ? op2
: op1
);
3441 return fold (build (COND_EXPR
, TREE_TYPE (op1
), ifexp
, op1
, op2
));
3445 /* Promote both alternatives. */
3447 if (TREE_CODE (TREE_TYPE (op1
)) != VOID_TYPE
)
3448 op1
= default_conversion (op1
);
3449 if (TREE_CODE (TREE_TYPE (op2
)) != VOID_TYPE
)
3450 op2
= default_conversion (op2
);
3452 if (TREE_CODE (ifexp
) == ERROR_MARK
3453 || TREE_CODE (TREE_TYPE (op1
)) == ERROR_MARK
3454 || TREE_CODE (TREE_TYPE (op2
)) == ERROR_MARK
)
3455 return error_mark_node
;
3457 type1
= TREE_TYPE (op1
);
3458 code1
= TREE_CODE (type1
);
3459 type2
= TREE_TYPE (op2
);
3460 code2
= TREE_CODE (type2
);
3462 /* Quickly detect the usual case where op1 and op2 have the same type
3464 if (TYPE_MAIN_VARIANT (type1
) == TYPE_MAIN_VARIANT (type2
))
3467 result_type
= type1
;
3469 result_type
= TYPE_MAIN_VARIANT (type1
);
3471 else if ((code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
)
3472 && (code2
== INTEGER_TYPE
|| code2
== REAL_TYPE
))
3474 result_type
= common_type (type1
, type2
);
3476 else if (code1
== VOID_TYPE
|| code2
== VOID_TYPE
)
3478 if (pedantic
&& (code1
!= VOID_TYPE
|| code2
!= VOID_TYPE
))
3479 pedwarn ("ANSI C forbids conditional expr with only one void side");
3480 result_type
= void_type_node
;
3482 else if (code1
== POINTER_TYPE
&& code2
== POINTER_TYPE
)
3484 if (comp_target_types (type1
, type2
))
3485 result_type
= common_type (type1
, type2
);
3486 else if (integer_zerop (op1
) && TREE_TYPE (type1
) == void_type_node
3487 && TREE_CODE (orig_op1
) != NOP_EXPR
)
3488 result_type
= qualify_type (type2
, type1
);
3489 else if (integer_zerop (op2
) && TREE_TYPE (type2
) == void_type_node
3490 && TREE_CODE (orig_op2
) != NOP_EXPR
)
3491 result_type
= qualify_type (type1
, type2
);
3492 else if (TYPE_MAIN_VARIANT (TREE_TYPE (type1
)) == void_type_node
)
3494 if (pedantic
&& TREE_CODE (TREE_TYPE (type2
)) == FUNCTION_TYPE
)
3495 pedwarn ("ANSI C forbids conditional expr between `void *' and function pointer");
3496 result_type
= qualify_type (type1
, type2
);
3498 else if (TYPE_MAIN_VARIANT (TREE_TYPE (type2
)) == void_type_node
)
3500 if (pedantic
&& TREE_CODE (TREE_TYPE (type1
)) == FUNCTION_TYPE
)
3501 pedwarn ("ANSI C forbids conditional expr between `void *' and function pointer");
3502 result_type
= qualify_type (type2
, type1
);
3506 pedwarn ("pointer type mismatch in conditional expression");
3507 result_type
= build_pointer_type (void_type_node
);
3510 else if (code1
== POINTER_TYPE
&& code2
== INTEGER_TYPE
)
3512 if (! integer_zerop (op2
))
3513 pedwarn ("pointer/integer type mismatch in conditional expression");
3516 op2
= null_pointer_node
;
3517 #if 0 /* The spec seems to say this is permitted. */
3518 if (pedantic
&& TREE_CODE (type1
) == FUNCTION_TYPE
)
3519 pedwarn ("ANSI C forbids conditional expr between 0 and function pointer");
3522 result_type
= type1
;
3524 else if (code2
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
3526 if (!integer_zerop (op1
))
3527 pedwarn ("pointer/integer type mismatch in conditional expression");
3530 op1
= null_pointer_node
;
3531 #if 0 /* The spec seems to say this is permitted. */
3532 if (pedantic
&& TREE_CODE (type2
) == FUNCTION_TYPE
)
3533 pedwarn ("ANSI C forbids conditional expr between 0 and function pointer");
3536 result_type
= type2
;
3541 if (flag_cond_mismatch
)
3542 result_type
= void_type_node
;
3545 error ("type mismatch in conditional expression");
3546 return error_mark_node
;
3550 /* Merge const and volatile flags of the incoming types. */
3552 = build_type_variant (result_type
,
3553 TREE_READONLY (op1
) || TREE_READONLY (op2
),
3554 TREE_THIS_VOLATILE (op1
) || TREE_THIS_VOLATILE (op2
));
3556 if (result_type
!= TREE_TYPE (op1
))
3557 op1
= convert_and_check (result_type
, op1
);
3558 if (result_type
!= TREE_TYPE (op2
))
3559 op2
= convert_and_check (result_type
, op2
);
3562 if (code1
== RECORD_TYPE
|| code1
== UNION_TYPE
)
3564 result_type
= TREE_TYPE (op1
);
3565 if (TREE_CONSTANT (ifexp
))
3566 return pedantic_non_lvalue (integer_zerop (ifexp
) ? op2
: op1
);
3568 if (TYPE_MODE (result_type
) == BLKmode
)
3570 register tree tempvar
3571 = build_decl (VAR_DECL
, NULL_TREE
, result_type
);
3572 register tree xop1
= build_modify_expr (tempvar
, op1
);
3573 register tree xop2
= build_modify_expr (tempvar
, op2
);
3574 register tree result
= fold (build (COND_EXPR
, result_type
,
3575 ifexp
, xop1
, xop2
));
3577 layout_decl (tempvar
, TYPE_ALIGN (result_type
));
3578 /* No way to handle variable-sized objects here.
3579 I fear that the entire handling of BLKmode conditional exprs
3580 needs to be redone. */
3581 if (TREE_CODE (DECL_SIZE (tempvar
)) != INTEGER_CST
)
3584 = assign_stack_local (DECL_MODE (tempvar
),
3585 (TREE_INT_CST_LOW (DECL_SIZE (tempvar
))
3586 + BITS_PER_UNIT
- 1)
3590 TREE_SIDE_EFFECTS (result
)
3591 = TREE_SIDE_EFFECTS (ifexp
) | TREE_SIDE_EFFECTS (op1
)
3592 | TREE_SIDE_EFFECTS (op2
);
3593 return build (COMPOUND_EXPR
, result_type
, result
, tempvar
);
3598 if (TREE_CODE (ifexp
) == INTEGER_CST
)
3599 return pedantic_non_lvalue (integer_zerop (ifexp
) ? op2
: op1
);
3601 return fold (build (COND_EXPR
, result_type
, ifexp
, op1
, op2
));
3604 /* Given a list of expressions, return a compound expression
3605 that performs them all and returns the value of the last of them. */
3608 build_compound_expr (list
)
3611 return internal_build_compound_expr (list
, TRUE
);
3615 internal_build_compound_expr (list
, first_p
)
3621 if (TREE_CHAIN (list
) == 0)
3623 #if 0 /* If something inside inhibited lvalueness, we should not override. */
3624 /* Consider (x, y+0), which is not an lvalue since y+0 is not. */
3626 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
3627 if (TREE_CODE (list
) == NON_LVALUE_EXPR
)
3628 list
= TREE_OPERAND (list
, 0);
3631 /* Don't let (0, 0) be null pointer constant. */
3632 if (!first_p
&& integer_zerop (TREE_VALUE (list
)))
3633 return non_lvalue (TREE_VALUE (list
));
3634 return TREE_VALUE (list
);
3637 if (TREE_CHAIN (list
) != 0 && TREE_CHAIN (TREE_CHAIN (list
)) == 0)
3639 /* Convert arrays to pointers when there really is a comma operator. */
3640 if (TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (list
)))) == ARRAY_TYPE
)
3641 TREE_VALUE (TREE_CHAIN (list
))
3642 = default_conversion (TREE_VALUE (TREE_CHAIN (list
)));
3645 rest
= internal_build_compound_expr (TREE_CHAIN (list
), FALSE
);
3647 if (! TREE_SIDE_EFFECTS (TREE_VALUE (list
)))
3649 /* The left-hand operand of a comma expression is like an expression
3650 statement: with -W or -Wunused, we should warn if it doesn't have
3651 any side-effects, unless it was explicitly cast to (void). */
3652 if ((extra_warnings
|| warn_unused
)
3653 && ! (TREE_CODE (TREE_VALUE (list
)) == CONVERT_EXPR
3654 && TREE_TYPE (TREE_VALUE (list
)) == void_type_node
))
3655 warning ("left-hand operand of comma expression has no effect");
3657 /* When pedantic, a compound expression can be neither an lvalue
3658 nor an integer constant expression. */
3663 /* With -Wunused, we should also warn if the left-hand operand does have
3664 side-effects, but computes a value which is not used. For example, in
3665 `foo() + bar(), baz()' the result of the `+' operator is not used,
3666 so we should issue a warning. */
3667 else if (warn_unused
)
3668 warn_if_unused_value (TREE_VALUE (list
));
3670 return build (COMPOUND_EXPR
, TREE_TYPE (rest
), TREE_VALUE (list
), rest
);
3673 /* Build an expression representing a cast to type TYPE of expression EXPR. */
3676 build_c_cast (type
, expr
)
3680 register tree value
= expr
;
3682 if (type
== error_mark_node
|| expr
== error_mark_node
)
3683 return error_mark_node
;
3684 type
= TYPE_MAIN_VARIANT (type
);
3687 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
3688 if (TREE_CODE (value
) == NON_LVALUE_EXPR
)
3689 value
= TREE_OPERAND (value
, 0);
3692 if (TREE_CODE (type
) == ARRAY_TYPE
)
3694 error ("cast specifies array type");
3695 return error_mark_node
;
3698 if (TREE_CODE (type
) == FUNCTION_TYPE
)
3700 error ("cast specifies function type");
3701 return error_mark_node
;
3704 if (type
== TREE_TYPE (value
))
3708 if (TREE_CODE (type
) == RECORD_TYPE
3709 || TREE_CODE (type
) == UNION_TYPE
)
3710 pedwarn ("ANSI C forbids casting nonscalar to the same type");
3713 else if (TREE_CODE (type
) == UNION_TYPE
)
3716 if (TREE_CODE (TREE_TYPE (value
)) == ARRAY_TYPE
3717 || TREE_CODE (TREE_TYPE (value
)) == FUNCTION_TYPE
)
3718 value
= default_conversion (value
);
3720 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
3721 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (field
)),
3722 TYPE_MAIN_VARIANT (TREE_TYPE (value
))))
3731 pedwarn ("ANSI C forbids casts to union type");
3732 if (TYPE_NAME (type
) != 0)
3734 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
3735 name
= IDENTIFIER_POINTER (TYPE_NAME (type
));
3737 name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
3741 t
= digest_init (type
, build (CONSTRUCTOR
, type
, NULL_TREE
,
3742 build_tree_list (field
, value
)),
3744 TREE_CONSTANT (t
) = TREE_CONSTANT (value
);
3747 error ("cast to union type from type not present in union");
3748 return error_mark_node
;
3754 /* If casting to void, avoid the error that would come
3755 from default_conversion in the case of a non-lvalue array. */
3756 if (type
== void_type_node
)
3757 return build1 (CONVERT_EXPR
, type
, value
);
3759 /* Convert functions and arrays to pointers,
3760 but don't convert any other types. */
3761 if (TREE_CODE (TREE_TYPE (value
)) == FUNCTION_TYPE
3762 || TREE_CODE (TREE_TYPE (value
)) == ARRAY_TYPE
)
3763 value
= default_conversion (value
);
3764 otype
= TREE_TYPE (value
);
3766 /* Optionally warn about potentially worrisome casts. */
3769 && TREE_CODE (type
) == POINTER_TYPE
3770 && TREE_CODE (otype
) == POINTER_TYPE
)
3772 /* Go to the innermost object being pointed to. */
3773 tree in_type
= type
;
3774 tree in_otype
= otype
;
3776 while (TREE_CODE (in_type
) == POINTER_TYPE
)
3777 in_type
= TREE_TYPE (in_type
);
3778 while (TREE_CODE (in_otype
) == POINTER_TYPE
)
3779 in_otype
= TREE_TYPE (in_otype
);
3781 if (TYPE_QUALS (in_otype
) & ~TYPE_QUALS (in_type
))
3782 /* There are qualifiers present in IN_OTYPE that are not
3783 present in IN_TYPE. */
3784 pedwarn ("cast discards qualifiers from pointer target type");
3787 /* Warn about possible alignment problems. */
3788 if (STRICT_ALIGNMENT
&& warn_cast_align
3789 && TREE_CODE (type
) == POINTER_TYPE
3790 && TREE_CODE (otype
) == POINTER_TYPE
3791 && TREE_CODE (TREE_TYPE (otype
)) != VOID_TYPE
3792 && TREE_CODE (TREE_TYPE (otype
)) != FUNCTION_TYPE
3793 /* Don't warn about opaque types, where the actual alignment
3794 restriction is unknown. */
3795 && !((TREE_CODE (TREE_TYPE (otype
)) == UNION_TYPE
3796 || TREE_CODE (TREE_TYPE (otype
)) == RECORD_TYPE
)
3797 && TYPE_MODE (TREE_TYPE (otype
)) == VOIDmode
)
3798 && TYPE_ALIGN (TREE_TYPE (type
)) > TYPE_ALIGN (TREE_TYPE (otype
)))
3799 warning ("cast increases required alignment of target type");
3801 if (TREE_CODE (type
) == INTEGER_TYPE
3802 && TREE_CODE (otype
) == POINTER_TYPE
3803 && TYPE_PRECISION (type
) != TYPE_PRECISION (otype
)
3804 && !TREE_CONSTANT (value
))
3805 warning ("cast from pointer to integer of different size");
3807 if (warn_bad_function_cast
3808 && TREE_CODE (value
) == CALL_EXPR
3809 && TREE_CODE (type
) != TREE_CODE (otype
))
3810 warning ("cast does not match function type");
3812 if (TREE_CODE (type
) == POINTER_TYPE
3813 && TREE_CODE (otype
) == INTEGER_TYPE
3814 && TYPE_PRECISION (type
) != TYPE_PRECISION (otype
)
3816 /* Don't warn about converting 0 to pointer,
3817 provided the 0 was explicit--not cast or made by folding. */
3818 && !(TREE_CODE (value
) == INTEGER_CST
&& integer_zerop (value
))
3820 /* Don't warn about converting any constant. */
3821 && !TREE_CONSTANT (value
))
3822 warning ("cast to pointer from integer of different size");
3825 value
= convert (type
, value
);
3827 /* Ignore any integer overflow caused by the cast. */
3828 if (TREE_CODE (value
) == INTEGER_CST
)
3830 TREE_OVERFLOW (value
) = TREE_OVERFLOW (ovalue
);
3831 TREE_CONSTANT_OVERFLOW (value
) = TREE_CONSTANT_OVERFLOW (ovalue
);
3835 /* Pedantically, don't ley (void *) (FOO *) 0 be a null pointer constant. */
3836 if (pedantic
&& TREE_CODE (value
) == INTEGER_CST
3837 && TREE_CODE (expr
) == INTEGER_CST
3838 && TREE_CODE (TREE_TYPE (expr
)) != INTEGER_TYPE
)
3839 value
= non_lvalue (value
);
3841 /* If pedantic, don't let a cast be an lvalue. */
3842 if (value
== expr
&& pedantic
)
3843 value
= non_lvalue (value
);
3848 /* Build an assignment expression of lvalue LHS from value RHS.
3849 MODIFYCODE is the code for a binary operator that we use
3850 to combine the old value of LHS with RHS to get the new value.
3851 Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment. */
3854 build_modify_expr (lhs
, modifycode
, rhs
)
3856 enum tree_code modifycode
;
3858 register tree result
;
3860 tree lhstype
= TREE_TYPE (lhs
);
3861 tree olhstype
= lhstype
;
3863 /* Types that aren't fully specified cannot be used in assignments. */
3864 lhs
= require_complete_type (lhs
);
3866 /* Avoid duplicate error messages from operands that had errors. */
3867 if (TREE_CODE (lhs
) == ERROR_MARK
|| TREE_CODE (rhs
) == ERROR_MARK
)
3868 return error_mark_node
;
3870 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
3871 /* Do not use STRIP_NOPS here. We do not want an enumerator
3872 whose value is 0 to count as a null pointer constant. */
3873 if (TREE_CODE (rhs
) == NON_LVALUE_EXPR
)
3874 rhs
= TREE_OPERAND (rhs
, 0);
3878 /* Handle control structure constructs used as "lvalues". */
3880 switch (TREE_CODE (lhs
))
3882 /* Handle (a, b) used as an "lvalue". */
3884 pedantic_lvalue_warning (COMPOUND_EXPR
);
3885 newrhs
= build_modify_expr (TREE_OPERAND (lhs
, 1),
3887 if (TREE_CODE (newrhs
) == ERROR_MARK
)
3888 return error_mark_node
;
3889 return build (COMPOUND_EXPR
, lhstype
,
3890 TREE_OPERAND (lhs
, 0), newrhs
);
3892 /* Handle (a ? b : c) used as an "lvalue". */
3894 pedantic_lvalue_warning (COND_EXPR
);
3895 rhs
= save_expr (rhs
);
3897 /* Produce (a ? (b = rhs) : (c = rhs))
3898 except that the RHS goes through a save-expr
3899 so the code to compute it is only emitted once. */
3901 = build_conditional_expr (TREE_OPERAND (lhs
, 0),
3902 build_modify_expr (TREE_OPERAND (lhs
, 1),
3904 build_modify_expr (TREE_OPERAND (lhs
, 2),
3906 if (TREE_CODE (cond
) == ERROR_MARK
)
3908 /* Make sure the code to compute the rhs comes out
3909 before the split. */
3910 return build (COMPOUND_EXPR
, TREE_TYPE (lhs
),
3911 /* But cast it to void to avoid an "unused" error. */
3912 convert (void_type_node
, rhs
), cond
);
3918 /* If a binary op has been requested, combine the old LHS value with the RHS
3919 producing the value we should actually store into the LHS. */
3921 if (modifycode
!= NOP_EXPR
)
3923 lhs
= stabilize_reference (lhs
);
3924 newrhs
= build_binary_op (modifycode
, lhs
, rhs
, 1);
3927 /* Handle a cast used as an "lvalue".
3928 We have already performed any binary operator using the value as cast.
3929 Now convert the result to the cast type of the lhs,
3930 and then true type of the lhs and store it there;
3931 then convert result back to the cast type to be the value
3932 of the assignment. */
3934 switch (TREE_CODE (lhs
))
3939 case FIX_TRUNC_EXPR
:
3940 case FIX_FLOOR_EXPR
:
3941 case FIX_ROUND_EXPR
:
3943 if (TREE_CODE (TREE_TYPE (newrhs
)) == ARRAY_TYPE
3944 || TREE_CODE (TREE_TYPE (newrhs
)) == FUNCTION_TYPE
)
3945 newrhs
= default_conversion (newrhs
);
3947 tree inner_lhs
= TREE_OPERAND (lhs
, 0);
3949 result
= build_modify_expr (inner_lhs
, NOP_EXPR
,
3950 convert (TREE_TYPE (inner_lhs
),
3951 convert (lhstype
, newrhs
)));
3952 if (TREE_CODE (result
) == ERROR_MARK
)
3954 pedantic_lvalue_warning (CONVERT_EXPR
);
3955 return convert (TREE_TYPE (lhs
), result
);
3962 /* Now we have handled acceptable kinds of LHS that are not truly lvalues.
3963 Reject anything strange now. */
3965 if (!lvalue_or_else (lhs
, "invalid lvalue in assignment"))
3966 return error_mark_node
;
3968 /* Warn about storing in something that is `const'. */
3970 if (TREE_READONLY (lhs
) || TYPE_READONLY (lhstype
)
3971 || ((TREE_CODE (lhstype
) == RECORD_TYPE
3972 || TREE_CODE (lhstype
) == UNION_TYPE
)
3973 && C_TYPE_FIELDS_READONLY (lhstype
)))
3974 readonly_warning (lhs
, "assignment");
3976 /* If storing into a structure or union member,
3977 it has probably been given type `int'.
3978 Compute the type that would go with
3979 the actual amount of storage the member occupies. */
3981 if (TREE_CODE (lhs
) == COMPONENT_REF
3982 && (TREE_CODE (lhstype
) == INTEGER_TYPE
3983 || TREE_CODE (lhstype
) == REAL_TYPE
3984 || TREE_CODE (lhstype
) == ENUMERAL_TYPE
))
3985 lhstype
= TREE_TYPE (get_unwidened (lhs
, 0));
3987 /* If storing in a field that is in actuality a short or narrower than one,
3988 we must store in the field in its actual type. */
3990 if (lhstype
!= TREE_TYPE (lhs
))
3992 lhs
= copy_node (lhs
);
3993 TREE_TYPE (lhs
) = lhstype
;
3996 /* Convert new value to destination type. */
3998 newrhs
= convert_for_assignment (lhstype
, newrhs
, _("assignment"),
3999 NULL_TREE
, NULL_TREE
, 0);
4000 if (TREE_CODE (newrhs
) == ERROR_MARK
)
4001 return error_mark_node
;
4003 result
= build (MODIFY_EXPR
, lhstype
, lhs
, newrhs
);
4004 TREE_SIDE_EFFECTS (result
) = 1;
4006 /* If we got the LHS in a different type for storing in,
4007 convert the result back to the nominal type of LHS
4008 so that the value we return always has the same type
4009 as the LHS argument. */
4011 if (olhstype
== TREE_TYPE (result
))
4013 return convert_for_assignment (olhstype
, result
, _("assignment"),
4014 NULL_TREE
, NULL_TREE
, 0);
4017 /* Convert value RHS to type TYPE as preparation for an assignment
4018 to an lvalue of type TYPE.
4019 The real work of conversion is done by `convert'.
4020 The purpose of this function is to generate error messages
4021 for assignments that are not allowed in C.
4022 ERRTYPE is a string to use in error messages:
4023 "assignment", "return", etc. If it is null, this is parameter passing
4024 for a function call (and different error messages are output).
4026 FUNNAME is the name of the function being called,
4027 as an IDENTIFIER_NODE, or null.
4028 PARMNUM is the number of the argument, for printing in error messages. */
4031 convert_for_assignment (type
, rhs
, errtype
, fundecl
, funname
, parmnum
)
4033 const char *errtype
;
4034 tree fundecl
, funname
;
4037 register enum tree_code codel
= TREE_CODE (type
);
4038 register tree rhstype
;
4039 register enum tree_code coder
;
4041 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
4042 /* Do not use STRIP_NOPS here. We do not want an enumerator
4043 whose value is 0 to count as a null pointer constant. */
4044 if (TREE_CODE (rhs
) == NON_LVALUE_EXPR
)
4045 rhs
= TREE_OPERAND (rhs
, 0);
4047 if (TREE_CODE (TREE_TYPE (rhs
)) == ARRAY_TYPE
4048 || TREE_CODE (TREE_TYPE (rhs
)) == FUNCTION_TYPE
)
4049 rhs
= default_conversion (rhs
);
4050 else if (optimize
&& TREE_CODE (rhs
) == VAR_DECL
)
4051 rhs
= decl_constant_value (rhs
);
4053 rhstype
= TREE_TYPE (rhs
);
4054 coder
= TREE_CODE (rhstype
);
4056 if (coder
== ERROR_MARK
)
4057 return error_mark_node
;
4059 if (TYPE_MAIN_VARIANT (type
) == TYPE_MAIN_VARIANT (rhstype
))
4061 overflow_warning (rhs
);
4062 /* Check for Objective-C protocols. This will issue a warning if
4063 there are protocol violations. No need to use the return value. */
4064 maybe_objc_comptypes (type
, rhstype
, 0);
4068 if (coder
== VOID_TYPE
)
4070 error ("void value not ignored as it ought to be");
4071 return error_mark_node
;
4073 /* Arithmetic types all interconvert, and enum is treated like int. */
4074 if ((codel
== INTEGER_TYPE
|| codel
== REAL_TYPE
|| codel
== ENUMERAL_TYPE
4075 || codel
== COMPLEX_TYPE
)
4076 && (coder
== INTEGER_TYPE
|| coder
== REAL_TYPE
|| coder
== ENUMERAL_TYPE
4077 || coder
== COMPLEX_TYPE
))
4078 return convert_and_check (type
, rhs
);
4080 /* Conversion to a transparent union from its member types.
4081 This applies only to function arguments. */
4082 else if (codel
== UNION_TYPE
&& TYPE_TRANSPARENT_UNION (type
) && ! errtype
)
4085 tree marginal_memb_type
= 0;
4087 for (memb_types
= TYPE_FIELDS (type
); memb_types
;
4088 memb_types
= TREE_CHAIN (memb_types
))
4090 tree memb_type
= TREE_TYPE (memb_types
);
4092 if (comptypes (TYPE_MAIN_VARIANT (memb_type
),
4093 TYPE_MAIN_VARIANT (rhstype
)))
4096 if (TREE_CODE (memb_type
) != POINTER_TYPE
)
4099 if (coder
== POINTER_TYPE
)
4101 register tree ttl
= TREE_TYPE (memb_type
);
4102 register tree ttr
= TREE_TYPE (rhstype
);
4104 /* Any non-function converts to a [const][volatile] void *
4105 and vice versa; otherwise, targets must be the same.
4106 Meanwhile, the lhs target must have all the qualifiers of
4108 if (TYPE_MAIN_VARIANT (ttl
) == void_type_node
4109 || TYPE_MAIN_VARIANT (ttr
) == void_type_node
4110 || comp_target_types (memb_type
, rhstype
))
4112 /* If this type won't generate any warnings, use it. */
4113 if (TYPE_QUALS (ttl
) == TYPE_QUALS (ttr
)
4114 || ((TREE_CODE (ttr
) == FUNCTION_TYPE
4115 && TREE_CODE (ttl
) == FUNCTION_TYPE
)
4116 ? ((TYPE_QUALS (ttl
) | TYPE_QUALS (ttr
))
4117 == TYPE_QUALS (ttr
))
4118 : ((TYPE_QUALS (ttl
) | TYPE_QUALS (ttr
))
4119 == TYPE_QUALS (ttl
))))
4122 /* Keep looking for a better type, but remember this one. */
4123 if (! marginal_memb_type
)
4124 marginal_memb_type
= memb_type
;
4128 /* Can convert integer zero to any pointer type. */
4129 if (integer_zerop (rhs
)
4130 || (TREE_CODE (rhs
) == NOP_EXPR
4131 && integer_zerop (TREE_OPERAND (rhs
, 0))))
4133 rhs
= null_pointer_node
;
4138 if (memb_types
|| marginal_memb_type
)
4142 /* We have only a marginally acceptable member type;
4143 it needs a warning. */
4144 register tree ttl
= TREE_TYPE (marginal_memb_type
);
4145 register tree ttr
= TREE_TYPE (rhstype
);
4147 /* Const and volatile mean something different for function
4148 types, so the usual warnings are not appropriate. */
4149 if (TREE_CODE (ttr
) == FUNCTION_TYPE
4150 && TREE_CODE (ttl
) == FUNCTION_TYPE
)
4152 /* Because const and volatile on functions are
4153 restrictions that say the function will not do
4154 certain things, it is okay to use a const or volatile
4155 function where an ordinary one is wanted, but not
4157 if (TYPE_QUALS (ttl
) & ~TYPE_QUALS (ttr
))
4158 warn_for_assignment ("%s makes qualified function pointer from unqualified",
4159 errtype
, funname
, parmnum
);
4161 else if (TYPE_QUALS (ttr
) & ~TYPE_QUALS (ttl
))
4162 warn_for_assignment ("%s discards qualifiers from pointer target type",
4167 if (pedantic
&& ! DECL_IN_SYSTEM_HEADER (fundecl
))
4168 pedwarn ("ANSI C prohibits argument conversion to union type");
4170 return build1 (NOP_EXPR
, type
, rhs
);
4174 /* Conversions among pointers */
4175 else if (codel
== POINTER_TYPE
&& coder
== POINTER_TYPE
)
4177 register tree ttl
= TREE_TYPE (type
);
4178 register tree ttr
= TREE_TYPE (rhstype
);
4180 /* Any non-function converts to a [const][volatile] void *
4181 and vice versa; otherwise, targets must be the same.
4182 Meanwhile, the lhs target must have all the qualifiers of the rhs. */
4183 if (TYPE_MAIN_VARIANT (ttl
) == void_type_node
4184 || TYPE_MAIN_VARIANT (ttr
) == void_type_node
4185 || comp_target_types (type
, rhstype
)
4186 || (unsigned_type (TYPE_MAIN_VARIANT (ttl
))
4187 == unsigned_type (TYPE_MAIN_VARIANT (ttr
))))
4190 && ((TYPE_MAIN_VARIANT (ttl
) == void_type_node
4191 && TREE_CODE (ttr
) == FUNCTION_TYPE
)
4193 (TYPE_MAIN_VARIANT (ttr
) == void_type_node
4194 /* Check TREE_CODE to catch cases like (void *) (char *) 0
4195 which are not ANSI null ptr constants. */
4196 && (!integer_zerop (rhs
) || TREE_CODE (rhs
) == NOP_EXPR
)
4197 && TREE_CODE (ttl
) == FUNCTION_TYPE
)))
4198 warn_for_assignment ("ANSI forbids %s between function pointer and `void *'",
4199 errtype
, funname
, parmnum
);
4200 /* Const and volatile mean something different for function types,
4201 so the usual warnings are not appropriate. */
4202 else if (TREE_CODE (ttr
) != FUNCTION_TYPE
4203 && TREE_CODE (ttl
) != FUNCTION_TYPE
)
4205 if (TYPE_QUALS (ttr
) & ~TYPE_QUALS (ttl
))
4206 warn_for_assignment ("%s discards qualifiers from pointer target type",
4207 errtype
, funname
, parmnum
);
4208 /* If this is not a case of ignoring a mismatch in signedness,
4210 else if (TYPE_MAIN_VARIANT (ttl
) == void_type_node
4211 || TYPE_MAIN_VARIANT (ttr
) == void_type_node
4212 || comp_target_types (type
, rhstype
))
4214 /* If there is a mismatch, do warn. */
4216 warn_for_assignment ("pointer targets in %s differ in signedness",
4217 errtype
, funname
, parmnum
);
4219 else if (TREE_CODE (ttl
) == FUNCTION_TYPE
4220 && TREE_CODE (ttr
) == FUNCTION_TYPE
)
4222 /* Because const and volatile on functions are restrictions
4223 that say the function will not do certain things,
4224 it is okay to use a const or volatile function
4225 where an ordinary one is wanted, but not vice-versa. */
4226 if (TYPE_QUALS (ttl
) & ~TYPE_QUALS (ttr
))
4227 warn_for_assignment ("%s makes qualified function pointer from unqualified",
4228 errtype
, funname
, parmnum
);
4232 warn_for_assignment ("%s from incompatible pointer type",
4233 errtype
, funname
, parmnum
);
4234 return convert (type
, rhs
);
4236 else if (codel
== POINTER_TYPE
&& coder
== INTEGER_TYPE
)
4238 /* An explicit constant 0 can convert to a pointer,
4239 or one that results from arithmetic, even including
4240 a cast to integer type. */
4241 if (! (TREE_CODE (rhs
) == INTEGER_CST
&& integer_zerop (rhs
))
4243 ! (TREE_CODE (rhs
) == NOP_EXPR
4244 && TREE_CODE (TREE_TYPE (rhs
)) == INTEGER_TYPE
4245 && TREE_CODE (TREE_OPERAND (rhs
, 0)) == INTEGER_CST
4246 && integer_zerop (TREE_OPERAND (rhs
, 0))))
4248 warn_for_assignment ("%s makes pointer from integer without a cast",
4249 errtype
, funname
, parmnum
);
4250 return convert (type
, rhs
);
4252 return null_pointer_node
;
4254 else if (codel
== INTEGER_TYPE
&& coder
== POINTER_TYPE
)
4256 warn_for_assignment ("%s makes integer from pointer without a cast",
4257 errtype
, funname
, parmnum
);
4258 return convert (type
, rhs
);
4265 tree selector
= maybe_building_objc_message_expr ();
4267 if (selector
&& parmnum
> 2)
4268 error ("incompatible type for argument %d of `%s'",
4269 parmnum
- 2, IDENTIFIER_POINTER (selector
));
4271 error ("incompatible type for argument %d of `%s'",
4272 parmnum
, IDENTIFIER_POINTER (funname
));
4275 error ("incompatible type for argument %d of indirect function call",
4279 error ("incompatible types in %s", errtype
);
4281 return error_mark_node
;
4284 /* Print a warning using MSGID.
4285 It gets OPNAME as its one parameter.
4286 If OPNAME is null, it is replaced by "passing arg ARGNUM of `FUNCTION'".
4287 FUNCTION and ARGNUM are handled specially if we are building an
4288 Objective-C selector. */
4291 warn_for_assignment (msgid
, opname
, function
, argnum
)
4299 tree selector
= maybe_building_objc_message_expr ();
4302 if (selector
&& argnum
> 2)
4304 function
= selector
;
4309 /* Function name is known; supply it. */
4310 const char *argstring
= _("passing arg %d of `%s'");
4311 new_opname
= (char *) alloca (IDENTIFIER_LENGTH (function
)
4312 + strlen (argstring
) + 1 + 25
4314 sprintf (new_opname
, argstring
, argnum
,
4315 IDENTIFIER_POINTER (function
));
4319 /* Function name unknown (call through ptr); just give arg number.*/
4320 const char *argnofun
= _("passing arg %d of pointer to function");
4321 new_opname
= (char *) alloca (strlen (argnofun
) + 1 + 25 /*%d*/ + 1);
4322 sprintf (new_opname
, argnofun
, argnum
);
4324 opname
= new_opname
;
4326 pedwarn (msgid
, opname
);
4329 /* Return nonzero if VALUE is a valid constant-valued expression
4330 for use in initializing a static variable; one that can be an
4331 element of a "constant" initializer.
4333 Return null_pointer_node if the value is absolute;
4334 if it is relocatable, return the variable that determines the relocation.
4335 We assume that VALUE has been folded as much as possible;
4336 therefore, we do not need to check for such things as
4337 arithmetic-combinations of integers. */
4340 initializer_constant_valid_p (value
, endtype
)
4344 switch (TREE_CODE (value
))
4347 if ((TREE_CODE (TREE_TYPE (value
)) == UNION_TYPE
4348 || TREE_CODE (TREE_TYPE (value
)) == RECORD_TYPE
)
4349 && TREE_CONSTANT (value
)
4350 && CONSTRUCTOR_ELTS (value
))
4352 initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value
)),
4355 return TREE_STATIC (value
) ? null_pointer_node
: 0;
4361 return null_pointer_node
;
4364 return TREE_OPERAND (value
, 0);
4366 case NON_LVALUE_EXPR
:
4367 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
4371 /* Allow conversions between pointer types. */
4372 if (TREE_CODE (TREE_TYPE (value
)) == POINTER_TYPE
4373 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value
, 0))) == POINTER_TYPE
)
4374 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
4376 /* Allow conversions between real types. */
4377 if (TREE_CODE (TREE_TYPE (value
)) == REAL_TYPE
4378 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value
, 0))) == REAL_TYPE
)
4379 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
4381 /* Allow length-preserving conversions between integer types. */
4382 if (TREE_CODE (TREE_TYPE (value
)) == INTEGER_TYPE
4383 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value
, 0))) == INTEGER_TYPE
4384 && (TYPE_PRECISION (TREE_TYPE (value
))
4385 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0)))))
4386 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
4388 /* Allow conversions between other integer types only if
4390 if (TREE_CODE (TREE_TYPE (value
)) == INTEGER_TYPE
4391 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value
, 0))) == INTEGER_TYPE
)
4393 tree inner
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4395 if (inner
== null_pointer_node
)
4396 return null_pointer_node
;
4400 /* Allow (int) &foo provided int is as wide as a pointer. */
4401 if (TREE_CODE (TREE_TYPE (value
)) == INTEGER_TYPE
4402 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value
, 0))) == POINTER_TYPE
4403 && (TYPE_PRECISION (TREE_TYPE (value
))
4404 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0)))))
4405 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4408 /* Likewise conversions from int to pointers, but also allow
4409 conversions from 0. */
4410 if (TREE_CODE (TREE_TYPE (value
)) == POINTER_TYPE
4411 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value
, 0))) == INTEGER_TYPE
)
4413 if (integer_zerop (TREE_OPERAND (value
, 0)))
4414 return null_pointer_node
;
4415 else if (TYPE_PRECISION (TREE_TYPE (value
))
4416 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0))))
4417 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4421 /* Allow conversions to union types if the value inside is okay. */
4422 if (TREE_CODE (TREE_TYPE (value
)) == UNION_TYPE
)
4423 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4428 if (TREE_CODE (endtype
) == INTEGER_TYPE
4429 && TYPE_PRECISION (endtype
) < POINTER_SIZE
)
4432 tree valid0
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4434 tree valid1
= initializer_constant_valid_p (TREE_OPERAND (value
, 1),
4436 /* If either term is absolute, use the other terms relocation. */
4437 if (valid0
== null_pointer_node
)
4439 if (valid1
== null_pointer_node
)
4445 if (TREE_CODE (endtype
) == INTEGER_TYPE
4446 && TYPE_PRECISION (endtype
) < POINTER_SIZE
)
4449 tree valid0
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4451 tree valid1
= initializer_constant_valid_p (TREE_OPERAND (value
, 1),
4453 /* Win if second argument is absolute. */
4454 if (valid1
== null_pointer_node
)
4456 /* Win if both arguments have the same relocation.
4457 Then the value is absolute. */
4458 if (valid0
== valid1
)
4459 return null_pointer_node
;
4468 /* If VALUE is a compound expr all of whose expressions are constant, then
4469 return its value. Otherwise, return error_mark_node.
4471 This is for handling COMPOUND_EXPRs as initializer elements
4472 which is allowed with a warning when -pedantic is specified. */
4475 valid_compound_expr_initializer (value
, endtype
)
4479 if (TREE_CODE (value
) == COMPOUND_EXPR
)
4481 if (valid_compound_expr_initializer (TREE_OPERAND (value
, 0), endtype
)
4483 return error_mark_node
;
4484 return valid_compound_expr_initializer (TREE_OPERAND (value
, 1),
4487 else if (! TREE_CONSTANT (value
)
4488 && ! initializer_constant_valid_p (value
, endtype
))
4489 return error_mark_node
;
4494 /* Perform appropriate conversions on the initial value of a variable,
4495 store it in the declaration DECL,
4496 and print any error messages that are appropriate.
4497 If the init is invalid, store an ERROR_MARK. */
4500 store_init_value (decl
, init
)
4503 register tree value
, type
;
4505 /* If variable's type was invalidly declared, just ignore it. */
4507 type
= TREE_TYPE (decl
);
4508 if (TREE_CODE (type
) == ERROR_MARK
)
4511 /* Digest the specified initializer into an expression. */
4513 value
= digest_init (type
, init
, TREE_STATIC (decl
),
4514 TREE_STATIC (decl
) || pedantic
);
4516 /* Store the expression if valid; else report error. */
4519 /* Note that this is the only place we can detect the error
4520 in a case such as struct foo bar = (struct foo) { x, y };
4521 where there is one initial value which is a constructor expression. */
4522 if (value
== error_mark_node
)
4524 else if (TREE_STATIC (decl
) && ! TREE_CONSTANT (value
))
4526 error ("initializer for static variable is not constant");
4527 value
= error_mark_node
;
4529 else if (TREE_STATIC (decl
)
4530 && initializer_constant_valid_p (value
, TREE_TYPE (value
)) == 0)
4532 error ("initializer for static variable uses complicated arithmetic");
4533 value
= error_mark_node
;
4537 if (pedantic
&& TREE_CODE (value
) == CONSTRUCTOR
)
4539 if (! TREE_CONSTANT (value
))
4540 pedwarn ("aggregate initializer is not constant");
4541 else if (! TREE_STATIC (value
))
4542 pedwarn ("aggregate initializer uses complicated arithmetic");
4547 DECL_INITIAL (decl
) = value
;
4549 /* ANSI wants warnings about out-of-range constant initializers. */
4550 STRIP_TYPE_NOPS (value
);
4551 constant_expression_warning (value
);
4554 /* Methods for storing and printing names for error messages. */
4556 /* Implement a spelling stack that allows components of a name to be pushed
4557 and popped. Each element on the stack is this structure. */
4569 #define SPELLING_STRING 1
4570 #define SPELLING_MEMBER 2
4571 #define SPELLING_BOUNDS 3
4573 static struct spelling
*spelling
; /* Next stack element (unused). */
4574 static struct spelling
*spelling_base
; /* Spelling stack base. */
4575 static int spelling_size
; /* Size of the spelling stack. */
4577 /* Macros to save and restore the spelling stack around push_... functions.
4578 Alternative to SAVE_SPELLING_STACK. */
4580 #define SPELLING_DEPTH() (spelling - spelling_base)
4581 #define RESTORE_SPELLING_DEPTH(depth) (spelling = spelling_base + depth)
4583 /* Save and restore the spelling stack around arbitrary C code. */
4585 #define SAVE_SPELLING_DEPTH(code) \
4587 int __depth = SPELLING_DEPTH (); \
4589 RESTORE_SPELLING_DEPTH (__depth); \
4592 /* Push an element on the spelling stack with type KIND and assign VALUE
4595 #define PUSH_SPELLING(KIND, VALUE, MEMBER) \
4597 int depth = SPELLING_DEPTH (); \
4599 if (depth >= spelling_size) \
4601 spelling_size += 10; \
4602 if (spelling_base == 0) \
4604 = (struct spelling *) xmalloc (spelling_size * sizeof (struct spelling)); \
4607 = (struct spelling *) xrealloc (spelling_base, \
4608 spelling_size * sizeof (struct spelling)); \
4609 RESTORE_SPELLING_DEPTH (depth); \
4612 spelling->kind = (KIND); \
4613 spelling->MEMBER = (VALUE); \
4617 /* Push STRING on the stack. Printed literally. */
4620 push_string (string
)
4623 PUSH_SPELLING (SPELLING_STRING
, string
, u
.s
);
4626 /* Push a member name on the stack. Printed as '.' STRING. */
4629 push_member_name (decl
)
4634 = DECL_NAME (decl
) ? IDENTIFIER_POINTER (DECL_NAME (decl
)) : "<anonymous>";
4635 PUSH_SPELLING (SPELLING_MEMBER
, string
, u
.s
);
4638 /* Push an array bounds on the stack. Printed as [BOUNDS]. */
4641 push_array_bounds (bounds
)
4644 PUSH_SPELLING (SPELLING_BOUNDS
, bounds
, u
.i
);
4647 /* Compute the maximum size in bytes of the printed spelling. */
4652 register int size
= 0;
4653 register struct spelling
*p
;
4655 for (p
= spelling_base
; p
< spelling
; p
++)
4657 if (p
->kind
== SPELLING_BOUNDS
)
4660 size
+= strlen (p
->u
.s
) + 1;
4666 /* Print the spelling to BUFFER and return it. */
4669 print_spelling (buffer
)
4670 register char *buffer
;
4672 register char *d
= buffer
;
4673 register struct spelling
*p
;
4675 for (p
= spelling_base
; p
< spelling
; p
++)
4676 if (p
->kind
== SPELLING_BOUNDS
)
4678 sprintf (d
, "[%d]", p
->u
.i
);
4683 register const char *s
;
4684 if (p
->kind
== SPELLING_MEMBER
)
4686 for (s
= p
->u
.s
; (*d
= *s
++); d
++)
4693 /* Issue an error message for a bad initializer component.
4694 MSGID identifies the message.
4695 The component name is taken from the spelling stack. */
4704 ofwhat
= print_spelling ((char *) alloca (spelling_length () + 1));
4706 error ("(near initialization for `%s')", ofwhat
);
4709 /* Issue a pedantic warning for a bad initializer component.
4710 MSGID identifies the message.
4711 The component name is taken from the spelling stack. */
4714 pedwarn_init (msgid
)
4720 ofwhat
= print_spelling ((char *) alloca (spelling_length () + 1));
4722 pedwarn ("(near initialization for `%s')", ofwhat
);
4725 /* Issue a warning for a bad initializer component.
4726 MSGID identifies the message.
4727 The component name is taken from the spelling stack. */
4730 warning_init (msgid
)
4736 ofwhat
= print_spelling ((char *) alloca (spelling_length () + 1));
4738 warning ("(near initialization for `%s')", ofwhat
);
4741 /* Digest the parser output INIT as an initializer for type TYPE.
4742 Return a C expression of type TYPE to represent the initial value.
4744 The arguments REQUIRE_CONSTANT and CONSTRUCTOR_CONSTANT request errors
4745 if non-constant initializers or elements are seen. CONSTRUCTOR_CONSTANT
4746 applies only to elements of constructors. */
4749 digest_init (type
, init
, require_constant
, constructor_constant
)
4751 int require_constant
, constructor_constant
;
4753 enum tree_code code
= TREE_CODE (type
);
4754 tree inside_init
= init
;
4756 if (init
== error_mark_node
)
4759 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
4760 /* Do not use STRIP_NOPS here. We do not want an enumerator
4761 whose value is 0 to count as a null pointer constant. */
4762 if (TREE_CODE (init
) == NON_LVALUE_EXPR
)
4763 inside_init
= TREE_OPERAND (init
, 0);
4765 /* Initialization of an array of chars from a string constant
4766 optionally enclosed in braces. */
4768 if (code
== ARRAY_TYPE
)
4770 tree typ1
= TYPE_MAIN_VARIANT (TREE_TYPE (type
));
4771 if ((typ1
== char_type_node
4772 || typ1
== signed_char_type_node
4773 || typ1
== unsigned_char_type_node
4774 || typ1
== unsigned_wchar_type_node
4775 || typ1
== signed_wchar_type_node
)
4776 && ((inside_init
&& TREE_CODE (inside_init
) == STRING_CST
)))
4778 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init
)),
4779 TYPE_MAIN_VARIANT (type
)))
4782 if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init
)))
4784 && TYPE_PRECISION (typ1
) == TYPE_PRECISION (char_type_node
))
4786 error_init ("char-array initialized from wide string");
4787 return error_mark_node
;
4789 if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init
)))
4791 && TYPE_PRECISION (typ1
) != TYPE_PRECISION (char_type_node
))
4793 error_init ("int-array initialized from non-wide string");
4794 return error_mark_node
;
4797 TREE_TYPE (inside_init
) = type
;
4798 if (TYPE_DOMAIN (type
) != 0
4799 && TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
4801 register int size
= TREE_INT_CST_LOW (TYPE_SIZE (type
));
4802 size
= (size
+ BITS_PER_UNIT
- 1) / BITS_PER_UNIT
;
4803 /* Subtract 1 (or sizeof (wchar_t))
4804 because it's ok to ignore the terminating null char
4805 that is counted in the length of the constant. */
4806 if (size
< TREE_STRING_LENGTH (inside_init
)
4807 - (TYPE_PRECISION (typ1
) != TYPE_PRECISION (char_type_node
)
4808 ? TYPE_PRECISION (wchar_type_node
) / BITS_PER_UNIT
4810 pedwarn_init ("initializer-string for array of chars is too long");
4816 /* Any type can be initialized
4817 from an expression of the same type, optionally with braces. */
4819 if (inside_init
&& TREE_TYPE (inside_init
) != 0
4820 && (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init
)),
4821 TYPE_MAIN_VARIANT (type
))
4822 || (code
== ARRAY_TYPE
4823 && comptypes (TREE_TYPE (inside_init
), type
))
4824 || (code
== POINTER_TYPE
4825 && (TREE_CODE (TREE_TYPE (inside_init
)) == ARRAY_TYPE
4826 || TREE_CODE (TREE_TYPE (inside_init
)) == FUNCTION_TYPE
)
4827 && comptypes (TREE_TYPE (TREE_TYPE (inside_init
)),
4828 TREE_TYPE (type
)))))
4830 if (code
== POINTER_TYPE
4831 && (TREE_CODE (TREE_TYPE (inside_init
)) == ARRAY_TYPE
4832 || TREE_CODE (TREE_TYPE (inside_init
)) == FUNCTION_TYPE
))
4833 inside_init
= default_conversion (inside_init
);
4834 else if (code
== ARRAY_TYPE
&& TREE_CODE (inside_init
) != STRING_CST
4835 && TREE_CODE (inside_init
) != CONSTRUCTOR
)
4837 error_init ("array initialized from non-constant array expression");
4838 return error_mark_node
;
4841 if (optimize
&& TREE_CODE (inside_init
) == VAR_DECL
)
4842 inside_init
= decl_constant_value (inside_init
);
4844 /* Compound expressions can only occur here if -pedantic or
4845 -pedantic-errors is specified. In the later case, we always want
4846 an error. In the former case, we simply want a warning. */
4847 if (require_constant
&& pedantic
4848 && TREE_CODE (inside_init
) == COMPOUND_EXPR
)
4851 = valid_compound_expr_initializer (inside_init
,
4852 TREE_TYPE (inside_init
));
4853 if (inside_init
== error_mark_node
)
4854 error_init ("initializer element is not constant");
4856 pedwarn_init ("initializer element is not constant");
4857 if (flag_pedantic_errors
)
4858 inside_init
= error_mark_node
;
4860 else if (require_constant
&& ! TREE_CONSTANT (inside_init
))
4862 error_init ("initializer element is not constant");
4863 inside_init
= error_mark_node
;
4865 else if (require_constant
4866 && initializer_constant_valid_p (inside_init
, TREE_TYPE (inside_init
)) == 0)
4868 error_init ("initializer element is not computable at load time");
4869 inside_init
= error_mark_node
;
4875 /* Handle scalar types, including conversions. */
4877 if (code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== POINTER_TYPE
4878 || code
== ENUMERAL_TYPE
|| code
== COMPLEX_TYPE
)
4880 /* Note that convert_for_assignment calls default_conversion
4881 for arrays and functions. We must not call it in the
4882 case where inside_init is a null pointer constant. */
4884 = convert_for_assignment (type
, init
, _("initialization"),
4885 NULL_TREE
, NULL_TREE
, 0);
4887 if (require_constant
&& ! TREE_CONSTANT (inside_init
))
4889 error_init ("initializer element is not constant");
4890 inside_init
= error_mark_node
;
4892 else if (require_constant
4893 && initializer_constant_valid_p (inside_init
, TREE_TYPE (inside_init
)) == 0)
4895 error_init ("initializer element is not computable at load time");
4896 inside_init
= error_mark_node
;
4902 /* Come here only for records and arrays. */
4904 if (TYPE_SIZE (type
) && TREE_CODE (TYPE_SIZE (type
)) != INTEGER_CST
)
4906 error_init ("variable-sized object may not be initialized");
4907 return error_mark_node
;
4910 /* Traditionally, you can write struct foo x = 0;
4911 and it initializes the first element of x to 0. */
4912 if (flag_traditional
)
4914 tree top
= 0, prev
= 0, otype
= type
;
4915 while (TREE_CODE (type
) == RECORD_TYPE
4916 || TREE_CODE (type
) == ARRAY_TYPE
4917 || TREE_CODE (type
) == QUAL_UNION_TYPE
4918 || TREE_CODE (type
) == UNION_TYPE
)
4920 tree temp
= build (CONSTRUCTOR
, type
, NULL_TREE
, NULL_TREE
);
4924 TREE_OPERAND (prev
, 1) = build_tree_list (NULL_TREE
, temp
);
4926 if (TREE_CODE (type
) == ARRAY_TYPE
)
4927 type
= TREE_TYPE (type
);
4928 else if (TYPE_FIELDS (type
))
4929 type
= TREE_TYPE (TYPE_FIELDS (type
));
4932 error_init ("invalid initializer");
4933 return error_mark_node
;
4939 TREE_OPERAND (prev
, 1)
4940 = build_tree_list (NULL_TREE
,
4941 digest_init (type
, init
, require_constant
,
4942 constructor_constant
));
4946 return error_mark_node
;
4948 error_init ("invalid initializer");
4949 return error_mark_node
;
4952 /* Handle initializers that use braces. */
4954 /* Type of object we are accumulating a constructor for.
4955 This type is always a RECORD_TYPE, UNION_TYPE or ARRAY_TYPE. */
4956 static tree constructor_type
;
4958 /* For a RECORD_TYPE or UNION_TYPE, this is the chain of fields
4960 static tree constructor_fields
;
4962 /* For an ARRAY_TYPE, this is the specified index
4963 at which to store the next element we get.
4964 This is a special INTEGER_CST node that we modify in place. */
4965 static tree constructor_index
;
4967 /* For an ARRAY_TYPE, this is the end index of the range
4968 to initialize with the next element, or NULL in the ordinary case
4969 where the element is used just once. */
4970 static tree constructor_range_end
;
4972 /* For an ARRAY_TYPE, this is the maximum index. */
4973 static tree constructor_max_index
;
4975 /* For a RECORD_TYPE, this is the first field not yet written out. */
4976 static tree constructor_unfilled_fields
;
4978 /* For an ARRAY_TYPE, this is the index of the first element
4979 not yet written out.
4980 This is a special INTEGER_CST node that we modify in place. */
4981 static tree constructor_unfilled_index
;
4983 /* In a RECORD_TYPE, the byte index of the next consecutive field.
4984 This is so we can generate gaps between fields, when appropriate.
4985 This is a special INTEGER_CST node that we modify in place. */
4986 static tree constructor_bit_index
;
4988 /* If we are saving up the elements rather than allocating them,
4989 this is the list of elements so far (in reverse order,
4990 most recent first). */
4991 static tree constructor_elements
;
4993 /* 1 if so far this constructor's elements are all compile-time constants. */
4994 static int constructor_constant
;
4996 /* 1 if so far this constructor's elements are all valid address constants. */
4997 static int constructor_simple
;
4999 /* 1 if this constructor is erroneous so far. */
5000 static int constructor_erroneous
;
5002 /* 1 if have called defer_addressed_constants. */
5003 static int constructor_subconstants_deferred
;
5005 /* Structure for managing pending initializer elements, organized as an
5010 struct init_node
*left
, *right
;
5011 struct init_node
*parent
;
5017 /* Tree of pending elements at this constructor level.
5018 These are elements encountered out of order
5019 which belong at places we haven't reached yet in actually
5020 writing the output. */
5021 static struct init_node
*constructor_pending_elts
;
5023 /* The SPELLING_DEPTH of this constructor. */
5024 static int constructor_depth
;
5026 /* 0 if implicitly pushing constructor levels is allowed. */
5027 int constructor_no_implicit
= 0; /* 0 for C; 1 for some other languages. */
5029 static int require_constant_value
;
5030 static int require_constant_elements
;
5032 /* 1 if it is ok to output this constructor as we read it.
5033 0 means must accumulate a CONSTRUCTOR expression. */
5034 static int constructor_incremental
;
5036 /* DECL node for which an initializer is being read.
5037 0 means we are reading a constructor expression
5038 such as (struct foo) {...}. */
5039 static tree constructor_decl
;
5041 /* start_init saves the ASMSPEC arg here for really_start_incremental_init. */
5042 static char *constructor_asmspec
;
5044 /* Nonzero if this is an initializer for a top-level decl. */
5045 static int constructor_top_level
;
5048 /* This stack has a level for each implicit or explicit level of
5049 structuring in the initializer, including the outermost one. It
5050 saves the values of most of the variables above. */
5052 struct constructor_stack
5054 struct constructor_stack
*next
;
5060 tree unfilled_index
;
5061 tree unfilled_fields
;
5065 struct init_node
*pending_elts
;
5067 /* If nonzero, this value should replace the entire
5068 constructor at this level. */
5069 tree replacement_value
;
5078 struct constructor_stack
*constructor_stack
;
5080 /* This stack records separate initializers that are nested.
5081 Nested initializers can't happen in ANSI C, but GNU C allows them
5082 in cases like { ... (struct foo) { ... } ... }. */
5084 struct initializer_stack
5086 struct initializer_stack
*next
;
5089 struct constructor_stack
*constructor_stack
;
5091 struct spelling
*spelling
;
5092 struct spelling
*spelling_base
;
5096 char require_constant_value
;
5097 char require_constant_elements
;
5101 struct initializer_stack
*initializer_stack
;
5103 /* Prepare to parse and output the initializer for variable DECL. */
5106 start_init (decl
, asmspec_tree
, top_level
)
5112 struct initializer_stack
*p
5113 = (struct initializer_stack
*) xmalloc (sizeof (struct initializer_stack
));
5117 asmspec
= TREE_STRING_POINTER (asmspec_tree
);
5119 p
->decl
= constructor_decl
;
5120 p
->asmspec
= constructor_asmspec
;
5121 p
->incremental
= constructor_incremental
;
5122 p
->require_constant_value
= require_constant_value
;
5123 p
->require_constant_elements
= require_constant_elements
;
5124 p
->constructor_stack
= constructor_stack
;
5125 p
->elements
= constructor_elements
;
5126 p
->spelling
= spelling
;
5127 p
->spelling_base
= spelling_base
;
5128 p
->spelling_size
= spelling_size
;
5129 p
->deferred
= constructor_subconstants_deferred
;
5130 p
->top_level
= constructor_top_level
;
5131 p
->next
= initializer_stack
;
5132 initializer_stack
= p
;
5134 constructor_decl
= decl
;
5135 constructor_incremental
= top_level
;
5136 constructor_asmspec
= asmspec
;
5137 constructor_subconstants_deferred
= 0;
5138 constructor_top_level
= top_level
;
5142 require_constant_value
= TREE_STATIC (decl
);
5143 require_constant_elements
5144 = ((TREE_STATIC (decl
) || pedantic
)
5145 /* For a scalar, you can always use any value to initialize,
5146 even within braces. */
5147 && (TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
5148 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
5149 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
5150 || TREE_CODE (TREE_TYPE (decl
)) == QUAL_UNION_TYPE
));
5151 locus
= IDENTIFIER_POINTER (DECL_NAME (decl
));
5152 constructor_incremental
|= TREE_STATIC (decl
);
5156 require_constant_value
= 0;
5157 require_constant_elements
= 0;
5158 locus
= "(anonymous)";
5161 constructor_stack
= 0;
5163 missing_braces_mentioned
= 0;
5167 RESTORE_SPELLING_DEPTH (0);
5170 push_string (locus
);
5176 struct initializer_stack
*p
= initializer_stack
;
5178 /* Output subconstants (string constants, usually)
5179 that were referenced within this initializer and saved up.
5180 Must do this if and only if we called defer_addressed_constants. */
5181 if (constructor_subconstants_deferred
)
5182 output_deferred_addressed_constants ();
5184 /* Free the whole constructor stack of this initializer. */
5185 while (constructor_stack
)
5187 struct constructor_stack
*q
= constructor_stack
;
5188 constructor_stack
= q
->next
;
5192 /* Pop back to the data of the outer initializer (if any). */
5193 constructor_decl
= p
->decl
;
5194 constructor_asmspec
= p
->asmspec
;
5195 constructor_incremental
= p
->incremental
;
5196 require_constant_value
= p
->require_constant_value
;
5197 require_constant_elements
= p
->require_constant_elements
;
5198 constructor_stack
= p
->constructor_stack
;
5199 constructor_elements
= p
->elements
;
5200 spelling
= p
->spelling
;
5201 spelling_base
= p
->spelling_base
;
5202 spelling_size
= p
->spelling_size
;
5203 constructor_subconstants_deferred
= p
->deferred
;
5204 constructor_top_level
= p
->top_level
;
5205 initializer_stack
= p
->next
;
5209 /* Call here when we see the initializer is surrounded by braces.
5210 This is instead of a call to push_init_level;
5211 it is matched by a call to pop_init_level.
5213 TYPE is the type to initialize, for a constructor expression.
5214 For an initializer for a decl, TYPE is zero. */
5217 really_start_incremental_init (type
)
5220 struct constructor_stack
*p
5221 = (struct constructor_stack
*) xmalloc (sizeof (struct constructor_stack
));
5224 type
= TREE_TYPE (constructor_decl
);
5226 /* Turn off constructor_incremental if type is a struct with bitfields.
5227 Do this before the first push, so that the corrected value
5228 is available in finish_init. */
5229 check_init_type_bitfields (type
);
5231 p
->type
= constructor_type
;
5232 p
->fields
= constructor_fields
;
5233 p
->index
= constructor_index
;
5234 p
->range_end
= constructor_range_end
;
5235 p
->max_index
= constructor_max_index
;
5236 p
->unfilled_index
= constructor_unfilled_index
;
5237 p
->unfilled_fields
= constructor_unfilled_fields
;
5238 p
->bit_index
= constructor_bit_index
;
5239 p
->elements
= constructor_elements
;
5240 p
->constant
= constructor_constant
;
5241 p
->simple
= constructor_simple
;
5242 p
->erroneous
= constructor_erroneous
;
5243 p
->pending_elts
= constructor_pending_elts
;
5244 p
->depth
= constructor_depth
;
5245 p
->replacement_value
= 0;
5247 p
->incremental
= constructor_incremental
;
5250 constructor_stack
= p
;
5252 constructor_constant
= 1;
5253 constructor_simple
= 1;
5254 constructor_depth
= SPELLING_DEPTH ();
5255 constructor_elements
= 0;
5256 constructor_pending_elts
= 0;
5257 constructor_type
= type
;
5259 if (TREE_CODE (constructor_type
) == RECORD_TYPE
5260 || TREE_CODE (constructor_type
) == UNION_TYPE
)
5262 constructor_fields
= TYPE_FIELDS (constructor_type
);
5263 /* Skip any nameless bit fields at the beginning. */
5264 while (constructor_fields
!= 0 && DECL_C_BIT_FIELD (constructor_fields
)
5265 && DECL_NAME (constructor_fields
) == 0)
5266 constructor_fields
= TREE_CHAIN (constructor_fields
);
5267 constructor_unfilled_fields
= constructor_fields
;
5268 constructor_bit_index
= copy_node (integer_zero_node
);
5269 TREE_TYPE (constructor_bit_index
) = sbitsizetype
;
5271 else if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
5273 constructor_range_end
= 0;
5274 if (TYPE_DOMAIN (constructor_type
))
5276 constructor_max_index
5277 = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type
));
5279 = copy_node (TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type
)));
5282 constructor_index
= copy_node (integer_zero_node
);
5283 constructor_unfilled_index
= copy_node (constructor_index
);
5287 /* Handle the case of int x = {5}; */
5288 constructor_fields
= constructor_type
;
5289 constructor_unfilled_fields
= constructor_type
;
5292 if (constructor_incremental
)
5294 int momentary
= suspend_momentary ();
5295 push_obstacks_nochange ();
5296 if (TREE_PERMANENT (constructor_decl
))
5297 end_temporary_allocation ();
5298 make_decl_rtl (constructor_decl
, constructor_asmspec
,
5299 constructor_top_level
);
5300 assemble_variable (constructor_decl
, constructor_top_level
, 0, 1);
5302 resume_momentary (momentary
);
5305 if (constructor_incremental
)
5307 defer_addressed_constants ();
5308 constructor_subconstants_deferred
= 1;
5312 /* Push down into a subobject, for initialization.
5313 If this is for an explicit set of braces, IMPLICIT is 0.
5314 If it is because the next element belongs at a lower level,
5318 push_init_level (implicit
)
5321 struct constructor_stack
*p
;
5323 /* If we've exhausted any levels that didn't have braces,
5325 while (constructor_stack
->implicit
)
5327 if ((TREE_CODE (constructor_type
) == RECORD_TYPE
5328 || TREE_CODE (constructor_type
) == UNION_TYPE
)
5329 && constructor_fields
== 0)
5330 process_init_element (pop_init_level (1));
5331 else if (TREE_CODE (constructor_type
) == ARRAY_TYPE
5332 && tree_int_cst_lt (constructor_max_index
, constructor_index
))
5333 process_init_element (pop_init_level (1));
5338 /* Structure elements may require alignment. Do this now if necessary
5339 for the subaggregate, and if it comes next in sequence. Don't do
5340 this for subaggregates that will go on the pending list. */
5341 if (constructor_incremental
&& constructor_type
!= 0
5342 && TREE_CODE (constructor_type
) == RECORD_TYPE
&& constructor_fields
5343 && constructor_fields
== constructor_unfilled_fields
)
5345 /* Advance to offset of this element. */
5346 if (! tree_int_cst_equal (constructor_bit_index
,
5347 DECL_FIELD_BITPOS (constructor_fields
)))
5349 /* By using unsigned arithmetic, the result will be correct even
5350 in case of overflows, if BITS_PER_UNIT is a power of two. */
5351 unsigned next
= (TREE_INT_CST_LOW
5352 (DECL_FIELD_BITPOS (constructor_fields
))
5353 / (unsigned)BITS_PER_UNIT
);
5354 unsigned here
= (TREE_INT_CST_LOW (constructor_bit_index
)
5355 / (unsigned)BITS_PER_UNIT
);
5357 assemble_zeros ((next
- here
)
5358 * (unsigned)BITS_PER_UNIT
5359 / (unsigned)BITS_PER_UNIT
);
5361 /* Indicate that we have now filled the structure up to the current
5363 constructor_unfilled_fields
= constructor_fields
;
5366 p
= (struct constructor_stack
*) xmalloc (sizeof (struct constructor_stack
));
5367 p
->type
= constructor_type
;
5368 p
->fields
= constructor_fields
;
5369 p
->index
= constructor_index
;
5370 p
->range_end
= constructor_range_end
;
5371 p
->max_index
= constructor_max_index
;
5372 p
->unfilled_index
= constructor_unfilled_index
;
5373 p
->unfilled_fields
= constructor_unfilled_fields
;
5374 p
->bit_index
= constructor_bit_index
;
5375 p
->elements
= constructor_elements
;
5376 p
->constant
= constructor_constant
;
5377 p
->simple
= constructor_simple
;
5378 p
->erroneous
= constructor_erroneous
;
5379 p
->pending_elts
= constructor_pending_elts
;
5380 p
->depth
= constructor_depth
;
5381 p
->replacement_value
= 0;
5382 p
->implicit
= implicit
;
5383 p
->incremental
= constructor_incremental
;
5385 p
->next
= constructor_stack
;
5386 constructor_stack
= p
;
5388 constructor_constant
= 1;
5389 constructor_simple
= 1;
5390 constructor_depth
= SPELLING_DEPTH ();
5391 constructor_elements
= 0;
5392 constructor_pending_elts
= 0;
5394 /* Don't die if an entire brace-pair level is superfluous
5395 in the containing level. */
5396 if (constructor_type
== 0)
5398 else if (TREE_CODE (constructor_type
) == RECORD_TYPE
5399 || TREE_CODE (constructor_type
) == UNION_TYPE
)
5401 /* Don't die if there are extra init elts at the end. */
5402 if (constructor_fields
== 0)
5403 constructor_type
= 0;
5406 constructor_type
= TREE_TYPE (constructor_fields
);
5407 push_member_name (constructor_fields
);
5408 constructor_depth
++;
5409 if (constructor_fields
!= constructor_unfilled_fields
)
5410 constructor_incremental
= 0;
5413 else if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
5415 constructor_type
= TREE_TYPE (constructor_type
);
5416 push_array_bounds (TREE_INT_CST_LOW (constructor_index
));
5417 constructor_depth
++;
5418 if (! tree_int_cst_equal (constructor_index
, constructor_unfilled_index
)
5419 || constructor_range_end
!= 0)
5420 constructor_incremental
= 0;
5423 if (constructor_type
== 0)
5425 error_init ("extra brace group at end of initializer");
5426 constructor_fields
= 0;
5427 constructor_unfilled_fields
= 0;
5431 /* Turn off constructor_incremental if type is a struct with bitfields. */
5432 check_init_type_bitfields (constructor_type
);
5434 if (implicit
&& warn_missing_braces
&& !missing_braces_mentioned
)
5436 missing_braces_mentioned
= 1;
5437 warning_init ("missing braces around initializer");
5440 if (TREE_CODE (constructor_type
) == RECORD_TYPE
5441 || TREE_CODE (constructor_type
) == UNION_TYPE
)
5443 constructor_fields
= TYPE_FIELDS (constructor_type
);
5444 /* Skip any nameless bit fields at the beginning. */
5445 while (constructor_fields
!= 0 && DECL_C_BIT_FIELD (constructor_fields
)
5446 && DECL_NAME (constructor_fields
) == 0)
5447 constructor_fields
= TREE_CHAIN (constructor_fields
);
5448 constructor_unfilled_fields
= constructor_fields
;
5449 constructor_bit_index
= copy_node (integer_zero_node
);
5450 TREE_TYPE (constructor_bit_index
) = sbitsizetype
;
5452 else if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
5454 constructor_range_end
= 0;
5455 if (TYPE_DOMAIN (constructor_type
))
5457 constructor_max_index
5458 = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type
));
5460 = copy_node (TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type
)));
5463 constructor_index
= copy_node (integer_zero_node
);
5464 constructor_unfilled_index
= copy_node (constructor_index
);
5468 warning_init ("braces around scalar initializer");
5469 constructor_fields
= constructor_type
;
5470 constructor_unfilled_fields
= constructor_type
;
5474 /* Don't read a struct incrementally if it has any bitfields,
5475 because the incremental reading code doesn't know how to
5476 handle bitfields yet. */
5479 check_init_type_bitfields (type
)
5482 if (TREE_CODE (type
) == RECORD_TYPE
)
5485 for (tail
= TYPE_FIELDS (type
); tail
;
5486 tail
= TREE_CHAIN (tail
))
5488 if (DECL_C_BIT_FIELD (tail
))
5490 constructor_incremental
= 0;
5494 check_init_type_bitfields (TREE_TYPE (tail
));
5498 else if (TREE_CODE (type
) == UNION_TYPE
)
5500 tree tail
= TYPE_FIELDS (type
);
5501 if (tail
&& DECL_C_BIT_FIELD (tail
))
5502 /* We also use the nonincremental algorithm for initiliazation
5503 of unions whose first member is a bitfield, becuase the
5504 incremental algorithm has no code for dealing with
5506 constructor_incremental
= 0;
5509 else if (TREE_CODE (type
) == ARRAY_TYPE
)
5510 check_init_type_bitfields (TREE_TYPE (type
));
5513 /* At the end of an implicit or explicit brace level,
5514 finish up that level of constructor.
5515 If we were outputting the elements as they are read, return 0
5516 from inner levels (process_init_element ignores that),
5517 but return error_mark_node from the outermost level
5518 (that's what we want to put in DECL_INITIAL).
5519 Otherwise, return a CONSTRUCTOR expression. */
5522 pop_init_level (implicit
)
5525 struct constructor_stack
*p
;
5527 tree constructor
= 0;
5531 /* When we come to an explicit close brace,
5532 pop any inner levels that didn't have explicit braces. */
5533 while (constructor_stack
->implicit
)
5534 process_init_element (pop_init_level (1));
5537 p
= constructor_stack
;
5539 if (constructor_type
!= 0)
5540 size
= int_size_in_bytes (constructor_type
);
5542 /* Warn when some struct elements are implicitly initialized to zero. */
5545 && TREE_CODE (constructor_type
) == RECORD_TYPE
5546 && constructor_unfilled_fields
)
5548 push_member_name (constructor_unfilled_fields
);
5549 warning_init ("missing initializer");
5550 RESTORE_SPELLING_DEPTH (constructor_depth
);
5553 /* Now output all pending elements. */
5554 output_pending_init_elements (1);
5556 #if 0 /* c-parse.in warns about {}. */
5557 /* In ANSI, each brace level must have at least one element. */
5558 if (! implicit
&& pedantic
5559 && (TREE_CODE (constructor_type
) == ARRAY_TYPE
5560 ? integer_zerop (constructor_unfilled_index
)
5561 : constructor_unfilled_fields
== TYPE_FIELDS (constructor_type
)))
5562 pedwarn_init ("empty braces in initializer");
5565 /* Pad out the end of the structure. */
5567 if (p
->replacement_value
)
5569 /* If this closes a superfluous brace pair,
5570 just pass out the element between them. */
5571 constructor
= p
->replacement_value
;
5572 /* If this is the top level thing within the initializer,
5573 and it's for a variable, then since we already called
5574 assemble_variable, we must output the value now. */
5575 if (p
->next
== 0 && constructor_decl
!= 0
5576 && constructor_incremental
)
5578 constructor
= digest_init (constructor_type
, constructor
,
5579 require_constant_value
,
5580 require_constant_elements
);
5582 /* If initializing an array of unknown size,
5583 determine the size now. */
5584 if (TREE_CODE (constructor_type
) == ARRAY_TYPE
5585 && TYPE_DOMAIN (constructor_type
) == 0)
5590 push_obstacks_nochange ();
5591 if (TREE_PERMANENT (constructor_type
))
5592 end_temporary_allocation ();
5594 momentary_p
= suspend_momentary ();
5596 /* We shouldn't have an incomplete array type within
5598 if (constructor_stack
->next
)
5602 = complete_array_type (constructor_type
,
5607 size
= int_size_in_bytes (constructor_type
);
5608 resume_momentary (momentary_p
);
5612 output_constant (constructor
, size
);
5615 else if (constructor_type
== 0)
5617 else if (TREE_CODE (constructor_type
) != RECORD_TYPE
5618 && TREE_CODE (constructor_type
) != UNION_TYPE
5619 && TREE_CODE (constructor_type
) != ARRAY_TYPE
5620 && ! constructor_incremental
)
5622 /* A nonincremental scalar initializer--just return
5623 the element, after verifying there is just one. */
5624 if (constructor_elements
== 0)
5626 error_init ("empty scalar initializer");
5627 constructor
= error_mark_node
;
5629 else if (TREE_CHAIN (constructor_elements
) != 0)
5631 error_init ("extra elements in scalar initializer");
5632 constructor
= TREE_VALUE (constructor_elements
);
5635 constructor
= TREE_VALUE (constructor_elements
);
5637 else if (! constructor_incremental
)
5639 if (constructor_erroneous
)
5640 constructor
= error_mark_node
;
5643 int momentary
= suspend_momentary ();
5645 constructor
= build (CONSTRUCTOR
, constructor_type
, NULL_TREE
,
5646 nreverse (constructor_elements
));
5647 if (constructor_constant
)
5648 TREE_CONSTANT (constructor
) = 1;
5649 if (constructor_constant
&& constructor_simple
)
5650 TREE_STATIC (constructor
) = 1;
5652 resume_momentary (momentary
);
5658 int momentary
= suspend_momentary ();
5660 if (TREE_CODE (constructor_type
) == RECORD_TYPE
5661 || TREE_CODE (constructor_type
) == UNION_TYPE
)
5663 /* Find the offset of the end of that field. */
5664 filled
= size_binop (CEIL_DIV_EXPR
,
5665 constructor_bit_index
,
5666 size_int (BITS_PER_UNIT
));
5668 else if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
5670 /* If initializing an array of unknown size,
5671 determine the size now. */
5672 if (TREE_CODE (constructor_type
) == ARRAY_TYPE
5673 && TYPE_DOMAIN (constructor_type
) == 0)
5676 = size_binop (MINUS_EXPR
,
5677 constructor_unfilled_index
,
5680 push_obstacks_nochange ();
5681 if (TREE_PERMANENT (constructor_type
))
5682 end_temporary_allocation ();
5683 maxindex
= copy_node (maxindex
);
5684 TYPE_DOMAIN (constructor_type
) = build_index_type (maxindex
);
5685 TREE_TYPE (maxindex
) = TYPE_DOMAIN (constructor_type
);
5687 /* TYPE_MAX_VALUE is always one less than the number of elements
5688 in the array, because we start counting at zero. Therefore,
5689 warn only if the value is less than zero. */
5691 && (tree_int_cst_sgn (TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type
)))
5693 error_with_decl (constructor_decl
,
5694 "zero or negative array size `%s'");
5695 layout_type (constructor_type
);
5696 size
= int_size_in_bytes (constructor_type
);
5700 filled
= size_binop (MULT_EXPR
, constructor_unfilled_index
,
5701 size_in_bytes (TREE_TYPE (constructor_type
)));
5707 assemble_zeros (size
- TREE_INT_CST_LOW (filled
));
5709 resume_momentary (momentary
);
5713 constructor_type
= p
->type
;
5714 constructor_fields
= p
->fields
;
5715 constructor_index
= p
->index
;
5716 constructor_range_end
= p
->range_end
;
5717 constructor_max_index
= p
->max_index
;
5718 constructor_unfilled_index
= p
->unfilled_index
;
5719 constructor_unfilled_fields
= p
->unfilled_fields
;
5720 constructor_bit_index
= p
->bit_index
;
5721 constructor_elements
= p
->elements
;
5722 constructor_constant
= p
->constant
;
5723 constructor_simple
= p
->simple
;
5724 constructor_erroneous
= p
->erroneous
;
5725 constructor_pending_elts
= p
->pending_elts
;
5726 constructor_depth
= p
->depth
;
5727 constructor_incremental
= p
->incremental
;
5728 RESTORE_SPELLING_DEPTH (constructor_depth
);
5730 constructor_stack
= p
->next
;
5733 if (constructor
== 0)
5735 if (constructor_stack
== 0)
5736 return error_mark_node
;
5742 /* Within an array initializer, specify the next index to be initialized.
5743 FIRST is that index. If LAST is nonzero, then initialize a range
5744 of indices, running from FIRST through LAST. */
5747 set_init_index (first
, last
)
5750 while ((TREE_CODE (first
) == NOP_EXPR
5751 || TREE_CODE (first
) == CONVERT_EXPR
5752 || TREE_CODE (first
) == NON_LVALUE_EXPR
)
5753 && (TYPE_MODE (TREE_TYPE (first
))
5754 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (first
, 0)))))
5755 (first
) = TREE_OPERAND (first
, 0);
5757 while ((TREE_CODE (last
) == NOP_EXPR
5758 || TREE_CODE (last
) == CONVERT_EXPR
5759 || TREE_CODE (last
) == NON_LVALUE_EXPR
)
5760 && (TYPE_MODE (TREE_TYPE (last
))
5761 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (last
, 0)))))
5762 (last
) = TREE_OPERAND (last
, 0);
5764 if (TREE_CODE (first
) != INTEGER_CST
)
5765 error_init ("nonconstant array index in initializer");
5766 else if (last
!= 0 && TREE_CODE (last
) != INTEGER_CST
)
5767 error_init ("nonconstant array index in initializer");
5768 else if (! constructor_unfilled_index
)
5769 error_init ("array index in non-array initializer");
5770 else if (tree_int_cst_lt (first
, constructor_unfilled_index
))
5771 error_init ("duplicate array index in initializer");
5774 TREE_INT_CST_LOW (constructor_index
) = TREE_INT_CST_LOW (first
);
5775 TREE_INT_CST_HIGH (constructor_index
) = TREE_INT_CST_HIGH (first
);
5777 if (last
!= 0 && tree_int_cst_lt (last
, first
))
5778 error_init ("empty index range in initializer");
5782 pedwarn ("ANSI C forbids specifying element to initialize");
5783 constructor_range_end
= last
;
5788 /* Within a struct initializer, specify the next field to be initialized. */
5791 set_init_label (fieldname
)
5797 /* Don't die if an entire brace-pair level is superfluous
5798 in the containing level. */
5799 if (constructor_type
== 0)
5802 for (tail
= TYPE_FIELDS (constructor_type
); tail
;
5803 tail
= TREE_CHAIN (tail
))
5805 if (tail
== constructor_unfilled_fields
)
5807 if (DECL_NAME (tail
) == fieldname
)
5812 error ("unknown field `%s' specified in initializer",
5813 IDENTIFIER_POINTER (fieldname
));
5815 error ("field `%s' already initialized",
5816 IDENTIFIER_POINTER (fieldname
));
5819 constructor_fields
= tail
;
5821 pedwarn ("ANSI C forbids specifying structure member to initialize");
5825 /* Add a new initializer to the tree of pending initializers. PURPOSE
5826 indentifies the initializer, either array index or field in a structure.
5827 VALUE is the value of that index or field. */
5830 add_pending_init (purpose
, value
)
5831 tree purpose
, value
;
5833 struct init_node
*p
, **q
, *r
;
5835 q
= &constructor_pending_elts
;
5838 if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
5843 if (tree_int_cst_lt (purpose
, p
->purpose
))
5845 else if (tree_int_cst_lt (p
->purpose
, purpose
))
5856 if (tree_int_cst_lt (DECL_FIELD_BITPOS (purpose
),
5857 DECL_FIELD_BITPOS (p
->purpose
)))
5859 else if (tree_int_cst_lt (DECL_FIELD_BITPOS (p
->purpose
),
5860 DECL_FIELD_BITPOS (purpose
)))
5867 r
= (struct init_node
*) oballoc (sizeof (struct init_node
));
5868 r
->purpose
= purpose
;
5879 struct init_node
*s
;
5883 if (p
->balance
== 0)
5885 else if (p
->balance
< 0)
5892 p
->left
->parent
= p
;
5909 constructor_pending_elts
= r
;
5914 struct init_node
*t
= r
->right
;
5918 r
->right
->parent
= r
;
5923 p
->left
->parent
= p
;
5926 p
->balance
= t
->balance
< 0;
5927 r
->balance
= -(t
->balance
> 0);
5942 constructor_pending_elts
= t
;
5948 /* p->balance == +1; growth of left side balances the node. */
5953 else /* r == p->right */
5955 if (p
->balance
== 0)
5956 /* Growth propagation from right side. */
5958 else if (p
->balance
> 0)
5965 p
->right
->parent
= p
;
5982 constructor_pending_elts
= r
;
5984 else /* r->balance == -1 */
5987 struct init_node
*t
= r
->left
;
5991 r
->left
->parent
= r
;
5996 p
->right
->parent
= p
;
5999 r
->balance
= (t
->balance
< 0);
6000 p
->balance
= -(t
->balance
> 0);
6015 constructor_pending_elts
= t
;
6021 /* p->balance == -1; growth of right side balances the node. */
6032 /* Return nonzero if FIELD is equal to the index of a pending initializer. */
6035 pending_init_member (field
)
6038 struct init_node
*p
;
6040 p
= constructor_pending_elts
;
6041 if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
6045 if (tree_int_cst_equal (field
, p
->purpose
))
6047 else if (tree_int_cst_lt (field
, p
->purpose
))
6057 if (field
== p
->purpose
)
6059 else if (tree_int_cst_lt (DECL_FIELD_BITPOS (field
),
6060 DECL_FIELD_BITPOS (p
->purpose
)))
6070 /* "Output" the next constructor element.
6071 At top level, really output it to assembler code now.
6072 Otherwise, collect it in a list from which we will make a CONSTRUCTOR.
6073 TYPE is the data type that the containing data type wants here.
6074 FIELD is the field (a FIELD_DECL) or the index that this element fills.
6076 PENDING if non-nil means output pending elements that belong
6077 right after this element. (PENDING is normally 1;
6078 it is 0 while outputting pending elements, to avoid recursion.) */
6081 output_init_element (value
, type
, field
, pending
)
6082 tree value
, type
, field
;
6087 if (TREE_CODE (TREE_TYPE (value
)) == FUNCTION_TYPE
6088 || (TREE_CODE (TREE_TYPE (value
)) == ARRAY_TYPE
6089 && !(TREE_CODE (value
) == STRING_CST
6090 && TREE_CODE (type
) == ARRAY_TYPE
6091 && TREE_CODE (TREE_TYPE (type
)) == INTEGER_TYPE
)
6092 && !comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (value
)),
6093 TYPE_MAIN_VARIANT (type
))))
6094 value
= default_conversion (value
);
6096 if (value
== error_mark_node
)
6097 constructor_erroneous
= 1;
6098 else if (!TREE_CONSTANT (value
))
6099 constructor_constant
= 0;
6100 else if (initializer_constant_valid_p (value
, TREE_TYPE (value
)) == 0
6101 || ((TREE_CODE (constructor_type
) == RECORD_TYPE
6102 || TREE_CODE (constructor_type
) == UNION_TYPE
)
6103 && DECL_C_BIT_FIELD (field
)
6104 && TREE_CODE (value
) != INTEGER_CST
))
6105 constructor_simple
= 0;
6107 if (require_constant_value
&& ! TREE_CONSTANT (value
))
6109 error_init ("initializer element is not constant");
6110 value
= error_mark_node
;
6112 else if (require_constant_elements
6113 && initializer_constant_valid_p (value
, TREE_TYPE (value
)) == 0)
6115 error_init ("initializer element is not computable at load time");
6116 value
= error_mark_node
;
6119 /* If this element duplicates one on constructor_pending_elts,
6120 print a message and ignore it. Don't do this when we're
6121 processing elements taken off constructor_pending_elts,
6122 because we'd always get spurious errors. */
6125 if (TREE_CODE (constructor_type
) == RECORD_TYPE
6126 || TREE_CODE (constructor_type
) == UNION_TYPE
6127 || TREE_CODE (constructor_type
) == ARRAY_TYPE
)
6129 if (pending_init_member (field
))
6131 error_init ("duplicate initializer");
6137 /* If this element doesn't come next in sequence,
6138 put it on constructor_pending_elts. */
6139 if (TREE_CODE (constructor_type
) == ARRAY_TYPE
6140 && !tree_int_cst_equal (field
, constructor_unfilled_index
))
6143 /* The copy_node is needed in case field is actually
6144 constructor_index, which is modified in place. */
6145 add_pending_init (copy_node (field
),
6146 digest_init (type
, value
, require_constant_value
,
6147 require_constant_elements
));
6149 else if (TREE_CODE (constructor_type
) == RECORD_TYPE
6150 && field
!= constructor_unfilled_fields
)
6152 /* We do this for records but not for unions. In a union,
6153 no matter which field is specified, it can be initialized
6154 right away since it starts at the beginning of the union. */
6156 add_pending_init (field
,
6157 digest_init (type
, value
, require_constant_value
,
6158 require_constant_elements
));
6162 /* Otherwise, output this element either to
6163 constructor_elements or to the assembler file. */
6167 if (! constructor_incremental
)
6169 if (field
&& TREE_CODE (field
) == INTEGER_CST
)
6170 field
= copy_node (field
);
6171 constructor_elements
6172 = tree_cons (field
, digest_init (type
, value
,
6173 require_constant_value
,
6174 require_constant_elements
),
6175 constructor_elements
);
6179 /* Structure elements may require alignment.
6180 Do this, if necessary. */
6181 if (TREE_CODE (constructor_type
) == RECORD_TYPE
)
6183 /* Advance to offset of this element. */
6184 if (! tree_int_cst_equal (constructor_bit_index
,
6185 DECL_FIELD_BITPOS (field
)))
6187 /* By using unsigned arithmetic, the result will be
6188 correct even in case of overflows, if BITS_PER_UNIT
6189 is a power of two. */
6190 unsigned next
= (TREE_INT_CST_LOW
6191 (DECL_FIELD_BITPOS (field
))
6192 / (unsigned)BITS_PER_UNIT
);
6193 unsigned here
= (TREE_INT_CST_LOW
6194 (constructor_bit_index
)
6195 / (unsigned)BITS_PER_UNIT
);
6197 assemble_zeros ((next
- here
)
6198 * (unsigned)BITS_PER_UNIT
6199 / (unsigned)BITS_PER_UNIT
);
6202 output_constant (digest_init (type
, value
,
6203 require_constant_value
,
6204 require_constant_elements
),
6205 int_size_in_bytes (type
));
6207 /* For a record or union,
6208 keep track of end position of last field. */
6209 if (TREE_CODE (constructor_type
) == RECORD_TYPE
6210 || TREE_CODE (constructor_type
) == UNION_TYPE
)
6212 tree temp
= size_binop (PLUS_EXPR
, DECL_FIELD_BITPOS (field
),
6214 TREE_INT_CST_LOW (constructor_bit_index
)
6215 = TREE_INT_CST_LOW (temp
);
6216 TREE_INT_CST_HIGH (constructor_bit_index
)
6217 = TREE_INT_CST_HIGH (temp
);
6222 /* Advance the variable that indicates sequential elements output. */
6223 if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
6225 tree tem
= size_binop (PLUS_EXPR
, constructor_unfilled_index
,
6227 TREE_INT_CST_LOW (constructor_unfilled_index
)
6228 = TREE_INT_CST_LOW (tem
);
6229 TREE_INT_CST_HIGH (constructor_unfilled_index
)
6230 = TREE_INT_CST_HIGH (tem
);
6232 else if (TREE_CODE (constructor_type
) == RECORD_TYPE
)
6233 constructor_unfilled_fields
= TREE_CHAIN (constructor_unfilled_fields
);
6234 else if (TREE_CODE (constructor_type
) == UNION_TYPE
)
6235 constructor_unfilled_fields
= 0;
6237 /* Now output any pending elements which have become next. */
6239 output_pending_init_elements (0);
6243 /* Output any pending elements which have become next.
6244 As we output elements, constructor_unfilled_{fields,index}
6245 advances, which may cause other elements to become next;
6246 if so, they too are output.
6248 If ALL is 0, we return when there are
6249 no more pending elements to output now.
6251 If ALL is 1, we output space as necessary so that
6252 we can output all the pending elements. */
6255 output_pending_init_elements (all
)
6258 struct init_node
*elt
= constructor_pending_elts
;
6263 /* Look thru the whole pending tree.
6264 If we find an element that should be output now,
6265 output it. Otherwise, set NEXT to the element
6266 that comes first among those still pending. */
6271 if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
6273 if (tree_int_cst_equal (elt
->purpose
,
6274 constructor_unfilled_index
))
6275 output_init_element (elt
->value
,
6276 TREE_TYPE (constructor_type
),
6277 constructor_unfilled_index
, 0);
6278 else if (tree_int_cst_lt (constructor_unfilled_index
,
6281 /* Advance to the next smaller node. */
6286 /* We have reached the smallest node bigger than the
6287 current unfilled index. Fill the space first. */
6288 next
= elt
->purpose
;
6294 /* Advance to the next bigger node. */
6299 /* We have reached the biggest node in a subtree. Find
6300 the parent of it, which is the next bigger node. */
6301 while (elt
->parent
&& elt
->parent
->right
== elt
)
6304 if (elt
&& tree_int_cst_lt (constructor_unfilled_index
,
6307 next
= elt
->purpose
;
6313 else if (TREE_CODE (constructor_type
) == RECORD_TYPE
6314 || TREE_CODE (constructor_type
) == UNION_TYPE
)
6316 /* If the current record is complete we are done. */
6317 if (constructor_unfilled_fields
== 0)
6319 if (elt
->purpose
== constructor_unfilled_fields
)
6321 output_init_element (elt
->value
,
6322 TREE_TYPE (constructor_unfilled_fields
),
6323 constructor_unfilled_fields
,
6326 else if (tree_int_cst_lt (DECL_FIELD_BITPOS (constructor_unfilled_fields
),
6327 DECL_FIELD_BITPOS (elt
->purpose
)))
6329 /* Advance to the next smaller node. */
6334 /* We have reached the smallest node bigger than the
6335 current unfilled field. Fill the space first. */
6336 next
= elt
->purpose
;
6342 /* Advance to the next bigger node. */
6347 /* We have reached the biggest node in a subtree. Find
6348 the parent of it, which is the next bigger node. */
6349 while (elt
->parent
&& elt
->parent
->right
== elt
)
6353 && tree_int_cst_lt (DECL_FIELD_BITPOS (constructor_unfilled_fields
),
6354 DECL_FIELD_BITPOS (elt
->purpose
)))
6356 next
= elt
->purpose
;
6364 /* Ordinarily return, but not if we want to output all
6365 and there are elements left. */
6366 if (! (all
&& next
!= 0))
6369 /* Generate space up to the position of NEXT. */
6370 if (constructor_incremental
)
6373 tree nextpos_tree
= size_int (0);
6375 if (TREE_CODE (constructor_type
) == RECORD_TYPE
6376 || TREE_CODE (constructor_type
) == UNION_TYPE
)
6379 /* Find the last field written out, if any. */
6380 for (tail
= TYPE_FIELDS (constructor_type
); tail
;
6381 tail
= TREE_CHAIN (tail
))
6382 if (TREE_CHAIN (tail
) == constructor_unfilled_fields
)
6386 /* Find the offset of the end of that field. */
6387 filled
= size_binop (CEIL_DIV_EXPR
,
6388 size_binop (PLUS_EXPR
,
6389 DECL_FIELD_BITPOS (tail
),
6391 size_int (BITS_PER_UNIT
));
6393 filled
= size_int (0);
6395 nextpos_tree
= size_binop (CEIL_DIV_EXPR
,
6396 DECL_FIELD_BITPOS (next
),
6397 size_int (BITS_PER_UNIT
));
6399 TREE_INT_CST_HIGH (constructor_bit_index
)
6400 = TREE_INT_CST_HIGH (DECL_FIELD_BITPOS (next
));
6401 TREE_INT_CST_LOW (constructor_bit_index
)
6402 = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (next
));
6403 constructor_unfilled_fields
= next
;
6405 else if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
6407 filled
= size_binop (MULT_EXPR
, constructor_unfilled_index
,
6408 size_in_bytes (TREE_TYPE (constructor_type
)));
6410 = size_binop (MULT_EXPR
, next
,
6411 size_in_bytes (TREE_TYPE (constructor_type
)));
6412 TREE_INT_CST_LOW (constructor_unfilled_index
)
6413 = TREE_INT_CST_LOW (next
);
6414 TREE_INT_CST_HIGH (constructor_unfilled_index
)
6415 = TREE_INT_CST_HIGH (next
);
6422 int nextpos
= TREE_INT_CST_LOW (nextpos_tree
);
6424 assemble_zeros (nextpos
- TREE_INT_CST_LOW (filled
));
6429 /* If it's not incremental, just skip over the gap,
6430 so that after jumping to retry we will output the next
6431 successive element. */
6432 if (TREE_CODE (constructor_type
) == RECORD_TYPE
6433 || TREE_CODE (constructor_type
) == UNION_TYPE
)
6434 constructor_unfilled_fields
= next
;
6435 else if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
6437 TREE_INT_CST_LOW (constructor_unfilled_index
)
6438 = TREE_INT_CST_LOW (next
);
6439 TREE_INT_CST_HIGH (constructor_unfilled_index
)
6440 = TREE_INT_CST_HIGH (next
);
6444 /* ELT now points to the node in the pending tree with the next
6445 initializer to output. */
6449 /* Add one non-braced element to the current constructor level.
6450 This adjusts the current position within the constructor's type.
6451 This may also start or terminate implicit levels
6452 to handle a partly-braced initializer.
6454 Once this has found the correct level for the new element,
6455 it calls output_init_element.
6457 Note: if we are incrementally outputting this constructor,
6458 this function may be called with a null argument
6459 representing a sub-constructor that was already incrementally output.
6460 When that happens, we output nothing, but we do the bookkeeping
6461 to skip past that element of the current constructor. */
6464 process_init_element (value
)
6467 tree orig_value
= value
;
6468 int string_flag
= value
!= 0 && TREE_CODE (value
) == STRING_CST
;
6470 /* Handle superfluous braces around string cst as in
6471 char x[] = {"foo"}; */
6474 && TREE_CODE (constructor_type
) == ARRAY_TYPE
6475 && TREE_CODE (TREE_TYPE (constructor_type
)) == INTEGER_TYPE
6476 && integer_zerop (constructor_unfilled_index
))
6478 constructor_stack
->replacement_value
= value
;
6482 if (constructor_stack
->replacement_value
!= 0)
6484 error_init ("excess elements in struct initializer");
6488 /* Ignore elements of a brace group if it is entirely superfluous
6489 and has already been diagnosed. */
6490 if (constructor_type
== 0)
6493 /* If we've exhausted any levels that didn't have braces,
6495 while (constructor_stack
->implicit
)
6497 if ((TREE_CODE (constructor_type
) == RECORD_TYPE
6498 || TREE_CODE (constructor_type
) == UNION_TYPE
)
6499 && constructor_fields
== 0)
6500 process_init_element (pop_init_level (1));
6501 else if (TREE_CODE (constructor_type
) == ARRAY_TYPE
6502 && (constructor_max_index
== 0
6503 || tree_int_cst_lt (constructor_max_index
,
6504 constructor_index
)))
6505 process_init_element (pop_init_level (1));
6512 if (TREE_CODE (constructor_type
) == RECORD_TYPE
)
6515 enum tree_code fieldcode
;
6517 if (constructor_fields
== 0)
6519 pedwarn_init ("excess elements in struct initializer");
6523 fieldtype
= TREE_TYPE (constructor_fields
);
6524 if (fieldtype
!= error_mark_node
)
6525 fieldtype
= TYPE_MAIN_VARIANT (fieldtype
);
6526 fieldcode
= TREE_CODE (fieldtype
);
6528 /* Accept a string constant to initialize a subarray. */
6530 && fieldcode
== ARRAY_TYPE
6531 && TREE_CODE (TREE_TYPE (fieldtype
)) == INTEGER_TYPE
6534 /* Otherwise, if we have come to a subaggregate,
6535 and we don't have an element of its type, push into it. */
6536 else if (value
!= 0 && !constructor_no_implicit
6537 && value
!= error_mark_node
6538 && TYPE_MAIN_VARIANT (TREE_TYPE (value
)) != fieldtype
6539 && (fieldcode
== RECORD_TYPE
|| fieldcode
== ARRAY_TYPE
6540 || fieldcode
== UNION_TYPE
))
6542 push_init_level (1);
6548 push_member_name (constructor_fields
);
6549 output_init_element (value
, fieldtype
, constructor_fields
, 1);
6550 RESTORE_SPELLING_DEPTH (constructor_depth
);
6553 /* Do the bookkeeping for an element that was
6554 directly output as a constructor. */
6556 /* For a record, keep track of end position of last field. */
6557 tree temp
= size_binop (PLUS_EXPR
,
6558 DECL_FIELD_BITPOS (constructor_fields
),
6559 DECL_SIZE (constructor_fields
));
6560 TREE_INT_CST_LOW (constructor_bit_index
)
6561 = TREE_INT_CST_LOW (temp
);
6562 TREE_INT_CST_HIGH (constructor_bit_index
)
6563 = TREE_INT_CST_HIGH (temp
);
6565 constructor_unfilled_fields
= TREE_CHAIN (constructor_fields
);
6568 constructor_fields
= TREE_CHAIN (constructor_fields
);
6569 /* Skip any nameless bit fields at the beginning. */
6570 while (constructor_fields
!= 0
6571 && DECL_C_BIT_FIELD (constructor_fields
)
6572 && DECL_NAME (constructor_fields
) == 0)
6573 constructor_fields
= TREE_CHAIN (constructor_fields
);
6576 if (TREE_CODE (constructor_type
) == UNION_TYPE
)
6579 enum tree_code fieldcode
;
6581 if (constructor_fields
== 0)
6583 pedwarn_init ("excess elements in union initializer");
6587 fieldtype
= TREE_TYPE (constructor_fields
);
6588 if (fieldtype
!= error_mark_node
)
6589 fieldtype
= TYPE_MAIN_VARIANT (fieldtype
);
6590 fieldcode
= TREE_CODE (fieldtype
);
6592 /* Accept a string constant to initialize a subarray. */
6594 && fieldcode
== ARRAY_TYPE
6595 && TREE_CODE (TREE_TYPE (fieldtype
)) == INTEGER_TYPE
6598 /* Otherwise, if we have come to a subaggregate,
6599 and we don't have an element of its type, push into it. */
6600 else if (value
!= 0 && !constructor_no_implicit
6601 && value
!= error_mark_node
6602 && TYPE_MAIN_VARIANT (TREE_TYPE (value
)) != fieldtype
6603 && (fieldcode
== RECORD_TYPE
|| fieldcode
== ARRAY_TYPE
6604 || fieldcode
== UNION_TYPE
))
6606 push_init_level (1);
6612 push_member_name (constructor_fields
);
6613 output_init_element (value
, fieldtype
, constructor_fields
, 1);
6614 RESTORE_SPELLING_DEPTH (constructor_depth
);
6617 /* Do the bookkeeping for an element that was
6618 directly output as a constructor. */
6620 TREE_INT_CST_LOW (constructor_bit_index
)
6621 = TREE_INT_CST_LOW (DECL_SIZE (constructor_fields
));
6622 TREE_INT_CST_HIGH (constructor_bit_index
)
6623 = TREE_INT_CST_HIGH (DECL_SIZE (constructor_fields
));
6625 constructor_unfilled_fields
= TREE_CHAIN (constructor_fields
);
6628 constructor_fields
= 0;
6631 if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
6633 tree elttype
= TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type
));
6634 enum tree_code eltcode
= TREE_CODE (elttype
);
6636 /* Accept a string constant to initialize a subarray. */
6638 && eltcode
== ARRAY_TYPE
6639 && TREE_CODE (TREE_TYPE (elttype
)) == INTEGER_TYPE
6642 /* Otherwise, if we have come to a subaggregate,
6643 and we don't have an element of its type, push into it. */
6644 else if (value
!= 0 && !constructor_no_implicit
6645 && value
!= error_mark_node
6646 && TYPE_MAIN_VARIANT (TREE_TYPE (value
)) != elttype
6647 && (eltcode
== RECORD_TYPE
|| eltcode
== ARRAY_TYPE
6648 || eltcode
== UNION_TYPE
))
6650 push_init_level (1);
6654 if (constructor_max_index
!= 0
6655 && tree_int_cst_lt (constructor_max_index
, constructor_index
))
6657 pedwarn_init ("excess elements in array initializer");
6661 /* In the case of [LO .. HI] = VALUE, only evaluate VALUE once. */
6662 if (constructor_range_end
)
6664 if (constructor_max_index
!= 0
6665 && tree_int_cst_lt (constructor_max_index
,
6666 constructor_range_end
))
6668 pedwarn_init ("excess elements in array initializer");
6669 TREE_INT_CST_HIGH (constructor_range_end
)
6670 = TREE_INT_CST_HIGH (constructor_max_index
);
6671 TREE_INT_CST_LOW (constructor_range_end
)
6672 = TREE_INT_CST_LOW (constructor_max_index
);
6675 value
= save_expr (value
);
6678 /* Now output the actual element.
6679 Ordinarily, output once.
6680 If there is a range, repeat it till we advance past the range. */
6687 push_array_bounds (TREE_INT_CST_LOW (constructor_index
));
6688 output_init_element (value
, elttype
, constructor_index
, 1);
6689 RESTORE_SPELLING_DEPTH (constructor_depth
);
6692 tem
= size_binop (PLUS_EXPR
, constructor_index
,
6694 TREE_INT_CST_LOW (constructor_index
) = TREE_INT_CST_LOW (tem
);
6695 TREE_INT_CST_HIGH (constructor_index
) = TREE_INT_CST_HIGH (tem
);
6698 /* If we are doing the bookkeeping for an element that was
6699 directly output as a constructor,
6700 we must update constructor_unfilled_index. */
6702 TREE_INT_CST_LOW (constructor_unfilled_index
)
6703 = TREE_INT_CST_LOW (constructor_index
);
6704 TREE_INT_CST_HIGH (constructor_unfilled_index
)
6705 = TREE_INT_CST_HIGH (constructor_index
);
6708 while (! (constructor_range_end
== 0
6709 || tree_int_cst_lt (constructor_range_end
,
6710 constructor_index
)));
6715 /* Handle the sole element allowed in a braced initializer
6716 for a scalar variable. */
6717 if (constructor_fields
== 0)
6719 pedwarn_init ("excess elements in scalar initializer");
6724 output_init_element (value
, constructor_type
, NULL_TREE
, 1);
6725 constructor_fields
= 0;
6729 /* If the (lexically) previous elments are not now saved,
6730 we can discard the storage for them. */
6731 if (constructor_incremental
&& constructor_pending_elts
== 0 && value
!= 0
6732 && constructor_stack
== 0)
6736 /* Expand an ASM statement with operands, handling output operands
6737 that are not variables or INDIRECT_REFS by transforming such
6738 cases into cases that expand_asm_operands can handle.
6740 Arguments are same as for expand_asm_operands. */
6743 c_expand_asm_operands (string
, outputs
, inputs
, clobbers
, vol
, filename
, line
)
6744 tree string
, outputs
, inputs
, clobbers
;
6749 int noutputs
= list_length (outputs
);
6751 /* o[I] is the place that output number I should be written. */
6752 register tree
*o
= (tree
*) alloca (noutputs
* sizeof (tree
));
6755 if (TREE_CODE (string
) == ADDR_EXPR
)
6756 string
= TREE_OPERAND (string
, 0);
6757 if (TREE_CODE (string
) != STRING_CST
)
6759 error ("asm template is not a string constant");
6763 /* Record the contents of OUTPUTS before it is modified. */
6764 for (i
= 0, tail
= outputs
; tail
; tail
= TREE_CHAIN (tail
), i
++)
6765 o
[i
] = TREE_VALUE (tail
);
6767 /* Perform default conversions on array and function inputs. */
6768 /* Don't do this for other types--
6769 it would screw up operands expected to be in memory. */
6770 for (i
= 0, tail
= inputs
; tail
; tail
= TREE_CHAIN (tail
), i
++)
6771 if (TREE_CODE (TREE_TYPE (TREE_VALUE (tail
))) == ARRAY_TYPE
6772 || TREE_CODE (TREE_TYPE (TREE_VALUE (tail
))) == FUNCTION_TYPE
)
6773 TREE_VALUE (tail
) = default_conversion (TREE_VALUE (tail
));
6775 /* Generate the ASM_OPERANDS insn;
6776 store into the TREE_VALUEs of OUTPUTS some trees for
6777 where the values were actually stored. */
6778 expand_asm_operands (string
, outputs
, inputs
, clobbers
, vol
, filename
, line
);
6780 /* Copy all the intermediate outputs into the specified outputs. */
6781 for (i
= 0, tail
= outputs
; tail
; tail
= TREE_CHAIN (tail
), i
++)
6783 if (o
[i
] != TREE_VALUE (tail
))
6785 expand_expr (build_modify_expr (o
[i
], NOP_EXPR
, TREE_VALUE (tail
)),
6786 NULL_RTX
, VOIDmode
, EXPAND_NORMAL
);
6789 /* Detect modification of read-only values.
6790 (Otherwise done by build_modify_expr.) */
6793 tree type
= TREE_TYPE (o
[i
]);
6794 if (TREE_READONLY (o
[i
])
6795 || TYPE_READONLY (type
)
6796 || ((TREE_CODE (type
) == RECORD_TYPE
6797 || TREE_CODE (type
) == UNION_TYPE
)
6798 && C_TYPE_FIELDS_READONLY (type
)))
6799 readonly_warning (o
[i
], "modification by `asm'");
6803 /* Those MODIFY_EXPRs could do autoincrements. */
6807 /* Expand a C `return' statement.
6808 RETVAL is the expression for what to return,
6809 or a null pointer for `return;' with no value. */
6812 c_expand_return (retval
)
6815 tree valtype
= TREE_TYPE (TREE_TYPE (current_function_decl
));
6817 if (TREE_THIS_VOLATILE (current_function_decl
))
6818 warning ("function declared `noreturn' has a `return' statement");
6822 current_function_returns_null
= 1;
6823 if (warn_return_type
&& valtype
!= 0 && TREE_CODE (valtype
) != VOID_TYPE
)
6824 warning ("`return' with no value, in function returning non-void");
6825 expand_null_return ();
6827 else if (valtype
== 0 || TREE_CODE (valtype
) == VOID_TYPE
)
6829 current_function_returns_null
= 1;
6830 if (pedantic
|| TREE_CODE (TREE_TYPE (retval
)) != VOID_TYPE
)
6831 pedwarn ("`return' with a value, in function returning void");
6832 expand_return (retval
);
6836 tree t
= convert_for_assignment (valtype
, retval
, _("return"),
6837 NULL_TREE
, NULL_TREE
, 0);
6838 tree res
= DECL_RESULT (current_function_decl
);
6841 if (t
== error_mark_node
)
6844 inner
= t
= convert (TREE_TYPE (res
), t
);
6846 /* Strip any conversions, additions, and subtractions, and see if
6847 we are returning the address of a local variable. Warn if so. */
6850 switch (TREE_CODE (inner
))
6852 case NOP_EXPR
: case NON_LVALUE_EXPR
: case CONVERT_EXPR
:
6854 inner
= TREE_OPERAND (inner
, 0);
6858 /* If the second operand of the MINUS_EXPR has a pointer
6859 type (or is converted from it), this may be valid, so
6860 don't give a warning. */
6862 tree op1
= TREE_OPERAND (inner
, 1);
6864 while (! POINTER_TYPE_P (TREE_TYPE (op1
))
6865 && (TREE_CODE (op1
) == NOP_EXPR
6866 || TREE_CODE (op1
) == NON_LVALUE_EXPR
6867 || TREE_CODE (op1
) == CONVERT_EXPR
))
6868 op1
= TREE_OPERAND (op1
, 0);
6870 if (POINTER_TYPE_P (TREE_TYPE (op1
)))
6873 inner
= TREE_OPERAND (inner
, 0);
6878 inner
= TREE_OPERAND (inner
, 0);
6880 while (TREE_CODE_CLASS (TREE_CODE (inner
)) == 'r')
6881 inner
= TREE_OPERAND (inner
, 0);
6883 if (TREE_CODE (inner
) == VAR_DECL
6884 && ! DECL_EXTERNAL (inner
)
6885 && ! TREE_STATIC (inner
)
6886 && DECL_CONTEXT (inner
) == current_function_decl
)
6887 warning ("function returns address of local variable");
6897 t
= build (MODIFY_EXPR
, TREE_TYPE (res
), res
, t
);
6898 TREE_SIDE_EFFECTS (t
) = 1;
6900 current_function_returns_value
= 1;
6904 /* Start a C switch statement, testing expression EXP.
6905 Return EXP if it is valid, an error node otherwise. */
6908 c_expand_start_case (exp
)
6911 register enum tree_code code
= TREE_CODE (TREE_TYPE (exp
));
6912 tree type
= TREE_TYPE (exp
);
6914 if (code
!= INTEGER_TYPE
&& code
!= ENUMERAL_TYPE
&& code
!= ERROR_MARK
)
6916 error ("switch quantity not an integer");
6917 exp
= error_mark_node
;
6922 type
= TYPE_MAIN_VARIANT (TREE_TYPE (exp
));
6924 if (warn_traditional
6925 && (type
== long_integer_type_node
6926 || type
== long_unsigned_type_node
))
6927 pedwarn ("`long' switch expression not converted to `int' in ANSI C");
6929 exp
= default_conversion (exp
);
6930 type
= TREE_TYPE (exp
);
6931 index
= get_unwidened (exp
, NULL_TREE
);
6932 /* We can't strip a conversion from a signed type to an unsigned,
6933 because if we did, int_fits_type_p would do the wrong thing
6934 when checking case values for being in range,
6935 and it's too hard to do the right thing. */
6936 if (TREE_UNSIGNED (TREE_TYPE (exp
))
6937 == TREE_UNSIGNED (TREE_TYPE (index
)))
6941 expand_start_case (1, exp
, type
, "switch statement");