1 /* Build expressions with type checking for C compiler.
2 Copyright (C) 1987-2013 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
21 /* This file is part of the C front end.
22 It contains routines to build C expressions given their operands,
23 including computing the types of the result, C-specific error checks,
24 and some optimization. */
28 #include "coretypes.h"
31 #include "langhooks.h"
37 #include "tree-iterator.h"
40 #include "c-family/c-objc.h"
41 #include "c-family/c-common.h"
43 /* Possible cases of implicit bad conversions. Used to select
44 diagnostic messages in convert_for_assignment. */
52 /* The level of nesting inside "__alignof__". */
55 /* The level of nesting inside "sizeof". */
58 /* The level of nesting inside "typeof". */
61 /* The argument of last parsed sizeof expression, only to be tested
62 if expr.original_code == SIZEOF_EXPR. */
63 tree c_last_sizeof_arg
;
65 /* Nonzero if we've already printed a "missing braces around initializer"
66 message within this initializer. */
67 static int missing_braces_mentioned
;
69 static int require_constant_value
;
70 static int require_constant_elements
;
72 static bool null_pointer_constant_p (const_tree
);
73 static tree
qualify_type (tree
, tree
);
74 static int tagged_types_tu_compatible_p (const_tree
, const_tree
, bool *,
76 static int comp_target_types (location_t
, tree
, tree
);
77 static int function_types_compatible_p (const_tree
, const_tree
, bool *,
79 static int type_lists_compatible_p (const_tree
, const_tree
, bool *, bool *);
80 static tree
lookup_field (tree
, tree
);
81 static int convert_arguments (tree
, vec
<tree
, va_gc
> *, vec
<tree
, va_gc
> *,
83 static tree
pointer_diff (location_t
, tree
, tree
);
84 static tree
convert_for_assignment (location_t
, tree
, tree
, tree
,
85 enum impl_conv
, bool, tree
, tree
, int);
86 static tree
valid_compound_expr_initializer (tree
, tree
);
87 static void push_string (const char *);
88 static void push_member_name (tree
);
89 static int spelling_length (void);
90 static char *print_spelling (char *);
91 static void warning_init (int, const char *);
92 static tree
digest_init (location_t
, tree
, tree
, tree
, bool, bool, int);
93 static void output_init_element (tree
, tree
, bool, tree
, tree
, int, bool,
95 static void output_pending_init_elements (int, struct obstack
*);
96 static int set_designator (int, struct obstack
*);
97 static void push_range_stack (tree
, struct obstack
*);
98 static void add_pending_init (tree
, tree
, tree
, bool, struct obstack
*);
99 static void set_nonincremental_init (struct obstack
*);
100 static void set_nonincremental_init_from_string (tree
, struct obstack
*);
101 static tree
find_init_member (tree
, struct obstack
*);
102 static void readonly_warning (tree
, enum lvalue_use
);
103 static int lvalue_or_else (location_t
, const_tree
, enum lvalue_use
);
104 static void record_maybe_used_decl (tree
);
105 static int comptypes_internal (const_tree
, const_tree
, bool *, bool *);
107 /* Return true if EXP is a null pointer constant, false otherwise. */
110 null_pointer_constant_p (const_tree expr
)
112 /* This should really operate on c_expr structures, but they aren't
113 yet available everywhere required. */
114 tree type
= TREE_TYPE (expr
);
115 return (TREE_CODE (expr
) == INTEGER_CST
116 && !TREE_OVERFLOW (expr
)
117 && integer_zerop (expr
)
118 && (INTEGRAL_TYPE_P (type
)
119 || (TREE_CODE (type
) == POINTER_TYPE
120 && VOID_TYPE_P (TREE_TYPE (type
))
121 && TYPE_QUALS (TREE_TYPE (type
)) == TYPE_UNQUALIFIED
)));
124 /* EXPR may appear in an unevaluated part of an integer constant
125 expression, but not in an evaluated part. Wrap it in a
126 C_MAYBE_CONST_EXPR, or mark it with TREE_OVERFLOW if it is just an
127 INTEGER_CST and we cannot create a C_MAYBE_CONST_EXPR. */
130 note_integer_operands (tree expr
)
133 if (TREE_CODE (expr
) == INTEGER_CST
&& in_late_binary_op
)
135 ret
= copy_node (expr
);
136 TREE_OVERFLOW (ret
) = 1;
140 ret
= build2 (C_MAYBE_CONST_EXPR
, TREE_TYPE (expr
), NULL_TREE
, expr
);
141 C_MAYBE_CONST_EXPR_INT_OPERANDS (ret
) = 1;
146 /* Having checked whether EXPR may appear in an unevaluated part of an
147 integer constant expression and found that it may, remove any
148 C_MAYBE_CONST_EXPR noting this fact and return the resulting
152 remove_c_maybe_const_expr (tree expr
)
154 if (TREE_CODE (expr
) == C_MAYBE_CONST_EXPR
)
155 return C_MAYBE_CONST_EXPR_EXPR (expr
);
160 \f/* This is a cache to hold if two types are compatible or not. */
162 struct tagged_tu_seen_cache
{
163 const struct tagged_tu_seen_cache
* next
;
166 /* The return value of tagged_types_tu_compatible_p if we had seen
167 these two types already. */
171 static const struct tagged_tu_seen_cache
* tagged_tu_seen_base
;
172 static void free_all_tagged_tu_seen_up_to (const struct tagged_tu_seen_cache
*);
174 /* Do `exp = require_complete_type (exp);' to make sure exp
175 does not have an incomplete type. (That includes void types.) */
178 require_complete_type (tree value
)
180 tree type
= TREE_TYPE (value
);
182 if (value
== error_mark_node
|| type
== error_mark_node
)
183 return error_mark_node
;
185 /* First, detect a valid value with a complete type. */
186 if (COMPLETE_TYPE_P (type
))
189 c_incomplete_type_error (value
, type
);
190 return error_mark_node
;
193 /* Print an error message for invalid use of an incomplete type.
194 VALUE is the expression that was used (or 0 if that isn't known)
195 and TYPE is the type that was invalid. */
198 c_incomplete_type_error (const_tree value
, const_tree type
)
200 const char *type_code_string
;
202 /* Avoid duplicate error message. */
203 if (TREE_CODE (type
) == ERROR_MARK
)
206 if (value
!= 0 && (TREE_CODE (value
) == VAR_DECL
207 || TREE_CODE (value
) == PARM_DECL
))
208 error ("%qD has an incomplete type", value
);
212 /* We must print an error message. Be clever about what it says. */
214 switch (TREE_CODE (type
))
217 type_code_string
= "struct";
221 type_code_string
= "union";
225 type_code_string
= "enum";
229 error ("invalid use of void expression");
233 if (TYPE_DOMAIN (type
))
235 if (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) == NULL
)
237 error ("invalid use of flexible array member");
240 type
= TREE_TYPE (type
);
243 error ("invalid use of array with unspecified bounds");
250 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
251 error ("invalid use of undefined type %<%s %E%>",
252 type_code_string
, TYPE_NAME (type
));
254 /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL. */
255 error ("invalid use of incomplete typedef %qD", TYPE_NAME (type
));
259 /* Given a type, apply default promotions wrt unnamed function
260 arguments and return the new type. */
263 c_type_promotes_to (tree type
)
265 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
266 return double_type_node
;
268 if (c_promoting_integer_type_p (type
))
270 /* Preserve unsignedness if not really getting any wider. */
271 if (TYPE_UNSIGNED (type
)
272 && (TYPE_PRECISION (type
) == TYPE_PRECISION (integer_type_node
)))
273 return unsigned_type_node
;
274 return integer_type_node
;
280 /* Return true if between two named address spaces, whether there is a superset
281 named address space that encompasses both address spaces. If there is a
282 superset, return which address space is the superset. */
285 addr_space_superset (addr_space_t as1
, addr_space_t as2
, addr_space_t
*common
)
292 else if (targetm
.addr_space
.subset_p (as1
, as2
))
297 else if (targetm
.addr_space
.subset_p (as2
, as1
))
306 /* Return a variant of TYPE which has all the type qualifiers of LIKE
307 as well as those of TYPE. */
310 qualify_type (tree type
, tree like
)
312 addr_space_t as_type
= TYPE_ADDR_SPACE (type
);
313 addr_space_t as_like
= TYPE_ADDR_SPACE (like
);
314 addr_space_t as_common
;
316 /* If the two named address spaces are different, determine the common
317 superset address space. If there isn't one, raise an error. */
318 if (!addr_space_superset (as_type
, as_like
, &as_common
))
321 error ("%qT and %qT are in disjoint named address spaces",
325 return c_build_qualified_type (type
,
326 TYPE_QUALS_NO_ADDR_SPACE (type
)
327 | TYPE_QUALS_NO_ADDR_SPACE (like
)
328 | ENCODE_QUAL_ADDR_SPACE (as_common
));
331 /* Return true iff the given tree T is a variable length array. */
334 c_vla_type_p (const_tree t
)
336 if (TREE_CODE (t
) == ARRAY_TYPE
337 && C_TYPE_VARIABLE_SIZE (t
))
342 /* Return the composite type of two compatible types.
344 We assume that comptypes has already been done and returned
345 nonzero; if that isn't so, this may crash. In particular, we
346 assume that qualifiers match. */
349 composite_type (tree t1
, tree t2
)
351 enum tree_code code1
;
352 enum tree_code code2
;
355 /* Save time if the two types are the same. */
357 if (t1
== t2
) return t1
;
359 /* If one type is nonsense, use the other. */
360 if (t1
== error_mark_node
)
362 if (t2
== error_mark_node
)
365 code1
= TREE_CODE (t1
);
366 code2
= TREE_CODE (t2
);
368 /* Merge the attributes. */
369 attributes
= targetm
.merge_type_attributes (t1
, t2
);
371 /* If one is an enumerated type and the other is the compatible
372 integer type, the composite type might be either of the two
373 (DR#013 question 3). For consistency, use the enumerated type as
374 the composite type. */
376 if (code1
== ENUMERAL_TYPE
&& code2
== INTEGER_TYPE
)
378 if (code2
== ENUMERAL_TYPE
&& code1
== INTEGER_TYPE
)
381 gcc_assert (code1
== code2
);
386 /* For two pointers, do this recursively on the target type. */
388 tree pointed_to_1
= TREE_TYPE (t1
);
389 tree pointed_to_2
= TREE_TYPE (t2
);
390 tree target
= composite_type (pointed_to_1
, pointed_to_2
);
391 t1
= build_pointer_type_for_mode (target
, TYPE_MODE (t1
), false);
392 t1
= build_type_attribute_variant (t1
, attributes
);
393 return qualify_type (t1
, t2
);
398 tree elt
= composite_type (TREE_TYPE (t1
), TREE_TYPE (t2
));
401 tree d1
= TYPE_DOMAIN (t1
);
402 tree d2
= TYPE_DOMAIN (t2
);
403 bool d1_variable
, d2_variable
;
404 bool d1_zero
, d2_zero
;
405 bool t1_complete
, t2_complete
;
407 /* We should not have any type quals on arrays at all. */
408 gcc_assert (!TYPE_QUALS_NO_ADDR_SPACE (t1
)
409 && !TYPE_QUALS_NO_ADDR_SPACE (t2
));
411 t1_complete
= COMPLETE_TYPE_P (t1
);
412 t2_complete
= COMPLETE_TYPE_P (t2
);
414 d1_zero
= d1
== 0 || !TYPE_MAX_VALUE (d1
);
415 d2_zero
= d2
== 0 || !TYPE_MAX_VALUE (d2
);
417 d1_variable
= (!d1_zero
418 && (TREE_CODE (TYPE_MIN_VALUE (d1
)) != INTEGER_CST
419 || TREE_CODE (TYPE_MAX_VALUE (d1
)) != INTEGER_CST
));
420 d2_variable
= (!d2_zero
421 && (TREE_CODE (TYPE_MIN_VALUE (d2
)) != INTEGER_CST
422 || TREE_CODE (TYPE_MAX_VALUE (d2
)) != INTEGER_CST
));
423 d1_variable
= d1_variable
|| (d1_zero
&& c_vla_type_p (t1
));
424 d2_variable
= d2_variable
|| (d2_zero
&& c_vla_type_p (t2
));
426 /* Save space: see if the result is identical to one of the args. */
427 if (elt
== TREE_TYPE (t1
) && TYPE_DOMAIN (t1
)
428 && (d2_variable
|| d2_zero
|| !d1_variable
))
429 return build_type_attribute_variant (t1
, attributes
);
430 if (elt
== TREE_TYPE (t2
) && TYPE_DOMAIN (t2
)
431 && (d1_variable
|| d1_zero
|| !d2_variable
))
432 return build_type_attribute_variant (t2
, attributes
);
434 if (elt
== TREE_TYPE (t1
) && !TYPE_DOMAIN (t2
) && !TYPE_DOMAIN (t1
))
435 return build_type_attribute_variant (t1
, attributes
);
436 if (elt
== TREE_TYPE (t2
) && !TYPE_DOMAIN (t2
) && !TYPE_DOMAIN (t1
))
437 return build_type_attribute_variant (t2
, attributes
);
439 /* Merge the element types, and have a size if either arg has
440 one. We may have qualifiers on the element types. To set
441 up TYPE_MAIN_VARIANT correctly, we need to form the
442 composite of the unqualified types and add the qualifiers
444 quals
= TYPE_QUALS (strip_array_types (elt
));
445 unqual_elt
= c_build_qualified_type (elt
, TYPE_UNQUALIFIED
);
446 t1
= build_array_type (unqual_elt
,
447 TYPE_DOMAIN ((TYPE_DOMAIN (t1
)
453 /* Ensure a composite type involving a zero-length array type
454 is a zero-length type not an incomplete type. */
455 if (d1_zero
&& d2_zero
456 && (t1_complete
|| t2_complete
)
457 && !COMPLETE_TYPE_P (t1
))
459 TYPE_SIZE (t1
) = bitsize_zero_node
;
460 TYPE_SIZE_UNIT (t1
) = size_zero_node
;
462 t1
= c_build_qualified_type (t1
, quals
);
463 return build_type_attribute_variant (t1
, attributes
);
469 if (attributes
!= NULL
)
471 /* Try harder not to create a new aggregate type. */
472 if (attribute_list_equal (TYPE_ATTRIBUTES (t1
), attributes
))
474 if (attribute_list_equal (TYPE_ATTRIBUTES (t2
), attributes
))
477 return build_type_attribute_variant (t1
, attributes
);
480 /* Function types: prefer the one that specified arg types.
481 If both do, merge the arg types. Also merge the return types. */
483 tree valtype
= composite_type (TREE_TYPE (t1
), TREE_TYPE (t2
));
484 tree p1
= TYPE_ARG_TYPES (t1
);
485 tree p2
= TYPE_ARG_TYPES (t2
);
490 /* Save space: see if the result is identical to one of the args. */
491 if (valtype
== TREE_TYPE (t1
) && !TYPE_ARG_TYPES (t2
))
492 return build_type_attribute_variant (t1
, attributes
);
493 if (valtype
== TREE_TYPE (t2
) && !TYPE_ARG_TYPES (t1
))
494 return build_type_attribute_variant (t2
, attributes
);
496 /* Simple way if one arg fails to specify argument types. */
497 if (TYPE_ARG_TYPES (t1
) == 0)
499 t1
= build_function_type (valtype
, TYPE_ARG_TYPES (t2
));
500 t1
= build_type_attribute_variant (t1
, attributes
);
501 return qualify_type (t1
, t2
);
503 if (TYPE_ARG_TYPES (t2
) == 0)
505 t1
= build_function_type (valtype
, TYPE_ARG_TYPES (t1
));
506 t1
= build_type_attribute_variant (t1
, attributes
);
507 return qualify_type (t1
, t2
);
510 /* If both args specify argument types, we must merge the two
511 lists, argument by argument. */
513 len
= list_length (p1
);
516 for (i
= 0; i
< len
; i
++)
517 newargs
= tree_cons (NULL_TREE
, NULL_TREE
, newargs
);
522 p1
= TREE_CHAIN (p1
), p2
= TREE_CHAIN (p2
), n
= TREE_CHAIN (n
))
524 /* A null type means arg type is not specified.
525 Take whatever the other function type has. */
526 if (TREE_VALUE (p1
) == 0)
528 TREE_VALUE (n
) = TREE_VALUE (p2
);
531 if (TREE_VALUE (p2
) == 0)
533 TREE_VALUE (n
) = TREE_VALUE (p1
);
537 /* Given wait (union {union wait *u; int *i} *)
538 and wait (union wait *),
539 prefer union wait * as type of parm. */
540 if (TREE_CODE (TREE_VALUE (p1
)) == UNION_TYPE
541 && TREE_VALUE (p1
) != TREE_VALUE (p2
))
544 tree mv2
= TREE_VALUE (p2
);
545 if (mv2
&& mv2
!= error_mark_node
546 && TREE_CODE (mv2
) != ARRAY_TYPE
)
547 mv2
= TYPE_MAIN_VARIANT (mv2
);
548 for (memb
= TYPE_FIELDS (TREE_VALUE (p1
));
549 memb
; memb
= DECL_CHAIN (memb
))
551 tree mv3
= TREE_TYPE (memb
);
552 if (mv3
&& mv3
!= error_mark_node
553 && TREE_CODE (mv3
) != ARRAY_TYPE
)
554 mv3
= TYPE_MAIN_VARIANT (mv3
);
555 if (comptypes (mv3
, mv2
))
557 TREE_VALUE (n
) = composite_type (TREE_TYPE (memb
),
559 pedwarn (input_location
, OPT_Wpedantic
,
560 "function types not truly compatible in ISO C");
565 if (TREE_CODE (TREE_VALUE (p2
)) == UNION_TYPE
566 && TREE_VALUE (p2
) != TREE_VALUE (p1
))
569 tree mv1
= TREE_VALUE (p1
);
570 if (mv1
&& mv1
!= error_mark_node
571 && TREE_CODE (mv1
) != ARRAY_TYPE
)
572 mv1
= TYPE_MAIN_VARIANT (mv1
);
573 for (memb
= TYPE_FIELDS (TREE_VALUE (p2
));
574 memb
; memb
= DECL_CHAIN (memb
))
576 tree mv3
= TREE_TYPE (memb
);
577 if (mv3
&& mv3
!= error_mark_node
578 && TREE_CODE (mv3
) != ARRAY_TYPE
)
579 mv3
= TYPE_MAIN_VARIANT (mv3
);
580 if (comptypes (mv3
, mv1
))
582 TREE_VALUE (n
) = composite_type (TREE_TYPE (memb
),
584 pedwarn (input_location
, OPT_Wpedantic
,
585 "function types not truly compatible in ISO C");
590 TREE_VALUE (n
) = composite_type (TREE_VALUE (p1
), TREE_VALUE (p2
));
594 t1
= build_function_type (valtype
, newargs
);
595 t1
= qualify_type (t1
, t2
);
596 /* ... falls through ... */
600 return build_type_attribute_variant (t1
, attributes
);
605 /* Return the type of a conditional expression between pointers to
606 possibly differently qualified versions of compatible types.
608 We assume that comp_target_types has already been done and returned
609 nonzero; if that isn't so, this may crash. */
612 common_pointer_type (tree t1
, tree t2
)
615 tree pointed_to_1
, mv1
;
616 tree pointed_to_2
, mv2
;
618 unsigned target_quals
;
619 addr_space_t as1
, as2
, as_common
;
622 /* Save time if the two types are the same. */
624 if (t1
== t2
) return t1
;
626 /* If one type is nonsense, use the other. */
627 if (t1
== error_mark_node
)
629 if (t2
== error_mark_node
)
632 gcc_assert (TREE_CODE (t1
) == POINTER_TYPE
633 && TREE_CODE (t2
) == POINTER_TYPE
);
635 /* Merge the attributes. */
636 attributes
= targetm
.merge_type_attributes (t1
, t2
);
638 /* Find the composite type of the target types, and combine the
639 qualifiers of the two types' targets. Do not lose qualifiers on
640 array element types by taking the TYPE_MAIN_VARIANT. */
641 mv1
= pointed_to_1
= TREE_TYPE (t1
);
642 mv2
= pointed_to_2
= TREE_TYPE (t2
);
643 if (TREE_CODE (mv1
) != ARRAY_TYPE
)
644 mv1
= TYPE_MAIN_VARIANT (pointed_to_1
);
645 if (TREE_CODE (mv2
) != ARRAY_TYPE
)
646 mv2
= TYPE_MAIN_VARIANT (pointed_to_2
);
647 target
= composite_type (mv1
, mv2
);
649 /* For function types do not merge const qualifiers, but drop them
650 if used inconsistently. The middle-end uses these to mark const
651 and noreturn functions. */
652 quals1
= TYPE_QUALS_NO_ADDR_SPACE (pointed_to_1
);
653 quals2
= TYPE_QUALS_NO_ADDR_SPACE (pointed_to_2
);
655 if (TREE_CODE (pointed_to_1
) == FUNCTION_TYPE
)
656 target_quals
= (quals1
& quals2
);
658 target_quals
= (quals1
| quals2
);
660 /* If the two named address spaces are different, determine the common
661 superset address space. This is guaranteed to exist due to the
662 assumption that comp_target_type returned non-zero. */
663 as1
= TYPE_ADDR_SPACE (pointed_to_1
);
664 as2
= TYPE_ADDR_SPACE (pointed_to_2
);
665 if (!addr_space_superset (as1
, as2
, &as_common
))
668 target_quals
|= ENCODE_QUAL_ADDR_SPACE (as_common
);
670 t1
= build_pointer_type (c_build_qualified_type (target
, target_quals
));
671 return build_type_attribute_variant (t1
, attributes
);
674 /* Return the common type for two arithmetic types under the usual
675 arithmetic conversions. The default conversions have already been
676 applied, and enumerated types converted to their compatible integer
677 types. The resulting type is unqualified and has no attributes.
679 This is the type for the result of most arithmetic operations
680 if the operands have the given two types. */
683 c_common_type (tree t1
, tree t2
)
685 enum tree_code code1
;
686 enum tree_code code2
;
688 /* If one type is nonsense, use the other. */
689 if (t1
== error_mark_node
)
691 if (t2
== error_mark_node
)
694 if (TYPE_QUALS (t1
) != TYPE_UNQUALIFIED
)
695 t1
= TYPE_MAIN_VARIANT (t1
);
697 if (TYPE_QUALS (t2
) != TYPE_UNQUALIFIED
)
698 t2
= TYPE_MAIN_VARIANT (t2
);
700 if (TYPE_ATTRIBUTES (t1
) != NULL_TREE
)
701 t1
= build_type_attribute_variant (t1
, NULL_TREE
);
703 if (TYPE_ATTRIBUTES (t2
) != NULL_TREE
)
704 t2
= build_type_attribute_variant (t2
, NULL_TREE
);
706 /* Save time if the two types are the same. */
708 if (t1
== t2
) return t1
;
710 code1
= TREE_CODE (t1
);
711 code2
= TREE_CODE (t2
);
713 gcc_assert (code1
== VECTOR_TYPE
|| code1
== COMPLEX_TYPE
714 || code1
== FIXED_POINT_TYPE
|| code1
== REAL_TYPE
715 || code1
== INTEGER_TYPE
);
716 gcc_assert (code2
== VECTOR_TYPE
|| code2
== COMPLEX_TYPE
717 || code2
== FIXED_POINT_TYPE
|| code2
== REAL_TYPE
718 || code2
== INTEGER_TYPE
);
720 /* When one operand is a decimal float type, the other operand cannot be
721 a generic float type or a complex type. We also disallow vector types
723 if ((DECIMAL_FLOAT_TYPE_P (t1
) || DECIMAL_FLOAT_TYPE_P (t2
))
724 && !(DECIMAL_FLOAT_TYPE_P (t1
) && DECIMAL_FLOAT_TYPE_P (t2
)))
726 if (code1
== VECTOR_TYPE
|| code2
== VECTOR_TYPE
)
728 error ("can%'t mix operands of decimal float and vector types");
729 return error_mark_node
;
731 if (code1
== COMPLEX_TYPE
|| code2
== COMPLEX_TYPE
)
733 error ("can%'t mix operands of decimal float and complex types");
734 return error_mark_node
;
736 if (code1
== REAL_TYPE
&& code2
== REAL_TYPE
)
738 error ("can%'t mix operands of decimal float and other float types");
739 return error_mark_node
;
743 /* If one type is a vector type, return that type. (How the usual
744 arithmetic conversions apply to the vector types extension is not
745 precisely specified.) */
746 if (code1
== VECTOR_TYPE
)
749 if (code2
== VECTOR_TYPE
)
752 /* If one type is complex, form the common type of the non-complex
753 components, then make that complex. Use T1 or T2 if it is the
755 if (code1
== COMPLEX_TYPE
|| code2
== COMPLEX_TYPE
)
757 tree subtype1
= code1
== COMPLEX_TYPE
? TREE_TYPE (t1
) : t1
;
758 tree subtype2
= code2
== COMPLEX_TYPE
? TREE_TYPE (t2
) : t2
;
759 tree subtype
= c_common_type (subtype1
, subtype2
);
761 if (code1
== COMPLEX_TYPE
&& TREE_TYPE (t1
) == subtype
)
763 else if (code2
== COMPLEX_TYPE
&& TREE_TYPE (t2
) == subtype
)
766 return build_complex_type (subtype
);
769 /* If only one is real, use it as the result. */
771 if (code1
== REAL_TYPE
&& code2
!= REAL_TYPE
)
774 if (code2
== REAL_TYPE
&& code1
!= REAL_TYPE
)
777 /* If both are real and either are decimal floating point types, use
778 the decimal floating point type with the greater precision. */
780 if (code1
== REAL_TYPE
&& code2
== REAL_TYPE
)
782 if (TYPE_MAIN_VARIANT (t1
) == dfloat128_type_node
783 || TYPE_MAIN_VARIANT (t2
) == dfloat128_type_node
)
784 return dfloat128_type_node
;
785 else if (TYPE_MAIN_VARIANT (t1
) == dfloat64_type_node
786 || TYPE_MAIN_VARIANT (t2
) == dfloat64_type_node
)
787 return dfloat64_type_node
;
788 else if (TYPE_MAIN_VARIANT (t1
) == dfloat32_type_node
789 || TYPE_MAIN_VARIANT (t2
) == dfloat32_type_node
)
790 return dfloat32_type_node
;
793 /* Deal with fixed-point types. */
794 if (code1
== FIXED_POINT_TYPE
|| code2
== FIXED_POINT_TYPE
)
796 unsigned int unsignedp
= 0, satp
= 0;
797 enum machine_mode m1
, m2
;
798 unsigned int fbit1
, ibit1
, fbit2
, ibit2
, max_fbit
, max_ibit
;
803 /* If one input type is saturating, the result type is saturating. */
804 if (TYPE_SATURATING (t1
) || TYPE_SATURATING (t2
))
807 /* If both fixed-point types are unsigned, the result type is unsigned.
808 When mixing fixed-point and integer types, follow the sign of the
810 Otherwise, the result type is signed. */
811 if ((TYPE_UNSIGNED (t1
) && TYPE_UNSIGNED (t2
)
812 && code1
== FIXED_POINT_TYPE
&& code2
== FIXED_POINT_TYPE
)
813 || (code1
== FIXED_POINT_TYPE
&& code2
!= FIXED_POINT_TYPE
814 && TYPE_UNSIGNED (t1
))
815 || (code1
!= FIXED_POINT_TYPE
&& code2
== FIXED_POINT_TYPE
816 && TYPE_UNSIGNED (t2
)))
819 /* The result type is signed. */
822 /* If the input type is unsigned, we need to convert to the
824 if (code1
== FIXED_POINT_TYPE
&& TYPE_UNSIGNED (t1
))
826 enum mode_class mclass
= (enum mode_class
) 0;
827 if (GET_MODE_CLASS (m1
) == MODE_UFRACT
)
829 else if (GET_MODE_CLASS (m1
) == MODE_UACCUM
)
833 m1
= mode_for_size (GET_MODE_PRECISION (m1
), mclass
, 0);
835 if (code2
== FIXED_POINT_TYPE
&& TYPE_UNSIGNED (t2
))
837 enum mode_class mclass
= (enum mode_class
) 0;
838 if (GET_MODE_CLASS (m2
) == MODE_UFRACT
)
840 else if (GET_MODE_CLASS (m2
) == MODE_UACCUM
)
844 m2
= mode_for_size (GET_MODE_PRECISION (m2
), mclass
, 0);
848 if (code1
== FIXED_POINT_TYPE
)
850 fbit1
= GET_MODE_FBIT (m1
);
851 ibit1
= GET_MODE_IBIT (m1
);
856 /* Signed integers need to subtract one sign bit. */
857 ibit1
= TYPE_PRECISION (t1
) - (!TYPE_UNSIGNED (t1
));
860 if (code2
== FIXED_POINT_TYPE
)
862 fbit2
= GET_MODE_FBIT (m2
);
863 ibit2
= GET_MODE_IBIT (m2
);
868 /* Signed integers need to subtract one sign bit. */
869 ibit2
= TYPE_PRECISION (t2
) - (!TYPE_UNSIGNED (t2
));
872 max_ibit
= ibit1
>= ibit2
? ibit1
: ibit2
;
873 max_fbit
= fbit1
>= fbit2
? fbit1
: fbit2
;
874 return c_common_fixed_point_type_for_size (max_ibit
, max_fbit
, unsignedp
,
878 /* Both real or both integers; use the one with greater precision. */
880 if (TYPE_PRECISION (t1
) > TYPE_PRECISION (t2
))
882 else if (TYPE_PRECISION (t2
) > TYPE_PRECISION (t1
))
885 /* Same precision. Prefer long longs to longs to ints when the
886 same precision, following the C99 rules on integer type rank
887 (which are equivalent to the C90 rules for C90 types). */
889 if (TYPE_MAIN_VARIANT (t1
) == long_long_unsigned_type_node
890 || TYPE_MAIN_VARIANT (t2
) == long_long_unsigned_type_node
)
891 return long_long_unsigned_type_node
;
893 if (TYPE_MAIN_VARIANT (t1
) == long_long_integer_type_node
894 || TYPE_MAIN_VARIANT (t2
) == long_long_integer_type_node
)
896 if (TYPE_UNSIGNED (t1
) || TYPE_UNSIGNED (t2
))
897 return long_long_unsigned_type_node
;
899 return long_long_integer_type_node
;
902 if (TYPE_MAIN_VARIANT (t1
) == long_unsigned_type_node
903 || TYPE_MAIN_VARIANT (t2
) == long_unsigned_type_node
)
904 return long_unsigned_type_node
;
906 if (TYPE_MAIN_VARIANT (t1
) == long_integer_type_node
907 || TYPE_MAIN_VARIANT (t2
) == long_integer_type_node
)
909 /* But preserve unsignedness from the other type,
910 since long cannot hold all the values of an unsigned int. */
911 if (TYPE_UNSIGNED (t1
) || TYPE_UNSIGNED (t2
))
912 return long_unsigned_type_node
;
914 return long_integer_type_node
;
917 /* Likewise, prefer long double to double even if same size. */
918 if (TYPE_MAIN_VARIANT (t1
) == long_double_type_node
919 || TYPE_MAIN_VARIANT (t2
) == long_double_type_node
)
920 return long_double_type_node
;
922 /* Likewise, prefer double to float even if same size.
923 We got a couple of embedded targets with 32 bit doubles, and the
924 pdp11 might have 64 bit floats. */
925 if (TYPE_MAIN_VARIANT (t1
) == double_type_node
926 || TYPE_MAIN_VARIANT (t2
) == double_type_node
)
927 return double_type_node
;
929 /* Otherwise prefer the unsigned one. */
931 if (TYPE_UNSIGNED (t1
))
937 /* Wrapper around c_common_type that is used by c-common.c and other
938 front end optimizations that remove promotions. ENUMERAL_TYPEs
939 are allowed here and are converted to their compatible integer types.
940 BOOLEAN_TYPEs are allowed here and return either boolean_type_node or
941 preferably a non-Boolean type as the common type. */
943 common_type (tree t1
, tree t2
)
945 if (TREE_CODE (t1
) == ENUMERAL_TYPE
)
946 t1
= c_common_type_for_size (TYPE_PRECISION (t1
), 1);
947 if (TREE_CODE (t2
) == ENUMERAL_TYPE
)
948 t2
= c_common_type_for_size (TYPE_PRECISION (t2
), 1);
950 /* If both types are BOOLEAN_TYPE, then return boolean_type_node. */
951 if (TREE_CODE (t1
) == BOOLEAN_TYPE
952 && TREE_CODE (t2
) == BOOLEAN_TYPE
)
953 return boolean_type_node
;
955 /* If either type is BOOLEAN_TYPE, then return the other. */
956 if (TREE_CODE (t1
) == BOOLEAN_TYPE
)
958 if (TREE_CODE (t2
) == BOOLEAN_TYPE
)
961 return c_common_type (t1
, t2
);
964 /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
965 or various other operations. Return 2 if they are compatible
966 but a warning may be needed if you use them together. */
969 comptypes (tree type1
, tree type2
)
971 const struct tagged_tu_seen_cache
* tagged_tu_seen_base1
= tagged_tu_seen_base
;
974 val
= comptypes_internal (type1
, type2
, NULL
, NULL
);
975 free_all_tagged_tu_seen_up_to (tagged_tu_seen_base1
);
980 /* Like comptypes, but if it returns non-zero because enum and int are
981 compatible, it sets *ENUM_AND_INT_P to true. */
984 comptypes_check_enum_int (tree type1
, tree type2
, bool *enum_and_int_p
)
986 const struct tagged_tu_seen_cache
* tagged_tu_seen_base1
= tagged_tu_seen_base
;
989 val
= comptypes_internal (type1
, type2
, enum_and_int_p
, NULL
);
990 free_all_tagged_tu_seen_up_to (tagged_tu_seen_base1
);
995 /* Like comptypes, but if it returns nonzero for different types, it
996 sets *DIFFERENT_TYPES_P to true. */
999 comptypes_check_different_types (tree type1
, tree type2
,
1000 bool *different_types_p
)
1002 const struct tagged_tu_seen_cache
* tagged_tu_seen_base1
= tagged_tu_seen_base
;
1005 val
= comptypes_internal (type1
, type2
, NULL
, different_types_p
);
1006 free_all_tagged_tu_seen_up_to (tagged_tu_seen_base1
);
1011 /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
1012 or various other operations. Return 2 if they are compatible
1013 but a warning may be needed if you use them together. If
1014 ENUM_AND_INT_P is not NULL, and one type is an enum and the other a
1015 compatible integer type, then this sets *ENUM_AND_INT_P to true;
1016 *ENUM_AND_INT_P is never set to false. If DIFFERENT_TYPES_P is not
1017 NULL, and the types are compatible but different enough not to be
1018 permitted in C11 typedef redeclarations, then this sets
1019 *DIFFERENT_TYPES_P to true; *DIFFERENT_TYPES_P is never set to
1020 false, but may or may not be set if the types are incompatible.
1021 This differs from comptypes, in that we don't free the seen
1025 comptypes_internal (const_tree type1
, const_tree type2
, bool *enum_and_int_p
,
1026 bool *different_types_p
)
1028 const_tree t1
= type1
;
1029 const_tree t2
= type2
;
1032 /* Suppress errors caused by previously reported errors. */
1034 if (t1
== t2
|| !t1
|| !t2
1035 || TREE_CODE (t1
) == ERROR_MARK
|| TREE_CODE (t2
) == ERROR_MARK
)
1038 /* Enumerated types are compatible with integer types, but this is
1039 not transitive: two enumerated types in the same translation unit
1040 are compatible with each other only if they are the same type. */
1042 if (TREE_CODE (t1
) == ENUMERAL_TYPE
&& TREE_CODE (t2
) != ENUMERAL_TYPE
)
1044 t1
= c_common_type_for_size (TYPE_PRECISION (t1
), TYPE_UNSIGNED (t1
));
1045 if (TREE_CODE (t2
) != VOID_TYPE
)
1047 if (enum_and_int_p
!= NULL
)
1048 *enum_and_int_p
= true;
1049 if (different_types_p
!= NULL
)
1050 *different_types_p
= true;
1053 else if (TREE_CODE (t2
) == ENUMERAL_TYPE
&& TREE_CODE (t1
) != ENUMERAL_TYPE
)
1055 t2
= c_common_type_for_size (TYPE_PRECISION (t2
), TYPE_UNSIGNED (t2
));
1056 if (TREE_CODE (t1
) != VOID_TYPE
)
1058 if (enum_and_int_p
!= NULL
)
1059 *enum_and_int_p
= true;
1060 if (different_types_p
!= NULL
)
1061 *different_types_p
= true;
1068 /* Different classes of types can't be compatible. */
1070 if (TREE_CODE (t1
) != TREE_CODE (t2
))
1073 /* Qualifiers must match. C99 6.7.3p9 */
1075 if (TYPE_QUALS (t1
) != TYPE_QUALS (t2
))
1078 /* Allow for two different type nodes which have essentially the same
1079 definition. Note that we already checked for equality of the type
1080 qualifiers (just above). */
1082 if (TREE_CODE (t1
) != ARRAY_TYPE
1083 && TYPE_MAIN_VARIANT (t1
) == TYPE_MAIN_VARIANT (t2
))
1086 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
1087 if (!(attrval
= comp_type_attributes (t1
, t2
)))
1090 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
1093 switch (TREE_CODE (t1
))
1096 /* Do not remove mode or aliasing information. */
1097 if (TYPE_MODE (t1
) != TYPE_MODE (t2
)
1098 || TYPE_REF_CAN_ALIAS_ALL (t1
) != TYPE_REF_CAN_ALIAS_ALL (t2
))
1100 val
= (TREE_TYPE (t1
) == TREE_TYPE (t2
)
1101 ? 1 : comptypes_internal (TREE_TYPE (t1
), TREE_TYPE (t2
),
1102 enum_and_int_p
, different_types_p
));
1106 val
= function_types_compatible_p (t1
, t2
, enum_and_int_p
,
1112 tree d1
= TYPE_DOMAIN (t1
);
1113 tree d2
= TYPE_DOMAIN (t2
);
1114 bool d1_variable
, d2_variable
;
1115 bool d1_zero
, d2_zero
;
1118 /* Target types must match incl. qualifiers. */
1119 if (TREE_TYPE (t1
) != TREE_TYPE (t2
)
1120 && 0 == (val
= comptypes_internal (TREE_TYPE (t1
), TREE_TYPE (t2
),
1122 different_types_p
)))
1125 if (different_types_p
!= NULL
1126 && (d1
== 0) != (d2
== 0))
1127 *different_types_p
= true;
1128 /* Sizes must match unless one is missing or variable. */
1129 if (d1
== 0 || d2
== 0 || d1
== d2
)
1132 d1_zero
= !TYPE_MAX_VALUE (d1
);
1133 d2_zero
= !TYPE_MAX_VALUE (d2
);
1135 d1_variable
= (!d1_zero
1136 && (TREE_CODE (TYPE_MIN_VALUE (d1
)) != INTEGER_CST
1137 || TREE_CODE (TYPE_MAX_VALUE (d1
)) != INTEGER_CST
));
1138 d2_variable
= (!d2_zero
1139 && (TREE_CODE (TYPE_MIN_VALUE (d2
)) != INTEGER_CST
1140 || TREE_CODE (TYPE_MAX_VALUE (d2
)) != INTEGER_CST
));
1141 d1_variable
= d1_variable
|| (d1_zero
&& c_vla_type_p (t1
));
1142 d2_variable
= d2_variable
|| (d2_zero
&& c_vla_type_p (t2
));
1144 if (different_types_p
!= NULL
1145 && d1_variable
!= d2_variable
)
1146 *different_types_p
= true;
1147 if (d1_variable
|| d2_variable
)
1149 if (d1_zero
&& d2_zero
)
1151 if (d1_zero
|| d2_zero
1152 || !tree_int_cst_equal (TYPE_MIN_VALUE (d1
), TYPE_MIN_VALUE (d2
))
1153 || !tree_int_cst_equal (TYPE_MAX_VALUE (d1
), TYPE_MAX_VALUE (d2
)))
1162 if (val
!= 1 && !same_translation_unit_p (t1
, t2
))
1164 tree a1
= TYPE_ATTRIBUTES (t1
);
1165 tree a2
= TYPE_ATTRIBUTES (t2
);
1167 if (! attribute_list_contained (a1
, a2
)
1168 && ! attribute_list_contained (a2
, a1
))
1172 return tagged_types_tu_compatible_p (t1
, t2
, enum_and_int_p
,
1174 val
= tagged_types_tu_compatible_p (t1
, t2
, enum_and_int_p
,
1180 val
= (TYPE_VECTOR_SUBPARTS (t1
) == TYPE_VECTOR_SUBPARTS (t2
)
1181 && comptypes_internal (TREE_TYPE (t1
), TREE_TYPE (t2
),
1182 enum_and_int_p
, different_types_p
));
1188 return attrval
== 2 && val
== 1 ? 2 : val
;
1191 /* Return 1 if TTL and TTR are pointers to types that are equivalent, ignoring
1192 their qualifiers, except for named address spaces. If the pointers point to
1193 different named addresses, then we must determine if one address space is a
1194 subset of the other. */
1197 comp_target_types (location_t location
, tree ttl
, tree ttr
)
1200 tree mvl
= TREE_TYPE (ttl
);
1201 tree mvr
= TREE_TYPE (ttr
);
1202 addr_space_t asl
= TYPE_ADDR_SPACE (mvl
);
1203 addr_space_t asr
= TYPE_ADDR_SPACE (mvr
);
1204 addr_space_t as_common
;
1205 bool enum_and_int_p
;
1207 /* Fail if pointers point to incompatible address spaces. */
1208 if (!addr_space_superset (asl
, asr
, &as_common
))
1211 /* Do not lose qualifiers on element types of array types that are
1212 pointer targets by taking their TYPE_MAIN_VARIANT. */
1213 if (TREE_CODE (mvl
) != ARRAY_TYPE
)
1214 mvl
= TYPE_MAIN_VARIANT (mvl
);
1215 if (TREE_CODE (mvr
) != ARRAY_TYPE
)
1216 mvr
= TYPE_MAIN_VARIANT (mvr
);
1217 enum_and_int_p
= false;
1218 val
= comptypes_check_enum_int (mvl
, mvr
, &enum_and_int_p
);
1221 pedwarn (location
, OPT_Wpedantic
, "types are not quite compatible");
1223 if (val
== 1 && enum_and_int_p
&& warn_cxx_compat
)
1224 warning_at (location
, OPT_Wc___compat
,
1225 "pointer target types incompatible in C++");
1230 /* Subroutines of `comptypes'. */
1232 /* Determine whether two trees derive from the same translation unit.
1233 If the CONTEXT chain ends in a null, that tree's context is still
1234 being parsed, so if two trees have context chains ending in null,
1235 they're in the same translation unit. */
1237 same_translation_unit_p (const_tree t1
, const_tree t2
)
1239 while (t1
&& TREE_CODE (t1
) != TRANSLATION_UNIT_DECL
)
1240 switch (TREE_CODE_CLASS (TREE_CODE (t1
)))
1242 case tcc_declaration
:
1243 t1
= DECL_CONTEXT (t1
); break;
1245 t1
= TYPE_CONTEXT (t1
); break;
1246 case tcc_exceptional
:
1247 t1
= BLOCK_SUPERCONTEXT (t1
); break; /* assume block */
1248 default: gcc_unreachable ();
1251 while (t2
&& TREE_CODE (t2
) != TRANSLATION_UNIT_DECL
)
1252 switch (TREE_CODE_CLASS (TREE_CODE (t2
)))
1254 case tcc_declaration
:
1255 t2
= DECL_CONTEXT (t2
); break;
1257 t2
= TYPE_CONTEXT (t2
); break;
1258 case tcc_exceptional
:
1259 t2
= BLOCK_SUPERCONTEXT (t2
); break; /* assume block */
1260 default: gcc_unreachable ();
1266 /* Allocate the seen two types, assuming that they are compatible. */
1268 static struct tagged_tu_seen_cache
*
1269 alloc_tagged_tu_seen_cache (const_tree t1
, const_tree t2
)
1271 struct tagged_tu_seen_cache
*tu
= XNEW (struct tagged_tu_seen_cache
);
1272 tu
->next
= tagged_tu_seen_base
;
1276 tagged_tu_seen_base
= tu
;
1278 /* The C standard says that two structures in different translation
1279 units are compatible with each other only if the types of their
1280 fields are compatible (among other things). We assume that they
1281 are compatible until proven otherwise when building the cache.
1282 An example where this can occur is:
1287 If we are comparing this against a similar struct in another TU,
1288 and did not assume they were compatible, we end up with an infinite
1294 /* Free the seen types until we get to TU_TIL. */
1297 free_all_tagged_tu_seen_up_to (const struct tagged_tu_seen_cache
*tu_til
)
1299 const struct tagged_tu_seen_cache
*tu
= tagged_tu_seen_base
;
1300 while (tu
!= tu_til
)
1302 const struct tagged_tu_seen_cache
*const tu1
1303 = (const struct tagged_tu_seen_cache
*) tu
;
1305 free (CONST_CAST (struct tagged_tu_seen_cache
*, tu1
));
1307 tagged_tu_seen_base
= tu_til
;
1310 /* Return 1 if two 'struct', 'union', or 'enum' types T1 and T2 are
1311 compatible. If the two types are not the same (which has been
1312 checked earlier), this can only happen when multiple translation
1313 units are being compiled. See C99 6.2.7 paragraph 1 for the exact
1314 rules. ENUM_AND_INT_P and DIFFERENT_TYPES_P are as in
1315 comptypes_internal. */
1318 tagged_types_tu_compatible_p (const_tree t1
, const_tree t2
,
1319 bool *enum_and_int_p
, bool *different_types_p
)
1322 bool needs_warning
= false;
1324 /* We have to verify that the tags of the types are the same. This
1325 is harder than it looks because this may be a typedef, so we have
1326 to go look at the original type. It may even be a typedef of a
1328 In the case of compiler-created builtin structs the TYPE_DECL
1329 may be a dummy, with no DECL_ORIGINAL_TYPE. Don't fault. */
1330 while (TYPE_NAME (t1
)
1331 && TREE_CODE (TYPE_NAME (t1
)) == TYPE_DECL
1332 && DECL_ORIGINAL_TYPE (TYPE_NAME (t1
)))
1333 t1
= DECL_ORIGINAL_TYPE (TYPE_NAME (t1
));
1335 while (TYPE_NAME (t2
)
1336 && TREE_CODE (TYPE_NAME (t2
)) == TYPE_DECL
1337 && DECL_ORIGINAL_TYPE (TYPE_NAME (t2
)))
1338 t2
= DECL_ORIGINAL_TYPE (TYPE_NAME (t2
));
1340 /* C90 didn't have the requirement that the two tags be the same. */
1341 if (flag_isoc99
&& TYPE_NAME (t1
) != TYPE_NAME (t2
))
1344 /* C90 didn't say what happened if one or both of the types were
1345 incomplete; we choose to follow C99 rules here, which is that they
1347 if (TYPE_SIZE (t1
) == NULL
1348 || TYPE_SIZE (t2
) == NULL
)
1352 const struct tagged_tu_seen_cache
* tts_i
;
1353 for (tts_i
= tagged_tu_seen_base
; tts_i
!= NULL
; tts_i
= tts_i
->next
)
1354 if (tts_i
->t1
== t1
&& tts_i
->t2
== t2
)
1358 switch (TREE_CODE (t1
))
1362 struct tagged_tu_seen_cache
*tu
= alloc_tagged_tu_seen_cache (t1
, t2
);
1363 /* Speed up the case where the type values are in the same order. */
1364 tree tv1
= TYPE_VALUES (t1
);
1365 tree tv2
= TYPE_VALUES (t2
);
1372 for (;tv1
&& tv2
; tv1
= TREE_CHAIN (tv1
), tv2
= TREE_CHAIN (tv2
))
1374 if (TREE_PURPOSE (tv1
) != TREE_PURPOSE (tv2
))
1376 if (simple_cst_equal (TREE_VALUE (tv1
), TREE_VALUE (tv2
)) != 1)
1383 if (tv1
== NULL_TREE
&& tv2
== NULL_TREE
)
1387 if (tv1
== NULL_TREE
|| tv2
== NULL_TREE
)
1393 if (list_length (TYPE_VALUES (t1
)) != list_length (TYPE_VALUES (t2
)))
1399 for (s1
= TYPE_VALUES (t1
); s1
; s1
= TREE_CHAIN (s1
))
1401 s2
= purpose_member (TREE_PURPOSE (s1
), TYPE_VALUES (t2
));
1403 || simple_cst_equal (TREE_VALUE (s1
), TREE_VALUE (s2
)) != 1)
1414 struct tagged_tu_seen_cache
*tu
= alloc_tagged_tu_seen_cache (t1
, t2
);
1415 if (list_length (TYPE_FIELDS (t1
)) != list_length (TYPE_FIELDS (t2
)))
1421 /* Speed up the common case where the fields are in the same order. */
1422 for (s1
= TYPE_FIELDS (t1
), s2
= TYPE_FIELDS (t2
); s1
&& s2
;
1423 s1
= DECL_CHAIN (s1
), s2
= DECL_CHAIN (s2
))
1427 if (DECL_NAME (s1
) != DECL_NAME (s2
))
1429 result
= comptypes_internal (TREE_TYPE (s1
), TREE_TYPE (s2
),
1430 enum_and_int_p
, different_types_p
);
1432 if (result
!= 1 && !DECL_NAME (s1
))
1440 needs_warning
= true;
1442 if (TREE_CODE (s1
) == FIELD_DECL
1443 && simple_cst_equal (DECL_FIELD_BIT_OFFSET (s1
),
1444 DECL_FIELD_BIT_OFFSET (s2
)) != 1)
1452 tu
->val
= needs_warning
? 2 : 1;
1456 for (s1
= TYPE_FIELDS (t1
); s1
; s1
= DECL_CHAIN (s1
))
1460 for (s2
= TYPE_FIELDS (t2
); s2
; s2
= DECL_CHAIN (s2
))
1461 if (DECL_NAME (s1
) == DECL_NAME (s2
))
1465 result
= comptypes_internal (TREE_TYPE (s1
), TREE_TYPE (s2
),
1469 if (result
!= 1 && !DECL_NAME (s1
))
1477 needs_warning
= true;
1479 if (TREE_CODE (s1
) == FIELD_DECL
1480 && simple_cst_equal (DECL_FIELD_BIT_OFFSET (s1
),
1481 DECL_FIELD_BIT_OFFSET (s2
)) != 1)
1493 tu
->val
= needs_warning
? 2 : 10;
1499 struct tagged_tu_seen_cache
*tu
= alloc_tagged_tu_seen_cache (t1
, t2
);
1501 for (s1
= TYPE_FIELDS (t1
), s2
= TYPE_FIELDS (t2
);
1503 s1
= DECL_CHAIN (s1
), s2
= DECL_CHAIN (s2
))
1506 if (TREE_CODE (s1
) != TREE_CODE (s2
)
1507 || DECL_NAME (s1
) != DECL_NAME (s2
))
1509 result
= comptypes_internal (TREE_TYPE (s1
), TREE_TYPE (s2
),
1510 enum_and_int_p
, different_types_p
);
1514 needs_warning
= true;
1516 if (TREE_CODE (s1
) == FIELD_DECL
1517 && simple_cst_equal (DECL_FIELD_BIT_OFFSET (s1
),
1518 DECL_FIELD_BIT_OFFSET (s2
)) != 1)
1524 tu
->val
= needs_warning
? 2 : 1;
1533 /* Return 1 if two function types F1 and F2 are compatible.
1534 If either type specifies no argument types,
1535 the other must specify a fixed number of self-promoting arg types.
1536 Otherwise, if one type specifies only the number of arguments,
1537 the other must specify that number of self-promoting arg types.
1538 Otherwise, the argument types must match.
1539 ENUM_AND_INT_P and DIFFERENT_TYPES_P are as in comptypes_internal. */
1542 function_types_compatible_p (const_tree f1
, const_tree f2
,
1543 bool *enum_and_int_p
, bool *different_types_p
)
1546 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
1551 ret1
= TREE_TYPE (f1
);
1552 ret2
= TREE_TYPE (f2
);
1554 /* 'volatile' qualifiers on a function's return type used to mean
1555 the function is noreturn. */
1556 if (TYPE_VOLATILE (ret1
) != TYPE_VOLATILE (ret2
))
1557 pedwarn (input_location
, 0, "function return types not compatible due to %<volatile%>");
1558 if (TYPE_VOLATILE (ret1
))
1559 ret1
= build_qualified_type (TYPE_MAIN_VARIANT (ret1
),
1560 TYPE_QUALS (ret1
) & ~TYPE_QUAL_VOLATILE
);
1561 if (TYPE_VOLATILE (ret2
))
1562 ret2
= build_qualified_type (TYPE_MAIN_VARIANT (ret2
),
1563 TYPE_QUALS (ret2
) & ~TYPE_QUAL_VOLATILE
);
1564 val
= comptypes_internal (ret1
, ret2
, enum_and_int_p
, different_types_p
);
1568 args1
= TYPE_ARG_TYPES (f1
);
1569 args2
= TYPE_ARG_TYPES (f2
);
1571 if (different_types_p
!= NULL
1572 && (args1
== 0) != (args2
== 0))
1573 *different_types_p
= true;
1575 /* An unspecified parmlist matches any specified parmlist
1576 whose argument types don't need default promotions. */
1580 if (!self_promoting_args_p (args2
))
1582 /* If one of these types comes from a non-prototype fn definition,
1583 compare that with the other type's arglist.
1584 If they don't match, ask for a warning (but no error). */
1585 if (TYPE_ACTUAL_ARG_TYPES (f1
)
1586 && 1 != type_lists_compatible_p (args2
, TYPE_ACTUAL_ARG_TYPES (f1
),
1587 enum_and_int_p
, different_types_p
))
1593 if (!self_promoting_args_p (args1
))
1595 if (TYPE_ACTUAL_ARG_TYPES (f2
)
1596 && 1 != type_lists_compatible_p (args1
, TYPE_ACTUAL_ARG_TYPES (f2
),
1597 enum_and_int_p
, different_types_p
))
1602 /* Both types have argument lists: compare them and propagate results. */
1603 val1
= type_lists_compatible_p (args1
, args2
, enum_and_int_p
,
1605 return val1
!= 1 ? val1
: val
;
1608 /* Check two lists of types for compatibility, returning 0 for
1609 incompatible, 1 for compatible, or 2 for compatible with
1610 warning. ENUM_AND_INT_P and DIFFERENT_TYPES_P are as in
1611 comptypes_internal. */
1614 type_lists_compatible_p (const_tree args1
, const_tree args2
,
1615 bool *enum_and_int_p
, bool *different_types_p
)
1617 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
1623 tree a1
, mv1
, a2
, mv2
;
1624 if (args1
== 0 && args2
== 0)
1626 /* If one list is shorter than the other,
1627 they fail to match. */
1628 if (args1
== 0 || args2
== 0)
1630 mv1
= a1
= TREE_VALUE (args1
);
1631 mv2
= a2
= TREE_VALUE (args2
);
1632 if (mv1
&& mv1
!= error_mark_node
&& TREE_CODE (mv1
) != ARRAY_TYPE
)
1633 mv1
= TYPE_MAIN_VARIANT (mv1
);
1634 if (mv2
&& mv2
!= error_mark_node
&& TREE_CODE (mv2
) != ARRAY_TYPE
)
1635 mv2
= TYPE_MAIN_VARIANT (mv2
);
1636 /* A null pointer instead of a type
1637 means there is supposed to be an argument
1638 but nothing is specified about what type it has.
1639 So match anything that self-promotes. */
1640 if (different_types_p
!= NULL
1641 && (a1
== 0) != (a2
== 0))
1642 *different_types_p
= true;
1645 if (c_type_promotes_to (a2
) != a2
)
1650 if (c_type_promotes_to (a1
) != a1
)
1653 /* If one of the lists has an error marker, ignore this arg. */
1654 else if (TREE_CODE (a1
) == ERROR_MARK
1655 || TREE_CODE (a2
) == ERROR_MARK
)
1657 else if (!(newval
= comptypes_internal (mv1
, mv2
, enum_and_int_p
,
1658 different_types_p
)))
1660 if (different_types_p
!= NULL
)
1661 *different_types_p
= true;
1662 /* Allow wait (union {union wait *u; int *i} *)
1663 and wait (union wait *) to be compatible. */
1664 if (TREE_CODE (a1
) == UNION_TYPE
1665 && (TYPE_NAME (a1
) == 0
1666 || TYPE_TRANSPARENT_AGGR (a1
))
1667 && TREE_CODE (TYPE_SIZE (a1
)) == INTEGER_CST
1668 && tree_int_cst_equal (TYPE_SIZE (a1
),
1672 for (memb
= TYPE_FIELDS (a1
);
1673 memb
; memb
= DECL_CHAIN (memb
))
1675 tree mv3
= TREE_TYPE (memb
);
1676 if (mv3
&& mv3
!= error_mark_node
1677 && TREE_CODE (mv3
) != ARRAY_TYPE
)
1678 mv3
= TYPE_MAIN_VARIANT (mv3
);
1679 if (comptypes_internal (mv3
, mv2
, enum_and_int_p
,
1686 else if (TREE_CODE (a2
) == UNION_TYPE
1687 && (TYPE_NAME (a2
) == 0
1688 || TYPE_TRANSPARENT_AGGR (a2
))
1689 && TREE_CODE (TYPE_SIZE (a2
)) == INTEGER_CST
1690 && tree_int_cst_equal (TYPE_SIZE (a2
),
1694 for (memb
= TYPE_FIELDS (a2
);
1695 memb
; memb
= DECL_CHAIN (memb
))
1697 tree mv3
= TREE_TYPE (memb
);
1698 if (mv3
&& mv3
!= error_mark_node
1699 && TREE_CODE (mv3
) != ARRAY_TYPE
)
1700 mv3
= TYPE_MAIN_VARIANT (mv3
);
1701 if (comptypes_internal (mv3
, mv1
, enum_and_int_p
,
1712 /* comptypes said ok, but record if it said to warn. */
1716 args1
= TREE_CHAIN (args1
);
1717 args2
= TREE_CHAIN (args2
);
1721 /* Compute the size to increment a pointer by. */
1724 c_size_in_bytes (const_tree type
)
1726 enum tree_code code
= TREE_CODE (type
);
1728 if (code
== FUNCTION_TYPE
|| code
== VOID_TYPE
|| code
== ERROR_MARK
)
1729 return size_one_node
;
1731 if (!COMPLETE_OR_VOID_TYPE_P (type
))
1733 error ("arithmetic on pointer to an incomplete type");
1734 return size_one_node
;
1737 /* Convert in case a char is more than one unit. */
1738 return size_binop_loc (input_location
, CEIL_DIV_EXPR
, TYPE_SIZE_UNIT (type
),
1739 size_int (TYPE_PRECISION (char_type_node
)
1743 /* Return either DECL or its known constant value (if it has one). */
1746 decl_constant_value (tree decl
)
1748 if (/* Don't change a variable array bound or initial value to a constant
1749 in a place where a variable is invalid. Note that DECL_INITIAL
1750 isn't valid for a PARM_DECL. */
1751 current_function_decl
!= 0
1752 && TREE_CODE (decl
) != PARM_DECL
1753 && !TREE_THIS_VOLATILE (decl
)
1754 && TREE_READONLY (decl
)
1755 && DECL_INITIAL (decl
) != 0
1756 && TREE_CODE (DECL_INITIAL (decl
)) != ERROR_MARK
1757 /* This is invalid if initial value is not constant.
1758 If it has either a function call, a memory reference,
1759 or a variable, then re-evaluating it could give different results. */
1760 && TREE_CONSTANT (DECL_INITIAL (decl
))
1761 /* Check for cases where this is sub-optimal, even though valid. */
1762 && TREE_CODE (DECL_INITIAL (decl
)) != CONSTRUCTOR
)
1763 return DECL_INITIAL (decl
);
1767 /* Convert the array expression EXP to a pointer. */
1769 array_to_pointer_conversion (location_t loc
, tree exp
)
1771 tree orig_exp
= exp
;
1772 tree type
= TREE_TYPE (exp
);
1774 tree restype
= TREE_TYPE (type
);
1777 gcc_assert (TREE_CODE (type
) == ARRAY_TYPE
);
1779 STRIP_TYPE_NOPS (exp
);
1781 if (TREE_NO_WARNING (orig_exp
))
1782 TREE_NO_WARNING (exp
) = 1;
1784 ptrtype
= build_pointer_type (restype
);
1786 if (TREE_CODE (exp
) == INDIRECT_REF
)
1787 return convert (ptrtype
, TREE_OPERAND (exp
, 0));
1789 /* In C++ array compound literals are temporary objects unless they are
1790 const or appear in namespace scope, so they are destroyed too soon
1791 to use them for much of anything (c++/53220). */
1792 if (warn_cxx_compat
&& TREE_CODE (exp
) == COMPOUND_LITERAL_EXPR
)
1794 tree decl
= TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
1795 if (!TREE_READONLY (decl
) && !TREE_STATIC (decl
))
1796 warning_at (DECL_SOURCE_LOCATION (decl
), OPT_Wc___compat
,
1797 "converting an array compound literal to a pointer "
1798 "is ill-formed in C++");
1801 adr
= build_unary_op (loc
, ADDR_EXPR
, exp
, 1);
1802 return convert (ptrtype
, adr
);
1805 /* Convert the function expression EXP to a pointer. */
1807 function_to_pointer_conversion (location_t loc
, tree exp
)
1809 tree orig_exp
= exp
;
1811 gcc_assert (TREE_CODE (TREE_TYPE (exp
)) == FUNCTION_TYPE
);
1813 STRIP_TYPE_NOPS (exp
);
1815 if (TREE_NO_WARNING (orig_exp
))
1816 TREE_NO_WARNING (exp
) = 1;
1818 return build_unary_op (loc
, ADDR_EXPR
, exp
, 0);
1821 /* Mark EXP as read, not just set, for set but not used -Wunused
1822 warning purposes. */
1825 mark_exp_read (tree exp
)
1827 switch (TREE_CODE (exp
))
1831 DECL_READ_P (exp
) = 1;
1840 mark_exp_read (TREE_OPERAND (exp
, 0));
1843 case C_MAYBE_CONST_EXPR
:
1844 mark_exp_read (TREE_OPERAND (exp
, 1));
1851 /* Perform the default conversion of arrays and functions to pointers.
1852 Return the result of converting EXP. For any other expression, just
1855 LOC is the location of the expression. */
1858 default_function_array_conversion (location_t loc
, struct c_expr exp
)
1860 tree orig_exp
= exp
.value
;
1861 tree type
= TREE_TYPE (exp
.value
);
1862 enum tree_code code
= TREE_CODE (type
);
1868 bool not_lvalue
= false;
1869 bool lvalue_array_p
;
1871 while ((TREE_CODE (exp
.value
) == NON_LVALUE_EXPR
1872 || CONVERT_EXPR_P (exp
.value
))
1873 && TREE_TYPE (TREE_OPERAND (exp
.value
, 0)) == type
)
1875 if (TREE_CODE (exp
.value
) == NON_LVALUE_EXPR
)
1877 exp
.value
= TREE_OPERAND (exp
.value
, 0);
1880 if (TREE_NO_WARNING (orig_exp
))
1881 TREE_NO_WARNING (exp
.value
) = 1;
1883 lvalue_array_p
= !not_lvalue
&& lvalue_p (exp
.value
);
1884 if (!flag_isoc99
&& !lvalue_array_p
)
1886 /* Before C99, non-lvalue arrays do not decay to pointers.
1887 Normally, using such an array would be invalid; but it can
1888 be used correctly inside sizeof or as a statement expression.
1889 Thus, do not give an error here; an error will result later. */
1893 exp
.value
= array_to_pointer_conversion (loc
, exp
.value
);
1897 exp
.value
= function_to_pointer_conversion (loc
, exp
.value
);
1907 default_function_array_read_conversion (location_t loc
, struct c_expr exp
)
1909 mark_exp_read (exp
.value
);
1910 return default_function_array_conversion (loc
, exp
);
1913 /* EXP is an expression of integer type. Apply the integer promotions
1914 to it and return the promoted value. */
1917 perform_integral_promotions (tree exp
)
1919 tree type
= TREE_TYPE (exp
);
1920 enum tree_code code
= TREE_CODE (type
);
1922 gcc_assert (INTEGRAL_TYPE_P (type
));
1924 /* Normally convert enums to int,
1925 but convert wide enums to something wider. */
1926 if (code
== ENUMERAL_TYPE
)
1928 type
= c_common_type_for_size (MAX (TYPE_PRECISION (type
),
1929 TYPE_PRECISION (integer_type_node
)),
1930 ((TYPE_PRECISION (type
)
1931 >= TYPE_PRECISION (integer_type_node
))
1932 && TYPE_UNSIGNED (type
)));
1934 return convert (type
, exp
);
1937 /* ??? This should no longer be needed now bit-fields have their
1939 if (TREE_CODE (exp
) == COMPONENT_REF
1940 && DECL_C_BIT_FIELD (TREE_OPERAND (exp
, 1))
1941 /* If it's thinner than an int, promote it like a
1942 c_promoting_integer_type_p, otherwise leave it alone. */
1943 && 0 > compare_tree_int (DECL_SIZE (TREE_OPERAND (exp
, 1)),
1944 TYPE_PRECISION (integer_type_node
)))
1945 return convert (integer_type_node
, exp
);
1947 if (c_promoting_integer_type_p (type
))
1949 /* Preserve unsignedness if not really getting any wider. */
1950 if (TYPE_UNSIGNED (type
)
1951 && TYPE_PRECISION (type
) == TYPE_PRECISION (integer_type_node
))
1952 return convert (unsigned_type_node
, exp
);
1954 return convert (integer_type_node
, exp
);
1961 /* Perform default promotions for C data used in expressions.
1962 Enumeral types or short or char are converted to int.
1963 In addition, manifest constants symbols are replaced by their values. */
1966 default_conversion (tree exp
)
1969 tree type
= TREE_TYPE (exp
);
1970 enum tree_code code
= TREE_CODE (type
);
1973 mark_exp_read (exp
);
1975 /* Functions and arrays have been converted during parsing. */
1976 gcc_assert (code
!= FUNCTION_TYPE
);
1977 if (code
== ARRAY_TYPE
)
1980 /* Constants can be used directly unless they're not loadable. */
1981 if (TREE_CODE (exp
) == CONST_DECL
)
1982 exp
= DECL_INITIAL (exp
);
1984 /* Strip no-op conversions. */
1986 STRIP_TYPE_NOPS (exp
);
1988 if (TREE_NO_WARNING (orig_exp
))
1989 TREE_NO_WARNING (exp
) = 1;
1991 if (code
== VOID_TYPE
)
1993 error ("void value not ignored as it ought to be");
1994 return error_mark_node
;
1997 exp
= require_complete_type (exp
);
1998 if (exp
== error_mark_node
)
1999 return error_mark_node
;
2001 promoted_type
= targetm
.promoted_type (type
);
2003 return convert (promoted_type
, exp
);
2005 if (INTEGRAL_TYPE_P (type
))
2006 return perform_integral_promotions (exp
);
2011 /* Look up COMPONENT in a structure or union TYPE.
2013 If the component name is not found, returns NULL_TREE. Otherwise,
2014 the return value is a TREE_LIST, with each TREE_VALUE a FIELD_DECL
2015 stepping down the chain to the component, which is in the last
2016 TREE_VALUE of the list. Normally the list is of length one, but if
2017 the component is embedded within (nested) anonymous structures or
2018 unions, the list steps down the chain to the component. */
2021 lookup_field (tree type
, tree component
)
2025 /* If TYPE_LANG_SPECIFIC is set, then it is a sorted array of pointers
2026 to the field elements. Use a binary search on this array to quickly
2027 find the element. Otherwise, do a linear search. TYPE_LANG_SPECIFIC
2028 will always be set for structures which have many elements. */
2030 if (TYPE_LANG_SPECIFIC (type
) && TYPE_LANG_SPECIFIC (type
)->s
)
2033 tree
*field_array
= &TYPE_LANG_SPECIFIC (type
)->s
->elts
[0];
2035 field
= TYPE_FIELDS (type
);
2037 top
= TYPE_LANG_SPECIFIC (type
)->s
->len
;
2038 while (top
- bot
> 1)
2040 half
= (top
- bot
+ 1) >> 1;
2041 field
= field_array
[bot
+half
];
2043 if (DECL_NAME (field
) == NULL_TREE
)
2045 /* Step through all anon unions in linear fashion. */
2046 while (DECL_NAME (field_array
[bot
]) == NULL_TREE
)
2048 field
= field_array
[bot
++];
2049 if (TREE_CODE (TREE_TYPE (field
)) == RECORD_TYPE
2050 || TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
)
2052 tree anon
= lookup_field (TREE_TYPE (field
), component
);
2055 return tree_cons (NULL_TREE
, field
, anon
);
2057 /* The Plan 9 compiler permits referring
2058 directly to an anonymous struct/union field
2059 using a typedef name. */
2060 if (flag_plan9_extensions
2061 && TYPE_NAME (TREE_TYPE (field
)) != NULL_TREE
2062 && (TREE_CODE (TYPE_NAME (TREE_TYPE (field
)))
2064 && (DECL_NAME (TYPE_NAME (TREE_TYPE (field
)))
2070 /* Entire record is only anon unions. */
2074 /* Restart the binary search, with new lower bound. */
2078 if (DECL_NAME (field
) == component
)
2080 if (DECL_NAME (field
) < component
)
2086 if (DECL_NAME (field_array
[bot
]) == component
)
2087 field
= field_array
[bot
];
2088 else if (DECL_NAME (field
) != component
)
2093 for (field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
2095 if (DECL_NAME (field
) == NULL_TREE
2096 && (TREE_CODE (TREE_TYPE (field
)) == RECORD_TYPE
2097 || TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
))
2099 tree anon
= lookup_field (TREE_TYPE (field
), component
);
2102 return tree_cons (NULL_TREE
, field
, anon
);
2104 /* The Plan 9 compiler permits referring directly to an
2105 anonymous struct/union field using a typedef
2107 if (flag_plan9_extensions
2108 && TYPE_NAME (TREE_TYPE (field
)) != NULL_TREE
2109 && TREE_CODE (TYPE_NAME (TREE_TYPE (field
))) == TYPE_DECL
2110 && (DECL_NAME (TYPE_NAME (TREE_TYPE (field
)))
2115 if (DECL_NAME (field
) == component
)
2119 if (field
== NULL_TREE
)
2123 return tree_cons (NULL_TREE
, field
, NULL_TREE
);
2126 /* Make an expression to refer to the COMPONENT field of structure or
2127 union value DATUM. COMPONENT is an IDENTIFIER_NODE. LOC is the
2128 location of the COMPONENT_REF. */
2131 build_component_ref (location_t loc
, tree datum
, tree component
)
2133 tree type
= TREE_TYPE (datum
);
2134 enum tree_code code
= TREE_CODE (type
);
2137 bool datum_lvalue
= lvalue_p (datum
);
2139 if (!objc_is_public (datum
, component
))
2140 return error_mark_node
;
2142 /* Detect Objective-C property syntax object.property. */
2143 if (c_dialect_objc ()
2144 && (ref
= objc_maybe_build_component_ref (datum
, component
)))
2147 /* See if there is a field or component with name COMPONENT. */
2149 if (code
== RECORD_TYPE
|| code
== UNION_TYPE
)
2151 if (!COMPLETE_TYPE_P (type
))
2153 c_incomplete_type_error (NULL_TREE
, type
);
2154 return error_mark_node
;
2157 field
= lookup_field (type
, component
);
2161 error_at (loc
, "%qT has no member named %qE", type
, component
);
2162 return error_mark_node
;
2165 /* Chain the COMPONENT_REFs if necessary down to the FIELD.
2166 This might be better solved in future the way the C++ front
2167 end does it - by giving the anonymous entities each a
2168 separate name and type, and then have build_component_ref
2169 recursively call itself. We can't do that here. */
2172 tree subdatum
= TREE_VALUE (field
);
2175 bool use_datum_quals
;
2177 if (TREE_TYPE (subdatum
) == error_mark_node
)
2178 return error_mark_node
;
2180 /* If this is an rvalue, it does not have qualifiers in C
2181 standard terms and we must avoid propagating such
2182 qualifiers down to a non-lvalue array that is then
2183 converted to a pointer. */
2184 use_datum_quals
= (datum_lvalue
2185 || TREE_CODE (TREE_TYPE (subdatum
)) != ARRAY_TYPE
);
2187 quals
= TYPE_QUALS (strip_array_types (TREE_TYPE (subdatum
)));
2188 if (use_datum_quals
)
2189 quals
|= TYPE_QUALS (TREE_TYPE (datum
));
2190 subtype
= c_build_qualified_type (TREE_TYPE (subdatum
), quals
);
2192 ref
= build3 (COMPONENT_REF
, subtype
, datum
, subdatum
,
2194 SET_EXPR_LOCATION (ref
, loc
);
2195 if (TREE_READONLY (subdatum
)
2196 || (use_datum_quals
&& TREE_READONLY (datum
)))
2197 TREE_READONLY (ref
) = 1;
2198 if (TREE_THIS_VOLATILE (subdatum
)
2199 || (use_datum_quals
&& TREE_THIS_VOLATILE (datum
)))
2200 TREE_THIS_VOLATILE (ref
) = 1;
2202 if (TREE_DEPRECATED (subdatum
))
2203 warn_deprecated_use (subdatum
, NULL_TREE
);
2207 field
= TREE_CHAIN (field
);
2213 else if (code
!= ERROR_MARK
)
2215 "request for member %qE in something not a structure or union",
2218 return error_mark_node
;
2221 /* Given an expression PTR for a pointer, return an expression
2222 for the value pointed to.
2223 ERRORSTRING is the name of the operator to appear in error messages.
2225 LOC is the location to use for the generated tree. */
2228 build_indirect_ref (location_t loc
, tree ptr
, ref_operator errstring
)
2230 tree pointer
= default_conversion (ptr
);
2231 tree type
= TREE_TYPE (pointer
);
2234 if (TREE_CODE (type
) == POINTER_TYPE
)
2236 if (CONVERT_EXPR_P (pointer
)
2237 || TREE_CODE (pointer
) == VIEW_CONVERT_EXPR
)
2239 /* If a warning is issued, mark it to avoid duplicates from
2240 the backend. This only needs to be done at
2241 warn_strict_aliasing > 2. */
2242 if (warn_strict_aliasing
> 2)
2243 if (strict_aliasing_warning (TREE_TYPE (TREE_OPERAND (pointer
, 0)),
2244 type
, TREE_OPERAND (pointer
, 0)))
2245 TREE_NO_WARNING (pointer
) = 1;
2248 if (TREE_CODE (pointer
) == ADDR_EXPR
2249 && (TREE_TYPE (TREE_OPERAND (pointer
, 0))
2250 == TREE_TYPE (type
)))
2252 ref
= TREE_OPERAND (pointer
, 0);
2253 protected_set_expr_location (ref
, loc
);
2258 tree t
= TREE_TYPE (type
);
2260 ref
= build1 (INDIRECT_REF
, t
, pointer
);
2262 if (!COMPLETE_OR_VOID_TYPE_P (t
) && TREE_CODE (t
) != ARRAY_TYPE
)
2264 error_at (loc
, "dereferencing pointer to incomplete type");
2265 return error_mark_node
;
2267 if (VOID_TYPE_P (t
) && c_inhibit_evaluation_warnings
== 0)
2268 warning_at (loc
, 0, "dereferencing %<void *%> pointer");
2270 /* We *must* set TREE_READONLY when dereferencing a pointer to const,
2271 so that we get the proper error message if the result is used
2272 to assign to. Also, &* is supposed to be a no-op.
2273 And ANSI C seems to specify that the type of the result
2274 should be the const type. */
2275 /* A de-reference of a pointer to const is not a const. It is valid
2276 to change it via some other pointer. */
2277 TREE_READONLY (ref
) = TYPE_READONLY (t
);
2278 TREE_SIDE_EFFECTS (ref
)
2279 = TYPE_VOLATILE (t
) || TREE_SIDE_EFFECTS (pointer
);
2280 TREE_THIS_VOLATILE (ref
) = TYPE_VOLATILE (t
);
2281 protected_set_expr_location (ref
, loc
);
2285 else if (TREE_CODE (pointer
) != ERROR_MARK
)
2286 invalid_indirection_error (loc
, type
, errstring
);
2288 return error_mark_node
;
2291 /* This handles expressions of the form "a[i]", which denotes
2294 This is logically equivalent in C to *(a+i), but we may do it differently.
2295 If A is a variable or a member, we generate a primitive ARRAY_REF.
2296 This avoids forcing the array out of registers, and can work on
2297 arrays that are not lvalues (for example, members of structures returned
2300 For vector types, allow vector[i] but not i[vector], and create
2301 *(((type*)&vectortype) + i) for the expression.
2303 LOC is the location to use for the returned expression. */
2306 build_array_ref (location_t loc
, tree array
, tree index
)
2309 bool swapped
= false;
2310 if (TREE_TYPE (array
) == error_mark_node
2311 || TREE_TYPE (index
) == error_mark_node
)
2312 return error_mark_node
;
2314 if (flag_enable_cilkplus
&& contains_array_notation_expr (index
))
2317 if (!find_rank (loc
, index
, index
, true, &rank
))
2318 return error_mark_node
;
2321 error_at (loc
, "rank of the array's index is greater than 1");
2322 return error_mark_node
;
2325 if (TREE_CODE (TREE_TYPE (array
)) != ARRAY_TYPE
2326 && TREE_CODE (TREE_TYPE (array
)) != POINTER_TYPE
2327 /* Allow vector[index] but not index[vector]. */
2328 && TREE_CODE (TREE_TYPE (array
)) != VECTOR_TYPE
)
2331 if (TREE_CODE (TREE_TYPE (index
)) != ARRAY_TYPE
2332 && TREE_CODE (TREE_TYPE (index
)) != POINTER_TYPE
)
2335 "subscripted value is neither array nor pointer nor vector");
2337 return error_mark_node
;
2345 if (!INTEGRAL_TYPE_P (TREE_TYPE (index
)))
2347 error_at (loc
, "array subscript is not an integer");
2348 return error_mark_node
;
2351 if (TREE_CODE (TREE_TYPE (TREE_TYPE (array
))) == FUNCTION_TYPE
)
2353 error_at (loc
, "subscripted value is pointer to function");
2354 return error_mark_node
;
2357 /* ??? Existing practice has been to warn only when the char
2358 index is syntactically the index, not for char[array]. */
2360 warn_array_subscript_with_type_char (index
);
2362 /* Apply default promotions *after* noticing character types. */
2363 index
= default_conversion (index
);
2365 gcc_assert (TREE_CODE (TREE_TYPE (index
)) == INTEGER_TYPE
);
2367 convert_vector_to_pointer_for_subscript (loc
, &array
, index
);
2369 if (TREE_CODE (TREE_TYPE (array
)) == ARRAY_TYPE
)
2373 /* An array that is indexed by a non-constant
2374 cannot be stored in a register; we must be able to do
2375 address arithmetic on its address.
2376 Likewise an array of elements of variable size. */
2377 if (TREE_CODE (index
) != INTEGER_CST
2378 || (COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (array
)))
2379 && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array
)))) != INTEGER_CST
))
2381 if (!c_mark_addressable (array
))
2382 return error_mark_node
;
2384 /* An array that is indexed by a constant value which is not within
2385 the array bounds cannot be stored in a register either; because we
2386 would get a crash in store_bit_field/extract_bit_field when trying
2387 to access a non-existent part of the register. */
2388 if (TREE_CODE (index
) == INTEGER_CST
2389 && TYPE_DOMAIN (TREE_TYPE (array
))
2390 && !int_fits_type_p (index
, TYPE_DOMAIN (TREE_TYPE (array
))))
2392 if (!c_mark_addressable (array
))
2393 return error_mark_node
;
2399 while (TREE_CODE (foo
) == COMPONENT_REF
)
2400 foo
= TREE_OPERAND (foo
, 0);
2401 if (TREE_CODE (foo
) == VAR_DECL
&& C_DECL_REGISTER (foo
))
2402 pedwarn (loc
, OPT_Wpedantic
,
2403 "ISO C forbids subscripting %<register%> array");
2404 else if (!flag_isoc99
&& !lvalue_p (foo
))
2405 pedwarn (loc
, OPT_Wpedantic
,
2406 "ISO C90 forbids subscripting non-lvalue array");
2409 type
= TREE_TYPE (TREE_TYPE (array
));
2410 rval
= build4 (ARRAY_REF
, type
, array
, index
, NULL_TREE
, NULL_TREE
);
2411 /* Array ref is const/volatile if the array elements are
2412 or if the array is. */
2413 TREE_READONLY (rval
)
2414 |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array
)))
2415 | TREE_READONLY (array
));
2416 TREE_SIDE_EFFECTS (rval
)
2417 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array
)))
2418 | TREE_SIDE_EFFECTS (array
));
2419 TREE_THIS_VOLATILE (rval
)
2420 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array
)))
2421 /* This was added by rms on 16 Nov 91.
2422 It fixes vol struct foo *a; a->elts[1]
2423 in an inline function.
2424 Hope it doesn't break something else. */
2425 | TREE_THIS_VOLATILE (array
));
2426 ret
= require_complete_type (rval
);
2427 protected_set_expr_location (ret
, loc
);
2432 tree ar
= default_conversion (array
);
2434 if (ar
== error_mark_node
)
2437 gcc_assert (TREE_CODE (TREE_TYPE (ar
)) == POINTER_TYPE
);
2438 gcc_assert (TREE_CODE (TREE_TYPE (TREE_TYPE (ar
))) != FUNCTION_TYPE
);
2440 return build_indirect_ref
2441 (loc
, build_binary_op (loc
, PLUS_EXPR
, ar
, index
, 0),
2446 /* Build an external reference to identifier ID. FUN indicates
2447 whether this will be used for a function call. LOC is the source
2448 location of the identifier. This sets *TYPE to the type of the
2449 identifier, which is not the same as the type of the returned value
2450 for CONST_DECLs defined as enum constants. If the type of the
2451 identifier is not available, *TYPE is set to NULL. */
2453 build_external_ref (location_t loc
, tree id
, int fun
, tree
*type
)
2456 tree decl
= lookup_name (id
);
2458 /* In Objective-C, an instance variable (ivar) may be preferred to
2459 whatever lookup_name() found. */
2460 decl
= objc_lookup_ivar (decl
, id
);
2463 if (decl
&& decl
!= error_mark_node
)
2466 *type
= TREE_TYPE (ref
);
2469 /* Implicit function declaration. */
2470 ref
= implicitly_declare (loc
, id
);
2471 else if (decl
== error_mark_node
)
2472 /* Don't complain about something that's already been
2473 complained about. */
2474 return error_mark_node
;
2477 undeclared_variable (loc
, id
);
2478 return error_mark_node
;
2481 if (TREE_TYPE (ref
) == error_mark_node
)
2482 return error_mark_node
;
2484 if (TREE_DEPRECATED (ref
))
2485 warn_deprecated_use (ref
, NULL_TREE
);
2487 /* Recursive call does not count as usage. */
2488 if (ref
!= current_function_decl
)
2490 TREE_USED (ref
) = 1;
2493 if (TREE_CODE (ref
) == FUNCTION_DECL
&& !in_alignof
)
2495 if (!in_sizeof
&& !in_typeof
)
2496 C_DECL_USED (ref
) = 1;
2497 else if (DECL_INITIAL (ref
) == 0
2498 && DECL_EXTERNAL (ref
)
2499 && !TREE_PUBLIC (ref
))
2500 record_maybe_used_decl (ref
);
2503 if (TREE_CODE (ref
) == CONST_DECL
)
2505 used_types_insert (TREE_TYPE (ref
));
2508 && TREE_CODE (TREE_TYPE (ref
)) == ENUMERAL_TYPE
2509 && C_TYPE_DEFINED_IN_STRUCT (TREE_TYPE (ref
)))
2511 warning_at (loc
, OPT_Wc___compat
,
2512 ("enum constant defined in struct or union "
2513 "is not visible in C++"));
2514 inform (DECL_SOURCE_LOCATION (ref
), "enum constant defined here");
2517 ref
= DECL_INITIAL (ref
);
2518 TREE_CONSTANT (ref
) = 1;
2520 else if (current_function_decl
!= 0
2521 && !DECL_FILE_SCOPE_P (current_function_decl
)
2522 && (TREE_CODE (ref
) == VAR_DECL
2523 || TREE_CODE (ref
) == PARM_DECL
2524 || TREE_CODE (ref
) == FUNCTION_DECL
))
2526 tree context
= decl_function_context (ref
);
2528 if (context
!= 0 && context
!= current_function_decl
)
2529 DECL_NONLOCAL (ref
) = 1;
2531 /* C99 6.7.4p3: An inline definition of a function with external
2532 linkage ... shall not contain a reference to an identifier with
2533 internal linkage. */
2534 else if (current_function_decl
!= 0
2535 && DECL_DECLARED_INLINE_P (current_function_decl
)
2536 && DECL_EXTERNAL (current_function_decl
)
2537 && VAR_OR_FUNCTION_DECL_P (ref
)
2538 && (TREE_CODE (ref
) != VAR_DECL
|| TREE_STATIC (ref
))
2539 && ! TREE_PUBLIC (ref
)
2540 && DECL_CONTEXT (ref
) != current_function_decl
)
2541 record_inline_static (loc
, current_function_decl
, ref
,
2547 /* Record details of decls possibly used inside sizeof or typeof. */
2548 struct maybe_used_decl
2552 /* The level seen at (in_sizeof + in_typeof). */
2554 /* The next one at this level or above, or NULL. */
2555 struct maybe_used_decl
*next
;
2558 static struct maybe_used_decl
*maybe_used_decls
;
2560 /* Record that DECL, an undefined static function reference seen
2561 inside sizeof or typeof, might be used if the operand of sizeof is
2562 a VLA type or the operand of typeof is a variably modified
2566 record_maybe_used_decl (tree decl
)
2568 struct maybe_used_decl
*t
= XOBNEW (&parser_obstack
, struct maybe_used_decl
);
2570 t
->level
= in_sizeof
+ in_typeof
;
2571 t
->next
= maybe_used_decls
;
2572 maybe_used_decls
= t
;
2575 /* Pop the stack of decls possibly used inside sizeof or typeof. If
2576 USED is false, just discard them. If it is true, mark them used
2577 (if no longer inside sizeof or typeof) or move them to the next
2578 level up (if still inside sizeof or typeof). */
2581 pop_maybe_used (bool used
)
2583 struct maybe_used_decl
*p
= maybe_used_decls
;
2584 int cur_level
= in_sizeof
+ in_typeof
;
2585 while (p
&& p
->level
> cur_level
)
2590 C_DECL_USED (p
->decl
) = 1;
2592 p
->level
= cur_level
;
2596 if (!used
|| cur_level
== 0)
2597 maybe_used_decls
= p
;
2600 /* Return the result of sizeof applied to EXPR. */
2603 c_expr_sizeof_expr (location_t loc
, struct c_expr expr
)
2606 if (expr
.value
== error_mark_node
)
2608 ret
.value
= error_mark_node
;
2609 ret
.original_code
= ERROR_MARK
;
2610 ret
.original_type
= NULL
;
2611 pop_maybe_used (false);
2615 bool expr_const_operands
= true;
2616 tree folded_expr
= c_fully_fold (expr
.value
, require_constant_value
,
2617 &expr_const_operands
);
2618 ret
.value
= c_sizeof (loc
, TREE_TYPE (folded_expr
));
2619 c_last_sizeof_arg
= expr
.value
;
2620 ret
.original_code
= SIZEOF_EXPR
;
2621 ret
.original_type
= NULL
;
2622 if (c_vla_type_p (TREE_TYPE (folded_expr
)))
2624 /* sizeof is evaluated when given a vla (C99 6.5.3.4p2). */
2625 ret
.value
= build2 (C_MAYBE_CONST_EXPR
, TREE_TYPE (ret
.value
),
2626 folded_expr
, ret
.value
);
2627 C_MAYBE_CONST_EXPR_NON_CONST (ret
.value
) = !expr_const_operands
;
2628 SET_EXPR_LOCATION (ret
.value
, loc
);
2630 pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (folded_expr
)));
2635 /* Return the result of sizeof applied to T, a structure for the type
2636 name passed to sizeof (rather than the type itself). LOC is the
2637 location of the original expression. */
2640 c_expr_sizeof_type (location_t loc
, struct c_type_name
*t
)
2644 tree type_expr
= NULL_TREE
;
2645 bool type_expr_const
= true;
2646 type
= groktypename (t
, &type_expr
, &type_expr_const
);
2647 ret
.value
= c_sizeof (loc
, type
);
2648 c_last_sizeof_arg
= type
;
2649 ret
.original_code
= SIZEOF_EXPR
;
2650 ret
.original_type
= NULL
;
2651 if ((type_expr
|| TREE_CODE (ret
.value
) == INTEGER_CST
)
2652 && c_vla_type_p (type
))
2654 /* If the type is a [*] array, it is a VLA but is represented as
2655 having a size of zero. In such a case we must ensure that
2656 the result of sizeof does not get folded to a constant by
2657 c_fully_fold, because if the size is evaluated the result is
2658 not constant and so constraints on zero or negative size
2659 arrays must not be applied when this sizeof call is inside
2660 another array declarator. */
2662 type_expr
= integer_zero_node
;
2663 ret
.value
= build2 (C_MAYBE_CONST_EXPR
, TREE_TYPE (ret
.value
),
2664 type_expr
, ret
.value
);
2665 C_MAYBE_CONST_EXPR_NON_CONST (ret
.value
) = !type_expr_const
;
2667 pop_maybe_used (type
!= error_mark_node
2668 ? C_TYPE_VARIABLE_SIZE (type
) : false);
2672 /* Build a function call to function FUNCTION with parameters PARAMS.
2673 The function call is at LOC.
2674 PARAMS is a list--a chain of TREE_LIST nodes--in which the
2675 TREE_VALUE of each node is a parameter-expression.
2676 FUNCTION's data type may be a function type or a pointer-to-function. */
2679 build_function_call (location_t loc
, tree function
, tree params
)
2681 vec
<tree
, va_gc
> *v
;
2684 vec_alloc (v
, list_length (params
));
2685 for (; params
; params
= TREE_CHAIN (params
))
2686 v
->quick_push (TREE_VALUE (params
));
2687 ret
= build_function_call_vec (loc
, function
, v
, NULL
);
2692 /* Give a note about the location of the declaration of DECL. */
2694 static void inform_declaration (tree decl
)
2696 if (decl
&& (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_BUILT_IN (decl
)))
2697 inform (DECL_SOURCE_LOCATION (decl
), "declared here");
2700 /* Build a function call to function FUNCTION with parameters PARAMS.
2701 ORIGTYPES, if not NULL, is a vector of types; each element is
2702 either NULL or the original type of the corresponding element in
2703 PARAMS. The original type may differ from TREE_TYPE of the
2704 parameter for enums. FUNCTION's data type may be a function type
2705 or pointer-to-function. This function changes the elements of
2709 build_function_call_vec (location_t loc
, tree function
,
2710 vec
<tree
, va_gc
> *params
,
2711 vec
<tree
, va_gc
> *origtypes
)
2713 tree fntype
, fundecl
= 0;
2714 tree name
= NULL_TREE
, result
;
2720 /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
2721 STRIP_TYPE_NOPS (function
);
2723 /* Convert anything with function type to a pointer-to-function. */
2724 if (TREE_CODE (function
) == FUNCTION_DECL
)
2726 /* Implement type-directed function overloading for builtins.
2727 resolve_overloaded_builtin and targetm.resolve_overloaded_builtin
2728 handle all the type checking. The result is a complete expression
2729 that implements this function call. */
2730 tem
= resolve_overloaded_builtin (loc
, function
, params
);
2734 name
= DECL_NAME (function
);
2737 tm_malloc_replacement (function
);
2739 /* Atomic functions have type checking/casting already done. They are
2740 often rewritten and don't match the original parameter list. */
2741 if (name
&& !strncmp (IDENTIFIER_POINTER (name
), "__atomic_", 9))
2744 if (flag_enable_cilkplus
2745 && is_cilkplus_reduce_builtin (function
))
2748 if (TREE_CODE (TREE_TYPE (function
)) == FUNCTION_TYPE
)
2749 function
= function_to_pointer_conversion (loc
, function
);
2751 /* For Objective-C, convert any calls via a cast to OBJC_TYPE_REF
2752 expressions, like those used for ObjC messenger dispatches. */
2753 if (params
&& !params
->is_empty ())
2754 function
= objc_rewrite_function_call (function
, (*params
)[0]);
2756 function
= c_fully_fold (function
, false, NULL
);
2758 fntype
= TREE_TYPE (function
);
2760 if (TREE_CODE (fntype
) == ERROR_MARK
)
2761 return error_mark_node
;
2763 if (!(TREE_CODE (fntype
) == POINTER_TYPE
2764 && TREE_CODE (TREE_TYPE (fntype
)) == FUNCTION_TYPE
))
2766 if (!flag_diagnostics_show_caret
)
2768 "called object %qE is not a function or function pointer",
2770 else if (DECL_P (function
))
2773 "called object %qD is not a function or function pointer",
2775 inform_declaration (function
);
2779 "called object is not a function or function pointer");
2780 return error_mark_node
;
2783 if (fundecl
&& TREE_THIS_VOLATILE (fundecl
))
2784 current_function_returns_abnormally
= 1;
2786 /* fntype now gets the type of function pointed to. */
2787 fntype
= TREE_TYPE (fntype
);
2789 /* Convert the parameters to the types declared in the
2790 function prototype, or apply default promotions. */
2792 nargs
= convert_arguments (TYPE_ARG_TYPES (fntype
), params
, origtypes
,
2795 return error_mark_node
;
2797 /* Check that the function is called through a compatible prototype.
2798 If it is not, replace the call by a trap, wrapped up in a compound
2799 expression if necessary. This has the nice side-effect to prevent
2800 the tree-inliner from generating invalid assignment trees which may
2801 blow up in the RTL expander later. */
2802 if (CONVERT_EXPR_P (function
)
2803 && TREE_CODE (tem
= TREE_OPERAND (function
, 0)) == ADDR_EXPR
2804 && TREE_CODE (tem
= TREE_OPERAND (tem
, 0)) == FUNCTION_DECL
2805 && !comptypes (fntype
, TREE_TYPE (tem
)))
2807 tree return_type
= TREE_TYPE (fntype
);
2808 tree trap
= build_function_call (loc
,
2809 builtin_decl_explicit (BUILT_IN_TRAP
),
2813 /* This situation leads to run-time undefined behavior. We can't,
2814 therefore, simply error unless we can prove that all possible
2815 executions of the program must execute the code. */
2816 if (warning_at (loc
, 0, "function called through a non-compatible type"))
2817 /* We can, however, treat "undefined" any way we please.
2818 Call abort to encourage the user to fix the program. */
2819 inform (loc
, "if this code is reached, the program will abort");
2820 /* Before the abort, allow the function arguments to exit or
2822 for (i
= 0; i
< nargs
; i
++)
2823 trap
= build2 (COMPOUND_EXPR
, void_type_node
, (*params
)[i
], trap
);
2825 if (VOID_TYPE_P (return_type
))
2827 if (TYPE_QUALS (return_type
) != TYPE_UNQUALIFIED
)
2829 "function with qualified void return type called");
2836 if (AGGREGATE_TYPE_P (return_type
))
2837 rhs
= build_compound_literal (loc
, return_type
,
2838 build_constructor (return_type
,
2842 rhs
= build_zero_cst (return_type
);
2844 return require_complete_type (build2 (COMPOUND_EXPR
, return_type
,
2849 argarray
= vec_safe_address (params
);
2851 /* Check that arguments to builtin functions match the expectations. */
2853 && DECL_BUILT_IN (fundecl
)
2854 && DECL_BUILT_IN_CLASS (fundecl
) == BUILT_IN_NORMAL
2855 && !check_builtin_function_arguments (fundecl
, nargs
, argarray
))
2856 return error_mark_node
;
2858 /* Check that the arguments to the function are valid. */
2859 check_function_arguments (fntype
, nargs
, argarray
);
2861 if (name
!= NULL_TREE
2862 && !strncmp (IDENTIFIER_POINTER (name
), "__builtin_", 10))
2864 if (require_constant_value
)
2866 fold_build_call_array_initializer_loc (loc
, TREE_TYPE (fntype
),
2867 function
, nargs
, argarray
);
2869 result
= fold_build_call_array_loc (loc
, TREE_TYPE (fntype
),
2870 function
, nargs
, argarray
);
2871 if (TREE_CODE (result
) == NOP_EXPR
2872 && TREE_CODE (TREE_OPERAND (result
, 0)) == INTEGER_CST
)
2873 STRIP_TYPE_NOPS (result
);
2876 result
= build_call_array_loc (loc
, TREE_TYPE (fntype
),
2877 function
, nargs
, argarray
);
2879 if (VOID_TYPE_P (TREE_TYPE (result
)))
2881 if (TYPE_QUALS (TREE_TYPE (result
)) != TYPE_UNQUALIFIED
)
2883 "function with qualified void return type called");
2886 return require_complete_type (result
);
2889 /* Convert the argument expressions in the vector VALUES
2890 to the types in the list TYPELIST.
2892 If TYPELIST is exhausted, or when an element has NULL as its type,
2893 perform the default conversions.
2895 ORIGTYPES is the original types of the expressions in VALUES. This
2896 holds the type of enum values which have been converted to integral
2897 types. It may be NULL.
2899 FUNCTION is a tree for the called function. It is used only for
2900 error messages, where it is formatted with %qE.
2902 This is also where warnings about wrong number of args are generated.
2904 Returns the actual number of arguments processed (which may be less
2905 than the length of VALUES in some error situations), or -1 on
2909 convert_arguments (tree typelist
, vec
<tree
, va_gc
> *values
,
2910 vec
<tree
, va_gc
> *origtypes
, tree function
, tree fundecl
)
2913 unsigned int parmnum
;
2914 bool error_args
= false;
2915 const bool type_generic
= fundecl
2916 && lookup_attribute ("type generic", TYPE_ATTRIBUTES(TREE_TYPE (fundecl
)));
2917 bool type_generic_remove_excess_precision
= false;
2920 /* Change pointer to function to the function itself for
2922 if (TREE_CODE (function
) == ADDR_EXPR
2923 && TREE_CODE (TREE_OPERAND (function
, 0)) == FUNCTION_DECL
)
2924 function
= TREE_OPERAND (function
, 0);
2926 /* Handle an ObjC selector specially for diagnostics. */
2927 selector
= objc_message_selector ();
2929 /* For type-generic built-in functions, determine whether excess
2930 precision should be removed (classification) or not
2933 && DECL_BUILT_IN (fundecl
)
2934 && DECL_BUILT_IN_CLASS (fundecl
) == BUILT_IN_NORMAL
)
2936 switch (DECL_FUNCTION_CODE (fundecl
))
2938 case BUILT_IN_ISFINITE
:
2939 case BUILT_IN_ISINF
:
2940 case BUILT_IN_ISINF_SIGN
:
2941 case BUILT_IN_ISNAN
:
2942 case BUILT_IN_ISNORMAL
:
2943 case BUILT_IN_FPCLASSIFY
:
2944 type_generic_remove_excess_precision
= true;
2948 type_generic_remove_excess_precision
= false;
2952 if (flag_enable_cilkplus
&& fundecl
&& is_cilkplus_reduce_builtin (fundecl
))
2953 return vec_safe_length (values
);
2955 /* Scan the given expressions and types, producing individual
2956 converted arguments. */
2958 for (typetail
= typelist
, parmnum
= 0;
2959 values
&& values
->iterate (parmnum
, &val
);
2962 tree type
= typetail
? TREE_VALUE (typetail
) : 0;
2963 tree valtype
= TREE_TYPE (val
);
2964 tree rname
= function
;
2965 int argnum
= parmnum
+ 1;
2966 const char *invalid_func_diag
;
2967 bool excess_precision
= false;
2971 if (type
== void_type_node
)
2974 error_at (input_location
,
2975 "too many arguments to method %qE", selector
);
2977 error_at (input_location
,
2978 "too many arguments to function %qE", function
);
2979 inform_declaration (fundecl
);
2983 if (selector
&& argnum
> 2)
2989 npc
= null_pointer_constant_p (val
);
2991 /* If there is excess precision and a prototype, convert once to
2992 the required type rather than converting via the semantic
2993 type. Likewise without a prototype a float value represented
2994 as long double should be converted once to double. But for
2995 type-generic classification functions excess precision must
2997 if (TREE_CODE (val
) == EXCESS_PRECISION_EXPR
2998 && (type
|| !type_generic
|| !type_generic_remove_excess_precision
))
3000 val
= TREE_OPERAND (val
, 0);
3001 excess_precision
= true;
3003 val
= c_fully_fold (val
, false, NULL
);
3004 STRIP_TYPE_NOPS (val
);
3006 val
= require_complete_type (val
);
3010 /* Formal parm type is specified by a function prototype. */
3012 if (type
== error_mark_node
|| !COMPLETE_TYPE_P (type
))
3014 error ("type of formal parameter %d is incomplete", parmnum
+ 1);
3021 /* Optionally warn about conversions that
3022 differ from the default conversions. */
3023 if (warn_traditional_conversion
|| warn_traditional
)
3025 unsigned int formal_prec
= TYPE_PRECISION (type
);
3027 if (INTEGRAL_TYPE_P (type
)
3028 && TREE_CODE (valtype
) == REAL_TYPE
)
3029 warning (0, "passing argument %d of %qE as integer "
3030 "rather than floating due to prototype",
3032 if (INTEGRAL_TYPE_P (type
)
3033 && TREE_CODE (valtype
) == COMPLEX_TYPE
)
3034 warning (0, "passing argument %d of %qE as integer "
3035 "rather than complex due to prototype",
3037 else if (TREE_CODE (type
) == COMPLEX_TYPE
3038 && TREE_CODE (valtype
) == REAL_TYPE
)
3039 warning (0, "passing argument %d of %qE as complex "
3040 "rather than floating due to prototype",
3042 else if (TREE_CODE (type
) == REAL_TYPE
3043 && INTEGRAL_TYPE_P (valtype
))
3044 warning (0, "passing argument %d of %qE as floating "
3045 "rather than integer due to prototype",
3047 else if (TREE_CODE (type
) == COMPLEX_TYPE
3048 && INTEGRAL_TYPE_P (valtype
))
3049 warning (0, "passing argument %d of %qE as complex "
3050 "rather than integer due to prototype",
3052 else if (TREE_CODE (type
) == REAL_TYPE
3053 && TREE_CODE (valtype
) == COMPLEX_TYPE
)
3054 warning (0, "passing argument %d of %qE as floating "
3055 "rather than complex due to prototype",
3057 /* ??? At some point, messages should be written about
3058 conversions between complex types, but that's too messy
3060 else if (TREE_CODE (type
) == REAL_TYPE
3061 && TREE_CODE (valtype
) == REAL_TYPE
)
3063 /* Warn if any argument is passed as `float',
3064 since without a prototype it would be `double'. */
3065 if (formal_prec
== TYPE_PRECISION (float_type_node
)
3066 && type
!= dfloat32_type_node
)
3067 warning (0, "passing argument %d of %qE as %<float%> "
3068 "rather than %<double%> due to prototype",
3071 /* Warn if mismatch between argument and prototype
3072 for decimal float types. Warn of conversions with
3073 binary float types and of precision narrowing due to
3075 else if (type
!= valtype
3076 && (type
== dfloat32_type_node
3077 || type
== dfloat64_type_node
3078 || type
== dfloat128_type_node
3079 || valtype
== dfloat32_type_node
3080 || valtype
== dfloat64_type_node
3081 || valtype
== dfloat128_type_node
)
3083 <= TYPE_PRECISION (valtype
)
3084 || (type
== dfloat128_type_node
3086 != dfloat64_type_node
3088 != dfloat32_type_node
)))
3089 || (type
== dfloat64_type_node
3091 != dfloat32_type_node
))))
3092 warning (0, "passing argument %d of %qE as %qT "
3093 "rather than %qT due to prototype",
3094 argnum
, rname
, type
, valtype
);
3097 /* Detect integer changing in width or signedness.
3098 These warnings are only activated with
3099 -Wtraditional-conversion, not with -Wtraditional. */
3100 else if (warn_traditional_conversion
&& INTEGRAL_TYPE_P (type
)
3101 && INTEGRAL_TYPE_P (valtype
))
3103 tree would_have_been
= default_conversion (val
);
3104 tree type1
= TREE_TYPE (would_have_been
);
3106 if (TREE_CODE (type
) == ENUMERAL_TYPE
3107 && (TYPE_MAIN_VARIANT (type
)
3108 == TYPE_MAIN_VARIANT (valtype
)))
3109 /* No warning if function asks for enum
3110 and the actual arg is that enum type. */
3112 else if (formal_prec
!= TYPE_PRECISION (type1
))
3113 warning (OPT_Wtraditional_conversion
,
3114 "passing argument %d of %qE "
3115 "with different width due to prototype",
3117 else if (TYPE_UNSIGNED (type
) == TYPE_UNSIGNED (type1
))
3119 /* Don't complain if the formal parameter type
3120 is an enum, because we can't tell now whether
3121 the value was an enum--even the same enum. */
3122 else if (TREE_CODE (type
) == ENUMERAL_TYPE
)
3124 else if (TREE_CODE (val
) == INTEGER_CST
3125 && int_fits_type_p (val
, type
))
3126 /* Change in signedness doesn't matter
3127 if a constant value is unaffected. */
3129 /* If the value is extended from a narrower
3130 unsigned type, it doesn't matter whether we
3131 pass it as signed or unsigned; the value
3132 certainly is the same either way. */
3133 else if (TYPE_PRECISION (valtype
) < TYPE_PRECISION (type
)
3134 && TYPE_UNSIGNED (valtype
))
3136 else if (TYPE_UNSIGNED (type
))
3137 warning (OPT_Wtraditional_conversion
,
3138 "passing argument %d of %qE "
3139 "as unsigned due to prototype",
3142 warning (OPT_Wtraditional_conversion
,
3143 "passing argument %d of %qE "
3144 "as signed due to prototype", argnum
, rname
);
3148 /* Possibly restore an EXCESS_PRECISION_EXPR for the
3149 sake of better warnings from convert_and_check. */
3150 if (excess_precision
)
3151 val
= build1 (EXCESS_PRECISION_EXPR
, valtype
, val
);
3152 origtype
= (!origtypes
) ? NULL_TREE
: (*origtypes
)[parmnum
];
3153 parmval
= convert_for_assignment (input_location
, type
, val
,
3154 origtype
, ic_argpass
, npc
,
3158 if (targetm
.calls
.promote_prototypes (fundecl
? TREE_TYPE (fundecl
) : 0)
3159 && INTEGRAL_TYPE_P (type
)
3160 && (TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
)))
3161 parmval
= default_conversion (parmval
);
3164 else if (TREE_CODE (valtype
) == REAL_TYPE
3165 && (TYPE_PRECISION (valtype
)
3166 <= TYPE_PRECISION (double_type_node
))
3167 && TYPE_MAIN_VARIANT (valtype
) != double_type_node
3168 && TYPE_MAIN_VARIANT (valtype
) != long_double_type_node
3169 && !DECIMAL_FLOAT_MODE_P (TYPE_MODE (valtype
)))
3175 /* Convert `float' to `double'. */
3176 if (warn_double_promotion
&& !c_inhibit_evaluation_warnings
)
3177 warning (OPT_Wdouble_promotion
,
3178 "implicit conversion from %qT to %qT when passing "
3179 "argument to function",
3180 valtype
, double_type_node
);
3181 parmval
= convert (double_type_node
, val
);
3184 else if (excess_precision
&& !type_generic
)
3185 /* A "double" argument with excess precision being passed
3186 without a prototype or in variable arguments. */
3187 parmval
= convert (valtype
, val
);
3188 else if ((invalid_func_diag
=
3189 targetm
.calls
.invalid_arg_for_unprototyped_fn (typelist
, fundecl
, val
)))
3191 error (invalid_func_diag
);
3195 /* Convert `short' and `char' to full-size `int'. */
3196 parmval
= default_conversion (val
);
3198 (*values
)[parmnum
] = parmval
;
3199 if (parmval
== error_mark_node
)
3203 typetail
= TREE_CHAIN (typetail
);
3206 gcc_assert (parmnum
== vec_safe_length (values
));
3208 if (typetail
!= 0 && TREE_VALUE (typetail
) != void_type_node
)
3210 error_at (input_location
,
3211 "too few arguments to function %qE", function
);
3212 inform_declaration (fundecl
);
3216 return error_args
? -1 : (int) parmnum
;
3219 /* This is the entry point used by the parser to build unary operators
3220 in the input. CODE, a tree_code, specifies the unary operator, and
3221 ARG is the operand. For unary plus, the C parser currently uses
3222 CONVERT_EXPR for code.
3224 LOC is the location to use for the tree generated.
3228 parser_build_unary_op (location_t loc
, enum tree_code code
, struct c_expr arg
)
3230 struct c_expr result
;
3232 result
.value
= build_unary_op (loc
, code
, arg
.value
, 0);
3233 result
.original_code
= code
;
3234 result
.original_type
= NULL
;
3236 if (TREE_OVERFLOW_P (result
.value
) && !TREE_OVERFLOW_P (arg
.value
))
3237 overflow_warning (loc
, result
.value
);
3242 /* This is the entry point used by the parser to build binary operators
3243 in the input. CODE, a tree_code, specifies the binary operator, and
3244 ARG1 and ARG2 are the operands. In addition to constructing the
3245 expression, we check for operands that were written with other binary
3246 operators in a way that is likely to confuse the user.
3248 LOCATION is the location of the binary operator. */
3251 parser_build_binary_op (location_t location
, enum tree_code code
,
3252 struct c_expr arg1
, struct c_expr arg2
)
3254 struct c_expr result
;
3256 enum tree_code code1
= arg1
.original_code
;
3257 enum tree_code code2
= arg2
.original_code
;
3258 tree type1
= (arg1
.original_type
3259 ? arg1
.original_type
3260 : TREE_TYPE (arg1
.value
));
3261 tree type2
= (arg2
.original_type
3262 ? arg2
.original_type
3263 : TREE_TYPE (arg2
.value
));
3265 result
.value
= build_binary_op (location
, code
,
3266 arg1
.value
, arg2
.value
, 1);
3267 result
.original_code
= code
;
3268 result
.original_type
= NULL
;
3270 if (TREE_CODE (result
.value
) == ERROR_MARK
)
3273 if (location
!= UNKNOWN_LOCATION
)
3274 protected_set_expr_location (result
.value
, location
);
3276 /* Check for cases such as x+y<<z which users are likely
3278 if (warn_parentheses
)
3279 warn_about_parentheses (input_location
, code
,
3280 code1
, arg1
.value
, code2
, arg2
.value
);
3282 if (warn_logical_op
)
3283 warn_logical_operator (input_location
, code
, TREE_TYPE (result
.value
),
3284 code1
, arg1
.value
, code2
, arg2
.value
);
3286 /* Warn about comparisons against string literals, with the exception
3287 of testing for equality or inequality of a string literal with NULL. */
3288 if (code
== EQ_EXPR
|| code
== NE_EXPR
)
3290 if ((code1
== STRING_CST
&& !integer_zerop (arg2
.value
))
3291 || (code2
== STRING_CST
&& !integer_zerop (arg1
.value
)))
3292 warning_at (location
, OPT_Waddress
,
3293 "comparison with string literal results in unspecified behavior");
3295 else if (TREE_CODE_CLASS (code
) == tcc_comparison
3296 && (code1
== STRING_CST
|| code2
== STRING_CST
))
3297 warning_at (location
, OPT_Waddress
,
3298 "comparison with string literal results in unspecified behavior");
3300 if (TREE_OVERFLOW_P (result
.value
)
3301 && !TREE_OVERFLOW_P (arg1
.value
)
3302 && !TREE_OVERFLOW_P (arg2
.value
))
3303 overflow_warning (location
, result
.value
);
3305 /* Warn about comparisons of different enum types. */
3306 if (warn_enum_compare
3307 && TREE_CODE_CLASS (code
) == tcc_comparison
3308 && TREE_CODE (type1
) == ENUMERAL_TYPE
3309 && TREE_CODE (type2
) == ENUMERAL_TYPE
3310 && TYPE_MAIN_VARIANT (type1
) != TYPE_MAIN_VARIANT (type2
))
3311 warning_at (location
, OPT_Wenum_compare
,
3312 "comparison between %qT and %qT",
3318 /* Return a tree for the difference of pointers OP0 and OP1.
3319 The resulting tree has type int. */
3322 pointer_diff (location_t loc
, tree op0
, tree op1
)
3324 tree restype
= ptrdiff_type_node
;
3325 tree result
, inttype
;
3327 addr_space_t as0
= TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (op0
)));
3328 addr_space_t as1
= TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (op1
)));
3329 tree target_type
= TREE_TYPE (TREE_TYPE (op0
));
3330 tree con0
, con1
, lit0
, lit1
;
3331 tree orig_op1
= op1
;
3333 /* If the operands point into different address spaces, we need to
3334 explicitly convert them to pointers into the common address space
3335 before we can subtract the numerical address values. */
3338 addr_space_t as_common
;
3341 /* Determine the common superset address space. This is guaranteed
3342 to exist because the caller verified that comp_target_types
3343 returned non-zero. */
3344 if (!addr_space_superset (as0
, as1
, &as_common
))
3347 common_type
= common_pointer_type (TREE_TYPE (op0
), TREE_TYPE (op1
));
3348 op0
= convert (common_type
, op0
);
3349 op1
= convert (common_type
, op1
);
3352 /* Determine integer type to perform computations in. This will usually
3353 be the same as the result type (ptrdiff_t), but may need to be a wider
3354 type if pointers for the address space are wider than ptrdiff_t. */
3355 if (TYPE_PRECISION (restype
) < TYPE_PRECISION (TREE_TYPE (op0
)))
3356 inttype
= c_common_type_for_size (TYPE_PRECISION (TREE_TYPE (op0
)), 0);
3361 if (TREE_CODE (target_type
) == VOID_TYPE
)
3362 pedwarn (loc
, OPT_Wpointer_arith
,
3363 "pointer of type %<void *%> used in subtraction");
3364 if (TREE_CODE (target_type
) == FUNCTION_TYPE
)
3365 pedwarn (loc
, OPT_Wpointer_arith
,
3366 "pointer to a function used in subtraction");
3368 /* If the conversion to ptrdiff_type does anything like widening or
3369 converting a partial to an integral mode, we get a convert_expression
3370 that is in the way to do any simplifications.
3371 (fold-const.c doesn't know that the extra bits won't be needed.
3372 split_tree uses STRIP_SIGN_NOPS, which leaves conversions to a
3373 different mode in place.)
3374 So first try to find a common term here 'by hand'; we want to cover
3375 at least the cases that occur in legal static initializers. */
3376 if (CONVERT_EXPR_P (op0
)
3377 && (TYPE_PRECISION (TREE_TYPE (op0
))
3378 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0
, 0)))))
3379 con0
= TREE_OPERAND (op0
, 0);
3382 if (CONVERT_EXPR_P (op1
)
3383 && (TYPE_PRECISION (TREE_TYPE (op1
))
3384 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op1
, 0)))))
3385 con1
= TREE_OPERAND (op1
, 0);
3389 if (TREE_CODE (con0
) == POINTER_PLUS_EXPR
)
3391 lit0
= TREE_OPERAND (con0
, 1);
3392 con0
= TREE_OPERAND (con0
, 0);
3395 lit0
= integer_zero_node
;
3397 if (TREE_CODE (con1
) == POINTER_PLUS_EXPR
)
3399 lit1
= TREE_OPERAND (con1
, 1);
3400 con1
= TREE_OPERAND (con1
, 0);
3403 lit1
= integer_zero_node
;
3405 if (operand_equal_p (con0
, con1
, 0))
3412 /* First do the subtraction as integers;
3413 then drop through to build the divide operator.
3414 Do not do default conversions on the minus operator
3415 in case restype is a short type. */
3417 op0
= build_binary_op (loc
,
3418 MINUS_EXPR
, convert (inttype
, op0
),
3419 convert (inttype
, op1
), 0);
3420 /* This generates an error if op1 is pointer to incomplete type. */
3421 if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (orig_op1
))))
3422 error_at (loc
, "arithmetic on pointer to an incomplete type");
3424 /* This generates an error if op0 is pointer to incomplete type. */
3425 op1
= c_size_in_bytes (target_type
);
3427 /* Divide by the size, in easiest possible way. */
3428 result
= fold_build2_loc (loc
, EXACT_DIV_EXPR
, inttype
,
3429 op0
, convert (inttype
, op1
));
3431 /* Convert to final result type if necessary. */
3432 return convert (restype
, result
);
3435 /* Construct and perhaps optimize a tree representation
3436 for a unary operation. CODE, a tree_code, specifies the operation
3437 and XARG is the operand.
3438 For any CODE other than ADDR_EXPR, FLAG nonzero suppresses
3439 the default promotions (such as from short to int).
3440 For ADDR_EXPR, the default promotions are not applied; FLAG nonzero
3441 allows non-lvalues; this is only used to handle conversion of non-lvalue
3442 arrays to pointers in C99.
3444 LOCATION is the location of the operator. */
3447 build_unary_op (location_t location
,
3448 enum tree_code code
, tree xarg
, int flag
)
3450 /* No default_conversion here. It causes trouble for ADDR_EXPR. */
3453 enum tree_code typecode
;
3455 tree ret
= error_mark_node
;
3456 tree eptype
= NULL_TREE
;
3457 int noconvert
= flag
;
3458 const char *invalid_op_diag
;
3461 int_operands
= EXPR_INT_CONST_OPERANDS (xarg
);
3463 arg
= remove_c_maybe_const_expr (arg
);
3465 if (code
!= ADDR_EXPR
)
3466 arg
= require_complete_type (arg
);
3468 typecode
= TREE_CODE (TREE_TYPE (arg
));
3469 if (typecode
== ERROR_MARK
)
3470 return error_mark_node
;
3471 if (typecode
== ENUMERAL_TYPE
|| typecode
== BOOLEAN_TYPE
)
3472 typecode
= INTEGER_TYPE
;
3474 if ((invalid_op_diag
3475 = targetm
.invalid_unary_op (code
, TREE_TYPE (xarg
))))
3477 error_at (location
, invalid_op_diag
);
3478 return error_mark_node
;
3481 if (TREE_CODE (arg
) == EXCESS_PRECISION_EXPR
)
3483 eptype
= TREE_TYPE (arg
);
3484 arg
= TREE_OPERAND (arg
, 0);
3490 /* This is used for unary plus, because a CONVERT_EXPR
3491 is enough to prevent anybody from looking inside for
3492 associativity, but won't generate any code. */
3493 if (!(typecode
== INTEGER_TYPE
|| typecode
== REAL_TYPE
3494 || typecode
== FIXED_POINT_TYPE
|| typecode
== COMPLEX_TYPE
3495 || typecode
== VECTOR_TYPE
))
3497 error_at (location
, "wrong type argument to unary plus");
3498 return error_mark_node
;
3500 else if (!noconvert
)
3501 arg
= default_conversion (arg
);
3502 arg
= non_lvalue_loc (location
, arg
);
3506 if (!(typecode
== INTEGER_TYPE
|| typecode
== REAL_TYPE
3507 || typecode
== FIXED_POINT_TYPE
|| typecode
== COMPLEX_TYPE
3508 || typecode
== VECTOR_TYPE
))
3510 error_at (location
, "wrong type argument to unary minus");
3511 return error_mark_node
;
3513 else if (!noconvert
)
3514 arg
= default_conversion (arg
);
3518 /* ~ works on integer types and non float vectors. */
3519 if (typecode
== INTEGER_TYPE
3520 || (typecode
== VECTOR_TYPE
3521 && !VECTOR_FLOAT_TYPE_P (TREE_TYPE (arg
))))
3524 arg
= default_conversion (arg
);
3526 else if (typecode
== COMPLEX_TYPE
)
3529 pedwarn (location
, OPT_Wpedantic
,
3530 "ISO C does not support %<~%> for complex conjugation");
3532 arg
= default_conversion (arg
);
3536 error_at (location
, "wrong type argument to bit-complement");
3537 return error_mark_node
;
3542 if (!(typecode
== INTEGER_TYPE
|| typecode
== REAL_TYPE
))
3544 error_at (location
, "wrong type argument to abs");
3545 return error_mark_node
;
3547 else if (!noconvert
)
3548 arg
= default_conversion (arg
);
3552 /* Conjugating a real value is a no-op, but allow it anyway. */
3553 if (!(typecode
== INTEGER_TYPE
|| typecode
== REAL_TYPE
3554 || typecode
== COMPLEX_TYPE
))
3556 error_at (location
, "wrong type argument to conjugation");
3557 return error_mark_node
;
3559 else if (!noconvert
)
3560 arg
= default_conversion (arg
);
3563 case TRUTH_NOT_EXPR
:
3564 if (typecode
!= INTEGER_TYPE
&& typecode
!= FIXED_POINT_TYPE
3565 && typecode
!= REAL_TYPE
&& typecode
!= POINTER_TYPE
3566 && typecode
!= COMPLEX_TYPE
)
3569 "wrong type argument to unary exclamation mark");
3570 return error_mark_node
;
3574 arg
= c_objc_common_truthvalue_conversion (location
, xarg
);
3575 arg
= remove_c_maybe_const_expr (arg
);
3578 arg
= c_objc_common_truthvalue_conversion (location
, arg
);
3579 ret
= invert_truthvalue_loc (location
, arg
);
3580 /* If the TRUTH_NOT_EXPR has been folded, reset the location. */
3581 if (EXPR_P (ret
) && EXPR_HAS_LOCATION (ret
))
3582 location
= EXPR_LOCATION (ret
);
3583 goto return_build_unary_op
;
3587 ret
= build_real_imag_expr (location
, code
, arg
);
3588 if (ret
== error_mark_node
)
3589 return error_mark_node
;
3590 if (eptype
&& TREE_CODE (eptype
) == COMPLEX_TYPE
)
3591 eptype
= TREE_TYPE (eptype
);
3592 goto return_build_unary_op
;
3594 case PREINCREMENT_EXPR
:
3595 case POSTINCREMENT_EXPR
:
3596 case PREDECREMENT_EXPR
:
3597 case POSTDECREMENT_EXPR
:
3599 if (TREE_CODE (arg
) == C_MAYBE_CONST_EXPR
)
3601 tree inner
= build_unary_op (location
, code
,
3602 C_MAYBE_CONST_EXPR_EXPR (arg
), flag
);
3603 if (inner
== error_mark_node
)
3604 return error_mark_node
;
3605 ret
= build2 (C_MAYBE_CONST_EXPR
, TREE_TYPE (inner
),
3606 C_MAYBE_CONST_EXPR_PRE (arg
), inner
);
3607 gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (arg
));
3608 C_MAYBE_CONST_EXPR_NON_CONST (ret
) = 1;
3609 goto return_build_unary_op
;
3612 /* Complain about anything that is not a true lvalue. In
3613 Objective-C, skip this check for property_refs. */
3614 if (!objc_is_property_ref (arg
)
3615 && !lvalue_or_else (location
,
3616 arg
, ((code
== PREINCREMENT_EXPR
3617 || code
== POSTINCREMENT_EXPR
)
3620 return error_mark_node
;
3622 if (warn_cxx_compat
&& TREE_CODE (TREE_TYPE (arg
)) == ENUMERAL_TYPE
)
3624 if (code
== PREINCREMENT_EXPR
|| code
== POSTINCREMENT_EXPR
)
3625 warning_at (location
, OPT_Wc___compat
,
3626 "increment of enumeration value is invalid in C++");
3628 warning_at (location
, OPT_Wc___compat
,
3629 "decrement of enumeration value is invalid in C++");
3632 /* Ensure the argument is fully folded inside any SAVE_EXPR. */
3633 arg
= c_fully_fold (arg
, false, NULL
);
3635 /* Increment or decrement the real part of the value,
3636 and don't change the imaginary part. */
3637 if (typecode
== COMPLEX_TYPE
)
3641 pedwarn (location
, OPT_Wpedantic
,
3642 "ISO C does not support %<++%> and %<--%> on complex types");
3644 arg
= stabilize_reference (arg
);
3645 real
= build_unary_op (EXPR_LOCATION (arg
), REALPART_EXPR
, arg
, 1);
3646 imag
= build_unary_op (EXPR_LOCATION (arg
), IMAGPART_EXPR
, arg
, 1);
3647 real
= build_unary_op (EXPR_LOCATION (arg
), code
, real
, 1);
3648 if (real
== error_mark_node
|| imag
== error_mark_node
)
3649 return error_mark_node
;
3650 ret
= build2 (COMPLEX_EXPR
, TREE_TYPE (arg
),
3652 goto return_build_unary_op
;
3655 /* Report invalid types. */
3657 if (typecode
!= POINTER_TYPE
&& typecode
!= FIXED_POINT_TYPE
3658 && typecode
!= INTEGER_TYPE
&& typecode
!= REAL_TYPE
)
3660 if (code
== PREINCREMENT_EXPR
|| code
== POSTINCREMENT_EXPR
)
3661 error_at (location
, "wrong type argument to increment");
3663 error_at (location
, "wrong type argument to decrement");
3665 return error_mark_node
;
3671 argtype
= TREE_TYPE (arg
);
3673 /* Compute the increment. */
3675 if (typecode
== POINTER_TYPE
)
3677 /* If pointer target is an undefined struct,
3678 we just cannot know how to do the arithmetic. */
3679 if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (argtype
)))
3681 if (code
== PREINCREMENT_EXPR
|| code
== POSTINCREMENT_EXPR
)
3683 "increment of pointer to unknown structure");
3686 "decrement of pointer to unknown structure");
3688 else if (TREE_CODE (TREE_TYPE (argtype
)) == FUNCTION_TYPE
3689 || TREE_CODE (TREE_TYPE (argtype
)) == VOID_TYPE
)
3691 if (code
== PREINCREMENT_EXPR
|| code
== POSTINCREMENT_EXPR
)
3692 pedwarn (location
, OPT_Wpointer_arith
,
3693 "wrong type argument to increment");
3695 pedwarn (location
, OPT_Wpointer_arith
,
3696 "wrong type argument to decrement");
3699 inc
= c_size_in_bytes (TREE_TYPE (argtype
));
3700 inc
= convert_to_ptrofftype_loc (location
, inc
);
3702 else if (FRACT_MODE_P (TYPE_MODE (argtype
)))
3704 /* For signed fract types, we invert ++ to -- or
3705 -- to ++, and change inc from 1 to -1, because
3706 it is not possible to represent 1 in signed fract constants.
3707 For unsigned fract types, the result always overflows and
3708 we get an undefined (original) or the maximum value. */
3709 if (code
== PREINCREMENT_EXPR
)
3710 code
= PREDECREMENT_EXPR
;
3711 else if (code
== PREDECREMENT_EXPR
)
3712 code
= PREINCREMENT_EXPR
;
3713 else if (code
== POSTINCREMENT_EXPR
)
3714 code
= POSTDECREMENT_EXPR
;
3715 else /* code == POSTDECREMENT_EXPR */
3716 code
= POSTINCREMENT_EXPR
;
3718 inc
= integer_minus_one_node
;
3719 inc
= convert (argtype
, inc
);
3723 inc
= integer_one_node
;
3724 inc
= convert (argtype
, inc
);
3727 /* If 'arg' is an Objective-C PROPERTY_REF expression, then we
3728 need to ask Objective-C to build the increment or decrement
3729 expression for it. */
3730 if (objc_is_property_ref (arg
))
3731 return objc_build_incr_expr_for_property_ref (location
, code
,
3734 /* Report a read-only lvalue. */
3735 if (TYPE_READONLY (argtype
))
3737 readonly_error (arg
,
3738 ((code
== PREINCREMENT_EXPR
3739 || code
== POSTINCREMENT_EXPR
)
3740 ? lv_increment
: lv_decrement
));
3741 return error_mark_node
;
3743 else if (TREE_READONLY (arg
))
3744 readonly_warning (arg
,
3745 ((code
== PREINCREMENT_EXPR
3746 || code
== POSTINCREMENT_EXPR
)
3747 ? lv_increment
: lv_decrement
));
3749 if (TREE_CODE (TREE_TYPE (arg
)) == BOOLEAN_TYPE
)
3750 val
= boolean_increment (code
, arg
);
3752 val
= build2 (code
, TREE_TYPE (arg
), arg
, inc
);
3753 TREE_SIDE_EFFECTS (val
) = 1;
3754 if (TREE_CODE (val
) != code
)
3755 TREE_NO_WARNING (val
) = 1;
3757 goto return_build_unary_op
;
3761 /* Note that this operation never does default_conversion. */
3763 /* The operand of unary '&' must be an lvalue (which excludes
3764 expressions of type void), or, in C99, the result of a [] or
3765 unary '*' operator. */
3766 if (VOID_TYPE_P (TREE_TYPE (arg
))
3767 && TYPE_QUALS (TREE_TYPE (arg
)) == TYPE_UNQUALIFIED
3768 && (TREE_CODE (arg
) != INDIRECT_REF
3770 pedwarn (location
, 0, "taking address of expression of type %<void%>");
3772 /* Let &* cancel out to simplify resulting code. */
3773 if (TREE_CODE (arg
) == INDIRECT_REF
)
3775 /* Don't let this be an lvalue. */
3776 if (lvalue_p (TREE_OPERAND (arg
, 0)))
3777 return non_lvalue_loc (location
, TREE_OPERAND (arg
, 0));
3778 ret
= TREE_OPERAND (arg
, 0);
3779 goto return_build_unary_op
;
3782 /* For &x[y], return x+y */
3783 if (TREE_CODE (arg
) == ARRAY_REF
)
3785 tree op0
= TREE_OPERAND (arg
, 0);
3786 if (!c_mark_addressable (op0
))
3787 return error_mark_node
;
3790 /* Anything not already handled and not a true memory reference
3791 or a non-lvalue array is an error. */
3792 else if (typecode
!= FUNCTION_TYPE
&& !flag
3793 && !lvalue_or_else (location
, arg
, lv_addressof
))
3794 return error_mark_node
;
3796 /* Move address operations inside C_MAYBE_CONST_EXPR to simplify
3798 if (TREE_CODE (arg
) == C_MAYBE_CONST_EXPR
)
3800 tree inner
= build_unary_op (location
, code
,
3801 C_MAYBE_CONST_EXPR_EXPR (arg
), flag
);
3802 ret
= build2 (C_MAYBE_CONST_EXPR
, TREE_TYPE (inner
),
3803 C_MAYBE_CONST_EXPR_PRE (arg
), inner
);
3804 gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (arg
));
3805 C_MAYBE_CONST_EXPR_NON_CONST (ret
)
3806 = C_MAYBE_CONST_EXPR_NON_CONST (arg
);
3807 goto return_build_unary_op
;
3810 /* Ordinary case; arg is a COMPONENT_REF or a decl. */
3811 argtype
= TREE_TYPE (arg
);
3813 /* If the lvalue is const or volatile, merge that into the type
3814 to which the address will point. This is only needed
3815 for function types. */
3816 if ((DECL_P (arg
) || REFERENCE_CLASS_P (arg
))
3817 && (TREE_READONLY (arg
) || TREE_THIS_VOLATILE (arg
))
3818 && TREE_CODE (argtype
) == FUNCTION_TYPE
)
3820 int orig_quals
= TYPE_QUALS (strip_array_types (argtype
));
3821 int quals
= orig_quals
;
3823 if (TREE_READONLY (arg
))
3824 quals
|= TYPE_QUAL_CONST
;
3825 if (TREE_THIS_VOLATILE (arg
))
3826 quals
|= TYPE_QUAL_VOLATILE
;
3828 argtype
= c_build_qualified_type (argtype
, quals
);
3831 if (!c_mark_addressable (arg
))
3832 return error_mark_node
;
3834 gcc_assert (TREE_CODE (arg
) != COMPONENT_REF
3835 || !DECL_C_BIT_FIELD (TREE_OPERAND (arg
, 1)));
3837 argtype
= build_pointer_type (argtype
);
3839 /* ??? Cope with user tricks that amount to offsetof. Delete this
3840 when we have proper support for integer constant expressions. */
3841 val
= get_base_address (arg
);
3842 if (val
&& TREE_CODE (val
) == INDIRECT_REF
3843 && TREE_CONSTANT (TREE_OPERAND (val
, 0)))
3845 ret
= fold_convert_loc (location
, argtype
, fold_offsetof_1 (arg
));
3846 goto return_build_unary_op
;
3849 val
= build1 (ADDR_EXPR
, argtype
, arg
);
3852 goto return_build_unary_op
;
3859 argtype
= TREE_TYPE (arg
);
3860 if (TREE_CODE (arg
) == INTEGER_CST
)
3861 ret
= (require_constant_value
3862 ? fold_build1_initializer_loc (location
, code
, argtype
, arg
)
3863 : fold_build1_loc (location
, code
, argtype
, arg
));
3865 ret
= build1 (code
, argtype
, arg
);
3866 return_build_unary_op
:
3867 gcc_assert (ret
!= error_mark_node
);
3868 if (TREE_CODE (ret
) == INTEGER_CST
&& !TREE_OVERFLOW (ret
)
3869 && !(TREE_CODE (xarg
) == INTEGER_CST
&& !TREE_OVERFLOW (xarg
)))
3870 ret
= build1 (NOP_EXPR
, TREE_TYPE (ret
), ret
);
3871 else if (TREE_CODE (ret
) != INTEGER_CST
&& int_operands
)
3872 ret
= note_integer_operands (ret
);
3874 ret
= build1 (EXCESS_PRECISION_EXPR
, eptype
, ret
);
3875 protected_set_expr_location (ret
, location
);
3879 /* Return nonzero if REF is an lvalue valid for this language.
3880 Lvalues can be assigned, unless their type has TYPE_READONLY.
3881 Lvalues can have their address taken, unless they have C_DECL_REGISTER. */
3884 lvalue_p (const_tree ref
)
3886 const enum tree_code code
= TREE_CODE (ref
);
3893 return lvalue_p (TREE_OPERAND (ref
, 0));
3895 case C_MAYBE_CONST_EXPR
:
3896 return lvalue_p (TREE_OPERAND (ref
, 1));
3898 case COMPOUND_LITERAL_EXPR
:
3904 case ARRAY_NOTATION_REF
:
3909 return (TREE_CODE (TREE_TYPE (ref
)) != FUNCTION_TYPE
3910 && TREE_CODE (TREE_TYPE (ref
)) != METHOD_TYPE
);
3913 return TREE_CODE (TREE_TYPE (ref
)) == ARRAY_TYPE
;
3920 /* Give a warning for storing in something that is read-only in GCC
3921 terms but not const in ISO C terms. */
3924 readonly_warning (tree arg
, enum lvalue_use use
)
3929 warning (0, "assignment of read-only location %qE", arg
);
3932 warning (0, "increment of read-only location %qE", arg
);
3935 warning (0, "decrement of read-only location %qE", arg
);
3944 /* Return nonzero if REF is an lvalue valid for this language;
3945 otherwise, print an error message and return zero. USE says
3946 how the lvalue is being used and so selects the error message.
3947 LOCATION is the location at which any error should be reported. */
3950 lvalue_or_else (location_t loc
, const_tree ref
, enum lvalue_use use
)
3952 int win
= lvalue_p (ref
);
3955 lvalue_error (loc
, use
);
3960 /* Mark EXP saying that we need to be able to take the
3961 address of it; it should not be allocated in a register.
3962 Returns true if successful. */
3965 c_mark_addressable (tree exp
)
3970 switch (TREE_CODE (x
))
3973 if (DECL_C_BIT_FIELD (TREE_OPERAND (x
, 1)))
3976 ("cannot take address of bit-field %qD", TREE_OPERAND (x
, 1));
3980 /* ... fall through ... */
3986 x
= TREE_OPERAND (x
, 0);
3989 case COMPOUND_LITERAL_EXPR
:
3991 TREE_ADDRESSABLE (x
) = 1;
3998 if (C_DECL_REGISTER (x
)
3999 && DECL_NONLOCAL (x
))
4001 if (TREE_PUBLIC (x
) || TREE_STATIC (x
) || DECL_EXTERNAL (x
))
4004 ("global register variable %qD used in nested function", x
);
4007 pedwarn (input_location
, 0, "register variable %qD used in nested function", x
);
4009 else if (C_DECL_REGISTER (x
))
4011 if (TREE_PUBLIC (x
) || TREE_STATIC (x
) || DECL_EXTERNAL (x
))
4012 error ("address of global register variable %qD requested", x
);
4014 error ("address of register variable %qD requested", x
);
4020 TREE_ADDRESSABLE (x
) = 1;
4027 /* Convert EXPR to TYPE, warning about conversion problems with
4028 constants. SEMANTIC_TYPE is the type this conversion would use
4029 without excess precision. If SEMANTIC_TYPE is NULL, this function
4030 is equivalent to convert_and_check. This function is a wrapper that
4031 handles conversions that may be different than
4032 the usual ones because of excess precision. */
4035 ep_convert_and_check (tree type
, tree expr
, tree semantic_type
)
4037 if (TREE_TYPE (expr
) == type
)
4041 return convert_and_check (type
, expr
);
4043 if (TREE_CODE (TREE_TYPE (expr
)) == INTEGER_TYPE
4044 && TREE_TYPE (expr
) != semantic_type
)
4046 /* For integers, we need to check the real conversion, not
4047 the conversion to the excess precision type. */
4048 expr
= convert_and_check (semantic_type
, expr
);
4050 /* Result type is the excess precision type, which should be
4051 large enough, so do not check. */
4052 return convert (type
, expr
);
4055 /* Build and return a conditional expression IFEXP ? OP1 : OP2. If
4056 IFEXP_BCP then the condition is a call to __builtin_constant_p, and
4057 if folded to an integer constant then the unselected half may
4058 contain arbitrary operations not normally permitted in constant
4059 expressions. Set the location of the expression to LOC. */
4062 build_conditional_expr (location_t colon_loc
, tree ifexp
, bool ifexp_bcp
,
4063 tree op1
, tree op1_original_type
, tree op2
,
4064 tree op2_original_type
)
4068 enum tree_code code1
;
4069 enum tree_code code2
;
4070 tree result_type
= NULL
;
4071 tree semantic_result_type
= NULL
;
4072 tree orig_op1
= op1
, orig_op2
= op2
;
4073 bool int_const
, op1_int_operands
, op2_int_operands
, int_operands
;
4074 bool ifexp_int_operands
;
4077 op1_int_operands
= EXPR_INT_CONST_OPERANDS (orig_op1
);
4078 if (op1_int_operands
)
4079 op1
= remove_c_maybe_const_expr (op1
);
4080 op2_int_operands
= EXPR_INT_CONST_OPERANDS (orig_op2
);
4081 if (op2_int_operands
)
4082 op2
= remove_c_maybe_const_expr (op2
);
4083 ifexp_int_operands
= EXPR_INT_CONST_OPERANDS (ifexp
);
4084 if (ifexp_int_operands
)
4085 ifexp
= remove_c_maybe_const_expr (ifexp
);
4087 /* Promote both alternatives. */
4089 if (TREE_CODE (TREE_TYPE (op1
)) != VOID_TYPE
)
4090 op1
= default_conversion (op1
);
4091 if (TREE_CODE (TREE_TYPE (op2
)) != VOID_TYPE
)
4092 op2
= default_conversion (op2
);
4094 if (TREE_CODE (ifexp
) == ERROR_MARK
4095 || TREE_CODE (TREE_TYPE (op1
)) == ERROR_MARK
4096 || TREE_CODE (TREE_TYPE (op2
)) == ERROR_MARK
)
4097 return error_mark_node
;
4099 type1
= TREE_TYPE (op1
);
4100 code1
= TREE_CODE (type1
);
4101 type2
= TREE_TYPE (op2
);
4102 code2
= TREE_CODE (type2
);
4104 /* C90 does not permit non-lvalue arrays in conditional expressions.
4105 In C99 they will be pointers by now. */
4106 if (code1
== ARRAY_TYPE
|| code2
== ARRAY_TYPE
)
4108 error_at (colon_loc
, "non-lvalue array in conditional expression");
4109 return error_mark_node
;
4112 if ((TREE_CODE (op1
) == EXCESS_PRECISION_EXPR
4113 || TREE_CODE (op2
) == EXCESS_PRECISION_EXPR
)
4114 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
4115 || code1
== COMPLEX_TYPE
)
4116 && (code2
== INTEGER_TYPE
|| code2
== REAL_TYPE
4117 || code2
== COMPLEX_TYPE
))
4119 semantic_result_type
= c_common_type (type1
, type2
);
4120 if (TREE_CODE (op1
) == EXCESS_PRECISION_EXPR
)
4122 op1
= TREE_OPERAND (op1
, 0);
4123 type1
= TREE_TYPE (op1
);
4124 gcc_assert (TREE_CODE (type1
) == code1
);
4126 if (TREE_CODE (op2
) == EXCESS_PRECISION_EXPR
)
4128 op2
= TREE_OPERAND (op2
, 0);
4129 type2
= TREE_TYPE (op2
);
4130 gcc_assert (TREE_CODE (type2
) == code2
);
4134 if (warn_cxx_compat
)
4136 tree t1
= op1_original_type
? op1_original_type
: TREE_TYPE (orig_op1
);
4137 tree t2
= op2_original_type
? op2_original_type
: TREE_TYPE (orig_op2
);
4139 if (TREE_CODE (t1
) == ENUMERAL_TYPE
4140 && TREE_CODE (t2
) == ENUMERAL_TYPE
4141 && TYPE_MAIN_VARIANT (t1
) != TYPE_MAIN_VARIANT (t2
))
4142 warning_at (colon_loc
, OPT_Wc___compat
,
4143 ("different enum types in conditional is "
4144 "invalid in C++: %qT vs %qT"),
4148 /* Quickly detect the usual case where op1 and op2 have the same type
4150 if (TYPE_MAIN_VARIANT (type1
) == TYPE_MAIN_VARIANT (type2
))
4153 result_type
= type1
;
4155 result_type
= TYPE_MAIN_VARIANT (type1
);
4157 else if ((code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
4158 || code1
== COMPLEX_TYPE
)
4159 && (code2
== INTEGER_TYPE
|| code2
== REAL_TYPE
4160 || code2
== COMPLEX_TYPE
))
4162 result_type
= c_common_type (type1
, type2
);
4163 do_warn_double_promotion (result_type
, type1
, type2
,
4164 "implicit conversion from %qT to %qT to "
4165 "match other result of conditional",
4168 /* If -Wsign-compare, warn here if type1 and type2 have
4169 different signedness. We'll promote the signed to unsigned
4170 and later code won't know it used to be different.
4171 Do this check on the original types, so that explicit casts
4172 will be considered, but default promotions won't. */
4173 if (c_inhibit_evaluation_warnings
== 0)
4175 int unsigned_op1
= TYPE_UNSIGNED (TREE_TYPE (orig_op1
));
4176 int unsigned_op2
= TYPE_UNSIGNED (TREE_TYPE (orig_op2
));
4178 if (unsigned_op1
^ unsigned_op2
)
4182 /* Do not warn if the result type is signed, since the
4183 signed type will only be chosen if it can represent
4184 all the values of the unsigned type. */
4185 if (!TYPE_UNSIGNED (result_type
))
4189 bool op1_maybe_const
= true;
4190 bool op2_maybe_const
= true;
4192 /* Do not warn if the signed quantity is an
4193 unsuffixed integer literal (or some static
4194 constant expression involving such literals) and
4195 it is non-negative. This warning requires the
4196 operands to be folded for best results, so do
4197 that folding in this case even without
4198 warn_sign_compare to avoid warning options
4199 possibly affecting code generation. */
4200 c_inhibit_evaluation_warnings
4201 += (ifexp
== truthvalue_false_node
);
4202 op1
= c_fully_fold (op1
, require_constant_value
,
4204 c_inhibit_evaluation_warnings
4205 -= (ifexp
== truthvalue_false_node
);
4207 c_inhibit_evaluation_warnings
4208 += (ifexp
== truthvalue_true_node
);
4209 op2
= c_fully_fold (op2
, require_constant_value
,
4211 c_inhibit_evaluation_warnings
4212 -= (ifexp
== truthvalue_true_node
);
4214 if (warn_sign_compare
)
4217 && tree_expr_nonnegative_warnv_p (op1
, &ovf
))
4219 && tree_expr_nonnegative_warnv_p (op2
, &ovf
)))
4222 warning_at (colon_loc
, OPT_Wsign_compare
,
4223 ("signed and unsigned type in "
4224 "conditional expression"));
4226 if (!op1_maybe_const
|| TREE_CODE (op1
) != INTEGER_CST
)
4227 op1
= c_wrap_maybe_const (op1
, !op1_maybe_const
);
4228 if (!op2_maybe_const
|| TREE_CODE (op2
) != INTEGER_CST
)
4229 op2
= c_wrap_maybe_const (op2
, !op2_maybe_const
);
4234 else if (code1
== VOID_TYPE
|| code2
== VOID_TYPE
)
4236 if (code1
!= VOID_TYPE
|| code2
!= VOID_TYPE
)
4237 pedwarn (colon_loc
, OPT_Wpedantic
,
4238 "ISO C forbids conditional expr with only one void side");
4239 result_type
= void_type_node
;
4241 else if (code1
== POINTER_TYPE
&& code2
== POINTER_TYPE
)
4243 addr_space_t as1
= TYPE_ADDR_SPACE (TREE_TYPE (type1
));
4244 addr_space_t as2
= TYPE_ADDR_SPACE (TREE_TYPE (type2
));
4245 addr_space_t as_common
;
4247 if (comp_target_types (colon_loc
, type1
, type2
))
4248 result_type
= common_pointer_type (type1
, type2
);
4249 else if (null_pointer_constant_p (orig_op1
))
4250 result_type
= type2
;
4251 else if (null_pointer_constant_p (orig_op2
))
4252 result_type
= type1
;
4253 else if (!addr_space_superset (as1
, as2
, &as_common
))
4255 error_at (colon_loc
, "pointers to disjoint address spaces "
4256 "used in conditional expression");
4257 return error_mark_node
;
4259 else if (VOID_TYPE_P (TREE_TYPE (type1
)))
4261 if (TREE_CODE (TREE_TYPE (type2
)) == FUNCTION_TYPE
)
4262 pedwarn (colon_loc
, OPT_Wpedantic
,
4263 "ISO C forbids conditional expr between "
4264 "%<void *%> and function pointer");
4265 result_type
= build_pointer_type (qualify_type (TREE_TYPE (type1
),
4266 TREE_TYPE (type2
)));
4268 else if (VOID_TYPE_P (TREE_TYPE (type2
)))
4270 if (TREE_CODE (TREE_TYPE (type1
)) == FUNCTION_TYPE
)
4271 pedwarn (colon_loc
, OPT_Wpedantic
,
4272 "ISO C forbids conditional expr between "
4273 "%<void *%> and function pointer");
4274 result_type
= build_pointer_type (qualify_type (TREE_TYPE (type2
),
4275 TREE_TYPE (type1
)));
4277 /* Objective-C pointer comparisons are a bit more lenient. */
4278 else if (objc_have_common_type (type1
, type2
, -3, NULL_TREE
))
4279 result_type
= objc_common_type (type1
, type2
);
4282 int qual
= ENCODE_QUAL_ADDR_SPACE (as_common
);
4284 pedwarn (colon_loc
, 0,
4285 "pointer type mismatch in conditional expression");
4286 result_type
= build_pointer_type
4287 (build_qualified_type (void_type_node
, qual
));
4290 else if (code1
== POINTER_TYPE
&& code2
== INTEGER_TYPE
)
4292 if (!null_pointer_constant_p (orig_op2
))
4293 pedwarn (colon_loc
, 0,
4294 "pointer/integer type mismatch in conditional expression");
4297 op2
= null_pointer_node
;
4299 result_type
= type1
;
4301 else if (code2
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
4303 if (!null_pointer_constant_p (orig_op1
))
4304 pedwarn (colon_loc
, 0,
4305 "pointer/integer type mismatch in conditional expression");
4308 op1
= null_pointer_node
;
4310 result_type
= type2
;
4315 if (flag_cond_mismatch
)
4316 result_type
= void_type_node
;
4319 error_at (colon_loc
, "type mismatch in conditional expression");
4320 return error_mark_node
;
4324 /* Merge const and volatile flags of the incoming types. */
4326 = build_type_variant (result_type
,
4327 TYPE_READONLY (type1
) || TYPE_READONLY (type2
),
4328 TYPE_VOLATILE (type1
) || TYPE_VOLATILE (type2
));
4330 op1
= ep_convert_and_check (result_type
, op1
, semantic_result_type
);
4331 op2
= ep_convert_and_check (result_type
, op2
, semantic_result_type
);
4333 if (ifexp_bcp
&& ifexp
== truthvalue_true_node
)
4335 op2_int_operands
= true;
4336 op1
= c_fully_fold (op1
, require_constant_value
, NULL
);
4338 if (ifexp_bcp
&& ifexp
== truthvalue_false_node
)
4340 op1_int_operands
= true;
4341 op2
= c_fully_fold (op2
, require_constant_value
, NULL
);
4343 int_const
= int_operands
= (ifexp_int_operands
4345 && op2_int_operands
);
4348 int_const
= ((ifexp
== truthvalue_true_node
4349 && TREE_CODE (orig_op1
) == INTEGER_CST
4350 && !TREE_OVERFLOW (orig_op1
))
4351 || (ifexp
== truthvalue_false_node
4352 && TREE_CODE (orig_op2
) == INTEGER_CST
4353 && !TREE_OVERFLOW (orig_op2
)));
4355 if (int_const
|| (ifexp_bcp
&& TREE_CODE (ifexp
) == INTEGER_CST
))
4356 ret
= fold_build3_loc (colon_loc
, COND_EXPR
, result_type
, ifexp
, op1
, op2
);
4361 op1
= remove_c_maybe_const_expr (op1
);
4362 op2
= remove_c_maybe_const_expr (op2
);
4364 ret
= build3 (COND_EXPR
, result_type
, ifexp
, op1
, op2
);
4366 ret
= note_integer_operands (ret
);
4368 if (semantic_result_type
)
4369 ret
= build1 (EXCESS_PRECISION_EXPR
, semantic_result_type
, ret
);
4371 protected_set_expr_location (ret
, colon_loc
);
4375 /* Return a compound expression that performs two expressions and
4376 returns the value of the second of them.
4378 LOC is the location of the COMPOUND_EXPR. */
4381 build_compound_expr (location_t loc
, tree expr1
, tree expr2
)
4383 bool expr1_int_operands
, expr2_int_operands
;
4384 tree eptype
= NULL_TREE
;
4387 expr1_int_operands
= EXPR_INT_CONST_OPERANDS (expr1
);
4388 if (expr1_int_operands
)
4389 expr1
= remove_c_maybe_const_expr (expr1
);
4390 expr2_int_operands
= EXPR_INT_CONST_OPERANDS (expr2
);
4391 if (expr2_int_operands
)
4392 expr2
= remove_c_maybe_const_expr (expr2
);
4394 if (TREE_CODE (expr1
) == EXCESS_PRECISION_EXPR
)
4395 expr1
= TREE_OPERAND (expr1
, 0);
4396 if (TREE_CODE (expr2
) == EXCESS_PRECISION_EXPR
)
4398 eptype
= TREE_TYPE (expr2
);
4399 expr2
= TREE_OPERAND (expr2
, 0);
4402 if (!TREE_SIDE_EFFECTS (expr1
))
4404 /* The left-hand operand of a comma expression is like an expression
4405 statement: with -Wunused, we should warn if it doesn't have
4406 any side-effects, unless it was explicitly cast to (void). */
4407 if (warn_unused_value
)
4409 if (VOID_TYPE_P (TREE_TYPE (expr1
))
4410 && CONVERT_EXPR_P (expr1
))
4412 else if (VOID_TYPE_P (TREE_TYPE (expr1
))
4413 && TREE_CODE (expr1
) == COMPOUND_EXPR
4414 && CONVERT_EXPR_P (TREE_OPERAND (expr1
, 1)))
4415 ; /* (void) a, (void) b, c */
4417 warning_at (loc
, OPT_Wunused_value
,
4418 "left-hand operand of comma expression has no effect");
4422 /* With -Wunused, we should also warn if the left-hand operand does have
4423 side-effects, but computes a value which is not used. For example, in
4424 `foo() + bar(), baz()' the result of the `+' operator is not used,
4425 so we should issue a warning. */
4426 else if (warn_unused_value
)
4427 warn_if_unused_value (expr1
, loc
);
4429 if (expr2
== error_mark_node
)
4430 return error_mark_node
;
4432 ret
= build2 (COMPOUND_EXPR
, TREE_TYPE (expr2
), expr1
, expr2
);
4435 && expr1_int_operands
4436 && expr2_int_operands
)
4437 ret
= note_integer_operands (ret
);
4440 ret
= build1 (EXCESS_PRECISION_EXPR
, eptype
, ret
);
4442 protected_set_expr_location (ret
, loc
);
4446 /* Issue -Wcast-qual warnings when appropriate. TYPE is the type to
4447 which we are casting. OTYPE is the type of the expression being
4448 cast. Both TYPE and OTYPE are pointer types. LOC is the location
4449 of the cast. -Wcast-qual appeared on the command line. Named
4450 address space qualifiers are not handled here, because they result
4451 in different warnings. */
4454 handle_warn_cast_qual (location_t loc
, tree type
, tree otype
)
4456 tree in_type
= type
;
4457 tree in_otype
= otype
;
4462 /* Check that the qualifiers on IN_TYPE are a superset of the
4463 qualifiers of IN_OTYPE. The outermost level of POINTER_TYPE
4464 nodes is uninteresting and we stop as soon as we hit a
4465 non-POINTER_TYPE node on either type. */
4468 in_otype
= TREE_TYPE (in_otype
);
4469 in_type
= TREE_TYPE (in_type
);
4471 /* GNU C allows cv-qualified function types. 'const' means the
4472 function is very pure, 'volatile' means it can't return. We
4473 need to warn when such qualifiers are added, not when they're
4475 if (TREE_CODE (in_otype
) == FUNCTION_TYPE
4476 && TREE_CODE (in_type
) == FUNCTION_TYPE
)
4477 added
|= (TYPE_QUALS_NO_ADDR_SPACE (in_type
)
4478 & ~TYPE_QUALS_NO_ADDR_SPACE (in_otype
));
4480 discarded
|= (TYPE_QUALS_NO_ADDR_SPACE (in_otype
)
4481 & ~TYPE_QUALS_NO_ADDR_SPACE (in_type
));
4483 while (TREE_CODE (in_type
) == POINTER_TYPE
4484 && TREE_CODE (in_otype
) == POINTER_TYPE
);
4487 warning_at (loc
, OPT_Wcast_qual
,
4488 "cast adds %q#v qualifier to function type", added
);
4491 /* There are qualifiers present in IN_OTYPE that are not present
4493 warning_at (loc
, OPT_Wcast_qual
,
4494 "cast discards %q#v qualifier from pointer target type",
4497 if (added
|| discarded
)
4500 /* A cast from **T to const **T is unsafe, because it can cause a
4501 const value to be changed with no additional warning. We only
4502 issue this warning if T is the same on both sides, and we only
4503 issue the warning if there are the same number of pointers on
4504 both sides, as otherwise the cast is clearly unsafe anyhow. A
4505 cast is unsafe when a qualifier is added at one level and const
4506 is not present at all outer levels.
4508 To issue this warning, we check at each level whether the cast
4509 adds new qualifiers not already seen. We don't need to special
4510 case function types, as they won't have the same
4511 TYPE_MAIN_VARIANT. */
4513 if (TYPE_MAIN_VARIANT (in_type
) != TYPE_MAIN_VARIANT (in_otype
))
4515 if (TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
)
4520 is_const
= TYPE_READONLY (TREE_TYPE (in_type
));
4523 in_type
= TREE_TYPE (in_type
);
4524 in_otype
= TREE_TYPE (in_otype
);
4525 if ((TYPE_QUALS (in_type
) &~ TYPE_QUALS (in_otype
)) != 0
4528 warning_at (loc
, OPT_Wcast_qual
,
4529 "to be safe all intermediate pointers in cast from "
4530 "%qT to %qT must be %<const%> qualified",
4535 is_const
= TYPE_READONLY (in_type
);
4537 while (TREE_CODE (in_type
) == POINTER_TYPE
);
4540 /* Build an expression representing a cast to type TYPE of expression EXPR.
4541 LOC is the location of the cast-- typically the open paren of the cast. */
4544 build_c_cast (location_t loc
, tree type
, tree expr
)
4548 if (TREE_CODE (expr
) == EXCESS_PRECISION_EXPR
)
4549 expr
= TREE_OPERAND (expr
, 0);
4553 if (type
== error_mark_node
|| expr
== error_mark_node
)
4554 return error_mark_node
;
4556 /* The ObjC front-end uses TYPE_MAIN_VARIANT to tie together types differing
4557 only in <protocol> qualifications. But when constructing cast expressions,
4558 the protocols do matter and must be kept around. */
4559 if (objc_is_object_ptr (type
) && objc_is_object_ptr (TREE_TYPE (expr
)))
4560 return build1 (NOP_EXPR
, type
, expr
);
4562 type
= TYPE_MAIN_VARIANT (type
);
4564 if (TREE_CODE (type
) == ARRAY_TYPE
)
4566 error_at (loc
, "cast specifies array type");
4567 return error_mark_node
;
4570 if (TREE_CODE (type
) == FUNCTION_TYPE
)
4572 error_at (loc
, "cast specifies function type");
4573 return error_mark_node
;
4576 if (!VOID_TYPE_P (type
))
4578 value
= require_complete_type (value
);
4579 if (value
== error_mark_node
)
4580 return error_mark_node
;
4583 if (type
== TYPE_MAIN_VARIANT (TREE_TYPE (value
)))
4585 if (TREE_CODE (type
) == RECORD_TYPE
4586 || TREE_CODE (type
) == UNION_TYPE
)
4587 pedwarn (loc
, OPT_Wpedantic
,
4588 "ISO C forbids casting nonscalar to the same type");
4590 else if (TREE_CODE (type
) == UNION_TYPE
)
4594 for (field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
4595 if (TREE_TYPE (field
) != error_mark_node
4596 && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (field
)),
4597 TYPE_MAIN_VARIANT (TREE_TYPE (value
))))
4603 bool maybe_const
= true;
4605 pedwarn (loc
, OPT_Wpedantic
, "ISO C forbids casts to union type");
4606 t
= c_fully_fold (value
, false, &maybe_const
);
4607 t
= build_constructor_single (type
, field
, t
);
4609 t
= c_wrap_maybe_const (t
, true);
4610 t
= digest_init (loc
, type
, t
,
4611 NULL_TREE
, false, true, 0);
4612 TREE_CONSTANT (t
) = TREE_CONSTANT (value
);
4615 error_at (loc
, "cast to union type from type not present in union");
4616 return error_mark_node
;
4622 if (type
== void_type_node
)
4624 tree t
= build1 (CONVERT_EXPR
, type
, value
);
4625 SET_EXPR_LOCATION (t
, loc
);
4629 otype
= TREE_TYPE (value
);
4631 /* Optionally warn about potentially worrisome casts. */
4633 && TREE_CODE (type
) == POINTER_TYPE
4634 && TREE_CODE (otype
) == POINTER_TYPE
)
4635 handle_warn_cast_qual (loc
, type
, otype
);
4637 /* Warn about conversions between pointers to disjoint
4639 if (TREE_CODE (type
) == POINTER_TYPE
4640 && TREE_CODE (otype
) == POINTER_TYPE
4641 && !null_pointer_constant_p (value
))
4643 addr_space_t as_to
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
4644 addr_space_t as_from
= TYPE_ADDR_SPACE (TREE_TYPE (otype
));
4645 addr_space_t as_common
;
4647 if (!addr_space_superset (as_to
, as_from
, &as_common
))
4649 if (ADDR_SPACE_GENERIC_P (as_from
))
4650 warning_at (loc
, 0, "cast to %s address space pointer "
4651 "from disjoint generic address space pointer",
4652 c_addr_space_name (as_to
));
4654 else if (ADDR_SPACE_GENERIC_P (as_to
))
4655 warning_at (loc
, 0, "cast to generic address space pointer "
4656 "from disjoint %s address space pointer",
4657 c_addr_space_name (as_from
));
4660 warning_at (loc
, 0, "cast to %s address space pointer "
4661 "from disjoint %s address space pointer",
4662 c_addr_space_name (as_to
),
4663 c_addr_space_name (as_from
));
4667 /* Warn about possible alignment problems. */
4668 if (STRICT_ALIGNMENT
4669 && TREE_CODE (type
) == POINTER_TYPE
4670 && TREE_CODE (otype
) == POINTER_TYPE
4671 && TREE_CODE (TREE_TYPE (otype
)) != VOID_TYPE
4672 && TREE_CODE (TREE_TYPE (otype
)) != FUNCTION_TYPE
4673 /* Don't warn about opaque types, where the actual alignment
4674 restriction is unknown. */
4675 && !((TREE_CODE (TREE_TYPE (otype
)) == UNION_TYPE
4676 || TREE_CODE (TREE_TYPE (otype
)) == RECORD_TYPE
)
4677 && TYPE_MODE (TREE_TYPE (otype
)) == VOIDmode
)
4678 && TYPE_ALIGN (TREE_TYPE (type
)) > TYPE_ALIGN (TREE_TYPE (otype
)))
4679 warning_at (loc
, OPT_Wcast_align
,
4680 "cast increases required alignment of target type");
4682 if (TREE_CODE (type
) == INTEGER_TYPE
4683 && TREE_CODE (otype
) == POINTER_TYPE
4684 && TYPE_PRECISION (type
) != TYPE_PRECISION (otype
))
4685 /* Unlike conversion of integers to pointers, where the
4686 warning is disabled for converting constants because
4687 of cases such as SIG_*, warn about converting constant
4688 pointers to integers. In some cases it may cause unwanted
4689 sign extension, and a warning is appropriate. */
4690 warning_at (loc
, OPT_Wpointer_to_int_cast
,
4691 "cast from pointer to integer of different size");
4693 if (TREE_CODE (value
) == CALL_EXPR
4694 && TREE_CODE (type
) != TREE_CODE (otype
))
4695 warning_at (loc
, OPT_Wbad_function_cast
,
4696 "cast from function call of type %qT "
4697 "to non-matching type %qT", otype
, type
);
4699 if (TREE_CODE (type
) == POINTER_TYPE
4700 && TREE_CODE (otype
) == INTEGER_TYPE
4701 && TYPE_PRECISION (type
) != TYPE_PRECISION (otype
)
4702 /* Don't warn about converting any constant. */
4703 && !TREE_CONSTANT (value
))
4705 OPT_Wint_to_pointer_cast
, "cast to pointer from integer "
4706 "of different size");
4708 if (warn_strict_aliasing
<= 2)
4709 strict_aliasing_warning (otype
, type
, expr
);
4711 /* If pedantic, warn for conversions between function and object
4712 pointer types, except for converting a null pointer constant
4713 to function pointer type. */
4715 && TREE_CODE (type
) == POINTER_TYPE
4716 && TREE_CODE (otype
) == POINTER_TYPE
4717 && TREE_CODE (TREE_TYPE (otype
)) == FUNCTION_TYPE
4718 && TREE_CODE (TREE_TYPE (type
)) != FUNCTION_TYPE
)
4719 pedwarn (loc
, OPT_Wpedantic
, "ISO C forbids "
4720 "conversion of function pointer to object pointer type");
4723 && TREE_CODE (type
) == POINTER_TYPE
4724 && TREE_CODE (otype
) == POINTER_TYPE
4725 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
4726 && TREE_CODE (TREE_TYPE (otype
)) != FUNCTION_TYPE
4727 && !null_pointer_constant_p (value
))
4728 pedwarn (loc
, OPT_Wpedantic
, "ISO C forbids "
4729 "conversion of object pointer to function pointer type");
4732 value
= convert (type
, value
);
4734 /* Ignore any integer overflow caused by the cast. */
4735 if (TREE_CODE (value
) == INTEGER_CST
&& !FLOAT_TYPE_P (otype
))
4737 if (CONSTANT_CLASS_P (ovalue
) && TREE_OVERFLOW (ovalue
))
4739 if (!TREE_OVERFLOW (value
))
4741 /* Avoid clobbering a shared constant. */
4742 value
= copy_node (value
);
4743 TREE_OVERFLOW (value
) = TREE_OVERFLOW (ovalue
);
4746 else if (TREE_OVERFLOW (value
))
4747 /* Reset VALUE's overflow flags, ensuring constant sharing. */
4748 value
= build_int_cst_wide (TREE_TYPE (value
),
4749 TREE_INT_CST_LOW (value
),
4750 TREE_INT_CST_HIGH (value
));
4754 /* Don't let a cast be an lvalue. */
4756 value
= non_lvalue_loc (loc
, value
);
4758 /* Don't allow the results of casting to floating-point or complex
4759 types be confused with actual constants, or casts involving
4760 integer and pointer types other than direct integer-to-integer
4761 and integer-to-pointer be confused with integer constant
4762 expressions and null pointer constants. */
4763 if (TREE_CODE (value
) == REAL_CST
4764 || TREE_CODE (value
) == COMPLEX_CST
4765 || (TREE_CODE (value
) == INTEGER_CST
4766 && !((TREE_CODE (expr
) == INTEGER_CST
4767 && INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
4768 || TREE_CODE (expr
) == REAL_CST
4769 || TREE_CODE (expr
) == COMPLEX_CST
)))
4770 value
= build1 (NOP_EXPR
, type
, value
);
4772 if (CAN_HAVE_LOCATION_P (value
))
4773 SET_EXPR_LOCATION (value
, loc
);
4777 /* Interpret a cast of expression EXPR to type TYPE. LOC is the
4778 location of the open paren of the cast, or the position of the cast
4781 c_cast_expr (location_t loc
, struct c_type_name
*type_name
, tree expr
)
4784 tree type_expr
= NULL_TREE
;
4785 bool type_expr_const
= true;
4787 int saved_wsp
= warn_strict_prototypes
;
4789 /* This avoids warnings about unprototyped casts on
4790 integers. E.g. "#define SIG_DFL (void(*)())0". */
4791 if (TREE_CODE (expr
) == INTEGER_CST
)
4792 warn_strict_prototypes
= 0;
4793 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
4794 warn_strict_prototypes
= saved_wsp
;
4796 ret
= build_c_cast (loc
, type
, expr
);
4799 bool inner_expr_const
= true;
4800 ret
= c_fully_fold (ret
, require_constant_value
, &inner_expr_const
);
4801 ret
= build2 (C_MAYBE_CONST_EXPR
, TREE_TYPE (ret
), type_expr
, ret
);
4802 C_MAYBE_CONST_EXPR_NON_CONST (ret
) = !(type_expr_const
4803 && inner_expr_const
);
4804 SET_EXPR_LOCATION (ret
, loc
);
4807 if (CAN_HAVE_LOCATION_P (ret
) && !EXPR_HAS_LOCATION (ret
))
4808 SET_EXPR_LOCATION (ret
, loc
);
4810 /* C++ does not permits types to be defined in a cast, but it
4811 allows references to incomplete types. */
4812 if (warn_cxx_compat
&& type_name
->specs
->typespec_kind
== ctsk_tagdef
)
4813 warning_at (loc
, OPT_Wc___compat
,
4814 "defining a type in a cast is invalid in C++");
4819 /* Build an assignment expression of lvalue LHS from value RHS.
4820 If LHS_ORIGTYPE is not NULL, it is the original type of LHS, which
4821 may differ from TREE_TYPE (LHS) for an enum bitfield.
4822 MODIFYCODE is the code for a binary operator that we use
4823 to combine the old value of LHS with RHS to get the new value.
4824 Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.
4825 If RHS_ORIGTYPE is not NULL_TREE, it is the original type of RHS,
4826 which may differ from TREE_TYPE (RHS) for an enum value.
4828 LOCATION is the location of the MODIFYCODE operator.
4829 RHS_LOC is the location of the RHS. */
4832 build_modify_expr (location_t location
, tree lhs
, tree lhs_origtype
,
4833 enum tree_code modifycode
,
4834 location_t rhs_loc
, tree rhs
, tree rhs_origtype
)
4838 tree rhs_semantic_type
= NULL_TREE
;
4839 tree lhstype
= TREE_TYPE (lhs
);
4840 tree olhstype
= lhstype
;
4843 /* Types that aren't fully specified cannot be used in assignments. */
4844 lhs
= require_complete_type (lhs
);
4846 /* Avoid duplicate error messages from operands that had errors. */
4847 if (TREE_CODE (lhs
) == ERROR_MARK
|| TREE_CODE (rhs
) == ERROR_MARK
)
4848 return error_mark_node
;
4850 /* For ObjC properties, defer this check. */
4851 if (!objc_is_property_ref (lhs
) && !lvalue_or_else (location
, lhs
, lv_assign
))
4852 return error_mark_node
;
4854 if (TREE_CODE (rhs
) == EXCESS_PRECISION_EXPR
)
4856 rhs_semantic_type
= TREE_TYPE (rhs
);
4857 rhs
= TREE_OPERAND (rhs
, 0);
4862 if (TREE_CODE (lhs
) == C_MAYBE_CONST_EXPR
)
4864 tree inner
= build_modify_expr (location
, C_MAYBE_CONST_EXPR_EXPR (lhs
),
4865 lhs_origtype
, modifycode
, rhs_loc
, rhs
,
4867 if (inner
== error_mark_node
)
4868 return error_mark_node
;
4869 result
= build2 (C_MAYBE_CONST_EXPR
, TREE_TYPE (inner
),
4870 C_MAYBE_CONST_EXPR_PRE (lhs
), inner
);
4871 gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (lhs
));
4872 C_MAYBE_CONST_EXPR_NON_CONST (result
) = 1;
4873 protected_set_expr_location (result
, location
);
4877 /* If a binary op has been requested, combine the old LHS value with the RHS
4878 producing the value we should actually store into the LHS. */
4880 if (modifycode
!= NOP_EXPR
)
4882 lhs
= c_fully_fold (lhs
, false, NULL
);
4883 lhs
= stabilize_reference (lhs
);
4884 newrhs
= build_binary_op (location
,
4885 modifycode
, lhs
, rhs
, 1);
4887 /* The original type of the right hand side is no longer
4889 rhs_origtype
= NULL_TREE
;
4892 if (c_dialect_objc ())
4894 /* Check if we are modifying an Objective-C property reference;
4895 if so, we need to generate setter calls. */
4896 result
= objc_maybe_build_modify_expr (lhs
, newrhs
);
4900 /* Else, do the check that we postponed for Objective-C. */
4901 if (!lvalue_or_else (location
, lhs
, lv_assign
))
4902 return error_mark_node
;
4905 /* Give an error for storing in something that is 'const'. */
4907 if (TYPE_READONLY (lhstype
)
4908 || ((TREE_CODE (lhstype
) == RECORD_TYPE
4909 || TREE_CODE (lhstype
) == UNION_TYPE
)
4910 && C_TYPE_FIELDS_READONLY (lhstype
)))
4912 readonly_error (lhs
, lv_assign
);
4913 return error_mark_node
;
4915 else if (TREE_READONLY (lhs
))
4916 readonly_warning (lhs
, lv_assign
);
4918 /* If storing into a structure or union member,
4919 it has probably been given type `int'.
4920 Compute the type that would go with
4921 the actual amount of storage the member occupies. */
4923 if (TREE_CODE (lhs
) == COMPONENT_REF
4924 && (TREE_CODE (lhstype
) == INTEGER_TYPE
4925 || TREE_CODE (lhstype
) == BOOLEAN_TYPE
4926 || TREE_CODE (lhstype
) == REAL_TYPE
4927 || TREE_CODE (lhstype
) == ENUMERAL_TYPE
))
4928 lhstype
= TREE_TYPE (get_unwidened (lhs
, 0));
4930 /* If storing in a field that is in actuality a short or narrower than one,
4931 we must store in the field in its actual type. */
4933 if (lhstype
!= TREE_TYPE (lhs
))
4935 lhs
= copy_node (lhs
);
4936 TREE_TYPE (lhs
) = lhstype
;
4939 /* Issue -Wc++-compat warnings about an assignment to an enum type
4940 when LHS does not have its original type. This happens for,
4941 e.g., an enum bitfield in a struct. */
4943 && lhs_origtype
!= NULL_TREE
4944 && lhs_origtype
!= lhstype
4945 && TREE_CODE (lhs_origtype
) == ENUMERAL_TYPE
)
4947 tree checktype
= (rhs_origtype
!= NULL_TREE
4950 if (checktype
!= error_mark_node
4951 && TYPE_MAIN_VARIANT (checktype
) != TYPE_MAIN_VARIANT (lhs_origtype
))
4952 warning_at (location
, OPT_Wc___compat
,
4953 "enum conversion in assignment is invalid in C++");
4956 /* Convert new value to destination type. Fold it first, then
4957 restore any excess precision information, for the sake of
4958 conversion warnings. */
4960 npc
= null_pointer_constant_p (newrhs
);
4961 newrhs
= c_fully_fold (newrhs
, false, NULL
);
4962 if (rhs_semantic_type
)
4963 newrhs
= build1 (EXCESS_PRECISION_EXPR
, rhs_semantic_type
, newrhs
);
4964 newrhs
= convert_for_assignment (location
, lhstype
, newrhs
, rhs_origtype
,
4965 ic_assign
, npc
, NULL_TREE
, NULL_TREE
, 0);
4966 if (TREE_CODE (newrhs
) == ERROR_MARK
)
4967 return error_mark_node
;
4969 /* Emit ObjC write barrier, if necessary. */
4970 if (c_dialect_objc () && flag_objc_gc
)
4972 result
= objc_generate_write_barrier (lhs
, modifycode
, newrhs
);
4975 protected_set_expr_location (result
, location
);
4980 /* Scan operands. */
4982 result
= build2 (MODIFY_EXPR
, lhstype
, lhs
, newrhs
);
4983 TREE_SIDE_EFFECTS (result
) = 1;
4984 protected_set_expr_location (result
, location
);
4986 /* If we got the LHS in a different type for storing in,
4987 convert the result back to the nominal type of LHS
4988 so that the value we return always has the same type
4989 as the LHS argument. */
4991 if (olhstype
== TREE_TYPE (result
))
4994 result
= convert_for_assignment (location
, olhstype
, result
, rhs_origtype
,
4995 ic_assign
, false, NULL_TREE
, NULL_TREE
, 0);
4996 protected_set_expr_location (result
, location
);
5000 /* Return whether STRUCT_TYPE has an anonymous field with type TYPE.
5001 This is used to implement -fplan9-extensions. */
5004 find_anonymous_field_with_type (tree struct_type
, tree type
)
5009 gcc_assert (TREE_CODE (struct_type
) == RECORD_TYPE
5010 || TREE_CODE (struct_type
) == UNION_TYPE
);
5012 for (field
= TYPE_FIELDS (struct_type
);
5014 field
= TREE_CHAIN (field
))
5016 if (DECL_NAME (field
) == NULL
5017 && comptypes (type
, TYPE_MAIN_VARIANT (TREE_TYPE (field
))))
5023 else if (DECL_NAME (field
) == NULL
5024 && (TREE_CODE (TREE_TYPE (field
)) == RECORD_TYPE
5025 || TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
)
5026 && find_anonymous_field_with_type (TREE_TYPE (field
), type
))
5036 /* RHS is an expression whose type is pointer to struct. If there is
5037 an anonymous field in RHS with type TYPE, then return a pointer to
5038 that field in RHS. This is used with -fplan9-extensions. This
5039 returns NULL if no conversion could be found. */
5042 convert_to_anonymous_field (location_t location
, tree type
, tree rhs
)
5044 tree rhs_struct_type
, lhs_main_type
;
5045 tree field
, found_field
;
5046 bool found_sub_field
;
5049 gcc_assert (POINTER_TYPE_P (TREE_TYPE (rhs
)));
5050 rhs_struct_type
= TREE_TYPE (TREE_TYPE (rhs
));
5051 gcc_assert (TREE_CODE (rhs_struct_type
) == RECORD_TYPE
5052 || TREE_CODE (rhs_struct_type
) == UNION_TYPE
);
5054 gcc_assert (POINTER_TYPE_P (type
));
5055 lhs_main_type
= TYPE_MAIN_VARIANT (TREE_TYPE (type
));
5057 found_field
= NULL_TREE
;
5058 found_sub_field
= false;
5059 for (field
= TYPE_FIELDS (rhs_struct_type
);
5061 field
= TREE_CHAIN (field
))
5063 if (DECL_NAME (field
) != NULL_TREE
5064 || (TREE_CODE (TREE_TYPE (field
)) != RECORD_TYPE
5065 && TREE_CODE (TREE_TYPE (field
)) != UNION_TYPE
))
5067 if (comptypes (lhs_main_type
, TYPE_MAIN_VARIANT (TREE_TYPE (field
))))
5069 if (found_field
!= NULL_TREE
)
5071 found_field
= field
;
5073 else if (find_anonymous_field_with_type (TREE_TYPE (field
),
5076 if (found_field
!= NULL_TREE
)
5078 found_field
= field
;
5079 found_sub_field
= true;
5083 if (found_field
== NULL_TREE
)
5086 ret
= fold_build3_loc (location
, COMPONENT_REF
, TREE_TYPE (found_field
),
5087 build_fold_indirect_ref (rhs
), found_field
,
5089 ret
= build_fold_addr_expr_loc (location
, ret
);
5091 if (found_sub_field
)
5093 ret
= convert_to_anonymous_field (location
, type
, ret
);
5094 gcc_assert (ret
!= NULL_TREE
);
5100 /* Convert value RHS to type TYPE as preparation for an assignment to
5101 an lvalue of type TYPE. If ORIGTYPE is not NULL_TREE, it is the
5102 original type of RHS; this differs from TREE_TYPE (RHS) for enum
5103 types. NULL_POINTER_CONSTANT says whether RHS was a null pointer
5104 constant before any folding.
5105 The real work of conversion is done by `convert'.
5106 The purpose of this function is to generate error messages
5107 for assignments that are not allowed in C.
5108 ERRTYPE says whether it is argument passing, assignment,
5109 initialization or return.
5111 LOCATION is the location of the RHS.
5112 FUNCTION is a tree for the function being called.
5113 PARMNUM is the number of the argument, for printing in error messages. */
5116 convert_for_assignment (location_t location
, tree type
, tree rhs
,
5117 tree origtype
, enum impl_conv errtype
,
5118 bool null_pointer_constant
, tree fundecl
,
5119 tree function
, int parmnum
)
5121 enum tree_code codel
= TREE_CODE (type
);
5122 tree orig_rhs
= rhs
;
5124 enum tree_code coder
;
5125 tree rname
= NULL_TREE
;
5126 bool objc_ok
= false;
5128 if (errtype
== ic_argpass
)
5131 /* Change pointer to function to the function itself for
5133 if (TREE_CODE (function
) == ADDR_EXPR
5134 && TREE_CODE (TREE_OPERAND (function
, 0)) == FUNCTION_DECL
)
5135 function
= TREE_OPERAND (function
, 0);
5137 /* Handle an ObjC selector specially for diagnostics. */
5138 selector
= objc_message_selector ();
5140 if (selector
&& parmnum
> 2)
5147 /* This macro is used to emit diagnostics to ensure that all format
5148 strings are complete sentences, visible to gettext and checked at
5150 #define WARN_FOR_ASSIGNMENT(LOCATION, OPT, AR, AS, IN, RE) \
5155 if (pedwarn (LOCATION, OPT, AR, parmnum, rname)) \
5156 inform ((fundecl && !DECL_IS_BUILTIN (fundecl)) \
5157 ? DECL_SOURCE_LOCATION (fundecl) : LOCATION, \
5158 "expected %qT but argument is of type %qT", \
5162 pedwarn (LOCATION, OPT, AS); \
5165 pedwarn_init (LOCATION, OPT, IN); \
5168 pedwarn (LOCATION, OPT, RE); \
5171 gcc_unreachable (); \
5175 /* This macro is used to emit diagnostics to ensure that all format
5176 strings are complete sentences, visible to gettext and checked at
5177 compile time. It is the same as WARN_FOR_ASSIGNMENT but with an
5178 extra parameter to enumerate qualifiers. */
5180 #define WARN_FOR_QUALIFIERS(LOCATION, OPT, AR, AS, IN, RE, QUALS) \
5185 if (pedwarn (LOCATION, OPT, AR, parmnum, rname, QUALS)) \
5186 inform ((fundecl && !DECL_IS_BUILTIN (fundecl)) \
5187 ? DECL_SOURCE_LOCATION (fundecl) : LOCATION, \
5188 "expected %qT but argument is of type %qT", \
5192 pedwarn (LOCATION, OPT, AS, QUALS); \
5195 pedwarn (LOCATION, OPT, IN, QUALS); \
5198 pedwarn (LOCATION, OPT, RE, QUALS); \
5201 gcc_unreachable (); \
5205 if (TREE_CODE (rhs
) == EXCESS_PRECISION_EXPR
)
5206 rhs
= TREE_OPERAND (rhs
, 0);
5208 rhstype
= TREE_TYPE (rhs
);
5209 coder
= TREE_CODE (rhstype
);
5211 if (coder
== ERROR_MARK
)
5212 return error_mark_node
;
5214 if (c_dialect_objc ())
5237 objc_ok
= objc_compare_types (type
, rhstype
, parmno
, rname
);
5240 if (warn_cxx_compat
)
5242 tree checktype
= origtype
!= NULL_TREE
? origtype
: rhstype
;
5243 if (checktype
!= error_mark_node
5244 && TREE_CODE (type
) == ENUMERAL_TYPE
5245 && TYPE_MAIN_VARIANT (checktype
) != TYPE_MAIN_VARIANT (type
))
5247 WARN_FOR_ASSIGNMENT (input_location
, OPT_Wc___compat
,
5248 G_("enum conversion when passing argument "
5249 "%d of %qE is invalid in C++"),
5250 G_("enum conversion in assignment is "
5252 G_("enum conversion in initialization is "
5254 G_("enum conversion in return is "
5259 if (TYPE_MAIN_VARIANT (type
) == TYPE_MAIN_VARIANT (rhstype
))
5262 if (coder
== VOID_TYPE
)
5264 /* Except for passing an argument to an unprototyped function,
5265 this is a constraint violation. When passing an argument to
5266 an unprototyped function, it is compile-time undefined;
5267 making it a constraint in that case was rejected in
5269 error_at (location
, "void value not ignored as it ought to be");
5270 return error_mark_node
;
5272 rhs
= require_complete_type (rhs
);
5273 if (rhs
== error_mark_node
)
5274 return error_mark_node
;
5275 /* A non-reference type can convert to a reference. This handles
5276 va_start, va_copy and possibly port built-ins. */
5277 if (codel
== REFERENCE_TYPE
&& coder
!= REFERENCE_TYPE
)
5279 if (!lvalue_p (rhs
))
5281 error_at (location
, "cannot pass rvalue to reference parameter");
5282 return error_mark_node
;
5284 if (!c_mark_addressable (rhs
))
5285 return error_mark_node
;
5286 rhs
= build1 (ADDR_EXPR
, build_pointer_type (TREE_TYPE (rhs
)), rhs
);
5287 SET_EXPR_LOCATION (rhs
, location
);
5289 rhs
= convert_for_assignment (location
, build_pointer_type (TREE_TYPE (type
)),
5290 rhs
, origtype
, errtype
, null_pointer_constant
,
5291 fundecl
, function
, parmnum
);
5292 if (rhs
== error_mark_node
)
5293 return error_mark_node
;
5295 rhs
= build1 (NOP_EXPR
, type
, rhs
);
5296 SET_EXPR_LOCATION (rhs
, location
);
5299 /* Some types can interconvert without explicit casts. */
5300 else if (codel
== VECTOR_TYPE
&& coder
== VECTOR_TYPE
5301 && vector_types_convertible_p (type
, TREE_TYPE (rhs
), true))
5302 return convert (type
, rhs
);
5303 /* Arithmetic types all interconvert, and enum is treated like int. */
5304 else if ((codel
== INTEGER_TYPE
|| codel
== REAL_TYPE
5305 || codel
== FIXED_POINT_TYPE
5306 || codel
== ENUMERAL_TYPE
|| codel
== COMPLEX_TYPE
5307 || codel
== BOOLEAN_TYPE
)
5308 && (coder
== INTEGER_TYPE
|| coder
== REAL_TYPE
5309 || coder
== FIXED_POINT_TYPE
5310 || coder
== ENUMERAL_TYPE
|| coder
== COMPLEX_TYPE
5311 || coder
== BOOLEAN_TYPE
))
5314 bool save
= in_late_binary_op
;
5315 if (codel
== BOOLEAN_TYPE
|| codel
== COMPLEX_TYPE
)
5316 in_late_binary_op
= true;
5317 ret
= convert_and_check (type
, orig_rhs
);
5318 if (codel
== BOOLEAN_TYPE
|| codel
== COMPLEX_TYPE
)
5319 in_late_binary_op
= save
;
5323 /* Aggregates in different TUs might need conversion. */
5324 if ((codel
== RECORD_TYPE
|| codel
== UNION_TYPE
)
5326 && comptypes (type
, rhstype
))
5327 return convert_and_check (type
, rhs
);
5329 /* Conversion to a transparent union or record from its member types.
5330 This applies only to function arguments. */
5331 if (((codel
== UNION_TYPE
|| codel
== RECORD_TYPE
)
5332 && TYPE_TRANSPARENT_AGGR (type
))
5333 && errtype
== ic_argpass
)
5335 tree memb
, marginal_memb
= NULL_TREE
;
5337 for (memb
= TYPE_FIELDS (type
); memb
; memb
= DECL_CHAIN (memb
))
5339 tree memb_type
= TREE_TYPE (memb
);
5341 if (comptypes (TYPE_MAIN_VARIANT (memb_type
),
5342 TYPE_MAIN_VARIANT (rhstype
)))
5345 if (TREE_CODE (memb_type
) != POINTER_TYPE
)
5348 if (coder
== POINTER_TYPE
)
5350 tree ttl
= TREE_TYPE (memb_type
);
5351 tree ttr
= TREE_TYPE (rhstype
);
5353 /* Any non-function converts to a [const][volatile] void *
5354 and vice versa; otherwise, targets must be the same.
5355 Meanwhile, the lhs target must have all the qualifiers of
5357 if (VOID_TYPE_P (ttl
) || VOID_TYPE_P (ttr
)
5358 || comp_target_types (location
, memb_type
, rhstype
))
5360 /* If this type won't generate any warnings, use it. */
5361 if (TYPE_QUALS (ttl
) == TYPE_QUALS (ttr
)
5362 || ((TREE_CODE (ttr
) == FUNCTION_TYPE
5363 && TREE_CODE (ttl
) == FUNCTION_TYPE
)
5364 ? ((TYPE_QUALS (ttl
) | TYPE_QUALS (ttr
))
5365 == TYPE_QUALS (ttr
))
5366 : ((TYPE_QUALS (ttl
) | TYPE_QUALS (ttr
))
5367 == TYPE_QUALS (ttl
))))
5370 /* Keep looking for a better type, but remember this one. */
5372 marginal_memb
= memb
;
5376 /* Can convert integer zero to any pointer type. */
5377 if (null_pointer_constant
)
5379 rhs
= null_pointer_node
;
5384 if (memb
|| marginal_memb
)
5388 /* We have only a marginally acceptable member type;
5389 it needs a warning. */
5390 tree ttl
= TREE_TYPE (TREE_TYPE (marginal_memb
));
5391 tree ttr
= TREE_TYPE (rhstype
);
5393 /* Const and volatile mean something different for function
5394 types, so the usual warnings are not appropriate. */
5395 if (TREE_CODE (ttr
) == FUNCTION_TYPE
5396 && TREE_CODE (ttl
) == FUNCTION_TYPE
)
5398 /* Because const and volatile on functions are
5399 restrictions that say the function will not do
5400 certain things, it is okay to use a const or volatile
5401 function where an ordinary one is wanted, but not
5403 if (TYPE_QUALS_NO_ADDR_SPACE (ttl
)
5404 & ~TYPE_QUALS_NO_ADDR_SPACE (ttr
))
5405 WARN_FOR_QUALIFIERS (location
, 0,
5406 G_("passing argument %d of %qE "
5407 "makes %q#v qualified function "
5408 "pointer from unqualified"),
5409 G_("assignment makes %q#v qualified "
5410 "function pointer from "
5412 G_("initialization makes %q#v qualified "
5413 "function pointer from "
5415 G_("return makes %q#v qualified function "
5416 "pointer from unqualified"),
5417 TYPE_QUALS (ttl
) & ~TYPE_QUALS (ttr
));
5419 else if (TYPE_QUALS_NO_ADDR_SPACE (ttr
)
5420 & ~TYPE_QUALS_NO_ADDR_SPACE (ttl
))
5421 WARN_FOR_QUALIFIERS (location
, 0,
5422 G_("passing argument %d of %qE discards "
5423 "%qv qualifier from pointer target type"),
5424 G_("assignment discards %qv qualifier "
5425 "from pointer target type"),
5426 G_("initialization discards %qv qualifier "
5427 "from pointer target type"),
5428 G_("return discards %qv qualifier from "
5429 "pointer target type"),
5430 TYPE_QUALS (ttr
) & ~TYPE_QUALS (ttl
));
5432 memb
= marginal_memb
;
5435 if (!fundecl
|| !DECL_IN_SYSTEM_HEADER (fundecl
))
5436 pedwarn (location
, OPT_Wpedantic
,
5437 "ISO C prohibits argument conversion to union type");
5439 rhs
= fold_convert_loc (location
, TREE_TYPE (memb
), rhs
);
5440 return build_constructor_single (type
, memb
, rhs
);
5444 /* Conversions among pointers */
5445 else if ((codel
== POINTER_TYPE
|| codel
== REFERENCE_TYPE
)
5446 && (coder
== codel
))
5448 tree ttl
= TREE_TYPE (type
);
5449 tree ttr
= TREE_TYPE (rhstype
);
5452 bool is_opaque_pointer
;
5453 int target_cmp
= 0; /* Cache comp_target_types () result. */
5457 if (TREE_CODE (mvl
) != ARRAY_TYPE
)
5458 mvl
= TYPE_MAIN_VARIANT (mvl
);
5459 if (TREE_CODE (mvr
) != ARRAY_TYPE
)
5460 mvr
= TYPE_MAIN_VARIANT (mvr
);
5461 /* Opaque pointers are treated like void pointers. */
5462 is_opaque_pointer
= vector_targets_convertible_p (ttl
, ttr
);
5464 /* The Plan 9 compiler permits a pointer to a struct to be
5465 automatically converted into a pointer to an anonymous field
5466 within the struct. */
5467 if (flag_plan9_extensions
5468 && (TREE_CODE (mvl
) == RECORD_TYPE
|| TREE_CODE(mvl
) == UNION_TYPE
)
5469 && (TREE_CODE (mvr
) == RECORD_TYPE
|| TREE_CODE(mvr
) == UNION_TYPE
)
5472 tree new_rhs
= convert_to_anonymous_field (location
, type
, rhs
);
5473 if (new_rhs
!= NULL_TREE
)
5476 rhstype
= TREE_TYPE (rhs
);
5477 coder
= TREE_CODE (rhstype
);
5478 ttr
= TREE_TYPE (rhstype
);
5479 mvr
= TYPE_MAIN_VARIANT (ttr
);
5483 /* C++ does not allow the implicit conversion void* -> T*. However,
5484 for the purpose of reducing the number of false positives, we
5485 tolerate the special case of
5489 where NULL is typically defined in C to be '(void *) 0'. */
5490 if (VOID_TYPE_P (ttr
) && rhs
!= null_pointer_node
&& !VOID_TYPE_P (ttl
))
5491 warning_at (location
, OPT_Wc___compat
,
5492 "request for implicit conversion "
5493 "from %qT to %qT not permitted in C++", rhstype
, type
);
5495 /* See if the pointers point to incompatible address spaces. */
5496 asl
= TYPE_ADDR_SPACE (ttl
);
5497 asr
= TYPE_ADDR_SPACE (ttr
);
5498 if (!null_pointer_constant_p (rhs
)
5499 && asr
!= asl
&& !targetm
.addr_space
.subset_p (asr
, asl
))
5504 error_at (location
, "passing argument %d of %qE from pointer to "
5505 "non-enclosed address space", parmnum
, rname
);
5508 error_at (location
, "assignment from pointer to "
5509 "non-enclosed address space");
5512 error_at (location
, "initialization from pointer to "
5513 "non-enclosed address space");
5516 error_at (location
, "return from pointer to "
5517 "non-enclosed address space");
5522 return error_mark_node
;
5525 /* Check if the right-hand side has a format attribute but the
5526 left-hand side doesn't. */
5527 if (warn_suggest_attribute_format
5528 && check_missing_format_attribute (type
, rhstype
))
5533 warning_at (location
, OPT_Wsuggest_attribute_format
,
5534 "argument %d of %qE might be "
5535 "a candidate for a format attribute",
5539 warning_at (location
, OPT_Wsuggest_attribute_format
,
5540 "assignment left-hand side might be "
5541 "a candidate for a format attribute");
5544 warning_at (location
, OPT_Wsuggest_attribute_format
,
5545 "initialization left-hand side might be "
5546 "a candidate for a format attribute");
5549 warning_at (location
, OPT_Wsuggest_attribute_format
,
5550 "return type might be "
5551 "a candidate for a format attribute");
5558 /* Any non-function converts to a [const][volatile] void *
5559 and vice versa; otherwise, targets must be the same.
5560 Meanwhile, the lhs target must have all the qualifiers of the rhs. */
5561 if (VOID_TYPE_P (ttl
) || VOID_TYPE_P (ttr
)
5562 || (target_cmp
= comp_target_types (location
, type
, rhstype
))
5563 || is_opaque_pointer
5564 || ((c_common_unsigned_type (mvl
)
5565 == c_common_unsigned_type (mvr
))
5566 && c_common_signed_type (mvl
)
5567 == c_common_signed_type (mvr
)))
5570 && ((VOID_TYPE_P (ttl
) && TREE_CODE (ttr
) == FUNCTION_TYPE
)
5573 && !null_pointer_constant
5574 && TREE_CODE (ttl
) == FUNCTION_TYPE
)))
5575 WARN_FOR_ASSIGNMENT (location
, OPT_Wpedantic
,
5576 G_("ISO C forbids passing argument %d of "
5577 "%qE between function pointer "
5579 G_("ISO C forbids assignment between "
5580 "function pointer and %<void *%>"),
5581 G_("ISO C forbids initialization between "
5582 "function pointer and %<void *%>"),
5583 G_("ISO C forbids return between function "
5584 "pointer and %<void *%>"));
5585 /* Const and volatile mean something different for function types,
5586 so the usual warnings are not appropriate. */
5587 else if (TREE_CODE (ttr
) != FUNCTION_TYPE
5588 && TREE_CODE (ttl
) != FUNCTION_TYPE
)
5590 if (TYPE_QUALS_NO_ADDR_SPACE (ttr
)
5591 & ~TYPE_QUALS_NO_ADDR_SPACE (ttl
))
5593 WARN_FOR_QUALIFIERS (location
, 0,
5594 G_("passing argument %d of %qE discards "
5595 "%qv qualifier from pointer target type"),
5596 G_("assignment discards %qv qualifier "
5597 "from pointer target type"),
5598 G_("initialization discards %qv qualifier "
5599 "from pointer target type"),
5600 G_("return discards %qv qualifier from "
5601 "pointer target type"),
5602 TYPE_QUALS (ttr
) & ~TYPE_QUALS (ttl
));
5604 /* If this is not a case of ignoring a mismatch in signedness,
5606 else if (VOID_TYPE_P (ttl
) || VOID_TYPE_P (ttr
)
5609 /* If there is a mismatch, do warn. */
5610 else if (warn_pointer_sign
)
5611 WARN_FOR_ASSIGNMENT (location
, OPT_Wpointer_sign
,
5612 G_("pointer targets in passing argument "
5613 "%d of %qE differ in signedness"),
5614 G_("pointer targets in assignment "
5615 "differ in signedness"),
5616 G_("pointer targets in initialization "
5617 "differ in signedness"),
5618 G_("pointer targets in return differ "
5621 else if (TREE_CODE (ttl
) == FUNCTION_TYPE
5622 && TREE_CODE (ttr
) == FUNCTION_TYPE
)
5624 /* Because const and volatile on functions are restrictions
5625 that say the function will not do certain things,
5626 it is okay to use a const or volatile function
5627 where an ordinary one is wanted, but not vice-versa. */
5628 if (TYPE_QUALS_NO_ADDR_SPACE (ttl
)
5629 & ~TYPE_QUALS_NO_ADDR_SPACE (ttr
))
5630 WARN_FOR_QUALIFIERS (location
, 0,
5631 G_("passing argument %d of %qE makes "
5632 "%q#v qualified function pointer "
5633 "from unqualified"),
5634 G_("assignment makes %q#v qualified function "
5635 "pointer from unqualified"),
5636 G_("initialization makes %q#v qualified "
5637 "function pointer from unqualified"),
5638 G_("return makes %q#v qualified function "
5639 "pointer from unqualified"),
5640 TYPE_QUALS (ttl
) & ~TYPE_QUALS (ttr
));
5644 /* Avoid warning about the volatile ObjC EH puts on decls. */
5646 WARN_FOR_ASSIGNMENT (location
, 0,
5647 G_("passing argument %d of %qE from "
5648 "incompatible pointer type"),
5649 G_("assignment from incompatible pointer type"),
5650 G_("initialization from incompatible "
5652 G_("return from incompatible pointer type"));
5654 return convert (type
, rhs
);
5656 else if (codel
== POINTER_TYPE
&& coder
== ARRAY_TYPE
)
5658 /* ??? This should not be an error when inlining calls to
5659 unprototyped functions. */
5660 error_at (location
, "invalid use of non-lvalue array");
5661 return error_mark_node
;
5663 else if (codel
== POINTER_TYPE
&& coder
== INTEGER_TYPE
)
5665 /* An explicit constant 0 can convert to a pointer,
5666 or one that results from arithmetic, even including
5667 a cast to integer type. */
5668 if (!null_pointer_constant
)
5669 WARN_FOR_ASSIGNMENT (location
, 0,
5670 G_("passing argument %d of %qE makes "
5671 "pointer from integer without a cast"),
5672 G_("assignment makes pointer from integer "
5674 G_("initialization makes pointer from "
5675 "integer without a cast"),
5676 G_("return makes pointer from integer "
5679 return convert (type
, rhs
);
5681 else if (codel
== INTEGER_TYPE
&& coder
== POINTER_TYPE
)
5683 WARN_FOR_ASSIGNMENT (location
, 0,
5684 G_("passing argument %d of %qE makes integer "
5685 "from pointer without a cast"),
5686 G_("assignment makes integer from pointer "
5688 G_("initialization makes integer from pointer "
5690 G_("return makes integer from pointer "
5692 return convert (type
, rhs
);
5694 else if (codel
== BOOLEAN_TYPE
&& coder
== POINTER_TYPE
)
5697 bool save
= in_late_binary_op
;
5698 in_late_binary_op
= true;
5699 ret
= convert (type
, rhs
);
5700 in_late_binary_op
= save
;
5707 error_at (location
, "incompatible type for argument %d of %qE", parmnum
, rname
);
5708 inform ((fundecl
&& !DECL_IS_BUILTIN (fundecl
))
5709 ? DECL_SOURCE_LOCATION (fundecl
) : input_location
,
5710 "expected %qT but argument is of type %qT", type
, rhstype
);
5713 error_at (location
, "incompatible types when assigning to type %qT from "
5714 "type %qT", type
, rhstype
);
5718 "incompatible types when initializing type %qT using type %qT",
5723 "incompatible types when returning type %qT but %qT was "
5724 "expected", rhstype
, type
);
5730 return error_mark_node
;
5733 /* If VALUE is a compound expr all of whose expressions are constant, then
5734 return its value. Otherwise, return error_mark_node.
5736 This is for handling COMPOUND_EXPRs as initializer elements
5737 which is allowed with a warning when -pedantic is specified. */
5740 valid_compound_expr_initializer (tree value
, tree endtype
)
5742 if (TREE_CODE (value
) == COMPOUND_EXPR
)
5744 if (valid_compound_expr_initializer (TREE_OPERAND (value
, 0), endtype
)
5746 return error_mark_node
;
5747 return valid_compound_expr_initializer (TREE_OPERAND (value
, 1),
5750 else if (!initializer_constant_valid_p (value
, endtype
))
5751 return error_mark_node
;
5756 /* Perform appropriate conversions on the initial value of a variable,
5757 store it in the declaration DECL,
5758 and print any error messages that are appropriate.
5759 If ORIGTYPE is not NULL_TREE, it is the original type of INIT.
5760 If the init is invalid, store an ERROR_MARK.
5762 INIT_LOC is the location of the initial value. */
5765 store_init_value (location_t init_loc
, tree decl
, tree init
, tree origtype
)
5770 /* If variable's type was invalidly declared, just ignore it. */
5772 type
= TREE_TYPE (decl
);
5773 if (TREE_CODE (type
) == ERROR_MARK
)
5776 /* Digest the specified initializer into an expression. */
5779 npc
= null_pointer_constant_p (init
);
5780 value
= digest_init (init_loc
, type
, init
, origtype
, npc
,
5781 true, TREE_STATIC (decl
));
5783 /* Store the expression if valid; else report error. */
5785 if (!in_system_header
5786 && AGGREGATE_TYPE_P (TREE_TYPE (decl
)) && !TREE_STATIC (decl
))
5787 warning (OPT_Wtraditional
, "traditional C rejects automatic "
5788 "aggregate initialization");
5790 DECL_INITIAL (decl
) = value
;
5792 /* ANSI wants warnings about out-of-range constant initializers. */
5793 STRIP_TYPE_NOPS (value
);
5794 if (TREE_STATIC (decl
))
5795 constant_expression_warning (value
);
5797 /* Check if we need to set array size from compound literal size. */
5798 if (TREE_CODE (type
) == ARRAY_TYPE
5799 && TYPE_DOMAIN (type
) == 0
5800 && value
!= error_mark_node
)
5802 tree inside_init
= init
;
5804 STRIP_TYPE_NOPS (inside_init
);
5805 inside_init
= fold (inside_init
);
5807 if (TREE_CODE (inside_init
) == COMPOUND_LITERAL_EXPR
)
5809 tree cldecl
= COMPOUND_LITERAL_EXPR_DECL (inside_init
);
5811 if (TYPE_DOMAIN (TREE_TYPE (cldecl
)))
5813 /* For int foo[] = (int [3]){1}; we need to set array size
5814 now since later on array initializer will be just the
5815 brace enclosed list of the compound literal. */
5816 tree etype
= strip_array_types (TREE_TYPE (decl
));
5817 type
= build_distinct_type_copy (TYPE_MAIN_VARIANT (type
));
5818 TYPE_DOMAIN (type
) = TYPE_DOMAIN (TREE_TYPE (cldecl
));
5820 layout_decl (cldecl
, 0);
5822 = c_build_qualified_type (type
, TYPE_QUALS (etype
));
5828 /* Methods for storing and printing names for error messages. */
5830 /* Implement a spelling stack that allows components of a name to be pushed
5831 and popped. Each element on the stack is this structure. */
5838 unsigned HOST_WIDE_INT i
;
5843 #define SPELLING_STRING 1
5844 #define SPELLING_MEMBER 2
5845 #define SPELLING_BOUNDS 3
5847 static struct spelling
*spelling
; /* Next stack element (unused). */
5848 static struct spelling
*spelling_base
; /* Spelling stack base. */
5849 static int spelling_size
; /* Size of the spelling stack. */
5851 /* Macros to save and restore the spelling stack around push_... functions.
5852 Alternative to SAVE_SPELLING_STACK. */
5854 #define SPELLING_DEPTH() (spelling - spelling_base)
5855 #define RESTORE_SPELLING_DEPTH(DEPTH) (spelling = spelling_base + (DEPTH))
5857 /* Push an element on the spelling stack with type KIND and assign VALUE
5860 #define PUSH_SPELLING(KIND, VALUE, MEMBER) \
5862 int depth = SPELLING_DEPTH (); \
5864 if (depth >= spelling_size) \
5866 spelling_size += 10; \
5867 spelling_base = XRESIZEVEC (struct spelling, spelling_base, \
5869 RESTORE_SPELLING_DEPTH (depth); \
5872 spelling->kind = (KIND); \
5873 spelling->MEMBER = (VALUE); \
5877 /* Push STRING on the stack. Printed literally. */
5880 push_string (const char *string
)
5882 PUSH_SPELLING (SPELLING_STRING
, string
, u
.s
);
5885 /* Push a member name on the stack. Printed as '.' STRING. */
5888 push_member_name (tree decl
)
5890 const char *const string
5892 ? identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl
)))
5893 : _("<anonymous>"));
5894 PUSH_SPELLING (SPELLING_MEMBER
, string
, u
.s
);
5897 /* Push an array bounds on the stack. Printed as [BOUNDS]. */
5900 push_array_bounds (unsigned HOST_WIDE_INT bounds
)
5902 PUSH_SPELLING (SPELLING_BOUNDS
, bounds
, u
.i
);
5905 /* Compute the maximum size in bytes of the printed spelling. */
5908 spelling_length (void)
5913 for (p
= spelling_base
; p
< spelling
; p
++)
5915 if (p
->kind
== SPELLING_BOUNDS
)
5918 size
+= strlen (p
->u
.s
) + 1;
5924 /* Print the spelling to BUFFER and return it. */
5927 print_spelling (char *buffer
)
5932 for (p
= spelling_base
; p
< spelling
; p
++)
5933 if (p
->kind
== SPELLING_BOUNDS
)
5935 sprintf (d
, "[" HOST_WIDE_INT_PRINT_UNSIGNED
"]", p
->u
.i
);
5941 if (p
->kind
== SPELLING_MEMBER
)
5943 for (s
= p
->u
.s
; (*d
= *s
++); d
++)
5950 /* Issue an error message for a bad initializer component.
5951 GMSGID identifies the message.
5952 The component name is taken from the spelling stack. */
5955 error_init (const char *gmsgid
)
5959 /* The gmsgid may be a format string with %< and %>. */
5961 ofwhat
= print_spelling ((char *) alloca (spelling_length () + 1));
5963 error ("(near initialization for %qs)", ofwhat
);
5966 /* Issue a pedantic warning for a bad initializer component. OPT is
5967 the option OPT_* (from options.h) controlling this warning or 0 if
5968 it is unconditionally given. GMSGID identifies the message. The
5969 component name is taken from the spelling stack. */
5972 pedwarn_init (location_t location
, int opt
, const char *gmsgid
)
5976 /* The gmsgid may be a format string with %< and %>. */
5977 pedwarn (location
, opt
, gmsgid
);
5978 ofwhat
= print_spelling ((char *) alloca (spelling_length () + 1));
5980 pedwarn (location
, opt
, "(near initialization for %qs)", ofwhat
);
5983 /* Issue a warning for a bad initializer component.
5985 OPT is the OPT_W* value corresponding to the warning option that
5986 controls this warning. GMSGID identifies the message. The
5987 component name is taken from the spelling stack. */
5990 warning_init (int opt
, const char *gmsgid
)
5994 /* The gmsgid may be a format string with %< and %>. */
5995 warning (opt
, gmsgid
);
5996 ofwhat
= print_spelling ((char *) alloca (spelling_length () + 1));
5998 warning (opt
, "(near initialization for %qs)", ofwhat
);
6001 /* If TYPE is an array type and EXPR is a parenthesized string
6002 constant, warn if pedantic that EXPR is being used to initialize an
6003 object of type TYPE. */
6006 maybe_warn_string_init (tree type
, struct c_expr expr
)
6009 && TREE_CODE (type
) == ARRAY_TYPE
6010 && TREE_CODE (expr
.value
) == STRING_CST
6011 && expr
.original_code
!= STRING_CST
)
6012 pedwarn_init (input_location
, OPT_Wpedantic
,
6013 "array initialized from parenthesized string constant");
6016 /* Digest the parser output INIT as an initializer for type TYPE.
6017 Return a C expression of type TYPE to represent the initial value.
6019 If ORIGTYPE is not NULL_TREE, it is the original type of INIT.
6021 NULL_POINTER_CONSTANT is true if INIT is a null pointer constant.
6023 If INIT is a string constant, STRICT_STRING is true if it is
6024 unparenthesized or we should not warn here for it being parenthesized.
6025 For other types of INIT, STRICT_STRING is not used.
6027 INIT_LOC is the location of the INIT.
6029 REQUIRE_CONSTANT requests an error if non-constant initializers or
6030 elements are seen. */
6033 digest_init (location_t init_loc
, tree type
, tree init
, tree origtype
,
6034 bool null_pointer_constant
, bool strict_string
,
6035 int require_constant
)
6037 enum tree_code code
= TREE_CODE (type
);
6038 tree inside_init
= init
;
6039 tree semantic_type
= NULL_TREE
;
6040 bool maybe_const
= true;
6042 if (type
== error_mark_node
6044 || init
== error_mark_node
6045 || TREE_TYPE (init
) == error_mark_node
)
6046 return error_mark_node
;
6048 STRIP_TYPE_NOPS (inside_init
);
6050 if (TREE_CODE (inside_init
) == EXCESS_PRECISION_EXPR
)
6052 semantic_type
= TREE_TYPE (inside_init
);
6053 inside_init
= TREE_OPERAND (inside_init
, 0);
6055 inside_init
= c_fully_fold (inside_init
, require_constant
, &maybe_const
);
6056 inside_init
= decl_constant_value_for_optimization (inside_init
);
6058 /* Initialization of an array of chars from a string constant
6059 optionally enclosed in braces. */
6061 if (code
== ARRAY_TYPE
&& inside_init
6062 && TREE_CODE (inside_init
) == STRING_CST
)
6064 tree typ1
= TYPE_MAIN_VARIANT (TREE_TYPE (type
));
6065 /* Note that an array could be both an array of character type
6066 and an array of wchar_t if wchar_t is signed char or unsigned
6068 bool char_array
= (typ1
== char_type_node
6069 || typ1
== signed_char_type_node
6070 || typ1
== unsigned_char_type_node
);
6071 bool wchar_array
= !!comptypes (typ1
, wchar_type_node
);
6072 bool char16_array
= !!comptypes (typ1
, char16_type_node
);
6073 bool char32_array
= !!comptypes (typ1
, char32_type_node
);
6075 if (char_array
|| wchar_array
|| char16_array
|| char32_array
)
6078 tree typ2
= TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init
)));
6079 expr
.value
= inside_init
;
6080 expr
.original_code
= (strict_string
? STRING_CST
: ERROR_MARK
);
6081 expr
.original_type
= NULL
;
6082 maybe_warn_string_init (type
, expr
);
6084 if (TYPE_DOMAIN (type
) && !TYPE_MAX_VALUE (TYPE_DOMAIN (type
)))
6085 pedwarn_init (init_loc
, OPT_Wpedantic
,
6086 "initialization of a flexible array member");
6088 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init
)),
6089 TYPE_MAIN_VARIANT (type
)))
6094 if (typ2
!= char_type_node
)
6096 error_init ("char-array initialized from wide string");
6097 return error_mark_node
;
6102 if (typ2
== char_type_node
)
6104 error_init ("wide character array initialized from non-wide "
6106 return error_mark_node
;
6108 else if (!comptypes(typ1
, typ2
))
6110 error_init ("wide character array initialized from "
6111 "incompatible wide string");
6112 return error_mark_node
;
6116 TREE_TYPE (inside_init
) = type
;
6117 if (TYPE_DOMAIN (type
) != 0
6118 && TYPE_SIZE (type
) != 0
6119 && TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
6121 unsigned HOST_WIDE_INT len
= TREE_STRING_LENGTH (inside_init
);
6123 /* Subtract the size of a single (possibly wide) character
6124 because it's ok to ignore the terminating null char
6125 that is counted in the length of the constant. */
6126 if (0 > compare_tree_int (TYPE_SIZE_UNIT (type
),
6128 - (TYPE_PRECISION (typ1
)
6130 pedwarn_init (init_loc
, 0,
6131 ("initializer-string for array of chars "
6133 else if (warn_cxx_compat
6134 && 0 > compare_tree_int (TYPE_SIZE_UNIT (type
), len
))
6135 warning_at (init_loc
, OPT_Wc___compat
,
6136 ("initializer-string for array chars "
6137 "is too long for C++"));
6142 else if (INTEGRAL_TYPE_P (typ1
))
6144 error_init ("array of inappropriate type initialized "
6145 "from string constant");
6146 return error_mark_node
;
6150 /* Build a VECTOR_CST from a *constant* vector constructor. If the
6151 vector constructor is not constant (e.g. {1,2,3,foo()}) then punt
6152 below and handle as a constructor. */
6153 if (code
== VECTOR_TYPE
6154 && TREE_CODE (TREE_TYPE (inside_init
)) == VECTOR_TYPE
6155 && vector_types_convertible_p (TREE_TYPE (inside_init
), type
, true)
6156 && TREE_CONSTANT (inside_init
))
6158 if (TREE_CODE (inside_init
) == VECTOR_CST
6159 && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init
)),
6160 TYPE_MAIN_VARIANT (type
)))
6163 if (TREE_CODE (inside_init
) == CONSTRUCTOR
)
6165 unsigned HOST_WIDE_INT ix
;
6167 bool constant_p
= true;
6169 /* Iterate through elements and check if all constructor
6170 elements are *_CSTs. */
6171 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (inside_init
), ix
, value
)
6172 if (!CONSTANT_CLASS_P (value
))
6179 return build_vector_from_ctor (type
,
6180 CONSTRUCTOR_ELTS (inside_init
));
6184 if (warn_sequence_point
)
6185 verify_sequence_points (inside_init
);
6187 /* Any type can be initialized
6188 from an expression of the same type, optionally with braces. */
6190 if (inside_init
&& TREE_TYPE (inside_init
) != 0
6191 && (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init
)),
6192 TYPE_MAIN_VARIANT (type
))
6193 || (code
== ARRAY_TYPE
6194 && comptypes (TREE_TYPE (inside_init
), type
))
6195 || (code
== VECTOR_TYPE
6196 && comptypes (TREE_TYPE (inside_init
), type
))
6197 || (code
== POINTER_TYPE
6198 && TREE_CODE (TREE_TYPE (inside_init
)) == ARRAY_TYPE
6199 && comptypes (TREE_TYPE (TREE_TYPE (inside_init
)),
6200 TREE_TYPE (type
)))))
6202 if (code
== POINTER_TYPE
)
6204 if (TREE_CODE (TREE_TYPE (inside_init
)) == ARRAY_TYPE
)
6206 if (TREE_CODE (inside_init
) == STRING_CST
6207 || TREE_CODE (inside_init
) == COMPOUND_LITERAL_EXPR
)
6208 inside_init
= array_to_pointer_conversion
6209 (init_loc
, inside_init
);
6212 error_init ("invalid use of non-lvalue array");
6213 return error_mark_node
;
6218 if (code
== VECTOR_TYPE
)
6219 /* Although the types are compatible, we may require a
6221 inside_init
= convert (type
, inside_init
);
6223 if (require_constant
6224 && (code
== VECTOR_TYPE
|| !flag_isoc99
)
6225 && TREE_CODE (inside_init
) == COMPOUND_LITERAL_EXPR
)
6227 /* As an extension, allow initializing objects with static storage
6228 duration with compound literals (which are then treated just as
6229 the brace enclosed list they contain). Also allow this for
6230 vectors, as we can only assign them with compound literals. */
6231 tree decl
= COMPOUND_LITERAL_EXPR_DECL (inside_init
);
6232 inside_init
= DECL_INITIAL (decl
);
6235 if (code
== ARRAY_TYPE
&& TREE_CODE (inside_init
) != STRING_CST
6236 && TREE_CODE (inside_init
) != CONSTRUCTOR
)
6238 error_init ("array initialized from non-constant array expression");
6239 return error_mark_node
;
6242 /* Compound expressions can only occur here if -Wpedantic or
6243 -pedantic-errors is specified. In the later case, we always want
6244 an error. In the former case, we simply want a warning. */
6245 if (require_constant
&& pedantic
6246 && TREE_CODE (inside_init
) == COMPOUND_EXPR
)
6249 = valid_compound_expr_initializer (inside_init
,
6250 TREE_TYPE (inside_init
));
6251 if (inside_init
== error_mark_node
)
6252 error_init ("initializer element is not constant");
6254 pedwarn_init (init_loc
, OPT_Wpedantic
,
6255 "initializer element is not constant");
6256 if (flag_pedantic_errors
)
6257 inside_init
= error_mark_node
;
6259 else if (require_constant
6260 && !initializer_constant_valid_p (inside_init
,
6261 TREE_TYPE (inside_init
)))
6263 error_init ("initializer element is not constant");
6264 inside_init
= error_mark_node
;
6266 else if (require_constant
&& !maybe_const
)
6267 pedwarn_init (init_loc
, 0,
6268 "initializer element is not a constant expression");
6270 /* Added to enable additional -Wsuggest-attribute=format warnings. */
6271 if (TREE_CODE (TREE_TYPE (inside_init
)) == POINTER_TYPE
)
6272 inside_init
= convert_for_assignment (init_loc
, type
, inside_init
,
6274 ic_init
, null_pointer_constant
,
6275 NULL_TREE
, NULL_TREE
, 0);
6279 /* Handle scalar types, including conversions. */
6281 if (code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
6282 || code
== POINTER_TYPE
|| code
== ENUMERAL_TYPE
|| code
== BOOLEAN_TYPE
6283 || code
== COMPLEX_TYPE
|| code
== VECTOR_TYPE
)
6285 if (TREE_CODE (TREE_TYPE (init
)) == ARRAY_TYPE
6286 && (TREE_CODE (init
) == STRING_CST
6287 || TREE_CODE (init
) == COMPOUND_LITERAL_EXPR
))
6288 inside_init
= init
= array_to_pointer_conversion (init_loc
, init
);
6290 inside_init
= build1 (EXCESS_PRECISION_EXPR
, semantic_type
,
6293 = convert_for_assignment (init_loc
, type
, inside_init
, origtype
,
6294 ic_init
, null_pointer_constant
,
6295 NULL_TREE
, NULL_TREE
, 0);
6297 /* Check to see if we have already given an error message. */
6298 if (inside_init
== error_mark_node
)
6300 else if (require_constant
&& !TREE_CONSTANT (inside_init
))
6302 error_init ("initializer element is not constant");
6303 inside_init
= error_mark_node
;
6305 else if (require_constant
6306 && !initializer_constant_valid_p (inside_init
,
6307 TREE_TYPE (inside_init
)))
6309 error_init ("initializer element is not computable at load time");
6310 inside_init
= error_mark_node
;
6312 else if (require_constant
&& !maybe_const
)
6313 pedwarn_init (init_loc
, 0,
6314 "initializer element is not a constant expression");
6319 /* Come here only for records and arrays. */
6321 if (COMPLETE_TYPE_P (type
) && TREE_CODE (TYPE_SIZE (type
)) != INTEGER_CST
)
6323 error_init ("variable-sized object may not be initialized");
6324 return error_mark_node
;
6327 error_init ("invalid initializer");
6328 return error_mark_node
;
6331 /* Handle initializers that use braces. */
6333 /* Type of object we are accumulating a constructor for.
6334 This type is always a RECORD_TYPE, UNION_TYPE or ARRAY_TYPE. */
6335 static tree constructor_type
;
6337 /* For a RECORD_TYPE or UNION_TYPE, this is the chain of fields
6339 static tree constructor_fields
;
6341 /* For an ARRAY_TYPE, this is the specified index
6342 at which to store the next element we get. */
6343 static tree constructor_index
;
6345 /* For an ARRAY_TYPE, this is the maximum index. */
6346 static tree constructor_max_index
;
6348 /* For a RECORD_TYPE, this is the first field not yet written out. */
6349 static tree constructor_unfilled_fields
;
6351 /* For an ARRAY_TYPE, this is the index of the first element
6352 not yet written out. */
6353 static tree constructor_unfilled_index
;
6355 /* In a RECORD_TYPE, the byte index of the next consecutive field.
6356 This is so we can generate gaps between fields, when appropriate. */
6357 static tree constructor_bit_index
;
6359 /* If we are saving up the elements rather than allocating them,
6360 this is the list of elements so far (in reverse order,
6361 most recent first). */
6362 static vec
<constructor_elt
, va_gc
> *constructor_elements
;
6364 /* 1 if constructor should be incrementally stored into a constructor chain,
6365 0 if all the elements should be kept in AVL tree. */
6366 static int constructor_incremental
;
6368 /* 1 if so far this constructor's elements are all compile-time constants. */
6369 static int constructor_constant
;
6371 /* 1 if so far this constructor's elements are all valid address constants. */
6372 static int constructor_simple
;
6374 /* 1 if this constructor has an element that cannot be part of a
6375 constant expression. */
6376 static int constructor_nonconst
;
6378 /* 1 if this constructor is erroneous so far. */
6379 static int constructor_erroneous
;
6381 /* Structure for managing pending initializer elements, organized as an
6386 struct init_node
*left
, *right
;
6387 struct init_node
*parent
;
6394 /* Tree of pending elements at this constructor level.
6395 These are elements encountered out of order
6396 which belong at places we haven't reached yet in actually
6398 Will never hold tree nodes across GC runs. */
6399 static struct init_node
*constructor_pending_elts
;
6401 /* The SPELLING_DEPTH of this constructor. */
6402 static int constructor_depth
;
6404 /* DECL node for which an initializer is being read.
6405 0 means we are reading a constructor expression
6406 such as (struct foo) {...}. */
6407 static tree constructor_decl
;
6409 /* Nonzero if this is an initializer for a top-level decl. */
6410 static int constructor_top_level
;
6412 /* Nonzero if there were any member designators in this initializer. */
6413 static int constructor_designated
;
6415 /* Nesting depth of designator list. */
6416 static int designator_depth
;
6418 /* Nonzero if there were diagnosed errors in this designator list. */
6419 static int designator_erroneous
;
6422 /* This stack has a level for each implicit or explicit level of
6423 structuring in the initializer, including the outermost one. It
6424 saves the values of most of the variables above. */
6426 struct constructor_range_stack
;
6428 struct constructor_stack
6430 struct constructor_stack
*next
;
6435 tree unfilled_index
;
6436 tree unfilled_fields
;
6438 vec
<constructor_elt
, va_gc
> *elements
;
6439 struct init_node
*pending_elts
;
6442 /* If value nonzero, this value should replace the entire
6443 constructor at this level. */
6444 struct c_expr replacement_value
;
6445 struct constructor_range_stack
*range_stack
;
6456 static struct constructor_stack
*constructor_stack
;
6458 /* This stack represents designators from some range designator up to
6459 the last designator in the list. */
6461 struct constructor_range_stack
6463 struct constructor_range_stack
*next
, *prev
;
6464 struct constructor_stack
*stack
;
6471 static struct constructor_range_stack
*constructor_range_stack
;
6473 /* This stack records separate initializers that are nested.
6474 Nested initializers can't happen in ANSI C, but GNU C allows them
6475 in cases like { ... (struct foo) { ... } ... }. */
6477 struct initializer_stack
6479 struct initializer_stack
*next
;
6481 struct constructor_stack
*constructor_stack
;
6482 struct constructor_range_stack
*constructor_range_stack
;
6483 vec
<constructor_elt
, va_gc
> *elements
;
6484 struct spelling
*spelling
;
6485 struct spelling
*spelling_base
;
6488 char require_constant_value
;
6489 char require_constant_elements
;
6492 static struct initializer_stack
*initializer_stack
;
6494 /* Prepare to parse and output the initializer for variable DECL. */
6497 start_init (tree decl
, tree asmspec_tree ATTRIBUTE_UNUSED
, int top_level
)
6500 struct initializer_stack
*p
= XNEW (struct initializer_stack
);
6502 p
->decl
= constructor_decl
;
6503 p
->require_constant_value
= require_constant_value
;
6504 p
->require_constant_elements
= require_constant_elements
;
6505 p
->constructor_stack
= constructor_stack
;
6506 p
->constructor_range_stack
= constructor_range_stack
;
6507 p
->elements
= constructor_elements
;
6508 p
->spelling
= spelling
;
6509 p
->spelling_base
= spelling_base
;
6510 p
->spelling_size
= spelling_size
;
6511 p
->top_level
= constructor_top_level
;
6512 p
->next
= initializer_stack
;
6513 initializer_stack
= p
;
6515 constructor_decl
= decl
;
6516 constructor_designated
= 0;
6517 constructor_top_level
= top_level
;
6519 if (decl
!= 0 && decl
!= error_mark_node
)
6521 require_constant_value
= TREE_STATIC (decl
);
6522 require_constant_elements
6523 = ((TREE_STATIC (decl
) || (pedantic
&& !flag_isoc99
))
6524 /* For a scalar, you can always use any value to initialize,
6525 even within braces. */
6526 && (TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
6527 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
6528 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
6529 || TREE_CODE (TREE_TYPE (decl
)) == QUAL_UNION_TYPE
));
6530 locus
= identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl
)));
6534 require_constant_value
= 0;
6535 require_constant_elements
= 0;
6536 locus
= _("(anonymous)");
6539 constructor_stack
= 0;
6540 constructor_range_stack
= 0;
6542 missing_braces_mentioned
= 0;
6546 RESTORE_SPELLING_DEPTH (0);
6549 push_string (locus
);
6555 struct initializer_stack
*p
= initializer_stack
;
6557 /* Free the whole constructor stack of this initializer. */
6558 while (constructor_stack
)
6560 struct constructor_stack
*q
= constructor_stack
;
6561 constructor_stack
= q
->next
;
6565 gcc_assert (!constructor_range_stack
);
6567 /* Pop back to the data of the outer initializer (if any). */
6568 free (spelling_base
);
6570 constructor_decl
= p
->decl
;
6571 require_constant_value
= p
->require_constant_value
;
6572 require_constant_elements
= p
->require_constant_elements
;
6573 constructor_stack
= p
->constructor_stack
;
6574 constructor_range_stack
= p
->constructor_range_stack
;
6575 constructor_elements
= p
->elements
;
6576 spelling
= p
->spelling
;
6577 spelling_base
= p
->spelling_base
;
6578 spelling_size
= p
->spelling_size
;
6579 constructor_top_level
= p
->top_level
;
6580 initializer_stack
= p
->next
;
6584 /* Call here when we see the initializer is surrounded by braces.
6585 This is instead of a call to push_init_level;
6586 it is matched by a call to pop_init_level.
6588 TYPE is the type to initialize, for a constructor expression.
6589 For an initializer for a decl, TYPE is zero. */
6592 really_start_incremental_init (tree type
)
6594 struct constructor_stack
*p
= XNEW (struct constructor_stack
);
6597 type
= TREE_TYPE (constructor_decl
);
6599 if (TREE_CODE (type
) == VECTOR_TYPE
6600 && TYPE_VECTOR_OPAQUE (type
))
6601 error ("opaque vector types cannot be initialized");
6603 p
->type
= constructor_type
;
6604 p
->fields
= constructor_fields
;
6605 p
->index
= constructor_index
;
6606 p
->max_index
= constructor_max_index
;
6607 p
->unfilled_index
= constructor_unfilled_index
;
6608 p
->unfilled_fields
= constructor_unfilled_fields
;
6609 p
->bit_index
= constructor_bit_index
;
6610 p
->elements
= constructor_elements
;
6611 p
->constant
= constructor_constant
;
6612 p
->simple
= constructor_simple
;
6613 p
->nonconst
= constructor_nonconst
;
6614 p
->erroneous
= constructor_erroneous
;
6615 p
->pending_elts
= constructor_pending_elts
;
6616 p
->depth
= constructor_depth
;
6617 p
->replacement_value
.value
= 0;
6618 p
->replacement_value
.original_code
= ERROR_MARK
;
6619 p
->replacement_value
.original_type
= NULL
;
6623 p
->incremental
= constructor_incremental
;
6624 p
->designated
= constructor_designated
;
6626 constructor_stack
= p
;
6628 constructor_constant
= 1;
6629 constructor_simple
= 1;
6630 constructor_nonconst
= 0;
6631 constructor_depth
= SPELLING_DEPTH ();
6632 constructor_elements
= NULL
;
6633 constructor_pending_elts
= 0;
6634 constructor_type
= type
;
6635 constructor_incremental
= 1;
6636 constructor_designated
= 0;
6637 designator_depth
= 0;
6638 designator_erroneous
= 0;
6640 if (TREE_CODE (constructor_type
) == RECORD_TYPE
6641 || TREE_CODE (constructor_type
) == UNION_TYPE
)
6643 constructor_fields
= TYPE_FIELDS (constructor_type
);
6644 /* Skip any nameless bit fields at the beginning. */
6645 while (constructor_fields
!= 0 && DECL_C_BIT_FIELD (constructor_fields
)
6646 && DECL_NAME (constructor_fields
) == 0)
6647 constructor_fields
= DECL_CHAIN (constructor_fields
);
6649 constructor_unfilled_fields
= constructor_fields
;
6650 constructor_bit_index
= bitsize_zero_node
;
6652 else if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
6654 if (TYPE_DOMAIN (constructor_type
))
6656 constructor_max_index
6657 = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type
));
6659 /* Detect non-empty initializations of zero-length arrays. */
6660 if (constructor_max_index
== NULL_TREE
6661 && TYPE_SIZE (constructor_type
))
6662 constructor_max_index
= integer_minus_one_node
;
6664 /* constructor_max_index needs to be an INTEGER_CST. Attempts
6665 to initialize VLAs will cause a proper error; avoid tree
6666 checking errors as well by setting a safe value. */
6667 if (constructor_max_index
6668 && TREE_CODE (constructor_max_index
) != INTEGER_CST
)
6669 constructor_max_index
= integer_minus_one_node
;
6672 = convert (bitsizetype
,
6673 TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type
)));
6677 constructor_index
= bitsize_zero_node
;
6678 constructor_max_index
= NULL_TREE
;
6681 constructor_unfilled_index
= constructor_index
;
6683 else if (TREE_CODE (constructor_type
) == VECTOR_TYPE
)
6685 /* Vectors are like simple fixed-size arrays. */
6686 constructor_max_index
=
6687 bitsize_int (TYPE_VECTOR_SUBPARTS (constructor_type
) - 1);
6688 constructor_index
= bitsize_zero_node
;
6689 constructor_unfilled_index
= constructor_index
;
6693 /* Handle the case of int x = {5}; */
6694 constructor_fields
= constructor_type
;
6695 constructor_unfilled_fields
= constructor_type
;
6699 /* Push down into a subobject, for initialization.
6700 If this is for an explicit set of braces, IMPLICIT is 0.
6701 If it is because the next element belongs at a lower level,
6702 IMPLICIT is 1 (or 2 if the push is because of designator list). */
6705 push_init_level (int implicit
, struct obstack
* braced_init_obstack
)
6707 struct constructor_stack
*p
;
6708 tree value
= NULL_TREE
;
6710 /* If we've exhausted any levels that didn't have braces,
6711 pop them now. If implicit == 1, this will have been done in
6712 process_init_element; do not repeat it here because in the case
6713 of excess initializers for an empty aggregate this leads to an
6714 infinite cycle of popping a level and immediately recreating
6718 while (constructor_stack
->implicit
)
6720 if ((TREE_CODE (constructor_type
) == RECORD_TYPE
6721 || TREE_CODE (constructor_type
) == UNION_TYPE
)
6722 && constructor_fields
== 0)
6723 process_init_element (pop_init_level (1, braced_init_obstack
),
6724 true, braced_init_obstack
);
6725 else if (TREE_CODE (constructor_type
) == ARRAY_TYPE
6726 && constructor_max_index
6727 && tree_int_cst_lt (constructor_max_index
,
6729 process_init_element (pop_init_level (1, braced_init_obstack
),
6730 true, braced_init_obstack
);
6736 /* Unless this is an explicit brace, we need to preserve previous
6740 if ((TREE_CODE (constructor_type
) == RECORD_TYPE
6741 || TREE_CODE (constructor_type
) == UNION_TYPE
)
6742 && constructor_fields
)
6743 value
= find_init_member (constructor_fields
, braced_init_obstack
);
6744 else if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
6745 value
= find_init_member (constructor_index
, braced_init_obstack
);
6748 p
= XNEW (struct constructor_stack
);
6749 p
->type
= constructor_type
;
6750 p
->fields
= constructor_fields
;
6751 p
->index
= constructor_index
;
6752 p
->max_index
= constructor_max_index
;
6753 p
->unfilled_index
= constructor_unfilled_index
;
6754 p
->unfilled_fields
= constructor_unfilled_fields
;
6755 p
->bit_index
= constructor_bit_index
;
6756 p
->elements
= constructor_elements
;
6757 p
->constant
= constructor_constant
;
6758 p
->simple
= constructor_simple
;
6759 p
->nonconst
= constructor_nonconst
;
6760 p
->erroneous
= constructor_erroneous
;
6761 p
->pending_elts
= constructor_pending_elts
;
6762 p
->depth
= constructor_depth
;
6763 p
->replacement_value
.value
= 0;
6764 p
->replacement_value
.original_code
= ERROR_MARK
;
6765 p
->replacement_value
.original_type
= NULL
;
6766 p
->implicit
= implicit
;
6768 p
->incremental
= constructor_incremental
;
6769 p
->designated
= constructor_designated
;
6770 p
->next
= constructor_stack
;
6772 constructor_stack
= p
;
6774 constructor_constant
= 1;
6775 constructor_simple
= 1;
6776 constructor_nonconst
= 0;
6777 constructor_depth
= SPELLING_DEPTH ();
6778 constructor_elements
= NULL
;
6779 constructor_incremental
= 1;
6780 constructor_designated
= 0;
6781 constructor_pending_elts
= 0;
6784 p
->range_stack
= constructor_range_stack
;
6785 constructor_range_stack
= 0;
6786 designator_depth
= 0;
6787 designator_erroneous
= 0;
6790 /* Don't die if an entire brace-pair level is superfluous
6791 in the containing level. */
6792 if (constructor_type
== 0)
6794 else if (TREE_CODE (constructor_type
) == RECORD_TYPE
6795 || TREE_CODE (constructor_type
) == UNION_TYPE
)
6797 /* Don't die if there are extra init elts at the end. */
6798 if (constructor_fields
== 0)
6799 constructor_type
= 0;
6802 constructor_type
= TREE_TYPE (constructor_fields
);
6803 push_member_name (constructor_fields
);
6804 constructor_depth
++;
6807 else if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
6809 constructor_type
= TREE_TYPE (constructor_type
);
6810 push_array_bounds (tree_low_cst (constructor_index
, 1));
6811 constructor_depth
++;
6814 if (constructor_type
== 0)
6816 error_init ("extra brace group at end of initializer");
6817 constructor_fields
= 0;
6818 constructor_unfilled_fields
= 0;
6822 if (value
&& TREE_CODE (value
) == CONSTRUCTOR
)
6824 constructor_constant
= TREE_CONSTANT (value
);
6825 constructor_simple
= TREE_STATIC (value
);
6826 constructor_nonconst
= CONSTRUCTOR_NON_CONST (value
);
6827 constructor_elements
= CONSTRUCTOR_ELTS (value
);
6828 if (!vec_safe_is_empty (constructor_elements
)
6829 && (TREE_CODE (constructor_type
) == RECORD_TYPE
6830 || TREE_CODE (constructor_type
) == ARRAY_TYPE
))
6831 set_nonincremental_init (braced_init_obstack
);
6834 if (implicit
== 1 && warn_missing_braces
&& !missing_braces_mentioned
)
6836 missing_braces_mentioned
= 1;
6837 warning_init (OPT_Wmissing_braces
, "missing braces around initializer");
6840 if (TREE_CODE (constructor_type
) == RECORD_TYPE
6841 || TREE_CODE (constructor_type
) == UNION_TYPE
)
6843 constructor_fields
= TYPE_FIELDS (constructor_type
);
6844 /* Skip any nameless bit fields at the beginning. */
6845 while (constructor_fields
!= 0 && DECL_C_BIT_FIELD (constructor_fields
)
6846 && DECL_NAME (constructor_fields
) == 0)
6847 constructor_fields
= DECL_CHAIN (constructor_fields
);
6849 constructor_unfilled_fields
= constructor_fields
;
6850 constructor_bit_index
= bitsize_zero_node
;
6852 else if (TREE_CODE (constructor_type
) == VECTOR_TYPE
)
6854 /* Vectors are like simple fixed-size arrays. */
6855 constructor_max_index
=
6856 bitsize_int (TYPE_VECTOR_SUBPARTS (constructor_type
) - 1);
6857 constructor_index
= bitsize_int (0);
6858 constructor_unfilled_index
= constructor_index
;
6860 else if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
6862 if (TYPE_DOMAIN (constructor_type
))
6864 constructor_max_index
6865 = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type
));
6867 /* Detect non-empty initializations of zero-length arrays. */
6868 if (constructor_max_index
== NULL_TREE
6869 && TYPE_SIZE (constructor_type
))
6870 constructor_max_index
= integer_minus_one_node
;
6872 /* constructor_max_index needs to be an INTEGER_CST. Attempts
6873 to initialize VLAs will cause a proper error; avoid tree
6874 checking errors as well by setting a safe value. */
6875 if (constructor_max_index
6876 && TREE_CODE (constructor_max_index
) != INTEGER_CST
)
6877 constructor_max_index
= integer_minus_one_node
;
6880 = convert (bitsizetype
,
6881 TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type
)));
6884 constructor_index
= bitsize_zero_node
;
6886 constructor_unfilled_index
= constructor_index
;
6887 if (value
&& TREE_CODE (value
) == STRING_CST
)
6889 /* We need to split the char/wchar array into individual
6890 characters, so that we don't have to special case it
6892 set_nonincremental_init_from_string (value
, braced_init_obstack
);
6897 if (constructor_type
!= error_mark_node
)
6898 warning_init (0, "braces around scalar initializer");
6899 constructor_fields
= constructor_type
;
6900 constructor_unfilled_fields
= constructor_type
;
6904 /* At the end of an implicit or explicit brace level,
6905 finish up that level of constructor. If a single expression
6906 with redundant braces initialized that level, return the
6907 c_expr structure for that expression. Otherwise, the original_code
6908 element is set to ERROR_MARK.
6909 If we were outputting the elements as they are read, return 0 as the value
6910 from inner levels (process_init_element ignores that),
6911 but return error_mark_node as the value from the outermost level
6912 (that's what we want to put in DECL_INITIAL).
6913 Otherwise, return a CONSTRUCTOR expression as the value. */
6916 pop_init_level (int implicit
, struct obstack
* braced_init_obstack
)
6918 struct constructor_stack
*p
;
6921 ret
.original_code
= ERROR_MARK
;
6922 ret
.original_type
= NULL
;
6926 /* When we come to an explicit close brace,
6927 pop any inner levels that didn't have explicit braces. */
6928 while (constructor_stack
->implicit
)
6930 process_init_element (pop_init_level (1, braced_init_obstack
),
6931 true, braced_init_obstack
);
6933 gcc_assert (!constructor_range_stack
);
6936 /* Now output all pending elements. */
6937 constructor_incremental
= 1;
6938 output_pending_init_elements (1, braced_init_obstack
);
6940 p
= constructor_stack
;
6942 /* Error for initializing a flexible array member, or a zero-length
6943 array member in an inappropriate context. */
6944 if (constructor_type
&& constructor_fields
6945 && TREE_CODE (constructor_type
) == ARRAY_TYPE
6946 && TYPE_DOMAIN (constructor_type
)
6947 && !TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type
)))
6949 /* Silently discard empty initializations. The parser will
6950 already have pedwarned for empty brackets. */
6951 if (integer_zerop (constructor_unfilled_index
))
6952 constructor_type
= NULL_TREE
;
6955 gcc_assert (!TYPE_SIZE (constructor_type
));
6957 if (constructor_depth
> 2)
6958 error_init ("initialization of flexible array member in a nested context");
6960 pedwarn_init (input_location
, OPT_Wpedantic
,
6961 "initialization of a flexible array member");
6963 /* We have already issued an error message for the existence
6964 of a flexible array member not at the end of the structure.
6965 Discard the initializer so that we do not die later. */
6966 if (DECL_CHAIN (constructor_fields
) != NULL_TREE
)
6967 constructor_type
= NULL_TREE
;
6971 /* Warn when some struct elements are implicitly initialized to zero. */
6972 if (warn_missing_field_initializers
6974 && TREE_CODE (constructor_type
) == RECORD_TYPE
6975 && constructor_unfilled_fields
)
6977 bool constructor_zeroinit
=
6978 (vec_safe_length (constructor_elements
) == 1
6979 && integer_zerop ((*constructor_elements
)[0].value
));
6981 /* Do not warn for flexible array members or zero-length arrays. */
6982 while (constructor_unfilled_fields
6983 && (!DECL_SIZE (constructor_unfilled_fields
)
6984 || integer_zerop (DECL_SIZE (constructor_unfilled_fields
))))
6985 constructor_unfilled_fields
= DECL_CHAIN (constructor_unfilled_fields
);
6987 if (constructor_unfilled_fields
6988 /* Do not warn if this level of the initializer uses member
6989 designators; it is likely to be deliberate. */
6990 && !constructor_designated
6991 /* Do not warn about initializing with ` = {0}'. */
6992 && !constructor_zeroinit
)
6994 if (warning_at (input_location
, OPT_Wmissing_field_initializers
,
6995 "missing initializer for field %qD of %qT",
6996 constructor_unfilled_fields
,
6998 inform (DECL_SOURCE_LOCATION (constructor_unfilled_fields
),
6999 "%qD declared here", constructor_unfilled_fields
);
7003 /* Pad out the end of the structure. */
7004 if (p
->replacement_value
.value
)
7005 /* If this closes a superfluous brace pair,
7006 just pass out the element between them. */
7007 ret
= p
->replacement_value
;
7008 else if (constructor_type
== 0)
7010 else if (TREE_CODE (constructor_type
) != RECORD_TYPE
7011 && TREE_CODE (constructor_type
) != UNION_TYPE
7012 && TREE_CODE (constructor_type
) != ARRAY_TYPE
7013 && TREE_CODE (constructor_type
) != VECTOR_TYPE
)
7015 /* A nonincremental scalar initializer--just return
7016 the element, after verifying there is just one. */
7017 if (vec_safe_is_empty (constructor_elements
))
7019 if (!constructor_erroneous
)
7020 error_init ("empty scalar initializer");
7021 ret
.value
= error_mark_node
;
7023 else if (vec_safe_length (constructor_elements
) != 1)
7025 error_init ("extra elements in scalar initializer");
7026 ret
.value
= (*constructor_elements
)[0].value
;
7029 ret
.value
= (*constructor_elements
)[0].value
;
7033 if (constructor_erroneous
)
7034 ret
.value
= error_mark_node
;
7037 ret
.value
= build_constructor (constructor_type
,
7038 constructor_elements
);
7039 if (constructor_constant
)
7040 TREE_CONSTANT (ret
.value
) = 1;
7041 if (constructor_constant
&& constructor_simple
)
7042 TREE_STATIC (ret
.value
) = 1;
7043 if (constructor_nonconst
)
7044 CONSTRUCTOR_NON_CONST (ret
.value
) = 1;
7048 if (ret
.value
&& TREE_CODE (ret
.value
) != CONSTRUCTOR
)
7050 if (constructor_nonconst
)
7051 ret
.original_code
= C_MAYBE_CONST_EXPR
;
7052 else if (ret
.original_code
== C_MAYBE_CONST_EXPR
)
7053 ret
.original_code
= ERROR_MARK
;
7056 constructor_type
= p
->type
;
7057 constructor_fields
= p
->fields
;
7058 constructor_index
= p
->index
;
7059 constructor_max_index
= p
->max_index
;
7060 constructor_unfilled_index
= p
->unfilled_index
;
7061 constructor_unfilled_fields
= p
->unfilled_fields
;
7062 constructor_bit_index
= p
->bit_index
;
7063 constructor_elements
= p
->elements
;
7064 constructor_constant
= p
->constant
;
7065 constructor_simple
= p
->simple
;
7066 constructor_nonconst
= p
->nonconst
;
7067 constructor_erroneous
= p
->erroneous
;
7068 constructor_incremental
= p
->incremental
;
7069 constructor_designated
= p
->designated
;
7070 constructor_pending_elts
= p
->pending_elts
;
7071 constructor_depth
= p
->depth
;
7073 constructor_range_stack
= p
->range_stack
;
7074 RESTORE_SPELLING_DEPTH (constructor_depth
);
7076 constructor_stack
= p
->next
;
7079 if (ret
.value
== 0 && constructor_stack
== 0)
7080 ret
.value
= error_mark_node
;
7084 /* Common handling for both array range and field name designators.
7085 ARRAY argument is nonzero for array ranges. Returns zero for success. */
7088 set_designator (int array
, struct obstack
* braced_init_obstack
)
7091 enum tree_code subcode
;
7093 /* Don't die if an entire brace-pair level is superfluous
7094 in the containing level. */
7095 if (constructor_type
== 0)
7098 /* If there were errors in this designator list already, bail out
7100 if (designator_erroneous
)
7103 if (!designator_depth
)
7105 gcc_assert (!constructor_range_stack
);
7107 /* Designator list starts at the level of closest explicit
7109 while (constructor_stack
->implicit
)
7111 process_init_element (pop_init_level (1, braced_init_obstack
),
7112 true, braced_init_obstack
);
7114 constructor_designated
= 1;
7118 switch (TREE_CODE (constructor_type
))
7122 subtype
= TREE_TYPE (constructor_fields
);
7123 if (subtype
!= error_mark_node
)
7124 subtype
= TYPE_MAIN_VARIANT (subtype
);
7127 subtype
= TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type
));
7133 subcode
= TREE_CODE (subtype
);
7134 if (array
&& subcode
!= ARRAY_TYPE
)
7136 error_init ("array index in non-array initializer");
7139 else if (!array
&& subcode
!= RECORD_TYPE
&& subcode
!= UNION_TYPE
)
7141 error_init ("field name not in record or union initializer");
7145 constructor_designated
= 1;
7146 push_init_level (2, braced_init_obstack
);
7150 /* If there are range designators in designator list, push a new designator
7151 to constructor_range_stack. RANGE_END is end of such stack range or
7152 NULL_TREE if there is no range designator at this level. */
7155 push_range_stack (tree range_end
, struct obstack
* braced_init_obstack
)
7157 struct constructor_range_stack
*p
;
7159 p
= (struct constructor_range_stack
*)
7160 obstack_alloc (braced_init_obstack
,
7161 sizeof (struct constructor_range_stack
));
7162 p
->prev
= constructor_range_stack
;
7164 p
->fields
= constructor_fields
;
7165 p
->range_start
= constructor_index
;
7166 p
->index
= constructor_index
;
7167 p
->stack
= constructor_stack
;
7168 p
->range_end
= range_end
;
7169 if (constructor_range_stack
)
7170 constructor_range_stack
->next
= p
;
7171 constructor_range_stack
= p
;
7174 /* Within an array initializer, specify the next index to be initialized.
7175 FIRST is that index. If LAST is nonzero, then initialize a range
7176 of indices, running from FIRST through LAST. */
7179 set_init_index (tree first
, tree last
,
7180 struct obstack
* braced_init_obstack
)
7182 if (set_designator (1, braced_init_obstack
))
7185 designator_erroneous
= 1;
7187 if (!INTEGRAL_TYPE_P (TREE_TYPE (first
))
7188 || (last
&& !INTEGRAL_TYPE_P (TREE_TYPE (last
))))
7190 error_init ("array index in initializer not of integer type");
7194 if (TREE_CODE (first
) != INTEGER_CST
)
7196 first
= c_fully_fold (first
, false, NULL
);
7197 if (TREE_CODE (first
) == INTEGER_CST
)
7198 pedwarn_init (input_location
, OPT_Wpedantic
,
7199 "array index in initializer is not "
7200 "an integer constant expression");
7203 if (last
&& TREE_CODE (last
) != INTEGER_CST
)
7205 last
= c_fully_fold (last
, false, NULL
);
7206 if (TREE_CODE (last
) == INTEGER_CST
)
7207 pedwarn_init (input_location
, OPT_Wpedantic
,
7208 "array index in initializer is not "
7209 "an integer constant expression");
7212 if (TREE_CODE (first
) != INTEGER_CST
)
7213 error_init ("nonconstant array index in initializer");
7214 else if (last
!= 0 && TREE_CODE (last
) != INTEGER_CST
)
7215 error_init ("nonconstant array index in initializer");
7216 else if (TREE_CODE (constructor_type
) != ARRAY_TYPE
)
7217 error_init ("array index in non-array initializer");
7218 else if (tree_int_cst_sgn (first
) == -1)
7219 error_init ("array index in initializer exceeds array bounds");
7220 else if (constructor_max_index
7221 && tree_int_cst_lt (constructor_max_index
, first
))
7222 error_init ("array index in initializer exceeds array bounds");
7225 constant_expression_warning (first
);
7227 constant_expression_warning (last
);
7228 constructor_index
= convert (bitsizetype
, first
);
7229 if (tree_int_cst_lt (constructor_index
, first
))
7231 constructor_index
= copy_node (constructor_index
);
7232 TREE_OVERFLOW (constructor_index
) = 1;
7237 if (tree_int_cst_equal (first
, last
))
7239 else if (tree_int_cst_lt (last
, first
))
7241 error_init ("empty index range in initializer");
7246 last
= convert (bitsizetype
, last
);
7247 if (constructor_max_index
!= 0
7248 && tree_int_cst_lt (constructor_max_index
, last
))
7250 error_init ("array index range in initializer exceeds array bounds");
7257 designator_erroneous
= 0;
7258 if (constructor_range_stack
|| last
)
7259 push_range_stack (last
, braced_init_obstack
);
7263 /* Within a struct initializer, specify the next field to be initialized. */
7266 set_init_label (tree fieldname
, struct obstack
* braced_init_obstack
)
7270 if (set_designator (0, braced_init_obstack
))
7273 designator_erroneous
= 1;
7275 if (TREE_CODE (constructor_type
) != RECORD_TYPE
7276 && TREE_CODE (constructor_type
) != UNION_TYPE
)
7278 error_init ("field name not in record or union initializer");
7282 field
= lookup_field (constructor_type
, fieldname
);
7285 error ("unknown field %qE specified in initializer", fieldname
);
7289 constructor_fields
= TREE_VALUE (field
);
7291 designator_erroneous
= 0;
7292 if (constructor_range_stack
)
7293 push_range_stack (NULL_TREE
, braced_init_obstack
);
7294 field
= TREE_CHAIN (field
);
7297 if (set_designator (0, braced_init_obstack
))
7301 while (field
!= NULL_TREE
);
7304 /* Add a new initializer to the tree of pending initializers. PURPOSE
7305 identifies the initializer, either array index or field in a structure.
7306 VALUE is the value of that index or field. If ORIGTYPE is not
7307 NULL_TREE, it is the original type of VALUE.
7309 IMPLICIT is true if value comes from pop_init_level (1),
7310 the new initializer has been merged with the existing one
7311 and thus no warnings should be emitted about overriding an
7312 existing initializer. */
7315 add_pending_init (tree purpose
, tree value
, tree origtype
, bool implicit
,
7316 struct obstack
* braced_init_obstack
)
7318 struct init_node
*p
, **q
, *r
;
7320 q
= &constructor_pending_elts
;
7323 if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
7328 if (tree_int_cst_lt (purpose
, p
->purpose
))
7330 else if (tree_int_cst_lt (p
->purpose
, purpose
))
7336 if (TREE_SIDE_EFFECTS (p
->value
))
7337 warning_init (0, "initialized field with side-effects overwritten");
7338 else if (warn_override_init
)
7339 warning_init (OPT_Woverride_init
, "initialized field overwritten");
7342 p
->origtype
= origtype
;
7351 bitpos
= bit_position (purpose
);
7355 if (tree_int_cst_lt (bitpos
, bit_position (p
->purpose
)))
7357 else if (p
->purpose
!= purpose
)
7363 if (TREE_SIDE_EFFECTS (p
->value
))
7364 warning_init (0, "initialized field with side-effects overwritten");
7365 else if (warn_override_init
)
7366 warning_init (OPT_Woverride_init
, "initialized field overwritten");
7369 p
->origtype
= origtype
;
7375 r
= (struct init_node
*) obstack_alloc (braced_init_obstack
,
7376 sizeof (struct init_node
));
7377 r
->purpose
= purpose
;
7379 r
->origtype
= origtype
;
7389 struct init_node
*s
;
7393 if (p
->balance
== 0)
7395 else if (p
->balance
< 0)
7402 p
->left
->parent
= p
;
7419 constructor_pending_elts
= r
;
7424 struct init_node
*t
= r
->right
;
7428 r
->right
->parent
= r
;
7433 p
->left
->parent
= p
;
7436 p
->balance
= t
->balance
< 0;
7437 r
->balance
= -(t
->balance
> 0);
7452 constructor_pending_elts
= t
;
7458 /* p->balance == +1; growth of left side balances the node. */
7463 else /* r == p->right */
7465 if (p
->balance
== 0)
7466 /* Growth propagation from right side. */
7468 else if (p
->balance
> 0)
7475 p
->right
->parent
= p
;
7492 constructor_pending_elts
= r
;
7494 else /* r->balance == -1 */
7497 struct init_node
*t
= r
->left
;
7501 r
->left
->parent
= r
;
7506 p
->right
->parent
= p
;
7509 r
->balance
= (t
->balance
< 0);
7510 p
->balance
= -(t
->balance
> 0);
7525 constructor_pending_elts
= t
;
7531 /* p->balance == -1; growth of right side balances the node. */
7542 /* Build AVL tree from a sorted chain. */
7545 set_nonincremental_init (struct obstack
* braced_init_obstack
)
7547 unsigned HOST_WIDE_INT ix
;
7550 if (TREE_CODE (constructor_type
) != RECORD_TYPE
7551 && TREE_CODE (constructor_type
) != ARRAY_TYPE
)
7554 FOR_EACH_CONSTRUCTOR_ELT (constructor_elements
, ix
, index
, value
)
7556 add_pending_init (index
, value
, NULL_TREE
, true,
7557 braced_init_obstack
);
7559 constructor_elements
= NULL
;
7560 if (TREE_CODE (constructor_type
) == RECORD_TYPE
)
7562 constructor_unfilled_fields
= TYPE_FIELDS (constructor_type
);
7563 /* Skip any nameless bit fields at the beginning. */
7564 while (constructor_unfilled_fields
!= 0
7565 && DECL_C_BIT_FIELD (constructor_unfilled_fields
)
7566 && DECL_NAME (constructor_unfilled_fields
) == 0)
7567 constructor_unfilled_fields
= TREE_CHAIN (constructor_unfilled_fields
);
7570 else if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
7572 if (TYPE_DOMAIN (constructor_type
))
7573 constructor_unfilled_index
7574 = convert (bitsizetype
,
7575 TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type
)));
7577 constructor_unfilled_index
= bitsize_zero_node
;
7579 constructor_incremental
= 0;
7582 /* Build AVL tree from a string constant. */
7585 set_nonincremental_init_from_string (tree str
,
7586 struct obstack
* braced_init_obstack
)
7588 tree value
, purpose
, type
;
7589 HOST_WIDE_INT val
[2];
7590 const char *p
, *end
;
7591 int byte
, wchar_bytes
, charwidth
, bitpos
;
7593 gcc_assert (TREE_CODE (constructor_type
) == ARRAY_TYPE
);
7595 wchar_bytes
= TYPE_PRECISION (TREE_TYPE (TREE_TYPE (str
))) / BITS_PER_UNIT
;
7596 charwidth
= TYPE_PRECISION (char_type_node
);
7597 type
= TREE_TYPE (constructor_type
);
7598 p
= TREE_STRING_POINTER (str
);
7599 end
= p
+ TREE_STRING_LENGTH (str
);
7601 for (purpose
= bitsize_zero_node
;
7603 && !(constructor_max_index
7604 && tree_int_cst_lt (constructor_max_index
, purpose
));
7605 purpose
= size_binop (PLUS_EXPR
, purpose
, bitsize_one_node
))
7607 if (wchar_bytes
== 1)
7609 val
[1] = (unsigned char) *p
++;
7616 for (byte
= 0; byte
< wchar_bytes
; byte
++)
7618 if (BYTES_BIG_ENDIAN
)
7619 bitpos
= (wchar_bytes
- byte
- 1) * charwidth
;
7621 bitpos
= byte
* charwidth
;
7622 val
[bitpos
< HOST_BITS_PER_WIDE_INT
]
7623 |= ((unsigned HOST_WIDE_INT
) ((unsigned char) *p
++))
7624 << (bitpos
% HOST_BITS_PER_WIDE_INT
);
7628 if (!TYPE_UNSIGNED (type
))
7630 bitpos
= ((wchar_bytes
- 1) * charwidth
) + HOST_BITS_PER_CHAR
;
7631 if (bitpos
< HOST_BITS_PER_WIDE_INT
)
7633 if (val
[1] & (((HOST_WIDE_INT
) 1) << (bitpos
- 1)))
7635 val
[1] |= ((HOST_WIDE_INT
) -1) << bitpos
;
7639 else if (bitpos
== HOST_BITS_PER_WIDE_INT
)
7644 else if (val
[0] & (((HOST_WIDE_INT
) 1)
7645 << (bitpos
- 1 - HOST_BITS_PER_WIDE_INT
)))
7646 val
[0] |= ((HOST_WIDE_INT
) -1)
7647 << (bitpos
- HOST_BITS_PER_WIDE_INT
);
7650 value
= build_int_cst_wide (type
, val
[1], val
[0]);
7651 add_pending_init (purpose
, value
, NULL_TREE
, true,
7652 braced_init_obstack
);
7655 constructor_incremental
= 0;
7658 /* Return value of FIELD in pending initializer or zero if the field was
7659 not initialized yet. */
7662 find_init_member (tree field
, struct obstack
* braced_init_obstack
)
7664 struct init_node
*p
;
7666 if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
7668 if (constructor_incremental
7669 && tree_int_cst_lt (field
, constructor_unfilled_index
))
7670 set_nonincremental_init (braced_init_obstack
);
7672 p
= constructor_pending_elts
;
7675 if (tree_int_cst_lt (field
, p
->purpose
))
7677 else if (tree_int_cst_lt (p
->purpose
, field
))
7683 else if (TREE_CODE (constructor_type
) == RECORD_TYPE
)
7685 tree bitpos
= bit_position (field
);
7687 if (constructor_incremental
7688 && (!constructor_unfilled_fields
7689 || tree_int_cst_lt (bitpos
,
7690 bit_position (constructor_unfilled_fields
))))
7691 set_nonincremental_init (braced_init_obstack
);
7693 p
= constructor_pending_elts
;
7696 if (field
== p
->purpose
)
7698 else if (tree_int_cst_lt (bitpos
, bit_position (p
->purpose
)))
7704 else if (TREE_CODE (constructor_type
) == UNION_TYPE
)
7706 if (!vec_safe_is_empty (constructor_elements
)
7707 && (constructor_elements
->last ().index
== field
))
7708 return constructor_elements
->last ().value
;
7713 /* "Output" the next constructor element.
7714 At top level, really output it to assembler code now.
7715 Otherwise, collect it in a list from which we will make a CONSTRUCTOR.
7716 If ORIGTYPE is not NULL_TREE, it is the original type of VALUE.
7717 TYPE is the data type that the containing data type wants here.
7718 FIELD is the field (a FIELD_DECL) or the index that this element fills.
7719 If VALUE is a string constant, STRICT_STRING is true if it is
7720 unparenthesized or we should not warn here for it being parenthesized.
7721 For other types of VALUE, STRICT_STRING is not used.
7723 PENDING if non-nil means output pending elements that belong
7724 right after this element. (PENDING is normally 1;
7725 it is 0 while outputting pending elements, to avoid recursion.)
7727 IMPLICIT is true if value comes from pop_init_level (1),
7728 the new initializer has been merged with the existing one
7729 and thus no warnings should be emitted about overriding an
7730 existing initializer. */
7733 output_init_element (tree value
, tree origtype
, bool strict_string
, tree type
,
7734 tree field
, int pending
, bool implicit
,
7735 struct obstack
* braced_init_obstack
)
7737 tree semantic_type
= NULL_TREE
;
7738 bool maybe_const
= true;
7741 if (type
== error_mark_node
|| value
== error_mark_node
)
7743 constructor_erroneous
= 1;
7746 if (TREE_CODE (TREE_TYPE (value
)) == ARRAY_TYPE
7747 && (TREE_CODE (value
) == STRING_CST
7748 || TREE_CODE (value
) == COMPOUND_LITERAL_EXPR
)
7749 && !(TREE_CODE (value
) == STRING_CST
7750 && TREE_CODE (type
) == ARRAY_TYPE
7751 && INTEGRAL_TYPE_P (TREE_TYPE (type
)))
7752 && !comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (value
)),
7753 TYPE_MAIN_VARIANT (type
)))
7754 value
= array_to_pointer_conversion (input_location
, value
);
7756 if (TREE_CODE (value
) == COMPOUND_LITERAL_EXPR
7757 && require_constant_value
&& !flag_isoc99
&& pending
)
7759 /* As an extension, allow initializing objects with static storage
7760 duration with compound literals (which are then treated just as
7761 the brace enclosed list they contain). */
7762 tree decl
= COMPOUND_LITERAL_EXPR_DECL (value
);
7763 value
= DECL_INITIAL (decl
);
7766 npc
= null_pointer_constant_p (value
);
7767 if (TREE_CODE (value
) == EXCESS_PRECISION_EXPR
)
7769 semantic_type
= TREE_TYPE (value
);
7770 value
= TREE_OPERAND (value
, 0);
7772 value
= c_fully_fold (value
, require_constant_value
, &maybe_const
);
7774 if (value
== error_mark_node
)
7775 constructor_erroneous
= 1;
7776 else if (!TREE_CONSTANT (value
))
7777 constructor_constant
= 0;
7778 else if (!initializer_constant_valid_p (value
, TREE_TYPE (value
))
7779 || ((TREE_CODE (constructor_type
) == RECORD_TYPE
7780 || TREE_CODE (constructor_type
) == UNION_TYPE
)
7781 && DECL_C_BIT_FIELD (field
)
7782 && TREE_CODE (value
) != INTEGER_CST
))
7783 constructor_simple
= 0;
7785 constructor_nonconst
= 1;
7787 if (!initializer_constant_valid_p (value
, TREE_TYPE (value
)))
7789 if (require_constant_value
)
7791 error_init ("initializer element is not constant");
7792 value
= error_mark_node
;
7794 else if (require_constant_elements
)
7795 pedwarn (input_location
, 0,
7796 "initializer element is not computable at load time");
7798 else if (!maybe_const
7799 && (require_constant_value
|| require_constant_elements
))
7800 pedwarn_init (input_location
, 0,
7801 "initializer element is not a constant expression");
7803 /* Issue -Wc++-compat warnings about initializing a bitfield with
7806 && field
!= NULL_TREE
7807 && TREE_CODE (field
) == FIELD_DECL
7808 && DECL_BIT_FIELD_TYPE (field
) != NULL_TREE
7809 && (TYPE_MAIN_VARIANT (DECL_BIT_FIELD_TYPE (field
))
7810 != TYPE_MAIN_VARIANT (type
))
7811 && TREE_CODE (DECL_BIT_FIELD_TYPE (field
)) == ENUMERAL_TYPE
)
7813 tree checktype
= origtype
!= NULL_TREE
? origtype
: TREE_TYPE (value
);
7814 if (checktype
!= error_mark_node
7815 && (TYPE_MAIN_VARIANT (checktype
)
7816 != TYPE_MAIN_VARIANT (DECL_BIT_FIELD_TYPE (field
))))
7817 warning_init (OPT_Wc___compat
,
7818 "enum conversion in initialization is invalid in C++");
7821 /* If this field is empty (and not at the end of structure),
7822 don't do anything other than checking the initializer. */
7824 && (TREE_TYPE (field
) == error_mark_node
7825 || (COMPLETE_TYPE_P (TREE_TYPE (field
))
7826 && integer_zerop (TYPE_SIZE (TREE_TYPE (field
)))
7827 && (TREE_CODE (constructor_type
) == ARRAY_TYPE
7828 || DECL_CHAIN (field
)))))
7832 value
= build1 (EXCESS_PRECISION_EXPR
, semantic_type
, value
);
7833 value
= digest_init (input_location
, type
, value
, origtype
, npc
,
7834 strict_string
, require_constant_value
);
7835 if (value
== error_mark_node
)
7837 constructor_erroneous
= 1;
7840 if (require_constant_value
|| require_constant_elements
)
7841 constant_expression_warning (value
);
7843 /* If this element doesn't come next in sequence,
7844 put it on constructor_pending_elts. */
7845 if (TREE_CODE (constructor_type
) == ARRAY_TYPE
7846 && (!constructor_incremental
7847 || !tree_int_cst_equal (field
, constructor_unfilled_index
)))
7849 if (constructor_incremental
7850 && tree_int_cst_lt (field
, constructor_unfilled_index
))
7851 set_nonincremental_init (braced_init_obstack
);
7853 add_pending_init (field
, value
, origtype
, implicit
,
7854 braced_init_obstack
);
7857 else if (TREE_CODE (constructor_type
) == RECORD_TYPE
7858 && (!constructor_incremental
7859 || field
!= constructor_unfilled_fields
))
7861 /* We do this for records but not for unions. In a union,
7862 no matter which field is specified, it can be initialized
7863 right away since it starts at the beginning of the union. */
7864 if (constructor_incremental
)
7866 if (!constructor_unfilled_fields
)
7867 set_nonincremental_init (braced_init_obstack
);
7870 tree bitpos
, unfillpos
;
7872 bitpos
= bit_position (field
);
7873 unfillpos
= bit_position (constructor_unfilled_fields
);
7875 if (tree_int_cst_lt (bitpos
, unfillpos
))
7876 set_nonincremental_init (braced_init_obstack
);
7880 add_pending_init (field
, value
, origtype
, implicit
,
7881 braced_init_obstack
);
7884 else if (TREE_CODE (constructor_type
) == UNION_TYPE
7885 && !vec_safe_is_empty (constructor_elements
))
7889 if (TREE_SIDE_EFFECTS (constructor_elements
->last ().value
))
7891 "initialized field with side-effects overwritten");
7892 else if (warn_override_init
)
7893 warning_init (OPT_Woverride_init
, "initialized field overwritten");
7896 /* We can have just one union field set. */
7897 constructor_elements
= NULL
;
7900 /* Otherwise, output this element either to
7901 constructor_elements or to the assembler file. */
7903 constructor_elt celt
= {field
, value
};
7904 vec_safe_push (constructor_elements
, celt
);
7906 /* Advance the variable that indicates sequential elements output. */
7907 if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
7908 constructor_unfilled_index
7909 = size_binop_loc (input_location
, PLUS_EXPR
, constructor_unfilled_index
,
7911 else if (TREE_CODE (constructor_type
) == RECORD_TYPE
)
7913 constructor_unfilled_fields
7914 = DECL_CHAIN (constructor_unfilled_fields
);
7916 /* Skip any nameless bit fields. */
7917 while (constructor_unfilled_fields
!= 0
7918 && DECL_C_BIT_FIELD (constructor_unfilled_fields
)
7919 && DECL_NAME (constructor_unfilled_fields
) == 0)
7920 constructor_unfilled_fields
=
7921 DECL_CHAIN (constructor_unfilled_fields
);
7923 else if (TREE_CODE (constructor_type
) == UNION_TYPE
)
7924 constructor_unfilled_fields
= 0;
7926 /* Now output any pending elements which have become next. */
7928 output_pending_init_elements (0, braced_init_obstack
);
7931 /* Output any pending elements which have become next.
7932 As we output elements, constructor_unfilled_{fields,index}
7933 advances, which may cause other elements to become next;
7934 if so, they too are output.
7936 If ALL is 0, we return when there are
7937 no more pending elements to output now.
7939 If ALL is 1, we output space as necessary so that
7940 we can output all the pending elements. */
7942 output_pending_init_elements (int all
, struct obstack
* braced_init_obstack
)
7944 struct init_node
*elt
= constructor_pending_elts
;
7949 /* Look through the whole pending tree.
7950 If we find an element that should be output now,
7951 output it. Otherwise, set NEXT to the element
7952 that comes first among those still pending. */
7957 if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
7959 if (tree_int_cst_equal (elt
->purpose
,
7960 constructor_unfilled_index
))
7961 output_init_element (elt
->value
, elt
->origtype
, true,
7962 TREE_TYPE (constructor_type
),
7963 constructor_unfilled_index
, 0, false,
7964 braced_init_obstack
);
7965 else if (tree_int_cst_lt (constructor_unfilled_index
,
7968 /* Advance to the next smaller node. */
7973 /* We have reached the smallest node bigger than the
7974 current unfilled index. Fill the space first. */
7975 next
= elt
->purpose
;
7981 /* Advance to the next bigger node. */
7986 /* We have reached the biggest node in a subtree. Find
7987 the parent of it, which is the next bigger node. */
7988 while (elt
->parent
&& elt
->parent
->right
== elt
)
7991 if (elt
&& tree_int_cst_lt (constructor_unfilled_index
,
7994 next
= elt
->purpose
;
8000 else if (TREE_CODE (constructor_type
) == RECORD_TYPE
8001 || TREE_CODE (constructor_type
) == UNION_TYPE
)
8003 tree ctor_unfilled_bitpos
, elt_bitpos
;
8005 /* If the current record is complete we are done. */
8006 if (constructor_unfilled_fields
== 0)
8009 ctor_unfilled_bitpos
= bit_position (constructor_unfilled_fields
);
8010 elt_bitpos
= bit_position (elt
->purpose
);
8011 /* We can't compare fields here because there might be empty
8012 fields in between. */
8013 if (tree_int_cst_equal (elt_bitpos
, ctor_unfilled_bitpos
))
8015 constructor_unfilled_fields
= elt
->purpose
;
8016 output_init_element (elt
->value
, elt
->origtype
, true,
8017 TREE_TYPE (elt
->purpose
),
8018 elt
->purpose
, 0, false,
8019 braced_init_obstack
);
8021 else if (tree_int_cst_lt (ctor_unfilled_bitpos
, elt_bitpos
))
8023 /* Advance to the next smaller node. */
8028 /* We have reached the smallest node bigger than the
8029 current unfilled field. Fill the space first. */
8030 next
= elt
->purpose
;
8036 /* Advance to the next bigger node. */
8041 /* We have reached the biggest node in a subtree. Find
8042 the parent of it, which is the next bigger node. */
8043 while (elt
->parent
&& elt
->parent
->right
== elt
)
8047 && (tree_int_cst_lt (ctor_unfilled_bitpos
,
8048 bit_position (elt
->purpose
))))
8050 next
= elt
->purpose
;
8058 /* Ordinarily return, but not if we want to output all
8059 and there are elements left. */
8060 if (!(all
&& next
!= 0))
8063 /* If it's not incremental, just skip over the gap, so that after
8064 jumping to retry we will output the next successive element. */
8065 if (TREE_CODE (constructor_type
) == RECORD_TYPE
8066 || TREE_CODE (constructor_type
) == UNION_TYPE
)
8067 constructor_unfilled_fields
= next
;
8068 else if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
8069 constructor_unfilled_index
= next
;
8071 /* ELT now points to the node in the pending tree with the next
8072 initializer to output. */
8076 /* Add one non-braced element to the current constructor level.
8077 This adjusts the current position within the constructor's type.
8078 This may also start or terminate implicit levels
8079 to handle a partly-braced initializer.
8081 Once this has found the correct level for the new element,
8082 it calls output_init_element.
8084 IMPLICIT is true if value comes from pop_init_level (1),
8085 the new initializer has been merged with the existing one
8086 and thus no warnings should be emitted about overriding an
8087 existing initializer. */
8090 process_init_element (struct c_expr value
, bool implicit
,
8091 struct obstack
* braced_init_obstack
)
8093 tree orig_value
= value
.value
;
8094 int string_flag
= orig_value
!= 0 && TREE_CODE (orig_value
) == STRING_CST
;
8095 bool strict_string
= value
.original_code
== STRING_CST
;
8097 designator_depth
= 0;
8098 designator_erroneous
= 0;
8100 /* Handle superfluous braces around string cst as in
8101 char x[] = {"foo"}; */
8104 && TREE_CODE (constructor_type
) == ARRAY_TYPE
8105 && INTEGRAL_TYPE_P (TREE_TYPE (constructor_type
))
8106 && integer_zerop (constructor_unfilled_index
))
8108 if (constructor_stack
->replacement_value
.value
)
8109 error_init ("excess elements in char array initializer");
8110 constructor_stack
->replacement_value
= value
;
8114 if (constructor_stack
->replacement_value
.value
!= 0)
8116 error_init ("excess elements in struct initializer");
8120 /* Ignore elements of a brace group if it is entirely superfluous
8121 and has already been diagnosed. */
8122 if (constructor_type
== 0)
8125 /* If we've exhausted any levels that didn't have braces,
8127 while (constructor_stack
->implicit
)
8129 if ((TREE_CODE (constructor_type
) == RECORD_TYPE
8130 || TREE_CODE (constructor_type
) == UNION_TYPE
)
8131 && constructor_fields
== 0)
8132 process_init_element (pop_init_level (1, braced_init_obstack
),
8133 true, braced_init_obstack
);
8134 else if ((TREE_CODE (constructor_type
) == ARRAY_TYPE
8135 || TREE_CODE (constructor_type
) == VECTOR_TYPE
)
8136 && constructor_max_index
8137 && tree_int_cst_lt (constructor_max_index
,
8139 process_init_element (pop_init_level (1, braced_init_obstack
),
8140 true, braced_init_obstack
);
8145 /* In the case of [LO ... HI] = VALUE, only evaluate VALUE once. */
8146 if (constructor_range_stack
)
8148 /* If value is a compound literal and we'll be just using its
8149 content, don't put it into a SAVE_EXPR. */
8150 if (TREE_CODE (value
.value
) != COMPOUND_LITERAL_EXPR
8151 || !require_constant_value
8154 tree semantic_type
= NULL_TREE
;
8155 if (TREE_CODE (value
.value
) == EXCESS_PRECISION_EXPR
)
8157 semantic_type
= TREE_TYPE (value
.value
);
8158 value
.value
= TREE_OPERAND (value
.value
, 0);
8160 value
.value
= c_save_expr (value
.value
);
8162 value
.value
= build1 (EXCESS_PRECISION_EXPR
, semantic_type
,
8169 if (TREE_CODE (constructor_type
) == RECORD_TYPE
)
8172 enum tree_code fieldcode
;
8174 if (constructor_fields
== 0)
8176 pedwarn_init (input_location
, 0,
8177 "excess elements in struct initializer");
8181 fieldtype
= TREE_TYPE (constructor_fields
);
8182 if (fieldtype
!= error_mark_node
)
8183 fieldtype
= TYPE_MAIN_VARIANT (fieldtype
);
8184 fieldcode
= TREE_CODE (fieldtype
);
8186 /* Error for non-static initialization of a flexible array member. */
8187 if (fieldcode
== ARRAY_TYPE
8188 && !require_constant_value
8189 && TYPE_SIZE (fieldtype
) == NULL_TREE
8190 && DECL_CHAIN (constructor_fields
) == NULL_TREE
)
8192 error_init ("non-static initialization of a flexible array member");
8196 /* Accept a string constant to initialize a subarray. */
8197 if (value
.value
!= 0
8198 && fieldcode
== ARRAY_TYPE
8199 && INTEGRAL_TYPE_P (TREE_TYPE (fieldtype
))
8201 value
.value
= orig_value
;
8202 /* Otherwise, if we have come to a subaggregate,
8203 and we don't have an element of its type, push into it. */
8204 else if (value
.value
!= 0
8205 && value
.value
!= error_mark_node
8206 && TYPE_MAIN_VARIANT (TREE_TYPE (value
.value
)) != fieldtype
8207 && (fieldcode
== RECORD_TYPE
|| fieldcode
== ARRAY_TYPE
8208 || fieldcode
== UNION_TYPE
|| fieldcode
== VECTOR_TYPE
))
8210 push_init_level (1, braced_init_obstack
);
8216 push_member_name (constructor_fields
);
8217 output_init_element (value
.value
, value
.original_type
,
8218 strict_string
, fieldtype
,
8219 constructor_fields
, 1, implicit
,
8220 braced_init_obstack
);
8221 RESTORE_SPELLING_DEPTH (constructor_depth
);
8224 /* Do the bookkeeping for an element that was
8225 directly output as a constructor. */
8227 /* For a record, keep track of end position of last field. */
8228 if (DECL_SIZE (constructor_fields
))
8229 constructor_bit_index
8230 = size_binop_loc (input_location
, PLUS_EXPR
,
8231 bit_position (constructor_fields
),
8232 DECL_SIZE (constructor_fields
));
8234 /* If the current field was the first one not yet written out,
8235 it isn't now, so update. */
8236 if (constructor_unfilled_fields
== constructor_fields
)
8238 constructor_unfilled_fields
= DECL_CHAIN (constructor_fields
);
8239 /* Skip any nameless bit fields. */
8240 while (constructor_unfilled_fields
!= 0
8241 && DECL_C_BIT_FIELD (constructor_unfilled_fields
)
8242 && DECL_NAME (constructor_unfilled_fields
) == 0)
8243 constructor_unfilled_fields
=
8244 DECL_CHAIN (constructor_unfilled_fields
);
8248 constructor_fields
= DECL_CHAIN (constructor_fields
);
8249 /* Skip any nameless bit fields at the beginning. */
8250 while (constructor_fields
!= 0
8251 && DECL_C_BIT_FIELD (constructor_fields
)
8252 && DECL_NAME (constructor_fields
) == 0)
8253 constructor_fields
= DECL_CHAIN (constructor_fields
);
8255 else if (TREE_CODE (constructor_type
) == UNION_TYPE
)
8258 enum tree_code fieldcode
;
8260 if (constructor_fields
== 0)
8262 pedwarn_init (input_location
, 0,
8263 "excess elements in union initializer");
8267 fieldtype
= TREE_TYPE (constructor_fields
);
8268 if (fieldtype
!= error_mark_node
)
8269 fieldtype
= TYPE_MAIN_VARIANT (fieldtype
);
8270 fieldcode
= TREE_CODE (fieldtype
);
8272 /* Warn that traditional C rejects initialization of unions.
8273 We skip the warning if the value is zero. This is done
8274 under the assumption that the zero initializer in user
8275 code appears conditioned on e.g. __STDC__ to avoid
8276 "missing initializer" warnings and relies on default
8277 initialization to zero in the traditional C case.
8278 We also skip the warning if the initializer is designated,
8279 again on the assumption that this must be conditional on
8280 __STDC__ anyway (and we've already complained about the
8281 member-designator already). */
8282 if (!in_system_header
&& !constructor_designated
8283 && !(value
.value
&& (integer_zerop (value
.value
)
8284 || real_zerop (value
.value
))))
8285 warning (OPT_Wtraditional
, "traditional C rejects initialization "
8288 /* Accept a string constant to initialize a subarray. */
8289 if (value
.value
!= 0
8290 && fieldcode
== ARRAY_TYPE
8291 && INTEGRAL_TYPE_P (TREE_TYPE (fieldtype
))
8293 value
.value
= orig_value
;
8294 /* Otherwise, if we have come to a subaggregate,
8295 and we don't have an element of its type, push into it. */
8296 else if (value
.value
!= 0
8297 && value
.value
!= error_mark_node
8298 && TYPE_MAIN_VARIANT (TREE_TYPE (value
.value
)) != fieldtype
8299 && (fieldcode
== RECORD_TYPE
|| fieldcode
== ARRAY_TYPE
8300 || fieldcode
== UNION_TYPE
|| fieldcode
== VECTOR_TYPE
))
8302 push_init_level (1, braced_init_obstack
);
8308 push_member_name (constructor_fields
);
8309 output_init_element (value
.value
, value
.original_type
,
8310 strict_string
, fieldtype
,
8311 constructor_fields
, 1, implicit
,
8312 braced_init_obstack
);
8313 RESTORE_SPELLING_DEPTH (constructor_depth
);
8316 /* Do the bookkeeping for an element that was
8317 directly output as a constructor. */
8319 constructor_bit_index
= DECL_SIZE (constructor_fields
);
8320 constructor_unfilled_fields
= DECL_CHAIN (constructor_fields
);
8323 constructor_fields
= 0;
8325 else if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
8327 tree elttype
= TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type
));
8328 enum tree_code eltcode
= TREE_CODE (elttype
);
8330 /* Accept a string constant to initialize a subarray. */
8331 if (value
.value
!= 0
8332 && eltcode
== ARRAY_TYPE
8333 && INTEGRAL_TYPE_P (TREE_TYPE (elttype
))
8335 value
.value
= orig_value
;
8336 /* Otherwise, if we have come to a subaggregate,
8337 and we don't have an element of its type, push into it. */
8338 else if (value
.value
!= 0
8339 && value
.value
!= error_mark_node
8340 && TYPE_MAIN_VARIANT (TREE_TYPE (value
.value
)) != elttype
8341 && (eltcode
== RECORD_TYPE
|| eltcode
== ARRAY_TYPE
8342 || eltcode
== UNION_TYPE
|| eltcode
== VECTOR_TYPE
))
8344 push_init_level (1, braced_init_obstack
);
8348 if (constructor_max_index
!= 0
8349 && (tree_int_cst_lt (constructor_max_index
, constructor_index
)
8350 || integer_all_onesp (constructor_max_index
)))
8352 pedwarn_init (input_location
, 0,
8353 "excess elements in array initializer");
8357 /* Now output the actual element. */
8360 push_array_bounds (tree_low_cst (constructor_index
, 1));
8361 output_init_element (value
.value
, value
.original_type
,
8362 strict_string
, elttype
,
8363 constructor_index
, 1, implicit
,
8364 braced_init_obstack
);
8365 RESTORE_SPELLING_DEPTH (constructor_depth
);
8369 = size_binop_loc (input_location
, PLUS_EXPR
,
8370 constructor_index
, bitsize_one_node
);
8373 /* If we are doing the bookkeeping for an element that was
8374 directly output as a constructor, we must update
8375 constructor_unfilled_index. */
8376 constructor_unfilled_index
= constructor_index
;
8378 else if (TREE_CODE (constructor_type
) == VECTOR_TYPE
)
8380 tree elttype
= TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type
));
8382 /* Do a basic check of initializer size. Note that vectors
8383 always have a fixed size derived from their type. */
8384 if (tree_int_cst_lt (constructor_max_index
, constructor_index
))
8386 pedwarn_init (input_location
, 0,
8387 "excess elements in vector initializer");
8391 /* Now output the actual element. */
8394 if (TREE_CODE (value
.value
) == VECTOR_CST
)
8395 elttype
= TYPE_MAIN_VARIANT (constructor_type
);
8396 output_init_element (value
.value
, value
.original_type
,
8397 strict_string
, elttype
,
8398 constructor_index
, 1, implicit
,
8399 braced_init_obstack
);
8403 = size_binop_loc (input_location
,
8404 PLUS_EXPR
, constructor_index
, bitsize_one_node
);
8407 /* If we are doing the bookkeeping for an element that was
8408 directly output as a constructor, we must update
8409 constructor_unfilled_index. */
8410 constructor_unfilled_index
= constructor_index
;
8413 /* Handle the sole element allowed in a braced initializer
8414 for a scalar variable. */
8415 else if (constructor_type
!= error_mark_node
8416 && constructor_fields
== 0)
8418 pedwarn_init (input_location
, 0,
8419 "excess elements in scalar initializer");
8425 output_init_element (value
.value
, value
.original_type
,
8426 strict_string
, constructor_type
,
8427 NULL_TREE
, 1, implicit
,
8428 braced_init_obstack
);
8429 constructor_fields
= 0;
8432 /* Handle range initializers either at this level or anywhere higher
8433 in the designator stack. */
8434 if (constructor_range_stack
)
8436 struct constructor_range_stack
*p
, *range_stack
;
8439 range_stack
= constructor_range_stack
;
8440 constructor_range_stack
= 0;
8441 while (constructor_stack
!= range_stack
->stack
)
8443 gcc_assert (constructor_stack
->implicit
);
8444 process_init_element (pop_init_level (1,
8445 braced_init_obstack
),
8446 true, braced_init_obstack
);
8448 for (p
= range_stack
;
8449 !p
->range_end
|| tree_int_cst_equal (p
->index
, p
->range_end
);
8452 gcc_assert (constructor_stack
->implicit
);
8453 process_init_element (pop_init_level (1, braced_init_obstack
),
8454 true, braced_init_obstack
);
8457 p
->index
= size_binop_loc (input_location
,
8458 PLUS_EXPR
, p
->index
, bitsize_one_node
);
8459 if (tree_int_cst_equal (p
->index
, p
->range_end
) && !p
->prev
)
8464 constructor_index
= p
->index
;
8465 constructor_fields
= p
->fields
;
8466 if (finish
&& p
->range_end
&& p
->index
== p
->range_start
)
8474 push_init_level (2, braced_init_obstack
);
8475 p
->stack
= constructor_stack
;
8476 if (p
->range_end
&& tree_int_cst_equal (p
->index
, p
->range_end
))
8477 p
->index
= p
->range_start
;
8481 constructor_range_stack
= range_stack
;
8488 constructor_range_stack
= 0;
8491 /* Build a complete asm-statement, whose components are a CV_QUALIFIER
8492 (guaranteed to be 'volatile' or null) and ARGS (represented using
8493 an ASM_EXPR node). */
8495 build_asm_stmt (tree cv_qualifier
, tree args
)
8497 if (!ASM_VOLATILE_P (args
) && cv_qualifier
)
8498 ASM_VOLATILE_P (args
) = 1;
8499 return add_stmt (args
);
8502 /* Build an asm-expr, whose components are a STRING, some OUTPUTS,
8503 some INPUTS, and some CLOBBERS. The latter three may be NULL.
8504 SIMPLE indicates whether there was anything at all after the
8505 string in the asm expression -- asm("blah") and asm("blah" : )
8506 are subtly different. We use a ASM_EXPR node to represent this. */
8508 build_asm_expr (location_t loc
, tree string
, tree outputs
, tree inputs
,
8509 tree clobbers
, tree labels
, bool simple
)
8514 const char *constraint
;
8515 const char **oconstraints
;
8516 bool allows_mem
, allows_reg
, is_inout
;
8517 int ninputs
, noutputs
;
8519 ninputs
= list_length (inputs
);
8520 noutputs
= list_length (outputs
);
8521 oconstraints
= (const char **) alloca (noutputs
* sizeof (const char *));
8523 string
= resolve_asm_operand_names (string
, outputs
, inputs
, labels
);
8525 /* Remove output conversions that change the type but not the mode. */
8526 for (i
= 0, tail
= outputs
; tail
; ++i
, tail
= TREE_CHAIN (tail
))
8528 tree output
= TREE_VALUE (tail
);
8530 output
= c_fully_fold (output
, false, NULL
);
8532 /* ??? Really, this should not be here. Users should be using a
8533 proper lvalue, dammit. But there's a long history of using casts
8534 in the output operands. In cases like longlong.h, this becomes a
8535 primitive form of typechecking -- if the cast can be removed, then
8536 the output operand had a type of the proper width; otherwise we'll
8537 get an error. Gross, but ... */
8538 STRIP_NOPS (output
);
8540 if (!lvalue_or_else (loc
, output
, lv_asm
))
8541 output
= error_mark_node
;
8543 if (output
!= error_mark_node
8544 && (TREE_READONLY (output
)
8545 || TYPE_READONLY (TREE_TYPE (output
))
8546 || ((TREE_CODE (TREE_TYPE (output
)) == RECORD_TYPE
8547 || TREE_CODE (TREE_TYPE (output
)) == UNION_TYPE
)
8548 && C_TYPE_FIELDS_READONLY (TREE_TYPE (output
)))))
8549 readonly_error (output
, lv_asm
);
8551 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (tail
)));
8552 oconstraints
[i
] = constraint
;
8554 if (parse_output_constraint (&constraint
, i
, ninputs
, noutputs
,
8555 &allows_mem
, &allows_reg
, &is_inout
))
8557 /* If the operand is going to end up in memory,
8558 mark it addressable. */
8559 if (!allows_reg
&& !c_mark_addressable (output
))
8560 output
= error_mark_node
;
8561 if (!(!allows_reg
&& allows_mem
)
8562 && output
!= error_mark_node
8563 && VOID_TYPE_P (TREE_TYPE (output
)))
8565 error_at (loc
, "invalid use of void expression");
8566 output
= error_mark_node
;
8570 output
= error_mark_node
;
8572 TREE_VALUE (tail
) = output
;
8575 for (i
= 0, tail
= inputs
; tail
; ++i
, tail
= TREE_CHAIN (tail
))
8579 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (tail
)));
8580 input
= TREE_VALUE (tail
);
8582 if (parse_input_constraint (&constraint
, i
, ninputs
, noutputs
, 0,
8583 oconstraints
, &allows_mem
, &allows_reg
))
8585 /* If the operand is going to end up in memory,
8586 mark it addressable. */
8587 if (!allows_reg
&& allows_mem
)
8589 input
= c_fully_fold (input
, false, NULL
);
8591 /* Strip the nops as we allow this case. FIXME, this really
8592 should be rejected or made deprecated. */
8594 if (!c_mark_addressable (input
))
8595 input
= error_mark_node
;
8600 memset (&expr
, 0, sizeof (expr
));
8602 expr
= default_function_array_conversion (loc
, expr
);
8603 input
= c_fully_fold (expr
.value
, false, NULL
);
8605 if (input
!= error_mark_node
&& VOID_TYPE_P (TREE_TYPE (input
)))
8607 error_at (loc
, "invalid use of void expression");
8608 input
= error_mark_node
;
8613 input
= error_mark_node
;
8615 TREE_VALUE (tail
) = input
;
8618 /* ASMs with labels cannot have outputs. This should have been
8619 enforced by the parser. */
8620 gcc_assert (outputs
== NULL
|| labels
== NULL
);
8622 args
= build_stmt (loc
, ASM_EXPR
, string
, outputs
, inputs
, clobbers
, labels
);
8624 /* asm statements without outputs, including simple ones, are treated
8626 ASM_INPUT_P (args
) = simple
;
8627 ASM_VOLATILE_P (args
) = (noutputs
== 0);
8632 /* Generate a goto statement to LABEL. LOC is the location of the
8636 c_finish_goto_label (location_t loc
, tree label
)
8638 tree decl
= lookup_label_for_goto (loc
, label
);
8641 TREE_USED (decl
) = 1;
8643 tree t
= build1 (GOTO_EXPR
, void_type_node
, decl
);
8644 SET_EXPR_LOCATION (t
, loc
);
8645 return add_stmt (t
);
8649 /* Generate a computed goto statement to EXPR. LOC is the location of
8653 c_finish_goto_ptr (location_t loc
, tree expr
)
8656 pedwarn (loc
, OPT_Wpedantic
, "ISO C forbids %<goto *expr;%>");
8657 expr
= c_fully_fold (expr
, false, NULL
);
8658 expr
= convert (ptr_type_node
, expr
);
8659 t
= build1 (GOTO_EXPR
, void_type_node
, expr
);
8660 SET_EXPR_LOCATION (t
, loc
);
8661 return add_stmt (t
);
8664 /* Generate a C `return' statement. RETVAL is the expression for what
8665 to return, or a null pointer for `return;' with no value. LOC is
8666 the location of the return statement. If ORIGTYPE is not NULL_TREE, it
8667 is the original type of RETVAL. */
8670 c_finish_return (location_t loc
, tree retval
, tree origtype
)
8672 tree valtype
= TREE_TYPE (TREE_TYPE (current_function_decl
)), ret_stmt
;
8673 bool no_warning
= false;
8677 if (TREE_THIS_VOLATILE (current_function_decl
))
8679 "function declared %<noreturn%> has a %<return%> statement");
8681 if (flag_enable_cilkplus
&& contains_array_notation_expr (retval
))
8683 /* Array notations are allowed in a return statement if it is inside a
8684 built-in array notation reduction function. */
8685 if (!find_rank (loc
, retval
, retval
, false, &rank
))
8686 return error_mark_node
;
8689 error_at (loc
, "array notation expression cannot be used as a "
8691 return error_mark_node
;
8696 tree semantic_type
= NULL_TREE
;
8697 npc
= null_pointer_constant_p (retval
);
8698 if (TREE_CODE (retval
) == EXCESS_PRECISION_EXPR
)
8700 semantic_type
= TREE_TYPE (retval
);
8701 retval
= TREE_OPERAND (retval
, 0);
8703 retval
= c_fully_fold (retval
, false, NULL
);
8705 retval
= build1 (EXCESS_PRECISION_EXPR
, semantic_type
, retval
);
8710 current_function_returns_null
= 1;
8711 if ((warn_return_type
|| flag_isoc99
)
8712 && valtype
!= 0 && TREE_CODE (valtype
) != VOID_TYPE
)
8714 pedwarn_c99 (loc
, flag_isoc99
? 0 : OPT_Wreturn_type
,
8715 "%<return%> with no value, in "
8716 "function returning non-void");
8720 else if (valtype
== 0 || TREE_CODE (valtype
) == VOID_TYPE
)
8722 current_function_returns_null
= 1;
8723 if (TREE_CODE (TREE_TYPE (retval
)) != VOID_TYPE
)
8725 "%<return%> with a value, in function returning void");
8727 pedwarn (loc
, OPT_Wpedantic
, "ISO C forbids "
8728 "%<return%> with expression, in function returning void");
8732 tree t
= convert_for_assignment (loc
, valtype
, retval
, origtype
,
8734 npc
, NULL_TREE
, NULL_TREE
, 0);
8735 tree res
= DECL_RESULT (current_function_decl
);
8739 current_function_returns_value
= 1;
8740 if (t
== error_mark_node
)
8743 save
= in_late_binary_op
;
8744 if (TREE_CODE (TREE_TYPE (res
)) == BOOLEAN_TYPE
8745 || TREE_CODE (TREE_TYPE (res
)) == COMPLEX_TYPE
)
8746 in_late_binary_op
= true;
8747 inner
= t
= convert (TREE_TYPE (res
), t
);
8748 in_late_binary_op
= save
;
8750 /* Strip any conversions, additions, and subtractions, and see if
8751 we are returning the address of a local variable. Warn if so. */
8754 switch (TREE_CODE (inner
))
8757 case NON_LVALUE_EXPR
:
8759 case POINTER_PLUS_EXPR
:
8760 inner
= TREE_OPERAND (inner
, 0);
8764 /* If the second operand of the MINUS_EXPR has a pointer
8765 type (or is converted from it), this may be valid, so
8766 don't give a warning. */
8768 tree op1
= TREE_OPERAND (inner
, 1);
8770 while (!POINTER_TYPE_P (TREE_TYPE (op1
))
8771 && (CONVERT_EXPR_P (op1
)
8772 || TREE_CODE (op1
) == NON_LVALUE_EXPR
))
8773 op1
= TREE_OPERAND (op1
, 0);
8775 if (POINTER_TYPE_P (TREE_TYPE (op1
)))
8778 inner
= TREE_OPERAND (inner
, 0);
8783 inner
= TREE_OPERAND (inner
, 0);
8785 while (REFERENCE_CLASS_P (inner
)
8786 && TREE_CODE (inner
) != INDIRECT_REF
)
8787 inner
= TREE_OPERAND (inner
, 0);
8790 && !DECL_EXTERNAL (inner
)
8791 && !TREE_STATIC (inner
)
8792 && DECL_CONTEXT (inner
) == current_function_decl
)
8794 OPT_Wreturn_local_addr
, "function returns address "
8795 "of local variable");
8805 retval
= build2 (MODIFY_EXPR
, TREE_TYPE (res
), res
, t
);
8806 SET_EXPR_LOCATION (retval
, loc
);
8808 if (warn_sequence_point
)
8809 verify_sequence_points (retval
);
8812 ret_stmt
= build_stmt (loc
, RETURN_EXPR
, retval
);
8813 TREE_NO_WARNING (ret_stmt
) |= no_warning
;
8814 return add_stmt (ret_stmt
);
8818 /* The SWITCH_EXPR being built. */
8821 /* The original type of the testing expression, i.e. before the
8822 default conversion is applied. */
8825 /* A splay-tree mapping the low element of a case range to the high
8826 element, or NULL_TREE if there is no high element. Used to
8827 determine whether or not a new case label duplicates an old case
8828 label. We need a tree, rather than simply a hash table, because
8829 of the GNU case range extension. */
8832 /* The bindings at the point of the switch. This is used for
8833 warnings crossing decls when branching to a case label. */
8834 struct c_spot_bindings
*bindings
;
8836 /* The next node on the stack. */
8837 struct c_switch
*next
;
8840 /* A stack of the currently active switch statements. The innermost
8841 switch statement is on the top of the stack. There is no need to
8842 mark the stack for garbage collection because it is only active
8843 during the processing of the body of a function, and we never
8844 collect at that point. */
8846 struct c_switch
*c_switch_stack
;
8848 /* Start a C switch statement, testing expression EXP. Return the new
8849 SWITCH_EXPR. SWITCH_LOC is the location of the `switch'.
8850 SWITCH_COND_LOC is the location of the switch's condition. */
8853 c_start_case (location_t switch_loc
,
8854 location_t switch_cond_loc
,
8857 tree orig_type
= error_mark_node
;
8858 struct c_switch
*cs
;
8860 if (exp
!= error_mark_node
)
8862 orig_type
= TREE_TYPE (exp
);
8864 if (!INTEGRAL_TYPE_P (orig_type
))
8866 if (orig_type
!= error_mark_node
)
8868 error_at (switch_cond_loc
, "switch quantity not an integer");
8869 orig_type
= error_mark_node
;
8871 exp
= integer_zero_node
;
8875 tree type
= TYPE_MAIN_VARIANT (orig_type
);
8877 if (!in_system_header
8878 && (type
== long_integer_type_node
8879 || type
== long_unsigned_type_node
))
8880 warning_at (switch_cond_loc
,
8881 OPT_Wtraditional
, "%<long%> switch expression not "
8882 "converted to %<int%> in ISO C");
8884 exp
= c_fully_fold (exp
, false, NULL
);
8885 exp
= default_conversion (exp
);
8887 if (warn_sequence_point
)
8888 verify_sequence_points (exp
);
8892 /* Add this new SWITCH_EXPR to the stack. */
8893 cs
= XNEW (struct c_switch
);
8894 cs
->switch_expr
= build3 (SWITCH_EXPR
, orig_type
, exp
, NULL_TREE
, NULL_TREE
);
8895 SET_EXPR_LOCATION (cs
->switch_expr
, switch_loc
);
8896 cs
->orig_type
= orig_type
;
8897 cs
->cases
= splay_tree_new (case_compare
, NULL
, NULL
);
8898 cs
->bindings
= c_get_switch_bindings ();
8899 cs
->next
= c_switch_stack
;
8900 c_switch_stack
= cs
;
8902 return add_stmt (cs
->switch_expr
);
8905 /* Process a case label at location LOC. */
8908 do_case (location_t loc
, tree low_value
, tree high_value
)
8910 tree label
= NULL_TREE
;
8912 if (low_value
&& TREE_CODE (low_value
) != INTEGER_CST
)
8914 low_value
= c_fully_fold (low_value
, false, NULL
);
8915 if (TREE_CODE (low_value
) == INTEGER_CST
)
8916 pedwarn (input_location
, OPT_Wpedantic
,
8917 "case label is not an integer constant expression");
8920 if (high_value
&& TREE_CODE (high_value
) != INTEGER_CST
)
8922 high_value
= c_fully_fold (high_value
, false, NULL
);
8923 if (TREE_CODE (high_value
) == INTEGER_CST
)
8924 pedwarn (input_location
, OPT_Wpedantic
,
8925 "case label is not an integer constant expression");
8928 if (c_switch_stack
== NULL
)
8931 error_at (loc
, "case label not within a switch statement");
8933 error_at (loc
, "%<default%> label not within a switch statement");
8937 if (c_check_switch_jump_warnings (c_switch_stack
->bindings
,
8938 EXPR_LOCATION (c_switch_stack
->switch_expr
),
8942 label
= c_add_case_label (loc
, c_switch_stack
->cases
,
8943 SWITCH_COND (c_switch_stack
->switch_expr
),
8944 c_switch_stack
->orig_type
,
8945 low_value
, high_value
);
8946 if (label
== error_mark_node
)
8951 /* Finish the switch statement. */
8954 c_finish_case (tree body
)
8956 struct c_switch
*cs
= c_switch_stack
;
8957 location_t switch_location
;
8959 SWITCH_BODY (cs
->switch_expr
) = body
;
8961 /* Emit warnings as needed. */
8962 switch_location
= EXPR_LOCATION (cs
->switch_expr
);
8963 c_do_switch_warnings (cs
->cases
, switch_location
,
8964 TREE_TYPE (cs
->switch_expr
),
8965 SWITCH_COND (cs
->switch_expr
));
8967 /* Pop the stack. */
8968 c_switch_stack
= cs
->next
;
8969 splay_tree_delete (cs
->cases
);
8970 c_release_switch_bindings (cs
->bindings
);
8974 /* Emit an if statement. IF_LOCUS is the location of the 'if'. COND,
8975 THEN_BLOCK and ELSE_BLOCK are expressions to be used; ELSE_BLOCK
8976 may be null. NESTED_IF is true if THEN_BLOCK contains another IF
8977 statement, and was not surrounded with parenthesis. */
8980 c_finish_if_stmt (location_t if_locus
, tree cond
, tree then_block
,
8981 tree else_block
, bool nested_if
)
8985 /* If the condition has array notations, then the rank of the then_block and
8986 else_block must be either 0 or be equal to the rank of the condition. If
8987 the condition does not have array notations then break them up as it is
8988 broken up in a normal expression. */
8989 if (flag_enable_cilkplus
&& contains_array_notation_expr (cond
))
8991 size_t then_rank
= 0, cond_rank
= 0, else_rank
= 0;
8992 if (!find_rank (if_locus
, cond
, cond
, true, &cond_rank
))
8995 && !find_rank (if_locus
, then_block
, then_block
, true, &then_rank
))
8998 && !find_rank (if_locus
, else_block
, else_block
, true, &else_rank
))
9000 if (cond_rank
!= then_rank
&& then_rank
!= 0)
9002 error_at (if_locus
, "rank-mismatch between if-statement%'s condition"
9003 " and the then-block");
9006 else if (cond_rank
!= else_rank
&& else_rank
!= 0)
9008 error_at (if_locus
, "rank-mismatch between if-statement%'s condition"
9009 " and the else-block");
9013 /* Diagnose an ambiguous else if if-then-else is nested inside if-then. */
9014 if (warn_parentheses
&& nested_if
&& else_block
== NULL
)
9016 tree inner_if
= then_block
;
9018 /* We know from the grammar productions that there is an IF nested
9019 within THEN_BLOCK. Due to labels and c99 conditional declarations,
9020 it might not be exactly THEN_BLOCK, but should be the last
9021 non-container statement within. */
9023 switch (TREE_CODE (inner_if
))
9028 inner_if
= BIND_EXPR_BODY (inner_if
);
9030 case STATEMENT_LIST
:
9031 inner_if
= expr_last (then_block
);
9033 case TRY_FINALLY_EXPR
:
9034 case TRY_CATCH_EXPR
:
9035 inner_if
= TREE_OPERAND (inner_if
, 0);
9042 if (COND_EXPR_ELSE (inner_if
))
9043 warning_at (if_locus
, OPT_Wparentheses
,
9044 "suggest explicit braces to avoid ambiguous %<else%>");
9047 stmt
= build3 (COND_EXPR
, void_type_node
, cond
, then_block
, else_block
);
9048 SET_EXPR_LOCATION (stmt
, if_locus
);
9052 /* Emit a general-purpose loop construct. START_LOCUS is the location of
9053 the beginning of the loop. COND is the loop condition. COND_IS_FIRST
9054 is false for DO loops. INCR is the FOR increment expression. BODY is
9055 the statement controlled by the loop. BLAB is the break label. CLAB is
9056 the continue label. Everything is allowed to be NULL. */
9059 c_finish_loop (location_t start_locus
, tree cond
, tree incr
, tree body
,
9060 tree blab
, tree clab
, bool cond_is_first
)
9062 tree entry
= NULL
, exit
= NULL
, t
;
9064 if (flag_enable_cilkplus
&& contains_array_notation_expr (cond
))
9066 error_at (start_locus
, "array notation expression cannot be used in a "
9067 "loop%'s condition");
9071 /* If the condition is zero don't generate a loop construct. */
9072 if (cond
&& integer_zerop (cond
))
9076 t
= build_and_jump (&blab
);
9077 SET_EXPR_LOCATION (t
, start_locus
);
9083 tree top
= build1 (LABEL_EXPR
, void_type_node
, NULL_TREE
);
9085 /* If we have an exit condition, then we build an IF with gotos either
9086 out of the loop, or to the top of it. If there's no exit condition,
9087 then we just build a jump back to the top. */
9088 exit
= build_and_jump (&LABEL_EXPR_LABEL (top
));
9090 if (cond
&& !integer_nonzerop (cond
))
9092 /* Canonicalize the loop condition to the end. This means
9093 generating a branch to the loop condition. Reuse the
9094 continue label, if possible. */
9099 entry
= build1 (LABEL_EXPR
, void_type_node
, NULL_TREE
);
9100 t
= build_and_jump (&LABEL_EXPR_LABEL (entry
));
9103 t
= build1 (GOTO_EXPR
, void_type_node
, clab
);
9104 SET_EXPR_LOCATION (t
, start_locus
);
9108 t
= build_and_jump (&blab
);
9110 exit
= fold_build3_loc (start_locus
,
9111 COND_EXPR
, void_type_node
, cond
, exit
, t
);
9113 exit
= fold_build3_loc (input_location
,
9114 COND_EXPR
, void_type_node
, cond
, exit
, t
);
9123 add_stmt (build1 (LABEL_EXPR
, void_type_node
, clab
));
9131 add_stmt (build1 (LABEL_EXPR
, void_type_node
, blab
));
9135 c_finish_bc_stmt (location_t loc
, tree
*label_p
, bool is_break
)
9138 tree label
= *label_p
;
9140 /* In switch statements break is sometimes stylistically used after
9141 a return statement. This can lead to spurious warnings about
9142 control reaching the end of a non-void function when it is
9143 inlined. Note that we are calling block_may_fallthru with
9144 language specific tree nodes; this works because
9145 block_may_fallthru returns true when given something it does not
9147 skip
= !block_may_fallthru (cur_stmt_list
);
9152 *label_p
= label
= create_artificial_label (loc
);
9154 else if (TREE_CODE (label
) == LABEL_DECL
)
9156 else switch (TREE_INT_CST_LOW (label
))
9160 error_at (loc
, "break statement not within loop or switch");
9162 error_at (loc
, "continue statement not within a loop");
9166 gcc_assert (is_break
);
9167 error_at (loc
, "break statement used with OpenMP for loop");
9178 add_stmt (build_predict_expr (PRED_CONTINUE
, NOT_TAKEN
));
9180 return add_stmt (build1 (GOTO_EXPR
, void_type_node
, label
));
9183 /* A helper routine for c_process_expr_stmt and c_finish_stmt_expr. */
9186 emit_side_effect_warnings (location_t loc
, tree expr
)
9188 if (expr
== error_mark_node
)
9190 else if (!TREE_SIDE_EFFECTS (expr
))
9192 if (!VOID_TYPE_P (TREE_TYPE (expr
)) && !TREE_NO_WARNING (expr
))
9193 warning_at (loc
, OPT_Wunused_value
, "statement with no effect");
9196 warn_if_unused_value (expr
, loc
);
9199 /* Process an expression as if it were a complete statement. Emit
9200 diagnostics, but do not call ADD_STMT. LOC is the location of the
9204 c_process_expr_stmt (location_t loc
, tree expr
)
9211 expr
= c_fully_fold (expr
, false, NULL
);
9213 if (warn_sequence_point
)
9214 verify_sequence_points (expr
);
9216 if (TREE_TYPE (expr
) != error_mark_node
9217 && !COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (expr
))
9218 && TREE_CODE (TREE_TYPE (expr
)) != ARRAY_TYPE
)
9219 error_at (loc
, "expression statement has incomplete type");
9221 /* If we're not processing a statement expression, warn about unused values.
9222 Warnings for statement expressions will be emitted later, once we figure
9223 out which is the result. */
9224 if (!STATEMENT_LIST_STMT_EXPR (cur_stmt_list
)
9225 && warn_unused_value
)
9226 emit_side_effect_warnings (loc
, expr
);
9229 while (TREE_CODE (exprv
) == COMPOUND_EXPR
)
9230 exprv
= TREE_OPERAND (exprv
, 1);
9231 while (CONVERT_EXPR_P (exprv
))
9232 exprv
= TREE_OPERAND (exprv
, 0);
9234 || handled_component_p (exprv
)
9235 || TREE_CODE (exprv
) == ADDR_EXPR
)
9236 mark_exp_read (exprv
);
9238 /* If the expression is not of a type to which we cannot assign a line
9239 number, wrap the thing in a no-op NOP_EXPR. */
9240 if (DECL_P (expr
) || CONSTANT_CLASS_P (expr
))
9242 expr
= build1 (NOP_EXPR
, TREE_TYPE (expr
), expr
);
9243 SET_EXPR_LOCATION (expr
, loc
);
9249 /* Emit an expression as a statement. LOC is the location of the
9253 c_finish_expr_stmt (location_t loc
, tree expr
)
9256 return add_stmt (c_process_expr_stmt (loc
, expr
));
9261 /* Do the opposite and emit a statement as an expression. To begin,
9262 create a new binding level and return it. */
9265 c_begin_stmt_expr (void)
9269 /* We must force a BLOCK for this level so that, if it is not expanded
9270 later, there is a way to turn off the entire subtree of blocks that
9271 are contained in it. */
9273 ret
= c_begin_compound_stmt (true);
9275 c_bindings_start_stmt_expr (c_switch_stack
== NULL
9277 : c_switch_stack
->bindings
);
9279 /* Mark the current statement list as belonging to a statement list. */
9280 STATEMENT_LIST_STMT_EXPR (ret
) = 1;
9285 /* LOC is the location of the compound statement to which this body
9289 c_finish_stmt_expr (location_t loc
, tree body
)
9291 tree last
, type
, tmp
, val
;
9294 body
= c_end_compound_stmt (loc
, body
, true);
9296 c_bindings_end_stmt_expr (c_switch_stack
== NULL
9298 : c_switch_stack
->bindings
);
9300 /* Locate the last statement in BODY. See c_end_compound_stmt
9301 about always returning a BIND_EXPR. */
9302 last_p
= &BIND_EXPR_BODY (body
);
9303 last
= BIND_EXPR_BODY (body
);
9306 if (TREE_CODE (last
) == STATEMENT_LIST
)
9308 tree_stmt_iterator i
;
9310 /* This can happen with degenerate cases like ({ }). No value. */
9311 if (!TREE_SIDE_EFFECTS (last
))
9314 /* If we're supposed to generate side effects warnings, process
9315 all of the statements except the last. */
9316 if (warn_unused_value
)
9318 for (i
= tsi_start (last
); !tsi_one_before_end_p (i
); tsi_next (&i
))
9321 tree t
= tsi_stmt (i
);
9323 tloc
= EXPR_HAS_LOCATION (t
) ? EXPR_LOCATION (t
) : loc
;
9324 emit_side_effect_warnings (tloc
, t
);
9328 i
= tsi_last (last
);
9329 last_p
= tsi_stmt_ptr (i
);
9333 /* If the end of the list is exception related, then the list was split
9334 by a call to push_cleanup. Continue searching. */
9335 if (TREE_CODE (last
) == TRY_FINALLY_EXPR
9336 || TREE_CODE (last
) == TRY_CATCH_EXPR
)
9338 last_p
= &TREE_OPERAND (last
, 0);
9340 goto continue_searching
;
9343 if (last
== error_mark_node
)
9346 /* In the case that the BIND_EXPR is not necessary, return the
9347 expression out from inside it. */
9348 if (last
== BIND_EXPR_BODY (body
)
9349 && BIND_EXPR_VARS (body
) == NULL
)
9351 /* Even if this looks constant, do not allow it in a constant
9353 last
= c_wrap_maybe_const (last
, true);
9354 /* Do not warn if the return value of a statement expression is
9356 TREE_NO_WARNING (last
) = 1;
9360 /* Extract the type of said expression. */
9361 type
= TREE_TYPE (last
);
9363 /* If we're not returning a value at all, then the BIND_EXPR that
9364 we already have is a fine expression to return. */
9365 if (!type
|| VOID_TYPE_P (type
))
9368 /* Now that we've located the expression containing the value, it seems
9369 silly to make voidify_wrapper_expr repeat the process. Create a
9370 temporary of the appropriate type and stick it in a TARGET_EXPR. */
9371 tmp
= create_tmp_var_raw (type
, NULL
);
9373 /* Unwrap a no-op NOP_EXPR as added by c_finish_expr_stmt. This avoids
9374 tree_expr_nonnegative_p giving up immediately. */
9376 if (TREE_CODE (val
) == NOP_EXPR
9377 && TREE_TYPE (val
) == TREE_TYPE (TREE_OPERAND (val
, 0)))
9378 val
= TREE_OPERAND (val
, 0);
9380 *last_p
= build2 (MODIFY_EXPR
, void_type_node
, tmp
, val
);
9381 SET_EXPR_LOCATION (*last_p
, EXPR_LOCATION (last
));
9384 tree t
= build4 (TARGET_EXPR
, type
, tmp
, body
, NULL_TREE
, NULL_TREE
);
9385 SET_EXPR_LOCATION (t
, loc
);
9390 /* Begin and end compound statements. This is as simple as pushing
9391 and popping new statement lists from the tree. */
9394 c_begin_compound_stmt (bool do_scope
)
9396 tree stmt
= push_stmt_list ();
9402 /* End a compound statement. STMT is the statement. LOC is the
9403 location of the compound statement-- this is usually the location
9404 of the opening brace. */
9407 c_end_compound_stmt (location_t loc
, tree stmt
, bool do_scope
)
9413 if (c_dialect_objc ())
9414 objc_clear_super_receiver ();
9415 block
= pop_scope ();
9418 stmt
= pop_stmt_list (stmt
);
9419 stmt
= c_build_bind_expr (loc
, block
, stmt
);
9421 /* If this compound statement is nested immediately inside a statement
9422 expression, then force a BIND_EXPR to be created. Otherwise we'll
9423 do the wrong thing for ({ { 1; } }) or ({ 1; { } }). In particular,
9424 STATEMENT_LISTs merge, and thus we can lose track of what statement
9426 if (building_stmt_list_p ()
9427 && STATEMENT_LIST_STMT_EXPR (cur_stmt_list
)
9428 && TREE_CODE (stmt
) != BIND_EXPR
)
9430 stmt
= build3 (BIND_EXPR
, void_type_node
, NULL
, stmt
, NULL
);
9431 TREE_SIDE_EFFECTS (stmt
) = 1;
9432 SET_EXPR_LOCATION (stmt
, loc
);
9438 /* Queue a cleanup. CLEANUP is an expression/statement to be executed
9439 when the current scope is exited. EH_ONLY is true when this is not
9440 meant to apply to normal control flow transfer. */
9443 push_cleanup (tree decl
, tree cleanup
, bool eh_only
)
9445 enum tree_code code
;
9449 code
= eh_only
? TRY_CATCH_EXPR
: TRY_FINALLY_EXPR
;
9450 stmt
= build_stmt (DECL_SOURCE_LOCATION (decl
), code
, NULL
, cleanup
);
9452 stmt_expr
= STATEMENT_LIST_STMT_EXPR (cur_stmt_list
);
9453 list
= push_stmt_list ();
9454 TREE_OPERAND (stmt
, 0) = list
;
9455 STATEMENT_LIST_STMT_EXPR (list
) = stmt_expr
;
9458 /* Build a binary-operation expression without default conversions.
9459 CODE is the kind of expression to build.
9460 LOCATION is the operator's location.
9461 This function differs from `build' in several ways:
9462 the data type of the result is computed and recorded in it,
9463 warnings are generated if arg data types are invalid,
9464 special handling for addition and subtraction of pointers is known,
9465 and some optimization is done (operations on narrow ints
9466 are done in the narrower type when that gives the same result).
9467 Constant folding is also done before the result is returned.
9469 Note that the operands will never have enumeral types, or function
9470 or array types, because either they will have the default conversions
9471 performed or they have both just been converted to some other type in which
9472 the arithmetic is to be done. */
9475 build_binary_op (location_t location
, enum tree_code code
,
9476 tree orig_op0
, tree orig_op1
, int convert_p
)
9478 tree type0
, type1
, orig_type0
, orig_type1
;
9480 enum tree_code code0
, code1
;
9482 tree ret
= error_mark_node
;
9483 const char *invalid_op_diag
;
9484 bool op0_int_operands
, op1_int_operands
;
9485 bool int_const
, int_const_or_overflow
, int_operands
;
9487 /* Expression code to give to the expression when it is built.
9488 Normally this is CODE, which is what the caller asked for,
9489 but in some special cases we change it. */
9490 enum tree_code resultcode
= code
;
9492 /* Data type in which the computation is to be performed.
9493 In the simplest cases this is the common type of the arguments. */
9494 tree result_type
= NULL
;
9496 /* When the computation is in excess precision, the type of the
9497 final EXCESS_PRECISION_EXPR. */
9498 tree semantic_result_type
= NULL
;
9500 /* Nonzero means operands have already been type-converted
9501 in whatever way is necessary.
9502 Zero means they need to be converted to RESULT_TYPE. */
9505 /* Nonzero means create the expression with this type, rather than
9507 tree build_type
= 0;
9509 /* Nonzero means after finally constructing the expression
9510 convert it to this type. */
9511 tree final_type
= 0;
9513 /* Nonzero if this is an operation like MIN or MAX which can
9514 safely be computed in short if both args are promoted shorts.
9515 Also implies COMMON.
9516 -1 indicates a bitwise operation; this makes a difference
9517 in the exact conditions for when it is safe to do the operation
9518 in a narrower mode. */
9521 /* Nonzero if this is a comparison operation;
9522 if both args are promoted shorts, compare the original shorts.
9523 Also implies COMMON. */
9524 int short_compare
= 0;
9526 /* Nonzero if this is a right-shift operation, which can be computed on the
9527 original short and then promoted if the operand is a promoted short. */
9528 int short_shift
= 0;
9530 /* Nonzero means set RESULT_TYPE to the common type of the args. */
9533 /* True means types are compatible as far as ObjC is concerned. */
9536 /* True means this is an arithmetic operation that may need excess
9538 bool may_need_excess_precision
;
9540 /* True means this is a boolean operation that converts both its
9541 operands to truth-values. */
9542 bool boolean_op
= false;
9544 if (location
== UNKNOWN_LOCATION
)
9545 location
= input_location
;
9550 op0_int_operands
= EXPR_INT_CONST_OPERANDS (orig_op0
);
9551 if (op0_int_operands
)
9552 op0
= remove_c_maybe_const_expr (op0
);
9553 op1_int_operands
= EXPR_INT_CONST_OPERANDS (orig_op1
);
9554 if (op1_int_operands
)
9555 op1
= remove_c_maybe_const_expr (op1
);
9556 int_operands
= (op0_int_operands
&& op1_int_operands
);
9559 int_const_or_overflow
= (TREE_CODE (orig_op0
) == INTEGER_CST
9560 && TREE_CODE (orig_op1
) == INTEGER_CST
);
9561 int_const
= (int_const_or_overflow
9562 && !TREE_OVERFLOW (orig_op0
)
9563 && !TREE_OVERFLOW (orig_op1
));
9566 int_const
= int_const_or_overflow
= false;
9568 /* Do not apply default conversion in mixed vector/scalar expression. */
9570 && !((TREE_CODE (TREE_TYPE (op0
)) == VECTOR_TYPE
)
9571 != (TREE_CODE (TREE_TYPE (op1
)) == VECTOR_TYPE
)))
9573 op0
= default_conversion (op0
);
9574 op1
= default_conversion (op1
);
9577 /* When Cilk Plus is enabled and there are array notations inside op0, then
9578 we check to see if there are builtin array notation functions. If
9579 so, then we take on the type of the array notation inside it. */
9580 if (flag_enable_cilkplus
&& contains_array_notation_expr (op0
))
9581 orig_type0
= type0
= find_correct_array_notation_type (op0
);
9583 orig_type0
= type0
= TREE_TYPE (op0
);
9585 if (flag_enable_cilkplus
&& contains_array_notation_expr (op1
))
9586 orig_type1
= type1
= find_correct_array_notation_type (op1
);
9588 orig_type1
= type1
= TREE_TYPE (op1
);
9590 /* The expression codes of the data types of the arguments tell us
9591 whether the arguments are integers, floating, pointers, etc. */
9592 code0
= TREE_CODE (type0
);
9593 code1
= TREE_CODE (type1
);
9595 /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
9596 STRIP_TYPE_NOPS (op0
);
9597 STRIP_TYPE_NOPS (op1
);
9599 /* If an error was already reported for one of the arguments,
9600 avoid reporting another error. */
9602 if (code0
== ERROR_MARK
|| code1
== ERROR_MARK
)
9603 return error_mark_node
;
9605 if ((invalid_op_diag
9606 = targetm
.invalid_binary_op (code
, type0
, type1
)))
9608 error_at (location
, invalid_op_diag
);
9609 return error_mark_node
;
9617 case TRUNC_DIV_EXPR
:
9619 case FLOOR_DIV_EXPR
:
9620 case ROUND_DIV_EXPR
:
9621 case EXACT_DIV_EXPR
:
9622 may_need_excess_precision
= true;
9625 may_need_excess_precision
= false;
9628 if (TREE_CODE (op0
) == EXCESS_PRECISION_EXPR
)
9630 op0
= TREE_OPERAND (op0
, 0);
9631 type0
= TREE_TYPE (op0
);
9633 else if (may_need_excess_precision
9634 && (eptype
= excess_precision_type (type0
)) != NULL_TREE
)
9637 op0
= convert (eptype
, op0
);
9639 if (TREE_CODE (op1
) == EXCESS_PRECISION_EXPR
)
9641 op1
= TREE_OPERAND (op1
, 0);
9642 type1
= TREE_TYPE (op1
);
9644 else if (may_need_excess_precision
9645 && (eptype
= excess_precision_type (type1
)) != NULL_TREE
)
9648 op1
= convert (eptype
, op1
);
9651 objc_ok
= objc_compare_types (type0
, type1
, -3, NULL_TREE
);
9653 /* In case when one of the operands of the binary operation is
9654 a vector and another is a scalar -- convert scalar to vector. */
9655 if ((code0
== VECTOR_TYPE
) != (code1
== VECTOR_TYPE
))
9657 enum stv_conv convert_flag
= scalar_to_vector (location
, code
, op0
, op1
,
9660 switch (convert_flag
)
9663 return error_mark_node
;
9666 bool maybe_const
= true;
9668 sc
= c_fully_fold (op0
, false, &maybe_const
);
9669 sc
= save_expr (sc
);
9670 sc
= convert (TREE_TYPE (type1
), sc
);
9671 op0
= build_vector_from_val (type1
, sc
);
9673 op0
= c_wrap_maybe_const (op0
, true);
9674 orig_type0
= type0
= TREE_TYPE (op0
);
9675 code0
= TREE_CODE (type0
);
9681 bool maybe_const
= true;
9683 sc
= c_fully_fold (op1
, false, &maybe_const
);
9684 sc
= save_expr (sc
);
9685 sc
= convert (TREE_TYPE (type0
), sc
);
9686 op1
= build_vector_from_val (type0
, sc
);
9688 op1
= c_wrap_maybe_const (op1
, true);
9689 orig_type1
= type1
= TREE_TYPE (op1
);
9690 code1
= TREE_CODE (type1
);
9702 /* Handle the pointer + int case. */
9703 if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
9705 ret
= pointer_int_sum (location
, PLUS_EXPR
, op0
, op1
);
9706 goto return_build_binary_op
;
9708 else if (code1
== POINTER_TYPE
&& code0
== INTEGER_TYPE
)
9710 ret
= pointer_int_sum (location
, PLUS_EXPR
, op1
, op0
);
9711 goto return_build_binary_op
;
9718 /* Subtraction of two similar pointers.
9719 We must subtract them as integers, then divide by object size. */
9720 if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
9721 && comp_target_types (location
, type0
, type1
))
9723 ret
= pointer_diff (location
, op0
, op1
);
9724 goto return_build_binary_op
;
9726 /* Handle pointer minus int. Just like pointer plus int. */
9727 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
9729 ret
= pointer_int_sum (location
, MINUS_EXPR
, op0
, op1
);
9730 goto return_build_binary_op
;
9740 case TRUNC_DIV_EXPR
:
9742 case FLOOR_DIV_EXPR
:
9743 case ROUND_DIV_EXPR
:
9744 case EXACT_DIV_EXPR
:
9745 warn_for_div_by_zero (location
, op1
);
9747 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
9748 || code0
== FIXED_POINT_TYPE
9749 || code0
== COMPLEX_TYPE
|| code0
== VECTOR_TYPE
)
9750 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
9751 || code1
== FIXED_POINT_TYPE
9752 || code1
== COMPLEX_TYPE
|| code1
== VECTOR_TYPE
))
9754 enum tree_code tcode0
= code0
, tcode1
= code1
;
9756 if (code0
== COMPLEX_TYPE
|| code0
== VECTOR_TYPE
)
9757 tcode0
= TREE_CODE (TREE_TYPE (TREE_TYPE (op0
)));
9758 if (code1
== COMPLEX_TYPE
|| code1
== VECTOR_TYPE
)
9759 tcode1
= TREE_CODE (TREE_TYPE (TREE_TYPE (op1
)));
9761 if (!((tcode0
== INTEGER_TYPE
&& tcode1
== INTEGER_TYPE
)
9762 || (tcode0
== FIXED_POINT_TYPE
&& tcode1
== FIXED_POINT_TYPE
)))
9763 resultcode
= RDIV_EXPR
;
9765 /* Although it would be tempting to shorten always here, that
9766 loses on some targets, since the modulo instruction is
9767 undefined if the quotient can't be represented in the
9768 computation mode. We shorten only if unsigned or if
9769 dividing by something we know != -1. */
9770 shorten
= (TYPE_UNSIGNED (TREE_TYPE (orig_op0
))
9771 || (TREE_CODE (op1
) == INTEGER_CST
9772 && !integer_all_onesp (op1
)));
9780 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
9782 /* Allow vector types which are not floating point types. */
9783 else if (code0
== VECTOR_TYPE
9784 && code1
== VECTOR_TYPE
9785 && !VECTOR_FLOAT_TYPE_P (type0
)
9786 && !VECTOR_FLOAT_TYPE_P (type1
))
9790 case TRUNC_MOD_EXPR
:
9791 case FLOOR_MOD_EXPR
:
9792 warn_for_div_by_zero (location
, op1
);
9794 if (code0
== VECTOR_TYPE
&& code1
== VECTOR_TYPE
9795 && TREE_CODE (TREE_TYPE (type0
)) == INTEGER_TYPE
9796 && TREE_CODE (TREE_TYPE (type1
)) == INTEGER_TYPE
)
9798 else if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
9800 /* Although it would be tempting to shorten always here, that loses
9801 on some targets, since the modulo instruction is undefined if the
9802 quotient can't be represented in the computation mode. We shorten
9803 only if unsigned or if dividing by something we know != -1. */
9804 shorten
= (TYPE_UNSIGNED (TREE_TYPE (orig_op0
))
9805 || (TREE_CODE (op1
) == INTEGER_CST
9806 && !integer_all_onesp (op1
)));
9811 case TRUTH_ANDIF_EXPR
:
9812 case TRUTH_ORIF_EXPR
:
9813 case TRUTH_AND_EXPR
:
9815 case TRUTH_XOR_EXPR
:
9816 if ((code0
== INTEGER_TYPE
|| code0
== POINTER_TYPE
9817 || code0
== REAL_TYPE
|| code0
== COMPLEX_TYPE
9818 || code0
== FIXED_POINT_TYPE
)
9819 && (code1
== INTEGER_TYPE
|| code1
== POINTER_TYPE
9820 || code1
== REAL_TYPE
|| code1
== COMPLEX_TYPE
9821 || code1
== FIXED_POINT_TYPE
))
9823 /* Result of these operations is always an int,
9824 but that does not mean the operands should be
9825 converted to ints! */
9826 result_type
= integer_type_node
;
9827 if (op0_int_operands
)
9829 op0
= c_objc_common_truthvalue_conversion (location
, orig_op0
);
9830 op0
= remove_c_maybe_const_expr (op0
);
9833 op0
= c_objc_common_truthvalue_conversion (location
, op0
);
9834 if (op1_int_operands
)
9836 op1
= c_objc_common_truthvalue_conversion (location
, orig_op1
);
9837 op1
= remove_c_maybe_const_expr (op1
);
9840 op1
= c_objc_common_truthvalue_conversion (location
, op1
);
9844 if (code
== TRUTH_ANDIF_EXPR
)
9846 int_const_or_overflow
= (int_operands
9847 && TREE_CODE (orig_op0
) == INTEGER_CST
9848 && (op0
== truthvalue_false_node
9849 || TREE_CODE (orig_op1
) == INTEGER_CST
));
9850 int_const
= (int_const_or_overflow
9851 && !TREE_OVERFLOW (orig_op0
)
9852 && (op0
== truthvalue_false_node
9853 || !TREE_OVERFLOW (orig_op1
)));
9855 else if (code
== TRUTH_ORIF_EXPR
)
9857 int_const_or_overflow
= (int_operands
9858 && TREE_CODE (orig_op0
) == INTEGER_CST
9859 && (op0
== truthvalue_true_node
9860 || TREE_CODE (orig_op1
) == INTEGER_CST
));
9861 int_const
= (int_const_or_overflow
9862 && !TREE_OVERFLOW (orig_op0
)
9863 && (op0
== truthvalue_true_node
9864 || !TREE_OVERFLOW (orig_op1
)));
9868 /* Shift operations: result has same type as first operand;
9869 always convert second operand to int.
9870 Also set SHORT_SHIFT if shifting rightward. */
9873 if (code0
== VECTOR_TYPE
&& code1
== INTEGER_TYPE
9874 && TREE_CODE (TREE_TYPE (type0
)) == INTEGER_TYPE
)
9876 result_type
= type0
;
9879 else if (code0
== VECTOR_TYPE
&& code1
== VECTOR_TYPE
9880 && TREE_CODE (TREE_TYPE (type0
)) == INTEGER_TYPE
9881 && TREE_CODE (TREE_TYPE (type1
)) == INTEGER_TYPE
9882 && TYPE_VECTOR_SUBPARTS (type0
) == TYPE_VECTOR_SUBPARTS (type1
))
9884 result_type
= type0
;
9887 else if ((code0
== INTEGER_TYPE
|| code0
== FIXED_POINT_TYPE
)
9888 && code1
== INTEGER_TYPE
)
9890 if (TREE_CODE (op1
) == INTEGER_CST
)
9892 if (tree_int_cst_sgn (op1
) < 0)
9895 if (c_inhibit_evaluation_warnings
== 0)
9896 warning (0, "right shift count is negative");
9900 if (!integer_zerop (op1
))
9903 if (compare_tree_int (op1
, TYPE_PRECISION (type0
)) >= 0)
9906 if (c_inhibit_evaluation_warnings
== 0)
9907 warning (0, "right shift count >= width of type");
9912 /* Use the type of the value to be shifted. */
9913 result_type
= type0
;
9914 /* Convert the non vector shift-count to an integer, regardless
9915 of size of value being shifted. */
9916 if (TREE_CODE (TREE_TYPE (op1
)) != VECTOR_TYPE
9917 && TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
9918 op1
= convert (integer_type_node
, op1
);
9919 /* Avoid converting op1 to result_type later. */
9925 if (code0
== VECTOR_TYPE
&& code1
== INTEGER_TYPE
9926 && TREE_CODE (TREE_TYPE (type0
)) == INTEGER_TYPE
)
9928 result_type
= type0
;
9931 else if (code0
== VECTOR_TYPE
&& code1
== VECTOR_TYPE
9932 && TREE_CODE (TREE_TYPE (type0
)) == INTEGER_TYPE
9933 && TREE_CODE (TREE_TYPE (type1
)) == INTEGER_TYPE
9934 && TYPE_VECTOR_SUBPARTS (type0
) == TYPE_VECTOR_SUBPARTS (type1
))
9936 result_type
= type0
;
9939 else if ((code0
== INTEGER_TYPE
|| code0
== FIXED_POINT_TYPE
)
9940 && code1
== INTEGER_TYPE
)
9942 if (TREE_CODE (op1
) == INTEGER_CST
)
9944 if (tree_int_cst_sgn (op1
) < 0)
9947 if (c_inhibit_evaluation_warnings
== 0)
9948 warning (0, "left shift count is negative");
9951 else if (compare_tree_int (op1
, TYPE_PRECISION (type0
)) >= 0)
9954 if (c_inhibit_evaluation_warnings
== 0)
9955 warning (0, "left shift count >= width of type");
9959 /* Use the type of the value to be shifted. */
9960 result_type
= type0
;
9961 /* Convert the non vector shift-count to an integer, regardless
9962 of size of value being shifted. */
9963 if (TREE_CODE (TREE_TYPE (op1
)) != VECTOR_TYPE
9964 && TYPE_MAIN_VARIANT (TREE_TYPE (op1
)) != integer_type_node
)
9965 op1
= convert (integer_type_node
, op1
);
9966 /* Avoid converting op1 to result_type later. */
9973 if (code0
== VECTOR_TYPE
&& code1
== VECTOR_TYPE
)
9976 if (TREE_TYPE (type0
) != TREE_TYPE (type1
))
9978 error_at (location
, "comparing vectors with different "
9980 return error_mark_node
;
9983 if (TYPE_VECTOR_SUBPARTS (type0
) != TYPE_VECTOR_SUBPARTS (type1
))
9985 error_at (location
, "comparing vectors with different "
9986 "number of elements");
9987 return error_mark_node
;
9990 /* Always construct signed integer vector type. */
9991 intt
= c_common_type_for_size (GET_MODE_BITSIZE
9992 (TYPE_MODE (TREE_TYPE (type0
))), 0);
9993 result_type
= build_opaque_vector_type (intt
,
9994 TYPE_VECTOR_SUBPARTS (type0
));
9998 if (FLOAT_TYPE_P (type0
) || FLOAT_TYPE_P (type1
))
9999 warning_at (location
,
10001 "comparing floating point with == or != is unsafe");
10002 /* Result of comparison is always int,
10003 but don't convert the args to int! */
10004 build_type
= integer_type_node
;
10005 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
10006 || code0
== FIXED_POINT_TYPE
|| code0
== COMPLEX_TYPE
)
10007 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
10008 || code1
== FIXED_POINT_TYPE
|| code1
== COMPLEX_TYPE
))
10010 else if (code0
== POINTER_TYPE
&& null_pointer_constant_p (orig_op1
))
10012 if (TREE_CODE (op0
) == ADDR_EXPR
10013 && decl_with_nonnull_addr_p (TREE_OPERAND (op0
, 0)))
10015 if (code
== EQ_EXPR
)
10016 warning_at (location
,
10018 "the comparison will always evaluate as %<false%> "
10019 "for the address of %qD will never be NULL",
10020 TREE_OPERAND (op0
, 0));
10022 warning_at (location
,
10024 "the comparison will always evaluate as %<true%> "
10025 "for the address of %qD will never be NULL",
10026 TREE_OPERAND (op0
, 0));
10028 result_type
= type0
;
10030 else if (code1
== POINTER_TYPE
&& null_pointer_constant_p (orig_op0
))
10032 if (TREE_CODE (op1
) == ADDR_EXPR
10033 && decl_with_nonnull_addr_p (TREE_OPERAND (op1
, 0)))
10035 if (code
== EQ_EXPR
)
10036 warning_at (location
,
10038 "the comparison will always evaluate as %<false%> "
10039 "for the address of %qD will never be NULL",
10040 TREE_OPERAND (op1
, 0));
10042 warning_at (location
,
10044 "the comparison will always evaluate as %<true%> "
10045 "for the address of %qD will never be NULL",
10046 TREE_OPERAND (op1
, 0));
10048 result_type
= type1
;
10050 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
10052 tree tt0
= TREE_TYPE (type0
);
10053 tree tt1
= TREE_TYPE (type1
);
10054 addr_space_t as0
= TYPE_ADDR_SPACE (tt0
);
10055 addr_space_t as1
= TYPE_ADDR_SPACE (tt1
);
10056 addr_space_t as_common
= ADDR_SPACE_GENERIC
;
10058 /* Anything compares with void *. void * compares with anything.
10059 Otherwise, the targets must be compatible
10060 and both must be object or both incomplete. */
10061 if (comp_target_types (location
, type0
, type1
))
10062 result_type
= common_pointer_type (type0
, type1
);
10063 else if (!addr_space_superset (as0
, as1
, &as_common
))
10065 error_at (location
, "comparison of pointers to "
10066 "disjoint address spaces");
10067 return error_mark_node
;
10069 else if (VOID_TYPE_P (tt0
))
10071 if (pedantic
&& TREE_CODE (tt1
) == FUNCTION_TYPE
)
10072 pedwarn (location
, OPT_Wpedantic
, "ISO C forbids "
10073 "comparison of %<void *%> with function pointer");
10075 else if (VOID_TYPE_P (tt1
))
10077 if (pedantic
&& TREE_CODE (tt0
) == FUNCTION_TYPE
)
10078 pedwarn (location
, OPT_Wpedantic
, "ISO C forbids "
10079 "comparison of %<void *%> with function pointer");
10082 /* Avoid warning about the volatile ObjC EH puts on decls. */
10084 pedwarn (location
, 0,
10085 "comparison of distinct pointer types lacks a cast");
10087 if (result_type
== NULL_TREE
)
10089 int qual
= ENCODE_QUAL_ADDR_SPACE (as_common
);
10090 result_type
= build_pointer_type
10091 (build_qualified_type (void_type_node
, qual
));
10094 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
10096 result_type
= type0
;
10097 pedwarn (location
, 0, "comparison between pointer and integer");
10099 else if (code0
== INTEGER_TYPE
&& code1
== POINTER_TYPE
)
10101 result_type
= type1
;
10102 pedwarn (location
, 0, "comparison between pointer and integer");
10110 if (code0
== VECTOR_TYPE
&& code1
== VECTOR_TYPE
)
10113 if (TREE_TYPE (type0
) != TREE_TYPE (type1
))
10115 error_at (location
, "comparing vectors with different "
10117 return error_mark_node
;
10120 if (TYPE_VECTOR_SUBPARTS (type0
) != TYPE_VECTOR_SUBPARTS (type1
))
10122 error_at (location
, "comparing vectors with different "
10123 "number of elements");
10124 return error_mark_node
;
10127 /* Always construct signed integer vector type. */
10128 intt
= c_common_type_for_size (GET_MODE_BITSIZE
10129 (TYPE_MODE (TREE_TYPE (type0
))), 0);
10130 result_type
= build_opaque_vector_type (intt
,
10131 TYPE_VECTOR_SUBPARTS (type0
));
10135 build_type
= integer_type_node
;
10136 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
10137 || code0
== FIXED_POINT_TYPE
)
10138 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
10139 || code1
== FIXED_POINT_TYPE
))
10141 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
10143 addr_space_t as0
= TYPE_ADDR_SPACE (TREE_TYPE (type0
));
10144 addr_space_t as1
= TYPE_ADDR_SPACE (TREE_TYPE (type1
));
10145 addr_space_t as_common
;
10147 if (comp_target_types (location
, type0
, type1
))
10149 result_type
= common_pointer_type (type0
, type1
);
10150 if (!COMPLETE_TYPE_P (TREE_TYPE (type0
))
10151 != !COMPLETE_TYPE_P (TREE_TYPE (type1
)))
10152 pedwarn (location
, 0,
10153 "comparison of complete and incomplete pointers");
10154 else if (TREE_CODE (TREE_TYPE (type0
)) == FUNCTION_TYPE
)
10155 pedwarn (location
, OPT_Wpedantic
, "ISO C forbids "
10156 "ordered comparisons of pointers to functions");
10157 else if (null_pointer_constant_p (orig_op0
)
10158 || null_pointer_constant_p (orig_op1
))
10159 warning_at (location
, OPT_Wextra
,
10160 "ordered comparison of pointer with null pointer");
10163 else if (!addr_space_superset (as0
, as1
, &as_common
))
10165 error_at (location
, "comparison of pointers to "
10166 "disjoint address spaces");
10167 return error_mark_node
;
10171 int qual
= ENCODE_QUAL_ADDR_SPACE (as_common
);
10172 result_type
= build_pointer_type
10173 (build_qualified_type (void_type_node
, qual
));
10174 pedwarn (location
, 0,
10175 "comparison of distinct pointer types lacks a cast");
10178 else if (code0
== POINTER_TYPE
&& null_pointer_constant_p (orig_op1
))
10180 result_type
= type0
;
10182 pedwarn (location
, OPT_Wpedantic
,
10183 "ordered comparison of pointer with integer zero");
10184 else if (extra_warnings
)
10185 warning_at (location
, OPT_Wextra
,
10186 "ordered comparison of pointer with integer zero");
10188 else if (code1
== POINTER_TYPE
&& null_pointer_constant_p (orig_op0
))
10190 result_type
= type1
;
10192 pedwarn (location
, OPT_Wpedantic
,
10193 "ordered comparison of pointer with integer zero");
10194 else if (extra_warnings
)
10195 warning_at (location
, OPT_Wextra
,
10196 "ordered comparison of pointer with integer zero");
10198 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
10200 result_type
= type0
;
10201 pedwarn (location
, 0, "comparison between pointer and integer");
10203 else if (code0
== INTEGER_TYPE
&& code1
== POINTER_TYPE
)
10205 result_type
= type1
;
10206 pedwarn (location
, 0, "comparison between pointer and integer");
10211 gcc_unreachable ();
10214 if (code0
== ERROR_MARK
|| code1
== ERROR_MARK
)
10215 return error_mark_node
;
10217 if (code0
== VECTOR_TYPE
&& code1
== VECTOR_TYPE
10218 && (!tree_int_cst_equal (TYPE_SIZE (type0
), TYPE_SIZE (type1
))
10219 || !same_scalar_type_ignoring_signedness (TREE_TYPE (type0
),
10220 TREE_TYPE (type1
))))
10222 binary_op_error (location
, code
, type0
, type1
);
10223 return error_mark_node
;
10226 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
|| code0
== COMPLEX_TYPE
10227 || code0
== FIXED_POINT_TYPE
|| code0
== VECTOR_TYPE
)
10229 (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
|| code1
== COMPLEX_TYPE
10230 || code1
== FIXED_POINT_TYPE
|| code1
== VECTOR_TYPE
))
10232 bool first_complex
= (code0
== COMPLEX_TYPE
);
10233 bool second_complex
= (code1
== COMPLEX_TYPE
);
10234 int none_complex
= (!first_complex
&& !second_complex
);
10236 if (shorten
|| common
|| short_compare
)
10238 result_type
= c_common_type (type0
, type1
);
10239 do_warn_double_promotion (result_type
, type0
, type1
,
10240 "implicit conversion from %qT to %qT "
10241 "to match other operand of binary "
10244 if (result_type
== error_mark_node
)
10245 return error_mark_node
;
10248 if (first_complex
!= second_complex
10249 && (code
== PLUS_EXPR
10250 || code
== MINUS_EXPR
10251 || code
== MULT_EXPR
10252 || (code
== TRUNC_DIV_EXPR
&& first_complex
))
10253 && TREE_CODE (TREE_TYPE (result_type
)) == REAL_TYPE
10254 && flag_signed_zeros
)
10256 /* An operation on mixed real/complex operands must be
10257 handled specially, but the language-independent code can
10258 more easily optimize the plain complex arithmetic if
10259 -fno-signed-zeros. */
10260 tree real_type
= TREE_TYPE (result_type
);
10262 if (type0
!= orig_type0
|| type1
!= orig_type1
)
10264 gcc_assert (may_need_excess_precision
&& common
);
10265 semantic_result_type
= c_common_type (orig_type0
, orig_type1
);
10269 if (TREE_TYPE (op0
) != result_type
)
10270 op0
= convert_and_check (result_type
, op0
);
10271 if (TREE_TYPE (op1
) != real_type
)
10272 op1
= convert_and_check (real_type
, op1
);
10276 if (TREE_TYPE (op0
) != real_type
)
10277 op0
= convert_and_check (real_type
, op0
);
10278 if (TREE_TYPE (op1
) != result_type
)
10279 op1
= convert_and_check (result_type
, op1
);
10281 if (TREE_CODE (op0
) == ERROR_MARK
|| TREE_CODE (op1
) == ERROR_MARK
)
10282 return error_mark_node
;
10285 op0
= c_save_expr (op0
);
10286 real
= build_unary_op (EXPR_LOCATION (orig_op0
), REALPART_EXPR
,
10288 imag
= build_unary_op (EXPR_LOCATION (orig_op0
), IMAGPART_EXPR
,
10293 case TRUNC_DIV_EXPR
:
10294 op1
= c_save_expr (op1
);
10295 imag
= build2 (resultcode
, real_type
, imag
, op1
);
10296 /* Fall through. */
10299 real
= build2 (resultcode
, real_type
, real
, op1
);
10307 op1
= c_save_expr (op1
);
10308 real
= build_unary_op (EXPR_LOCATION (orig_op1
), REALPART_EXPR
,
10310 imag
= build_unary_op (EXPR_LOCATION (orig_op1
), IMAGPART_EXPR
,
10315 op0
= c_save_expr (op0
);
10316 imag
= build2 (resultcode
, real_type
, op0
, imag
);
10317 /* Fall through. */
10319 real
= build2 (resultcode
, real_type
, op0
, real
);
10322 real
= build2 (resultcode
, real_type
, op0
, real
);
10323 imag
= build1 (NEGATE_EXPR
, real_type
, imag
);
10329 ret
= build2 (COMPLEX_EXPR
, result_type
, real
, imag
);
10330 goto return_build_binary_op
;
10333 /* For certain operations (which identify themselves by shorten != 0)
10334 if both args were extended from the same smaller type,
10335 do the arithmetic in that type and then extend.
10337 shorten !=0 and !=1 indicates a bitwise operation.
10338 For them, this optimization is safe only if
10339 both args are zero-extended or both are sign-extended.
10340 Otherwise, we might change the result.
10341 Eg, (short)-1 | (unsigned short)-1 is (int)-1
10342 but calculated in (unsigned short) it would be (unsigned short)-1. */
10344 if (shorten
&& none_complex
)
10346 final_type
= result_type
;
10347 result_type
= shorten_binary_op (result_type
, op0
, op1
,
10351 /* Shifts can be shortened if shifting right. */
10356 tree arg0
= get_narrower (op0
, &unsigned_arg
);
10358 final_type
= result_type
;
10360 if (arg0
== op0
&& final_type
== TREE_TYPE (op0
))
10361 unsigned_arg
= TYPE_UNSIGNED (TREE_TYPE (op0
));
10363 if (TYPE_PRECISION (TREE_TYPE (arg0
)) < TYPE_PRECISION (result_type
)
10364 && tree_int_cst_sgn (op1
) > 0
10365 /* We can shorten only if the shift count is less than the
10366 number of bits in the smaller type size. */
10367 && compare_tree_int (op1
, TYPE_PRECISION (TREE_TYPE (arg0
))) < 0
10368 /* We cannot drop an unsigned shift after sign-extension. */
10369 && (!TYPE_UNSIGNED (final_type
) || unsigned_arg
))
10371 /* Do an unsigned shift if the operand was zero-extended. */
10373 = c_common_signed_or_unsigned_type (unsigned_arg
,
10375 /* Convert value-to-be-shifted to that type. */
10376 if (TREE_TYPE (op0
) != result_type
)
10377 op0
= convert (result_type
, op0
);
10382 /* Comparison operations are shortened too but differently.
10383 They identify themselves by setting short_compare = 1. */
10387 /* Don't write &op0, etc., because that would prevent op0
10388 from being kept in a register.
10389 Instead, make copies of the our local variables and
10390 pass the copies by reference, then copy them back afterward. */
10391 tree xop0
= op0
, xop1
= op1
, xresult_type
= result_type
;
10392 enum tree_code xresultcode
= resultcode
;
10394 = shorten_compare (&xop0
, &xop1
, &xresult_type
, &xresultcode
);
10399 goto return_build_binary_op
;
10402 op0
= xop0
, op1
= xop1
;
10404 resultcode
= xresultcode
;
10406 if (c_inhibit_evaluation_warnings
== 0)
10408 bool op0_maybe_const
= true;
10409 bool op1_maybe_const
= true;
10410 tree orig_op0_folded
, orig_op1_folded
;
10412 if (in_late_binary_op
)
10414 orig_op0_folded
= orig_op0
;
10415 orig_op1_folded
= orig_op1
;
10419 /* Fold for the sake of possible warnings, as in
10420 build_conditional_expr. This requires the
10421 "original" values to be folded, not just op0 and
10423 c_inhibit_evaluation_warnings
++;
10424 op0
= c_fully_fold (op0
, require_constant_value
,
10426 op1
= c_fully_fold (op1
, require_constant_value
,
10428 c_inhibit_evaluation_warnings
--;
10429 orig_op0_folded
= c_fully_fold (orig_op0
,
10430 require_constant_value
,
10432 orig_op1_folded
= c_fully_fold (orig_op1
,
10433 require_constant_value
,
10437 if (warn_sign_compare
)
10438 warn_for_sign_compare (location
, orig_op0_folded
,
10439 orig_op1_folded
, op0
, op1
,
10440 result_type
, resultcode
);
10441 if (!in_late_binary_op
&& !int_operands
)
10443 if (!op0_maybe_const
|| TREE_CODE (op0
) != INTEGER_CST
)
10444 op0
= c_wrap_maybe_const (op0
, !op0_maybe_const
);
10445 if (!op1_maybe_const
|| TREE_CODE (op1
) != INTEGER_CST
)
10446 op1
= c_wrap_maybe_const (op1
, !op1_maybe_const
);
10452 /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
10453 If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
10454 Then the expression will be built.
10455 It will be given type FINAL_TYPE if that is nonzero;
10456 otherwise, it will be given type RESULT_TYPE. */
10460 binary_op_error (location
, code
, TREE_TYPE (op0
), TREE_TYPE (op1
));
10461 return error_mark_node
;
10464 if (build_type
== NULL_TREE
)
10466 build_type
= result_type
;
10467 if ((type0
!= orig_type0
|| type1
!= orig_type1
)
10470 gcc_assert (may_need_excess_precision
&& common
);
10471 semantic_result_type
= c_common_type (orig_type0
, orig_type1
);
10477 op0
= ep_convert_and_check (result_type
, op0
, semantic_result_type
);
10478 op1
= ep_convert_and_check (result_type
, op1
, semantic_result_type
);
10480 /* This can happen if one operand has a vector type, and the other
10481 has a different type. */
10482 if (TREE_CODE (op0
) == ERROR_MARK
|| TREE_CODE (op1
) == ERROR_MARK
)
10483 return error_mark_node
;
10486 /* Treat expressions in initializers specially as they can't trap. */
10487 if (int_const_or_overflow
)
10488 ret
= (require_constant_value
10489 ? fold_build2_initializer_loc (location
, resultcode
, build_type
,
10491 : fold_build2_loc (location
, resultcode
, build_type
, op0
, op1
));
10493 ret
= build2 (resultcode
, build_type
, op0
, op1
);
10494 if (final_type
!= 0)
10495 ret
= convert (final_type
, ret
);
10497 return_build_binary_op
:
10498 gcc_assert (ret
!= error_mark_node
);
10499 if (TREE_CODE (ret
) == INTEGER_CST
&& !TREE_OVERFLOW (ret
) && !int_const
)
10500 ret
= (int_operands
10501 ? note_integer_operands (ret
)
10502 : build1 (NOP_EXPR
, TREE_TYPE (ret
), ret
));
10503 else if (TREE_CODE (ret
) != INTEGER_CST
&& int_operands
10504 && !in_late_binary_op
)
10505 ret
= note_integer_operands (ret
);
10506 if (semantic_result_type
)
10507 ret
= build1 (EXCESS_PRECISION_EXPR
, semantic_result_type
, ret
);
10508 protected_set_expr_location (ret
, location
);
10513 /* Convert EXPR to be a truth-value, validating its type for this
10514 purpose. LOCATION is the source location for the expression. */
10517 c_objc_common_truthvalue_conversion (location_t location
, tree expr
)
10519 bool int_const
, int_operands
;
10521 switch (TREE_CODE (TREE_TYPE (expr
)))
10524 error_at (location
, "used array that cannot be converted to pointer where scalar is required");
10525 return error_mark_node
;
10528 error_at (location
, "used struct type value where scalar is required");
10529 return error_mark_node
;
10532 error_at (location
, "used union type value where scalar is required");
10533 return error_mark_node
;
10536 error_at (location
, "void value not ignored as it ought to be");
10537 return error_mark_node
;
10539 case FUNCTION_TYPE
:
10540 gcc_unreachable ();
10543 error_at (location
, "used vector type where scalar is required");
10544 return error_mark_node
;
10550 int_const
= (TREE_CODE (expr
) == INTEGER_CST
&& !TREE_OVERFLOW (expr
));
10551 int_operands
= EXPR_INT_CONST_OPERANDS (expr
);
10552 if (int_operands
&& TREE_CODE (expr
) != INTEGER_CST
)
10554 expr
= remove_c_maybe_const_expr (expr
);
10555 expr
= build2 (NE_EXPR
, integer_type_node
, expr
,
10556 convert (TREE_TYPE (expr
), integer_zero_node
));
10557 expr
= note_integer_operands (expr
);
10560 /* ??? Should we also give an error for vectors rather than leaving
10561 those to give errors later? */
10562 expr
= c_common_truthvalue_conversion (location
, expr
);
10564 if (TREE_CODE (expr
) == INTEGER_CST
&& int_operands
&& !int_const
)
10566 if (TREE_OVERFLOW (expr
))
10569 return note_integer_operands (expr
);
10571 if (TREE_CODE (expr
) == INTEGER_CST
&& !int_const
)
10572 return build1 (NOP_EXPR
, TREE_TYPE (expr
), expr
);
10577 /* Convert EXPR to a contained DECL, updating *TC, *TI and *SE as
10581 c_expr_to_decl (tree expr
, bool *tc ATTRIBUTE_UNUSED
, bool *se
)
10583 if (TREE_CODE (expr
) == COMPOUND_LITERAL_EXPR
)
10585 tree decl
= COMPOUND_LITERAL_EXPR_DECL (expr
);
10586 /* Executing a compound literal inside a function reinitializes
10588 if (!TREE_STATIC (decl
))
10596 /* Like c_begin_compound_stmt, except force the retention of the BLOCK. */
10599 c_begin_omp_parallel (void)
10603 keep_next_level ();
10604 block
= c_begin_compound_stmt (true);
10609 /* Generate OMP_PARALLEL, with CLAUSES and BLOCK as its compound
10610 statement. LOC is the location of the OMP_PARALLEL. */
10613 c_finish_omp_parallel (location_t loc
, tree clauses
, tree block
)
10617 block
= c_end_compound_stmt (loc
, block
, true);
10619 stmt
= make_node (OMP_PARALLEL
);
10620 TREE_TYPE (stmt
) = void_type_node
;
10621 OMP_PARALLEL_CLAUSES (stmt
) = clauses
;
10622 OMP_PARALLEL_BODY (stmt
) = block
;
10623 SET_EXPR_LOCATION (stmt
, loc
);
10625 return add_stmt (stmt
);
10628 /* Like c_begin_compound_stmt, except force the retention of the BLOCK. */
10631 c_begin_omp_task (void)
10635 keep_next_level ();
10636 block
= c_begin_compound_stmt (true);
10641 /* Generate OMP_TASK, with CLAUSES and BLOCK as its compound
10642 statement. LOC is the location of the #pragma. */
10645 c_finish_omp_task (location_t loc
, tree clauses
, tree block
)
10649 block
= c_end_compound_stmt (loc
, block
, true);
10651 stmt
= make_node (OMP_TASK
);
10652 TREE_TYPE (stmt
) = void_type_node
;
10653 OMP_TASK_CLAUSES (stmt
) = clauses
;
10654 OMP_TASK_BODY (stmt
) = block
;
10655 SET_EXPR_LOCATION (stmt
, loc
);
10657 return add_stmt (stmt
);
10660 /* For all elements of CLAUSES, validate them vs OpenMP constraints.
10661 Remove any elements from the list that are invalid. */
10664 c_finish_omp_clauses (tree clauses
)
10666 bitmap_head generic_head
, firstprivate_head
, lastprivate_head
;
10667 tree c
, t
, *pc
= &clauses
;
10670 bitmap_obstack_initialize (NULL
);
10671 bitmap_initialize (&generic_head
, &bitmap_default_obstack
);
10672 bitmap_initialize (&firstprivate_head
, &bitmap_default_obstack
);
10673 bitmap_initialize (&lastprivate_head
, &bitmap_default_obstack
);
10675 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
10677 bool remove
= false;
10678 bool need_complete
= false;
10679 bool need_implicitly_determined
= false;
10681 switch (OMP_CLAUSE_CODE (c
))
10683 case OMP_CLAUSE_SHARED
:
10685 need_implicitly_determined
= true;
10686 goto check_dup_generic
;
10688 case OMP_CLAUSE_PRIVATE
:
10690 need_complete
= true;
10691 need_implicitly_determined
= true;
10692 goto check_dup_generic
;
10694 case OMP_CLAUSE_REDUCTION
:
10695 name
= "reduction";
10696 need_implicitly_determined
= true;
10697 t
= OMP_CLAUSE_DECL (c
);
10698 if (AGGREGATE_TYPE_P (TREE_TYPE (t
))
10699 || POINTER_TYPE_P (TREE_TYPE (t
)))
10701 error_at (OMP_CLAUSE_LOCATION (c
),
10702 "%qE has invalid type for %<reduction%>", t
);
10705 else if (FLOAT_TYPE_P (TREE_TYPE (t
)))
10707 enum tree_code r_code
= OMP_CLAUSE_REDUCTION_CODE (c
);
10708 const char *r_name
= NULL
;
10727 case TRUTH_ANDIF_EXPR
:
10730 case TRUTH_ORIF_EXPR
:
10734 gcc_unreachable ();
10738 error_at (OMP_CLAUSE_LOCATION (c
),
10739 "%qE has invalid type for %<reduction(%s)%>",
10744 goto check_dup_generic
;
10746 case OMP_CLAUSE_COPYPRIVATE
:
10747 name
= "copyprivate";
10748 goto check_dup_generic
;
10750 case OMP_CLAUSE_COPYIN
:
10752 t
= OMP_CLAUSE_DECL (c
);
10753 if (TREE_CODE (t
) != VAR_DECL
|| !DECL_THREAD_LOCAL_P (t
))
10755 error_at (OMP_CLAUSE_LOCATION (c
),
10756 "%qE must be %<threadprivate%> for %<copyin%>", t
);
10759 goto check_dup_generic
;
10762 t
= OMP_CLAUSE_DECL (c
);
10763 if (TREE_CODE (t
) != VAR_DECL
&& TREE_CODE (t
) != PARM_DECL
)
10765 error_at (OMP_CLAUSE_LOCATION (c
),
10766 "%qE is not a variable in clause %qs", t
, name
);
10769 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
10770 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
))
10771 || bitmap_bit_p (&lastprivate_head
, DECL_UID (t
)))
10773 error_at (OMP_CLAUSE_LOCATION (c
),
10774 "%qE appears more than once in data clauses", t
);
10778 bitmap_set_bit (&generic_head
, DECL_UID (t
));
10781 case OMP_CLAUSE_FIRSTPRIVATE
:
10782 name
= "firstprivate";
10783 t
= OMP_CLAUSE_DECL (c
);
10784 need_complete
= true;
10785 need_implicitly_determined
= true;
10786 if (TREE_CODE (t
) != VAR_DECL
&& TREE_CODE (t
) != PARM_DECL
)
10788 error_at (OMP_CLAUSE_LOCATION (c
),
10789 "%qE is not a variable in clause %<firstprivate%>", t
);
10792 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
10793 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
10795 error_at (OMP_CLAUSE_LOCATION (c
),
10796 "%qE appears more than once in data clauses", t
);
10800 bitmap_set_bit (&firstprivate_head
, DECL_UID (t
));
10803 case OMP_CLAUSE_LASTPRIVATE
:
10804 name
= "lastprivate";
10805 t
= OMP_CLAUSE_DECL (c
);
10806 need_complete
= true;
10807 need_implicitly_determined
= true;
10808 if (TREE_CODE (t
) != VAR_DECL
&& TREE_CODE (t
) != PARM_DECL
)
10810 error_at (OMP_CLAUSE_LOCATION (c
),
10811 "%qE is not a variable in clause %<lastprivate%>", t
);
10814 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
10815 || bitmap_bit_p (&lastprivate_head
, DECL_UID (t
)))
10817 error_at (OMP_CLAUSE_LOCATION (c
),
10818 "%qE appears more than once in data clauses", t
);
10822 bitmap_set_bit (&lastprivate_head
, DECL_UID (t
));
10825 case OMP_CLAUSE_IF
:
10826 case OMP_CLAUSE_NUM_THREADS
:
10827 case OMP_CLAUSE_SCHEDULE
:
10828 case OMP_CLAUSE_NOWAIT
:
10829 case OMP_CLAUSE_ORDERED
:
10830 case OMP_CLAUSE_DEFAULT
:
10831 case OMP_CLAUSE_UNTIED
:
10832 case OMP_CLAUSE_COLLAPSE
:
10833 case OMP_CLAUSE_FINAL
:
10834 case OMP_CLAUSE_MERGEABLE
:
10835 pc
= &OMP_CLAUSE_CHAIN (c
);
10839 gcc_unreachable ();
10844 t
= OMP_CLAUSE_DECL (c
);
10848 t
= require_complete_type (t
);
10849 if (t
== error_mark_node
)
10853 if (need_implicitly_determined
)
10855 const char *share_name
= NULL
;
10857 if (TREE_CODE (t
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (t
))
10858 share_name
= "threadprivate";
10859 else switch (c_omp_predetermined_sharing (t
))
10861 case OMP_CLAUSE_DEFAULT_UNSPECIFIED
:
10863 case OMP_CLAUSE_DEFAULT_SHARED
:
10864 /* const vars may be specified in firstprivate clause. */
10865 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
10866 && TREE_READONLY (t
))
10868 share_name
= "shared";
10870 case OMP_CLAUSE_DEFAULT_PRIVATE
:
10871 share_name
= "private";
10874 gcc_unreachable ();
10878 error_at (OMP_CLAUSE_LOCATION (c
),
10879 "%qE is predetermined %qs for %qs",
10880 t
, share_name
, name
);
10887 *pc
= OMP_CLAUSE_CHAIN (c
);
10889 pc
= &OMP_CLAUSE_CHAIN (c
);
10892 bitmap_obstack_release (NULL
);
10896 /* Create a transaction node. */
10899 c_finish_transaction (location_t loc
, tree block
, int flags
)
10901 tree stmt
= build_stmt (loc
, TRANSACTION_EXPR
, block
);
10902 if (flags
& TM_STMT_ATTR_OUTER
)
10903 TRANSACTION_EXPR_OUTER (stmt
) = 1;
10904 if (flags
& TM_STMT_ATTR_RELAXED
)
10905 TRANSACTION_EXPR_RELAXED (stmt
) = 1;
10906 return add_stmt (stmt
);
10909 /* Make a variant type in the proper way for C/C++, propagating qualifiers
10910 down to the element type of an array. */
10913 c_build_qualified_type (tree type
, int type_quals
)
10915 if (type
== error_mark_node
)
10918 if (TREE_CODE (type
) == ARRAY_TYPE
)
10921 tree element_type
= c_build_qualified_type (TREE_TYPE (type
),
10924 /* See if we already have an identically qualified type. */
10925 for (t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
10927 if (TYPE_QUALS (strip_array_types (t
)) == type_quals
10928 && TYPE_NAME (t
) == TYPE_NAME (type
)
10929 && TYPE_CONTEXT (t
) == TYPE_CONTEXT (type
)
10930 && attribute_list_equal (TYPE_ATTRIBUTES (t
),
10931 TYPE_ATTRIBUTES (type
)))
10936 tree domain
= TYPE_DOMAIN (type
);
10938 t
= build_variant_type_copy (type
);
10939 TREE_TYPE (t
) = element_type
;
10941 if (TYPE_STRUCTURAL_EQUALITY_P (element_type
)
10942 || (domain
&& TYPE_STRUCTURAL_EQUALITY_P (domain
)))
10943 SET_TYPE_STRUCTURAL_EQUALITY (t
);
10944 else if (TYPE_CANONICAL (element_type
) != element_type
10945 || (domain
&& TYPE_CANONICAL (domain
) != domain
))
10947 tree unqualified_canon
10948 = build_array_type (TYPE_CANONICAL (element_type
),
10949 domain
? TYPE_CANONICAL (domain
)
10952 = c_build_qualified_type (unqualified_canon
, type_quals
);
10955 TYPE_CANONICAL (t
) = t
;
10960 /* A restrict-qualified pointer type must be a pointer to object or
10961 incomplete type. Note that the use of POINTER_TYPE_P also allows
10962 REFERENCE_TYPEs, which is appropriate for C++. */
10963 if ((type_quals
& TYPE_QUAL_RESTRICT
)
10964 && (!POINTER_TYPE_P (type
)
10965 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type
))))
10967 error ("invalid use of %<restrict%>");
10968 type_quals
&= ~TYPE_QUAL_RESTRICT
;
10971 return build_qualified_type (type
, type_quals
);
10974 /* Build a VA_ARG_EXPR for the C parser. */
10977 c_build_va_arg (location_t loc
, tree expr
, tree type
)
10979 if (warn_cxx_compat
&& TREE_CODE (type
) == ENUMERAL_TYPE
)
10980 warning_at (loc
, OPT_Wc___compat
,
10981 "C++ requires promoted type, not enum type, in %<va_arg%>");
10982 return build_va_arg (loc
, expr
, type
);