1 /* Build expressions with type checking for C compiler.
2 Copyright (C) 1987, 1988, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 /* This file is part of the C front end.
24 It contains routines to build C expressions given their operands,
25 including computing the types of the result, C-specific error checks,
26 and some optimization.
28 There are also routines to build RETURN_STMT nodes and CASE_STMT nodes,
29 and to process initializations in declarations (since they work
30 like a strange sort of assignment). */
34 #include "coretypes.h"
48 /* Nonzero if we've already printed a "missing braces around initializer"
49 message within this initializer. */
50 static int missing_braces_mentioned
;
52 static tree
qualify_type (tree
, tree
);
53 static int same_translation_unit_p (tree
, tree
);
54 static int tagged_types_tu_compatible_p (tree
, tree
, int);
55 static int comp_target_types (tree
, tree
, int);
56 static int function_types_compatible_p (tree
, tree
, int);
57 static int type_lists_compatible_p (tree
, tree
, int);
58 static tree
decl_constant_value_for_broken_optimization (tree
);
59 static tree
default_function_array_conversion (tree
);
60 static tree
lookup_field (tree
, tree
);
61 static tree
convert_arguments (tree
, tree
, tree
, tree
);
62 static tree
pointer_diff (tree
, tree
);
63 static tree
unary_complex_lvalue (enum tree_code
, tree
, int);
64 static void pedantic_lvalue_warning (enum tree_code
);
65 static tree
internal_build_compound_expr (tree
, int);
66 static tree
convert_for_assignment (tree
, tree
, const char *, tree
, tree
,
68 static void warn_for_assignment (const char *, const char *, tree
, int);
69 static tree
valid_compound_expr_initializer (tree
, tree
);
70 static void push_string (const char *);
71 static void push_member_name (tree
);
72 static void push_array_bounds (int);
73 static int spelling_length (void);
74 static char *print_spelling (char *);
75 static void warning_init (const char *);
76 static tree
digest_init (tree
, tree
, int);
77 static void output_init_element (tree
, tree
, tree
, int);
78 static void output_pending_init_elements (int);
79 static int set_designator (int);
80 static void push_range_stack (tree
);
81 static void add_pending_init (tree
, tree
);
82 static void set_nonincremental_init (void);
83 static void set_nonincremental_init_from_string (tree
);
84 static tree
find_init_member (tree
);
86 /* Do `exp = require_complete_type (exp);' to make sure exp
87 does not have an incomplete type. (That includes void types.) */
90 require_complete_type (tree value
)
92 tree type
= TREE_TYPE (value
);
94 if (value
== error_mark_node
|| type
== error_mark_node
)
95 return error_mark_node
;
97 /* First, detect a valid value with a complete type. */
98 if (COMPLETE_TYPE_P (type
))
101 c_incomplete_type_error (value
, type
);
102 return error_mark_node
;
105 /* Print an error message for invalid use of an incomplete type.
106 VALUE is the expression that was used (or 0 if that isn't known)
107 and TYPE is the type that was invalid. */
110 c_incomplete_type_error (tree value
, tree type
)
112 const char *type_code_string
;
114 /* Avoid duplicate error message. */
115 if (TREE_CODE (type
) == ERROR_MARK
)
118 if (value
!= 0 && (TREE_CODE (value
) == VAR_DECL
119 || TREE_CODE (value
) == PARM_DECL
))
120 error ("`%s' has an incomplete type",
121 IDENTIFIER_POINTER (DECL_NAME (value
)));
125 /* We must print an error message. Be clever about what it says. */
127 switch (TREE_CODE (type
))
130 type_code_string
= "struct";
134 type_code_string
= "union";
138 type_code_string
= "enum";
142 error ("invalid use of void expression");
146 if (TYPE_DOMAIN (type
))
148 if (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) == NULL
)
150 error ("invalid use of flexible array member");
153 type
= TREE_TYPE (type
);
156 error ("invalid use of array with unspecified bounds");
163 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
164 error ("invalid use of undefined type `%s %s'",
165 type_code_string
, IDENTIFIER_POINTER (TYPE_NAME (type
)));
167 /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL. */
168 error ("invalid use of incomplete typedef `%s'",
169 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
))));
173 /* Given a type, apply default promotions wrt unnamed function
174 arguments and return the new type. */
177 c_type_promotes_to (tree type
)
179 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
180 return double_type_node
;
182 if (c_promoting_integer_type_p (type
))
184 /* Preserve unsignedness if not really getting any wider. */
185 if (TREE_UNSIGNED (type
)
186 && (TYPE_PRECISION (type
) == TYPE_PRECISION (integer_type_node
)))
187 return unsigned_type_node
;
188 return integer_type_node
;
194 /* Return a variant of TYPE which has all the type qualifiers of LIKE
195 as well as those of TYPE. */
198 qualify_type (tree type
, tree like
)
200 return c_build_qualified_type (type
,
201 TYPE_QUALS (type
) | TYPE_QUALS (like
));
204 /* Return the common type of two types.
205 We assume that comptypes has already been done and returned 1;
206 if that isn't so, this may crash. In particular, we assume that qualifiers
209 This is the type for the result of most arithmetic operations
210 if the operands have the given two types. */
213 common_type (tree t1
, tree t2
)
215 enum tree_code code1
;
216 enum tree_code code2
;
219 /* Save time if the two types are the same. */
221 if (t1
== t2
) return t1
;
223 /* If one type is nonsense, use the other. */
224 if (t1
== error_mark_node
)
226 if (t2
== error_mark_node
)
229 /* Merge the attributes. */
230 attributes
= (*targetm
.merge_type_attributes
) (t1
, t2
);
232 /* Treat an enum type as the unsigned integer type of the same width. */
234 if (TREE_CODE (t1
) == ENUMERAL_TYPE
)
235 t1
= c_common_type_for_size (TYPE_PRECISION (t1
), 1);
236 if (TREE_CODE (t2
) == ENUMERAL_TYPE
)
237 t2
= c_common_type_for_size (TYPE_PRECISION (t2
), 1);
239 code1
= TREE_CODE (t1
);
240 code2
= TREE_CODE (t2
);
242 /* If one type is complex, form the common type of the non-complex
243 components, then make that complex. Use T1 or T2 if it is the
245 if (code1
== COMPLEX_TYPE
|| code2
== COMPLEX_TYPE
)
247 tree subtype1
= code1
== COMPLEX_TYPE
? TREE_TYPE (t1
) : t1
;
248 tree subtype2
= code2
== COMPLEX_TYPE
? TREE_TYPE (t2
) : t2
;
249 tree subtype
= common_type (subtype1
, subtype2
);
251 if (code1
== COMPLEX_TYPE
&& TREE_TYPE (t1
) == subtype
)
252 return build_type_attribute_variant (t1
, attributes
);
253 else if (code2
== COMPLEX_TYPE
&& TREE_TYPE (t2
) == subtype
)
254 return build_type_attribute_variant (t2
, attributes
);
256 return build_type_attribute_variant (build_complex_type (subtype
),
264 /* If only one is real, use it as the result. */
266 if (code1
== REAL_TYPE
&& code2
!= REAL_TYPE
)
267 return build_type_attribute_variant (t1
, attributes
);
269 if (code2
== REAL_TYPE
&& code1
!= REAL_TYPE
)
270 return build_type_attribute_variant (t2
, attributes
);
272 /* Both real or both integers; use the one with greater precision. */
274 if (TYPE_PRECISION (t1
) > TYPE_PRECISION (t2
))
275 return build_type_attribute_variant (t1
, attributes
);
276 else if (TYPE_PRECISION (t2
) > TYPE_PRECISION (t1
))
277 return build_type_attribute_variant (t2
, attributes
);
279 /* Same precision. Prefer longs to ints even when same size. */
281 if (TYPE_MAIN_VARIANT (t1
) == long_unsigned_type_node
282 || TYPE_MAIN_VARIANT (t2
) == long_unsigned_type_node
)
283 return build_type_attribute_variant (long_unsigned_type_node
,
286 if (TYPE_MAIN_VARIANT (t1
) == long_integer_type_node
287 || TYPE_MAIN_VARIANT (t2
) == long_integer_type_node
)
289 /* But preserve unsignedness from the other type,
290 since long cannot hold all the values of an unsigned int. */
291 if (TREE_UNSIGNED (t1
) || TREE_UNSIGNED (t2
))
292 t1
= long_unsigned_type_node
;
294 t1
= long_integer_type_node
;
295 return build_type_attribute_variant (t1
, attributes
);
298 /* Likewise, prefer long double to double even if same size. */
299 if (TYPE_MAIN_VARIANT (t1
) == long_double_type_node
300 || TYPE_MAIN_VARIANT (t2
) == long_double_type_node
)
301 return build_type_attribute_variant (long_double_type_node
,
304 /* Otherwise prefer the unsigned one. */
306 if (TREE_UNSIGNED (t1
))
307 return build_type_attribute_variant (t1
, attributes
);
309 return build_type_attribute_variant (t2
, attributes
);
312 /* For two pointers, do this recursively on the target type,
313 and combine the qualifiers of the two types' targets. */
314 /* This code was turned off; I don't know why.
315 But ANSI C specifies doing this with the qualifiers.
316 So I turned it on again. */
318 tree pointed_to_1
= TREE_TYPE (t1
);
319 tree pointed_to_2
= TREE_TYPE (t2
);
320 tree target
= common_type (TYPE_MAIN_VARIANT (pointed_to_1
),
321 TYPE_MAIN_VARIANT (pointed_to_2
));
322 t1
= build_pointer_type (c_build_qualified_type
324 TYPE_QUALS (pointed_to_1
) |
325 TYPE_QUALS (pointed_to_2
)));
326 return build_type_attribute_variant (t1
, attributes
);
331 tree elt
= common_type (TREE_TYPE (t1
), TREE_TYPE (t2
));
332 /* Save space: see if the result is identical to one of the args. */
333 if (elt
== TREE_TYPE (t1
) && TYPE_DOMAIN (t1
))
334 return build_type_attribute_variant (t1
, attributes
);
335 if (elt
== TREE_TYPE (t2
) && TYPE_DOMAIN (t2
))
336 return build_type_attribute_variant (t2
, attributes
);
337 /* Merge the element types, and have a size if either arg has one. */
338 t1
= build_array_type (elt
, TYPE_DOMAIN (TYPE_DOMAIN (t1
) ? t1
: t2
));
339 return build_type_attribute_variant (t1
, attributes
);
343 /* Function types: prefer the one that specified arg types.
344 If both do, merge the arg types. Also merge the return types. */
346 tree valtype
= common_type (TREE_TYPE (t1
), TREE_TYPE (t2
));
347 tree p1
= TYPE_ARG_TYPES (t1
);
348 tree p2
= TYPE_ARG_TYPES (t2
);
353 /* Save space: see if the result is identical to one of the args. */
354 if (valtype
== TREE_TYPE (t1
) && ! TYPE_ARG_TYPES (t2
))
355 return build_type_attribute_variant (t1
, attributes
);
356 if (valtype
== TREE_TYPE (t2
) && ! TYPE_ARG_TYPES (t1
))
357 return build_type_attribute_variant (t2
, attributes
);
359 /* Simple way if one arg fails to specify argument types. */
360 if (TYPE_ARG_TYPES (t1
) == 0)
362 t1
= build_function_type (valtype
, TYPE_ARG_TYPES (t2
));
363 return build_type_attribute_variant (t1
, attributes
);
365 if (TYPE_ARG_TYPES (t2
) == 0)
367 t1
= build_function_type (valtype
, TYPE_ARG_TYPES (t1
));
368 return build_type_attribute_variant (t1
, attributes
);
371 /* If both args specify argument types, we must merge the two
372 lists, argument by argument. */
375 declare_parm_level ();
377 len
= list_length (p1
);
380 for (i
= 0; i
< len
; i
++)
381 newargs
= tree_cons (NULL_TREE
, NULL_TREE
, newargs
);
386 p1
= TREE_CHAIN (p1
), p2
= TREE_CHAIN (p2
), n
= TREE_CHAIN (n
))
388 /* A null type means arg type is not specified.
389 Take whatever the other function type has. */
390 if (TREE_VALUE (p1
) == 0)
392 TREE_VALUE (n
) = TREE_VALUE (p2
);
395 if (TREE_VALUE (p2
) == 0)
397 TREE_VALUE (n
) = TREE_VALUE (p1
);
401 /* Given wait (union {union wait *u; int *i} *)
402 and wait (union wait *),
403 prefer union wait * as type of parm. */
404 if (TREE_CODE (TREE_VALUE (p1
)) == UNION_TYPE
405 && TREE_VALUE (p1
) != TREE_VALUE (p2
))
408 for (memb
= TYPE_FIELDS (TREE_VALUE (p1
));
409 memb
; memb
= TREE_CHAIN (memb
))
410 if (comptypes (TREE_TYPE (memb
), TREE_VALUE (p2
),
413 TREE_VALUE (n
) = TREE_VALUE (p2
);
415 pedwarn ("function types not truly compatible in ISO C");
419 if (TREE_CODE (TREE_VALUE (p2
)) == UNION_TYPE
420 && TREE_VALUE (p2
) != TREE_VALUE (p1
))
423 for (memb
= TYPE_FIELDS (TREE_VALUE (p2
));
424 memb
; memb
= TREE_CHAIN (memb
))
425 if (comptypes (TREE_TYPE (memb
), TREE_VALUE (p1
),
428 TREE_VALUE (n
) = TREE_VALUE (p1
);
430 pedwarn ("function types not truly compatible in ISO C");
434 TREE_VALUE (n
) = common_type (TREE_VALUE (p1
), TREE_VALUE (p2
));
440 t1
= build_function_type (valtype
, newargs
);
441 /* ... falls through ... */
445 return build_type_attribute_variant (t1
, attributes
);
450 /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
451 or various other operations. Return 2 if they are compatible
452 but a warning may be needed if you use them together. */
455 comptypes (tree type1
, tree type2
, int flags
)
461 /* Suppress errors caused by previously reported errors. */
463 if (t1
== t2
|| !t1
|| !t2
464 || TREE_CODE (t1
) == ERROR_MARK
|| TREE_CODE (t2
) == ERROR_MARK
)
467 /* If either type is the internal version of sizetype, return the
469 if (TREE_CODE (t1
) == INTEGER_TYPE
&& TYPE_IS_SIZETYPE (t1
)
470 && TYPE_DOMAIN (t1
) != 0)
471 t1
= TYPE_DOMAIN (t1
);
473 if (TREE_CODE (t2
) == INTEGER_TYPE
&& TYPE_IS_SIZETYPE (t2
)
474 && TYPE_DOMAIN (t2
) != 0)
475 t2
= TYPE_DOMAIN (t2
);
477 /* Enumerated types are compatible with integer types, but this is
478 not transitive: two enumerated types in the same translation unit
479 are compatible with each other only if they are the same type. */
481 if (TREE_CODE (t1
) == ENUMERAL_TYPE
&& TREE_CODE (t2
) != ENUMERAL_TYPE
)
482 t1
= c_common_type_for_size (TYPE_PRECISION (t1
), TREE_UNSIGNED (t1
));
483 else if (TREE_CODE (t2
) == ENUMERAL_TYPE
&& TREE_CODE (t1
) != ENUMERAL_TYPE
)
484 t2
= c_common_type_for_size (TYPE_PRECISION (t2
), TREE_UNSIGNED (t2
));
489 /* Different classes of types can't be compatible. */
491 if (TREE_CODE (t1
) != TREE_CODE (t2
)) return 0;
493 /* Qualifiers must match. */
495 if (TYPE_QUALS (t1
) != TYPE_QUALS (t2
))
498 /* Allow for two different type nodes which have essentially the same
499 definition. Note that we already checked for equality of the type
500 qualifiers (just above). */
502 if (TYPE_MAIN_VARIANT (t1
) == TYPE_MAIN_VARIANT (t2
))
505 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
506 if (! (attrval
= (*targetm
.comp_type_attributes
) (t1
, t2
)))
509 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
512 switch (TREE_CODE (t1
))
515 /* We must give ObjC the first crack at comparing pointers, since
516 protocol qualifiers may be involved. */
517 if (c_dialect_objc () && (val
= objc_comptypes (t1
, t2
, 0)) >= 0)
519 val
= (TREE_TYPE (t1
) == TREE_TYPE (t2
)
520 ? 1 : comptypes (TREE_TYPE (t1
), TREE_TYPE (t2
), flags
));
524 val
= function_types_compatible_p (t1
, t2
, flags
);
529 tree d1
= TYPE_DOMAIN (t1
);
530 tree d2
= TYPE_DOMAIN (t2
);
531 bool d1_variable
, d2_variable
;
532 bool d1_zero
, d2_zero
;
535 /* Target types must match incl. qualifiers. */
536 if (TREE_TYPE (t1
) != TREE_TYPE (t2
)
537 && 0 == (val
= comptypes (TREE_TYPE (t1
), TREE_TYPE (t2
),
541 /* Sizes must match unless one is missing or variable. */
542 if (d1
== 0 || d2
== 0 || d1
== d2
)
545 d1_zero
= ! TYPE_MAX_VALUE (d1
);
546 d2_zero
= ! TYPE_MAX_VALUE (d2
);
548 d1_variable
= (! d1_zero
549 && (TREE_CODE (TYPE_MIN_VALUE (d1
)) != INTEGER_CST
550 || TREE_CODE (TYPE_MAX_VALUE (d1
)) != INTEGER_CST
));
551 d2_variable
= (! d2_zero
552 && (TREE_CODE (TYPE_MIN_VALUE (d2
)) != INTEGER_CST
553 || TREE_CODE (TYPE_MAX_VALUE (d2
)) != INTEGER_CST
));
555 if (d1_variable
|| d2_variable
)
557 if (d1_zero
&& d2_zero
)
559 if (d1_zero
|| d2_zero
560 || ! tree_int_cst_equal (TYPE_MIN_VALUE (d1
), TYPE_MIN_VALUE (d2
))
561 || ! tree_int_cst_equal (TYPE_MAX_VALUE (d1
), TYPE_MAX_VALUE (d2
)))
568 /* We are dealing with two distinct structs. In assorted Objective-C
569 corner cases, however, these can still be deemed equivalent. */
570 if (c_dialect_objc () && objc_comptypes (t1
, t2
, 0) == 1)
575 if (val
!= 1 && !same_translation_unit_p (t1
, t2
))
576 val
= tagged_types_tu_compatible_p (t1
, t2
, flags
);
580 /* The target might allow certain vector types to be compatible. */
581 val
= (*targetm
.vector_opaque_p
) (t1
)
582 || (*targetm
.vector_opaque_p
) (t2
);
588 return attrval
== 2 && val
== 1 ? 2 : val
;
591 /* Return 1 if TTL and TTR are pointers to types that are equivalent,
592 ignoring their qualifiers. REFLEXIVE is only used by ObjC - set it
593 to 1 or 0 depending if the check of the pointer types is meant to
594 be reflexive or not (typically, assignments are not reflexive,
595 while comparisons are reflexive).
599 comp_target_types (tree ttl
, tree ttr
, int reflexive
)
603 /* Give objc_comptypes a crack at letting these types through. */
604 if ((val
= objc_comptypes (ttl
, ttr
, reflexive
)) >= 0)
607 val
= comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (ttl
)),
608 TYPE_MAIN_VARIANT (TREE_TYPE (ttr
)), COMPARE_STRICT
);
610 if (val
== 2 && pedantic
)
611 pedwarn ("types are not quite compatible");
615 /* Subroutines of `comptypes'. */
617 /* Determine whether two types derive from the same translation unit.
618 If the CONTEXT chain ends in a null, that type's context is still
619 being parsed, so if two types have context chains ending in null,
620 they're in the same translation unit. */
622 same_translation_unit_p (tree t1
, tree t2
)
624 while (t1
&& TREE_CODE (t1
) != TRANSLATION_UNIT_DECL
)
625 switch (TREE_CODE_CLASS (TREE_CODE (t1
)))
627 case 'd': t1
= DECL_CONTEXT (t1
); break;
628 case 't': t1
= TYPE_CONTEXT (t1
); break;
629 case 'b': t1
= BLOCK_SUPERCONTEXT (t1
); break;
633 while (t2
&& TREE_CODE (t2
) != TRANSLATION_UNIT_DECL
)
634 switch (TREE_CODE_CLASS (TREE_CODE (t2
)))
636 case 'd': t2
= DECL_CONTEXT (t1
); break;
637 case 't': t2
= TYPE_CONTEXT (t2
); break;
638 case 'b': t2
= BLOCK_SUPERCONTEXT (t2
); break;
645 /* The C standard says that two structures in different translation
646 units are compatible with each other only if the types of their
647 fields are compatible (among other things). So, consider two copies
648 of this structure: */
650 struct tagged_tu_seen
{
651 const struct tagged_tu_seen
* next
;
656 /* Can they be compatible with each other? We choose to break the
657 recursion by allowing those types to be compatible. */
659 static const struct tagged_tu_seen
* tagged_tu_seen_base
;
661 /* Return 1 if two 'struct', 'union', or 'enum' types T1 and T2 are
662 compatible. If the two types are not the same (which has been
663 checked earlier), this can only happen when multiple translation
664 units are being compiled. See C99 6.2.7 paragraph 1 for the exact
668 tagged_types_tu_compatible_p (tree t1
, tree t2
, int flags
)
671 bool needs_warning
= false;
673 /* We have to verify that the tags of the types are the same. This
674 is harder than it looks because this may be a typedef, so we have
675 to go look at the original type. It may even be a typedef of a
677 while (TYPE_NAME (t1
) && TREE_CODE (TYPE_NAME (t1
)) == TYPE_DECL
)
678 t1
= DECL_ORIGINAL_TYPE (TYPE_NAME (t1
));
680 while (TYPE_NAME (t2
) && TREE_CODE (TYPE_NAME (t2
)) == TYPE_DECL
)
681 t2
= DECL_ORIGINAL_TYPE (TYPE_NAME (t2
));
683 /* C90 didn't have the requirement that the two tags be the same. */
684 if (flag_isoc99
&& TYPE_NAME (t1
) != TYPE_NAME (t2
))
687 /* C90 didn't say what happened if one or both of the types were
688 incomplete; we choose to follow C99 rules here, which is that they
690 if (TYPE_SIZE (t1
) == NULL
691 || TYPE_SIZE (t2
) == NULL
)
695 const struct tagged_tu_seen
* tts_i
;
696 for (tts_i
= tagged_tu_seen_base
; tts_i
!= NULL
; tts_i
= tts_i
->next
)
697 if (tts_i
->t1
== t1
&& tts_i
->t2
== t2
)
701 switch (TREE_CODE (t1
))
705 if (list_length (TYPE_VALUES (t1
)) != list_length (TYPE_VALUES (t2
)))
708 for (s1
= TYPE_VALUES (t1
); s1
; s1
= TREE_CHAIN (s1
))
710 s2
= purpose_member (TREE_PURPOSE (s1
), TYPE_VALUES (t2
));
712 || simple_cst_equal (TREE_VALUE (s1
), TREE_VALUE (s2
)) != 1)
720 if (list_length (TYPE_FIELDS (t1
)) != list_length (TYPE_FIELDS (t2
)))
723 for (s1
= TYPE_FIELDS (t1
); s1
; s1
= TREE_CHAIN (s1
))
726 struct tagged_tu_seen tts
;
728 tts
.next
= tagged_tu_seen_base
;
731 tagged_tu_seen_base
= &tts
;
733 if (DECL_NAME (s1
) != NULL
)
734 for (s2
= TYPE_VALUES (t2
); s2
; s2
= TREE_CHAIN (s2
))
735 if (DECL_NAME (s1
) == DECL_NAME (s2
))
738 result
= comptypes (TREE_TYPE (s1
), TREE_TYPE (s2
), flags
);
742 needs_warning
= true;
744 if (TREE_CODE (s1
) == FIELD_DECL
745 && simple_cst_equal (DECL_FIELD_BIT_OFFSET (s1
),
746 DECL_FIELD_BIT_OFFSET (s2
)) != 1)
752 tagged_tu_seen_base
= tts
.next
;
756 return needs_warning
? 2 : 1;
761 struct tagged_tu_seen tts
;
763 tts
.next
= tagged_tu_seen_base
;
766 tagged_tu_seen_base
= &tts
;
768 for (s1
= TYPE_FIELDS (t1
), s2
= TYPE_FIELDS (t2
);
770 s1
= TREE_CHAIN (s1
), s2
= TREE_CHAIN (s2
))
773 if (TREE_CODE (s1
) != TREE_CODE (s2
)
774 || DECL_NAME (s1
) != DECL_NAME (s2
))
776 result
= comptypes (TREE_TYPE (s1
), TREE_TYPE (s2
), flags
);
780 needs_warning
= true;
782 if (TREE_CODE (s1
) == FIELD_DECL
783 && simple_cst_equal (DECL_FIELD_BIT_OFFSET (s1
),
784 DECL_FIELD_BIT_OFFSET (s2
)) != 1)
787 tagged_tu_seen_base
= tts
.next
;
790 return needs_warning
? 2 : 1;
798 /* Return 1 if two function types F1 and F2 are compatible.
799 If either type specifies no argument types,
800 the other must specify a fixed number of self-promoting arg types.
801 Otherwise, if one type specifies only the number of arguments,
802 the other must specify that number of self-promoting arg types.
803 Otherwise, the argument types must match. */
806 function_types_compatible_p (tree f1
, tree f2
, int flags
)
809 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
814 ret1
= TREE_TYPE (f1
);
815 ret2
= TREE_TYPE (f2
);
817 /* 'volatile' qualifiers on a function's return type mean the function
819 if (pedantic
&& TYPE_VOLATILE (ret1
) != TYPE_VOLATILE (ret2
))
820 pedwarn ("function return types not compatible due to `volatile'");
821 if (TYPE_VOLATILE (ret1
))
822 ret1
= build_qualified_type (TYPE_MAIN_VARIANT (ret1
),
823 TYPE_QUALS (ret1
) & ~TYPE_QUAL_VOLATILE
);
824 if (TYPE_VOLATILE (ret2
))
825 ret2
= build_qualified_type (TYPE_MAIN_VARIANT (ret2
),
826 TYPE_QUALS (ret2
) & ~TYPE_QUAL_VOLATILE
);
827 val
= comptypes (ret1
, ret2
, flags
);
831 args1
= TYPE_ARG_TYPES (f1
);
832 args2
= TYPE_ARG_TYPES (f2
);
834 /* An unspecified parmlist matches any specified parmlist
835 whose argument types don't need default promotions. */
839 if (!self_promoting_args_p (args2
))
841 /* If one of these types comes from a non-prototype fn definition,
842 compare that with the other type's arglist.
843 If they don't match, ask for a warning (but no error). */
844 if (TYPE_ACTUAL_ARG_TYPES (f1
)
845 && 1 != type_lists_compatible_p (args2
, TYPE_ACTUAL_ARG_TYPES (f1
),
852 if (!self_promoting_args_p (args1
))
854 if (TYPE_ACTUAL_ARG_TYPES (f2
)
855 && 1 != type_lists_compatible_p (args1
, TYPE_ACTUAL_ARG_TYPES (f2
),
861 /* Both types have argument lists: compare them and propagate results. */
862 val1
= type_lists_compatible_p (args1
, args2
, flags
);
863 return val1
!= 1 ? val1
: val
;
866 /* Check two lists of types for compatibility,
867 returning 0 for incompatible, 1 for compatible,
868 or 2 for compatible with warning. */
871 type_lists_compatible_p (tree args1
, tree args2
, int flags
)
873 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
879 if (args1
== 0 && args2
== 0)
881 /* If one list is shorter than the other,
882 they fail to match. */
883 if (args1
== 0 || args2
== 0)
885 /* A null pointer instead of a type
886 means there is supposed to be an argument
887 but nothing is specified about what type it has.
888 So match anything that self-promotes. */
889 if (TREE_VALUE (args1
) == 0)
891 if (c_type_promotes_to (TREE_VALUE (args2
)) != TREE_VALUE (args2
))
894 else if (TREE_VALUE (args2
) == 0)
896 if (c_type_promotes_to (TREE_VALUE (args1
)) != TREE_VALUE (args1
))
899 /* If one of the lists has an error marker, ignore this arg. */
900 else if (TREE_CODE (TREE_VALUE (args1
)) == ERROR_MARK
901 || TREE_CODE (TREE_VALUE (args2
)) == ERROR_MARK
)
903 else if (! (newval
= comptypes (TYPE_MAIN_VARIANT (TREE_VALUE (args1
)),
904 TYPE_MAIN_VARIANT (TREE_VALUE (args2
)),
907 /* Allow wait (union {union wait *u; int *i} *)
908 and wait (union wait *) to be compatible. */
909 if (TREE_CODE (TREE_VALUE (args1
)) == UNION_TYPE
910 && (TYPE_NAME (TREE_VALUE (args1
)) == 0
911 || TYPE_TRANSPARENT_UNION (TREE_VALUE (args1
)))
912 && TREE_CODE (TYPE_SIZE (TREE_VALUE (args1
))) == INTEGER_CST
913 && tree_int_cst_equal (TYPE_SIZE (TREE_VALUE (args1
)),
914 TYPE_SIZE (TREE_VALUE (args2
))))
917 for (memb
= TYPE_FIELDS (TREE_VALUE (args1
));
918 memb
; memb
= TREE_CHAIN (memb
))
919 if (comptypes (TREE_TYPE (memb
), TREE_VALUE (args2
),
925 else if (TREE_CODE (TREE_VALUE (args2
)) == UNION_TYPE
926 && (TYPE_NAME (TREE_VALUE (args2
)) == 0
927 || TYPE_TRANSPARENT_UNION (TREE_VALUE (args2
)))
928 && TREE_CODE (TYPE_SIZE (TREE_VALUE (args2
))) == INTEGER_CST
929 && tree_int_cst_equal (TYPE_SIZE (TREE_VALUE (args2
)),
930 TYPE_SIZE (TREE_VALUE (args1
))))
933 for (memb
= TYPE_FIELDS (TREE_VALUE (args2
));
934 memb
; memb
= TREE_CHAIN (memb
))
935 if (comptypes (TREE_TYPE (memb
), TREE_VALUE (args1
),
945 /* comptypes said ok, but record if it said to warn. */
949 args1
= TREE_CHAIN (args1
);
950 args2
= TREE_CHAIN (args2
);
954 /* Compute the size to increment a pointer by. */
957 c_size_in_bytes (tree type
)
959 enum tree_code code
= TREE_CODE (type
);
961 if (code
== FUNCTION_TYPE
|| code
== VOID_TYPE
|| code
== ERROR_MARK
)
962 return size_one_node
;
964 if (!COMPLETE_OR_VOID_TYPE_P (type
))
966 error ("arithmetic on pointer to an incomplete type");
967 return size_one_node
;
970 /* Convert in case a char is more than one unit. */
971 return size_binop (CEIL_DIV_EXPR
, TYPE_SIZE_UNIT (type
),
972 size_int (TYPE_PRECISION (char_type_node
)
976 /* Return either DECL or its known constant value (if it has one). */
979 decl_constant_value (tree decl
)
981 if (/* Don't change a variable array bound or initial value to a constant
982 in a place where a variable is invalid. */
983 current_function_decl
!= 0
984 && ! TREE_THIS_VOLATILE (decl
)
985 && TREE_READONLY (decl
)
986 && DECL_INITIAL (decl
) != 0
987 && TREE_CODE (DECL_INITIAL (decl
)) != ERROR_MARK
988 /* This is invalid if initial value is not constant.
989 If it has either a function call, a memory reference,
990 or a variable, then re-evaluating it could give different results. */
991 && TREE_CONSTANT (DECL_INITIAL (decl
))
992 /* Check for cases where this is sub-optimal, even though valid. */
993 && TREE_CODE (DECL_INITIAL (decl
)) != CONSTRUCTOR
)
994 return DECL_INITIAL (decl
);
998 /* Return either DECL or its known constant value (if it has one), but
999 return DECL if pedantic or DECL has mode BLKmode. This is for
1000 bug-compatibility with the old behavior of decl_constant_value
1001 (before GCC 3.0); every use of this function is a bug and it should
1002 be removed before GCC 3.1. It is not appropriate to use pedantic
1003 in a way that affects optimization, and BLKmode is probably not the
1004 right test for avoiding misoptimizations either. */
1007 decl_constant_value_for_broken_optimization (tree decl
)
1009 if (pedantic
|| DECL_MODE (decl
) == BLKmode
)
1012 return decl_constant_value (decl
);
1016 /* Perform the default conversion of arrays and functions to pointers.
1017 Return the result of converting EXP. For any other expression, just
1021 default_function_array_conversion (tree exp
)
1024 tree type
= TREE_TYPE (exp
);
1025 enum tree_code code
= TREE_CODE (type
);
1028 /* Strip NON_LVALUE_EXPRs and no-op conversions, since we aren't using as
1031 Do not use STRIP_NOPS here! It will remove conversions from pointer
1032 to integer and cause infinite recursion. */
1034 while (TREE_CODE (exp
) == NON_LVALUE_EXPR
1035 || (TREE_CODE (exp
) == NOP_EXPR
1036 && TREE_TYPE (TREE_OPERAND (exp
, 0)) == TREE_TYPE (exp
)))
1038 if (TREE_CODE (exp
) == NON_LVALUE_EXPR
)
1040 exp
= TREE_OPERAND (exp
, 0);
1043 /* Preserve the original expression code. */
1044 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (exp
))))
1045 C_SET_EXP_ORIGINAL_CODE (exp
, C_EXP_ORIGINAL_CODE (orig_exp
));
1047 if (code
== FUNCTION_TYPE
)
1049 return build_unary_op (ADDR_EXPR
, exp
, 0);
1051 if (code
== ARRAY_TYPE
)
1054 tree restype
= TREE_TYPE (type
);
1060 if (TREE_CODE_CLASS (TREE_CODE (exp
)) == 'r' || DECL_P (exp
))
1062 constp
= TREE_READONLY (exp
);
1063 volatilep
= TREE_THIS_VOLATILE (exp
);
1066 if (TYPE_QUALS (type
) || constp
|| volatilep
)
1068 = c_build_qualified_type (restype
,
1070 | (constp
* TYPE_QUAL_CONST
)
1071 | (volatilep
* TYPE_QUAL_VOLATILE
));
1073 if (TREE_CODE (exp
) == INDIRECT_REF
)
1074 return convert (TYPE_POINTER_TO (restype
),
1075 TREE_OPERAND (exp
, 0));
1077 if (TREE_CODE (exp
) == COMPOUND_EXPR
)
1079 tree op1
= default_conversion (TREE_OPERAND (exp
, 1));
1080 return build (COMPOUND_EXPR
, TREE_TYPE (op1
),
1081 TREE_OPERAND (exp
, 0), op1
);
1084 lvalue_array_p
= !not_lvalue
&& lvalue_p (exp
);
1085 if (!flag_isoc99
&& !lvalue_array_p
)
1087 /* Before C99, non-lvalue arrays do not decay to pointers.
1088 Normally, using such an array would be invalid; but it can
1089 be used correctly inside sizeof or as a statement expression.
1090 Thus, do not give an error here; an error will result later. */
1094 ptrtype
= build_pointer_type (restype
);
1096 if (TREE_CODE (exp
) == VAR_DECL
)
1098 /* ??? This is not really quite correct
1099 in that the type of the operand of ADDR_EXPR
1100 is not the target type of the type of the ADDR_EXPR itself.
1101 Question is, can this lossage be avoided? */
1102 adr
= build1 (ADDR_EXPR
, ptrtype
, exp
);
1103 if (!c_mark_addressable (exp
))
1104 return error_mark_node
;
1105 TREE_CONSTANT (adr
) = staticp (exp
);
1106 TREE_SIDE_EFFECTS (adr
) = 0; /* Default would be, same as EXP. */
1109 /* This way is better for a COMPONENT_REF since it can
1110 simplify the offset for a component. */
1111 adr
= build_unary_op (ADDR_EXPR
, exp
, 1);
1112 return convert (ptrtype
, adr
);
1117 /* Perform default promotions for C data used in expressions.
1118 Arrays and functions are converted to pointers;
1119 enumeral types or short or char, to int.
1120 In addition, manifest constants symbols are replaced by their values. */
1123 default_conversion (tree exp
)
1126 tree type
= TREE_TYPE (exp
);
1127 enum tree_code code
= TREE_CODE (type
);
1129 if (code
== FUNCTION_TYPE
|| code
== ARRAY_TYPE
)
1130 return default_function_array_conversion (exp
);
1132 /* Constants can be used directly unless they're not loadable. */
1133 if (TREE_CODE (exp
) == CONST_DECL
)
1134 exp
= DECL_INITIAL (exp
);
1136 /* Replace a nonvolatile const static variable with its value unless
1137 it is an array, in which case we must be sure that taking the
1138 address of the array produces consistent results. */
1139 else if (optimize
&& TREE_CODE (exp
) == VAR_DECL
&& code
!= ARRAY_TYPE
)
1141 exp
= decl_constant_value_for_broken_optimization (exp
);
1142 type
= TREE_TYPE (exp
);
1145 /* Strip NON_LVALUE_EXPRs and no-op conversions, since we aren't using as
1148 Do not use STRIP_NOPS here! It will remove conversions from pointer
1149 to integer and cause infinite recursion. */
1151 while (TREE_CODE (exp
) == NON_LVALUE_EXPR
1152 || (TREE_CODE (exp
) == NOP_EXPR
1153 && TREE_TYPE (TREE_OPERAND (exp
, 0)) == TREE_TYPE (exp
)))
1154 exp
= TREE_OPERAND (exp
, 0);
1156 /* Preserve the original expression code. */
1157 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (exp
))))
1158 C_SET_EXP_ORIGINAL_CODE (exp
, C_EXP_ORIGINAL_CODE (orig_exp
));
1160 /* Normally convert enums to int,
1161 but convert wide enums to something wider. */
1162 if (code
== ENUMERAL_TYPE
)
1164 type
= c_common_type_for_size (MAX (TYPE_PRECISION (type
),
1165 TYPE_PRECISION (integer_type_node
)),
1166 ((TYPE_PRECISION (type
)
1167 >= TYPE_PRECISION (integer_type_node
))
1168 && TREE_UNSIGNED (type
)));
1170 return convert (type
, exp
);
1173 if (TREE_CODE (exp
) == COMPONENT_REF
1174 && DECL_C_BIT_FIELD (TREE_OPERAND (exp
, 1))
1175 /* If it's thinner than an int, promote it like a
1176 c_promoting_integer_type_p, otherwise leave it alone. */
1177 && 0 > compare_tree_int (DECL_SIZE (TREE_OPERAND (exp
, 1)),
1178 TYPE_PRECISION (integer_type_node
)))
1179 return convert (integer_type_node
, exp
);
1181 if (c_promoting_integer_type_p (type
))
1183 /* Preserve unsignedness if not really getting any wider. */
1184 if (TREE_UNSIGNED (type
)
1185 && TYPE_PRECISION (type
) == TYPE_PRECISION (integer_type_node
))
1186 return convert (unsigned_type_node
, exp
);
1188 return convert (integer_type_node
, exp
);
1191 if (code
== VOID_TYPE
)
1193 error ("void value not ignored as it ought to be");
1194 return error_mark_node
;
1199 /* Look up COMPONENT in a structure or union DECL.
1201 If the component name is not found, returns NULL_TREE. Otherwise,
1202 the return value is a TREE_LIST, with each TREE_VALUE a FIELD_DECL
1203 stepping down the chain to the component, which is in the last
1204 TREE_VALUE of the list. Normally the list is of length one, but if
1205 the component is embedded within (nested) anonymous structures or
1206 unions, the list steps down the chain to the component. */
1209 lookup_field (tree decl
, tree component
)
1211 tree type
= TREE_TYPE (decl
);
1214 /* If TYPE_LANG_SPECIFIC is set, then it is a sorted array of pointers
1215 to the field elements. Use a binary search on this array to quickly
1216 find the element. Otherwise, do a linear search. TYPE_LANG_SPECIFIC
1217 will always be set for structures which have many elements. */
1219 if (TYPE_LANG_SPECIFIC (type
))
1222 tree
*field_array
= &TYPE_LANG_SPECIFIC (type
)->s
->elts
[0];
1224 field
= TYPE_FIELDS (type
);
1226 top
= TYPE_LANG_SPECIFIC (type
)->s
->len
;
1227 while (top
- bot
> 1)
1229 half
= (top
- bot
+ 1) >> 1;
1230 field
= field_array
[bot
+half
];
1232 if (DECL_NAME (field
) == NULL_TREE
)
1234 /* Step through all anon unions in linear fashion. */
1235 while (DECL_NAME (field_array
[bot
]) == NULL_TREE
)
1237 field
= field_array
[bot
++];
1238 if (TREE_CODE (TREE_TYPE (field
)) == RECORD_TYPE
1239 || TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
)
1241 tree anon
= lookup_field (field
, component
);
1244 return tree_cons (NULL_TREE
, field
, anon
);
1248 /* Entire record is only anon unions. */
1252 /* Restart the binary search, with new lower bound. */
1256 if (DECL_NAME (field
) == component
)
1258 if (DECL_NAME (field
) < component
)
1264 if (DECL_NAME (field_array
[bot
]) == component
)
1265 field
= field_array
[bot
];
1266 else if (DECL_NAME (field
) != component
)
1271 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
1273 if (DECL_NAME (field
) == NULL_TREE
1274 && (TREE_CODE (TREE_TYPE (field
)) == RECORD_TYPE
1275 || TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
))
1277 tree anon
= lookup_field (field
, component
);
1280 return tree_cons (NULL_TREE
, field
, anon
);
1283 if (DECL_NAME (field
) == component
)
1287 if (field
== NULL_TREE
)
1291 return tree_cons (NULL_TREE
, field
, NULL_TREE
);
1294 /* Make an expression to refer to the COMPONENT field of
1295 structure or union value DATUM. COMPONENT is an IDENTIFIER_NODE. */
1298 build_component_ref (tree datum
, tree component
)
1300 tree type
= TREE_TYPE (datum
);
1301 enum tree_code code
= TREE_CODE (type
);
1305 /* If DATUM is a COMPOUND_EXPR, move our reference inside it.
1306 If pedantic ensure that the arguments are not lvalues; otherwise,
1307 if the component is an array, it would wrongly decay to a pointer in
1309 We cannot do this with a COND_EXPR, because in a conditional expression
1310 the default promotions are applied to both sides, and this would yield
1311 the wrong type of the result; for example, if the components have
1313 switch (TREE_CODE (datum
))
1317 tree value
= build_component_ref (TREE_OPERAND (datum
, 1), component
);
1318 return build (COMPOUND_EXPR
, TREE_TYPE (value
),
1319 TREE_OPERAND (datum
, 0), pedantic_non_lvalue (value
));
1325 /* See if there is a field or component with name COMPONENT. */
1327 if (code
== RECORD_TYPE
|| code
== UNION_TYPE
)
1329 if (!COMPLETE_TYPE_P (type
))
1331 c_incomplete_type_error (NULL_TREE
, type
);
1332 return error_mark_node
;
1335 field
= lookup_field (datum
, component
);
1339 error ("%s has no member named `%s'",
1340 code
== RECORD_TYPE
? "structure" : "union",
1341 IDENTIFIER_POINTER (component
));
1342 return error_mark_node
;
1345 /* Chain the COMPONENT_REFs if necessary down to the FIELD.
1346 This might be better solved in future the way the C++ front
1347 end does it - by giving the anonymous entities each a
1348 separate name and type, and then have build_component_ref
1349 recursively call itself. We can't do that here. */
1352 tree subdatum
= TREE_VALUE (field
);
1354 if (TREE_TYPE (subdatum
) == error_mark_node
)
1355 return error_mark_node
;
1357 ref
= build (COMPONENT_REF
, TREE_TYPE (subdatum
), datum
, subdatum
);
1358 if (TREE_READONLY (datum
) || TREE_READONLY (subdatum
))
1359 TREE_READONLY (ref
) = 1;
1360 if (TREE_THIS_VOLATILE (datum
) || TREE_THIS_VOLATILE (subdatum
))
1361 TREE_THIS_VOLATILE (ref
) = 1;
1363 if (TREE_DEPRECATED (subdatum
))
1364 warn_deprecated_use (subdatum
);
1368 field
= TREE_CHAIN (field
);
1374 else if (code
!= ERROR_MARK
)
1375 error ("request for member `%s' in something not a structure or union",
1376 IDENTIFIER_POINTER (component
));
1378 return error_mark_node
;
1381 /* Given an expression PTR for a pointer, return an expression
1382 for the value pointed to.
1383 ERRORSTRING is the name of the operator to appear in error messages. */
1386 build_indirect_ref (tree ptr
, const char *errorstring
)
1388 tree pointer
= default_conversion (ptr
);
1389 tree type
= TREE_TYPE (pointer
);
1391 if (TREE_CODE (type
) == POINTER_TYPE
)
1393 if (TREE_CODE (pointer
) == ADDR_EXPR
1394 && (TREE_TYPE (TREE_OPERAND (pointer
, 0))
1395 == TREE_TYPE (type
)))
1396 return TREE_OPERAND (pointer
, 0);
1399 tree t
= TREE_TYPE (type
);
1400 tree ref
= build1 (INDIRECT_REF
, TYPE_MAIN_VARIANT (t
), pointer
);
1402 if (!COMPLETE_OR_VOID_TYPE_P (t
) && TREE_CODE (t
) != ARRAY_TYPE
)
1404 error ("dereferencing pointer to incomplete type");
1405 return error_mark_node
;
1407 if (VOID_TYPE_P (t
) && skip_evaluation
== 0)
1408 warning ("dereferencing `void *' pointer");
1410 /* We *must* set TREE_READONLY when dereferencing a pointer to const,
1411 so that we get the proper error message if the result is used
1412 to assign to. Also, &* is supposed to be a no-op.
1413 And ANSI C seems to specify that the type of the result
1414 should be the const type. */
1415 /* A de-reference of a pointer to const is not a const. It is valid
1416 to change it via some other pointer. */
1417 TREE_READONLY (ref
) = TYPE_READONLY (t
);
1418 TREE_SIDE_EFFECTS (ref
)
1419 = TYPE_VOLATILE (t
) || TREE_SIDE_EFFECTS (pointer
);
1420 TREE_THIS_VOLATILE (ref
) = TYPE_VOLATILE (t
);
1424 else if (TREE_CODE (pointer
) != ERROR_MARK
)
1425 error ("invalid type argument of `%s'", errorstring
);
1426 return error_mark_node
;
1429 /* This handles expressions of the form "a[i]", which denotes
1432 This is logically equivalent in C to *(a+i), but we may do it differently.
1433 If A is a variable or a member, we generate a primitive ARRAY_REF.
1434 This avoids forcing the array out of registers, and can work on
1435 arrays that are not lvalues (for example, members of structures returned
1439 build_array_ref (tree array
, tree index
)
1443 error ("subscript missing in array reference");
1444 return error_mark_node
;
1447 if (TREE_TYPE (array
) == error_mark_node
1448 || TREE_TYPE (index
) == error_mark_node
)
1449 return error_mark_node
;
1451 if (TREE_CODE (TREE_TYPE (array
)) == ARRAY_TYPE
1452 && TREE_CODE (array
) != INDIRECT_REF
)
1456 /* Subscripting with type char is likely to lose
1457 on a machine where chars are signed.
1458 So warn on any machine, but optionally.
1459 Don't warn for unsigned char since that type is safe.
1460 Don't warn for signed char because anyone who uses that
1461 must have done so deliberately. */
1462 if (warn_char_subscripts
1463 && TYPE_MAIN_VARIANT (TREE_TYPE (index
)) == char_type_node
)
1464 warning ("array subscript has type `char'");
1466 /* Apply default promotions *after* noticing character types. */
1467 index
= default_conversion (index
);
1469 /* Require integer *after* promotion, for sake of enums. */
1470 if (TREE_CODE (TREE_TYPE (index
)) != INTEGER_TYPE
)
1472 error ("array subscript is not an integer");
1473 return error_mark_node
;
1476 /* An array that is indexed by a non-constant
1477 cannot be stored in a register; we must be able to do
1478 address arithmetic on its address.
1479 Likewise an array of elements of variable size. */
1480 if (TREE_CODE (index
) != INTEGER_CST
1481 || (COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (array
)))
1482 && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array
)))) != INTEGER_CST
))
1484 if (!c_mark_addressable (array
))
1485 return error_mark_node
;
1487 /* An array that is indexed by a constant value which is not within
1488 the array bounds cannot be stored in a register either; because we
1489 would get a crash in store_bit_field/extract_bit_field when trying
1490 to access a non-existent part of the register. */
1491 if (TREE_CODE (index
) == INTEGER_CST
1492 && TYPE_VALUES (TREE_TYPE (array
))
1493 && ! int_fits_type_p (index
, TYPE_VALUES (TREE_TYPE (array
))))
1495 if (!c_mark_addressable (array
))
1496 return error_mark_node
;
1502 while (TREE_CODE (foo
) == COMPONENT_REF
)
1503 foo
= TREE_OPERAND (foo
, 0);
1504 if (TREE_CODE (foo
) == VAR_DECL
&& DECL_REGISTER (foo
))
1505 pedwarn ("ISO C forbids subscripting `register' array");
1506 else if (! flag_isoc99
&& ! lvalue_p (foo
))
1507 pedwarn ("ISO C90 forbids subscripting non-lvalue array");
1510 type
= TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (array
)));
1511 rval
= build (ARRAY_REF
, type
, array
, index
);
1512 /* Array ref is const/volatile if the array elements are
1513 or if the array is. */
1514 TREE_READONLY (rval
)
1515 |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array
)))
1516 | TREE_READONLY (array
));
1517 TREE_SIDE_EFFECTS (rval
)
1518 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array
)))
1519 | TREE_SIDE_EFFECTS (array
));
1520 TREE_THIS_VOLATILE (rval
)
1521 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array
)))
1522 /* This was added by rms on 16 Nov 91.
1523 It fixes vol struct foo *a; a->elts[1]
1524 in an inline function.
1525 Hope it doesn't break something else. */
1526 | TREE_THIS_VOLATILE (array
));
1527 return require_complete_type (fold (rval
));
1531 tree ar
= default_conversion (array
);
1532 tree ind
= default_conversion (index
);
1534 /* Do the same warning check as above, but only on the part that's
1535 syntactically the index and only if it is also semantically
1537 if (warn_char_subscripts
1538 && TREE_CODE (TREE_TYPE (index
)) == INTEGER_TYPE
1539 && TYPE_MAIN_VARIANT (TREE_TYPE (index
)) == char_type_node
)
1540 warning ("subscript has type `char'");
1542 /* Put the integer in IND to simplify error checking. */
1543 if (TREE_CODE (TREE_TYPE (ar
)) == INTEGER_TYPE
)
1550 if (ar
== error_mark_node
)
1553 if (TREE_CODE (TREE_TYPE (ar
)) != POINTER_TYPE
1554 || TREE_CODE (TREE_TYPE (TREE_TYPE (ar
))) == FUNCTION_TYPE
)
1556 error ("subscripted value is neither array nor pointer");
1557 return error_mark_node
;
1559 if (TREE_CODE (TREE_TYPE (ind
)) != INTEGER_TYPE
)
1561 error ("array subscript is not an integer");
1562 return error_mark_node
;
1565 return build_indirect_ref (build_binary_op (PLUS_EXPR
, ar
, ind
, 0),
1570 /* Build an external reference to identifier ID. FUN indicates
1571 whether this will be used for a function call. */
1573 build_external_ref (tree id
, int fun
)
1576 tree decl
= lookup_name (id
);
1577 tree objc_ivar
= lookup_objc_ivar (id
);
1579 if (decl
&& decl
!= error_mark_node
)
1581 /* Properly declared variable or function reference. */
1584 else if (decl
!= objc_ivar
&& !DECL_FILE_SCOPE_P (decl
))
1586 warning ("local declaration of `%s' hides instance variable",
1587 IDENTIFIER_POINTER (id
));
1596 /* Implicit function declaration. */
1597 ref
= implicitly_declare (id
);
1598 else if (decl
== error_mark_node
)
1599 /* Don't complain about something that's already been
1600 complained about. */
1601 return error_mark_node
;
1604 undeclared_variable (id
);
1605 return error_mark_node
;
1608 if (TREE_TYPE (ref
) == error_mark_node
)
1609 return error_mark_node
;
1611 if (TREE_DEPRECATED (ref
))
1612 warn_deprecated_use (ref
);
1614 if (!skip_evaluation
)
1615 assemble_external (ref
);
1616 TREE_USED (ref
) = 1;
1618 if (TREE_CODE (ref
) == CONST_DECL
)
1620 ref
= DECL_INITIAL (ref
);
1621 TREE_CONSTANT (ref
) = 1;
1623 else if (current_function_decl
!= 0
1624 && !DECL_FILE_SCOPE_P (current_function_decl
)
1625 && (TREE_CODE (ref
) == VAR_DECL
1626 || TREE_CODE (ref
) == PARM_DECL
1627 || TREE_CODE (ref
) == FUNCTION_DECL
))
1629 tree context
= decl_function_context (ref
);
1631 if (context
!= 0 && context
!= current_function_decl
)
1632 DECL_NONLOCAL (ref
) = 1;
1638 /* Build a function call to function FUNCTION with parameters PARAMS.
1639 PARAMS is a list--a chain of TREE_LIST nodes--in which the
1640 TREE_VALUE of each node is a parameter-expression.
1641 FUNCTION's data type may be a function type or a pointer-to-function. */
1644 build_function_call (tree function
, tree params
)
1646 tree fntype
, fundecl
= 0;
1647 tree coerced_params
;
1648 tree name
= NULL_TREE
, result
;
1651 /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
1652 STRIP_TYPE_NOPS (function
);
1654 /* Convert anything with function type to a pointer-to-function. */
1655 if (TREE_CODE (function
) == FUNCTION_DECL
)
1657 name
= DECL_NAME (function
);
1659 /* Differs from default_conversion by not setting TREE_ADDRESSABLE
1660 (because calling an inline function does not mean the function
1661 needs to be separately compiled). */
1662 fntype
= build_type_variant (TREE_TYPE (function
),
1663 TREE_READONLY (function
),
1664 TREE_THIS_VOLATILE (function
));
1666 function
= build1 (ADDR_EXPR
, build_pointer_type (fntype
), function
);
1669 function
= default_conversion (function
);
1671 fntype
= TREE_TYPE (function
);
1673 if (TREE_CODE (fntype
) == ERROR_MARK
)
1674 return error_mark_node
;
1676 if (!(TREE_CODE (fntype
) == POINTER_TYPE
1677 && TREE_CODE (TREE_TYPE (fntype
)) == FUNCTION_TYPE
))
1679 error ("called object is not a function");
1680 return error_mark_node
;
1683 if (fundecl
&& TREE_THIS_VOLATILE (fundecl
))
1684 current_function_returns_abnormally
= 1;
1686 /* fntype now gets the type of function pointed to. */
1687 fntype
= TREE_TYPE (fntype
);
1689 /* Check that the function is called through a compatible prototype.
1690 If it is not, replace the call by a trap, wrapped up in a compound
1691 expression if necessary. This has the nice side-effect to prevent
1692 the tree-inliner from generating invalid assignment trees which may
1693 blow up in the RTL expander later.
1695 ??? This doesn't work for Objective-C because objc_comptypes
1696 refuses to compare function prototypes, yet the compiler appears
1697 to build calls that are flagged as invalid by C's comptypes. */
1698 if (! c_dialect_objc ()
1699 && TREE_CODE (function
) == NOP_EXPR
1700 && TREE_CODE (tem
= TREE_OPERAND (function
, 0)) == ADDR_EXPR
1701 && TREE_CODE (tem
= TREE_OPERAND (tem
, 0)) == FUNCTION_DECL
1702 && ! comptypes (fntype
, TREE_TYPE (tem
), COMPARE_STRICT
))
1704 tree return_type
= TREE_TYPE (fntype
);
1705 tree trap
= build_function_call (built_in_decls
[BUILT_IN_TRAP
],
1708 /* This situation leads to run-time undefined behavior. We can't,
1709 therefore, simply error unless we can prove that all possible
1710 executions of the program must execute the code. */
1711 warning ("function called through a non-compatible type");
1713 if (VOID_TYPE_P (return_type
))
1719 if (AGGREGATE_TYPE_P (return_type
))
1720 rhs
= build_compound_literal (return_type
,
1721 build_constructor (return_type
,
1724 rhs
= fold (build1 (NOP_EXPR
, return_type
, integer_zero_node
));
1726 return build (COMPOUND_EXPR
, return_type
, trap
, rhs
);
1730 /* Convert the parameters to the types declared in the
1731 function prototype, or apply default promotions. */
1734 = convert_arguments (TYPE_ARG_TYPES (fntype
), params
, name
, fundecl
);
1736 /* Check that the arguments to the function are valid. */
1738 check_function_arguments (TYPE_ATTRIBUTES (fntype
), coerced_params
);
1740 /* Recognize certain built-in functions so we can make tree-codes
1741 other than CALL_EXPR. We do this when it enables fold-const.c
1742 to do something useful. */
1744 if (TREE_CODE (function
) == ADDR_EXPR
1745 && TREE_CODE (TREE_OPERAND (function
, 0)) == FUNCTION_DECL
1746 && DECL_BUILT_IN (TREE_OPERAND (function
, 0)))
1748 result
= expand_tree_builtin (TREE_OPERAND (function
, 0),
1749 params
, coerced_params
);
1754 result
= build (CALL_EXPR
, TREE_TYPE (fntype
),
1755 function
, coerced_params
, NULL_TREE
);
1756 TREE_SIDE_EFFECTS (result
) = 1;
1757 result
= fold (result
);
1759 if (VOID_TYPE_P (TREE_TYPE (result
)))
1761 return require_complete_type (result
);
1764 /* Convert the argument expressions in the list VALUES
1765 to the types in the list TYPELIST. The result is a list of converted
1766 argument expressions.
1768 If TYPELIST is exhausted, or when an element has NULL as its type,
1769 perform the default conversions.
1771 PARMLIST is the chain of parm decls for the function being called.
1772 It may be 0, if that info is not available.
1773 It is used only for generating error messages.
1775 NAME is an IDENTIFIER_NODE or 0. It is used only for error messages.
1777 This is also where warnings about wrong number of args are generated.
1779 Both VALUES and the returned value are chains of TREE_LIST nodes
1780 with the elements of the list in the TREE_VALUE slots of those nodes. */
1783 convert_arguments (tree typelist
, tree values
, tree name
, tree fundecl
)
1785 tree typetail
, valtail
;
1789 /* Scan the given expressions and types, producing individual
1790 converted arguments and pushing them on RESULT in reverse order. */
1792 for (valtail
= values
, typetail
= typelist
, parmnum
= 0;
1794 valtail
= TREE_CHAIN (valtail
), parmnum
++)
1796 tree type
= typetail
? TREE_VALUE (typetail
) : 0;
1797 tree val
= TREE_VALUE (valtail
);
1799 if (type
== void_type_node
)
1802 error ("too many arguments to function `%s'",
1803 IDENTIFIER_POINTER (name
));
1805 error ("too many arguments to function");
1809 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
1810 /* Do not use STRIP_NOPS here! We do not want an enumerator with value 0
1811 to convert automatically to a pointer. */
1812 if (TREE_CODE (val
) == NON_LVALUE_EXPR
)
1813 val
= TREE_OPERAND (val
, 0);
1815 val
= default_function_array_conversion (val
);
1817 val
= require_complete_type (val
);
1821 /* Formal parm type is specified by a function prototype. */
1824 if (!COMPLETE_TYPE_P (type
))
1826 error ("type of formal parameter %d is incomplete", parmnum
+ 1);
1831 /* Optionally warn about conversions that
1832 differ from the default conversions. */
1833 if (warn_conversion
|| warn_traditional
)
1835 int formal_prec
= TYPE_PRECISION (type
);
1837 if (INTEGRAL_TYPE_P (type
)
1838 && TREE_CODE (TREE_TYPE (val
)) == REAL_TYPE
)
1839 warn_for_assignment ("%s as integer rather than floating due to prototype", (char *) 0, name
, parmnum
+ 1);
1840 if (INTEGRAL_TYPE_P (type
)
1841 && TREE_CODE (TREE_TYPE (val
)) == COMPLEX_TYPE
)
1842 warn_for_assignment ("%s as integer rather than complex due to prototype", (char *) 0, name
, parmnum
+ 1);
1843 else if (TREE_CODE (type
) == COMPLEX_TYPE
1844 && TREE_CODE (TREE_TYPE (val
)) == REAL_TYPE
)
1845 warn_for_assignment ("%s as complex rather than floating due to prototype", (char *) 0, name
, parmnum
+ 1);
1846 else if (TREE_CODE (type
) == REAL_TYPE
1847 && INTEGRAL_TYPE_P (TREE_TYPE (val
)))
1848 warn_for_assignment ("%s as floating rather than integer due to prototype", (char *) 0, name
, parmnum
+ 1);
1849 else if (TREE_CODE (type
) == COMPLEX_TYPE
1850 && INTEGRAL_TYPE_P (TREE_TYPE (val
)))
1851 warn_for_assignment ("%s as complex rather than integer due to prototype", (char *) 0, name
, parmnum
+ 1);
1852 else if (TREE_CODE (type
) == REAL_TYPE
1853 && TREE_CODE (TREE_TYPE (val
)) == COMPLEX_TYPE
)
1854 warn_for_assignment ("%s as floating rather than complex due to prototype", (char *) 0, name
, parmnum
+ 1);
1855 /* ??? At some point, messages should be written about
1856 conversions between complex types, but that's too messy
1858 else if (TREE_CODE (type
) == REAL_TYPE
1859 && TREE_CODE (TREE_TYPE (val
)) == REAL_TYPE
)
1861 /* Warn if any argument is passed as `float',
1862 since without a prototype it would be `double'. */
1863 if (formal_prec
== TYPE_PRECISION (float_type_node
))
1864 warn_for_assignment ("%s as `float' rather than `double' due to prototype", (char *) 0, name
, parmnum
+ 1);
1866 /* Detect integer changing in width or signedness.
1867 These warnings are only activated with
1868 -Wconversion, not with -Wtraditional. */
1869 else if (warn_conversion
&& INTEGRAL_TYPE_P (type
)
1870 && INTEGRAL_TYPE_P (TREE_TYPE (val
)))
1872 tree would_have_been
= default_conversion (val
);
1873 tree type1
= TREE_TYPE (would_have_been
);
1875 if (TREE_CODE (type
) == ENUMERAL_TYPE
1876 && (TYPE_MAIN_VARIANT (type
)
1877 == TYPE_MAIN_VARIANT (TREE_TYPE (val
))))
1878 /* No warning if function asks for enum
1879 and the actual arg is that enum type. */
1881 else if (formal_prec
!= TYPE_PRECISION (type1
))
1882 warn_for_assignment ("%s with different width due to prototype", (char *) 0, name
, parmnum
+ 1);
1883 else if (TREE_UNSIGNED (type
) == TREE_UNSIGNED (type1
))
1885 /* Don't complain if the formal parameter type
1886 is an enum, because we can't tell now whether
1887 the value was an enum--even the same enum. */
1888 else if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1890 else if (TREE_CODE (val
) == INTEGER_CST
1891 && int_fits_type_p (val
, type
))
1892 /* Change in signedness doesn't matter
1893 if a constant value is unaffected. */
1895 /* Likewise for a constant in a NOP_EXPR. */
1896 else if (TREE_CODE (val
) == NOP_EXPR
1897 && TREE_CODE (TREE_OPERAND (val
, 0)) == INTEGER_CST
1898 && int_fits_type_p (TREE_OPERAND (val
, 0), type
))
1900 /* If the value is extended from a narrower
1901 unsigned type, it doesn't matter whether we
1902 pass it as signed or unsigned; the value
1903 certainly is the same either way. */
1904 else if (TYPE_PRECISION (TREE_TYPE (val
)) < TYPE_PRECISION (type
)
1905 && TREE_UNSIGNED (TREE_TYPE (val
)))
1907 else if (TREE_UNSIGNED (type
))
1908 warn_for_assignment ("%s as unsigned due to prototype", (char *) 0, name
, parmnum
+ 1);
1910 warn_for_assignment ("%s as signed due to prototype", (char *) 0, name
, parmnum
+ 1);
1914 parmval
= convert_for_assignment (type
, val
,
1915 (char *) 0, /* arg passing */
1916 fundecl
, name
, parmnum
+ 1);
1918 if (targetm
.calls
.promote_prototypes (fundecl
? TREE_TYPE (fundecl
) : 0)
1919 && INTEGRAL_TYPE_P (type
)
1920 && (TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
)))
1921 parmval
= default_conversion (parmval
);
1923 result
= tree_cons (NULL_TREE
, parmval
, result
);
1925 else if (TREE_CODE (TREE_TYPE (val
)) == REAL_TYPE
1926 && (TYPE_PRECISION (TREE_TYPE (val
))
1927 < TYPE_PRECISION (double_type_node
)))
1928 /* Convert `float' to `double'. */
1929 result
= tree_cons (NULL_TREE
, convert (double_type_node
, val
), result
);
1931 /* Convert `short' and `char' to full-size `int'. */
1932 result
= tree_cons (NULL_TREE
, default_conversion (val
), result
);
1935 typetail
= TREE_CHAIN (typetail
);
1938 if (typetail
!= 0 && TREE_VALUE (typetail
) != void_type_node
)
1941 error ("too few arguments to function `%s'",
1942 IDENTIFIER_POINTER (name
));
1944 error ("too few arguments to function");
1947 return nreverse (result
);
1950 /* This is the entry point used by the parser
1951 for binary operators in the input.
1952 In addition to constructing the expression,
1953 we check for operands that were written with other binary operators
1954 in a way that is likely to confuse the user. */
1957 parser_build_binary_op (enum tree_code code
, tree arg1
, tree arg2
)
1959 tree result
= build_binary_op (code
, arg1
, arg2
, 1);
1962 char class1
= TREE_CODE_CLASS (TREE_CODE (arg1
));
1963 char class2
= TREE_CODE_CLASS (TREE_CODE (arg2
));
1964 enum tree_code code1
= ERROR_MARK
;
1965 enum tree_code code2
= ERROR_MARK
;
1967 if (TREE_CODE (result
) == ERROR_MARK
)
1968 return error_mark_node
;
1970 if (IS_EXPR_CODE_CLASS (class1
))
1971 code1
= C_EXP_ORIGINAL_CODE (arg1
);
1972 if (IS_EXPR_CODE_CLASS (class2
))
1973 code2
= C_EXP_ORIGINAL_CODE (arg2
);
1975 /* Check for cases such as x+y<<z which users are likely
1976 to misinterpret. If parens are used, C_EXP_ORIGINAL_CODE
1977 is cleared to prevent these warnings. */
1978 if (warn_parentheses
)
1980 if (code
== LSHIFT_EXPR
|| code
== RSHIFT_EXPR
)
1982 if (code1
== PLUS_EXPR
|| code1
== MINUS_EXPR
1983 || code2
== PLUS_EXPR
|| code2
== MINUS_EXPR
)
1984 warning ("suggest parentheses around + or - inside shift");
1987 if (code
== TRUTH_ORIF_EXPR
)
1989 if (code1
== TRUTH_ANDIF_EXPR
1990 || code2
== TRUTH_ANDIF_EXPR
)
1991 warning ("suggest parentheses around && within ||");
1994 if (code
== BIT_IOR_EXPR
)
1996 if (code1
== BIT_AND_EXPR
|| code1
== BIT_XOR_EXPR
1997 || code1
== PLUS_EXPR
|| code1
== MINUS_EXPR
1998 || code2
== BIT_AND_EXPR
|| code2
== BIT_XOR_EXPR
1999 || code2
== PLUS_EXPR
|| code2
== MINUS_EXPR
)
2000 warning ("suggest parentheses around arithmetic in operand of |");
2001 /* Check cases like x|y==z */
2002 if (TREE_CODE_CLASS (code1
) == '<' || TREE_CODE_CLASS (code2
) == '<')
2003 warning ("suggest parentheses around comparison in operand of |");
2006 if (code
== BIT_XOR_EXPR
)
2008 if (code1
== BIT_AND_EXPR
2009 || code1
== PLUS_EXPR
|| code1
== MINUS_EXPR
2010 || code2
== BIT_AND_EXPR
2011 || code2
== PLUS_EXPR
|| code2
== MINUS_EXPR
)
2012 warning ("suggest parentheses around arithmetic in operand of ^");
2013 /* Check cases like x^y==z */
2014 if (TREE_CODE_CLASS (code1
) == '<' || TREE_CODE_CLASS (code2
) == '<')
2015 warning ("suggest parentheses around comparison in operand of ^");
2018 if (code
== BIT_AND_EXPR
)
2020 if (code1
== PLUS_EXPR
|| code1
== MINUS_EXPR
2021 || code2
== PLUS_EXPR
|| code2
== MINUS_EXPR
)
2022 warning ("suggest parentheses around + or - in operand of &");
2023 /* Check cases like x&y==z */
2024 if (TREE_CODE_CLASS (code1
) == '<' || TREE_CODE_CLASS (code2
) == '<')
2025 warning ("suggest parentheses around comparison in operand of &");
2029 /* Similarly, check for cases like 1<=i<=10 that are probably errors. */
2030 if (TREE_CODE_CLASS (code
) == '<' && extra_warnings
2031 && (TREE_CODE_CLASS (code1
) == '<' || TREE_CODE_CLASS (code2
) == '<'))
2032 warning ("comparisons like X<=Y<=Z do not have their mathematical meaning");
2034 unsigned_conversion_warning (result
, arg1
);
2035 unsigned_conversion_warning (result
, arg2
);
2036 overflow_warning (result
);
2038 class = TREE_CODE_CLASS (TREE_CODE (result
));
2040 /* Record the code that was specified in the source,
2041 for the sake of warnings about confusing nesting. */
2042 if (IS_EXPR_CODE_CLASS (class))
2043 C_SET_EXP_ORIGINAL_CODE (result
, code
);
2046 int flag
= TREE_CONSTANT (result
);
2047 /* We used to use NOP_EXPR rather than NON_LVALUE_EXPR
2048 so that convert_for_assignment wouldn't strip it.
2049 That way, we got warnings for things like p = (1 - 1).
2050 But it turns out we should not get those warnings. */
2051 result
= build1 (NON_LVALUE_EXPR
, TREE_TYPE (result
), result
);
2052 C_SET_EXP_ORIGINAL_CODE (result
, code
);
2053 TREE_CONSTANT (result
) = flag
;
2060 /* Return true if `t' is known to be non-negative. */
2063 c_tree_expr_nonnegative_p (tree t
)
2065 if (TREE_CODE (t
) == STMT_EXPR
)
2067 t
= COMPOUND_BODY (STMT_EXPR_STMT (t
));
2069 /* Find the last statement in the chain, ignoring the final
2070 * scope statement */
2071 while (TREE_CHAIN (t
) != NULL_TREE
2072 && TREE_CODE (TREE_CHAIN (t
)) != SCOPE_STMT
)
2074 return tree_expr_nonnegative_p (TREE_OPERAND (t
, 0));
2076 return tree_expr_nonnegative_p (t
);
2079 /* Return a tree for the difference of pointers OP0 and OP1.
2080 The resulting tree has type int. */
2083 pointer_diff (tree op0
, tree op1
)
2085 tree result
, folded
;
2086 tree restype
= ptrdiff_type_node
;
2088 tree target_type
= TREE_TYPE (TREE_TYPE (op0
));
2089 tree con0
, con1
, lit0
, lit1
;
2090 tree orig_op1
= op1
;
2092 if (pedantic
|| warn_pointer_arith
)
2094 if (TREE_CODE (target_type
) == VOID_TYPE
)
2095 pedwarn ("pointer of type `void *' used in subtraction");
2096 if (TREE_CODE (target_type
) == FUNCTION_TYPE
)
2097 pedwarn ("pointer to a function used in subtraction");
2100 /* If the conversion to ptrdiff_type does anything like widening or
2101 converting a partial to an integral mode, we get a convert_expression
2102 that is in the way to do any simplifications.
2103 (fold-const.c doesn't know that the extra bits won't be needed.
2104 split_tree uses STRIP_SIGN_NOPS, which leaves conversions to a
2105 different mode in place.)
2106 So first try to find a common term here 'by hand'; we want to cover
2107 at least the cases that occur in legal static initializers. */
2108 con0
= TREE_CODE (op0
) == NOP_EXPR
? TREE_OPERAND (op0
, 0) : op0
;
2109 con1
= TREE_CODE (op1
) == NOP_EXPR
? TREE_OPERAND (op1
, 0) : op1
;
2111 if (TREE_CODE (con0
) == PLUS_EXPR
)
2113 lit0
= TREE_OPERAND (con0
, 1);
2114 con0
= TREE_OPERAND (con0
, 0);
2117 lit0
= integer_zero_node
;
2119 if (TREE_CODE (con1
) == PLUS_EXPR
)
2121 lit1
= TREE_OPERAND (con1
, 1);
2122 con1
= TREE_OPERAND (con1
, 0);
2125 lit1
= integer_zero_node
;
2127 if (operand_equal_p (con0
, con1
, 0))
2134 /* First do the subtraction as integers;
2135 then drop through to build the divide operator.
2136 Do not do default conversions on the minus operator
2137 in case restype is a short type. */
2139 op0
= build_binary_op (MINUS_EXPR
, convert (restype
, op0
),
2140 convert (restype
, op1
), 0);
2141 /* This generates an error if op1 is pointer to incomplete type. */
2142 if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (orig_op1
))))
2143 error ("arithmetic on pointer to an incomplete type");
2145 /* This generates an error if op0 is pointer to incomplete type. */
2146 op1
= c_size_in_bytes (target_type
);
2148 /* Divide by the size, in easiest possible way. */
2150 result
= build (EXACT_DIV_EXPR
, restype
, op0
, convert (restype
, op1
));
2152 folded
= fold (result
);
2153 if (folded
== result
)
2154 TREE_CONSTANT (folded
) = TREE_CONSTANT (op0
) & TREE_CONSTANT (op1
);
2158 /* Construct and perhaps optimize a tree representation
2159 for a unary operation. CODE, a tree_code, specifies the operation
2160 and XARG is the operand.
2161 For any CODE other than ADDR_EXPR, FLAG nonzero suppresses
2162 the default promotions (such as from short to int).
2163 For ADDR_EXPR, the default promotions are not applied; FLAG nonzero
2164 allows non-lvalues; this is only used to handle conversion of non-lvalue
2165 arrays to pointers in C99. */
2168 build_unary_op (enum tree_code code
, tree xarg
, int flag
)
2170 /* No default_conversion here. It causes trouble for ADDR_EXPR. */
2173 enum tree_code typecode
= TREE_CODE (TREE_TYPE (arg
));
2175 int noconvert
= flag
;
2177 if (typecode
== ERROR_MARK
)
2178 return error_mark_node
;
2179 if (typecode
== ENUMERAL_TYPE
|| typecode
== BOOLEAN_TYPE
)
2180 typecode
= INTEGER_TYPE
;
2185 /* This is used for unary plus, because a CONVERT_EXPR
2186 is enough to prevent anybody from looking inside for
2187 associativity, but won't generate any code. */
2188 if (!(typecode
== INTEGER_TYPE
|| typecode
== REAL_TYPE
2189 || typecode
== COMPLEX_TYPE
))
2191 error ("wrong type argument to unary plus");
2192 return error_mark_node
;
2194 else if (!noconvert
)
2195 arg
= default_conversion (arg
);
2196 arg
= non_lvalue (arg
);
2200 if (!(typecode
== INTEGER_TYPE
|| typecode
== REAL_TYPE
2201 || typecode
== COMPLEX_TYPE
2202 || typecode
== VECTOR_TYPE
))
2204 error ("wrong type argument to unary minus");
2205 return error_mark_node
;
2207 else if (!noconvert
)
2208 arg
= default_conversion (arg
);
2212 if (typecode
== INTEGER_TYPE
|| typecode
== VECTOR_TYPE
)
2215 arg
= default_conversion (arg
);
2217 else if (typecode
== COMPLEX_TYPE
)
2221 pedwarn ("ISO C does not support `~' for complex conjugation");
2223 arg
= default_conversion (arg
);
2227 error ("wrong type argument to bit-complement");
2228 return error_mark_node
;
2233 if (!(typecode
== INTEGER_TYPE
|| typecode
== REAL_TYPE
))
2235 error ("wrong type argument to abs");
2236 return error_mark_node
;
2238 else if (!noconvert
)
2239 arg
= default_conversion (arg
);
2243 /* Conjugating a real value is a no-op, but allow it anyway. */
2244 if (!(typecode
== INTEGER_TYPE
|| typecode
== REAL_TYPE
2245 || typecode
== COMPLEX_TYPE
))
2247 error ("wrong type argument to conjugation");
2248 return error_mark_node
;
2250 else if (!noconvert
)
2251 arg
= default_conversion (arg
);
2254 case TRUTH_NOT_EXPR
:
2255 if (typecode
!= INTEGER_TYPE
2256 && typecode
!= REAL_TYPE
&& typecode
!= POINTER_TYPE
2257 && typecode
!= COMPLEX_TYPE
2258 /* These will convert to a pointer. */
2259 && typecode
!= ARRAY_TYPE
&& typecode
!= FUNCTION_TYPE
)
2261 error ("wrong type argument to unary exclamation mark");
2262 return error_mark_node
;
2264 arg
= c_common_truthvalue_conversion (arg
);
2265 return invert_truthvalue (arg
);
2271 if (TREE_CODE (arg
) == COMPLEX_CST
)
2272 return TREE_REALPART (arg
);
2273 else if (TREE_CODE (TREE_TYPE (arg
)) == COMPLEX_TYPE
)
2274 return fold (build1 (REALPART_EXPR
, TREE_TYPE (TREE_TYPE (arg
)), arg
));
2279 if (TREE_CODE (arg
) == COMPLEX_CST
)
2280 return TREE_IMAGPART (arg
);
2281 else if (TREE_CODE (TREE_TYPE (arg
)) == COMPLEX_TYPE
)
2282 return fold (build1 (IMAGPART_EXPR
, TREE_TYPE (TREE_TYPE (arg
)), arg
));
2284 return convert (TREE_TYPE (arg
), integer_zero_node
);
2286 case PREINCREMENT_EXPR
:
2287 case POSTINCREMENT_EXPR
:
2288 case PREDECREMENT_EXPR
:
2289 case POSTDECREMENT_EXPR
:
2290 /* Handle complex lvalues (when permitted)
2291 by reduction to simpler cases. */
2293 val
= unary_complex_lvalue (code
, arg
, 0);
2297 /* Increment or decrement the real part of the value,
2298 and don't change the imaginary part. */
2299 if (typecode
== COMPLEX_TYPE
)
2304 pedwarn ("ISO C does not support `++' and `--' on complex types");
2306 arg
= stabilize_reference (arg
);
2307 real
= build_unary_op (REALPART_EXPR
, arg
, 1);
2308 imag
= build_unary_op (IMAGPART_EXPR
, arg
, 1);
2309 return build (COMPLEX_EXPR
, TREE_TYPE (arg
),
2310 build_unary_op (code
, real
, 1), imag
);
2313 /* Report invalid types. */
2315 if (typecode
!= POINTER_TYPE
2316 && typecode
!= INTEGER_TYPE
&& typecode
!= REAL_TYPE
)
2318 if (code
== PREINCREMENT_EXPR
|| code
== POSTINCREMENT_EXPR
)
2319 error ("wrong type argument to increment");
2321 error ("wrong type argument to decrement");
2323 return error_mark_node
;
2328 tree result_type
= TREE_TYPE (arg
);
2330 arg
= get_unwidened (arg
, 0);
2331 argtype
= TREE_TYPE (arg
);
2333 /* Compute the increment. */
2335 if (typecode
== POINTER_TYPE
)
2337 /* If pointer target is an undefined struct,
2338 we just cannot know how to do the arithmetic. */
2339 if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (result_type
)))
2341 if (code
== PREINCREMENT_EXPR
|| code
== POSTINCREMENT_EXPR
)
2342 error ("increment of pointer to unknown structure");
2344 error ("decrement of pointer to unknown structure");
2346 else if ((pedantic
|| warn_pointer_arith
)
2347 && (TREE_CODE (TREE_TYPE (result_type
)) == FUNCTION_TYPE
2348 || TREE_CODE (TREE_TYPE (result_type
)) == VOID_TYPE
))
2350 if (code
== PREINCREMENT_EXPR
|| code
== POSTINCREMENT_EXPR
)
2351 pedwarn ("wrong type argument to increment");
2353 pedwarn ("wrong type argument to decrement");
2356 inc
= c_size_in_bytes (TREE_TYPE (result_type
));
2359 inc
= integer_one_node
;
2361 inc
= convert (argtype
, inc
);
2363 /* Handle incrementing a cast-expression. */
2366 switch (TREE_CODE (arg
))
2371 case FIX_TRUNC_EXPR
:
2372 case FIX_FLOOR_EXPR
:
2373 case FIX_ROUND_EXPR
:
2375 pedantic_lvalue_warning (CONVERT_EXPR
);
2376 /* If the real type has the same machine representation
2377 as the type it is cast to, we can make better output
2378 by adding directly to the inside of the cast. */
2379 if ((TREE_CODE (TREE_TYPE (arg
))
2380 == TREE_CODE (TREE_TYPE (TREE_OPERAND (arg
, 0))))
2381 && (TYPE_MODE (TREE_TYPE (arg
))
2382 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (arg
, 0)))))
2383 arg
= TREE_OPERAND (arg
, 0);
2386 tree incremented
, modify
, value
;
2387 if (TREE_CODE (TREE_TYPE (arg
)) == BOOLEAN_TYPE
)
2388 value
= boolean_increment (code
, arg
);
2391 arg
= stabilize_reference (arg
);
2392 if (code
== PREINCREMENT_EXPR
|| code
== PREDECREMENT_EXPR
)
2395 value
= save_expr (arg
);
2396 incremented
= build (((code
== PREINCREMENT_EXPR
2397 || code
== POSTINCREMENT_EXPR
)
2398 ? PLUS_EXPR
: MINUS_EXPR
),
2399 argtype
, value
, inc
);
2400 TREE_SIDE_EFFECTS (incremented
) = 1;
2401 modify
= build_modify_expr (arg
, NOP_EXPR
, incremented
);
2402 value
= build (COMPOUND_EXPR
, TREE_TYPE (arg
), modify
, value
);
2404 TREE_USED (value
) = 1;
2414 /* Complain about anything else that is not a true lvalue. */
2415 if (!lvalue_or_else (arg
, ((code
== PREINCREMENT_EXPR
2416 || code
== POSTINCREMENT_EXPR
)
2417 ? "invalid lvalue in increment"
2418 : "invalid lvalue in decrement")))
2419 return error_mark_node
;
2421 /* Report a read-only lvalue. */
2422 if (TREE_READONLY (arg
))
2423 readonly_warning (arg
,
2424 ((code
== PREINCREMENT_EXPR
2425 || code
== POSTINCREMENT_EXPR
)
2426 ? "increment" : "decrement"));
2428 if (TREE_CODE (TREE_TYPE (arg
)) == BOOLEAN_TYPE
)
2429 val
= boolean_increment (code
, arg
);
2431 val
= build (code
, TREE_TYPE (arg
), arg
, inc
);
2432 TREE_SIDE_EFFECTS (val
) = 1;
2433 val
= convert (result_type
, val
);
2434 if (TREE_CODE (val
) != code
)
2435 TREE_NO_UNUSED_WARNING (val
) = 1;
2440 /* Note that this operation never does default_conversion. */
2442 /* Let &* cancel out to simplify resulting code. */
2443 if (TREE_CODE (arg
) == INDIRECT_REF
)
2445 /* Don't let this be an lvalue. */
2446 if (lvalue_p (TREE_OPERAND (arg
, 0)))
2447 return non_lvalue (TREE_OPERAND (arg
, 0));
2448 return TREE_OPERAND (arg
, 0);
2451 /* For &x[y], return x+y */
2452 if (TREE_CODE (arg
) == ARRAY_REF
)
2454 if (!c_mark_addressable (TREE_OPERAND (arg
, 0)))
2455 return error_mark_node
;
2456 return build_binary_op (PLUS_EXPR
, TREE_OPERAND (arg
, 0),
2457 TREE_OPERAND (arg
, 1), 1);
2460 /* Handle complex lvalues (when permitted)
2461 by reduction to simpler cases. */
2462 val
= unary_complex_lvalue (code
, arg
, flag
);
2466 /* Anything not already handled and not a true memory reference
2467 or a non-lvalue array is an error. */
2468 else if (typecode
!= FUNCTION_TYPE
&& !flag
2469 && !lvalue_or_else (arg
, "invalid lvalue in unary `&'"))
2470 return error_mark_node
;
2472 /* Ordinary case; arg is a COMPONENT_REF or a decl. */
2473 argtype
= TREE_TYPE (arg
);
2475 /* If the lvalue is const or volatile, merge that into the type
2476 to which the address will point. Note that you can't get a
2477 restricted pointer by taking the address of something, so we
2478 only have to deal with `const' and `volatile' here. */
2479 if ((DECL_P (arg
) || TREE_CODE_CLASS (TREE_CODE (arg
)) == 'r')
2480 && (TREE_READONLY (arg
) || TREE_THIS_VOLATILE (arg
)))
2481 argtype
= c_build_type_variant (argtype
,
2482 TREE_READONLY (arg
),
2483 TREE_THIS_VOLATILE (arg
));
2485 argtype
= build_pointer_type (argtype
);
2487 if (!c_mark_addressable (arg
))
2488 return error_mark_node
;
2493 if (TREE_CODE (arg
) == COMPONENT_REF
)
2495 tree field
= TREE_OPERAND (arg
, 1);
2497 addr
= build_unary_op (ADDR_EXPR
, TREE_OPERAND (arg
, 0), flag
);
2499 if (DECL_C_BIT_FIELD (field
))
2501 error ("attempt to take address of bit-field structure member `%s'",
2502 IDENTIFIER_POINTER (DECL_NAME (field
)));
2503 return error_mark_node
;
2506 addr
= fold (build (PLUS_EXPR
, argtype
,
2507 convert (argtype
, addr
),
2508 convert (argtype
, byte_position (field
))));
2511 addr
= build1 (code
, argtype
, arg
);
2513 /* Address of a static or external variable or
2514 file-scope function counts as a constant. */
2516 && ! (TREE_CODE (arg
) == FUNCTION_DECL
2517 && !DECL_FILE_SCOPE_P (arg
)))
2518 TREE_CONSTANT (addr
) = 1;
2527 argtype
= TREE_TYPE (arg
);
2528 return fold (build1 (code
, argtype
, arg
));
2531 /* Return nonzero if REF is an lvalue valid for this language.
2532 Lvalues can be assigned, unless their type has TYPE_READONLY.
2533 Lvalues can have their address taken, unless they have DECL_REGISTER. */
2538 enum tree_code code
= TREE_CODE (ref
);
2545 return lvalue_p (TREE_OPERAND (ref
, 0));
2547 case COMPOUND_LITERAL_EXPR
:
2557 return (TREE_CODE (TREE_TYPE (ref
)) != FUNCTION_TYPE
2558 && TREE_CODE (TREE_TYPE (ref
)) != METHOD_TYPE
);
2562 return TREE_CODE (TREE_TYPE (ref
)) == ARRAY_TYPE
;
2569 /* Return nonzero if REF is an lvalue valid for this language;
2570 otherwise, print an error message and return zero. */
2573 lvalue_or_else (tree ref
, const char *msgid
)
2575 int win
= lvalue_p (ref
);
2578 error ("%s", msgid
);
2583 /* Apply unary lvalue-demanding operator CODE to the expression ARG
2584 for certain kinds of expressions which are not really lvalues
2585 but which we can accept as lvalues. If FLAG is nonzero, then
2586 non-lvalues are OK since we may be converting a non-lvalue array to
2589 If ARG is not a kind of expression we can handle, return zero. */
2592 unary_complex_lvalue (enum tree_code code
, tree arg
, int flag
)
2594 /* Handle (a, b) used as an "lvalue". */
2595 if (TREE_CODE (arg
) == COMPOUND_EXPR
)
2597 tree real_result
= build_unary_op (code
, TREE_OPERAND (arg
, 1), 0);
2599 /* If this returns a function type, it isn't really being used as
2600 an lvalue, so don't issue a warning about it. */
2601 if (TREE_CODE (TREE_TYPE (arg
)) != FUNCTION_TYPE
&& !flag
)
2602 pedantic_lvalue_warning (COMPOUND_EXPR
);
2604 return build (COMPOUND_EXPR
, TREE_TYPE (real_result
),
2605 TREE_OPERAND (arg
, 0), real_result
);
2608 /* Handle (a ? b : c) used as an "lvalue". */
2609 if (TREE_CODE (arg
) == COND_EXPR
)
2612 pedantic_lvalue_warning (COND_EXPR
);
2613 if (TREE_CODE (TREE_TYPE (arg
)) != FUNCTION_TYPE
&& !flag
)
2614 pedantic_lvalue_warning (COMPOUND_EXPR
);
2616 return (build_conditional_expr
2617 (TREE_OPERAND (arg
, 0),
2618 build_unary_op (code
, TREE_OPERAND (arg
, 1), flag
),
2619 build_unary_op (code
, TREE_OPERAND (arg
, 2), flag
)));
2625 /* If pedantic, warn about improper lvalue. CODE is either COND_EXPR
2626 COMPOUND_EXPR, or CONVERT_EXPR (for casts). */
2629 pedantic_lvalue_warning (enum tree_code code
)
2634 pedwarn ("use of conditional expressions as lvalues is deprecated");
2637 pedwarn ("use of compound expressions as lvalues is deprecated");
2640 pedwarn ("use of cast expressions as lvalues is deprecated");
2645 /* Warn about storing in something that is `const'. */
2648 readonly_warning (tree arg
, const char *msgid
)
2650 if (TREE_CODE (arg
) == COMPONENT_REF
)
2652 if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg
, 0))))
2653 readonly_warning (TREE_OPERAND (arg
, 0), msgid
);
2655 pedwarn ("%s of read-only member `%s'", _(msgid
),
2656 IDENTIFIER_POINTER (DECL_NAME (TREE_OPERAND (arg
, 1))));
2658 else if (TREE_CODE (arg
) == VAR_DECL
)
2659 pedwarn ("%s of read-only variable `%s'", _(msgid
),
2660 IDENTIFIER_POINTER (DECL_NAME (arg
)));
2662 pedwarn ("%s of read-only location", _(msgid
));
2665 /* Mark EXP saying that we need to be able to take the
2666 address of it; it should not be allocated in a register.
2667 Returns true if successful. */
2670 c_mark_addressable (tree exp
)
2675 switch (TREE_CODE (x
))
2678 if (DECL_C_BIT_FIELD (TREE_OPERAND (x
, 1)))
2680 error ("cannot take address of bit-field `%s'",
2681 IDENTIFIER_POINTER (DECL_NAME (TREE_OPERAND (x
, 1))));
2685 /* ... fall through ... */
2691 x
= TREE_OPERAND (x
, 0);
2694 case COMPOUND_LITERAL_EXPR
:
2696 TREE_ADDRESSABLE (x
) = 1;
2703 if (DECL_REGISTER (x
) && !TREE_ADDRESSABLE (x
)
2704 && DECL_NONLOCAL (x
))
2706 if (TREE_PUBLIC (x
))
2708 error ("global register variable `%s' used in nested function",
2709 IDENTIFIER_POINTER (DECL_NAME (x
)));
2712 pedwarn ("register variable `%s' used in nested function",
2713 IDENTIFIER_POINTER (DECL_NAME (x
)));
2715 else if (DECL_REGISTER (x
) && !TREE_ADDRESSABLE (x
))
2717 if (TREE_PUBLIC (x
))
2719 error ("address of global register variable `%s' requested",
2720 IDENTIFIER_POINTER (DECL_NAME (x
)));
2724 /* If we are making this addressable due to its having
2725 volatile components, give a different error message. Also
2726 handle the case of an unnamed parameter by not trying
2727 to give the name. */
2729 else if (C_TYPE_FIELDS_VOLATILE (TREE_TYPE (x
)))
2731 error ("cannot put object with volatile field into register");
2735 pedwarn ("address of register variable `%s' requested",
2736 IDENTIFIER_POINTER (DECL_NAME (x
)));
2738 put_var_into_stack (x
, /*rescan=*/true);
2742 TREE_ADDRESSABLE (x
) = 1;
2749 /* Build and return a conditional expression IFEXP ? OP1 : OP2. */
2752 build_conditional_expr (tree ifexp
, tree op1
, tree op2
)
2756 enum tree_code code1
;
2757 enum tree_code code2
;
2758 tree result_type
= NULL
;
2759 tree orig_op1
= op1
, orig_op2
= op2
;
2761 ifexp
= c_common_truthvalue_conversion (default_conversion (ifexp
));
2763 /* Promote both alternatives. */
2765 if (TREE_CODE (TREE_TYPE (op1
)) != VOID_TYPE
)
2766 op1
= default_conversion (op1
);
2767 if (TREE_CODE (TREE_TYPE (op2
)) != VOID_TYPE
)
2768 op2
= default_conversion (op2
);
2770 if (TREE_CODE (ifexp
) == ERROR_MARK
2771 || TREE_CODE (TREE_TYPE (op1
)) == ERROR_MARK
2772 || TREE_CODE (TREE_TYPE (op2
)) == ERROR_MARK
)
2773 return error_mark_node
;
2775 type1
= TREE_TYPE (op1
);
2776 code1
= TREE_CODE (type1
);
2777 type2
= TREE_TYPE (op2
);
2778 code2
= TREE_CODE (type2
);
2780 /* Quickly detect the usual case where op1 and op2 have the same type
2782 if (TYPE_MAIN_VARIANT (type1
) == TYPE_MAIN_VARIANT (type2
))
2785 result_type
= type1
;
2787 result_type
= TYPE_MAIN_VARIANT (type1
);
2789 else if ((code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
2790 || code1
== COMPLEX_TYPE
)
2791 && (code2
== INTEGER_TYPE
|| code2
== REAL_TYPE
2792 || code2
== COMPLEX_TYPE
))
2794 result_type
= common_type (type1
, type2
);
2796 /* If -Wsign-compare, warn here if type1 and type2 have
2797 different signedness. We'll promote the signed to unsigned
2798 and later code won't know it used to be different.
2799 Do this check on the original types, so that explicit casts
2800 will be considered, but default promotions won't. */
2801 if (warn_sign_compare
&& !skip_evaluation
)
2803 int unsigned_op1
= TREE_UNSIGNED (TREE_TYPE (orig_op1
));
2804 int unsigned_op2
= TREE_UNSIGNED (TREE_TYPE (orig_op2
));
2806 if (unsigned_op1
^ unsigned_op2
)
2808 /* Do not warn if the result type is signed, since the
2809 signed type will only be chosen if it can represent
2810 all the values of the unsigned type. */
2811 if (! TREE_UNSIGNED (result_type
))
2813 /* Do not warn if the signed quantity is an unsuffixed
2814 integer literal (or some static constant expression
2815 involving such literals) and it is non-negative. */
2816 else if ((unsigned_op2
&& c_tree_expr_nonnegative_p (op1
))
2817 || (unsigned_op1
&& c_tree_expr_nonnegative_p (op2
)))
2820 warning ("signed and unsigned type in conditional expression");
2824 else if (code1
== VOID_TYPE
|| code2
== VOID_TYPE
)
2826 if (pedantic
&& (code1
!= VOID_TYPE
|| code2
!= VOID_TYPE
))
2827 pedwarn ("ISO C forbids conditional expr with only one void side");
2828 result_type
= void_type_node
;
2830 else if (code1
== POINTER_TYPE
&& code2
== POINTER_TYPE
)
2832 if (comp_target_types (type1
, type2
, 1))
2833 result_type
= common_type (type1
, type2
);
2834 else if (integer_zerop (op1
) && TREE_TYPE (type1
) == void_type_node
2835 && TREE_CODE (orig_op1
) != NOP_EXPR
)
2836 result_type
= qualify_type (type2
, type1
);
2837 else if (integer_zerop (op2
) && TREE_TYPE (type2
) == void_type_node
2838 && TREE_CODE (orig_op2
) != NOP_EXPR
)
2839 result_type
= qualify_type (type1
, type2
);
2840 else if (VOID_TYPE_P (TREE_TYPE (type1
)))
2842 if (pedantic
&& TREE_CODE (TREE_TYPE (type2
)) == FUNCTION_TYPE
)
2843 pedwarn ("ISO C forbids conditional expr between `void *' and function pointer");
2844 result_type
= build_pointer_type (qualify_type (TREE_TYPE (type1
),
2845 TREE_TYPE (type2
)));
2847 else if (VOID_TYPE_P (TREE_TYPE (type2
)))
2849 if (pedantic
&& TREE_CODE (TREE_TYPE (type1
)) == FUNCTION_TYPE
)
2850 pedwarn ("ISO C forbids conditional expr between `void *' and function pointer");
2851 result_type
= build_pointer_type (qualify_type (TREE_TYPE (type2
),
2852 TREE_TYPE (type1
)));
2856 pedwarn ("pointer type mismatch in conditional expression");
2857 result_type
= build_pointer_type (void_type_node
);
2860 else if (code1
== POINTER_TYPE
&& code2
== INTEGER_TYPE
)
2862 if (! integer_zerop (op2
))
2863 pedwarn ("pointer/integer type mismatch in conditional expression");
2866 op2
= null_pointer_node
;
2868 result_type
= type1
;
2870 else if (code2
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
2872 if (!integer_zerop (op1
))
2873 pedwarn ("pointer/integer type mismatch in conditional expression");
2876 op1
= null_pointer_node
;
2878 result_type
= type2
;
2883 if (flag_cond_mismatch
)
2884 result_type
= void_type_node
;
2887 error ("type mismatch in conditional expression");
2888 return error_mark_node
;
2892 /* Merge const and volatile flags of the incoming types. */
2894 = build_type_variant (result_type
,
2895 TREE_READONLY (op1
) || TREE_READONLY (op2
),
2896 TREE_THIS_VOLATILE (op1
) || TREE_THIS_VOLATILE (op2
));
2898 if (result_type
!= TREE_TYPE (op1
))
2899 op1
= convert_and_check (result_type
, op1
);
2900 if (result_type
!= TREE_TYPE (op2
))
2901 op2
= convert_and_check (result_type
, op2
);
2903 if (TREE_CODE (ifexp
) == INTEGER_CST
)
2904 return pedantic_non_lvalue (integer_zerop (ifexp
) ? op2
: op1
);
2906 return fold (build (COND_EXPR
, result_type
, ifexp
, op1
, op2
));
2909 /* Given a list of expressions, return a compound expression
2910 that performs them all and returns the value of the last of them. */
2913 build_compound_expr (tree list
)
2915 return internal_build_compound_expr (list
, TRUE
);
2919 internal_build_compound_expr (tree list
, int first_p
)
2923 if (TREE_CHAIN (list
) == 0)
2925 /* Convert arrays and functions to pointers when there
2926 really is a comma operator. */
2929 = default_function_array_conversion (TREE_VALUE (list
));
2931 /* Don't let (0, 0) be null pointer constant. */
2932 if (!first_p
&& integer_zerop (TREE_VALUE (list
)))
2933 return non_lvalue (TREE_VALUE (list
));
2934 return TREE_VALUE (list
);
2937 rest
= internal_build_compound_expr (TREE_CHAIN (list
), FALSE
);
2939 if (! TREE_SIDE_EFFECTS (TREE_VALUE (list
)))
2941 /* The left-hand operand of a comma expression is like an expression
2942 statement: with -Wextra or -Wunused, we should warn if it doesn't have
2943 any side-effects, unless it was explicitly cast to (void). */
2944 if (warn_unused_value
2945 && ! (TREE_CODE (TREE_VALUE (list
)) == CONVERT_EXPR
2946 && VOID_TYPE_P (TREE_TYPE (TREE_VALUE (list
)))))
2947 warning ("left-hand operand of comma expression has no effect");
2950 /* With -Wunused, we should also warn if the left-hand operand does have
2951 side-effects, but computes a value which is not used. For example, in
2952 `foo() + bar(), baz()' the result of the `+' operator is not used,
2953 so we should issue a warning. */
2954 else if (warn_unused_value
)
2955 warn_if_unused_value (TREE_VALUE (list
));
2957 return build (COMPOUND_EXPR
, TREE_TYPE (rest
), TREE_VALUE (list
), rest
);
2960 /* Build an expression representing a cast to type TYPE of expression EXPR. */
2963 build_c_cast (tree type
, tree expr
)
2967 if (type
== error_mark_node
|| expr
== error_mark_node
)
2968 return error_mark_node
;
2970 /* The ObjC front-end uses TYPE_MAIN_VARIANT to tie together types differing
2971 only in <protocol> qualifications. But when constructing cast expressions,
2972 the protocols do matter and must be kept around. */
2973 if (!c_dialect_objc () || !objc_is_object_ptr (type
))
2974 type
= TYPE_MAIN_VARIANT (type
);
2976 if (TREE_CODE (type
) == ARRAY_TYPE
)
2978 error ("cast specifies array type");
2979 return error_mark_node
;
2982 if (TREE_CODE (type
) == FUNCTION_TYPE
)
2984 error ("cast specifies function type");
2985 return error_mark_node
;
2988 if (type
== TYPE_MAIN_VARIANT (TREE_TYPE (value
)))
2992 if (TREE_CODE (type
) == RECORD_TYPE
2993 || TREE_CODE (type
) == UNION_TYPE
)
2994 pedwarn ("ISO C forbids casting nonscalar to the same type");
2997 else if (TREE_CODE (type
) == UNION_TYPE
)
3000 value
= default_function_array_conversion (value
);
3002 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
3003 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (field
)),
3004 TYPE_MAIN_VARIANT (TREE_TYPE (value
)), COMPARE_STRICT
))
3012 pedwarn ("ISO C forbids casts to union type");
3013 t
= digest_init (type
,
3014 build_constructor (type
,
3015 build_tree_list (field
, value
)),
3017 TREE_CONSTANT (t
) = TREE_CONSTANT (value
);
3020 error ("cast to union type from type not present in union");
3021 return error_mark_node
;
3027 /* If casting to void, avoid the error that would come
3028 from default_conversion in the case of a non-lvalue array. */
3029 if (type
== void_type_node
)
3030 return build1 (CONVERT_EXPR
, type
, value
);
3032 /* Convert functions and arrays to pointers,
3033 but don't convert any other types. */
3034 value
= default_function_array_conversion (value
);
3035 otype
= TREE_TYPE (value
);
3037 /* Optionally warn about potentially worrisome casts. */
3040 && TREE_CODE (type
) == POINTER_TYPE
3041 && TREE_CODE (otype
) == POINTER_TYPE
)
3043 tree in_type
= type
;
3044 tree in_otype
= otype
;
3048 /* Check that the qualifiers on IN_TYPE are a superset of
3049 the qualifiers of IN_OTYPE. The outermost level of
3050 POINTER_TYPE nodes is uninteresting and we stop as soon
3051 as we hit a non-POINTER_TYPE node on either type. */
3054 in_otype
= TREE_TYPE (in_otype
);
3055 in_type
= TREE_TYPE (in_type
);
3057 /* GNU C allows cv-qualified function types. 'const'
3058 means the function is very pure, 'volatile' means it
3059 can't return. We need to warn when such qualifiers
3060 are added, not when they're taken away. */
3061 if (TREE_CODE (in_otype
) == FUNCTION_TYPE
3062 && TREE_CODE (in_type
) == FUNCTION_TYPE
)
3063 added
|= (TYPE_QUALS (in_type
) & ~TYPE_QUALS (in_otype
));
3065 discarded
|= (TYPE_QUALS (in_otype
) & ~TYPE_QUALS (in_type
));
3067 while (TREE_CODE (in_type
) == POINTER_TYPE
3068 && TREE_CODE (in_otype
) == POINTER_TYPE
);
3071 warning ("cast adds new qualifiers to function type");
3074 /* There are qualifiers present in IN_OTYPE that are not
3075 present in IN_TYPE. */
3076 warning ("cast discards qualifiers from pointer target type");
3079 /* Warn about possible alignment problems. */
3080 if (STRICT_ALIGNMENT
&& warn_cast_align
3081 && TREE_CODE (type
) == POINTER_TYPE
3082 && TREE_CODE (otype
) == POINTER_TYPE
3083 && TREE_CODE (TREE_TYPE (otype
)) != VOID_TYPE
3084 && TREE_CODE (TREE_TYPE (otype
)) != FUNCTION_TYPE
3085 /* Don't warn about opaque types, where the actual alignment
3086 restriction is unknown. */
3087 && !((TREE_CODE (TREE_TYPE (otype
)) == UNION_TYPE
3088 || TREE_CODE (TREE_TYPE (otype
)) == RECORD_TYPE
)
3089 && TYPE_MODE (TREE_TYPE (otype
)) == VOIDmode
)
3090 && TYPE_ALIGN (TREE_TYPE (type
)) > TYPE_ALIGN (TREE_TYPE (otype
)))
3091 warning ("cast increases required alignment of target type");
3093 if (TREE_CODE (type
) == INTEGER_TYPE
3094 && TREE_CODE (otype
) == POINTER_TYPE
3095 && TYPE_PRECISION (type
) != TYPE_PRECISION (otype
)
3096 && !TREE_CONSTANT (value
))
3097 warning ("cast from pointer to integer of different size");
3099 if (warn_bad_function_cast
3100 && TREE_CODE (value
) == CALL_EXPR
3101 && TREE_CODE (type
) != TREE_CODE (otype
))
3102 warning ("cast does not match function type");
3104 if (TREE_CODE (type
) == POINTER_TYPE
3105 && TREE_CODE (otype
) == INTEGER_TYPE
3106 && TYPE_PRECISION (type
) != TYPE_PRECISION (otype
)
3107 /* Don't warn about converting any constant. */
3108 && !TREE_CONSTANT (value
))
3109 warning ("cast to pointer from integer of different size");
3111 if (TREE_CODE (type
) == POINTER_TYPE
3112 && TREE_CODE (otype
) == POINTER_TYPE
3113 && TREE_CODE (expr
) == ADDR_EXPR
3114 && DECL_P (TREE_OPERAND (expr
, 0))
3115 && flag_strict_aliasing
&& warn_strict_aliasing
3116 && !VOID_TYPE_P (TREE_TYPE (type
)))
3118 /* Casting the address of a decl to non void pointer. Warn
3119 if the cast breaks type based aliasing. */
3120 if (!COMPLETE_TYPE_P (TREE_TYPE (type
)))
3121 warning ("type-punning to incomplete type might break strict-aliasing rules");
3122 else if (!alias_sets_conflict_p
3123 (get_alias_set (TREE_TYPE (TREE_OPERAND (expr
, 0))),
3124 get_alias_set (TREE_TYPE (type
))))
3125 warning ("dereferencing type-punned pointer will break strict-aliasing rules");
3128 /* If pedantic, warn for conversions between function and object
3129 pointer types, except for converting a null pointer constant
3130 to function pointer type. */
3132 && TREE_CODE (type
) == POINTER_TYPE
3133 && TREE_CODE (otype
) == POINTER_TYPE
3134 && TREE_CODE (TREE_TYPE (otype
)) == FUNCTION_TYPE
3135 && TREE_CODE (TREE_TYPE (type
)) != FUNCTION_TYPE
)
3136 pedwarn ("ISO C forbids conversion of function pointer to object pointer type");
3139 && TREE_CODE (type
) == POINTER_TYPE
3140 && TREE_CODE (otype
) == POINTER_TYPE
3141 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
3142 && TREE_CODE (TREE_TYPE (otype
)) != FUNCTION_TYPE
3143 && !(integer_zerop (value
) && TREE_TYPE (otype
) == void_type_node
3144 && TREE_CODE (expr
) != NOP_EXPR
))
3145 pedwarn ("ISO C forbids conversion of object pointer to function pointer type");
3148 /* Replace a nonvolatile const static variable with its value. */
3149 if (optimize
&& TREE_CODE (value
) == VAR_DECL
)
3150 value
= decl_constant_value (value
);
3151 value
= convert (type
, value
);
3153 /* Ignore any integer overflow caused by the cast. */
3154 if (TREE_CODE (value
) == INTEGER_CST
)
3156 TREE_OVERFLOW (value
) = TREE_OVERFLOW (ovalue
);
3157 TREE_CONSTANT_OVERFLOW (value
) = TREE_CONSTANT_OVERFLOW (ovalue
);
3161 /* Pedantically, don't let (void *) (FOO *) 0 be a null pointer constant. */
3162 if (pedantic
&& TREE_CODE (value
) == INTEGER_CST
3163 && TREE_CODE (expr
) == INTEGER_CST
3164 && TREE_CODE (TREE_TYPE (expr
)) != INTEGER_TYPE
)
3165 value
= non_lvalue (value
);
3167 /* If pedantic, don't let a cast be an lvalue. */
3168 if (value
== expr
&& pedantic
)
3169 value
= non_lvalue (value
);
3174 /* Interpret a cast of expression EXPR to type TYPE. */
3176 c_cast_expr (tree type
, tree expr
)
3178 int saved_wsp
= warn_strict_prototypes
;
3180 /* This avoids warnings about unprototyped casts on
3181 integers. E.g. "#define SIG_DFL (void(*)())0". */
3182 if (TREE_CODE (expr
) == INTEGER_CST
)
3183 warn_strict_prototypes
= 0;
3184 type
= groktypename (type
);
3185 warn_strict_prototypes
= saved_wsp
;
3187 return build_c_cast (type
, expr
);
3191 /* Build an assignment expression of lvalue LHS from value RHS.
3192 MODIFYCODE is the code for a binary operator that we use
3193 to combine the old value of LHS with RHS to get the new value.
3194 Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment. */
3197 build_modify_expr (tree lhs
, enum tree_code modifycode
, tree rhs
)
3201 tree lhstype
= TREE_TYPE (lhs
);
3202 tree olhstype
= lhstype
;
3204 /* Types that aren't fully specified cannot be used in assignments. */
3205 lhs
= require_complete_type (lhs
);
3207 /* Avoid duplicate error messages from operands that had errors. */
3208 if (TREE_CODE (lhs
) == ERROR_MARK
|| TREE_CODE (rhs
) == ERROR_MARK
)
3209 return error_mark_node
;
3211 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
3212 /* Do not use STRIP_NOPS here. We do not want an enumerator
3213 whose value is 0 to count as a null pointer constant. */
3214 if (TREE_CODE (rhs
) == NON_LVALUE_EXPR
)
3215 rhs
= TREE_OPERAND (rhs
, 0);
3219 /* Handle control structure constructs used as "lvalues". */
3221 switch (TREE_CODE (lhs
))
3223 /* Handle (a, b) used as an "lvalue". */
3225 pedantic_lvalue_warning (COMPOUND_EXPR
);
3226 newrhs
= build_modify_expr (TREE_OPERAND (lhs
, 1), modifycode
, rhs
);
3227 if (TREE_CODE (newrhs
) == ERROR_MARK
)
3228 return error_mark_node
;
3229 return build (COMPOUND_EXPR
, lhstype
,
3230 TREE_OPERAND (lhs
, 0), newrhs
);
3232 /* Handle (a ? b : c) used as an "lvalue". */
3234 pedantic_lvalue_warning (COND_EXPR
);
3235 rhs
= save_expr (rhs
);
3237 /* Produce (a ? (b = rhs) : (c = rhs))
3238 except that the RHS goes through a save-expr
3239 so the code to compute it is only emitted once. */
3241 = build_conditional_expr (TREE_OPERAND (lhs
, 0),
3242 build_modify_expr (TREE_OPERAND (lhs
, 1),
3244 build_modify_expr (TREE_OPERAND (lhs
, 2),
3246 if (TREE_CODE (cond
) == ERROR_MARK
)
3248 /* Make sure the code to compute the rhs comes out
3249 before the split. */
3250 return build (COMPOUND_EXPR
, TREE_TYPE (lhs
),
3251 /* But cast it to void to avoid an "unused" error. */
3252 convert (void_type_node
, rhs
), cond
);
3258 /* If a binary op has been requested, combine the old LHS value with the RHS
3259 producing the value we should actually store into the LHS. */
3261 if (modifycode
!= NOP_EXPR
)
3263 lhs
= stabilize_reference (lhs
);
3264 newrhs
= build_binary_op (modifycode
, lhs
, rhs
, 1);
3267 /* Handle a cast used as an "lvalue".
3268 We have already performed any binary operator using the value as cast.
3269 Now convert the result to the cast type of the lhs,
3270 and then true type of the lhs and store it there;
3271 then convert result back to the cast type to be the value
3272 of the assignment. */
3274 switch (TREE_CODE (lhs
))
3279 case FIX_TRUNC_EXPR
:
3280 case FIX_FLOOR_EXPR
:
3281 case FIX_ROUND_EXPR
:
3283 newrhs
= default_function_array_conversion (newrhs
);
3285 tree inner_lhs
= TREE_OPERAND (lhs
, 0);
3287 result
= build_modify_expr (inner_lhs
, NOP_EXPR
,
3288 convert (TREE_TYPE (inner_lhs
),
3289 convert (lhstype
, newrhs
)));
3290 if (TREE_CODE (result
) == ERROR_MARK
)
3292 pedantic_lvalue_warning (CONVERT_EXPR
);
3293 return convert (TREE_TYPE (lhs
), result
);
3300 /* Now we have handled acceptable kinds of LHS that are not truly lvalues.
3301 Reject anything strange now. */
3303 if (!lvalue_or_else (lhs
, "invalid lvalue in assignment"))
3304 return error_mark_node
;
3306 /* Warn about storing in something that is `const'. */
3308 if (TREE_READONLY (lhs
) || TYPE_READONLY (lhstype
)
3309 || ((TREE_CODE (lhstype
) == RECORD_TYPE
3310 || TREE_CODE (lhstype
) == UNION_TYPE
)
3311 && C_TYPE_FIELDS_READONLY (lhstype
)))
3312 readonly_warning (lhs
, "assignment");
3314 /* If storing into a structure or union member,
3315 it has probably been given type `int'.
3316 Compute the type that would go with
3317 the actual amount of storage the member occupies. */
3319 if (TREE_CODE (lhs
) == COMPONENT_REF
3320 && (TREE_CODE (lhstype
) == INTEGER_TYPE
3321 || TREE_CODE (lhstype
) == BOOLEAN_TYPE
3322 || TREE_CODE (lhstype
) == REAL_TYPE
3323 || TREE_CODE (lhstype
) == ENUMERAL_TYPE
))
3324 lhstype
= TREE_TYPE (get_unwidened (lhs
, 0));
3326 /* If storing in a field that is in actuality a short or narrower than one,
3327 we must store in the field in its actual type. */
3329 if (lhstype
!= TREE_TYPE (lhs
))
3331 lhs
= copy_node (lhs
);
3332 TREE_TYPE (lhs
) = lhstype
;
3335 /* Convert new value to destination type. */
3337 newrhs
= convert_for_assignment (lhstype
, newrhs
, _("assignment"),
3338 NULL_TREE
, NULL_TREE
, 0);
3339 if (TREE_CODE (newrhs
) == ERROR_MARK
)
3340 return error_mark_node
;
3344 result
= build (MODIFY_EXPR
, lhstype
, lhs
, newrhs
);
3345 TREE_SIDE_EFFECTS (result
) = 1;
3347 /* If we got the LHS in a different type for storing in,
3348 convert the result back to the nominal type of LHS
3349 so that the value we return always has the same type
3350 as the LHS argument. */
3352 if (olhstype
== TREE_TYPE (result
))
3354 return convert_for_assignment (olhstype
, result
, _("assignment"),
3355 NULL_TREE
, NULL_TREE
, 0);
3358 /* Convert value RHS to type TYPE as preparation for an assignment
3359 to an lvalue of type TYPE.
3360 The real work of conversion is done by `convert'.
3361 The purpose of this function is to generate error messages
3362 for assignments that are not allowed in C.
3363 ERRTYPE is a string to use in error messages:
3364 "assignment", "return", etc. If it is null, this is parameter passing
3365 for a function call (and different error messages are output).
3367 FUNNAME is the name of the function being called,
3368 as an IDENTIFIER_NODE, or null.
3369 PARMNUM is the number of the argument, for printing in error messages. */
3372 convert_for_assignment (tree type
, tree rhs
, const char *errtype
,
3373 tree fundecl
, tree funname
, int parmnum
)
3375 enum tree_code codel
= TREE_CODE (type
);
3377 enum tree_code coder
;
3379 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
3380 /* Do not use STRIP_NOPS here. We do not want an enumerator
3381 whose value is 0 to count as a null pointer constant. */
3382 if (TREE_CODE (rhs
) == NON_LVALUE_EXPR
)
3383 rhs
= TREE_OPERAND (rhs
, 0);
3385 if (TREE_CODE (TREE_TYPE (rhs
)) == ARRAY_TYPE
3386 || TREE_CODE (TREE_TYPE (rhs
)) == FUNCTION_TYPE
)
3387 rhs
= default_conversion (rhs
);
3388 else if (optimize
&& TREE_CODE (rhs
) == VAR_DECL
)
3389 rhs
= decl_constant_value_for_broken_optimization (rhs
);
3391 rhstype
= TREE_TYPE (rhs
);
3392 coder
= TREE_CODE (rhstype
);
3394 if (coder
== ERROR_MARK
)
3395 return error_mark_node
;
3397 if (TYPE_MAIN_VARIANT (type
) == TYPE_MAIN_VARIANT (rhstype
))
3399 overflow_warning (rhs
);
3400 /* Check for Objective-C protocols. This will automatically
3401 issue a warning if there are protocol violations. No need to
3402 use the return value. */
3403 if (c_dialect_objc ())
3404 objc_comptypes (type
, rhstype
, 0);
3408 if (coder
== VOID_TYPE
)
3410 error ("void value not ignored as it ought to be");
3411 return error_mark_node
;
3413 /* A type converts to a reference to it.
3414 This code doesn't fully support references, it's just for the
3415 special case of va_start and va_copy. */
3416 if (codel
== REFERENCE_TYPE
3417 && comptypes (TREE_TYPE (type
), TREE_TYPE (rhs
), COMPARE_STRICT
) == 1)
3419 if (!lvalue_p (rhs
))
3421 error ("cannot pass rvalue to reference parameter");
3422 return error_mark_node
;
3424 if (!c_mark_addressable (rhs
))
3425 return error_mark_node
;
3426 rhs
= build1 (ADDR_EXPR
, build_pointer_type (TREE_TYPE (rhs
)), rhs
);
3428 /* We already know that these two types are compatible, but they
3429 may not be exactly identical. In fact, `TREE_TYPE (type)' is
3430 likely to be __builtin_va_list and `TREE_TYPE (rhs)' is
3431 likely to be va_list, a typedef to __builtin_va_list, which
3432 is different enough that it will cause problems later. */
3433 if (TREE_TYPE (TREE_TYPE (rhs
)) != TREE_TYPE (type
))
3434 rhs
= build1 (NOP_EXPR
, build_pointer_type (TREE_TYPE (type
)), rhs
);
3436 rhs
= build1 (NOP_EXPR
, type
, rhs
);
3439 /* Some types can interconvert without explicit casts. */
3440 else if (codel
== VECTOR_TYPE
&& coder
== VECTOR_TYPE
3441 && ((*targetm
.vector_opaque_p
) (type
)
3442 || (*targetm
.vector_opaque_p
) (rhstype
)))
3443 return convert (type
, rhs
);
3444 /* Arithmetic types all interconvert, and enum is treated like int. */
3445 else if ((codel
== INTEGER_TYPE
|| codel
== REAL_TYPE
3446 || codel
== ENUMERAL_TYPE
|| codel
== COMPLEX_TYPE
3447 || codel
== BOOLEAN_TYPE
)
3448 && (coder
== INTEGER_TYPE
|| coder
== REAL_TYPE
3449 || coder
== ENUMERAL_TYPE
|| coder
== COMPLEX_TYPE
3450 || coder
== BOOLEAN_TYPE
))
3451 return convert_and_check (type
, rhs
);
3453 /* Conversion to a transparent union from its member types.
3454 This applies only to function arguments. */
3455 else if (codel
== UNION_TYPE
&& TYPE_TRANSPARENT_UNION (type
) && ! errtype
)
3458 tree marginal_memb_type
= 0;
3460 for (memb_types
= TYPE_FIELDS (type
); memb_types
;
3461 memb_types
= TREE_CHAIN (memb_types
))
3463 tree memb_type
= TREE_TYPE (memb_types
);
3465 if (comptypes (TYPE_MAIN_VARIANT (memb_type
),
3466 TYPE_MAIN_VARIANT (rhstype
), COMPARE_STRICT
))
3469 if (TREE_CODE (memb_type
) != POINTER_TYPE
)
3472 if (coder
== POINTER_TYPE
)
3474 tree ttl
= TREE_TYPE (memb_type
);
3475 tree ttr
= TREE_TYPE (rhstype
);
3477 /* Any non-function converts to a [const][volatile] void *
3478 and vice versa; otherwise, targets must be the same.
3479 Meanwhile, the lhs target must have all the qualifiers of
3481 if (VOID_TYPE_P (ttl
) || VOID_TYPE_P (ttr
)
3482 || comp_target_types (memb_type
, rhstype
, 0))
3484 /* If this type won't generate any warnings, use it. */
3485 if (TYPE_QUALS (ttl
) == TYPE_QUALS (ttr
)
3486 || ((TREE_CODE (ttr
) == FUNCTION_TYPE
3487 && TREE_CODE (ttl
) == FUNCTION_TYPE
)
3488 ? ((TYPE_QUALS (ttl
) | TYPE_QUALS (ttr
))
3489 == TYPE_QUALS (ttr
))
3490 : ((TYPE_QUALS (ttl
) | TYPE_QUALS (ttr
))
3491 == TYPE_QUALS (ttl
))))
3494 /* Keep looking for a better type, but remember this one. */
3495 if (! marginal_memb_type
)
3496 marginal_memb_type
= memb_type
;
3500 /* Can convert integer zero to any pointer type. */
3501 if (integer_zerop (rhs
)
3502 || (TREE_CODE (rhs
) == NOP_EXPR
3503 && integer_zerop (TREE_OPERAND (rhs
, 0))))
3505 rhs
= null_pointer_node
;
3510 if (memb_types
|| marginal_memb_type
)
3514 /* We have only a marginally acceptable member type;
3515 it needs a warning. */
3516 tree ttl
= TREE_TYPE (marginal_memb_type
);
3517 tree ttr
= TREE_TYPE (rhstype
);
3519 /* Const and volatile mean something different for function
3520 types, so the usual warnings are not appropriate. */
3521 if (TREE_CODE (ttr
) == FUNCTION_TYPE
3522 && TREE_CODE (ttl
) == FUNCTION_TYPE
)
3524 /* Because const and volatile on functions are
3525 restrictions that say the function will not do
3526 certain things, it is okay to use a const or volatile
3527 function where an ordinary one is wanted, but not
3529 if (TYPE_QUALS (ttl
) & ~TYPE_QUALS (ttr
))
3530 warn_for_assignment ("%s makes qualified function pointer from unqualified",
3531 errtype
, funname
, parmnum
);
3533 else if (TYPE_QUALS (ttr
) & ~TYPE_QUALS (ttl
))
3534 warn_for_assignment ("%s discards qualifiers from pointer target type",
3539 if (pedantic
&& ! DECL_IN_SYSTEM_HEADER (fundecl
))
3540 pedwarn ("ISO C prohibits argument conversion to union type");
3542 return build1 (NOP_EXPR
, type
, rhs
);
3546 /* Conversions among pointers */
3547 else if ((codel
== POINTER_TYPE
|| codel
== REFERENCE_TYPE
)
3548 && (coder
== codel
))
3550 tree ttl
= TREE_TYPE (type
);
3551 tree ttr
= TREE_TYPE (rhstype
);
3552 bool is_opaque_pointer
;
3553 int target_cmp
= 0; /* Cache comp_target_types () result. */
3555 /* Opaque pointers are treated like void pointers. */
3556 is_opaque_pointer
= ((*targetm
.vector_opaque_p
) (type
)
3557 || (*targetm
.vector_opaque_p
) (rhstype
))
3558 && TREE_CODE (ttl
) == VECTOR_TYPE
3559 && TREE_CODE (ttr
) == VECTOR_TYPE
;
3561 /* Any non-function converts to a [const][volatile] void *
3562 and vice versa; otherwise, targets must be the same.
3563 Meanwhile, the lhs target must have all the qualifiers of the rhs. */
3564 if (VOID_TYPE_P (ttl
) || VOID_TYPE_P (ttr
)
3565 || (target_cmp
= comp_target_types (type
, rhstype
, 0))
3566 || is_opaque_pointer
3567 || (c_common_unsigned_type (TYPE_MAIN_VARIANT (ttl
))
3568 == c_common_unsigned_type (TYPE_MAIN_VARIANT (ttr
))))
3571 && ((VOID_TYPE_P (ttl
) && TREE_CODE (ttr
) == FUNCTION_TYPE
)
3574 /* Check TREE_CODE to catch cases like (void *) (char *) 0
3575 which are not ANSI null ptr constants. */
3576 && (!integer_zerop (rhs
) || TREE_CODE (rhs
) == NOP_EXPR
)
3577 && TREE_CODE (ttl
) == FUNCTION_TYPE
)))
3578 warn_for_assignment ("ISO C forbids %s between function pointer and `void *'",
3579 errtype
, funname
, parmnum
);
3580 /* Const and volatile mean something different for function types,
3581 so the usual warnings are not appropriate. */
3582 else if (TREE_CODE (ttr
) != FUNCTION_TYPE
3583 && TREE_CODE (ttl
) != FUNCTION_TYPE
)
3585 if (TYPE_QUALS (ttr
) & ~TYPE_QUALS (ttl
))
3586 warn_for_assignment ("%s discards qualifiers from pointer target type",
3587 errtype
, funname
, parmnum
);
3588 /* If this is not a case of ignoring a mismatch in signedness,
3590 else if (VOID_TYPE_P (ttl
) || VOID_TYPE_P (ttr
)
3593 /* If there is a mismatch, do warn. */
3595 warn_for_assignment ("pointer targets in %s differ in signedness",
3596 errtype
, funname
, parmnum
);
3598 else if (TREE_CODE (ttl
) == FUNCTION_TYPE
3599 && TREE_CODE (ttr
) == FUNCTION_TYPE
)
3601 /* Because const and volatile on functions are restrictions
3602 that say the function will not do certain things,
3603 it is okay to use a const or volatile function
3604 where an ordinary one is wanted, but not vice-versa. */
3605 if (TYPE_QUALS (ttl
) & ~TYPE_QUALS (ttr
))
3606 warn_for_assignment ("%s makes qualified function pointer from unqualified",
3607 errtype
, funname
, parmnum
);
3611 warn_for_assignment ("%s from incompatible pointer type",
3612 errtype
, funname
, parmnum
);
3613 return convert (type
, rhs
);
3615 else if (codel
== POINTER_TYPE
&& coder
== ARRAY_TYPE
)
3617 error ("invalid use of non-lvalue array");
3618 return error_mark_node
;
3620 else if (codel
== POINTER_TYPE
&& coder
== INTEGER_TYPE
)
3622 /* An explicit constant 0 can convert to a pointer,
3623 or one that results from arithmetic, even including
3624 a cast to integer type. */
3625 if (! (TREE_CODE (rhs
) == INTEGER_CST
&& integer_zerop (rhs
))
3627 ! (TREE_CODE (rhs
) == NOP_EXPR
3628 && TREE_CODE (TREE_TYPE (rhs
)) == INTEGER_TYPE
3629 && TREE_CODE (TREE_OPERAND (rhs
, 0)) == INTEGER_CST
3630 && integer_zerop (TREE_OPERAND (rhs
, 0))))
3631 warn_for_assignment ("%s makes pointer from integer without a cast",
3632 errtype
, funname
, parmnum
);
3634 return convert (type
, rhs
);
3636 else if (codel
== INTEGER_TYPE
&& coder
== POINTER_TYPE
)
3638 warn_for_assignment ("%s makes integer from pointer without a cast",
3639 errtype
, funname
, parmnum
);
3640 return convert (type
, rhs
);
3642 else if (codel
== BOOLEAN_TYPE
&& coder
== POINTER_TYPE
)
3643 return convert (type
, rhs
);
3649 tree selector
= objc_message_selector ();
3651 if (selector
&& parmnum
> 2)
3652 error ("incompatible type for argument %d of `%s'",
3653 parmnum
- 2, IDENTIFIER_POINTER (selector
));
3655 error ("incompatible type for argument %d of `%s'",
3656 parmnum
, IDENTIFIER_POINTER (funname
));
3659 error ("incompatible type for argument %d of indirect function call",
3663 error ("incompatible types in %s", errtype
);
3665 return error_mark_node
;
3668 /* Convert VALUE for assignment into inlined parameter PARM. ARGNUM
3669 is used for error and waring reporting and indicates which argument
3670 is being processed. */
3673 c_convert_parm_for_inlining (tree parm
, tree value
, tree fn
, int argnum
)
3677 /* If FN was prototyped, the value has been converted already
3678 in convert_arguments. */
3679 if (! value
|| TYPE_ARG_TYPES (TREE_TYPE (fn
)))
3682 type
= TREE_TYPE (parm
);
3683 ret
= convert_for_assignment (type
, value
,
3684 (char *) 0 /* arg passing */, fn
,
3685 DECL_NAME (fn
), argnum
);
3686 if (targetm
.calls
.promote_prototypes (TREE_TYPE (fn
))
3687 && INTEGRAL_TYPE_P (type
)
3688 && (TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
)))
3689 ret
= default_conversion (ret
);
3693 /* Print a warning using MSGID.
3694 It gets OPNAME as its one parameter.
3695 if OPNAME is null and ARGNUM is 0, it is replaced by "passing arg of `FUNCTION'".
3696 Otherwise if OPNAME is null, it is replaced by "passing arg ARGNUM of `FUNCTION'".
3697 FUNCTION and ARGNUM are handled specially if we are building an
3698 Objective-C selector. */
3701 warn_for_assignment (const char *msgid
, const char *opname
, tree function
,
3706 tree selector
= objc_message_selector ();
3709 if (selector
&& argnum
> 2)
3711 function
= selector
;
3718 /* Function name is known; supply it. */
3719 const char *const argstring
= _("passing arg of `%s'");
3720 new_opname
= alloca (IDENTIFIER_LENGTH (function
)
3721 + strlen (argstring
) + 1 + 1);
3722 sprintf (new_opname
, argstring
,
3723 IDENTIFIER_POINTER (function
));
3727 /* Function name unknown (call through ptr). */
3728 const char *const argnofun
= _("passing arg of pointer to function");
3729 new_opname
= alloca (strlen (argnofun
) + 1 + 1);
3730 sprintf (new_opname
, argnofun
);
3735 /* Function name is known; supply it. */
3736 const char *const argstring
= _("passing arg %d of `%s'");
3737 new_opname
= alloca (IDENTIFIER_LENGTH (function
)
3738 + strlen (argstring
) + 1 + 25 /*%d*/ + 1);
3739 sprintf (new_opname
, argstring
, argnum
,
3740 IDENTIFIER_POINTER (function
));
3744 /* Function name unknown (call through ptr); just give arg number. */
3745 const char *const argnofun
= _("passing arg %d of pointer to function");
3746 new_opname
= alloca (strlen (argnofun
) + 1 + 25 /*%d*/ + 1);
3747 sprintf (new_opname
, argnofun
, argnum
);
3749 opname
= new_opname
;
3751 pedwarn (msgid
, opname
);
3754 /* If VALUE is a compound expr all of whose expressions are constant, then
3755 return its value. Otherwise, return error_mark_node.
3757 This is for handling COMPOUND_EXPRs as initializer elements
3758 which is allowed with a warning when -pedantic is specified. */
3761 valid_compound_expr_initializer (tree value
, tree endtype
)
3763 if (TREE_CODE (value
) == COMPOUND_EXPR
)
3765 if (valid_compound_expr_initializer (TREE_OPERAND (value
, 0), endtype
)
3767 return error_mark_node
;
3768 return valid_compound_expr_initializer (TREE_OPERAND (value
, 1),
3771 else if (! TREE_CONSTANT (value
)
3772 && ! initializer_constant_valid_p (value
, endtype
))
3773 return error_mark_node
;
3778 /* Perform appropriate conversions on the initial value of a variable,
3779 store it in the declaration DECL,
3780 and print any error messages that are appropriate.
3781 If the init is invalid, store an ERROR_MARK. */
3784 store_init_value (tree decl
, tree init
)
3788 /* If variable's type was invalidly declared, just ignore it. */
3790 type
= TREE_TYPE (decl
);
3791 if (TREE_CODE (type
) == ERROR_MARK
)
3794 /* Digest the specified initializer into an expression. */
3796 value
= digest_init (type
, init
, TREE_STATIC (decl
));
3798 /* Store the expression if valid; else report error. */
3800 if (warn_traditional
&& !in_system_header
3801 && AGGREGATE_TYPE_P (TREE_TYPE (decl
)) && ! TREE_STATIC (decl
))
3802 warning ("traditional C rejects automatic aggregate initialization");
3804 DECL_INITIAL (decl
) = value
;
3806 /* ANSI wants warnings about out-of-range constant initializers. */
3807 STRIP_TYPE_NOPS (value
);
3808 constant_expression_warning (value
);
3810 /* Check if we need to set array size from compound literal size. */
3811 if (TREE_CODE (type
) == ARRAY_TYPE
3812 && TYPE_DOMAIN (type
) == 0
3813 && value
!= error_mark_node
)
3815 tree inside_init
= init
;
3817 if (TREE_CODE (init
) == NON_LVALUE_EXPR
)
3818 inside_init
= TREE_OPERAND (init
, 0);
3819 inside_init
= fold (inside_init
);
3821 if (TREE_CODE (inside_init
) == COMPOUND_LITERAL_EXPR
)
3823 tree decl
= COMPOUND_LITERAL_EXPR_DECL (inside_init
);
3825 if (TYPE_DOMAIN (TREE_TYPE (decl
)))
3827 /* For int foo[] = (int [3]){1}; we need to set array size
3828 now since later on array initializer will be just the
3829 brace enclosed list of the compound literal. */
3830 TYPE_DOMAIN (type
) = TYPE_DOMAIN (TREE_TYPE (decl
));
3832 layout_decl (decl
, 0);
3838 /* Methods for storing and printing names for error messages. */
3840 /* Implement a spelling stack that allows components of a name to be pushed
3841 and popped. Each element on the stack is this structure. */
3853 #define SPELLING_STRING 1
3854 #define SPELLING_MEMBER 2
3855 #define SPELLING_BOUNDS 3
3857 static struct spelling
*spelling
; /* Next stack element (unused). */
3858 static struct spelling
*spelling_base
; /* Spelling stack base. */
3859 static int spelling_size
; /* Size of the spelling stack. */
3861 /* Macros to save and restore the spelling stack around push_... functions.
3862 Alternative to SAVE_SPELLING_STACK. */
3864 #define SPELLING_DEPTH() (spelling - spelling_base)
3865 #define RESTORE_SPELLING_DEPTH(DEPTH) (spelling = spelling_base + (DEPTH))
3867 /* Push an element on the spelling stack with type KIND and assign VALUE
3870 #define PUSH_SPELLING(KIND, VALUE, MEMBER) \
3872 int depth = SPELLING_DEPTH (); \
3874 if (depth >= spelling_size) \
3876 spelling_size += 10; \
3877 if (spelling_base == 0) \
3878 spelling_base = xmalloc (spelling_size * sizeof (struct spelling)); \
3880 spelling_base = xrealloc (spelling_base, \
3881 spelling_size * sizeof (struct spelling)); \
3882 RESTORE_SPELLING_DEPTH (depth); \
3885 spelling->kind = (KIND); \
3886 spelling->MEMBER = (VALUE); \
3890 /* Push STRING on the stack. Printed literally. */
3893 push_string (const char *string
)
3895 PUSH_SPELLING (SPELLING_STRING
, string
, u
.s
);
3898 /* Push a member name on the stack. Printed as '.' STRING. */
3901 push_member_name (tree decl
)
3903 const char *const string
3904 = DECL_NAME (decl
) ? IDENTIFIER_POINTER (DECL_NAME (decl
)) : "<anonymous>";
3905 PUSH_SPELLING (SPELLING_MEMBER
, string
, u
.s
);
3908 /* Push an array bounds on the stack. Printed as [BOUNDS]. */
3911 push_array_bounds (int bounds
)
3913 PUSH_SPELLING (SPELLING_BOUNDS
, bounds
, u
.i
);
3916 /* Compute the maximum size in bytes of the printed spelling. */
3919 spelling_length (void)
3924 for (p
= spelling_base
; p
< spelling
; p
++)
3926 if (p
->kind
== SPELLING_BOUNDS
)
3929 size
+= strlen (p
->u
.s
) + 1;
3935 /* Print the spelling to BUFFER and return it. */
3938 print_spelling (char *buffer
)
3943 for (p
= spelling_base
; p
< spelling
; p
++)
3944 if (p
->kind
== SPELLING_BOUNDS
)
3946 sprintf (d
, "[%d]", p
->u
.i
);
3952 if (p
->kind
== SPELLING_MEMBER
)
3954 for (s
= p
->u
.s
; (*d
= *s
++); d
++)
3961 /* Issue an error message for a bad initializer component.
3962 MSGID identifies the message.
3963 The component name is taken from the spelling stack. */
3966 error_init (const char *msgid
)
3970 error ("%s", _(msgid
));
3971 ofwhat
= print_spelling (alloca (spelling_length () + 1));
3973 error ("(near initialization for `%s')", ofwhat
);
3976 /* Issue a pedantic warning for a bad initializer component.
3977 MSGID identifies the message.
3978 The component name is taken from the spelling stack. */
3981 pedwarn_init (const char *msgid
)
3985 pedwarn ("%s", _(msgid
));
3986 ofwhat
= print_spelling (alloca (spelling_length () + 1));
3988 pedwarn ("(near initialization for `%s')", ofwhat
);
3991 /* Issue a warning for a bad initializer component.
3992 MSGID identifies the message.
3993 The component name is taken from the spelling stack. */
3996 warning_init (const char *msgid
)
4000 warning ("%s", _(msgid
));
4001 ofwhat
= print_spelling (alloca (spelling_length () + 1));
4003 warning ("(near initialization for `%s')", ofwhat
);
4006 /* Digest the parser output INIT as an initializer for type TYPE.
4007 Return a C expression of type TYPE to represent the initial value.
4009 REQUIRE_CONSTANT requests an error if non-constant initializers or
4010 elements are seen. */
4013 digest_init (tree type
, tree init
, int require_constant
)
4015 enum tree_code code
= TREE_CODE (type
);
4016 tree inside_init
= init
;
4018 if (type
== error_mark_node
4019 || init
== error_mark_node
4020 || TREE_TYPE (init
) == error_mark_node
)
4021 return error_mark_node
;
4023 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
4024 /* Do not use STRIP_NOPS here. We do not want an enumerator
4025 whose value is 0 to count as a null pointer constant. */
4026 if (TREE_CODE (init
) == NON_LVALUE_EXPR
)
4027 inside_init
= TREE_OPERAND (init
, 0);
4029 inside_init
= fold (inside_init
);
4031 /* Initialization of an array of chars from a string constant
4032 optionally enclosed in braces. */
4034 if (code
== ARRAY_TYPE
)
4036 tree typ1
= TYPE_MAIN_VARIANT (TREE_TYPE (type
));
4037 if ((typ1
== char_type_node
4038 || typ1
== signed_char_type_node
4039 || typ1
== unsigned_char_type_node
4040 || typ1
== unsigned_wchar_type_node
4041 || typ1
== signed_wchar_type_node
)
4042 && ((inside_init
&& TREE_CODE (inside_init
) == STRING_CST
)))
4044 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init
)),
4045 TYPE_MAIN_VARIANT (type
), COMPARE_STRICT
))
4048 if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init
)))
4050 && TYPE_PRECISION (typ1
) == TYPE_PRECISION (char_type_node
))
4052 error_init ("char-array initialized from wide string");
4053 return error_mark_node
;
4055 if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init
)))
4057 && TYPE_PRECISION (typ1
) != TYPE_PRECISION (char_type_node
))
4059 error_init ("int-array initialized from non-wide string");
4060 return error_mark_node
;
4063 TREE_TYPE (inside_init
) = type
;
4064 if (TYPE_DOMAIN (type
) != 0
4065 && TYPE_SIZE (type
) != 0
4066 && TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
4067 /* Subtract 1 (or sizeof (wchar_t))
4068 because it's ok to ignore the terminating null char
4069 that is counted in the length of the constant. */
4070 && 0 > compare_tree_int (TYPE_SIZE_UNIT (type
),
4071 TREE_STRING_LENGTH (inside_init
)
4072 - ((TYPE_PRECISION (typ1
)
4073 != TYPE_PRECISION (char_type_node
))
4074 ? (TYPE_PRECISION (wchar_type_node
)
4077 pedwarn_init ("initializer-string for array of chars is too long");
4083 /* Build a VECTOR_CST from a *constant* vector constructor. If the
4084 vector constructor is not constant (e.g. {1,2,3,foo()}) then punt
4085 below and handle as a constructor. */
4086 if (code
== VECTOR_TYPE
4087 && comptypes (TREE_TYPE (inside_init
), type
, COMPARE_STRICT
)
4088 && TREE_CONSTANT (inside_init
))
4090 if (TREE_CODE (inside_init
) == VECTOR_CST
4091 && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init
)),
4092 TYPE_MAIN_VARIANT (type
),
4096 return build_vector (type
, CONSTRUCTOR_ELTS (inside_init
));
4099 /* Any type can be initialized
4100 from an expression of the same type, optionally with braces. */
4102 if (inside_init
&& TREE_TYPE (inside_init
) != 0
4103 && (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init
)),
4104 TYPE_MAIN_VARIANT (type
), COMPARE_STRICT
)
4105 || (code
== ARRAY_TYPE
4106 && comptypes (TREE_TYPE (inside_init
), type
, COMPARE_STRICT
))
4107 || (code
== VECTOR_TYPE
4108 && comptypes (TREE_TYPE (inside_init
), type
, COMPARE_STRICT
))
4109 || (code
== POINTER_TYPE
4110 && TREE_CODE (TREE_TYPE (inside_init
)) == ARRAY_TYPE
4111 && comptypes (TREE_TYPE (TREE_TYPE (inside_init
)),
4112 TREE_TYPE (type
), COMPARE_STRICT
))
4113 || (code
== POINTER_TYPE
4114 && TREE_CODE (TREE_TYPE (inside_init
)) == FUNCTION_TYPE
4115 && comptypes (TREE_TYPE (inside_init
),
4116 TREE_TYPE (type
), COMPARE_STRICT
))))
4118 if (code
== POINTER_TYPE
)
4120 inside_init
= default_function_array_conversion (inside_init
);
4122 if (TREE_CODE (TREE_TYPE (inside_init
)) == ARRAY_TYPE
)
4124 error_init ("invalid use of non-lvalue array");
4125 return error_mark_node
;
4129 if (code
== VECTOR_TYPE
)
4130 /* Although the types are compatible, we may require a
4132 inside_init
= convert (type
, inside_init
);
4134 if (require_constant
&& !flag_isoc99
4135 && TREE_CODE (inside_init
) == COMPOUND_LITERAL_EXPR
)
4137 /* As an extension, allow initializing objects with static storage
4138 duration with compound literals (which are then treated just as
4139 the brace enclosed list they contain). */
4140 tree decl
= COMPOUND_LITERAL_EXPR_DECL (inside_init
);
4141 inside_init
= DECL_INITIAL (decl
);
4144 if (code
== ARRAY_TYPE
&& TREE_CODE (inside_init
) != STRING_CST
4145 && TREE_CODE (inside_init
) != CONSTRUCTOR
)
4147 error_init ("array initialized from non-constant array expression");
4148 return error_mark_node
;
4151 if (optimize
&& TREE_CODE (inside_init
) == VAR_DECL
)
4152 inside_init
= decl_constant_value_for_broken_optimization (inside_init
);
4154 /* Compound expressions can only occur here if -pedantic or
4155 -pedantic-errors is specified. In the later case, we always want
4156 an error. In the former case, we simply want a warning. */
4157 if (require_constant
&& pedantic
4158 && TREE_CODE (inside_init
) == COMPOUND_EXPR
)
4161 = valid_compound_expr_initializer (inside_init
,
4162 TREE_TYPE (inside_init
));
4163 if (inside_init
== error_mark_node
)
4164 error_init ("initializer element is not constant");
4166 pedwarn_init ("initializer element is not constant");
4167 if (flag_pedantic_errors
)
4168 inside_init
= error_mark_node
;
4170 else if (require_constant
4171 && (!TREE_CONSTANT (inside_init
)
4172 /* This test catches things like `7 / 0' which
4173 result in an expression for which TREE_CONSTANT
4174 is true, but which is not actually something
4175 that is a legal constant. We really should not
4176 be using this function, because it is a part of
4177 the back-end. Instead, the expression should
4178 already have been turned into ERROR_MARK_NODE. */
4179 || !initializer_constant_valid_p (inside_init
,
4180 TREE_TYPE (inside_init
))))
4182 error_init ("initializer element is not constant");
4183 inside_init
= error_mark_node
;
4189 /* Handle scalar types, including conversions. */
4191 if (code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== POINTER_TYPE
4192 || code
== ENUMERAL_TYPE
|| code
== BOOLEAN_TYPE
|| code
== COMPLEX_TYPE
)
4194 /* Note that convert_for_assignment calls default_conversion
4195 for arrays and functions. We must not call it in the
4196 case where inside_init is a null pointer constant. */
4198 = convert_for_assignment (type
, init
, _("initialization"),
4199 NULL_TREE
, NULL_TREE
, 0);
4201 if (require_constant
&& ! TREE_CONSTANT (inside_init
))
4203 error_init ("initializer element is not constant");
4204 inside_init
= error_mark_node
;
4206 else if (require_constant
4207 && initializer_constant_valid_p (inside_init
, TREE_TYPE (inside_init
)) == 0)
4209 error_init ("initializer element is not computable at load time");
4210 inside_init
= error_mark_node
;
4216 /* Come here only for records and arrays. */
4218 if (COMPLETE_TYPE_P (type
) && TREE_CODE (TYPE_SIZE (type
)) != INTEGER_CST
)
4220 error_init ("variable-sized object may not be initialized");
4221 return error_mark_node
;
4224 error_init ("invalid initializer");
4225 return error_mark_node
;
4228 /* Handle initializers that use braces. */
4230 /* Type of object we are accumulating a constructor for.
4231 This type is always a RECORD_TYPE, UNION_TYPE or ARRAY_TYPE. */
4232 static tree constructor_type
;
4234 /* For a RECORD_TYPE or UNION_TYPE, this is the chain of fields
4236 static tree constructor_fields
;
4238 /* For an ARRAY_TYPE, this is the specified index
4239 at which to store the next element we get. */
4240 static tree constructor_index
;
4242 /* For an ARRAY_TYPE, this is the maximum index. */
4243 static tree constructor_max_index
;
4245 /* For a RECORD_TYPE, this is the first field not yet written out. */
4246 static tree constructor_unfilled_fields
;
4248 /* For an ARRAY_TYPE, this is the index of the first element
4249 not yet written out. */
4250 static tree constructor_unfilled_index
;
4252 /* In a RECORD_TYPE, the byte index of the next consecutive field.
4253 This is so we can generate gaps between fields, when appropriate. */
4254 static tree constructor_bit_index
;
4256 /* If we are saving up the elements rather than allocating them,
4257 this is the list of elements so far (in reverse order,
4258 most recent first). */
4259 static tree constructor_elements
;
4261 /* 1 if constructor should be incrementally stored into a constructor chain,
4262 0 if all the elements should be kept in AVL tree. */
4263 static int constructor_incremental
;
4265 /* 1 if so far this constructor's elements are all compile-time constants. */
4266 static int constructor_constant
;
4268 /* 1 if so far this constructor's elements are all valid address constants. */
4269 static int constructor_simple
;
4271 /* 1 if this constructor is erroneous so far. */
4272 static int constructor_erroneous
;
4274 /* Structure for managing pending initializer elements, organized as an
4279 struct init_node
*left
, *right
;
4280 struct init_node
*parent
;
4286 /* Tree of pending elements at this constructor level.
4287 These are elements encountered out of order
4288 which belong at places we haven't reached yet in actually
4290 Will never hold tree nodes across GC runs. */
4291 static struct init_node
*constructor_pending_elts
;
4293 /* The SPELLING_DEPTH of this constructor. */
4294 static int constructor_depth
;
4296 /* 0 if implicitly pushing constructor levels is allowed. */
4297 int constructor_no_implicit
= 0; /* 0 for C; 1 for some other languages. */
4299 static int require_constant_value
;
4300 static int require_constant_elements
;
4302 /* DECL node for which an initializer is being read.
4303 0 means we are reading a constructor expression
4304 such as (struct foo) {...}. */
4305 static tree constructor_decl
;
4307 /* Nonzero if this is an initializer for a top-level decl. */
4308 static int constructor_top_level
;
4310 /* Nonzero if there were any member designators in this initializer. */
4311 static int constructor_designated
;
4313 /* Nesting depth of designator list. */
4314 static int designator_depth
;
4316 /* Nonzero if there were diagnosed errors in this designator list. */
4317 static int designator_errorneous
;
4320 /* This stack has a level for each implicit or explicit level of
4321 structuring in the initializer, including the outermost one. It
4322 saves the values of most of the variables above. */
4324 struct constructor_range_stack
;
4326 struct constructor_stack
4328 struct constructor_stack
*next
;
4333 tree unfilled_index
;
4334 tree unfilled_fields
;
4337 struct init_node
*pending_elts
;
4340 /* If nonzero, this value should replace the entire
4341 constructor at this level. */
4342 tree replacement_value
;
4343 struct constructor_range_stack
*range_stack
;
4353 struct constructor_stack
*constructor_stack
;
4355 /* This stack represents designators from some range designator up to
4356 the last designator in the list. */
4358 struct constructor_range_stack
4360 struct constructor_range_stack
*next
, *prev
;
4361 struct constructor_stack
*stack
;
4368 struct constructor_range_stack
*constructor_range_stack
;
4370 /* This stack records separate initializers that are nested.
4371 Nested initializers can't happen in ANSI C, but GNU C allows them
4372 in cases like { ... (struct foo) { ... } ... }. */
4374 struct initializer_stack
4376 struct initializer_stack
*next
;
4378 struct constructor_stack
*constructor_stack
;
4379 struct constructor_range_stack
*constructor_range_stack
;
4381 struct spelling
*spelling
;
4382 struct spelling
*spelling_base
;
4385 char require_constant_value
;
4386 char require_constant_elements
;
4389 struct initializer_stack
*initializer_stack
;
4391 /* Prepare to parse and output the initializer for variable DECL. */
4394 start_init (tree decl
, tree asmspec_tree ATTRIBUTE_UNUSED
, int top_level
)
4397 struct initializer_stack
*p
= xmalloc (sizeof (struct initializer_stack
));
4399 p
->decl
= constructor_decl
;
4400 p
->require_constant_value
= require_constant_value
;
4401 p
->require_constant_elements
= require_constant_elements
;
4402 p
->constructor_stack
= constructor_stack
;
4403 p
->constructor_range_stack
= constructor_range_stack
;
4404 p
->elements
= constructor_elements
;
4405 p
->spelling
= spelling
;
4406 p
->spelling_base
= spelling_base
;
4407 p
->spelling_size
= spelling_size
;
4408 p
->top_level
= constructor_top_level
;
4409 p
->next
= initializer_stack
;
4410 initializer_stack
= p
;
4412 constructor_decl
= decl
;
4413 constructor_designated
= 0;
4414 constructor_top_level
= top_level
;
4418 require_constant_value
= TREE_STATIC (decl
);
4419 require_constant_elements
4420 = ((TREE_STATIC (decl
) || (pedantic
&& !flag_isoc99
))
4421 /* For a scalar, you can always use any value to initialize,
4422 even within braces. */
4423 && (TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
4424 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
4425 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
4426 || TREE_CODE (TREE_TYPE (decl
)) == QUAL_UNION_TYPE
));
4427 locus
= IDENTIFIER_POINTER (DECL_NAME (decl
));
4431 require_constant_value
= 0;
4432 require_constant_elements
= 0;
4433 locus
= "(anonymous)";
4436 constructor_stack
= 0;
4437 constructor_range_stack
= 0;
4439 missing_braces_mentioned
= 0;
4443 RESTORE_SPELLING_DEPTH (0);
4446 push_string (locus
);
4452 struct initializer_stack
*p
= initializer_stack
;
4454 /* Free the whole constructor stack of this initializer. */
4455 while (constructor_stack
)
4457 struct constructor_stack
*q
= constructor_stack
;
4458 constructor_stack
= q
->next
;
4462 if (constructor_range_stack
)
4465 /* Pop back to the data of the outer initializer (if any). */
4466 free (spelling_base
);
4468 constructor_decl
= p
->decl
;
4469 require_constant_value
= p
->require_constant_value
;
4470 require_constant_elements
= p
->require_constant_elements
;
4471 constructor_stack
= p
->constructor_stack
;
4472 constructor_range_stack
= p
->constructor_range_stack
;
4473 constructor_elements
= p
->elements
;
4474 spelling
= p
->spelling
;
4475 spelling_base
= p
->spelling_base
;
4476 spelling_size
= p
->spelling_size
;
4477 constructor_top_level
= p
->top_level
;
4478 initializer_stack
= p
->next
;
4482 /* Call here when we see the initializer is surrounded by braces.
4483 This is instead of a call to push_init_level;
4484 it is matched by a call to pop_init_level.
4486 TYPE is the type to initialize, for a constructor expression.
4487 For an initializer for a decl, TYPE is zero. */
4490 really_start_incremental_init (tree type
)
4492 struct constructor_stack
*p
= xmalloc (sizeof (struct constructor_stack
));
4495 type
= TREE_TYPE (constructor_decl
);
4497 if ((*targetm
.vector_opaque_p
) (type
))
4498 error ("opaque vector types cannot be initialized");
4500 p
->type
= constructor_type
;
4501 p
->fields
= constructor_fields
;
4502 p
->index
= constructor_index
;
4503 p
->max_index
= constructor_max_index
;
4504 p
->unfilled_index
= constructor_unfilled_index
;
4505 p
->unfilled_fields
= constructor_unfilled_fields
;
4506 p
->bit_index
= constructor_bit_index
;
4507 p
->elements
= constructor_elements
;
4508 p
->constant
= constructor_constant
;
4509 p
->simple
= constructor_simple
;
4510 p
->erroneous
= constructor_erroneous
;
4511 p
->pending_elts
= constructor_pending_elts
;
4512 p
->depth
= constructor_depth
;
4513 p
->replacement_value
= 0;
4517 p
->incremental
= constructor_incremental
;
4518 p
->designated
= constructor_designated
;
4520 constructor_stack
= p
;
4522 constructor_constant
= 1;
4523 constructor_simple
= 1;
4524 constructor_depth
= SPELLING_DEPTH ();
4525 constructor_elements
= 0;
4526 constructor_pending_elts
= 0;
4527 constructor_type
= type
;
4528 constructor_incremental
= 1;
4529 constructor_designated
= 0;
4530 designator_depth
= 0;
4531 designator_errorneous
= 0;
4533 if (TREE_CODE (constructor_type
) == RECORD_TYPE
4534 || TREE_CODE (constructor_type
) == UNION_TYPE
)
4536 constructor_fields
= TYPE_FIELDS (constructor_type
);
4537 /* Skip any nameless bit fields at the beginning. */
4538 while (constructor_fields
!= 0 && DECL_C_BIT_FIELD (constructor_fields
)
4539 && DECL_NAME (constructor_fields
) == 0)
4540 constructor_fields
= TREE_CHAIN (constructor_fields
);
4542 constructor_unfilled_fields
= constructor_fields
;
4543 constructor_bit_index
= bitsize_zero_node
;
4545 else if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
4547 if (TYPE_DOMAIN (constructor_type
))
4549 constructor_max_index
4550 = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type
));
4552 /* Detect non-empty initializations of zero-length arrays. */
4553 if (constructor_max_index
== NULL_TREE
4554 && TYPE_SIZE (constructor_type
))
4555 constructor_max_index
= build_int_2 (-1, -1);
4557 /* constructor_max_index needs to be an INTEGER_CST. Attempts
4558 to initialize VLAs will cause a proper error; avoid tree
4559 checking errors as well by setting a safe value. */
4560 if (constructor_max_index
4561 && TREE_CODE (constructor_max_index
) != INTEGER_CST
)
4562 constructor_max_index
= build_int_2 (-1, -1);
4565 = convert (bitsizetype
,
4566 TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type
)));
4569 constructor_index
= bitsize_zero_node
;
4571 constructor_unfilled_index
= constructor_index
;
4573 else if (TREE_CODE (constructor_type
) == VECTOR_TYPE
)
4575 /* Vectors are like simple fixed-size arrays. */
4576 constructor_max_index
=
4577 build_int_2 (TYPE_VECTOR_SUBPARTS (constructor_type
) - 1, 0);
4578 constructor_index
= convert (bitsizetype
, bitsize_zero_node
);
4579 constructor_unfilled_index
= constructor_index
;
4583 /* Handle the case of int x = {5}; */
4584 constructor_fields
= constructor_type
;
4585 constructor_unfilled_fields
= constructor_type
;
4589 /* Push down into a subobject, for initialization.
4590 If this is for an explicit set of braces, IMPLICIT is 0.
4591 If it is because the next element belongs at a lower level,
4592 IMPLICIT is 1 (or 2 if the push is because of designator list). */
4595 push_init_level (int implicit
)
4597 struct constructor_stack
*p
;
4598 tree value
= NULL_TREE
;
4600 /* If we've exhausted any levels that didn't have braces,
4602 while (constructor_stack
->implicit
)
4604 if ((TREE_CODE (constructor_type
) == RECORD_TYPE
4605 || TREE_CODE (constructor_type
) == UNION_TYPE
)
4606 && constructor_fields
== 0)
4607 process_init_element (pop_init_level (1));
4608 else if (TREE_CODE (constructor_type
) == ARRAY_TYPE
4609 && constructor_max_index
4610 && tree_int_cst_lt (constructor_max_index
, constructor_index
))
4611 process_init_element (pop_init_level (1));
4616 /* Unless this is an explicit brace, we need to preserve previous
4620 if ((TREE_CODE (constructor_type
) == RECORD_TYPE
4621 || TREE_CODE (constructor_type
) == UNION_TYPE
)
4622 && constructor_fields
)
4623 value
= find_init_member (constructor_fields
);
4624 else if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
4625 value
= find_init_member (constructor_index
);
4628 p
= xmalloc (sizeof (struct constructor_stack
));
4629 p
->type
= constructor_type
;
4630 p
->fields
= constructor_fields
;
4631 p
->index
= constructor_index
;
4632 p
->max_index
= constructor_max_index
;
4633 p
->unfilled_index
= constructor_unfilled_index
;
4634 p
->unfilled_fields
= constructor_unfilled_fields
;
4635 p
->bit_index
= constructor_bit_index
;
4636 p
->elements
= constructor_elements
;
4637 p
->constant
= constructor_constant
;
4638 p
->simple
= constructor_simple
;
4639 p
->erroneous
= constructor_erroneous
;
4640 p
->pending_elts
= constructor_pending_elts
;
4641 p
->depth
= constructor_depth
;
4642 p
->replacement_value
= 0;
4643 p
->implicit
= implicit
;
4645 p
->incremental
= constructor_incremental
;
4646 p
->designated
= constructor_designated
;
4647 p
->next
= constructor_stack
;
4649 constructor_stack
= p
;
4651 constructor_constant
= 1;
4652 constructor_simple
= 1;
4653 constructor_depth
= SPELLING_DEPTH ();
4654 constructor_elements
= 0;
4655 constructor_incremental
= 1;
4656 constructor_designated
= 0;
4657 constructor_pending_elts
= 0;
4660 p
->range_stack
= constructor_range_stack
;
4661 constructor_range_stack
= 0;
4662 designator_depth
= 0;
4663 designator_errorneous
= 0;
4666 /* Don't die if an entire brace-pair level is superfluous
4667 in the containing level. */
4668 if (constructor_type
== 0)
4670 else if (TREE_CODE (constructor_type
) == RECORD_TYPE
4671 || TREE_CODE (constructor_type
) == UNION_TYPE
)
4673 /* Don't die if there are extra init elts at the end. */
4674 if (constructor_fields
== 0)
4675 constructor_type
= 0;
4678 constructor_type
= TREE_TYPE (constructor_fields
);
4679 push_member_name (constructor_fields
);
4680 constructor_depth
++;
4683 else if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
4685 constructor_type
= TREE_TYPE (constructor_type
);
4686 push_array_bounds (tree_low_cst (constructor_index
, 0));
4687 constructor_depth
++;
4690 if (constructor_type
== 0)
4692 error_init ("extra brace group at end of initializer");
4693 constructor_fields
= 0;
4694 constructor_unfilled_fields
= 0;
4698 if (value
&& TREE_CODE (value
) == CONSTRUCTOR
)
4700 constructor_constant
= TREE_CONSTANT (value
);
4701 constructor_simple
= TREE_STATIC (value
);
4702 constructor_elements
= CONSTRUCTOR_ELTS (value
);
4703 if (constructor_elements
4704 && (TREE_CODE (constructor_type
) == RECORD_TYPE
4705 || TREE_CODE (constructor_type
) == ARRAY_TYPE
))
4706 set_nonincremental_init ();
4709 if (implicit
== 1 && warn_missing_braces
&& !missing_braces_mentioned
)
4711 missing_braces_mentioned
= 1;
4712 warning_init ("missing braces around initializer");
4715 if (TREE_CODE (constructor_type
) == RECORD_TYPE
4716 || TREE_CODE (constructor_type
) == UNION_TYPE
)
4718 constructor_fields
= TYPE_FIELDS (constructor_type
);
4719 /* Skip any nameless bit fields at the beginning. */
4720 while (constructor_fields
!= 0 && DECL_C_BIT_FIELD (constructor_fields
)
4721 && DECL_NAME (constructor_fields
) == 0)
4722 constructor_fields
= TREE_CHAIN (constructor_fields
);
4724 constructor_unfilled_fields
= constructor_fields
;
4725 constructor_bit_index
= bitsize_zero_node
;
4727 else if (TREE_CODE (constructor_type
) == VECTOR_TYPE
)
4729 /* Vectors are like simple fixed-size arrays. */
4730 constructor_max_index
=
4731 build_int_2 (TYPE_VECTOR_SUBPARTS (constructor_type
) - 1, 0);
4732 constructor_index
= convert (bitsizetype
, integer_zero_node
);
4733 constructor_unfilled_index
= constructor_index
;
4735 else if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
4737 if (TYPE_DOMAIN (constructor_type
))
4739 constructor_max_index
4740 = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type
));
4742 /* Detect non-empty initializations of zero-length arrays. */
4743 if (constructor_max_index
== NULL_TREE
4744 && TYPE_SIZE (constructor_type
))
4745 constructor_max_index
= build_int_2 (-1, -1);
4747 /* constructor_max_index needs to be an INTEGER_CST. Attempts
4748 to initialize VLAs will cause a proper error; avoid tree
4749 checking errors as well by setting a safe value. */
4750 if (constructor_max_index
4751 && TREE_CODE (constructor_max_index
) != INTEGER_CST
)
4752 constructor_max_index
= build_int_2 (-1, -1);
4755 = convert (bitsizetype
,
4756 TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type
)));
4759 constructor_index
= bitsize_zero_node
;
4761 constructor_unfilled_index
= constructor_index
;
4762 if (value
&& TREE_CODE (value
) == STRING_CST
)
4764 /* We need to split the char/wchar array into individual
4765 characters, so that we don't have to special case it
4767 set_nonincremental_init_from_string (value
);
4772 warning_init ("braces around scalar initializer");
4773 constructor_fields
= constructor_type
;
4774 constructor_unfilled_fields
= constructor_type
;
4778 /* At the end of an implicit or explicit brace level,
4779 finish up that level of constructor.
4780 If we were outputting the elements as they are read, return 0
4781 from inner levels (process_init_element ignores that),
4782 but return error_mark_node from the outermost level
4783 (that's what we want to put in DECL_INITIAL).
4784 Otherwise, return a CONSTRUCTOR expression. */
4787 pop_init_level (int implicit
)
4789 struct constructor_stack
*p
;
4790 tree constructor
= 0;
4794 /* When we come to an explicit close brace,
4795 pop any inner levels that didn't have explicit braces. */
4796 while (constructor_stack
->implicit
)
4797 process_init_element (pop_init_level (1));
4799 if (constructor_range_stack
)
4803 p
= constructor_stack
;
4805 /* Error for initializing a flexible array member, or a zero-length
4806 array member in an inappropriate context. */
4807 if (constructor_type
&& constructor_fields
4808 && TREE_CODE (constructor_type
) == ARRAY_TYPE
4809 && TYPE_DOMAIN (constructor_type
)
4810 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type
)))
4812 /* Silently discard empty initializations. The parser will
4813 already have pedwarned for empty brackets. */
4814 if (integer_zerop (constructor_unfilled_index
))
4815 constructor_type
= NULL_TREE
;
4816 else if (! TYPE_SIZE (constructor_type
))
4818 if (constructor_depth
> 2)
4819 error_init ("initialization of flexible array member in a nested context");
4821 pedwarn_init ("initialization of a flexible array member");
4823 /* We have already issued an error message for the existence
4824 of a flexible array member not at the end of the structure.
4825 Discard the initializer so that we do not abort later. */
4826 if (TREE_CHAIN (constructor_fields
) != NULL_TREE
)
4827 constructor_type
= NULL_TREE
;
4830 /* Zero-length arrays are no longer special, so we should no longer
4835 /* Warn when some struct elements are implicitly initialized to zero. */
4838 && TREE_CODE (constructor_type
) == RECORD_TYPE
4839 && constructor_unfilled_fields
)
4841 /* Do not warn for flexible array members or zero-length arrays. */
4842 while (constructor_unfilled_fields
4843 && (! DECL_SIZE (constructor_unfilled_fields
)
4844 || integer_zerop (DECL_SIZE (constructor_unfilled_fields
))))
4845 constructor_unfilled_fields
= TREE_CHAIN (constructor_unfilled_fields
);
4847 /* Do not warn if this level of the initializer uses member
4848 designators; it is likely to be deliberate. */
4849 if (constructor_unfilled_fields
&& !constructor_designated
)
4851 push_member_name (constructor_unfilled_fields
);
4852 warning_init ("missing initializer");
4853 RESTORE_SPELLING_DEPTH (constructor_depth
);
4857 /* Now output all pending elements. */
4858 constructor_incremental
= 1;
4859 output_pending_init_elements (1);
4861 /* Pad out the end of the structure. */
4862 if (p
->replacement_value
)
4863 /* If this closes a superfluous brace pair,
4864 just pass out the element between them. */
4865 constructor
= p
->replacement_value
;
4866 else if (constructor_type
== 0)
4868 else if (TREE_CODE (constructor_type
) != RECORD_TYPE
4869 && TREE_CODE (constructor_type
) != UNION_TYPE
4870 && TREE_CODE (constructor_type
) != ARRAY_TYPE
4871 && TREE_CODE (constructor_type
) != VECTOR_TYPE
)
4873 /* A nonincremental scalar initializer--just return
4874 the element, after verifying there is just one. */
4875 if (constructor_elements
== 0)
4877 if (!constructor_erroneous
)
4878 error_init ("empty scalar initializer");
4879 constructor
= error_mark_node
;
4881 else if (TREE_CHAIN (constructor_elements
) != 0)
4883 error_init ("extra elements in scalar initializer");
4884 constructor
= TREE_VALUE (constructor_elements
);
4887 constructor
= TREE_VALUE (constructor_elements
);
4891 if (constructor_erroneous
)
4892 constructor
= error_mark_node
;
4895 constructor
= build_constructor (constructor_type
,
4896 nreverse (constructor_elements
));
4897 if (constructor_constant
)
4898 TREE_CONSTANT (constructor
) = 1;
4899 if (constructor_constant
&& constructor_simple
)
4900 TREE_STATIC (constructor
) = 1;
4904 constructor_type
= p
->type
;
4905 constructor_fields
= p
->fields
;
4906 constructor_index
= p
->index
;
4907 constructor_max_index
= p
->max_index
;
4908 constructor_unfilled_index
= p
->unfilled_index
;
4909 constructor_unfilled_fields
= p
->unfilled_fields
;
4910 constructor_bit_index
= p
->bit_index
;
4911 constructor_elements
= p
->elements
;
4912 constructor_constant
= p
->constant
;
4913 constructor_simple
= p
->simple
;
4914 constructor_erroneous
= p
->erroneous
;
4915 constructor_incremental
= p
->incremental
;
4916 constructor_designated
= p
->designated
;
4917 constructor_pending_elts
= p
->pending_elts
;
4918 constructor_depth
= p
->depth
;
4920 constructor_range_stack
= p
->range_stack
;
4921 RESTORE_SPELLING_DEPTH (constructor_depth
);
4923 constructor_stack
= p
->next
;
4926 if (constructor
== 0)
4928 if (constructor_stack
== 0)
4929 return error_mark_node
;
4935 /* Common handling for both array range and field name designators.
4936 ARRAY argument is nonzero for array ranges. Returns zero for success. */
4939 set_designator (int array
)
4942 enum tree_code subcode
;
4944 /* Don't die if an entire brace-pair level is superfluous
4945 in the containing level. */
4946 if (constructor_type
== 0)
4949 /* If there were errors in this designator list already, bail out silently. */
4950 if (designator_errorneous
)
4953 if (!designator_depth
)
4955 if (constructor_range_stack
)
4958 /* Designator list starts at the level of closest explicit
4960 while (constructor_stack
->implicit
)
4961 process_init_element (pop_init_level (1));
4962 constructor_designated
= 1;
4966 if (constructor_no_implicit
)
4968 error_init ("initialization designators may not nest");
4972 if (TREE_CODE (constructor_type
) == RECORD_TYPE
4973 || TREE_CODE (constructor_type
) == UNION_TYPE
)
4975 subtype
= TREE_TYPE (constructor_fields
);
4976 if (subtype
!= error_mark_node
)
4977 subtype
= TYPE_MAIN_VARIANT (subtype
);
4979 else if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
4981 subtype
= TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type
));
4986 subcode
= TREE_CODE (subtype
);
4987 if (array
&& subcode
!= ARRAY_TYPE
)
4989 error_init ("array index in non-array initializer");
4992 else if (!array
&& subcode
!= RECORD_TYPE
&& subcode
!= UNION_TYPE
)
4994 error_init ("field name not in record or union initializer");
4998 constructor_designated
= 1;
4999 push_init_level (2);
5003 /* If there are range designators in designator list, push a new designator
5004 to constructor_range_stack. RANGE_END is end of such stack range or
5005 NULL_TREE if there is no range designator at this level. */
5008 push_range_stack (tree range_end
)
5010 struct constructor_range_stack
*p
;
5012 p
= ggc_alloc (sizeof (struct constructor_range_stack
));
5013 p
->prev
= constructor_range_stack
;
5015 p
->fields
= constructor_fields
;
5016 p
->range_start
= constructor_index
;
5017 p
->index
= constructor_index
;
5018 p
->stack
= constructor_stack
;
5019 p
->range_end
= range_end
;
5020 if (constructor_range_stack
)
5021 constructor_range_stack
->next
= p
;
5022 constructor_range_stack
= p
;
5025 /* Within an array initializer, specify the next index to be initialized.
5026 FIRST is that index. If LAST is nonzero, then initialize a range
5027 of indices, running from FIRST through LAST. */
5030 set_init_index (tree first
, tree last
)
5032 if (set_designator (1))
5035 designator_errorneous
= 1;
5037 while ((TREE_CODE (first
) == NOP_EXPR
5038 || TREE_CODE (first
) == CONVERT_EXPR
5039 || TREE_CODE (first
) == NON_LVALUE_EXPR
)
5040 && (TYPE_MODE (TREE_TYPE (first
))
5041 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (first
, 0)))))
5042 first
= TREE_OPERAND (first
, 0);
5045 while ((TREE_CODE (last
) == NOP_EXPR
5046 || TREE_CODE (last
) == CONVERT_EXPR
5047 || TREE_CODE (last
) == NON_LVALUE_EXPR
)
5048 && (TYPE_MODE (TREE_TYPE (last
))
5049 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (last
, 0)))))
5050 last
= TREE_OPERAND (last
, 0);
5052 if (TREE_CODE (first
) != INTEGER_CST
)
5053 error_init ("nonconstant array index in initializer");
5054 else if (last
!= 0 && TREE_CODE (last
) != INTEGER_CST
)
5055 error_init ("nonconstant array index in initializer");
5056 else if (TREE_CODE (constructor_type
) != ARRAY_TYPE
)
5057 error_init ("array index in non-array initializer");
5058 else if (tree_int_cst_sgn (first
) == -1)
5059 error_init ("array index in initializer exceeds array bounds");
5060 else if (constructor_max_index
5061 && tree_int_cst_lt (constructor_max_index
, first
))
5062 error_init ("array index in initializer exceeds array bounds");
5065 constructor_index
= convert (bitsizetype
, first
);
5069 if (tree_int_cst_equal (first
, last
))
5071 else if (tree_int_cst_lt (last
, first
))
5073 error_init ("empty index range in initializer");
5078 last
= convert (bitsizetype
, last
);
5079 if (constructor_max_index
!= 0
5080 && tree_int_cst_lt (constructor_max_index
, last
))
5082 error_init ("array index range in initializer exceeds array bounds");
5089 designator_errorneous
= 0;
5090 if (constructor_range_stack
|| last
)
5091 push_range_stack (last
);
5095 /* Within a struct initializer, specify the next field to be initialized. */
5098 set_init_label (tree fieldname
)
5102 if (set_designator (0))
5105 designator_errorneous
= 1;
5107 if (TREE_CODE (constructor_type
) != RECORD_TYPE
5108 && TREE_CODE (constructor_type
) != UNION_TYPE
)
5110 error_init ("field name not in record or union initializer");
5114 for (tail
= TYPE_FIELDS (constructor_type
); tail
;
5115 tail
= TREE_CHAIN (tail
))
5117 if (DECL_NAME (tail
) == fieldname
)
5122 error ("unknown field `%s' specified in initializer",
5123 IDENTIFIER_POINTER (fieldname
));
5126 constructor_fields
= tail
;
5128 designator_errorneous
= 0;
5129 if (constructor_range_stack
)
5130 push_range_stack (NULL_TREE
);
5134 /* Add a new initializer to the tree of pending initializers. PURPOSE
5135 identifies the initializer, either array index or field in a structure.
5136 VALUE is the value of that index or field. */
5139 add_pending_init (tree purpose
, tree value
)
5141 struct init_node
*p
, **q
, *r
;
5143 q
= &constructor_pending_elts
;
5146 if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
5151 if (tree_int_cst_lt (purpose
, p
->purpose
))
5153 else if (tree_int_cst_lt (p
->purpose
, purpose
))
5157 if (TREE_SIDE_EFFECTS (p
->value
))
5158 warning_init ("initialized field with side-effects overwritten");
5168 bitpos
= bit_position (purpose
);
5172 if (tree_int_cst_lt (bitpos
, bit_position (p
->purpose
)))
5174 else if (p
->purpose
!= purpose
)
5178 if (TREE_SIDE_EFFECTS (p
->value
))
5179 warning_init ("initialized field with side-effects overwritten");
5186 r
= ggc_alloc (sizeof (struct init_node
));
5187 r
->purpose
= purpose
;
5198 struct init_node
*s
;
5202 if (p
->balance
== 0)
5204 else if (p
->balance
< 0)
5211 p
->left
->parent
= p
;
5228 constructor_pending_elts
= r
;
5233 struct init_node
*t
= r
->right
;
5237 r
->right
->parent
= r
;
5242 p
->left
->parent
= p
;
5245 p
->balance
= t
->balance
< 0;
5246 r
->balance
= -(t
->balance
> 0);
5261 constructor_pending_elts
= t
;
5267 /* p->balance == +1; growth of left side balances the node. */
5272 else /* r == p->right */
5274 if (p
->balance
== 0)
5275 /* Growth propagation from right side. */
5277 else if (p
->balance
> 0)
5284 p
->right
->parent
= p
;
5301 constructor_pending_elts
= r
;
5303 else /* r->balance == -1 */
5306 struct init_node
*t
= r
->left
;
5310 r
->left
->parent
= r
;
5315 p
->right
->parent
= p
;
5318 r
->balance
= (t
->balance
< 0);
5319 p
->balance
= -(t
->balance
> 0);
5334 constructor_pending_elts
= t
;
5340 /* p->balance == -1; growth of right side balances the node. */
5351 /* Build AVL tree from a sorted chain. */
5354 set_nonincremental_init (void)
5358 if (TREE_CODE (constructor_type
) != RECORD_TYPE
5359 && TREE_CODE (constructor_type
) != ARRAY_TYPE
)
5362 for (chain
= constructor_elements
; chain
; chain
= TREE_CHAIN (chain
))
5363 add_pending_init (TREE_PURPOSE (chain
), TREE_VALUE (chain
));
5364 constructor_elements
= 0;
5365 if (TREE_CODE (constructor_type
) == RECORD_TYPE
)
5367 constructor_unfilled_fields
= TYPE_FIELDS (constructor_type
);
5368 /* Skip any nameless bit fields at the beginning. */
5369 while (constructor_unfilled_fields
!= 0
5370 && DECL_C_BIT_FIELD (constructor_unfilled_fields
)
5371 && DECL_NAME (constructor_unfilled_fields
) == 0)
5372 constructor_unfilled_fields
= TREE_CHAIN (constructor_unfilled_fields
);
5375 else if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
5377 if (TYPE_DOMAIN (constructor_type
))
5378 constructor_unfilled_index
5379 = convert (bitsizetype
,
5380 TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type
)));
5382 constructor_unfilled_index
= bitsize_zero_node
;
5384 constructor_incremental
= 0;
5387 /* Build AVL tree from a string constant. */
5390 set_nonincremental_init_from_string (tree str
)
5392 tree value
, purpose
, type
;
5393 HOST_WIDE_INT val
[2];
5394 const char *p
, *end
;
5395 int byte
, wchar_bytes
, charwidth
, bitpos
;
5397 if (TREE_CODE (constructor_type
) != ARRAY_TYPE
)
5400 if (TYPE_PRECISION (TREE_TYPE (TREE_TYPE (str
)))
5401 == TYPE_PRECISION (char_type_node
))
5403 else if (TYPE_PRECISION (TREE_TYPE (TREE_TYPE (str
)))
5404 == TYPE_PRECISION (wchar_type_node
))
5405 wchar_bytes
= TYPE_PRECISION (wchar_type_node
) / BITS_PER_UNIT
;
5409 charwidth
= TYPE_PRECISION (char_type_node
);
5410 type
= TREE_TYPE (constructor_type
);
5411 p
= TREE_STRING_POINTER (str
);
5412 end
= p
+ TREE_STRING_LENGTH (str
);
5414 for (purpose
= bitsize_zero_node
;
5415 p
< end
&& !tree_int_cst_lt (constructor_max_index
, purpose
);
5416 purpose
= size_binop (PLUS_EXPR
, purpose
, bitsize_one_node
))
5418 if (wchar_bytes
== 1)
5420 val
[1] = (unsigned char) *p
++;
5427 for (byte
= 0; byte
< wchar_bytes
; byte
++)
5429 if (BYTES_BIG_ENDIAN
)
5430 bitpos
= (wchar_bytes
- byte
- 1) * charwidth
;
5432 bitpos
= byte
* charwidth
;
5433 val
[bitpos
< HOST_BITS_PER_WIDE_INT
]
5434 |= ((unsigned HOST_WIDE_INT
) ((unsigned char) *p
++))
5435 << (bitpos
% HOST_BITS_PER_WIDE_INT
);
5439 if (!TREE_UNSIGNED (type
))
5441 bitpos
= ((wchar_bytes
- 1) * charwidth
) + HOST_BITS_PER_CHAR
;
5442 if (bitpos
< HOST_BITS_PER_WIDE_INT
)
5444 if (val
[1] & (((HOST_WIDE_INT
) 1) << (bitpos
- 1)))
5446 val
[1] |= ((HOST_WIDE_INT
) -1) << bitpos
;
5450 else if (bitpos
== HOST_BITS_PER_WIDE_INT
)
5455 else if (val
[0] & (((HOST_WIDE_INT
) 1)
5456 << (bitpos
- 1 - HOST_BITS_PER_WIDE_INT
)))
5457 val
[0] |= ((HOST_WIDE_INT
) -1)
5458 << (bitpos
- HOST_BITS_PER_WIDE_INT
);
5461 value
= build_int_2 (val
[1], val
[0]);
5462 TREE_TYPE (value
) = type
;
5463 add_pending_init (purpose
, value
);
5466 constructor_incremental
= 0;
5469 /* Return value of FIELD in pending initializer or zero if the field was
5470 not initialized yet. */
5473 find_init_member (tree field
)
5475 struct init_node
*p
;
5477 if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
5479 if (constructor_incremental
5480 && tree_int_cst_lt (field
, constructor_unfilled_index
))
5481 set_nonincremental_init ();
5483 p
= constructor_pending_elts
;
5486 if (tree_int_cst_lt (field
, p
->purpose
))
5488 else if (tree_int_cst_lt (p
->purpose
, field
))
5494 else if (TREE_CODE (constructor_type
) == RECORD_TYPE
)
5496 tree bitpos
= bit_position (field
);
5498 if (constructor_incremental
5499 && (!constructor_unfilled_fields
5500 || tree_int_cst_lt (bitpos
,
5501 bit_position (constructor_unfilled_fields
))))
5502 set_nonincremental_init ();
5504 p
= constructor_pending_elts
;
5507 if (field
== p
->purpose
)
5509 else if (tree_int_cst_lt (bitpos
, bit_position (p
->purpose
)))
5515 else if (TREE_CODE (constructor_type
) == UNION_TYPE
)
5517 if (constructor_elements
5518 && TREE_PURPOSE (constructor_elements
) == field
)
5519 return TREE_VALUE (constructor_elements
);
5524 /* "Output" the next constructor element.
5525 At top level, really output it to assembler code now.
5526 Otherwise, collect it in a list from which we will make a CONSTRUCTOR.
5527 TYPE is the data type that the containing data type wants here.
5528 FIELD is the field (a FIELD_DECL) or the index that this element fills.
5530 PENDING if non-nil means output pending elements that belong
5531 right after this element. (PENDING is normally 1;
5532 it is 0 while outputting pending elements, to avoid recursion.) */
5535 output_init_element (tree value
, tree type
, tree field
, int pending
)
5537 if (type
== error_mark_node
)
5539 constructor_erroneous
= 1;
5542 if (TREE_CODE (TREE_TYPE (value
)) == FUNCTION_TYPE
5543 || (TREE_CODE (TREE_TYPE (value
)) == ARRAY_TYPE
5544 && !(TREE_CODE (value
) == STRING_CST
5545 && TREE_CODE (type
) == ARRAY_TYPE
5546 && TREE_CODE (TREE_TYPE (type
)) == INTEGER_TYPE
)
5547 && !comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (value
)),
5548 TYPE_MAIN_VARIANT (type
), COMPARE_STRICT
)))
5549 value
= default_conversion (value
);
5551 if (TREE_CODE (value
) == COMPOUND_LITERAL_EXPR
5552 && require_constant_value
&& !flag_isoc99
&& pending
)
5554 /* As an extension, allow initializing objects with static storage
5555 duration with compound literals (which are then treated just as
5556 the brace enclosed list they contain). */
5557 tree decl
= COMPOUND_LITERAL_EXPR_DECL (value
);
5558 value
= DECL_INITIAL (decl
);
5561 if (value
== error_mark_node
)
5562 constructor_erroneous
= 1;
5563 else if (!TREE_CONSTANT (value
))
5564 constructor_constant
= 0;
5565 else if (initializer_constant_valid_p (value
, TREE_TYPE (value
)) == 0
5566 || ((TREE_CODE (constructor_type
) == RECORD_TYPE
5567 || TREE_CODE (constructor_type
) == UNION_TYPE
)
5568 && DECL_C_BIT_FIELD (field
)
5569 && TREE_CODE (value
) != INTEGER_CST
))
5570 constructor_simple
= 0;
5572 if (require_constant_value
&& ! TREE_CONSTANT (value
))
5574 error_init ("initializer element is not constant");
5575 value
= error_mark_node
;
5577 else if (require_constant_elements
5578 && initializer_constant_valid_p (value
, TREE_TYPE (value
)) == 0)
5579 pedwarn ("initializer element is not computable at load time");
5581 /* If this field is empty (and not at the end of structure),
5582 don't do anything other than checking the initializer. */
5584 && (TREE_TYPE (field
) == error_mark_node
5585 || (COMPLETE_TYPE_P (TREE_TYPE (field
))
5586 && integer_zerop (TYPE_SIZE (TREE_TYPE (field
)))
5587 && (TREE_CODE (constructor_type
) == ARRAY_TYPE
5588 || TREE_CHAIN (field
)))))
5591 value
= digest_init (type
, value
, require_constant_value
);
5592 if (value
== error_mark_node
)
5594 constructor_erroneous
= 1;
5598 /* If this element doesn't come next in sequence,
5599 put it on constructor_pending_elts. */
5600 if (TREE_CODE (constructor_type
) == ARRAY_TYPE
5601 && (!constructor_incremental
5602 || !tree_int_cst_equal (field
, constructor_unfilled_index
)))
5604 if (constructor_incremental
5605 && tree_int_cst_lt (field
, constructor_unfilled_index
))
5606 set_nonincremental_init ();
5608 add_pending_init (field
, value
);
5611 else if (TREE_CODE (constructor_type
) == RECORD_TYPE
5612 && (!constructor_incremental
5613 || field
!= constructor_unfilled_fields
))
5615 /* We do this for records but not for unions. In a union,
5616 no matter which field is specified, it can be initialized
5617 right away since it starts at the beginning of the union. */
5618 if (constructor_incremental
)
5620 if (!constructor_unfilled_fields
)
5621 set_nonincremental_init ();
5624 tree bitpos
, unfillpos
;
5626 bitpos
= bit_position (field
);
5627 unfillpos
= bit_position (constructor_unfilled_fields
);
5629 if (tree_int_cst_lt (bitpos
, unfillpos
))
5630 set_nonincremental_init ();
5634 add_pending_init (field
, value
);
5637 else if (TREE_CODE (constructor_type
) == UNION_TYPE
5638 && constructor_elements
)
5640 if (TREE_SIDE_EFFECTS (TREE_VALUE (constructor_elements
)))
5641 warning_init ("initialized field with side-effects overwritten");
5643 /* We can have just one union field set. */
5644 constructor_elements
= 0;
5647 /* Otherwise, output this element either to
5648 constructor_elements or to the assembler file. */
5650 if (field
&& TREE_CODE (field
) == INTEGER_CST
)
5651 field
= copy_node (field
);
5652 constructor_elements
5653 = tree_cons (field
, value
, constructor_elements
);
5655 /* Advance the variable that indicates sequential elements output. */
5656 if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
5657 constructor_unfilled_index
5658 = size_binop (PLUS_EXPR
, constructor_unfilled_index
,
5660 else if (TREE_CODE (constructor_type
) == RECORD_TYPE
)
5662 constructor_unfilled_fields
5663 = TREE_CHAIN (constructor_unfilled_fields
);
5665 /* Skip any nameless bit fields. */
5666 while (constructor_unfilled_fields
!= 0
5667 && DECL_C_BIT_FIELD (constructor_unfilled_fields
)
5668 && DECL_NAME (constructor_unfilled_fields
) == 0)
5669 constructor_unfilled_fields
=
5670 TREE_CHAIN (constructor_unfilled_fields
);
5672 else if (TREE_CODE (constructor_type
) == UNION_TYPE
)
5673 constructor_unfilled_fields
= 0;
5675 /* Now output any pending elements which have become next. */
5677 output_pending_init_elements (0);
5680 /* Output any pending elements which have become next.
5681 As we output elements, constructor_unfilled_{fields,index}
5682 advances, which may cause other elements to become next;
5683 if so, they too are output.
5685 If ALL is 0, we return when there are
5686 no more pending elements to output now.
5688 If ALL is 1, we output space as necessary so that
5689 we can output all the pending elements. */
5692 output_pending_init_elements (int all
)
5694 struct init_node
*elt
= constructor_pending_elts
;
5699 /* Look through the whole pending tree.
5700 If we find an element that should be output now,
5701 output it. Otherwise, set NEXT to the element
5702 that comes first among those still pending. */
5707 if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
5709 if (tree_int_cst_equal (elt
->purpose
,
5710 constructor_unfilled_index
))
5711 output_init_element (elt
->value
,
5712 TREE_TYPE (constructor_type
),
5713 constructor_unfilled_index
, 0);
5714 else if (tree_int_cst_lt (constructor_unfilled_index
,
5717 /* Advance to the next smaller node. */
5722 /* We have reached the smallest node bigger than the
5723 current unfilled index. Fill the space first. */
5724 next
= elt
->purpose
;
5730 /* Advance to the next bigger node. */
5735 /* We have reached the biggest node in a subtree. Find
5736 the parent of it, which is the next bigger node. */
5737 while (elt
->parent
&& elt
->parent
->right
== elt
)
5740 if (elt
&& tree_int_cst_lt (constructor_unfilled_index
,
5743 next
= elt
->purpose
;
5749 else if (TREE_CODE (constructor_type
) == RECORD_TYPE
5750 || TREE_CODE (constructor_type
) == UNION_TYPE
)
5752 tree ctor_unfilled_bitpos
, elt_bitpos
;
5754 /* If the current record is complete we are done. */
5755 if (constructor_unfilled_fields
== 0)
5758 ctor_unfilled_bitpos
= bit_position (constructor_unfilled_fields
);
5759 elt_bitpos
= bit_position (elt
->purpose
);
5760 /* We can't compare fields here because there might be empty
5761 fields in between. */
5762 if (tree_int_cst_equal (elt_bitpos
, ctor_unfilled_bitpos
))
5764 constructor_unfilled_fields
= elt
->purpose
;
5765 output_init_element (elt
->value
, TREE_TYPE (elt
->purpose
),
5768 else if (tree_int_cst_lt (ctor_unfilled_bitpos
, elt_bitpos
))
5770 /* Advance to the next smaller node. */
5775 /* We have reached the smallest node bigger than the
5776 current unfilled field. Fill the space first. */
5777 next
= elt
->purpose
;
5783 /* Advance to the next bigger node. */
5788 /* We have reached the biggest node in a subtree. Find
5789 the parent of it, which is the next bigger node. */
5790 while (elt
->parent
&& elt
->parent
->right
== elt
)
5794 && (tree_int_cst_lt (ctor_unfilled_bitpos
,
5795 bit_position (elt
->purpose
))))
5797 next
= elt
->purpose
;
5805 /* Ordinarily return, but not if we want to output all
5806 and there are elements left. */
5807 if (! (all
&& next
!= 0))
5810 /* If it's not incremental, just skip over the gap, so that after
5811 jumping to retry we will output the next successive element. */
5812 if (TREE_CODE (constructor_type
) == RECORD_TYPE
5813 || TREE_CODE (constructor_type
) == UNION_TYPE
)
5814 constructor_unfilled_fields
= next
;
5815 else if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
5816 constructor_unfilled_index
= next
;
5818 /* ELT now points to the node in the pending tree with the next
5819 initializer to output. */
5823 /* Add one non-braced element to the current constructor level.
5824 This adjusts the current position within the constructor's type.
5825 This may also start or terminate implicit levels
5826 to handle a partly-braced initializer.
5828 Once this has found the correct level for the new element,
5829 it calls output_init_element. */
5832 process_init_element (tree value
)
5834 tree orig_value
= value
;
5835 int string_flag
= value
!= 0 && TREE_CODE (value
) == STRING_CST
;
5837 designator_depth
= 0;
5838 designator_errorneous
= 0;
5840 /* Handle superfluous braces around string cst as in
5841 char x[] = {"foo"}; */
5844 && TREE_CODE (constructor_type
) == ARRAY_TYPE
5845 && TREE_CODE (TREE_TYPE (constructor_type
)) == INTEGER_TYPE
5846 && integer_zerop (constructor_unfilled_index
))
5848 if (constructor_stack
->replacement_value
)
5849 error_init ("excess elements in char array initializer");
5850 constructor_stack
->replacement_value
= value
;
5854 if (constructor_stack
->replacement_value
!= 0)
5856 error_init ("excess elements in struct initializer");
5860 /* Ignore elements of a brace group if it is entirely superfluous
5861 and has already been diagnosed. */
5862 if (constructor_type
== 0)
5865 /* If we've exhausted any levels that didn't have braces,
5867 while (constructor_stack
->implicit
)
5869 if ((TREE_CODE (constructor_type
) == RECORD_TYPE
5870 || TREE_CODE (constructor_type
) == UNION_TYPE
)
5871 && constructor_fields
== 0)
5872 process_init_element (pop_init_level (1));
5873 else if (TREE_CODE (constructor_type
) == ARRAY_TYPE
5874 && (constructor_max_index
== 0
5875 || tree_int_cst_lt (constructor_max_index
,
5876 constructor_index
)))
5877 process_init_element (pop_init_level (1));
5882 /* In the case of [LO ... HI] = VALUE, only evaluate VALUE once. */
5883 if (constructor_range_stack
)
5885 /* If value is a compound literal and we'll be just using its
5886 content, don't put it into a SAVE_EXPR. */
5887 if (TREE_CODE (value
) != COMPOUND_LITERAL_EXPR
5888 || !require_constant_value
5890 value
= save_expr (value
);
5895 if (TREE_CODE (constructor_type
) == RECORD_TYPE
)
5898 enum tree_code fieldcode
;
5900 if (constructor_fields
== 0)
5902 pedwarn_init ("excess elements in struct initializer");
5906 fieldtype
= TREE_TYPE (constructor_fields
);
5907 if (fieldtype
!= error_mark_node
)
5908 fieldtype
= TYPE_MAIN_VARIANT (fieldtype
);
5909 fieldcode
= TREE_CODE (fieldtype
);
5911 /* Error for non-static initialization of a flexible array member. */
5912 if (fieldcode
== ARRAY_TYPE
5913 && !require_constant_value
5914 && TYPE_SIZE (fieldtype
) == NULL_TREE
5915 && TREE_CHAIN (constructor_fields
) == NULL_TREE
)
5917 error_init ("non-static initialization of a flexible array member");
5921 /* Accept a string constant to initialize a subarray. */
5923 && fieldcode
== ARRAY_TYPE
5924 && TREE_CODE (TREE_TYPE (fieldtype
)) == INTEGER_TYPE
5927 /* Otherwise, if we have come to a subaggregate,
5928 and we don't have an element of its type, push into it. */
5929 else if (value
!= 0 && !constructor_no_implicit
5930 && value
!= error_mark_node
5931 && TYPE_MAIN_VARIANT (TREE_TYPE (value
)) != fieldtype
5932 && (fieldcode
== RECORD_TYPE
|| fieldcode
== ARRAY_TYPE
5933 || fieldcode
== UNION_TYPE
))
5935 push_init_level (1);
5941 push_member_name (constructor_fields
);
5942 output_init_element (value
, fieldtype
, constructor_fields
, 1);
5943 RESTORE_SPELLING_DEPTH (constructor_depth
);
5946 /* Do the bookkeeping for an element that was
5947 directly output as a constructor. */
5949 /* For a record, keep track of end position of last field. */
5950 if (DECL_SIZE (constructor_fields
))
5951 constructor_bit_index
5952 = size_binop (PLUS_EXPR
,
5953 bit_position (constructor_fields
),
5954 DECL_SIZE (constructor_fields
));
5956 /* If the current field was the first one not yet written out,
5957 it isn't now, so update. */
5958 if (constructor_unfilled_fields
== constructor_fields
)
5960 constructor_unfilled_fields
= TREE_CHAIN (constructor_fields
);
5961 /* Skip any nameless bit fields. */
5962 while (constructor_unfilled_fields
!= 0
5963 && DECL_C_BIT_FIELD (constructor_unfilled_fields
)
5964 && DECL_NAME (constructor_unfilled_fields
) == 0)
5965 constructor_unfilled_fields
=
5966 TREE_CHAIN (constructor_unfilled_fields
);
5970 constructor_fields
= TREE_CHAIN (constructor_fields
);
5971 /* Skip any nameless bit fields at the beginning. */
5972 while (constructor_fields
!= 0
5973 && DECL_C_BIT_FIELD (constructor_fields
)
5974 && DECL_NAME (constructor_fields
) == 0)
5975 constructor_fields
= TREE_CHAIN (constructor_fields
);
5977 else if (TREE_CODE (constructor_type
) == UNION_TYPE
)
5980 enum tree_code fieldcode
;
5982 if (constructor_fields
== 0)
5984 pedwarn_init ("excess elements in union initializer");
5988 fieldtype
= TREE_TYPE (constructor_fields
);
5989 if (fieldtype
!= error_mark_node
)
5990 fieldtype
= TYPE_MAIN_VARIANT (fieldtype
);
5991 fieldcode
= TREE_CODE (fieldtype
);
5993 /* Warn that traditional C rejects initialization of unions.
5994 We skip the warning if the value is zero. This is done
5995 under the assumption that the zero initializer in user
5996 code appears conditioned on e.g. __STDC__ to avoid
5997 "missing initializer" warnings and relies on default
5998 initialization to zero in the traditional C case.
5999 We also skip the warning if the initializer is designated,
6000 again on the assumption that this must be conditional on
6001 __STDC__ anyway (and we've already complained about the
6002 member-designator already). */
6003 if (warn_traditional
&& !in_system_header
&& !constructor_designated
6004 && !(value
&& (integer_zerop (value
) || real_zerop (value
))))
6005 warning ("traditional C rejects initialization of unions");
6007 /* Accept a string constant to initialize a subarray. */
6009 && fieldcode
== ARRAY_TYPE
6010 && TREE_CODE (TREE_TYPE (fieldtype
)) == INTEGER_TYPE
6013 /* Otherwise, if we have come to a subaggregate,
6014 and we don't have an element of its type, push into it. */
6015 else if (value
!= 0 && !constructor_no_implicit
6016 && value
!= error_mark_node
6017 && TYPE_MAIN_VARIANT (TREE_TYPE (value
)) != fieldtype
6018 && (fieldcode
== RECORD_TYPE
|| fieldcode
== ARRAY_TYPE
6019 || fieldcode
== UNION_TYPE
))
6021 push_init_level (1);
6027 push_member_name (constructor_fields
);
6028 output_init_element (value
, fieldtype
, constructor_fields
, 1);
6029 RESTORE_SPELLING_DEPTH (constructor_depth
);
6032 /* Do the bookkeeping for an element that was
6033 directly output as a constructor. */
6035 constructor_bit_index
= DECL_SIZE (constructor_fields
);
6036 constructor_unfilled_fields
= TREE_CHAIN (constructor_fields
);
6039 constructor_fields
= 0;
6041 else if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
6043 tree elttype
= TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type
));
6044 enum tree_code eltcode
= TREE_CODE (elttype
);
6046 /* Accept a string constant to initialize a subarray. */
6048 && eltcode
== ARRAY_TYPE
6049 && TREE_CODE (TREE_TYPE (elttype
)) == INTEGER_TYPE
6052 /* Otherwise, if we have come to a subaggregate,
6053 and we don't have an element of its type, push into it. */
6054 else if (value
!= 0 && !constructor_no_implicit
6055 && value
!= error_mark_node
6056 && TYPE_MAIN_VARIANT (TREE_TYPE (value
)) != elttype
6057 && (eltcode
== RECORD_TYPE
|| eltcode
== ARRAY_TYPE
6058 || eltcode
== UNION_TYPE
))
6060 push_init_level (1);
6064 if (constructor_max_index
!= 0
6065 && (tree_int_cst_lt (constructor_max_index
, constructor_index
)
6066 || integer_all_onesp (constructor_max_index
)))
6068 pedwarn_init ("excess elements in array initializer");
6072 /* Now output the actual element. */
6075 push_array_bounds (tree_low_cst (constructor_index
, 0));
6076 output_init_element (value
, elttype
, constructor_index
, 1);
6077 RESTORE_SPELLING_DEPTH (constructor_depth
);
6081 = size_binop (PLUS_EXPR
, constructor_index
, bitsize_one_node
);
6084 /* If we are doing the bookkeeping for an element that was
6085 directly output as a constructor, we must update
6086 constructor_unfilled_index. */
6087 constructor_unfilled_index
= constructor_index
;
6089 else if (TREE_CODE (constructor_type
) == VECTOR_TYPE
)
6091 tree elttype
= TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type
));
6093 /* Do a basic check of initializer size. Note that vectors
6094 always have a fixed size derived from their type. */
6095 if (tree_int_cst_lt (constructor_max_index
, constructor_index
))
6097 pedwarn_init ("excess elements in vector initializer");
6101 /* Now output the actual element. */
6103 output_init_element (value
, elttype
, constructor_index
, 1);
6106 = size_binop (PLUS_EXPR
, constructor_index
, bitsize_one_node
);
6109 /* If we are doing the bookkeeping for an element that was
6110 directly output as a constructor, we must update
6111 constructor_unfilled_index. */
6112 constructor_unfilled_index
= constructor_index
;
6115 /* Handle the sole element allowed in a braced initializer
6116 for a scalar variable. */
6117 else if (constructor_fields
== 0)
6119 pedwarn_init ("excess elements in scalar initializer");
6125 output_init_element (value
, constructor_type
, NULL_TREE
, 1);
6126 constructor_fields
= 0;
6129 /* Handle range initializers either at this level or anywhere higher
6130 in the designator stack. */
6131 if (constructor_range_stack
)
6133 struct constructor_range_stack
*p
, *range_stack
;
6136 range_stack
= constructor_range_stack
;
6137 constructor_range_stack
= 0;
6138 while (constructor_stack
!= range_stack
->stack
)
6140 if (!constructor_stack
->implicit
)
6142 process_init_element (pop_init_level (1));
6144 for (p
= range_stack
;
6145 !p
->range_end
|| tree_int_cst_equal (p
->index
, p
->range_end
);
6148 if (!constructor_stack
->implicit
)
6150 process_init_element (pop_init_level (1));
6153 p
->index
= size_binop (PLUS_EXPR
, p
->index
, bitsize_one_node
);
6154 if (tree_int_cst_equal (p
->index
, p
->range_end
) && !p
->prev
)
6159 constructor_index
= p
->index
;
6160 constructor_fields
= p
->fields
;
6161 if (finish
&& p
->range_end
&& p
->index
== p
->range_start
)
6169 push_init_level (2);
6170 p
->stack
= constructor_stack
;
6171 if (p
->range_end
&& tree_int_cst_equal (p
->index
, p
->range_end
))
6172 p
->index
= p
->range_start
;
6176 constructor_range_stack
= range_stack
;
6183 constructor_range_stack
= 0;
6186 /* Build a simple asm-statement, from one string literal. */
6188 simple_asm_stmt (tree expr
)
6192 if (TREE_CODE (expr
) == ADDR_EXPR
)
6193 expr
= TREE_OPERAND (expr
, 0);
6195 if (TREE_CODE (expr
) == STRING_CST
)
6199 /* Simple asm statements are treated as volatile. */
6200 stmt
= add_stmt (build_stmt (ASM_STMT
, ridpointers
[(int) RID_VOLATILE
],
6201 expr
, NULL_TREE
, NULL_TREE
, NULL_TREE
));
6202 ASM_INPUT_P (stmt
) = 1;
6206 error ("argument of `asm' is not a constant string");
6210 /* Build an asm-statement, whose components are a CV_QUALIFIER, a
6211 STRING, some OUTPUTS, some INPUTS, and some CLOBBERS. */
6214 build_asm_stmt (tree cv_qualifier
, tree string
, tree outputs
, tree inputs
,
6219 if (TREE_CODE (string
) != STRING_CST
)
6221 error ("asm template is not a string constant");
6225 if (cv_qualifier
!= NULL_TREE
6226 && cv_qualifier
!= ridpointers
[(int) RID_VOLATILE
])
6228 warning ("%s qualifier ignored on asm",
6229 IDENTIFIER_POINTER (cv_qualifier
));
6230 cv_qualifier
= NULL_TREE
;
6233 /* We can remove output conversions that change the type,
6234 but not the mode. */
6235 for (tail
= outputs
; tail
; tail
= TREE_CHAIN (tail
))
6237 tree output
= TREE_VALUE (tail
);
6239 STRIP_NOPS (output
);
6240 TREE_VALUE (tail
) = output
;
6242 /* Allow conversions as LHS here. build_modify_expr as called below
6243 will do the right thing with them. */
6244 while (TREE_CODE (output
) == NOP_EXPR
6245 || TREE_CODE (output
) == CONVERT_EXPR
6246 || TREE_CODE (output
) == FLOAT_EXPR
6247 || TREE_CODE (output
) == FIX_TRUNC_EXPR
6248 || TREE_CODE (output
) == FIX_FLOOR_EXPR
6249 || TREE_CODE (output
) == FIX_ROUND_EXPR
6250 || TREE_CODE (output
) == FIX_CEIL_EXPR
)
6251 output
= TREE_OPERAND (output
, 0);
6253 lvalue_or_else (TREE_VALUE (tail
), "invalid lvalue in asm statement");
6256 /* Remove output conversions that change the type but not the mode. */
6257 for (tail
= outputs
; tail
; tail
= TREE_CHAIN (tail
))
6259 tree output
= TREE_VALUE (tail
);
6260 STRIP_NOPS (output
);
6261 TREE_VALUE (tail
) = output
;
6264 /* Perform default conversions on array and function inputs.
6265 Don't do this for other types as it would screw up operands
6266 expected to be in memory. */
6267 for (tail
= inputs
; tail
; tail
= TREE_CHAIN (tail
))
6268 TREE_VALUE (tail
) = default_function_array_conversion (TREE_VALUE (tail
));
6270 return add_stmt (build_stmt (ASM_STMT
, cv_qualifier
, string
,
6271 outputs
, inputs
, clobbers
));
6274 /* Expand an ASM statement with operands, handling output operands
6275 that are not variables or INDIRECT_REFS by transforming such
6276 cases into cases that expand_asm_operands can handle.
6278 Arguments are same as for expand_asm_operands. */
6281 c_expand_asm_operands (tree string
, tree outputs
, tree inputs
,
6282 tree clobbers
, int vol
, location_t locus
)
6284 int noutputs
= list_length (outputs
);
6286 /* o[I] is the place that output number I should be written. */
6287 tree
*o
= alloca (noutputs
* sizeof (tree
));
6290 /* Record the contents of OUTPUTS before it is modified. */
6291 for (i
= 0, tail
= outputs
; tail
; tail
= TREE_CHAIN (tail
), i
++)
6293 o
[i
] = TREE_VALUE (tail
);
6294 if (o
[i
] == error_mark_node
)
6298 /* Generate the ASM_OPERANDS insn; store into the TREE_VALUEs of
6299 OUTPUTS some trees for where the values were actually stored. */
6300 expand_asm_operands (string
, outputs
, inputs
, clobbers
, vol
, locus
);
6302 /* Copy all the intermediate outputs into the specified outputs. */
6303 for (i
= 0, tail
= outputs
; tail
; tail
= TREE_CHAIN (tail
), i
++)
6305 if (o
[i
] != TREE_VALUE (tail
))
6307 expand_expr (build_modify_expr (o
[i
], NOP_EXPR
, TREE_VALUE (tail
)),
6308 NULL_RTX
, VOIDmode
, EXPAND_NORMAL
);
6311 /* Restore the original value so that it's correct the next
6312 time we expand this function. */
6313 TREE_VALUE (tail
) = o
[i
];
6315 /* Detect modification of read-only values.
6316 (Otherwise done by build_modify_expr.) */
6319 tree type
= TREE_TYPE (o
[i
]);
6320 if (TREE_READONLY (o
[i
])
6321 || TYPE_READONLY (type
)
6322 || ((TREE_CODE (type
) == RECORD_TYPE
6323 || TREE_CODE (type
) == UNION_TYPE
)
6324 && C_TYPE_FIELDS_READONLY (type
)))
6325 readonly_warning (o
[i
], "modification by `asm'");
6329 /* Those MODIFY_EXPRs could do autoincrements. */
6333 /* Expand a C `return' statement.
6334 RETVAL is the expression for what to return,
6335 or a null pointer for `return;' with no value. */
6338 c_expand_return (tree retval
)
6340 tree valtype
= TREE_TYPE (TREE_TYPE (current_function_decl
));
6342 if (TREE_THIS_VOLATILE (current_function_decl
))
6343 warning ("function declared `noreturn' has a `return' statement");
6347 current_function_returns_null
= 1;
6348 if ((warn_return_type
|| flag_isoc99
)
6349 && valtype
!= 0 && TREE_CODE (valtype
) != VOID_TYPE
)
6350 pedwarn_c99 ("`return' with no value, in function returning non-void");
6352 else if (valtype
== 0 || TREE_CODE (valtype
) == VOID_TYPE
)
6354 current_function_returns_null
= 1;
6355 if (pedantic
|| TREE_CODE (TREE_TYPE (retval
)) != VOID_TYPE
)
6356 pedwarn ("`return' with a value, in function returning void");
6360 tree t
= convert_for_assignment (valtype
, retval
, _("return"),
6361 NULL_TREE
, NULL_TREE
, 0);
6362 tree res
= DECL_RESULT (current_function_decl
);
6365 current_function_returns_value
= 1;
6366 if (t
== error_mark_node
)
6369 inner
= t
= convert (TREE_TYPE (res
), t
);
6371 /* Strip any conversions, additions, and subtractions, and see if
6372 we are returning the address of a local variable. Warn if so. */
6375 switch (TREE_CODE (inner
))
6377 case NOP_EXPR
: case NON_LVALUE_EXPR
: case CONVERT_EXPR
:
6379 inner
= TREE_OPERAND (inner
, 0);
6383 /* If the second operand of the MINUS_EXPR has a pointer
6384 type (or is converted from it), this may be valid, so
6385 don't give a warning. */
6387 tree op1
= TREE_OPERAND (inner
, 1);
6389 while (! POINTER_TYPE_P (TREE_TYPE (op1
))
6390 && (TREE_CODE (op1
) == NOP_EXPR
6391 || TREE_CODE (op1
) == NON_LVALUE_EXPR
6392 || TREE_CODE (op1
) == CONVERT_EXPR
))
6393 op1
= TREE_OPERAND (op1
, 0);
6395 if (POINTER_TYPE_P (TREE_TYPE (op1
)))
6398 inner
= TREE_OPERAND (inner
, 0);
6403 inner
= TREE_OPERAND (inner
, 0);
6405 while (TREE_CODE_CLASS (TREE_CODE (inner
)) == 'r')
6406 inner
= TREE_OPERAND (inner
, 0);
6408 if (TREE_CODE (inner
) == VAR_DECL
6409 && ! DECL_EXTERNAL (inner
)
6410 && ! TREE_STATIC (inner
)
6411 && DECL_CONTEXT (inner
) == current_function_decl
)
6412 warning ("function returns address of local variable");
6422 retval
= build (MODIFY_EXPR
, TREE_TYPE (res
), res
, t
);
6425 return add_stmt (build_return_stmt (retval
));
6429 /* The SWITCH_STMT being built. */
6431 /* A splay-tree mapping the low element of a case range to the high
6432 element, or NULL_TREE if there is no high element. Used to
6433 determine whether or not a new case label duplicates an old case
6434 label. We need a tree, rather than simply a hash table, because
6435 of the GNU case range extension. */
6437 /* The next node on the stack. */
6438 struct c_switch
*next
;
6441 /* A stack of the currently active switch statements. The innermost
6442 switch statement is on the top of the stack. There is no need to
6443 mark the stack for garbage collection because it is only active
6444 during the processing of the body of a function, and we never
6445 collect at that point. */
6447 static struct c_switch
*switch_stack
;
6449 /* Start a C switch statement, testing expression EXP. Return the new
6453 c_start_case (tree exp
)
6455 enum tree_code code
;
6456 tree type
, orig_type
= error_mark_node
;
6457 struct c_switch
*cs
;
6459 if (exp
!= error_mark_node
)
6461 code
= TREE_CODE (TREE_TYPE (exp
));
6462 orig_type
= TREE_TYPE (exp
);
6464 if (! INTEGRAL_TYPE_P (orig_type
)
6465 && code
!= ERROR_MARK
)
6467 error ("switch quantity not an integer");
6468 exp
= integer_zero_node
;
6472 type
= TYPE_MAIN_VARIANT (TREE_TYPE (exp
));
6474 if (warn_traditional
&& !in_system_header
6475 && (type
== long_integer_type_node
6476 || type
== long_unsigned_type_node
))
6477 warning ("`long' switch expression not converted to `int' in ISO C");
6479 exp
= default_conversion (exp
);
6480 type
= TREE_TYPE (exp
);
6484 /* Add this new SWITCH_STMT to the stack. */
6485 cs
= xmalloc (sizeof (*cs
));
6486 cs
->switch_stmt
= build_stmt (SWITCH_STMT
, exp
, NULL_TREE
, orig_type
);
6487 cs
->cases
= splay_tree_new (case_compare
, NULL
, NULL
);
6488 cs
->next
= switch_stack
;
6491 return add_stmt (switch_stack
->switch_stmt
);
6494 /* Process a case label. */
6497 do_case (tree low_value
, tree high_value
)
6499 tree label
= NULL_TREE
;
6503 bool switch_was_empty_p
= (SWITCH_BODY (switch_stack
->switch_stmt
) == NULL_TREE
);
6505 label
= c_add_case_label (switch_stack
->cases
,
6506 SWITCH_COND (switch_stack
->switch_stmt
),
6507 low_value
, high_value
);
6508 if (label
== error_mark_node
)
6510 else if (switch_was_empty_p
)
6512 /* Attach the first case label to the SWITCH_BODY. */
6513 SWITCH_BODY (switch_stack
->switch_stmt
) = TREE_CHAIN (switch_stack
->switch_stmt
);
6514 TREE_CHAIN (switch_stack
->switch_stmt
) = NULL_TREE
;
6518 error ("case label not within a switch statement");
6520 error ("`default' label not within a switch statement");
6525 /* Finish the switch statement. */
6528 c_finish_case (void)
6530 struct c_switch
*cs
= switch_stack
;
6532 /* Rechain the next statements to the SWITCH_STMT. */
6533 last_tree
= cs
->switch_stmt
;
6535 /* Pop the stack. */
6536 switch_stack
= switch_stack
->next
;
6537 splay_tree_delete (cs
->cases
);
6541 /* Build a binary-operation expression without default conversions.
6542 CODE is the kind of expression to build.
6543 This function differs from `build' in several ways:
6544 the data type of the result is computed and recorded in it,
6545 warnings are generated if arg data types are invalid,
6546 special handling for addition and subtraction of pointers is known,
6547 and some optimization is done (operations on narrow ints
6548 are done in the narrower type when that gives the same result).
6549 Constant folding is also done before the result is returned.
6551 Note that the operands will never have enumeral types, or function
6552 or array types, because either they will have the default conversions
6553 performed or they have both just been converted to some other type in which
6554 the arithmetic is to be done. */
6557 build_binary_op (enum tree_code code
, tree orig_op0
, tree orig_op1
,
6561 enum tree_code code0
, code1
;
6564 /* Expression code to give to the expression when it is built.
6565 Normally this is CODE, which is what the caller asked for,
6566 but in some special cases we change it. */
6567 enum tree_code resultcode
= code
;
6569 /* Data type in which the computation is to be performed.
6570 In the simplest cases this is the common type of the arguments. */
6571 tree result_type
= NULL
;
6573 /* Nonzero means operands have already been type-converted
6574 in whatever way is necessary.
6575 Zero means they need to be converted to RESULT_TYPE. */
6578 /* Nonzero means create the expression with this type, rather than
6580 tree build_type
= 0;
6582 /* Nonzero means after finally constructing the expression
6583 convert it to this type. */
6584 tree final_type
= 0;
6586 /* Nonzero if this is an operation like MIN or MAX which can
6587 safely be computed in short if both args are promoted shorts.
6588 Also implies COMMON.
6589 -1 indicates a bitwise operation; this makes a difference
6590 in the exact conditions for when it is safe to do the operation
6591 in a narrower mode. */
6594 /* Nonzero if this is a comparison operation;
6595 if both args are promoted shorts, compare the original shorts.
6596 Also implies COMMON. */
6597 int short_compare
= 0;
6599 /* Nonzero if this is a right-shift operation, which can be computed on the
6600 original short and then promoted if the operand is a promoted short. */
6601 int short_shift
= 0;
6603 /* Nonzero means set RESULT_TYPE to the common type of the args. */
6608 op0
= default_conversion (orig_op0
);
6609 op1
= default_conversion (orig_op1
);
6617 type0
= TREE_TYPE (op0
);
6618 type1
= TREE_TYPE (op1
);
6620 /* The expression codes of the data types of the arguments tell us
6621 whether the arguments are integers, floating, pointers, etc. */
6622 code0
= TREE_CODE (type0
);
6623 code1
= TREE_CODE (type1
);
6625 /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
6626 STRIP_TYPE_NOPS (op0
);
6627 STRIP_TYPE_NOPS (op1
);
6629 /* If an error was already reported for one of the arguments,
6630 avoid reporting another error. */
6632 if (code0
== ERROR_MARK
|| code1
== ERROR_MARK
)
6633 return error_mark_node
;
6638 /* Handle the pointer + int case. */
6639 if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
6640 return pointer_int_sum (PLUS_EXPR
, op0
, op1
);
6641 else if (code1
== POINTER_TYPE
&& code0
== INTEGER_TYPE
)
6642 return pointer_int_sum (PLUS_EXPR
, op1
, op0
);
6648 /* Subtraction of two similar pointers.
6649 We must subtract them as integers, then divide by object size. */
6650 if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
6651 && comp_target_types (type0
, type1
, 1))
6652 return pointer_diff (op0
, op1
);
6653 /* Handle pointer minus int. Just like pointer plus int. */
6654 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
6655 return pointer_int_sum (MINUS_EXPR
, op0
, op1
);
6664 case TRUNC_DIV_EXPR
:
6666 case FLOOR_DIV_EXPR
:
6667 case ROUND_DIV_EXPR
:
6668 case EXACT_DIV_EXPR
:
6669 /* Floating point division by zero is a legitimate way to obtain
6670 infinities and NaNs. */
6671 if (warn_div_by_zero
&& skip_evaluation
== 0 && integer_zerop (op1
))
6672 warning ("division by zero");
6674 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
6675 || code0
== COMPLEX_TYPE
|| code0
== VECTOR_TYPE
)
6676 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
6677 || code1
== COMPLEX_TYPE
|| code1
== VECTOR_TYPE
))
6679 if (!(code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
))
6680 resultcode
= RDIV_EXPR
;
6682 /* Although it would be tempting to shorten always here, that
6683 loses on some targets, since the modulo instruction is
6684 undefined if the quotient can't be represented in the
6685 computation mode. We shorten only if unsigned or if
6686 dividing by something we know != -1. */
6687 shorten
= (TREE_UNSIGNED (TREE_TYPE (orig_op0
))
6688 || (TREE_CODE (op1
) == INTEGER_CST
6689 && ! integer_all_onesp (op1
)));
6697 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
6699 else if (code0
== VECTOR_TYPE
&& code1
== VECTOR_TYPE
)
6703 case TRUNC_MOD_EXPR
:
6704 case FLOOR_MOD_EXPR
:
6705 if (warn_div_by_zero
&& skip_evaluation
== 0 && integer_zerop (op1
))
6706 warning ("division by zero");
6708 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
6710 /* Although it would be tempting to shorten always here, that loses
6711 on some targets, since the modulo instruction is undefined if the
6712 quotient can't be represented in the computation mode. We shorten
6713 only if unsigned or if dividing by something we know != -1. */
6714 shorten
= (TREE_UNSIGNED (TREE_TYPE (orig_op0
))
6715 || (TREE_CODE (op1
) == INTEGER_CST
6716 && ! integer_all_onesp (op1
)));
6721 case TRUTH_ANDIF_EXPR
:
6722 case TRUTH_ORIF_EXPR
:
6723 case TRUTH_AND_EXPR
:
6725 case TRUTH_XOR_EXPR
:
6726 if ((code0
== INTEGER_TYPE
|| code0
== POINTER_TYPE
6727 || code0
== REAL_TYPE
|| code0
== COMPLEX_TYPE
)
6728 && (code1
== INTEGER_TYPE
|| code1
== POINTER_TYPE
6729 || code1
== REAL_TYPE
|| code1
== COMPLEX_TYPE
))
6731 /* Result of these operations is always an int,
6732 but that does not mean the operands should be
6733 converted to ints! */
6734 result_type
= integer_type_node
;
6735 op0
= c_common_truthvalue_conversion (op0
);
6736 op1
= c_common_truthvalue_conversion (op1
);
6741 /* Shift operations: result has same type as first operand;
6742 always convert second operand to int.
6743 Also set SHORT_SHIFT if shifting rightward. */
6746 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
6748 if (TREE_CODE (op1
) == INTEGER_CST
&& skip_evaluation
== 0)
6750 if (tree_int_cst_sgn (op1
) < 0)
6751 warning ("right shift count is negative");
6754 if (! integer_zerop (op1
))
6757 if (compare_tree_int (op1
, TYPE_PRECISION (type0
)) >= 0)
6758 warning ("right shift count >= width of type");
6762 /* Use the type of the value to be shifted. */
6763 result_type
= type0
;
6764 /* Convert the shift-count to an integer, regardless of size
6765 of value being shifted. */
6766 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
6767 op1
= convert (integer_type_node
, op1
);
6768 /* Avoid converting op1 to result_type later. */
6774 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
6776 if (TREE_CODE (op1
) == INTEGER_CST
&& skip_evaluation
== 0)
6778 if (tree_int_cst_sgn (op1
) < 0)
6779 warning ("left shift count is negative");
6781 else if (compare_tree_int (op1
, TYPE_PRECISION (type0
)) >= 0)
6782 warning ("left shift count >= width of type");
6785 /* Use the type of the value to be shifted. */
6786 result_type
= type0
;
6787 /* Convert the shift-count to an integer, regardless of size
6788 of value being shifted. */
6789 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
6790 op1
= convert (integer_type_node
, op1
);
6791 /* Avoid converting op1 to result_type later. */
6798 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
6800 if (TREE_CODE (op1
) == INTEGER_CST
&& skip_evaluation
== 0)
6802 if (tree_int_cst_sgn (op1
) < 0)
6803 warning ("shift count is negative");
6804 else if (compare_tree_int (op1
, TYPE_PRECISION (type0
)) >= 0)
6805 warning ("shift count >= width of type");
6808 /* Use the type of the value to be shifted. */
6809 result_type
= type0
;
6810 /* Convert the shift-count to an integer, regardless of size
6811 of value being shifted. */
6812 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
6813 op1
= convert (integer_type_node
, op1
);
6814 /* Avoid converting op1 to result_type later. */
6821 if (warn_float_equal
&& (code0
== REAL_TYPE
|| code1
== REAL_TYPE
))
6822 warning ("comparing floating point with == or != is unsafe");
6823 /* Result of comparison is always int,
6824 but don't convert the args to int! */
6825 build_type
= integer_type_node
;
6826 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
6827 || code0
== COMPLEX_TYPE
6828 || code0
== VECTOR_TYPE
)
6829 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
6830 || code1
== COMPLEX_TYPE
6831 || code1
== VECTOR_TYPE
))
6833 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
6835 tree tt0
= TREE_TYPE (type0
);
6836 tree tt1
= TREE_TYPE (type1
);
6837 /* Anything compares with void *. void * compares with anything.
6838 Otherwise, the targets must be compatible
6839 and both must be object or both incomplete. */
6840 if (comp_target_types (type0
, type1
, 1))
6841 result_type
= common_type (type0
, type1
);
6842 else if (VOID_TYPE_P (tt0
))
6844 /* op0 != orig_op0 detects the case of something
6845 whose value is 0 but which isn't a valid null ptr const. */
6846 if (pedantic
&& (!integer_zerop (op0
) || op0
!= orig_op0
)
6847 && TREE_CODE (tt1
) == FUNCTION_TYPE
)
6848 pedwarn ("ISO C forbids comparison of `void *' with function pointer");
6850 else if (VOID_TYPE_P (tt1
))
6852 if (pedantic
&& (!integer_zerop (op1
) || op1
!= orig_op1
)
6853 && TREE_CODE (tt0
) == FUNCTION_TYPE
)
6854 pedwarn ("ISO C forbids comparison of `void *' with function pointer");
6857 pedwarn ("comparison of distinct pointer types lacks a cast");
6859 if (result_type
== NULL_TREE
)
6860 result_type
= ptr_type_node
;
6862 else if (code0
== POINTER_TYPE
&& TREE_CODE (op1
) == INTEGER_CST
6863 && integer_zerop (op1
))
6864 result_type
= type0
;
6865 else if (code1
== POINTER_TYPE
&& TREE_CODE (op0
) == INTEGER_CST
6866 && integer_zerop (op0
))
6867 result_type
= type1
;
6868 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
6870 result_type
= type0
;
6871 pedwarn ("comparison between pointer and integer");
6873 else if (code0
== INTEGER_TYPE
&& code1
== POINTER_TYPE
)
6875 result_type
= type1
;
6876 pedwarn ("comparison between pointer and integer");
6882 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
6883 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
6885 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
6887 if (comp_target_types (type0
, type1
, 1))
6889 result_type
= common_type (type0
, type1
);
6891 && TREE_CODE (TREE_TYPE (type0
)) == FUNCTION_TYPE
)
6892 pedwarn ("ISO C forbids ordered comparisons of pointers to functions");
6896 result_type
= ptr_type_node
;
6897 pedwarn ("comparison of distinct pointer types lacks a cast");
6906 build_type
= integer_type_node
;
6907 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
)
6908 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
))
6910 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
6912 if (comp_target_types (type0
, type1
, 1))
6914 result_type
= common_type (type0
, type1
);
6915 if (!COMPLETE_TYPE_P (TREE_TYPE (type0
))
6916 != !COMPLETE_TYPE_P (TREE_TYPE (type1
)))
6917 pedwarn ("comparison of complete and incomplete pointers");
6919 && TREE_CODE (TREE_TYPE (type0
)) == FUNCTION_TYPE
)
6920 pedwarn ("ISO C forbids ordered comparisons of pointers to functions");
6924 result_type
= ptr_type_node
;
6925 pedwarn ("comparison of distinct pointer types lacks a cast");
6928 else if (code0
== POINTER_TYPE
&& TREE_CODE (op1
) == INTEGER_CST
6929 && integer_zerop (op1
))
6931 result_type
= type0
;
6932 if (pedantic
|| extra_warnings
)
6933 pedwarn ("ordered comparison of pointer with integer zero");
6935 else if (code1
== POINTER_TYPE
&& TREE_CODE (op0
) == INTEGER_CST
6936 && integer_zerop (op0
))
6938 result_type
= type1
;
6940 pedwarn ("ordered comparison of pointer with integer zero");
6942 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
6944 result_type
= type0
;
6945 pedwarn ("comparison between pointer and integer");
6947 else if (code0
== INTEGER_TYPE
&& code1
== POINTER_TYPE
)
6949 result_type
= type1
;
6950 pedwarn ("comparison between pointer and integer");
6954 case UNORDERED_EXPR
:
6961 build_type
= integer_type_node
;
6962 if (code0
!= REAL_TYPE
|| code1
!= REAL_TYPE
)
6964 error ("unordered comparison on non-floating point argument");
6965 return error_mark_node
;
6974 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
|| code0
== COMPLEX_TYPE
6975 || code0
== VECTOR_TYPE
)
6977 (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
|| code1
== COMPLEX_TYPE
6978 || code1
== VECTOR_TYPE
))
6980 int none_complex
= (code0
!= COMPLEX_TYPE
&& code1
!= COMPLEX_TYPE
);
6982 if (shorten
|| common
|| short_compare
)
6983 result_type
= common_type (type0
, type1
);
6985 /* For certain operations (which identify themselves by shorten != 0)
6986 if both args were extended from the same smaller type,
6987 do the arithmetic in that type and then extend.
6989 shorten !=0 and !=1 indicates a bitwise operation.
6990 For them, this optimization is safe only if
6991 both args are zero-extended or both are sign-extended.
6992 Otherwise, we might change the result.
6993 Eg, (short)-1 | (unsigned short)-1 is (int)-1
6994 but calculated in (unsigned short) it would be (unsigned short)-1. */
6996 if (shorten
&& none_complex
)
6998 int unsigned0
, unsigned1
;
6999 tree arg0
= get_narrower (op0
, &unsigned0
);
7000 tree arg1
= get_narrower (op1
, &unsigned1
);
7001 /* UNS is 1 if the operation to be done is an unsigned one. */
7002 int uns
= TREE_UNSIGNED (result_type
);
7005 final_type
= result_type
;
7007 /* Handle the case that OP0 (or OP1) does not *contain* a conversion
7008 but it *requires* conversion to FINAL_TYPE. */
7010 if ((TYPE_PRECISION (TREE_TYPE (op0
))
7011 == TYPE_PRECISION (TREE_TYPE (arg0
)))
7012 && TREE_TYPE (op0
) != final_type
)
7013 unsigned0
= TREE_UNSIGNED (TREE_TYPE (op0
));
7014 if ((TYPE_PRECISION (TREE_TYPE (op1
))
7015 == TYPE_PRECISION (TREE_TYPE (arg1
)))
7016 && TREE_TYPE (op1
) != final_type
)
7017 unsigned1
= TREE_UNSIGNED (TREE_TYPE (op1
));
7019 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
7021 /* For bitwise operations, signedness of nominal type
7022 does not matter. Consider only how operands were extended. */
7026 /* Note that in all three cases below we refrain from optimizing
7027 an unsigned operation on sign-extended args.
7028 That would not be valid. */
7030 /* Both args variable: if both extended in same way
7031 from same width, do it in that width.
7032 Do it unsigned if args were zero-extended. */
7033 if ((TYPE_PRECISION (TREE_TYPE (arg0
))
7034 < TYPE_PRECISION (result_type
))
7035 && (TYPE_PRECISION (TREE_TYPE (arg1
))
7036 == TYPE_PRECISION (TREE_TYPE (arg0
)))
7037 && unsigned0
== unsigned1
7038 && (unsigned0
|| !uns
))
7040 = c_common_signed_or_unsigned_type
7041 (unsigned0
, common_type (TREE_TYPE (arg0
), TREE_TYPE (arg1
)));
7042 else if (TREE_CODE (arg0
) == INTEGER_CST
7043 && (unsigned1
|| !uns
)
7044 && (TYPE_PRECISION (TREE_TYPE (arg1
))
7045 < TYPE_PRECISION (result_type
))
7047 = c_common_signed_or_unsigned_type (unsigned1
,
7049 int_fits_type_p (arg0
, type
)))
7051 else if (TREE_CODE (arg1
) == INTEGER_CST
7052 && (unsigned0
|| !uns
)
7053 && (TYPE_PRECISION (TREE_TYPE (arg0
))
7054 < TYPE_PRECISION (result_type
))
7056 = c_common_signed_or_unsigned_type (unsigned0
,
7058 int_fits_type_p (arg1
, type
)))
7062 /* Shifts can be shortened if shifting right. */
7067 tree arg0
= get_narrower (op0
, &unsigned_arg
);
7069 final_type
= result_type
;
7071 if (arg0
== op0
&& final_type
== TREE_TYPE (op0
))
7072 unsigned_arg
= TREE_UNSIGNED (TREE_TYPE (op0
));
7074 if (TYPE_PRECISION (TREE_TYPE (arg0
)) < TYPE_PRECISION (result_type
)
7075 /* We can shorten only if the shift count is less than the
7076 number of bits in the smaller type size. */
7077 && compare_tree_int (op1
, TYPE_PRECISION (TREE_TYPE (arg0
))) < 0
7078 /* We cannot drop an unsigned shift after sign-extension. */
7079 && (!TREE_UNSIGNED (final_type
) || unsigned_arg
))
7081 /* Do an unsigned shift if the operand was zero-extended. */
7083 = c_common_signed_or_unsigned_type (unsigned_arg
,
7085 /* Convert value-to-be-shifted to that type. */
7086 if (TREE_TYPE (op0
) != result_type
)
7087 op0
= convert (result_type
, op0
);
7092 /* Comparison operations are shortened too but differently.
7093 They identify themselves by setting short_compare = 1. */
7097 /* Don't write &op0, etc., because that would prevent op0
7098 from being kept in a register.
7099 Instead, make copies of the our local variables and
7100 pass the copies by reference, then copy them back afterward. */
7101 tree xop0
= op0
, xop1
= op1
, xresult_type
= result_type
;
7102 enum tree_code xresultcode
= resultcode
;
7104 = shorten_compare (&xop0
, &xop1
, &xresult_type
, &xresultcode
);
7109 op0
= xop0
, op1
= xop1
;
7111 resultcode
= xresultcode
;
7113 if (warn_sign_compare
&& skip_evaluation
== 0)
7115 int op0_signed
= ! TREE_UNSIGNED (TREE_TYPE (orig_op0
));
7116 int op1_signed
= ! TREE_UNSIGNED (TREE_TYPE (orig_op1
));
7117 int unsignedp0
, unsignedp1
;
7118 tree primop0
= get_narrower (op0
, &unsignedp0
);
7119 tree primop1
= get_narrower (op1
, &unsignedp1
);
7123 STRIP_TYPE_NOPS (xop0
);
7124 STRIP_TYPE_NOPS (xop1
);
7126 /* Give warnings for comparisons between signed and unsigned
7127 quantities that may fail.
7129 Do the checking based on the original operand trees, so that
7130 casts will be considered, but default promotions won't be.
7132 Do not warn if the comparison is being done in a signed type,
7133 since the signed type will only be chosen if it can represent
7134 all the values of the unsigned type. */
7135 if (! TREE_UNSIGNED (result_type
))
7137 /* Do not warn if both operands are the same signedness. */
7138 else if (op0_signed
== op1_signed
)
7145 sop
= xop0
, uop
= xop1
;
7147 sop
= xop1
, uop
= xop0
;
7149 /* Do not warn if the signed quantity is an
7150 unsuffixed integer literal (or some static
7151 constant expression involving such literals or a
7152 conditional expression involving such literals)
7153 and it is non-negative. */
7154 if (c_tree_expr_nonnegative_p (sop
))
7156 /* Do not warn if the comparison is an equality operation,
7157 the unsigned quantity is an integral constant, and it
7158 would fit in the result if the result were signed. */
7159 else if (TREE_CODE (uop
) == INTEGER_CST
7160 && (resultcode
== EQ_EXPR
|| resultcode
== NE_EXPR
)
7162 (uop
, c_common_signed_type (result_type
)))
7164 /* Do not warn if the unsigned quantity is an enumeration
7165 constant and its maximum value would fit in the result
7166 if the result were signed. */
7167 else if (TREE_CODE (uop
) == INTEGER_CST
7168 && TREE_CODE (TREE_TYPE (uop
)) == ENUMERAL_TYPE
7170 (TYPE_MAX_VALUE (TREE_TYPE(uop
)),
7171 c_common_signed_type (result_type
)))
7174 warning ("comparison between signed and unsigned");
7177 /* Warn if two unsigned values are being compared in a size
7178 larger than their original size, and one (and only one) is the
7179 result of a `~' operator. This comparison will always fail.
7181 Also warn if one operand is a constant, and the constant
7182 does not have all bits set that are set in the ~ operand
7183 when it is extended. */
7185 if ((TREE_CODE (primop0
) == BIT_NOT_EXPR
)
7186 != (TREE_CODE (primop1
) == BIT_NOT_EXPR
))
7188 if (TREE_CODE (primop0
) == BIT_NOT_EXPR
)
7189 primop0
= get_narrower (TREE_OPERAND (primop0
, 0),
7192 primop1
= get_narrower (TREE_OPERAND (primop1
, 0),
7195 if (host_integerp (primop0
, 0) || host_integerp (primop1
, 0))
7198 HOST_WIDE_INT constant
, mask
;
7199 int unsignedp
, bits
;
7201 if (host_integerp (primop0
, 0))
7204 unsignedp
= unsignedp1
;
7205 constant
= tree_low_cst (primop0
, 0);
7210 unsignedp
= unsignedp0
;
7211 constant
= tree_low_cst (primop1
, 0);
7214 bits
= TYPE_PRECISION (TREE_TYPE (primop
));
7215 if (bits
< TYPE_PRECISION (result_type
)
7216 && bits
< HOST_BITS_PER_WIDE_INT
&& unsignedp
)
7218 mask
= (~ (HOST_WIDE_INT
) 0) << bits
;
7219 if ((mask
& constant
) != mask
)
7220 warning ("comparison of promoted ~unsigned with constant");
7223 else if (unsignedp0
&& unsignedp1
7224 && (TYPE_PRECISION (TREE_TYPE (primop0
))
7225 < TYPE_PRECISION (result_type
))
7226 && (TYPE_PRECISION (TREE_TYPE (primop1
))
7227 < TYPE_PRECISION (result_type
)))
7228 warning ("comparison of promoted ~unsigned with unsigned");
7234 /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
7235 If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
7236 Then the expression will be built.
7237 It will be given type FINAL_TYPE if that is nonzero;
7238 otherwise, it will be given type RESULT_TYPE. */
7242 binary_op_error (code
);
7243 return error_mark_node
;
7248 if (TREE_TYPE (op0
) != result_type
)
7249 op0
= convert (result_type
, op0
);
7250 if (TREE_TYPE (op1
) != result_type
)
7251 op1
= convert (result_type
, op1
);
7254 if (build_type
== NULL_TREE
)
7255 build_type
= result_type
;
7258 tree result
= build (resultcode
, build_type
, op0
, op1
);
7261 /* Treat expressions in initializers specially as they can't trap. */
7262 folded
= initializer_stack
? fold_initializer (result
)
7264 if (folded
== result
)
7265 TREE_CONSTANT (folded
) = TREE_CONSTANT (op0
) & TREE_CONSTANT (op1
);
7266 if (final_type
!= 0)
7267 return convert (final_type
, folded
);