1 /* Build expressions with type checking for C compiler.
2 Copyright (C) 1987, 1988, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
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. */
30 #include "coretypes.h"
33 #include "langhooks.h"
40 #include "tree-iterator.h"
43 #include "c-family/c-objc.h"
45 /* Possible cases of implicit bad conversions. Used to select
46 diagnostic messages in convert_for_assignment. */
54 /* The level of nesting inside "__alignof__". */
57 /* The level of nesting inside "sizeof". */
60 /* The level of nesting inside "typeof". */
63 /* Nonzero if we've already printed a "missing braces around initializer"
64 message within this initializer. */
65 static int missing_braces_mentioned;
67 static int require_constant_value;
68 static int require_constant_elements;
70 static bool null_pointer_constant_p (const_tree);
71 static tree qualify_type (tree, tree);
72 static int tagged_types_tu_compatible_p (const_tree, const_tree, bool *,
74 static int comp_target_types (location_t, tree, tree);
75 static int function_types_compatible_p (const_tree, const_tree, bool *,
77 static int type_lists_compatible_p (const_tree, const_tree, bool *, bool *);
78 static tree lookup_field (tree, tree);
79 static int convert_arguments (tree, VEC(tree,gc) *, VEC(tree,gc) *, tree,
81 static tree pointer_diff (location_t, tree, tree);
82 static tree convert_for_assignment (location_t, tree, tree, tree,
83 enum impl_conv, bool, tree, tree, int);
84 static tree valid_compound_expr_initializer (tree, tree);
85 static void push_string (const char *);
86 static void push_member_name (tree);
87 static int spelling_length (void);
88 static char *print_spelling (char *);
89 static void warning_init (int, const char *);
90 static tree digest_init (location_t, tree, tree, tree, bool, bool, int);
91 static void output_init_element (tree, tree, bool, tree, tree, int, bool,
93 static void output_pending_init_elements (int, struct obstack *);
94 static int set_designator (int, struct obstack *);
95 static void push_range_stack (tree, struct obstack *);
96 static void add_pending_init (tree, tree, tree, bool, struct obstack *);
97 static void set_nonincremental_init (struct obstack *);
98 static void set_nonincremental_init_from_string (tree, struct obstack *);
99 static tree find_init_member (tree, struct obstack *);
100 static void readonly_warning (tree, enum lvalue_use);
101 static int lvalue_or_else (location_t, const_tree, enum lvalue_use);
102 static void record_maybe_used_decl (tree);
103 static int comptypes_internal (const_tree, const_tree, bool *, bool *);
105 /* Return true if EXP is a null pointer constant, false otherwise. */
108 null_pointer_constant_p (const_tree expr)
110 /* This should really operate on c_expr structures, but they aren't
111 yet available everywhere required. */
112 tree type = TREE_TYPE (expr);
113 return (TREE_CODE (expr) == INTEGER_CST
114 && !TREE_OVERFLOW (expr)
115 && integer_zerop (expr)
116 && (INTEGRAL_TYPE_P (type)
117 || (TREE_CODE (type) == POINTER_TYPE
118 && VOID_TYPE_P (TREE_TYPE (type))
119 && TYPE_QUALS (TREE_TYPE (type)) == TYPE_UNQUALIFIED)));
122 /* EXPR may appear in an unevaluated part of an integer constant
123 expression, but not in an evaluated part. Wrap it in a
124 C_MAYBE_CONST_EXPR, or mark it with TREE_OVERFLOW if it is just an
125 INTEGER_CST and we cannot create a C_MAYBE_CONST_EXPR. */
128 note_integer_operands (tree expr)
131 if (TREE_CODE (expr) == INTEGER_CST && in_late_binary_op)
133 ret = copy_node (expr);
134 TREE_OVERFLOW (ret) = 1;
138 ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (expr), NULL_TREE, expr);
139 C_MAYBE_CONST_EXPR_INT_OPERANDS (ret) = 1;
144 /* Having checked whether EXPR may appear in an unevaluated part of an
145 integer constant expression and found that it may, remove any
146 C_MAYBE_CONST_EXPR noting this fact and return the resulting
150 remove_c_maybe_const_expr (tree expr)
152 if (TREE_CODE (expr) == C_MAYBE_CONST_EXPR)
153 return C_MAYBE_CONST_EXPR_EXPR (expr);
158 \f/* This is a cache to hold if two types are compatible or not. */
160 struct tagged_tu_seen_cache {
161 const struct tagged_tu_seen_cache * next;
164 /* The return value of tagged_types_tu_compatible_p if we had seen
165 these two types already. */
169 static const struct tagged_tu_seen_cache * tagged_tu_seen_base;
170 static void free_all_tagged_tu_seen_up_to (const struct tagged_tu_seen_cache *);
172 /* Do `exp = require_complete_type (exp);' to make sure exp
173 does not have an incomplete type. (That includes void types.) */
176 require_complete_type (tree value)
178 tree type = TREE_TYPE (value);
180 if (value == error_mark_node || type == error_mark_node)
181 return error_mark_node;
183 /* First, detect a valid value with a complete type. */
184 if (COMPLETE_TYPE_P (type))
187 c_incomplete_type_error (value, type);
188 return error_mark_node;
191 /* Print an error message for invalid use of an incomplete type.
192 VALUE is the expression that was used (or 0 if that isn't known)
193 and TYPE is the type that was invalid. */
196 c_incomplete_type_error (const_tree value, const_tree type)
198 const char *type_code_string;
200 /* Avoid duplicate error message. */
201 if (TREE_CODE (type) == ERROR_MARK)
204 if (value != 0 && (TREE_CODE (value) == VAR_DECL
205 || TREE_CODE (value) == PARM_DECL))
206 error ("%qD has an incomplete type", value);
210 /* We must print an error message. Be clever about what it says. */
212 switch (TREE_CODE (type))
215 type_code_string = "struct";
219 type_code_string = "union";
223 type_code_string = "enum";
227 error ("invalid use of void expression");
231 if (TYPE_DOMAIN (type))
233 if (TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL)
235 error ("invalid use of flexible array member");
238 type = TREE_TYPE (type);
241 error ("invalid use of array with unspecified bounds");
248 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
249 error ("invalid use of undefined type %<%s %E%>",
250 type_code_string, TYPE_NAME (type));
252 /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL. */
253 error ("invalid use of incomplete typedef %qD", TYPE_NAME (type));
257 /* Given a type, apply default promotions wrt unnamed function
258 arguments and return the new type. */
261 c_type_promotes_to (tree type)
263 if (TYPE_MAIN_VARIANT (type) == float_type_node)
264 return double_type_node;
266 if (c_promoting_integer_type_p (type))
268 /* Preserve unsignedness if not really getting any wider. */
269 if (TYPE_UNSIGNED (type)
270 && (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)))
271 return unsigned_type_node;
272 return integer_type_node;
278 /* Return true if between two named address spaces, whether there is a superset
279 named address space that encompasses both address spaces. If there is a
280 superset, return which address space is the superset. */
283 addr_space_superset (addr_space_t as1, addr_space_t as2, addr_space_t *common)
290 else if (targetm.addr_space.subset_p (as1, as2))
295 else if (targetm.addr_space.subset_p (as2, as1))
304 /* Return a variant of TYPE which has all the type qualifiers of LIKE
305 as well as those of TYPE. */
308 qualify_type (tree type, tree like)
310 addr_space_t as_type = TYPE_ADDR_SPACE (type);
311 addr_space_t as_like = TYPE_ADDR_SPACE (like);
312 addr_space_t as_common;
314 /* If the two named address spaces are different, determine the common
315 superset address space. If there isn't one, raise an error. */
316 if (!addr_space_superset (as_type, as_like, &as_common))
319 error ("%qT and %qT are in disjoint named address spaces",
323 return c_build_qualified_type (type,
324 TYPE_QUALS_NO_ADDR_SPACE (type)
325 | TYPE_QUALS_NO_ADDR_SPACE (like)
326 | ENCODE_QUAL_ADDR_SPACE (as_common));
329 /* Return true iff the given tree T is a variable length array. */
332 c_vla_type_p (const_tree t)
334 if (TREE_CODE (t) == ARRAY_TYPE
335 && C_TYPE_VARIABLE_SIZE (t))
340 /* Return the composite type of two compatible types.
342 We assume that comptypes has already been done and returned
343 nonzero; if that isn't so, this may crash. In particular, we
344 assume that qualifiers match. */
347 composite_type (tree t1, tree t2)
349 enum tree_code code1;
350 enum tree_code code2;
353 /* Save time if the two types are the same. */
355 if (t1 == t2) return t1;
357 /* If one type is nonsense, use the other. */
358 if (t1 == error_mark_node)
360 if (t2 == error_mark_node)
363 code1 = TREE_CODE (t1);
364 code2 = TREE_CODE (t2);
366 /* Merge the attributes. */
367 attributes = targetm.merge_type_attributes (t1, t2);
369 /* If one is an enumerated type and the other is the compatible
370 integer type, the composite type might be either of the two
371 (DR#013 question 3). For consistency, use the enumerated type as
372 the composite type. */
374 if (code1 == ENUMERAL_TYPE && code2 == INTEGER_TYPE)
376 if (code2 == ENUMERAL_TYPE && code1 == INTEGER_TYPE)
379 gcc_assert (code1 == code2);
384 /* For two pointers, do this recursively on the target type. */
386 tree pointed_to_1 = TREE_TYPE (t1);
387 tree pointed_to_2 = TREE_TYPE (t2);
388 tree target = composite_type (pointed_to_1, pointed_to_2);
389 t1 = build_pointer_type (target);
390 t1 = build_type_attribute_variant (t1, attributes);
391 return qualify_type (t1, t2);
396 tree elt = composite_type (TREE_TYPE (t1), TREE_TYPE (t2));
399 tree d1 = TYPE_DOMAIN (t1);
400 tree d2 = TYPE_DOMAIN (t2);
401 bool d1_variable, d2_variable;
402 bool d1_zero, d2_zero;
403 bool t1_complete, t2_complete;
405 /* We should not have any type quals on arrays at all. */
406 gcc_assert (!TYPE_QUALS_NO_ADDR_SPACE (t1)
407 && !TYPE_QUALS_NO_ADDR_SPACE (t2));
409 t1_complete = COMPLETE_TYPE_P (t1);
410 t2_complete = COMPLETE_TYPE_P (t2);
412 d1_zero = d1 == 0 || !TYPE_MAX_VALUE (d1);
413 d2_zero = d2 == 0 || !TYPE_MAX_VALUE (d2);
415 d1_variable = (!d1_zero
416 && (TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST
417 || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST));
418 d2_variable = (!d2_zero
419 && (TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST
420 || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST));
421 d1_variable = d1_variable || (d1_zero && c_vla_type_p (t1));
422 d2_variable = d2_variable || (d2_zero && c_vla_type_p (t2));
424 /* Save space: see if the result is identical to one of the args. */
425 if (elt == TREE_TYPE (t1) && TYPE_DOMAIN (t1)
426 && (d2_variable || d2_zero || !d1_variable))
427 return build_type_attribute_variant (t1, attributes);
428 if (elt == TREE_TYPE (t2) && TYPE_DOMAIN (t2)
429 && (d1_variable || d1_zero || !d2_variable))
430 return build_type_attribute_variant (t2, attributes);
432 if (elt == TREE_TYPE (t1) && !TYPE_DOMAIN (t2) && !TYPE_DOMAIN (t1))
433 return build_type_attribute_variant (t1, attributes);
434 if (elt == TREE_TYPE (t2) && !TYPE_DOMAIN (t2) && !TYPE_DOMAIN (t1))
435 return build_type_attribute_variant (t2, attributes);
437 /* Merge the element types, and have a size if either arg has
438 one. We may have qualifiers on the element types. To set
439 up TYPE_MAIN_VARIANT correctly, we need to form the
440 composite of the unqualified types and add the qualifiers
442 quals = TYPE_QUALS (strip_array_types (elt));
443 unqual_elt = c_build_qualified_type (elt, TYPE_UNQUALIFIED);
444 t1 = build_array_type (unqual_elt,
445 TYPE_DOMAIN ((TYPE_DOMAIN (t1)
451 /* Ensure a composite type involving a zero-length array type
452 is a zero-length type not an incomplete type. */
453 if (d1_zero && d2_zero
454 && (t1_complete || t2_complete)
455 && !COMPLETE_TYPE_P (t1))
457 TYPE_SIZE (t1) = bitsize_zero_node;
458 TYPE_SIZE_UNIT (t1) = size_zero_node;
460 t1 = c_build_qualified_type (t1, quals);
461 return build_type_attribute_variant (t1, attributes);
467 if (attributes != NULL)
469 /* Try harder not to create a new aggregate type. */
470 if (attribute_list_equal (TYPE_ATTRIBUTES (t1), attributes))
472 if (attribute_list_equal (TYPE_ATTRIBUTES (t2), attributes))
475 return build_type_attribute_variant (t1, attributes);
478 /* Function types: prefer the one that specified arg types.
479 If both do, merge the arg types. Also merge the return types. */
481 tree valtype = composite_type (TREE_TYPE (t1), TREE_TYPE (t2));
482 tree p1 = TYPE_ARG_TYPES (t1);
483 tree p2 = TYPE_ARG_TYPES (t2);
488 /* Save space: see if the result is identical to one of the args. */
489 if (valtype == TREE_TYPE (t1) && !TYPE_ARG_TYPES (t2))
490 return build_type_attribute_variant (t1, attributes);
491 if (valtype == TREE_TYPE (t2) && !TYPE_ARG_TYPES (t1))
492 return build_type_attribute_variant (t2, attributes);
494 /* Simple way if one arg fails to specify argument types. */
495 if (TYPE_ARG_TYPES (t1) == 0)
497 t1 = build_function_type (valtype, TYPE_ARG_TYPES (t2));
498 t1 = build_type_attribute_variant (t1, attributes);
499 return qualify_type (t1, t2);
501 if (TYPE_ARG_TYPES (t2) == 0)
503 t1 = build_function_type (valtype, TYPE_ARG_TYPES (t1));
504 t1 = build_type_attribute_variant (t1, attributes);
505 return qualify_type (t1, t2);
508 /* If both args specify argument types, we must merge the two
509 lists, argument by argument. */
511 len = list_length (p1);
514 for (i = 0; i < len; i++)
515 newargs = tree_cons (NULL_TREE, NULL_TREE, newargs);
520 p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2), n = TREE_CHAIN (n))
522 /* A null type means arg type is not specified.
523 Take whatever the other function type has. */
524 if (TREE_VALUE (p1) == 0)
526 TREE_VALUE (n) = TREE_VALUE (p2);
529 if (TREE_VALUE (p2) == 0)
531 TREE_VALUE (n) = TREE_VALUE (p1);
535 /* Given wait (union {union wait *u; int *i} *)
536 and wait (union wait *),
537 prefer union wait * as type of parm. */
538 if (TREE_CODE (TREE_VALUE (p1)) == UNION_TYPE
539 && TREE_VALUE (p1) != TREE_VALUE (p2))
542 tree mv2 = TREE_VALUE (p2);
543 if (mv2 && mv2 != error_mark_node
544 && TREE_CODE (mv2) != ARRAY_TYPE)
545 mv2 = TYPE_MAIN_VARIANT (mv2);
546 for (memb = TYPE_FIELDS (TREE_VALUE (p1));
547 memb; memb = DECL_CHAIN (memb))
549 tree mv3 = TREE_TYPE (memb);
550 if (mv3 && mv3 != error_mark_node
551 && TREE_CODE (mv3) != ARRAY_TYPE)
552 mv3 = TYPE_MAIN_VARIANT (mv3);
553 if (comptypes (mv3, mv2))
555 TREE_VALUE (n) = composite_type (TREE_TYPE (memb),
557 pedwarn (input_location, OPT_pedantic,
558 "function types not truly compatible in ISO C");
563 if (TREE_CODE (TREE_VALUE (p2)) == UNION_TYPE
564 && TREE_VALUE (p2) != TREE_VALUE (p1))
567 tree mv1 = TREE_VALUE (p1);
568 if (mv1 && mv1 != error_mark_node
569 && TREE_CODE (mv1) != ARRAY_TYPE)
570 mv1 = TYPE_MAIN_VARIANT (mv1);
571 for (memb = TYPE_FIELDS (TREE_VALUE (p2));
572 memb; memb = DECL_CHAIN (memb))
574 tree mv3 = TREE_TYPE (memb);
575 if (mv3 && mv3 != error_mark_node
576 && TREE_CODE (mv3) != ARRAY_TYPE)
577 mv3 = TYPE_MAIN_VARIANT (mv3);
578 if (comptypes (mv3, mv1))
580 TREE_VALUE (n) = composite_type (TREE_TYPE (memb),
582 pedwarn (input_location, OPT_pedantic,
583 "function types not truly compatible in ISO C");
588 TREE_VALUE (n) = composite_type (TREE_VALUE (p1), TREE_VALUE (p2));
592 t1 = build_function_type (valtype, newargs);
593 t1 = qualify_type (t1, t2);
594 /* ... falls through ... */
598 return build_type_attribute_variant (t1, attributes);
603 /* Return the type of a conditional expression between pointers to
604 possibly differently qualified versions of compatible types.
606 We assume that comp_target_types has already been done and returned
607 nonzero; if that isn't so, this may crash. */
610 common_pointer_type (tree t1, tree t2)
613 tree pointed_to_1, mv1;
614 tree pointed_to_2, mv2;
616 unsigned target_quals;
617 addr_space_t as1, as2, as_common;
620 /* Save time if the two types are the same. */
622 if (t1 == t2) return t1;
624 /* If one type is nonsense, use the other. */
625 if (t1 == error_mark_node)
627 if (t2 == error_mark_node)
630 gcc_assert (TREE_CODE (t1) == POINTER_TYPE
631 && TREE_CODE (t2) == POINTER_TYPE);
633 /* Merge the attributes. */
634 attributes = targetm.merge_type_attributes (t1, t2);
636 /* Find the composite type of the target types, and combine the
637 qualifiers of the two types' targets. Do not lose qualifiers on
638 array element types by taking the TYPE_MAIN_VARIANT. */
639 mv1 = pointed_to_1 = TREE_TYPE (t1);
640 mv2 = pointed_to_2 = TREE_TYPE (t2);
641 if (TREE_CODE (mv1) != ARRAY_TYPE)
642 mv1 = TYPE_MAIN_VARIANT (pointed_to_1);
643 if (TREE_CODE (mv2) != ARRAY_TYPE)
644 mv2 = TYPE_MAIN_VARIANT (pointed_to_2);
645 target = composite_type (mv1, mv2);
647 /* For function types do not merge const qualifiers, but drop them
648 if used inconsistently. The middle-end uses these to mark const
649 and noreturn functions. */
650 quals1 = TYPE_QUALS_NO_ADDR_SPACE (pointed_to_1);
651 quals2 = TYPE_QUALS_NO_ADDR_SPACE (pointed_to_2);
653 if (TREE_CODE (pointed_to_1) == FUNCTION_TYPE)
654 target_quals = (quals1 & quals2);
656 target_quals = (quals1 | quals2);
658 /* If the two named address spaces are different, determine the common
659 superset address space. This is guaranteed to exist due to the
660 assumption that comp_target_type returned non-zero. */
661 as1 = TYPE_ADDR_SPACE (pointed_to_1);
662 as2 = TYPE_ADDR_SPACE (pointed_to_2);
663 if (!addr_space_superset (as1, as2, &as_common))
666 target_quals |= ENCODE_QUAL_ADDR_SPACE (as_common);
668 t1 = build_pointer_type (c_build_qualified_type (target, target_quals));
669 return build_type_attribute_variant (t1, attributes);
672 /* Return the common type for two arithmetic types under the usual
673 arithmetic conversions. The default conversions have already been
674 applied, and enumerated types converted to their compatible integer
675 types. The resulting type is unqualified and has no attributes.
677 This is the type for the result of most arithmetic operations
678 if the operands have the given two types. */
681 c_common_type (tree t1, tree t2)
683 enum tree_code code1;
684 enum tree_code code2;
686 /* If one type is nonsense, use the other. */
687 if (t1 == error_mark_node)
689 if (t2 == error_mark_node)
692 if (TYPE_QUALS (t1) != TYPE_UNQUALIFIED)
693 t1 = TYPE_MAIN_VARIANT (t1);
695 if (TYPE_QUALS (t2) != TYPE_UNQUALIFIED)
696 t2 = TYPE_MAIN_VARIANT (t2);
698 if (TYPE_ATTRIBUTES (t1) != NULL_TREE)
699 t1 = build_type_attribute_variant (t1, NULL_TREE);
701 if (TYPE_ATTRIBUTES (t2) != NULL_TREE)
702 t2 = build_type_attribute_variant (t2, NULL_TREE);
704 /* Save time if the two types are the same. */
706 if (t1 == t2) return t1;
708 code1 = TREE_CODE (t1);
709 code2 = TREE_CODE (t2);
711 gcc_assert (code1 == VECTOR_TYPE || code1 == COMPLEX_TYPE
712 || code1 == FIXED_POINT_TYPE || code1 == REAL_TYPE
713 || code1 == INTEGER_TYPE);
714 gcc_assert (code2 == VECTOR_TYPE || code2 == COMPLEX_TYPE
715 || code2 == FIXED_POINT_TYPE || code2 == REAL_TYPE
716 || code2 == INTEGER_TYPE);
718 /* When one operand is a decimal float type, the other operand cannot be
719 a generic float type or a complex type. We also disallow vector types
721 if ((DECIMAL_FLOAT_TYPE_P (t1) || DECIMAL_FLOAT_TYPE_P (t2))
722 && !(DECIMAL_FLOAT_TYPE_P (t1) && DECIMAL_FLOAT_TYPE_P (t2)))
724 if (code1 == VECTOR_TYPE || code2 == VECTOR_TYPE)
726 error ("can%'t mix operands of decimal float and vector types");
727 return error_mark_node;
729 if (code1 == COMPLEX_TYPE || code2 == COMPLEX_TYPE)
731 error ("can%'t mix operands of decimal float and complex types");
732 return error_mark_node;
734 if (code1 == REAL_TYPE && code2 == REAL_TYPE)
736 error ("can%'t mix operands of decimal float and other float types");
737 return error_mark_node;
741 /* If one type is a vector type, return that type. (How the usual
742 arithmetic conversions apply to the vector types extension is not
743 precisely specified.) */
744 if (code1 == VECTOR_TYPE)
747 if (code2 == VECTOR_TYPE)
750 /* If one type is complex, form the common type of the non-complex
751 components, then make that complex. Use T1 or T2 if it is the
753 if (code1 == COMPLEX_TYPE || code2 == COMPLEX_TYPE)
755 tree subtype1 = code1 == COMPLEX_TYPE ? TREE_TYPE (t1) : t1;
756 tree subtype2 = code2 == COMPLEX_TYPE ? TREE_TYPE (t2) : t2;
757 tree subtype = c_common_type (subtype1, subtype2);
759 if (code1 == COMPLEX_TYPE && TREE_TYPE (t1) == subtype)
761 else if (code2 == COMPLEX_TYPE && TREE_TYPE (t2) == subtype)
764 return build_complex_type (subtype);
767 /* If only one is real, use it as the result. */
769 if (code1 == REAL_TYPE && code2 != REAL_TYPE)
772 if (code2 == REAL_TYPE && code1 != REAL_TYPE)
775 /* If both are real and either are decimal floating point types, use
776 the decimal floating point type with the greater precision. */
778 if (code1 == REAL_TYPE && code2 == REAL_TYPE)
780 if (TYPE_MAIN_VARIANT (t1) == dfloat128_type_node
781 || TYPE_MAIN_VARIANT (t2) == dfloat128_type_node)
782 return dfloat128_type_node;
783 else if (TYPE_MAIN_VARIANT (t1) == dfloat64_type_node
784 || TYPE_MAIN_VARIANT (t2) == dfloat64_type_node)
785 return dfloat64_type_node;
786 else if (TYPE_MAIN_VARIANT (t1) == dfloat32_type_node
787 || TYPE_MAIN_VARIANT (t2) == dfloat32_type_node)
788 return dfloat32_type_node;
791 /* Deal with fixed-point types. */
792 if (code1 == FIXED_POINT_TYPE || code2 == FIXED_POINT_TYPE)
794 unsigned int unsignedp = 0, satp = 0;
795 enum machine_mode m1, m2;
796 unsigned int fbit1, ibit1, fbit2, ibit2, max_fbit, max_ibit;
801 /* If one input type is saturating, the result type is saturating. */
802 if (TYPE_SATURATING (t1) || TYPE_SATURATING (t2))
805 /* If both fixed-point types are unsigned, the result type is unsigned.
806 When mixing fixed-point and integer types, follow the sign of the
808 Otherwise, the result type is signed. */
809 if ((TYPE_UNSIGNED (t1) && TYPE_UNSIGNED (t2)
810 && code1 == FIXED_POINT_TYPE && code2 == FIXED_POINT_TYPE)
811 || (code1 == FIXED_POINT_TYPE && code2 != FIXED_POINT_TYPE
812 && TYPE_UNSIGNED (t1))
813 || (code1 != FIXED_POINT_TYPE && code2 == FIXED_POINT_TYPE
814 && TYPE_UNSIGNED (t2)))
817 /* The result type is signed. */
820 /* If the input type is unsigned, we need to convert to the
822 if (code1 == FIXED_POINT_TYPE && TYPE_UNSIGNED (t1))
824 enum mode_class mclass = (enum mode_class) 0;
825 if (GET_MODE_CLASS (m1) == MODE_UFRACT)
827 else if (GET_MODE_CLASS (m1) == MODE_UACCUM)
831 m1 = mode_for_size (GET_MODE_PRECISION (m1), mclass, 0);
833 if (code2 == FIXED_POINT_TYPE && TYPE_UNSIGNED (t2))
835 enum mode_class mclass = (enum mode_class) 0;
836 if (GET_MODE_CLASS (m2) == MODE_UFRACT)
838 else if (GET_MODE_CLASS (m2) == MODE_UACCUM)
842 m2 = mode_for_size (GET_MODE_PRECISION (m2), mclass, 0);
846 if (code1 == FIXED_POINT_TYPE)
848 fbit1 = GET_MODE_FBIT (m1);
849 ibit1 = GET_MODE_IBIT (m1);
854 /* Signed integers need to subtract one sign bit. */
855 ibit1 = TYPE_PRECISION (t1) - (!TYPE_UNSIGNED (t1));
858 if (code2 == FIXED_POINT_TYPE)
860 fbit2 = GET_MODE_FBIT (m2);
861 ibit2 = GET_MODE_IBIT (m2);
866 /* Signed integers need to subtract one sign bit. */
867 ibit2 = TYPE_PRECISION (t2) - (!TYPE_UNSIGNED (t2));
870 max_ibit = ibit1 >= ibit2 ? ibit1 : ibit2;
871 max_fbit = fbit1 >= fbit2 ? fbit1 : fbit2;
872 return c_common_fixed_point_type_for_size (max_ibit, max_fbit, unsignedp,
876 /* Both real or both integers; use the one with greater precision. */
878 if (TYPE_PRECISION (t1) > TYPE_PRECISION (t2))
880 else if (TYPE_PRECISION (t2) > TYPE_PRECISION (t1))
883 /* Same precision. Prefer long longs to longs to ints when the
884 same precision, following the C99 rules on integer type rank
885 (which are equivalent to the C90 rules for C90 types). */
887 if (TYPE_MAIN_VARIANT (t1) == long_long_unsigned_type_node
888 || TYPE_MAIN_VARIANT (t2) == long_long_unsigned_type_node)
889 return long_long_unsigned_type_node;
891 if (TYPE_MAIN_VARIANT (t1) == long_long_integer_type_node
892 || TYPE_MAIN_VARIANT (t2) == long_long_integer_type_node)
894 if (TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2))
895 return long_long_unsigned_type_node;
897 return long_long_integer_type_node;
900 if (TYPE_MAIN_VARIANT (t1) == long_unsigned_type_node
901 || TYPE_MAIN_VARIANT (t2) == long_unsigned_type_node)
902 return long_unsigned_type_node;
904 if (TYPE_MAIN_VARIANT (t1) == long_integer_type_node
905 || TYPE_MAIN_VARIANT (t2) == long_integer_type_node)
907 /* But preserve unsignedness from the other type,
908 since long cannot hold all the values of an unsigned int. */
909 if (TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2))
910 return long_unsigned_type_node;
912 return long_integer_type_node;
915 /* Likewise, prefer long double to double even if same size. */
916 if (TYPE_MAIN_VARIANT (t1) == long_double_type_node
917 || TYPE_MAIN_VARIANT (t2) == long_double_type_node)
918 return long_double_type_node;
920 /* Otherwise prefer the unsigned one. */
922 if (TYPE_UNSIGNED (t1))
928 /* Wrapper around c_common_type that is used by c-common.c and other
929 front end optimizations that remove promotions. ENUMERAL_TYPEs
930 are allowed here and are converted to their compatible integer types.
931 BOOLEAN_TYPEs are allowed here and return either boolean_type_node or
932 preferably a non-Boolean type as the common type. */
934 common_type (tree t1, tree t2)
936 if (TREE_CODE (t1) == ENUMERAL_TYPE)
937 t1 = c_common_type_for_size (TYPE_PRECISION (t1), 1);
938 if (TREE_CODE (t2) == ENUMERAL_TYPE)
939 t2 = c_common_type_for_size (TYPE_PRECISION (t2), 1);
941 /* If both types are BOOLEAN_TYPE, then return boolean_type_node. */
942 if (TREE_CODE (t1) == BOOLEAN_TYPE
943 && TREE_CODE (t2) == BOOLEAN_TYPE)
944 return boolean_type_node;
946 /* If either type is BOOLEAN_TYPE, then return the other. */
947 if (TREE_CODE (t1) == BOOLEAN_TYPE)
949 if (TREE_CODE (t2) == BOOLEAN_TYPE)
952 return c_common_type (t1, t2);
955 /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
956 or various other operations. Return 2 if they are compatible
957 but a warning may be needed if you use them together. */
960 comptypes (tree type1, tree type2)
962 const struct tagged_tu_seen_cache * tagged_tu_seen_base1 = tagged_tu_seen_base;
965 val = comptypes_internal (type1, type2, NULL, NULL);
966 free_all_tagged_tu_seen_up_to (tagged_tu_seen_base1);
971 /* Like comptypes, but if it returns non-zero because enum and int are
972 compatible, it sets *ENUM_AND_INT_P to true. */
975 comptypes_check_enum_int (tree type1, tree type2, bool *enum_and_int_p)
977 const struct tagged_tu_seen_cache * tagged_tu_seen_base1 = tagged_tu_seen_base;
980 val = comptypes_internal (type1, type2, enum_and_int_p, NULL);
981 free_all_tagged_tu_seen_up_to (tagged_tu_seen_base1);
986 /* Like comptypes, but if it returns nonzero for different types, it
987 sets *DIFFERENT_TYPES_P to true. */
990 comptypes_check_different_types (tree type1, tree type2,
991 bool *different_types_p)
993 const struct tagged_tu_seen_cache * tagged_tu_seen_base1 = tagged_tu_seen_base;
996 val = comptypes_internal (type1, type2, NULL, different_types_p);
997 free_all_tagged_tu_seen_up_to (tagged_tu_seen_base1);
1002 /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
1003 or various other operations. Return 2 if they are compatible
1004 but a warning may be needed if you use them together. If
1005 ENUM_AND_INT_P is not NULL, and one type is an enum and the other a
1006 compatible integer type, then this sets *ENUM_AND_INT_P to true;
1007 *ENUM_AND_INT_P is never set to false. If DIFFERENT_TYPES_P is not
1008 NULL, and the types are compatible but different enough not to be
1009 permitted in C1X typedef redeclarations, then this sets
1010 *DIFFERENT_TYPES_P to true; *DIFFERENT_TYPES_P is never set to
1011 false, but may or may not be set if the types are incompatible.
1012 This differs from comptypes, in that we don't free the seen
1016 comptypes_internal (const_tree type1, const_tree type2, bool *enum_and_int_p,
1017 bool *different_types_p)
1019 const_tree t1 = type1;
1020 const_tree t2 = type2;
1023 /* Suppress errors caused by previously reported errors. */
1025 if (t1 == t2 || !t1 || !t2
1026 || TREE_CODE (t1) == ERROR_MARK || TREE_CODE (t2) == ERROR_MARK)
1029 /* Enumerated types are compatible with integer types, but this is
1030 not transitive: two enumerated types in the same translation unit
1031 are compatible with each other only if they are the same type. */
1033 if (TREE_CODE (t1) == ENUMERAL_TYPE && TREE_CODE (t2) != ENUMERAL_TYPE)
1035 t1 = c_common_type_for_size (TYPE_PRECISION (t1), TYPE_UNSIGNED (t1));
1036 if (TREE_CODE (t2) != VOID_TYPE)
1038 if (enum_and_int_p != NULL)
1039 *enum_and_int_p = true;
1040 if (different_types_p != NULL)
1041 *different_types_p = true;
1044 else if (TREE_CODE (t2) == ENUMERAL_TYPE && TREE_CODE (t1) != ENUMERAL_TYPE)
1046 t2 = c_common_type_for_size (TYPE_PRECISION (t2), TYPE_UNSIGNED (t2));
1047 if (TREE_CODE (t1) != VOID_TYPE)
1049 if (enum_and_int_p != NULL)
1050 *enum_and_int_p = true;
1051 if (different_types_p != NULL)
1052 *different_types_p = true;
1059 /* Different classes of types can't be compatible. */
1061 if (TREE_CODE (t1) != TREE_CODE (t2))
1064 /* Qualifiers must match. C99 6.7.3p9 */
1066 if (TYPE_QUALS (t1) != TYPE_QUALS (t2))
1069 /* Allow for two different type nodes which have essentially the same
1070 definition. Note that we already checked for equality of the type
1071 qualifiers (just above). */
1073 if (TREE_CODE (t1) != ARRAY_TYPE
1074 && TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
1077 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
1078 if (!(attrval = comp_type_attributes (t1, t2)))
1081 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
1084 switch (TREE_CODE (t1))
1087 /* Do not remove mode or aliasing information. */
1088 if (TYPE_MODE (t1) != TYPE_MODE (t2)
1089 || TYPE_REF_CAN_ALIAS_ALL (t1) != TYPE_REF_CAN_ALIAS_ALL (t2))
1091 val = (TREE_TYPE (t1) == TREE_TYPE (t2)
1092 ? 1 : comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2),
1093 enum_and_int_p, different_types_p));
1097 val = function_types_compatible_p (t1, t2, enum_and_int_p,
1103 tree d1 = TYPE_DOMAIN (t1);
1104 tree d2 = TYPE_DOMAIN (t2);
1105 bool d1_variable, d2_variable;
1106 bool d1_zero, d2_zero;
1109 /* Target types must match incl. qualifiers. */
1110 if (TREE_TYPE (t1) != TREE_TYPE (t2)
1111 && 0 == (val = comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2),
1113 different_types_p)))
1116 if (different_types_p != NULL
1117 && (d1 == 0) != (d2 == 0))
1118 *different_types_p = true;
1119 /* Sizes must match unless one is missing or variable. */
1120 if (d1 == 0 || d2 == 0 || d1 == d2)
1123 d1_zero = !TYPE_MAX_VALUE (d1);
1124 d2_zero = !TYPE_MAX_VALUE (d2);
1126 d1_variable = (!d1_zero
1127 && (TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST
1128 || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST));
1129 d2_variable = (!d2_zero
1130 && (TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST
1131 || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST));
1132 d1_variable = d1_variable || (d1_zero && c_vla_type_p (t1));
1133 d2_variable = d2_variable || (d2_zero && c_vla_type_p (t2));
1135 if (different_types_p != NULL
1136 && d1_variable != d2_variable)
1137 *different_types_p = true;
1138 if (d1_variable || d2_variable)
1140 if (d1_zero && d2_zero)
1142 if (d1_zero || d2_zero
1143 || !tree_int_cst_equal (TYPE_MIN_VALUE (d1), TYPE_MIN_VALUE (d2))
1144 || !tree_int_cst_equal (TYPE_MAX_VALUE (d1), TYPE_MAX_VALUE (d2)))
1153 if (val != 1 && !same_translation_unit_p (t1, t2))
1155 tree a1 = TYPE_ATTRIBUTES (t1);
1156 tree a2 = TYPE_ATTRIBUTES (t2);
1158 if (! attribute_list_contained (a1, a2)
1159 && ! attribute_list_contained (a2, a1))
1163 return tagged_types_tu_compatible_p (t1, t2, enum_and_int_p,
1165 val = tagged_types_tu_compatible_p (t1, t2, enum_and_int_p,
1171 val = (TYPE_VECTOR_SUBPARTS (t1) == TYPE_VECTOR_SUBPARTS (t2)
1172 && comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2),
1173 enum_and_int_p, different_types_p));
1179 return attrval == 2 && val == 1 ? 2 : val;
1182 /* Return 1 if TTL and TTR are pointers to types that are equivalent, ignoring
1183 their qualifiers, except for named address spaces. If the pointers point to
1184 different named addresses, then we must determine if one address space is a
1185 subset of the other. */
1188 comp_target_types (location_t location, tree ttl, tree ttr)
1191 tree mvl = TREE_TYPE (ttl);
1192 tree mvr = TREE_TYPE (ttr);
1193 addr_space_t asl = TYPE_ADDR_SPACE (mvl);
1194 addr_space_t asr = TYPE_ADDR_SPACE (mvr);
1195 addr_space_t as_common;
1196 bool enum_and_int_p;
1198 /* Fail if pointers point to incompatible address spaces. */
1199 if (!addr_space_superset (asl, asr, &as_common))
1202 /* Do not lose qualifiers on element types of array types that are
1203 pointer targets by taking their TYPE_MAIN_VARIANT. */
1204 if (TREE_CODE (mvl) != ARRAY_TYPE)
1205 mvl = TYPE_MAIN_VARIANT (mvl);
1206 if (TREE_CODE (mvr) != ARRAY_TYPE)
1207 mvr = TYPE_MAIN_VARIANT (mvr);
1208 enum_and_int_p = false;
1209 val = comptypes_check_enum_int (mvl, mvr, &enum_and_int_p);
1212 pedwarn (location, OPT_pedantic, "types are not quite compatible");
1214 if (val == 1 && enum_and_int_p && warn_cxx_compat)
1215 warning_at (location, OPT_Wc___compat,
1216 "pointer target types incompatible in C++");
1221 /* Subroutines of `comptypes'. */
1223 /* Determine whether two trees derive from the same translation unit.
1224 If the CONTEXT chain ends in a null, that tree's context is still
1225 being parsed, so if two trees have context chains ending in null,
1226 they're in the same translation unit. */
1228 same_translation_unit_p (const_tree t1, const_tree t2)
1230 while (t1 && TREE_CODE (t1) != TRANSLATION_UNIT_DECL)
1231 switch (TREE_CODE_CLASS (TREE_CODE (t1)))
1233 case tcc_declaration:
1234 t1 = DECL_CONTEXT (t1); break;
1236 t1 = TYPE_CONTEXT (t1); break;
1237 case tcc_exceptional:
1238 t1 = BLOCK_SUPERCONTEXT (t1); break; /* assume block */
1239 default: gcc_unreachable ();
1242 while (t2 && TREE_CODE (t2) != TRANSLATION_UNIT_DECL)
1243 switch (TREE_CODE_CLASS (TREE_CODE (t2)))
1245 case tcc_declaration:
1246 t2 = DECL_CONTEXT (t2); break;
1248 t2 = TYPE_CONTEXT (t2); break;
1249 case tcc_exceptional:
1250 t2 = BLOCK_SUPERCONTEXT (t2); break; /* assume block */
1251 default: gcc_unreachable ();
1257 /* Allocate the seen two types, assuming that they are compatible. */
1259 static struct tagged_tu_seen_cache *
1260 alloc_tagged_tu_seen_cache (const_tree t1, const_tree t2)
1262 struct tagged_tu_seen_cache *tu = XNEW (struct tagged_tu_seen_cache);
1263 tu->next = tagged_tu_seen_base;
1267 tagged_tu_seen_base = tu;
1269 /* The C standard says that two structures in different translation
1270 units are compatible with each other only if the types of their
1271 fields are compatible (among other things). We assume that they
1272 are compatible until proven otherwise when building the cache.
1273 An example where this can occur is:
1278 If we are comparing this against a similar struct in another TU,
1279 and did not assume they were compatible, we end up with an infinite
1285 /* Free the seen types until we get to TU_TIL. */
1288 free_all_tagged_tu_seen_up_to (const struct tagged_tu_seen_cache *tu_til)
1290 const struct tagged_tu_seen_cache *tu = tagged_tu_seen_base;
1291 while (tu != tu_til)
1293 const struct tagged_tu_seen_cache *const tu1
1294 = (const struct tagged_tu_seen_cache *) tu;
1296 free (CONST_CAST (struct tagged_tu_seen_cache *, tu1));
1298 tagged_tu_seen_base = tu_til;
1301 /* Return 1 if two 'struct', 'union', or 'enum' types T1 and T2 are
1302 compatible. If the two types are not the same (which has been
1303 checked earlier), this can only happen when multiple translation
1304 units are being compiled. See C99 6.2.7 paragraph 1 for the exact
1305 rules. ENUM_AND_INT_P and DIFFERENT_TYPES_P are as in
1306 comptypes_internal. */
1309 tagged_types_tu_compatible_p (const_tree t1, const_tree t2,
1310 bool *enum_and_int_p, bool *different_types_p)
1313 bool needs_warning = false;
1315 /* We have to verify that the tags of the types are the same. This
1316 is harder than it looks because this may be a typedef, so we have
1317 to go look at the original type. It may even be a typedef of a
1319 In the case of compiler-created builtin structs the TYPE_DECL
1320 may be a dummy, with no DECL_ORIGINAL_TYPE. Don't fault. */
1321 while (TYPE_NAME (t1)
1322 && TREE_CODE (TYPE_NAME (t1)) == TYPE_DECL
1323 && DECL_ORIGINAL_TYPE (TYPE_NAME (t1)))
1324 t1 = DECL_ORIGINAL_TYPE (TYPE_NAME (t1));
1326 while (TYPE_NAME (t2)
1327 && TREE_CODE (TYPE_NAME (t2)) == TYPE_DECL
1328 && DECL_ORIGINAL_TYPE (TYPE_NAME (t2)))
1329 t2 = DECL_ORIGINAL_TYPE (TYPE_NAME (t2));
1331 /* C90 didn't have the requirement that the two tags be the same. */
1332 if (flag_isoc99 && TYPE_NAME (t1) != TYPE_NAME (t2))
1335 /* C90 didn't say what happened if one or both of the types were
1336 incomplete; we choose to follow C99 rules here, which is that they
1338 if (TYPE_SIZE (t1) == NULL
1339 || TYPE_SIZE (t2) == NULL)
1343 const struct tagged_tu_seen_cache * tts_i;
1344 for (tts_i = tagged_tu_seen_base; tts_i != NULL; tts_i = tts_i->next)
1345 if (tts_i->t1 == t1 && tts_i->t2 == t2)
1349 switch (TREE_CODE (t1))
1353 struct tagged_tu_seen_cache *tu = alloc_tagged_tu_seen_cache (t1, t2);
1354 /* Speed up the case where the type values are in the same order. */
1355 tree tv1 = TYPE_VALUES (t1);
1356 tree tv2 = TYPE_VALUES (t2);
1363 for (;tv1 && tv2; tv1 = TREE_CHAIN (tv1), tv2 = TREE_CHAIN (tv2))
1365 if (TREE_PURPOSE (tv1) != TREE_PURPOSE (tv2))
1367 if (simple_cst_equal (TREE_VALUE (tv1), TREE_VALUE (tv2)) != 1)
1374 if (tv1 == NULL_TREE && tv2 == NULL_TREE)
1378 if (tv1 == NULL_TREE || tv2 == NULL_TREE)
1384 if (list_length (TYPE_VALUES (t1)) != list_length (TYPE_VALUES (t2)))
1390 for (s1 = TYPE_VALUES (t1); s1; s1 = TREE_CHAIN (s1))
1392 s2 = purpose_member (TREE_PURPOSE (s1), TYPE_VALUES (t2));
1394 || simple_cst_equal (TREE_VALUE (s1), TREE_VALUE (s2)) != 1)
1405 struct tagged_tu_seen_cache *tu = alloc_tagged_tu_seen_cache (t1, t2);
1406 if (list_length (TYPE_FIELDS (t1)) != list_length (TYPE_FIELDS (t2)))
1412 /* Speed up the common case where the fields are in the same order. */
1413 for (s1 = TYPE_FIELDS (t1), s2 = TYPE_FIELDS (t2); s1 && s2;
1414 s1 = DECL_CHAIN (s1), s2 = DECL_CHAIN (s2))
1418 if (DECL_NAME (s1) != DECL_NAME (s2))
1420 result = comptypes_internal (TREE_TYPE (s1), TREE_TYPE (s2),
1421 enum_and_int_p, different_types_p);
1423 if (result != 1 && !DECL_NAME (s1))
1431 needs_warning = true;
1433 if (TREE_CODE (s1) == FIELD_DECL
1434 && simple_cst_equal (DECL_FIELD_BIT_OFFSET (s1),
1435 DECL_FIELD_BIT_OFFSET (s2)) != 1)
1443 tu->val = needs_warning ? 2 : 1;
1447 for (s1 = TYPE_FIELDS (t1); s1; s1 = DECL_CHAIN (s1))
1451 for (s2 = TYPE_FIELDS (t2); s2; s2 = DECL_CHAIN (s2))
1452 if (DECL_NAME (s1) == DECL_NAME (s2))
1456 result = comptypes_internal (TREE_TYPE (s1), TREE_TYPE (s2),
1460 if (result != 1 && !DECL_NAME (s1))
1468 needs_warning = true;
1470 if (TREE_CODE (s1) == FIELD_DECL
1471 && simple_cst_equal (DECL_FIELD_BIT_OFFSET (s1),
1472 DECL_FIELD_BIT_OFFSET (s2)) != 1)
1484 tu->val = needs_warning ? 2 : 10;
1490 struct tagged_tu_seen_cache *tu = alloc_tagged_tu_seen_cache (t1, t2);
1492 for (s1 = TYPE_FIELDS (t1), s2 = TYPE_FIELDS (t2);
1494 s1 = DECL_CHAIN (s1), s2 = DECL_CHAIN (s2))
1497 if (TREE_CODE (s1) != TREE_CODE (s2)
1498 || DECL_NAME (s1) != DECL_NAME (s2))
1500 result = comptypes_internal (TREE_TYPE (s1), TREE_TYPE (s2),
1501 enum_and_int_p, different_types_p);
1505 needs_warning = true;
1507 if (TREE_CODE (s1) == FIELD_DECL
1508 && simple_cst_equal (DECL_FIELD_BIT_OFFSET (s1),
1509 DECL_FIELD_BIT_OFFSET (s2)) != 1)
1515 tu->val = needs_warning ? 2 : 1;
1524 /* Return 1 if two function types F1 and F2 are compatible.
1525 If either type specifies no argument types,
1526 the other must specify a fixed number of self-promoting arg types.
1527 Otherwise, if one type specifies only the number of arguments,
1528 the other must specify that number of self-promoting arg types.
1529 Otherwise, the argument types must match.
1530 ENUM_AND_INT_P and DIFFERENT_TYPES_P are as in comptypes_internal. */
1533 function_types_compatible_p (const_tree f1, const_tree f2,
1534 bool *enum_and_int_p, bool *different_types_p)
1537 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
1542 ret1 = TREE_TYPE (f1);
1543 ret2 = TREE_TYPE (f2);
1545 /* 'volatile' qualifiers on a function's return type used to mean
1546 the function is noreturn. */
1547 if (TYPE_VOLATILE (ret1) != TYPE_VOLATILE (ret2))
1548 pedwarn (input_location, 0, "function return types not compatible due to %<volatile%>");
1549 if (TYPE_VOLATILE (ret1))
1550 ret1 = build_qualified_type (TYPE_MAIN_VARIANT (ret1),
1551 TYPE_QUALS (ret1) & ~TYPE_QUAL_VOLATILE);
1552 if (TYPE_VOLATILE (ret2))
1553 ret2 = build_qualified_type (TYPE_MAIN_VARIANT (ret2),
1554 TYPE_QUALS (ret2) & ~TYPE_QUAL_VOLATILE);
1555 val = comptypes_internal (ret1, ret2, enum_and_int_p, different_types_p);
1559 args1 = TYPE_ARG_TYPES (f1);
1560 args2 = TYPE_ARG_TYPES (f2);
1562 if (different_types_p != NULL
1563 && (args1 == 0) != (args2 == 0))
1564 *different_types_p = true;
1566 /* An unspecified parmlist matches any specified parmlist
1567 whose argument types don't need default promotions. */
1571 if (!self_promoting_args_p (args2))
1573 /* If one of these types comes from a non-prototype fn definition,
1574 compare that with the other type's arglist.
1575 If they don't match, ask for a warning (but no error). */
1576 if (TYPE_ACTUAL_ARG_TYPES (f1)
1577 && 1 != type_lists_compatible_p (args2, TYPE_ACTUAL_ARG_TYPES (f1),
1578 enum_and_int_p, different_types_p))
1584 if (!self_promoting_args_p (args1))
1586 if (TYPE_ACTUAL_ARG_TYPES (f2)
1587 && 1 != type_lists_compatible_p (args1, TYPE_ACTUAL_ARG_TYPES (f2),
1588 enum_and_int_p, different_types_p))
1593 /* Both types have argument lists: compare them and propagate results. */
1594 val1 = type_lists_compatible_p (args1, args2, enum_and_int_p,
1596 return val1 != 1 ? val1 : val;
1599 /* Check two lists of types for compatibility, returning 0 for
1600 incompatible, 1 for compatible, or 2 for compatible with
1601 warning. ENUM_AND_INT_P and DIFFERENT_TYPES_P are as in
1602 comptypes_internal. */
1605 type_lists_compatible_p (const_tree args1, const_tree args2,
1606 bool *enum_and_int_p, bool *different_types_p)
1608 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
1614 tree a1, mv1, a2, mv2;
1615 if (args1 == 0 && args2 == 0)
1617 /* If one list is shorter than the other,
1618 they fail to match. */
1619 if (args1 == 0 || args2 == 0)
1621 mv1 = a1 = TREE_VALUE (args1);
1622 mv2 = a2 = TREE_VALUE (args2);
1623 if (mv1 && mv1 != error_mark_node && TREE_CODE (mv1) != ARRAY_TYPE)
1624 mv1 = TYPE_MAIN_VARIANT (mv1);
1625 if (mv2 && mv2 != error_mark_node && TREE_CODE (mv2) != ARRAY_TYPE)
1626 mv2 = TYPE_MAIN_VARIANT (mv2);
1627 /* A null pointer instead of a type
1628 means there is supposed to be an argument
1629 but nothing is specified about what type it has.
1630 So match anything that self-promotes. */
1631 if (different_types_p != NULL
1632 && (a1 == 0) != (a2 == 0))
1633 *different_types_p = true;
1636 if (c_type_promotes_to (a2) != a2)
1641 if (c_type_promotes_to (a1) != a1)
1644 /* If one of the lists has an error marker, ignore this arg. */
1645 else if (TREE_CODE (a1) == ERROR_MARK
1646 || TREE_CODE (a2) == ERROR_MARK)
1648 else if (!(newval = comptypes_internal (mv1, mv2, enum_and_int_p,
1649 different_types_p)))
1651 if (different_types_p != NULL)
1652 *different_types_p = true;
1653 /* Allow wait (union {union wait *u; int *i} *)
1654 and wait (union wait *) to be compatible. */
1655 if (TREE_CODE (a1) == UNION_TYPE
1656 && (TYPE_NAME (a1) == 0
1657 || TYPE_TRANSPARENT_AGGR (a1))
1658 && TREE_CODE (TYPE_SIZE (a1)) == INTEGER_CST
1659 && tree_int_cst_equal (TYPE_SIZE (a1),
1663 for (memb = TYPE_FIELDS (a1);
1664 memb; memb = DECL_CHAIN (memb))
1666 tree mv3 = TREE_TYPE (memb);
1667 if (mv3 && mv3 != error_mark_node
1668 && TREE_CODE (mv3) != ARRAY_TYPE)
1669 mv3 = TYPE_MAIN_VARIANT (mv3);
1670 if (comptypes_internal (mv3, mv2, enum_and_int_p,
1677 else if (TREE_CODE (a2) == UNION_TYPE
1678 && (TYPE_NAME (a2) == 0
1679 || TYPE_TRANSPARENT_AGGR (a2))
1680 && TREE_CODE (TYPE_SIZE (a2)) == INTEGER_CST
1681 && tree_int_cst_equal (TYPE_SIZE (a2),
1685 for (memb = TYPE_FIELDS (a2);
1686 memb; memb = DECL_CHAIN (memb))
1688 tree mv3 = TREE_TYPE (memb);
1689 if (mv3 && mv3 != error_mark_node
1690 && TREE_CODE (mv3) != ARRAY_TYPE)
1691 mv3 = TYPE_MAIN_VARIANT (mv3);
1692 if (comptypes_internal (mv3, mv1, enum_and_int_p,
1703 /* comptypes said ok, but record if it said to warn. */
1707 args1 = TREE_CHAIN (args1);
1708 args2 = TREE_CHAIN (args2);
1712 /* Compute the size to increment a pointer by. */
1715 c_size_in_bytes (const_tree type)
1717 enum tree_code code = TREE_CODE (type);
1719 if (code == FUNCTION_TYPE || code == VOID_TYPE || code == ERROR_MARK)
1720 return size_one_node;
1722 if (!COMPLETE_OR_VOID_TYPE_P (type))
1724 error ("arithmetic on pointer to an incomplete type");
1725 return size_one_node;
1728 /* Convert in case a char is more than one unit. */
1729 return size_binop_loc (input_location, CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
1730 size_int (TYPE_PRECISION (char_type_node)
1734 /* Return either DECL or its known constant value (if it has one). */
1737 decl_constant_value (tree decl)
1739 if (/* Don't change a variable array bound or initial value to a constant
1740 in a place where a variable is invalid. Note that DECL_INITIAL
1741 isn't valid for a PARM_DECL. */
1742 current_function_decl != 0
1743 && TREE_CODE (decl) != PARM_DECL
1744 && !TREE_THIS_VOLATILE (decl)
1745 && TREE_READONLY (decl)
1746 && DECL_INITIAL (decl) != 0
1747 && TREE_CODE (DECL_INITIAL (decl)) != ERROR_MARK
1748 /* This is invalid if initial value is not constant.
1749 If it has either a function call, a memory reference,
1750 or a variable, then re-evaluating it could give different results. */
1751 && TREE_CONSTANT (DECL_INITIAL (decl))
1752 /* Check for cases where this is sub-optimal, even though valid. */
1753 && TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR)
1754 return DECL_INITIAL (decl);
1758 /* Convert the array expression EXP to a pointer. */
1760 array_to_pointer_conversion (location_t loc, tree exp)
1762 tree orig_exp = exp;
1763 tree type = TREE_TYPE (exp);
1765 tree restype = TREE_TYPE (type);
1768 gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
1770 STRIP_TYPE_NOPS (exp);
1772 if (TREE_NO_WARNING (orig_exp))
1773 TREE_NO_WARNING (exp) = 1;
1775 ptrtype = build_pointer_type (restype);
1777 if (TREE_CODE (exp) == INDIRECT_REF)
1778 return convert (ptrtype, TREE_OPERAND (exp, 0));
1780 adr = build_unary_op (loc, ADDR_EXPR, exp, 1);
1781 return convert (ptrtype, adr);
1784 /* Convert the function expression EXP to a pointer. */
1786 function_to_pointer_conversion (location_t loc, tree exp)
1788 tree orig_exp = exp;
1790 gcc_assert (TREE_CODE (TREE_TYPE (exp)) == FUNCTION_TYPE);
1792 STRIP_TYPE_NOPS (exp);
1794 if (TREE_NO_WARNING (orig_exp))
1795 TREE_NO_WARNING (exp) = 1;
1797 return build_unary_op (loc, ADDR_EXPR, exp, 0);
1800 /* Mark EXP as read, not just set, for set but not used -Wunused
1801 warning purposes. */
1804 mark_exp_read (tree exp)
1806 switch (TREE_CODE (exp))
1810 DECL_READ_P (exp) = 1;
1819 mark_exp_read (TREE_OPERAND (exp, 0));
1822 case C_MAYBE_CONST_EXPR:
1823 mark_exp_read (TREE_OPERAND (exp, 1));
1830 /* Perform the default conversion of arrays and functions to pointers.
1831 Return the result of converting EXP. For any other expression, just
1834 LOC is the location of the expression. */
1837 default_function_array_conversion (location_t loc, struct c_expr exp)
1839 tree orig_exp = exp.value;
1840 tree type = TREE_TYPE (exp.value);
1841 enum tree_code code = TREE_CODE (type);
1847 bool not_lvalue = false;
1848 bool lvalue_array_p;
1850 while ((TREE_CODE (exp.value) == NON_LVALUE_EXPR
1851 || CONVERT_EXPR_P (exp.value))
1852 && TREE_TYPE (TREE_OPERAND (exp.value, 0)) == type)
1854 if (TREE_CODE (exp.value) == NON_LVALUE_EXPR)
1856 exp.value = TREE_OPERAND (exp.value, 0);
1859 if (TREE_NO_WARNING (orig_exp))
1860 TREE_NO_WARNING (exp.value) = 1;
1862 lvalue_array_p = !not_lvalue && lvalue_p (exp.value);
1863 if (!flag_isoc99 && !lvalue_array_p)
1865 /* Before C99, non-lvalue arrays do not decay to pointers.
1866 Normally, using such an array would be invalid; but it can
1867 be used correctly inside sizeof or as a statement expression.
1868 Thus, do not give an error here; an error will result later. */
1872 exp.value = array_to_pointer_conversion (loc, exp.value);
1876 exp.value = function_to_pointer_conversion (loc, exp.value);
1886 default_function_array_read_conversion (location_t loc, struct c_expr exp)
1888 mark_exp_read (exp.value);
1889 return default_function_array_conversion (loc, exp);
1892 /* EXP is an expression of integer type. Apply the integer promotions
1893 to it and return the promoted value. */
1896 perform_integral_promotions (tree exp)
1898 tree type = TREE_TYPE (exp);
1899 enum tree_code code = TREE_CODE (type);
1901 gcc_assert (INTEGRAL_TYPE_P (type));
1903 /* Normally convert enums to int,
1904 but convert wide enums to something wider. */
1905 if (code == ENUMERAL_TYPE)
1907 type = c_common_type_for_size (MAX (TYPE_PRECISION (type),
1908 TYPE_PRECISION (integer_type_node)),
1909 ((TYPE_PRECISION (type)
1910 >= TYPE_PRECISION (integer_type_node))
1911 && TYPE_UNSIGNED (type)));
1913 return convert (type, exp);
1916 /* ??? This should no longer be needed now bit-fields have their
1918 if (TREE_CODE (exp) == COMPONENT_REF
1919 && DECL_C_BIT_FIELD (TREE_OPERAND (exp, 1))
1920 /* If it's thinner than an int, promote it like a
1921 c_promoting_integer_type_p, otherwise leave it alone. */
1922 && 0 > compare_tree_int (DECL_SIZE (TREE_OPERAND (exp, 1)),
1923 TYPE_PRECISION (integer_type_node)))
1924 return convert (integer_type_node, exp);
1926 if (c_promoting_integer_type_p (type))
1928 /* Preserve unsignedness if not really getting any wider. */
1929 if (TYPE_UNSIGNED (type)
1930 && TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
1931 return convert (unsigned_type_node, exp);
1933 return convert (integer_type_node, exp);
1940 /* Perform default promotions for C data used in expressions.
1941 Enumeral types or short or char are converted to int.
1942 In addition, manifest constants symbols are replaced by their values. */
1945 default_conversion (tree exp)
1948 tree type = TREE_TYPE (exp);
1949 enum tree_code code = TREE_CODE (type);
1952 mark_exp_read (exp);
1954 /* Functions and arrays have been converted during parsing. */
1955 gcc_assert (code != FUNCTION_TYPE);
1956 if (code == ARRAY_TYPE)
1959 /* Constants can be used directly unless they're not loadable. */
1960 if (TREE_CODE (exp) == CONST_DECL)
1961 exp = DECL_INITIAL (exp);
1963 /* Strip no-op conversions. */
1965 STRIP_TYPE_NOPS (exp);
1967 if (TREE_NO_WARNING (orig_exp))
1968 TREE_NO_WARNING (exp) = 1;
1970 if (code == VOID_TYPE)
1972 error ("void value not ignored as it ought to be");
1973 return error_mark_node;
1976 exp = require_complete_type (exp);
1977 if (exp == error_mark_node)
1978 return error_mark_node;
1980 promoted_type = targetm.promoted_type (type);
1982 return convert (promoted_type, exp);
1984 if (INTEGRAL_TYPE_P (type))
1985 return perform_integral_promotions (exp);
1990 /* Look up COMPONENT in a structure or union TYPE.
1992 If the component name is not found, returns NULL_TREE. Otherwise,
1993 the return value is a TREE_LIST, with each TREE_VALUE a FIELD_DECL
1994 stepping down the chain to the component, which is in the last
1995 TREE_VALUE of the list. Normally the list is of length one, but if
1996 the component is embedded within (nested) anonymous structures or
1997 unions, the list steps down the chain to the component. */
2000 lookup_field (tree type, tree component)
2004 /* If TYPE_LANG_SPECIFIC is set, then it is a sorted array of pointers
2005 to the field elements. Use a binary search on this array to quickly
2006 find the element. Otherwise, do a linear search. TYPE_LANG_SPECIFIC
2007 will always be set for structures which have many elements. */
2009 if (TYPE_LANG_SPECIFIC (type) && TYPE_LANG_SPECIFIC (type)->s)
2012 tree *field_array = &TYPE_LANG_SPECIFIC (type)->s->elts[0];
2014 field = TYPE_FIELDS (type);
2016 top = TYPE_LANG_SPECIFIC (type)->s->len;
2017 while (top - bot > 1)
2019 half = (top - bot + 1) >> 1;
2020 field = field_array[bot+half];
2022 if (DECL_NAME (field) == NULL_TREE)
2024 /* Step through all anon unions in linear fashion. */
2025 while (DECL_NAME (field_array[bot]) == NULL_TREE)
2027 field = field_array[bot++];
2028 if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE
2029 || TREE_CODE (TREE_TYPE (field)) == UNION_TYPE)
2031 tree anon = lookup_field (TREE_TYPE (field), component);
2034 return tree_cons (NULL_TREE, field, anon);
2036 /* The Plan 9 compiler permits referring
2037 directly to an anonymous struct/union field
2038 using a typedef name. */
2039 if (flag_plan9_extensions
2040 && TYPE_NAME (TREE_TYPE (field)) != NULL_TREE
2041 && (TREE_CODE (TYPE_NAME (TREE_TYPE (field)))
2043 && (DECL_NAME (TYPE_NAME (TREE_TYPE (field)))
2049 /* Entire record is only anon unions. */
2053 /* Restart the binary search, with new lower bound. */
2057 if (DECL_NAME (field) == component)
2059 if (DECL_NAME (field) < component)
2065 if (DECL_NAME (field_array[bot]) == component)
2066 field = field_array[bot];
2067 else if (DECL_NAME (field) != component)
2072 for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
2074 if (DECL_NAME (field) == NULL_TREE
2075 && (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE
2076 || TREE_CODE (TREE_TYPE (field)) == UNION_TYPE))
2078 tree anon = lookup_field (TREE_TYPE (field), component);
2081 return tree_cons (NULL_TREE, field, anon);
2083 /* The Plan 9 compiler permits referring directly to an
2084 anonymous struct/union field using a typedef
2086 if (flag_plan9_extensions
2087 && TYPE_NAME (TREE_TYPE (field)) != NULL_TREE
2088 && TREE_CODE (TYPE_NAME (TREE_TYPE (field))) == TYPE_DECL
2089 && (DECL_NAME (TYPE_NAME (TREE_TYPE (field)))
2094 if (DECL_NAME (field) == component)
2098 if (field == NULL_TREE)
2102 return tree_cons (NULL_TREE, field, NULL_TREE);
2105 /* Make an expression to refer to the COMPONENT field of structure or
2106 union value DATUM. COMPONENT is an IDENTIFIER_NODE. LOC is the
2107 location of the COMPONENT_REF. */
2110 build_component_ref (location_t loc, tree datum, tree component)
2112 tree type = TREE_TYPE (datum);
2113 enum tree_code code = TREE_CODE (type);
2116 bool datum_lvalue = lvalue_p (datum);
2118 if (!objc_is_public (datum, component))
2119 return error_mark_node;
2121 /* Detect Objective-C property syntax object.property. */
2122 if (c_dialect_objc ()
2123 && (ref = objc_maybe_build_component_ref (datum, component)))
2126 /* See if there is a field or component with name COMPONENT. */
2128 if (code == RECORD_TYPE || code == UNION_TYPE)
2130 if (!COMPLETE_TYPE_P (type))
2132 c_incomplete_type_error (NULL_TREE, type);
2133 return error_mark_node;
2136 field = lookup_field (type, component);
2140 error_at (loc, "%qT has no member named %qE", type, component);
2141 return error_mark_node;
2144 /* Chain the COMPONENT_REFs if necessary down to the FIELD.
2145 This might be better solved in future the way the C++ front
2146 end does it - by giving the anonymous entities each a
2147 separate name and type, and then have build_component_ref
2148 recursively call itself. We can't do that here. */
2151 tree subdatum = TREE_VALUE (field);
2154 bool use_datum_quals;
2156 if (TREE_TYPE (subdatum) == error_mark_node)
2157 return error_mark_node;
2159 /* If this is an rvalue, it does not have qualifiers in C
2160 standard terms and we must avoid propagating such
2161 qualifiers down to a non-lvalue array that is then
2162 converted to a pointer. */
2163 use_datum_quals = (datum_lvalue
2164 || TREE_CODE (TREE_TYPE (subdatum)) != ARRAY_TYPE);
2166 quals = TYPE_QUALS (strip_array_types (TREE_TYPE (subdatum)));
2167 if (use_datum_quals)
2168 quals |= TYPE_QUALS (TREE_TYPE (datum));
2169 subtype = c_build_qualified_type (TREE_TYPE (subdatum), quals);
2171 ref = build3 (COMPONENT_REF, subtype, datum, subdatum,
2173 SET_EXPR_LOCATION (ref, loc);
2174 if (TREE_READONLY (subdatum)
2175 || (use_datum_quals && TREE_READONLY (datum)))
2176 TREE_READONLY (ref) = 1;
2177 if (TREE_THIS_VOLATILE (subdatum)
2178 || (use_datum_quals && TREE_THIS_VOLATILE (datum)))
2179 TREE_THIS_VOLATILE (ref) = 1;
2181 if (TREE_DEPRECATED (subdatum))
2182 warn_deprecated_use (subdatum, NULL_TREE);
2186 field = TREE_CHAIN (field);
2192 else if (code != ERROR_MARK)
2194 "request for member %qE in something not a structure or union",
2197 return error_mark_node;
2200 /* Given an expression PTR for a pointer, return an expression
2201 for the value pointed to.
2202 ERRORSTRING is the name of the operator to appear in error messages.
2204 LOC is the location to use for the generated tree. */
2207 build_indirect_ref (location_t loc, tree ptr, ref_operator errstring)
2209 tree pointer = default_conversion (ptr);
2210 tree type = TREE_TYPE (pointer);
2213 if (TREE_CODE (type) == POINTER_TYPE)
2215 if (CONVERT_EXPR_P (pointer)
2216 || TREE_CODE (pointer) == VIEW_CONVERT_EXPR)
2218 /* If a warning is issued, mark it to avoid duplicates from
2219 the backend. This only needs to be done at
2220 warn_strict_aliasing > 2. */
2221 if (warn_strict_aliasing > 2)
2222 if (strict_aliasing_warning (TREE_TYPE (TREE_OPERAND (pointer, 0)),
2223 type, TREE_OPERAND (pointer, 0)))
2224 TREE_NO_WARNING (pointer) = 1;
2227 if (TREE_CODE (pointer) == ADDR_EXPR
2228 && (TREE_TYPE (TREE_OPERAND (pointer, 0))
2229 == TREE_TYPE (type)))
2231 ref = TREE_OPERAND (pointer, 0);
2232 protected_set_expr_location (ref, loc);
2237 tree t = TREE_TYPE (type);
2239 ref = build1 (INDIRECT_REF, t, pointer);
2241 if (!COMPLETE_OR_VOID_TYPE_P (t) && TREE_CODE (t) != ARRAY_TYPE)
2243 error_at (loc, "dereferencing pointer to incomplete type");
2244 return error_mark_node;
2246 if (VOID_TYPE_P (t) && c_inhibit_evaluation_warnings == 0)
2247 warning_at (loc, 0, "dereferencing %<void *%> pointer");
2249 /* We *must* set TREE_READONLY when dereferencing a pointer to const,
2250 so that we get the proper error message if the result is used
2251 to assign to. Also, &* is supposed to be a no-op.
2252 And ANSI C seems to specify that the type of the result
2253 should be the const type. */
2254 /* A de-reference of a pointer to const is not a const. It is valid
2255 to change it via some other pointer. */
2256 TREE_READONLY (ref) = TYPE_READONLY (t);
2257 TREE_SIDE_EFFECTS (ref)
2258 = TYPE_VOLATILE (t) || TREE_SIDE_EFFECTS (pointer);
2259 TREE_THIS_VOLATILE (ref) = TYPE_VOLATILE (t);
2260 protected_set_expr_location (ref, loc);
2264 else if (TREE_CODE (pointer) != ERROR_MARK)
2265 invalid_indirection_error (loc, type, errstring);
2267 return error_mark_node;
2270 /* This handles expressions of the form "a[i]", which denotes
2273 This is logically equivalent in C to *(a+i), but we may do it differently.
2274 If A is a variable or a member, we generate a primitive ARRAY_REF.
2275 This avoids forcing the array out of registers, and can work on
2276 arrays that are not lvalues (for example, members of structures returned
2279 For vector types, allow vector[i] but not i[vector], and create
2280 *(((type*)&vectortype) + i) for the expression.
2282 LOC is the location to use for the returned expression. */
2285 build_array_ref (location_t loc, tree array, tree index)
2288 bool swapped = false;
2289 if (TREE_TYPE (array) == error_mark_node
2290 || TREE_TYPE (index) == error_mark_node)
2291 return error_mark_node;
2293 if (TREE_CODE (TREE_TYPE (array)) != ARRAY_TYPE
2294 && TREE_CODE (TREE_TYPE (array)) != POINTER_TYPE
2295 /* Allow vector[index] but not index[vector]. */
2296 && TREE_CODE (TREE_TYPE (array)) != VECTOR_TYPE)
2299 if (TREE_CODE (TREE_TYPE (index)) != ARRAY_TYPE
2300 && TREE_CODE (TREE_TYPE (index)) != POINTER_TYPE)
2303 "subscripted value is neither array nor pointer nor vector");
2305 return error_mark_node;
2313 if (!INTEGRAL_TYPE_P (TREE_TYPE (index)))
2315 error_at (loc, "array subscript is not an integer");
2316 return error_mark_node;
2319 if (TREE_CODE (TREE_TYPE (TREE_TYPE (array))) == FUNCTION_TYPE)
2321 error_at (loc, "subscripted value is pointer to function");
2322 return error_mark_node;
2325 /* ??? Existing practice has been to warn only when the char
2326 index is syntactically the index, not for char[array]. */
2328 warn_array_subscript_with_type_char (index);
2330 /* Apply default promotions *after* noticing character types. */
2331 index = default_conversion (index);
2333 gcc_assert (TREE_CODE (TREE_TYPE (index)) == INTEGER_TYPE);
2335 /* For vector[index], convert the vector to a
2336 pointer of the underlying type. */
2337 if (TREE_CODE (TREE_TYPE (array)) == VECTOR_TYPE)
2339 tree type = TREE_TYPE (array);
2342 if (TREE_CODE (index) == INTEGER_CST)
2343 if (!host_integerp (index, 1)
2344 || ((unsigned HOST_WIDE_INT) tree_low_cst (index, 1)
2345 >= TYPE_VECTOR_SUBPARTS (TREE_TYPE (array))))
2346 warning_at (loc, OPT_Warray_bounds, "index value is out of bound");
2348 c_common_mark_addressable_vec (array);
2349 type = build_qualified_type (TREE_TYPE (type), TYPE_QUALS (type));
2350 type = build_pointer_type (type);
2351 type1 = build_pointer_type (TREE_TYPE (array));
2352 array = build1 (ADDR_EXPR, type1, array);
2353 array = convert (type, array);
2356 if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE)
2360 /* An array that is indexed by a non-constant
2361 cannot be stored in a register; we must be able to do
2362 address arithmetic on its address.
2363 Likewise an array of elements of variable size. */
2364 if (TREE_CODE (index) != INTEGER_CST
2365 || (COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (array)))
2366 && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array)))) != INTEGER_CST))
2368 if (!c_mark_addressable (array))
2369 return error_mark_node;
2371 /* An array that is indexed by a constant value which is not within
2372 the array bounds cannot be stored in a register either; because we
2373 would get a crash in store_bit_field/extract_bit_field when trying
2374 to access a non-existent part of the register. */
2375 if (TREE_CODE (index) == INTEGER_CST
2376 && TYPE_DOMAIN (TREE_TYPE (array))
2377 && !int_fits_type_p (index, TYPE_DOMAIN (TREE_TYPE (array))))
2379 if (!c_mark_addressable (array))
2380 return error_mark_node;
2386 while (TREE_CODE (foo) == COMPONENT_REF)
2387 foo = TREE_OPERAND (foo, 0);
2388 if (TREE_CODE (foo) == VAR_DECL && C_DECL_REGISTER (foo))
2389 pedwarn (loc, OPT_pedantic,
2390 "ISO C forbids subscripting %<register%> array");
2391 else if (!flag_isoc99 && !lvalue_p (foo))
2392 pedwarn (loc, OPT_pedantic,
2393 "ISO C90 forbids subscripting non-lvalue array");
2396 type = TREE_TYPE (TREE_TYPE (array));
2397 rval = build4 (ARRAY_REF, type, array, index, NULL_TREE, NULL_TREE);
2398 /* Array ref is const/volatile if the array elements are
2399 or if the array is. */
2400 TREE_READONLY (rval)
2401 |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array)))
2402 | TREE_READONLY (array));
2403 TREE_SIDE_EFFECTS (rval)
2404 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
2405 | TREE_SIDE_EFFECTS (array));
2406 TREE_THIS_VOLATILE (rval)
2407 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
2408 /* This was added by rms on 16 Nov 91.
2409 It fixes vol struct foo *a; a->elts[1]
2410 in an inline function.
2411 Hope it doesn't break something else. */
2412 | TREE_THIS_VOLATILE (array));
2413 ret = require_complete_type (rval);
2414 protected_set_expr_location (ret, loc);
2419 tree ar = default_conversion (array);
2421 if (ar == error_mark_node)
2424 gcc_assert (TREE_CODE (TREE_TYPE (ar)) == POINTER_TYPE);
2425 gcc_assert (TREE_CODE (TREE_TYPE (TREE_TYPE (ar))) != FUNCTION_TYPE);
2427 return build_indirect_ref
2428 (loc, build_binary_op (loc, PLUS_EXPR, ar, index, 0),
2433 /* Build an external reference to identifier ID. FUN indicates
2434 whether this will be used for a function call. LOC is the source
2435 location of the identifier. This sets *TYPE to the type of the
2436 identifier, which is not the same as the type of the returned value
2437 for CONST_DECLs defined as enum constants. If the type of the
2438 identifier is not available, *TYPE is set to NULL. */
2440 build_external_ref (location_t loc, tree id, int fun, tree *type)
2443 tree decl = lookup_name (id);
2445 /* In Objective-C, an instance variable (ivar) may be preferred to
2446 whatever lookup_name() found. */
2447 decl = objc_lookup_ivar (decl, id);
2450 if (decl && decl != error_mark_node)
2453 *type = TREE_TYPE (ref);
2456 /* Implicit function declaration. */
2457 ref = implicitly_declare (loc, id);
2458 else if (decl == error_mark_node)
2459 /* Don't complain about something that's already been
2460 complained about. */
2461 return error_mark_node;
2464 undeclared_variable (loc, id);
2465 return error_mark_node;
2468 if (TREE_TYPE (ref) == error_mark_node)
2469 return error_mark_node;
2471 if (TREE_DEPRECATED (ref))
2472 warn_deprecated_use (ref, NULL_TREE);
2474 /* Recursive call does not count as usage. */
2475 if (ref != current_function_decl)
2477 TREE_USED (ref) = 1;
2480 if (TREE_CODE (ref) == FUNCTION_DECL && !in_alignof)
2482 if (!in_sizeof && !in_typeof)
2483 C_DECL_USED (ref) = 1;
2484 else if (DECL_INITIAL (ref) == 0
2485 && DECL_EXTERNAL (ref)
2486 && !TREE_PUBLIC (ref))
2487 record_maybe_used_decl (ref);
2490 if (TREE_CODE (ref) == CONST_DECL)
2492 used_types_insert (TREE_TYPE (ref));
2495 && TREE_CODE (TREE_TYPE (ref)) == ENUMERAL_TYPE
2496 && C_TYPE_DEFINED_IN_STRUCT (TREE_TYPE (ref)))
2498 warning_at (loc, OPT_Wc___compat,
2499 ("enum constant defined in struct or union "
2500 "is not visible in C++"));
2501 inform (DECL_SOURCE_LOCATION (ref), "enum constant defined here");
2504 ref = DECL_INITIAL (ref);
2505 TREE_CONSTANT (ref) = 1;
2507 else if (current_function_decl != 0
2508 && !DECL_FILE_SCOPE_P (current_function_decl)
2509 && (TREE_CODE (ref) == VAR_DECL
2510 || TREE_CODE (ref) == PARM_DECL
2511 || TREE_CODE (ref) == FUNCTION_DECL))
2513 tree context = decl_function_context (ref);
2515 if (context != 0 && context != current_function_decl)
2516 DECL_NONLOCAL (ref) = 1;
2518 /* C99 6.7.4p3: An inline definition of a function with external
2519 linkage ... shall not contain a reference to an identifier with
2520 internal linkage. */
2521 else if (current_function_decl != 0
2522 && DECL_DECLARED_INLINE_P (current_function_decl)
2523 && DECL_EXTERNAL (current_function_decl)
2524 && VAR_OR_FUNCTION_DECL_P (ref)
2525 && (TREE_CODE (ref) != VAR_DECL || TREE_STATIC (ref))
2526 && ! TREE_PUBLIC (ref)
2527 && DECL_CONTEXT (ref) != current_function_decl)
2528 record_inline_static (loc, current_function_decl, ref,
2534 /* Record details of decls possibly used inside sizeof or typeof. */
2535 struct maybe_used_decl
2539 /* The level seen at (in_sizeof + in_typeof). */
2541 /* The next one at this level or above, or NULL. */
2542 struct maybe_used_decl *next;
2545 static struct maybe_used_decl *maybe_used_decls;
2547 /* Record that DECL, an undefined static function reference seen
2548 inside sizeof or typeof, might be used if the operand of sizeof is
2549 a VLA type or the operand of typeof is a variably modified
2553 record_maybe_used_decl (tree decl)
2555 struct maybe_used_decl *t = XOBNEW (&parser_obstack, struct maybe_used_decl);
2557 t->level = in_sizeof + in_typeof;
2558 t->next = maybe_used_decls;
2559 maybe_used_decls = t;
2562 /* Pop the stack of decls possibly used inside sizeof or typeof. If
2563 USED is false, just discard them. If it is true, mark them used
2564 (if no longer inside sizeof or typeof) or move them to the next
2565 level up (if still inside sizeof or typeof). */
2568 pop_maybe_used (bool used)
2570 struct maybe_used_decl *p = maybe_used_decls;
2571 int cur_level = in_sizeof + in_typeof;
2572 while (p && p->level > cur_level)
2577 C_DECL_USED (p->decl) = 1;
2579 p->level = cur_level;
2583 if (!used || cur_level == 0)
2584 maybe_used_decls = p;
2587 /* Return the result of sizeof applied to EXPR. */
2590 c_expr_sizeof_expr (location_t loc, struct c_expr expr)
2593 if (expr.value == error_mark_node)
2595 ret.value = error_mark_node;
2596 ret.original_code = ERROR_MARK;
2597 ret.original_type = NULL;
2598 pop_maybe_used (false);
2602 bool expr_const_operands = true;
2603 tree folded_expr = c_fully_fold (expr.value, require_constant_value,
2604 &expr_const_operands);
2605 ret.value = c_sizeof (loc, TREE_TYPE (folded_expr));
2606 ret.original_code = ERROR_MARK;
2607 ret.original_type = NULL;
2608 if (c_vla_type_p (TREE_TYPE (folded_expr)))
2610 /* sizeof is evaluated when given a vla (C99 6.5.3.4p2). */
2611 ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
2612 folded_expr, ret.value);
2613 C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !expr_const_operands;
2614 SET_EXPR_LOCATION (ret.value, loc);
2616 pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (folded_expr)));
2621 /* Return the result of sizeof applied to T, a structure for the type
2622 name passed to sizeof (rather than the type itself). LOC is the
2623 location of the original expression. */
2626 c_expr_sizeof_type (location_t loc, struct c_type_name *t)
2630 tree type_expr = NULL_TREE;
2631 bool type_expr_const = true;
2632 type = groktypename (t, &type_expr, &type_expr_const);
2633 ret.value = c_sizeof (loc, type);
2634 ret.original_code = ERROR_MARK;
2635 ret.original_type = NULL;
2636 if ((type_expr || TREE_CODE (ret.value) == INTEGER_CST)
2637 && c_vla_type_p (type))
2639 /* If the type is a [*] array, it is a VLA but is represented as
2640 having a size of zero. In such a case we must ensure that
2641 the result of sizeof does not get folded to a constant by
2642 c_fully_fold, because if the size is evaluated the result is
2643 not constant and so constraints on zero or negative size
2644 arrays must not be applied when this sizeof call is inside
2645 another array declarator. */
2647 type_expr = integer_zero_node;
2648 ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
2649 type_expr, ret.value);
2650 C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !type_expr_const;
2652 pop_maybe_used (type != error_mark_node
2653 ? C_TYPE_VARIABLE_SIZE (type) : false);
2657 /* Build a function call to function FUNCTION with parameters PARAMS.
2658 The function call is at LOC.
2659 PARAMS is a list--a chain of TREE_LIST nodes--in which the
2660 TREE_VALUE of each node is a parameter-expression.
2661 FUNCTION's data type may be a function type or a pointer-to-function. */
2664 build_function_call (location_t loc, tree function, tree params)
2669 vec = VEC_alloc (tree, gc, list_length (params));
2670 for (; params; params = TREE_CHAIN (params))
2671 VEC_quick_push (tree, vec, TREE_VALUE (params));
2672 ret = build_function_call_vec (loc, function, vec, NULL);
2673 VEC_free (tree, gc, vec);
2677 /* Build a function call to function FUNCTION with parameters PARAMS.
2678 ORIGTYPES, if not NULL, is a vector of types; each element is
2679 either NULL or the original type of the corresponding element in
2680 PARAMS. The original type may differ from TREE_TYPE of the
2681 parameter for enums. FUNCTION's data type may be a function type
2682 or pointer-to-function. This function changes the elements of
2686 build_function_call_vec (location_t loc, tree function, VEC(tree,gc) *params,
2687 VEC(tree,gc) *origtypes)
2689 tree fntype, fundecl = 0;
2690 tree name = NULL_TREE, result;
2696 /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
2697 STRIP_TYPE_NOPS (function);
2699 /* Convert anything with function type to a pointer-to-function. */
2700 if (TREE_CODE (function) == FUNCTION_DECL)
2702 /* Implement type-directed function overloading for builtins.
2703 resolve_overloaded_builtin and targetm.resolve_overloaded_builtin
2704 handle all the type checking. The result is a complete expression
2705 that implements this function call. */
2706 tem = resolve_overloaded_builtin (loc, function, params);
2710 name = DECL_NAME (function);
2713 if (TREE_CODE (TREE_TYPE (function)) == FUNCTION_TYPE)
2714 function = function_to_pointer_conversion (loc, function);
2716 /* For Objective-C, convert any calls via a cast to OBJC_TYPE_REF
2717 expressions, like those used for ObjC messenger dispatches. */
2718 if (!VEC_empty (tree, params))
2719 function = objc_rewrite_function_call (function,
2720 VEC_index (tree, params, 0));
2722 function = c_fully_fold (function, false, NULL);
2724 fntype = TREE_TYPE (function);
2726 if (TREE_CODE (fntype) == ERROR_MARK)
2727 return error_mark_node;
2729 if (!(TREE_CODE (fntype) == POINTER_TYPE
2730 && TREE_CODE (TREE_TYPE (fntype)) == FUNCTION_TYPE))
2732 error_at (loc, "called object %qE is not a function", function);
2733 return error_mark_node;
2736 if (fundecl && TREE_THIS_VOLATILE (fundecl))
2737 current_function_returns_abnormally = 1;
2739 /* fntype now gets the type of function pointed to. */
2740 fntype = TREE_TYPE (fntype);
2742 /* Convert the parameters to the types declared in the
2743 function prototype, or apply default promotions. */
2745 nargs = convert_arguments (TYPE_ARG_TYPES (fntype), params, origtypes,
2748 return error_mark_node;
2750 /* Check that the function is called through a compatible prototype.
2751 If it is not, replace the call by a trap, wrapped up in a compound
2752 expression if necessary. This has the nice side-effect to prevent
2753 the tree-inliner from generating invalid assignment trees which may
2754 blow up in the RTL expander later. */
2755 if (CONVERT_EXPR_P (function)
2756 && TREE_CODE (tem = TREE_OPERAND (function, 0)) == ADDR_EXPR
2757 && TREE_CODE (tem = TREE_OPERAND (tem, 0)) == FUNCTION_DECL
2758 && !comptypes (fntype, TREE_TYPE (tem)))
2760 tree return_type = TREE_TYPE (fntype);
2761 tree trap = build_function_call (loc, built_in_decls[BUILT_IN_TRAP],
2765 /* This situation leads to run-time undefined behavior. We can't,
2766 therefore, simply error unless we can prove that all possible
2767 executions of the program must execute the code. */
2768 if (warning_at (loc, 0, "function called through a non-compatible type"))
2769 /* We can, however, treat "undefined" any way we please.
2770 Call abort to encourage the user to fix the program. */
2771 inform (loc, "if this code is reached, the program will abort");
2772 /* Before the abort, allow the function arguments to exit or
2774 for (i = 0; i < nargs; i++)
2775 trap = build2 (COMPOUND_EXPR, void_type_node,
2776 VEC_index (tree, params, i), trap);
2778 if (VOID_TYPE_P (return_type))
2780 if (TYPE_QUALS (return_type) != TYPE_UNQUALIFIED)
2782 "function with qualified void return type called");
2789 if (AGGREGATE_TYPE_P (return_type))
2790 rhs = build_compound_literal (loc, return_type,
2791 build_constructor (return_type, 0),
2794 rhs = build_zero_cst (return_type);
2796 return require_complete_type (build2 (COMPOUND_EXPR, return_type,
2801 argarray = VEC_address (tree, params);
2803 /* Check that arguments to builtin functions match the expectations. */
2805 && DECL_BUILT_IN (fundecl)
2806 && DECL_BUILT_IN_CLASS (fundecl) == BUILT_IN_NORMAL
2807 && !check_builtin_function_arguments (fundecl, nargs, argarray))
2808 return error_mark_node;
2810 /* Check that the arguments to the function are valid. */
2811 check_function_arguments (TYPE_ATTRIBUTES (fntype), nargs, argarray,
2812 TYPE_ARG_TYPES (fntype));
2814 if (name != NULL_TREE
2815 && !strncmp (IDENTIFIER_POINTER (name), "__builtin_", 10))
2817 if (require_constant_value)
2819 fold_build_call_array_initializer_loc (loc, TREE_TYPE (fntype),
2820 function, nargs, argarray);
2822 result = fold_build_call_array_loc (loc, TREE_TYPE (fntype),
2823 function, nargs, argarray);
2824 if (TREE_CODE (result) == NOP_EXPR
2825 && TREE_CODE (TREE_OPERAND (result, 0)) == INTEGER_CST)
2826 STRIP_TYPE_NOPS (result);
2829 result = build_call_array_loc (loc, TREE_TYPE (fntype),
2830 function, nargs, argarray);
2832 if (VOID_TYPE_P (TREE_TYPE (result)))
2834 if (TYPE_QUALS (TREE_TYPE (result)) != TYPE_UNQUALIFIED)
2836 "function with qualified void return type called");
2839 return require_complete_type (result);
2842 /* Convert the argument expressions in the vector VALUES
2843 to the types in the list TYPELIST.
2845 If TYPELIST is exhausted, or when an element has NULL as its type,
2846 perform the default conversions.
2848 ORIGTYPES is the original types of the expressions in VALUES. This
2849 holds the type of enum values which have been converted to integral
2850 types. It may be NULL.
2852 FUNCTION is a tree for the called function. It is used only for
2853 error messages, where it is formatted with %qE.
2855 This is also where warnings about wrong number of args are generated.
2857 Returns the actual number of arguments processed (which may be less
2858 than the length of VALUES in some error situations), or -1 on
2862 convert_arguments (tree typelist, VEC(tree,gc) *values,
2863 VEC(tree,gc) *origtypes, tree function, tree fundecl)
2866 unsigned int parmnum;
2867 bool error_args = false;
2868 const bool type_generic = fundecl
2869 && lookup_attribute ("type generic", TYPE_ATTRIBUTES(TREE_TYPE (fundecl)));
2870 bool type_generic_remove_excess_precision = false;
2873 /* Change pointer to function to the function itself for
2875 if (TREE_CODE (function) == ADDR_EXPR
2876 && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL)
2877 function = TREE_OPERAND (function, 0);
2879 /* Handle an ObjC selector specially for diagnostics. */
2880 selector = objc_message_selector ();
2882 /* For type-generic built-in functions, determine whether excess
2883 precision should be removed (classification) or not
2886 && DECL_BUILT_IN (fundecl)
2887 && DECL_BUILT_IN_CLASS (fundecl) == BUILT_IN_NORMAL)
2889 switch (DECL_FUNCTION_CODE (fundecl))
2891 case BUILT_IN_ISFINITE:
2892 case BUILT_IN_ISINF:
2893 case BUILT_IN_ISINF_SIGN:
2894 case BUILT_IN_ISNAN:
2895 case BUILT_IN_ISNORMAL:
2896 case BUILT_IN_FPCLASSIFY:
2897 type_generic_remove_excess_precision = true;
2901 type_generic_remove_excess_precision = false;
2906 /* Scan the given expressions and types, producing individual
2907 converted arguments. */
2909 for (typetail = typelist, parmnum = 0;
2910 VEC_iterate (tree, values, parmnum, val);
2913 tree type = typetail ? TREE_VALUE (typetail) : 0;
2914 tree valtype = TREE_TYPE (val);
2915 tree rname = function;
2916 int argnum = parmnum + 1;
2917 const char *invalid_func_diag;
2918 bool excess_precision = false;
2922 if (type == void_type_node)
2925 error_at (input_location,
2926 "too many arguments to method %qE", selector);
2928 error_at (input_location,
2929 "too many arguments to function %qE", function);
2931 if (fundecl && !DECL_BUILT_IN (fundecl))
2932 inform (DECL_SOURCE_LOCATION (fundecl), "declared here");
2936 if (selector && argnum > 2)
2942 npc = null_pointer_constant_p (val);
2944 /* If there is excess precision and a prototype, convert once to
2945 the required type rather than converting via the semantic
2946 type. Likewise without a prototype a float value represented
2947 as long double should be converted once to double. But for
2948 type-generic classification functions excess precision must
2950 if (TREE_CODE (val) == EXCESS_PRECISION_EXPR
2951 && (type || !type_generic || !type_generic_remove_excess_precision))
2953 val = TREE_OPERAND (val, 0);
2954 excess_precision = true;
2956 val = c_fully_fold (val, false, NULL);
2957 STRIP_TYPE_NOPS (val);
2959 val = require_complete_type (val);
2963 /* Formal parm type is specified by a function prototype. */
2965 if (type == error_mark_node || !COMPLETE_TYPE_P (type))
2967 error ("type of formal parameter %d is incomplete", parmnum + 1);
2974 /* Optionally warn about conversions that
2975 differ from the default conversions. */
2976 if (warn_traditional_conversion || warn_traditional)
2978 unsigned int formal_prec = TYPE_PRECISION (type);
2980 if (INTEGRAL_TYPE_P (type)
2981 && TREE_CODE (valtype) == REAL_TYPE)
2982 warning (0, "passing argument %d of %qE as integer "
2983 "rather than floating due to prototype",
2985 if (INTEGRAL_TYPE_P (type)
2986 && TREE_CODE (valtype) == COMPLEX_TYPE)
2987 warning (0, "passing argument %d of %qE as integer "
2988 "rather than complex due to prototype",
2990 else if (TREE_CODE (type) == COMPLEX_TYPE
2991 && TREE_CODE (valtype) == REAL_TYPE)
2992 warning (0, "passing argument %d of %qE as complex "
2993 "rather than floating due to prototype",
2995 else if (TREE_CODE (type) == REAL_TYPE
2996 && INTEGRAL_TYPE_P (valtype))
2997 warning (0, "passing argument %d of %qE as floating "
2998 "rather than integer due to prototype",
3000 else if (TREE_CODE (type) == COMPLEX_TYPE
3001 && INTEGRAL_TYPE_P (valtype))
3002 warning (0, "passing argument %d of %qE as complex "
3003 "rather than integer due to prototype",
3005 else if (TREE_CODE (type) == REAL_TYPE
3006 && TREE_CODE (valtype) == COMPLEX_TYPE)
3007 warning (0, "passing argument %d of %qE as floating "
3008 "rather than complex due to prototype",
3010 /* ??? At some point, messages should be written about
3011 conversions between complex types, but that's too messy
3013 else if (TREE_CODE (type) == REAL_TYPE
3014 && TREE_CODE (valtype) == REAL_TYPE)
3016 /* Warn if any argument is passed as `float',
3017 since without a prototype it would be `double'. */
3018 if (formal_prec == TYPE_PRECISION (float_type_node)
3019 && type != dfloat32_type_node)
3020 warning (0, "passing argument %d of %qE as %<float%> "
3021 "rather than %<double%> due to prototype",
3024 /* Warn if mismatch between argument and prototype
3025 for decimal float types. Warn of conversions with
3026 binary float types and of precision narrowing due to
3028 else if (type != valtype
3029 && (type == dfloat32_type_node
3030 || type == dfloat64_type_node
3031 || type == dfloat128_type_node
3032 || valtype == dfloat32_type_node
3033 || valtype == dfloat64_type_node
3034 || valtype == dfloat128_type_node)
3036 <= TYPE_PRECISION (valtype)
3037 || (type == dfloat128_type_node
3039 != dfloat64_type_node
3041 != dfloat32_type_node)))
3042 || (type == dfloat64_type_node
3044 != dfloat32_type_node))))
3045 warning (0, "passing argument %d of %qE as %qT "
3046 "rather than %qT due to prototype",
3047 argnum, rname, type, valtype);
3050 /* Detect integer changing in width or signedness.
3051 These warnings are only activated with
3052 -Wtraditional-conversion, not with -Wtraditional. */
3053 else if (warn_traditional_conversion && INTEGRAL_TYPE_P (type)
3054 && INTEGRAL_TYPE_P (valtype))
3056 tree would_have_been = default_conversion (val);
3057 tree type1 = TREE_TYPE (would_have_been);
3059 if (TREE_CODE (type) == ENUMERAL_TYPE
3060 && (TYPE_MAIN_VARIANT (type)
3061 == TYPE_MAIN_VARIANT (valtype)))
3062 /* No warning if function asks for enum
3063 and the actual arg is that enum type. */
3065 else if (formal_prec != TYPE_PRECISION (type1))
3066 warning (OPT_Wtraditional_conversion,
3067 "passing argument %d of %qE "
3068 "with different width due to prototype",
3070 else if (TYPE_UNSIGNED (type) == TYPE_UNSIGNED (type1))
3072 /* Don't complain if the formal parameter type
3073 is an enum, because we can't tell now whether
3074 the value was an enum--even the same enum. */
3075 else if (TREE_CODE (type) == ENUMERAL_TYPE)
3077 else if (TREE_CODE (val) == INTEGER_CST
3078 && int_fits_type_p (val, type))
3079 /* Change in signedness doesn't matter
3080 if a constant value is unaffected. */
3082 /* If the value is extended from a narrower
3083 unsigned type, it doesn't matter whether we
3084 pass it as signed or unsigned; the value
3085 certainly is the same either way. */
3086 else if (TYPE_PRECISION (valtype) < TYPE_PRECISION (type)
3087 && TYPE_UNSIGNED (valtype))
3089 else if (TYPE_UNSIGNED (type))
3090 warning (OPT_Wtraditional_conversion,
3091 "passing argument %d of %qE "
3092 "as unsigned due to prototype",
3095 warning (OPT_Wtraditional_conversion,
3096 "passing argument %d of %qE "
3097 "as signed due to prototype", argnum, rname);
3101 /* Possibly restore an EXCESS_PRECISION_EXPR for the
3102 sake of better warnings from convert_and_check. */
3103 if (excess_precision)
3104 val = build1 (EXCESS_PRECISION_EXPR, valtype, val);
3105 origtype = (origtypes == NULL
3107 : VEC_index (tree, origtypes, parmnum));
3108 parmval = convert_for_assignment (input_location, type, val,
3109 origtype, ic_argpass, npc,
3113 if (targetm.calls.promote_prototypes (fundecl ? TREE_TYPE (fundecl) : 0)
3114 && INTEGRAL_TYPE_P (type)
3115 && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
3116 parmval = default_conversion (parmval);
3119 else if (TREE_CODE (valtype) == REAL_TYPE
3120 && (TYPE_PRECISION (valtype)
3121 < TYPE_PRECISION (double_type_node))
3122 && !DECIMAL_FLOAT_MODE_P (TYPE_MODE (valtype)))
3128 /* Convert `float' to `double'. */
3129 if (warn_double_promotion && !c_inhibit_evaluation_warnings)
3130 warning (OPT_Wdouble_promotion,
3131 "implicit conversion from %qT to %qT when passing "
3132 "argument to function",
3133 valtype, double_type_node);
3134 parmval = convert (double_type_node, val);
3137 else if (excess_precision && !type_generic)
3138 /* A "double" argument with excess precision being passed
3139 without a prototype or in variable arguments. */
3140 parmval = convert (valtype, val);
3141 else if ((invalid_func_diag =
3142 targetm.calls.invalid_arg_for_unprototyped_fn (typelist, fundecl, val)))
3144 error (invalid_func_diag);
3148 /* Convert `short' and `char' to full-size `int'. */
3149 parmval = default_conversion (val);
3151 VEC_replace (tree, values, parmnum, parmval);
3152 if (parmval == error_mark_node)
3156 typetail = TREE_CHAIN (typetail);
3159 gcc_assert (parmnum == VEC_length (tree, values));
3161 if (typetail != 0 && TREE_VALUE (typetail) != void_type_node)
3163 error_at (input_location,
3164 "too few arguments to function %qE", function);
3165 if (fundecl && !DECL_BUILT_IN (fundecl))
3166 inform (DECL_SOURCE_LOCATION (fundecl), "declared here");
3170 return error_args ? -1 : (int) parmnum;
3173 /* This is the entry point used by the parser to build unary operators
3174 in the input. CODE, a tree_code, specifies the unary operator, and
3175 ARG is the operand. For unary plus, the C parser currently uses
3176 CONVERT_EXPR for code.
3178 LOC is the location to use for the tree generated.
3182 parser_build_unary_op (location_t loc, enum tree_code code, struct c_expr arg)
3184 struct c_expr result;
3186 result.value = build_unary_op (loc, code, arg.value, 0);
3187 result.original_code = code;
3188 result.original_type = NULL;
3190 if (TREE_OVERFLOW_P (result.value) && !TREE_OVERFLOW_P (arg.value))
3191 overflow_warning (loc, result.value);
3196 /* This is the entry point used by the parser to build binary operators
3197 in the input. CODE, a tree_code, specifies the binary operator, and
3198 ARG1 and ARG2 are the operands. In addition to constructing the
3199 expression, we check for operands that were written with other binary
3200 operators in a way that is likely to confuse the user.
3202 LOCATION is the location of the binary operator. */
3205 parser_build_binary_op (location_t location, enum tree_code code,
3206 struct c_expr arg1, struct c_expr arg2)
3208 struct c_expr result;
3210 enum tree_code code1 = arg1.original_code;
3211 enum tree_code code2 = arg2.original_code;
3212 tree type1 = (arg1.original_type
3213 ? arg1.original_type
3214 : TREE_TYPE (arg1.value));
3215 tree type2 = (arg2.original_type
3216 ? arg2.original_type
3217 : TREE_TYPE (arg2.value));
3219 result.value = build_binary_op (location, code,
3220 arg1.value, arg2.value, 1);
3221 result.original_code = code;
3222 result.original_type = NULL;
3224 if (TREE_CODE (result.value) == ERROR_MARK)
3227 if (location != UNKNOWN_LOCATION)
3228 protected_set_expr_location (result.value, location);
3230 /* Check for cases such as x+y<<z which users are likely
3232 if (warn_parentheses)
3233 warn_about_parentheses (code, code1, arg1.value, code2, arg2.value);
3235 if (warn_logical_op)
3236 warn_logical_operator (input_location, code, TREE_TYPE (result.value),
3237 code1, arg1.value, code2, arg2.value);
3239 /* Warn about comparisons against string literals, with the exception
3240 of testing for equality or inequality of a string literal with NULL. */
3241 if (code == EQ_EXPR || code == NE_EXPR)
3243 if ((code1 == STRING_CST && !integer_zerop (arg2.value))
3244 || (code2 == STRING_CST && !integer_zerop (arg1.value)))
3245 warning_at (location, OPT_Waddress,
3246 "comparison with string literal results in unspecified behavior");
3248 else if (TREE_CODE_CLASS (code) == tcc_comparison
3249 && (code1 == STRING_CST || code2 == STRING_CST))
3250 warning_at (location, OPT_Waddress,
3251 "comparison with string literal results in unspecified behavior");
3253 if (TREE_OVERFLOW_P (result.value)
3254 && !TREE_OVERFLOW_P (arg1.value)
3255 && !TREE_OVERFLOW_P (arg2.value))
3256 overflow_warning (location, result.value);
3258 /* Warn about comparisons of different enum types. */
3259 if (warn_enum_compare
3260 && TREE_CODE_CLASS (code) == tcc_comparison
3261 && TREE_CODE (type1) == ENUMERAL_TYPE
3262 && TREE_CODE (type2) == ENUMERAL_TYPE
3263 && TYPE_MAIN_VARIANT (type1) != TYPE_MAIN_VARIANT (type2))
3264 warning_at (location, OPT_Wenum_compare,
3265 "comparison between %qT and %qT",
3271 /* Return a tree for the difference of pointers OP0 and OP1.
3272 The resulting tree has type int. */
3275 pointer_diff (location_t loc, tree op0, tree op1)
3277 tree restype = ptrdiff_type_node;
3278 tree result, inttype;
3280 addr_space_t as0 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (op0)));
3281 addr_space_t as1 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (op1)));
3282 tree target_type = TREE_TYPE (TREE_TYPE (op0));
3283 tree con0, con1, lit0, lit1;
3284 tree orig_op1 = op1;
3286 /* If the operands point into different address spaces, we need to
3287 explicitly convert them to pointers into the common address space
3288 before we can subtract the numerical address values. */
3291 addr_space_t as_common;
3294 /* Determine the common superset address space. This is guaranteed
3295 to exist because the caller verified that comp_target_types
3296 returned non-zero. */
3297 if (!addr_space_superset (as0, as1, &as_common))
3300 common_type = common_pointer_type (TREE_TYPE (op0), TREE_TYPE (op1));
3301 op0 = convert (common_type, op0);
3302 op1 = convert (common_type, op1);
3305 /* Determine integer type to perform computations in. This will usually
3306 be the same as the result type (ptrdiff_t), but may need to be a wider
3307 type if pointers for the address space are wider than ptrdiff_t. */
3308 if (TYPE_PRECISION (restype) < TYPE_PRECISION (TREE_TYPE (op0)))
3309 inttype = lang_hooks.types.type_for_size
3310 (TYPE_PRECISION (TREE_TYPE (op0)), 0);
3315 if (TREE_CODE (target_type) == VOID_TYPE)
3316 pedwarn (loc, pedantic ? OPT_pedantic : OPT_Wpointer_arith,
3317 "pointer of type %<void *%> used in subtraction");
3318 if (TREE_CODE (target_type) == FUNCTION_TYPE)
3319 pedwarn (loc, pedantic ? OPT_pedantic : OPT_Wpointer_arith,
3320 "pointer to a function used in subtraction");
3322 /* If the conversion to ptrdiff_type does anything like widening or
3323 converting a partial to an integral mode, we get a convert_expression
3324 that is in the way to do any simplifications.
3325 (fold-const.c doesn't know that the extra bits won't be needed.
3326 split_tree uses STRIP_SIGN_NOPS, which leaves conversions to a
3327 different mode in place.)
3328 So first try to find a common term here 'by hand'; we want to cover
3329 at least the cases that occur in legal static initializers. */
3330 if (CONVERT_EXPR_P (op0)
3331 && (TYPE_PRECISION (TREE_TYPE (op0))
3332 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0, 0)))))
3333 con0 = TREE_OPERAND (op0, 0);
3336 if (CONVERT_EXPR_P (op1)
3337 && (TYPE_PRECISION (TREE_TYPE (op1))
3338 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op1, 0)))))
3339 con1 = TREE_OPERAND (op1, 0);
3343 if (TREE_CODE (con0) == PLUS_EXPR)
3345 lit0 = TREE_OPERAND (con0, 1);
3346 con0 = TREE_OPERAND (con0, 0);
3349 lit0 = integer_zero_node;
3351 if (TREE_CODE (con1) == PLUS_EXPR)
3353 lit1 = TREE_OPERAND (con1, 1);
3354 con1 = TREE_OPERAND (con1, 0);
3357 lit1 = integer_zero_node;
3359 if (operand_equal_p (con0, con1, 0))
3366 /* First do the subtraction as integers;
3367 then drop through to build the divide operator.
3368 Do not do default conversions on the minus operator
3369 in case restype is a short type. */
3371 op0 = build_binary_op (loc,
3372 MINUS_EXPR, convert (inttype, op0),
3373 convert (inttype, op1), 0);
3374 /* This generates an error if op1 is pointer to incomplete type. */
3375 if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (orig_op1))))
3376 error_at (loc, "arithmetic on pointer to an incomplete type");
3378 /* This generates an error if op0 is pointer to incomplete type. */
3379 op1 = c_size_in_bytes (target_type);
3381 /* Divide by the size, in easiest possible way. */
3382 result = fold_build2_loc (loc, EXACT_DIV_EXPR, inttype,
3383 op0, convert (inttype, op1));
3385 /* Convert to final result type if necessary. */
3386 return convert (restype, result);
3389 /* Construct and perhaps optimize a tree representation
3390 for a unary operation. CODE, a tree_code, specifies the operation
3391 and XARG is the operand.
3392 For any CODE other than ADDR_EXPR, FLAG nonzero suppresses
3393 the default promotions (such as from short to int).
3394 For ADDR_EXPR, the default promotions are not applied; FLAG nonzero
3395 allows non-lvalues; this is only used to handle conversion of non-lvalue
3396 arrays to pointers in C99.
3398 LOCATION is the location of the operator. */
3401 build_unary_op (location_t location,
3402 enum tree_code code, tree xarg, int flag)
3404 /* No default_conversion here. It causes trouble for ADDR_EXPR. */
3407 enum tree_code typecode;
3409 tree ret = error_mark_node;
3410 tree eptype = NULL_TREE;
3411 int noconvert = flag;
3412 const char *invalid_op_diag;
3415 int_operands = EXPR_INT_CONST_OPERANDS (xarg);
3417 arg = remove_c_maybe_const_expr (arg);
3419 if (code != ADDR_EXPR)
3420 arg = require_complete_type (arg);
3422 typecode = TREE_CODE (TREE_TYPE (arg));
3423 if (typecode == ERROR_MARK)
3424 return error_mark_node;
3425 if (typecode == ENUMERAL_TYPE || typecode == BOOLEAN_TYPE)
3426 typecode = INTEGER_TYPE;
3428 if ((invalid_op_diag
3429 = targetm.invalid_unary_op (code, TREE_TYPE (xarg))))
3431 error_at (location, invalid_op_diag);
3432 return error_mark_node;
3435 if (TREE_CODE (arg) == EXCESS_PRECISION_EXPR)
3437 eptype = TREE_TYPE (arg);
3438 arg = TREE_OPERAND (arg, 0);
3444 /* This is used for unary plus, because a CONVERT_EXPR
3445 is enough to prevent anybody from looking inside for
3446 associativity, but won't generate any code. */
3447 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
3448 || typecode == FIXED_POINT_TYPE || typecode == COMPLEX_TYPE
3449 || typecode == VECTOR_TYPE))
3451 error_at (location, "wrong type argument to unary plus");
3452 return error_mark_node;
3454 else if (!noconvert)
3455 arg = default_conversion (arg);
3456 arg = non_lvalue_loc (location, arg);
3460 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
3461 || typecode == FIXED_POINT_TYPE || typecode == COMPLEX_TYPE
3462 || typecode == VECTOR_TYPE))
3464 error_at (location, "wrong type argument to unary minus");
3465 return error_mark_node;
3467 else if (!noconvert)
3468 arg = default_conversion (arg);
3472 /* ~ works on integer types and non float vectors. */
3473 if (typecode == INTEGER_TYPE
3474 || (typecode == VECTOR_TYPE
3475 && !VECTOR_FLOAT_TYPE_P (TREE_TYPE (arg))))
3478 arg = default_conversion (arg);
3480 else if (typecode == COMPLEX_TYPE)
3483 pedwarn (location, OPT_pedantic,
3484 "ISO C does not support %<~%> for complex conjugation");
3486 arg = default_conversion (arg);
3490 error_at (location, "wrong type argument to bit-complement");
3491 return error_mark_node;
3496 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE))
3498 error_at (location, "wrong type argument to abs");
3499 return error_mark_node;
3501 else if (!noconvert)
3502 arg = default_conversion (arg);
3506 /* Conjugating a real value is a no-op, but allow it anyway. */
3507 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
3508 || typecode == COMPLEX_TYPE))
3510 error_at (location, "wrong type argument to conjugation");
3511 return error_mark_node;
3513 else if (!noconvert)
3514 arg = default_conversion (arg);
3517 case TRUTH_NOT_EXPR:
3518 if (typecode != INTEGER_TYPE && typecode != FIXED_POINT_TYPE
3519 && typecode != REAL_TYPE && typecode != POINTER_TYPE
3520 && typecode != COMPLEX_TYPE)
3523 "wrong type argument to unary exclamation mark");
3524 return error_mark_node;
3526 arg = c_objc_common_truthvalue_conversion (location, arg);
3527 ret = invert_truthvalue_loc (location, arg);
3528 /* If the TRUTH_NOT_EXPR has been folded, reset the location. */
3529 if (EXPR_P (ret) && EXPR_HAS_LOCATION (ret))
3530 location = EXPR_LOCATION (ret);
3531 goto return_build_unary_op;
3535 ret = build_real_imag_expr (location, code, arg);
3536 if (ret == error_mark_node)
3537 return error_mark_node;
3538 if (eptype && TREE_CODE (eptype) == COMPLEX_TYPE)
3539 eptype = TREE_TYPE (eptype);
3540 goto return_build_unary_op;
3542 case PREINCREMENT_EXPR:
3543 case POSTINCREMENT_EXPR:
3544 case PREDECREMENT_EXPR:
3545 case POSTDECREMENT_EXPR:
3547 if (TREE_CODE (arg) == C_MAYBE_CONST_EXPR)
3549 tree inner = build_unary_op (location, code,
3550 C_MAYBE_CONST_EXPR_EXPR (arg), flag);
3551 if (inner == error_mark_node)
3552 return error_mark_node;
3553 ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (inner),
3554 C_MAYBE_CONST_EXPR_PRE (arg), inner);
3555 gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (arg));
3556 C_MAYBE_CONST_EXPR_NON_CONST (ret) = 1;
3557 goto return_build_unary_op;
3560 /* Complain about anything that is not a true lvalue. In
3561 Objective-C, skip this check for property_refs. */
3562 if (!objc_is_property_ref (arg)
3563 && !lvalue_or_else (location,
3564 arg, ((code == PREINCREMENT_EXPR
3565 || code == POSTINCREMENT_EXPR)
3568 return error_mark_node;
3570 if (warn_cxx_compat && TREE_CODE (TREE_TYPE (arg)) == ENUMERAL_TYPE)
3572 if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
3573 warning_at (location, OPT_Wc___compat,
3574 "increment of enumeration value is invalid in C++");
3576 warning_at (location, OPT_Wc___compat,
3577 "decrement of enumeration value is invalid in C++");
3580 /* Ensure the argument is fully folded inside any SAVE_EXPR. */
3581 arg = c_fully_fold (arg, false, NULL);
3583 /* Increment or decrement the real part of the value,
3584 and don't change the imaginary part. */
3585 if (typecode == COMPLEX_TYPE)
3589 pedwarn (location, OPT_pedantic,
3590 "ISO C does not support %<++%> and %<--%> on complex types");
3592 arg = stabilize_reference (arg);
3593 real = build_unary_op (EXPR_LOCATION (arg), REALPART_EXPR, arg, 1);
3594 imag = build_unary_op (EXPR_LOCATION (arg), IMAGPART_EXPR, arg, 1);
3595 real = build_unary_op (EXPR_LOCATION (arg), code, real, 1);
3596 if (real == error_mark_node || imag == error_mark_node)
3597 return error_mark_node;
3598 ret = build2 (COMPLEX_EXPR, TREE_TYPE (arg),
3600 goto return_build_unary_op;
3603 /* Report invalid types. */
3605 if (typecode != POINTER_TYPE && typecode != FIXED_POINT_TYPE
3606 && typecode != INTEGER_TYPE && typecode != REAL_TYPE)
3608 if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
3609 error_at (location, "wrong type argument to increment");
3611 error_at (location, "wrong type argument to decrement");
3613 return error_mark_node;
3619 argtype = TREE_TYPE (arg);
3621 /* Compute the increment. */
3623 if (typecode == POINTER_TYPE)
3625 /* If pointer target is an undefined struct,
3626 we just cannot know how to do the arithmetic. */
3627 if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (argtype)))
3629 if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
3631 "increment of pointer to unknown structure");
3634 "decrement of pointer to unknown structure");
3636 else if (TREE_CODE (TREE_TYPE (argtype)) == FUNCTION_TYPE
3637 || TREE_CODE (TREE_TYPE (argtype)) == VOID_TYPE)
3639 if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
3640 pedwarn (location, pedantic ? OPT_pedantic : OPT_Wpointer_arith,
3641 "wrong type argument to increment");
3643 pedwarn (location, pedantic ? OPT_pedantic : OPT_Wpointer_arith,
3644 "wrong type argument to decrement");
3647 inc = c_size_in_bytes (TREE_TYPE (argtype));
3648 inc = fold_convert_loc (location, sizetype, inc);
3650 else if (FRACT_MODE_P (TYPE_MODE (argtype)))
3652 /* For signed fract types, we invert ++ to -- or
3653 -- to ++, and change inc from 1 to -1, because
3654 it is not possible to represent 1 in signed fract constants.
3655 For unsigned fract types, the result always overflows and
3656 we get an undefined (original) or the maximum value. */
3657 if (code == PREINCREMENT_EXPR)
3658 code = PREDECREMENT_EXPR;
3659 else if (code == PREDECREMENT_EXPR)
3660 code = PREINCREMENT_EXPR;
3661 else if (code == POSTINCREMENT_EXPR)
3662 code = POSTDECREMENT_EXPR;
3663 else /* code == POSTDECREMENT_EXPR */
3664 code = POSTINCREMENT_EXPR;
3666 inc = integer_minus_one_node;
3667 inc = convert (argtype, inc);
3671 inc = integer_one_node;
3672 inc = convert (argtype, inc);
3675 /* If 'arg' is an Objective-C PROPERTY_REF expression, then we
3676 need to ask Objective-C to build the increment or decrement
3677 expression for it. */
3678 if (objc_is_property_ref (arg))
3679 return objc_build_incr_expr_for_property_ref (location, code,
3682 /* Report a read-only lvalue. */
3683 if (TYPE_READONLY (argtype))
3685 readonly_error (arg,
3686 ((code == PREINCREMENT_EXPR
3687 || code == POSTINCREMENT_EXPR)
3688 ? lv_increment : lv_decrement));
3689 return error_mark_node;
3691 else if (TREE_READONLY (arg))
3692 readonly_warning (arg,
3693 ((code == PREINCREMENT_EXPR
3694 || code == POSTINCREMENT_EXPR)
3695 ? lv_increment : lv_decrement));
3697 if (TREE_CODE (TREE_TYPE (arg)) == BOOLEAN_TYPE)
3698 val = boolean_increment (code, arg);
3700 val = build2 (code, TREE_TYPE (arg), arg, inc);
3701 TREE_SIDE_EFFECTS (val) = 1;
3702 if (TREE_CODE (val) != code)
3703 TREE_NO_WARNING (val) = 1;
3705 goto return_build_unary_op;
3709 /* Note that this operation never does default_conversion. */
3711 /* The operand of unary '&' must be an lvalue (which excludes
3712 expressions of type void), or, in C99, the result of a [] or
3713 unary '*' operator. */
3714 if (VOID_TYPE_P (TREE_TYPE (arg))
3715 && TYPE_QUALS (TREE_TYPE (arg)) == TYPE_UNQUALIFIED
3716 && (TREE_CODE (arg) != INDIRECT_REF
3718 pedwarn (location, 0, "taking address of expression of type %<void%>");
3720 /* Let &* cancel out to simplify resulting code. */
3721 if (TREE_CODE (arg) == INDIRECT_REF)
3723 /* Don't let this be an lvalue. */
3724 if (lvalue_p (TREE_OPERAND (arg, 0)))
3725 return non_lvalue_loc (location, TREE_OPERAND (arg, 0));
3726 ret = TREE_OPERAND (arg, 0);
3727 goto return_build_unary_op;
3730 /* For &x[y], return x+y */
3731 if (TREE_CODE (arg) == ARRAY_REF)
3733 tree op0 = TREE_OPERAND (arg, 0);
3734 if (!c_mark_addressable (op0))
3735 return error_mark_node;
3738 /* Anything not already handled and not a true memory reference
3739 or a non-lvalue array is an error. */
3740 else if (typecode != FUNCTION_TYPE && !flag
3741 && !lvalue_or_else (location, arg, lv_addressof))
3742 return error_mark_node;
3744 /* Move address operations inside C_MAYBE_CONST_EXPR to simplify
3746 if (TREE_CODE (arg) == C_MAYBE_CONST_EXPR)
3748 tree inner = build_unary_op (location, code,
3749 C_MAYBE_CONST_EXPR_EXPR (arg), flag);
3750 ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (inner),
3751 C_MAYBE_CONST_EXPR_PRE (arg), inner);
3752 gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (arg));
3753 C_MAYBE_CONST_EXPR_NON_CONST (ret)
3754 = C_MAYBE_CONST_EXPR_NON_CONST (arg);
3755 goto return_build_unary_op;
3758 /* Ordinary case; arg is a COMPONENT_REF or a decl. */
3759 argtype = TREE_TYPE (arg);
3761 /* If the lvalue is const or volatile, merge that into the type
3762 to which the address will point. This is only needed
3763 for function types. */
3764 if ((DECL_P (arg) || REFERENCE_CLASS_P (arg))
3765 && (TREE_READONLY (arg) || TREE_THIS_VOLATILE (arg))
3766 && TREE_CODE (argtype) == FUNCTION_TYPE)
3768 int orig_quals = TYPE_QUALS (strip_array_types (argtype));
3769 int quals = orig_quals;
3771 if (TREE_READONLY (arg))
3772 quals |= TYPE_QUAL_CONST;
3773 if (TREE_THIS_VOLATILE (arg))
3774 quals |= TYPE_QUAL_VOLATILE;
3776 argtype = c_build_qualified_type (argtype, quals);
3779 if (!c_mark_addressable (arg))
3780 return error_mark_node;
3782 gcc_assert (TREE_CODE (arg) != COMPONENT_REF
3783 || !DECL_C_BIT_FIELD (TREE_OPERAND (arg, 1)));
3785 argtype = build_pointer_type (argtype);
3787 /* ??? Cope with user tricks that amount to offsetof. Delete this
3788 when we have proper support for integer constant expressions. */
3789 val = get_base_address (arg);
3790 if (val && TREE_CODE (val) == INDIRECT_REF
3791 && TREE_CONSTANT (TREE_OPERAND (val, 0)))
3793 tree op0 = fold_convert_loc (location, sizetype,
3794 fold_offsetof (arg, val)), op1;
3796 op1 = fold_convert_loc (location, argtype, TREE_OPERAND (val, 0));
3797 ret = fold_build2_loc (location, POINTER_PLUS_EXPR, argtype, op1, op0);
3798 goto return_build_unary_op;
3801 val = build1 (ADDR_EXPR, argtype, arg);
3804 goto return_build_unary_op;
3811 argtype = TREE_TYPE (arg);
3812 if (TREE_CODE (arg) == INTEGER_CST)
3813 ret = (require_constant_value
3814 ? fold_build1_initializer_loc (location, code, argtype, arg)
3815 : fold_build1_loc (location, code, argtype, arg));
3817 ret = build1 (code, argtype, arg);
3818 return_build_unary_op:
3819 gcc_assert (ret != error_mark_node);
3820 if (TREE_CODE (ret) == INTEGER_CST && !TREE_OVERFLOW (ret)
3821 && !(TREE_CODE (xarg) == INTEGER_CST && !TREE_OVERFLOW (xarg)))
3822 ret = build1 (NOP_EXPR, TREE_TYPE (ret), ret);
3823 else if (TREE_CODE (ret) != INTEGER_CST && int_operands)
3824 ret = note_integer_operands (ret);
3826 ret = build1 (EXCESS_PRECISION_EXPR, eptype, ret);
3827 protected_set_expr_location (ret, location);
3831 /* Return nonzero if REF is an lvalue valid for this language.
3832 Lvalues can be assigned, unless their type has TYPE_READONLY.
3833 Lvalues can have their address taken, unless they have C_DECL_REGISTER. */
3836 lvalue_p (const_tree ref)
3838 const enum tree_code code = TREE_CODE (ref);
3845 return lvalue_p (TREE_OPERAND (ref, 0));
3847 case C_MAYBE_CONST_EXPR:
3848 return lvalue_p (TREE_OPERAND (ref, 1));
3850 case COMPOUND_LITERAL_EXPR:
3860 return (TREE_CODE (TREE_TYPE (ref)) != FUNCTION_TYPE
3861 && TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE);
3864 return TREE_CODE (TREE_TYPE (ref)) == ARRAY_TYPE;
3871 /* Give a warning for storing in something that is read-only in GCC
3872 terms but not const in ISO C terms. */
3875 readonly_warning (tree arg, enum lvalue_use use)
3880 warning (0, "assignment of read-only location %qE", arg);
3883 warning (0, "increment of read-only location %qE", arg);
3886 warning (0, "decrement of read-only location %qE", arg);
3895 /* Return nonzero if REF is an lvalue valid for this language;
3896 otherwise, print an error message and return zero. USE says
3897 how the lvalue is being used and so selects the error message.
3898 LOCATION is the location at which any error should be reported. */
3901 lvalue_or_else (location_t loc, const_tree ref, enum lvalue_use use)
3903 int win = lvalue_p (ref);
3906 lvalue_error (loc, use);
3911 /* Mark EXP saying that we need to be able to take the
3912 address of it; it should not be allocated in a register.
3913 Returns true if successful. */
3916 c_mark_addressable (tree exp)
3921 switch (TREE_CODE (x))
3924 if (DECL_C_BIT_FIELD (TREE_OPERAND (x, 1)))
3927 ("cannot take address of bit-field %qD", TREE_OPERAND (x, 1));
3931 /* ... fall through ... */
3937 x = TREE_OPERAND (x, 0);
3940 case COMPOUND_LITERAL_EXPR:
3942 TREE_ADDRESSABLE (x) = 1;
3949 if (C_DECL_REGISTER (x)
3950 && DECL_NONLOCAL (x))
3952 if (TREE_PUBLIC (x) || TREE_STATIC (x) || DECL_EXTERNAL (x))
3955 ("global register variable %qD used in nested function", x);
3958 pedwarn (input_location, 0, "register variable %qD used in nested function", x);
3960 else if (C_DECL_REGISTER (x))
3962 if (TREE_PUBLIC (x) || TREE_STATIC (x) || DECL_EXTERNAL (x))
3963 error ("address of global register variable %qD requested", x);
3965 error ("address of register variable %qD requested", x);
3971 TREE_ADDRESSABLE (x) = 1;
3978 /* Convert EXPR to TYPE, warning about conversion problems with
3979 constants. SEMANTIC_TYPE is the type this conversion would use
3980 without excess precision. If SEMANTIC_TYPE is NULL, this function
3981 is equivalent to convert_and_check. This function is a wrapper that
3982 handles conversions that may be different than
3983 the usual ones because of excess precision. */
3986 ep_convert_and_check (tree type, tree expr, tree semantic_type)
3988 if (TREE_TYPE (expr) == type)
3992 return convert_and_check (type, expr);
3994 if (TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE
3995 && TREE_TYPE (expr) != semantic_type)
3997 /* For integers, we need to check the real conversion, not
3998 the conversion to the excess precision type. */
3999 expr = convert_and_check (semantic_type, expr);
4001 /* Result type is the excess precision type, which should be
4002 large enough, so do not check. */
4003 return convert (type, expr);
4006 /* Build and return a conditional expression IFEXP ? OP1 : OP2. If
4007 IFEXP_BCP then the condition is a call to __builtin_constant_p, and
4008 if folded to an integer constant then the unselected half may
4009 contain arbitrary operations not normally permitted in constant
4010 expressions. Set the location of the expression to LOC. */
4013 build_conditional_expr (location_t colon_loc, tree ifexp, bool ifexp_bcp,
4014 tree op1, tree op1_original_type, tree op2,
4015 tree op2_original_type)
4019 enum tree_code code1;
4020 enum tree_code code2;
4021 tree result_type = NULL;
4022 tree semantic_result_type = NULL;
4023 tree orig_op1 = op1, orig_op2 = op2;
4024 bool int_const, op1_int_operands, op2_int_operands, int_operands;
4025 bool ifexp_int_operands;
4028 op1_int_operands = EXPR_INT_CONST_OPERANDS (orig_op1);
4029 if (op1_int_operands)
4030 op1 = remove_c_maybe_const_expr (op1);
4031 op2_int_operands = EXPR_INT_CONST_OPERANDS (orig_op2);
4032 if (op2_int_operands)
4033 op2 = remove_c_maybe_const_expr (op2);
4034 ifexp_int_operands = EXPR_INT_CONST_OPERANDS (ifexp);
4035 if (ifexp_int_operands)
4036 ifexp = remove_c_maybe_const_expr (ifexp);
4038 /* Promote both alternatives. */
4040 if (TREE_CODE (TREE_TYPE (op1)) != VOID_TYPE)
4041 op1 = default_conversion (op1);
4042 if (TREE_CODE (TREE_TYPE (op2)) != VOID_TYPE)
4043 op2 = default_conversion (op2);
4045 if (TREE_CODE (ifexp) == ERROR_MARK
4046 || TREE_CODE (TREE_TYPE (op1)) == ERROR_MARK
4047 || TREE_CODE (TREE_TYPE (op2)) == ERROR_MARK)
4048 return error_mark_node;
4050 type1 = TREE_TYPE (op1);
4051 code1 = TREE_CODE (type1);
4052 type2 = TREE_TYPE (op2);
4053 code2 = TREE_CODE (type2);
4055 /* C90 does not permit non-lvalue arrays in conditional expressions.
4056 In C99 they will be pointers by now. */
4057 if (code1 == ARRAY_TYPE || code2 == ARRAY_TYPE)
4059 error_at (colon_loc, "non-lvalue array in conditional expression");
4060 return error_mark_node;
4063 if ((TREE_CODE (op1) == EXCESS_PRECISION_EXPR
4064 || TREE_CODE (op2) == EXCESS_PRECISION_EXPR)
4065 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
4066 || code1 == COMPLEX_TYPE)
4067 && (code2 == INTEGER_TYPE || code2 == REAL_TYPE
4068 || code2 == COMPLEX_TYPE))
4070 semantic_result_type = c_common_type (type1, type2);
4071 if (TREE_CODE (op1) == EXCESS_PRECISION_EXPR)
4073 op1 = TREE_OPERAND (op1, 0);
4074 type1 = TREE_TYPE (op1);
4075 gcc_assert (TREE_CODE (type1) == code1);
4077 if (TREE_CODE (op2) == EXCESS_PRECISION_EXPR)
4079 op2 = TREE_OPERAND (op2, 0);
4080 type2 = TREE_TYPE (op2);
4081 gcc_assert (TREE_CODE (type2) == code2);
4085 if (warn_cxx_compat)
4087 tree t1 = op1_original_type ? op1_original_type : TREE_TYPE (orig_op1);
4088 tree t2 = op2_original_type ? op2_original_type : TREE_TYPE (orig_op2);
4090 if (TREE_CODE (t1) == ENUMERAL_TYPE
4091 && TREE_CODE (t2) == ENUMERAL_TYPE
4092 && TYPE_MAIN_VARIANT (t1) != TYPE_MAIN_VARIANT (t2))
4093 warning_at (colon_loc, OPT_Wc___compat,
4094 ("different enum types in conditional is "
4095 "invalid in C++: %qT vs %qT"),
4099 /* Quickly detect the usual case where op1 and op2 have the same type
4101 if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2))
4104 result_type = type1;
4106 result_type = TYPE_MAIN_VARIANT (type1);
4108 else if ((code1 == INTEGER_TYPE || code1 == REAL_TYPE
4109 || code1 == COMPLEX_TYPE)
4110 && (code2 == INTEGER_TYPE || code2 == REAL_TYPE
4111 || code2 == COMPLEX_TYPE))
4113 result_type = c_common_type (type1, type2);
4114 do_warn_double_promotion (result_type, type1, type2,
4115 "implicit conversion from %qT to %qT to "
4116 "match other result of conditional",
4119 /* If -Wsign-compare, warn here if type1 and type2 have
4120 different signedness. We'll promote the signed to unsigned
4121 and later code won't know it used to be different.
4122 Do this check on the original types, so that explicit casts
4123 will be considered, but default promotions won't. */
4124 if (c_inhibit_evaluation_warnings == 0)
4126 int unsigned_op1 = TYPE_UNSIGNED (TREE_TYPE (orig_op1));
4127 int unsigned_op2 = TYPE_UNSIGNED (TREE_TYPE (orig_op2));
4129 if (unsigned_op1 ^ unsigned_op2)
4133 /* Do not warn if the result type is signed, since the
4134 signed type will only be chosen if it can represent
4135 all the values of the unsigned type. */
4136 if (!TYPE_UNSIGNED (result_type))
4140 bool op1_maybe_const = true;
4141 bool op2_maybe_const = true;
4143 /* Do not warn if the signed quantity is an
4144 unsuffixed integer literal (or some static
4145 constant expression involving such literals) and
4146 it is non-negative. This warning requires the
4147 operands to be folded for best results, so do
4148 that folding in this case even without
4149 warn_sign_compare to avoid warning options
4150 possibly affecting code generation. */
4151 c_inhibit_evaluation_warnings
4152 += (ifexp == truthvalue_false_node);
4153 op1 = c_fully_fold (op1, require_constant_value,
4155 c_inhibit_evaluation_warnings
4156 -= (ifexp == truthvalue_false_node);
4158 c_inhibit_evaluation_warnings
4159 += (ifexp == truthvalue_true_node);
4160 op2 = c_fully_fold (op2, require_constant_value,
4162 c_inhibit_evaluation_warnings
4163 -= (ifexp == truthvalue_true_node);
4165 if (warn_sign_compare)
4168 && tree_expr_nonnegative_warnv_p (op1, &ovf))
4170 && tree_expr_nonnegative_warnv_p (op2, &ovf)))
4173 warning_at (colon_loc, OPT_Wsign_compare,
4174 ("signed and unsigned type in "
4175 "conditional expression"));
4177 if (!op1_maybe_const || TREE_CODE (op1) != INTEGER_CST)
4178 op1 = c_wrap_maybe_const (op1, !op1_maybe_const);
4179 if (!op2_maybe_const || TREE_CODE (op2) != INTEGER_CST)
4180 op2 = c_wrap_maybe_const (op2, !op2_maybe_const);
4185 else if (code1 == VOID_TYPE || code2 == VOID_TYPE)
4187 if (code1 != VOID_TYPE || code2 != VOID_TYPE)
4188 pedwarn (colon_loc, OPT_pedantic,
4189 "ISO C forbids conditional expr with only one void side");
4190 result_type = void_type_node;
4192 else if (code1 == POINTER_TYPE && code2 == POINTER_TYPE)
4194 addr_space_t as1 = TYPE_ADDR_SPACE (TREE_TYPE (type1));
4195 addr_space_t as2 = TYPE_ADDR_SPACE (TREE_TYPE (type2));
4196 addr_space_t as_common;
4198 if (comp_target_types (colon_loc, type1, type2))
4199 result_type = common_pointer_type (type1, type2);
4200 else if (null_pointer_constant_p (orig_op1))
4201 result_type = type2;
4202 else if (null_pointer_constant_p (orig_op2))
4203 result_type = type1;
4204 else if (!addr_space_superset (as1, as2, &as_common))
4206 error_at (colon_loc, "pointers to disjoint address spaces "
4207 "used in conditional expression");
4208 return error_mark_node;
4210 else if (VOID_TYPE_P (TREE_TYPE (type1)))
4212 if (TREE_CODE (TREE_TYPE (type2)) == FUNCTION_TYPE)
4213 pedwarn (colon_loc, OPT_pedantic,
4214 "ISO C forbids conditional expr between "
4215 "%<void *%> and function pointer");
4216 result_type = build_pointer_type (qualify_type (TREE_TYPE (type1),
4217 TREE_TYPE (type2)));
4219 else if (VOID_TYPE_P (TREE_TYPE (type2)))
4221 if (TREE_CODE (TREE_TYPE (type1)) == FUNCTION_TYPE)
4222 pedwarn (colon_loc, OPT_pedantic,
4223 "ISO C forbids conditional expr between "
4224 "%<void *%> and function pointer");
4225 result_type = build_pointer_type (qualify_type (TREE_TYPE (type2),
4226 TREE_TYPE (type1)));
4228 /* Objective-C pointer comparisons are a bit more lenient. */
4229 else if (objc_have_common_type (type1, type2, -3, NULL_TREE))
4230 result_type = objc_common_type (type1, type2);
4233 int qual = ENCODE_QUAL_ADDR_SPACE (as_common);
4235 pedwarn (colon_loc, 0,
4236 "pointer type mismatch in conditional expression");
4237 result_type = build_pointer_type
4238 (build_qualified_type (void_type_node, qual));
4241 else if (code1 == POINTER_TYPE && code2 == INTEGER_TYPE)
4243 if (!null_pointer_constant_p (orig_op2))
4244 pedwarn (colon_loc, 0,
4245 "pointer/integer type mismatch in conditional expression");
4248 op2 = null_pointer_node;
4250 result_type = type1;
4252 else if (code2 == POINTER_TYPE && code1 == INTEGER_TYPE)
4254 if (!null_pointer_constant_p (orig_op1))
4255 pedwarn (colon_loc, 0,
4256 "pointer/integer type mismatch in conditional expression");
4259 op1 = null_pointer_node;
4261 result_type = type2;
4266 if (flag_cond_mismatch)
4267 result_type = void_type_node;
4270 error_at (colon_loc, "type mismatch in conditional expression");
4271 return error_mark_node;
4275 /* Merge const and volatile flags of the incoming types. */
4277 = build_type_variant (result_type,
4278 TYPE_READONLY (type1) || TYPE_READONLY (type2),
4279 TYPE_VOLATILE (type1) || TYPE_VOLATILE (type2));
4281 op1 = ep_convert_and_check (result_type, op1, semantic_result_type);
4282 op2 = ep_convert_and_check (result_type, op2, semantic_result_type);
4284 if (ifexp_bcp && ifexp == truthvalue_true_node)
4286 op2_int_operands = true;
4287 op1 = c_fully_fold (op1, require_constant_value, NULL);
4289 if (ifexp_bcp && ifexp == truthvalue_false_node)
4291 op1_int_operands = true;
4292 op2 = c_fully_fold (op2, require_constant_value, NULL);
4294 int_const = int_operands = (ifexp_int_operands
4296 && op2_int_operands);
4299 int_const = ((ifexp == truthvalue_true_node
4300 && TREE_CODE (orig_op1) == INTEGER_CST
4301 && !TREE_OVERFLOW (orig_op1))
4302 || (ifexp == truthvalue_false_node
4303 && TREE_CODE (orig_op2) == INTEGER_CST
4304 && !TREE_OVERFLOW (orig_op2)));
4306 if (int_const || (ifexp_bcp && TREE_CODE (ifexp) == INTEGER_CST))
4307 ret = fold_build3_loc (colon_loc, COND_EXPR, result_type, ifexp, op1, op2);
4310 ret = build3 (COND_EXPR, result_type, ifexp, op1, op2);
4312 ret = note_integer_operands (ret);
4314 if (semantic_result_type)
4315 ret = build1 (EXCESS_PRECISION_EXPR, semantic_result_type, ret);
4317 protected_set_expr_location (ret, colon_loc);
4321 /* Return a compound expression that performs two expressions and
4322 returns the value of the second of them.
4324 LOC is the location of the COMPOUND_EXPR. */
4327 build_compound_expr (location_t loc, tree expr1, tree expr2)
4329 bool expr1_int_operands, expr2_int_operands;
4330 tree eptype = NULL_TREE;
4333 expr1_int_operands = EXPR_INT_CONST_OPERANDS (expr1);
4334 if (expr1_int_operands)
4335 expr1 = remove_c_maybe_const_expr (expr1);
4336 expr2_int_operands = EXPR_INT_CONST_OPERANDS (expr2);
4337 if (expr2_int_operands)
4338 expr2 = remove_c_maybe_const_expr (expr2);
4340 if (TREE_CODE (expr1) == EXCESS_PRECISION_EXPR)
4341 expr1 = TREE_OPERAND (expr1, 0);
4342 if (TREE_CODE (expr2) == EXCESS_PRECISION_EXPR)
4344 eptype = TREE_TYPE (expr2);
4345 expr2 = TREE_OPERAND (expr2, 0);
4348 if (!TREE_SIDE_EFFECTS (expr1))
4350 /* The left-hand operand of a comma expression is like an expression
4351 statement: with -Wunused, we should warn if it doesn't have
4352 any side-effects, unless it was explicitly cast to (void). */
4353 if (warn_unused_value)
4355 if (VOID_TYPE_P (TREE_TYPE (expr1))
4356 && CONVERT_EXPR_P (expr1))
4358 else if (VOID_TYPE_P (TREE_TYPE (expr1))
4359 && TREE_CODE (expr1) == COMPOUND_EXPR
4360 && CONVERT_EXPR_P (TREE_OPERAND (expr1, 1)))
4361 ; /* (void) a, (void) b, c */
4363 warning_at (loc, OPT_Wunused_value,
4364 "left-hand operand of comma expression has no effect");
4368 /* With -Wunused, we should also warn if the left-hand operand does have
4369 side-effects, but computes a value which is not used. For example, in
4370 `foo() + bar(), baz()' the result of the `+' operator is not used,
4371 so we should issue a warning. */
4372 else if (warn_unused_value)
4373 warn_if_unused_value (expr1, loc);
4375 if (expr2 == error_mark_node)
4376 return error_mark_node;
4378 ret = build2 (COMPOUND_EXPR, TREE_TYPE (expr2), expr1, expr2);
4381 && expr1_int_operands
4382 && expr2_int_operands)
4383 ret = note_integer_operands (ret);
4386 ret = build1 (EXCESS_PRECISION_EXPR, eptype, ret);
4388 protected_set_expr_location (ret, loc);
4392 /* Issue -Wcast-qual warnings when appropriate. TYPE is the type to
4393 which we are casting. OTYPE is the type of the expression being
4394 cast. Both TYPE and OTYPE are pointer types. LOC is the location
4395 of the cast. -Wcast-qual appeared on the command line. Named
4396 address space qualifiers are not handled here, because they result
4397 in different warnings. */
4400 handle_warn_cast_qual (location_t loc, tree type, tree otype)
4402 tree in_type = type;
4403 tree in_otype = otype;
4408 /* Check that the qualifiers on IN_TYPE are a superset of the
4409 qualifiers of IN_OTYPE. The outermost level of POINTER_TYPE
4410 nodes is uninteresting and we stop as soon as we hit a
4411 non-POINTER_TYPE node on either type. */
4414 in_otype = TREE_TYPE (in_otype);
4415 in_type = TREE_TYPE (in_type);
4417 /* GNU C allows cv-qualified function types. 'const' means the
4418 function is very pure, 'volatile' means it can't return. We
4419 need to warn when such qualifiers are added, not when they're
4421 if (TREE_CODE (in_otype) == FUNCTION_TYPE
4422 && TREE_CODE (in_type) == FUNCTION_TYPE)
4423 added |= (TYPE_QUALS_NO_ADDR_SPACE (in_type)
4424 & ~TYPE_QUALS_NO_ADDR_SPACE (in_otype));
4426 discarded |= (TYPE_QUALS_NO_ADDR_SPACE (in_otype)
4427 & ~TYPE_QUALS_NO_ADDR_SPACE (in_type));
4429 while (TREE_CODE (in_type) == POINTER_TYPE
4430 && TREE_CODE (in_otype) == POINTER_TYPE);
4433 warning_at (loc, OPT_Wcast_qual,
4434 "cast adds %q#v qualifier to function type", added);
4437 /* There are qualifiers present in IN_OTYPE that are not present
4439 warning_at (loc, OPT_Wcast_qual,
4440 "cast discards %q#v qualifier from pointer target type",
4443 if (added || discarded)
4446 /* A cast from **T to const **T is unsafe, because it can cause a
4447 const value to be changed with no additional warning. We only
4448 issue this warning if T is the same on both sides, and we only
4449 issue the warning if there are the same number of pointers on
4450 both sides, as otherwise the cast is clearly unsafe anyhow. A
4451 cast is unsafe when a qualifier is added at one level and const
4452 is not present at all outer levels.
4454 To issue this warning, we check at each level whether the cast
4455 adds new qualifiers not already seen. We don't need to special
4456 case function types, as they won't have the same
4457 TYPE_MAIN_VARIANT. */
4459 if (TYPE_MAIN_VARIANT (in_type) != TYPE_MAIN_VARIANT (in_otype))
4461 if (TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE)
4466 is_const = TYPE_READONLY (TREE_TYPE (in_type));
4469 in_type = TREE_TYPE (in_type);
4470 in_otype = TREE_TYPE (in_otype);
4471 if ((TYPE_QUALS (in_type) &~ TYPE_QUALS (in_otype)) != 0
4474 warning_at (loc, OPT_Wcast_qual,
4475 "to be safe all intermediate pointers in cast from "
4476 "%qT to %qT must be %<const%> qualified",
4481 is_const = TYPE_READONLY (in_type);
4483 while (TREE_CODE (in_type) == POINTER_TYPE);
4486 /* Build an expression representing a cast to type TYPE of expression EXPR.
4487 LOC is the location of the cast-- typically the open paren of the cast. */
4490 build_c_cast (location_t loc, tree type, tree expr)
4494 if (TREE_CODE (expr) == EXCESS_PRECISION_EXPR)
4495 expr = TREE_OPERAND (expr, 0);
4499 if (type == error_mark_node || expr == error_mark_node)
4500 return error_mark_node;
4502 /* The ObjC front-end uses TYPE_MAIN_VARIANT to tie together types differing
4503 only in <protocol> qualifications. But when constructing cast expressions,
4504 the protocols do matter and must be kept around. */
4505 if (objc_is_object_ptr (type) && objc_is_object_ptr (TREE_TYPE (expr)))
4506 return build1 (NOP_EXPR, type, expr);
4508 type = TYPE_MAIN_VARIANT (type);
4510 if (TREE_CODE (type) == ARRAY_TYPE)
4512 error_at (loc, "cast specifies array type");
4513 return error_mark_node;
4516 if (TREE_CODE (type) == FUNCTION_TYPE)
4518 error_at (loc, "cast specifies function type");
4519 return error_mark_node;
4522 if (!VOID_TYPE_P (type))
4524 value = require_complete_type (value);
4525 if (value == error_mark_node)
4526 return error_mark_node;
4529 if (type == TYPE_MAIN_VARIANT (TREE_TYPE (value)))
4531 if (TREE_CODE (type) == RECORD_TYPE
4532 || TREE_CODE (type) == UNION_TYPE)
4533 pedwarn (loc, OPT_pedantic,
4534 "ISO C forbids casting nonscalar to the same type");
4536 else if (TREE_CODE (type) == UNION_TYPE)
4540 for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
4541 if (TREE_TYPE (field) != error_mark_node
4542 && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (field)),
4543 TYPE_MAIN_VARIANT (TREE_TYPE (value))))
4549 bool maybe_const = true;
4551 pedwarn (loc, OPT_pedantic, "ISO C forbids casts to union type");
4552 t = c_fully_fold (value, false, &maybe_const);
4553 t = build_constructor_single (type, field, t);
4555 t = c_wrap_maybe_const (t, true);
4556 t = digest_init (loc, type, t,
4557 NULL_TREE, false, true, 0);
4558 TREE_CONSTANT (t) = TREE_CONSTANT (value);
4561 error_at (loc, "cast to union type from type not present in union");
4562 return error_mark_node;
4568 if (type == void_type_node)
4570 tree t = build1 (CONVERT_EXPR, type, value);
4571 SET_EXPR_LOCATION (t, loc);
4575 otype = TREE_TYPE (value);
4577 /* Optionally warn about potentially worrisome casts. */
4579 && TREE_CODE (type) == POINTER_TYPE
4580 && TREE_CODE (otype) == POINTER_TYPE)
4581 handle_warn_cast_qual (loc, type, otype);
4583 /* Warn about conversions between pointers to disjoint
4585 if (TREE_CODE (type) == POINTER_TYPE
4586 && TREE_CODE (otype) == POINTER_TYPE
4587 && !null_pointer_constant_p (value))
4589 addr_space_t as_to = TYPE_ADDR_SPACE (TREE_TYPE (type));
4590 addr_space_t as_from = TYPE_ADDR_SPACE (TREE_TYPE (otype));
4591 addr_space_t as_common;
4593 if (!addr_space_superset (as_to, as_from, &as_common))
4595 if (ADDR_SPACE_GENERIC_P (as_from))
4596 warning_at (loc, 0, "cast to %s address space pointer "
4597 "from disjoint generic address space pointer",
4598 c_addr_space_name (as_to));
4600 else if (ADDR_SPACE_GENERIC_P (as_to))
4601 warning_at (loc, 0, "cast to generic address space pointer "
4602 "from disjoint %s address space pointer",
4603 c_addr_space_name (as_from));
4606 warning_at (loc, 0, "cast to %s address space pointer "
4607 "from disjoint %s address space pointer",
4608 c_addr_space_name (as_to),
4609 c_addr_space_name (as_from));
4613 /* Warn about possible alignment problems. */
4614 if (STRICT_ALIGNMENT
4615 && TREE_CODE (type) == POINTER_TYPE
4616 && TREE_CODE (otype) == POINTER_TYPE
4617 && TREE_CODE (TREE_TYPE (otype)) != VOID_TYPE
4618 && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
4619 /* Don't warn about opaque types, where the actual alignment
4620 restriction is unknown. */
4621 && !((TREE_CODE (TREE_TYPE (otype)) == UNION_TYPE
4622 || TREE_CODE (TREE_TYPE (otype)) == RECORD_TYPE)
4623 && TYPE_MODE (TREE_TYPE (otype)) == VOIDmode)
4624 && TYPE_ALIGN (TREE_TYPE (type)) > TYPE_ALIGN (TREE_TYPE (otype)))
4625 warning_at (loc, OPT_Wcast_align,
4626 "cast increases required alignment of target type");
4628 if (TREE_CODE (type) == INTEGER_TYPE
4629 && TREE_CODE (otype) == POINTER_TYPE
4630 && TYPE_PRECISION (type) != TYPE_PRECISION (otype))
4631 /* Unlike conversion of integers to pointers, where the
4632 warning is disabled for converting constants because
4633 of cases such as SIG_*, warn about converting constant
4634 pointers to integers. In some cases it may cause unwanted
4635 sign extension, and a warning is appropriate. */
4636 warning_at (loc, OPT_Wpointer_to_int_cast,
4637 "cast from pointer to integer of different size");
4639 if (TREE_CODE (value) == CALL_EXPR
4640 && TREE_CODE (type) != TREE_CODE (otype))
4641 warning_at (loc, OPT_Wbad_function_cast,
4642 "cast from function call of type %qT "
4643 "to non-matching type %qT", otype, type);
4645 if (TREE_CODE (type) == POINTER_TYPE
4646 && TREE_CODE (otype) == INTEGER_TYPE
4647 && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
4648 /* Don't warn about converting any constant. */
4649 && !TREE_CONSTANT (value))
4651 OPT_Wint_to_pointer_cast, "cast to pointer from integer "
4652 "of different size");
4654 if (warn_strict_aliasing <= 2)
4655 strict_aliasing_warning (otype, type, expr);
4657 /* If pedantic, warn for conversions between function and object
4658 pointer types, except for converting a null pointer constant
4659 to function pointer type. */
4661 && TREE_CODE (type) == POINTER_TYPE
4662 && TREE_CODE (otype) == POINTER_TYPE
4663 && TREE_CODE (TREE_TYPE (otype)) == FUNCTION_TYPE
4664 && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE)
4665 pedwarn (loc, OPT_pedantic, "ISO C forbids "
4666 "conversion of function pointer to object pointer type");
4669 && TREE_CODE (type) == POINTER_TYPE
4670 && TREE_CODE (otype) == POINTER_TYPE
4671 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
4672 && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
4673 && !null_pointer_constant_p (value))
4674 pedwarn (loc, OPT_pedantic, "ISO C forbids "
4675 "conversion of object pointer to function pointer type");
4678 value = convert (type, value);
4680 /* Ignore any integer overflow caused by the cast. */
4681 if (TREE_CODE (value) == INTEGER_CST && !FLOAT_TYPE_P (otype))
4683 if (CONSTANT_CLASS_P (ovalue) && TREE_OVERFLOW (ovalue))
4685 if (!TREE_OVERFLOW (value))
4687 /* Avoid clobbering a shared constant. */
4688 value = copy_node (value);
4689 TREE_OVERFLOW (value) = TREE_OVERFLOW (ovalue);
4692 else if (TREE_OVERFLOW (value))
4693 /* Reset VALUE's overflow flags, ensuring constant sharing. */
4694 value = build_int_cst_wide (TREE_TYPE (value),
4695 TREE_INT_CST_LOW (value),
4696 TREE_INT_CST_HIGH (value));
4700 /* Don't let a cast be an lvalue. */
4702 value = non_lvalue_loc (loc, value);
4704 /* Don't allow the results of casting to floating-point or complex
4705 types be confused with actual constants, or casts involving
4706 integer and pointer types other than direct integer-to-integer
4707 and integer-to-pointer be confused with integer constant
4708 expressions and null pointer constants. */
4709 if (TREE_CODE (value) == REAL_CST
4710 || TREE_CODE (value) == COMPLEX_CST
4711 || (TREE_CODE (value) == INTEGER_CST
4712 && !((TREE_CODE (expr) == INTEGER_CST
4713 && INTEGRAL_TYPE_P (TREE_TYPE (expr)))
4714 || TREE_CODE (expr) == REAL_CST
4715 || TREE_CODE (expr) == COMPLEX_CST)))
4716 value = build1 (NOP_EXPR, type, value);
4718 if (CAN_HAVE_LOCATION_P (value))
4719 SET_EXPR_LOCATION (value, loc);
4723 /* Interpret a cast of expression EXPR to type TYPE. LOC is the
4724 location of the open paren of the cast, or the position of the cast
4727 c_cast_expr (location_t loc, struct c_type_name *type_name, tree expr)
4730 tree type_expr = NULL_TREE;
4731 bool type_expr_const = true;
4733 int saved_wsp = warn_strict_prototypes;
4735 /* This avoids warnings about unprototyped casts on
4736 integers. E.g. "#define SIG_DFL (void(*)())0". */
4737 if (TREE_CODE (expr) == INTEGER_CST)
4738 warn_strict_prototypes = 0;
4739 type = groktypename (type_name, &type_expr, &type_expr_const);
4740 warn_strict_prototypes = saved_wsp;
4742 ret = build_c_cast (loc, type, expr);
4745 ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret), type_expr, ret);
4746 C_MAYBE_CONST_EXPR_NON_CONST (ret) = !type_expr_const;
4747 SET_EXPR_LOCATION (ret, loc);
4750 if (CAN_HAVE_LOCATION_P (ret) && !EXPR_HAS_LOCATION (ret))
4751 SET_EXPR_LOCATION (ret, loc);
4753 /* C++ does not permits types to be defined in a cast, but it
4754 allows references to incomplete types. */
4755 if (warn_cxx_compat && type_name->specs->typespec_kind == ctsk_tagdef)
4756 warning_at (loc, OPT_Wc___compat,
4757 "defining a type in a cast is invalid in C++");
4762 /* Build an assignment expression of lvalue LHS from value RHS.
4763 If LHS_ORIGTYPE is not NULL, it is the original type of LHS, which
4764 may differ from TREE_TYPE (LHS) for an enum bitfield.
4765 MODIFYCODE is the code for a binary operator that we use
4766 to combine the old value of LHS with RHS to get the new value.
4767 Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.
4768 If RHS_ORIGTYPE is not NULL_TREE, it is the original type of RHS,
4769 which may differ from TREE_TYPE (RHS) for an enum value.
4771 LOCATION is the location of the MODIFYCODE operator.
4772 RHS_LOC is the location of the RHS. */
4775 build_modify_expr (location_t location, tree lhs, tree lhs_origtype,
4776 enum tree_code modifycode,
4777 location_t rhs_loc, tree rhs, tree rhs_origtype)
4781 tree rhs_semantic_type = NULL_TREE;
4782 tree lhstype = TREE_TYPE (lhs);
4783 tree olhstype = lhstype;
4786 /* Types that aren't fully specified cannot be used in assignments. */
4787 lhs = require_complete_type (lhs);
4789 /* Avoid duplicate error messages from operands that had errors. */
4790 if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK)
4791 return error_mark_node;
4793 /* For ObjC properties, defer this check. */
4794 if (!objc_is_property_ref (lhs) && !lvalue_or_else (location, lhs, lv_assign))
4795 return error_mark_node;
4797 if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
4799 rhs_semantic_type = TREE_TYPE (rhs);
4800 rhs = TREE_OPERAND (rhs, 0);
4805 if (TREE_CODE (lhs) == C_MAYBE_CONST_EXPR)
4807 tree inner = build_modify_expr (location, C_MAYBE_CONST_EXPR_EXPR (lhs),
4808 lhs_origtype, modifycode, rhs_loc, rhs,
4810 if (inner == error_mark_node)
4811 return error_mark_node;
4812 result = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (inner),
4813 C_MAYBE_CONST_EXPR_PRE (lhs), inner);
4814 gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (lhs));
4815 C_MAYBE_CONST_EXPR_NON_CONST (result) = 1;
4816 protected_set_expr_location (result, location);
4820 /* If a binary op has been requested, combine the old LHS value with the RHS
4821 producing the value we should actually store into the LHS. */
4823 if (modifycode != NOP_EXPR)
4825 lhs = c_fully_fold (lhs, false, NULL);
4826 lhs = stabilize_reference (lhs);
4827 newrhs = build_binary_op (location,
4828 modifycode, lhs, rhs, 1);
4830 /* The original type of the right hand side is no longer
4832 rhs_origtype = NULL_TREE;
4835 if (c_dialect_objc ())
4837 /* Check if we are modifying an Objective-C property reference;
4838 if so, we need to generate setter calls. */
4839 result = objc_maybe_build_modify_expr (lhs, newrhs);
4843 /* Else, do the check that we postponed for Objective-C. */
4844 if (!lvalue_or_else (location, lhs, lv_assign))
4845 return error_mark_node;
4848 /* Give an error for storing in something that is 'const'. */
4850 if (TYPE_READONLY (lhstype)
4851 || ((TREE_CODE (lhstype) == RECORD_TYPE
4852 || TREE_CODE (lhstype) == UNION_TYPE)
4853 && C_TYPE_FIELDS_READONLY (lhstype)))
4855 readonly_error (lhs, lv_assign);
4856 return error_mark_node;
4858 else if (TREE_READONLY (lhs))
4859 readonly_warning (lhs, lv_assign);
4861 /* If storing into a structure or union member,
4862 it has probably been given type `int'.
4863 Compute the type that would go with
4864 the actual amount of storage the member occupies. */
4866 if (TREE_CODE (lhs) == COMPONENT_REF
4867 && (TREE_CODE (lhstype) == INTEGER_TYPE
4868 || TREE_CODE (lhstype) == BOOLEAN_TYPE
4869 || TREE_CODE (lhstype) == REAL_TYPE
4870 || TREE_CODE (lhstype) == ENUMERAL_TYPE))
4871 lhstype = TREE_TYPE (get_unwidened (lhs, 0));
4873 /* If storing in a field that is in actuality a short or narrower than one,
4874 we must store in the field in its actual type. */
4876 if (lhstype != TREE_TYPE (lhs))
4878 lhs = copy_node (lhs);
4879 TREE_TYPE (lhs) = lhstype;
4882 /* Issue -Wc++-compat warnings about an assignment to an enum type
4883 when LHS does not have its original type. This happens for,
4884 e.g., an enum bitfield in a struct. */
4886 && lhs_origtype != NULL_TREE
4887 && lhs_origtype != lhstype
4888 && TREE_CODE (lhs_origtype) == ENUMERAL_TYPE)
4890 tree checktype = (rhs_origtype != NULL_TREE
4893 if (checktype != error_mark_node
4894 && TYPE_MAIN_VARIANT (checktype) != TYPE_MAIN_VARIANT (lhs_origtype))
4895 warning_at (location, OPT_Wc___compat,
4896 "enum conversion in assignment is invalid in C++");
4899 /* Convert new value to destination type. Fold it first, then
4900 restore any excess precision information, for the sake of
4901 conversion warnings. */
4903 npc = null_pointer_constant_p (newrhs);
4904 newrhs = c_fully_fold (newrhs, false, NULL);
4905 if (rhs_semantic_type)
4906 newrhs = build1 (EXCESS_PRECISION_EXPR, rhs_semantic_type, newrhs);
4907 newrhs = convert_for_assignment (location, lhstype, newrhs, rhs_origtype,
4908 ic_assign, npc, NULL_TREE, NULL_TREE, 0);
4909 if (TREE_CODE (newrhs) == ERROR_MARK)
4910 return error_mark_node;
4912 /* Emit ObjC write barrier, if necessary. */
4913 if (c_dialect_objc () && flag_objc_gc)
4915 result = objc_generate_write_barrier (lhs, modifycode, newrhs);
4918 protected_set_expr_location (result, location);
4923 /* Scan operands. */
4925 result = build2 (MODIFY_EXPR, lhstype, lhs, newrhs);
4926 TREE_SIDE_EFFECTS (result) = 1;
4927 protected_set_expr_location (result, location);
4929 /* If we got the LHS in a different type for storing in,
4930 convert the result back to the nominal type of LHS
4931 so that the value we return always has the same type
4932 as the LHS argument. */
4934 if (olhstype == TREE_TYPE (result))
4937 result = convert_for_assignment (location, olhstype, result, rhs_origtype,
4938 ic_assign, false, NULL_TREE, NULL_TREE, 0);
4939 protected_set_expr_location (result, location);
4943 /* Return whether STRUCT_TYPE has an anonymous field with type TYPE.
4944 This is used to implement -fplan9-extensions. */
4947 find_anonymous_field_with_type (tree struct_type, tree type)
4952 gcc_assert (TREE_CODE (struct_type) == RECORD_TYPE
4953 || TREE_CODE (struct_type) == UNION_TYPE);
4955 for (field = TYPE_FIELDS (struct_type);
4957 field = TREE_CHAIN (field))
4959 if (DECL_NAME (field) == NULL
4960 && comptypes (type, TYPE_MAIN_VARIANT (TREE_TYPE (field))))
4966 else if (DECL_NAME (field) == NULL
4967 && (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE
4968 || TREE_CODE (TREE_TYPE (field)) == UNION_TYPE)
4969 && find_anonymous_field_with_type (TREE_TYPE (field), type))
4979 /* RHS is an expression whose type is pointer to struct. If there is
4980 an anonymous field in RHS with type TYPE, then return a pointer to
4981 that field in RHS. This is used with -fplan9-extensions. This
4982 returns NULL if no conversion could be found. */
4985 convert_to_anonymous_field (location_t location, tree type, tree rhs)
4987 tree rhs_struct_type, lhs_main_type;
4988 tree field, found_field;
4989 bool found_sub_field;
4992 gcc_assert (POINTER_TYPE_P (TREE_TYPE (rhs)));
4993 rhs_struct_type = TREE_TYPE (TREE_TYPE (rhs));
4994 gcc_assert (TREE_CODE (rhs_struct_type) == RECORD_TYPE
4995 || TREE_CODE (rhs_struct_type) == UNION_TYPE);
4997 gcc_assert (POINTER_TYPE_P (type));
4998 lhs_main_type = TYPE_MAIN_VARIANT (TREE_TYPE (type));
5000 found_field = NULL_TREE;
5001 found_sub_field = false;
5002 for (field = TYPE_FIELDS (rhs_struct_type);
5004 field = TREE_CHAIN (field))
5006 if (DECL_NAME (field) != NULL_TREE
5007 || (TREE_CODE (TREE_TYPE (field)) != RECORD_TYPE
5008 && TREE_CODE (TREE_TYPE (field)) != UNION_TYPE))
5010 if (comptypes (lhs_main_type, TYPE_MAIN_VARIANT (TREE_TYPE (field))))
5012 if (found_field != NULL_TREE)
5014 found_field = field;
5016 else if (find_anonymous_field_with_type (TREE_TYPE (field),
5019 if (found_field != NULL_TREE)
5021 found_field = field;
5022 found_sub_field = true;
5026 if (found_field == NULL_TREE)
5029 ret = fold_build3_loc (location, COMPONENT_REF, TREE_TYPE (found_field),
5030 build_fold_indirect_ref (rhs), found_field,
5032 ret = build_fold_addr_expr_loc (location, ret);
5034 if (found_sub_field)
5036 ret = convert_to_anonymous_field (location, type, ret);
5037 gcc_assert (ret != NULL_TREE);
5043 /* Convert value RHS to type TYPE as preparation for an assignment to
5044 an lvalue of type TYPE. If ORIGTYPE is not NULL_TREE, it is the
5045 original type of RHS; this differs from TREE_TYPE (RHS) for enum
5046 types. NULL_POINTER_CONSTANT says whether RHS was a null pointer
5047 constant before any folding.
5048 The real work of conversion is done by `convert'.
5049 The purpose of this function is to generate error messages
5050 for assignments that are not allowed in C.
5051 ERRTYPE says whether it is argument passing, assignment,
5052 initialization or return.
5054 LOCATION is the location of the RHS.
5055 FUNCTION is a tree for the function being called.
5056 PARMNUM is the number of the argument, for printing in error messages. */
5059 convert_for_assignment (location_t location, tree type, tree rhs,
5060 tree origtype, enum impl_conv errtype,
5061 bool null_pointer_constant, tree fundecl,
5062 tree function, int parmnum)
5064 enum tree_code codel = TREE_CODE (type);
5065 tree orig_rhs = rhs;
5067 enum tree_code coder;
5068 tree rname = NULL_TREE;
5069 bool objc_ok = false;
5071 if (errtype == ic_argpass)
5074 /* Change pointer to function to the function itself for
5076 if (TREE_CODE (function) == ADDR_EXPR
5077 && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL)
5078 function = TREE_OPERAND (function, 0);
5080 /* Handle an ObjC selector specially for diagnostics. */
5081 selector = objc_message_selector ();
5083 if (selector && parmnum > 2)
5090 /* This macro is used to emit diagnostics to ensure that all format
5091 strings are complete sentences, visible to gettext and checked at
5093 #define WARN_FOR_ASSIGNMENT(LOCATION, OPT, AR, AS, IN, RE) \
5098 if (pedwarn (LOCATION, OPT, AR, parmnum, rname)) \
5099 inform ((fundecl && !DECL_IS_BUILTIN (fundecl)) \
5100 ? DECL_SOURCE_LOCATION (fundecl) : LOCATION, \
5101 "expected %qT but argument is of type %qT", \
5105 pedwarn (LOCATION, OPT, AS); \
5108 pedwarn_init (LOCATION, OPT, IN); \
5111 pedwarn (LOCATION, OPT, RE); \
5114 gcc_unreachable (); \
5118 /* This macro is used to emit diagnostics to ensure that all format
5119 strings are complete sentences, visible to gettext and checked at
5120 compile time. It is the same as WARN_FOR_ASSIGNMENT but with an
5121 extra parameter to enumerate qualifiers. */
5123 #define WARN_FOR_QUALIFIERS(LOCATION, OPT, AR, AS, IN, RE, QUALS) \
5128 if (pedwarn (LOCATION, OPT, AR, parmnum, rname, QUALS)) \
5129 inform ((fundecl && !DECL_IS_BUILTIN (fundecl)) \
5130 ? DECL_SOURCE_LOCATION (fundecl) : LOCATION, \
5131 "expected %qT but argument is of type %qT", \
5135 pedwarn (LOCATION, OPT, AS, QUALS); \
5138 pedwarn (LOCATION, OPT, IN, QUALS); \
5141 pedwarn (LOCATION, OPT, RE, QUALS); \
5144 gcc_unreachable (); \
5148 if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
5149 rhs = TREE_OPERAND (rhs, 0);
5151 rhstype = TREE_TYPE (rhs);
5152 coder = TREE_CODE (rhstype);
5154 if (coder == ERROR_MARK)
5155 return error_mark_node;
5157 if (c_dialect_objc ())
5180 objc_ok = objc_compare_types (type, rhstype, parmno, rname);
5183 if (warn_cxx_compat)
5185 tree checktype = origtype != NULL_TREE ? origtype : rhstype;
5186 if (checktype != error_mark_node
5187 && TREE_CODE (type) == ENUMERAL_TYPE
5188 && TYPE_MAIN_VARIANT (checktype) != TYPE_MAIN_VARIANT (type))
5190 WARN_FOR_ASSIGNMENT (input_location, OPT_Wc___compat,
5191 G_("enum conversion when passing argument "
5192 "%d of %qE is invalid in C++"),
5193 G_("enum conversion in assignment is "
5195 G_("enum conversion in initialization is "
5197 G_("enum conversion in return is "
5202 if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype))
5205 if (coder == VOID_TYPE)
5207 /* Except for passing an argument to an unprototyped function,
5208 this is a constraint violation. When passing an argument to
5209 an unprototyped function, it is compile-time undefined;
5210 making it a constraint in that case was rejected in
5212 error_at (location, "void value not ignored as it ought to be");
5213 return error_mark_node;
5215 rhs = require_complete_type (rhs);
5216 if (rhs == error_mark_node)
5217 return error_mark_node;
5218 /* A type converts to a reference to it.
5219 This code doesn't fully support references, it's just for the
5220 special case of va_start and va_copy. */
5221 if (codel == REFERENCE_TYPE
5222 && comptypes (TREE_TYPE (type), TREE_TYPE (rhs)) == 1)
5224 if (!lvalue_p (rhs))
5226 error_at (location, "cannot pass rvalue to reference parameter");
5227 return error_mark_node;
5229 if (!c_mark_addressable (rhs))
5230 return error_mark_node;
5231 rhs = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (rhs)), rhs);
5232 SET_EXPR_LOCATION (rhs, location);
5234 /* We already know that these two types are compatible, but they
5235 may not be exactly identical. In fact, `TREE_TYPE (type)' is
5236 likely to be __builtin_va_list and `TREE_TYPE (rhs)' is
5237 likely to be va_list, a typedef to __builtin_va_list, which
5238 is different enough that it will cause problems later. */
5239 if (TREE_TYPE (TREE_TYPE (rhs)) != TREE_TYPE (type))
5241 rhs = build1 (NOP_EXPR, build_pointer_type (TREE_TYPE (type)), rhs);
5242 SET_EXPR_LOCATION (rhs, location);
5245 rhs = build1 (NOP_EXPR, type, rhs);
5246 SET_EXPR_LOCATION (rhs, location);
5249 /* Some types can interconvert without explicit casts. */
5250 else if (codel == VECTOR_TYPE && coder == VECTOR_TYPE
5251 && vector_types_convertible_p (type, TREE_TYPE (rhs), true))
5252 return convert (type, rhs);
5253 /* Arithmetic types all interconvert, and enum is treated like int. */
5254 else if ((codel == INTEGER_TYPE || codel == REAL_TYPE
5255 || codel == FIXED_POINT_TYPE
5256 || codel == ENUMERAL_TYPE || codel == COMPLEX_TYPE
5257 || codel == BOOLEAN_TYPE)
5258 && (coder == INTEGER_TYPE || coder == REAL_TYPE
5259 || coder == FIXED_POINT_TYPE
5260 || coder == ENUMERAL_TYPE || coder == COMPLEX_TYPE
5261 || coder == BOOLEAN_TYPE))
5264 bool save = in_late_binary_op;
5265 if (codel == BOOLEAN_TYPE || codel == COMPLEX_TYPE)
5266 in_late_binary_op = true;
5267 ret = convert_and_check (type, orig_rhs);
5268 if (codel == BOOLEAN_TYPE || codel == COMPLEX_TYPE)
5269 in_late_binary_op = save;
5273 /* Aggregates in different TUs might need conversion. */
5274 if ((codel == RECORD_TYPE || codel == UNION_TYPE)
5276 && comptypes (type, rhstype))
5277 return convert_and_check (type, rhs);
5279 /* Conversion to a transparent union or record from its member types.
5280 This applies only to function arguments. */
5281 if (((codel == UNION_TYPE || codel == RECORD_TYPE)
5282 && TYPE_TRANSPARENT_AGGR (type))
5283 && errtype == ic_argpass)
5285 tree memb, marginal_memb = NULL_TREE;
5287 for (memb = TYPE_FIELDS (type); memb ; memb = DECL_CHAIN (memb))
5289 tree memb_type = TREE_TYPE (memb);
5291 if (comptypes (TYPE_MAIN_VARIANT (memb_type),
5292 TYPE_MAIN_VARIANT (rhstype)))
5295 if (TREE_CODE (memb_type) != POINTER_TYPE)
5298 if (coder == POINTER_TYPE)
5300 tree ttl = TREE_TYPE (memb_type);
5301 tree ttr = TREE_TYPE (rhstype);
5303 /* Any non-function converts to a [const][volatile] void *
5304 and vice versa; otherwise, targets must be the same.
5305 Meanwhile, the lhs target must have all the qualifiers of
5307 if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr)
5308 || comp_target_types (location, memb_type, rhstype))
5310 /* If this type won't generate any warnings, use it. */
5311 if (TYPE_QUALS (ttl) == TYPE_QUALS (ttr)
5312 || ((TREE_CODE (ttr) == FUNCTION_TYPE
5313 && TREE_CODE (ttl) == FUNCTION_TYPE)
5314 ? ((TYPE_QUALS (ttl) | TYPE_QUALS (ttr))
5315 == TYPE_QUALS (ttr))
5316 : ((TYPE_QUALS (ttl) | TYPE_QUALS (ttr))
5317 == TYPE_QUALS (ttl))))
5320 /* Keep looking for a better type, but remember this one. */
5322 marginal_memb = memb;
5326 /* Can convert integer zero to any pointer type. */
5327 if (null_pointer_constant)
5329 rhs = null_pointer_node;
5334 if (memb || marginal_memb)
5338 /* We have only a marginally acceptable member type;
5339 it needs a warning. */
5340 tree ttl = TREE_TYPE (TREE_TYPE (marginal_memb));
5341 tree ttr = TREE_TYPE (rhstype);
5343 /* Const and volatile mean something different for function
5344 types, so the usual warnings are not appropriate. */
5345 if (TREE_CODE (ttr) == FUNCTION_TYPE
5346 && TREE_CODE (ttl) == FUNCTION_TYPE)
5348 /* Because const and volatile on functions are
5349 restrictions that say the function will not do
5350 certain things, it is okay to use a const or volatile
5351 function where an ordinary one is wanted, but not
5353 if (TYPE_QUALS_NO_ADDR_SPACE (ttl)
5354 & ~TYPE_QUALS_NO_ADDR_SPACE (ttr))
5355 WARN_FOR_QUALIFIERS (location, 0,
5356 G_("passing argument %d of %qE "
5357 "makes %q#v qualified function "
5358 "pointer from unqualified"),
5359 G_("assignment makes %q#v qualified "
5360 "function pointer from "
5362 G_("initialization makes %q#v qualified "
5363 "function pointer from "
5365 G_("return makes %q#v qualified function "
5366 "pointer from unqualified"),
5367 TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr));
5369 else if (TYPE_QUALS_NO_ADDR_SPACE (ttr)
5370 & ~TYPE_QUALS_NO_ADDR_SPACE (ttl))
5371 WARN_FOR_QUALIFIERS (location, 0,
5372 G_("passing argument %d of %qE discards "
5373 "%qv qualifier from pointer target type"),
5374 G_("assignment discards %qv qualifier "
5375 "from pointer target type"),
5376 G_("initialization discards %qv qualifier "
5377 "from pointer target type"),
5378 G_("return discards %qv qualifier from "
5379 "pointer target type"),
5380 TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl));
5382 memb = marginal_memb;
5385 if (!fundecl || !DECL_IN_SYSTEM_HEADER (fundecl))
5386 pedwarn (location, OPT_pedantic,
5387 "ISO C prohibits argument conversion to union type");
5389 rhs = fold_convert_loc (location, TREE_TYPE (memb), rhs);
5390 return build_constructor_single (type, memb, rhs);
5394 /* Conversions among pointers */
5395 else if ((codel == POINTER_TYPE || codel == REFERENCE_TYPE)
5396 && (coder == codel))
5398 tree ttl = TREE_TYPE (type);
5399 tree ttr = TREE_TYPE (rhstype);
5402 bool is_opaque_pointer;
5403 int target_cmp = 0; /* Cache comp_target_types () result. */
5407 if (TREE_CODE (mvl) != ARRAY_TYPE)
5408 mvl = TYPE_MAIN_VARIANT (mvl);
5409 if (TREE_CODE (mvr) != ARRAY_TYPE)
5410 mvr = TYPE_MAIN_VARIANT (mvr);
5411 /* Opaque pointers are treated like void pointers. */
5412 is_opaque_pointer = vector_targets_convertible_p (ttl, ttr);
5414 /* The Plan 9 compiler permits a pointer to a struct to be
5415 automatically converted into a pointer to an anonymous field
5416 within the struct. */
5417 if (flag_plan9_extensions
5418 && (TREE_CODE (mvl) == RECORD_TYPE || TREE_CODE(mvl) == UNION_TYPE)
5419 && (TREE_CODE (mvr) == RECORD_TYPE || TREE_CODE(mvr) == UNION_TYPE)
5422 tree new_rhs = convert_to_anonymous_field (location, type, rhs);
5423 if (new_rhs != NULL_TREE)
5426 rhstype = TREE_TYPE (rhs);
5427 coder = TREE_CODE (rhstype);
5428 ttr = TREE_TYPE (rhstype);
5429 mvr = TYPE_MAIN_VARIANT (ttr);
5433 /* C++ does not allow the implicit conversion void* -> T*. However,
5434 for the purpose of reducing the number of false positives, we
5435 tolerate the special case of
5439 where NULL is typically defined in C to be '(void *) 0'. */
5440 if (VOID_TYPE_P (ttr) && rhs != null_pointer_node && !VOID_TYPE_P (ttl))
5441 warning_at (location, OPT_Wc___compat,
5442 "request for implicit conversion "
5443 "from %qT to %qT not permitted in C++", rhstype, type);
5445 /* See if the pointers point to incompatible address spaces. */
5446 asl = TYPE_ADDR_SPACE (ttl);
5447 asr = TYPE_ADDR_SPACE (ttr);
5448 if (!null_pointer_constant_p (rhs)
5449 && asr != asl && !targetm.addr_space.subset_p (asr, asl))
5454 error_at (location, "passing argument %d of %qE from pointer to "
5455 "non-enclosed address space", parmnum, rname);
5458 error_at (location, "assignment from pointer to "
5459 "non-enclosed address space");
5462 error_at (location, "initialization from pointer to "
5463 "non-enclosed address space");
5466 error_at (location, "return from pointer to "
5467 "non-enclosed address space");
5472 return error_mark_node;
5475 /* Check if the right-hand side has a format attribute but the
5476 left-hand side doesn't. */
5477 if (warn_missing_format_attribute
5478 && check_missing_format_attribute (type, rhstype))
5483 warning_at (location, OPT_Wmissing_format_attribute,
5484 "argument %d of %qE might be "
5485 "a candidate for a format attribute",
5489 warning_at (location, OPT_Wmissing_format_attribute,
5490 "assignment left-hand side might be "
5491 "a candidate for a format attribute");
5494 warning_at (location, OPT_Wmissing_format_attribute,
5495 "initialization left-hand side might be "
5496 "a candidate for a format attribute");
5499 warning_at (location, OPT_Wmissing_format_attribute,
5500 "return type might be "
5501 "a candidate for a format attribute");
5508 /* Any non-function converts to a [const][volatile] void *
5509 and vice versa; otherwise, targets must be the same.
5510 Meanwhile, the lhs target must have all the qualifiers of the rhs. */
5511 if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr)
5512 || (target_cmp = comp_target_types (location, type, rhstype))
5513 || is_opaque_pointer
5514 || (c_common_unsigned_type (mvl)
5515 == c_common_unsigned_type (mvr)))
5518 && ((VOID_TYPE_P (ttl) && TREE_CODE (ttr) == FUNCTION_TYPE)
5521 && !null_pointer_constant
5522 && TREE_CODE (ttl) == FUNCTION_TYPE)))
5523 WARN_FOR_ASSIGNMENT (location, OPT_pedantic,
5524 G_("ISO C forbids passing argument %d of "
5525 "%qE between function pointer "
5527 G_("ISO C forbids assignment between "
5528 "function pointer and %<void *%>"),
5529 G_("ISO C forbids initialization between "
5530 "function pointer and %<void *%>"),
5531 G_("ISO C forbids return between function "
5532 "pointer and %<void *%>"));
5533 /* Const and volatile mean something different for function types,
5534 so the usual warnings are not appropriate. */
5535 else if (TREE_CODE (ttr) != FUNCTION_TYPE
5536 && TREE_CODE (ttl) != FUNCTION_TYPE)
5538 if (TYPE_QUALS_NO_ADDR_SPACE (ttr)
5539 & ~TYPE_QUALS_NO_ADDR_SPACE (ttl))
5541 WARN_FOR_QUALIFIERS (location, 0,
5542 G_("passing argument %d of %qE discards "
5543 "%qv qualifier from pointer target type"),
5544 G_("assignment discards %qv qualifier "
5545 "from pointer target type"),
5546 G_("initialization discards %qv qualifier "
5547 "from pointer target type"),
5548 G_("return discards %qv qualifier from "
5549 "pointer target type"),
5550 TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl));
5552 /* If this is not a case of ignoring a mismatch in signedness,
5554 else if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr)
5557 /* If there is a mismatch, do warn. */
5558 else if (warn_pointer_sign)
5559 WARN_FOR_ASSIGNMENT (location, OPT_Wpointer_sign,
5560 G_("pointer targets in passing argument "
5561 "%d of %qE differ in signedness"),
5562 G_("pointer targets in assignment "
5563 "differ in signedness"),
5564 G_("pointer targets in initialization "
5565 "differ in signedness"),
5566 G_("pointer targets in return differ "
5569 else if (TREE_CODE (ttl) == FUNCTION_TYPE
5570 && TREE_CODE (ttr) == FUNCTION_TYPE)
5572 /* Because const and volatile on functions are restrictions
5573 that say the function will not do certain things,
5574 it is okay to use a const or volatile function
5575 where an ordinary one is wanted, but not vice-versa. */
5576 if (TYPE_QUALS_NO_ADDR_SPACE (ttl)
5577 & ~TYPE_QUALS_NO_ADDR_SPACE (ttr))
5578 WARN_FOR_QUALIFIERS (location, 0,
5579 G_("passing argument %d of %qE makes "
5580 "%q#v qualified function pointer "
5581 "from unqualified"),
5582 G_("assignment makes %q#v qualified function "
5583 "pointer from unqualified"),
5584 G_("initialization makes %q#v qualified "
5585 "function pointer from unqualified"),
5586 G_("return makes %q#v qualified function "
5587 "pointer from unqualified"),
5588 TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr));
5592 /* Avoid warning about the volatile ObjC EH puts on decls. */
5594 WARN_FOR_ASSIGNMENT (location, 0,
5595 G_("passing argument %d of %qE from "
5596 "incompatible pointer type"),
5597 G_("assignment from incompatible pointer type"),
5598 G_("initialization from incompatible "
5600 G_("return from incompatible pointer type"));
5602 return convert (type, rhs);
5604 else if (codel == POINTER_TYPE && coder == ARRAY_TYPE)
5606 /* ??? This should not be an error when inlining calls to
5607 unprototyped functions. */
5608 error_at (location, "invalid use of non-lvalue array");
5609 return error_mark_node;
5611 else if (codel == POINTER_TYPE && coder == INTEGER_TYPE)
5613 /* An explicit constant 0 can convert to a pointer,
5614 or one that results from arithmetic, even including
5615 a cast to integer type. */
5616 if (!null_pointer_constant)
5617 WARN_FOR_ASSIGNMENT (location, 0,
5618 G_("passing argument %d of %qE makes "
5619 "pointer from integer without a cast"),
5620 G_("assignment makes pointer from integer "
5622 G_("initialization makes pointer from "
5623 "integer without a cast"),
5624 G_("return makes pointer from integer "
5627 return convert (type, rhs);
5629 else if (codel == INTEGER_TYPE && coder == POINTER_TYPE)
5631 WARN_FOR_ASSIGNMENT (location, 0,
5632 G_("passing argument %d of %qE makes integer "
5633 "from pointer without a cast"),
5634 G_("assignment makes integer from pointer "
5636 G_("initialization makes integer from pointer "
5638 G_("return makes integer from pointer "
5640 return convert (type, rhs);
5642 else if (codel == BOOLEAN_TYPE && coder == POINTER_TYPE)
5645 bool save = in_late_binary_op;
5646 in_late_binary_op = true;
5647 ret = convert (type, rhs);
5648 in_late_binary_op = save;
5655 error_at (location, "incompatible type for argument %d of %qE", parmnum, rname);
5656 inform ((fundecl && !DECL_IS_BUILTIN (fundecl))
5657 ? DECL_SOURCE_LOCATION (fundecl) : input_location,
5658 "expected %qT but argument is of type %qT", type, rhstype);
5661 error_at (location, "incompatible types when assigning to type %qT from "
5662 "type %qT", type, rhstype);
5666 "incompatible types when initializing type %qT using type %qT",
5671 "incompatible types when returning type %qT but %qT was "
5672 "expected", rhstype, type);
5678 return error_mark_node;
5681 /* If VALUE is a compound expr all of whose expressions are constant, then
5682 return its value. Otherwise, return error_mark_node.
5684 This is for handling COMPOUND_EXPRs as initializer elements
5685 which is allowed with a warning when -pedantic is specified. */
5688 valid_compound_expr_initializer (tree value, tree endtype)
5690 if (TREE_CODE (value) == COMPOUND_EXPR)
5692 if (valid_compound_expr_initializer (TREE_OPERAND (value, 0), endtype)
5694 return error_mark_node;
5695 return valid_compound_expr_initializer (TREE_OPERAND (value, 1),
5698 else if (!initializer_constant_valid_p (value, endtype))
5699 return error_mark_node;
5704 /* Perform appropriate conversions on the initial value of a variable,
5705 store it in the declaration DECL,
5706 and print any error messages that are appropriate.
5707 If ORIGTYPE is not NULL_TREE, it is the original type of INIT.
5708 If the init is invalid, store an ERROR_MARK.
5710 INIT_LOC is the location of the initial value. */
5713 store_init_value (location_t init_loc, tree decl, tree init, tree origtype)
5718 /* If variable's type was invalidly declared, just ignore it. */
5720 type = TREE_TYPE (decl);
5721 if (TREE_CODE (type) == ERROR_MARK)
5724 /* Digest the specified initializer into an expression. */
5727 npc = null_pointer_constant_p (init);
5728 value = digest_init (init_loc, type, init, origtype, npc,
5729 true, TREE_STATIC (decl));
5731 /* Store the expression if valid; else report error. */
5733 if (!in_system_header
5734 && AGGREGATE_TYPE_P (TREE_TYPE (decl)) && !TREE_STATIC (decl))
5735 warning (OPT_Wtraditional, "traditional C rejects automatic "
5736 "aggregate initialization");
5738 DECL_INITIAL (decl) = value;
5740 /* ANSI wants warnings about out-of-range constant initializers. */
5741 STRIP_TYPE_NOPS (value);
5742 if (TREE_STATIC (decl))
5743 constant_expression_warning (value);
5745 /* Check if we need to set array size from compound literal size. */
5746 if (TREE_CODE (type) == ARRAY_TYPE
5747 && TYPE_DOMAIN (type) == 0
5748 && value != error_mark_node)
5750 tree inside_init = init;
5752 STRIP_TYPE_NOPS (inside_init);
5753 inside_init = fold (inside_init);
5755 if (TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR)
5757 tree cldecl = COMPOUND_LITERAL_EXPR_DECL (inside_init);
5759 if (TYPE_DOMAIN (TREE_TYPE (cldecl)))
5761 /* For int foo[] = (int [3]){1}; we need to set array size
5762 now since later on array initializer will be just the
5763 brace enclosed list of the compound literal. */
5764 tree etype = strip_array_types (TREE_TYPE (decl));
5765 type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
5766 TYPE_DOMAIN (type) = TYPE_DOMAIN (TREE_TYPE (cldecl));
5768 layout_decl (cldecl, 0);
5770 = c_build_qualified_type (type, TYPE_QUALS (etype));
5776 /* Methods for storing and printing names for error messages. */
5778 /* Implement a spelling stack that allows components of a name to be pushed
5779 and popped. Each element on the stack is this structure. */
5786 unsigned HOST_WIDE_INT i;
5791 #define SPELLING_STRING 1
5792 #define SPELLING_MEMBER 2
5793 #define SPELLING_BOUNDS 3
5795 static struct spelling *spelling; /* Next stack element (unused). */
5796 static struct spelling *spelling_base; /* Spelling stack base. */
5797 static int spelling_size; /* Size of the spelling stack. */
5799 /* Macros to save and restore the spelling stack around push_... functions.
5800 Alternative to SAVE_SPELLING_STACK. */
5802 #define SPELLING_DEPTH() (spelling - spelling_base)
5803 #define RESTORE_SPELLING_DEPTH(DEPTH) (spelling = spelling_base + (DEPTH))
5805 /* Push an element on the spelling stack with type KIND and assign VALUE
5808 #define PUSH_SPELLING(KIND, VALUE, MEMBER) \
5810 int depth = SPELLING_DEPTH (); \
5812 if (depth >= spelling_size) \
5814 spelling_size += 10; \
5815 spelling_base = XRESIZEVEC (struct spelling, spelling_base, \
5817 RESTORE_SPELLING_DEPTH (depth); \
5820 spelling->kind = (KIND); \
5821 spelling->MEMBER = (VALUE); \
5825 /* Push STRING on the stack. Printed literally. */
5828 push_string (const char *string)
5830 PUSH_SPELLING (SPELLING_STRING, string, u.s);
5833 /* Push a member name on the stack. Printed as '.' STRING. */
5836 push_member_name (tree decl)
5838 const char *const string
5840 ? identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl)))
5841 : _("<anonymous>"));
5842 PUSH_SPELLING (SPELLING_MEMBER, string, u.s);
5845 /* Push an array bounds on the stack. Printed as [BOUNDS]. */
5848 push_array_bounds (unsigned HOST_WIDE_INT bounds)
5850 PUSH_SPELLING (SPELLING_BOUNDS, bounds, u.i);
5853 /* Compute the maximum size in bytes of the printed spelling. */
5856 spelling_length (void)
5861 for (p = spelling_base; p < spelling; p++)
5863 if (p->kind == SPELLING_BOUNDS)
5866 size += strlen (p->u.s) + 1;
5872 /* Print the spelling to BUFFER and return it. */
5875 print_spelling (char *buffer)
5880 for (p = spelling_base; p < spelling; p++)
5881 if (p->kind == SPELLING_BOUNDS)
5883 sprintf (d, "[" HOST_WIDE_INT_PRINT_UNSIGNED "]", p->u.i);
5889 if (p->kind == SPELLING_MEMBER)
5891 for (s = p->u.s; (*d = *s++); d++)
5898 /* Issue an error message for a bad initializer component.
5899 GMSGID identifies the message.
5900 The component name is taken from the spelling stack. */
5903 error_init (const char *gmsgid)
5907 /* The gmsgid may be a format string with %< and %>. */
5909 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
5911 error ("(near initialization for %qs)", ofwhat);
5914 /* Issue a pedantic warning for a bad initializer component. OPT is
5915 the option OPT_* (from options.h) controlling this warning or 0 if
5916 it is unconditionally given. GMSGID identifies the message. The
5917 component name is taken from the spelling stack. */
5920 pedwarn_init (location_t location, int opt, const char *gmsgid)
5924 /* The gmsgid may be a format string with %< and %>. */
5925 pedwarn (location, opt, gmsgid);
5926 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
5928 pedwarn (location, opt, "(near initialization for %qs)", ofwhat);
5931 /* Issue a warning for a bad initializer component.
5933 OPT is the OPT_W* value corresponding to the warning option that
5934 controls this warning. GMSGID identifies the message. The
5935 component name is taken from the spelling stack. */
5938 warning_init (int opt, const char *gmsgid)
5942 /* The gmsgid may be a format string with %< and %>. */
5943 warning (opt, gmsgid);
5944 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
5946 warning (opt, "(near initialization for %qs)", ofwhat);
5949 /* If TYPE is an array type and EXPR is a parenthesized string
5950 constant, warn if pedantic that EXPR is being used to initialize an
5951 object of type TYPE. */
5954 maybe_warn_string_init (tree type, struct c_expr expr)
5957 && TREE_CODE (type) == ARRAY_TYPE
5958 && TREE_CODE (expr.value) == STRING_CST
5959 && expr.original_code != STRING_CST)
5960 pedwarn_init (input_location, OPT_pedantic,
5961 "array initialized from parenthesized string constant");
5964 /* Digest the parser output INIT as an initializer for type TYPE.
5965 Return a C expression of type TYPE to represent the initial value.
5967 If ORIGTYPE is not NULL_TREE, it is the original type of INIT.
5969 NULL_POINTER_CONSTANT is true if INIT is a null pointer constant.
5971 If INIT is a string constant, STRICT_STRING is true if it is
5972 unparenthesized or we should not warn here for it being parenthesized.
5973 For other types of INIT, STRICT_STRING is not used.
5975 INIT_LOC is the location of the INIT.
5977 REQUIRE_CONSTANT requests an error if non-constant initializers or
5978 elements are seen. */
5981 digest_init (location_t init_loc, tree type, tree init, tree origtype,
5982 bool null_pointer_constant, bool strict_string,
5983 int require_constant)
5985 enum tree_code code = TREE_CODE (type);
5986 tree inside_init = init;
5987 tree semantic_type = NULL_TREE;
5988 bool maybe_const = true;
5990 if (type == error_mark_node
5992 || init == error_mark_node
5993 || TREE_TYPE (init) == error_mark_node)
5994 return error_mark_node;
5996 STRIP_TYPE_NOPS (inside_init);
5998 if (TREE_CODE (inside_init) == EXCESS_PRECISION_EXPR)
6000 semantic_type = TREE_TYPE (inside_init);
6001 inside_init = TREE_OPERAND (inside_init, 0);
6003 inside_init = c_fully_fold (inside_init, require_constant, &maybe_const);
6004 inside_init = decl_constant_value_for_optimization (inside_init);
6006 /* Initialization of an array of chars from a string constant
6007 optionally enclosed in braces. */
6009 if (code == ARRAY_TYPE && inside_init
6010 && TREE_CODE (inside_init) == STRING_CST)
6012 tree typ1 = TYPE_MAIN_VARIANT (TREE_TYPE (type));
6013 /* Note that an array could be both an array of character type
6014 and an array of wchar_t if wchar_t is signed char or unsigned
6016 bool char_array = (typ1 == char_type_node
6017 || typ1 == signed_char_type_node
6018 || typ1 == unsigned_char_type_node);
6019 bool wchar_array = !!comptypes (typ1, wchar_type_node);
6020 bool char16_array = !!comptypes (typ1, char16_type_node);
6021 bool char32_array = !!comptypes (typ1, char32_type_node);
6023 if (char_array || wchar_array || char16_array || char32_array)
6026 tree typ2 = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init)));
6027 expr.value = inside_init;
6028 expr.original_code = (strict_string ? STRING_CST : ERROR_MARK);
6029 expr.original_type = NULL;
6030 maybe_warn_string_init (type, expr);
6032 if (TYPE_DOMAIN (type) && !TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
6033 pedwarn_init (init_loc, OPT_pedantic,
6034 "initialization of a flexible array member");
6036 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
6037 TYPE_MAIN_VARIANT (type)))
6042 if (typ2 != char_type_node)
6044 error_init ("char-array initialized from wide string");
6045 return error_mark_node;
6050 if (typ2 == char_type_node)
6052 error_init ("wide character array initialized from non-wide "
6054 return error_mark_node;
6056 else if (!comptypes(typ1, typ2))
6058 error_init ("wide character array initialized from "
6059 "incompatible wide string");
6060 return error_mark_node;
6064 TREE_TYPE (inside_init) = type;
6065 if (TYPE_DOMAIN (type) != 0
6066 && TYPE_SIZE (type) != 0
6067 && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
6069 unsigned HOST_WIDE_INT len = TREE_STRING_LENGTH (inside_init);
6071 /* Subtract the size of a single (possibly wide) character
6072 because it's ok to ignore the terminating null char
6073 that is counted in the length of the constant. */
6074 if (0 > compare_tree_int (TYPE_SIZE_UNIT (type),
6076 - (TYPE_PRECISION (typ1)
6078 pedwarn_init (init_loc, 0,
6079 ("initializer-string for array of chars "
6081 else if (warn_cxx_compat
6082 && 0 > compare_tree_int (TYPE_SIZE_UNIT (type), len))
6083 warning_at (init_loc, OPT_Wc___compat,
6084 ("initializer-string for array chars "
6085 "is too long for C++"));
6090 else if (INTEGRAL_TYPE_P (typ1))
6092 error_init ("array of inappropriate type initialized "
6093 "from string constant");
6094 return error_mark_node;
6098 /* Build a VECTOR_CST from a *constant* vector constructor. If the
6099 vector constructor is not constant (e.g. {1,2,3,foo()}) then punt
6100 below and handle as a constructor. */
6101 if (code == VECTOR_TYPE
6102 && TREE_CODE (TREE_TYPE (inside_init)) == VECTOR_TYPE
6103 && vector_types_convertible_p (TREE_TYPE (inside_init), type, true)
6104 && TREE_CONSTANT (inside_init))
6106 if (TREE_CODE (inside_init) == VECTOR_CST
6107 && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
6108 TYPE_MAIN_VARIANT (type)))
6111 if (TREE_CODE (inside_init) == CONSTRUCTOR)
6113 unsigned HOST_WIDE_INT ix;
6115 bool constant_p = true;
6117 /* Iterate through elements and check if all constructor
6118 elements are *_CSTs. */
6119 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (inside_init), ix, value)
6120 if (!CONSTANT_CLASS_P (value))
6127 return build_vector_from_ctor (type,
6128 CONSTRUCTOR_ELTS (inside_init));
6132 if (warn_sequence_point)
6133 verify_sequence_points (inside_init);
6135 /* Any type can be initialized
6136 from an expression of the same type, optionally with braces. */
6138 if (inside_init && TREE_TYPE (inside_init) != 0
6139 && (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
6140 TYPE_MAIN_VARIANT (type))
6141 || (code == ARRAY_TYPE
6142 && comptypes (TREE_TYPE (inside_init), type))
6143 || (code == VECTOR_TYPE
6144 && comptypes (TREE_TYPE (inside_init), type))
6145 || (code == POINTER_TYPE
6146 && TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE
6147 && comptypes (TREE_TYPE (TREE_TYPE (inside_init)),
6148 TREE_TYPE (type)))))
6150 if (code == POINTER_TYPE)
6152 if (TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE)
6154 if (TREE_CODE (inside_init) == STRING_CST
6155 || TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR)
6156 inside_init = array_to_pointer_conversion
6157 (init_loc, inside_init);
6160 error_init ("invalid use of non-lvalue array");
6161 return error_mark_node;
6166 if (code == VECTOR_TYPE)
6167 /* Although the types are compatible, we may require a
6169 inside_init = convert (type, inside_init);
6171 if (require_constant
6172 && (code == VECTOR_TYPE || !flag_isoc99)
6173 && TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR)
6175 /* As an extension, allow initializing objects with static storage
6176 duration with compound literals (which are then treated just as
6177 the brace enclosed list they contain). Also allow this for
6178 vectors, as we can only assign them with compound literals. */
6179 tree decl = COMPOUND_LITERAL_EXPR_DECL (inside_init);
6180 inside_init = DECL_INITIAL (decl);
6183 if (code == ARRAY_TYPE && TREE_CODE (inside_init) != STRING_CST
6184 && TREE_CODE (inside_init) != CONSTRUCTOR)
6186 error_init ("array initialized from non-constant array expression");
6187 return error_mark_node;
6190 /* Compound expressions can only occur here if -pedantic or
6191 -pedantic-errors is specified. In the later case, we always want
6192 an error. In the former case, we simply want a warning. */
6193 if (require_constant && pedantic
6194 && TREE_CODE (inside_init) == COMPOUND_EXPR)
6197 = valid_compound_expr_initializer (inside_init,
6198 TREE_TYPE (inside_init));
6199 if (inside_init == error_mark_node)
6200 error_init ("initializer element is not constant");
6202 pedwarn_init (init_loc, OPT_pedantic,
6203 "initializer element is not constant");
6204 if (flag_pedantic_errors)
6205 inside_init = error_mark_node;
6207 else if (require_constant
6208 && !initializer_constant_valid_p (inside_init,
6209 TREE_TYPE (inside_init)))
6211 error_init ("initializer element is not constant");
6212 inside_init = error_mark_node;
6214 else if (require_constant && !maybe_const)
6215 pedwarn_init (init_loc, 0,
6216 "initializer element is not a constant expression");
6218 /* Added to enable additional -Wmissing-format-attribute warnings. */
6219 if (TREE_CODE (TREE_TYPE (inside_init)) == POINTER_TYPE)
6220 inside_init = convert_for_assignment (init_loc, type, inside_init,
6222 ic_init, null_pointer_constant,
6223 NULL_TREE, NULL_TREE, 0);
6227 /* Handle scalar types, including conversions. */
6229 if (code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE
6230 || code == POINTER_TYPE || code == ENUMERAL_TYPE || code == BOOLEAN_TYPE
6231 || code == COMPLEX_TYPE || code == VECTOR_TYPE)
6233 if (TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE
6234 && (TREE_CODE (init) == STRING_CST
6235 || TREE_CODE (init) == COMPOUND_LITERAL_EXPR))
6236 inside_init = init = array_to_pointer_conversion (init_loc, init);
6238 inside_init = build1 (EXCESS_PRECISION_EXPR, semantic_type,
6241 = convert_for_assignment (init_loc, type, inside_init, origtype,
6242 ic_init, null_pointer_constant,
6243 NULL_TREE, NULL_TREE, 0);
6245 /* Check to see if we have already given an error message. */
6246 if (inside_init == error_mark_node)
6248 else if (require_constant && !TREE_CONSTANT (inside_init))
6250 error_init ("initializer element is not constant");
6251 inside_init = error_mark_node;
6253 else if (require_constant
6254 && !initializer_constant_valid_p (inside_init,
6255 TREE_TYPE (inside_init)))
6257 error_init ("initializer element is not computable at load time");
6258 inside_init = error_mark_node;
6260 else if (require_constant && !maybe_const)
6261 pedwarn_init (init_loc, 0,
6262 "initializer element is not a constant expression");
6267 /* Come here only for records and arrays. */
6269 if (COMPLETE_TYPE_P (type) && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
6271 error_init ("variable-sized object may not be initialized");
6272 return error_mark_node;
6275 error_init ("invalid initializer");
6276 return error_mark_node;
6279 /* Handle initializers that use braces. */
6281 /* Type of object we are accumulating a constructor for.
6282 This type is always a RECORD_TYPE, UNION_TYPE or ARRAY_TYPE. */
6283 static tree constructor_type;
6285 /* For a RECORD_TYPE or UNION_TYPE, this is the chain of fields
6287 static tree constructor_fields;
6289 /* For an ARRAY_TYPE, this is the specified index
6290 at which to store the next element we get. */
6291 static tree constructor_index;
6293 /* For an ARRAY_TYPE, this is the maximum index. */
6294 static tree constructor_max_index;
6296 /* For a RECORD_TYPE, this is the first field not yet written out. */
6297 static tree constructor_unfilled_fields;
6299 /* For an ARRAY_TYPE, this is the index of the first element
6300 not yet written out. */
6301 static tree constructor_unfilled_index;
6303 /* In a RECORD_TYPE, the byte index of the next consecutive field.
6304 This is so we can generate gaps between fields, when appropriate. */
6305 static tree constructor_bit_index;
6307 /* If we are saving up the elements rather than allocating them,
6308 this is the list of elements so far (in reverse order,
6309 most recent first). */
6310 static VEC(constructor_elt,gc) *constructor_elements;
6312 /* 1 if constructor should be incrementally stored into a constructor chain,
6313 0 if all the elements should be kept in AVL tree. */
6314 static int constructor_incremental;
6316 /* 1 if so far this constructor's elements are all compile-time constants. */
6317 static int constructor_constant;
6319 /* 1 if so far this constructor's elements are all valid address constants. */
6320 static int constructor_simple;
6322 /* 1 if this constructor has an element that cannot be part of a
6323 constant expression. */
6324 static int constructor_nonconst;
6326 /* 1 if this constructor is erroneous so far. */
6327 static int constructor_erroneous;
6329 /* Structure for managing pending initializer elements, organized as an
6334 struct init_node *left, *right;
6335 struct init_node *parent;
6342 /* Tree of pending elements at this constructor level.
6343 These are elements encountered out of order
6344 which belong at places we haven't reached yet in actually
6346 Will never hold tree nodes across GC runs. */
6347 static struct init_node *constructor_pending_elts;
6349 /* The SPELLING_DEPTH of this constructor. */
6350 static int constructor_depth;
6352 /* DECL node for which an initializer is being read.
6353 0 means we are reading a constructor expression
6354 such as (struct foo) {...}. */
6355 static tree constructor_decl;
6357 /* Nonzero if this is an initializer for a top-level decl. */
6358 static int constructor_top_level;
6360 /* Nonzero if there were any member designators in this initializer. */
6361 static int constructor_designated;
6363 /* Nesting depth of designator list. */
6364 static int designator_depth;
6366 /* Nonzero if there were diagnosed errors in this designator list. */
6367 static int designator_erroneous;
6370 /* This stack has a level for each implicit or explicit level of
6371 structuring in the initializer, including the outermost one. It
6372 saves the values of most of the variables above. */
6374 struct constructor_range_stack;
6376 struct constructor_stack
6378 struct constructor_stack *next;
6383 tree unfilled_index;
6384 tree unfilled_fields;
6386 VEC(constructor_elt,gc) *elements;
6387 struct init_node *pending_elts;
6390 /* If value nonzero, this value should replace the entire
6391 constructor at this level. */
6392 struct c_expr replacement_value;
6393 struct constructor_range_stack *range_stack;
6404 static struct constructor_stack *constructor_stack;
6406 /* This stack represents designators from some range designator up to
6407 the last designator in the list. */
6409 struct constructor_range_stack
6411 struct constructor_range_stack *next, *prev;
6412 struct constructor_stack *stack;
6419 static struct constructor_range_stack *constructor_range_stack;
6421 /* This stack records separate initializers that are nested.
6422 Nested initializers can't happen in ANSI C, but GNU C allows them
6423 in cases like { ... (struct foo) { ... } ... }. */
6425 struct initializer_stack
6427 struct initializer_stack *next;
6429 struct constructor_stack *constructor_stack;
6430 struct constructor_range_stack *constructor_range_stack;
6431 VEC(constructor_elt,gc) *elements;
6432 struct spelling *spelling;
6433 struct spelling *spelling_base;
6436 char require_constant_value;
6437 char require_constant_elements;
6440 static struct initializer_stack *initializer_stack;
6442 /* Prepare to parse and output the initializer for variable DECL. */
6445 start_init (tree decl, tree asmspec_tree ATTRIBUTE_UNUSED, int top_level)
6448 struct initializer_stack *p = XNEW (struct initializer_stack);
6450 p->decl = constructor_decl;
6451 p->require_constant_value = require_constant_value;
6452 p->require_constant_elements = require_constant_elements;
6453 p->constructor_stack = constructor_stack;
6454 p->constructor_range_stack = constructor_range_stack;
6455 p->elements = constructor_elements;
6456 p->spelling = spelling;
6457 p->spelling_base = spelling_base;
6458 p->spelling_size = spelling_size;
6459 p->top_level = constructor_top_level;
6460 p->next = initializer_stack;
6461 initializer_stack = p;
6463 constructor_decl = decl;
6464 constructor_designated = 0;
6465 constructor_top_level = top_level;
6467 if (decl != 0 && decl != error_mark_node)
6469 require_constant_value = TREE_STATIC (decl);
6470 require_constant_elements
6471 = ((TREE_STATIC (decl) || (pedantic && !flag_isoc99))
6472 /* For a scalar, you can always use any value to initialize,
6473 even within braces. */
6474 && (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
6475 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
6476 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
6477 || TREE_CODE (TREE_TYPE (decl)) == QUAL_UNION_TYPE));
6478 locus = identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl)));
6482 require_constant_value = 0;
6483 require_constant_elements = 0;
6484 locus = _("(anonymous)");
6487 constructor_stack = 0;
6488 constructor_range_stack = 0;
6490 missing_braces_mentioned = 0;
6494 RESTORE_SPELLING_DEPTH (0);
6497 push_string (locus);
6503 struct initializer_stack *p = initializer_stack;
6505 /* Free the whole constructor stack of this initializer. */
6506 while (constructor_stack)
6508 struct constructor_stack *q = constructor_stack;
6509 constructor_stack = q->next;
6513 gcc_assert (!constructor_range_stack);
6515 /* Pop back to the data of the outer initializer (if any). */
6516 free (spelling_base);
6518 constructor_decl = p->decl;
6519 require_constant_value = p->require_constant_value;
6520 require_constant_elements = p->require_constant_elements;
6521 constructor_stack = p->constructor_stack;
6522 constructor_range_stack = p->constructor_range_stack;
6523 constructor_elements = p->elements;
6524 spelling = p->spelling;
6525 spelling_base = p->spelling_base;
6526 spelling_size = p->spelling_size;
6527 constructor_top_level = p->top_level;
6528 initializer_stack = p->next;
6532 /* Call here when we see the initializer is surrounded by braces.
6533 This is instead of a call to push_init_level;
6534 it is matched by a call to pop_init_level.
6536 TYPE is the type to initialize, for a constructor expression.
6537 For an initializer for a decl, TYPE is zero. */
6540 really_start_incremental_init (tree type)
6542 struct constructor_stack *p = XNEW (struct constructor_stack);
6545 type = TREE_TYPE (constructor_decl);
6547 if (TREE_CODE (type) == VECTOR_TYPE
6548 && TYPE_VECTOR_OPAQUE (type))
6549 error ("opaque vector types cannot be initialized");
6551 p->type = constructor_type;
6552 p->fields = constructor_fields;
6553 p->index = constructor_index;
6554 p->max_index = constructor_max_index;
6555 p->unfilled_index = constructor_unfilled_index;
6556 p->unfilled_fields = constructor_unfilled_fields;
6557 p->bit_index = constructor_bit_index;
6558 p->elements = constructor_elements;
6559 p->constant = constructor_constant;
6560 p->simple = constructor_simple;
6561 p->nonconst = constructor_nonconst;
6562 p->erroneous = constructor_erroneous;
6563 p->pending_elts = constructor_pending_elts;
6564 p->depth = constructor_depth;
6565 p->replacement_value.value = 0;
6566 p->replacement_value.original_code = ERROR_MARK;
6567 p->replacement_value.original_type = NULL;
6571 p->incremental = constructor_incremental;
6572 p->designated = constructor_designated;
6574 constructor_stack = p;
6576 constructor_constant = 1;
6577 constructor_simple = 1;
6578 constructor_nonconst = 0;
6579 constructor_depth = SPELLING_DEPTH ();
6580 constructor_elements = 0;
6581 constructor_pending_elts = 0;
6582 constructor_type = type;
6583 constructor_incremental = 1;
6584 constructor_designated = 0;
6585 designator_depth = 0;
6586 designator_erroneous = 0;
6588 if (TREE_CODE (constructor_type) == RECORD_TYPE
6589 || TREE_CODE (constructor_type) == UNION_TYPE)
6591 constructor_fields = TYPE_FIELDS (constructor_type);
6592 /* Skip any nameless bit fields at the beginning. */
6593 while (constructor_fields != 0 && DECL_C_BIT_FIELD (constructor_fields)
6594 && DECL_NAME (constructor_fields) == 0)
6595 constructor_fields = DECL_CHAIN (constructor_fields);
6597 constructor_unfilled_fields = constructor_fields;
6598 constructor_bit_index = bitsize_zero_node;
6600 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
6602 if (TYPE_DOMAIN (constructor_type))
6604 constructor_max_index
6605 = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
6607 /* Detect non-empty initializations of zero-length arrays. */
6608 if (constructor_max_index == NULL_TREE
6609 && TYPE_SIZE (constructor_type))
6610 constructor_max_index = integer_minus_one_node;
6612 /* constructor_max_index needs to be an INTEGER_CST. Attempts
6613 to initialize VLAs will cause a proper error; avoid tree
6614 checking errors as well by setting a safe value. */
6615 if (constructor_max_index
6616 && TREE_CODE (constructor_max_index) != INTEGER_CST)
6617 constructor_max_index = integer_minus_one_node;
6620 = convert (bitsizetype,
6621 TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
6625 constructor_index = bitsize_zero_node;
6626 constructor_max_index = NULL_TREE;
6629 constructor_unfilled_index = constructor_index;
6631 else if (TREE_CODE (constructor_type) == VECTOR_TYPE)
6633 /* Vectors are like simple fixed-size arrays. */
6634 constructor_max_index =
6635 bitsize_int (TYPE_VECTOR_SUBPARTS (constructor_type) - 1);
6636 constructor_index = bitsize_zero_node;
6637 constructor_unfilled_index = constructor_index;
6641 /* Handle the case of int x = {5}; */
6642 constructor_fields = constructor_type;
6643 constructor_unfilled_fields = constructor_type;
6647 /* Push down into a subobject, for initialization.
6648 If this is for an explicit set of braces, IMPLICIT is 0.
6649 If it is because the next element belongs at a lower level,
6650 IMPLICIT is 1 (or 2 if the push is because of designator list). */
6653 push_init_level (int implicit, struct obstack * braced_init_obstack)
6655 struct constructor_stack *p;
6656 tree value = NULL_TREE;
6658 /* If we've exhausted any levels that didn't have braces,
6659 pop them now. If implicit == 1, this will have been done in
6660 process_init_element; do not repeat it here because in the case
6661 of excess initializers for an empty aggregate this leads to an
6662 infinite cycle of popping a level and immediately recreating
6666 while (constructor_stack->implicit)
6668 if ((TREE_CODE (constructor_type) == RECORD_TYPE
6669 || TREE_CODE (constructor_type) == UNION_TYPE)
6670 && constructor_fields == 0)
6671 process_init_element (pop_init_level (1, braced_init_obstack),
6672 true, braced_init_obstack);
6673 else if (TREE_CODE (constructor_type) == ARRAY_TYPE
6674 && constructor_max_index
6675 && tree_int_cst_lt (constructor_max_index,
6677 process_init_element (pop_init_level (1, braced_init_obstack),
6678 true, braced_init_obstack);
6684 /* Unless this is an explicit brace, we need to preserve previous
6688 if ((TREE_CODE (constructor_type) == RECORD_TYPE
6689 || TREE_CODE (constructor_type) == UNION_TYPE)
6690 && constructor_fields)
6691 value = find_init_member (constructor_fields, braced_init_obstack);
6692 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
6693 value = find_init_member (constructor_index, braced_init_obstack);
6696 p = XNEW (struct constructor_stack);
6697 p->type = constructor_type;
6698 p->fields = constructor_fields;
6699 p->index = constructor_index;
6700 p->max_index = constructor_max_index;
6701 p->unfilled_index = constructor_unfilled_index;
6702 p->unfilled_fields = constructor_unfilled_fields;
6703 p->bit_index = constructor_bit_index;
6704 p->elements = constructor_elements;
6705 p->constant = constructor_constant;
6706 p->simple = constructor_simple;
6707 p->nonconst = constructor_nonconst;
6708 p->erroneous = constructor_erroneous;
6709 p->pending_elts = constructor_pending_elts;
6710 p->depth = constructor_depth;
6711 p->replacement_value.value = 0;
6712 p->replacement_value.original_code = ERROR_MARK;
6713 p->replacement_value.original_type = NULL;
6714 p->implicit = implicit;
6716 p->incremental = constructor_incremental;
6717 p->designated = constructor_designated;
6718 p->next = constructor_stack;
6720 constructor_stack = p;
6722 constructor_constant = 1;
6723 constructor_simple = 1;
6724 constructor_nonconst = 0;
6725 constructor_depth = SPELLING_DEPTH ();
6726 constructor_elements = 0;
6727 constructor_incremental = 1;
6728 constructor_designated = 0;
6729 constructor_pending_elts = 0;
6732 p->range_stack = constructor_range_stack;
6733 constructor_range_stack = 0;
6734 designator_depth = 0;
6735 designator_erroneous = 0;
6738 /* Don't die if an entire brace-pair level is superfluous
6739 in the containing level. */
6740 if (constructor_type == 0)
6742 else if (TREE_CODE (constructor_type) == RECORD_TYPE
6743 || TREE_CODE (constructor_type) == UNION_TYPE)
6745 /* Don't die if there are extra init elts at the end. */
6746 if (constructor_fields == 0)
6747 constructor_type = 0;
6750 constructor_type = TREE_TYPE (constructor_fields);
6751 push_member_name (constructor_fields);
6752 constructor_depth++;
6755 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
6757 constructor_type = TREE_TYPE (constructor_type);
6758 push_array_bounds (tree_low_cst (constructor_index, 1));
6759 constructor_depth++;
6762 if (constructor_type == 0)
6764 error_init ("extra brace group at end of initializer");
6765 constructor_fields = 0;
6766 constructor_unfilled_fields = 0;
6770 if (value && TREE_CODE (value) == CONSTRUCTOR)
6772 constructor_constant = TREE_CONSTANT (value);
6773 constructor_simple = TREE_STATIC (value);
6774 constructor_nonconst = CONSTRUCTOR_NON_CONST (value);
6775 constructor_elements = CONSTRUCTOR_ELTS (value);
6776 if (!VEC_empty (constructor_elt, constructor_elements)
6777 && (TREE_CODE (constructor_type) == RECORD_TYPE
6778 || TREE_CODE (constructor_type) == ARRAY_TYPE))
6779 set_nonincremental_init (braced_init_obstack);
6782 if (implicit == 1 && warn_missing_braces && !missing_braces_mentioned)
6784 missing_braces_mentioned = 1;
6785 warning_init (OPT_Wmissing_braces, "missing braces around initializer");
6788 if (TREE_CODE (constructor_type) == RECORD_TYPE
6789 || TREE_CODE (constructor_type) == UNION_TYPE)
6791 constructor_fields = TYPE_FIELDS (constructor_type);
6792 /* Skip any nameless bit fields at the beginning. */
6793 while (constructor_fields != 0 && DECL_C_BIT_FIELD (constructor_fields)
6794 && DECL_NAME (constructor_fields) == 0)
6795 constructor_fields = DECL_CHAIN (constructor_fields);
6797 constructor_unfilled_fields = constructor_fields;
6798 constructor_bit_index = bitsize_zero_node;
6800 else if (TREE_CODE (constructor_type) == VECTOR_TYPE)
6802 /* Vectors are like simple fixed-size arrays. */
6803 constructor_max_index =
6804 bitsize_int (TYPE_VECTOR_SUBPARTS (constructor_type) - 1);
6805 constructor_index = bitsize_int (0);
6806 constructor_unfilled_index = constructor_index;
6808 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
6810 if (TYPE_DOMAIN (constructor_type))
6812 constructor_max_index
6813 = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
6815 /* Detect non-empty initializations of zero-length arrays. */
6816 if (constructor_max_index == NULL_TREE
6817 && TYPE_SIZE (constructor_type))
6818 constructor_max_index = integer_minus_one_node;
6820 /* constructor_max_index needs to be an INTEGER_CST. Attempts
6821 to initialize VLAs will cause a proper error; avoid tree
6822 checking errors as well by setting a safe value. */
6823 if (constructor_max_index
6824 && TREE_CODE (constructor_max_index) != INTEGER_CST)
6825 constructor_max_index = integer_minus_one_node;
6828 = convert (bitsizetype,
6829 TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
6832 constructor_index = bitsize_zero_node;
6834 constructor_unfilled_index = constructor_index;
6835 if (value && TREE_CODE (value) == STRING_CST)
6837 /* We need to split the char/wchar array into individual
6838 characters, so that we don't have to special case it
6840 set_nonincremental_init_from_string (value, braced_init_obstack);
6845 if (constructor_type != error_mark_node)
6846 warning_init (0, "braces around scalar initializer");
6847 constructor_fields = constructor_type;
6848 constructor_unfilled_fields = constructor_type;
6852 /* At the end of an implicit or explicit brace level,
6853 finish up that level of constructor. If a single expression
6854 with redundant braces initialized that level, return the
6855 c_expr structure for that expression. Otherwise, the original_code
6856 element is set to ERROR_MARK.
6857 If we were outputting the elements as they are read, return 0 as the value
6858 from inner levels (process_init_element ignores that),
6859 but return error_mark_node as the value from the outermost level
6860 (that's what we want to put in DECL_INITIAL).
6861 Otherwise, return a CONSTRUCTOR expression as the value. */
6864 pop_init_level (int implicit, struct obstack * braced_init_obstack)
6866 struct constructor_stack *p;
6869 ret.original_code = ERROR_MARK;
6870 ret.original_type = NULL;
6874 /* When we come to an explicit close brace,
6875 pop any inner levels that didn't have explicit braces. */
6876 while (constructor_stack->implicit)
6878 process_init_element (pop_init_level (1, braced_init_obstack),
6879 true, braced_init_obstack);
6881 gcc_assert (!constructor_range_stack);
6884 /* Now output all pending elements. */
6885 constructor_incremental = 1;
6886 output_pending_init_elements (1, braced_init_obstack);
6888 p = constructor_stack;
6890 /* Error for initializing a flexible array member, or a zero-length
6891 array member in an inappropriate context. */
6892 if (constructor_type && constructor_fields
6893 && TREE_CODE (constructor_type) == ARRAY_TYPE
6894 && TYPE_DOMAIN (constructor_type)
6895 && !TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type)))
6897 /* Silently discard empty initializations. The parser will
6898 already have pedwarned for empty brackets. */
6899 if (integer_zerop (constructor_unfilled_index))
6900 constructor_type = NULL_TREE;
6903 gcc_assert (!TYPE_SIZE (constructor_type));
6905 if (constructor_depth > 2)
6906 error_init ("initialization of flexible array member in a nested context");
6908 pedwarn_init (input_location, OPT_pedantic,
6909 "initialization of a flexible array member");
6911 /* We have already issued an error message for the existence
6912 of a flexible array member not at the end of the structure.
6913 Discard the initializer so that we do not die later. */
6914 if (DECL_CHAIN (constructor_fields) != NULL_TREE)
6915 constructor_type = NULL_TREE;
6919 /* Warn when some struct elements are implicitly initialized to zero. */
6920 if (warn_missing_field_initializers
6922 && TREE_CODE (constructor_type) == RECORD_TYPE
6923 && constructor_unfilled_fields)
6925 bool constructor_zeroinit =
6926 (VEC_length (constructor_elt, constructor_elements) == 1
6928 (VEC_index (constructor_elt, constructor_elements, 0)->value));
6930 /* Do not warn for flexible array members or zero-length arrays. */
6931 while (constructor_unfilled_fields
6932 && (!DECL_SIZE (constructor_unfilled_fields)
6933 || integer_zerop (DECL_SIZE (constructor_unfilled_fields))))
6934 constructor_unfilled_fields = DECL_CHAIN (constructor_unfilled_fields);
6936 if (constructor_unfilled_fields
6937 /* Do not warn if this level of the initializer uses member
6938 designators; it is likely to be deliberate. */
6939 && !constructor_designated
6940 /* Do not warn about initializing with ` = {0}'. */
6941 && !constructor_zeroinit)
6943 push_member_name (constructor_unfilled_fields);
6944 warning_init (OPT_Wmissing_field_initializers,
6945 "missing initializer");
6946 RESTORE_SPELLING_DEPTH (constructor_depth);
6950 /* Pad out the end of the structure. */
6951 if (p->replacement_value.value)
6952 /* If this closes a superfluous brace pair,
6953 just pass out the element between them. */
6954 ret = p->replacement_value;
6955 else if (constructor_type == 0)
6957 else if (TREE_CODE (constructor_type) != RECORD_TYPE
6958 && TREE_CODE (constructor_type) != UNION_TYPE
6959 && TREE_CODE (constructor_type) != ARRAY_TYPE
6960 && TREE_CODE (constructor_type) != VECTOR_TYPE)
6962 /* A nonincremental scalar initializer--just return
6963 the element, after verifying there is just one. */
6964 if (VEC_empty (constructor_elt,constructor_elements))
6966 if (!constructor_erroneous)
6967 error_init ("empty scalar initializer");
6968 ret.value = error_mark_node;
6970 else if (VEC_length (constructor_elt,constructor_elements) != 1)
6972 error_init ("extra elements in scalar initializer");
6973 ret.value = VEC_index (constructor_elt,constructor_elements,0)->value;
6976 ret.value = VEC_index (constructor_elt,constructor_elements,0)->value;
6980 if (constructor_erroneous)
6981 ret.value = error_mark_node;
6984 ret.value = build_constructor (constructor_type,
6985 constructor_elements);
6986 if (constructor_constant)
6987 TREE_CONSTANT (ret.value) = 1;
6988 if (constructor_constant && constructor_simple)
6989 TREE_STATIC (ret.value) = 1;
6990 if (constructor_nonconst)
6991 CONSTRUCTOR_NON_CONST (ret.value) = 1;
6995 if (ret.value && TREE_CODE (ret.value) != CONSTRUCTOR)
6997 if (constructor_nonconst)
6998 ret.original_code = C_MAYBE_CONST_EXPR;
6999 else if (ret.original_code == C_MAYBE_CONST_EXPR)
7000 ret.original_code = ERROR_MARK;
7003 constructor_type = p->type;
7004 constructor_fields = p->fields;
7005 constructor_index = p->index;
7006 constructor_max_index = p->max_index;
7007 constructor_unfilled_index = p->unfilled_index;
7008 constructor_unfilled_fields = p->unfilled_fields;
7009 constructor_bit_index = p->bit_index;
7010 constructor_elements = p->elements;
7011 constructor_constant = p->constant;
7012 constructor_simple = p->simple;
7013 constructor_nonconst = p->nonconst;
7014 constructor_erroneous = p->erroneous;
7015 constructor_incremental = p->incremental;
7016 constructor_designated = p->designated;
7017 constructor_pending_elts = p->pending_elts;
7018 constructor_depth = p->depth;
7020 constructor_range_stack = p->range_stack;
7021 RESTORE_SPELLING_DEPTH (constructor_depth);
7023 constructor_stack = p->next;
7026 if (ret.value == 0 && constructor_stack == 0)
7027 ret.value = error_mark_node;
7031 /* Common handling for both array range and field name designators.
7032 ARRAY argument is nonzero for array ranges. Returns zero for success. */
7035 set_designator (int array, struct obstack * braced_init_obstack)
7038 enum tree_code subcode;
7040 /* Don't die if an entire brace-pair level is superfluous
7041 in the containing level. */
7042 if (constructor_type == 0)
7045 /* If there were errors in this designator list already, bail out
7047 if (designator_erroneous)
7050 if (!designator_depth)
7052 gcc_assert (!constructor_range_stack);
7054 /* Designator list starts at the level of closest explicit
7056 while (constructor_stack->implicit)
7058 process_init_element (pop_init_level (1, braced_init_obstack),
7059 true, braced_init_obstack);
7061 constructor_designated = 1;
7065 switch (TREE_CODE (constructor_type))
7069 subtype = TREE_TYPE (constructor_fields);
7070 if (subtype != error_mark_node)
7071 subtype = TYPE_MAIN_VARIANT (subtype);
7074 subtype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
7080 subcode = TREE_CODE (subtype);
7081 if (array && subcode != ARRAY_TYPE)
7083 error_init ("array index in non-array initializer");
7086 else if (!array && subcode != RECORD_TYPE && subcode != UNION_TYPE)
7088 error_init ("field name not in record or union initializer");
7092 constructor_designated = 1;
7093 push_init_level (2, braced_init_obstack);
7097 /* If there are range designators in designator list, push a new designator
7098 to constructor_range_stack. RANGE_END is end of such stack range or
7099 NULL_TREE if there is no range designator at this level. */
7102 push_range_stack (tree range_end, struct obstack * braced_init_obstack)
7104 struct constructor_range_stack *p;
7106 p = (struct constructor_range_stack *)
7107 obstack_alloc (braced_init_obstack,
7108 sizeof (struct constructor_range_stack));
7109 p->prev = constructor_range_stack;
7111 p->fields = constructor_fields;
7112 p->range_start = constructor_index;
7113 p->index = constructor_index;
7114 p->stack = constructor_stack;
7115 p->range_end = range_end;
7116 if (constructor_range_stack)
7117 constructor_range_stack->next = p;
7118 constructor_range_stack = p;
7121 /* Within an array initializer, specify the next index to be initialized.
7122 FIRST is that index. If LAST is nonzero, then initialize a range
7123 of indices, running from FIRST through LAST. */
7126 set_init_index (tree first, tree last,
7127 struct obstack * braced_init_obstack)
7129 if (set_designator (1, braced_init_obstack))
7132 designator_erroneous = 1;
7134 if (!INTEGRAL_TYPE_P (TREE_TYPE (first))
7135 || (last && !INTEGRAL_TYPE_P (TREE_TYPE (last))))
7137 error_init ("array index in initializer not of integer type");
7141 if (TREE_CODE (first) != INTEGER_CST)
7143 first = c_fully_fold (first, false, NULL);
7144 if (TREE_CODE (first) == INTEGER_CST)
7145 pedwarn_init (input_location, OPT_pedantic,
7146 "array index in initializer is not "
7147 "an integer constant expression");
7150 if (last && TREE_CODE (last) != INTEGER_CST)
7152 last = c_fully_fold (last, false, NULL);
7153 if (TREE_CODE (last) == INTEGER_CST)
7154 pedwarn_init (input_location, OPT_pedantic,
7155 "array index in initializer is not "
7156 "an integer constant expression");
7159 if (TREE_CODE (first) != INTEGER_CST)
7160 error_init ("nonconstant array index in initializer");
7161 else if (last != 0 && TREE_CODE (last) != INTEGER_CST)
7162 error_init ("nonconstant array index in initializer");
7163 else if (TREE_CODE (constructor_type) != ARRAY_TYPE)
7164 error_init ("array index in non-array initializer");
7165 else if (tree_int_cst_sgn (first) == -1)
7166 error_init ("array index in initializer exceeds array bounds");
7167 else if (constructor_max_index
7168 && tree_int_cst_lt (constructor_max_index, first))
7169 error_init ("array index in initializer exceeds array bounds");
7172 constant_expression_warning (first);
7174 constant_expression_warning (last);
7175 constructor_index = convert (bitsizetype, first);
7179 if (tree_int_cst_equal (first, last))
7181 else if (tree_int_cst_lt (last, first))
7183 error_init ("empty index range in initializer");
7188 last = convert (bitsizetype, last);
7189 if (constructor_max_index != 0
7190 && tree_int_cst_lt (constructor_max_index, last))
7192 error_init ("array index range in initializer exceeds array bounds");
7199 designator_erroneous = 0;
7200 if (constructor_range_stack || last)
7201 push_range_stack (last, braced_init_obstack);
7205 /* Within a struct initializer, specify the next field to be initialized. */
7208 set_init_label (tree fieldname, struct obstack * braced_init_obstack)
7212 if (set_designator (0, braced_init_obstack))
7215 designator_erroneous = 1;
7217 if (TREE_CODE (constructor_type) != RECORD_TYPE
7218 && TREE_CODE (constructor_type) != UNION_TYPE)
7220 error_init ("field name not in record or union initializer");
7224 field = lookup_field (constructor_type, fieldname);
7227 error ("unknown field %qE specified in initializer", fieldname);
7231 constructor_fields = TREE_VALUE (field);
7233 designator_erroneous = 0;
7234 if (constructor_range_stack)
7235 push_range_stack (NULL_TREE, braced_init_obstack);
7236 field = TREE_CHAIN (field);
7239 if (set_designator (0, braced_init_obstack))
7243 while (field != NULL_TREE);
7246 /* Add a new initializer to the tree of pending initializers. PURPOSE
7247 identifies the initializer, either array index or field in a structure.
7248 VALUE is the value of that index or field. If ORIGTYPE is not
7249 NULL_TREE, it is the original type of VALUE.
7251 IMPLICIT is true if value comes from pop_init_level (1),
7252 the new initializer has been merged with the existing one
7253 and thus no warnings should be emitted about overriding an
7254 existing initializer. */
7257 add_pending_init (tree purpose, tree value, tree origtype, bool implicit,
7258 struct obstack * braced_init_obstack)
7260 struct init_node *p, **q, *r;
7262 q = &constructor_pending_elts;
7265 if (TREE_CODE (constructor_type) == ARRAY_TYPE)
7270 if (tree_int_cst_lt (purpose, p->purpose))
7272 else if (tree_int_cst_lt (p->purpose, purpose))
7278 if (TREE_SIDE_EFFECTS (p->value))
7279 warning_init (0, "initialized field with side-effects overwritten");
7280 else if (warn_override_init)
7281 warning_init (OPT_Woverride_init, "initialized field overwritten");
7284 p->origtype = origtype;
7293 bitpos = bit_position (purpose);
7297 if (tree_int_cst_lt (bitpos, bit_position (p->purpose)))
7299 else if (p->purpose != purpose)
7305 if (TREE_SIDE_EFFECTS (p->value))
7306 warning_init (0, "initialized field with side-effects overwritten");
7307 else if (warn_override_init)
7308 warning_init (OPT_Woverride_init, "initialized field overwritten");
7311 p->origtype = origtype;
7317 r = (struct init_node *) obstack_alloc (braced_init_obstack,
7318 sizeof (struct init_node));
7319 r->purpose = purpose;
7321 r->origtype = origtype;
7331 struct init_node *s;
7335 if (p->balance == 0)
7337 else if (p->balance < 0)
7344 p->left->parent = p;
7361 constructor_pending_elts = r;
7366 struct init_node *t = r->right;
7370 r->right->parent = r;
7375 p->left->parent = p;
7378 p->balance = t->balance < 0;
7379 r->balance = -(t->balance > 0);
7394 constructor_pending_elts = t;
7400 /* p->balance == +1; growth of left side balances the node. */
7405 else /* r == p->right */
7407 if (p->balance == 0)
7408 /* Growth propagation from right side. */
7410 else if (p->balance > 0)
7417 p->right->parent = p;
7434 constructor_pending_elts = r;
7436 else /* r->balance == -1 */
7439 struct init_node *t = r->left;
7443 r->left->parent = r;
7448 p->right->parent = p;
7451 r->balance = (t->balance < 0);
7452 p->balance = -(t->balance > 0);
7467 constructor_pending_elts = t;
7473 /* p->balance == -1; growth of right side balances the node. */
7484 /* Build AVL tree from a sorted chain. */
7487 set_nonincremental_init (struct obstack * braced_init_obstack)
7489 unsigned HOST_WIDE_INT ix;
7492 if (TREE_CODE (constructor_type) != RECORD_TYPE
7493 && TREE_CODE (constructor_type) != ARRAY_TYPE)
7496 FOR_EACH_CONSTRUCTOR_ELT (constructor_elements, ix, index, value)
7498 add_pending_init (index, value, NULL_TREE, false,
7499 braced_init_obstack);
7501 constructor_elements = 0;
7502 if (TREE_CODE (constructor_type) == RECORD_TYPE)
7504 constructor_unfilled_fields = TYPE_FIELDS (constructor_type);
7505 /* Skip any nameless bit fields at the beginning. */
7506 while (constructor_unfilled_fields != 0
7507 && DECL_C_BIT_FIELD (constructor_unfilled_fields)
7508 && DECL_NAME (constructor_unfilled_fields) == 0)
7509 constructor_unfilled_fields = TREE_CHAIN (constructor_unfilled_fields);
7512 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
7514 if (TYPE_DOMAIN (constructor_type))
7515 constructor_unfilled_index
7516 = convert (bitsizetype,
7517 TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
7519 constructor_unfilled_index = bitsize_zero_node;
7521 constructor_incremental = 0;
7524 /* Build AVL tree from a string constant. */
7527 set_nonincremental_init_from_string (tree str,
7528 struct obstack * braced_init_obstack)
7530 tree value, purpose, type;
7531 HOST_WIDE_INT val[2];
7532 const char *p, *end;
7533 int byte, wchar_bytes, charwidth, bitpos;
7535 gcc_assert (TREE_CODE (constructor_type) == ARRAY_TYPE);
7537 wchar_bytes = TYPE_PRECISION (TREE_TYPE (TREE_TYPE (str))) / BITS_PER_UNIT;
7538 charwidth = TYPE_PRECISION (char_type_node);
7539 type = TREE_TYPE (constructor_type);
7540 p = TREE_STRING_POINTER (str);
7541 end = p + TREE_STRING_LENGTH (str);
7543 for (purpose = bitsize_zero_node;
7544 p < end && !tree_int_cst_lt (constructor_max_index, purpose);
7545 purpose = size_binop (PLUS_EXPR, purpose, bitsize_one_node))
7547 if (wchar_bytes == 1)
7549 val[1] = (unsigned char) *p++;
7556 for (byte = 0; byte < wchar_bytes; byte++)
7558 if (BYTES_BIG_ENDIAN)
7559 bitpos = (wchar_bytes - byte - 1) * charwidth;
7561 bitpos = byte * charwidth;
7562 val[bitpos < HOST_BITS_PER_WIDE_INT]
7563 |= ((unsigned HOST_WIDE_INT) ((unsigned char) *p++))
7564 << (bitpos % HOST_BITS_PER_WIDE_INT);
7568 if (!TYPE_UNSIGNED (type))
7570 bitpos = ((wchar_bytes - 1) * charwidth) + HOST_BITS_PER_CHAR;
7571 if (bitpos < HOST_BITS_PER_WIDE_INT)
7573 if (val[1] & (((HOST_WIDE_INT) 1) << (bitpos - 1)))
7575 val[1] |= ((HOST_WIDE_INT) -1) << bitpos;
7579 else if (bitpos == HOST_BITS_PER_WIDE_INT)
7584 else if (val[0] & (((HOST_WIDE_INT) 1)
7585 << (bitpos - 1 - HOST_BITS_PER_WIDE_INT)))
7586 val[0] |= ((HOST_WIDE_INT) -1)
7587 << (bitpos - HOST_BITS_PER_WIDE_INT);
7590 value = build_int_cst_wide (type, val[1], val[0]);
7591 add_pending_init (purpose, value, NULL_TREE, false,
7592 braced_init_obstack);
7595 constructor_incremental = 0;
7598 /* Return value of FIELD in pending initializer or zero if the field was
7599 not initialized yet. */
7602 find_init_member (tree field, struct obstack * braced_init_obstack)
7604 struct init_node *p;
7606 if (TREE_CODE (constructor_type) == ARRAY_TYPE)
7608 if (constructor_incremental
7609 && tree_int_cst_lt (field, constructor_unfilled_index))
7610 set_nonincremental_init (braced_init_obstack);
7612 p = constructor_pending_elts;
7615 if (tree_int_cst_lt (field, p->purpose))
7617 else if (tree_int_cst_lt (p->purpose, field))
7623 else if (TREE_CODE (constructor_type) == RECORD_TYPE)
7625 tree bitpos = bit_position (field);
7627 if (constructor_incremental
7628 && (!constructor_unfilled_fields
7629 || tree_int_cst_lt (bitpos,
7630 bit_position (constructor_unfilled_fields))))
7631 set_nonincremental_init (braced_init_obstack);
7633 p = constructor_pending_elts;
7636 if (field == p->purpose)
7638 else if (tree_int_cst_lt (bitpos, bit_position (p->purpose)))
7644 else if (TREE_CODE (constructor_type) == UNION_TYPE)
7646 if (!VEC_empty (constructor_elt, constructor_elements)
7647 && (VEC_last (constructor_elt, constructor_elements)->index
7649 return VEC_last (constructor_elt, constructor_elements)->value;
7654 /* "Output" the next constructor element.
7655 At top level, really output it to assembler code now.
7656 Otherwise, collect it in a list from which we will make a CONSTRUCTOR.
7657 If ORIGTYPE is not NULL_TREE, it is the original type of VALUE.
7658 TYPE is the data type that the containing data type wants here.
7659 FIELD is the field (a FIELD_DECL) or the index that this element fills.
7660 If VALUE is a string constant, STRICT_STRING is true if it is
7661 unparenthesized or we should not warn here for it being parenthesized.
7662 For other types of VALUE, STRICT_STRING is not used.
7664 PENDING if non-nil means output pending elements that belong
7665 right after this element. (PENDING is normally 1;
7666 it is 0 while outputting pending elements, to avoid recursion.)
7668 IMPLICIT is true if value comes from pop_init_level (1),
7669 the new initializer has been merged with the existing one
7670 and thus no warnings should be emitted about overriding an
7671 existing initializer. */
7674 output_init_element (tree value, tree origtype, bool strict_string, tree type,
7675 tree field, int pending, bool implicit,
7676 struct obstack * braced_init_obstack)
7678 tree semantic_type = NULL_TREE;
7679 constructor_elt *celt;
7680 bool maybe_const = true;
7683 if (type == error_mark_node || value == error_mark_node)
7685 constructor_erroneous = 1;
7688 if (TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE
7689 && (TREE_CODE (value) == STRING_CST
7690 || TREE_CODE (value) == COMPOUND_LITERAL_EXPR)
7691 && !(TREE_CODE (value) == STRING_CST
7692 && TREE_CODE (type) == ARRAY_TYPE
7693 && INTEGRAL_TYPE_P (TREE_TYPE (type)))
7694 && !comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (value)),
7695 TYPE_MAIN_VARIANT (type)))
7696 value = array_to_pointer_conversion (input_location, value);
7698 if (TREE_CODE (value) == COMPOUND_LITERAL_EXPR
7699 && require_constant_value && !flag_isoc99 && pending)
7701 /* As an extension, allow initializing objects with static storage
7702 duration with compound literals (which are then treated just as
7703 the brace enclosed list they contain). */
7704 tree decl = COMPOUND_LITERAL_EXPR_DECL (value);
7705 value = DECL_INITIAL (decl);
7708 npc = null_pointer_constant_p (value);
7709 if (TREE_CODE (value) == EXCESS_PRECISION_EXPR)
7711 semantic_type = TREE_TYPE (value);
7712 value = TREE_OPERAND (value, 0);
7714 value = c_fully_fold (value, require_constant_value, &maybe_const);
7716 if (value == error_mark_node)
7717 constructor_erroneous = 1;
7718 else if (!TREE_CONSTANT (value))
7719 constructor_constant = 0;
7720 else if (!initializer_constant_valid_p (value, TREE_TYPE (value))
7721 || ((TREE_CODE (constructor_type) == RECORD_TYPE
7722 || TREE_CODE (constructor_type) == UNION_TYPE)
7723 && DECL_C_BIT_FIELD (field)
7724 && TREE_CODE (value) != INTEGER_CST))
7725 constructor_simple = 0;
7727 constructor_nonconst = 1;
7729 if (!initializer_constant_valid_p (value, TREE_TYPE (value)))
7731 if (require_constant_value)
7733 error_init ("initializer element is not constant");
7734 value = error_mark_node;
7736 else if (require_constant_elements)
7737 pedwarn (input_location, 0,
7738 "initializer element is not computable at load time");
7740 else if (!maybe_const
7741 && (require_constant_value || require_constant_elements))
7742 pedwarn_init (input_location, 0,
7743 "initializer element is not a constant expression");
7745 /* Issue -Wc++-compat warnings about initializing a bitfield with
7748 && field != NULL_TREE
7749 && TREE_CODE (field) == FIELD_DECL
7750 && DECL_BIT_FIELD_TYPE (field) != NULL_TREE
7751 && (TYPE_MAIN_VARIANT (DECL_BIT_FIELD_TYPE (field))
7752 != TYPE_MAIN_VARIANT (type))
7753 && TREE_CODE (DECL_BIT_FIELD_TYPE (field)) == ENUMERAL_TYPE)
7755 tree checktype = origtype != NULL_TREE ? origtype : TREE_TYPE (value);
7756 if (checktype != error_mark_node
7757 && (TYPE_MAIN_VARIANT (checktype)
7758 != TYPE_MAIN_VARIANT (DECL_BIT_FIELD_TYPE (field))))
7759 warning_init (OPT_Wc___compat,
7760 "enum conversion in initialization is invalid in C++");
7763 /* If this field is empty (and not at the end of structure),
7764 don't do anything other than checking the initializer. */
7766 && (TREE_TYPE (field) == error_mark_node
7767 || (COMPLETE_TYPE_P (TREE_TYPE (field))
7768 && integer_zerop (TYPE_SIZE (TREE_TYPE (field)))
7769 && (TREE_CODE (constructor_type) == ARRAY_TYPE
7770 || DECL_CHAIN (field)))))
7774 value = build1 (EXCESS_PRECISION_EXPR, semantic_type, value);
7775 value = digest_init (input_location, type, value, origtype, npc,
7776 strict_string, require_constant_value);
7777 if (value == error_mark_node)
7779 constructor_erroneous = 1;
7782 if (require_constant_value || require_constant_elements)
7783 constant_expression_warning (value);
7785 /* If this element doesn't come next in sequence,
7786 put it on constructor_pending_elts. */
7787 if (TREE_CODE (constructor_type) == ARRAY_TYPE
7788 && (!constructor_incremental
7789 || !tree_int_cst_equal (field, constructor_unfilled_index)))
7791 if (constructor_incremental
7792 && tree_int_cst_lt (field, constructor_unfilled_index))
7793 set_nonincremental_init (braced_init_obstack);
7795 add_pending_init (field, value, origtype, implicit,
7796 braced_init_obstack);
7799 else if (TREE_CODE (constructor_type) == RECORD_TYPE
7800 && (!constructor_incremental
7801 || field != constructor_unfilled_fields))
7803 /* We do this for records but not for unions. In a union,
7804 no matter which field is specified, it can be initialized
7805 right away since it starts at the beginning of the union. */
7806 if (constructor_incremental)
7808 if (!constructor_unfilled_fields)
7809 set_nonincremental_init (braced_init_obstack);
7812 tree bitpos, unfillpos;
7814 bitpos = bit_position (field);
7815 unfillpos = bit_position (constructor_unfilled_fields);
7817 if (tree_int_cst_lt (bitpos, unfillpos))
7818 set_nonincremental_init (braced_init_obstack);
7822 add_pending_init (field, value, origtype, implicit,
7823 braced_init_obstack);
7826 else if (TREE_CODE (constructor_type) == UNION_TYPE
7827 && !VEC_empty (constructor_elt, constructor_elements))
7831 if (TREE_SIDE_EFFECTS (VEC_last (constructor_elt,
7832 constructor_elements)->value))
7834 "initialized field with side-effects overwritten");
7835 else if (warn_override_init)
7836 warning_init (OPT_Woverride_init, "initialized field overwritten");
7839 /* We can have just one union field set. */
7840 constructor_elements = 0;
7843 /* Otherwise, output this element either to
7844 constructor_elements or to the assembler file. */
7846 celt = VEC_safe_push (constructor_elt, gc, constructor_elements, NULL);
7847 celt->index = field;
7848 celt->value = value;
7850 /* Advance the variable that indicates sequential elements output. */
7851 if (TREE_CODE (constructor_type) == ARRAY_TYPE)
7852 constructor_unfilled_index
7853 = size_binop_loc (input_location, PLUS_EXPR, constructor_unfilled_index,
7855 else if (TREE_CODE (constructor_type) == RECORD_TYPE)
7857 constructor_unfilled_fields
7858 = DECL_CHAIN (constructor_unfilled_fields);
7860 /* Skip any nameless bit fields. */
7861 while (constructor_unfilled_fields != 0
7862 && DECL_C_BIT_FIELD (constructor_unfilled_fields)
7863 && DECL_NAME (constructor_unfilled_fields) == 0)
7864 constructor_unfilled_fields =
7865 DECL_CHAIN (constructor_unfilled_fields);
7867 else if (TREE_CODE (constructor_type) == UNION_TYPE)
7868 constructor_unfilled_fields = 0;
7870 /* Now output any pending elements which have become next. */
7872 output_pending_init_elements (0, braced_init_obstack);
7875 /* Output any pending elements which have become next.
7876 As we output elements, constructor_unfilled_{fields,index}
7877 advances, which may cause other elements to become next;
7878 if so, they too are output.
7880 If ALL is 0, we return when there are
7881 no more pending elements to output now.
7883 If ALL is 1, we output space as necessary so that
7884 we can output all the pending elements. */
7886 output_pending_init_elements (int all, struct obstack * braced_init_obstack)
7888 struct init_node *elt = constructor_pending_elts;
7893 /* Look through the whole pending tree.
7894 If we find an element that should be output now,
7895 output it. Otherwise, set NEXT to the element
7896 that comes first among those still pending. */
7901 if (TREE_CODE (constructor_type) == ARRAY_TYPE)
7903 if (tree_int_cst_equal (elt->purpose,
7904 constructor_unfilled_index))
7905 output_init_element (elt->value, elt->origtype, true,
7906 TREE_TYPE (constructor_type),
7907 constructor_unfilled_index, 0, false,
7908 braced_init_obstack);
7909 else if (tree_int_cst_lt (constructor_unfilled_index,
7912 /* Advance to the next smaller node. */
7917 /* We have reached the smallest node bigger than the
7918 current unfilled index. Fill the space first. */
7919 next = elt->purpose;
7925 /* Advance to the next bigger node. */
7930 /* We have reached the biggest node in a subtree. Find
7931 the parent of it, which is the next bigger node. */
7932 while (elt->parent && elt->parent->right == elt)
7935 if (elt && tree_int_cst_lt (constructor_unfilled_index,
7938 next = elt->purpose;
7944 else if (TREE_CODE (constructor_type) == RECORD_TYPE
7945 || TREE_CODE (constructor_type) == UNION_TYPE)
7947 tree ctor_unfilled_bitpos, elt_bitpos;
7949 /* If the current record is complete we are done. */
7950 if (constructor_unfilled_fields == 0)
7953 ctor_unfilled_bitpos = bit_position (constructor_unfilled_fields);
7954 elt_bitpos = bit_position (elt->purpose);
7955 /* We can't compare fields here because there might be empty
7956 fields in between. */
7957 if (tree_int_cst_equal (elt_bitpos, ctor_unfilled_bitpos))
7959 constructor_unfilled_fields = elt->purpose;
7960 output_init_element (elt->value, elt->origtype, true,
7961 TREE_TYPE (elt->purpose),
7962 elt->purpose, 0, false,
7963 braced_init_obstack);
7965 else if (tree_int_cst_lt (ctor_unfilled_bitpos, elt_bitpos))
7967 /* Advance to the next smaller node. */
7972 /* We have reached the smallest node bigger than the
7973 current unfilled field. Fill the space first. */
7974 next = elt->purpose;
7980 /* Advance to the next bigger node. */
7985 /* We have reached the biggest node in a subtree. Find
7986 the parent of it, which is the next bigger node. */
7987 while (elt->parent && elt->parent->right == elt)
7991 && (tree_int_cst_lt (ctor_unfilled_bitpos,
7992 bit_position (elt->purpose))))
7994 next = elt->purpose;
8002 /* Ordinarily return, but not if we want to output all
8003 and there are elements left. */
8004 if (!(all && next != 0))
8007 /* If it's not incremental, just skip over the gap, so that after
8008 jumping to retry we will output the next successive element. */
8009 if (TREE_CODE (constructor_type) == RECORD_TYPE
8010 || TREE_CODE (constructor_type) == UNION_TYPE)
8011 constructor_unfilled_fields = next;
8012 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
8013 constructor_unfilled_index = next;
8015 /* ELT now points to the node in the pending tree with the next
8016 initializer to output. */
8020 /* Add one non-braced element to the current constructor level.
8021 This adjusts the current position within the constructor's type.
8022 This may also start or terminate implicit levels
8023 to handle a partly-braced initializer.
8025 Once this has found the correct level for the new element,
8026 it calls output_init_element.
8028 IMPLICIT is true if value comes from pop_init_level (1),
8029 the new initializer has been merged with the existing one
8030 and thus no warnings should be emitted about overriding an
8031 existing initializer. */
8034 process_init_element (struct c_expr value, bool implicit,
8035 struct obstack * braced_init_obstack)
8037 tree orig_value = value.value;
8038 int string_flag = orig_value != 0 && TREE_CODE (orig_value) == STRING_CST;
8039 bool strict_string = value.original_code == STRING_CST;
8041 designator_depth = 0;
8042 designator_erroneous = 0;
8044 /* Handle superfluous braces around string cst as in
8045 char x[] = {"foo"}; */
8048 && TREE_CODE (constructor_type) == ARRAY_TYPE
8049 && INTEGRAL_TYPE_P (TREE_TYPE (constructor_type))
8050 && integer_zerop (constructor_unfilled_index))
8052 if (constructor_stack->replacement_value.value)
8053 error_init ("excess elements in char array initializer");
8054 constructor_stack->replacement_value = value;
8058 if (constructor_stack->replacement_value.value != 0)
8060 error_init ("excess elements in struct initializer");
8064 /* Ignore elements of a brace group if it is entirely superfluous
8065 and has already been diagnosed. */
8066 if (constructor_type == 0)
8069 /* If we've exhausted any levels that didn't have braces,
8071 while (constructor_stack->implicit)
8073 if ((TREE_CODE (constructor_type) == RECORD_TYPE
8074 || TREE_CODE (constructor_type) == UNION_TYPE)
8075 && constructor_fields == 0)
8076 process_init_element (pop_init_level (1, braced_init_obstack),
8077 true, braced_init_obstack);
8078 else if ((TREE_CODE (constructor_type) == ARRAY_TYPE
8079 || TREE_CODE (constructor_type) == VECTOR_TYPE)
8080 && (constructor_max_index == 0
8081 || tree_int_cst_lt (constructor_max_index,
8082 constructor_index)))
8083 process_init_element (pop_init_level (1, braced_init_obstack),
8084 true, braced_init_obstack);
8089 /* In the case of [LO ... HI] = VALUE, only evaluate VALUE once. */
8090 if (constructor_range_stack)
8092 /* If value is a compound literal and we'll be just using its
8093 content, don't put it into a SAVE_EXPR. */
8094 if (TREE_CODE (value.value) != COMPOUND_LITERAL_EXPR
8095 || !require_constant_value
8098 tree semantic_type = NULL_TREE;
8099 if (TREE_CODE (value.value) == EXCESS_PRECISION_EXPR)
8101 semantic_type = TREE_TYPE (value.value);
8102 value.value = TREE_OPERAND (value.value, 0);
8104 value.value = c_save_expr (value.value);
8106 value.value = build1 (EXCESS_PRECISION_EXPR, semantic_type,
8113 if (TREE_CODE (constructor_type) == RECORD_TYPE)
8116 enum tree_code fieldcode;
8118 if (constructor_fields == 0)
8120 pedwarn_init (input_location, 0,
8121 "excess elements in struct initializer");
8125 fieldtype = TREE_TYPE (constructor_fields);
8126 if (fieldtype != error_mark_node)
8127 fieldtype = TYPE_MAIN_VARIANT (fieldtype);
8128 fieldcode = TREE_CODE (fieldtype);
8130 /* Error for non-static initialization of a flexible array member. */
8131 if (fieldcode == ARRAY_TYPE
8132 && !require_constant_value
8133 && TYPE_SIZE (fieldtype) == NULL_TREE
8134 && DECL_CHAIN (constructor_fields) == NULL_TREE)
8136 error_init ("non-static initialization of a flexible array member");
8140 /* Accept a string constant to initialize a subarray. */
8141 if (value.value != 0
8142 && fieldcode == ARRAY_TYPE
8143 && INTEGRAL_TYPE_P (TREE_TYPE (fieldtype))
8145 value.value = orig_value;
8146 /* Otherwise, if we have come to a subaggregate,
8147 and we don't have an element of its type, push into it. */
8148 else if (value.value != 0
8149 && value.value != error_mark_node
8150 && TYPE_MAIN_VARIANT (TREE_TYPE (value.value)) != fieldtype
8151 && (fieldcode == RECORD_TYPE || fieldcode == ARRAY_TYPE
8152 || fieldcode == UNION_TYPE || fieldcode == VECTOR_TYPE))
8154 push_init_level (1, braced_init_obstack);
8160 push_member_name (constructor_fields);
8161 output_init_element (value.value, value.original_type,
8162 strict_string, fieldtype,
8163 constructor_fields, 1, implicit,
8164 braced_init_obstack);
8165 RESTORE_SPELLING_DEPTH (constructor_depth);
8168 /* Do the bookkeeping for an element that was
8169 directly output as a constructor. */
8171 /* For a record, keep track of end position of last field. */
8172 if (DECL_SIZE (constructor_fields))
8173 constructor_bit_index
8174 = size_binop_loc (input_location, PLUS_EXPR,
8175 bit_position (constructor_fields),
8176 DECL_SIZE (constructor_fields));
8178 /* If the current field was the first one not yet written out,
8179 it isn't now, so update. */
8180 if (constructor_unfilled_fields == constructor_fields)
8182 constructor_unfilled_fields = DECL_CHAIN (constructor_fields);
8183 /* Skip any nameless bit fields. */
8184 while (constructor_unfilled_fields != 0
8185 && DECL_C_BIT_FIELD (constructor_unfilled_fields)
8186 && DECL_NAME (constructor_unfilled_fields) == 0)
8187 constructor_unfilled_fields =
8188 DECL_CHAIN (constructor_unfilled_fields);
8192 constructor_fields = DECL_CHAIN (constructor_fields);
8193 /* Skip any nameless bit fields at the beginning. */
8194 while (constructor_fields != 0
8195 && DECL_C_BIT_FIELD (constructor_fields)
8196 && DECL_NAME (constructor_fields) == 0)
8197 constructor_fields = DECL_CHAIN (constructor_fields);
8199 else if (TREE_CODE (constructor_type) == UNION_TYPE)
8202 enum tree_code fieldcode;
8204 if (constructor_fields == 0)
8206 pedwarn_init (input_location, 0,
8207 "excess elements in union initializer");
8211 fieldtype = TREE_TYPE (constructor_fields);
8212 if (fieldtype != error_mark_node)
8213 fieldtype = TYPE_MAIN_VARIANT (fieldtype);
8214 fieldcode = TREE_CODE (fieldtype);
8216 /* Warn that traditional C rejects initialization of unions.
8217 We skip the warning if the value is zero. This is done
8218 under the assumption that the zero initializer in user
8219 code appears conditioned on e.g. __STDC__ to avoid
8220 "missing initializer" warnings and relies on default
8221 initialization to zero in the traditional C case.
8222 We also skip the warning if the initializer is designated,
8223 again on the assumption that this must be conditional on
8224 __STDC__ anyway (and we've already complained about the
8225 member-designator already). */
8226 if (!in_system_header && !constructor_designated
8227 && !(value.value && (integer_zerop (value.value)
8228 || real_zerop (value.value))))
8229 warning (OPT_Wtraditional, "traditional C rejects initialization "
8232 /* Accept a string constant to initialize a subarray. */
8233 if (value.value != 0
8234 && fieldcode == ARRAY_TYPE
8235 && INTEGRAL_TYPE_P (TREE_TYPE (fieldtype))
8237 value.value = orig_value;
8238 /* Otherwise, if we have come to a subaggregate,
8239 and we don't have an element of its type, push into it. */
8240 else if (value.value != 0
8241 && value.value != error_mark_node
8242 && TYPE_MAIN_VARIANT (TREE_TYPE (value.value)) != fieldtype
8243 && (fieldcode == RECORD_TYPE || fieldcode == ARRAY_TYPE
8244 || fieldcode == UNION_TYPE || fieldcode == VECTOR_TYPE))
8246 push_init_level (1, braced_init_obstack);
8252 push_member_name (constructor_fields);
8253 output_init_element (value.value, value.original_type,
8254 strict_string, fieldtype,
8255 constructor_fields, 1, implicit,
8256 braced_init_obstack);
8257 RESTORE_SPELLING_DEPTH (constructor_depth);
8260 /* Do the bookkeeping for an element that was
8261 directly output as a constructor. */
8263 constructor_bit_index = DECL_SIZE (constructor_fields);
8264 constructor_unfilled_fields = DECL_CHAIN (constructor_fields);
8267 constructor_fields = 0;
8269 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
8271 tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
8272 enum tree_code eltcode = TREE_CODE (elttype);
8274 /* Accept a string constant to initialize a subarray. */
8275 if (value.value != 0
8276 && eltcode == ARRAY_TYPE
8277 && INTEGRAL_TYPE_P (TREE_TYPE (elttype))
8279 value.value = orig_value;
8280 /* Otherwise, if we have come to a subaggregate,
8281 and we don't have an element of its type, push into it. */
8282 else if (value.value != 0
8283 && value.value != error_mark_node
8284 && TYPE_MAIN_VARIANT (TREE_TYPE (value.value)) != elttype
8285 && (eltcode == RECORD_TYPE || eltcode == ARRAY_TYPE
8286 || eltcode == UNION_TYPE || eltcode == VECTOR_TYPE))
8288 push_init_level (1, braced_init_obstack);
8292 if (constructor_max_index != 0
8293 && (tree_int_cst_lt (constructor_max_index, constructor_index)
8294 || integer_all_onesp (constructor_max_index)))
8296 pedwarn_init (input_location, 0,
8297 "excess elements in array initializer");
8301 /* Now output the actual element. */
8304 push_array_bounds (tree_low_cst (constructor_index, 1));
8305 output_init_element (value.value, value.original_type,
8306 strict_string, elttype,
8307 constructor_index, 1, implicit,
8308 braced_init_obstack);
8309 RESTORE_SPELLING_DEPTH (constructor_depth);
8313 = size_binop_loc (input_location, PLUS_EXPR,
8314 constructor_index, bitsize_one_node);
8317 /* If we are doing the bookkeeping for an element that was
8318 directly output as a constructor, we must update
8319 constructor_unfilled_index. */
8320 constructor_unfilled_index = constructor_index;
8322 else if (TREE_CODE (constructor_type) == VECTOR_TYPE)
8324 tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
8326 /* Do a basic check of initializer size. Note that vectors
8327 always have a fixed size derived from their type. */
8328 if (tree_int_cst_lt (constructor_max_index, constructor_index))
8330 pedwarn_init (input_location, 0,
8331 "excess elements in vector initializer");
8335 /* Now output the actual element. */
8338 if (TREE_CODE (value.value) == VECTOR_CST)
8339 elttype = TYPE_MAIN_VARIANT (constructor_type);
8340 output_init_element (value.value, value.original_type,
8341 strict_string, elttype,
8342 constructor_index, 1, implicit,
8343 braced_init_obstack);
8347 = size_binop_loc (input_location,
8348 PLUS_EXPR, constructor_index, bitsize_one_node);
8351 /* If we are doing the bookkeeping for an element that was
8352 directly output as a constructor, we must update
8353 constructor_unfilled_index. */
8354 constructor_unfilled_index = constructor_index;
8357 /* Handle the sole element allowed in a braced initializer
8358 for a scalar variable. */
8359 else if (constructor_type != error_mark_node
8360 && constructor_fields == 0)
8362 pedwarn_init (input_location, 0,
8363 "excess elements in scalar initializer");
8369 output_init_element (value.value, value.original_type,
8370 strict_string, constructor_type,
8371 NULL_TREE, 1, implicit,
8372 braced_init_obstack);
8373 constructor_fields = 0;
8376 /* Handle range initializers either at this level or anywhere higher
8377 in the designator stack. */
8378 if (constructor_range_stack)
8380 struct constructor_range_stack *p, *range_stack;
8383 range_stack = constructor_range_stack;
8384 constructor_range_stack = 0;
8385 while (constructor_stack != range_stack->stack)
8387 gcc_assert (constructor_stack->implicit);
8388 process_init_element (pop_init_level (1,
8389 braced_init_obstack),
8390 true, braced_init_obstack);
8392 for (p = range_stack;
8393 !p->range_end || tree_int_cst_equal (p->index, p->range_end);
8396 gcc_assert (constructor_stack->implicit);
8397 process_init_element (pop_init_level (1, braced_init_obstack),
8398 true, braced_init_obstack);
8401 p->index = size_binop_loc (input_location,
8402 PLUS_EXPR, p->index, bitsize_one_node);
8403 if (tree_int_cst_equal (p->index, p->range_end) && !p->prev)
8408 constructor_index = p->index;
8409 constructor_fields = p->fields;
8410 if (finish && p->range_end && p->index == p->range_start)
8418 push_init_level (2, braced_init_obstack);
8419 p->stack = constructor_stack;
8420 if (p->range_end && tree_int_cst_equal (p->index, p->range_end))
8421 p->index = p->range_start;
8425 constructor_range_stack = range_stack;
8432 constructor_range_stack = 0;
8435 /* Build a complete asm-statement, whose components are a CV_QUALIFIER
8436 (guaranteed to be 'volatile' or null) and ARGS (represented using
8437 an ASM_EXPR node). */
8439 build_asm_stmt (tree cv_qualifier, tree args)
8441 if (!ASM_VOLATILE_P (args) && cv_qualifier)
8442 ASM_VOLATILE_P (args) = 1;
8443 return add_stmt (args);
8446 /* Build an asm-expr, whose components are a STRING, some OUTPUTS,
8447 some INPUTS, and some CLOBBERS. The latter three may be NULL.
8448 SIMPLE indicates whether there was anything at all after the
8449 string in the asm expression -- asm("blah") and asm("blah" : )
8450 are subtly different. We use a ASM_EXPR node to represent this. */
8452 build_asm_expr (location_t loc, tree string, tree outputs, tree inputs,
8453 tree clobbers, tree labels, bool simple)
8458 const char *constraint;
8459 const char **oconstraints;
8460 bool allows_mem, allows_reg, is_inout;
8461 int ninputs, noutputs;
8463 ninputs = list_length (inputs);
8464 noutputs = list_length (outputs);
8465 oconstraints = (const char **) alloca (noutputs * sizeof (const char *));
8467 string = resolve_asm_operand_names (string, outputs, inputs, labels);
8469 /* Remove output conversions that change the type but not the mode. */
8470 for (i = 0, tail = outputs; tail; ++i, tail = TREE_CHAIN (tail))
8472 tree output = TREE_VALUE (tail);
8474 /* ??? Really, this should not be here. Users should be using a
8475 proper lvalue, dammit. But there's a long history of using casts
8476 in the output operands. In cases like longlong.h, this becomes a
8477 primitive form of typechecking -- if the cast can be removed, then
8478 the output operand had a type of the proper width; otherwise we'll
8479 get an error. Gross, but ... */
8480 STRIP_NOPS (output);
8482 if (!lvalue_or_else (loc, output, lv_asm))
8483 output = error_mark_node;
8485 if (output != error_mark_node
8486 && (TREE_READONLY (output)
8487 || TYPE_READONLY (TREE_TYPE (output))
8488 || ((TREE_CODE (TREE_TYPE (output)) == RECORD_TYPE
8489 || TREE_CODE (TREE_TYPE (output)) == UNION_TYPE)
8490 && C_TYPE_FIELDS_READONLY (TREE_TYPE (output)))))
8491 readonly_error (output, lv_asm);
8493 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (tail)));
8494 oconstraints[i] = constraint;
8496 if (parse_output_constraint (&constraint, i, ninputs, noutputs,
8497 &allows_mem, &allows_reg, &is_inout))
8499 /* If the operand is going to end up in memory,
8500 mark it addressable. */
8501 if (!allows_reg && !c_mark_addressable (output))
8502 output = error_mark_node;
8503 if (!(!allows_reg && allows_mem)
8504 && output != error_mark_node
8505 && VOID_TYPE_P (TREE_TYPE (output)))
8507 error_at (loc, "invalid use of void expression");
8508 output = error_mark_node;
8512 output = error_mark_node;
8514 TREE_VALUE (tail) = output;
8517 for (i = 0, tail = inputs; tail; ++i, tail = TREE_CHAIN (tail))
8521 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (tail)));
8522 input = TREE_VALUE (tail);
8524 if (parse_input_constraint (&constraint, i, ninputs, noutputs, 0,
8525 oconstraints, &allows_mem, &allows_reg))
8527 /* If the operand is going to end up in memory,
8528 mark it addressable. */
8529 if (!allows_reg && allows_mem)
8531 /* Strip the nops as we allow this case. FIXME, this really
8532 should be rejected or made deprecated. */
8534 if (!c_mark_addressable (input))
8535 input = error_mark_node;
8537 else if (input != error_mark_node && VOID_TYPE_P (TREE_TYPE (input)))
8539 error_at (loc, "invalid use of void expression");
8540 input = error_mark_node;
8544 input = error_mark_node;
8546 TREE_VALUE (tail) = input;
8549 /* ASMs with labels cannot have outputs. This should have been
8550 enforced by the parser. */
8551 gcc_assert (outputs == NULL || labels == NULL);
8553 args = build_stmt (loc, ASM_EXPR, string, outputs, inputs, clobbers, labels);
8555 /* asm statements without outputs, including simple ones, are treated
8557 ASM_INPUT_P (args) = simple;
8558 ASM_VOLATILE_P (args) = (noutputs == 0);
8563 /* Generate a goto statement to LABEL. LOC is the location of the
8567 c_finish_goto_label (location_t loc, tree label)
8569 tree decl = lookup_label_for_goto (loc, label);
8572 TREE_USED (decl) = 1;
8574 tree t = build1 (GOTO_EXPR, void_type_node, decl);
8575 SET_EXPR_LOCATION (t, loc);
8576 return add_stmt (t);
8580 /* Generate a computed goto statement to EXPR. LOC is the location of
8584 c_finish_goto_ptr (location_t loc, tree expr)
8587 pedwarn (loc, OPT_pedantic, "ISO C forbids %<goto *expr;%>");
8588 expr = c_fully_fold (expr, false, NULL);
8589 expr = convert (ptr_type_node, expr);
8590 t = build1 (GOTO_EXPR, void_type_node, expr);
8591 SET_EXPR_LOCATION (t, loc);
8592 return add_stmt (t);
8595 /* Generate a C `return' statement. RETVAL is the expression for what
8596 to return, or a null pointer for `return;' with no value. LOC is
8597 the location of the return statement. If ORIGTYPE is not NULL_TREE, it
8598 is the original type of RETVAL. */
8601 c_finish_return (location_t loc, tree retval, tree origtype)
8603 tree valtype = TREE_TYPE (TREE_TYPE (current_function_decl)), ret_stmt;
8604 bool no_warning = false;
8607 if (TREE_THIS_VOLATILE (current_function_decl))
8609 "function declared %<noreturn%> has a %<return%> statement");
8613 tree semantic_type = NULL_TREE;
8614 npc = null_pointer_constant_p (retval);
8615 if (TREE_CODE (retval) == EXCESS_PRECISION_EXPR)
8617 semantic_type = TREE_TYPE (retval);
8618 retval = TREE_OPERAND (retval, 0);
8620 retval = c_fully_fold (retval, false, NULL);
8622 retval = build1 (EXCESS_PRECISION_EXPR, semantic_type, retval);
8627 current_function_returns_null = 1;
8628 if ((warn_return_type || flag_isoc99)
8629 && valtype != 0 && TREE_CODE (valtype) != VOID_TYPE)
8631 pedwarn_c99 (loc, flag_isoc99 ? 0 : OPT_Wreturn_type,
8632 "%<return%> with no value, in "
8633 "function returning non-void");
8637 else if (valtype == 0 || TREE_CODE (valtype) == VOID_TYPE)
8639 current_function_returns_null = 1;
8640 if (TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
8642 "%<return%> with a value, in function returning void");
8644 pedwarn (loc, OPT_pedantic, "ISO C forbids "
8645 "%<return%> with expression, in function returning void");
8649 tree t = convert_for_assignment (loc, valtype, retval, origtype,
8651 npc, NULL_TREE, NULL_TREE, 0);
8652 tree res = DECL_RESULT (current_function_decl);
8655 current_function_returns_value = 1;
8656 if (t == error_mark_node)
8659 inner = t = convert (TREE_TYPE (res), t);
8661 /* Strip any conversions, additions, and subtractions, and see if
8662 we are returning the address of a local variable. Warn if so. */
8665 switch (TREE_CODE (inner))
8668 case NON_LVALUE_EXPR:
8670 case POINTER_PLUS_EXPR:
8671 inner = TREE_OPERAND (inner, 0);
8675 /* If the second operand of the MINUS_EXPR has a pointer
8676 type (or is converted from it), this may be valid, so
8677 don't give a warning. */
8679 tree op1 = TREE_OPERAND (inner, 1);
8681 while (!POINTER_TYPE_P (TREE_TYPE (op1))
8682 && (CONVERT_EXPR_P (op1)
8683 || TREE_CODE (op1) == NON_LVALUE_EXPR))
8684 op1 = TREE_OPERAND (op1, 0);
8686 if (POINTER_TYPE_P (TREE_TYPE (op1)))
8689 inner = TREE_OPERAND (inner, 0);
8694 inner = TREE_OPERAND (inner, 0);
8696 while (REFERENCE_CLASS_P (inner)
8697 && TREE_CODE (inner) != INDIRECT_REF)
8698 inner = TREE_OPERAND (inner, 0);
8701 && !DECL_EXTERNAL (inner)
8702 && !TREE_STATIC (inner)
8703 && DECL_CONTEXT (inner) == current_function_decl)
8705 0, "function returns address of local variable");
8715 retval = build2 (MODIFY_EXPR, TREE_TYPE (res), res, t);
8716 SET_EXPR_LOCATION (retval, loc);
8718 if (warn_sequence_point)
8719 verify_sequence_points (retval);
8722 ret_stmt = build_stmt (loc, RETURN_EXPR, retval);
8723 TREE_NO_WARNING (ret_stmt) |= no_warning;
8724 return add_stmt (ret_stmt);
8728 /* The SWITCH_EXPR being built. */
8731 /* The original type of the testing expression, i.e. before the
8732 default conversion is applied. */
8735 /* A splay-tree mapping the low element of a case range to the high
8736 element, or NULL_TREE if there is no high element. Used to
8737 determine whether or not a new case label duplicates an old case
8738 label. We need a tree, rather than simply a hash table, because
8739 of the GNU case range extension. */
8742 /* The bindings at the point of the switch. This is used for
8743 warnings crossing decls when branching to a case label. */
8744 struct c_spot_bindings *bindings;
8746 /* The next node on the stack. */
8747 struct c_switch *next;
8750 /* A stack of the currently active switch statements. The innermost
8751 switch statement is on the top of the stack. There is no need to
8752 mark the stack for garbage collection because it is only active
8753 during the processing of the body of a function, and we never
8754 collect at that point. */
8756 struct c_switch *c_switch_stack;
8758 /* Start a C switch statement, testing expression EXP. Return the new
8759 SWITCH_EXPR. SWITCH_LOC is the location of the `switch'.
8760 SWITCH_COND_LOC is the location of the switch's condition. */
8763 c_start_case (location_t switch_loc,
8764 location_t switch_cond_loc,
8767 tree orig_type = error_mark_node;
8768 struct c_switch *cs;
8770 if (exp != error_mark_node)
8772 orig_type = TREE_TYPE (exp);
8774 if (!INTEGRAL_TYPE_P (orig_type))
8776 if (orig_type != error_mark_node)
8778 error_at (switch_cond_loc, "switch quantity not an integer");
8779 orig_type = error_mark_node;
8781 exp = integer_zero_node;
8785 tree type = TYPE_MAIN_VARIANT (orig_type);
8787 if (!in_system_header
8788 && (type == long_integer_type_node
8789 || type == long_unsigned_type_node))
8790 warning_at (switch_cond_loc,
8791 OPT_Wtraditional, "%<long%> switch expression not "
8792 "converted to %<int%> in ISO C");
8794 exp = c_fully_fold (exp, false, NULL);
8795 exp = default_conversion (exp);
8797 if (warn_sequence_point)
8798 verify_sequence_points (exp);
8802 /* Add this new SWITCH_EXPR to the stack. */
8803 cs = XNEW (struct c_switch);
8804 cs->switch_expr = build3 (SWITCH_EXPR, orig_type, exp, NULL_TREE, NULL_TREE);
8805 SET_EXPR_LOCATION (cs->switch_expr, switch_loc);
8806 cs->orig_type = orig_type;
8807 cs->cases = splay_tree_new (case_compare, NULL, NULL);
8808 cs->bindings = c_get_switch_bindings ();
8809 cs->next = c_switch_stack;
8810 c_switch_stack = cs;
8812 return add_stmt (cs->switch_expr);
8815 /* Process a case label at location LOC. */
8818 do_case (location_t loc, tree low_value, tree high_value)
8820 tree label = NULL_TREE;
8822 if (low_value && TREE_CODE (low_value) != INTEGER_CST)
8824 low_value = c_fully_fold (low_value, false, NULL);
8825 if (TREE_CODE (low_value) == INTEGER_CST)
8826 pedwarn (input_location, OPT_pedantic,
8827 "case label is not an integer constant expression");
8830 if (high_value && TREE_CODE (high_value) != INTEGER_CST)
8832 high_value = c_fully_fold (high_value, false, NULL);
8833 if (TREE_CODE (high_value) == INTEGER_CST)
8834 pedwarn (input_location, OPT_pedantic,
8835 "case label is not an integer constant expression");
8838 if (c_switch_stack == NULL)
8841 error_at (loc, "case label not within a switch statement");
8843 error_at (loc, "%<default%> label not within a switch statement");
8847 if (c_check_switch_jump_warnings (c_switch_stack->bindings,
8848 EXPR_LOCATION (c_switch_stack->switch_expr),
8852 label = c_add_case_label (loc, c_switch_stack->cases,
8853 SWITCH_COND (c_switch_stack->switch_expr),
8854 c_switch_stack->orig_type,
8855 low_value, high_value);
8856 if (label == error_mark_node)
8861 /* Finish the switch statement. */
8864 c_finish_case (tree body)
8866 struct c_switch *cs = c_switch_stack;
8867 location_t switch_location;
8869 SWITCH_BODY (cs->switch_expr) = body;
8871 /* Emit warnings as needed. */
8872 switch_location = EXPR_LOCATION (cs->switch_expr);
8873 c_do_switch_warnings (cs->cases, switch_location,
8874 TREE_TYPE (cs->switch_expr),
8875 SWITCH_COND (cs->switch_expr));
8877 /* Pop the stack. */
8878 c_switch_stack = cs->next;
8879 splay_tree_delete (cs->cases);
8880 c_release_switch_bindings (cs->bindings);
8884 /* Emit an if statement. IF_LOCUS is the location of the 'if'. COND,
8885 THEN_BLOCK and ELSE_BLOCK are expressions to be used; ELSE_BLOCK
8886 may be null. NESTED_IF is true if THEN_BLOCK contains another IF
8887 statement, and was not surrounded with parenthesis. */
8890 c_finish_if_stmt (location_t if_locus, tree cond, tree then_block,
8891 tree else_block, bool nested_if)
8895 /* Diagnose an ambiguous else if if-then-else is nested inside if-then. */
8896 if (warn_parentheses && nested_if && else_block == NULL)
8898 tree inner_if = then_block;
8900 /* We know from the grammar productions that there is an IF nested
8901 within THEN_BLOCK. Due to labels and c99 conditional declarations,
8902 it might not be exactly THEN_BLOCK, but should be the last
8903 non-container statement within. */
8905 switch (TREE_CODE (inner_if))
8910 inner_if = BIND_EXPR_BODY (inner_if);
8912 case STATEMENT_LIST:
8913 inner_if = expr_last (then_block);
8915 case TRY_FINALLY_EXPR:
8916 case TRY_CATCH_EXPR:
8917 inner_if = TREE_OPERAND (inner_if, 0);
8924 if (COND_EXPR_ELSE (inner_if))
8925 warning_at (if_locus, OPT_Wparentheses,
8926 "suggest explicit braces to avoid ambiguous %<else%>");
8929 stmt = build3 (COND_EXPR, void_type_node, cond, then_block, else_block);
8930 SET_EXPR_LOCATION (stmt, if_locus);
8934 /* Emit a general-purpose loop construct. START_LOCUS is the location of
8935 the beginning of the loop. COND is the loop condition. COND_IS_FIRST
8936 is false for DO loops. INCR is the FOR increment expression. BODY is
8937 the statement controlled by the loop. BLAB is the break label. CLAB is
8938 the continue label. Everything is allowed to be NULL. */
8941 c_finish_loop (location_t start_locus, tree cond, tree incr, tree body,
8942 tree blab, tree clab, bool cond_is_first)
8944 tree entry = NULL, exit = NULL, t;
8946 /* If the condition is zero don't generate a loop construct. */
8947 if (cond && integer_zerop (cond))
8951 t = build_and_jump (&blab);
8952 SET_EXPR_LOCATION (t, start_locus);
8958 tree top = build1 (LABEL_EXPR, void_type_node, NULL_TREE);
8960 /* If we have an exit condition, then we build an IF with gotos either
8961 out of the loop, or to the top of it. If there's no exit condition,
8962 then we just build a jump back to the top. */
8963 exit = build_and_jump (&LABEL_EXPR_LABEL (top));
8965 if (cond && !integer_nonzerop (cond))
8967 /* Canonicalize the loop condition to the end. This means
8968 generating a branch to the loop condition. Reuse the
8969 continue label, if possible. */
8974 entry = build1 (LABEL_EXPR, void_type_node, NULL_TREE);
8975 t = build_and_jump (&LABEL_EXPR_LABEL (entry));
8978 t = build1 (GOTO_EXPR, void_type_node, clab);
8979 SET_EXPR_LOCATION (t, start_locus);
8983 t = build_and_jump (&blab);
8985 exit = fold_build3_loc (start_locus,
8986 COND_EXPR, void_type_node, cond, exit, t);
8988 exit = fold_build3_loc (input_location,
8989 COND_EXPR, void_type_node, cond, exit, t);
8998 add_stmt (build1 (LABEL_EXPR, void_type_node, clab));
9006 add_stmt (build1 (LABEL_EXPR, void_type_node, blab));
9010 c_finish_bc_stmt (location_t loc, tree *label_p, bool is_break)
9013 tree label = *label_p;
9015 /* In switch statements break is sometimes stylistically used after
9016 a return statement. This can lead to spurious warnings about
9017 control reaching the end of a non-void function when it is
9018 inlined. Note that we are calling block_may_fallthru with
9019 language specific tree nodes; this works because
9020 block_may_fallthru returns true when given something it does not
9022 skip = !block_may_fallthru (cur_stmt_list);
9027 *label_p = label = create_artificial_label (loc);
9029 else if (TREE_CODE (label) == LABEL_DECL)
9031 else switch (TREE_INT_CST_LOW (label))
9035 error_at (loc, "break statement not within loop or switch");
9037 error_at (loc, "continue statement not within a loop");
9041 gcc_assert (is_break);
9042 error_at (loc, "break statement used with OpenMP for loop");
9053 add_stmt (build_predict_expr (PRED_CONTINUE, NOT_TAKEN));
9055 return add_stmt (build1 (GOTO_EXPR, void_type_node, label));
9058 /* A helper routine for c_process_expr_stmt and c_finish_stmt_expr. */
9061 emit_side_effect_warnings (location_t loc, tree expr)
9063 if (expr == error_mark_node)
9065 else if (!TREE_SIDE_EFFECTS (expr))
9067 if (!VOID_TYPE_P (TREE_TYPE (expr)) && !TREE_NO_WARNING (expr))
9068 warning_at (loc, OPT_Wunused_value, "statement with no effect");
9071 warn_if_unused_value (expr, loc);
9074 /* Process an expression as if it were a complete statement. Emit
9075 diagnostics, but do not call ADD_STMT. LOC is the location of the
9079 c_process_expr_stmt (location_t loc, tree expr)
9086 expr = c_fully_fold (expr, false, NULL);
9088 if (warn_sequence_point)
9089 verify_sequence_points (expr);
9091 if (TREE_TYPE (expr) != error_mark_node
9092 && !COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (expr))
9093 && TREE_CODE (TREE_TYPE (expr)) != ARRAY_TYPE)
9094 error_at (loc, "expression statement has incomplete type");
9096 /* If we're not processing a statement expression, warn about unused values.
9097 Warnings for statement expressions will be emitted later, once we figure
9098 out which is the result. */
9099 if (!STATEMENT_LIST_STMT_EXPR (cur_stmt_list)
9100 && warn_unused_value)
9101 emit_side_effect_warnings (loc, expr);
9104 while (TREE_CODE (exprv) == COMPOUND_EXPR)
9105 exprv = TREE_OPERAND (exprv, 1);
9106 if (DECL_P (exprv) || handled_component_p (exprv))
9107 mark_exp_read (exprv);
9109 /* If the expression is not of a type to which we cannot assign a line
9110 number, wrap the thing in a no-op NOP_EXPR. */
9111 if (DECL_P (expr) || CONSTANT_CLASS_P (expr))
9113 expr = build1 (NOP_EXPR, TREE_TYPE (expr), expr);
9114 SET_EXPR_LOCATION (expr, loc);
9120 /* Emit an expression as a statement. LOC is the location of the
9124 c_finish_expr_stmt (location_t loc, tree expr)
9127 return add_stmt (c_process_expr_stmt (loc, expr));
9132 /* Do the opposite and emit a statement as an expression. To begin,
9133 create a new binding level and return it. */
9136 c_begin_stmt_expr (void)
9140 /* We must force a BLOCK for this level so that, if it is not expanded
9141 later, there is a way to turn off the entire subtree of blocks that
9142 are contained in it. */
9144 ret = c_begin_compound_stmt (true);
9146 c_bindings_start_stmt_expr (c_switch_stack == NULL
9148 : c_switch_stack->bindings);
9150 /* Mark the current statement list as belonging to a statement list. */
9151 STATEMENT_LIST_STMT_EXPR (ret) = 1;
9156 /* LOC is the location of the compound statement to which this body
9160 c_finish_stmt_expr (location_t loc, tree body)
9162 tree last, type, tmp, val;
9165 body = c_end_compound_stmt (loc, body, true);
9167 c_bindings_end_stmt_expr (c_switch_stack == NULL
9169 : c_switch_stack->bindings);
9171 /* Locate the last statement in BODY. See c_end_compound_stmt
9172 about always returning a BIND_EXPR. */
9173 last_p = &BIND_EXPR_BODY (body);
9174 last = BIND_EXPR_BODY (body);
9177 if (TREE_CODE (last) == STATEMENT_LIST)
9179 tree_stmt_iterator i;
9181 /* This can happen with degenerate cases like ({ }). No value. */
9182 if (!TREE_SIDE_EFFECTS (last))
9185 /* If we're supposed to generate side effects warnings, process
9186 all of the statements except the last. */
9187 if (warn_unused_value)
9189 for (i = tsi_start (last); !tsi_one_before_end_p (i); tsi_next (&i))
9192 tree t = tsi_stmt (i);
9194 tloc = EXPR_HAS_LOCATION (t) ? EXPR_LOCATION (t) : loc;
9195 emit_side_effect_warnings (tloc, t);
9199 i = tsi_last (last);
9200 last_p = tsi_stmt_ptr (i);
9204 /* If the end of the list is exception related, then the list was split
9205 by a call to push_cleanup. Continue searching. */
9206 if (TREE_CODE (last) == TRY_FINALLY_EXPR
9207 || TREE_CODE (last) == TRY_CATCH_EXPR)
9209 last_p = &TREE_OPERAND (last, 0);
9211 goto continue_searching;
9214 if (last == error_mark_node)
9217 /* In the case that the BIND_EXPR is not necessary, return the
9218 expression out from inside it. */
9219 if (last == BIND_EXPR_BODY (body)
9220 && BIND_EXPR_VARS (body) == NULL)
9222 /* Even if this looks constant, do not allow it in a constant
9224 last = c_wrap_maybe_const (last, true);
9225 /* Do not warn if the return value of a statement expression is
9227 TREE_NO_WARNING (last) = 1;
9231 /* Extract the type of said expression. */
9232 type = TREE_TYPE (last);
9234 /* If we're not returning a value at all, then the BIND_EXPR that
9235 we already have is a fine expression to return. */
9236 if (!type || VOID_TYPE_P (type))
9239 /* Now that we've located the expression containing the value, it seems
9240 silly to make voidify_wrapper_expr repeat the process. Create a
9241 temporary of the appropriate type and stick it in a TARGET_EXPR. */
9242 tmp = create_tmp_var_raw (type, NULL);
9244 /* Unwrap a no-op NOP_EXPR as added by c_finish_expr_stmt. This avoids
9245 tree_expr_nonnegative_p giving up immediately. */
9247 if (TREE_CODE (val) == NOP_EXPR
9248 && TREE_TYPE (val) == TREE_TYPE (TREE_OPERAND (val, 0)))
9249 val = TREE_OPERAND (val, 0);
9251 *last_p = build2 (MODIFY_EXPR, void_type_node, tmp, val);
9252 SET_EXPR_LOCATION (*last_p, EXPR_LOCATION (last));
9255 tree t = build4 (TARGET_EXPR, type, tmp, body, NULL_TREE, NULL_TREE);
9256 SET_EXPR_LOCATION (t, loc);
9261 /* Begin and end compound statements. This is as simple as pushing
9262 and popping new statement lists from the tree. */
9265 c_begin_compound_stmt (bool do_scope)
9267 tree stmt = push_stmt_list ();
9273 /* End a compound statement. STMT is the statement. LOC is the
9274 location of the compound statement-- this is usually the location
9275 of the opening brace. */
9278 c_end_compound_stmt (location_t loc, tree stmt, bool do_scope)
9284 if (c_dialect_objc ())
9285 objc_clear_super_receiver ();
9286 block = pop_scope ();
9289 stmt = pop_stmt_list (stmt);
9290 stmt = c_build_bind_expr (loc, block, stmt);
9292 /* If this compound statement is nested immediately inside a statement
9293 expression, then force a BIND_EXPR to be created. Otherwise we'll
9294 do the wrong thing for ({ { 1; } }) or ({ 1; { } }). In particular,
9295 STATEMENT_LISTs merge, and thus we can lose track of what statement
9298 && STATEMENT_LIST_STMT_EXPR (cur_stmt_list)
9299 && TREE_CODE (stmt) != BIND_EXPR)
9301 stmt = build3 (BIND_EXPR, void_type_node, NULL, stmt, NULL);
9302 TREE_SIDE_EFFECTS (stmt) = 1;
9303 SET_EXPR_LOCATION (stmt, loc);
9309 /* Queue a cleanup. CLEANUP is an expression/statement to be executed
9310 when the current scope is exited. EH_ONLY is true when this is not
9311 meant to apply to normal control flow transfer. */
9314 push_cleanup (tree decl, tree cleanup, bool eh_only)
9316 enum tree_code code;
9320 code = eh_only ? TRY_CATCH_EXPR : TRY_FINALLY_EXPR;
9321 stmt = build_stmt (DECL_SOURCE_LOCATION (decl), code, NULL, cleanup);
9323 stmt_expr = STATEMENT_LIST_STMT_EXPR (cur_stmt_list);
9324 list = push_stmt_list ();
9325 TREE_OPERAND (stmt, 0) = list;
9326 STATEMENT_LIST_STMT_EXPR (list) = stmt_expr;
9329 /* Build a binary-operation expression without default conversions.
9330 CODE is the kind of expression to build.
9331 LOCATION is the operator's location.
9332 This function differs from `build' in several ways:
9333 the data type of the result is computed and recorded in it,
9334 warnings are generated if arg data types are invalid,
9335 special handling for addition and subtraction of pointers is known,
9336 and some optimization is done (operations on narrow ints
9337 are done in the narrower type when that gives the same result).
9338 Constant folding is also done before the result is returned.
9340 Note that the operands will never have enumeral types, or function
9341 or array types, because either they will have the default conversions
9342 performed or they have both just been converted to some other type in which
9343 the arithmetic is to be done. */
9346 build_binary_op (location_t location, enum tree_code code,
9347 tree orig_op0, tree orig_op1, int convert_p)
9349 tree type0, type1, orig_type0, orig_type1;
9351 enum tree_code code0, code1;
9353 tree ret = error_mark_node;
9354 const char *invalid_op_diag;
9355 bool op0_int_operands, op1_int_operands;
9356 bool int_const, int_const_or_overflow, int_operands;
9358 /* Expression code to give to the expression when it is built.
9359 Normally this is CODE, which is what the caller asked for,
9360 but in some special cases we change it. */
9361 enum tree_code resultcode = code;
9363 /* Data type in which the computation is to be performed.
9364 In the simplest cases this is the common type of the arguments. */
9365 tree result_type = NULL;
9367 /* When the computation is in excess precision, the type of the
9368 final EXCESS_PRECISION_EXPR. */
9369 tree semantic_result_type = NULL;
9371 /* Nonzero means operands have already been type-converted
9372 in whatever way is necessary.
9373 Zero means they need to be converted to RESULT_TYPE. */
9376 /* Nonzero means create the expression with this type, rather than
9378 tree build_type = 0;
9380 /* Nonzero means after finally constructing the expression
9381 convert it to this type. */
9382 tree final_type = 0;
9384 /* Nonzero if this is an operation like MIN or MAX which can
9385 safely be computed in short if both args are promoted shorts.
9386 Also implies COMMON.
9387 -1 indicates a bitwise operation; this makes a difference
9388 in the exact conditions for when it is safe to do the operation
9389 in a narrower mode. */
9392 /* Nonzero if this is a comparison operation;
9393 if both args are promoted shorts, compare the original shorts.
9394 Also implies COMMON. */
9395 int short_compare = 0;
9397 /* Nonzero if this is a right-shift operation, which can be computed on the
9398 original short and then promoted if the operand is a promoted short. */
9399 int short_shift = 0;
9401 /* Nonzero means set RESULT_TYPE to the common type of the args. */
9404 /* True means types are compatible as far as ObjC is concerned. */
9407 /* True means this is an arithmetic operation that may need excess
9409 bool may_need_excess_precision;
9411 /* True means this is a boolean operation that converts both its
9412 operands to truth-values. */
9413 bool boolean_op = false;
9415 if (location == UNKNOWN_LOCATION)
9416 location = input_location;
9421 op0_int_operands = EXPR_INT_CONST_OPERANDS (orig_op0);
9422 if (op0_int_operands)
9423 op0 = remove_c_maybe_const_expr (op0);
9424 op1_int_operands = EXPR_INT_CONST_OPERANDS (orig_op1);
9425 if (op1_int_operands)
9426 op1 = remove_c_maybe_const_expr (op1);
9427 int_operands = (op0_int_operands && op1_int_operands);
9430 int_const_or_overflow = (TREE_CODE (orig_op0) == INTEGER_CST
9431 && TREE_CODE (orig_op1) == INTEGER_CST);
9432 int_const = (int_const_or_overflow
9433 && !TREE_OVERFLOW (orig_op0)
9434 && !TREE_OVERFLOW (orig_op1));
9437 int_const = int_const_or_overflow = false;
9441 op0 = default_conversion (op0);
9442 op1 = default_conversion (op1);
9445 orig_type0 = type0 = TREE_TYPE (op0);
9446 orig_type1 = type1 = TREE_TYPE (op1);
9448 /* The expression codes of the data types of the arguments tell us
9449 whether the arguments are integers, floating, pointers, etc. */
9450 code0 = TREE_CODE (type0);
9451 code1 = TREE_CODE (type1);
9453 /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
9454 STRIP_TYPE_NOPS (op0);
9455 STRIP_TYPE_NOPS (op1);
9457 /* If an error was already reported for one of the arguments,
9458 avoid reporting another error. */
9460 if (code0 == ERROR_MARK || code1 == ERROR_MARK)
9461 return error_mark_node;
9463 if ((invalid_op_diag
9464 = targetm.invalid_binary_op (code, type0, type1)))
9466 error_at (location, invalid_op_diag);
9467 return error_mark_node;
9475 case TRUNC_DIV_EXPR:
9477 case FLOOR_DIV_EXPR:
9478 case ROUND_DIV_EXPR:
9479 case EXACT_DIV_EXPR:
9480 may_need_excess_precision = true;
9483 may_need_excess_precision = false;
9486 if (TREE_CODE (op0) == EXCESS_PRECISION_EXPR)
9488 op0 = TREE_OPERAND (op0, 0);
9489 type0 = TREE_TYPE (op0);
9491 else if (may_need_excess_precision
9492 && (eptype = excess_precision_type (type0)) != NULL_TREE)
9495 op0 = convert (eptype, op0);
9497 if (TREE_CODE (op1) == EXCESS_PRECISION_EXPR)
9499 op1 = TREE_OPERAND (op1, 0);
9500 type1 = TREE_TYPE (op1);
9502 else if (may_need_excess_precision
9503 && (eptype = excess_precision_type (type1)) != NULL_TREE)
9506 op1 = convert (eptype, op1);
9509 objc_ok = objc_compare_types (type0, type1, -3, NULL_TREE);
9514 /* Handle the pointer + int case. */
9515 if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
9517 ret = pointer_int_sum (location, PLUS_EXPR, op0, op1);
9518 goto return_build_binary_op;
9520 else if (code1 == POINTER_TYPE && code0 == INTEGER_TYPE)
9522 ret = pointer_int_sum (location, PLUS_EXPR, op1, op0);
9523 goto return_build_binary_op;
9530 /* Subtraction of two similar pointers.
9531 We must subtract them as integers, then divide by object size. */
9532 if (code0 == POINTER_TYPE && code1 == POINTER_TYPE
9533 && comp_target_types (location, type0, type1))
9535 ret = pointer_diff (location, op0, op1);
9536 goto return_build_binary_op;
9538 /* Handle pointer minus int. Just like pointer plus int. */
9539 else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
9541 ret = pointer_int_sum (location, MINUS_EXPR, op0, op1);
9542 goto return_build_binary_op;
9552 case TRUNC_DIV_EXPR:
9554 case FLOOR_DIV_EXPR:
9555 case ROUND_DIV_EXPR:
9556 case EXACT_DIV_EXPR:
9557 warn_for_div_by_zero (location, op1);
9559 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
9560 || code0 == FIXED_POINT_TYPE
9561 || code0 == COMPLEX_TYPE || code0 == VECTOR_TYPE)
9562 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
9563 || code1 == FIXED_POINT_TYPE
9564 || code1 == COMPLEX_TYPE || code1 == VECTOR_TYPE))
9566 enum tree_code tcode0 = code0, tcode1 = code1;
9568 if (code0 == COMPLEX_TYPE || code0 == VECTOR_TYPE)
9569 tcode0 = TREE_CODE (TREE_TYPE (TREE_TYPE (op0)));
9570 if (code1 == COMPLEX_TYPE || code1 == VECTOR_TYPE)
9571 tcode1 = TREE_CODE (TREE_TYPE (TREE_TYPE (op1)));
9573 if (!((tcode0 == INTEGER_TYPE && tcode1 == INTEGER_TYPE)
9574 || (tcode0 == FIXED_POINT_TYPE && tcode1 == FIXED_POINT_TYPE)))
9575 resultcode = RDIV_EXPR;
9577 /* Although it would be tempting to shorten always here, that
9578 loses on some targets, since the modulo instruction is
9579 undefined if the quotient can't be represented in the
9580 computation mode. We shorten only if unsigned or if
9581 dividing by something we know != -1. */
9582 shorten = (TYPE_UNSIGNED (TREE_TYPE (orig_op0))
9583 || (TREE_CODE (op1) == INTEGER_CST
9584 && !integer_all_onesp (op1)));
9592 if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
9594 /* Allow vector types which are not floating point types. */
9595 else if (code0 == VECTOR_TYPE
9596 && code1 == VECTOR_TYPE
9597 && !VECTOR_FLOAT_TYPE_P (type0)
9598 && !VECTOR_FLOAT_TYPE_P (type1))
9602 case TRUNC_MOD_EXPR:
9603 case FLOOR_MOD_EXPR:
9604 warn_for_div_by_zero (location, op1);
9606 if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE
9607 && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
9608 && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE)
9610 else if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
9612 /* Although it would be tempting to shorten always here, that loses
9613 on some targets, since the modulo instruction is undefined if the
9614 quotient can't be represented in the computation mode. We shorten
9615 only if unsigned or if dividing by something we know != -1. */
9616 shorten = (TYPE_UNSIGNED (TREE_TYPE (orig_op0))
9617 || (TREE_CODE (op1) == INTEGER_CST
9618 && !integer_all_onesp (op1)));
9623 case TRUTH_ANDIF_EXPR:
9624 case TRUTH_ORIF_EXPR:
9625 case TRUTH_AND_EXPR:
9627 case TRUTH_XOR_EXPR:
9628 if ((code0 == INTEGER_TYPE || code0 == POINTER_TYPE
9629 || code0 == REAL_TYPE || code0 == COMPLEX_TYPE
9630 || code0 == FIXED_POINT_TYPE)
9631 && (code1 == INTEGER_TYPE || code1 == POINTER_TYPE
9632 || code1 == REAL_TYPE || code1 == COMPLEX_TYPE
9633 || code1 == FIXED_POINT_TYPE))
9635 /* Result of these operations is always an int,
9636 but that does not mean the operands should be
9637 converted to ints! */
9638 result_type = integer_type_node;
9639 op0 = c_common_truthvalue_conversion (location, op0);
9640 op1 = c_common_truthvalue_conversion (location, op1);
9644 if (code == TRUTH_ANDIF_EXPR)
9646 int_const_or_overflow = (int_operands
9647 && TREE_CODE (orig_op0) == INTEGER_CST
9648 && (op0 == truthvalue_false_node
9649 || TREE_CODE (orig_op1) == INTEGER_CST));
9650 int_const = (int_const_or_overflow
9651 && !TREE_OVERFLOW (orig_op0)
9652 && (op0 == truthvalue_false_node
9653 || !TREE_OVERFLOW (orig_op1)));
9655 else if (code == TRUTH_ORIF_EXPR)
9657 int_const_or_overflow = (int_operands
9658 && TREE_CODE (orig_op0) == INTEGER_CST
9659 && (op0 == truthvalue_true_node
9660 || TREE_CODE (orig_op1) == INTEGER_CST));
9661 int_const = (int_const_or_overflow
9662 && !TREE_OVERFLOW (orig_op0)
9663 && (op0 == truthvalue_true_node
9664 || !TREE_OVERFLOW (orig_op1)));
9668 /* Shift operations: result has same type as first operand;
9669 always convert second operand to int.
9670 Also set SHORT_SHIFT if shifting rightward. */
9673 if (code0 == VECTOR_TYPE && code1 == INTEGER_TYPE
9674 && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE)
9676 result_type = type0;
9679 else if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE
9680 && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
9681 && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE
9682 && TYPE_VECTOR_SUBPARTS (type0) == TYPE_VECTOR_SUBPARTS (type1))
9684 result_type = type0;
9687 else if ((code0 == INTEGER_TYPE || code0 == FIXED_POINT_TYPE)
9688 && code1 == INTEGER_TYPE)
9690 if (TREE_CODE (op1) == INTEGER_CST)
9692 if (tree_int_cst_sgn (op1) < 0)
9695 if (c_inhibit_evaluation_warnings == 0)
9696 warning (0, "right shift count is negative");
9700 if (!integer_zerop (op1))
9703 if (compare_tree_int (op1, TYPE_PRECISION (type0)) >= 0)
9706 if (c_inhibit_evaluation_warnings == 0)
9707 warning (0, "right shift count >= width of type");
9712 /* Use the type of the value to be shifted. */
9713 result_type = type0;
9714 /* Convert the non vector shift-count to an integer, regardless
9715 of size of value being shifted. */
9716 if (TREE_CODE (TREE_TYPE (op1)) != VECTOR_TYPE
9717 && TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
9718 op1 = convert (integer_type_node, op1);
9719 /* Avoid converting op1 to result_type later. */
9725 if (code0 == VECTOR_TYPE && code1 == INTEGER_TYPE
9726 && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE)
9728 result_type = type0;
9731 else if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE
9732 && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
9733 && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE
9734 && TYPE_VECTOR_SUBPARTS (type0) == TYPE_VECTOR_SUBPARTS (type1))
9736 result_type = type0;
9739 else if ((code0 == INTEGER_TYPE || code0 == FIXED_POINT_TYPE)
9740 && code1 == INTEGER_TYPE)
9742 if (TREE_CODE (op1) == INTEGER_CST)
9744 if (tree_int_cst_sgn (op1) < 0)
9747 if (c_inhibit_evaluation_warnings == 0)
9748 warning (0, "left shift count is negative");
9751 else if (compare_tree_int (op1, TYPE_PRECISION (type0)) >= 0)
9754 if (c_inhibit_evaluation_warnings == 0)
9755 warning (0, "left shift count >= width of type");
9759 /* Use the type of the value to be shifted. */
9760 result_type = type0;
9761 /* Convert the non vector shift-count to an integer, regardless
9762 of size of value being shifted. */
9763 if (TREE_CODE (TREE_TYPE (op1)) != VECTOR_TYPE
9764 && TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
9765 op1 = convert (integer_type_node, op1);
9766 /* Avoid converting op1 to result_type later. */
9773 if (FLOAT_TYPE_P (type0) || FLOAT_TYPE_P (type1))
9774 warning_at (location,
9776 "comparing floating point with == or != is unsafe");
9777 /* Result of comparison is always int,
9778 but don't convert the args to int! */
9779 build_type = integer_type_node;
9780 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
9781 || code0 == FIXED_POINT_TYPE || code0 == COMPLEX_TYPE)
9782 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
9783 || code1 == FIXED_POINT_TYPE || code1 == COMPLEX_TYPE))
9785 else if (code0 == POINTER_TYPE && null_pointer_constant_p (orig_op1))
9787 if (TREE_CODE (op0) == ADDR_EXPR
9788 && decl_with_nonnull_addr_p (TREE_OPERAND (op0, 0)))
9790 if (code == EQ_EXPR)
9791 warning_at (location,
9793 "the comparison will always evaluate as %<false%> "
9794 "for the address of %qD will never be NULL",
9795 TREE_OPERAND (op0, 0));
9797 warning_at (location,
9799 "the comparison will always evaluate as %<true%> "
9800 "for the address of %qD will never be NULL",
9801 TREE_OPERAND (op0, 0));
9803 result_type = type0;
9805 else if (code1 == POINTER_TYPE && null_pointer_constant_p (orig_op0))
9807 if (TREE_CODE (op1) == ADDR_EXPR
9808 && decl_with_nonnull_addr_p (TREE_OPERAND (op1, 0)))
9810 if (code == EQ_EXPR)
9811 warning_at (location,
9813 "the comparison will always evaluate as %<false%> "
9814 "for the address of %qD will never be NULL",
9815 TREE_OPERAND (op1, 0));
9817 warning_at (location,
9819 "the comparison will always evaluate as %<true%> "
9820 "for the address of %qD will never be NULL",
9821 TREE_OPERAND (op1, 0));
9823 result_type = type1;
9825 else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
9827 tree tt0 = TREE_TYPE (type0);
9828 tree tt1 = TREE_TYPE (type1);
9829 addr_space_t as0 = TYPE_ADDR_SPACE (tt0);
9830 addr_space_t as1 = TYPE_ADDR_SPACE (tt1);
9831 addr_space_t as_common = ADDR_SPACE_GENERIC;
9833 /* Anything compares with void *. void * compares with anything.
9834 Otherwise, the targets must be compatible
9835 and both must be object or both incomplete. */
9836 if (comp_target_types (location, type0, type1))
9837 result_type = common_pointer_type (type0, type1);
9838 else if (!addr_space_superset (as0, as1, &as_common))
9840 error_at (location, "comparison of pointers to "
9841 "disjoint address spaces");
9842 return error_mark_node;
9844 else if (VOID_TYPE_P (tt0))
9846 if (pedantic && TREE_CODE (tt1) == FUNCTION_TYPE)
9847 pedwarn (location, OPT_pedantic, "ISO C forbids "
9848 "comparison of %<void *%> with function pointer");
9850 else if (VOID_TYPE_P (tt1))
9852 if (pedantic && TREE_CODE (tt0) == FUNCTION_TYPE)
9853 pedwarn (location, OPT_pedantic, "ISO C forbids "
9854 "comparison of %<void *%> with function pointer");
9857 /* Avoid warning about the volatile ObjC EH puts on decls. */
9859 pedwarn (location, 0,
9860 "comparison of distinct pointer types lacks a cast");
9862 if (result_type == NULL_TREE)
9864 int qual = ENCODE_QUAL_ADDR_SPACE (as_common);
9865 result_type = build_pointer_type
9866 (build_qualified_type (void_type_node, qual));
9869 else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
9871 result_type = type0;
9872 pedwarn (location, 0, "comparison between pointer and integer");
9874 else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
9876 result_type = type1;
9877 pedwarn (location, 0, "comparison between pointer and integer");
9885 build_type = integer_type_node;
9886 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
9887 || code0 == FIXED_POINT_TYPE)
9888 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
9889 || code1 == FIXED_POINT_TYPE))
9891 else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
9893 addr_space_t as0 = TYPE_ADDR_SPACE (TREE_TYPE (type0));
9894 addr_space_t as1 = TYPE_ADDR_SPACE (TREE_TYPE (type1));
9895 addr_space_t as_common;
9897 if (comp_target_types (location, type0, type1))
9899 result_type = common_pointer_type (type0, type1);
9900 if (!COMPLETE_TYPE_P (TREE_TYPE (type0))
9901 != !COMPLETE_TYPE_P (TREE_TYPE (type1)))
9902 pedwarn (location, 0,
9903 "comparison of complete and incomplete pointers");
9904 else if (TREE_CODE (TREE_TYPE (type0)) == FUNCTION_TYPE)
9905 pedwarn (location, OPT_pedantic, "ISO C forbids "
9906 "ordered comparisons of pointers to functions");
9907 else if (null_pointer_constant_p (orig_op0)
9908 || null_pointer_constant_p (orig_op1))
9909 warning_at (location, OPT_Wextra,
9910 "ordered comparison of pointer with null pointer");
9913 else if (!addr_space_superset (as0, as1, &as_common))
9915 error_at (location, "comparison of pointers to "
9916 "disjoint address spaces");
9917 return error_mark_node;
9921 int qual = ENCODE_QUAL_ADDR_SPACE (as_common);
9922 result_type = build_pointer_type
9923 (build_qualified_type (void_type_node, qual));
9924 pedwarn (location, 0,
9925 "comparison of distinct pointer types lacks a cast");
9928 else if (code0 == POINTER_TYPE && null_pointer_constant_p (orig_op1))
9930 result_type = type0;
9932 pedwarn (location, OPT_pedantic,
9933 "ordered comparison of pointer with integer zero");
9934 else if (extra_warnings)
9935 warning_at (location, OPT_Wextra,
9936 "ordered comparison of pointer with integer zero");
9938 else if (code1 == POINTER_TYPE && null_pointer_constant_p (orig_op0))
9940 result_type = type1;
9942 pedwarn (location, OPT_pedantic,
9943 "ordered comparison of pointer with integer zero");
9944 else if (extra_warnings)
9945 warning_at (location, OPT_Wextra,
9946 "ordered comparison of pointer with integer zero");
9948 else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
9950 result_type = type0;
9951 pedwarn (location, 0, "comparison between pointer and integer");
9953 else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
9955 result_type = type1;
9956 pedwarn (location, 0, "comparison between pointer and integer");
9964 if (code0 == ERROR_MARK || code1 == ERROR_MARK)
9965 return error_mark_node;
9967 if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE
9968 && (!tree_int_cst_equal (TYPE_SIZE (type0), TYPE_SIZE (type1))
9969 || !same_scalar_type_ignoring_signedness (TREE_TYPE (type0),
9970 TREE_TYPE (type1))))
9972 binary_op_error (location, code, type0, type1);
9973 return error_mark_node;
9976 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == COMPLEX_TYPE
9977 || code0 == FIXED_POINT_TYPE || code0 == VECTOR_TYPE)
9979 (code1 == INTEGER_TYPE || code1 == REAL_TYPE || code1 == COMPLEX_TYPE
9980 || code1 == FIXED_POINT_TYPE || code1 == VECTOR_TYPE))
9982 bool first_complex = (code0 == COMPLEX_TYPE);
9983 bool second_complex = (code1 == COMPLEX_TYPE);
9984 int none_complex = (!first_complex && !second_complex);
9986 if (shorten || common || short_compare)
9988 result_type = c_common_type (type0, type1);
9989 do_warn_double_promotion (result_type, type0, type1,
9990 "implicit conversion from %qT to %qT "
9991 "to match other operand of binary "
9994 if (result_type == error_mark_node)
9995 return error_mark_node;
9998 if (first_complex != second_complex
9999 && (code == PLUS_EXPR
10000 || code == MINUS_EXPR
10001 || code == MULT_EXPR
10002 || (code == TRUNC_DIV_EXPR && first_complex))
10003 && TREE_CODE (TREE_TYPE (result_type)) == REAL_TYPE
10004 && flag_signed_zeros)
10006 /* An operation on mixed real/complex operands must be
10007 handled specially, but the language-independent code can
10008 more easily optimize the plain complex arithmetic if
10009 -fno-signed-zeros. */
10010 tree real_type = TREE_TYPE (result_type);
10012 if (type0 != orig_type0 || type1 != orig_type1)
10014 gcc_assert (may_need_excess_precision && common);
10015 semantic_result_type = c_common_type (orig_type0, orig_type1);
10019 if (TREE_TYPE (op0) != result_type)
10020 op0 = convert_and_check (result_type, op0);
10021 if (TREE_TYPE (op1) != real_type)
10022 op1 = convert_and_check (real_type, op1);
10026 if (TREE_TYPE (op0) != real_type)
10027 op0 = convert_and_check (real_type, op0);
10028 if (TREE_TYPE (op1) != result_type)
10029 op1 = convert_and_check (result_type, op1);
10031 if (TREE_CODE (op0) == ERROR_MARK || TREE_CODE (op1) == ERROR_MARK)
10032 return error_mark_node;
10035 op0 = c_save_expr (op0);
10036 real = build_unary_op (EXPR_LOCATION (orig_op0), REALPART_EXPR,
10038 imag = build_unary_op (EXPR_LOCATION (orig_op0), IMAGPART_EXPR,
10043 case TRUNC_DIV_EXPR:
10044 imag = build2 (resultcode, real_type, imag, op1);
10045 /* Fall through. */
10048 real = build2 (resultcode, real_type, real, op1);
10056 op1 = c_save_expr (op1);
10057 real = build_unary_op (EXPR_LOCATION (orig_op1), REALPART_EXPR,
10059 imag = build_unary_op (EXPR_LOCATION (orig_op1), IMAGPART_EXPR,
10064 imag = build2 (resultcode, real_type, op0, imag);
10065 /* Fall through. */
10067 real = build2 (resultcode, real_type, op0, real);
10070 real = build2 (resultcode, real_type, op0, real);
10071 imag = build1 (NEGATE_EXPR, real_type, imag);
10077 ret = build2 (COMPLEX_EXPR, result_type, real, imag);
10078 goto return_build_binary_op;
10081 /* For certain operations (which identify themselves by shorten != 0)
10082 if both args were extended from the same smaller type,
10083 do the arithmetic in that type and then extend.
10085 shorten !=0 and !=1 indicates a bitwise operation.
10086 For them, this optimization is safe only if
10087 both args are zero-extended or both are sign-extended.
10088 Otherwise, we might change the result.
10089 Eg, (short)-1 | (unsigned short)-1 is (int)-1
10090 but calculated in (unsigned short) it would be (unsigned short)-1. */
10092 if (shorten && none_complex)
10094 final_type = result_type;
10095 result_type = shorten_binary_op (result_type, op0, op1,
10099 /* Shifts can be shortened if shifting right. */
10104 tree arg0 = get_narrower (op0, &unsigned_arg);
10106 final_type = result_type;
10108 if (arg0 == op0 && final_type == TREE_TYPE (op0))
10109 unsigned_arg = TYPE_UNSIGNED (TREE_TYPE (op0));
10111 if (TYPE_PRECISION (TREE_TYPE (arg0)) < TYPE_PRECISION (result_type)
10112 && tree_int_cst_sgn (op1) > 0
10113 /* We can shorten only if the shift count is less than the
10114 number of bits in the smaller type size. */
10115 && compare_tree_int (op1, TYPE_PRECISION (TREE_TYPE (arg0))) < 0
10116 /* We cannot drop an unsigned shift after sign-extension. */
10117 && (!TYPE_UNSIGNED (final_type) || unsigned_arg))
10119 /* Do an unsigned shift if the operand was zero-extended. */
10121 = c_common_signed_or_unsigned_type (unsigned_arg,
10123 /* Convert value-to-be-shifted to that type. */
10124 if (TREE_TYPE (op0) != result_type)
10125 op0 = convert (result_type, op0);
10130 /* Comparison operations are shortened too but differently.
10131 They identify themselves by setting short_compare = 1. */
10135 /* Don't write &op0, etc., because that would prevent op0
10136 from being kept in a register.
10137 Instead, make copies of the our local variables and
10138 pass the copies by reference, then copy them back afterward. */
10139 tree xop0 = op0, xop1 = op1, xresult_type = result_type;
10140 enum tree_code xresultcode = resultcode;
10142 = shorten_compare (&xop0, &xop1, &xresult_type, &xresultcode);
10147 goto return_build_binary_op;
10150 op0 = xop0, op1 = xop1;
10152 resultcode = xresultcode;
10154 if (c_inhibit_evaluation_warnings == 0)
10156 bool op0_maybe_const = true;
10157 bool op1_maybe_const = true;
10158 tree orig_op0_folded, orig_op1_folded;
10160 if (in_late_binary_op)
10162 orig_op0_folded = orig_op0;
10163 orig_op1_folded = orig_op1;
10167 /* Fold for the sake of possible warnings, as in
10168 build_conditional_expr. This requires the
10169 "original" values to be folded, not just op0 and
10171 c_inhibit_evaluation_warnings++;
10172 op0 = c_fully_fold (op0, require_constant_value,
10174 op1 = c_fully_fold (op1, require_constant_value,
10176 c_inhibit_evaluation_warnings--;
10177 orig_op0_folded = c_fully_fold (orig_op0,
10178 require_constant_value,
10180 orig_op1_folded = c_fully_fold (orig_op1,
10181 require_constant_value,
10185 if (warn_sign_compare)
10186 warn_for_sign_compare (location, orig_op0_folded,
10187 orig_op1_folded, op0, op1,
10188 result_type, resultcode);
10189 if (!in_late_binary_op && !int_operands)
10191 if (!op0_maybe_const || TREE_CODE (op0) != INTEGER_CST)
10192 op0 = c_wrap_maybe_const (op0, !op0_maybe_const);
10193 if (!op1_maybe_const || TREE_CODE (op1) != INTEGER_CST)
10194 op1 = c_wrap_maybe_const (op1, !op1_maybe_const);
10200 /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
10201 If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
10202 Then the expression will be built.
10203 It will be given type FINAL_TYPE if that is nonzero;
10204 otherwise, it will be given type RESULT_TYPE. */
10208 binary_op_error (location, code, TREE_TYPE (op0), TREE_TYPE (op1));
10209 return error_mark_node;
10212 if (build_type == NULL_TREE)
10214 build_type = result_type;
10215 if ((type0 != orig_type0 || type1 != orig_type1)
10218 gcc_assert (may_need_excess_precision && common);
10219 semantic_result_type = c_common_type (orig_type0, orig_type1);
10225 op0 = ep_convert_and_check (result_type, op0, semantic_result_type);
10226 op1 = ep_convert_and_check (result_type, op1, semantic_result_type);
10228 /* This can happen if one operand has a vector type, and the other
10229 has a different type. */
10230 if (TREE_CODE (op0) == ERROR_MARK || TREE_CODE (op1) == ERROR_MARK)
10231 return error_mark_node;
10234 /* Treat expressions in initializers specially as they can't trap. */
10235 if (int_const_or_overflow)
10236 ret = (require_constant_value
10237 ? fold_build2_initializer_loc (location, resultcode, build_type,
10239 : fold_build2_loc (location, resultcode, build_type, op0, op1));
10241 ret = build2 (resultcode, build_type, op0, op1);
10242 if (final_type != 0)
10243 ret = convert (final_type, ret);
10245 return_build_binary_op:
10246 gcc_assert (ret != error_mark_node);
10247 if (TREE_CODE (ret) == INTEGER_CST && !TREE_OVERFLOW (ret) && !int_const)
10248 ret = (int_operands
10249 ? note_integer_operands (ret)
10250 : build1 (NOP_EXPR, TREE_TYPE (ret), ret));
10251 else if (TREE_CODE (ret) != INTEGER_CST && int_operands
10252 && !in_late_binary_op)
10253 ret = note_integer_operands (ret);
10254 if (semantic_result_type)
10255 ret = build1 (EXCESS_PRECISION_EXPR, semantic_result_type, ret);
10256 protected_set_expr_location (ret, location);
10261 /* Convert EXPR to be a truth-value, validating its type for this
10262 purpose. LOCATION is the source location for the expression. */
10265 c_objc_common_truthvalue_conversion (location_t location, tree expr)
10267 bool int_const, int_operands;
10269 switch (TREE_CODE (TREE_TYPE (expr)))
10272 error_at (location, "used array that cannot be converted to pointer where scalar is required");
10273 return error_mark_node;
10276 error_at (location, "used struct type value where scalar is required");
10277 return error_mark_node;
10280 error_at (location, "used union type value where scalar is required");
10281 return error_mark_node;
10284 error_at (location, "void value not ignored as it ought to be");
10285 return error_mark_node;
10287 case FUNCTION_TYPE:
10288 gcc_unreachable ();
10294 int_const = (TREE_CODE (expr) == INTEGER_CST && !TREE_OVERFLOW (expr));
10295 int_operands = EXPR_INT_CONST_OPERANDS (expr);
10297 expr = remove_c_maybe_const_expr (expr);
10299 /* ??? Should we also give an error for vectors rather than leaving
10300 those to give errors later? */
10301 expr = c_common_truthvalue_conversion (location, expr);
10303 if (TREE_CODE (expr) == INTEGER_CST && int_operands && !int_const)
10305 if (TREE_OVERFLOW (expr))
10308 return note_integer_operands (expr);
10310 if (TREE_CODE (expr) == INTEGER_CST && !int_const)
10311 return build1 (NOP_EXPR, TREE_TYPE (expr), expr);
10316 /* Convert EXPR to a contained DECL, updating *TC, *TI and *SE as
10320 c_expr_to_decl (tree expr, bool *tc ATTRIBUTE_UNUSED, bool *se)
10322 if (TREE_CODE (expr) == COMPOUND_LITERAL_EXPR)
10324 tree decl = COMPOUND_LITERAL_EXPR_DECL (expr);
10325 /* Executing a compound literal inside a function reinitializes
10327 if (!TREE_STATIC (decl))
10335 /* Like c_begin_compound_stmt, except force the retention of the BLOCK. */
10338 c_begin_omp_parallel (void)
10342 keep_next_level ();
10343 block = c_begin_compound_stmt (true);
10348 /* Generate OMP_PARALLEL, with CLAUSES and BLOCK as its compound
10349 statement. LOC is the location of the OMP_PARALLEL. */
10352 c_finish_omp_parallel (location_t loc, tree clauses, tree block)
10356 block = c_end_compound_stmt (loc, block, true);
10358 stmt = make_node (OMP_PARALLEL);
10359 TREE_TYPE (stmt) = void_type_node;
10360 OMP_PARALLEL_CLAUSES (stmt) = clauses;
10361 OMP_PARALLEL_BODY (stmt) = block;
10362 SET_EXPR_LOCATION (stmt, loc);
10364 return add_stmt (stmt);
10367 /* Like c_begin_compound_stmt, except force the retention of the BLOCK. */
10370 c_begin_omp_task (void)
10374 keep_next_level ();
10375 block = c_begin_compound_stmt (true);
10380 /* Generate OMP_TASK, with CLAUSES and BLOCK as its compound
10381 statement. LOC is the location of the #pragma. */
10384 c_finish_omp_task (location_t loc, tree clauses, tree block)
10388 block = c_end_compound_stmt (loc, block, true);
10390 stmt = make_node (OMP_TASK);
10391 TREE_TYPE (stmt) = void_type_node;
10392 OMP_TASK_CLAUSES (stmt) = clauses;
10393 OMP_TASK_BODY (stmt) = block;
10394 SET_EXPR_LOCATION (stmt, loc);
10396 return add_stmt (stmt);
10399 /* For all elements of CLAUSES, validate them vs OpenMP constraints.
10400 Remove any elements from the list that are invalid. */
10403 c_finish_omp_clauses (tree clauses)
10405 bitmap_head generic_head, firstprivate_head, lastprivate_head;
10406 tree c, t, *pc = &clauses;
10409 bitmap_obstack_initialize (NULL);
10410 bitmap_initialize (&generic_head, &bitmap_default_obstack);
10411 bitmap_initialize (&firstprivate_head, &bitmap_default_obstack);
10412 bitmap_initialize (&lastprivate_head, &bitmap_default_obstack);
10414 for (pc = &clauses, c = clauses; c ; c = *pc)
10416 bool remove = false;
10417 bool need_complete = false;
10418 bool need_implicitly_determined = false;
10420 switch (OMP_CLAUSE_CODE (c))
10422 case OMP_CLAUSE_SHARED:
10424 need_implicitly_determined = true;
10425 goto check_dup_generic;
10427 case OMP_CLAUSE_PRIVATE:
10429 need_complete = true;
10430 need_implicitly_determined = true;
10431 goto check_dup_generic;
10433 case OMP_CLAUSE_REDUCTION:
10434 name = "reduction";
10435 need_implicitly_determined = true;
10436 t = OMP_CLAUSE_DECL (c);
10437 if (AGGREGATE_TYPE_P (TREE_TYPE (t))
10438 || POINTER_TYPE_P (TREE_TYPE (t)))
10440 error_at (OMP_CLAUSE_LOCATION (c),
10441 "%qE has invalid type for %<reduction%>", t);
10444 else if (FLOAT_TYPE_P (TREE_TYPE (t)))
10446 enum tree_code r_code = OMP_CLAUSE_REDUCTION_CODE (c);
10447 const char *r_name = NULL;
10464 case TRUTH_ANDIF_EXPR:
10467 case TRUTH_ORIF_EXPR:
10471 gcc_unreachable ();
10475 error_at (OMP_CLAUSE_LOCATION (c),
10476 "%qE has invalid type for %<reduction(%s)%>",
10481 goto check_dup_generic;
10483 case OMP_CLAUSE_COPYPRIVATE:
10484 name = "copyprivate";
10485 goto check_dup_generic;
10487 case OMP_CLAUSE_COPYIN:
10489 t = OMP_CLAUSE_DECL (c);
10490 if (TREE_CODE (t) != VAR_DECL || !DECL_THREAD_LOCAL_P (t))
10492 error_at (OMP_CLAUSE_LOCATION (c),
10493 "%qE must be %<threadprivate%> for %<copyin%>", t);
10496 goto check_dup_generic;
10499 t = OMP_CLAUSE_DECL (c);
10500 if (TREE_CODE (t) != VAR_DECL && TREE_CODE (t) != PARM_DECL)
10502 error_at (OMP_CLAUSE_LOCATION (c),
10503 "%qE is not a variable in clause %qs", t, name);
10506 else if (bitmap_bit_p (&generic_head, DECL_UID (t))
10507 || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
10508 || bitmap_bit_p (&lastprivate_head, DECL_UID (t)))
10510 error_at (OMP_CLAUSE_LOCATION (c),
10511 "%qE appears more than once in data clauses", t);
10515 bitmap_set_bit (&generic_head, DECL_UID (t));
10518 case OMP_CLAUSE_FIRSTPRIVATE:
10519 name = "firstprivate";
10520 t = OMP_CLAUSE_DECL (c);
10521 need_complete = true;
10522 need_implicitly_determined = true;
10523 if (TREE_CODE (t) != VAR_DECL && TREE_CODE (t) != PARM_DECL)
10525 error_at (OMP_CLAUSE_LOCATION (c),
10526 "%qE is not a variable in clause %<firstprivate%>", t);
10529 else if (bitmap_bit_p (&generic_head, DECL_UID (t))
10530 || bitmap_bit_p (&firstprivate_head, DECL_UID (t)))
10532 error_at (OMP_CLAUSE_LOCATION (c),
10533 "%qE appears more than once in data clauses", t);
10537 bitmap_set_bit (&firstprivate_head, DECL_UID (t));
10540 case OMP_CLAUSE_LASTPRIVATE:
10541 name = "lastprivate";
10542 t = OMP_CLAUSE_DECL (c);
10543 need_complete = true;
10544 need_implicitly_determined = true;
10545 if (TREE_CODE (t) != VAR_DECL && TREE_CODE (t) != PARM_DECL)
10547 error_at (OMP_CLAUSE_LOCATION (c),
10548 "%qE is not a variable in clause %<lastprivate%>", t);
10551 else if (bitmap_bit_p (&generic_head, DECL_UID (t))
10552 || bitmap_bit_p (&lastprivate_head, DECL_UID (t)))
10554 error_at (OMP_CLAUSE_LOCATION (c),
10555 "%qE appears more than once in data clauses", t);
10559 bitmap_set_bit (&lastprivate_head, DECL_UID (t));
10562 case OMP_CLAUSE_IF:
10563 case OMP_CLAUSE_NUM_THREADS:
10564 case OMP_CLAUSE_SCHEDULE:
10565 case OMP_CLAUSE_NOWAIT:
10566 case OMP_CLAUSE_ORDERED:
10567 case OMP_CLAUSE_DEFAULT:
10568 case OMP_CLAUSE_UNTIED:
10569 case OMP_CLAUSE_COLLAPSE:
10570 pc = &OMP_CLAUSE_CHAIN (c);
10574 gcc_unreachable ();
10579 t = OMP_CLAUSE_DECL (c);
10583 t = require_complete_type (t);
10584 if (t == error_mark_node)
10588 if (need_implicitly_determined)
10590 const char *share_name = NULL;
10592 if (TREE_CODE (t) == VAR_DECL && DECL_THREAD_LOCAL_P (t))
10593 share_name = "threadprivate";
10594 else switch (c_omp_predetermined_sharing (t))
10596 case OMP_CLAUSE_DEFAULT_UNSPECIFIED:
10598 case OMP_CLAUSE_DEFAULT_SHARED:
10599 share_name = "shared";
10601 case OMP_CLAUSE_DEFAULT_PRIVATE:
10602 share_name = "private";
10605 gcc_unreachable ();
10609 error_at (OMP_CLAUSE_LOCATION (c),
10610 "%qE is predetermined %qs for %qs",
10611 t, share_name, name);
10618 *pc = OMP_CLAUSE_CHAIN (c);
10620 pc = &OMP_CLAUSE_CHAIN (c);
10623 bitmap_obstack_release (NULL);
10627 /* Make a variant type in the proper way for C/C++, propagating qualifiers
10628 down to the element type of an array. */
10631 c_build_qualified_type (tree type, int type_quals)
10633 if (type == error_mark_node)
10636 if (TREE_CODE (type) == ARRAY_TYPE)
10639 tree element_type = c_build_qualified_type (TREE_TYPE (type),
10642 /* See if we already have an identically qualified type. */
10643 for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
10645 if (TYPE_QUALS (strip_array_types (t)) == type_quals
10646 && TYPE_NAME (t) == TYPE_NAME (type)
10647 && TYPE_CONTEXT (t) == TYPE_CONTEXT (type)
10648 && attribute_list_equal (TYPE_ATTRIBUTES (t),
10649 TYPE_ATTRIBUTES (type)))
10654 tree domain = TYPE_DOMAIN (type);
10656 t = build_variant_type_copy (type);
10657 TREE_TYPE (t) = element_type;
10659 if (TYPE_STRUCTURAL_EQUALITY_P (element_type)
10660 || (domain && TYPE_STRUCTURAL_EQUALITY_P (domain)))
10661 SET_TYPE_STRUCTURAL_EQUALITY (t);
10662 else if (TYPE_CANONICAL (element_type) != element_type
10663 || (domain && TYPE_CANONICAL (domain) != domain))
10665 tree unqualified_canon
10666 = build_array_type (TYPE_CANONICAL (element_type),
10667 domain? TYPE_CANONICAL (domain)
10670 = c_build_qualified_type (unqualified_canon, type_quals);
10673 TYPE_CANONICAL (t) = t;
10678 /* A restrict-qualified pointer type must be a pointer to object or
10679 incomplete type. Note that the use of POINTER_TYPE_P also allows
10680 REFERENCE_TYPEs, which is appropriate for C++. */
10681 if ((type_quals & TYPE_QUAL_RESTRICT)
10682 && (!POINTER_TYPE_P (type)
10683 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type))))
10685 error ("invalid use of %<restrict%>");
10686 type_quals &= ~TYPE_QUAL_RESTRICT;
10689 return build_qualified_type (type, type_quals);
10692 /* Build a VA_ARG_EXPR for the C parser. */
10695 c_build_va_arg (location_t loc, tree expr, tree type)
10697 if (warn_cxx_compat && TREE_CODE (type) == ENUMERAL_TYPE)
10698 warning_at (loc, OPT_Wc___compat,
10699 "C++ requires promoted type, not enum type, in %<va_arg%>");
10700 return build_va_arg (loc, expr, type);