Line data Source code
1 : /* Build expressions with type checking for C compiler.
2 : Copyright (C) 1987-2026 Free Software Foundation, Inc.
3 :
4 : This file is part of GCC.
5 :
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
9 : version.
10 :
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
14 : for more details.
15 :
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/>. */
19 :
20 :
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. */
25 :
26 : #include "config.h"
27 : #include "system.h"
28 : #include "coretypes.h"
29 : #include "memmodel.h"
30 : #include "target.h"
31 : #include "function.h"
32 : #include "bitmap.h"
33 : #include "c-tree.h"
34 : #include "gimple-expr.h"
35 : #include "predict.h"
36 : #include "stor-layout.h"
37 : #include "trans-mem.h"
38 : #include "varasm.h"
39 : #include "stmt.h"
40 : #include "langhooks.h"
41 : #include "c-lang.h"
42 : #include "intl.h"
43 : #include "tree-iterator.h"
44 : #include "gimplify.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 "c-family/c-type-mismatch.h"
52 : #include "stringpool.h"
53 : #include "attribs.h"
54 : #include "asan.h"
55 : #include "realmpfr.h"
56 : #include "tree-pretty-print-markup.h"
57 : #include "gcc-urlifier.h"
58 :
59 : /* Possible cases of implicit conversions. Used to select diagnostic messages
60 : and control folding initializers in convert_for_assignment. */
61 : enum impl_conv {
62 : ic_argpass,
63 : ic_assign,
64 : ic_init,
65 : ic_init_const,
66 : ic_return
67 : };
68 :
69 : /* The level of nesting inside "__alignof__". */
70 : int in_alignof;
71 :
72 : /* The level of nesting inside "sizeof". */
73 : int in_sizeof;
74 :
75 : /* The level of nesting inside "countof". */
76 : int in_countof;
77 :
78 : /* The level of nesting inside "typeof". */
79 : int in_typeof;
80 :
81 : /* The level of nesting inside "_Generic". */
82 : int in_generic;
83 :
84 : /* True when parsing OpenMP loop expressions. */
85 : bool c_in_omp_for;
86 :
87 : /* True when parsing OpenMP map clause. */
88 : bool c_omp_array_section_p;
89 :
90 : /* The argument of last parsed sizeof expression, only to be tested
91 : if expr.original_code == SIZEOF_EXPR. */
92 : tree c_last_sizeof_arg;
93 : location_t c_last_sizeof_loc;
94 :
95 : /* Nonzero if we might need to print a "missing braces around
96 : initializer" message within this initializer. */
97 : static int found_missing_braces;
98 :
99 : static bool require_constant_value;
100 : static bool require_constant_elements;
101 : static bool require_constexpr_value;
102 :
103 : static tree qualify_type (tree, tree);
104 : struct comptypes_data;
105 : static bool tagged_types_tu_compatible_p (const_tree, const_tree,
106 : struct comptypes_data *);
107 : static bool comp_target_types (location_t, tree, tree);
108 : static bool function_types_compatible_p (const_tree, const_tree,
109 : struct comptypes_data *);
110 : static bool type_lists_compatible_p (const_tree, const_tree,
111 : struct comptypes_data *);
112 : static int convert_arguments (location_t, vec<location_t>, tree,
113 : vec<tree, va_gc> *, vec<tree, va_gc> *, tree,
114 : tree);
115 : static tree pointer_diff (location_t, tree, tree, tree *);
116 : static tree convert_for_assignment (location_t, location_t, tree, tree, tree,
117 : enum impl_conv, bool, tree, tree, int,
118 : int = 0);
119 : static tree valid_compound_expr_initializer (tree, tree);
120 : static void push_string (const char *);
121 : static void push_member_name (tree);
122 : static int spelling_length (void);
123 : static char *print_spelling (char *);
124 : static void warning_init (location_t, int, const char *);
125 : static tree digest_init (location_t, tree, tree, tree, tree, bool, bool, bool,
126 : bool, bool, bool);
127 : static void output_init_element (location_t, tree, tree, bool, tree, tree, bool,
128 : bool, struct obstack *);
129 : static void output_pending_init_elements (int, struct obstack *);
130 : static bool set_designator (location_t, bool, struct obstack *);
131 : static void push_range_stack (tree, struct obstack *);
132 : static void add_pending_init (location_t, tree, tree, tree, bool,
133 : struct obstack *);
134 : static void set_nonincremental_init (struct obstack *);
135 : static void set_nonincremental_init_from_string (tree, struct obstack *);
136 : static tree find_init_member (tree, struct obstack *);
137 : static void readonly_warning (tree, enum lvalue_use);
138 : static int lvalue_or_else (location_t, const_tree, enum lvalue_use);
139 : static void record_maybe_used_decl (tree, bool address);
140 : static bool comptypes_internal (const_tree, const_tree,
141 : struct comptypes_data *data);
142 : static bool comptypes_check_for_composite (tree t1, tree t2);
143 : static bool handle_counted_by_p (tree);
144 : static bool top_array_vla_p (const_tree type);
145 :
146 :
147 : /* Return true if EXP is a null pointer constant, false otherwise. */
148 :
149 : bool
150 193362487 : null_pointer_constant_p (const_tree expr)
151 : {
152 : /* This should really operate on c_expr structures, but they aren't
153 : yet available everywhere required. */
154 193362487 : tree type = TREE_TYPE (expr);
155 :
156 : /* An integer constant expression with the value 0, such an expression
157 : cast to type void*, or the predefined constant nullptr, are a null
158 : pointer constant. */
159 193362487 : if (expr == nullptr_node)
160 : return true;
161 :
162 193361793 : return (TREE_CODE (expr) == INTEGER_CST
163 19476417 : && !TREE_OVERFLOW (expr)
164 19476320 : && integer_zerop (expr)
165 197321709 : && (INTEGRAL_TYPE_P (type)
166 338756 : || (TREE_CODE (type) == POINTER_TYPE
167 338754 : && VOID_TYPE_P (TREE_TYPE (type))
168 263393 : && TYPE_QUALS (TREE_TYPE (type)) == TYPE_UNQUALIFIED)));
169 : }
170 :
171 : /* EXPR may appear in an unevaluated part of an integer constant
172 : expression, but not in an evaluated part. Wrap it in a
173 : C_MAYBE_CONST_EXPR, or mark it with TREE_OVERFLOW if it is just an
174 : INTEGER_CST and we cannot create a C_MAYBE_CONST_EXPR. */
175 :
176 : static tree
177 62369 : note_integer_operands (tree expr)
178 : {
179 62369 : tree ret;
180 62369 : if (TREE_CODE (expr) == INTEGER_CST && in_late_binary_op)
181 : {
182 22 : ret = copy_node (expr);
183 22 : TREE_OVERFLOW (ret) = 1;
184 : }
185 : else
186 : {
187 62347 : ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (expr), NULL_TREE, expr);
188 62347 : C_MAYBE_CONST_EXPR_INT_OPERANDS (ret) = 1;
189 : }
190 62369 : return ret;
191 : }
192 :
193 : /* Having checked whether EXPR may appear in an unevaluated part of an
194 : integer constant expression and found that it may, remove any
195 : C_MAYBE_CONST_EXPR noting this fact and return the resulting
196 : expression. */
197 :
198 : static inline tree
199 34547619 : remove_c_maybe_const_expr (tree expr)
200 : {
201 34547619 : if (TREE_CODE (expr) == C_MAYBE_CONST_EXPR)
202 61517 : return C_MAYBE_CONST_EXPR_EXPR (expr);
203 : else
204 : return expr;
205 : }
206 :
207 : /* This is a cache to hold if two types are seen. */
208 :
209 : struct tagged_tu_seen_cache {
210 : const struct tagged_tu_seen_cache * next;
211 : const_tree t1;
212 : const_tree t2;
213 : };
214 :
215 : /* Do `exp = require_complete_type (loc, exp);' to make sure exp
216 : does not have an incomplete type. (That includes void types.)
217 : LOC is the location of the use. */
218 :
219 : tree
220 794328869 : require_complete_type (location_t loc, tree value)
221 : {
222 794328869 : tree type = TREE_TYPE (value);
223 :
224 794328869 : if (error_operand_p (value))
225 8960 : return error_mark_node;
226 :
227 : /* First, detect a valid value with a complete type. */
228 794319909 : if (COMPLETE_TYPE_P (type))
229 : return value;
230 :
231 164 : c_incomplete_type_error (loc, value, type);
232 164 : return error_mark_node;
233 : }
234 :
235 : /* Print an error message for invalid use of an incomplete type.
236 : VALUE is the expression that was used (or 0 if that isn't known)
237 : and TYPE is the type that was invalid. LOC is the location for
238 : the error. */
239 :
240 : void
241 232 : c_incomplete_type_error (location_t loc, const_tree value, const_tree type)
242 : {
243 : /* Avoid duplicate error message. */
244 232 : if (TREE_CODE (type) == ERROR_MARK)
245 : return;
246 :
247 232 : if (value != NULL_TREE && (VAR_P (value) || TREE_CODE (value) == PARM_DECL))
248 98 : error_at (loc, "%qD has an incomplete type %qT", value, type);
249 : else
250 : {
251 134 : retry:
252 : /* We must print an error message. Be clever about what it says. */
253 :
254 134 : switch (TREE_CODE (type))
255 : {
256 90 : case RECORD_TYPE:
257 90 : case UNION_TYPE:
258 90 : case ENUMERAL_TYPE:
259 90 : break;
260 :
261 38 : case VOID_TYPE:
262 38 : error_at (loc, "invalid use of void expression");
263 38 : return;
264 :
265 6 : case ARRAY_TYPE:
266 6 : if (TYPE_DOMAIN (type))
267 : {
268 3 : if (flexible_array_member_type_p (type))
269 : {
270 3 : error_at (loc, "invalid use of flexible array member");
271 3 : return;
272 : }
273 0 : type = TREE_TYPE (type);
274 0 : goto retry;
275 : }
276 3 : error_at (loc, "invalid use of array with unspecified bounds");
277 3 : return;
278 :
279 0 : default:
280 0 : gcc_unreachable ();
281 : }
282 :
283 90 : if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
284 88 : error_at (loc, "invalid use of undefined type %qT", type);
285 : else
286 : /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL. */
287 2 : error_at (loc, "invalid use of incomplete typedef %qT", type);
288 : }
289 : }
290 :
291 : /* Given a type, apply default promotions wrt unnamed function
292 : arguments and return the new type. */
293 :
294 : tree
295 128262097 : c_type_promotes_to (tree type)
296 : {
297 128262097 : tree ret = NULL_TREE;
298 :
299 128262097 : if (TYPE_MAIN_VARIANT (type) == float_type_node)
300 1639856 : ret = double_type_node;
301 126622241 : else if (c_promoting_integer_type_p (type))
302 : {
303 : /* Preserve unsignedness if not really getting any wider. */
304 19183347 : if (TYPE_UNSIGNED (type)
305 19183347 : && (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)))
306 0 : ret = unsigned_type_node;
307 : else
308 19183347 : ret = integer_type_node;
309 : }
310 :
311 20823203 : if (ret != NULL_TREE)
312 20823203 : return (TYPE_ATOMIC (type)
313 20823203 : ? c_build_qualified_type (ret, TYPE_QUAL_ATOMIC)
314 : : ret);
315 :
316 : return type;
317 : }
318 :
319 : /* Return true if between two named address spaces, whether there is a superset
320 : named address space that encompasses both address spaces. If there is a
321 : superset, return which address space is the superset. */
322 :
323 : static bool
324 7716200 : addr_space_superset (addr_space_t as1, addr_space_t as2, addr_space_t *common)
325 : {
326 7716200 : if (as1 == as2)
327 : {
328 7716200 : *common = as1;
329 7716200 : return true;
330 : }
331 0 : else if (targetm.addr_space.subset_p (as1, as2))
332 : {
333 0 : *common = as2;
334 0 : return true;
335 : }
336 0 : else if (targetm.addr_space.subset_p (as2, as1))
337 : {
338 0 : *common = as1;
339 0 : return true;
340 : }
341 : else
342 : return false;
343 : }
344 :
345 : /* Return a variant of TYPE which has all the type qualifiers of LIKE
346 : as well as those of TYPE. */
347 :
348 : static tree
349 2910369 : qualify_type (tree type, tree like)
350 : {
351 2910369 : addr_space_t as_type = TYPE_ADDR_SPACE (type);
352 2910369 : addr_space_t as_like = TYPE_ADDR_SPACE (like);
353 2910369 : addr_space_t as_common;
354 :
355 : /* If the two named address spaces are different, determine the common
356 : superset address space. If there isn't one, raise an error. */
357 2910369 : if (!addr_space_superset (as_type, as_like, &as_common))
358 : {
359 0 : as_common = as_type;
360 0 : error ("%qT and %qT are in disjoint named address spaces",
361 : type, like);
362 : }
363 :
364 5820738 : return c_build_qualified_type (type,
365 2910369 : TYPE_QUALS_NO_ADDR_SPACE (type)
366 2910369 : | TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (like)
367 2910369 : | ENCODE_QUAL_ADDR_SPACE (as_common));
368 : }
369 :
370 :
371 : /* Check consistency of type TYPE. For derived types, we test that
372 : C_TYPE_VARIABLE_SIZE and C_TYPE_VARIABLY_MODIFIED are consistent with
373 : the requirements of the base type. We also check that arrays with a
374 : non-constant length are marked with C_TYPE_VARIABLE_SIZE. If any
375 : inconsistency is detected false is returned and true otherwise. */
376 :
377 : static bool
378 145257251 : c_verify_type (tree type)
379 : {
380 145257251 : switch (TREE_CODE (type))
381 : {
382 69526582 : case POINTER_TYPE:
383 69526582 : case FUNCTION_TYPE:
384 69526582 : case ARRAY_TYPE:
385 : /* Pointer, array, functions are variably modified if and only if the
386 : target, element, return type is variably modified. */
387 69526582 : if (!TYPE_STRUCTURAL_EQUALITY_P (type)
388 69526582 : && (C_TYPE_VARIABLY_MODIFIED (type)
389 69139819 : != C_TYPE_VARIABLY_MODIFIED (TREE_TYPE (type))))
390 : return false;
391 : /* If the target type is structural equality, the type should also. */
392 69526582 : if (!TYPE_STRUCTURAL_EQUALITY_P (type)
393 69526582 : && TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (type)))
394 : return false;
395 145257251 : default:
396 145257251 : break;
397 : }
398 :
399 145257251 : switch (TREE_CODE (type))
400 : {
401 68606175 : case POINTER_TYPE:
402 68606175 : case FUNCTION_TYPE:
403 : /* Pointer and functions can not have variable size. */
404 68606175 : if (C_TYPE_VARIABLE_SIZE (type))
405 0 : return false;
406 : break;
407 920407 : case ARRAY_TYPE:
408 : /* An array has variable size if and only if it has a non-constant
409 : dimensions or its element type has variable size. */
410 920407 : if ((C_TYPE_VARIABLE_SIZE (TREE_TYPE (type))
411 920407 : || top_array_vla_p (type))
412 920407 : != C_TYPE_VARIABLE_SIZE (type))
413 : return false;
414 : /* If the element type or the array has variable size, then the
415 : array has variable size and is variably modified. */
416 920407 : if (C_TYPE_VARIABLE_SIZE (TREE_TYPE (type))
417 920407 : || C_TYPE_VARIABLE_SIZE (type))
418 : {
419 27704 : if (!C_TYPE_VARIABLE_SIZE (type))
420 : return false;
421 27704 : if (!C_TYPE_VARIABLY_MODIFIED (type))
422 : return false;
423 : }
424 :
425 : /* va_list violates this, accept such types here. */
426 920407 : if (!COMPLETE_TYPE_P (TREE_TYPE (type)))
427 : return true;
428 :
429 920401 : if (COMPLETE_TYPE_P (type))
430 : {
431 : /* If the size is unknown, it can not be complete. */
432 912130 : if (NULL_TREE == TYPE_DOMAIN (type))
433 : return false;
434 :
435 : /* Zero-length arrays must have size zero. */
436 912130 : if (zero_length_array_type_p (type)
437 912130 : && !integer_zerop (TYPE_SIZE (type)))
438 : return false;
439 : }
440 : else
441 : {
442 : /* If not complete but has a domain, it must be a FAM. */
443 8271 : if (NULL_TREE != TYPE_DOMAIN (type)
444 8271 : && !flexible_array_member_type_p (type))
445 : return false;
446 : }
447 : default:
448 : break;
449 : }
450 : return true;
451 : }
452 :
453 : /* Propagate C_TYPE_VARIABLY_MODIFIED and C_TYPE_VARIABLE_SIZE
454 : from a base type to a newly built derived or qualified type. */
455 :
456 : static tree
457 137983625 : c_set_type_bits (tree new_type, tree old_type)
458 : {
459 137983625 : gcc_checking_assert (c_verify_type (old_type));
460 :
461 137983625 : if (c_type_variably_modified_p (old_type))
462 28354 : C_TYPE_VARIABLY_MODIFIED (new_type) = true;
463 :
464 137983625 : if (TREE_CODE (new_type) == ARRAY_TYPE && C_TYPE_VARIABLE_SIZE (old_type))
465 : {
466 16809 : C_TYPE_VARIABLY_MODIFIED (new_type) = true;
467 16809 : C_TYPE_VARIABLE_SIZE (new_type) = true;
468 : }
469 137983625 : return new_type;
470 : }
471 :
472 : /* Build a pointer type using the default pointer mode. */
473 :
474 : tree
475 73766154 : c_build_pointer_type (tree to_type)
476 : {
477 73766154 : addr_space_t as = to_type == error_mark_node ? ADDR_SPACE_GENERIC
478 73766154 : : TYPE_ADDR_SPACE (to_type);
479 73766154 : machine_mode pointer_mode;
480 :
481 73766154 : if (as != ADDR_SPACE_GENERIC || c_default_pointer_mode == VOIDmode)
482 73766154 : pointer_mode = targetm.addr_space.pointer_mode (as);
483 : else
484 : pointer_mode = c_default_pointer_mode;
485 :
486 73766154 : return c_build_pointer_type_for_mode (to_type, pointer_mode, false);
487 : }
488 :
489 : /* Build a pointer type using the given mode. */
490 :
491 : tree
492 74015485 : c_build_pointer_type_for_mode (tree type, machine_mode mode, bool m)
493 : {
494 74015485 : tree ret = build_pointer_type_for_mode (type, mode, m);
495 74015485 : return c_set_type_bits (ret, type);
496 : }
497 :
498 : /* Build a function type. */
499 :
500 : tree
501 55236076 : c_build_function_type (tree type, tree args, bool no)
502 : {
503 55236076 : tree ret = build_function_type (type, args, no);
504 55236076 : return c_set_type_bits (ret, type);
505 : }
506 :
507 : /* Build an array type. This sets typeless storage as required
508 : by C2Y and C_TYPE_VARIABLY_MODIFIED and C_TYPE_VARIABLE_SIZE
509 : based on the element type and domain. */
510 :
511 : tree
512 1164040 : c_build_array_type (tree type, tree domain)
513 : {
514 1164040 : int type_quals = TYPE_QUALS (type);
515 :
516 : /* Identify typeless storage as introduced in C2Y
517 : and supported also in earlier language modes. */
518 1729340 : bool typeless = (char_type_p (type) && !(type_quals & TYPE_QUAL_ATOMIC))
519 1164040 : || (AGGREGATE_TYPE_P (type) && TYPE_TYPELESS_STORAGE (type));
520 :
521 1164040 : tree ret = build_array_type (type, domain, typeless);
522 :
523 1164040 : if (top_array_vla_p (ret))
524 : {
525 24283 : C_TYPE_VARIABLE_SIZE (ret) = 1;
526 24283 : C_TYPE_VARIABLY_MODIFIED (ret) = 1;
527 : }
528 :
529 1164040 : return c_set_type_bits (ret, type);
530 : }
531 :
532 : /* Build an array type of unspecified size. */
533 : tree
534 151 : c_build_array_type_unspecified (tree type)
535 : {
536 151 : tree upper = build2 (COMPOUND_EXPR, TREE_TYPE (size_zero_node),
537 : integer_zero_node, size_zero_node);
538 151 : return c_build_array_type (type, build_index_type (upper));
539 : }
540 :
541 : /* Build an array type of zero size. */
542 : tree
543 2609 : c_build_array_type_zero_size (tree type)
544 : {
545 : /* The GCC extension for zero-length arrays differs from
546 : ISO flexible array members in that sizeof yields
547 : zero. */
548 2609 : type = c_build_array_type (type, build_index_type (NULL_TREE));
549 2609 : type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
550 2609 : TYPE_SIZE (type) = bitsize_zero_node;
551 2609 : TYPE_SIZE_UNIT (type) = size_zero_node;
552 2609 : SET_TYPE_STRUCTURAL_EQUALITY (type);
553 2609 : return type;
554 : }
555 :
556 : tree
557 7568024 : c_build_type_attribute_qual_variant (tree type, tree attrs, int quals)
558 : {
559 7568024 : tree ret = build_type_attribute_qual_variant (type, attrs, quals);
560 7568024 : return c_set_type_bits (ret, type);
561 : }
562 :
563 : tree
564 7377964 : c_build_type_attribute_variant (tree type, tree attrs)
565 : {
566 7377964 : return c_build_type_attribute_qual_variant (type, attrs, TYPE_QUALS (type));
567 : }
568 :
569 : /* Reconstruct a complex derived type. This is used to re-construct types
570 : with the vector attribute. It is called via a langhook. */
571 :
572 : tree
573 844736 : c_reconstruct_complex_type (tree type, tree bottom)
574 : {
575 844736 : tree inner, outer;
576 :
577 844736 : if (TREE_CODE (type) == POINTER_TYPE)
578 : {
579 175691 : inner = c_reconstruct_complex_type (TREE_TYPE (type), bottom);
580 175691 : outer = c_build_pointer_type_for_mode (inner, TYPE_MODE (type),
581 175691 : TYPE_REF_CAN_ALIAS_ALL (type));
582 : }
583 : else if (TREE_CODE (type) == ARRAY_TYPE)
584 : {
585 7391 : bool rso = TYPE_REVERSE_STORAGE_ORDER (type);
586 7391 : inner = c_reconstruct_complex_type (TREE_TYPE (type), bottom);
587 7391 : outer = c_build_array_type (inner, TYPE_DOMAIN (type));
588 7391 : if (rso)
589 : {
590 1 : outer = build_distinct_type_copy (outer);
591 1 : TYPE_REVERSE_STORAGE_ORDER (outer) = 1;
592 : }
593 :
594 7391 : gcc_checking_assert (C_TYPE_VARIABLE_SIZE (type)
595 : == C_TYPE_VARIABLE_SIZE (outer));
596 : }
597 : else if (TREE_CODE (type) == FUNCTION_TYPE)
598 : {
599 602 : inner = c_reconstruct_complex_type (TREE_TYPE (type), bottom);
600 602 : outer = c_build_function_type (inner, TYPE_ARG_TYPES (type),
601 602 : TYPE_NO_NAMED_ARGS_STDARG_P (type));
602 : }
603 : else if (TREE_CODE (type) == REFERENCE_TYPE
604 : || TREE_CODE (type) == OFFSET_TYPE)
605 0 : gcc_unreachable ();
606 : else
607 : return bottom;
608 :
609 183684 : return c_build_type_attribute_qual_variant (outer, TYPE_ATTRIBUTES (type),
610 367368 : TYPE_QUALS (type));
611 : }
612 :
613 :
614 : /* Helper function for c_canonical_type. Check whether FIELD
615 : contains a pointer to a structure or union with tag,
616 : possibly nested in other type derivations, and return the
617 : type of this nested structure or union. */
618 : static tree
619 3459330 : ptr_to_tagged_member (tree field)
620 : {
621 3459330 : gcc_assert (FIELD_DECL == TREE_CODE (field));
622 3459330 : tree type = TREE_TYPE (field);
623 3459330 : bool ptr_seen = false;
624 3459330 : while (TREE_CODE (type) == ARRAY_TYPE
625 : || TREE_CODE (type) == FUNCTION_TYPE
626 4742092 : || TREE_CODE (type) == POINTER_TYPE)
627 : {
628 1282762 : if (TREE_CODE (type) == POINTER_TYPE)
629 702903 : ptr_seen = true;
630 1282762 : type = TREE_TYPE (type);
631 : }
632 :
633 3459330 : if (ptr_seen
634 682599 : && RECORD_OR_UNION_TYPE_P (type)
635 3709029 : && NULL_TREE != c_type_tag (type))
636 245544 : return type;
637 :
638 : return NULL_TREE;
639 : }
640 :
641 : /* For a record or union type, make necessary adaptations so that the
642 : type can be used as TYPE_CANONICAL.
643 :
644 : If the TYPE contains a pointer (possibly nested in other type
645 : derivations) to a structure or union as a member, create a copy and
646 : change the nested type to an incomplete type. Otherwise, the middle-end
647 : gets confused when recording component aliases in the case where we
648 : have formed equivalency classes that include types for which these
649 : member pointers end up pointing to other structure or unions types
650 : which have the same tag but are not compatible. */
651 : tree
652 892052 : c_type_canonical (tree type)
653 : {
654 892052 : gcc_assert (RECORD_OR_UNION_TYPE_P (type));
655 :
656 892052 : bool needs_mod = false;
657 3654029 : for (tree x = TYPE_FIELDS (type); x; x = DECL_CHAIN (x))
658 : {
659 2844190 : if (!ptr_to_tagged_member (x))
660 2761977 : continue;
661 : needs_mod = true;
662 : break;
663 : }
664 892052 : if (!needs_mod)
665 : return type;
666 :
667 : /* Construct new version with such members replaced. */
668 82213 : tree n = build_distinct_type_copy (type);
669 82213 : tree *fields = &TYPE_FIELDS (n);
670 697353 : for (tree x = TYPE_FIELDS (type); x; x = DECL_CHAIN (x))
671 : {
672 615140 : tree f = copy_node (x);
673 615140 : if (tree m = ptr_to_tagged_member (x))
674 : {
675 163331 : tree new_node = make_node (TREE_CODE (m));
676 163331 : TYPE_NAME (new_node) = TYPE_NAME (m);
677 163331 : SET_TYPE_STRUCTURAL_EQUALITY (new_node);
678 163331 : new_node = qualify_type (new_node, m);
679 163331 : TREE_TYPE (f) = c_reconstruct_complex_type (TREE_TYPE (x),
680 : new_node);
681 : }
682 615140 : *fields = f;
683 615140 : fields = &DECL_CHAIN (f);
684 : }
685 82213 : TYPE_CANONICAL (n) = n;
686 82213 : return n;
687 : }
688 :
689 :
690 : /* If NTYPE is a type of a non-variadic function with a prototype
691 : and OTYPE is a type of a function without a prototype and ATTRS
692 : contains attribute format, diagnosess and removes it from ATTRS.
693 : Returns the result of build_type_attribute_variant of NTYPE and
694 : the (possibly) modified ATTRS. */
695 :
696 : static tree
697 10777 : c_build_functype_attribute_variant (tree ntype, tree otype, tree attrs)
698 : {
699 10777 : if (!prototype_p (otype)
700 10765 : && prototype_p (ntype)
701 21512 : && lookup_attribute ("format", attrs))
702 : {
703 14 : warning_at (input_location, OPT_Wattributes,
704 : "%qs attribute can only be applied to variadic functions",
705 : "format");
706 14 : attrs = remove_attribute ("format", attrs);
707 : }
708 10777 : return c_build_type_attribute_variant (ntype, attrs);
709 :
710 : }
711 :
712 : /* Given a type which could be a typedef name, make sure to return the
713 : original type. See set_underlying_type. */
714 : static const_tree
715 62828481 : c_type_original (const_tree t)
716 : {
717 : /* It may even be a typedef of a typedef...
718 : In the case of compiler-created builtin structs the TYPE_DECL
719 : may be a dummy, with no DECL_ORIGINAL_TYPE. Don't fault. */
720 62828481 : while (TYPE_NAME (t)
721 32388064 : && TREE_CODE (TYPE_NAME (t)) == TYPE_DECL
722 62872949 : && DECL_ORIGINAL_TYPE (TYPE_NAME (t)))
723 22232 : t = DECL_ORIGINAL_TYPE (TYPE_NAME (t));
724 62828481 : return t;
725 : }
726 :
727 : /* Return the tag for a tagged type. */
728 : tree
729 62828481 : c_type_tag (const_tree t)
730 : {
731 62828481 : gcc_assert (RECORD_OR_UNION_TYPE_P (t) || TREE_CODE (t) == ENUMERAL_TYPE);
732 62828481 : const_tree orig = c_type_original (t);
733 62828481 : tree name = TYPE_NAME (orig);
734 62828481 : if (!name)
735 : return NULL_TREE;
736 32365832 : if (TREE_CODE (name) == TYPE_DECL)
737 : {
738 4 : if (!DECL_NAME (name))
739 : return NULL_TREE;
740 2 : name = DECL_NAME (name);
741 : }
742 32365830 : gcc_checking_assert (TREE_CODE (name) == IDENTIFIER_NODE);
743 : return name;
744 : }
745 :
746 : /* Remove qualifiers but not atomic. For arrays remove qualifiers
747 : on the element type but also do not remove atomic. */
748 : static tree
749 66223045 : remove_qualifiers (tree t)
750 : {
751 66223045 : if (!t || t == error_mark_node)
752 : return t;
753 66223020 : return TYPE_ATOMIC (strip_array_types (t))
754 66223020 : ? c_build_qualified_type (TYPE_MAIN_VARIANT (t), TYPE_QUAL_ATOMIC)
755 66207441 : : TYPE_MAIN_VARIANT (t);
756 : }
757 :
758 :
759 : /* Helper function for composite_type_internal. Find a compatible type
760 : in a (transparent) union U compatible to T. If found, return the
761 : type of the corresponding member. Otherwise, return the union type U. */
762 : static tree
763 8729214 : transparent_union_replacement (tree u, tree t)
764 : {
765 8729209 : if (u == error_mark_node || t == error_mark_node
766 8729204 : || TREE_CODE (u) != UNION_TYPE
767 64 : || !(TYPE_TRANSPARENT_AGGR (u) || TYPE_NAME (u) == NULL_TREE)
768 8729278 : || comptypes (u, t))
769 : return u;
770 :
771 80 : for (tree memb = TYPE_FIELDS (u); memb; memb = DECL_CHAIN (memb))
772 : {
773 80 : tree m = remove_qualifiers (TREE_TYPE (memb));
774 80 : if (comptypes (m, t))
775 : {
776 64 : pedwarn (input_location, OPT_Wpedantic,
777 : "function types not truly compatible in ISO C");
778 64 : return m;
779 : }
780 : }
781 :
782 : return u;
783 : }
784 :
785 :
786 :
787 : /* Return the composite type of two compatible types.
788 :
789 : We assume that comptypes has already been done and returned
790 : nonzero; if that isn't so, this may crash. In particular, we
791 : assume that qualifiers match. */
792 :
793 : struct composite_cache {
794 : tree t1;
795 : tree t2;
796 : tree composite;
797 : struct composite_cache* next;
798 : };
799 :
800 : tree
801 13769545 : composite_type_internal (tree t1, tree t2, tree cond,
802 : struct composite_cache* cache)
803 : {
804 13769545 : enum tree_code code1;
805 13769545 : enum tree_code code2;
806 13769545 : tree attributes;
807 :
808 : /* Save time if the two types are the same. */
809 :
810 13769545 : if (t1 == t2) return t1;
811 :
812 : /* If one type is nonsense, use the other. */
813 2789566 : if (t1 == error_mark_node)
814 : return t2;
815 2789562 : if (t2 == error_mark_node)
816 : return t1;
817 :
818 2789560 : code1 = TREE_CODE (t1);
819 2789560 : code2 = TREE_CODE (t2);
820 :
821 : /* Merge the attributes. */
822 2789560 : attributes = targetm.merge_type_attributes (t1, t2);
823 :
824 : /* If one is an enumerated type and the other is the compatible
825 : integer type, the composite type might be either of the two
826 : (DR#013 question 3). For consistency, use the enumerated type as
827 : the composite type. */
828 :
829 2789560 : if (code1 == ENUMERAL_TYPE
830 193 : && (code2 == INTEGER_TYPE
831 193 : || code2 == BOOLEAN_TYPE))
832 : return t1;
833 2789367 : if (code2 == ENUMERAL_TYPE
834 69 : && (code1 == INTEGER_TYPE
835 69 : || code1 == BOOLEAN_TYPE))
836 : return t2;
837 :
838 2789298 : gcc_assert (code1 == code2);
839 :
840 2789298 : switch (code1)
841 : {
842 6376 : case POINTER_TYPE:
843 : /* For two pointers, do this recursively on the target type. */
844 6376 : {
845 6376 : gcc_checking_assert (TYPE_QUALS (t1) == TYPE_QUALS (t2));
846 6376 : tree target = composite_type_internal (TREE_TYPE (t1), TREE_TYPE (t2),
847 : cond, cache);
848 6376 : tree n = c_build_pointer_type_for_mode (target, TYPE_MODE (t1), false);
849 12752 : return c_build_type_attribute_qual_variant (n, attributes,
850 6376 : TYPE_QUALS (t2));
851 : }
852 :
853 10996 : case ARRAY_TYPE:
854 10996 : {
855 10996 : tree d1 = TYPE_DOMAIN (t1);
856 10996 : tree d2 = TYPE_DOMAIN (t2);
857 :
858 : /* We should not have any type quals on arrays at all. */
859 10996 : gcc_assert (!TYPE_QUALS_NO_ADDR_SPACE (t1)
860 : && !TYPE_QUALS_NO_ADDR_SPACE (t2));
861 :
862 10996 : bool d1_zero = zero_length_array_type_p (t1)
863 10996 : || flexible_array_member_type_p (t1);
864 10996 : bool d2_zero = zero_length_array_type_p (t2)
865 10996 : || flexible_array_member_type_p (t2);
866 :
867 10996 : bool d1_variable = top_array_vla_p (t1);
868 10996 : bool d2_variable = top_array_vla_p (t2);
869 :
870 10996 : bool use1 = d1 && (d2_variable || !d2 || d2_zero || !d1_variable);
871 10996 : bool use2 = d2 && (d1_variable || !d1 || d1_zero || !d2_variable);
872 :
873 : /* If the first is an unspecified size pick the other one. */
874 10996 : if (d2_variable && c_type_unspecified_p (t1))
875 : {
876 29 : gcc_assert (use1 && use2);
877 : use1 = false;
878 : }
879 :
880 : /* If both are VLAs but not unspecified and we are in the
881 : conditional operator, we create a conditional to select
882 : the size of the active branch. */
883 232 : bool use0 = cond && d1_variable && !c_type_unspecified_p (t1)
884 11225 : && d2_variable && !c_type_unspecified_p (t2);
885 :
886 10996 : tree td;
887 10996 : tree elt = composite_type_internal (TREE_TYPE (t1), TREE_TYPE (t2),
888 : cond, cache);
889 :
890 10996 : if (!use0)
891 : {
892 : /* Save space: see if the result is identical to one of the args. */
893 10879 : if (elt == TREE_TYPE (t1) && use1)
894 10088 : return c_build_type_attribute_variant (t1, attributes);
895 791 : if (elt == TREE_TYPE (t2) && use2)
896 673 : return c_build_type_attribute_variant (t2, attributes);
897 :
898 161 : if (elt == TREE_TYPE (t1) && !TYPE_DOMAIN (t2) && !TYPE_DOMAIN (t1))
899 10 : return c_build_type_attribute_variant (t1, attributes);
900 116 : if (elt == TREE_TYPE (t2) && !TYPE_DOMAIN (t2) && !TYPE_DOMAIN (t1))
901 2 : return c_build_type_attribute_variant (t2, attributes);
902 :
903 212 : td = TYPE_DOMAIN (use1 ? t1 : t2);
904 : }
905 : else
906 : {
907 : /* Not used in C. */
908 117 : gcc_assert (size_zero_node == TYPE_MIN_VALUE (d1));
909 117 : gcc_assert (size_zero_node == TYPE_MIN_VALUE (d2));
910 :
911 117 : tree d = fold_build3_loc (UNKNOWN_LOCATION, COND_EXPR, sizetype,
912 117 : cond, TYPE_MAX_VALUE (d1),
913 117 : TYPE_MAX_VALUE (d2));
914 :
915 117 : td = build_index_type (d);
916 : }
917 :
918 : /* Merge the element types, and have a size if either arg has
919 : one. We may have qualifiers on the element types. To set
920 : up TYPE_MAIN_VARIANT correctly, we need to form the
921 : composite of the unqualified types and add the qualifiers
922 : back at the end. */
923 223 : int quals = TYPE_QUALS (strip_array_types (elt));
924 223 : tree unqual_elt = c_build_qualified_type (elt, TYPE_UNQUALIFIED);
925 :
926 223 : if ((!d1 || d1_zero) && (!d2 || d2_zero) && (d1 || d2))
927 1 : t1 = c_build_array_type_zero_size (unqual_elt);
928 : else
929 222 : t1 = c_build_array_type (unqual_elt, td);
930 :
931 : /* Check that a type which has a varying outermost dimension
932 : got marked as having a variable size. */
933 223 : bool varsize = (d1_variable && d2_variable)
934 97 : || (d1_variable && !d2)
935 309 : || (d2_variable && !d1);
936 157 : gcc_checking_assert (!varsize || C_TYPE_VARIABLE_SIZE (t1));
937 :
938 223 : t1 = c_build_qualified_type (t1, quals);
939 223 : return c_build_type_attribute_variant (t1, attributes);
940 : }
941 :
942 253 : case RECORD_TYPE:
943 253 : case UNION_TYPE:
944 253 : if (flag_isoc23 && !comptypes_same_p (t1, t2))
945 : {
946 : /* Go to the original type to get the right tag. */
947 150 : tree tag = c_type_tag (t1);
948 :
949 150 : gcc_checking_assert (COMPLETE_TYPE_P (t1) && COMPLETE_TYPE_P (t2));
950 150 : gcc_checking_assert (!tag || comptypes (t1, t2));
951 :
952 : /* If a composite type for these two types is already under
953 : construction, return it. */
954 :
955 376 : for (struct composite_cache *c = cache; c != NULL; c = c->next)
956 246 : if ((c->t1 == t1 && c->t2 == t2) || (c->t1 == t2 && c->t2 == t1))
957 20 : return c->composite;
958 :
959 : /* Otherwise, create a new type node and link it into the cache. */
960 :
961 130 : tree n = make_node (code1);
962 130 : SET_TYPE_STRUCTURAL_EQUALITY (n);
963 130 : TYPE_NAME (n) = tag;
964 :
965 130 : struct composite_cache cache2 = { t1, t2, n, cache };
966 130 : cache = &cache2;
967 :
968 130 : tree f1 = TYPE_FIELDS (t1);
969 130 : tree f2 = TYPE_FIELDS (t2);
970 130 : tree fields = NULL_TREE;
971 :
972 321 : for (tree a = f1, b = f2; a && b;
973 191 : a = DECL_CHAIN (a), b = DECL_CHAIN (b))
974 : {
975 191 : tree ta = TREE_TYPE (a);
976 191 : tree tb = TREE_TYPE (b);
977 :
978 191 : if (DECL_C_BIT_FIELD (a))
979 : {
980 19 : ta = DECL_BIT_FIELD_TYPE (a);
981 19 : tb = DECL_BIT_FIELD_TYPE (b);
982 : }
983 :
984 191 : gcc_assert (DECL_NAME (a) == DECL_NAME (b));
985 191 : gcc_checking_assert (!DECL_NAME (a) || comptypes (ta, tb));
986 :
987 191 : tree t = composite_type_internal (ta, tb, cond, cache);
988 191 : tree f = build_decl (input_location, FIELD_DECL, DECL_NAME (a), t);
989 :
990 191 : DECL_PACKED (f) = DECL_PACKED (a);
991 191 : SET_DECL_ALIGN (f, DECL_ALIGN (a));
992 191 : DECL_ATTRIBUTES (f) = DECL_ATTRIBUTES (a);
993 191 : C_DECL_VARIABLE_SIZE (f) = C_TYPE_VARIABLE_SIZE (t);
994 :
995 191 : decl_attributes (&f, DECL_ATTRIBUTES (f), 0);
996 :
997 191 : finish_decl (f, input_location, NULL, NULL, NULL);
998 :
999 191 : if (DECL_C_BIT_FIELD (a))
1000 : {
1001 : /* This will be processed by finish_struct. */
1002 19 : SET_DECL_C_BIT_FIELD (f);
1003 19 : DECL_INITIAL (f) = build_int_cst (integer_type_node,
1004 19 : tree_to_uhwi (DECL_SIZE (a)));
1005 19 : DECL_NONADDRESSABLE_P (f) = true;
1006 19 : DECL_PADDING_P (f) = !DECL_NAME (a);
1007 : }
1008 :
1009 191 : DECL_CHAIN (f) = fields;
1010 191 : fields = f;
1011 : }
1012 :
1013 130 : fields = nreverse (fields);
1014 :
1015 : /* Setup the struct/union type. Because we inherit all variably
1016 : modified components, we can ignore the size expression. */
1017 130 : tree expr = NULL_TREE;
1018 :
1019 : /* Set TYPE_STUB_DECL for debugging symbols. */
1020 130 : TYPE_STUB_DECL (n) = pushdecl (build_decl (input_location, TYPE_DECL,
1021 : NULL_TREE, n));
1022 :
1023 130 : n = finish_struct (input_location, n, fields, attributes, NULL,
1024 : &expr);
1025 :
1026 130 : return qualify_type (n, t1);
1027 : }
1028 : /* FALLTHRU */
1029 103 : case ENUMERAL_TYPE:
1030 103 : if (attributes != NULL)
1031 : {
1032 : /* Try harder not to create a new aggregate type. */
1033 4 : if (attribute_list_equal (TYPE_ATTRIBUTES (t1), attributes))
1034 : return t1;
1035 0 : if (attribute_list_equal (TYPE_ATTRIBUTES (t2), attributes))
1036 : return t2;
1037 : }
1038 99 : return c_build_type_attribute_variant (t1, attributes);
1039 :
1040 2722452 : case FUNCTION_TYPE:
1041 : /* Function types: prefer the one that specified arg types.
1042 : If both do, merge the arg types. Also merge the return types. */
1043 2722452 : {
1044 2722452 : tree valtype = composite_type_internal (TREE_TYPE (t1), TREE_TYPE (t2),
1045 : cond, cache);
1046 2722452 : tree p1 = TYPE_ARG_TYPES (t1);
1047 2722452 : tree p2 = TYPE_ARG_TYPES (t2);
1048 :
1049 : /* Save space: see if the result is identical to one of the args. */
1050 2722452 : if (valtype == TREE_TYPE (t1) && !TYPE_ARG_TYPES (t2))
1051 10787 : return c_build_functype_attribute_variant (t1, t2, attributes);
1052 2712200 : if (valtype == TREE_TYPE (t2) && !TYPE_ARG_TYPES (t1))
1053 525 : return c_build_functype_attribute_variant (t2, t1, attributes);
1054 :
1055 : /* Simple way if one arg fails to specify argument types. */
1056 2711675 : if (TYPE_ARG_TYPES (t1) == NULL_TREE)
1057 : {
1058 9 : t1 = c_build_function_type (valtype, TYPE_ARG_TYPES (t2),
1059 9 : TYPE_NO_NAMED_ARGS_STDARG_P (t2));
1060 9 : t1 = c_build_type_attribute_variant (t1, attributes);
1061 9 : return qualify_type (t1, t2);
1062 : }
1063 2711666 : if (TYPE_ARG_TYPES (t2) == NULL_TREE)
1064 : {
1065 1 : t1 = c_build_function_type (valtype, TYPE_ARG_TYPES (t1),
1066 1 : TYPE_NO_NAMED_ARGS_STDARG_P (t1));
1067 1 : t1 = c_build_type_attribute_variant (t1, attributes);
1068 1 : return qualify_type (t1, t2);
1069 : }
1070 :
1071 : /* If both args specify argument types, we must merge the two
1072 : lists, argument by argument. */
1073 2711665 : tree newargs = NULL_TREE;
1074 2711665 : tree *endp = &newargs;
1075 :
1076 7076272 : for (; p1; p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2))
1077 : {
1078 6907478 : if (p1 == void_list_node)
1079 : {
1080 2542871 : *endp = void_list_node;
1081 2542871 : break;
1082 : }
1083 4364607 : tree mv1 = remove_qualifiers (TREE_VALUE (p1));
1084 4364607 : tree mv2 = remove_qualifiers (TREE_VALUE (p2));
1085 :
1086 4364607 : gcc_assert (mv1);
1087 4364607 : gcc_assert (mv2);
1088 :
1089 4364607 : mv1 = transparent_union_replacement (mv1, mv2);
1090 4364607 : mv2 = transparent_union_replacement (mv2, mv1);
1091 :
1092 4364607 : *endp = tree_cons (NULL_TREE,
1093 : composite_type_internal (mv1, mv2, cond, cache),
1094 : NULL_TREE);
1095 :
1096 4364607 : endp = &TREE_CHAIN (*endp);
1097 : }
1098 :
1099 2711665 : t1 = c_build_function_type (valtype, newargs);
1100 2711665 : t1 = qualify_type (t1, t2);
1101 : }
1102 : /* FALLTHRU */
1103 :
1104 2760886 : default:
1105 2760886 : return c_build_type_attribute_variant (t1, attributes);
1106 : }
1107 : }
1108 :
1109 : tree
1110 6664923 : composite_type_cond (tree t1, tree t2, tree cond)
1111 : {
1112 6664923 : gcc_checking_assert (comptypes_check_for_composite (t1, t2));
1113 :
1114 6664923 : struct composite_cache cache = { };
1115 6664923 : tree n = composite_type_internal (t1, t2, cond, &cache);
1116 :
1117 6664923 : gcc_checking_assert (comptypes_check_for_composite (n, t1));
1118 6664923 : gcc_checking_assert (comptypes_check_for_composite (n, t2));
1119 6664923 : return n;
1120 : }
1121 :
1122 :
1123 : tree
1124 6660446 : composite_type (tree t1, tree t2)
1125 : {
1126 6660446 : return composite_type_cond (t1, t2, NULL_TREE);
1127 : }
1128 :
1129 : /* Return the type of a conditional expression between pointers to
1130 : possibly differently qualified versions of compatible types.
1131 :
1132 : We assume that comp_target_types has already been done and returned
1133 : true; if that isn't so, this may crash. */
1134 :
1135 : static tree
1136 116881 : common_pointer_type (tree t1, tree t2, tree cond)
1137 : {
1138 116881 : tree attributes;
1139 116881 : unsigned target_quals;
1140 116881 : addr_space_t as1, as2, as_common;
1141 116881 : int quals1, quals2;
1142 :
1143 : /* Save time if the two types are the same. */
1144 :
1145 116881 : if (t1 == t2) return t1;
1146 :
1147 : /* If one type is nonsense, use the other. */
1148 4477 : if (t1 == error_mark_node)
1149 : return t2;
1150 4477 : if (t2 == error_mark_node)
1151 : return t1;
1152 :
1153 4477 : gcc_assert (TREE_CODE (t1) == POINTER_TYPE
1154 : && TREE_CODE (t2) == POINTER_TYPE);
1155 :
1156 : /* Merge the attributes. */
1157 4477 : attributes = targetm.merge_type_attributes (t1, t2);
1158 :
1159 : /* Find the composite type of the target types, and combine the
1160 : qualifiers of the two types' targets. */
1161 4477 : tree pointed_to_1 = TREE_TYPE (t1);
1162 4477 : tree pointed_to_2 = TREE_TYPE (t2);
1163 4477 : tree target = composite_type_cond (TYPE_MAIN_VARIANT (pointed_to_1),
1164 4477 : TYPE_MAIN_VARIANT (pointed_to_2), cond);
1165 :
1166 : /* Strip array types to get correct qualifier for pointers to arrays */
1167 4477 : quals1 = TYPE_QUALS_NO_ADDR_SPACE (strip_array_types (pointed_to_1));
1168 4477 : quals2 = TYPE_QUALS_NO_ADDR_SPACE (strip_array_types (pointed_to_2));
1169 :
1170 : /* For function types do not merge const qualifiers, but drop them
1171 : if used inconsistently. The middle-end uses these to mark const
1172 : and noreturn functions. */
1173 4477 : if (TREE_CODE (pointed_to_1) == FUNCTION_TYPE)
1174 2129 : target_quals = (quals1 & quals2);
1175 : else
1176 2348 : target_quals = (quals1 | quals2);
1177 :
1178 : /* If the two named address spaces are different, determine the common
1179 : superset address space. This is guaranteed to exist due to the
1180 : assumption that comp_target_type returned true. */
1181 4477 : as1 = TYPE_ADDR_SPACE (pointed_to_1);
1182 4477 : as2 = TYPE_ADDR_SPACE (pointed_to_2);
1183 4477 : if (!addr_space_superset (as1, as2, &as_common))
1184 0 : gcc_unreachable ();
1185 :
1186 4477 : target_quals |= ENCODE_QUAL_ADDR_SPACE (as_common);
1187 :
1188 4477 : t1 = c_build_pointer_type (c_build_qualified_type (target, target_quals));
1189 4477 : return c_build_type_attribute_variant (t1, attributes);
1190 : }
1191 :
1192 : /* Return the common type for two arithmetic types under the usual
1193 : arithmetic conversions. The default conversions have already been
1194 : applied, and enumerated types converted to their compatible integer
1195 : types. The resulting type is unqualified and has no attributes.
1196 :
1197 : This is the type for the result of most arithmetic operations
1198 : if the operands have the given two types. */
1199 :
1200 : static tree
1201 14105269 : c_common_type (tree t1, tree t2)
1202 : {
1203 14105269 : enum tree_code code1;
1204 14105269 : enum tree_code code2;
1205 :
1206 : /* If one type is nonsense, use the other. */
1207 14105269 : if (t1 == error_mark_node)
1208 : return t2;
1209 14105269 : if (t2 == error_mark_node)
1210 : return t1;
1211 :
1212 14105269 : if (TYPE_QUALS (t1) != TYPE_UNQUALIFIED)
1213 38008 : t1 = TYPE_MAIN_VARIANT (t1);
1214 :
1215 14105269 : if (TYPE_QUALS (t2) != TYPE_UNQUALIFIED)
1216 49416 : t2 = TYPE_MAIN_VARIANT (t2);
1217 :
1218 14105269 : if (TYPE_ATTRIBUTES (t1) != NULL_TREE)
1219 : {
1220 189258 : tree attrs = affects_type_identity_attributes (TYPE_ATTRIBUTES (t1));
1221 189258 : t1 = c_build_type_attribute_variant (t1, attrs);
1222 : }
1223 :
1224 14105269 : if (TYPE_ATTRIBUTES (t2) != NULL_TREE)
1225 : {
1226 188736 : tree attrs = affects_type_identity_attributes (TYPE_ATTRIBUTES (t2));
1227 188736 : t2 = c_build_type_attribute_variant (t2, attrs);
1228 : }
1229 :
1230 : /* Save time if the two types are the same. */
1231 :
1232 14105269 : if (t1 == t2) return t1;
1233 :
1234 2344671 : code1 = TREE_CODE (t1);
1235 2344671 : code2 = TREE_CODE (t2);
1236 :
1237 2344671 : gcc_assert (code1 == VECTOR_TYPE || code1 == COMPLEX_TYPE
1238 : || code1 == FIXED_POINT_TYPE || code1 == REAL_TYPE
1239 : || code1 == INTEGER_TYPE || code1 == BITINT_TYPE);
1240 2344671 : gcc_assert (code2 == VECTOR_TYPE || code2 == COMPLEX_TYPE
1241 : || code2 == FIXED_POINT_TYPE || code2 == REAL_TYPE
1242 : || code2 == INTEGER_TYPE || code2 == BITINT_TYPE);
1243 :
1244 : /* When one operand is a decimal float type, the other operand cannot be
1245 : a generic float type or a complex type. We also disallow vector types
1246 : here. */
1247 2344671 : if ((DECIMAL_FLOAT_TYPE_P (t1) || DECIMAL_FLOAT_TYPE_P (t2))
1248 2347094 : && !(DECIMAL_FLOAT_TYPE_P (t1) && DECIMAL_FLOAT_TYPE_P (t2)))
1249 : {
1250 1080 : if (code1 == VECTOR_TYPE || code2 == VECTOR_TYPE)
1251 : {
1252 3 : error ("cannot mix operands of decimal floating and vector types");
1253 3 : return error_mark_node;
1254 : }
1255 1077 : if (code1 == COMPLEX_TYPE || code2 == COMPLEX_TYPE)
1256 : {
1257 5 : error ("cannot mix operands of decimal floating and complex types");
1258 5 : return error_mark_node;
1259 : }
1260 1072 : if (code1 == REAL_TYPE && code2 == REAL_TYPE)
1261 : {
1262 16 : error ("cannot mix operands of decimal floating "
1263 : "and other floating types");
1264 16 : return error_mark_node;
1265 : }
1266 : }
1267 :
1268 : /* If one type is a vector type, return that type. (How the usual
1269 : arithmetic conversions apply to the vector types extension is not
1270 : precisely specified.) */
1271 2344647 : if (code1 == VECTOR_TYPE)
1272 : return t1;
1273 :
1274 2344355 : if (code2 == VECTOR_TYPE)
1275 : return t2;
1276 :
1277 : /* If one type is complex, form the common type of the non-complex
1278 : components, then make that complex. Use T1 or T2 if it is the
1279 : required type. */
1280 2344352 : if (code1 == COMPLEX_TYPE || code2 == COMPLEX_TYPE)
1281 : {
1282 89365 : tree subtype1 = code1 == COMPLEX_TYPE ? TREE_TYPE (t1) : t1;
1283 89365 : tree subtype2 = code2 == COMPLEX_TYPE ? TREE_TYPE (t2) : t2;
1284 89365 : tree subtype = c_common_type (subtype1, subtype2);
1285 :
1286 89365 : if (code1 == COMPLEX_TYPE && TREE_TYPE (t1) == subtype)
1287 : return t1;
1288 59243 : else if (code2 == COMPLEX_TYPE && TREE_TYPE (t2) == subtype)
1289 : return t2;
1290 3258 : else if (TREE_CODE (subtype) == BITINT_TYPE)
1291 : {
1292 8 : sorry ("%<_Complex _BitInt(%d)%> unsupported",
1293 4 : TYPE_PRECISION (subtype));
1294 4 : return code1 == COMPLEX_TYPE ? t1 : t2;
1295 : }
1296 : else
1297 3254 : return build_complex_type (subtype);
1298 : }
1299 :
1300 : /* If only one is real, use it as the result. */
1301 :
1302 2254987 : if (code1 == REAL_TYPE && code2 != REAL_TYPE)
1303 : return t1;
1304 :
1305 2125954 : if (code2 == REAL_TYPE && code1 != REAL_TYPE)
1306 : return t2;
1307 :
1308 : /* If both are real and either are decimal floating point types, use
1309 : the decimal floating point type with the greater precision. */
1310 :
1311 2094611 : if (code1 == REAL_TYPE && code2 == REAL_TYPE)
1312 : {
1313 107560 : if (TYPE_MAIN_VARIANT (t1) == dfloat128_type_node
1314 107560 : || TYPE_MAIN_VARIANT (t2) == dfloat128_type_node)
1315 : return dfloat128_type_node;
1316 : /* And prefer _Decimal128 over _Decimal64x which has in GCC's
1317 : implementation the same mode. */
1318 107011 : else if (TYPE_MAIN_VARIANT (t1) == dfloat64x_type_node
1319 107011 : || TYPE_MAIN_VARIANT (t2) == dfloat64x_type_node)
1320 : return dfloat64x_type_node;
1321 107007 : else if (TYPE_MAIN_VARIANT (t1) == dfloat64_type_node
1322 107007 : || TYPE_MAIN_VARIANT (t2) == dfloat64_type_node)
1323 : return dfloat64_type_node;
1324 106562 : else if (TYPE_MAIN_VARIANT (t1) == dfloat32_type_node
1325 106562 : || TYPE_MAIN_VARIANT (t2) == dfloat32_type_node)
1326 : return dfloat32_type_node;
1327 : }
1328 :
1329 : /* Deal with fixed-point types. */
1330 2093268 : if (code1 == FIXED_POINT_TYPE || code2 == FIXED_POINT_TYPE)
1331 : {
1332 0 : unsigned int unsignedp = 0, satp = 0;
1333 0 : scalar_mode m1, m2;
1334 0 : unsigned int fbit1, ibit1, fbit2, ibit2, max_fbit, max_ibit;
1335 :
1336 0 : m1 = SCALAR_TYPE_MODE (t1);
1337 0 : m2 = SCALAR_TYPE_MODE (t2);
1338 :
1339 : /* If one input type is saturating, the result type is saturating. */
1340 0 : if (TYPE_SATURATING (t1) || TYPE_SATURATING (t2))
1341 : satp = 1;
1342 :
1343 : /* If both fixed-point types are unsigned, the result type is unsigned.
1344 : When mixing fixed-point and integer types, follow the sign of the
1345 : fixed-point type.
1346 : Otherwise, the result type is signed. */
1347 0 : if ((TYPE_UNSIGNED (t1) && TYPE_UNSIGNED (t2)
1348 0 : && code1 == FIXED_POINT_TYPE && code2 == FIXED_POINT_TYPE)
1349 0 : || (code1 == FIXED_POINT_TYPE && code2 != FIXED_POINT_TYPE
1350 0 : && TYPE_UNSIGNED (t1))
1351 0 : || (code1 != FIXED_POINT_TYPE && code2 == FIXED_POINT_TYPE
1352 0 : && TYPE_UNSIGNED (t2)))
1353 : unsignedp = 1;
1354 :
1355 : /* The result type is signed. */
1356 0 : if (unsignedp == 0)
1357 : {
1358 : /* If the input type is unsigned, we need to convert to the
1359 : signed type. */
1360 0 : if (code1 == FIXED_POINT_TYPE && TYPE_UNSIGNED (t1))
1361 : {
1362 0 : enum mode_class mclass = (enum mode_class) 0;
1363 0 : if (GET_MODE_CLASS (m1) == MODE_UFRACT)
1364 : mclass = MODE_FRACT;
1365 0 : else if (GET_MODE_CLASS (m1) == MODE_UACCUM)
1366 : mclass = MODE_ACCUM;
1367 : else
1368 0 : gcc_unreachable ();
1369 0 : m1 = as_a <scalar_mode>
1370 0 : (mode_for_size (GET_MODE_PRECISION (m1), mclass, 0));
1371 : }
1372 0 : if (code2 == FIXED_POINT_TYPE && TYPE_UNSIGNED (t2))
1373 : {
1374 0 : enum mode_class mclass = (enum mode_class) 0;
1375 0 : if (GET_MODE_CLASS (m2) == MODE_UFRACT)
1376 : mclass = MODE_FRACT;
1377 0 : else if (GET_MODE_CLASS (m2) == MODE_UACCUM)
1378 : mclass = MODE_ACCUM;
1379 : else
1380 0 : gcc_unreachable ();
1381 0 : m2 = as_a <scalar_mode>
1382 0 : (mode_for_size (GET_MODE_PRECISION (m2), mclass, 0));
1383 : }
1384 : }
1385 :
1386 0 : if (code1 == FIXED_POINT_TYPE)
1387 : {
1388 0 : fbit1 = GET_MODE_FBIT (m1);
1389 0 : ibit1 = GET_MODE_IBIT (m1);
1390 : }
1391 : else
1392 : {
1393 0 : fbit1 = 0;
1394 : /* Signed integers need to subtract one sign bit. */
1395 0 : ibit1 = TYPE_PRECISION (t1) - (!TYPE_UNSIGNED (t1));
1396 : }
1397 :
1398 0 : if (code2 == FIXED_POINT_TYPE)
1399 : {
1400 0 : fbit2 = GET_MODE_FBIT (m2);
1401 0 : ibit2 = GET_MODE_IBIT (m2);
1402 : }
1403 : else
1404 : {
1405 0 : fbit2 = 0;
1406 : /* Signed integers need to subtract one sign bit. */
1407 0 : ibit2 = TYPE_PRECISION (t2) - (!TYPE_UNSIGNED (t2));
1408 : }
1409 :
1410 0 : max_ibit = ibit1 >= ibit2 ? ibit1 : ibit2;
1411 0 : max_fbit = fbit1 >= fbit2 ? fbit1 : fbit2;
1412 0 : return c_common_fixed_point_type_for_size (max_ibit, max_fbit, unsignedp,
1413 : satp);
1414 : }
1415 :
1416 : /* Both real or both integers; use the one with greater precision. */
1417 :
1418 2093268 : if (TYPE_PRECISION (t1) > TYPE_PRECISION (t2))
1419 : return t1;
1420 1117303 : else if (TYPE_PRECISION (t2) > TYPE_PRECISION (t1))
1421 : return t2;
1422 :
1423 : /* Same precision. Prefer long longs to longs to ints when the
1424 : same precision, following the C99 rules on integer type rank
1425 : (which are equivalent to the C90 rules for C90 types). */
1426 :
1427 751447 : if (TYPE_MAIN_VARIANT (t1) == long_long_unsigned_type_node
1428 751447 : || TYPE_MAIN_VARIANT (t2) == long_long_unsigned_type_node)
1429 : return long_long_unsigned_type_node;
1430 :
1431 662172 : if (TYPE_MAIN_VARIANT (t1) == long_long_integer_type_node
1432 662172 : || TYPE_MAIN_VARIANT (t2) == long_long_integer_type_node)
1433 : {
1434 15348 : if (TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2))
1435 361 : return long_long_unsigned_type_node;
1436 : else
1437 : return long_long_integer_type_node;
1438 : }
1439 :
1440 646824 : if (TYPE_MAIN_VARIANT (t1) == long_unsigned_type_node
1441 646824 : || TYPE_MAIN_VARIANT (t2) == long_unsigned_type_node)
1442 : return long_unsigned_type_node;
1443 :
1444 547453 : if (TYPE_MAIN_VARIANT (t1) == long_integer_type_node
1445 547453 : || TYPE_MAIN_VARIANT (t2) == long_integer_type_node)
1446 : {
1447 : /* But preserve unsignedness from the other type,
1448 : since long cannot hold all the values of an unsigned int. */
1449 26485 : if (TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2))
1450 129 : return long_unsigned_type_node;
1451 : else
1452 : return long_integer_type_node;
1453 : }
1454 :
1455 : /* For floating types of the same TYPE_PRECISION (which we here
1456 : assume means either the same set of values, or sets of values
1457 : neither a subset of the other, with behavior being undefined in
1458 : the latter case), follow the rules from TS 18661-3: prefer
1459 : interchange types _FloatN, then standard types long double,
1460 : double, float, then extended types _FloatNx. For extended types,
1461 : check them starting with _Float128x as that seems most consistent
1462 : in spirit with preferring long double to double; for interchange
1463 : types, also check in that order for consistency although it's not
1464 : possible for more than one of them to have the same
1465 : precision. */
1466 520968 : tree mv1 = TYPE_MAIN_VARIANT (t1);
1467 520968 : tree mv2 = TYPE_MAIN_VARIANT (t2);
1468 :
1469 2604194 : for (int i = NUM_FLOATN_TYPES - 1; i >= 0; i--)
1470 2083409 : if (mv1 == FLOATN_TYPE_NODE (i) || mv2 == FLOATN_TYPE_NODE (i))
1471 : return FLOATN_TYPE_NODE (i);
1472 :
1473 : /* Likewise, prefer long double to double even if same size. */
1474 520785 : if (mv1 == long_double_type_node || mv2 == long_double_type_node)
1475 : return long_double_type_node;
1476 :
1477 : /* Likewise, prefer double to float even if same size.
1478 : We got a couple of embedded targets with 32 bit doubles, and the
1479 : pdp11 might have 64 bit floats. */
1480 520527 : if (mv1 == double_type_node || mv2 == double_type_node)
1481 : return double_type_node;
1482 :
1483 519955 : if (mv1 == float_type_node || mv2 == float_type_node)
1484 : return float_type_node;
1485 :
1486 2071080 : for (int i = NUM_FLOATNX_TYPES - 1; i >= 0; i--)
1487 1553310 : if (mv1 == FLOATNX_TYPE_NODE (i) || mv2 == FLOATNX_TYPE_NODE (i))
1488 : return FLOATNX_TYPE_NODE (i);
1489 :
1490 517770 : if ((code1 == BITINT_TYPE || code2 == BITINT_TYPE) && code1 != code2)
1491 : {
1492 : /* Prefer any other integral types over bit-precise integer types. */
1493 10 : if (TYPE_UNSIGNED (t1) == TYPE_UNSIGNED (t2))
1494 4 : return code1 == BITINT_TYPE ? t2 : t1;
1495 : /* If BITINT_TYPE is unsigned and the other type is signed
1496 : non-BITINT_TYPE with the same precision, the latter has higher rank.
1497 : In that case:
1498 : Otherwise, both operands are converted to the unsigned integer type
1499 : corresponding to the type of the operand with signed integer type. */
1500 8 : if (TYPE_UNSIGNED (code1 == BITINT_TYPE ? t1 : t2))
1501 5 : return c_common_unsigned_type (code1 == BITINT_TYPE ? t2 : t1);
1502 : }
1503 :
1504 : /* Otherwise prefer the unsigned one. */
1505 :
1506 517762 : if (TYPE_UNSIGNED (t1))
1507 : return t1;
1508 : else
1509 212441 : return t2;
1510 : }
1511 :
1512 : /* Wrapper around c_common_type that is used by c-common.cc and other
1513 : front end optimizations that remove promotions. ENUMERAL_TYPEs
1514 : are allowed here and are converted to their compatible integer types.
1515 : BOOLEAN_TYPEs are allowed here and return either boolean_type_node or
1516 : preferably a non-Boolean type as the common type. */
1517 : tree
1518 104138 : common_type (tree t1, tree t2)
1519 : {
1520 104138 : if (TREE_CODE (t1) == ENUMERAL_TYPE)
1521 0 : t1 = ENUM_UNDERLYING_TYPE (t1);
1522 104138 : if (TREE_CODE (t2) == ENUMERAL_TYPE)
1523 1 : t2 = ENUM_UNDERLYING_TYPE (t2);
1524 :
1525 : /* If both types are BOOLEAN_TYPE, then return boolean_type_node. */
1526 104138 : if (TREE_CODE (t1) == BOOLEAN_TYPE
1527 584 : && TREE_CODE (t2) == BOOLEAN_TYPE)
1528 584 : return boolean_type_node;
1529 :
1530 : /* If either type is BOOLEAN_TYPE, then return the other. */
1531 103554 : if (TREE_CODE (t1) == BOOLEAN_TYPE)
1532 : return t2;
1533 103554 : if (TREE_CODE (t2) == BOOLEAN_TYPE)
1534 : return t1;
1535 :
1536 103554 : return c_common_type (t1, t2);
1537 : }
1538 :
1539 :
1540 :
1541 : /* Helper function for comptypes. For two compatible types, return 1
1542 : if they pass consistency checks. In particular we test that
1543 : TYPE_CANONICAL is set correctly, i.e. the two types can alias. */
1544 :
1545 : static bool
1546 43507462 : comptypes_verify (tree type1, tree type2)
1547 : {
1548 43507462 : if (type1 == type2 || !type1 || !type2
1549 3636814 : || TREE_CODE (type1) == ERROR_MARK || TREE_CODE (type2) == ERROR_MARK)
1550 : return true;
1551 :
1552 3636813 : gcc_checking_assert (c_verify_type (type1));
1553 3636813 : gcc_checking_assert (c_verify_type (type2));
1554 :
1555 3636813 : if (TYPE_CANONICAL (type1) != TYPE_CANONICAL (type2)
1556 403434 : && !TYPE_STRUCTURAL_EQUALITY_P (type1)
1557 4038744 : && !TYPE_STRUCTURAL_EQUALITY_P (type2))
1558 : {
1559 : /* FIXME: check other types. */
1560 401620 : if (RECORD_OR_UNION_TYPE_P (type1)
1561 401620 : || TREE_CODE (type1) == ENUMERAL_TYPE
1562 401620 : || TREE_CODE (type2) == ENUMERAL_TYPE)
1563 0 : return false;
1564 : }
1565 : return true;
1566 : }
1567 :
1568 : struct comptypes_data {
1569 :
1570 : /* output */
1571 : bool enum_and_int_p;
1572 : bool different_types_p;
1573 : bool warning_needed;
1574 :
1575 : /* context */
1576 : bool anon_field;
1577 : bool pointedto;
1578 :
1579 : /* configuration */
1580 : bool equiv;
1581 : bool ignore_promoting_args;
1582 :
1583 : const struct tagged_tu_seen_cache* cache;
1584 : };
1585 :
1586 :
1587 : /* Helper function for composite_type. This function ignores when the
1588 : function type of an old-style declaration is incompatible with a type
1589 : of a declaration with prototype because some are arguments are not
1590 : self-promoting. This is ignored only for function types but not
1591 : ignored in a nested context. */
1592 :
1593 : static bool
1594 19994769 : comptypes_check_for_composite (tree t1, tree t2)
1595 : {
1596 19994769 : struct comptypes_data data = { };
1597 19994769 : data.ignore_promoting_args = FUNCTION_TYPE == TREE_CODE (t1);
1598 19994769 : return comptypes_internal (t1, t2, &data);
1599 : }
1600 :
1601 :
1602 : /* C implementation of compatible_types_for_indirection_note_p. */
1603 :
1604 : bool
1605 762 : compatible_types_for_indirection_note_p (tree type1, tree type2)
1606 : {
1607 762 : return comptypes (type1, type2);
1608 : }
1609 :
1610 : /* Return true if TYPE1 and TYPE2 are compatible types for assignment
1611 : or various other operations. */
1612 :
1613 : bool
1614 56984083 : comptypes (tree type1, tree type2)
1615 : {
1616 56984083 : struct comptypes_data data = { };
1617 56984083 : bool ret = comptypes_internal (type1, type2, &data);
1618 :
1619 56984083 : gcc_checking_assert (!ret || comptypes_verify (type1, type2));
1620 :
1621 56984083 : return ret;
1622 : }
1623 :
1624 :
1625 : /* Like comptypes, but it returns non-zero only for identical
1626 : types. */
1627 :
1628 : bool
1629 46462 : comptypes_same_p (tree type1, tree type2)
1630 : {
1631 46462 : struct comptypes_data data = { };
1632 46462 : bool ret = comptypes_internal (type1, type2, &data);
1633 :
1634 46462 : gcc_checking_assert (!ret || comptypes_verify (type1, type2));
1635 :
1636 46462 : if (data.different_types_p)
1637 163 : return false;
1638 :
1639 : return ret;
1640 : }
1641 :
1642 :
1643 : /* Like comptypes, but if it returns true because enum and int are
1644 : compatible, it sets *ENUM_AND_INT_P to true. */
1645 :
1646 : bool
1647 5246640 : comptypes_check_enum_int (tree type1, tree type2, bool *enum_and_int_p)
1648 : {
1649 5246640 : struct comptypes_data data = { };
1650 5246640 : bool ret = comptypes_internal (type1, type2, &data);
1651 5246640 : *enum_and_int_p = data.enum_and_int_p;
1652 :
1653 5246640 : gcc_checking_assert (!ret || comptypes_verify (type1, type2));
1654 :
1655 5246640 : return ret;
1656 : }
1657 :
1658 :
1659 :
1660 : /* Like comptypes, but if it returns true for struct and union types
1661 : considered equivalent for aliasing purposes, i.e. for setting
1662 : TYPE_CANONICAL after completing a struct or union.
1663 :
1664 : This function must return false only for types which are not
1665 : compatible according to C language semantics (cf. comptypes),
1666 : otherwise the middle-end would make incorrect aliasing decisions.
1667 : It may return true for some similar types that are not compatible
1668 : according to those stricter rules.
1669 :
1670 : In particular, we ignore size expression in arrays so that the
1671 : following structs are in the same equivalence class:
1672 :
1673 : struct foo { char (*buf)[]; };
1674 : struct foo { char (*buf)[3]; };
1675 : struct foo { char (*buf)[4]; };
1676 :
1677 : We also treat unions / structs with members which are pointers to
1678 : structures or unions with the same tag as equivalent (if they are not
1679 : incompatible for other reasons). Although incomplete structure
1680 : or union types are not compatible to any other type, they may become
1681 : compatible to different types when completed. To avoid having to update
1682 : TYPE_CANONICAL at this point, we only consider the tag when forming
1683 : the equivalence classes. For example, the following types with tag
1684 : 'foo' are all considered equivalent:
1685 :
1686 : struct bar;
1687 : struct foo { struct bar *x };
1688 : struct foo { struct bar { int a; } *x };
1689 : struct foo { struct bar { char b; } *x }; */
1690 :
1691 : bool
1692 14739414 : comptypes_equiv_p (tree type1, tree type2)
1693 : {
1694 14739414 : struct comptypes_data data = { };
1695 14739414 : data.equiv = true;
1696 14739414 : bool ret = comptypes_internal (type1, type2, &data);
1697 :
1698 : /* check that different equivance classes are assigned only
1699 : to types that are not compatible. */
1700 14739414 : gcc_checking_assert (ret || !comptypes (type1, type2));
1701 :
1702 14739414 : return ret;
1703 : }
1704 :
1705 :
1706 : /* Return true if TYPE1 and TYPE2 are compatible types for assignment
1707 : or various other operations. If they are compatible but a warning may
1708 : be needed if you use them together, 'warning_needed' in DATA is set.
1709 : If one type is an enum and the other a compatible integer type, then
1710 : this sets 'enum_and_int_p' in DATA to true (it is never set to
1711 : false). If the types are compatible but different enough not to be
1712 : permitted in C11 typedef redeclarations, then this sets
1713 : 'different_types_p' in DATA to true; it is never set to
1714 : false, but may or may not be set if the types are incompatible.
1715 : If two functions types are not compatible only because one is
1716 : an old-style definition that does not have self-promoting arguments,
1717 : then this can be ignored by setting 'ignore_promoting_args_p'.
1718 : For 'equiv' we can compute equivalency classes (see above). */
1719 :
1720 : static bool
1721 136933772 : comptypes_internal (const_tree type1, const_tree type2,
1722 : struct comptypes_data *data)
1723 : {
1724 137218303 : const_tree t1 = type1;
1725 137218303 : const_tree t2 = type2;
1726 :
1727 : /* Suppress errors caused by previously reported errors. */
1728 :
1729 137218303 : if (t1 == t2 || !t1 || !t2
1730 45903929 : || TREE_CODE (t1) == ERROR_MARK || TREE_CODE (t2) == ERROR_MARK)
1731 : return true;
1732 :
1733 : /* Qualifiers must match. C99 6.7.3p9 */
1734 :
1735 45903926 : if (TYPE_QUALS (t1) != TYPE_QUALS (t2))
1736 : return false;
1737 :
1738 : /* Enumerated types are compatible with integer types, but this is
1739 : not transitive: two enumerated types in the same translation unit
1740 : are compatible with each other only if they are the same type. */
1741 :
1742 45863701 : if (TREE_CODE (t1) == ENUMERAL_TYPE
1743 1000 : && COMPLETE_TYPE_P (t1)
1744 45864657 : && TREE_CODE (t2) != ENUMERAL_TYPE)
1745 : {
1746 840 : t1 = ENUM_UNDERLYING_TYPE (t1);
1747 840 : if (TREE_CODE (t2) != VOID_TYPE)
1748 : {
1749 836 : data->enum_and_int_p = true;
1750 836 : data->different_types_p = true;
1751 : }
1752 : }
1753 45862861 : else if (TREE_CODE (t2) == ENUMERAL_TYPE
1754 4737 : && COMPLETE_TYPE_P (t2)
1755 45867592 : && TREE_CODE (t1) != ENUMERAL_TYPE)
1756 : {
1757 4615 : t2 = ENUM_UNDERLYING_TYPE (t2);
1758 4615 : if (TREE_CODE (t1) != VOID_TYPE)
1759 : {
1760 3716 : data->enum_and_int_p = true;
1761 3716 : data->different_types_p = true;
1762 : }
1763 : }
1764 :
1765 45863701 : if (t1 == t2)
1766 : return true;
1767 :
1768 : /* Different classes of types can't be compatible. */
1769 :
1770 45862329 : if (TREE_CODE (t1) != TREE_CODE (t2))
1771 : return false;
1772 :
1773 : /* Allow for two different type nodes which have essentially the same
1774 : definition. Note that we already checked for equality of the type
1775 : qualifiers (just above). */
1776 :
1777 37854053 : if (TREE_CODE (t1) != ARRAY_TYPE
1778 37854053 : && TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
1779 : return true;
1780 :
1781 37485204 : int attrval;
1782 :
1783 : /* 1 if no need for warning yet, 2 if warning cause has been seen. */
1784 37485204 : if (!(attrval = comp_type_attributes (t1, t2)))
1785 : return false;
1786 :
1787 37484827 : if (2 == attrval)
1788 336 : data->warning_needed = true;
1789 :
1790 37484827 : switch (TREE_CODE (t1))
1791 : {
1792 3375017 : case INTEGER_TYPE:
1793 3375017 : case FIXED_POINT_TYPE:
1794 3375017 : case REAL_TYPE:
1795 3375017 : case BITINT_TYPE:
1796 : /* With these nodes, we can't determine type equivalence by
1797 : looking at what is stored in the nodes themselves, because
1798 : two nodes might have different TYPE_MAIN_VARIANTs but still
1799 : represent the same type. For example, wchar_t and int could
1800 : have the same properties (TYPE_PRECISION, TYPE_MIN_VALUE,
1801 : TYPE_MAX_VALUE, etc.), but have different TYPE_MAIN_VARIANTs
1802 : and are distinct types. On the other hand, int and the
1803 : following typedef
1804 :
1805 : typedef int INT __attribute((may_alias));
1806 :
1807 : have identical properties, different TYPE_MAIN_VARIANTs, but
1808 : represent the same type. The canonical type system keeps
1809 : track of equivalence in this case, so we fall back on it. */
1810 3375017 : return TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2);
1811 :
1812 284531 : case POINTER_TYPE:
1813 : /* Do not remove mode information. */
1814 284531 : if (TYPE_MODE (t1) != TYPE_MODE (t2))
1815 : return false;
1816 284531 : data->pointedto = true;
1817 284531 : return comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2), data);
1818 :
1819 9473352 : case FUNCTION_TYPE:
1820 9473352 : return function_types_compatible_p (t1, t2, data);
1821 :
1822 155110 : case ARRAY_TYPE:
1823 155110 : {
1824 155110 : tree d1 = TYPE_DOMAIN (t1);
1825 155110 : tree d2 = TYPE_DOMAIN (t2);
1826 :
1827 : /* Target types must match incl. qualifiers. */
1828 155110 : if (!comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2), data))
1829 : return false;
1830 :
1831 120150 : if ((d1 == NULL_TREE) != (d2 == NULL_TREE))
1832 6355 : data->different_types_p = true;
1833 : /* Ignore size mismatches when forming equivalence classes. */
1834 120150 : if (data->equiv)
1835 : return true;
1836 : /* Sizes must match unless one is missing or variable. */
1837 50407 : if (d1 == NULL_TREE || d2 == NULL_TREE || d1 == d2)
1838 : return true;
1839 :
1840 34127 : bool d1_variable = top_array_vla_p (t1);
1841 34127 : bool d2_variable = top_array_vla_p (t2);
1842 :
1843 34127 : if (d1_variable != d2_variable)
1844 943 : data->different_types_p = true;
1845 34127 : if (d1_variable || d2_variable)
1846 : return true;
1847 :
1848 4027 : bool d1_zero = zero_length_array_type_p (t1)
1849 4027 : || flexible_array_member_type_p (t1);
1850 :
1851 4027 : bool d2_zero = zero_length_array_type_p (t2)
1852 4027 : || flexible_array_member_type_p (t2);
1853 :
1854 93 : if (d1_zero && d2_zero)
1855 : return true;
1856 4027 : if (d1_zero || d2_zero)
1857 : return false;
1858 :
1859 3931 : if (!tree_int_cst_equal (TYPE_MIN_VALUE (d1), TYPE_MIN_VALUE (d2))
1860 3931 : || !tree_int_cst_equal (TYPE_MAX_VALUE (d1), TYPE_MAX_VALUE (d2)))
1861 3931 : return false;
1862 :
1863 : return true;
1864 : }
1865 :
1866 23657284 : case ENUMERAL_TYPE:
1867 23657284 : case RECORD_TYPE:
1868 23657284 : case UNION_TYPE:
1869 :
1870 23657284 : if (!flag_isoc23)
1871 : return false;
1872 :
1873 23657237 : return tagged_types_tu_compatible_p (t1, t2, data);
1874 :
1875 538728 : case VECTOR_TYPE:
1876 1077456 : return known_eq (TYPE_VECTOR_SUBPARTS (t1), TYPE_VECTOR_SUBPARTS (t2))
1877 538728 : && comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2), data);
1878 :
1879 : default:
1880 : return false;
1881 : }
1882 : gcc_unreachable ();
1883 : }
1884 :
1885 : /* Return true if TTL and TTR are pointers to types that are equivalent, ignoring
1886 : their qualifiers, except for named address spaces. If the pointers point to
1887 : different named addresses, then we must determine if one address space is a
1888 : subset of the other. */
1889 :
1890 : static bool
1891 1780632 : comp_target_types (location_t location, tree ttl, tree ttr)
1892 : {
1893 1780632 : tree mvl = TREE_TYPE (ttl);
1894 1780632 : tree mvr = TREE_TYPE (ttr);
1895 1780632 : addr_space_t asl = TYPE_ADDR_SPACE (mvl);
1896 1780632 : addr_space_t asr = TYPE_ADDR_SPACE (mvr);
1897 1780632 : addr_space_t as_common;
1898 :
1899 : /* Fail if pointers point to incompatible address spaces. */
1900 1780632 : if (!addr_space_superset (asl, asr, &as_common))
1901 : return 0;
1902 :
1903 : /* Qualifiers on element types of array types that are
1904 : pointer targets are also removed. */
1905 1780632 : struct comptypes_data data = { };
1906 1780632 : if (!comptypes_internal (remove_qualifiers (mvl),
1907 1780632 : remove_qualifiers (mvr), &data))
1908 : return false;
1909 :
1910 : /* For pedantic use comptypes on arrays before removing
1911 : qualifiers on the element type. */
1912 1679164 : if (TREE_CODE (mvl) == ARRAY_TYPE
1913 1891 : && TREE_CODE (mvr) == ARRAY_TYPE
1914 1681055 : && !comptypes (mvl, mvr))
1915 190 : pedwarn_c11 (location, OPT_Wpedantic, "invalid use of pointers to arrays "
1916 : "with different qualifiers in ISO C "
1917 : "before C23");
1918 :
1919 1679164 : if (data.warning_needed)
1920 126 : pedwarn (location, OPT_Wpedantic, "types are not quite compatible");
1921 :
1922 1679164 : if (data.enum_and_int_p && warn_cxx_compat)
1923 2 : warning_at (location, OPT_Wc___compat,
1924 : "pointer target types incompatible in C++");
1925 :
1926 : return true;
1927 : }
1928 :
1929 : /* Subroutines of `comptypes'. */
1930 :
1931 : /* Return true if two 'struct', 'union', or 'enum' types T1 and T2 are
1932 : compatible. The two types are not the same (which has been
1933 : checked earlier in comptypes_internal). */
1934 :
1935 : static bool
1936 23657237 : tagged_types_tu_compatible_p (const_tree t1, const_tree t2,
1937 : struct comptypes_data *data)
1938 : {
1939 23657237 : tree s1, s2;
1940 :
1941 23657237 : if (c_type_tag (t1) != c_type_tag (t2))
1942 : return false;
1943 :
1944 : /* When forming equivalence classes for TYPE_CANONICAL in C23, we treat
1945 : structs with the same tag as equivalent, but only when they are targets
1946 : of pointers inside other structs. */
1947 19463056 : if (data->equiv && data->pointedto && NULL_TREE != c_type_tag (t1))
1948 : return true;
1949 :
1950 : /* Different types without tag are incompatible except as an anonymous
1951 : field or when forming equivalence classes for TYPE_CANONICAL. */
1952 19462994 : if (!data->anon_field && !data->equiv && NULL_TREE == c_type_tag (t1))
1953 : return false;
1954 :
1955 14293459 : if (!data->anon_field && TYPE_STUB_DECL (t1) != TYPE_STUB_DECL (t2))
1956 14292398 : data->different_types_p = true;
1957 :
1958 : /* Incomplete types are incompatible inside a TU. */
1959 14293459 : if (TYPE_SIZE (t1) == NULL || TYPE_SIZE (t2) == NULL)
1960 : return false;
1961 :
1962 14293449 : if (ENUMERAL_TYPE != TREE_CODE (t1)
1963 14293449 : && (TYPE_REVERSE_STORAGE_ORDER (t1)
1964 14293394 : != TYPE_REVERSE_STORAGE_ORDER (t2)))
1965 : return false;
1966 :
1967 14293439 : if (TYPE_USER_ALIGN (t1) != TYPE_USER_ALIGN (t2))
1968 145147 : data->different_types_p = true;
1969 :
1970 : /* For types already being looked at in some active
1971 : invocation of this function, assume compatibility.
1972 : The cache is built as a linked list on the stack
1973 : with the head of the list passed downwards. */
1974 14293439 : for (const struct tagged_tu_seen_cache *t = data->cache;
1975 14303132 : t != NULL; t = t->next)
1976 9988 : if (t->t1 == t1 && t->t2 == t2)
1977 : return true;
1978 :
1979 14293144 : const struct tagged_tu_seen_cache entry = { data->cache, t1, t2 };
1980 :
1981 14293144 : switch (TREE_CODE (t1))
1982 : {
1983 55 : case ENUMERAL_TYPE:
1984 55 : {
1985 55 : if (!comptypes (ENUM_UNDERLYING_TYPE (t1), ENUM_UNDERLYING_TYPE (t2)))
1986 : return false;
1987 :
1988 : /* Speed up the case where the type values are in the same order. */
1989 51 : tree tv1 = TYPE_VALUES (t1);
1990 51 : tree tv2 = TYPE_VALUES (t2);
1991 :
1992 51 : if (tv1 == tv2)
1993 : return true;
1994 :
1995 97 : for (;tv1 && tv2; tv1 = TREE_CHAIN (tv1), tv2 = TREE_CHAIN (tv2))
1996 : {
1997 58 : if (TREE_PURPOSE (tv1) != TREE_PURPOSE (tv2))
1998 : break;
1999 :
2000 51 : if (simple_cst_equal (DECL_INITIAL (TREE_VALUE (tv1)),
2001 51 : DECL_INITIAL (TREE_VALUE (tv2))) != 1)
2002 : break;
2003 : }
2004 :
2005 51 : if (tv1 == NULL_TREE && tv2 == NULL_TREE)
2006 : return true;
2007 :
2008 12 : if (tv1 == NULL_TREE || tv2 == NULL_TREE)
2009 : return false;
2010 :
2011 12 : if (list_length (TYPE_VALUES (t1)) != list_length (TYPE_VALUES (t2)))
2012 : return false;
2013 :
2014 20 : for (s1 = TYPE_VALUES (t1); s1; s1 = TREE_CHAIN (s1))
2015 : {
2016 16 : s2 = purpose_member (TREE_PURPOSE (s1), TYPE_VALUES (t2));
2017 :
2018 16 : if (s2 == NULL
2019 29 : || simple_cst_equal (DECL_INITIAL (TREE_VALUE (s1)),
2020 13 : DECL_INITIAL (TREE_VALUE (s2))) != 1)
2021 : return false;
2022 : }
2023 :
2024 : return true;
2025 : }
2026 :
2027 14293089 : case UNION_TYPE:
2028 14293089 : case RECORD_TYPE:
2029 :
2030 14293089 : if (list_length (TYPE_FIELDS (t1)) != list_length (TYPE_FIELDS (t2)))
2031 : return false;
2032 :
2033 12336414 : for (s1 = TYPE_FIELDS (t1), s2 = TYPE_FIELDS (t2);
2034 13859538 : s1 && s2;
2035 1523124 : s1 = DECL_CHAIN (s1), s2 = DECL_CHAIN (s2))
2036 : {
2037 13793768 : gcc_assert (TREE_CODE (s1) == FIELD_DECL);
2038 13793768 : gcc_assert (TREE_CODE (s2) == FIELD_DECL);
2039 :
2040 13793768 : tree ft1 = TREE_TYPE (s1);
2041 13793768 : tree ft2 = TREE_TYPE (s2);
2042 :
2043 13793768 : if (DECL_NAME (s1) != DECL_NAME (s2))
2044 : return false;
2045 :
2046 12138354 : if (DECL_ALIGN (s1) != DECL_ALIGN (s2))
2047 : return false;
2048 :
2049 3234994 : if (DECL_C_BIT_FIELD (s1) != DECL_C_BIT_FIELD (s2))
2050 : return false;
2051 :
2052 3234974 : if (DECL_C_BIT_FIELD (s1))
2053 : {
2054 496 : if (!tree_int_cst_equal (DECL_SIZE (s1), DECL_SIZE (s2)))
2055 : return false;
2056 :
2057 342 : ft1 = DECL_BIT_FIELD_TYPE (s1);
2058 342 : ft2 = DECL_BIT_FIELD_TYPE (s2);
2059 : }
2060 :
2061 3234820 : if (!ft1 || !ft2)
2062 : return false;
2063 :
2064 3234820 : if (TREE_CODE (ft1) == ERROR_MARK || TREE_CODE (ft2) == ERROR_MARK)
2065 : return false;
2066 :
2067 3234819 : data->anon_field = !DECL_NAME (s1);
2068 3234819 : data->pointedto = false;
2069 :
2070 3234819 : const struct tagged_tu_seen_cache *cache = data->cache;
2071 3234819 : data->cache = &entry;
2072 3234819 : bool ret = comptypes_internal (ft1, ft2, data);
2073 3234819 : data->cache = cache;
2074 3234819 : if (!ret)
2075 : return false;
2076 :
2077 1592755 : tree st1 = TYPE_SIZE (TREE_TYPE (s1));
2078 1592755 : tree st2 = TYPE_SIZE (TREE_TYPE (s2));
2079 :
2080 1592755 : if (data->equiv
2081 998471 : && st1 && TREE_CODE (st1) == INTEGER_CST
2082 997989 : && st2 && TREE_CODE (st2) == INTEGER_CST
2083 2590738 : && !tree_int_cst_equal (st1, st2))
2084 : return false;
2085 :
2086 1523158 : tree counted_by1 = lookup_attribute ("counted_by",
2087 1523158 : DECL_ATTRIBUTES (s1));
2088 1523158 : tree counted_by2 = lookup_attribute ("counted_by",
2089 1523158 : DECL_ATTRIBUTES (s2));
2090 : /* If there is no counted_by attribute for both fields. */
2091 1523158 : if (!counted_by1 && !counted_by2)
2092 1523094 : continue;
2093 :
2094 : /* If only one field has counted_by attribute. */
2095 64 : if ((counted_by1 && !counted_by2)
2096 64 : || (!counted_by1 && counted_by2))
2097 : return false;
2098 :
2099 : /* Now both s1 and s2 have counted_by attributes, check
2100 : whether they are the same. */
2101 :
2102 52 : tree counted_by_field1
2103 52 : = lookup_field (t1, TREE_VALUE (TREE_VALUE (counted_by1)));
2104 52 : tree counted_by_field2
2105 52 : = lookup_field (t2, TREE_VALUE (TREE_VALUE (counted_by2)));
2106 :
2107 52 : gcc_assert (counted_by_field1 && counted_by_field2);
2108 :
2109 94 : while (TREE_CHAIN (counted_by_field1))
2110 42 : counted_by_field1 = TREE_CHAIN (counted_by_field1);
2111 86 : while (TREE_CHAIN (counted_by_field2))
2112 34 : counted_by_field2 = TREE_CHAIN (counted_by_field2);
2113 :
2114 52 : if (DECL_NAME (TREE_VALUE (counted_by_field1))
2115 52 : != DECL_NAME (TREE_VALUE (counted_by_field2)))
2116 : return false;
2117 : }
2118 : return true;
2119 :
2120 0 : default:
2121 0 : gcc_unreachable ();
2122 : }
2123 : }
2124 :
2125 : /* Return true if two function types F1 and F2 are compatible.
2126 : If either type specifies no argument types,
2127 : the other must specify a fixed number of self-promoting arg types.
2128 : Otherwise, if one type specifies only the number of arguments,
2129 : the other must specify that number of self-promoting arg types.
2130 : Otherwise, the argument types must match. */
2131 :
2132 : static bool
2133 9473352 : function_types_compatible_p (const_tree f1, const_tree f2,
2134 : struct comptypes_data *data)
2135 : {
2136 9473352 : tree ret1 = TREE_TYPE (f1);
2137 9473352 : tree ret2 = TREE_TYPE (f2);
2138 :
2139 : /* 'volatile' qualifiers on a function's return type used to mean
2140 : the function is noreturn. */
2141 9473352 : if (TYPE_VOLATILE (ret1) != TYPE_VOLATILE (ret2))
2142 29 : pedwarn (input_location, 0, "function return types not compatible due to %<volatile%>");
2143 9473352 : if (TYPE_VOLATILE (ret1))
2144 15 : ret1 = build_qualified_type (TYPE_MAIN_VARIANT (ret1),
2145 15 : TYPE_QUALS (ret1) & ~TYPE_QUAL_VOLATILE);
2146 9473352 : if (TYPE_VOLATILE (ret2))
2147 18 : ret2 = build_qualified_type (TYPE_MAIN_VARIANT (ret2),
2148 18 : TYPE_QUALS (ret2) & ~TYPE_QUAL_VOLATILE);
2149 :
2150 9473352 : bool ignore_pargs = data->ignore_promoting_args;
2151 9473352 : data->ignore_promoting_args = false;
2152 :
2153 9473352 : if (!comptypes_internal (ret1, ret2, data))
2154 : return false;
2155 :
2156 9470757 : data->ignore_promoting_args = ignore_pargs;
2157 :
2158 9470757 : tree args1 = TYPE_ARG_TYPES (f1);
2159 9470757 : tree args2 = TYPE_ARG_TYPES (f2);
2160 :
2161 9470757 : if ((args1 == NULL_TREE) != (args2 == NULL_TREE))
2162 45289 : data->different_types_p = true;
2163 :
2164 : /* An unspecified parmlist matches any specified parmlist
2165 : whose argument types don't need default promotions. */
2166 :
2167 9470757 : if (args1 == NULL_TREE)
2168 : {
2169 23785 : if (TYPE_NO_NAMED_ARGS_STDARG_P (f1) != TYPE_NO_NAMED_ARGS_STDARG_P (f2))
2170 : return false;
2171 23782 : if (!(data->ignore_promoting_args || self_promoting_args_p (args2)))
2172 : return false;
2173 23310 : data->ignore_promoting_args = false;
2174 : /* If one of these types comes from a non-prototype fn definition,
2175 : compare that with the other type's arglist.
2176 : If they don't match, ask for a warning (but no error). */
2177 23310 : if (TYPE_ACTUAL_ARG_TYPES (f1)
2178 23310 : && !type_lists_compatible_p (args2, TYPE_ACTUAL_ARG_TYPES (f1), data))
2179 12 : data->warning_needed = true;
2180 : return true;
2181 : }
2182 9446972 : if (args2 == NULL_TREE)
2183 : {
2184 21586 : if (TYPE_NO_NAMED_ARGS_STDARG_P (f1) != TYPE_NO_NAMED_ARGS_STDARG_P (f2))
2185 : return false;
2186 21584 : if (!(data->ignore_promoting_args || self_promoting_args_p (args1)))
2187 : return false;
2188 21523 : data->ignore_promoting_args = false;
2189 21523 : if (TYPE_ACTUAL_ARG_TYPES (f2)
2190 21523 : && !type_lists_compatible_p (args1, TYPE_ACTUAL_ARG_TYPES (f2), data))
2191 1 : data->warning_needed = true;
2192 : return true;
2193 : }
2194 :
2195 : /* Both types have argument lists: compare them and propagate results. */
2196 9425386 : return type_lists_compatible_p (args1, args2, data);
2197 : }
2198 :
2199 : /* Check two lists of types for compatibility, returning false for
2200 : incompatible, true for compatible. */
2201 :
2202 : static bool
2203 9425462 : type_lists_compatible_p (const_tree args1, const_tree args2,
2204 : struct comptypes_data *data)
2205 : {
2206 59005130 : while (1)
2207 : {
2208 34215296 : if (args1 == NULL_TREE && args2 == NULL_TREE)
2209 : return true;
2210 : /* If one list is shorter than the other,
2211 : they fail to match. */
2212 24935450 : if (args1 == NULL_TREE || args2 == NULL_TREE)
2213 : return false;
2214 24935443 : tree a1 = TREE_VALUE (args1);
2215 24935443 : tree a2 = TREE_VALUE (args2);
2216 24935443 : tree mv1 = remove_qualifiers (a1);
2217 24935443 : tree mv2 = remove_qualifiers (a2);
2218 :
2219 24935443 : gcc_assert (mv2);
2220 24935443 : gcc_assert (mv2);
2221 :
2222 : /* If one of the lists has an error marker, ignore this arg. */
2223 24935443 : if (TREE_CODE (a1) == ERROR_MARK
2224 24935439 : || TREE_CODE (a2) == ERROR_MARK)
2225 : ;
2226 24935423 : else if (!comptypes_internal (mv1, mv2, data))
2227 : {
2228 145840 : data->different_types_p = true;
2229 : /* Allow wait (union {union wait *u; int *i} *)
2230 : and wait (union wait *) to be compatible. */
2231 145840 : if (TREE_CODE (a1) == UNION_TYPE
2232 130 : && (TYPE_NAME (a1) == NULL_TREE
2233 98 : || TYPE_TRANSPARENT_AGGR (a1))
2234 130 : && TREE_CODE (TYPE_SIZE (a1)) == INTEGER_CST
2235 145970 : && tree_int_cst_equal (TYPE_SIZE (a1),
2236 130 : TYPE_SIZE (a2)))
2237 : {
2238 130 : tree memb;
2239 130 : for (memb = TYPE_FIELDS (a1);
2240 166 : memb; memb = DECL_CHAIN (memb))
2241 : {
2242 164 : tree mv3 = remove_qualifiers (TREE_TYPE (memb));
2243 164 : if (comptypes_internal (mv3, mv2, data))
2244 : break;
2245 : }
2246 : if (memb == NULL_TREE)
2247 : return false;
2248 : }
2249 145710 : else if (TREE_CODE (a2) == UNION_TYPE
2250 105 : && (TYPE_NAME (a2) == NULL_TREE
2251 74 : || TYPE_TRANSPARENT_AGGR (a2))
2252 105 : && TREE_CODE (TYPE_SIZE (a2)) == INTEGER_CST
2253 145815 : && tree_int_cst_equal (TYPE_SIZE (a2),
2254 105 : TYPE_SIZE (a1)))
2255 : {
2256 105 : tree memb;
2257 105 : for (memb = TYPE_FIELDS (a2);
2258 133 : memb; memb = DECL_CHAIN (memb))
2259 : {
2260 131 : tree mv3 = remove_qualifiers (TREE_TYPE (memb));
2261 131 : if (comptypes_internal (mv3, mv1, data))
2262 : break;
2263 : }
2264 : if (memb == NULL_TREE)
2265 : return false;
2266 : }
2267 : else
2268 : return false;
2269 : }
2270 :
2271 24789834 : args1 = TREE_CHAIN (args1);
2272 24789834 : args2 = TREE_CHAIN (args2);
2273 24789834 : }
2274 : }
2275 :
2276 : /* Compute the size to increment a pointer by. When a function type or void
2277 : type or incomplete type is passed, size_one_node is returned.
2278 : This function does not emit any diagnostics; the caller is responsible
2279 : for that. */
2280 :
2281 : static tree
2282 236830 : c_size_in_bytes (const_tree type)
2283 : {
2284 236830 : enum tree_code code = TREE_CODE (type);
2285 :
2286 236830 : if (code == FUNCTION_TYPE || code == VOID_TYPE || code == ERROR_MARK
2287 236830 : || !COMPLETE_TYPE_P (type))
2288 195 : return size_one_node;
2289 :
2290 : /* Convert in case a char is more than one unit. */
2291 236635 : return size_binop_loc (input_location, CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
2292 236635 : size_int (TYPE_PRECISION (char_type_node)
2293 : / BITS_PER_UNIT));
2294 : }
2295 :
2296 : /* Return either DECL or its known constant value (if it has one). */
2297 :
2298 : tree
2299 14428559 : decl_constant_value_1 (tree decl, bool in_init)
2300 : {
2301 14428559 : if (/* Note that DECL_INITIAL isn't valid for a PARM_DECL. */
2302 14428559 : TREE_CODE (decl) != PARM_DECL
2303 14428559 : && !TREE_THIS_VOLATILE (decl)
2304 14082922 : && TREE_READONLY (decl)
2305 37360 : && DECL_INITIAL (decl) != NULL_TREE
2306 36346 : && !error_operand_p (DECL_INITIAL (decl))
2307 : /* This is invalid if initial value is not constant.
2308 : If it has either a function call, a memory reference,
2309 : or a variable, then re-evaluating it could give different results. */
2310 36337 : && TREE_CONSTANT (DECL_INITIAL (decl))
2311 : /* Check for cases where this is sub-optimal, even though valid. */
2312 14451715 : && (in_init || TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR))
2313 17723 : return DECL_INITIAL (decl);
2314 : return decl;
2315 : }
2316 :
2317 : /* Return either DECL or its known constant value (if it has one).
2318 : Like the above, but always return decl outside of functions. */
2319 :
2320 : tree
2321 14428295 : decl_constant_value (tree decl)
2322 : {
2323 : /* Don't change a variable array bound or initial value to a constant
2324 : in a place where a variable is invalid. */
2325 14428295 : return current_function_decl ? decl_constant_value_1 (decl, false) : decl;
2326 : }
2327 :
2328 : /* Convert the array expression EXP to a pointer. */
2329 : static tree
2330 830827 : array_to_pointer_conversion (location_t loc, tree exp)
2331 : {
2332 830827 : tree orig_exp = exp;
2333 830827 : tree type = TREE_TYPE (exp);
2334 830827 : tree adr;
2335 830827 : tree restype = TREE_TYPE (type);
2336 830827 : tree ptrtype;
2337 :
2338 830827 : gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
2339 :
2340 830827 : STRIP_TYPE_NOPS (exp);
2341 :
2342 830827 : copy_warning (exp, orig_exp);
2343 :
2344 830827 : ptrtype = c_build_pointer_type (restype);
2345 :
2346 830827 : if (INDIRECT_REF_P (exp))
2347 2906 : return convert (ptrtype, TREE_OPERAND (exp, 0));
2348 :
2349 : /* In C++ array compound literals are temporary objects unless they are
2350 : const or appear in namespace scope, so they are destroyed too soon
2351 : to use them for much of anything (c++/53220). */
2352 827921 : if (warn_cxx_compat && TREE_CODE (exp) == COMPOUND_LITERAL_EXPR)
2353 : {
2354 48 : tree decl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
2355 48 : if (!TREE_READONLY (decl) && !TREE_STATIC (decl))
2356 46 : warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat,
2357 : "converting an array compound literal to a pointer "
2358 : "leads to a dangling pointer in C++");
2359 : }
2360 :
2361 827921 : adr = build_unary_op (loc, ADDR_EXPR, exp, true);
2362 827921 : return convert (ptrtype, adr);
2363 : }
2364 :
2365 : /* Convert the function expression EXP to a pointer. */
2366 : static tree
2367 52317407 : function_to_pointer_conversion (location_t loc, tree exp)
2368 : {
2369 52317407 : tree orig_exp = exp;
2370 :
2371 52317407 : gcc_assert (TREE_CODE (TREE_TYPE (exp)) == FUNCTION_TYPE);
2372 :
2373 52317407 : STRIP_TYPE_NOPS (exp);
2374 :
2375 52317407 : copy_warning (exp, orig_exp);
2376 :
2377 52317407 : tree exp2 = build_unary_op (loc, ADDR_EXPR, exp, false);
2378 :
2379 : /* If the function is defined and known to not require a non-local
2380 : context, make sure no trampoline is generated. */
2381 52317407 : if (TREE_CODE (exp) == FUNCTION_DECL
2382 52317407 : && DECL_INITIAL (exp) && !C_FUNC_NONLOCAL_CONTEXT (exp))
2383 16641239 : TREE_NO_TRAMPOLINE (exp2) = 1;
2384 :
2385 52317407 : return exp2;
2386 : }
2387 :
2388 : /* Mark EXP as read, not just set, for set but not used -Wunused
2389 : warning purposes. */
2390 :
2391 : void
2392 502433102 : mark_exp_read (tree exp)
2393 : {
2394 632726019 : switch (TREE_CODE (exp))
2395 : {
2396 208534925 : case VAR_DECL:
2397 208534925 : case PARM_DECL:
2398 208534925 : DECL_READ_P (exp) = 1;
2399 208534925 : break;
2400 20378560 : CASE_CONVERT:
2401 20378560 : if (VOID_TYPE_P (TREE_TYPE (exp)))
2402 3807 : switch (TREE_CODE (TREE_OPERAND (exp, 0)))
2403 : {
2404 : case PREINCREMENT_EXPR:
2405 : case PREDECREMENT_EXPR:
2406 : case POSTINCREMENT_EXPR:
2407 : case POSTDECREMENT_EXPR:
2408 : return;
2409 : default:
2410 : break;
2411 : }
2412 : /* FALLTHRU */
2413 127535874 : case ARRAY_REF:
2414 127535874 : case COMPONENT_REF:
2415 127535874 : case MODIFY_EXPR:
2416 127535874 : case REALPART_EXPR:
2417 127535874 : case IMAGPART_EXPR:
2418 127535874 : case ADDR_EXPR:
2419 127535874 : case VIEW_CONVERT_EXPR:
2420 127535874 : case PREINCREMENT_EXPR:
2421 127535874 : case PREDECREMENT_EXPR:
2422 127535874 : case POSTINCREMENT_EXPR:
2423 127535874 : case POSTDECREMENT_EXPR:
2424 127535874 : mark_exp_read (TREE_OPERAND (exp, 0));
2425 127535874 : break;
2426 236141 : case COMPOUND_EXPR:
2427 : /* Pattern match what build_atomic_assign produces with modifycode
2428 : NOP_EXPR. */
2429 236141 : if (VAR_P (TREE_OPERAND (exp, 1))
2430 27227 : && DECL_ARTIFICIAL (TREE_OPERAND (exp, 1))
2431 263284 : && TREE_CODE (TREE_OPERAND (exp, 0)) == COMPOUND_EXPR)
2432 : {
2433 2210 : tree t1 = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
2434 2210 : tree t2 = TREE_OPERAND (TREE_OPERAND (exp, 0), 1);
2435 2210 : if (TREE_CODE (t1) == TARGET_EXPR
2436 2202 : && TARGET_EXPR_SLOT (t1) == TREE_OPERAND (exp, 1)
2437 4410 : && TREE_CODE (t2) == CALL_EXPR)
2438 : {
2439 2200 : tree fndecl = get_callee_fndecl (t2);
2440 2200 : tree arg = NULL_TREE;
2441 2200 : if (fndecl
2442 2200 : && TREE_CODE (fndecl) == FUNCTION_DECL
2443 2200 : && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL)
2444 4400 : && call_expr_nargs (t2) >= 2)
2445 2200 : switch (DECL_FUNCTION_CODE (fndecl))
2446 : {
2447 130 : case BUILT_IN_ATOMIC_STORE:
2448 130 : arg = CALL_EXPR_ARG (t2, 1);
2449 130 : break;
2450 2070 : case BUILT_IN_ATOMIC_STORE_1:
2451 2070 : case BUILT_IN_ATOMIC_STORE_2:
2452 2070 : case BUILT_IN_ATOMIC_STORE_4:
2453 2070 : case BUILT_IN_ATOMIC_STORE_8:
2454 2070 : case BUILT_IN_ATOMIC_STORE_16:
2455 2070 : arg = CALL_EXPR_ARG (t2, 0);
2456 2070 : break;
2457 : default:
2458 : break;
2459 : }
2460 2200 : if (arg)
2461 : {
2462 2200 : STRIP_NOPS (arg);
2463 2200 : if (TREE_CODE (arg) == ADDR_EXPR
2464 2200 : && DECL_P (TREE_OPERAND (arg, 0))
2465 4400 : && TYPE_ATOMIC (TREE_TYPE (TREE_OPERAND (arg, 0))))
2466 2200 : mark_exp_read (TREE_OPERAND (arg, 0));
2467 : }
2468 : }
2469 : }
2470 : /* FALLTHRU */
2471 2756492 : case C_MAYBE_CONST_EXPR:
2472 2756492 : mark_exp_read (TREE_OPERAND (exp, 1));
2473 2756492 : break;
2474 586 : case OMP_ARRAY_SECTION:
2475 586 : mark_exp_read (TREE_OPERAND (exp, 0));
2476 586 : if (TREE_OPERAND (exp, 1))
2477 388 : mark_exp_read (TREE_OPERAND (exp, 1));
2478 586 : if (TREE_OPERAND (exp, 2))
2479 551 : mark_exp_read (TREE_OPERAND (exp, 2));
2480 : break;
2481 : default:
2482 : break;
2483 : }
2484 : }
2485 :
2486 : /* Perform the default conversion of arrays and functions to pointers.
2487 : Return the result of converting EXP. For any other expression, just
2488 : return EXP.
2489 :
2490 : LOC is the location of the expression. */
2491 :
2492 : struct c_expr
2493 371794195 : default_function_array_conversion (location_t loc, struct c_expr exp)
2494 : {
2495 371794195 : tree orig_exp = exp.value;
2496 371794195 : tree type = TREE_TYPE (exp.value);
2497 371794195 : enum tree_code code = TREE_CODE (type);
2498 :
2499 371794195 : switch (code)
2500 : {
2501 : case ARRAY_TYPE:
2502 : {
2503 : bool not_lvalue = false;
2504 : bool lvalue_array_p;
2505 :
2506 783898 : while ((TREE_CODE (exp.value) == NON_LVALUE_EXPR
2507 783898 : || CONVERT_EXPR_P (exp.value))
2508 783898 : && TREE_TYPE (TREE_OPERAND (exp.value, 0)) == type)
2509 : {
2510 0 : if (TREE_CODE (exp.value) == NON_LVALUE_EXPR)
2511 0 : not_lvalue = true;
2512 0 : exp.value = TREE_OPERAND (exp.value, 0);
2513 : }
2514 :
2515 783898 : copy_warning (exp.value, orig_exp);
2516 :
2517 783898 : lvalue_array_p = !not_lvalue && lvalue_p (exp.value);
2518 783898 : if (!flag_isoc99 && !lvalue_array_p)
2519 : {
2520 : /* Before C99, non-lvalue arrays do not decay to pointers.
2521 : Normally, using such an array would be invalid; but it can
2522 : be used correctly inside sizeof or as a statement expression.
2523 : Thus, do not give an error here; an error will result later. */
2524 109 : return exp;
2525 : }
2526 :
2527 783789 : exp.value = array_to_pointer_conversion (loc, exp.value);
2528 : }
2529 783789 : break;
2530 762538 : case FUNCTION_TYPE:
2531 762538 : exp.value = function_to_pointer_conversion (loc, exp.value);
2532 762538 : break;
2533 : default:
2534 : break;
2535 : }
2536 :
2537 371794086 : return exp;
2538 : }
2539 :
2540 : struct c_expr
2541 12679 : default_function_array_read_conversion (location_t loc, struct c_expr exp)
2542 : {
2543 12679 : mark_exp_read (exp.value);
2544 : /* We only generate a call to .ACCESS_WITH_SIZE when it is a read. */
2545 12679 : if (TREE_CODE (exp.value) == COMPONENT_REF
2546 12679 : && handle_counted_by_p (exp.value))
2547 4 : exp.value = handle_counted_by_for_component_ref (loc, exp.value);
2548 12679 : return default_function_array_conversion (loc, exp);
2549 : }
2550 :
2551 : /* Return whether EXPR should be treated as an atomic lvalue for the
2552 : purposes of load and store handling. */
2553 :
2554 : static bool
2555 372911123 : really_atomic_lvalue (tree expr)
2556 : {
2557 372911123 : if (error_operand_p (expr))
2558 : return false;
2559 372903553 : if (!TYPE_ATOMIC (TREE_TYPE (expr)))
2560 : return false;
2561 57407 : if (!COMPLETE_TYPE_P (TREE_TYPE (expr)))
2562 : return false;
2563 57404 : if (!lvalue_p (expr))
2564 : return false;
2565 :
2566 : /* Ignore _Atomic on register variables, since their addresses can't
2567 : be taken so (a) atomicity is irrelevant and (b) the normal atomic
2568 : sequences wouldn't work. Ignore _Atomic on structures containing
2569 : bit-fields, since accessing elements of atomic structures or
2570 : unions is undefined behavior (C11 6.5.2.3#5), but it's unclear if
2571 : it's undefined at translation time or execution time, and the
2572 : normal atomic sequences again wouldn't work. */
2573 57530 : while (handled_component_p (expr))
2574 : {
2575 128 : if (TREE_CODE (expr) == COMPONENT_REF
2576 128 : && DECL_C_BIT_FIELD (TREE_OPERAND (expr, 1)))
2577 : return false;
2578 128 : expr = TREE_OPERAND (expr, 0);
2579 : }
2580 57402 : if (TREE_CODE (expr) == COMPOUND_LITERAL_EXPR)
2581 1 : expr = COMPOUND_LITERAL_EXPR_DECL (expr);
2582 112616 : if (DECL_P (expr) && C_DECL_REGISTER (expr))
2583 7 : return false;
2584 : return true;
2585 : }
2586 :
2587 : /* If EXPR is a named constant (C23) derived from a constexpr variable
2588 : - that is, a reference to such a variable, or a member extracted by
2589 : a sequence of structure and union (but not array) member accesses
2590 : (where union member accesses must access the same member as
2591 : initialized) - then return the corresponding initializer;
2592 : otherwise, return NULL_TREE. */
2593 :
2594 : static tree
2595 369688954 : maybe_get_constexpr_init (tree expr)
2596 : {
2597 369688954 : tree decl = NULL_TREE;
2598 369688954 : if (TREE_CODE (expr) == VAR_DECL)
2599 : decl = expr;
2600 357899239 : else if (TREE_CODE (expr) == COMPOUND_LITERAL_EXPR)
2601 826382 : decl = COMPOUND_LITERAL_EXPR_DECL (expr);
2602 826382 : if (decl
2603 12616097 : && C_DECL_DECLARED_CONSTEXPR (decl)
2604 498 : && DECL_INITIAL (decl) != NULL_TREE
2605 826880 : && !error_operand_p (DECL_INITIAL (decl)))
2606 498 : return DECL_INITIAL (decl);
2607 369688456 : if (TREE_CODE (expr) != COMPONENT_REF)
2608 : return NULL_TREE;
2609 879747 : tree inner = maybe_get_constexpr_init (TREE_OPERAND (expr, 0));
2610 879747 : if (inner == NULL_TREE)
2611 : return NULL_TREE;
2612 126 : while ((CONVERT_EXPR_P (inner) || TREE_CODE (inner) == NON_LVALUE_EXPR)
2613 47 : && !error_operand_p (inner)
2614 220 : && (TYPE_MAIN_VARIANT (TREE_TYPE (inner))
2615 47 : == TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (inner, 0)))))
2616 47 : inner = TREE_OPERAND (inner, 0);
2617 126 : if (TREE_CODE (inner) != CONSTRUCTOR)
2618 : return NULL_TREE;
2619 126 : tree field = TREE_OPERAND (expr, 1);
2620 126 : unsigned HOST_WIDE_INT cidx;
2621 126 : tree cfield, cvalue;
2622 126 : bool have_other_init = false;
2623 266 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (inner), cidx, cfield, cvalue)
2624 : {
2625 250 : if (cfield == field)
2626 : return cvalue;
2627 140 : have_other_init = true;
2628 : }
2629 16 : if (TREE_CODE (TREE_TYPE (inner)) == UNION_TYPE
2630 16 : && (have_other_init || field != TYPE_FIELDS (TREE_TYPE (inner))))
2631 : return NULL_TREE;
2632 : /* Return a default initializer. */
2633 13 : if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (expr)))
2634 5 : return build_constructor (TREE_TYPE (expr), NULL);
2635 8 : return build_zero_cst (TREE_TYPE (expr));
2636 : }
2637 :
2638 : /* Helper function for convert_lvalue_to_rvalue called via
2639 : walk_tree_without_duplicates. Find DATA inside of the expression. */
2640 :
2641 : static tree
2642 230125 : c_find_var_r (tree *tp, int *walk_subtrees, void *data)
2643 : {
2644 230125 : if (TYPE_P (*tp))
2645 0 : *walk_subtrees = 0;
2646 230125 : else if (*tp == (tree) data)
2647 0 : return *tp;
2648 : return NULL_TREE;
2649 : }
2650 :
2651 : /* Convert expression EXP (location LOC) from lvalue to rvalue,
2652 : including converting functions and arrays to pointers if CONVERT_P.
2653 : If READ_P, also mark the expression as having been read. If
2654 : FOR_INIT, constexpr expressions of structure and union type should
2655 : be replaced by the corresponding CONSTRUCTOR; otherwise, only
2656 : constexpr scalars (including elements of structures and unions) are
2657 : replaced by their initializers. */
2658 :
2659 : struct c_expr
2660 368997104 : convert_lvalue_to_rvalue (location_t loc, struct c_expr exp,
2661 : bool convert_p, bool read_p, bool for_init)
2662 : {
2663 368997104 : bool force_non_npc = false;
2664 368997104 : if (read_p)
2665 323728774 : mark_exp_read (exp.value);
2666 : /* We only generate a call to .ACCESS_WITH_SIZE when it is a read. */
2667 323728774 : if (read_p && TREE_CODE (exp.value) == COMPONENT_REF
2668 786322 : && handle_counted_by_p (exp.value))
2669 786293 : exp.value = handle_counted_by_for_component_ref (loc, exp.value);
2670 :
2671 368997104 : if (convert_p)
2672 368983788 : exp = default_function_array_conversion (loc, exp);
2673 368997104 : if (!VOID_TYPE_P (TREE_TYPE (exp.value))
2674 368997104 : || (flag_isoc2y
2675 1574 : && TYPE_QUALS (TREE_TYPE (exp.value)) != TYPE_UNQUALIFIED))
2676 366402778 : exp.value = require_complete_type (loc, exp.value);
2677 368997104 : if (for_init || !RECORD_OR_UNION_TYPE_P (TREE_TYPE (exp.value)))
2678 : {
2679 368809207 : tree init = maybe_get_constexpr_init (exp.value);
2680 368809207 : if (init != NULL_TREE)
2681 : {
2682 : /* A named constant of pointer type or type nullptr_t is not
2683 : a null pointer constant even if the initializer is
2684 : one. */
2685 495 : if (TREE_CODE (init) == INTEGER_CST
2686 360 : && !INTEGRAL_TYPE_P (TREE_TYPE (init))
2687 521 : && integer_zerop (init))
2688 : force_non_npc = true;
2689 : exp.value = init;
2690 : }
2691 : }
2692 368997104 : if (really_atomic_lvalue (exp.value))
2693 : {
2694 26928 : vec<tree, va_gc> *params;
2695 26928 : tree nonatomic_type, tmp, tmp_addr, fndecl, func_call;
2696 26928 : tree expr_type = TREE_TYPE (exp.value);
2697 26928 : tree expr_addr = build_unary_op (loc, ADDR_EXPR, exp.value, false);
2698 26928 : tree seq_cst = build_int_cst (integer_type_node, MEMMODEL_SEQ_CST);
2699 :
2700 26928 : gcc_assert (TYPE_ATOMIC (expr_type));
2701 :
2702 : /* Expansion of a generic atomic load may require an addition
2703 : element, so allocate enough to prevent a resize. */
2704 26928 : vec_alloc (params, 4);
2705 :
2706 : /* Remove the qualifiers for the rest of the expressions and
2707 : create the VAL temp variable to hold the RHS. */
2708 26928 : nonatomic_type = build_qualified_type (expr_type, TYPE_UNQUALIFIED);
2709 26928 : tmp = create_tmp_var_raw (nonatomic_type);
2710 26928 : tmp_addr = build_unary_op (loc, ADDR_EXPR, tmp, false);
2711 26928 : TREE_ADDRESSABLE (tmp) = 1;
2712 : /* Do not disable warnings for TMP even though it's artificial.
2713 : -Winvalid-memory-model depends on it. */
2714 :
2715 : /* Issue __atomic_load (&expr, &tmp, SEQ_CST); */
2716 26928 : fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_LOAD);
2717 26928 : params->quick_push (expr_addr);
2718 26928 : params->quick_push (tmp_addr);
2719 26928 : params->quick_push (seq_cst);
2720 26928 : func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
2721 :
2722 : /* EXPR is always read. */
2723 26928 : mark_exp_read (exp.value);
2724 :
2725 : /* Optimize the common case where c_build_function_call_vec
2726 : immediately folds __atomic_load (&expr, &tmp, SEQ_CST); into
2727 : tmp = __atomic_load_<N> (&expr, SEQ_CST);
2728 : In that case tmp is not addressable and can be initialized
2729 : fully by the rhs of the MODIFY_EXPR. */
2730 26928 : tree tem = func_call;
2731 26928 : if (CONVERT_EXPR_P (tem) && VOID_TYPE_P (TREE_TYPE (tem)))
2732 : {
2733 25673 : tem = TREE_OPERAND (tem, 0);
2734 25673 : if (TREE_CODE (tem) == MODIFY_EXPR
2735 25673 : && TREE_OPERAND (tem, 0) == tmp
2736 51346 : && !walk_tree_without_duplicates (&TREE_OPERAND (tem, 1),
2737 : c_find_var_r, tmp))
2738 : {
2739 25673 : TREE_ADDRESSABLE (tmp) = 0;
2740 25673 : func_call = TREE_OPERAND (tem, 1);
2741 : }
2742 : }
2743 :
2744 : /* Return tmp which contains the value loaded. */
2745 26928 : exp.value = build4 (TARGET_EXPR, nonatomic_type, tmp, func_call,
2746 : NULL_TREE, NULL_TREE);
2747 : }
2748 368983788 : if (convert_p && !error_operand_p (exp.value)
2749 737973367 : && (TREE_CODE (TREE_TYPE (exp.value)) != ARRAY_TYPE))
2750 368976154 : exp.value = convert (build_qualified_type (TREE_TYPE (exp.value), TYPE_UNQUALIFIED), exp.value);
2751 368997104 : if (force_non_npc)
2752 24 : exp.value = build1 (NOP_EXPR, TREE_TYPE (exp.value), exp.value);
2753 :
2754 368997104 : {
2755 368997104 : tree false_value, true_value;
2756 368983788 : if (convert_p && !error_operand_p (exp.value)
2757 737973367 : && c_hardbool_type_attr (TREE_TYPE (exp.value),
2758 : &false_value, &true_value))
2759 : {
2760 9721 : tree t = save_expr (exp.value);
2761 :
2762 9721 : mark_exp_read (exp.value);
2763 :
2764 9721 : tree trapfn = builtin_decl_explicit (BUILT_IN_TRAP);
2765 9721 : tree expr = build_call_expr_loc (loc, trapfn, 0);
2766 9721 : expr = build_compound_expr (loc, expr, boolean_true_node);
2767 9721 : expr = fold_build3_loc (loc, COND_EXPR, boolean_type_node,
2768 : fold_build2_loc (loc, NE_EXPR,
2769 : boolean_type_node,
2770 : t, true_value),
2771 : expr, boolean_true_node);
2772 9721 : expr = fold_build3_loc (loc, COND_EXPR, boolean_type_node,
2773 : fold_build2_loc (loc, NE_EXPR,
2774 : boolean_type_node,
2775 : t, false_value),
2776 : expr, boolean_false_node);
2777 :
2778 9721 : exp.value = expr;
2779 : }
2780 : }
2781 :
2782 368997104 : return exp;
2783 : }
2784 :
2785 : /* Wrapper for the overload above, same arguments but for tree rather than
2786 : c_expr. This is important for hardbools to decay to bools. */
2787 :
2788 : static inline tree
2789 579262 : convert_lvalue_to_rvalue (location_t loc, tree val,
2790 : bool convert_p, bool read_p, bool for_init = false)
2791 : {
2792 579262 : struct c_expr expr;
2793 579262 : memset (&expr, 0, sizeof (expr));
2794 579262 : expr.value = val;
2795 579262 : expr = convert_lvalue_to_rvalue (loc, expr, convert_p, read_p, for_init);
2796 579262 : return expr.value;
2797 : }
2798 :
2799 : /* EXP is an expression of integer type. Apply the integer promotions
2800 : to it and return the promoted value. */
2801 :
2802 : tree
2803 78274799 : perform_integral_promotions (tree exp)
2804 : {
2805 78274799 : tree type = TREE_TYPE (exp);
2806 78274799 : enum tree_code code = TREE_CODE (type);
2807 :
2808 78274799 : gcc_assert (INTEGRAL_TYPE_P (type));
2809 :
2810 : /* Convert enums to the result of applying the integer promotions to
2811 : their underlying type. */
2812 78274799 : if (code == ENUMERAL_TYPE)
2813 : {
2814 653640 : type = ENUM_UNDERLYING_TYPE (type);
2815 653640 : if (c_promoting_integer_type_p (type))
2816 : {
2817 94 : if (TYPE_UNSIGNED (type)
2818 94 : && TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
2819 0 : type = unsigned_type_node;
2820 : else
2821 94 : type = integer_type_node;
2822 : }
2823 :
2824 653640 : return convert (type, exp);
2825 : }
2826 :
2827 : /* ??? This should no longer be needed now bit-fields have their
2828 : proper types. */
2829 77621159 : if (TREE_CODE (exp) == COMPONENT_REF
2830 77621159 : && DECL_C_BIT_FIELD (TREE_OPERAND (exp, 1)))
2831 : {
2832 62352 : if (BITINT_TYPE_P (DECL_BIT_FIELD_TYPE (TREE_OPERAND (exp, 1))))
2833 : {
2834 500 : tree btype = DECL_BIT_FIELD_TYPE (TREE_OPERAND (exp, 1));
2835 500 : if (TREE_CODE (btype) == BITINT_TYPE)
2836 462 : return convert (btype, exp);
2837 : else
2838 38 : return convert (ENUM_UNDERLYING_TYPE (btype), exp);
2839 : }
2840 : /* If it's thinner than an int, promote it like a
2841 : c_promoting_integer_type_p, otherwise leave it alone. */
2842 61852 : if (compare_tree_int (DECL_SIZE (TREE_OPERAND (exp, 1)),
2843 61852 : TYPE_PRECISION (integer_type_node)) < 0)
2844 53590 : return convert (integer_type_node, exp);
2845 : }
2846 :
2847 77567069 : if (c_promoting_integer_type_p (type))
2848 : {
2849 : /* Preserve unsignedness if not really getting any wider. */
2850 653098 : if (TYPE_UNSIGNED (type)
2851 653098 : && TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
2852 0 : return convert (unsigned_type_node, exp);
2853 :
2854 653098 : return convert (integer_type_node, exp);
2855 : }
2856 :
2857 : return exp;
2858 : }
2859 :
2860 :
2861 : /* Perform default promotions for C data used in expressions.
2862 : Enumeral types or short or char are converted to int.
2863 : In addition, manifest constants symbols are replaced by their values. */
2864 :
2865 : tree
2866 87859875 : default_conversion (tree exp)
2867 : {
2868 87859875 : tree orig_exp;
2869 87859875 : tree type = TREE_TYPE (exp);
2870 87859875 : enum tree_code code = TREE_CODE (type);
2871 87859875 : tree promoted_type;
2872 :
2873 87859875 : mark_exp_read (exp);
2874 : /* We only generate a call to .ACCESS_WITH_SIZE when it is a read. */
2875 87859875 : if (TREE_CODE (exp) == COMPONENT_REF
2876 87859875 : && handle_counted_by_p (exp))
2877 603053 : exp = handle_counted_by_for_component_ref (EXPR_LOCATION (exp), exp);
2878 :
2879 : /* Functions and arrays have been converted during parsing. */
2880 87859875 : gcc_assert (code != FUNCTION_TYPE);
2881 87859875 : if (code == ARRAY_TYPE)
2882 : return exp;
2883 :
2884 : /* Constants can be used directly unless they're not loadable. */
2885 87859715 : if (TREE_CODE (exp) == CONST_DECL)
2886 0 : exp = DECL_INITIAL (exp);
2887 :
2888 : /* Strip no-op conversions. */
2889 87859715 : orig_exp = exp;
2890 88232798 : STRIP_TYPE_NOPS (exp);
2891 :
2892 87859715 : copy_warning (exp, orig_exp);
2893 :
2894 87859715 : if (code == VOID_TYPE)
2895 : {
2896 2 : error_at (EXPR_LOC_OR_LOC (exp, input_location),
2897 : "void value not ignored as it ought to be");
2898 2 : return error_mark_node;
2899 : }
2900 :
2901 87859713 : exp = require_complete_type (EXPR_LOC_OR_LOC (exp, input_location), exp);
2902 87859713 : if (exp == error_mark_node)
2903 : return error_mark_node;
2904 :
2905 87858809 : promoted_type = targetm.promoted_type (type);
2906 87858809 : if (promoted_type)
2907 0 : return convert (promoted_type, exp);
2908 :
2909 87858809 : if (INTEGRAL_TYPE_P (type))
2910 : {
2911 : /* Avoid performing integral promotion of bit-precise integer
2912 : type bit-field to its corresponding bit-precise integer if
2913 : orig_exp is a cast to it to its underlying type. */
2914 77275521 : if (orig_exp != exp
2915 12928 : && TREE_CODE (exp) == COMPONENT_REF
2916 42 : && DECL_C_BIT_FIELD (TREE_OPERAND (exp, 1))
2917 77275552 : && BITINT_TYPE_P (DECL_BIT_FIELD_TYPE (TREE_OPERAND (exp, 1))))
2918 31 : return perform_integral_promotions (orig_exp);
2919 77275490 : return perform_integral_promotions (exp);
2920 : }
2921 :
2922 : return exp;
2923 : }
2924 :
2925 : /* Look up COMPONENT in a structure or union TYPE.
2926 :
2927 : If the component name is not found, returns NULL_TREE. Otherwise,
2928 : the return value is a TREE_LIST, with each TREE_VALUE a FIELD_DECL
2929 : stepping down the chain to the component, which is in the last
2930 : TREE_VALUE of the list. Normally the list is of length one, but if
2931 : the component is embedded within (nested) anonymous structures or
2932 : unions, the list steps down the chain to the component. */
2933 :
2934 : tree
2935 2329176 : lookup_field (const_tree type, tree component)
2936 : {
2937 2329176 : tree field;
2938 :
2939 : /* If TYPE_LANG_SPECIFIC is set, then it is a sorted array of pointers
2940 : to the field elements. Use a binary search on this array to quickly
2941 : find the element. Otherwise, do a linear search. TYPE_LANG_SPECIFIC
2942 : will always be set for structures which have many elements.
2943 :
2944 : Duplicate field checking replaces duplicates with NULL_TREE so
2945 : TYPE_LANG_SPECIFIC arrays are potentially no longer sorted. In that
2946 : case just iterate using DECL_CHAIN. */
2947 :
2948 2631624 : if (TYPE_LANG_SPECIFIC (type) && TYPE_LANG_SPECIFIC (type)->s
2949 2631624 : && !seen_error ())
2950 : {
2951 302427 : int bot, top, half;
2952 302427 : tree *field_array = &TYPE_LANG_SPECIFIC (type)->s->elts[0];
2953 :
2954 302427 : field = TYPE_FIELDS (type);
2955 302427 : bot = 0;
2956 302427 : top = TYPE_LANG_SPECIFIC (type)->s->len;
2957 1389090 : while (top - bot > 1)
2958 : {
2959 1359817 : half = (top - bot + 1) >> 1;
2960 1359817 : field = field_array[bot+half];
2961 :
2962 1359817 : if (DECL_NAME (field) == NULL_TREE)
2963 : {
2964 : /* Step through all anon unions in linear fashion. */
2965 0 : while (DECL_NAME (field_array[bot]) == NULL_TREE)
2966 : {
2967 0 : field = field_array[bot++];
2968 0 : if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (field)))
2969 : {
2970 0 : tree anon = lookup_field (TREE_TYPE (field), component);
2971 :
2972 0 : if (anon)
2973 0 : return tree_cons (NULL_TREE, field, anon);
2974 :
2975 : /* The Plan 9 compiler permits referring
2976 : directly to an anonymous struct/union field
2977 : using a typedef name. */
2978 0 : if (flag_plan9_extensions
2979 0 : && TYPE_NAME (TREE_TYPE (field)) != NULL_TREE
2980 0 : && (TREE_CODE (TYPE_NAME (TREE_TYPE (field)))
2981 : == TYPE_DECL)
2982 0 : && (DECL_NAME (TYPE_NAME (TREE_TYPE (field)))
2983 : == component))
2984 : break;
2985 : }
2986 : }
2987 :
2988 : /* Entire record is only anon unions. */
2989 0 : if (bot > top)
2990 : return NULL_TREE;
2991 :
2992 : /* Restart the binary search, with new lower bound. */
2993 0 : continue;
2994 0 : }
2995 :
2996 1359817 : if (DECL_NAME (field) == component)
2997 : break;
2998 1086663 : if (DECL_NAME (field) < component)
2999 : bot += half;
3000 : else
3001 899280 : top = bot + half;
3002 : }
3003 :
3004 302427 : if (DECL_NAME (field_array[bot]) == component)
3005 : field = field_array[bot];
3006 273154 : else if (DECL_NAME (field) != component)
3007 : return NULL_TREE;
3008 : }
3009 : else
3010 : {
3011 5276049 : for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
3012 : {
3013 5266556 : if (DECL_NAME (field) == NULL_TREE
3014 5266556 : && RECORD_OR_UNION_TYPE_P (TREE_TYPE (field)))
3015 : {
3016 12406 : tree anon = lookup_field (TREE_TYPE (field), component);
3017 :
3018 12406 : if (anon)
3019 3008 : return tree_cons (NULL_TREE, field, anon);
3020 :
3021 : /* The Plan 9 compiler permits referring directly to an
3022 : anonymous struct/union field using a typedef
3023 : name. */
3024 9398 : if (flag_plan9_extensions
3025 174 : && TYPE_NAME (TREE_TYPE (field)) != NULL_TREE
3026 172 : && TREE_CODE (TYPE_NAME (TREE_TYPE (field))) == TYPE_DECL
3027 9460 : && (DECL_NAME (TYPE_NAME (TREE_TYPE (field)))
3028 : == component))
3029 : break;
3030 : }
3031 :
3032 5263544 : if (DECL_NAME (field) == component)
3033 : break;
3034 : }
3035 :
3036 2023741 : if (field == NULL_TREE)
3037 : return NULL_TREE;
3038 : }
3039 :
3040 2316675 : return tree_cons (NULL_TREE, field, NULL_TREE);
3041 : }
3042 :
3043 : /* Recursively append candidate IDENTIFIER_NODEs to CANDIDATES. */
3044 :
3045 : static void
3046 101 : lookup_field_fuzzy_find_candidates (tree type, tree component,
3047 : vec<tree> *candidates)
3048 : {
3049 101 : tree field;
3050 258 : for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
3051 : {
3052 157 : if (DECL_NAME (field) == NULL_TREE
3053 157 : && RECORD_OR_UNION_TYPE_P (TREE_TYPE (field)))
3054 30 : lookup_field_fuzzy_find_candidates (TREE_TYPE (field), component,
3055 : candidates);
3056 :
3057 157 : if (DECL_NAME (field))
3058 111 : candidates->safe_push (DECL_NAME (field));
3059 : }
3060 101 : }
3061 :
3062 : /* Like "lookup_field", but find the closest matching IDENTIFIER_NODE,
3063 : rather than returning a TREE_LIST for an exact match. */
3064 :
3065 : static tree
3066 71 : lookup_field_fuzzy (tree type, tree component)
3067 : {
3068 71 : gcc_assert (TREE_CODE (component) == IDENTIFIER_NODE);
3069 :
3070 : /* First, gather a list of candidates. */
3071 71 : auto_vec <tree> candidates;
3072 :
3073 71 : lookup_field_fuzzy_find_candidates (type, component,
3074 : &candidates);
3075 :
3076 71 : return find_closest_identifier (component, &candidates);
3077 71 : }
3078 :
3079 : /* Support function for build_component_ref's error-handling.
3080 :
3081 : Given DATUM_TYPE, and "DATUM.COMPONENT", where DATUM is *not* a
3082 : struct or union, should we suggest "DATUM->COMPONENT" as a hint? */
3083 :
3084 : static bool
3085 72 : should_suggest_deref_p (tree datum_type)
3086 : {
3087 : /* We don't do it for Objective-C, since Objective-C 2.0 dot-syntax
3088 : allows "." for ptrs; we could be handling a failed attempt
3089 : to access a property. */
3090 72 : if (c_dialect_objc ())
3091 : return false;
3092 :
3093 : /* Only suggest it for pointers... */
3094 72 : if (TREE_CODE (datum_type) != POINTER_TYPE)
3095 : return false;
3096 :
3097 : /* ...to structs/unions. */
3098 8 : tree underlying_type = TREE_TYPE (datum_type);
3099 8 : enum tree_code code = TREE_CODE (underlying_type);
3100 8 : if (code == RECORD_TYPE || code == UNION_TYPE)
3101 : return true;
3102 : else
3103 1 : return false;
3104 : }
3105 :
3106 : /* Give a component ref REF, decide whether we should handle its counted_by
3107 : attribute based on its context:
3108 : Do not handle counted_by when in offsetof, typeof and alignof operator. */
3109 :
3110 : static bool
3111 2215199 : handle_counted_by_p (tree ref)
3112 : {
3113 2215199 : gcc_assert (TREE_CODE (ref) == COMPONENT_REF);
3114 2215199 : tree datum = TREE_OPERAND (ref, 0);
3115 : /* If the component_ref is build for a offsetof, i.e., the datum
3116 : of the component_ref is a indirect_ref of null_pointer_node,
3117 : we should not generate call to .ACCESS_WITH_SIZE. */
3118 2215199 : if (TREE_CODE (datum) == INDIRECT_REF
3119 2215199 : && TREE_OPERAND (datum, 0) == null_pointer_node)
3120 : return false;
3121 2214861 : if (in_typeof || in_alignof)
3122 8786 : return false;
3123 : return true;
3124 : }
3125 :
3126 : /* Given a component ref REF, if there is a counted_by attribute attached,
3127 : issue error when the element_type is a structure or union including a
3128 : flexible array member. */
3129 :
3130 : static void
3131 2282660 : check_counted_by_attribute (location_t loc, tree ref)
3132 : {
3133 2282660 : tree subdatum = TREE_OPERAND (ref, 1);
3134 2282660 : tree sub_type = TREE_TYPE (subdatum);
3135 :
3136 2282660 : if (!flexible_array_member_type_p (sub_type)
3137 2282660 : && TREE_CODE (sub_type) != POINTER_TYPE)
3138 : return;
3139 :
3140 390063 : tree element_type = TREE_TYPE (sub_type);
3141 :
3142 390063 : tree attr_counted_by = lookup_attribute ("counted_by",
3143 390063 : DECL_ATTRIBUTES (subdatum));
3144 390063 : if (attr_counted_by)
3145 : {
3146 : /* Issue error when the element_type is a structure or
3147 : union including a flexible array member. */
3148 881 : if (RECORD_OR_UNION_TYPE_P (element_type)
3149 881 : && TYPE_INCLUDES_FLEXARRAY (element_type))
3150 : {
3151 2 : error_at (loc,
3152 : "%<counted_by%> attribute is not allowed for a pointer to"
3153 : " structure or union with flexible array member");
3154 2 : return;
3155 : }
3156 : }
3157 : }
3158 :
3159 : /* For a SUBDATUM field of a structure or union DATUM, generate a REF
3160 : to the object that represents its counted_by per the attribute
3161 : counted_by attached to this field if it's a flexible array member
3162 : or a pointer field, otherwise return NULL_TREE.
3163 : Set COUNTED_BY_TYPE to the TYPE of the counted_by field.
3164 : For example, if:
3165 :
3166 : struct P {
3167 : int k;
3168 : int x[] __attribute__ ((counted_by (k)));
3169 : } *p;
3170 :
3171 : for:
3172 : p->x
3173 :
3174 : the ref to the object that represents its element count will be:
3175 :
3176 : &(p->k)
3177 : */
3178 :
3179 : static tree
3180 442237 : build_counted_by_ref (tree datum, tree subdatum,
3181 : tree *counted_by_type)
3182 : {
3183 442237 : tree sub_type = TREE_TYPE (subdatum);
3184 442237 : if (!flexible_array_member_type_p (sub_type)
3185 442237 : && TREE_CODE (sub_type) != POINTER_TYPE)
3186 : return NULL_TREE;
3187 :
3188 442237 : tree attr_counted_by = lookup_attribute ("counted_by",
3189 442237 : DECL_ATTRIBUTES (subdatum));
3190 442237 : if (!attr_counted_by)
3191 : return NULL_TREE;
3192 :
3193 660 : tree counted_by_ref = NULL_TREE;
3194 660 : *counted_by_type = NULL_TREE;
3195 :
3196 660 : tree type = TREE_TYPE (datum);
3197 :
3198 : /* If the type of the containing structure is an anonymous struct/union,
3199 : and this anonymous struct/union is not a root type, get the first
3200 : outer named structure/union type. */
3201 660 : while (TREE_CODE (datum) == COMPONENT_REF
3202 35 : && c_type_tag (type) == NULL_TREE
3203 730 : && DECL_NAME (TREE_OPERAND (datum, 1)) == NULL_TREE)
3204 : {
3205 35 : datum = TREE_OPERAND (datum, 0);
3206 35 : type = TREE_TYPE (datum);
3207 : }
3208 :
3209 660 : tree field_id = TREE_VALUE (TREE_VALUE (attr_counted_by));
3210 660 : tree counted_by_field = lookup_field (type, field_id);
3211 660 : gcc_assert (counted_by_field);
3212 :
3213 1072 : tree counted_by_subdatum;
3214 1072 : do
3215 : {
3216 1072 : counted_by_subdatum = TREE_VALUE (counted_by_field);
3217 : /* Get the TYPE of the counted_by field. */
3218 1072 : *counted_by_type = TREE_TYPE (counted_by_subdatum);
3219 :
3220 1072 : counted_by_ref
3221 1072 : = build3 (COMPONENT_REF, TREE_TYPE (counted_by_subdatum),
3222 : datum, counted_by_subdatum, NULL_TREE);
3223 :
3224 1072 : datum = counted_by_ref;
3225 1072 : counted_by_field = TREE_CHAIN (counted_by_field);
3226 : }
3227 1072 : while (counted_by_field);
3228 :
3229 660 : counted_by_ref = build_fold_addr_expr (counted_by_ref);
3230 660 : return counted_by_ref;
3231 : }
3232 :
3233 : /* Given a COMPONENT_REF REF with the location LOC, the corresponding
3234 : COUNTED_BY_REF, and the COUNTED_BY_TYPE, generate the corresponding
3235 : call to the internal function .ACCESS_WITH_SIZE.
3236 :
3237 : A: For the Flexible Array Member, Generate an INDIRECT_REF to a call to
3238 : the internal function .ACCESS_WITH_SIZE.
3239 :
3240 : REF
3241 :
3242 : to:
3243 :
3244 : (*.ACCESS_WITH_SIZE (REF, COUNTED_BY_REF, (* TYPE_OF_SIZE)0,
3245 : TYPE_SIZE_UNIT for element)
3246 :
3247 : NOTE: The return type of this function is the POINTER type pointing
3248 : to the original flexible array type. Then the type of the INDIRECT_REF
3249 : is the original flexible array type.
3250 : The type of the first argument of this function is a POINTER type
3251 : to the original flexible array type.
3252 :
3253 : B: For pointers with counted_by, generate a call to the internal function
3254 : .ACCESS_WITH_SIZE.
3255 :
3256 : REF
3257 :
3258 : to:
3259 :
3260 : .ACCESS_WITH_SIZE (REF, COUNTED_BY_REF, (* TYPE_OF_SIZE)0,
3261 : TYPE_SIZE_UNIT for element)
3262 :
3263 : NOTE: The return type of this function is the original pointer type.
3264 : The type of the first argument of this function is the original
3265 : pointer type.
3266 :
3267 : The 3rd argument of the call is a constant 0 with the pointer TYPE whose
3268 : pointee type is the TYPE of the object pointed by COUNTED_BY_REF.
3269 :
3270 : The 4th argument of the call is the TYPE_SIZE_UNIT of the element TYPE
3271 : of the array.
3272 :
3273 : */
3274 : static tree
3275 660 : build_access_with_size_for_counted_by (location_t loc, tree ref,
3276 : tree counted_by_ref,
3277 : tree counted_by_type)
3278 : {
3279 660 : gcc_assert (flexible_array_member_type_p (TREE_TYPE (ref))
3280 : || TREE_CODE (TREE_TYPE (ref)) == POINTER_TYPE);
3281 :
3282 660 : bool is_fam = flexible_array_member_type_p (TREE_TYPE (ref));
3283 :
3284 : /* The result type of the call is a pointer to the flexible array type;
3285 : or is the original pointer type to the pointer field with counted_by. */
3286 660 : tree result_type = is_fam ? c_build_pointer_type (TREE_TYPE (ref))
3287 459 : : TREE_TYPE (ref);
3288 :
3289 660 : tree element_type = TREE_TYPE (TREE_TYPE (ref));
3290 660 : tree element_size = VOID_TYPE_P (element_type)
3291 660 : ? size_one_node
3292 660 : : TYPE_SIZE_UNIT (element_type);
3293 660 : if (element_size == NULL_TREE)
3294 : return ref;
3295 :
3296 646 : tree first_param = is_fam
3297 646 : ? c_fully_fold (array_to_pointer_conversion (loc, ref),
3298 : false, NULL)
3299 445 : : c_fully_fold (ref, false, NULL);
3300 646 : tree second_param
3301 646 : = c_fully_fold (counted_by_ref, false, NULL);
3302 646 : tree third_param = build_int_cst (c_build_pointer_type (counted_by_type), 0);
3303 :
3304 646 : tree call
3305 646 : = build_call_expr_internal_loc (loc, IFN_ACCESS_WITH_SIZE,
3306 : result_type, 4,
3307 : first_param,
3308 : second_param,
3309 : third_param,
3310 : element_size);
3311 :
3312 : /* Wrap the call with an INDIRECT_REF with the flexible array type. */
3313 646 : if (is_fam)
3314 201 : call = build1 (INDIRECT_REF, TREE_TYPE (ref), call);
3315 646 : SET_EXPR_LOCATION (call, loc);
3316 646 : return call;
3317 : }
3318 :
3319 : /* For the COMPONENT_REF ref, check whether it has a counted_by attribute,
3320 : if so, wrap this COMPONENT_REF with the corresponding CALL to the
3321 : function .ACCESS_WITH_SIZE.
3322 : Otherwise, return the ref itself. */
3323 :
3324 : tree
3325 2206155 : handle_counted_by_for_component_ref (location_t loc, tree ref)
3326 : {
3327 2206155 : gcc_assert (TREE_CODE (ref) == COMPONENT_REF);
3328 2206155 : tree datum = TREE_OPERAND (ref, 0);
3329 2206155 : tree subdatum = TREE_OPERAND (ref, 1);
3330 2206155 : tree counted_by_type = NULL_TREE;
3331 :
3332 2206155 : if (!(flexible_array_member_type_p (TREE_TYPE (ref))
3333 2135613 : || TREE_CODE (TREE_TYPE (ref)) == POINTER_TYPE))
3334 : return ref;
3335 :
3336 442237 : tree counted_by_ref = build_counted_by_ref (datum, subdatum,
3337 : &counted_by_type);
3338 442237 : if (counted_by_ref)
3339 660 : ref = build_access_with_size_for_counted_by (loc, ref,
3340 : counted_by_ref,
3341 : counted_by_type);
3342 : return ref;
3343 : }
3344 :
3345 : /* Make an expression to refer to the COMPONENT field of structure or
3346 : union value DATUM. COMPONENT is an IDENTIFIER_NODE. LOC is the
3347 : location of the COMPONENT_REF. COMPONENT_LOC is the location
3348 : of COMPONENT. ARROW_LOC is the location of the first -> operand if
3349 : it is from -> operator.
3350 : If HANDLE_COUNTED_BY is true, check the counted_by attribute and generate
3351 : a call to .ACCESS_WITH_SIZE. Otherwise, ignore the attribute. */
3352 :
3353 : tree
3354 2280541 : build_component_ref (location_t loc, tree datum, tree component,
3355 : location_t component_loc, location_t arrow_loc)
3356 : {
3357 2280541 : tree type = TREE_TYPE (datum);
3358 2280541 : enum tree_code code = TREE_CODE (type);
3359 2280541 : tree field = NULL;
3360 2280541 : tree ref;
3361 2280541 : bool datum_lvalue = lvalue_p (datum);
3362 :
3363 2280541 : if (!objc_is_public (datum, component))
3364 0 : return error_mark_node;
3365 :
3366 : /* Detect Objective-C property syntax object.property. */
3367 2280541 : if (c_dialect_objc ()
3368 2280541 : && (ref = objc_maybe_build_component_ref (datum, component)))
3369 : return ref;
3370 :
3371 : /* See if there is a field or component with name COMPONENT. */
3372 :
3373 2280541 : if (code == RECORD_TYPE || code == UNION_TYPE)
3374 : {
3375 2280469 : if (!COMPLETE_TYPE_P (type))
3376 : {
3377 19 : c_incomplete_type_error (loc, NULL_TREE, type);
3378 19 : return error_mark_node;
3379 : }
3380 :
3381 2280450 : field = lookup_field (type, component);
3382 :
3383 2280450 : if (!field)
3384 : {
3385 63 : tree guessed_id = lookup_field_fuzzy (type, component);
3386 63 : if (guessed_id)
3387 : {
3388 : /* Attempt to provide a fixit replacement hint, if
3389 : we have a valid range for the component. */
3390 0 : location_t reported_loc
3391 26 : = (component_loc != UNKNOWN_LOCATION) ? component_loc : loc;
3392 26 : gcc_rich_location rich_loc (reported_loc);
3393 26 : if (component_loc != UNKNOWN_LOCATION)
3394 26 : rich_loc.add_fixit_misspelled_id (component_loc, guessed_id);
3395 26 : error_at (&rich_loc,
3396 : "%qT has no member named %qE; did you mean %qE?",
3397 : type, component, guessed_id);
3398 26 : }
3399 : else
3400 37 : error_at (loc, "%qT has no member named %qE", type, component);
3401 63 : return error_mark_node;
3402 : }
3403 :
3404 : /* Accessing elements of atomic structures or unions is undefined
3405 : behavior (C11 6.5.2.3#5). */
3406 2280387 : if (TYPE_ATOMIC (type) && c_inhibit_evaluation_warnings == 0)
3407 : {
3408 18 : if (code == RECORD_TYPE)
3409 12 : warning_at (loc, 0, "accessing a member %qE of an atomic "
3410 : "structure %qE", component, datum);
3411 : else
3412 6 : warning_at (loc, 0, "accessing a member %qE of an atomic "
3413 : "union %qE", component, datum);
3414 : }
3415 :
3416 : /* Chain the COMPONENT_REFs if necessary down to the FIELD.
3417 : This might be better solved in future the way the C++ front
3418 : end does it - by giving the anonymous entities each a
3419 : separate name and type, and then have build_component_ref
3420 : recursively call itself. We can't do that here. */
3421 2282660 : do
3422 : {
3423 2282660 : tree subdatum = TREE_VALUE (field);
3424 2282660 : int quals;
3425 2282660 : tree subtype;
3426 2282660 : bool use_datum_quals;
3427 :
3428 2282660 : if (TREE_TYPE (subdatum) == error_mark_node)
3429 : return error_mark_node;
3430 :
3431 : /* If this is an rvalue, it does not have qualifiers in C
3432 : standard terms and we must avoid propagating such
3433 : qualifiers down to a non-lvalue array that is then
3434 : converted to a pointer. */
3435 4565320 : use_datum_quals = (datum_lvalue
3436 2282660 : || TREE_CODE (TREE_TYPE (subdatum)) != ARRAY_TYPE);
3437 :
3438 2282660 : quals = TYPE_QUALS (strip_array_types (TREE_TYPE (subdatum)));
3439 2282660 : if (use_datum_quals)
3440 2282398 : quals |= TYPE_QUALS (TREE_TYPE (datum));
3441 2282660 : subtype = c_build_qualified_type (TREE_TYPE (subdatum), quals);
3442 :
3443 2282660 : ref = build3 (COMPONENT_REF, subtype, datum, subdatum,
3444 : NULL_TREE);
3445 2282660 : SET_EXPR_LOCATION (ref, loc);
3446 :
3447 2282660 : check_counted_by_attribute (loc, ref);
3448 :
3449 2282660 : if (TREE_READONLY (subdatum)
3450 2282660 : || (use_datum_quals && TREE_READONLY (datum)))
3451 30821 : TREE_READONLY (ref) = 1;
3452 2282660 : if (TREE_THIS_VOLATILE (subdatum)
3453 2281634 : || (use_datum_quals && TREE_THIS_VOLATILE (datum)))
3454 2476 : TREE_THIS_VOLATILE (ref) = 1;
3455 :
3456 2282660 : if (TREE_UNAVAILABLE (subdatum))
3457 10 : error_unavailable_use (subdatum, NULL_TREE);
3458 2282650 : else if (TREE_DEPRECATED (subdatum))
3459 16 : warn_deprecated_use (subdatum, NULL_TREE);
3460 :
3461 2282660 : datum = ref;
3462 :
3463 2282660 : field = TREE_CHAIN (field);
3464 : }
3465 2282660 : while (field);
3466 :
3467 : return ref;
3468 : }
3469 72 : else if (should_suggest_deref_p (type))
3470 : {
3471 : /* Special-case the error message for "ptr.field" for the case
3472 : where the user has confused "." vs "->". */
3473 7 : rich_location richloc (line_table, loc);
3474 7 : if (INDIRECT_REF_P (datum) && arrow_loc != UNKNOWN_LOCATION)
3475 : {
3476 2 : richloc.add_fixit_insert_before (arrow_loc, "(*");
3477 2 : richloc.add_fixit_insert_after (arrow_loc, ")");
3478 2 : error_at (&richloc,
3479 : "%qE is a pointer to pointer; did you mean to dereference "
3480 : "it before applying %<->%> to it?",
3481 2 : TREE_OPERAND (datum, 0));
3482 : }
3483 : else
3484 : {
3485 : /* "loc" should be the "." token. */
3486 5 : richloc.add_fixit_replace ("->");
3487 5 : error_at (&richloc,
3488 : "%qE is a pointer; did you mean to use %<->%>?",
3489 : datum);
3490 : }
3491 7 : return error_mark_node;
3492 7 : }
3493 65 : else if (code != ERROR_MARK)
3494 1 : error_at (loc,
3495 : "request for member %qE in something not a structure or union",
3496 : component);
3497 :
3498 65 : return error_mark_node;
3499 : }
3500 :
3501 : /* Given an expression PTR for a pointer, return an expression
3502 : for the value pointed to.
3503 : ERRORSTRING is the name of the operator to appear in error messages.
3504 :
3505 : LOC is the location to use for the generated tree. */
3506 :
3507 : tree
3508 2767489 : build_indirect_ref (location_t loc, tree ptr, ref_operator errstring)
3509 : {
3510 2767489 : tree pointer = default_conversion (ptr);
3511 2767489 : tree type = TREE_TYPE (pointer);
3512 2767489 : tree ref;
3513 :
3514 2767489 : if (TREE_CODE (type) == POINTER_TYPE)
3515 : {
3516 2767135 : if (CONVERT_EXPR_P (pointer)
3517 1984041 : || TREE_CODE (pointer) == VIEW_CONVERT_EXPR)
3518 : {
3519 : /* If a warning is issued, mark it to avoid duplicates from
3520 : the backend. This only needs to be done at
3521 : warn_strict_aliasing > 2. */
3522 783094 : if (warn_strict_aliasing > 2)
3523 335156 : if (strict_aliasing_warning (EXPR_LOCATION (pointer),
3524 335156 : type, TREE_OPERAND (pointer, 0)))
3525 8 : suppress_warning (pointer, OPT_Wstrict_aliasing_);
3526 : }
3527 :
3528 2767135 : if (TREE_CODE (pointer) == ADDR_EXPR
3529 2767135 : && (TREE_TYPE (TREE_OPERAND (pointer, 0))
3530 67454 : == TREE_TYPE (type)))
3531 : {
3532 67445 : ref = TREE_OPERAND (pointer, 0);
3533 67445 : protected_set_expr_location (ref, loc);
3534 67445 : return ref;
3535 : }
3536 : else
3537 : {
3538 2699690 : tree t = TREE_TYPE (type);
3539 :
3540 2699690 : ref = build1 (INDIRECT_REF, t, pointer);
3541 :
3542 2699690 : if (VOID_TYPE_P (t) && c_inhibit_evaluation_warnings == 0)
3543 151 : warning_at (loc, 0, "dereferencing %<void *%> pointer");
3544 :
3545 : /* We *must* set TREE_READONLY when dereferencing a pointer to const,
3546 : so that we get the proper error message if the result is used
3547 : to assign to. Also, &* is supposed to be a no-op.
3548 : And ANSI C seems to specify that the type of the result
3549 : should be the const type. */
3550 : /* A de-reference of a pointer to const is not a const. It is valid
3551 : to change it via some other pointer. */
3552 2699690 : TREE_READONLY (ref) = TYPE_READONLY (t);
3553 2699690 : TREE_SIDE_EFFECTS (ref)
3554 2699690 : = TYPE_VOLATILE (t) || TREE_SIDE_EFFECTS (pointer);
3555 2699690 : TREE_THIS_VOLATILE (ref) = TYPE_VOLATILE (t);
3556 2699690 : protected_set_expr_location (ref, loc);
3557 2699690 : return ref;
3558 : }
3559 : }
3560 354 : else if (TREE_CODE (pointer) != ERROR_MARK)
3561 278 : invalid_indirection_error (loc, type, errstring);
3562 :
3563 354 : return error_mark_node;
3564 : }
3565 :
3566 : /* This handles expressions of the form "a[i]", which denotes
3567 : an array reference.
3568 :
3569 : This is logically equivalent in C to *(a+i), but we may do it differently.
3570 : If A is a variable or a member, we generate a primitive ARRAY_REF.
3571 : This avoids forcing the array out of registers, and can work on
3572 : arrays that are not lvalues (for example, members of structures returned
3573 : by functions).
3574 :
3575 : For vector types, allow vector[i] but not i[vector], and create
3576 : *(((type*)&vectortype) + i) for the expression.
3577 :
3578 : LOC is the location to use for the returned expression. */
3579 :
3580 : tree
3581 3491113 : build_array_ref (location_t loc, tree array, tree index)
3582 : {
3583 3491113 : tree ret;
3584 3491113 : bool swapped = false;
3585 3491113 : if (TREE_TYPE (array) == error_mark_node
3586 3491113 : || TREE_TYPE (index) == error_mark_node)
3587 : return error_mark_node;
3588 :
3589 3491005 : if (TREE_CODE (TREE_TYPE (array)) != ARRAY_TYPE
3590 2006717 : && TREE_CODE (TREE_TYPE (array)) != POINTER_TYPE
3591 : /* Allow vector[index] but not index[vector]. */
3592 4519022 : && !gnu_vector_type_p (TREE_TYPE (array)))
3593 : {
3594 194 : if (TREE_CODE (TREE_TYPE (index)) != ARRAY_TYPE
3595 194 : && TREE_CODE (TREE_TYPE (index)) != POINTER_TYPE)
3596 : {
3597 2 : error_at (loc,
3598 : "subscripted value is neither array nor pointer nor vector");
3599 :
3600 2 : return error_mark_node;
3601 : }
3602 192 : std::swap (array, index);
3603 192 : swapped = true;
3604 : }
3605 :
3606 3491003 : if (!INTEGRAL_TYPE_P (TREE_TYPE (index)))
3607 : {
3608 2 : error_at (loc, "array subscript is not an integer");
3609 2 : return error_mark_node;
3610 : }
3611 :
3612 3491001 : if (TREE_CODE (TREE_TYPE (TREE_TYPE (array))) == FUNCTION_TYPE)
3613 : {
3614 10 : error_at (loc, "subscripted value is pointer to function");
3615 10 : return error_mark_node;
3616 : }
3617 :
3618 : /* ??? Existing practice has been to warn only when the char
3619 : index is syntactically the index, not for char[array]. */
3620 3490991 : if (!swapped)
3621 3490805 : warn_array_subscript_with_type_char (loc, index);
3622 :
3623 : /* Apply default promotions *after* noticing character types. */
3624 3490991 : index = default_conversion (index);
3625 3490991 : if (index == error_mark_node)
3626 : return error_mark_node;
3627 :
3628 3490990 : gcc_assert (TREE_CODE (TREE_TYPE (index)) == INTEGER_TYPE
3629 : || TREE_CODE (TREE_TYPE (index)) == BITINT_TYPE);
3630 :
3631 3490990 : bool was_vector = VECTOR_TYPE_P (TREE_TYPE (array));
3632 3490990 : bool non_lvalue = convert_vector_to_array_for_subscript (loc, &array, index);
3633 :
3634 : /* We only generate a call to .ACCESS_WITH_SIZE when it is a read. */
3635 3490990 : if (TREE_CODE (array) == COMPONENT_REF
3636 3490990 : && handle_counted_by_p (array))
3637 816725 : array = handle_counted_by_for_component_ref (loc, array);
3638 :
3639 3490990 : if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE)
3640 : {
3641 2512118 : tree rval, type;
3642 :
3643 : /* An array that is indexed by a non-constant
3644 : cannot be stored in a register; we must be able to do
3645 : address arithmetic on its address.
3646 : Likewise an array of elements of variable size. */
3647 2512118 : if (TREE_CODE (index) != INTEGER_CST
3648 2512118 : || (COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (array)))
3649 2031609 : && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array)))) != INTEGER_CST))
3650 : {
3651 481249 : if (!c_mark_addressable (array, true, true))
3652 1 : return error_mark_node;
3653 : }
3654 : /* An array that is indexed by a constant value which is not within
3655 : the array bounds cannot be stored in a register either; because we
3656 : would get a crash in store_bit_field/extract_bit_field when trying
3657 : to access a non-existent part of the register. */
3658 2512117 : if (TREE_CODE (index) == INTEGER_CST
3659 2031609 : && TYPE_DOMAIN (TREE_TYPE (array))
3660 4540367 : && !int_fits_type_p (index, TYPE_DOMAIN (TREE_TYPE (array))))
3661 : {
3662 60657 : if (!c_mark_addressable (array, false, true))
3663 0 : return error_mark_node;
3664 : /* ISO C2Y disallows a negative integer constant expression index
3665 : when array subscripting has an operand of array type. */
3666 60657 : if (flag_isoc2y
3667 26 : && !TREE_OVERFLOW (index)
3668 60680 : && tree_int_cst_sgn (index) < 0)
3669 10 : error_at (loc, "array subscript is negative");
3670 : }
3671 :
3672 2512117 : if ((pedantic || warn_c90_c99_compat || warn_c23_c2y_compat)
3673 2488660 : && ! was_vector)
3674 : {
3675 1483566 : tree foo = array;
3676 2319366 : while (TREE_CODE (foo) == COMPONENT_REF)
3677 835800 : foo = TREE_OPERAND (foo, 0);
3678 983842 : if ((VAR_P (foo) && C_DECL_REGISTER (foo))
3679 2467342 : || (TREE_CODE (foo) == COMPOUND_LITERAL_EXPR
3680 72 : && C_DECL_REGISTER (COMPOUND_LITERAL_EXPR_DECL (foo))))
3681 78 : pedwarn_c23 (loc, OPT_Wpedantic,
3682 : "ISO C forbids subscripting %<register%> array "
3683 : "before C2Y");
3684 1483488 : else if (!lvalue_p (foo))
3685 118 : pedwarn_c90 (loc, OPT_Wpedantic,
3686 : "ISO C90 forbids subscripting non-lvalue "
3687 : "array");
3688 : }
3689 :
3690 2512117 : if (TREE_CODE (TREE_TYPE (index)) == BITINT_TYPE
3691 2512117 : && TYPE_PRECISION (TREE_TYPE (index)) > TYPE_PRECISION (sizetype))
3692 3 : index = fold_convert (sizetype, index);
3693 :
3694 2512117 : type = TREE_TYPE (TREE_TYPE (array));
3695 2512117 : rval = build4 (ARRAY_REF, type, array, index, NULL_TREE, NULL_TREE);
3696 : /* Array ref is const/volatile if the array elements are
3697 : or if the array is. */
3698 7536351 : TREE_READONLY (rval)
3699 2512117 : |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array)))
3700 2512117 : | TREE_READONLY (array));
3701 7536351 : TREE_SIDE_EFFECTS (rval)
3702 2512117 : |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
3703 2512117 : | TREE_SIDE_EFFECTS (array));
3704 5024234 : TREE_THIS_VOLATILE (rval)
3705 2512117 : |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
3706 : /* This was added by rms on 16 Nov 91.
3707 : It fixes vol struct foo *a; a->elts[1]
3708 : in an inline function.
3709 : Hope it doesn't break something else. */
3710 2512117 : | TREE_THIS_VOLATILE (array));
3711 2512117 : ret = require_complete_type (loc, rval);
3712 2512117 : protected_set_expr_location (ret, loc);
3713 2512117 : if (non_lvalue)
3714 105622 : ret = non_lvalue_loc (loc, ret);
3715 : return ret;
3716 : }
3717 : else
3718 : {
3719 978872 : tree ar = default_conversion (array);
3720 :
3721 978872 : if (ar == error_mark_node)
3722 : return ar;
3723 :
3724 978872 : gcc_assert (TREE_CODE (TREE_TYPE (ar)) == POINTER_TYPE);
3725 978872 : gcc_assert (TREE_CODE (TREE_TYPE (TREE_TYPE (ar))) != FUNCTION_TYPE);
3726 :
3727 978872 : ret = build_indirect_ref (loc, build_binary_op (loc, PLUS_EXPR, ar,
3728 : index, false),
3729 : RO_ARRAY_INDEXING);
3730 978872 : if (non_lvalue)
3731 0 : ret = non_lvalue_loc (loc, ret);
3732 : return ret;
3733 : }
3734 : }
3735 :
3736 : /* Build an OpenMP array section reference, creating an exact type for the
3737 : resulting expression based on the element type and bounds if possible. If
3738 : we have variable bounds, create an incomplete array type for the result
3739 : instead. */
3740 :
3741 : tree
3742 3984 : build_omp_array_section (location_t loc, tree array, tree index, tree length)
3743 : {
3744 3984 : tree type = TREE_TYPE (array);
3745 3984 : gcc_assert (type);
3746 :
3747 3984 : tree sectype, eltype = TREE_TYPE (type);
3748 :
3749 : /* It's not an array or pointer type. Just reuse the type of the original
3750 : expression as the type of the array section (an error will be raised
3751 : anyway, later). */
3752 3984 : if (eltype == NULL_TREE || error_operand_p (eltype))
3753 12 : sectype = TREE_TYPE (array);
3754 : else
3755 : {
3756 3972 : tree idxtype = NULL_TREE;
3757 :
3758 3972 : if (index != NULL_TREE
3759 3972 : && length != NULL_TREE
3760 3032 : && INTEGRAL_TYPE_P (TREE_TYPE (index))
3761 6999 : && INTEGRAL_TYPE_P (TREE_TYPE (length)))
3762 : {
3763 3020 : tree low = fold_convert (sizetype, index);
3764 3020 : tree high = fold_convert (sizetype, length);
3765 3020 : high = size_binop (PLUS_EXPR, low, high);
3766 3020 : high = size_binop (MINUS_EXPR, high, size_one_node);
3767 3020 : idxtype = build_range_type (sizetype, low, high);
3768 : }
3769 137 : else if ((index == NULL_TREE || integer_zerop (index))
3770 840 : && length != NULL_TREE
3771 1638 : && INTEGRAL_TYPE_P (TREE_TYPE (length)))
3772 669 : idxtype = build_index_type (length);
3773 :
3774 3972 : gcc_assert (!error_operand_p (idxtype));
3775 :
3776 3972 : sectype = c_build_array_type (eltype, idxtype);
3777 : }
3778 :
3779 3984 : return build3_loc (loc, OMP_ARRAY_SECTION, sectype, array, index, length);
3780 : }
3781 :
3782 :
3783 : /* Record that REF is used. This is relevant for undeclared static
3784 : function and declarations referenced from a non-local context.
3785 : ADDRESS indicates whether the address is taken. */
3786 :
3787 : void
3788 489062921 : mark_decl_used (tree ref, bool address)
3789 : {
3790 489062921 : if (!ref || !DECL_P (ref) || in_alignof)
3791 : return;
3792 :
3793 : /* Non-file-scope and non-local reference in nested function. */
3794 358675977 : bool nonloc_p = current_function_decl && DECL_CONTEXT (ref)
3795 124945717 : && DECL_CONTEXT (current_function_decl)
3796 489028873 : && DECL_CONTEXT (ref) != current_function_decl;
3797 :
3798 : /* An undeclared static function. */
3799 489018775 : bool static_p = TREE_CODE (ref) == FUNCTION_DECL
3800 105357657 : && DECL_INITIAL (ref) == NULL_TREE
3801 72011602 : && DECL_EXTERNAL (ref)
3802 561027681 : && !TREE_PUBLIC (ref);
3803 :
3804 488884785 : if (!static_p && !nonloc_p)
3805 : return;
3806 :
3807 : /* If we may be in an unevaluated context, delay the decision. */
3808 136629 : if (in_sizeof || in_typeof || in_countof || in_generic)
3809 273 : return record_maybe_used_decl (ref, address);
3810 :
3811 136356 : if (static_p)
3812 133734 : C_DECL_USED (ref) = 1;
3813 :
3814 136356 : if (nonloc_p && (VAR_OR_FUNCTION_DECL_P (ref)
3815 : || TREE_CODE (ref) == PARM_DECL))
3816 2059 : DECL_NONLOCAL (ref) = 1;
3817 :
3818 : /* Nothing to do anymore. */
3819 2622 : if (!nonloc_p || C_FUNC_NONLOCAL_CONTEXT (current_function_decl))
3820 : return;
3821 :
3822 : /* Filter out the cases where referencing a non-local variable does not
3823 : require a non-local context passed via the static chain. */
3824 1217 : if (!c_type_variably_modified_p (TREE_TYPE (ref)))
3825 1145 : switch (TREE_CODE (ref))
3826 : {
3827 219 : case FUNCTION_DECL:
3828 : /* Use of another local function that requires no context is ok. */
3829 219 : if (!C_FUNC_NONLOCAL_CONTEXT (ref) && DECL_INITIAL (ref))
3830 : return;
3831 : break;
3832 440 : case VAR_DECL:
3833 : /* Static variables and constexpr are ok, but for the later only
3834 : when the address is not taken. */
3835 440 : if (TREE_STATIC (ref) || (C_DECL_DECLARED_CONSTEXPR (ref) && !address))
3836 : return;
3837 : break;
3838 : case TYPE_DECL:
3839 : /* A typedef is ok when not for a variably-modified type. */
3840 : return;
3841 : case CONST_DECL:
3842 : /* An enumeration constant is ok. */
3843 : return;
3844 : case PARM_DECL:
3845 : break;
3846 : case LABEL_DECL:
3847 : break;
3848 0 : default:
3849 0 : gcc_unreachable ();
3850 : }
3851 :
3852 : /* Mark all parent functions up to the nesting level of the variable as
3853 : as needing the non-local context. */
3854 2027 : for (tree cont = current_function_decl; cont; cont = DECL_CONTEXT (cont))
3855 : {
3856 2027 : if (cont == DECL_CONTEXT (ref))
3857 : break;
3858 :
3859 : /* There should not be any other type of context used for function
3860 : except TRANSLATION_UNIT_DECL which we should be able to reach. */
3861 1019 : gcc_checking_assert (TREE_CODE (cont) == FUNCTION_DECL);
3862 :
3863 1019 : if (TREE_CODE (cont) == FUNCTION_DECL)
3864 1019 : C_FUNC_NONLOCAL_CONTEXT (cont) = 1;
3865 : }
3866 : }
3867 :
3868 :
3869 : /* Build an external reference to identifier ID. FUN indicates
3870 : whether this will be used for a function call. LOC is the source
3871 : location of the identifier. This sets *TYPE to the type of the
3872 : identifier, which is not the same as the type of the returned value
3873 : for CONST_DECLs defined as enum constants. If the type of the
3874 : identifier is not available, *TYPE is set to NULL. */
3875 : tree
3876 179448517 : build_external_ref (location_t loc, tree id, bool fun, tree *type)
3877 : {
3878 179448517 : tree ref;
3879 179448517 : tree decl = lookup_name (id);
3880 :
3881 : /* In Objective-C, an instance variable (ivar) may be preferred to
3882 : whatever lookup_name() found. */
3883 179448517 : decl = objc_lookup_ivar (decl, id);
3884 :
3885 179448517 : *type = NULL;
3886 179448517 : if (decl && decl != error_mark_node)
3887 : {
3888 179442352 : ref = decl;
3889 179442352 : *type = TREE_TYPE (ref);
3890 179442352 : if (DECL_P (decl) && C_DECL_UNDERSPECIFIED (decl))
3891 4 : error_at (loc, "underspecified %qD referenced in its initializer",
3892 : decl);
3893 : }
3894 6165 : else if (fun)
3895 : /* Implicit function declaration. */
3896 4729 : ref = implicitly_declare (loc, id);
3897 1436 : else if (decl == error_mark_node)
3898 : /* Don't complain about something that's already been
3899 : complained about. */
3900 : return error_mark_node;
3901 : else
3902 : {
3903 1201 : undeclared_variable (loc, id);
3904 1201 : return error_mark_node;
3905 : }
3906 :
3907 : /* For an OpenMP map clause, we can get better diagnostics for decls with
3908 : unmappable types if we return the decl with an error_mark_node type,
3909 : rather than returning error_mark_node for the decl itself. */
3910 179447081 : if (TREE_TYPE (ref) == error_mark_node
3911 179447081 : && !c_omp_array_section_p)
3912 : return error_mark_node;
3913 :
3914 179447063 : if (TREE_UNAVAILABLE (ref))
3915 14 : error_unavailable_use (ref, NULL_TREE);
3916 179447049 : else if (TREE_DEPRECATED (ref))
3917 100 : warn_deprecated_use (ref, NULL_TREE);
3918 :
3919 : /* Recursive call does not count as usage. */
3920 179447063 : if (ref != current_function_decl)
3921 : {
3922 179444366 : TREE_USED (ref) = 1;
3923 : }
3924 :
3925 179447063 : mark_decl_used (ref, false);
3926 :
3927 179447063 : if (TREE_CODE (ref) == CONST_DECL)
3928 : {
3929 419746 : used_types_insert (TREE_TYPE (ref));
3930 :
3931 419746 : if (warn_cxx_compat
3932 429 : && TREE_CODE (TREE_TYPE (ref)) == ENUMERAL_TYPE
3933 420173 : && C_TYPE_DEFINED_IN_STRUCT (TREE_TYPE (ref)))
3934 : {
3935 1 : warning_at (loc, OPT_Wc___compat,
3936 : "enum constant defined in struct or union "
3937 : "is not visible in C++");
3938 1 : inform (DECL_SOURCE_LOCATION (ref), "enum constant defined here");
3939 : }
3940 :
3941 419746 : ref = DECL_INITIAL (ref);
3942 419746 : TREE_CONSTANT (ref) = 1;
3943 : }
3944 : /* C99 6.7.4p3: An inline definition of a function with external
3945 : linkage ... shall not contain a reference to an identifier with
3946 : internal linkage. */
3947 179027317 : else if (current_function_decl != NULL_TREE
3948 177512447 : && DECL_DECLARED_INLINE_P (current_function_decl)
3949 163721315 : && DECL_EXTERNAL (current_function_decl)
3950 162946181 : && VAR_OR_FUNCTION_DECL_P (ref)
3951 58251351 : && (!VAR_P (ref) || TREE_STATIC (ref))
3952 49057793 : && ! TREE_PUBLIC (ref)
3953 179027351 : && DECL_CONTEXT (ref) != current_function_decl)
3954 25 : record_inline_static (loc, current_function_decl, ref,
3955 : csi_internal);
3956 :
3957 : return ref;
3958 : }
3959 :
3960 : static struct maybe_used_decl *maybe_used_decls;
3961 :
3962 : /* Record that DECL, a reference seen inside sizeof or typeof or _Countof or
3963 : _Generic, might be used if the operand of sizeof is a VLA type or the
3964 : operand of typeof is a variably modified type or the operand of _Countof has
3965 : a variable number of elements or the operand of _Generic is the one selected
3966 : as the result. */
3967 :
3968 : static void
3969 273 : record_maybe_used_decl (tree decl, bool address)
3970 : {
3971 273 : struct maybe_used_decl *t = XOBNEW (&parser_obstack, struct maybe_used_decl);
3972 273 : t->decl = decl;
3973 273 : t->level = in_sizeof + in_typeof + in_countof + in_generic;
3974 273 : t->address = address;
3975 273 : t->next = maybe_used_decls;
3976 273 : maybe_used_decls = t;
3977 273 : }
3978 :
3979 : /* Pop the stack of decls possibly used inside sizeof or typeof or _Countof or
3980 : _Generic. If USED is false, just discard them. If it is true, mark them
3981 : used (if no longer inside sizeof or typeof or _Countof or _Generic) or move
3982 : them to the next level up (if still inside sizeof or typeof or _Countof or
3983 : _Generic). */
3984 :
3985 : void
3986 1471895 : pop_maybe_used (bool used)
3987 : {
3988 1471895 : struct maybe_used_decl *p = maybe_used_decls;
3989 1471895 : int cur_level = in_sizeof + in_typeof + in_countof + in_generic;
3990 1472192 : while (p && p->level > cur_level)
3991 : {
3992 297 : if (used)
3993 : {
3994 77 : if (cur_level == 0)
3995 53 : mark_decl_used (p->decl, p->address);
3996 : else
3997 24 : p->level = cur_level;
3998 : }
3999 297 : p = p->next;
4000 : }
4001 1471895 : if (!used || cur_level == 0)
4002 1471814 : maybe_used_decls = p;
4003 1471895 : }
4004 :
4005 : /* Pop the stack of decls possibly used inside sizeof or typeof or _Countof or
4006 : _Generic, without acting on them, and return the pointer to the previous top
4007 : of the stack. This for use at the end of a default generic association when
4008 : it is not yet known whether the expression is used. If it later turns out
4009 : the expression is used (or treated as used before C23), restore_maybe_used
4010 : should be called on the return value followed by pop_maybe_used (true);
4011 : otherwise, the return value can be discarded. */
4012 :
4013 : struct maybe_used_decl *
4014 1207 : save_maybe_used ()
4015 : {
4016 1207 : struct maybe_used_decl *p = maybe_used_decls, *orig = p;
4017 1207 : int cur_level = in_sizeof + in_typeof + in_countof + in_generic;
4018 1239 : while (p && p->level > cur_level)
4019 32 : p = p->next;
4020 1207 : maybe_used_decls = p;
4021 1207 : return orig;
4022 : }
4023 :
4024 : /* Restore the stack of decls possibly used inside sizeof or typeof or _Countof
4025 : or _Generic returned by save_maybe_used. It is required that the stack is
4026 : at exactly the point where it was left by save_maybe_used. */
4027 :
4028 : void
4029 277 : restore_maybe_used (struct maybe_used_decl *stack)
4030 : {
4031 277 : maybe_used_decls = stack;
4032 277 : }
4033 :
4034 : /* Return the result of sizeof applied to EXPR. */
4035 :
4036 : struct c_expr
4037 313656 : c_expr_sizeof_expr (location_t loc, struct c_expr expr)
4038 : {
4039 313656 : struct c_expr ret;
4040 313656 : if (expr.value == error_mark_node)
4041 : {
4042 111 : ret.value = error_mark_node;
4043 111 : ret.original_code = ERROR_MARK;
4044 111 : ret.original_type = NULL;
4045 111 : ret.m_decimal = 0;
4046 111 : pop_maybe_used (false);
4047 : }
4048 : else
4049 : {
4050 313545 : bool expr_const_operands = true;
4051 :
4052 313545 : if (TREE_CODE (expr.value) == PARM_DECL
4053 313545 : && C_ARRAY_PARAMETER (expr.value))
4054 : {
4055 55 : auto_diagnostic_group d;
4056 55 : if (warning_at (loc, OPT_Wsizeof_array_argument,
4057 : "%<sizeof%> on array function parameter %qE will "
4058 : "return size of %qT", expr.value,
4059 55 : TREE_TYPE (expr.value)))
4060 19 : inform (DECL_SOURCE_LOCATION (expr.value), "declared here");
4061 55 : }
4062 313545 : tree folded_expr = c_fully_fold (expr.value, require_constant_value,
4063 : &expr_const_operands);
4064 313545 : ret.value = c_sizeof (loc, TREE_TYPE (folded_expr));
4065 313545 : c_last_sizeof_arg = expr.value;
4066 313545 : c_last_sizeof_loc = loc;
4067 313545 : ret.original_code = SIZEOF_EXPR;
4068 313545 : ret.original_type = NULL;
4069 313545 : ret.m_decimal = 0;
4070 313545 : if (C_TYPE_VARIABLE_SIZE (TREE_TYPE (folded_expr)))
4071 : {
4072 : /* sizeof is evaluated when given a vla (C99 6.5.3.4p2). */
4073 292 : ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
4074 : folded_expr, ret.value);
4075 292 : C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !expr_const_operands;
4076 292 : SET_EXPR_LOCATION (ret.value, loc);
4077 : }
4078 313545 : pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (folded_expr)));
4079 : }
4080 313656 : return ret;
4081 : }
4082 :
4083 : /* Return the result of sizeof applied to T, a structure for the type
4084 : name passed to sizeof (rather than the type itself). LOC is the
4085 : location of the original expression. */
4086 :
4087 : struct c_expr
4088 332542 : c_expr_sizeof_type (location_t loc, struct c_type_name *t)
4089 : {
4090 332542 : tree type;
4091 332542 : struct c_expr ret;
4092 332542 : tree type_expr = NULL_TREE;
4093 332542 : bool type_expr_const = true;
4094 332542 : type = groktypename (t, &type_expr, &type_expr_const);
4095 332542 : ret.value = c_sizeof (loc, type);
4096 332542 : c_last_sizeof_arg = type;
4097 332542 : c_last_sizeof_loc = loc;
4098 332542 : ret.original_code = SIZEOF_EXPR;
4099 332542 : ret.original_type = NULL;
4100 332542 : ret.m_decimal = 0;
4101 332542 : if (type == error_mark_node)
4102 : {
4103 5 : ret.value = error_mark_node;
4104 5 : ret.original_code = ERROR_MARK;
4105 : }
4106 : else
4107 332495 : if ((type_expr || TREE_CODE (ret.value) == INTEGER_CST)
4108 664947 : && C_TYPE_VARIABLE_SIZE (type))
4109 : {
4110 : /* If the type is a [*] array, it is a VLA but is represented as
4111 : having a size of zero. In such a case we must ensure that
4112 : the result of sizeof does not get folded to a constant by
4113 : c_fully_fold, because if the size is evaluated the result is
4114 : not constant and so constraints on zero or negative size
4115 : arrays must not be applied when this sizeof call is inside
4116 : another array declarator. */
4117 41 : if (!type_expr)
4118 16 : type_expr = integer_zero_node;
4119 41 : ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
4120 : type_expr, ret.value);
4121 41 : C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !type_expr_const;
4122 : }
4123 332542 : pop_maybe_used (type != error_mark_node
4124 332542 : ? C_TYPE_VARIABLE_SIZE (type) : false);
4125 332542 : return ret;
4126 : }
4127 :
4128 : static bool
4129 2158548 : top_array_vla_p (const_tree type)
4130 : {
4131 2158548 : if (TREE_CODE (type) != ARRAY_TYPE)
4132 : return false;
4133 :
4134 2158530 : tree d = TYPE_DOMAIN (type);
4135 :
4136 2158530 : if (!d)
4137 : return false;
4138 2064785 : if (!TYPE_MAX_VALUE (d))
4139 : return false;
4140 :
4141 1972431 : return TREE_CODE (TYPE_MAX_VALUE (d)) != INTEGER_CST
4142 1972431 : || TREE_CODE (TYPE_MIN_VALUE (d)) != INTEGER_CST;
4143 : }
4144 :
4145 : /* Return the result of countof applied to EXPR. */
4146 :
4147 : struct c_expr
4148 54 : c_expr_countof_expr (location_t loc, struct c_expr expr)
4149 : {
4150 54 : struct c_expr ret;
4151 54 : if (expr.value == error_mark_node)
4152 : {
4153 1 : ret.value = error_mark_node;
4154 1 : ret.original_code = ERROR_MARK;
4155 1 : ret.original_type = NULL;
4156 1 : ret.m_decimal = 0;
4157 1 : pop_maybe_used (false);
4158 : }
4159 : else
4160 : {
4161 53 : bool expr_const_operands = true;
4162 :
4163 53 : tree folded_expr = c_fully_fold (expr.value, require_constant_value,
4164 : &expr_const_operands);
4165 53 : ret.value = c_countof_type (loc, TREE_TYPE (folded_expr));
4166 53 : c_last_sizeof_arg = expr.value;
4167 53 : c_last_sizeof_loc = loc;
4168 53 : ret.original_code = COUNTOF_EXPR;
4169 53 : ret.original_type = NULL;
4170 53 : ret.m_decimal = 0;
4171 53 : if (top_array_vla_p (TREE_TYPE (folded_expr)))
4172 : {
4173 : /* countof is evaluated when given a vla. */
4174 11 : ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
4175 : folded_expr, ret.value);
4176 11 : C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !expr_const_operands;
4177 11 : SET_EXPR_LOCATION (ret.value, loc);
4178 : }
4179 53 : pop_maybe_used (top_array_vla_p (TREE_TYPE (folded_expr)));
4180 : }
4181 54 : return ret;
4182 : }
4183 :
4184 : /* Return the result of countof applied to T, a structure for the type
4185 : name passed to countof (rather than the type itself). LOC is the
4186 : location of the original expression. */
4187 :
4188 : struct c_expr
4189 18 : c_expr_countof_type (location_t loc, struct c_type_name *t)
4190 : {
4191 18 : tree type;
4192 18 : struct c_expr ret;
4193 18 : tree type_expr = NULL_TREE;
4194 18 : bool type_expr_const = true;
4195 18 : type = groktypename (t, &type_expr, &type_expr_const);
4196 18 : ret.value = c_countof_type (loc, type);
4197 18 : c_last_sizeof_arg = type;
4198 18 : c_last_sizeof_loc = loc;
4199 18 : ret.original_code = COUNTOF_EXPR;
4200 18 : ret.original_type = NULL;
4201 18 : ret.m_decimal = 0;
4202 18 : if (type == error_mark_node)
4203 : {
4204 0 : ret.value = error_mark_node;
4205 0 : ret.original_code = ERROR_MARK;
4206 : }
4207 : else
4208 8 : if ((type_expr || TREE_CODE (ret.value) == INTEGER_CST)
4209 22 : && top_array_vla_p (type))
4210 : {
4211 : /* If the type is a [*] array, it is a VLA but is represented as
4212 : having a size of zero. In such a case we must ensure that
4213 : the result of countof does not get folded to a constant by
4214 : c_fully_fold, because if the number of elements is evaluated
4215 : the result is not constant and so
4216 : constraints on zero or negative size arrays must not be applied
4217 : when this countof call is inside another array declarator. */
4218 6 : if (!type_expr)
4219 0 : type_expr = integer_zero_node;
4220 6 : ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
4221 : type_expr, ret.value);
4222 6 : C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !type_expr_const;
4223 : }
4224 18 : pop_maybe_used (type != error_mark_node ? top_array_vla_p (type) : false);
4225 18 : return ret;
4226 : }
4227 :
4228 : /* Return the result of maxof applied to T, a structure for the type
4229 : name passed to maxof (rather than the type itself). LOC is the
4230 : location of the original expression. */
4231 :
4232 : struct c_expr
4233 46 : c_expr_maxof_type (location_t loc, struct c_type_name *t)
4234 : {
4235 46 : tree type;
4236 46 : struct c_expr ret;
4237 46 : tree type_expr = NULL_TREE;
4238 46 : bool type_expr_const = true;
4239 46 : type = groktypename (t, &type_expr, &type_expr_const);
4240 46 : ret.value = c_maxof_type (loc, type);
4241 46 : c_last_sizeof_arg = type;
4242 46 : c_last_sizeof_loc = loc;
4243 46 : ret.original_code = MAXOF_EXPR;
4244 46 : ret.original_type = NULL;
4245 46 : ret.m_decimal = 0;
4246 46 : if (type == error_mark_node)
4247 : {
4248 0 : ret.value = error_mark_node;
4249 0 : ret.original_code = ERROR_MARK;
4250 : }
4251 46 : pop_maybe_used (type != error_mark_node);
4252 46 : return ret;
4253 : }
4254 :
4255 : /* Return the result of minof applied to T, a structure for the type
4256 : name passed to minof (rather than the type itself). LOC is the
4257 : location of the original expression. */
4258 :
4259 : struct c_expr
4260 46 : c_expr_minof_type (location_t loc, struct c_type_name *t)
4261 : {
4262 46 : tree type;
4263 46 : struct c_expr ret;
4264 46 : tree type_expr = NULL_TREE;
4265 46 : bool type_expr_const = true;
4266 46 : type = groktypename (t, &type_expr, &type_expr_const);
4267 46 : ret.value = c_minof_type (loc, type);
4268 46 : c_last_sizeof_arg = type;
4269 46 : c_last_sizeof_loc = loc;
4270 46 : ret.original_code = MINOF_EXPR;
4271 46 : ret.original_type = NULL;
4272 46 : ret.m_decimal = 0;
4273 46 : if (type == error_mark_node)
4274 : {
4275 0 : ret.value = error_mark_node;
4276 0 : ret.original_code = ERROR_MARK;
4277 : }
4278 46 : pop_maybe_used (type != error_mark_node);
4279 46 : return ret;
4280 : }
4281 :
4282 : /* Build a function call to function FUNCTION with parameters PARAMS.
4283 : The function call is at LOC.
4284 : PARAMS is a list--a chain of TREE_LIST nodes--in which the
4285 : TREE_VALUE of each node is a parameter-expression.
4286 : FUNCTION's data type may be a function type or a pointer-to-function. */
4287 :
4288 : tree
4289 0 : build_function_call (location_t loc, tree function, tree params)
4290 : {
4291 0 : vec<tree, va_gc> *v;
4292 0 : tree ret;
4293 :
4294 0 : vec_alloc (v, list_length (params));
4295 0 : for (; params; params = TREE_CHAIN (params))
4296 0 : v->quick_push (TREE_VALUE (params));
4297 0 : ret = c_build_function_call_vec (loc, vNULL, function, v, NULL);
4298 0 : vec_free (v);
4299 0 : return ret;
4300 : }
4301 :
4302 : /* Give a note about the location of the declaration of DECL,
4303 : or, failing that, a pertinent declaration for FUNCTION_EXPR. */
4304 :
4305 : static void
4306 299 : inform_declaration (tree decl, tree function_expr)
4307 : {
4308 299 : if (decl && (TREE_CODE (decl) != FUNCTION_DECL
4309 278 : || !DECL_IS_UNDECLARED_BUILTIN (decl)))
4310 207 : inform (DECL_SOURCE_LOCATION (decl), "declared here");
4311 92 : else if (function_expr)
4312 92 : switch (TREE_CODE (function_expr))
4313 : {
4314 : default:
4315 : break;
4316 13 : case COMPONENT_REF:
4317 : /* Show the decl of the pertinent field (e.g. for callback
4318 : fields in a struct. */
4319 13 : {
4320 13 : tree field_decl = TREE_OPERAND (function_expr, 1);
4321 13 : if (location_t loc = DECL_SOURCE_LOCATION (field_decl))
4322 13 : inform (loc, "declared here");
4323 : }
4324 : break;
4325 : }
4326 299 : }
4327 :
4328 :
4329 : /* Build a function call to function FUNCTION with parameters PARAMS.
4330 : If FUNCTION is the result of resolving an overloaded target built-in,
4331 : ORIG_FUNDECL is the original function decl, otherwise it is null.
4332 : ORIGTYPES, if not NULL, is a vector of types; each element is
4333 : either NULL or the original type of the corresponding element in
4334 : PARAMS. The original type may differ from TREE_TYPE of the
4335 : parameter for enums. FUNCTION's data type may be a function type
4336 : or pointer-to-function. This function changes the elements of
4337 : PARAMS. */
4338 :
4339 : tree
4340 51617962 : build_function_call_vec (location_t loc, vec<location_t> arg_loc,
4341 : tree function, vec<tree, va_gc> *params,
4342 : vec<tree, va_gc> *origtypes, tree orig_fundecl)
4343 : {
4344 51617962 : tree fntype, fundecl = NULL_TREE;
4345 51617962 : tree name = NULL_TREE, result;
4346 51617962 : tree tem;
4347 51617962 : int nargs;
4348 51617962 : tree *argarray;
4349 :
4350 :
4351 : /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
4352 51617962 : STRIP_TYPE_NOPS (function);
4353 :
4354 : /* Convert anything with function type to a pointer-to-function. */
4355 51617962 : if (TREE_CODE (function) == FUNCTION_DECL)
4356 : {
4357 51540288 : name = DECL_NAME (function);
4358 :
4359 51540288 : if (flag_tm)
4360 421 : tm_malloc_replacement (function);
4361 51540288 : fundecl = function;
4362 51540288 : if (!orig_fundecl)
4363 51540288 : orig_fundecl = fundecl;
4364 : /* Atomic functions have type checking/casting already done. They are
4365 : often rewritten and don't match the original parameter list. */
4366 103080576 : if (name && startswith (IDENTIFIER_POINTER (name), "__atomic_"))
4367 : origtypes = NULL;
4368 : }
4369 51617962 : if (TREE_CODE (TREE_TYPE (function)) == FUNCTION_TYPE)
4370 51554869 : function = function_to_pointer_conversion (loc, function);
4371 :
4372 : /* For Objective-C, convert any calls via a cast to OBJC_TYPE_REF
4373 : expressions, like those used for ObjC messenger dispatches. */
4374 51617962 : if (params && !params->is_empty ())
4375 39331213 : function = objc_rewrite_function_call (function, (*params)[0]);
4376 :
4377 51617962 : function = c_fully_fold (function, false, NULL);
4378 :
4379 51617962 : fntype = TREE_TYPE (function);
4380 :
4381 51617962 : if (TREE_CODE (fntype) == ERROR_MARK)
4382 5 : return error_mark_node;
4383 :
4384 51617957 : if (!(TREE_CODE (fntype) == POINTER_TYPE
4385 51617922 : && TREE_CODE (TREE_TYPE (fntype)) == FUNCTION_TYPE))
4386 : {
4387 38 : if (!flag_diagnostics_show_caret && !STATEMENT_CLASS_P (function))
4388 34 : error_at (loc,
4389 : "called object %qE is not a function or function pointer",
4390 : function);
4391 4 : else if (DECL_P (function))
4392 : {
4393 1 : auto_diagnostic_group d;
4394 1 : error_at (loc,
4395 : "called object %qD is not a function or function pointer",
4396 : function);
4397 1 : inform_declaration (function, NULL_TREE);
4398 1 : }
4399 : else
4400 3 : error_at (loc,
4401 : "called object is not a function or function pointer");
4402 38 : return error_mark_node;
4403 : }
4404 :
4405 51617919 : if (fundecl && TREE_THIS_VOLATILE (fundecl))
4406 383376 : current_function_returns_abnormally = 1;
4407 :
4408 : /* fntype now gets the type of function pointed to. */
4409 51617919 : fntype = TREE_TYPE (fntype);
4410 51617919 : tree return_type = TREE_TYPE (fntype);
4411 :
4412 : /* Convert the parameters to the types declared in the
4413 : function prototype, or apply default promotions. */
4414 :
4415 51617919 : nargs = convert_arguments (loc, arg_loc, fntype, params,
4416 : origtypes, function, fundecl);
4417 51617919 : if (nargs < 0)
4418 178 : return error_mark_node;
4419 :
4420 : /* Check that the function is called through a compatible prototype.
4421 : If it is not, warn. */
4422 51616826 : if (CONVERT_EXPR_P (function)
4423 931 : && TREE_CODE (tem = TREE_OPERAND (function, 0)) == ADDR_EXPR
4424 215 : && TREE_CODE (tem = TREE_OPERAND (tem, 0)) == FUNCTION_DECL
4425 51617926 : && !comptypes (fntype, TREE_TYPE (tem)))
4426 : {
4427 : /* This situation leads to run-time undefined behavior. We can't,
4428 : therefore, simply error unless we can prove that all possible
4429 : executions of the program must execute the code. */
4430 20 : warning_at (loc, 0, "function called through a non-compatible type");
4431 :
4432 20 : if (VOID_TYPE_P (return_type)
4433 20 : && TYPE_QUALS (return_type) != TYPE_UNQUALIFIED)
4434 1 : pedwarn (loc, 0,
4435 : "function with qualified void return type called");
4436 : }
4437 :
4438 51617741 : argarray = vec_safe_address (params);
4439 :
4440 : /* Check that arguments to builtin functions match the expectations. */
4441 51617741 : if (fundecl
4442 51540125 : && fndecl_built_in_p (fundecl)
4443 86004743 : && !check_builtin_function_arguments (loc, arg_loc, fundecl,
4444 : orig_fundecl, nargs, argarray))
4445 338 : return error_mark_node;
4446 :
4447 : /* Check that the arguments to the function are valid. */
4448 51617403 : bool warned_p = check_function_arguments (loc, fundecl, fntype,
4449 : nargs, argarray, &arg_loc,
4450 : comptypes);
4451 :
4452 51617403 : if (TYPE_QUALS (return_type) != TYPE_UNQUALIFIED
4453 51617403 : && !VOID_TYPE_P (return_type))
4454 11 : return_type = c_build_qualified_type (return_type, TYPE_UNQUALIFIED);
4455 51617403 : if (name != NULL_TREE
4456 103157190 : && startswith (IDENTIFIER_POINTER (name), "__builtin_"))
4457 : {
4458 33655140 : if (require_constant_value)
4459 3462 : result
4460 3462 : = fold_build_call_array_initializer_loc (loc, return_type,
4461 : function, nargs, argarray);
4462 : else
4463 33651678 : result = fold_build_call_array_loc (loc, return_type,
4464 : function, nargs, argarray);
4465 33655140 : if (TREE_CODE (result) == NOP_EXPR
4466 33655140 : && TREE_CODE (TREE_OPERAND (result, 0)) == INTEGER_CST)
4467 26542 : STRIP_TYPE_NOPS (result);
4468 : }
4469 : else
4470 17962263 : result = build_call_array_loc (loc, return_type,
4471 : function, nargs, argarray);
4472 : /* If -Wnonnull warning has been diagnosed, avoid diagnosing it again
4473 : later. */
4474 51617403 : if (warned_p && TREE_CODE (result) == CALL_EXPR)
4475 215 : suppress_warning (result, OPT_Wnonnull);
4476 :
4477 : /* In this improbable scenario, a nested function returns a VM type.
4478 : Create a TARGET_EXPR so that the call always has a LHS, much as
4479 : what the C++ FE does for functions returning non-PODs. */
4480 51617403 : if (c_type_variably_modified_p (TREE_TYPE (fntype)))
4481 : {
4482 83 : tree tmp = create_tmp_var_raw (TREE_TYPE (fntype));
4483 83 : result = build4 (TARGET_EXPR, TREE_TYPE (fntype), tmp, result,
4484 : NULL_TREE, NULL_TREE);
4485 : }
4486 :
4487 51617403 : if (VOID_TYPE_P (TREE_TYPE (result)))
4488 : {
4489 2503974 : if (TYPE_QUALS (TREE_TYPE (result)) != TYPE_UNQUALIFIED)
4490 2 : pedwarn (loc, 0,
4491 : "function with qualified void return type called");
4492 : return result;
4493 : }
4494 49113429 : return require_complete_type (loc, result);
4495 : }
4496 :
4497 : /* Like build_function_call_vec, but call also resolve_overloaded_builtin. */
4498 :
4499 : tree
4500 51617518 : c_build_function_call_vec (location_t loc, const vec<location_t> &arg_loc,
4501 : tree function, vec<tree, va_gc> *params,
4502 : vec<tree, va_gc> *origtypes)
4503 : {
4504 : /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
4505 51617529 : STRIP_TYPE_NOPS (function);
4506 :
4507 : /* Convert anything with function type to a pointer-to-function. */
4508 51617518 : if (TREE_CODE (function) == FUNCTION_DECL)
4509 : {
4510 : /* Implement type-directed function overloading for builtins.
4511 : resolve_overloaded_builtin and targetm.resolve_overloaded_builtin
4512 : handle all the type checking. The result is a complete expression
4513 : that implements this function call. */
4514 51539844 : tree tem = resolve_overloaded_builtin (loc, function, params);
4515 51539844 : if (tem)
4516 : return tem;
4517 : }
4518 51531267 : return build_function_call_vec (loc, arg_loc, function, params, origtypes);
4519 : }
4520 :
4521 : /* Helper for convert_arguments called to convert the VALue of argument
4522 : number ARGNUM from ORIGTYPE to the corresponding parameter number
4523 : PARMNUM and TYPE.
4524 : PLOC is the location where the conversion is being performed.
4525 : FUNCTION and FUNDECL are the same as in convert_arguments.
4526 : VALTYPE is the original type of VAL before the conversion and,
4527 : for EXCESS_PRECISION_EXPR, the operand of the expression.
4528 : NPC is true if VAL represents the null pointer constant (VAL itself
4529 : will have been folded to an integer constant).
4530 : RNAME is the same as FUNCTION except in Objective C when it's
4531 : the function selector.
4532 : EXCESS_PRECISION is true when VAL was originally represented
4533 : as EXCESS_PRECISION_EXPR.
4534 : WARNOPT is the same as in convert_for_assignment. */
4535 :
4536 : static tree
4537 129119460 : convert_argument (location_t ploc, tree function, tree fundecl,
4538 : tree type, tree origtype, tree val, tree valtype,
4539 : bool npc, tree rname, int parmnum, int argnum,
4540 : bool excess_precision, int warnopt)
4541 : {
4542 : /* Formal parm type is specified by a function prototype. */
4543 :
4544 129119460 : if (type == error_mark_node || !COMPLETE_TYPE_P (type))
4545 : {
4546 3 : error_at (ploc, "type of formal parameter %d is incomplete",
4547 : parmnum + 1);
4548 3 : return error_mark_node;
4549 : }
4550 :
4551 : /* Optionally warn about conversions that differ from the default
4552 : conversions. */
4553 129119457 : if (warn_traditional_conversion || warn_traditional)
4554 : {
4555 193 : if (INTEGRAL_TYPE_P (type)
4556 107 : && SCALAR_FLOAT_TYPE_P (valtype))
4557 19 : warning_at (ploc, OPT_Wtraditional_conversion,
4558 : "passing argument %d of %qE as integer rather "
4559 : "than floating due to prototype",
4560 : argnum, rname);
4561 193 : if (INTEGRAL_TYPE_P (type)
4562 107 : && TREE_CODE (valtype) == COMPLEX_TYPE)
4563 5 : warning_at (ploc, OPT_Wtraditional_conversion,
4564 : "passing argument %d of %qE as integer rather "
4565 : "than complex due to prototype",
4566 : argnum, rname);
4567 188 : else if (TREE_CODE (type) == COMPLEX_TYPE
4568 14 : && SCALAR_FLOAT_TYPE_P (valtype))
4569 7 : warning_at (ploc, OPT_Wtraditional_conversion,
4570 : "passing argument %d of %qE as complex rather "
4571 : "than floating due to prototype",
4572 : argnum, rname);
4573 181 : else if (SCALAR_FLOAT_TYPE_P (type)
4574 71 : && INTEGRAL_TYPE_P (valtype))
4575 19 : warning_at (ploc, OPT_Wtraditional_conversion,
4576 : "passing argument %d of %qE as floating rather "
4577 : "than integer due to prototype",
4578 : argnum, rname);
4579 162 : else if (TREE_CODE (type) == COMPLEX_TYPE
4580 7 : && INTEGRAL_TYPE_P (valtype))
4581 5 : warning_at (ploc, OPT_Wtraditional_conversion,
4582 : "passing argument %d of %qE as complex rather "
4583 : "than integer due to prototype",
4584 : argnum, rname);
4585 157 : else if (SCALAR_FLOAT_TYPE_P (type)
4586 52 : && TREE_CODE (valtype) == COMPLEX_TYPE)
4587 7 : warning_at (ploc, OPT_Wtraditional_conversion,
4588 : "passing argument %d of %qE as floating rather "
4589 : "than complex due to prototype",
4590 : argnum, rname);
4591 : /* ??? At some point, messages should be written about
4592 : conversions between complex types, but that's too messy
4593 : to do now. */
4594 150 : else if (SCALAR_FLOAT_TYPE_P (type)
4595 45 : && SCALAR_FLOAT_TYPE_P (valtype))
4596 : {
4597 45 : unsigned int formal_prec = TYPE_PRECISION (type);
4598 :
4599 : /* Warn if any argument is passed as `float',
4600 : since without a prototype it would be `double'. */
4601 45 : if (formal_prec == TYPE_PRECISION (float_type_node)
4602 45 : && type != dfloat32_type_node)
4603 7 : warning_at (ploc, 0,
4604 : "passing argument %d of %qE as %<float%> "
4605 : "rather than %<double%> due to prototype",
4606 : argnum, rname);
4607 :
4608 : /* Warn if mismatch between argument and prototype
4609 : for decimal float types. Warn of conversions with
4610 : binary float types and of precision narrowing due to
4611 : prototype. */
4612 38 : else if (type != valtype
4613 32 : && (type == dfloat32_type_node
4614 22 : || type == dfloat64_type_node
4615 12 : || type == dfloat128_type_node
4616 2 : || valtype == dfloat32_type_node
4617 2 : || valtype == dfloat64_type_node
4618 2 : || valtype == dfloat128_type_node)
4619 38 : && (formal_prec
4620 30 : <= TYPE_PRECISION (valtype)
4621 14 : || (type == dfloat128_type_node
4622 10 : && (valtype
4623 10 : != dfloat64_type_node
4624 8 : && (valtype
4625 : != dfloat32_type_node)))
4626 8 : || (type == dfloat64_type_node
4627 4 : && (valtype
4628 : != dfloat32_type_node))))
4629 24 : warning_at (ploc, 0,
4630 : "passing argument %d of %qE as %qT "
4631 : "rather than %qT due to prototype",
4632 : argnum, rname, type, valtype);
4633 :
4634 : }
4635 : /* Detect integer changing in width or signedness.
4636 : These warnings are only activated with
4637 : -Wtraditional-conversion, not with -Wtraditional. */
4638 105 : else if (warn_traditional_conversion
4639 105 : && INTEGRAL_TYPE_P (type)
4640 102 : && INTEGRAL_TYPE_P (valtype))
4641 : {
4642 83 : unsigned int formal_prec = TYPE_PRECISION (type);
4643 83 : tree would_have_been = default_conversion (val);
4644 83 : tree type1 = TREE_TYPE (would_have_been);
4645 :
4646 83 : if (val == error_mark_node)
4647 : /* VAL could have been of incomplete type. */;
4648 83 : else if (TREE_CODE (type) == ENUMERAL_TYPE
4649 83 : && (TYPE_MAIN_VARIANT (type)
4650 2 : == TYPE_MAIN_VARIANT (valtype)))
4651 : /* No warning if function asks for enum
4652 : and the actual arg is that enum type. */
4653 : ;
4654 81 : else if (formal_prec != TYPE_PRECISION (type1))
4655 14 : warning_at (ploc, OPT_Wtraditional_conversion,
4656 : "passing argument %d of %qE "
4657 : "with different width due to prototype",
4658 : argnum, rname);
4659 67 : else if (TYPE_UNSIGNED (type) == TYPE_UNSIGNED (type1))
4660 : ;
4661 : /* Don't complain if the formal parameter type
4662 : is an enum, because we can't tell now whether
4663 : the value was an enum--even the same enum. */
4664 32 : else if (TREE_CODE (type) == ENUMERAL_TYPE)
4665 : ;
4666 32 : else if (TREE_CODE (val) == INTEGER_CST
4667 5 : && int_fits_type_p (val, type))
4668 : /* Change in signedness doesn't matter
4669 : if a constant value is unaffected. */
4670 : ;
4671 : /* If the value is extended from a narrower
4672 : unsigned type, it doesn't matter whether we
4673 : pass it as signed or unsigned; the value
4674 : certainly is the same either way. */
4675 32 : else if (TYPE_PRECISION (valtype) < TYPE_PRECISION (type)
4676 32 : && TYPE_UNSIGNED (valtype))
4677 : ;
4678 32 : else if (TYPE_UNSIGNED (type))
4679 17 : warning_at (ploc, OPT_Wtraditional_conversion,
4680 : "passing argument %d of %qE "
4681 : "as unsigned due to prototype",
4682 : argnum, rname);
4683 : else
4684 15 : warning_at (ploc, OPT_Wtraditional_conversion,
4685 : "passing argument %d of %qE "
4686 : "as signed due to prototype",
4687 : argnum, rname);
4688 : }
4689 : }
4690 :
4691 : /* Possibly restore an EXCESS_PRECISION_EXPR for the
4692 : sake of better warnings from convert_and_check. */
4693 129119457 : if (excess_precision)
4694 380 : val = build1 (EXCESS_PRECISION_EXPR, valtype, val);
4695 :
4696 129119457 : tree parmval = convert_for_assignment (ploc, ploc, type,
4697 : val, origtype, ic_argpass,
4698 : npc, fundecl, function,
4699 : parmnum + 1, warnopt);
4700 129119457 : return parmval;
4701 : }
4702 :
4703 : /* Convert the argument expressions in the vector VALUES
4704 : to the types in the list TYPE_ARG_TYPES (FNTYPE).
4705 :
4706 : If the list is exhausted, or when an element has NULL as its type,
4707 : perform the default conversions.
4708 :
4709 : ORIGTYPES is the original types of the expressions in VALUES. This
4710 : holds the type of enum values which have been converted to integral
4711 : types. It may be NULL.
4712 :
4713 : FUNCTION is a tree for the called function. It is used only for
4714 : error messages, where it is formatted with %qE.
4715 :
4716 : This is also where warnings about wrong number of args are generated.
4717 :
4718 : ARG_LOC are locations of function arguments (if any).
4719 :
4720 : Returns the actual number of arguments processed (which may be less
4721 : than the length of VALUES in some error situations), or -1 on
4722 : failure. */
4723 :
4724 : static int
4725 51617919 : convert_arguments (location_t loc, vec<location_t> arg_loc, tree fntype,
4726 : vec<tree, va_gc> *values, vec<tree, va_gc> *origtypes,
4727 : tree function, tree fundecl)
4728 : {
4729 51617919 : tree typelist = TYPE_ARG_TYPES (fntype);
4730 51617919 : unsigned int parmnum;
4731 51617919 : bool error_args = false;
4732 51617919 : const bool type_generic = fundecl
4733 51617919 : && lookup_attribute ("type generic", TYPE_ATTRIBUTES (TREE_TYPE (fundecl)));
4734 51617919 : bool type_generic_remove_excess_precision = false;
4735 51617919 : bool type_generic_overflow_p = false;
4736 51617919 : bool type_generic_bit_query = false;
4737 51617919 : tree selector;
4738 :
4739 : /* Change pointer to function to the function itself for
4740 : diagnostics. */
4741 51617919 : if (TREE_CODE (function) == ADDR_EXPR
4742 51617919 : && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL)
4743 51542386 : function = TREE_OPERAND (function, 0);
4744 :
4745 : /* Handle an ObjC selector specially for diagnostics. */
4746 51617919 : selector = objc_message_selector ();
4747 :
4748 : /* For a call to a built-in function declared without a prototype,
4749 : set to the built-in function's argument list. */
4750 51617919 : tree builtin_typelist = NULL_TREE;
4751 :
4752 : /* For type-generic built-in functions, determine whether excess
4753 : precision should be removed (classification) or not
4754 : (comparison). */
4755 51617919 : if (fundecl
4756 51617919 : && fndecl_built_in_p (fundecl, BUILT_IN_NORMAL))
4757 : {
4758 1413730 : built_in_function code = DECL_FUNCTION_CODE (fundecl);
4759 1413730 : if (C_DECL_BUILTIN_PROTOTYPE (fundecl))
4760 : {
4761 : /* For a call to a built-in function declared without a prototype
4762 : use the types of the parameters of the internal built-in to
4763 : match those of the arguments to. */
4764 695133 : if (tree bdecl = builtin_decl_explicit (code))
4765 695133 : builtin_typelist = TYPE_ARG_TYPES (TREE_TYPE (bdecl));
4766 : }
4767 :
4768 : /* For type-generic built-in functions, determine whether excess
4769 : precision should be removed (classification) or not
4770 : (comparison). */
4771 1413730 : if (type_generic)
4772 61149 : switch (code)
4773 : {
4774 5441 : case BUILT_IN_ISFINITE:
4775 5441 : case BUILT_IN_ISINF:
4776 5441 : case BUILT_IN_ISINF_SIGN:
4777 5441 : case BUILT_IN_ISNAN:
4778 5441 : case BUILT_IN_ISNORMAL:
4779 5441 : case BUILT_IN_ISSIGNALING:
4780 5441 : case BUILT_IN_FPCLASSIFY:
4781 5441 : type_generic_remove_excess_precision = true;
4782 5441 : break;
4783 :
4784 21033 : case BUILT_IN_ADD_OVERFLOW_P:
4785 21033 : case BUILT_IN_SUB_OVERFLOW_P:
4786 21033 : case BUILT_IN_MUL_OVERFLOW_P:
4787 : /* The last argument of these type-generic builtins
4788 : should not be promoted. */
4789 21033 : type_generic_overflow_p = true;
4790 21033 : break;
4791 :
4792 1377 : case BUILT_IN_CLZG:
4793 1377 : case BUILT_IN_CTZG:
4794 1377 : case BUILT_IN_CLRSBG:
4795 1377 : case BUILT_IN_FFSG:
4796 1377 : case BUILT_IN_PARITYG:
4797 1377 : case BUILT_IN_POPCOUNTG:
4798 : /* The first argument of these type-generic builtins
4799 : should not be promoted. */
4800 1377 : type_generic_bit_query = true;
4801 1377 : break;
4802 :
4803 : default:
4804 : break;
4805 : }
4806 : }
4807 :
4808 : /* Scan the given expressions (VALUES) and types (TYPELIST), producing
4809 : individual converted arguments. */
4810 :
4811 51617919 : tree typetail, builtin_typetail, val;
4812 130058321 : for (typetail = typelist,
4813 51617919 : builtin_typetail = builtin_typelist,
4814 51617919 : parmnum = 0;
4815 181676240 : values && values->iterate (parmnum, &val);
4816 : ++parmnum)
4817 : {
4818 : /* The type of the function parameter (if it was declared with one). */
4819 259175931 : tree type = typetail ? TREE_VALUE (typetail) : NULL_TREE;
4820 : /* The type of the built-in function parameter (if the function
4821 : is a built-in). Used to detect type incompatibilities in
4822 : calls to built-ins declared without a prototype. */
4823 130058357 : tree builtin_type = (builtin_typetail
4824 131100174 : ? TREE_VALUE (builtin_typetail) : NULL_TREE);
4825 : /* The original type of the argument being passed to the function. */
4826 130058357 : tree valtype = TREE_TYPE (val);
4827 : /* The called function (or function selector in Objective C). */
4828 130058357 : tree rname = function;
4829 130058357 : int argnum = parmnum + 1;
4830 130058357 : const char *invalid_func_diag;
4831 : /* Set for EXCESS_PRECISION_EXPR arguments. */
4832 130058357 : bool excess_precision = false;
4833 : /* The value of the argument after conversion to the type
4834 : of the function parameter it is passed to. */
4835 130058357 : tree parmval;
4836 : /* Some __atomic_* builtins have additional hidden argument at
4837 : position 0. */
4838 130058357 : location_t ploc
4839 129788546 : = !arg_loc.is_empty () && values->length () == arg_loc.length ()
4840 129787946 : ? expansion_point_location_if_in_system_header (arg_loc[parmnum])
4841 130058357 : : input_location;
4842 :
4843 130058357 : if (type == void_type_node)
4844 : {
4845 33 : auto_diagnostic_group d;
4846 33 : int num_expected = parmnum;
4847 33 : int num_actual = values->length ();
4848 33 : gcc_rich_location rich_loc (loc);
4849 33 : if (ploc != input_location)
4850 32 : rich_loc.add_range (ploc);
4851 33 : if (selector)
4852 0 : error_at (&rich_loc,
4853 : "too many arguments to method %qE; expected %i, have %i",
4854 : selector, num_expected, num_actual);
4855 : else
4856 33 : error_at (&rich_loc,
4857 : "too many arguments to function %qE; expected %i, have %i",
4858 : function, num_expected, num_actual);
4859 33 : inform_declaration (fundecl, function);
4860 65 : return error_args ? -1 : (int) parmnum;
4861 33 : }
4862 :
4863 130058324 : if (builtin_type == void_type_node)
4864 : {
4865 12 : auto_diagnostic_group d;
4866 12 : if (warning_at (loc, OPT_Wbuiltin_declaration_mismatch,
4867 : "too many arguments to built-in function %qE "
4868 : "expecting %d", function, parmnum))
4869 12 : inform_declaration (fundecl, function);
4870 12 : builtin_typetail = NULL_TREE;
4871 12 : }
4872 :
4873 90758 : if (!typetail && parmnum == 0 && !TYPE_NO_NAMED_ARGS_STDARG_P (fntype)
4874 130148963 : && !(fundecl && fndecl_built_in_p (fundecl)))
4875 : {
4876 6961 : auto_diagnostic_group d;
4877 6961 : bool warned;
4878 6961 : if (selector)
4879 0 : warned = warning_at (loc, OPT_Wdeprecated_non_prototype,
4880 : "ISO C23 does not allow arguments"
4881 : " for method %qE declared without parameters",
4882 : function);
4883 : else
4884 6961 : warned = warning_at (loc, OPT_Wdeprecated_non_prototype,
4885 : "ISO C23 does not allow arguments"
4886 : " for function %qE declared without parameters",
4887 : function);
4888 6961 : if (warned)
4889 4 : inform_declaration (fundecl, function);
4890 6961 : }
4891 :
4892 130058324 : if (selector && argnum > 2)
4893 : {
4894 0 : rname = selector;
4895 0 : argnum -= 2;
4896 : }
4897 :
4898 : /* Determine if VAL is a null pointer constant before folding it. */
4899 130058324 : bool npc = null_pointer_constant_p (val);
4900 :
4901 : /* If there is excess precision and a prototype, convert once to
4902 : the required type rather than converting via the semantic
4903 : type. Likewise without a prototype a float value represented
4904 : as long double should be converted once to double. But for
4905 : type-generic classification functions excess precision must
4906 : be removed here. */
4907 130058324 : if (TREE_CODE (val) == EXCESS_PRECISION_EXPR
4908 433 : && (type || !type_generic || !type_generic_remove_excess_precision))
4909 : {
4910 413 : val = TREE_OPERAND (val, 0);
4911 413 : excess_precision = true;
4912 : }
4913 130058324 : val = c_fully_fold (val, false, NULL);
4914 260116649 : STRIP_TYPE_NOPS (val);
4915 :
4916 130058324 : val = require_complete_type (ploc, val);
4917 :
4918 : /* Some floating-point arguments must be promoted to double when
4919 : no type is specified by a prototype. This applies to
4920 : arguments of type float, and to architecture-specific types
4921 : (ARM __fp16), but not to _FloatN or _FloatNx types. */
4922 130058324 : bool promote_float_arg = false;
4923 130058324 : if (type == NULL_TREE
4924 940783 : && TREE_CODE (valtype) == REAL_TYPE
4925 269703 : && (TYPE_PRECISION (valtype)
4926 269703 : <= TYPE_PRECISION (double_type_node))
4927 262449 : && TYPE_MAIN_VARIANT (valtype) != double_type_node
4928 131443 : && TYPE_MAIN_VARIANT (valtype) != long_double_type_node
4929 130189767 : && !DECIMAL_FLOAT_MODE_P (TYPE_MODE (valtype)))
4930 : {
4931 : /* Promote this argument, unless it has a _FloatN or
4932 : _FloatNx type. */
4933 1028046 : promote_float_arg = true;
4934 1028046 : for (int i = 0; i < NUM_FLOATN_NX_TYPES; i++)
4935 900613 : if (TYPE_MAIN_VARIANT (valtype) == FLOATN_NX_TYPE_NODE (i))
4936 : {
4937 : promote_float_arg = false;
4938 : break;
4939 : }
4940 : /* Don't promote __bf16 either. */
4941 130710 : if (TYPE_MAIN_VARIANT (valtype) == bfloat16_type_node)
4942 129927684 : promote_float_arg = false;
4943 : }
4944 :
4945 130058324 : if (type != NULL_TREE)
4946 : {
4947 129117541 : tree origtype = (!origtypes) ? NULL_TREE : (*origtypes)[parmnum];
4948 129117541 : parmval = convert_argument (ploc, function, fundecl, type, origtype,
4949 : val, valtype, npc, rname, parmnum, argnum,
4950 : excess_precision, 0);
4951 : }
4952 : /* A NULLPTR type is just a nullptr always. */
4953 940783 : else if (TREE_CODE (TREE_TYPE (val)) == NULLPTR_TYPE)
4954 9 : parmval = omit_one_operand_loc (ploc, TREE_TYPE (val), nullptr_node, val);
4955 940774 : else if (promote_float_arg)
4956 : {
4957 127363 : if (type_generic)
4958 : parmval = val;
4959 : else
4960 : {
4961 : /* Convert `float' to `double'. */
4962 124528 : if (warn_double_promotion && !c_inhibit_evaluation_warnings)
4963 6 : warning_at (ploc, OPT_Wdouble_promotion,
4964 : "implicit conversion from %qT to %qT when passing "
4965 : "argument to function",
4966 : valtype, double_type_node);
4967 124528 : parmval = convert (double_type_node, val);
4968 : }
4969 : }
4970 813411 : else if ((excess_precision && !type_generic)
4971 813409 : || (type_generic_overflow_p && parmnum == 2)
4972 792380 : || (type_generic_bit_query && parmnum == 0))
4973 : /* A "double" argument with excess precision being passed
4974 : without a prototype or in variable arguments.
4975 : The last argument of __builtin_*_overflow_p should not be
4976 : promoted, similarly the first argument of
4977 : __builtin_{clz,ctz,clrsb,ffs,parity,popcount}g. */
4978 22402 : parmval = convert (valtype, val);
4979 1582018 : else if ((invalid_func_diag =
4980 791009 : targetm.calls.invalid_arg_for_unprototyped_fn (typelist, fundecl, val)))
4981 : {
4982 0 : error (invalid_func_diag);
4983 0 : return -1;
4984 : }
4985 791009 : else if (TREE_CODE (val) == ADDR_EXPR && reject_gcc_builtin (val))
4986 : {
4987 : return -1;
4988 : }
4989 : else
4990 : /* Convert `short' and `char' to full-size `int'. */
4991 791006 : parmval = default_conversion (val);
4992 :
4993 130058321 : (*values)[parmnum] = parmval;
4994 130058321 : if (parmval == error_mark_node)
4995 105 : error_args = true;
4996 :
4997 130058321 : if (!type && builtin_type && TREE_CODE (builtin_type) != VOID_TYPE)
4998 : {
4999 : /* For a call to a built-in function declared without a prototype,
5000 : perform the conversions from the argument to the expected type
5001 : but issue warnings rather than errors for any mismatches.
5002 : Ignore the converted argument and use the PARMVAL obtained
5003 : above by applying default conversions instead. */
5004 1919 : tree origtype = (!origtypes) ? NULL_TREE : (*origtypes)[parmnum];
5005 1919 : convert_argument (ploc, function, fundecl, builtin_type, origtype,
5006 : val, valtype, npc, rname, parmnum, argnum,
5007 : excess_precision,
5008 : OPT_Wbuiltin_declaration_mismatch);
5009 : }
5010 :
5011 130058321 : if (typetail)
5012 129117541 : typetail = TREE_CHAIN (typetail);
5013 :
5014 130058321 : if (builtin_typetail)
5015 1041800 : builtin_typetail = TREE_CHAIN (builtin_typetail);
5016 : }
5017 :
5018 90949048 : gcc_assert (parmnum == vec_safe_length (values));
5019 :
5020 102902407 : if (typetail != NULL_TREE && TREE_VALUE (typetail) != void_type_node)
5021 : {
5022 : /* Not enough args.
5023 : Determine minimum number of arguments required. */
5024 : int min_expected_num = 0;
5025 231 : bool at_least_p = false;
5026 : tree iter = typelist;
5027 386 : while (true)
5028 : {
5029 231 : if (!iter)
5030 : {
5031 : /* Variadic arguments; stop iterating. */
5032 : at_least_p = true;
5033 : break;
5034 : }
5035 222 : if (iter == void_list_node)
5036 : /* End of arguments; stop iterating. */
5037 : break;
5038 155 : ++min_expected_num;
5039 155 : iter = TREE_CHAIN (iter);
5040 : }
5041 76 : auto_diagnostic_group d;
5042 76 : int actual_num = vec_safe_length (values);
5043 143 : error_at (loc,
5044 : at_least_p
5045 : ? G_("too few arguments to function %qE; expected at least %i, have %i")
5046 : : G_("too few arguments to function %qE; expected %i, have %i"),
5047 : function, min_expected_num, actual_num);
5048 76 : inform_declaration (fundecl, function);
5049 76 : return -1;
5050 76 : }
5051 :
5052 52276619 : if (builtin_typetail && TREE_VALUE (builtin_typetail) != void_type_node)
5053 : {
5054 616 : unsigned nargs = parmnum;
5055 616 : for (tree t = builtin_typetail; t; t = TREE_CHAIN (t))
5056 428 : ++nargs;
5057 :
5058 188 : auto_diagnostic_group d;
5059 188 : if (warning_at (loc, OPT_Wbuiltin_declaration_mismatch,
5060 : "too few arguments to built-in function %qE "
5061 : "expecting %u", function, nargs - 1))
5062 173 : inform_declaration (fundecl, function);
5063 188 : }
5064 :
5065 51617807 : return error_args ? -1 : (int) parmnum;
5066 : }
5067 :
5068 : /* This is the entry point used by the parser to build unary operators
5069 : in the input. CODE, a tree_code, specifies the unary operator, and
5070 : ARG is the operand. For unary plus, the C parser currently uses
5071 : CONVERT_EXPR for code.
5072 :
5073 : LOC is the location to use for the tree generated.
5074 : */
5075 :
5076 : struct c_expr
5077 8455579 : parser_build_unary_op (location_t loc, enum tree_code code, struct c_expr arg)
5078 : {
5079 8455579 : struct c_expr result;
5080 :
5081 8455579 : result.original_code = code;
5082 8455579 : result.original_type = NULL;
5083 8455579 : result.m_decimal = 0;
5084 :
5085 8455579 : if (reject_gcc_builtin (arg.value))
5086 : {
5087 2 : result.value = error_mark_node;
5088 : }
5089 : else
5090 : {
5091 8455577 : result.value = build_unary_op (loc, code, arg.value, false);
5092 :
5093 8455577 : if (TREE_OVERFLOW_P (result.value) && !TREE_OVERFLOW_P (arg.value))
5094 5 : overflow_warning (loc, result.value, arg.value);
5095 : }
5096 :
5097 : /* We are typically called when parsing a prefix token at LOC acting on
5098 : ARG. Reflect this by updating the source range of the result to
5099 : start at LOC and end at the end of ARG. */
5100 8455579 : set_c_expr_source_range (&result,
5101 : loc, arg.get_finish ());
5102 :
5103 8455579 : return result;
5104 : }
5105 :
5106 : /* Returns true if TYPE is a character type, *not* including wchar_t. */
5107 :
5108 : bool
5109 1275013 : char_type_p (tree type)
5110 : {
5111 1275013 : return (type == char_type_node
5112 982916 : || type == unsigned_char_type_node
5113 963769 : || type == signed_char_type_node
5114 962911 : || type == char16_type_node
5115 2016388 : || type == char32_type_node);
5116 : }
5117 :
5118 : /* This is the entry point used by the parser to build binary operators
5119 : in the input. CODE, a tree_code, specifies the binary operator, and
5120 : ARG1 and ARG2 are the operands. In addition to constructing the
5121 : expression, we check for operands that were written with other binary
5122 : operators in a way that is likely to confuse the user. ORIG_ARG1 is
5123 : the original first operand for TRUTH_{AND,OR}IF_EXPR before it is
5124 : converted to truth value, otherwise NULL_TREE.
5125 :
5126 : LOCATION is the location of the binary operator. */
5127 :
5128 : struct c_expr
5129 9402736 : parser_build_binary_op (location_t location, enum tree_code code,
5130 : struct c_expr arg1, struct c_expr arg2, tree orig_arg1)
5131 : {
5132 9402736 : struct c_expr result;
5133 9402736 : result.m_decimal = 0;
5134 :
5135 9402736 : enum tree_code code1 = arg1.original_code;
5136 9402736 : enum tree_code code2 = arg2.original_code;
5137 9402736 : tree type1 = (arg1.original_type
5138 9402736 : ? arg1.original_type
5139 6032588 : : TREE_TYPE (arg1.value));
5140 9402736 : tree type2 = (arg2.original_type
5141 9402736 : ? arg2.original_type
5142 6938367 : : TREE_TYPE (arg2.value));
5143 :
5144 9402736 : result.value = build_binary_op (location, code,
5145 : arg1.value, arg2.value, true);
5146 9402735 : result.original_code = code;
5147 9402735 : result.original_type = NULL;
5148 9402735 : result.m_decimal = 0;
5149 :
5150 9402735 : if (TREE_CODE (result.value) == ERROR_MARK)
5151 : {
5152 1297 : set_c_expr_source_range (&result,
5153 : arg1.get_start (),
5154 : arg2.get_finish ());
5155 1297 : return result;
5156 : }
5157 :
5158 9401438 : if (location != UNKNOWN_LOCATION)
5159 9401438 : protected_set_expr_location (result.value, location);
5160 :
5161 9401438 : set_c_expr_source_range (&result,
5162 : arg1.get_start (),
5163 : arg2.get_finish ());
5164 :
5165 : /* Check for cases such as x+y<<z which users are likely
5166 : to misinterpret. */
5167 9401438 : if (warn_parentheses)
5168 2013771 : warn_about_parentheses (location, code, code1, arg1.value, code2,
5169 : arg2.value);
5170 :
5171 9401438 : if (warn_logical_op)
5172 340 : warn_logical_operator (location, code, TREE_TYPE (result.value),
5173 : code1, arg1.value, code2, arg2.value);
5174 :
5175 9401438 : if (warn_constant_logical_operand
5176 2012186 : && (code == TRUTH_ANDIF_EXPR || code == TRUTH_ORIF_EXPR)
5177 74718 : && INTEGRAL_NB_TYPE_P (type1)
5178 72897 : && INTEGRAL_NB_TYPE_P (type2))
5179 : {
5180 71300 : const char *name = code == TRUTH_ANDIF_EXPR ? "&&" : "||";
5181 71300 : if (orig_arg1 == NULL_TREE)
5182 0 : orig_arg1 = arg1.value;
5183 76693 : auto enum_other_than_0_1 = [] (tree type) {
5184 5393 : if (TREE_CODE (type) != ENUMERAL_TYPE)
5185 : return false;
5186 48 : for (tree l = TYPE_VALUES (type); l; l = TREE_CHAIN (l))
5187 : {
5188 40 : tree v = DECL_INITIAL (TREE_VALUE (l));
5189 40 : if (!integer_zerop (v) && !integer_onep (v))
5190 : return true;
5191 : }
5192 : return false;
5193 : };
5194 213884 : auto diagnose_constant_logical_operand = [=] (tree val, tree type) {
5195 142584 : if (TREE_CODE (val) != INTEGER_CST || integer_zerop (val))
5196 : return false;
5197 5417 : if (integer_onep (val) && !enum_other_than_0_1 (type))
5198 : return false;
5199 32 : gcc_rich_location richloc (location);
5200 32 : richloc.add_fixit_replace (name + 1);
5201 32 : auto_diagnostic_group d;
5202 32 : if (warning_at (location, OPT_Wconstant_logical_operand,
5203 : "use of logical %qs with constant operand %qE",
5204 : name, val))
5205 32 : inform (&richloc, "use %qs for bitwise operation", name + 1);
5206 32 : return true;
5207 32 : };
5208 71300 : if (!diagnose_constant_logical_operand (arg2.value, type2))
5209 71284 : diagnose_constant_logical_operand (orig_arg1, type1);
5210 : }
5211 :
5212 9401438 : if (warn_tautological_compare)
5213 : {
5214 2012284 : tree lhs = arg1.value;
5215 2012284 : tree rhs = arg2.value;
5216 2012284 : if (TREE_CODE (lhs) == C_MAYBE_CONST_EXPR)
5217 : {
5218 2 : if (C_MAYBE_CONST_EXPR_PRE (lhs) != NULL_TREE
5219 2 : && TREE_SIDE_EFFECTS (C_MAYBE_CONST_EXPR_PRE (lhs)))
5220 : lhs = NULL_TREE;
5221 : else
5222 2 : lhs = C_MAYBE_CONST_EXPR_EXPR (lhs);
5223 : }
5224 2012284 : if (TREE_CODE (rhs) == C_MAYBE_CONST_EXPR)
5225 : {
5226 12 : if (C_MAYBE_CONST_EXPR_PRE (rhs) != NULL_TREE
5227 12 : && TREE_SIDE_EFFECTS (C_MAYBE_CONST_EXPR_PRE (rhs)))
5228 : rhs = NULL_TREE;
5229 : else
5230 12 : rhs = C_MAYBE_CONST_EXPR_EXPR (rhs);
5231 : }
5232 2012284 : if (lhs != NULL_TREE && rhs != NULL_TREE)
5233 2012284 : warn_tautological_cmp (location, code, lhs, rhs);
5234 : }
5235 :
5236 9401438 : if (warn_logical_not_paren
5237 2012367 : && TREE_CODE_CLASS (code) == tcc_comparison
5238 410647 : && code1 == TRUTH_NOT_EXPR
5239 410647 : && code2 != TRUTH_NOT_EXPR
5240 : /* Avoid warning for !!x == y. */
5241 9401572 : && (TREE_CODE (arg1.value) != NE_EXPR
5242 27 : || !integer_zerop (TREE_OPERAND (arg1.value, 1))))
5243 : {
5244 : /* Avoid warning for !b == y where b has _Bool type. */
5245 107 : tree t = integer_zero_node;
5246 107 : if (TREE_CODE (arg1.value) == EQ_EXPR
5247 98 : && integer_zerop (TREE_OPERAND (arg1.value, 1))
5248 205 : && TREE_TYPE (TREE_OPERAND (arg1.value, 0)) == integer_type_node)
5249 : {
5250 90 : t = TREE_OPERAND (arg1.value, 0);
5251 199 : do
5252 : {
5253 199 : if (TREE_TYPE (t) != integer_type_node)
5254 : break;
5255 180 : if (TREE_CODE (t) == C_MAYBE_CONST_EXPR)
5256 90 : t = C_MAYBE_CONST_EXPR_EXPR (t);
5257 90 : else if (CONVERT_EXPR_P (t))
5258 19 : t = TREE_OPERAND (t, 0);
5259 : else
5260 : break;
5261 : }
5262 : while (1);
5263 : }
5264 107 : if (!C_BOOLEAN_TYPE_P (TREE_TYPE (t)))
5265 88 : warn_logical_not_parentheses (location, code, arg1.value, arg2.value);
5266 : }
5267 :
5268 : /* Warn about comparisons against string literals, with the exception
5269 : of testing for equality or inequality of a string literal with NULL. */
5270 9401438 : if (code == EQ_EXPR || code == NE_EXPR)
5271 : {
5272 1179938 : if ((code1 == STRING_CST
5273 16 : && !integer_zerop (tree_strip_nop_conversions (arg2.value)))
5274 1179949 : || (code2 == STRING_CST
5275 39 : && !integer_zerop (tree_strip_nop_conversions (arg1.value))))
5276 36 : warning_at (location, OPT_Waddress,
5277 : "comparison with string literal results in unspecified behavior");
5278 : /* Warn for ptr == '\0', it's likely that it should've been ptr[0]. */
5279 1179938 : if (POINTER_TYPE_P (type1)
5280 92537 : && null_pointer_constant_p (arg2.value)
5281 1201273 : && char_type_p (type2))
5282 : {
5283 18 : auto_diagnostic_group d;
5284 18 : if (warning_at (location, OPT_Wpointer_compare,
5285 : "comparison between pointer and zero character "
5286 : "constant"))
5287 10 : inform (arg1.get_start (),
5288 : "did you mean to dereference the pointer?");
5289 18 : }
5290 1179920 : else if (POINTER_TYPE_P (type2)
5291 89872 : && null_pointer_constant_p (arg1.value)
5292 1180192 : && char_type_p (type1))
5293 : {
5294 10 : auto_diagnostic_group d;
5295 10 : if (warning_at (location, OPT_Wpointer_compare,
5296 : "comparison between pointer and zero character "
5297 : "constant"))
5298 10 : inform (arg2.get_start (),
5299 : "did you mean to dereference the pointer?");
5300 10 : }
5301 : }
5302 8221500 : else if (TREE_CODE_CLASS (code) == tcc_comparison
5303 1010437 : && (code1 == STRING_CST || code2 == STRING_CST))
5304 0 : warning_at (location, OPT_Waddress,
5305 : "comparison with string literal results in unspecified "
5306 : "behavior");
5307 :
5308 9401438 : if (warn_zero_as_null_pointer_constant
5309 24 : && c_inhibit_evaluation_warnings == 0
5310 24 : && TREE_CODE_CLASS (code) == tcc_comparison)
5311 : {
5312 24 : if ((TREE_CODE (type1) == POINTER_TYPE
5313 17 : || TREE_CODE (type1) == NULLPTR_TYPE)
5314 9 : && INTEGRAL_TYPE_P (type2)
5315 33 : && null_pointer_constant_p (arg2.value))
5316 9 : warning_at (arg2.get_location(), OPT_Wzero_as_null_pointer_constant,
5317 : "zero as null pointer constant");
5318 :
5319 24 : if ((TREE_CODE (type2) == POINTER_TYPE
5320 15 : || TREE_CODE (type2) == NULLPTR_TYPE)
5321 11 : && INTEGRAL_TYPE_P (type1)
5322 35 : && null_pointer_constant_p (arg1.value))
5323 11 : warning_at (arg1.get_location(), OPT_Wzero_as_null_pointer_constant,
5324 : "zero as null pointer constant");
5325 : }
5326 :
5327 9401438 : if (warn_array_compare
5328 2012122 : && TREE_CODE_CLASS (code) == tcc_comparison
5329 410432 : && TREE_CODE (type1) == ARRAY_TYPE
5330 38 : && TREE_CODE (type2) == ARRAY_TYPE)
5331 15 : do_warn_array_compare (location, code, arg1.value, arg2.value);
5332 :
5333 2201021 : if (TREE_OVERFLOW_P (result.value)
5334 299 : && !TREE_OVERFLOW_P (arg1.value)
5335 9401730 : && !TREE_OVERFLOW_P (arg2.value))
5336 249 : overflow_warning (location, result.value);
5337 :
5338 : /* Warn about comparisons of different enum types. */
5339 9401437 : if (warn_enum_compare
5340 2032246 : && TREE_CODE_CLASS (code) == tcc_comparison
5341 414973 : && TREE_CODE (type1) == ENUMERAL_TYPE
5342 7305 : && TREE_CODE (type2) == ENUMERAL_TYPE
5343 9408678 : && TYPE_MAIN_VARIANT (type1) != TYPE_MAIN_VARIANT (type2))
5344 2 : warning_at (location, OPT_Wenum_compare,
5345 : "comparison between %qT and %qT",
5346 : type1, type2);
5347 :
5348 9401437 : if (warn_xor_used_as_pow
5349 9401437 : && code == BIT_XOR_EXPR
5350 83976 : && arg1.m_decimal
5351 735 : && arg2.m_decimal)
5352 427 : check_for_xor_used_as_pow (arg1.get_location (), arg1.value,
5353 : location,
5354 : arg2.get_location (), arg2.value);
5355 :
5356 : return result;
5357 : }
5358 :
5359 : /* Return a tree for the difference of pointers OP0 and OP1.
5360 : The resulting tree has type ptrdiff_t. If POINTER_SUBTRACT sanitization is
5361 : enabled, assign to INSTRUMENT_EXPR call to libsanitizer. */
5362 :
5363 : static tree
5364 3753 : pointer_diff (location_t loc, tree op0, tree op1, tree *instrument_expr)
5365 : {
5366 3753 : tree restype = ptrdiff_type_node;
5367 3753 : tree result, inttype;
5368 :
5369 3753 : addr_space_t as0 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (op0)));
5370 3753 : addr_space_t as1 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (op1)));
5371 3753 : tree target_type = TREE_TYPE (TREE_TYPE (op0));
5372 3753 : tree orig_op0 = op0;
5373 3753 : tree orig_op1 = op1;
5374 :
5375 : /* If the operands point into different address spaces, we need to
5376 : explicitly convert them to pointers into the common address space
5377 : before we can subtract the numerical address values. */
5378 3753 : if (as0 != as1)
5379 : {
5380 0 : addr_space_t as_common;
5381 0 : tree common_type;
5382 :
5383 : /* Determine the common superset address space. This is guaranteed
5384 : to exist because the caller verified that comp_target_types
5385 : returned non-zero. */
5386 0 : if (!addr_space_superset (as0, as1, &as_common))
5387 0 : gcc_unreachable ();
5388 :
5389 0 : common_type = common_pointer_type (TREE_TYPE (op0), TREE_TYPE (op1), NULL_TREE);
5390 0 : op0 = convert (common_type, op0);
5391 0 : op1 = convert (common_type, op1);
5392 : }
5393 :
5394 : /* Determine integer type result of the subtraction. This will usually
5395 : be the same as the result type (ptrdiff_t), but may need to be a wider
5396 : type if pointers for the address space are wider than ptrdiff_t. */
5397 3753 : if (TYPE_PRECISION (restype) < TYPE_PRECISION (TREE_TYPE (op0)))
5398 0 : inttype = c_common_type_for_size (TYPE_PRECISION (TREE_TYPE (op0)), 0);
5399 : else
5400 : inttype = restype;
5401 :
5402 3753 : if (VOID_TYPE_P (target_type))
5403 150 : pedwarn (loc, OPT_Wpointer_arith,
5404 : "pointer of type %<void *%> used in subtraction");
5405 3753 : if (TREE_CODE (target_type) == FUNCTION_TYPE)
5406 4 : pedwarn (loc, OPT_Wpointer_arith,
5407 : "pointer to a function used in subtraction");
5408 :
5409 3753 : if (current_function_decl != NULL_TREE
5410 3753 : && sanitize_flags_p (SANITIZE_POINTER_SUBTRACT))
5411 : {
5412 70 : op0 = save_expr (c_fully_fold (op0, false, NULL));
5413 70 : op1 = save_expr (c_fully_fold (op1, false, NULL));
5414 :
5415 70 : tree tt = builtin_decl_explicit (BUILT_IN_ASAN_POINTER_SUBTRACT);
5416 70 : *instrument_expr = build_call_expr_loc (loc, tt, 2, op0, op1);
5417 : }
5418 :
5419 : /* First do the subtraction, then build the divide operator
5420 : and only convert at the very end.
5421 : Do not do default conversions in case restype is a short type. */
5422 :
5423 : /* POINTER_DIFF_EXPR requires a signed integer type of the same size as
5424 : pointers. If some platform cannot provide that, or has a larger
5425 : ptrdiff_type to support differences larger than half the address
5426 : space, cast the pointers to some larger integer type and do the
5427 : computations in that type. */
5428 3753 : if (TYPE_PRECISION (inttype) > TYPE_PRECISION (TREE_TYPE (op0)))
5429 0 : op0 = build_binary_op (loc, MINUS_EXPR, convert (inttype, op0),
5430 : convert (inttype, op1), false);
5431 : else
5432 : {
5433 : /* Cast away qualifiers. */
5434 3753 : op0 = convert (c_common_type (TREE_TYPE (op0), TREE_TYPE (op0)), op0);
5435 3753 : op1 = convert (c_common_type (TREE_TYPE (op1), TREE_TYPE (op1)), op1);
5436 3753 : op0 = build2_loc (loc, POINTER_DIFF_EXPR, inttype, op0, op1);
5437 : }
5438 :
5439 : /* This generates an error if op1 is pointer to incomplete type. */
5440 3753 : if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (orig_op1))))
5441 4 : error_at (loc, "arithmetic on pointer to an incomplete type");
5442 3749 : else if (verify_type_context (loc, TCTX_POINTER_ARITH,
5443 3749 : TREE_TYPE (TREE_TYPE (orig_op0))))
5444 7498 : verify_type_context (loc, TCTX_POINTER_ARITH,
5445 3749 : TREE_TYPE (TREE_TYPE (orig_op1)));
5446 :
5447 3753 : op1 = c_size_in_bytes (target_type);
5448 :
5449 3753 : if (pointer_to_zero_sized_aggr_p (TREE_TYPE (orig_op1)))
5450 4 : error_at (loc, "arithmetic on pointer to an empty aggregate");
5451 :
5452 : /* Divide by the size, in easiest possible way. */
5453 3753 : result = fold_build2_loc (loc, EXACT_DIV_EXPR, inttype,
5454 : op0, convert (inttype, op1));
5455 :
5456 : /* Convert to final result type if necessary. */
5457 3753 : return convert (restype, result);
5458 : }
5459 :
5460 : /* Expand atomic compound assignments into an appropriate sequence as
5461 : specified by the C11 standard section 6.5.16.2.
5462 :
5463 : _Atomic T1 E1
5464 : T2 E2
5465 : E1 op= E2
5466 :
5467 : This sequence is used for all types for which these operations are
5468 : supported.
5469 :
5470 : In addition, built-in versions of the 'fe' prefixed routines may
5471 : need to be invoked for floating point (real, complex or vector) when
5472 : floating-point exceptions are supported. See 6.5.16.2 footnote 113.
5473 :
5474 : T1 newval;
5475 : T1 old;
5476 : T1 *addr
5477 : T2 val
5478 : fenv_t fenv
5479 :
5480 : addr = &E1;
5481 : val = (E2);
5482 : __atomic_load (addr, &old, SEQ_CST);
5483 : feholdexcept (&fenv);
5484 : loop:
5485 : newval = old op val;
5486 : if (__atomic_compare_exchange_strong (addr, &old, &newval, SEQ_CST,
5487 : SEQ_CST))
5488 : goto done;
5489 : feclearexcept (FE_ALL_EXCEPT);
5490 : goto loop:
5491 : done:
5492 : feupdateenv (&fenv);
5493 :
5494 : The compiler will issue the __atomic_fetch_* built-in when possible,
5495 : otherwise it will generate the generic form of the atomic operations.
5496 : This requires temp(s) and has their address taken. The atomic processing
5497 : is smart enough to figure out when the size of an object can utilize
5498 : a lock-free version, and convert the built-in call to the appropriate
5499 : lock-free routine. The optimizers will then dispose of any temps that
5500 : are no longer required, and lock-free implementations are utilized as
5501 : long as there is target support for the required size.
5502 :
5503 : If the operator is NOP_EXPR, then this is a simple assignment, and
5504 : an __atomic_store is issued to perform the assignment rather than
5505 : the above loop. */
5506 :
5507 : /* Build an atomic assignment at LOC, expanding into the proper
5508 : sequence to store LHS MODIFYCODE= RHS. Return a value representing
5509 : the result of the operation, unless RETURN_OLD_P, in which case
5510 : return the old value of LHS (this is only for postincrement and
5511 : postdecrement). */
5512 :
5513 : static tree
5514 30457 : build_atomic_assign (location_t loc, tree lhs, enum tree_code modifycode,
5515 : tree rhs, bool return_old_p)
5516 : {
5517 30457 : tree fndecl, func_call;
5518 30457 : vec<tree, va_gc> *params;
5519 30457 : tree val, nonatomic_lhs_type, nonatomic_rhs_type, newval, newval_addr;
5520 30457 : tree old, old_addr;
5521 30457 : tree compound_stmt = NULL_TREE;
5522 30457 : tree stmt, goto_stmt;
5523 30457 : tree loop_label, loop_decl, done_label, done_decl;
5524 :
5525 30457 : tree lhs_type = TREE_TYPE (lhs);
5526 30457 : tree lhs_addr = build_unary_op (loc, ADDR_EXPR, lhs, false);
5527 30457 : tree seq_cst = build_int_cst (integer_type_node, MEMMODEL_SEQ_CST);
5528 30457 : tree rhs_semantic_type = TREE_TYPE (rhs);
5529 30457 : tree nonatomic_rhs_semantic_type;
5530 30457 : tree rhs_type;
5531 :
5532 30457 : gcc_assert (TYPE_ATOMIC (lhs_type));
5533 :
5534 30457 : if (return_old_p)
5535 2313 : gcc_assert (modifycode == PLUS_EXPR || modifycode == MINUS_EXPR);
5536 :
5537 : /* Allocate enough vector items for a compare_exchange. */
5538 30457 : vec_alloc (params, 6);
5539 :
5540 : /* Create a compound statement to hold the sequence of statements
5541 : with a loop. */
5542 30457 : if (modifycode != NOP_EXPR)
5543 : {
5544 19954 : compound_stmt = c_begin_compound_stmt (false);
5545 :
5546 : /* For consistency with build_modify_expr on non-_Atomic,
5547 : mark the lhs as read. Also, it would be very hard to match
5548 : such expressions in mark_exp_read. */
5549 19954 : mark_exp_read (lhs);
5550 : }
5551 :
5552 : /* Remove any excess precision (which is only present here in the
5553 : case of compound assignments). */
5554 30457 : if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
5555 : {
5556 0 : gcc_assert (modifycode != NOP_EXPR);
5557 0 : rhs = TREE_OPERAND (rhs, 0);
5558 : }
5559 30457 : rhs_type = TREE_TYPE (rhs);
5560 :
5561 : /* Fold the RHS if it hasn't already been folded. */
5562 30457 : if (modifycode != NOP_EXPR)
5563 19954 : rhs = c_fully_fold (rhs, false, NULL);
5564 :
5565 : /* Remove the qualifiers for the rest of the expressions and create
5566 : the VAL temp variable to hold the RHS. */
5567 30457 : nonatomic_lhs_type = build_qualified_type (lhs_type, TYPE_UNQUALIFIED);
5568 30457 : nonatomic_rhs_type = build_qualified_type (rhs_type, TYPE_UNQUALIFIED);
5569 30457 : nonatomic_rhs_semantic_type = build_qualified_type (rhs_semantic_type,
5570 : TYPE_UNQUALIFIED);
5571 30457 : val = create_tmp_var_raw (nonatomic_rhs_type);
5572 30457 : TREE_ADDRESSABLE (val) = 1;
5573 30457 : suppress_warning (val);
5574 30457 : rhs = build4 (TARGET_EXPR, nonatomic_rhs_type, val, rhs, NULL_TREE,
5575 : NULL_TREE);
5576 30457 : TREE_SIDE_EFFECTS (rhs) = 1;
5577 30457 : SET_EXPR_LOCATION (rhs, loc);
5578 30457 : if (modifycode != NOP_EXPR)
5579 19954 : add_stmt (rhs);
5580 :
5581 : /* NOP_EXPR indicates it's a straight store of the RHS. Simply issue
5582 : an atomic_store. */
5583 19954 : if (modifycode == NOP_EXPR)
5584 : {
5585 10503 : compound_stmt = rhs;
5586 : /* Build __atomic_store (&lhs, &val, SEQ_CST) */
5587 10503 : rhs = build_unary_op (loc, ADDR_EXPR, val, false);
5588 10503 : fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_STORE);
5589 10503 : params->quick_push (lhs_addr);
5590 10503 : params->quick_push (rhs);
5591 10503 : params->quick_push (seq_cst);
5592 10503 : func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
5593 :
5594 10503 : compound_stmt = build2 (COMPOUND_EXPR, void_type_node,
5595 : compound_stmt, func_call);
5596 :
5597 : /* VAL is the value which was stored, return a COMPOUND_STMT of
5598 : the statement and that value. */
5599 10503 : return build2 (COMPOUND_EXPR, nonatomic_lhs_type, compound_stmt, val);
5600 : }
5601 :
5602 : /* Attempt to implement the atomic operation as an __atomic_fetch_* or
5603 : __atomic_*_fetch built-in rather than a CAS loop. atomic_bool type
5604 : isn't applicable for such builtins. ??? Do we want to handle enums? */
5605 19954 : if ((TREE_CODE (lhs_type) == INTEGER_TYPE || POINTER_TYPE_P (lhs_type))
5606 13941 : && TREE_CODE (rhs_type) == INTEGER_TYPE)
5607 : {
5608 11713 : built_in_function fncode;
5609 11713 : switch (modifycode)
5610 : {
5611 3075 : case PLUS_EXPR:
5612 3075 : case POINTER_PLUS_EXPR:
5613 2124 : fncode = (return_old_p
5614 3075 : ? BUILT_IN_ATOMIC_FETCH_ADD_N
5615 : : BUILT_IN_ATOMIC_ADD_FETCH_N);
5616 : break;
5617 2889 : case MINUS_EXPR:
5618 2094 : fncode = (return_old_p
5619 2889 : ? BUILT_IN_ATOMIC_FETCH_SUB_N
5620 : : BUILT_IN_ATOMIC_SUB_FETCH_N);
5621 : break;
5622 609 : case BIT_AND_EXPR:
5623 609 : fncode = (return_old_p
5624 609 : ? BUILT_IN_ATOMIC_FETCH_AND_N
5625 : : BUILT_IN_ATOMIC_AND_FETCH_N);
5626 : break;
5627 609 : case BIT_IOR_EXPR:
5628 609 : fncode = (return_old_p
5629 609 : ? BUILT_IN_ATOMIC_FETCH_OR_N
5630 : : BUILT_IN_ATOMIC_OR_FETCH_N);
5631 : break;
5632 609 : case BIT_XOR_EXPR:
5633 609 : fncode = (return_old_p
5634 609 : ? BUILT_IN_ATOMIC_FETCH_XOR_N
5635 : : BUILT_IN_ATOMIC_XOR_FETCH_N);
5636 : break;
5637 3922 : default:
5638 3922 : goto cas_loop;
5639 : }
5640 :
5641 : /* We can only use "_1" through "_16" variants of the atomic fetch
5642 : built-ins. */
5643 7791 : unsigned HOST_WIDE_INT size = tree_to_uhwi (TYPE_SIZE_UNIT (lhs_type));
5644 7791 : if (size != 1 && size != 2 && size != 4 && size != 8 && size != 16)
5645 0 : goto cas_loop;
5646 :
5647 : /* If this is a pointer type, we need to multiply by the size of
5648 : the pointer target type. */
5649 7791 : if (POINTER_TYPE_P (lhs_type))
5650 : {
5651 1018 : if (!COMPLETE_TYPE_P (TREE_TYPE (lhs_type))
5652 : /* ??? This would introduce -Wdiscarded-qualifiers
5653 : warning: __atomic_fetch_* expect volatile void *
5654 : type as the first argument. (Assignments between
5655 : atomic and non-atomic objects are OK.) */
5656 1018 : || TYPE_RESTRICT (lhs_type))
5657 17 : goto cas_loop;
5658 1001 : tree sz = TYPE_SIZE_UNIT (TREE_TYPE (lhs_type));
5659 1001 : rhs = fold_build2_loc (loc, MULT_EXPR, ptrdiff_type_node,
5660 : convert (ptrdiff_type_node, rhs),
5661 : convert (ptrdiff_type_node, sz));
5662 : }
5663 :
5664 : /* Build __atomic_fetch_* (&lhs, &val, SEQ_CST), or
5665 : __atomic_*_fetch (&lhs, &val, SEQ_CST). */
5666 7774 : fndecl = builtin_decl_explicit (fncode);
5667 7774 : params->quick_push (lhs_addr);
5668 7774 : params->quick_push (rhs);
5669 7774 : params->quick_push (seq_cst);
5670 7774 : func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
5671 :
5672 7774 : newval = create_tmp_var_raw (nonatomic_lhs_type);
5673 7774 : TREE_ADDRESSABLE (newval) = 1;
5674 7774 : suppress_warning (newval);
5675 7774 : rhs = build4 (TARGET_EXPR, nonatomic_lhs_type, newval, func_call,
5676 : NULL_TREE, NULL_TREE);
5677 7774 : SET_EXPR_LOCATION (rhs, loc);
5678 7774 : add_stmt (rhs);
5679 :
5680 : /* Finish the compound statement. */
5681 7774 : compound_stmt = c_end_compound_stmt (loc, compound_stmt, false);
5682 :
5683 : /* NEWVAL is the value which was stored, return a COMPOUND_STMT of
5684 : the statement and that value. */
5685 7774 : return build2 (COMPOUND_EXPR, nonatomic_lhs_type, compound_stmt, newval);
5686 : }
5687 :
5688 8241 : cas_loop:
5689 : /* Create the variables and labels required for the op= form. */
5690 12180 : old = create_tmp_var_raw (nonatomic_lhs_type);
5691 12180 : old_addr = build_unary_op (loc, ADDR_EXPR, old, false);
5692 12180 : TREE_ADDRESSABLE (old) = 1;
5693 12180 : suppress_warning (old);
5694 :
5695 12180 : newval = create_tmp_var_raw (nonatomic_lhs_type);
5696 12180 : newval_addr = build_unary_op (loc, ADDR_EXPR, newval, false);
5697 12180 : TREE_ADDRESSABLE (newval) = 1;
5698 12180 : suppress_warning (newval);
5699 :
5700 12180 : loop_decl = create_artificial_label (loc);
5701 12180 : loop_label = build1 (LABEL_EXPR, void_type_node, loop_decl);
5702 :
5703 12180 : done_decl = create_artificial_label (loc);
5704 12180 : done_label = build1 (LABEL_EXPR, void_type_node, done_decl);
5705 :
5706 : /* __atomic_load (addr, &old, SEQ_CST). */
5707 12180 : fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_LOAD);
5708 12180 : params->quick_push (lhs_addr);
5709 12180 : params->quick_push (old_addr);
5710 12180 : params->quick_push (seq_cst);
5711 12180 : func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
5712 12180 : old = build4 (TARGET_EXPR, nonatomic_lhs_type, old, func_call, NULL_TREE,
5713 : NULL_TREE);
5714 12180 : add_stmt (old);
5715 12180 : params->truncate (0);
5716 :
5717 : /* Create the expressions for floating-point environment
5718 : manipulation, if required. */
5719 12180 : bool need_fenv = (flag_trapping_math
5720 12180 : && (FLOAT_TYPE_P (lhs_type) || FLOAT_TYPE_P (rhs_type)));
5721 12180 : tree hold_call = NULL_TREE, clear_call = NULL_TREE, update_call = NULL_TREE;
5722 12180 : if (need_fenv)
5723 7054 : targetm.atomic_assign_expand_fenv (&hold_call, &clear_call, &update_call);
5724 :
5725 12180 : if (hold_call)
5726 7054 : add_stmt (hold_call);
5727 :
5728 : /* loop: */
5729 12180 : add_stmt (loop_label);
5730 :
5731 : /* newval = old + val; */
5732 12180 : if (rhs_type != rhs_semantic_type)
5733 0 : val = build1 (EXCESS_PRECISION_EXPR, nonatomic_rhs_semantic_type, val);
5734 12180 : rhs = build_binary_op (loc, modifycode,
5735 : convert_lvalue_to_rvalue (loc, old, true, true),
5736 : val, true);
5737 12180 : if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
5738 : {
5739 0 : tree eptype = TREE_TYPE (rhs);
5740 0 : rhs = c_fully_fold (TREE_OPERAND (rhs, 0), false, NULL);
5741 0 : rhs = build1 (EXCESS_PRECISION_EXPR, eptype, rhs);
5742 : }
5743 : else
5744 12180 : rhs = c_fully_fold (rhs, false, NULL);
5745 12180 : rhs = convert_for_assignment (loc, UNKNOWN_LOCATION, nonatomic_lhs_type,
5746 : rhs, NULL_TREE, ic_assign, false, NULL_TREE,
5747 : NULL_TREE, 0);
5748 : /* The temporary variable for NEWVAL is only gimplified correctly (in
5749 : particular, given a DECL_CONTEXT) if used in a TARGET_EXPR. To avoid
5750 : subsequent ICEs in nested function processing after an error, ensure such
5751 : a TARGET_EXPR is built even after an error. */
5752 12180 : if (rhs == error_mark_node)
5753 10 : rhs = old;
5754 12180 : rhs = build4 (TARGET_EXPR, nonatomic_lhs_type, newval, rhs, NULL_TREE,
5755 : NULL_TREE);
5756 12180 : SET_EXPR_LOCATION (rhs, loc);
5757 12180 : add_stmt (rhs);
5758 :
5759 : /* if (__atomic_compare_exchange (addr, &old, &new, false, SEQ_CST, SEQ_CST))
5760 : goto done; */
5761 12180 : fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_COMPARE_EXCHANGE);
5762 12180 : params->quick_push (lhs_addr);
5763 12180 : params->quick_push (old_addr);
5764 12180 : params->quick_push (newval_addr);
5765 12180 : params->quick_push (integer_zero_node);
5766 12180 : params->quick_push (seq_cst);
5767 12180 : params->quick_push (seq_cst);
5768 12180 : func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
5769 :
5770 12180 : goto_stmt = build1 (GOTO_EXPR, void_type_node, done_decl);
5771 12180 : SET_EXPR_LOCATION (goto_stmt, loc);
5772 :
5773 12180 : stmt = build3 (COND_EXPR, void_type_node, func_call, goto_stmt, NULL_TREE);
5774 12180 : SET_EXPR_LOCATION (stmt, loc);
5775 12180 : add_stmt (stmt);
5776 :
5777 12180 : if (clear_call)
5778 7054 : add_stmt (clear_call);
5779 :
5780 : /* goto loop; */
5781 12180 : goto_stmt = build1 (GOTO_EXPR, void_type_node, loop_decl);
5782 12180 : SET_EXPR_LOCATION (goto_stmt, loc);
5783 12180 : add_stmt (goto_stmt);
5784 :
5785 : /* done: */
5786 12180 : add_stmt (done_label);
5787 :
5788 12180 : if (update_call)
5789 7054 : add_stmt (update_call);
5790 :
5791 : /* Finish the compound statement. */
5792 12180 : compound_stmt = c_end_compound_stmt (loc, compound_stmt, false);
5793 :
5794 : /* NEWVAL is the value that was successfully stored, return a
5795 : COMPOUND_EXPR of the statement and the appropriate value. */
5796 23787 : return build2 (COMPOUND_EXPR, nonatomic_lhs_type, compound_stmt,
5797 12180 : return_old_p ? old : newval);
5798 : }
5799 :
5800 : /* Construct and perhaps optimize a tree representation
5801 : for a unary operation. CODE, a tree_code, specifies the operation
5802 : and XARG is the operand.
5803 : For any CODE other than ADDR_EXPR, NOCONVERT suppresses the default
5804 : promotions (such as from short to int).
5805 : For ADDR_EXPR, the default promotions are not applied; NOCONVERT allows
5806 : non-lvalues; this is only used to handle conversion of non-lvalue arrays
5807 : to pointers in C99.
5808 :
5809 : LOCATION is the location of the operator. */
5810 :
5811 : tree
5812 62553086 : build_unary_op (location_t location, enum tree_code code, tree xarg,
5813 : bool noconvert)
5814 : {
5815 : /* No default_conversion here. It causes trouble for ADDR_EXPR. */
5816 62553086 : tree arg = xarg;
5817 62553086 : tree argtype = NULL_TREE;
5818 62553086 : enum tree_code typecode;
5819 62553086 : tree val;
5820 62553086 : tree ret = error_mark_node;
5821 62553086 : tree eptype = NULL_TREE;
5822 62553086 : const char *invalid_op_diag;
5823 :
5824 : /* If ARG is wrapped in a call to .ACCESS_WITH_SIZE — created when the
5825 : C parser rvalue-converts a counted_by-annotated member access (see
5826 : PR123569) — unwrap it here. Unary operators that consume an rvalue
5827 : (!, -, +) read the value itself rather than dereferencing into the
5828 : pointed-to data, so the bounds-checking wrapper is unnecessary and
5829 : would otherwise reach build_unary_op while it is not equipped to
5830 : handle the wrapped form. PR123569 fixed the ++/-- side of this by
5831 : suppressing wrapper creation in the parser; the rvalue-consuming
5832 : ops still receive the wrapper and need to strip it here. */
5833 62553086 : if (is_access_with_size_p (arg))
5834 1 : xarg = arg = get_ref_from_access_with_size (arg);
5835 :
5836 62553086 : gcc_checking_assert (!is_access_with_size_p (arg));
5837 :
5838 62553086 : bool int_operands = EXPR_INT_CONST_OPERANDS (xarg);
5839 : if (int_operands)
5840 6742535 : arg = remove_c_maybe_const_expr (arg);
5841 :
5842 62553086 : if (code != ADDR_EXPR)
5843 8834643 : arg = require_complete_type (location, arg);
5844 :
5845 62553086 : typecode = TREE_CODE (TREE_TYPE (arg));
5846 62553086 : if (typecode == ERROR_MARK)
5847 74 : return error_mark_node;
5848 62553012 : if (typecode == ENUMERAL_TYPE || typecode == BOOLEAN_TYPE)
5849 32404 : typecode = INTEGER_TYPE;
5850 :
5851 125106024 : if ((invalid_op_diag
5852 62553012 : = targetm.invalid_unary_op (code, TREE_TYPE (xarg))))
5853 : {
5854 0 : error_at (location, invalid_op_diag);
5855 0 : return error_mark_node;
5856 : }
5857 :
5858 62553012 : if (TREE_CODE (arg) == EXCESS_PRECISION_EXPR)
5859 : {
5860 245 : eptype = TREE_TYPE (arg);
5861 245 : arg = TREE_OPERAND (arg, 0);
5862 : }
5863 :
5864 62553012 : switch (code)
5865 : {
5866 28807 : case CONVERT_EXPR:
5867 : /* This is used for unary plus, because a CONVERT_EXPR
5868 : is enough to prevent anybody from looking inside for
5869 : associativity, but won't generate any code. */
5870 28812 : if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
5871 53 : || typecode == FIXED_POINT_TYPE || typecode == COMPLEX_TYPE
5872 50 : || typecode == BITINT_TYPE
5873 5 : || gnu_vector_type_p (TREE_TYPE (arg))))
5874 : {
5875 1 : error_at (location, "wrong type argument to unary plus");
5876 1 : return error_mark_node;
5877 : }
5878 28806 : else if (!noconvert)
5879 28806 : arg = default_conversion (arg);
5880 28806 : arg = non_lvalue_loc (location, arg);
5881 28806 : break;
5882 :
5883 6980600 : case NEGATE_EXPR:
5884 7430303 : if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
5885 486417 : || typecode == FIXED_POINT_TYPE || typecode == COMPLEX_TYPE
5886 455149 : || typecode == BITINT_TYPE
5887 449703 : || gnu_vector_type_p (TREE_TYPE (arg))))
5888 : {
5889 1 : error_at (location, "wrong type argument to unary minus");
5890 1 : return error_mark_node;
5891 : }
5892 6980599 : else if (!noconvert)
5893 6980589 : arg = default_conversion (arg);
5894 : break;
5895 :
5896 296837 : case BIT_NOT_EXPR:
5897 : /* ~ works on integer types and non float vectors. */
5898 296837 : if (typecode == INTEGER_TYPE
5899 296837 : || typecode == BITINT_TYPE
5900 296837 : || (gnu_vector_type_p (TREE_TYPE (arg))
5901 2132 : && !VECTOR_FLOAT_TYPE_P (TREE_TYPE (arg))))
5902 : {
5903 : tree e = arg;
5904 :
5905 : /* Warn if the expression has boolean value. */
5906 296238 : while (TREE_CODE (e) == COMPOUND_EXPR)
5907 11 : e = TREE_OPERAND (e, 1);
5908 :
5909 592438 : if ((C_BOOLEAN_TYPE_P (TREE_TYPE (arg))
5910 592438 : || truth_value_p (TREE_CODE (e))))
5911 : {
5912 149 : auto_diagnostic_group d;
5913 149 : if (warning_at (location, OPT_Wbool_operation,
5914 : "%<~%> on a boolean expression"))
5915 : {
5916 12 : gcc_rich_location richloc (location);
5917 12 : richloc.add_fixit_insert_before (location, "!");
5918 12 : inform (&richloc, "did you mean to use logical not?");
5919 12 : }
5920 149 : }
5921 296227 : if (!noconvert)
5922 296224 : arg = default_conversion (arg);
5923 : }
5924 610 : else if (typecode == COMPLEX_TYPE)
5925 : {
5926 605 : code = CONJ_EXPR;
5927 605 : pedwarn (location, OPT_Wpedantic,
5928 : "ISO C does not support %<~%> for complex conjugation");
5929 605 : if (!noconvert)
5930 605 : arg = default_conversion (arg);
5931 : }
5932 : else
5933 : {
5934 5 : error_at (location, "wrong type argument to bit-complement");
5935 5 : return error_mark_node;
5936 : }
5937 : break;
5938 :
5939 3 : case ABS_EXPR:
5940 3 : if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE))
5941 : {
5942 0 : error_at (location, "wrong type argument to abs");
5943 0 : return error_mark_node;
5944 : }
5945 3 : else if (!noconvert)
5946 0 : arg = default_conversion (arg);
5947 : break;
5948 :
5949 7 : case ABSU_EXPR:
5950 7 : if (!(typecode == INTEGER_TYPE))
5951 : {
5952 0 : error_at (location, "wrong type argument to absu");
5953 0 : return error_mark_node;
5954 : }
5955 7 : else if (!noconvert)
5956 0 : arg = default_conversion (arg);
5957 : break;
5958 :
5959 0 : case CONJ_EXPR:
5960 : /* Conjugating a real value is a no-op, but allow it anyway. */
5961 0 : if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
5962 : || typecode == COMPLEX_TYPE))
5963 : {
5964 0 : error_at (location, "wrong type argument to conjugation");
5965 0 : return error_mark_node;
5966 : }
5967 0 : else if (!noconvert)
5968 0 : arg = default_conversion (arg);
5969 : break;
5970 :
5971 378853 : case TRUTH_NOT_EXPR:
5972 378853 : if (typecode != INTEGER_TYPE && typecode != FIXED_POINT_TYPE
5973 7215 : && typecode != REAL_TYPE && typecode != POINTER_TYPE
5974 21 : && typecode != COMPLEX_TYPE && typecode != NULLPTR_TYPE
5975 18 : && typecode != BITINT_TYPE)
5976 : {
5977 10 : error_at (location,
5978 : "wrong type argument to unary exclamation mark");
5979 10 : return error_mark_node;
5980 : }
5981 378843 : if (int_operands)
5982 : {
5983 139879 : arg = c_objc_common_truthvalue_conversion (location, xarg);
5984 139879 : arg = remove_c_maybe_const_expr (arg);
5985 : }
5986 : else
5987 238964 : arg = c_objc_common_truthvalue_conversion (location, arg);
5988 378843 : ret = invert_truthvalue_loc (location, arg);
5989 : /* If the TRUTH_NOT_EXPR has been folded, reset the location. */
5990 378843 : if (EXPR_P (ret) && EXPR_HAS_LOCATION (ret))
5991 238557 : location = EXPR_LOCATION (ret);
5992 378843 : goto return_build_unary_op;
5993 :
5994 203107 : case REALPART_EXPR:
5995 203107 : case IMAGPART_EXPR:
5996 203107 : ret = build_real_imag_expr (location, code, arg);
5997 203107 : if (ret == error_mark_node)
5998 : return error_mark_node;
5999 203099 : if (eptype && TREE_CODE (eptype) == COMPLEX_TYPE)
6000 2 : eptype = TREE_TYPE (eptype);
6001 203099 : goto return_build_unary_op;
6002 :
6003 946384 : case PREINCREMENT_EXPR:
6004 946384 : case POSTINCREMENT_EXPR:
6005 946384 : case PREDECREMENT_EXPR:
6006 946384 : case POSTDECREMENT_EXPR:
6007 :
6008 946384 : if (TREE_CODE (arg) == C_MAYBE_CONST_EXPR)
6009 : {
6010 2 : tree inner = build_unary_op (location, code,
6011 2 : C_MAYBE_CONST_EXPR_EXPR (arg),
6012 : noconvert);
6013 2 : if (inner == error_mark_node)
6014 : return error_mark_node;
6015 4 : ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (inner),
6016 2 : C_MAYBE_CONST_EXPR_PRE (arg), inner);
6017 2 : gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (arg));
6018 2 : C_MAYBE_CONST_EXPR_NON_CONST (ret) = 1;
6019 2 : goto return_build_unary_op;
6020 : }
6021 :
6022 : /* Complain about anything that is not a true lvalue. In
6023 : Objective-C, skip this check for property_refs. */
6024 946382 : if (!objc_is_property_ref (arg)
6025 1892764 : && !lvalue_or_else (location,
6026 946382 : arg, ((code == PREINCREMENT_EXPR
6027 946382 : || code == POSTINCREMENT_EXPR)
6028 : ? lv_increment
6029 : : lv_decrement)))
6030 22 : return error_mark_node;
6031 :
6032 946360 : if (warn_cxx_compat && TREE_CODE (TREE_TYPE (arg)) == ENUMERAL_TYPE)
6033 : {
6034 4 : if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
6035 2 : warning_at (location, OPT_Wc___compat,
6036 : "increment of enumeration value is invalid in C++");
6037 : else
6038 2 : warning_at (location, OPT_Wc___compat,
6039 : "decrement of enumeration value is invalid in C++");
6040 : }
6041 :
6042 946360 : if (C_BOOLEAN_TYPE_P (TREE_TYPE (arg)))
6043 : {
6044 664 : if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
6045 328 : warning_at (location, OPT_Wbool_operation,
6046 : "increment of a boolean expression");
6047 : else
6048 336 : warning_at (location, OPT_Wbool_operation,
6049 : "decrement of a boolean expression");
6050 : }
6051 :
6052 : /* Ensure the argument is fully folded inside any SAVE_EXPR. */
6053 946360 : arg = c_fully_fold (arg, false, NULL, true);
6054 :
6055 946360 : bool atomic_op;
6056 946360 : atomic_op = really_atomic_lvalue (arg);
6057 :
6058 : /* Increment or decrement the real part of the value,
6059 : and don't change the imaginary part. */
6060 946360 : if (typecode == COMPLEX_TYPE)
6061 : {
6062 57 : tree real, imag;
6063 :
6064 57 : pedwarn_c23 (location, OPT_Wpedantic,
6065 : "ISO C does not support %<++%> and %<--%> on complex "
6066 : "types before C2Y");
6067 :
6068 57 : if (!atomic_op)
6069 : {
6070 53 : arg = stabilize_reference (arg);
6071 53 : real = build_unary_op (EXPR_LOCATION (arg), REALPART_EXPR, arg,
6072 : true);
6073 53 : imag = build_unary_op (EXPR_LOCATION (arg), IMAGPART_EXPR, arg,
6074 : true);
6075 53 : real = build_unary_op (EXPR_LOCATION (arg), code, real, true);
6076 53 : if (real == error_mark_node || imag == error_mark_node)
6077 : return error_mark_node;
6078 53 : ret = build2 (COMPLEX_EXPR, TREE_TYPE (arg),
6079 : real, imag);
6080 53 : goto return_build_unary_op;
6081 : }
6082 : }
6083 :
6084 : /* Report invalid types. */
6085 :
6086 946307 : if (typecode != POINTER_TYPE && typecode != FIXED_POINT_TYPE
6087 713230 : && typecode != INTEGER_TYPE && typecode != REAL_TYPE
6088 208 : && typecode != COMPLEX_TYPE && typecode != BITINT_TYPE
6089 946363 : && !gnu_vector_type_p (TREE_TYPE (arg)))
6090 : {
6091 5 : if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
6092 3 : error_at (location, "wrong type argument to increment");
6093 : else
6094 2 : error_at (location, "wrong type argument to decrement");
6095 :
6096 5 : return error_mark_node;
6097 : }
6098 :
6099 946302 : {
6100 946302 : tree inc;
6101 :
6102 946302 : argtype = TREE_TYPE (arg);
6103 :
6104 : /* Compute the increment. */
6105 :
6106 946302 : if (typecode == POINTER_TYPE)
6107 : {
6108 : /* If pointer target is an incomplete type,
6109 : we just cannot know how to do the arithmetic. */
6110 233077 : if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (argtype)))
6111 : {
6112 27 : if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
6113 17 : error_at (location,
6114 : "increment of pointer to an incomplete type %qT",
6115 17 : TREE_TYPE (argtype));
6116 : else
6117 10 : error_at (location,
6118 : "decrement of pointer to an incomplete type %qT",
6119 10 : TREE_TYPE (argtype));
6120 : }
6121 233050 : else if (TREE_CODE (TREE_TYPE (argtype)) == FUNCTION_TYPE
6122 233050 : || VOID_TYPE_P (TREE_TYPE (argtype)))
6123 : {
6124 10 : if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
6125 6 : pedwarn (location, OPT_Wpointer_arith,
6126 : "wrong type argument to increment");
6127 : else
6128 4 : pedwarn (location, OPT_Wpointer_arith,
6129 : "wrong type argument to decrement");
6130 : }
6131 : else
6132 466080 : verify_type_context (location, TCTX_POINTER_ARITH,
6133 233040 : TREE_TYPE (argtype));
6134 :
6135 233077 : inc = c_size_in_bytes (TREE_TYPE (argtype));
6136 233077 : inc = convert_to_ptrofftype_loc (location, inc);
6137 : }
6138 713225 : else if (FRACT_MODE_P (TYPE_MODE (argtype)))
6139 : {
6140 : /* For signed fract types, we invert ++ to -- or
6141 : -- to ++, and change inc from 1 to -1, because
6142 : it is not possible to represent 1 in signed fract constants.
6143 : For unsigned fract types, the result always overflows and
6144 : we get an undefined (original) or the maximum value. */
6145 0 : if (code == PREINCREMENT_EXPR)
6146 : code = PREDECREMENT_EXPR;
6147 : else if (code == PREDECREMENT_EXPR)
6148 : code = PREINCREMENT_EXPR;
6149 : else if (code == POSTINCREMENT_EXPR)
6150 : code = POSTDECREMENT_EXPR;
6151 : else /* code == POSTDECREMENT_EXPR */
6152 0 : code = POSTINCREMENT_EXPR;
6153 :
6154 0 : inc = integer_minus_one_node;
6155 0 : inc = convert (argtype, inc);
6156 : }
6157 : else
6158 : {
6159 713174 : inc = VECTOR_TYPE_P (argtype)
6160 713225 : ? build_one_cst (argtype)
6161 : : integer_one_node;
6162 713225 : inc = convert (argtype, inc);
6163 : }
6164 :
6165 : /* If 'arg' is an Objective-C PROPERTY_REF expression, then we
6166 : need to ask Objective-C to build the increment or decrement
6167 : expression for it. */
6168 946302 : if (objc_is_property_ref (arg))
6169 0 : return objc_build_incr_expr_for_property_ref (location, code,
6170 20 : arg, inc);
6171 :
6172 : /* Report a read-only lvalue. */
6173 946302 : if (TYPE_READONLY (argtype))
6174 : {
6175 20 : readonly_error (location, arg,
6176 20 : ((code == PREINCREMENT_EXPR
6177 20 : || code == POSTINCREMENT_EXPR)
6178 : ? lv_increment : lv_decrement));
6179 20 : return error_mark_node;
6180 : }
6181 946282 : else if (TREE_READONLY (arg))
6182 4 : readonly_warning (arg,
6183 4 : ((code == PREINCREMENT_EXPR
6184 4 : || code == POSTINCREMENT_EXPR)
6185 : ? lv_increment : lv_decrement));
6186 :
6187 : /* If the argument is atomic, use the special code sequences for
6188 : atomic compound assignment. */
6189 946282 : if (atomic_op)
6190 : {
6191 4469 : arg = stabilize_reference (arg);
6192 8938 : ret = build_atomic_assign (location, arg,
6193 4469 : ((code == PREINCREMENT_EXPR
6194 4469 : || code == POSTINCREMENT_EXPR)
6195 : ? PLUS_EXPR
6196 : : MINUS_EXPR),
6197 4469 : (FRACT_MODE_P (TYPE_MODE (argtype))
6198 : ? inc
6199 : : integer_one_node),
6200 : (code == POSTINCREMENT_EXPR
6201 4469 : || code == POSTDECREMENT_EXPR));
6202 946282 : goto return_build_unary_op;
6203 : }
6204 :
6205 941813 : tree true_res;
6206 941813 : if (c_hardbool_type_attr (TREE_TYPE (arg), NULL, &true_res))
6207 : {
6208 364 : tree larg = stabilize_reference (arg);
6209 364 : tree sarg = save_expr (larg);
6210 364 : switch (code)
6211 : {
6212 91 : case PREINCREMENT_EXPR:
6213 91 : val = build2 (MODIFY_EXPR, TREE_TYPE (larg), larg, true_res);
6214 91 : val = build2 (COMPOUND_EXPR, TREE_TYPE (larg), sarg, val);
6215 91 : break;
6216 91 : case POSTINCREMENT_EXPR:
6217 91 : val = build2 (MODIFY_EXPR, TREE_TYPE (larg), larg, true_res);
6218 91 : val = build2 (COMPOUND_EXPR, TREE_TYPE (larg), val, sarg);
6219 91 : val = build2 (COMPOUND_EXPR, TREE_TYPE (larg), sarg, val);
6220 91 : break;
6221 91 : case PREDECREMENT_EXPR:
6222 91 : {
6223 91 : tree rarg = convert_lvalue_to_rvalue (location, sarg,
6224 : true, true);
6225 91 : rarg = invert_truthvalue_loc (location, rarg);
6226 91 : rarg = convert (TREE_TYPE (sarg), rarg);
6227 91 : val = build2 (MODIFY_EXPR, TREE_TYPE (larg), larg, rarg);
6228 : }
6229 91 : break;
6230 91 : case POSTDECREMENT_EXPR:
6231 91 : {
6232 91 : tree rarg = convert_lvalue_to_rvalue (location, sarg,
6233 : true, true);
6234 91 : rarg = invert_truthvalue_loc (location, rarg);
6235 91 : tree iarg = convert (TREE_TYPE (larg), rarg);
6236 91 : val = build2 (MODIFY_EXPR, TREE_TYPE (larg), larg, iarg);
6237 91 : val = build2 (COMPOUND_EXPR, TREE_TYPE (larg), val, sarg);
6238 91 : val = build2 (COMPOUND_EXPR, TREE_TYPE (larg), sarg, val);
6239 : }
6240 91 : break;
6241 : default:
6242 : gcc_unreachable ();
6243 : }
6244 364 : TREE_SIDE_EFFECTS (val) = 1;
6245 : }
6246 941449 : else if (C_BOOLEAN_TYPE_P (TREE_TYPE (arg)))
6247 64 : val = boolean_increment (code, arg);
6248 : else
6249 941385 : val = build2 (code, TREE_TYPE (arg), arg, inc);
6250 941813 : TREE_SIDE_EFFECTS (val) = 1;
6251 941813 : if (TYPE_QUALS (TREE_TYPE (val)) != TYPE_UNQUALIFIED)
6252 3952 : TREE_TYPE (val) = c_build_qualified_type (TREE_TYPE (val),
6253 : TYPE_UNQUALIFIED);
6254 941813 : ret = val;
6255 941813 : goto return_build_unary_op;
6256 : }
6257 :
6258 53718402 : case ADDR_EXPR:
6259 : /* Note that this operation never does default_conversion. */
6260 :
6261 : /* The operand of unary '&' must be an lvalue (which excludes
6262 : expressions of type void), or, in C99, the result of a [] or
6263 : unary '*' operator. */
6264 53718402 : if (VOID_TYPE_P (TREE_TYPE (arg))
6265 25 : && TYPE_QUALS (TREE_TYPE (arg)) == TYPE_UNQUALIFIED
6266 53718421 : && (!INDIRECT_REF_P (arg) || !flag_isoc99))
6267 18 : pedwarn (location, 0, "taking address of expression of type %<void%>");
6268 :
6269 : /* Let &* cancel out to simplify resulting code. */
6270 53718402 : if (INDIRECT_REF_P (arg))
6271 : {
6272 : /* Don't let this be an lvalue. */
6273 22444 : if (lvalue_p (TREE_OPERAND (arg, 0)))
6274 16896 : return non_lvalue_loc (location, TREE_OPERAND (arg, 0));
6275 5548 : ret = TREE_OPERAND (arg, 0);
6276 5548 : goto return_build_unary_op;
6277 : }
6278 :
6279 : /* Anything not already handled and not a true memory reference
6280 : or a non-lvalue array is an error. */
6281 53695958 : if (typecode != FUNCTION_TYPE && !noconvert
6282 53695958 : && !lvalue_or_else (location, arg, lv_addressof))
6283 17 : return error_mark_node;
6284 :
6285 : /* Move address operations inside C_MAYBE_CONST_EXPR to simplify
6286 : folding later. */
6287 53695941 : if (TREE_CODE (arg) == C_MAYBE_CONST_EXPR)
6288 : {
6289 14 : tree inner = build_unary_op (location, code,
6290 14 : C_MAYBE_CONST_EXPR_EXPR (arg),
6291 : noconvert);
6292 28 : ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (inner),
6293 14 : C_MAYBE_CONST_EXPR_PRE (arg), inner);
6294 14 : gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (arg));
6295 14 : C_MAYBE_CONST_EXPR_NON_CONST (ret)
6296 14 : = C_MAYBE_CONST_EXPR_NON_CONST (arg);
6297 14 : goto return_build_unary_op;
6298 : }
6299 :
6300 : /* Ordinary case; arg is a COMPONENT_REF or a decl. */
6301 :
6302 53695927 : argtype = TREE_TYPE (arg);
6303 :
6304 : /* If the lvalue is const or volatile, merge that into the type
6305 : to which the address will point. This is only needed
6306 : for function types. */
6307 53695927 : if ((DECL_P (arg) || REFERENCE_CLASS_P (arg))
6308 53202936 : && (TREE_READONLY (arg) || TREE_THIS_VOLATILE (arg))
6309 84777680 : && TREE_CODE (argtype) == FUNCTION_TYPE)
6310 : {
6311 31001533 : int orig_quals = TYPE_QUALS (strip_array_types (argtype));
6312 31001533 : int quals = orig_quals;
6313 :
6314 31001533 : if (TREE_READONLY (arg))
6315 30618935 : quals |= TYPE_QUAL_CONST;
6316 31001533 : if (TREE_THIS_VOLATILE (arg))
6317 383564 : quals |= TYPE_QUAL_VOLATILE;
6318 :
6319 31001533 : argtype = c_build_qualified_type (argtype, quals);
6320 : }
6321 :
6322 53695927 : switch (TREE_CODE (arg))
6323 : {
6324 65908 : case COMPONENT_REF:
6325 65908 : if (DECL_C_BIT_FIELD (TREE_OPERAND (arg, 1)))
6326 : {
6327 8 : error_at (location, "cannot take address of bit-field %qD",
6328 8 : TREE_OPERAND (arg, 1));
6329 8 : return error_mark_node;
6330 : }
6331 :
6332 : /* fall through */
6333 :
6334 141730 : case ARRAY_REF:
6335 141730 : if (TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (TREE_OPERAND (arg, 0))))
6336 : {
6337 78 : if (!AGGREGATE_TYPE_P (TREE_TYPE (arg))
6338 7 : && !POINTER_TYPE_P (TREE_TYPE (arg))
6339 75 : && !VECTOR_TYPE_P (TREE_TYPE (arg)))
6340 : {
6341 6 : error_at (location, "cannot take address of scalar with "
6342 : "reverse storage order");
6343 6 : return error_mark_node;
6344 : }
6345 :
6346 63 : if (TREE_CODE (TREE_TYPE (arg)) == ARRAY_TYPE
6347 63 : && TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (arg)))
6348 58 : warning_at (location, OPT_Wscalar_storage_order,
6349 : "address of array with reverse scalar storage "
6350 : "order requested");
6351 : }
6352 :
6353 53695913 : default:
6354 53695913 : break;
6355 : }
6356 :
6357 53695913 : if (!c_mark_addressable (arg))
6358 20 : return error_mark_node;
6359 :
6360 53695893 : gcc_assert (TREE_CODE (arg) != COMPONENT_REF
6361 : || !DECL_C_BIT_FIELD (TREE_OPERAND (arg, 1)));
6362 :
6363 53695893 : argtype = c_build_pointer_type (argtype);
6364 :
6365 : /* ??? Cope with user tricks that amount to offsetof. Delete this
6366 : when we have proper support for integer constant expressions. */
6367 53695893 : val = get_base_address (arg);
6368 53695893 : if (val && INDIRECT_REF_P (val)
6369 53720207 : && TREE_CONSTANT (TREE_OPERAND (val, 0)))
6370 : {
6371 540 : ret = fold_offsetof (arg, argtype);
6372 540 : goto return_build_unary_op;
6373 : }
6374 :
6375 53695353 : val = build1 (ADDR_EXPR, argtype, arg);
6376 :
6377 53695353 : ret = val;
6378 53695353 : goto return_build_unary_op;
6379 :
6380 12 : case PAREN_EXPR:
6381 12 : ret = build1 (code, TREE_TYPE (arg), arg);
6382 12 : goto return_build_unary_op;
6383 :
6384 0 : default:
6385 0 : gcc_unreachable ();
6386 : }
6387 :
6388 7306247 : if (argtype == NULL_TREE)
6389 7306247 : argtype = TREE_TYPE (arg);
6390 7306247 : if (TREE_CODE (arg) == INTEGER_CST)
6391 6598313 : ret = (require_constant_value
6392 6598313 : ? fold_build1_initializer_loc (location, code, argtype, arg)
6393 6579364 : : fold_build1_loc (location, code, argtype, arg));
6394 : else
6395 707934 : ret = build1 (code, argtype, arg);
6396 62535993 : return_build_unary_op:
6397 62535993 : gcc_assert (ret != error_mark_node);
6398 6743011 : if (TREE_CODE (ret) == INTEGER_CST && !TREE_OVERFLOW (ret)
6399 69278995 : && !(TREE_CODE (xarg) == INTEGER_CST && !TREE_OVERFLOW (xarg)))
6400 562 : ret = build1 (NOP_EXPR, TREE_TYPE (ret), ret);
6401 62535431 : else if (TREE_CODE (ret) != INTEGER_CST && int_operands)
6402 74 : ret = note_integer_operands (ret);
6403 62535993 : if (eptype)
6404 245 : ret = build1 (EXCESS_PRECISION_EXPR, eptype, ret);
6405 62535993 : protected_set_expr_location (ret, location);
6406 62535993 : return ret;
6407 : }
6408 :
6409 : /* Return nonzero if REF is an lvalue valid for this language.
6410 : Lvalues can be assigned, unless their type has TYPE_READONLY.
6411 : Lvalues can have their address taken, unless they have C_DECL_REGISTER. */
6412 :
6413 : bool
6414 183342588 : lvalue_p (const_tree ref)
6415 : {
6416 184854044 : const enum tree_code code = TREE_CODE (ref);
6417 :
6418 184854044 : switch (code)
6419 : {
6420 1486463 : case REALPART_EXPR:
6421 1486463 : case IMAGPART_EXPR:
6422 1486463 : case COMPONENT_REF:
6423 1486463 : return lvalue_p (TREE_OPERAND (ref, 0));
6424 :
6425 24993 : case C_MAYBE_CONST_EXPR:
6426 24993 : return lvalue_p (TREE_OPERAND (ref, 1));
6427 :
6428 : case COMPOUND_LITERAL_EXPR:
6429 : case STRING_CST:
6430 : return true;
6431 :
6432 25752457 : case MEM_REF:
6433 25752457 : case TARGET_MEM_REF:
6434 : /* MEM_REFs can appear from -fgimple parsing or folding, so allow them
6435 : here as well. */
6436 25752457 : case INDIRECT_REF:
6437 25752457 : case ARRAY_REF:
6438 25752457 : case VAR_DECL:
6439 25752457 : case PARM_DECL:
6440 25752457 : case RESULT_DECL:
6441 25752457 : case ERROR_MARK:
6442 25752457 : return (TREE_CODE (TREE_TYPE (ref)) != FUNCTION_TYPE
6443 25752457 : && TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE);
6444 :
6445 6 : case BIND_EXPR:
6446 6 : return TREE_CODE (TREE_TYPE (ref)) == ARRAY_TYPE;
6447 :
6448 7244027 : case CALL_EXPR:
6449 7244027 : return is_access_with_size_p (ref);
6450 :
6451 : default:
6452 : return false;
6453 : }
6454 : }
6455 :
6456 : /* Give a warning for storing in something that is read-only in GCC
6457 : terms but not const in ISO C terms. */
6458 :
6459 : static void
6460 5 : readonly_warning (tree arg, enum lvalue_use use)
6461 : {
6462 5 : switch (use)
6463 : {
6464 1 : case lv_assign:
6465 1 : warning (0, "assignment of read-only location %qE", arg);
6466 1 : break;
6467 2 : case lv_increment:
6468 2 : warning (0, "increment of read-only location %qE", arg);
6469 2 : break;
6470 2 : case lv_decrement:
6471 2 : warning (0, "decrement of read-only location %qE", arg);
6472 2 : break;
6473 0 : default:
6474 0 : gcc_unreachable ();
6475 : }
6476 5 : return;
6477 : }
6478 :
6479 :
6480 : /* Return nonzero if REF is an lvalue valid for this language;
6481 : otherwise, print an error message and return zero. USE says
6482 : how the lvalue is being used and so selects the error message.
6483 : LOCATION is the location at which any error should be reported. */
6484 :
6485 : static int
6486 4764017 : lvalue_or_else (location_t loc, const_tree ref, enum lvalue_use use)
6487 : {
6488 4764017 : int win = lvalue_p (ref);
6489 :
6490 4764017 : if (!win)
6491 75 : lvalue_error (loc, use);
6492 :
6493 4764017 : return win;
6494 : }
6495 :
6496 : /* Mark EXP saying that we need to be able to take the
6497 : address of it; it should not be allocated in a register.
6498 : Returns true if successful. ARRAY_REF_P is true if this
6499 : is for ARRAY_REF construction - in that case we don't want
6500 : to look through VIEW_CONVERT_EXPR from VECTOR_TYPE to ARRAY_TYPE,
6501 : it is fine to use ARRAY_REFs for vector subscripts on vector
6502 : register variables. If OVERRIDE_REGISTER, clear DECL_REGISTER rather
6503 : than producing an error for taking the address of a register. */
6504 :
6505 : bool
6506 54247737 : c_mark_addressable (tree exp, bool array_ref_p, bool override_register)
6507 : {
6508 54247737 : tree x = exp;
6509 :
6510 54830560 : while (1)
6511 54830560 : switch (TREE_CODE (x))
6512 : {
6513 10103 : case VIEW_CONVERT_EXPR:
6514 10103 : if (array_ref_p
6515 9993 : && TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
6516 20096 : && VECTOR_TYPE_P (TREE_TYPE (TREE_OPERAND (x, 0))))
6517 : return true;
6518 110 : x = TREE_OPERAND (x, 0);
6519 110 : break;
6520 :
6521 396927 : case COMPONENT_REF:
6522 396927 : if (DECL_C_BIT_FIELD (TREE_OPERAND (x, 1)))
6523 : {
6524 6 : error ("cannot take address of bit-field %qD",
6525 3 : TREE_OPERAND (x, 1));
6526 3 : return false;
6527 : }
6528 : /* FALLTHRU */
6529 582713 : case ADDR_EXPR:
6530 582713 : case ARRAY_REF:
6531 582713 : case REALPART_EXPR:
6532 582713 : case IMAGPART_EXPR:
6533 582713 : x = TREE_OPERAND (x, 0);
6534 582713 : break;
6535 :
6536 594 : case COMPOUND_LITERAL_EXPR:
6537 594 : if (C_DECL_REGISTER (COMPOUND_LITERAL_EXPR_DECL (x)))
6538 : {
6539 16 : if (override_register)
6540 12 : DECL_REGISTER (COMPOUND_LITERAL_EXPR_DECL (x)) = 0;
6541 : else
6542 : {
6543 4 : error ("address of register compound literal requested");
6544 4 : return false;
6545 : }
6546 : }
6547 590 : TREE_ADDRESSABLE (x) = 1;
6548 590 : TREE_ADDRESSABLE (COMPOUND_LITERAL_EXPR_DECL (x)) = 1;
6549 590 : return true;
6550 :
6551 0 : case CONSTRUCTOR:
6552 0 : TREE_ADDRESSABLE (x) = 1;
6553 0 : return true;
6554 :
6555 1336656 : case VAR_DECL:
6556 1336656 : case CONST_DECL:
6557 1336656 : case PARM_DECL:
6558 1336656 : case RESULT_DECL:
6559 1336656 : if (C_DECL_REGISTER (x)
6560 1336656 : && DECL_NONLOCAL (x))
6561 : {
6562 0 : if (TREE_PUBLIC (x) || is_global_var (x))
6563 : {
6564 0 : error
6565 0 : ("global register variable %qD used in nested function", x);
6566 0 : return false;
6567 : }
6568 0 : pedwarn (input_location, 0, "register variable %qD used in nested function", x);
6569 : }
6570 1336656 : else if (C_DECL_REGISTER (x))
6571 : {
6572 73 : if (TREE_PUBLIC (x) || is_global_var (x))
6573 4 : error ("address of global register variable %qD requested", x);
6574 123 : else if (override_register && !DECL_HARD_REGISTER (x))
6575 : {
6576 54 : DECL_REGISTER (x) = 0;
6577 54 : TREE_ADDRESSABLE (x) = 1;
6578 54 : mark_decl_used (x, true);
6579 54 : return true;
6580 : }
6581 : else
6582 15 : error ("address of register variable %qD requested", x);
6583 : return false;
6584 : }
6585 :
6586 : /* FALLTHRU */
6587 53668581 : case FUNCTION_DECL:
6588 53668581 : TREE_ADDRESSABLE (x) = 1;
6589 53668581 : mark_decl_used (x, true);
6590 : /* FALLTHRU */
6591 : default:
6592 : return true;
6593 : }
6594 : }
6595 :
6596 : /* Convert EXPR to TYPE, warning about conversion problems with
6597 : constants. SEMANTIC_TYPE is the type this conversion would use
6598 : without excess precision. If SEMANTIC_TYPE is NULL, this function
6599 : is equivalent to convert_and_check. This function is a wrapper that
6600 : handles conversions that may be different than
6601 : the usual ones because of excess precision. */
6602 :
6603 : static tree
6604 23857194 : ep_convert_and_check (location_t loc, tree type, tree expr,
6605 : tree semantic_type)
6606 : {
6607 23857194 : if (TREE_TYPE (expr) == type)
6608 : return expr;
6609 :
6610 : /* For C11, integer conversions may have results with excess
6611 : precision. */
6612 2073304 : if (flag_isoc11 || !semantic_type)
6613 2073300 : return convert_and_check (loc, type, expr);
6614 :
6615 4 : if (TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE
6616 4 : && TREE_TYPE (expr) != semantic_type)
6617 : {
6618 : /* For integers, we need to check the real conversion, not
6619 : the conversion to the excess precision type. */
6620 4 : expr = convert_and_check (loc, semantic_type, expr);
6621 : }
6622 : /* Result type is the excess precision type, which should be
6623 : large enough, so do not check. */
6624 4 : return convert (type, expr);
6625 : }
6626 :
6627 : /* If EXPR refers to a built-in declared without a prototype returns
6628 : the actual type of the built-in and, if non-null, set *BLTIN to
6629 : a pointer to the built-in. Otherwise return the type of EXPR
6630 : and clear *BLTIN if non-null. */
6631 :
6632 : static tree
6633 2840928 : type_or_builtin_type (tree expr, tree *bltin = NULL)
6634 : {
6635 2840928 : tree dummy;
6636 2840928 : if (!bltin)
6637 0 : bltin = &dummy;
6638 :
6639 2840928 : *bltin = NULL_TREE;
6640 :
6641 2840928 : tree type = TREE_TYPE (expr);
6642 2840928 : if (TREE_CODE (expr) != ADDR_EXPR)
6643 : return type;
6644 :
6645 209827 : tree oper = TREE_OPERAND (expr, 0);
6646 209827 : if (!DECL_P (oper)
6647 171127 : || TREE_CODE (oper) != FUNCTION_DECL
6648 246265 : || !fndecl_built_in_p (oper, BUILT_IN_NORMAL))
6649 : return type;
6650 :
6651 2086 : built_in_function code = DECL_FUNCTION_CODE (oper);
6652 2086 : if (!C_DECL_BUILTIN_PROTOTYPE (oper))
6653 : return type;
6654 :
6655 1977 : if ((*bltin = builtin_decl_implicit (code)))
6656 991 : type = c_build_pointer_type (TREE_TYPE (*bltin));
6657 :
6658 : return type;
6659 : }
6660 :
6661 : /* Build and return a conditional expression IFEXP ? OP1 : OP2. If
6662 : IFEXP_BCP then the condition is a call to __builtin_constant_p, and
6663 : if folded to an integer constant then the unselected half may
6664 : contain arbitrary operations not normally permitted in constant
6665 : expressions. Set the location of the expression to LOC. */
6666 :
6667 : tree
6668 405251 : build_conditional_expr (location_t colon_loc, tree ifexp, bool ifexp_bcp,
6669 : tree op1, tree op1_original_type, location_t op1_loc,
6670 : tree op2, tree op2_original_type, location_t op2_loc)
6671 : {
6672 405251 : tree type1;
6673 405251 : tree type2;
6674 405251 : tree result_type = NULL;
6675 405251 : tree semantic_result_type = NULL;
6676 405251 : tree orig_op1 = op1, orig_op2 = op2;
6677 405251 : bool int_const, op1_int_operands, op2_int_operands, int_operands;
6678 405251 : bool ifexp_int_operands;
6679 405251 : tree ret;
6680 :
6681 405251 : op1_int_operands = EXPR_INT_CONST_OPERANDS (orig_op1);
6682 : if (op1_int_operands)
6683 110670 : op1 = remove_c_maybe_const_expr (op1);
6684 405251 : op2_int_operands = EXPR_INT_CONST_OPERANDS (orig_op2);
6685 : if (op2_int_operands)
6686 145865 : op2 = remove_c_maybe_const_expr (op2);
6687 405251 : ifexp_int_operands = EXPR_INT_CONST_OPERANDS (ifexp);
6688 : if (ifexp_int_operands)
6689 242689 : ifexp = remove_c_maybe_const_expr (ifexp);
6690 :
6691 : /* Promote both alternatives. */
6692 :
6693 405251 : if (TREE_CODE (TREE_TYPE (op1)) != VOID_TYPE)
6694 401327 : op1 = default_conversion (op1);
6695 405251 : if (TREE_CODE (TREE_TYPE (op2)) != VOID_TYPE)
6696 375404 : op2 = default_conversion (op2);
6697 :
6698 405251 : if (TREE_CODE (ifexp) == ERROR_MARK
6699 405182 : || TREE_CODE (TREE_TYPE (op1)) == ERROR_MARK
6700 810419 : || TREE_CODE (TREE_TYPE (op2)) == ERROR_MARK)
6701 83 : return error_mark_node;
6702 :
6703 405168 : tree bltin1 = NULL_TREE;
6704 405168 : tree bltin2 = NULL_TREE;
6705 405168 : type1 = type_or_builtin_type (op1, &bltin1);
6706 405168 : const enum tree_code code1 = TREE_CODE (type1);
6707 405168 : type2 = type_or_builtin_type (op2, &bltin2);
6708 405168 : const enum tree_code code2 = TREE_CODE (type2);
6709 :
6710 405168 : if (code1 == POINTER_TYPE && reject_gcc_builtin (op1))
6711 1 : return error_mark_node;
6712 :
6713 405167 : if (code2 == POINTER_TYPE && reject_gcc_builtin (op2))
6714 1 : return error_mark_node;
6715 :
6716 : /* C90 does not permit non-lvalue arrays in conditional expressions.
6717 : In C99 they will be pointers by now. */
6718 405166 : if (code1 == ARRAY_TYPE || code2 == ARRAY_TYPE)
6719 : {
6720 1 : error_at (colon_loc, "non-lvalue array in conditional expression");
6721 1 : return error_mark_node;
6722 : }
6723 :
6724 405165 : if ((TREE_CODE (op1) == EXCESS_PRECISION_EXPR
6725 405159 : || TREE_CODE (op2) == EXCESS_PRECISION_EXPR)
6726 7 : && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
6727 0 : || code1 == COMPLEX_TYPE || code1 == BITINT_TYPE)
6728 7 : && (code2 == INTEGER_TYPE || code2 == REAL_TYPE
6729 0 : || code2 == COMPLEX_TYPE || code2 == BITINT_TYPE))
6730 : {
6731 7 : semantic_result_type = c_common_type (type1, type2);
6732 7 : if (TREE_CODE (op1) == EXCESS_PRECISION_EXPR)
6733 : {
6734 6 : op1 = TREE_OPERAND (op1, 0);
6735 6 : type1 = TREE_TYPE (op1);
6736 6 : gcc_assert (TREE_CODE (type1) == code1);
6737 : }
6738 7 : if (TREE_CODE (op2) == EXCESS_PRECISION_EXPR)
6739 : {
6740 1 : op2 = TREE_OPERAND (op2, 0);
6741 1 : type2 = TREE_TYPE (op2);
6742 1 : gcc_assert (TREE_CODE (type2) == code2);
6743 : }
6744 : }
6745 :
6746 405165 : if (warn_cxx_compat)
6747 : {
6748 420 : tree t1 = op1_original_type ? op1_original_type : TREE_TYPE (orig_op1);
6749 420 : tree t2 = op2_original_type ? op2_original_type : TREE_TYPE (orig_op2);
6750 :
6751 420 : if (TREE_CODE (t1) == ENUMERAL_TYPE
6752 6 : && TREE_CODE (t2) == ENUMERAL_TYPE
6753 426 : && TYPE_MAIN_VARIANT (t1) != TYPE_MAIN_VARIANT (t2))
6754 2 : warning_at (colon_loc, OPT_Wc___compat,
6755 : "different enum types in conditional is "
6756 : "invalid in C++: %qT vs %qT", t1, t2);
6757 : }
6758 :
6759 405165 : if (warn_zero_as_null_pointer_constant
6760 20 : && c_inhibit_evaluation_warnings == 0)
6761 : {
6762 20 : if ((code1 == POINTER_TYPE || code1 == NULLPTR_TYPE)
6763 20 : && INTEGRAL_TYPE_P (type2) && null_pointer_constant_p (orig_op2))
6764 5 : warning_at (op2_loc, OPT_Wzero_as_null_pointer_constant,
6765 : "zero as null pointer constant");
6766 :
6767 20 : if ((code2 == POINTER_TYPE || code2 == NULLPTR_TYPE)
6768 20 : && INTEGRAL_TYPE_P (type1) && null_pointer_constant_p (orig_op1))
6769 5 : warning_at (op1_loc, OPT_Wzero_as_null_pointer_constant,
6770 : "zero as null pointer constant");
6771 : }
6772 :
6773 : /* Quickly detect the usual case where op1 and op2 have the same type
6774 : after promotion. */
6775 405165 : if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2))
6776 : {
6777 269967 : if (type1 == type2)
6778 : result_type = type1;
6779 : else
6780 6427 : result_type = TYPE_MAIN_VARIANT (type1);
6781 : }
6782 135198 : else if ((code1 == INTEGER_TYPE || code1 == REAL_TYPE
6783 80458 : || code1 == COMPLEX_TYPE || code1 == BITINT_TYPE)
6784 54792 : && (code2 == INTEGER_TYPE || code2 == REAL_TYPE
6785 26160 : || code2 == COMPLEX_TYPE || code2 == BITINT_TYPE))
6786 : {
6787 : /* In C11, a conditional expression between a floating-point
6788 : type and an integer type should convert the integer type to
6789 : the evaluation format of the floating-point type, with
6790 : possible excess precision. */
6791 28740 : tree eptype1 = type1;
6792 28740 : tree eptype2 = type2;
6793 28740 : if (flag_isoc11)
6794 : {
6795 28427 : tree eptype;
6796 11644 : if (ANY_INTEGRAL_TYPE_P (type1)
6797 28427 : && (eptype = excess_precision_type (type2)) != NULL_TREE)
6798 : {
6799 2 : eptype2 = eptype;
6800 2 : if (!semantic_result_type)
6801 2 : semantic_result_type = c_common_type (type1, type2);
6802 : }
6803 502 : else if (ANY_INTEGRAL_TYPE_P (type2)
6804 28425 : && (eptype = excess_precision_type (type1)) != NULL_TREE)
6805 : {
6806 4626 : eptype1 = eptype;
6807 4626 : if (!semantic_result_type)
6808 4626 : semantic_result_type = c_common_type (type1, type2);
6809 : }
6810 : }
6811 28740 : result_type = c_common_type (eptype1, eptype2);
6812 28740 : if (result_type == error_mark_node)
6813 : return error_mark_node;
6814 28738 : do_warn_double_promotion (result_type, type1, type2,
6815 : "implicit conversion from %qT to %qT to "
6816 : "match other result of conditional",
6817 : colon_loc);
6818 :
6819 : /* If -Wsign-compare, warn here if type1 and type2 have
6820 : different signedness. We'll promote the signed to unsigned
6821 : and later code won't know it used to be different.
6822 : Do this check on the original types, so that explicit casts
6823 : will be considered, but default promotions won't. */
6824 28738 : if (c_inhibit_evaluation_warnings == 0)
6825 : {
6826 28547 : int unsigned_op1 = TYPE_UNSIGNED (TREE_TYPE (orig_op1));
6827 28547 : int unsigned_op2 = TYPE_UNSIGNED (TREE_TYPE (orig_op2));
6828 :
6829 28547 : if (unsigned_op1 ^ unsigned_op2)
6830 : {
6831 : /* Do not warn if the result type is signed, since the
6832 : signed type will only be chosen if it can represent
6833 : all the values of the unsigned type. */
6834 13046 : if (!TYPE_UNSIGNED (result_type))
6835 : /* OK */;
6836 : else
6837 : {
6838 12942 : bool op1_maybe_const = true;
6839 12942 : bool op2_maybe_const = true;
6840 :
6841 : /* Do not warn if the signed quantity is an
6842 : unsuffixed integer literal (or some static
6843 : constant expression involving such literals) and
6844 : it is non-negative. This warning requires the
6845 : operands to be folded for best results, so do
6846 : that folding in this case even without
6847 : warn_sign_compare to avoid warning options
6848 : possibly affecting code generation. */
6849 12942 : c_inhibit_evaluation_warnings
6850 12942 : += (ifexp == truthvalue_false_node);
6851 12942 : op1 = c_fully_fold (op1, require_constant_value,
6852 : &op1_maybe_const);
6853 12942 : c_inhibit_evaluation_warnings
6854 12942 : -= (ifexp == truthvalue_false_node);
6855 :
6856 12942 : c_inhibit_evaluation_warnings
6857 12942 : += (ifexp == truthvalue_true_node);
6858 12942 : op2 = c_fully_fold (op2, require_constant_value,
6859 : &op2_maybe_const);
6860 12942 : c_inhibit_evaluation_warnings
6861 12942 : -= (ifexp == truthvalue_true_node);
6862 :
6863 12942 : if (warn_sign_compare)
6864 : {
6865 1245 : if ((unsigned_op2
6866 685 : && tree_expr_nonnegative_p (op1))
6867 1248 : || (unsigned_op1
6868 560 : && tree_expr_nonnegative_p (op2)))
6869 : /* OK */;
6870 10 : else if (unsigned_op2)
6871 3 : warning_at (op1_loc, OPT_Wsign_compare,
6872 : "operand of %<?:%> changes signedness from "
6873 : "%qT to %qT due to unsignedness of other "
6874 3 : "operand", TREE_TYPE (orig_op1),
6875 3 : TREE_TYPE (orig_op2));
6876 : else
6877 7 : warning_at (op2_loc, OPT_Wsign_compare,
6878 : "operand of %<?:%> changes signedness from "
6879 : "%qT to %qT due to unsignedness of other "
6880 7 : "operand", TREE_TYPE (orig_op2),
6881 7 : TREE_TYPE (orig_op1));
6882 : }
6883 12942 : if (!op1_maybe_const || TREE_CODE (op1) != INTEGER_CST)
6884 7582 : op1 = c_wrap_maybe_const (op1, !op1_maybe_const);
6885 12942 : if (!op2_maybe_const || TREE_CODE (op2) != INTEGER_CST)
6886 4400 : op2 = c_wrap_maybe_const (op2, !op2_maybe_const);
6887 : }
6888 : }
6889 : }
6890 : }
6891 106458 : else if (code1 == VOID_TYPE || code2 == VOID_TYPE)
6892 : {
6893 25995 : if (code1 != VOID_TYPE || code2 != VOID_TYPE)
6894 25995 : pedwarn (colon_loc, OPT_Wpedantic,
6895 : "ISO C forbids conditional expr with only one void side");
6896 25995 : result_type = void_type_node;
6897 : }
6898 80463 : else if (code1 == POINTER_TYPE && code2 == POINTER_TYPE)
6899 : {
6900 80045 : addr_space_t as1 = TYPE_ADDR_SPACE (TREE_TYPE (type1));
6901 80045 : addr_space_t as2 = TYPE_ADDR_SPACE (TREE_TYPE (type2));
6902 80045 : addr_space_t as_common;
6903 :
6904 80045 : if (comp_target_types (colon_loc, type1, type2))
6905 : {
6906 2626 : ifexp = save_expr (ifexp);
6907 2626 : result_type = common_pointer_type (type1, type2, ifexp);
6908 : }
6909 77419 : else if (null_pointer_constant_p (orig_op1))
6910 : result_type = type2;
6911 73257 : else if (null_pointer_constant_p (orig_op2))
6912 : result_type = type1;
6913 35281 : else if (!addr_space_superset (as1, as2, &as_common))
6914 : {
6915 0 : error_at (colon_loc, "pointers to disjoint address spaces "
6916 : "used in conditional expression");
6917 0 : return error_mark_node;
6918 : }
6919 35281 : else if ((VOID_TYPE_P (TREE_TYPE (type1))
6920 326 : && !TYPE_ATOMIC (TREE_TYPE (type1)))
6921 35283 : || (VOID_TYPE_P (TREE_TYPE (type2))
6922 34910 : && !TYPE_ATOMIC (TREE_TYPE (type2))))
6923 : {
6924 35233 : tree t1 = TREE_TYPE (type1);
6925 35233 : tree t2 = TREE_TYPE (type2);
6926 35233 : if (!(VOID_TYPE_P (t1)
6927 325 : && !TYPE_ATOMIC (t1)))
6928 : {
6929 : /* roles are swapped */
6930 34909 : t1 = t2;
6931 34909 : t2 = TREE_TYPE (type1);
6932 : }
6933 35233 : tree t2_stripped = strip_array_types (t2);
6934 35233 : if ((TREE_CODE (t2) == ARRAY_TYPE)
6935 35233 : && (TYPE_QUALS (t2_stripped) & ~TYPE_QUALS (t1)))
6936 : {
6937 18 : if (!flag_isoc23)
6938 6 : warning_at (colon_loc, OPT_Wdiscarded_array_qualifiers,
6939 : "pointer to array loses qualifier "
6940 : "in conditional expression");
6941 12 : else if (warn_c11_c23_compat > 0)
6942 6 : warning_at (colon_loc, OPT_Wc11_c23_compat,
6943 : "pointer to array loses qualifier "
6944 : "in conditional expression in ISO C before C23");
6945 : }
6946 35233 : if (TREE_CODE (t2) == FUNCTION_TYPE)
6947 4 : pedwarn (colon_loc, OPT_Wpedantic,
6948 : "ISO C forbids conditional expr between "
6949 : "%<void *%> and function pointer");
6950 : /* for array, use qualifiers of element type */
6951 35233 : if (flag_isoc23)
6952 11452 : t2 = t2_stripped;
6953 35233 : result_type = c_build_pointer_type (qualify_type (t1, t2));
6954 : }
6955 : /* Objective-C pointer comparisons are a bit more lenient. */
6956 48 : else if (objc_have_common_type (type1, type2, -3, NULL_TREE))
6957 0 : result_type = objc_common_type (type1, type2);
6958 : else
6959 : {
6960 48 : int qual = ENCODE_QUAL_ADDR_SPACE (as_common);
6961 48 : enum diagnostics::kind kind = diagnostics::kind::permerror;
6962 48 : if (!flag_isoc99)
6963 : /* This downgrade to a warning ensures that -std=gnu89
6964 : -pedantic-errors does not flag these mismatches between
6965 : builtins as errors (as diagnostics::kind::permerror would)
6966 : ISO C99 and later do not have implicit function declarations,
6967 : so the mismatch cannot occur naturally there. */
6968 5 : kind = (bltin1 && bltin2
6969 5 : ? diagnostics::kind::warning
6970 : : diagnostics::kind::pedwarn);
6971 48 : if (emit_diagnostic (kind, colon_loc, OPT_Wincompatible_pointer_types,
6972 : "pointer type mismatch "
6973 : "in conditional expression"))
6974 : {
6975 46 : inform (op1_loc, "first expression has type %qT", type1);
6976 46 : inform (op2_loc, "second expression has type %qT", type2);
6977 : }
6978 48 : result_type = c_build_pointer_type
6979 48 : (c_build_qualified_type (void_type_node, qual));
6980 : }
6981 : }
6982 418 : else if (code1 == POINTER_TYPE
6983 298 : && (code2 == INTEGER_TYPE || code2 == BITINT_TYPE))
6984 : {
6985 294 : if (!null_pointer_constant_p (orig_op2))
6986 14 : permerror_opt (colon_loc, OPT_Wint_conversion,
6987 : "pointer/integer type mismatch "
6988 : "in conditional expression");
6989 : else
6990 : {
6991 280 : op2 = null_pointer_node;
6992 : }
6993 : result_type = type1;
6994 : }
6995 124 : else if (code2 == POINTER_TYPE
6996 90 : && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
6997 : {
6998 86 : if (!null_pointer_constant_p (orig_op1))
6999 14 : permerror_opt (colon_loc, OPT_Wint_conversion,
7000 : "pointer/integer type mismatch "
7001 : "in conditional expression");
7002 : else
7003 : {
7004 72 : op1 = null_pointer_node;
7005 : }
7006 : result_type = type2;
7007 : }
7008 : /* 6.5.15: "if one is a null pointer constant (other than a pointer) or has
7009 : type nullptr_t and the other is a pointer, the result type is the pointer
7010 : type." */
7011 38 : else if (code1 == NULLPTR_TYPE && code2 == POINTER_TYPE)
7012 : result_type = type2;
7013 34 : else if (code1 == POINTER_TYPE && code2 == NULLPTR_TYPE)
7014 : result_type = type1;
7015 8 : else if (RECORD_OR_UNION_TYPE_P (type1) && RECORD_OR_UNION_TYPE_P (type2)
7016 38 : && comptypes (TYPE_MAIN_VARIANT (type1),
7017 8 : TYPE_MAIN_VARIANT (type2)))
7018 8 : result_type = composite_type (TYPE_MAIN_VARIANT (type1),
7019 8 : TYPE_MAIN_VARIANT (type2));
7020 :
7021 405141 : if (!result_type)
7022 : {
7023 22 : if (flag_cond_mismatch)
7024 0 : result_type = void_type_node;
7025 : else
7026 : {
7027 22 : error_at (colon_loc, "type mismatch in conditional expression");
7028 22 : return error_mark_node;
7029 : }
7030 : }
7031 :
7032 : /* Merge const and volatile flags of the incoming types. */
7033 405141 : result_type
7034 405141 : = build_type_variant (result_type,
7035 : TYPE_READONLY (type1) || TYPE_READONLY (type2),
7036 : TYPE_VOLATILE (type1) || TYPE_VOLATILE (type2));
7037 :
7038 405141 : op1 = ep_convert_and_check (colon_loc, result_type, op1,
7039 : semantic_result_type);
7040 405141 : op2 = ep_convert_and_check (colon_loc, result_type, op2,
7041 : semantic_result_type);
7042 :
7043 405141 : if (ifexp_bcp && ifexp == truthvalue_true_node)
7044 : {
7045 10 : op2_int_operands = true;
7046 10 : op1 = c_fully_fold (op1, require_constant_value, NULL);
7047 : }
7048 59 : if (ifexp_bcp && ifexp == truthvalue_false_node)
7049 : {
7050 49 : op1_int_operands = true;
7051 49 : op2 = c_fully_fold (op2, require_constant_value, NULL);
7052 : }
7053 907341 : int_const = int_operands = (ifexp_int_operands
7054 405141 : && op1_int_operands
7055 405141 : && op2_int_operands);
7056 97059 : if (int_operands)
7057 : {
7058 97059 : int_const = ((ifexp == truthvalue_true_node
7059 58784 : && TREE_CODE (orig_op1) == INTEGER_CST
7060 58770 : && !TREE_OVERFLOW (orig_op1))
7061 97073 : || (ifexp == truthvalue_false_node
7062 38229 : && TREE_CODE (orig_op2) == INTEGER_CST
7063 38213 : && !TREE_OVERFLOW (orig_op2)));
7064 : }
7065 :
7066 : /* Need to convert condition operand into a vector mask. */
7067 405141 : if (VECTOR_TYPE_P (TREE_TYPE (ifexp)))
7068 : {
7069 0 : tree vectype = TREE_TYPE (ifexp);
7070 0 : tree elem_type = TREE_TYPE (vectype);
7071 0 : tree zero = build_int_cst (elem_type, 0);
7072 0 : tree zero_vec = build_vector_from_val (vectype, zero);
7073 0 : tree cmp_type = truth_type_for (vectype);
7074 0 : ifexp = build2 (NE_EXPR, cmp_type, ifexp, zero_vec);
7075 : }
7076 :
7077 405141 : if (int_const || (ifexp_bcp && TREE_CODE (ifexp) == INTEGER_CST))
7078 97015 : ret = fold_build3_loc (colon_loc, COND_EXPR, result_type, ifexp, op1, op2);
7079 : else
7080 : {
7081 308126 : if (int_operands)
7082 : {
7083 : /* Use c_fully_fold here, since C_MAYBE_CONST_EXPR might be
7084 : nested inside of the expression. */
7085 76 : op1 = c_fully_fold (op1, false, NULL);
7086 76 : op2 = c_fully_fold (op2, false, NULL);
7087 : }
7088 308126 : ret = build3 (COND_EXPR, result_type, ifexp, op1, op2);
7089 308126 : if (int_operands)
7090 76 : ret = note_integer_operands (ret);
7091 : }
7092 405141 : if (semantic_result_type)
7093 4635 : ret = build1 (EXCESS_PRECISION_EXPR, semantic_result_type, ret);
7094 :
7095 405141 : protected_set_expr_location (ret, colon_loc);
7096 :
7097 : /* If the OP1 and OP2 are the same and don't have side-effects,
7098 : warn here, because the COND_EXPR will be turned into OP1. */
7099 405141 : if (warn_duplicated_branches
7100 34 : && TREE_CODE (ret) == COND_EXPR
7101 405175 : && (op1 == op2 || operand_equal_p (op1, op2, OEP_ADDRESS_OF_SAME_FIELD)))
7102 13 : warning_at (EXPR_LOCATION (ret), OPT_Wduplicated_branches,
7103 : "this condition has identical branches");
7104 :
7105 : return ret;
7106 : }
7107 :
7108 : /* EXPR is an expression, location LOC, whose result is discarded.
7109 : Warn if it is a call to a nodiscard function (or a COMPOUND_EXPR
7110 : whose right-hand operand is such a call, possibly recursively). */
7111 :
7112 : static void
7113 6631260 : maybe_warn_nodiscard (location_t loc, tree expr)
7114 : {
7115 6631260 : if (VOID_TYPE_P (TREE_TYPE (expr)))
7116 : return;
7117 4004549 : while (TREE_CODE (expr) == COMPOUND_EXPR)
7118 : {
7119 52011 : expr = TREE_OPERAND (expr, 1);
7120 52011 : if (EXPR_HAS_LOCATION (expr))
7121 52011 : loc = EXPR_LOCATION (expr);
7122 : }
7123 3952538 : if (TREE_CODE (expr) != CALL_EXPR)
7124 : return;
7125 347696 : tree fn = CALL_EXPR_FN (expr);
7126 347696 : if (!fn)
7127 : return;
7128 347680 : tree attr;
7129 347680 : if (TREE_CODE (fn) == ADDR_EXPR
7130 347013 : && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL
7131 694693 : && (attr = lookup_attribute ("nodiscard",
7132 347013 : DECL_ATTRIBUTES (TREE_OPERAND (fn, 0)))))
7133 : {
7134 3 : fn = TREE_OPERAND (fn, 0);
7135 3 : tree args = TREE_VALUE (attr);
7136 3 : if (args)
7137 1 : args = TREE_VALUE (args);
7138 3 : auto_diagnostic_group d;
7139 3 : auto_urlify_attributes sentinel;
7140 3 : int warned;
7141 3 : if (args)
7142 1 : warned = warning_at (loc, OPT_Wunused_result,
7143 : "ignoring return value of %qD, declared with "
7144 : "attribute %<nodiscard%>: %E", fn, args);
7145 : else
7146 2 : warned = warning_at (loc, OPT_Wunused_result,
7147 : "ignoring return value of %qD, declared with "
7148 : "attribute %<nodiscard%>", fn);
7149 3 : if (warned)
7150 3 : inform (DECL_SOURCE_LOCATION (fn), "declared here");
7151 3 : }
7152 : else
7153 : {
7154 347677 : tree rettype = TREE_TYPE (TREE_TYPE (TREE_TYPE (fn)));
7155 347677 : attr = lookup_attribute ("nodiscard", TYPE_ATTRIBUTES (rettype));
7156 347677 : if (!attr)
7157 347665 : return;
7158 12 : tree args = TREE_VALUE (attr);
7159 12 : if (args)
7160 5 : args = TREE_VALUE (args);
7161 12 : auto_diagnostic_group d;
7162 12 : auto_urlify_attributes sentinel;
7163 12 : int warned;
7164 12 : if (args)
7165 5 : warned = warning_at (loc, OPT_Wunused_result,
7166 : "ignoring return value of type %qT, declared "
7167 : "with attribute %<nodiscard%>: %E",
7168 : rettype, args);
7169 : else
7170 7 : warned = warning_at (loc, OPT_Wunused_result,
7171 : "ignoring return value of type %qT, declared "
7172 : "with attribute %<nodiscard%>", rettype);
7173 12 : if (warned)
7174 : {
7175 12 : if (TREE_CODE (fn) == ADDR_EXPR)
7176 : {
7177 11 : fn = TREE_OPERAND (fn, 0);
7178 11 : if (TREE_CODE (fn) == FUNCTION_DECL)
7179 11 : inform (DECL_SOURCE_LOCATION (fn),
7180 : "in call to %qD, declared here", fn);
7181 : }
7182 : }
7183 12 : }
7184 : }
7185 :
7186 : /* Return a compound expression that performs two expressions and
7187 : returns the value of the second of them.
7188 :
7189 : LOC is the location of the COMPOUND_EXPR. */
7190 :
7191 : tree
7192 114303 : build_compound_expr (location_t loc, tree expr1, tree expr2)
7193 : {
7194 114303 : bool expr1_int_operands, expr2_int_operands;
7195 114303 : tree eptype = NULL_TREE;
7196 114303 : tree ret;
7197 :
7198 114303 : expr1_int_operands = EXPR_INT_CONST_OPERANDS (expr1);
7199 : if (expr1_int_operands)
7200 326 : expr1 = remove_c_maybe_const_expr (expr1);
7201 114303 : expr2_int_operands = EXPR_INT_CONST_OPERANDS (expr2);
7202 : if (expr2_int_operands)
7203 66136 : expr2 = remove_c_maybe_const_expr (expr2);
7204 :
7205 114303 : if (TREE_CODE (expr1) == EXCESS_PRECISION_EXPR)
7206 0 : expr1 = TREE_OPERAND (expr1, 0);
7207 114303 : if (TREE_CODE (expr2) == EXCESS_PRECISION_EXPR)
7208 : {
7209 1 : eptype = TREE_TYPE (expr2);
7210 1 : expr2 = TREE_OPERAND (expr2, 0);
7211 : }
7212 :
7213 114303 : if (!TREE_SIDE_EFFECTS (expr1))
7214 : {
7215 : /* The left-hand operand of a comma expression is like an expression
7216 : statement: with -Wunused, we should warn if it doesn't have
7217 : any side-effects, unless it was explicitly cast to (void). */
7218 8455 : if (warn_unused_value)
7219 : {
7220 1284 : if (VOID_TYPE_P (TREE_TYPE (expr1))
7221 1284 : && CONVERT_EXPR_P (expr1))
7222 : ; /* (void) a, b */
7223 14 : else if (VOID_TYPE_P (TREE_TYPE (expr1))
7224 4 : && TREE_CODE (expr1) == COMPOUND_EXPR
7225 17 : && CONVERT_EXPR_P (TREE_OPERAND (expr1, 1)))
7226 : ; /* (void) a, (void) b, c */
7227 : else
7228 11 : warning_at (loc, OPT_Wunused_value,
7229 : "left-hand operand of comma expression has no effect");
7230 : }
7231 : }
7232 105848 : else if (TREE_CODE (expr1) == COMPOUND_EXPR
7233 13113 : && warn_unused_value)
7234 : {
7235 : tree r = expr1;
7236 : location_t cloc = loc;
7237 4833 : while (TREE_CODE (r) == COMPOUND_EXPR)
7238 : {
7239 2417 : if (EXPR_HAS_LOCATION (r))
7240 2417 : cloc = EXPR_LOCATION (r);
7241 2417 : r = TREE_OPERAND (r, 1);
7242 : }
7243 2416 : if (!TREE_SIDE_EFFECTS (r)
7244 4 : && !VOID_TYPE_P (TREE_TYPE (r))
7245 2420 : && !CONVERT_EXPR_P (r))
7246 4 : warning_at (cloc, OPT_Wunused_value,
7247 : "right-hand operand of comma expression has no effect");
7248 : }
7249 :
7250 : /* With -Wunused, we should also warn if the left-hand operand does have
7251 : side-effects, but computes a value which is not used. For example, in
7252 : `foo() + bar(), baz()' the result of the `+' operator is not used,
7253 : so we should issue a warning. */
7254 103432 : else if (warn_unused_value)
7255 35423 : warn_if_unused_value (expr1, loc);
7256 :
7257 114303 : maybe_warn_nodiscard (loc, expr1);
7258 :
7259 114303 : if (expr2 == error_mark_node)
7260 : return error_mark_node;
7261 :
7262 114290 : ret = build2 (COMPOUND_EXPR, TREE_TYPE (expr2), expr1, expr2);
7263 :
7264 114290 : if (flag_isoc99
7265 : && expr1_int_operands
7266 113830 : && expr2_int_operands)
7267 153 : ret = note_integer_operands (ret);
7268 :
7269 114290 : if (eptype)
7270 1 : ret = build1 (EXCESS_PRECISION_EXPR, eptype, ret);
7271 :
7272 114290 : protected_set_expr_location (ret, loc);
7273 114290 : return ret;
7274 : }
7275 :
7276 : /* Issue -Wcast-qual warnings when appropriate. TYPE is the type to
7277 : which we are casting. OTYPE is the type of the expression being
7278 : cast. Both TYPE and OTYPE are pointer types. LOC is the location
7279 : of the cast. -Wcast-qual appeared on the command line. Named
7280 : address space qualifiers are not handled here, because they result
7281 : in different warnings. */
7282 :
7283 : static void
7284 14107 : handle_warn_cast_qual (location_t loc, tree type, tree otype)
7285 : {
7286 14107 : tree in_type = type;
7287 14107 : tree in_otype = otype;
7288 14107 : int added = 0;
7289 14107 : int discarded = 0;
7290 14277 : bool is_const;
7291 :
7292 : /* Check that the qualifiers on IN_TYPE are a superset of the
7293 : qualifiers of IN_OTYPE. The outermost level of POINTER_TYPE
7294 : nodes is uninteresting and we stop as soon as we hit a
7295 : non-POINTER_TYPE node on either type. */
7296 14277 : do
7297 : {
7298 14277 : in_otype = TREE_TYPE (in_otype);
7299 14277 : in_type = TREE_TYPE (in_type);
7300 :
7301 : /* GNU C allows cv-qualified function types. 'const' means the
7302 : function is very pure, 'volatile' means it can't return. We
7303 : need to warn when such qualifiers are added, not when they're
7304 : taken away. */
7305 14277 : if (TREE_CODE (in_otype) == FUNCTION_TYPE
7306 26 : && TREE_CODE (in_type) == FUNCTION_TYPE)
7307 18 : added |= (TYPE_QUALS_NO_ADDR_SPACE (in_type)
7308 18 : & ~TYPE_QUALS_NO_ADDR_SPACE (in_otype));
7309 : else
7310 14259 : discarded |= (TYPE_QUALS_NO_ADDR_SPACE (in_otype)
7311 14259 : & ~TYPE_QUALS_NO_ADDR_SPACE (in_type));
7312 : }
7313 14277 : while (TREE_CODE (in_type) == POINTER_TYPE
7314 14277 : && TREE_CODE (in_otype) == POINTER_TYPE);
7315 :
7316 14107 : if (added)
7317 2 : warning_at (loc, OPT_Wcast_qual,
7318 : "cast adds %q#v qualifier to function type", added);
7319 :
7320 14107 : if (discarded)
7321 : /* There are qualifiers present in IN_OTYPE that are not present
7322 : in IN_TYPE. */
7323 1203 : warning_at (loc, OPT_Wcast_qual,
7324 : "cast discards %qv qualifier from pointer target type",
7325 : discarded);
7326 :
7327 14107 : if (added || discarded)
7328 : return;
7329 :
7330 : /* A cast from **T to const **T is unsafe, because it can cause a
7331 : const value to be changed with no additional warning. We only
7332 : issue this warning if T is the same on both sides, and we only
7333 : issue the warning if there are the same number of pointers on
7334 : both sides, as otherwise the cast is clearly unsafe anyhow. A
7335 : cast is unsafe when a qualifier is added at one level and const
7336 : is not present at all outer levels.
7337 :
7338 : To issue this warning, we check at each level whether the cast
7339 : adds new qualifiers not already seen. We don't need to special
7340 : case function types, as they won't have the same
7341 : TYPE_MAIN_VARIANT. */
7342 :
7343 12902 : if (TYPE_MAIN_VARIANT (in_type) != TYPE_MAIN_VARIANT (in_otype))
7344 : return;
7345 227 : if (TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE)
7346 : return;
7347 :
7348 48 : in_type = type;
7349 48 : in_otype = otype;
7350 48 : is_const = TYPE_READONLY (TREE_TYPE (in_type));
7351 130 : do
7352 : {
7353 130 : in_type = TREE_TYPE (in_type);
7354 130 : in_otype = TREE_TYPE (in_otype);
7355 130 : if ((TYPE_QUALS (in_type) &~ TYPE_QUALS (in_otype)) != 0
7356 130 : && !is_const)
7357 : {
7358 27 : warning_at (loc, OPT_Wcast_qual,
7359 : "to be safe all intermediate pointers in cast from "
7360 : "%qT to %qT must be %<const%> qualified",
7361 : otype, type);
7362 27 : break;
7363 : }
7364 103 : if (is_const)
7365 72 : is_const = TYPE_READONLY (in_type);
7366 : }
7367 103 : while (TREE_CODE (in_type) == POINTER_TYPE);
7368 : }
7369 :
7370 : /* Heuristic check if two parameter types can be considered ABI-equivalent. */
7371 :
7372 : static bool
7373 1316 : c_safe_arg_type_equiv_p (tree t1, tree t2)
7374 : {
7375 1316 : if (error_operand_p (t1) || error_operand_p (t2))
7376 : return true;
7377 :
7378 1315 : t1 = TYPE_MAIN_VARIANT (t1);
7379 1315 : t2 = TYPE_MAIN_VARIANT (t2);
7380 :
7381 1315 : if (TREE_CODE (t1) == POINTER_TYPE
7382 229 : && TREE_CODE (t2) == POINTER_TYPE)
7383 : return true;
7384 :
7385 : /* Only the precision of the parameter matters. This check should
7386 : make sure that the callee does not see undefined values in argument
7387 : registers. */
7388 1107 : if (INTEGRAL_TYPE_P (t1)
7389 917 : && INTEGRAL_TYPE_P (t2)
7390 1452 : && TYPE_PRECISION (t1) == TYPE_PRECISION (t2))
7391 : return true;
7392 :
7393 942 : return comptypes (t1, t2);
7394 : }
7395 :
7396 : /* Check if a type cast between two function types can be considered safe. */
7397 :
7398 : static bool
7399 7563 : c_safe_function_type_cast_p (tree t1, tree t2)
7400 : {
7401 7563 : if (TREE_TYPE (t1) == void_type_node &&
7402 5561 : TYPE_ARG_TYPES (t1) == void_list_node)
7403 : return true;
7404 :
7405 3726 : if (TREE_TYPE (t2) == void_type_node &&
7406 2889 : TYPE_ARG_TYPES (t2) == void_list_node)
7407 : return true;
7408 :
7409 896 : if (!c_safe_arg_type_equiv_p (TREE_TYPE (t1), TREE_TYPE (t2)))
7410 : return false;
7411 :
7412 197 : for (t1 = TYPE_ARG_TYPES (t1), t2 = TYPE_ARG_TYPES (t2);
7413 513 : t1 && t2;
7414 316 : t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
7415 420 : if (!c_safe_arg_type_equiv_p (TREE_VALUE (t1), TREE_VALUE (t2)))
7416 : return false;
7417 :
7418 : return true;
7419 : }
7420 :
7421 : /* Build an expression representing a cast to type TYPE of expression EXPR.
7422 : LOC is the location of the cast-- typically the open paren of the cast. */
7423 :
7424 : tree
7425 124423863 : build_c_cast (location_t loc, tree type, tree expr)
7426 : {
7427 124423863 : tree value;
7428 :
7429 124423863 : bool int_operands = EXPR_INT_CONST_OPERANDS (expr);
7430 :
7431 124423863 : if (TREE_CODE (expr) == EXCESS_PRECISION_EXPR)
7432 66 : expr = TREE_OPERAND (expr, 0);
7433 :
7434 124423863 : value = expr;
7435 124423863 : if (int_operands)
7436 7151480 : value = remove_c_maybe_const_expr (value);
7437 :
7438 124423863 : if (type == error_mark_node || expr == error_mark_node)
7439 : return error_mark_node;
7440 :
7441 : /* The ObjC front-end uses TYPE_MAIN_VARIANT to tie together types differing
7442 : only in <protocol> qualifications. But when constructing cast expressions,
7443 : the protocols do matter and must be kept around. */
7444 124422843 : if (objc_is_object_ptr (type) && objc_is_object_ptr (TREE_TYPE (expr)))
7445 0 : return build1 (NOP_EXPR, type, expr);
7446 :
7447 124422843 : type = TYPE_MAIN_VARIANT (type);
7448 :
7449 124422843 : if (TREE_CODE (type) == ARRAY_TYPE)
7450 : {
7451 13 : error_at (loc, "cast specifies array type");
7452 13 : return error_mark_node;
7453 : }
7454 :
7455 124422830 : if (TREE_CODE (type) == FUNCTION_TYPE)
7456 : {
7457 6 : error_at (loc, "cast specifies function type");
7458 6 : return error_mark_node;
7459 : }
7460 :
7461 124422824 : if (!VOID_TYPE_P (type))
7462 : {
7463 124378161 : value = require_complete_type (loc, value);
7464 124378161 : if (value == error_mark_node)
7465 : return error_mark_node;
7466 : }
7467 :
7468 124422823 : if (type == TYPE_MAIN_VARIANT (TREE_TYPE (value)))
7469 : {
7470 18807839 : if (RECORD_OR_UNION_TYPE_P (type)
7471 18807839 : && pedwarn (loc, OPT_Wpedantic,
7472 : "ISO C forbids casting nonscalar to the same type"))
7473 : ;
7474 18807835 : else if (warn_useless_cast && c_inhibit_evaluation_warnings == 0)
7475 8 : warning_at (loc, OPT_Wuseless_cast,
7476 : "useless cast to type %qT", type);
7477 :
7478 : /* Convert to remove any qualifiers from VALUE's type. */
7479 18807839 : value = convert (type, value);
7480 : }
7481 105614984 : else if (TREE_CODE (type) == UNION_TYPE)
7482 : {
7483 137 : tree field;
7484 :
7485 192 : for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
7486 185 : if (TREE_TYPE (field) != error_mark_node
7487 369 : && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (field)),
7488 184 : TYPE_MAIN_VARIANT (TREE_TYPE (value))))
7489 : break;
7490 :
7491 137 : if (field)
7492 : {
7493 130 : tree t;
7494 130 : bool maybe_const = true;
7495 :
7496 130 : pedwarn (loc, OPT_Wpedantic, "ISO C forbids casts to union type");
7497 130 : t = c_fully_fold (value, false, &maybe_const);
7498 130 : t = build_constructor_single (type, field, t);
7499 130 : if (!maybe_const)
7500 15 : t = c_wrap_maybe_const (t, true);
7501 130 : t = digest_init (loc, field, type, t,
7502 : NULL_TREE, false, false, false, true, false, false);
7503 130 : TREE_CONSTANT (t) = TREE_CONSTANT (value);
7504 130 : return t;
7505 : }
7506 7 : error_at (loc, "cast to union type from type not present in union");
7507 7 : return error_mark_node;
7508 : }
7509 : else
7510 : {
7511 105614847 : tree otype, ovalue;
7512 :
7513 105614847 : if (type == void_type_node)
7514 : {
7515 18693 : tree t = build1 (CONVERT_EXPR, type, value);
7516 18693 : SET_EXPR_LOCATION (t, loc);
7517 18693 : return t;
7518 : }
7519 :
7520 105596154 : otype = TREE_TYPE (value);
7521 :
7522 : /* Optionally warn about potentially worrisome casts. */
7523 105596154 : if (warn_cast_qual
7524 204404 : && TREE_CODE (type) == POINTER_TYPE
7525 27455 : && TREE_CODE (otype) == POINTER_TYPE)
7526 14107 : handle_warn_cast_qual (loc, type, otype);
7527 :
7528 : /* Warn about conversions between pointers to disjoint
7529 : address spaces. */
7530 105596154 : if (TREE_CODE (type) == POINTER_TYPE
7531 3365425 : && TREE_CODE (otype) == POINTER_TYPE
7532 108614145 : && !null_pointer_constant_p (value))
7533 : {
7534 2963913 : addr_space_t as_to = TYPE_ADDR_SPACE (TREE_TYPE (type));
7535 2963913 : addr_space_t as_from = TYPE_ADDR_SPACE (TREE_TYPE (otype));
7536 2963913 : addr_space_t as_common;
7537 :
7538 2963913 : if (!addr_space_superset (as_to, as_from, &as_common))
7539 : {
7540 0 : if (ADDR_SPACE_GENERIC_P (as_from))
7541 0 : warning_at (loc, 0, "cast to %qs address space pointer "
7542 : "from disjoint generic address space pointer",
7543 : c_addr_space_name (as_to));
7544 :
7545 0 : else if (ADDR_SPACE_GENERIC_P (as_to))
7546 0 : warning_at (loc, 0, "cast to generic address space pointer "
7547 : "from disjoint %qs address space pointer",
7548 : c_addr_space_name (as_from));
7549 :
7550 : else
7551 0 : warning_at (loc, 0, "cast to %qs address space pointer "
7552 : "from disjoint %qs address space pointer",
7553 : c_addr_space_name (as_to),
7554 : c_addr_space_name (as_from));
7555 : }
7556 :
7557 : /* Warn of new allocations that are not big enough for the target
7558 : type. */
7559 2963913 : if (warn_alloc_size && TREE_CODE (value) == CALL_EXPR)
7560 1069 : if (tree fndecl = get_callee_fndecl (value))
7561 1065 : if (DECL_IS_MALLOC (fndecl))
7562 : {
7563 573 : tree attrs = TYPE_ATTRIBUTES (TREE_TYPE (fndecl));
7564 573 : tree alloc_size = lookup_attribute ("alloc_size", attrs);
7565 573 : if (alloc_size)
7566 215 : warn_for_alloc_size (loc, TREE_TYPE (type), value,
7567 : alloc_size);
7568 : }
7569 : }
7570 :
7571 : /* Warn about possible alignment problems. */
7572 105596154 : if ((STRICT_ALIGNMENT || warn_cast_align == 2)
7573 7 : && TREE_CODE (type) == POINTER_TYPE
7574 7 : && TREE_CODE (otype) == POINTER_TYPE
7575 7 : && TREE_CODE (TREE_TYPE (otype)) != VOID_TYPE
7576 7 : && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
7577 : /* Don't warn about opaque types, where the actual alignment
7578 : restriction is unknown. */
7579 12 : && !(RECORD_OR_UNION_TYPE_P (TREE_TYPE (otype))
7580 5 : && TYPE_MODE (TREE_TYPE (otype)) == VOIDmode)
7581 105596168 : && min_align_of_type (TREE_TYPE (type))
7582 7 : > min_align_of_type (TREE_TYPE (otype)))
7583 5 : warning_at (loc, OPT_Wcast_align,
7584 : "cast increases required alignment of target type");
7585 :
7586 105596154 : if ((TREE_CODE (type) == INTEGER_TYPE
7587 105596154 : || TREE_CODE (type) == BITINT_TYPE)
7588 7369297 : && TREE_CODE (otype) == POINTER_TYPE
7589 105621606 : && TYPE_PRECISION (type) != TYPE_PRECISION (otype))
7590 : /* Unlike conversion of integers to pointers, where the
7591 : warning is disabled for converting constants because
7592 : of cases such as SIG_*, warn about converting constant
7593 : pointers to integers. In some cases it may cause unwanted
7594 : sign extension, and a warning is appropriate. */
7595 1464 : warning_at (loc, OPT_Wpointer_to_int_cast,
7596 : "cast from pointer to integer of different size");
7597 :
7598 105596154 : if ((TREE_CODE (value) == CALL_EXPR
7599 36156958 : && !is_access_with_size_p (value))
7600 141753108 : && TREE_CODE (type) != TREE_CODE (otype))
7601 2308 : warning_at (loc, OPT_Wbad_function_cast,
7602 : "cast from function call of type %qT "
7603 : "to non-matching type %qT", otype, type);
7604 :
7605 105596154 : if (TREE_CODE (type) == POINTER_TYPE
7606 3365425 : && (TREE_CODE (otype) == INTEGER_TYPE
7607 3365425 : || TREE_CODE (otype) == BITINT_TYPE)
7608 347345 : && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
7609 : /* Don't warn about converting any constant. */
7610 105905465 : && !TREE_CONSTANT (value))
7611 407 : warning_at (loc,
7612 407 : OPT_Wint_to_pointer_cast, "cast to pointer from integer "
7613 : "of different size");
7614 :
7615 105596154 : if (warn_strict_aliasing <= 2)
7616 96818762 : strict_aliasing_warning (EXPR_LOCATION (value), type, expr);
7617 :
7618 : /* If pedantic, warn for conversions between function and object
7619 : pointer types, except for converting a null pointer constant
7620 : to function pointer type. */
7621 105596154 : if (pedantic
7622 261471 : && TREE_CODE (type) == POINTER_TYPE
7623 144380 : && TREE_CODE (otype) == POINTER_TYPE
7624 3035 : && TREE_CODE (TREE_TYPE (otype)) == FUNCTION_TYPE
7625 105596175 : && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE)
7626 18 : pedwarn (loc, OPT_Wpedantic, "ISO C forbids "
7627 : "conversion of function pointer to object pointer type");
7628 :
7629 105596154 : if (pedantic
7630 261471 : && TREE_CODE (type) == POINTER_TYPE
7631 144380 : && TREE_CODE (otype) == POINTER_TYPE
7632 3035 : && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
7633 13 : && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
7634 105596164 : && !null_pointer_constant_p (value))
7635 4 : pedwarn (loc, OPT_Wpedantic, "ISO C forbids "
7636 : "conversion of object pointer to function pointer type");
7637 :
7638 105596154 : if (TREE_CODE (type) == POINTER_TYPE
7639 3365425 : && TREE_CODE (otype) == POINTER_TYPE
7640 3017991 : && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
7641 8684 : && TREE_CODE (TREE_TYPE (otype)) == FUNCTION_TYPE
7642 105603717 : && !c_safe_function_type_cast_p (TREE_TYPE (type),
7643 7563 : TREE_TYPE (otype)))
7644 803 : warning_at (loc, OPT_Wcast_function_type,
7645 : "cast between incompatible function types"
7646 : " from %qT to %qT", otype, type);
7647 :
7648 105596154 : ovalue = value;
7649 : /* If converting to boolean a value with integer operands that
7650 : is not itself represented as an INTEGER_CST, the call below
7651 : to note_integer_operands may insert a C_MAYBE_CONST_EXPR, but
7652 : build_binary_op as called by c_common_truthvalue_conversion
7653 : may also insert a C_MAYBE_CONST_EXPR to indicate that a
7654 : subexpression has been fully folded. To avoid nested
7655 : C_MAYBE_CONST_EXPR, ensure that
7656 : c_objc_common_truthvalue_conversion receives an argument
7657 : properly marked as having integer operands in that case. */
7658 105596154 : if (int_operands
7659 6960439 : && TREE_CODE (value) != INTEGER_CST
7660 105596196 : && (TREE_CODE (type) == BOOLEAN_TYPE
7661 28 : || (TREE_CODE (type) == ENUMERAL_TYPE
7662 14 : && ENUM_UNDERLYING_TYPE (type) != NULL_TREE
7663 14 : && TREE_CODE (ENUM_UNDERLYING_TYPE (type)) == BOOLEAN_TYPE)))
7664 28 : value = note_integer_operands (value);
7665 105596154 : value = convert (type, value);
7666 :
7667 : /* Ignore any integer overflow caused by the cast. */
7668 105596154 : if (TREE_CODE (value) == INTEGER_CST && !FLOAT_TYPE_P (otype))
7669 : {
7670 6907093 : if (TREE_OVERFLOW_P (ovalue))
7671 : {
7672 9 : if (!TREE_OVERFLOW (value))
7673 : {
7674 : /* Avoid clobbering a shared constant. */
7675 0 : value = copy_node (value);
7676 0 : TREE_OVERFLOW (value) = TREE_OVERFLOW (ovalue);
7677 : }
7678 : }
7679 6907084 : else if (TREE_OVERFLOW (value))
7680 : /* Reset VALUE's overflow flags, ensuring constant sharing. */
7681 3107 : value = wide_int_to_tree (TREE_TYPE (value), wi::to_wide (value));
7682 : }
7683 : }
7684 :
7685 : /* Don't let a cast be an lvalue. */
7686 124403993 : if (lvalue_p (value)
7687 : /* Also, don't let a cast be a bit-field of a bit-precise integer type,
7688 : otherwise it could be incorrectly subject of integer promotions. */
7689 124403993 : || (TREE_CODE (value) == COMPONENT_REF
7690 24 : && DECL_C_BIT_FIELD (TREE_OPERAND (value, 1))
7691 24 : && BITINT_TYPE_P (DECL_BIT_FIELD_TYPE (TREE_OPERAND (value, 1)))))
7692 91179 : value = non_lvalue_loc (loc, value);
7693 :
7694 : /* Don't allow the results of casting to floating-point or complex
7695 : types be confused with actual constants, or casts involving
7696 : integer and pointer types other than direct integer-to-integer
7697 : and integer-to-pointer be confused with integer constant
7698 : expressions and null pointer constants. */
7699 124403993 : if (TREE_CODE (value) == REAL_CST
7700 124354041 : || TREE_CODE (value) == COMPLEX_CST
7701 248735408 : || (TREE_CODE (value) == INTEGER_CST
7702 7157038 : && !((TREE_CODE (expr) == INTEGER_CST
7703 7083220 : && INTEGRAL_TYPE_P (TREE_TYPE (expr)))
7704 66415 : || TREE_CODE (expr) == REAL_CST
7705 : || TREE_CODE (expr) == COMPLEX_CST)))
7706 134626 : value = build1 (NOP_EXPR, type, value);
7707 :
7708 : /* If the expression has integer operands and so can occur in an
7709 : unevaluated part of an integer constant expression, ensure the
7710 : return value reflects this. */
7711 124403993 : if (int_operands
7712 7137505 : && INTEGRAL_TYPE_P (type)
7713 6690342 : && value != error_mark_node
7714 131094334 : && !EXPR_INT_CONST_OPERANDS (value))
7715 11 : value = note_integer_operands (value);
7716 :
7717 124403993 : protected_set_expr_location (value, loc);
7718 124403993 : return value;
7719 : }
7720 :
7721 : /* Interpret a cast of expression EXPR to type TYPE. LOC is the
7722 : location of the open paren of the cast, or the position of the cast
7723 : expr. */
7724 : tree
7725 124423358 : c_cast_expr (location_t loc, struct c_type_name *type_name, tree expr)
7726 : {
7727 124423358 : tree type;
7728 124423358 : tree type_expr = NULL_TREE;
7729 124423358 : bool type_expr_const = true;
7730 124423358 : tree ret;
7731 124423358 : int saved_wsp = warn_strict_prototypes;
7732 :
7733 : /* This avoids warnings about unprototyped casts on
7734 : integers. E.g. "#define SIG_DFL (void(*)())0". */
7735 124423358 : if (TREE_CODE (expr) == INTEGER_CST)
7736 7205663 : warn_strict_prototypes = 0;
7737 124423358 : type = groktypename (type_name, &type_expr, &type_expr_const);
7738 124423358 : warn_strict_prototypes = saved_wsp;
7739 :
7740 765170 : if (TREE_CODE (expr) == ADDR_EXPR && !VOID_TYPE_P (type)
7741 125188273 : && reject_gcc_builtin (expr))
7742 2 : return error_mark_node;
7743 :
7744 124423356 : ret = build_c_cast (loc, type, expr);
7745 124423356 : if (ret == error_mark_node)
7746 : return error_mark_node;
7747 :
7748 124422196 : if (type_expr)
7749 : {
7750 250 : bool inner_expr_const = true;
7751 250 : ret = c_fully_fold (ret, require_constant_value, &inner_expr_const);
7752 250 : ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret), type_expr, ret);
7753 500 : C_MAYBE_CONST_EXPR_NON_CONST (ret) = !(type_expr_const
7754 145 : && inner_expr_const);
7755 250 : SET_EXPR_LOCATION (ret, loc);
7756 : }
7757 :
7758 124422196 : if (!EXPR_HAS_LOCATION (ret))
7759 7083746 : protected_set_expr_location (ret, loc);
7760 :
7761 : /* C++ does not permits types to be defined in a cast, but it
7762 : allows references to incomplete types. */
7763 124422196 : if (warn_cxx_compat && type_name->specs->typespec_kind == ctsk_tagdef)
7764 1 : warning_at (loc, OPT_Wc___compat,
7765 : "defining a type in a cast is invalid in C++");
7766 :
7767 : return ret;
7768 : }
7769 :
7770 : /* Build an assignment expression of lvalue LHS from value RHS.
7771 : If LHS_ORIGTYPE is not NULL, it is the original type of LHS, which
7772 : may differ from TREE_TYPE (LHS) for an enum bitfield.
7773 : MODIFYCODE is the code for a binary operator that we use
7774 : to combine the old value of LHS with RHS to get the new value.
7775 : Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.
7776 : If RHS_ORIGTYPE is not NULL_TREE, it is the original type of RHS,
7777 : which may differ from TREE_TYPE (RHS) for an enum value.
7778 :
7779 : LOCATION is the location of the MODIFYCODE operator.
7780 : RHS_LOC is the location of the RHS. */
7781 :
7782 : tree
7783 2930659 : build_modify_expr (location_t location, tree lhs, tree lhs_origtype,
7784 : enum tree_code modifycode,
7785 : location_t rhs_loc, tree rhs, tree rhs_origtype)
7786 : {
7787 2930659 : tree result;
7788 2930659 : tree newrhs;
7789 2930659 : tree rhseval = NULL_TREE;
7790 2930659 : tree lhstype = TREE_TYPE (lhs);
7791 2930659 : tree olhstype = lhstype;
7792 2930659 : bool npc;
7793 2930659 : bool is_atomic_op;
7794 :
7795 : /* Types that aren't fully specified cannot be used in assignments. */
7796 2930659 : lhs = require_complete_type (location, lhs);
7797 2930659 : rhs = require_complete_type (location, rhs);
7798 :
7799 : /* Avoid duplicate error messages from operands that had errors. */
7800 2930659 : if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK)
7801 473 : return error_mark_node;
7802 :
7803 : /* Ensure an error for assigning a non-lvalue array to an array in
7804 : C90. */
7805 2930186 : if (TREE_CODE (lhstype) == ARRAY_TYPE)
7806 : {
7807 1 : error_at (location, "assignment to expression with array type");
7808 1 : return error_mark_node;
7809 : }
7810 :
7811 : /* For ObjC properties, defer this check. */
7812 2930185 : if (!objc_is_property_ref (lhs) && !lvalue_or_else (location, lhs, lv_assign))
7813 32 : return error_mark_node;
7814 :
7815 2930153 : is_atomic_op = really_atomic_lvalue (lhs);
7816 :
7817 2930153 : newrhs = rhs;
7818 :
7819 2930153 : if (TREE_CODE (lhs) == C_MAYBE_CONST_EXPR)
7820 : {
7821 2 : tree inner = build_modify_expr (location, C_MAYBE_CONST_EXPR_EXPR (lhs),
7822 : lhs_origtype, modifycode, rhs_loc, rhs,
7823 : rhs_origtype);
7824 2 : if (inner == error_mark_node)
7825 : return error_mark_node;
7826 4 : result = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (inner),
7827 2 : C_MAYBE_CONST_EXPR_PRE (lhs), inner);
7828 2 : gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (lhs));
7829 2 : C_MAYBE_CONST_EXPR_NON_CONST (result) = 1;
7830 2 : protected_set_expr_location (result, location);
7831 2 : return result;
7832 : }
7833 :
7834 : /* If a binary op has been requested, combine the old LHS value with the RHS
7835 : producing the value we should actually store into the LHS. */
7836 :
7837 2930151 : if (modifycode != NOP_EXPR)
7838 : {
7839 217066 : lhs = c_fully_fold (lhs, false, NULL, true);
7840 217066 : lhs = stabilize_reference (lhs);
7841 :
7842 : /* Construct the RHS for any non-atomic compound assignment. */
7843 217066 : if (!is_atomic_op)
7844 : {
7845 : /* If in LHS op= RHS the RHS has side-effects, ensure they
7846 : are preevaluated before the rest of the assignment expression's
7847 : side-effects, because RHS could contain e.g. function calls
7848 : that modify LHS. */
7849 201581 : if (TREE_SIDE_EFFECTS (rhs))
7850 : {
7851 8927 : if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
7852 28 : newrhs = save_expr (TREE_OPERAND (rhs, 0));
7853 : else
7854 8899 : newrhs = save_expr (rhs);
7855 8927 : rhseval = newrhs;
7856 8927 : if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
7857 28 : newrhs = build1 (EXCESS_PRECISION_EXPR, TREE_TYPE (rhs),
7858 : newrhs);
7859 : }
7860 201581 : bool clear_decl_read = false;
7861 89269 : if ((VAR_P (lhs) || TREE_CODE (lhs) == PARM_DECL)
7862 154951 : && !DECL_READ_P (lhs)
7863 254553 : && (VAR_P (lhs) ? warn_unused_but_set_variable
7864 : : warn_unused_but_set_parameter) > 2)
7865 : {
7866 21663 : mark_exp_read (newrhs);
7867 21663 : if (!DECL_READ_P (lhs))
7868 201581 : clear_decl_read = true;
7869 : }
7870 :
7871 201581 : newrhs = build_binary_op (location, modifycode,
7872 : convert_lvalue_to_rvalue (location, lhs,
7873 : true, true),
7874 : newrhs, true);
7875 201581 : if (clear_decl_read)
7876 21663 : DECL_READ_P (lhs) = 0;
7877 :
7878 : /* The original type of the right hand side is no longer
7879 : meaningful. */
7880 : rhs_origtype = NULL_TREE;
7881 : }
7882 : }
7883 :
7884 2930151 : if (c_dialect_objc ())
7885 : {
7886 : /* Check if we are modifying an Objective-C property reference;
7887 : if so, we need to generate setter calls. */
7888 0 : if (TREE_CODE (newrhs) == EXCESS_PRECISION_EXPR)
7889 0 : result = objc_maybe_build_modify_expr (lhs, TREE_OPERAND (newrhs, 0));
7890 : else
7891 0 : result = objc_maybe_build_modify_expr (lhs, newrhs);
7892 0 : if (result)
7893 0 : goto return_result;
7894 :
7895 : /* Else, do the check that we postponed for Objective-C. */
7896 0 : if (!lvalue_or_else (location, lhs, lv_assign))
7897 0 : return error_mark_node;
7898 : }
7899 :
7900 : /* Give an error for storing in something that is 'const'. */
7901 :
7902 2930151 : if (TYPE_READONLY (lhstype)
7903 2930151 : || (RECORD_OR_UNION_TYPE_P (lhstype)
7904 25821 : && C_TYPE_FIELDS_READONLY (lhstype)))
7905 : {
7906 88 : readonly_error (location, lhs, lv_assign);
7907 88 : return error_mark_node;
7908 : }
7909 2930063 : else if (TREE_READONLY (lhs))
7910 1 : readonly_warning (lhs, lv_assign);
7911 :
7912 : /* If storing into a structure or union member,
7913 : it has probably been given type `int'.
7914 : Compute the type that would go with
7915 : the actual amount of storage the member occupies. */
7916 :
7917 2930063 : if (TREE_CODE (lhs) == COMPONENT_REF
7918 250972 : && (TREE_CODE (lhstype) == INTEGER_TYPE
7919 250972 : || TREE_CODE (lhstype) == BOOLEAN_TYPE
7920 110498 : || SCALAR_FLOAT_TYPE_P (lhstype)
7921 87060 : || TREE_CODE (lhstype) == ENUMERAL_TYPE))
7922 170928 : lhstype = TREE_TYPE (get_unwidened (lhs, 0));
7923 :
7924 : /* If storing in a field that is in actuality a short or narrower than one,
7925 : we must store in the field in its actual type. */
7926 :
7927 2930063 : if (lhstype != TREE_TYPE (lhs))
7928 : {
7929 0 : lhs = copy_node (lhs);
7930 0 : TREE_TYPE (lhs) = lhstype;
7931 : }
7932 :
7933 : /* Issue -Wc++-compat warnings about an assignment to an enum type
7934 : when LHS does not have its original type. This happens for,
7935 : e.g., an enum bitfield in a struct. */
7936 2930063 : if (warn_cxx_compat
7937 3275 : && lhs_origtype != NULL_TREE
7938 3275 : && lhs_origtype != lhstype
7939 7 : && TREE_CODE (lhs_origtype) == ENUMERAL_TYPE)
7940 : {
7941 4 : tree checktype = (rhs_origtype != NULL_TREE
7942 4 : ? rhs_origtype
7943 0 : : TREE_TYPE (rhs));
7944 4 : if (checktype != error_mark_node
7945 4 : && (TYPE_MAIN_VARIANT (checktype) != TYPE_MAIN_VARIANT (lhs_origtype)
7946 2 : || (is_atomic_op && modifycode != NOP_EXPR)))
7947 2 : warning_at (location, OPT_Wc___compat,
7948 : "enum conversion in assignment is invalid in C++");
7949 : }
7950 :
7951 : /* Remove qualifiers. */
7952 2930063 : lhstype = c_build_qualified_type (lhstype, TYPE_UNQUALIFIED);
7953 2930063 : olhstype = c_build_qualified_type (olhstype, TYPE_UNQUALIFIED);
7954 :
7955 : /* Convert new value to destination type. Fold it first, then
7956 : restore any excess precision information, for the sake of
7957 : conversion warnings. */
7958 :
7959 2930063 : if (!(is_atomic_op && modifycode != NOP_EXPR))
7960 : {
7961 2914578 : tree rhs_semantic_type = NULL_TREE;
7962 2914578 : if (!c_in_omp_for)
7963 : {
7964 2898235 : if (TREE_CODE (newrhs) == EXCESS_PRECISION_EXPR)
7965 : {
7966 5077 : rhs_semantic_type = TREE_TYPE (newrhs);
7967 5077 : newrhs = TREE_OPERAND (newrhs, 0);
7968 : }
7969 2898235 : npc = null_pointer_constant_p (newrhs);
7970 2898235 : newrhs = c_fully_fold (newrhs, false, NULL);
7971 2898235 : if (rhs_semantic_type)
7972 5077 : newrhs = build1 (EXCESS_PRECISION_EXPR, rhs_semantic_type, newrhs);
7973 : }
7974 : else
7975 16343 : npc = null_pointer_constant_p (newrhs);
7976 2914578 : newrhs = convert_for_assignment (location, rhs_loc, lhstype, newrhs,
7977 : rhs_origtype, ic_assign, npc,
7978 : NULL_TREE, NULL_TREE, 0);
7979 2914578 : if (TREE_CODE (newrhs) == ERROR_MARK)
7980 127 : return error_mark_node;
7981 : }
7982 :
7983 : /* Emit ObjC write barrier, if necessary. */
7984 2929936 : if (c_dialect_objc () && flag_objc_gc)
7985 : {
7986 0 : result = objc_generate_write_barrier (lhs, modifycode, newrhs);
7987 0 : if (result)
7988 : {
7989 0 : protected_set_expr_location (result, location);
7990 0 : goto return_result;
7991 : }
7992 : }
7993 :
7994 : /* Scan operands. */
7995 :
7996 2929936 : if (is_atomic_op)
7997 25988 : result = build_atomic_assign (location, lhs, modifycode, newrhs, false);
7998 : else
7999 : {
8000 2903948 : result = build2 (MODIFY_EXPR, lhstype, lhs, newrhs);
8001 2903948 : TREE_SIDE_EFFECTS (result) = 1;
8002 2903948 : protected_set_expr_location (result, location);
8003 : }
8004 :
8005 : /* If we got the LHS in a different type for storing in,
8006 : convert the result back to the nominal type of LHS
8007 : so that the value we return always has the same type
8008 : as the LHS argument. */
8009 :
8010 2929936 : if (olhstype == TREE_TYPE (result))
8011 2929936 : goto return_result;
8012 :
8013 0 : result = convert_for_assignment (location, rhs_loc, olhstype, result,
8014 : rhs_origtype, ic_assign, false, NULL_TREE,
8015 : NULL_TREE, 0);
8016 0 : protected_set_expr_location (result, location);
8017 :
8018 2929936 : return_result:
8019 2929936 : if (rhseval)
8020 8927 : result = build2 (COMPOUND_EXPR, TREE_TYPE (result), rhseval, result);
8021 : return result;
8022 : }
8023 :
8024 : /* Return whether STRUCT_TYPE has an anonymous field with type TYPE.
8025 : This is used to implement -fplan9-extensions. */
8026 :
8027 : static bool
8028 26 : find_anonymous_field_with_type (tree struct_type, tree type)
8029 : {
8030 26 : tree field;
8031 26 : bool found;
8032 :
8033 26 : gcc_assert (RECORD_OR_UNION_TYPE_P (struct_type));
8034 26 : found = false;
8035 26 : for (field = TYPE_FIELDS (struct_type);
8036 68 : field != NULL_TREE;
8037 42 : field = TREE_CHAIN (field))
8038 : {
8039 42 : tree fieldtype = remove_qualifiers (TREE_TYPE (field));
8040 42 : if (DECL_NAME (field) == NULL
8041 42 : && comptypes (type, fieldtype))
8042 : {
8043 4 : if (found)
8044 : return false;
8045 : found = true;
8046 : }
8047 38 : else if (DECL_NAME (field) == NULL
8048 2 : && RECORD_OR_UNION_TYPE_P (TREE_TYPE (field))
8049 40 : && find_anonymous_field_with_type (TREE_TYPE (field), type))
8050 : {
8051 0 : if (found)
8052 : return false;
8053 : found = true;
8054 : }
8055 : }
8056 : return found;
8057 : }
8058 :
8059 : /* RHS is an expression whose type is pointer to struct. If there is
8060 : an anonymous field in RHS with type TYPE, then return a pointer to
8061 : that field in RHS. This is used with -fplan9-extensions. This
8062 : returns NULL if no conversion could be found. */
8063 :
8064 : static tree
8065 28 : convert_to_anonymous_field (location_t location, tree type, tree rhs)
8066 : {
8067 28 : tree rhs_struct_type, lhs_main_type;
8068 28 : tree field, found_field;
8069 28 : bool found_sub_field;
8070 28 : tree ret;
8071 :
8072 28 : gcc_assert (POINTER_TYPE_P (TREE_TYPE (rhs)));
8073 28 : rhs_struct_type = TREE_TYPE (TREE_TYPE (rhs));
8074 28 : gcc_assert (RECORD_OR_UNION_TYPE_P (rhs_struct_type));
8075 :
8076 28 : gcc_assert (POINTER_TYPE_P (type));
8077 28 : lhs_main_type = remove_qualifiers (TREE_TYPE (type));
8078 :
8079 28 : found_field = NULL_TREE;
8080 28 : found_sub_field = false;
8081 28 : for (field = TYPE_FIELDS (rhs_struct_type);
8082 172 : field != NULL_TREE;
8083 144 : field = TREE_CHAIN (field))
8084 : {
8085 148 : if (DECL_NAME (field) != NULL_TREE
8086 148 : || !RECORD_OR_UNION_TYPE_P (TREE_TYPE (field)))
8087 96 : continue;
8088 52 : tree fieldtype = remove_qualifiers (TREE_TYPE (field));
8089 52 : if (comptypes (lhs_main_type, fieldtype))
8090 : {
8091 28 : if (found_field != NULL_TREE)
8092 : return NULL_TREE;
8093 : found_field = field;
8094 : }
8095 24 : else if (find_anonymous_field_with_type (TREE_TYPE (field),
8096 : lhs_main_type))
8097 : {
8098 4 : if (found_field != NULL_TREE)
8099 : return NULL_TREE;
8100 : found_field = field;
8101 : found_sub_field = true;
8102 : }
8103 : }
8104 :
8105 24 : if (found_field == NULL_TREE)
8106 : return NULL_TREE;
8107 :
8108 24 : ret = fold_build3_loc (location, COMPONENT_REF, TREE_TYPE (found_field),
8109 : build_fold_indirect_ref (rhs), found_field,
8110 : NULL_TREE);
8111 24 : ret = build_fold_addr_expr_loc (location, ret);
8112 :
8113 24 : if (found_sub_field)
8114 : {
8115 2 : ret = convert_to_anonymous_field (location, type, ret);
8116 2 : gcc_assert (ret != NULL_TREE);
8117 : }
8118 :
8119 : return ret;
8120 : }
8121 :
8122 : /* Issue an error message for a bad initializer component.
8123 : GMSGID identifies the message.
8124 : The component name is taken from the spelling stack. */
8125 :
8126 : static void ATTRIBUTE_GCC_DIAG (2,0)
8127 944 : error_init (location_t loc, const char *gmsgid, ...)
8128 : {
8129 944 : char *ofwhat;
8130 :
8131 944 : auto_diagnostic_group d;
8132 :
8133 : /* The gmsgid may be a format string with %< and %>. */
8134 944 : va_list ap;
8135 944 : va_start (ap, gmsgid);
8136 944 : bool warned = emit_diagnostic_valist (diagnostics::kind::error,
8137 944 : loc, -1, gmsgid, &ap);
8138 944 : va_end (ap);
8139 :
8140 944 : ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
8141 944 : if (*ofwhat && warned)
8142 220 : inform (loc, "(near initialization for %qs)", ofwhat);
8143 944 : }
8144 :
8145 : /* Used to implement pedwarn_init and permerror_init. */
8146 :
8147 : static bool ATTRIBUTE_GCC_DIAG (3,0)
8148 2478 : pedwarn_permerror_init (location_t loc, int opt, const char *gmsgid,
8149 : va_list *ap, enum diagnostics::kind kind)
8150 : {
8151 : /* Use the location where a macro was expanded rather than where
8152 : it was defined to make sure macros defined in system headers
8153 : but used incorrectly elsewhere are diagnosed. */
8154 2478 : location_t exploc = expansion_point_location_if_in_system_header (loc);
8155 2478 : auto_diagnostic_group d;
8156 2478 : bool warned = emit_diagnostic_valist (kind, exploc, opt, gmsgid, ap);
8157 2478 : if (warned)
8158 : {
8159 1815 : char *ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
8160 1815 : if (*ofwhat)
8161 1494 : inform (exploc, "(near initialization for %qs)", ofwhat);
8162 : }
8163 4956 : return warned;
8164 2478 : }
8165 :
8166 : /* Issue a pedantic warning for a bad initializer component. OPT is
8167 : the option OPT_* (from options.h) controlling this warning or 0 if
8168 : it is unconditionally given. GMSGID identifies the message. The
8169 : component name is taken from the spelling stack. */
8170 :
8171 : static bool ATTRIBUTE_GCC_DIAG (3,0)
8172 2127 : pedwarn_init (location_t loc, int opt, const char *gmsgid, ...)
8173 : {
8174 2127 : va_list ap;
8175 2127 : va_start (ap, gmsgid);
8176 2127 : bool warned = pedwarn_permerror_init (loc, opt, gmsgid, &ap,
8177 : diagnostics::kind::pedwarn);
8178 2127 : va_end (ap);
8179 2127 : return warned;
8180 : }
8181 :
8182 : /* Like pedwarn_init, but issue a permerror. */
8183 :
8184 : static bool ATTRIBUTE_GCC_DIAG (3,0)
8185 351 : permerror_init (location_t loc, int opt, const char *gmsgid, ...)
8186 : {
8187 351 : va_list ap;
8188 351 : va_start (ap, gmsgid);
8189 351 : bool warned = pedwarn_permerror_init (loc, opt, gmsgid, &ap,
8190 : diagnostics::kind::permerror);
8191 351 : va_end (ap);
8192 351 : return warned;
8193 : }
8194 :
8195 : /* Issue a warning for a bad initializer component.
8196 :
8197 : OPT is the OPT_W* value corresponding to the warning option that
8198 : controls this warning. GMSGID identifies the message. The
8199 : component name is taken from the spelling stack. */
8200 :
8201 : static void
8202 146 : warning_init (location_t loc, int opt, const char *gmsgid)
8203 : {
8204 146 : char *ofwhat;
8205 146 : bool warned;
8206 :
8207 146 : auto_diagnostic_group d;
8208 :
8209 : /* Use the location where a macro was expanded rather than where
8210 : it was defined to make sure macros defined in system headers
8211 : but used incorrectly elsewhere are diagnosed. */
8212 146 : location_t exploc = expansion_point_location_if_in_system_header (loc);
8213 :
8214 : /* The gmsgid may be a format string with %< and %>. */
8215 146 : warned = warning_at (exploc, opt, gmsgid);
8216 146 : if (warned)
8217 : {
8218 133 : ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
8219 133 : if (*ofwhat)
8220 133 : inform (exploc, "(near initialization for %qs)", ofwhat);
8221 : }
8222 146 : }
8223 :
8224 : /* If TYPE is an array type and EXPR is a parenthesized string
8225 : constant, warn if pedantic that EXPR is being used to initialize an
8226 : object of type TYPE. */
8227 :
8228 : void
8229 7320308 : maybe_warn_string_init (location_t loc, tree type, struct c_expr expr)
8230 : {
8231 7320308 : if (pedantic
8232 81846 : && TREE_CODE (type) == ARRAY_TYPE
8233 1193 : && TREE_CODE (expr.value) == STRING_CST
8234 472 : && expr.original_code != STRING_CST)
8235 13 : pedwarn_init (loc, OPT_Wpedantic,
8236 : "array initialized from parenthesized string constant");
8237 7320308 : }
8238 :
8239 : /* Attempt to locate the parameter with the given index within FNDECL,
8240 : returning DECL_SOURCE_LOCATION (FNDECL) if it can't be found. */
8241 :
8242 : static location_t
8243 937 : get_fndecl_argument_location (tree fndecl, int argnum)
8244 : {
8245 937 : int i;
8246 937 : tree param;
8247 :
8248 : /* Locate param by index within DECL_ARGUMENTS (fndecl). */
8249 937 : for (i = 0, param = DECL_ARGUMENTS (fndecl);
8250 1016 : i < argnum && param;
8251 79 : i++, param = TREE_CHAIN (param))
8252 : ;
8253 :
8254 : /* If something went wrong (e.g. if we have a builtin and thus no arguments),
8255 : return DECL_SOURCE_LOCATION (FNDECL). */
8256 937 : if (param == NULL)
8257 653 : return DECL_SOURCE_LOCATION (fndecl);
8258 :
8259 284 : return DECL_SOURCE_LOCATION (param);
8260 : }
8261 :
8262 : /* Issue a note about a mismatching argument for parameter PARMNUM
8263 : to FUNDECL, for types EXPECTED_TYPE and ACTUAL_TYPE.
8264 : Attempt to issue the note at the pertinent parameter of the decl;
8265 : failing that issue it at the location of FUNDECL; failing that
8266 : issue it at PLOC.
8267 : Use highlight_colors::actual for the ACTUAL_TYPE
8268 : and highlight_colors::expected for EXPECTED_TYPE and the
8269 : parameter of FUNDECL*/
8270 :
8271 : static void
8272 1062 : inform_for_arg (tree fundecl, location_t ploc, int parmnum,
8273 : tree expected_type, tree actual_type)
8274 : {
8275 1062 : location_t loc;
8276 1062 : if (fundecl && !DECL_IS_UNDECLARED_BUILTIN (fundecl))
8277 937 : loc = get_fndecl_argument_location (fundecl, parmnum - 1);
8278 : else
8279 : loc = ploc;
8280 :
8281 1062 : gcc_rich_location richloc (loc, nullptr, highlight_colors::expected);
8282 :
8283 1062 : pp_markup::element_expected_type elem_expected_type (expected_type);
8284 1062 : pp_markup::element_actual_type elem_actual_type (actual_type);
8285 1062 : inform (&richloc,
8286 : "expected %e but argument is of type %e",
8287 : &elem_expected_type, &elem_actual_type);
8288 1062 : }
8289 :
8290 : /* Issue a warning when an argument of ARGTYPE is passed to a built-in
8291 : function FUNDECL declared without prototype to parameter PARMNUM of
8292 : PARMTYPE when ARGTYPE does not promote to PARMTYPE. */
8293 :
8294 : static void
8295 418 : maybe_warn_builtin_no_proto_arg (location_t loc, tree fundecl, int parmnum,
8296 : tree parmtype, tree argtype)
8297 : {
8298 418 : tree_code parmcode = TREE_CODE (parmtype);
8299 418 : tree_code argcode = TREE_CODE (argtype);
8300 418 : tree promoted = c_type_promotes_to (argtype);
8301 :
8302 : /* Avoid warning for enum arguments that promote to an integer type
8303 : of the same size/mode. */
8304 418 : if (parmcode == INTEGER_TYPE
8305 418 : && argcode == ENUMERAL_TYPE
8306 418 : && TYPE_MODE (parmtype) == TYPE_MODE (argtype))
8307 : return;
8308 :
8309 417 : if ((parmcode == argcode
8310 222 : || (parmcode == INTEGER_TYPE
8311 : && argcode == ENUMERAL_TYPE))
8312 418 : && TYPE_MAIN_VARIANT (parmtype) == TYPE_MAIN_VARIANT (promoted))
8313 : return;
8314 :
8315 : /* This diagnoses even signed/unsigned mismatches. Those might be
8316 : safe in many cases but GCC may emit suboptimal code for them so
8317 : warning on those cases drives efficiency improvements. */
8318 398 : if (warning_at (loc, OPT_Wbuiltin_declaration_mismatch,
8319 398 : TYPE_MAIN_VARIANT (promoted) == argtype
8320 : ? G_("%qD argument %d type is %qT where %qT is expected "
8321 : "in a call to built-in function declared without "
8322 : "prototype")
8323 : : G_("%qD argument %d promotes to %qT where %qT is expected "
8324 : "in a call to built-in function declared without "
8325 : "prototype"),
8326 : fundecl, parmnum, promoted, parmtype))
8327 150 : inform (DECL_SOURCE_LOCATION (fundecl),
8328 : "built-in %qD declared here",
8329 : fundecl);
8330 : }
8331 :
8332 : /* Print a declaration in quotes, with the given highlight_color.
8333 : Analogous to handler for %qD, but with a specific highlight color. */
8334 :
8335 199 : class pp_element_quoted_decl : public pp_element
8336 : {
8337 : public:
8338 199 : pp_element_quoted_decl (tree decl, const char *highlight_color)
8339 199 : : m_decl (decl),
8340 199 : m_highlight_color (highlight_color)
8341 : {
8342 : }
8343 :
8344 199 : void add_to_phase_2 (pp_markup::context &ctxt) override
8345 : {
8346 199 : ctxt.begin_quote ();
8347 199 : ctxt.begin_highlight_color (m_highlight_color);
8348 :
8349 199 : print_decl (ctxt);
8350 :
8351 199 : ctxt.end_highlight_color ();
8352 199 : ctxt.end_quote ();
8353 199 : }
8354 :
8355 199 : void print_decl (pp_markup::context &ctxt)
8356 : {
8357 199 : pretty_printer *const pp = &ctxt.m_pp;
8358 199 : pp->set_padding (pp_none);
8359 199 : if (DECL_NAME (m_decl))
8360 199 : pp_identifier (pp, lang_hooks.decl_printable_name (m_decl, 2));
8361 : else
8362 0 : pp_string (pp, _("({anonymous})"));
8363 199 : }
8364 :
8365 : private:
8366 : tree m_decl;
8367 : const char *m_highlight_color;
8368 : };
8369 :
8370 : /* If TYPE is from a typedef, issue a note showing the location
8371 : to the user.
8372 : Use HIGHLIGHT_COLOR as the highlight color. */
8373 :
8374 : static void
8375 1180 : maybe_inform_typedef_location (tree type, const char *highlight_color)
8376 : {
8377 1180 : if (!typedef_variant_p (type))
8378 1146 : return;
8379 :
8380 34 : tree typedef_decl = TYPE_NAME (type);
8381 34 : gcc_assert (TREE_CODE (typedef_decl) == TYPE_DECL);
8382 34 : gcc_rich_location richloc (DECL_SOURCE_LOCATION (typedef_decl),
8383 34 : nullptr, highlight_color);
8384 34 : pp_element_quoted_decl e_typedef_decl (typedef_decl, highlight_color);
8385 34 : inform (&richloc, "%e declared here", &e_typedef_decl);
8386 34 : }
8387 :
8388 : /* Convert value RHS to type TYPE as preparation for an assignment to
8389 : an lvalue of type TYPE. If ORIGTYPE is not NULL_TREE, it is the
8390 : original type of RHS; this differs from TREE_TYPE (RHS) for enum
8391 : types. NULL_POINTER_CONSTANT says whether RHS was a null pointer
8392 : constant before any folding.
8393 : The real work of conversion is done by `convert'.
8394 : The purpose of this function is to generate error messages
8395 : for assignments that are not allowed in C.
8396 : ERRTYPE says whether it is argument passing, assignment,
8397 : initialization or return.
8398 :
8399 : In the following example, '~' denotes where EXPR_LOC and '^' where
8400 : LOCATION point to:
8401 :
8402 : f (var); [ic_argpass]
8403 : ^ ~~~
8404 : x = var; [ic_assign]
8405 : ^ ~~~;
8406 : int x = var; [ic_init]
8407 : ^^^
8408 : return x; [ic_return]
8409 : ^
8410 :
8411 : FUNCTION is a tree for the function being called.
8412 : PARMNUM is the number of the argument, for printing in error messages.
8413 : WARNOPT may be set to a warning option to issue the corresponding warning
8414 : rather than an error for invalid conversions. Used for calls to built-in
8415 : functions declared without a prototype. */
8416 :
8417 : static tree
8418 171654677 : convert_for_assignment (location_t location, location_t expr_loc, tree type,
8419 : tree rhs, tree origtype, enum impl_conv errtype,
8420 : bool null_pointer_constant, tree fundecl,
8421 : tree function, int parmnum, int warnopt /* = 0 */)
8422 : {
8423 171654677 : enum tree_code codel = TREE_CODE (type);
8424 171654677 : tree orig_rhs = rhs;
8425 171654677 : tree rhstype;
8426 171654677 : enum tree_code coder;
8427 171654677 : tree rname = NULL_TREE;
8428 171654677 : bool objc_ok = false;
8429 :
8430 : /* Use the expansion point location to handle cases such as user's
8431 : function returning a wrong-type macro defined in a system header. */
8432 171654677 : location = expansion_point_location_if_in_system_header (location);
8433 :
8434 171654677 : if (errtype == ic_argpass)
8435 : {
8436 129119743 : tree selector;
8437 : /* Change pointer to function to the function itself for
8438 : diagnostics. */
8439 129119743 : if (TREE_CODE (function) == ADDR_EXPR
8440 129119743 : && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL)
8441 0 : function = TREE_OPERAND (function, 0);
8442 :
8443 : /* Handle an ObjC selector specially for diagnostics. */
8444 129119743 : selector = objc_message_selector ();
8445 129119743 : rname = function;
8446 129119743 : if (selector && parmnum > 2)
8447 : {
8448 0 : rname = selector;
8449 0 : parmnum -= 2;
8450 : }
8451 : }
8452 :
8453 : /* This macro is used to emit diagnostics to ensure that all format
8454 : strings are complete sentences, visible to gettext and checked at
8455 : compile time. */
8456 : #define PEDWARN_FOR_ASSIGNMENT(LOCATION, PLOC, OPT, AR, AS, IN, RE) \
8457 : do { \
8458 : switch (errtype) \
8459 : { \
8460 : case ic_argpass: \
8461 : { \
8462 : auto_diagnostic_group d; \
8463 : if (pedwarn (PLOC, OPT, AR, parmnum, rname)) \
8464 : inform_for_arg (fundecl, (PLOC), parmnum, type, rhstype); \
8465 : } \
8466 : break; \
8467 : case ic_assign: \
8468 : pedwarn (LOCATION, OPT, AS); \
8469 : break; \
8470 : case ic_init: \
8471 : case ic_init_const: \
8472 : pedwarn_init (LOCATION, OPT, IN); \
8473 : break; \
8474 : case ic_return: \
8475 : pedwarn (LOCATION, OPT, RE); \
8476 : break; \
8477 : default: \
8478 : gcc_unreachable (); \
8479 : } \
8480 : } while (0)
8481 :
8482 : /* This macro is used to emit diagnostics to ensure that all format
8483 : strings are complete sentences, visible to gettext and checked at
8484 : compile time. It can be called with 'pedwarn' or 'warning_at'. */
8485 : #define WARNING_FOR_QUALIFIERS(PEDWARN, LOCATION, PLOC, OPT, AR, AS, IN, RE, QUALS) \
8486 : do { \
8487 : switch (errtype) \
8488 : { \
8489 : case ic_argpass: \
8490 : { \
8491 : auto_diagnostic_group d; \
8492 : if (PEDWARN) { \
8493 : if (pedwarn (PLOC, OPT, AR, parmnum, rname, QUALS)) \
8494 : inform_for_arg (fundecl, (PLOC), parmnum, type, rhstype); \
8495 : } else { \
8496 : if (warning_at (PLOC, OPT, AR, parmnum, rname, QUALS)) \
8497 : inform_for_arg (fundecl, (PLOC), parmnum, type, rhstype); \
8498 : } \
8499 : } \
8500 : break; \
8501 : case ic_assign: \
8502 : if (PEDWARN) \
8503 : pedwarn (LOCATION, OPT, AS, QUALS); \
8504 : else \
8505 : warning_at (LOCATION, OPT, AS, QUALS); \
8506 : break; \
8507 : case ic_init: \
8508 : case ic_init_const: \
8509 : if (PEDWARN) \
8510 : pedwarn (LOCATION, OPT, IN, QUALS); \
8511 : else \
8512 : warning_at (LOCATION, OPT, IN, QUALS); \
8513 : break; \
8514 : case ic_return: \
8515 : if (PEDWARN) \
8516 : pedwarn (LOCATION, OPT, RE, QUALS); \
8517 : else \
8518 : warning_at (LOCATION, OPT, RE, QUALS); \
8519 : break; \
8520 : default: \
8521 : gcc_unreachable (); \
8522 : } \
8523 : } while (0)
8524 :
8525 : /* This macro is used to emit diagnostics to ensure that all format
8526 : strings are complete sentences, visible to gettext and checked at
8527 : compile time. It is the same as PEDWARN_FOR_ASSIGNMENT but with an
8528 : extra parameter to enumerate qualifiers. */
8529 : #define PEDWARN_FOR_QUALIFIERS(LOCATION, PLOC, OPT, AR, AS, IN, RE, QUALS) \
8530 : WARNING_FOR_QUALIFIERS (true, LOCATION, PLOC, OPT, AR, AS, IN, RE, QUALS)
8531 :
8532 :
8533 171654677 : if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
8534 5985 : rhs = TREE_OPERAND (rhs, 0);
8535 :
8536 171654677 : rhstype = TREE_TYPE (rhs);
8537 171654677 : coder = TREE_CODE (rhstype);
8538 :
8539 171654677 : if (coder == ERROR_MARK)
8540 347 : return error_mark_node;
8541 :
8542 171654330 : if (c_dialect_objc ())
8543 : {
8544 0 : int parmno;
8545 :
8546 0 : switch (errtype)
8547 : {
8548 : case ic_return:
8549 : parmno = 0;
8550 : break;
8551 :
8552 : case ic_assign:
8553 : parmno = -1;
8554 : break;
8555 :
8556 : case ic_init:
8557 : case ic_init_const:
8558 : parmno = -2;
8559 : break;
8560 :
8561 : default:
8562 0 : parmno = parmnum;
8563 : break;
8564 : }
8565 :
8566 0 : objc_ok = objc_compare_types (type, rhstype, parmno, rname);
8567 : }
8568 :
8569 171654330 : if (warn_cxx_compat)
8570 : {
8571 29134 : tree checktype = origtype != NULL_TREE ? origtype : rhstype;
8572 29134 : if (checktype != error_mark_node
8573 29134 : && TREE_CODE (type) == ENUMERAL_TYPE
8574 29240 : && TYPE_MAIN_VARIANT (checktype) != TYPE_MAIN_VARIANT (type))
8575 45 : switch (errtype)
8576 : {
8577 8 : case ic_argpass:
8578 8 : if (pedwarn (expr_loc, OPT_Wc___compat, "enum conversion when "
8579 : "passing argument %d of %qE is invalid in C++",
8580 : parmnum, rname))
8581 16 : inform ((fundecl && !DECL_IS_UNDECLARED_BUILTIN (fundecl))
8582 8 : ? DECL_SOURCE_LOCATION (fundecl) : expr_loc,
8583 : "expected %qT but argument is of type %qT",
8584 : type, rhstype);
8585 : break;
8586 10 : case ic_assign:
8587 10 : pedwarn (location, OPT_Wc___compat, "enum conversion from %qT to "
8588 : "%qT in assignment is invalid in C++", rhstype, type);
8589 10 : break;
8590 18 : case ic_init:
8591 18 : case ic_init_const:
8592 18 : pedwarn_init (location, OPT_Wc___compat, "enum conversion from "
8593 : "%qT to %qT in initialization is invalid in C++",
8594 : rhstype, type);
8595 18 : break;
8596 9 : case ic_return:
8597 9 : pedwarn (location, OPT_Wc___compat, "enum conversion from %qT to "
8598 : "%qT in return is invalid in C++", rhstype, type);
8599 9 : break;
8600 0 : default:
8601 0 : gcc_unreachable ();
8602 : }
8603 : }
8604 :
8605 171654330 : if (warn_enum_conversion)
8606 : {
8607 14902028 : tree checktype = origtype != NULL_TREE ? origtype : rhstype;
8608 14902028 : if (checktype != error_mark_node
8609 14902028 : && TREE_CODE (checktype) == ENUMERAL_TYPE
8610 12851 : && TREE_CODE (type) == ENUMERAL_TYPE
8611 14910332 : && !comptypes (TYPE_MAIN_VARIANT (checktype), TYPE_MAIN_VARIANT (type)))
8612 : {
8613 7 : gcc_rich_location loc (location);
8614 7 : warning_at (&loc, OPT_Wenum_conversion,
8615 : "implicit conversion from %qT to %qT",
8616 : checktype, type);
8617 7 : }
8618 : }
8619 :
8620 171654330 : if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype))
8621 : {
8622 152354100 : warn_for_address_of_packed_member (type, orig_rhs);
8623 152354100 : if (type != rhstype)
8624 : /* Convert RHS to TYPE in order to not lose TYPE in diagnostics. */
8625 37878776 : rhs = convert (type, rhs);
8626 : return rhs;
8627 : }
8628 :
8629 19300230 : if (coder == VOID_TYPE)
8630 : {
8631 : /* Except for passing an argument to an unprototyped function,
8632 : this is a constraint violation. When passing an argument to
8633 : an unprototyped function, it is compile-time undefined;
8634 : making it a constraint in that case was rejected in
8635 : DR#252. */
8636 8 : const char msg[] = "void value not ignored as it ought to be";
8637 8 : if (warnopt)
8638 0 : warning_at (location, warnopt, msg);
8639 : else
8640 8 : error_at (location, msg);
8641 8 : return error_mark_node;
8642 : }
8643 19300222 : rhs = require_complete_type (location, rhs);
8644 19300222 : if (rhs == error_mark_node)
8645 : return error_mark_node;
8646 :
8647 19300222 : if (coder == POINTER_TYPE && reject_gcc_builtin (rhs))
8648 6 : return error_mark_node;
8649 :
8650 : /* A non-reference type can convert to a reference. This handles
8651 : va_start, va_copy and possibly port built-ins. */
8652 19300216 : if (codel == REFERENCE_TYPE && coder != REFERENCE_TYPE)
8653 : {
8654 286 : if (!lvalue_p (rhs))
8655 : {
8656 0 : const char msg[] = "cannot pass rvalue to reference parameter";
8657 0 : if (warnopt)
8658 0 : warning_at (location, warnopt, msg);
8659 : else
8660 0 : error_at (location, msg);
8661 0 : return error_mark_node;
8662 : }
8663 286 : if (!c_mark_addressable (rhs))
8664 0 : return error_mark_node;
8665 286 : rhs = build1 (ADDR_EXPR, c_build_pointer_type (TREE_TYPE (rhs)), rhs);
8666 286 : SET_EXPR_LOCATION (rhs, location);
8667 :
8668 286 : rhs = convert_for_assignment (location, expr_loc,
8669 286 : c_build_pointer_type (TREE_TYPE (type)),
8670 : rhs, origtype, errtype,
8671 : null_pointer_constant, fundecl, function,
8672 : parmnum, warnopt);
8673 286 : if (rhs == error_mark_node)
8674 : return error_mark_node;
8675 :
8676 286 : rhs = build1 (NOP_EXPR, type, rhs);
8677 286 : SET_EXPR_LOCATION (rhs, location);
8678 286 : return rhs;
8679 : }
8680 : /* Some types can interconvert without explicit casts. */
8681 19299930 : else if (codel == VECTOR_TYPE && coder == VECTOR_TYPE
8682 19299930 : && vector_types_convertible_p (type, TREE_TYPE (rhs), true))
8683 9332938 : return convert (type, rhs);
8684 : /* Arithmetic types all interconvert, and enum is treated like int. */
8685 9966992 : else if ((codel == INTEGER_TYPE || codel == REAL_TYPE
8686 2296629 : || codel == FIXED_POINT_TYPE
8687 2296629 : || codel == ENUMERAL_TYPE || codel == COMPLEX_TYPE
8688 2210052 : || codel == BOOLEAN_TYPE || codel == BITINT_TYPE)
8689 7857736 : && (coder == INTEGER_TYPE || coder == REAL_TYPE
8690 83924 : || coder == FIXED_POINT_TYPE
8691 83924 : || coder == ENUMERAL_TYPE || coder == COMPLEX_TYPE
8692 40652 : || coder == BOOLEAN_TYPE || coder == BITINT_TYPE))
8693 : {
8694 7856359 : if (warnopt && errtype == ic_argpass)
8695 418 : maybe_warn_builtin_no_proto_arg (expr_loc, fundecl, parmnum, type,
8696 : rhstype);
8697 :
8698 7856359 : bool save = in_late_binary_op;
8699 7819139 : if (C_BOOLEAN_TYPE_P (type) || codel == COMPLEX_TYPE
8700 15618333 : || (coder == REAL_TYPE
8701 277017 : && (codel == INTEGER_TYPE || codel == ENUMERAL_TYPE)
8702 24222 : && sanitize_flags_p (SANITIZE_FLOAT_CAST)))
8703 101129 : in_late_binary_op = true;
8704 11253647 : tree ret = convert_and_check (expr_loc != UNKNOWN_LOCATION
8705 : ? expr_loc : location, type, orig_rhs,
8706 : errtype == ic_init_const);
8707 7856359 : in_late_binary_op = save;
8708 7856359 : return ret;
8709 : }
8710 :
8711 : /* Aggregates in different TUs might need conversion. */
8712 2110633 : if ((codel == RECORD_TYPE || codel == UNION_TYPE)
8713 105 : && codel == coder
8714 2110655 : && comptypes (TYPE_MAIN_VARIANT (type), TYPE_MAIN_VARIANT (rhstype)))
8715 9 : return convert_and_check (expr_loc != UNKNOWN_LOCATION
8716 9 : ? expr_loc : location, type, rhs);
8717 :
8718 : /* Conversion to a transparent union or record from its member types.
8719 : This applies only to function arguments. */
8720 2110624 : if (((codel == UNION_TYPE || codel == RECORD_TYPE)
8721 96 : && TYPE_TRANSPARENT_AGGR (type))
8722 2110663 : && errtype == ic_argpass)
8723 : {
8724 39 : tree memb, marginal_memb = NULL_TREE;
8725 :
8726 50 : for (memb = TYPE_FIELDS (type); memb ; memb = DECL_CHAIN (memb))
8727 : {
8728 50 : tree memb_type = TREE_TYPE (memb);
8729 :
8730 50 : if (comptypes (TYPE_MAIN_VARIANT (memb_type),
8731 50 : TYPE_MAIN_VARIANT (rhstype)))
8732 : break;
8733 :
8734 27 : if (TREE_CODE (memb_type) != POINTER_TYPE)
8735 1 : continue;
8736 :
8737 26 : if (coder == POINTER_TYPE)
8738 : {
8739 26 : tree ttl = TREE_TYPE (memb_type);
8740 26 : tree ttr = TREE_TYPE (rhstype);
8741 :
8742 : /* Any non-function converts to a [const][volatile] void *
8743 : and vice versa; otherwise, targets must be the same.
8744 : Meanwhile, the lhs target must have all the qualifiers of
8745 : the rhs. */
8746 0 : if ((VOID_TYPE_P (ttl) && !TYPE_ATOMIC (ttl))
8747 26 : || (VOID_TYPE_P (ttr) && !TYPE_ATOMIC (ttr))
8748 45 : || comp_target_types (location, memb_type, rhstype))
8749 : {
8750 16 : int lquals = TYPE_QUALS (ttl) & ~TYPE_QUAL_ATOMIC;
8751 16 : int rquals = TYPE_QUALS (ttr) & ~TYPE_QUAL_ATOMIC;
8752 : /* If this type won't generate any warnings, use it. */
8753 16 : if (lquals == rquals
8754 16 : || ((TREE_CODE (ttr) == FUNCTION_TYPE
8755 0 : && TREE_CODE (ttl) == FUNCTION_TYPE)
8756 0 : ? ((lquals | rquals) == rquals)
8757 16 : : ((lquals | rquals) == lquals)))
8758 : break;
8759 :
8760 : /* Keep looking for a better type, but remember this one. */
8761 0 : if (!marginal_memb)
8762 10 : marginal_memb = memb;
8763 : }
8764 : }
8765 :
8766 : /* Can convert integer zero to any pointer type. */
8767 10 : if (null_pointer_constant)
8768 : {
8769 0 : rhs = null_pointer_node;
8770 0 : break;
8771 : }
8772 : }
8773 :
8774 39 : if (memb || marginal_memb)
8775 : {
8776 39 : if (!memb)
8777 : {
8778 : /* We have only a marginally acceptable member type;
8779 : it needs a warning. */
8780 0 : tree ttl = TREE_TYPE (TREE_TYPE (marginal_memb));
8781 0 : tree ttr = TREE_TYPE (rhstype);
8782 :
8783 : /* Const and volatile mean something different for function
8784 : types, so the usual warnings are not appropriate. */
8785 0 : if (TREE_CODE (ttr) == FUNCTION_TYPE
8786 0 : && TREE_CODE (ttl) == FUNCTION_TYPE)
8787 : {
8788 : /* Because const and volatile on functions are
8789 : restrictions that say the function will not do
8790 : certain things, it is okay to use a const or volatile
8791 : function where an ordinary one is wanted, but not
8792 : vice-versa. */
8793 0 : if (TYPE_QUALS_NO_ADDR_SPACE (ttl)
8794 0 : & ~TYPE_QUALS_NO_ADDR_SPACE (ttr))
8795 0 : PEDWARN_FOR_QUALIFIERS (location, expr_loc,
8796 : OPT_Wdiscarded_qualifiers,
8797 : G_("passing argument %d of %qE "
8798 : "makes %q#v qualified function "
8799 : "pointer from unqualified"),
8800 : G_("assignment makes %q#v qualified "
8801 : "function pointer from "
8802 : "unqualified"),
8803 : G_("initialization makes %q#v qualified "
8804 : "function pointer from "
8805 : "unqualified"),
8806 : G_("return makes %q#v qualified function "
8807 : "pointer from unqualified"),
8808 : TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr));
8809 : }
8810 0 : else if (TYPE_QUALS_NO_ADDR_SPACE (ttr)
8811 0 : & ~TYPE_QUALS_NO_ADDR_SPACE (ttl))
8812 0 : PEDWARN_FOR_QUALIFIERS (location, expr_loc,
8813 : OPT_Wdiscarded_qualifiers,
8814 : G_("passing argument %d of %qE discards "
8815 : "%qv qualifier from pointer target type"),
8816 : G_("assignment discards %qv qualifier "
8817 : "from pointer target type"),
8818 : G_("initialization discards %qv qualifier "
8819 : "from pointer target type"),
8820 : G_("return discards %qv qualifier from "
8821 : "pointer target type"),
8822 : TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl));
8823 :
8824 : memb = marginal_memb;
8825 : }
8826 :
8827 39 : if (!fundecl || !DECL_IN_SYSTEM_HEADER (fundecl))
8828 31 : pedwarn (location, OPT_Wpedantic,
8829 : "ISO C prohibits argument conversion to union type");
8830 :
8831 39 : rhs = fold_convert_loc (location, TREE_TYPE (memb), rhs);
8832 39 : return build_constructor_single (type, memb, rhs);
8833 : }
8834 : }
8835 :
8836 : /* Conversions among pointers */
8837 2110585 : else if ((codel == POINTER_TYPE || codel == REFERENCE_TYPE)
8838 2109052 : && (coder == codel))
8839 : {
8840 : /* If RHS refers to a built-in declared without a prototype
8841 : BLTIN is the declaration of the built-in with a prototype
8842 : and RHSTYPE is set to the actual type of the built-in. */
8843 2030592 : tree bltin;
8844 2030592 : rhstype = type_or_builtin_type (rhs, &bltin);
8845 :
8846 2030592 : tree ttl = TREE_TYPE (type);
8847 2030592 : tree ttr = TREE_TYPE (rhstype);
8848 2030592 : bool is_opaque_pointer;
8849 2030592 : bool target_cmp = false; /* Cache comp_target_types () result. */
8850 2030592 : addr_space_t asl;
8851 2030592 : addr_space_t asr;
8852 :
8853 2030592 : tree mvl = remove_qualifiers (ttl);
8854 2030592 : tree mvr = remove_qualifiers (ttr);
8855 :
8856 : /* Opaque pointers are treated like void pointers. */
8857 2030592 : is_opaque_pointer = vector_targets_convertible_p (ttl, ttr);
8858 :
8859 : /* The Plan 9 compiler permits a pointer to a struct to be
8860 : automatically converted into a pointer to an anonymous field
8861 : within the struct. */
8862 2030592 : if (flag_plan9_extensions
8863 50 : && RECORD_OR_UNION_TYPE_P (mvl)
8864 26 : && RECORD_OR_UNION_TYPE_P (mvr)
8865 26 : && mvl != mvr)
8866 : {
8867 26 : tree new_rhs = convert_to_anonymous_field (location, type, rhs);
8868 26 : if (new_rhs != NULL_TREE)
8869 : {
8870 22 : rhs = new_rhs;
8871 22 : rhstype = TREE_TYPE (rhs);
8872 22 : coder = TREE_CODE (rhstype);
8873 22 : ttr = TREE_TYPE (rhstype);
8874 22 : mvr = TYPE_MAIN_VARIANT (ttr);
8875 : }
8876 : }
8877 :
8878 : /* C++ does not allow the implicit conversion void* -> T*. However,
8879 : for the purpose of reducing the number of false positives, we
8880 : tolerate the special case of
8881 :
8882 : int *p = NULL;
8883 :
8884 : where NULL is typically defined in C to be '(void *) 0'. */
8885 2030592 : if (VOID_TYPE_P (ttr) && rhs != null_pointer_node && !VOID_TYPE_P (ttl))
8886 27439 : warning_at (errtype == ic_argpass ? expr_loc : location,
8887 14543 : OPT_Wc___compat,
8888 : "request for implicit conversion "
8889 : "from %qT to %qT not permitted in C++", rhstype, type);
8890 :
8891 : /* Warn of new allocations that are not big enough for the target
8892 : type. */
8893 2030592 : if (warn_alloc_size && TREE_CODE (rhs) == CALL_EXPR)
8894 5463 : if (tree fndecl = get_callee_fndecl (rhs))
8895 5463 : if (DECL_IS_MALLOC (fndecl))
8896 : {
8897 4614 : tree attrs = TYPE_ATTRIBUTES (TREE_TYPE (fndecl));
8898 4614 : tree alloc_size = lookup_attribute ("alloc_size", attrs);
8899 4614 : if (alloc_size)
8900 451 : warn_for_alloc_size (location, ttl, rhs, alloc_size);
8901 : }
8902 :
8903 : /* See if the pointers point to incompatible address spaces. */
8904 2030592 : asl = TYPE_ADDR_SPACE (ttl);
8905 2030592 : asr = TYPE_ADDR_SPACE (ttr);
8906 2030592 : if (!null_pointer_constant_p (rhs)
8907 2030592 : && asr != asl && !targetm.addr_space.subset_p (asr, asl))
8908 : {
8909 3 : auto_diagnostic_group d;
8910 3 : bool diagnosed = true;
8911 3 : switch (errtype)
8912 : {
8913 1 : case ic_argpass:
8914 1 : {
8915 1 : const char msg[] = G_("passing argument %d of %qE from "
8916 : "pointer to non-enclosed address space");
8917 1 : if (warnopt)
8918 0 : diagnosed
8919 0 : = warning_at (expr_loc, warnopt, msg, parmnum, rname);
8920 : else
8921 1 : error_at (expr_loc, msg, parmnum, rname);
8922 0 : break;
8923 : }
8924 0 : case ic_assign:
8925 0 : {
8926 0 : const char msg[] = G_("assignment from pointer to "
8927 : "non-enclosed address space");
8928 0 : if (warnopt)
8929 0 : diagnosed = warning_at (location, warnopt, msg);
8930 : else
8931 0 : error_at (location, msg);
8932 0 : break;
8933 : }
8934 0 : case ic_init:
8935 0 : case ic_init_const:
8936 0 : {
8937 0 : const char msg[] = G_("initialization from pointer to "
8938 : "non-enclosed address space");
8939 0 : if (warnopt)
8940 0 : diagnosed = warning_at (location, warnopt, msg);
8941 : else
8942 0 : error_at (location, msg);
8943 0 : break;
8944 : }
8945 2 : case ic_return:
8946 2 : {
8947 2 : const char msg[] = G_("return from pointer to "
8948 : "non-enclosed address space");
8949 2 : if (warnopt)
8950 0 : diagnosed = warning_at (location, warnopt, msg);
8951 : else
8952 2 : error_at (location, msg);
8953 0 : break;
8954 : }
8955 0 : default:
8956 0 : gcc_unreachable ();
8957 : }
8958 3 : if (diagnosed)
8959 : {
8960 3 : if (errtype == ic_argpass)
8961 1 : inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
8962 : else
8963 2 : inform (location, "expected %qT but pointer is of type %qT",
8964 : type, rhstype);
8965 : }
8966 3 : return error_mark_node;
8967 3 : }
8968 :
8969 : /* Check if the right-hand side has a format attribute but the
8970 : left-hand side doesn't. */
8971 2030589 : if (warn_suggest_attribute_format
8972 2030589 : && check_missing_format_attribute (type, rhstype))
8973 : {
8974 16 : switch (errtype)
8975 : {
8976 4 : case ic_argpass:
8977 4 : warning_at (expr_loc, OPT_Wsuggest_attribute_format,
8978 : "argument %d of %qE might be "
8979 : "a candidate for a format attribute",
8980 : parmnum, rname);
8981 4 : break;
8982 4 : case ic_assign:
8983 4 : warning_at (location, OPT_Wsuggest_attribute_format,
8984 : "assignment left-hand side might be "
8985 : "a candidate for a format attribute");
8986 4 : break;
8987 4 : case ic_init:
8988 4 : case ic_init_const:
8989 4 : warning_at (location, OPT_Wsuggest_attribute_format,
8990 : "initialization left-hand side might be "
8991 : "a candidate for a format attribute");
8992 4 : break;
8993 4 : case ic_return:
8994 4 : warning_at (location, OPT_Wsuggest_attribute_format,
8995 : "return type might be "
8996 : "a candidate for a format attribute");
8997 4 : break;
8998 0 : default:
8999 0 : gcc_unreachable ();
9000 : }
9001 : }
9002 :
9003 : /* See if the pointers point to incompatible scalar storage orders. */
9004 2030589 : if (warn_scalar_storage_order
9005 2027673 : && !null_pointer_constant_p (rhs)
9006 6017109 : && (AGGREGATE_TYPE_P (ttl) && TYPE_REVERSE_STORAGE_ORDER (ttl))
9007 1993260 : != (AGGREGATE_TYPE_P (ttr) && TYPE_REVERSE_STORAGE_ORDER (ttr)))
9008 : {
9009 18 : tree t;
9010 :
9011 18 : switch (errtype)
9012 : {
9013 11 : case ic_argpass:
9014 : /* Do not warn for built-in functions, for example memcpy, since we
9015 : control how they behave and they can be useful in this area. */
9016 11 : if (TREE_CODE (rname) != FUNCTION_DECL
9017 11 : || !fndecl_built_in_p (rname))
9018 1 : warning_at (location, OPT_Wscalar_storage_order,
9019 : "passing argument %d of %qE from incompatible "
9020 : "scalar storage order", parmnum, rname);
9021 : break;
9022 3 : case ic_assign:
9023 : /* Do not warn if the RHS is a call to a function that returns a
9024 : pointer that is not an alias. */
9025 3 : if (TREE_CODE (rhs) != CALL_EXPR
9026 2 : || (t = get_callee_fndecl (rhs)) == NULL_TREE
9027 5 : || !DECL_IS_MALLOC (t))
9028 1 : warning_at (location, OPT_Wscalar_storage_order,
9029 : "assignment to %qT from pointer type %qT with "
9030 : "incompatible scalar storage order", type, rhstype);
9031 : break;
9032 3 : case ic_init:
9033 3 : case ic_init_const:
9034 : /* Likewise. */
9035 3 : if (TREE_CODE (rhs) != CALL_EXPR
9036 2 : || (t = get_callee_fndecl (rhs)) == NULL_TREE
9037 5 : || !DECL_IS_MALLOC (t))
9038 1 : warning_at (location, OPT_Wscalar_storage_order,
9039 : "initialization of %qT from pointer type %qT with "
9040 : "incompatible scalar storage order", type, rhstype);
9041 : break;
9042 1 : case ic_return:
9043 1 : warning_at (location, OPT_Wscalar_storage_order,
9044 : "returning %qT from pointer type with incompatible "
9045 : "scalar storage order %qT", rhstype, type);
9046 1 : break;
9047 0 : default:
9048 0 : gcc_unreachable ();
9049 : }
9050 : }
9051 :
9052 : /* Any non-function converts to a [const][volatile] void *
9053 : and vice versa; otherwise, targets must be the same.
9054 : Meanwhile, the lhs target must have all the qualifiers of the rhs. */
9055 420753 : if ((VOID_TYPE_P (ttl) && !TYPE_ATOMIC (ttl))
9056 1609837 : || (VOID_TYPE_P (ttr) && !TYPE_ATOMIC (ttr))
9057 1561020 : || (target_cmp = comp_target_types (location, type, rhstype))
9058 2499 : || is_opaque_pointer
9059 2035587 : || ((c_common_unsigned_type (mvl)
9060 2499 : == c_common_unsigned_type (mvr))
9061 3444 : && (c_common_signed_type (mvl)
9062 1722 : == c_common_signed_type (mvr))
9063 1707 : && TYPE_ATOMIC (mvl) == TYPE_ATOMIC (mvr)))
9064 : {
9065 : /* Warn about loss of qualifers from pointers to arrays with
9066 : qualifiers on the element type. */
9067 2029789 : if (TREE_CODE (ttr) == ARRAY_TYPE)
9068 : {
9069 2131 : ttr = strip_array_types (ttr);
9070 2131 : ttl = strip_array_types (ttl);
9071 :
9072 2131 : if (TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttr)
9073 2131 : & ~TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttl))
9074 115 : WARNING_FOR_QUALIFIERS (flag_isoc23,
9075 : location, expr_loc,
9076 : OPT_Wdiscarded_array_qualifiers,
9077 : G_("passing argument %d of %qE discards "
9078 : "%qv qualifier from pointer target type"),
9079 : G_("assignment discards %qv qualifier "
9080 : "from pointer target type"),
9081 : G_("initialization discards %qv qualifier "
9082 : "from pointer target type"),
9083 : G_("return discards %qv qualifier from "
9084 : "pointer target type"),
9085 : TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl));
9086 : }
9087 2027658 : else if (pedantic
9088 146625 : && ((VOID_TYPE_P (ttl) && TREE_CODE (ttr) == FUNCTION_TYPE)
9089 146605 : ||
9090 : (VOID_TYPE_P (ttr)
9091 2923 : && !null_pointer_constant
9092 184 : && TREE_CODE (ttl) == FUNCTION_TYPE)))
9093 34 : PEDWARN_FOR_ASSIGNMENT (location, expr_loc, OPT_Wpedantic,
9094 : G_("ISO C forbids passing argument %d of "
9095 : "%qE between function pointer "
9096 : "and %<void *%>"),
9097 : G_("ISO C forbids assignment between "
9098 : "function pointer and %<void *%>"),
9099 : G_("ISO C forbids initialization between "
9100 : "function pointer and %<void *%>"),
9101 : G_("ISO C forbids return between function "
9102 : "pointer and %<void *%>"));
9103 : /* Const and volatile mean something different for function types,
9104 : so the usual warnings are not appropriate. */
9105 2027624 : else if (TREE_CODE (ttr) != FUNCTION_TYPE
9106 1995188 : && TREE_CODE (ttl) != FUNCTION_TYPE)
9107 : {
9108 : /* Assignments between atomic and non-atomic objects are OK. */
9109 1994449 : bool warn_quals_ped = TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttr)
9110 1994449 : & ~TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttl);
9111 1994449 : bool warn_quals = TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttr)
9112 1994449 : & ~TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (strip_array_types (ttl));
9113 :
9114 : /* Don't warn about loss of qualifier for conversions from
9115 : qualified void* to pointers to arrays with corresponding
9116 : qualifier on the element type (except for pedantic before C23). */
9117 1994449 : if (warn_quals || (warn_quals_ped && pedantic && !flag_isoc23))
9118 697 : PEDWARN_FOR_QUALIFIERS (location, expr_loc,
9119 : OPT_Wdiscarded_qualifiers,
9120 : G_("passing argument %d of %qE discards "
9121 : "%qv qualifier from pointer target type"),
9122 : G_("assignment discards %qv qualifier "
9123 : "from pointer target type"),
9124 : G_("initialization discards %qv qualifier "
9125 : "from pointer target type"),
9126 : G_("return discards %qv qualifier from "
9127 : "pointer target type"),
9128 : TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl));
9129 11 : else if (warn_quals_ped)
9130 11 : pedwarn_c11 (location, OPT_Wc11_c23_compat,
9131 : "array with qualifier on the element is not qualified before C23");
9132 :
9133 : /* If this is not a case of ignoring a mismatch in signedness,
9134 : no warning. */
9135 1993741 : else if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr)
9136 1556095 : || target_cmp)
9137 : ;
9138 : /* If there is a mismatch, do warn. */
9139 1699 : else if (warn_pointer_sign)
9140 82 : switch (errtype)
9141 : {
9142 33 : case ic_argpass:
9143 33 : {
9144 33 : auto_diagnostic_group d;
9145 33 : range_label_for_type_mismatch rhs_label (rhstype, type);
9146 33 : gcc_rich_location richloc (expr_loc, &rhs_label,
9147 33 : highlight_colors::actual);
9148 33 : if (pedwarn (&richloc, OPT_Wpointer_sign,
9149 : "pointer targets in passing argument %d of "
9150 : "%qE differ in signedness", parmnum, rname))
9151 33 : inform_for_arg (fundecl, expr_loc, parmnum, type,
9152 : rhstype);
9153 33 : }
9154 33 : break;
9155 21 : case ic_assign:
9156 21 : pedwarn (location, OPT_Wpointer_sign,
9157 : "pointer targets in assignment from %qT to %qT "
9158 : "differ in signedness", rhstype, type);
9159 21 : break;
9160 14 : case ic_init:
9161 14 : case ic_init_const:
9162 14 : pedwarn_init (location, OPT_Wpointer_sign,
9163 : "pointer targets in initialization of %qT "
9164 : "from %qT differ in signedness", type,
9165 : rhstype);
9166 14 : break;
9167 14 : case ic_return:
9168 14 : pedwarn (location, OPT_Wpointer_sign, "pointer targets in "
9169 : "returning %qT from a function with return type "
9170 : "%qT differ in signedness", rhstype, type);
9171 14 : break;
9172 0 : default:
9173 0 : gcc_unreachable ();
9174 : }
9175 : }
9176 33175 : else if (TREE_CODE (ttl) == FUNCTION_TYPE
9177 4193 : && TREE_CODE (ttr) == FUNCTION_TYPE)
9178 : {
9179 : /* Because const and volatile on functions are restrictions
9180 : that say the function will not do certain things,
9181 : it is okay to use a const or volatile function
9182 : where an ordinary one is wanted, but not vice-versa. */
9183 3454 : if (TYPE_QUALS_NO_ADDR_SPACE (ttl)
9184 3454 : & ~TYPE_QUALS_NO_ADDR_SPACE (ttr))
9185 18 : PEDWARN_FOR_QUALIFIERS (location, expr_loc,
9186 : OPT_Wdiscarded_qualifiers,
9187 : G_("passing argument %d of %qE makes "
9188 : "%q#v qualified function pointer "
9189 : "from unqualified"),
9190 : G_("assignment makes %q#v qualified function "
9191 : "pointer from unqualified"),
9192 : G_("initialization makes %q#v qualified "
9193 : "function pointer from unqualified"),
9194 : G_("return makes %q#v qualified function "
9195 : "pointer from unqualified"),
9196 : TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr));
9197 : }
9198 : }
9199 : /* Avoid warning about the volatile ObjC EH puts on decls. */
9200 800 : else if (!objc_ok)
9201 : {
9202 800 : auto_diagnostic_group d;
9203 800 : bool warned = false;
9204 800 : pp_markup::element_expected_type e_type (type);
9205 800 : pp_markup::element_actual_type e_rhstype (rhstype);
9206 800 : switch (errtype)
9207 : {
9208 307 : case ic_argpass:
9209 307 : {
9210 307 : range_label_for_type_mismatch rhs_label (rhstype, type);
9211 307 : gcc_rich_location richloc (expr_loc, &rhs_label,
9212 307 : highlight_colors::actual);
9213 307 : warned
9214 307 : = permerror_opt (&richloc, OPT_Wincompatible_pointer_types,
9215 : "passing argument %d of %qE from "
9216 : "incompatible pointer type",
9217 : parmnum, rname);
9218 307 : if (warned)
9219 175 : inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
9220 307 : }
9221 307 : break;
9222 267 : case ic_assign:
9223 267 : if (bltin)
9224 11 : warned
9225 11 : = permerror_opt (location, OPT_Wincompatible_pointer_types,
9226 : "assignment to %e from pointer to "
9227 : "%qD with incompatible type %e",
9228 : &e_type, bltin, &e_rhstype);
9229 : else
9230 256 : warned
9231 256 : = permerror_opt (location, OPT_Wincompatible_pointer_types,
9232 : "assignment to %e from incompatible "
9233 : "pointer type %e",
9234 : &e_type, &e_rhstype);
9235 : break;
9236 167 : case ic_init:
9237 167 : case ic_init_const:
9238 167 : if (bltin)
9239 13 : warned
9240 13 : = permerror_init (location, OPT_Wincompatible_pointer_types,
9241 : "initialization of %e from pointer to "
9242 : "%qD with incompatible type %e",
9243 : &e_type, bltin, &e_rhstype);
9244 : else
9245 154 : warned
9246 154 : = permerror_init (location, OPT_Wincompatible_pointer_types,
9247 : "initialization of %e from incompatible "
9248 : "pointer type %e",
9249 : &e_type, &e_rhstype);
9250 : break;
9251 59 : case ic_return:
9252 59 : if (bltin)
9253 11 : warned
9254 11 : = permerror_opt (location, OPT_Wincompatible_pointer_types,
9255 : "returning pointer to %qD of type %e from "
9256 : "a function with incompatible type %e",
9257 : bltin, &e_rhstype, &e_type);
9258 : else
9259 48 : warned
9260 48 : = permerror_opt (location, OPT_Wincompatible_pointer_types,
9261 : "returning %e from a function with "
9262 : "incompatible return type %e",
9263 : &e_rhstype, &e_type);
9264 : break;
9265 0 : default:
9266 0 : gcc_unreachable ();
9267 : }
9268 800 : if (warned)
9269 : {
9270 : /* If the mismatching function type is a pointer to a function,
9271 : try to show the decl of the function. */
9272 590 : if (TREE_CODE (rhs) == ADDR_EXPR
9273 590 : && TREE_CODE (TREE_OPERAND (rhs, 0)) == FUNCTION_DECL)
9274 : {
9275 191 : tree rhs_fndecl = TREE_OPERAND (rhs, 0);
9276 191 : if (!DECL_IS_UNDECLARED_BUILTIN (rhs_fndecl))
9277 : {
9278 165 : gcc_rich_location richloc
9279 165 : (DECL_SOURCE_LOCATION (rhs_fndecl), nullptr,
9280 165 : highlight_colors::actual);
9281 165 : pp_element_quoted_decl e_rhs_fndecl
9282 165 : (rhs_fndecl, highlight_colors::actual);
9283 165 : inform (&richloc,
9284 : "%e declared here", &e_rhs_fndecl);
9285 165 : }
9286 : }
9287 : /* If either/both of the types are typedefs, show the decl. */
9288 590 : maybe_inform_typedef_location (type,
9289 : highlight_colors::expected);
9290 590 : maybe_inform_typedef_location (rhstype,
9291 : highlight_colors::actual);
9292 : }
9293 800 : }
9294 :
9295 : /* If RHS isn't an address, check pointer or array of packed
9296 : struct or union. */
9297 2030589 : warn_for_address_of_packed_member (type, orig_rhs);
9298 :
9299 2030589 : return convert (type, rhs);
9300 : }
9301 79993 : else if (codel == POINTER_TYPE && coder == ARRAY_TYPE)
9302 : {
9303 : /* ??? This should not be an error when inlining calls to
9304 : unprototyped functions. */
9305 4 : const char msg[] = "invalid use of non-lvalue array";
9306 4 : if (warnopt)
9307 0 : warning_at (location, warnopt, msg);
9308 : else
9309 4 : error_at (location, msg);
9310 4 : return error_mark_node;
9311 : }
9312 79989 : else if (codel == POINTER_TYPE
9313 78456 : && (coder == INTEGER_TYPE
9314 78456 : || coder == ENUMERAL_TYPE
9315 620 : || coder == BOOLEAN_TYPE
9316 620 : || coder == NULLPTR_TYPE
9317 27 : || coder == BITINT_TYPE))
9318 : {
9319 78443 : if (null_pointer_constant && c_inhibit_evaluation_warnings == 0
9320 77445 : && coder != NULLPTR_TYPE)
9321 76881 : warning_at (location, OPT_Wzero_as_null_pointer_constant,
9322 : "zero as null pointer constant");
9323 : /* A NULLPTR type is just a nullptr always. */
9324 77879 : if (coder == NULLPTR_TYPE)
9325 579 : return omit_one_operand_loc (expr_loc, type, nullptr_node, rhs);
9326 : /* An explicit constant 0 or type nullptr_t can convert to a pointer,
9327 : or one that results from arithmetic, even including a cast to
9328 : integer type. */
9329 77864 : else if (!null_pointer_constant)
9330 972 : switch (errtype)
9331 : {
9332 800 : case ic_argpass:
9333 800 : {
9334 800 : auto_diagnostic_group d;
9335 800 : range_label_for_type_mismatch rhs_label (rhstype, type);
9336 800 : gcc_rich_location richloc (expr_loc, &rhs_label,
9337 800 : highlight_colors::actual);
9338 800 : if (permerror_opt (&richloc, OPT_Wint_conversion,
9339 : "passing argument %d of %qE makes pointer "
9340 : "from integer without a cast", parmnum, rname))
9341 : {
9342 439 : maybe_emit_indirection_note (expr_loc, rhs, type);
9343 439 : inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
9344 : }
9345 800 : }
9346 800 : break;
9347 93 : case ic_assign:
9348 93 : permerror_opt (location, OPT_Wint_conversion,
9349 : "assignment to %qT from %qT makes pointer from "
9350 : "integer without a cast", type, rhstype);
9351 93 : break;
9352 56 : case ic_init:
9353 56 : case ic_init_const:
9354 56 : permerror_init (location, OPT_Wint_conversion,
9355 : "initialization of %qT from %qT makes pointer "
9356 : "from integer without a cast", type, rhstype);
9357 56 : break;
9358 23 : case ic_return:
9359 23 : permerror_init (location, OPT_Wint_conversion,
9360 : "returning %qT from a function with return type "
9361 : "%qT makes pointer from integer without a cast",
9362 : rhstype, type);
9363 23 : break;
9364 0 : default:
9365 0 : gcc_unreachable ();
9366 : }
9367 :
9368 77864 : return convert (type, rhs);
9369 : }
9370 1546 : else if ((codel == INTEGER_TYPE || codel == BITINT_TYPE)
9371 540 : && coder == POINTER_TYPE)
9372 : {
9373 514 : switch (errtype)
9374 : {
9375 344 : case ic_argpass:
9376 344 : {
9377 344 : auto_diagnostic_group d;
9378 344 : range_label_for_type_mismatch rhs_label (rhstype, type);
9379 344 : gcc_rich_location richloc (expr_loc, &rhs_label,
9380 344 : highlight_colors::actual);
9381 344 : if (permerror_opt (&richloc, OPT_Wint_conversion,
9382 : "passing argument %d of %qE makes integer from "
9383 : "pointer without a cast", parmnum, rname))
9384 : {
9385 323 : maybe_emit_indirection_note (expr_loc, rhs, type);
9386 323 : inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
9387 : }
9388 344 : }
9389 344 : break;
9390 52 : case ic_assign:
9391 52 : permerror_opt (location, OPT_Wint_conversion,
9392 : "assignment to %qT from %qT makes integer from "
9393 : "pointer without a cast", type, rhstype);
9394 52 : break;
9395 83 : case ic_init:
9396 83 : case ic_init_const:
9397 83 : permerror_init (location, OPT_Wint_conversion,
9398 : "initialization of %qT from %qT makes integer "
9399 : "from pointer without a cast", type, rhstype);
9400 83 : break;
9401 35 : case ic_return:
9402 35 : permerror_opt (location, OPT_Wint_conversion, "returning %qT from a "
9403 : "function with return type %qT makes integer from "
9404 : "pointer without a cast", rhstype, type);
9405 35 : break;
9406 0 : default:
9407 0 : gcc_unreachable ();
9408 : }
9409 :
9410 514 : return convert (type, rhs);
9411 : }
9412 626 : else if (C_BOOLEAN_TYPE_P (type)
9413 : /* The type nullptr_t may be converted to bool. The
9414 : result is false. */
9415 1034 : && (coder == POINTER_TYPE || coder == NULLPTR_TYPE))
9416 : {
9417 408 : tree ret;
9418 408 : bool save = in_late_binary_op;
9419 408 : in_late_binary_op = true;
9420 408 : ret = convert (type, rhs);
9421 408 : in_late_binary_op = save;
9422 408 : return ret;
9423 : }
9424 624 : else if (codel == NULLPTR_TYPE && null_pointer_constant)
9425 6 : return convert (type, rhs);
9426 :
9427 618 : switch (errtype)
9428 : {
9429 35 : case ic_argpass:
9430 35 : {
9431 35 : auto_diagnostic_group d;
9432 35 : range_label_for_type_mismatch rhs_label (rhstype, type);
9433 35 : gcc_rich_location richloc (expr_loc, &rhs_label,
9434 35 : highlight_colors::actual);
9435 35 : const char msg[] = G_("incompatible type for argument %d of %qE");
9436 35 : if (warnopt)
9437 8 : warning_at (expr_loc, warnopt, msg, parmnum, rname);
9438 : else
9439 27 : error_at (&richloc, msg, parmnum, rname);
9440 35 : inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
9441 35 : }
9442 35 : break;
9443 108 : case ic_assign:
9444 108 : {
9445 108 : const char msg[]
9446 : = G_("incompatible types when assigning to type %qT from type %qT");
9447 108 : if (warnopt)
9448 0 : warning_at (expr_loc, 0, msg, type, rhstype);
9449 : else
9450 108 : error_at (expr_loc, msg, type, rhstype);
9451 108 : break;
9452 : }
9453 460 : case ic_init:
9454 460 : case ic_init_const:
9455 460 : {
9456 460 : const char msg[]
9457 : = G_("incompatible types when initializing type %qT using type %qT");
9458 460 : if (warnopt)
9459 0 : warning_at (location, 0, msg, type, rhstype);
9460 : else
9461 460 : error_at (location, msg, type, rhstype);
9462 460 : break;
9463 : }
9464 15 : case ic_return:
9465 15 : {
9466 15 : const char msg[]
9467 : = G_("incompatible types when returning type %qT but %qT was expected");
9468 15 : if (warnopt)
9469 0 : warning_at (location, 0, msg, rhstype, type);
9470 : else
9471 15 : error_at (location, msg, rhstype, type);
9472 15 : break;
9473 : }
9474 0 : default:
9475 0 : gcc_unreachable ();
9476 : }
9477 :
9478 618 : return error_mark_node;
9479 : }
9480 :
9481 : /* If VALUE is a compound expr all of whose expressions are constant, then
9482 : return its value. Otherwise, return error_mark_node.
9483 :
9484 : This is for handling COMPOUND_EXPRs as initializer elements
9485 : which is allowed with a warning when -pedantic is specified. */
9486 :
9487 : static tree
9488 2 : valid_compound_expr_initializer (tree value, tree endtype)
9489 : {
9490 2 : if (TREE_CODE (value) == COMPOUND_EXPR)
9491 : {
9492 1 : if (valid_compound_expr_initializer (TREE_OPERAND (value, 0), endtype)
9493 1 : == error_mark_node)
9494 : return error_mark_node;
9495 0 : return valid_compound_expr_initializer (TREE_OPERAND (value, 1),
9496 0 : endtype);
9497 : }
9498 1 : else if (!initializer_constant_valid_p (value, endtype))
9499 1 : return error_mark_node;
9500 : else
9501 : return value;
9502 : }
9503 :
9504 : /* Perform appropriate conversions on the initial value of a variable,
9505 : store it in the declaration DECL,
9506 : and print any error messages that are appropriate.
9507 : If ORIGTYPE is not NULL_TREE, it is the original type of INIT.
9508 : If the init is invalid, store an ERROR_MARK.
9509 :
9510 : INIT_LOC is the location of the initial value. */
9511 :
9512 : void
9513 7311405 : store_init_value (location_t init_loc, tree decl, tree init, tree origtype)
9514 : {
9515 7311405 : tree value, type;
9516 7311405 : bool npc = false;
9517 7311405 : bool int_const_expr = false;
9518 7311405 : bool arith_const_expr = false;
9519 :
9520 : /* If variable's type was invalidly declared, just ignore it. */
9521 :
9522 7311405 : type = TREE_TYPE (decl);
9523 7311405 : if (TREE_CODE (type) == ERROR_MARK)
9524 : return;
9525 :
9526 : /* Digest the specified initializer into an expression. */
9527 :
9528 7311397 : if (init)
9529 : {
9530 7311394 : npc = null_pointer_constant_p (init);
9531 7311394 : int_const_expr = (TREE_CODE (init) == INTEGER_CST
9532 423360 : && !TREE_OVERFLOW (init)
9533 7734718 : && INTEGRAL_TYPE_P (TREE_TYPE (init)));
9534 : /* Not fully determined before folding. */
9535 : arith_const_expr = true;
9536 : }
9537 7311397 : bool constexpr_p = (VAR_P (decl)
9538 7311397 : && C_DECL_DECLARED_CONSTEXPR (decl));
9539 7311397 : value = digest_init (init_loc, decl, type, init, origtype, npc,
9540 : int_const_expr, arith_const_expr, true,
9541 7311397 : TREE_STATIC (decl) || constexpr_p, constexpr_p);
9542 :
9543 : /* Store the expression if valid; else report error. */
9544 :
9545 7311397 : if (!in_system_header_at (input_location)
9546 7311397 : && AGGREGATE_TYPE_P (TREE_TYPE (decl)) && !TREE_STATIC (decl))
9547 29120 : warning (OPT_Wtraditional, "traditional C rejects automatic "
9548 : "aggregate initialization");
9549 :
9550 7311397 : if (value != error_mark_node || TREE_CODE (decl) != FUNCTION_DECL)
9551 7311396 : DECL_INITIAL (decl) = value;
9552 :
9553 : /* ANSI wants warnings about out-of-range constant initializers. */
9554 7311408 : STRIP_TYPE_NOPS (value);
9555 7311397 : if (TREE_STATIC (decl))
9556 181381 : constant_expression_warning (value);
9557 :
9558 : /* Check if we need to set array size from compound literal size. */
9559 7311397 : if (TREE_CODE (type) == ARRAY_TYPE
9560 26779 : && TYPE_DOMAIN (type) == NULL_TREE
9561 7324086 : && value != error_mark_node)
9562 : {
9563 : tree inside_init = init;
9564 :
9565 11817 : STRIP_TYPE_NOPS (inside_init);
9566 11817 : inside_init = fold (inside_init);
9567 :
9568 11817 : if (TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR)
9569 : {
9570 13 : tree cldecl = COMPOUND_LITERAL_EXPR_DECL (inside_init);
9571 :
9572 13 : if (TYPE_DOMAIN (TREE_TYPE (cldecl)))
9573 : {
9574 : /* For int foo[] = (int [3]){1}; we need to set array size
9575 : now since later on array initializer will be just the
9576 : brace enclosed list of the compound literal. */
9577 13 : tree etype = strip_array_types (TREE_TYPE (decl));
9578 13 : type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
9579 13 : TYPE_DOMAIN (type) = TYPE_DOMAIN (TREE_TYPE (cldecl));
9580 13 : layout_type (type);
9581 13 : layout_decl (cldecl, 0);
9582 13 : TREE_TYPE (decl)
9583 26 : = c_build_qualified_type (type, TYPE_QUALS (etype));
9584 : }
9585 : }
9586 : }
9587 : }
9588 :
9589 : /* Methods for storing and printing names for error messages. */
9590 :
9591 : /* Implement a spelling stack that allows components of a name to be pushed
9592 : and popped. Each element on the stack is this structure. */
9593 :
9594 : struct spelling
9595 : {
9596 : int kind;
9597 : union
9598 : {
9599 : unsigned HOST_WIDE_INT i;
9600 : const char *s;
9601 : } u;
9602 : };
9603 :
9604 : #define SPELLING_STRING 1
9605 : #define SPELLING_MEMBER 2
9606 : #define SPELLING_BOUNDS 3
9607 :
9608 : static struct spelling *spelling; /* Next stack element (unused). */
9609 : static struct spelling *spelling_base; /* Spelling stack base. */
9610 : static int spelling_size; /* Size of the spelling stack. */
9611 :
9612 : /* Macros to save and restore the spelling stack around push_... functions.
9613 : Alternative to SAVE_SPELLING_STACK. */
9614 :
9615 : #define SPELLING_DEPTH() (spelling - spelling_base)
9616 : #define RESTORE_SPELLING_DEPTH(DEPTH) (spelling = spelling_base + (DEPTH))
9617 :
9618 : /* Push an element on the spelling stack with type KIND and assign VALUE
9619 : to MEMBER. */
9620 :
9621 : #define PUSH_SPELLING(KIND, VALUE, MEMBER) \
9622 : { \
9623 : int depth = SPELLING_DEPTH (); \
9624 : \
9625 : if (depth >= spelling_size) \
9626 : { \
9627 : spelling_size += 10; \
9628 : spelling_base = XRESIZEVEC (struct spelling, spelling_base, \
9629 : spelling_size); \
9630 : RESTORE_SPELLING_DEPTH (depth); \
9631 : } \
9632 : \
9633 : spelling->kind = (KIND); \
9634 : spelling->MEMBER = (VALUE); \
9635 : spelling++; \
9636 : }
9637 :
9638 : /* Push STRING on the stack. Printed literally. */
9639 :
9640 : static void
9641 7308603 : push_string (const char *string)
9642 : {
9643 7308603 : PUSH_SPELLING (SPELLING_STRING, string, u.s);
9644 7308603 : }
9645 :
9646 : /* Push a member name on the stack. Printed as '.' STRING. */
9647 :
9648 : static void
9649 1231784 : push_member_name (tree decl)
9650 : {
9651 1231784 : const char *const string
9652 1231784 : = (DECL_NAME (decl)
9653 1231784 : ? identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl)))
9654 210 : : _("<anonymous>"));
9655 1231784 : PUSH_SPELLING (SPELLING_MEMBER, string, u.s);
9656 1231784 : }
9657 :
9658 : /* Push an array bounds on the stack. Printed as [BOUNDS]. */
9659 :
9660 : static void
9661 2606676 : push_array_bounds (unsigned HOST_WIDE_INT bounds)
9662 : {
9663 2606676 : PUSH_SPELLING (SPELLING_BOUNDS, bounds, u.i);
9664 2606676 : }
9665 :
9666 : /* Compute the maximum size in bytes of the printed spelling. */
9667 :
9668 : static int
9669 2892 : spelling_length (void)
9670 : {
9671 2892 : int size = 0;
9672 2892 : struct spelling *p;
9673 :
9674 6416 : for (p = spelling_base; p < spelling; p++)
9675 : {
9676 3524 : if (p->kind == SPELLING_BOUNDS)
9677 1479 : size += 25;
9678 : else
9679 2045 : size += strlen (p->u.s) + 1;
9680 : }
9681 :
9682 2892 : return size;
9683 : }
9684 :
9685 : /* Print the spelling to BUFFER and return it. */
9686 :
9687 : static char *
9688 2892 : print_spelling (char *buffer)
9689 : {
9690 2892 : char *d = buffer;
9691 2892 : struct spelling *p;
9692 :
9693 6416 : for (p = spelling_base; p < spelling; p++)
9694 3524 : if (p->kind == SPELLING_BOUNDS)
9695 : {
9696 1479 : sprintf (d, "[" HOST_WIDE_INT_PRINT_UNSIGNED "]", p->u.i);
9697 1479 : d += strlen (d);
9698 : }
9699 : else
9700 : {
9701 2045 : const char *s;
9702 2045 : if (p->kind == SPELLING_MEMBER)
9703 198 : *d++ = '.';
9704 16715 : for (s = p->u.s; (*d = *s++); d++)
9705 : ;
9706 : }
9707 2892 : *d++ = '\0';
9708 2892 : return buffer;
9709 : }
9710 :
9711 : /* Check whether INIT, a floating or integer constant, is
9712 : representable in TYPE, a real floating type with the same radix or
9713 : a decimal floating type initialized with a binary floating
9714 : constant. Return true if OK, false if not. */
9715 : static bool
9716 362 : constexpr_init_fits_real_type (tree type, tree init)
9717 : {
9718 362 : gcc_assert (SCALAR_FLOAT_TYPE_P (type));
9719 362 : gcc_assert (TREE_CODE (init) == INTEGER_CST || TREE_CODE (init) == REAL_CST);
9720 362 : if (TREE_CODE (init) == REAL_CST
9721 362 : && TYPE_MODE (TREE_TYPE (init)) == TYPE_MODE (type))
9722 : {
9723 : /* Same mode, no conversion required except for the case of
9724 : signaling NaNs if the types are incompatible (e.g. double and
9725 : long double with the same mode). */
9726 177 : if (REAL_VALUE_ISSIGNALING_NAN (TREE_REAL_CST (init))
9727 195 : && !comptypes (TYPE_MAIN_VARIANT (type),
9728 18 : TYPE_MAIN_VARIANT (TREE_TYPE (init))))
9729 0 : return false;
9730 : return true;
9731 : }
9732 185 : if (TREE_CODE (init) == INTEGER_CST)
9733 : {
9734 54 : tree converted = build_real_from_int_cst (type, init);
9735 54 : bool fail = false;
9736 108 : wide_int w = real_to_integer (&TREE_REAL_CST (converted), &fail,
9737 54 : TYPE_PRECISION (TREE_TYPE (init)));
9738 68 : return !fail && wi::eq_p (w, wi::to_wide (init));
9739 54 : }
9740 131 : if (REAL_VALUE_ISSIGNALING_NAN (TREE_REAL_CST (init)))
9741 : return false;
9742 114 : if ((REAL_VALUE_ISINF (TREE_REAL_CST (init))
9743 34 : && MODE_HAS_INFINITIES (TYPE_MODE (type)))
9744 218 : || (REAL_VALUE_ISNAN (TREE_REAL_CST (init))
9745 44 : && MODE_HAS_NANS (TYPE_MODE (type))))
9746 : return true;
9747 94 : if (DECIMAL_FLOAT_TYPE_P (type)
9748 134 : && !DECIMAL_FLOAT_TYPE_P (TREE_TYPE (init)))
9749 : {
9750 : /* This is valid if the real number represented by the
9751 : initializer can be exactly represented in the decimal
9752 : type. Compare the values using MPFR. */
9753 8 : REAL_VALUE_TYPE t;
9754 8 : real_convert (&t, TYPE_MODE (type), &TREE_REAL_CST (init));
9755 8 : mpfr_t bin_val, dec_val;
9756 8 : mpfr_init2 (bin_val, REAL_MODE_FORMAT (TYPE_MODE (TREE_TYPE (init)))->p);
9757 8 : mpfr_init2 (dec_val, REAL_MODE_FORMAT (TYPE_MODE (TREE_TYPE (init)))->p);
9758 8 : mpfr_from_real (bin_val, &TREE_REAL_CST (init), MPFR_RNDN);
9759 8 : char string[256];
9760 8 : real_to_decimal (string, &t, sizeof string, 0, 1);
9761 8 : bool res = (mpfr_strtofr (dec_val, string, NULL, 10, MPFR_RNDN) == 0
9762 8 : && mpfr_equal_p (bin_val, dec_val));
9763 8 : mpfr_clear (bin_val);
9764 8 : mpfr_clear (dec_val);
9765 8 : return res;
9766 : }
9767 : /* exact_real_truncate is not quite right here, since it doesn't
9768 : allow even an exact conversion to subnormal values. */
9769 86 : REAL_VALUE_TYPE t;
9770 86 : real_convert (&t, TYPE_MODE (type), &TREE_REAL_CST (init));
9771 86 : return real_identical (&t, &TREE_REAL_CST (init));
9772 : }
9773 :
9774 : /* Check whether INIT (location LOC) is valid as a 'constexpr'
9775 : initializer for type TYPE, and give an error if not. INIT has
9776 : already been folded and verified to be constant. INT_CONST_EXPR
9777 : and ARITH_CONST_EXPR say whether it is an integer constant
9778 : expression or arithmetic constant expression, respectively. If
9779 : TYPE is not a scalar type, this function does nothing. */
9780 :
9781 : static void
9782 942 : check_constexpr_init (location_t loc, tree type, tree init,
9783 : bool int_const_expr, bool arith_const_expr)
9784 : {
9785 942 : if (POINTER_TYPE_P (type))
9786 : {
9787 : /* The initializer must be null. */
9788 86 : if (TREE_CODE (init) != INTEGER_CST || !integer_zerop (init))
9789 8 : error_at (loc, "%<constexpr%> pointer initializer is not null");
9790 : return;
9791 : }
9792 856 : if (INTEGRAL_TYPE_P (type))
9793 : {
9794 : /* The initializer must be an integer constant expression,
9795 : representable in the target type. */
9796 346 : if (!int_const_expr)
9797 : {
9798 13 : if (TREE_CODE (init) == RAW_DATA_CST
9799 13 : && TYPE_PRECISION (type) == CHAR_BIT)
9800 : {
9801 4 : if (!TYPE_UNSIGNED (type))
9802 137 : for (unsigned int i = 0;
9803 140 : i < (unsigned) RAW_DATA_LENGTH (init); ++i)
9804 138 : if (RAW_DATA_SCHAR_ELT (init, i) < 0)
9805 : {
9806 1 : error_at (loc, "%<constexpr%> initializer not "
9807 : "representable in type of object");
9808 1 : break;
9809 : }
9810 : }
9811 : else
9812 9 : error_at (loc, "%<constexpr%> integer initializer is not an "
9813 : "integer constant expression");
9814 : }
9815 333 : else if (!int_fits_type_p (init, type))
9816 6 : error_at (loc, "%<constexpr%> initializer not representable in "
9817 : "type of object");
9818 : return;
9819 : }
9820 : /* We don't apply any extra checks to extension types such as vector
9821 : or fixed-point types. */
9822 510 : if (TREE_CODE (type) != REAL_TYPE && TREE_CODE (type) != COMPLEX_TYPE)
9823 : return;
9824 353 : if (!arith_const_expr)
9825 : {
9826 5 : error_at (loc, "%<constexpr%> initializer is not an arithmetic "
9827 : "constant expression");
9828 5 : return;
9829 : }
9830 : /* We don't apply any extra checks to complex integers. */
9831 348 : if (TREE_CODE (type) == COMPLEX_TYPE
9832 348 : && TREE_CODE (TREE_TYPE (type)) != REAL_TYPE)
9833 : return;
9834 : /* Following N3082, a real type cannot be initialized from a complex
9835 : type and a binary type cannot be initialized from a decimal type
9836 : (but initializing a decimal type from a binary type is OK).
9837 : Signaling NaN initializers are OK only if the types are
9838 : compatible (not just the same mode); all quiet NaN and infinity
9839 : initializations are considered to preserve the value. */
9840 348 : if (TREE_CODE (TREE_TYPE (init)) == COMPLEX_TYPE
9841 348 : && SCALAR_FLOAT_TYPE_P (type))
9842 : {
9843 6 : error_at (loc, "%<constexpr%> initializer for a real type is of "
9844 : "complex type");
9845 6 : return;
9846 : }
9847 342 : if (SCALAR_FLOAT_TYPE_P (type)
9848 300 : && SCALAR_FLOAT_TYPE_P (TREE_TYPE (init))
9849 250 : && DECIMAL_FLOAT_TYPE_P (TREE_TYPE (init))
9850 481 : && !DECIMAL_FLOAT_TYPE_P (type))
9851 : {
9852 6 : error_at (loc, "%<constexpr%> initializer for a binary "
9853 : "floating-point type is of decimal type");
9854 6 : return;
9855 : }
9856 336 : bool fits;
9857 336 : if (TREE_CODE (type) == COMPLEX_TYPE)
9858 : {
9859 42 : switch (TREE_CODE (init))
9860 : {
9861 10 : case INTEGER_CST:
9862 10 : case REAL_CST:
9863 10 : fits = constexpr_init_fits_real_type (TREE_TYPE (type), init);
9864 10 : break;
9865 32 : case COMPLEX_CST:
9866 32 : fits = (constexpr_init_fits_real_type (TREE_TYPE (type),
9867 32 : TREE_REALPART (init))
9868 58 : && constexpr_init_fits_real_type (TREE_TYPE (type),
9869 26 : TREE_IMAGPART (init)));
9870 : break;
9871 0 : default:
9872 0 : gcc_unreachable ();
9873 : }
9874 : }
9875 : else
9876 294 : fits = constexpr_init_fits_real_type (type, init);
9877 304 : if (!fits)
9878 65 : error_at (loc, "%<constexpr%> initializer not representable in "
9879 : "type of object");
9880 : }
9881 :
9882 : /* Digest the parser output INIT as an initializer for type TYPE
9883 : initializing DECL.
9884 : Return a C expression of type TYPE to represent the initial value.
9885 :
9886 : If ORIGTYPE is not NULL_TREE, it is the original type of INIT.
9887 :
9888 : NULL_POINTER_CONSTANT is true if INIT is a null pointer constant,
9889 : INT_CONST_EXPR is true if INIT is an integer constant expression,
9890 : and ARITH_CONST_EXPR is true if INIT is, or might be, an arithmetic
9891 : constant expression, false if it has already been determined in the
9892 : caller that it is not (but folding may have made the value passed here
9893 : indistinguishable from an arithmetic constant expression).
9894 :
9895 : If INIT is a string constant, STRICT_STRING is true if it is
9896 : unparenthesized or we should not warn here for it being parenthesized.
9897 : For other types of INIT, STRICT_STRING is not used.
9898 :
9899 : INIT_LOC is the location of the INIT.
9900 :
9901 : REQUIRE_CONSTANT requests an error if non-constant initializers or
9902 : elements are seen. REQUIRE_CONSTEXPR means the stricter requirements
9903 : on initializers for 'constexpr' objects apply. */
9904 :
9905 : static tree
9906 16979678 : digest_init (location_t init_loc, tree decl, tree type, tree init,
9907 : tree origtype, bool null_pointer_constant, bool int_const_expr,
9908 : bool arith_const_expr, bool strict_string,
9909 : bool require_constant, bool require_constexpr)
9910 : {
9911 16979678 : enum tree_code code = TREE_CODE (type);
9912 16979678 : tree inside_init = init;
9913 16979678 : tree semantic_type = NULL_TREE;
9914 16979678 : bool maybe_const = true;
9915 :
9916 16979678 : if (type == error_mark_node
9917 16979678 : || !init
9918 33959353 : || error_operand_p (init))
9919 : return error_mark_node;
9920 :
9921 16987155 : STRIP_TYPE_NOPS (inside_init);
9922 :
9923 : /* If require_constant is TRUE, when the initializer is a call to
9924 : .ACCESS_WITH_SIZE, use the first argument as the initializer.
9925 : For example:
9926 : y = (char *) .ACCESS_WITH_SIZE ((char *) &static_annotated.c,...)
9927 : will be converted to
9928 : y = &static_annotated.c. */
9929 :
9930 16978572 : if (require_constant
9931 2897179 : && TREE_CODE (inside_init) == NOP_EXPR
9932 736267 : && TREE_CODE (TREE_OPERAND (inside_init, 0)) == CALL_EXPR
9933 16978574 : && is_access_with_size_p (TREE_OPERAND (inside_init, 0)))
9934 2 : inside_init
9935 2 : = get_ref_from_access_with_size (TREE_OPERAND (inside_init, 0));
9936 :
9937 16978572 : if (!c_in_omp_for)
9938 : {
9939 16973818 : if (TREE_CODE (inside_init) == EXCESS_PRECISION_EXPR)
9940 : {
9941 441 : semantic_type = TREE_TYPE (inside_init);
9942 441 : inside_init = TREE_OPERAND (inside_init, 0);
9943 : }
9944 16973818 : inside_init = c_fully_fold (inside_init, require_constant, &maybe_const);
9945 : }
9946 : /* TODO: this may not detect all cases of expressions folding to
9947 : constants that are not arithmetic constant expressions. */
9948 16978572 : if (!maybe_const)
9949 : arith_const_expr = false;
9950 25334977 : else if (!INTEGRAL_TYPE_P (TREE_TYPE (inside_init))
9951 5679252 : && TREE_CODE (TREE_TYPE (inside_init)) != REAL_TYPE
9952 16905428 : && TREE_CODE (TREE_TYPE (inside_init)) != COMPLEX_TYPE)
9953 : arith_const_expr = false;
9954 8458228 : else if (TREE_CODE (inside_init) != INTEGER_CST
9955 : && TREE_CODE (inside_init) != REAL_CST
9956 : && TREE_CODE (inside_init) != COMPLEX_CST
9957 : && TREE_CODE (inside_init) != RAW_DATA_CST)
9958 : arith_const_expr = false;
9959 5100615 : else if (TREE_OVERFLOW (inside_init))
9960 11878001 : arith_const_expr = false;
9961 :
9962 : /* Initialization of an array of chars from a string constant
9963 : optionally enclosed in braces. */
9964 :
9965 16978572 : if (code == ARRAY_TYPE && inside_init
9966 189756 : && TREE_CODE (inside_init) == STRING_CST)
9967 : {
9968 11808 : tree typ1
9969 11808 : = (TYPE_ATOMIC (TREE_TYPE (type))
9970 11808 : ? c_build_qualified_type (TYPE_MAIN_VARIANT (TREE_TYPE (type)),
9971 : TYPE_QUAL_ATOMIC)
9972 11794 : : TYPE_MAIN_VARIANT (TREE_TYPE (type)));
9973 : /* Note that an array could be both an array of character type
9974 : and an array of wchar_t if wchar_t is signed char or unsigned
9975 : char. */
9976 23616 : bool char_array = (typ1 == char_type_node
9977 516 : || typ1 == signed_char_type_node
9978 12289 : || typ1 == unsigned_char_type_node);
9979 11808 : bool wchar_array = comptypes (typ1, wchar_type_node);
9980 11808 : bool char16_array = comptypes (typ1, char16_type_node);
9981 11808 : bool char32_array = comptypes (typ1, char32_type_node);
9982 :
9983 11808 : if (char_array || wchar_array || char16_array || char32_array)
9984 : {
9985 11779 : struct c_expr expr;
9986 11779 : tree typ2 = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init)));
9987 11779 : bool incompat_string_cst = false;
9988 11779 : expr.value = inside_init;
9989 11779 : expr.original_code = (strict_string ? STRING_CST : ERROR_MARK);
9990 11779 : expr.original_type = NULL;
9991 11779 : expr.m_decimal = 0;
9992 11779 : maybe_warn_string_init (init_loc, type, expr);
9993 :
9994 11779 : if (flexible_array_member_type_p (type))
9995 61 : pedwarn_init (init_loc, OPT_Wpedantic,
9996 : "initialization of a flexible array member");
9997 :
9998 11779 : if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
9999 11779 : TYPE_MAIN_VARIANT (type)))
10000 : return inside_init;
10001 :
10002 4186 : if (char_array)
10003 : {
10004 4075 : if (typ2 != char_type_node && typ2 != char8_type_node)
10005 : incompat_string_cst = true;
10006 : }
10007 111 : else if (!comptypes (typ1, typ2))
10008 : incompat_string_cst = true;
10009 :
10010 : if (incompat_string_cst)
10011 : {
10012 72 : error_init (init_loc, "cannot initialize array of %qT from "
10013 : "a string literal with type array of %qT",
10014 : typ1, typ2);
10015 72 : return error_mark_node;
10016 : }
10017 :
10018 4114 : if (require_constexpr
10019 4114 : && TYPE_UNSIGNED (typ1) != TYPE_UNSIGNED (typ2))
10020 : {
10021 : /* Check if all characters of the string can be
10022 : represented in the type of the constexpr object being
10023 : initialized. */
10024 24 : unsigned HOST_WIDE_INT len = TREE_STRING_LENGTH (inside_init);
10025 24 : const unsigned char *p =
10026 24 : (const unsigned char *) TREE_STRING_POINTER (inside_init);
10027 24 : gcc_assert (CHAR_TYPE_SIZE == 8 && CHAR_BIT == 8);
10028 70 : for (unsigned i = 0; i < len; i++)
10029 58 : if (p[i] > 127)
10030 : {
10031 12 : error_init (init_loc, "%<constexpr%> initializer not "
10032 : "representable in type of object");
10033 12 : break;
10034 : }
10035 : }
10036 :
10037 4114 : if (TYPE_DOMAIN (type) != NULL_TREE
10038 4020 : && TYPE_SIZE (type) != NULL_TREE
10039 8075 : && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
10040 : {
10041 3961 : unsigned HOST_WIDE_INT len = TREE_STRING_LENGTH (inside_init);
10042 :
10043 3961 : if (compare_tree_int (TYPE_SIZE_UNIT (type), len) < 0)
10044 : {
10045 397 : unsigned HOST_WIDE_INT avail
10046 397 : = tree_to_uhwi (TYPE_SIZE_UNIT (type));
10047 397 : unsigned unit = TYPE_PRECISION (typ1) / BITS_PER_UNIT;
10048 397 : const char *p = TREE_STRING_POINTER (inside_init);
10049 :
10050 : /* Construct truncated string. */
10051 397 : inside_init = build_string (avail, p);
10052 :
10053 : /* Subtract the size of a single (possibly wide) character
10054 : because it may be ok to ignore the terminating NUL char
10055 : that is counted in the length of the constant. */
10056 397 : if (len - unit > avail)
10057 63 : pedwarn_init (init_loc, 0,
10058 : "initializer-string for array of %qT "
10059 : "is too long (%wu chars into %wu "
10060 : "available)", typ1, len, avail);
10061 334 : else if (warn_cxx_compat)
10062 9 : warning_at (init_loc, OPT_Wc___compat,
10063 : "initializer-string for array of %qT "
10064 : "is too long for C++ (%wu chars into %wu "
10065 : "available)", typ1, len, avail);
10066 325 : else if (warn_unterminated_string_initialization
10067 325 : && get_attr_nonstring_decl (decl) == NULL_TREE)
10068 22 : warning_at (init_loc,
10069 22 : OPT_Wunterminated_string_initialization,
10070 : "initializer-string for array of %qT "
10071 : "truncates NUL terminator but destination "
10072 : "lacks %qs attribute (%wu chars into %wu "
10073 : "available)", typ1, "nonstring", len, avail);
10074 : }
10075 : }
10076 :
10077 4114 : TREE_TYPE (inside_init) = type;
10078 4114 : return inside_init;
10079 : }
10080 29 : else if (INTEGRAL_TYPE_P (typ1))
10081 : {
10082 29 : error_init (init_loc, "array of inappropriate type initialized "
10083 : "from string constant");
10084 29 : return error_mark_node;
10085 : }
10086 : }
10087 :
10088 : /* Build a VECTOR_CST from a *constant* vector constructor. If the
10089 : vector constructor is not constant (e.g. {1,2,3,foo()}) then punt
10090 : below and handle as a constructor. */
10091 16966764 : if (code == VECTOR_TYPE
10092 6342694 : && VECTOR_TYPE_P (TREE_TYPE (inside_init))
10093 6342692 : && vector_types_convertible_p (TREE_TYPE (inside_init), type, true)
10094 23309418 : && TREE_CONSTANT (inside_init))
10095 : {
10096 636221 : if (TREE_CODE (inside_init) == VECTOR_CST
10097 636318 : && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
10098 97 : TYPE_MAIN_VARIANT (type)))
10099 : return inside_init;
10100 :
10101 636124 : if (TREE_CODE (inside_init) == CONSTRUCTOR)
10102 : {
10103 : unsigned HOST_WIDE_INT ix;
10104 : tree value;
10105 4191554 : bool constant_p = true;
10106 :
10107 : /* Iterate through elements and check if all constructor
10108 : elements are *_CSTs. */
10109 4191554 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (inside_init), ix, value)
10110 3555487 : if (!CONSTANT_CLASS_P (value))
10111 : {
10112 : constant_p = false;
10113 : break;
10114 : }
10115 :
10116 636124 : if (constant_p)
10117 636067 : return build_vector_from_ctor (type,
10118 636067 : CONSTRUCTOR_ELTS (inside_init));
10119 : }
10120 : }
10121 :
10122 16330600 : if (warn_sequence_point)
10123 2449444 : verify_sequence_points (inside_init);
10124 :
10125 : /* Any type can be initialized
10126 : from an expression of the same type, optionally with braces. */
10127 :
10128 16330600 : if (inside_init && TREE_TYPE (inside_init) != NULL_TREE
10129 32661200 : && (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
10130 16330600 : TYPE_MAIN_VARIANT (type))
10131 3148821 : || (code == ARRAY_TYPE
10132 477 : && comptypes (TREE_TYPE (inside_init), type))
10133 3148821 : || (gnu_vector_type_p (type)
10134 189 : && comptypes (TREE_TYPE (inside_init), type))
10135 3148821 : || (code == POINTER_TYPE
10136 112777 : && TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE
10137 9298 : && comptypes (TREE_TYPE (TREE_TYPE (inside_init)),
10138 9298 : TREE_TYPE (type)))))
10139 : {
10140 13183757 : if (code == POINTER_TYPE)
10141 : {
10142 785504 : if (TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE)
10143 : {
10144 1978 : if (TREE_CODE (inside_init) == STRING_CST
10145 68 : || TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR)
10146 1975 : inside_init = array_to_pointer_conversion
10147 1975 : (init_loc, inside_init);
10148 : else
10149 : {
10150 3 : error_init (init_loc, "invalid use of non-lvalue array");
10151 3 : return error_mark_node;
10152 : }
10153 : }
10154 : }
10155 :
10156 13183754 : if (code == VECTOR_TYPE || c_hardbool_type_attr (type))
10157 : /* Although the types are compatible, we may require a
10158 : conversion. */
10159 5706474 : inside_init = convert (type, inside_init);
10160 :
10161 13183754 : if ((code == RECORD_TYPE || code == UNION_TYPE)
10162 13183754 : && !comptypes (TYPE_MAIN_VARIANT (type), TYPE_MAIN_VARIANT (TREE_TYPE (inside_init))))
10163 : {
10164 0 : error_init (init_loc, "invalid initializer");
10165 0 : return error_mark_node;
10166 : }
10167 :
10168 13183754 : if (require_constant
10169 2300397 : && TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR)
10170 : {
10171 : /* As an extension, allow initializing objects with static storage
10172 : duration with compound literals (which are then treated just as
10173 : the brace enclosed list they contain). Also allow this for
10174 : vectors, as we can only assign them with compound literals. */
10175 31 : if (flag_isoc99 && code != VECTOR_TYPE)
10176 8 : pedwarn_init (init_loc, OPT_Wpedantic, "initializer element "
10177 : "is not constant");
10178 31 : tree decl = COMPOUND_LITERAL_EXPR_DECL (inside_init);
10179 31 : inside_init = DECL_INITIAL (decl);
10180 : }
10181 :
10182 13183754 : if (code == ARRAY_TYPE && TREE_CODE (inside_init) != STRING_CST
10183 177471 : && TREE_CODE (inside_init) != CONSTRUCTOR)
10184 : {
10185 2 : error_init (init_loc, "array initialized from non-constant array "
10186 : "expression");
10187 2 : return error_mark_node;
10188 : }
10189 :
10190 : /* Compound expressions can only occur here if -Wpedantic or
10191 : -pedantic-errors is specified. In the later case, we always want
10192 : an error. In the former case, we simply want a warning. */
10193 13183752 : if (require_constant && pedantic
10194 20351 : && TREE_CODE (inside_init) == COMPOUND_EXPR)
10195 : {
10196 1 : inside_init
10197 1 : = valid_compound_expr_initializer (inside_init,
10198 1 : TREE_TYPE (inside_init));
10199 1 : if (inside_init == error_mark_node)
10200 1 : error_init (init_loc, "initializer element is not constant");
10201 : else
10202 0 : pedwarn_init (init_loc, OPT_Wpedantic,
10203 : "initializer element is not constant");
10204 1 : if (flag_pedantic_errors)
10205 0 : inside_init = error_mark_node;
10206 : }
10207 2300396 : else if (require_constant
10208 2300396 : && !initializer_constant_valid_p (inside_init,
10209 2300396 : TREE_TYPE (inside_init)))
10210 : {
10211 94 : error_init (init_loc, "initializer element is not constant");
10212 94 : inside_init = error_mark_node;
10213 : }
10214 13183657 : else if (require_constant && !maybe_const)
10215 219 : pedwarn_init (init_loc, OPT_Wpedantic,
10216 : "initializer element is not a constant expression");
10217 13183438 : else if (require_constexpr)
10218 610 : check_constexpr_init (init_loc, type, inside_init,
10219 : int_const_expr, arith_const_expr);
10220 :
10221 : /* Added to enable additional -Wsuggest-attribute=format warnings. */
10222 13183752 : if (TREE_CODE (TREE_TYPE (inside_init)) == POINTER_TYPE)
10223 855172 : inside_init = convert_for_assignment (init_loc, UNKNOWN_LOCATION,
10224 : type, inside_init, origtype,
10225 : (require_constant
10226 : ? ic_init_const
10227 : : ic_init), null_pointer_constant,
10228 : NULL_TREE, NULL_TREE, 0);
10229 13183752 : if (TREE_CODE (inside_init) == RAW_DATA_CST
10230 257 : && c_inhibit_evaluation_warnings == 0
10231 257 : && warn_conversion
10232 1 : && !TYPE_UNSIGNED (type)
10233 13183753 : && TYPE_PRECISION (type) == CHAR_BIT)
10234 303 : for (unsigned int i = 0;
10235 304 : i < (unsigned) RAW_DATA_LENGTH (inside_init); ++i)
10236 303 : if (RAW_DATA_SCHAR_ELT (inside_init, i) < 0)
10237 10 : warning_at (init_loc, OPT_Wconversion,
10238 : "conversion from %qT to %qT changes value from "
10239 : "%qd to %qd",
10240 : integer_type_node, type,
10241 10 : RAW_DATA_UCHAR_ELT (inside_init, i),
10242 10 : RAW_DATA_SCHAR_ELT (inside_init, i));
10243 : return inside_init;
10244 : }
10245 :
10246 : /* Handle scalar types, including conversions. */
10247 :
10248 3146843 : if (code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE
10249 130376 : || code == POINTER_TYPE || code == ENUMERAL_TYPE || code == BOOLEAN_TYPE
10250 11898 : || code == COMPLEX_TYPE || code == VECTOR_TYPE || code == NULLPTR_TYPE
10251 9835 : || code == BITINT_TYPE)
10252 : {
10253 3146355 : tree unconverted_init = inside_init;
10254 3146355 : if (TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE
10255 3146355 : && (TREE_CODE (init) == STRING_CST
10256 2 : || TREE_CODE (init) == COMPOUND_LITERAL_EXPR))
10257 7321 : inside_init = init = array_to_pointer_conversion (init_loc, init);
10258 3146355 : if (semantic_type)
10259 436 : inside_init = build1 (EXCESS_PRECISION_EXPR, semantic_type,
10260 : inside_init);
10261 3146355 : inside_init
10262 5710769 : = convert_for_assignment (init_loc, UNKNOWN_LOCATION, type,
10263 : inside_init, origtype,
10264 : require_constant ? ic_init_const : ic_init,
10265 : null_pointer_constant, NULL_TREE, NULL_TREE,
10266 : 0);
10267 :
10268 : /* Check to see if we have already given an error message. */
10269 3146355 : if (inside_init == error_mark_node)
10270 : ;
10271 3145895 : else if (require_constant && !TREE_CONSTANT (inside_init))
10272 : {
10273 36 : error_init (init_loc, "initializer element is not constant");
10274 36 : inside_init = error_mark_node;
10275 : }
10276 3145859 : else if (require_constant
10277 3727372 : && !initializer_constant_valid_p (inside_init,
10278 581513 : TREE_TYPE (inside_init)))
10279 : {
10280 10 : error_init (init_loc, "initializer element is not computable at "
10281 : "load time");
10282 10 : inside_init = error_mark_node;
10283 : }
10284 3145849 : else if (require_constant && !maybe_const)
10285 5 : pedwarn_init (init_loc, OPT_Wpedantic,
10286 : "initializer element is not a constant expression");
10287 3145844 : else if (require_constexpr)
10288 332 : check_constexpr_init (init_loc, type, unconverted_init,
10289 : int_const_expr, arith_const_expr);
10290 :
10291 : return inside_init;
10292 : }
10293 :
10294 : /* Come here only for records and arrays. */
10295 :
10296 488 : if (COMPLETE_TYPE_P (type) && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
10297 : {
10298 0 : error_init (init_loc,
10299 : "variable-sized object may not be initialized except "
10300 : "with an empty initializer");
10301 0 : return error_mark_node;
10302 : }
10303 :
10304 488 : error_init (init_loc, "invalid initializer");
10305 488 : return error_mark_node;
10306 : }
10307 :
10308 : /* Handle initializers that use braces. */
10309 :
10310 : /* Type of object we are accumulating a constructor for.
10311 : This type is always a RECORD_TYPE, UNION_TYPE or ARRAY_TYPE. */
10312 : static tree constructor_type;
10313 :
10314 : /* For a RECORD_TYPE or UNION_TYPE, this is the chain of fields
10315 : left to fill. */
10316 : static tree constructor_fields;
10317 :
10318 : /* For an ARRAY_TYPE, this is the specified index
10319 : at which to store the next element we get. */
10320 : static tree constructor_index;
10321 :
10322 : /* For an ARRAY_TYPE, this is the maximum index. */
10323 : static tree constructor_max_index;
10324 :
10325 : /* For a RECORD_TYPE, this is the first field not yet written out. */
10326 : static tree constructor_unfilled_fields;
10327 :
10328 : /* For an ARRAY_TYPE, this is the index of the first element
10329 : not yet written out. */
10330 : static tree constructor_unfilled_index;
10331 :
10332 : /* In a RECORD_TYPE, the byte index of the next consecutive field.
10333 : This is so we can generate gaps between fields, when appropriate. */
10334 : static tree constructor_bit_index;
10335 :
10336 : /* If we are saving up the elements rather than allocating them,
10337 : this is the list of elements so far (in reverse order,
10338 : most recent first). */
10339 : static vec<constructor_elt, va_gc> *constructor_elements;
10340 :
10341 : /* 1 if constructor should be incrementally stored into a constructor chain,
10342 : 0 if all the elements should be kept in AVL tree. */
10343 : static int constructor_incremental;
10344 :
10345 : /* 1 if so far this constructor's elements are all compile-time constants. */
10346 : static int constructor_constant;
10347 :
10348 : /* 1 if so far this constructor's elements are all valid address constants. */
10349 : static int constructor_simple;
10350 :
10351 : /* 1 if this constructor has an element that cannot be part of a
10352 : constant expression. */
10353 : static int constructor_nonconst;
10354 :
10355 : /* 1 if this constructor is erroneous so far. */
10356 : static int constructor_erroneous;
10357 :
10358 : /* 1 if this constructor is the universal zero initializer { 0 }. */
10359 : static int constructor_zeroinit;
10360 :
10361 : /* 1 if this constructor should have padding bits zeroed (C23 {}. */
10362 : static bool constructor_zero_padding_bits;
10363 :
10364 : /* 1 if this constructor is a braced scalar initializer (further nested levels
10365 : of braces are an error). */
10366 : static bool constructor_braced_scalar;
10367 :
10368 : /* Structure for managing pending initializer elements, organized as an
10369 : AVL tree. */
10370 :
10371 : struct init_node
10372 : {
10373 : struct init_node *left, *right;
10374 : struct init_node *parent;
10375 : int balance;
10376 : tree purpose;
10377 : tree value;
10378 : tree origtype;
10379 : };
10380 :
10381 : /* Tree of pending elements at this constructor level.
10382 : These are elements encountered out of order
10383 : which belong at places we haven't reached yet in actually
10384 : writing the output.
10385 : Will never hold tree nodes across GC runs. */
10386 : static struct init_node *constructor_pending_elts;
10387 :
10388 : /* The SPELLING_DEPTH of this constructor. */
10389 : static int constructor_depth;
10390 :
10391 : /* DECL node for which an initializer is being read.
10392 : 0 means we are reading a constructor expression
10393 : such as (struct foo) {...}. */
10394 : static tree constructor_decl;
10395 :
10396 : /* Nonzero if there were any member designators in this initializer. */
10397 : static int constructor_designated;
10398 :
10399 : /* Nesting depth of designator list. */
10400 : static int designator_depth;
10401 :
10402 : /* Nonzero if there were diagnosed errors in this designator list. */
10403 : static int designator_erroneous;
10404 :
10405 :
10406 : /* This stack has a level for each implicit or explicit level of
10407 : structuring in the initializer, including the outermost one. It
10408 : saves the values of most of the variables above. */
10409 :
10410 : struct constructor_range_stack;
10411 :
10412 : struct constructor_stack
10413 : {
10414 : struct constructor_stack *next;
10415 : tree type;
10416 : tree fields;
10417 : tree index;
10418 : tree max_index;
10419 : tree unfilled_index;
10420 : tree unfilled_fields;
10421 : tree bit_index;
10422 : vec<constructor_elt, va_gc> *elements;
10423 : struct init_node *pending_elts;
10424 : int offset;
10425 : int depth;
10426 : /* If value nonzero, this value should replace the entire
10427 : constructor at this level. */
10428 : struct c_expr replacement_value;
10429 : struct constructor_range_stack *range_stack;
10430 : char constant;
10431 : char simple;
10432 : char nonconst;
10433 : char implicit;
10434 : char erroneous;
10435 : char outer;
10436 : char incremental;
10437 : char designated;
10438 : bool zero_padding_bits;
10439 : bool braced_scalar;
10440 : int designator_depth;
10441 : };
10442 :
10443 : static struct constructor_stack *constructor_stack;
10444 :
10445 : /* This stack represents designators from some range designator up to
10446 : the last designator in the list. */
10447 :
10448 : struct constructor_range_stack
10449 : {
10450 : struct constructor_range_stack *next, *prev;
10451 : struct constructor_stack *stack;
10452 : tree range_start;
10453 : tree index;
10454 : tree range_end;
10455 : tree fields;
10456 : };
10457 :
10458 : static struct constructor_range_stack *constructor_range_stack;
10459 :
10460 : /* This stack records separate initializers that are nested.
10461 : Nested initializers can't happen in ANSI C, but GNU C allows them
10462 : in cases like { ... (struct foo) { ... } ... }. */
10463 :
10464 : struct initializer_stack
10465 : {
10466 : struct initializer_stack *next;
10467 : tree decl;
10468 : struct constructor_stack *constructor_stack;
10469 : struct constructor_range_stack *constructor_range_stack;
10470 : vec<constructor_elt, va_gc> *elements;
10471 : struct spelling *spelling;
10472 : struct spelling *spelling_base;
10473 : int spelling_size;
10474 : char require_constant_value;
10475 : char require_constant_elements;
10476 : char require_constexpr_value;
10477 : char designated;
10478 : rich_location *missing_brace_richloc;
10479 : };
10480 :
10481 : static struct initializer_stack *initializer_stack;
10482 :
10483 : /* Prepare to parse and output the initializer for variable DECL. */
10484 :
10485 : void
10486 7308603 : start_init (tree decl, tree asmspec_tree ATTRIBUTE_UNUSED,
10487 : bool init_require_constant, bool init_require_constexpr,
10488 : rich_location *richloc)
10489 : {
10490 7308603 : const char *locus;
10491 7308603 : struct initializer_stack *p = XNEW (struct initializer_stack);
10492 :
10493 7308603 : p->decl = constructor_decl;
10494 7308603 : p->require_constant_value = require_constant_value;
10495 7308603 : p->require_constant_elements = require_constant_elements;
10496 7308603 : p->require_constexpr_value = require_constexpr_value;
10497 7308603 : p->constructor_stack = constructor_stack;
10498 7308603 : p->constructor_range_stack = constructor_range_stack;
10499 7308603 : p->elements = constructor_elements;
10500 7308603 : p->spelling = spelling;
10501 7308603 : p->spelling_base = spelling_base;
10502 7308603 : p->spelling_size = spelling_size;
10503 7308603 : p->next = initializer_stack;
10504 7308603 : p->missing_brace_richloc = richloc;
10505 7308603 : p->designated = constructor_designated;
10506 7308603 : initializer_stack = p;
10507 :
10508 7308603 : constructor_decl = decl;
10509 7308603 : constructor_designated = 0;
10510 :
10511 7308603 : require_constant_value = init_require_constant;
10512 7308603 : require_constexpr_value = init_require_constexpr;
10513 7308603 : if (decl != NULL_TREE && decl != error_mark_node)
10514 : {
10515 6382148 : require_constant_elements
10516 6203965 : = ((init_require_constant || (pedantic && !flag_isoc99))
10517 : /* For a scalar, you can always use any value to initialize,
10518 : even within braces. */
10519 6395284 : && AGGREGATE_TYPE_P (TREE_TYPE (decl)));
10520 6382148 : locus = identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl)));
10521 : }
10522 : else
10523 : {
10524 926455 : require_constant_elements = false;
10525 926455 : locus = _("(anonymous)");
10526 : }
10527 :
10528 7308603 : constructor_stack = 0;
10529 7308603 : constructor_range_stack = 0;
10530 :
10531 7308603 : found_missing_braces = 0;
10532 :
10533 7308603 : spelling_base = 0;
10534 7308603 : spelling_size = 0;
10535 7308603 : RESTORE_SPELLING_DEPTH (0);
10536 :
10537 7308603 : if (locus)
10538 7308603 : push_string (locus);
10539 7308603 : }
10540 :
10541 : void
10542 7308601 : finish_init (void)
10543 : {
10544 7308601 : struct initializer_stack *p = initializer_stack;
10545 :
10546 : /* Free the whole constructor stack of this initializer. */
10547 7308601 : while (constructor_stack)
10548 : {
10549 0 : struct constructor_stack *q = constructor_stack;
10550 0 : constructor_stack = q->next;
10551 0 : XDELETE (q);
10552 : }
10553 :
10554 7308601 : gcc_assert (!constructor_range_stack);
10555 :
10556 : /* Pop back to the data of the outer initializer (if any). */
10557 7308601 : XDELETE (spelling_base);
10558 :
10559 7308601 : constructor_decl = p->decl;
10560 7308601 : require_constant_value = p->require_constant_value;
10561 7308601 : require_constant_elements = p->require_constant_elements;
10562 7308601 : require_constexpr_value = p->require_constexpr_value;
10563 7308601 : constructor_stack = p->constructor_stack;
10564 7308601 : constructor_designated = p->designated;
10565 7308601 : constructor_range_stack = p->constructor_range_stack;
10566 7308601 : constructor_elements = p->elements;
10567 7308601 : spelling = p->spelling;
10568 7308601 : spelling_base = p->spelling_base;
10569 7308601 : spelling_size = p->spelling_size;
10570 7308601 : initializer_stack = p->next;
10571 7308601 : XDELETE (p);
10572 7308601 : }
10573 :
10574 : /* Call here when we see the initializer is surrounded by braces.
10575 : This is instead of a call to push_init_level;
10576 : it is matched by a call to pop_init_level.
10577 :
10578 : TYPE is the type to initialize, for a constructor expression.
10579 : For an initializer for a decl, TYPE is zero. */
10580 :
10581 : void
10582 1031248 : really_start_incremental_init (tree type)
10583 : {
10584 1031248 : struct constructor_stack *p = XNEW (struct constructor_stack);
10585 :
10586 1031248 : if (type == NULL_TREE)
10587 106761 : type = TREE_TYPE (constructor_decl);
10588 :
10589 1031248 : if (VECTOR_TYPE_P (type)
10590 1031248 : && TYPE_VECTOR_OPAQUE (type))
10591 0 : error ("opaque vector types cannot be initialized");
10592 :
10593 1031248 : p->type = constructor_type;
10594 1031248 : p->fields = constructor_fields;
10595 1031248 : p->index = constructor_index;
10596 1031248 : p->max_index = constructor_max_index;
10597 1031248 : p->unfilled_index = constructor_unfilled_index;
10598 1031248 : p->unfilled_fields = constructor_unfilled_fields;
10599 1031248 : p->bit_index = constructor_bit_index;
10600 1031248 : p->elements = constructor_elements;
10601 1031248 : p->constant = constructor_constant;
10602 1031248 : p->simple = constructor_simple;
10603 1031248 : p->nonconst = constructor_nonconst;
10604 1031248 : p->erroneous = constructor_erroneous;
10605 1031248 : p->pending_elts = constructor_pending_elts;
10606 1031248 : p->depth = constructor_depth;
10607 1031248 : p->replacement_value.value = 0;
10608 1031248 : p->replacement_value.original_code = ERROR_MARK;
10609 1031248 : p->replacement_value.original_type = NULL;
10610 1031248 : p->implicit = 0;
10611 1031248 : p->range_stack = 0;
10612 1031248 : p->outer = 0;
10613 1031248 : p->incremental = constructor_incremental;
10614 1031248 : p->designated = constructor_designated;
10615 1031248 : p->zero_padding_bits = constructor_zero_padding_bits;
10616 1031248 : p->braced_scalar = constructor_braced_scalar;
10617 1031248 : p->designator_depth = designator_depth;
10618 1031248 : p->next = 0;
10619 1031248 : constructor_stack = p;
10620 :
10621 1031248 : constructor_constant = 1;
10622 1031248 : constructor_simple = 1;
10623 1031248 : constructor_nonconst = 0;
10624 1031248 : constructor_depth = SPELLING_DEPTH ();
10625 1031248 : constructor_elements = NULL;
10626 1031248 : constructor_pending_elts = 0;
10627 1031248 : constructor_type = type;
10628 1031248 : constructor_incremental = 1;
10629 1031248 : constructor_designated = 0;
10630 1031248 : constructor_zero_padding_bits = false;
10631 1031248 : constructor_zeroinit = 1;
10632 1031248 : constructor_braced_scalar = false;
10633 1031248 : designator_depth = 0;
10634 1031248 : designator_erroneous = 0;
10635 :
10636 1031248 : if (RECORD_OR_UNION_TYPE_P (constructor_type))
10637 : {
10638 82333 : constructor_fields = TYPE_FIELDS (constructor_type);
10639 : /* Skip any nameless bit fields at the beginning. */
10640 82333 : while (constructor_fields != NULL_TREE
10641 82361 : && DECL_UNNAMED_BIT_FIELD (constructor_fields))
10642 28 : constructor_fields = DECL_CHAIN (constructor_fields);
10643 :
10644 82333 : constructor_unfilled_fields = constructor_fields;
10645 82333 : constructor_bit_index = bitsize_zero_node;
10646 : }
10647 948915 : else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
10648 : {
10649 18216 : if (TYPE_DOMAIN (constructor_type))
10650 : {
10651 9619 : constructor_max_index
10652 9619 : = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
10653 :
10654 : /* Detect non-empty initializations of zero-length arrays. */
10655 9619 : if (constructor_max_index == NULL_TREE
10656 9619 : && TYPE_SIZE (constructor_type))
10657 207 : constructor_max_index = integer_minus_one_node;
10658 :
10659 : /* constructor_max_index needs to be an INTEGER_CST. Attempts
10660 : to initialize VLAs with a nonempty initializer will cause a
10661 : proper error; avoid tree checking errors as well by setting a
10662 : safe value. */
10663 9619 : if (constructor_max_index
10664 9619 : && TREE_CODE (constructor_max_index) != INTEGER_CST)
10665 73 : constructor_max_index = integer_minus_one_node;
10666 :
10667 9619 : constructor_index
10668 9619 : = convert (bitsizetype,
10669 9619 : TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
10670 : }
10671 : else
10672 : {
10673 8597 : constructor_index = bitsize_zero_node;
10674 8597 : constructor_max_index = NULL_TREE;
10675 : }
10676 :
10677 18216 : constructor_unfilled_index = constructor_index;
10678 : }
10679 930699 : else if (gnu_vector_type_p (constructor_type))
10680 : {
10681 : /* Vectors are like simple fixed-size arrays. */
10682 1860286 : constructor_max_index =
10683 930143 : bitsize_int (TYPE_VECTOR_SUBPARTS (constructor_type) - 1);
10684 930143 : constructor_index = bitsize_zero_node;
10685 930143 : constructor_unfilled_index = constructor_index;
10686 : }
10687 : else
10688 : {
10689 : /* Handle the case of int x = {5}; */
10690 556 : constructor_fields = constructor_type;
10691 556 : constructor_unfilled_fields = constructor_type;
10692 556 : constructor_braced_scalar = true;
10693 : }
10694 1031248 : }
10695 :
10696 : extern location_t last_init_list_comma;
10697 :
10698 : /* Called when we see an open brace for a nested initializer. Finish
10699 : off any pending levels with implicit braces. */
10700 : void
10701 342504 : finish_implicit_inits (location_t loc, struct obstack *braced_init_obstack)
10702 : {
10703 342506 : while (constructor_stack->implicit)
10704 : {
10705 1154 : if (RECORD_OR_UNION_TYPE_P (constructor_type)
10706 208 : && constructor_fields == NULL_TREE)
10707 0 : process_init_element (input_location,
10708 : pop_init_level (loc, 1, braced_init_obstack,
10709 : last_init_list_comma),
10710 : true, braced_init_obstack);
10711 1154 : else if (TREE_CODE (constructor_type) == ARRAY_TYPE
10712 946 : && constructor_max_index
10713 2100 : && tree_int_cst_lt (constructor_max_index,
10714 : constructor_index))
10715 2 : process_init_element (input_location,
10716 : pop_init_level (loc, 1, braced_init_obstack,
10717 : last_init_list_comma),
10718 : true, braced_init_obstack);
10719 : else
10720 : break;
10721 : }
10722 342504 : }
10723 :
10724 : /* Push down into a subobject, for initialization.
10725 : If this is for an explicit set of braces, IMPLICIT is 0.
10726 : If it is because the next element belongs at a lower level,
10727 : IMPLICIT is 1 (or 2 if the push is because of designator list). */
10728 :
10729 : void
10730 1045184 : push_init_level (location_t loc, int implicit,
10731 : struct obstack *braced_init_obstack)
10732 : {
10733 1045184 : struct constructor_stack *p;
10734 1045184 : tree value = NULL_TREE;
10735 :
10736 : /* Unless this is an explicit brace, we need to preserve previous
10737 : content if any. */
10738 1045184 : if (implicit)
10739 : {
10740 705323 : if (RECORD_OR_UNION_TYPE_P (constructor_type) && constructor_fields)
10741 1819 : value = find_init_member (constructor_fields, braced_init_obstack);
10742 703504 : else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
10743 703504 : value = find_init_member (constructor_index, braced_init_obstack);
10744 : }
10745 :
10746 1045184 : p = XNEW (struct constructor_stack);
10747 1045184 : p->type = constructor_type;
10748 1045184 : p->fields = constructor_fields;
10749 1045184 : p->index = constructor_index;
10750 1045184 : p->max_index = constructor_max_index;
10751 1045184 : p->unfilled_index = constructor_unfilled_index;
10752 1045184 : p->unfilled_fields = constructor_unfilled_fields;
10753 1045184 : p->bit_index = constructor_bit_index;
10754 1045184 : p->elements = constructor_elements;
10755 1045184 : p->constant = constructor_constant;
10756 1045184 : p->simple = constructor_simple;
10757 1045184 : p->nonconst = constructor_nonconst;
10758 1045184 : p->erroneous = constructor_erroneous;
10759 1045184 : p->pending_elts = constructor_pending_elts;
10760 1045184 : p->depth = constructor_depth;
10761 1045184 : p->replacement_value.value = NULL_TREE;
10762 1045184 : p->replacement_value.original_code = ERROR_MARK;
10763 1045184 : p->replacement_value.original_type = NULL;
10764 1045184 : p->implicit = implicit;
10765 1045184 : p->outer = 0;
10766 1045184 : p->incremental = constructor_incremental;
10767 1045184 : p->designated = constructor_designated;
10768 1045184 : p->zero_padding_bits = constructor_zero_padding_bits;
10769 1045184 : p->braced_scalar = constructor_braced_scalar;
10770 1045184 : p->designator_depth = designator_depth;
10771 1045184 : p->next = constructor_stack;
10772 1045184 : p->range_stack = 0;
10773 1045184 : constructor_stack = p;
10774 :
10775 1045184 : constructor_constant = 1;
10776 1045184 : constructor_simple = 1;
10777 1045184 : constructor_nonconst = 0;
10778 1045184 : constructor_depth = SPELLING_DEPTH ();
10779 1045184 : constructor_elements = NULL;
10780 1045184 : constructor_incremental = 1;
10781 : /* If the upper initializer is designated, then mark this as
10782 : designated too to prevent bogus warnings. */
10783 1045184 : constructor_designated = p->designated;
10784 : /* If the upper initializer has padding bits zeroed, that includes
10785 : all nested initializers as well. */
10786 1045184 : constructor_zero_padding_bits = p->zero_padding_bits;
10787 1045184 : constructor_braced_scalar = false;
10788 1045184 : constructor_pending_elts = 0;
10789 1045184 : if (!implicit)
10790 : {
10791 339861 : p->range_stack = constructor_range_stack;
10792 339861 : constructor_range_stack = 0;
10793 339861 : designator_depth = 0;
10794 339861 : designator_erroneous = 0;
10795 : }
10796 :
10797 : /* Don't die if an entire brace-pair level is superfluous
10798 : in the containing level. */
10799 1045184 : if (constructor_type == NULL_TREE)
10800 : ;
10801 1045184 : else if (RECORD_OR_UNION_TYPE_P (constructor_type))
10802 : {
10803 : /* Don't die if there are extra init elts at the end. */
10804 160059 : if (constructor_fields == NULL_TREE)
10805 51 : constructor_type = NULL_TREE;
10806 : else
10807 : {
10808 160008 : constructor_type = TREE_TYPE (constructor_fields);
10809 160008 : push_member_name (constructor_fields);
10810 160008 : constructor_depth++;
10811 : }
10812 : }
10813 885125 : else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
10814 : {
10815 885074 : constructor_type = TREE_TYPE (constructor_type);
10816 885074 : push_array_bounds (tree_to_uhwi (constructor_index));
10817 885074 : constructor_depth++;
10818 : }
10819 :
10820 1045184 : if (constructor_type == NULL_TREE)
10821 : {
10822 51 : error_init (loc, "extra brace group at end of initializer");
10823 51 : constructor_fields = NULL_TREE;
10824 51 : constructor_unfilled_fields = NULL_TREE;
10825 51 : return;
10826 : }
10827 :
10828 1045133 : if (value && TREE_CODE (value) == CONSTRUCTOR)
10829 : {
10830 1686 : constructor_constant = TREE_CONSTANT (value);
10831 1686 : constructor_simple = TREE_STATIC (value);
10832 1686 : constructor_nonconst = CONSTRUCTOR_NON_CONST (value);
10833 1686 : constructor_elements = CONSTRUCTOR_ELTS (value);
10834 1686 : constructor_zero_padding_bits |= CONSTRUCTOR_ZERO_PADDING_BITS (value);
10835 1686 : if (!vec_safe_is_empty (constructor_elements)
10836 1462 : && (TREE_CODE (constructor_type) == RECORD_TYPE
10837 1462 : || TREE_CODE (constructor_type) == ARRAY_TYPE))
10838 1416 : set_nonincremental_init (braced_init_obstack);
10839 : }
10840 :
10841 1045133 : if (implicit == 1)
10842 : {
10843 702680 : found_missing_braces = 1;
10844 702680 : if (initializer_stack->missing_brace_richloc)
10845 702680 : initializer_stack->missing_brace_richloc->add_fixit_insert_before
10846 702680 : (loc, "{");
10847 : }
10848 :
10849 1045133 : if (RECORD_OR_UNION_TYPE_P (constructor_type))
10850 : {
10851 880923 : constructor_fields = TYPE_FIELDS (constructor_type);
10852 : /* Skip any nameless bit fields at the beginning. */
10853 880923 : while (constructor_fields != NULL_TREE
10854 880987 : && DECL_UNNAMED_BIT_FIELD (constructor_fields))
10855 64 : constructor_fields = DECL_CHAIN (constructor_fields);
10856 :
10857 880923 : constructor_unfilled_fields = constructor_fields;
10858 880923 : constructor_bit_index = bitsize_zero_node;
10859 : }
10860 164210 : else if (gnu_vector_type_p (constructor_type))
10861 : {
10862 : /* Vectors are like simple fixed-size arrays. */
10863 9602 : constructor_max_index =
10864 4801 : bitsize_int (TYPE_VECTOR_SUBPARTS (constructor_type) - 1);
10865 4801 : constructor_index = bitsize_int (0);
10866 4801 : constructor_unfilled_index = constructor_index;
10867 : }
10868 159409 : else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
10869 : {
10870 159329 : if (TYPE_DOMAIN (constructor_type))
10871 : {
10872 159329 : constructor_max_index
10873 159329 : = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
10874 :
10875 : /* Detect non-empty initializations of zero-length arrays. */
10876 159329 : if (constructor_max_index == NULL_TREE
10877 159329 : && TYPE_SIZE (constructor_type))
10878 135 : constructor_max_index = integer_minus_one_node;
10879 :
10880 : /* constructor_max_index needs to be an INTEGER_CST. Attempts
10881 : to initialize VLAs will cause a proper error; avoid tree
10882 : checking errors as well by setting a safe value. */
10883 159329 : if (constructor_max_index
10884 159059 : && TREE_CODE (constructor_max_index) != INTEGER_CST)
10885 2 : constructor_max_index = integer_minus_one_node;
10886 :
10887 159329 : constructor_index
10888 159329 : = convert (bitsizetype,
10889 159329 : TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
10890 : }
10891 : else
10892 0 : constructor_index = bitsize_zero_node;
10893 :
10894 159329 : constructor_unfilled_index = constructor_index;
10895 159329 : if (value && TREE_CODE (value) == STRING_CST)
10896 : {
10897 : /* We need to split the char/wchar array into individual
10898 : characters, so that we don't have to special case it
10899 : everywhere. */
10900 7 : set_nonincremental_init_from_string (value, braced_init_obstack);
10901 : }
10902 : }
10903 : else
10904 : {
10905 80 : if (constructor_type != error_mark_node)
10906 : {
10907 51 : if (p->braced_scalar)
10908 22 : permerror_init (input_location, 0,
10909 : "braces around scalar initializer");
10910 : else
10911 29 : warning_init (input_location, 0,
10912 : "braces around scalar initializer");
10913 51 : constructor_braced_scalar = true;
10914 : }
10915 80 : constructor_fields = constructor_type;
10916 80 : constructor_unfilled_fields = constructor_type;
10917 : }
10918 : }
10919 :
10920 : /* At the end of an implicit or explicit brace level,
10921 : finish up that level of constructor. If a single expression
10922 : with redundant braces initialized that level, return the
10923 : c_expr structure for that expression. Otherwise, the original_code
10924 : element is set to ERROR_MARK.
10925 : If we were outputting the elements as they are read, return 0 as the value
10926 : from inner levels (process_init_element ignores that),
10927 : but return error_mark_node as the value from the outermost level
10928 : (that's what we want to put in DECL_INITIAL).
10929 : Otherwise, return a CONSTRUCTOR expression as the value. */
10930 :
10931 : struct c_expr
10932 2076432 : pop_init_level (location_t loc, int implicit,
10933 : struct obstack *braced_init_obstack,
10934 : location_t insert_before)
10935 : {
10936 2076432 : struct constructor_stack *p;
10937 2076432 : struct c_expr ret;
10938 2076432 : ret.value = NULL_TREE;
10939 2076432 : ret.original_code = ERROR_MARK;
10940 2076432 : ret.original_type = NULL;
10941 2076432 : ret.m_decimal = 0;
10942 :
10943 2076432 : if (implicit == 0)
10944 : {
10945 : /* When we come to an explicit close brace,
10946 : pop any inner levels that didn't have explicit braces. */
10947 1372451 : while (constructor_stack->implicit)
10948 1342 : process_init_element (input_location,
10949 : pop_init_level (loc, 1, braced_init_obstack,
10950 : insert_before),
10951 : true, braced_init_obstack);
10952 1371109 : gcc_assert (!constructor_range_stack);
10953 : }
10954 : else
10955 705323 : if (initializer_stack->missing_brace_richloc)
10956 705323 : initializer_stack->missing_brace_richloc->add_fixit_insert_before
10957 705323 : (insert_before, "}");
10958 :
10959 : /* Now output all pending elements. */
10960 2076432 : constructor_incremental = 1;
10961 2076432 : output_pending_init_elements (1, braced_init_obstack);
10962 :
10963 2076432 : p = constructor_stack;
10964 :
10965 : /* Error for initializing a flexible array member. */
10966 2076381 : if (constructor_type && constructor_fields
10967 2237463 : && flexible_array_member_type_p (constructor_type))
10968 : {
10969 : /* Silently discard empty initializations. The parser will
10970 : already have pedwarned for empty brackets for C17 and earlier. */
10971 270 : if (integer_zerop (constructor_unfilled_index))
10972 54 : constructor_type = NULL_TREE;
10973 270 : if (constructor_type || flag_isoc23)
10974 : {
10975 266 : gcc_assert (!constructor_type || !TYPE_SIZE (constructor_type));
10976 :
10977 266 : if (constructor_depth <= 2)
10978 219 : pedwarn_init (loc, OPT_Wpedantic,
10979 : "initialization of a flexible array member");
10980 47 : else if (constructor_type)
10981 33 : error_init (loc, "initialization of flexible array member "
10982 : "in a nested context");
10983 : else
10984 14 : pedwarn_init (loc, OPT_Wpedantic,
10985 : "initialization of flexible array member "
10986 : "in a nested context");
10987 :
10988 : /* We have already issued an error message for the existence
10989 : of a flexible array member not at the end of the structure.
10990 : Discard the initializer so that we do not die later. */
10991 266 : if (constructor_type
10992 216 : && DECL_CHAIN (constructor_fields) != NULL_TREE
10993 272 : && (!p->type || TREE_CODE (p->type) != UNION_TYPE))
10994 0 : constructor_type = NULL_TREE;
10995 : }
10996 : }
10997 :
10998 2076432 : switch (vec_safe_length (constructor_elements))
10999 : {
11000 5102 : case 0:
11001 : /* Initialization with { } counts as zeroinit. */
11002 5102 : constructor_zeroinit = 1;
11003 5102 : break;
11004 916505 : case 1:
11005 : /* This might be zeroinit as well. */
11006 916505 : if (integer_zerop ((*constructor_elements)[0].value))
11007 2107 : constructor_zeroinit = 1;
11008 : break;
11009 1154825 : default:
11010 : /* If the constructor has more than one element, it can't be { 0 }. */
11011 1154825 : constructor_zeroinit = 0;
11012 1154825 : break;
11013 : }
11014 :
11015 : /* Warn when some structs are initialized with direct aggregation. */
11016 2076432 : if (!implicit && found_missing_braces && warn_missing_braces
11017 37 : && !constructor_zeroinit)
11018 : {
11019 18 : gcc_assert (initializer_stack->missing_brace_richloc);
11020 18 : warning_at (initializer_stack->missing_brace_richloc,
11021 18 : OPT_Wmissing_braces,
11022 : "missing braces around initializer");
11023 : }
11024 :
11025 : /* Warn when some struct elements are implicitly initialized to zero. */
11026 2076432 : if (warn_missing_field_initializers
11027 425477 : && constructor_type
11028 425463 : && TREE_CODE (constructor_type) == RECORD_TYPE
11029 193409 : && constructor_unfilled_fields)
11030 : {
11031 : /* Do not warn for flexible array members or zero-length arrays. */
11032 43 : while (constructor_unfilled_fields
11033 43 : && (!DECL_SIZE (constructor_unfilled_fields)
11034 43 : || integer_zerop (DECL_SIZE (constructor_unfilled_fields))))
11035 0 : constructor_unfilled_fields = DECL_CHAIN (constructor_unfilled_fields);
11036 :
11037 43 : if (constructor_unfilled_fields
11038 : /* Do not warn if this level of the initializer uses member
11039 : designators; it is likely to be deliberate. */
11040 43 : && !constructor_designated
11041 : /* Do not warn about initializing with { 0 } or with { }. */
11042 24 : && !constructor_zeroinit)
11043 : {
11044 10 : if (warning_at (input_location, OPT_Wmissing_field_initializers,
11045 : "missing initializer for field %qD of %qT",
11046 : constructor_unfilled_fields,
11047 : constructor_type))
11048 10 : inform (DECL_SOURCE_LOCATION (constructor_unfilled_fields),
11049 : "%qD declared here", constructor_unfilled_fields);
11050 : }
11051 : }
11052 :
11053 : /* Pad out the end of the structure. */
11054 2076432 : if (p->replacement_value.value)
11055 : /* If this closes a superfluous brace pair,
11056 : just pass out the element between them. */
11057 138 : ret = p->replacement_value;
11058 2076294 : else if (constructor_type == NULL_TREE)
11059 : ;
11060 2076197 : else if (!RECORD_OR_UNION_TYPE_P (constructor_type)
11061 2076197 : && TREE_CODE (constructor_type) != ARRAY_TYPE
11062 2076197 : && !gnu_vector_type_p (constructor_type))
11063 : {
11064 : /* A nonincremental scalar initializer--just return
11065 : the element, after verifying there is just one.
11066 : Empty scalar initializers are supported in C23. */
11067 636 : if (vec_safe_is_empty (constructor_elements))
11068 : {
11069 201 : if (constructor_erroneous || constructor_type == error_mark_node)
11070 85 : ret.value = error_mark_node;
11071 116 : else if (TREE_CODE (constructor_type) == FUNCTION_TYPE)
11072 : {
11073 2 : error_init (loc, "invalid initializer");
11074 2 : ret.value = error_mark_node;
11075 : }
11076 114 : else if (TREE_CODE (constructor_type) == POINTER_TYPE)
11077 : /* Ensure this is a null pointer constant in the case of a
11078 : 'constexpr' object initialized with {}. */
11079 33 : ret.value = build_zero_cst (ptr_type_node);
11080 : else
11081 81 : ret.value = build_zero_cst (constructor_type);
11082 : }
11083 435 : else if (vec_safe_length (constructor_elements) != 1)
11084 : {
11085 0 : error_init (loc, "extra elements in scalar initializer");
11086 0 : ret.value = (*constructor_elements)[0].value;
11087 : }
11088 : else
11089 435 : ret.value = (*constructor_elements)[0].value;
11090 : }
11091 : else
11092 : {
11093 2075561 : if (constructor_erroneous)
11094 285 : ret.value = error_mark_node;
11095 : else
11096 : {
11097 2075276 : ret.value = build_constructor (constructor_type,
11098 : constructor_elements);
11099 2075276 : if (constructor_constant)
11100 1743251 : TREE_CONSTANT (ret.value) = 1;
11101 2075276 : if (constructor_constant && constructor_simple)
11102 1743212 : TREE_STATIC (ret.value) = 1;
11103 2075276 : if (constructor_nonconst)
11104 673 : CONSTRUCTOR_NON_CONST (ret.value) = 1;
11105 2075276 : if (constructor_zero_padding_bits)
11106 687 : CONSTRUCTOR_ZERO_PADDING_BITS (ret.value) = 1;
11107 : }
11108 : }
11109 :
11110 2076432 : if (ret.value && TREE_CODE (ret.value) != CONSTRUCTOR)
11111 : {
11112 1059 : if (constructor_nonconst)
11113 15 : ret.original_code = C_MAYBE_CONST_EXPR;
11114 1044 : else if (ret.original_code == C_MAYBE_CONST_EXPR)
11115 0 : ret.original_code = ERROR_MARK;
11116 : }
11117 :
11118 2076432 : constructor_type = p->type;
11119 2076432 : constructor_fields = p->fields;
11120 2076432 : constructor_index = p->index;
11121 2076432 : constructor_max_index = p->max_index;
11122 2076432 : constructor_unfilled_index = p->unfilled_index;
11123 2076432 : constructor_unfilled_fields = p->unfilled_fields;
11124 2076432 : constructor_bit_index = p->bit_index;
11125 2076432 : constructor_elements = p->elements;
11126 2076432 : constructor_constant = p->constant;
11127 2076432 : constructor_simple = p->simple;
11128 2076432 : constructor_nonconst = p->nonconst;
11129 2076432 : constructor_erroneous = p->erroneous;
11130 2076432 : constructor_incremental = p->incremental;
11131 2076432 : constructor_designated = p->designated;
11132 2076432 : constructor_zero_padding_bits = p->zero_padding_bits;
11133 2076432 : constructor_braced_scalar = p->braced_scalar;
11134 2076432 : designator_depth = p->designator_depth;
11135 2076432 : constructor_pending_elts = p->pending_elts;
11136 2076432 : constructor_depth = p->depth;
11137 2076432 : if (!p->implicit)
11138 1371109 : constructor_range_stack = p->range_stack;
11139 2076432 : RESTORE_SPELLING_DEPTH (constructor_depth);
11140 :
11141 2076432 : constructor_stack = p->next;
11142 2076432 : XDELETE (p);
11143 :
11144 2076432 : if (ret.value == NULL_TREE && constructor_stack == 0)
11145 0 : ret.value = error_mark_node;
11146 2076432 : return ret;
11147 : }
11148 :
11149 : /* Common handling for both array range and field name designators.
11150 : ARRAY argument is nonzero for array ranges. Returns false for success. */
11151 :
11152 : static bool
11153 37158 : set_designator (location_t loc, bool array,
11154 : struct obstack *braced_init_obstack)
11155 : {
11156 37158 : tree subtype;
11157 37158 : enum tree_code subcode;
11158 :
11159 : /* Don't die if an entire brace-pair level is superfluous
11160 : in the containing level, or for an erroneous type. */
11161 37158 : if (constructor_type == NULL_TREE || constructor_type == error_mark_node)
11162 : return true;
11163 :
11164 : /* If there were errors in this designator list already, bail out
11165 : silently. */
11166 37149 : if (designator_erroneous)
11167 : return true;
11168 :
11169 : /* Likewise for an initializer for a variable-size type. Those are
11170 : diagnosed in the parser, except for empty initializer braces. */
11171 37149 : if (COMPLETE_TYPE_P (constructor_type)
11172 37149 : && TREE_CODE (TYPE_SIZE (constructor_type)) != INTEGER_CST)
11173 : return true;
11174 :
11175 37139 : if (!designator_depth)
11176 : {
11177 34820 : gcc_assert (!constructor_range_stack);
11178 :
11179 : /* Designator list starts at the level of closest explicit
11180 : braces. */
11181 36495 : while (constructor_stack->implicit)
11182 1675 : process_init_element (input_location,
11183 : pop_init_level (loc, 1, braced_init_obstack,
11184 : last_init_list_comma),
11185 : true, braced_init_obstack);
11186 34820 : constructor_designated = 1;
11187 34820 : return false;
11188 : }
11189 :
11190 2319 : switch (TREE_CODE (constructor_type))
11191 : {
11192 1442 : case RECORD_TYPE:
11193 1442 : case UNION_TYPE:
11194 1442 : subtype = TREE_TYPE (constructor_fields);
11195 1442 : if (subtype != error_mark_node)
11196 1442 : subtype = TYPE_MAIN_VARIANT (subtype);
11197 : break;
11198 877 : case ARRAY_TYPE:
11199 877 : subtype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
11200 877 : break;
11201 0 : default:
11202 0 : gcc_unreachable ();
11203 : }
11204 :
11205 2319 : subcode = TREE_CODE (subtype);
11206 2319 : if (array && subcode != ARRAY_TYPE)
11207 : {
11208 1 : error_init (loc, "array index in non-array initializer");
11209 1 : return true;
11210 : }
11211 2318 : else if (!array && subcode != RECORD_TYPE && subcode != UNION_TYPE)
11212 : {
11213 0 : error_init (loc, "field name not in record or union initializer");
11214 0 : return true;
11215 : }
11216 :
11217 2318 : constructor_designated = 1;
11218 2318 : finish_implicit_inits (loc, braced_init_obstack);
11219 2318 : push_init_level (loc, 2, braced_init_obstack);
11220 2318 : return false;
11221 : }
11222 :
11223 : /* If there are range designators in designator list, push a new designator
11224 : to constructor_range_stack. RANGE_END is end of such stack range or
11225 : NULL_TREE if there is no range designator at this level. */
11226 :
11227 : static void
11228 390 : push_range_stack (tree range_end, struct obstack * braced_init_obstack)
11229 : {
11230 390 : struct constructor_range_stack *p;
11231 :
11232 780 : p = (struct constructor_range_stack *)
11233 390 : obstack_alloc (braced_init_obstack,
11234 : sizeof (struct constructor_range_stack));
11235 390 : p->prev = constructor_range_stack;
11236 390 : p->next = 0;
11237 390 : p->fields = constructor_fields;
11238 390 : p->range_start = constructor_index;
11239 390 : p->index = constructor_index;
11240 390 : p->stack = constructor_stack;
11241 390 : p->range_end = range_end;
11242 390 : if (constructor_range_stack)
11243 19 : constructor_range_stack->next = p;
11244 390 : constructor_range_stack = p;
11245 390 : }
11246 :
11247 : /* Within an array initializer, specify the next index to be initialized.
11248 : FIRST is that index. If LAST is nonzero, then initialize a range
11249 : of indices, running from FIRST through LAST. */
11250 :
11251 : void
11252 1936 : set_init_index (location_t loc, tree first, tree last,
11253 : struct obstack *braced_init_obstack)
11254 : {
11255 1936 : if (set_designator (loc, true, braced_init_obstack))
11256 : return;
11257 :
11258 1933 : designator_erroneous = 1;
11259 :
11260 3866 : if (!INTEGRAL_TYPE_P (TREE_TYPE (first))
11261 3855 : || (last && !INTEGRAL_TYPE_P (TREE_TYPE (last))))
11262 : {
11263 12 : error_init (loc, "array index in initializer not of integer type");
11264 12 : return;
11265 : }
11266 :
11267 1921 : if (TREE_CODE (first) != INTEGER_CST)
11268 : {
11269 6 : first = c_fully_fold (first, false, NULL);
11270 6 : if (TREE_CODE (first) == INTEGER_CST)
11271 5 : pedwarn_init (loc, OPT_Wpedantic,
11272 : "array index in initializer is not "
11273 : "an integer constant expression");
11274 : }
11275 :
11276 1921 : if (last && TREE_CODE (last) != INTEGER_CST)
11277 : {
11278 2 : last = c_fully_fold (last, false, NULL);
11279 2 : if (TREE_CODE (last) == INTEGER_CST)
11280 1 : pedwarn_init (loc, OPT_Wpedantic,
11281 : "array index in initializer is not "
11282 : "an integer constant expression");
11283 : }
11284 :
11285 1921 : if (TREE_CODE (first) != INTEGER_CST)
11286 1 : error_init (loc, "nonconstant array index in initializer");
11287 1920 : else if (last != NULL_TREE && TREE_CODE (last) != INTEGER_CST)
11288 1 : error_init (loc, "nonconstant array index in initializer");
11289 1919 : else if (TREE_CODE (constructor_type) != ARRAY_TYPE)
11290 9 : error_init (loc, "array index in non-array initializer");
11291 1910 : else if (tree_int_cst_sgn (first) == -1)
11292 15 : error_init (loc, "array index in initializer exceeds array bounds");
11293 1895 : else if (constructor_max_index
11294 1895 : && tree_int_cst_lt (constructor_max_index, first))
11295 7 : error_init (loc, "array index in initializer exceeds array bounds");
11296 : else
11297 : {
11298 1888 : constant_expression_warning (first);
11299 1888 : if (last)
11300 385 : constant_expression_warning (last);
11301 1888 : constructor_index = convert (bitsizetype, first);
11302 1888 : if (tree_int_cst_lt (constructor_index, first))
11303 : {
11304 0 : constructor_index = copy_node (constructor_index);
11305 0 : TREE_OVERFLOW (constructor_index) = 1;
11306 : }
11307 :
11308 1888 : if (last)
11309 : {
11310 385 : if (tree_int_cst_equal (first, last))
11311 : last = NULL_TREE;
11312 384 : else if (tree_int_cst_lt (last, first))
11313 : {
11314 2 : error_init (loc, "empty index range in initializer");
11315 2 : last = NULL_TREE;
11316 : }
11317 : else
11318 : {
11319 382 : last = convert (bitsizetype, last);
11320 382 : if (constructor_max_index != NULL_TREE
11321 382 : && tree_int_cst_lt (constructor_max_index, last))
11322 : {
11323 3 : error_init (loc, "array index range in initializer exceeds "
11324 : "array bounds");
11325 3 : last = NULL_TREE;
11326 : }
11327 : }
11328 : }
11329 :
11330 1888 : designator_depth++;
11331 1888 : designator_erroneous = 0;
11332 1888 : if (constructor_range_stack || last)
11333 379 : push_range_stack (last, braced_init_obstack);
11334 : }
11335 : }
11336 :
11337 : /* Within a struct initializer, specify the next field to be initialized. */
11338 :
11339 : void
11340 35176 : set_init_label (location_t loc, tree fieldname, location_t fieldname_loc,
11341 : struct obstack *braced_init_obstack)
11342 : {
11343 35176 : tree field;
11344 :
11345 35176 : if (set_designator (loc, false, braced_init_obstack))
11346 : return;
11347 :
11348 35159 : designator_erroneous = 1;
11349 :
11350 35159 : if (!RECORD_OR_UNION_TYPE_P (constructor_type))
11351 : {
11352 3 : error_init (loc, "field name not in record or union initializer");
11353 3 : return;
11354 : }
11355 :
11356 35156 : field = lookup_field (constructor_type, fieldname);
11357 :
11358 35156 : if (field == NULL_TREE)
11359 : {
11360 8 : tree guessed_id = lookup_field_fuzzy (constructor_type, fieldname);
11361 8 : if (guessed_id)
11362 : {
11363 4 : gcc_rich_location rich_loc (fieldname_loc);
11364 4 : rich_loc.add_fixit_misspelled_id (fieldname_loc, guessed_id);
11365 4 : error_at (&rich_loc,
11366 : "%qT has no member named %qE; did you mean %qE?",
11367 : constructor_type, fieldname, guessed_id);
11368 4 : }
11369 : else
11370 4 : error_at (fieldname_loc, "%qT has no member named %qE",
11371 : constructor_type, fieldname);
11372 : }
11373 : else
11374 35194 : do
11375 : {
11376 35194 : constructor_fields = TREE_VALUE (field);
11377 35194 : designator_depth++;
11378 35194 : designator_erroneous = 0;
11379 35194 : if (constructor_range_stack)
11380 11 : push_range_stack (NULL_TREE, braced_init_obstack);
11381 35194 : field = TREE_CHAIN (field);
11382 35194 : if (field)
11383 : {
11384 46 : if (set_designator (loc, false, braced_init_obstack))
11385 : return;
11386 : }
11387 : }
11388 35194 : while (field != NULL_TREE);
11389 : }
11390 :
11391 : /* Helper function for add_pending_init. Find inorder successor of P
11392 : in AVL tree. */
11393 : static struct init_node *
11394 129 : init_node_successor (struct init_node *p)
11395 : {
11396 129 : struct init_node *r;
11397 129 : if (p->right)
11398 : {
11399 : r = p->right;
11400 58 : while (r->left)
11401 : r = r->left;
11402 : return r;
11403 : }
11404 75 : r = p->parent;
11405 114 : while (r && p == r->right)
11406 : {
11407 39 : p = r;
11408 39 : r = r->parent;
11409 : }
11410 : return r;
11411 : }
11412 :
11413 : /* Add a new initializer to the tree of pending initializers. PURPOSE
11414 : identifies the initializer, either array index or field in a structure.
11415 : VALUE is the value of that index or field. If ORIGTYPE is not
11416 : NULL_TREE, it is the original type of VALUE.
11417 :
11418 : IMPLICIT is true if value comes from pop_init_level (1),
11419 : the new initializer has been merged with the existing one
11420 : and thus no warnings should be emitted about overriding an
11421 : existing initializer. */
11422 :
11423 : static void
11424 7989 : add_pending_init (location_t loc, tree purpose, tree value, tree origtype,
11425 : bool implicit, struct obstack *braced_init_obstack)
11426 : {
11427 7989 : struct init_node *p, **q, *r;
11428 :
11429 12538 : q = &constructor_pending_elts;
11430 7989 : p = 0;
11431 :
11432 7989 : if (TREE_CODE (constructor_type) == ARRAY_TYPE)
11433 : {
11434 7221 : while (*q != 0)
11435 : {
11436 4386 : p = *q;
11437 4386 : if (tree_int_cst_lt (purpose, p->purpose))
11438 419 : q = &p->left;
11439 3967 : else if (tree_int_cst_lt (p->purpose, purpose))
11440 : {
11441 3356 : if (TREE_CODE (p->value) != RAW_DATA_CST
11442 3356 : || (p->right
11443 112 : && tree_int_cst_le (p->right->purpose, purpose)))
11444 3226 : q = &p->right;
11445 : else
11446 : {
11447 130 : widest_int pp = wi::to_widest (p->purpose);
11448 130 : widest_int pw = wi::to_widest (purpose);
11449 130 : if (pp + RAW_DATA_LENGTH (p->value) <= pw)
11450 98 : q = &p->right;
11451 : else
11452 : {
11453 : /* Override which should split the old RAW_DATA_CST
11454 : into 2 or 3 pieces. */
11455 32 : if (!implicit && warn_override_init)
11456 9 : warning_init (loc, OPT_Woverride_init,
11457 : "initialized field overwritten");
11458 32 : unsigned HOST_WIDE_INT start = (pw - pp).to_uhwi ();
11459 32 : unsigned HOST_WIDE_INT len = 1;
11460 32 : if (TREE_CODE (value) == RAW_DATA_CST)
11461 0 : len = RAW_DATA_LENGTH (value);
11462 32 : unsigned HOST_WIDE_INT end = 0;
11463 32 : unsigned plen = RAW_DATA_LENGTH (p->value);
11464 32 : gcc_checking_assert (start < plen && start);
11465 32 : if (plen - start > len)
11466 30 : end = plen - start - len;
11467 32 : tree v = p->value;
11468 32 : tree origtype = p->origtype;
11469 32 : if (start == 1)
11470 2 : p->value = build_int_cst (TREE_TYPE (v),
11471 2 : RAW_DATA_UCHAR_ELT (v, 0));
11472 : else
11473 : {
11474 30 : p->value = v;
11475 30 : if (end > 1)
11476 26 : v = copy_node (v);
11477 30 : RAW_DATA_LENGTH (p->value) = start;
11478 : }
11479 32 : if (end)
11480 : {
11481 30 : tree epurpose
11482 30 : = size_binop (PLUS_EXPR, purpose,
11483 : bitsize_int (len));
11484 30 : if (end > 1)
11485 : {
11486 28 : RAW_DATA_LENGTH (v) -= plen - end;
11487 28 : RAW_DATA_POINTER (v) += plen - end;
11488 : }
11489 : else
11490 2 : v = build_int_cst (TREE_TYPE (v),
11491 2 : RAW_DATA_UCHAR_ELT (v, plen
11492 : - end));
11493 30 : add_pending_init (loc, epurpose, v, origtype,
11494 : implicit, braced_init_obstack);
11495 : }
11496 32 : q = &constructor_pending_elts;
11497 32 : continue;
11498 32 : }
11499 130 : }
11500 : }
11501 : else
11502 : {
11503 611 : if (TREE_CODE (p->value) == RAW_DATA_CST
11504 621 : && (RAW_DATA_LENGTH (p->value)
11505 10 : > (TREE_CODE (value) == RAW_DATA_CST
11506 10 : ? RAW_DATA_LENGTH (value) : 1)))
11507 : {
11508 : /* Override which should split the old RAW_DATA_CST
11509 : into 2 pieces. */
11510 6 : if (!implicit && warn_override_init)
11511 3 : warning_init (loc, OPT_Woverride_init,
11512 : "initialized field overwritten");
11513 6 : unsigned HOST_WIDE_INT len = 1;
11514 6 : if (TREE_CODE (value) == RAW_DATA_CST)
11515 2 : len = RAW_DATA_LENGTH (value);
11516 6 : if ((unsigned) RAW_DATA_LENGTH (p->value) > len + 1)
11517 : {
11518 6 : RAW_DATA_LENGTH (p->value) -= len;
11519 6 : RAW_DATA_POINTER (p->value) += len;
11520 : }
11521 : else
11522 : {
11523 0 : unsigned int l = RAW_DATA_LENGTH (p->value) - 1;
11524 0 : p->value
11525 0 : = build_int_cst (TREE_TYPE (p->value),
11526 0 : RAW_DATA_UCHAR_ELT (p->value, l));
11527 : }
11528 6 : p->purpose = size_binop (PLUS_EXPR, p->purpose,
11529 : bitsize_int (len));
11530 6 : continue;
11531 6 : }
11532 605 : if (TREE_CODE (value) == RAW_DATA_CST)
11533 : {
11534 8 : handle_raw_data:
11535 : /* RAW_DATA_CST value might overlap various further
11536 : prior initval entries. Find out how many. */
11537 13 : unsigned cnt = 0;
11538 13 : widest_int w
11539 26 : = wi::to_widest (purpose) + RAW_DATA_LENGTH (value);
11540 13 : struct init_node *r = p, *last = NULL;
11541 13 : bool override_init = warn_override_init;
11542 13 : while ((r = init_node_successor (r))
11543 53 : && wi::to_widest (r->purpose) < w)
11544 : {
11545 40 : ++cnt;
11546 40 : if (TREE_SIDE_EFFECTS (r->value))
11547 2 : warning_init (loc, OPT_Woverride_init_side_effects,
11548 : "initialized field with side-effects "
11549 : "overwritten");
11550 38 : else if (override_init)
11551 : {
11552 6 : warning_init (loc, OPT_Woverride_init,
11553 : "initialized field overwritten");
11554 6 : override_init = false;
11555 : }
11556 40 : last = r;
11557 : }
11558 13 : if (cnt)
11559 : {
11560 26 : if (TREE_CODE (last->value) == RAW_DATA_CST
11561 13 : && (wi::to_widest (last->purpose)
11562 13 : + RAW_DATA_LENGTH (last->value) > w))
11563 : {
11564 : /* The last overlapping prior initval overlaps
11565 : only partially. Shrink it and decrease cnt. */
11566 0 : unsigned int l = (wi::to_widest (last->purpose)
11567 0 : + RAW_DATA_LENGTH (last->value)
11568 0 : - w).to_uhwi ();
11569 0 : --cnt;
11570 0 : RAW_DATA_LENGTH (last->value) -= l;
11571 0 : RAW_DATA_POINTER (last->value) += l;
11572 0 : if (RAW_DATA_LENGTH (last->value) == 1)
11573 0 : last->value
11574 0 : = build_int_cst (TREE_TYPE (last->value),
11575 0 : RAW_DATA_UCHAR_ELT (last->value,
11576 : 0));
11577 0 : last->purpose
11578 0 : = size_binop (PLUS_EXPR, last->purpose,
11579 : bitsize_int (l));
11580 : }
11581 : /* Instead of deleting cnt nodes from the AVL tree
11582 : and rebalancing, peel of last cnt bytes from the
11583 : RAW_DATA_CST. Overriding thousands of previously
11584 : initialized array elements with #embed needs to work,
11585 : but doesn't need to be super efficient. */
11586 13 : gcc_checking_assert ((unsigned) RAW_DATA_LENGTH (value)
11587 : > cnt);
11588 13 : RAW_DATA_LENGTH (value) -= cnt;
11589 13 : const unsigned char *s
11590 13 : = &RAW_DATA_UCHAR_ELT (value, RAW_DATA_LENGTH (value));
11591 13 : unsigned int o = RAW_DATA_LENGTH (value);
11592 53 : for (r = p; cnt--; ++o, ++s)
11593 : {
11594 40 : r = init_node_successor (r);
11595 40 : r->purpose = size_binop (PLUS_EXPR, purpose,
11596 : bitsize_int (o));
11597 40 : r->value = build_int_cst (TREE_TYPE (value), *s);
11598 40 : r->origtype = origtype;
11599 : }
11600 13 : if (RAW_DATA_LENGTH (value) == 1)
11601 0 : value = build_int_cst (TREE_TYPE (value),
11602 0 : RAW_DATA_UCHAR_ELT (value, 0));
11603 : }
11604 : }
11605 610 : if (!implicit)
11606 : {
11607 54 : if (TREE_SIDE_EFFECTS (p->value))
11608 6 : warning_init (loc, OPT_Woverride_init_side_effects,
11609 : "initialized field with side-effects "
11610 : "overwritten");
11611 48 : else if (warn_override_init)
11612 13 : warning_init (loc, OPT_Woverride_init,
11613 : "initialized field overwritten");
11614 : }
11615 610 : p->value = value;
11616 610 : p->origtype = origtype;
11617 610 : return;
11618 : }
11619 : }
11620 2835 : if (TREE_CODE (value) == RAW_DATA_CST && p)
11621 : {
11622 61 : struct init_node *r;
11623 61 : if (q == &p->left)
11624 : r = p;
11625 : else
11626 36 : r = init_node_successor (p);
11627 131 : if (r && wi::to_widest (r->purpose) < (wi::to_widest (purpose)
11628 131 : + RAW_DATA_LENGTH (value)))
11629 : {
11630 : /* Overlap with at least one prior initval in the range but
11631 : not at the start. */
11632 5 : p = r;
11633 5 : p->purpose = purpose;
11634 5 : goto handle_raw_data;
11635 : }
11636 : }
11637 : }
11638 : else
11639 : {
11640 4549 : tree bitpos;
11641 :
11642 4549 : bitpos = bit_position (purpose);
11643 8187 : while (*q != NULL)
11644 : {
11645 4881 : p = *q;
11646 4881 : if (tree_int_cst_lt (bitpos, bit_position (p->purpose)))
11647 81 : q = &p->left;
11648 4800 : else if (p->purpose != purpose)
11649 3557 : q = &p->right;
11650 : else
11651 : {
11652 1243 : if (!implicit)
11653 : {
11654 101 : if (TREE_SIDE_EFFECTS (p->value))
11655 4 : warning_init (loc, OPT_Woverride_init_side_effects,
11656 : "initialized field with side-effects "
11657 : "overwritten");
11658 97 : else if (warn_override_init)
11659 6 : warning_init (loc, OPT_Woverride_init,
11660 : "initialized field overwritten");
11661 : }
11662 1243 : p->value = value;
11663 1243 : p->origtype = origtype;
11664 1243 : return;
11665 : }
11666 : }
11667 : }
11668 :
11669 6136 : r = (struct init_node *) obstack_alloc (braced_init_obstack,
11670 : sizeof (struct init_node));
11671 6136 : r->purpose = purpose;
11672 6136 : r->value = value;
11673 6136 : r->origtype = origtype;
11674 :
11675 6136 : *q = r;
11676 6136 : r->parent = p;
11677 6136 : r->left = 0;
11678 6136 : r->right = 0;
11679 6136 : r->balance = 0;
11680 :
11681 9962 : while (p)
11682 : {
11683 5214 : struct init_node *s;
11684 :
11685 5214 : if (r == p->left)
11686 : {
11687 343 : if (p->balance == 0)
11688 246 : p->balance = -1;
11689 97 : else if (p->balance < 0)
11690 : {
11691 45 : if (r->balance < 0)
11692 : {
11693 : /* L rotation. */
11694 40 : p->left = r->right;
11695 40 : if (p->left)
11696 2 : p->left->parent = p;
11697 40 : r->right = p;
11698 :
11699 40 : p->balance = 0;
11700 40 : r->balance = 0;
11701 :
11702 40 : s = p->parent;
11703 40 : p->parent = r;
11704 40 : r->parent = s;
11705 40 : if (s)
11706 : {
11707 31 : if (s->left == p)
11708 10 : s->left = r;
11709 : else
11710 21 : s->right = r;
11711 : }
11712 : else
11713 9 : constructor_pending_elts = r;
11714 : }
11715 : else
11716 : {
11717 : /* LR rotation. */
11718 5 : struct init_node *t = r->right;
11719 :
11720 5 : r->right = t->left;
11721 5 : if (r->right)
11722 0 : r->right->parent = r;
11723 5 : t->left = r;
11724 :
11725 5 : p->left = t->right;
11726 5 : if (p->left)
11727 0 : p->left->parent = p;
11728 5 : t->right = p;
11729 :
11730 5 : p->balance = t->balance < 0;
11731 5 : r->balance = -(t->balance > 0);
11732 5 : t->balance = 0;
11733 :
11734 5 : s = p->parent;
11735 5 : p->parent = t;
11736 5 : r->parent = t;
11737 5 : t->parent = s;
11738 5 : if (s)
11739 : {
11740 0 : if (s->left == p)
11741 0 : s->left = t;
11742 : else
11743 0 : s->right = t;
11744 : }
11745 : else
11746 5 : constructor_pending_elts = t;
11747 : }
11748 : break;
11749 : }
11750 : else
11751 : {
11752 : /* p->balance == +1; growth of left side balances the node. */
11753 52 : p->balance = 0;
11754 52 : break;
11755 : }
11756 : }
11757 : else /* r == p->right */
11758 : {
11759 4871 : if (p->balance == 0)
11760 : /* Growth propagation from right side. */
11761 3580 : p->balance++;
11762 1291 : else if (p->balance > 0)
11763 : {
11764 1228 : if (r->balance > 0)
11765 : {
11766 : /* R rotation. */
11767 1222 : p->right = r->left;
11768 1222 : if (p->right)
11769 193 : p->right->parent = p;
11770 1222 : r->left = p;
11771 :
11772 1222 : p->balance = 0;
11773 1222 : r->balance = 0;
11774 :
11775 1222 : s = p->parent;
11776 1222 : p->parent = r;
11777 1222 : r->parent = s;
11778 1222 : if (s)
11779 : {
11780 414 : if (s->left == p)
11781 2 : s->left = r;
11782 : else
11783 412 : s->right = r;
11784 : }
11785 : else
11786 808 : constructor_pending_elts = r;
11787 : }
11788 : else /* r->balance == -1 */
11789 : {
11790 : /* RL rotation */
11791 6 : struct init_node *t = r->left;
11792 :
11793 6 : r->left = t->right;
11794 6 : if (r->left)
11795 2 : r->left->parent = r;
11796 6 : t->right = r;
11797 :
11798 6 : p->right = t->left;
11799 6 : if (p->right)
11800 2 : p->right->parent = p;
11801 6 : t->left = p;
11802 :
11803 6 : r->balance = (t->balance < 0);
11804 6 : p->balance = -(t->balance > 0);
11805 6 : t->balance = 0;
11806 :
11807 6 : s = p->parent;
11808 6 : p->parent = t;
11809 6 : r->parent = t;
11810 6 : t->parent = s;
11811 6 : if (s)
11812 : {
11813 4 : if (s->left == p)
11814 0 : s->left = t;
11815 : else
11816 4 : s->right = t;
11817 : }
11818 : else
11819 2 : constructor_pending_elts = t;
11820 : }
11821 : break;
11822 : }
11823 : else
11824 : {
11825 : /* p->balance == -1; growth of right side balances the node. */
11826 63 : p->balance = 0;
11827 63 : break;
11828 : }
11829 : }
11830 :
11831 3826 : r = p;
11832 3826 : p = p->parent;
11833 : }
11834 : }
11835 :
11836 : /* Build AVL tree from a sorted chain. */
11837 :
11838 : static void
11839 1812 : set_nonincremental_init (struct obstack * braced_init_obstack)
11840 : {
11841 1812 : unsigned HOST_WIDE_INT ix;
11842 1812 : tree index, value;
11843 :
11844 1812 : if (TREE_CODE (constructor_type) != RECORD_TYPE
11845 1812 : && TREE_CODE (constructor_type) != ARRAY_TYPE)
11846 : return;
11847 :
11848 5511 : FOR_EACH_CONSTRUCTOR_ELT (constructor_elements, ix, index, value)
11849 3699 : add_pending_init (input_location, index, value, NULL_TREE, true,
11850 : braced_init_obstack);
11851 1812 : constructor_elements = NULL;
11852 1812 : if (TREE_CODE (constructor_type) == RECORD_TYPE)
11853 : {
11854 948 : constructor_unfilled_fields = TYPE_FIELDS (constructor_type);
11855 : /* Skip any nameless bit fields at the beginning. */
11856 948 : while (constructor_unfilled_fields != NULL_TREE
11857 948 : && DECL_UNNAMED_BIT_FIELD (constructor_unfilled_fields))
11858 0 : constructor_unfilled_fields = TREE_CHAIN (constructor_unfilled_fields);
11859 :
11860 : }
11861 864 : else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
11862 : {
11863 864 : if (TYPE_DOMAIN (constructor_type))
11864 806 : constructor_unfilled_index
11865 806 : = convert (bitsizetype,
11866 806 : TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
11867 : else
11868 58 : constructor_unfilled_index = bitsize_zero_node;
11869 : }
11870 1812 : constructor_incremental = 0;
11871 : }
11872 :
11873 : /* Build AVL tree from a string constant. */
11874 :
11875 : static void
11876 7 : set_nonincremental_init_from_string (tree str,
11877 : struct obstack * braced_init_obstack)
11878 : {
11879 7 : tree value, purpose, type;
11880 7 : HOST_WIDE_INT val[2];
11881 7 : const char *p, *end;
11882 7 : int byte, wchar_bytes, charwidth, bitpos;
11883 :
11884 7 : gcc_assert (TREE_CODE (constructor_type) == ARRAY_TYPE);
11885 :
11886 7 : wchar_bytes = TYPE_PRECISION (TREE_TYPE (TREE_TYPE (str))) / BITS_PER_UNIT;
11887 7 : charwidth = TYPE_PRECISION (char_type_node);
11888 7 : gcc_assert ((size_t) wchar_bytes * charwidth
11889 : <= ARRAY_SIZE (val) * HOST_BITS_PER_WIDE_INT);
11890 7 : type = TREE_TYPE (constructor_type);
11891 7 : p = TREE_STRING_POINTER (str);
11892 7 : end = p + TREE_STRING_LENGTH (str);
11893 :
11894 7 : for (purpose = bitsize_zero_node;
11895 : p < end
11896 52 : && !(constructor_max_index
11897 20 : && tree_int_cst_lt (constructor_max_index, purpose));
11898 25 : purpose = size_binop (PLUS_EXPR, purpose, bitsize_one_node))
11899 : {
11900 25 : if (wchar_bytes == 1)
11901 : {
11902 9 : val[0] = (unsigned char) *p++;
11903 9 : val[1] = 0;
11904 : }
11905 : else
11906 : {
11907 16 : val[1] = 0;
11908 16 : val[0] = 0;
11909 64 : for (byte = 0; byte < wchar_bytes; byte++)
11910 : {
11911 48 : if (BYTES_BIG_ENDIAN)
11912 : bitpos = (wchar_bytes - byte - 1) * charwidth;
11913 : else
11914 48 : bitpos = byte * charwidth;
11915 48 : val[bitpos / HOST_BITS_PER_WIDE_INT]
11916 48 : |= ((unsigned HOST_WIDE_INT) ((unsigned char) *p++))
11917 48 : << (bitpos % HOST_BITS_PER_WIDE_INT);
11918 : }
11919 : }
11920 :
11921 25 : if (!TYPE_UNSIGNED (type))
11922 : {
11923 13 : bitpos = ((wchar_bytes - 1) * charwidth) + HOST_BITS_PER_CHAR;
11924 13 : if (bitpos < HOST_BITS_PER_WIDE_INT)
11925 : {
11926 13 : if (val[0] & (HOST_WIDE_INT_1 << (bitpos - 1)))
11927 : {
11928 0 : val[0] |= HOST_WIDE_INT_M1U << bitpos;
11929 0 : val[1] = -1;
11930 : }
11931 : }
11932 0 : else if (bitpos == HOST_BITS_PER_WIDE_INT)
11933 : {
11934 0 : if (val[0] < 0)
11935 0 : val[1] = -1;
11936 : }
11937 0 : else if (val[1] & (HOST_WIDE_INT_1
11938 0 : << (bitpos - 1 - HOST_BITS_PER_WIDE_INT)))
11939 0 : val[1] |= HOST_WIDE_INT_M1U << (bitpos - HOST_BITS_PER_WIDE_INT);
11940 : }
11941 :
11942 25 : value = wide_int_to_tree (type,
11943 25 : wide_int::from_array (val, 2,
11944 : HOST_BITS_PER_WIDE_INT * 2));
11945 25 : add_pending_init (input_location, purpose, value, NULL_TREE, true,
11946 : braced_init_obstack);
11947 : }
11948 :
11949 7 : constructor_incremental = 0;
11950 7 : }
11951 :
11952 : /* Return value of FIELD in pending initializer or NULL_TREE if the field was
11953 : not initialized yet. */
11954 :
11955 : static tree
11956 705323 : find_init_member (tree field, struct obstack * braced_init_obstack)
11957 : {
11958 705323 : struct init_node *p;
11959 :
11960 705323 : if (TREE_CODE (constructor_type) == ARRAY_TYPE)
11961 : {
11962 703504 : if (constructor_incremental
11963 703504 : && tree_int_cst_lt (field, constructor_unfilled_index))
11964 16 : set_nonincremental_init (braced_init_obstack);
11965 :
11966 703504 : p = constructor_pending_elts;
11967 704103 : while (p)
11968 : {
11969 1151 : if (tree_int_cst_lt (field, p->purpose))
11970 93 : p = p->left;
11971 1058 : else if (tree_int_cst_lt (p->purpose, field))
11972 506 : p = p->right;
11973 : else
11974 552 : return p->value;
11975 : }
11976 : }
11977 1819 : else if (TREE_CODE (constructor_type) == RECORD_TYPE)
11978 : {
11979 1696 : tree bitpos = bit_position (field);
11980 :
11981 1696 : if (constructor_incremental
11982 1696 : && (!constructor_unfilled_fields
11983 609 : || tree_int_cst_lt (bitpos,
11984 609 : bit_position (constructor_unfilled_fields))))
11985 289 : set_nonincremental_init (braced_init_obstack);
11986 :
11987 1696 : p = constructor_pending_elts;
11988 2652 : while (p)
11989 : {
11990 2047 : if (field == p->purpose)
11991 1091 : return p->value;
11992 956 : else if (tree_int_cst_lt (bitpos, bit_position (p->purpose)))
11993 7 : p = p->left;
11994 : else
11995 949 : p = p->right;
11996 : }
11997 : }
11998 123 : else if (TREE_CODE (constructor_type) == UNION_TYPE)
11999 : {
12000 123 : if (!vec_safe_is_empty (constructor_elements)
12001 50 : && (constructor_elements->last ().index == field))
12002 50 : return constructor_elements->last ().value;
12003 : }
12004 : return NULL_TREE;
12005 : }
12006 :
12007 : /* "Output" the next constructor element.
12008 : At top level, really output it to assembler code now.
12009 : Otherwise, collect it in a list from which we will make a CONSTRUCTOR.
12010 : If ORIGTYPE is not NULL_TREE, it is the original type of VALUE.
12011 : TYPE is the data type that the containing data type wants here.
12012 : FIELD is the field (a FIELD_DECL) or the index that this element fills.
12013 : If VALUE is a string constant, STRICT_STRING is true if it is
12014 : unparenthesized or we should not warn here for it being parenthesized.
12015 : For other types of VALUE, STRICT_STRING is not used.
12016 :
12017 : PENDING if true means output pending elements that belong
12018 : right after this element. (PENDING is normally true;
12019 : it is false while outputting pending elements, to avoid recursion.)
12020 :
12021 : IMPLICIT is true if value comes from pop_init_level (1),
12022 : the new initializer has been merged with the existing one
12023 : and thus no warnings should be emitted about overriding an
12024 : existing initializer. */
12025 :
12026 : static void
12027 9668419 : output_init_element (location_t loc, tree value, tree origtype,
12028 : bool strict_string, tree type, tree field, bool pending,
12029 : bool implicit, struct obstack * braced_init_obstack)
12030 : {
12031 9668419 : tree semantic_type = NULL_TREE;
12032 9668419 : bool maybe_const = true;
12033 9668419 : bool npc, int_const_expr, arith_const_expr;
12034 :
12035 9668419 : if (type == error_mark_node || value == error_mark_node)
12036 : {
12037 257 : constructor_erroneous = 1;
12038 4596 : return;
12039 : }
12040 9668162 : if (TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE
12041 201020 : && (TREE_CODE (value) == STRING_CST
12042 159589 : || TREE_CODE (value) == COMPOUND_LITERAL_EXPR)
12043 41439 : && !(TREE_CODE (value) == STRING_CST
12044 41431 : && TREE_CODE (type) == ARRAY_TYPE
12045 3898 : && INTEGRAL_TYPE_P (TREE_TYPE (type)))
12046 9705703 : && !comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (value)),
12047 37541 : TYPE_MAIN_VARIANT (type)))
12048 37541 : value = array_to_pointer_conversion (input_location, value);
12049 :
12050 9668162 : if (TREE_CODE (value) == COMPOUND_LITERAL_EXPR
12051 182 : && require_constant_value && pending)
12052 : {
12053 : /* As an extension, allow initializing objects with static storage
12054 : duration with compound literals (which are then treated just as
12055 : the brace enclosed list they contain). */
12056 114 : if (flag_isoc99)
12057 24 : pedwarn_init (loc, OPT_Wpedantic, "initializer element is not "
12058 : "constant");
12059 114 : tree decl = COMPOUND_LITERAL_EXPR_DECL (value);
12060 114 : value = DECL_INITIAL (decl);
12061 : }
12062 :
12063 9668162 : npc = null_pointer_constant_p (value);
12064 19336324 : int_const_expr = (TREE_CODE (value) == INTEGER_CST
12065 4240319 : && !TREE_OVERFLOW (value)
12066 13908480 : && INTEGRAL_TYPE_P (TREE_TYPE (value)));
12067 : /* Not fully determined before folding. */
12068 9668162 : arith_const_expr = true;
12069 9668162 : if (TREE_CODE (value) == EXCESS_PRECISION_EXPR)
12070 : {
12071 16 : semantic_type = TREE_TYPE (value);
12072 16 : value = TREE_OPERAND (value, 0);
12073 : }
12074 9668162 : value = c_fully_fold (value, require_constant_value, &maybe_const);
12075 : /* TODO: this may not detect all cases of expressions folding to
12076 : constants that are not arithmetic constant expressions. */
12077 9668162 : if (!maybe_const)
12078 : arith_const_expr = false;
12079 19333783 : else if (!INTEGRAL_TYPE_P (TREE_TYPE (value))
12080 3196757 : && TREE_CODE (TREE_TYPE (value)) != REAL_TYPE
12081 11513284 : && TREE_CODE (TREE_TYPE (value)) != COMPLEX_TYPE)
12082 : arith_const_expr = false;
12083 7835875 : else if (TREE_CODE (value) != INTEGER_CST
12084 : && TREE_CODE (value) != REAL_CST
12085 : && TREE_CODE (value) != COMPLEX_CST
12086 : && TREE_CODE (value) != RAW_DATA_CST)
12087 : arith_const_expr = false;
12088 4631527 : else if (TREE_OVERFLOW (value))
12089 5036636 : arith_const_expr = false;
12090 :
12091 9668162 : if (value == error_mark_node)
12092 0 : constructor_erroneous = 1;
12093 9668162 : else if (!TREE_CONSTANT (value))
12094 3224874 : constructor_constant = 0;
12095 6443288 : else if (!initializer_constant_valid_p (value,
12096 6443288 : TREE_TYPE (value),
12097 6443288 : AGGREGATE_TYPE_P (constructor_type)
12098 2761994 : && TYPE_REVERSE_STORAGE_ORDER
12099 : (constructor_type))
12100 6443288 : || (RECORD_OR_UNION_TYPE_P (constructor_type)
12101 1041905 : && DECL_C_BIT_FIELD (field)
12102 7978 : && TREE_CODE (value) != INTEGER_CST))
12103 77 : constructor_simple = 0;
12104 9668162 : if (!maybe_const)
12105 1174 : constructor_nonconst = 1;
12106 :
12107 : /* Digest the initializer and issue any errors about incompatible
12108 : types before issuing errors about non-constant initializers. */
12109 9668162 : tree new_value = value;
12110 9668162 : if (semantic_type)
12111 16 : new_value = build1 (EXCESS_PRECISION_EXPR, semantic_type, value);
12112 : /* In the case of braces around a scalar initializer, the result of
12113 : this initializer processing goes through digest_init again at the
12114 : outer level. In the case of a constexpr initializer for a
12115 : pointer, avoid converting a null pointer constant to something
12116 : that is not a null pointer constant to avoid a spurious error
12117 : from that second processing. */
12118 9668162 : if (!require_constexpr_value
12119 398 : || !npc
12120 69 : || TREE_CODE (constructor_type) != POINTER_TYPE)
12121 9668151 : new_value = digest_init (loc,
12122 9668151 : RECORD_OR_UNION_TYPE_P (constructor_type)
12123 8593030 : ? field : constructor_fields
12124 8593030 : ? constructor_fields : constructor_decl,
12125 : type, new_value, origtype, npc,
12126 : int_const_expr, arith_const_expr, strict_string,
12127 : require_constant_value, require_constexpr_value);
12128 9668162 : if (new_value == error_mark_node)
12129 : {
12130 76 : constructor_erroneous = 1;
12131 76 : return;
12132 : }
12133 9668086 : if (require_constant_value || require_constant_elements)
12134 2716572 : constant_expression_warning (new_value);
12135 :
12136 : /* Proceed to check the constness of the original initializer. */
12137 9668086 : if (!initializer_constant_valid_p (value, TREE_TYPE (value)))
12138 : {
12139 3224900 : if (require_constant_value)
12140 : {
12141 0 : error_init (loc, "initializer element is not constant");
12142 0 : value = error_mark_node;
12143 : }
12144 3224900 : else if (require_constant_elements)
12145 21 : pedwarn (loc, OPT_Wpedantic,
12146 : "initializer element is not computable at load time");
12147 : }
12148 6443186 : else if (!maybe_const
12149 54 : && (require_constant_value || require_constant_elements))
12150 28 : pedwarn_init (loc, OPT_Wpedantic,
12151 : "initializer element is not a constant expression");
12152 : /* digest_init has already carried out the additional checks
12153 : required for 'constexpr' initializers (using the information
12154 : passed to it about whether the original initializer was certain
12155 : kinds of constant expression), so that check does not need to be
12156 : repeated here. */
12157 :
12158 : /* Issue -Wc++-compat warnings about initializing a bitfield with
12159 : enum type. */
12160 9668086 : if (warn_cxx_compat
12161 6900 : && field != NULL_TREE
12162 6900 : && TREE_CODE (field) == FIELD_DECL
12163 464 : && DECL_BIT_FIELD_TYPE (field) != NULL_TREE
12164 21 : && (TYPE_MAIN_VARIANT (DECL_BIT_FIELD_TYPE (field))
12165 21 : != TYPE_MAIN_VARIANT (type))
12166 9668107 : && TREE_CODE (DECL_BIT_FIELD_TYPE (field)) == ENUMERAL_TYPE)
12167 : {
12168 21 : tree checktype = origtype != NULL_TREE ? origtype : TREE_TYPE (value);
12169 21 : if (checktype != error_mark_node
12170 21 : && (TYPE_MAIN_VARIANT (checktype)
12171 21 : != TYPE_MAIN_VARIANT (DECL_BIT_FIELD_TYPE (field))))
12172 9 : warning_init (loc, OPT_Wc___compat,
12173 : "enum conversion in initialization is invalid in C++");
12174 : }
12175 :
12176 : /* If this field is empty and does not have side effects (and is not at
12177 : the end of structure), don't do anything other than checking the
12178 : initializer. */
12179 9668086 : if (field
12180 9668086 : && (TREE_TYPE (field) == error_mark_node
12181 9667651 : || (COMPLETE_TYPE_P (TREE_TYPE (field))
12182 9667342 : && integer_zerop (TYPE_SIZE (TREE_TYPE (field)))
12183 92 : && !TREE_SIDE_EFFECTS (new_value)
12184 63 : && (TREE_CODE (constructor_type) == ARRAY_TYPE
12185 63 : || DECL_CHAIN (field)))))
12186 : return;
12187 :
12188 : /* Finally, set VALUE to the initializer value digested above. */
12189 9668058 : value = new_value;
12190 :
12191 : /* If this element doesn't come next in sequence,
12192 : put it on constructor_pending_elts. */
12193 9668058 : if (TREE_CODE (constructor_type) == ARRAY_TYPE
12194 9668058 : && (!constructor_incremental
12195 1723278 : || !tree_int_cst_equal (field, constructor_unfilled_index)
12196 1722839 : || (TREE_CODE (value) == RAW_DATA_CST
12197 238 : && constructor_pending_elts
12198 66 : && pending)))
12199 : {
12200 1346 : if (constructor_incremental
12201 1346 : && (tree_int_cst_lt (field, constructor_unfilled_index)
12202 410 : || (TREE_CODE (value) == RAW_DATA_CST
12203 14 : && constructor_pending_elts
12204 14 : && pending)))
12205 48 : set_nonincremental_init (braced_init_obstack);
12206 :
12207 1346 : add_pending_init (loc, field, value, origtype, implicit,
12208 : braced_init_obstack);
12209 1346 : return;
12210 : }
12211 9666712 : else if (TREE_CODE (constructor_type) == RECORD_TYPE
12212 1043617 : && (!constructor_incremental
12213 1041951 : || field != constructor_unfilled_fields))
12214 : {
12215 : /* We do this for records but not for unions. In a union,
12216 : no matter which field is specified, it can be initialized
12217 : right away since it starts at the beginning of the union. */
12218 2889 : if (constructor_incremental)
12219 : {
12220 1223 : if (!constructor_unfilled_fields)
12221 39 : set_nonincremental_init (braced_init_obstack);
12222 : else
12223 : {
12224 1184 : tree bitpos, unfillpos;
12225 :
12226 1184 : bitpos = bit_position (field);
12227 1184 : unfillpos = bit_position (constructor_unfilled_fields);
12228 :
12229 1184 : if (tree_int_cst_lt (bitpos, unfillpos))
12230 4 : set_nonincremental_init (braced_init_obstack);
12231 : }
12232 : }
12233 :
12234 2889 : add_pending_init (loc, field, value, origtype, implicit,
12235 : braced_init_obstack);
12236 2889 : return;
12237 : }
12238 9663823 : else if (TREE_CODE (constructor_type) == UNION_TYPE
12239 9663823 : && !vec_safe_is_empty (constructor_elements))
12240 : {
12241 62 : if (!implicit)
12242 : {
12243 12 : if (TREE_SIDE_EFFECTS (constructor_elements->last ().value))
12244 3 : warning_init (loc, OPT_Woverride_init_side_effects,
12245 : "initialized field with side-effects overwritten");
12246 9 : else if (warn_override_init)
12247 6 : warning_init (loc, OPT_Woverride_init,
12248 : "initialized field overwritten");
12249 : }
12250 :
12251 : /* We can have just one union field set. */
12252 62 : constructor_elements = NULL;
12253 : }
12254 :
12255 : /* Otherwise, output this element either to
12256 : constructor_elements or to the assembler file. */
12257 :
12258 9663823 : constructor_elt celt = {field, value};
12259 9663823 : vec_safe_push (constructor_elements, celt);
12260 :
12261 : /* Advance the variable that indicates sequential elements output. */
12262 9663823 : if (TREE_CODE (constructor_type) == ARRAY_TYPE)
12263 : {
12264 1722834 : tree inc = bitsize_one_node;
12265 1722834 : if (value && TREE_CODE (value) == RAW_DATA_CST)
12266 233 : inc = bitsize_int (RAW_DATA_LENGTH (value));
12267 1722834 : constructor_unfilled_index
12268 1722834 : = size_binop_loc (input_location, PLUS_EXPR,
12269 : constructor_unfilled_index, inc);
12270 : }
12271 7940989 : else if (TREE_CODE (constructor_type) == RECORD_TYPE)
12272 : {
12273 1040728 : constructor_unfilled_fields
12274 1040728 : = DECL_CHAIN (constructor_unfilled_fields);
12275 :
12276 : /* Skip any nameless bit fields. */
12277 1040728 : while (constructor_unfilled_fields != NULL_TREE
12278 1040829 : && DECL_UNNAMED_BIT_FIELD (constructor_unfilled_fields))
12279 101 : constructor_unfilled_fields
12280 101 : = DECL_CHAIN (constructor_unfilled_fields);
12281 : }
12282 6900261 : else if (TREE_CODE (constructor_type) == UNION_TYPE)
12283 31462 : constructor_unfilled_fields = NULL_TREE;
12284 :
12285 : /* Now output any pending elements which have become next. */
12286 9663823 : if (pending)
12287 9657632 : output_pending_init_elements (0, braced_init_obstack);
12288 : }
12289 :
12290 : /* For two FIELD_DECLs in the same chain, return -1 if field1
12291 : comes before field2, 1 if field1 comes after field2 and
12292 : 0 if field1 == field2. */
12293 :
12294 : static int
12295 7104 : init_field_decl_cmp (tree field1, tree field2)
12296 : {
12297 7104 : if (field1 == field2)
12298 : return 0;
12299 :
12300 3342 : tree bitpos1 = bit_position (field1);
12301 3342 : tree bitpos2 = bit_position (field2);
12302 3342 : if (tree_int_cst_equal (bitpos1, bitpos2))
12303 : {
12304 : /* If one of the fields has non-zero bitsize, then that
12305 : field must be the last one in a sequence of zero
12306 : sized fields, fields after it will have bigger
12307 : bit_position. */
12308 32 : if (TREE_TYPE (field1) != error_mark_node
12309 32 : && COMPLETE_TYPE_P (TREE_TYPE (field1))
12310 64 : && integer_nonzerop (TREE_TYPE (field1)))
12311 : return 1;
12312 32 : if (TREE_TYPE (field2) != error_mark_node
12313 32 : && COMPLETE_TYPE_P (TREE_TYPE (field2))
12314 57 : && integer_nonzerop (TREE_TYPE (field2)))
12315 : return -1;
12316 : /* Otherwise, fallback to DECL_CHAIN walk to find out
12317 : which field comes earlier. Walk chains of both
12318 : fields, so that if field1 and field2 are close to each
12319 : other in either order, it is found soon even for large
12320 : sequences of zero sized fields. */
12321 : tree f1 = field1, f2 = field2;
12322 32 : while (1)
12323 : {
12324 32 : f1 = DECL_CHAIN (f1);
12325 32 : f2 = DECL_CHAIN (f2);
12326 32 : if (f1 == NULL_TREE)
12327 : {
12328 7 : gcc_assert (f2);
12329 : return 1;
12330 : }
12331 25 : if (f2 == NULL_TREE)
12332 : return -1;
12333 9 : if (f1 == field2)
12334 : return -1;
12335 0 : if (f2 == field1)
12336 : return 1;
12337 0 : if (!tree_int_cst_equal (bit_position (f1), bitpos1))
12338 : return 1;
12339 0 : if (!tree_int_cst_equal (bit_position (f2), bitpos1))
12340 : return -1;
12341 : }
12342 : }
12343 3310 : else if (tree_int_cst_lt (bitpos1, bitpos2))
12344 : return -1;
12345 : else
12346 1948 : return 1;
12347 : }
12348 :
12349 : /* Output any pending elements which have become next.
12350 : As we output elements, constructor_unfilled_{fields,index}
12351 : advances, which may cause other elements to become next;
12352 : if so, they too are output.
12353 :
12354 : If ALL is 0, we return when there are
12355 : no more pending elements to output now.
12356 :
12357 : If ALL is 1, we output space as necessary so that
12358 : we can output all the pending elements. */
12359 : static void
12360 11734064 : output_pending_init_elements (int all, struct obstack * braced_init_obstack)
12361 : {
12362 11734064 : struct init_node *elt = constructor_pending_elts;
12363 11735231 : tree next;
12364 :
12365 11735231 : retry:
12366 :
12367 : /* Look through the whole pending tree.
12368 : If we find an element that should be output now,
12369 : output it. Otherwise, set NEXT to the element
12370 : that comes first among those still pending. */
12371 :
12372 11735231 : next = NULL_TREE;
12373 11747410 : while (elt)
12374 : {
12375 15058 : if (TREE_CODE (constructor_type) == ARRAY_TYPE)
12376 : {
12377 6827 : if (tree_int_cst_equal (elt->purpose,
12378 : constructor_unfilled_index))
12379 2834 : output_init_element (input_location, elt->value, elt->origtype,
12380 2834 : true, TREE_TYPE (constructor_type),
12381 : constructor_unfilled_index, false, false,
12382 : braced_init_obstack);
12383 3993 : else if (tree_int_cst_lt (constructor_unfilled_index,
12384 3993 : elt->purpose))
12385 : {
12386 : /* Advance to the next smaller node. */
12387 1138 : if (elt->left)
12388 : elt = elt->left;
12389 : else
12390 : {
12391 : /* We have reached the smallest node bigger than the
12392 : current unfilled index. Fill the space first. */
12393 350 : next = elt->purpose;
12394 350 : break;
12395 : }
12396 : }
12397 : else
12398 : {
12399 : /* Advance to the next bigger node. */
12400 2855 : if (elt->right)
12401 : elt = elt->right;
12402 : else
12403 : {
12404 : /* We have reached the biggest node in a subtree. Find
12405 : the parent of it, which is the next bigger node. */
12406 2855 : while (elt->parent && elt->parent->right == elt)
12407 : elt = elt->parent;
12408 1899 : elt = elt->parent;
12409 2682 : if (elt && tree_int_cst_lt (constructor_unfilled_index,
12410 783 : elt->purpose))
12411 : {
12412 22 : next = elt->purpose;
12413 22 : break;
12414 : }
12415 : }
12416 : }
12417 : }
12418 8231 : else if (RECORD_OR_UNION_TYPE_P (constructor_type))
12419 : {
12420 : /* If the current record is complete we are done. */
12421 8231 : if (constructor_unfilled_fields == NULL_TREE)
12422 : break;
12423 :
12424 6628 : int cmp = init_field_decl_cmp (constructor_unfilled_fields,
12425 : elt->purpose);
12426 6628 : if (cmp == 0)
12427 3357 : output_init_element (input_location, elt->value, elt->origtype,
12428 3357 : true, TREE_TYPE (elt->purpose),
12429 : elt->purpose, false, false,
12430 : braced_init_obstack);
12431 3271 : else if (cmp < 0)
12432 : {
12433 : /* Advance to the next smaller node. */
12434 1316 : if (elt->left)
12435 : elt = elt->left;
12436 : else
12437 : {
12438 : /* We have reached the smallest node bigger than the
12439 : current unfilled field. Fill the space first. */
12440 833 : next = elt->purpose;
12441 833 : break;
12442 : }
12443 : }
12444 : else
12445 : {
12446 : /* Advance to the next bigger node. */
12447 1955 : if (elt->right)
12448 : elt = elt->right;
12449 : else
12450 : {
12451 : /* We have reached the biggest node in a subtree. Find
12452 : the parent of it, which is the next bigger node. */
12453 1025 : while (elt->parent && elt->parent->right == elt)
12454 : elt = elt->parent;
12455 789 : elt = elt->parent;
12456 789 : if (elt
12457 789 : && init_field_decl_cmp (constructor_unfilled_fields,
12458 : elt->purpose) < 0)
12459 : {
12460 71 : next = elt->purpose;
12461 71 : break;
12462 : }
12463 : }
12464 : }
12465 : }
12466 : }
12467 :
12468 : /* Ordinarily return, but not if we want to output all
12469 : and there are elements left. */
12470 11735231 : if (!(all && next != NULL_TREE))
12471 11734064 : return;
12472 :
12473 : /* If it's not incremental, just skip over the gap, so that after
12474 : jumping to retry we will output the next successive element. */
12475 1167 : if (RECORD_OR_UNION_TYPE_P (constructor_type))
12476 834 : constructor_unfilled_fields = next;
12477 333 : else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
12478 333 : constructor_unfilled_index = next;
12479 :
12480 : /* ELT now points to the node in the pending tree with the next
12481 : initializer to output. */
12482 1167 : goto retry;
12483 : }
12484 :
12485 : /* Expression VALUE coincides with the start of type TYPE in a braced
12486 : initializer. Return true if we should treat VALUE as initializing
12487 : the first element of TYPE, false if we should treat it as initializing
12488 : TYPE as a whole.
12489 :
12490 : If the initializer is clearly invalid, the question becomes:
12491 : which choice gives the best error message? */
12492 :
12493 : static bool
12494 3492351 : initialize_elementwise_p (tree type, tree value)
12495 : {
12496 3492351 : if (type == error_mark_node || value == error_mark_node)
12497 : return false;
12498 :
12499 3492115 : gcc_checking_assert (TYPE_MAIN_VARIANT (type) == type);
12500 :
12501 3492115 : tree value_type = TREE_TYPE (value);
12502 3492115 : if (value_type == error_mark_node)
12503 : return false;
12504 :
12505 : /* GNU vectors can be initialized elementwise. However, treat any
12506 : kind of vector value as initializing the vector type as a whole,
12507 : regardless of whether the value is a GNU vector. Such initializers
12508 : are valid if and only if they would have been valid in a non-braced
12509 : initializer like:
12510 :
12511 : TYPE foo = VALUE;
12512 :
12513 : so recursing into the vector type would be at best confusing or at
12514 : worst wrong. For example, when -flax-vector-conversions is in effect,
12515 : it's possible to initialize a V8HI from a V4SI, even though the vectors
12516 : have different element types and different numbers of elements. */
12517 3492115 : if (gnu_vector_type_p (type))
12518 19604 : return !VECTOR_TYPE_P (value_type);
12519 :
12520 3472511 : if (AGGREGATE_TYPE_P (type))
12521 1743326 : return !comptypes (type, TYPE_MAIN_VARIANT (value_type));
12522 :
12523 : return false;
12524 : }
12525 :
12526 : /* Helper function for process_init_element. Split first element of
12527 : RAW_DATA_CST and save the rest to *RAW_DATA. */
12528 :
12529 : static inline tree
12530 9662075 : maybe_split_raw_data (tree value, tree *raw_data)
12531 : {
12532 9662075 : if (value == NULL_TREE || TREE_CODE (value) != RAW_DATA_CST)
12533 : return value;
12534 211 : *raw_data = value;
12535 211 : value = build_int_cst (integer_type_node,
12536 211 : RAW_DATA_UCHAR_ELT (*raw_data, 0));
12537 211 : ++RAW_DATA_POINTER (*raw_data);
12538 211 : --RAW_DATA_LENGTH (*raw_data);
12539 211 : return value;
12540 : }
12541 :
12542 : /* Return non-zero if c_parser_initval should attempt to optimize
12543 : large initializers into RAW_DATA_CST. In that case return how
12544 : many elements to optimize at most. */
12545 :
12546 : unsigned
12547 3007562 : c_maybe_optimize_large_byte_initializer (void)
12548 : {
12549 3007562 : if (!constructor_type
12550 3007492 : || TREE_CODE (constructor_type) != ARRAY_TYPE
12551 212068 : || constructor_stack->implicit)
12552 : return 0;
12553 209303 : tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
12554 209303 : if (TREE_CODE (elttype) != INTEGER_TYPE
12555 209303 : && TREE_CODE (elttype) != BITINT_TYPE)
12556 : return 0;
12557 186327 : if (TYPE_PRECISION (elttype) != CHAR_BIT
12558 27934 : || constructor_stack->replacement_value.value
12559 27934 : || (COMPLETE_TYPE_P (constructor_type)
12560 26289 : && !poly_int_tree_p (TYPE_SIZE (constructor_type)))
12561 214261 : || constructor_range_stack)
12562 : return 0;
12563 27934 : if (constructor_max_index == NULL_TREE)
12564 : return INT_MAX;
12565 26289 : if (tree_int_cst_le (constructor_max_index, constructor_index)
12566 26289 : || integer_all_onesp (constructor_max_index))
12567 : return 0;
12568 21520 : widest_int w = wi::to_widest (constructor_max_index);
12569 21520 : w -= wi::to_widest (constructor_index);
12570 21520 : w += 1;
12571 21520 : if (w < 64)
12572 : return 0;
12573 6893 : if (w > INT_MAX)
12574 : return INT_MAX;
12575 6893 : return w.to_uhwi ();
12576 3007562 : }
12577 :
12578 : /* Add one non-braced element to the current constructor level.
12579 : This adjusts the current position within the constructor's type.
12580 : This may also start or terminate implicit levels
12581 : to handle a partly-braced initializer.
12582 :
12583 : Once this has found the correct level for the new element,
12584 : it calls output_init_element.
12585 :
12586 : IMPLICIT is true if value comes from pop_init_level (1),
12587 : the new initializer has been merged with the existing one
12588 : and thus no warnings should be emitted about overriding an
12589 : existing initializer. */
12590 :
12591 : void
12592 9652372 : process_init_element (location_t loc, struct c_expr value, bool implicit,
12593 : struct obstack * braced_init_obstack)
12594 : {
12595 9652372 : tree orig_value = value.value;
12596 19304744 : int string_flag
12597 9652372 : = (orig_value != NULL_TREE && TREE_CODE (orig_value) == STRING_CST);
12598 9652372 : bool strict_string = value.original_code == STRING_CST;
12599 9652372 : bool was_designated = designator_depth != 0;
12600 9652372 : tree raw_data = NULL_TREE;
12601 :
12602 9652584 : retry:
12603 9652584 : designator_depth = 0;
12604 9652584 : designator_erroneous = 0;
12605 :
12606 9652584 : if (!implicit && value.value && !integer_zerop (value.value))
12607 7621618 : constructor_zeroinit = 0;
12608 :
12609 : /* Handle superfluous braces around string cst as in
12610 : char x[] = {"foo"}; */
12611 9652584 : if (constructor_type
12612 9652456 : && !was_designated
12613 9615373 : && TREE_CODE (constructor_type) == ARRAY_TYPE
12614 1708759 : && INTEGRAL_TYPE_P (TREE_TYPE (constructor_type))
12615 10391658 : && integer_zerop (constructor_unfilled_index))
12616 : {
12617 163246 : if (constructor_stack->replacement_value.value)
12618 : {
12619 8 : error_init (loc, "excess elements in %qT initializer", constructor_type);
12620 409 : return;
12621 : }
12622 163238 : else if (string_flag)
12623 : {
12624 138 : constructor_stack->replacement_value = value;
12625 138 : return;
12626 : }
12627 : }
12628 :
12629 9652438 : if (constructor_stack->replacement_value.value != NULL_TREE)
12630 : {
12631 0 : error_init (loc, "excess elements in struct initializer");
12632 0 : return;
12633 : }
12634 :
12635 : /* Ignore elements of a brace group if it is entirely superfluous
12636 : and has already been diagnosed, or if the type is erroneous. */
12637 9652438 : if (constructor_type == NULL_TREE || constructor_type == error_mark_node)
12638 : return;
12639 :
12640 : /* Ignore elements of an initializer for a variable-size type.
12641 : Those are diagnosed in the parser (empty initializer braces are OK). */
12642 9652241 : if (COMPLETE_TYPE_P (constructor_type)
12643 9652241 : && !poly_int_tree_p (TYPE_SIZE (constructor_type)))
12644 : return;
12645 :
12646 8946860 : if (!implicit && warn_designated_init && !was_designated
12647 8912095 : && TREE_CODE (constructor_type) == RECORD_TYPE
12648 10687985 : && lookup_attribute ("designated_init",
12649 1035802 : TYPE_ATTRIBUTES (constructor_type)))
12650 50 : warning_init (loc,
12651 : OPT_Wdesignated_init,
12652 : "positional initialization of field "
12653 : "in %<struct%> declared with %<designated_init%> attribute");
12654 :
12655 : /* If we've exhausted any levels that didn't have braces,
12656 : pop them now. */
12657 10354162 : while (constructor_stack->implicit)
12658 : {
12659 708550 : if (RECORD_OR_UNION_TYPE_P (constructor_type)
12660 703711 : && constructor_fields == NULL_TREE)
12661 701738 : process_init_element (loc,
12662 : pop_init_level (loc, 1, braced_init_obstack,
12663 : last_init_list_comma),
12664 : true, braced_init_obstack);
12665 6812 : else if ((TREE_CODE (constructor_type) == ARRAY_TYPE
12666 2617 : || gnu_vector_type_p (constructor_type))
12667 4839 : && constructor_max_index
12668 11624 : && tree_int_cst_lt (constructor_max_index,
12669 : constructor_index))
12670 241 : process_init_element (loc,
12671 : pop_init_level (loc, 1, braced_init_obstack,
12672 : last_init_list_comma),
12673 : true, braced_init_obstack);
12674 : else
12675 : break;
12676 : }
12677 :
12678 : /* In the case of [LO ... HI] = VALUE, only evaluate VALUE once. */
12679 9652183 : if (constructor_range_stack)
12680 : {
12681 : /* If value is a compound literal and we'll be just using its
12682 : content, don't put it into a SAVE_EXPR. */
12683 371 : if (TREE_CODE (value.value) != COMPOUND_LITERAL_EXPR
12684 3 : || !require_constant_value)
12685 : {
12686 368 : tree semantic_type = NULL_TREE;
12687 368 : if (TREE_CODE (value.value) == EXCESS_PRECISION_EXPR)
12688 : {
12689 0 : semantic_type = TREE_TYPE (value.value);
12690 0 : value.value = TREE_OPERAND (value.value, 0);
12691 : }
12692 368 : value.value = save_expr (value.value);
12693 368 : if (semantic_type)
12694 0 : value.value = build1 (EXCESS_PRECISION_EXPR, semantic_type,
12695 : value.value);
12696 : }
12697 : }
12698 :
12699 10366427 : while (1)
12700 : {
12701 10366427 : if (TREE_CODE (constructor_type) == RECORD_TYPE)
12702 : {
12703 1041980 : tree fieldtype;
12704 1041980 : enum tree_code fieldcode;
12705 :
12706 1041980 : if (constructor_fields == NULL_TREE)
12707 : {
12708 1280 : pedwarn_init (loc, 0, "excess elements in struct initializer");
12709 1280 : break;
12710 : }
12711 :
12712 1040700 : fieldtype = TREE_TYPE (constructor_fields);
12713 1040700 : if (fieldtype != error_mark_node)
12714 1040699 : fieldtype = TYPE_MAIN_VARIANT (fieldtype);
12715 1040700 : fieldcode = TREE_CODE (fieldtype);
12716 :
12717 : /* Error for non-static initialization of a flexible array member. */
12718 1040700 : if (fieldcode == ARRAY_TYPE
12719 156028 : && !require_constant_value
12720 1892 : && TYPE_SIZE (fieldtype) == NULL_TREE
12721 1040710 : && DECL_CHAIN (constructor_fields) == NULL_TREE)
12722 : {
12723 10 : error_init (loc, "non-static initialization of a flexible "
12724 : "array member");
12725 10 : break;
12726 : }
12727 :
12728 : /* Error for initialization of a flexible array member with
12729 : a string constant if the structure is in an array. E.g.:
12730 : struct S { int x; char y[]; };
12731 : struct S s[] = { { 1, "foo" } };
12732 : is invalid. */
12733 1040690 : if (string_flag
12734 1040690 : && fieldcode == ARRAY_TYPE
12735 3353 : && constructor_depth > 1
12736 489 : && TYPE_SIZE (fieldtype) == NULL_TREE
12737 1040737 : && DECL_CHAIN (constructor_fields) == NULL_TREE)
12738 : {
12739 47 : bool in_array_p = false;
12740 47 : for (struct constructor_stack *p = constructor_stack;
12741 73 : p && p->type; p = p->next)
12742 59 : if (TREE_CODE (p->type) == ARRAY_TYPE)
12743 : {
12744 : in_array_p = true;
12745 : break;
12746 : }
12747 47 : if (in_array_p)
12748 : {
12749 33 : error_init (loc, "initialization of flexible array "
12750 : "member in a nested context");
12751 33 : break;
12752 : }
12753 : }
12754 :
12755 : /* Accept a string constant to initialize a subarray. */
12756 1040657 : if (value.value != NULL_TREE
12757 1040614 : && fieldcode == ARRAY_TYPE
12758 155942 : && INTEGRAL_TYPE_P (TREE_TYPE (fieldtype))
12759 1195288 : && string_flag)
12760 : value.value = orig_value;
12761 : /* Otherwise, if we have come to a subaggregate,
12762 : and we don't have an element of its type, push into it. */
12763 1037641 : else if (value.value != NULL_TREE
12764 1037337 : && initialize_elementwise_p (fieldtype, value.value))
12765 : {
12766 304 : push_init_level (loc, 1, braced_init_obstack);
12767 304 : continue;
12768 : }
12769 :
12770 1040353 : value.value = maybe_split_raw_data (value.value, &raw_data);
12771 1040353 : if (value.value)
12772 : {
12773 1040310 : push_member_name (constructor_fields);
12774 1040310 : output_init_element (loc, value.value, value.original_type,
12775 : strict_string, fieldtype,
12776 : constructor_fields, true, implicit,
12777 : braced_init_obstack);
12778 1040310 : RESTORE_SPELLING_DEPTH (constructor_depth);
12779 : }
12780 : else
12781 : /* Do the bookkeeping for an element that was
12782 : directly output as a constructor. */
12783 : {
12784 : /* For a record, keep track of end position of last field. */
12785 43 : if (DECL_SIZE (constructor_fields))
12786 0 : constructor_bit_index
12787 0 : = size_binop_loc (input_location, PLUS_EXPR,
12788 : bit_position (constructor_fields),
12789 0 : DECL_SIZE (constructor_fields));
12790 :
12791 : /* If the current field was the first one not yet written out,
12792 : it isn't now, so update. */
12793 43 : if (constructor_unfilled_fields == constructor_fields)
12794 : {
12795 34 : constructor_unfilled_fields = DECL_CHAIN (constructor_fields);
12796 : /* Skip any nameless bit fields. */
12797 34 : while (constructor_unfilled_fields != 0
12798 34 : && (DECL_UNNAMED_BIT_FIELD
12799 : (constructor_unfilled_fields)))
12800 0 : constructor_unfilled_fields =
12801 0 : DECL_CHAIN (constructor_unfilled_fields);
12802 : }
12803 : }
12804 :
12805 1040353 : constructor_fields = DECL_CHAIN (constructor_fields);
12806 : /* Skip any nameless bit fields at the beginning. */
12807 1040353 : while (constructor_fields != NULL_TREE
12808 1040454 : && DECL_UNNAMED_BIT_FIELD (constructor_fields))
12809 101 : constructor_fields = DECL_CHAIN (constructor_fields);
12810 : }
12811 9324447 : else if (TREE_CODE (constructor_type) == UNION_TYPE)
12812 : {
12813 31525 : tree fieldtype;
12814 31525 : enum tree_code fieldcode;
12815 :
12816 31525 : if (constructor_fields == NULL_TREE)
12817 : {
12818 3 : pedwarn_init (loc, 0,
12819 : "excess elements in union initializer");
12820 3 : break;
12821 : }
12822 :
12823 31522 : fieldtype = TREE_TYPE (constructor_fields);
12824 31522 : if (fieldtype != error_mark_node)
12825 31522 : fieldtype = TYPE_MAIN_VARIANT (fieldtype);
12826 31522 : fieldcode = TREE_CODE (fieldtype);
12827 :
12828 : /* Warn that traditional C rejects initialization of unions.
12829 : We skip the warning if the value is zero. This is done
12830 : under the assumption that the zero initializer in user
12831 : code appears conditioned on e.g. __STDC__ to avoid
12832 : "missing initializer" warnings and relies on default
12833 : initialization to zero in the traditional C case.
12834 : We also skip the warning if the initializer is designated,
12835 : again on the assumption that this must be conditional on
12836 : __STDC__ anyway (and we've already complained about the
12837 : member-designator already). */
12838 33976 : if (!in_system_header_at (input_location) && !constructor_designated
12839 33059 : && !(value.value && (integer_zerop (value.value)
12840 1438 : || real_zerop (value.value))))
12841 1431 : warning (OPT_Wtraditional, "traditional C rejects initialization "
12842 : "of unions");
12843 :
12844 : /* Error for non-static initialization of a flexible array member. */
12845 31522 : if (fieldcode == ARRAY_TYPE
12846 766 : && !require_constant_value
12847 31579 : && TYPE_SIZE (fieldtype) == NULL_TREE)
12848 : {
12849 3 : error_init (loc, "non-static initialization of a flexible "
12850 : "array member");
12851 3 : break;
12852 : }
12853 :
12854 : /* Error for initialization of a flexible array member with
12855 : a string constant if the structure is in an array. E.g.:
12856 : union U { int x; char y[]; };
12857 : union U s[] = { { 1, "foo" } };
12858 : is invalid. */
12859 31519 : if (string_flag
12860 31519 : && fieldcode == ARRAY_TYPE
12861 7 : && constructor_depth > 1
12862 31523 : && TYPE_SIZE (fieldtype) == NULL_TREE)
12863 : {
12864 3 : bool in_array_p = false;
12865 3 : for (struct constructor_stack *p = constructor_stack;
12866 3 : p && p->type; p = p->next)
12867 3 : if (TREE_CODE (p->type) == ARRAY_TYPE)
12868 : {
12869 : in_array_p = true;
12870 : break;
12871 : }
12872 3 : if (in_array_p)
12873 : {
12874 3 : error_init (loc, "initialization of flexible array "
12875 : "member in a nested context");
12876 3 : break;
12877 : }
12878 : }
12879 :
12880 : /* Accept a string constant to initialize a subarray. */
12881 31516 : if (value.value != NULL_TREE
12882 31516 : && fieldcode == ARRAY_TYPE
12883 760 : && INTEGRAL_TYPE_P (TREE_TYPE (fieldtype))
12884 32271 : && string_flag)
12885 : value.value = orig_value;
12886 : /* Otherwise, if we have come to a subaggregate,
12887 : and we don't have an element of its type, push into it. */
12888 31562 : else if (value.value != NULL_TREE
12889 31512 : && initialize_elementwise_p (fieldtype, value.value))
12890 : {
12891 50 : push_init_level (loc, 1, braced_init_obstack);
12892 50 : continue;
12893 : }
12894 :
12895 31466 : value.value = maybe_split_raw_data (value.value, &raw_data);
12896 31466 : if (value.value)
12897 : {
12898 31466 : push_member_name (constructor_fields);
12899 31466 : output_init_element (loc, value.value, value.original_type,
12900 : strict_string, fieldtype,
12901 : constructor_fields, true, implicit,
12902 : braced_init_obstack);
12903 31466 : RESTORE_SPELLING_DEPTH (constructor_depth);
12904 : }
12905 : else
12906 : /* Do the bookkeeping for an element that was
12907 : directly output as a constructor. */
12908 : {
12909 0 : constructor_bit_index = DECL_SIZE (constructor_fields);
12910 0 : constructor_unfilled_fields = DECL_CHAIN (constructor_fields);
12911 : }
12912 :
12913 31466 : constructor_fields = NULL_TREE;
12914 : }
12915 9292922 : else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
12916 : {
12917 2424041 : tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
12918 2424041 : enum tree_code eltcode = TREE_CODE (elttype);
12919 :
12920 : /* Accept a string constant to initialize a subarray. */
12921 2424041 : if (value.value != NULL_TREE
12922 2424041 : && eltcode == ARRAY_TYPE
12923 7031 : && INTEGRAL_TYPE_P (TREE_TYPE (elttype))
12924 2429589 : && string_flag)
12925 : value.value = orig_value;
12926 : /* Otherwise, if we have come to a subaggregate,
12927 : and we don't have an element of its type, push into it. */
12928 3125871 : else if (value.value != NULL_TREE
12929 2423545 : && initialize_elementwise_p (elttype, value.value))
12930 : {
12931 702326 : push_init_level (loc, 1, braced_init_obstack);
12932 702326 : continue;
12933 : }
12934 :
12935 1721715 : if (constructor_max_index != NULL_TREE
12936 677894 : && (tree_int_cst_lt (constructor_max_index, constructor_index)
12937 677779 : || integer_all_onesp (constructor_max_index))
12938 : /* For VLA we got an error already. */
12939 1721830 : && !C_TYPE_VARIABLE_SIZE (constructor_type))
12940 : {
12941 113 : pedwarn_init (loc, 0,
12942 : "excess elements in array initializer");
12943 113 : break;
12944 : }
12945 :
12946 1721602 : if (value.value
12947 1721602 : && TREE_CODE (value.value) == RAW_DATA_CST
12948 196 : && RAW_DATA_LENGTH (value.value) > 1
12949 196 : && (TREE_CODE (elttype) == INTEGER_TYPE
12950 196 : || TREE_CODE (elttype) == BITINT_TYPE)
12951 196 : && TYPE_PRECISION (elttype) == CHAR_BIT
12952 1721798 : && (constructor_max_index == NULL_TREE
12953 58 : || tree_int_cst_lt (constructor_index,
12954 : constructor_max_index)))
12955 : {
12956 196 : unsigned int len = RAW_DATA_LENGTH (value.value);
12957 196 : if (constructor_max_index)
12958 : {
12959 58 : widest_int w = wi::to_widest (constructor_max_index);
12960 58 : w -= wi::to_widest (constructor_index);
12961 58 : w += 1;
12962 58 : if (w < len)
12963 3 : len = w.to_uhwi ();
12964 58 : }
12965 196 : if (len < (unsigned) RAW_DATA_LENGTH (value.value))
12966 : {
12967 3 : raw_data = copy_node (value.value);
12968 3 : RAW_DATA_LENGTH (raw_data) -= len;
12969 3 : RAW_DATA_POINTER (raw_data) += len;
12970 3 : RAW_DATA_LENGTH (value.value) = len;
12971 : }
12972 196 : TREE_TYPE (value.value) = elttype;
12973 196 : push_array_bounds (tree_to_uhwi (constructor_index));
12974 196 : output_init_element (loc, value.value, value.original_type,
12975 : false, elttype, constructor_index, true,
12976 : implicit, braced_init_obstack);
12977 196 : RESTORE_SPELLING_DEPTH (constructor_depth);
12978 196 : constructor_index
12979 196 : = size_binop_loc (input_location, PLUS_EXPR,
12980 196 : constructor_index, bitsize_int (len));
12981 : }
12982 : else
12983 : {
12984 1721406 : value.value = maybe_split_raw_data (value.value, &raw_data);
12985 : /* Now output the actual element. */
12986 1721406 : if (value.value)
12987 : {
12988 1721406 : push_array_bounds (tree_to_uhwi (constructor_index));
12989 1721406 : output_init_element (loc, value.value, value.original_type,
12990 : strict_string, elttype,
12991 : constructor_index, true, implicit,
12992 : braced_init_obstack);
12993 1721406 : RESTORE_SPELLING_DEPTH (constructor_depth);
12994 : }
12995 :
12996 1721406 : constructor_index
12997 1721406 : = size_binop_loc (input_location, PLUS_EXPR,
12998 : constructor_index, bitsize_one_node);
12999 :
13000 1721406 : if (!value.value)
13001 : /* If we are doing the bookkeeping for an element that was
13002 : directly output as a constructor, we must update
13003 : constructor_unfilled_index. */
13004 0 : constructor_unfilled_index = constructor_index;
13005 : }
13006 : }
13007 6868881 : else if (gnu_vector_type_p (constructor_type))
13008 : {
13009 6868389 : tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
13010 :
13011 : /* Do a basic check of initializer size. Note that vectors
13012 : may not always have a fixed size derived from their type. */
13013 6868389 : if (maybe_lt (tree_to_poly_uint64 (constructor_max_index),
13014 6868389 : tree_to_poly_uint64 (constructor_index)))
13015 : {
13016 : /* Diagose VLA out-of-bounds as errors. */
13017 2 : if (tree_to_poly_uint64 (constructor_max_index).is_constant())
13018 2 : pedwarn_init (loc, 0,
13019 : "excess elements in vector initializer");
13020 : else
13021 : error_init (loc, "excess elements in vector initializer");
13022 :
13023 : break;
13024 : }
13025 :
13026 6868387 : value.value = maybe_split_raw_data (value.value, &raw_data);
13027 : /* Now output the actual element. */
13028 6868387 : if (value.value)
13029 : {
13030 6868387 : if (TREE_CODE (value.value) == VECTOR_CST)
13031 0 : elttype = TYPE_MAIN_VARIANT (constructor_type);
13032 6868387 : output_init_element (loc, value.value, value.original_type,
13033 : strict_string, elttype,
13034 : constructor_index, true, implicit,
13035 : braced_init_obstack);
13036 : }
13037 :
13038 6868387 : constructor_index
13039 6868387 : = size_binop_loc (input_location,
13040 : PLUS_EXPR, constructor_index, bitsize_one_node);
13041 :
13042 6868387 : if (!value.value)
13043 : /* If we are doing the bookkeeping for an element that was
13044 : directly output as a constructor, we must update
13045 : constructor_unfilled_index. */
13046 0 : constructor_unfilled_index = constructor_index;
13047 : }
13048 :
13049 : /* Handle the sole element allowed in a braced initializer
13050 : for a scalar variable. */
13051 492 : else if (constructor_type != error_mark_node
13052 492 : && constructor_fields == NULL_TREE)
13053 : {
13054 29 : pedwarn_init (loc, 0,
13055 : "excess elements in scalar initializer");
13056 29 : break;
13057 : }
13058 : else
13059 : {
13060 463 : value.value = maybe_split_raw_data (value.value, &raw_data);
13061 463 : if (value.value)
13062 463 : output_init_element (loc, value.value, value.original_type,
13063 : strict_string, constructor_type,
13064 : NULL_TREE, true, implicit,
13065 : braced_init_obstack);
13066 463 : constructor_fields = NULL_TREE;
13067 : }
13068 :
13069 : /* Handle range initializers either at this level or anywhere higher
13070 : in the designator stack. */
13071 9662271 : if (constructor_range_stack)
13072 : {
13073 11564 : struct constructor_range_stack *p, *range_stack;
13074 11564 : int finish = 0;
13075 :
13076 11564 : range_stack = constructor_range_stack;
13077 11564 : constructor_range_stack = 0;
13078 11564 : while (constructor_stack != range_stack->stack)
13079 : {
13080 0 : gcc_assert (constructor_stack->implicit);
13081 0 : process_init_element (loc,
13082 : pop_init_level (loc, 1,
13083 : braced_init_obstack,
13084 : last_init_list_comma),
13085 : true, braced_init_obstack);
13086 : }
13087 325 : for (p = range_stack;
13088 11889 : !p->range_end || tree_int_cst_equal (p->index, p->range_end);
13089 325 : p = p->prev)
13090 : {
13091 325 : gcc_assert (constructor_stack->implicit);
13092 325 : process_init_element (loc,
13093 : pop_init_level (loc, 1,
13094 : braced_init_obstack,
13095 : last_init_list_comma),
13096 : true, braced_init_obstack);
13097 : }
13098 :
13099 11564 : p->index = size_binop_loc (input_location,
13100 : PLUS_EXPR, p->index, bitsize_one_node);
13101 11564 : if (tree_int_cst_equal (p->index, p->range_end) && !p->prev)
13102 11564 : finish = 1;
13103 :
13104 11889 : while (1)
13105 : {
13106 11889 : constructor_index = p->index;
13107 11889 : constructor_fields = p->fields;
13108 11889 : if (finish && p->range_end && p->index == p->range_start)
13109 : {
13110 8 : finish = 0;
13111 8 : p->prev = 0;
13112 : }
13113 11889 : p = p->next;
13114 11889 : if (!p)
13115 : break;
13116 325 : finish_implicit_inits (loc, braced_init_obstack);
13117 325 : push_init_level (loc, 2, braced_init_obstack);
13118 325 : p->stack = constructor_stack;
13119 325 : if (p->range_end && tree_int_cst_equal (p->index, p->range_end))
13120 33 : p->index = p->range_start;
13121 : }
13122 :
13123 11564 : if (!finish)
13124 11193 : constructor_range_stack = range_stack;
13125 11564 : continue;
13126 11564 : }
13127 :
13128 : break;
13129 : }
13130 :
13131 9652183 : constructor_range_stack = 0;
13132 :
13133 9652183 : if (raw_data && RAW_DATA_LENGTH (raw_data))
13134 : {
13135 212 : gcc_assert (!string_flag && !was_designated);
13136 212 : value.value = raw_data;
13137 212 : raw_data = NULL_TREE;
13138 212 : goto retry;
13139 : }
13140 : }
13141 :
13142 : /* Build a complete asm-statement, whose components are a CV_QUALIFIER
13143 : (guaranteed to be 'volatile' or null) and ARGS (represented using
13144 : an ASM_EXPR node). */
13145 : tree
13146 195344 : build_asm_stmt (bool is_volatile, tree args)
13147 : {
13148 195344 : if (is_volatile)
13149 155484 : ASM_VOLATILE_P (args) = 1;
13150 195344 : return add_stmt (args);
13151 : }
13152 :
13153 : /* Build an asm-expr, whose components are a STRING, some OUTPUTS,
13154 : some INPUTS, and some CLOBBERS. The latter three may be NULL.
13155 : SIMPLE indicates whether there was anything at all after the
13156 : string in the asm expression -- asm("blah") and asm("blah" : )
13157 : are subtly different. We use a ASM_EXPR node to represent this.
13158 : LOC is the location of the asm, and IS_INLINE says whether this
13159 : is asm inline. */
13160 : tree
13161 195396 : build_asm_expr (location_t loc, tree string, tree outputs, tree inputs,
13162 : tree clobbers, tree labels, bool simple, bool is_inline)
13163 : {
13164 195396 : tree tail;
13165 195396 : tree args;
13166 195396 : int i;
13167 195396 : const char *constraint;
13168 195396 : const char **oconstraints;
13169 195396 : bool allows_mem, allows_reg, is_inout;
13170 195396 : int ninputs, noutputs;
13171 :
13172 195396 : ninputs = list_length (inputs);
13173 195396 : noutputs = list_length (outputs);
13174 195396 : oconstraints = (const char **) alloca (noutputs * sizeof (const char *));
13175 :
13176 195396 : string = resolve_asm_operand_names (string, outputs, inputs, labels);
13177 :
13178 : /* Remove output conversions that change the type but not the mode. */
13179 742254 : for (i = 0, tail = outputs; tail; ++i, tail = TREE_CHAIN (tail))
13180 : {
13181 351462 : tree output = TREE_VALUE (tail);
13182 :
13183 351462 : output = c_fully_fold (output, false, NULL, true);
13184 :
13185 : /* ??? Really, this should not be here. Users should be using a
13186 : proper lvalue, dammit. But there's a long history of using casts
13187 : in the output operands. In cases like longlong.h, this becomes a
13188 : primitive form of typechecking -- if the cast can be removed, then
13189 : the output operand had a type of the proper width; otherwise we'll
13190 : get an error. Gross, but ... */
13191 351462 : STRIP_NOPS (output);
13192 :
13193 351462 : if (!lvalue_or_else (loc, output, lv_asm))
13194 4 : output = error_mark_node;
13195 :
13196 351462 : if (output != error_mark_node
13197 351462 : && (TREE_READONLY (output)
13198 351455 : || TYPE_READONLY (TREE_TYPE (output))
13199 351455 : || (RECORD_OR_UNION_TYPE_P (TREE_TYPE (output))
13200 112 : && C_TYPE_FIELDS_READONLY (TREE_TYPE (output)))))
13201 2 : readonly_error (loc, output, lv_asm);
13202 :
13203 351462 : constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (tail)));
13204 351462 : oconstraints[i] = constraint;
13205 :
13206 351462 : if (parse_output_constraint (&constraint, i, ninputs, noutputs,
13207 : &allows_mem, &allows_reg, &is_inout,
13208 : nullptr))
13209 : {
13210 : /* If the operand is going to end up in memory,
13211 : mark it addressable. */
13212 351454 : if (!allows_reg && !c_mark_addressable (output))
13213 3 : output = error_mark_node;
13214 1422 : if (!(!allows_reg && allows_mem)
13215 350032 : && output != error_mark_node
13216 701484 : && VOID_TYPE_P (TREE_TYPE (output)))
13217 : {
13218 4 : error_at (loc, "invalid use of void expression");
13219 4 : output = error_mark_node;
13220 : }
13221 351454 : if (allows_reg && current_function_decl == NULL_TREE)
13222 : {
13223 1 : error_at (loc, "constraint allows registers outside of "
13224 : "a function");
13225 1 : output = error_mark_node;
13226 : }
13227 : }
13228 : else
13229 8 : output = error_mark_node;
13230 :
13231 351462 : if (current_function_decl == NULL_TREE && output != error_mark_node)
13232 : {
13233 7 : if (TREE_SIDE_EFFECTS (output))
13234 : {
13235 0 : error_at (loc, "side-effects in output operand outside "
13236 : "of a function");
13237 0 : output = error_mark_node;
13238 : }
13239 : else
13240 : {
13241 7 : tree addr = build_unary_op (loc, ADDR_EXPR, output, false);
13242 7 : if (addr == error_mark_node)
13243 : output = error_mark_node;
13244 7 : else if (!initializer_constant_valid_p (addr, TREE_TYPE (addr)))
13245 : {
13246 1 : error_at (loc, "output operand outside of a function is not "
13247 : "constant");
13248 1 : output = error_mark_node;
13249 : }
13250 : }
13251 : }
13252 351455 : else if (output != error_mark_node && strstr (constraint, "-"))
13253 : {
13254 1 : error_at (loc, "%<-%> modifier used inside of a function");
13255 1 : output = error_mark_node;
13256 : }
13257 :
13258 351462 : TREE_VALUE (tail) = output;
13259 : }
13260 :
13261 562080 : for (i = 0, tail = inputs; tail; ++i, tail = TREE_CHAIN (tail))
13262 : {
13263 366684 : tree input;
13264 :
13265 366684 : constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (tail)));
13266 366684 : input = TREE_VALUE (tail);
13267 :
13268 366684 : if (parse_input_constraint (&constraint, i, ninputs, noutputs, 0,
13269 : oconstraints, &allows_mem, &allows_reg,
13270 : nullptr))
13271 : {
13272 : /* If the operand is going to end up in memory,
13273 : mark it addressable. */
13274 366676 : if (!allows_reg && allows_mem)
13275 : {
13276 1359 : input = c_fully_fold (input, false, NULL, true);
13277 :
13278 : /* Strip the nops as we allow this case. FIXME, this really
13279 : should be rejected or made deprecated. */
13280 1359 : STRIP_NOPS (input);
13281 1359 : if (!c_mark_addressable (input))
13282 2 : input = error_mark_node;
13283 : }
13284 : else
13285 : {
13286 365317 : input = c_fully_fold (convert_lvalue_to_rvalue (loc, input,
13287 : true, false),
13288 : false, NULL);
13289 :
13290 365317 : if (input != error_mark_node && VOID_TYPE_P (TREE_TYPE (input)))
13291 : {
13292 4 : error_at (loc, "invalid use of void expression");
13293 4 : input = error_mark_node;
13294 : }
13295 : }
13296 366676 : if (allows_reg && current_function_decl == NULL_TREE)
13297 : {
13298 1 : error_at (loc, "constraint allows registers outside of "
13299 : "a function");
13300 1 : input = error_mark_node;
13301 : }
13302 366676 : if (constraint[0] == ':' && input != error_mark_node)
13303 : {
13304 35 : tree t = input;
13305 35 : STRIP_NOPS (t);
13306 35 : if (TREE_CODE (t) != ADDR_EXPR
13307 35 : || !(TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL
13308 23 : || (VAR_P (TREE_OPERAND (t, 0))
13309 21 : && is_global_var (TREE_OPERAND (t, 0)))))
13310 : {
13311 5 : error_at (loc, "%<:%> constraint operand is not address "
13312 : "of a function or non-automatic variable");
13313 5 : input = error_mark_node;
13314 : }
13315 30 : else if (TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL)
13316 10 : suppress_warning (TREE_OPERAND (t, 0), OPT_Wunused);
13317 : }
13318 : }
13319 : else
13320 8 : input = error_mark_node;
13321 :
13322 366684 : if (current_function_decl == NULL_TREE && input != error_mark_node)
13323 : {
13324 58 : if (TREE_SIDE_EFFECTS (input))
13325 : {
13326 2 : error_at (loc, "side-effects in input operand outside "
13327 : "of a function");
13328 2 : input = error_mark_node;
13329 : }
13330 : else
13331 : {
13332 56 : tree tem = input;
13333 56 : if (allows_mem && lvalue_p (input))
13334 7 : tem = build_unary_op (loc, ADDR_EXPR, input, false);
13335 56 : if (!initializer_constant_valid_p (tem, TREE_TYPE (tem)))
13336 : {
13337 2 : error_at (loc, "input operand outside of a function is not "
13338 : "constant");
13339 2 : input = error_mark_node;
13340 : }
13341 : }
13342 : }
13343 366626 : else if (input != error_mark_node && strstr (constraint, "-"))
13344 : {
13345 3 : error_at (loc, "%<-%> modifier used inside of a function");
13346 3 : input = error_mark_node;
13347 : }
13348 :
13349 366684 : TREE_VALUE (tail) = input;
13350 : }
13351 :
13352 195396 : args = build_stmt (loc, ASM_EXPR, string, outputs, inputs, clobbers, labels);
13353 :
13354 : /* asm statements without outputs, including simple ones, are treated
13355 : as volatile. */
13356 195396 : ASM_BASIC_P (args) = simple;
13357 195396 : ASM_VOLATILE_P (args) = (noutputs == 0);
13358 195396 : ASM_INLINE_P (args) = is_inline;
13359 :
13360 195396 : return args;
13361 : }
13362 :
13363 : /* Generate a goto statement to LABEL. LOC is the location of the
13364 : GOTO. */
13365 :
13366 : tree
13367 83483 : c_finish_goto_label (location_t loc, tree label)
13368 : {
13369 83483 : tree decl = lookup_label_for_goto (loc, label);
13370 83483 : if (!decl)
13371 : return NULL_TREE;
13372 83483 : TREE_USED (decl) = 1;
13373 83483 : mark_decl_used (decl, false);
13374 83483 : {
13375 83483 : add_stmt (build_predict_expr (PRED_GOTO, NOT_TAKEN));
13376 83483 : tree t = build1 (GOTO_EXPR, void_type_node, decl);
13377 83483 : SET_EXPR_LOCATION (t, loc);
13378 83483 : return add_stmt (t);
13379 : }
13380 : }
13381 :
13382 : /* Generate a computed goto statement to EXPR. LOC is the location of
13383 : the GOTO. */
13384 :
13385 : tree
13386 959 : c_finish_goto_ptr (location_t loc, c_expr val)
13387 : {
13388 959 : tree expr = val.value;
13389 959 : tree t;
13390 959 : pedwarn (loc, OPT_Wpedantic, "ISO C forbids %<goto *expr;%>");
13391 959 : if (expr != error_mark_node
13392 958 : && !POINTER_TYPE_P (TREE_TYPE (expr))
13393 964 : && !null_pointer_constant_p (expr))
13394 : {
13395 2 : error_at (val.get_location (),
13396 : "computed goto must be pointer type");
13397 2 : expr = build_zero_cst (ptr_type_node);
13398 : }
13399 959 : expr = c_fully_fold (expr, false, NULL);
13400 959 : expr = convert (ptr_type_node, expr);
13401 959 : t = build1 (GOTO_EXPR, void_type_node, expr);
13402 959 : SET_EXPR_LOCATION (t, loc);
13403 959 : return add_stmt (t);
13404 : }
13405 :
13406 : /* Generate a C `return' statement. RETVAL is the expression for what
13407 : to return, or a null pointer for `return;' with no value. LOC is
13408 : the location of the return statement, or the location of the expression,
13409 : if the statement has any. If ORIGTYPE is not NULL_TREE, it
13410 : is the original type of RETVAL. MUSTTAIL_P indicates a musttail
13411 : attribute. */
13412 :
13413 : tree
13414 35698213 : c_finish_return (location_t loc, tree retval, tree origtype, bool musttail_p)
13415 : {
13416 35698213 : tree valtype = TREE_TYPE (TREE_TYPE (current_function_decl)), ret_stmt;
13417 35698213 : bool no_warning = false;
13418 35698213 : bool npc = false;
13419 :
13420 : /* Use the expansion point to handle cases such as returning NULL
13421 : in a function returning void. */
13422 35698213 : location_t xloc = expansion_point_location_if_in_system_header (loc);
13423 :
13424 35698213 : if (TREE_THIS_VOLATILE (current_function_decl))
13425 23 : warning_at (xloc, 0,
13426 : "function declared %<noreturn%> has a %<return%> statement");
13427 :
13428 35698213 : set_musttail_on_return (retval, xloc, musttail_p);
13429 :
13430 35698213 : if (retval)
13431 : {
13432 35676644 : tree semantic_type = NULL_TREE;
13433 35676644 : npc = null_pointer_constant_p (retval);
13434 35676644 : if (TREE_CODE (retval) == EXCESS_PRECISION_EXPR)
13435 : {
13436 92 : semantic_type = TREE_TYPE (retval);
13437 92 : retval = TREE_OPERAND (retval, 0);
13438 : }
13439 35676644 : retval = c_fully_fold (retval, false, NULL);
13440 35676644 : if (semantic_type
13441 35676644 : && valtype != NULL_TREE
13442 92 : && TREE_CODE (valtype) != VOID_TYPE)
13443 92 : retval = build1 (EXCESS_PRECISION_EXPR, semantic_type, retval);
13444 : }
13445 :
13446 35676644 : if (!retval)
13447 : {
13448 21569 : current_function_returns_null = 1;
13449 21569 : if ((warn_return_type >= 0 || flag_isoc99)
13450 21444 : && valtype != NULL_TREE && TREE_CODE (valtype) != VOID_TYPE)
13451 : {
13452 46 : no_warning = true;
13453 47 : if (emit_diagnostic (flag_isoc99
13454 : ? diagnostics::kind::permerror
13455 : : diagnostics::kind::warning,
13456 46 : loc, OPT_Wreturn_mismatch,
13457 : "%<return%> with no value,"
13458 : " in function returning non-void"))
13459 27 : inform (DECL_SOURCE_LOCATION (current_function_decl),
13460 : "declared here");
13461 : }
13462 : }
13463 35676644 : else if (valtype == NULL_TREE || VOID_TYPE_P (valtype))
13464 : {
13465 322 : current_function_returns_null = 1;
13466 322 : bool warned_here;
13467 322 : if (TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
13468 64 : warned_here = permerror_opt
13469 64 : (xloc, OPT_Wreturn_mismatch,
13470 : "%<return%> with a value, in function returning void");
13471 : else
13472 258 : warned_here = pedwarn
13473 258 : (xloc, OPT_Wpedantic, "ISO C forbids "
13474 : "%<return%> with expression, in function returning void");
13475 322 : if (warned_here)
13476 43 : inform (DECL_SOURCE_LOCATION (current_function_decl),
13477 : "declared here");
13478 : }
13479 : else
13480 : {
13481 35676322 : tree t = convert_for_assignment (loc, UNKNOWN_LOCATION, valtype,
13482 : retval, origtype, ic_return,
13483 : npc, NULL_TREE, NULL_TREE, 0);
13484 35676322 : tree res = DECL_RESULT (current_function_decl);
13485 35676322 : tree inner;
13486 35676322 : bool save;
13487 :
13488 35676322 : current_function_returns_value = 1;
13489 35676322 : if (t == error_mark_node)
13490 : {
13491 : /* Suppress -Wreturn-type for this function. */
13492 299 : if (warn_return_type)
13493 298 : suppress_warning (current_function_decl, OPT_Wreturn_type);
13494 : return NULL_TREE;
13495 : }
13496 :
13497 35676023 : save = in_late_binary_op;
13498 71343335 : if (C_BOOLEAN_TYPE_P (TREE_TYPE (res))
13499 35666507 : || TREE_CODE (TREE_TYPE (res)) == COMPLEX_TYPE
13500 71341227 : || (SCALAR_FLOAT_TYPE_P (TREE_TYPE (t))
13501 334560 : && (TREE_CODE (TREE_TYPE (res)) == INTEGER_TYPE
13502 334560 : || TREE_CODE (TREE_TYPE (res)) == ENUMERAL_TYPE)
13503 0 : && sanitize_flags_p (SANITIZE_FLOAT_CAST)))
13504 10819 : in_late_binary_op = true;
13505 35676023 : inner = t = convert (TREE_TYPE (res), t);
13506 35676023 : in_late_binary_op = save;
13507 :
13508 : /* Strip any conversions, additions, and subtractions, and see if
13509 : we are returning the address of a local variable. Warn if so. */
13510 38971413 : while (1)
13511 : {
13512 38971413 : switch (TREE_CODE (inner))
13513 : {
13514 3293851 : CASE_CONVERT:
13515 3293851 : case NON_LVALUE_EXPR:
13516 3293851 : case PLUS_EXPR:
13517 3293851 : case POINTER_PLUS_EXPR:
13518 3293851 : inner = TREE_OPERAND (inner, 0);
13519 3293851 : continue;
13520 :
13521 1544 : case MINUS_EXPR:
13522 : /* If the second operand of the MINUS_EXPR has a pointer
13523 : type (or is converted from it), this may be valid, so
13524 : don't give a warning. */
13525 1544 : {
13526 1544 : tree op1 = TREE_OPERAND (inner, 1);
13527 :
13528 3337 : while (!POINTER_TYPE_P (TREE_TYPE (op1))
13529 3591 : && (CONVERT_EXPR_P (op1)
13530 1539 : || TREE_CODE (op1) == NON_LVALUE_EXPR))
13531 254 : op1 = TREE_OPERAND (op1, 0);
13532 :
13533 1544 : if (POINTER_TYPE_P (TREE_TYPE (op1)))
13534 : break;
13535 :
13536 1539 : inner = TREE_OPERAND (inner, 0);
13537 1539 : continue;
13538 1539 : }
13539 :
13540 2964 : case ADDR_EXPR:
13541 2964 : inner = TREE_OPERAND (inner, 0);
13542 :
13543 2964 : while (REFERENCE_CLASS_P (inner)
13544 3867 : && !INDIRECT_REF_P (inner))
13545 903 : inner = TREE_OPERAND (inner, 0);
13546 :
13547 2964 : if (DECL_P (inner)
13548 1640 : && !DECL_EXTERNAL (inner)
13549 992 : && DECL_CONTEXT (inner) == current_function_decl
13550 3186 : && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (current_function_decl))))
13551 : {
13552 182 : if (TREE_CODE (inner) == LABEL_DECL)
13553 4 : warning_at (loc, OPT_Wreturn_local_addr,
13554 : "function returns address of label");
13555 178 : else if (TREE_CODE (inner) == FUNCTION_DECL
13556 178 : && (C_FUNC_NONLOCAL_CONTEXT (inner)
13557 9 : || !DECL_INITIAL (inner)))
13558 14 : warning_at (loc, OPT_Wreturn_local_addr,
13559 : "function returns address of nested function "
13560 : "referencing local context");
13561 164 : else if (TREE_CODE (inner) != FUNCTION_DECL
13562 156 : && !TREE_STATIC (inner))
13563 : {
13564 9 : warning_at (loc, OPT_Wreturn_local_addr,
13565 : "function returns address of local variable");
13566 9 : tree zero = build_zero_cst (TREE_TYPE (res));
13567 9 : t = build2 (COMPOUND_EXPR, TREE_TYPE (res), t, zero);
13568 : }
13569 : }
13570 : break;
13571 :
13572 : default:
13573 : break;
13574 3293851 : }
13575 :
13576 35676023 : break;
13577 : }
13578 :
13579 35676023 : retval = build2 (MODIFY_EXPR, TREE_TYPE (res), res, t);
13580 35676023 : SET_EXPR_LOCATION (retval, loc);
13581 :
13582 35676023 : if (warn_sequence_point)
13583 3037118 : verify_sequence_points (retval);
13584 : }
13585 :
13586 35697914 : ret_stmt = build_stmt (loc, RETURN_EXPR, retval);
13587 35697914 : if (no_warning)
13588 46 : suppress_warning (ret_stmt, OPT_Wreturn_type);
13589 35697914 : return add_stmt (ret_stmt);
13590 : }
13591 :
13592 : struct c_switch {
13593 : /* The SWITCH_STMT being built. */
13594 : tree switch_stmt;
13595 :
13596 : /* The original type of the testing expression, i.e. before the
13597 : default conversion is applied. */
13598 : tree orig_type;
13599 :
13600 : /* A splay-tree mapping the low element of a case range to the high
13601 : element, or NULL_TREE if there is no high element. Used to
13602 : determine whether or not a new case label duplicates an old case
13603 : label. We need a tree, rather than simply a hash table, because
13604 : of the GNU case range extension. */
13605 : splay_tree cases;
13606 :
13607 : /* The bindings at the point of the switch. This is used for
13608 : warnings crossing decls when branching to a case label. */
13609 : struct c_spot_bindings *bindings;
13610 :
13611 : /* Whether the switch includes any break statements. */
13612 : bool break_stmt_seen_p;
13613 :
13614 : /* The next node on the stack. */
13615 : struct c_switch *next;
13616 :
13617 : /* Remember whether the controlling expression had boolean type
13618 : before integer promotions for the sake of -Wswitch-bool. */
13619 : bool bool_cond_p;
13620 : };
13621 :
13622 : /* A stack of the currently active switch statements. The innermost
13623 : switch statement is on the top of the stack. There is no need to
13624 : mark the stack for garbage collection because it is only active
13625 : during the processing of the body of a function, and we never
13626 : collect at that point. */
13627 :
13628 : struct c_switch *c_switch_stack;
13629 :
13630 : /* Start a C switch statement, testing expression EXP. Return the new
13631 : SWITCH_STMT. SWITCH_LOC is the location of the `switch'.
13632 : SWITCH_COND_LOC is the location of the switch's condition.
13633 : EXPLICIT_CAST_P is true if the expression EXP has an explicit cast. */
13634 :
13635 : tree
13636 37582 : c_start_switch (location_t switch_loc,
13637 : location_t switch_cond_loc,
13638 : tree exp, bool explicit_cast_p, tree switch_name)
13639 : {
13640 37582 : tree orig_type = error_mark_node;
13641 37582 : bool bool_cond_p = false;
13642 37582 : struct c_switch *cs;
13643 :
13644 37582 : if (exp != error_mark_node)
13645 : {
13646 37539 : orig_type = TREE_TYPE (exp);
13647 :
13648 37539 : if (!INTEGRAL_TYPE_P (orig_type))
13649 : {
13650 12 : if (orig_type != error_mark_node)
13651 : {
13652 12 : error_at (switch_cond_loc, "switch quantity not an integer");
13653 12 : orig_type = error_mark_node;
13654 : }
13655 12 : exp = integer_zero_node;
13656 : }
13657 : else
13658 : {
13659 37527 : tree type = TYPE_MAIN_VARIANT (orig_type);
13660 37527 : tree e = exp;
13661 :
13662 : /* Warn if the condition has boolean value. */
13663 37530 : while (TREE_CODE (e) == COMPOUND_EXPR)
13664 3 : e = TREE_OPERAND (e, 1);
13665 :
13666 37502 : if ((C_BOOLEAN_TYPE_P (type)
13667 37502 : || truth_value_p (TREE_CODE (e)))
13668 : /* Explicit cast to int suppresses this warning. */
13669 37549 : && !(TREE_CODE (type) == INTEGER_TYPE
13670 : && explicit_cast_p))
13671 : bool_cond_p = true;
13672 :
13673 37527 : if (!in_system_header_at (input_location)
13674 37527 : && (type == long_integer_type_node
13675 12070 : || type == long_unsigned_type_node))
13676 306 : warning_at (switch_cond_loc,
13677 306 : OPT_Wtraditional, "%<long%> switch expression not "
13678 : "converted to %<int%> in ISO C");
13679 :
13680 37527 : exp = c_fully_fold (exp, false, NULL);
13681 37527 : exp = default_conversion (exp);
13682 :
13683 37527 : if (warn_sequence_point)
13684 6054 : verify_sequence_points (exp);
13685 : }
13686 : }
13687 :
13688 : /* Add this new SWITCH_STMT to the stack. */
13689 37582 : cs = XNEW (struct c_switch);
13690 37582 : cs->switch_stmt = build_stmt (switch_loc, SWITCH_STMT, exp,
13691 : NULL_TREE, orig_type, NULL_TREE, switch_name);
13692 37582 : cs->orig_type = orig_type;
13693 37582 : cs->cases = splay_tree_new (case_compare, NULL, NULL);
13694 37582 : cs->bindings = c_get_switch_bindings ();
13695 37582 : cs->break_stmt_seen_p = false;
13696 37582 : cs->bool_cond_p = bool_cond_p;
13697 37582 : cs->next = c_switch_stack;
13698 37582 : c_switch_stack = cs;
13699 :
13700 37582 : return add_stmt (cs->switch_stmt);
13701 : }
13702 :
13703 : /* Process a case label at location LOC, with attributes ATTRS. */
13704 :
13705 : tree
13706 1032659 : do_case (location_t loc, tree low_value, tree high_value, tree attrs)
13707 : {
13708 1032659 : tree label = NULL_TREE;
13709 :
13710 1032659 : if (low_value && TREE_CODE (low_value) != INTEGER_CST)
13711 : {
13712 87 : low_value = c_fully_fold (low_value, false, NULL);
13713 87 : if (TREE_CODE (low_value) == INTEGER_CST)
13714 9 : pedwarn (loc, OPT_Wpedantic,
13715 : "case label is not an integer constant expression");
13716 : }
13717 :
13718 1032659 : if (high_value && TREE_CODE (high_value) != INTEGER_CST)
13719 : {
13720 0 : high_value = c_fully_fold (high_value, false, NULL);
13721 0 : if (TREE_CODE (high_value) == INTEGER_CST)
13722 0 : pedwarn (input_location, OPT_Wpedantic,
13723 : "case label is not an integer constant expression");
13724 : }
13725 :
13726 1032659 : if (c_switch_stack == NULL)
13727 : {
13728 3 : if (low_value)
13729 2 : error_at (loc, "case label not within a switch statement");
13730 : else
13731 1 : error_at (loc, "%<default%> label not within a switch statement");
13732 : return NULL_TREE;
13733 : }
13734 :
13735 1032656 : if (c_check_switch_jump_warnings (c_switch_stack->bindings,
13736 1032656 : EXPR_LOCATION (c_switch_stack->switch_stmt),
13737 : loc))
13738 : return NULL_TREE;
13739 :
13740 1032644 : label = c_add_case_label (loc, c_switch_stack->cases,
13741 1032644 : SWITCH_STMT_COND (c_switch_stack->switch_stmt),
13742 : low_value, high_value, attrs);
13743 1032644 : if (label == error_mark_node)
13744 144 : label = NULL_TREE;
13745 : return label;
13746 : }
13747 :
13748 : /* Finish the switch statement. TYPE is the original type of the
13749 : controlling expression of the switch, or NULL_TREE. */
13750 :
13751 : void
13752 37582 : c_finish_switch (tree body, tree type)
13753 : {
13754 37582 : struct c_switch *cs = c_switch_stack;
13755 37582 : location_t switch_location;
13756 :
13757 37582 : SWITCH_STMT_BODY (cs->switch_stmt) = body;
13758 :
13759 : /* Emit warnings as needed. */
13760 37582 : switch_location = EXPR_LOCATION (cs->switch_stmt);
13761 43794 : c_do_switch_warnings (cs->cases, switch_location,
13762 6212 : type ? type : SWITCH_STMT_TYPE (cs->switch_stmt),
13763 37582 : SWITCH_STMT_COND (cs->switch_stmt), cs->bool_cond_p);
13764 37582 : if (c_switch_covers_all_cases_p (cs->cases,
13765 37582 : SWITCH_STMT_TYPE (cs->switch_stmt)))
13766 33608 : SWITCH_STMT_ALL_CASES_P (cs->switch_stmt) = 1;
13767 37582 : SWITCH_STMT_NO_BREAK_P (cs->switch_stmt) = !cs->break_stmt_seen_p;
13768 :
13769 : /* Pop the stack. */
13770 37582 : c_switch_stack = cs->next;
13771 37582 : splay_tree_delete (cs->cases);
13772 37582 : c_release_switch_bindings (cs->bindings);
13773 37582 : XDELETE (cs);
13774 37582 : }
13775 :
13776 : /* Emit an if statement. IF_LOCUS is the location of the 'if'. COND,
13777 : THEN_BLOCK and ELSE_BLOCK are expressions to be used; ELSE_BLOCK
13778 : may be null. */
13779 :
13780 : void
13781 1284390 : c_finish_if_stmt (location_t if_locus, tree cond, tree then_block,
13782 : tree else_block)
13783 : {
13784 1284390 : tree stmt;
13785 :
13786 1284390 : stmt = build3 (COND_EXPR, void_type_node, cond, then_block, else_block);
13787 1284390 : SET_EXPR_LOCATION (stmt, if_locus);
13788 1284390 : add_stmt (stmt);
13789 1284390 : }
13790 :
13791 : tree
13792 188555 : c_finish_bc_stmt (location_t loc, tree label, bool is_break, tree name)
13793 : {
13794 : /* In switch statements break is sometimes stylistically used after
13795 : a return statement. This can lead to spurious warnings about
13796 : control reaching the end of a non-void function when it is
13797 : inlined. Note that we are calling block_may_fallthru with
13798 : language specific tree nodes; this works because
13799 : block_may_fallthru returns true when given something it does not
13800 : understand. */
13801 188555 : bool skip = !block_may_fallthru (cur_stmt_list);
13802 :
13803 188555 : if (is_break)
13804 175237 : switch (in_statement & ~IN_NAMED_STMT)
13805 : {
13806 9 : case 0:
13807 9 : error_at (loc, "break statement not within loop or switch");
13808 9 : return NULL_TREE;
13809 4 : case IN_OMP_BLOCK:
13810 4 : error_at (loc, "invalid exit from OpenMP structured block");
13811 4 : return NULL_TREE;
13812 12 : case IN_OMP_FOR:
13813 12 : error_at (loc, "break statement used with OpenMP for loop");
13814 12 : return NULL_TREE;
13815 : case IN_ITERATION_STMT:
13816 : case IN_OBJC_FOREACH:
13817 : break;
13818 159241 : default:
13819 159241 : gcc_assert (in_statement & IN_SWITCH_STMT);
13820 159241 : c_switch_stack->break_stmt_seen_p = true;
13821 159241 : break;
13822 : }
13823 : else
13824 13318 : switch (in_statement & ~(IN_SWITCH_STMT | IN_NAMED_STMT))
13825 : {
13826 7 : case 0:
13827 7 : error_at (loc, "continue statement not within a loop");
13828 7 : return NULL_TREE;
13829 4 : case IN_OMP_BLOCK:
13830 4 : error_at (loc, "invalid exit from OpenMP structured block");
13831 4 : return NULL_TREE;
13832 : case IN_ITERATION_STMT:
13833 : case IN_OMP_FOR:
13834 : case IN_OBJC_FOREACH:
13835 : break;
13836 0 : default:
13837 0 : gcc_unreachable ();
13838 : }
13839 :
13840 188519 : if (skip)
13841 : return NULL_TREE;
13842 188001 : else if ((in_statement & IN_OBJC_FOREACH)
13843 0 : && !(is_break && (in_statement & IN_SWITCH_STMT))
13844 0 : && name == NULL_TREE)
13845 : {
13846 : /* The foreach expander produces low-level code using gotos instead
13847 : of a structured loop construct. */
13848 0 : gcc_assert (label);
13849 0 : return add_stmt (build_stmt (loc, GOTO_EXPR, label));
13850 : }
13851 188098 : else if (name && C_DECL_LOOP_NAME (name) && C_DECL_SWITCH_NAME (name))
13852 : {
13853 0 : label = DECL_CHAIN (name);
13854 0 : if (!is_break)
13855 0 : label = DECL_CHAIN (label);
13856 : /* Foreach expander from some outer level. */
13857 0 : return add_stmt (build_stmt (loc, GOTO_EXPR, label));
13858 : }
13859 201308 : return add_stmt (build_stmt (loc, is_break ? BREAK_STMT : CONTINUE_STMT,
13860 188001 : name));
13861 : }
13862 :
13863 : /* A helper routine for c_process_expr_stmt and c_finish_stmt_expr. */
13864 :
13865 : static void
13866 6516957 : emit_side_effect_warnings (location_t loc, tree expr)
13867 : {
13868 6516957 : maybe_warn_nodiscard (loc, expr);
13869 6516957 : if (!warn_unused_value)
13870 : return;
13871 1312862 : if (expr == error_mark_node)
13872 : ;
13873 1312787 : else if (!TREE_SIDE_EFFECTS (expr))
13874 : {
13875 6567 : if (!VOID_TYPE_P (TREE_TYPE (expr))
13876 6567 : && !warning_suppressed_p (expr, OPT_Wunused_value))
13877 28 : warning_at (loc, OPT_Wunused_value, "statement with no effect");
13878 : }
13879 1306220 : else if (TREE_CODE (expr) == COMPOUND_EXPR)
13880 : {
13881 : tree r = expr;
13882 : location_t cloc = loc;
13883 12011 : while (TREE_CODE (r) == COMPOUND_EXPR)
13884 : {
13885 6021 : if (EXPR_HAS_LOCATION (r))
13886 5479 : cloc = EXPR_LOCATION (r);
13887 6021 : r = TREE_OPERAND (r, 1);
13888 : }
13889 5990 : if (!TREE_SIDE_EFFECTS (r)
13890 33 : && !VOID_TYPE_P (TREE_TYPE (r))
13891 24 : && !CONVERT_EXPR_P (r)
13892 24 : && !warning_suppressed_p (r, OPT_Wunused_value)
13893 6002 : && !warning_suppressed_p (expr, OPT_Wunused_value))
13894 8 : warning_at (cloc, OPT_Wunused_value,
13895 : "right-hand operand of comma expression has no effect");
13896 : }
13897 : else
13898 1300230 : warn_if_unused_value (expr, loc);
13899 : }
13900 :
13901 : /* Process an expression as if it were a complete statement. Emit
13902 : diagnostics, but do not call ADD_STMT. LOC is the location of the
13903 : statement. */
13904 :
13905 : tree
13906 6393553 : c_process_expr_stmt (location_t loc, tree expr)
13907 : {
13908 6393553 : tree exprv;
13909 :
13910 6393553 : if (!expr)
13911 : return NULL_TREE;
13912 :
13913 6389138 : expr = c_fully_fold (expr, false, NULL);
13914 :
13915 6389138 : if (warn_sequence_point)
13916 1308563 : verify_sequence_points (expr);
13917 :
13918 6389138 : if (TREE_TYPE (expr) != error_mark_node
13919 6386484 : && !COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (expr))
13920 6389138 : && TREE_CODE (TREE_TYPE (expr)) != ARRAY_TYPE)
13921 0 : error_at (loc, "expression statement has incomplete type");
13922 :
13923 : /* If we're not processing a statement expression, warn about unused values.
13924 : Warnings for statement expressions will be emitted later, once we figure
13925 : out which is the result. */
13926 6389138 : if (!STATEMENT_LIST_STMT_EXPR (cur_stmt_list)
13927 6389138 : && (warn_unused_value || warn_unused_result))
13928 6266762 : emit_side_effect_warnings (EXPR_LOC_OR_LOC (expr, loc), expr);
13929 :
13930 6389137 : exprv = expr;
13931 6430562 : while (TREE_CODE (exprv) == COMPOUND_EXPR)
13932 41425 : exprv = TREE_OPERAND (exprv, 1);
13933 6400869 : while (CONVERT_EXPR_P (exprv))
13934 11732 : exprv = TREE_OPERAND (exprv, 0);
13935 6389137 : if (DECL_P (exprv)
13936 6389722 : || handled_component_p (exprv)
13937 12758289 : || TREE_CODE (exprv) == ADDR_EXPR)
13938 20570 : mark_exp_read (exprv);
13939 :
13940 : /* If the expression is not of a type to which we cannot assign a line
13941 : number, wrap the thing in a no-op NOP_EXPR. */
13942 6389137 : if (DECL_P (expr) || CONSTANT_CLASS_P (expr))
13943 : {
13944 14897 : expr = build1 (NOP_EXPR, TREE_TYPE (expr), expr);
13945 14897 : SET_EXPR_LOCATION (expr, loc);
13946 : }
13947 :
13948 : return expr;
13949 : }
13950 :
13951 : /* Emit an expression as a statement. LOC is the location of the
13952 : expression. */
13953 :
13954 : tree
13955 6087404 : c_finish_expr_stmt (location_t loc, tree expr)
13956 : {
13957 6087404 : if (expr)
13958 6073145 : return add_stmt (c_process_expr_stmt (loc, expr));
13959 : else
13960 : return NULL;
13961 : }
13962 :
13963 : /* Do the opposite and emit a statement as an expression. To begin,
13964 : create a new binding level and return it. */
13965 :
13966 : tree
13967 34966 : c_begin_stmt_expr (void)
13968 : {
13969 34966 : tree ret;
13970 :
13971 : /* We must force a BLOCK for this level so that, if it is not expanded
13972 : later, there is a way to turn off the entire subtree of blocks that
13973 : are contained in it. */
13974 34966 : keep_next_level ();
13975 34966 : ret = c_begin_compound_stmt (true);
13976 :
13977 34966 : c_bindings_start_stmt_expr (c_switch_stack == NULL
13978 : ? NULL
13979 : : c_switch_stack->bindings);
13980 :
13981 : /* Mark the current statement list as belonging to a statement list. */
13982 34966 : STATEMENT_LIST_STMT_EXPR (ret) = 1;
13983 :
13984 34966 : return ret;
13985 : }
13986 :
13987 : /* LOC is the location of the compound statement to which this body
13988 : belongs. */
13989 :
13990 : tree
13991 34966 : c_finish_stmt_expr (location_t loc, tree body)
13992 : {
13993 34966 : tree last, type, tmp, val;
13994 34966 : tree *last_p;
13995 :
13996 34966 : body = c_end_compound_stmt (loc, body, true);
13997 :
13998 34966 : c_bindings_end_stmt_expr (c_switch_stack == NULL
13999 : ? NULL
14000 : : c_switch_stack->bindings);
14001 :
14002 : /* Locate the last statement in BODY. See c_end_compound_stmt
14003 : about always returning a BIND_EXPR. */
14004 34966 : last_p = &BIND_EXPR_BODY (body);
14005 34966 : last = BIND_EXPR_BODY (body);
14006 :
14007 34966 : continue_searching:
14008 34966 : if (TREE_CODE (last) == STATEMENT_LIST)
14009 : {
14010 26130 : tree_stmt_iterator l = tsi_last (last);
14011 :
14012 26136 : while (!tsi_end_p (l) && TREE_CODE (tsi_stmt (l)) == DEBUG_BEGIN_STMT)
14013 6 : tsi_prev (&l);
14014 :
14015 : /* This can happen with degenerate cases like ({ }). No value. */
14016 26130 : if (tsi_end_p (l))
14017 389 : return body;
14018 :
14019 : /* If we're supposed to generate side effects warnings, process
14020 : all of the statements except the last. */
14021 25741 : if (warn_unused_value || warn_unused_result)
14022 : {
14023 25741 : for (tree_stmt_iterator i = tsi_start (last);
14024 275936 : tsi_stmt (i) != tsi_stmt (l); tsi_next (&i))
14025 : {
14026 250195 : location_t tloc;
14027 250195 : tree t = tsi_stmt (i);
14028 :
14029 250195 : tloc = EXPR_HAS_LOCATION (t) ? EXPR_LOCATION (t) : loc;
14030 250195 : emit_side_effect_warnings (tloc, t);
14031 : }
14032 : }
14033 25741 : last_p = tsi_stmt_ptr (l);
14034 25741 : last = *last_p;
14035 : }
14036 :
14037 : /* If the end of the list is exception related, then the list was split
14038 : by a call to push_cleanup. Continue searching. */
14039 34577 : if (TREE_CODE (last) == TRY_FINALLY_EXPR
14040 34577 : || TREE_CODE (last) == TRY_CATCH_EXPR)
14041 : {
14042 0 : last_p = &TREE_OPERAND (last, 0);
14043 0 : last = *last_p;
14044 0 : goto continue_searching;
14045 : }
14046 :
14047 34577 : if (last == error_mark_node)
14048 : return last;
14049 :
14050 : /* In the case that the BIND_EXPR is not necessary, return the
14051 : expression out from inside it. */
14052 34568 : if ((last == BIND_EXPR_BODY (body)
14053 : /* Skip nested debug stmts. */
14054 25740 : || last == expr_first (BIND_EXPR_BODY (body)))
14055 45624 : && BIND_EXPR_VARS (body) == NULL)
14056 : {
14057 : /* Even if this looks constant, do not allow it in a constant
14058 : expression. */
14059 11044 : last = c_wrap_maybe_const (last, true);
14060 : /* Do not warn if the return value of a statement expression is
14061 : unused. */
14062 11044 : suppress_warning (last, OPT_Wunused);
14063 11044 : return last;
14064 : }
14065 :
14066 : /* Extract the type of said expression. */
14067 23524 : type = TREE_TYPE (last);
14068 :
14069 : /* If we're not returning a value at all, then the BIND_EXPR that
14070 : we already have is a fine expression to return. */
14071 23524 : if (!type || VOID_TYPE_P (type))
14072 : return body;
14073 :
14074 : /* Now that we've located the expression containing the value, it seems
14075 : silly to make voidify_wrapper_expr repeat the process. Create a
14076 : temporary of the appropriate type and stick it in a TARGET_EXPR. */
14077 18200 : tmp = create_tmp_var_raw (type);
14078 :
14079 : /* Unwrap a no-op NOP_EXPR as added by c_finish_expr_stmt. This avoids
14080 : tree_expr_nonnegative_p giving up immediately. */
14081 18200 : val = last;
14082 18200 : if (TREE_CODE (val) == NOP_EXPR
14083 18200 : && TREE_TYPE (val) == TREE_TYPE (TREE_OPERAND (val, 0)))
14084 3794 : val = TREE_OPERAND (val, 0);
14085 :
14086 18200 : *last_p = build2 (MODIFY_EXPR, void_type_node, tmp, val);
14087 18200 : SET_EXPR_LOCATION (*last_p, EXPR_LOCATION (last));
14088 :
14089 18200 : {
14090 18200 : tree t = build4 (TARGET_EXPR, type, tmp, body, NULL_TREE, NULL_TREE);
14091 18200 : SET_EXPR_LOCATION (t, loc);
14092 18200 : return t;
14093 : }
14094 : }
14095 :
14096 : /* Begin and end compound statements. This is as simple as pushing
14097 : and popping new statement lists from the tree. */
14098 :
14099 : tree
14100 42387214 : c_begin_compound_stmt (bool do_scope)
14101 : {
14102 42387214 : tree stmt = push_stmt_list ();
14103 42387214 : if (do_scope)
14104 42291040 : push_scope ();
14105 42387214 : return stmt;
14106 : }
14107 :
14108 : /* End a compound statement. STMT is the statement. LOC is the
14109 : location of the compound statement-- this is usually the location
14110 : of the opening brace. */
14111 :
14112 : tree
14113 42387213 : c_end_compound_stmt (location_t loc, tree stmt, bool do_scope)
14114 : {
14115 42387213 : tree block = NULL;
14116 :
14117 42387213 : if (do_scope)
14118 : {
14119 42291039 : if (c_dialect_objc ())
14120 0 : objc_clear_super_receiver ();
14121 42291039 : block = pop_scope ();
14122 : }
14123 :
14124 42387213 : stmt = pop_stmt_list (stmt);
14125 42387213 : stmt = c_build_bind_expr (loc, block, stmt);
14126 :
14127 : /* If this compound statement is nested immediately inside a statement
14128 : expression, then force a BIND_EXPR to be created. Otherwise we'll
14129 : do the wrong thing for ({ { 1; } }) or ({ 1; { } }). In particular,
14130 : STATEMENT_LISTs merge, and thus we can lose track of what statement
14131 : was really last. */
14132 84774426 : if (building_stmt_list_p ()
14133 42387128 : && STATEMENT_LIST_STMT_EXPR (cur_stmt_list)
14134 42509927 : && TREE_CODE (stmt) != BIND_EXPR)
14135 : {
14136 120971 : stmt = build3 (BIND_EXPR, void_type_node, NULL, stmt, NULL);
14137 120971 : TREE_SIDE_EFFECTS (stmt) = 1;
14138 120971 : SET_EXPR_LOCATION (stmt, loc);
14139 : }
14140 :
14141 42387213 : return stmt;
14142 : }
14143 :
14144 : /* Queue a cleanup. CLEANUP is an expression/statement to be executed
14145 : when the current scope is exited. EH_ONLY is true when this is not
14146 : meant to apply to normal control flow transfer. */
14147 :
14148 : void
14149 131 : push_cleanup (tree decl, tree cleanup, bool eh_only)
14150 : {
14151 131 : enum tree_code code;
14152 131 : tree stmt, list;
14153 131 : bool stmt_expr;
14154 :
14155 131 : code = eh_only ? TRY_CATCH_EXPR : TRY_FINALLY_EXPR;
14156 131 : stmt = build_stmt (DECL_SOURCE_LOCATION (decl), code, NULL, cleanup);
14157 131 : add_stmt (stmt);
14158 131 : stmt_expr = STATEMENT_LIST_STMT_EXPR (cur_stmt_list);
14159 131 : list = push_stmt_list ();
14160 131 : TREE_OPERAND (stmt, 0) = list;
14161 131 : STATEMENT_LIST_STMT_EXPR (list) = stmt_expr;
14162 131 : }
14163 :
14164 : /* Build a vector comparison of ARG0 and ARG1 using CODE opcode
14165 : into a value of TYPE type. Comparison is done via VEC_COND_EXPR. */
14166 :
14167 : static tree
14168 101539 : build_vec_cmp (tree_code code, tree type,
14169 : tree arg0, tree arg1)
14170 : {
14171 101539 : tree zero_vec = build_zero_cst (type);
14172 101539 : tree minus_one_vec = build_minus_one_cst (type);
14173 101539 : tree cmp_type = truth_type_for (TREE_TYPE (arg0));
14174 101539 : tree cmp = build2 (code, cmp_type, arg0, arg1);
14175 101539 : return build3 (VEC_COND_EXPR, type, cmp, minus_one_vec, zero_vec);
14176 : }
14177 :
14178 : /* Possibly warn about an address of OP never being NULL in a comparison
14179 : operation CODE involving null. */
14180 :
14181 : static void
14182 52353 : maybe_warn_for_null_address (location_t loc, tree op, tree_code code)
14183 : {
14184 : /* Prevent warnings issued for macro expansion. */
14185 52353 : if (!warn_address
14186 30678 : || warning_suppressed_p (op, OPT_Waddress)
14187 82655 : || from_macro_expansion_at (loc))
14188 : return;
14189 :
14190 27555 : if (TREE_CODE (op) == NOP_EXPR)
14191 : {
14192 : /* Allow casts to intptr_t to suppress the warning. */
14193 1135 : tree type = TREE_TYPE (op);
14194 1135 : if (TREE_CODE (type) == INTEGER_TYPE)
14195 : return;
14196 1135 : op = TREE_OPERAND (op, 0);
14197 : }
14198 :
14199 27555 : if (TREE_CODE (op) == POINTER_PLUS_EXPR)
14200 : {
14201 : /* Allow a cast to void* to suppress the warning. */
14202 24 : tree type = TREE_TYPE (TREE_TYPE (op));
14203 24 : if (VOID_TYPE_P (type))
14204 : return;
14205 :
14206 : /* Adding any value to a null pointer, including zero, is undefined
14207 : in C. This includes the expression &p[0] where p is the null
14208 : pointer, although &p[0] will have been folded to p by this point
14209 : and so not diagnosed. */
14210 24 : if (code == EQ_EXPR)
14211 22 : warning_at (loc, OPT_Waddress,
14212 : "the comparison will always evaluate as %<false%> "
14213 : "for the pointer operand in %qE must not be NULL",
14214 : op);
14215 : else
14216 2 : warning_at (loc, OPT_Waddress,
14217 : "the comparison will always evaluate as %<true%> "
14218 : "for the pointer operand in %qE must not be NULL",
14219 : op);
14220 :
14221 : return;
14222 : }
14223 :
14224 27531 : if (TREE_CODE (op) != ADDR_EXPR)
14225 : return;
14226 :
14227 254 : op = TREE_OPERAND (op, 0);
14228 :
14229 254 : if (TREE_CODE (op) == IMAGPART_EXPR
14230 254 : || TREE_CODE (op) == REALPART_EXPR)
14231 : {
14232 : /* The address of either complex part may not be null. */
14233 14 : if (code == EQ_EXPR)
14234 9 : warning_at (loc, OPT_Waddress,
14235 : "the comparison will always evaluate as %<false%> "
14236 : "for the address of %qE will never be NULL",
14237 : op);
14238 : else
14239 5 : warning_at (loc, OPT_Waddress,
14240 : "the comparison will always evaluate as %<true%> "
14241 : "for the address of %qE will never be NULL",
14242 : op);
14243 : return;
14244 : }
14245 :
14246 : /* Set to true in the loop below if OP dereferences is operand.
14247 : In such a case the ultimate target need not be a decl for
14248 : the null [in]equality test to be constant. */
14249 : bool deref = false;
14250 :
14251 : /* Get the outermost array or object, or member. */
14252 294 : while (handled_component_p (op))
14253 : {
14254 72 : if (TREE_CODE (op) == COMPONENT_REF)
14255 : {
14256 : /* Get the member (its address is never null). */
14257 18 : op = TREE_OPERAND (op, 1);
14258 18 : break;
14259 : }
14260 :
14261 : /* Get the outer array/object to refer to in the warning. */
14262 54 : op = TREE_OPERAND (op, 0);
14263 54 : deref = true;
14264 : }
14265 :
14266 192 : if ((!deref && !decl_with_nonnull_addr_p (op))
14267 371 : || from_macro_expansion_at (loc))
14268 : return;
14269 :
14270 131 : bool w;
14271 131 : if (code == EQ_EXPR)
14272 93 : w = warning_at (loc, OPT_Waddress,
14273 : "the comparison will always evaluate as %<false%> "
14274 : "for the address of %qE will never be NULL",
14275 : op);
14276 : else
14277 38 : w = warning_at (loc, OPT_Waddress,
14278 : "the comparison will always evaluate as %<true%> "
14279 : "for the address of %qE will never be NULL",
14280 : op);
14281 :
14282 131 : if (w && DECL_P (op))
14283 120 : inform (DECL_SOURCE_LOCATION (op), "%qD declared here", op);
14284 : }
14285 :
14286 : /* Build a binary-operation expression without default conversions.
14287 : CODE is the kind of expression to build.
14288 : LOCATION is the operator's location.
14289 : This function differs from `build' in several ways:
14290 : the data type of the result is computed and recorded in it,
14291 : warnings are generated if arg data types are invalid,
14292 : special handling for addition and subtraction of pointers is known,
14293 : and some optimization is done (operations on narrow ints
14294 : are done in the narrower type when that gives the same result).
14295 : Constant folding is also done before the result is returned.
14296 :
14297 : Note that the operands will never have enumeral types, or function
14298 : or array types, because either they will have the default conversions
14299 : performed or they have both just been converted to some other type in which
14300 : the arithmetic is to be done. */
14301 :
14302 : tree
14303 16995399 : build_binary_op (location_t location, enum tree_code code,
14304 : tree orig_op0, tree orig_op1, bool convert_p)
14305 : {
14306 16995399 : tree type0, type1, orig_type0, orig_type1;
14307 16995399 : tree eptype;
14308 16995399 : enum tree_code code0, code1;
14309 16995399 : tree op0, op1;
14310 16995399 : tree ret = error_mark_node;
14311 16995399 : const char *invalid_op_diag;
14312 16995399 : bool op0_int_operands, op1_int_operands;
14313 16995399 : bool int_const, int_const_or_overflow, int_operands;
14314 :
14315 : /* Expression code to give to the expression when it is built.
14316 : Normally this is CODE, which is what the caller asked for,
14317 : but in some special cases we change it. */
14318 16995399 : enum tree_code resultcode = code;
14319 :
14320 : /* Data type in which the computation is to be performed.
14321 : In the simplest cases this is the common type of the arguments. */
14322 16995399 : tree result_type = NULL;
14323 :
14324 : /* When the computation is in excess precision, the type of the
14325 : final EXCESS_PRECISION_EXPR. */
14326 16995399 : tree semantic_result_type = NULL;
14327 :
14328 : /* Nonzero means operands have already been type-converted
14329 : in whatever way is necessary.
14330 : Zero means they need to be converted to RESULT_TYPE. */
14331 16995399 : int converted = 0;
14332 :
14333 : /* Nonzero means create the expression with this type, rather than
14334 : RESULT_TYPE. */
14335 16995399 : tree build_type = NULL_TREE;
14336 :
14337 : /* Nonzero means after finally constructing the expression
14338 : convert it to this type. */
14339 16995399 : tree final_type = NULL_TREE;
14340 :
14341 : /* Nonzero if this is an operation like MIN or MAX which can
14342 : safely be computed in short if both args are promoted shorts.
14343 : Also implies COMMON.
14344 : -1 indicates a bitwise operation; this makes a difference
14345 : in the exact conditions for when it is safe to do the operation
14346 : in a narrower mode. */
14347 16995399 : int shorten = 0;
14348 :
14349 : /* Nonzero if this is a comparison operation;
14350 : if both args are promoted shorts, compare the original shorts.
14351 : Also implies COMMON. */
14352 16995399 : int short_compare = 0;
14353 :
14354 : /* Nonzero if this is a right-shift operation, which can be computed on the
14355 : original short and then promoted if the operand is a promoted short. */
14356 16995399 : int short_shift = 0;
14357 :
14358 : /* Nonzero means set RESULT_TYPE to the common type of the args. */
14359 16995399 : int common = 0;
14360 :
14361 : /* True means types are compatible as far as ObjC is concerned. */
14362 16995399 : bool objc_ok;
14363 :
14364 : /* True means this is an arithmetic operation that may need excess
14365 : precision. */
14366 16995399 : bool may_need_excess_precision;
14367 :
14368 : /* True means this is a boolean operation that converts both its
14369 : operands to truth-values. */
14370 16995399 : bool boolean_op = false;
14371 :
14372 : /* Remember whether we're doing / or %. */
14373 16995399 : bool doing_div_or_mod = false;
14374 :
14375 : /* Remember whether we're doing << or >>. */
14376 16995399 : bool doing_shift = false;
14377 :
14378 : /* Tree holding instrumentation expression. */
14379 16995399 : tree instrument_expr = NULL;
14380 :
14381 16995399 : if (location == UNKNOWN_LOCATION)
14382 80 : location = input_location;
14383 :
14384 16995399 : op0 = orig_op0;
14385 16995399 : op1 = orig_op1;
14386 :
14387 16995399 : op0_int_operands = EXPR_INT_CONST_OPERANDS (orig_op0);
14388 : if (op0_int_operands)
14389 8234531 : op0 = remove_c_maybe_const_expr (op0);
14390 16995399 : op1_int_operands = EXPR_INT_CONST_OPERANDS (orig_op1);
14391 : if (op1_int_operands)
14392 11531461 : op1 = remove_c_maybe_const_expr (op1);
14393 28526860 : int_operands = (op0_int_operands && op1_int_operands);
14394 11531461 : if (int_operands)
14395 : {
14396 16110917 : int_const_or_overflow = (TREE_CODE (orig_op0) == INTEGER_CST
14397 8070629 : && TREE_CODE (orig_op1) == INTEGER_CST);
14398 8040288 : int_const = (int_const_or_overflow
14399 8040288 : && !TREE_OVERFLOW (orig_op0)
14400 8040219 : && !TREE_OVERFLOW (orig_op1));
14401 : }
14402 : else
14403 : int_const = int_const_or_overflow = false;
14404 :
14405 : /* Do not apply default conversion in mixed vector/scalar expression. */
14406 16995399 : if (convert_p
14407 16995399 : && VECTOR_TYPE_P (TREE_TYPE (op0)) == VECTOR_TYPE_P (TREE_TYPE (op1)))
14408 : {
14409 10205562 : op0 = default_conversion (op0);
14410 10205562 : op1 = default_conversion (op1);
14411 : }
14412 :
14413 16995399 : orig_type0 = type0 = TREE_TYPE (op0);
14414 :
14415 16995399 : orig_type1 = type1 = TREE_TYPE (op1);
14416 :
14417 : /* The expression codes of the data types of the arguments tell us
14418 : whether the arguments are integers, floating, pointers, etc. */
14419 16995399 : code0 = TREE_CODE (type0);
14420 16995399 : code1 = TREE_CODE (type1);
14421 :
14422 : /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
14423 16995401 : STRIP_TYPE_NOPS (op0);
14424 16995402 : STRIP_TYPE_NOPS (op1);
14425 :
14426 : /* If an error was already reported for one of the arguments,
14427 : avoid reporting another error. */
14428 :
14429 16995399 : if (code0 == ERROR_MARK || code1 == ERROR_MARK)
14430 710 : return error_mark_node;
14431 :
14432 16994689 : if (code0 == POINTER_TYPE
14433 16994689 : && reject_gcc_builtin (op0, EXPR_LOCATION (orig_op0)))
14434 11 : return error_mark_node;
14435 :
14436 16994678 : if (code1 == POINTER_TYPE
14437 16994678 : && reject_gcc_builtin (op1, EXPR_LOCATION (orig_op1)))
14438 11 : return error_mark_node;
14439 :
14440 33989334 : if ((invalid_op_diag
14441 16994667 : = targetm.invalid_binary_op (code, type0, type1)))
14442 : {
14443 0 : error_at (location, invalid_op_diag);
14444 0 : return error_mark_node;
14445 : }
14446 :
14447 16994667 : switch (code)
14448 : {
14449 : case PLUS_EXPR:
14450 : case MINUS_EXPR:
14451 : case MULT_EXPR:
14452 : case TRUNC_DIV_EXPR:
14453 : case CEIL_DIV_EXPR:
14454 : case FLOOR_DIV_EXPR:
14455 : case ROUND_DIV_EXPR:
14456 : case EXACT_DIV_EXPR:
14457 : may_need_excess_precision = true;
14458 : break;
14459 :
14460 2762014 : case EQ_EXPR:
14461 2762014 : case NE_EXPR:
14462 2762014 : case LE_EXPR:
14463 2762014 : case GE_EXPR:
14464 2762014 : case LT_EXPR:
14465 2762014 : case GT_EXPR:
14466 : /* Excess precision for implicit conversions of integers to
14467 : floating point in C11 and later. */
14468 2762014 : may_need_excess_precision = (flag_isoc11
14469 2762014 : && (ANY_INTEGRAL_TYPE_P (type0)
14470 488174 : || ANY_INTEGRAL_TYPE_P (type1)));
14471 : break;
14472 :
14473 : default:
14474 16994667 : may_need_excess_precision = false;
14475 : break;
14476 : }
14477 16994667 : if (TREE_CODE (op0) == EXCESS_PRECISION_EXPR)
14478 : {
14479 184 : op0 = TREE_OPERAND (op0, 0);
14480 184 : type0 = TREE_TYPE (op0);
14481 : }
14482 16994483 : else if (may_need_excess_precision
14483 16994483 : && (eptype = excess_precision_type (type0)) != NULL_TREE)
14484 : {
14485 771 : type0 = eptype;
14486 771 : op0 = convert (eptype, op0);
14487 : }
14488 16994667 : if (TREE_CODE (op1) == EXCESS_PRECISION_EXPR)
14489 : {
14490 896 : op1 = TREE_OPERAND (op1, 0);
14491 896 : type1 = TREE_TYPE (op1);
14492 : }
14493 16993771 : else if (may_need_excess_precision
14494 16993771 : && (eptype = excess_precision_type (type1)) != NULL_TREE)
14495 : {
14496 592 : type1 = eptype;
14497 592 : op1 = convert (eptype, op1);
14498 : }
14499 :
14500 16994667 : objc_ok = objc_compare_types (type0, type1, -3, NULL_TREE);
14501 :
14502 : /* In case when one of the operands of the binary operation is
14503 : a vector and another is a scalar -- convert scalar to vector. */
14504 18582518 : if ((gnu_vector_type_p (type0) && code1 != VECTOR_TYPE)
14505 18580559 : || (gnu_vector_type_p (type1) && code0 != VECTOR_TYPE))
14506 : {
14507 2585 : enum stv_conv convert_flag = scalar_to_vector (location, code, orig_op0,
14508 : orig_op1, true);
14509 :
14510 2585 : switch (convert_flag)
14511 : {
14512 12 : case stv_error:
14513 12 : return error_mark_node;
14514 613 : case stv_firstarg:
14515 613 : {
14516 613 : bool maybe_const = true;
14517 613 : tree sc;
14518 613 : sc = c_fully_fold (op0, false, &maybe_const);
14519 613 : sc = save_expr (sc);
14520 613 : sc = convert (TREE_TYPE (type1), sc);
14521 613 : op0 = build_vector_from_val (type1, sc);
14522 613 : if (!maybe_const)
14523 93 : op0 = c_wrap_maybe_const (op0, true);
14524 613 : orig_type0 = type0 = TREE_TYPE (op0);
14525 613 : code0 = TREE_CODE (type0);
14526 613 : converted = 1;
14527 613 : break;
14528 : }
14529 1093 : case stv_secondarg:
14530 1093 : {
14531 1093 : bool maybe_const = true;
14532 1093 : tree sc;
14533 1093 : sc = c_fully_fold (op1, false, &maybe_const);
14534 1093 : sc = save_expr (sc);
14535 1093 : sc = convert (TREE_TYPE (type0), sc);
14536 1093 : op1 = build_vector_from_val (type0, sc);
14537 1093 : if (!maybe_const)
14538 38 : op1 = c_wrap_maybe_const (op1, true);
14539 1093 : orig_type1 = type1 = TREE_TYPE (op1);
14540 1093 : code1 = TREE_CODE (type1);
14541 1093 : converted = 1;
14542 1093 : break;
14543 : }
14544 : default:
14545 : break;
14546 : }
14547 : }
14548 :
14549 16994655 : switch (code)
14550 : {
14551 8724967 : case PLUS_EXPR:
14552 : /* Handle the pointer + int case. */
14553 8724967 : if (code0 == POINTER_TYPE
14554 1257836 : && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
14555 : {
14556 1257830 : ret = pointer_int_sum (location, PLUS_EXPR, op0, op1);
14557 1257830 : goto return_build_binary_op;
14558 : }
14559 7467137 : else if (code1 == POINTER_TYPE
14560 1541 : && (code0 == INTEGER_TYPE || code0 == BITINT_TYPE))
14561 : {
14562 1535 : ret = pointer_int_sum (location, PLUS_EXPR, op1, op0);
14563 1535 : goto return_build_binary_op;
14564 : }
14565 : else
14566 : common = 1;
14567 : break;
14568 :
14569 800963 : case MINUS_EXPR:
14570 : /* Subtraction of two similar pointers.
14571 : We must subtract them as integers, then divide by object size. */
14572 800963 : if (code0 == POINTER_TYPE && code1 == POINTER_TYPE
14573 800963 : && comp_target_types (location, type0, type1))
14574 : {
14575 3753 : ret = pointer_diff (location, op0, op1, &instrument_expr);
14576 3753 : goto return_build_binary_op;
14577 : }
14578 : /* Handle pointer minus int. Just like pointer plus int. */
14579 797210 : else if (code0 == POINTER_TYPE
14580 16905 : && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
14581 : {
14582 16893 : ret = pointer_int_sum (location, MINUS_EXPR, op0, op1);
14583 16893 : goto return_build_binary_op;
14584 : }
14585 : else
14586 : common = 1;
14587 : break;
14588 :
14589 : case MULT_EXPR:
14590 : common = 1;
14591 : break;
14592 :
14593 276095 : case TRUNC_DIV_EXPR:
14594 276095 : case CEIL_DIV_EXPR:
14595 276095 : case FLOOR_DIV_EXPR:
14596 276095 : case ROUND_DIV_EXPR:
14597 276095 : case EXACT_DIV_EXPR:
14598 276095 : doing_div_or_mod = true;
14599 276095 : warn_for_div_by_zero (location, op1);
14600 :
14601 276094 : if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
14602 49874 : || code0 == FIXED_POINT_TYPE || code0 == BITINT_TYPE
14603 47860 : || code0 == COMPLEX_TYPE
14604 45805 : || gnu_vector_type_p (type0))
14605 325967 : && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
14606 47434 : || code1 == FIXED_POINT_TYPE || code1 == BITINT_TYPE
14607 47267 : || code1 == COMPLEX_TYPE
14608 45807 : || gnu_vector_type_p (type1)))
14609 : {
14610 276090 : enum tree_code tcode0 = code0, tcode1 = code1;
14611 :
14612 276090 : if (code0 == COMPLEX_TYPE || code0 == VECTOR_TYPE)
14613 47859 : tcode0 = TREE_CODE (TREE_TYPE (TREE_TYPE (op0)));
14614 276090 : if (code1 == COMPLEX_TYPE || code1 == VECTOR_TYPE)
14615 47264 : tcode1 = TREE_CODE (TREE_TYPE (TREE_TYPE (op1)));
14616 :
14617 276090 : if (!(((tcode0 == INTEGER_TYPE || tcode0 == BITINT_TYPE
14618 69921 : || (tcode0 == ENUMERAL_TYPE && code0 == VECTOR_TYPE))
14619 206170 : && (tcode1 == INTEGER_TYPE || tcode1 == BITINT_TYPE
14620 12988 : || (tcode1 == ENUMERAL_TYPE && code1 == VECTOR_TYPE)))
14621 82907 : || (tcode0 == FIXED_POINT_TYPE && tcode1 == FIXED_POINT_TYPE)))
14622 : resultcode = RDIV_EXPR;
14623 : else
14624 : /* Although it would be tempting to shorten always here, that
14625 : loses on some targets, since the modulo instruction is
14626 : undefined if the quotient can't be represented in the
14627 : computation mode. We shorten only if unsigned or if
14628 : dividing by something we know != -1. */
14629 193183 : shorten = may_shorten_divmod (op0, op1);
14630 : common = 1;
14631 : }
14632 : break;
14633 :
14634 1597364 : case BIT_AND_EXPR:
14635 1597364 : case BIT_IOR_EXPR:
14636 1597364 : case BIT_XOR_EXPR:
14637 1597364 : if ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE)
14638 1059225 : && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
14639 : shorten = -1;
14640 : /* Allow vector types which are not floating point types. */
14641 538175 : else if (gnu_vector_type_p (type0)
14642 538098 : && gnu_vector_type_p (type1)
14643 538098 : && !VECTOR_FLOAT_TYPE_P (type0)
14644 1076270 : && !VECTOR_FLOAT_TYPE_P (type1))
14645 : common = 1;
14646 : break;
14647 :
14648 58922 : case TRUNC_MOD_EXPR:
14649 58922 : case FLOOR_MOD_EXPR:
14650 58922 : doing_div_or_mod = true;
14651 58922 : warn_for_div_by_zero (location, op1);
14652 :
14653 58922 : if (gnu_vector_type_p (type0)
14654 301 : && gnu_vector_type_p (type1)
14655 301 : && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
14656 59223 : && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE)
14657 : common = 1;
14658 58621 : else if ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE)
14659 58620 : && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
14660 : {
14661 : /* Although it would be tempting to shorten always here, that loses
14662 : on some targets, since the modulo instruction is undefined if the
14663 : quotient can't be represented in the computation mode. We shorten
14664 : only if unsigned or if dividing by something we know != -1. */
14665 58620 : shorten = may_shorten_divmod (op0, op1);
14666 58620 : common = 1;
14667 : }
14668 : break;
14669 :
14670 512769 : case TRUTH_ANDIF_EXPR:
14671 512769 : case TRUTH_ORIF_EXPR:
14672 512769 : case TRUTH_AND_EXPR:
14673 512769 : case TRUTH_OR_EXPR:
14674 512769 : case TRUTH_XOR_EXPR:
14675 512769 : if ((code0 == INTEGER_TYPE || code0 == POINTER_TYPE
14676 0 : || code0 == REAL_TYPE || code0 == COMPLEX_TYPE
14677 0 : || code0 == FIXED_POINT_TYPE || code0 == NULLPTR_TYPE
14678 0 : || code0 == BITINT_TYPE)
14679 512769 : && (code1 == INTEGER_TYPE || code1 == POINTER_TYPE
14680 165 : || code1 == REAL_TYPE || code1 == COMPLEX_TYPE
14681 24 : || code1 == FIXED_POINT_TYPE || code1 == NULLPTR_TYPE
14682 22 : || code1 == BITINT_TYPE))
14683 : {
14684 : /* Result of these operations is always an int,
14685 : but that does not mean the operands should be
14686 : converted to ints! */
14687 512769 : result_type = integer_type_node;
14688 512769 : if (op0_int_operands)
14689 : {
14690 110377 : op0 = c_objc_common_truthvalue_conversion (location, orig_op0);
14691 110377 : op0 = remove_c_maybe_const_expr (op0);
14692 : }
14693 : else
14694 402392 : op0 = c_objc_common_truthvalue_conversion (location, op0);
14695 512769 : if (op1_int_operands)
14696 : {
14697 71351 : op1 = c_objc_common_truthvalue_conversion (location, orig_op1);
14698 71351 : op1 = remove_c_maybe_const_expr (op1);
14699 : }
14700 : else
14701 441418 : op1 = c_objc_common_truthvalue_conversion (location, op1);
14702 : converted = 1;
14703 : boolean_op = true;
14704 : }
14705 512769 : if (code == TRUTH_ANDIF_EXPR)
14706 : {
14707 250410 : int_const_or_overflow = (int_operands
14708 63161 : && TREE_CODE (orig_op0) == INTEGER_CST
14709 250426 : && (op0 == truthvalue_false_node
14710 13120 : || TREE_CODE (orig_op1) == INTEGER_CST));
14711 : int_const = (int_const_or_overflow
14712 63134 : && !TREE_OVERFLOW (orig_op0)
14713 63134 : && (op0 == truthvalue_false_node
14714 13104 : || !TREE_OVERFLOW (orig_op1)));
14715 : }
14716 325493 : else if (code == TRUTH_ORIF_EXPR)
14717 : {
14718 332173 : int_const_or_overflow = (int_operands
14719 6831 : && TREE_CODE (orig_op0) == INTEGER_CST
14720 332196 : && (op0 == truthvalue_true_node
14721 2146 : || TREE_CODE (orig_op1) == INTEGER_CST));
14722 : int_const = (int_const_or_overflow
14723 6801 : && !TREE_OVERFLOW (orig_op0)
14724 6801 : && (op0 == truthvalue_true_node
14725 2123 : || !TREE_OVERFLOW (orig_op1)));
14726 : }
14727 : break;
14728 :
14729 : /* Shift operations: result has same type as first operand;
14730 : always convert second operand to int.
14731 : Also set SHORT_SHIFT if shifting rightward. */
14732 :
14733 233226 : case RSHIFT_EXPR:
14734 233226 : if (gnu_vector_type_p (type0)
14735 837 : && gnu_vector_type_p (type1)
14736 258 : && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
14737 256 : && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE
14738 233482 : && known_eq (TYPE_VECTOR_SUBPARTS (type0),
14739 : TYPE_VECTOR_SUBPARTS (type1)))
14740 : {
14741 : result_type = type0;
14742 : converted = 1;
14743 : }
14744 232972 : else if ((code0 == INTEGER_TYPE || code0 == FIXED_POINT_TYPE
14745 1160 : || code0 == BITINT_TYPE
14746 587 : || (gnu_vector_type_p (type0)
14747 583 : && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE))
14748 234125 : && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
14749 : {
14750 232963 : doing_shift = true;
14751 232963 : if (TREE_CODE (op1) == INTEGER_CST)
14752 : {
14753 203375 : if (tree_int_cst_sgn (op1) < 0)
14754 : {
14755 269 : int_const = false;
14756 269 : if (c_inhibit_evaluation_warnings == 0)
14757 129 : warning_at (location, OPT_Wshift_count_negative,
14758 : "right shift count is negative");
14759 : }
14760 203106 : else if (code0 == VECTOR_TYPE)
14761 : {
14762 479 : if (compare_tree_int (op1,
14763 479 : TYPE_PRECISION (TREE_TYPE (type0)))
14764 : >= 0)
14765 : {
14766 16 : int_const = false;
14767 16 : if (c_inhibit_evaluation_warnings == 0)
14768 16 : warning_at (location, OPT_Wshift_count_overflow,
14769 : "right shift count >= width of vector element");
14770 : }
14771 : }
14772 : else
14773 : {
14774 202627 : if (!integer_zerop (op1))
14775 202265 : short_shift = 1;
14776 :
14777 202627 : if (compare_tree_int (op1, TYPE_PRECISION (type0)) >= 0)
14778 : {
14779 586 : int_const = false;
14780 586 : if (c_inhibit_evaluation_warnings == 0)
14781 52 : warning_at (location, OPT_Wshift_count_overflow,
14782 : "right shift count >= width of type");
14783 : }
14784 : }
14785 : }
14786 :
14787 : /* Use the type of the value to be shifted. */
14788 : result_type = type0;
14789 : /* Avoid converting op1 to result_type later. */
14790 : converted = 1;
14791 : }
14792 : break;
14793 :
14794 807719 : case LSHIFT_EXPR:
14795 807719 : if (gnu_vector_type_p (type0)
14796 598 : && gnu_vector_type_p (type1)
14797 316 : && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
14798 314 : && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE
14799 808032 : && known_eq (TYPE_VECTOR_SUBPARTS (type0),
14800 : TYPE_VECTOR_SUBPARTS (type1)))
14801 : {
14802 : result_type = type0;
14803 : converted = 1;
14804 : }
14805 807408 : else if ((code0 == INTEGER_TYPE || code0 == FIXED_POINT_TYPE
14806 801 : || code0 == BITINT_TYPE
14807 293 : || (gnu_vector_type_p (type0)
14808 287 : && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE))
14809 808200 : && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
14810 : {
14811 807394 : doing_shift = true;
14812 807394 : if (TREE_CODE (op0) == INTEGER_CST
14813 441368 : && tree_int_cst_sgn (op0) < 0
14814 808143 : && !TYPE_OVERFLOW_WRAPS (type0))
14815 : {
14816 : /* Don't reject a left shift of a negative value in a context
14817 : where a constant expression is needed in C90. */
14818 712 : if (flag_isoc99)
14819 666 : int_const = false;
14820 712 : if (c_inhibit_evaluation_warnings == 0)
14821 712 : warning_at (location, OPT_Wshift_negative_value,
14822 : "left shift of negative value");
14823 : }
14824 807394 : if (TREE_CODE (op1) == INTEGER_CST)
14825 : {
14826 734684 : if (tree_int_cst_sgn (op1) < 0)
14827 : {
14828 313 : int_const = false;
14829 313 : if (c_inhibit_evaluation_warnings == 0)
14830 135 : warning_at (location, OPT_Wshift_count_negative,
14831 : "left shift count is negative");
14832 : }
14833 734371 : else if (code0 == VECTOR_TYPE)
14834 : {
14835 216 : if (compare_tree_int (op1,
14836 216 : TYPE_PRECISION (TREE_TYPE (type0)))
14837 : >= 0)
14838 : {
14839 6 : int_const = false;
14840 6 : if (c_inhibit_evaluation_warnings == 0)
14841 6 : warning_at (location, OPT_Wshift_count_overflow,
14842 : "left shift count >= width of vector element");
14843 : }
14844 : }
14845 734155 : else if (compare_tree_int (op1, TYPE_PRECISION (type0)) >= 0)
14846 : {
14847 29733 : int_const = false;
14848 29733 : if (c_inhibit_evaluation_warnings == 0)
14849 113 : warning_at (location, OPT_Wshift_count_overflow,
14850 : "left shift count >= width of type");
14851 : }
14852 704422 : else if (TREE_CODE (op0) == INTEGER_CST
14853 367475 : && maybe_warn_shift_overflow (location, op0, op1)
14854 705049 : && flag_isoc99)
14855 : int_const = false;
14856 : }
14857 :
14858 : /* Use the type of the value to be shifted. */
14859 : result_type = type0;
14860 : /* Avoid converting op1 to result_type later. */
14861 : converted = 1;
14862 : }
14863 : break;
14864 :
14865 1751521 : case EQ_EXPR:
14866 1751521 : case NE_EXPR:
14867 1751521 : if (gnu_vector_type_p (type0) && gnu_vector_type_p (type1))
14868 : {
14869 42105 : tree intt;
14870 42105 : if (!vector_types_compatible_elements_p (type0, type1))
14871 : {
14872 4 : error_at (location, "comparing vectors with different "
14873 : "element types");
14874 4 : return error_mark_node;
14875 : }
14876 :
14877 42101 : if (maybe_ne (TYPE_VECTOR_SUBPARTS (type0),
14878 84202 : TYPE_VECTOR_SUBPARTS (type1)))
14879 : {
14880 1 : error_at (location, "comparing vectors with different "
14881 : "number of elements");
14882 1 : return error_mark_node;
14883 : }
14884 :
14885 : /* It's not precisely specified how the usual arithmetic
14886 : conversions apply to the vector types. Here, we use
14887 : the unsigned type if one of the operands is signed and
14888 : the other one is unsigned. */
14889 42100 : if (TYPE_UNSIGNED (type0) != TYPE_UNSIGNED (type1))
14890 : {
14891 4 : if (!TYPE_UNSIGNED (type0))
14892 4 : op0 = build1 (VIEW_CONVERT_EXPR, type1, op0);
14893 : else
14894 0 : op1 = build1 (VIEW_CONVERT_EXPR, type0, op1);
14895 4 : warning_at (location, OPT_Wsign_compare, "comparison between "
14896 : "types %qT and %qT", type0, type1);
14897 : }
14898 :
14899 : /* Always construct signed integer vector type. */
14900 42100 : if (VECTOR_BOOLEAN_TYPE_P (type0) && VECTOR_BOOLEAN_TYPE_P (type1))
14901 : result_type = type0;
14902 : else
14903 : {
14904 42100 : auto nelts = TYPE_VECTOR_SUBPARTS (type0);
14905 :
14906 126300 : intt = c_common_type_for_size (GET_MODE_BITSIZE
14907 84200 : (SCALAR_TYPE_MODE
14908 : (TREE_TYPE (type0))), 0);
14909 42100 : if (!intt)
14910 : {
14911 0 : error_at (location, "could not find an integer type "
14912 : "of the same size as %qT",
14913 0 : TREE_TYPE (type0));
14914 0 : return error_mark_node;
14915 : }
14916 42100 : result_type = build_opaque_vector_type (intt, nelts);
14917 : }
14918 42100 : converted = 1;
14919 42100 : ret = build_vec_cmp (resultcode, result_type, op0, op1);
14920 42100 : goto return_build_binary_op;
14921 : }
14922 1709416 : if (FLOAT_TYPE_P (type0) || FLOAT_TYPE_P (type1))
14923 254873 : warning_at (location,
14924 254873 : OPT_Wfloat_equal,
14925 : "comparing floating-point with %<==%> or %<!=%> is unsafe");
14926 : /* Result of comparison is always int,
14927 : but don't convert the args to int! */
14928 1709416 : build_type = integer_type_node;
14929 1709416 : if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == BITINT_TYPE
14930 159148 : || code0 == FIXED_POINT_TYPE || code0 == COMPLEX_TYPE)
14931 1586017 : && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
14932 : || code1 == BITINT_TYPE
14933 : || code1 == FIXED_POINT_TYPE || code1 == COMPLEX_TYPE))
14934 : short_compare = 1;
14935 123665 : else if (code0 == POINTER_TYPE
14936 123665 : && (code1 == NULLPTR_TYPE
14937 123282 : || null_pointer_constant_p (orig_op1)))
14938 : {
14939 52059 : maybe_warn_for_null_address (location, op0, code);
14940 52059 : result_type = type0;
14941 : }
14942 71606 : else if (code1 == POINTER_TYPE
14943 71606 : && (code0 == NULLPTR_TYPE
14944 71504 : || null_pointer_constant_p (orig_op0)))
14945 : {
14946 294 : maybe_warn_for_null_address (location, op1, code);
14947 294 : result_type = type1;
14948 : }
14949 71312 : else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
14950 : {
14951 71222 : tree tt0 = TREE_TYPE (type0);
14952 71222 : tree tt1 = TREE_TYPE (type1);
14953 71222 : addr_space_t as0 = TYPE_ADDR_SPACE (tt0);
14954 71222 : addr_space_t as1 = TYPE_ADDR_SPACE (tt1);
14955 71222 : addr_space_t as_common = ADDR_SPACE_GENERIC;
14956 :
14957 : /* Anything compares with void *. void * compares with anything.
14958 : Otherwise, the targets must be compatible
14959 : and both must be object or both incomplete. */
14960 71222 : if (comp_target_types (location, type0, type1))
14961 49859 : result_type = common_pointer_type (type0, type1, NULL_TREE);
14962 21363 : else if (!addr_space_superset (as0, as1, &as_common))
14963 : {
14964 0 : error_at (location, "comparison of pointers to "
14965 : "disjoint address spaces");
14966 0 : return error_mark_node;
14967 : }
14968 21363 : else if (VOID_TYPE_P (tt0) && !TYPE_ATOMIC (tt0))
14969 : {
14970 21111 : if (pedantic && TREE_CODE (tt1) == FUNCTION_TYPE)
14971 4 : pedwarn (location, OPT_Wpedantic, "ISO C forbids "
14972 : "comparison of %<void *%> with function pointer");
14973 : }
14974 252 : else if (VOID_TYPE_P (tt1) && !TYPE_ATOMIC (tt1))
14975 : {
14976 204 : if (pedantic && TREE_CODE (tt0) == FUNCTION_TYPE)
14977 4 : pedwarn (location, OPT_Wpedantic, "ISO C forbids "
14978 : "comparison of %<void *%> with function pointer");
14979 : }
14980 : else
14981 : /* Avoid warning about the volatile ObjC EH puts on decls. */
14982 48 : if (!objc_ok)
14983 48 : pedwarn (location, OPT_Wcompare_distinct_pointer_types,
14984 : "comparison of distinct pointer types lacks a cast");
14985 :
14986 49915 : if (result_type == NULL_TREE)
14987 : {
14988 21363 : int qual = ENCODE_QUAL_ADDR_SPACE (as_common);
14989 21363 : result_type = c_build_pointer_type
14990 21363 : (c_build_qualified_type (void_type_node, qual));
14991 : }
14992 : }
14993 90 : else if (code0 == POINTER_TYPE
14994 26 : && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
14995 : {
14996 26 : result_type = type0;
14997 26 : pedwarn (location, 0, "comparison between pointer and integer");
14998 : }
14999 64 : else if ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE)
15000 21 : && code1 == POINTER_TYPE)
15001 : {
15002 8 : result_type = type1;
15003 8 : pedwarn (location, 0, "comparison between pointer and integer");
15004 : }
15005 : /* 6.5.9: One of the following shall hold:
15006 : -- both operands have type nullptr_t; */
15007 56 : else if (code0 == NULLPTR_TYPE && code1 == NULLPTR_TYPE)
15008 : {
15009 22 : result_type = nullptr_type_node;
15010 : /* No need to convert the operands to result_type later. */
15011 22 : converted = 1;
15012 : }
15013 : /* -- one operand has type nullptr_t and the other is a null pointer
15014 : constant. We will have to convert the former to the type of the
15015 : latter, because during gimplification we can't have mismatching
15016 : comparison operand type. We convert from nullptr_t to the other
15017 : type, since only nullptr_t can be converted to nullptr_t. Also,
15018 : even a constant 0 is a null pointer constant, so we may have to
15019 : create a pointer type from its type. */
15020 34 : else if (code0 == NULLPTR_TYPE && null_pointer_constant_p (orig_op1))
15021 19 : result_type = (INTEGRAL_TYPE_P (type1)
15022 19 : ? c_build_pointer_type (type1) : type1);
15023 15 : else if (code1 == NULLPTR_TYPE && null_pointer_constant_p (orig_op0))
15024 11 : result_type = (INTEGRAL_TYPE_P (type0)
15025 11 : ? c_build_pointer_type (type0) : type0);
15026 5052939 : if ((C_BOOLEAN_TYPE_P (TREE_TYPE (orig_op0))
15027 3343498 : || truth_value_p (TREE_CODE (orig_op0)))
15028 3411400 : ^ (C_BOOLEAN_TYPE_P (TREE_TYPE (orig_op1))
15029 3411396 : || truth_value_p (TREE_CODE (orig_op1))))
15030 72194 : maybe_warn_bool_compare (location, code, orig_op0, orig_op1);
15031 : break;
15032 :
15033 1010489 : case LE_EXPR:
15034 1010489 : case GE_EXPR:
15035 1010489 : case LT_EXPR:
15036 1010489 : case GT_EXPR:
15037 1010489 : if (gnu_vector_type_p (type0) && gnu_vector_type_p (type1))
15038 : {
15039 59444 : tree intt;
15040 59444 : if (!vector_types_compatible_elements_p (type0, type1))
15041 : {
15042 5 : error_at (location, "comparing vectors with different "
15043 : "element types");
15044 5 : return error_mark_node;
15045 : }
15046 :
15047 59439 : if (maybe_ne (TYPE_VECTOR_SUBPARTS (type0),
15048 118878 : TYPE_VECTOR_SUBPARTS (type1)))
15049 : {
15050 0 : error_at (location, "comparing vectors with different "
15051 : "number of elements");
15052 0 : return error_mark_node;
15053 : }
15054 :
15055 : /* It's not precisely specified how the usual arithmetic
15056 : conversions apply to the vector types. Here, we use
15057 : the unsigned type if one of the operands is signed and
15058 : the other one is unsigned. */
15059 59439 : if (TYPE_UNSIGNED (type0) != TYPE_UNSIGNED (type1))
15060 : {
15061 15 : if (!TYPE_UNSIGNED (type0))
15062 8 : op0 = build1 (VIEW_CONVERT_EXPR, type1, op0);
15063 : else
15064 7 : op1 = build1 (VIEW_CONVERT_EXPR, type0, op1);
15065 15 : warning_at (location, OPT_Wsign_compare, "comparison between "
15066 : "types %qT and %qT", type0, type1);
15067 : }
15068 :
15069 : /* Always construct signed integer vector type. */
15070 178317 : intt = c_common_type_for_size (GET_MODE_BITSIZE
15071 118878 : (SCALAR_TYPE_MODE
15072 : (TREE_TYPE (type0))), 0);
15073 59439 : if (!intt)
15074 : {
15075 0 : error_at (location, "could not find an integer type "
15076 : "of the same size as %qT",
15077 0 : TREE_TYPE (type0));
15078 0 : return error_mark_node;
15079 : }
15080 59439 : result_type = build_opaque_vector_type (intt,
15081 59439 : TYPE_VECTOR_SUBPARTS (type0));
15082 59439 : converted = 1;
15083 59439 : ret = build_vec_cmp (resultcode, result_type, op0, op1);
15084 59439 : goto return_build_binary_op;
15085 : }
15086 951045 : build_type = integer_type_node;
15087 951045 : if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
15088 65199 : || code0 == BITINT_TYPE || code0 == FIXED_POINT_TYPE)
15089 886449 : && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
15090 : || code1 == BITINT_TYPE || code1 == FIXED_POINT_TYPE))
15091 : short_compare = 1;
15092 64628 : else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
15093 : {
15094 64561 : addr_space_t as0 = TYPE_ADDR_SPACE (TREE_TYPE (type0));
15095 64561 : addr_space_t as1 = TYPE_ADDR_SPACE (TREE_TYPE (type1));
15096 64561 : addr_space_t as_common;
15097 :
15098 64561 : if (comp_target_types (location, type0, type1))
15099 : {
15100 64396 : result_type = common_pointer_type (type0, type1, NULL_TREE);
15101 64396 : if (!COMPLETE_TYPE_P (TREE_TYPE (type0))
15102 64396 : != !COMPLETE_TYPE_P (TREE_TYPE (type1)))
15103 32 : pedwarn_c99 (location, OPT_Wpedantic,
15104 : "comparison of complete and incomplete pointers");
15105 64364 : else if (TREE_CODE (TREE_TYPE (type0)) == FUNCTION_TYPE)
15106 0 : pedwarn (location, OPT_Wpedantic, "ISO C forbids "
15107 : "ordered comparisons of pointers to functions");
15108 64364 : else if (null_pointer_constant_p (orig_op0)
15109 64364 : || null_pointer_constant_p (orig_op1))
15110 8 : warning_at (location, OPT_Wextra,
15111 : "ordered comparison of pointer with null pointer");
15112 :
15113 : }
15114 165 : else if (!addr_space_superset (as0, as1, &as_common))
15115 : {
15116 0 : error_at (location, "comparison of pointers to "
15117 : "disjoint address spaces");
15118 0 : return error_mark_node;
15119 : }
15120 : else
15121 : {
15122 165 : int qual = ENCODE_QUAL_ADDR_SPACE (as_common);
15123 165 : result_type = c_build_pointer_type
15124 165 : (c_build_qualified_type (void_type_node, qual));
15125 165 : pedwarn (location, OPT_Wcompare_distinct_pointer_types,
15126 : "comparison of distinct pointer types lacks a cast");
15127 : }
15128 : }
15129 67 : else if (code0 == POINTER_TYPE && null_pointer_constant_p (orig_op1))
15130 : {
15131 17 : result_type = type0;
15132 17 : if (pedantic)
15133 11 : pedwarn (location, OPT_Wpedantic,
15134 : "ordered comparison of pointer with integer zero");
15135 6 : else if (extra_warnings)
15136 1 : warning_at (location, OPT_Wextra,
15137 : "ordered comparison of pointer with integer zero");
15138 : }
15139 50 : else if (code1 == POINTER_TYPE && null_pointer_constant_p (orig_op0))
15140 : {
15141 12 : result_type = type1;
15142 12 : if (pedantic)
15143 2 : pedwarn (location, OPT_Wpedantic,
15144 : "ordered comparison of pointer with integer zero");
15145 10 : else if (extra_warnings)
15146 1 : warning_at (location, OPT_Wextra,
15147 : "ordered comparison of pointer with integer zero");
15148 : }
15149 38 : else if (code0 == POINTER_TYPE
15150 18 : && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
15151 : {
15152 18 : result_type = type0;
15153 18 : pedwarn (location, 0, "comparison between pointer and integer");
15154 : }
15155 20 : else if ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE)
15156 20 : && code1 == POINTER_TYPE)
15157 : {
15158 18 : result_type = type1;
15159 18 : pedwarn (location, 0, "comparison between pointer and integer");
15160 : }
15161 :
15162 951045 : if ((code0 == POINTER_TYPE || code1 == POINTER_TYPE)
15163 64626 : && current_function_decl != NULL_TREE
15164 1015660 : && sanitize_flags_p (SANITIZE_POINTER_COMPARE))
15165 : {
15166 35 : op0 = save_expr (c_fully_fold (op0, false, NULL));
15167 35 : op1 = save_expr (c_fully_fold (op1, false, NULL));
15168 :
15169 35 : tree tt = builtin_decl_explicit (BUILT_IN_ASAN_POINTER_COMPARE);
15170 35 : instrument_expr = build_call_expr_loc (location, tt, 2, op0, op1);
15171 : }
15172 :
15173 2853037 : if ((C_BOOLEAN_TYPE_P (TREE_TYPE (orig_op0))
15174 1901992 : || truth_value_p (TREE_CODE (orig_op0)))
15175 1902009 : ^ (C_BOOLEAN_TYPE_P (TREE_TYPE (orig_op1))
15176 1902009 : || truth_value_p (TREE_CODE (orig_op1))))
15177 526 : maybe_warn_bool_compare (location, code, orig_op0, orig_op1);
15178 : break;
15179 :
15180 43 : case MIN_EXPR:
15181 43 : case MAX_EXPR:
15182 : /* Used for OpenMP atomics. */
15183 43 : gcc_assert (flag_openmp);
15184 : common = 1;
15185 : break;
15186 :
15187 0 : default:
15188 0 : gcc_unreachable ();
15189 : }
15190 :
15191 15613094 : if (code0 == ERROR_MARK || code1 == ERROR_MARK)
15192 0 : return error_mark_node;
15193 :
15194 15613094 : if (gnu_vector_type_p (type0)
15195 1486911 : && gnu_vector_type_p (type1)
15196 17099143 : && (!tree_int_cst_equal (TYPE_SIZE (type0), TYPE_SIZE (type1))
15197 1486029 : || !vector_types_compatible_elements_p (type0, type1)))
15198 : {
15199 26 : gcc_rich_location richloc (location);
15200 26 : maybe_range_label_for_tree_type_mismatch
15201 26 : label_for_op0 (orig_op0, orig_op1),
15202 26 : label_for_op1 (orig_op1, orig_op0);
15203 26 : richloc.maybe_add_expr (orig_op0, &label_for_op0, highlight_colors::lhs);
15204 26 : richloc.maybe_add_expr (orig_op1, &label_for_op1, highlight_colors::rhs);
15205 26 : binary_op_error (&richloc, code, type0, type1);
15206 26 : return error_mark_node;
15207 26 : }
15208 :
15209 15613068 : if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == COMPLEX_TYPE
15210 1744409 : || code0 == FIXED_POINT_TYPE || code0 == BITINT_TYPE
15211 1675295 : || gnu_vector_type_p (type0))
15212 17169067 : && (code1 == INTEGER_TYPE || code1 == REAL_TYPE || code1 == COMPLEX_TYPE
15213 1580581 : || code1 == FIXED_POINT_TYPE || code1 == BITINT_TYPE
15214 1488157 : || gnu_vector_type_p (type1)))
15215 : {
15216 15422529 : bool first_complex = (code0 == COMPLEX_TYPE);
15217 15422529 : bool second_complex = (code1 == COMPLEX_TYPE);
15218 15422529 : int none_complex = (!first_complex && !second_complex);
15219 :
15220 15422529 : if (shorten || common || short_compare)
15221 : {
15222 13870578 : result_type = c_common_type (type0, type1);
15223 13870578 : do_warn_double_promotion (result_type, type0, type1,
15224 : "implicit conversion from %qT to %qT "
15225 : "to match other operand of binary "
15226 : "expression",
15227 : location);
15228 13870578 : if (result_type == error_mark_node)
15229 : return error_mark_node;
15230 : }
15231 :
15232 15422507 : if (first_complex != second_complex
15233 82085 : && (code == PLUS_EXPR
15234 : || code == MINUS_EXPR
15235 82085 : || code == MULT_EXPR
15236 17533 : || (code == TRUNC_DIV_EXPR && first_complex))
15237 65973 : && TREE_CODE (TREE_TYPE (result_type)) == REAL_TYPE
15238 15484762 : && flag_signed_zeros)
15239 : {
15240 : /* An operation on mixed real/complex operands must be
15241 : handled specially, but the language-independent code can
15242 : more easily optimize the plain complex arithmetic if
15243 : -fno-signed-zeros. */
15244 61943 : tree real_type = TREE_TYPE (result_type);
15245 61943 : tree real, imag;
15246 61943 : if (type0 != orig_type0 || type1 != orig_type1)
15247 : {
15248 94 : gcc_assert (may_need_excess_precision && common);
15249 94 : semantic_result_type = c_common_type (orig_type0, orig_type1);
15250 : }
15251 61943 : if (first_complex)
15252 : {
15253 8253 : if (TREE_TYPE (op0) != result_type)
15254 1787 : op0 = convert_and_check (location, result_type, op0);
15255 8253 : if (TREE_TYPE (op1) != real_type)
15256 4601 : op1 = convert_and_check (location, real_type, op1);
15257 : }
15258 : else
15259 : {
15260 53690 : if (TREE_TYPE (op0) != real_type)
15261 2698 : op0 = convert_and_check (location, real_type, op0);
15262 53690 : if (TREE_TYPE (op1) != result_type)
15263 1866 : op1 = convert_and_check (location, result_type, op1);
15264 : }
15265 61943 : if (TREE_CODE (op0) == ERROR_MARK || TREE_CODE (op1) == ERROR_MARK)
15266 0 : return error_mark_node;
15267 61943 : if (first_complex)
15268 : {
15269 8253 : op0 = save_expr (op0);
15270 8253 : real = build_unary_op (EXPR_LOCATION (orig_op0), REALPART_EXPR,
15271 : op0, true);
15272 8253 : imag = build_unary_op (EXPR_LOCATION (orig_op0), IMAGPART_EXPR,
15273 : op0, true);
15274 8253 : switch (code)
15275 : {
15276 3488 : case MULT_EXPR:
15277 3488 : case TRUNC_DIV_EXPR:
15278 3488 : op1 = save_expr (op1);
15279 3488 : imag = build2 (resultcode, real_type, imag, op1);
15280 : /* Fall through. */
15281 8253 : case PLUS_EXPR:
15282 8253 : case MINUS_EXPR:
15283 8253 : real = build2 (resultcode, real_type, real, op1);
15284 8253 : break;
15285 : default:
15286 : gcc_unreachable();
15287 : }
15288 : }
15289 : else
15290 : {
15291 53690 : op1 = save_expr (op1);
15292 53690 : real = build_unary_op (EXPR_LOCATION (orig_op1), REALPART_EXPR,
15293 : op1, true);
15294 53690 : imag = build_unary_op (EXPR_LOCATION (orig_op1), IMAGPART_EXPR,
15295 : op1, true);
15296 53690 : switch (code)
15297 : {
15298 2008 : case MULT_EXPR:
15299 2008 : op0 = save_expr (op0);
15300 2008 : imag = build2 (resultcode, real_type, op0, imag);
15301 : /* Fall through. */
15302 31958 : case PLUS_EXPR:
15303 31958 : real = build2 (resultcode, real_type, op0, real);
15304 31958 : break;
15305 21732 : case MINUS_EXPR:
15306 21732 : real = build2 (resultcode, real_type, op0, real);
15307 21732 : imag = build1 (NEGATE_EXPR, real_type, imag);
15308 21732 : break;
15309 0 : default:
15310 0 : gcc_unreachable();
15311 : }
15312 : }
15313 61943 : ret = build2 (COMPLEX_EXPR, result_type, real, imag);
15314 61943 : goto return_build_binary_op;
15315 : }
15316 :
15317 : /* For certain operations (which identify themselves by shorten != 0)
15318 : if both args were extended from the same smaller type,
15319 : do the arithmetic in that type and then extend.
15320 :
15321 : shorten !=0 and !=1 indicates a bitwise operation.
15322 : For them, this optimization is safe only if
15323 : both args are zero-extended or both are sign-extended.
15324 : Otherwise, we might change the result.
15325 : Eg, (short)-1 | (unsigned short)-1 is (int)-1
15326 : but calculated in (unsigned short) it would be (unsigned short)-1. */
15327 :
15328 15360564 : if (shorten && none_complex)
15329 : {
15330 1304065 : final_type = result_type;
15331 1304065 : result_type = shorten_binary_op (result_type, op0, op1,
15332 : shorten == -1);
15333 : }
15334 :
15335 : /* Shifts can be shortened if shifting right. */
15336 :
15337 15360564 : if (short_shift)
15338 : {
15339 202265 : int unsigned_arg;
15340 202265 : tree arg0 = get_narrower (op0, &unsigned_arg);
15341 :
15342 202265 : final_type = result_type;
15343 :
15344 202265 : if (arg0 == op0 && final_type == TREE_TYPE (op0))
15345 142459 : unsigned_arg = TYPE_UNSIGNED (TREE_TYPE (op0));
15346 :
15347 202265 : if (TYPE_PRECISION (TREE_TYPE (arg0)) < TYPE_PRECISION (result_type)
15348 3005 : && tree_int_cst_sgn (op1) > 0
15349 : /* We can shorten only if the shift count is less than the
15350 : number of bits in the smaller type size. */
15351 3005 : && compare_tree_int (op1, TYPE_PRECISION (TREE_TYPE (arg0))) < 0
15352 : /* We cannot drop an unsigned shift after sign-extension. */
15353 205130 : && (!TYPE_UNSIGNED (final_type) || unsigned_arg))
15354 : {
15355 : /* Do an unsigned shift if the operand was zero-extended. */
15356 2850 : result_type
15357 2850 : = c_common_signed_or_unsigned_type (unsigned_arg,
15358 2850 : TREE_TYPE (arg0));
15359 : /* Convert value-to-be-shifted to that type. */
15360 2850 : if (TREE_TYPE (op0) != result_type)
15361 2850 : op0 = convert (result_type, op0);
15362 : converted = 1;
15363 : }
15364 : }
15365 :
15366 : /* Comparison operations are shortened too but differently.
15367 : They identify themselves by setting short_compare = 1. */
15368 :
15369 15360564 : if (short_compare)
15370 : {
15371 : /* Don't write &op0, etc., because that would prevent op0
15372 : from being kept in a register.
15373 : Instead, make copies of the our local variables and
15374 : pass the copies by reference, then copy them back afterward. */
15375 2472166 : tree xop0 = op0, xop1 = op1, xresult_type = result_type;
15376 2472166 : enum tree_code xresultcode = resultcode;
15377 2472166 : tree val
15378 2472166 : = shorten_compare (location, &xop0, &xop1, &xresult_type,
15379 : &xresultcode);
15380 :
15381 2472166 : if (val != NULL_TREE)
15382 : {
15383 15889 : ret = val;
15384 15889 : goto return_build_binary_op;
15385 : }
15386 :
15387 2456277 : op0 = xop0, op1 = xop1;
15388 2456277 : converted = 1;
15389 2456277 : resultcode = xresultcode;
15390 :
15391 2456277 : if (c_inhibit_evaluation_warnings == 0 && !c_in_omp_for)
15392 : {
15393 2308739 : bool op0_maybe_const = true;
15394 2308739 : bool op1_maybe_const = true;
15395 2308739 : tree orig_op0_folded, orig_op1_folded;
15396 :
15397 2308739 : if (in_late_binary_op)
15398 : {
15399 : orig_op0_folded = orig_op0;
15400 : orig_op1_folded = orig_op1;
15401 : }
15402 : else
15403 : {
15404 : /* Fold for the sake of possible warnings, as in
15405 : build_conditional_expr. This requires the
15406 : "original" values to be folded, not just op0 and
15407 : op1. */
15408 2300084 : c_inhibit_evaluation_warnings++;
15409 2300084 : op0 = c_fully_fold (op0, require_constant_value,
15410 : &op0_maybe_const);
15411 2300084 : op1 = c_fully_fold (op1, require_constant_value,
15412 : &op1_maybe_const);
15413 2300084 : c_inhibit_evaluation_warnings--;
15414 2300084 : orig_op0_folded = c_fully_fold (orig_op0,
15415 : require_constant_value,
15416 : NULL);
15417 2300084 : orig_op1_folded = c_fully_fold (orig_op1,
15418 : require_constant_value,
15419 : NULL);
15420 : }
15421 :
15422 2308739 : if (warn_sign_compare)
15423 377562 : warn_for_sign_compare (location, orig_op0_folded,
15424 : orig_op1_folded, op0, op1,
15425 : result_type, resultcode);
15426 2308739 : if (!in_late_binary_op && !int_operands)
15427 : {
15428 2122548 : if (!op0_maybe_const || TREE_CODE (op0) != INTEGER_CST)
15429 2119038 : op0 = c_wrap_maybe_const (op0, !op0_maybe_const);
15430 2122548 : if (!op1_maybe_const || TREE_CODE (op1) != INTEGER_CST)
15431 832385 : op1 = c_wrap_maybe_const (op1, !op1_maybe_const);
15432 : }
15433 : }
15434 : }
15435 : }
15436 :
15437 : /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
15438 : If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
15439 : Then the expression will be built.
15440 : It will be given type FINAL_TYPE if that is nonzero;
15441 : otherwise, it will be given type RESULT_TYPE. */
15442 :
15443 15535214 : if (!result_type)
15444 : {
15445 : /* Favor showing any expression locations that are available. */
15446 514 : op_location_t oploc (location, UNKNOWN_LOCATION);
15447 514 : binary_op_rich_location richloc (oploc, orig_op0, orig_op1, true);
15448 514 : binary_op_error (&richloc, code, TREE_TYPE (op0), TREE_TYPE (op1));
15449 514 : return error_mark_node;
15450 514 : }
15451 :
15452 15534700 : if (build_type == NULL_TREE)
15453 : {
15454 12890136 : build_type = result_type;
15455 12890136 : if ((type0 != orig_type0 || type1 != orig_type1)
15456 797 : && !boolean_op)
15457 : {
15458 797 : gcc_assert (may_need_excess_precision && common);
15459 797 : semantic_result_type = c_common_type (orig_type0, orig_type1);
15460 : }
15461 : }
15462 :
15463 15534700 : if (!converted)
15464 : {
15465 11523456 : op0 = ep_convert_and_check (location, result_type, op0,
15466 : semantic_result_type);
15467 11523456 : op1 = ep_convert_and_check (location, result_type, op1,
15468 : semantic_result_type);
15469 :
15470 : /* This can happen if one operand has a vector type, and the other
15471 : has a different type. */
15472 11523456 : if (TREE_CODE (op0) == ERROR_MARK || TREE_CODE (op1) == ERROR_MARK)
15473 3 : return error_mark_node;
15474 : }
15475 :
15476 15534697 : if (sanitize_flags_p ((SANITIZE_SHIFT
15477 : | SANITIZE_DIVIDE
15478 : | SANITIZE_FLOAT_DIVIDE
15479 : | SANITIZE_SI_OVERFLOW))
15480 23437 : && current_function_decl != NULL_TREE
15481 19967 : && (doing_div_or_mod || doing_shift)
15482 15537628 : && !require_constant_value)
15483 : {
15484 : /* OP0 and/or OP1 might have side-effects. */
15485 2875 : op0 = save_expr (op0);
15486 2875 : op1 = save_expr (op1);
15487 2875 : op0 = c_fully_fold (op0, false, NULL);
15488 2875 : op1 = c_fully_fold (op1, false, NULL);
15489 2875 : if (doing_div_or_mod && (sanitize_flags_p ((SANITIZE_DIVIDE
15490 : | SANITIZE_FLOAT_DIVIDE
15491 : | SANITIZE_SI_OVERFLOW))))
15492 916 : instrument_expr = ubsan_instrument_division (location, op0, op1);
15493 1959 : else if (doing_shift && sanitize_flags_p (SANITIZE_SHIFT))
15494 1778 : instrument_expr = ubsan_instrument_shift (location, code, op0, op1);
15495 : }
15496 :
15497 : /* Treat expressions in initializers specially as they can't trap. */
15498 15534697 : if (int_const_or_overflow)
15499 8024859 : ret = (require_constant_value
15500 8024859 : ? fold_build2_initializer_loc (location, resultcode, build_type,
15501 : op0, op1)
15502 7978652 : : fold_build2_loc (location, resultcode, build_type, op0, op1));
15503 : else
15504 7509838 : ret = build2 (resultcode, build_type, op0, op1);
15505 15534697 : if (final_type != NULL_TREE)
15506 1506330 : ret = convert (final_type, ret);
15507 :
15508 14028367 : return_build_binary_op:
15509 16994079 : gcc_assert (ret != error_mark_node);
15510 16994079 : if (TREE_CODE (ret) == INTEGER_CST && !TREE_OVERFLOW (ret) && !int_const)
15511 1853 : ret = (int_operands
15512 1853 : ? note_integer_operands (ret)
15513 532 : : build1 (NOP_EXPR, TREE_TYPE (ret), ret));
15514 16992226 : else if (TREE_CODE (ret) != INTEGER_CST && int_operands
15515 60311 : && !in_late_binary_op)
15516 60311 : ret = note_integer_operands (ret);
15517 16994079 : protected_set_expr_location (ret, location);
15518 :
15519 16994079 : if (instrument_expr != NULL)
15520 1425 : ret = fold_build2 (COMPOUND_EXPR, TREE_TYPE (ret),
15521 : instrument_expr, ret);
15522 :
15523 16994079 : if (semantic_result_type)
15524 891 : ret = build1_loc (location, EXCESS_PRECISION_EXPR,
15525 : semantic_result_type, ret);
15526 :
15527 : return ret;
15528 : }
15529 :
15530 :
15531 : /* Convert EXPR to be a truth-value (type TYPE), validating its type for this
15532 : purpose. LOCATION is the source location for the expression. */
15533 :
15534 : tree
15535 4159319 : c_objc_common_truthvalue_conversion (location_t location, tree expr, tree type)
15536 : {
15537 4159319 : bool int_const, int_operands;
15538 :
15539 4159319 : switch (TREE_CODE (TREE_TYPE (expr)))
15540 : {
15541 72 : case ARRAY_TYPE:
15542 72 : error_at (location, "used array that cannot be converted to pointer where scalar is required");
15543 72 : return error_mark_node;
15544 :
15545 86 : case RECORD_TYPE:
15546 86 : error_at (location, "used struct type value where scalar is required");
15547 86 : return error_mark_node;
15548 :
15549 83 : case UNION_TYPE:
15550 83 : error_at (location, "used union type value where scalar is required");
15551 83 : return error_mark_node;
15552 :
15553 22 : case VOID_TYPE:
15554 22 : error_at (location, "void value not ignored as it ought to be");
15555 22 : return error_mark_node;
15556 :
15557 31022 : case POINTER_TYPE:
15558 31022 : if (reject_gcc_builtin (expr))
15559 3 : return error_mark_node;
15560 : break;
15561 :
15562 0 : case FUNCTION_TYPE:
15563 0 : gcc_unreachable ();
15564 :
15565 8 : case VECTOR_TYPE:
15566 8 : error_at (location, "used vector type where scalar is required");
15567 8 : return error_mark_node;
15568 :
15569 : default:
15570 : break;
15571 : }
15572 :
15573 : /* Conversion of a floating constant to boolean goes through here
15574 : and yields an integer constant expression. Otherwise, the result
15575 : is only an integer constant expression if the argument is. */
15576 899889 : int_const = ((TREE_CODE (expr) == INTEGER_CST && !TREE_OVERFLOW (expr))
15577 4159121 : || ((TREE_CODE (expr) == REAL_CST
15578 3258858 : || TREE_CODE (expr) == COMPLEX_CST)
15579 374 : && (TREE_CODE (type) == BOOLEAN_TYPE
15580 15 : || (TREE_CODE (type) == ENUMERAL_TYPE
15581 5 : && ENUM_UNDERLYING_TYPE (type) != NULL_TREE
15582 5 : && (TREE_CODE (ENUM_UNDERLYING_TYPE (type))
15583 : == BOOLEAN_TYPE)))));
15584 4159045 : int_operands = EXPR_INT_CONST_OPERANDS (expr);
15585 900049 : if (int_operands && TREE_CODE (expr) != INTEGER_CST)
15586 : {
15587 319 : expr = remove_c_maybe_const_expr (expr);
15588 319 : expr = build2 (NE_EXPR, type, expr,
15589 319 : convert (TREE_TYPE (expr), integer_zero_node));
15590 319 : expr = note_integer_operands (expr);
15591 : }
15592 : else
15593 : {
15594 : /* ??? Should we also give an error for vectors rather than leaving
15595 : those to give errors later? */
15596 4158726 : expr = c_common_truthvalue_conversion (location, expr);
15597 4158726 : expr = fold_convert_loc (location, type, expr);
15598 : }
15599 :
15600 4159045 : if (TREE_CODE (expr) == INTEGER_CST && int_operands && !int_const)
15601 : {
15602 76 : if (TREE_OVERFLOW (expr))
15603 : return expr;
15604 : else
15605 76 : return note_integer_operands (expr);
15606 : }
15607 4158969 : if (TREE_CODE (expr) == INTEGER_CST && !int_const)
15608 857 : return build1 (NOP_EXPR, TREE_TYPE (expr), expr);
15609 : return expr;
15610 : }
15611 :
15612 :
15613 : /* Convert EXPR to a contained DECL, updating *TC, *TI and *SE as
15614 : required. */
15615 :
15616 : tree
15617 126632458 : c_expr_to_decl (tree expr, bool *tc ATTRIBUTE_UNUSED, bool *se)
15618 : {
15619 126632458 : if (TREE_CODE (expr) == COMPOUND_LITERAL_EXPR)
15620 : {
15621 706 : tree decl = COMPOUND_LITERAL_EXPR_DECL (expr);
15622 : /* Executing a compound literal inside a function reinitializes
15623 : it. */
15624 706 : if (!TREE_STATIC (decl))
15625 440 : *se = true;
15626 : return decl;
15627 : }
15628 : else
15629 : return expr;
15630 : }
15631 :
15632 : /* Generate OMP construct CODE, with BODY and CLAUSES as its compound
15633 : statement. LOC is the location of the construct. */
15634 :
15635 : tree
15636 2154 : c_finish_omp_construct (location_t loc, enum tree_code code, tree body,
15637 : tree clauses)
15638 : {
15639 2154 : body = c_end_compound_stmt (loc, body, true);
15640 :
15641 2154 : tree stmt = make_node (code);
15642 2154 : TREE_TYPE (stmt) = void_type_node;
15643 2154 : OMP_BODY (stmt) = body;
15644 2154 : OMP_CLAUSES (stmt) = clauses;
15645 2154 : SET_EXPR_LOCATION (stmt, loc);
15646 :
15647 2154 : return add_stmt (stmt);
15648 : }
15649 :
15650 : /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound
15651 : statement. LOC is the location of the OACC_DATA. */
15652 :
15653 : tree
15654 497 : c_finish_oacc_data (location_t loc, tree clauses, tree block)
15655 : {
15656 497 : tree stmt;
15657 :
15658 497 : block = c_end_compound_stmt (loc, block, true);
15659 :
15660 497 : stmt = make_node (OACC_DATA);
15661 497 : TREE_TYPE (stmt) = void_type_node;
15662 497 : OACC_DATA_CLAUSES (stmt) = clauses;
15663 497 : OACC_DATA_BODY (stmt) = block;
15664 497 : SET_EXPR_LOCATION (stmt, loc);
15665 :
15666 497 : return add_stmt (stmt);
15667 : }
15668 :
15669 : /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound
15670 : statement. LOC is the location of the OACC_HOST_DATA. */
15671 :
15672 : tree
15673 21 : c_finish_oacc_host_data (location_t loc, tree clauses, tree block)
15674 : {
15675 21 : tree stmt;
15676 :
15677 21 : block = c_end_compound_stmt (loc, block, true);
15678 :
15679 21 : stmt = make_node (OACC_HOST_DATA);
15680 21 : TREE_TYPE (stmt) = void_type_node;
15681 21 : OACC_HOST_DATA_CLAUSES (stmt) = clauses;
15682 21 : OACC_HOST_DATA_BODY (stmt) = block;
15683 21 : SET_EXPR_LOCATION (stmt, loc);
15684 :
15685 21 : return add_stmt (stmt);
15686 : }
15687 :
15688 : /* Like c_begin_compound_stmt, except force the retention of the BLOCK. */
15689 :
15690 : tree
15691 12031 : c_begin_omp_parallel (void)
15692 : {
15693 12031 : tree block;
15694 :
15695 12031 : keep_next_level ();
15696 12031 : block = c_begin_compound_stmt (true);
15697 :
15698 12031 : return block;
15699 : }
15700 :
15701 : /* Generate OMP_PARALLEL, with CLAUSES and BLOCK as its compound
15702 : statement. LOC is the location of the OMP_PARALLEL. */
15703 :
15704 : tree
15705 5694 : c_finish_omp_parallel (location_t loc, tree clauses, tree block)
15706 : {
15707 5694 : tree stmt;
15708 :
15709 5694 : block = c_end_compound_stmt (loc, block, true);
15710 :
15711 5694 : stmt = make_node (OMP_PARALLEL);
15712 5694 : TREE_TYPE (stmt) = void_type_node;
15713 5694 : OMP_PARALLEL_CLAUSES (stmt) = clauses;
15714 5694 : OMP_PARALLEL_BODY (stmt) = block;
15715 5694 : SET_EXPR_LOCATION (stmt, loc);
15716 :
15717 5694 : return add_stmt (stmt);
15718 : }
15719 :
15720 : /* Like c_begin_compound_stmt, except force the retention of the BLOCK. */
15721 :
15722 : tree
15723 903 : c_begin_omp_task (void)
15724 : {
15725 903 : tree block;
15726 :
15727 903 : keep_next_level ();
15728 903 : block = c_begin_compound_stmt (true);
15729 :
15730 903 : return block;
15731 : }
15732 :
15733 : /* Generate OMP_TASK, with CLAUSES and BLOCK as its compound
15734 : statement. LOC is the location of the #pragma. */
15735 :
15736 : tree
15737 903 : c_finish_omp_task (location_t loc, tree clauses, tree block)
15738 : {
15739 903 : tree stmt;
15740 :
15741 903 : block = c_end_compound_stmt (loc, block, true);
15742 :
15743 903 : stmt = make_node (OMP_TASK);
15744 903 : TREE_TYPE (stmt) = void_type_node;
15745 903 : OMP_TASK_CLAUSES (stmt) = clauses;
15746 903 : OMP_TASK_BODY (stmt) = block;
15747 903 : SET_EXPR_LOCATION (stmt, loc);
15748 :
15749 903 : return add_stmt (stmt);
15750 : }
15751 :
15752 : /* Generate GOMP_cancel call for #pragma omp cancel. */
15753 :
15754 : void
15755 213 : c_finish_omp_cancel (location_t loc, tree clauses)
15756 : {
15757 213 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCEL);
15758 213 : int mask = 0;
15759 213 : if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
15760 : mask = 1;
15761 150 : else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
15762 : mask = 2;
15763 101 : else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
15764 : mask = 4;
15765 58 : else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
15766 : mask = 8;
15767 : else
15768 : {
15769 0 : error_at (loc, "%<#pragma omp cancel%> must specify one of "
15770 : "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> "
15771 : "clauses");
15772 0 : return;
15773 : }
15774 213 : tree ifc = omp_find_clause (clauses, OMP_CLAUSE_IF);
15775 213 : if (ifc != NULL_TREE)
15776 : {
15777 31 : if (OMP_CLAUSE_IF_MODIFIER (ifc) != ERROR_MARK
15778 31 : && OMP_CLAUSE_IF_MODIFIER (ifc) != VOID_CST)
15779 2 : error_at (OMP_CLAUSE_LOCATION (ifc),
15780 : "expected %<cancel%> %<if%> clause modifier");
15781 : else
15782 : {
15783 29 : tree ifc2 = omp_find_clause (OMP_CLAUSE_CHAIN (ifc), OMP_CLAUSE_IF);
15784 29 : if (ifc2 != NULL_TREE)
15785 : {
15786 1 : gcc_assert (OMP_CLAUSE_IF_MODIFIER (ifc) == VOID_CST
15787 : && OMP_CLAUSE_IF_MODIFIER (ifc2) != ERROR_MARK
15788 : && OMP_CLAUSE_IF_MODIFIER (ifc2) != VOID_CST);
15789 1 : error_at (OMP_CLAUSE_LOCATION (ifc2),
15790 : "expected %<cancel%> %<if%> clause modifier");
15791 : }
15792 : }
15793 :
15794 31 : tree type = TREE_TYPE (OMP_CLAUSE_IF_EXPR (ifc));
15795 62 : ifc = fold_build2_loc (OMP_CLAUSE_LOCATION (ifc), NE_EXPR,
15796 31 : boolean_type_node, OMP_CLAUSE_IF_EXPR (ifc),
15797 : build_zero_cst (type));
15798 : }
15799 : else
15800 182 : ifc = boolean_true_node;
15801 213 : tree stmt = build_call_expr_loc (loc, fn, 2,
15802 213 : build_int_cst (integer_type_node, mask),
15803 : ifc);
15804 213 : add_stmt (stmt);
15805 : }
15806 :
15807 : /* Generate GOMP_cancellation_point call for
15808 : #pragma omp cancellation point. */
15809 :
15810 : void
15811 167 : c_finish_omp_cancellation_point (location_t loc, tree clauses)
15812 : {
15813 167 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT);
15814 167 : int mask = 0;
15815 167 : if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
15816 : mask = 1;
15817 123 : else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
15818 : mask = 2;
15819 88 : else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
15820 : mask = 4;
15821 53 : else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
15822 : mask = 8;
15823 : else
15824 : {
15825 1 : error_at (loc, "%<#pragma omp cancellation point%> must specify one of "
15826 : "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> "
15827 : "clauses");
15828 1 : return;
15829 : }
15830 166 : tree stmt = build_call_expr_loc (loc, fn, 1,
15831 166 : build_int_cst (integer_type_node, mask));
15832 166 : add_stmt (stmt);
15833 : }
15834 :
15835 : /* Helper function for handle_omp_array_sections. Called recursively
15836 : to handle multiple array-section-subscripts. C is the clause,
15837 : T current expression (initially OMP_CLAUSE_DECL), which is either
15838 : a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound
15839 : expression if specified, TREE_VALUE length expression if specified,
15840 : TREE_CHAIN is what it has been specified after, or some decl.
15841 : TYPES vector is populated with array section types, MAYBE_ZERO_LEN
15842 : set to true if any of the array-section-subscript could have length
15843 : of zero (explicit or implicit), FIRST_NON_ONE is the index of the
15844 : first array-section-subscript which is known not to have length
15845 : of one. Given say:
15846 : map(a[:b][2:1][:c][:2][:d][e:f][2:5])
15847 : FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c]
15848 : all are or may have length of 1, array-section-subscript [:2] is the
15849 : first one known not to have length 1. For array-section-subscript
15850 : <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't
15851 : 0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we
15852 : can if MAYBE_ZERO_LEN is false. MAYBE_ZERO_LEN will be true in the above
15853 : case though, as some lengths could be zero. */
15854 :
15855 : static tree
15856 6443 : handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types,
15857 : bool &maybe_zero_len, unsigned int &first_non_one,
15858 : enum c_omp_region_type ort)
15859 : {
15860 6443 : tree ret, low_bound, length, type;
15861 6443 : bool openacc = (ort & C_ORT_ACC) != 0;
15862 6443 : if (TREE_CODE (t) != OMP_ARRAY_SECTION)
15863 : {
15864 3001 : if (error_operand_p (t))
15865 2 : return error_mark_node;
15866 2999 : c_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
15867 2999 : ret = t;
15868 2999 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
15869 2895 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
15870 5580 : && TYPE_ATOMIC (strip_array_types (TREE_TYPE (t))))
15871 : {
15872 6 : error_at (OMP_CLAUSE_LOCATION (c), "%<_Atomic%> %qE in %qs clause",
15873 6 : t, omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
15874 6 : return error_mark_node;
15875 : }
15876 2993 : if (!ai.check_clause (c))
15877 0 : return error_mark_node;
15878 2993 : else if (ai.component_access_p ()
15879 3296 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
15880 16 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO
15881 11 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM))
15882 303 : t = ai.get_root_term (true);
15883 : else
15884 2690 : t = ai.unconverted_ref_origin ();
15885 2993 : if (t == error_mark_node)
15886 : return error_mark_node;
15887 2993 : if (!VAR_P (t)
15888 751 : && (ort == C_ORT_ACC || !EXPR_P (t))
15889 744 : && TREE_CODE (t) != PARM_DECL)
15890 : {
15891 5 : if (DECL_P (t))
15892 5 : error_at (OMP_CLAUSE_LOCATION (c),
15893 : "%qD is not a variable in %qs clause", t,
15894 5 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
15895 : else
15896 0 : error_at (OMP_CLAUSE_LOCATION (c),
15897 : "%qE is not a variable in %qs clause", t,
15898 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
15899 5 : return error_mark_node;
15900 : }
15901 2988 : else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
15902 2885 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
15903 5560 : && TYPE_ATOMIC (TREE_TYPE (t)))
15904 : {
15905 0 : error_at (OMP_CLAUSE_LOCATION (c), "%<_Atomic%> %qD in %qs clause",
15906 0 : t, omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
15907 0 : return error_mark_node;
15908 : }
15909 2988 : else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
15910 2885 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
15911 2572 : && VAR_P (t)
15912 5004 : && DECL_THREAD_LOCAL_P (t))
15913 : {
15914 3 : error_at (OMP_CLAUSE_LOCATION (c),
15915 : "%qD is threadprivate variable in %qs clause", t,
15916 3 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
15917 3 : return error_mark_node;
15918 : }
15919 2985 : if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
15920 2882 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND)
15921 416 : && TYPE_ATOMIC (TREE_TYPE (t))
15922 2987 : && POINTER_TYPE_P (TREE_TYPE (t)))
15923 : {
15924 : /* If the array section is pointer based and the pointer
15925 : itself is _Atomic qualified, we need to atomically load
15926 : the pointer. */
15927 2 : ret = convert_lvalue_to_rvalue (OMP_CLAUSE_LOCATION (c),
15928 : ret, false, false);
15929 : }
15930 : return ret;
15931 2999 : }
15932 :
15933 3442 : ret = handle_omp_array_sections_1 (c, TREE_OPERAND (t, 0), types,
15934 : maybe_zero_len, first_non_one, ort);
15935 3442 : if (ret == error_mark_node || ret == NULL_TREE)
15936 : return ret;
15937 :
15938 3374 : type = TREE_TYPE (ret);
15939 3374 : low_bound = TREE_OPERAND (t, 1);
15940 3374 : length = TREE_OPERAND (t, 2);
15941 :
15942 3374 : if (low_bound == error_mark_node || length == error_mark_node)
15943 : return error_mark_node;
15944 :
15945 3374 : if (low_bound && !INTEGRAL_TYPE_P (TREE_TYPE (low_bound)))
15946 : {
15947 13 : error_at (OMP_CLAUSE_LOCATION (c),
15948 : "low bound %qE of array section does not have integral type",
15949 : low_bound);
15950 13 : return error_mark_node;
15951 : }
15952 3361 : if (length && !INTEGRAL_TYPE_P (TREE_TYPE (length)))
15953 : {
15954 12 : error_at (OMP_CLAUSE_LOCATION (c),
15955 : "length %qE of array section does not have integral type",
15956 : length);
15957 12 : return error_mark_node;
15958 : }
15959 3349 : if (low_bound
15960 2758 : && TREE_CODE (low_bound) == INTEGER_CST
15961 5815 : && TYPE_PRECISION (TREE_TYPE (low_bound))
15962 2466 : > TYPE_PRECISION (sizetype))
15963 0 : low_bound = fold_convert (sizetype, low_bound);
15964 3349 : if (length
15965 3157 : && TREE_CODE (length) == INTEGER_CST
15966 5559 : && TYPE_PRECISION (TREE_TYPE (length))
15967 2210 : > TYPE_PRECISION (sizetype))
15968 0 : length = fold_convert (sizetype, length);
15969 3349 : if (low_bound == NULL_TREE)
15970 591 : low_bound = integer_zero_node;
15971 3349 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
15972 3349 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
15973 1948 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH))
15974 : {
15975 10 : if (length != integer_one_node)
15976 : {
15977 6 : error_at (OMP_CLAUSE_LOCATION (c),
15978 : "expected single pointer in %qs clause",
15979 : user_omp_clause_code_name (c, openacc));
15980 6 : return error_mark_node;
15981 : }
15982 : }
15983 3343 : if (length != NULL_TREE)
15984 : {
15985 3155 : if (!integer_nonzerop (length))
15986 : {
15987 978 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
15988 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
15989 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
15990 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
15991 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
15992 : {
15993 180 : if (integer_zerop (length))
15994 : {
15995 12 : error_at (OMP_CLAUSE_LOCATION (c),
15996 : "zero length array section in %qs clause",
15997 12 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
15998 12 : return error_mark_node;
15999 : }
16000 : }
16001 : else
16002 798 : maybe_zero_len = true;
16003 : }
16004 3143 : if (first_non_one == types.length ()
16005 3143 : && (TREE_CODE (length) != INTEGER_CST || integer_onep (length)))
16006 1609 : first_non_one++;
16007 : }
16008 3331 : if (TREE_CODE (type) == ARRAY_TYPE)
16009 : {
16010 1503 : if (length == NULL_TREE
16011 1503 : && (TYPE_DOMAIN (type) == NULL_TREE
16012 170 : || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE))
16013 : {
16014 8 : error_at (OMP_CLAUSE_LOCATION (c),
16015 : "for unknown bound array type length expression must "
16016 : "be specified");
16017 8 : return error_mark_node;
16018 : }
16019 1495 : if (TREE_CODE (low_bound) == INTEGER_CST
16020 1495 : && tree_int_cst_sgn (low_bound) == -1)
16021 : {
16022 36 : error_at (OMP_CLAUSE_LOCATION (c),
16023 : "negative low bound in array section in %qs clause",
16024 36 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
16025 36 : return error_mark_node;
16026 : }
16027 1459 : if (length != NULL_TREE
16028 1302 : && TREE_CODE (length) == INTEGER_CST
16029 2321 : && tree_int_cst_sgn (length) == -1)
16030 : {
16031 36 : error_at (OMP_CLAUSE_LOCATION (c),
16032 : "negative length in array section in %qs clause",
16033 36 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
16034 36 : return error_mark_node;
16035 : }
16036 1423 : if (TYPE_DOMAIN (type)
16037 1412 : && TYPE_MAX_VALUE (TYPE_DOMAIN (type))
16038 2835 : && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
16039 : == INTEGER_CST)
16040 : {
16041 1066 : tree size
16042 1066 : = fold_convert (sizetype, TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
16043 1066 : size = size_binop (PLUS_EXPR, size, size_one_node);
16044 1066 : if (TREE_CODE (low_bound) == INTEGER_CST)
16045 : {
16046 879 : if (tree_int_cst_lt (size, low_bound))
16047 : {
16048 11 : error_at (OMP_CLAUSE_LOCATION (c),
16049 : "low bound %qE above array section size "
16050 : "in %qs clause", low_bound,
16051 11 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
16052 11 : return error_mark_node;
16053 : }
16054 868 : if (tree_int_cst_equal (size, low_bound))
16055 : {
16056 5 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
16057 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
16058 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
16059 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
16060 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
16061 : {
16062 5 : error_at (OMP_CLAUSE_LOCATION (c),
16063 : "zero length array section in %qs clause",
16064 5 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
16065 5 : return error_mark_node;
16066 : }
16067 0 : maybe_zero_len = true;
16068 : }
16069 863 : else if (length == NULL_TREE
16070 256 : && first_non_one == types.length ()
16071 918 : && tree_int_cst_equal
16072 55 : (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
16073 : low_bound))
16074 30 : first_non_one++;
16075 : }
16076 187 : else if (length == NULL_TREE)
16077 : {
16078 3 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
16079 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
16080 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
16081 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
16082 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
16083 0 : maybe_zero_len = true;
16084 6 : if (first_non_one == types.length ())
16085 1 : first_non_one++;
16086 : }
16087 1050 : if (length && TREE_CODE (length) == INTEGER_CST)
16088 : {
16089 803 : if (tree_int_cst_lt (size, length))
16090 : {
16091 11 : error_at (OMP_CLAUSE_LOCATION (c),
16092 : "length %qE above array section size "
16093 : "in %qs clause", length,
16094 11 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
16095 11 : return error_mark_node;
16096 : }
16097 792 : if (TREE_CODE (low_bound) == INTEGER_CST)
16098 : {
16099 692 : tree lbpluslen
16100 692 : = size_binop (PLUS_EXPR,
16101 : fold_convert (sizetype, low_bound),
16102 : fold_convert (sizetype, length));
16103 692 : if (TREE_CODE (lbpluslen) == INTEGER_CST
16104 692 : && tree_int_cst_lt (size, lbpluslen))
16105 : {
16106 10 : error_at (OMP_CLAUSE_LOCATION (c),
16107 : "high bound %qE above array section size "
16108 : "in %qs clause", lbpluslen,
16109 10 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
16110 10 : return error_mark_node;
16111 : }
16112 : }
16113 : }
16114 : }
16115 357 : else if (length == NULL_TREE)
16116 : {
16117 10 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
16118 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
16119 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
16120 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
16121 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
16122 0 : maybe_zero_len = true;
16123 20 : if (first_non_one == types.length ())
16124 10 : first_non_one++;
16125 : }
16126 :
16127 : /* For [lb:] we will need to evaluate lb more than once. */
16128 933 : if (length == NULL_TREE && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
16129 : {
16130 127 : tree lb = save_expr (low_bound);
16131 127 : if (lb != low_bound)
16132 : {
16133 2 : TREE_OPERAND (t, 1) = lb;
16134 2 : low_bound = lb;
16135 : }
16136 : }
16137 : }
16138 1828 : else if (TREE_CODE (type) == POINTER_TYPE)
16139 : {
16140 1817 : if (length == NULL_TREE)
16141 : {
16142 12 : if (TREE_CODE (ret) == PARM_DECL && C_ARRAY_PARAMETER (ret))
16143 10 : error_at (OMP_CLAUSE_LOCATION (c),
16144 : "for array function parameter length expression "
16145 : "must be specified");
16146 : else
16147 2 : error_at (OMP_CLAUSE_LOCATION (c),
16148 : "for pointer type length expression must be specified");
16149 12 : return error_mark_node;
16150 : }
16151 1805 : if (length != NULL_TREE
16152 1805 : && TREE_CODE (length) == INTEGER_CST
16153 1298 : && tree_int_cst_sgn (length) == -1)
16154 : {
16155 20 : error_at (OMP_CLAUSE_LOCATION (c),
16156 : "negative length in array section in %qs clause",
16157 20 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
16158 20 : return error_mark_node;
16159 : }
16160 : /* If there is a pointer type anywhere but in the very first
16161 : array-section-subscript, the array section could be non-contiguous. */
16162 1785 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
16163 1624 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
16164 3380 : && TREE_CODE (TREE_OPERAND (t, 0)) == OMP_ARRAY_SECTION)
16165 : {
16166 : /* If any prior dimension has a non-one length, then deem this
16167 : array section as non-contiguous. */
16168 42 : for (tree d = TREE_OPERAND (t, 0);
16169 82 : TREE_CODE (d) == OMP_ARRAY_SECTION;
16170 40 : d = TREE_OPERAND (d, 0))
16171 : {
16172 44 : tree d_length = TREE_OPERAND (d, 2);
16173 44 : if (d_length == NULL_TREE || !integer_onep (d_length))
16174 : {
16175 4 : error_at (OMP_CLAUSE_LOCATION (c),
16176 : "array section is not contiguous in %qs clause",
16177 4 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
16178 4 : return error_mark_node;
16179 : }
16180 : }
16181 : }
16182 : }
16183 : else
16184 : {
16185 11 : error_at (OMP_CLAUSE_LOCATION (c),
16186 : "%qE does not have pointer or array type", ret);
16187 11 : return error_mark_node;
16188 : }
16189 3167 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
16190 2851 : types.safe_push (TREE_TYPE (ret));
16191 : /* We will need to evaluate lb more than once. */
16192 3167 : tree lb = save_expr (low_bound);
16193 3167 : if (lb != low_bound)
16194 : {
16195 276 : TREE_OPERAND (t, 1) = lb;
16196 276 : low_bound = lb;
16197 : }
16198 3167 : ret = build_array_ref (OMP_CLAUSE_LOCATION (c), ret, low_bound);
16199 3167 : return ret;
16200 : }
16201 :
16202 : /* Handle array sections for clause C. */
16203 :
16204 : static bool
16205 3001 : handle_omp_array_sections (tree &c, enum c_omp_region_type ort)
16206 : {
16207 3001 : bool maybe_zero_len = false;
16208 3001 : unsigned int first_non_one = 0;
16209 3001 : auto_vec<tree, 10> types;
16210 3001 : tree *tp = &OMP_CLAUSE_DECL (c);
16211 3001 : if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
16212 2687 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
16213 3105 : && OMP_ITERATOR_DECL_P (*tp))
16214 66 : tp = &TREE_VALUE (*tp);
16215 3001 : tree first = handle_omp_array_sections_1 (c, *tp, types,
16216 : maybe_zero_len, first_non_one,
16217 : ort);
16218 3001 : if (first == error_mark_node)
16219 : return true;
16220 2778 : if (first == NULL_TREE)
16221 : return false;
16222 2778 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
16223 2778 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
16224 : {
16225 336 : tree t = *tp;
16226 336 : tree tem = NULL_TREE;
16227 : /* Need to evaluate side effects in the length expressions
16228 : if any. */
16229 336 : while (TREE_CODE (t) == TREE_LIST)
16230 : {
16231 0 : if (TREE_VALUE (t) && TREE_SIDE_EFFECTS (TREE_VALUE (t)))
16232 : {
16233 0 : if (tem == NULL_TREE)
16234 : tem = TREE_VALUE (t);
16235 : else
16236 0 : tem = build2 (COMPOUND_EXPR, TREE_TYPE (tem),
16237 0 : TREE_VALUE (t), tem);
16238 : }
16239 0 : t = TREE_CHAIN (t);
16240 : }
16241 336 : if (tem)
16242 0 : first = build2 (COMPOUND_EXPR, TREE_TYPE (first), tem, first);
16243 336 : first = c_fully_fold (first, false, NULL, true);
16244 336 : *tp = first;
16245 : }
16246 : else
16247 : {
16248 2442 : unsigned int num = types.length (), i;
16249 2442 : tree t, side_effects = NULL_TREE, size = NULL_TREE;
16250 2442 : tree condition = NULL_TREE;
16251 :
16252 2442 : if (int_size_in_bytes (TREE_TYPE (first)) <= 0)
16253 3 : maybe_zero_len = true;
16254 :
16255 5084 : for (i = num, t = OMP_CLAUSE_DECL (c); i > 0;
16256 2642 : t = TREE_OPERAND (t, 0))
16257 : {
16258 2657 : tree low_bound = TREE_OPERAND (t, 1);
16259 2657 : tree length = TREE_OPERAND (t, 2);
16260 :
16261 2657 : i--;
16262 2657 : if (low_bound
16263 2189 : && TREE_CODE (low_bound) == INTEGER_CST
16264 4657 : && TYPE_PRECISION (TREE_TYPE (low_bound))
16265 2000 : > TYPE_PRECISION (sizetype))
16266 0 : low_bound = fold_convert (sizetype, low_bound);
16267 2657 : if (length
16268 2565 : && TREE_CODE (length) == INTEGER_CST
16269 4293 : && TYPE_PRECISION (TREE_TYPE (length))
16270 1636 : > TYPE_PRECISION (sizetype))
16271 0 : length = fold_convert (sizetype, length);
16272 2657 : if (low_bound == NULL_TREE)
16273 468 : low_bound = integer_zero_node;
16274 2657 : if (!maybe_zero_len && i > first_non_one)
16275 : {
16276 109 : if (integer_nonzerop (low_bound))
16277 6 : goto do_warn_noncontiguous;
16278 103 : if (length != NULL_TREE
16279 50 : && TREE_CODE (length) == INTEGER_CST
16280 50 : && TYPE_DOMAIN (types[i])
16281 50 : && TYPE_MAX_VALUE (TYPE_DOMAIN (types[i]))
16282 153 : && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])))
16283 : == INTEGER_CST)
16284 : {
16285 50 : tree size;
16286 50 : size = size_binop (PLUS_EXPR,
16287 : TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
16288 : size_one_node);
16289 50 : if (!tree_int_cst_equal (length, size))
16290 : {
16291 7 : do_warn_noncontiguous:
16292 26 : error_at (OMP_CLAUSE_LOCATION (c),
16293 : "array section is not contiguous in %qs "
16294 : "clause",
16295 13 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
16296 2442 : return true;
16297 : }
16298 : }
16299 96 : if (length != NULL_TREE
16300 96 : && TREE_SIDE_EFFECTS (length))
16301 : {
16302 0 : if (side_effects == NULL_TREE)
16303 : side_effects = length;
16304 : else
16305 0 : side_effects = build2 (COMPOUND_EXPR,
16306 0 : TREE_TYPE (side_effects),
16307 : length, side_effects);
16308 : }
16309 : }
16310 : else
16311 : {
16312 2548 : tree l;
16313 :
16314 2548 : if (i > first_non_one
16315 2548 : && ((length && integer_nonzerop (length))
16316 0 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
16317 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
16318 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION))
16319 0 : continue;
16320 2548 : if (length)
16321 2515 : l = fold_convert (sizetype, length);
16322 : else
16323 : {
16324 33 : l = size_binop (PLUS_EXPR,
16325 : TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
16326 : size_one_node);
16327 33 : l = size_binop (MINUS_EXPR, l,
16328 : fold_convert (sizetype, low_bound));
16329 : }
16330 2548 : if (i > first_non_one)
16331 : {
16332 0 : l = fold_build2 (NE_EXPR, boolean_type_node, l,
16333 : size_zero_node);
16334 0 : if (condition == NULL_TREE)
16335 : condition = l;
16336 : else
16337 0 : condition = fold_build2 (BIT_AND_EXPR, boolean_type_node,
16338 : l, condition);
16339 : }
16340 2548 : else if (size == NULL_TREE)
16341 : {
16342 2429 : size = size_in_bytes (TREE_TYPE (types[i]));
16343 2429 : tree eltype = TREE_TYPE (types[num - 1]);
16344 2449 : while (TREE_CODE (eltype) == ARRAY_TYPE)
16345 20 : eltype = TREE_TYPE (eltype);
16346 2429 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
16347 2194 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
16348 4363 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
16349 : {
16350 539 : if (integer_zerop (size)
16351 1076 : || integer_zerop (size_in_bytes (eltype)))
16352 : {
16353 4 : error_at (OMP_CLAUSE_LOCATION (c),
16354 : "zero length array section in %qs clause",
16355 2 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
16356 2 : return error_mark_node;
16357 : }
16358 537 : size = size_binop (EXACT_DIV_EXPR, size,
16359 : size_in_bytes (eltype));
16360 : }
16361 2427 : size = size_binop (MULT_EXPR, size, l);
16362 2427 : if (condition)
16363 0 : size = fold_build3 (COND_EXPR, sizetype, condition,
16364 : size, size_zero_node);
16365 : }
16366 : else
16367 119 : size = size_binop (MULT_EXPR, size, l);
16368 : }
16369 : }
16370 2427 : if (side_effects)
16371 0 : size = build2 (COMPOUND_EXPR, sizetype, side_effects, size);
16372 2427 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
16373 2194 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
16374 4361 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
16375 : {
16376 537 : size = size_binop (MINUS_EXPR, size, size_one_node);
16377 537 : size = c_fully_fold (size, false, NULL);
16378 537 : size = save_expr (size);
16379 537 : tree index_type = build_index_type (size);
16380 537 : tree eltype = TREE_TYPE (first);
16381 549 : while (TREE_CODE (eltype) == ARRAY_TYPE)
16382 12 : eltype = TREE_TYPE (eltype);
16383 537 : tree type = c_build_array_type (eltype, index_type);
16384 537 : tree ptype = c_build_pointer_type (eltype);
16385 537 : if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
16386 296 : t = build_fold_addr_expr (t);
16387 537 : tree t2 = build_fold_addr_expr (first);
16388 537 : t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
16389 : ptrdiff_type_node, t2);
16390 537 : t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
16391 : ptrdiff_type_node, t2,
16392 537 : fold_convert_loc (OMP_CLAUSE_LOCATION (c),
16393 : ptrdiff_type_node, t));
16394 537 : t2 = c_fully_fold (t2, false, NULL);
16395 537 : if (tree_fits_shwi_p (t2))
16396 398 : t = build2 (MEM_REF, type, t,
16397 398 : build_int_cst (ptype, tree_to_shwi (t2)));
16398 : else
16399 : {
16400 139 : t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c), sizetype, t2);
16401 139 : t = build2_loc (OMP_CLAUSE_LOCATION (c), POINTER_PLUS_EXPR,
16402 139 : TREE_TYPE (t), t, t2);
16403 139 : t = build2 (MEM_REF, type, t, build_int_cst (ptype, 0));
16404 : }
16405 537 : OMP_CLAUSE_DECL (c) = t;
16406 537 : return false;
16407 : }
16408 1890 : first = c_fully_fold (first, false, NULL);
16409 1890 : OMP_CLAUSE_DECL (c) = first;
16410 1890 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR)
16411 : return false;
16412 : /* Don't set OMP_CLAUSE_SIZE for bare attach/detach clauses. */
16413 1879 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
16414 1879 : || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
16415 1733 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH
16416 1731 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FORCE_DETACH))
16417 : {
16418 1875 : if (size)
16419 1875 : size = c_fully_fold (size, false, NULL);
16420 1875 : OMP_CLAUSE_SIZE (c) = size;
16421 : }
16422 :
16423 1879 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
16424 : return false;
16425 :
16426 1735 : auto_vec<omp_addr_token *, 10> addr_tokens;
16427 :
16428 1735 : if (!omp_parse_expr (addr_tokens, first))
16429 1735 : return true;
16430 :
16431 1735 : c_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
16432 :
16433 1735 : tree nc = ai.expand_map_clause (c, first, addr_tokens, ort);
16434 1735 : if (nc != error_mark_node)
16435 : {
16436 1735 : using namespace omp_addr_tokenizer;
16437 :
16438 1735 : if (ai.maybe_zero_length_array_section (c))
16439 1731 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
16440 :
16441 : /* !!! If we're accessing a base decl via chained access
16442 : methods (e.g. multiple indirections), duplicate clause
16443 : detection won't work properly. Skip it in that case. */
16444 1735 : if ((addr_tokens[0]->type == STRUCTURE_BASE
16445 1445 : || addr_tokens[0]->type == ARRAY_BASE)
16446 1735 : && addr_tokens[0]->u.structure_base_kind == BASE_DECL
16447 1735 : && addr_tokens[1]->type == ACCESS_METHOD
16448 3470 : && omp_access_chain_p (addr_tokens, 1))
16449 36 : c = nc;
16450 :
16451 1735 : return false;
16452 : }
16453 : }
16454 : return false;
16455 3001 : }
16456 :
16457 : /* Helper function of finish_omp_clauses. Clone STMT as if we were making
16458 : an inline call. But, remap
16459 : the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER
16460 : and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL. */
16461 :
16462 : static tree
16463 516 : c_clone_omp_udr (tree stmt, tree omp_decl1, tree omp_decl2,
16464 : tree decl, tree placeholder)
16465 : {
16466 516 : copy_body_data id;
16467 516 : hash_map<tree, tree> decl_map;
16468 :
16469 516 : decl_map.put (omp_decl1, placeholder);
16470 516 : decl_map.put (omp_decl2, decl);
16471 516 : memset (&id, 0, sizeof (id));
16472 516 : id.src_fn = DECL_CONTEXT (omp_decl1);
16473 516 : id.dst_fn = current_function_decl;
16474 516 : id.src_cfun = DECL_STRUCT_FUNCTION (id.src_fn);
16475 516 : id.decl_map = &decl_map;
16476 :
16477 516 : id.copy_decl = copy_decl_no_change;
16478 516 : id.transform_call_graph_edges = CB_CGE_DUPLICATE;
16479 516 : id.transform_new_cfg = true;
16480 516 : id.transform_return_to_modify = false;
16481 516 : id.eh_lp_nr = 0;
16482 516 : walk_tree (&stmt, copy_tree_body_r, &id, NULL);
16483 516 : return stmt;
16484 516 : }
16485 :
16486 : /* Helper function of c_finish_omp_clauses, called via walk_tree.
16487 : Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP. */
16488 :
16489 : static tree
16490 1147 : c_find_omp_placeholder_r (tree *tp, int *, void *data)
16491 : {
16492 1147 : if (*tp == (tree) data)
16493 31 : return *tp;
16494 : return NULL_TREE;
16495 : }
16496 :
16497 : /* Similarly, but also walk aggregate fields. */
16498 :
16499 : struct c_find_omp_var_s { tree var; hash_set<tree> *pset; };
16500 :
16501 : static tree
16502 288 : c_find_omp_var_r (tree *tp, int *, void *data)
16503 : {
16504 288 : if (*tp == ((struct c_find_omp_var_s *) data)->var)
16505 : return *tp;
16506 280 : if (RECORD_OR_UNION_TYPE_P (*tp))
16507 : {
16508 2 : tree field;
16509 2 : hash_set<tree> *pset = ((struct c_find_omp_var_s *) data)->pset;
16510 :
16511 2 : for (field = TYPE_FIELDS (*tp); field;
16512 0 : field = DECL_CHAIN (field))
16513 2 : if (TREE_CODE (field) == FIELD_DECL)
16514 : {
16515 2 : tree ret = walk_tree (&DECL_FIELD_OFFSET (field),
16516 : c_find_omp_var_r, data, pset);
16517 2 : if (ret)
16518 : return ret;
16519 2 : ret = walk_tree (&DECL_SIZE (field), c_find_omp_var_r, data, pset);
16520 2 : if (ret)
16521 : return ret;
16522 2 : ret = walk_tree (&DECL_SIZE_UNIT (field), c_find_omp_var_r, data,
16523 : pset);
16524 2 : if (ret)
16525 : return ret;
16526 2 : ret = walk_tree (&TREE_TYPE (field), c_find_omp_var_r, data, pset);
16527 2 : if (ret)
16528 : return ret;
16529 : }
16530 : }
16531 278 : else if (INTEGRAL_TYPE_P (*tp))
16532 45 : return walk_tree (&TYPE_MAX_VALUE (*tp), c_find_omp_var_r, data,
16533 : ((struct c_find_omp_var_s *) data)->pset);
16534 : return NULL_TREE;
16535 : }
16536 :
16537 : /* Finish OpenMP iterators ITER. Return true if they are erroneous
16538 : and clauses containing them should be removed. */
16539 :
16540 : static bool
16541 146 : c_omp_finish_iterators (tree iter)
16542 : {
16543 146 : bool ret = false;
16544 331 : for (tree it = iter; it; it = TREE_CHAIN (it))
16545 : {
16546 185 : tree var = OMP_ITERATOR_VAR (it);
16547 185 : tree begin = OMP_ITERATOR_BEGIN (it);
16548 185 : tree end = OMP_ITERATOR_END (it);
16549 185 : tree step = OMP_ITERATOR_STEP (it);
16550 185 : tree orig_step;
16551 185 : tree type = TREE_TYPE (var);
16552 185 : location_t loc = DECL_SOURCE_LOCATION (var);
16553 185 : if (type == error_mark_node)
16554 : {
16555 0 : ret = true;
16556 34 : continue;
16557 : }
16558 185 : if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type))
16559 : {
16560 6 : error_at (loc, "iterator %qD has neither integral nor pointer type",
16561 : var);
16562 6 : ret = true;
16563 6 : continue;
16564 : }
16565 179 : else if (TYPE_ATOMIC (type))
16566 : {
16567 2 : error_at (loc, "iterator %qD has %<_Atomic%> qualified type", var);
16568 2 : ret = true;
16569 2 : continue;
16570 : }
16571 177 : else if (TYPE_READONLY (type))
16572 : {
16573 4 : error_at (loc, "iterator %qD has const qualified type", var);
16574 4 : ret = true;
16575 4 : continue;
16576 : }
16577 173 : else if (step == error_mark_node
16578 173 : || TREE_TYPE (step) == error_mark_node)
16579 : {
16580 0 : ret = true;
16581 0 : continue;
16582 : }
16583 173 : else if (!INTEGRAL_TYPE_P (TREE_TYPE (step)))
16584 : {
16585 4 : error_at (EXPR_LOC_OR_LOC (step, loc),
16586 : "iterator step with non-integral type");
16587 4 : ret = true;
16588 4 : continue;
16589 : }
16590 169 : begin = c_fully_fold (build_c_cast (loc, type, begin), false, NULL);
16591 169 : end = c_fully_fold (build_c_cast (loc, type, end), false, NULL);
16592 169 : orig_step = save_expr (c_fully_fold (step, false, NULL));
16593 169 : tree stype = POINTER_TYPE_P (type) ? sizetype : type;
16594 169 : step = c_fully_fold (build_c_cast (loc, stype, orig_step), false, NULL);
16595 169 : if (POINTER_TYPE_P (type))
16596 : {
16597 14 : begin = save_expr (begin);
16598 14 : step = pointer_int_sum (loc, PLUS_EXPR, begin, step);
16599 14 : step = fold_build2_loc (loc, MINUS_EXPR, sizetype,
16600 : fold_convert (sizetype, step),
16601 : fold_convert (sizetype, begin));
16602 14 : step = fold_convert (ssizetype, step);
16603 : }
16604 169 : if (integer_zerop (step))
16605 : {
16606 6 : error_at (loc, "iterator %qD has zero step", var);
16607 6 : ret = true;
16608 6 : continue;
16609 : }
16610 :
16611 163 : if (begin == error_mark_node
16612 161 : || end == error_mark_node
16613 159 : || step == error_mark_node
16614 159 : || orig_step == error_mark_node)
16615 : {
16616 4 : ret = true;
16617 4 : continue;
16618 : }
16619 159 : hash_set<tree> pset;
16620 159 : tree it2;
16621 200 : for (it2 = TREE_CHAIN (it); it2; it2 = TREE_CHAIN (it2))
16622 : {
16623 49 : tree var2 = OMP_ITERATOR_VAR (it2);
16624 49 : tree begin2 = OMP_ITERATOR_BEGIN (it2);
16625 49 : tree end2 = OMP_ITERATOR_END (it2);
16626 49 : tree step2 = OMP_ITERATOR_STEP (it2);
16627 49 : tree type2 = TREE_TYPE (var2);
16628 49 : location_t loc2 = DECL_SOURCE_LOCATION (var2);
16629 49 : struct c_find_omp_var_s data = { var, &pset };
16630 49 : if (walk_tree (&type2, c_find_omp_var_r, &data, &pset))
16631 : {
16632 2 : error_at (loc2,
16633 : "type of iterator %qD refers to outer iterator %qD",
16634 : var2, var);
16635 10 : break;
16636 : }
16637 47 : else if (walk_tree (&begin2, c_find_omp_var_r, &data, &pset))
16638 : {
16639 2 : error_at (EXPR_LOC_OR_LOC (begin2, loc2),
16640 : "begin expression refers to outer iterator %qD", var);
16641 2 : break;
16642 : }
16643 45 : else if (walk_tree (&end2, c_find_omp_var_r, &data, &pset))
16644 : {
16645 2 : error_at (EXPR_LOC_OR_LOC (end2, loc2),
16646 : "end expression refers to outer iterator %qD", var);
16647 2 : break;
16648 : }
16649 43 : else if (walk_tree (&step2, c_find_omp_var_r, &data, &pset))
16650 : {
16651 2 : error_at (EXPR_LOC_OR_LOC (step2, loc2),
16652 : "step expression refers to outer iterator %qD", var);
16653 2 : break;
16654 : }
16655 : }
16656 159 : if (it2)
16657 : {
16658 8 : ret = true;
16659 8 : continue;
16660 : }
16661 151 : OMP_ITERATOR_BEGIN (it) = begin;
16662 151 : OMP_ITERATOR_END (it) = end;
16663 151 : OMP_ITERATOR_STEP (it) = step;
16664 151 : OMP_ITERATOR_ORIG_STEP (it) = orig_step;
16665 159 : }
16666 146 : return ret;
16667 : }
16668 :
16669 : /* Ensure that pointers are used in OpenACC attach and detach clauses.
16670 : Return true if an error has been detected. */
16671 :
16672 : static bool
16673 9725 : c_oacc_check_attachments (tree c)
16674 : {
16675 9725 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
16676 : return false;
16677 :
16678 : /* OpenACC attach / detach clauses must be pointers. */
16679 6679 : if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
16680 6679 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
16681 : {
16682 75 : tree t = OMP_CLAUSE_DECL (c);
16683 :
16684 81 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
16685 6 : t = TREE_OPERAND (t, 0);
16686 :
16687 75 : if (TREE_CODE (TREE_TYPE (t)) != POINTER_TYPE)
16688 : {
16689 6 : error_at (OMP_CLAUSE_LOCATION (c), "expected pointer in %qs clause",
16690 : user_omp_clause_code_name (c, true));
16691 6 : return true;
16692 : }
16693 : }
16694 :
16695 : return false;
16696 : }
16697 :
16698 : /* For all elements of CLAUSES, validate them against their constraints.
16699 : Remove any elements from the list that are invalid. */
16700 :
16701 : tree
16702 29758 : c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
16703 : {
16704 29758 : bitmap_head generic_head, firstprivate_head, lastprivate_head;
16705 29758 : bitmap_head aligned_head, map_head, map_field_head, map_firstprivate_head;
16706 29758 : bitmap_head oacc_reduction_head, is_on_device_head;
16707 29758 : tree c, t, type, *pc;
16708 29758 : tree simdlen = NULL_TREE, safelen = NULL_TREE;
16709 29758 : bool branch_seen = false;
16710 29758 : bool copyprivate_seen = false;
16711 29758 : bool mergeable_seen = false;
16712 29758 : tree *detach_seen = NULL;
16713 29758 : bool linear_variable_step_check = false;
16714 29758 : tree *nowait_clause = NULL;
16715 29758 : tree *grainsize_seen = NULL;
16716 29758 : bool num_tasks_seen = false;
16717 29758 : tree ordered_clause = NULL_TREE;
16718 29758 : tree schedule_clause = NULL_TREE;
16719 29758 : bool oacc_async = false;
16720 29758 : tree last_iterators = NULL_TREE;
16721 29758 : bool last_iterators_remove = false;
16722 29758 : tree *nogroup_seen = NULL;
16723 29758 : tree *order_clause = NULL;
16724 : /* 1 if normal/task reduction has been seen, -1 if inscan reduction
16725 : has been seen, -2 if mixed inscan/normal reduction diagnosed. */
16726 29758 : int reduction_seen = 0;
16727 29758 : bool allocate_seen = false;
16728 29758 : bool implicit_moved = false;
16729 29758 : bool target_in_reduction_seen = false;
16730 29758 : tree *full_seen = NULL;
16731 29758 : bool partial_seen = false;
16732 29758 : bool openacc = (ort & C_ORT_ACC) != 0;
16733 29758 : bool init_seen = false;
16734 29758 : bool init_use_destroy_seen = false;
16735 29758 : tree init_no_targetsync_clause = NULL_TREE;
16736 29758 : tree depend_clause = NULL_TREE;
16737 :
16738 29758 : if (!openacc)
16739 24521 : clauses = omp_remove_duplicate_maps (clauses, true);
16740 :
16741 29758 : bitmap_obstack_initialize (NULL);
16742 29758 : bitmap_initialize (&generic_head, &bitmap_default_obstack);
16743 29758 : bitmap_initialize (&firstprivate_head, &bitmap_default_obstack);
16744 29758 : bitmap_initialize (&lastprivate_head, &bitmap_default_obstack);
16745 29758 : bitmap_initialize (&aligned_head, &bitmap_default_obstack);
16746 : /* If ort == C_ORT_OMP_DECLARE_SIMD used as uniform_head instead. */
16747 29758 : bitmap_initialize (&map_head, &bitmap_default_obstack);
16748 29758 : bitmap_initialize (&map_field_head, &bitmap_default_obstack);
16749 29758 : bitmap_initialize (&map_firstprivate_head, &bitmap_default_obstack);
16750 : /* If ort == C_ORT_OMP used as nontemporal_head or use_device_xxx_head
16751 : instead and for ort == C_ORT_OMP_TARGET used as in_reduction_head. */
16752 29758 : bitmap_initialize (&oacc_reduction_head, &bitmap_default_obstack);
16753 29758 : bitmap_initialize (&is_on_device_head, &bitmap_default_obstack);
16754 :
16755 29758 : if (openacc)
16756 12269 : for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
16757 7258 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ASYNC)
16758 : {
16759 : oacc_async = true;
16760 : break;
16761 : }
16762 :
16763 29758 : tree *grp_start_p = NULL, grp_sentinel = NULL_TREE;
16764 :
16765 78079 : for (pc = &clauses, c = clauses; c ; c = *pc)
16766 : {
16767 48321 : bool remove = false;
16768 48321 : bool need_complete = false;
16769 48321 : bool need_implicitly_determined = false;
16770 :
16771 : /* We've reached the end of a list of expanded nodes. Reset the group
16772 : start pointer. */
16773 48321 : if (c == grp_sentinel)
16774 : {
16775 2542 : if (grp_start_p
16776 2542 : && OMP_CLAUSE_HAS_ITERATORS (*grp_start_p))
16777 32 : for (tree gc = *grp_start_p; gc != grp_sentinel;
16778 22 : gc = OMP_CLAUSE_CHAIN (gc))
16779 22 : OMP_CLAUSE_ITERATORS (gc) = OMP_CLAUSE_ITERATORS (*grp_start_p);
16780 : grp_start_p = NULL;
16781 : }
16782 :
16783 48321 : switch (OMP_CLAUSE_CODE (c))
16784 : {
16785 1139 : case OMP_CLAUSE_SHARED:
16786 1139 : need_implicitly_determined = true;
16787 1139 : goto check_dup_generic;
16788 :
16789 851 : case OMP_CLAUSE_PRIVATE:
16790 851 : need_complete = true;
16791 851 : need_implicitly_determined = true;
16792 851 : goto check_dup_generic;
16793 :
16794 3539 : case OMP_CLAUSE_REDUCTION:
16795 3539 : if (reduction_seen == 0)
16796 2935 : reduction_seen = OMP_CLAUSE_REDUCTION_INSCAN (c) ? -1 : 1;
16797 604 : else if (reduction_seen != -2
16798 1208 : && reduction_seen != (OMP_CLAUSE_REDUCTION_INSCAN (c)
16799 604 : ? -1 : 1))
16800 : {
16801 2 : error_at (OMP_CLAUSE_LOCATION (c),
16802 : "%<inscan%> and non-%<inscan%> %<reduction%> clauses "
16803 : "on the same construct");
16804 2 : reduction_seen = -2;
16805 : }
16806 : /* FALLTHRU */
16807 4203 : case OMP_CLAUSE_IN_REDUCTION:
16808 4203 : case OMP_CLAUSE_TASK_REDUCTION:
16809 4203 : need_implicitly_determined = true;
16810 4203 : t = OMP_CLAUSE_DECL (c);
16811 4203 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
16812 : {
16813 553 : if (handle_omp_array_sections (c, ort))
16814 : {
16815 : remove = true;
16816 : break;
16817 : }
16818 :
16819 537 : t = OMP_CLAUSE_DECL (c);
16820 537 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
16821 537 : && OMP_CLAUSE_REDUCTION_INSCAN (c))
16822 : {
16823 1 : error_at (OMP_CLAUSE_LOCATION (c),
16824 : "%<inscan%> %<reduction%> clause with array "
16825 : "section");
16826 1 : remove = true;
16827 1 : break;
16828 : }
16829 : }
16830 4186 : t = require_complete_type (OMP_CLAUSE_LOCATION (c), t);
16831 4186 : if (t == error_mark_node)
16832 : {
16833 : remove = true;
16834 : break;
16835 : }
16836 4184 : if (oacc_async)
16837 3 : c_mark_addressable (t);
16838 4184 : type = TREE_TYPE (t);
16839 4184 : if (TREE_CODE (t) == MEM_REF)
16840 536 : type = TREE_TYPE (type);
16841 4184 : if (TREE_CODE (type) == ARRAY_TYPE)
16842 : {
16843 74 : tree oatype = type;
16844 74 : gcc_assert (TREE_CODE (t) != MEM_REF);
16845 148 : while (TREE_CODE (type) == ARRAY_TYPE)
16846 74 : type = TREE_TYPE (type);
16847 74 : if (integer_zerop (TYPE_SIZE_UNIT (type)))
16848 : {
16849 1 : error_at (OMP_CLAUSE_LOCATION (c),
16850 : "%qD in %<reduction%> clause is a zero size array",
16851 : t);
16852 1 : remove = true;
16853 1 : break;
16854 : }
16855 73 : tree size = size_binop (EXACT_DIV_EXPR, TYPE_SIZE_UNIT (oatype),
16856 : TYPE_SIZE_UNIT (type));
16857 73 : if (integer_zerop (size))
16858 : {
16859 1 : error_at (OMP_CLAUSE_LOCATION (c),
16860 : "%qD in %<reduction%> clause is a zero size array",
16861 : t);
16862 1 : remove = true;
16863 1 : break;
16864 : }
16865 72 : size = size_binop (MINUS_EXPR, size, size_one_node);
16866 72 : size = save_expr (size);
16867 72 : tree index_type = build_index_type (size);
16868 72 : tree atype = c_build_array_type (TYPE_MAIN_VARIANT (type),
16869 : index_type);
16870 72 : atype = c_build_qualified_type (atype, TYPE_QUALS (type));
16871 72 : tree ptype = c_build_pointer_type (type);
16872 72 : if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
16873 72 : t = build_fold_addr_expr (t);
16874 72 : t = build2 (MEM_REF, atype, t, build_int_cst (ptype, 0));
16875 72 : OMP_CLAUSE_DECL (c) = t;
16876 : }
16877 4182 : if (TYPE_ATOMIC (type))
16878 : {
16879 3 : error_at (OMP_CLAUSE_LOCATION (c),
16880 : "%<_Atomic%> %qE in %<reduction%> clause", t);
16881 3 : remove = true;
16882 3 : break;
16883 : }
16884 4179 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
16885 4179 : || OMP_CLAUSE_REDUCTION_TASK (c))
16886 : {
16887 : /* Disallow zero sized or potentially zero sized task
16888 : reductions. */
16889 873 : if (integer_zerop (TYPE_SIZE_UNIT (type)))
16890 : {
16891 6 : error_at (OMP_CLAUSE_LOCATION (c),
16892 : "zero sized type %qT in %qs clause", type,
16893 3 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
16894 3 : remove = true;
16895 3 : break;
16896 : }
16897 870 : else if (TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST)
16898 : {
16899 0 : error_at (OMP_CLAUSE_LOCATION (c),
16900 : "variable sized type %qT in %qs clause", type,
16901 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
16902 0 : remove = true;
16903 0 : break;
16904 : }
16905 : }
16906 4176 : if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == NULL_TREE
16907 4176 : && (FLOAT_TYPE_P (type)
16908 3621 : || TREE_CODE (type) == COMPLEX_TYPE))
16909 : {
16910 340 : enum tree_code r_code = OMP_CLAUSE_REDUCTION_CODE (c);
16911 340 : const char *r_name = NULL;
16912 :
16913 340 : switch (r_code)
16914 : {
16915 : case PLUS_EXPR:
16916 : case MULT_EXPR:
16917 : case MINUS_EXPR:
16918 : case TRUTH_ANDIF_EXPR:
16919 : case TRUTH_ORIF_EXPR:
16920 : break;
16921 13 : case MIN_EXPR:
16922 13 : if (TREE_CODE (type) == COMPLEX_TYPE)
16923 : r_name = "min";
16924 : break;
16925 38 : case MAX_EXPR:
16926 38 : if (TREE_CODE (type) == COMPLEX_TYPE)
16927 : r_name = "max";
16928 : break;
16929 3 : case BIT_AND_EXPR:
16930 3 : r_name = "&";
16931 3 : break;
16932 2 : case BIT_XOR_EXPR:
16933 2 : r_name = "^";
16934 2 : break;
16935 : case BIT_IOR_EXPR:
16936 : r_name = "|";
16937 : break;
16938 0 : default:
16939 0 : gcc_unreachable ();
16940 : }
16941 5 : if (r_name)
16942 : {
16943 12 : error_at (OMP_CLAUSE_LOCATION (c),
16944 : "%qE has invalid type for %<reduction(%s)%>",
16945 : t, r_name);
16946 12 : remove = true;
16947 12 : break;
16948 : }
16949 : }
16950 3836 : else if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == error_mark_node)
16951 : {
16952 2 : error_at (OMP_CLAUSE_LOCATION (c),
16953 : "user defined reduction not found for %qE", t);
16954 2 : remove = true;
16955 2 : break;
16956 : }
16957 3834 : else if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
16958 : {
16959 280 : tree list = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c);
16960 280 : type = TYPE_MAIN_VARIANT (type);
16961 280 : tree placeholder = build_decl (OMP_CLAUSE_LOCATION (c),
16962 : VAR_DECL, NULL_TREE, type);
16963 280 : tree decl_placeholder = NULL_TREE;
16964 280 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = placeholder;
16965 280 : DECL_ARTIFICIAL (placeholder) = 1;
16966 280 : DECL_IGNORED_P (placeholder) = 1;
16967 280 : if (TREE_CODE (t) == MEM_REF)
16968 : {
16969 56 : decl_placeholder = build_decl (OMP_CLAUSE_LOCATION (c),
16970 : VAR_DECL, NULL_TREE, type);
16971 56 : OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c) = decl_placeholder;
16972 56 : DECL_ARTIFICIAL (decl_placeholder) = 1;
16973 56 : DECL_IGNORED_P (decl_placeholder) = 1;
16974 : }
16975 280 : if (TREE_ADDRESSABLE (TREE_VEC_ELT (list, 0)))
16976 45 : c_mark_addressable (placeholder);
16977 280 : if (TREE_ADDRESSABLE (TREE_VEC_ELT (list, 1)))
16978 82 : c_mark_addressable (decl_placeholder ? decl_placeholder
16979 37 : : OMP_CLAUSE_DECL (c));
16980 280 : OMP_CLAUSE_REDUCTION_MERGE (c)
16981 784 : = c_clone_omp_udr (TREE_VEC_ELT (list, 2),
16982 280 : TREE_VEC_ELT (list, 0),
16983 280 : TREE_VEC_ELT (list, 1),
16984 : decl_placeholder ? decl_placeholder
16985 224 : : OMP_CLAUSE_DECL (c), placeholder);
16986 280 : OMP_CLAUSE_REDUCTION_MERGE (c)
16987 280 : = build3_loc (OMP_CLAUSE_LOCATION (c), BIND_EXPR,
16988 : void_type_node, NULL_TREE,
16989 280 : OMP_CLAUSE_REDUCTION_MERGE (c), NULL_TREE);
16990 280 : TREE_SIDE_EFFECTS (OMP_CLAUSE_REDUCTION_MERGE (c)) = 1;
16991 280 : if (TREE_VEC_LENGTH (list) == 6)
16992 : {
16993 236 : if (TREE_ADDRESSABLE (TREE_VEC_ELT (list, 3)))
16994 70 : c_mark_addressable (decl_placeholder ? decl_placeholder
16995 33 : : OMP_CLAUSE_DECL (c));
16996 236 : if (TREE_ADDRESSABLE (TREE_VEC_ELT (list, 4)))
16997 30 : c_mark_addressable (placeholder);
16998 236 : tree init = TREE_VEC_ELT (list, 5);
16999 236 : if (init == error_mark_node)
17000 200 : init = DECL_INITIAL (TREE_VEC_ELT (list, 3));
17001 236 : OMP_CLAUSE_REDUCTION_INIT (c)
17002 660 : = c_clone_omp_udr (init, TREE_VEC_ELT (list, 4),
17003 236 : TREE_VEC_ELT (list, 3),
17004 : decl_placeholder ? decl_placeholder
17005 188 : : OMP_CLAUSE_DECL (c), placeholder);
17006 236 : if (TREE_VEC_ELT (list, 5) == error_mark_node)
17007 : {
17008 200 : tree v = decl_placeholder ? decl_placeholder : t;
17009 200 : OMP_CLAUSE_REDUCTION_INIT (c)
17010 400 : = build2 (INIT_EXPR, TREE_TYPE (v), v,
17011 200 : OMP_CLAUSE_REDUCTION_INIT (c));
17012 : }
17013 236 : if (walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c),
17014 : c_find_omp_placeholder_r,
17015 : placeholder, NULL))
17016 31 : OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c) = 1;
17017 : }
17018 : else
17019 : {
17020 44 : tree init;
17021 44 : tree v = decl_placeholder ? decl_placeholder : t;
17022 44 : if (AGGREGATE_TYPE_P (TREE_TYPE (v)))
17023 34 : init = build_constructor (TREE_TYPE (v), NULL);
17024 : else
17025 10 : init = fold_convert (TREE_TYPE (v), integer_zero_node);
17026 44 : OMP_CLAUSE_REDUCTION_INIT (c)
17027 88 : = build2 (INIT_EXPR, TREE_TYPE (v), v, init);
17028 : }
17029 280 : OMP_CLAUSE_REDUCTION_INIT (c)
17030 280 : = build3_loc (OMP_CLAUSE_LOCATION (c), BIND_EXPR,
17031 : void_type_node, NULL_TREE,
17032 280 : OMP_CLAUSE_REDUCTION_INIT (c), NULL_TREE);
17033 280 : TREE_SIDE_EFFECTS (OMP_CLAUSE_REDUCTION_INIT (c)) = 1;
17034 : }
17035 4162 : if (TREE_CODE (t) == MEM_REF)
17036 : {
17037 607 : if (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t))) == NULL_TREE
17038 607 : || TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t))))
17039 : != INTEGER_CST)
17040 : {
17041 0 : sorry ("variable length element type in array "
17042 : "%<reduction%> clause");
17043 0 : remove = true;
17044 0 : break;
17045 : }
17046 607 : t = TREE_OPERAND (t, 0);
17047 607 : if (TREE_CODE (t) == POINTER_PLUS_EXPR)
17048 139 : t = TREE_OPERAND (t, 0);
17049 607 : if (TREE_CODE (t) == ADDR_EXPR)
17050 367 : t = TREE_OPERAND (t, 0);
17051 : }
17052 4162 : goto check_dup_generic_t;
17053 :
17054 24 : case OMP_CLAUSE_COPYPRIVATE:
17055 24 : copyprivate_seen = true;
17056 24 : if (nowait_clause)
17057 : {
17058 1 : error_at (OMP_CLAUSE_LOCATION (*nowait_clause),
17059 : "%<nowait%> clause must not be used together "
17060 : "with %<copyprivate%> clause");
17061 1 : *nowait_clause = OMP_CLAUSE_CHAIN (*nowait_clause);
17062 1 : nowait_clause = NULL;
17063 : }
17064 24 : goto check_dup_generic;
17065 :
17066 100 : case OMP_CLAUSE_COPYIN:
17067 100 : t = OMP_CLAUSE_DECL (c);
17068 100 : if (!VAR_P (t) || !DECL_THREAD_LOCAL_P (t))
17069 : {
17070 5 : error_at (OMP_CLAUSE_LOCATION (c),
17071 : "%qE must be %<threadprivate%> for %<copyin%>", t);
17072 5 : remove = true;
17073 5 : break;
17074 : }
17075 95 : goto check_dup_generic;
17076 :
17077 480 : case OMP_CLAUSE_LINEAR:
17078 480 : if (ort != C_ORT_OMP_DECLARE_SIMD)
17079 327 : need_implicitly_determined = true;
17080 480 : t = OMP_CLAUSE_DECL (c);
17081 480 : if (ort != C_ORT_OMP_DECLARE_SIMD
17082 327 : && OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_DEFAULT
17083 485 : && OMP_CLAUSE_LINEAR_OLD_LINEAR_MODIFIER (c))
17084 : {
17085 5 : error_at (OMP_CLAUSE_LOCATION (c),
17086 : "modifier should not be specified in %<linear%> "
17087 : "clause on %<simd%> or %<for%> constructs when not "
17088 : "using OpenMP 5.2 modifiers");
17089 5 : OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT;
17090 : }
17091 960 : if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
17092 503 : && TREE_CODE (TREE_TYPE (t)) != POINTER_TYPE)
17093 : {
17094 1 : error_at (OMP_CLAUSE_LOCATION (c),
17095 : "linear clause applied to non-integral non-pointer "
17096 1 : "variable with type %qT", TREE_TYPE (t));
17097 1 : remove = true;
17098 1 : break;
17099 : }
17100 479 : if (TYPE_ATOMIC (TREE_TYPE (t)))
17101 : {
17102 3 : error_at (OMP_CLAUSE_LOCATION (c),
17103 : "%<_Atomic%> %qD in %<linear%> clause", t);
17104 3 : remove = true;
17105 3 : break;
17106 : }
17107 476 : if (ort == C_ORT_OMP_DECLARE_SIMD)
17108 : {
17109 152 : tree s = OMP_CLAUSE_LINEAR_STEP (c);
17110 152 : if (TREE_CODE (s) == PARM_DECL)
17111 : {
17112 9 : OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c) = 1;
17113 : /* map_head bitmap is used as uniform_head if
17114 : declare_simd. */
17115 9 : if (!bitmap_bit_p (&map_head, DECL_UID (s)))
17116 5 : linear_variable_step_check = true;
17117 9 : goto check_dup_generic;
17118 : }
17119 143 : if (TREE_CODE (s) != INTEGER_CST)
17120 : {
17121 7 : error_at (OMP_CLAUSE_LOCATION (c),
17122 : "%<linear%> clause step %qE is neither constant "
17123 : "nor a parameter", s);
17124 7 : remove = true;
17125 7 : break;
17126 : }
17127 : }
17128 460 : if (TREE_CODE (TREE_TYPE (OMP_CLAUSE_DECL (c))) == POINTER_TYPE)
17129 : {
17130 20 : tree s = OMP_CLAUSE_LINEAR_STEP (c);
17131 20 : s = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
17132 20 : OMP_CLAUSE_DECL (c), s);
17133 20 : s = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
17134 : sizetype, fold_convert (sizetype, s),
17135 20 : fold_convert
17136 : (sizetype, OMP_CLAUSE_DECL (c)));
17137 20 : if (s == error_mark_node)
17138 0 : s = size_one_node;
17139 20 : OMP_CLAUSE_LINEAR_STEP (c) = s;
17140 : }
17141 : else
17142 440 : OMP_CLAUSE_LINEAR_STEP (c)
17143 880 : = fold_convert (TREE_TYPE (t), OMP_CLAUSE_LINEAR_STEP (c));
17144 460 : goto check_dup_generic;
17145 :
17146 2892 : check_dup_generic:
17147 2892 : t = OMP_CLAUSE_DECL (c);
17148 7143 : check_dup_generic_t:
17149 7143 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
17150 : {
17151 4 : error_at (OMP_CLAUSE_LOCATION (c),
17152 : "%qE is not a variable in clause %qs", t,
17153 2 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
17154 2 : remove = true;
17155 : }
17156 1149 : else if ((openacc && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
17157 6102 : || (ort == C_ORT_OMP
17158 5381 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
17159 5370 : || (OMP_CLAUSE_CODE (c)
17160 : == OMP_CLAUSE_USE_DEVICE_ADDR)))
17161 13196 : || (ort == C_ORT_OMP_TARGET
17162 349 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION))
17163 : {
17164 1196 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
17165 1196 : && (bitmap_bit_p (&generic_head, DECL_UID (t))
17166 109 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))))
17167 : {
17168 2 : error_at (OMP_CLAUSE_LOCATION (c),
17169 : "%qD appears more than once in data-sharing "
17170 : "clauses", t);
17171 2 : remove = true;
17172 2 : break;
17173 : }
17174 1194 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION)
17175 108 : target_in_reduction_seen = true;
17176 1194 : if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
17177 : {
17178 4 : error_at (OMP_CLAUSE_LOCATION (c),
17179 : openacc
17180 : ? "%qD appears more than once in reduction clauses"
17181 : : "%qD appears more than once in data clauses",
17182 : t);
17183 2 : remove = true;
17184 : }
17185 : else
17186 1192 : bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
17187 : }
17188 5945 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
17189 5922 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
17190 5921 : || bitmap_bit_p (&lastprivate_head, DECL_UID (t))
17191 11866 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
17192 : {
17193 24 : error_at (OMP_CLAUSE_LOCATION (c),
17194 : "%qE appears more than once in data clauses", t);
17195 24 : remove = true;
17196 : }
17197 5921 : else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
17198 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR
17199 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
17200 1051 : && bitmap_bit_p (&map_head, DECL_UID (t)))
17201 : {
17202 3 : if (openacc)
17203 0 : error_at (OMP_CLAUSE_LOCATION (c),
17204 : "%qD appears more than once in data clauses", t);
17205 : else
17206 3 : error_at (OMP_CLAUSE_LOCATION (c),
17207 : "%qD appears both in data and map clauses", t);
17208 : remove = true;
17209 : }
17210 : else
17211 5918 : bitmap_set_bit (&generic_head, DECL_UID (t));
17212 : break;
17213 :
17214 1350 : case OMP_CLAUSE_FIRSTPRIVATE:
17215 1350 : if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c) && !implicit_moved)
17216 : {
17217 153 : move_implicit:
17218 153 : implicit_moved = true;
17219 : /* Move firstprivate and map clauses with
17220 : OMP_CLAUSE_{FIRSTPRIVATE,MAP}_IMPLICIT set to the end of
17221 : clauses chain. */
17222 153 : tree cl1 = NULL_TREE, cl2 = NULL_TREE;
17223 153 : tree *pc1 = pc, *pc2 = &cl1, *pc3 = &cl2;
17224 972 : while (*pc1)
17225 819 : if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_FIRSTPRIVATE
17226 819 : && OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (*pc1))
17227 : {
17228 113 : *pc3 = *pc1;
17229 113 : pc3 = &OMP_CLAUSE_CHAIN (*pc3);
17230 113 : *pc1 = OMP_CLAUSE_CHAIN (*pc1);
17231 : }
17232 706 : else if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_MAP
17233 706 : && OMP_CLAUSE_MAP_IMPLICIT (*pc1))
17234 : {
17235 131 : *pc2 = *pc1;
17236 131 : pc2 = &OMP_CLAUSE_CHAIN (*pc2);
17237 131 : *pc1 = OMP_CLAUSE_CHAIN (*pc1);
17238 : }
17239 : else
17240 575 : pc1 = &OMP_CLAUSE_CHAIN (*pc1);
17241 153 : *pc3 = NULL;
17242 153 : *pc2 = cl2;
17243 153 : *pc1 = cl1;
17244 153 : continue;
17245 153 : }
17246 1255 : t = OMP_CLAUSE_DECL (c);
17247 1255 : need_complete = true;
17248 1255 : need_implicitly_determined = true;
17249 1255 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
17250 : {
17251 1 : error_at (OMP_CLAUSE_LOCATION (c),
17252 : "%qE is not a variable in clause %<firstprivate%>", t);
17253 1 : remove = true;
17254 : }
17255 1254 : else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
17256 113 : && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c)
17257 1360 : && bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
17258 : remove = true;
17259 1254 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
17260 1252 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
17261 2505 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
17262 : {
17263 4 : error_at (OMP_CLAUSE_LOCATION (c),
17264 : "%qE appears more than once in data clauses", t);
17265 4 : remove = true;
17266 : }
17267 1250 : else if (bitmap_bit_p (&map_head, DECL_UID (t))
17268 1250 : || bitmap_bit_p (&map_field_head, DECL_UID (t)))
17269 : {
17270 7 : if (openacc)
17271 0 : error_at (OMP_CLAUSE_LOCATION (c),
17272 : "%qD appears more than once in data clauses", t);
17273 7 : else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
17274 7 : && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c))
17275 : /* Silently drop the clause. */;
17276 : else
17277 6 : error_at (OMP_CLAUSE_LOCATION (c),
17278 : "%qD appears both in data and map clauses", t);
17279 : remove = true;
17280 : }
17281 : else
17282 1243 : bitmap_set_bit (&firstprivate_head, DECL_UID (t));
17283 : break;
17284 :
17285 1524 : case OMP_CLAUSE_LASTPRIVATE:
17286 1524 : t = OMP_CLAUSE_DECL (c);
17287 1524 : need_complete = true;
17288 1524 : need_implicitly_determined = true;
17289 1524 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
17290 : {
17291 0 : error_at (OMP_CLAUSE_LOCATION (c),
17292 : "%qE is not a variable in clause %<lastprivate%>", t);
17293 0 : remove = true;
17294 : }
17295 1524 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
17296 1524 : || bitmap_bit_p (&lastprivate_head, DECL_UID (t)))
17297 : {
17298 3 : error_at (OMP_CLAUSE_LOCATION (c),
17299 : "%qE appears more than once in data clauses", t);
17300 3 : remove = true;
17301 : }
17302 : else
17303 1521 : bitmap_set_bit (&lastprivate_head, DECL_UID (t));
17304 : break;
17305 :
17306 253 : case OMP_CLAUSE_ALIGNED:
17307 253 : t = OMP_CLAUSE_DECL (c);
17308 253 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
17309 : {
17310 0 : error_at (OMP_CLAUSE_LOCATION (c),
17311 : "%qE is not a variable in %<aligned%> clause", t);
17312 0 : remove = true;
17313 : }
17314 289 : else if (!POINTER_TYPE_P (TREE_TYPE (t))
17315 289 : && TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE)
17316 : {
17317 7 : error_at (OMP_CLAUSE_LOCATION (c),
17318 : "%qE in %<aligned%> clause is neither a pointer nor "
17319 : "an array", t);
17320 7 : remove = true;
17321 : }
17322 246 : else if (TYPE_ATOMIC (TREE_TYPE (t)))
17323 : {
17324 1 : error_at (OMP_CLAUSE_LOCATION (c),
17325 : "%<_Atomic%> %qD in %<aligned%> clause", t);
17326 1 : remove = true;
17327 1 : break;
17328 : }
17329 245 : else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
17330 : {
17331 0 : error_at (OMP_CLAUSE_LOCATION (c),
17332 : "%qE appears more than once in %<aligned%> clauses",
17333 : t);
17334 0 : remove = true;
17335 : }
17336 : else
17337 245 : bitmap_set_bit (&aligned_head, DECL_UID (t));
17338 : break;
17339 :
17340 125 : case OMP_CLAUSE_NONTEMPORAL:
17341 125 : t = OMP_CLAUSE_DECL (c);
17342 125 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
17343 : {
17344 0 : error_at (OMP_CLAUSE_LOCATION (c),
17345 : "%qE is not a variable in %<nontemporal%> clause", t);
17346 0 : remove = true;
17347 : }
17348 125 : else if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
17349 : {
17350 2 : error_at (OMP_CLAUSE_LOCATION (c),
17351 : "%qE appears more than once in %<nontemporal%> "
17352 : "clauses", t);
17353 2 : remove = true;
17354 : }
17355 : else
17356 123 : bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
17357 : break;
17358 :
17359 814 : case OMP_CLAUSE_ALLOCATE:
17360 814 : t = OMP_CLAUSE_DECL (c);
17361 814 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
17362 : {
17363 1 : error_at (OMP_CLAUSE_LOCATION (c),
17364 : "%qE is not a variable in %<allocate%> clause", t);
17365 1 : remove = true;
17366 : }
17367 813 : else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
17368 : {
17369 2 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
17370 : "%qE appears more than once in %<allocate%> clauses",
17371 : t);
17372 2 : remove = true;
17373 : }
17374 : else
17375 : {
17376 811 : bitmap_set_bit (&aligned_head, DECL_UID (t));
17377 811 : if (!OMP_CLAUSE_ALLOCATE_COMBINED (c))
17378 711 : allocate_seen = true;
17379 : }
17380 : break;
17381 :
17382 357 : case OMP_CLAUSE_DOACROSS:
17383 357 : t = OMP_CLAUSE_DECL (c);
17384 357 : if (t == NULL_TREE)
17385 : break;
17386 169 : if (OMP_CLAUSE_DOACROSS_KIND (c) == OMP_CLAUSE_DOACROSS_SINK)
17387 : {
17388 169 : gcc_assert (TREE_CODE (t) == TREE_LIST);
17389 1315 : for (; t; t = TREE_CHAIN (t))
17390 : {
17391 1146 : tree decl = TREE_VALUE (t);
17392 1146 : if (TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE)
17393 : {
17394 3 : tree offset = TREE_PURPOSE (t);
17395 3 : bool neg = wi::neg_p (wi::to_wide (offset));
17396 3 : offset = fold_unary (ABS_EXPR, TREE_TYPE (offset), offset);
17397 6 : tree t2 = pointer_int_sum (OMP_CLAUSE_LOCATION (c),
17398 : neg ? MINUS_EXPR : PLUS_EXPR,
17399 : decl, offset);
17400 3 : t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
17401 : sizetype,
17402 : fold_convert (sizetype, t2),
17403 : fold_convert (sizetype, decl));
17404 3 : if (t2 == error_mark_node)
17405 : {
17406 : remove = true;
17407 : break;
17408 : }
17409 3 : TREE_PURPOSE (t) = t2;
17410 : }
17411 : }
17412 : break;
17413 : }
17414 0 : gcc_unreachable ();
17415 :
17416 64 : case OMP_CLAUSE_USES_ALLOCATORS:
17417 64 : t = OMP_CLAUSE_USES_ALLOCATORS_ALLOCATOR (c);
17418 64 : if (t == error_mark_node)
17419 : {
17420 : remove = true;
17421 : break;
17422 : }
17423 8 : if ((VAR_P (t) || TREE_CODE (t) == PARM_DECL)
17424 60 : && (bitmap_bit_p (&generic_head, DECL_UID (t))
17425 52 : || bitmap_bit_p (&map_head, DECL_UID (t))
17426 52 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
17427 51 : || bitmap_bit_p (&lastprivate_head, DECL_UID (t))))
17428 : {
17429 1 : error_at (OMP_CLAUSE_LOCATION (c),
17430 : "%qE appears more than once in data clauses", t);
17431 1 : remove = true;
17432 1 : break;
17433 : }
17434 : else
17435 58 : bitmap_set_bit (&generic_head, DECL_UID (t));
17436 58 : if (TREE_CODE (TREE_TYPE (t)) != ENUMERAL_TYPE
17437 113 : || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (TREE_TYPE (t))),
17438 : "omp_allocator_handle_t") != 0)
17439 : {
17440 3 : error_at (OMP_CLAUSE_LOCATION (c),
17441 : "allocator %qE must be of %<omp_allocator_handle_t%> "
17442 : "type", t);
17443 3 : remove = true;
17444 3 : break;
17445 : }
17446 55 : tree init;
17447 55 : if (!DECL_P (t)
17448 55 : || (TREE_CODE (t) == CONST_DECL
17449 7 : && ((init = DECL_INITIAL(t)) == nullptr
17450 7 : || TREE_CODE (init) != INTEGER_CST
17451 7 : || ((wi::to_widest (init) < 0
17452 7 : || wi::to_widest (init) > GOMP_OMP_PREDEF_ALLOC_MAX)
17453 0 : && (wi::to_widest (init) < GOMP_OMPX_PREDEF_ALLOC_MIN
17454 0 : || (wi::to_widest (init)
17455 0 : > GOMP_OMPX_PREDEF_ALLOC_MAX))))))
17456 : {
17457 0 : remove = true;
17458 0 : error_at (OMP_CLAUSE_LOCATION (c),
17459 : "allocator %qE must be either a variable or a "
17460 : "predefined allocator", t);
17461 0 : break;
17462 : }
17463 55 : else if (TREE_CODE (t) == CONST_DECL)
17464 : {
17465 : /* omp_null_allocator is ignored and for predefined allocators,
17466 : no special handling is required; thus, mark them removed. */
17467 7 : remove = true;
17468 :
17469 7 : if (OMP_CLAUSE_USES_ALLOCATORS_MEMSPACE (c)
17470 7 : || OMP_CLAUSE_USES_ALLOCATORS_TRAITS (c))
17471 : {
17472 0 : error_at (OMP_CLAUSE_LOCATION (c),
17473 : "modifiers cannot be used with predefined "
17474 : "allocator %qE", t);
17475 0 : break;
17476 : }
17477 : }
17478 55 : t = OMP_CLAUSE_USES_ALLOCATORS_MEMSPACE (c);
17479 55 : if (t == error_mark_node)
17480 : {
17481 : remove = true;
17482 : break;
17483 : }
17484 55 : if (t != NULL_TREE
17485 55 : && ((TREE_CODE (t) != CONST_DECL && TREE_CODE (t) != INTEGER_CST)
17486 11 : || TREE_CODE (TREE_TYPE (t)) != ENUMERAL_TYPE
17487 20 : || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (TREE_TYPE (t))),
17488 : "omp_memspace_handle_t") != 0))
17489 : {
17490 1 : error_at (OMP_CLAUSE_LOCATION (c), "memspace modifier %qE must be"
17491 : " constant enum of %<omp_memspace_handle_t%> type", t);
17492 1 : remove = true;
17493 1 : break;
17494 : }
17495 54 : t = OMP_CLAUSE_USES_ALLOCATORS_TRAITS (c);
17496 54 : if (t == error_mark_node)
17497 : {
17498 : remove = true;
17499 : break;
17500 : }
17501 54 : if (t != NULL_TREE
17502 : && t != error_mark_node
17503 54 : && (DECL_EXTERNAL (t)
17504 25 : || TREE_CODE (t) == PARM_DECL))
17505 : {
17506 3 : error_at (OMP_CLAUSE_LOCATION (c), "traits array %qE must be "
17507 : "defined in same scope as the construct on which the "
17508 : "clause appears", t);
17509 3 : remove = true;
17510 : }
17511 54 : if (t != NULL_TREE)
17512 : {
17513 27 : bool type_err = false;
17514 :
17515 27 : if (TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE
17516 26 : || DECL_SIZE (t) == NULL_TREE
17517 52 : || !COMPLETE_TYPE_P (TREE_TYPE (t)))
17518 : type_err = true;
17519 : else
17520 : {
17521 25 : tree elem_t = TREE_TYPE (TREE_TYPE (t));
17522 25 : if (TREE_CODE (elem_t) != RECORD_TYPE
17523 50 : || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (elem_t)),
17524 : "omp_alloctrait_t") != 0
17525 50 : || !TYPE_READONLY (elem_t))
17526 : type_err = true;
17527 : }
17528 24 : if (type_err)
17529 : {
17530 3 : if (t != error_mark_node)
17531 3 : error_at (OMP_CLAUSE_LOCATION (c), "traits array %qE must "
17532 : "be of %<const omp_alloctrait_t []%> type", t);
17533 : else
17534 0 : error_at (OMP_CLAUSE_LOCATION (c), "traits array must "
17535 : "be of %<const omp_alloctrait_t []%> type");
17536 : remove = true;
17537 : }
17538 : else
17539 : {
17540 24 : tree cst_val = decl_constant_value_1 (t, true);
17541 24 : if (cst_val == t)
17542 : {
17543 1 : error_at (OMP_CLAUSE_LOCATION (c), "traits array must be "
17544 : "initialized with constants");
17545 :
17546 1 : remove = true;
17547 : }
17548 : }
17549 : }
17550 54 : if (remove)
17551 : break;
17552 43 : pc = &OMP_CLAUSE_CHAIN (c);
17553 43 : continue;
17554 713 : case OMP_CLAUSE_DEPEND:
17555 713 : depend_clause = c;
17556 : /* FALLTHRU */
17557 875 : case OMP_CLAUSE_AFFINITY:
17558 875 : t = OMP_CLAUSE_DECL (c);
17559 875 : if (OMP_ITERATOR_DECL_P (t))
17560 : {
17561 131 : if (TREE_PURPOSE (t) != last_iterators)
17562 111 : last_iterators_remove
17563 111 : = c_omp_finish_iterators (TREE_PURPOSE (t));
17564 131 : last_iterators = TREE_PURPOSE (t);
17565 131 : t = TREE_VALUE (t);
17566 131 : if (last_iterators_remove)
17567 34 : t = error_mark_node;
17568 : }
17569 : else
17570 : last_iterators = NULL_TREE;
17571 875 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
17572 : {
17573 418 : if (handle_omp_array_sections (c, ort))
17574 : remove = true;
17575 336 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
17576 336 : && OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ)
17577 : {
17578 1 : error_at (OMP_CLAUSE_LOCATION (c),
17579 : "%<depend%> clause with %<depobj%> dependence "
17580 : "type on array section");
17581 1 : remove = true;
17582 : }
17583 : break;
17584 : }
17585 457 : if (t == error_mark_node)
17586 : remove = true;
17587 423 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
17588 423 : && t == ridpointers[RID_OMP_ALL_MEMORY])
17589 : {
17590 15 : if (OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_OUT
17591 15 : && OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_INOUT)
17592 : {
17593 3 : error_at (OMP_CLAUSE_LOCATION (c),
17594 : "%<omp_all_memory%> used with %<depend%> kind "
17595 : "other than %<out%> or %<inout%>");
17596 3 : remove = true;
17597 : }
17598 : }
17599 408 : else if (!lvalue_p (t))
17600 : {
17601 6 : error_at (OMP_CLAUSE_LOCATION (c),
17602 : "%qE is not lvalue expression nor array section in "
17603 : "%qs clause", t,
17604 3 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
17605 3 : remove = true;
17606 : }
17607 405 : else if (TREE_CODE (t) == COMPONENT_REF
17608 405 : && DECL_C_BIT_FIELD (TREE_OPERAND (t, 1)))
17609 : {
17610 2 : gcc_assert (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
17611 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY);
17612 2 : error_at (OMP_CLAUSE_LOCATION (c),
17613 : "bit-field %qE in %qs clause", t,
17614 2 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
17615 2 : remove = true;
17616 : }
17617 403 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
17618 403 : && OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ)
17619 : {
17620 20 : if (!c_omp_depend_t_p (TREE_TYPE (t)))
17621 : {
17622 2 : error_at (OMP_CLAUSE_LOCATION (c),
17623 : "%qE does not have %<omp_depend_t%> type in "
17624 : "%<depend%> clause with %<depobj%> dependence "
17625 : "type", t);
17626 2 : remove = true;
17627 : }
17628 : }
17629 383 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
17630 383 : && c_omp_depend_t_p (TREE_TYPE (t)))
17631 : {
17632 2 : error_at (OMP_CLAUSE_LOCATION (c),
17633 : "%qE should not have %<omp_depend_t%> type in "
17634 : "%<depend%> clause with dependence type other than "
17635 : "%<depobj%>", t);
17636 2 : remove = true;
17637 : }
17638 12 : if (!remove)
17639 : {
17640 411 : if (t == ridpointers[RID_OMP_ALL_MEMORY])
17641 12 : t = null_pointer_node;
17642 : else
17643 : {
17644 399 : tree addr = build_unary_op (OMP_CLAUSE_LOCATION (c),
17645 : ADDR_EXPR, t, false);
17646 399 : if (addr == error_mark_node)
17647 : {
17648 : remove = true;
17649 : break;
17650 : }
17651 399 : t = build_indirect_ref (OMP_CLAUSE_LOCATION (c), addr,
17652 : RO_UNARY_STAR);
17653 399 : if (t == error_mark_node)
17654 : {
17655 : remove = true;
17656 : break;
17657 : }
17658 : }
17659 411 : if (OMP_ITERATOR_DECL_P (OMP_CLAUSE_DECL (c)))
17660 31 : TREE_VALUE (OMP_CLAUSE_DECL (c)) = t;
17661 : else
17662 380 : OMP_CLAUSE_DECL (c) = t;
17663 : }
17664 : break;
17665 :
17666 6785 : case OMP_CLAUSE_MAP:
17667 6785 : if (OMP_CLAUSE_MAP_IMPLICIT (c) && !implicit_moved)
17668 58 : goto move_implicit;
17669 6727 : if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_PUSH_MAPPER_NAME
17670 6727 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POP_MAPPER_NAME)
17671 : {
17672 : remove = true;
17673 : break;
17674 : }
17675 : /* FALLTHRU */
17676 9619 : case OMP_CLAUSE_TO:
17677 9619 : case OMP_CLAUSE_FROM:
17678 9619 : if (OMP_CLAUSE_ITERATORS (c)
17679 9619 : && c_omp_finish_iterators (OMP_CLAUSE_ITERATORS (c)))
17680 : {
17681 23159 : t = error_mark_node;
17682 : break;
17683 : }
17684 : /* FALLTHRU */
17685 9755 : case OMP_CLAUSE__CACHE_:
17686 9755 : {
17687 9755 : using namespace omp_addr_tokenizer;
17688 9755 : auto_vec<omp_addr_token *, 10> addr_tokens;
17689 :
17690 9755 : t = OMP_CLAUSE_DECL (c);
17691 9755 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
17692 : {
17693 2019 : grp_start_p = pc;
17694 2019 : grp_sentinel = OMP_CLAUSE_CHAIN (c);
17695 :
17696 2019 : if (handle_omp_array_sections (c, ort))
17697 : remove = true;
17698 : else
17699 : {
17700 1879 : t = OMP_CLAUSE_DECL (c);
17701 1879 : if (!omp_mappable_type (TREE_TYPE (t)))
17702 : {
17703 2 : error_at (OMP_CLAUSE_LOCATION (c),
17704 : "array section does not have mappable type "
17705 : "in %qs clause",
17706 1 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
17707 1 : remove = true;
17708 : }
17709 1878 : else if (TYPE_ATOMIC (TREE_TYPE (t)))
17710 : {
17711 2 : error_at (OMP_CLAUSE_LOCATION (c),
17712 : "%<_Atomic%> %qE in %qs clause", t,
17713 1 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
17714 1 : remove = true;
17715 : }
17716 2534 : while (TREE_CODE (t) == ARRAY_REF)
17717 655 : t = TREE_OPERAND (t, 0);
17718 :
17719 1879 : c_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
17720 :
17721 1879 : if (!omp_parse_expr (addr_tokens, t))
17722 : {
17723 0 : sorry_at (OMP_CLAUSE_LOCATION (c),
17724 : "unsupported map expression %qE",
17725 0 : OMP_CLAUSE_DECL (c));
17726 0 : remove = true;
17727 0 : break;
17728 : }
17729 :
17730 : /* This check is to determine if this will be the only map
17731 : node created for this clause. Otherwise, we'll check
17732 : the following FIRSTPRIVATE_POINTER or ATTACH_DETACH
17733 : node on the next iteration(s) of the loop. */
17734 1879 : if (addr_tokens.length () >= 4
17735 308 : && addr_tokens[0]->type == STRUCTURE_BASE
17736 306 : && addr_tokens[0]->u.structure_base_kind == BASE_DECL
17737 306 : && addr_tokens[1]->type == ACCESS_METHOD
17738 306 : && addr_tokens[2]->type == COMPONENT_SELECTOR
17739 306 : && addr_tokens[3]->type == ACCESS_METHOD
17740 2124 : && (addr_tokens[3]->u.access_kind == ACCESS_DIRECT
17741 192 : || (addr_tokens[3]->u.access_kind
17742 : == ACCESS_INDEXED_ARRAY)))
17743 : {
17744 57 : tree rt = addr_tokens[1]->expr;
17745 :
17746 57 : gcc_assert (DECL_P (rt));
17747 :
17748 57 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
17749 52 : && OMP_CLAUSE_MAP_IMPLICIT (c)
17750 57 : && (bitmap_bit_p (&map_head, DECL_UID (rt))
17751 0 : || bitmap_bit_p (&map_field_head, DECL_UID (rt))
17752 0 : || bitmap_bit_p (&map_firstprivate_head,
17753 0 : DECL_UID (rt))))
17754 : {
17755 : remove = true;
17756 : break;
17757 : }
17758 57 : if (bitmap_bit_p (&map_field_head, DECL_UID (rt)))
17759 : break;
17760 39 : if (bitmap_bit_p (&map_head, DECL_UID (rt)))
17761 : {
17762 0 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
17763 0 : error_at (OMP_CLAUSE_LOCATION (c),
17764 : "%qD appears more than once in motion "
17765 : "clauses", rt);
17766 0 : else if (openacc)
17767 0 : error_at (OMP_CLAUSE_LOCATION (c),
17768 : "%qD appears more than once in data "
17769 : "clauses", rt);
17770 : else
17771 0 : error_at (OMP_CLAUSE_LOCATION (c),
17772 : "%qD appears more than once in map "
17773 : "clauses", rt);
17774 : remove = true;
17775 : }
17776 : else
17777 : {
17778 39 : bitmap_set_bit (&map_head, DECL_UID (rt));
17779 39 : bitmap_set_bit (&map_field_head, DECL_UID (rt));
17780 : }
17781 : }
17782 : }
17783 2001 : if (c_oacc_check_attachments (c))
17784 2 : remove = true;
17785 2001 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
17786 1819 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
17787 1799 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
17788 2028 : && !OMP_CLAUSE_SIZE (c))
17789 : /* In this case, we have a single array element which is a
17790 : pointer, and we already set OMP_CLAUSE_SIZE in
17791 : handle_omp_array_sections above. For attach/detach
17792 : clauses, reset the OMP_CLAUSE_SIZE (representing a bias)
17793 : to zero here. */
17794 10 : OMP_CLAUSE_SIZE (c) = size_zero_node;
17795 : break;
17796 : }
17797 7736 : else if (!omp_parse_expr (addr_tokens, t))
17798 : {
17799 0 : sorry_at (OMP_CLAUSE_LOCATION (c),
17800 : "unsupported map expression %qE",
17801 0 : OMP_CLAUSE_DECL (c));
17802 0 : remove = true;
17803 0 : break;
17804 : }
17805 7736 : if (t == error_mark_node)
17806 : {
17807 : remove = true;
17808 : break;
17809 : }
17810 :
17811 7724 : tree attr;
17812 7724 : if (DECL_P (t)
17813 7135 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
17814 4312 : && (attr = lookup_attribute ("omp declare target",
17815 4312 : DECL_ATTRIBUTES (t)))
17816 7964 : && value_member (get_identifier ("local"),
17817 240 : TREE_VALUE (attr)))
17818 : {
17819 0 : error_at (OMP_CLAUSE_LOCATION (c),
17820 : "device-local variable %qD cannot appear "
17821 : "in map clause", t);
17822 0 : remove = true;
17823 0 : break;
17824 : }
17825 :
17826 : /* OpenACC attach / detach clauses must be pointers. */
17827 7724 : if (c_oacc_check_attachments (c))
17828 : {
17829 : remove = true;
17830 : break;
17831 : }
17832 7720 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
17833 4856 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
17834 4827 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
17835 7764 : && !OMP_CLAUSE_SIZE (c))
17836 : /* For attach/detach clauses, set OMP_CLAUSE_SIZE (representing a
17837 : bias) to zero here, so it is not set erroneously to the pointer
17838 : size later on in gimplify.cc. */
17839 28 : OMP_CLAUSE_SIZE (c) = size_zero_node;
17840 :
17841 7720 : c_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
17842 :
17843 7720 : if (!ai.check_clause (c))
17844 : {
17845 : remove = true;
17846 : break;
17847 : }
17848 :
17849 7712 : if (!ai.map_supported_p ())
17850 : {
17851 14 : sorry_at (OMP_CLAUSE_LOCATION (c),
17852 : "unsupported map expression %qE",
17853 7 : OMP_CLAUSE_DECL (c));
17854 7 : remove = true;
17855 7 : break;
17856 : }
17857 :
17858 15410 : gcc_assert ((addr_tokens[0]->type == ARRAY_BASE
17859 : || addr_tokens[0]->type == STRUCTURE_BASE)
17860 : && addr_tokens[1]->type == ACCESS_METHOD);
17861 :
17862 7705 : t = addr_tokens[1]->expr;
17863 :
17864 7705 : if (addr_tokens[0]->u.structure_base_kind != BASE_DECL)
17865 0 : goto skip_decl_checks;
17866 :
17867 : /* For OpenMP, we can access a struct "t" and "t.d" on the same
17868 : mapping. OpenACC allows multiple fields of the same structure
17869 : to be written. */
17870 7705 : if (addr_tokens[0]->type == STRUCTURE_BASE
17871 7705 : && (bitmap_bit_p (&map_field_head, DECL_UID (t))
17872 267 : || (!openacc && bitmap_bit_p (&map_head, DECL_UID (t)))))
17873 309 : goto skip_decl_checks;
17874 :
17875 7396 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
17876 : {
17877 3 : if (ort != C_ORT_ACC && EXPR_P (t))
17878 : break;
17879 :
17880 6 : error_at (OMP_CLAUSE_LOCATION (c),
17881 : "%qE is not a variable in %qs clause", t,
17882 3 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
17883 3 : remove = true;
17884 : }
17885 7393 : else if (VAR_P (t) && DECL_THREAD_LOCAL_P (t))
17886 : {
17887 0 : error_at (OMP_CLAUSE_LOCATION (c),
17888 : "%qD is threadprivate variable in %qs clause", t,
17889 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
17890 0 : remove = true;
17891 : }
17892 7393 : else if ((OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
17893 4556 : || (OMP_CLAUSE_MAP_KIND (c)
17894 : != GOMP_MAP_FIRSTPRIVATE_POINTER))
17895 10905 : && !c_mark_addressable (t))
17896 : remove = true;
17897 7393 : else if (!(OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
17898 4556 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
17899 4556 : || (OMP_CLAUSE_MAP_KIND (c)
17900 : == GOMP_MAP_FIRSTPRIVATE_POINTER)
17901 3512 : || (OMP_CLAUSE_MAP_KIND (c)
17902 : == GOMP_MAP_FORCE_DEVICEPTR)))
17903 6291 : && t == OMP_CLAUSE_DECL (c)
17904 13419 : && !omp_mappable_type (TREE_TYPE (t)))
17905 : {
17906 16 : error_at (OMP_CLAUSE_LOCATION (c),
17907 : "%qD does not have a mappable type in %qs clause", t,
17908 8 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
17909 8 : remove = true;
17910 : }
17911 7385 : else if (TREE_TYPE (t) == error_mark_node)
17912 : remove = true;
17913 7384 : else if (TYPE_ATOMIC (strip_array_types (TREE_TYPE (t))))
17914 : {
17915 8 : error_at (OMP_CLAUSE_LOCATION (c),
17916 : "%<_Atomic%> %qE in %qs clause", t,
17917 4 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
17918 4 : remove = true;
17919 : }
17920 7380 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
17921 4546 : && OMP_CLAUSE_MAP_IMPLICIT (c)
17922 7511 : && (bitmap_bit_p (&map_head, DECL_UID (t))
17923 130 : || bitmap_bit_p (&map_field_head, DECL_UID (t))
17924 130 : || bitmap_bit_p (&map_firstprivate_head,
17925 130 : DECL_UID (t))))
17926 : remove = true;
17927 7378 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
17928 7378 : && (OMP_CLAUSE_MAP_KIND (c)
17929 : == GOMP_MAP_FIRSTPRIVATE_POINTER))
17930 : {
17931 1042 : if (bitmap_bit_p (&generic_head, DECL_UID (t))
17932 1042 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
17933 2083 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
17934 : {
17935 4 : error_at (OMP_CLAUSE_LOCATION (c),
17936 : "%qD appears more than once in data clauses", t);
17937 4 : remove = true;
17938 : }
17939 1038 : else if (bitmap_bit_p (&map_head, DECL_UID (t))
17940 4 : && !bitmap_bit_p (&map_field_head, DECL_UID (t))
17941 1040 : && openacc)
17942 : {
17943 1 : error_at (OMP_CLAUSE_LOCATION (c),
17944 : "%qD appears more than once in data clauses", t);
17945 1 : remove = true;
17946 : }
17947 : else
17948 1037 : bitmap_set_bit (&map_firstprivate_head, DECL_UID (t));
17949 : }
17950 6336 : else if (bitmap_bit_p (&map_head, DECL_UID (t))
17951 67 : && !bitmap_bit_p (&map_field_head, DECL_UID (t))
17952 20 : && ort != C_ORT_OMP
17953 20 : && ort != C_ORT_OMP_TARGET
17954 6346 : && ort != C_ORT_OMP_EXIT_DATA)
17955 : {
17956 7 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
17957 0 : error_at (OMP_CLAUSE_LOCATION (c),
17958 : "%qD appears more than once in motion clauses", t);
17959 7 : else if (openacc)
17960 7 : error_at (OMP_CLAUSE_LOCATION (c),
17961 : "%qD appears more than once in data clauses", t);
17962 : else
17963 0 : error_at (OMP_CLAUSE_LOCATION (c),
17964 : "%qD appears more than once in map clauses", t);
17965 : remove = true;
17966 : }
17967 6329 : else if (openacc && bitmap_bit_p (&generic_head, DECL_UID (t)))
17968 : {
17969 0 : error_at (OMP_CLAUSE_LOCATION (c),
17970 : "%qD appears more than once in data clauses", t);
17971 0 : remove = true;
17972 : }
17973 6329 : else if (bitmap_bit_p (&firstprivate_head, DECL_UID (t))
17974 6329 : || bitmap_bit_p (&is_on_device_head, DECL_UID (t)))
17975 : {
17976 9 : if (openacc)
17977 0 : error_at (OMP_CLAUSE_LOCATION (c),
17978 : "%qD appears more than once in data clauses", t);
17979 : else
17980 9 : error_at (OMP_CLAUSE_LOCATION (c),
17981 : "%qD appears both in data and map clauses", t);
17982 : remove = true;
17983 : }
17984 6320 : else if (!omp_access_chain_p (addr_tokens, 1))
17985 : {
17986 6320 : bitmap_set_bit (&map_head, DECL_UID (t));
17987 6320 : if (t != OMP_CLAUSE_DECL (c)
17988 6320 : && TREE_CODE (OMP_CLAUSE_DECL (c)) == COMPONENT_REF)
17989 261 : bitmap_set_bit (&map_field_head, DECL_UID (t));
17990 : }
17991 :
17992 0 : skip_decl_checks:
17993 : /* If we call omp_expand_map_clause in handle_omp_array_sections,
17994 : the containing loop (here) iterates through the new nodes
17995 : created by that expansion. Avoid expanding those again (just
17996 : by checking the node type). */
17997 7705 : if (!remove
17998 7705 : && ort != C_ORT_DECLARE_SIMD
17999 7705 : && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
18000 4806 : || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FIRSTPRIVATE_POINTER
18001 3769 : && (OMP_CLAUSE_MAP_KIND (c)
18002 : != GOMP_MAP_FIRSTPRIVATE_REFERENCE)
18003 3769 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ALWAYS_POINTER
18004 3769 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH_DETACH
18005 3464 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
18006 3435 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH)))
18007 : {
18008 6280 : grp_start_p = pc;
18009 6280 : grp_sentinel = OMP_CLAUSE_CHAIN (c);
18010 6280 : tree nc = ai.expand_map_clause (c, OMP_CLAUSE_DECL (c),
18011 : addr_tokens, ort);
18012 6280 : if (nc != error_mark_node)
18013 6280 : c = nc;
18014 : }
18015 9770 : }
18016 7705 : break;
18017 :
18018 276 : case OMP_CLAUSE_ENTER:
18019 276 : case OMP_CLAUSE_LINK:
18020 276 : case OMP_CLAUSE_LOCAL:
18021 276 : t = OMP_CLAUSE_DECL (c);
18022 276 : const char *cname;
18023 276 : cname = omp_clause_code_name[OMP_CLAUSE_CODE (c)];
18024 276 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER
18025 276 : && OMP_CLAUSE_ENTER_TO (c))
18026 : cname = "to";
18027 276 : if (TREE_CODE (t) == FUNCTION_DECL
18028 276 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
18029 : ;
18030 194 : else if (!VAR_P (t))
18031 : {
18032 1 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
18033 0 : error_at (OMP_CLAUSE_LOCATION (c),
18034 : "%qE is neither a variable nor a function name in "
18035 : "clause %qs", t, cname);
18036 : else
18037 1 : error_at (OMP_CLAUSE_LOCATION (c),
18038 : "%qE is not a variable in clause %qs", t, cname);
18039 : remove = true;
18040 : }
18041 193 : else if (DECL_THREAD_LOCAL_P (t))
18042 : {
18043 2 : error_at (OMP_CLAUSE_LOCATION (c),
18044 : "%qD is threadprivate variable in %qs clause", t,
18045 : cname);
18046 2 : remove = true;
18047 : }
18048 191 : else if (!omp_mappable_type (TREE_TYPE (t)))
18049 : {
18050 6 : error_at (OMP_CLAUSE_LOCATION (c),
18051 : "%qD does not have a mappable type in %qs clause", t,
18052 : cname);
18053 6 : remove = true;
18054 : }
18055 9 : if (remove)
18056 : break;
18057 267 : if (bitmap_bit_p (&generic_head, DECL_UID (t)))
18058 : {
18059 10 : error_at (OMP_CLAUSE_LOCATION (c),
18060 : "%qE appears more than once on the same "
18061 : "%<declare target%> directive", t);
18062 10 : remove = true;
18063 : }
18064 : else
18065 257 : bitmap_set_bit (&generic_head, DECL_UID (t));
18066 : break;
18067 :
18068 117 : case OMP_CLAUSE_UNIFORM:
18069 117 : t = OMP_CLAUSE_DECL (c);
18070 117 : if (TREE_CODE (t) != PARM_DECL)
18071 : {
18072 0 : if (DECL_P (t))
18073 0 : error_at (OMP_CLAUSE_LOCATION (c),
18074 : "%qD is not an argument in %<uniform%> clause", t);
18075 : else
18076 0 : error_at (OMP_CLAUSE_LOCATION (c),
18077 : "%qE is not an argument in %<uniform%> clause", t);
18078 : remove = true;
18079 : break;
18080 : }
18081 : /* map_head bitmap is used as uniform_head if declare_simd. */
18082 117 : bitmap_set_bit (&map_head, DECL_UID (t));
18083 117 : goto check_dup_generic;
18084 :
18085 161 : case OMP_CLAUSE_IS_DEVICE_PTR:
18086 161 : case OMP_CLAUSE_USE_DEVICE_PTR:
18087 161 : t = OMP_CLAUSE_DECL (c);
18088 161 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
18089 123 : bitmap_set_bit (&is_on_device_head, DECL_UID (t));
18090 161 : if (TREE_CODE (TREE_TYPE (t)) != POINTER_TYPE)
18091 : {
18092 21 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
18093 21 : && !openacc)
18094 : {
18095 1 : error_at (OMP_CLAUSE_LOCATION (c),
18096 : "%qs variable is not a pointer",
18097 1 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
18098 1 : remove = true;
18099 : }
18100 20 : else if (TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE)
18101 : {
18102 4 : error_at (OMP_CLAUSE_LOCATION (c),
18103 : "%qs variable is neither a pointer nor an array",
18104 4 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
18105 4 : remove = true;
18106 : }
18107 : }
18108 161 : goto check_dup_generic;
18109 :
18110 89 : case OMP_CLAUSE_HAS_DEVICE_ADDR:
18111 89 : t = OMP_CLAUSE_DECL (c);
18112 89 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
18113 : {
18114 11 : if (handle_omp_array_sections (c, ort))
18115 : remove = true;
18116 : else
18117 : {
18118 11 : t = OMP_CLAUSE_DECL (c);
18119 24 : while (TREE_CODE (t) == ARRAY_REF)
18120 13 : t = TREE_OPERAND (t, 0);
18121 : }
18122 : }
18123 89 : bitmap_set_bit (&is_on_device_head, DECL_UID (t));
18124 89 : if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
18125 89 : c_mark_addressable (t);
18126 89 : goto check_dup_generic_t;
18127 :
18128 36 : case OMP_CLAUSE_USE_DEVICE_ADDR:
18129 36 : t = OMP_CLAUSE_DECL (c);
18130 36 : if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
18131 36 : c_mark_addressable (t);
18132 36 : goto check_dup_generic;
18133 :
18134 4793 : case OMP_CLAUSE_NOWAIT:
18135 4793 : if (copyprivate_seen)
18136 : {
18137 1 : error_at (OMP_CLAUSE_LOCATION (c),
18138 : "%<nowait%> clause must not be used together "
18139 : "with %<copyprivate%> clause");
18140 1 : remove = true;
18141 1 : break;
18142 : }
18143 4792 : nowait_clause = pc;
18144 4792 : pc = &OMP_CLAUSE_CHAIN (c);
18145 4792 : continue;
18146 :
18147 523 : case OMP_CLAUSE_ORDER:
18148 523 : if (ordered_clause)
18149 : {
18150 2 : error_at (OMP_CLAUSE_LOCATION (c),
18151 : "%<order%> clause must not be used together "
18152 : "with %<ordered%> clause");
18153 2 : remove = true;
18154 2 : break;
18155 : }
18156 521 : else if (order_clause)
18157 : {
18158 : /* Silently remove duplicates. */
18159 : remove = true;
18160 : break;
18161 : }
18162 513 : order_clause = pc;
18163 513 : pc = &OMP_CLAUSE_CHAIN (c);
18164 513 : continue;
18165 :
18166 32 : case OMP_CLAUSE_DETACH:
18167 32 : t = OMP_CLAUSE_DECL (c);
18168 32 : if (detach_seen)
18169 : {
18170 1 : error_at (OMP_CLAUSE_LOCATION (c),
18171 : "too many %qs clauses on a task construct",
18172 : "detach");
18173 1 : remove = true;
18174 1 : break;
18175 : }
18176 31 : detach_seen = pc;
18177 31 : pc = &OMP_CLAUSE_CHAIN (c);
18178 31 : c_mark_addressable (t);
18179 31 : continue;
18180 :
18181 14601 : case OMP_CLAUSE_IF:
18182 14601 : case OMP_CLAUSE_SELF:
18183 14601 : case OMP_CLAUSE_NUM_THREADS:
18184 14601 : case OMP_CLAUSE_NUM_TEAMS:
18185 14601 : case OMP_CLAUSE_THREAD_LIMIT:
18186 14601 : case OMP_CLAUSE_DEFAULT:
18187 14601 : case OMP_CLAUSE_UNTIED:
18188 14601 : case OMP_CLAUSE_COLLAPSE:
18189 14601 : case OMP_CLAUSE_FINAL:
18190 14601 : case OMP_CLAUSE_DEVICE:
18191 14601 : case OMP_CLAUSE_DIST_SCHEDULE:
18192 14601 : case OMP_CLAUSE_DYN_GROUPPRIVATE:
18193 14601 : case OMP_CLAUSE_PARALLEL:
18194 14601 : case OMP_CLAUSE_FOR:
18195 14601 : case OMP_CLAUSE_SECTIONS:
18196 14601 : case OMP_CLAUSE_TASKGROUP:
18197 14601 : case OMP_CLAUSE_PROC_BIND:
18198 14601 : case OMP_CLAUSE_DEVICE_TYPE:
18199 14601 : case OMP_CLAUSE_PRIORITY:
18200 14601 : case OMP_CLAUSE_THREADS:
18201 14601 : case OMP_CLAUSE_SIMD:
18202 14601 : case OMP_CLAUSE_HINT:
18203 14601 : case OMP_CLAUSE_FILTER:
18204 14601 : case OMP_CLAUSE_DEFAULTMAP:
18205 14601 : case OMP_CLAUSE_BIND:
18206 14601 : case OMP_CLAUSE_NUM_GANGS:
18207 14601 : case OMP_CLAUSE_NUM_WORKERS:
18208 14601 : case OMP_CLAUSE_VECTOR_LENGTH:
18209 14601 : case OMP_CLAUSE_ASYNC:
18210 14601 : case OMP_CLAUSE_WAIT:
18211 14601 : case OMP_CLAUSE_AUTO:
18212 14601 : case OMP_CLAUSE_INDEPENDENT:
18213 14601 : case OMP_CLAUSE_SEQ:
18214 14601 : case OMP_CLAUSE_GANG:
18215 14601 : case OMP_CLAUSE_WORKER:
18216 14601 : case OMP_CLAUSE_VECTOR:
18217 14601 : case OMP_CLAUSE_TILE:
18218 14601 : case OMP_CLAUSE_IF_PRESENT:
18219 14601 : case OMP_CLAUSE_FINALIZE:
18220 14601 : case OMP_CLAUSE_NOHOST:
18221 14601 : case OMP_CLAUSE_INDIRECT:
18222 14601 : case OMP_CLAUSE_NOVARIANTS:
18223 14601 : case OMP_CLAUSE_NOCONTEXT:
18224 14601 : pc = &OMP_CLAUSE_CHAIN (c);
18225 14601 : continue;
18226 :
18227 62 : case OMP_CLAUSE_GRAINSIZE:
18228 62 : grainsize_seen = pc;
18229 62 : pc = &OMP_CLAUSE_CHAIN (c);
18230 62 : continue;
18231 :
18232 50 : case OMP_CLAUSE_NUM_TASKS:
18233 50 : num_tasks_seen = true;
18234 50 : pc = &OMP_CLAUSE_CHAIN (c);
18235 50 : continue;
18236 :
18237 79 : case OMP_CLAUSE_MERGEABLE:
18238 79 : mergeable_seen = true;
18239 79 : pc = &OMP_CLAUSE_CHAIN (c);
18240 79 : continue;
18241 :
18242 18 : case OMP_CLAUSE_NOGROUP:
18243 18 : nogroup_seen = pc;
18244 18 : pc = &OMP_CLAUSE_CHAIN (c);
18245 18 : continue;
18246 :
18247 3475 : case OMP_CLAUSE_SCHEDULE:
18248 3475 : schedule_clause = c;
18249 3475 : pc = &OMP_CLAUSE_CHAIN (c);
18250 3475 : continue;
18251 :
18252 304 : case OMP_CLAUSE_ORDERED:
18253 304 : ordered_clause = c;
18254 304 : if (order_clause)
18255 : {
18256 2 : error_at (OMP_CLAUSE_LOCATION (*order_clause),
18257 : "%<order%> clause must not be used together "
18258 : "with %<ordered%> clause");
18259 2 : *order_clause = OMP_CLAUSE_CHAIN (*order_clause);
18260 2 : order_clause = NULL;
18261 : }
18262 304 : pc = &OMP_CLAUSE_CHAIN (c);
18263 304 : continue;
18264 :
18265 223 : case OMP_CLAUSE_SAFELEN:
18266 223 : safelen = c;
18267 223 : pc = &OMP_CLAUSE_CHAIN (c);
18268 223 : continue;
18269 321 : case OMP_CLAUSE_SIMDLEN:
18270 321 : simdlen = c;
18271 321 : pc = &OMP_CLAUSE_CHAIN (c);
18272 321 : continue;
18273 :
18274 69 : case OMP_CLAUSE_FULL:
18275 69 : full_seen = pc;
18276 69 : pc = &OMP_CLAUSE_CHAIN (c);
18277 69 : continue;
18278 :
18279 223 : case OMP_CLAUSE_PARTIAL:
18280 223 : partial_seen = true;
18281 223 : pc = &OMP_CLAUSE_CHAIN (c);
18282 223 : continue;
18283 :
18284 0 : case OMP_CLAUSE_SIZES:
18285 0 : pc = &OMP_CLAUSE_CHAIN (c);
18286 0 : continue;
18287 :
18288 206 : case OMP_CLAUSE_INBRANCH:
18289 206 : case OMP_CLAUSE_NOTINBRANCH:
18290 206 : if (branch_seen)
18291 : {
18292 1 : error_at (OMP_CLAUSE_LOCATION (c),
18293 : "%<inbranch%> clause is incompatible with "
18294 : "%<notinbranch%>");
18295 1 : remove = true;
18296 1 : break;
18297 : }
18298 205 : branch_seen = true;
18299 205 : pc = &OMP_CLAUSE_CHAIN (c);
18300 205 : continue;
18301 :
18302 370 : case OMP_CLAUSE_INCLUSIVE:
18303 370 : case OMP_CLAUSE_EXCLUSIVE:
18304 370 : need_complete = true;
18305 370 : need_implicitly_determined = true;
18306 370 : t = OMP_CLAUSE_DECL (c);
18307 370 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
18308 : {
18309 0 : error_at (OMP_CLAUSE_LOCATION (c),
18310 : "%qE is not a variable in clause %qs", t,
18311 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
18312 0 : remove = true;
18313 : }
18314 : break;
18315 :
18316 152 : case OMP_CLAUSE_INIT:
18317 152 : init_seen = true;
18318 152 : if (!OMP_CLAUSE_INIT_TARGETSYNC (c))
18319 71 : init_no_targetsync_clause = c;
18320 : /* FALLTHRU */
18321 242 : case OMP_CLAUSE_DESTROY:
18322 242 : case OMP_CLAUSE_USE:
18323 242 : init_use_destroy_seen = true;
18324 242 : t = OMP_CLAUSE_DECL (c);
18325 242 : if (bitmap_bit_p (&generic_head, DECL_UID (t)))
18326 : {
18327 3 : error_at (OMP_CLAUSE_LOCATION (c),
18328 : "%qD appears more than once in action clauses", t);
18329 3 : remove = true;
18330 3 : break;
18331 : }
18332 239 : bitmap_set_bit (&generic_head, DECL_UID (t));
18333 : /* FALLTHRU */
18334 298 : case OMP_CLAUSE_INTEROP:
18335 298 : if (/* ort == C_ORT_OMP_INTEROP [uncomment for depobj init] */
18336 298 : !c_omp_interop_t_p (TREE_TYPE (OMP_CLAUSE_DECL (c))))
18337 : {
18338 40 : error_at (OMP_CLAUSE_LOCATION (c),
18339 : "%qD must be of %<omp_interop_t%>",
18340 20 : OMP_CLAUSE_DECL (c));
18341 20 : remove = true;
18342 : }
18343 278 : else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INIT
18344 133 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DESTROY)
18345 318 : && TREE_READONLY (OMP_CLAUSE_DECL (c)))
18346 : {
18347 12 : error_at (OMP_CLAUSE_LOCATION (c),
18348 6 : "%qD shall not be const", OMP_CLAUSE_DECL (c));
18349 6 : remove = true;
18350 : }
18351 298 : pc = &OMP_CLAUSE_CHAIN (c);
18352 298 : break;
18353 0 : default:
18354 0 : gcc_unreachable ();
18355 25009 : }
18356 :
18357 23159 : if (!remove)
18358 : {
18359 22591 : t = OMP_CLAUSE_DECL (c);
18360 :
18361 22591 : if (need_complete)
18362 : {
18363 3978 : t = require_complete_type (OMP_CLAUSE_LOCATION (c), t);
18364 3978 : if (t == error_mark_node)
18365 7 : remove = true;
18366 : }
18367 :
18368 22591 : if (need_implicitly_determined)
18369 : {
18370 9597 : const char *share_name = NULL;
18371 :
18372 9597 : if (VAR_P (t) && DECL_THREAD_LOCAL_P (t))
18373 : share_name = "threadprivate";
18374 9591 : else switch (c_omp_predetermined_sharing (t))
18375 : {
18376 : case OMP_CLAUSE_DEFAULT_UNSPECIFIED:
18377 : break;
18378 20 : case OMP_CLAUSE_DEFAULT_SHARED:
18379 20 : if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
18380 12 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE)
18381 28 : && c_omp_predefined_variable (t))
18382 : /* The __func__ variable and similar function-local
18383 : predefined variables may be listed in a shared or
18384 : firstprivate clause. */
18385 : break;
18386 : share_name = "shared";
18387 : break;
18388 : case OMP_CLAUSE_DEFAULT_PRIVATE:
18389 : share_name = "private";
18390 : break;
18391 0 : default:
18392 0 : gcc_unreachable ();
18393 : }
18394 : if (share_name)
18395 : {
18396 20 : error_at (OMP_CLAUSE_LOCATION (c),
18397 : "%qE is predetermined %qs for %qs",
18398 : t, share_name,
18399 10 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
18400 10 : remove = true;
18401 : }
18402 9587 : else if (TREE_READONLY (t)
18403 23 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
18404 9600 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FIRSTPRIVATE)
18405 : {
18406 4 : error_at (OMP_CLAUSE_LOCATION (c),
18407 : "%<const%> qualified %qE may appear only in "
18408 : "%<shared%> or %<firstprivate%> clauses", t);
18409 4 : remove = true;
18410 : }
18411 : }
18412 : }
18413 :
18414 22591 : if (remove)
18415 : {
18416 589 : if (grp_start_p)
18417 : {
18418 : /* If we found a clause to remove, we want to remove the whole
18419 : expanded group, otherwise gimplify
18420 : (omp_resolve_clause_dependencies) can get confused. */
18421 153 : *grp_start_p = grp_sentinel;
18422 153 : pc = grp_start_p;
18423 153 : grp_start_p = NULL;
18424 : }
18425 : else
18426 436 : *pc = OMP_CLAUSE_CHAIN (c);
18427 : }
18428 : else
18429 22570 : pc = &OMP_CLAUSE_CHAIN (c);
18430 : }
18431 :
18432 29758 : if (grp_start_p
18433 29758 : && OMP_CLAUSE_HAS_ITERATORS (*grp_start_p))
18434 58 : for (tree gc = *grp_start_p; gc; gc = OMP_CLAUSE_CHAIN (gc))
18435 35 : OMP_CLAUSE_ITERATORS (gc) = OMP_CLAUSE_ITERATORS (*grp_start_p);
18436 :
18437 29758 : if (simdlen
18438 29758 : && safelen
18439 29875 : && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen),
18440 117 : OMP_CLAUSE_SIMDLEN_EXPR (simdlen)))
18441 : {
18442 0 : error_at (OMP_CLAUSE_LOCATION (simdlen),
18443 : "%<simdlen%> clause value is bigger than "
18444 : "%<safelen%> clause value");
18445 0 : OMP_CLAUSE_SIMDLEN_EXPR (simdlen)
18446 0 : = OMP_CLAUSE_SAFELEN_EXPR (safelen);
18447 : }
18448 :
18449 29758 : if (ordered_clause
18450 29758 : && schedule_clause
18451 29758 : && (OMP_CLAUSE_SCHEDULE_KIND (schedule_clause)
18452 : & OMP_CLAUSE_SCHEDULE_NONMONOTONIC))
18453 : {
18454 7 : error_at (OMP_CLAUSE_LOCATION (schedule_clause),
18455 : "%<nonmonotonic%> schedule modifier specified together "
18456 : "with %<ordered%> clause");
18457 14 : OMP_CLAUSE_SCHEDULE_KIND (schedule_clause)
18458 7 : = (enum omp_clause_schedule_kind)
18459 7 : (OMP_CLAUSE_SCHEDULE_KIND (schedule_clause)
18460 : & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC);
18461 : }
18462 :
18463 29758 : if (reduction_seen < 0 && ordered_clause)
18464 : {
18465 2 : error_at (OMP_CLAUSE_LOCATION (ordered_clause),
18466 : "%qs clause specified together with %<inscan%> "
18467 : "%<reduction%> clause", "ordered");
18468 2 : reduction_seen = -2;
18469 : }
18470 :
18471 29758 : if (reduction_seen < 0 && schedule_clause)
18472 : {
18473 3 : error_at (OMP_CLAUSE_LOCATION (schedule_clause),
18474 : "%qs clause specified together with %<inscan%> "
18475 : "%<reduction%> clause", "schedule");
18476 3 : reduction_seen = -2;
18477 : }
18478 :
18479 29758 : if (linear_variable_step_check
18480 29758 : || reduction_seen == -2
18481 : || allocate_seen
18482 29746 : || target_in_reduction_seen)
18483 5225 : for (pc = &clauses, c = clauses; c ; c = *pc)
18484 : {
18485 4618 : bool remove = false;
18486 4618 : if (allocate_seen)
18487 4460 : switch (OMP_CLAUSE_CODE (c))
18488 : {
18489 430 : case OMP_CLAUSE_REDUCTION:
18490 430 : case OMP_CLAUSE_IN_REDUCTION:
18491 430 : case OMP_CLAUSE_TASK_REDUCTION:
18492 430 : if (TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF)
18493 : {
18494 23 : t = TREE_OPERAND (OMP_CLAUSE_DECL (c), 0);
18495 23 : if (TREE_CODE (t) == POINTER_PLUS_EXPR)
18496 0 : t = TREE_OPERAND (t, 0);
18497 23 : if (TREE_CODE (t) == ADDR_EXPR
18498 10 : || INDIRECT_REF_P (t))
18499 13 : t = TREE_OPERAND (t, 0);
18500 23 : if (DECL_P (t))
18501 23 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
18502 : break;
18503 : }
18504 : /* FALLTHRU */
18505 1329 : case OMP_CLAUSE_PRIVATE:
18506 1329 : case OMP_CLAUSE_FIRSTPRIVATE:
18507 1329 : case OMP_CLAUSE_LASTPRIVATE:
18508 1329 : case OMP_CLAUSE_LINEAR:
18509 1329 : if (DECL_P (OMP_CLAUSE_DECL (c)))
18510 2658 : bitmap_clear_bit (&aligned_head,
18511 1329 : DECL_UID (OMP_CLAUSE_DECL (c)));
18512 : break;
18513 : default:
18514 : break;
18515 : }
18516 4618 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
18517 29 : && OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c)
18518 4625 : && !bitmap_bit_p (&map_head,
18519 7 : DECL_UID (OMP_CLAUSE_LINEAR_STEP (c))))
18520 : {
18521 2 : error_at (OMP_CLAUSE_LOCATION (c),
18522 : "%<linear%> clause step is a parameter %qD not "
18523 : "specified in %<uniform%> clause",
18524 2 : OMP_CLAUSE_LINEAR_STEP (c));
18525 2 : remove = true;
18526 : }
18527 4616 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
18528 4616 : && reduction_seen == -2)
18529 9 : OMP_CLAUSE_REDUCTION_INSCAN (c) = 0;
18530 4618 : if (target_in_reduction_seen
18531 4618 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP)
18532 : {
18533 256 : tree t = OMP_CLAUSE_DECL (c);
18534 256 : while (handled_component_p (t)
18535 : || INDIRECT_REF_P (t)
18536 : || TREE_CODE (t) == ADDR_EXPR
18537 : || TREE_CODE (t) == MEM_REF
18538 288 : || TREE_CODE (t) == NON_LVALUE_EXPR)
18539 32 : t = TREE_OPERAND (t, 0);
18540 256 : if (DECL_P (t)
18541 256 : && bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
18542 138 : OMP_CLAUSE_MAP_IN_REDUCTION (c) = 1;
18543 : }
18544 :
18545 4618 : if (remove)
18546 2 : *pc = OMP_CLAUSE_CHAIN (c);
18547 : else
18548 4616 : pc = &OMP_CLAUSE_CHAIN (c);
18549 : }
18550 :
18551 607 : if (allocate_seen)
18552 5041 : for (pc = &clauses, c = clauses; c ; c = *pc)
18553 : {
18554 4460 : bool remove = false;
18555 4460 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ALLOCATE
18556 731 : && !OMP_CLAUSE_ALLOCATE_COMBINED (c)
18557 5171 : && bitmap_bit_p (&aligned_head, DECL_UID (OMP_CLAUSE_DECL (c))))
18558 : {
18559 3 : error_at (OMP_CLAUSE_LOCATION (c),
18560 : "%qD specified in %<allocate%> clause but not in "
18561 3 : "an explicit privatization clause", OMP_CLAUSE_DECL (c));
18562 3 : remove = true;
18563 : }
18564 4460 : if (remove)
18565 3 : *pc = OMP_CLAUSE_CHAIN (c);
18566 : else
18567 4457 : pc = &OMP_CLAUSE_CHAIN (c);
18568 : }
18569 :
18570 29758 : if (nogroup_seen && reduction_seen)
18571 : {
18572 1 : error_at (OMP_CLAUSE_LOCATION (*nogroup_seen),
18573 : "%<nogroup%> clause must not be used together with "
18574 : "%<reduction%> clause");
18575 1 : *nogroup_seen = OMP_CLAUSE_CHAIN (*nogroup_seen);
18576 : }
18577 :
18578 29758 : if (grainsize_seen && num_tasks_seen)
18579 : {
18580 2 : error_at (OMP_CLAUSE_LOCATION (*grainsize_seen),
18581 : "%<grainsize%> clause must not be used together with "
18582 : "%<num_tasks%> clause");
18583 2 : *grainsize_seen = OMP_CLAUSE_CHAIN (*grainsize_seen);
18584 : }
18585 :
18586 29758 : if (full_seen && partial_seen)
18587 : {
18588 4 : error_at (OMP_CLAUSE_LOCATION (*full_seen),
18589 : "%<full%> clause must not be used together with "
18590 : "%<partial%> clause");
18591 4 : *full_seen = OMP_CLAUSE_CHAIN (*full_seen);
18592 : }
18593 :
18594 29758 : if (detach_seen)
18595 : {
18596 31 : if (mergeable_seen)
18597 : {
18598 2 : error_at (OMP_CLAUSE_LOCATION (*detach_seen),
18599 : "%<detach%> clause must not be used together with "
18600 : "%<mergeable%> clause");
18601 2 : *detach_seen = OMP_CLAUSE_CHAIN (*detach_seen);
18602 : }
18603 : else
18604 : {
18605 29 : tree detach_decl = OMP_CLAUSE_DECL (*detach_seen);
18606 :
18607 79 : for (pc = &clauses, c = clauses; c ; c = *pc)
18608 : {
18609 50 : bool remove = false;
18610 50 : if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
18611 48 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
18612 48 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
18613 44 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE)
18614 54 : && OMP_CLAUSE_DECL (c) == detach_decl)
18615 : {
18616 2 : error_at (OMP_CLAUSE_LOCATION (c),
18617 : "the event handle of a %<detach%> clause "
18618 : "should not be in a data-sharing clause");
18619 2 : remove = true;
18620 : }
18621 50 : if (remove)
18622 2 : *pc = OMP_CLAUSE_CHAIN (c);
18623 : else
18624 48 : pc = &OMP_CLAUSE_CHAIN (c);
18625 : }
18626 : }
18627 : }
18628 :
18629 29758 : if (ort == C_ORT_OMP_INTEROP
18630 29758 : && depend_clause
18631 21 : && (!init_use_destroy_seen
18632 20 : || (init_seen && init_no_targetsync_clause)))
18633 : {
18634 3 : error_at (OMP_CLAUSE_LOCATION (depend_clause),
18635 : "%<depend%> clause requires action clauses with "
18636 : "%<targetsync%> interop-type");
18637 3 : if (init_no_targetsync_clause)
18638 2 : inform (OMP_CLAUSE_LOCATION (init_no_targetsync_clause),
18639 : "%<init%> clause lacks the %<targetsync%> modifier");
18640 : }
18641 :
18642 29758 : bitmap_obstack_release (NULL);
18643 29758 : return clauses;
18644 : }
18645 :
18646 : /* Do processing necessary to make CLAUSES well-formed, where CLAUSES result
18647 : from implicit instantiation of user-defined mappers (in gimplify.cc). */
18648 :
18649 : tree
18650 15 : c_omp_finish_mapper_clauses (tree clauses)
18651 : {
18652 15 : return c_finish_omp_clauses (clauses, C_ORT_OMP);
18653 : }
18654 :
18655 : /* Return code to initialize DST with a copy constructor from SRC.
18656 : C doesn't have copy constructors nor assignment operators, only for
18657 : _Atomic vars we need to perform __atomic_load from src into a temporary
18658 : followed by __atomic_store of the temporary to dst. */
18659 :
18660 : tree
18661 18755 : c_omp_clause_copy_ctor (tree clause, tree dst, tree src)
18662 : {
18663 18755 : if (!really_atomic_lvalue (dst) && !really_atomic_lvalue (src))
18664 18751 : return build2 (MODIFY_EXPR, TREE_TYPE (dst), dst, src);
18665 :
18666 4 : location_t loc = OMP_CLAUSE_LOCATION (clause);
18667 4 : tree type = TREE_TYPE (dst);
18668 4 : tree nonatomic_type = build_qualified_type (type, TYPE_UNQUALIFIED);
18669 4 : tree tmp = create_tmp_var (nonatomic_type);
18670 4 : tree tmp_addr = build_fold_addr_expr (tmp);
18671 4 : TREE_ADDRESSABLE (tmp) = 1;
18672 4 : suppress_warning (tmp);
18673 4 : tree src_addr = build_fold_addr_expr (src);
18674 4 : tree dst_addr = build_fold_addr_expr (dst);
18675 4 : tree seq_cst = build_int_cst (integer_type_node, MEMMODEL_SEQ_CST);
18676 4 : vec<tree, va_gc> *params;
18677 : /* Expansion of a generic atomic load may require an addition
18678 : element, so allocate enough to prevent a resize. */
18679 4 : vec_alloc (params, 4);
18680 :
18681 : /* Build __atomic_load (&src, &tmp, SEQ_CST); */
18682 4 : tree fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_LOAD);
18683 4 : params->quick_push (src_addr);
18684 4 : params->quick_push (tmp_addr);
18685 4 : params->quick_push (seq_cst);
18686 4 : tree load = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
18687 :
18688 4 : vec_alloc (params, 4);
18689 :
18690 : /* Build __atomic_store (&dst, &tmp, SEQ_CST); */
18691 4 : fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_STORE);
18692 4 : params->quick_push (dst_addr);
18693 4 : params->quick_push (tmp_addr);
18694 4 : params->quick_push (seq_cst);
18695 4 : tree store = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
18696 4 : return build2 (COMPOUND_EXPR, void_type_node, load, store);
18697 : }
18698 :
18699 : /* Create a transaction node. */
18700 :
18701 : tree
18702 135 : c_finish_transaction (location_t loc, tree block, int flags)
18703 : {
18704 135 : tree stmt = build_stmt (loc, TRANSACTION_EXPR, block);
18705 135 : if (flags & TM_STMT_ATTR_OUTER)
18706 10 : TRANSACTION_EXPR_OUTER (stmt) = 1;
18707 135 : if (flags & TM_STMT_ATTR_RELAXED)
18708 31 : TRANSACTION_EXPR_RELAXED (stmt) = 1;
18709 135 : return add_stmt (stmt);
18710 : }
18711 :
18712 : /* Make a variant type in the proper way for C/C++, propagating qualifiers
18713 : down to the element type of an array. If ORIG_QUAL_TYPE is not
18714 : NULL, then it should be used as the qualified type
18715 : ORIG_QUAL_INDIRECT levels down in array type derivation (to
18716 : preserve information about the typedef name from which an array
18717 : type was derived). */
18718 :
18719 : tree
18720 76556898 : c_build_qualified_type (tree type, int type_quals, tree orig_qual_type,
18721 : size_t orig_qual_indirect)
18722 : {
18723 76556898 : if (type == error_mark_node)
18724 : return type;
18725 :
18726 76556746 : if (TREE_CODE (type) == ARRAY_TYPE)
18727 : {
18728 3154491 : tree t;
18729 3154491 : tree element_type = c_build_qualified_type (TREE_TYPE (type),
18730 : type_quals, orig_qual_type,
18731 : orig_qual_indirect - 1);
18732 :
18733 : /* See if we already have an identically qualified type. */
18734 3154491 : if (orig_qual_type && orig_qual_indirect == 0)
18735 : t = orig_qual_type;
18736 : else
18737 4598095 : for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
18738 : {
18739 4456956 : if (TYPE_QUALS (strip_array_types (t)) == type_quals
18740 3034369 : && TYPE_NAME (t) == TYPE_NAME (type)
18741 3013311 : && TYPE_CONTEXT (t) == TYPE_CONTEXT (type)
18742 7470267 : && attribute_list_equal (TYPE_ATTRIBUTES (t),
18743 3013311 : TYPE_ATTRIBUTES (type)))
18744 : break;
18745 : }
18746 3154450 : if (!t)
18747 : {
18748 141139 : tree domain = TYPE_DOMAIN (type);
18749 :
18750 141139 : t = build_variant_type_copy (type);
18751 141139 : TREE_TYPE (t) = element_type;
18752 141139 : TYPE_ADDR_SPACE (t) = TYPE_ADDR_SPACE (element_type);
18753 :
18754 141139 : if (TYPE_STRUCTURAL_EQUALITY_P (element_type)
18755 141139 : || (domain && TYPE_STRUCTURAL_EQUALITY_P (domain)))
18756 196 : SET_TYPE_STRUCTURAL_EQUALITY (t);
18757 140943 : else if (TYPE_CANONICAL (element_type) != element_type
18758 140943 : || (domain && TYPE_CANONICAL (domain) != domain))
18759 : {
18760 2842 : tree unqualified_canon
18761 5427 : = c_build_array_type (TYPE_CANONICAL (element_type),
18762 2585 : domain ? TYPE_CANONICAL (domain)
18763 : : NULL_TREE);
18764 2842 : if (TYPE_REVERSE_STORAGE_ORDER (type))
18765 : {
18766 0 : unqualified_canon
18767 0 : = build_distinct_type_copy (unqualified_canon);
18768 0 : TYPE_REVERSE_STORAGE_ORDER (unqualified_canon) = 1;
18769 : }
18770 2842 : TYPE_CANONICAL (t)
18771 5684 : = c_build_qualified_type (unqualified_canon, type_quals);
18772 : }
18773 : else
18774 138101 : TYPE_CANONICAL (t) = t;
18775 : }
18776 : return t;
18777 : }
18778 :
18779 : /* A restrict-qualified pointer type must be a pointer to object or
18780 : incomplete type. Note that the use of POINTER_TYPE_P also allows
18781 : REFERENCE_TYPEs, which is appropriate for C++. */
18782 73402255 : if ((type_quals & TYPE_QUAL_RESTRICT)
18783 73402255 : && (!POINTER_TYPE_P (type)
18784 3488275 : || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type))))
18785 : {
18786 3 : error ("invalid use of %<restrict%>");
18787 3 : type_quals &= ~TYPE_QUAL_RESTRICT;
18788 : }
18789 :
18790 73402255 : tree var_type = (orig_qual_type && orig_qual_indirect == 0
18791 73402255 : ? orig_qual_type
18792 73402224 : : build_qualified_type (type, type_quals));
18793 :
18794 73402255 : gcc_checking_assert (C_TYPE_VARIABLE_SIZE (var_type)
18795 : == C_TYPE_VARIABLE_SIZE (type));
18796 73402255 : gcc_checking_assert (c_type_variably_modified_p (var_type)
18797 : == c_type_variably_modified_p (type));
18798 :
18799 : /* A variant type does not inherit the list of incomplete vars from the
18800 : type main variant. */
18801 73402255 : if ((RECORD_OR_UNION_TYPE_P (var_type)
18802 71311616 : || TREE_CODE (var_type) == ENUMERAL_TYPE)
18803 73508474 : && TYPE_MAIN_VARIANT (var_type) != var_type)
18804 1415131 : C_TYPE_INCOMPLETE_VARS (var_type) = 0;
18805 : return var_type;
18806 : }
18807 :
18808 : /* Build a VA_ARG_EXPR for the C parser. */
18809 :
18810 : tree
18811 19972 : c_build_va_arg (location_t loc1, tree expr, location_t loc2, tree type,
18812 : tree type_expr)
18813 : {
18814 19972 : if (error_operand_p (type))
18815 2 : return error_mark_node;
18816 : /* VA_ARG_EXPR cannot be used for a scalar va_list with reverse storage
18817 : order because it takes the address of the expression. */
18818 19970 : else if (handled_component_p (expr)
18819 31 : && reverse_storage_order_for_component_p (expr))
18820 : {
18821 0 : error_at (loc1, "cannot use %<va_arg%> with reverse storage order");
18822 0 : return error_mark_node;
18823 : }
18824 19970 : else if (!COMPLETE_TYPE_P (type))
18825 : {
18826 11 : error_at (loc2, "second argument to %<va_arg%> is of incomplete "
18827 : "type %qT", type);
18828 11 : return error_mark_node;
18829 : }
18830 19959 : else if (TREE_CODE (type) == FUNCTION_TYPE)
18831 : {
18832 1 : error_at (loc2, "second argument to %<va_arg%> is a function type %qT",
18833 : type);
18834 1 : return error_mark_node;
18835 : }
18836 6 : else if (TREE_CODE (type) == ARRAY_TYPE && C_TYPE_VARIABLE_SIZE (type)
18837 19961 : && !flag_isoc99)
18838 : {
18839 1 : error_at (loc2, "second argument to %<va_arg%> is an array type %qT",
18840 : type);
18841 1 : return error_mark_node;
18842 : }
18843 19957 : else if (warn_cxx_compat && TREE_CODE (type) == ENUMERAL_TYPE)
18844 1 : warning_at (loc2, OPT_Wc___compat,
18845 : "C++ requires promoted type, not enum type, in %<va_arg%>");
18846 :
18847 19957 : if (flag_isoc99 && TREE_CODE (type) == ARRAY_TYPE)
18848 : {
18849 3 : warning_at (loc2, 0, "second argument to %<va_arg%> is an array type %qT",
18850 : type);
18851 : /* We create a trap but evaluate side effects first. */
18852 3 : tree trapfn = builtin_decl_explicit (BUILT_IN_TRAP);
18853 3 : trapfn = build_call_expr_loc (loc2, trapfn, 0);
18854 3 : tree e2 = build2 (COMPOUND_EXPR, void_type_node, expr, trapfn);
18855 : /* Return a compound literal of the right type. */
18856 3 : tree e1 = build_compound_literal (loc2, type, NULL, true, 0, NULL);
18857 3 : expr = build2 (COMPOUND_EXPR, type, e2, e1);
18858 3 : }
18859 : else
18860 19954 : expr = build_va_arg (loc2, expr, type);
18861 :
18862 19957 : if (type_expr)
18863 26 : expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr), type_expr, expr);
18864 :
18865 : return expr;
18866 : }
18867 :
18868 : /* Return truthvalue of whether T1 is the same tree structure as T2.
18869 : Return 1 if they are the same. Return false if they are different. */
18870 :
18871 : bool
18872 1854 : c_tree_equal (tree t1, tree t2)
18873 : {
18874 1883 : enum tree_code code1, code2;
18875 :
18876 1883 : if (t1 == t2)
18877 : return true;
18878 661 : if (!t1 || !t2)
18879 : return false;
18880 :
18881 681 : for (code1 = TREE_CODE (t1); code1 == NON_LVALUE_EXPR;
18882 20 : code1 = TREE_CODE (t1))
18883 20 : t1 = TREE_OPERAND (t1, 0);
18884 682 : for (code2 = TREE_CODE (t2); code2 == NON_LVALUE_EXPR;
18885 21 : code2 = TREE_CODE (t2))
18886 21 : t2 = TREE_OPERAND (t2, 0);
18887 :
18888 : /* They might have become equal now. */
18889 661 : if (t1 == t2)
18890 : return true;
18891 :
18892 640 : if (code1 != code2)
18893 : return false;
18894 :
18895 379 : if (CONSTANT_CLASS_P (t1) && !comptypes (TREE_TYPE (t1), TREE_TYPE (t2)))
18896 : return false;
18897 :
18898 379 : switch (code1)
18899 : {
18900 2 : case INTEGER_CST:
18901 2 : return wi::to_wide (t1) == wi::to_wide (t2);
18902 :
18903 10 : case REAL_CST:
18904 10 : return real_equal (&TREE_REAL_CST (t1), &TREE_REAL_CST (t2));
18905 :
18906 0 : case STRING_CST:
18907 0 : return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
18908 0 : && !memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
18909 0 : TREE_STRING_LENGTH (t1));
18910 :
18911 0 : case FIXED_CST:
18912 0 : return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1),
18913 : TREE_FIXED_CST (t2));
18914 :
18915 0 : case COMPLEX_CST:
18916 0 : return c_tree_equal (TREE_REALPART (t1), TREE_REALPART (t2))
18917 0 : && c_tree_equal (TREE_IMAGPART (t1), TREE_IMAGPART (t2));
18918 :
18919 0 : case VECTOR_CST:
18920 0 : return operand_equal_p (t1, t2, OEP_ONLY_CONST);
18921 :
18922 0 : case CONSTRUCTOR:
18923 : /* We need to do this when determining whether or not two
18924 : non-type pointer to member function template arguments
18925 : are the same. */
18926 0 : if (!comptypes (TREE_TYPE (t1), TREE_TYPE (t2))
18927 0 : || CONSTRUCTOR_NELTS (t1) != CONSTRUCTOR_NELTS (t2))
18928 : return false;
18929 : {
18930 : tree field, value;
18931 : unsigned int i;
18932 0 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t1), i, field, value)
18933 : {
18934 0 : constructor_elt *elt2 = CONSTRUCTOR_ELT (t2, i);
18935 0 : if (!c_tree_equal (field, elt2->index)
18936 0 : || !c_tree_equal (value, elt2->value))
18937 : return false;
18938 : }
18939 : }
18940 : return true;
18941 :
18942 0 : case TREE_LIST:
18943 0 : if (!c_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)))
18944 : return false;
18945 0 : if (!c_tree_equal (TREE_VALUE (t1), TREE_VALUE (t2)))
18946 : return false;
18947 0 : return c_tree_equal (TREE_CHAIN (t1), TREE_CHAIN (t2));
18948 :
18949 0 : case SAVE_EXPR:
18950 0 : return c_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
18951 :
18952 25 : case CALL_EXPR:
18953 25 : {
18954 25 : tree arg1, arg2;
18955 25 : call_expr_arg_iterator iter1, iter2;
18956 25 : if (!c_tree_equal (CALL_EXPR_FN (t1), CALL_EXPR_FN (t2)))
18957 : return false;
18958 50 : for (arg1 = first_call_expr_arg (t1, &iter1),
18959 25 : arg2 = first_call_expr_arg (t2, &iter2);
18960 25 : arg1 && arg2;
18961 0 : arg1 = next_call_expr_arg (&iter1),
18962 0 : arg2 = next_call_expr_arg (&iter2))
18963 0 : if (!c_tree_equal (arg1, arg2))
18964 : return false;
18965 25 : if (arg1 || arg2)
18966 0 : return false;
18967 : return true;
18968 : }
18969 :
18970 0 : case TARGET_EXPR:
18971 0 : {
18972 0 : tree o1 = TREE_OPERAND (t1, 0);
18973 0 : tree o2 = TREE_OPERAND (t2, 0);
18974 :
18975 : /* Special case: if either target is an unallocated VAR_DECL,
18976 : it means that it's going to be unified with whatever the
18977 : TARGET_EXPR is really supposed to initialize, so treat it
18978 : as being equivalent to anything. */
18979 0 : if (VAR_P (o1) && DECL_NAME (o1) == NULL_TREE
18980 0 : && !DECL_RTL_SET_P (o1))
18981 : /*Nop*/;
18982 0 : else if (VAR_P (o2) && DECL_NAME (o2) == NULL_TREE
18983 0 : && !DECL_RTL_SET_P (o2))
18984 : /*Nop*/;
18985 0 : else if (!c_tree_equal (o1, o2))
18986 : return false;
18987 :
18988 0 : return c_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
18989 : }
18990 :
18991 29 : case COMPONENT_REF:
18992 29 : if (TREE_OPERAND (t1, 1) != TREE_OPERAND (t2, 1))
18993 : return false;
18994 29 : return c_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
18995 :
18996 : case PARM_DECL:
18997 : case VAR_DECL:
18998 : case CONST_DECL:
18999 : case FIELD_DECL:
19000 : case FUNCTION_DECL:
19001 : case IDENTIFIER_NODE:
19002 : case SSA_NAME:
19003 : return false;
19004 :
19005 0 : case TREE_VEC:
19006 0 : {
19007 0 : unsigned ix;
19008 0 : if (TREE_VEC_LENGTH (t1) != TREE_VEC_LENGTH (t2))
19009 : return false;
19010 0 : for (ix = TREE_VEC_LENGTH (t1); ix--;)
19011 0 : if (!c_tree_equal (TREE_VEC_ELT (t1, ix),
19012 0 : TREE_VEC_ELT (t2, ix)))
19013 : return false;
19014 : return true;
19015 : }
19016 :
19017 22 : CASE_CONVERT:
19018 22 : if (!comptypes (TREE_TYPE (t1), TREE_TYPE (t2)))
19019 : return false;
19020 : break;
19021 :
19022 : default:
19023 : break;
19024 : }
19025 :
19026 131 : switch (TREE_CODE_CLASS (code1))
19027 : {
19028 131 : case tcc_unary:
19029 131 : case tcc_binary:
19030 131 : case tcc_comparison:
19031 131 : case tcc_expression:
19032 131 : case tcc_vl_exp:
19033 131 : case tcc_reference:
19034 131 : case tcc_statement:
19035 131 : {
19036 131 : int i, n = TREE_OPERAND_LENGTH (t1);
19037 :
19038 131 : switch (code1)
19039 : {
19040 0 : case PREINCREMENT_EXPR:
19041 0 : case PREDECREMENT_EXPR:
19042 0 : case POSTINCREMENT_EXPR:
19043 0 : case POSTDECREMENT_EXPR:
19044 0 : n = 1;
19045 0 : break;
19046 16 : case ARRAY_REF:
19047 16 : n = 2;
19048 16 : break;
19049 : default:
19050 : break;
19051 : }
19052 :
19053 131 : if (TREE_CODE_CLASS (code1) == tcc_vl_exp
19054 131 : && n != TREE_OPERAND_LENGTH (t2))
19055 : return false;
19056 :
19057 305 : for (i = 0; i < n; ++i)
19058 186 : if (!c_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i)))
19059 : return false;
19060 :
19061 : return true;
19062 : }
19063 :
19064 0 : case tcc_type:
19065 0 : return comptypes (t1, t2);
19066 0 : default:
19067 0 : gcc_unreachable ();
19068 : }
19069 : }
19070 :
19071 : /* Returns true when the function declaration FNDECL is implicit,
19072 : introduced as a result of a call to an otherwise undeclared
19073 : function, and false otherwise. */
19074 :
19075 : bool
19076 2013 : c_decl_implicit (const_tree fndecl)
19077 : {
19078 2013 : return C_DECL_IMPLICIT (fndecl);
19079 : }
|