1 /* Build expressions with type checking for C compiler.
2 Copyright (C) 1987-2018 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"
34 #include "gimple-expr.h"
36 #include "stor-layout.h"
37 #include "trans-mem.h"
40 #include "langhooks.h"
43 #include "tree-iterator.h"
45 #include "tree-inline.h"
46 #include "omp-general.h"
47 #include "c-family/c-objc.h"
48 #include "c-family/c-ubsan.h"
49 #include "gomp-constants.h"
50 #include "spellcheck-tree.h"
51 #include "gcc-rich-location.h"
52 #include "stringpool.h"
56 /* Possible cases of implicit bad conversions. Used to select
57 diagnostic messages in convert_for_assignment. */
65 /* The level of nesting inside "__alignof__". */
68 /* The level of nesting inside "sizeof". */
71 /* The level of nesting inside "typeof". */
74 /* The argument of last parsed sizeof expression, only to be tested
75 if expr.original_code == SIZEOF_EXPR. */
76 tree c_last_sizeof_arg
;
77 location_t c_last_sizeof_loc
;
79 /* Nonzero if we might need to print a "missing braces around
80 initializer" message within this initializer. */
81 static int found_missing_braces
;
83 static int require_constant_value
;
84 static int require_constant_elements
;
86 static bool null_pointer_constant_p (const_tree
);
87 static tree
qualify_type (tree
, tree
);
88 static int tagged_types_tu_compatible_p (const_tree
, const_tree
, bool *,
90 static int comp_target_types (location_t
, tree
, tree
);
91 static int function_types_compatible_p (const_tree
, const_tree
, bool *,
93 static int type_lists_compatible_p (const_tree
, const_tree
, bool *, bool *);
94 static tree
lookup_field (tree
, tree
);
95 static int convert_arguments (location_t
, vec
<location_t
>, tree
,
96 vec
<tree
, va_gc
> *, vec
<tree
, va_gc
> *, tree
,
98 static tree
pointer_diff (location_t
, tree
, tree
, tree
*);
99 static tree
convert_for_assignment (location_t
, location_t
, tree
, tree
, tree
,
100 enum impl_conv
, bool, tree
, tree
, int);
101 static tree
valid_compound_expr_initializer (tree
, tree
);
102 static void push_string (const char *);
103 static void push_member_name (tree
);
104 static int spelling_length (void);
105 static char *print_spelling (char *);
106 static void warning_init (location_t
, int, const char *);
107 static tree
digest_init (location_t
, tree
, tree
, tree
, bool, bool, int);
108 static void output_init_element (location_t
, tree
, tree
, bool, tree
, tree
, bool,
109 bool, struct obstack
*);
110 static void output_pending_init_elements (int, struct obstack
*);
111 static bool set_designator (location_t
, bool, struct obstack
*);
112 static void push_range_stack (tree
, struct obstack
*);
113 static void add_pending_init (location_t
, tree
, tree
, tree
, bool,
115 static void set_nonincremental_init (struct obstack
*);
116 static void set_nonincremental_init_from_string (tree
, struct obstack
*);
117 static tree
find_init_member (tree
, struct obstack
*);
118 static void readonly_warning (tree
, enum lvalue_use
);
119 static int lvalue_or_else (location_t
, const_tree
, enum lvalue_use
);
120 static void record_maybe_used_decl (tree
);
121 static int comptypes_internal (const_tree
, const_tree
, bool *, bool *);
123 /* Return true if EXP is a null pointer constant, false otherwise. */
126 null_pointer_constant_p (const_tree expr
)
128 /* This should really operate on c_expr structures, but they aren't
129 yet available everywhere required. */
130 tree type
= TREE_TYPE (expr
);
131 return (TREE_CODE (expr
) == INTEGER_CST
132 && !TREE_OVERFLOW (expr
)
133 && integer_zerop (expr
)
134 && (INTEGRAL_TYPE_P (type
)
135 || (TREE_CODE (type
) == POINTER_TYPE
136 && VOID_TYPE_P (TREE_TYPE (type
))
137 && TYPE_QUALS (TREE_TYPE (type
)) == TYPE_UNQUALIFIED
)));
140 /* EXPR may appear in an unevaluated part of an integer constant
141 expression, but not in an evaluated part. Wrap it in a
142 C_MAYBE_CONST_EXPR, or mark it with TREE_OVERFLOW if it is just an
143 INTEGER_CST and we cannot create a C_MAYBE_CONST_EXPR. */
146 note_integer_operands (tree expr
)
149 if (TREE_CODE (expr
) == INTEGER_CST
&& in_late_binary_op
)
151 ret
= copy_node (expr
);
152 TREE_OVERFLOW (ret
) = 1;
156 ret
= build2 (C_MAYBE_CONST_EXPR
, TREE_TYPE (expr
), NULL_TREE
, expr
);
157 C_MAYBE_CONST_EXPR_INT_OPERANDS (ret
) = 1;
162 /* Having checked whether EXPR may appear in an unevaluated part of an
163 integer constant expression and found that it may, remove any
164 C_MAYBE_CONST_EXPR noting this fact and return the resulting
168 remove_c_maybe_const_expr (tree expr
)
170 if (TREE_CODE (expr
) == C_MAYBE_CONST_EXPR
)
171 return C_MAYBE_CONST_EXPR_EXPR (expr
);
176 \f/* This is a cache to hold if two types are compatible or not. */
178 struct tagged_tu_seen_cache
{
179 const struct tagged_tu_seen_cache
* next
;
182 /* The return value of tagged_types_tu_compatible_p if we had seen
183 these two types already. */
187 static const struct tagged_tu_seen_cache
* tagged_tu_seen_base
;
188 static void free_all_tagged_tu_seen_up_to (const struct tagged_tu_seen_cache
*);
190 /* Do `exp = require_complete_type (loc, exp);' to make sure exp
191 does not have an incomplete type. (That includes void types.)
192 LOC is the location of the use. */
195 require_complete_type (location_t loc
, tree value
)
197 tree type
= TREE_TYPE (value
);
199 if (error_operand_p (value
))
200 return error_mark_node
;
202 /* First, detect a valid value with a complete type. */
203 if (COMPLETE_TYPE_P (type
))
206 c_incomplete_type_error (loc
, value
, type
);
207 return error_mark_node
;
210 /* Print an error message for invalid use of an incomplete type.
211 VALUE is the expression that was used (or 0 if that isn't known)
212 and TYPE is the type that was invalid. LOC is the location for
216 c_incomplete_type_error (location_t loc
, const_tree value
, const_tree type
)
218 /* Avoid duplicate error message. */
219 if (TREE_CODE (type
) == ERROR_MARK
)
222 if (value
!= NULL_TREE
&& (VAR_P (value
) || TREE_CODE (value
) == PARM_DECL
))
223 error_at (loc
, "%qD has an incomplete type %qT", value
, type
);
227 /* We must print an error message. Be clever about what it says. */
229 switch (TREE_CODE (type
))
237 error_at (loc
, "invalid use of void expression");
241 if (TYPE_DOMAIN (type
))
243 if (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) == NULL
)
245 error_at (loc
, "invalid use of flexible array member");
248 type
= TREE_TYPE (type
);
251 error_at (loc
, "invalid use of array with unspecified bounds");
258 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
259 error_at (loc
, "invalid use of undefined type %qT", type
);
261 /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL. */
262 error_at (loc
, "invalid use of incomplete typedef %qT", type
);
266 /* Given a type, apply default promotions wrt unnamed function
267 arguments and return the new type. */
270 c_type_promotes_to (tree type
)
272 tree ret
= NULL_TREE
;
274 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
275 ret
= double_type_node
;
276 else if (c_promoting_integer_type_p (type
))
278 /* Preserve unsignedness if not really getting any wider. */
279 if (TYPE_UNSIGNED (type
)
280 && (TYPE_PRECISION (type
) == TYPE_PRECISION (integer_type_node
)))
281 ret
= unsigned_type_node
;
283 ret
= integer_type_node
;
286 if (ret
!= NULL_TREE
)
287 return (TYPE_ATOMIC (type
)
288 ? c_build_qualified_type (ret
, TYPE_QUAL_ATOMIC
)
294 /* Return true if between two named address spaces, whether there is a superset
295 named address space that encompasses both address spaces. If there is a
296 superset, return which address space is the superset. */
299 addr_space_superset (addr_space_t as1
, addr_space_t as2
, addr_space_t
*common
)
306 else if (targetm
.addr_space
.subset_p (as1
, as2
))
311 else if (targetm
.addr_space
.subset_p (as2
, as1
))
320 /* Return a variant of TYPE which has all the type qualifiers of LIKE
321 as well as those of TYPE. */
324 qualify_type (tree type
, tree like
)
326 addr_space_t as_type
= TYPE_ADDR_SPACE (type
);
327 addr_space_t as_like
= TYPE_ADDR_SPACE (like
);
328 addr_space_t as_common
;
330 /* If the two named address spaces are different, determine the common
331 superset address space. If there isn't one, raise an error. */
332 if (!addr_space_superset (as_type
, as_like
, &as_common
))
335 error ("%qT and %qT are in disjoint named address spaces",
339 return c_build_qualified_type (type
,
340 TYPE_QUALS_NO_ADDR_SPACE (type
)
341 | TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (like
)
342 | ENCODE_QUAL_ADDR_SPACE (as_common
));
345 /* Return true iff the given tree T is a variable length array. */
348 c_vla_type_p (const_tree t
)
350 if (TREE_CODE (t
) == ARRAY_TYPE
351 && C_TYPE_VARIABLE_SIZE (t
))
356 /* Return the composite type of two compatible types.
358 We assume that comptypes has already been done and returned
359 nonzero; if that isn't so, this may crash. In particular, we
360 assume that qualifiers match. */
363 composite_type (tree t1
, tree t2
)
365 enum tree_code code1
;
366 enum tree_code code2
;
369 /* Save time if the two types are the same. */
371 if (t1
== t2
) return t1
;
373 /* If one type is nonsense, use the other. */
374 if (t1
== error_mark_node
)
376 if (t2
== error_mark_node
)
379 code1
= TREE_CODE (t1
);
380 code2
= TREE_CODE (t2
);
382 /* Merge the attributes. */
383 attributes
= targetm
.merge_type_attributes (t1
, t2
);
385 /* If one is an enumerated type and the other is the compatible
386 integer type, the composite type might be either of the two
387 (DR#013 question 3). For consistency, use the enumerated type as
388 the composite type. */
390 if (code1
== ENUMERAL_TYPE
&& code2
== INTEGER_TYPE
)
392 if (code2
== ENUMERAL_TYPE
&& code1
== INTEGER_TYPE
)
395 gcc_assert (code1
== code2
);
400 /* For two pointers, do this recursively on the target type. */
402 tree pointed_to_1
= TREE_TYPE (t1
);
403 tree pointed_to_2
= TREE_TYPE (t2
);
404 tree target
= composite_type (pointed_to_1
, pointed_to_2
);
405 t1
= build_pointer_type_for_mode (target
, TYPE_MODE (t1
), false);
406 t1
= build_type_attribute_variant (t1
, attributes
);
407 return qualify_type (t1
, t2
);
412 tree elt
= composite_type (TREE_TYPE (t1
), TREE_TYPE (t2
));
415 tree d1
= TYPE_DOMAIN (t1
);
416 tree d2
= TYPE_DOMAIN (t2
);
417 bool d1_variable
, d2_variable
;
418 bool d1_zero
, d2_zero
;
419 bool t1_complete
, t2_complete
;
421 /* We should not have any type quals on arrays at all. */
422 gcc_assert (!TYPE_QUALS_NO_ADDR_SPACE (t1
)
423 && !TYPE_QUALS_NO_ADDR_SPACE (t2
));
425 t1_complete
= COMPLETE_TYPE_P (t1
);
426 t2_complete
= COMPLETE_TYPE_P (t2
);
428 d1_zero
= d1
== NULL_TREE
|| !TYPE_MAX_VALUE (d1
);
429 d2_zero
= d2
== NULL_TREE
|| !TYPE_MAX_VALUE (d2
);
431 d1_variable
= (!d1_zero
432 && (TREE_CODE (TYPE_MIN_VALUE (d1
)) != INTEGER_CST
433 || TREE_CODE (TYPE_MAX_VALUE (d1
)) != INTEGER_CST
));
434 d2_variable
= (!d2_zero
435 && (TREE_CODE (TYPE_MIN_VALUE (d2
)) != INTEGER_CST
436 || TREE_CODE (TYPE_MAX_VALUE (d2
)) != INTEGER_CST
));
437 d1_variable
= d1_variable
|| (d1_zero
&& c_vla_type_p (t1
));
438 d2_variable
= d2_variable
|| (d2_zero
&& c_vla_type_p (t2
));
440 /* Save space: see if the result is identical to one of the args. */
441 if (elt
== TREE_TYPE (t1
) && TYPE_DOMAIN (t1
)
442 && (d2_variable
|| d2_zero
|| !d1_variable
))
443 return build_type_attribute_variant (t1
, attributes
);
444 if (elt
== TREE_TYPE (t2
) && TYPE_DOMAIN (t2
)
445 && (d1_variable
|| d1_zero
|| !d2_variable
))
446 return build_type_attribute_variant (t2
, attributes
);
448 if (elt
== TREE_TYPE (t1
) && !TYPE_DOMAIN (t2
) && !TYPE_DOMAIN (t1
))
449 return build_type_attribute_variant (t1
, attributes
);
450 if (elt
== TREE_TYPE (t2
) && !TYPE_DOMAIN (t2
) && !TYPE_DOMAIN (t1
))
451 return build_type_attribute_variant (t2
, attributes
);
453 /* Merge the element types, and have a size if either arg has
454 one. We may have qualifiers on the element types. To set
455 up TYPE_MAIN_VARIANT correctly, we need to form the
456 composite of the unqualified types and add the qualifiers
458 quals
= TYPE_QUALS (strip_array_types (elt
));
459 unqual_elt
= c_build_qualified_type (elt
, TYPE_UNQUALIFIED
);
460 t1
= build_array_type (unqual_elt
,
461 TYPE_DOMAIN ((TYPE_DOMAIN (t1
)
467 /* Ensure a composite type involving a zero-length array type
468 is a zero-length type not an incomplete type. */
469 if (d1_zero
&& d2_zero
470 && (t1_complete
|| t2_complete
)
471 && !COMPLETE_TYPE_P (t1
))
473 TYPE_SIZE (t1
) = bitsize_zero_node
;
474 TYPE_SIZE_UNIT (t1
) = size_zero_node
;
476 t1
= c_build_qualified_type (t1
, quals
);
477 return build_type_attribute_variant (t1
, attributes
);
483 if (attributes
!= NULL
)
485 /* Try harder not to create a new aggregate type. */
486 if (attribute_list_equal (TYPE_ATTRIBUTES (t1
), attributes
))
488 if (attribute_list_equal (TYPE_ATTRIBUTES (t2
), attributes
))
491 return build_type_attribute_variant (t1
, attributes
);
494 /* Function types: prefer the one that specified arg types.
495 If both do, merge the arg types. Also merge the return types. */
497 tree valtype
= composite_type (TREE_TYPE (t1
), TREE_TYPE (t2
));
498 tree p1
= TYPE_ARG_TYPES (t1
);
499 tree p2
= TYPE_ARG_TYPES (t2
);
504 /* Save space: see if the result is identical to one of the args. */
505 if (valtype
== TREE_TYPE (t1
) && !TYPE_ARG_TYPES (t2
))
506 return build_type_attribute_variant (t1
, attributes
);
507 if (valtype
== TREE_TYPE (t2
) && !TYPE_ARG_TYPES (t1
))
508 return build_type_attribute_variant (t2
, attributes
);
510 /* Simple way if one arg fails to specify argument types. */
511 if (TYPE_ARG_TYPES (t1
) == NULL_TREE
)
513 t1
= build_function_type (valtype
, TYPE_ARG_TYPES (t2
));
514 t1
= build_type_attribute_variant (t1
, attributes
);
515 return qualify_type (t1
, t2
);
517 if (TYPE_ARG_TYPES (t2
) == NULL_TREE
)
519 t1
= build_function_type (valtype
, TYPE_ARG_TYPES (t1
));
520 t1
= build_type_attribute_variant (t1
, attributes
);
521 return qualify_type (t1
, t2
);
524 /* If both args specify argument types, we must merge the two
525 lists, argument by argument. */
527 for (len
= 0, newargs
= p1
;
528 newargs
&& newargs
!= void_list_node
;
529 len
++, newargs
= TREE_CHAIN (newargs
))
532 for (i
= 0; i
< len
; i
++)
533 newargs
= tree_cons (NULL_TREE
, NULL_TREE
, newargs
);
537 for (; p1
&& p1
!= void_list_node
;
538 p1
= TREE_CHAIN (p1
), p2
= TREE_CHAIN (p2
), n
= TREE_CHAIN (n
))
540 /* A null type means arg type is not specified.
541 Take whatever the other function type has. */
542 if (TREE_VALUE (p1
) == NULL_TREE
)
544 TREE_VALUE (n
) = TREE_VALUE (p2
);
547 if (TREE_VALUE (p2
) == NULL_TREE
)
549 TREE_VALUE (n
) = TREE_VALUE (p1
);
553 /* Given wait (union {union wait *u; int *i} *)
554 and wait (union wait *),
555 prefer union wait * as type of parm. */
556 if (TREE_CODE (TREE_VALUE (p1
)) == UNION_TYPE
557 && TREE_VALUE (p1
) != TREE_VALUE (p2
))
560 tree mv2
= TREE_VALUE (p2
);
561 if (mv2
&& mv2
!= error_mark_node
562 && TREE_CODE (mv2
) != ARRAY_TYPE
)
563 mv2
= TYPE_MAIN_VARIANT (mv2
);
564 for (memb
= TYPE_FIELDS (TREE_VALUE (p1
));
565 memb
; memb
= DECL_CHAIN (memb
))
567 tree mv3
= TREE_TYPE (memb
);
568 if (mv3
&& mv3
!= error_mark_node
569 && TREE_CODE (mv3
) != ARRAY_TYPE
)
570 mv3
= TYPE_MAIN_VARIANT (mv3
);
571 if (comptypes (mv3
, mv2
))
573 TREE_VALUE (n
) = composite_type (TREE_TYPE (memb
),
575 pedwarn (input_location
, OPT_Wpedantic
,
576 "function types not truly compatible in ISO C");
581 if (TREE_CODE (TREE_VALUE (p2
)) == UNION_TYPE
582 && TREE_VALUE (p2
) != TREE_VALUE (p1
))
585 tree mv1
= TREE_VALUE (p1
);
586 if (mv1
&& mv1
!= error_mark_node
587 && TREE_CODE (mv1
) != ARRAY_TYPE
)
588 mv1
= TYPE_MAIN_VARIANT (mv1
);
589 for (memb
= TYPE_FIELDS (TREE_VALUE (p2
));
590 memb
; memb
= DECL_CHAIN (memb
))
592 tree mv3
= TREE_TYPE (memb
);
593 if (mv3
&& mv3
!= error_mark_node
594 && TREE_CODE (mv3
) != ARRAY_TYPE
)
595 mv3
= TYPE_MAIN_VARIANT (mv3
);
596 if (comptypes (mv3
, mv1
))
598 TREE_VALUE (n
) = composite_type (TREE_TYPE (memb
),
600 pedwarn (input_location
, OPT_Wpedantic
,
601 "function types not truly compatible in ISO C");
606 TREE_VALUE (n
) = composite_type (TREE_VALUE (p1
), TREE_VALUE (p2
));
610 t1
= build_function_type (valtype
, newargs
);
611 t1
= qualify_type (t1
, t2
);
616 return build_type_attribute_variant (t1
, attributes
);
621 /* Return the type of a conditional expression between pointers to
622 possibly differently qualified versions of compatible types.
624 We assume that comp_target_types has already been done and returned
625 nonzero; if that isn't so, this may crash. */
628 common_pointer_type (tree t1
, tree t2
)
631 tree pointed_to_1
, mv1
;
632 tree pointed_to_2
, mv2
;
634 unsigned target_quals
;
635 addr_space_t as1
, as2
, as_common
;
638 /* Save time if the two types are the same. */
640 if (t1
== t2
) return t1
;
642 /* If one type is nonsense, use the other. */
643 if (t1
== error_mark_node
)
645 if (t2
== error_mark_node
)
648 gcc_assert (TREE_CODE (t1
) == POINTER_TYPE
649 && TREE_CODE (t2
) == POINTER_TYPE
);
651 /* Merge the attributes. */
652 attributes
= targetm
.merge_type_attributes (t1
, t2
);
654 /* Find the composite type of the target types, and combine the
655 qualifiers of the two types' targets. Do not lose qualifiers on
656 array element types by taking the TYPE_MAIN_VARIANT. */
657 mv1
= pointed_to_1
= TREE_TYPE (t1
);
658 mv2
= pointed_to_2
= TREE_TYPE (t2
);
659 if (TREE_CODE (mv1
) != ARRAY_TYPE
)
660 mv1
= TYPE_MAIN_VARIANT (pointed_to_1
);
661 if (TREE_CODE (mv2
) != ARRAY_TYPE
)
662 mv2
= TYPE_MAIN_VARIANT (pointed_to_2
);
663 target
= composite_type (mv1
, mv2
);
665 /* Strip array types to get correct qualifier for pointers to arrays */
666 quals1
= TYPE_QUALS_NO_ADDR_SPACE (strip_array_types (pointed_to_1
));
667 quals2
= TYPE_QUALS_NO_ADDR_SPACE (strip_array_types (pointed_to_2
));
669 /* For function types do not merge const qualifiers, but drop them
670 if used inconsistently. The middle-end uses these to mark const
671 and noreturn functions. */
672 if (TREE_CODE (pointed_to_1
) == FUNCTION_TYPE
)
673 target_quals
= (quals1
& quals2
);
675 target_quals
= (quals1
| quals2
);
677 /* If the two named address spaces are different, determine the common
678 superset address space. This is guaranteed to exist due to the
679 assumption that comp_target_type returned non-zero. */
680 as1
= TYPE_ADDR_SPACE (pointed_to_1
);
681 as2
= TYPE_ADDR_SPACE (pointed_to_2
);
682 if (!addr_space_superset (as1
, as2
, &as_common
))
685 target_quals
|= ENCODE_QUAL_ADDR_SPACE (as_common
);
687 t1
= build_pointer_type (c_build_qualified_type (target
, target_quals
));
688 return build_type_attribute_variant (t1
, attributes
);
691 /* Return the common type for two arithmetic types under the usual
692 arithmetic conversions. The default conversions have already been
693 applied, and enumerated types converted to their compatible integer
694 types. The resulting type is unqualified and has no attributes.
696 This is the type for the result of most arithmetic operations
697 if the operands have the given two types. */
700 c_common_type (tree t1
, tree t2
)
702 enum tree_code code1
;
703 enum tree_code code2
;
705 /* If one type is nonsense, use the other. */
706 if (t1
== error_mark_node
)
708 if (t2
== error_mark_node
)
711 if (TYPE_QUALS (t1
) != TYPE_UNQUALIFIED
)
712 t1
= TYPE_MAIN_VARIANT (t1
);
714 if (TYPE_QUALS (t2
) != TYPE_UNQUALIFIED
)
715 t2
= TYPE_MAIN_VARIANT (t2
);
717 if (TYPE_ATTRIBUTES (t1
) != NULL_TREE
)
718 t1
= build_type_attribute_variant (t1
, NULL_TREE
);
720 if (TYPE_ATTRIBUTES (t2
) != NULL_TREE
)
721 t2
= build_type_attribute_variant (t2
, NULL_TREE
);
723 /* Save time if the two types are the same. */
725 if (t1
== t2
) return t1
;
727 code1
= TREE_CODE (t1
);
728 code2
= TREE_CODE (t2
);
730 gcc_assert (code1
== VECTOR_TYPE
|| code1
== COMPLEX_TYPE
731 || code1
== FIXED_POINT_TYPE
|| code1
== REAL_TYPE
732 || code1
== INTEGER_TYPE
);
733 gcc_assert (code2
== VECTOR_TYPE
|| code2
== COMPLEX_TYPE
734 || code2
== FIXED_POINT_TYPE
|| code2
== REAL_TYPE
735 || code2
== INTEGER_TYPE
);
737 /* When one operand is a decimal float type, the other operand cannot be
738 a generic float type or a complex type. We also disallow vector types
740 if ((DECIMAL_FLOAT_TYPE_P (t1
) || DECIMAL_FLOAT_TYPE_P (t2
))
741 && !(DECIMAL_FLOAT_TYPE_P (t1
) && DECIMAL_FLOAT_TYPE_P (t2
)))
743 if (code1
== VECTOR_TYPE
|| code2
== VECTOR_TYPE
)
745 error ("can%'t mix operands of decimal float and vector types");
746 return error_mark_node
;
748 if (code1
== COMPLEX_TYPE
|| code2
== COMPLEX_TYPE
)
750 error ("can%'t mix operands of decimal float and complex types");
751 return error_mark_node
;
753 if (code1
== REAL_TYPE
&& code2
== REAL_TYPE
)
755 error ("can%'t mix operands of decimal float and other float types");
756 return error_mark_node
;
760 /* If one type is a vector type, return that type. (How the usual
761 arithmetic conversions apply to the vector types extension is not
762 precisely specified.) */
763 if (code1
== VECTOR_TYPE
)
766 if (code2
== VECTOR_TYPE
)
769 /* If one type is complex, form the common type of the non-complex
770 components, then make that complex. Use T1 or T2 if it is the
772 if (code1
== COMPLEX_TYPE
|| code2
== COMPLEX_TYPE
)
774 tree subtype1
= code1
== COMPLEX_TYPE
? TREE_TYPE (t1
) : t1
;
775 tree subtype2
= code2
== COMPLEX_TYPE
? TREE_TYPE (t2
) : t2
;
776 tree subtype
= c_common_type (subtype1
, subtype2
);
778 if (code1
== COMPLEX_TYPE
&& TREE_TYPE (t1
) == subtype
)
780 else if (code2
== COMPLEX_TYPE
&& TREE_TYPE (t2
) == subtype
)
783 return build_complex_type (subtype
);
786 /* If only one is real, use it as the result. */
788 if (code1
== REAL_TYPE
&& code2
!= REAL_TYPE
)
791 if (code2
== REAL_TYPE
&& code1
!= REAL_TYPE
)
794 /* If both are real and either are decimal floating point types, use
795 the decimal floating point type with the greater precision. */
797 if (code1
== REAL_TYPE
&& code2
== REAL_TYPE
)
799 if (TYPE_MAIN_VARIANT (t1
) == dfloat128_type_node
800 || TYPE_MAIN_VARIANT (t2
) == dfloat128_type_node
)
801 return dfloat128_type_node
;
802 else if (TYPE_MAIN_VARIANT (t1
) == dfloat64_type_node
803 || TYPE_MAIN_VARIANT (t2
) == dfloat64_type_node
)
804 return dfloat64_type_node
;
805 else if (TYPE_MAIN_VARIANT (t1
) == dfloat32_type_node
806 || TYPE_MAIN_VARIANT (t2
) == dfloat32_type_node
)
807 return dfloat32_type_node
;
810 /* Deal with fixed-point types. */
811 if (code1
== FIXED_POINT_TYPE
|| code2
== FIXED_POINT_TYPE
)
813 unsigned int unsignedp
= 0, satp
= 0;
815 unsigned int fbit1
, ibit1
, fbit2
, ibit2
, max_fbit
, max_ibit
;
817 m1
= SCALAR_TYPE_MODE (t1
);
818 m2
= SCALAR_TYPE_MODE (t2
);
820 /* If one input type is saturating, the result type is saturating. */
821 if (TYPE_SATURATING (t1
) || TYPE_SATURATING (t2
))
824 /* If both fixed-point types are unsigned, the result type is unsigned.
825 When mixing fixed-point and integer types, follow the sign of the
827 Otherwise, the result type is signed. */
828 if ((TYPE_UNSIGNED (t1
) && TYPE_UNSIGNED (t2
)
829 && code1
== FIXED_POINT_TYPE
&& code2
== FIXED_POINT_TYPE
)
830 || (code1
== FIXED_POINT_TYPE
&& code2
!= FIXED_POINT_TYPE
831 && TYPE_UNSIGNED (t1
))
832 || (code1
!= FIXED_POINT_TYPE
&& code2
== FIXED_POINT_TYPE
833 && TYPE_UNSIGNED (t2
)))
836 /* The result type is signed. */
839 /* If the input type is unsigned, we need to convert to the
841 if (code1
== FIXED_POINT_TYPE
&& TYPE_UNSIGNED (t1
))
843 enum mode_class mclass
= (enum mode_class
) 0;
844 if (GET_MODE_CLASS (m1
) == MODE_UFRACT
)
846 else if (GET_MODE_CLASS (m1
) == MODE_UACCUM
)
850 m1
= as_a
<scalar_mode
>
851 (mode_for_size (GET_MODE_PRECISION (m1
), mclass
, 0));
853 if (code2
== FIXED_POINT_TYPE
&& TYPE_UNSIGNED (t2
))
855 enum mode_class mclass
= (enum mode_class
) 0;
856 if (GET_MODE_CLASS (m2
) == MODE_UFRACT
)
858 else if (GET_MODE_CLASS (m2
) == MODE_UACCUM
)
862 m2
= as_a
<scalar_mode
>
863 (mode_for_size (GET_MODE_PRECISION (m2
), mclass
, 0));
867 if (code1
== FIXED_POINT_TYPE
)
869 fbit1
= GET_MODE_FBIT (m1
);
870 ibit1
= GET_MODE_IBIT (m1
);
875 /* Signed integers need to subtract one sign bit. */
876 ibit1
= TYPE_PRECISION (t1
) - (!TYPE_UNSIGNED (t1
));
879 if (code2
== FIXED_POINT_TYPE
)
881 fbit2
= GET_MODE_FBIT (m2
);
882 ibit2
= GET_MODE_IBIT (m2
);
887 /* Signed integers need to subtract one sign bit. */
888 ibit2
= TYPE_PRECISION (t2
) - (!TYPE_UNSIGNED (t2
));
891 max_ibit
= ibit1
>= ibit2
? ibit1
: ibit2
;
892 max_fbit
= fbit1
>= fbit2
? fbit1
: fbit2
;
893 return c_common_fixed_point_type_for_size (max_ibit
, max_fbit
, unsignedp
,
897 /* Both real or both integers; use the one with greater precision. */
899 if (TYPE_PRECISION (t1
) > TYPE_PRECISION (t2
))
901 else if (TYPE_PRECISION (t2
) > TYPE_PRECISION (t1
))
904 /* Same precision. Prefer long longs to longs to ints when the
905 same precision, following the C99 rules on integer type rank
906 (which are equivalent to the C90 rules for C90 types). */
908 if (TYPE_MAIN_VARIANT (t1
) == long_long_unsigned_type_node
909 || TYPE_MAIN_VARIANT (t2
) == long_long_unsigned_type_node
)
910 return long_long_unsigned_type_node
;
912 if (TYPE_MAIN_VARIANT (t1
) == long_long_integer_type_node
913 || TYPE_MAIN_VARIANT (t2
) == long_long_integer_type_node
)
915 if (TYPE_UNSIGNED (t1
) || TYPE_UNSIGNED (t2
))
916 return long_long_unsigned_type_node
;
918 return long_long_integer_type_node
;
921 if (TYPE_MAIN_VARIANT (t1
) == long_unsigned_type_node
922 || TYPE_MAIN_VARIANT (t2
) == long_unsigned_type_node
)
923 return long_unsigned_type_node
;
925 if (TYPE_MAIN_VARIANT (t1
) == long_integer_type_node
926 || TYPE_MAIN_VARIANT (t2
) == long_integer_type_node
)
928 /* But preserve unsignedness from the other type,
929 since long cannot hold all the values of an unsigned int. */
930 if (TYPE_UNSIGNED (t1
) || TYPE_UNSIGNED (t2
))
931 return long_unsigned_type_node
;
933 return long_integer_type_node
;
936 /* For floating types of the same TYPE_PRECISION (which we here
937 assume means either the same set of values, or sets of values
938 neither a subset of the other, with behavior being undefined in
939 the latter case), follow the rules from TS 18661-3: prefer
940 interchange types _FloatN, then standard types long double,
941 double, float, then extended types _FloatNx. For extended types,
942 check them starting with _Float128x as that seems most consistent
943 in spirit with preferring long double to double; for interchange
944 types, also check in that order for consistency although it's not
945 possible for more than one of them to have the same
947 tree mv1
= TYPE_MAIN_VARIANT (t1
);
948 tree mv2
= TYPE_MAIN_VARIANT (t2
);
950 for (int i
= NUM_FLOATN_TYPES
- 1; i
>= 0; i
--)
951 if (mv1
== FLOATN_TYPE_NODE (i
) || mv2
== FLOATN_TYPE_NODE (i
))
952 return FLOATN_TYPE_NODE (i
);
954 /* Likewise, prefer long double to double even if same size. */
955 if (mv1
== long_double_type_node
|| mv2
== long_double_type_node
)
956 return long_double_type_node
;
958 /* Likewise, prefer double to float even if same size.
959 We got a couple of embedded targets with 32 bit doubles, and the
960 pdp11 might have 64 bit floats. */
961 if (mv1
== double_type_node
|| mv2
== double_type_node
)
962 return double_type_node
;
964 if (mv1
== float_type_node
|| mv2
== float_type_node
)
965 return float_type_node
;
967 for (int i
= NUM_FLOATNX_TYPES
- 1; i
>= 0; i
--)
968 if (mv1
== FLOATNX_TYPE_NODE (i
) || mv2
== FLOATNX_TYPE_NODE (i
))
969 return FLOATNX_TYPE_NODE (i
);
971 /* Otherwise prefer the unsigned one. */
973 if (TYPE_UNSIGNED (t1
))
979 /* Wrapper around c_common_type that is used by c-common.c and other
980 front end optimizations that remove promotions. ENUMERAL_TYPEs
981 are allowed here and are converted to their compatible integer types.
982 BOOLEAN_TYPEs are allowed here and return either boolean_type_node or
983 preferably a non-Boolean type as the common type. */
985 common_type (tree t1
, tree t2
)
987 if (TREE_CODE (t1
) == ENUMERAL_TYPE
)
988 t1
= c_common_type_for_size (TYPE_PRECISION (t1
), 1);
989 if (TREE_CODE (t2
) == ENUMERAL_TYPE
)
990 t2
= c_common_type_for_size (TYPE_PRECISION (t2
), 1);
992 /* If both types are BOOLEAN_TYPE, then return boolean_type_node. */
993 if (TREE_CODE (t1
) == BOOLEAN_TYPE
994 && TREE_CODE (t2
) == BOOLEAN_TYPE
)
995 return boolean_type_node
;
997 /* If either type is BOOLEAN_TYPE, then return the other. */
998 if (TREE_CODE (t1
) == BOOLEAN_TYPE
)
1000 if (TREE_CODE (t2
) == BOOLEAN_TYPE
)
1003 return c_common_type (t1
, t2
);
1006 /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
1007 or various other operations. Return 2 if they are compatible
1008 but a warning may be needed if you use them together. */
1011 comptypes (tree type1
, tree type2
)
1013 const struct tagged_tu_seen_cache
* tagged_tu_seen_base1
= tagged_tu_seen_base
;
1016 val
= comptypes_internal (type1
, type2
, NULL
, NULL
);
1017 free_all_tagged_tu_seen_up_to (tagged_tu_seen_base1
);
1022 /* Like comptypes, but if it returns non-zero because enum and int are
1023 compatible, it sets *ENUM_AND_INT_P to true. */
1026 comptypes_check_enum_int (tree type1
, tree type2
, bool *enum_and_int_p
)
1028 const struct tagged_tu_seen_cache
* tagged_tu_seen_base1
= tagged_tu_seen_base
;
1031 val
= comptypes_internal (type1
, type2
, enum_and_int_p
, NULL
);
1032 free_all_tagged_tu_seen_up_to (tagged_tu_seen_base1
);
1037 /* Like comptypes, but if it returns nonzero for different types, it
1038 sets *DIFFERENT_TYPES_P to true. */
1041 comptypes_check_different_types (tree type1
, tree type2
,
1042 bool *different_types_p
)
1044 const struct tagged_tu_seen_cache
* tagged_tu_seen_base1
= tagged_tu_seen_base
;
1047 val
= comptypes_internal (type1
, type2
, NULL
, different_types_p
);
1048 free_all_tagged_tu_seen_up_to (tagged_tu_seen_base1
);
1053 /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
1054 or various other operations. Return 2 if they are compatible
1055 but a warning may be needed if you use them together. If
1056 ENUM_AND_INT_P is not NULL, and one type is an enum and the other a
1057 compatible integer type, then this sets *ENUM_AND_INT_P to true;
1058 *ENUM_AND_INT_P is never set to false. If DIFFERENT_TYPES_P is not
1059 NULL, and the types are compatible but different enough not to be
1060 permitted in C11 typedef redeclarations, then this sets
1061 *DIFFERENT_TYPES_P to true; *DIFFERENT_TYPES_P is never set to
1062 false, but may or may not be set if the types are incompatible.
1063 This differs from comptypes, in that we don't free the seen
1067 comptypes_internal (const_tree type1
, const_tree type2
, bool *enum_and_int_p
,
1068 bool *different_types_p
)
1070 const_tree t1
= type1
;
1071 const_tree t2
= type2
;
1074 /* Suppress errors caused by previously reported errors. */
1076 if (t1
== t2
|| !t1
|| !t2
1077 || TREE_CODE (t1
) == ERROR_MARK
|| TREE_CODE (t2
) == ERROR_MARK
)
1080 /* Enumerated types are compatible with integer types, but this is
1081 not transitive: two enumerated types in the same translation unit
1082 are compatible with each other only if they are the same type. */
1084 if (TREE_CODE (t1
) == ENUMERAL_TYPE
&& TREE_CODE (t2
) != ENUMERAL_TYPE
)
1086 t1
= c_common_type_for_size (TYPE_PRECISION (t1
), TYPE_UNSIGNED (t1
));
1087 if (TREE_CODE (t2
) != VOID_TYPE
)
1089 if (enum_and_int_p
!= NULL
)
1090 *enum_and_int_p
= true;
1091 if (different_types_p
!= NULL
)
1092 *different_types_p
= true;
1095 else if (TREE_CODE (t2
) == ENUMERAL_TYPE
&& TREE_CODE (t1
) != ENUMERAL_TYPE
)
1097 t2
= c_common_type_for_size (TYPE_PRECISION (t2
), TYPE_UNSIGNED (t2
));
1098 if (TREE_CODE (t1
) != VOID_TYPE
)
1100 if (enum_and_int_p
!= NULL
)
1101 *enum_and_int_p
= true;
1102 if (different_types_p
!= NULL
)
1103 *different_types_p
= true;
1110 /* Different classes of types can't be compatible. */
1112 if (TREE_CODE (t1
) != TREE_CODE (t2
))
1115 /* Qualifiers must match. C99 6.7.3p9 */
1117 if (TYPE_QUALS (t1
) != TYPE_QUALS (t2
))
1120 /* Allow for two different type nodes which have essentially the same
1121 definition. Note that we already checked for equality of the type
1122 qualifiers (just above). */
1124 if (TREE_CODE (t1
) != ARRAY_TYPE
1125 && TYPE_MAIN_VARIANT (t1
) == TYPE_MAIN_VARIANT (t2
))
1128 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
1129 if (!(attrval
= comp_type_attributes (t1
, t2
)))
1132 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
1135 switch (TREE_CODE (t1
))
1138 case FIXED_POINT_TYPE
:
1140 /* With these nodes, we can't determine type equivalence by
1141 looking at what is stored in the nodes themselves, because
1142 two nodes might have different TYPE_MAIN_VARIANTs but still
1143 represent the same type. For example, wchar_t and int could
1144 have the same properties (TYPE_PRECISION, TYPE_MIN_VALUE,
1145 TYPE_MAX_VALUE, etc.), but have different TYPE_MAIN_VARIANTs
1146 and are distinct types. On the other hand, int and the
1149 typedef int INT __attribute((may_alias));
1151 have identical properties, different TYPE_MAIN_VARIANTs, but
1152 represent the same type. The canonical type system keeps
1153 track of equivalence in this case, so we fall back on it. */
1154 return TYPE_CANONICAL (t1
) == TYPE_CANONICAL (t2
);
1157 /* Do not remove mode information. */
1158 if (TYPE_MODE (t1
) != TYPE_MODE (t2
))
1160 val
= (TREE_TYPE (t1
) == TREE_TYPE (t2
)
1161 ? 1 : comptypes_internal (TREE_TYPE (t1
), TREE_TYPE (t2
),
1162 enum_and_int_p
, different_types_p
));
1166 val
= function_types_compatible_p (t1
, t2
, enum_and_int_p
,
1172 tree d1
= TYPE_DOMAIN (t1
);
1173 tree d2
= TYPE_DOMAIN (t2
);
1174 bool d1_variable
, d2_variable
;
1175 bool d1_zero
, d2_zero
;
1178 /* Target types must match incl. qualifiers. */
1179 if (TREE_TYPE (t1
) != TREE_TYPE (t2
)
1180 && (val
= comptypes_internal (TREE_TYPE (t1
), TREE_TYPE (t2
),
1182 different_types_p
)) == 0)
1185 if (different_types_p
!= NULL
1186 && (d1
== NULL_TREE
) != (d2
== NULL_TREE
))
1187 *different_types_p
= true;
1188 /* Sizes must match unless one is missing or variable. */
1189 if (d1
== NULL_TREE
|| d2
== NULL_TREE
|| d1
== d2
)
1192 d1_zero
= !TYPE_MAX_VALUE (d1
);
1193 d2_zero
= !TYPE_MAX_VALUE (d2
);
1195 d1_variable
= (!d1_zero
1196 && (TREE_CODE (TYPE_MIN_VALUE (d1
)) != INTEGER_CST
1197 || TREE_CODE (TYPE_MAX_VALUE (d1
)) != INTEGER_CST
));
1198 d2_variable
= (!d2_zero
1199 && (TREE_CODE (TYPE_MIN_VALUE (d2
)) != INTEGER_CST
1200 || TREE_CODE (TYPE_MAX_VALUE (d2
)) != INTEGER_CST
));
1201 d1_variable
= d1_variable
|| (d1_zero
&& c_vla_type_p (t1
));
1202 d2_variable
= d2_variable
|| (d2_zero
&& c_vla_type_p (t2
));
1204 if (different_types_p
!= NULL
1205 && d1_variable
!= d2_variable
)
1206 *different_types_p
= true;
1207 if (d1_variable
|| d2_variable
)
1209 if (d1_zero
&& d2_zero
)
1211 if (d1_zero
|| d2_zero
1212 || !tree_int_cst_equal (TYPE_MIN_VALUE (d1
), TYPE_MIN_VALUE (d2
))
1213 || !tree_int_cst_equal (TYPE_MAX_VALUE (d1
), TYPE_MAX_VALUE (d2
)))
1222 if (val
!= 1 && !same_translation_unit_p (t1
, t2
))
1224 tree a1
= TYPE_ATTRIBUTES (t1
);
1225 tree a2
= TYPE_ATTRIBUTES (t2
);
1227 if (! attribute_list_contained (a1
, a2
)
1228 && ! attribute_list_contained (a2
, a1
))
1232 return tagged_types_tu_compatible_p (t1
, t2
, enum_and_int_p
,
1234 val
= tagged_types_tu_compatible_p (t1
, t2
, enum_and_int_p
,
1240 val
= (known_eq (TYPE_VECTOR_SUBPARTS (t1
), TYPE_VECTOR_SUBPARTS (t2
))
1241 && comptypes_internal (TREE_TYPE (t1
), TREE_TYPE (t2
),
1242 enum_and_int_p
, different_types_p
));
1248 return attrval
== 2 && val
== 1 ? 2 : val
;
1251 /* Return 1 if TTL and TTR are pointers to types that are equivalent, ignoring
1252 their qualifiers, except for named address spaces. If the pointers point to
1253 different named addresses, then we must determine if one address space is a
1254 subset of the other. */
1257 comp_target_types (location_t location
, tree ttl
, tree ttr
)
1261 tree mvl
= TREE_TYPE (ttl
);
1262 tree mvr
= TREE_TYPE (ttr
);
1263 addr_space_t asl
= TYPE_ADDR_SPACE (mvl
);
1264 addr_space_t asr
= TYPE_ADDR_SPACE (mvr
);
1265 addr_space_t as_common
;
1266 bool enum_and_int_p
;
1268 /* Fail if pointers point to incompatible address spaces. */
1269 if (!addr_space_superset (asl
, asr
, &as_common
))
1272 /* For pedantic record result of comptypes on arrays before losing
1273 qualifiers on the element type below. */
1276 if (TREE_CODE (mvl
) == ARRAY_TYPE
1277 && TREE_CODE (mvr
) == ARRAY_TYPE
)
1278 val_ped
= comptypes (mvl
, mvr
);
1280 /* Qualifiers on element types of array types that are
1281 pointer targets are lost by taking their TYPE_MAIN_VARIANT. */
1283 mvl
= (TYPE_ATOMIC (strip_array_types (mvl
))
1284 ? c_build_qualified_type (TYPE_MAIN_VARIANT (mvl
), TYPE_QUAL_ATOMIC
)
1285 : TYPE_MAIN_VARIANT (mvl
));
1287 mvr
= (TYPE_ATOMIC (strip_array_types (mvr
))
1288 ? c_build_qualified_type (TYPE_MAIN_VARIANT (mvr
), TYPE_QUAL_ATOMIC
)
1289 : TYPE_MAIN_VARIANT (mvr
));
1291 enum_and_int_p
= false;
1292 val
= comptypes_check_enum_int (mvl
, mvr
, &enum_and_int_p
);
1294 if (val
== 1 && val_ped
!= 1)
1295 pedwarn (location
, OPT_Wpedantic
, "pointers to arrays with different qualifiers "
1296 "are incompatible in ISO C");
1299 pedwarn (location
, OPT_Wpedantic
, "types are not quite compatible");
1301 if (val
== 1 && enum_and_int_p
&& warn_cxx_compat
)
1302 warning_at (location
, OPT_Wc___compat
,
1303 "pointer target types incompatible in C++");
1308 /* Subroutines of `comptypes'. */
1310 /* Determine whether two trees derive from the same translation unit.
1311 If the CONTEXT chain ends in a null, that tree's context is still
1312 being parsed, so if two trees have context chains ending in null,
1313 they're in the same translation unit. */
1316 same_translation_unit_p (const_tree t1
, const_tree t2
)
1318 while (t1
&& TREE_CODE (t1
) != TRANSLATION_UNIT_DECL
)
1319 switch (TREE_CODE_CLASS (TREE_CODE (t1
)))
1321 case tcc_declaration
:
1322 t1
= DECL_CONTEXT (t1
); break;
1324 t1
= TYPE_CONTEXT (t1
); break;
1325 case tcc_exceptional
:
1326 t1
= BLOCK_SUPERCONTEXT (t1
); break; /* assume block */
1327 default: gcc_unreachable ();
1330 while (t2
&& TREE_CODE (t2
) != TRANSLATION_UNIT_DECL
)
1331 switch (TREE_CODE_CLASS (TREE_CODE (t2
)))
1333 case tcc_declaration
:
1334 t2
= DECL_CONTEXT (t2
); break;
1336 t2
= TYPE_CONTEXT (t2
); break;
1337 case tcc_exceptional
:
1338 t2
= BLOCK_SUPERCONTEXT (t2
); break; /* assume block */
1339 default: gcc_unreachable ();
1345 /* Allocate the seen two types, assuming that they are compatible. */
1347 static struct tagged_tu_seen_cache
*
1348 alloc_tagged_tu_seen_cache (const_tree t1
, const_tree t2
)
1350 struct tagged_tu_seen_cache
*tu
= XNEW (struct tagged_tu_seen_cache
);
1351 tu
->next
= tagged_tu_seen_base
;
1355 tagged_tu_seen_base
= tu
;
1357 /* The C standard says that two structures in different translation
1358 units are compatible with each other only if the types of their
1359 fields are compatible (among other things). We assume that they
1360 are compatible until proven otherwise when building the cache.
1361 An example where this can occur is:
1366 If we are comparing this against a similar struct in another TU,
1367 and did not assume they were compatible, we end up with an infinite
1373 /* Free the seen types until we get to TU_TIL. */
1376 free_all_tagged_tu_seen_up_to (const struct tagged_tu_seen_cache
*tu_til
)
1378 const struct tagged_tu_seen_cache
*tu
= tagged_tu_seen_base
;
1379 while (tu
!= tu_til
)
1381 const struct tagged_tu_seen_cache
*const tu1
1382 = (const struct tagged_tu_seen_cache
*) tu
;
1384 free (CONST_CAST (struct tagged_tu_seen_cache
*, tu1
));
1386 tagged_tu_seen_base
= tu_til
;
1389 /* Return 1 if two 'struct', 'union', or 'enum' types T1 and T2 are
1390 compatible. If the two types are not the same (which has been
1391 checked earlier), this can only happen when multiple translation
1392 units are being compiled. See C99 6.2.7 paragraph 1 for the exact
1393 rules. ENUM_AND_INT_P and DIFFERENT_TYPES_P are as in
1394 comptypes_internal. */
1397 tagged_types_tu_compatible_p (const_tree t1
, const_tree t2
,
1398 bool *enum_and_int_p
, bool *different_types_p
)
1401 bool needs_warning
= false;
1403 /* We have to verify that the tags of the types are the same. This
1404 is harder than it looks because this may be a typedef, so we have
1405 to go look at the original type. It may even be a typedef of a
1407 In the case of compiler-created builtin structs the TYPE_DECL
1408 may be a dummy, with no DECL_ORIGINAL_TYPE. Don't fault. */
1409 while (TYPE_NAME (t1
)
1410 && TREE_CODE (TYPE_NAME (t1
)) == TYPE_DECL
1411 && DECL_ORIGINAL_TYPE (TYPE_NAME (t1
)))
1412 t1
= DECL_ORIGINAL_TYPE (TYPE_NAME (t1
));
1414 while (TYPE_NAME (t2
)
1415 && TREE_CODE (TYPE_NAME (t2
)) == TYPE_DECL
1416 && DECL_ORIGINAL_TYPE (TYPE_NAME (t2
)))
1417 t2
= DECL_ORIGINAL_TYPE (TYPE_NAME (t2
));
1419 /* C90 didn't have the requirement that the two tags be the same. */
1420 if (flag_isoc99
&& TYPE_NAME (t1
) != TYPE_NAME (t2
))
1423 /* C90 didn't say what happened if one or both of the types were
1424 incomplete; we choose to follow C99 rules here, which is that they
1426 if (TYPE_SIZE (t1
) == NULL
1427 || TYPE_SIZE (t2
) == NULL
)
1431 const struct tagged_tu_seen_cache
* tts_i
;
1432 for (tts_i
= tagged_tu_seen_base
; tts_i
!= NULL
; tts_i
= tts_i
->next
)
1433 if (tts_i
->t1
== t1
&& tts_i
->t2
== t2
)
1437 switch (TREE_CODE (t1
))
1441 struct tagged_tu_seen_cache
*tu
= alloc_tagged_tu_seen_cache (t1
, t2
);
1442 /* Speed up the case where the type values are in the same order. */
1443 tree tv1
= TYPE_VALUES (t1
);
1444 tree tv2
= TYPE_VALUES (t2
);
1451 for (;tv1
&& tv2
; tv1
= TREE_CHAIN (tv1
), tv2
= TREE_CHAIN (tv2
))
1453 if (TREE_PURPOSE (tv1
) != TREE_PURPOSE (tv2
))
1455 if (simple_cst_equal (TREE_VALUE (tv1
), TREE_VALUE (tv2
)) != 1)
1462 if (tv1
== NULL_TREE
&& tv2
== NULL_TREE
)
1466 if (tv1
== NULL_TREE
|| tv2
== NULL_TREE
)
1472 if (list_length (TYPE_VALUES (t1
)) != list_length (TYPE_VALUES (t2
)))
1478 for (s1
= TYPE_VALUES (t1
); s1
; s1
= TREE_CHAIN (s1
))
1480 s2
= purpose_member (TREE_PURPOSE (s1
), TYPE_VALUES (t2
));
1482 || simple_cst_equal (TREE_VALUE (s1
), TREE_VALUE (s2
)) != 1)
1493 struct tagged_tu_seen_cache
*tu
= alloc_tagged_tu_seen_cache (t1
, t2
);
1494 if (list_length (TYPE_FIELDS (t1
)) != list_length (TYPE_FIELDS (t2
)))
1500 /* Speed up the common case where the fields are in the same order. */
1501 for (s1
= TYPE_FIELDS (t1
), s2
= TYPE_FIELDS (t2
); s1
&& s2
;
1502 s1
= DECL_CHAIN (s1
), s2
= DECL_CHAIN (s2
))
1506 if (DECL_NAME (s1
) != DECL_NAME (s2
))
1508 result
= comptypes_internal (TREE_TYPE (s1
), TREE_TYPE (s2
),
1509 enum_and_int_p
, different_types_p
);
1511 if (result
!= 1 && !DECL_NAME (s1
))
1519 needs_warning
= true;
1521 if (TREE_CODE (s1
) == FIELD_DECL
1522 && simple_cst_equal (DECL_FIELD_BIT_OFFSET (s1
),
1523 DECL_FIELD_BIT_OFFSET (s2
)) != 1)
1531 tu
->val
= needs_warning
? 2 : 1;
1535 for (s1
= TYPE_FIELDS (t1
); s1
; s1
= DECL_CHAIN (s1
))
1539 for (s2
= TYPE_FIELDS (t2
); s2
; s2
= DECL_CHAIN (s2
))
1540 if (DECL_NAME (s1
) == DECL_NAME (s2
))
1544 result
= comptypes_internal (TREE_TYPE (s1
), TREE_TYPE (s2
),
1548 if (result
!= 1 && !DECL_NAME (s1
))
1556 needs_warning
= true;
1558 if (TREE_CODE (s1
) == FIELD_DECL
1559 && simple_cst_equal (DECL_FIELD_BIT_OFFSET (s1
),
1560 DECL_FIELD_BIT_OFFSET (s2
)) != 1)
1572 tu
->val
= needs_warning
? 2 : 10;
1578 struct tagged_tu_seen_cache
*tu
= alloc_tagged_tu_seen_cache (t1
, t2
);
1580 for (s1
= TYPE_FIELDS (t1
), s2
= TYPE_FIELDS (t2
);
1582 s1
= DECL_CHAIN (s1
), s2
= DECL_CHAIN (s2
))
1585 if (TREE_CODE (s1
) != TREE_CODE (s2
)
1586 || DECL_NAME (s1
) != DECL_NAME (s2
))
1588 result
= comptypes_internal (TREE_TYPE (s1
), TREE_TYPE (s2
),
1589 enum_and_int_p
, different_types_p
);
1593 needs_warning
= true;
1595 if (TREE_CODE (s1
) == FIELD_DECL
1596 && simple_cst_equal (DECL_FIELD_BIT_OFFSET (s1
),
1597 DECL_FIELD_BIT_OFFSET (s2
)) != 1)
1603 tu
->val
= needs_warning
? 2 : 1;
1612 /* Return 1 if two function types F1 and F2 are compatible.
1613 If either type specifies no argument types,
1614 the other must specify a fixed number of self-promoting arg types.
1615 Otherwise, if one type specifies only the number of arguments,
1616 the other must specify that number of self-promoting arg types.
1617 Otherwise, the argument types must match.
1618 ENUM_AND_INT_P and DIFFERENT_TYPES_P are as in comptypes_internal. */
1621 function_types_compatible_p (const_tree f1
, const_tree f2
,
1622 bool *enum_and_int_p
, bool *different_types_p
)
1625 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
1630 ret1
= TREE_TYPE (f1
);
1631 ret2
= TREE_TYPE (f2
);
1633 /* 'volatile' qualifiers on a function's return type used to mean
1634 the function is noreturn. */
1635 if (TYPE_VOLATILE (ret1
) != TYPE_VOLATILE (ret2
))
1636 pedwarn (input_location
, 0, "function return types not compatible due to %<volatile%>");
1637 if (TYPE_VOLATILE (ret1
))
1638 ret1
= build_qualified_type (TYPE_MAIN_VARIANT (ret1
),
1639 TYPE_QUALS (ret1
) & ~TYPE_QUAL_VOLATILE
);
1640 if (TYPE_VOLATILE (ret2
))
1641 ret2
= build_qualified_type (TYPE_MAIN_VARIANT (ret2
),
1642 TYPE_QUALS (ret2
) & ~TYPE_QUAL_VOLATILE
);
1643 val
= comptypes_internal (ret1
, ret2
, enum_and_int_p
, different_types_p
);
1647 args1
= TYPE_ARG_TYPES (f1
);
1648 args2
= TYPE_ARG_TYPES (f2
);
1650 if (different_types_p
!= NULL
1651 && (args1
== NULL_TREE
) != (args2
== NULL_TREE
))
1652 *different_types_p
= true;
1654 /* An unspecified parmlist matches any specified parmlist
1655 whose argument types don't need default promotions. */
1657 if (args1
== NULL_TREE
)
1659 if (!self_promoting_args_p (args2
))
1661 /* If one of these types comes from a non-prototype fn definition,
1662 compare that with the other type's arglist.
1663 If they don't match, ask for a warning (but no error). */
1664 if (TYPE_ACTUAL_ARG_TYPES (f1
)
1665 && type_lists_compatible_p (args2
, TYPE_ACTUAL_ARG_TYPES (f1
),
1666 enum_and_int_p
, different_types_p
) != 1)
1670 if (args2
== NULL_TREE
)
1672 if (!self_promoting_args_p (args1
))
1674 if (TYPE_ACTUAL_ARG_TYPES (f2
)
1675 && type_lists_compatible_p (args1
, TYPE_ACTUAL_ARG_TYPES (f2
),
1676 enum_and_int_p
, different_types_p
) != 1)
1681 /* Both types have argument lists: compare them and propagate results. */
1682 val1
= type_lists_compatible_p (args1
, args2
, enum_and_int_p
,
1684 return val1
!= 1 ? val1
: val
;
1687 /* Check two lists of types for compatibility, returning 0 for
1688 incompatible, 1 for compatible, or 2 for compatible with
1689 warning. ENUM_AND_INT_P and DIFFERENT_TYPES_P are as in
1690 comptypes_internal. */
1693 type_lists_compatible_p (const_tree args1
, const_tree args2
,
1694 bool *enum_and_int_p
, bool *different_types_p
)
1696 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
1702 tree a1
, mv1
, a2
, mv2
;
1703 if (args1
== NULL_TREE
&& args2
== NULL_TREE
)
1705 /* If one list is shorter than the other,
1706 they fail to match. */
1707 if (args1
== NULL_TREE
|| args2
== NULL_TREE
)
1709 mv1
= a1
= TREE_VALUE (args1
);
1710 mv2
= a2
= TREE_VALUE (args2
);
1711 if (mv1
&& mv1
!= error_mark_node
&& TREE_CODE (mv1
) != ARRAY_TYPE
)
1712 mv1
= (TYPE_ATOMIC (mv1
)
1713 ? c_build_qualified_type (TYPE_MAIN_VARIANT (mv1
),
1715 : TYPE_MAIN_VARIANT (mv1
));
1716 if (mv2
&& mv2
!= error_mark_node
&& TREE_CODE (mv2
) != ARRAY_TYPE
)
1717 mv2
= (TYPE_ATOMIC (mv2
)
1718 ? c_build_qualified_type (TYPE_MAIN_VARIANT (mv2
),
1720 : TYPE_MAIN_VARIANT (mv2
));
1721 /* A null pointer instead of a type
1722 means there is supposed to be an argument
1723 but nothing is specified about what type it has.
1724 So match anything that self-promotes. */
1725 if (different_types_p
!= NULL
1726 && (a1
== NULL_TREE
) != (a2
== NULL_TREE
))
1727 *different_types_p
= true;
1728 if (a1
== NULL_TREE
)
1730 if (c_type_promotes_to (a2
) != a2
)
1733 else if (a2
== NULL_TREE
)
1735 if (c_type_promotes_to (a1
) != a1
)
1738 /* If one of the lists has an error marker, ignore this arg. */
1739 else if (TREE_CODE (a1
) == ERROR_MARK
1740 || TREE_CODE (a2
) == ERROR_MARK
)
1742 else if (!(newval
= comptypes_internal (mv1
, mv2
, enum_and_int_p
,
1743 different_types_p
)))
1745 if (different_types_p
!= NULL
)
1746 *different_types_p
= true;
1747 /* Allow wait (union {union wait *u; int *i} *)
1748 and wait (union wait *) to be compatible. */
1749 if (TREE_CODE (a1
) == UNION_TYPE
1750 && (TYPE_NAME (a1
) == NULL_TREE
1751 || TYPE_TRANSPARENT_AGGR (a1
))
1752 && TREE_CODE (TYPE_SIZE (a1
)) == INTEGER_CST
1753 && tree_int_cst_equal (TYPE_SIZE (a1
),
1757 for (memb
= TYPE_FIELDS (a1
);
1758 memb
; memb
= DECL_CHAIN (memb
))
1760 tree mv3
= TREE_TYPE (memb
);
1761 if (mv3
&& mv3
!= error_mark_node
1762 && TREE_CODE (mv3
) != ARRAY_TYPE
)
1763 mv3
= (TYPE_ATOMIC (mv3
)
1764 ? c_build_qualified_type (TYPE_MAIN_VARIANT (mv3
),
1766 : TYPE_MAIN_VARIANT (mv3
));
1767 if (comptypes_internal (mv3
, mv2
, enum_and_int_p
,
1771 if (memb
== NULL_TREE
)
1774 else if (TREE_CODE (a2
) == UNION_TYPE
1775 && (TYPE_NAME (a2
) == NULL_TREE
1776 || TYPE_TRANSPARENT_AGGR (a2
))
1777 && TREE_CODE (TYPE_SIZE (a2
)) == INTEGER_CST
1778 && tree_int_cst_equal (TYPE_SIZE (a2
),
1782 for (memb
= TYPE_FIELDS (a2
);
1783 memb
; memb
= DECL_CHAIN (memb
))
1785 tree mv3
= TREE_TYPE (memb
);
1786 if (mv3
&& mv3
!= error_mark_node
1787 && TREE_CODE (mv3
) != ARRAY_TYPE
)
1788 mv3
= (TYPE_ATOMIC (mv3
)
1789 ? c_build_qualified_type (TYPE_MAIN_VARIANT (mv3
),
1791 : TYPE_MAIN_VARIANT (mv3
));
1792 if (comptypes_internal (mv3
, mv1
, enum_and_int_p
,
1796 if (memb
== NULL_TREE
)
1803 /* comptypes said ok, but record if it said to warn. */
1807 args1
= TREE_CHAIN (args1
);
1808 args2
= TREE_CHAIN (args2
);
1812 /* Compute the size to increment a pointer by. When a function type or void
1813 type or incomplete type is passed, size_one_node is returned.
1814 This function does not emit any diagnostics; the caller is responsible
1818 c_size_in_bytes (const_tree type
)
1820 enum tree_code code
= TREE_CODE (type
);
1822 if (code
== FUNCTION_TYPE
|| code
== VOID_TYPE
|| code
== ERROR_MARK
1823 || !COMPLETE_TYPE_P (type
))
1824 return size_one_node
;
1826 /* Convert in case a char is more than one unit. */
1827 return size_binop_loc (input_location
, CEIL_DIV_EXPR
, TYPE_SIZE_UNIT (type
),
1828 size_int (TYPE_PRECISION (char_type_node
)
1832 /* Return either DECL or its known constant value (if it has one). */
1835 decl_constant_value_1 (tree decl
, bool in_init
)
1837 if (/* Note that DECL_INITIAL isn't valid for a PARM_DECL. */
1838 TREE_CODE (decl
) != PARM_DECL
1839 && !TREE_THIS_VOLATILE (decl
)
1840 && TREE_READONLY (decl
)
1841 && DECL_INITIAL (decl
) != NULL_TREE
1842 && !error_operand_p (DECL_INITIAL (decl
))
1843 /* This is invalid if initial value is not constant.
1844 If it has either a function call, a memory reference,
1845 or a variable, then re-evaluating it could give different results. */
1846 && TREE_CONSTANT (DECL_INITIAL (decl
))
1847 /* Check for cases where this is sub-optimal, even though valid. */
1848 && (in_init
|| TREE_CODE (DECL_INITIAL (decl
)) != CONSTRUCTOR
))
1849 return DECL_INITIAL (decl
);
1853 /* Return either DECL or its known constant value (if it has one).
1854 Like the above, but always return decl outside of functions. */
1857 decl_constant_value (tree decl
)
1859 /* Don't change a variable array bound or initial value to a constant
1860 in a place where a variable is invalid. */
1861 return current_function_decl
? decl_constant_value_1 (decl
, false) : decl
;
1864 /* Convert the array expression EXP to a pointer. */
1866 array_to_pointer_conversion (location_t loc
, tree exp
)
1868 tree orig_exp
= exp
;
1869 tree type
= TREE_TYPE (exp
);
1871 tree restype
= TREE_TYPE (type
);
1874 gcc_assert (TREE_CODE (type
) == ARRAY_TYPE
);
1876 STRIP_TYPE_NOPS (exp
);
1878 if (TREE_NO_WARNING (orig_exp
))
1879 TREE_NO_WARNING (exp
) = 1;
1881 ptrtype
= build_pointer_type (restype
);
1883 if (INDIRECT_REF_P (exp
))
1884 return convert (ptrtype
, TREE_OPERAND (exp
, 0));
1886 /* In C++ array compound literals are temporary objects unless they are
1887 const or appear in namespace scope, so they are destroyed too soon
1888 to use them for much of anything (c++/53220). */
1889 if (warn_cxx_compat
&& TREE_CODE (exp
) == COMPOUND_LITERAL_EXPR
)
1891 tree decl
= TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
1892 if (!TREE_READONLY (decl
) && !TREE_STATIC (decl
))
1893 warning_at (DECL_SOURCE_LOCATION (decl
), OPT_Wc___compat
,
1894 "converting an array compound literal to a pointer "
1895 "is ill-formed in C++");
1898 adr
= build_unary_op (loc
, ADDR_EXPR
, exp
, true);
1899 return convert (ptrtype
, adr
);
1902 /* Convert the function expression EXP to a pointer. */
1904 function_to_pointer_conversion (location_t loc
, tree exp
)
1906 tree orig_exp
= exp
;
1908 gcc_assert (TREE_CODE (TREE_TYPE (exp
)) == FUNCTION_TYPE
);
1910 STRIP_TYPE_NOPS (exp
);
1912 if (TREE_NO_WARNING (orig_exp
))
1913 TREE_NO_WARNING (exp
) = 1;
1915 return build_unary_op (loc
, ADDR_EXPR
, exp
, false);
1918 /* Mark EXP as read, not just set, for set but not used -Wunused
1919 warning purposes. */
1922 mark_exp_read (tree exp
)
1924 switch (TREE_CODE (exp
))
1928 DECL_READ_P (exp
) = 1;
1937 case VIEW_CONVERT_EXPR
:
1938 mark_exp_read (TREE_OPERAND (exp
, 0));
1941 case C_MAYBE_CONST_EXPR
:
1942 mark_exp_read (TREE_OPERAND (exp
, 1));
1949 /* Perform the default conversion of arrays and functions to pointers.
1950 Return the result of converting EXP. For any other expression, just
1953 LOC is the location of the expression. */
1956 default_function_array_conversion (location_t loc
, struct c_expr exp
)
1958 tree orig_exp
= exp
.value
;
1959 tree type
= TREE_TYPE (exp
.value
);
1960 enum tree_code code
= TREE_CODE (type
);
1966 bool not_lvalue
= false;
1967 bool lvalue_array_p
;
1969 while ((TREE_CODE (exp
.value
) == NON_LVALUE_EXPR
1970 || CONVERT_EXPR_P (exp
.value
))
1971 && TREE_TYPE (TREE_OPERAND (exp
.value
, 0)) == type
)
1973 if (TREE_CODE (exp
.value
) == NON_LVALUE_EXPR
)
1975 exp
.value
= TREE_OPERAND (exp
.value
, 0);
1978 if (TREE_NO_WARNING (orig_exp
))
1979 TREE_NO_WARNING (exp
.value
) = 1;
1981 lvalue_array_p
= !not_lvalue
&& lvalue_p (exp
.value
);
1982 if (!flag_isoc99
&& !lvalue_array_p
)
1984 /* Before C99, non-lvalue arrays do not decay to pointers.
1985 Normally, using such an array would be invalid; but it can
1986 be used correctly inside sizeof or as a statement expression.
1987 Thus, do not give an error here; an error will result later. */
1991 exp
.value
= array_to_pointer_conversion (loc
, exp
.value
);
1995 exp
.value
= function_to_pointer_conversion (loc
, exp
.value
);
2005 default_function_array_read_conversion (location_t loc
, struct c_expr exp
)
2007 mark_exp_read (exp
.value
);
2008 return default_function_array_conversion (loc
, exp
);
2011 /* Return whether EXPR should be treated as an atomic lvalue for the
2012 purposes of load and store handling. */
2015 really_atomic_lvalue (tree expr
)
2017 if (error_operand_p (expr
))
2019 if (!TYPE_ATOMIC (TREE_TYPE (expr
)))
2021 if (!lvalue_p (expr
))
2024 /* Ignore _Atomic on register variables, since their addresses can't
2025 be taken so (a) atomicity is irrelevant and (b) the normal atomic
2026 sequences wouldn't work. Ignore _Atomic on structures containing
2027 bit-fields, since accessing elements of atomic structures or
2028 unions is undefined behavior (C11 6.5.2.3#5), but it's unclear if
2029 it's undefined at translation time or execution time, and the
2030 normal atomic sequences again wouldn't work. */
2031 while (handled_component_p (expr
))
2033 if (TREE_CODE (expr
) == COMPONENT_REF
2034 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
, 1)))
2036 expr
= TREE_OPERAND (expr
, 0);
2038 if (DECL_P (expr
) && C_DECL_REGISTER (expr
))
2043 /* Convert expression EXP (location LOC) from lvalue to rvalue,
2044 including converting functions and arrays to pointers if CONVERT_P.
2045 If READ_P, also mark the expression as having been read. */
2048 convert_lvalue_to_rvalue (location_t loc
, struct c_expr exp
,
2049 bool convert_p
, bool read_p
)
2052 mark_exp_read (exp
.value
);
2054 exp
= default_function_array_conversion (loc
, exp
);
2055 if (really_atomic_lvalue (exp
.value
))
2057 vec
<tree
, va_gc
> *params
;
2058 tree nonatomic_type
, tmp
, tmp_addr
, fndecl
, func_call
;
2059 tree expr_type
= TREE_TYPE (exp
.value
);
2060 tree expr_addr
= build_unary_op (loc
, ADDR_EXPR
, exp
.value
, false);
2061 tree seq_cst
= build_int_cst (integer_type_node
, MEMMODEL_SEQ_CST
);
2063 gcc_assert (TYPE_ATOMIC (expr_type
));
2065 /* Expansion of a generic atomic load may require an addition
2066 element, so allocate enough to prevent a resize. */
2067 vec_alloc (params
, 4);
2069 /* Remove the qualifiers for the rest of the expressions and
2070 create the VAL temp variable to hold the RHS. */
2071 nonatomic_type
= build_qualified_type (expr_type
, TYPE_UNQUALIFIED
);
2072 tmp
= create_tmp_var_raw (nonatomic_type
);
2073 tmp_addr
= build_unary_op (loc
, ADDR_EXPR
, tmp
, false);
2074 TREE_ADDRESSABLE (tmp
) = 1;
2075 TREE_NO_WARNING (tmp
) = 1;
2077 /* Issue __atomic_load (&expr, &tmp, SEQ_CST); */
2078 fndecl
= builtin_decl_explicit (BUILT_IN_ATOMIC_LOAD
);
2079 params
->quick_push (expr_addr
);
2080 params
->quick_push (tmp_addr
);
2081 params
->quick_push (seq_cst
);
2082 func_call
= c_build_function_call_vec (loc
, vNULL
, fndecl
, params
, NULL
);
2084 /* EXPR is always read. */
2085 mark_exp_read (exp
.value
);
2087 /* Return tmp which contains the value loaded. */
2088 exp
.value
= build4 (TARGET_EXPR
, nonatomic_type
, tmp
, func_call
,
2089 NULL_TREE
, NULL_TREE
);
2094 /* EXP is an expression of integer type. Apply the integer promotions
2095 to it and return the promoted value. */
2098 perform_integral_promotions (tree exp
)
2100 tree type
= TREE_TYPE (exp
);
2101 enum tree_code code
= TREE_CODE (type
);
2103 gcc_assert (INTEGRAL_TYPE_P (type
));
2105 /* Normally convert enums to int,
2106 but convert wide enums to something wider. */
2107 if (code
== ENUMERAL_TYPE
)
2109 type
= c_common_type_for_size (MAX (TYPE_PRECISION (type
),
2110 TYPE_PRECISION (integer_type_node
)),
2111 ((TYPE_PRECISION (type
)
2112 >= TYPE_PRECISION (integer_type_node
))
2113 && TYPE_UNSIGNED (type
)));
2115 return convert (type
, exp
);
2118 /* ??? This should no longer be needed now bit-fields have their
2120 if (TREE_CODE (exp
) == COMPONENT_REF
2121 && DECL_C_BIT_FIELD (TREE_OPERAND (exp
, 1))
2122 /* If it's thinner than an int, promote it like a
2123 c_promoting_integer_type_p, otherwise leave it alone. */
2124 && compare_tree_int (DECL_SIZE (TREE_OPERAND (exp
, 1)),
2125 TYPE_PRECISION (integer_type_node
)) < 0)
2126 return convert (integer_type_node
, exp
);
2128 if (c_promoting_integer_type_p (type
))
2130 /* Preserve unsignedness if not really getting any wider. */
2131 if (TYPE_UNSIGNED (type
)
2132 && TYPE_PRECISION (type
) == TYPE_PRECISION (integer_type_node
))
2133 return convert (unsigned_type_node
, exp
);
2135 return convert (integer_type_node
, exp
);
2142 /* Perform default promotions for C data used in expressions.
2143 Enumeral types or short or char are converted to int.
2144 In addition, manifest constants symbols are replaced by their values. */
2147 default_conversion (tree exp
)
2150 tree type
= TREE_TYPE (exp
);
2151 enum tree_code code
= TREE_CODE (type
);
2154 mark_exp_read (exp
);
2156 /* Functions and arrays have been converted during parsing. */
2157 gcc_assert (code
!= FUNCTION_TYPE
);
2158 if (code
== ARRAY_TYPE
)
2161 /* Constants can be used directly unless they're not loadable. */
2162 if (TREE_CODE (exp
) == CONST_DECL
)
2163 exp
= DECL_INITIAL (exp
);
2165 /* Strip no-op conversions. */
2167 STRIP_TYPE_NOPS (exp
);
2169 if (TREE_NO_WARNING (orig_exp
))
2170 TREE_NO_WARNING (exp
) = 1;
2172 if (code
== VOID_TYPE
)
2174 error_at (EXPR_LOC_OR_LOC (exp
, input_location
),
2175 "void value not ignored as it ought to be");
2176 return error_mark_node
;
2179 exp
= require_complete_type (EXPR_LOC_OR_LOC (exp
, input_location
), exp
);
2180 if (exp
== error_mark_node
)
2181 return error_mark_node
;
2183 promoted_type
= targetm
.promoted_type (type
);
2185 return convert (promoted_type
, exp
);
2187 if (INTEGRAL_TYPE_P (type
))
2188 return perform_integral_promotions (exp
);
2193 /* Look up COMPONENT in a structure or union TYPE.
2195 If the component name is not found, returns NULL_TREE. Otherwise,
2196 the return value is a TREE_LIST, with each TREE_VALUE a FIELD_DECL
2197 stepping down the chain to the component, which is in the last
2198 TREE_VALUE of the list. Normally the list is of length one, but if
2199 the component is embedded within (nested) anonymous structures or
2200 unions, the list steps down the chain to the component. */
2203 lookup_field (tree type
, tree component
)
2207 /* If TYPE_LANG_SPECIFIC is set, then it is a sorted array of pointers
2208 to the field elements. Use a binary search on this array to quickly
2209 find the element. Otherwise, do a linear search. TYPE_LANG_SPECIFIC
2210 will always be set for structures which have many elements. */
2212 if (TYPE_LANG_SPECIFIC (type
) && TYPE_LANG_SPECIFIC (type
)->s
)
2215 tree
*field_array
= &TYPE_LANG_SPECIFIC (type
)->s
->elts
[0];
2217 field
= TYPE_FIELDS (type
);
2219 top
= TYPE_LANG_SPECIFIC (type
)->s
->len
;
2220 while (top
- bot
> 1)
2222 half
= (top
- bot
+ 1) >> 1;
2223 field
= field_array
[bot
+half
];
2225 if (DECL_NAME (field
) == NULL_TREE
)
2227 /* Step through all anon unions in linear fashion. */
2228 while (DECL_NAME (field_array
[bot
]) == NULL_TREE
)
2230 field
= field_array
[bot
++];
2231 if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (field
)))
2233 tree anon
= lookup_field (TREE_TYPE (field
), component
);
2236 return tree_cons (NULL_TREE
, field
, anon
);
2238 /* The Plan 9 compiler permits referring
2239 directly to an anonymous struct/union field
2240 using a typedef name. */
2241 if (flag_plan9_extensions
2242 && TYPE_NAME (TREE_TYPE (field
)) != NULL_TREE
2243 && (TREE_CODE (TYPE_NAME (TREE_TYPE (field
)))
2245 && (DECL_NAME (TYPE_NAME (TREE_TYPE (field
)))
2251 /* Entire record is only anon unions. */
2255 /* Restart the binary search, with new lower bound. */
2259 if (DECL_NAME (field
) == component
)
2261 if (DECL_NAME (field
) < component
)
2267 if (DECL_NAME (field_array
[bot
]) == component
)
2268 field
= field_array
[bot
];
2269 else if (DECL_NAME (field
) != component
)
2274 for (field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
2276 if (DECL_NAME (field
) == NULL_TREE
2277 && RECORD_OR_UNION_TYPE_P (TREE_TYPE (field
)))
2279 tree anon
= lookup_field (TREE_TYPE (field
), component
);
2282 return tree_cons (NULL_TREE
, field
, anon
);
2284 /* The Plan 9 compiler permits referring directly to an
2285 anonymous struct/union field using a typedef
2287 if (flag_plan9_extensions
2288 && TYPE_NAME (TREE_TYPE (field
)) != NULL_TREE
2289 && TREE_CODE (TYPE_NAME (TREE_TYPE (field
))) == TYPE_DECL
2290 && (DECL_NAME (TYPE_NAME (TREE_TYPE (field
)))
2295 if (DECL_NAME (field
) == component
)
2299 if (field
== NULL_TREE
)
2303 return tree_cons (NULL_TREE
, field
, NULL_TREE
);
2306 /* Recursively append candidate IDENTIFIER_NODEs to CANDIDATES. */
2309 lookup_field_fuzzy_find_candidates (tree type
, tree component
,
2310 vec
<tree
> *candidates
)
2313 for (field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
2315 if (DECL_NAME (field
) == NULL_TREE
2316 && RECORD_OR_UNION_TYPE_P (TREE_TYPE (field
)))
2317 lookup_field_fuzzy_find_candidates (TREE_TYPE (field
), component
,
2320 if (DECL_NAME (field
))
2321 candidates
->safe_push (DECL_NAME (field
));
2325 /* Like "lookup_field", but find the closest matching IDENTIFIER_NODE,
2326 rather than returning a TREE_LIST for an exact match. */
2329 lookup_field_fuzzy (tree type
, tree component
)
2331 gcc_assert (TREE_CODE (component
) == IDENTIFIER_NODE
);
2333 /* First, gather a list of candidates. */
2334 auto_vec
<tree
> candidates
;
2336 lookup_field_fuzzy_find_candidates (type
, component
,
2339 return find_closest_identifier (component
, &candidates
);
2342 /* Support function for build_component_ref's error-handling.
2344 Given DATUM_TYPE, and "DATUM.COMPONENT", where DATUM is *not* a
2345 struct or union, should we suggest "DATUM->COMPONENT" as a hint? */
2348 should_suggest_deref_p (tree datum_type
)
2350 /* We don't do it for Objective-C, since Objective-C 2.0 dot-syntax
2351 allows "." for ptrs; we could be handling a failed attempt
2352 to access a property. */
2353 if (c_dialect_objc ())
2356 /* Only suggest it for pointers... */
2357 if (TREE_CODE (datum_type
) != POINTER_TYPE
)
2360 /* ...to structs/unions. */
2361 tree underlying_type
= TREE_TYPE (datum_type
);
2362 enum tree_code code
= TREE_CODE (underlying_type
);
2363 if (code
== RECORD_TYPE
|| code
== UNION_TYPE
)
2369 /* Make an expression to refer to the COMPONENT field of structure or
2370 union value DATUM. COMPONENT is an IDENTIFIER_NODE. LOC is the
2371 location of the COMPONENT_REF. COMPONENT_LOC is the location
2375 build_component_ref (location_t loc
, tree datum
, tree component
,
2376 location_t component_loc
)
2378 tree type
= TREE_TYPE (datum
);
2379 enum tree_code code
= TREE_CODE (type
);
2382 bool datum_lvalue
= lvalue_p (datum
);
2384 if (!objc_is_public (datum
, component
))
2385 return error_mark_node
;
2387 /* Detect Objective-C property syntax object.property. */
2388 if (c_dialect_objc ()
2389 && (ref
= objc_maybe_build_component_ref (datum
, component
)))
2392 /* See if there is a field or component with name COMPONENT. */
2394 if (code
== RECORD_TYPE
|| code
== UNION_TYPE
)
2396 if (!COMPLETE_TYPE_P (type
))
2398 c_incomplete_type_error (loc
, NULL_TREE
, type
);
2399 return error_mark_node
;
2402 field
= lookup_field (type
, component
);
2406 tree guessed_id
= lookup_field_fuzzy (type
, component
);
2409 /* Attempt to provide a fixit replacement hint, if
2410 we have a valid range for the component. */
2411 location_t reported_loc
2412 = (component_loc
!= UNKNOWN_LOCATION
) ? component_loc
: loc
;
2413 gcc_rich_location
rich_loc (reported_loc
);
2414 if (component_loc
!= UNKNOWN_LOCATION
)
2415 rich_loc
.add_fixit_misspelled_id (component_loc
, guessed_id
);
2416 error_at (&rich_loc
,
2417 "%qT has no member named %qE; did you mean %qE?",
2418 type
, component
, guessed_id
);
2421 error_at (loc
, "%qT has no member named %qE", type
, component
);
2422 return error_mark_node
;
2425 /* Accessing elements of atomic structures or unions is undefined
2426 behavior (C11 6.5.2.3#5). */
2427 if (TYPE_ATOMIC (type
) && c_inhibit_evaluation_warnings
== 0)
2429 if (code
== RECORD_TYPE
)
2430 warning_at (loc
, 0, "accessing a member %qE of an atomic "
2431 "structure %qE", component
, datum
);
2433 warning_at (loc
, 0, "accessing a member %qE of an atomic "
2434 "union %qE", component
, datum
);
2437 /* Chain the COMPONENT_REFs if necessary down to the FIELD.
2438 This might be better solved in future the way the C++ front
2439 end does it - by giving the anonymous entities each a
2440 separate name and type, and then have build_component_ref
2441 recursively call itself. We can't do that here. */
2444 tree subdatum
= TREE_VALUE (field
);
2447 bool use_datum_quals
;
2449 if (TREE_TYPE (subdatum
) == error_mark_node
)
2450 return error_mark_node
;
2452 /* If this is an rvalue, it does not have qualifiers in C
2453 standard terms and we must avoid propagating such
2454 qualifiers down to a non-lvalue array that is then
2455 converted to a pointer. */
2456 use_datum_quals
= (datum_lvalue
2457 || TREE_CODE (TREE_TYPE (subdatum
)) != ARRAY_TYPE
);
2459 quals
= TYPE_QUALS (strip_array_types (TREE_TYPE (subdatum
)));
2460 if (use_datum_quals
)
2461 quals
|= TYPE_QUALS (TREE_TYPE (datum
));
2462 subtype
= c_build_qualified_type (TREE_TYPE (subdatum
), quals
);
2464 ref
= build3 (COMPONENT_REF
, subtype
, datum
, subdatum
,
2466 SET_EXPR_LOCATION (ref
, loc
);
2467 if (TREE_READONLY (subdatum
)
2468 || (use_datum_quals
&& TREE_READONLY (datum
)))
2469 TREE_READONLY (ref
) = 1;
2470 if (TREE_THIS_VOLATILE (subdatum
)
2471 || (use_datum_quals
&& TREE_THIS_VOLATILE (datum
)))
2472 TREE_THIS_VOLATILE (ref
) = 1;
2474 if (TREE_DEPRECATED (subdatum
))
2475 warn_deprecated_use (subdatum
, NULL_TREE
);
2479 field
= TREE_CHAIN (field
);
2485 else if (should_suggest_deref_p (type
))
2487 /* Special-case the error message for "ptr.field" for the case
2488 where the user has confused "." vs "->". */
2489 rich_location
richloc (line_table
, loc
);
2490 /* "loc" should be the "." token. */
2491 richloc
.add_fixit_replace ("->");
2493 "%qE is a pointer; did you mean to use %<->%>?",
2495 return error_mark_node
;
2497 else if (code
!= ERROR_MARK
)
2499 "request for member %qE in something not a structure or union",
2502 return error_mark_node
;
2505 /* Given an expression PTR for a pointer, return an expression
2506 for the value pointed to.
2507 ERRORSTRING is the name of the operator to appear in error messages.
2509 LOC is the location to use for the generated tree. */
2512 build_indirect_ref (location_t loc
, tree ptr
, ref_operator errstring
)
2514 tree pointer
= default_conversion (ptr
);
2515 tree type
= TREE_TYPE (pointer
);
2518 if (TREE_CODE (type
) == POINTER_TYPE
)
2520 if (CONVERT_EXPR_P (pointer
)
2521 || TREE_CODE (pointer
) == VIEW_CONVERT_EXPR
)
2523 /* If a warning is issued, mark it to avoid duplicates from
2524 the backend. This only needs to be done at
2525 warn_strict_aliasing > 2. */
2526 if (warn_strict_aliasing
> 2)
2527 if (strict_aliasing_warning (EXPR_LOCATION (pointer
),
2528 type
, TREE_OPERAND (pointer
, 0)))
2529 TREE_NO_WARNING (pointer
) = 1;
2532 if (TREE_CODE (pointer
) == ADDR_EXPR
2533 && (TREE_TYPE (TREE_OPERAND (pointer
, 0))
2534 == TREE_TYPE (type
)))
2536 ref
= TREE_OPERAND (pointer
, 0);
2537 protected_set_expr_location (ref
, loc
);
2542 tree t
= TREE_TYPE (type
);
2544 ref
= build1 (INDIRECT_REF
, t
, pointer
);
2546 if (!COMPLETE_OR_VOID_TYPE_P (t
) && TREE_CODE (t
) != ARRAY_TYPE
)
2548 if (!C_TYPE_ERROR_REPORTED (TREE_TYPE (ptr
)))
2550 error_at (loc
, "dereferencing pointer to incomplete type "
2552 C_TYPE_ERROR_REPORTED (TREE_TYPE (ptr
)) = 1;
2554 return error_mark_node
;
2556 if (VOID_TYPE_P (t
) && c_inhibit_evaluation_warnings
== 0)
2557 warning_at (loc
, 0, "dereferencing %<void *%> pointer");
2559 /* We *must* set TREE_READONLY when dereferencing a pointer to const,
2560 so that we get the proper error message if the result is used
2561 to assign to. Also, &* is supposed to be a no-op.
2562 And ANSI C seems to specify that the type of the result
2563 should be the const type. */
2564 /* A de-reference of a pointer to const is not a const. It is valid
2565 to change it via some other pointer. */
2566 TREE_READONLY (ref
) = TYPE_READONLY (t
);
2567 TREE_SIDE_EFFECTS (ref
)
2568 = TYPE_VOLATILE (t
) || TREE_SIDE_EFFECTS (pointer
);
2569 TREE_THIS_VOLATILE (ref
) = TYPE_VOLATILE (t
);
2570 protected_set_expr_location (ref
, loc
);
2574 else if (TREE_CODE (pointer
) != ERROR_MARK
)
2575 invalid_indirection_error (loc
, type
, errstring
);
2577 return error_mark_node
;
2580 /* This handles expressions of the form "a[i]", which denotes
2583 This is logically equivalent in C to *(a+i), but we may do it differently.
2584 If A is a variable or a member, we generate a primitive ARRAY_REF.
2585 This avoids forcing the array out of registers, and can work on
2586 arrays that are not lvalues (for example, members of structures returned
2589 For vector types, allow vector[i] but not i[vector], and create
2590 *(((type*)&vectortype) + i) for the expression.
2592 LOC is the location to use for the returned expression. */
2595 build_array_ref (location_t loc
, tree array
, tree index
)
2598 bool swapped
= false;
2599 if (TREE_TYPE (array
) == error_mark_node
2600 || TREE_TYPE (index
) == error_mark_node
)
2601 return error_mark_node
;
2603 if (TREE_CODE (TREE_TYPE (array
)) != ARRAY_TYPE
2604 && TREE_CODE (TREE_TYPE (array
)) != POINTER_TYPE
2605 /* Allow vector[index] but not index[vector]. */
2606 && !VECTOR_TYPE_P (TREE_TYPE (array
)))
2608 if (TREE_CODE (TREE_TYPE (index
)) != ARRAY_TYPE
2609 && TREE_CODE (TREE_TYPE (index
)) != POINTER_TYPE
)
2612 "subscripted value is neither array nor pointer nor vector");
2614 return error_mark_node
;
2616 std::swap (array
, index
);
2620 if (!INTEGRAL_TYPE_P (TREE_TYPE (index
)))
2622 error_at (loc
, "array subscript is not an integer");
2623 return error_mark_node
;
2626 if (TREE_CODE (TREE_TYPE (TREE_TYPE (array
))) == FUNCTION_TYPE
)
2628 error_at (loc
, "subscripted value is pointer to function");
2629 return error_mark_node
;
2632 /* ??? Existing practice has been to warn only when the char
2633 index is syntactically the index, not for char[array]. */
2635 warn_array_subscript_with_type_char (loc
, index
);
2637 /* Apply default promotions *after* noticing character types. */
2638 index
= default_conversion (index
);
2639 if (index
== error_mark_node
)
2640 return error_mark_node
;
2642 gcc_assert (TREE_CODE (TREE_TYPE (index
)) == INTEGER_TYPE
);
2644 bool was_vector
= VECTOR_TYPE_P (TREE_TYPE (array
));
2645 bool non_lvalue
= convert_vector_to_array_for_subscript (loc
, &array
, index
);
2647 if (TREE_CODE (TREE_TYPE (array
)) == ARRAY_TYPE
)
2651 /* An array that is indexed by a non-constant
2652 cannot be stored in a register; we must be able to do
2653 address arithmetic on its address.
2654 Likewise an array of elements of variable size. */
2655 if (TREE_CODE (index
) != INTEGER_CST
2656 || (COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (array
)))
2657 && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array
)))) != INTEGER_CST
))
2659 if (!c_mark_addressable (array
, true))
2660 return error_mark_node
;
2662 /* An array that is indexed by a constant value which is not within
2663 the array bounds cannot be stored in a register either; because we
2664 would get a crash in store_bit_field/extract_bit_field when trying
2665 to access a non-existent part of the register. */
2666 if (TREE_CODE (index
) == INTEGER_CST
2667 && TYPE_DOMAIN (TREE_TYPE (array
))
2668 && !int_fits_type_p (index
, TYPE_DOMAIN (TREE_TYPE (array
))))
2670 if (!c_mark_addressable (array
))
2671 return error_mark_node
;
2674 if ((pedantic
|| warn_c90_c99_compat
)
2678 while (TREE_CODE (foo
) == COMPONENT_REF
)
2679 foo
= TREE_OPERAND (foo
, 0);
2680 if (VAR_P (foo
) && C_DECL_REGISTER (foo
))
2681 pedwarn (loc
, OPT_Wpedantic
,
2682 "ISO C forbids subscripting %<register%> array");
2683 else if (!lvalue_p (foo
))
2684 pedwarn_c90 (loc
, OPT_Wpedantic
,
2685 "ISO C90 forbids subscripting non-lvalue "
2689 type
= TREE_TYPE (TREE_TYPE (array
));
2690 rval
= build4 (ARRAY_REF
, type
, array
, index
, NULL_TREE
, NULL_TREE
);
2691 /* Array ref is const/volatile if the array elements are
2692 or if the array is. */
2693 TREE_READONLY (rval
)
2694 |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array
)))
2695 | TREE_READONLY (array
));
2696 TREE_SIDE_EFFECTS (rval
)
2697 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array
)))
2698 | TREE_SIDE_EFFECTS (array
));
2699 TREE_THIS_VOLATILE (rval
)
2700 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array
)))
2701 /* This was added by rms on 16 Nov 91.
2702 It fixes vol struct foo *a; a->elts[1]
2703 in an inline function.
2704 Hope it doesn't break something else. */
2705 | TREE_THIS_VOLATILE (array
));
2706 ret
= require_complete_type (loc
, rval
);
2707 protected_set_expr_location (ret
, loc
);
2709 ret
= non_lvalue_loc (loc
, ret
);
2714 tree ar
= default_conversion (array
);
2716 if (ar
== error_mark_node
)
2719 gcc_assert (TREE_CODE (TREE_TYPE (ar
)) == POINTER_TYPE
);
2720 gcc_assert (TREE_CODE (TREE_TYPE (TREE_TYPE (ar
))) != FUNCTION_TYPE
);
2722 ret
= build_indirect_ref (loc
, build_binary_op (loc
, PLUS_EXPR
, ar
,
2726 ret
= non_lvalue_loc (loc
, ret
);
2731 /* Build an external reference to identifier ID. FUN indicates
2732 whether this will be used for a function call. LOC is the source
2733 location of the identifier. This sets *TYPE to the type of the
2734 identifier, which is not the same as the type of the returned value
2735 for CONST_DECLs defined as enum constants. If the type of the
2736 identifier is not available, *TYPE is set to NULL. */
2738 build_external_ref (location_t loc
, tree id
, bool fun
, tree
*type
)
2741 tree decl
= lookup_name (id
);
2743 /* In Objective-C, an instance variable (ivar) may be preferred to
2744 whatever lookup_name() found. */
2745 decl
= objc_lookup_ivar (decl
, id
);
2748 if (decl
&& decl
!= error_mark_node
)
2751 *type
= TREE_TYPE (ref
);
2754 /* Implicit function declaration. */
2755 ref
= implicitly_declare (loc
, id
);
2756 else if (decl
== error_mark_node
)
2757 /* Don't complain about something that's already been
2758 complained about. */
2759 return error_mark_node
;
2762 undeclared_variable (loc
, id
);
2763 return error_mark_node
;
2766 if (TREE_TYPE (ref
) == error_mark_node
)
2767 return error_mark_node
;
2769 if (TREE_DEPRECATED (ref
))
2770 warn_deprecated_use (ref
, NULL_TREE
);
2772 /* Recursive call does not count as usage. */
2773 if (ref
!= current_function_decl
)
2775 TREE_USED (ref
) = 1;
2778 if (TREE_CODE (ref
) == FUNCTION_DECL
&& !in_alignof
)
2780 if (!in_sizeof
&& !in_typeof
)
2781 C_DECL_USED (ref
) = 1;
2782 else if (DECL_INITIAL (ref
) == NULL_TREE
2783 && DECL_EXTERNAL (ref
)
2784 && !TREE_PUBLIC (ref
))
2785 record_maybe_used_decl (ref
);
2788 if (TREE_CODE (ref
) == CONST_DECL
)
2790 used_types_insert (TREE_TYPE (ref
));
2793 && TREE_CODE (TREE_TYPE (ref
)) == ENUMERAL_TYPE
2794 && C_TYPE_DEFINED_IN_STRUCT (TREE_TYPE (ref
)))
2796 warning_at (loc
, OPT_Wc___compat
,
2797 ("enum constant defined in struct or union "
2798 "is not visible in C++"));
2799 inform (DECL_SOURCE_LOCATION (ref
), "enum constant defined here");
2802 ref
= DECL_INITIAL (ref
);
2803 TREE_CONSTANT (ref
) = 1;
2805 else if (current_function_decl
!= NULL_TREE
2806 && !DECL_FILE_SCOPE_P (current_function_decl
)
2807 && (VAR_OR_FUNCTION_DECL_P (ref
)
2808 || TREE_CODE (ref
) == PARM_DECL
))
2810 tree context
= decl_function_context (ref
);
2812 if (context
!= NULL_TREE
&& context
!= current_function_decl
)
2813 DECL_NONLOCAL (ref
) = 1;
2815 /* C99 6.7.4p3: An inline definition of a function with external
2816 linkage ... shall not contain a reference to an identifier with
2817 internal linkage. */
2818 else if (current_function_decl
!= NULL_TREE
2819 && DECL_DECLARED_INLINE_P (current_function_decl
)
2820 && DECL_EXTERNAL (current_function_decl
)
2821 && VAR_OR_FUNCTION_DECL_P (ref
)
2822 && (!VAR_P (ref
) || TREE_STATIC (ref
))
2823 && ! TREE_PUBLIC (ref
)
2824 && DECL_CONTEXT (ref
) != current_function_decl
)
2825 record_inline_static (loc
, current_function_decl
, ref
,
2831 /* Record details of decls possibly used inside sizeof or typeof. */
2832 struct maybe_used_decl
2836 /* The level seen at (in_sizeof + in_typeof). */
2838 /* The next one at this level or above, or NULL. */
2839 struct maybe_used_decl
*next
;
2842 static struct maybe_used_decl
*maybe_used_decls
;
2844 /* Record that DECL, an undefined static function reference seen
2845 inside sizeof or typeof, might be used if the operand of sizeof is
2846 a VLA type or the operand of typeof is a variably modified
2850 record_maybe_used_decl (tree decl
)
2852 struct maybe_used_decl
*t
= XOBNEW (&parser_obstack
, struct maybe_used_decl
);
2854 t
->level
= in_sizeof
+ in_typeof
;
2855 t
->next
= maybe_used_decls
;
2856 maybe_used_decls
= t
;
2859 /* Pop the stack of decls possibly used inside sizeof or typeof. If
2860 USED is false, just discard them. If it is true, mark them used
2861 (if no longer inside sizeof or typeof) or move them to the next
2862 level up (if still inside sizeof or typeof). */
2865 pop_maybe_used (bool used
)
2867 struct maybe_used_decl
*p
= maybe_used_decls
;
2868 int cur_level
= in_sizeof
+ in_typeof
;
2869 while (p
&& p
->level
> cur_level
)
2874 C_DECL_USED (p
->decl
) = 1;
2876 p
->level
= cur_level
;
2880 if (!used
|| cur_level
== 0)
2881 maybe_used_decls
= p
;
2884 /* Return the result of sizeof applied to EXPR. */
2887 c_expr_sizeof_expr (location_t loc
, struct c_expr expr
)
2890 if (expr
.value
== error_mark_node
)
2892 ret
.value
= error_mark_node
;
2893 ret
.original_code
= ERROR_MARK
;
2894 ret
.original_type
= NULL
;
2895 pop_maybe_used (false);
2899 bool expr_const_operands
= true;
2901 if (TREE_CODE (expr
.value
) == PARM_DECL
2902 && C_ARRAY_PARAMETER (expr
.value
))
2904 if (warning_at (loc
, OPT_Wsizeof_array_argument
,
2905 "%<sizeof%> on array function parameter %qE will "
2906 "return size of %qT", expr
.value
,
2907 TREE_TYPE (expr
.value
)))
2908 inform (DECL_SOURCE_LOCATION (expr
.value
), "declared here");
2910 tree folded_expr
= c_fully_fold (expr
.value
, require_constant_value
,
2911 &expr_const_operands
);
2912 ret
.value
= c_sizeof (loc
, TREE_TYPE (folded_expr
));
2913 c_last_sizeof_arg
= expr
.value
;
2914 c_last_sizeof_loc
= loc
;
2915 ret
.original_code
= SIZEOF_EXPR
;
2916 ret
.original_type
= NULL
;
2917 if (c_vla_type_p (TREE_TYPE (folded_expr
)))
2919 /* sizeof is evaluated when given a vla (C99 6.5.3.4p2). */
2920 ret
.value
= build2 (C_MAYBE_CONST_EXPR
, TREE_TYPE (ret
.value
),
2921 folded_expr
, ret
.value
);
2922 C_MAYBE_CONST_EXPR_NON_CONST (ret
.value
) = !expr_const_operands
;
2923 SET_EXPR_LOCATION (ret
.value
, loc
);
2925 pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (folded_expr
)));
2930 /* Return the result of sizeof applied to T, a structure for the type
2931 name passed to sizeof (rather than the type itself). LOC is the
2932 location of the original expression. */
2935 c_expr_sizeof_type (location_t loc
, struct c_type_name
*t
)
2939 tree type_expr
= NULL_TREE
;
2940 bool type_expr_const
= true;
2941 type
= groktypename (t
, &type_expr
, &type_expr_const
);
2942 ret
.value
= c_sizeof (loc
, type
);
2943 c_last_sizeof_arg
= type
;
2944 c_last_sizeof_loc
= loc
;
2945 ret
.original_code
= SIZEOF_EXPR
;
2946 ret
.original_type
= NULL
;
2947 if ((type_expr
|| TREE_CODE (ret
.value
) == INTEGER_CST
)
2948 && c_vla_type_p (type
))
2950 /* If the type is a [*] array, it is a VLA but is represented as
2951 having a size of zero. In such a case we must ensure that
2952 the result of sizeof does not get folded to a constant by
2953 c_fully_fold, because if the size is evaluated the result is
2954 not constant and so constraints on zero or negative size
2955 arrays must not be applied when this sizeof call is inside
2956 another array declarator. */
2958 type_expr
= integer_zero_node
;
2959 ret
.value
= build2 (C_MAYBE_CONST_EXPR
, TREE_TYPE (ret
.value
),
2960 type_expr
, ret
.value
);
2961 C_MAYBE_CONST_EXPR_NON_CONST (ret
.value
) = !type_expr_const
;
2963 pop_maybe_used (type
!= error_mark_node
2964 ? C_TYPE_VARIABLE_SIZE (type
) : false);
2968 /* Build a function call to function FUNCTION with parameters PARAMS.
2969 The function call is at LOC.
2970 PARAMS is a list--a chain of TREE_LIST nodes--in which the
2971 TREE_VALUE of each node is a parameter-expression.
2972 FUNCTION's data type may be a function type or a pointer-to-function. */
2975 build_function_call (location_t loc
, tree function
, tree params
)
2977 vec
<tree
, va_gc
> *v
;
2980 vec_alloc (v
, list_length (params
));
2981 for (; params
; params
= TREE_CHAIN (params
))
2982 v
->quick_push (TREE_VALUE (params
));
2983 ret
= c_build_function_call_vec (loc
, vNULL
, function
, v
, NULL
);
2988 /* Give a note about the location of the declaration of DECL. */
2991 inform_declaration (tree decl
)
2993 if (decl
&& (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_IS_BUILTIN (decl
)))
2994 inform (DECL_SOURCE_LOCATION (decl
), "declared here");
2997 /* Build a function call to function FUNCTION with parameters PARAMS.
2998 ORIGTYPES, if not NULL, is a vector of types; each element is
2999 either NULL or the original type of the corresponding element in
3000 PARAMS. The original type may differ from TREE_TYPE of the
3001 parameter for enums. FUNCTION's data type may be a function type
3002 or pointer-to-function. This function changes the elements of
3006 build_function_call_vec (location_t loc
, vec
<location_t
> arg_loc
,
3007 tree function
, vec
<tree
, va_gc
> *params
,
3008 vec
<tree
, va_gc
> *origtypes
)
3010 tree fntype
, fundecl
= NULL_TREE
;
3011 tree name
= NULL_TREE
, result
;
3017 /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
3018 STRIP_TYPE_NOPS (function
);
3020 /* Convert anything with function type to a pointer-to-function. */
3021 if (TREE_CODE (function
) == FUNCTION_DECL
)
3023 name
= DECL_NAME (function
);
3026 tm_malloc_replacement (function
);
3028 /* Atomic functions have type checking/casting already done. They are
3029 often rewritten and don't match the original parameter list. */
3030 if (name
&& !strncmp (IDENTIFIER_POINTER (name
), "__atomic_", 9))
3033 if (TREE_CODE (TREE_TYPE (function
)) == FUNCTION_TYPE
)
3034 function
= function_to_pointer_conversion (loc
, function
);
3036 /* For Objective-C, convert any calls via a cast to OBJC_TYPE_REF
3037 expressions, like those used for ObjC messenger dispatches. */
3038 if (params
&& !params
->is_empty ())
3039 function
= objc_rewrite_function_call (function
, (*params
)[0]);
3041 function
= c_fully_fold (function
, false, NULL
);
3043 fntype
= TREE_TYPE (function
);
3045 if (TREE_CODE (fntype
) == ERROR_MARK
)
3046 return error_mark_node
;
3048 if (!(TREE_CODE (fntype
) == POINTER_TYPE
3049 && TREE_CODE (TREE_TYPE (fntype
)) == FUNCTION_TYPE
))
3051 if (!flag_diagnostics_show_caret
)
3053 "called object %qE is not a function or function pointer",
3055 else if (DECL_P (function
))
3058 "called object %qD is not a function or function pointer",
3060 inform_declaration (function
);
3064 "called object is not a function or function pointer");
3065 return error_mark_node
;
3068 if (fundecl
&& TREE_THIS_VOLATILE (fundecl
))
3069 current_function_returns_abnormally
= 1;
3071 /* fntype now gets the type of function pointed to. */
3072 fntype
= TREE_TYPE (fntype
);
3074 /* Convert the parameters to the types declared in the
3075 function prototype, or apply default promotions. */
3077 nargs
= convert_arguments (loc
, arg_loc
, TYPE_ARG_TYPES (fntype
), params
,
3078 origtypes
, function
, fundecl
);
3080 return error_mark_node
;
3082 /* Check that the function is called through a compatible prototype.
3083 If it is not, warn. */
3084 if (CONVERT_EXPR_P (function
)
3085 && TREE_CODE (tem
= TREE_OPERAND (function
, 0)) == ADDR_EXPR
3086 && TREE_CODE (tem
= TREE_OPERAND (tem
, 0)) == FUNCTION_DECL
3087 && !comptypes (fntype
, TREE_TYPE (tem
)))
3089 tree return_type
= TREE_TYPE (fntype
);
3091 /* This situation leads to run-time undefined behavior. We can't,
3092 therefore, simply error unless we can prove that all possible
3093 executions of the program must execute the code. */
3094 warning_at (loc
, 0, "function called through a non-compatible type");
3096 if (VOID_TYPE_P (return_type
)
3097 && TYPE_QUALS (return_type
) != TYPE_UNQUALIFIED
)
3099 "function with qualified void return type called");
3102 argarray
= vec_safe_address (params
);
3104 /* Check that arguments to builtin functions match the expectations. */
3106 && DECL_BUILT_IN (fundecl
)
3107 && DECL_BUILT_IN_CLASS (fundecl
) == BUILT_IN_NORMAL
3108 && !check_builtin_function_arguments (loc
, arg_loc
, fundecl
, nargs
,
3110 return error_mark_node
;
3112 /* Check that the arguments to the function are valid. */
3113 bool warned_p
= check_function_arguments (loc
, fundecl
, fntype
,
3114 nargs
, argarray
, &arg_loc
);
3116 if (name
!= NULL_TREE
3117 && !strncmp (IDENTIFIER_POINTER (name
), "__builtin_", 10))
3119 if (require_constant_value
)
3121 = fold_build_call_array_initializer_loc (loc
, TREE_TYPE (fntype
),
3122 function
, nargs
, argarray
);
3124 result
= fold_build_call_array_loc (loc
, TREE_TYPE (fntype
),
3125 function
, nargs
, argarray
);
3126 if (TREE_CODE (result
) == NOP_EXPR
3127 && TREE_CODE (TREE_OPERAND (result
, 0)) == INTEGER_CST
)
3128 STRIP_TYPE_NOPS (result
);
3131 result
= build_call_array_loc (loc
, TREE_TYPE (fntype
),
3132 function
, nargs
, argarray
);
3133 /* If -Wnonnull warning has been diagnosed, avoid diagnosing it again
3135 if (warned_p
&& TREE_CODE (result
) == CALL_EXPR
)
3136 TREE_NO_WARNING (result
) = 1;
3138 /* In this improbable scenario, a nested function returns a VM type.
3139 Create a TARGET_EXPR so that the call always has a LHS, much as
3140 what the C++ FE does for functions returning non-PODs. */
3141 if (variably_modified_type_p (TREE_TYPE (fntype
), NULL_TREE
))
3143 tree tmp
= create_tmp_var_raw (TREE_TYPE (fntype
));
3144 result
= build4 (TARGET_EXPR
, TREE_TYPE (fntype
), tmp
, result
,
3145 NULL_TREE
, NULL_TREE
);
3148 if (VOID_TYPE_P (TREE_TYPE (result
)))
3150 if (TYPE_QUALS (TREE_TYPE (result
)) != TYPE_UNQUALIFIED
)
3152 "function with qualified void return type called");
3155 return require_complete_type (loc
, result
);
3158 /* Like build_function_call_vec, but call also resolve_overloaded_builtin. */
3161 c_build_function_call_vec (location_t loc
, vec
<location_t
> arg_loc
,
3162 tree function
, vec
<tree
, va_gc
> *params
,
3163 vec
<tree
, va_gc
> *origtypes
)
3165 /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
3166 STRIP_TYPE_NOPS (function
);
3168 /* Convert anything with function type to a pointer-to-function. */
3169 if (TREE_CODE (function
) == FUNCTION_DECL
)
3171 /* Implement type-directed function overloading for builtins.
3172 resolve_overloaded_builtin and targetm.resolve_overloaded_builtin
3173 handle all the type checking. The result is a complete expression
3174 that implements this function call. */
3175 tree tem
= resolve_overloaded_builtin (loc
, function
, params
);
3179 return build_function_call_vec (loc
, arg_loc
, function
, params
, origtypes
);
3182 /* Convert the argument expressions in the vector VALUES
3183 to the types in the list TYPELIST.
3185 If TYPELIST is exhausted, or when an element has NULL as its type,
3186 perform the default conversions.
3188 ORIGTYPES is the original types of the expressions in VALUES. This
3189 holds the type of enum values which have been converted to integral
3190 types. It may be NULL.
3192 FUNCTION is a tree for the called function. It is used only for
3193 error messages, where it is formatted with %qE.
3195 This is also where warnings about wrong number of args are generated.
3197 ARG_LOC are locations of function arguments (if any).
3199 Returns the actual number of arguments processed (which may be less
3200 than the length of VALUES in some error situations), or -1 on
3204 convert_arguments (location_t loc
, vec
<location_t
> arg_loc
, tree typelist
,
3205 vec
<tree
, va_gc
> *values
, vec
<tree
, va_gc
> *origtypes
,
3206 tree function
, tree fundecl
)
3209 unsigned int parmnum
;
3210 bool error_args
= false;
3211 const bool type_generic
= fundecl
3212 && lookup_attribute ("type generic", TYPE_ATTRIBUTES (TREE_TYPE (fundecl
)));
3213 bool type_generic_remove_excess_precision
= false;
3214 bool type_generic_overflow_p
= false;
3217 /* Change pointer to function to the function itself for
3219 if (TREE_CODE (function
) == ADDR_EXPR
3220 && TREE_CODE (TREE_OPERAND (function
, 0)) == FUNCTION_DECL
)
3221 function
= TREE_OPERAND (function
, 0);
3223 /* Handle an ObjC selector specially for diagnostics. */
3224 selector
= objc_message_selector ();
3226 /* For type-generic built-in functions, determine whether excess
3227 precision should be removed (classification) or not
3230 && DECL_BUILT_IN (fundecl
)
3231 && DECL_BUILT_IN_CLASS (fundecl
) == BUILT_IN_NORMAL
)
3233 switch (DECL_FUNCTION_CODE (fundecl
))
3235 case BUILT_IN_ISFINITE
:
3236 case BUILT_IN_ISINF
:
3237 case BUILT_IN_ISINF_SIGN
:
3238 case BUILT_IN_ISNAN
:
3239 case BUILT_IN_ISNORMAL
:
3240 case BUILT_IN_FPCLASSIFY
:
3241 type_generic_remove_excess_precision
= true;
3244 case BUILT_IN_ADD_OVERFLOW_P
:
3245 case BUILT_IN_SUB_OVERFLOW_P
:
3246 case BUILT_IN_MUL_OVERFLOW_P
:
3247 /* The last argument of these type-generic builtins
3248 should not be promoted. */
3249 type_generic_overflow_p
= true;
3257 /* Scan the given expressions and types, producing individual
3258 converted arguments. */
3260 for (typetail
= typelist
, parmnum
= 0;
3261 values
&& values
->iterate (parmnum
, &val
);
3264 tree type
= typetail
? TREE_VALUE (typetail
) : 0;
3265 tree valtype
= TREE_TYPE (val
);
3266 tree rname
= function
;
3267 int argnum
= parmnum
+ 1;
3268 const char *invalid_func_diag
;
3269 bool excess_precision
= false;
3272 /* Some __atomic_* builtins have additional hidden argument at
3275 = !arg_loc
.is_empty () && values
->length () == arg_loc
.length ()
3276 ? expansion_point_location_if_in_system_header (arg_loc
[parmnum
])
3279 if (type
== void_type_node
)
3282 error_at (loc
, "too many arguments to method %qE", selector
);
3284 error_at (loc
, "too many arguments to function %qE", function
);
3285 inform_declaration (fundecl
);
3286 return error_args
? -1 : (int) parmnum
;
3289 if (selector
&& argnum
> 2)
3295 npc
= null_pointer_constant_p (val
);
3297 /* If there is excess precision and a prototype, convert once to
3298 the required type rather than converting via the semantic
3299 type. Likewise without a prototype a float value represented
3300 as long double should be converted once to double. But for
3301 type-generic classification functions excess precision must
3303 if (TREE_CODE (val
) == EXCESS_PRECISION_EXPR
3304 && (type
|| !type_generic
|| !type_generic_remove_excess_precision
))
3306 val
= TREE_OPERAND (val
, 0);
3307 excess_precision
= true;
3309 val
= c_fully_fold (val
, false, NULL
);
3310 STRIP_TYPE_NOPS (val
);
3312 val
= require_complete_type (ploc
, val
);
3314 /* Some floating-point arguments must be promoted to double when
3315 no type is specified by a prototype. This applies to
3316 arguments of type float, and to architecture-specific types
3317 (ARM __fp16), but not to _FloatN or _FloatNx types. */
3318 bool promote_float_arg
= false;
3319 if (type
== NULL_TREE
3320 && TREE_CODE (valtype
) == REAL_TYPE
3321 && (TYPE_PRECISION (valtype
)
3322 <= TYPE_PRECISION (double_type_node
))
3323 && TYPE_MAIN_VARIANT (valtype
) != double_type_node
3324 && TYPE_MAIN_VARIANT (valtype
) != long_double_type_node
3325 && !DECIMAL_FLOAT_MODE_P (TYPE_MODE (valtype
)))
3327 /* Promote this argument, unless it has a _FloatN or
3329 promote_float_arg
= true;
3330 for (int i
= 0; i
< NUM_FLOATN_NX_TYPES
; i
++)
3331 if (TYPE_MAIN_VARIANT (valtype
) == FLOATN_NX_TYPE_NODE (i
))
3333 promote_float_arg
= false;
3338 if (type
!= NULL_TREE
)
3340 /* Formal parm type is specified by a function prototype. */
3342 if (type
== error_mark_node
|| !COMPLETE_TYPE_P (type
))
3344 error_at (ploc
, "type of formal parameter %d is incomplete",
3352 /* Optionally warn about conversions that
3353 differ from the default conversions. */
3354 if (warn_traditional_conversion
|| warn_traditional
)
3356 unsigned int formal_prec
= TYPE_PRECISION (type
);
3358 if (INTEGRAL_TYPE_P (type
)
3359 && TREE_CODE (valtype
) == REAL_TYPE
)
3360 warning_at (ploc
, OPT_Wtraditional_conversion
,
3361 "passing argument %d of %qE as integer rather "
3362 "than floating due to prototype",
3364 if (INTEGRAL_TYPE_P (type
)
3365 && TREE_CODE (valtype
) == COMPLEX_TYPE
)
3366 warning_at (ploc
, OPT_Wtraditional_conversion
,
3367 "passing argument %d of %qE as integer rather "
3368 "than complex due to prototype",
3370 else if (TREE_CODE (type
) == COMPLEX_TYPE
3371 && TREE_CODE (valtype
) == REAL_TYPE
)
3372 warning_at (ploc
, OPT_Wtraditional_conversion
,
3373 "passing argument %d of %qE as complex rather "
3374 "than floating due to prototype",
3376 else if (TREE_CODE (type
) == REAL_TYPE
3377 && INTEGRAL_TYPE_P (valtype
))
3378 warning_at (ploc
, OPT_Wtraditional_conversion
,
3379 "passing argument %d of %qE as floating rather "
3380 "than integer due to prototype",
3382 else if (TREE_CODE (type
) == COMPLEX_TYPE
3383 && INTEGRAL_TYPE_P (valtype
))
3384 warning_at (ploc
, OPT_Wtraditional_conversion
,
3385 "passing argument %d of %qE as complex rather "
3386 "than integer due to prototype",
3388 else if (TREE_CODE (type
) == REAL_TYPE
3389 && TREE_CODE (valtype
) == COMPLEX_TYPE
)
3390 warning_at (ploc
, OPT_Wtraditional_conversion
,
3391 "passing argument %d of %qE as floating rather "
3392 "than complex due to prototype",
3394 /* ??? At some point, messages should be written about
3395 conversions between complex types, but that's too messy
3397 else if (TREE_CODE (type
) == REAL_TYPE
3398 && TREE_CODE (valtype
) == REAL_TYPE
)
3400 /* Warn if any argument is passed as `float',
3401 since without a prototype it would be `double'. */
3402 if (formal_prec
== TYPE_PRECISION (float_type_node
)
3403 && type
!= dfloat32_type_node
)
3404 warning_at (ploc
, 0,
3405 "passing argument %d of %qE as %<float%> "
3406 "rather than %<double%> due to prototype",
3409 /* Warn if mismatch between argument and prototype
3410 for decimal float types. Warn of conversions with
3411 binary float types and of precision narrowing due to
3413 else if (type
!= valtype
3414 && (type
== dfloat32_type_node
3415 || type
== dfloat64_type_node
3416 || type
== dfloat128_type_node
3417 || valtype
== dfloat32_type_node
3418 || valtype
== dfloat64_type_node
3419 || valtype
== dfloat128_type_node
)
3421 <= TYPE_PRECISION (valtype
)
3422 || (type
== dfloat128_type_node
3424 != dfloat64_type_node
3426 != dfloat32_type_node
)))
3427 || (type
== dfloat64_type_node
3429 != dfloat32_type_node
))))
3430 warning_at (ploc
, 0,
3431 "passing argument %d of %qE as %qT "
3432 "rather than %qT due to prototype",
3433 argnum
, rname
, type
, valtype
);
3436 /* Detect integer changing in width or signedness.
3437 These warnings are only activated with
3438 -Wtraditional-conversion, not with -Wtraditional. */
3439 else if (warn_traditional_conversion
3440 && INTEGRAL_TYPE_P (type
)
3441 && INTEGRAL_TYPE_P (valtype
))
3443 tree would_have_been
= default_conversion (val
);
3444 tree type1
= TREE_TYPE (would_have_been
);
3446 if (val
== error_mark_node
)
3447 /* VAL could have been of incomplete type. */;
3448 else if (TREE_CODE (type
) == ENUMERAL_TYPE
3449 && (TYPE_MAIN_VARIANT (type
)
3450 == TYPE_MAIN_VARIANT (valtype
)))
3451 /* No warning if function asks for enum
3452 and the actual arg is that enum type. */
3454 else if (formal_prec
!= TYPE_PRECISION (type1
))
3455 warning_at (ploc
, OPT_Wtraditional_conversion
,
3456 "passing argument %d of %qE "
3457 "with different width due to prototype",
3459 else if (TYPE_UNSIGNED (type
) == TYPE_UNSIGNED (type1
))
3461 /* Don't complain if the formal parameter type
3462 is an enum, because we can't tell now whether
3463 the value was an enum--even the same enum. */
3464 else if (TREE_CODE (type
) == ENUMERAL_TYPE
)
3466 else if (TREE_CODE (val
) == INTEGER_CST
3467 && int_fits_type_p (val
, type
))
3468 /* Change in signedness doesn't matter
3469 if a constant value is unaffected. */
3471 /* If the value is extended from a narrower
3472 unsigned type, it doesn't matter whether we
3473 pass it as signed or unsigned; the value
3474 certainly is the same either way. */
3475 else if (TYPE_PRECISION (valtype
) < TYPE_PRECISION (type
)
3476 && TYPE_UNSIGNED (valtype
))
3478 else if (TYPE_UNSIGNED (type
))
3479 warning_at (ploc
, OPT_Wtraditional_conversion
,
3480 "passing argument %d of %qE "
3481 "as unsigned due to prototype",
3484 warning_at (ploc
, OPT_Wtraditional_conversion
,
3485 "passing argument %d of %qE "
3486 "as signed due to prototype",
3491 /* Possibly restore an EXCESS_PRECISION_EXPR for the
3492 sake of better warnings from convert_and_check. */
3493 if (excess_precision
)
3494 val
= build1 (EXCESS_PRECISION_EXPR
, valtype
, val
);
3495 origtype
= (!origtypes
) ? NULL_TREE
: (*origtypes
)[parmnum
];
3496 parmval
= convert_for_assignment (loc
, ploc
, type
,
3497 val
, origtype
, ic_argpass
,
3498 npc
, fundecl
, function
,
3501 if (targetm
.calls
.promote_prototypes (fundecl
? TREE_TYPE (fundecl
) : 0)
3502 && INTEGRAL_TYPE_P (type
)
3503 && (TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
)))
3504 parmval
= default_conversion (parmval
);
3507 else if (promote_float_arg
)
3513 /* Convert `float' to `double'. */
3514 if (warn_double_promotion
&& !c_inhibit_evaluation_warnings
)
3515 warning_at (ploc
, OPT_Wdouble_promotion
,
3516 "implicit conversion from %qT to %qT when passing "
3517 "argument to function",
3518 valtype
, double_type_node
);
3519 parmval
= convert (double_type_node
, val
);
3522 else if ((excess_precision
&& !type_generic
)
3523 || (type_generic_overflow_p
&& parmnum
== 2))
3524 /* A "double" argument with excess precision being passed
3525 without a prototype or in variable arguments.
3526 The last argument of __builtin_*_overflow_p should not be
3528 parmval
= convert (valtype
, val
);
3529 else if ((invalid_func_diag
=
3530 targetm
.calls
.invalid_arg_for_unprototyped_fn (typelist
, fundecl
, val
)))
3532 error (invalid_func_diag
);
3535 else if (TREE_CODE (val
) == ADDR_EXPR
&& reject_gcc_builtin (val
))
3540 /* Convert `short' and `char' to full-size `int'. */
3541 parmval
= default_conversion (val
);
3543 (*values
)[parmnum
] = parmval
;
3544 if (parmval
== error_mark_node
)
3548 typetail
= TREE_CHAIN (typetail
);
3551 gcc_assert (parmnum
== vec_safe_length (values
));
3553 if (typetail
!= NULL_TREE
&& TREE_VALUE (typetail
) != void_type_node
)
3555 error_at (loc
, "too few arguments to function %qE", function
);
3556 inform_declaration (fundecl
);
3560 return error_args
? -1 : (int) parmnum
;
3563 /* This is the entry point used by the parser to build unary operators
3564 in the input. CODE, a tree_code, specifies the unary operator, and
3565 ARG is the operand. For unary plus, the C parser currently uses
3566 CONVERT_EXPR for code.
3568 LOC is the location to use for the tree generated.
3572 parser_build_unary_op (location_t loc
, enum tree_code code
, struct c_expr arg
)
3574 struct c_expr result
;
3576 result
.original_code
= code
;
3577 result
.original_type
= NULL
;
3579 if (reject_gcc_builtin (arg
.value
))
3581 result
.value
= error_mark_node
;
3585 result
.value
= build_unary_op (loc
, code
, arg
.value
, false);
3587 if (TREE_OVERFLOW_P (result
.value
) && !TREE_OVERFLOW_P (arg
.value
))
3588 overflow_warning (loc
, result
.value
, arg
.value
);
3591 /* We are typically called when parsing a prefix token at LOC acting on
3592 ARG. Reflect this by updating the source range of the result to
3593 start at LOC and end at the end of ARG. */
3594 set_c_expr_source_range (&result
,
3595 loc
, arg
.get_finish ());
3600 /* Returns true if TYPE is a character type, *not* including wchar_t. */
3603 char_type_p (tree type
)
3605 return (type
== char_type_node
3606 || type
== unsigned_char_type_node
3607 || type
== signed_char_type_node
3608 || type
== char16_type_node
3609 || type
== char32_type_node
);
3612 /* This is the entry point used by the parser to build binary operators
3613 in the input. CODE, a tree_code, specifies the binary operator, and
3614 ARG1 and ARG2 are the operands. In addition to constructing the
3615 expression, we check for operands that were written with other binary
3616 operators in a way that is likely to confuse the user.
3618 LOCATION is the location of the binary operator. */
3621 parser_build_binary_op (location_t location
, enum tree_code code
,
3622 struct c_expr arg1
, struct c_expr arg2
)
3624 struct c_expr result
;
3626 enum tree_code code1
= arg1
.original_code
;
3627 enum tree_code code2
= arg2
.original_code
;
3628 tree type1
= (arg1
.original_type
3629 ? arg1
.original_type
3630 : TREE_TYPE (arg1
.value
));
3631 tree type2
= (arg2
.original_type
3632 ? arg2
.original_type
3633 : TREE_TYPE (arg2
.value
));
3635 result
.value
= build_binary_op (location
, code
,
3636 arg1
.value
, arg2
.value
, true);
3637 result
.original_code
= code
;
3638 result
.original_type
= NULL
;
3640 if (TREE_CODE (result
.value
) == ERROR_MARK
)
3642 set_c_expr_source_range (&result
,
3644 arg2
.get_finish ());
3648 if (location
!= UNKNOWN_LOCATION
)
3649 protected_set_expr_location (result
.value
, location
);
3651 set_c_expr_source_range (&result
,
3653 arg2
.get_finish ());
3655 /* Check for cases such as x+y<<z which users are likely
3657 if (warn_parentheses
)
3658 warn_about_parentheses (location
, code
, code1
, arg1
.value
, code2
,
3661 if (warn_logical_op
)
3662 warn_logical_operator (location
, code
, TREE_TYPE (result
.value
),
3663 code1
, arg1
.value
, code2
, arg2
.value
);
3665 if (warn_tautological_compare
)
3667 tree lhs
= arg1
.value
;
3668 tree rhs
= arg2
.value
;
3669 if (TREE_CODE (lhs
) == C_MAYBE_CONST_EXPR
)
3671 if (C_MAYBE_CONST_EXPR_PRE (lhs
) != NULL_TREE
3672 && TREE_SIDE_EFFECTS (C_MAYBE_CONST_EXPR_PRE (lhs
)))
3675 lhs
= C_MAYBE_CONST_EXPR_EXPR (lhs
);
3677 if (TREE_CODE (rhs
) == C_MAYBE_CONST_EXPR
)
3679 if (C_MAYBE_CONST_EXPR_PRE (rhs
) != NULL_TREE
3680 && TREE_SIDE_EFFECTS (C_MAYBE_CONST_EXPR_PRE (rhs
)))
3683 rhs
= C_MAYBE_CONST_EXPR_EXPR (rhs
);
3685 if (lhs
!= NULL_TREE
&& rhs
!= NULL_TREE
)
3686 warn_tautological_cmp (location
, code
, lhs
, rhs
);
3689 if (warn_logical_not_paren
3690 && TREE_CODE_CLASS (code
) == tcc_comparison
3691 && code1
== TRUTH_NOT_EXPR
3692 && code2
!= TRUTH_NOT_EXPR
3693 /* Avoid warning for !!x == y. */
3694 && (TREE_CODE (arg1
.value
) != NE_EXPR
3695 || !integer_zerop (TREE_OPERAND (arg1
.value
, 1))))
3697 /* Avoid warning for !b == y where b has _Bool type. */
3698 tree t
= integer_zero_node
;
3699 if (TREE_CODE (arg1
.value
) == EQ_EXPR
3700 && integer_zerop (TREE_OPERAND (arg1
.value
, 1))
3701 && TREE_TYPE (TREE_OPERAND (arg1
.value
, 0)) == integer_type_node
)
3703 t
= TREE_OPERAND (arg1
.value
, 0);
3706 if (TREE_TYPE (t
) != integer_type_node
)
3708 if (TREE_CODE (t
) == C_MAYBE_CONST_EXPR
)
3709 t
= C_MAYBE_CONST_EXPR_EXPR (t
);
3710 else if (CONVERT_EXPR_P (t
))
3711 t
= TREE_OPERAND (t
, 0);
3717 if (TREE_CODE (TREE_TYPE (t
)) != BOOLEAN_TYPE
)
3718 warn_logical_not_parentheses (location
, code
, arg1
.value
, arg2
.value
);
3721 /* Warn about comparisons against string literals, with the exception
3722 of testing for equality or inequality of a string literal with NULL. */
3723 if (code
== EQ_EXPR
|| code
== NE_EXPR
)
3725 if ((code1
== STRING_CST
3726 && !integer_zerop (tree_strip_nop_conversions (arg2
.value
)))
3727 || (code2
== STRING_CST
3728 && !integer_zerop (tree_strip_nop_conversions (arg1
.value
))))
3729 warning_at (location
, OPT_Waddress
,
3730 "comparison with string literal results in unspecified behavior");
3731 /* Warn for ptr == '\0', it's likely that it should've been ptr[0]. */
3732 if (POINTER_TYPE_P (type1
)
3733 && null_pointer_constant_p (arg2
.value
)
3734 && char_type_p (type2
)
3735 && warning_at (location
, OPT_Wpointer_compare
,
3736 "comparison between pointer and zero character "
3738 inform (arg1
.get_start (), "did you mean to dereference the pointer?");
3739 else if (POINTER_TYPE_P (type2
)
3740 && null_pointer_constant_p (arg1
.value
)
3741 && char_type_p (type1
)
3742 && warning_at (location
, OPT_Wpointer_compare
,
3743 "comparison between pointer and zero character "
3745 inform (arg2
.get_start (), "did you mean to dereference the pointer?");
3747 else if (TREE_CODE_CLASS (code
) == tcc_comparison
3748 && (code1
== STRING_CST
|| code2
== STRING_CST
))
3749 warning_at (location
, OPT_Waddress
,
3750 "comparison with string literal results in unspecified behavior");
3752 if (TREE_OVERFLOW_P (result
.value
)
3753 && !TREE_OVERFLOW_P (arg1
.value
)
3754 && !TREE_OVERFLOW_P (arg2
.value
))
3755 overflow_warning (location
, result
.value
);
3757 /* Warn about comparisons of different enum types. */
3758 if (warn_enum_compare
3759 && TREE_CODE_CLASS (code
) == tcc_comparison
3760 && TREE_CODE (type1
) == ENUMERAL_TYPE
3761 && TREE_CODE (type2
) == ENUMERAL_TYPE
3762 && TYPE_MAIN_VARIANT (type1
) != TYPE_MAIN_VARIANT (type2
))
3763 warning_at (location
, OPT_Wenum_compare
,
3764 "comparison between %qT and %qT",
3770 /* Return a tree for the difference of pointers OP0 and OP1.
3771 The resulting tree has type ptrdiff_t. If POINTER_SUBTRACT sanitization is
3772 enabled, assign to INSTRUMENT_EXPR call to libsanitizer. */
3775 pointer_diff (location_t loc
, tree op0
, tree op1
, tree
*instrument_expr
)
3777 tree restype
= ptrdiff_type_node
;
3778 tree result
, inttype
;
3780 addr_space_t as0
= TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (op0
)));
3781 addr_space_t as1
= TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (op1
)));
3782 tree target_type
= TREE_TYPE (TREE_TYPE (op0
));
3783 tree orig_op1
= op1
;
3785 /* If the operands point into different address spaces, we need to
3786 explicitly convert them to pointers into the common address space
3787 before we can subtract the numerical address values. */
3790 addr_space_t as_common
;
3793 /* Determine the common superset address space. This is guaranteed
3794 to exist because the caller verified that comp_target_types
3795 returned non-zero. */
3796 if (!addr_space_superset (as0
, as1
, &as_common
))
3799 common_type
= common_pointer_type (TREE_TYPE (op0
), TREE_TYPE (op1
));
3800 op0
= convert (common_type
, op0
);
3801 op1
= convert (common_type
, op1
);
3804 /* Determine integer type result of the subtraction. This will usually
3805 be the same as the result type (ptrdiff_t), but may need to be a wider
3806 type if pointers for the address space are wider than ptrdiff_t. */
3807 if (TYPE_PRECISION (restype
) < TYPE_PRECISION (TREE_TYPE (op0
)))
3808 inttype
= c_common_type_for_size (TYPE_PRECISION (TREE_TYPE (op0
)), 0);
3812 if (TREE_CODE (target_type
) == VOID_TYPE
)
3813 pedwarn (loc
, OPT_Wpointer_arith
,
3814 "pointer of type %<void *%> used in subtraction");
3815 if (TREE_CODE (target_type
) == FUNCTION_TYPE
)
3816 pedwarn (loc
, OPT_Wpointer_arith
,
3817 "pointer to a function used in subtraction");
3819 if (sanitize_flags_p (SANITIZE_POINTER_SUBTRACT
))
3821 gcc_assert (current_function_decl
!= NULL_TREE
);
3823 op0
= save_expr (op0
);
3824 op1
= save_expr (op1
);
3826 tree tt
= builtin_decl_explicit (BUILT_IN_ASAN_POINTER_SUBTRACT
);
3827 *instrument_expr
= build_call_expr_loc (loc
, tt
, 2, op0
, op1
);
3830 /* First do the subtraction, then build the divide operator
3831 and only convert at the very end.
3832 Do not do default conversions in case restype is a short type. */
3834 /* POINTER_DIFF_EXPR requires a signed integer type of the same size as
3835 pointers. If some platform cannot provide that, or has a larger
3836 ptrdiff_type to support differences larger than half the address
3837 space, cast the pointers to some larger integer type and do the
3838 computations in that type. */
3839 if (TYPE_PRECISION (inttype
) > TYPE_PRECISION (TREE_TYPE (op0
)))
3840 op0
= build_binary_op (loc
, MINUS_EXPR
, convert (inttype
, op0
),
3841 convert (inttype
, op1
), false);
3844 /* Cast away qualifiers. */
3845 op0
= convert (c_common_type (TREE_TYPE (op0
), TREE_TYPE (op0
)), op0
);
3846 op1
= convert (c_common_type (TREE_TYPE (op1
), TREE_TYPE (op1
)), op1
);
3847 op0
= build2_loc (loc
, POINTER_DIFF_EXPR
, inttype
, op0
, op1
);
3850 /* This generates an error if op1 is pointer to incomplete type. */
3851 if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (orig_op1
))))
3852 error_at (loc
, "arithmetic on pointer to an incomplete type");
3854 op1
= c_size_in_bytes (target_type
);
3856 if (pointer_to_zero_sized_aggr_p (TREE_TYPE (orig_op1
)))
3857 error_at (loc
, "arithmetic on pointer to an empty aggregate");
3859 /* Divide by the size, in easiest possible way. */
3860 result
= fold_build2_loc (loc
, EXACT_DIV_EXPR
, inttype
,
3861 op0
, convert (inttype
, op1
));
3863 /* Convert to final result type if necessary. */
3864 return convert (restype
, result
);
3867 /* Expand atomic compound assignments into an appropriate sequence as
3868 specified by the C11 standard section 6.5.16.2.
3874 This sequence is used for all types for which these operations are
3877 In addition, built-in versions of the 'fe' prefixed routines may
3878 need to be invoked for floating point (real, complex or vector) when
3879 floating-point exceptions are supported. See 6.5.16.2 footnote 113.
3889 __atomic_load (addr, &old, SEQ_CST);
3890 feholdexcept (&fenv);
3892 newval = old op val;
3893 if (__atomic_compare_exchange_strong (addr, &old, &newval, SEQ_CST,
3896 feclearexcept (FE_ALL_EXCEPT);
3899 feupdateenv (&fenv);
3901 The compiler will issue the __atomic_fetch_* built-in when possible,
3902 otherwise it will generate the generic form of the atomic operations.
3903 This requires temp(s) and has their address taken. The atomic processing
3904 is smart enough to figure out when the size of an object can utilize
3905 a lock-free version, and convert the built-in call to the appropriate
3906 lock-free routine. The optimizers will then dispose of any temps that
3907 are no longer required, and lock-free implementations are utilized as
3908 long as there is target support for the required size.
3910 If the operator is NOP_EXPR, then this is a simple assignment, and
3911 an __atomic_store is issued to perform the assignment rather than
3914 /* Build an atomic assignment at LOC, expanding into the proper
3915 sequence to store LHS MODIFYCODE= RHS. Return a value representing
3916 the result of the operation, unless RETURN_OLD_P, in which case
3917 return the old value of LHS (this is only for postincrement and
3921 build_atomic_assign (location_t loc
, tree lhs
, enum tree_code modifycode
,
3922 tree rhs
, bool return_old_p
)
3924 tree fndecl
, func_call
;
3925 vec
<tree
, va_gc
> *params
;
3926 tree val
, nonatomic_lhs_type
, nonatomic_rhs_type
, newval
, newval_addr
;
3929 tree stmt
, goto_stmt
;
3930 tree loop_label
, loop_decl
, done_label
, done_decl
;
3932 tree lhs_type
= TREE_TYPE (lhs
);
3933 tree lhs_addr
= build_unary_op (loc
, ADDR_EXPR
, lhs
, false);
3934 tree seq_cst
= build_int_cst (integer_type_node
, MEMMODEL_SEQ_CST
);
3935 tree rhs_semantic_type
= TREE_TYPE (rhs
);
3936 tree nonatomic_rhs_semantic_type
;
3939 gcc_assert (TYPE_ATOMIC (lhs_type
));
3942 gcc_assert (modifycode
== PLUS_EXPR
|| modifycode
== MINUS_EXPR
);
3944 /* Allocate enough vector items for a compare_exchange. */
3945 vec_alloc (params
, 6);
3947 /* Create a compound statement to hold the sequence of statements
3949 compound_stmt
= c_begin_compound_stmt (false);
3951 /* Remove any excess precision (which is only present here in the
3952 case of compound assignments). */
3953 if (TREE_CODE (rhs
) == EXCESS_PRECISION_EXPR
)
3955 gcc_assert (modifycode
!= NOP_EXPR
);
3956 rhs
= TREE_OPERAND (rhs
, 0);
3958 rhs_type
= TREE_TYPE (rhs
);
3960 /* Fold the RHS if it hasn't already been folded. */
3961 if (modifycode
!= NOP_EXPR
)
3962 rhs
= c_fully_fold (rhs
, false, NULL
);
3964 /* Remove the qualifiers for the rest of the expressions and create
3965 the VAL temp variable to hold the RHS. */
3966 nonatomic_lhs_type
= build_qualified_type (lhs_type
, TYPE_UNQUALIFIED
);
3967 nonatomic_rhs_type
= build_qualified_type (rhs_type
, TYPE_UNQUALIFIED
);
3968 nonatomic_rhs_semantic_type
= build_qualified_type (rhs_semantic_type
,
3970 val
= create_tmp_var_raw (nonatomic_rhs_type
);
3971 TREE_ADDRESSABLE (val
) = 1;
3972 TREE_NO_WARNING (val
) = 1;
3973 rhs
= build4 (TARGET_EXPR
, nonatomic_rhs_type
, val
, rhs
, NULL_TREE
,
3975 SET_EXPR_LOCATION (rhs
, loc
);
3978 /* NOP_EXPR indicates it's a straight store of the RHS. Simply issue
3980 if (modifycode
== NOP_EXPR
)
3982 /* Build __atomic_store (&lhs, &val, SEQ_CST) */
3983 rhs
= build_unary_op (loc
, ADDR_EXPR
, val
, false);
3984 fndecl
= builtin_decl_explicit (BUILT_IN_ATOMIC_STORE
);
3985 params
->quick_push (lhs_addr
);
3986 params
->quick_push (rhs
);
3987 params
->quick_push (seq_cst
);
3988 func_call
= c_build_function_call_vec (loc
, vNULL
, fndecl
, params
, NULL
);
3989 add_stmt (func_call
);
3991 /* Finish the compound statement. */
3992 compound_stmt
= c_end_compound_stmt (loc
, compound_stmt
, false);
3994 /* VAL is the value which was stored, return a COMPOUND_STMT of
3995 the statement and that value. */
3996 return build2 (COMPOUND_EXPR
, nonatomic_lhs_type
, compound_stmt
, val
);
3999 /* Attempt to implement the atomic operation as an __atomic_fetch_* or
4000 __atomic_*_fetch built-in rather than a CAS loop. atomic_bool type
4001 isn't applicable for such builtins. ??? Do we want to handle enums? */
4002 if ((TREE_CODE (lhs_type
) == INTEGER_TYPE
|| POINTER_TYPE_P (lhs_type
))
4003 && TREE_CODE (rhs_type
) == INTEGER_TYPE
)
4005 built_in_function fncode
;
4009 case POINTER_PLUS_EXPR
:
4010 fncode
= (return_old_p
4011 ? BUILT_IN_ATOMIC_FETCH_ADD_N
4012 : BUILT_IN_ATOMIC_ADD_FETCH_N
);
4015 fncode
= (return_old_p
4016 ? BUILT_IN_ATOMIC_FETCH_SUB_N
4017 : BUILT_IN_ATOMIC_SUB_FETCH_N
);
4020 fncode
= (return_old_p
4021 ? BUILT_IN_ATOMIC_FETCH_AND_N
4022 : BUILT_IN_ATOMIC_AND_FETCH_N
);
4025 fncode
= (return_old_p
4026 ? BUILT_IN_ATOMIC_FETCH_OR_N
4027 : BUILT_IN_ATOMIC_OR_FETCH_N
);
4030 fncode
= (return_old_p
4031 ? BUILT_IN_ATOMIC_FETCH_XOR_N
4032 : BUILT_IN_ATOMIC_XOR_FETCH_N
);
4038 /* We can only use "_1" through "_16" variants of the atomic fetch
4040 unsigned HOST_WIDE_INT size
= tree_to_uhwi (TYPE_SIZE_UNIT (lhs_type
));
4041 if (size
!= 1 && size
!= 2 && size
!= 4 && size
!= 8 && size
!= 16)
4044 /* If this is a pointer type, we need to multiply by the size of
4045 the pointer target type. */
4046 if (POINTER_TYPE_P (lhs_type
))
4048 if (!COMPLETE_TYPE_P (TREE_TYPE (lhs_type
))
4049 /* ??? This would introduce -Wdiscarded-qualifiers
4050 warning: __atomic_fetch_* expect volatile void *
4051 type as the first argument. (Assignments between
4052 atomic and non-atomic objects are OK.) */
4053 || TYPE_RESTRICT (lhs_type
))
4055 tree sz
= TYPE_SIZE_UNIT (TREE_TYPE (lhs_type
));
4056 rhs
= fold_build2_loc (loc
, MULT_EXPR
, ptrdiff_type_node
,
4057 convert (ptrdiff_type_node
, rhs
),
4058 convert (ptrdiff_type_node
, sz
));
4061 /* Build __atomic_fetch_* (&lhs, &val, SEQ_CST), or
4062 __atomic_*_fetch (&lhs, &val, SEQ_CST). */
4063 fndecl
= builtin_decl_explicit (fncode
);
4064 params
->quick_push (lhs_addr
);
4065 params
->quick_push (rhs
);
4066 params
->quick_push (seq_cst
);
4067 func_call
= c_build_function_call_vec (loc
, vNULL
, fndecl
, params
, NULL
);
4069 newval
= create_tmp_var_raw (nonatomic_lhs_type
);
4070 TREE_ADDRESSABLE (newval
) = 1;
4071 TREE_NO_WARNING (newval
) = 1;
4072 rhs
= build4 (TARGET_EXPR
, nonatomic_lhs_type
, newval
, func_call
,
4073 NULL_TREE
, NULL_TREE
);
4074 SET_EXPR_LOCATION (rhs
, loc
);
4077 /* Finish the compound statement. */
4078 compound_stmt
= c_end_compound_stmt (loc
, compound_stmt
, false);
4080 /* NEWVAL is the value which was stored, return a COMPOUND_STMT of
4081 the statement and that value. */
4082 return build2 (COMPOUND_EXPR
, nonatomic_lhs_type
, compound_stmt
, newval
);
4086 /* Create the variables and labels required for the op= form. */
4087 old
= create_tmp_var_raw (nonatomic_lhs_type
);
4088 old_addr
= build_unary_op (loc
, ADDR_EXPR
, old
, false);
4089 TREE_ADDRESSABLE (old
) = 1;
4090 TREE_NO_WARNING (old
) = 1;
4092 newval
= create_tmp_var_raw (nonatomic_lhs_type
);
4093 newval_addr
= build_unary_op (loc
, ADDR_EXPR
, newval
, false);
4094 TREE_ADDRESSABLE (newval
) = 1;
4095 TREE_NO_WARNING (newval
) = 1;
4097 loop_decl
= create_artificial_label (loc
);
4098 loop_label
= build1 (LABEL_EXPR
, void_type_node
, loop_decl
);
4100 done_decl
= create_artificial_label (loc
);
4101 done_label
= build1 (LABEL_EXPR
, void_type_node
, done_decl
);
4103 /* __atomic_load (addr, &old, SEQ_CST). */
4104 fndecl
= builtin_decl_explicit (BUILT_IN_ATOMIC_LOAD
);
4105 params
->quick_push (lhs_addr
);
4106 params
->quick_push (old_addr
);
4107 params
->quick_push (seq_cst
);
4108 func_call
= c_build_function_call_vec (loc
, vNULL
, fndecl
, params
, NULL
);
4109 old
= build4 (TARGET_EXPR
, nonatomic_lhs_type
, old
, func_call
, NULL_TREE
,
4112 params
->truncate (0);
4114 /* Create the expressions for floating-point environment
4115 manipulation, if required. */
4116 bool need_fenv
= (flag_trapping_math
4117 && (FLOAT_TYPE_P (lhs_type
) || FLOAT_TYPE_P (rhs_type
)));
4118 tree hold_call
= NULL_TREE
, clear_call
= NULL_TREE
, update_call
= NULL_TREE
;
4120 targetm
.atomic_assign_expand_fenv (&hold_call
, &clear_call
, &update_call
);
4123 add_stmt (hold_call
);
4126 add_stmt (loop_label
);
4128 /* newval = old + val; */
4129 if (rhs_type
!= rhs_semantic_type
)
4130 val
= build1 (EXCESS_PRECISION_EXPR
, nonatomic_rhs_semantic_type
, val
);
4131 rhs
= build_binary_op (loc
, modifycode
, old
, val
, true);
4132 if (TREE_CODE (rhs
) == EXCESS_PRECISION_EXPR
)
4134 tree eptype
= TREE_TYPE (rhs
);
4135 rhs
= c_fully_fold (TREE_OPERAND (rhs
, 0), false, NULL
);
4136 rhs
= build1 (EXCESS_PRECISION_EXPR
, eptype
, rhs
);
4139 rhs
= c_fully_fold (rhs
, false, NULL
);
4140 rhs
= convert_for_assignment (loc
, UNKNOWN_LOCATION
, nonatomic_lhs_type
,
4141 rhs
, NULL_TREE
, ic_assign
, false, NULL_TREE
,
4143 if (rhs
!= error_mark_node
)
4145 rhs
= build4 (TARGET_EXPR
, nonatomic_lhs_type
, newval
, rhs
, NULL_TREE
,
4147 SET_EXPR_LOCATION (rhs
, loc
);
4151 /* if (__atomic_compare_exchange (addr, &old, &new, false, SEQ_CST, SEQ_CST))
4153 fndecl
= builtin_decl_explicit (BUILT_IN_ATOMIC_COMPARE_EXCHANGE
);
4154 params
->quick_push (lhs_addr
);
4155 params
->quick_push (old_addr
);
4156 params
->quick_push (newval_addr
);
4157 params
->quick_push (integer_zero_node
);
4158 params
->quick_push (seq_cst
);
4159 params
->quick_push (seq_cst
);
4160 func_call
= c_build_function_call_vec (loc
, vNULL
, fndecl
, params
, NULL
);
4162 goto_stmt
= build1 (GOTO_EXPR
, void_type_node
, done_decl
);
4163 SET_EXPR_LOCATION (goto_stmt
, loc
);
4165 stmt
= build3 (COND_EXPR
, void_type_node
, func_call
, goto_stmt
, NULL_TREE
);
4166 SET_EXPR_LOCATION (stmt
, loc
);
4170 add_stmt (clear_call
);
4173 goto_stmt
= build1 (GOTO_EXPR
, void_type_node
, loop_decl
);
4174 SET_EXPR_LOCATION (goto_stmt
, loc
);
4175 add_stmt (goto_stmt
);
4178 add_stmt (done_label
);
4181 add_stmt (update_call
);
4183 /* Finish the compound statement. */
4184 compound_stmt
= c_end_compound_stmt (loc
, compound_stmt
, false);
4186 /* NEWVAL is the value that was successfully stored, return a
4187 COMPOUND_EXPR of the statement and the appropriate value. */
4188 return build2 (COMPOUND_EXPR
, nonatomic_lhs_type
, compound_stmt
,
4189 return_old_p
? old
: newval
);
4192 /* Construct and perhaps optimize a tree representation
4193 for a unary operation. CODE, a tree_code, specifies the operation
4194 and XARG is the operand.
4195 For any CODE other than ADDR_EXPR, NOCONVERT suppresses the default
4196 promotions (such as from short to int).
4197 For ADDR_EXPR, the default promotions are not applied; NOCONVERT allows
4198 non-lvalues; this is only used to handle conversion of non-lvalue arrays
4201 LOCATION is the location of the operator. */
4204 build_unary_op (location_t location
, enum tree_code code
, tree xarg
,
4207 /* No default_conversion here. It causes trouble for ADDR_EXPR. */
4209 tree argtype
= NULL_TREE
;
4210 enum tree_code typecode
;
4212 tree ret
= error_mark_node
;
4213 tree eptype
= NULL_TREE
;
4214 const char *invalid_op_diag
;
4217 int_operands
= EXPR_INT_CONST_OPERANDS (xarg
);
4219 arg
= remove_c_maybe_const_expr (arg
);
4221 if (code
!= ADDR_EXPR
)
4222 arg
= require_complete_type (location
, arg
);
4224 typecode
= TREE_CODE (TREE_TYPE (arg
));
4225 if (typecode
== ERROR_MARK
)
4226 return error_mark_node
;
4227 if (typecode
== ENUMERAL_TYPE
|| typecode
== BOOLEAN_TYPE
)
4228 typecode
= INTEGER_TYPE
;
4230 if ((invalid_op_diag
4231 = targetm
.invalid_unary_op (code
, TREE_TYPE (xarg
))))
4233 error_at (location
, invalid_op_diag
);
4234 return error_mark_node
;
4237 if (TREE_CODE (arg
) == EXCESS_PRECISION_EXPR
)
4239 eptype
= TREE_TYPE (arg
);
4240 arg
= TREE_OPERAND (arg
, 0);
4246 /* This is used for unary plus, because a CONVERT_EXPR
4247 is enough to prevent anybody from looking inside for
4248 associativity, but won't generate any code. */
4249 if (!(typecode
== INTEGER_TYPE
|| typecode
== REAL_TYPE
4250 || typecode
== FIXED_POINT_TYPE
|| typecode
== COMPLEX_TYPE
4251 || typecode
== VECTOR_TYPE
))
4253 error_at (location
, "wrong type argument to unary plus");
4254 return error_mark_node
;
4256 else if (!noconvert
)
4257 arg
= default_conversion (arg
);
4258 arg
= non_lvalue_loc (location
, arg
);
4262 if (!(typecode
== INTEGER_TYPE
|| typecode
== REAL_TYPE
4263 || typecode
== FIXED_POINT_TYPE
|| typecode
== COMPLEX_TYPE
4264 || typecode
== VECTOR_TYPE
))
4266 error_at (location
, "wrong type argument to unary minus");
4267 return error_mark_node
;
4269 else if (!noconvert
)
4270 arg
= default_conversion (arg
);
4274 /* ~ works on integer types and non float vectors. */
4275 if (typecode
== INTEGER_TYPE
4276 || (typecode
== VECTOR_TYPE
4277 && !VECTOR_FLOAT_TYPE_P (TREE_TYPE (arg
))))
4281 /* Warn if the expression has boolean value. */
4282 while (TREE_CODE (e
) == COMPOUND_EXPR
)
4283 e
= TREE_OPERAND (e
, 1);
4285 if ((TREE_CODE (TREE_TYPE (arg
)) == BOOLEAN_TYPE
4286 || truth_value_p (TREE_CODE (e
)))
4287 && warning_at (location
, OPT_Wbool_operation
,
4288 "%<~%> on a boolean expression"))
4290 gcc_rich_location
richloc (location
);
4291 richloc
.add_fixit_insert_before (location
, "!");
4292 inform (&richloc
, "did you mean to use logical not?");
4295 arg
= default_conversion (arg
);
4297 else if (typecode
== COMPLEX_TYPE
)
4300 pedwarn (location
, OPT_Wpedantic
,
4301 "ISO C does not support %<~%> for complex conjugation");
4303 arg
= default_conversion (arg
);
4307 error_at (location
, "wrong type argument to bit-complement");
4308 return error_mark_node
;
4313 if (!(typecode
== INTEGER_TYPE
|| typecode
== REAL_TYPE
))
4315 error_at (location
, "wrong type argument to abs");
4316 return error_mark_node
;
4318 else if (!noconvert
)
4319 arg
= default_conversion (arg
);
4323 /* Conjugating a real value is a no-op, but allow it anyway. */
4324 if (!(typecode
== INTEGER_TYPE
|| typecode
== REAL_TYPE
4325 || typecode
== COMPLEX_TYPE
))
4327 error_at (location
, "wrong type argument to conjugation");
4328 return error_mark_node
;
4330 else if (!noconvert
)
4331 arg
= default_conversion (arg
);
4334 case TRUTH_NOT_EXPR
:
4335 if (typecode
!= INTEGER_TYPE
&& typecode
!= FIXED_POINT_TYPE
4336 && typecode
!= REAL_TYPE
&& typecode
!= POINTER_TYPE
4337 && typecode
!= COMPLEX_TYPE
)
4340 "wrong type argument to unary exclamation mark");
4341 return error_mark_node
;
4345 arg
= c_objc_common_truthvalue_conversion (location
, xarg
);
4346 arg
= remove_c_maybe_const_expr (arg
);
4349 arg
= c_objc_common_truthvalue_conversion (location
, arg
);
4350 ret
= invert_truthvalue_loc (location
, arg
);
4351 /* If the TRUTH_NOT_EXPR has been folded, reset the location. */
4352 if (EXPR_P (ret
) && EXPR_HAS_LOCATION (ret
))
4353 location
= EXPR_LOCATION (ret
);
4354 goto return_build_unary_op
;
4358 ret
= build_real_imag_expr (location
, code
, arg
);
4359 if (ret
== error_mark_node
)
4360 return error_mark_node
;
4361 if (eptype
&& TREE_CODE (eptype
) == COMPLEX_TYPE
)
4362 eptype
= TREE_TYPE (eptype
);
4363 goto return_build_unary_op
;
4365 case PREINCREMENT_EXPR
:
4366 case POSTINCREMENT_EXPR
:
4367 case PREDECREMENT_EXPR
:
4368 case POSTDECREMENT_EXPR
:
4370 if (TREE_CODE (arg
) == C_MAYBE_CONST_EXPR
)
4372 tree inner
= build_unary_op (location
, code
,
4373 C_MAYBE_CONST_EXPR_EXPR (arg
),
4375 if (inner
== error_mark_node
)
4376 return error_mark_node
;
4377 ret
= build2 (C_MAYBE_CONST_EXPR
, TREE_TYPE (inner
),
4378 C_MAYBE_CONST_EXPR_PRE (arg
), inner
);
4379 gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (arg
));
4380 C_MAYBE_CONST_EXPR_NON_CONST (ret
) = 1;
4381 goto return_build_unary_op
;
4384 /* Complain about anything that is not a true lvalue. In
4385 Objective-C, skip this check for property_refs. */
4386 if (!objc_is_property_ref (arg
)
4387 && !lvalue_or_else (location
,
4388 arg
, ((code
== PREINCREMENT_EXPR
4389 || code
== POSTINCREMENT_EXPR
)
4392 return error_mark_node
;
4394 if (warn_cxx_compat
&& TREE_CODE (TREE_TYPE (arg
)) == ENUMERAL_TYPE
)
4396 if (code
== PREINCREMENT_EXPR
|| code
== POSTINCREMENT_EXPR
)
4397 warning_at (location
, OPT_Wc___compat
,
4398 "increment of enumeration value is invalid in C++");
4400 warning_at (location
, OPT_Wc___compat
,
4401 "decrement of enumeration value is invalid in C++");
4404 if (TREE_CODE (TREE_TYPE (arg
)) == BOOLEAN_TYPE
)
4406 if (code
== PREINCREMENT_EXPR
|| code
== POSTINCREMENT_EXPR
)
4407 warning_at (location
, OPT_Wbool_operation
,
4408 "increment of a boolean expression");
4410 warning_at (location
, OPT_Wbool_operation
,
4411 "decrement of a boolean expression");
4414 /* Ensure the argument is fully folded inside any SAVE_EXPR. */
4415 arg
= c_fully_fold (arg
, false, NULL
, true);
4418 atomic_op
= really_atomic_lvalue (arg
);
4420 /* Increment or decrement the real part of the value,
4421 and don't change the imaginary part. */
4422 if (typecode
== COMPLEX_TYPE
)
4426 pedwarn (location
, OPT_Wpedantic
,
4427 "ISO C does not support %<++%> and %<--%> on complex types");
4431 arg
= stabilize_reference (arg
);
4432 real
= build_unary_op (EXPR_LOCATION (arg
), REALPART_EXPR
, arg
,
4434 imag
= build_unary_op (EXPR_LOCATION (arg
), IMAGPART_EXPR
, arg
,
4436 real
= build_unary_op (EXPR_LOCATION (arg
), code
, real
, true);
4437 if (real
== error_mark_node
|| imag
== error_mark_node
)
4438 return error_mark_node
;
4439 ret
= build2 (COMPLEX_EXPR
, TREE_TYPE (arg
),
4441 goto return_build_unary_op
;
4445 /* Report invalid types. */
4447 if (typecode
!= POINTER_TYPE
&& typecode
!= FIXED_POINT_TYPE
4448 && typecode
!= INTEGER_TYPE
&& typecode
!= REAL_TYPE
4449 && typecode
!= COMPLEX_TYPE
&& typecode
!= VECTOR_TYPE
)
4451 if (code
== PREINCREMENT_EXPR
|| code
== POSTINCREMENT_EXPR
)
4452 error_at (location
, "wrong type argument to increment");
4454 error_at (location
, "wrong type argument to decrement");
4456 return error_mark_node
;
4462 argtype
= TREE_TYPE (arg
);
4464 /* Compute the increment. */
4466 if (typecode
== POINTER_TYPE
)
4468 /* If pointer target is an incomplete type,
4469 we just cannot know how to do the arithmetic. */
4470 if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (argtype
)))
4472 if (code
== PREINCREMENT_EXPR
|| code
== POSTINCREMENT_EXPR
)
4474 "increment of pointer to an incomplete type %qT",
4475 TREE_TYPE (argtype
));
4478 "decrement of pointer to an incomplete type %qT",
4479 TREE_TYPE (argtype
));
4481 else if (TREE_CODE (TREE_TYPE (argtype
)) == FUNCTION_TYPE
4482 || TREE_CODE (TREE_TYPE (argtype
)) == VOID_TYPE
)
4484 if (code
== PREINCREMENT_EXPR
|| code
== POSTINCREMENT_EXPR
)
4485 pedwarn (location
, OPT_Wpointer_arith
,
4486 "wrong type argument to increment");
4488 pedwarn (location
, OPT_Wpointer_arith
,
4489 "wrong type argument to decrement");
4492 inc
= c_size_in_bytes (TREE_TYPE (argtype
));
4493 inc
= convert_to_ptrofftype_loc (location
, inc
);
4495 else if (FRACT_MODE_P (TYPE_MODE (argtype
)))
4497 /* For signed fract types, we invert ++ to -- or
4498 -- to ++, and change inc from 1 to -1, because
4499 it is not possible to represent 1 in signed fract constants.
4500 For unsigned fract types, the result always overflows and
4501 we get an undefined (original) or the maximum value. */
4502 if (code
== PREINCREMENT_EXPR
)
4503 code
= PREDECREMENT_EXPR
;
4504 else if (code
== PREDECREMENT_EXPR
)
4505 code
= PREINCREMENT_EXPR
;
4506 else if (code
== POSTINCREMENT_EXPR
)
4507 code
= POSTDECREMENT_EXPR
;
4508 else /* code == POSTDECREMENT_EXPR */
4509 code
= POSTINCREMENT_EXPR
;
4511 inc
= integer_minus_one_node
;
4512 inc
= convert (argtype
, inc
);
4516 inc
= VECTOR_TYPE_P (argtype
)
4517 ? build_one_cst (argtype
)
4519 inc
= convert (argtype
, inc
);
4522 /* If 'arg' is an Objective-C PROPERTY_REF expression, then we
4523 need to ask Objective-C to build the increment or decrement
4524 expression for it. */
4525 if (objc_is_property_ref (arg
))
4526 return objc_build_incr_expr_for_property_ref (location
, code
,
4529 /* Report a read-only lvalue. */
4530 if (TYPE_READONLY (argtype
))
4532 readonly_error (location
, arg
,
4533 ((code
== PREINCREMENT_EXPR
4534 || code
== POSTINCREMENT_EXPR
)
4535 ? lv_increment
: lv_decrement
));
4536 return error_mark_node
;
4538 else if (TREE_READONLY (arg
))
4539 readonly_warning (arg
,
4540 ((code
== PREINCREMENT_EXPR
4541 || code
== POSTINCREMENT_EXPR
)
4542 ? lv_increment
: lv_decrement
));
4544 /* If the argument is atomic, use the special code sequences for
4545 atomic compound assignment. */
4548 arg
= stabilize_reference (arg
);
4549 ret
= build_atomic_assign (location
, arg
,
4550 ((code
== PREINCREMENT_EXPR
4551 || code
== POSTINCREMENT_EXPR
)
4554 (FRACT_MODE_P (TYPE_MODE (argtype
))
4556 : integer_one_node
),
4557 (code
== POSTINCREMENT_EXPR
4558 || code
== POSTDECREMENT_EXPR
));
4559 goto return_build_unary_op
;
4562 if (TREE_CODE (TREE_TYPE (arg
)) == BOOLEAN_TYPE
)
4563 val
= boolean_increment (code
, arg
);
4565 val
= build2 (code
, TREE_TYPE (arg
), arg
, inc
);
4566 TREE_SIDE_EFFECTS (val
) = 1;
4567 if (TREE_CODE (val
) != code
)
4568 TREE_NO_WARNING (val
) = 1;
4570 goto return_build_unary_op
;
4574 /* Note that this operation never does default_conversion. */
4576 /* The operand of unary '&' must be an lvalue (which excludes
4577 expressions of type void), or, in C99, the result of a [] or
4578 unary '*' operator. */
4579 if (VOID_TYPE_P (TREE_TYPE (arg
))
4580 && TYPE_QUALS (TREE_TYPE (arg
)) == TYPE_UNQUALIFIED
4581 && (!INDIRECT_REF_P (arg
) || !flag_isoc99
))
4582 pedwarn (location
, 0, "taking address of expression of type %<void%>");
4584 /* Let &* cancel out to simplify resulting code. */
4585 if (INDIRECT_REF_P (arg
))
4587 /* Don't let this be an lvalue. */
4588 if (lvalue_p (TREE_OPERAND (arg
, 0)))
4589 return non_lvalue_loc (location
, TREE_OPERAND (arg
, 0));
4590 ret
= TREE_OPERAND (arg
, 0);
4591 goto return_build_unary_op
;
4594 /* Anything not already handled and not a true memory reference
4595 or a non-lvalue array is an error. */
4596 if (typecode
!= FUNCTION_TYPE
&& !noconvert
4597 && !lvalue_or_else (location
, arg
, lv_addressof
))
4598 return error_mark_node
;
4600 /* Move address operations inside C_MAYBE_CONST_EXPR to simplify
4602 if (TREE_CODE (arg
) == C_MAYBE_CONST_EXPR
)
4604 tree inner
= build_unary_op (location
, code
,
4605 C_MAYBE_CONST_EXPR_EXPR (arg
),
4607 ret
= build2 (C_MAYBE_CONST_EXPR
, TREE_TYPE (inner
),
4608 C_MAYBE_CONST_EXPR_PRE (arg
), inner
);
4609 gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (arg
));
4610 C_MAYBE_CONST_EXPR_NON_CONST (ret
)
4611 = C_MAYBE_CONST_EXPR_NON_CONST (arg
);
4612 goto return_build_unary_op
;
4615 /* Ordinary case; arg is a COMPONENT_REF or a decl. */
4616 argtype
= TREE_TYPE (arg
);
4618 /* If the lvalue is const or volatile, merge that into the type
4619 to which the address will point. This is only needed
4620 for function types. */
4621 if ((DECL_P (arg
) || REFERENCE_CLASS_P (arg
))
4622 && (TREE_READONLY (arg
) || TREE_THIS_VOLATILE (arg
))
4623 && TREE_CODE (argtype
) == FUNCTION_TYPE
)
4625 int orig_quals
= TYPE_QUALS (strip_array_types (argtype
));
4626 int quals
= orig_quals
;
4628 if (TREE_READONLY (arg
))
4629 quals
|= TYPE_QUAL_CONST
;
4630 if (TREE_THIS_VOLATILE (arg
))
4631 quals
|= TYPE_QUAL_VOLATILE
;
4633 argtype
= c_build_qualified_type (argtype
, quals
);
4636 switch (TREE_CODE (arg
))
4639 if (DECL_C_BIT_FIELD (TREE_OPERAND (arg
, 1)))
4641 error_at (location
, "cannot take address of bit-field %qD",
4642 TREE_OPERAND (arg
, 1));
4643 return error_mark_node
;
4649 if (TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (TREE_OPERAND (arg
, 0))))
4651 if (!AGGREGATE_TYPE_P (TREE_TYPE (arg
))
4652 && !VECTOR_TYPE_P (TREE_TYPE (arg
)))
4654 error_at (location
, "cannot take address of scalar with "
4655 "reverse storage order");
4656 return error_mark_node
;
4659 if (TREE_CODE (TREE_TYPE (arg
)) == ARRAY_TYPE
4660 && TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (arg
)))
4661 warning_at (location
, OPT_Wscalar_storage_order
,
4662 "address of array with reverse scalar storage "
4670 if (!c_mark_addressable (arg
))
4671 return error_mark_node
;
4673 gcc_assert (TREE_CODE (arg
) != COMPONENT_REF
4674 || !DECL_C_BIT_FIELD (TREE_OPERAND (arg
, 1)));
4676 argtype
= build_pointer_type (argtype
);
4678 /* ??? Cope with user tricks that amount to offsetof. Delete this
4679 when we have proper support for integer constant expressions. */
4680 val
= get_base_address (arg
);
4681 if (val
&& INDIRECT_REF_P (val
)
4682 && TREE_CONSTANT (TREE_OPERAND (val
, 0)))
4684 ret
= fold_offsetof (arg
, argtype
);
4685 goto return_build_unary_op
;
4688 val
= build1 (ADDR_EXPR
, argtype
, arg
);
4691 goto return_build_unary_op
;
4697 if (argtype
== NULL_TREE
)
4698 argtype
= TREE_TYPE (arg
);
4699 if (TREE_CODE (arg
) == INTEGER_CST
)
4700 ret
= (require_constant_value
4701 ? fold_build1_initializer_loc (location
, code
, argtype
, arg
)
4702 : fold_build1_loc (location
, code
, argtype
, arg
));
4704 ret
= build1 (code
, argtype
, arg
);
4705 return_build_unary_op
:
4706 gcc_assert (ret
!= error_mark_node
);
4707 if (TREE_CODE (ret
) == INTEGER_CST
&& !TREE_OVERFLOW (ret
)
4708 && !(TREE_CODE (xarg
) == INTEGER_CST
&& !TREE_OVERFLOW (xarg
)))
4709 ret
= build1 (NOP_EXPR
, TREE_TYPE (ret
), ret
);
4710 else if (TREE_CODE (ret
) != INTEGER_CST
&& int_operands
)
4711 ret
= note_integer_operands (ret
);
4713 ret
= build1 (EXCESS_PRECISION_EXPR
, eptype
, ret
);
4714 protected_set_expr_location (ret
, location
);
4718 /* Return nonzero if REF is an lvalue valid for this language.
4719 Lvalues can be assigned, unless their type has TYPE_READONLY.
4720 Lvalues can have their address taken, unless they have C_DECL_REGISTER. */
4723 lvalue_p (const_tree ref
)
4725 const enum tree_code code
= TREE_CODE (ref
);
4732 return lvalue_p (TREE_OPERAND (ref
, 0));
4734 case C_MAYBE_CONST_EXPR
:
4735 return lvalue_p (TREE_OPERAND (ref
, 1));
4737 case COMPOUND_LITERAL_EXPR
:
4747 return (TREE_CODE (TREE_TYPE (ref
)) != FUNCTION_TYPE
4748 && TREE_CODE (TREE_TYPE (ref
)) != METHOD_TYPE
);
4751 return TREE_CODE (TREE_TYPE (ref
)) == ARRAY_TYPE
;
4758 /* Give a warning for storing in something that is read-only in GCC
4759 terms but not const in ISO C terms. */
4762 readonly_warning (tree arg
, enum lvalue_use use
)
4767 warning (0, "assignment of read-only location %qE", arg
);
4770 warning (0, "increment of read-only location %qE", arg
);
4773 warning (0, "decrement of read-only location %qE", arg
);
4782 /* Return nonzero if REF is an lvalue valid for this language;
4783 otherwise, print an error message and return zero. USE says
4784 how the lvalue is being used and so selects the error message.
4785 LOCATION is the location at which any error should be reported. */
4788 lvalue_or_else (location_t loc
, const_tree ref
, enum lvalue_use use
)
4790 int win
= lvalue_p (ref
);
4793 lvalue_error (loc
, use
);
4798 /* Mark EXP saying that we need to be able to take the
4799 address of it; it should not be allocated in a register.
4800 Returns true if successful. ARRAY_REF_P is true if this
4801 is for ARRAY_REF construction - in that case we don't want
4802 to look through VIEW_CONVERT_EXPR from VECTOR_TYPE to ARRAY_TYPE,
4803 it is fine to use ARRAY_REFs for vector subscripts on vector
4804 register variables. */
4807 c_mark_addressable (tree exp
, bool array_ref_p
)
4812 switch (TREE_CODE (x
))
4814 case VIEW_CONVERT_EXPR
:
4816 && TREE_CODE (TREE_TYPE (x
)) == ARRAY_TYPE
4817 && VECTOR_TYPE_P (TREE_TYPE (TREE_OPERAND (x
, 0))))
4825 x
= TREE_OPERAND (x
, 0);
4828 case COMPOUND_LITERAL_EXPR
:
4829 TREE_ADDRESSABLE (x
) = 1;
4830 TREE_ADDRESSABLE (COMPOUND_LITERAL_EXPR_DECL (x
)) = 1;
4834 TREE_ADDRESSABLE (x
) = 1;
4841 if (C_DECL_REGISTER (x
)
4842 && DECL_NONLOCAL (x
))
4844 if (TREE_PUBLIC (x
) || is_global_var (x
))
4847 ("global register variable %qD used in nested function", x
);
4850 pedwarn (input_location
, 0, "register variable %qD used in nested function", x
);
4852 else if (C_DECL_REGISTER (x
))
4854 if (TREE_PUBLIC (x
) || is_global_var (x
))
4855 error ("address of global register variable %qD requested", x
);
4857 error ("address of register variable %qD requested", x
);
4863 TREE_ADDRESSABLE (x
) = 1;
4870 /* Convert EXPR to TYPE, warning about conversion problems with
4871 constants. SEMANTIC_TYPE is the type this conversion would use
4872 without excess precision. If SEMANTIC_TYPE is NULL, this function
4873 is equivalent to convert_and_check. This function is a wrapper that
4874 handles conversions that may be different than
4875 the usual ones because of excess precision. */
4878 ep_convert_and_check (location_t loc
, tree type
, tree expr
,
4881 if (TREE_TYPE (expr
) == type
)
4884 /* For C11, integer conversions may have results with excess
4886 if (flag_isoc11
|| !semantic_type
)
4887 return convert_and_check (loc
, type
, expr
);
4889 if (TREE_CODE (TREE_TYPE (expr
)) == INTEGER_TYPE
4890 && TREE_TYPE (expr
) != semantic_type
)
4892 /* For integers, we need to check the real conversion, not
4893 the conversion to the excess precision type. */
4894 expr
= convert_and_check (loc
, semantic_type
, expr
);
4896 /* Result type is the excess precision type, which should be
4897 large enough, so do not check. */
4898 return convert (type
, expr
);
4901 /* Build and return a conditional expression IFEXP ? OP1 : OP2. If
4902 IFEXP_BCP then the condition is a call to __builtin_constant_p, and
4903 if folded to an integer constant then the unselected half may
4904 contain arbitrary operations not normally permitted in constant
4905 expressions. Set the location of the expression to LOC. */
4908 build_conditional_expr (location_t colon_loc
, tree ifexp
, bool ifexp_bcp
,
4909 tree op1
, tree op1_original_type
, location_t op1_loc
,
4910 tree op2
, tree op2_original_type
, location_t op2_loc
)
4914 enum tree_code code1
;
4915 enum tree_code code2
;
4916 tree result_type
= NULL
;
4917 tree semantic_result_type
= NULL
;
4918 tree orig_op1
= op1
, orig_op2
= op2
;
4919 bool int_const
, op1_int_operands
, op2_int_operands
, int_operands
;
4920 bool ifexp_int_operands
;
4923 op1_int_operands
= EXPR_INT_CONST_OPERANDS (orig_op1
);
4924 if (op1_int_operands
)
4925 op1
= remove_c_maybe_const_expr (op1
);
4926 op2_int_operands
= EXPR_INT_CONST_OPERANDS (orig_op2
);
4927 if (op2_int_operands
)
4928 op2
= remove_c_maybe_const_expr (op2
);
4929 ifexp_int_operands
= EXPR_INT_CONST_OPERANDS (ifexp
);
4930 if (ifexp_int_operands
)
4931 ifexp
= remove_c_maybe_const_expr (ifexp
);
4933 /* Promote both alternatives. */
4935 if (TREE_CODE (TREE_TYPE (op1
)) != VOID_TYPE
)
4936 op1
= default_conversion (op1
);
4937 if (TREE_CODE (TREE_TYPE (op2
)) != VOID_TYPE
)
4938 op2
= default_conversion (op2
);
4940 if (TREE_CODE (ifexp
) == ERROR_MARK
4941 || TREE_CODE (TREE_TYPE (op1
)) == ERROR_MARK
4942 || TREE_CODE (TREE_TYPE (op2
)) == ERROR_MARK
)
4943 return error_mark_node
;
4945 type1
= TREE_TYPE (op1
);
4946 code1
= TREE_CODE (type1
);
4947 type2
= TREE_TYPE (op2
);
4948 code2
= TREE_CODE (type2
);
4950 if (code1
== POINTER_TYPE
&& reject_gcc_builtin (op1
))
4951 return error_mark_node
;
4953 if (code2
== POINTER_TYPE
&& reject_gcc_builtin (op2
))
4954 return error_mark_node
;
4956 /* C90 does not permit non-lvalue arrays in conditional expressions.
4957 In C99 they will be pointers by now. */
4958 if (code1
== ARRAY_TYPE
|| code2
== ARRAY_TYPE
)
4960 error_at (colon_loc
, "non-lvalue array in conditional expression");
4961 return error_mark_node
;
4964 if ((TREE_CODE (op1
) == EXCESS_PRECISION_EXPR
4965 || TREE_CODE (op2
) == EXCESS_PRECISION_EXPR
)
4966 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
4967 || code1
== COMPLEX_TYPE
)
4968 && (code2
== INTEGER_TYPE
|| code2
== REAL_TYPE
4969 || code2
== COMPLEX_TYPE
))
4971 semantic_result_type
= c_common_type (type1
, type2
);
4972 if (TREE_CODE (op1
) == EXCESS_PRECISION_EXPR
)
4974 op1
= TREE_OPERAND (op1
, 0);
4975 type1
= TREE_TYPE (op1
);
4976 gcc_assert (TREE_CODE (type1
) == code1
);
4978 if (TREE_CODE (op2
) == EXCESS_PRECISION_EXPR
)
4980 op2
= TREE_OPERAND (op2
, 0);
4981 type2
= TREE_TYPE (op2
);
4982 gcc_assert (TREE_CODE (type2
) == code2
);
4986 if (warn_cxx_compat
)
4988 tree t1
= op1_original_type
? op1_original_type
: TREE_TYPE (orig_op1
);
4989 tree t2
= op2_original_type
? op2_original_type
: TREE_TYPE (orig_op2
);
4991 if (TREE_CODE (t1
) == ENUMERAL_TYPE
4992 && TREE_CODE (t2
) == ENUMERAL_TYPE
4993 && TYPE_MAIN_VARIANT (t1
) != TYPE_MAIN_VARIANT (t2
))
4994 warning_at (colon_loc
, OPT_Wc___compat
,
4995 ("different enum types in conditional is "
4996 "invalid in C++: %qT vs %qT"),
5000 /* Quickly detect the usual case where op1 and op2 have the same type
5002 if (TYPE_MAIN_VARIANT (type1
) == TYPE_MAIN_VARIANT (type2
))
5005 result_type
= type1
;
5007 result_type
= TYPE_MAIN_VARIANT (type1
);
5009 else if ((code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
5010 || code1
== COMPLEX_TYPE
)
5011 && (code2
== INTEGER_TYPE
|| code2
== REAL_TYPE
5012 || code2
== COMPLEX_TYPE
))
5014 /* In C11, a conditional expression between a floating-point
5015 type and an integer type should convert the integer type to
5016 the evaluation format of the floating-point type, with
5017 possible excess precision. */
5018 tree eptype1
= type1
;
5019 tree eptype2
= type2
;
5023 if (ANY_INTEGRAL_TYPE_P (type1
)
5024 && (eptype
= excess_precision_type (type2
)) != NULL_TREE
)
5027 if (!semantic_result_type
)
5028 semantic_result_type
= c_common_type (type1
, type2
);
5030 else if (ANY_INTEGRAL_TYPE_P (type2
)
5031 && (eptype
= excess_precision_type (type1
)) != NULL_TREE
)
5034 if (!semantic_result_type
)
5035 semantic_result_type
= c_common_type (type1
, type2
);
5038 result_type
= c_common_type (eptype1
, eptype2
);
5039 if (result_type
== error_mark_node
)
5040 return error_mark_node
;
5041 do_warn_double_promotion (result_type
, type1
, type2
,
5042 "implicit conversion from %qT to %qT to "
5043 "match other result of conditional",
5046 /* If -Wsign-compare, warn here if type1 and type2 have
5047 different signedness. We'll promote the signed to unsigned
5048 and later code won't know it used to be different.
5049 Do this check on the original types, so that explicit casts
5050 will be considered, but default promotions won't. */
5051 if (c_inhibit_evaluation_warnings
== 0)
5053 int unsigned_op1
= TYPE_UNSIGNED (TREE_TYPE (orig_op1
));
5054 int unsigned_op2
= TYPE_UNSIGNED (TREE_TYPE (orig_op2
));
5056 if (unsigned_op1
^ unsigned_op2
)
5060 /* Do not warn if the result type is signed, since the
5061 signed type will only be chosen if it can represent
5062 all the values of the unsigned type. */
5063 if (!TYPE_UNSIGNED (result_type
))
5067 bool op1_maybe_const
= true;
5068 bool op2_maybe_const
= true;
5070 /* Do not warn if the signed quantity is an
5071 unsuffixed integer literal (or some static
5072 constant expression involving such literals) and
5073 it is non-negative. This warning requires the
5074 operands to be folded for best results, so do
5075 that folding in this case even without
5076 warn_sign_compare to avoid warning options
5077 possibly affecting code generation. */
5078 c_inhibit_evaluation_warnings
5079 += (ifexp
== truthvalue_false_node
);
5080 op1
= c_fully_fold (op1
, require_constant_value
,
5082 c_inhibit_evaluation_warnings
5083 -= (ifexp
== truthvalue_false_node
);
5085 c_inhibit_evaluation_warnings
5086 += (ifexp
== truthvalue_true_node
);
5087 op2
= c_fully_fold (op2
, require_constant_value
,
5089 c_inhibit_evaluation_warnings
5090 -= (ifexp
== truthvalue_true_node
);
5092 if (warn_sign_compare
)
5095 && tree_expr_nonnegative_warnv_p (op1
, &ovf
))
5097 && tree_expr_nonnegative_warnv_p (op2
, &ovf
)))
5099 else if (unsigned_op2
)
5100 warning_at (op1_loc
, OPT_Wsign_compare
,
5101 "operand of ?: changes signedness from "
5102 "%qT to %qT due to unsignedness of other "
5103 "operand", TREE_TYPE (orig_op1
),
5104 TREE_TYPE (orig_op2
));
5106 warning_at (op2_loc
, OPT_Wsign_compare
,
5107 "operand of ?: changes signedness from "
5108 "%qT to %qT due to unsignedness of other "
5109 "operand", TREE_TYPE (orig_op2
),
5110 TREE_TYPE (orig_op1
));
5112 if (!op1_maybe_const
|| TREE_CODE (op1
) != INTEGER_CST
)
5113 op1
= c_wrap_maybe_const (op1
, !op1_maybe_const
);
5114 if (!op2_maybe_const
|| TREE_CODE (op2
) != INTEGER_CST
)
5115 op2
= c_wrap_maybe_const (op2
, !op2_maybe_const
);
5120 else if (code1
== VOID_TYPE
|| code2
== VOID_TYPE
)
5122 if (code1
!= VOID_TYPE
|| code2
!= VOID_TYPE
)
5123 pedwarn (colon_loc
, OPT_Wpedantic
,
5124 "ISO C forbids conditional expr with only one void side");
5125 result_type
= void_type_node
;
5127 else if (code1
== POINTER_TYPE
&& code2
== POINTER_TYPE
)
5129 addr_space_t as1
= TYPE_ADDR_SPACE (TREE_TYPE (type1
));
5130 addr_space_t as2
= TYPE_ADDR_SPACE (TREE_TYPE (type2
));
5131 addr_space_t as_common
;
5133 if (comp_target_types (colon_loc
, type1
, type2
))
5134 result_type
= common_pointer_type (type1
, type2
);
5135 else if (null_pointer_constant_p (orig_op1
))
5136 result_type
= type2
;
5137 else if (null_pointer_constant_p (orig_op2
))
5138 result_type
= type1
;
5139 else if (!addr_space_superset (as1
, as2
, &as_common
))
5141 error_at (colon_loc
, "pointers to disjoint address spaces "
5142 "used in conditional expression");
5143 return error_mark_node
;
5145 else if (VOID_TYPE_P (TREE_TYPE (type1
))
5146 && !TYPE_ATOMIC (TREE_TYPE (type1
)))
5148 if ((TREE_CODE (TREE_TYPE (type2
)) == ARRAY_TYPE
)
5149 && (TYPE_QUALS (strip_array_types (TREE_TYPE (type2
)))
5150 & ~TYPE_QUALS (TREE_TYPE (type1
))))
5151 warning_at (colon_loc
, OPT_Wdiscarded_array_qualifiers
,
5152 "pointer to array loses qualifier "
5153 "in conditional expression");
5155 if (TREE_CODE (TREE_TYPE (type2
)) == FUNCTION_TYPE
)
5156 pedwarn (colon_loc
, OPT_Wpedantic
,
5157 "ISO C forbids conditional expr between "
5158 "%<void *%> and function pointer");
5159 result_type
= build_pointer_type (qualify_type (TREE_TYPE (type1
),
5160 TREE_TYPE (type2
)));
5162 else if (VOID_TYPE_P (TREE_TYPE (type2
))
5163 && !TYPE_ATOMIC (TREE_TYPE (type2
)))
5165 if ((TREE_CODE (TREE_TYPE (type1
)) == ARRAY_TYPE
)
5166 && (TYPE_QUALS (strip_array_types (TREE_TYPE (type1
)))
5167 & ~TYPE_QUALS (TREE_TYPE (type2
))))
5168 warning_at (colon_loc
, OPT_Wdiscarded_array_qualifiers
,
5169 "pointer to array loses qualifier "
5170 "in conditional expression");
5172 if (TREE_CODE (TREE_TYPE (type1
)) == FUNCTION_TYPE
)
5173 pedwarn (colon_loc
, OPT_Wpedantic
,
5174 "ISO C forbids conditional expr between "
5175 "%<void *%> and function pointer");
5176 result_type
= build_pointer_type (qualify_type (TREE_TYPE (type2
),
5177 TREE_TYPE (type1
)));
5179 /* Objective-C pointer comparisons are a bit more lenient. */
5180 else if (objc_have_common_type (type1
, type2
, -3, NULL_TREE
))
5181 result_type
= objc_common_type (type1
, type2
);
5184 int qual
= ENCODE_QUAL_ADDR_SPACE (as_common
);
5186 pedwarn (colon_loc
, 0,
5187 "pointer type mismatch in conditional expression");
5188 result_type
= build_pointer_type
5189 (build_qualified_type (void_type_node
, qual
));
5192 else if (code1
== POINTER_TYPE
&& code2
== INTEGER_TYPE
)
5194 if (!null_pointer_constant_p (orig_op2
))
5195 pedwarn (colon_loc
, 0,
5196 "pointer/integer type mismatch in conditional expression");
5199 op2
= null_pointer_node
;
5201 result_type
= type1
;
5203 else if (code2
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
5205 if (!null_pointer_constant_p (orig_op1
))
5206 pedwarn (colon_loc
, 0,
5207 "pointer/integer type mismatch in conditional expression");
5210 op1
= null_pointer_node
;
5212 result_type
= type2
;
5217 if (flag_cond_mismatch
)
5218 result_type
= void_type_node
;
5221 error_at (colon_loc
, "type mismatch in conditional expression");
5222 return error_mark_node
;
5226 /* Merge const and volatile flags of the incoming types. */
5228 = build_type_variant (result_type
,
5229 TYPE_READONLY (type1
) || TYPE_READONLY (type2
),
5230 TYPE_VOLATILE (type1
) || TYPE_VOLATILE (type2
));
5232 op1
= ep_convert_and_check (colon_loc
, result_type
, op1
,
5233 semantic_result_type
);
5234 op2
= ep_convert_and_check (colon_loc
, result_type
, op2
,
5235 semantic_result_type
);
5237 if (ifexp_bcp
&& ifexp
== truthvalue_true_node
)
5239 op2_int_operands
= true;
5240 op1
= c_fully_fold (op1
, require_constant_value
, NULL
);
5242 if (ifexp_bcp
&& ifexp
== truthvalue_false_node
)
5244 op1_int_operands
= true;
5245 op2
= c_fully_fold (op2
, require_constant_value
, NULL
);
5247 int_const
= int_operands
= (ifexp_int_operands
5249 && op2_int_operands
);
5252 int_const
= ((ifexp
== truthvalue_true_node
5253 && TREE_CODE (orig_op1
) == INTEGER_CST
5254 && !TREE_OVERFLOW (orig_op1
))
5255 || (ifexp
== truthvalue_false_node
5256 && TREE_CODE (orig_op2
) == INTEGER_CST
5257 && !TREE_OVERFLOW (orig_op2
)));
5260 /* Need to convert condition operand into a vector mask. */
5261 if (VECTOR_TYPE_P (TREE_TYPE (ifexp
)))
5263 tree vectype
= TREE_TYPE (ifexp
);
5264 tree elem_type
= TREE_TYPE (vectype
);
5265 tree zero
= build_int_cst (elem_type
, 0);
5266 tree zero_vec
= build_vector_from_val (vectype
, zero
);
5267 tree cmp_type
= build_same_sized_truth_vector_type (vectype
);
5268 ifexp
= build2 (NE_EXPR
, cmp_type
, ifexp
, zero_vec
);
5271 if (int_const
|| (ifexp_bcp
&& TREE_CODE (ifexp
) == INTEGER_CST
))
5272 ret
= fold_build3_loc (colon_loc
, COND_EXPR
, result_type
, ifexp
, op1
, op2
);
5277 /* Use c_fully_fold here, since C_MAYBE_CONST_EXPR might be
5278 nested inside of the expression. */
5279 op1
= c_fully_fold (op1
, false, NULL
);
5280 op2
= c_fully_fold (op2
, false, NULL
);
5282 ret
= build3 (COND_EXPR
, result_type
, ifexp
, op1
, op2
);
5284 ret
= note_integer_operands (ret
);
5286 if (semantic_result_type
)
5287 ret
= build1 (EXCESS_PRECISION_EXPR
, semantic_result_type
, ret
);
5289 protected_set_expr_location (ret
, colon_loc
);
5291 /* If the OP1 and OP2 are the same and don't have side-effects,
5292 warn here, because the COND_EXPR will be turned into OP1. */
5293 if (warn_duplicated_branches
5294 && TREE_CODE (ret
) == COND_EXPR
5295 && (op1
== op2
|| operand_equal_p (op1
, op2
, 0)))
5296 warning_at (EXPR_LOCATION (ret
), OPT_Wduplicated_branches
,
5297 "this condition has identical branches");
5302 /* Return a compound expression that performs two expressions and
5303 returns the value of the second of them.
5305 LOC is the location of the COMPOUND_EXPR. */
5308 build_compound_expr (location_t loc
, tree expr1
, tree expr2
)
5310 bool expr1_int_operands
, expr2_int_operands
;
5311 tree eptype
= NULL_TREE
;
5314 expr1_int_operands
= EXPR_INT_CONST_OPERANDS (expr1
);
5315 if (expr1_int_operands
)
5316 expr1
= remove_c_maybe_const_expr (expr1
);
5317 expr2_int_operands
= EXPR_INT_CONST_OPERANDS (expr2
);
5318 if (expr2_int_operands
)
5319 expr2
= remove_c_maybe_const_expr (expr2
);
5321 if (TREE_CODE (expr1
) == EXCESS_PRECISION_EXPR
)
5322 expr1
= TREE_OPERAND (expr1
, 0);
5323 if (TREE_CODE (expr2
) == EXCESS_PRECISION_EXPR
)
5325 eptype
= TREE_TYPE (expr2
);
5326 expr2
= TREE_OPERAND (expr2
, 0);
5329 if (!TREE_SIDE_EFFECTS (expr1
))
5331 /* The left-hand operand of a comma expression is like an expression
5332 statement: with -Wunused, we should warn if it doesn't have
5333 any side-effects, unless it was explicitly cast to (void). */
5334 if (warn_unused_value
)
5336 if (VOID_TYPE_P (TREE_TYPE (expr1
))
5337 && CONVERT_EXPR_P (expr1
))
5339 else if (VOID_TYPE_P (TREE_TYPE (expr1
))
5340 && TREE_CODE (expr1
) == COMPOUND_EXPR
5341 && CONVERT_EXPR_P (TREE_OPERAND (expr1
, 1)))
5342 ; /* (void) a, (void) b, c */
5344 warning_at (loc
, OPT_Wunused_value
,
5345 "left-hand operand of comma expression has no effect");
5348 else if (TREE_CODE (expr1
) == COMPOUND_EXPR
5349 && warn_unused_value
)
5352 location_t cloc
= loc
;
5353 while (TREE_CODE (r
) == COMPOUND_EXPR
)
5355 if (EXPR_HAS_LOCATION (r
))
5356 cloc
= EXPR_LOCATION (r
);
5357 r
= TREE_OPERAND (r
, 1);
5359 if (!TREE_SIDE_EFFECTS (r
)
5360 && !VOID_TYPE_P (TREE_TYPE (r
))
5361 && !CONVERT_EXPR_P (r
))
5362 warning_at (cloc
, OPT_Wunused_value
,
5363 "right-hand operand of comma expression has no effect");
5366 /* With -Wunused, we should also warn if the left-hand operand does have
5367 side-effects, but computes a value which is not used. For example, in
5368 `foo() + bar(), baz()' the result of the `+' operator is not used,
5369 so we should issue a warning. */
5370 else if (warn_unused_value
)
5371 warn_if_unused_value (expr1
, loc
);
5373 if (expr2
== error_mark_node
)
5374 return error_mark_node
;
5376 ret
= build2 (COMPOUND_EXPR
, TREE_TYPE (expr2
), expr1
, expr2
);
5379 && expr1_int_operands
5380 && expr2_int_operands
)
5381 ret
= note_integer_operands (ret
);
5384 ret
= build1 (EXCESS_PRECISION_EXPR
, eptype
, ret
);
5386 protected_set_expr_location (ret
, loc
);
5390 /* Issue -Wcast-qual warnings when appropriate. TYPE is the type to
5391 which we are casting. OTYPE is the type of the expression being
5392 cast. Both TYPE and OTYPE are pointer types. LOC is the location
5393 of the cast. -Wcast-qual appeared on the command line. Named
5394 address space qualifiers are not handled here, because they result
5395 in different warnings. */
5398 handle_warn_cast_qual (location_t loc
, tree type
, tree otype
)
5400 tree in_type
= type
;
5401 tree in_otype
= otype
;
5406 /* Check that the qualifiers on IN_TYPE are a superset of the
5407 qualifiers of IN_OTYPE. The outermost level of POINTER_TYPE
5408 nodes is uninteresting and we stop as soon as we hit a
5409 non-POINTER_TYPE node on either type. */
5412 in_otype
= TREE_TYPE (in_otype
);
5413 in_type
= TREE_TYPE (in_type
);
5415 /* GNU C allows cv-qualified function types. 'const' means the
5416 function is very pure, 'volatile' means it can't return. We
5417 need to warn when such qualifiers are added, not when they're
5419 if (TREE_CODE (in_otype
) == FUNCTION_TYPE
5420 && TREE_CODE (in_type
) == FUNCTION_TYPE
)
5421 added
|= (TYPE_QUALS_NO_ADDR_SPACE (in_type
)
5422 & ~TYPE_QUALS_NO_ADDR_SPACE (in_otype
));
5424 discarded
|= (TYPE_QUALS_NO_ADDR_SPACE (in_otype
)
5425 & ~TYPE_QUALS_NO_ADDR_SPACE (in_type
));
5427 while (TREE_CODE (in_type
) == POINTER_TYPE
5428 && TREE_CODE (in_otype
) == POINTER_TYPE
);
5431 warning_at (loc
, OPT_Wcast_qual
,
5432 "cast adds %q#v qualifier to function type", added
);
5435 /* There are qualifiers present in IN_OTYPE that are not present
5437 warning_at (loc
, OPT_Wcast_qual
,
5438 "cast discards %qv qualifier from pointer target type",
5441 if (added
|| discarded
)
5444 /* A cast from **T to const **T is unsafe, because it can cause a
5445 const value to be changed with no additional warning. We only
5446 issue this warning if T is the same on both sides, and we only
5447 issue the warning if there are the same number of pointers on
5448 both sides, as otherwise the cast is clearly unsafe anyhow. A
5449 cast is unsafe when a qualifier is added at one level and const
5450 is not present at all outer levels.
5452 To issue this warning, we check at each level whether the cast
5453 adds new qualifiers not already seen. We don't need to special
5454 case function types, as they won't have the same
5455 TYPE_MAIN_VARIANT. */
5457 if (TYPE_MAIN_VARIANT (in_type
) != TYPE_MAIN_VARIANT (in_otype
))
5459 if (TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
)
5464 is_const
= TYPE_READONLY (TREE_TYPE (in_type
));
5467 in_type
= TREE_TYPE (in_type
);
5468 in_otype
= TREE_TYPE (in_otype
);
5469 if ((TYPE_QUALS (in_type
) &~ TYPE_QUALS (in_otype
)) != 0
5472 warning_at (loc
, OPT_Wcast_qual
,
5473 "to be safe all intermediate pointers in cast from "
5474 "%qT to %qT must be %<const%> qualified",
5479 is_const
= TYPE_READONLY (in_type
);
5481 while (TREE_CODE (in_type
) == POINTER_TYPE
);
5484 /* Heuristic check if two parameter types can be considered ABI-equivalent. */
5487 c_safe_arg_type_equiv_p (tree t1
, tree t2
)
5489 t1
= TYPE_MAIN_VARIANT (t1
);
5490 t2
= TYPE_MAIN_VARIANT (t2
);
5492 if (TREE_CODE (t1
) == POINTER_TYPE
5493 && TREE_CODE (t2
) == POINTER_TYPE
)
5496 /* The signedness of the parameter matters only when an integral
5497 type smaller than int is promoted to int, otherwise only the
5498 precision of the parameter matters.
5499 This check should make sure that the callee does not see
5500 undefined values in argument registers. */
5501 if (INTEGRAL_TYPE_P (t1
)
5502 && INTEGRAL_TYPE_P (t2
)
5503 && TYPE_PRECISION (t1
) == TYPE_PRECISION (t2
)
5504 && (TYPE_UNSIGNED (t1
) == TYPE_UNSIGNED (t2
)
5505 || !targetm
.calls
.promote_prototypes (NULL_TREE
)
5506 || TYPE_PRECISION (t1
) >= TYPE_PRECISION (integer_type_node
)))
5509 return comptypes (t1
, t2
);
5512 /* Check if a type cast between two function types can be considered safe. */
5515 c_safe_function_type_cast_p (tree t1
, tree t2
)
5517 if (TREE_TYPE (t1
) == void_type_node
&&
5518 TYPE_ARG_TYPES (t1
) == void_list_node
)
5521 if (TREE_TYPE (t2
) == void_type_node
&&
5522 TYPE_ARG_TYPES (t2
) == void_list_node
)
5525 if (!c_safe_arg_type_equiv_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
5528 for (t1
= TYPE_ARG_TYPES (t1
), t2
= TYPE_ARG_TYPES (t2
);
5530 t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
))
5531 if (!c_safe_arg_type_equiv_p (TREE_VALUE (t1
), TREE_VALUE (t2
)))
5537 /* Build an expression representing a cast to type TYPE of expression EXPR.
5538 LOC is the location of the cast-- typically the open paren of the cast. */
5541 build_c_cast (location_t loc
, tree type
, tree expr
)
5545 if (TREE_CODE (expr
) == EXCESS_PRECISION_EXPR
)
5546 expr
= TREE_OPERAND (expr
, 0);
5550 if (type
== error_mark_node
|| expr
== error_mark_node
)
5551 return error_mark_node
;
5553 /* The ObjC front-end uses TYPE_MAIN_VARIANT to tie together types differing
5554 only in <protocol> qualifications. But when constructing cast expressions,
5555 the protocols do matter and must be kept around. */
5556 if (objc_is_object_ptr (type
) && objc_is_object_ptr (TREE_TYPE (expr
)))
5557 return build1 (NOP_EXPR
, type
, expr
);
5559 type
= TYPE_MAIN_VARIANT (type
);
5561 if (TREE_CODE (type
) == ARRAY_TYPE
)
5563 error_at (loc
, "cast specifies array type");
5564 return error_mark_node
;
5567 if (TREE_CODE (type
) == FUNCTION_TYPE
)
5569 error_at (loc
, "cast specifies function type");
5570 return error_mark_node
;
5573 if (!VOID_TYPE_P (type
))
5575 value
= require_complete_type (loc
, value
);
5576 if (value
== error_mark_node
)
5577 return error_mark_node
;
5580 if (type
== TYPE_MAIN_VARIANT (TREE_TYPE (value
)))
5582 if (RECORD_OR_UNION_TYPE_P (type
))
5583 pedwarn (loc
, OPT_Wpedantic
,
5584 "ISO C forbids casting nonscalar to the same type");
5586 /* Convert to remove any qualifiers from VALUE's type. */
5587 value
= convert (type
, value
);
5589 else if (TREE_CODE (type
) == UNION_TYPE
)
5593 for (field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
5594 if (TREE_TYPE (field
) != error_mark_node
5595 && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (field
)),
5596 TYPE_MAIN_VARIANT (TREE_TYPE (value
))))
5602 bool maybe_const
= true;
5604 pedwarn (loc
, OPT_Wpedantic
, "ISO C forbids casts to union type");
5605 t
= c_fully_fold (value
, false, &maybe_const
);
5606 t
= build_constructor_single (type
, field
, t
);
5608 t
= c_wrap_maybe_const (t
, true);
5609 t
= digest_init (loc
, type
, t
,
5610 NULL_TREE
, false, true, 0);
5611 TREE_CONSTANT (t
) = TREE_CONSTANT (value
);
5614 error_at (loc
, "cast to union type from type not present in union");
5615 return error_mark_node
;
5621 if (type
== void_type_node
)
5623 tree t
= build1 (CONVERT_EXPR
, type
, value
);
5624 SET_EXPR_LOCATION (t
, loc
);
5628 otype
= TREE_TYPE (value
);
5630 /* Optionally warn about potentially worrisome casts. */
5632 && TREE_CODE (type
) == POINTER_TYPE
5633 && TREE_CODE (otype
) == POINTER_TYPE
)
5634 handle_warn_cast_qual (loc
, type
, otype
);
5636 /* Warn about conversions between pointers to disjoint
5638 if (TREE_CODE (type
) == POINTER_TYPE
5639 && TREE_CODE (otype
) == POINTER_TYPE
5640 && !null_pointer_constant_p (value
))
5642 addr_space_t as_to
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
5643 addr_space_t as_from
= TYPE_ADDR_SPACE (TREE_TYPE (otype
));
5644 addr_space_t as_common
;
5646 if (!addr_space_superset (as_to
, as_from
, &as_common
))
5648 if (ADDR_SPACE_GENERIC_P (as_from
))
5649 warning_at (loc
, 0, "cast to %s address space pointer "
5650 "from disjoint generic address space pointer",
5651 c_addr_space_name (as_to
));
5653 else if (ADDR_SPACE_GENERIC_P (as_to
))
5654 warning_at (loc
, 0, "cast to generic address space pointer "
5655 "from disjoint %s address space pointer",
5656 c_addr_space_name (as_from
));
5659 warning_at (loc
, 0, "cast to %s address space pointer "
5660 "from disjoint %s address space pointer",
5661 c_addr_space_name (as_to
),
5662 c_addr_space_name (as_from
));
5666 /* Warn about possible alignment problems. */
5667 if ((STRICT_ALIGNMENT
|| warn_cast_align
== 2)
5668 && TREE_CODE (type
) == POINTER_TYPE
5669 && TREE_CODE (otype
) == POINTER_TYPE
5670 && TREE_CODE (TREE_TYPE (otype
)) != VOID_TYPE
5671 && TREE_CODE (TREE_TYPE (otype
)) != FUNCTION_TYPE
5672 /* Don't warn about opaque types, where the actual alignment
5673 restriction is unknown. */
5674 && !(RECORD_OR_UNION_TYPE_P (TREE_TYPE (otype
))
5675 && TYPE_MODE (TREE_TYPE (otype
)) == VOIDmode
)
5676 && min_align_of_type (TREE_TYPE (type
))
5677 > min_align_of_type (TREE_TYPE (otype
)))
5678 warning_at (loc
, OPT_Wcast_align
,
5679 "cast increases required alignment of target type");
5681 if (TREE_CODE (type
) == INTEGER_TYPE
5682 && TREE_CODE (otype
) == POINTER_TYPE
5683 && TYPE_PRECISION (type
) != TYPE_PRECISION (otype
))
5684 /* Unlike conversion of integers to pointers, where the
5685 warning is disabled for converting constants because
5686 of cases such as SIG_*, warn about converting constant
5687 pointers to integers. In some cases it may cause unwanted
5688 sign extension, and a warning is appropriate. */
5689 warning_at (loc
, OPT_Wpointer_to_int_cast
,
5690 "cast from pointer to integer of different size");
5692 if (TREE_CODE (value
) == CALL_EXPR
5693 && TREE_CODE (type
) != TREE_CODE (otype
))
5694 warning_at (loc
, OPT_Wbad_function_cast
,
5695 "cast from function call of type %qT "
5696 "to non-matching type %qT", otype
, type
);
5698 if (TREE_CODE (type
) == POINTER_TYPE
5699 && TREE_CODE (otype
) == INTEGER_TYPE
5700 && TYPE_PRECISION (type
) != TYPE_PRECISION (otype
)
5701 /* Don't warn about converting any constant. */
5702 && !TREE_CONSTANT (value
))
5704 OPT_Wint_to_pointer_cast
, "cast to pointer from integer "
5705 "of different size");
5707 if (warn_strict_aliasing
<= 2)
5708 strict_aliasing_warning (EXPR_LOCATION (value
), type
, expr
);
5710 /* If pedantic, warn for conversions between function and object
5711 pointer types, except for converting a null pointer constant
5712 to function pointer type. */
5714 && TREE_CODE (type
) == POINTER_TYPE
5715 && TREE_CODE (otype
) == POINTER_TYPE
5716 && TREE_CODE (TREE_TYPE (otype
)) == FUNCTION_TYPE
5717 && TREE_CODE (TREE_TYPE (type
)) != FUNCTION_TYPE
)
5718 pedwarn (loc
, OPT_Wpedantic
, "ISO C forbids "
5719 "conversion of function pointer to object pointer type");
5722 && TREE_CODE (type
) == POINTER_TYPE
5723 && TREE_CODE (otype
) == POINTER_TYPE
5724 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
5725 && TREE_CODE (TREE_TYPE (otype
)) != FUNCTION_TYPE
5726 && !null_pointer_constant_p (value
))
5727 pedwarn (loc
, OPT_Wpedantic
, "ISO C forbids "
5728 "conversion of object pointer to function pointer type");
5730 if (TREE_CODE (type
) == POINTER_TYPE
5731 && TREE_CODE (otype
) == POINTER_TYPE
5732 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
5733 && TREE_CODE (TREE_TYPE (otype
)) == FUNCTION_TYPE
5734 && !c_safe_function_type_cast_p (TREE_TYPE (type
),
5736 warning_at (loc
, OPT_Wcast_function_type
,
5737 "cast between incompatible function types"
5738 " from %qT to %qT", otype
, type
);
5741 value
= convert (type
, value
);
5743 /* Ignore any integer overflow caused by the cast. */
5744 if (TREE_CODE (value
) == INTEGER_CST
&& !FLOAT_TYPE_P (otype
))
5746 if (CONSTANT_CLASS_P (ovalue
) && TREE_OVERFLOW (ovalue
))
5748 if (!TREE_OVERFLOW (value
))
5750 /* Avoid clobbering a shared constant. */
5751 value
= copy_node (value
);
5752 TREE_OVERFLOW (value
) = TREE_OVERFLOW (ovalue
);
5755 else if (TREE_OVERFLOW (value
))
5756 /* Reset VALUE's overflow flags, ensuring constant sharing. */
5757 value
= wide_int_to_tree (TREE_TYPE (value
), wi::to_wide (value
));
5761 /* Don't let a cast be an lvalue. */
5762 if (lvalue_p (value
))
5763 value
= non_lvalue_loc (loc
, value
);
5765 /* Don't allow the results of casting to floating-point or complex
5766 types be confused with actual constants, or casts involving
5767 integer and pointer types other than direct integer-to-integer
5768 and integer-to-pointer be confused with integer constant
5769 expressions and null pointer constants. */
5770 if (TREE_CODE (value
) == REAL_CST
5771 || TREE_CODE (value
) == COMPLEX_CST
5772 || (TREE_CODE (value
) == INTEGER_CST
5773 && !((TREE_CODE (expr
) == INTEGER_CST
5774 && INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
5775 || TREE_CODE (expr
) == REAL_CST
5776 || TREE_CODE (expr
) == COMPLEX_CST
)))
5777 value
= build1 (NOP_EXPR
, type
, value
);
5779 protected_set_expr_location (value
, loc
);
5783 /* Interpret a cast of expression EXPR to type TYPE. LOC is the
5784 location of the open paren of the cast, or the position of the cast
5787 c_cast_expr (location_t loc
, struct c_type_name
*type_name
, tree expr
)
5790 tree type_expr
= NULL_TREE
;
5791 bool type_expr_const
= true;
5793 int saved_wsp
= warn_strict_prototypes
;
5795 /* This avoids warnings about unprototyped casts on
5796 integers. E.g. "#define SIG_DFL (void(*)())0". */
5797 if (TREE_CODE (expr
) == INTEGER_CST
)
5798 warn_strict_prototypes
= 0;
5799 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
5800 warn_strict_prototypes
= saved_wsp
;
5802 if (TREE_CODE (expr
) == ADDR_EXPR
&& !VOID_TYPE_P (type
)
5803 && reject_gcc_builtin (expr
))
5804 return error_mark_node
;
5806 ret
= build_c_cast (loc
, type
, expr
);
5809 bool inner_expr_const
= true;
5810 ret
= c_fully_fold (ret
, require_constant_value
, &inner_expr_const
);
5811 ret
= build2 (C_MAYBE_CONST_EXPR
, TREE_TYPE (ret
), type_expr
, ret
);
5812 C_MAYBE_CONST_EXPR_NON_CONST (ret
) = !(type_expr_const
5813 && inner_expr_const
);
5814 SET_EXPR_LOCATION (ret
, loc
);
5817 if (!EXPR_HAS_LOCATION (ret
))
5818 protected_set_expr_location (ret
, loc
);
5820 /* C++ does not permits types to be defined in a cast, but it
5821 allows references to incomplete types. */
5822 if (warn_cxx_compat
&& type_name
->specs
->typespec_kind
== ctsk_tagdef
)
5823 warning_at (loc
, OPT_Wc___compat
,
5824 "defining a type in a cast is invalid in C++");
5829 /* Build an assignment expression of lvalue LHS from value RHS.
5830 If LHS_ORIGTYPE is not NULL, it is the original type of LHS, which
5831 may differ from TREE_TYPE (LHS) for an enum bitfield.
5832 MODIFYCODE is the code for a binary operator that we use
5833 to combine the old value of LHS with RHS to get the new value.
5834 Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.
5835 If RHS_ORIGTYPE is not NULL_TREE, it is the original type of RHS,
5836 which may differ from TREE_TYPE (RHS) for an enum value.
5838 LOCATION is the location of the MODIFYCODE operator.
5839 RHS_LOC is the location of the RHS. */
5842 build_modify_expr (location_t location
, tree lhs
, tree lhs_origtype
,
5843 enum tree_code modifycode
,
5844 location_t rhs_loc
, tree rhs
, tree rhs_origtype
)
5848 tree rhseval
= NULL_TREE
;
5849 tree lhstype
= TREE_TYPE (lhs
);
5850 tree olhstype
= lhstype
;
5854 /* Types that aren't fully specified cannot be used in assignments. */
5855 lhs
= require_complete_type (location
, lhs
);
5857 /* Avoid duplicate error messages from operands that had errors. */
5858 if (TREE_CODE (lhs
) == ERROR_MARK
|| TREE_CODE (rhs
) == ERROR_MARK
)
5859 return error_mark_node
;
5861 /* Ensure an error for assigning a non-lvalue array to an array in
5863 if (TREE_CODE (lhstype
) == ARRAY_TYPE
)
5865 error_at (location
, "assignment to expression with array type");
5866 return error_mark_node
;
5869 /* For ObjC properties, defer this check. */
5870 if (!objc_is_property_ref (lhs
) && !lvalue_or_else (location
, lhs
, lv_assign
))
5871 return error_mark_node
;
5873 is_atomic_op
= really_atomic_lvalue (lhs
);
5877 if (TREE_CODE (lhs
) == C_MAYBE_CONST_EXPR
)
5879 tree inner
= build_modify_expr (location
, C_MAYBE_CONST_EXPR_EXPR (lhs
),
5880 lhs_origtype
, modifycode
, rhs_loc
, rhs
,
5882 if (inner
== error_mark_node
)
5883 return error_mark_node
;
5884 result
= build2 (C_MAYBE_CONST_EXPR
, TREE_TYPE (inner
),
5885 C_MAYBE_CONST_EXPR_PRE (lhs
), inner
);
5886 gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (lhs
));
5887 C_MAYBE_CONST_EXPR_NON_CONST (result
) = 1;
5888 protected_set_expr_location (result
, location
);
5892 /* If a binary op has been requested, combine the old LHS value with the RHS
5893 producing the value we should actually store into the LHS. */
5895 if (modifycode
!= NOP_EXPR
)
5897 lhs
= c_fully_fold (lhs
, false, NULL
, true);
5898 lhs
= stabilize_reference (lhs
);
5900 /* Construct the RHS for any non-atomic compound assignemnt. */
5903 /* If in LHS op= RHS the RHS has side-effects, ensure they
5904 are preevaluated before the rest of the assignment expression's
5905 side-effects, because RHS could contain e.g. function calls
5907 if (TREE_SIDE_EFFECTS (rhs
))
5909 if (TREE_CODE (rhs
) == EXCESS_PRECISION_EXPR
)
5910 newrhs
= save_expr (TREE_OPERAND (rhs
, 0));
5912 newrhs
= save_expr (rhs
);
5914 if (TREE_CODE (rhs
) == EXCESS_PRECISION_EXPR
)
5915 newrhs
= build1 (EXCESS_PRECISION_EXPR
, TREE_TYPE (rhs
),
5918 newrhs
= build_binary_op (location
,
5919 modifycode
, lhs
, newrhs
, true);
5921 /* The original type of the right hand side is no longer
5923 rhs_origtype
= NULL_TREE
;
5927 if (c_dialect_objc ())
5929 /* Check if we are modifying an Objective-C property reference;
5930 if so, we need to generate setter calls. */
5931 if (TREE_CODE (newrhs
) == EXCESS_PRECISION_EXPR
)
5932 result
= objc_maybe_build_modify_expr (lhs
, TREE_OPERAND (newrhs
, 0));
5934 result
= objc_maybe_build_modify_expr (lhs
, newrhs
);
5938 /* Else, do the check that we postponed for Objective-C. */
5939 if (!lvalue_or_else (location
, lhs
, lv_assign
))
5940 return error_mark_node
;
5943 /* Give an error for storing in something that is 'const'. */
5945 if (TYPE_READONLY (lhstype
)
5946 || (RECORD_OR_UNION_TYPE_P (lhstype
)
5947 && C_TYPE_FIELDS_READONLY (lhstype
)))
5949 readonly_error (location
, lhs
, lv_assign
);
5950 return error_mark_node
;
5952 else if (TREE_READONLY (lhs
))
5953 readonly_warning (lhs
, lv_assign
);
5955 /* If storing into a structure or union member,
5956 it has probably been given type `int'.
5957 Compute the type that would go with
5958 the actual amount of storage the member occupies. */
5960 if (TREE_CODE (lhs
) == COMPONENT_REF
5961 && (TREE_CODE (lhstype
) == INTEGER_TYPE
5962 || TREE_CODE (lhstype
) == BOOLEAN_TYPE
5963 || TREE_CODE (lhstype
) == REAL_TYPE
5964 || TREE_CODE (lhstype
) == ENUMERAL_TYPE
))
5965 lhstype
= TREE_TYPE (get_unwidened (lhs
, 0));
5967 /* If storing in a field that is in actuality a short or narrower than one,
5968 we must store in the field in its actual type. */
5970 if (lhstype
!= TREE_TYPE (lhs
))
5972 lhs
= copy_node (lhs
);
5973 TREE_TYPE (lhs
) = lhstype
;
5976 /* Issue -Wc++-compat warnings about an assignment to an enum type
5977 when LHS does not have its original type. This happens for,
5978 e.g., an enum bitfield in a struct. */
5980 && lhs_origtype
!= NULL_TREE
5981 && lhs_origtype
!= lhstype
5982 && TREE_CODE (lhs_origtype
) == ENUMERAL_TYPE
)
5984 tree checktype
= (rhs_origtype
!= NULL_TREE
5987 if (checktype
!= error_mark_node
5988 && (TYPE_MAIN_VARIANT (checktype
) != TYPE_MAIN_VARIANT (lhs_origtype
)
5989 || (is_atomic_op
&& modifycode
!= NOP_EXPR
)))
5990 warning_at (location
, OPT_Wc___compat
,
5991 "enum conversion in assignment is invalid in C++");
5994 /* If the lhs is atomic, remove that qualifier. */
5997 lhstype
= build_qualified_type (lhstype
,
5998 (TYPE_QUALS (lhstype
)
5999 & ~TYPE_QUAL_ATOMIC
));
6000 olhstype
= build_qualified_type (olhstype
,
6001 (TYPE_QUALS (lhstype
)
6002 & ~TYPE_QUAL_ATOMIC
));
6005 /* Convert new value to destination type. Fold it first, then
6006 restore any excess precision information, for the sake of
6007 conversion warnings. */
6009 if (!(is_atomic_op
&& modifycode
!= NOP_EXPR
))
6011 tree rhs_semantic_type
= NULL_TREE
;
6012 if (TREE_CODE (newrhs
) == EXCESS_PRECISION_EXPR
)
6014 rhs_semantic_type
= TREE_TYPE (newrhs
);
6015 newrhs
= TREE_OPERAND (newrhs
, 0);
6017 npc
= null_pointer_constant_p (newrhs
);
6018 newrhs
= c_fully_fold (newrhs
, false, NULL
);
6019 if (rhs_semantic_type
)
6020 newrhs
= build1 (EXCESS_PRECISION_EXPR
, rhs_semantic_type
, newrhs
);
6021 newrhs
= convert_for_assignment (location
, rhs_loc
, lhstype
, newrhs
,
6022 rhs_origtype
, ic_assign
, npc
,
6023 NULL_TREE
, NULL_TREE
, 0);
6024 if (TREE_CODE (newrhs
) == ERROR_MARK
)
6025 return error_mark_node
;
6028 /* Emit ObjC write barrier, if necessary. */
6029 if (c_dialect_objc () && flag_objc_gc
)
6031 result
= objc_generate_write_barrier (lhs
, modifycode
, newrhs
);
6034 protected_set_expr_location (result
, location
);
6039 /* Scan operands. */
6042 result
= build_atomic_assign (location
, lhs
, modifycode
, newrhs
, false);
6045 result
= build2 (MODIFY_EXPR
, lhstype
, lhs
, newrhs
);
6046 TREE_SIDE_EFFECTS (result
) = 1;
6047 protected_set_expr_location (result
, location
);
6050 /* If we got the LHS in a different type for storing in,
6051 convert the result back to the nominal type of LHS
6052 so that the value we return always has the same type
6053 as the LHS argument. */
6055 if (olhstype
== TREE_TYPE (result
))
6058 result
= convert_for_assignment (location
, rhs_loc
, olhstype
, result
,
6059 rhs_origtype
, ic_assign
, false, NULL_TREE
,
6061 protected_set_expr_location (result
, location
);
6065 result
= build2 (COMPOUND_EXPR
, TREE_TYPE (result
), rhseval
, result
);
6069 /* Return whether STRUCT_TYPE has an anonymous field with type TYPE.
6070 This is used to implement -fplan9-extensions. */
6073 find_anonymous_field_with_type (tree struct_type
, tree type
)
6078 gcc_assert (RECORD_OR_UNION_TYPE_P (struct_type
));
6080 for (field
= TYPE_FIELDS (struct_type
);
6082 field
= TREE_CHAIN (field
))
6084 tree fieldtype
= (TYPE_ATOMIC (TREE_TYPE (field
))
6085 ? c_build_qualified_type (TREE_TYPE (field
),
6087 : TYPE_MAIN_VARIANT (TREE_TYPE (field
)));
6088 if (DECL_NAME (field
) == NULL
6089 && comptypes (type
, fieldtype
))
6095 else if (DECL_NAME (field
) == NULL
6096 && RECORD_OR_UNION_TYPE_P (TREE_TYPE (field
))
6097 && find_anonymous_field_with_type (TREE_TYPE (field
), type
))
6107 /* RHS is an expression whose type is pointer to struct. If there is
6108 an anonymous field in RHS with type TYPE, then return a pointer to
6109 that field in RHS. This is used with -fplan9-extensions. This
6110 returns NULL if no conversion could be found. */
6113 convert_to_anonymous_field (location_t location
, tree type
, tree rhs
)
6115 tree rhs_struct_type
, lhs_main_type
;
6116 tree field
, found_field
;
6117 bool found_sub_field
;
6120 gcc_assert (POINTER_TYPE_P (TREE_TYPE (rhs
)));
6121 rhs_struct_type
= TREE_TYPE (TREE_TYPE (rhs
));
6122 gcc_assert (RECORD_OR_UNION_TYPE_P (rhs_struct_type
));
6124 gcc_assert (POINTER_TYPE_P (type
));
6125 lhs_main_type
= (TYPE_ATOMIC (TREE_TYPE (type
))
6126 ? c_build_qualified_type (TREE_TYPE (type
),
6128 : TYPE_MAIN_VARIANT (TREE_TYPE (type
)));
6130 found_field
= NULL_TREE
;
6131 found_sub_field
= false;
6132 for (field
= TYPE_FIELDS (rhs_struct_type
);
6134 field
= TREE_CHAIN (field
))
6136 if (DECL_NAME (field
) != NULL_TREE
6137 || !RECORD_OR_UNION_TYPE_P (TREE_TYPE (field
)))
6139 tree fieldtype
= (TYPE_ATOMIC (TREE_TYPE (field
))
6140 ? c_build_qualified_type (TREE_TYPE (field
),
6142 : TYPE_MAIN_VARIANT (TREE_TYPE (field
)));
6143 if (comptypes (lhs_main_type
, fieldtype
))
6145 if (found_field
!= NULL_TREE
)
6147 found_field
= field
;
6149 else if (find_anonymous_field_with_type (TREE_TYPE (field
),
6152 if (found_field
!= NULL_TREE
)
6154 found_field
= field
;
6155 found_sub_field
= true;
6159 if (found_field
== NULL_TREE
)
6162 ret
= fold_build3_loc (location
, COMPONENT_REF
, TREE_TYPE (found_field
),
6163 build_fold_indirect_ref (rhs
), found_field
,
6165 ret
= build_fold_addr_expr_loc (location
, ret
);
6167 if (found_sub_field
)
6169 ret
= convert_to_anonymous_field (location
, type
, ret
);
6170 gcc_assert (ret
!= NULL_TREE
);
6176 /* Issue an error message for a bad initializer component.
6177 GMSGID identifies the message.
6178 The component name is taken from the spelling stack. */
6181 error_init (location_t loc
, const char *gmsgid
)
6185 /* The gmsgid may be a format string with %< and %>. */
6186 error_at (loc
, gmsgid
);
6187 ofwhat
= print_spelling ((char *) alloca (spelling_length () + 1));
6189 inform (loc
, "(near initialization for %qs)", ofwhat
);
6192 /* Issue a pedantic warning for a bad initializer component. OPT is
6193 the option OPT_* (from options.h) controlling this warning or 0 if
6194 it is unconditionally given. GMSGID identifies the message. The
6195 component name is taken from the spelling stack. */
6197 static void ATTRIBUTE_GCC_DIAG (3,0)
6198 pedwarn_init (location_t loc
, int opt
, const char *gmsgid
, ...)
6200 /* Use the location where a macro was expanded rather than where
6201 it was defined to make sure macros defined in system headers
6202 but used incorrectly elsewhere are diagnosed. */
6203 source_location exploc
= expansion_point_location_if_in_system_header (loc
);
6206 va_start (ap
, gmsgid
);
6207 bool warned
= emit_diagnostic_valist (DK_PEDWARN
, exploc
, opt
, gmsgid
, &ap
);
6209 char *ofwhat
= print_spelling ((char *) alloca (spelling_length () + 1));
6210 if (*ofwhat
&& warned
)
6211 inform (exploc
, "(near initialization for %qs)", ofwhat
);
6214 /* Issue a warning for a bad initializer component.
6216 OPT is the OPT_W* value corresponding to the warning option that
6217 controls this warning. GMSGID identifies the message. The
6218 component name is taken from the spelling stack. */
6221 warning_init (location_t loc
, int opt
, const char *gmsgid
)
6226 /* Use the location where a macro was expanded rather than where
6227 it was defined to make sure macros defined in system headers
6228 but used incorrectly elsewhere are diagnosed. */
6229 source_location exploc
= expansion_point_location_if_in_system_header (loc
);
6231 /* The gmsgid may be a format string with %< and %>. */
6232 warned
= warning_at (exploc
, opt
, gmsgid
);
6233 ofwhat
= print_spelling ((char *) alloca (spelling_length () + 1));
6234 if (*ofwhat
&& warned
)
6235 inform (exploc
, "(near initialization for %qs)", ofwhat
);
6238 /* If TYPE is an array type and EXPR is a parenthesized string
6239 constant, warn if pedantic that EXPR is being used to initialize an
6240 object of type TYPE. */
6243 maybe_warn_string_init (location_t loc
, tree type
, struct c_expr expr
)
6246 && TREE_CODE (type
) == ARRAY_TYPE
6247 && TREE_CODE (expr
.value
) == STRING_CST
6248 && expr
.original_code
!= STRING_CST
)
6249 pedwarn_init (loc
, OPT_Wpedantic
,
6250 "array initialized from parenthesized string constant");
6253 /* Attempt to locate the parameter with the given index within FNDECL,
6254 returning DECL_SOURCE_LOCATION (FNDECL) if it can't be found. */
6257 get_fndecl_argument_location (tree fndecl
, int argnum
)
6262 /* Locate param by index within DECL_ARGUMENTS (fndecl). */
6263 for (i
= 0, param
= DECL_ARGUMENTS (fndecl
);
6264 i
< argnum
&& param
;
6265 i
++, param
= TREE_CHAIN (param
))
6268 /* If something went wrong (e.g. if we have a builtin and thus no arguments),
6269 return DECL_SOURCE_LOCATION (FNDECL). */
6271 return DECL_SOURCE_LOCATION (fndecl
);
6273 return DECL_SOURCE_LOCATION (param
);
6276 /* Issue a note about a mismatching argument for parameter PARMNUM
6277 to FUNDECL, for types EXPECTED_TYPE and ACTUAL_TYPE.
6278 Attempt to issue the note at the pertinent parameter of the decl;
6279 failing that issue it at the location of FUNDECL; failing that
6280 issue it at PLOC. */
6283 inform_for_arg (tree fundecl
, location_t ploc
, int parmnum
,
6284 tree expected_type
, tree actual_type
)
6287 if (fundecl
&& !DECL_IS_BUILTIN (fundecl
))
6288 loc
= get_fndecl_argument_location (fundecl
, parmnum
- 1);
6293 "expected %qT but argument is of type %qT",
6294 expected_type
, actual_type
);
6297 /* Convert value RHS to type TYPE as preparation for an assignment to
6298 an lvalue of type TYPE. If ORIGTYPE is not NULL_TREE, it is the
6299 original type of RHS; this differs from TREE_TYPE (RHS) for enum
6300 types. NULL_POINTER_CONSTANT says whether RHS was a null pointer
6301 constant before any folding.
6302 The real work of conversion is done by `convert'.
6303 The purpose of this function is to generate error messages
6304 for assignments that are not allowed in C.
6305 ERRTYPE says whether it is argument passing, assignment,
6306 initialization or return.
6308 In the following example, '~' denotes where EXPR_LOC and '^' where
6311 f (var); [ic_argpass]
6313 x = var; [ic_assign]
6315 int x = var; [ic_init]
6317 return x; [ic_return]
6320 FUNCTION is a tree for the function being called.
6321 PARMNUM is the number of the argument, for printing in error messages. */
6324 convert_for_assignment (location_t location
, location_t expr_loc
, tree type
,
6325 tree rhs
, tree origtype
, enum impl_conv errtype
,
6326 bool null_pointer_constant
, tree fundecl
,
6327 tree function
, int parmnum
)
6329 enum tree_code codel
= TREE_CODE (type
);
6330 tree orig_rhs
= rhs
;
6332 enum tree_code coder
;
6333 tree rname
= NULL_TREE
;
6334 bool objc_ok
= false;
6336 /* Use the expansion point location to handle cases such as user's
6337 function returning a wrong-type macro defined in a system header. */
6338 location
= expansion_point_location_if_in_system_header (location
);
6340 if (errtype
== ic_argpass
)
6343 /* Change pointer to function to the function itself for
6345 if (TREE_CODE (function
) == ADDR_EXPR
6346 && TREE_CODE (TREE_OPERAND (function
, 0)) == FUNCTION_DECL
)
6347 function
= TREE_OPERAND (function
, 0);
6349 /* Handle an ObjC selector specially for diagnostics. */
6350 selector
= objc_message_selector ();
6352 if (selector
&& parmnum
> 2)
6359 /* This macro is used to emit diagnostics to ensure that all format
6360 strings are complete sentences, visible to gettext and checked at
6362 #define PEDWARN_FOR_ASSIGNMENT(LOCATION, PLOC, OPT, AR, AS, IN, RE) \
6367 if (pedwarn (PLOC, OPT, AR, parmnum, rname)) \
6368 inform_for_arg (fundecl, (PLOC), parmnum, type, rhstype); \
6371 pedwarn (LOCATION, OPT, AS); \
6374 pedwarn_init (LOCATION, OPT, IN); \
6377 pedwarn (LOCATION, OPT, RE); \
6380 gcc_unreachable (); \
6384 /* This macro is used to emit diagnostics to ensure that all format
6385 strings are complete sentences, visible to gettext and checked at
6386 compile time. It is the same as PEDWARN_FOR_ASSIGNMENT but with an
6387 extra parameter to enumerate qualifiers. */
6388 #define PEDWARN_FOR_QUALIFIERS(LOCATION, PLOC, OPT, AR, AS, IN, RE, QUALS) \
6393 if (pedwarn (PLOC, OPT, AR, parmnum, rname, QUALS)) \
6394 inform_for_arg (fundecl, (PLOC), parmnum, type, rhstype); \
6397 pedwarn (LOCATION, OPT, AS, QUALS); \
6400 pedwarn (LOCATION, OPT, IN, QUALS); \
6403 pedwarn (LOCATION, OPT, RE, QUALS); \
6406 gcc_unreachable (); \
6410 /* This macro is used to emit diagnostics to ensure that all format
6411 strings are complete sentences, visible to gettext and checked at
6412 compile time. It is the same as PEDWARN_FOR_QUALIFIERS but uses
6413 warning_at instead of pedwarn. */
6414 #define WARNING_FOR_QUALIFIERS(LOCATION, PLOC, OPT, AR, AS, IN, RE, QUALS) \
6419 if (warning_at (PLOC, OPT, AR, parmnum, rname, QUALS)) \
6420 inform_for_arg (fundecl, (PLOC), parmnum, type, rhstype); \
6423 warning_at (LOCATION, OPT, AS, QUALS); \
6426 warning_at (LOCATION, OPT, IN, QUALS); \
6429 warning_at (LOCATION, OPT, RE, QUALS); \
6432 gcc_unreachable (); \
6436 if (TREE_CODE (rhs
) == EXCESS_PRECISION_EXPR
)
6437 rhs
= TREE_OPERAND (rhs
, 0);
6439 rhstype
= TREE_TYPE (rhs
);
6440 coder
= TREE_CODE (rhstype
);
6442 if (coder
== ERROR_MARK
)
6443 return error_mark_node
;
6445 if (c_dialect_objc ())
6468 objc_ok
= objc_compare_types (type
, rhstype
, parmno
, rname
);
6471 if (warn_cxx_compat
)
6473 tree checktype
= origtype
!= NULL_TREE
? origtype
: rhstype
;
6474 if (checktype
!= error_mark_node
6475 && TREE_CODE (type
) == ENUMERAL_TYPE
6476 && TYPE_MAIN_VARIANT (checktype
) != TYPE_MAIN_VARIANT (type
))
6480 if (pedwarn (expr_loc
, OPT_Wc___compat
, "enum conversion when "
6481 "passing argument %d of %qE is invalid in C++",
6483 inform ((fundecl
&& !DECL_IS_BUILTIN (fundecl
))
6484 ? DECL_SOURCE_LOCATION (fundecl
) : expr_loc
,
6485 "expected %qT but argument is of type %qT",
6489 pedwarn (location
, OPT_Wc___compat
, "enum conversion from %qT to "
6490 "%qT in assignment is invalid in C++", rhstype
, type
);
6493 pedwarn_init (location
, OPT_Wc___compat
, "enum conversion from "
6494 "%qT to %qT in initialization is invalid in C++",
6498 pedwarn (location
, OPT_Wc___compat
, "enum conversion from %qT to "
6499 "%qT in return is invalid in C++", rhstype
, type
);
6506 if (TYPE_MAIN_VARIANT (type
) == TYPE_MAIN_VARIANT (rhstype
))
6509 if (coder
== VOID_TYPE
)
6511 /* Except for passing an argument to an unprototyped function,
6512 this is a constraint violation. When passing an argument to
6513 an unprototyped function, it is compile-time undefined;
6514 making it a constraint in that case was rejected in
6516 error_at (location
, "void value not ignored as it ought to be");
6517 return error_mark_node
;
6519 rhs
= require_complete_type (location
, rhs
);
6520 if (rhs
== error_mark_node
)
6521 return error_mark_node
;
6523 if (coder
== POINTER_TYPE
&& reject_gcc_builtin (rhs
))
6524 return error_mark_node
;
6526 /* A non-reference type can convert to a reference. This handles
6527 va_start, va_copy and possibly port built-ins. */
6528 if (codel
== REFERENCE_TYPE
&& coder
!= REFERENCE_TYPE
)
6530 if (!lvalue_p (rhs
))
6532 error_at (location
, "cannot pass rvalue to reference parameter");
6533 return error_mark_node
;
6535 if (!c_mark_addressable (rhs
))
6536 return error_mark_node
;
6537 rhs
= build1 (ADDR_EXPR
, build_pointer_type (TREE_TYPE (rhs
)), rhs
);
6538 SET_EXPR_LOCATION (rhs
, location
);
6540 rhs
= convert_for_assignment (location
, expr_loc
,
6541 build_pointer_type (TREE_TYPE (type
)),
6542 rhs
, origtype
, errtype
,
6543 null_pointer_constant
, fundecl
, function
,
6545 if (rhs
== error_mark_node
)
6546 return error_mark_node
;
6548 rhs
= build1 (NOP_EXPR
, type
, rhs
);
6549 SET_EXPR_LOCATION (rhs
, location
);
6552 /* Some types can interconvert without explicit casts. */
6553 else if (codel
== VECTOR_TYPE
&& coder
== VECTOR_TYPE
6554 && vector_types_convertible_p (type
, TREE_TYPE (rhs
), true))
6555 return convert (type
, rhs
);
6556 /* Arithmetic types all interconvert, and enum is treated like int. */
6557 else if ((codel
== INTEGER_TYPE
|| codel
== REAL_TYPE
6558 || codel
== FIXED_POINT_TYPE
6559 || codel
== ENUMERAL_TYPE
|| codel
== COMPLEX_TYPE
6560 || codel
== BOOLEAN_TYPE
)
6561 && (coder
== INTEGER_TYPE
|| coder
== REAL_TYPE
6562 || coder
== FIXED_POINT_TYPE
6563 || coder
== ENUMERAL_TYPE
|| coder
== COMPLEX_TYPE
6564 || coder
== BOOLEAN_TYPE
))
6567 bool save
= in_late_binary_op
;
6568 if (codel
== BOOLEAN_TYPE
|| codel
== COMPLEX_TYPE
6569 || (coder
== REAL_TYPE
6570 && (codel
== INTEGER_TYPE
|| codel
== ENUMERAL_TYPE
)
6571 && sanitize_flags_p (SANITIZE_FLOAT_CAST
)))
6572 in_late_binary_op
= true;
6573 ret
= convert_and_check (expr_loc
!= UNKNOWN_LOCATION
6574 ? expr_loc
: location
, type
, orig_rhs
);
6575 in_late_binary_op
= save
;
6579 /* Aggregates in different TUs might need conversion. */
6580 if ((codel
== RECORD_TYPE
|| codel
== UNION_TYPE
)
6582 && comptypes (type
, rhstype
))
6583 return convert_and_check (expr_loc
!= UNKNOWN_LOCATION
6584 ? expr_loc
: location
, type
, rhs
);
6586 /* Conversion to a transparent union or record from its member types.
6587 This applies only to function arguments. */
6588 if (((codel
== UNION_TYPE
|| codel
== RECORD_TYPE
)
6589 && TYPE_TRANSPARENT_AGGR (type
))
6590 && errtype
== ic_argpass
)
6592 tree memb
, marginal_memb
= NULL_TREE
;
6594 for (memb
= TYPE_FIELDS (type
); memb
; memb
= DECL_CHAIN (memb
))
6596 tree memb_type
= TREE_TYPE (memb
);
6598 if (comptypes (TYPE_MAIN_VARIANT (memb_type
),
6599 TYPE_MAIN_VARIANT (rhstype
)))
6602 if (TREE_CODE (memb_type
) != POINTER_TYPE
)
6605 if (coder
== POINTER_TYPE
)
6607 tree ttl
= TREE_TYPE (memb_type
);
6608 tree ttr
= TREE_TYPE (rhstype
);
6610 /* Any non-function converts to a [const][volatile] void *
6611 and vice versa; otherwise, targets must be the same.
6612 Meanwhile, the lhs target must have all the qualifiers of
6614 if ((VOID_TYPE_P (ttl
) && !TYPE_ATOMIC (ttl
))
6615 || (VOID_TYPE_P (ttr
) && !TYPE_ATOMIC (ttr
))
6616 || comp_target_types (location
, memb_type
, rhstype
))
6618 int lquals
= TYPE_QUALS (ttl
) & ~TYPE_QUAL_ATOMIC
;
6619 int rquals
= TYPE_QUALS (ttr
) & ~TYPE_QUAL_ATOMIC
;
6620 /* If this type won't generate any warnings, use it. */
6621 if (lquals
== rquals
6622 || ((TREE_CODE (ttr
) == FUNCTION_TYPE
6623 && TREE_CODE (ttl
) == FUNCTION_TYPE
)
6624 ? ((lquals
| rquals
) == rquals
)
6625 : ((lquals
| rquals
) == lquals
)))
6628 /* Keep looking for a better type, but remember this one. */
6630 marginal_memb
= memb
;
6634 /* Can convert integer zero to any pointer type. */
6635 if (null_pointer_constant
)
6637 rhs
= null_pointer_node
;
6642 if (memb
|| marginal_memb
)
6646 /* We have only a marginally acceptable member type;
6647 it needs a warning. */
6648 tree ttl
= TREE_TYPE (TREE_TYPE (marginal_memb
));
6649 tree ttr
= TREE_TYPE (rhstype
);
6651 /* Const and volatile mean something different for function
6652 types, so the usual warnings are not appropriate. */
6653 if (TREE_CODE (ttr
) == FUNCTION_TYPE
6654 && TREE_CODE (ttl
) == FUNCTION_TYPE
)
6656 /* Because const and volatile on functions are
6657 restrictions that say the function will not do
6658 certain things, it is okay to use a const or volatile
6659 function where an ordinary one is wanted, but not
6661 if (TYPE_QUALS_NO_ADDR_SPACE (ttl
)
6662 & ~TYPE_QUALS_NO_ADDR_SPACE (ttr
))
6663 PEDWARN_FOR_QUALIFIERS (location
, expr_loc
,
6664 OPT_Wdiscarded_qualifiers
,
6665 G_("passing argument %d of %qE "
6666 "makes %q#v qualified function "
6667 "pointer from unqualified"),
6668 G_("assignment makes %q#v qualified "
6669 "function pointer from "
6671 G_("initialization makes %q#v qualified "
6672 "function pointer from "
6674 G_("return makes %q#v qualified function "
6675 "pointer from unqualified"),
6676 TYPE_QUALS (ttl
) & ~TYPE_QUALS (ttr
));
6678 else if (TYPE_QUALS_NO_ADDR_SPACE (ttr
)
6679 & ~TYPE_QUALS_NO_ADDR_SPACE (ttl
))
6680 PEDWARN_FOR_QUALIFIERS (location
, expr_loc
,
6681 OPT_Wdiscarded_qualifiers
,
6682 G_("passing argument %d of %qE discards "
6683 "%qv qualifier from pointer target type"),
6684 G_("assignment discards %qv qualifier "
6685 "from pointer target type"),
6686 G_("initialization discards %qv qualifier "
6687 "from pointer target type"),
6688 G_("return discards %qv qualifier from "
6689 "pointer target type"),
6690 TYPE_QUALS (ttr
) & ~TYPE_QUALS (ttl
));
6692 memb
= marginal_memb
;
6695 if (!fundecl
|| !DECL_IN_SYSTEM_HEADER (fundecl
))
6696 pedwarn (location
, OPT_Wpedantic
,
6697 "ISO C prohibits argument conversion to union type");
6699 rhs
= fold_convert_loc (location
, TREE_TYPE (memb
), rhs
);
6700 return build_constructor_single (type
, memb
, rhs
);
6704 /* Conversions among pointers */
6705 else if ((codel
== POINTER_TYPE
|| codel
== REFERENCE_TYPE
)
6706 && (coder
== codel
))
6708 tree ttl
= TREE_TYPE (type
);
6709 tree ttr
= TREE_TYPE (rhstype
);
6712 bool is_opaque_pointer
;
6713 int target_cmp
= 0; /* Cache comp_target_types () result. */
6717 if (TREE_CODE (mvl
) != ARRAY_TYPE
)
6718 mvl
= (TYPE_ATOMIC (mvl
)
6719 ? c_build_qualified_type (TYPE_MAIN_VARIANT (mvl
),
6721 : TYPE_MAIN_VARIANT (mvl
));
6722 if (TREE_CODE (mvr
) != ARRAY_TYPE
)
6723 mvr
= (TYPE_ATOMIC (mvr
)
6724 ? c_build_qualified_type (TYPE_MAIN_VARIANT (mvr
),
6726 : TYPE_MAIN_VARIANT (mvr
));
6727 /* Opaque pointers are treated like void pointers. */
6728 is_opaque_pointer
= vector_targets_convertible_p (ttl
, ttr
);
6730 /* The Plan 9 compiler permits a pointer to a struct to be
6731 automatically converted into a pointer to an anonymous field
6732 within the struct. */
6733 if (flag_plan9_extensions
6734 && RECORD_OR_UNION_TYPE_P (mvl
)
6735 && RECORD_OR_UNION_TYPE_P (mvr
)
6738 tree new_rhs
= convert_to_anonymous_field (location
, type
, rhs
);
6739 if (new_rhs
!= NULL_TREE
)
6742 rhstype
= TREE_TYPE (rhs
);
6743 coder
= TREE_CODE (rhstype
);
6744 ttr
= TREE_TYPE (rhstype
);
6745 mvr
= TYPE_MAIN_VARIANT (ttr
);
6749 /* C++ does not allow the implicit conversion void* -> T*. However,
6750 for the purpose of reducing the number of false positives, we
6751 tolerate the special case of
6755 where NULL is typically defined in C to be '(void *) 0'. */
6756 if (VOID_TYPE_P (ttr
) && rhs
!= null_pointer_node
&& !VOID_TYPE_P (ttl
))
6757 warning_at (errtype
== ic_argpass
? expr_loc
: location
,
6759 "request for implicit conversion "
6760 "from %qT to %qT not permitted in C++", rhstype
, type
);
6762 /* See if the pointers point to incompatible address spaces. */
6763 asl
= TYPE_ADDR_SPACE (ttl
);
6764 asr
= TYPE_ADDR_SPACE (ttr
);
6765 if (!null_pointer_constant_p (rhs
)
6766 && asr
!= asl
&& !targetm
.addr_space
.subset_p (asr
, asl
))
6771 error_at (expr_loc
, "passing argument %d of %qE from pointer to "
6772 "non-enclosed address space", parmnum
, rname
);
6775 error_at (location
, "assignment from pointer to "
6776 "non-enclosed address space");
6779 error_at (location
, "initialization from pointer to "
6780 "non-enclosed address space");
6783 error_at (location
, "return from pointer to "
6784 "non-enclosed address space");
6789 return error_mark_node
;
6792 /* Check if the right-hand side has a format attribute but the
6793 left-hand side doesn't. */
6794 if (warn_suggest_attribute_format
6795 && check_missing_format_attribute (type
, rhstype
))
6800 warning_at (expr_loc
, OPT_Wsuggest_attribute_format
,
6801 "argument %d of %qE might be "
6802 "a candidate for a format attribute",
6806 warning_at (location
, OPT_Wsuggest_attribute_format
,
6807 "assignment left-hand side might be "
6808 "a candidate for a format attribute");
6811 warning_at (location
, OPT_Wsuggest_attribute_format
,
6812 "initialization left-hand side might be "
6813 "a candidate for a format attribute");
6816 warning_at (location
, OPT_Wsuggest_attribute_format
,
6817 "return type might be "
6818 "a candidate for a format attribute");
6825 /* Any non-function converts to a [const][volatile] void *
6826 and vice versa; otherwise, targets must be the same.
6827 Meanwhile, the lhs target must have all the qualifiers of the rhs. */
6828 if ((VOID_TYPE_P (ttl
) && !TYPE_ATOMIC (ttl
))
6829 || (VOID_TYPE_P (ttr
) && !TYPE_ATOMIC (ttr
))
6830 || (target_cmp
= comp_target_types (location
, type
, rhstype
))
6831 || is_opaque_pointer
6832 || ((c_common_unsigned_type (mvl
)
6833 == c_common_unsigned_type (mvr
))
6834 && (c_common_signed_type (mvl
)
6835 == c_common_signed_type (mvr
))
6836 && TYPE_ATOMIC (mvl
) == TYPE_ATOMIC (mvr
)))
6838 /* Warn about loss of qualifers from pointers to arrays with
6839 qualifiers on the element type. */
6840 if (TREE_CODE (ttr
) == ARRAY_TYPE
)
6842 ttr
= strip_array_types (ttr
);
6843 ttl
= strip_array_types (ttl
);
6845 if (TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttr
)
6846 & ~TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttl
))
6847 WARNING_FOR_QUALIFIERS (location
, expr_loc
,
6848 OPT_Wdiscarded_array_qualifiers
,
6849 G_("passing argument %d of %qE discards "
6850 "%qv qualifier from pointer target type"),
6851 G_("assignment discards %qv qualifier "
6852 "from pointer target type"),
6853 G_("initialization discards %qv qualifier "
6854 "from pointer target type"),
6855 G_("return discards %qv qualifier from "
6856 "pointer target type"),
6857 TYPE_QUALS (ttr
) & ~TYPE_QUALS (ttl
));
6860 && ((VOID_TYPE_P (ttl
) && TREE_CODE (ttr
) == FUNCTION_TYPE
)
6863 && !null_pointer_constant
6864 && TREE_CODE (ttl
) == FUNCTION_TYPE
)))
6865 PEDWARN_FOR_ASSIGNMENT (location
, expr_loc
, OPT_Wpedantic
,
6866 G_("ISO C forbids passing argument %d of "
6867 "%qE between function pointer "
6869 G_("ISO C forbids assignment between "
6870 "function pointer and %<void *%>"),
6871 G_("ISO C forbids initialization between "
6872 "function pointer and %<void *%>"),
6873 G_("ISO C forbids return between function "
6874 "pointer and %<void *%>"));
6875 /* Const and volatile mean something different for function types,
6876 so the usual warnings are not appropriate. */
6877 else if (TREE_CODE (ttr
) != FUNCTION_TYPE
6878 && TREE_CODE (ttl
) != FUNCTION_TYPE
)
6880 /* Don't warn about loss of qualifier for conversions from
6881 qualified void* to pointers to arrays with corresponding
6882 qualifier on the element type. */
6884 ttl
= strip_array_types (ttl
);
6886 /* Assignments between atomic and non-atomic objects are OK. */
6887 if (TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttr
)
6888 & ~TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttl
))
6890 PEDWARN_FOR_QUALIFIERS (location
, expr_loc
,
6891 OPT_Wdiscarded_qualifiers
,
6892 G_("passing argument %d of %qE discards "
6893 "%qv qualifier from pointer target type"),
6894 G_("assignment discards %qv qualifier "
6895 "from pointer target type"),
6896 G_("initialization discards %qv qualifier "
6897 "from pointer target type"),
6898 G_("return discards %qv qualifier from "
6899 "pointer target type"),
6900 TYPE_QUALS (ttr
) & ~TYPE_QUALS (ttl
));
6902 /* If this is not a case of ignoring a mismatch in signedness,
6904 else if (VOID_TYPE_P (ttl
) || VOID_TYPE_P (ttr
)
6907 /* If there is a mismatch, do warn. */
6908 else if (warn_pointer_sign
)
6912 if (pedwarn (expr_loc
, OPT_Wpointer_sign
,
6913 "pointer targets in passing argument %d of "
6914 "%qE differ in signedness", parmnum
, rname
))
6915 inform ((fundecl
&& !DECL_IS_BUILTIN (fundecl
))
6916 ? DECL_SOURCE_LOCATION (fundecl
) : expr_loc
,
6917 "expected %qT but argument is of type %qT",
6921 pedwarn (location
, OPT_Wpointer_sign
,
6922 "pointer targets in assignment from %qT to %qT "
6923 "differ in signedness", rhstype
, type
);
6926 pedwarn_init (location
, OPT_Wpointer_sign
,
6927 "pointer targets in initialization of %qT "
6928 "from %qT differ in signedness", type
,
6932 pedwarn (location
, OPT_Wpointer_sign
, "pointer targets in "
6933 "returning %qT from a function with return type "
6934 "%qT differ in signedness", rhstype
, type
);
6940 else if (TREE_CODE (ttl
) == FUNCTION_TYPE
6941 && TREE_CODE (ttr
) == FUNCTION_TYPE
)
6943 /* Because const and volatile on functions are restrictions
6944 that say the function will not do certain things,
6945 it is okay to use a const or volatile function
6946 where an ordinary one is wanted, but not vice-versa. */
6947 if (TYPE_QUALS_NO_ADDR_SPACE (ttl
)
6948 & ~TYPE_QUALS_NO_ADDR_SPACE (ttr
))
6949 PEDWARN_FOR_QUALIFIERS (location
, expr_loc
,
6950 OPT_Wdiscarded_qualifiers
,
6951 G_("passing argument %d of %qE makes "
6952 "%q#v qualified function pointer "
6953 "from unqualified"),
6954 G_("assignment makes %q#v qualified function "
6955 "pointer from unqualified"),
6956 G_("initialization makes %q#v qualified "
6957 "function pointer from unqualified"),
6958 G_("return makes %q#v qualified function "
6959 "pointer from unqualified"),
6960 TYPE_QUALS (ttl
) & ~TYPE_QUALS (ttr
));
6963 /* Avoid warning about the volatile ObjC EH puts on decls. */
6969 if (pedwarn (expr_loc
, OPT_Wincompatible_pointer_types
,
6970 "passing argument %d of %qE from incompatible "
6971 "pointer type", parmnum
, rname
))
6972 inform_for_arg (fundecl
, expr_loc
, parmnum
, type
, rhstype
);
6975 pedwarn (location
, OPT_Wincompatible_pointer_types
,
6976 "assignment to %qT from incompatible pointer type %qT",
6980 pedwarn_init (location
, OPT_Wincompatible_pointer_types
,
6981 "initialization of %qT from incompatible pointer "
6982 "type %qT", type
, rhstype
);
6985 pedwarn (location
, OPT_Wincompatible_pointer_types
,
6986 "returning %qT from a function with incompatible "
6987 "return type %qT", rhstype
, type
);
6994 return convert (type
, rhs
);
6996 else if (codel
== POINTER_TYPE
&& coder
== ARRAY_TYPE
)
6998 /* ??? This should not be an error when inlining calls to
6999 unprototyped functions. */
7000 error_at (location
, "invalid use of non-lvalue array");
7001 return error_mark_node
;
7003 else if (codel
== POINTER_TYPE
&& coder
== INTEGER_TYPE
)
7005 /* An explicit constant 0 can convert to a pointer,
7006 or one that results from arithmetic, even including
7007 a cast to integer type. */
7008 if (!null_pointer_constant
)
7012 if (pedwarn (expr_loc
, OPT_Wint_conversion
,
7013 "passing argument %d of %qE makes pointer from "
7014 "integer without a cast", parmnum
, rname
))
7015 inform_for_arg (fundecl
, expr_loc
, parmnum
, type
, rhstype
);
7018 pedwarn (location
, OPT_Wint_conversion
,
7019 "assignment to %qT from %qT makes pointer from integer "
7020 "without a cast", type
, rhstype
);
7023 pedwarn_init (location
, OPT_Wint_conversion
,
7024 "initialization of %qT from %qT makes pointer from "
7025 "integer without a cast", type
, rhstype
);
7028 pedwarn (location
, OPT_Wint_conversion
, "returning %qT from a "
7029 "function with return type %qT makes pointer from "
7030 "integer without a cast", rhstype
, type
);
7036 return convert (type
, rhs
);
7038 else if (codel
== INTEGER_TYPE
&& coder
== POINTER_TYPE
)
7043 if (pedwarn (expr_loc
, OPT_Wint_conversion
,
7044 "passing argument %d of %qE makes integer from "
7045 "pointer without a cast", parmnum
, rname
))
7046 inform_for_arg (fundecl
, expr_loc
, parmnum
, type
, rhstype
);
7049 pedwarn (location
, OPT_Wint_conversion
,
7050 "assignment to %qT from %qT makes integer from pointer "
7051 "without a cast", type
, rhstype
);
7054 pedwarn_init (location
, OPT_Wint_conversion
,
7055 "initialization of %qT from %qT makes integer from "
7056 "pointer without a cast", type
, rhstype
);
7059 pedwarn (location
, OPT_Wint_conversion
, "returning %qT from a "
7060 "function with return type %qT makes integer from "
7061 "pointer without a cast", rhstype
, type
);
7067 return convert (type
, rhs
);
7069 else if (codel
== BOOLEAN_TYPE
&& coder
== POINTER_TYPE
)
7072 bool save
= in_late_binary_op
;
7073 in_late_binary_op
= true;
7074 ret
= convert (type
, rhs
);
7075 in_late_binary_op
= save
;
7082 error_at (expr_loc
, "incompatible type for argument %d of %qE", parmnum
,
7084 inform_for_arg (fundecl
, expr_loc
, parmnum
, type
, rhstype
);
7087 error_at (location
, "incompatible types when assigning to type %qT from "
7088 "type %qT", type
, rhstype
);
7092 "incompatible types when initializing type %qT using type %qT",
7097 "incompatible types when returning type %qT but %qT was "
7098 "expected", rhstype
, type
);
7104 return error_mark_node
;
7107 /* If VALUE is a compound expr all of whose expressions are constant, then
7108 return its value. Otherwise, return error_mark_node.
7110 This is for handling COMPOUND_EXPRs as initializer elements
7111 which is allowed with a warning when -pedantic is specified. */
7114 valid_compound_expr_initializer (tree value
, tree endtype
)
7116 if (TREE_CODE (value
) == COMPOUND_EXPR
)
7118 if (valid_compound_expr_initializer (TREE_OPERAND (value
, 0), endtype
)
7120 return error_mark_node
;
7121 return valid_compound_expr_initializer (TREE_OPERAND (value
, 1),
7124 else if (!initializer_constant_valid_p (value
, endtype
))
7125 return error_mark_node
;
7130 /* Perform appropriate conversions on the initial value of a variable,
7131 store it in the declaration DECL,
7132 and print any error messages that are appropriate.
7133 If ORIGTYPE is not NULL_TREE, it is the original type of INIT.
7134 If the init is invalid, store an ERROR_MARK.
7136 INIT_LOC is the location of the initial value. */
7139 store_init_value (location_t init_loc
, tree decl
, tree init
, tree origtype
)
7144 /* If variable's type was invalidly declared, just ignore it. */
7146 type
= TREE_TYPE (decl
);
7147 if (TREE_CODE (type
) == ERROR_MARK
)
7150 /* Digest the specified initializer into an expression. */
7153 npc
= null_pointer_constant_p (init
);
7154 value
= digest_init (init_loc
, type
, init
, origtype
, npc
,
7155 true, TREE_STATIC (decl
));
7157 /* Store the expression if valid; else report error. */
7159 if (!in_system_header_at (input_location
)
7160 && AGGREGATE_TYPE_P (TREE_TYPE (decl
)) && !TREE_STATIC (decl
))
7161 warning (OPT_Wtraditional
, "traditional C rejects automatic "
7162 "aggregate initialization");
7164 if (value
!= error_mark_node
|| TREE_CODE (decl
) != FUNCTION_DECL
)
7165 DECL_INITIAL (decl
) = value
;
7167 /* ANSI wants warnings about out-of-range constant initializers. */
7168 STRIP_TYPE_NOPS (value
);
7169 if (TREE_STATIC (decl
))
7170 constant_expression_warning (value
);
7172 /* Check if we need to set array size from compound literal size. */
7173 if (TREE_CODE (type
) == ARRAY_TYPE
7174 && TYPE_DOMAIN (type
) == NULL_TREE
7175 && value
!= error_mark_node
)
7177 tree inside_init
= init
;
7179 STRIP_TYPE_NOPS (inside_init
);
7180 inside_init
= fold (inside_init
);
7182 if (TREE_CODE (inside_init
) == COMPOUND_LITERAL_EXPR
)
7184 tree cldecl
= COMPOUND_LITERAL_EXPR_DECL (inside_init
);
7186 if (TYPE_DOMAIN (TREE_TYPE (cldecl
)))
7188 /* For int foo[] = (int [3]){1}; we need to set array size
7189 now since later on array initializer will be just the
7190 brace enclosed list of the compound literal. */
7191 tree etype
= strip_array_types (TREE_TYPE (decl
));
7192 type
= build_distinct_type_copy (TYPE_MAIN_VARIANT (type
));
7193 TYPE_DOMAIN (type
) = TYPE_DOMAIN (TREE_TYPE (cldecl
));
7195 layout_decl (cldecl
, 0);
7197 = c_build_qualified_type (type
, TYPE_QUALS (etype
));
7203 /* Methods for storing and printing names for error messages. */
7205 /* Implement a spelling stack that allows components of a name to be pushed
7206 and popped. Each element on the stack is this structure. */
7213 unsigned HOST_WIDE_INT i
;
7218 #define SPELLING_STRING 1
7219 #define SPELLING_MEMBER 2
7220 #define SPELLING_BOUNDS 3
7222 static struct spelling
*spelling
; /* Next stack element (unused). */
7223 static struct spelling
*spelling_base
; /* Spelling stack base. */
7224 static int spelling_size
; /* Size of the spelling stack. */
7226 /* Macros to save and restore the spelling stack around push_... functions.
7227 Alternative to SAVE_SPELLING_STACK. */
7229 #define SPELLING_DEPTH() (spelling - spelling_base)
7230 #define RESTORE_SPELLING_DEPTH(DEPTH) (spelling = spelling_base + (DEPTH))
7232 /* Push an element on the spelling stack with type KIND and assign VALUE
7235 #define PUSH_SPELLING(KIND, VALUE, MEMBER) \
7237 int depth = SPELLING_DEPTH (); \
7239 if (depth >= spelling_size) \
7241 spelling_size += 10; \
7242 spelling_base = XRESIZEVEC (struct spelling, spelling_base, \
7244 RESTORE_SPELLING_DEPTH (depth); \
7247 spelling->kind = (KIND); \
7248 spelling->MEMBER = (VALUE); \
7252 /* Push STRING on the stack. Printed literally. */
7255 push_string (const char *string
)
7257 PUSH_SPELLING (SPELLING_STRING
, string
, u
.s
);
7260 /* Push a member name on the stack. Printed as '.' STRING. */
7263 push_member_name (tree decl
)
7265 const char *const string
7267 ? identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl
)))
7268 : _("<anonymous>"));
7269 PUSH_SPELLING (SPELLING_MEMBER
, string
, u
.s
);
7272 /* Push an array bounds on the stack. Printed as [BOUNDS]. */
7275 push_array_bounds (unsigned HOST_WIDE_INT bounds
)
7277 PUSH_SPELLING (SPELLING_BOUNDS
, bounds
, u
.i
);
7280 /* Compute the maximum size in bytes of the printed spelling. */
7283 spelling_length (void)
7288 for (p
= spelling_base
; p
< spelling
; p
++)
7290 if (p
->kind
== SPELLING_BOUNDS
)
7293 size
+= strlen (p
->u
.s
) + 1;
7299 /* Print the spelling to BUFFER and return it. */
7302 print_spelling (char *buffer
)
7307 for (p
= spelling_base
; p
< spelling
; p
++)
7308 if (p
->kind
== SPELLING_BOUNDS
)
7310 sprintf (d
, "[" HOST_WIDE_INT_PRINT_UNSIGNED
"]", p
->u
.i
);
7316 if (p
->kind
== SPELLING_MEMBER
)
7318 for (s
= p
->u
.s
; (*d
= *s
++); d
++)
7325 /* Digest the parser output INIT as an initializer for type TYPE.
7326 Return a C expression of type TYPE to represent the initial value.
7328 If ORIGTYPE is not NULL_TREE, it is the original type of INIT.
7330 NULL_POINTER_CONSTANT is true if INIT is a null pointer constant.
7332 If INIT is a string constant, STRICT_STRING is true if it is
7333 unparenthesized or we should not warn here for it being parenthesized.
7334 For other types of INIT, STRICT_STRING is not used.
7336 INIT_LOC is the location of the INIT.
7338 REQUIRE_CONSTANT requests an error if non-constant initializers or
7339 elements are seen. */
7342 digest_init (location_t init_loc
, tree type
, tree init
, tree origtype
,
7343 bool null_pointer_constant
, bool strict_string
,
7344 int require_constant
)
7346 enum tree_code code
= TREE_CODE (type
);
7347 tree inside_init
= init
;
7348 tree semantic_type
= NULL_TREE
;
7349 bool maybe_const
= true;
7351 if (type
== error_mark_node
7353 || error_operand_p (init
))
7354 return error_mark_node
;
7356 STRIP_TYPE_NOPS (inside_init
);
7358 if (TREE_CODE (inside_init
) == EXCESS_PRECISION_EXPR
)
7360 semantic_type
= TREE_TYPE (inside_init
);
7361 inside_init
= TREE_OPERAND (inside_init
, 0);
7363 inside_init
= c_fully_fold (inside_init
, require_constant
, &maybe_const
);
7365 /* Initialization of an array of chars from a string constant
7366 optionally enclosed in braces. */
7368 if (code
== ARRAY_TYPE
&& inside_init
7369 && TREE_CODE (inside_init
) == STRING_CST
)
7372 = (TYPE_ATOMIC (TREE_TYPE (type
))
7373 ? c_build_qualified_type (TYPE_MAIN_VARIANT (TREE_TYPE (type
)),
7375 : TYPE_MAIN_VARIANT (TREE_TYPE (type
)));
7376 /* Note that an array could be both an array of character type
7377 and an array of wchar_t if wchar_t is signed char or unsigned
7379 bool char_array
= (typ1
== char_type_node
7380 || typ1
== signed_char_type_node
7381 || typ1
== unsigned_char_type_node
);
7382 bool wchar_array
= !!comptypes (typ1
, wchar_type_node
);
7383 bool char16_array
= !!comptypes (typ1
, char16_type_node
);
7384 bool char32_array
= !!comptypes (typ1
, char32_type_node
);
7386 if (char_array
|| wchar_array
|| char16_array
|| char32_array
)
7389 tree typ2
= TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init
)));
7390 expr
.value
= inside_init
;
7391 expr
.original_code
= (strict_string
? STRING_CST
: ERROR_MARK
);
7392 expr
.original_type
= NULL
;
7393 maybe_warn_string_init (init_loc
, type
, expr
);
7395 if (TYPE_DOMAIN (type
) && !TYPE_MAX_VALUE (TYPE_DOMAIN (type
)))
7396 pedwarn_init (init_loc
, OPT_Wpedantic
,
7397 "initialization of a flexible array member");
7399 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init
)),
7400 TYPE_MAIN_VARIANT (type
)))
7405 if (typ2
!= char_type_node
)
7407 error_init (init_loc
, "char-array initialized from wide "
7409 return error_mark_node
;
7414 if (typ2
== char_type_node
)
7416 error_init (init_loc
, "wide character array initialized "
7417 "from non-wide string");
7418 return error_mark_node
;
7420 else if (!comptypes(typ1
, typ2
))
7422 error_init (init_loc
, "wide character array initialized "
7423 "from incompatible wide string");
7424 return error_mark_node
;
7428 TREE_TYPE (inside_init
) = type
;
7429 if (TYPE_DOMAIN (type
) != NULL_TREE
7430 && TYPE_SIZE (type
) != NULL_TREE
7431 && TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
7433 unsigned HOST_WIDE_INT len
= TREE_STRING_LENGTH (inside_init
);
7435 /* Subtract the size of a single (possibly wide) character
7436 because it's ok to ignore the terminating null char
7437 that is counted in the length of the constant. */
7438 if (compare_tree_int (TYPE_SIZE_UNIT (type
),
7439 (len
- (TYPE_PRECISION (typ1
)
7440 / BITS_PER_UNIT
))) < 0)
7441 pedwarn_init (init_loc
, 0,
7442 ("initializer-string for array of chars "
7444 else if (warn_cxx_compat
7445 && compare_tree_int (TYPE_SIZE_UNIT (type
), len
) < 0)
7446 warning_at (init_loc
, OPT_Wc___compat
,
7447 ("initializer-string for array chars "
7448 "is too long for C++"));
7453 else if (INTEGRAL_TYPE_P (typ1
))
7455 error_init (init_loc
, "array of inappropriate type initialized "
7456 "from string constant");
7457 return error_mark_node
;
7461 /* Build a VECTOR_CST from a *constant* vector constructor. If the
7462 vector constructor is not constant (e.g. {1,2,3,foo()}) then punt
7463 below and handle as a constructor. */
7464 if (code
== VECTOR_TYPE
7465 && VECTOR_TYPE_P (TREE_TYPE (inside_init
))
7466 && vector_types_convertible_p (TREE_TYPE (inside_init
), type
, true)
7467 && TREE_CONSTANT (inside_init
))
7469 if (TREE_CODE (inside_init
) == VECTOR_CST
7470 && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init
)),
7471 TYPE_MAIN_VARIANT (type
)))
7474 if (TREE_CODE (inside_init
) == CONSTRUCTOR
)
7476 unsigned HOST_WIDE_INT ix
;
7478 bool constant_p
= true;
7480 /* Iterate through elements and check if all constructor
7481 elements are *_CSTs. */
7482 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (inside_init
), ix
, value
)
7483 if (!CONSTANT_CLASS_P (value
))
7490 return build_vector_from_ctor (type
,
7491 CONSTRUCTOR_ELTS (inside_init
));
7495 if (warn_sequence_point
)
7496 verify_sequence_points (inside_init
);
7498 /* Any type can be initialized
7499 from an expression of the same type, optionally with braces. */
7501 if (inside_init
&& TREE_TYPE (inside_init
) != NULL_TREE
7502 && (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init
)),
7503 TYPE_MAIN_VARIANT (type
))
7504 || (code
== ARRAY_TYPE
7505 && comptypes (TREE_TYPE (inside_init
), type
))
7506 || (code
== VECTOR_TYPE
7507 && comptypes (TREE_TYPE (inside_init
), type
))
7508 || (code
== POINTER_TYPE
7509 && TREE_CODE (TREE_TYPE (inside_init
)) == ARRAY_TYPE
7510 && comptypes (TREE_TYPE (TREE_TYPE (inside_init
)),
7511 TREE_TYPE (type
)))))
7513 if (code
== POINTER_TYPE
)
7515 if (TREE_CODE (TREE_TYPE (inside_init
)) == ARRAY_TYPE
)
7517 if (TREE_CODE (inside_init
) == STRING_CST
7518 || TREE_CODE (inside_init
) == COMPOUND_LITERAL_EXPR
)
7519 inside_init
= array_to_pointer_conversion
7520 (init_loc
, inside_init
);
7523 error_init (init_loc
, "invalid use of non-lvalue array");
7524 return error_mark_node
;
7529 if (code
== VECTOR_TYPE
)
7530 /* Although the types are compatible, we may require a
7532 inside_init
= convert (type
, inside_init
);
7534 if (require_constant
7535 && TREE_CODE (inside_init
) == COMPOUND_LITERAL_EXPR
)
7537 /* As an extension, allow initializing objects with static storage
7538 duration with compound literals (which are then treated just as
7539 the brace enclosed list they contain). Also allow this for
7540 vectors, as we can only assign them with compound literals. */
7541 if (flag_isoc99
&& code
!= VECTOR_TYPE
)
7542 pedwarn_init (init_loc
, OPT_Wpedantic
, "initializer element "
7544 tree decl
= COMPOUND_LITERAL_EXPR_DECL (inside_init
);
7545 inside_init
= DECL_INITIAL (decl
);
7548 if (code
== ARRAY_TYPE
&& TREE_CODE (inside_init
) != STRING_CST
7549 && TREE_CODE (inside_init
) != CONSTRUCTOR
)
7551 error_init (init_loc
, "array initialized from non-constant array "
7553 return error_mark_node
;
7556 /* Compound expressions can only occur here if -Wpedantic or
7557 -pedantic-errors is specified. In the later case, we always want
7558 an error. In the former case, we simply want a warning. */
7559 if (require_constant
&& pedantic
7560 && TREE_CODE (inside_init
) == COMPOUND_EXPR
)
7563 = valid_compound_expr_initializer (inside_init
,
7564 TREE_TYPE (inside_init
));
7565 if (inside_init
== error_mark_node
)
7566 error_init (init_loc
, "initializer element is not constant");
7568 pedwarn_init (init_loc
, OPT_Wpedantic
,
7569 "initializer element is not constant");
7570 if (flag_pedantic_errors
)
7571 inside_init
= error_mark_node
;
7573 else if (require_constant
7574 && !initializer_constant_valid_p (inside_init
,
7575 TREE_TYPE (inside_init
)))
7577 error_init (init_loc
, "initializer element is not constant");
7578 inside_init
= error_mark_node
;
7580 else if (require_constant
&& !maybe_const
)
7581 pedwarn_init (init_loc
, OPT_Wpedantic
,
7582 "initializer element is not a constant expression");
7584 /* Added to enable additional -Wsuggest-attribute=format warnings. */
7585 if (TREE_CODE (TREE_TYPE (inside_init
)) == POINTER_TYPE
)
7586 inside_init
= convert_for_assignment (init_loc
, UNKNOWN_LOCATION
,
7587 type
, inside_init
, origtype
,
7588 ic_init
, null_pointer_constant
,
7589 NULL_TREE
, NULL_TREE
, 0);
7593 /* Handle scalar types, including conversions. */
7595 if (code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
7596 || code
== POINTER_TYPE
|| code
== ENUMERAL_TYPE
|| code
== BOOLEAN_TYPE
7597 || code
== COMPLEX_TYPE
|| code
== VECTOR_TYPE
)
7599 if (TREE_CODE (TREE_TYPE (init
)) == ARRAY_TYPE
7600 && (TREE_CODE (init
) == STRING_CST
7601 || TREE_CODE (init
) == COMPOUND_LITERAL_EXPR
))
7602 inside_init
= init
= array_to_pointer_conversion (init_loc
, init
);
7604 inside_init
= build1 (EXCESS_PRECISION_EXPR
, semantic_type
,
7607 = convert_for_assignment (init_loc
, UNKNOWN_LOCATION
, type
,
7608 inside_init
, origtype
, ic_init
,
7609 null_pointer_constant
, NULL_TREE
, NULL_TREE
,
7612 /* Check to see if we have already given an error message. */
7613 if (inside_init
== error_mark_node
)
7615 else if (require_constant
&& !TREE_CONSTANT (inside_init
))
7617 error_init (init_loc
, "initializer element is not constant");
7618 inside_init
= error_mark_node
;
7620 else if (require_constant
7621 && !initializer_constant_valid_p (inside_init
,
7622 TREE_TYPE (inside_init
)))
7624 error_init (init_loc
, "initializer element is not computable at "
7626 inside_init
= error_mark_node
;
7628 else if (require_constant
&& !maybe_const
)
7629 pedwarn_init (init_loc
, OPT_Wpedantic
,
7630 "initializer element is not a constant expression");
7635 /* Come here only for records and arrays. */
7637 if (COMPLETE_TYPE_P (type
) && TREE_CODE (TYPE_SIZE (type
)) != INTEGER_CST
)
7639 error_init (init_loc
, "variable-sized object may not be initialized");
7640 return error_mark_node
;
7643 error_init (init_loc
, "invalid initializer");
7644 return error_mark_node
;
7647 /* Handle initializers that use braces. */
7649 /* Type of object we are accumulating a constructor for.
7650 This type is always a RECORD_TYPE, UNION_TYPE or ARRAY_TYPE. */
7651 static tree constructor_type
;
7653 /* For a RECORD_TYPE or UNION_TYPE, this is the chain of fields
7655 static tree constructor_fields
;
7657 /* For an ARRAY_TYPE, this is the specified index
7658 at which to store the next element we get. */
7659 static tree constructor_index
;
7661 /* For an ARRAY_TYPE, this is the maximum index. */
7662 static tree constructor_max_index
;
7664 /* For a RECORD_TYPE, this is the first field not yet written out. */
7665 static tree constructor_unfilled_fields
;
7667 /* For an ARRAY_TYPE, this is the index of the first element
7668 not yet written out. */
7669 static tree constructor_unfilled_index
;
7671 /* In a RECORD_TYPE, the byte index of the next consecutive field.
7672 This is so we can generate gaps between fields, when appropriate. */
7673 static tree constructor_bit_index
;
7675 /* If we are saving up the elements rather than allocating them,
7676 this is the list of elements so far (in reverse order,
7677 most recent first). */
7678 static vec
<constructor_elt
, va_gc
> *constructor_elements
;
7680 /* 1 if constructor should be incrementally stored into a constructor chain,
7681 0 if all the elements should be kept in AVL tree. */
7682 static int constructor_incremental
;
7684 /* 1 if so far this constructor's elements are all compile-time constants. */
7685 static int constructor_constant
;
7687 /* 1 if so far this constructor's elements are all valid address constants. */
7688 static int constructor_simple
;
7690 /* 1 if this constructor has an element that cannot be part of a
7691 constant expression. */
7692 static int constructor_nonconst
;
7694 /* 1 if this constructor is erroneous so far. */
7695 static int constructor_erroneous
;
7697 /* 1 if this constructor is the universal zero initializer { 0 }. */
7698 static int constructor_zeroinit
;
7700 /* Structure for managing pending initializer elements, organized as an
7705 struct init_node
*left
, *right
;
7706 struct init_node
*parent
;
7713 /* Tree of pending elements at this constructor level.
7714 These are elements encountered out of order
7715 which belong at places we haven't reached yet in actually
7717 Will never hold tree nodes across GC runs. */
7718 static struct init_node
*constructor_pending_elts
;
7720 /* The SPELLING_DEPTH of this constructor. */
7721 static int constructor_depth
;
7723 /* DECL node for which an initializer is being read.
7724 0 means we are reading a constructor expression
7725 such as (struct foo) {...}. */
7726 static tree constructor_decl
;
7728 /* Nonzero if this is an initializer for a top-level decl. */
7729 static int constructor_top_level
;
7731 /* Nonzero if there were any member designators in this initializer. */
7732 static int constructor_designated
;
7734 /* Nesting depth of designator list. */
7735 static int designator_depth
;
7737 /* Nonzero if there were diagnosed errors in this designator list. */
7738 static int designator_erroneous
;
7741 /* This stack has a level for each implicit or explicit level of
7742 structuring in the initializer, including the outermost one. It
7743 saves the values of most of the variables above. */
7745 struct constructor_range_stack
;
7747 struct constructor_stack
7749 struct constructor_stack
*next
;
7754 tree unfilled_index
;
7755 tree unfilled_fields
;
7757 vec
<constructor_elt
, va_gc
> *elements
;
7758 struct init_node
*pending_elts
;
7761 /* If value nonzero, this value should replace the entire
7762 constructor at this level. */
7763 struct c_expr replacement_value
;
7764 struct constructor_range_stack
*range_stack
;
7773 int designator_depth
;
7776 static struct constructor_stack
*constructor_stack
;
7778 /* This stack represents designators from some range designator up to
7779 the last designator in the list. */
7781 struct constructor_range_stack
7783 struct constructor_range_stack
*next
, *prev
;
7784 struct constructor_stack
*stack
;
7791 static struct constructor_range_stack
*constructor_range_stack
;
7793 /* This stack records separate initializers that are nested.
7794 Nested initializers can't happen in ANSI C, but GNU C allows them
7795 in cases like { ... (struct foo) { ... } ... }. */
7797 struct initializer_stack
7799 struct initializer_stack
*next
;
7801 struct constructor_stack
*constructor_stack
;
7802 struct constructor_range_stack
*constructor_range_stack
;
7803 vec
<constructor_elt
, va_gc
> *elements
;
7804 struct spelling
*spelling
;
7805 struct spelling
*spelling_base
;
7808 char require_constant_value
;
7809 char require_constant_elements
;
7810 rich_location
*missing_brace_richloc
;
7813 static struct initializer_stack
*initializer_stack
;
7815 /* Prepare to parse and output the initializer for variable DECL. */
7818 start_init (tree decl
, tree asmspec_tree ATTRIBUTE_UNUSED
, int top_level
,
7819 rich_location
*richloc
)
7822 struct initializer_stack
*p
= XNEW (struct initializer_stack
);
7824 p
->decl
= constructor_decl
;
7825 p
->require_constant_value
= require_constant_value
;
7826 p
->require_constant_elements
= require_constant_elements
;
7827 p
->constructor_stack
= constructor_stack
;
7828 p
->constructor_range_stack
= constructor_range_stack
;
7829 p
->elements
= constructor_elements
;
7830 p
->spelling
= spelling
;
7831 p
->spelling_base
= spelling_base
;
7832 p
->spelling_size
= spelling_size
;
7833 p
->top_level
= constructor_top_level
;
7834 p
->next
= initializer_stack
;
7835 p
->missing_brace_richloc
= richloc
;
7836 initializer_stack
= p
;
7838 constructor_decl
= decl
;
7839 constructor_designated
= 0;
7840 constructor_top_level
= top_level
;
7842 if (decl
!= NULL_TREE
&& decl
!= error_mark_node
)
7844 require_constant_value
= TREE_STATIC (decl
);
7845 require_constant_elements
7846 = ((TREE_STATIC (decl
) || (pedantic
&& !flag_isoc99
))
7847 /* For a scalar, you can always use any value to initialize,
7848 even within braces. */
7849 && AGGREGATE_TYPE_P (TREE_TYPE (decl
)));
7850 locus
= identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl
)));
7854 require_constant_value
= 0;
7855 require_constant_elements
= 0;
7856 locus
= _("(anonymous)");
7859 constructor_stack
= 0;
7860 constructor_range_stack
= 0;
7862 found_missing_braces
= 0;
7866 RESTORE_SPELLING_DEPTH (0);
7869 push_string (locus
);
7875 struct initializer_stack
*p
= initializer_stack
;
7877 /* Free the whole constructor stack of this initializer. */
7878 while (constructor_stack
)
7880 struct constructor_stack
*q
= constructor_stack
;
7881 constructor_stack
= q
->next
;
7885 gcc_assert (!constructor_range_stack
);
7887 /* Pop back to the data of the outer initializer (if any). */
7888 free (spelling_base
);
7890 constructor_decl
= p
->decl
;
7891 require_constant_value
= p
->require_constant_value
;
7892 require_constant_elements
= p
->require_constant_elements
;
7893 constructor_stack
= p
->constructor_stack
;
7894 constructor_range_stack
= p
->constructor_range_stack
;
7895 constructor_elements
= p
->elements
;
7896 spelling
= p
->spelling
;
7897 spelling_base
= p
->spelling_base
;
7898 spelling_size
= p
->spelling_size
;
7899 constructor_top_level
= p
->top_level
;
7900 initializer_stack
= p
->next
;
7904 /* Call here when we see the initializer is surrounded by braces.
7905 This is instead of a call to push_init_level;
7906 it is matched by a call to pop_init_level.
7908 TYPE is the type to initialize, for a constructor expression.
7909 For an initializer for a decl, TYPE is zero. */
7912 really_start_incremental_init (tree type
)
7914 struct constructor_stack
*p
= XNEW (struct constructor_stack
);
7916 if (type
== NULL_TREE
)
7917 type
= TREE_TYPE (constructor_decl
);
7919 if (VECTOR_TYPE_P (type
)
7920 && TYPE_VECTOR_OPAQUE (type
))
7921 error ("opaque vector types cannot be initialized");
7923 p
->type
= constructor_type
;
7924 p
->fields
= constructor_fields
;
7925 p
->index
= constructor_index
;
7926 p
->max_index
= constructor_max_index
;
7927 p
->unfilled_index
= constructor_unfilled_index
;
7928 p
->unfilled_fields
= constructor_unfilled_fields
;
7929 p
->bit_index
= constructor_bit_index
;
7930 p
->elements
= constructor_elements
;
7931 p
->constant
= constructor_constant
;
7932 p
->simple
= constructor_simple
;
7933 p
->nonconst
= constructor_nonconst
;
7934 p
->erroneous
= constructor_erroneous
;
7935 p
->pending_elts
= constructor_pending_elts
;
7936 p
->depth
= constructor_depth
;
7937 p
->replacement_value
.value
= 0;
7938 p
->replacement_value
.original_code
= ERROR_MARK
;
7939 p
->replacement_value
.original_type
= NULL
;
7943 p
->incremental
= constructor_incremental
;
7944 p
->designated
= constructor_designated
;
7945 p
->designator_depth
= designator_depth
;
7947 constructor_stack
= p
;
7949 constructor_constant
= 1;
7950 constructor_simple
= 1;
7951 constructor_nonconst
= 0;
7952 constructor_depth
= SPELLING_DEPTH ();
7953 constructor_elements
= NULL
;
7954 constructor_pending_elts
= 0;
7955 constructor_type
= type
;
7956 constructor_incremental
= 1;
7957 constructor_designated
= 0;
7958 constructor_zeroinit
= 1;
7959 designator_depth
= 0;
7960 designator_erroneous
= 0;
7962 if (RECORD_OR_UNION_TYPE_P (constructor_type
))
7964 constructor_fields
= TYPE_FIELDS (constructor_type
);
7965 /* Skip any nameless bit fields at the beginning. */
7966 while (constructor_fields
!= NULL_TREE
7967 && DECL_UNNAMED_BIT_FIELD (constructor_fields
))
7968 constructor_fields
= DECL_CHAIN (constructor_fields
);
7970 constructor_unfilled_fields
= constructor_fields
;
7971 constructor_bit_index
= bitsize_zero_node
;
7973 else if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
7975 if (TYPE_DOMAIN (constructor_type
))
7977 constructor_max_index
7978 = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type
));
7980 /* Detect non-empty initializations of zero-length arrays. */
7981 if (constructor_max_index
== NULL_TREE
7982 && TYPE_SIZE (constructor_type
))
7983 constructor_max_index
= integer_minus_one_node
;
7985 /* constructor_max_index needs to be an INTEGER_CST. Attempts
7986 to initialize VLAs will cause a proper error; avoid tree
7987 checking errors as well by setting a safe value. */
7988 if (constructor_max_index
7989 && TREE_CODE (constructor_max_index
) != INTEGER_CST
)
7990 constructor_max_index
= integer_minus_one_node
;
7993 = convert (bitsizetype
,
7994 TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type
)));
7998 constructor_index
= bitsize_zero_node
;
7999 constructor_max_index
= NULL_TREE
;
8002 constructor_unfilled_index
= constructor_index
;
8004 else if (VECTOR_TYPE_P (constructor_type
))
8006 /* Vectors are like simple fixed-size arrays. */
8007 constructor_max_index
=
8008 bitsize_int (TYPE_VECTOR_SUBPARTS (constructor_type
) - 1);
8009 constructor_index
= bitsize_zero_node
;
8010 constructor_unfilled_index
= constructor_index
;
8014 /* Handle the case of int x = {5}; */
8015 constructor_fields
= constructor_type
;
8016 constructor_unfilled_fields
= constructor_type
;
8020 extern location_t last_init_list_comma
;
8022 /* Called when we see an open brace for a nested initializer. Finish
8023 off any pending levels with implicit braces. */
8025 finish_implicit_inits (location_t loc
, struct obstack
*braced_init_obstack
)
8027 while (constructor_stack
->implicit
)
8029 if (RECORD_OR_UNION_TYPE_P (constructor_type
)
8030 && constructor_fields
== NULL_TREE
)
8031 process_init_element (input_location
,
8032 pop_init_level (loc
, 1, braced_init_obstack
,
8033 last_init_list_comma
),
8034 true, braced_init_obstack
);
8035 else if (TREE_CODE (constructor_type
) == ARRAY_TYPE
8036 && constructor_max_index
8037 && tree_int_cst_lt (constructor_max_index
,
8039 process_init_element (input_location
,
8040 pop_init_level (loc
, 1, braced_init_obstack
,
8041 last_init_list_comma
),
8042 true, braced_init_obstack
);
8048 /* Push down into a subobject, for initialization.
8049 If this is for an explicit set of braces, IMPLICIT is 0.
8050 If it is because the next element belongs at a lower level,
8051 IMPLICIT is 1 (or 2 if the push is because of designator list). */
8054 push_init_level (location_t loc
, int implicit
,
8055 struct obstack
*braced_init_obstack
)
8057 struct constructor_stack
*p
;
8058 tree value
= NULL_TREE
;
8060 /* Unless this is an explicit brace, we need to preserve previous
8064 if (RECORD_OR_UNION_TYPE_P (constructor_type
) && constructor_fields
)
8065 value
= find_init_member (constructor_fields
, braced_init_obstack
);
8066 else if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
8067 value
= find_init_member (constructor_index
, braced_init_obstack
);
8070 p
= XNEW (struct constructor_stack
);
8071 p
->type
= constructor_type
;
8072 p
->fields
= constructor_fields
;
8073 p
->index
= constructor_index
;
8074 p
->max_index
= constructor_max_index
;
8075 p
->unfilled_index
= constructor_unfilled_index
;
8076 p
->unfilled_fields
= constructor_unfilled_fields
;
8077 p
->bit_index
= constructor_bit_index
;
8078 p
->elements
= constructor_elements
;
8079 p
->constant
= constructor_constant
;
8080 p
->simple
= constructor_simple
;
8081 p
->nonconst
= constructor_nonconst
;
8082 p
->erroneous
= constructor_erroneous
;
8083 p
->pending_elts
= constructor_pending_elts
;
8084 p
->depth
= constructor_depth
;
8085 p
->replacement_value
.value
= NULL_TREE
;
8086 p
->replacement_value
.original_code
= ERROR_MARK
;
8087 p
->replacement_value
.original_type
= NULL
;
8088 p
->implicit
= implicit
;
8090 p
->incremental
= constructor_incremental
;
8091 p
->designated
= constructor_designated
;
8092 p
->designator_depth
= designator_depth
;
8093 p
->next
= constructor_stack
;
8095 constructor_stack
= p
;
8097 constructor_constant
= 1;
8098 constructor_simple
= 1;
8099 constructor_nonconst
= 0;
8100 constructor_depth
= SPELLING_DEPTH ();
8101 constructor_elements
= NULL
;
8102 constructor_incremental
= 1;
8103 constructor_designated
= 0;
8104 constructor_pending_elts
= 0;
8107 p
->range_stack
= constructor_range_stack
;
8108 constructor_range_stack
= 0;
8109 designator_depth
= 0;
8110 designator_erroneous
= 0;
8113 /* Don't die if an entire brace-pair level is superfluous
8114 in the containing level. */
8115 if (constructor_type
== NULL_TREE
)
8117 else if (RECORD_OR_UNION_TYPE_P (constructor_type
))
8119 /* Don't die if there are extra init elts at the end. */
8120 if (constructor_fields
== NULL_TREE
)
8121 constructor_type
= NULL_TREE
;
8124 constructor_type
= TREE_TYPE (constructor_fields
);
8125 push_member_name (constructor_fields
);
8126 constructor_depth
++;
8128 /* If upper initializer is designated, then mark this as
8129 designated too to prevent bogus warnings. */
8130 constructor_designated
= p
->designated
;
8132 else if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
8134 constructor_type
= TREE_TYPE (constructor_type
);
8135 push_array_bounds (tree_to_uhwi (constructor_index
));
8136 constructor_depth
++;
8139 if (constructor_type
== NULL_TREE
)
8141 error_init (loc
, "extra brace group at end of initializer");
8142 constructor_fields
= NULL_TREE
;
8143 constructor_unfilled_fields
= NULL_TREE
;
8147 if (value
&& TREE_CODE (value
) == CONSTRUCTOR
)
8149 constructor_constant
= TREE_CONSTANT (value
);
8150 constructor_simple
= TREE_STATIC (value
);
8151 constructor_nonconst
= CONSTRUCTOR_NON_CONST (value
);
8152 constructor_elements
= CONSTRUCTOR_ELTS (value
);
8153 if (!vec_safe_is_empty (constructor_elements
)
8154 && (TREE_CODE (constructor_type
) == RECORD_TYPE
8155 || TREE_CODE (constructor_type
) == ARRAY_TYPE
))
8156 set_nonincremental_init (braced_init_obstack
);
8161 found_missing_braces
= 1;
8162 if (initializer_stack
->missing_brace_richloc
)
8163 initializer_stack
->missing_brace_richloc
->add_fixit_insert_before
8167 if (RECORD_OR_UNION_TYPE_P (constructor_type
))
8169 constructor_fields
= TYPE_FIELDS (constructor_type
);
8170 /* Skip any nameless bit fields at the beginning. */
8171 while (constructor_fields
!= NULL_TREE
8172 && DECL_UNNAMED_BIT_FIELD (constructor_fields
))
8173 constructor_fields
= DECL_CHAIN (constructor_fields
);
8175 constructor_unfilled_fields
= constructor_fields
;
8176 constructor_bit_index
= bitsize_zero_node
;
8178 else if (VECTOR_TYPE_P (constructor_type
))
8180 /* Vectors are like simple fixed-size arrays. */
8181 constructor_max_index
=
8182 bitsize_int (TYPE_VECTOR_SUBPARTS (constructor_type
) - 1);
8183 constructor_index
= bitsize_int (0);
8184 constructor_unfilled_index
= constructor_index
;
8186 else if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
8188 if (TYPE_DOMAIN (constructor_type
))
8190 constructor_max_index
8191 = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type
));
8193 /* Detect non-empty initializations of zero-length arrays. */
8194 if (constructor_max_index
== NULL_TREE
8195 && TYPE_SIZE (constructor_type
))
8196 constructor_max_index
= integer_minus_one_node
;
8198 /* constructor_max_index needs to be an INTEGER_CST. Attempts
8199 to initialize VLAs will cause a proper error; avoid tree
8200 checking errors as well by setting a safe value. */
8201 if (constructor_max_index
8202 && TREE_CODE (constructor_max_index
) != INTEGER_CST
)
8203 constructor_max_index
= integer_minus_one_node
;
8206 = convert (bitsizetype
,
8207 TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type
)));
8210 constructor_index
= bitsize_zero_node
;
8212 constructor_unfilled_index
= constructor_index
;
8213 if (value
&& TREE_CODE (value
) == STRING_CST
)
8215 /* We need to split the char/wchar array into individual
8216 characters, so that we don't have to special case it
8218 set_nonincremental_init_from_string (value
, braced_init_obstack
);
8223 if (constructor_type
!= error_mark_node
)
8224 warning_init (input_location
, 0, "braces around scalar initializer");
8225 constructor_fields
= constructor_type
;
8226 constructor_unfilled_fields
= constructor_type
;
8230 /* At the end of an implicit or explicit brace level,
8231 finish up that level of constructor. If a single expression
8232 with redundant braces initialized that level, return the
8233 c_expr structure for that expression. Otherwise, the original_code
8234 element is set to ERROR_MARK.
8235 If we were outputting the elements as they are read, return 0 as the value
8236 from inner levels (process_init_element ignores that),
8237 but return error_mark_node as the value from the outermost level
8238 (that's what we want to put in DECL_INITIAL).
8239 Otherwise, return a CONSTRUCTOR expression as the value. */
8242 pop_init_level (location_t loc
, int implicit
,
8243 struct obstack
*braced_init_obstack
,
8244 location_t insert_before
)
8246 struct constructor_stack
*p
;
8248 ret
.value
= NULL_TREE
;
8249 ret
.original_code
= ERROR_MARK
;
8250 ret
.original_type
= NULL
;
8254 /* When we come to an explicit close brace,
8255 pop any inner levels that didn't have explicit braces. */
8256 while (constructor_stack
->implicit
)
8257 process_init_element (input_location
,
8258 pop_init_level (loc
, 1, braced_init_obstack
,
8260 true, braced_init_obstack
);
8261 gcc_assert (!constructor_range_stack
);
8264 if (initializer_stack
->missing_brace_richloc
)
8265 initializer_stack
->missing_brace_richloc
->add_fixit_insert_before
8266 (insert_before
, "}");
8268 /* Now output all pending elements. */
8269 constructor_incremental
= 1;
8270 output_pending_init_elements (1, braced_init_obstack
);
8272 p
= constructor_stack
;
8274 /* Error for initializing a flexible array member, or a zero-length
8275 array member in an inappropriate context. */
8276 if (constructor_type
&& constructor_fields
8277 && TREE_CODE (constructor_type
) == ARRAY_TYPE
8278 && TYPE_DOMAIN (constructor_type
)
8279 && !TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type
)))
8281 /* Silently discard empty initializations. The parser will
8282 already have pedwarned for empty brackets. */
8283 if (integer_zerop (constructor_unfilled_index
))
8284 constructor_type
= NULL_TREE
;
8287 gcc_assert (!TYPE_SIZE (constructor_type
));
8289 if (constructor_depth
> 2)
8290 error_init (loc
, "initialization of flexible array member in a nested context");
8292 pedwarn_init (loc
, OPT_Wpedantic
,
8293 "initialization of a flexible array member");
8295 /* We have already issued an error message for the existence
8296 of a flexible array member not at the end of the structure.
8297 Discard the initializer so that we do not die later. */
8298 if (DECL_CHAIN (constructor_fields
) != NULL_TREE
)
8299 constructor_type
= NULL_TREE
;
8303 switch (vec_safe_length (constructor_elements
))
8306 /* Initialization with { } counts as zeroinit. */
8307 constructor_zeroinit
= 1;
8310 /* This might be zeroinit as well. */
8311 if (integer_zerop ((*constructor_elements
)[0].value
))
8312 constructor_zeroinit
= 1;
8315 /* If the constructor has more than one element, it can't be { 0 }. */
8316 constructor_zeroinit
= 0;
8320 /* Warn when some structs are initialized with direct aggregation. */
8321 if (!implicit
&& found_missing_braces
&& warn_missing_braces
8322 && !constructor_zeroinit
)
8324 gcc_assert (initializer_stack
->missing_brace_richloc
);
8325 warning_at (initializer_stack
->missing_brace_richloc
,
8326 OPT_Wmissing_braces
,
8327 "missing braces around initializer");
8330 /* Warn when some struct elements are implicitly initialized to zero. */
8331 if (warn_missing_field_initializers
8333 && TREE_CODE (constructor_type
) == RECORD_TYPE
8334 && constructor_unfilled_fields
)
8336 /* Do not warn for flexible array members or zero-length arrays. */
8337 while (constructor_unfilled_fields
8338 && (!DECL_SIZE (constructor_unfilled_fields
)
8339 || integer_zerop (DECL_SIZE (constructor_unfilled_fields
))))
8340 constructor_unfilled_fields
= DECL_CHAIN (constructor_unfilled_fields
);
8342 if (constructor_unfilled_fields
8343 /* Do not warn if this level of the initializer uses member
8344 designators; it is likely to be deliberate. */
8345 && !constructor_designated
8346 /* Do not warn about initializing with { 0 } or with { }. */
8347 && !constructor_zeroinit
)
8349 if (warning_at (input_location
, OPT_Wmissing_field_initializers
,
8350 "missing initializer for field %qD of %qT",
8351 constructor_unfilled_fields
,
8353 inform (DECL_SOURCE_LOCATION (constructor_unfilled_fields
),
8354 "%qD declared here", constructor_unfilled_fields
);
8358 /* Pad out the end of the structure. */
8359 if (p
->replacement_value
.value
)
8360 /* If this closes a superfluous brace pair,
8361 just pass out the element between them. */
8362 ret
= p
->replacement_value
;
8363 else if (constructor_type
== NULL_TREE
)
8365 else if (!RECORD_OR_UNION_TYPE_P (constructor_type
)
8366 && TREE_CODE (constructor_type
) != ARRAY_TYPE
8367 && !VECTOR_TYPE_P (constructor_type
))
8369 /* A nonincremental scalar initializer--just return
8370 the element, after verifying there is just one. */
8371 if (vec_safe_is_empty (constructor_elements
))
8373 if (!constructor_erroneous
)
8374 error_init (loc
, "empty scalar initializer");
8375 ret
.value
= error_mark_node
;
8377 else if (vec_safe_length (constructor_elements
) != 1)
8379 error_init (loc
, "extra elements in scalar initializer");
8380 ret
.value
= (*constructor_elements
)[0].value
;
8383 ret
.value
= (*constructor_elements
)[0].value
;
8387 if (constructor_erroneous
)
8388 ret
.value
= error_mark_node
;
8391 ret
.value
= build_constructor (constructor_type
,
8392 constructor_elements
);
8393 if (constructor_constant
)
8394 TREE_CONSTANT (ret
.value
) = 1;
8395 if (constructor_constant
&& constructor_simple
)
8396 TREE_STATIC (ret
.value
) = 1;
8397 if (constructor_nonconst
)
8398 CONSTRUCTOR_NON_CONST (ret
.value
) = 1;
8402 if (ret
.value
&& TREE_CODE (ret
.value
) != CONSTRUCTOR
)
8404 if (constructor_nonconst
)
8405 ret
.original_code
= C_MAYBE_CONST_EXPR
;
8406 else if (ret
.original_code
== C_MAYBE_CONST_EXPR
)
8407 ret
.original_code
= ERROR_MARK
;
8410 constructor_type
= p
->type
;
8411 constructor_fields
= p
->fields
;
8412 constructor_index
= p
->index
;
8413 constructor_max_index
= p
->max_index
;
8414 constructor_unfilled_index
= p
->unfilled_index
;
8415 constructor_unfilled_fields
= p
->unfilled_fields
;
8416 constructor_bit_index
= p
->bit_index
;
8417 constructor_elements
= p
->elements
;
8418 constructor_constant
= p
->constant
;
8419 constructor_simple
= p
->simple
;
8420 constructor_nonconst
= p
->nonconst
;
8421 constructor_erroneous
= p
->erroneous
;
8422 constructor_incremental
= p
->incremental
;
8423 constructor_designated
= p
->designated
;
8424 designator_depth
= p
->designator_depth
;
8425 constructor_pending_elts
= p
->pending_elts
;
8426 constructor_depth
= p
->depth
;
8428 constructor_range_stack
= p
->range_stack
;
8429 RESTORE_SPELLING_DEPTH (constructor_depth
);
8431 constructor_stack
= p
->next
;
8434 if (ret
.value
== NULL_TREE
&& constructor_stack
== 0)
8435 ret
.value
= error_mark_node
;
8439 /* Common handling for both array range and field name designators.
8440 ARRAY argument is nonzero for array ranges. Returns false for success. */
8443 set_designator (location_t loc
, bool array
,
8444 struct obstack
*braced_init_obstack
)
8447 enum tree_code subcode
;
8449 /* Don't die if an entire brace-pair level is superfluous
8450 in the containing level. */
8451 if (constructor_type
== NULL_TREE
)
8454 /* If there were errors in this designator list already, bail out
8456 if (designator_erroneous
)
8459 if (!designator_depth
)
8461 gcc_assert (!constructor_range_stack
);
8463 /* Designator list starts at the level of closest explicit
8465 while (constructor_stack
->implicit
)
8466 process_init_element (input_location
,
8467 pop_init_level (loc
, 1, braced_init_obstack
,
8468 last_init_list_comma
),
8469 true, braced_init_obstack
);
8470 constructor_designated
= 1;
8474 switch (TREE_CODE (constructor_type
))
8478 subtype
= TREE_TYPE (constructor_fields
);
8479 if (subtype
!= error_mark_node
)
8480 subtype
= TYPE_MAIN_VARIANT (subtype
);
8483 subtype
= TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type
));
8489 subcode
= TREE_CODE (subtype
);
8490 if (array
&& subcode
!= ARRAY_TYPE
)
8492 error_init (loc
, "array index in non-array initializer");
8495 else if (!array
&& subcode
!= RECORD_TYPE
&& subcode
!= UNION_TYPE
)
8497 error_init (loc
, "field name not in record or union initializer");
8501 constructor_designated
= 1;
8502 finish_implicit_inits (loc
, braced_init_obstack
);
8503 push_init_level (loc
, 2, braced_init_obstack
);
8507 /* If there are range designators in designator list, push a new designator
8508 to constructor_range_stack. RANGE_END is end of such stack range or
8509 NULL_TREE if there is no range designator at this level. */
8512 push_range_stack (tree range_end
, struct obstack
* braced_init_obstack
)
8514 struct constructor_range_stack
*p
;
8516 p
= (struct constructor_range_stack
*)
8517 obstack_alloc (braced_init_obstack
,
8518 sizeof (struct constructor_range_stack
));
8519 p
->prev
= constructor_range_stack
;
8521 p
->fields
= constructor_fields
;
8522 p
->range_start
= constructor_index
;
8523 p
->index
= constructor_index
;
8524 p
->stack
= constructor_stack
;
8525 p
->range_end
= range_end
;
8526 if (constructor_range_stack
)
8527 constructor_range_stack
->next
= p
;
8528 constructor_range_stack
= p
;
8531 /* Within an array initializer, specify the next index to be initialized.
8532 FIRST is that index. If LAST is nonzero, then initialize a range
8533 of indices, running from FIRST through LAST. */
8536 set_init_index (location_t loc
, tree first
, tree last
,
8537 struct obstack
*braced_init_obstack
)
8539 if (set_designator (loc
, true, braced_init_obstack
))
8542 designator_erroneous
= 1;
8544 if (!INTEGRAL_TYPE_P (TREE_TYPE (first
))
8545 || (last
&& !INTEGRAL_TYPE_P (TREE_TYPE (last
))))
8547 error_init (loc
, "array index in initializer not of integer type");
8551 if (TREE_CODE (first
) != INTEGER_CST
)
8553 first
= c_fully_fold (first
, false, NULL
);
8554 if (TREE_CODE (first
) == INTEGER_CST
)
8555 pedwarn_init (loc
, OPT_Wpedantic
,
8556 "array index in initializer is not "
8557 "an integer constant expression");
8560 if (last
&& TREE_CODE (last
) != INTEGER_CST
)
8562 last
= c_fully_fold (last
, false, NULL
);
8563 if (TREE_CODE (last
) == INTEGER_CST
)
8564 pedwarn_init (loc
, OPT_Wpedantic
,
8565 "array index in initializer is not "
8566 "an integer constant expression");
8569 if (TREE_CODE (first
) != INTEGER_CST
)
8570 error_init (loc
, "nonconstant array index in initializer");
8571 else if (last
!= NULL_TREE
&& TREE_CODE (last
) != INTEGER_CST
)
8572 error_init (loc
, "nonconstant array index in initializer");
8573 else if (TREE_CODE (constructor_type
) != ARRAY_TYPE
)
8574 error_init (loc
, "array index in non-array initializer");
8575 else if (tree_int_cst_sgn (first
) == -1)
8576 error_init (loc
, "array index in initializer exceeds array bounds");
8577 else if (constructor_max_index
8578 && tree_int_cst_lt (constructor_max_index
, first
))
8579 error_init (loc
, "array index in initializer exceeds array bounds");
8582 constant_expression_warning (first
);
8584 constant_expression_warning (last
);
8585 constructor_index
= convert (bitsizetype
, first
);
8586 if (tree_int_cst_lt (constructor_index
, first
))
8588 constructor_index
= copy_node (constructor_index
);
8589 TREE_OVERFLOW (constructor_index
) = 1;
8594 if (tree_int_cst_equal (first
, last
))
8596 else if (tree_int_cst_lt (last
, first
))
8598 error_init (loc
, "empty index range in initializer");
8603 last
= convert (bitsizetype
, last
);
8604 if (constructor_max_index
!= NULL_TREE
8605 && tree_int_cst_lt (constructor_max_index
, last
))
8607 error_init (loc
, "array index range in initializer exceeds "
8615 designator_erroneous
= 0;
8616 if (constructor_range_stack
|| last
)
8617 push_range_stack (last
, braced_init_obstack
);
8621 /* Within a struct initializer, specify the next field to be initialized. */
8624 set_init_label (location_t loc
, tree fieldname
, location_t fieldname_loc
,
8625 struct obstack
*braced_init_obstack
)
8629 if (set_designator (loc
, false, braced_init_obstack
))
8632 designator_erroneous
= 1;
8634 if (!RECORD_OR_UNION_TYPE_P (constructor_type
))
8636 error_init (loc
, "field name not in record or union initializer");
8640 field
= lookup_field (constructor_type
, fieldname
);
8642 if (field
== NULL_TREE
)
8644 tree guessed_id
= lookup_field_fuzzy (constructor_type
, fieldname
);
8647 gcc_rich_location
rich_loc (fieldname_loc
);
8648 rich_loc
.add_fixit_misspelled_id (fieldname_loc
, guessed_id
);
8649 error_at (&rich_loc
,
8650 "%qT has no member named %qE; did you mean %qE?",
8651 constructor_type
, fieldname
, guessed_id
);
8654 error_at (fieldname_loc
, "%qT has no member named %qE",
8655 constructor_type
, fieldname
);
8660 constructor_fields
= TREE_VALUE (field
);
8662 designator_erroneous
= 0;
8663 if (constructor_range_stack
)
8664 push_range_stack (NULL_TREE
, braced_init_obstack
);
8665 field
= TREE_CHAIN (field
);
8668 if (set_designator (loc
, false, braced_init_obstack
))
8672 while (field
!= NULL_TREE
);
8675 /* Add a new initializer to the tree of pending initializers. PURPOSE
8676 identifies the initializer, either array index or field in a structure.
8677 VALUE is the value of that index or field. If ORIGTYPE is not
8678 NULL_TREE, it is the original type of VALUE.
8680 IMPLICIT is true if value comes from pop_init_level (1),
8681 the new initializer has been merged with the existing one
8682 and thus no warnings should be emitted about overriding an
8683 existing initializer. */
8686 add_pending_init (location_t loc
, tree purpose
, tree value
, tree origtype
,
8687 bool implicit
, struct obstack
*braced_init_obstack
)
8689 struct init_node
*p
, **q
, *r
;
8691 q
= &constructor_pending_elts
;
8694 if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
8699 if (tree_int_cst_lt (purpose
, p
->purpose
))
8701 else if (tree_int_cst_lt (p
->purpose
, purpose
))
8707 if (TREE_SIDE_EFFECTS (p
->value
))
8708 warning_init (loc
, OPT_Woverride_init_side_effects
,
8709 "initialized field with side-effects "
8711 else if (warn_override_init
)
8712 warning_init (loc
, OPT_Woverride_init
,
8713 "initialized field overwritten");
8716 p
->origtype
= origtype
;
8725 bitpos
= bit_position (purpose
);
8729 if (tree_int_cst_lt (bitpos
, bit_position (p
->purpose
)))
8731 else if (p
->purpose
!= purpose
)
8737 if (TREE_SIDE_EFFECTS (p
->value
))
8738 warning_init (loc
, OPT_Woverride_init_side_effects
,
8739 "initialized field with side-effects "
8741 else if (warn_override_init
)
8742 warning_init (loc
, OPT_Woverride_init
,
8743 "initialized field overwritten");
8746 p
->origtype
= origtype
;
8752 r
= (struct init_node
*) obstack_alloc (braced_init_obstack
,
8753 sizeof (struct init_node
));
8754 r
->purpose
= purpose
;
8756 r
->origtype
= origtype
;
8766 struct init_node
*s
;
8770 if (p
->balance
== 0)
8772 else if (p
->balance
< 0)
8779 p
->left
->parent
= p
;
8796 constructor_pending_elts
= r
;
8801 struct init_node
*t
= r
->right
;
8805 r
->right
->parent
= r
;
8810 p
->left
->parent
= p
;
8813 p
->balance
= t
->balance
< 0;
8814 r
->balance
= -(t
->balance
> 0);
8829 constructor_pending_elts
= t
;
8835 /* p->balance == +1; growth of left side balances the node. */
8840 else /* r == p->right */
8842 if (p
->balance
== 0)
8843 /* Growth propagation from right side. */
8845 else if (p
->balance
> 0)
8852 p
->right
->parent
= p
;
8869 constructor_pending_elts
= r
;
8871 else /* r->balance == -1 */
8874 struct init_node
*t
= r
->left
;
8878 r
->left
->parent
= r
;
8883 p
->right
->parent
= p
;
8886 r
->balance
= (t
->balance
< 0);
8887 p
->balance
= -(t
->balance
> 0);
8902 constructor_pending_elts
= t
;
8908 /* p->balance == -1; growth of right side balances the node. */
8919 /* Build AVL tree from a sorted chain. */
8922 set_nonincremental_init (struct obstack
* braced_init_obstack
)
8924 unsigned HOST_WIDE_INT ix
;
8927 if (TREE_CODE (constructor_type
) != RECORD_TYPE
8928 && TREE_CODE (constructor_type
) != ARRAY_TYPE
)
8931 FOR_EACH_CONSTRUCTOR_ELT (constructor_elements
, ix
, index
, value
)
8932 add_pending_init (input_location
, index
, value
, NULL_TREE
, true,
8933 braced_init_obstack
);
8934 constructor_elements
= NULL
;
8935 if (TREE_CODE (constructor_type
) == RECORD_TYPE
)
8937 constructor_unfilled_fields
= TYPE_FIELDS (constructor_type
);
8938 /* Skip any nameless bit fields at the beginning. */
8939 while (constructor_unfilled_fields
!= NULL_TREE
8940 && DECL_UNNAMED_BIT_FIELD (constructor_unfilled_fields
))
8941 constructor_unfilled_fields
= TREE_CHAIN (constructor_unfilled_fields
);
8944 else if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
8946 if (TYPE_DOMAIN (constructor_type
))
8947 constructor_unfilled_index
8948 = convert (bitsizetype
,
8949 TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type
)));
8951 constructor_unfilled_index
= bitsize_zero_node
;
8953 constructor_incremental
= 0;
8956 /* Build AVL tree from a string constant. */
8959 set_nonincremental_init_from_string (tree str
,
8960 struct obstack
* braced_init_obstack
)
8962 tree value
, purpose
, type
;
8963 HOST_WIDE_INT val
[2];
8964 const char *p
, *end
;
8965 int byte
, wchar_bytes
, charwidth
, bitpos
;
8967 gcc_assert (TREE_CODE (constructor_type
) == ARRAY_TYPE
);
8969 wchar_bytes
= TYPE_PRECISION (TREE_TYPE (TREE_TYPE (str
))) / BITS_PER_UNIT
;
8970 charwidth
= TYPE_PRECISION (char_type_node
);
8971 gcc_assert ((size_t) wchar_bytes
* charwidth
8972 <= ARRAY_SIZE (val
) * HOST_BITS_PER_WIDE_INT
);
8973 type
= TREE_TYPE (constructor_type
);
8974 p
= TREE_STRING_POINTER (str
);
8975 end
= p
+ TREE_STRING_LENGTH (str
);
8977 for (purpose
= bitsize_zero_node
;
8979 && !(constructor_max_index
8980 && tree_int_cst_lt (constructor_max_index
, purpose
));
8981 purpose
= size_binop (PLUS_EXPR
, purpose
, bitsize_one_node
))
8983 if (wchar_bytes
== 1)
8985 val
[0] = (unsigned char) *p
++;
8992 for (byte
= 0; byte
< wchar_bytes
; byte
++)
8994 if (BYTES_BIG_ENDIAN
)
8995 bitpos
= (wchar_bytes
- byte
- 1) * charwidth
;
8997 bitpos
= byte
* charwidth
;
8998 val
[bitpos
/ HOST_BITS_PER_WIDE_INT
]
8999 |= ((unsigned HOST_WIDE_INT
) ((unsigned char) *p
++))
9000 << (bitpos
% HOST_BITS_PER_WIDE_INT
);
9004 if (!TYPE_UNSIGNED (type
))
9006 bitpos
= ((wchar_bytes
- 1) * charwidth
) + HOST_BITS_PER_CHAR
;
9007 if (bitpos
< HOST_BITS_PER_WIDE_INT
)
9009 if (val
[0] & (HOST_WIDE_INT_1
<< (bitpos
- 1)))
9011 val
[0] |= HOST_WIDE_INT_M1U
<< bitpos
;
9015 else if (bitpos
== HOST_BITS_PER_WIDE_INT
)
9020 else if (val
[1] & (HOST_WIDE_INT_1
9021 << (bitpos
- 1 - HOST_BITS_PER_WIDE_INT
)))
9022 val
[1] |= HOST_WIDE_INT_M1U
<< (bitpos
- HOST_BITS_PER_WIDE_INT
);
9025 value
= wide_int_to_tree (type
,
9026 wide_int::from_array (val
, 2,
9027 HOST_BITS_PER_WIDE_INT
* 2));
9028 add_pending_init (input_location
, purpose
, value
, NULL_TREE
, true,
9029 braced_init_obstack
);
9032 constructor_incremental
= 0;
9035 /* Return value of FIELD in pending initializer or NULL_TREE if the field was
9036 not initialized yet. */
9039 find_init_member (tree field
, struct obstack
* braced_init_obstack
)
9041 struct init_node
*p
;
9043 if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
9045 if (constructor_incremental
9046 && tree_int_cst_lt (field
, constructor_unfilled_index
))
9047 set_nonincremental_init (braced_init_obstack
);
9049 p
= constructor_pending_elts
;
9052 if (tree_int_cst_lt (field
, p
->purpose
))
9054 else if (tree_int_cst_lt (p
->purpose
, field
))
9060 else if (TREE_CODE (constructor_type
) == RECORD_TYPE
)
9062 tree bitpos
= bit_position (field
);
9064 if (constructor_incremental
9065 && (!constructor_unfilled_fields
9066 || tree_int_cst_lt (bitpos
,
9067 bit_position (constructor_unfilled_fields
))))
9068 set_nonincremental_init (braced_init_obstack
);
9070 p
= constructor_pending_elts
;
9073 if (field
== p
->purpose
)
9075 else if (tree_int_cst_lt (bitpos
, bit_position (p
->purpose
)))
9081 else if (TREE_CODE (constructor_type
) == UNION_TYPE
)
9083 if (!vec_safe_is_empty (constructor_elements
)
9084 && (constructor_elements
->last ().index
== field
))
9085 return constructor_elements
->last ().value
;
9090 /* "Output" the next constructor element.
9091 At top level, really output it to assembler code now.
9092 Otherwise, collect it in a list from which we will make a CONSTRUCTOR.
9093 If ORIGTYPE is not NULL_TREE, it is the original type of VALUE.
9094 TYPE is the data type that the containing data type wants here.
9095 FIELD is the field (a FIELD_DECL) or the index that this element fills.
9096 If VALUE is a string constant, STRICT_STRING is true if it is
9097 unparenthesized or we should not warn here for it being parenthesized.
9098 For other types of VALUE, STRICT_STRING is not used.
9100 PENDING if true means output pending elements that belong
9101 right after this element. (PENDING is normally true;
9102 it is false while outputting pending elements, to avoid recursion.)
9104 IMPLICIT is true if value comes from pop_init_level (1),
9105 the new initializer has been merged with the existing one
9106 and thus no warnings should be emitted about overriding an
9107 existing initializer. */
9110 output_init_element (location_t loc
, tree value
, tree origtype
,
9111 bool strict_string
, tree type
, tree field
, bool pending
,
9112 bool implicit
, struct obstack
* braced_init_obstack
)
9114 tree semantic_type
= NULL_TREE
;
9115 bool maybe_const
= true;
9118 if (type
== error_mark_node
|| value
== error_mark_node
)
9120 constructor_erroneous
= 1;
9123 if (TREE_CODE (TREE_TYPE (value
)) == ARRAY_TYPE
9124 && (TREE_CODE (value
) == STRING_CST
9125 || TREE_CODE (value
) == COMPOUND_LITERAL_EXPR
)
9126 && !(TREE_CODE (value
) == STRING_CST
9127 && TREE_CODE (type
) == ARRAY_TYPE
9128 && INTEGRAL_TYPE_P (TREE_TYPE (type
)))
9129 && !comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (value
)),
9130 TYPE_MAIN_VARIANT (type
)))
9131 value
= array_to_pointer_conversion (input_location
, value
);
9133 if (TREE_CODE (value
) == COMPOUND_LITERAL_EXPR
9134 && require_constant_value
&& pending
)
9136 /* As an extension, allow initializing objects with static storage
9137 duration with compound literals (which are then treated just as
9138 the brace enclosed list they contain). */
9140 pedwarn_init (loc
, OPT_Wpedantic
, "initializer element is not "
9142 tree decl
= COMPOUND_LITERAL_EXPR_DECL (value
);
9143 value
= DECL_INITIAL (decl
);
9146 npc
= null_pointer_constant_p (value
);
9147 if (TREE_CODE (value
) == EXCESS_PRECISION_EXPR
)
9149 semantic_type
= TREE_TYPE (value
);
9150 value
= TREE_OPERAND (value
, 0);
9152 value
= c_fully_fold (value
, require_constant_value
, &maybe_const
);
9154 if (value
== error_mark_node
)
9155 constructor_erroneous
= 1;
9156 else if (!TREE_CONSTANT (value
))
9157 constructor_constant
= 0;
9158 else if (!initializer_constant_valid_p (value
,
9160 AGGREGATE_TYPE_P (constructor_type
)
9161 && TYPE_REVERSE_STORAGE_ORDER
9163 || (RECORD_OR_UNION_TYPE_P (constructor_type
)
9164 && DECL_C_BIT_FIELD (field
)
9165 && TREE_CODE (value
) != INTEGER_CST
))
9166 constructor_simple
= 0;
9168 constructor_nonconst
= 1;
9170 /* Digest the initializer and issue any errors about incompatible
9171 types before issuing errors about non-constant initializers. */
9172 tree new_value
= value
;
9174 new_value
= build1 (EXCESS_PRECISION_EXPR
, semantic_type
, value
);
9175 new_value
= digest_init (loc
, type
, new_value
, origtype
, npc
, strict_string
,
9176 require_constant_value
);
9177 if (new_value
== error_mark_node
)
9179 constructor_erroneous
= 1;
9182 if (require_constant_value
|| require_constant_elements
)
9183 constant_expression_warning (new_value
);
9185 /* Proceed to check the constness of the original initializer. */
9186 if (!initializer_constant_valid_p (value
, TREE_TYPE (value
)))
9188 if (require_constant_value
)
9190 error_init (loc
, "initializer element is not constant");
9191 value
= error_mark_node
;
9193 else if (require_constant_elements
)
9194 pedwarn (loc
, OPT_Wpedantic
,
9195 "initializer element is not computable at load time");
9197 else if (!maybe_const
9198 && (require_constant_value
|| require_constant_elements
))
9199 pedwarn_init (loc
, OPT_Wpedantic
,
9200 "initializer element is not a constant expression");
9202 /* Issue -Wc++-compat warnings about initializing a bitfield with
9205 && field
!= NULL_TREE
9206 && TREE_CODE (field
) == FIELD_DECL
9207 && DECL_BIT_FIELD_TYPE (field
) != NULL_TREE
9208 && (TYPE_MAIN_VARIANT (DECL_BIT_FIELD_TYPE (field
))
9209 != TYPE_MAIN_VARIANT (type
))
9210 && TREE_CODE (DECL_BIT_FIELD_TYPE (field
)) == ENUMERAL_TYPE
)
9212 tree checktype
= origtype
!= NULL_TREE
? origtype
: TREE_TYPE (value
);
9213 if (checktype
!= error_mark_node
9214 && (TYPE_MAIN_VARIANT (checktype
)
9215 != TYPE_MAIN_VARIANT (DECL_BIT_FIELD_TYPE (field
))))
9216 warning_init (loc
, OPT_Wc___compat
,
9217 "enum conversion in initialization is invalid in C++");
9220 /* If this field is empty and does not have side effects (and is not at
9221 the end of structure), don't do anything other than checking the
9224 && (TREE_TYPE (field
) == error_mark_node
9225 || (COMPLETE_TYPE_P (TREE_TYPE (field
))
9226 && integer_zerop (TYPE_SIZE (TREE_TYPE (field
)))
9227 && !TREE_SIDE_EFFECTS (new_value
)
9228 && (TREE_CODE (constructor_type
) == ARRAY_TYPE
9229 || DECL_CHAIN (field
)))))
9232 /* Finally, set VALUE to the initializer value digested above. */
9235 /* If this element doesn't come next in sequence,
9236 put it on constructor_pending_elts. */
9237 if (TREE_CODE (constructor_type
) == ARRAY_TYPE
9238 && (!constructor_incremental
9239 || !tree_int_cst_equal (field
, constructor_unfilled_index
)))
9241 if (constructor_incremental
9242 && tree_int_cst_lt (field
, constructor_unfilled_index
))
9243 set_nonincremental_init (braced_init_obstack
);
9245 add_pending_init (loc
, field
, value
, origtype
, implicit
,
9246 braced_init_obstack
);
9249 else if (TREE_CODE (constructor_type
) == RECORD_TYPE
9250 && (!constructor_incremental
9251 || field
!= constructor_unfilled_fields
))
9253 /* We do this for records but not for unions. In a union,
9254 no matter which field is specified, it can be initialized
9255 right away since it starts at the beginning of the union. */
9256 if (constructor_incremental
)
9258 if (!constructor_unfilled_fields
)
9259 set_nonincremental_init (braced_init_obstack
);
9262 tree bitpos
, unfillpos
;
9264 bitpos
= bit_position (field
);
9265 unfillpos
= bit_position (constructor_unfilled_fields
);
9267 if (tree_int_cst_lt (bitpos
, unfillpos
))
9268 set_nonincremental_init (braced_init_obstack
);
9272 add_pending_init (loc
, field
, value
, origtype
, implicit
,
9273 braced_init_obstack
);
9276 else if (TREE_CODE (constructor_type
) == UNION_TYPE
9277 && !vec_safe_is_empty (constructor_elements
))
9281 if (TREE_SIDE_EFFECTS (constructor_elements
->last ().value
))
9282 warning_init (loc
, OPT_Woverride_init_side_effects
,
9283 "initialized field with side-effects overwritten");
9284 else if (warn_override_init
)
9285 warning_init (loc
, OPT_Woverride_init
,
9286 "initialized field overwritten");
9289 /* We can have just one union field set. */
9290 constructor_elements
= NULL
;
9293 /* Otherwise, output this element either to
9294 constructor_elements or to the assembler file. */
9296 constructor_elt celt
= {field
, value
};
9297 vec_safe_push (constructor_elements
, celt
);
9299 /* Advance the variable that indicates sequential elements output. */
9300 if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
9301 constructor_unfilled_index
9302 = size_binop_loc (input_location
, PLUS_EXPR
, constructor_unfilled_index
,
9304 else if (TREE_CODE (constructor_type
) == RECORD_TYPE
)
9306 constructor_unfilled_fields
9307 = DECL_CHAIN (constructor_unfilled_fields
);
9309 /* Skip any nameless bit fields. */
9310 while (constructor_unfilled_fields
!= NULL_TREE
9311 && DECL_UNNAMED_BIT_FIELD (constructor_unfilled_fields
))
9312 constructor_unfilled_fields
=
9313 DECL_CHAIN (constructor_unfilled_fields
);
9315 else if (TREE_CODE (constructor_type
) == UNION_TYPE
)
9316 constructor_unfilled_fields
= NULL_TREE
;
9318 /* Now output any pending elements which have become next. */
9320 output_pending_init_elements (0, braced_init_obstack
);
9323 /* Output any pending elements which have become next.
9324 As we output elements, constructor_unfilled_{fields,index}
9325 advances, which may cause other elements to become next;
9326 if so, they too are output.
9328 If ALL is 0, we return when there are
9329 no more pending elements to output now.
9331 If ALL is 1, we output space as necessary so that
9332 we can output all the pending elements. */
9334 output_pending_init_elements (int all
, struct obstack
* braced_init_obstack
)
9336 struct init_node
*elt
= constructor_pending_elts
;
9341 /* Look through the whole pending tree.
9342 If we find an element that should be output now,
9343 output it. Otherwise, set NEXT to the element
9344 that comes first among those still pending. */
9349 if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
9351 if (tree_int_cst_equal (elt
->purpose
,
9352 constructor_unfilled_index
))
9353 output_init_element (input_location
, elt
->value
, elt
->origtype
,
9354 true, TREE_TYPE (constructor_type
),
9355 constructor_unfilled_index
, false, false,
9356 braced_init_obstack
);
9357 else if (tree_int_cst_lt (constructor_unfilled_index
,
9360 /* Advance to the next smaller node. */
9365 /* We have reached the smallest node bigger than the
9366 current unfilled index. Fill the space first. */
9367 next
= elt
->purpose
;
9373 /* Advance to the next bigger node. */
9378 /* We have reached the biggest node in a subtree. Find
9379 the parent of it, which is the next bigger node. */
9380 while (elt
->parent
&& elt
->parent
->right
== elt
)
9383 if (elt
&& tree_int_cst_lt (constructor_unfilled_index
,
9386 next
= elt
->purpose
;
9392 else if (RECORD_OR_UNION_TYPE_P (constructor_type
))
9394 tree ctor_unfilled_bitpos
, elt_bitpos
;
9396 /* If the current record is complete we are done. */
9397 if (constructor_unfilled_fields
== NULL_TREE
)
9400 ctor_unfilled_bitpos
= bit_position (constructor_unfilled_fields
);
9401 elt_bitpos
= bit_position (elt
->purpose
);
9402 /* We can't compare fields here because there might be empty
9403 fields in between. */
9404 if (tree_int_cst_equal (elt_bitpos
, ctor_unfilled_bitpos
))
9406 constructor_unfilled_fields
= elt
->purpose
;
9407 output_init_element (input_location
, elt
->value
, elt
->origtype
,
9408 true, TREE_TYPE (elt
->purpose
),
9409 elt
->purpose
, false, false,
9410 braced_init_obstack
);
9412 else if (tree_int_cst_lt (ctor_unfilled_bitpos
, elt_bitpos
))
9414 /* Advance to the next smaller node. */
9419 /* We have reached the smallest node bigger than the
9420 current unfilled field. Fill the space first. */
9421 next
= elt
->purpose
;
9427 /* Advance to the next bigger node. */
9432 /* We have reached the biggest node in a subtree. Find
9433 the parent of it, which is the next bigger node. */
9434 while (elt
->parent
&& elt
->parent
->right
== elt
)
9438 && (tree_int_cst_lt (ctor_unfilled_bitpos
,
9439 bit_position (elt
->purpose
))))
9441 next
= elt
->purpose
;
9449 /* Ordinarily return, but not if we want to output all
9450 and there are elements left. */
9451 if (!(all
&& next
!= NULL_TREE
))
9454 /* If it's not incremental, just skip over the gap, so that after
9455 jumping to retry we will output the next successive element. */
9456 if (RECORD_OR_UNION_TYPE_P (constructor_type
))
9457 constructor_unfilled_fields
= next
;
9458 else if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
9459 constructor_unfilled_index
= next
;
9461 /* ELT now points to the node in the pending tree with the next
9462 initializer to output. */
9466 /* Add one non-braced element to the current constructor level.
9467 This adjusts the current position within the constructor's type.
9468 This may also start or terminate implicit levels
9469 to handle a partly-braced initializer.
9471 Once this has found the correct level for the new element,
9472 it calls output_init_element.
9474 IMPLICIT is true if value comes from pop_init_level (1),
9475 the new initializer has been merged with the existing one
9476 and thus no warnings should be emitted about overriding an
9477 existing initializer. */
9480 process_init_element (location_t loc
, struct c_expr value
, bool implicit
,
9481 struct obstack
* braced_init_obstack
)
9483 tree orig_value
= value
.value
;
9485 = (orig_value
!= NULL_TREE
&& TREE_CODE (orig_value
) == STRING_CST
);
9486 bool strict_string
= value
.original_code
== STRING_CST
;
9487 bool was_designated
= designator_depth
!= 0;
9489 designator_depth
= 0;
9490 designator_erroneous
= 0;
9492 if (!implicit
&& value
.value
&& !integer_zerop (value
.value
))
9493 constructor_zeroinit
= 0;
9495 /* Handle superfluous braces around string cst as in
9496 char x[] = {"foo"}; */
9500 && TREE_CODE (constructor_type
) == ARRAY_TYPE
9501 && INTEGRAL_TYPE_P (TREE_TYPE (constructor_type
))
9502 && integer_zerop (constructor_unfilled_index
))
9504 if (constructor_stack
->replacement_value
.value
)
9505 error_init (loc
, "excess elements in char array initializer");
9506 constructor_stack
->replacement_value
= value
;
9510 if (constructor_stack
->replacement_value
.value
!= NULL_TREE
)
9512 error_init (loc
, "excess elements in struct initializer");
9516 /* Ignore elements of a brace group if it is entirely superfluous
9517 and has already been diagnosed. */
9518 if (constructor_type
== NULL_TREE
)
9521 if (!implicit
&& warn_designated_init
&& !was_designated
9522 && TREE_CODE (constructor_type
) == RECORD_TYPE
9523 && lookup_attribute ("designated_init",
9524 TYPE_ATTRIBUTES (constructor_type
)))
9526 OPT_Wdesignated_init
,
9527 "positional initialization of field "
9528 "in %<struct%> declared with %<designated_init%> attribute");
9530 /* If we've exhausted any levels that didn't have braces,
9532 while (constructor_stack
->implicit
)
9534 if (RECORD_OR_UNION_TYPE_P (constructor_type
)
9535 && constructor_fields
== NULL_TREE
)
9536 process_init_element (loc
,
9537 pop_init_level (loc
, 1, braced_init_obstack
,
9538 last_init_list_comma
),
9539 true, braced_init_obstack
);
9540 else if ((TREE_CODE (constructor_type
) == ARRAY_TYPE
9541 || VECTOR_TYPE_P (constructor_type
))
9542 && constructor_max_index
9543 && tree_int_cst_lt (constructor_max_index
,
9545 process_init_element (loc
,
9546 pop_init_level (loc
, 1, braced_init_obstack
,
9547 last_init_list_comma
),
9548 true, braced_init_obstack
);
9553 /* In the case of [LO ... HI] = VALUE, only evaluate VALUE once. */
9554 if (constructor_range_stack
)
9556 /* If value is a compound literal and we'll be just using its
9557 content, don't put it into a SAVE_EXPR. */
9558 if (TREE_CODE (value
.value
) != COMPOUND_LITERAL_EXPR
9559 || !require_constant_value
)
9561 tree semantic_type
= NULL_TREE
;
9562 if (TREE_CODE (value
.value
) == EXCESS_PRECISION_EXPR
)
9564 semantic_type
= TREE_TYPE (value
.value
);
9565 value
.value
= TREE_OPERAND (value
.value
, 0);
9567 value
.value
= save_expr (value
.value
);
9569 value
.value
= build1 (EXCESS_PRECISION_EXPR
, semantic_type
,
9576 if (TREE_CODE (constructor_type
) == RECORD_TYPE
)
9579 enum tree_code fieldcode
;
9581 if (constructor_fields
== NULL_TREE
)
9583 pedwarn_init (loc
, 0, "excess elements in struct initializer");
9587 fieldtype
= TREE_TYPE (constructor_fields
);
9588 if (fieldtype
!= error_mark_node
)
9589 fieldtype
= TYPE_MAIN_VARIANT (fieldtype
);
9590 fieldcode
= TREE_CODE (fieldtype
);
9592 /* Error for non-static initialization of a flexible array member. */
9593 if (fieldcode
== ARRAY_TYPE
9594 && !require_constant_value
9595 && TYPE_SIZE (fieldtype
) == NULL_TREE
9596 && DECL_CHAIN (constructor_fields
) == NULL_TREE
)
9598 error_init (loc
, "non-static initialization of a flexible "
9603 /* Error for initialization of a flexible array member with
9604 a string constant if the structure is in an array. E.g.:
9605 struct S { int x; char y[]; };
9606 struct S s[] = { { 1, "foo" } };
9609 && fieldcode
== ARRAY_TYPE
9610 && constructor_depth
> 1
9611 && TYPE_SIZE (fieldtype
) == NULL_TREE
9612 && DECL_CHAIN (constructor_fields
) == NULL_TREE
)
9614 bool in_array_p
= false;
9615 for (struct constructor_stack
*p
= constructor_stack
;
9616 p
&& p
->type
; p
= p
->next
)
9617 if (TREE_CODE (p
->type
) == ARRAY_TYPE
)
9624 error_init (loc
, "initialization of flexible array "
9625 "member in a nested context");
9630 /* Accept a string constant to initialize a subarray. */
9631 if (value
.value
!= NULL_TREE
9632 && fieldcode
== ARRAY_TYPE
9633 && INTEGRAL_TYPE_P (TREE_TYPE (fieldtype
))
9635 value
.value
= orig_value
;
9636 /* Otherwise, if we have come to a subaggregate,
9637 and we don't have an element of its type, push into it. */
9638 else if (value
.value
!= NULL_TREE
9639 && value
.value
!= error_mark_node
9640 && TYPE_MAIN_VARIANT (TREE_TYPE (value
.value
)) != fieldtype
9641 && (fieldcode
== RECORD_TYPE
|| fieldcode
== ARRAY_TYPE
9642 || fieldcode
== UNION_TYPE
|| fieldcode
== VECTOR_TYPE
))
9644 push_init_level (loc
, 1, braced_init_obstack
);
9650 push_member_name (constructor_fields
);
9651 output_init_element (loc
, value
.value
, value
.original_type
,
9652 strict_string
, fieldtype
,
9653 constructor_fields
, true, implicit
,
9654 braced_init_obstack
);
9655 RESTORE_SPELLING_DEPTH (constructor_depth
);
9658 /* Do the bookkeeping for an element that was
9659 directly output as a constructor. */
9661 /* For a record, keep track of end position of last field. */
9662 if (DECL_SIZE (constructor_fields
))
9663 constructor_bit_index
9664 = size_binop_loc (input_location
, PLUS_EXPR
,
9665 bit_position (constructor_fields
),
9666 DECL_SIZE (constructor_fields
));
9668 /* If the current field was the first one not yet written out,
9669 it isn't now, so update. */
9670 if (constructor_unfilled_fields
== constructor_fields
)
9672 constructor_unfilled_fields
= DECL_CHAIN (constructor_fields
);
9673 /* Skip any nameless bit fields. */
9674 while (constructor_unfilled_fields
!= 0
9675 && (DECL_UNNAMED_BIT_FIELD
9676 (constructor_unfilled_fields
)))
9677 constructor_unfilled_fields
=
9678 DECL_CHAIN (constructor_unfilled_fields
);
9682 constructor_fields
= DECL_CHAIN (constructor_fields
);
9683 /* Skip any nameless bit fields at the beginning. */
9684 while (constructor_fields
!= NULL_TREE
9685 && DECL_UNNAMED_BIT_FIELD (constructor_fields
))
9686 constructor_fields
= DECL_CHAIN (constructor_fields
);
9688 else if (TREE_CODE (constructor_type
) == UNION_TYPE
)
9691 enum tree_code fieldcode
;
9693 if (constructor_fields
== NULL_TREE
)
9695 pedwarn_init (loc
, 0,
9696 "excess elements in union initializer");
9700 fieldtype
= TREE_TYPE (constructor_fields
);
9701 if (fieldtype
!= error_mark_node
)
9702 fieldtype
= TYPE_MAIN_VARIANT (fieldtype
);
9703 fieldcode
= TREE_CODE (fieldtype
);
9705 /* Warn that traditional C rejects initialization of unions.
9706 We skip the warning if the value is zero. This is done
9707 under the assumption that the zero initializer in user
9708 code appears conditioned on e.g. __STDC__ to avoid
9709 "missing initializer" warnings and relies on default
9710 initialization to zero in the traditional C case.
9711 We also skip the warning if the initializer is designated,
9712 again on the assumption that this must be conditional on
9713 __STDC__ anyway (and we've already complained about the
9714 member-designator already). */
9715 if (!in_system_header_at (input_location
) && !constructor_designated
9716 && !(value
.value
&& (integer_zerop (value
.value
)
9717 || real_zerop (value
.value
))))
9718 warning (OPT_Wtraditional
, "traditional C rejects initialization "
9721 /* Accept a string constant to initialize a subarray. */
9722 if (value
.value
!= NULL_TREE
9723 && fieldcode
== ARRAY_TYPE
9724 && INTEGRAL_TYPE_P (TREE_TYPE (fieldtype
))
9726 value
.value
= orig_value
;
9727 /* Otherwise, if we have come to a subaggregate,
9728 and we don't have an element of its type, push into it. */
9729 else if (value
.value
!= NULL_TREE
9730 && value
.value
!= error_mark_node
9731 && TYPE_MAIN_VARIANT (TREE_TYPE (value
.value
)) != fieldtype
9732 && (fieldcode
== RECORD_TYPE
|| fieldcode
== ARRAY_TYPE
9733 || fieldcode
== UNION_TYPE
|| fieldcode
== VECTOR_TYPE
))
9735 push_init_level (loc
, 1, braced_init_obstack
);
9741 push_member_name (constructor_fields
);
9742 output_init_element (loc
, value
.value
, value
.original_type
,
9743 strict_string
, fieldtype
,
9744 constructor_fields
, true, implicit
,
9745 braced_init_obstack
);
9746 RESTORE_SPELLING_DEPTH (constructor_depth
);
9749 /* Do the bookkeeping for an element that was
9750 directly output as a constructor. */
9752 constructor_bit_index
= DECL_SIZE (constructor_fields
);
9753 constructor_unfilled_fields
= DECL_CHAIN (constructor_fields
);
9756 constructor_fields
= NULL_TREE
;
9758 else if (TREE_CODE (constructor_type
) == ARRAY_TYPE
)
9760 tree elttype
= TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type
));
9761 enum tree_code eltcode
= TREE_CODE (elttype
);
9763 /* Accept a string constant to initialize a subarray. */
9764 if (value
.value
!= NULL_TREE
9765 && eltcode
== ARRAY_TYPE
9766 && INTEGRAL_TYPE_P (TREE_TYPE (elttype
))
9768 value
.value
= orig_value
;
9769 /* Otherwise, if we have come to a subaggregate,
9770 and we don't have an element of its type, push into it. */
9771 else if (value
.value
!= NULL_TREE
9772 && value
.value
!= error_mark_node
9773 && TYPE_MAIN_VARIANT (TREE_TYPE (value
.value
)) != elttype
9774 && (eltcode
== RECORD_TYPE
|| eltcode
== ARRAY_TYPE
9775 || eltcode
== UNION_TYPE
|| eltcode
== VECTOR_TYPE
))
9777 push_init_level (loc
, 1, braced_init_obstack
);
9781 if (constructor_max_index
!= NULL_TREE
9782 && (tree_int_cst_lt (constructor_max_index
, constructor_index
)
9783 || integer_all_onesp (constructor_max_index
)))
9785 pedwarn_init (loc
, 0,
9786 "excess elements in array initializer");
9790 /* Now output the actual element. */
9793 push_array_bounds (tree_to_uhwi (constructor_index
));
9794 output_init_element (loc
, value
.value
, value
.original_type
,
9795 strict_string
, elttype
,
9796 constructor_index
, true, implicit
,
9797 braced_init_obstack
);
9798 RESTORE_SPELLING_DEPTH (constructor_depth
);
9802 = size_binop_loc (input_location
, PLUS_EXPR
,
9803 constructor_index
, bitsize_one_node
);
9806 /* If we are doing the bookkeeping for an element that was
9807 directly output as a constructor, we must update
9808 constructor_unfilled_index. */
9809 constructor_unfilled_index
= constructor_index
;
9811 else if (VECTOR_TYPE_P (constructor_type
))
9813 tree elttype
= TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type
));
9815 /* Do a basic check of initializer size. Note that vectors
9816 always have a fixed size derived from their type. */
9817 if (tree_int_cst_lt (constructor_max_index
, constructor_index
))
9819 pedwarn_init (loc
, 0,
9820 "excess elements in vector initializer");
9824 /* Now output the actual element. */
9827 if (TREE_CODE (value
.value
) == VECTOR_CST
)
9828 elttype
= TYPE_MAIN_VARIANT (constructor_type
);
9829 output_init_element (loc
, value
.value
, value
.original_type
,
9830 strict_string
, elttype
,
9831 constructor_index
, true, implicit
,
9832 braced_init_obstack
);
9836 = size_binop_loc (input_location
,
9837 PLUS_EXPR
, constructor_index
, bitsize_one_node
);
9840 /* If we are doing the bookkeeping for an element that was
9841 directly output as a constructor, we must update
9842 constructor_unfilled_index. */
9843 constructor_unfilled_index
= constructor_index
;
9846 /* Handle the sole element allowed in a braced initializer
9847 for a scalar variable. */
9848 else if (constructor_type
!= error_mark_node
9849 && constructor_fields
== NULL_TREE
)
9851 pedwarn_init (loc
, 0,
9852 "excess elements in scalar initializer");
9858 output_init_element (loc
, value
.value
, value
.original_type
,
9859 strict_string
, constructor_type
,
9860 NULL_TREE
, true, implicit
,
9861 braced_init_obstack
);
9862 constructor_fields
= NULL_TREE
;
9865 /* Handle range initializers either at this level or anywhere higher
9866 in the designator stack. */
9867 if (constructor_range_stack
)
9869 struct constructor_range_stack
*p
, *range_stack
;
9872 range_stack
= constructor_range_stack
;
9873 constructor_range_stack
= 0;
9874 while (constructor_stack
!= range_stack
->stack
)
9876 gcc_assert (constructor_stack
->implicit
);
9877 process_init_element (loc
,
9878 pop_init_level (loc
, 1,
9879 braced_init_obstack
,
9880 last_init_list_comma
),
9881 true, braced_init_obstack
);
9883 for (p
= range_stack
;
9884 !p
->range_end
|| tree_int_cst_equal (p
->index
, p
->range_end
);
9887 gcc_assert (constructor_stack
->implicit
);
9888 process_init_element (loc
,
9889 pop_init_level (loc
, 1,
9890 braced_init_obstack
,
9891 last_init_list_comma
),
9892 true, braced_init_obstack
);
9895 p
->index
= size_binop_loc (input_location
,
9896 PLUS_EXPR
, p
->index
, bitsize_one_node
);
9897 if (tree_int_cst_equal (p
->index
, p
->range_end
) && !p
->prev
)
9902 constructor_index
= p
->index
;
9903 constructor_fields
= p
->fields
;
9904 if (finish
&& p
->range_end
&& p
->index
== p
->range_start
)
9912 finish_implicit_inits (loc
, braced_init_obstack
);
9913 push_init_level (loc
, 2, braced_init_obstack
);
9914 p
->stack
= constructor_stack
;
9915 if (p
->range_end
&& tree_int_cst_equal (p
->index
, p
->range_end
))
9916 p
->index
= p
->range_start
;
9920 constructor_range_stack
= range_stack
;
9927 constructor_range_stack
= 0;
9930 /* Build a complete asm-statement, whose components are a CV_QUALIFIER
9931 (guaranteed to be 'volatile' or null) and ARGS (represented using
9932 an ASM_EXPR node). */
9934 build_asm_stmt (tree cv_qualifier
, tree args
)
9936 if (!ASM_VOLATILE_P (args
) && cv_qualifier
)
9937 ASM_VOLATILE_P (args
) = 1;
9938 return add_stmt (args
);
9941 /* Build an asm-expr, whose components are a STRING, some OUTPUTS,
9942 some INPUTS, and some CLOBBERS. The latter three may be NULL.
9943 SIMPLE indicates whether there was anything at all after the
9944 string in the asm expression -- asm("blah") and asm("blah" : )
9945 are subtly different. We use a ASM_EXPR node to represent this. */
9947 build_asm_expr (location_t loc
, tree string
, tree outputs
, tree inputs
,
9948 tree clobbers
, tree labels
, bool simple
)
9953 const char *constraint
;
9954 const char **oconstraints
;
9955 bool allows_mem
, allows_reg
, is_inout
;
9956 int ninputs
, noutputs
;
9958 ninputs
= list_length (inputs
);
9959 noutputs
= list_length (outputs
);
9960 oconstraints
= (const char **) alloca (noutputs
* sizeof (const char *));
9962 string
= resolve_asm_operand_names (string
, outputs
, inputs
, labels
);
9964 /* Remove output conversions that change the type but not the mode. */
9965 for (i
= 0, tail
= outputs
; tail
; ++i
, tail
= TREE_CHAIN (tail
))
9967 tree output
= TREE_VALUE (tail
);
9969 output
= c_fully_fold (output
, false, NULL
, true);
9971 /* ??? Really, this should not be here. Users should be using a
9972 proper lvalue, dammit. But there's a long history of using casts
9973 in the output operands. In cases like longlong.h, this becomes a
9974 primitive form of typechecking -- if the cast can be removed, then
9975 the output operand had a type of the proper width; otherwise we'll
9976 get an error. Gross, but ... */
9977 STRIP_NOPS (output
);
9979 if (!lvalue_or_else (loc
, output
, lv_asm
))
9980 output
= error_mark_node
;
9982 if (output
!= error_mark_node
9983 && (TREE_READONLY (output
)
9984 || TYPE_READONLY (TREE_TYPE (output
))
9985 || (RECORD_OR_UNION_TYPE_P (TREE_TYPE (output
))
9986 && C_TYPE_FIELDS_READONLY (TREE_TYPE (output
)))))
9987 readonly_error (loc
, output
, lv_asm
);
9989 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (tail
)));
9990 oconstraints
[i
] = constraint
;
9992 if (parse_output_constraint (&constraint
, i
, ninputs
, noutputs
,
9993 &allows_mem
, &allows_reg
, &is_inout
))
9995 /* If the operand is going to end up in memory,
9996 mark it addressable. */
9997 if (!allows_reg
&& !c_mark_addressable (output
))
9998 output
= error_mark_node
;
9999 if (!(!allows_reg
&& allows_mem
)
10000 && output
!= error_mark_node
10001 && VOID_TYPE_P (TREE_TYPE (output
)))
10003 error_at (loc
, "invalid use of void expression");
10004 output
= error_mark_node
;
10008 output
= error_mark_node
;
10010 TREE_VALUE (tail
) = output
;
10013 for (i
= 0, tail
= inputs
; tail
; ++i
, tail
= TREE_CHAIN (tail
))
10017 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (tail
)));
10018 input
= TREE_VALUE (tail
);
10020 if (parse_input_constraint (&constraint
, i
, ninputs
, noutputs
, 0,
10021 oconstraints
, &allows_mem
, &allows_reg
))
10023 /* If the operand is going to end up in memory,
10024 mark it addressable. */
10025 if (!allows_reg
&& allows_mem
)
10027 input
= c_fully_fold (input
, false, NULL
, true);
10029 /* Strip the nops as we allow this case. FIXME, this really
10030 should be rejected or made deprecated. */
10031 STRIP_NOPS (input
);
10032 if (!c_mark_addressable (input
))
10033 input
= error_mark_node
;
10037 struct c_expr expr
;
10038 memset (&expr
, 0, sizeof (expr
));
10039 expr
.value
= input
;
10040 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, false);
10041 input
= c_fully_fold (expr
.value
, false, NULL
);
10043 if (input
!= error_mark_node
&& VOID_TYPE_P (TREE_TYPE (input
)))
10045 error_at (loc
, "invalid use of void expression");
10046 input
= error_mark_node
;
10051 input
= error_mark_node
;
10053 TREE_VALUE (tail
) = input
;
10056 /* ASMs with labels cannot have outputs. This should have been
10057 enforced by the parser. */
10058 gcc_assert (outputs
== NULL
|| labels
== NULL
);
10060 args
= build_stmt (loc
, ASM_EXPR
, string
, outputs
, inputs
, clobbers
, labels
);
10062 /* asm statements without outputs, including simple ones, are treated
10064 ASM_INPUT_P (args
) = simple
;
10065 ASM_VOLATILE_P (args
) = (noutputs
== 0);
10070 /* Generate a goto statement to LABEL. LOC is the location of the
10074 c_finish_goto_label (location_t loc
, tree label
)
10076 tree decl
= lookup_label_for_goto (loc
, label
);
10079 TREE_USED (decl
) = 1;
10081 add_stmt (build_predict_expr (PRED_GOTO
, NOT_TAKEN
));
10082 tree t
= build1 (GOTO_EXPR
, void_type_node
, decl
);
10083 SET_EXPR_LOCATION (t
, loc
);
10084 return add_stmt (t
);
10088 /* Generate a computed goto statement to EXPR. LOC is the location of
10092 c_finish_goto_ptr (location_t loc
, tree expr
)
10095 pedwarn (loc
, OPT_Wpedantic
, "ISO C forbids %<goto *expr;%>");
10096 expr
= c_fully_fold (expr
, false, NULL
);
10097 expr
= convert (ptr_type_node
, expr
);
10098 t
= build1 (GOTO_EXPR
, void_type_node
, expr
);
10099 SET_EXPR_LOCATION (t
, loc
);
10100 return add_stmt (t
);
10103 /* Generate a C `return' statement. RETVAL is the expression for what
10104 to return, or a null pointer for `return;' with no value. LOC is
10105 the location of the return statement, or the location of the expression,
10106 if the statement has any. If ORIGTYPE is not NULL_TREE, it
10107 is the original type of RETVAL. */
10110 c_finish_return (location_t loc
, tree retval
, tree origtype
)
10112 tree valtype
= TREE_TYPE (TREE_TYPE (current_function_decl
)), ret_stmt
;
10113 bool no_warning
= false;
10116 /* Use the expansion point to handle cases such as returning NULL
10117 in a function returning void. */
10118 source_location xloc
= expansion_point_location_if_in_system_header (loc
);
10120 if (TREE_THIS_VOLATILE (current_function_decl
))
10121 warning_at (xloc
, 0,
10122 "function declared %<noreturn%> has a %<return%> statement");
10126 tree semantic_type
= NULL_TREE
;
10127 npc
= null_pointer_constant_p (retval
);
10128 if (TREE_CODE (retval
) == EXCESS_PRECISION_EXPR
)
10130 semantic_type
= TREE_TYPE (retval
);
10131 retval
= TREE_OPERAND (retval
, 0);
10133 retval
= c_fully_fold (retval
, false, NULL
);
10135 retval
= build1 (EXCESS_PRECISION_EXPR
, semantic_type
, retval
);
10140 current_function_returns_null
= 1;
10141 if ((warn_return_type
>= 0 || flag_isoc99
)
10142 && valtype
!= NULL_TREE
&& TREE_CODE (valtype
) != VOID_TYPE
)
10146 warned_here
= pedwarn
10147 (loc
, warn_return_type
>= 0 ? OPT_Wreturn_type
: 0,
10148 "%<return%> with no value, in function returning non-void");
10150 warned_here
= warning_at
10151 (loc
, OPT_Wreturn_type
,
10152 "%<return%> with no value, in function returning non-void");
10155 inform (DECL_SOURCE_LOCATION (current_function_decl
),
10159 else if (valtype
== NULL_TREE
|| TREE_CODE (valtype
) == VOID_TYPE
)
10161 current_function_returns_null
= 1;
10163 if (TREE_CODE (TREE_TYPE (retval
)) != VOID_TYPE
)
10164 warned_here
= pedwarn
10165 (xloc
, warn_return_type
>= 0 ? OPT_Wreturn_type
: 0,
10166 "%<return%> with a value, in function returning void");
10168 warned_here
= pedwarn
10169 (xloc
, OPT_Wpedantic
, "ISO C forbids "
10170 "%<return%> with expression, in function returning void");
10172 inform (DECL_SOURCE_LOCATION (current_function_decl
),
10177 tree t
= convert_for_assignment (loc
, UNKNOWN_LOCATION
, valtype
,
10178 retval
, origtype
, ic_return
,
10179 npc
, NULL_TREE
, NULL_TREE
, 0);
10180 tree res
= DECL_RESULT (current_function_decl
);
10184 current_function_returns_value
= 1;
10185 if (t
== error_mark_node
)
10188 save
= in_late_binary_op
;
10189 if (TREE_CODE (TREE_TYPE (res
)) == BOOLEAN_TYPE
10190 || TREE_CODE (TREE_TYPE (res
)) == COMPLEX_TYPE
10191 || (TREE_CODE (TREE_TYPE (t
)) == REAL_TYPE
10192 && (TREE_CODE (TREE_TYPE (res
)) == INTEGER_TYPE
10193 || TREE_CODE (TREE_TYPE (res
)) == ENUMERAL_TYPE
)
10194 && sanitize_flags_p (SANITIZE_FLOAT_CAST
)))
10195 in_late_binary_op
= true;
10196 inner
= t
= convert (TREE_TYPE (res
), t
);
10197 in_late_binary_op
= save
;
10199 /* Strip any conversions, additions, and subtractions, and see if
10200 we are returning the address of a local variable. Warn if so. */
10203 switch (TREE_CODE (inner
))
10206 case NON_LVALUE_EXPR
:
10208 case POINTER_PLUS_EXPR
:
10209 inner
= TREE_OPERAND (inner
, 0);
10213 /* If the second operand of the MINUS_EXPR has a pointer
10214 type (or is converted from it), this may be valid, so
10215 don't give a warning. */
10217 tree op1
= TREE_OPERAND (inner
, 1);
10219 while (!POINTER_TYPE_P (TREE_TYPE (op1
))
10220 && (CONVERT_EXPR_P (op1
)
10221 || TREE_CODE (op1
) == NON_LVALUE_EXPR
))
10222 op1
= TREE_OPERAND (op1
, 0);
10224 if (POINTER_TYPE_P (TREE_TYPE (op1
)))
10227 inner
= TREE_OPERAND (inner
, 0);
10232 inner
= TREE_OPERAND (inner
, 0);
10234 while (REFERENCE_CLASS_P (inner
)
10235 && !INDIRECT_REF_P (inner
))
10236 inner
= TREE_OPERAND (inner
, 0);
10239 && !DECL_EXTERNAL (inner
)
10240 && !TREE_STATIC (inner
)
10241 && DECL_CONTEXT (inner
) == current_function_decl
)
10243 if (TREE_CODE (inner
) == LABEL_DECL
)
10244 warning_at (loc
, OPT_Wreturn_local_addr
,
10245 "function returns address of label");
10248 warning_at (loc
, OPT_Wreturn_local_addr
,
10249 "function returns address of local variable");
10250 tree zero
= build_zero_cst (TREE_TYPE (res
));
10251 t
= build2 (COMPOUND_EXPR
, TREE_TYPE (res
), t
, zero
);
10263 retval
= build2 (MODIFY_EXPR
, TREE_TYPE (res
), res
, t
);
10264 SET_EXPR_LOCATION (retval
, loc
);
10266 if (warn_sequence_point
)
10267 verify_sequence_points (retval
);
10270 ret_stmt
= build_stmt (loc
, RETURN_EXPR
, retval
);
10271 TREE_NO_WARNING (ret_stmt
) |= no_warning
;
10272 return add_stmt (ret_stmt
);
10276 /* The SWITCH_EXPR being built. */
10279 /* The original type of the testing expression, i.e. before the
10280 default conversion is applied. */
10283 /* A splay-tree mapping the low element of a case range to the high
10284 element, or NULL_TREE if there is no high element. Used to
10285 determine whether or not a new case label duplicates an old case
10286 label. We need a tree, rather than simply a hash table, because
10287 of the GNU case range extension. */
10290 /* The bindings at the point of the switch. This is used for
10291 warnings crossing decls when branching to a case label. */
10292 struct c_spot_bindings
*bindings
;
10294 /* The next node on the stack. */
10295 struct c_switch
*next
;
10297 /* Remember whether the controlling expression had boolean type
10298 before integer promotions for the sake of -Wswitch-bool. */
10301 /* Remember whether there was a case value that is outside the
10302 range of the ORIG_TYPE. */
10303 bool outside_range_p
;
10306 /* A stack of the currently active switch statements. The innermost
10307 switch statement is on the top of the stack. There is no need to
10308 mark the stack for garbage collection because it is only active
10309 during the processing of the body of a function, and we never
10310 collect at that point. */
10312 struct c_switch
*c_switch_stack
;
10314 /* Start a C switch statement, testing expression EXP. Return the new
10315 SWITCH_EXPR. SWITCH_LOC is the location of the `switch'.
10316 SWITCH_COND_LOC is the location of the switch's condition.
10317 EXPLICIT_CAST_P is true if the expression EXP has an explicit cast. */
10320 c_start_case (location_t switch_loc
,
10321 location_t switch_cond_loc
,
10322 tree exp
, bool explicit_cast_p
)
10324 tree orig_type
= error_mark_node
;
10325 bool bool_cond_p
= false;
10326 struct c_switch
*cs
;
10328 if (exp
!= error_mark_node
)
10330 orig_type
= TREE_TYPE (exp
);
10332 if (!INTEGRAL_TYPE_P (orig_type
))
10334 if (orig_type
!= error_mark_node
)
10336 error_at (switch_cond_loc
, "switch quantity not an integer");
10337 orig_type
= error_mark_node
;
10339 exp
= integer_zero_node
;
10343 tree type
= TYPE_MAIN_VARIANT (orig_type
);
10346 /* Warn if the condition has boolean value. */
10347 while (TREE_CODE (e
) == COMPOUND_EXPR
)
10348 e
= TREE_OPERAND (e
, 1);
10350 if ((TREE_CODE (type
) == BOOLEAN_TYPE
10351 || truth_value_p (TREE_CODE (e
)))
10352 /* Explicit cast to int suppresses this warning. */
10353 && !(TREE_CODE (type
) == INTEGER_TYPE
10354 && explicit_cast_p
))
10355 bool_cond_p
= true;
10357 if (!in_system_header_at (input_location
)
10358 && (type
== long_integer_type_node
10359 || type
== long_unsigned_type_node
))
10360 warning_at (switch_cond_loc
,
10361 OPT_Wtraditional
, "%<long%> switch expression not "
10362 "converted to %<int%> in ISO C");
10364 exp
= c_fully_fold (exp
, false, NULL
);
10365 exp
= default_conversion (exp
);
10367 if (warn_sequence_point
)
10368 verify_sequence_points (exp
);
10372 /* Add this new SWITCH_EXPR to the stack. */
10373 cs
= XNEW (struct c_switch
);
10374 cs
->switch_expr
= build2 (SWITCH_EXPR
, orig_type
, exp
, NULL_TREE
);
10375 SET_EXPR_LOCATION (cs
->switch_expr
, switch_loc
);
10376 cs
->orig_type
= orig_type
;
10377 cs
->cases
= splay_tree_new (case_compare
, NULL
, NULL
);
10378 cs
->bindings
= c_get_switch_bindings ();
10379 cs
->bool_cond_p
= bool_cond_p
;
10380 cs
->outside_range_p
= false;
10381 cs
->next
= c_switch_stack
;
10382 c_switch_stack
= cs
;
10384 return add_stmt (cs
->switch_expr
);
10387 /* Process a case label at location LOC. */
10390 do_case (location_t loc
, tree low_value
, tree high_value
)
10392 tree label
= NULL_TREE
;
10394 if (low_value
&& TREE_CODE (low_value
) != INTEGER_CST
)
10396 low_value
= c_fully_fold (low_value
, false, NULL
);
10397 if (TREE_CODE (low_value
) == INTEGER_CST
)
10398 pedwarn (loc
, OPT_Wpedantic
,
10399 "case label is not an integer constant expression");
10402 if (high_value
&& TREE_CODE (high_value
) != INTEGER_CST
)
10404 high_value
= c_fully_fold (high_value
, false, NULL
);
10405 if (TREE_CODE (high_value
) == INTEGER_CST
)
10406 pedwarn (input_location
, OPT_Wpedantic
,
10407 "case label is not an integer constant expression");
10410 if (c_switch_stack
== NULL
)
10413 error_at (loc
, "case label not within a switch statement");
10415 error_at (loc
, "%<default%> label not within a switch statement");
10419 if (c_check_switch_jump_warnings (c_switch_stack
->bindings
,
10420 EXPR_LOCATION (c_switch_stack
->switch_expr
),
10424 label
= c_add_case_label (loc
, c_switch_stack
->cases
,
10425 SWITCH_COND (c_switch_stack
->switch_expr
),
10426 c_switch_stack
->orig_type
,
10427 low_value
, high_value
,
10428 &c_switch_stack
->outside_range_p
);
10429 if (label
== error_mark_node
)
10434 /* Finish the switch statement. TYPE is the original type of the
10435 controlling expression of the switch, or NULL_TREE. */
10438 c_finish_case (tree body
, tree type
)
10440 struct c_switch
*cs
= c_switch_stack
;
10441 location_t switch_location
;
10443 SWITCH_BODY (cs
->switch_expr
) = body
;
10445 /* Emit warnings as needed. */
10446 switch_location
= EXPR_LOCATION (cs
->switch_expr
);
10447 c_do_switch_warnings (cs
->cases
, switch_location
,
10448 type
? type
: TREE_TYPE (cs
->switch_expr
),
10449 SWITCH_COND (cs
->switch_expr
),
10450 cs
->bool_cond_p
, cs
->outside_range_p
);
10451 if (c_switch_covers_all_cases_p (cs
->cases
, TREE_TYPE (cs
->switch_expr
)))
10452 SWITCH_ALL_CASES_P (cs
->switch_expr
) = 1;
10454 /* Pop the stack. */
10455 c_switch_stack
= cs
->next
;
10456 splay_tree_delete (cs
->cases
);
10457 c_release_switch_bindings (cs
->bindings
);
10461 /* Emit an if statement. IF_LOCUS is the location of the 'if'. COND,
10462 THEN_BLOCK and ELSE_BLOCK are expressions to be used; ELSE_BLOCK
10466 c_finish_if_stmt (location_t if_locus
, tree cond
, tree then_block
,
10471 stmt
= build3 (COND_EXPR
, void_type_node
, cond
, then_block
, else_block
);
10472 SET_EXPR_LOCATION (stmt
, if_locus
);
10476 /* Emit a general-purpose loop construct. START_LOCUS is the location of
10477 the beginning of the loop. COND is the loop condition. COND_IS_FIRST
10478 is false for DO loops. INCR is the FOR increment expression. BODY is
10479 the statement controlled by the loop. BLAB is the break label. CLAB is
10480 the continue label. Everything is allowed to be NULL. */
10483 c_finish_loop (location_t start_locus
, tree cond
, tree incr
, tree body
,
10484 tree blab
, tree clab
, bool cond_is_first
)
10486 tree entry
= NULL
, exit
= NULL
, t
;
10488 /* If the condition is zero don't generate a loop construct. */
10489 if (cond
&& integer_zerop (cond
))
10493 t
= build_and_jump (&blab
);
10494 SET_EXPR_LOCATION (t
, start_locus
);
10500 tree top
= build1 (LABEL_EXPR
, void_type_node
, NULL_TREE
);
10502 /* If we have an exit condition, then we build an IF with gotos either
10503 out of the loop, or to the top of it. If there's no exit condition,
10504 then we just build a jump back to the top. */
10505 exit
= build_and_jump (&LABEL_EXPR_LABEL (top
));
10507 if (cond
&& !integer_nonzerop (cond
))
10509 /* Canonicalize the loop condition to the end. This means
10510 generating a branch to the loop condition. Reuse the
10511 continue label, if possible. */
10516 entry
= build1 (LABEL_EXPR
, void_type_node
, NULL_TREE
);
10517 t
= build_and_jump (&LABEL_EXPR_LABEL (entry
));
10520 t
= build1 (GOTO_EXPR
, void_type_node
, clab
);
10521 SET_EXPR_LOCATION (t
, start_locus
);
10525 t
= build_and_jump (&blab
);
10527 exit
= fold_build3_loc (start_locus
,
10528 COND_EXPR
, void_type_node
, cond
, exit
, t
);
10530 exit
= fold_build3_loc (input_location
,
10531 COND_EXPR
, void_type_node
, cond
, exit
, t
);
10535 /* For the backward-goto's location of an unconditional loop
10536 use the beginning of the body, or, if there is none, the
10537 top of the loop. */
10538 location_t loc
= EXPR_LOCATION (expr_first (body
));
10539 if (loc
== UNKNOWN_LOCATION
)
10541 SET_EXPR_LOCATION (exit
, loc
);
10550 add_stmt (build1 (LABEL_EXPR
, void_type_node
, clab
));
10558 add_stmt (build1 (LABEL_EXPR
, void_type_node
, blab
));
10562 c_finish_bc_stmt (location_t loc
, tree
*label_p
, bool is_break
)
10565 tree label
= *label_p
;
10567 /* In switch statements break is sometimes stylistically used after
10568 a return statement. This can lead to spurious warnings about
10569 control reaching the end of a non-void function when it is
10570 inlined. Note that we are calling block_may_fallthru with
10571 language specific tree nodes; this works because
10572 block_may_fallthru returns true when given something it does not
10574 skip
= !block_may_fallthru (cur_stmt_list
);
10579 *label_p
= label
= create_artificial_label (loc
);
10581 else if (TREE_CODE (label
) == LABEL_DECL
)
10583 else switch (TREE_INT_CST_LOW (label
))
10587 error_at (loc
, "break statement not within loop or switch");
10589 error_at (loc
, "continue statement not within a loop");
10593 gcc_assert (is_break
);
10594 error_at (loc
, "break statement used with OpenMP for loop");
10599 error ("break statement within %<#pragma simd%> loop body");
10601 error ("continue statement within %<#pragma simd%> loop body");
10605 gcc_unreachable ();
10612 add_stmt (build_predict_expr (PRED_CONTINUE
, NOT_TAKEN
));
10614 return add_stmt (build1 (GOTO_EXPR
, void_type_node
, label
));
10617 /* A helper routine for c_process_expr_stmt and c_finish_stmt_expr. */
10620 emit_side_effect_warnings (location_t loc
, tree expr
)
10622 if (expr
== error_mark_node
)
10624 else if (!TREE_SIDE_EFFECTS (expr
))
10626 if (!VOID_TYPE_P (TREE_TYPE (expr
)) && !TREE_NO_WARNING (expr
))
10627 warning_at (loc
, OPT_Wunused_value
, "statement with no effect");
10629 else if (TREE_CODE (expr
) == COMPOUND_EXPR
)
10632 location_t cloc
= loc
;
10633 while (TREE_CODE (r
) == COMPOUND_EXPR
)
10635 if (EXPR_HAS_LOCATION (r
))
10636 cloc
= EXPR_LOCATION (r
);
10637 r
= TREE_OPERAND (r
, 1);
10639 if (!TREE_SIDE_EFFECTS (r
)
10640 && !VOID_TYPE_P (TREE_TYPE (r
))
10641 && !CONVERT_EXPR_P (r
)
10642 && !TREE_NO_WARNING (r
)
10643 && !TREE_NO_WARNING (expr
))
10644 warning_at (cloc
, OPT_Wunused_value
,
10645 "right-hand operand of comma expression has no effect");
10648 warn_if_unused_value (expr
, loc
);
10651 /* Process an expression as if it were a complete statement. Emit
10652 diagnostics, but do not call ADD_STMT. LOC is the location of the
10656 c_process_expr_stmt (location_t loc
, tree expr
)
10663 expr
= c_fully_fold (expr
, false, NULL
);
10665 if (warn_sequence_point
)
10666 verify_sequence_points (expr
);
10668 if (TREE_TYPE (expr
) != error_mark_node
10669 && !COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (expr
))
10670 && TREE_CODE (TREE_TYPE (expr
)) != ARRAY_TYPE
)
10671 error_at (loc
, "expression statement has incomplete type");
10673 /* If we're not processing a statement expression, warn about unused values.
10674 Warnings for statement expressions will be emitted later, once we figure
10675 out which is the result. */
10676 if (!STATEMENT_LIST_STMT_EXPR (cur_stmt_list
)
10677 && warn_unused_value
)
10678 emit_side_effect_warnings (EXPR_LOC_OR_LOC (expr
, loc
), expr
);
10681 while (TREE_CODE (exprv
) == COMPOUND_EXPR
)
10682 exprv
= TREE_OPERAND (exprv
, 1);
10683 while (CONVERT_EXPR_P (exprv
))
10684 exprv
= TREE_OPERAND (exprv
, 0);
10686 || handled_component_p (exprv
)
10687 || TREE_CODE (exprv
) == ADDR_EXPR
)
10688 mark_exp_read (exprv
);
10690 /* If the expression is not of a type to which we cannot assign a line
10691 number, wrap the thing in a no-op NOP_EXPR. */
10692 if (DECL_P (expr
) || CONSTANT_CLASS_P (expr
))
10694 expr
= build1 (NOP_EXPR
, TREE_TYPE (expr
), expr
);
10695 SET_EXPR_LOCATION (expr
, loc
);
10701 /* Emit an expression as a statement. LOC is the location of the
10705 c_finish_expr_stmt (location_t loc
, tree expr
)
10708 return add_stmt (c_process_expr_stmt (loc
, expr
));
10713 /* Do the opposite and emit a statement as an expression. To begin,
10714 create a new binding level and return it. */
10717 c_begin_stmt_expr (void)
10721 /* We must force a BLOCK for this level so that, if it is not expanded
10722 later, there is a way to turn off the entire subtree of blocks that
10723 are contained in it. */
10724 keep_next_level ();
10725 ret
= c_begin_compound_stmt (true);
10727 c_bindings_start_stmt_expr (c_switch_stack
== NULL
10729 : c_switch_stack
->bindings
);
10731 /* Mark the current statement list as belonging to a statement list. */
10732 STATEMENT_LIST_STMT_EXPR (ret
) = 1;
10737 /* LOC is the location of the compound statement to which this body
10741 c_finish_stmt_expr (location_t loc
, tree body
)
10743 tree last
, type
, tmp
, val
;
10746 body
= c_end_compound_stmt (loc
, body
, true);
10748 c_bindings_end_stmt_expr (c_switch_stack
== NULL
10750 : c_switch_stack
->bindings
);
10752 /* Locate the last statement in BODY. See c_end_compound_stmt
10753 about always returning a BIND_EXPR. */
10754 last_p
= &BIND_EXPR_BODY (body
);
10755 last
= BIND_EXPR_BODY (body
);
10757 continue_searching
:
10758 if (TREE_CODE (last
) == STATEMENT_LIST
)
10760 tree_stmt_iterator l
= tsi_last (last
);
10762 while (!tsi_end_p (l
) && TREE_CODE (tsi_stmt (l
)) == DEBUG_BEGIN_STMT
)
10765 /* This can happen with degenerate cases like ({ }). No value. */
10769 /* If we're supposed to generate side effects warnings, process
10770 all of the statements except the last. */
10771 if (warn_unused_value
)
10773 for (tree_stmt_iterator i
= tsi_start (last
);
10774 tsi_stmt (i
) != tsi_stmt (l
); tsi_next (&i
))
10777 tree t
= tsi_stmt (i
);
10779 tloc
= EXPR_HAS_LOCATION (t
) ? EXPR_LOCATION (t
) : loc
;
10780 emit_side_effect_warnings (tloc
, t
);
10783 last_p
= tsi_stmt_ptr (l
);
10787 /* If the end of the list is exception related, then the list was split
10788 by a call to push_cleanup. Continue searching. */
10789 if (TREE_CODE (last
) == TRY_FINALLY_EXPR
10790 || TREE_CODE (last
) == TRY_CATCH_EXPR
)
10792 last_p
= &TREE_OPERAND (last
, 0);
10794 goto continue_searching
;
10797 if (last
== error_mark_node
)
10800 /* In the case that the BIND_EXPR is not necessary, return the
10801 expression out from inside it. */
10802 if ((last
== BIND_EXPR_BODY (body
)
10803 /* Skip nested debug stmts. */
10804 || last
== expr_first (BIND_EXPR_BODY (body
)))
10805 && BIND_EXPR_VARS (body
) == NULL
)
10807 /* Even if this looks constant, do not allow it in a constant
10809 last
= c_wrap_maybe_const (last
, true);
10810 /* Do not warn if the return value of a statement expression is
10812 TREE_NO_WARNING (last
) = 1;
10816 /* Extract the type of said expression. */
10817 type
= TREE_TYPE (last
);
10819 /* If we're not returning a value at all, then the BIND_EXPR that
10820 we already have is a fine expression to return. */
10821 if (!type
|| VOID_TYPE_P (type
))
10824 /* Now that we've located the expression containing the value, it seems
10825 silly to make voidify_wrapper_expr repeat the process. Create a
10826 temporary of the appropriate type and stick it in a TARGET_EXPR. */
10827 tmp
= create_tmp_var_raw (type
);
10829 /* Unwrap a no-op NOP_EXPR as added by c_finish_expr_stmt. This avoids
10830 tree_expr_nonnegative_p giving up immediately. */
10832 if (TREE_CODE (val
) == NOP_EXPR
10833 && TREE_TYPE (val
) == TREE_TYPE (TREE_OPERAND (val
, 0)))
10834 val
= TREE_OPERAND (val
, 0);
10836 *last_p
= build2 (MODIFY_EXPR
, void_type_node
, tmp
, val
);
10837 SET_EXPR_LOCATION (*last_p
, EXPR_LOCATION (last
));
10840 tree t
= build4 (TARGET_EXPR
, type
, tmp
, body
, NULL_TREE
, NULL_TREE
);
10841 SET_EXPR_LOCATION (t
, loc
);
10846 /* Begin and end compound statements. This is as simple as pushing
10847 and popping new statement lists from the tree. */
10850 c_begin_compound_stmt (bool do_scope
)
10852 tree stmt
= push_stmt_list ();
10858 /* End a compound statement. STMT is the statement. LOC is the
10859 location of the compound statement-- this is usually the location
10860 of the opening brace. */
10863 c_end_compound_stmt (location_t loc
, tree stmt
, bool do_scope
)
10869 if (c_dialect_objc ())
10870 objc_clear_super_receiver ();
10871 block
= pop_scope ();
10874 stmt
= pop_stmt_list (stmt
);
10875 stmt
= c_build_bind_expr (loc
, block
, stmt
);
10877 /* If this compound statement is nested immediately inside a statement
10878 expression, then force a BIND_EXPR to be created. Otherwise we'll
10879 do the wrong thing for ({ { 1; } }) or ({ 1; { } }). In particular,
10880 STATEMENT_LISTs merge, and thus we can lose track of what statement
10881 was really last. */
10882 if (building_stmt_list_p ()
10883 && STATEMENT_LIST_STMT_EXPR (cur_stmt_list
)
10884 && TREE_CODE (stmt
) != BIND_EXPR
)
10886 stmt
= build3 (BIND_EXPR
, void_type_node
, NULL
, stmt
, NULL
);
10887 TREE_SIDE_EFFECTS (stmt
) = 1;
10888 SET_EXPR_LOCATION (stmt
, loc
);
10894 /* Queue a cleanup. CLEANUP is an expression/statement to be executed
10895 when the current scope is exited. EH_ONLY is true when this is not
10896 meant to apply to normal control flow transfer. */
10899 push_cleanup (tree decl
, tree cleanup
, bool eh_only
)
10901 enum tree_code code
;
10905 code
= eh_only
? TRY_CATCH_EXPR
: TRY_FINALLY_EXPR
;
10906 stmt
= build_stmt (DECL_SOURCE_LOCATION (decl
), code
, NULL
, cleanup
);
10908 stmt_expr
= STATEMENT_LIST_STMT_EXPR (cur_stmt_list
);
10909 list
= push_stmt_list ();
10910 TREE_OPERAND (stmt
, 0) = list
;
10911 STATEMENT_LIST_STMT_EXPR (list
) = stmt_expr
;
10914 /* Build a vector comparison of ARG0 and ARG1 using CODE opcode
10915 into a value of TYPE type. Comparison is done via VEC_COND_EXPR. */
10918 build_vec_cmp (tree_code code
, tree type
,
10919 tree arg0
, tree arg1
)
10921 tree zero_vec
= build_zero_cst (type
);
10922 tree minus_one_vec
= build_minus_one_cst (type
);
10923 tree cmp_type
= build_same_sized_truth_vector_type (type
);
10924 tree cmp
= build2 (code
, cmp_type
, arg0
, arg1
);
10925 return build3 (VEC_COND_EXPR
, type
, cmp
, minus_one_vec
, zero_vec
);
10928 /* Build a binary-operation expression without default conversions.
10929 CODE is the kind of expression to build.
10930 LOCATION is the operator's location.
10931 This function differs from `build' in several ways:
10932 the data type of the result is computed and recorded in it,
10933 warnings are generated if arg data types are invalid,
10934 special handling for addition and subtraction of pointers is known,
10935 and some optimization is done (operations on narrow ints
10936 are done in the narrower type when that gives the same result).
10937 Constant folding is also done before the result is returned.
10939 Note that the operands will never have enumeral types, or function
10940 or array types, because either they will have the default conversions
10941 performed or they have both just been converted to some other type in which
10942 the arithmetic is to be done. */
10945 build_binary_op (location_t location
, enum tree_code code
,
10946 tree orig_op0
, tree orig_op1
, bool convert_p
)
10948 tree type0
, type1
, orig_type0
, orig_type1
;
10950 enum tree_code code0
, code1
;
10952 tree ret
= error_mark_node
;
10953 const char *invalid_op_diag
;
10954 bool op0_int_operands
, op1_int_operands
;
10955 bool int_const
, int_const_or_overflow
, int_operands
;
10957 /* Expression code to give to the expression when it is built.
10958 Normally this is CODE, which is what the caller asked for,
10959 but in some special cases we change it. */
10960 enum tree_code resultcode
= code
;
10962 /* Data type in which the computation is to be performed.
10963 In the simplest cases this is the common type of the arguments. */
10964 tree result_type
= NULL
;
10966 /* When the computation is in excess precision, the type of the
10967 final EXCESS_PRECISION_EXPR. */
10968 tree semantic_result_type
= NULL
;
10970 /* Nonzero means operands have already been type-converted
10971 in whatever way is necessary.
10972 Zero means they need to be converted to RESULT_TYPE. */
10975 /* Nonzero means create the expression with this type, rather than
10977 tree build_type
= NULL_TREE
;
10979 /* Nonzero means after finally constructing the expression
10980 convert it to this type. */
10981 tree final_type
= NULL_TREE
;
10983 /* Nonzero if this is an operation like MIN or MAX which can
10984 safely be computed in short if both args are promoted shorts.
10985 Also implies COMMON.
10986 -1 indicates a bitwise operation; this makes a difference
10987 in the exact conditions for when it is safe to do the operation
10988 in a narrower mode. */
10991 /* Nonzero if this is a comparison operation;
10992 if both args are promoted shorts, compare the original shorts.
10993 Also implies COMMON. */
10994 int short_compare
= 0;
10996 /* Nonzero if this is a right-shift operation, which can be computed on the
10997 original short and then promoted if the operand is a promoted short. */
10998 int short_shift
= 0;
11000 /* Nonzero means set RESULT_TYPE to the common type of the args. */
11003 /* True means types are compatible as far as ObjC is concerned. */
11006 /* True means this is an arithmetic operation that may need excess
11008 bool may_need_excess_precision
;
11010 /* True means this is a boolean operation that converts both its
11011 operands to truth-values. */
11012 bool boolean_op
= false;
11014 /* Remember whether we're doing / or %. */
11015 bool doing_div_or_mod
= false;
11017 /* Remember whether we're doing << or >>. */
11018 bool doing_shift
= false;
11020 /* Tree holding instrumentation expression. */
11021 tree instrument_expr
= NULL
;
11023 if (location
== UNKNOWN_LOCATION
)
11024 location
= input_location
;
11029 op0_int_operands
= EXPR_INT_CONST_OPERANDS (orig_op0
);
11030 if (op0_int_operands
)
11031 op0
= remove_c_maybe_const_expr (op0
);
11032 op1_int_operands
= EXPR_INT_CONST_OPERANDS (orig_op1
);
11033 if (op1_int_operands
)
11034 op1
= remove_c_maybe_const_expr (op1
);
11035 int_operands
= (op0_int_operands
&& op1_int_operands
);
11038 int_const_or_overflow
= (TREE_CODE (orig_op0
) == INTEGER_CST
11039 && TREE_CODE (orig_op1
) == INTEGER_CST
);
11040 int_const
= (int_const_or_overflow
11041 && !TREE_OVERFLOW (orig_op0
)
11042 && !TREE_OVERFLOW (orig_op1
));
11045 int_const
= int_const_or_overflow
= false;
11047 /* Do not apply default conversion in mixed vector/scalar expression. */
11049 && VECTOR_TYPE_P (TREE_TYPE (op0
)) == VECTOR_TYPE_P (TREE_TYPE (op1
)))
11051 op0
= default_conversion (op0
);
11052 op1
= default_conversion (op1
);
11055 orig_type0
= type0
= TREE_TYPE (op0
);
11057 orig_type1
= type1
= TREE_TYPE (op1
);
11059 /* The expression codes of the data types of the arguments tell us
11060 whether the arguments are integers, floating, pointers, etc. */
11061 code0
= TREE_CODE (type0
);
11062 code1
= TREE_CODE (type1
);
11064 /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
11065 STRIP_TYPE_NOPS (op0
);
11066 STRIP_TYPE_NOPS (op1
);
11068 /* If an error was already reported for one of the arguments,
11069 avoid reporting another error. */
11071 if (code0
== ERROR_MARK
|| code1
== ERROR_MARK
)
11072 return error_mark_node
;
11074 if (code0
== POINTER_TYPE
11075 && reject_gcc_builtin (op0
, EXPR_LOCATION (orig_op0
)))
11076 return error_mark_node
;
11078 if (code1
== POINTER_TYPE
11079 && reject_gcc_builtin (op1
, EXPR_LOCATION (orig_op1
)))
11080 return error_mark_node
;
11082 if ((invalid_op_diag
11083 = targetm
.invalid_binary_op (code
, type0
, type1
)))
11085 error_at (location
, invalid_op_diag
);
11086 return error_mark_node
;
11094 case TRUNC_DIV_EXPR
:
11095 case CEIL_DIV_EXPR
:
11096 case FLOOR_DIV_EXPR
:
11097 case ROUND_DIV_EXPR
:
11098 case EXACT_DIV_EXPR
:
11099 may_need_excess_precision
= true;
11102 may_need_excess_precision
= false;
11105 if (TREE_CODE (op0
) == EXCESS_PRECISION_EXPR
)
11107 op0
= TREE_OPERAND (op0
, 0);
11108 type0
= TREE_TYPE (op0
);
11110 else if (may_need_excess_precision
11111 && (eptype
= excess_precision_type (type0
)) != NULL_TREE
)
11114 op0
= convert (eptype
, op0
);
11116 if (TREE_CODE (op1
) == EXCESS_PRECISION_EXPR
)
11118 op1
= TREE_OPERAND (op1
, 0);
11119 type1
= TREE_TYPE (op1
);
11121 else if (may_need_excess_precision
11122 && (eptype
= excess_precision_type (type1
)) != NULL_TREE
)
11125 op1
= convert (eptype
, op1
);
11128 objc_ok
= objc_compare_types (type0
, type1
, -3, NULL_TREE
);
11130 /* In case when one of the operands of the binary operation is
11131 a vector and another is a scalar -- convert scalar to vector. */
11132 if ((code0
== VECTOR_TYPE
) != (code1
== VECTOR_TYPE
))
11134 enum stv_conv convert_flag
= scalar_to_vector (location
, code
, op0
, op1
,
11137 switch (convert_flag
)
11140 return error_mark_node
;
11143 bool maybe_const
= true;
11145 sc
= c_fully_fold (op0
, false, &maybe_const
);
11146 sc
= save_expr (sc
);
11147 sc
= convert (TREE_TYPE (type1
), sc
);
11148 op0
= build_vector_from_val (type1
, sc
);
11150 op0
= c_wrap_maybe_const (op0
, true);
11151 orig_type0
= type0
= TREE_TYPE (op0
);
11152 code0
= TREE_CODE (type0
);
11156 case stv_secondarg
:
11158 bool maybe_const
= true;
11160 sc
= c_fully_fold (op1
, false, &maybe_const
);
11161 sc
= save_expr (sc
);
11162 sc
= convert (TREE_TYPE (type0
), sc
);
11163 op1
= build_vector_from_val (type0
, sc
);
11165 op1
= c_wrap_maybe_const (op1
, true);
11166 orig_type1
= type1
= TREE_TYPE (op1
);
11167 code1
= TREE_CODE (type1
);
11179 /* Handle the pointer + int case. */
11180 if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
11182 ret
= pointer_int_sum (location
, PLUS_EXPR
, op0
, op1
);
11183 goto return_build_binary_op
;
11185 else if (code1
== POINTER_TYPE
&& code0
== INTEGER_TYPE
)
11187 ret
= pointer_int_sum (location
, PLUS_EXPR
, op1
, op0
);
11188 goto return_build_binary_op
;
11195 /* Subtraction of two similar pointers.
11196 We must subtract them as integers, then divide by object size. */
11197 if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
11198 && comp_target_types (location
, type0
, type1
))
11200 ret
= pointer_diff (location
, op0
, op1
, &instrument_expr
);
11201 goto return_build_binary_op
;
11203 /* Handle pointer minus int. Just like pointer plus int. */
11204 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
11206 ret
= pointer_int_sum (location
, MINUS_EXPR
, op0
, op1
);
11207 goto return_build_binary_op
;
11217 case TRUNC_DIV_EXPR
:
11218 case CEIL_DIV_EXPR
:
11219 case FLOOR_DIV_EXPR
:
11220 case ROUND_DIV_EXPR
:
11221 case EXACT_DIV_EXPR
:
11222 doing_div_or_mod
= true;
11223 warn_for_div_by_zero (location
, op1
);
11225 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
11226 || code0
== FIXED_POINT_TYPE
11227 || code0
== COMPLEX_TYPE
|| code0
== VECTOR_TYPE
)
11228 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
11229 || code1
== FIXED_POINT_TYPE
11230 || code1
== COMPLEX_TYPE
|| code1
== VECTOR_TYPE
))
11232 enum tree_code tcode0
= code0
, tcode1
= code1
;
11234 if (code0
== COMPLEX_TYPE
|| code0
== VECTOR_TYPE
)
11235 tcode0
= TREE_CODE (TREE_TYPE (TREE_TYPE (op0
)));
11236 if (code1
== COMPLEX_TYPE
|| code1
== VECTOR_TYPE
)
11237 tcode1
= TREE_CODE (TREE_TYPE (TREE_TYPE (op1
)));
11239 if (!((tcode0
== INTEGER_TYPE
&& tcode1
== INTEGER_TYPE
)
11240 || (tcode0
== FIXED_POINT_TYPE
&& tcode1
== FIXED_POINT_TYPE
)))
11241 resultcode
= RDIV_EXPR
;
11243 /* Although it would be tempting to shorten always here, that
11244 loses on some targets, since the modulo instruction is
11245 undefined if the quotient can't be represented in the
11246 computation mode. We shorten only if unsigned or if
11247 dividing by something we know != -1. */
11248 shorten
= (TYPE_UNSIGNED (TREE_TYPE (orig_op0
))
11249 || (TREE_CODE (op1
) == INTEGER_CST
11250 && !integer_all_onesp (op1
)));
11258 if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
11260 /* Allow vector types which are not floating point types. */
11261 else if (code0
== VECTOR_TYPE
11262 && code1
== VECTOR_TYPE
11263 && !VECTOR_FLOAT_TYPE_P (type0
)
11264 && !VECTOR_FLOAT_TYPE_P (type1
))
11268 case TRUNC_MOD_EXPR
:
11269 case FLOOR_MOD_EXPR
:
11270 doing_div_or_mod
= true;
11271 warn_for_div_by_zero (location
, op1
);
11273 if (code0
== VECTOR_TYPE
&& code1
== VECTOR_TYPE
11274 && TREE_CODE (TREE_TYPE (type0
)) == INTEGER_TYPE
11275 && TREE_CODE (TREE_TYPE (type1
)) == INTEGER_TYPE
)
11277 else if (code0
== INTEGER_TYPE
&& code1
== INTEGER_TYPE
)
11279 /* Although it would be tempting to shorten always here, that loses
11280 on some targets, since the modulo instruction is undefined if the
11281 quotient can't be represented in the computation mode. We shorten
11282 only if unsigned or if dividing by something we know != -1. */
11283 shorten
= (TYPE_UNSIGNED (TREE_TYPE (orig_op0
))
11284 || (TREE_CODE (op1
) == INTEGER_CST
11285 && !integer_all_onesp (op1
)));
11290 case TRUTH_ANDIF_EXPR
:
11291 case TRUTH_ORIF_EXPR
:
11292 case TRUTH_AND_EXPR
:
11293 case TRUTH_OR_EXPR
:
11294 case TRUTH_XOR_EXPR
:
11295 if ((code0
== INTEGER_TYPE
|| code0
== POINTER_TYPE
11296 || code0
== REAL_TYPE
|| code0
== COMPLEX_TYPE
11297 || code0
== FIXED_POINT_TYPE
)
11298 && (code1
== INTEGER_TYPE
|| code1
== POINTER_TYPE
11299 || code1
== REAL_TYPE
|| code1
== COMPLEX_TYPE
11300 || code1
== FIXED_POINT_TYPE
))
11302 /* Result of these operations is always an int,
11303 but that does not mean the operands should be
11304 converted to ints! */
11305 result_type
= integer_type_node
;
11306 if (op0_int_operands
)
11308 op0
= c_objc_common_truthvalue_conversion (location
, orig_op0
);
11309 op0
= remove_c_maybe_const_expr (op0
);
11312 op0
= c_objc_common_truthvalue_conversion (location
, op0
);
11313 if (op1_int_operands
)
11315 op1
= c_objc_common_truthvalue_conversion (location
, orig_op1
);
11316 op1
= remove_c_maybe_const_expr (op1
);
11319 op1
= c_objc_common_truthvalue_conversion (location
, op1
);
11323 if (code
== TRUTH_ANDIF_EXPR
)
11325 int_const_or_overflow
= (int_operands
11326 && TREE_CODE (orig_op0
) == INTEGER_CST
11327 && (op0
== truthvalue_false_node
11328 || TREE_CODE (orig_op1
) == INTEGER_CST
));
11329 int_const
= (int_const_or_overflow
11330 && !TREE_OVERFLOW (orig_op0
)
11331 && (op0
== truthvalue_false_node
11332 || !TREE_OVERFLOW (orig_op1
)));
11334 else if (code
== TRUTH_ORIF_EXPR
)
11336 int_const_or_overflow
= (int_operands
11337 && TREE_CODE (orig_op0
) == INTEGER_CST
11338 && (op0
== truthvalue_true_node
11339 || TREE_CODE (orig_op1
) == INTEGER_CST
));
11340 int_const
= (int_const_or_overflow
11341 && !TREE_OVERFLOW (orig_op0
)
11342 && (op0
== truthvalue_true_node
11343 || !TREE_OVERFLOW (orig_op1
)));
11347 /* Shift operations: result has same type as first operand;
11348 always convert second operand to int.
11349 Also set SHORT_SHIFT if shifting rightward. */
11352 if (code0
== VECTOR_TYPE
&& code1
== VECTOR_TYPE
11353 && TREE_CODE (TREE_TYPE (type0
)) == INTEGER_TYPE
11354 && TREE_CODE (TREE_TYPE (type1
)) == INTEGER_TYPE
11355 && known_eq (TYPE_VECTOR_SUBPARTS (type0
),
11356 TYPE_VECTOR_SUBPARTS (type1
)))
11358 result_type
= type0
;
11361 else if ((code0
== INTEGER_TYPE
|| code0
== FIXED_POINT_TYPE
11362 || (code0
== VECTOR_TYPE
11363 && TREE_CODE (TREE_TYPE (type0
)) == INTEGER_TYPE
))
11364 && code1
== INTEGER_TYPE
)
11366 doing_shift
= true;
11367 if (TREE_CODE (op1
) == INTEGER_CST
)
11369 if (tree_int_cst_sgn (op1
) < 0)
11372 if (c_inhibit_evaluation_warnings
== 0)
11373 warning_at (location
, OPT_Wshift_count_negative
,
11374 "right shift count is negative");
11376 else if (code0
== VECTOR_TYPE
)
11378 if (compare_tree_int (op1
,
11379 TYPE_PRECISION (TREE_TYPE (type0
)))
11383 if (c_inhibit_evaluation_warnings
== 0)
11384 warning_at (location
, OPT_Wshift_count_overflow
,
11385 "right shift count >= width of vector element");
11390 if (!integer_zerop (op1
))
11393 if (compare_tree_int (op1
, TYPE_PRECISION (type0
)) >= 0)
11396 if (c_inhibit_evaluation_warnings
== 0)
11397 warning_at (location
, OPT_Wshift_count_overflow
,
11398 "right shift count >= width of type");
11403 /* Use the type of the value to be shifted. */
11404 result_type
= type0
;
11405 /* Avoid converting op1 to result_type later. */
11411 if (code0
== VECTOR_TYPE
&& code1
== VECTOR_TYPE
11412 && TREE_CODE (TREE_TYPE (type0
)) == INTEGER_TYPE
11413 && TREE_CODE (TREE_TYPE (type1
)) == INTEGER_TYPE
11414 && known_eq (TYPE_VECTOR_SUBPARTS (type0
),
11415 TYPE_VECTOR_SUBPARTS (type1
)))
11417 result_type
= type0
;
11420 else if ((code0
== INTEGER_TYPE
|| code0
== FIXED_POINT_TYPE
11421 || (code0
== VECTOR_TYPE
11422 && TREE_CODE (TREE_TYPE (type0
)) == INTEGER_TYPE
))
11423 && code1
== INTEGER_TYPE
)
11425 doing_shift
= true;
11426 if (TREE_CODE (op0
) == INTEGER_CST
11427 && tree_int_cst_sgn (op0
) < 0)
11429 /* Don't reject a left shift of a negative value in a context
11430 where a constant expression is needed in C90. */
11433 if (c_inhibit_evaluation_warnings
== 0)
11434 warning_at (location
, OPT_Wshift_negative_value
,
11435 "left shift of negative value");
11437 if (TREE_CODE (op1
) == INTEGER_CST
)
11439 if (tree_int_cst_sgn (op1
) < 0)
11442 if (c_inhibit_evaluation_warnings
== 0)
11443 warning_at (location
, OPT_Wshift_count_negative
,
11444 "left shift count is negative");
11446 else if (code0
== VECTOR_TYPE
)
11448 if (compare_tree_int (op1
,
11449 TYPE_PRECISION (TREE_TYPE (type0
)))
11453 if (c_inhibit_evaluation_warnings
== 0)
11454 warning_at (location
, OPT_Wshift_count_overflow
,
11455 "left shift count >= width of vector element");
11458 else if (compare_tree_int (op1
, TYPE_PRECISION (type0
)) >= 0)
11461 if (c_inhibit_evaluation_warnings
== 0)
11462 warning_at (location
, OPT_Wshift_count_overflow
,
11463 "left shift count >= width of type");
11465 else if (TREE_CODE (op0
) == INTEGER_CST
11466 && maybe_warn_shift_overflow (location
, op0
, op1
)
11471 /* Use the type of the value to be shifted. */
11472 result_type
= type0
;
11473 /* Avoid converting op1 to result_type later. */
11480 if (code0
== VECTOR_TYPE
&& code1
== VECTOR_TYPE
)
11483 if (!vector_types_compatible_elements_p (type0
, type1
))
11485 error_at (location
, "comparing vectors with different "
11487 return error_mark_node
;
11490 if (maybe_ne (TYPE_VECTOR_SUBPARTS (type0
),
11491 TYPE_VECTOR_SUBPARTS (type1
)))
11493 error_at (location
, "comparing vectors with different "
11494 "number of elements");
11495 return error_mark_node
;
11498 /* It's not precisely specified how the usual arithmetic
11499 conversions apply to the vector types. Here, we use
11500 the unsigned type if one of the operands is signed and
11501 the other one is unsigned. */
11502 if (TYPE_UNSIGNED (type0
) != TYPE_UNSIGNED (type1
))
11504 if (!TYPE_UNSIGNED (type0
))
11505 op0
= build1 (VIEW_CONVERT_EXPR
, type1
, op0
);
11507 op1
= build1 (VIEW_CONVERT_EXPR
, type0
, op1
);
11508 warning_at (location
, OPT_Wsign_compare
, "comparison between "
11509 "types %qT and %qT", type0
, type1
);
11512 /* Always construct signed integer vector type. */
11513 intt
= c_common_type_for_size (GET_MODE_BITSIZE
11515 (TREE_TYPE (type0
))), 0);
11518 error_at (location
, "could not find an integer type "
11519 "of the same size as %qT",
11520 TREE_TYPE (type0
));
11521 return error_mark_node
;
11523 result_type
= build_opaque_vector_type (intt
,
11524 TYPE_VECTOR_SUBPARTS (type0
));
11526 ret
= build_vec_cmp (resultcode
, result_type
, op0
, op1
);
11527 goto return_build_binary_op
;
11529 if (FLOAT_TYPE_P (type0
) || FLOAT_TYPE_P (type1
))
11530 warning_at (location
,
11532 "comparing floating point with == or != is unsafe");
11533 /* Result of comparison is always int,
11534 but don't convert the args to int! */
11535 build_type
= integer_type_node
;
11536 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
11537 || code0
== FIXED_POINT_TYPE
|| code0
== COMPLEX_TYPE
)
11538 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
11539 || code1
== FIXED_POINT_TYPE
|| code1
== COMPLEX_TYPE
))
11541 else if (code0
== POINTER_TYPE
&& null_pointer_constant_p (orig_op1
))
11543 if (TREE_CODE (op0
) == ADDR_EXPR
11544 && decl_with_nonnull_addr_p (TREE_OPERAND (op0
, 0))
11545 && !from_macro_expansion_at (location
))
11547 if (code
== EQ_EXPR
)
11548 warning_at (location
,
11550 "the comparison will always evaluate as %<false%> "
11551 "for the address of %qD will never be NULL",
11552 TREE_OPERAND (op0
, 0));
11554 warning_at (location
,
11556 "the comparison will always evaluate as %<true%> "
11557 "for the address of %qD will never be NULL",
11558 TREE_OPERAND (op0
, 0));
11560 result_type
= type0
;
11562 else if (code1
== POINTER_TYPE
&& null_pointer_constant_p (orig_op0
))
11564 if (TREE_CODE (op1
) == ADDR_EXPR
11565 && decl_with_nonnull_addr_p (TREE_OPERAND (op1
, 0))
11566 && !from_macro_expansion_at (location
))
11568 if (code
== EQ_EXPR
)
11569 warning_at (location
,
11571 "the comparison will always evaluate as %<false%> "
11572 "for the address of %qD will never be NULL",
11573 TREE_OPERAND (op1
, 0));
11575 warning_at (location
,
11577 "the comparison will always evaluate as %<true%> "
11578 "for the address of %qD will never be NULL",
11579 TREE_OPERAND (op1
, 0));
11581 result_type
= type1
;
11583 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
11585 tree tt0
= TREE_TYPE (type0
);
11586 tree tt1
= TREE_TYPE (type1
);
11587 addr_space_t as0
= TYPE_ADDR_SPACE (tt0
);
11588 addr_space_t as1
= TYPE_ADDR_SPACE (tt1
);
11589 addr_space_t as_common
= ADDR_SPACE_GENERIC
;
11591 /* Anything compares with void *. void * compares with anything.
11592 Otherwise, the targets must be compatible
11593 and both must be object or both incomplete. */
11594 if (comp_target_types (location
, type0
, type1
))
11595 result_type
= common_pointer_type (type0
, type1
);
11596 else if (!addr_space_superset (as0
, as1
, &as_common
))
11598 error_at (location
, "comparison of pointers to "
11599 "disjoint address spaces");
11600 return error_mark_node
;
11602 else if (VOID_TYPE_P (tt0
) && !TYPE_ATOMIC (tt0
))
11604 if (pedantic
&& TREE_CODE (tt1
) == FUNCTION_TYPE
)
11605 pedwarn (location
, OPT_Wpedantic
, "ISO C forbids "
11606 "comparison of %<void *%> with function pointer");
11608 else if (VOID_TYPE_P (tt1
) && !TYPE_ATOMIC (tt1
))
11610 if (pedantic
&& TREE_CODE (tt0
) == FUNCTION_TYPE
)
11611 pedwarn (location
, OPT_Wpedantic
, "ISO C forbids "
11612 "comparison of %<void *%> with function pointer");
11615 /* Avoid warning about the volatile ObjC EH puts on decls. */
11617 pedwarn (location
, 0,
11618 "comparison of distinct pointer types lacks a cast");
11620 if (result_type
== NULL_TREE
)
11622 int qual
= ENCODE_QUAL_ADDR_SPACE (as_common
);
11623 result_type
= build_pointer_type
11624 (build_qualified_type (void_type_node
, qual
));
11627 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
11629 result_type
= type0
;
11630 pedwarn (location
, 0, "comparison between pointer and integer");
11632 else if (code0
== INTEGER_TYPE
&& code1
== POINTER_TYPE
)
11634 result_type
= type1
;
11635 pedwarn (location
, 0, "comparison between pointer and integer");
11637 if ((TREE_CODE (TREE_TYPE (orig_op0
)) == BOOLEAN_TYPE
11638 || truth_value_p (TREE_CODE (orig_op0
)))
11639 ^ (TREE_CODE (TREE_TYPE (orig_op1
)) == BOOLEAN_TYPE
11640 || truth_value_p (TREE_CODE (orig_op1
))))
11641 maybe_warn_bool_compare (location
, code
, orig_op0
, orig_op1
);
11648 if (code0
== VECTOR_TYPE
&& code1
== VECTOR_TYPE
)
11651 if (!vector_types_compatible_elements_p (type0
, type1
))
11653 error_at (location
, "comparing vectors with different "
11655 return error_mark_node
;
11658 if (maybe_ne (TYPE_VECTOR_SUBPARTS (type0
),
11659 TYPE_VECTOR_SUBPARTS (type1
)))
11661 error_at (location
, "comparing vectors with different "
11662 "number of elements");
11663 return error_mark_node
;
11666 /* It's not precisely specified how the usual arithmetic
11667 conversions apply to the vector types. Here, we use
11668 the unsigned type if one of the operands is signed and
11669 the other one is unsigned. */
11670 if (TYPE_UNSIGNED (type0
) != TYPE_UNSIGNED (type1
))
11672 if (!TYPE_UNSIGNED (type0
))
11673 op0
= build1 (VIEW_CONVERT_EXPR
, type1
, op0
);
11675 op1
= build1 (VIEW_CONVERT_EXPR
, type0
, op1
);
11676 warning_at (location
, OPT_Wsign_compare
, "comparison between "
11677 "types %qT and %qT", type0
, type1
);
11680 /* Always construct signed integer vector type. */
11681 intt
= c_common_type_for_size (GET_MODE_BITSIZE
11683 (TREE_TYPE (type0
))), 0);
11686 error_at (location
, "could not find an integer type "
11687 "of the same size as %qT",
11688 TREE_TYPE (type0
));
11689 return error_mark_node
;
11691 result_type
= build_opaque_vector_type (intt
,
11692 TYPE_VECTOR_SUBPARTS (type0
));
11694 ret
= build_vec_cmp (resultcode
, result_type
, op0
, op1
);
11695 goto return_build_binary_op
;
11697 build_type
= integer_type_node
;
11698 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
11699 || code0
== FIXED_POINT_TYPE
)
11700 && (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
11701 || code1
== FIXED_POINT_TYPE
))
11703 else if (code0
== POINTER_TYPE
&& code1
== POINTER_TYPE
)
11705 addr_space_t as0
= TYPE_ADDR_SPACE (TREE_TYPE (type0
));
11706 addr_space_t as1
= TYPE_ADDR_SPACE (TREE_TYPE (type1
));
11707 addr_space_t as_common
;
11709 if (comp_target_types (location
, type0
, type1
))
11711 result_type
= common_pointer_type (type0
, type1
);
11712 if (!COMPLETE_TYPE_P (TREE_TYPE (type0
))
11713 != !COMPLETE_TYPE_P (TREE_TYPE (type1
)))
11714 pedwarn (location
, 0,
11715 "comparison of complete and incomplete pointers");
11716 else if (TREE_CODE (TREE_TYPE (type0
)) == FUNCTION_TYPE
)
11717 pedwarn (location
, OPT_Wpedantic
, "ISO C forbids "
11718 "ordered comparisons of pointers to functions");
11719 else if (null_pointer_constant_p (orig_op0
)
11720 || null_pointer_constant_p (orig_op1
))
11721 warning_at (location
, OPT_Wextra
,
11722 "ordered comparison of pointer with null pointer");
11725 else if (!addr_space_superset (as0
, as1
, &as_common
))
11727 error_at (location
, "comparison of pointers to "
11728 "disjoint address spaces");
11729 return error_mark_node
;
11733 int qual
= ENCODE_QUAL_ADDR_SPACE (as_common
);
11734 result_type
= build_pointer_type
11735 (build_qualified_type (void_type_node
, qual
));
11736 pedwarn (location
, 0,
11737 "comparison of distinct pointer types lacks a cast");
11740 else if (code0
== POINTER_TYPE
&& null_pointer_constant_p (orig_op1
))
11742 result_type
= type0
;
11744 pedwarn (location
, OPT_Wpedantic
,
11745 "ordered comparison of pointer with integer zero");
11746 else if (extra_warnings
)
11747 warning_at (location
, OPT_Wextra
,
11748 "ordered comparison of pointer with integer zero");
11750 else if (code1
== POINTER_TYPE
&& null_pointer_constant_p (orig_op0
))
11752 result_type
= type1
;
11754 pedwarn (location
, OPT_Wpedantic
,
11755 "ordered comparison of pointer with integer zero");
11756 else if (extra_warnings
)
11757 warning_at (location
, OPT_Wextra
,
11758 "ordered comparison of pointer with integer zero");
11760 else if (code0
== POINTER_TYPE
&& code1
== INTEGER_TYPE
)
11762 result_type
= type0
;
11763 pedwarn (location
, 0, "comparison between pointer and integer");
11765 else if (code0
== INTEGER_TYPE
&& code1
== POINTER_TYPE
)
11767 result_type
= type1
;
11768 pedwarn (location
, 0, "comparison between pointer and integer");
11771 if ((code0
== POINTER_TYPE
|| code1
== POINTER_TYPE
)
11772 && sanitize_flags_p (SANITIZE_POINTER_COMPARE
))
11774 op0
= save_expr (op0
);
11775 op1
= save_expr (op1
);
11777 tree tt
= builtin_decl_explicit (BUILT_IN_ASAN_POINTER_COMPARE
);
11778 instrument_expr
= build_call_expr_loc (location
, tt
, 2, op0
, op1
);
11781 if ((TREE_CODE (TREE_TYPE (orig_op0
)) == BOOLEAN_TYPE
11782 || truth_value_p (TREE_CODE (orig_op0
)))
11783 ^ (TREE_CODE (TREE_TYPE (orig_op1
)) == BOOLEAN_TYPE
11784 || truth_value_p (TREE_CODE (orig_op1
))))
11785 maybe_warn_bool_compare (location
, code
, orig_op0
, orig_op1
);
11789 gcc_unreachable ();
11792 if (code0
== ERROR_MARK
|| code1
== ERROR_MARK
)
11793 return error_mark_node
;
11795 if (code0
== VECTOR_TYPE
&& code1
== VECTOR_TYPE
11796 && (!tree_int_cst_equal (TYPE_SIZE (type0
), TYPE_SIZE (type1
))
11797 || !vector_types_compatible_elements_p (type0
, type1
)))
11799 gcc_rich_location
richloc (location
);
11800 richloc
.maybe_add_expr (orig_op0
);
11801 richloc
.maybe_add_expr (orig_op1
);
11802 binary_op_error (&richloc
, code
, type0
, type1
);
11803 return error_mark_node
;
11806 if ((code0
== INTEGER_TYPE
|| code0
== REAL_TYPE
|| code0
== COMPLEX_TYPE
11807 || code0
== FIXED_POINT_TYPE
|| code0
== VECTOR_TYPE
)
11809 (code1
== INTEGER_TYPE
|| code1
== REAL_TYPE
|| code1
== COMPLEX_TYPE
11810 || code1
== FIXED_POINT_TYPE
|| code1
== VECTOR_TYPE
))
11812 bool first_complex
= (code0
== COMPLEX_TYPE
);
11813 bool second_complex
= (code1
== COMPLEX_TYPE
);
11814 int none_complex
= (!first_complex
&& !second_complex
);
11816 if (shorten
|| common
|| short_compare
)
11818 result_type
= c_common_type (type0
, type1
);
11819 do_warn_double_promotion (result_type
, type0
, type1
,
11820 "implicit conversion from %qT to %qT "
11821 "to match other operand of binary "
11824 if (result_type
== error_mark_node
)
11825 return error_mark_node
;
11828 if (first_complex
!= second_complex
11829 && (code
== PLUS_EXPR
11830 || code
== MINUS_EXPR
11831 || code
== MULT_EXPR
11832 || (code
== TRUNC_DIV_EXPR
&& first_complex
))
11833 && TREE_CODE (TREE_TYPE (result_type
)) == REAL_TYPE
11834 && flag_signed_zeros
)
11836 /* An operation on mixed real/complex operands must be
11837 handled specially, but the language-independent code can
11838 more easily optimize the plain complex arithmetic if
11839 -fno-signed-zeros. */
11840 tree real_type
= TREE_TYPE (result_type
);
11842 if (type0
!= orig_type0
|| type1
!= orig_type1
)
11844 gcc_assert (may_need_excess_precision
&& common
);
11845 semantic_result_type
= c_common_type (orig_type0
, orig_type1
);
11849 if (TREE_TYPE (op0
) != result_type
)
11850 op0
= convert_and_check (location
, result_type
, op0
);
11851 if (TREE_TYPE (op1
) != real_type
)
11852 op1
= convert_and_check (location
, real_type
, op1
);
11856 if (TREE_TYPE (op0
) != real_type
)
11857 op0
= convert_and_check (location
, real_type
, op0
);
11858 if (TREE_TYPE (op1
) != result_type
)
11859 op1
= convert_and_check (location
, result_type
, op1
);
11861 if (TREE_CODE (op0
) == ERROR_MARK
|| TREE_CODE (op1
) == ERROR_MARK
)
11862 return error_mark_node
;
11865 op0
= save_expr (op0
);
11866 real
= build_unary_op (EXPR_LOCATION (orig_op0
), REALPART_EXPR
,
11868 imag
= build_unary_op (EXPR_LOCATION (orig_op0
), IMAGPART_EXPR
,
11873 case TRUNC_DIV_EXPR
:
11874 op1
= save_expr (op1
);
11875 imag
= build2 (resultcode
, real_type
, imag
, op1
);
11876 /* Fall through. */
11879 real
= build2 (resultcode
, real_type
, real
, op1
);
11887 op1
= save_expr (op1
);
11888 real
= build_unary_op (EXPR_LOCATION (orig_op1
), REALPART_EXPR
,
11890 imag
= build_unary_op (EXPR_LOCATION (orig_op1
), IMAGPART_EXPR
,
11895 op0
= save_expr (op0
);
11896 imag
= build2 (resultcode
, real_type
, op0
, imag
);
11897 /* Fall through. */
11899 real
= build2 (resultcode
, real_type
, op0
, real
);
11902 real
= build2 (resultcode
, real_type
, op0
, real
);
11903 imag
= build1 (NEGATE_EXPR
, real_type
, imag
);
11909 ret
= build2 (COMPLEX_EXPR
, result_type
, real
, imag
);
11910 goto return_build_binary_op
;
11913 /* For certain operations (which identify themselves by shorten != 0)
11914 if both args were extended from the same smaller type,
11915 do the arithmetic in that type and then extend.
11917 shorten !=0 and !=1 indicates a bitwise operation.
11918 For them, this optimization is safe only if
11919 both args are zero-extended or both are sign-extended.
11920 Otherwise, we might change the result.
11921 Eg, (short)-1 | (unsigned short)-1 is (int)-1
11922 but calculated in (unsigned short) it would be (unsigned short)-1. */
11924 if (shorten
&& none_complex
)
11926 final_type
= result_type
;
11927 result_type
= shorten_binary_op (result_type
, op0
, op1
,
11931 /* Shifts can be shortened if shifting right. */
11936 tree arg0
= get_narrower (op0
, &unsigned_arg
);
11938 final_type
= result_type
;
11940 if (arg0
== op0
&& final_type
== TREE_TYPE (op0
))
11941 unsigned_arg
= TYPE_UNSIGNED (TREE_TYPE (op0
));
11943 if (TYPE_PRECISION (TREE_TYPE (arg0
)) < TYPE_PRECISION (result_type
)
11944 && tree_int_cst_sgn (op1
) > 0
11945 /* We can shorten only if the shift count is less than the
11946 number of bits in the smaller type size. */
11947 && compare_tree_int (op1
, TYPE_PRECISION (TREE_TYPE (arg0
))) < 0
11948 /* We cannot drop an unsigned shift after sign-extension. */
11949 && (!TYPE_UNSIGNED (final_type
) || unsigned_arg
))
11951 /* Do an unsigned shift if the operand was zero-extended. */
11953 = c_common_signed_or_unsigned_type (unsigned_arg
,
11955 /* Convert value-to-be-shifted to that type. */
11956 if (TREE_TYPE (op0
) != result_type
)
11957 op0
= convert (result_type
, op0
);
11962 /* Comparison operations are shortened too but differently.
11963 They identify themselves by setting short_compare = 1. */
11967 /* Don't write &op0, etc., because that would prevent op0
11968 from being kept in a register.
11969 Instead, make copies of the our local variables and
11970 pass the copies by reference, then copy them back afterward. */
11971 tree xop0
= op0
, xop1
= op1
, xresult_type
= result_type
;
11972 enum tree_code xresultcode
= resultcode
;
11974 = shorten_compare (location
, &xop0
, &xop1
, &xresult_type
,
11977 if (val
!= NULL_TREE
)
11980 goto return_build_binary_op
;
11983 op0
= xop0
, op1
= xop1
;
11985 resultcode
= xresultcode
;
11987 if (c_inhibit_evaluation_warnings
== 0)
11989 bool op0_maybe_const
= true;
11990 bool op1_maybe_const
= true;
11991 tree orig_op0_folded
, orig_op1_folded
;
11993 if (in_late_binary_op
)
11995 orig_op0_folded
= orig_op0
;
11996 orig_op1_folded
= orig_op1
;
12000 /* Fold for the sake of possible warnings, as in
12001 build_conditional_expr. This requires the
12002 "original" values to be folded, not just op0 and
12004 c_inhibit_evaluation_warnings
++;
12005 op0
= c_fully_fold (op0
, require_constant_value
,
12007 op1
= c_fully_fold (op1
, require_constant_value
,
12009 c_inhibit_evaluation_warnings
--;
12010 orig_op0_folded
= c_fully_fold (orig_op0
,
12011 require_constant_value
,
12013 orig_op1_folded
= c_fully_fold (orig_op1
,
12014 require_constant_value
,
12018 if (warn_sign_compare
)
12019 warn_for_sign_compare (location
, orig_op0_folded
,
12020 orig_op1_folded
, op0
, op1
,
12021 result_type
, resultcode
);
12022 if (!in_late_binary_op
&& !int_operands
)
12024 if (!op0_maybe_const
|| TREE_CODE (op0
) != INTEGER_CST
)
12025 op0
= c_wrap_maybe_const (op0
, !op0_maybe_const
);
12026 if (!op1_maybe_const
|| TREE_CODE (op1
) != INTEGER_CST
)
12027 op1
= c_wrap_maybe_const (op1
, !op1_maybe_const
);
12033 /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
12034 If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
12035 Then the expression will be built.
12036 It will be given type FINAL_TYPE if that is nonzero;
12037 otherwise, it will be given type RESULT_TYPE. */
12041 gcc_rich_location
richloc (location
);
12042 richloc
.maybe_add_expr (orig_op0
);
12043 richloc
.maybe_add_expr (orig_op1
);
12044 binary_op_error (&richloc
, code
, TREE_TYPE (op0
), TREE_TYPE (op1
));
12045 return error_mark_node
;
12048 if (build_type
== NULL_TREE
)
12050 build_type
= result_type
;
12051 if ((type0
!= orig_type0
|| type1
!= orig_type1
)
12054 gcc_assert (may_need_excess_precision
&& common
);
12055 semantic_result_type
= c_common_type (orig_type0
, orig_type1
);
12061 op0
= ep_convert_and_check (location
, result_type
, op0
,
12062 semantic_result_type
);
12063 op1
= ep_convert_and_check (location
, result_type
, op1
,
12064 semantic_result_type
);
12066 /* This can happen if one operand has a vector type, and the other
12067 has a different type. */
12068 if (TREE_CODE (op0
) == ERROR_MARK
|| TREE_CODE (op1
) == ERROR_MARK
)
12069 return error_mark_node
;
12072 if (sanitize_flags_p ((SANITIZE_SHIFT
12073 | SANITIZE_DIVIDE
| SANITIZE_FLOAT_DIVIDE
))
12074 && current_function_decl
!= NULL_TREE
12075 && (doing_div_or_mod
|| doing_shift
)
12076 && !require_constant_value
)
12078 /* OP0 and/or OP1 might have side-effects. */
12079 op0
= save_expr (op0
);
12080 op1
= save_expr (op1
);
12081 op0
= c_fully_fold (op0
, false, NULL
);
12082 op1
= c_fully_fold (op1
, false, NULL
);
12083 if (doing_div_or_mod
&& (sanitize_flags_p ((SANITIZE_DIVIDE
12084 | SANITIZE_FLOAT_DIVIDE
))))
12085 instrument_expr
= ubsan_instrument_division (location
, op0
, op1
);
12086 else if (doing_shift
&& sanitize_flags_p (SANITIZE_SHIFT
))
12087 instrument_expr
= ubsan_instrument_shift (location
, code
, op0
, op1
);
12090 /* Treat expressions in initializers specially as they can't trap. */
12091 if (int_const_or_overflow
)
12092 ret
= (require_constant_value
12093 ? fold_build2_initializer_loc (location
, resultcode
, build_type
,
12095 : fold_build2_loc (location
, resultcode
, build_type
, op0
, op1
));
12097 ret
= build2 (resultcode
, build_type
, op0
, op1
);
12098 if (final_type
!= NULL_TREE
)
12099 ret
= convert (final_type
, ret
);
12101 return_build_binary_op
:
12102 gcc_assert (ret
!= error_mark_node
);
12103 if (TREE_CODE (ret
) == INTEGER_CST
&& !TREE_OVERFLOW (ret
) && !int_const
)
12104 ret
= (int_operands
12105 ? note_integer_operands (ret
)
12106 : build1 (NOP_EXPR
, TREE_TYPE (ret
), ret
));
12107 else if (TREE_CODE (ret
) != INTEGER_CST
&& int_operands
12108 && !in_late_binary_op
)
12109 ret
= note_integer_operands (ret
);
12110 protected_set_expr_location (ret
, location
);
12112 if (instrument_expr
!= NULL
)
12113 ret
= fold_build2 (COMPOUND_EXPR
, TREE_TYPE (ret
),
12114 instrument_expr
, ret
);
12116 if (semantic_result_type
)
12117 ret
= build1_loc (location
, EXCESS_PRECISION_EXPR
,
12118 semantic_result_type
, ret
);
12124 /* Convert EXPR to be a truth-value, validating its type for this
12125 purpose. LOCATION is the source location for the expression. */
12128 c_objc_common_truthvalue_conversion (location_t location
, tree expr
)
12130 bool int_const
, int_operands
;
12132 switch (TREE_CODE (TREE_TYPE (expr
)))
12135 error_at (location
, "used array that cannot be converted to pointer where scalar is required");
12136 return error_mark_node
;
12139 error_at (location
, "used struct type value where scalar is required");
12140 return error_mark_node
;
12143 error_at (location
, "used union type value where scalar is required");
12144 return error_mark_node
;
12147 error_at (location
, "void value not ignored as it ought to be");
12148 return error_mark_node
;
12151 if (reject_gcc_builtin (expr
))
12152 return error_mark_node
;
12155 case FUNCTION_TYPE
:
12156 gcc_unreachable ();
12159 error_at (location
, "used vector type where scalar is required");
12160 return error_mark_node
;
12166 int_const
= (TREE_CODE (expr
) == INTEGER_CST
&& !TREE_OVERFLOW (expr
));
12167 int_operands
= EXPR_INT_CONST_OPERANDS (expr
);
12168 if (int_operands
&& TREE_CODE (expr
) != INTEGER_CST
)
12170 expr
= remove_c_maybe_const_expr (expr
);
12171 expr
= build2 (NE_EXPR
, integer_type_node
, expr
,
12172 convert (TREE_TYPE (expr
), integer_zero_node
));
12173 expr
= note_integer_operands (expr
);
12176 /* ??? Should we also give an error for vectors rather than leaving
12177 those to give errors later? */
12178 expr
= c_common_truthvalue_conversion (location
, expr
);
12180 if (TREE_CODE (expr
) == INTEGER_CST
&& int_operands
&& !int_const
)
12182 if (TREE_OVERFLOW (expr
))
12185 return note_integer_operands (expr
);
12187 if (TREE_CODE (expr
) == INTEGER_CST
&& !int_const
)
12188 return build1 (NOP_EXPR
, TREE_TYPE (expr
), expr
);
12193 /* Convert EXPR to a contained DECL, updating *TC, *TI and *SE as
12197 c_expr_to_decl (tree expr
, bool *tc ATTRIBUTE_UNUSED
, bool *se
)
12199 if (TREE_CODE (expr
) == COMPOUND_LITERAL_EXPR
)
12201 tree decl
= COMPOUND_LITERAL_EXPR_DECL (expr
);
12202 /* Executing a compound literal inside a function reinitializes
12204 if (!TREE_STATIC (decl
))
12212 /* Generate OMP construct CODE, with BODY and CLAUSES as its compound
12213 statement. LOC is the location of the construct. */
12216 c_finish_omp_construct (location_t loc
, enum tree_code code
, tree body
,
12219 body
= c_end_compound_stmt (loc
, body
, true);
12221 tree stmt
= make_node (code
);
12222 TREE_TYPE (stmt
) = void_type_node
;
12223 OMP_BODY (stmt
) = body
;
12224 OMP_CLAUSES (stmt
) = clauses
;
12225 SET_EXPR_LOCATION (stmt
, loc
);
12227 return add_stmt (stmt
);
12230 /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound
12231 statement. LOC is the location of the OACC_DATA. */
12234 c_finish_oacc_data (location_t loc
, tree clauses
, tree block
)
12238 block
= c_end_compound_stmt (loc
, block
, true);
12240 stmt
= make_node (OACC_DATA
);
12241 TREE_TYPE (stmt
) = void_type_node
;
12242 OACC_DATA_CLAUSES (stmt
) = clauses
;
12243 OACC_DATA_BODY (stmt
) = block
;
12244 SET_EXPR_LOCATION (stmt
, loc
);
12246 return add_stmt (stmt
);
12249 /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound
12250 statement. LOC is the location of the OACC_HOST_DATA. */
12253 c_finish_oacc_host_data (location_t loc
, tree clauses
, tree block
)
12257 block
= c_end_compound_stmt (loc
, block
, true);
12259 stmt
= make_node (OACC_HOST_DATA
);
12260 TREE_TYPE (stmt
) = void_type_node
;
12261 OACC_HOST_DATA_CLAUSES (stmt
) = clauses
;
12262 OACC_HOST_DATA_BODY (stmt
) = block
;
12263 SET_EXPR_LOCATION (stmt
, loc
);
12265 return add_stmt (stmt
);
12268 /* Like c_begin_compound_stmt, except force the retention of the BLOCK. */
12271 c_begin_omp_parallel (void)
12275 keep_next_level ();
12276 block
= c_begin_compound_stmt (true);
12281 /* Generate OMP_PARALLEL, with CLAUSES and BLOCK as its compound
12282 statement. LOC is the location of the OMP_PARALLEL. */
12285 c_finish_omp_parallel (location_t loc
, tree clauses
, tree block
)
12289 block
= c_end_compound_stmt (loc
, block
, true);
12291 stmt
= make_node (OMP_PARALLEL
);
12292 TREE_TYPE (stmt
) = void_type_node
;
12293 OMP_PARALLEL_CLAUSES (stmt
) = clauses
;
12294 OMP_PARALLEL_BODY (stmt
) = block
;
12295 SET_EXPR_LOCATION (stmt
, loc
);
12297 return add_stmt (stmt
);
12300 /* Like c_begin_compound_stmt, except force the retention of the BLOCK. */
12303 c_begin_omp_task (void)
12307 keep_next_level ();
12308 block
= c_begin_compound_stmt (true);
12313 /* Generate OMP_TASK, with CLAUSES and BLOCK as its compound
12314 statement. LOC is the location of the #pragma. */
12317 c_finish_omp_task (location_t loc
, tree clauses
, tree block
)
12321 block
= c_end_compound_stmt (loc
, block
, true);
12323 stmt
= make_node (OMP_TASK
);
12324 TREE_TYPE (stmt
) = void_type_node
;
12325 OMP_TASK_CLAUSES (stmt
) = clauses
;
12326 OMP_TASK_BODY (stmt
) = block
;
12327 SET_EXPR_LOCATION (stmt
, loc
);
12329 return add_stmt (stmt
);
12332 /* Generate GOMP_cancel call for #pragma omp cancel. */
12335 c_finish_omp_cancel (location_t loc
, tree clauses
)
12337 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_CANCEL
);
12339 if (omp_find_clause (clauses
, OMP_CLAUSE_PARALLEL
))
12341 else if (omp_find_clause (clauses
, OMP_CLAUSE_FOR
))
12343 else if (omp_find_clause (clauses
, OMP_CLAUSE_SECTIONS
))
12345 else if (omp_find_clause (clauses
, OMP_CLAUSE_TASKGROUP
))
12349 error_at (loc
, "%<#pragma omp cancel%> must specify one of "
12350 "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> "
12354 tree ifc
= omp_find_clause (clauses
, OMP_CLAUSE_IF
);
12355 if (ifc
!= NULL_TREE
)
12357 tree type
= TREE_TYPE (OMP_CLAUSE_IF_EXPR (ifc
));
12358 ifc
= fold_build2_loc (OMP_CLAUSE_LOCATION (ifc
), NE_EXPR
,
12359 boolean_type_node
, OMP_CLAUSE_IF_EXPR (ifc
),
12360 build_zero_cst (type
));
12363 ifc
= boolean_true_node
;
12364 tree stmt
= build_call_expr_loc (loc
, fn
, 2,
12365 build_int_cst (integer_type_node
, mask
),
12370 /* Generate GOMP_cancellation_point call for
12371 #pragma omp cancellation point. */
12374 c_finish_omp_cancellation_point (location_t loc
, tree clauses
)
12376 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT
);
12378 if (omp_find_clause (clauses
, OMP_CLAUSE_PARALLEL
))
12380 else if (omp_find_clause (clauses
, OMP_CLAUSE_FOR
))
12382 else if (omp_find_clause (clauses
, OMP_CLAUSE_SECTIONS
))
12384 else if (omp_find_clause (clauses
, OMP_CLAUSE_TASKGROUP
))
12388 error_at (loc
, "%<#pragma omp cancellation point%> must specify one of "
12389 "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> "
12393 tree stmt
= build_call_expr_loc (loc
, fn
, 1,
12394 build_int_cst (integer_type_node
, mask
));
12398 /* Helper function for handle_omp_array_sections. Called recursively
12399 to handle multiple array-section-subscripts. C is the clause,
12400 T current expression (initially OMP_CLAUSE_DECL), which is either
12401 a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound
12402 expression if specified, TREE_VALUE length expression if specified,
12403 TREE_CHAIN is what it has been specified after, or some decl.
12404 TYPES vector is populated with array section types, MAYBE_ZERO_LEN
12405 set to true if any of the array-section-subscript could have length
12406 of zero (explicit or implicit), FIRST_NON_ONE is the index of the
12407 first array-section-subscript which is known not to have length
12409 map(a[:b][2:1][:c][:2][:d][e:f][2:5])
12410 FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c]
12411 all are or may have length of 1, array-section-subscript [:2] is the
12412 first one known not to have length 1. For array-section-subscript
12413 <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't
12414 0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we
12415 can if MAYBE_ZERO_LEN is false. MAYBE_ZERO_LEN will be true in the above
12416 case though, as some lengths could be zero. */
12419 handle_omp_array_sections_1 (tree c
, tree t
, vec
<tree
> &types
,
12420 bool &maybe_zero_len
, unsigned int &first_non_one
,
12421 enum c_omp_region_type ort
)
12423 tree ret
, low_bound
, length
, type
;
12424 if (TREE_CODE (t
) != TREE_LIST
)
12426 if (error_operand_p (t
))
12427 return error_mark_node
;
12429 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
12430 && TYPE_ATOMIC (strip_array_types (TREE_TYPE (t
))))
12432 error_at (OMP_CLAUSE_LOCATION (c
), "%<_Atomic%> %qE in %qs clause",
12433 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
12434 return error_mark_node
;
12436 if (TREE_CODE (t
) == COMPONENT_REF
12437 && ort
== C_ORT_OMP
12438 && (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
12439 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO
12440 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FROM
))
12442 if (DECL_BIT_FIELD (TREE_OPERAND (t
, 1)))
12444 error_at (OMP_CLAUSE_LOCATION (c
),
12445 "bit-field %qE in %qs clause",
12446 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
12447 return error_mark_node
;
12449 while (TREE_CODE (t
) == COMPONENT_REF
)
12451 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == UNION_TYPE
)
12453 error_at (OMP_CLAUSE_LOCATION (c
),
12454 "%qE is a member of a union", t
);
12455 return error_mark_node
;
12457 t
= TREE_OPERAND (t
, 0);
12460 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
12463 error_at (OMP_CLAUSE_LOCATION (c
),
12464 "%qD is not a variable in %qs clause", t
,
12465 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
12467 error_at (OMP_CLAUSE_LOCATION (c
),
12468 "%qE is not a variable in %qs clause", t
,
12469 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
12470 return error_mark_node
;
12472 else if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
12473 && TYPE_ATOMIC (TREE_TYPE (t
)))
12475 error_at (OMP_CLAUSE_LOCATION (c
), "%<_Atomic%> %qD in %qs clause",
12476 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
12477 return error_mark_node
;
12479 else if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
12481 && DECL_THREAD_LOCAL_P (t
))
12483 error_at (OMP_CLAUSE_LOCATION (c
),
12484 "%qD is threadprivate variable in %qs clause", t
,
12485 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
12486 return error_mark_node
;
12488 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
12489 && TYPE_ATOMIC (TREE_TYPE (t
))
12490 && POINTER_TYPE_P (TREE_TYPE (t
)))
12492 /* If the array section is pointer based and the pointer
12493 itself is _Atomic qualified, we need to atomically load
12496 memset (&expr
, 0, sizeof (expr
));
12498 expr
= convert_lvalue_to_rvalue (OMP_CLAUSE_LOCATION (c
),
12499 expr
, false, false);
12505 ret
= handle_omp_array_sections_1 (c
, TREE_CHAIN (t
), types
,
12506 maybe_zero_len
, first_non_one
, ort
);
12507 if (ret
== error_mark_node
|| ret
== NULL_TREE
)
12510 type
= TREE_TYPE (ret
);
12511 low_bound
= TREE_PURPOSE (t
);
12512 length
= TREE_VALUE (t
);
12514 if (low_bound
== error_mark_node
|| length
== error_mark_node
)
12515 return error_mark_node
;
12517 if (low_bound
&& !INTEGRAL_TYPE_P (TREE_TYPE (low_bound
)))
12519 error_at (OMP_CLAUSE_LOCATION (c
),
12520 "low bound %qE of array section does not have integral type",
12522 return error_mark_node
;
12524 if (length
&& !INTEGRAL_TYPE_P (TREE_TYPE (length
)))
12526 error_at (OMP_CLAUSE_LOCATION (c
),
12527 "length %qE of array section does not have integral type",
12529 return error_mark_node
;
12532 && TREE_CODE (low_bound
) == INTEGER_CST
12533 && TYPE_PRECISION (TREE_TYPE (low_bound
))
12534 > TYPE_PRECISION (sizetype
))
12535 low_bound
= fold_convert (sizetype
, low_bound
);
12537 && TREE_CODE (length
) == INTEGER_CST
12538 && TYPE_PRECISION (TREE_TYPE (length
))
12539 > TYPE_PRECISION (sizetype
))
12540 length
= fold_convert (sizetype
, length
);
12541 if (low_bound
== NULL_TREE
)
12542 low_bound
= integer_zero_node
;
12544 if (length
!= NULL_TREE
)
12546 if (!integer_nonzerop (length
))
12548 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
12549 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
12551 if (integer_zerop (length
))
12553 error_at (OMP_CLAUSE_LOCATION (c
),
12554 "zero length array section in %qs clause",
12555 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
12556 return error_mark_node
;
12560 maybe_zero_len
= true;
12562 if (first_non_one
== types
.length ()
12563 && (TREE_CODE (length
) != INTEGER_CST
|| integer_onep (length
)))
12566 if (TREE_CODE (type
) == ARRAY_TYPE
)
12568 if (length
== NULL_TREE
12569 && (TYPE_DOMAIN (type
) == NULL_TREE
12570 || TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) == NULL_TREE
))
12572 error_at (OMP_CLAUSE_LOCATION (c
),
12573 "for unknown bound array type length expression must "
12575 return error_mark_node
;
12577 if (TREE_CODE (low_bound
) == INTEGER_CST
12578 && tree_int_cst_sgn (low_bound
) == -1)
12580 error_at (OMP_CLAUSE_LOCATION (c
),
12581 "negative low bound in array section in %qs clause",
12582 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
12583 return error_mark_node
;
12585 if (length
!= NULL_TREE
12586 && TREE_CODE (length
) == INTEGER_CST
12587 && tree_int_cst_sgn (length
) == -1)
12589 error_at (OMP_CLAUSE_LOCATION (c
),
12590 "negative length in array section in %qs clause",
12591 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
12592 return error_mark_node
;
12594 if (TYPE_DOMAIN (type
)
12595 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
))
12596 && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)))
12600 = fold_convert (sizetype
, TYPE_MAX_VALUE (TYPE_DOMAIN (type
)));
12601 size
= size_binop (PLUS_EXPR
, size
, size_one_node
);
12602 if (TREE_CODE (low_bound
) == INTEGER_CST
)
12604 if (tree_int_cst_lt (size
, low_bound
))
12606 error_at (OMP_CLAUSE_LOCATION (c
),
12607 "low bound %qE above array section size "
12608 "in %qs clause", low_bound
,
12609 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
12610 return error_mark_node
;
12612 if (tree_int_cst_equal (size
, low_bound
))
12614 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
12615 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
12617 error_at (OMP_CLAUSE_LOCATION (c
),
12618 "zero length array section in %qs clause",
12619 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
12620 return error_mark_node
;
12622 maybe_zero_len
= true;
12624 else if (length
== NULL_TREE
12625 && first_non_one
== types
.length ()
12626 && tree_int_cst_equal
12627 (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)),
12631 else if (length
== NULL_TREE
)
12633 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
12634 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_REDUCTION
)
12635 maybe_zero_len
= true;
12636 if (first_non_one
== types
.length ())
12639 if (length
&& TREE_CODE (length
) == INTEGER_CST
)
12641 if (tree_int_cst_lt (size
, length
))
12643 error_at (OMP_CLAUSE_LOCATION (c
),
12644 "length %qE above array section size "
12645 "in %qs clause", length
,
12646 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
12647 return error_mark_node
;
12649 if (TREE_CODE (low_bound
) == INTEGER_CST
)
12652 = size_binop (PLUS_EXPR
,
12653 fold_convert (sizetype
, low_bound
),
12654 fold_convert (sizetype
, length
));
12655 if (TREE_CODE (lbpluslen
) == INTEGER_CST
12656 && tree_int_cst_lt (size
, lbpluslen
))
12658 error_at (OMP_CLAUSE_LOCATION (c
),
12659 "high bound %qE above array section size "
12660 "in %qs clause", lbpluslen
,
12661 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
12662 return error_mark_node
;
12667 else if (length
== NULL_TREE
)
12669 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
12670 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_REDUCTION
)
12671 maybe_zero_len
= true;
12672 if (first_non_one
== types
.length ())
12676 /* For [lb:] we will need to evaluate lb more than once. */
12677 if (length
== NULL_TREE
&& OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
)
12679 tree lb
= save_expr (low_bound
);
12680 if (lb
!= low_bound
)
12682 TREE_PURPOSE (t
) = lb
;
12687 else if (TREE_CODE (type
) == POINTER_TYPE
)
12689 if (length
== NULL_TREE
)
12691 error_at (OMP_CLAUSE_LOCATION (c
),
12692 "for pointer type length expression must be specified");
12693 return error_mark_node
;
12695 if (length
!= NULL_TREE
12696 && TREE_CODE (length
) == INTEGER_CST
12697 && tree_int_cst_sgn (length
) == -1)
12699 error_at (OMP_CLAUSE_LOCATION (c
),
12700 "negative length in array section in %qs clause",
12701 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
12702 return error_mark_node
;
12704 /* If there is a pointer type anywhere but in the very first
12705 array-section-subscript, the array section can't be contiguous. */
12706 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
12707 && TREE_CODE (TREE_CHAIN (t
)) == TREE_LIST
)
12709 error_at (OMP_CLAUSE_LOCATION (c
),
12710 "array section is not contiguous in %qs clause",
12711 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
12712 return error_mark_node
;
12717 error_at (OMP_CLAUSE_LOCATION (c
),
12718 "%qE does not have pointer or array type", ret
);
12719 return error_mark_node
;
12721 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
)
12722 types
.safe_push (TREE_TYPE (ret
));
12723 /* We will need to evaluate lb more than once. */
12724 tree lb
= save_expr (low_bound
);
12725 if (lb
!= low_bound
)
12727 TREE_PURPOSE (t
) = lb
;
12730 ret
= build_array_ref (OMP_CLAUSE_LOCATION (c
), ret
, low_bound
);
12734 /* Handle array sections for clause C. */
12737 handle_omp_array_sections (tree c
, enum c_omp_region_type ort
)
12739 bool maybe_zero_len
= false;
12740 unsigned int first_non_one
= 0;
12741 auto_vec
<tree
, 10> types
;
12742 tree first
= handle_omp_array_sections_1 (c
, OMP_CLAUSE_DECL (c
), types
,
12743 maybe_zero_len
, first_non_one
,
12745 if (first
== error_mark_node
)
12747 if (first
== NULL_TREE
)
12749 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
)
12751 tree t
= OMP_CLAUSE_DECL (c
);
12752 tree tem
= NULL_TREE
;
12753 /* Need to evaluate side effects in the length expressions
12755 while (TREE_CODE (t
) == TREE_LIST
)
12757 if (TREE_VALUE (t
) && TREE_SIDE_EFFECTS (TREE_VALUE (t
)))
12759 if (tem
== NULL_TREE
)
12760 tem
= TREE_VALUE (t
);
12762 tem
= build2 (COMPOUND_EXPR
, TREE_TYPE (tem
),
12763 TREE_VALUE (t
), tem
);
12765 t
= TREE_CHAIN (t
);
12768 first
= build2 (COMPOUND_EXPR
, TREE_TYPE (first
), tem
, first
);
12769 first
= c_fully_fold (first
, false, NULL
, true);
12770 OMP_CLAUSE_DECL (c
) = first
;
12774 unsigned int num
= types
.length (), i
;
12775 tree t
, side_effects
= NULL_TREE
, size
= NULL_TREE
;
12776 tree condition
= NULL_TREE
;
12778 if (int_size_in_bytes (TREE_TYPE (first
)) <= 0)
12779 maybe_zero_len
= true;
12781 for (i
= num
, t
= OMP_CLAUSE_DECL (c
); i
> 0;
12782 t
= TREE_CHAIN (t
))
12784 tree low_bound
= TREE_PURPOSE (t
);
12785 tree length
= TREE_VALUE (t
);
12789 && TREE_CODE (low_bound
) == INTEGER_CST
12790 && TYPE_PRECISION (TREE_TYPE (low_bound
))
12791 > TYPE_PRECISION (sizetype
))
12792 low_bound
= fold_convert (sizetype
, low_bound
);
12794 && TREE_CODE (length
) == INTEGER_CST
12795 && TYPE_PRECISION (TREE_TYPE (length
))
12796 > TYPE_PRECISION (sizetype
))
12797 length
= fold_convert (sizetype
, length
);
12798 if (low_bound
== NULL_TREE
)
12799 low_bound
= integer_zero_node
;
12800 if (!maybe_zero_len
&& i
> first_non_one
)
12802 if (integer_nonzerop (low_bound
))
12803 goto do_warn_noncontiguous
;
12804 if (length
!= NULL_TREE
12805 && TREE_CODE (length
) == INTEGER_CST
12806 && TYPE_DOMAIN (types
[i
])
12807 && TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
]))
12808 && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])))
12812 size
= size_binop (PLUS_EXPR
,
12813 TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])),
12815 if (!tree_int_cst_equal (length
, size
))
12817 do_warn_noncontiguous
:
12818 error_at (OMP_CLAUSE_LOCATION (c
),
12819 "array section is not contiguous in %qs "
12821 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
12825 if (length
!= NULL_TREE
12826 && TREE_SIDE_EFFECTS (length
))
12828 if (side_effects
== NULL_TREE
)
12829 side_effects
= length
;
12831 side_effects
= build2 (COMPOUND_EXPR
,
12832 TREE_TYPE (side_effects
),
12833 length
, side_effects
);
12840 if (i
> first_non_one
12841 && ((length
&& integer_nonzerop (length
))
12842 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
))
12845 l
= fold_convert (sizetype
, length
);
12848 l
= size_binop (PLUS_EXPR
,
12849 TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])),
12851 l
= size_binop (MINUS_EXPR
, l
,
12852 fold_convert (sizetype
, low_bound
));
12854 if (i
> first_non_one
)
12856 l
= fold_build2 (NE_EXPR
, boolean_type_node
, l
,
12858 if (condition
== NULL_TREE
)
12861 condition
= fold_build2 (BIT_AND_EXPR
, boolean_type_node
,
12864 else if (size
== NULL_TREE
)
12866 size
= size_in_bytes (TREE_TYPE (types
[i
]));
12867 tree eltype
= TREE_TYPE (types
[num
- 1]);
12868 while (TREE_CODE (eltype
) == ARRAY_TYPE
)
12869 eltype
= TREE_TYPE (eltype
);
12870 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
12872 if (integer_zerop (size
)
12873 || integer_zerop (size_in_bytes (eltype
)))
12875 error_at (OMP_CLAUSE_LOCATION (c
),
12876 "zero length array section in %qs clause",
12877 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
12878 return error_mark_node
;
12880 size
= size_binop (EXACT_DIV_EXPR
, size
,
12881 size_in_bytes (eltype
));
12883 size
= size_binop (MULT_EXPR
, size
, l
);
12885 size
= fold_build3 (COND_EXPR
, sizetype
, condition
,
12886 size
, size_zero_node
);
12889 size
= size_binop (MULT_EXPR
, size
, l
);
12893 size
= build2 (COMPOUND_EXPR
, sizetype
, side_effects
, size
);
12894 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
12896 size
= size_binop (MINUS_EXPR
, size
, size_one_node
);
12897 size
= c_fully_fold (size
, false, NULL
);
12898 tree index_type
= build_index_type (size
);
12899 tree eltype
= TREE_TYPE (first
);
12900 while (TREE_CODE (eltype
) == ARRAY_TYPE
)
12901 eltype
= TREE_TYPE (eltype
);
12902 tree type
= build_array_type (eltype
, index_type
);
12903 tree ptype
= build_pointer_type (eltype
);
12904 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
12905 t
= build_fold_addr_expr (t
);
12906 tree t2
= build_fold_addr_expr (first
);
12907 t2
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
12908 ptrdiff_type_node
, t2
);
12909 t2
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MINUS_EXPR
,
12910 ptrdiff_type_node
, t2
,
12911 fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
12912 ptrdiff_type_node
, t
));
12913 t2
= c_fully_fold (t2
, false, NULL
);
12914 if (tree_fits_shwi_p (t2
))
12915 t
= build2 (MEM_REF
, type
, t
,
12916 build_int_cst (ptype
, tree_to_shwi (t2
)));
12919 t2
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
), sizetype
, t2
);
12920 t
= build2_loc (OMP_CLAUSE_LOCATION (c
), POINTER_PLUS_EXPR
,
12921 TREE_TYPE (t
), t
, t2
);
12922 t
= build2 (MEM_REF
, type
, t
, build_int_cst (ptype
, 0));
12924 OMP_CLAUSE_DECL (c
) = t
;
12927 first
= c_fully_fold (first
, false, NULL
);
12928 OMP_CLAUSE_DECL (c
) = first
;
12930 size
= c_fully_fold (size
, false, NULL
);
12931 OMP_CLAUSE_SIZE (c
) = size
;
12932 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
12933 || (TREE_CODE (t
) == COMPONENT_REF
12934 && TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
))
12936 gcc_assert (OMP_CLAUSE_MAP_KIND (c
) != GOMP_MAP_FORCE_DEVICEPTR
);
12937 if (ort
== C_ORT_OMP
|| ort
== C_ORT_ACC
)
12938 switch (OMP_CLAUSE_MAP_KIND (c
))
12940 case GOMP_MAP_ALLOC
:
12942 case GOMP_MAP_FROM
:
12943 case GOMP_MAP_TOFROM
:
12944 case GOMP_MAP_ALWAYS_TO
:
12945 case GOMP_MAP_ALWAYS_FROM
:
12946 case GOMP_MAP_ALWAYS_TOFROM
:
12947 case GOMP_MAP_RELEASE
:
12948 case GOMP_MAP_DELETE
:
12949 case GOMP_MAP_FORCE_TO
:
12950 case GOMP_MAP_FORCE_FROM
:
12951 case GOMP_MAP_FORCE_TOFROM
:
12952 case GOMP_MAP_FORCE_PRESENT
:
12953 OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c
) = 1;
12958 tree c2
= build_omp_clause (OMP_CLAUSE_LOCATION (c
), OMP_CLAUSE_MAP
);
12959 if (ort
!= C_ORT_OMP
&& ort
!= C_ORT_ACC
)
12960 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_POINTER
);
12961 else if (TREE_CODE (t
) == COMPONENT_REF
)
12962 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_ALWAYS_POINTER
);
12964 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_FIRSTPRIVATE_POINTER
);
12965 if (OMP_CLAUSE_MAP_KIND (c2
) != GOMP_MAP_FIRSTPRIVATE_POINTER
12966 && !c_mark_addressable (t
))
12968 OMP_CLAUSE_DECL (c2
) = t
;
12969 t
= build_fold_addr_expr (first
);
12970 t
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
), ptrdiff_type_node
, t
);
12971 tree ptr
= OMP_CLAUSE_DECL (c2
);
12972 if (!POINTER_TYPE_P (TREE_TYPE (ptr
)))
12973 ptr
= build_fold_addr_expr (ptr
);
12974 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MINUS_EXPR
,
12975 ptrdiff_type_node
, t
,
12976 fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
12977 ptrdiff_type_node
, ptr
));
12978 t
= c_fully_fold (t
, false, NULL
);
12979 OMP_CLAUSE_SIZE (c2
) = t
;
12980 OMP_CLAUSE_CHAIN (c2
) = OMP_CLAUSE_CHAIN (c
);
12981 OMP_CLAUSE_CHAIN (c
) = c2
;
12986 /* Helper function of finish_omp_clauses. Clone STMT as if we were making
12987 an inline call. But, remap
12988 the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER
12989 and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL. */
12992 c_clone_omp_udr (tree stmt
, tree omp_decl1
, tree omp_decl2
,
12993 tree decl
, tree placeholder
)
12996 hash_map
<tree
, tree
> decl_map
;
12998 decl_map
.put (omp_decl1
, placeholder
);
12999 decl_map
.put (omp_decl2
, decl
);
13000 memset (&id
, 0, sizeof (id
));
13001 id
.src_fn
= DECL_CONTEXT (omp_decl1
);
13002 id
.dst_fn
= current_function_decl
;
13003 id
.src_cfun
= DECL_STRUCT_FUNCTION (id
.src_fn
);
13004 id
.decl_map
= &decl_map
;
13006 id
.copy_decl
= copy_decl_no_change
;
13007 id
.transform_call_graph_edges
= CB_CGE_DUPLICATE
;
13008 id
.transform_new_cfg
= true;
13009 id
.transform_return_to_modify
= false;
13010 id
.transform_lang_insert_block
= NULL
;
13012 walk_tree (&stmt
, copy_tree_body_r
, &id
, NULL
);
13016 /* Helper function of c_finish_omp_clauses, called via walk_tree.
13017 Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP. */
13020 c_find_omp_placeholder_r (tree
*tp
, int *, void *data
)
13022 if (*tp
== (tree
) data
)
13027 /* For all elements of CLAUSES, validate them against their constraints.
13028 Remove any elements from the list that are invalid. */
13031 c_finish_omp_clauses (tree clauses
, enum c_omp_region_type ort
)
13033 bitmap_head generic_head
, firstprivate_head
, lastprivate_head
;
13034 bitmap_head aligned_head
, map_head
, map_field_head
, oacc_reduction_head
;
13035 tree c
, t
, type
, *pc
;
13036 tree simdlen
= NULL_TREE
, safelen
= NULL_TREE
;
13037 bool branch_seen
= false;
13038 bool copyprivate_seen
= false;
13039 bool linear_variable_step_check
= false;
13040 tree
*nowait_clause
= NULL
;
13041 bool ordered_seen
= false;
13042 tree schedule_clause
= NULL_TREE
;
13043 bool oacc_async
= false;
13045 bitmap_obstack_initialize (NULL
);
13046 bitmap_initialize (&generic_head
, &bitmap_default_obstack
);
13047 bitmap_initialize (&firstprivate_head
, &bitmap_default_obstack
);
13048 bitmap_initialize (&lastprivate_head
, &bitmap_default_obstack
);
13049 bitmap_initialize (&aligned_head
, &bitmap_default_obstack
);
13050 bitmap_initialize (&map_head
, &bitmap_default_obstack
);
13051 bitmap_initialize (&map_field_head
, &bitmap_default_obstack
);
13052 bitmap_initialize (&oacc_reduction_head
, &bitmap_default_obstack
);
13054 if (ort
& C_ORT_ACC
)
13055 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
13056 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_ASYNC
)
13062 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
13064 bool remove
= false;
13065 bool need_complete
= false;
13066 bool need_implicitly_determined
= false;
13068 switch (OMP_CLAUSE_CODE (c
))
13070 case OMP_CLAUSE_SHARED
:
13071 need_implicitly_determined
= true;
13072 goto check_dup_generic
;
13074 case OMP_CLAUSE_PRIVATE
:
13075 need_complete
= true;
13076 need_implicitly_determined
= true;
13077 goto check_dup_generic
;
13079 case OMP_CLAUSE_REDUCTION
:
13080 need_implicitly_determined
= true;
13081 t
= OMP_CLAUSE_DECL (c
);
13082 if (TREE_CODE (t
) == TREE_LIST
)
13084 if (handle_omp_array_sections (c
, ort
))
13090 t
= OMP_CLAUSE_DECL (c
);
13092 t
= require_complete_type (OMP_CLAUSE_LOCATION (c
), t
);
13093 if (t
== error_mark_node
)
13099 c_mark_addressable (t
);
13100 type
= TREE_TYPE (t
);
13101 if (TREE_CODE (t
) == MEM_REF
)
13102 type
= TREE_TYPE (type
);
13103 if (TREE_CODE (type
) == ARRAY_TYPE
)
13105 tree oatype
= type
;
13106 gcc_assert (TREE_CODE (t
) != MEM_REF
);
13107 while (TREE_CODE (type
) == ARRAY_TYPE
)
13108 type
= TREE_TYPE (type
);
13109 if (integer_zerop (TYPE_SIZE_UNIT (type
)))
13111 error_at (OMP_CLAUSE_LOCATION (c
),
13112 "%qD in %<reduction%> clause is a zero size array",
13117 tree size
= size_binop (EXACT_DIV_EXPR
, TYPE_SIZE_UNIT (oatype
),
13118 TYPE_SIZE_UNIT (type
));
13119 if (integer_zerop (size
))
13121 error_at (OMP_CLAUSE_LOCATION (c
),
13122 "%qD in %<reduction%> clause is a zero size array",
13127 size
= size_binop (MINUS_EXPR
, size
, size_one_node
);
13128 tree index_type
= build_index_type (size
);
13129 tree atype
= build_array_type (type
, index_type
);
13130 tree ptype
= build_pointer_type (type
);
13131 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
13132 t
= build_fold_addr_expr (t
);
13133 t
= build2 (MEM_REF
, atype
, t
, build_int_cst (ptype
, 0));
13134 OMP_CLAUSE_DECL (c
) = t
;
13136 if (TYPE_ATOMIC (type
))
13138 error_at (OMP_CLAUSE_LOCATION (c
),
13139 "%<_Atomic%> %qE in %<reduction%> clause", t
);
13143 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) == NULL_TREE
13144 && (FLOAT_TYPE_P (type
)
13145 || TREE_CODE (type
) == COMPLEX_TYPE
))
13147 enum tree_code r_code
= OMP_CLAUSE_REDUCTION_CODE (c
);
13148 const char *r_name
= NULL
;
13157 if (TREE_CODE (type
) == COMPLEX_TYPE
)
13161 if (TREE_CODE (type
) == COMPLEX_TYPE
)
13173 case TRUTH_ANDIF_EXPR
:
13174 if (FLOAT_TYPE_P (type
))
13177 case TRUTH_ORIF_EXPR
:
13178 if (FLOAT_TYPE_P (type
))
13182 gcc_unreachable ();
13186 error_at (OMP_CLAUSE_LOCATION (c
),
13187 "%qE has invalid type for %<reduction(%s)%>",
13193 else if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) == error_mark_node
)
13195 error_at (OMP_CLAUSE_LOCATION (c
),
13196 "user defined reduction not found for %qE", t
);
13200 else if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
))
13202 tree list
= OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
);
13203 type
= TYPE_MAIN_VARIANT (type
);
13204 tree placeholder
= build_decl (OMP_CLAUSE_LOCATION (c
),
13205 VAR_DECL
, NULL_TREE
, type
);
13206 tree decl_placeholder
= NULL_TREE
;
13207 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = placeholder
;
13208 DECL_ARTIFICIAL (placeholder
) = 1;
13209 DECL_IGNORED_P (placeholder
) = 1;
13210 if (TREE_CODE (t
) == MEM_REF
)
13212 decl_placeholder
= build_decl (OMP_CLAUSE_LOCATION (c
),
13213 VAR_DECL
, NULL_TREE
, type
);
13214 OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c
) = decl_placeholder
;
13215 DECL_ARTIFICIAL (decl_placeholder
) = 1;
13216 DECL_IGNORED_P (decl_placeholder
) = 1;
13218 if (TREE_ADDRESSABLE (TREE_VEC_ELT (list
, 0)))
13219 c_mark_addressable (placeholder
);
13220 if (TREE_ADDRESSABLE (TREE_VEC_ELT (list
, 1)))
13221 c_mark_addressable (decl_placeholder
? decl_placeholder
13222 : OMP_CLAUSE_DECL (c
));
13223 OMP_CLAUSE_REDUCTION_MERGE (c
)
13224 = c_clone_omp_udr (TREE_VEC_ELT (list
, 2),
13225 TREE_VEC_ELT (list
, 0),
13226 TREE_VEC_ELT (list
, 1),
13227 decl_placeholder
? decl_placeholder
13228 : OMP_CLAUSE_DECL (c
), placeholder
);
13229 OMP_CLAUSE_REDUCTION_MERGE (c
)
13230 = build3_loc (OMP_CLAUSE_LOCATION (c
), BIND_EXPR
,
13231 void_type_node
, NULL_TREE
,
13232 OMP_CLAUSE_REDUCTION_MERGE (c
), NULL_TREE
);
13233 TREE_SIDE_EFFECTS (OMP_CLAUSE_REDUCTION_MERGE (c
)) = 1;
13234 if (TREE_VEC_LENGTH (list
) == 6)
13236 if (TREE_ADDRESSABLE (TREE_VEC_ELT (list
, 3)))
13237 c_mark_addressable (decl_placeholder
? decl_placeholder
13238 : OMP_CLAUSE_DECL (c
));
13239 if (TREE_ADDRESSABLE (TREE_VEC_ELT (list
, 4)))
13240 c_mark_addressable (placeholder
);
13241 tree init
= TREE_VEC_ELT (list
, 5);
13242 if (init
== error_mark_node
)
13243 init
= DECL_INITIAL (TREE_VEC_ELT (list
, 3));
13244 OMP_CLAUSE_REDUCTION_INIT (c
)
13245 = c_clone_omp_udr (init
, TREE_VEC_ELT (list
, 4),
13246 TREE_VEC_ELT (list
, 3),
13247 decl_placeholder
? decl_placeholder
13248 : OMP_CLAUSE_DECL (c
), placeholder
);
13249 if (TREE_VEC_ELT (list
, 5) == error_mark_node
)
13251 tree v
= decl_placeholder
? decl_placeholder
: t
;
13252 OMP_CLAUSE_REDUCTION_INIT (c
)
13253 = build2 (INIT_EXPR
, TREE_TYPE (v
), v
,
13254 OMP_CLAUSE_REDUCTION_INIT (c
));
13256 if (walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c
),
13257 c_find_omp_placeholder_r
,
13258 placeholder
, NULL
))
13259 OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c
) = 1;
13264 tree v
= decl_placeholder
? decl_placeholder
: t
;
13265 if (AGGREGATE_TYPE_P (TREE_TYPE (v
)))
13266 init
= build_constructor (TREE_TYPE (v
), NULL
);
13268 init
= fold_convert (TREE_TYPE (v
), integer_zero_node
);
13269 OMP_CLAUSE_REDUCTION_INIT (c
)
13270 = build2 (INIT_EXPR
, TREE_TYPE (v
), v
, init
);
13272 OMP_CLAUSE_REDUCTION_INIT (c
)
13273 = build3_loc (OMP_CLAUSE_LOCATION (c
), BIND_EXPR
,
13274 void_type_node
, NULL_TREE
,
13275 OMP_CLAUSE_REDUCTION_INIT (c
), NULL_TREE
);
13276 TREE_SIDE_EFFECTS (OMP_CLAUSE_REDUCTION_INIT (c
)) = 1;
13278 if (TREE_CODE (t
) == MEM_REF
)
13280 if (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t
))) == NULL_TREE
13281 || TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t
))))
13284 sorry ("variable length element type in array "
13285 "%<reduction%> clause");
13289 t
= TREE_OPERAND (t
, 0);
13290 if (TREE_CODE (t
) == POINTER_PLUS_EXPR
)
13291 t
= TREE_OPERAND (t
, 0);
13292 if (TREE_CODE (t
) == ADDR_EXPR
)
13293 t
= TREE_OPERAND (t
, 0);
13295 goto check_dup_generic_t
;
13297 case OMP_CLAUSE_COPYPRIVATE
:
13298 copyprivate_seen
= true;
13301 error_at (OMP_CLAUSE_LOCATION (*nowait_clause
),
13302 "%<nowait%> clause must not be used together "
13303 "with %<copyprivate%>");
13304 *nowait_clause
= OMP_CLAUSE_CHAIN (*nowait_clause
);
13305 nowait_clause
= NULL
;
13307 goto check_dup_generic
;
13309 case OMP_CLAUSE_COPYIN
:
13310 t
= OMP_CLAUSE_DECL (c
);
13311 if (!VAR_P (t
) || !DECL_THREAD_LOCAL_P (t
))
13313 error_at (OMP_CLAUSE_LOCATION (c
),
13314 "%qE must be %<threadprivate%> for %<copyin%>", t
);
13318 goto check_dup_generic
;
13320 case OMP_CLAUSE_LINEAR
:
13321 if (ort
!= C_ORT_OMP_DECLARE_SIMD
)
13322 need_implicitly_determined
= true;
13323 t
= OMP_CLAUSE_DECL (c
);
13324 if (ort
!= C_ORT_OMP_DECLARE_SIMD
13325 && OMP_CLAUSE_LINEAR_KIND (c
) != OMP_CLAUSE_LINEAR_DEFAULT
)
13327 error_at (OMP_CLAUSE_LOCATION (c
),
13328 "modifier should not be specified in %<linear%> "
13329 "clause on %<simd%> or %<for%> constructs");
13330 OMP_CLAUSE_LINEAR_KIND (c
) = OMP_CLAUSE_LINEAR_DEFAULT
;
13332 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
13333 && TREE_CODE (TREE_TYPE (t
)) != POINTER_TYPE
)
13335 error_at (OMP_CLAUSE_LOCATION (c
),
13336 "linear clause applied to non-integral non-pointer "
13337 "variable with type %qT", TREE_TYPE (t
));
13341 if (TYPE_ATOMIC (TREE_TYPE (t
)))
13343 error_at (OMP_CLAUSE_LOCATION (c
),
13344 "%<_Atomic%> %qD in %<linear%> clause", t
);
13348 if (ort
== C_ORT_OMP_DECLARE_SIMD
)
13350 tree s
= OMP_CLAUSE_LINEAR_STEP (c
);
13351 if (TREE_CODE (s
) == PARM_DECL
)
13353 OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c
) = 1;
13354 /* map_head bitmap is used as uniform_head if
13356 if (!bitmap_bit_p (&map_head
, DECL_UID (s
)))
13357 linear_variable_step_check
= true;
13358 goto check_dup_generic
;
13360 if (TREE_CODE (s
) != INTEGER_CST
)
13362 error_at (OMP_CLAUSE_LOCATION (c
),
13363 "%<linear%> clause step %qE is neither constant "
13364 "nor a parameter", s
);
13369 if (TREE_CODE (TREE_TYPE (OMP_CLAUSE_DECL (c
))) == POINTER_TYPE
)
13371 tree s
= OMP_CLAUSE_LINEAR_STEP (c
);
13372 s
= pointer_int_sum (OMP_CLAUSE_LOCATION (c
), PLUS_EXPR
,
13373 OMP_CLAUSE_DECL (c
), s
);
13374 s
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MINUS_EXPR
,
13375 sizetype
, fold_convert (sizetype
, s
),
13377 (sizetype
, OMP_CLAUSE_DECL (c
)));
13378 if (s
== error_mark_node
)
13380 OMP_CLAUSE_LINEAR_STEP (c
) = s
;
13383 OMP_CLAUSE_LINEAR_STEP (c
)
13384 = fold_convert (TREE_TYPE (t
), OMP_CLAUSE_LINEAR_STEP (c
));
13385 goto check_dup_generic
;
13388 t
= OMP_CLAUSE_DECL (c
);
13389 check_dup_generic_t
:
13390 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
13392 error_at (OMP_CLAUSE_LOCATION (c
),
13393 "%qE is not a variable in clause %qs", t
,
13394 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
13397 else if (ort
== C_ORT_ACC
13398 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
13400 if (bitmap_bit_p (&oacc_reduction_head
, DECL_UID (t
)))
13402 error ("%qD appears more than once in reduction clauses", t
);
13406 bitmap_set_bit (&oacc_reduction_head
, DECL_UID (t
));
13408 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
13409 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
))
13410 || bitmap_bit_p (&lastprivate_head
, DECL_UID (t
)))
13412 error_at (OMP_CLAUSE_LOCATION (c
),
13413 "%qE appears more than once in data clauses", t
);
13416 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_PRIVATE
13417 && bitmap_bit_p (&map_head
, DECL_UID (t
)))
13419 if (ort
== C_ORT_ACC
)
13420 error ("%qD appears more than once in data clauses", t
);
13422 error ("%qD appears both in data and map clauses", t
);
13426 bitmap_set_bit (&generic_head
, DECL_UID (t
));
13429 case OMP_CLAUSE_FIRSTPRIVATE
:
13430 t
= OMP_CLAUSE_DECL (c
);
13431 need_complete
= true;
13432 need_implicitly_determined
= true;
13433 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
13435 error_at (OMP_CLAUSE_LOCATION (c
),
13436 "%qE is not a variable in clause %<firstprivate%>", t
);
13439 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
13440 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
13442 error_at (OMP_CLAUSE_LOCATION (c
),
13443 "%qE appears more than once in data clauses", t
);
13446 else if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
13448 if (ort
== C_ORT_ACC
)
13449 error ("%qD appears more than once in data clauses", t
);
13451 error ("%qD appears both in data and map clauses", t
);
13455 bitmap_set_bit (&firstprivate_head
, DECL_UID (t
));
13458 case OMP_CLAUSE_LASTPRIVATE
:
13459 t
= OMP_CLAUSE_DECL (c
);
13460 need_complete
= true;
13461 need_implicitly_determined
= true;
13462 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
13464 error_at (OMP_CLAUSE_LOCATION (c
),
13465 "%qE is not a variable in clause %<lastprivate%>", t
);
13468 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
13469 || bitmap_bit_p (&lastprivate_head
, DECL_UID (t
)))
13471 error_at (OMP_CLAUSE_LOCATION (c
),
13472 "%qE appears more than once in data clauses", t
);
13476 bitmap_set_bit (&lastprivate_head
, DECL_UID (t
));
13479 case OMP_CLAUSE_ALIGNED
:
13480 t
= OMP_CLAUSE_DECL (c
);
13481 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
13483 error_at (OMP_CLAUSE_LOCATION (c
),
13484 "%qE is not a variable in %<aligned%> clause", t
);
13487 else if (!POINTER_TYPE_P (TREE_TYPE (t
))
13488 && TREE_CODE (TREE_TYPE (t
)) != ARRAY_TYPE
)
13490 error_at (OMP_CLAUSE_LOCATION (c
),
13491 "%qE in %<aligned%> clause is neither a pointer nor "
13495 else if (TYPE_ATOMIC (TREE_TYPE (t
)))
13497 error_at (OMP_CLAUSE_LOCATION (c
),
13498 "%<_Atomic%> %qD in %<aligned%> clause", t
);
13502 else if (bitmap_bit_p (&aligned_head
, DECL_UID (t
)))
13504 error_at (OMP_CLAUSE_LOCATION (c
),
13505 "%qE appears more than once in %<aligned%> clauses",
13510 bitmap_set_bit (&aligned_head
, DECL_UID (t
));
13513 case OMP_CLAUSE_DEPEND
:
13514 t
= OMP_CLAUSE_DECL (c
);
13515 if (t
== NULL_TREE
)
13517 gcc_assert (OMP_CLAUSE_DEPEND_KIND (c
)
13518 == OMP_CLAUSE_DEPEND_SOURCE
);
13521 if (OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_SINK
)
13523 gcc_assert (TREE_CODE (t
) == TREE_LIST
);
13524 for (; t
; t
= TREE_CHAIN (t
))
13526 tree decl
= TREE_VALUE (t
);
13527 if (TREE_CODE (TREE_TYPE (decl
)) == POINTER_TYPE
)
13529 tree offset
= TREE_PURPOSE (t
);
13530 bool neg
= wi::neg_p (wi::to_wide (offset
));
13531 offset
= fold_unary (ABS_EXPR
, TREE_TYPE (offset
), offset
);
13532 tree t2
= pointer_int_sum (OMP_CLAUSE_LOCATION (c
),
13533 neg
? MINUS_EXPR
: PLUS_EXPR
,
13535 t2
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MINUS_EXPR
,
13537 fold_convert (sizetype
, t2
),
13538 fold_convert (sizetype
, decl
));
13539 if (t2
== error_mark_node
)
13544 TREE_PURPOSE (t
) = t2
;
13549 if (TREE_CODE (t
) == TREE_LIST
)
13551 if (handle_omp_array_sections (c
, ort
))
13555 if (t
== error_mark_node
)
13557 else if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
13559 error_at (OMP_CLAUSE_LOCATION (c
),
13560 "%qE is not a variable in %<depend%> clause", t
);
13563 else if (!c_mark_addressable (t
))
13567 case OMP_CLAUSE_MAP
:
13568 case OMP_CLAUSE_TO
:
13569 case OMP_CLAUSE_FROM
:
13570 case OMP_CLAUSE__CACHE_
:
13571 t
= OMP_CLAUSE_DECL (c
);
13572 if (TREE_CODE (t
) == TREE_LIST
)
13574 if (handle_omp_array_sections (c
, ort
))
13578 t
= OMP_CLAUSE_DECL (c
);
13579 if (!lang_hooks
.types
.omp_mappable_type (TREE_TYPE (t
)))
13581 error_at (OMP_CLAUSE_LOCATION (c
),
13582 "array section does not have mappable type "
13584 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
13587 else if (TYPE_ATOMIC (TREE_TYPE (t
)))
13589 error_at (OMP_CLAUSE_LOCATION (c
),
13590 "%<_Atomic%> %qE in %qs clause", t
,
13591 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
13594 while (TREE_CODE (t
) == ARRAY_REF
)
13595 t
= TREE_OPERAND (t
, 0);
13596 if (TREE_CODE (t
) == COMPONENT_REF
13597 && TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
13599 while (TREE_CODE (t
) == COMPONENT_REF
)
13600 t
= TREE_OPERAND (t
, 0);
13601 if (bitmap_bit_p (&map_field_head
, DECL_UID (t
)))
13603 if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
13605 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
13606 error ("%qD appears more than once in motion"
13608 else if (ort
== C_ORT_ACC
)
13609 error ("%qD appears more than once in data"
13612 error ("%qD appears more than once in map"
13618 bitmap_set_bit (&map_head
, DECL_UID (t
));
13619 bitmap_set_bit (&map_field_head
, DECL_UID (t
));
13625 if (t
== error_mark_node
)
13630 if (TREE_CODE (t
) == COMPONENT_REF
13631 && (ort
& C_ORT_OMP
)
13632 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE__CACHE_
)
13634 if (DECL_BIT_FIELD (TREE_OPERAND (t
, 1)))
13636 error_at (OMP_CLAUSE_LOCATION (c
),
13637 "bit-field %qE in %qs clause",
13638 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
13641 else if (!lang_hooks
.types
.omp_mappable_type (TREE_TYPE (t
)))
13643 error_at (OMP_CLAUSE_LOCATION (c
),
13644 "%qE does not have a mappable type in %qs clause",
13645 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
13648 else if (TYPE_ATOMIC (TREE_TYPE (t
)))
13650 error_at (OMP_CLAUSE_LOCATION (c
),
13651 "%<_Atomic%> %qE in %qs clause", t
,
13652 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
13655 while (TREE_CODE (t
) == COMPONENT_REF
)
13657 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0)))
13660 error_at (OMP_CLAUSE_LOCATION (c
),
13661 "%qE is a member of a union", t
);
13665 t
= TREE_OPERAND (t
, 0);
13669 if (VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
13671 if (bitmap_bit_p (&map_field_head
, DECL_UID (t
)))
13675 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
13677 error_at (OMP_CLAUSE_LOCATION (c
),
13678 "%qE is not a variable in %qs clause", t
,
13679 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
13682 else if (VAR_P (t
) && DECL_THREAD_LOCAL_P (t
))
13684 error_at (OMP_CLAUSE_LOCATION (c
),
13685 "%qD is threadprivate variable in %qs clause", t
,
13686 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
13689 else if ((OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
13690 || (OMP_CLAUSE_MAP_KIND (c
)
13691 != GOMP_MAP_FIRSTPRIVATE_POINTER
))
13692 && !c_mark_addressable (t
))
13694 else if (!(OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
13695 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_POINTER
13696 || (OMP_CLAUSE_MAP_KIND (c
)
13697 == GOMP_MAP_FIRSTPRIVATE_POINTER
)
13698 || (OMP_CLAUSE_MAP_KIND (c
)
13699 == GOMP_MAP_FORCE_DEVICEPTR
)))
13700 && t
== OMP_CLAUSE_DECL (c
)
13701 && !lang_hooks
.types
.omp_mappable_type (TREE_TYPE (t
)))
13703 error_at (OMP_CLAUSE_LOCATION (c
),
13704 "%qD does not have a mappable type in %qs clause", t
,
13705 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
13708 else if (TREE_TYPE (t
) == error_mark_node
)
13710 else if (TYPE_ATOMIC (strip_array_types (TREE_TYPE (t
))))
13712 error_at (OMP_CLAUSE_LOCATION (c
),
13713 "%<_Atomic%> %qE in %qs clause", t
,
13714 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
13717 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
13718 && OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FIRSTPRIVATE_POINTER
)
13720 if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
13721 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
13723 error ("%qD appears more than once in data clauses", t
);
13726 else if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
13728 if (ort
== C_ORT_ACC
)
13729 error ("%qD appears more than once in data clauses", t
);
13731 error ("%qD appears both in data and map clauses", t
);
13735 bitmap_set_bit (&generic_head
, DECL_UID (t
));
13737 else if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
13739 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
13740 error ("%qD appears more than once in motion clauses", t
);
13741 else if (ort
== C_ORT_ACC
)
13742 error ("%qD appears more than once in data clauses", t
);
13744 error ("%qD appears more than once in map clauses", t
);
13747 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
13748 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
13750 if (ort
== C_ORT_ACC
)
13751 error ("%qD appears more than once in data clauses", t
);
13753 error ("%qD appears both in data and map clauses", t
);
13758 bitmap_set_bit (&map_head
, DECL_UID (t
));
13759 if (t
!= OMP_CLAUSE_DECL (c
)
13760 && TREE_CODE (OMP_CLAUSE_DECL (c
)) == COMPONENT_REF
)
13761 bitmap_set_bit (&map_field_head
, DECL_UID (t
));
13765 case OMP_CLAUSE_TO_DECLARE
:
13766 case OMP_CLAUSE_LINK
:
13767 t
= OMP_CLAUSE_DECL (c
);
13768 if (TREE_CODE (t
) == FUNCTION_DECL
13769 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO_DECLARE
)
13771 else if (!VAR_P (t
))
13773 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO_DECLARE
)
13774 error_at (OMP_CLAUSE_LOCATION (c
),
13775 "%qE is neither a variable nor a function name in "
13777 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
13779 error_at (OMP_CLAUSE_LOCATION (c
),
13780 "%qE is not a variable in clause %qs", t
,
13781 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
13784 else if (DECL_THREAD_LOCAL_P (t
))
13786 error_at (OMP_CLAUSE_LOCATION (c
),
13787 "%qD is threadprivate variable in %qs clause", t
,
13788 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
13791 else if (!lang_hooks
.types
.omp_mappable_type (TREE_TYPE (t
)))
13793 error_at (OMP_CLAUSE_LOCATION (c
),
13794 "%qD does not have a mappable type in %qs clause", t
,
13795 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
13800 if (bitmap_bit_p (&generic_head
, DECL_UID (t
)))
13802 error_at (OMP_CLAUSE_LOCATION (c
),
13803 "%qE appears more than once on the same "
13804 "%<declare target%> directive", t
);
13808 bitmap_set_bit (&generic_head
, DECL_UID (t
));
13811 case OMP_CLAUSE_UNIFORM
:
13812 t
= OMP_CLAUSE_DECL (c
);
13813 if (TREE_CODE (t
) != PARM_DECL
)
13816 error_at (OMP_CLAUSE_LOCATION (c
),
13817 "%qD is not an argument in %<uniform%> clause", t
);
13819 error_at (OMP_CLAUSE_LOCATION (c
),
13820 "%qE is not an argument in %<uniform%> clause", t
);
13824 /* map_head bitmap is used as uniform_head if declare_simd. */
13825 bitmap_set_bit (&map_head
, DECL_UID (t
));
13826 goto check_dup_generic
;
13828 case OMP_CLAUSE_IS_DEVICE_PTR
:
13829 case OMP_CLAUSE_USE_DEVICE_PTR
:
13830 t
= OMP_CLAUSE_DECL (c
);
13831 if (TREE_CODE (TREE_TYPE (t
)) != POINTER_TYPE
13832 && TREE_CODE (TREE_TYPE (t
)) != ARRAY_TYPE
)
13834 error_at (OMP_CLAUSE_LOCATION (c
),
13835 "%qs variable is neither a pointer nor an array",
13836 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
13839 goto check_dup_generic
;
13841 case OMP_CLAUSE_NOWAIT
:
13842 if (copyprivate_seen
)
13844 error_at (OMP_CLAUSE_LOCATION (c
),
13845 "%<nowait%> clause must not be used together "
13846 "with %<copyprivate%>");
13850 nowait_clause
= pc
;
13851 pc
= &OMP_CLAUSE_CHAIN (c
);
13854 case OMP_CLAUSE_IF
:
13855 case OMP_CLAUSE_NUM_THREADS
:
13856 case OMP_CLAUSE_NUM_TEAMS
:
13857 case OMP_CLAUSE_THREAD_LIMIT
:
13858 case OMP_CLAUSE_DEFAULT
:
13859 case OMP_CLAUSE_UNTIED
:
13860 case OMP_CLAUSE_COLLAPSE
:
13861 case OMP_CLAUSE_FINAL
:
13862 case OMP_CLAUSE_MERGEABLE
:
13863 case OMP_CLAUSE_DEVICE
:
13864 case OMP_CLAUSE_DIST_SCHEDULE
:
13865 case OMP_CLAUSE_PARALLEL
:
13866 case OMP_CLAUSE_FOR
:
13867 case OMP_CLAUSE_SECTIONS
:
13868 case OMP_CLAUSE_TASKGROUP
:
13869 case OMP_CLAUSE_PROC_BIND
:
13870 case OMP_CLAUSE_PRIORITY
:
13871 case OMP_CLAUSE_GRAINSIZE
:
13872 case OMP_CLAUSE_NUM_TASKS
:
13873 case OMP_CLAUSE_NOGROUP
:
13874 case OMP_CLAUSE_THREADS
:
13875 case OMP_CLAUSE_SIMD
:
13876 case OMP_CLAUSE_HINT
:
13877 case OMP_CLAUSE_DEFAULTMAP
:
13878 case OMP_CLAUSE_NUM_GANGS
:
13879 case OMP_CLAUSE_NUM_WORKERS
:
13880 case OMP_CLAUSE_VECTOR_LENGTH
:
13881 case OMP_CLAUSE_ASYNC
:
13882 case OMP_CLAUSE_WAIT
:
13883 case OMP_CLAUSE_AUTO
:
13884 case OMP_CLAUSE_INDEPENDENT
:
13885 case OMP_CLAUSE_SEQ
:
13886 case OMP_CLAUSE_GANG
:
13887 case OMP_CLAUSE_WORKER
:
13888 case OMP_CLAUSE_VECTOR
:
13889 case OMP_CLAUSE_TILE
:
13890 pc
= &OMP_CLAUSE_CHAIN (c
);
13893 case OMP_CLAUSE_SCHEDULE
:
13894 if (OMP_CLAUSE_SCHEDULE_KIND (c
) & OMP_CLAUSE_SCHEDULE_NONMONOTONIC
)
13896 const char *p
= NULL
;
13897 switch (OMP_CLAUSE_SCHEDULE_KIND (c
) & OMP_CLAUSE_SCHEDULE_MASK
)
13899 case OMP_CLAUSE_SCHEDULE_STATIC
: p
= "static"; break;
13900 case OMP_CLAUSE_SCHEDULE_DYNAMIC
: break;
13901 case OMP_CLAUSE_SCHEDULE_GUIDED
: break;
13902 case OMP_CLAUSE_SCHEDULE_AUTO
: p
= "auto"; break;
13903 case OMP_CLAUSE_SCHEDULE_RUNTIME
: p
= "runtime"; break;
13904 default: gcc_unreachable ();
13908 error_at (OMP_CLAUSE_LOCATION (c
),
13909 "%<nonmonotonic%> modifier specified for %qs "
13910 "schedule kind", p
);
13911 OMP_CLAUSE_SCHEDULE_KIND (c
)
13912 = (enum omp_clause_schedule_kind
)
13913 (OMP_CLAUSE_SCHEDULE_KIND (c
)
13914 & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC
);
13917 schedule_clause
= c
;
13918 pc
= &OMP_CLAUSE_CHAIN (c
);
13921 case OMP_CLAUSE_ORDERED
:
13922 ordered_seen
= true;
13923 pc
= &OMP_CLAUSE_CHAIN (c
);
13926 case OMP_CLAUSE_SAFELEN
:
13928 pc
= &OMP_CLAUSE_CHAIN (c
);
13930 case OMP_CLAUSE_SIMDLEN
:
13932 pc
= &OMP_CLAUSE_CHAIN (c
);
13935 case OMP_CLAUSE_INBRANCH
:
13936 case OMP_CLAUSE_NOTINBRANCH
:
13939 error_at (OMP_CLAUSE_LOCATION (c
),
13940 "%<inbranch%> clause is incompatible with "
13941 "%<notinbranch%>");
13945 branch_seen
= true;
13946 pc
= &OMP_CLAUSE_CHAIN (c
);
13950 gcc_unreachable ();
13955 t
= OMP_CLAUSE_DECL (c
);
13959 t
= require_complete_type (OMP_CLAUSE_LOCATION (c
), t
);
13960 if (t
== error_mark_node
)
13964 if (need_implicitly_determined
)
13966 const char *share_name
= NULL
;
13968 if (VAR_P (t
) && DECL_THREAD_LOCAL_P (t
))
13969 share_name
= "threadprivate";
13970 else switch (c_omp_predetermined_sharing (t
))
13972 case OMP_CLAUSE_DEFAULT_UNSPECIFIED
:
13974 case OMP_CLAUSE_DEFAULT_SHARED
:
13975 /* const vars may be specified in firstprivate clause. */
13976 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
13977 && TREE_READONLY (t
))
13979 share_name
= "shared";
13981 case OMP_CLAUSE_DEFAULT_PRIVATE
:
13982 share_name
= "private";
13985 gcc_unreachable ();
13989 error_at (OMP_CLAUSE_LOCATION (c
),
13990 "%qE is predetermined %qs for %qs",
13992 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
13999 *pc
= OMP_CLAUSE_CHAIN (c
);
14001 pc
= &OMP_CLAUSE_CHAIN (c
);
14006 && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen
),
14007 OMP_CLAUSE_SIMDLEN_EXPR (simdlen
)))
14009 error_at (OMP_CLAUSE_LOCATION (simdlen
),
14010 "%<simdlen%> clause value is bigger than "
14011 "%<safelen%> clause value");
14012 OMP_CLAUSE_SIMDLEN_EXPR (simdlen
)
14013 = OMP_CLAUSE_SAFELEN_EXPR (safelen
);
14018 && (OMP_CLAUSE_SCHEDULE_KIND (schedule_clause
)
14019 & OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
14021 error_at (OMP_CLAUSE_LOCATION (schedule_clause
),
14022 "%<nonmonotonic%> schedule modifier specified together "
14023 "with %<ordered%> clause");
14024 OMP_CLAUSE_SCHEDULE_KIND (schedule_clause
)
14025 = (enum omp_clause_schedule_kind
)
14026 (OMP_CLAUSE_SCHEDULE_KIND (schedule_clause
)
14027 & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC
);
14030 if (linear_variable_step_check
)
14031 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
14033 bool remove
= false;
14034 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINEAR
14035 && OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c
)
14036 && !bitmap_bit_p (&map_head
,
14037 DECL_UID (OMP_CLAUSE_LINEAR_STEP (c
))))
14039 error_at (OMP_CLAUSE_LOCATION (c
),
14040 "%<linear%> clause step is a parameter %qD not "
14041 "specified in %<uniform%> clause",
14042 OMP_CLAUSE_LINEAR_STEP (c
));
14047 *pc
= OMP_CLAUSE_CHAIN (c
);
14049 pc
= &OMP_CLAUSE_CHAIN (c
);
14052 bitmap_obstack_release (NULL
);
14056 /* Return code to initialize DST with a copy constructor from SRC.
14057 C doesn't have copy constructors nor assignment operators, only for
14058 _Atomic vars we need to perform __atomic_load from src into a temporary
14059 followed by __atomic_store of the temporary to dst. */
14062 c_omp_clause_copy_ctor (tree clause
, tree dst
, tree src
)
14064 if (!really_atomic_lvalue (dst
) && !really_atomic_lvalue (src
))
14065 return build2 (MODIFY_EXPR
, TREE_TYPE (dst
), dst
, src
);
14067 location_t loc
= OMP_CLAUSE_LOCATION (clause
);
14068 tree type
= TREE_TYPE (dst
);
14069 tree nonatomic_type
= build_qualified_type (type
, TYPE_UNQUALIFIED
);
14070 tree tmp
= create_tmp_var (nonatomic_type
);
14071 tree tmp_addr
= build_fold_addr_expr (tmp
);
14072 TREE_ADDRESSABLE (tmp
) = 1;
14073 TREE_NO_WARNING (tmp
) = 1;
14074 tree src_addr
= build_fold_addr_expr (src
);
14075 tree dst_addr
= build_fold_addr_expr (dst
);
14076 tree seq_cst
= build_int_cst (integer_type_node
, MEMMODEL_SEQ_CST
);
14077 vec
<tree
, va_gc
> *params
;
14078 /* Expansion of a generic atomic load may require an addition
14079 element, so allocate enough to prevent a resize. */
14080 vec_alloc (params
, 4);
14082 /* Build __atomic_load (&src, &tmp, SEQ_CST); */
14083 tree fndecl
= builtin_decl_explicit (BUILT_IN_ATOMIC_LOAD
);
14084 params
->quick_push (src_addr
);
14085 params
->quick_push (tmp_addr
);
14086 params
->quick_push (seq_cst
);
14087 tree load
= c_build_function_call_vec (loc
, vNULL
, fndecl
, params
, NULL
);
14089 vec_alloc (params
, 4);
14091 /* Build __atomic_store (&dst, &tmp, SEQ_CST); */
14092 fndecl
= builtin_decl_explicit (BUILT_IN_ATOMIC_STORE
);
14093 params
->quick_push (dst_addr
);
14094 params
->quick_push (tmp_addr
);
14095 params
->quick_push (seq_cst
);
14096 tree store
= c_build_function_call_vec (loc
, vNULL
, fndecl
, params
, NULL
);
14097 return build2 (COMPOUND_EXPR
, void_type_node
, load
, store
);
14100 /* Create a transaction node. */
14103 c_finish_transaction (location_t loc
, tree block
, int flags
)
14105 tree stmt
= build_stmt (loc
, TRANSACTION_EXPR
, block
);
14106 if (flags
& TM_STMT_ATTR_OUTER
)
14107 TRANSACTION_EXPR_OUTER (stmt
) = 1;
14108 if (flags
& TM_STMT_ATTR_RELAXED
)
14109 TRANSACTION_EXPR_RELAXED (stmt
) = 1;
14110 return add_stmt (stmt
);
14113 /* Make a variant type in the proper way for C/C++, propagating qualifiers
14114 down to the element type of an array. If ORIG_QUAL_TYPE is not
14115 NULL, then it should be used as the qualified type
14116 ORIG_QUAL_INDIRECT levels down in array type derivation (to
14117 preserve information about the typedef name from which an array
14118 type was derived). */
14121 c_build_qualified_type (tree type
, int type_quals
, tree orig_qual_type
,
14122 size_t orig_qual_indirect
)
14124 if (type
== error_mark_node
)
14127 if (TREE_CODE (type
) == ARRAY_TYPE
)
14130 tree element_type
= c_build_qualified_type (TREE_TYPE (type
),
14131 type_quals
, orig_qual_type
,
14132 orig_qual_indirect
- 1);
14134 /* See if we already have an identically qualified type. */
14135 if (orig_qual_type
&& orig_qual_indirect
== 0)
14136 t
= orig_qual_type
;
14138 for (t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
14140 if (TYPE_QUALS (strip_array_types (t
)) == type_quals
14141 && TYPE_NAME (t
) == TYPE_NAME (type
)
14142 && TYPE_CONTEXT (t
) == TYPE_CONTEXT (type
)
14143 && attribute_list_equal (TYPE_ATTRIBUTES (t
),
14144 TYPE_ATTRIBUTES (type
)))
14149 tree domain
= TYPE_DOMAIN (type
);
14151 t
= build_variant_type_copy (type
);
14152 TREE_TYPE (t
) = element_type
;
14154 if (TYPE_STRUCTURAL_EQUALITY_P (element_type
)
14155 || (domain
&& TYPE_STRUCTURAL_EQUALITY_P (domain
)))
14156 SET_TYPE_STRUCTURAL_EQUALITY (t
);
14157 else if (TYPE_CANONICAL (element_type
) != element_type
14158 || (domain
&& TYPE_CANONICAL (domain
) != domain
))
14160 tree unqualified_canon
14161 = build_array_type (TYPE_CANONICAL (element_type
),
14162 domain
? TYPE_CANONICAL (domain
)
14164 if (TYPE_REVERSE_STORAGE_ORDER (type
))
14167 = build_distinct_type_copy (unqualified_canon
);
14168 TYPE_REVERSE_STORAGE_ORDER (unqualified_canon
) = 1;
14171 = c_build_qualified_type (unqualified_canon
, type_quals
);
14174 TYPE_CANONICAL (t
) = t
;
14179 /* A restrict-qualified pointer type must be a pointer to object or
14180 incomplete type. Note that the use of POINTER_TYPE_P also allows
14181 REFERENCE_TYPEs, which is appropriate for C++. */
14182 if ((type_quals
& TYPE_QUAL_RESTRICT
)
14183 && (!POINTER_TYPE_P (type
)
14184 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type
))))
14186 error ("invalid use of %<restrict%>");
14187 type_quals
&= ~TYPE_QUAL_RESTRICT
;
14190 tree var_type
= (orig_qual_type
&& orig_qual_indirect
== 0
14192 : build_qualified_type (type
, type_quals
));
14193 /* A variant type does not inherit the list of incomplete vars from the
14194 type main variant. */
14195 if (RECORD_OR_UNION_TYPE_P (var_type
)
14196 && TYPE_MAIN_VARIANT (var_type
) != var_type
)
14197 C_TYPE_INCOMPLETE_VARS (var_type
) = 0;
14201 /* Build a VA_ARG_EXPR for the C parser. */
14204 c_build_va_arg (location_t loc1
, tree expr
, location_t loc2
, tree type
)
14206 if (error_operand_p (type
))
14207 return error_mark_node
;
14208 /* VA_ARG_EXPR cannot be used for a scalar va_list with reverse storage
14209 order because it takes the address of the expression. */
14210 else if (handled_component_p (expr
)
14211 && reverse_storage_order_for_component_p (expr
))
14213 error_at (loc1
, "cannot use %<va_arg%> with reverse storage order");
14214 return error_mark_node
;
14216 else if (!COMPLETE_TYPE_P (type
))
14218 error_at (loc2
, "second argument to %<va_arg%> is of incomplete "
14220 return error_mark_node
;
14222 else if (warn_cxx_compat
&& TREE_CODE (type
) == ENUMERAL_TYPE
)
14223 warning_at (loc2
, OPT_Wc___compat
,
14224 "C++ requires promoted type, not enum type, in %<va_arg%>");
14225 return build_va_arg (loc2
, expr
, type
);
14228 /* Return truthvalue of whether T1 is the same tree structure as T2.
14229 Return 1 if they are the same. Return false if they are different. */
14232 c_tree_equal (tree t1
, tree t2
)
14234 enum tree_code code1
, code2
;
14241 for (code1
= TREE_CODE (t1
);
14242 CONVERT_EXPR_CODE_P (code1
)
14243 || code1
== NON_LVALUE_EXPR
;
14244 code1
= TREE_CODE (t1
))
14245 t1
= TREE_OPERAND (t1
, 0);
14246 for (code2
= TREE_CODE (t2
);
14247 CONVERT_EXPR_CODE_P (code2
)
14248 || code2
== NON_LVALUE_EXPR
;
14249 code2
= TREE_CODE (t2
))
14250 t2
= TREE_OPERAND (t2
, 0);
14252 /* They might have become equal now. */
14256 if (code1
!= code2
)
14262 return wi::to_wide (t1
) == wi::to_wide (t2
);
14265 return real_equal (&TREE_REAL_CST (t1
), &TREE_REAL_CST (t2
));
14268 return TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
14269 && !memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
14270 TREE_STRING_LENGTH (t1
));
14273 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1
),
14274 TREE_FIXED_CST (t2
));
14277 return c_tree_equal (TREE_REALPART (t1
), TREE_REALPART (t2
))
14278 && c_tree_equal (TREE_IMAGPART (t1
), TREE_IMAGPART (t2
));
14281 return operand_equal_p (t1
, t2
, OEP_ONLY_CONST
);
14284 /* We need to do this when determining whether or not two
14285 non-type pointer to member function template arguments
14287 if (!comptypes (TREE_TYPE (t1
), TREE_TYPE (t2
))
14288 || CONSTRUCTOR_NELTS (t1
) != CONSTRUCTOR_NELTS (t2
))
14293 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t1
), i
, field
, value
)
14295 constructor_elt
*elt2
= CONSTRUCTOR_ELT (t2
, i
);
14296 if (!c_tree_equal (field
, elt2
->index
)
14297 || !c_tree_equal (value
, elt2
->value
))
14304 if (!c_tree_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
)))
14306 if (!c_tree_equal (TREE_VALUE (t1
), TREE_VALUE (t2
)))
14308 return c_tree_equal (TREE_CHAIN (t1
), TREE_CHAIN (t2
));
14311 return c_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
14316 call_expr_arg_iterator iter1
, iter2
;
14317 if (!c_tree_equal (CALL_EXPR_FN (t1
), CALL_EXPR_FN (t2
)))
14319 for (arg1
= first_call_expr_arg (t1
, &iter1
),
14320 arg2
= first_call_expr_arg (t2
, &iter2
);
14322 arg1
= next_call_expr_arg (&iter1
),
14323 arg2
= next_call_expr_arg (&iter2
))
14324 if (!c_tree_equal (arg1
, arg2
))
14333 tree o1
= TREE_OPERAND (t1
, 0);
14334 tree o2
= TREE_OPERAND (t2
, 0);
14336 /* Special case: if either target is an unallocated VAR_DECL,
14337 it means that it's going to be unified with whatever the
14338 TARGET_EXPR is really supposed to initialize, so treat it
14339 as being equivalent to anything. */
14340 if (VAR_P (o1
) && DECL_NAME (o1
) == NULL_TREE
14341 && !DECL_RTL_SET_P (o1
))
14343 else if (VAR_P (o2
) && DECL_NAME (o2
) == NULL_TREE
14344 && !DECL_RTL_SET_P (o2
))
14346 else if (!c_tree_equal (o1
, o2
))
14349 return c_tree_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
14352 case COMPONENT_REF
:
14353 if (TREE_OPERAND (t1
, 1) != TREE_OPERAND (t2
, 1))
14355 return c_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
14361 case FUNCTION_DECL
:
14362 case IDENTIFIER_NODE
:
14369 if (TREE_VEC_LENGTH (t1
) != TREE_VEC_LENGTH (t2
))
14371 for (ix
= TREE_VEC_LENGTH (t1
); ix
--;)
14372 if (!c_tree_equal (TREE_VEC_ELT (t1
, ix
),
14373 TREE_VEC_ELT (t2
, ix
)))
14382 switch (TREE_CODE_CLASS (code1
))
14386 case tcc_comparison
:
14387 case tcc_expression
:
14389 case tcc_reference
:
14390 case tcc_statement
:
14392 int i
, n
= TREE_OPERAND_LENGTH (t1
);
14396 case PREINCREMENT_EXPR
:
14397 case PREDECREMENT_EXPR
:
14398 case POSTINCREMENT_EXPR
:
14399 case POSTDECREMENT_EXPR
:
14409 if (TREE_CODE_CLASS (code1
) == tcc_vl_exp
14410 && n
!= TREE_OPERAND_LENGTH (t2
))
14413 for (i
= 0; i
< n
; ++i
)
14414 if (!c_tree_equal (TREE_OPERAND (t1
, i
), TREE_OPERAND (t2
, i
)))
14421 return comptypes (t1
, t2
);
14423 gcc_unreachable ();
14425 /* We can get here with --disable-checking. */
14429 /* Returns true when the function declaration FNDECL is implicit,
14430 introduced as a result of a call to an otherwise undeclared
14431 function, and false otherwise. */
14434 c_decl_implicit (const_tree fndecl
)
14436 return C_DECL_IMPLICIT (fndecl
);