Branch data Line data Source code
1 : : /* Build expressions with type checking for C compiler.
2 : : Copyright (C) 1987-2025 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 : : /* True when parsing OpenMP loop expressions. */
82 : : bool c_in_omp_for;
83 : :
84 : : /* True when parsing OpenMP map clause. */
85 : : bool c_omp_array_section_p;
86 : :
87 : : /* The argument of last parsed sizeof expression, only to be tested
88 : : if expr.original_code == SIZEOF_EXPR. */
89 : : tree c_last_sizeof_arg;
90 : : location_t c_last_sizeof_loc;
91 : :
92 : : /* Nonzero if we might need to print a "missing braces around
93 : : initializer" message within this initializer. */
94 : : static int found_missing_braces;
95 : :
96 : : static bool require_constant_value;
97 : : static bool require_constant_elements;
98 : : static bool require_constexpr_value;
99 : :
100 : : static tree qualify_type (tree, tree);
101 : : struct comptypes_data;
102 : : static bool tagged_types_tu_compatible_p (const_tree, const_tree,
103 : : struct comptypes_data *);
104 : : static bool comp_target_types (location_t, tree, tree);
105 : : static bool function_types_compatible_p (const_tree, const_tree,
106 : : struct comptypes_data *);
107 : : static bool type_lists_compatible_p (const_tree, const_tree,
108 : : struct comptypes_data *);
109 : : static int convert_arguments (location_t, vec<location_t>, tree,
110 : : vec<tree, va_gc> *, vec<tree, va_gc> *, tree,
111 : : tree);
112 : : static tree pointer_diff (location_t, tree, tree, tree *);
113 : : static tree convert_for_assignment (location_t, location_t, tree, tree, tree,
114 : : enum impl_conv, bool, tree, tree, int,
115 : : int = 0);
116 : : static tree valid_compound_expr_initializer (tree, tree);
117 : : static void push_string (const char *);
118 : : static void push_member_name (tree);
119 : : static int spelling_length (void);
120 : : static char *print_spelling (char *);
121 : : static void warning_init (location_t, int, const char *);
122 : : static tree digest_init (location_t, tree, tree, tree, tree, bool, bool, bool,
123 : : bool, bool, bool);
124 : : static void output_init_element (location_t, tree, tree, bool, tree, tree, bool,
125 : : bool, struct obstack *);
126 : : static void output_pending_init_elements (int, struct obstack *);
127 : : static bool set_designator (location_t, bool, struct obstack *);
128 : : static void push_range_stack (tree, struct obstack *);
129 : : static void add_pending_init (location_t, tree, tree, tree, bool,
130 : : struct obstack *);
131 : : static void set_nonincremental_init (struct obstack *);
132 : : static void set_nonincremental_init_from_string (tree, struct obstack *);
133 : : static tree find_init_member (tree, struct obstack *);
134 : : static void readonly_warning (tree, enum lvalue_use);
135 : : static int lvalue_or_else (location_t, const_tree, enum lvalue_use);
136 : : static void record_maybe_used_decl (tree);
137 : : static bool comptypes_internal (const_tree, const_tree,
138 : : struct comptypes_data *data);
139 : : static bool comptypes_check_for_composite (tree t1, tree t2);
140 : :
141 : : /* Return true if EXP is a null pointer constant, false otherwise. */
142 : :
143 : : bool
144 : 183933063 : null_pointer_constant_p (const_tree expr)
145 : : {
146 : : /* This should really operate on c_expr structures, but they aren't
147 : : yet available everywhere required. */
148 : 183933063 : tree type = TREE_TYPE (expr);
149 : :
150 : : /* An integer constant expression with the value 0, such an expression
151 : : cast to type void*, or the predefined constant nullptr, are a null
152 : : pointer constant. */
153 : 183933063 : if (expr == nullptr_node)
154 : : return true;
155 : :
156 : 183932423 : return (TREE_CODE (expr) == INTEGER_CST
157 : 18662461 : && !TREE_OVERFLOW (expr)
158 : 18662364 : && integer_zerop (expr)
159 : 187784163 : && (INTEGRAL_TYPE_P (type)
160 : 329266 : || (TREE_CODE (type) == POINTER_TYPE
161 : 329264 : && VOID_TYPE_P (TREE_TYPE (type))
162 : 254192 : && TYPE_QUALS (TREE_TYPE (type)) == TYPE_UNQUALIFIED)));
163 : : }
164 : :
165 : : /* EXPR may appear in an unevaluated part of an integer constant
166 : : expression, but not in an evaluated part. Wrap it in a
167 : : C_MAYBE_CONST_EXPR, or mark it with TREE_OVERFLOW if it is just an
168 : : INTEGER_CST and we cannot create a C_MAYBE_CONST_EXPR. */
169 : :
170 : : static tree
171 : 62358 : note_integer_operands (tree expr)
172 : : {
173 : 62358 : tree ret;
174 : 62358 : if (TREE_CODE (expr) == INTEGER_CST && in_late_binary_op)
175 : : {
176 : 22 : ret = copy_node (expr);
177 : 22 : TREE_OVERFLOW (ret) = 1;
178 : : }
179 : : else
180 : : {
181 : 62336 : ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (expr), NULL_TREE, expr);
182 : 62336 : C_MAYBE_CONST_EXPR_INT_OPERANDS (ret) = 1;
183 : : }
184 : 62358 : return ret;
185 : : }
186 : :
187 : : /* Having checked whether EXPR may appear in an unevaluated part of an
188 : : integer constant expression and found that it may, remove any
189 : : C_MAYBE_CONST_EXPR noting this fact and return the resulting
190 : : expression. */
191 : :
192 : : static inline tree
193 : 32920237 : remove_c_maybe_const_expr (tree expr)
194 : : {
195 : 32920237 : if (TREE_CODE (expr) == C_MAYBE_CONST_EXPR)
196 : 61506 : return C_MAYBE_CONST_EXPR_EXPR (expr);
197 : : else
198 : : return expr;
199 : : }
200 : :
201 : : /* This is a cache to hold if two types are seen. */
202 : :
203 : : struct tagged_tu_seen_cache {
204 : : const struct tagged_tu_seen_cache * next;
205 : : const_tree t1;
206 : : const_tree t2;
207 : : };
208 : :
209 : : /* Do `exp = require_complete_type (loc, exp);' to make sure exp
210 : : does not have an incomplete type. (That includes void types.)
211 : : LOC is the location of the use. */
212 : :
213 : : tree
214 : 754608603 : require_complete_type (location_t loc, tree value)
215 : : {
216 : 754608603 : tree type = TREE_TYPE (value);
217 : :
218 : 754608603 : if (error_operand_p (value))
219 : 9008 : return error_mark_node;
220 : :
221 : : /* First, detect a valid value with a complete type. */
222 : 754599595 : if (COMPLETE_TYPE_P (type))
223 : : return value;
224 : :
225 : 142 : c_incomplete_type_error (loc, value, type);
226 : 142 : return error_mark_node;
227 : : }
228 : :
229 : : /* Print an error message for invalid use of an incomplete type.
230 : : VALUE is the expression that was used (or 0 if that isn't known)
231 : : and TYPE is the type that was invalid. LOC is the location for
232 : : the error. */
233 : :
234 : : void
235 : 198 : c_incomplete_type_error (location_t loc, const_tree value, const_tree type)
236 : : {
237 : : /* Avoid duplicate error message. */
238 : 198 : if (TREE_CODE (type) == ERROR_MARK)
239 : : return;
240 : :
241 : 198 : if (value != NULL_TREE && (VAR_P (value) || TREE_CODE (value) == PARM_DECL))
242 : 88 : error_at (loc, "%qD has an incomplete type %qT", value, type);
243 : : else
244 : : {
245 : 110 : retry:
246 : : /* We must print an error message. Be clever about what it says. */
247 : :
248 : 110 : switch (TREE_CODE (type))
249 : : {
250 : 70 : case RECORD_TYPE:
251 : 70 : case UNION_TYPE:
252 : 70 : case ENUMERAL_TYPE:
253 : 70 : break;
254 : :
255 : 34 : case VOID_TYPE:
256 : 34 : error_at (loc, "invalid use of void expression");
257 : 34 : return;
258 : :
259 : 6 : case ARRAY_TYPE:
260 : 6 : if (TYPE_DOMAIN (type))
261 : : {
262 : 3 : if (TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL)
263 : : {
264 : 3 : error_at (loc, "invalid use of flexible array member");
265 : 3 : return;
266 : : }
267 : 0 : type = TREE_TYPE (type);
268 : 0 : goto retry;
269 : : }
270 : 3 : error_at (loc, "invalid use of array with unspecified bounds");
271 : 3 : return;
272 : :
273 : 0 : default:
274 : 0 : gcc_unreachable ();
275 : : }
276 : :
277 : 70 : if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
278 : 68 : error_at (loc, "invalid use of undefined type %qT", type);
279 : : else
280 : : /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL. */
281 : 2 : error_at (loc, "invalid use of incomplete typedef %qT", type);
282 : : }
283 : : }
284 : :
285 : : /* Given a type, apply default promotions wrt unnamed function
286 : : arguments and return the new type. */
287 : :
288 : : tree
289 : 120650350 : c_type_promotes_to (tree type)
290 : : {
291 : 120650350 : tree ret = NULL_TREE;
292 : :
293 : 120650350 : if (TYPE_MAIN_VARIANT (type) == float_type_node)
294 : 1384386 : ret = double_type_node;
295 : 119265964 : else if (c_promoting_integer_type_p (type))
296 : : {
297 : : /* Preserve unsignedness if not really getting any wider. */
298 : 18186094 : if (TYPE_UNSIGNED (type)
299 : 18186094 : && (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)))
300 : 0 : ret = unsigned_type_node;
301 : : else
302 : 18186094 : ret = integer_type_node;
303 : : }
304 : :
305 : 19570480 : if (ret != NULL_TREE)
306 : 19570480 : return (TYPE_ATOMIC (type)
307 : 19570480 : ? c_build_qualified_type (ret, TYPE_QUAL_ATOMIC)
308 : : : ret);
309 : :
310 : : return type;
311 : : }
312 : :
313 : : /* Return true if between two named address spaces, whether there is a superset
314 : : named address space that encompasses both address spaces. If there is a
315 : : superset, return which address space is the superset. */
316 : :
317 : : static bool
318 : 7070229 : addr_space_superset (addr_space_t as1, addr_space_t as2, addr_space_t *common)
319 : : {
320 : 7070229 : if (as1 == as2)
321 : : {
322 : 7070229 : *common = as1;
323 : 7070229 : return true;
324 : : }
325 : 0 : else if (targetm.addr_space.subset_p (as1, as2))
326 : : {
327 : 0 : *common = as2;
328 : 0 : return true;
329 : : }
330 : 0 : else if (targetm.addr_space.subset_p (as2, as1))
331 : : {
332 : 0 : *common = as1;
333 : 0 : return true;
334 : : }
335 : : else
336 : : return false;
337 : : }
338 : :
339 : : /* Return a variant of TYPE which has all the type qualifiers of LIKE
340 : : as well as those of TYPE. */
341 : :
342 : : static tree
343 : 2394604 : qualify_type (tree type, tree like)
344 : : {
345 : 2394604 : addr_space_t as_type = TYPE_ADDR_SPACE (type);
346 : 2394604 : addr_space_t as_like = TYPE_ADDR_SPACE (like);
347 : 2394604 : addr_space_t as_common;
348 : :
349 : : /* If the two named address spaces are different, determine the common
350 : : superset address space. If there isn't one, raise an error. */
351 : 2394604 : if (!addr_space_superset (as_type, as_like, &as_common))
352 : : {
353 : 0 : as_common = as_type;
354 : 0 : error ("%qT and %qT are in disjoint named address spaces",
355 : : type, like);
356 : : }
357 : :
358 : 4789208 : return c_build_qualified_type (type,
359 : 2394604 : TYPE_QUALS_NO_ADDR_SPACE (type)
360 : 2394604 : | TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (like)
361 : 2394604 : | ENCODE_QUAL_ADDR_SPACE (as_common));
362 : : }
363 : :
364 : :
365 : : /* Check consistency of type TYPE. For derived types, we test that
366 : : C_TYPE_VARIABLE_SIZE and C_TYPE_VARIABLY_MODIFIED are consistent with
367 : : the requirements of the base type. We also check that arrays with a
368 : : non-constant length are marked with C_TYPE_VARIABLE_SIZE. If any
369 : : inconsistency is detected false is returned and true otherwise. */
370 : :
371 : : static bool
372 : 135473188 : c_verify_type (tree type)
373 : : {
374 : 135473188 : switch (TREE_CODE (type))
375 : : {
376 : 63699352 : case POINTER_TYPE:
377 : 63699352 : case FUNCTION_TYPE:
378 : : /* Pointer and funcions can not have variable size. */
379 : 63699352 : if (C_TYPE_VARIABLE_SIZE (type))
380 : : return false;
381 : : /* Pointer and funcions are variably modified if and only if the
382 : : return / target type is variably modified. */
383 : 63699352 : if (C_TYPE_VARIABLY_MODIFIED (type)
384 : 63699352 : != C_TYPE_VARIABLY_MODIFIED (TREE_TYPE (type)))
385 : 0 : return false;
386 : : break;
387 : 892412 : case ARRAY_TYPE:
388 : : /* An array has variable size if and only if it has a non-constant
389 : : dimensions or its element type has variable size. */
390 : 892412 : if ((C_TYPE_VARIABLE_SIZE (TREE_TYPE (type))
391 : 892412 : || (TYPE_DOMAIN (type) && TYPE_MAX_VALUE (TYPE_DOMAIN (type))
392 : 867205 : && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
393 : : != INTEGER_CST))
394 : 892412 : != C_TYPE_VARIABLE_SIZE (type))
395 : : return false;
396 : : /* If the element type or the array has variable size, then the
397 : : array has variable size and is variably modified. */
398 : 892412 : if (C_TYPE_VARIABLE_SIZE (TREE_TYPE (type))
399 : 892412 : || C_TYPE_VARIABLE_SIZE (type))
400 : : {
401 : 27597 : if (!C_TYPE_VARIABLE_SIZE (type))
402 : : return false;
403 : 27597 : if (!C_TYPE_VARIABLY_MODIFIED (type))
404 : : return false;
405 : : }
406 : : /* If the element type is variably modified, then also the array. */
407 : 892412 : if (C_TYPE_VARIABLY_MODIFIED (TREE_TYPE (type))
408 : 892412 : && !C_TYPE_VARIABLY_MODIFIED (type))
409 : 0 : return false;
410 : : break;
411 : : default:
412 : : break;
413 : : }
414 : : return true;
415 : : }
416 : :
417 : : /* Propagate C_TYPE_VARIABLY_MODIFIED and C_TYPE_VARIABLE_SIZE
418 : : from a base type to a newly built derived or qualified type. */
419 : :
420 : : static tree
421 : 128942678 : c_set_type_bits (tree new_type, tree old_type)
422 : : {
423 : 128942678 : gcc_checking_assert (c_verify_type (old_type));
424 : :
425 : 128942678 : if (C_TYPE_VARIABLY_MODIFIED (old_type))
426 : 27230 : C_TYPE_VARIABLY_MODIFIED (new_type) = true;
427 : :
428 : 128942678 : if (TREE_CODE (new_type) == ARRAY_TYPE && C_TYPE_VARIABLE_SIZE (old_type))
429 : : {
430 : 16725 : C_TYPE_VARIABLY_MODIFIED (new_type) = true;
431 : 16725 : C_TYPE_VARIABLE_SIZE (new_type) = true;
432 : : }
433 : 128942678 : return new_type;
434 : : }
435 : :
436 : : /* Build a pointer type using the default pointer mode. */
437 : :
438 : : tree
439 : 69828497 : c_build_pointer_type (tree to_type)
440 : : {
441 : 69828497 : addr_space_t as = to_type == error_mark_node ? ADDR_SPACE_GENERIC
442 : 69828497 : : TYPE_ADDR_SPACE (to_type);
443 : 69828497 : machine_mode pointer_mode;
444 : :
445 : 69828497 : if (as != ADDR_SPACE_GENERIC || c_default_pointer_mode == VOIDmode)
446 : 69828497 : pointer_mode = targetm.addr_space.pointer_mode (as);
447 : : else
448 : : pointer_mode = c_default_pointer_mode;
449 : :
450 : 69828497 : return c_build_pointer_type_for_mode (to_type, pointer_mode, false);
451 : : }
452 : :
453 : : /* Build a pointer type using the given mode. */
454 : :
455 : : tree
456 : 69837242 : c_build_pointer_type_for_mode (tree type, machine_mode mode, bool m)
457 : : {
458 : 69837242 : tree ret = build_pointer_type_for_mode (type, mode, m);
459 : 69837242 : return c_set_type_bits (ret, type);
460 : : }
461 : :
462 : : /* Build a function type. */
463 : :
464 : : tree
465 : 51347260 : c_build_function_type (tree type, tree args, bool no)
466 : : {
467 : 51347260 : tree ret = build_function_type (type, args, no);
468 : 51347260 : return c_set_type_bits (ret, type);
469 : : }
470 : :
471 : : /* Build an array type. This sets typeless storage as required
472 : : by C2Y and C_TYPE_VARIABLY_MODIFIED and C_TYPE_VARIABLE_SIZE
473 : : based on the element type and domain. */
474 : :
475 : : tree
476 : 1135235 : c_build_array_type (tree type, tree domain)
477 : : {
478 : 1135235 : int type_quals = TYPE_QUALS (type);
479 : :
480 : : /* Identify typeless storage as introduced in C2Y
481 : : and supported also in earlier language modes. */
482 : 1697963 : bool typeless = (char_type_p (type) && !(type_quals & TYPE_QUAL_ATOMIC))
483 : 1135235 : || (AGGREGATE_TYPE_P (type) && TYPE_TYPELESS_STORAGE (type));
484 : :
485 : 1135235 : tree ret = build_array_type (type, domain, typeless);
486 : :
487 : 1051282 : if (domain && TYPE_MAX_VALUE (domain)
488 : 2098891 : && TREE_CODE (TYPE_MAX_VALUE (domain)) != INTEGER_CST)
489 : : {
490 : 23940 : C_TYPE_VARIABLE_SIZE (ret) = 1;
491 : 23940 : C_TYPE_VARIABLY_MODIFIED (ret) = 1;
492 : : }
493 : :
494 : 1135235 : return c_set_type_bits (ret, type);
495 : : }
496 : :
497 : :
498 : : /* Build an array type of unspecified size. */
499 : : tree
500 : 142 : c_build_array_type_unspecified (tree type)
501 : : {
502 : 142 : tree upper = build2 (COMPOUND_EXPR, TREE_TYPE (size_zero_node),
503 : : integer_zero_node, size_zero_node);
504 : 142 : return c_build_array_type (type, build_index_type (upper));
505 : : }
506 : :
507 : :
508 : : tree
509 : 6622941 : c_build_type_attribute_qual_variant (tree type, tree attrs, int quals)
510 : : {
511 : 6622941 : tree ret = build_type_attribute_qual_variant (type, attrs, quals);
512 : 6622941 : return c_set_type_bits (ret, type);
513 : : }
514 : :
515 : : tree
516 : 6622743 : c_build_type_attribute_variant (tree type, tree attrs)
517 : : {
518 : 6622743 : return c_build_type_attribute_qual_variant (type, attrs, TYPE_QUALS (type));
519 : : }
520 : :
521 : : /* Reconstruct a complex derived type. This is used to re-construct types
522 : : with the vector attribute. It is called via a langhook. */
523 : :
524 : : tree
525 : 483706 : c_reconstruct_complex_type (tree type, tree bottom)
526 : : {
527 : 483706 : tree inner, outer;
528 : :
529 : 483706 : if (TREE_CODE (type) == POINTER_TYPE)
530 : : {
531 : 16 : inner = c_reconstruct_complex_type (TREE_TYPE (type), bottom);
532 : 16 : outer = c_build_pointer_type_for_mode (inner, TYPE_MODE (type),
533 : 16 : TYPE_REF_CAN_ALIAS_ALL (type));
534 : : }
535 : : else if (TREE_CODE (type) == ARRAY_TYPE)
536 : : {
537 : 13 : inner = c_reconstruct_complex_type (TREE_TYPE (type), bottom);
538 : 13 : outer = c_build_array_type (inner, TYPE_DOMAIN (type));
539 : :
540 : 13 : gcc_checking_assert (C_TYPE_VARIABLE_SIZE (type)
541 : : == C_TYPE_VARIABLE_SIZE (outer));
542 : 13 : gcc_checking_assert (C_TYPE_VARIABLY_MODIFIED (outer)
543 : : == C_TYPE_VARIABLY_MODIFIED (type));
544 : : }
545 : : else if (TREE_CODE (type) == FUNCTION_TYPE)
546 : : {
547 : 169 : inner = c_reconstruct_complex_type (TREE_TYPE (type), bottom);
548 : 169 : outer = c_build_function_type (inner, TYPE_ARG_TYPES (type),
549 : 169 : TYPE_NO_NAMED_ARGS_STDARG_P (type));
550 : : }
551 : : else if (TREE_CODE (type) == REFERENCE_TYPE
552 : : || TREE_CODE (type) == OFFSET_TYPE)
553 : 0 : gcc_unreachable ();
554 : : else
555 : : return bottom;
556 : :
557 : 198 : return c_build_type_attribute_qual_variant (outer, TYPE_ATTRIBUTES (type),
558 : 396 : TYPE_QUALS (type));
559 : : }
560 : :
561 : : /* If NTYPE is a type of a non-variadic function with a prototype
562 : : and OTYPE is a type of a function without a prototype and ATTRS
563 : : contains attribute format, diagnosess and removes it from ATTRS.
564 : : Returns the result of build_type_attribute_variant of NTYPE and
565 : : the (possibly) modified ATTRS. */
566 : :
567 : : static tree
568 : 9695 : c_build_functype_attribute_variant (tree ntype, tree otype, tree attrs)
569 : : {
570 : 9695 : if (!prototype_p (otype)
571 : 9683 : && prototype_p (ntype)
572 : 19348 : && lookup_attribute ("format", attrs))
573 : : {
574 : 14 : warning_at (input_location, OPT_Wattributes,
575 : : "%qs attribute can only be applied to variadic functions",
576 : : "format");
577 : 14 : attrs = remove_attribute ("format", attrs);
578 : : }
579 : 9695 : return c_build_type_attribute_variant (ntype, attrs);
580 : :
581 : : }
582 : :
583 : : /* Given a type which could be a typedef name, make sure to return the
584 : : original type. See set_underlying_type. */
585 : : static const_tree
586 : 60468183 : c_type_original (const_tree t)
587 : : {
588 : : /* It may even be a typedef of a typedef...
589 : : In the case of compiler-created builtin structs the TYPE_DECL
590 : : may be a dummy, with no DECL_ORIGINAL_TYPE. Don't fault. */
591 : 60468183 : while (TYPE_NAME (t)
592 : 31668022 : && TREE_CODE (TYPE_NAME (t)) == TYPE_DECL
593 : 60472063 : && DECL_ORIGINAL_TYPE (TYPE_NAME (t)))
594 : 1939 : t = DECL_ORIGINAL_TYPE (TYPE_NAME (t));
595 : 60468183 : return t;
596 : : }
597 : :
598 : : /* Return the tag for a tagged type. */
599 : : tree
600 : 60468183 : c_type_tag (const_tree t)
601 : : {
602 : 60468183 : gcc_assert (RECORD_OR_UNION_TYPE_P (t) || TREE_CODE (t) == ENUMERAL_TYPE);
603 : 60468183 : const_tree orig = c_type_original (t);
604 : 60468183 : tree name = TYPE_NAME (orig);
605 : 60468183 : if (!name)
606 : : return NULL_TREE;
607 : 31666083 : if (TREE_CODE (name) == TYPE_DECL)
608 : : {
609 : : /* A TYPE_DECL added by add_decl_expr. */
610 : 2 : gcc_checking_assert (!DECL_NAME (name));
611 : : return NULL_TREE;
612 : : }
613 : 31666081 : gcc_checking_assert (TREE_CODE (name) == IDENTIFIER_NODE);
614 : : return name;
615 : : }
616 : :
617 : : /* Remove qualifiers but not atomic. For arrays remove qualifiers
618 : : on the element type but also do not remove atomic. */
619 : : static tree
620 : 58982843 : remove_qualifiers (tree t)
621 : : {
622 : 58982843 : if (!t || t == error_mark_node)
623 : : return t;
624 : 58982818 : return TYPE_ATOMIC (strip_array_types (t))
625 : 58982818 : ? c_build_qualified_type (TYPE_MAIN_VARIANT (t), TYPE_QUAL_ATOMIC)
626 : 58967273 : : TYPE_MAIN_VARIANT (t);
627 : : }
628 : :
629 : :
630 : : /* Return the composite type of two compatible types.
631 : :
632 : : We assume that comptypes has already been done and returned
633 : : nonzero; if that isn't so, this may crash. In particular, we
634 : : assume that qualifiers match. */
635 : :
636 : : struct composite_cache {
637 : : tree t1;
638 : : tree t2;
639 : : tree composite;
640 : : struct composite_cache* next;
641 : : };
642 : :
643 : : tree
644 : 11983486 : composite_type_internal (tree t1, tree t2, struct composite_cache* cache)
645 : : {
646 : 11983486 : enum tree_code code1;
647 : 11983486 : enum tree_code code2;
648 : 11983486 : tree attributes;
649 : :
650 : : /* Save time if the two types are the same. */
651 : :
652 : 11983486 : if (t1 == t2) return t1;
653 : :
654 : : /* If one type is nonsense, use the other. */
655 : 2421348 : if (t1 == error_mark_node)
656 : : return t2;
657 : 2421344 : if (t2 == error_mark_node)
658 : : return t1;
659 : :
660 : 2421342 : code1 = TREE_CODE (t1);
661 : 2421342 : code2 = TREE_CODE (t2);
662 : :
663 : : /* Merge the attributes. */
664 : 2421342 : attributes = targetm.merge_type_attributes (t1, t2);
665 : :
666 : : /* If one is an enumerated type and the other is the compatible
667 : : integer type, the composite type might be either of the two
668 : : (DR#013 question 3). For consistency, use the enumerated type as
669 : : the composite type. */
670 : :
671 : 2421342 : if (code1 == ENUMERAL_TYPE
672 : 194 : && (code2 == INTEGER_TYPE
673 : 194 : || code2 == BOOLEAN_TYPE))
674 : : return t1;
675 : 2421148 : if (code2 == ENUMERAL_TYPE
676 : 69 : && (code1 == INTEGER_TYPE
677 : 69 : || code1 == BOOLEAN_TYPE))
678 : : return t2;
679 : :
680 : 2421079 : gcc_assert (code1 == code2);
681 : :
682 : 2421079 : switch (code1)
683 : : {
684 : 6325 : case POINTER_TYPE:
685 : : /* For two pointers, do this recursively on the target type. */
686 : 6325 : {
687 : 6325 : tree pointed_to_1 = TREE_TYPE (t1);
688 : 6325 : tree pointed_to_2 = TREE_TYPE (t2);
689 : 6325 : tree target = composite_type_internal (pointed_to_1,
690 : : pointed_to_2, cache);
691 : 6325 : t1 = c_build_pointer_type_for_mode (target, TYPE_MODE (t1), false);
692 : 6325 : t1 = c_build_type_attribute_variant (t1, attributes);
693 : 6325 : return qualify_type (t1, t2);
694 : : }
695 : :
696 : 10911 : case ARRAY_TYPE:
697 : 10911 : {
698 : 10911 : tree elt = composite_type_internal (TREE_TYPE (t1), TREE_TYPE (t2),
699 : : cache);
700 : 10911 : int quals;
701 : 10911 : tree unqual_elt;
702 : 10911 : tree d1 = TYPE_DOMAIN (t1);
703 : 10911 : tree d2 = TYPE_DOMAIN (t2);
704 : 10911 : bool d1_variable, d2_variable;
705 : 10911 : bool d1_zero, d2_zero;
706 : 10911 : bool t1_complete, t2_complete;
707 : :
708 : : /* We should not have any type quals on arrays at all. */
709 : 10911 : gcc_assert (!TYPE_QUALS_NO_ADDR_SPACE (t1)
710 : : && !TYPE_QUALS_NO_ADDR_SPACE (t2));
711 : :
712 : 10911 : t1_complete = COMPLETE_TYPE_P (t1);
713 : 10911 : t2_complete = COMPLETE_TYPE_P (t2);
714 : :
715 : 10911 : d1_zero = d1 == NULL_TREE || !TYPE_MAX_VALUE (d1);
716 : 10911 : d2_zero = d2 == NULL_TREE || !TYPE_MAX_VALUE (d2);
717 : :
718 : 21822 : d1_variable = (!d1_zero
719 : 10911 : && (TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST
720 : 10326 : || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST));
721 : 21822 : d2_variable = (!d2_zero
722 : 10911 : && (TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST
723 : 10584 : || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST));
724 : :
725 : 10911 : bool use1 = TYPE_DOMAIN (t1)
726 : 10911 : && (d2_variable || d2_zero || !d1_variable);
727 : 10911 : bool use2 = TYPE_DOMAIN (t2)
728 : 10911 : && (d1_variable || d1_zero || !d2_variable);
729 : :
730 : : /* If the first is an unspecified size pick the other one. */
731 : 8929 : if (d2_variable && c_type_unspecified_p (t1))
732 : : {
733 : 28 : gcc_assert (use1 && use2);
734 : : use1 = false;
735 : : }
736 : :
737 : : /* Save space: see if the result is identical to one of the args. */
738 : 10911 : if (elt == TREE_TYPE (t1) && use1)
739 : 10125 : return c_build_type_attribute_variant (t1, attributes);
740 : 786 : if (elt == TREE_TYPE (t2) && use2)
741 : 673 : return c_build_type_attribute_variant (t2, attributes);
742 : :
743 : 156 : if (elt == TREE_TYPE (t1) && !TYPE_DOMAIN (t2) && !TYPE_DOMAIN (t1))
744 : 10 : return c_build_type_attribute_variant (t1, attributes);
745 : 111 : if (elt == TREE_TYPE (t2) && !TYPE_DOMAIN (t2) && !TYPE_DOMAIN (t1))
746 : 2 : return c_build_type_attribute_variant (t2, attributes);
747 : :
748 : : /* Merge the element types, and have a size if either arg has
749 : : one. We may have qualifiers on the element types. To set
750 : : up TYPE_MAIN_VARIANT correctly, we need to form the
751 : : composite of the unqualified types and add the qualifiers
752 : : back at the end. */
753 : 101 : quals = TYPE_QUALS (strip_array_types (elt));
754 : 101 : unqual_elt = c_build_qualified_type (elt, TYPE_UNQUALIFIED);
755 : 202 : t1 = c_build_array_type (unqual_elt, TYPE_DOMAIN (use1 ? t1 : t2));
756 : :
757 : : /* Check that a type which has a varying outermost dimension
758 : : got marked has having a variable size. */
759 : 101 : bool varsize = (d1_variable && d2_variable)
760 : 81 : || (d1_variable && !t2_complete)
761 : 171 : || (d2_variable && !t1_complete);
762 : 51 : gcc_checking_assert (!varsize || C_TYPE_VARIABLE_SIZE (t1));
763 : :
764 : : /* Ensure a composite type involving a zero-length array type
765 : : is a zero-length type not an incomplete type. */
766 : 101 : if (d1_zero && d2_zero
767 : 16 : && (t1_complete || t2_complete)
768 : 102 : && !COMPLETE_TYPE_P (t1))
769 : : {
770 : 1 : TYPE_SIZE (t1) = bitsize_zero_node;
771 : 1 : TYPE_SIZE_UNIT (t1) = size_zero_node;
772 : : }
773 : 101 : t1 = c_build_qualified_type (t1, quals);
774 : 101 : return c_build_type_attribute_variant (t1, attributes);
775 : : }
776 : :
777 : 162 : case RECORD_TYPE:
778 : 162 : case UNION_TYPE:
779 : 162 : if (flag_isoc23 && !comptypes_same_p (t1, t2))
780 : : {
781 : : /* Go to the original type to get the right tag. */
782 : 101 : tree tag = c_type_tag (t1);
783 : :
784 : 101 : gcc_checking_assert (COMPLETE_TYPE_P (t1) && COMPLETE_TYPE_P (t2));
785 : 101 : gcc_checking_assert (!tag || comptypes (t1, t2));
786 : :
787 : : /* If a composite type for these two types is already under
788 : : construction, return it. */
789 : :
790 : 246 : for (struct composite_cache *c = cache; c != NULL; c = c->next)
791 : 152 : if ((c->t1 == t1 && c->t2 == t2) || (c->t1 == t2 && c->t2 == t1))
792 : 7 : return c->composite;
793 : :
794 : : /* Otherwise, create a new type node and link it into the cache. */
795 : :
796 : 94 : tree n = make_node (code1);
797 : 94 : SET_TYPE_STRUCTURAL_EQUALITY (n);
798 : 94 : TYPE_NAME (n) = tag;
799 : :
800 : 94 : struct composite_cache cache2 = { t1, t2, n, cache };
801 : 94 : cache = &cache2;
802 : :
803 : 94 : tree f1 = TYPE_FIELDS (t1);
804 : 94 : tree f2 = TYPE_FIELDS (t2);
805 : 94 : tree fields = NULL_TREE;
806 : :
807 : 214 : for (tree a = f1, b = f2; a && b;
808 : 120 : a = DECL_CHAIN (a), b = DECL_CHAIN (b))
809 : : {
810 : 120 : tree ta = TREE_TYPE (a);
811 : 120 : tree tb = TREE_TYPE (b);
812 : :
813 : 120 : if (DECL_C_BIT_FIELD (a))
814 : : {
815 : 19 : ta = DECL_BIT_FIELD_TYPE (a);
816 : 19 : tb = DECL_BIT_FIELD_TYPE (b);
817 : : }
818 : :
819 : 120 : gcc_assert (DECL_NAME (a) == DECL_NAME (b));
820 : 120 : gcc_checking_assert (!DECL_NAME (a) || comptypes (ta, tb));
821 : :
822 : 120 : tree t = composite_type_internal (ta, tb, cache);
823 : 120 : tree f = build_decl (input_location, FIELD_DECL, DECL_NAME (a), t);
824 : :
825 : 120 : DECL_PACKED (f) = DECL_PACKED (a);
826 : 120 : SET_DECL_ALIGN (f, DECL_ALIGN (a));
827 : 120 : DECL_ATTRIBUTES (f) = DECL_ATTRIBUTES (a);
828 : 120 : C_DECL_VARIABLE_SIZE (f) = C_TYPE_VARIABLE_SIZE (t);
829 : :
830 : 120 : decl_attributes (&f, DECL_ATTRIBUTES (f), 0);
831 : :
832 : 120 : finish_decl (f, input_location, NULL, NULL, NULL);
833 : :
834 : 120 : if (DECL_C_BIT_FIELD (a))
835 : : {
836 : : /* This will be processed by finish_struct. */
837 : 19 : SET_DECL_C_BIT_FIELD (f);
838 : 19 : DECL_INITIAL (f) = build_int_cst (integer_type_node,
839 : 19 : tree_to_uhwi (DECL_SIZE (a)));
840 : 19 : DECL_NONADDRESSABLE_P (f) = true;
841 : 19 : DECL_PADDING_P (f) = !DECL_NAME (a);
842 : : }
843 : :
844 : 120 : DECL_CHAIN (f) = fields;
845 : 120 : fields = f;
846 : : }
847 : :
848 : 94 : fields = nreverse (fields);
849 : :
850 : : /* Setup the struct/union type. Because we inherit all variably
851 : : modified components, we can ignore the size expression. */
852 : 94 : tree expr = NULL_TREE;
853 : :
854 : : /* Set TYPE_STUB_DECL for debugging symbols. */
855 : 94 : TYPE_STUB_DECL (n) = pushdecl (build_decl (input_location, TYPE_DECL,
856 : : NULL_TREE, n));
857 : :
858 : 94 : n = finish_struct (input_location, n, fields, attributes, NULL,
859 : : &expr);
860 : :
861 : 94 : return qualify_type (n, t1);
862 : : }
863 : : /* FALLTHRU */
864 : 61 : case ENUMERAL_TYPE:
865 : 61 : if (attributes != NULL)
866 : : {
867 : : /* Try harder not to create a new aggregate type. */
868 : 4 : if (attribute_list_equal (TYPE_ATTRIBUTES (t1), attributes))
869 : : return t1;
870 : 0 : if (attribute_list_equal (TYPE_ATTRIBUTES (t2), attributes))
871 : : return t2;
872 : : }
873 : 57 : return c_build_type_attribute_variant (t1, attributes);
874 : :
875 : 2363137 : case FUNCTION_TYPE:
876 : : /* Function types: prefer the one that specified arg types.
877 : : If both do, merge the arg types. Also merge the return types. */
878 : 2363137 : {
879 : 2363137 : tree valtype = composite_type_internal (TREE_TYPE (t1),
880 : 2363137 : TREE_TYPE (t2), cache);
881 : 2363137 : tree p1 = TYPE_ARG_TYPES (t1);
882 : 2363137 : tree p2 = TYPE_ARG_TYPES (t2);
883 : 2363137 : int len;
884 : 2363137 : tree newargs, n;
885 : 2363137 : int i;
886 : :
887 : : /* Save space: see if the result is identical to one of the args. */
888 : 2363137 : if (valtype == TREE_TYPE (t1) && !TYPE_ARG_TYPES (t2))
889 : 9178 : return c_build_functype_attribute_variant (t1, t2, attributes);
890 : 2353959 : if (valtype == TREE_TYPE (t2) && !TYPE_ARG_TYPES (t1))
891 : 517 : return c_build_functype_attribute_variant (t2, t1, attributes);
892 : :
893 : : /* Simple way if one arg fails to specify argument types. */
894 : 2353442 : if (TYPE_ARG_TYPES (t1) == NULL_TREE)
895 : : {
896 : 9 : t1 = c_build_function_type (valtype, TYPE_ARG_TYPES (t2),
897 : 9 : TYPE_NO_NAMED_ARGS_STDARG_P (t2));
898 : 9 : t1 = c_build_type_attribute_variant (t1, attributes);
899 : 9 : return qualify_type (t1, t2);
900 : : }
901 : 2353433 : if (TYPE_ARG_TYPES (t2) == NULL_TREE)
902 : : {
903 : 1 : t1 = c_build_function_type (valtype, TYPE_ARG_TYPES (t1),
904 : 1 : TYPE_NO_NAMED_ARGS_STDARG_P (t1));
905 : 1 : t1 = c_build_type_attribute_variant (t1, attributes);
906 : 1 : return qualify_type (t1, t2);
907 : : }
908 : :
909 : : /* If both args specify argument types, we must merge the two
910 : : lists, argument by argument. */
911 : :
912 : : for (len = 0, newargs = p1;
913 : 6225953 : newargs && newargs != void_list_node;
914 : 3872521 : len++, newargs = TREE_CHAIN (newargs))
915 : : ;
916 : :
917 : 6225953 : for (i = 0; i < len; i++)
918 : 3872521 : newargs = tree_cons (NULL_TREE, NULL_TREE, newargs);
919 : :
920 : : n = newargs;
921 : :
922 : 6225953 : for (; p1 && p1 != void_list_node;
923 : 3872521 : p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2), n = TREE_CHAIN (n))
924 : : {
925 : 3872521 : tree mv1 = remove_qualifiers (TREE_VALUE (p1));
926 : 3872521 : tree mv2 = remove_qualifiers (TREE_VALUE (p2));
927 : :
928 : : /* A null type means arg type is not specified.
929 : : Take whatever the other function type has. */
930 : 3872521 : if (TREE_VALUE (p1) == NULL_TREE)
931 : : {
932 : 0 : TREE_VALUE (n) = TREE_VALUE (p2);
933 : 0 : goto parm_done;
934 : : }
935 : 3872521 : if (TREE_VALUE (p2) == NULL_TREE)
936 : : {
937 : 0 : TREE_VALUE (n) = TREE_VALUE (p1);
938 : 0 : goto parm_done;
939 : : }
940 : :
941 : : /* Given wait (union {union wait *u; int *i} *)
942 : : and wait (union wait *),
943 : : prefer union wait * as type of parm. */
944 : 3872521 : if (TREE_CODE (TREE_VALUE (p1)) == UNION_TYPE
945 : 3872521 : && TREE_VALUE (p1) != TREE_VALUE (p2))
946 : : {
947 : 30 : tree memb;
948 : 30 : for (memb = TYPE_FIELDS (TREE_VALUE (p1));
949 : 38 : memb; memb = DECL_CHAIN (memb))
950 : : {
951 : 38 : tree mv3 = TREE_TYPE (memb);
952 : 38 : if (mv3 && mv3 != error_mark_node
953 : 38 : && TREE_CODE (mv3) != ARRAY_TYPE)
954 : 38 : mv3 = TYPE_MAIN_VARIANT (mv3);
955 : 38 : if (comptypes (mv3, mv2))
956 : : {
957 : 60 : TREE_VALUE (n) = composite_type_internal (TREE_TYPE (memb),
958 : 30 : TREE_VALUE (p2),
959 : : cache);
960 : 30 : pedwarn (input_location, OPT_Wpedantic,
961 : : "function types not truly compatible in ISO C");
962 : 30 : goto parm_done;
963 : : }
964 : : }
965 : : }
966 : 3872491 : if (TREE_CODE (TREE_VALUE (p2)) == UNION_TYPE
967 : 3872491 : && TREE_VALUE (p2) != TREE_VALUE (p1))
968 : : {
969 : 30 : tree memb;
970 : 30 : for (memb = TYPE_FIELDS (TREE_VALUE (p2));
971 : 38 : memb; memb = DECL_CHAIN (memb))
972 : : {
973 : 38 : tree mv3 = TREE_TYPE (memb);
974 : 38 : if (mv3 && mv3 != error_mark_node
975 : 38 : && TREE_CODE (mv3) != ARRAY_TYPE)
976 : 38 : mv3 = TYPE_MAIN_VARIANT (mv3);
977 : 38 : if (comptypes (mv3, mv1))
978 : : {
979 : 30 : TREE_VALUE (n)
980 : 30 : = composite_type_internal (TREE_TYPE (memb),
981 : 30 : TREE_VALUE (p1),
982 : : cache);
983 : 30 : pedwarn (input_location, OPT_Wpedantic,
984 : : "function types not truly compatible in ISO C");
985 : 30 : goto parm_done;
986 : : }
987 : : }
988 : : }
989 : 3872461 : TREE_VALUE (n) = composite_type_internal (mv1, mv2, cache);
990 : 3872521 : parm_done: ;
991 : : }
992 : :
993 : 2353432 : t1 = c_build_function_type (valtype, newargs);
994 : 2353432 : t1 = qualify_type (t1, t2);
995 : : }
996 : : /* FALLTHRU */
997 : :
998 : 2393976 : default:
999 : 2393976 : return c_build_type_attribute_variant (t1, attributes);
1000 : : }
1001 : : }
1002 : :
1003 : : tree
1004 : 5730472 : composite_type (tree t1, tree t2)
1005 : : {
1006 : 5730472 : gcc_checking_assert (comptypes_check_for_composite (t1, t2));
1007 : :
1008 : 5730472 : struct composite_cache cache = { };
1009 : 5730472 : tree n = composite_type_internal (t1, t2, &cache);
1010 : :
1011 : 5730472 : gcc_checking_assert (comptypes_check_for_composite (n, t1));
1012 : 5730472 : gcc_checking_assert (comptypes_check_for_composite (n, t2));
1013 : 5730472 : return n;
1014 : : }
1015 : :
1016 : : /* Return the type of a conditional expression between pointers to
1017 : : possibly differently qualified versions of compatible types.
1018 : :
1019 : : We assume that comp_target_types has already been done and returned
1020 : : true; if that isn't so, this may crash. */
1021 : :
1022 : : static tree
1023 : 113637 : common_pointer_type (tree t1, tree t2)
1024 : : {
1025 : 113637 : tree attributes;
1026 : 113637 : unsigned target_quals;
1027 : 113637 : addr_space_t as1, as2, as_common;
1028 : 113637 : int quals1, quals2;
1029 : :
1030 : : /* Save time if the two types are the same. */
1031 : :
1032 : 113637 : if (t1 == t2) return t1;
1033 : :
1034 : : /* If one type is nonsense, use the other. */
1035 : 4428 : if (t1 == error_mark_node)
1036 : : return t2;
1037 : 4428 : if (t2 == error_mark_node)
1038 : : return t1;
1039 : :
1040 : 4428 : gcc_assert (TREE_CODE (t1) == POINTER_TYPE
1041 : : && TREE_CODE (t2) == POINTER_TYPE);
1042 : :
1043 : : /* Merge the attributes. */
1044 : 4428 : attributes = targetm.merge_type_attributes (t1, t2);
1045 : :
1046 : : /* Find the composite type of the target types, and combine the
1047 : : qualifiers of the two types' targets. */
1048 : 4428 : tree pointed_to_1 = TREE_TYPE (t1);
1049 : 4428 : tree pointed_to_2 = TREE_TYPE (t2);
1050 : 4428 : tree target = composite_type (TYPE_MAIN_VARIANT (pointed_to_1),
1051 : 4428 : TYPE_MAIN_VARIANT (pointed_to_2));
1052 : :
1053 : : /* Strip array types to get correct qualifier for pointers to arrays */
1054 : 4428 : quals1 = TYPE_QUALS_NO_ADDR_SPACE (strip_array_types (pointed_to_1));
1055 : 4428 : quals2 = TYPE_QUALS_NO_ADDR_SPACE (strip_array_types (pointed_to_2));
1056 : :
1057 : : /* For function types do not merge const qualifiers, but drop them
1058 : : if used inconsistently. The middle-end uses these to mark const
1059 : : and noreturn functions. */
1060 : 4428 : if (TREE_CODE (pointed_to_1) == FUNCTION_TYPE)
1061 : 2129 : target_quals = (quals1 & quals2);
1062 : : else
1063 : 2299 : target_quals = (quals1 | quals2);
1064 : :
1065 : : /* If the two named address spaces are different, determine the common
1066 : : superset address space. This is guaranteed to exist due to the
1067 : : assumption that comp_target_type returned true. */
1068 : 4428 : as1 = TYPE_ADDR_SPACE (pointed_to_1);
1069 : 4428 : as2 = TYPE_ADDR_SPACE (pointed_to_2);
1070 : 4428 : if (!addr_space_superset (as1, as2, &as_common))
1071 : 0 : gcc_unreachable ();
1072 : :
1073 : 4428 : target_quals |= ENCODE_QUAL_ADDR_SPACE (as_common);
1074 : :
1075 : 4428 : t1 = c_build_pointer_type (c_build_qualified_type (target, target_quals));
1076 : 4428 : return c_build_type_attribute_variant (t1, attributes);
1077 : : }
1078 : :
1079 : : /* Return the common type for two arithmetic types under the usual
1080 : : arithmetic conversions. The default conversions have already been
1081 : : applied, and enumerated types converted to their compatible integer
1082 : : types. The resulting type is unqualified and has no attributes.
1083 : :
1084 : : This is the type for the result of most arithmetic operations
1085 : : if the operands have the given two types. */
1086 : :
1087 : : static tree
1088 : 13609206 : c_common_type (tree t1, tree t2)
1089 : : {
1090 : 13609206 : enum tree_code code1;
1091 : 13609206 : enum tree_code code2;
1092 : :
1093 : : /* If one type is nonsense, use the other. */
1094 : 13609206 : if (t1 == error_mark_node)
1095 : : return t2;
1096 : 13609206 : if (t2 == error_mark_node)
1097 : : return t1;
1098 : :
1099 : 13609206 : if (TYPE_QUALS (t1) != TYPE_UNQUALIFIED)
1100 : 38275 : t1 = TYPE_MAIN_VARIANT (t1);
1101 : :
1102 : 13609206 : if (TYPE_QUALS (t2) != TYPE_UNQUALIFIED)
1103 : 47715 : t2 = TYPE_MAIN_VARIANT (t2);
1104 : :
1105 : 13609206 : if (TYPE_ATTRIBUTES (t1) != NULL_TREE)
1106 : : {
1107 : 183785 : tree attrs = affects_type_identity_attributes (TYPE_ATTRIBUTES (t1));
1108 : 183785 : t1 = c_build_type_attribute_variant (t1, attrs);
1109 : : }
1110 : :
1111 : 13609206 : if (TYPE_ATTRIBUTES (t2) != NULL_TREE)
1112 : : {
1113 : 183264 : tree attrs = affects_type_identity_attributes (TYPE_ATTRIBUTES (t2));
1114 : 183264 : t2 = c_build_type_attribute_variant (t2, attrs);
1115 : : }
1116 : :
1117 : : /* Save time if the two types are the same. */
1118 : :
1119 : 13609206 : if (t1 == t2) return t1;
1120 : :
1121 : 2285495 : code1 = TREE_CODE (t1);
1122 : 2285495 : code2 = TREE_CODE (t2);
1123 : :
1124 : 2285495 : gcc_assert (code1 == VECTOR_TYPE || code1 == COMPLEX_TYPE
1125 : : || code1 == FIXED_POINT_TYPE || code1 == REAL_TYPE
1126 : : || code1 == INTEGER_TYPE || code1 == BITINT_TYPE);
1127 : 2285495 : gcc_assert (code2 == VECTOR_TYPE || code2 == COMPLEX_TYPE
1128 : : || code2 == FIXED_POINT_TYPE || code2 == REAL_TYPE
1129 : : || code2 == INTEGER_TYPE || code2 == BITINT_TYPE);
1130 : :
1131 : : /* When one operand is a decimal float type, the other operand cannot be
1132 : : a generic float type or a complex type. We also disallow vector types
1133 : : here. */
1134 : 2285495 : if ((DECIMAL_FLOAT_TYPE_P (t1) || DECIMAL_FLOAT_TYPE_P (t2))
1135 : 2287918 : && !(DECIMAL_FLOAT_TYPE_P (t1) && DECIMAL_FLOAT_TYPE_P (t2)))
1136 : : {
1137 : 1080 : if (code1 == VECTOR_TYPE || code2 == VECTOR_TYPE)
1138 : : {
1139 : 3 : error ("cannot mix operands of decimal floating and vector types");
1140 : 3 : return error_mark_node;
1141 : : }
1142 : 1077 : if (code1 == COMPLEX_TYPE || code2 == COMPLEX_TYPE)
1143 : : {
1144 : 5 : error ("cannot mix operands of decimal floating and complex types");
1145 : 5 : return error_mark_node;
1146 : : }
1147 : 1072 : if (code1 == REAL_TYPE && code2 == REAL_TYPE)
1148 : : {
1149 : 16 : error ("cannot mix operands of decimal floating "
1150 : : "and other floating types");
1151 : 16 : return error_mark_node;
1152 : : }
1153 : : }
1154 : :
1155 : : /* If one type is a vector type, return that type. (How the usual
1156 : : arithmetic conversions apply to the vector types extension is not
1157 : : precisely specified.) */
1158 : 2285471 : if (code1 == VECTOR_TYPE)
1159 : : return t1;
1160 : :
1161 : 2285193 : if (code2 == VECTOR_TYPE)
1162 : : return t2;
1163 : :
1164 : : /* If one type is complex, form the common type of the non-complex
1165 : : components, then make that complex. Use T1 or T2 if it is the
1166 : : required type. */
1167 : 2285190 : if (code1 == COMPLEX_TYPE || code2 == COMPLEX_TYPE)
1168 : : {
1169 : 89315 : tree subtype1 = code1 == COMPLEX_TYPE ? TREE_TYPE (t1) : t1;
1170 : 89315 : tree subtype2 = code2 == COMPLEX_TYPE ? TREE_TYPE (t2) : t2;
1171 : 89315 : tree subtype = c_common_type (subtype1, subtype2);
1172 : :
1173 : 89315 : if (code1 == COMPLEX_TYPE && TREE_TYPE (t1) == subtype)
1174 : : return t1;
1175 : 59200 : else if (code2 == COMPLEX_TYPE && TREE_TYPE (t2) == subtype)
1176 : : return t2;
1177 : 3241 : else if (TREE_CODE (subtype) == BITINT_TYPE)
1178 : : {
1179 : 8 : sorry ("%<_Complex _BitInt(%d)%> unsupported",
1180 : 4 : TYPE_PRECISION (subtype));
1181 : 6 : return code1 == COMPLEX_TYPE ? t1 : t2;
1182 : : }
1183 : : else
1184 : 3237 : return build_complex_type (subtype);
1185 : : }
1186 : :
1187 : : /* If only one is real, use it as the result. */
1188 : :
1189 : 2195875 : if (code1 == REAL_TYPE && code2 != REAL_TYPE)
1190 : : return t1;
1191 : :
1192 : 2071403 : if (code2 == REAL_TYPE && code1 != REAL_TYPE)
1193 : : return t2;
1194 : :
1195 : : /* If both are real and either are decimal floating point types, use
1196 : : the decimal floating point type with the greater precision. */
1197 : :
1198 : 2041101 : if (code1 == REAL_TYPE && code2 == REAL_TYPE)
1199 : : {
1200 : 102626 : if (TYPE_MAIN_VARIANT (t1) == dfloat128_type_node
1201 : 102626 : || TYPE_MAIN_VARIANT (t2) == dfloat128_type_node)
1202 : : return dfloat128_type_node;
1203 : : /* And prefer _Decimal128 over _Decimal64x which has in GCC's
1204 : : implementation the same mode. */
1205 : 102077 : else if (TYPE_MAIN_VARIANT (t1) == dfloat64x_type_node
1206 : 102077 : || TYPE_MAIN_VARIANT (t2) == dfloat64x_type_node)
1207 : : return dfloat64x_type_node;
1208 : 102073 : else if (TYPE_MAIN_VARIANT (t1) == dfloat64_type_node
1209 : 102073 : || TYPE_MAIN_VARIANT (t2) == dfloat64_type_node)
1210 : : return dfloat64_type_node;
1211 : 101628 : else if (TYPE_MAIN_VARIANT (t1) == dfloat32_type_node
1212 : 101628 : || TYPE_MAIN_VARIANT (t2) == dfloat32_type_node)
1213 : : return dfloat32_type_node;
1214 : : }
1215 : :
1216 : : /* Deal with fixed-point types. */
1217 : 2039758 : if (code1 == FIXED_POINT_TYPE || code2 == FIXED_POINT_TYPE)
1218 : : {
1219 : 0 : unsigned int unsignedp = 0, satp = 0;
1220 : 0 : scalar_mode m1, m2;
1221 : 0 : unsigned int fbit1, ibit1, fbit2, ibit2, max_fbit, max_ibit;
1222 : :
1223 : 0 : m1 = SCALAR_TYPE_MODE (t1);
1224 : 0 : m2 = SCALAR_TYPE_MODE (t2);
1225 : :
1226 : : /* If one input type is saturating, the result type is saturating. */
1227 : 0 : if (TYPE_SATURATING (t1) || TYPE_SATURATING (t2))
1228 : : satp = 1;
1229 : :
1230 : : /* If both fixed-point types are unsigned, the result type is unsigned.
1231 : : When mixing fixed-point and integer types, follow the sign of the
1232 : : fixed-point type.
1233 : : Otherwise, the result type is signed. */
1234 : 0 : if ((TYPE_UNSIGNED (t1) && TYPE_UNSIGNED (t2)
1235 : 0 : && code1 == FIXED_POINT_TYPE && code2 == FIXED_POINT_TYPE)
1236 : 0 : || (code1 == FIXED_POINT_TYPE && code2 != FIXED_POINT_TYPE
1237 : 0 : && TYPE_UNSIGNED (t1))
1238 : 0 : || (code1 != FIXED_POINT_TYPE && code2 == FIXED_POINT_TYPE
1239 : 0 : && TYPE_UNSIGNED (t2)))
1240 : : unsignedp = 1;
1241 : :
1242 : : /* The result type is signed. */
1243 : 0 : if (unsignedp == 0)
1244 : : {
1245 : : /* If the input type is unsigned, we need to convert to the
1246 : : signed type. */
1247 : 0 : if (code1 == FIXED_POINT_TYPE && TYPE_UNSIGNED (t1))
1248 : : {
1249 : 0 : enum mode_class mclass = (enum mode_class) 0;
1250 : 0 : if (GET_MODE_CLASS (m1) == MODE_UFRACT)
1251 : : mclass = MODE_FRACT;
1252 : 0 : else if (GET_MODE_CLASS (m1) == MODE_UACCUM)
1253 : : mclass = MODE_ACCUM;
1254 : : else
1255 : 0 : gcc_unreachable ();
1256 : 0 : m1 = as_a <scalar_mode>
1257 : 0 : (mode_for_size (GET_MODE_PRECISION (m1), mclass, 0));
1258 : : }
1259 : 0 : if (code2 == FIXED_POINT_TYPE && TYPE_UNSIGNED (t2))
1260 : : {
1261 : 0 : enum mode_class mclass = (enum mode_class) 0;
1262 : 0 : if (GET_MODE_CLASS (m2) == MODE_UFRACT)
1263 : : mclass = MODE_FRACT;
1264 : 0 : else if (GET_MODE_CLASS (m2) == MODE_UACCUM)
1265 : : mclass = MODE_ACCUM;
1266 : : else
1267 : 0 : gcc_unreachable ();
1268 : 0 : m2 = as_a <scalar_mode>
1269 : 0 : (mode_for_size (GET_MODE_PRECISION (m2), mclass, 0));
1270 : : }
1271 : : }
1272 : :
1273 : 0 : if (code1 == FIXED_POINT_TYPE)
1274 : : {
1275 : 0 : fbit1 = GET_MODE_FBIT (m1);
1276 : 0 : ibit1 = GET_MODE_IBIT (m1);
1277 : : }
1278 : : else
1279 : : {
1280 : 0 : fbit1 = 0;
1281 : : /* Signed integers need to subtract one sign bit. */
1282 : 0 : ibit1 = TYPE_PRECISION (t1) - (!TYPE_UNSIGNED (t1));
1283 : : }
1284 : :
1285 : 0 : if (code2 == FIXED_POINT_TYPE)
1286 : : {
1287 : 0 : fbit2 = GET_MODE_FBIT (m2);
1288 : 0 : ibit2 = GET_MODE_IBIT (m2);
1289 : : }
1290 : : else
1291 : : {
1292 : 0 : fbit2 = 0;
1293 : : /* Signed integers need to subtract one sign bit. */
1294 : 0 : ibit2 = TYPE_PRECISION (t2) - (!TYPE_UNSIGNED (t2));
1295 : : }
1296 : :
1297 : 0 : max_ibit = ibit1 >= ibit2 ? ibit1 : ibit2;
1298 : 0 : max_fbit = fbit1 >= fbit2 ? fbit1 : fbit2;
1299 : 0 : return c_common_fixed_point_type_for_size (max_ibit, max_fbit, unsignedp,
1300 : : satp);
1301 : : }
1302 : :
1303 : : /* Both real or both integers; use the one with greater precision. */
1304 : :
1305 : 2039758 : if (TYPE_PRECISION (t1) > TYPE_PRECISION (t2))
1306 : : return t1;
1307 : 1076216 : else if (TYPE_PRECISION (t2) > TYPE_PRECISION (t1))
1308 : : return t2;
1309 : :
1310 : : /* Same precision. Prefer long longs to longs to ints when the
1311 : : same precision, following the C99 rules on integer type rank
1312 : : (which are equivalent to the C90 rules for C90 types). */
1313 : :
1314 : 723978 : if (TYPE_MAIN_VARIANT (t1) == long_long_unsigned_type_node
1315 : 723978 : || TYPE_MAIN_VARIANT (t2) == long_long_unsigned_type_node)
1316 : : return long_long_unsigned_type_node;
1317 : :
1318 : 636938 : if (TYPE_MAIN_VARIANT (t1) == long_long_integer_type_node
1319 : 636938 : || TYPE_MAIN_VARIANT (t2) == long_long_integer_type_node)
1320 : : {
1321 : 14729 : if (TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2))
1322 : 361 : return long_long_unsigned_type_node;
1323 : : else
1324 : : return long_long_integer_type_node;
1325 : : }
1326 : :
1327 : 622209 : if (TYPE_MAIN_VARIANT (t1) == long_unsigned_type_node
1328 : 622209 : || TYPE_MAIN_VARIANT (t2) == long_unsigned_type_node)
1329 : : return long_unsigned_type_node;
1330 : :
1331 : 523242 : if (TYPE_MAIN_VARIANT (t1) == long_integer_type_node
1332 : 523242 : || TYPE_MAIN_VARIANT (t2) == long_integer_type_node)
1333 : : {
1334 : : /* But preserve unsignedness from the other type,
1335 : : since long cannot hold all the values of an unsigned int. */
1336 : 26195 : if (TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2))
1337 : 131 : return long_unsigned_type_node;
1338 : : else
1339 : : return long_integer_type_node;
1340 : : }
1341 : :
1342 : : /* For floating types of the same TYPE_PRECISION (which we here
1343 : : assume means either the same set of values, or sets of values
1344 : : neither a subset of the other, with behavior being undefined in
1345 : : the latter case), follow the rules from TS 18661-3: prefer
1346 : : interchange types _FloatN, then standard types long double,
1347 : : double, float, then extended types _FloatNx. For extended types,
1348 : : check them starting with _Float128x as that seems most consistent
1349 : : in spirit with preferring long double to double; for interchange
1350 : : types, also check in that order for consistency although it's not
1351 : : possible for more than one of them to have the same
1352 : : precision. */
1353 : 497047 : tree mv1 = TYPE_MAIN_VARIANT (t1);
1354 : 497047 : tree mv2 = TYPE_MAIN_VARIANT (t2);
1355 : :
1356 : 2484669 : for (int i = NUM_FLOATN_TYPES - 1; i >= 0; i--)
1357 : 1987785 : if (mv1 == FLOATN_TYPE_NODE (i) || mv2 == FLOATN_TYPE_NODE (i))
1358 : : return FLOATN_TYPE_NODE (i);
1359 : :
1360 : : /* Likewise, prefer long double to double even if same size. */
1361 : 496884 : if (mv1 == long_double_type_node || mv2 == long_double_type_node)
1362 : : return long_double_type_node;
1363 : :
1364 : : /* Likewise, prefer double to float even if same size.
1365 : : We got a couple of embedded targets with 32 bit doubles, and the
1366 : : pdp11 might have 64 bit floats. */
1367 : 496642 : if (mv1 == double_type_node || mv2 == double_type_node)
1368 : : return double_type_node;
1369 : :
1370 : 496070 : if (mv1 == float_type_node || mv2 == float_type_node)
1371 : : return float_type_node;
1372 : :
1373 : 1975604 : for (int i = NUM_FLOATNX_TYPES - 1; i >= 0; i--)
1374 : 1481703 : if (mv1 == FLOATNX_TYPE_NODE (i) || mv2 == FLOATNX_TYPE_NODE (i))
1375 : : return FLOATNX_TYPE_NODE (i);
1376 : :
1377 : 493901 : if ((code1 == BITINT_TYPE || code2 == BITINT_TYPE) && code1 != code2)
1378 : : {
1379 : : /* Prefer any other integral types over bit-precise integer types. */
1380 : 10 : if (TYPE_UNSIGNED (t1) == TYPE_UNSIGNED (t2))
1381 : 6 : return code1 == BITINT_TYPE ? t2 : t1;
1382 : : /* If BITINT_TYPE is unsigned and the other type is signed
1383 : : non-BITINT_TYPE with the same precision, the latter has higher rank.
1384 : : In that case:
1385 : : Otherwise, both operands are converted to the unsigned integer type
1386 : : corresponding to the type of the operand with signed integer type. */
1387 : 8 : if (TYPE_UNSIGNED (code1 == BITINT_TYPE ? t1 : t2))
1388 : 5 : return c_common_unsigned_type (code1 == BITINT_TYPE ? t2 : t1);
1389 : : }
1390 : :
1391 : : /* Otherwise prefer the unsigned one. */
1392 : :
1393 : 493893 : if (TYPE_UNSIGNED (t1))
1394 : : return t1;
1395 : : else
1396 : : return t2;
1397 : : }
1398 : :
1399 : : /* Wrapper around c_common_type that is used by c-common.cc and other
1400 : : front end optimizations that remove promotions. ENUMERAL_TYPEs
1401 : : are allowed here and are converted to their compatible integer types.
1402 : : BOOLEAN_TYPEs are allowed here and return either boolean_type_node or
1403 : : preferably a non-Boolean type as the common type. */
1404 : : tree
1405 : 99953 : common_type (tree t1, tree t2)
1406 : : {
1407 : 99953 : if (TREE_CODE (t1) == ENUMERAL_TYPE)
1408 : 0 : t1 = ENUM_UNDERLYING_TYPE (t1);
1409 : 99953 : if (TREE_CODE (t2) == ENUMERAL_TYPE)
1410 : 1 : t2 = ENUM_UNDERLYING_TYPE (t2);
1411 : :
1412 : : /* If both types are BOOLEAN_TYPE, then return boolean_type_node. */
1413 : 99953 : if (TREE_CODE (t1) == BOOLEAN_TYPE
1414 : 584 : && TREE_CODE (t2) == BOOLEAN_TYPE)
1415 : 584 : return boolean_type_node;
1416 : :
1417 : : /* If either type is BOOLEAN_TYPE, then return the other. */
1418 : 99369 : if (TREE_CODE (t1) == BOOLEAN_TYPE)
1419 : : return t2;
1420 : 99369 : if (TREE_CODE (t2) == BOOLEAN_TYPE)
1421 : : return t1;
1422 : :
1423 : 99369 : return c_common_type (t1, t2);
1424 : : }
1425 : :
1426 : :
1427 : :
1428 : : /* Helper function for comptypes. For two compatible types, return 1
1429 : : if they pass consistency checks. In particular we test that
1430 : : TYPE_CANONICAL is set correctly, i.e. the two types can alias. */
1431 : :
1432 : : static bool
1433 : 42787093 : comptypes_verify (tree type1, tree type2)
1434 : : {
1435 : 42787093 : if (type1 == type2 || !type1 || !type2
1436 : 3265256 : || TREE_CODE (type1) == ERROR_MARK || TREE_CODE (type2) == ERROR_MARK)
1437 : : return true;
1438 : :
1439 : 3265255 : gcc_checking_assert (c_verify_type (type1));
1440 : 3265255 : gcc_checking_assert (c_verify_type (type2));
1441 : :
1442 : 3265255 : if (TYPE_CANONICAL (type1) != TYPE_CANONICAL (type2)
1443 : 380754 : && !TYPE_STRUCTURAL_EQUALITY_P (type1)
1444 : 3644364 : && !TYPE_STRUCTURAL_EQUALITY_P (type2))
1445 : : {
1446 : : /* FIXME: check other types. */
1447 : 378922 : if (RECORD_OR_UNION_TYPE_P (type1)
1448 : 378922 : || TREE_CODE (type1) == ENUMERAL_TYPE
1449 : 378922 : || TREE_CODE (type2) == ENUMERAL_TYPE)
1450 : 0 : return false;
1451 : : }
1452 : : return true;
1453 : : }
1454 : :
1455 : : struct comptypes_data {
1456 : :
1457 : : /* output */
1458 : : bool enum_and_int_p;
1459 : : bool different_types_p;
1460 : : bool warning_needed;
1461 : :
1462 : : /* context */
1463 : : bool anon_field;
1464 : : bool pointedto;
1465 : :
1466 : : /* configuration */
1467 : : bool equiv;
1468 : : bool ignore_promoting_args;
1469 : :
1470 : : const struct tagged_tu_seen_cache* cache;
1471 : : };
1472 : :
1473 : :
1474 : : /* Helper function for composite_type. This function ignores when the
1475 : : function type of an old-style declaration is incompatible with a type
1476 : : of a declaration with prototype because some are arguments are not
1477 : : self-promoting. This is ignored only for function types but not
1478 : : ignored in a nested context. */
1479 : :
1480 : : static bool
1481 : 17191416 : comptypes_check_for_composite (tree t1, tree t2)
1482 : : {
1483 : 17191416 : struct comptypes_data data = { };
1484 : 17191416 : data.ignore_promoting_args = FUNCTION_TYPE == TREE_CODE (t1);
1485 : 17191416 : return comptypes_internal (t1, t2, &data);
1486 : : }
1487 : :
1488 : :
1489 : : /* C implementation of compatible_types_for_indirection_note_p. */
1490 : :
1491 : : bool
1492 : 761 : compatible_types_for_indirection_note_p (tree type1, tree type2)
1493 : : {
1494 : 761 : return comptypes (type1, type2) == 1;
1495 : : }
1496 : :
1497 : : /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
1498 : : or various other operations. Return 2 if they are compatible
1499 : : but a warning may be needed if you use them together. */
1500 : :
1501 : : int
1502 : 54681440 : comptypes (tree type1, tree type2)
1503 : : {
1504 : 54681440 : struct comptypes_data data = { };
1505 : 54681440 : bool ret = comptypes_internal (type1, type2, &data);
1506 : :
1507 : 54681440 : gcc_checking_assert (!ret || comptypes_verify (type1, type2));
1508 : :
1509 : 36600555 : return ret ? (data.warning_needed ? 2 : 1) : 0;
1510 : : }
1511 : :
1512 : :
1513 : : /* Like comptypes, but it returns non-zero only for identical
1514 : : types. */
1515 : :
1516 : : bool
1517 : 275 : comptypes_same_p (tree type1, tree type2)
1518 : : {
1519 : 275 : struct comptypes_data data = { };
1520 : 275 : bool ret = comptypes_internal (type1, type2, &data);
1521 : :
1522 : 275 : gcc_checking_assert (!ret || comptypes_verify (type1, type2));
1523 : :
1524 : 275 : if (data.different_types_p)
1525 : 103 : return false;
1526 : :
1527 : : return ret;
1528 : : }
1529 : :
1530 : :
1531 : : /* Like comptypes, but if it returns non-zero because enum and int are
1532 : : compatible, it sets *ENUM_AND_INT_P to true. */
1533 : :
1534 : : int
1535 : 6385042 : comptypes_check_enum_int (tree type1, tree type2, bool *enum_and_int_p)
1536 : : {
1537 : 6385042 : struct comptypes_data data = { };
1538 : 6385042 : bool ret = comptypes_internal (type1, type2, &data);
1539 : 6385042 : *enum_and_int_p = data.enum_and_int_p;
1540 : :
1541 : 6385042 : gcc_checking_assert (!ret || comptypes_verify (type1, type2));
1542 : :
1543 : 6141789 : return ret ? (data.warning_needed ? 2 : 1) : 0;
1544 : : }
1545 : :
1546 : : /* Like comptypes, but if it returns nonzero for different types, it
1547 : : sets *DIFFERENT_TYPES_P to true. */
1548 : :
1549 : : int
1550 : 44511 : comptypes_check_different_types (tree type1, tree type2,
1551 : : bool *different_types_p)
1552 : : {
1553 : 44511 : struct comptypes_data data = { };
1554 : 44511 : bool ret = comptypes_internal (type1, type2, &data);
1555 : 44511 : *different_types_p = data.different_types_p;
1556 : :
1557 : 44511 : gcc_checking_assert (!ret || comptypes_verify (type1, type2));
1558 : :
1559 : 44511 : return ret ? (data.warning_needed ? 2 : 1) : 0;
1560 : : }
1561 : :
1562 : :
1563 : : /* Like comptypes, but if it returns true for struct and union types
1564 : : considered equivalent for aliasing purposes, i.e. for setting
1565 : : TYPE_CANONICAL after completing a struct or union.
1566 : :
1567 : : This function must return false only for types which are not
1568 : : compatible according to C language semantics (cf. comptypes),
1569 : : otherwise the middle-end would make incorrect aliasing decisions.
1570 : : It may return true for some similar types that are not compatible
1571 : : according to those stricter rules.
1572 : :
1573 : : In particular, we ignore size expression in arrays so that the
1574 : : following structs are in the same equivalence class:
1575 : :
1576 : : struct foo { char (*buf)[]; };
1577 : : struct foo { char (*buf)[3]; };
1578 : : struct foo { char (*buf)[4]; };
1579 : :
1580 : : We also treat unions / structs with members which are pointers to
1581 : : structures or unions with the same tag as equivalent (if they are not
1582 : : incompatible for other reasons). Although incomplete structure
1583 : : or union types are not compatible to any other type, they may become
1584 : : compatible to different types when completed. To avoid having to update
1585 : : TYPE_CANONICAL at this point, we only consider the tag when forming
1586 : : the equivalence classes. For example, the following types with tag
1587 : : 'foo' are all considered equivalent:
1588 : :
1589 : : struct bar;
1590 : : struct foo { struct bar *x };
1591 : : struct foo { struct bar { int a; } *x };
1592 : : struct foo { struct bar { char b; } *x }; */
1593 : :
1594 : : bool
1595 : 14273026 : comptypes_equiv_p (tree type1, tree type2)
1596 : : {
1597 : 14273026 : struct comptypes_data data = { };
1598 : 14273026 : data.equiv = true;
1599 : 14273026 : bool ret = comptypes_internal (type1, type2, &data);
1600 : :
1601 : : /* check that different equivance classes are assigned only
1602 : : to types that are not compatible. */
1603 : 14273026 : gcc_checking_assert (ret || !comptypes (type1, type2));
1604 : :
1605 : 14273026 : return ret;
1606 : : }
1607 : :
1608 : :
1609 : : /* Return true if TYPE1 and TYPE2 are compatible types for assignment
1610 : : or various other operations. If they are compatible but a warning may
1611 : : be needed if you use them together, 'warning_needed' in DATA is set.
1612 : : If one type is an enum and the other a compatible integer type, then
1613 : : this sets 'enum_and_int_p' in DATA to true (it is never set to
1614 : : false). If the types are compatible but different enough not to be
1615 : : permitted in C11 typedef redeclarations, then this sets
1616 : : 'different_types_p' in DATA to true; it is never set to
1617 : : false, but may or may not be set if the types are incompatible.
1618 : : If two functions types are not compatible only because one is
1619 : : an old-style definition that does not have self-promoting arguments,
1620 : : then this can be ignored by setting 'ignore_promoting_args_p'.
1621 : : For 'equiv' we can compute equivalency classes (see above).
1622 : : This differs from comptypes, in that we don't free the seen
1623 : : types. */
1624 : :
1625 : : static bool
1626 : 126404679 : comptypes_internal (const_tree type1, const_tree type2,
1627 : : struct comptypes_data *data)
1628 : : {
1629 : 126675635 : const_tree t1 = type1;
1630 : 126675635 : const_tree t2 = type2;
1631 : :
1632 : : /* Suppress errors caused by previously reported errors. */
1633 : :
1634 : 126675635 : if (t1 == t2 || !t1 || !t2
1635 : 43568451 : || TREE_CODE (t1) == ERROR_MARK || TREE_CODE (t2) == ERROR_MARK)
1636 : : return true;
1637 : :
1638 : : /* Enumerated types are compatible with integer types, but this is
1639 : : not transitive: two enumerated types in the same translation unit
1640 : : are compatible with each other only if they are the same type. */
1641 : :
1642 : 43568448 : if (TREE_CODE (t1) == ENUMERAL_TYPE
1643 : 1008 : && COMPLETE_TYPE_P (t1)
1644 : 43569412 : && TREE_CODE (t2) != ENUMERAL_TYPE)
1645 : : {
1646 : 852 : t1 = ENUM_UNDERLYING_TYPE (t1);
1647 : 852 : if (TREE_CODE (t2) != VOID_TYPE)
1648 : : {
1649 : 848 : data->enum_and_int_p = true;
1650 : 848 : data->different_types_p = true;
1651 : : }
1652 : : }
1653 : 43567596 : else if (TREE_CODE (t2) == ENUMERAL_TYPE
1654 : 4526 : && COMPLETE_TYPE_P (t2)
1655 : 43572116 : && TREE_CODE (t1) != ENUMERAL_TYPE)
1656 : : {
1657 : 4408 : t2 = ENUM_UNDERLYING_TYPE (t2);
1658 : 4408 : if (TREE_CODE (t1) != VOID_TYPE)
1659 : : {
1660 : 3509 : data->enum_and_int_p = true;
1661 : 3509 : data->different_types_p = true;
1662 : : }
1663 : : }
1664 : :
1665 : 43568448 : if (t1 == t2)
1666 : : return true;
1667 : :
1668 : : /* Different classes of types can't be compatible. */
1669 : :
1670 : 43567155 : if (TREE_CODE (t1) != TREE_CODE (t2))
1671 : : return false;
1672 : :
1673 : : /* Qualifiers must match. C99 6.7.3p9 */
1674 : :
1675 : 35721473 : if (TYPE_QUALS (t1) != TYPE_QUALS (t2))
1676 : : return false;
1677 : :
1678 : : /* Allow for two different type nodes which have essentially the same
1679 : : definition. Note that we already checked for equality of the type
1680 : : qualifiers (just above). */
1681 : :
1682 : 35682298 : if (TREE_CODE (t1) != ARRAY_TYPE
1683 : 35682298 : && TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
1684 : : return true;
1685 : :
1686 : 35352016 : int attrval;
1687 : :
1688 : : /* 1 if no need for warning yet, 2 if warning cause has been seen. */
1689 : 35352016 : if (!(attrval = comp_type_attributes (t1, t2)))
1690 : : return false;
1691 : :
1692 : 35351655 : if (2 == attrval)
1693 : 336 : data->warning_needed = true;
1694 : :
1695 : 35351655 : switch (TREE_CODE (t1))
1696 : : {
1697 : 3294471 : case INTEGER_TYPE:
1698 : 3294471 : case FIXED_POINT_TYPE:
1699 : 3294471 : case REAL_TYPE:
1700 : 3294471 : case BITINT_TYPE:
1701 : : /* With these nodes, we can't determine type equivalence by
1702 : : looking at what is stored in the nodes themselves, because
1703 : : two nodes might have different TYPE_MAIN_VARIANTs but still
1704 : : represent the same type. For example, wchar_t and int could
1705 : : have the same properties (TYPE_PRECISION, TYPE_MIN_VALUE,
1706 : : TYPE_MAX_VALUE, etc.), but have different TYPE_MAIN_VARIANTs
1707 : : and are distinct types. On the other hand, int and the
1708 : : following typedef
1709 : :
1710 : : typedef int INT __attribute((may_alias));
1711 : :
1712 : : have identical properties, different TYPE_MAIN_VARIANTs, but
1713 : : represent the same type. The canonical type system keeps
1714 : : track of equivalence in this case, so we fall back on it. */
1715 : 3294471 : return TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2);
1716 : :
1717 : 270956 : case POINTER_TYPE:
1718 : : /* Do not remove mode information. */
1719 : 270956 : if (TYPE_MODE (t1) != TYPE_MODE (t2))
1720 : : return false;
1721 : 270956 : data->pointedto = true;
1722 : 270956 : return comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2), data);
1723 : :
1724 : 8247485 : case FUNCTION_TYPE:
1725 : 8247485 : return function_types_compatible_p (t1, t2, data);
1726 : :
1727 : 150332 : case ARRAY_TYPE:
1728 : 150332 : {
1729 : 150332 : tree d1 = TYPE_DOMAIN (t1);
1730 : 150332 : tree d2 = TYPE_DOMAIN (t2);
1731 : 150332 : bool d1_variable, d2_variable;
1732 : 150332 : bool d1_zero, d2_zero;
1733 : :
1734 : : /* Target types must match incl. qualifiers. */
1735 : 150332 : if (!comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2), data))
1736 : : return false;
1737 : :
1738 : 116797 : if ((d1 == NULL_TREE) != (d2 == NULL_TREE))
1739 : 6166 : data->different_types_p = true;
1740 : : /* Ignore size mismatches when forming equivalence classes. */
1741 : 116797 : if (data->equiv)
1742 : : return true;
1743 : : /* Sizes must match unless one is missing or variable. */
1744 : 49416 : if (d1 == NULL_TREE || d2 == NULL_TREE || d1 == d2)
1745 : : return true;
1746 : :
1747 : 33331 : d1_zero = !TYPE_MAX_VALUE (d1);
1748 : 33331 : d2_zero = !TYPE_MAX_VALUE (d2);
1749 : :
1750 : 66662 : d1_variable = (!d1_zero
1751 : 33331 : && (TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST
1752 : 33325 : || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST));
1753 : 66662 : d2_variable = (!d2_zero
1754 : 33331 : && (TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST
1755 : 33235 : || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST));
1756 : :
1757 : 33331 : if (d1_variable != d2_variable)
1758 : 740 : data->different_types_p = true;
1759 : 33331 : if (d1_variable || d2_variable)
1760 : : return true;
1761 : 4038 : if (d1_zero && d2_zero)
1762 : : return true;
1763 : 4038 : if (d1_zero || d2_zero
1764 : 3942 : || !tree_int_cst_equal (TYPE_MIN_VALUE (d1), TYPE_MIN_VALUE (d2))
1765 : 7980 : || !tree_int_cst_equal (TYPE_MAX_VALUE (d1), TYPE_MAX_VALUE (d2)))
1766 : 4038 : return false;
1767 : :
1768 : : return true;
1769 : : }
1770 : :
1771 : 22871378 : case ENUMERAL_TYPE:
1772 : 22871378 : case RECORD_TYPE:
1773 : 22871378 : case UNION_TYPE:
1774 : :
1775 : 22871378 : if (!flag_isoc23)
1776 : : return false;
1777 : :
1778 : 22871332 : return tagged_types_tu_compatible_p (t1, t2, data);
1779 : :
1780 : 516468 : case VECTOR_TYPE:
1781 : 1032936 : return known_eq (TYPE_VECTOR_SUBPARTS (t1), TYPE_VECTOR_SUBPARTS (t2))
1782 : 516468 : && comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2), data);
1783 : :
1784 : : default:
1785 : : return false;
1786 : : }
1787 : : gcc_unreachable ();
1788 : : }
1789 : :
1790 : : /* Return true if TTL and TTR are pointers to types that are equivalent, ignoring
1791 : : their qualifiers, except for named address spaces. If the pointers point to
1792 : : different named addresses, then we must determine if one address space is a
1793 : : subset of the other. */
1794 : :
1795 : : static bool
1796 : 1731016 : comp_target_types (location_t location, tree ttl, tree ttr)
1797 : : {
1798 : 1731016 : int val;
1799 : 1731016 : int val_ped;
1800 : 1731016 : tree mvl = TREE_TYPE (ttl);
1801 : 1731016 : tree mvr = TREE_TYPE (ttr);
1802 : 1731016 : addr_space_t asl = TYPE_ADDR_SPACE (mvl);
1803 : 1731016 : addr_space_t asr = TYPE_ADDR_SPACE (mvr);
1804 : 1731016 : addr_space_t as_common;
1805 : 1731016 : bool enum_and_int_p;
1806 : :
1807 : : /* Fail if pointers point to incompatible address spaces. */
1808 : 1731016 : if (!addr_space_superset (asl, asr, &as_common))
1809 : : return 0;
1810 : :
1811 : : /* For pedantic record result of comptypes on arrays before losing
1812 : : qualifiers on the element type below. */
1813 : 1731016 : val_ped = 1;
1814 : :
1815 : 1731016 : if (TREE_CODE (mvl) == ARRAY_TYPE
1816 : 1953 : && TREE_CODE (mvr) == ARRAY_TYPE)
1817 : 1930 : val_ped = comptypes (mvl, mvr);
1818 : :
1819 : : /* Qualifiers on element types of array types that are
1820 : : pointer targets are also removed. */
1821 : 1731016 : mvl = remove_qualifiers (mvl);
1822 : 1731016 : mvr = remove_qualifiers (mvr);
1823 : :
1824 : 1731016 : enum_and_int_p = false;
1825 : 1731016 : val = comptypes_check_enum_int (mvl, mvr, &enum_and_int_p);
1826 : :
1827 : 1731016 : if (val == 1 && val_ped != 1)
1828 : 190 : pedwarn_c11 (location, OPT_Wpedantic, "invalid use of pointers to arrays with different qualifiers "
1829 : : "in ISO C before C23");
1830 : :
1831 : 1731016 : if (val == 2)
1832 : 126 : pedwarn (location, OPT_Wpedantic, "types are not quite compatible");
1833 : :
1834 : 1731016 : if (val == 1 && enum_and_int_p && warn_cxx_compat)
1835 : 2 : warning_at (location, OPT_Wc___compat,
1836 : : "pointer target types incompatible in C++");
1837 : :
1838 : 1731016 : return val;
1839 : : }
1840 : :
1841 : : /* Subroutines of `comptypes'. */
1842 : :
1843 : : /* Return true if two 'struct', 'union', or 'enum' types T1 and T2 are
1844 : : compatible. The two types are not the same (which has been
1845 : : checked earlier in comptypes_internal). */
1846 : :
1847 : : static bool
1848 : 22871332 : tagged_types_tu_compatible_p (const_tree t1, const_tree t2,
1849 : : struct comptypes_data *data)
1850 : : {
1851 : 22871332 : tree s1, s2;
1852 : :
1853 : 22871332 : if (c_type_tag (t1) != c_type_tag (t2))
1854 : : return false;
1855 : :
1856 : : /* When forming equivalence classes for TYPE_CANONICAL in C23, we treat
1857 : : structs with the same tag as equivalent, but only when they are targets
1858 : : of pointers inside other structs. */
1859 : 18892760 : if (data->equiv && data->pointedto)
1860 : : return true;
1861 : :
1862 : : /* Different types without tag are incompatible except as an anonymous
1863 : : field or when forming equivalence classes for TYPE_CANONICAL. */
1864 : 18892726 : if (!data->anon_field && !data->equiv && NULL_TREE == c_type_tag (t1))
1865 : : return false;
1866 : :
1867 : 14006720 : if (!data->anon_field && TYPE_STUB_DECL (t1) != TYPE_STUB_DECL (t2))
1868 : 14005770 : data->different_types_p = true;
1869 : :
1870 : : /* Incomplete types are incompatible inside a TU. */
1871 : 14006720 : if (TYPE_SIZE (t1) == NULL || TYPE_SIZE (t2) == NULL)
1872 : : return false;
1873 : :
1874 : 14006710 : if (ENUMERAL_TYPE != TREE_CODE (t1)
1875 : 14006710 : && (TYPE_REVERSE_STORAGE_ORDER (t1)
1876 : 14006655 : != TYPE_REVERSE_STORAGE_ORDER (t2)))
1877 : : return false;
1878 : :
1879 : 14006700 : if (TYPE_USER_ALIGN (t1) != TYPE_USER_ALIGN (t2))
1880 : 140962 : data->different_types_p = true;
1881 : :
1882 : : /* For types already being looked at in some active
1883 : : invocation of this function, assume compatibility.
1884 : : The cache is built as a linked list on the stack
1885 : : with the head of the list passed downwards. */
1886 : 14006700 : for (const struct tagged_tu_seen_cache *t = data->cache;
1887 : 14015524 : t != NULL; t = t->next)
1888 : 8935 : if (t->t1 == t1 && t->t2 == t2)
1889 : : return true;
1890 : :
1891 : 14006589 : const struct tagged_tu_seen_cache entry = { data->cache, t1, t2 };
1892 : :
1893 : 14006589 : switch (TREE_CODE (t1))
1894 : : {
1895 : 55 : case ENUMERAL_TYPE:
1896 : 55 : {
1897 : 55 : if (!comptypes (ENUM_UNDERLYING_TYPE (t1), ENUM_UNDERLYING_TYPE (t2)))
1898 : : return false;
1899 : :
1900 : : /* Speed up the case where the type values are in the same order. */
1901 : 51 : tree tv1 = TYPE_VALUES (t1);
1902 : 51 : tree tv2 = TYPE_VALUES (t2);
1903 : :
1904 : 51 : if (tv1 == tv2)
1905 : : return true;
1906 : :
1907 : 97 : for (;tv1 && tv2; tv1 = TREE_CHAIN (tv1), tv2 = TREE_CHAIN (tv2))
1908 : : {
1909 : 58 : if (TREE_PURPOSE (tv1) != TREE_PURPOSE (tv2))
1910 : : break;
1911 : :
1912 : 51 : if (simple_cst_equal (DECL_INITIAL (TREE_VALUE (tv1)),
1913 : 51 : DECL_INITIAL (TREE_VALUE (tv2))) != 1)
1914 : : break;
1915 : : }
1916 : :
1917 : 51 : if (tv1 == NULL_TREE && tv2 == NULL_TREE)
1918 : : return true;
1919 : :
1920 : 12 : if (tv1 == NULL_TREE || tv2 == NULL_TREE)
1921 : : return false;
1922 : :
1923 : 12 : if (list_length (TYPE_VALUES (t1)) != list_length (TYPE_VALUES (t2)))
1924 : : return false;
1925 : :
1926 : 20 : for (s1 = TYPE_VALUES (t1); s1; s1 = TREE_CHAIN (s1))
1927 : : {
1928 : 16 : s2 = purpose_member (TREE_PURPOSE (s1), TYPE_VALUES (t2));
1929 : :
1930 : 16 : if (s2 == NULL
1931 : 29 : || simple_cst_equal (DECL_INITIAL (TREE_VALUE (s1)),
1932 : 13 : DECL_INITIAL (TREE_VALUE (s2))) != 1)
1933 : 8 : return false;
1934 : : }
1935 : :
1936 : : return true;
1937 : : }
1938 : :
1939 : 14006534 : case UNION_TYPE:
1940 : 14006534 : case RECORD_TYPE:
1941 : :
1942 : 14006534 : if (list_length (TYPE_FIELDS (t1)) != list_length (TYPE_FIELDS (t2)))
1943 : : return false;
1944 : :
1945 : 12168508 : for (s1 = TYPE_FIELDS (t1), s2 = TYPE_FIELDS (t2);
1946 : 13677824 : s1 && s2;
1947 : 1509316 : s1 = DECL_CHAIN (s1), s2 = DECL_CHAIN (s2))
1948 : : {
1949 : 13615038 : gcc_assert (TREE_CODE (s1) == FIELD_DECL);
1950 : 13615038 : gcc_assert (TREE_CODE (s2) == FIELD_DECL);
1951 : :
1952 : 13615038 : tree ft1 = TREE_TYPE (s1);
1953 : 13615038 : tree ft2 = TREE_TYPE (s2);
1954 : :
1955 : 13615038 : if (DECL_NAME (s1) != DECL_NAME (s2))
1956 : : return false;
1957 : :
1958 : 12040381 : if (DECL_ALIGN (s1) != DECL_ALIGN (s2))
1959 : : return false;
1960 : :
1961 : 3192826 : if (DECL_C_BIT_FIELD (s1) != DECL_C_BIT_FIELD (s2))
1962 : : return false;
1963 : :
1964 : 3192806 : if (DECL_C_BIT_FIELD (s1))
1965 : : {
1966 : 496 : if (!tree_int_cst_equal (DECL_SIZE (s1), DECL_SIZE (s2)))
1967 : : return false;
1968 : :
1969 : 342 : ft1 = DECL_BIT_FIELD_TYPE (s1);
1970 : 342 : ft2 = DECL_BIT_FIELD_TYPE (s2);
1971 : : }
1972 : :
1973 : 3192652 : if (TREE_CODE (ft1) == ERROR_MARK || TREE_CODE (ft2) == ERROR_MARK)
1974 : : return false;
1975 : :
1976 : 3192651 : data->anon_field = !DECL_NAME (s1);
1977 : 3192651 : data->pointedto = false;
1978 : :
1979 : 3192651 : const struct tagged_tu_seen_cache *cache = data->cache;
1980 : 3192651 : data->cache = &entry;
1981 : 3192651 : bool ret = comptypes_internal (ft1, ft2, data);
1982 : 3192651 : data->cache = cache;
1983 : 3192651 : if (!ret)
1984 : : return false;
1985 : :
1986 : 1576630 : tree st1 = TYPE_SIZE (TREE_TYPE (s1));
1987 : 1576630 : tree st2 = TYPE_SIZE (TREE_TYPE (s2));
1988 : :
1989 : 1576630 : if (data->equiv
1990 : 983527 : && st1 && TREE_CODE (st1) == INTEGER_CST
1991 : 983491 : && st2 && TREE_CODE (st2) == INTEGER_CST
1992 : 2560118 : && !tree_int_cst_equal (st1, st2))
1993 : : return false;
1994 : :
1995 : 1509333 : tree counted_by1 = lookup_attribute ("counted_by",
1996 : 1509333 : DECL_ATTRIBUTES (s1));
1997 : 1509333 : tree counted_by2 = lookup_attribute ("counted_by",
1998 : 1509333 : DECL_ATTRIBUTES (s2));
1999 : : /* If there is no counted_by attribute for both fields. */
2000 : 1509333 : if (!counted_by1 && !counted_by2)
2001 : 1509306 : continue;
2002 : :
2003 : : /* If only one field has counted_by attribute. */
2004 : 27 : if ((counted_by1 && !counted_by2)
2005 : 27 : || (!counted_by1 && counted_by2))
2006 : : return false;
2007 : :
2008 : : /* Now both s1 and s2 have counted_by attributes, check
2009 : : whether they are the same. */
2010 : :
2011 : 21 : tree counted_by_field1
2012 : 21 : = lookup_field (t1, TREE_VALUE (TREE_VALUE (counted_by1)));
2013 : 21 : tree counted_by_field2
2014 : 21 : = lookup_field (t2, TREE_VALUE (TREE_VALUE (counted_by2)));
2015 : :
2016 : 21 : gcc_assert (counted_by_field1 && counted_by_field2);
2017 : :
2018 : 42 : while (TREE_CHAIN (counted_by_field1))
2019 : 21 : counted_by_field1 = TREE_CHAIN (counted_by_field1);
2020 : 38 : while (TREE_CHAIN (counted_by_field2))
2021 : 17 : counted_by_field2 = TREE_CHAIN (counted_by_field2);
2022 : :
2023 : 21 : if (DECL_NAME (TREE_VALUE (counted_by_field1))
2024 : 21 : != DECL_NAME (TREE_VALUE (counted_by_field2)))
2025 : : return false;
2026 : : }
2027 : : return true;
2028 : :
2029 : 0 : default:
2030 : 0 : gcc_unreachable ();
2031 : : }
2032 : : }
2033 : :
2034 : : /* Return true if two function types F1 and F2 are compatible.
2035 : : If either type specifies no argument types,
2036 : : the other must specify a fixed number of self-promoting arg types.
2037 : : Otherwise, if one type specifies only the number of arguments,
2038 : : the other must specify that number of self-promoting arg types.
2039 : : Otherwise, the argument types must match. */
2040 : :
2041 : : static bool
2042 : 8247485 : function_types_compatible_p (const_tree f1, const_tree f2,
2043 : : struct comptypes_data *data)
2044 : : {
2045 : 8247485 : tree ret1 = TREE_TYPE (f1);
2046 : 8247485 : tree ret2 = TREE_TYPE (f2);
2047 : :
2048 : : /* 'volatile' qualifiers on a function's return type used to mean
2049 : : the function is noreturn. */
2050 : 8247485 : if (TYPE_VOLATILE (ret1) != TYPE_VOLATILE (ret2))
2051 : 29 : pedwarn (input_location, 0, "function return types not compatible due to %<volatile%>");
2052 : 8247485 : if (TYPE_VOLATILE (ret1))
2053 : 15 : ret1 = build_qualified_type (TYPE_MAIN_VARIANT (ret1),
2054 : 15 : TYPE_QUALS (ret1) & ~TYPE_QUAL_VOLATILE);
2055 : 8247485 : if (TYPE_VOLATILE (ret2))
2056 : 18 : ret2 = build_qualified_type (TYPE_MAIN_VARIANT (ret2),
2057 : 18 : TYPE_QUALS (ret2) & ~TYPE_QUAL_VOLATILE);
2058 : :
2059 : 8247485 : bool ignore_pargs = data->ignore_promoting_args;
2060 : 8247485 : data->ignore_promoting_args = false;
2061 : :
2062 : 8247485 : if (!comptypes_internal (ret1, ret2, data))
2063 : : return false;
2064 : :
2065 : 8244898 : data->ignore_promoting_args = ignore_pargs;
2066 : :
2067 : 8244898 : tree args1 = TYPE_ARG_TYPES (f1);
2068 : 8244898 : tree args2 = TYPE_ARG_TYPES (f2);
2069 : :
2070 : 8244898 : if ((args1 == NULL_TREE) != (args2 == NULL_TREE))
2071 : 40973 : data->different_types_p = true;
2072 : :
2073 : : /* An unspecified parmlist matches any specified parmlist
2074 : : whose argument types don't need default promotions. */
2075 : :
2076 : 8244898 : if (args1 == NULL_TREE)
2077 : : {
2078 : 21630 : if (TYPE_NO_NAMED_ARGS_STDARG_P (f1) != TYPE_NO_NAMED_ARGS_STDARG_P (f2))
2079 : : return false;
2080 : 21625 : if (!(data->ignore_promoting_args || self_promoting_args_p (args2)))
2081 : : return false;
2082 : 21155 : data->ignore_promoting_args = false;
2083 : : /* If one of these types comes from a non-prototype fn definition,
2084 : : compare that with the other type's arglist.
2085 : : If they don't match, ask for a warning (but no error). */
2086 : 21155 : if (TYPE_ACTUAL_ARG_TYPES (f1)
2087 : 21155 : && !type_lists_compatible_p (args2, TYPE_ACTUAL_ARG_TYPES (f1), data))
2088 : 12 : data->warning_needed = true;
2089 : 21155 : return true;
2090 : : }
2091 : 8223268 : if (args2 == NULL_TREE)
2092 : : {
2093 : 19425 : if (TYPE_NO_NAMED_ARGS_STDARG_P (f1) != TYPE_NO_NAMED_ARGS_STDARG_P (f2))
2094 : : return false;
2095 : 19421 : if (!(data->ignore_promoting_args || self_promoting_args_p (args1)))
2096 : : return false;
2097 : 19360 : data->ignore_promoting_args = false;
2098 : 19360 : if (TYPE_ACTUAL_ARG_TYPES (f2)
2099 : 19360 : && !type_lists_compatible_p (args1, TYPE_ACTUAL_ARG_TYPES (f2), data))
2100 : 1 : data->warning_needed = true;
2101 : 19360 : return true;
2102 : : }
2103 : :
2104 : : /* Both types have argument lists: compare them and propagate results. */
2105 : 8203843 : return type_lists_compatible_p (args1, args2, data);
2106 : : }
2107 : :
2108 : : /* Check two lists of types for compatibility, returning false for
2109 : : incompatible, true for compatible. */
2110 : :
2111 : : static bool
2112 : 8203919 : type_lists_compatible_p (const_tree args1, const_tree args2,
2113 : : struct comptypes_data *data)
2114 : : {
2115 : 51733023 : while (1)
2116 : : {
2117 : 29968471 : if (args1 == NULL_TREE && args2 == NULL_TREE)
2118 : : return true;
2119 : : /* If one list is shorter than the other,
2120 : : they fail to match. */
2121 : 21907186 : if (args1 == NULL_TREE || args2 == NULL_TREE)
2122 : : return false;
2123 : 21907179 : tree a1 = TREE_VALUE (args1);
2124 : 21907179 : tree a2 = TREE_VALUE (args2);
2125 : 21907179 : tree mv1 = remove_qualifiers (a1);
2126 : 21907179 : tree mv2 = remove_qualifiers (a2);
2127 : : /* A null pointer instead of a type
2128 : : means there is supposed to be an argument
2129 : : but nothing is specified about what type it has.
2130 : : So match anything that self-promotes. */
2131 : 21907179 : if ((a1 == NULL_TREE) != (a2 == NULL_TREE))
2132 : 0 : data->different_types_p = true;
2133 : 21907179 : if (a1 == NULL_TREE)
2134 : : {
2135 : 0 : if (c_type_promotes_to (a2) != a2)
2136 : : return false;
2137 : : }
2138 : 21907179 : else if (a2 == NULL_TREE)
2139 : : {
2140 : 0 : if (c_type_promotes_to (a1) != a1)
2141 : : return false;
2142 : : }
2143 : : /* If one of the lists has an error marker, ignore this arg. */
2144 : 21907179 : else if (TREE_CODE (a1) == ERROR_MARK
2145 : 21907175 : || TREE_CODE (a2) == ERROR_MARK)
2146 : : ;
2147 : 21907159 : else if (!comptypes_internal (mv1, mv2, data))
2148 : : {
2149 : 142844 : data->different_types_p = true;
2150 : : /* Allow wait (union {union wait *u; int *i} *)
2151 : : and wait (union wait *) to be compatible. */
2152 : 142844 : if (TREE_CODE (a1) == UNION_TYPE
2153 : 122 : && (TYPE_NAME (a1) == NULL_TREE
2154 : 94 : || TYPE_TRANSPARENT_AGGR (a1))
2155 : 122 : && TREE_CODE (TYPE_SIZE (a1)) == INTEGER_CST
2156 : 142966 : && tree_int_cst_equal (TYPE_SIZE (a1),
2157 : 122 : TYPE_SIZE (a2)))
2158 : : {
2159 : 122 : tree memb;
2160 : 122 : for (memb = TYPE_FIELDS (a1);
2161 : 158 : memb; memb = DECL_CHAIN (memb))
2162 : : {
2163 : 156 : tree mv3 = remove_qualifiers (TREE_TYPE (memb));
2164 : 156 : if (comptypes_internal (mv3, mv2, data))
2165 : : break;
2166 : : }
2167 : : if (memb == NULL_TREE)
2168 : : return false;
2169 : : }
2170 : 142722 : else if (TREE_CODE (a2) == UNION_TYPE
2171 : 99 : && (TYPE_NAME (a2) == NULL_TREE
2172 : 71 : || TYPE_TRANSPARENT_AGGR (a2))
2173 : 99 : && TREE_CODE (TYPE_SIZE (a2)) == INTEGER_CST
2174 : 142821 : && tree_int_cst_equal (TYPE_SIZE (a2),
2175 : 99 : TYPE_SIZE (a1)))
2176 : : {
2177 : 99 : tree memb;
2178 : 99 : for (memb = TYPE_FIELDS (a2);
2179 : 127 : memb; memb = DECL_CHAIN (memb))
2180 : : {
2181 : 125 : tree mv3 = remove_qualifiers (TREE_TYPE (memb));
2182 : 125 : if (comptypes_internal (mv3, mv1, data))
2183 : : break;
2184 : : }
2185 : : if (memb == NULL_TREE)
2186 : : return false;
2187 : : }
2188 : : else
2189 : 142623 : return false;
2190 : : }
2191 : :
2192 : 21764552 : args1 = TREE_CHAIN (args1);
2193 : 21764552 : args2 = TREE_CHAIN (args2);
2194 : 21764552 : }
2195 : : }
2196 : :
2197 : : /* Compute the size to increment a pointer by. When a function type or void
2198 : : type or incomplete type is passed, size_one_node is returned.
2199 : : This function does not emit any diagnostics; the caller is responsible
2200 : : for that. */
2201 : :
2202 : : static tree
2203 : 232530 : c_size_in_bytes (const_tree type)
2204 : : {
2205 : 232530 : enum tree_code code = TREE_CODE (type);
2206 : :
2207 : 232530 : if (code == FUNCTION_TYPE || code == VOID_TYPE || code == ERROR_MARK
2208 : 232530 : || !COMPLETE_TYPE_P (type))
2209 : 180 : return size_one_node;
2210 : :
2211 : : /* Convert in case a char is more than one unit. */
2212 : 232350 : return size_binop_loc (input_location, CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
2213 : 232350 : size_int (TYPE_PRECISION (char_type_node)
2214 : : / BITS_PER_UNIT));
2215 : : }
2216 : :
2217 : : /* Return either DECL or its known constant value (if it has one). */
2218 : :
2219 : : tree
2220 : 13970312 : decl_constant_value_1 (tree decl, bool in_init)
2221 : : {
2222 : 13970312 : if (/* Note that DECL_INITIAL isn't valid for a PARM_DECL. */
2223 : 13970312 : TREE_CODE (decl) != PARM_DECL
2224 : 13970312 : && !TREE_THIS_VOLATILE (decl)
2225 : 13626914 : && TREE_READONLY (decl)
2226 : 35695 : && DECL_INITIAL (decl) != NULL_TREE
2227 : 34684 : && !error_operand_p (DECL_INITIAL (decl))
2228 : : /* This is invalid if initial value is not constant.
2229 : : If it has either a function call, a memory reference,
2230 : : or a variable, then re-evaluating it could give different results. */
2231 : 34675 : && TREE_CONSTANT (DECL_INITIAL (decl))
2232 : : /* Check for cases where this is sub-optimal, even though valid. */
2233 : 13992149 : && (in_init || TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR))
2234 : 16638 : return DECL_INITIAL (decl);
2235 : : return decl;
2236 : : }
2237 : :
2238 : : /* Return either DECL or its known constant value (if it has one).
2239 : : Like the above, but always return decl outside of functions. */
2240 : :
2241 : : tree
2242 : 13970127 : decl_constant_value (tree decl)
2243 : : {
2244 : : /* Don't change a variable array bound or initial value to a constant
2245 : : in a place where a variable is invalid. */
2246 : 13970127 : return current_function_decl ? decl_constant_value_1 (decl, false) : decl;
2247 : : }
2248 : :
2249 : : /* Convert the array expression EXP to a pointer. */
2250 : : static tree
2251 : 809726 : array_to_pointer_conversion (location_t loc, tree exp)
2252 : : {
2253 : 809726 : tree orig_exp = exp;
2254 : 809726 : tree type = TREE_TYPE (exp);
2255 : 809726 : tree adr;
2256 : 809726 : tree restype = TREE_TYPE (type);
2257 : 809726 : tree ptrtype;
2258 : :
2259 : 809726 : gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
2260 : :
2261 : 809726 : STRIP_TYPE_NOPS (exp);
2262 : :
2263 : 809726 : copy_warning (exp, orig_exp);
2264 : :
2265 : 809726 : ptrtype = c_build_pointer_type (restype);
2266 : :
2267 : 809726 : if (INDIRECT_REF_P (exp))
2268 : 2883 : return convert (ptrtype, TREE_OPERAND (exp, 0));
2269 : :
2270 : : /* In C++ array compound literals are temporary objects unless they are
2271 : : const or appear in namespace scope, so they are destroyed too soon
2272 : : to use them for much of anything (c++/53220). */
2273 : 806843 : if (warn_cxx_compat && TREE_CODE (exp) == COMPOUND_LITERAL_EXPR)
2274 : : {
2275 : 48 : tree decl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
2276 : 48 : if (!TREE_READONLY (decl) && !TREE_STATIC (decl))
2277 : 46 : warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat,
2278 : : "converting an array compound literal to a pointer "
2279 : : "leads to a dangling pointer in C++");
2280 : : }
2281 : :
2282 : 806843 : adr = build_unary_op (loc, ADDR_EXPR, exp, true);
2283 : 806843 : return convert (ptrtype, adr);
2284 : : }
2285 : :
2286 : : /* Convert the function expression EXP to a pointer. */
2287 : : static tree
2288 : 49302706 : function_to_pointer_conversion (location_t loc, tree exp)
2289 : : {
2290 : 49302706 : tree orig_exp = exp;
2291 : :
2292 : 49302706 : gcc_assert (TREE_CODE (TREE_TYPE (exp)) == FUNCTION_TYPE);
2293 : :
2294 : 49302706 : STRIP_TYPE_NOPS (exp);
2295 : :
2296 : 49302706 : copy_warning (exp, orig_exp);
2297 : :
2298 : 49302706 : return build_unary_op (loc, ADDR_EXPR, exp, false);
2299 : : }
2300 : :
2301 : : /* Mark EXP as read, not just set, for set but not used -Wunused
2302 : : warning purposes. */
2303 : :
2304 : : void
2305 : 478380418 : mark_exp_read (tree exp)
2306 : : {
2307 : 600750332 : switch (TREE_CODE (exp))
2308 : : {
2309 : 197795686 : case VAR_DECL:
2310 : 197795686 : case PARM_DECL:
2311 : 197795686 : DECL_READ_P (exp) = 1;
2312 : 197795686 : break;
2313 : 119691540 : case ARRAY_REF:
2314 : 119691540 : case COMPONENT_REF:
2315 : 119691540 : case MODIFY_EXPR:
2316 : 119691540 : case REALPART_EXPR:
2317 : 119691540 : case IMAGPART_EXPR:
2318 : 119691540 : CASE_CONVERT:
2319 : 119691540 : case ADDR_EXPR:
2320 : 119691540 : case VIEW_CONVERT_EXPR:
2321 : 119691540 : mark_exp_read (TREE_OPERAND (exp, 0));
2322 : 119691540 : break;
2323 : 230222 : case COMPOUND_EXPR:
2324 : : /* Pattern match what build_atomic_assign produces with modifycode
2325 : : NOP_EXPR. */
2326 : 230222 : if (VAR_P (TREE_OPERAND (exp, 1))
2327 : 27101 : && DECL_ARTIFICIAL (TREE_OPERAND (exp, 1))
2328 : 257239 : && TREE_CODE (TREE_OPERAND (exp, 0)) == COMPOUND_EXPR)
2329 : : {
2330 : 2112 : tree t1 = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
2331 : 2112 : tree t2 = TREE_OPERAND (TREE_OPERAND (exp, 0), 1);
2332 : 2112 : if (TREE_CODE (t1) == TARGET_EXPR
2333 : 2104 : && TARGET_EXPR_SLOT (t1) == TREE_OPERAND (exp, 1)
2334 : 4214 : && TREE_CODE (t2) == CALL_EXPR)
2335 : : {
2336 : 2102 : tree fndecl = get_callee_fndecl (t2);
2337 : 2102 : tree arg = NULL_TREE;
2338 : 2102 : if (fndecl
2339 : 2102 : && TREE_CODE (fndecl) == FUNCTION_DECL
2340 : 2102 : && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL)
2341 : 4204 : && call_expr_nargs (t2) >= 2)
2342 : 2102 : switch (DECL_FUNCTION_CODE (fndecl))
2343 : : {
2344 : 130 : case BUILT_IN_ATOMIC_STORE:
2345 : 130 : arg = CALL_EXPR_ARG (t2, 1);
2346 : 130 : break;
2347 : 1972 : case BUILT_IN_ATOMIC_STORE_1:
2348 : 1972 : case BUILT_IN_ATOMIC_STORE_2:
2349 : 1972 : case BUILT_IN_ATOMIC_STORE_4:
2350 : 1972 : case BUILT_IN_ATOMIC_STORE_8:
2351 : 1972 : case BUILT_IN_ATOMIC_STORE_16:
2352 : 1972 : arg = CALL_EXPR_ARG (t2, 0);
2353 : 1972 : break;
2354 : : default:
2355 : : break;
2356 : : }
2357 : 2102 : if (arg)
2358 : : {
2359 : 2102 : STRIP_NOPS (arg);
2360 : 2102 : if (TREE_CODE (arg) == ADDR_EXPR
2361 : 2102 : && DECL_P (TREE_OPERAND (arg, 0))
2362 : 4204 : && TYPE_ATOMIC (TREE_TYPE (TREE_OPERAND (arg, 0))))
2363 : 2102 : mark_exp_read (TREE_OPERAND (arg, 0));
2364 : : }
2365 : : }
2366 : : }
2367 : : /* FALLTHRU */
2368 : 2677849 : case C_MAYBE_CONST_EXPR:
2369 : 2677849 : mark_exp_read (TREE_OPERAND (exp, 1));
2370 : 2677849 : break;
2371 : 560 : case OMP_ARRAY_SECTION:
2372 : 560 : mark_exp_read (TREE_OPERAND (exp, 0));
2373 : 560 : if (TREE_OPERAND (exp, 1))
2374 : 377 : mark_exp_read (TREE_OPERAND (exp, 1));
2375 : 560 : if (TREE_OPERAND (exp, 2))
2376 : 525 : mark_exp_read (TREE_OPERAND (exp, 2));
2377 : : break;
2378 : : default:
2379 : : break;
2380 : : }
2381 : 478380418 : }
2382 : :
2383 : : /* Perform the default conversion of arrays and functions to pointers.
2384 : : Return the result of converting EXP. For any other expression, just
2385 : : return EXP.
2386 : :
2387 : : LOC is the location of the expression. */
2388 : :
2389 : : struct c_expr
2390 : 352760844 : default_function_array_conversion (location_t loc, struct c_expr exp)
2391 : : {
2392 : 352760844 : tree orig_exp = exp.value;
2393 : 352760844 : tree type = TREE_TYPE (exp.value);
2394 : 352760844 : enum tree_code code = TREE_CODE (type);
2395 : :
2396 : 352760844 : switch (code)
2397 : : {
2398 : : case ARRAY_TYPE:
2399 : : {
2400 : : bool not_lvalue = false;
2401 : : bool lvalue_array_p;
2402 : :
2403 : 762918 : while ((TREE_CODE (exp.value) == NON_LVALUE_EXPR
2404 : 762918 : || CONVERT_EXPR_P (exp.value))
2405 : 762918 : && TREE_TYPE (TREE_OPERAND (exp.value, 0)) == type)
2406 : : {
2407 : 0 : if (TREE_CODE (exp.value) == NON_LVALUE_EXPR)
2408 : 0 : not_lvalue = true;
2409 : 0 : exp.value = TREE_OPERAND (exp.value, 0);
2410 : : }
2411 : :
2412 : 762918 : copy_warning (exp.value, orig_exp);
2413 : :
2414 : 762918 : lvalue_array_p = !not_lvalue && lvalue_p (exp.value);
2415 : 762918 : if (!flag_isoc99 && !lvalue_array_p)
2416 : : {
2417 : : /* Before C99, non-lvalue arrays do not decay to pointers.
2418 : : Normally, using such an array would be invalid; but it can
2419 : : be used correctly inside sizeof or as a statement expression.
2420 : : Thus, do not give an error here; an error will result later. */
2421 : 108 : return exp;
2422 : : }
2423 : :
2424 : 762810 : exp.value = array_to_pointer_conversion (loc, exp.value);
2425 : : }
2426 : 762810 : break;
2427 : 761652 : case FUNCTION_TYPE:
2428 : 761652 : exp.value = function_to_pointer_conversion (loc, exp.value);
2429 : 761652 : break;
2430 : : default:
2431 : : break;
2432 : : }
2433 : :
2434 : 352760736 : return exp;
2435 : : }
2436 : :
2437 : : struct c_expr
2438 : 925401 : default_function_array_read_conversion (location_t loc, struct c_expr exp)
2439 : : {
2440 : 925401 : mark_exp_read (exp.value);
2441 : 925401 : return default_function_array_conversion (loc, exp);
2442 : : }
2443 : :
2444 : : /* Return whether EXPR should be treated as an atomic lvalue for the
2445 : : purposes of load and store handling. */
2446 : :
2447 : : static bool
2448 : 353828942 : really_atomic_lvalue (tree expr)
2449 : : {
2450 : 353828942 : if (error_operand_p (expr))
2451 : : return false;
2452 : 353821339 : if (!TYPE_ATOMIC (TREE_TYPE (expr)))
2453 : : return false;
2454 : 56796 : if (!lvalue_p (expr))
2455 : : return false;
2456 : :
2457 : : /* Ignore _Atomic on register variables, since their addresses can't
2458 : : be taken so (a) atomicity is irrelevant and (b) the normal atomic
2459 : : sequences wouldn't work. Ignore _Atomic on structures containing
2460 : : bit-fields, since accessing elements of atomic structures or
2461 : : unions is undefined behavior (C11 6.5.2.3#5), but it's unclear if
2462 : : it's undefined at translation time or execution time, and the
2463 : : normal atomic sequences again wouldn't work. */
2464 : 56830 : while (handled_component_p (expr))
2465 : : {
2466 : 36 : if (TREE_CODE (expr) == COMPONENT_REF
2467 : 36 : && DECL_C_BIT_FIELD (TREE_OPERAND (expr, 1)))
2468 : : return false;
2469 : 36 : expr = TREE_OPERAND (expr, 0);
2470 : : }
2471 : 56794 : if (DECL_P (expr) && C_DECL_REGISTER (expr))
2472 : : return false;
2473 : : return true;
2474 : : }
2475 : :
2476 : : /* If EXPR is a named constant (C23) derived from a constexpr variable
2477 : : - that is, a reference to such a variable, or a member extracted by
2478 : : a sequence of structure and union (but not array) member accesses
2479 : : (where union member accesses must access the same member as
2480 : : initialized) - then return the corresponding initializer;
2481 : : otherwise, return NULL_TREE. */
2482 : :
2483 : : static tree
2484 : 350700524 : maybe_get_constexpr_init (tree expr)
2485 : : {
2486 : 350700524 : tree decl = NULL_TREE;
2487 : 350700524 : if (TREE_CODE (expr) == VAR_DECL)
2488 : : decl = expr;
2489 : 339374123 : else if (TREE_CODE (expr) == COMPOUND_LITERAL_EXPR)
2490 : 802842 : decl = COMPOUND_LITERAL_EXPR_DECL (expr);
2491 : 802842 : if (decl
2492 : 12129243 : && C_DECL_DECLARED_CONSTEXPR (decl)
2493 : 350 : && DECL_INITIAL (decl) != NULL_TREE
2494 : 803192 : && !error_operand_p (DECL_INITIAL (decl)))
2495 : 350 : return DECL_INITIAL (decl);
2496 : 350700174 : if (TREE_CODE (expr) != COMPONENT_REF)
2497 : : return NULL_TREE;
2498 : 846471 : tree inner = maybe_get_constexpr_init (TREE_OPERAND (expr, 0));
2499 : 846471 : if (inner == NULL_TREE)
2500 : : return NULL_TREE;
2501 : 126 : while ((CONVERT_EXPR_P (inner) || TREE_CODE (inner) == NON_LVALUE_EXPR)
2502 : 47 : && !error_operand_p (inner)
2503 : 220 : && (TYPE_MAIN_VARIANT (TREE_TYPE (inner))
2504 : 47 : == TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (inner, 0)))))
2505 : 47 : inner = TREE_OPERAND (inner, 0);
2506 : 126 : if (TREE_CODE (inner) != CONSTRUCTOR)
2507 : : return NULL_TREE;
2508 : 126 : tree field = TREE_OPERAND (expr, 1);
2509 : 126 : unsigned HOST_WIDE_INT cidx;
2510 : 126 : tree cfield, cvalue;
2511 : 126 : bool have_other_init = false;
2512 : 266 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (inner), cidx, cfield, cvalue)
2513 : : {
2514 : 250 : if (cfield == field)
2515 : : return cvalue;
2516 : 140 : have_other_init = true;
2517 : : }
2518 : 16 : if (TREE_CODE (TREE_TYPE (inner)) == UNION_TYPE
2519 : 16 : && (have_other_init || field != TYPE_FIELDS (TREE_TYPE (inner))))
2520 : : return NULL_TREE;
2521 : : /* Return a default initializer. */
2522 : 13 : if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (expr)))
2523 : 5 : return build_constructor (TREE_TYPE (expr), NULL);
2524 : 8 : return build_zero_cst (TREE_TYPE (expr));
2525 : : }
2526 : :
2527 : : /* Convert expression EXP (location LOC) from lvalue to rvalue,
2528 : : including converting functions and arrays to pointers if CONVERT_P.
2529 : : If READ_P, also mark the expression as having been read. If
2530 : : FOR_INIT, constexpr expressions of structure and union type should
2531 : : be replaced by the corresponding CONSTRUCTOR; otherwise, only
2532 : : constexpr scalars (including elements of structures and unions) are
2533 : : replaced by their initializers. */
2534 : :
2535 : : struct c_expr
2536 : 350040068 : convert_lvalue_to_rvalue (location_t loc, struct c_expr exp,
2537 : : bool convert_p, bool read_p, bool for_init)
2538 : : {
2539 : 350040068 : bool force_non_npc = false;
2540 : 350040068 : if (read_p)
2541 : 307116771 : mark_exp_read (exp.value);
2542 : 350040068 : if (convert_p)
2543 : 350026944 : exp = default_function_array_conversion (loc, exp);
2544 : 350040068 : if (!VOID_TYPE_P (TREE_TYPE (exp.value)))
2545 : 347610293 : exp.value = require_complete_type (loc, exp.value);
2546 : 350040068 : if (for_init || !RECORD_OR_UNION_TYPE_P (TREE_TYPE (exp.value)))
2547 : : {
2548 : 349854053 : tree init = maybe_get_constexpr_init (exp.value);
2549 : 349854053 : if (init != NULL_TREE)
2550 : : {
2551 : : /* A named constant of pointer type or type nullptr_t is not
2552 : : a null pointer constant even if the initializer is
2553 : : one. */
2554 : 347 : if (TREE_CODE (init) == INTEGER_CST
2555 : 212 : && !INTEGRAL_TYPE_P (TREE_TYPE (init))
2556 : 373 : && integer_zerop (init))
2557 : : force_non_npc = true;
2558 : : exp.value = init;
2559 : : }
2560 : : }
2561 : 350040068 : if (really_atomic_lvalue (exp.value))
2562 : : {
2563 : 26495 : vec<tree, va_gc> *params;
2564 : 26495 : tree nonatomic_type, tmp, tmp_addr, fndecl, func_call;
2565 : 26495 : tree expr_type = TREE_TYPE (exp.value);
2566 : 26495 : tree expr_addr = build_unary_op (loc, ADDR_EXPR, exp.value, false);
2567 : 26495 : tree seq_cst = build_int_cst (integer_type_node, MEMMODEL_SEQ_CST);
2568 : :
2569 : 26495 : gcc_assert (TYPE_ATOMIC (expr_type));
2570 : :
2571 : : /* Expansion of a generic atomic load may require an addition
2572 : : element, so allocate enough to prevent a resize. */
2573 : 26495 : vec_alloc (params, 4);
2574 : :
2575 : : /* Remove the qualifiers for the rest of the expressions and
2576 : : create the VAL temp variable to hold the RHS. */
2577 : 26495 : nonatomic_type = build_qualified_type (expr_type, TYPE_UNQUALIFIED);
2578 : 26495 : tmp = create_tmp_var_raw (nonatomic_type);
2579 : 26495 : tmp_addr = build_unary_op (loc, ADDR_EXPR, tmp, false);
2580 : 26495 : TREE_ADDRESSABLE (tmp) = 1;
2581 : : /* Do not disable warnings for TMP even though it's artificial.
2582 : : -Winvalid-memory-model depends on it. */
2583 : :
2584 : : /* Issue __atomic_load (&expr, &tmp, SEQ_CST); */
2585 : 26495 : fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_LOAD);
2586 : 26495 : params->quick_push (expr_addr);
2587 : 26495 : params->quick_push (tmp_addr);
2588 : 26495 : params->quick_push (seq_cst);
2589 : 26495 : func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
2590 : :
2591 : : /* EXPR is always read. */
2592 : 26495 : mark_exp_read (exp.value);
2593 : :
2594 : : /* Return tmp which contains the value loaded. */
2595 : 26495 : exp.value = build4 (TARGET_EXPR, nonatomic_type, tmp, func_call,
2596 : : NULL_TREE, NULL_TREE);
2597 : : }
2598 : 350026944 : if (convert_p && !error_operand_p (exp.value)
2599 : 700059453 : && (TREE_CODE (TREE_TYPE (exp.value)) != ARRAY_TYPE))
2600 : 350019277 : exp.value = convert (build_qualified_type (TREE_TYPE (exp.value), TYPE_UNQUALIFIED), exp.value);
2601 : 350040068 : if (force_non_npc)
2602 : 24 : exp.value = build1 (NOP_EXPR, TREE_TYPE (exp.value), exp.value);
2603 : :
2604 : 350040068 : {
2605 : 350040068 : tree false_value, true_value;
2606 : 350026944 : if (convert_p && !error_operand_p (exp.value)
2607 : 700059453 : && c_hardbool_type_attr (TREE_TYPE (exp.value),
2608 : : &false_value, &true_value))
2609 : : {
2610 : 3445 : tree t = save_expr (exp.value);
2611 : :
2612 : 3445 : mark_exp_read (exp.value);
2613 : :
2614 : 3445 : tree trapfn = builtin_decl_explicit (BUILT_IN_TRAP);
2615 : 3445 : tree expr = build_call_expr_loc (loc, trapfn, 0);
2616 : 3445 : expr = build_compound_expr (loc, expr, boolean_true_node);
2617 : 3445 : expr = fold_build3_loc (loc, COND_EXPR, boolean_type_node,
2618 : : fold_build2_loc (loc, NE_EXPR,
2619 : : boolean_type_node,
2620 : : t, true_value),
2621 : : expr, boolean_true_node);
2622 : 3445 : expr = fold_build3_loc (loc, COND_EXPR, boolean_type_node,
2623 : : fold_build2_loc (loc, NE_EXPR,
2624 : : boolean_type_node,
2625 : : t, false_value),
2626 : : expr, boolean_false_node);
2627 : :
2628 : 3445 : exp.value = expr;
2629 : : }
2630 : : }
2631 : :
2632 : 350040068 : return exp;
2633 : : }
2634 : :
2635 : : /* EXP is an expression of integer type. Apply the integer promotions
2636 : : to it and return the promoted value. */
2637 : :
2638 : : tree
2639 : 76032840 : perform_integral_promotions (tree exp)
2640 : : {
2641 : 76032840 : tree type = TREE_TYPE (exp);
2642 : 76032840 : enum tree_code code = TREE_CODE (type);
2643 : :
2644 : 76032840 : gcc_assert (INTEGRAL_TYPE_P (type));
2645 : :
2646 : : /* Convert enums to the result of applying the integer promotions to
2647 : : their underlying type. */
2648 : 76032840 : if (code == ENUMERAL_TYPE)
2649 : : {
2650 : 634595 : type = ENUM_UNDERLYING_TYPE (type);
2651 : 634595 : if (c_promoting_integer_type_p (type))
2652 : : {
2653 : 92 : if (TYPE_UNSIGNED (type)
2654 : 92 : && TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
2655 : 0 : type = unsigned_type_node;
2656 : : else
2657 : 92 : type = integer_type_node;
2658 : : }
2659 : :
2660 : 634595 : return convert (type, exp);
2661 : : }
2662 : :
2663 : : /* ??? This should no longer be needed now bit-fields have their
2664 : : proper types. */
2665 : 75398245 : if (TREE_CODE (exp) == COMPONENT_REF
2666 : 75398245 : && DECL_C_BIT_FIELD (TREE_OPERAND (exp, 1)))
2667 : : {
2668 : 62144 : if (TREE_CODE (DECL_BIT_FIELD_TYPE (TREE_OPERAND (exp, 1)))
2669 : : == BITINT_TYPE)
2670 : 454 : return convert (DECL_BIT_FIELD_TYPE (TREE_OPERAND (exp, 1)), exp);
2671 : : /* If it's thinner than an int, promote it like a
2672 : : c_promoting_integer_type_p, otherwise leave it alone. */
2673 : 61690 : if (compare_tree_int (DECL_SIZE (TREE_OPERAND (exp, 1)),
2674 : 61690 : TYPE_PRECISION (integer_type_node)) < 0)
2675 : 53428 : return convert (integer_type_node, exp);
2676 : : }
2677 : :
2678 : 75344363 : if (c_promoting_integer_type_p (type))
2679 : : {
2680 : : /* Preserve unsignedness if not really getting any wider. */
2681 : 622836 : if (TYPE_UNSIGNED (type)
2682 : 622836 : && TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
2683 : 0 : return convert (unsigned_type_node, exp);
2684 : :
2685 : 622836 : return convert (integer_type_node, exp);
2686 : : }
2687 : :
2688 : : return exp;
2689 : : }
2690 : :
2691 : :
2692 : : /* Perform default promotions for C data used in expressions.
2693 : : Enumeral types or short or char are converted to int.
2694 : : In addition, manifest constants symbols are replaced by their values. */
2695 : :
2696 : : tree
2697 : 85322062 : default_conversion (tree exp)
2698 : : {
2699 : 85322062 : tree orig_exp;
2700 : 85322062 : tree type = TREE_TYPE (exp);
2701 : 85322062 : enum tree_code code = TREE_CODE (type);
2702 : 85322062 : tree promoted_type;
2703 : :
2704 : 85322062 : mark_exp_read (exp);
2705 : :
2706 : : /* Functions and arrays have been converted during parsing. */
2707 : 85322062 : gcc_assert (code != FUNCTION_TYPE);
2708 : 85322062 : if (code == ARRAY_TYPE)
2709 : : return exp;
2710 : :
2711 : : /* Constants can be used directly unless they're not loadable. */
2712 : 85321903 : if (TREE_CODE (exp) == CONST_DECL)
2713 : 0 : exp = DECL_INITIAL (exp);
2714 : :
2715 : : /* Strip no-op conversions. */
2716 : 85321903 : orig_exp = exp;
2717 : 85688044 : STRIP_TYPE_NOPS (exp);
2718 : :
2719 : 85321903 : copy_warning (exp, orig_exp);
2720 : :
2721 : 85321903 : if (code == VOID_TYPE)
2722 : : {
2723 : 2 : error_at (EXPR_LOC_OR_LOC (exp, input_location),
2724 : : "void value not ignored as it ought to be");
2725 : 2 : return error_mark_node;
2726 : : }
2727 : :
2728 : 85321901 : exp = require_complete_type (EXPR_LOC_OR_LOC (exp, input_location), exp);
2729 : 85321901 : if (exp == error_mark_node)
2730 : : return error_mark_node;
2731 : :
2732 : 85321002 : promoted_type = targetm.promoted_type (type);
2733 : 85321002 : if (promoted_type)
2734 : 0 : return convert (promoted_type, exp);
2735 : :
2736 : 85321002 : if (INTEGRAL_TYPE_P (type))
2737 : 75041354 : return perform_integral_promotions (exp);
2738 : :
2739 : : return exp;
2740 : : }
2741 : :
2742 : : /* Look up COMPONENT in a structure or union TYPE.
2743 : :
2744 : : If the component name is not found, returns NULL_TREE. Otherwise,
2745 : : the return value is a TREE_LIST, with each TREE_VALUE a FIELD_DECL
2746 : : stepping down the chain to the component, which is in the last
2747 : : TREE_VALUE of the list. Normally the list is of length one, but if
2748 : : the component is embedded within (nested) anonymous structures or
2749 : : unions, the list steps down the chain to the component. */
2750 : :
2751 : : tree
2752 : 2267626 : lookup_field (const_tree type, tree component)
2753 : : {
2754 : 2267626 : tree field;
2755 : :
2756 : : /* If TYPE_LANG_SPECIFIC is set, then it is a sorted array of pointers
2757 : : to the field elements. Use a binary search on this array to quickly
2758 : : find the element. Otherwise, do a linear search. TYPE_LANG_SPECIFIC
2759 : : will always be set for structures which have many elements.
2760 : :
2761 : : Duplicate field checking replaces duplicates with NULL_TREE so
2762 : : TYPE_LANG_SPECIFIC arrays are potentially no longer sorted. In that
2763 : : case just iterate using DECL_CHAIN. */
2764 : :
2765 : 2563852 : if (TYPE_LANG_SPECIFIC (type) && TYPE_LANG_SPECIFIC (type)->s
2766 : 2563852 : && !seen_error ())
2767 : : {
2768 : 296205 : int bot, top, half;
2769 : 296205 : tree *field_array = &TYPE_LANG_SPECIFIC (type)->s->elts[0];
2770 : :
2771 : 296205 : field = TYPE_FIELDS (type);
2772 : 296205 : bot = 0;
2773 : 296205 : top = TYPE_LANG_SPECIFIC (type)->s->len;
2774 : 1349022 : while (top - bot > 1)
2775 : : {
2776 : 1319992 : half = (top - bot + 1) >> 1;
2777 : 1319992 : field = field_array[bot+half];
2778 : :
2779 : 1319992 : if (DECL_NAME (field) == NULL_TREE)
2780 : : {
2781 : : /* Step through all anon unions in linear fashion. */
2782 : 0 : while (DECL_NAME (field_array[bot]) == NULL_TREE)
2783 : : {
2784 : 0 : field = field_array[bot++];
2785 : 0 : if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (field)))
2786 : : {
2787 : 0 : tree anon = lookup_field (TREE_TYPE (field), component);
2788 : :
2789 : 0 : if (anon)
2790 : 0 : return tree_cons (NULL_TREE, field, anon);
2791 : :
2792 : : /* The Plan 9 compiler permits referring
2793 : : directly to an anonymous struct/union field
2794 : : using a typedef name. */
2795 : 0 : if (flag_plan9_extensions
2796 : 0 : && TYPE_NAME (TREE_TYPE (field)) != NULL_TREE
2797 : 0 : && (TREE_CODE (TYPE_NAME (TREE_TYPE (field)))
2798 : : == TYPE_DECL)
2799 : 0 : && (DECL_NAME (TYPE_NAME (TREE_TYPE (field)))
2800 : : == component))
2801 : : break;
2802 : : }
2803 : : }
2804 : :
2805 : : /* Entire record is only anon unions. */
2806 : 0 : if (bot > top)
2807 : : return NULL_TREE;
2808 : :
2809 : : /* Restart the binary search, with new lower bound. */
2810 : 0 : continue;
2811 : 0 : }
2812 : :
2813 : 1319992 : if (DECL_NAME (field) == component)
2814 : : break;
2815 : 1052817 : if (DECL_NAME (field) < component)
2816 : : bot += half;
2817 : : else
2818 : 851940 : top = bot + half;
2819 : : }
2820 : :
2821 : 296205 : if (DECL_NAME (field_array[bot]) == component)
2822 : : field = field_array[bot];
2823 : 267175 : else if (DECL_NAME (field) != component)
2824 : : return NULL_TREE;
2825 : : }
2826 : : else
2827 : : {
2828 : 5162502 : for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
2829 : : {
2830 : 5153767 : if (DECL_NAME (field) == NULL_TREE
2831 : 5153767 : && RECORD_OR_UNION_TYPE_P (TREE_TYPE (field)))
2832 : : {
2833 : 10866 : tree anon = lookup_field (TREE_TYPE (field), component);
2834 : :
2835 : 10866 : if (anon)
2836 : 2204 : return tree_cons (NULL_TREE, field, anon);
2837 : :
2838 : : /* The Plan 9 compiler permits referring directly to an
2839 : : anonymous struct/union field using a typedef
2840 : : name. */
2841 : 8662 : if (flag_plan9_extensions
2842 : 38 : && TYPE_NAME (TREE_TYPE (field)) != NULL_TREE
2843 : 36 : && TREE_CODE (TYPE_NAME (TREE_TYPE (field))) == TYPE_DECL
2844 : 8668 : && (DECL_NAME (TYPE_NAME (TREE_TYPE (field)))
2845 : : == component))
2846 : : break;
2847 : : }
2848 : :
2849 : 5151559 : if (DECL_NAME (field) == component)
2850 : : break;
2851 : : }
2852 : :
2853 : 1969217 : if (field == NULL_TREE)
2854 : : return NULL_TREE;
2855 : : }
2856 : :
2857 : 2256687 : return tree_cons (NULL_TREE, field, NULL_TREE);
2858 : : }
2859 : :
2860 : : /* Recursively append candidate IDENTIFIER_NODEs to CANDIDATES. */
2861 : :
2862 : : static void
2863 : 101 : lookup_field_fuzzy_find_candidates (tree type, tree component,
2864 : : vec<tree> *candidates)
2865 : : {
2866 : 101 : tree field;
2867 : 258 : for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
2868 : : {
2869 : 157 : if (DECL_NAME (field) == NULL_TREE
2870 : 157 : && RECORD_OR_UNION_TYPE_P (TREE_TYPE (field)))
2871 : 30 : lookup_field_fuzzy_find_candidates (TREE_TYPE (field), component,
2872 : : candidates);
2873 : :
2874 : 157 : if (DECL_NAME (field))
2875 : 111 : candidates->safe_push (DECL_NAME (field));
2876 : : }
2877 : 101 : }
2878 : :
2879 : : /* Like "lookup_field", but find the closest matching IDENTIFIER_NODE,
2880 : : rather than returning a TREE_LIST for an exact match. */
2881 : :
2882 : : static tree
2883 : 71 : lookup_field_fuzzy (tree type, tree component)
2884 : : {
2885 : 71 : gcc_assert (TREE_CODE (component) == IDENTIFIER_NODE);
2886 : :
2887 : : /* First, gather a list of candidates. */
2888 : 71 : auto_vec <tree> candidates;
2889 : :
2890 : 71 : lookup_field_fuzzy_find_candidates (type, component,
2891 : : &candidates);
2892 : :
2893 : 71 : return find_closest_identifier (component, &candidates);
2894 : 71 : }
2895 : :
2896 : : /* Support function for build_component_ref's error-handling.
2897 : :
2898 : : Given DATUM_TYPE, and "DATUM.COMPONENT", where DATUM is *not* a
2899 : : struct or union, should we suggest "DATUM->COMPONENT" as a hint? */
2900 : :
2901 : : static bool
2902 : 72 : should_suggest_deref_p (tree datum_type)
2903 : : {
2904 : : /* We don't do it for Objective-C, since Objective-C 2.0 dot-syntax
2905 : : allows "." for ptrs; we could be handling a failed attempt
2906 : : to access a property. */
2907 : 72 : if (c_dialect_objc ())
2908 : : return false;
2909 : :
2910 : : /* Only suggest it for pointers... */
2911 : 72 : if (TREE_CODE (datum_type) != POINTER_TYPE)
2912 : : return false;
2913 : :
2914 : : /* ...to structs/unions. */
2915 : 8 : tree underlying_type = TREE_TYPE (datum_type);
2916 : 8 : enum tree_code code = TREE_CODE (underlying_type);
2917 : 8 : if (code == RECORD_TYPE || code == UNION_TYPE)
2918 : : return true;
2919 : : else
2920 : 1 : return false;
2921 : : }
2922 : :
2923 : : /* For a SUBDATUM field of a structure or union DATUM, generate a REF to
2924 : : the object that represents its counted_by per the attribute counted_by
2925 : : attached to this field if it's a flexible array member field, otherwise
2926 : : return NULL_TREE.
2927 : : Set COUNTED_BY_TYPE to the TYPE of the counted_by field.
2928 : : For example, if:
2929 : :
2930 : : struct P {
2931 : : int k;
2932 : : int x[] __attribute__ ((counted_by (k)));
2933 : : } *p;
2934 : :
2935 : : for:
2936 : : p->x
2937 : :
2938 : : the ref to the object that represents its element count will be:
2939 : :
2940 : : &(p->k)
2941 : :
2942 : : */
2943 : : static tree
2944 : 2175114 : build_counted_by_ref (tree datum, tree subdatum, tree *counted_by_type)
2945 : : {
2946 : 2175114 : tree type = TREE_TYPE (datum);
2947 : 2175114 : if (!c_flexible_array_member_type_p (TREE_TYPE (subdatum)))
2948 : : return NULL_TREE;
2949 : :
2950 : 70303 : tree attr_counted_by = lookup_attribute ("counted_by",
2951 : 70303 : DECL_ATTRIBUTES (subdatum));
2952 : 70303 : tree counted_by_ref = NULL_TREE;
2953 : 70303 : *counted_by_type = NULL_TREE;
2954 : 70303 : if (attr_counted_by)
2955 : : {
2956 : 157 : tree field_id = TREE_VALUE (TREE_VALUE (attr_counted_by));
2957 : 157 : counted_by_ref
2958 : 157 : = build_component_ref (UNKNOWN_LOCATION,
2959 : : datum, field_id,
2960 : : UNKNOWN_LOCATION, UNKNOWN_LOCATION);
2961 : 157 : counted_by_ref = build_fold_addr_expr (counted_by_ref);
2962 : :
2963 : : /* Get the TYPE of the counted_by field. */
2964 : 157 : tree counted_by_field = lookup_field (type, field_id);
2965 : 157 : gcc_assert (counted_by_field);
2966 : :
2967 : 203 : do
2968 : : {
2969 : 203 : *counted_by_type = TREE_TYPE (TREE_VALUE (counted_by_field));
2970 : 203 : counted_by_field = TREE_CHAIN (counted_by_field);
2971 : : }
2972 : 203 : while (counted_by_field);
2973 : : }
2974 : : return counted_by_ref;
2975 : : }
2976 : :
2977 : : /* Given a COMPONENT_REF REF with the location LOC, the corresponding
2978 : : COUNTED_BY_REF, and the COUNTED_BY_TYPE, generate an INDIRECT_REF
2979 : : to a call to the internal function .ACCESS_WITH_SIZE.
2980 : :
2981 : : REF
2982 : :
2983 : : to:
2984 : :
2985 : : (*.ACCESS_WITH_SIZE (REF, COUNTED_BY_REF, (* TYPE_OF_SIZE)0,
2986 : : TYPE_SIZE_UNIT for element)
2987 : :
2988 : : NOTE: The return type of this function is the POINTER type pointing
2989 : : to the original flexible array type.
2990 : : Then the type of the INDIRECT_REF is the original flexible array type.
2991 : :
2992 : : The type of the first argument of this function is a POINTER type
2993 : : to the original flexible array type.
2994 : :
2995 : : The 3rd argument of the call is a constant 0 with the pointer TYPE whose
2996 : : pointee type is the TYPE of the object pointed by COUNTED_BY_REF.
2997 : :
2998 : : The 4th argument of the call is the TYPE_SIZE_UNIT of the element TYPE
2999 : : of the array.
3000 : :
3001 : : */
3002 : : static tree
3003 : 157 : build_access_with_size_for_counted_by (location_t loc, tree ref,
3004 : : tree counted_by_ref,
3005 : : tree counted_by_type)
3006 : : {
3007 : 157 : gcc_assert (c_flexible_array_member_type_p (TREE_TYPE (ref)));
3008 : : /* The result type of the call is a pointer to the flexible array type. */
3009 : 157 : tree result_type = c_build_pointer_type (TREE_TYPE (ref));
3010 : 157 : tree element_size = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (ref)));
3011 : :
3012 : 157 : tree first_param
3013 : 157 : = c_fully_fold (array_to_pointer_conversion (loc, ref), false, NULL);
3014 : 157 : tree second_param
3015 : 157 : = c_fully_fold (counted_by_ref, false, NULL);
3016 : 157 : tree third_param = build_int_cst (build_pointer_type (counted_by_type), 0);
3017 : :
3018 : 157 : tree call
3019 : 157 : = build_call_expr_internal_loc (loc, IFN_ACCESS_WITH_SIZE,
3020 : : result_type, 4,
3021 : : first_param,
3022 : : second_param,
3023 : : third_param,
3024 : : element_size);
3025 : :
3026 : : /* Wrap the call with an INDIRECT_REF with the flexible array type. */
3027 : 157 : call = build1 (INDIRECT_REF, TREE_TYPE (ref), call);
3028 : 157 : SET_EXPR_LOCATION (call, loc);
3029 : 157 : return call;
3030 : : }
3031 : :
3032 : : /* For the COMPONENT_REF ref, check whether it has a counted_by attribute,
3033 : : if so, wrap this COMPONENT_REF with the corresponding CALL to the
3034 : : function .ACCESS_WITH_SIZE.
3035 : : Otherwise, return the ref itself. */
3036 : :
3037 : : tree
3038 : 2175114 : handle_counted_by_for_component_ref (location_t loc, tree ref)
3039 : : {
3040 : 2175114 : gcc_assert (TREE_CODE (ref) == COMPONENT_REF);
3041 : 2175114 : tree datum = TREE_OPERAND (ref, 0);
3042 : 2175114 : tree subdatum = TREE_OPERAND (ref, 1);
3043 : 2175114 : tree counted_by_type = NULL_TREE;
3044 : 2175114 : tree counted_by_ref = build_counted_by_ref (datum, subdatum,
3045 : : &counted_by_type);
3046 : 2175114 : if (counted_by_ref)
3047 : 157 : ref = build_access_with_size_for_counted_by (loc, ref,
3048 : : counted_by_ref,
3049 : : counted_by_type);
3050 : 2175114 : return ref;
3051 : : }
3052 : :
3053 : : /* Make an expression to refer to the COMPONENT field of structure or
3054 : : union value DATUM. COMPONENT is an IDENTIFIER_NODE. LOC is the
3055 : : location of the COMPONENT_REF. COMPONENT_LOC is the location
3056 : : of COMPONENT. ARROW_LOC is the location of the first -> operand if
3057 : : it is from -> operator.
3058 : : If HANDLE_COUNTED_BY is true, check the counted_by attribute and generate
3059 : : a call to .ACCESS_WITH_SIZE. Otherwise, ignore the attribute. */
3060 : :
3061 : : tree
3062 : 2224706 : build_component_ref (location_t loc, tree datum, tree component,
3063 : : location_t component_loc, location_t arrow_loc,
3064 : : bool handle_counted_by)
3065 : : {
3066 : 2224706 : tree type = TREE_TYPE (datum);
3067 : 2224706 : enum tree_code code = TREE_CODE (type);
3068 : 2224706 : tree field = NULL;
3069 : 2224706 : tree ref;
3070 : 2224706 : bool datum_lvalue = lvalue_p (datum);
3071 : :
3072 : 2224706 : if (!objc_is_public (datum, component))
3073 : 0 : return error_mark_node;
3074 : :
3075 : : /* Detect Objective-C property syntax object.property. */
3076 : 2224706 : if (c_dialect_objc ()
3077 : 2224706 : && (ref = objc_maybe_build_component_ref (datum, component)))
3078 : : return ref;
3079 : :
3080 : : /* See if there is a field or component with name COMPONENT. */
3081 : :
3082 : 2224706 : if (code == RECORD_TYPE || code == UNION_TYPE)
3083 : : {
3084 : 2224634 : if (!COMPLETE_TYPE_P (type))
3085 : : {
3086 : 15 : c_incomplete_type_error (loc, NULL_TREE, type);
3087 : 15 : return error_mark_node;
3088 : : }
3089 : :
3090 : 2224619 : field = lookup_field (type, component);
3091 : :
3092 : 2224619 : if (!field)
3093 : : {
3094 : 63 : tree guessed_id = lookup_field_fuzzy (type, component);
3095 : 63 : if (guessed_id)
3096 : : {
3097 : : /* Attempt to provide a fixit replacement hint, if
3098 : : we have a valid range for the component. */
3099 : 0 : location_t reported_loc
3100 : 26 : = (component_loc != UNKNOWN_LOCATION) ? component_loc : loc;
3101 : 26 : gcc_rich_location rich_loc (reported_loc);
3102 : 26 : if (component_loc != UNKNOWN_LOCATION)
3103 : 26 : rich_loc.add_fixit_misspelled_id (component_loc, guessed_id);
3104 : 26 : error_at (&rich_loc,
3105 : : "%qT has no member named %qE; did you mean %qE?",
3106 : : type, component, guessed_id);
3107 : 26 : }
3108 : : else
3109 : 37 : error_at (loc, "%qT has no member named %qE", type, component);
3110 : 63 : return error_mark_node;
3111 : : }
3112 : :
3113 : : /* Accessing elements of atomic structures or unions is undefined
3114 : : behavior (C11 6.5.2.3#5). */
3115 : 2224556 : if (TYPE_ATOMIC (type) && c_inhibit_evaluation_warnings == 0)
3116 : : {
3117 : 18 : if (code == RECORD_TYPE)
3118 : 12 : warning_at (loc, 0, "accessing a member %qE of an atomic "
3119 : : "structure %qE", component, datum);
3120 : : else
3121 : 6 : warning_at (loc, 0, "accessing a member %qE of an atomic "
3122 : : "union %qE", component, datum);
3123 : : }
3124 : :
3125 : : /* Chain the COMPONENT_REFs if necessary down to the FIELD.
3126 : : This might be better solved in future the way the C++ front
3127 : : end does it - by giving the anonymous entities each a
3128 : : separate name and type, and then have build_component_ref
3129 : : recursively call itself. We can't do that here. */
3130 : 2226613 : do
3131 : : {
3132 : 2226613 : tree subdatum = TREE_VALUE (field);
3133 : 2226613 : int quals;
3134 : 2226613 : tree subtype;
3135 : 2226613 : bool use_datum_quals;
3136 : : /* Do not handle counted_by when in typeof and alignof operator. */
3137 : 2226613 : handle_counted_by = handle_counted_by && !in_typeof && !in_alignof;
3138 : :
3139 : 2226613 : if (TREE_TYPE (subdatum) == error_mark_node)
3140 : : return error_mark_node;
3141 : :
3142 : : /* If this is an rvalue, it does not have qualifiers in C
3143 : : standard terms and we must avoid propagating such
3144 : : qualifiers down to a non-lvalue array that is then
3145 : : converted to a pointer. */
3146 : 4453226 : use_datum_quals = (datum_lvalue
3147 : 2226613 : || TREE_CODE (TREE_TYPE (subdatum)) != ARRAY_TYPE);
3148 : :
3149 : 2226613 : quals = TYPE_QUALS (strip_array_types (TREE_TYPE (subdatum)));
3150 : 2226613 : if (use_datum_quals)
3151 : 2226351 : quals |= TYPE_QUALS (TREE_TYPE (datum));
3152 : 2226613 : subtype = c_build_qualified_type (TREE_TYPE (subdatum), quals);
3153 : :
3154 : 2226613 : ref = build3 (COMPONENT_REF, subtype, datum, subdatum,
3155 : : NULL_TREE);
3156 : 2226613 : SET_EXPR_LOCATION (ref, loc);
3157 : :
3158 : 2226613 : if (handle_counted_by)
3159 : 2175104 : ref = handle_counted_by_for_component_ref (loc, ref);
3160 : :
3161 : 2226613 : if (TREE_READONLY (subdatum)
3162 : 2226613 : || (use_datum_quals && TREE_READONLY (datum)))
3163 : 30378 : TREE_READONLY (ref) = 1;
3164 : 2226613 : if (TREE_THIS_VOLATILE (subdatum)
3165 : 2225769 : || (use_datum_quals && TREE_THIS_VOLATILE (datum)))
3166 : 2278 : TREE_THIS_VOLATILE (ref) = 1;
3167 : :
3168 : 2226613 : if (TREE_UNAVAILABLE (subdatum))
3169 : 10 : error_unavailable_use (subdatum, NULL_TREE);
3170 : 2226603 : else if (TREE_DEPRECATED (subdatum))
3171 : 16 : warn_deprecated_use (subdatum, NULL_TREE);
3172 : :
3173 : 2226613 : datum = ref;
3174 : :
3175 : 2226613 : field = TREE_CHAIN (field);
3176 : : }
3177 : 2226613 : while (field);
3178 : :
3179 : : return ref;
3180 : : }
3181 : 72 : else if (should_suggest_deref_p (type))
3182 : : {
3183 : : /* Special-case the error message for "ptr.field" for the case
3184 : : where the user has confused "." vs "->". */
3185 : 7 : rich_location richloc (line_table, loc);
3186 : 7 : if (INDIRECT_REF_P (datum) && arrow_loc != UNKNOWN_LOCATION)
3187 : : {
3188 : 2 : richloc.add_fixit_insert_before (arrow_loc, "(*");
3189 : 2 : richloc.add_fixit_insert_after (arrow_loc, ")");
3190 : 2 : error_at (&richloc,
3191 : : "%qE is a pointer to pointer; did you mean to dereference "
3192 : : "it before applying %<->%> to it?",
3193 : 2 : TREE_OPERAND (datum, 0));
3194 : : }
3195 : : else
3196 : : {
3197 : : /* "loc" should be the "." token. */
3198 : 5 : richloc.add_fixit_replace ("->");
3199 : 5 : error_at (&richloc,
3200 : : "%qE is a pointer; did you mean to use %<->%>?",
3201 : : datum);
3202 : : }
3203 : 7 : return error_mark_node;
3204 : 7 : }
3205 : 65 : else if (code != ERROR_MARK)
3206 : 1 : error_at (loc,
3207 : : "request for member %qE in something not a structure or union",
3208 : : component);
3209 : :
3210 : 65 : return error_mark_node;
3211 : : }
3212 : :
3213 : : /* Given an expression PTR for a pointer, return an expression
3214 : : for the value pointed to.
3215 : : ERRORSTRING is the name of the operator to appear in error messages.
3216 : :
3217 : : LOC is the location to use for the generated tree. */
3218 : :
3219 : : tree
3220 : 2675635 : build_indirect_ref (location_t loc, tree ptr, ref_operator errstring)
3221 : : {
3222 : 2675635 : tree pointer = default_conversion (ptr);
3223 : 2675635 : tree type = TREE_TYPE (pointer);
3224 : 2675635 : tree ref;
3225 : :
3226 : 2675635 : if (TREE_CODE (type) == POINTER_TYPE)
3227 : : {
3228 : 2675284 : if (CONVERT_EXPR_P (pointer)
3229 : 1906686 : || TREE_CODE (pointer) == VIEW_CONVERT_EXPR)
3230 : : {
3231 : : /* If a warning is issued, mark it to avoid duplicates from
3232 : : the backend. This only needs to be done at
3233 : : warn_strict_aliasing > 2. */
3234 : 768598 : if (warn_strict_aliasing > 2)
3235 : 334841 : if (strict_aliasing_warning (EXPR_LOCATION (pointer),
3236 : 334841 : type, TREE_OPERAND (pointer, 0)))
3237 : 7 : suppress_warning (pointer, OPT_Wstrict_aliasing_);
3238 : : }
3239 : :
3240 : 2675284 : if (TREE_CODE (pointer) == ADDR_EXPR
3241 : 2675284 : && (TREE_TYPE (TREE_OPERAND (pointer, 0))
3242 : 66764 : == TREE_TYPE (type)))
3243 : : {
3244 : 66755 : ref = TREE_OPERAND (pointer, 0);
3245 : 66755 : protected_set_expr_location (ref, loc);
3246 : 66755 : return ref;
3247 : : }
3248 : : else
3249 : : {
3250 : 2608529 : tree t = TREE_TYPE (type);
3251 : :
3252 : 2608529 : ref = build1 (INDIRECT_REF, t, pointer);
3253 : :
3254 : 2608529 : if (VOID_TYPE_P (t) && c_inhibit_evaluation_warnings == 0)
3255 : 147 : warning_at (loc, 0, "dereferencing %<void *%> pointer");
3256 : :
3257 : : /* We *must* set TREE_READONLY when dereferencing a pointer to const,
3258 : : so that we get the proper error message if the result is used
3259 : : to assign to. Also, &* is supposed to be a no-op.
3260 : : And ANSI C seems to specify that the type of the result
3261 : : should be the const type. */
3262 : : /* A de-reference of a pointer to const is not a const. It is valid
3263 : : to change it via some other pointer. */
3264 : 2608529 : TREE_READONLY (ref) = TYPE_READONLY (t);
3265 : 2608529 : TREE_SIDE_EFFECTS (ref)
3266 : 2608529 : = TYPE_VOLATILE (t) || TREE_SIDE_EFFECTS (pointer);
3267 : 2608529 : TREE_THIS_VOLATILE (ref) = TYPE_VOLATILE (t);
3268 : 2608529 : protected_set_expr_location (ref, loc);
3269 : 2608529 : return ref;
3270 : : }
3271 : : }
3272 : 351 : else if (TREE_CODE (pointer) != ERROR_MARK)
3273 : 278 : invalid_indirection_error (loc, type, errstring);
3274 : :
3275 : 351 : return error_mark_node;
3276 : : }
3277 : :
3278 : : /* This handles expressions of the form "a[i]", which denotes
3279 : : an array reference.
3280 : :
3281 : : This is logically equivalent in C to *(a+i), but we may do it differently.
3282 : : If A is a variable or a member, we generate a primitive ARRAY_REF.
3283 : : This avoids forcing the array out of registers, and can work on
3284 : : arrays that are not lvalues (for example, members of structures returned
3285 : : by functions).
3286 : :
3287 : : For vector types, allow vector[i] but not i[vector], and create
3288 : : *(((type*)&vectortype) + i) for the expression.
3289 : :
3290 : : LOC is the location to use for the returned expression. */
3291 : :
3292 : : tree
3293 : 3393426 : build_array_ref (location_t loc, tree array, tree index)
3294 : : {
3295 : 3393426 : tree ret;
3296 : 3393426 : bool swapped = false;
3297 : 3393426 : if (TREE_TYPE (array) == error_mark_node
3298 : 3393426 : || TREE_TYPE (index) == error_mark_node)
3299 : : return error_mark_node;
3300 : :
3301 : 3393318 : if (TREE_CODE (TREE_TYPE (array)) != ARRAY_TYPE
3302 : 1938053 : && TREE_CODE (TREE_TYPE (array)) != POINTER_TYPE
3303 : : /* Allow vector[index] but not index[vector]. */
3304 : 4390945 : && !gnu_vector_type_p (TREE_TYPE (array)))
3305 : : {
3306 : 194 : if (TREE_CODE (TREE_TYPE (index)) != ARRAY_TYPE
3307 : 194 : && TREE_CODE (TREE_TYPE (index)) != POINTER_TYPE)
3308 : : {
3309 : 2 : error_at (loc,
3310 : : "subscripted value is neither array nor pointer nor vector");
3311 : :
3312 : 2 : return error_mark_node;
3313 : : }
3314 : 192 : std::swap (array, index);
3315 : 192 : swapped = true;
3316 : : }
3317 : :
3318 : 3393316 : if (!INTEGRAL_TYPE_P (TREE_TYPE (index)))
3319 : : {
3320 : 2 : error_at (loc, "array subscript is not an integer");
3321 : 2 : return error_mark_node;
3322 : : }
3323 : :
3324 : 3393314 : if (TREE_CODE (TREE_TYPE (TREE_TYPE (array))) == FUNCTION_TYPE)
3325 : : {
3326 : 10 : error_at (loc, "subscripted value is pointer to function");
3327 : 10 : return error_mark_node;
3328 : : }
3329 : :
3330 : : /* ??? Existing practice has been to warn only when the char
3331 : : index is syntactically the index, not for char[array]. */
3332 : 3393304 : if (!swapped)
3333 : 3393118 : warn_array_subscript_with_type_char (loc, index);
3334 : :
3335 : : /* Apply default promotions *after* noticing character types. */
3336 : 3393304 : index = default_conversion (index);
3337 : 3393304 : if (index == error_mark_node)
3338 : : return error_mark_node;
3339 : :
3340 : 3393303 : gcc_assert (TREE_CODE (TREE_TYPE (index)) == INTEGER_TYPE
3341 : : || TREE_CODE (TREE_TYPE (index)) == BITINT_TYPE);
3342 : :
3343 : 3393303 : bool was_vector = VECTOR_TYPE_P (TREE_TYPE (array));
3344 : 3393303 : bool non_lvalue = convert_vector_to_array_for_subscript (loc, &array, index);
3345 : :
3346 : 3393303 : if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE)
3347 : : {
3348 : 2452705 : tree rval, type;
3349 : :
3350 : : /* An array that is indexed by a non-constant
3351 : : cannot be stored in a register; we must be able to do
3352 : : address arithmetic on its address.
3353 : : Likewise an array of elements of variable size. */
3354 : 2452705 : if (TREE_CODE (index) != INTEGER_CST
3355 : 2452705 : || (COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (array)))
3356 : 1990337 : && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array)))) != INTEGER_CST))
3357 : : {
3358 : 463105 : if (!c_mark_addressable (array, true))
3359 : 1 : return error_mark_node;
3360 : : }
3361 : : /* An array that is indexed by a constant value which is not within
3362 : : the array bounds cannot be stored in a register either; because we
3363 : : would get a crash in store_bit_field/extract_bit_field when trying
3364 : : to access a non-existent part of the register. */
3365 : 2452704 : if (TREE_CODE (index) == INTEGER_CST
3366 : 1990337 : && TYPE_DOMAIN (TREE_TYPE (array))
3367 : 4439685 : && !int_fits_type_p (index, TYPE_DOMAIN (TREE_TYPE (array))))
3368 : : {
3369 : 60556 : if (!c_mark_addressable (array))
3370 : 0 : return error_mark_node;
3371 : : }
3372 : :
3373 : 2452704 : if ((pedantic || warn_c90_c99_compat)
3374 : 2429848 : && ! was_vector)
3375 : : {
3376 : 1454559 : tree foo = array;
3377 : 2274396 : while (TREE_CODE (foo) == COMPONENT_REF)
3378 : 819837 : foo = TREE_OPERAND (foo, 0);
3379 : 1454559 : if (VAR_P (foo) && C_DECL_REGISTER (foo))
3380 : 0 : pedwarn (loc, OPT_Wpedantic,
3381 : : "ISO C forbids subscripting %<register%> array");
3382 : 1454559 : else if (!lvalue_p (foo))
3383 : 118 : pedwarn_c90 (loc, OPT_Wpedantic,
3384 : : "ISO C90 forbids subscripting non-lvalue "
3385 : : "array");
3386 : : }
3387 : :
3388 : 2452704 : if (TREE_CODE (TREE_TYPE (index)) == BITINT_TYPE
3389 : 2452704 : && TYPE_PRECISION (TREE_TYPE (index)) > TYPE_PRECISION (sizetype))
3390 : 3 : index = fold_convert (sizetype, index);
3391 : :
3392 : 2452704 : type = TREE_TYPE (TREE_TYPE (array));
3393 : 2452704 : rval = build4 (ARRAY_REF, type, array, index, NULL_TREE, NULL_TREE);
3394 : : /* Array ref is const/volatile if the array elements are
3395 : : or if the array is. */
3396 : 7358112 : TREE_READONLY (rval)
3397 : 2452704 : |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array)))
3398 : 2452704 : | TREE_READONLY (array));
3399 : 7358112 : TREE_SIDE_EFFECTS (rval)
3400 : 2452704 : |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
3401 : 2452704 : | TREE_SIDE_EFFECTS (array));
3402 : 4905408 : TREE_THIS_VOLATILE (rval)
3403 : 2452704 : |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
3404 : : /* This was added by rms on 16 Nov 91.
3405 : : It fixes vol struct foo *a; a->elts[1]
3406 : : in an inline function.
3407 : : Hope it doesn't break something else. */
3408 : 2452704 : | TREE_THIS_VOLATILE (array));
3409 : 2452704 : ret = require_complete_type (loc, rval);
3410 : 2452704 : protected_set_expr_location (ret, loc);
3411 : 2452704 : if (non_lvalue)
3412 : 102853 : ret = non_lvalue_loc (loc, ret);
3413 : 2452704 : return ret;
3414 : : }
3415 : : else
3416 : : {
3417 : 940598 : tree ar = default_conversion (array);
3418 : :
3419 : 940598 : if (ar == error_mark_node)
3420 : : return ar;
3421 : :
3422 : 940598 : gcc_assert (TREE_CODE (TREE_TYPE (ar)) == POINTER_TYPE);
3423 : 940598 : gcc_assert (TREE_CODE (TREE_TYPE (TREE_TYPE (ar))) != FUNCTION_TYPE);
3424 : :
3425 : 940598 : ret = build_indirect_ref (loc, build_binary_op (loc, PLUS_EXPR, ar,
3426 : : index, false),
3427 : : RO_ARRAY_INDEXING);
3428 : 940598 : if (non_lvalue)
3429 : 0 : ret = non_lvalue_loc (loc, ret);
3430 : 940598 : return ret;
3431 : : }
3432 : : }
3433 : :
3434 : : /* Build an OpenMP array section reference, creating an exact type for the
3435 : : resulting expression based on the element type and bounds if possible. If
3436 : : we have variable bounds, create an incomplete array type for the result
3437 : : instead. */
3438 : :
3439 : : tree
3440 : 3879 : build_omp_array_section (location_t loc, tree array, tree index, tree length)
3441 : : {
3442 : 3879 : tree type = TREE_TYPE (array);
3443 : 3879 : gcc_assert (type);
3444 : :
3445 : 3879 : tree sectype, eltype = TREE_TYPE (type);
3446 : :
3447 : : /* It's not an array or pointer type. Just reuse the type of the original
3448 : : expression as the type of the array section (an error will be raised
3449 : : anyway, later). */
3450 : 3879 : if (eltype == NULL_TREE || error_operand_p (eltype))
3451 : 12 : sectype = TREE_TYPE (array);
3452 : : else
3453 : : {
3454 : 3867 : tree idxtype = NULL_TREE;
3455 : :
3456 : 3867 : if (index != NULL_TREE
3457 : 3867 : && length != NULL_TREE
3458 : 2967 : && INTEGRAL_TYPE_P (TREE_TYPE (index))
3459 : 6829 : && INTEGRAL_TYPE_P (TREE_TYPE (length)))
3460 : : {
3461 : 2955 : tree low = fold_convert (sizetype, index);
3462 : 2955 : tree high = fold_convert (sizetype, length);
3463 : 2955 : high = size_binop (PLUS_EXPR, low, high);
3464 : 2955 : high = size_binop (MINUS_EXPR, high, size_one_node);
3465 : 2955 : idxtype = build_range_type (sizetype, low, high);
3466 : : }
3467 : 135 : else if ((index == NULL_TREE || integer_zerop (index))
3468 : 802 : && length != NULL_TREE
3469 : 1562 : && INTEGRAL_TYPE_P (TREE_TYPE (length)))
3470 : 633 : idxtype = build_index_type (length);
3471 : :
3472 : 3867 : gcc_assert (!error_operand_p (idxtype));
3473 : :
3474 : 3867 : sectype = c_build_array_type (eltype, idxtype);
3475 : : }
3476 : :
3477 : 3879 : return build3_loc (loc, OMP_ARRAY_SECTION, sectype, array, index, length);
3478 : : }
3479 : :
3480 : :
3481 : : /* Build an external reference to identifier ID. FUN indicates
3482 : : whether this will be used for a function call. LOC is the source
3483 : : location of the identifier. This sets *TYPE to the type of the
3484 : : identifier, which is not the same as the type of the returned value
3485 : : for CONST_DECLs defined as enum constants. If the type of the
3486 : : identifier is not available, *TYPE is set to NULL. */
3487 : : tree
3488 : 170477043 : build_external_ref (location_t loc, tree id, bool fun, tree *type)
3489 : : {
3490 : 170477043 : tree ref;
3491 : 170477043 : tree decl = lookup_name (id);
3492 : :
3493 : : /* In Objective-C, an instance variable (ivar) may be preferred to
3494 : : whatever lookup_name() found. */
3495 : 170477043 : decl = objc_lookup_ivar (decl, id);
3496 : :
3497 : 170477043 : *type = NULL;
3498 : 170477043 : if (decl && decl != error_mark_node)
3499 : : {
3500 : 170470700 : ref = decl;
3501 : 170470700 : *type = TREE_TYPE (ref);
3502 : 170470700 : if (DECL_P (decl) && C_DECL_UNDERSPECIFIED (decl))
3503 : 4 : error_at (loc, "underspecified %qD referenced in its initializer",
3504 : : decl);
3505 : : }
3506 : 6343 : else if (fun)
3507 : : /* Implicit function declaration. */
3508 : 4729 : ref = implicitly_declare (loc, id);
3509 : 1614 : else if (decl == error_mark_node)
3510 : : /* Don't complain about something that's already been
3511 : : complained about. */
3512 : : return error_mark_node;
3513 : : else
3514 : : {
3515 : 1384 : undeclared_variable (loc, id);
3516 : 1384 : return error_mark_node;
3517 : : }
3518 : :
3519 : : /* For an OpenMP map clause, we can get better diagnostics for decls with
3520 : : unmappable types if we return the decl with an error_mark_node type,
3521 : : rather than returning error_mark_node for the decl itself. */
3522 : 170475429 : if (TREE_TYPE (ref) == error_mark_node
3523 : 170475429 : && !c_omp_array_section_p)
3524 : : return error_mark_node;
3525 : :
3526 : 170475412 : if (TREE_UNAVAILABLE (ref))
3527 : 14 : error_unavailable_use (ref, NULL_TREE);
3528 : 170475398 : else if (TREE_DEPRECATED (ref))
3529 : 49 : warn_deprecated_use (ref, NULL_TREE);
3530 : :
3531 : : /* Recursive call does not count as usage. */
3532 : 170475412 : if (ref != current_function_decl)
3533 : : {
3534 : 170472807 : TREE_USED (ref) = 1;
3535 : : }
3536 : :
3537 : 170475412 : if (TREE_CODE (ref) == FUNCTION_DECL && !in_alignof)
3538 : : {
3539 : 49993064 : if (!in_sizeof && !in_typeof && !in_countof)
3540 : 49368465 : C_DECL_USED (ref) = 1;
3541 : 624599 : else if (DECL_INITIAL (ref) == NULL_TREE
3542 : 618501 : && DECL_EXTERNAL (ref)
3543 : 1243099 : && !TREE_PUBLIC (ref))
3544 : 100 : record_maybe_used_decl (ref);
3545 : : }
3546 : :
3547 : 170475412 : if (TREE_CODE (ref) == CONST_DECL)
3548 : : {
3549 : 410081 : used_types_insert (TREE_TYPE (ref));
3550 : :
3551 : 410081 : if (warn_cxx_compat
3552 : 377 : && TREE_CODE (TREE_TYPE (ref)) == ENUMERAL_TYPE
3553 : 410456 : && C_TYPE_DEFINED_IN_STRUCT (TREE_TYPE (ref)))
3554 : : {
3555 : 1 : warning_at (loc, OPT_Wc___compat,
3556 : : ("enum constant defined in struct or union "
3557 : : "is not visible in C++"));
3558 : 1 : inform (DECL_SOURCE_LOCATION (ref), "enum constant defined here");
3559 : : }
3560 : :
3561 : 410081 : ref = DECL_INITIAL (ref);
3562 : 410081 : TREE_CONSTANT (ref) = 1;
3563 : : }
3564 : 170065331 : else if (current_function_decl != NULL_TREE
3565 : 168569866 : && !DECL_FILE_SCOPE_P (current_function_decl)
3566 : 170065331 : && (VAR_OR_FUNCTION_DECL_P (ref)
3567 : : || TREE_CODE (ref) == PARM_DECL))
3568 : : {
3569 : 10083 : tree context = decl_function_context (ref);
3570 : :
3571 : 10083 : if (context != NULL_TREE && context != current_function_decl)
3572 : 1612 : DECL_NONLOCAL (ref) = 1;
3573 : : }
3574 : : /* C99 6.7.4p3: An inline definition of a function with external
3575 : : linkage ... shall not contain a reference to an identifier with
3576 : : internal linkage. */
3577 : 170055248 : else if (current_function_decl != NULL_TREE
3578 : 168559783 : && DECL_DECLARED_INLINE_P (current_function_decl)
3579 : 155194914 : && DECL_EXTERNAL (current_function_decl)
3580 : 154441852 : && VAR_OR_FUNCTION_DECL_P (ref)
3581 : 55029818 : && (!VAR_P (ref) || TREE_STATIC (ref))
3582 : 46107057 : && ! TREE_PUBLIC (ref)
3583 : 170055282 : && DECL_CONTEXT (ref) != current_function_decl)
3584 : 25 : record_inline_static (loc, current_function_decl, ref,
3585 : : csi_internal);
3586 : :
3587 : : return ref;
3588 : : }
3589 : :
3590 : : /* Record details of decls possibly used inside sizeof or typeof. */
3591 : : struct maybe_used_decl
3592 : : {
3593 : : /* The decl. */
3594 : : tree decl;
3595 : : /* The level seen at (in_sizeof + in_typeof + in_countof). */
3596 : : int level;
3597 : : /* The next one at this level or above, or NULL. */
3598 : : struct maybe_used_decl *next;
3599 : : };
3600 : :
3601 : : static struct maybe_used_decl *maybe_used_decls;
3602 : :
3603 : : /* Record that DECL, an undefined static function reference seen
3604 : : inside sizeof or typeof, might be used if the operand of sizeof is
3605 : : a VLA type or the operand of typeof is a variably modified
3606 : : type. */
3607 : :
3608 : : static void
3609 : 100 : record_maybe_used_decl (tree decl)
3610 : : {
3611 : 100 : struct maybe_used_decl *t = XOBNEW (&parser_obstack, struct maybe_used_decl);
3612 : 100 : t->decl = decl;
3613 : 100 : t->level = in_sizeof + in_typeof + in_countof;
3614 : 100 : t->next = maybe_used_decls;
3615 : 100 : maybe_used_decls = t;
3616 : 100 : }
3617 : :
3618 : : /* Pop the stack of decls possibly used inside sizeof or typeof. If
3619 : : USED is false, just discard them. If it is true, mark them used
3620 : : (if no longer inside sizeof or typeof) or move them to the next
3621 : : level up (if still inside sizeof or typeof). */
3622 : :
3623 : : void
3624 : 1437628 : pop_maybe_used (bool used)
3625 : : {
3626 : 1437628 : struct maybe_used_decl *p = maybe_used_decls;
3627 : 1437628 : int cur_level = in_sizeof + in_typeof + in_countof;
3628 : 1437731 : while (p && p->level > cur_level)
3629 : : {
3630 : 103 : if (used)
3631 : : {
3632 : 13 : if (cur_level == 0)
3633 : 10 : C_DECL_USED (p->decl) = 1;
3634 : : else
3635 : 3 : p->level = cur_level;
3636 : : }
3637 : 103 : p = p->next;
3638 : : }
3639 : 1437628 : if (!used || cur_level == 0)
3640 : 1437612 : maybe_used_decls = p;
3641 : 1437628 : }
3642 : :
3643 : : /* Return the result of sizeof applied to EXPR. */
3644 : :
3645 : : struct c_expr
3646 : 301088 : c_expr_sizeof_expr (location_t loc, struct c_expr expr)
3647 : : {
3648 : 301088 : struct c_expr ret;
3649 : 301088 : if (expr.value == error_mark_node)
3650 : : {
3651 : 109 : ret.value = error_mark_node;
3652 : 109 : ret.original_code = ERROR_MARK;
3653 : 109 : ret.original_type = NULL;
3654 : 109 : ret.m_decimal = 0;
3655 : 109 : pop_maybe_used (false);
3656 : : }
3657 : : else
3658 : : {
3659 : 300979 : bool expr_const_operands = true;
3660 : :
3661 : 300979 : if (TREE_CODE (expr.value) == PARM_DECL
3662 : 300979 : && C_ARRAY_PARAMETER (expr.value))
3663 : : {
3664 : 55 : auto_diagnostic_group d;
3665 : 55 : if (warning_at (loc, OPT_Wsizeof_array_argument,
3666 : : "%<sizeof%> on array function parameter %qE will "
3667 : : "return size of %qT", expr.value,
3668 : 55 : TREE_TYPE (expr.value)))
3669 : 19 : inform (DECL_SOURCE_LOCATION (expr.value), "declared here");
3670 : 55 : }
3671 : 300979 : tree folded_expr = c_fully_fold (expr.value, require_constant_value,
3672 : : &expr_const_operands);
3673 : 300979 : ret.value = c_sizeof (loc, TREE_TYPE (folded_expr));
3674 : 300979 : c_last_sizeof_arg = expr.value;
3675 : 300979 : c_last_sizeof_loc = loc;
3676 : 300979 : ret.original_code = SIZEOF_EXPR;
3677 : 300979 : ret.original_type = NULL;
3678 : 300979 : ret.m_decimal = 0;
3679 : 300979 : if (C_TYPE_VARIABLE_SIZE (TREE_TYPE (folded_expr)))
3680 : : {
3681 : : /* sizeof is evaluated when given a vla (C99 6.5.3.4p2). */
3682 : 271 : ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
3683 : : folded_expr, ret.value);
3684 : 271 : C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !expr_const_operands;
3685 : 271 : SET_EXPR_LOCATION (ret.value, loc);
3686 : : }
3687 : 300979 : pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (folded_expr)));
3688 : : }
3689 : 301088 : return ret;
3690 : : }
3691 : :
3692 : : /* Return the result of sizeof applied to T, a structure for the type
3693 : : name passed to sizeof (rather than the type itself). LOC is the
3694 : : location of the original expression. */
3695 : :
3696 : : struct c_expr
3697 : 329405 : c_expr_sizeof_type (location_t loc, struct c_type_name *t)
3698 : : {
3699 : 329405 : tree type;
3700 : 329405 : struct c_expr ret;
3701 : 329405 : tree type_expr = NULL_TREE;
3702 : 329405 : bool type_expr_const = true;
3703 : 329405 : type = groktypename (t, &type_expr, &type_expr_const);
3704 : 329405 : ret.value = c_sizeof (loc, type);
3705 : 329405 : c_last_sizeof_arg = type;
3706 : 329405 : c_last_sizeof_loc = loc;
3707 : 329405 : ret.original_code = SIZEOF_EXPR;
3708 : 329405 : ret.original_type = NULL;
3709 : 329405 : ret.m_decimal = 0;
3710 : 329405 : if (type == error_mark_node)
3711 : : {
3712 : 5 : ret.value = error_mark_node;
3713 : 5 : ret.original_code = ERROR_MARK;
3714 : : }
3715 : : else
3716 : 329358 : if ((type_expr || TREE_CODE (ret.value) == INTEGER_CST)
3717 : 658692 : && C_TYPE_VARIABLE_SIZE (type))
3718 : : {
3719 : : /* If the type is a [*] array, it is a VLA but is represented as
3720 : : having a size of zero. In such a case we must ensure that
3721 : : the result of sizeof does not get folded to a constant by
3722 : : c_fully_fold, because if the size is evaluated the result is
3723 : : not constant and so constraints on zero or negative size
3724 : : arrays must not be applied when this sizeof call is inside
3725 : : another array declarator. */
3726 : 41 : if (!type_expr)
3727 : 16 : type_expr = integer_zero_node;
3728 : 41 : ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
3729 : : type_expr, ret.value);
3730 : 41 : C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !type_expr_const;
3731 : : }
3732 : 329405 : pop_maybe_used (type != error_mark_node
3733 : 329405 : ? C_TYPE_VARIABLE_SIZE (type) : false);
3734 : 329405 : return ret;
3735 : : }
3736 : :
3737 : : static bool
3738 : 136 : is_top_array_vla (tree type)
3739 : : {
3740 : 136 : bool zero, var;
3741 : 136 : tree d;
3742 : :
3743 : 136 : if (TREE_CODE (type) != ARRAY_TYPE)
3744 : : return false;
3745 : 118 : if (!COMPLETE_TYPE_P (type))
3746 : : return false;
3747 : :
3748 : 114 : d = TYPE_DOMAIN (type);
3749 : 114 : zero = !TYPE_MAX_VALUE (d);
3750 : 114 : if (zero)
3751 : : return false;
3752 : :
3753 : 98 : var = (TREE_CODE (TYPE_MIN_VALUE (d)) != INTEGER_CST
3754 : 98 : || TREE_CODE (TYPE_MAX_VALUE (d)) != INTEGER_CST);
3755 : : return var;
3756 : : }
3757 : :
3758 : : /* Return the result of countof applied to EXPR. */
3759 : :
3760 : : struct c_expr
3761 : 53 : c_expr_countof_expr (location_t loc, struct c_expr expr)
3762 : : {
3763 : 53 : struct c_expr ret;
3764 : 53 : if (expr.value == error_mark_node)
3765 : : {
3766 : 1 : ret.value = error_mark_node;
3767 : 1 : ret.original_code = ERROR_MARK;
3768 : 1 : ret.original_type = NULL;
3769 : 1 : ret.m_decimal = 0;
3770 : 1 : pop_maybe_used (false);
3771 : : }
3772 : : else
3773 : : {
3774 : 52 : bool expr_const_operands = true;
3775 : :
3776 : 52 : tree folded_expr = c_fully_fold (expr.value, require_constant_value,
3777 : : &expr_const_operands);
3778 : 52 : ret.value = c_countof_type (loc, TREE_TYPE (folded_expr));
3779 : 52 : c_last_sizeof_arg = expr.value;
3780 : 52 : c_last_sizeof_loc = loc;
3781 : 52 : ret.original_code = COUNTOF_EXPR;
3782 : 52 : ret.original_type = NULL;
3783 : 52 : ret.m_decimal = 0;
3784 : 52 : if (is_top_array_vla (TREE_TYPE (folded_expr)))
3785 : : {
3786 : : /* countof is evaluated when given a vla. */
3787 : 11 : ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
3788 : : folded_expr, ret.value);
3789 : 11 : C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !expr_const_operands;
3790 : 11 : SET_EXPR_LOCATION (ret.value, loc);
3791 : : }
3792 : 52 : pop_maybe_used (is_top_array_vla (TREE_TYPE (folded_expr)));
3793 : : }
3794 : 53 : return ret;
3795 : : }
3796 : :
3797 : : /* Return the result of countof applied to T, a structure for the type
3798 : : name passed to countof (rather than the type itself). LOC is the
3799 : : location of the original expression. */
3800 : :
3801 : : struct c_expr
3802 : 18 : c_expr_countof_type (location_t loc, struct c_type_name *t)
3803 : : {
3804 : 18 : tree type;
3805 : 18 : struct c_expr ret;
3806 : 18 : tree type_expr = NULL_TREE;
3807 : 18 : bool type_expr_const = true;
3808 : 18 : type = groktypename (t, &type_expr, &type_expr_const);
3809 : 18 : ret.value = c_countof_type (loc, type);
3810 : 18 : c_last_sizeof_arg = type;
3811 : 18 : c_last_sizeof_loc = loc;
3812 : 18 : ret.original_code = COUNTOF_EXPR;
3813 : 18 : ret.original_type = NULL;
3814 : 18 : ret.m_decimal = 0;
3815 : 18 : if (type == error_mark_node)
3816 : : {
3817 : 0 : ret.value = error_mark_node;
3818 : 0 : ret.original_code = ERROR_MARK;
3819 : : }
3820 : : else
3821 : 8 : if ((type_expr || TREE_CODE (ret.value) == INTEGER_CST)
3822 : 22 : && is_top_array_vla (type))
3823 : : {
3824 : : /* If the type is a [*] array, it is a VLA but is represented as
3825 : : having a size of zero. In such a case we must ensure that
3826 : : the result of countof does not get folded to a constant by
3827 : : c_fully_fold, because if the number of elements is evaluated
3828 : : the result is not constant and so
3829 : : constraints on zero or negative size arrays must not be applied
3830 : : when this countof call is inside another array declarator. */
3831 : 6 : if (!type_expr)
3832 : 0 : type_expr = integer_zero_node;
3833 : 6 : ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
3834 : : type_expr, ret.value);
3835 : 6 : C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !type_expr_const;
3836 : : }
3837 : 18 : pop_maybe_used (type != error_mark_node ? is_top_array_vla (type) : false);
3838 : 18 : return ret;
3839 : : }
3840 : :
3841 : : /* Build a function call to function FUNCTION with parameters PARAMS.
3842 : : The function call is at LOC.
3843 : : PARAMS is a list--a chain of TREE_LIST nodes--in which the
3844 : : TREE_VALUE of each node is a parameter-expression.
3845 : : FUNCTION's data type may be a function type or a pointer-to-function. */
3846 : :
3847 : : tree
3848 : 0 : build_function_call (location_t loc, tree function, tree params)
3849 : : {
3850 : 0 : vec<tree, va_gc> *v;
3851 : 0 : tree ret;
3852 : :
3853 : 0 : vec_alloc (v, list_length (params));
3854 : 0 : for (; params; params = TREE_CHAIN (params))
3855 : 0 : v->quick_push (TREE_VALUE (params));
3856 : 0 : ret = c_build_function_call_vec (loc, vNULL, function, v, NULL);
3857 : 0 : vec_free (v);
3858 : 0 : return ret;
3859 : : }
3860 : :
3861 : : /* Give a note about the location of the declaration of DECL,
3862 : : or, failing that, a pertinent declaration for FUNCTION_EXPR. */
3863 : :
3864 : : static void
3865 : 299 : inform_declaration (tree decl, tree function_expr)
3866 : : {
3867 : 299 : if (decl && (TREE_CODE (decl) != FUNCTION_DECL
3868 : 278 : || !DECL_IS_UNDECLARED_BUILTIN (decl)))
3869 : 207 : inform (DECL_SOURCE_LOCATION (decl), "declared here");
3870 : 92 : else if (function_expr)
3871 : 92 : switch (TREE_CODE (function_expr))
3872 : : {
3873 : : default:
3874 : : break;
3875 : 13 : case COMPONENT_REF:
3876 : : /* Show the decl of the pertinent field (e.g. for callback
3877 : : fields in a struct. */
3878 : 13 : {
3879 : 13 : tree field_decl = TREE_OPERAND (function_expr, 1);
3880 : 13 : if (location_t loc = DECL_SOURCE_LOCATION (field_decl))
3881 : 13 : inform (loc, "declared here");
3882 : : }
3883 : : break;
3884 : : }
3885 : 299 : }
3886 : :
3887 : : /* C implementation of callback for use when checking param types. */
3888 : :
3889 : : static bool
3890 : 2 : comp_parm_types (tree wanted_type, tree actual_type)
3891 : : {
3892 : 2 : return comptypes (wanted_type, actual_type);
3893 : : }
3894 : :
3895 : : /* Build a function call to function FUNCTION with parameters PARAMS.
3896 : : If FUNCTION is the result of resolving an overloaded target built-in,
3897 : : ORIG_FUNDECL is the original function decl, otherwise it is null.
3898 : : ORIGTYPES, if not NULL, is a vector of types; each element is
3899 : : either NULL or the original type of the corresponding element in
3900 : : PARAMS. The original type may differ from TREE_TYPE of the
3901 : : parameter for enums. FUNCTION's data type may be a function type
3902 : : or pointer-to-function. This function changes the elements of
3903 : : PARAMS. */
3904 : :
3905 : : tree
3906 : 48603843 : build_function_call_vec (location_t loc, vec<location_t> arg_loc,
3907 : : tree function, vec<tree, va_gc> *params,
3908 : : vec<tree, va_gc> *origtypes, tree orig_fundecl)
3909 : : {
3910 : 48603843 : tree fntype, fundecl = NULL_TREE;
3911 : 48603843 : tree name = NULL_TREE, result;
3912 : 48603843 : tree tem;
3913 : 48603843 : int nargs;
3914 : 48603843 : tree *argarray;
3915 : :
3916 : :
3917 : : /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
3918 : 48603843 : STRIP_TYPE_NOPS (function);
3919 : :
3920 : : /* Convert anything with function type to a pointer-to-function. */
3921 : 48603843 : if (TREE_CODE (function) == FUNCTION_DECL)
3922 : : {
3923 : 48526837 : name = DECL_NAME (function);
3924 : :
3925 : 48526837 : if (flag_tm)
3926 : 421 : tm_malloc_replacement (function);
3927 : 48526837 : fundecl = function;
3928 : 48526837 : if (!orig_fundecl)
3929 : 48526837 : orig_fundecl = fundecl;
3930 : : /* Atomic functions have type checking/casting already done. They are
3931 : : often rewritten and don't match the original parameter list. */
3932 : 97053674 : if (name && startswith (IDENTIFIER_POINTER (name), "__atomic_"))
3933 : : origtypes = NULL;
3934 : : }
3935 : 48603843 : if (TREE_CODE (TREE_TYPE (function)) == FUNCTION_TYPE)
3936 : 48541054 : function = function_to_pointer_conversion (loc, function);
3937 : :
3938 : : /* For Objective-C, convert any calls via a cast to OBJC_TYPE_REF
3939 : : expressions, like those used for ObjC messenger dispatches. */
3940 : 48603843 : if (params && !params->is_empty ())
3941 : 37199789 : function = objc_rewrite_function_call (function, (*params)[0]);
3942 : :
3943 : 48603843 : function = c_fully_fold (function, false, NULL);
3944 : :
3945 : 48603843 : fntype = TREE_TYPE (function);
3946 : :
3947 : 48603843 : if (TREE_CODE (fntype) == ERROR_MARK)
3948 : 3 : return error_mark_node;
3949 : :
3950 : 48603840 : if (!(TREE_CODE (fntype) == POINTER_TYPE
3951 : 48603806 : && TREE_CODE (TREE_TYPE (fntype)) == FUNCTION_TYPE))
3952 : : {
3953 : 37 : if (!flag_diagnostics_show_caret && !STATEMENT_CLASS_P (function))
3954 : 33 : error_at (loc,
3955 : : "called object %qE is not a function or function pointer",
3956 : : function);
3957 : 4 : else if (DECL_P (function))
3958 : : {
3959 : 1 : auto_diagnostic_group d;
3960 : 1 : error_at (loc,
3961 : : "called object %qD is not a function or function pointer",
3962 : : function);
3963 : 1 : inform_declaration (function, NULL_TREE);
3964 : 1 : }
3965 : : else
3966 : 3 : error_at (loc,
3967 : : "called object is not a function or function pointer");
3968 : 37 : return error_mark_node;
3969 : : }
3970 : :
3971 : 48603803 : if (fundecl && TREE_THIS_VOLATILE (fundecl))
3972 : 370093 : current_function_returns_abnormally = 1;
3973 : :
3974 : : /* fntype now gets the type of function pointed to. */
3975 : 48603803 : fntype = TREE_TYPE (fntype);
3976 : 48603803 : tree return_type = TREE_TYPE (fntype);
3977 : :
3978 : : /* Convert the parameters to the types declared in the
3979 : : function prototype, or apply default promotions. */
3980 : :
3981 : 48603803 : nargs = convert_arguments (loc, arg_loc, fntype, params,
3982 : : origtypes, function, fundecl);
3983 : 48603803 : if (nargs < 0)
3984 : 178 : return error_mark_node;
3985 : :
3986 : : /* Check that the function is called through a compatible prototype.
3987 : : If it is not, warn. */
3988 : 48602762 : if (CONVERT_EXPR_P (function)
3989 : 879 : && TREE_CODE (tem = TREE_OPERAND (function, 0)) == ADDR_EXPR
3990 : 215 : && TREE_CODE (tem = TREE_OPERAND (tem, 0)) == FUNCTION_DECL
3991 : 48603810 : && !comptypes (fntype, TREE_TYPE (tem)))
3992 : : {
3993 : : /* This situation leads to run-time undefined behavior. We can't,
3994 : : therefore, simply error unless we can prove that all possible
3995 : : executions of the program must execute the code. */
3996 : 20 : warning_at (loc, 0, "function called through a non-compatible type");
3997 : :
3998 : 20 : if (VOID_TYPE_P (return_type)
3999 : 20 : && TYPE_QUALS (return_type) != TYPE_UNQUALIFIED)
4000 : 1 : pedwarn (loc, 0,
4001 : : "function with qualified void return type called");
4002 : : }
4003 : :
4004 : 48603625 : argarray = vec_safe_address (params);
4005 : :
4006 : : /* Check that arguments to builtin functions match the expectations. */
4007 : 48603625 : if (fundecl
4008 : 48526674 : && fndecl_built_in_p (fundecl)
4009 : 80989323 : && !check_builtin_function_arguments (loc, arg_loc, fundecl,
4010 : : orig_fundecl, nargs, argarray))
4011 : 298 : return error_mark_node;
4012 : :
4013 : : /* Check that the arguments to the function are valid. */
4014 : 48603327 : bool warned_p = check_function_arguments (loc, fundecl, fntype,
4015 : : nargs, argarray, &arg_loc,
4016 : : comp_parm_types);
4017 : :
4018 : 48603327 : if (TYPE_QUALS (return_type) != TYPE_UNQUALIFIED
4019 : 48603327 : && !VOID_TYPE_P (return_type))
4020 : 11 : return_type = c_build_qualified_type (return_type, TYPE_UNQUALIFIED);
4021 : 48603327 : if (name != NULL_TREE
4022 : 97129703 : && startswith (IDENTIFIER_POINTER (name), "__builtin_"))
4023 : : {
4024 : 31671196 : if (require_constant_value)
4025 : 3487 : result
4026 : 3487 : = fold_build_call_array_initializer_loc (loc, return_type,
4027 : : function, nargs, argarray);
4028 : : else
4029 : 31667709 : result = fold_build_call_array_loc (loc, return_type,
4030 : : function, nargs, argarray);
4031 : 31671196 : if (TREE_CODE (result) == NOP_EXPR
4032 : 31671196 : && TREE_CODE (TREE_OPERAND (result, 0)) == INTEGER_CST)
4033 : 26510 : STRIP_TYPE_NOPS (result);
4034 : : }
4035 : : else
4036 : 16932131 : result = build_call_array_loc (loc, return_type,
4037 : : function, nargs, argarray);
4038 : : /* If -Wnonnull warning has been diagnosed, avoid diagnosing it again
4039 : : later. */
4040 : 48603327 : if (warned_p && TREE_CODE (result) == CALL_EXPR)
4041 : 215 : suppress_warning (result, OPT_Wnonnull);
4042 : :
4043 : : /* In this improbable scenario, a nested function returns a VM type.
4044 : : Create a TARGET_EXPR so that the call always has a LHS, much as
4045 : : what the C++ FE does for functions returning non-PODs. */
4046 : 48603327 : if (C_TYPE_VARIABLY_MODIFIED (TREE_TYPE (fntype)))
4047 : : {
4048 : 79 : tree tmp = create_tmp_var_raw (TREE_TYPE (fntype));
4049 : 79 : result = build4 (TARGET_EXPR, TREE_TYPE (fntype), tmp, result,
4050 : : NULL_TREE, NULL_TREE);
4051 : : }
4052 : :
4053 : 48603327 : if (VOID_TYPE_P (TREE_TYPE (result)))
4054 : : {
4055 : 2344239 : if (TYPE_QUALS (TREE_TYPE (result)) != TYPE_UNQUALIFIED)
4056 : 2 : pedwarn (loc, 0,
4057 : : "function with qualified void return type called");
4058 : 2344239 : return result;
4059 : : }
4060 : 46259088 : return require_complete_type (loc, result);
4061 : : }
4062 : :
4063 : : /* Like build_function_call_vec, but call also resolve_overloaded_builtin. */
4064 : :
4065 : : tree
4066 : 48603400 : c_build_function_call_vec (location_t loc, const vec<location_t> &arg_loc,
4067 : : tree function, vec<tree, va_gc> *params,
4068 : : vec<tree, va_gc> *origtypes)
4069 : : {
4070 : : /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
4071 : 48603411 : STRIP_TYPE_NOPS (function);
4072 : :
4073 : : /* Convert anything with function type to a pointer-to-function. */
4074 : 48603400 : if (TREE_CODE (function) == FUNCTION_DECL)
4075 : : {
4076 : : /* Implement type-directed function overloading for builtins.
4077 : : resolve_overloaded_builtin and targetm.resolve_overloaded_builtin
4078 : : handle all the type checking. The result is a complete expression
4079 : : that implements this function call. */
4080 : 48526394 : tree tem = resolve_overloaded_builtin (loc, function, params);
4081 : 48526394 : if (tem)
4082 : : return tem;
4083 : : }
4084 : 48518485 : return build_function_call_vec (loc, arg_loc, function, params, origtypes);
4085 : : }
4086 : :
4087 : : /* Helper for convert_arguments called to convert the VALue of argument
4088 : : number ARGNUM from ORIGTYPE to the corresponding parameter number
4089 : : PARMNUM and TYPE.
4090 : : PLOC is the location where the conversion is being performed.
4091 : : FUNCTION and FUNDECL are the same as in convert_arguments.
4092 : : VALTYPE is the original type of VAL before the conversion and,
4093 : : for EXCESS_PRECISION_EXPR, the operand of the expression.
4094 : : NPC is true if VAL represents the null pointer constant (VAL itself
4095 : : will have been folded to an integer constant).
4096 : : RNAME is the same as FUNCTION except in Objective C when it's
4097 : : the function selector.
4098 : : EXCESS_PRECISION is true when VAL was originally represented
4099 : : as EXCESS_PRECISION_EXPR.
4100 : : WARNOPT is the same as in convert_for_assignment. */
4101 : :
4102 : : static tree
4103 : 122363416 : convert_argument (location_t ploc, tree function, tree fundecl,
4104 : : tree type, tree origtype, tree val, tree valtype,
4105 : : bool npc, tree rname, int parmnum, int argnum,
4106 : : bool excess_precision, int warnopt)
4107 : : {
4108 : : /* Formal parm type is specified by a function prototype. */
4109 : :
4110 : 122363416 : if (type == error_mark_node || !COMPLETE_TYPE_P (type))
4111 : : {
4112 : 3 : error_at (ploc, "type of formal parameter %d is incomplete",
4113 : : parmnum + 1);
4114 : 3 : return error_mark_node;
4115 : : }
4116 : :
4117 : : /* Optionally warn about conversions that differ from the default
4118 : : conversions. */
4119 : 122363413 : if (warn_traditional_conversion || warn_traditional)
4120 : : {
4121 : 193 : if (INTEGRAL_TYPE_P (type)
4122 : 107 : && SCALAR_FLOAT_TYPE_P (valtype))
4123 : 19 : warning_at (ploc, OPT_Wtraditional_conversion,
4124 : : "passing argument %d of %qE as integer rather "
4125 : : "than floating due to prototype",
4126 : : argnum, rname);
4127 : 193 : if (INTEGRAL_TYPE_P (type)
4128 : 107 : && TREE_CODE (valtype) == COMPLEX_TYPE)
4129 : 5 : warning_at (ploc, OPT_Wtraditional_conversion,
4130 : : "passing argument %d of %qE as integer rather "
4131 : : "than complex due to prototype",
4132 : : argnum, rname);
4133 : 188 : else if (TREE_CODE (type) == COMPLEX_TYPE
4134 : 14 : && SCALAR_FLOAT_TYPE_P (valtype))
4135 : 7 : warning_at (ploc, OPT_Wtraditional_conversion,
4136 : : "passing argument %d of %qE as complex rather "
4137 : : "than floating due to prototype",
4138 : : argnum, rname);
4139 : 181 : else if (SCALAR_FLOAT_TYPE_P (type)
4140 : 71 : && INTEGRAL_TYPE_P (valtype))
4141 : 19 : warning_at (ploc, OPT_Wtraditional_conversion,
4142 : : "passing argument %d of %qE as floating rather "
4143 : : "than integer due to prototype",
4144 : : argnum, rname);
4145 : 162 : else if (TREE_CODE (type) == COMPLEX_TYPE
4146 : 7 : && INTEGRAL_TYPE_P (valtype))
4147 : 5 : warning_at (ploc, OPT_Wtraditional_conversion,
4148 : : "passing argument %d of %qE as complex rather "
4149 : : "than integer due to prototype",
4150 : : argnum, rname);
4151 : 157 : else if (SCALAR_FLOAT_TYPE_P (type)
4152 : 52 : && TREE_CODE (valtype) == COMPLEX_TYPE)
4153 : 7 : warning_at (ploc, OPT_Wtraditional_conversion,
4154 : : "passing argument %d of %qE as floating rather "
4155 : : "than complex due to prototype",
4156 : : argnum, rname);
4157 : : /* ??? At some point, messages should be written about
4158 : : conversions between complex types, but that's too messy
4159 : : to do now. */
4160 : 150 : else if (SCALAR_FLOAT_TYPE_P (type)
4161 : 45 : && SCALAR_FLOAT_TYPE_P (valtype))
4162 : : {
4163 : 45 : unsigned int formal_prec = TYPE_PRECISION (type);
4164 : :
4165 : : /* Warn if any argument is passed as `float',
4166 : : since without a prototype it would be `double'. */
4167 : 45 : if (formal_prec == TYPE_PRECISION (float_type_node)
4168 : 45 : && type != dfloat32_type_node)
4169 : 7 : warning_at (ploc, 0,
4170 : : "passing argument %d of %qE as %<float%> "
4171 : : "rather than %<double%> due to prototype",
4172 : : argnum, rname);
4173 : :
4174 : : /* Warn if mismatch between argument and prototype
4175 : : for decimal float types. Warn of conversions with
4176 : : binary float types and of precision narrowing due to
4177 : : prototype. */
4178 : 38 : else if (type != valtype
4179 : 32 : && (type == dfloat32_type_node
4180 : 22 : || type == dfloat64_type_node
4181 : 12 : || type == dfloat128_type_node
4182 : 2 : || valtype == dfloat32_type_node
4183 : 2 : || valtype == dfloat64_type_node
4184 : 2 : || valtype == dfloat128_type_node)
4185 : 38 : && (formal_prec
4186 : 30 : <= TYPE_PRECISION (valtype)
4187 : 14 : || (type == dfloat128_type_node
4188 : 10 : && (valtype
4189 : 10 : != dfloat64_type_node
4190 : 8 : && (valtype
4191 : : != dfloat32_type_node)))
4192 : 8 : || (type == dfloat64_type_node
4193 : 4 : && (valtype
4194 : : != dfloat32_type_node))))
4195 : 24 : warning_at (ploc, 0,
4196 : : "passing argument %d of %qE as %qT "
4197 : : "rather than %qT due to prototype",
4198 : : argnum, rname, type, valtype);
4199 : :
4200 : : }
4201 : : /* Detect integer changing in width or signedness.
4202 : : These warnings are only activated with
4203 : : -Wtraditional-conversion, not with -Wtraditional. */
4204 : 105 : else if (warn_traditional_conversion
4205 : 105 : && INTEGRAL_TYPE_P (type)
4206 : 102 : && INTEGRAL_TYPE_P (valtype))
4207 : : {
4208 : 83 : unsigned int formal_prec = TYPE_PRECISION (type);
4209 : 83 : tree would_have_been = default_conversion (val);
4210 : 83 : tree type1 = TREE_TYPE (would_have_been);
4211 : :
4212 : 83 : if (val == error_mark_node)
4213 : : /* VAL could have been of incomplete type. */;
4214 : 83 : else if (TREE_CODE (type) == ENUMERAL_TYPE
4215 : 83 : && (TYPE_MAIN_VARIANT (type)
4216 : 2 : == TYPE_MAIN_VARIANT (valtype)))
4217 : : /* No warning if function asks for enum
4218 : : and the actual arg is that enum type. */
4219 : : ;
4220 : 81 : else if (formal_prec != TYPE_PRECISION (type1))
4221 : 14 : warning_at (ploc, OPT_Wtraditional_conversion,
4222 : : "passing argument %d of %qE "
4223 : : "with different width due to prototype",
4224 : : argnum, rname);
4225 : 67 : else if (TYPE_UNSIGNED (type) == TYPE_UNSIGNED (type1))
4226 : : ;
4227 : : /* Don't complain if the formal parameter type
4228 : : is an enum, because we can't tell now whether
4229 : : the value was an enum--even the same enum. */
4230 : 32 : else if (TREE_CODE (type) == ENUMERAL_TYPE)
4231 : : ;
4232 : 32 : else if (TREE_CODE (val) == INTEGER_CST
4233 : 5 : && int_fits_type_p (val, type))
4234 : : /* Change in signedness doesn't matter
4235 : : if a constant value is unaffected. */
4236 : : ;
4237 : : /* If the value is extended from a narrower
4238 : : unsigned type, it doesn't matter whether we
4239 : : pass it as signed or unsigned; the value
4240 : : certainly is the same either way. */
4241 : 32 : else if (TYPE_PRECISION (valtype) < TYPE_PRECISION (type)
4242 : 32 : && TYPE_UNSIGNED (valtype))
4243 : : ;
4244 : 32 : else if (TYPE_UNSIGNED (type))
4245 : 17 : warning_at (ploc, OPT_Wtraditional_conversion,
4246 : : "passing argument %d of %qE "
4247 : : "as unsigned due to prototype",
4248 : : argnum, rname);
4249 : : else
4250 : 15 : warning_at (ploc, OPT_Wtraditional_conversion,
4251 : : "passing argument %d of %qE "
4252 : : "as signed due to prototype",
4253 : : argnum, rname);
4254 : : }
4255 : : }
4256 : :
4257 : : /* Possibly restore an EXCESS_PRECISION_EXPR for the
4258 : : sake of better warnings from convert_and_check. */
4259 : 122363413 : if (excess_precision)
4260 : 370 : val = build1 (EXCESS_PRECISION_EXPR, valtype, val);
4261 : :
4262 : 122363413 : tree parmval = convert_for_assignment (ploc, ploc, type,
4263 : : val, origtype, ic_argpass,
4264 : : npc, fundecl, function,
4265 : : parmnum + 1, warnopt);
4266 : 122363413 : return parmval;
4267 : : }
4268 : :
4269 : : /* Convert the argument expressions in the vector VALUES
4270 : : to the types in the list TYPE_ARG_TYPES (FNTYPE).
4271 : :
4272 : : If the list is exhausted, or when an element has NULL as its type,
4273 : : perform the default conversions.
4274 : :
4275 : : ORIGTYPES is the original types of the expressions in VALUES. This
4276 : : holds the type of enum values which have been converted to integral
4277 : : types. It may be NULL.
4278 : :
4279 : : FUNCTION is a tree for the called function. It is used only for
4280 : : error messages, where it is formatted with %qE.
4281 : :
4282 : : This is also where warnings about wrong number of args are generated.
4283 : :
4284 : : ARG_LOC are locations of function arguments (if any).
4285 : :
4286 : : Returns the actual number of arguments processed (which may be less
4287 : : than the length of VALUES in some error situations), or -1 on
4288 : : failure. */
4289 : :
4290 : : static int
4291 : 48603803 : convert_arguments (location_t loc, vec<location_t> arg_loc, tree fntype,
4292 : : vec<tree, va_gc> *values, vec<tree, va_gc> *origtypes,
4293 : : tree function, tree fundecl)
4294 : : {
4295 : 48603803 : tree typelist = TYPE_ARG_TYPES (fntype);
4296 : 48603803 : unsigned int parmnum;
4297 : 48603803 : bool error_args = false;
4298 : 48603803 : const bool type_generic = fundecl
4299 : 48603803 : && lookup_attribute ("type generic", TYPE_ATTRIBUTES (TREE_TYPE (fundecl)));
4300 : 48603803 : bool type_generic_remove_excess_precision = false;
4301 : 48603803 : bool type_generic_overflow_p = false;
4302 : 48603803 : bool type_generic_bit_query = false;
4303 : 48603803 : tree selector;
4304 : :
4305 : : /* Change pointer to function to the function itself for
4306 : : diagnostics. */
4307 : 48603803 : if (TREE_CODE (function) == ADDR_EXPR
4308 : 48603803 : && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL)
4309 : 48528935 : function = TREE_OPERAND (function, 0);
4310 : :
4311 : : /* Handle an ObjC selector specially for diagnostics. */
4312 : 48603803 : selector = objc_message_selector ();
4313 : :
4314 : : /* For a call to a built-in function declared without a prototype,
4315 : : set to the built-in function's argument list. */
4316 : 48603803 : tree builtin_typelist = NULL_TREE;
4317 : :
4318 : : /* For type-generic built-in functions, determine whether excess
4319 : : precision should be removed (classification) or not
4320 : : (comparison). */
4321 : 48603803 : if (fundecl
4322 : 48603803 : && fndecl_built_in_p (fundecl, BUILT_IN_NORMAL))
4323 : : {
4324 : 1383241 : built_in_function code = DECL_FUNCTION_CODE (fundecl);
4325 : 1383241 : if (C_DECL_BUILTIN_PROTOTYPE (fundecl))
4326 : : {
4327 : : /* For a call to a built-in function declared without a prototype
4328 : : use the types of the parameters of the internal built-in to
4329 : : match those of the arguments to. */
4330 : 681570 : if (tree bdecl = builtin_decl_explicit (code))
4331 : 681570 : builtin_typelist = TYPE_ARG_TYPES (TREE_TYPE (bdecl));
4332 : : }
4333 : :
4334 : : /* For type-generic built-in functions, determine whether excess
4335 : : precision should be removed (classification) or not
4336 : : (comparison). */
4337 : 1383241 : if (type_generic)
4338 : 60717 : switch (code)
4339 : : {
4340 : 5305 : case BUILT_IN_ISFINITE:
4341 : 5305 : case BUILT_IN_ISINF:
4342 : 5305 : case BUILT_IN_ISINF_SIGN:
4343 : 5305 : case BUILT_IN_ISNAN:
4344 : 5305 : case BUILT_IN_ISNORMAL:
4345 : 5305 : case BUILT_IN_ISSIGNALING:
4346 : 5305 : case BUILT_IN_FPCLASSIFY:
4347 : 5305 : type_generic_remove_excess_precision = true;
4348 : 5305 : break;
4349 : :
4350 : 21012 : case BUILT_IN_ADD_OVERFLOW_P:
4351 : 21012 : case BUILT_IN_SUB_OVERFLOW_P:
4352 : 21012 : case BUILT_IN_MUL_OVERFLOW_P:
4353 : : /* The last argument of these type-generic builtins
4354 : : should not be promoted. */
4355 : 21012 : type_generic_overflow_p = true;
4356 : 21012 : break;
4357 : :
4358 : 1278 : case BUILT_IN_CLZG:
4359 : 1278 : case BUILT_IN_CTZG:
4360 : 1278 : case BUILT_IN_CLRSBG:
4361 : 1278 : case BUILT_IN_FFSG:
4362 : 1278 : case BUILT_IN_PARITYG:
4363 : 1278 : case BUILT_IN_POPCOUNTG:
4364 : : /* The first argument of these type-generic builtins
4365 : : should not be promoted. */
4366 : 1278 : type_generic_bit_query = true;
4367 : 1278 : break;
4368 : :
4369 : : default:
4370 : : break;
4371 : : }
4372 : : }
4373 : :
4374 : : /* Scan the given expressions (VALUES) and types (TYPELIST), producing
4375 : : individual converted arguments. */
4376 : :
4377 : 48603803 : tree typetail, builtin_typetail, val;
4378 : 48603803 : for (typetail = typelist,
4379 : 48603803 : builtin_typetail = builtin_typelist,
4380 : 48603803 : parmnum = 0;
4381 : 171899748 : values && values->iterate (parmnum, &val);
4382 : : ++parmnum)
4383 : : {
4384 : : /* The type of the function parameter (if it was declared with one). */
4385 : 245657511 : tree type = typetail ? TREE_VALUE (typetail) : NULL_TREE;
4386 : : /* The type of the built-in function parameter (if the function
4387 : : is a built-in). Used to detect type incompatibilities in
4388 : : calls to built-ins declared without a prototype. */
4389 : 123295981 : tree builtin_type = (builtin_typetail
4390 : 124321706 : ? TREE_VALUE (builtin_typetail) : NULL_TREE);
4391 : : /* The original type of the argument being passed to the function. */
4392 : 123295981 : tree valtype = TREE_TYPE (val);
4393 : : /* The called function (or function selector in Objective C). */
4394 : 123295981 : tree rname = function;
4395 : 123295981 : int argnum = parmnum + 1;
4396 : 123295981 : const char *invalid_func_diag;
4397 : : /* Set for EXCESS_PRECISION_EXPR arguments. */
4398 : 123295981 : bool excess_precision = false;
4399 : : /* The value of the argument after conversion to the type
4400 : : of the function parameter it is passed to. */
4401 : 123295981 : tree parmval;
4402 : : /* Some __atomic_* builtins have additional hidden argument at
4403 : : position 0. */
4404 : 123295981 : location_t ploc
4405 : 123029928 : = !arg_loc.is_empty () && values->length () == arg_loc.length ()
4406 : 123029328 : ? expansion_point_location_if_in_system_header (arg_loc[parmnum])
4407 : 123295981 : : input_location;
4408 : :
4409 : 123295981 : if (type == void_type_node)
4410 : : {
4411 : 33 : auto_diagnostic_group d;
4412 : 33 : int num_expected = parmnum;
4413 : 33 : int num_actual = values->length ();
4414 : 33 : gcc_rich_location rich_loc (loc);
4415 : 33 : if (ploc != input_location)
4416 : 32 : rich_loc.add_range (ploc);
4417 : 33 : if (selector)
4418 : 0 : error_at (&rich_loc,
4419 : : "too many arguments to method %qE; expected %i, have %i",
4420 : : selector, num_expected, num_actual);
4421 : : else
4422 : 33 : error_at (&rich_loc,
4423 : : "too many arguments to function %qE; expected %i, have %i",
4424 : : function, num_expected, num_actual);
4425 : 33 : inform_declaration (fundecl, function);
4426 : 65 : return error_args ? -1 : (int) parmnum;
4427 : 33 : }
4428 : :
4429 : 123295948 : if (builtin_type == void_type_node)
4430 : : {
4431 : 12 : auto_diagnostic_group d;
4432 : 12 : if (warning_at (loc, OPT_Wbuiltin_declaration_mismatch,
4433 : : "too many arguments to built-in function %qE "
4434 : : "expecting %d", function, parmnum))
4435 : 12 : inform_declaration (fundecl, function);
4436 : 12 : builtin_typetail = NULL_TREE;
4437 : 12 : }
4438 : :
4439 : 89786 : if (!typetail && parmnum == 0 && !TYPE_NO_NAMED_ARGS_STDARG_P (fntype)
4440 : 123385617 : && !(fundecl && fndecl_built_in_p (fundecl)))
4441 : : {
4442 : 6962 : auto_diagnostic_group d;
4443 : 6962 : bool warned;
4444 : 6962 : if (selector)
4445 : 0 : warned = warning_at (loc, OPT_Wdeprecated_non_prototype,
4446 : : "ISO C23 does not allow arguments"
4447 : : " for method %qE declared without parameters",
4448 : : function);
4449 : : else
4450 : 6962 : warned = warning_at (loc, OPT_Wdeprecated_non_prototype,
4451 : : "ISO C23 does not allow arguments"
4452 : : " for function %qE declared without parameters",
4453 : : function);
4454 : 6962 : if (warned)
4455 : 4 : inform_declaration (fundecl, function);
4456 : 6962 : }
4457 : :
4458 : 123295948 : if (selector && argnum > 2)
4459 : : {
4460 : 0 : rname = selector;
4461 : 0 : argnum -= 2;
4462 : : }
4463 : :
4464 : : /* Determine if VAL is a null pointer constant before folding it. */
4465 : 123295948 : bool npc = null_pointer_constant_p (val);
4466 : :
4467 : : /* If there is excess precision and a prototype, convert once to
4468 : : the required type rather than converting via the semantic
4469 : : type. Likewise without a prototype a float value represented
4470 : : as long double should be converted once to double. But for
4471 : : type-generic classification functions excess precision must
4472 : : be removed here. */
4473 : 123295948 : if (TREE_CODE (val) == EXCESS_PRECISION_EXPR
4474 : 423 : && (type || !type_generic || !type_generic_remove_excess_precision))
4475 : : {
4476 : 403 : val = TREE_OPERAND (val, 0);
4477 : 403 : excess_precision = true;
4478 : : }
4479 : 123295948 : val = c_fully_fold (val, false, NULL);
4480 : 246591897 : STRIP_TYPE_NOPS (val);
4481 : :
4482 : 123295948 : val = require_complete_type (ploc, val);
4483 : :
4484 : : /* Some floating-point arguments must be promoted to double when
4485 : : no type is specified by a prototype. This applies to
4486 : : arguments of type float, and to architecture-specific types
4487 : : (ARM __fp16), but not to _FloatN or _FloatNx types. */
4488 : 123295948 : bool promote_float_arg = false;
4489 : 123295948 : if (type == NULL_TREE
4490 : 934451 : && TREE_CODE (valtype) == REAL_TYPE
4491 : 269617 : && (TYPE_PRECISION (valtype)
4492 : 269617 : <= TYPE_PRECISION (double_type_node))
4493 : 262335 : && TYPE_MAIN_VARIANT (valtype) != double_type_node
4494 : 131343 : && TYPE_MAIN_VARIANT (valtype) != long_double_type_node
4495 : 123427291 : && !DECIMAL_FLOAT_MODE_P (TYPE_MODE (valtype)))
4496 : : {
4497 : : /* Promote this argument, unless it has a _FloatN or
4498 : : _FloatNx type. */
4499 : 1027603 : promote_float_arg = true;
4500 : 1027603 : for (int i = 0; i < NUM_FLOATN_NX_TYPES; i++)
4501 : 900219 : if (TYPE_MAIN_VARIANT (valtype) == FLOATN_NX_TYPE_NODE (i))
4502 : : {
4503 : : promote_float_arg = false;
4504 : : break;
4505 : : }
4506 : : /* Don't promote __bf16 either. */
4507 : 130610 : if (TYPE_MAIN_VARIANT (valtype) == bfloat16_type_node)
4508 : 123165408 : promote_float_arg = false;
4509 : : }
4510 : :
4511 : 123295948 : if (type != NULL_TREE)
4512 : : {
4513 : 122361497 : tree origtype = (!origtypes) ? NULL_TREE : (*origtypes)[parmnum];
4514 : 122361497 : parmval = convert_argument (ploc, function, fundecl, type, origtype,
4515 : : val, valtype, npc, rname, parmnum, argnum,
4516 : : excess_precision, 0);
4517 : : }
4518 : 934451 : else if (promote_float_arg)
4519 : : {
4520 : 127314 : if (type_generic)
4521 : : parmval = val;
4522 : : else
4523 : : {
4524 : : /* Convert `float' to `double'. */
4525 : 124446 : if (warn_double_promotion && !c_inhibit_evaluation_warnings)
4526 : 6 : warning_at (ploc, OPT_Wdouble_promotion,
4527 : : "implicit conversion from %qT to %qT when passing "
4528 : : "argument to function",
4529 : : valtype, double_type_node);
4530 : 124446 : parmval = convert (double_type_node, val);
4531 : : }
4532 : : }
4533 : 807137 : else if ((excess_precision && !type_generic)
4534 : 807135 : || (type_generic_overflow_p && parmnum == 2)
4535 : 786127 : || (type_generic_bit_query && parmnum == 0))
4536 : : /* A "double" argument with excess precision being passed
4537 : : without a prototype or in variable arguments.
4538 : : The last argument of __builtin_*_overflow_p should not be
4539 : : promoted, similarly the first argument of
4540 : : __builtin_{clz,ctz,clrsb,ffs,parity,popcount}g. */
4541 : 22282 : parmval = convert (valtype, val);
4542 : 1569710 : else if ((invalid_func_diag =
4543 : 784855 : targetm.calls.invalid_arg_for_unprototyped_fn (typelist, fundecl, val)))
4544 : : {
4545 : 0 : error (invalid_func_diag);
4546 : 0 : return -1;
4547 : : }
4548 : 784855 : else if (TREE_CODE (val) == ADDR_EXPR && reject_gcc_builtin (val))
4549 : : {
4550 : : return -1;
4551 : : }
4552 : : else
4553 : : /* Convert `short' and `char' to full-size `int'. */
4554 : 784852 : parmval = default_conversion (val);
4555 : :
4556 : 123295945 : (*values)[parmnum] = parmval;
4557 : 123295945 : if (parmval == error_mark_node)
4558 : 105 : error_args = true;
4559 : :
4560 : 123295945 : if (!type && builtin_type && TREE_CODE (builtin_type) != VOID_TYPE)
4561 : : {
4562 : : /* For a call to a built-in function declared without a prototype,
4563 : : perform the conversions from the argument to the expected type
4564 : : but issue warnings rather than errors for any mismatches.
4565 : : Ignore the converted argument and use the PARMVAL obtained
4566 : : above by applying default conversions instead. */
4567 : 1919 : tree origtype = (!origtypes) ? NULL_TREE : (*origtypes)[parmnum];
4568 : 1919 : convert_argument (ploc, function, fundecl, builtin_type, origtype,
4569 : : val, valtype, npc, rname, parmnum, argnum,
4570 : : excess_precision,
4571 : : OPT_Wbuiltin_declaration_mismatch);
4572 : : }
4573 : :
4574 : 123295945 : if (typetail)
4575 : 122361497 : typetail = TREE_CHAIN (typetail);
4576 : :
4577 : 123295945 : if (builtin_typetail)
4578 : 1025708 : builtin_typetail = TREE_CHAIN (builtin_typetail);
4579 : : }
4580 : :
4581 : 85803511 : gcc_assert (parmnum == vec_safe_length (values));
4582 : :
4583 : 96879334 : if (typetail != NULL_TREE && TREE_VALUE (typetail) != void_type_node)
4584 : : {
4585 : : /* Not enough args.
4586 : : Determine minimum number of arguments required. */
4587 : : int min_expected_num = 0;
4588 : 231 : bool at_least_p = false;
4589 : : tree iter = typelist;
4590 : 386 : while (true)
4591 : : {
4592 : 231 : if (!iter)
4593 : : {
4594 : : /* Variadic arguments; stop iterating. */
4595 : : at_least_p = true;
4596 : : break;
4597 : : }
4598 : 222 : if (iter == void_list_node)
4599 : : /* End of arguments; stop iterating. */
4600 : : break;
4601 : 155 : ++min_expected_num;
4602 : 155 : iter = TREE_CHAIN (iter);
4603 : : }
4604 : 76 : auto_diagnostic_group d;
4605 : 76 : int actual_num = vec_safe_length (values);
4606 : 143 : error_at (loc,
4607 : : at_least_p
4608 : : ? G_("too few arguments to function %qE; expected at least %i, have %i")
4609 : : : G_("too few arguments to function %qE; expected %i, have %i"),
4610 : : function, min_expected_num, actual_num);
4611 : 76 : inform_declaration (fundecl, function);
4612 : 76 : return -1;
4613 : 76 : }
4614 : :
4615 : 49249619 : if (builtin_typetail && TREE_VALUE (builtin_typetail) != void_type_node)
4616 : : {
4617 : : unsigned nargs = parmnum;
4618 : 616 : for (tree t = builtin_typetail; t; t = TREE_CHAIN (t))
4619 : 428 : ++nargs;
4620 : :
4621 : 188 : auto_diagnostic_group d;
4622 : 188 : if (warning_at (loc, OPT_Wbuiltin_declaration_mismatch,
4623 : : "too few arguments to built-in function %qE "
4624 : : "expecting %u", function, nargs - 1))
4625 : 173 : inform_declaration (fundecl, function);
4626 : 188 : }
4627 : :
4628 : 48603691 : return error_args ? -1 : (int) parmnum;
4629 : : }
4630 : :
4631 : : /* This is the entry point used by the parser to build unary operators
4632 : : in the input. CODE, a tree_code, specifies the unary operator, and
4633 : : ARG is the operand. For unary plus, the C parser currently uses
4634 : : CONVERT_EXPR for code.
4635 : :
4636 : : LOC is the location to use for the tree generated.
4637 : : */
4638 : :
4639 : : struct c_expr
4640 : 7963957 : parser_build_unary_op (location_t loc, enum tree_code code, struct c_expr arg)
4641 : : {
4642 : 7963957 : struct c_expr result;
4643 : :
4644 : 7963957 : result.original_code = code;
4645 : 7963957 : result.original_type = NULL;
4646 : 7963957 : result.m_decimal = 0;
4647 : :
4648 : 7963957 : if (reject_gcc_builtin (arg.value))
4649 : : {
4650 : 2 : result.value = error_mark_node;
4651 : : }
4652 : : else
4653 : : {
4654 : 7963955 : result.value = build_unary_op (loc, code, arg.value, false);
4655 : :
4656 : 7963955 : if (TREE_OVERFLOW_P (result.value) && !TREE_OVERFLOW_P (arg.value))
4657 : 5 : overflow_warning (loc, result.value, arg.value);
4658 : : }
4659 : :
4660 : : /* We are typically called when parsing a prefix token at LOC acting on
4661 : : ARG. Reflect this by updating the source range of the result to
4662 : : start at LOC and end at the end of ARG. */
4663 : 7963957 : set_c_expr_source_range (&result,
4664 : : loc, arg.get_finish ());
4665 : :
4666 : 7963957 : return result;
4667 : : }
4668 : :
4669 : : /* Returns true if TYPE is a character type, *not* including wchar_t. */
4670 : :
4671 : : bool
4672 : 1240482 : char_type_p (tree type)
4673 : : {
4674 : 1240482 : return (type == char_type_node
4675 : 956411 : || type == unsigned_char_type_node
4676 : 922463 : || type == signed_char_type_node
4677 : 921624 : || type == char16_type_node
4678 : 1948505 : || type == char32_type_node);
4679 : : }
4680 : :
4681 : : /* This is the entry point used by the parser to build binary operators
4682 : : in the input. CODE, a tree_code, specifies the binary operator, and
4683 : : ARG1 and ARG2 are the operands. In addition to constructing the
4684 : : expression, we check for operands that were written with other binary
4685 : : operators in a way that is likely to confuse the user.
4686 : :
4687 : : LOCATION is the location of the binary operator. */
4688 : :
4689 : : struct c_expr
4690 : 9140356 : parser_build_binary_op (location_t location, enum tree_code code,
4691 : : struct c_expr arg1, struct c_expr arg2)
4692 : : {
4693 : 9140356 : struct c_expr result;
4694 : 9140356 : result.m_decimal = 0;
4695 : :
4696 : 9140356 : enum tree_code code1 = arg1.original_code;
4697 : 9140356 : enum tree_code code2 = arg2.original_code;
4698 : 9140356 : tree type1 = (arg1.original_type
4699 : 9140356 : ? arg1.original_type
4700 : 5878317 : : TREE_TYPE (arg1.value));
4701 : 9140356 : tree type2 = (arg2.original_type
4702 : 9140356 : ? arg2.original_type
4703 : 6747520 : : TREE_TYPE (arg2.value));
4704 : :
4705 : 9140356 : result.value = build_binary_op (location, code,
4706 : : arg1.value, arg2.value, true);
4707 : 9140355 : result.original_code = code;
4708 : 9140355 : result.original_type = NULL;
4709 : 9140355 : result.m_decimal = 0;
4710 : :
4711 : 9140355 : if (TREE_CODE (result.value) == ERROR_MARK)
4712 : : {
4713 : 1295 : set_c_expr_source_range (&result,
4714 : : arg1.get_start (),
4715 : : arg2.get_finish ());
4716 : 1295 : return result;
4717 : : }
4718 : :
4719 : 9139060 : if (location != UNKNOWN_LOCATION)
4720 : 9139060 : protected_set_expr_location (result.value, location);
4721 : :
4722 : 9139060 : set_c_expr_source_range (&result,
4723 : : arg1.get_start (),
4724 : : arg2.get_finish ());
4725 : :
4726 : : /* Check for cases such as x+y<<z which users are likely
4727 : : to misinterpret. */
4728 : 9139060 : if (warn_parentheses)
4729 : 1999925 : warn_about_parentheses (location, code, code1, arg1.value, code2,
4730 : : arg2.value);
4731 : :
4732 : 9139060 : if (warn_logical_op)
4733 : 340 : warn_logical_operator (location, code, TREE_TYPE (result.value),
4734 : : code1, arg1.value, code2, arg2.value);
4735 : :
4736 : 9139060 : if (warn_tautological_compare)
4737 : : {
4738 : 1998438 : tree lhs = arg1.value;
4739 : 1998438 : tree rhs = arg2.value;
4740 : 1998438 : if (TREE_CODE (lhs) == C_MAYBE_CONST_EXPR)
4741 : : {
4742 : 2 : if (C_MAYBE_CONST_EXPR_PRE (lhs) != NULL_TREE
4743 : 2 : && TREE_SIDE_EFFECTS (C_MAYBE_CONST_EXPR_PRE (lhs)))
4744 : : lhs = NULL_TREE;
4745 : : else
4746 : 2 : lhs = C_MAYBE_CONST_EXPR_EXPR (lhs);
4747 : : }
4748 : 1998438 : if (TREE_CODE (rhs) == C_MAYBE_CONST_EXPR)
4749 : : {
4750 : 12 : if (C_MAYBE_CONST_EXPR_PRE (rhs) != NULL_TREE
4751 : 12 : && TREE_SIDE_EFFECTS (C_MAYBE_CONST_EXPR_PRE (rhs)))
4752 : : rhs = NULL_TREE;
4753 : : else
4754 : 12 : rhs = C_MAYBE_CONST_EXPR_EXPR (rhs);
4755 : : }
4756 : 1998438 : if (lhs != NULL_TREE && rhs != NULL_TREE)
4757 : 1998438 : warn_tautological_cmp (location, code, lhs, rhs);
4758 : : }
4759 : :
4760 : 9139060 : if (warn_logical_not_paren
4761 : 1998521 : && TREE_CODE_CLASS (code) == tcc_comparison
4762 : 403974 : && code1 == TRUTH_NOT_EXPR
4763 : 403974 : && code2 != TRUTH_NOT_EXPR
4764 : : /* Avoid warning for !!x == y. */
4765 : 9139186 : && (TREE_CODE (arg1.value) != NE_EXPR
4766 : 19 : || !integer_zerop (TREE_OPERAND (arg1.value, 1))))
4767 : : {
4768 : : /* Avoid warning for !b == y where b has _Bool type. */
4769 : 107 : tree t = integer_zero_node;
4770 : 107 : if (TREE_CODE (arg1.value) == EQ_EXPR
4771 : 98 : && integer_zerop (TREE_OPERAND (arg1.value, 1))
4772 : 205 : && TREE_TYPE (TREE_OPERAND (arg1.value, 0)) == integer_type_node)
4773 : : {
4774 : 90 : t = TREE_OPERAND (arg1.value, 0);
4775 : 199 : do
4776 : : {
4777 : 199 : if (TREE_TYPE (t) != integer_type_node)
4778 : : break;
4779 : 180 : if (TREE_CODE (t) == C_MAYBE_CONST_EXPR)
4780 : 90 : t = C_MAYBE_CONST_EXPR_EXPR (t);
4781 : 90 : else if (CONVERT_EXPR_P (t))
4782 : 19 : t = TREE_OPERAND (t, 0);
4783 : : else
4784 : : break;
4785 : : }
4786 : : while (1);
4787 : : }
4788 : 107 : if (!C_BOOLEAN_TYPE_P (TREE_TYPE (t)))
4789 : 88 : warn_logical_not_parentheses (location, code, arg1.value, arg2.value);
4790 : : }
4791 : :
4792 : : /* Warn about comparisons against string literals, with the exception
4793 : : of testing for equality or inequality of a string literal with NULL. */
4794 : 9139060 : if (code == EQ_EXPR || code == NE_EXPR)
4795 : : {
4796 : 1146124 : if ((code1 == STRING_CST
4797 : 16 : && !integer_zerop (tree_strip_nop_conversions (arg2.value)))
4798 : 1146135 : || (code2 == STRING_CST
4799 : 20 : && !integer_zerop (tree_strip_nop_conversions (arg1.value))))
4800 : 17 : warning_at (location, OPT_Waddress,
4801 : : "comparison with string literal results in unspecified behavior");
4802 : : /* Warn for ptr == '\0', it's likely that it should've been ptr[0]. */
4803 : 1146124 : if (POINTER_TYPE_P (type1)
4804 : 90138 : && null_pointer_constant_p (arg2.value)
4805 : 1166910 : && char_type_p (type2))
4806 : : {
4807 : 18 : auto_diagnostic_group d;
4808 : 18 : if (warning_at (location, OPT_Wpointer_compare,
4809 : : "comparison between pointer and zero character "
4810 : : "constant"))
4811 : 10 : inform (arg1.get_start (),
4812 : : "did you mean to dereference the pointer?");
4813 : 18 : }
4814 : 1146106 : else if (POINTER_TYPE_P (type2)
4815 : 87477 : && null_pointer_constant_p (arg1.value)
4816 : 1146368 : && char_type_p (type1))
4817 : : {
4818 : 10 : auto_diagnostic_group d;
4819 : 10 : if (warning_at (location, OPT_Wpointer_compare,
4820 : : "comparison between pointer and zero character "
4821 : : "constant"))
4822 : 10 : inform (arg2.get_start (),
4823 : : "did you mean to dereference the pointer?");
4824 : 10 : }
4825 : : }
4826 : 7992936 : else if (TREE_CODE_CLASS (code) == tcc_comparison
4827 : 971948 : && (code1 == STRING_CST || code2 == STRING_CST))
4828 : 0 : warning_at (location, OPT_Waddress,
4829 : : "comparison with string literal results in unspecified "
4830 : : "behavior");
4831 : :
4832 : 9139060 : if (warn_zero_as_null_pointer_constant
4833 : 18 : && c_inhibit_evaluation_warnings == 0
4834 : 18 : && TREE_CODE_CLASS (code) == tcc_comparison)
4835 : : {
4836 : 18 : if ((TREE_CODE (type1) == POINTER_TYPE
4837 : 14 : || TREE_CODE (type1) == NULLPTR_TYPE)
4838 : 6 : && TREE_CODE (type2) == INTEGER_TYPE
4839 : 24 : && null_pointer_constant_p (arg2.value))
4840 : 6 : warning_at (arg2.get_location(), OPT_Wzero_as_null_pointer_constant,
4841 : : "zero as null pointer constant");
4842 : :
4843 : 18 : if ((TREE_CODE (type2) == POINTER_TYPE
4844 : 12 : || TREE_CODE (type2) == NULLPTR_TYPE)
4845 : 8 : && TREE_CODE (type1) == INTEGER_TYPE
4846 : 26 : && null_pointer_constant_p (arg1.value))
4847 : 8 : warning_at (arg1.get_location(), OPT_Wzero_as_null_pointer_constant,
4848 : : "zero as null pointer constant");
4849 : : }
4850 : :
4851 : 9139060 : if (warn_array_compare
4852 : 1998276 : && TREE_CODE_CLASS (code) == tcc_comparison
4853 : 403759 : && TREE_CODE (type1) == ARRAY_TYPE
4854 : 38 : && TREE_CODE (type2) == ARRAY_TYPE)
4855 : 15 : do_warn_array_compare (location, code, arg1.value, arg2.value);
4856 : :
4857 : 2150711 : if (TREE_OVERFLOW_P (result.value)
4858 : 290 : && !TREE_OVERFLOW_P (arg1.value)
4859 : 9139343 : && !TREE_OVERFLOW_P (arg2.value))
4860 : 240 : overflow_warning (location, result.value);
4861 : :
4862 : : /* Warn about comparisons of different enum types. */
4863 : 9139059 : if (warn_enum_compare
4864 : 2018129 : && TREE_CODE_CLASS (code) == tcc_comparison
4865 : 408172 : && TREE_CODE (type1) == ENUMERAL_TYPE
4866 : 6966 : && TREE_CODE (type2) == ENUMERAL_TYPE
4867 : 9145963 : && TYPE_MAIN_VARIANT (type1) != TYPE_MAIN_VARIANT (type2))
4868 : 2 : warning_at (location, OPT_Wenum_compare,
4869 : : "comparison between %qT and %qT",
4870 : : type1, type2);
4871 : :
4872 : 9139059 : if (warn_xor_used_as_pow
4873 : 9139059 : && code == BIT_XOR_EXPR
4874 : 75013 : && arg1.m_decimal
4875 : 722 : && arg2.m_decimal)
4876 : 427 : check_for_xor_used_as_pow (arg1.get_location (), arg1.value,
4877 : : location,
4878 : : arg2.get_location (), arg2.value);
4879 : :
4880 : : return result;
4881 : : }
4882 : :
4883 : : /* Return a tree for the difference of pointers OP0 and OP1.
4884 : : The resulting tree has type ptrdiff_t. If POINTER_SUBTRACT sanitization is
4885 : : enabled, assign to INSTRUMENT_EXPR call to libsanitizer. */
4886 : :
4887 : : static tree
4888 : 3607 : pointer_diff (location_t loc, tree op0, tree op1, tree *instrument_expr)
4889 : : {
4890 : 3607 : tree restype = ptrdiff_type_node;
4891 : 3607 : tree result, inttype;
4892 : :
4893 : 3607 : addr_space_t as0 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (op0)));
4894 : 3607 : addr_space_t as1 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (op1)));
4895 : 3607 : tree target_type = TREE_TYPE (TREE_TYPE (op0));
4896 : 3607 : tree orig_op0 = op0;
4897 : 3607 : tree orig_op1 = op1;
4898 : :
4899 : : /* If the operands point into different address spaces, we need to
4900 : : explicitly convert them to pointers into the common address space
4901 : : before we can subtract the numerical address values. */
4902 : 3607 : if (as0 != as1)
4903 : : {
4904 : 0 : addr_space_t as_common;
4905 : 0 : tree common_type;
4906 : :
4907 : : /* Determine the common superset address space. This is guaranteed
4908 : : to exist because the caller verified that comp_target_types
4909 : : returned non-zero. */
4910 : 0 : if (!addr_space_superset (as0, as1, &as_common))
4911 : 0 : gcc_unreachable ();
4912 : :
4913 : 0 : common_type = common_pointer_type (TREE_TYPE (op0), TREE_TYPE (op1));
4914 : 0 : op0 = convert (common_type, op0);
4915 : 0 : op1 = convert (common_type, op1);
4916 : : }
4917 : :
4918 : : /* Determine integer type result of the subtraction. This will usually
4919 : : be the same as the result type (ptrdiff_t), but may need to be a wider
4920 : : type if pointers for the address space are wider than ptrdiff_t. */
4921 : 3607 : if (TYPE_PRECISION (restype) < TYPE_PRECISION (TREE_TYPE (op0)))
4922 : 0 : inttype = c_common_type_for_size (TYPE_PRECISION (TREE_TYPE (op0)), 0);
4923 : : else
4924 : : inttype = restype;
4925 : :
4926 : 3607 : if (VOID_TYPE_P (target_type))
4927 : 135 : pedwarn (loc, OPT_Wpointer_arith,
4928 : : "pointer of type %<void *%> used in subtraction");
4929 : 3607 : if (TREE_CODE (target_type) == FUNCTION_TYPE)
4930 : 4 : pedwarn (loc, OPT_Wpointer_arith,
4931 : : "pointer to a function used in subtraction");
4932 : :
4933 : 3607 : if (current_function_decl != NULL_TREE
4934 : 3607 : && sanitize_flags_p (SANITIZE_POINTER_SUBTRACT))
4935 : : {
4936 : 70 : op0 = save_expr (c_fully_fold (op0, false, NULL));
4937 : 70 : op1 = save_expr (c_fully_fold (op1, false, NULL));
4938 : :
4939 : 70 : tree tt = builtin_decl_explicit (BUILT_IN_ASAN_POINTER_SUBTRACT);
4940 : 70 : *instrument_expr = build_call_expr_loc (loc, tt, 2, op0, op1);
4941 : : }
4942 : :
4943 : : /* First do the subtraction, then build the divide operator
4944 : : and only convert at the very end.
4945 : : Do not do default conversions in case restype is a short type. */
4946 : :
4947 : : /* POINTER_DIFF_EXPR requires a signed integer type of the same size as
4948 : : pointers. If some platform cannot provide that, or has a larger
4949 : : ptrdiff_type to support differences larger than half the address
4950 : : space, cast the pointers to some larger integer type and do the
4951 : : computations in that type. */
4952 : 3607 : if (TYPE_PRECISION (inttype) > TYPE_PRECISION (TREE_TYPE (op0)))
4953 : 0 : op0 = build_binary_op (loc, MINUS_EXPR, convert (inttype, op0),
4954 : : convert (inttype, op1), false);
4955 : : else
4956 : : {
4957 : : /* Cast away qualifiers. */
4958 : 3607 : op0 = convert (c_common_type (TREE_TYPE (op0), TREE_TYPE (op0)), op0);
4959 : 3607 : op1 = convert (c_common_type (TREE_TYPE (op1), TREE_TYPE (op1)), op1);
4960 : 3607 : op0 = build2_loc (loc, POINTER_DIFF_EXPR, inttype, op0, op1);
4961 : : }
4962 : :
4963 : : /* This generates an error if op1 is pointer to incomplete type. */
4964 : 3607 : if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (orig_op1))))
4965 : 4 : error_at (loc, "arithmetic on pointer to an incomplete type");
4966 : 3603 : else if (verify_type_context (loc, TCTX_POINTER_ARITH,
4967 : 3603 : TREE_TYPE (TREE_TYPE (orig_op0))))
4968 : 7206 : verify_type_context (loc, TCTX_POINTER_ARITH,
4969 : 3603 : TREE_TYPE (TREE_TYPE (orig_op1)));
4970 : :
4971 : 3607 : op1 = c_size_in_bytes (target_type);
4972 : :
4973 : 3607 : if (pointer_to_zero_sized_aggr_p (TREE_TYPE (orig_op1)))
4974 : 4 : error_at (loc, "arithmetic on pointer to an empty aggregate");
4975 : :
4976 : : /* Divide by the size, in easiest possible way. */
4977 : 3607 : result = fold_build2_loc (loc, EXACT_DIV_EXPR, inttype,
4978 : : op0, convert (inttype, op1));
4979 : :
4980 : : /* Convert to final result type if necessary. */
4981 : 3607 : return convert (restype, result);
4982 : : }
4983 : :
4984 : : /* Expand atomic compound assignments into an appropriate sequence as
4985 : : specified by the C11 standard section 6.5.16.2.
4986 : :
4987 : : _Atomic T1 E1
4988 : : T2 E2
4989 : : E1 op= E2
4990 : :
4991 : : This sequence is used for all types for which these operations are
4992 : : supported.
4993 : :
4994 : : In addition, built-in versions of the 'fe' prefixed routines may
4995 : : need to be invoked for floating point (real, complex or vector) when
4996 : : floating-point exceptions are supported. See 6.5.16.2 footnote 113.
4997 : :
4998 : : T1 newval;
4999 : : T1 old;
5000 : : T1 *addr
5001 : : T2 val
5002 : : fenv_t fenv
5003 : :
5004 : : addr = &E1;
5005 : : val = (E2);
5006 : : __atomic_load (addr, &old, SEQ_CST);
5007 : : feholdexcept (&fenv);
5008 : : loop:
5009 : : newval = old op val;
5010 : : if (__atomic_compare_exchange_strong (addr, &old, &newval, SEQ_CST,
5011 : : SEQ_CST))
5012 : : goto done;
5013 : : feclearexcept (FE_ALL_EXCEPT);
5014 : : goto loop:
5015 : : done:
5016 : : feupdateenv (&fenv);
5017 : :
5018 : : The compiler will issue the __atomic_fetch_* built-in when possible,
5019 : : otherwise it will generate the generic form of the atomic operations.
5020 : : This requires temp(s) and has their address taken. The atomic processing
5021 : : is smart enough to figure out when the size of an object can utilize
5022 : : a lock-free version, and convert the built-in call to the appropriate
5023 : : lock-free routine. The optimizers will then dispose of any temps that
5024 : : are no longer required, and lock-free implementations are utilized as
5025 : : long as there is target support for the required size.
5026 : :
5027 : : If the operator is NOP_EXPR, then this is a simple assignment, and
5028 : : an __atomic_store is issued to perform the assignment rather than
5029 : : the above loop. */
5030 : :
5031 : : /* Build an atomic assignment at LOC, expanding into the proper
5032 : : sequence to store LHS MODIFYCODE= RHS. Return a value representing
5033 : : the result of the operation, unless RETURN_OLD_P, in which case
5034 : : return the old value of LHS (this is only for postincrement and
5035 : : postdecrement). */
5036 : :
5037 : : static tree
5038 : 30283 : build_atomic_assign (location_t loc, tree lhs, enum tree_code modifycode,
5039 : : tree rhs, bool return_old_p)
5040 : : {
5041 : 30283 : tree fndecl, func_call;
5042 : 30283 : vec<tree, va_gc> *params;
5043 : 30283 : tree val, nonatomic_lhs_type, nonatomic_rhs_type, newval, newval_addr;
5044 : 30283 : tree old, old_addr;
5045 : 30283 : tree compound_stmt = NULL_TREE;
5046 : 30283 : tree stmt, goto_stmt;
5047 : 30283 : tree loop_label, loop_decl, done_label, done_decl;
5048 : :
5049 : 30283 : tree lhs_type = TREE_TYPE (lhs);
5050 : 30283 : tree lhs_addr = build_unary_op (loc, ADDR_EXPR, lhs, false);
5051 : 30283 : tree seq_cst = build_int_cst (integer_type_node, MEMMODEL_SEQ_CST);
5052 : 30283 : tree rhs_semantic_type = TREE_TYPE (rhs);
5053 : 30283 : tree nonatomic_rhs_semantic_type;
5054 : 30283 : tree rhs_type;
5055 : :
5056 : 30283 : gcc_assert (TYPE_ATOMIC (lhs_type));
5057 : :
5058 : 30283 : if (return_old_p)
5059 : 2299 : gcc_assert (modifycode == PLUS_EXPR || modifycode == MINUS_EXPR);
5060 : :
5061 : : /* Allocate enough vector items for a compare_exchange. */
5062 : 30283 : vec_alloc (params, 6);
5063 : :
5064 : : /* Create a compound statement to hold the sequence of statements
5065 : : with a loop. */
5066 : 30283 : if (modifycode != NOP_EXPR)
5067 : : {
5068 : 19910 : compound_stmt = c_begin_compound_stmt (false);
5069 : :
5070 : : /* For consistency with build_modify_expr on non-_Atomic,
5071 : : mark the lhs as read. Also, it would be very hard to match
5072 : : such expressions in mark_exp_read. */
5073 : 19910 : mark_exp_read (lhs);
5074 : : }
5075 : :
5076 : : /* Remove any excess precision (which is only present here in the
5077 : : case of compound assignments). */
5078 : 30283 : if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
5079 : : {
5080 : 0 : gcc_assert (modifycode != NOP_EXPR);
5081 : 0 : rhs = TREE_OPERAND (rhs, 0);
5082 : : }
5083 : 30283 : rhs_type = TREE_TYPE (rhs);
5084 : :
5085 : : /* Fold the RHS if it hasn't already been folded. */
5086 : 30283 : if (modifycode != NOP_EXPR)
5087 : 19910 : rhs = c_fully_fold (rhs, false, NULL);
5088 : :
5089 : : /* Remove the qualifiers for the rest of the expressions and create
5090 : : the VAL temp variable to hold the RHS. */
5091 : 30283 : nonatomic_lhs_type = build_qualified_type (lhs_type, TYPE_UNQUALIFIED);
5092 : 30283 : nonatomic_rhs_type = build_qualified_type (rhs_type, TYPE_UNQUALIFIED);
5093 : 30283 : nonatomic_rhs_semantic_type = build_qualified_type (rhs_semantic_type,
5094 : : TYPE_UNQUALIFIED);
5095 : 30283 : val = create_tmp_var_raw (nonatomic_rhs_type);
5096 : 30283 : TREE_ADDRESSABLE (val) = 1;
5097 : 30283 : suppress_warning (val);
5098 : 30283 : rhs = build4 (TARGET_EXPR, nonatomic_rhs_type, val, rhs, NULL_TREE,
5099 : : NULL_TREE);
5100 : 30283 : TREE_SIDE_EFFECTS (rhs) = 1;
5101 : 30283 : SET_EXPR_LOCATION (rhs, loc);
5102 : 30283 : if (modifycode != NOP_EXPR)
5103 : 19910 : add_stmt (rhs);
5104 : :
5105 : : /* NOP_EXPR indicates it's a straight store of the RHS. Simply issue
5106 : : an atomic_store. */
5107 : 30283 : if (modifycode == NOP_EXPR)
5108 : : {
5109 : 10373 : compound_stmt = rhs;
5110 : : /* Build __atomic_store (&lhs, &val, SEQ_CST) */
5111 : 10373 : rhs = build_unary_op (loc, ADDR_EXPR, val, false);
5112 : 10373 : fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_STORE);
5113 : 10373 : params->quick_push (lhs_addr);
5114 : 10373 : params->quick_push (rhs);
5115 : 10373 : params->quick_push (seq_cst);
5116 : 10373 : func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
5117 : :
5118 : 10373 : compound_stmt = build2 (COMPOUND_EXPR, void_type_node,
5119 : : compound_stmt, func_call);
5120 : :
5121 : : /* VAL is the value which was stored, return a COMPOUND_STMT of
5122 : : the statement and that value. */
5123 : 10373 : return build2 (COMPOUND_EXPR, nonatomic_lhs_type, compound_stmt, val);
5124 : : }
5125 : :
5126 : : /* Attempt to implement the atomic operation as an __atomic_fetch_* or
5127 : : __atomic_*_fetch built-in rather than a CAS loop. atomic_bool type
5128 : : isn't applicable for such builtins. ??? Do we want to handle enums? */
5129 : 19910 : if ((TREE_CODE (lhs_type) == INTEGER_TYPE || POINTER_TYPE_P (lhs_type))
5130 : 13941 : && TREE_CODE (rhs_type) == INTEGER_TYPE)
5131 : : {
5132 : 11713 : built_in_function fncode;
5133 : 11713 : switch (modifycode)
5134 : : {
5135 : 3075 : case PLUS_EXPR:
5136 : 3075 : case POINTER_PLUS_EXPR:
5137 : 2124 : fncode = (return_old_p
5138 : 3075 : ? BUILT_IN_ATOMIC_FETCH_ADD_N
5139 : : : BUILT_IN_ATOMIC_ADD_FETCH_N);
5140 : : break;
5141 : 2889 : case MINUS_EXPR:
5142 : 2094 : fncode = (return_old_p
5143 : 2889 : ? BUILT_IN_ATOMIC_FETCH_SUB_N
5144 : : : BUILT_IN_ATOMIC_SUB_FETCH_N);
5145 : : break;
5146 : 609 : case BIT_AND_EXPR:
5147 : 609 : fncode = (return_old_p
5148 : 609 : ? BUILT_IN_ATOMIC_FETCH_AND_N
5149 : : : BUILT_IN_ATOMIC_AND_FETCH_N);
5150 : : break;
5151 : 609 : case BIT_IOR_EXPR:
5152 : 609 : fncode = (return_old_p
5153 : 609 : ? BUILT_IN_ATOMIC_FETCH_OR_N
5154 : : : BUILT_IN_ATOMIC_OR_FETCH_N);
5155 : : break;
5156 : 609 : case BIT_XOR_EXPR:
5157 : 609 : fncode = (return_old_p
5158 : 609 : ? BUILT_IN_ATOMIC_FETCH_XOR_N
5159 : : : BUILT_IN_ATOMIC_XOR_FETCH_N);
5160 : : break;
5161 : 3922 : default:
5162 : 3922 : goto cas_loop;
5163 : : }
5164 : :
5165 : : /* We can only use "_1" through "_16" variants of the atomic fetch
5166 : : built-ins. */
5167 : 7791 : unsigned HOST_WIDE_INT size = tree_to_uhwi (TYPE_SIZE_UNIT (lhs_type));
5168 : 7791 : if (size != 1 && size != 2 && size != 4 && size != 8 && size != 16)
5169 : 0 : goto cas_loop;
5170 : :
5171 : : /* If this is a pointer type, we need to multiply by the size of
5172 : : the pointer target type. */
5173 : 7791 : if (POINTER_TYPE_P (lhs_type))
5174 : : {
5175 : 1018 : if (!COMPLETE_TYPE_P (TREE_TYPE (lhs_type))
5176 : : /* ??? This would introduce -Wdiscarded-qualifiers
5177 : : warning: __atomic_fetch_* expect volatile void *
5178 : : type as the first argument. (Assignments between
5179 : : atomic and non-atomic objects are OK.) */
5180 : 1018 : || TYPE_RESTRICT (lhs_type))
5181 : 17 : goto cas_loop;
5182 : 1001 : tree sz = TYPE_SIZE_UNIT (TREE_TYPE (lhs_type));
5183 : 1001 : rhs = fold_build2_loc (loc, MULT_EXPR, ptrdiff_type_node,
5184 : : convert (ptrdiff_type_node, rhs),
5185 : : convert (ptrdiff_type_node, sz));
5186 : : }
5187 : :
5188 : : /* Build __atomic_fetch_* (&lhs, &val, SEQ_CST), or
5189 : : __atomic_*_fetch (&lhs, &val, SEQ_CST). */
5190 : 7774 : fndecl = builtin_decl_explicit (fncode);
5191 : 7774 : params->quick_push (lhs_addr);
5192 : 7774 : params->quick_push (rhs);
5193 : 7774 : params->quick_push (seq_cst);
5194 : 7774 : func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
5195 : :
5196 : 7774 : newval = create_tmp_var_raw (nonatomic_lhs_type);
5197 : 7774 : TREE_ADDRESSABLE (newval) = 1;
5198 : 7774 : suppress_warning (newval);
5199 : 7774 : rhs = build4 (TARGET_EXPR, nonatomic_lhs_type, newval, func_call,
5200 : : NULL_TREE, NULL_TREE);
5201 : 7774 : SET_EXPR_LOCATION (rhs, loc);
5202 : 7774 : add_stmt (rhs);
5203 : :
5204 : : /* Finish the compound statement. */
5205 : 7774 : compound_stmt = c_end_compound_stmt (loc, compound_stmt, false);
5206 : :
5207 : : /* NEWVAL is the value which was stored, return a COMPOUND_STMT of
5208 : : the statement and that value. */
5209 : 7774 : return build2 (COMPOUND_EXPR, nonatomic_lhs_type, compound_stmt, newval);
5210 : : }
5211 : :
5212 : 8197 : cas_loop:
5213 : : /* Create the variables and labels required for the op= form. */
5214 : 12136 : old = create_tmp_var_raw (nonatomic_lhs_type);
5215 : 12136 : old_addr = build_unary_op (loc, ADDR_EXPR, old, false);
5216 : 12136 : TREE_ADDRESSABLE (old) = 1;
5217 : 12136 : suppress_warning (old);
5218 : :
5219 : 12136 : newval = create_tmp_var_raw (nonatomic_lhs_type);
5220 : 12136 : newval_addr = build_unary_op (loc, ADDR_EXPR, newval, false);
5221 : 12136 : TREE_ADDRESSABLE (newval) = 1;
5222 : 12136 : suppress_warning (newval);
5223 : :
5224 : 12136 : loop_decl = create_artificial_label (loc);
5225 : 12136 : loop_label = build1 (LABEL_EXPR, void_type_node, loop_decl);
5226 : :
5227 : 12136 : done_decl = create_artificial_label (loc);
5228 : 12136 : done_label = build1 (LABEL_EXPR, void_type_node, done_decl);
5229 : :
5230 : : /* __atomic_load (addr, &old, SEQ_CST). */
5231 : 12136 : fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_LOAD);
5232 : 12136 : params->quick_push (lhs_addr);
5233 : 12136 : params->quick_push (old_addr);
5234 : 12136 : params->quick_push (seq_cst);
5235 : 12136 : func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
5236 : 12136 : old = build4 (TARGET_EXPR, nonatomic_lhs_type, old, func_call, NULL_TREE,
5237 : : NULL_TREE);
5238 : 12136 : add_stmt (old);
5239 : 12136 : params->truncate (0);
5240 : :
5241 : : /* Create the expressions for floating-point environment
5242 : : manipulation, if required. */
5243 : 12136 : bool need_fenv = (flag_trapping_math
5244 : 12136 : && (FLOAT_TYPE_P (lhs_type) || FLOAT_TYPE_P (rhs_type)));
5245 : 12136 : tree hold_call = NULL_TREE, clear_call = NULL_TREE, update_call = NULL_TREE;
5246 : 12136 : if (need_fenv)
5247 : 7054 : targetm.atomic_assign_expand_fenv (&hold_call, &clear_call, &update_call);
5248 : :
5249 : 12136 : if (hold_call)
5250 : 7054 : add_stmt (hold_call);
5251 : :
5252 : : /* loop: */
5253 : 12136 : add_stmt (loop_label);
5254 : :
5255 : : /* newval = old + val; */
5256 : 12136 : if (rhs_type != rhs_semantic_type)
5257 : 0 : val = build1 (EXCESS_PRECISION_EXPR, nonatomic_rhs_semantic_type, val);
5258 : 12136 : rhs = build_binary_op (loc, modifycode, old, val, true);
5259 : 12136 : if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
5260 : : {
5261 : 0 : tree eptype = TREE_TYPE (rhs);
5262 : 0 : rhs = c_fully_fold (TREE_OPERAND (rhs, 0), false, NULL);
5263 : 0 : rhs = build1 (EXCESS_PRECISION_EXPR, eptype, rhs);
5264 : : }
5265 : : else
5266 : 12136 : rhs = c_fully_fold (rhs, false, NULL);
5267 : 12136 : rhs = convert_for_assignment (loc, UNKNOWN_LOCATION, nonatomic_lhs_type,
5268 : : rhs, NULL_TREE, ic_assign, false, NULL_TREE,
5269 : : NULL_TREE, 0);
5270 : : /* The temporary variable for NEWVAL is only gimplified correctly (in
5271 : : particular, given a DECL_CONTEXT) if used in a TARGET_EXPR. To avoid
5272 : : subsequent ICEs in nested function processing after an error, ensure such
5273 : : a TARGET_EXPR is built even after an error. */
5274 : 12136 : if (rhs == error_mark_node)
5275 : 10 : rhs = old;
5276 : 12136 : rhs = build4 (TARGET_EXPR, nonatomic_lhs_type, newval, rhs, NULL_TREE,
5277 : : NULL_TREE);
5278 : 12136 : SET_EXPR_LOCATION (rhs, loc);
5279 : 12136 : add_stmt (rhs);
5280 : :
5281 : : /* if (__atomic_compare_exchange (addr, &old, &new, false, SEQ_CST, SEQ_CST))
5282 : : goto done; */
5283 : 12136 : fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_COMPARE_EXCHANGE);
5284 : 12136 : params->quick_push (lhs_addr);
5285 : 12136 : params->quick_push (old_addr);
5286 : 12136 : params->quick_push (newval_addr);
5287 : 12136 : params->quick_push (integer_zero_node);
5288 : 12136 : params->quick_push (seq_cst);
5289 : 12136 : params->quick_push (seq_cst);
5290 : 12136 : func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
5291 : :
5292 : 12136 : goto_stmt = build1 (GOTO_EXPR, void_type_node, done_decl);
5293 : 12136 : SET_EXPR_LOCATION (goto_stmt, loc);
5294 : :
5295 : 12136 : stmt = build3 (COND_EXPR, void_type_node, func_call, goto_stmt, NULL_TREE);
5296 : 12136 : SET_EXPR_LOCATION (stmt, loc);
5297 : 12136 : add_stmt (stmt);
5298 : :
5299 : 12136 : if (clear_call)
5300 : 7054 : add_stmt (clear_call);
5301 : :
5302 : : /* goto loop; */
5303 : 12136 : goto_stmt = build1 (GOTO_EXPR, void_type_node, loop_decl);
5304 : 12136 : SET_EXPR_LOCATION (goto_stmt, loc);
5305 : 12136 : add_stmt (goto_stmt);
5306 : :
5307 : : /* done: */
5308 : 12136 : add_stmt (done_label);
5309 : :
5310 : 12136 : if (update_call)
5311 : 7054 : add_stmt (update_call);
5312 : :
5313 : : /* Finish the compound statement. */
5314 : 12136 : compound_stmt = c_end_compound_stmt (loc, compound_stmt, false);
5315 : :
5316 : : /* NEWVAL is the value that was successfully stored, return a
5317 : : COMPOUND_EXPR of the statement and the appropriate value. */
5318 : 23713 : return build2 (COMPOUND_EXPR, nonatomic_lhs_type, compound_stmt,
5319 : 12136 : return_old_p ? old : newval);
5320 : : }
5321 : :
5322 : : /* Construct and perhaps optimize a tree representation
5323 : : for a unary operation. CODE, a tree_code, specifies the operation
5324 : : and XARG is the operand.
5325 : : For any CODE other than ADDR_EXPR, NOCONVERT suppresses the default
5326 : : promotions (such as from short to int).
5327 : : For ADDR_EXPR, the default promotions are not applied; NOCONVERT allows
5328 : : non-lvalues; this is only used to handle conversion of non-lvalue arrays
5329 : : to pointers in C99.
5330 : :
5331 : : LOCATION is the location of the operator. */
5332 : :
5333 : : tree
5334 : 58992488 : build_unary_op (location_t location, enum tree_code code, tree xarg,
5335 : : bool noconvert)
5336 : : {
5337 : : /* No default_conversion here. It causes trouble for ADDR_EXPR. */
5338 : 58992488 : tree arg = xarg;
5339 : 58992488 : tree argtype = NULL_TREE;
5340 : 58992488 : enum tree_code typecode;
5341 : 58992488 : tree val;
5342 : 58992488 : tree ret = error_mark_node;
5343 : 58992488 : tree eptype = NULL_TREE;
5344 : 58992488 : const char *invalid_op_diag;
5345 : 58992488 : bool int_operands;
5346 : :
5347 : 58992488 : int_operands = EXPR_INT_CONST_OPERANDS (xarg);
5348 : 6289570 : if (int_operands)
5349 : 6289570 : arg = remove_c_maybe_const_expr (arg);
5350 : :
5351 : 58992488 : if (code != ADDR_EXPR)
5352 : 8321411 : arg = require_complete_type (location, arg);
5353 : :
5354 : 58992488 : typecode = TREE_CODE (TREE_TYPE (arg));
5355 : 58992488 : if (typecode == ERROR_MARK)
5356 : 74 : return error_mark_node;
5357 : 58992414 : if (typecode == ENUMERAL_TYPE || typecode == BOOLEAN_TYPE)
5358 : 28152 : typecode = INTEGER_TYPE;
5359 : :
5360 : 117984828 : if ((invalid_op_diag
5361 : 58992414 : = targetm.invalid_unary_op (code, TREE_TYPE (xarg))))
5362 : : {
5363 : 0 : error_at (location, invalid_op_diag);
5364 : 0 : return error_mark_node;
5365 : : }
5366 : :
5367 : 58992414 : if (TREE_CODE (arg) == EXCESS_PRECISION_EXPR)
5368 : : {
5369 : 235 : eptype = TREE_TYPE (arg);
5370 : 235 : arg = TREE_OPERAND (arg, 0);
5371 : : }
5372 : :
5373 : 58992414 : switch (code)
5374 : : {
5375 : 28531 : case CONVERT_EXPR:
5376 : : /* This is used for unary plus, because a CONVERT_EXPR
5377 : : is enough to prevent anybody from looking inside for
5378 : : associativity, but won't generate any code. */
5379 : 28536 : if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
5380 : 8 : || typecode == FIXED_POINT_TYPE || typecode == COMPLEX_TYPE
5381 : 5 : || typecode == BITINT_TYPE
5382 : 5 : || gnu_vector_type_p (TREE_TYPE (arg))))
5383 : : {
5384 : 1 : error_at (location, "wrong type argument to unary plus");
5385 : 1 : return error_mark_node;
5386 : : }
5387 : 28530 : else if (!noconvert)
5388 : 28530 : arg = default_conversion (arg);
5389 : 28530 : arg = non_lvalue_loc (location, arg);
5390 : 28530 : break;
5391 : :
5392 : 6517049 : case NEGATE_EXPR:
5393 : 6953392 : if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
5394 : 472828 : || typecode == FIXED_POINT_TYPE || typecode == COMPLEX_TYPE
5395 : 441561 : || typecode == BITINT_TYPE
5396 : 436343 : || gnu_vector_type_p (TREE_TYPE (arg))))
5397 : : {
5398 : 1 : error_at (location, "wrong type argument to unary minus");
5399 : 1 : return error_mark_node;
5400 : : }
5401 : 6517048 : else if (!noconvert)
5402 : 6517042 : arg = default_conversion (arg);
5403 : : break;
5404 : :
5405 : 288576 : case BIT_NOT_EXPR:
5406 : : /* ~ works on integer types and non float vectors. */
5407 : 288576 : if (typecode == INTEGER_TYPE
5408 : 288576 : || typecode == BITINT_TYPE
5409 : 288576 : || (gnu_vector_type_p (TREE_TYPE (arg))
5410 : 2057 : && !VECTOR_FLOAT_TYPE_P (TREE_TYPE (arg))))
5411 : : {
5412 : : tree e = arg;
5413 : :
5414 : : /* Warn if the expression has boolean value. */
5415 : 287977 : while (TREE_CODE (e) == COMPOUND_EXPR)
5416 : 11 : e = TREE_OPERAND (e, 1);
5417 : :
5418 : 575918 : if ((C_BOOLEAN_TYPE_P (TREE_TYPE (arg))
5419 : 575918 : || truth_value_p (TREE_CODE (e))))
5420 : : {
5421 : 145 : auto_diagnostic_group d;
5422 : 145 : if (warning_at (location, OPT_Wbool_operation,
5423 : : "%<~%> on a boolean expression"))
5424 : : {
5425 : 12 : gcc_rich_location richloc (location);
5426 : 12 : richloc.add_fixit_insert_before (location, "!");
5427 : 12 : inform (&richloc, "did you mean to use logical not?");
5428 : 12 : }
5429 : 145 : }
5430 : 287966 : if (!noconvert)
5431 : 287963 : arg = default_conversion (arg);
5432 : : }
5433 : 610 : else if (typecode == COMPLEX_TYPE)
5434 : : {
5435 : 605 : code = CONJ_EXPR;
5436 : 605 : pedwarn (location, OPT_Wpedantic,
5437 : : "ISO C does not support %<~%> for complex conjugation");
5438 : 605 : if (!noconvert)
5439 : 605 : arg = default_conversion (arg);
5440 : : }
5441 : : else
5442 : : {
5443 : 5 : error_at (location, "wrong type argument to bit-complement");
5444 : 5 : return error_mark_node;
5445 : : }
5446 : : break;
5447 : :
5448 : 3 : case ABS_EXPR:
5449 : 3 : if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE))
5450 : : {
5451 : 0 : error_at (location, "wrong type argument to abs");
5452 : 0 : return error_mark_node;
5453 : : }
5454 : 3 : else if (!noconvert)
5455 : 0 : arg = default_conversion (arg);
5456 : : break;
5457 : :
5458 : 7 : case ABSU_EXPR:
5459 : 7 : if (!(typecode == INTEGER_TYPE))
5460 : : {
5461 : 0 : error_at (location, "wrong type argument to absu");
5462 : 0 : return error_mark_node;
5463 : : }
5464 : 7 : else if (!noconvert)
5465 : 0 : arg = default_conversion (arg);
5466 : : break;
5467 : :
5468 : 0 : case CONJ_EXPR:
5469 : : /* Conjugating a real value is a no-op, but allow it anyway. */
5470 : 0 : if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
5471 : : || typecode == COMPLEX_TYPE))
5472 : : {
5473 : 0 : error_at (location, "wrong type argument to conjugation");
5474 : 0 : return error_mark_node;
5475 : : }
5476 : 0 : else if (!noconvert)
5477 : 0 : arg = default_conversion (arg);
5478 : : break;
5479 : :
5480 : 373259 : case TRUTH_NOT_EXPR:
5481 : 373259 : if (typecode != INTEGER_TYPE && typecode != FIXED_POINT_TYPE
5482 : 6926 : && typecode != REAL_TYPE && typecode != POINTER_TYPE
5483 : 21 : && typecode != COMPLEX_TYPE && typecode != NULLPTR_TYPE
5484 : 18 : && typecode != BITINT_TYPE)
5485 : : {
5486 : 10 : error_at (location,
5487 : : "wrong type argument to unary exclamation mark");
5488 : 10 : return error_mark_node;
5489 : : }
5490 : 373249 : if (int_operands)
5491 : : {
5492 : 139609 : arg = c_objc_common_truthvalue_conversion (location, xarg);
5493 : 139609 : arg = remove_c_maybe_const_expr (arg);
5494 : : }
5495 : : else
5496 : 233640 : arg = c_objc_common_truthvalue_conversion (location, arg);
5497 : 373249 : ret = invert_truthvalue_loc (location, arg);
5498 : : /* If the TRUTH_NOT_EXPR has been folded, reset the location. */
5499 : 373249 : if (EXPR_P (ret) && EXPR_HAS_LOCATION (ret))
5500 : 233245 : location = EXPR_LOCATION (ret);
5501 : 373249 : goto return_build_unary_op;
5502 : :
5503 : 201157 : case REALPART_EXPR:
5504 : 201157 : case IMAGPART_EXPR:
5505 : 201157 : ret = build_real_imag_expr (location, code, arg);
5506 : 201157 : if (ret == error_mark_node)
5507 : : return error_mark_node;
5508 : 201149 : if (eptype && TREE_CODE (eptype) == COMPLEX_TYPE)
5509 : 2 : eptype = TREE_TYPE (eptype);
5510 : 201149 : goto return_build_unary_op;
5511 : :
5512 : 912786 : case PREINCREMENT_EXPR:
5513 : 912786 : case POSTINCREMENT_EXPR:
5514 : 912786 : case PREDECREMENT_EXPR:
5515 : 912786 : case POSTDECREMENT_EXPR:
5516 : :
5517 : 912786 : if (TREE_CODE (arg) == C_MAYBE_CONST_EXPR)
5518 : : {
5519 : 2 : tree inner = build_unary_op (location, code,
5520 : 2 : C_MAYBE_CONST_EXPR_EXPR (arg),
5521 : : noconvert);
5522 : 2 : if (inner == error_mark_node)
5523 : : return error_mark_node;
5524 : 4 : ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (inner),
5525 : 2 : C_MAYBE_CONST_EXPR_PRE (arg), inner);
5526 : 2 : gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (arg));
5527 : 2 : C_MAYBE_CONST_EXPR_NON_CONST (ret) = 1;
5528 : 2 : goto return_build_unary_op;
5529 : : }
5530 : :
5531 : : /* Complain about anything that is not a true lvalue. In
5532 : : Objective-C, skip this check for property_refs. */
5533 : 912784 : if (!objc_is_property_ref (arg)
5534 : 1825568 : && !lvalue_or_else (location,
5535 : 912784 : arg, ((code == PREINCREMENT_EXPR
5536 : 912784 : || code == POSTINCREMENT_EXPR)
5537 : : ? lv_increment
5538 : : : lv_decrement)))
5539 : 22 : return error_mark_node;
5540 : :
5541 : 912762 : if (warn_cxx_compat && TREE_CODE (TREE_TYPE (arg)) == ENUMERAL_TYPE)
5542 : : {
5543 : 4 : if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
5544 : 2 : warning_at (location, OPT_Wc___compat,
5545 : : "increment of enumeration value is invalid in C++");
5546 : : else
5547 : 2 : warning_at (location, OPT_Wc___compat,
5548 : : "decrement of enumeration value is invalid in C++");
5549 : : }
5550 : :
5551 : 912762 : if (C_BOOLEAN_TYPE_P (TREE_TYPE (arg)))
5552 : : {
5553 : 264 : if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
5554 : 132 : warning_at (location, OPT_Wbool_operation,
5555 : : "increment of a boolean expression");
5556 : : else
5557 : 132 : warning_at (location, OPT_Wbool_operation,
5558 : : "decrement of a boolean expression");
5559 : : }
5560 : :
5561 : : /* Ensure the argument is fully folded inside any SAVE_EXPR. */
5562 : 912762 : arg = c_fully_fold (arg, false, NULL, true);
5563 : :
5564 : 912762 : bool atomic_op;
5565 : 912762 : atomic_op = really_atomic_lvalue (arg);
5566 : :
5567 : : /* Increment or decrement the real part of the value,
5568 : : and don't change the imaginary part. */
5569 : 912762 : if (typecode == COMPLEX_TYPE)
5570 : : {
5571 : 57 : tree real, imag;
5572 : :
5573 : 57 : pedwarn_c23 (location, OPT_Wpedantic,
5574 : : "ISO C does not support %<++%> and %<--%> on complex "
5575 : : "types before C2Y");
5576 : :
5577 : 57 : if (!atomic_op)
5578 : : {
5579 : 53 : arg = stabilize_reference (arg);
5580 : 53 : real = build_unary_op (EXPR_LOCATION (arg), REALPART_EXPR, arg,
5581 : : true);
5582 : 53 : imag = build_unary_op (EXPR_LOCATION (arg), IMAGPART_EXPR, arg,
5583 : : true);
5584 : 53 : real = build_unary_op (EXPR_LOCATION (arg), code, real, true);
5585 : 53 : if (real == error_mark_node || imag == error_mark_node)
5586 : : return error_mark_node;
5587 : 53 : ret = build2 (COMPLEX_EXPR, TREE_TYPE (arg),
5588 : : real, imag);
5589 : 53 : goto return_build_unary_op;
5590 : : }
5591 : : }
5592 : :
5593 : : /* Report invalid types. */
5594 : :
5595 : 912709 : if (typecode != POINTER_TYPE && typecode != FIXED_POINT_TYPE
5596 : 683786 : && typecode != INTEGER_TYPE && typecode != REAL_TYPE
5597 : 143 : && typecode != COMPLEX_TYPE && typecode != BITINT_TYPE
5598 : 912758 : && !gnu_vector_type_p (TREE_TYPE (arg)))
5599 : : {
5600 : 5 : if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
5601 : 3 : error_at (location, "wrong type argument to increment");
5602 : : else
5603 : 2 : error_at (location, "wrong type argument to decrement");
5604 : :
5605 : 5 : return error_mark_node;
5606 : : }
5607 : :
5608 : 912704 : {
5609 : 912704 : tree inc;
5610 : :
5611 : 912704 : argtype = TREE_TYPE (arg);
5612 : :
5613 : : /* Compute the increment. */
5614 : :
5615 : 912704 : if (typecode == POINTER_TYPE)
5616 : : {
5617 : : /* If pointer target is an incomplete type,
5618 : : we just cannot know how to do the arithmetic. */
5619 : 228923 : if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (argtype)))
5620 : : {
5621 : 27 : if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
5622 : 17 : error_at (location,
5623 : : "increment of pointer to an incomplete type %qT",
5624 : 17 : TREE_TYPE (argtype));
5625 : : else
5626 : 10 : error_at (location,
5627 : : "decrement of pointer to an incomplete type %qT",
5628 : 10 : TREE_TYPE (argtype));
5629 : : }
5630 : 228896 : else if (TREE_CODE (TREE_TYPE (argtype)) == FUNCTION_TYPE
5631 : 228896 : || VOID_TYPE_P (TREE_TYPE (argtype)))
5632 : : {
5633 : 10 : if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
5634 : 6 : pedwarn (location, OPT_Wpointer_arith,
5635 : : "wrong type argument to increment");
5636 : : else
5637 : 4 : pedwarn (location, OPT_Wpointer_arith,
5638 : : "wrong type argument to decrement");
5639 : : }
5640 : : else
5641 : 457772 : verify_type_context (location, TCTX_POINTER_ARITH,
5642 : 228886 : TREE_TYPE (argtype));
5643 : :
5644 : 228923 : inc = c_size_in_bytes (TREE_TYPE (argtype));
5645 : 228923 : inc = convert_to_ptrofftype_loc (location, inc);
5646 : : }
5647 : 683781 : else if (FRACT_MODE_P (TYPE_MODE (argtype)))
5648 : : {
5649 : : /* For signed fract types, we invert ++ to -- or
5650 : : -- to ++, and change inc from 1 to -1, because
5651 : : it is not possible to represent 1 in signed fract constants.
5652 : : For unsigned fract types, the result always overflows and
5653 : : we get an undefined (original) or the maximum value. */
5654 : 0 : if (code == PREINCREMENT_EXPR)
5655 : : code = PREDECREMENT_EXPR;
5656 : : else if (code == PREDECREMENT_EXPR)
5657 : : code = PREINCREMENT_EXPR;
5658 : : else if (code == POSTINCREMENT_EXPR)
5659 : : code = POSTDECREMENT_EXPR;
5660 : : else /* code == POSTDECREMENT_EXPR */
5661 : 0 : code = POSTINCREMENT_EXPR;
5662 : :
5663 : 0 : inc = integer_minus_one_node;
5664 : 0 : inc = convert (argtype, inc);
5665 : : }
5666 : : else
5667 : : {
5668 : 683737 : inc = VECTOR_TYPE_P (argtype)
5669 : 683781 : ? build_one_cst (argtype)
5670 : : : integer_one_node;
5671 : 683781 : inc = convert (argtype, inc);
5672 : : }
5673 : :
5674 : : /* If 'arg' is an Objective-C PROPERTY_REF expression, then we
5675 : : need to ask Objective-C to build the increment or decrement
5676 : : expression for it. */
5677 : 912704 : if (objc_is_property_ref (arg))
5678 : 0 : return objc_build_incr_expr_for_property_ref (location, code,
5679 : 0 : arg, inc);
5680 : :
5681 : : /* Report a read-only lvalue. */
5682 : 912704 : if (TYPE_READONLY (argtype))
5683 : : {
5684 : 20 : readonly_error (location, arg,
5685 : 20 : ((code == PREINCREMENT_EXPR
5686 : 20 : || code == POSTINCREMENT_EXPR)
5687 : : ? lv_increment : lv_decrement));
5688 : 20 : return error_mark_node;
5689 : : }
5690 : 912684 : else if (TREE_READONLY (arg))
5691 : 4 : readonly_warning (arg,
5692 : 4 : ((code == PREINCREMENT_EXPR
5693 : 4 : || code == POSTINCREMENT_EXPR)
5694 : : ? lv_increment : lv_decrement));
5695 : :
5696 : : /* If the argument is atomic, use the special code sequences for
5697 : : atomic compound assignment. */
5698 : 912684 : if (atomic_op)
5699 : : {
5700 : 4441 : arg = stabilize_reference (arg);
5701 : 8882 : ret = build_atomic_assign (location, arg,
5702 : 4441 : ((code == PREINCREMENT_EXPR
5703 : 4441 : || code == POSTINCREMENT_EXPR)
5704 : : ? PLUS_EXPR
5705 : : : MINUS_EXPR),
5706 : 4441 : (FRACT_MODE_P (TYPE_MODE (argtype))
5707 : : ? inc
5708 : : : integer_one_node),
5709 : : (code == POSTINCREMENT_EXPR
5710 : 4441 : || code == POSTDECREMENT_EXPR));
5711 : 4441 : goto return_build_unary_op;
5712 : : }
5713 : :
5714 : 908243 : if (C_BOOLEAN_TYPE_P (TREE_TYPE (arg)))
5715 : 56 : val = boolean_increment (code, arg);
5716 : : else
5717 : 908187 : val = build2 (code, TREE_TYPE (arg), arg, inc);
5718 : 908243 : TREE_SIDE_EFFECTS (val) = 1;
5719 : 908243 : if (TYPE_QUALS (TREE_TYPE (val)) != TYPE_UNQUALIFIED)
5720 : 3905 : TREE_TYPE (val) = c_build_qualified_type (TREE_TYPE (val),
5721 : : TYPE_UNQUALIFIED);
5722 : 908243 : ret = val;
5723 : 908243 : goto return_build_unary_op;
5724 : : }
5725 : :
5726 : 50671036 : case ADDR_EXPR:
5727 : : /* Note that this operation never does default_conversion. */
5728 : :
5729 : : /* The operand of unary '&' must be an lvalue (which excludes
5730 : : expressions of type void), or, in C99, the result of a [] or
5731 : : unary '*' operator. */
5732 : 50671036 : if (VOID_TYPE_P (TREE_TYPE (arg))
5733 : 25 : && TYPE_QUALS (TREE_TYPE (arg)) == TYPE_UNQUALIFIED
5734 : 50671055 : && (!INDIRECT_REF_P (arg) || !flag_isoc99))
5735 : 18 : pedwarn (location, 0, "taking address of expression of type %<void%>");
5736 : :
5737 : : /* Let &* cancel out to simplify resulting code. */
5738 : 50671036 : if (INDIRECT_REF_P (arg))
5739 : : {
5740 : : /* Don't let this be an lvalue. */
5741 : 21735 : if (lvalue_p (TREE_OPERAND (arg, 0)))
5742 : 16408 : return non_lvalue_loc (location, TREE_OPERAND (arg, 0));
5743 : 5327 : ret = TREE_OPERAND (arg, 0);
5744 : 5327 : goto return_build_unary_op;
5745 : : }
5746 : :
5747 : : /* Anything not already handled and not a true memory reference
5748 : : or a non-lvalue array is an error. */
5749 : 50649301 : if (typecode != FUNCTION_TYPE && !noconvert
5750 : 50649301 : && !lvalue_or_else (location, arg, lv_addressof))
5751 : 17 : return error_mark_node;
5752 : :
5753 : : /* Move address operations inside C_MAYBE_CONST_EXPR to simplify
5754 : : folding later. */
5755 : 50649284 : if (TREE_CODE (arg) == C_MAYBE_CONST_EXPR)
5756 : : {
5757 : 1 : tree inner = build_unary_op (location, code,
5758 : 1 : C_MAYBE_CONST_EXPR_EXPR (arg),
5759 : : noconvert);
5760 : 2 : ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (inner),
5761 : 1 : C_MAYBE_CONST_EXPR_PRE (arg), inner);
5762 : 1 : gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (arg));
5763 : 1 : C_MAYBE_CONST_EXPR_NON_CONST (ret)
5764 : 1 : = C_MAYBE_CONST_EXPR_NON_CONST (arg);
5765 : 1 : goto return_build_unary_op;
5766 : : }
5767 : :
5768 : : /* Ordinary case; arg is a COMPONENT_REF or a decl, or a call to
5769 : : .ACCESS_WITH_SIZE. */
5770 : 50649283 : if (is_access_with_size_p (arg))
5771 : 0 : arg = TREE_OPERAND (TREE_OPERAND (CALL_EXPR_ARG (arg, 0), 0), 0);
5772 : :
5773 : 50649283 : argtype = TREE_TYPE (arg);
5774 : :
5775 : : /* If the lvalue is const or volatile, merge that into the type
5776 : : to which the address will point. This is only needed
5777 : : for function types. */
5778 : 50649283 : if ((DECL_P (arg) || REFERENCE_CLASS_P (arg))
5779 : 50167491 : && (TREE_READONLY (arg) || TREE_THIS_VOLATILE (arg))
5780 : 79947008 : && TREE_CODE (argtype) == FUNCTION_TYPE)
5781 : : {
5782 : 29219418 : int orig_quals = TYPE_QUALS (strip_array_types (argtype));
5783 : 29219418 : int quals = orig_quals;
5784 : :
5785 : 29219418 : if (TREE_READONLY (arg))
5786 : 28849971 : quals |= TYPE_QUAL_CONST;
5787 : 29219418 : if (TREE_THIS_VOLATILE (arg))
5788 : 370279 : quals |= TYPE_QUAL_VOLATILE;
5789 : :
5790 : 29219418 : argtype = c_build_qualified_type (argtype, quals);
5791 : : }
5792 : :
5793 : 50649283 : switch (TREE_CODE (arg))
5794 : : {
5795 : 63500 : case COMPONENT_REF:
5796 : 63500 : if (DECL_C_BIT_FIELD (TREE_OPERAND (arg, 1)))
5797 : : {
5798 : 8 : error_at (location, "cannot take address of bit-field %qD",
5799 : 8 : TREE_OPERAND (arg, 1));
5800 : 8 : return error_mark_node;
5801 : : }
5802 : :
5803 : : /* fall through */
5804 : :
5805 : 137509 : case ARRAY_REF:
5806 : 137509 : if (TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (TREE_OPERAND (arg, 0))))
5807 : : {
5808 : 78 : if (!AGGREGATE_TYPE_P (TREE_TYPE (arg))
5809 : 7 : && !POINTER_TYPE_P (TREE_TYPE (arg))
5810 : 75 : && !VECTOR_TYPE_P (TREE_TYPE (arg)))
5811 : : {
5812 : 6 : error_at (location, "cannot take address of scalar with "
5813 : : "reverse storage order");
5814 : 6 : return error_mark_node;
5815 : : }
5816 : :
5817 : 63 : if (TREE_CODE (TREE_TYPE (arg)) == ARRAY_TYPE
5818 : 63 : && TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (arg)))
5819 : 58 : warning_at (location, OPT_Wscalar_storage_order,
5820 : : "address of array with reverse scalar storage "
5821 : : "order requested");
5822 : : }
5823 : :
5824 : 50649269 : default:
5825 : 50649269 : break;
5826 : : }
5827 : :
5828 : 50649269 : if (!c_mark_addressable (arg))
5829 : 10 : return error_mark_node;
5830 : :
5831 : 50649259 : gcc_assert (TREE_CODE (arg) != COMPONENT_REF
5832 : : || !DECL_C_BIT_FIELD (TREE_OPERAND (arg, 1)));
5833 : :
5834 : 50649259 : argtype = c_build_pointer_type (argtype);
5835 : :
5836 : : /* ??? Cope with user tricks that amount to offsetof. Delete this
5837 : : when we have proper support for integer constant expressions. */
5838 : 50649259 : val = get_base_address (arg);
5839 : 50649259 : if (val && INDIRECT_REF_P (val)
5840 : 50671894 : && TREE_CONSTANT (TREE_OPERAND (val, 0)))
5841 : : {
5842 : 538 : ret = fold_offsetof (arg, argtype);
5843 : 538 : goto return_build_unary_op;
5844 : : }
5845 : :
5846 : 50648721 : val = build1 (ADDR_EXPR, argtype, arg);
5847 : :
5848 : 50648721 : ret = val;
5849 : 50648721 : goto return_build_unary_op;
5850 : :
5851 : 10 : case PAREN_EXPR:
5852 : 10 : ret = build1 (code, TREE_TYPE (arg), arg);
5853 : 10 : goto return_build_unary_op;
5854 : :
5855 : 0 : default:
5856 : 0 : gcc_unreachable ();
5857 : : }
5858 : :
5859 : 6834159 : if (argtype == NULL_TREE)
5860 : 6834159 : argtype = TREE_TYPE (arg);
5861 : 6834159 : if (TREE_CODE (arg) == INTEGER_CST)
5862 : 6146002 : ret = (require_constant_value
5863 : 6146002 : ? fold_build1_initializer_loc (location, code, argtype, arg)
5864 : 6127705 : : fold_build1_loc (location, code, argtype, arg));
5865 : : else
5866 : 688157 : ret = build1 (code, argtype, arg);
5867 : 58975893 : return_build_unary_op:
5868 : 58975893 : gcc_assert (ret != error_mark_node);
5869 : 6290046 : if (TREE_CODE (ret) == INTEGER_CST && !TREE_OVERFLOW (ret)
5870 : 65265930 : && !(TREE_CODE (xarg) == INTEGER_CST && !TREE_OVERFLOW (xarg)))
5871 : 562 : ret = build1 (NOP_EXPR, TREE_TYPE (ret), ret);
5872 : 58975331 : else if (TREE_CODE (ret) != INTEGER_CST && int_operands)
5873 : 74 : ret = note_integer_operands (ret);
5874 : 58975893 : if (eptype)
5875 : 235 : ret = build1 (EXCESS_PRECISION_EXPR, eptype, ret);
5876 : 58975893 : protected_set_expr_location (ret, location);
5877 : 58975893 : return ret;
5878 : : }
5879 : :
5880 : : /* Return nonzero if REF is an lvalue valid for this language.
5881 : : Lvalues can be assigned, unless their type has TYPE_READONLY.
5882 : : Lvalues can have their address taken, unless they have C_DECL_REGISTER. */
5883 : :
5884 : : bool
5885 : 174709518 : lvalue_p (const_tree ref)
5886 : : {
5887 : 176187922 : const enum tree_code code = TREE_CODE (ref);
5888 : :
5889 : 176187922 : switch (code)
5890 : : {
5891 : 1454494 : case REALPART_EXPR:
5892 : 1454494 : case IMAGPART_EXPR:
5893 : 1454494 : case COMPONENT_REF:
5894 : 1454494 : return lvalue_p (TREE_OPERAND (ref, 0));
5895 : :
5896 : 23910 : case C_MAYBE_CONST_EXPR:
5897 : 23910 : return lvalue_p (TREE_OPERAND (ref, 1));
5898 : :
5899 : : case COMPOUND_LITERAL_EXPR:
5900 : : case STRING_CST:
5901 : : return true;
5902 : :
5903 : 25238805 : case MEM_REF:
5904 : 25238805 : case TARGET_MEM_REF:
5905 : : /* MEM_REFs can appear from -fgimple parsing or folding, so allow them
5906 : : here as well. */
5907 : 25238805 : case INDIRECT_REF:
5908 : 25238805 : case ARRAY_REF:
5909 : 25238805 : case VAR_DECL:
5910 : 25238805 : case PARM_DECL:
5911 : 25238805 : case RESULT_DECL:
5912 : 25238805 : case ERROR_MARK:
5913 : 25238805 : return (TREE_CODE (TREE_TYPE (ref)) != FUNCTION_TYPE
5914 : 25238805 : && TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE);
5915 : :
5916 : 6 : case BIND_EXPR:
5917 : 6 : return TREE_CODE (TREE_TYPE (ref)) == ARRAY_TYPE;
5918 : :
5919 : 6993991 : case CALL_EXPR:
5920 : 6993991 : return is_access_with_size_p (ref);
5921 : :
5922 : : default:
5923 : : return false;
5924 : : }
5925 : : }
5926 : :
5927 : : /* Give a warning for storing in something that is read-only in GCC
5928 : : terms but not const in ISO C terms. */
5929 : :
5930 : : static void
5931 : 5 : readonly_warning (tree arg, enum lvalue_use use)
5932 : : {
5933 : 5 : switch (use)
5934 : : {
5935 : 1 : case lv_assign:
5936 : 1 : warning (0, "assignment of read-only location %qE", arg);
5937 : 1 : break;
5938 : 2 : case lv_increment:
5939 : 2 : warning (0, "increment of read-only location %qE", arg);
5940 : 2 : break;
5941 : 2 : case lv_decrement:
5942 : 2 : warning (0, "decrement of read-only location %qE", arg);
5943 : 2 : break;
5944 : 0 : default:
5945 : 0 : gcc_unreachable ();
5946 : : }
5947 : 5 : return;
5948 : : }
5949 : :
5950 : :
5951 : : /* Return nonzero if REF is an lvalue valid for this language;
5952 : : otherwise, print an error message and return zero. USE says
5953 : : how the lvalue is being used and so selects the error message.
5954 : : LOCATION is the location at which any error should be reported. */
5955 : :
5956 : : static int
5957 : 4614880 : lvalue_or_else (location_t loc, const_tree ref, enum lvalue_use use)
5958 : : {
5959 : 4614880 : int win = lvalue_p (ref);
5960 : :
5961 : 4614880 : if (!win)
5962 : 74 : lvalue_error (loc, use);
5963 : :
5964 : 4614880 : return win;
5965 : : }
5966 : :
5967 : : /* Mark EXP saying that we need to be able to take the
5968 : : address of it; it should not be allocated in a register.
5969 : : Returns true if successful. ARRAY_REF_P is true if this
5970 : : is for ARRAY_REF construction - in that case we don't want
5971 : : to look through VIEW_CONVERT_EXPR from VECTOR_TYPE to ARRAY_TYPE,
5972 : : it is fine to use ARRAY_REFs for vector subscripts on vector
5973 : : register variables. */
5974 : :
5975 : : bool
5976 : 51181923 : c_mark_addressable (tree exp, bool array_ref_p)
5977 : : {
5978 : 51181923 : tree x = exp;
5979 : :
5980 : 51750723 : while (1)
5981 : 51750723 : switch (TREE_CODE (x))
5982 : : {
5983 : 9942 : case VIEW_CONVERT_EXPR:
5984 : 9942 : if (array_ref_p
5985 : 9841 : && TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
5986 : 19783 : && VECTOR_TYPE_P (TREE_TYPE (TREE_OPERAND (x, 0))))
5987 : : return true;
5988 : 101 : x = TREE_OPERAND (x, 0);
5989 : 101 : break;
5990 : :
5991 : 384912 : case COMPONENT_REF:
5992 : 384912 : if (DECL_C_BIT_FIELD (TREE_OPERAND (x, 1)))
5993 : : {
5994 : 6 : error ("cannot take address of bit-field %qD",
5995 : 3 : TREE_OPERAND (x, 1));
5996 : 3 : return false;
5997 : : }
5998 : : /* FALLTHRU */
5999 : 568699 : case ADDR_EXPR:
6000 : 568699 : case ARRAY_REF:
6001 : 568699 : case REALPART_EXPR:
6002 : 568699 : case IMAGPART_EXPR:
6003 : 568699 : x = TREE_OPERAND (x, 0);
6004 : 568699 : break;
6005 : :
6006 : 534 : case COMPOUND_LITERAL_EXPR:
6007 : 534 : if (C_DECL_REGISTER (COMPOUND_LITERAL_EXPR_DECL (x)))
6008 : : {
6009 : 2 : error ("address of register compound literal requested");
6010 : 2 : return false;
6011 : : }
6012 : 532 : TREE_ADDRESSABLE (x) = 1;
6013 : 532 : TREE_ADDRESSABLE (COMPOUND_LITERAL_EXPR_DECL (x)) = 1;
6014 : 532 : return true;
6015 : :
6016 : 0 : case CONSTRUCTOR:
6017 : 0 : TREE_ADDRESSABLE (x) = 1;
6018 : 0 : return true;
6019 : :
6020 : 1298777 : case VAR_DECL:
6021 : 1298777 : case CONST_DECL:
6022 : 1298777 : case PARM_DECL:
6023 : 1298777 : case RESULT_DECL:
6024 : 1298777 : if (C_DECL_REGISTER (x)
6025 : 1298777 : && DECL_NONLOCAL (x))
6026 : : {
6027 : 0 : if (TREE_PUBLIC (x) || is_global_var (x))
6028 : : {
6029 : 0 : error
6030 : 0 : ("global register variable %qD used in nested function", x);
6031 : 0 : return false;
6032 : : }
6033 : 0 : pedwarn (input_location, 0, "register variable %qD used in nested function", x);
6034 : : }
6035 : 1298777 : else if (C_DECL_REGISTER (x))
6036 : : {
6037 : 11 : if (TREE_PUBLIC (x) || is_global_var (x))
6038 : 4 : error ("address of global register variable %qD requested", x);
6039 : : else
6040 : 7 : error ("address of register variable %qD requested", x);
6041 : 11 : return false;
6042 : : }
6043 : :
6044 : : /* FALLTHRU */
6045 : 50616393 : case FUNCTION_DECL:
6046 : 50616393 : TREE_ADDRESSABLE (x) = 1;
6047 : : /* FALLTHRU */
6048 : : default:
6049 : : return true;
6050 : : }
6051 : : }
6052 : :
6053 : : /* Convert EXPR to TYPE, warning about conversion problems with
6054 : : constants. SEMANTIC_TYPE is the type this conversion would use
6055 : : without excess precision. If SEMANTIC_TYPE is NULL, this function
6056 : : is equivalent to convert_and_check. This function is a wrapper that
6057 : : handles conversions that may be different than
6058 : : the usual ones because of excess precision. */
6059 : :
6060 : : static tree
6061 : 23024916 : ep_convert_and_check (location_t loc, tree type, tree expr,
6062 : : tree semantic_type)
6063 : : {
6064 : 23024916 : if (TREE_TYPE (expr) == type)
6065 : : return expr;
6066 : :
6067 : : /* For C11, integer conversions may have results with excess
6068 : : precision. */
6069 : 2023992 : if (flag_isoc11 || !semantic_type)
6070 : 2023988 : return convert_and_check (loc, type, expr);
6071 : :
6072 : 4 : if (TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE
6073 : 4 : && TREE_TYPE (expr) != semantic_type)
6074 : : {
6075 : : /* For integers, we need to check the real conversion, not
6076 : : the conversion to the excess precision type. */
6077 : 4 : expr = convert_and_check (loc, semantic_type, expr);
6078 : : }
6079 : : /* Result type is the excess precision type, which should be
6080 : : large enough, so do not check. */
6081 : 4 : return convert (type, expr);
6082 : : }
6083 : :
6084 : : /* If EXPR refers to a built-in declared without a prototype returns
6085 : : the actual type of the built-in and, if non-null, set *BLTIN to
6086 : : a pointer to the built-in. Otherwise return the type of EXPR
6087 : : and clear *BLTIN if non-null. */
6088 : :
6089 : : static tree
6090 : 2783554 : type_or_builtin_type (tree expr, tree *bltin = NULL)
6091 : : {
6092 : 2783554 : tree dummy;
6093 : 2783554 : if (!bltin)
6094 : 0 : bltin = &dummy;
6095 : :
6096 : 2783554 : *bltin = NULL_TREE;
6097 : :
6098 : 2783554 : tree type = TREE_TYPE (expr);
6099 : 2783554 : if (TREE_CODE (expr) != ADDR_EXPR)
6100 : : return type;
6101 : :
6102 : 207387 : tree oper = TREE_OPERAND (expr, 0);
6103 : 207387 : if (!DECL_P (oper)
6104 : 169305 : || TREE_CODE (oper) != FUNCTION_DECL
6105 : 243773 : || !fndecl_built_in_p (oper, BUILT_IN_NORMAL))
6106 : : return type;
6107 : :
6108 : 2084 : built_in_function code = DECL_FUNCTION_CODE (oper);
6109 : 2084 : if (!C_DECL_BUILTIN_PROTOTYPE (oper))
6110 : : return type;
6111 : :
6112 : 1977 : if ((*bltin = builtin_decl_implicit (code)))
6113 : 991 : type = c_build_pointer_type (TREE_TYPE (*bltin));
6114 : :
6115 : : return type;
6116 : : }
6117 : :
6118 : : /* Build and return a conditional expression IFEXP ? OP1 : OP2. If
6119 : : IFEXP_BCP then the condition is a call to __builtin_constant_p, and
6120 : : if folded to an integer constant then the unselected half may
6121 : : contain arbitrary operations not normally permitted in constant
6122 : : expressions. Set the location of the expression to LOC. */
6123 : :
6124 : : tree
6125 : 401588 : build_conditional_expr (location_t colon_loc, tree ifexp, bool ifexp_bcp,
6126 : : tree op1, tree op1_original_type, location_t op1_loc,
6127 : : tree op2, tree op2_original_type, location_t op2_loc)
6128 : : {
6129 : 401588 : tree type1;
6130 : 401588 : tree type2;
6131 : 401588 : enum tree_code code1;
6132 : 401588 : enum tree_code code2;
6133 : 401588 : tree result_type = NULL;
6134 : 401588 : tree semantic_result_type = NULL;
6135 : 401588 : tree orig_op1 = op1, orig_op2 = op2;
6136 : 401588 : bool int_const, op1_int_operands, op2_int_operands, int_operands;
6137 : 401588 : bool ifexp_int_operands;
6138 : 401588 : tree ret;
6139 : :
6140 : 401588 : op1_int_operands = EXPR_INT_CONST_OPERANDS (orig_op1);
6141 : 114373 : if (op1_int_operands)
6142 : 114373 : op1 = remove_c_maybe_const_expr (op1);
6143 : 401588 : op2_int_operands = EXPR_INT_CONST_OPERANDS (orig_op2);
6144 : 147228 : if (op2_int_operands)
6145 : 147228 : op2 = remove_c_maybe_const_expr (op2);
6146 : 401588 : ifexp_int_operands = EXPR_INT_CONST_OPERANDS (ifexp);
6147 : 242061 : if (ifexp_int_operands)
6148 : 242061 : ifexp = remove_c_maybe_const_expr (ifexp);
6149 : :
6150 : : /* Promote both alternatives. */
6151 : :
6152 : 401588 : if (TREE_CODE (TREE_TYPE (op1)) != VOID_TYPE)
6153 : 397693 : op1 = default_conversion (op1);
6154 : 401588 : if (TREE_CODE (TREE_TYPE (op2)) != VOID_TYPE)
6155 : 371770 : op2 = default_conversion (op2);
6156 : :
6157 : 401588 : if (TREE_CODE (ifexp) == ERROR_MARK
6158 : 401519 : || TREE_CODE (TREE_TYPE (op1)) == ERROR_MARK
6159 : 803093 : || TREE_CODE (TREE_TYPE (op2)) == ERROR_MARK)
6160 : 83 : return error_mark_node;
6161 : :
6162 : 401505 : tree bltin1 = NULL_TREE;
6163 : 401505 : tree bltin2 = NULL_TREE;
6164 : 401505 : type1 = type_or_builtin_type (op1, &bltin1);
6165 : 401505 : code1 = TREE_CODE (type1);
6166 : 401505 : type2 = type_or_builtin_type (op2, &bltin2);
6167 : 401505 : code2 = TREE_CODE (type2);
6168 : :
6169 : 401505 : if (code1 == POINTER_TYPE && reject_gcc_builtin (op1))
6170 : 1 : return error_mark_node;
6171 : :
6172 : 401504 : if (code2 == POINTER_TYPE && reject_gcc_builtin (op2))
6173 : 1 : return error_mark_node;
6174 : :
6175 : : /* C90 does not permit non-lvalue arrays in conditional expressions.
6176 : : In C99 they will be pointers by now. */
6177 : 401503 : if (code1 == ARRAY_TYPE || code2 == ARRAY_TYPE)
6178 : : {
6179 : 1 : error_at (colon_loc, "non-lvalue array in conditional expression");
6180 : 1 : return error_mark_node;
6181 : : }
6182 : :
6183 : 401502 : if ((TREE_CODE (op1) == EXCESS_PRECISION_EXPR
6184 : 401496 : || TREE_CODE (op2) == EXCESS_PRECISION_EXPR)
6185 : 7 : && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
6186 : 0 : || code1 == COMPLEX_TYPE || code1 == BITINT_TYPE)
6187 : 7 : && (code2 == INTEGER_TYPE || code2 == REAL_TYPE
6188 : 0 : || code2 == COMPLEX_TYPE || code2 == BITINT_TYPE))
6189 : : {
6190 : 7 : semantic_result_type = c_common_type (type1, type2);
6191 : 7 : if (TREE_CODE (op1) == EXCESS_PRECISION_EXPR)
6192 : : {
6193 : 6 : op1 = TREE_OPERAND (op1, 0);
6194 : 6 : type1 = TREE_TYPE (op1);
6195 : 6 : gcc_assert (TREE_CODE (type1) == code1);
6196 : : }
6197 : 7 : if (TREE_CODE (op2) == EXCESS_PRECISION_EXPR)
6198 : : {
6199 : 1 : op2 = TREE_OPERAND (op2, 0);
6200 : 1 : type2 = TREE_TYPE (op2);
6201 : 1 : gcc_assert (TREE_CODE (type2) == code2);
6202 : : }
6203 : : }
6204 : :
6205 : 401502 : if (warn_cxx_compat)
6206 : : {
6207 : 416 : tree t1 = op1_original_type ? op1_original_type : TREE_TYPE (orig_op1);
6208 : 416 : tree t2 = op2_original_type ? op2_original_type : TREE_TYPE (orig_op2);
6209 : :
6210 : 416 : if (TREE_CODE (t1) == ENUMERAL_TYPE
6211 : 6 : && TREE_CODE (t2) == ENUMERAL_TYPE
6212 : 422 : && TYPE_MAIN_VARIANT (t1) != TYPE_MAIN_VARIANT (t2))
6213 : 2 : warning_at (colon_loc, OPT_Wc___compat,
6214 : : ("different enum types in conditional is "
6215 : : "invalid in C++: %qT vs %qT"),
6216 : : t1, t2);
6217 : : }
6218 : :
6219 : 401502 : if (warn_zero_as_null_pointer_constant
6220 : 14 : && c_inhibit_evaluation_warnings == 0)
6221 : : {
6222 : 14 : if ((code1 == POINTER_TYPE || code1 == NULLPTR_TYPE)
6223 : 14 : && code2 == INTEGER_TYPE && null_pointer_constant_p (orig_op2))
6224 : 2 : warning_at (op2_loc, OPT_Wzero_as_null_pointer_constant,
6225 : : "zero as null pointer constant");
6226 : :
6227 : 14 : if ((code2 == POINTER_TYPE || code2 == NULLPTR_TYPE)
6228 : 14 : && code1 == INTEGER_TYPE && null_pointer_constant_p (orig_op1))
6229 : 2 : warning_at (op1_loc, OPT_Wzero_as_null_pointer_constant,
6230 : : "zero as null pointer constant");
6231 : : }
6232 : :
6233 : : /* Quickly detect the usual case where op1 and op2 have the same type
6234 : : after promotion. */
6235 : 401502 : if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2))
6236 : : {
6237 : 268506 : if (type1 == type2)
6238 : : result_type = type1;
6239 : : else
6240 : 6253 : result_type = TYPE_MAIN_VARIANT (type1);
6241 : : }
6242 : 132996 : else if ((code1 == INTEGER_TYPE || code1 == REAL_TYPE
6243 : 79801 : || code1 == COMPLEX_TYPE || code1 == BITINT_TYPE)
6244 : 53240 : && (code2 == INTEGER_TYPE || code2 == REAL_TYPE
6245 : 26148 : || code2 == COMPLEX_TYPE || code2 == BITINT_TYPE))
6246 : : {
6247 : : /* In C11, a conditional expression between a floating-point
6248 : : type and an integer type should convert the integer type to
6249 : : the evaluation format of the floating-point type, with
6250 : : possible excess precision. */
6251 : 27191 : tree eptype1 = type1;
6252 : 27191 : tree eptype2 = type2;
6253 : 27191 : if (flag_isoc11)
6254 : : {
6255 : 26879 : tree eptype;
6256 : 10834 : if (ANY_INTEGRAL_TYPE_P (type1)
6257 : 26879 : && (eptype = excess_precision_type (type2)) != NULL_TREE)
6258 : : {
6259 : 2 : eptype2 = eptype;
6260 : 2 : if (!semantic_result_type)
6261 : 2 : semantic_result_type = c_common_type (type1, type2);
6262 : : }
6263 : 369 : else if (ANY_INTEGRAL_TYPE_P (type2)
6264 : 26877 : && (eptype = excess_precision_type (type1)) != NULL_TREE)
6265 : : {
6266 : 4618 : eptype1 = eptype;
6267 : 4618 : if (!semantic_result_type)
6268 : 4618 : semantic_result_type = c_common_type (type1, type2);
6269 : : }
6270 : : }
6271 : 27191 : result_type = c_common_type (eptype1, eptype2);
6272 : 27191 : if (result_type == error_mark_node)
6273 : : return error_mark_node;
6274 : 27189 : do_warn_double_promotion (result_type, type1, type2,
6275 : : "implicit conversion from %qT to %qT to "
6276 : : "match other result of conditional",
6277 : : colon_loc);
6278 : :
6279 : : /* If -Wsign-compare, warn here if type1 and type2 have
6280 : : different signedness. We'll promote the signed to unsigned
6281 : : and later code won't know it used to be different.
6282 : : Do this check on the original types, so that explicit casts
6283 : : will be considered, but default promotions won't. */
6284 : 27189 : if (c_inhibit_evaluation_warnings == 0)
6285 : : {
6286 : 26998 : int unsigned_op1 = TYPE_UNSIGNED (TREE_TYPE (orig_op1));
6287 : 26998 : int unsigned_op2 = TYPE_UNSIGNED (TREE_TYPE (orig_op2));
6288 : :
6289 : 26998 : if (unsigned_op1 ^ unsigned_op2)
6290 : : {
6291 : 12589 : bool ovf;
6292 : :
6293 : : /* Do not warn if the result type is signed, since the
6294 : : signed type will only be chosen if it can represent
6295 : : all the values of the unsigned type. */
6296 : 12589 : if (!TYPE_UNSIGNED (result_type))
6297 : : /* OK */;
6298 : : else
6299 : : {
6300 : 12485 : bool op1_maybe_const = true;
6301 : 12485 : bool op2_maybe_const = true;
6302 : :
6303 : : /* Do not warn if the signed quantity is an
6304 : : unsuffixed integer literal (or some static
6305 : : constant expression involving such literals) and
6306 : : it is non-negative. This warning requires the
6307 : : operands to be folded for best results, so do
6308 : : that folding in this case even without
6309 : : warn_sign_compare to avoid warning options
6310 : : possibly affecting code generation. */
6311 : 12485 : c_inhibit_evaluation_warnings
6312 : 12485 : += (ifexp == truthvalue_false_node);
6313 : 12485 : op1 = c_fully_fold (op1, require_constant_value,
6314 : : &op1_maybe_const);
6315 : 12485 : c_inhibit_evaluation_warnings
6316 : 12485 : -= (ifexp == truthvalue_false_node);
6317 : :
6318 : 12485 : c_inhibit_evaluation_warnings
6319 : 12485 : += (ifexp == truthvalue_true_node);
6320 : 12485 : op2 = c_fully_fold (op2, require_constant_value,
6321 : : &op2_maybe_const);
6322 : 12485 : c_inhibit_evaluation_warnings
6323 : 12485 : -= (ifexp == truthvalue_true_node);
6324 : :
6325 : 12485 : if (warn_sign_compare)
6326 : : {
6327 : 1241 : if ((unsigned_op2
6328 : 681 : && tree_expr_nonnegative_warnv_p (op1, &ovf))
6329 : 1244 : || (unsigned_op1
6330 : 560 : && tree_expr_nonnegative_warnv_p (op2, &ovf)))
6331 : : /* OK */;
6332 : 10 : else if (unsigned_op2)
6333 : 3 : warning_at (op1_loc, OPT_Wsign_compare,
6334 : : "operand of %<?:%> changes signedness from "
6335 : : "%qT to %qT due to unsignedness of other "
6336 : 3 : "operand", TREE_TYPE (orig_op1),
6337 : 3 : TREE_TYPE (orig_op2));
6338 : : else
6339 : 7 : warning_at (op2_loc, OPT_Wsign_compare,
6340 : : "operand of %<?:%> changes signedness from "
6341 : : "%qT to %qT due to unsignedness of other "
6342 : 7 : "operand", TREE_TYPE (orig_op2),
6343 : 7 : TREE_TYPE (orig_op1));
6344 : : }
6345 : 12485 : if (!op1_maybe_const || TREE_CODE (op1) != INTEGER_CST)
6346 : 7145 : op1 = c_wrap_maybe_const (op1, !op1_maybe_const);
6347 : 12485 : if (!op2_maybe_const || TREE_CODE (op2) != INTEGER_CST)
6348 : 4375 : op2 = c_wrap_maybe_const (op2, !op2_maybe_const);
6349 : : }
6350 : : }
6351 : : }
6352 : : }
6353 : 105805 : else if (code1 == VOID_TYPE || code2 == VOID_TYPE)
6354 : : {
6355 : 25995 : if (code1 != VOID_TYPE || code2 != VOID_TYPE)
6356 : 25995 : pedwarn (colon_loc, OPT_Wpedantic,
6357 : : "ISO C forbids conditional expr with only one void side");
6358 : 25995 : result_type = void_type_node;
6359 : : }
6360 : 79810 : else if (code1 == POINTER_TYPE && code2 == POINTER_TYPE)
6361 : : {
6362 : 79419 : addr_space_t as1 = TYPE_ADDR_SPACE (TREE_TYPE (type1));
6363 : 79419 : addr_space_t as2 = TYPE_ADDR_SPACE (TREE_TYPE (type2));
6364 : 79419 : addr_space_t as_common;
6365 : :
6366 : 79419 : if (comp_target_types (colon_loc, type1, type2))
6367 : 2584 : result_type = common_pointer_type (type1, type2);
6368 : 76835 : else if (null_pointer_constant_p (orig_op1))
6369 : : result_type = type2;
6370 : 72674 : else if (null_pointer_constant_p (orig_op2))
6371 : : result_type = type1;
6372 : 34791 : else if (!addr_space_superset (as1, as2, &as_common))
6373 : : {
6374 : 0 : error_at (colon_loc, "pointers to disjoint address spaces "
6375 : : "used in conditional expression");
6376 : 0 : return error_mark_node;
6377 : : }
6378 : 34791 : else if ((VOID_TYPE_P (TREE_TYPE (type1))
6379 : 322 : && !TYPE_ATOMIC (TREE_TYPE (type1)))
6380 : 34793 : || (VOID_TYPE_P (TREE_TYPE (type2))
6381 : 34424 : && !TYPE_ATOMIC (TREE_TYPE (type2))))
6382 : : {
6383 : 34743 : tree t1 = TREE_TYPE (type1);
6384 : 34743 : tree t2 = TREE_TYPE (type2);
6385 : 34743 : if (!(VOID_TYPE_P (t1)
6386 : 321 : && !TYPE_ATOMIC (t1)))
6387 : : {
6388 : : /* roles are swapped */
6389 : 34423 : t1 = t2;
6390 : 34423 : t2 = TREE_TYPE (type1);
6391 : : }
6392 : 34743 : tree t2_stripped = strip_array_types (t2);
6393 : 34743 : if ((TREE_CODE (t2) == ARRAY_TYPE)
6394 : 34743 : && (TYPE_QUALS (t2_stripped) & ~TYPE_QUALS (t1)))
6395 : : {
6396 : 18 : if (!flag_isoc23)
6397 : 6 : warning_at (colon_loc, OPT_Wdiscarded_array_qualifiers,
6398 : : "pointer to array loses qualifier "
6399 : : "in conditional expression");
6400 : 12 : else if (warn_c11_c23_compat > 0)
6401 : 6 : warning_at (colon_loc, OPT_Wc11_c23_compat,
6402 : : "pointer to array loses qualifier "
6403 : : "in conditional expression in ISO C before C23");
6404 : : }
6405 : 34743 : if (TREE_CODE (t2) == FUNCTION_TYPE)
6406 : 4 : pedwarn (colon_loc, OPT_Wpedantic,
6407 : : "ISO C forbids conditional expr between "
6408 : : "%<void *%> and function pointer");
6409 : : /* for array, use qualifiers of element type */
6410 : 34743 : if (flag_isoc23)
6411 : 11002 : t2 = t2_stripped;
6412 : 34743 : result_type = c_build_pointer_type (qualify_type (t1, t2));
6413 : : }
6414 : : /* Objective-C pointer comparisons are a bit more lenient. */
6415 : 48 : else if (objc_have_common_type (type1, type2, -3, NULL_TREE))
6416 : 0 : result_type = objc_common_type (type1, type2);
6417 : : else
6418 : : {
6419 : 48 : int qual = ENCODE_QUAL_ADDR_SPACE (as_common);
6420 : 48 : diagnostic_t kind = DK_PERMERROR;
6421 : 48 : if (!flag_isoc99)
6422 : : /* This downgrade to a warning ensures that -std=gnu89
6423 : : -pedantic-errors does not flag these mismatches between
6424 : : builtins as errors (as DK_PERMERROR would). ISO C99
6425 : : and later do not have implicit function declarations,
6426 : : so the mismatch cannot occur naturally there. */
6427 : 5 : kind = bltin1 && bltin2 ? DK_WARNING : DK_PEDWARN;
6428 : 48 : if (emit_diagnostic (kind, colon_loc, OPT_Wincompatible_pointer_types,
6429 : : "pointer type mismatch "
6430 : : "in conditional expression"))
6431 : : {
6432 : 46 : inform (op1_loc, "first expression has type %qT", type1);
6433 : 46 : inform (op2_loc, "second expression has type %qT", type2);
6434 : : }
6435 : 48 : result_type = c_build_pointer_type
6436 : 48 : (c_build_qualified_type (void_type_node, qual));
6437 : : }
6438 : : }
6439 : 391 : else if (code1 == POINTER_TYPE
6440 : 274 : && (code2 == INTEGER_TYPE || code2 == BITINT_TYPE))
6441 : : {
6442 : 270 : if (!null_pointer_constant_p (orig_op2))
6443 : 14 : permerror_opt (colon_loc, OPT_Wint_conversion,
6444 : : "pointer/integer type mismatch "
6445 : : "in conditional expression");
6446 : : else
6447 : : {
6448 : 256 : op2 = null_pointer_node;
6449 : : }
6450 : : result_type = type1;
6451 : : }
6452 : 121 : else if (code2 == POINTER_TYPE
6453 : 87 : && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
6454 : : {
6455 : 83 : if (!null_pointer_constant_p (orig_op1))
6456 : 14 : permerror_opt (colon_loc, OPT_Wint_conversion,
6457 : : "pointer/integer type mismatch "
6458 : : "in conditional expression");
6459 : : else
6460 : : {
6461 : 69 : op1 = null_pointer_node;
6462 : : }
6463 : : result_type = type2;
6464 : : }
6465 : : /* 6.5.15: "if one is a null pointer constant (other than a pointer) or has
6466 : : type nullptr_t and the other is a pointer, the result type is the pointer
6467 : : type." */
6468 : 38 : else if (code1 == NULLPTR_TYPE && code2 == POINTER_TYPE)
6469 : : result_type = type2;
6470 : 34 : else if (code1 == POINTER_TYPE && code2 == NULLPTR_TYPE)
6471 : : result_type = type1;
6472 : 8 : else if (RECORD_OR_UNION_TYPE_P (type1) && RECORD_OR_UNION_TYPE_P (type2)
6473 : 38 : && comptypes (TYPE_MAIN_VARIANT (type1),
6474 : 8 : TYPE_MAIN_VARIANT (type2)))
6475 : 8 : result_type = composite_type (TYPE_MAIN_VARIANT (type1),
6476 : 8 : TYPE_MAIN_VARIANT (type2));
6477 : :
6478 : 401478 : if (!result_type)
6479 : : {
6480 : 22 : if (flag_cond_mismatch)
6481 : 0 : result_type = void_type_node;
6482 : : else
6483 : : {
6484 : 22 : error_at (colon_loc, "type mismatch in conditional expression");
6485 : 22 : return error_mark_node;
6486 : : }
6487 : : }
6488 : :
6489 : : /* Merge const and volatile flags of the incoming types. */
6490 : 401478 : result_type
6491 : 401478 : = build_type_variant (result_type,
6492 : : TYPE_READONLY (type1) || TYPE_READONLY (type2),
6493 : : TYPE_VOLATILE (type1) || TYPE_VOLATILE (type2));
6494 : :
6495 : 401478 : op1 = ep_convert_and_check (colon_loc, result_type, op1,
6496 : : semantic_result_type);
6497 : 401478 : op2 = ep_convert_and_check (colon_loc, result_type, op2,
6498 : : semantic_result_type);
6499 : :
6500 : 401478 : if (ifexp_bcp && ifexp == truthvalue_true_node)
6501 : : {
6502 : 10 : op2_int_operands = true;
6503 : 10 : op1 = c_fully_fold (op1, require_constant_value, NULL);
6504 : : }
6505 : 59 : if (ifexp_bcp && ifexp == truthvalue_false_node)
6506 : : {
6507 : 49 : op1_int_operands = true;
6508 : 49 : op2 = c_fully_fold (op2, require_constant_value, NULL);
6509 : : }
6510 : 899934 : int_const = int_operands = (ifexp_int_operands
6511 : 401478 : && op1_int_operands
6512 : 401478 : && op2_int_operands);
6513 : 96978 : if (int_operands)
6514 : : {
6515 : 96978 : int_const = ((ifexp == truthvalue_true_node
6516 : 58600 : && TREE_CODE (orig_op1) == INTEGER_CST
6517 : 58586 : && !TREE_OVERFLOW (orig_op1))
6518 : 96992 : || (ifexp == truthvalue_false_node
6519 : 38332 : && TREE_CODE (orig_op2) == INTEGER_CST
6520 : 38316 : && !TREE_OVERFLOW (orig_op2)));
6521 : : }
6522 : :
6523 : : /* Need to convert condition operand into a vector mask. */
6524 : 401478 : if (VECTOR_TYPE_P (TREE_TYPE (ifexp)))
6525 : : {
6526 : 0 : tree vectype = TREE_TYPE (ifexp);
6527 : 0 : tree elem_type = TREE_TYPE (vectype);
6528 : 0 : tree zero = build_int_cst (elem_type, 0);
6529 : 0 : tree zero_vec = build_vector_from_val (vectype, zero);
6530 : 0 : tree cmp_type = truth_type_for (vectype);
6531 : 0 : ifexp = build2 (NE_EXPR, cmp_type, ifexp, zero_vec);
6532 : : }
6533 : :
6534 : 401478 : if (int_const || (ifexp_bcp && TREE_CODE (ifexp) == INTEGER_CST))
6535 : 96934 : ret = fold_build3_loc (colon_loc, COND_EXPR, result_type, ifexp, op1, op2);
6536 : : else
6537 : : {
6538 : 304544 : if (int_operands)
6539 : : {
6540 : : /* Use c_fully_fold here, since C_MAYBE_CONST_EXPR might be
6541 : : nested inside of the expression. */
6542 : 76 : op1 = c_fully_fold (op1, false, NULL);
6543 : 76 : op2 = c_fully_fold (op2, false, NULL);
6544 : : }
6545 : 304544 : ret = build3 (COND_EXPR, result_type, ifexp, op1, op2);
6546 : 304544 : if (int_operands)
6547 : 76 : ret = note_integer_operands (ret);
6548 : : }
6549 : 401478 : if (semantic_result_type)
6550 : 4627 : ret = build1 (EXCESS_PRECISION_EXPR, semantic_result_type, ret);
6551 : :
6552 : 401478 : protected_set_expr_location (ret, colon_loc);
6553 : :
6554 : : /* If the OP1 and OP2 are the same and don't have side-effects,
6555 : : warn here, because the COND_EXPR will be turned into OP1. */
6556 : 401478 : if (warn_duplicated_branches
6557 : 34 : && TREE_CODE (ret) == COND_EXPR
6558 : 401512 : && (op1 == op2 || operand_equal_p (op1, op2, OEP_ADDRESS_OF_SAME_FIELD)))
6559 : 13 : warning_at (EXPR_LOCATION (ret), OPT_Wduplicated_branches,
6560 : : "this condition has identical branches");
6561 : :
6562 : : return ret;
6563 : : }
6564 : :
6565 : : /* EXPR is an expression, location LOC, whose result is discarded.
6566 : : Warn if it is a call to a nodiscard function (or a COMPOUND_EXPR
6567 : : whose right-hand operand is such a call, possibly recursively). */
6568 : :
6569 : : static void
6570 : 6333437 : maybe_warn_nodiscard (location_t loc, tree expr)
6571 : : {
6572 : 6333437 : if (VOID_TYPE_P (TREE_TYPE (expr)))
6573 : : return;
6574 : 3873566 : while (TREE_CODE (expr) == COMPOUND_EXPR)
6575 : : {
6576 : 48904 : expr = TREE_OPERAND (expr, 1);
6577 : 48904 : if (EXPR_HAS_LOCATION (expr))
6578 : 31813 : loc = EXPR_LOCATION (expr);
6579 : : }
6580 : 3824662 : if (TREE_CODE (expr) != CALL_EXPR)
6581 : : return;
6582 : 341718 : tree fn = CALL_EXPR_FN (expr);
6583 : 341718 : if (!fn)
6584 : : return;
6585 : 341705 : tree attr;
6586 : 341705 : if (TREE_CODE (fn) == ADDR_EXPR
6587 : 341040 : && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL
6588 : 682745 : && (attr = lookup_attribute ("nodiscard",
6589 : 341040 : DECL_ATTRIBUTES (TREE_OPERAND (fn, 0)))))
6590 : : {
6591 : 3 : fn = TREE_OPERAND (fn, 0);
6592 : 3 : tree args = TREE_VALUE (attr);
6593 : 3 : if (args)
6594 : 1 : args = TREE_VALUE (args);
6595 : 3 : auto_diagnostic_group d;
6596 : 3 : auto_urlify_attributes sentinel;
6597 : 3 : int warned;
6598 : 3 : if (args)
6599 : 1 : warned = warning_at (loc, OPT_Wunused_result,
6600 : : "ignoring return value of %qD, declared with "
6601 : : "attribute %<nodiscard%>: %E", fn, args);
6602 : : else
6603 : 2 : warned = warning_at (loc, OPT_Wunused_result,
6604 : : "ignoring return value of %qD, declared with "
6605 : : "attribute %<nodiscard%>", fn);
6606 : 3 : if (warned)
6607 : 3 : inform (DECL_SOURCE_LOCATION (fn), "declared here");
6608 : 3 : }
6609 : : else
6610 : : {
6611 : 341702 : tree rettype = TREE_TYPE (TREE_TYPE (TREE_TYPE (fn)));
6612 : 341702 : attr = lookup_attribute ("nodiscard", TYPE_ATTRIBUTES (rettype));
6613 : 341702 : if (!attr)
6614 : 341690 : return;
6615 : 12 : tree args = TREE_VALUE (attr);
6616 : 12 : if (args)
6617 : 5 : args = TREE_VALUE (args);
6618 : 12 : auto_diagnostic_group d;
6619 : 12 : auto_urlify_attributes sentinel;
6620 : 12 : int warned;
6621 : 12 : if (args)
6622 : 5 : warned = warning_at (loc, OPT_Wunused_result,
6623 : : "ignoring return value of type %qT, declared "
6624 : : "with attribute %<nodiscard%>: %E",
6625 : : rettype, args);
6626 : : else
6627 : 7 : warned = warning_at (loc, OPT_Wunused_result,
6628 : : "ignoring return value of type %qT, declared "
6629 : : "with attribute %<nodiscard%>", rettype);
6630 : 12 : if (warned)
6631 : : {
6632 : 12 : if (TREE_CODE (fn) == ADDR_EXPR)
6633 : : {
6634 : 11 : fn = TREE_OPERAND (fn, 0);
6635 : 11 : if (TREE_CODE (fn) == FUNCTION_DECL)
6636 : 11 : inform (DECL_SOURCE_LOCATION (fn),
6637 : : "in call to %qD, declared here", fn);
6638 : : }
6639 : : }
6640 : 12 : }
6641 : : }
6642 : :
6643 : : /* Return a compound expression that performs two expressions and
6644 : : returns the value of the second of them.
6645 : :
6646 : : LOC is the location of the COMPOUND_EXPR. */
6647 : :
6648 : : tree
6649 : 103555 : build_compound_expr (location_t loc, tree expr1, tree expr2)
6650 : : {
6651 : 103555 : bool expr1_int_operands, expr2_int_operands;
6652 : 103555 : tree eptype = NULL_TREE;
6653 : 103555 : tree ret;
6654 : :
6655 : 103555 : expr1_int_operands = EXPR_INT_CONST_OPERANDS (expr1);
6656 : 325 : if (expr1_int_operands)
6657 : 325 : expr1 = remove_c_maybe_const_expr (expr1);
6658 : 103555 : expr2_int_operands = EXPR_INT_CONST_OPERANDS (expr2);
6659 : 59787 : if (expr2_int_operands)
6660 : 59787 : expr2 = remove_c_maybe_const_expr (expr2);
6661 : :
6662 : 103555 : if (TREE_CODE (expr1) == EXCESS_PRECISION_EXPR)
6663 : 0 : expr1 = TREE_OPERAND (expr1, 0);
6664 : 103555 : if (TREE_CODE (expr2) == EXCESS_PRECISION_EXPR)
6665 : : {
6666 : 1 : eptype = TREE_TYPE (expr2);
6667 : 1 : expr2 = TREE_OPERAND (expr2, 0);
6668 : : }
6669 : :
6670 : 103555 : if (!TREE_SIDE_EFFECTS (expr1))
6671 : : {
6672 : : /* The left-hand operand of a comma expression is like an expression
6673 : : statement: with -Wunused, we should warn if it doesn't have
6674 : : any side-effects, unless it was explicitly cast to (void). */
6675 : 7035 : if (warn_unused_value)
6676 : : {
6677 : 1241 : if (VOID_TYPE_P (TREE_TYPE (expr1))
6678 : 1241 : && CONVERT_EXPR_P (expr1))
6679 : : ; /* (void) a, b */
6680 : 14 : else if (VOID_TYPE_P (TREE_TYPE (expr1))
6681 : 4 : && TREE_CODE (expr1) == COMPOUND_EXPR
6682 : 17 : && CONVERT_EXPR_P (TREE_OPERAND (expr1, 1)))
6683 : : ; /* (void) a, (void) b, c */
6684 : : else
6685 : 11 : warning_at (loc, OPT_Wunused_value,
6686 : : "left-hand operand of comma expression has no effect");
6687 : : }
6688 : : }
6689 : 96520 : else if (TREE_CODE (expr1) == COMPOUND_EXPR
6690 : 13104 : && warn_unused_value)
6691 : : {
6692 : : tree r = expr1;
6693 : : location_t cloc = loc;
6694 : 4833 : while (TREE_CODE (r) == COMPOUND_EXPR)
6695 : : {
6696 : 2417 : if (EXPR_HAS_LOCATION (r))
6697 : 2417 : cloc = EXPR_LOCATION (r);
6698 : 2417 : r = TREE_OPERAND (r, 1);
6699 : : }
6700 : 2416 : if (!TREE_SIDE_EFFECTS (r)
6701 : 4 : && !VOID_TYPE_P (TREE_TYPE (r))
6702 : 2420 : && !CONVERT_EXPR_P (r))
6703 : 4 : warning_at (cloc, OPT_Wunused_value,
6704 : : "right-hand operand of comma expression has no effect");
6705 : : }
6706 : :
6707 : : /* With -Wunused, we should also warn if the left-hand operand does have
6708 : : side-effects, but computes a value which is not used. For example, in
6709 : : `foo() + bar(), baz()' the result of the `+' operator is not used,
6710 : : so we should issue a warning. */
6711 : 94104 : else if (warn_unused_value)
6712 : 35362 : warn_if_unused_value (expr1, loc);
6713 : :
6714 : 103555 : maybe_warn_nodiscard (loc, expr1);
6715 : :
6716 : 103555 : if (expr2 == error_mark_node)
6717 : : return error_mark_node;
6718 : :
6719 : 103542 : ret = build2 (COMPOUND_EXPR, TREE_TYPE (expr2), expr1, expr2);
6720 : :
6721 : 103542 : if (flag_isoc99
6722 : : && expr1_int_operands
6723 : 103086 : && expr2_int_operands)
6724 : 152 : ret = note_integer_operands (ret);
6725 : :
6726 : 103542 : if (eptype)
6727 : 1 : ret = build1 (EXCESS_PRECISION_EXPR, eptype, ret);
6728 : :
6729 : 103542 : protected_set_expr_location (ret, loc);
6730 : 103542 : return ret;
6731 : : }
6732 : :
6733 : : /* Issue -Wcast-qual warnings when appropriate. TYPE is the type to
6734 : : which we are casting. OTYPE is the type of the expression being
6735 : : cast. Both TYPE and OTYPE are pointer types. LOC is the location
6736 : : of the cast. -Wcast-qual appeared on the command line. Named
6737 : : address space qualifiers are not handled here, because they result
6738 : : in different warnings. */
6739 : :
6740 : : static void
6741 : 13405 : handle_warn_cast_qual (location_t loc, tree type, tree otype)
6742 : : {
6743 : 13405 : tree in_type = type;
6744 : 13405 : tree in_otype = otype;
6745 : 13405 : int added = 0;
6746 : 13405 : int discarded = 0;
6747 : 13575 : bool is_const;
6748 : :
6749 : : /* Check that the qualifiers on IN_TYPE are a superset of the
6750 : : qualifiers of IN_OTYPE. The outermost level of POINTER_TYPE
6751 : : nodes is uninteresting and we stop as soon as we hit a
6752 : : non-POINTER_TYPE node on either type. */
6753 : 13575 : do
6754 : : {
6755 : 13575 : in_otype = TREE_TYPE (in_otype);
6756 : 13575 : in_type = TREE_TYPE (in_type);
6757 : :
6758 : : /* GNU C allows cv-qualified function types. 'const' means the
6759 : : function is very pure, 'volatile' means it can't return. We
6760 : : need to warn when such qualifiers are added, not when they're
6761 : : taken away. */
6762 : 13575 : if (TREE_CODE (in_otype) == FUNCTION_TYPE
6763 : 26 : && TREE_CODE (in_type) == FUNCTION_TYPE)
6764 : 18 : added |= (TYPE_QUALS_NO_ADDR_SPACE (in_type)
6765 : 18 : & ~TYPE_QUALS_NO_ADDR_SPACE (in_otype));
6766 : : else
6767 : 13557 : discarded |= (TYPE_QUALS_NO_ADDR_SPACE (in_otype)
6768 : 13557 : & ~TYPE_QUALS_NO_ADDR_SPACE (in_type));
6769 : : }
6770 : 13575 : while (TREE_CODE (in_type) == POINTER_TYPE
6771 : 13575 : && TREE_CODE (in_otype) == POINTER_TYPE);
6772 : :
6773 : 13405 : if (added)
6774 : 2 : warning_at (loc, OPT_Wcast_qual,
6775 : : "cast adds %q#v qualifier to function type", added);
6776 : :
6777 : 13405 : if (discarded)
6778 : : /* There are qualifiers present in IN_OTYPE that are not present
6779 : : in IN_TYPE. */
6780 : 1117 : warning_at (loc, OPT_Wcast_qual,
6781 : : "cast discards %qv qualifier from pointer target type",
6782 : : discarded);
6783 : :
6784 : 13405 : if (added || discarded)
6785 : : return;
6786 : :
6787 : : /* A cast from **T to const **T is unsafe, because it can cause a
6788 : : const value to be changed with no additional warning. We only
6789 : : issue this warning if T is the same on both sides, and we only
6790 : : issue the warning if there are the same number of pointers on
6791 : : both sides, as otherwise the cast is clearly unsafe anyhow. A
6792 : : cast is unsafe when a qualifier is added at one level and const
6793 : : is not present at all outer levels.
6794 : :
6795 : : To issue this warning, we check at each level whether the cast
6796 : : adds new qualifiers not already seen. We don't need to special
6797 : : case function types, as they won't have the same
6798 : : TYPE_MAIN_VARIANT. */
6799 : :
6800 : 12286 : if (TYPE_MAIN_VARIANT (in_type) != TYPE_MAIN_VARIANT (in_otype))
6801 : : return;
6802 : 51 : if (TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE)
6803 : : return;
6804 : :
6805 : 48 : in_type = type;
6806 : 48 : in_otype = otype;
6807 : 48 : is_const = TYPE_READONLY (TREE_TYPE (in_type));
6808 : 130 : do
6809 : : {
6810 : 130 : in_type = TREE_TYPE (in_type);
6811 : 130 : in_otype = TREE_TYPE (in_otype);
6812 : 130 : if ((TYPE_QUALS (in_type) &~ TYPE_QUALS (in_otype)) != 0
6813 : 130 : && !is_const)
6814 : : {
6815 : 27 : warning_at (loc, OPT_Wcast_qual,
6816 : : "to be safe all intermediate pointers in cast from "
6817 : : "%qT to %qT must be %<const%> qualified",
6818 : : otype, type);
6819 : 27 : break;
6820 : : }
6821 : 103 : if (is_const)
6822 : 72 : is_const = TYPE_READONLY (in_type);
6823 : : }
6824 : 103 : while (TREE_CODE (in_type) == POINTER_TYPE);
6825 : : }
6826 : :
6827 : : /* Heuristic check if two parameter types can be considered ABI-equivalent. */
6828 : :
6829 : : static bool
6830 : 1067 : c_safe_arg_type_equiv_p (tree t1, tree t2)
6831 : : {
6832 : 1067 : if (error_operand_p (t1) || error_operand_p (t2))
6833 : : return true;
6834 : :
6835 : 1066 : t1 = TYPE_MAIN_VARIANT (t1);
6836 : 1066 : t2 = TYPE_MAIN_VARIANT (t2);
6837 : :
6838 : 1066 : if (TREE_CODE (t1) == POINTER_TYPE
6839 : 114 : && TREE_CODE (t2) == POINTER_TYPE)
6840 : : return true;
6841 : :
6842 : : /* Only the precision of the parameter matters. This check should
6843 : : make sure that the callee does not see undefined values in argument
6844 : : registers. */
6845 : 974 : if (INTEGRAL_TYPE_P (t1)
6846 : 869 : && INTEGRAL_TYPE_P (t2)
6847 : 1275 : && TYPE_PRECISION (t1) == TYPE_PRECISION (t2))
6848 : : return true;
6849 : :
6850 : 853 : return comptypes (t1, t2);
6851 : : }
6852 : :
6853 : : /* Check if a type cast between two function types can be considered safe. */
6854 : :
6855 : : static bool
6856 : 7420 : c_safe_function_type_cast_p (tree t1, tree t2)
6857 : : {
6858 : 7420 : if (TREE_TYPE (t1) == void_type_node &&
6859 : 5437 : TYPE_ARG_TYPES (t1) == void_list_node)
6860 : : return true;
6861 : :
6862 : 3665 : if (TREE_TYPE (t2) == void_type_node &&
6863 : 2862 : TYPE_ARG_TYPES (t2) == void_list_node)
6864 : : return true;
6865 : :
6866 : 835 : if (!c_safe_arg_type_equiv_p (TREE_TYPE (t1), TREE_TYPE (t2)))
6867 : : return false;
6868 : :
6869 : 153 : for (t1 = TYPE_ARG_TYPES (t1), t2 = TYPE_ARG_TYPES (t2);
6870 : 281 : t1 && t2;
6871 : 128 : t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
6872 : 232 : if (!c_safe_arg_type_equiv_p (TREE_VALUE (t1), TREE_VALUE (t2)))
6873 : : return false;
6874 : :
6875 : : return true;
6876 : : }
6877 : :
6878 : : /* Build an expression representing a cast to type TYPE of expression EXPR.
6879 : : LOC is the location of the cast-- typically the open paren of the cast. */
6880 : :
6881 : : tree
6882 : 117048298 : build_c_cast (location_t loc, tree type, tree expr)
6883 : : {
6884 : 117048298 : tree value;
6885 : :
6886 : 117048298 : bool int_operands = EXPR_INT_CONST_OPERANDS (expr);
6887 : :
6888 : 117048298 : if (TREE_CODE (expr) == EXCESS_PRECISION_EXPR)
6889 : 66 : expr = TREE_OPERAND (expr, 0);
6890 : :
6891 : 117048298 : value = expr;
6892 : 117048298 : if (int_operands)
6893 : 6703679 : value = remove_c_maybe_const_expr (value);
6894 : :
6895 : 117048298 : if (type == error_mark_node || expr == error_mark_node)
6896 : : return error_mark_node;
6897 : :
6898 : : /* The ObjC front-end uses TYPE_MAIN_VARIANT to tie together types differing
6899 : : only in <protocol> qualifications. But when constructing cast expressions,
6900 : : the protocols do matter and must be kept around. */
6901 : 117047277 : if (objc_is_object_ptr (type) && objc_is_object_ptr (TREE_TYPE (expr)))
6902 : 0 : return build1 (NOP_EXPR, type, expr);
6903 : :
6904 : 117047277 : type = TYPE_MAIN_VARIANT (type);
6905 : :
6906 : 117047277 : if (TREE_CODE (type) == ARRAY_TYPE)
6907 : : {
6908 : 13 : error_at (loc, "cast specifies array type");
6909 : 13 : return error_mark_node;
6910 : : }
6911 : :
6912 : 117047264 : if (TREE_CODE (type) == FUNCTION_TYPE)
6913 : : {
6914 : 6 : error_at (loc, "cast specifies function type");
6915 : 6 : return error_mark_node;
6916 : : }
6917 : :
6918 : 117047258 : if (!VOID_TYPE_P (type))
6919 : : {
6920 : 117004572 : value = require_complete_type (loc, value);
6921 : 117004572 : if (value == error_mark_node)
6922 : : return error_mark_node;
6923 : : }
6924 : :
6925 : 117047258 : if (type == TYPE_MAIN_VARIANT (TREE_TYPE (value)))
6926 : : {
6927 : 17617558 : if (RECORD_OR_UNION_TYPE_P (type)
6928 : 17617558 : && pedwarn (loc, OPT_Wpedantic,
6929 : : "ISO C forbids casting nonscalar to the same type"))
6930 : : ;
6931 : 17617554 : else if (warn_useless_cast)
6932 : 7 : warning_at (loc, OPT_Wuseless_cast,
6933 : : "useless cast to type %qT", type);
6934 : :
6935 : : /* Convert to remove any qualifiers from VALUE's type. */
6936 : 17617558 : value = convert (type, value);
6937 : : }
6938 : 99429700 : else if (TREE_CODE (type) == UNION_TYPE)
6939 : : {
6940 : 128 : tree field;
6941 : :
6942 : 182 : for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
6943 : 176 : if (TREE_TYPE (field) != error_mark_node
6944 : 351 : && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (field)),
6945 : 175 : TYPE_MAIN_VARIANT (TREE_TYPE (value))))
6946 : : break;
6947 : :
6948 : 128 : if (field)
6949 : : {
6950 : 122 : tree t;
6951 : 122 : bool maybe_const = true;
6952 : :
6953 : 122 : pedwarn (loc, OPT_Wpedantic, "ISO C forbids casts to union type");
6954 : 122 : t = c_fully_fold (value, false, &maybe_const);
6955 : 122 : t = build_constructor_single (type, field, t);
6956 : 122 : if (!maybe_const)
6957 : 8 : t = c_wrap_maybe_const (t, true);
6958 : 122 : t = digest_init (loc, field, type, t,
6959 : : NULL_TREE, false, false, false, true, false, false);
6960 : 122 : TREE_CONSTANT (t) = TREE_CONSTANT (value);
6961 : 122 : return t;
6962 : : }
6963 : 6 : error_at (loc, "cast to union type from type not present in union");
6964 : 6 : return error_mark_node;
6965 : : }
6966 : : else
6967 : : {
6968 : 99429572 : tree otype, ovalue;
6969 : :
6970 : 99429572 : if (type == void_type_node)
6971 : : {
6972 : 16730 : tree t = build1 (CONVERT_EXPR, type, value);
6973 : 16730 : SET_EXPR_LOCATION (t, loc);
6974 : 16730 : return t;
6975 : : }
6976 : :
6977 : 99412842 : otype = TREE_TYPE (value);
6978 : :
6979 : : /* Optionally warn about potentially worrisome casts. */
6980 : 99412842 : if (warn_cast_qual
6981 : 179273 : && TREE_CODE (type) == POINTER_TYPE
6982 : 26423 : && TREE_CODE (otype) == POINTER_TYPE)
6983 : 13405 : handle_warn_cast_qual (loc, type, otype);
6984 : :
6985 : : /* Warn about conversions between pointers to disjoint
6986 : : address spaces. */
6987 : 99412842 : if (TREE_CODE (type) == POINTER_TYPE
6988 : 3278106 : && TREE_CODE (otype) == POINTER_TYPE
6989 : 102349457 : && !null_pointer_constant_p (value))
6990 : : {
6991 : 2883994 : addr_space_t as_to = TYPE_ADDR_SPACE (TREE_TYPE (type));
6992 : 2883994 : addr_space_t as_from = TYPE_ADDR_SPACE (TREE_TYPE (otype));
6993 : 2883994 : addr_space_t as_common;
6994 : :
6995 : 2883994 : if (!addr_space_superset (as_to, as_from, &as_common))
6996 : : {
6997 : 0 : if (ADDR_SPACE_GENERIC_P (as_from))
6998 : 0 : warning_at (loc, 0, "cast to %qs address space pointer "
6999 : : "from disjoint generic address space pointer",
7000 : : c_addr_space_name (as_to));
7001 : :
7002 : 0 : else if (ADDR_SPACE_GENERIC_P (as_to))
7003 : 0 : warning_at (loc, 0, "cast to generic address space pointer "
7004 : : "from disjoint %qs address space pointer",
7005 : : c_addr_space_name (as_from));
7006 : :
7007 : : else
7008 : 0 : warning_at (loc, 0, "cast to %qs address space pointer "
7009 : : "from disjoint %qs address space pointer",
7010 : : c_addr_space_name (as_to),
7011 : : c_addr_space_name (as_from));
7012 : : }
7013 : :
7014 : : /* Warn of new allocations that are not big enough for the target
7015 : : type. */
7016 : 2883994 : if (warn_alloc_size && TREE_CODE (value) == CALL_EXPR)
7017 : 805 : if (tree fndecl = get_callee_fndecl (value))
7018 : 801 : if (DECL_IS_MALLOC (fndecl))
7019 : : {
7020 : 517 : tree attrs = TYPE_ATTRIBUTES (TREE_TYPE (fndecl));
7021 : 517 : tree alloc_size = lookup_attribute ("alloc_size", attrs);
7022 : 517 : if (alloc_size)
7023 : 159 : warn_for_alloc_size (loc, TREE_TYPE (type), value,
7024 : : alloc_size);
7025 : : }
7026 : : }
7027 : :
7028 : : /* Warn about possible alignment problems. */
7029 : 99412842 : if ((STRICT_ALIGNMENT || warn_cast_align == 2)
7030 : 7 : && TREE_CODE (type) == POINTER_TYPE
7031 : 7 : && TREE_CODE (otype) == POINTER_TYPE
7032 : 7 : && TREE_CODE (TREE_TYPE (otype)) != VOID_TYPE
7033 : 7 : && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
7034 : : /* Don't warn about opaque types, where the actual alignment
7035 : : restriction is unknown. */
7036 : 12 : && !(RECORD_OR_UNION_TYPE_P (TREE_TYPE (otype))
7037 : 5 : && TYPE_MODE (TREE_TYPE (otype)) == VOIDmode)
7038 : 99412856 : && min_align_of_type (TREE_TYPE (type))
7039 : 7 : > min_align_of_type (TREE_TYPE (otype)))
7040 : 5 : warning_at (loc, OPT_Wcast_align,
7041 : : "cast increases required alignment of target type");
7042 : :
7043 : 99412842 : if ((TREE_CODE (type) == INTEGER_TYPE
7044 : 99412842 : || TREE_CODE (type) == BITINT_TYPE)
7045 : 6908434 : && TREE_CODE (otype) == POINTER_TYPE
7046 : 99437722 : && TYPE_PRECISION (type) != TYPE_PRECISION (otype))
7047 : : /* Unlike conversion of integers to pointers, where the
7048 : : warning is disabled for converting constants because
7049 : : of cases such as SIG_*, warn about converting constant
7050 : : pointers to integers. In some cases it may cause unwanted
7051 : : sign extension, and a warning is appropriate. */
7052 : 1449 : warning_at (loc, OPT_Wpointer_to_int_cast,
7053 : : "cast from pointer to integer of different size");
7054 : :
7055 : 99412842 : if (TREE_CODE (value) == CALL_EXPR
7056 : 33747899 : && TREE_CODE (type) != TREE_CODE (otype))
7057 : 2284 : warning_at (loc, OPT_Wbad_function_cast,
7058 : : "cast from function call of type %qT "
7059 : : "to non-matching type %qT", otype, type);
7060 : :
7061 : 99412842 : if (TREE_CODE (type) == POINTER_TYPE
7062 : 3278106 : && (TREE_CODE (otype) == INTEGER_TYPE
7063 : 3278106 : || TREE_CODE (otype) == BITINT_TYPE)
7064 : 341413 : && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
7065 : : /* Don't warn about converting any constant. */
7066 : 99717401 : && !TREE_CONSTANT (value))
7067 : 407 : warning_at (loc,
7068 : 407 : OPT_Wint_to_pointer_cast, "cast to pointer from integer "
7069 : : "of different size");
7070 : :
7071 : 99412842 : if (warn_strict_aliasing <= 2)
7072 : 90900081 : strict_aliasing_warning (EXPR_LOCATION (value), type, expr);
7073 : :
7074 : : /* If pedantic, warn for conversions between function and object
7075 : : pointer types, except for converting a null pointer constant
7076 : : to function pointer type. */
7077 : 99412842 : if (pedantic
7078 : 238799 : && TREE_CODE (type) == POINTER_TYPE
7079 : 144158 : && TREE_CODE (otype) == POINTER_TYPE
7080 : 2769 : && TREE_CODE (TREE_TYPE (otype)) == FUNCTION_TYPE
7081 : 99412863 : && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE)
7082 : 18 : pedwarn (loc, OPT_Wpedantic, "ISO C forbids "
7083 : : "conversion of function pointer to object pointer type");
7084 : :
7085 : 99412842 : if (pedantic
7086 : 238799 : && TREE_CODE (type) == POINTER_TYPE
7087 : 144158 : && TREE_CODE (otype) == POINTER_TYPE
7088 : 2769 : && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
7089 : 13 : && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
7090 : 99412852 : && !null_pointer_constant_p (value))
7091 : 4 : pedwarn (loc, OPT_Wpedantic, "ISO C forbids "
7092 : : "conversion of object pointer to function pointer type");
7093 : :
7094 : 99412842 : if (TREE_CODE (type) == POINTER_TYPE
7095 : 3278106 : && TREE_CODE (otype) == POINTER_TYPE
7096 : 2936615 : && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
7097 : 8482 : && TREE_CODE (TREE_TYPE (otype)) == FUNCTION_TYPE
7098 : 99420262 : && !c_safe_function_type_cast_p (TREE_TYPE (type),
7099 : 7420 : TREE_TYPE (otype)))
7100 : 786 : warning_at (loc, OPT_Wcast_function_type,
7101 : : "cast between incompatible function types"
7102 : : " from %qT to %qT", otype, type);
7103 : :
7104 : 99412842 : ovalue = value;
7105 : : /* If converting to boolean a value with integer operands that
7106 : : is not itself represented as an INTEGER_CST, the call below
7107 : : to note_integer_operands may insert a C_MAYBE_CONST_EXPR, but
7108 : : build_binary_op as called by c_common_truthvalue_conversion
7109 : : may also insert a C_MAYBE_CONST_EXPR to indicate that a
7110 : : subexpression has been fully folded. To avoid nested
7111 : : C_MAYBE_CONST_EXPR, ensure that
7112 : : c_objc_common_truthvalue_conversion receives an argument
7113 : : properly marked as having integer operands in that case. */
7114 : 99412842 : if (int_operands
7115 : 6516118 : && TREE_CODE (value) != INTEGER_CST
7116 : 99412884 : && (TREE_CODE (type) == BOOLEAN_TYPE
7117 : 28 : || (TREE_CODE (type) == ENUMERAL_TYPE
7118 : 14 : && ENUM_UNDERLYING_TYPE (type) != NULL_TREE
7119 : 14 : && TREE_CODE (ENUM_UNDERLYING_TYPE (type)) == BOOLEAN_TYPE)))
7120 : 28 : value = note_integer_operands (value);
7121 : 99412842 : value = convert (type, value);
7122 : :
7123 : : /* Ignore any integer overflow caused by the cast. */
7124 : 99412842 : if (TREE_CODE (value) == INTEGER_CST && !FLOAT_TYPE_P (otype))
7125 : : {
7126 : 6462639 : if (TREE_OVERFLOW_P (ovalue))
7127 : : {
7128 : 9 : if (!TREE_OVERFLOW (value))
7129 : : {
7130 : : /* Avoid clobbering a shared constant. */
7131 : 0 : value = copy_node (value);
7132 : 0 : TREE_OVERFLOW (value) = TREE_OVERFLOW (ovalue);
7133 : : }
7134 : : }
7135 : 6462630 : else if (TREE_OVERFLOW (value))
7136 : : /* Reset VALUE's overflow flags, ensuring constant sharing. */
7137 : 3085 : value = wide_int_to_tree (TREE_TYPE (value), wi::to_wide (value));
7138 : : }
7139 : : }
7140 : :
7141 : : /* Don't let a cast be an lvalue. */
7142 : 117030400 : if (lvalue_p (value))
7143 : 88553 : value = non_lvalue_loc (loc, value);
7144 : :
7145 : : /* Don't allow the results of casting to floating-point or complex
7146 : : types be confused with actual constants, or casts involving
7147 : : integer and pointer types other than direct integer-to-integer
7148 : : and integer-to-pointer be confused with integer constant
7149 : : expressions and null pointer constants. */
7150 : 117030400 : if (TREE_CODE (value) == REAL_CST
7151 : 116980622 : || TREE_CODE (value) == COMPLEX_CST
7152 : 233988399 : || (TREE_CODE (value) == INTEGER_CST
7153 : 6709094 : && !((TREE_CODE (expr) == INTEGER_CST
7154 : 6636737 : && INTEGRAL_TYPE_P (TREE_TYPE (expr)))
7155 : 64954 : || TREE_CODE (expr) == REAL_CST
7156 : : || TREE_CODE (expr) == COMPLEX_CST)))
7157 : 132988 : value = build1 (NOP_EXPR, type, value);
7158 : :
7159 : : /* If the expression has integer operands and so can occur in an
7160 : : unevaluated part of an integer constant expression, ensure the
7161 : : return value reflects this. */
7162 : 117030400 : if (int_operands
7163 : 6691155 : && INTEGRAL_TYPE_P (type)
7164 : 6251028 : && value != error_mark_node
7165 : 123281427 : && !EXPR_INT_CONST_OPERANDS (value))
7166 : 11 : value = note_integer_operands (value);
7167 : :
7168 : 117030400 : protected_set_expr_location (value, loc);
7169 : 117030400 : return value;
7170 : : }
7171 : :
7172 : : /* Interpret a cast of expression EXPR to type TYPE. LOC is the
7173 : : location of the open paren of the cast, or the position of the cast
7174 : : expr. */
7175 : : tree
7176 : 117047952 : c_cast_expr (location_t loc, struct c_type_name *type_name, tree expr)
7177 : : {
7178 : 117047952 : tree type;
7179 : 117047952 : tree type_expr = NULL_TREE;
7180 : 117047952 : bool type_expr_const = true;
7181 : 117047952 : tree ret;
7182 : 117047952 : int saved_wsp = warn_strict_prototypes;
7183 : :
7184 : : /* This avoids warnings about unprototyped casts on
7185 : : integers. E.g. "#define SIG_DFL (void(*)())0". */
7186 : 117047952 : if (TREE_CODE (expr) == INTEGER_CST)
7187 : 6756557 : warn_strict_prototypes = 0;
7188 : 117047952 : type = groktypename (type_name, &type_expr, &type_expr_const);
7189 : 117047952 : warn_strict_prototypes = saved_wsp;
7190 : :
7191 : 764514 : if (TREE_CODE (expr) == ADDR_EXPR && !VOID_TYPE_P (type)
7192 : 117812229 : && reject_gcc_builtin (expr))
7193 : 2 : return error_mark_node;
7194 : :
7195 : 117047950 : ret = build_c_cast (loc, type, expr);
7196 : 117047950 : if (ret == error_mark_node)
7197 : : return error_mark_node;
7198 : :
7199 : 117046800 : if (type_expr)
7200 : : {
7201 : 203 : bool inner_expr_const = true;
7202 : 203 : ret = c_fully_fold (ret, require_constant_value, &inner_expr_const);
7203 : 203 : ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret), type_expr, ret);
7204 : 406 : C_MAYBE_CONST_EXPR_NON_CONST (ret) = !(type_expr_const
7205 : 129 : && inner_expr_const);
7206 : 203 : SET_EXPR_LOCATION (ret, loc);
7207 : : }
7208 : :
7209 : 117046800 : if (!EXPR_HAS_LOCATION (ret))
7210 : 6637583 : protected_set_expr_location (ret, loc);
7211 : :
7212 : : /* C++ does not permits types to be defined in a cast, but it
7213 : : allows references to incomplete types. */
7214 : 117046800 : if (warn_cxx_compat && type_name->specs->typespec_kind == ctsk_tagdef)
7215 : 1 : warning_at (loc, OPT_Wc___compat,
7216 : : "defining a type in a cast is invalid in C++");
7217 : :
7218 : : return ret;
7219 : : }
7220 : :
7221 : : /* Build an assignment expression of lvalue LHS from value RHS.
7222 : : If LHS_ORIGTYPE is not NULL, it is the original type of LHS, which
7223 : : may differ from TREE_TYPE (LHS) for an enum bitfield.
7224 : : MODIFYCODE is the code for a binary operator that we use
7225 : : to combine the old value of LHS with RHS to get the new value.
7226 : : Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.
7227 : : If RHS_ORIGTYPE is not NULL_TREE, it is the original type of RHS,
7228 : : which may differ from TREE_TYPE (RHS) for an enum value.
7229 : :
7230 : : LOCATION is the location of the MODIFYCODE operator.
7231 : : RHS_LOC is the location of the RHS. */
7232 : :
7233 : : tree
7234 : 2839202 : build_modify_expr (location_t location, tree lhs, tree lhs_origtype,
7235 : : enum tree_code modifycode,
7236 : : location_t rhs_loc, tree rhs, tree rhs_origtype)
7237 : : {
7238 : 2839202 : tree result;
7239 : 2839202 : tree newrhs;
7240 : 2839202 : tree rhseval = NULL_TREE;
7241 : 2839202 : tree lhstype = TREE_TYPE (lhs);
7242 : 2839202 : tree olhstype = lhstype;
7243 : 2839202 : bool npc;
7244 : 2839202 : bool is_atomic_op;
7245 : :
7246 : : /* Types that aren't fully specified cannot be used in assignments. */
7247 : 2839202 : lhs = require_complete_type (location, lhs);
7248 : 2839202 : rhs = require_complete_type (location, rhs);
7249 : :
7250 : : /* Avoid duplicate error messages from operands that had errors. */
7251 : 2839202 : if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK)
7252 : 472 : return error_mark_node;
7253 : :
7254 : : /* Ensure an error for assigning a non-lvalue array to an array in
7255 : : C90. */
7256 : 2838730 : if (TREE_CODE (lhstype) == ARRAY_TYPE)
7257 : : {
7258 : 1 : error_at (location, "assignment to expression with array type");
7259 : 1 : return error_mark_node;
7260 : : }
7261 : :
7262 : : /* For ObjC properties, defer this check. */
7263 : 2838729 : if (!objc_is_property_ref (lhs) && !lvalue_or_else (location, lhs, lv_assign))
7264 : 31 : return error_mark_node;
7265 : :
7266 : 2838698 : is_atomic_op = really_atomic_lvalue (lhs);
7267 : :
7268 : 2838698 : newrhs = rhs;
7269 : :
7270 : 2838698 : if (TREE_CODE (lhs) == C_MAYBE_CONST_EXPR)
7271 : : {
7272 : 2 : tree inner = build_modify_expr (location, C_MAYBE_CONST_EXPR_EXPR (lhs),
7273 : : lhs_origtype, modifycode, rhs_loc, rhs,
7274 : : rhs_origtype);
7275 : 2 : if (inner == error_mark_node)
7276 : : return error_mark_node;
7277 : 4 : result = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (inner),
7278 : 2 : C_MAYBE_CONST_EXPR_PRE (lhs), inner);
7279 : 2 : gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (lhs));
7280 : 2 : C_MAYBE_CONST_EXPR_NON_CONST (result) = 1;
7281 : 2 : protected_set_expr_location (result, location);
7282 : 2 : return result;
7283 : : }
7284 : :
7285 : : /* If a binary op has been requested, combine the old LHS value with the RHS
7286 : : producing the value we should actually store into the LHS. */
7287 : :
7288 : 2838696 : if (modifycode != NOP_EXPR)
7289 : : {
7290 : 209683 : lhs = c_fully_fold (lhs, false, NULL, true);
7291 : 209683 : lhs = stabilize_reference (lhs);
7292 : :
7293 : : /* Construct the RHS for any non-atomic compound assignemnt. */
7294 : 209683 : if (!is_atomic_op)
7295 : : {
7296 : : /* If in LHS op= RHS the RHS has side-effects, ensure they
7297 : : are preevaluated before the rest of the assignment expression's
7298 : : side-effects, because RHS could contain e.g. function calls
7299 : : that modify LHS. */
7300 : 194214 : if (TREE_SIDE_EFFECTS (rhs))
7301 : : {
7302 : 8603 : if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
7303 : 28 : newrhs = save_expr (TREE_OPERAND (rhs, 0));
7304 : : else
7305 : 8575 : newrhs = save_expr (rhs);
7306 : 8603 : rhseval = newrhs;
7307 : 8603 : if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
7308 : 28 : newrhs = build1 (EXCESS_PRECISION_EXPR, TREE_TYPE (rhs),
7309 : : newrhs);
7310 : : }
7311 : 194214 : newrhs = build_binary_op (location,
7312 : : modifycode, lhs, newrhs, true);
7313 : :
7314 : : /* The original type of the right hand side is no longer
7315 : : meaningful. */
7316 : 194214 : rhs_origtype = NULL_TREE;
7317 : : }
7318 : : }
7319 : :
7320 : 2838696 : if (c_dialect_objc ())
7321 : : {
7322 : : /* Check if we are modifying an Objective-C property reference;
7323 : : if so, we need to generate setter calls. */
7324 : 0 : if (TREE_CODE (newrhs) == EXCESS_PRECISION_EXPR)
7325 : 0 : result = objc_maybe_build_modify_expr (lhs, TREE_OPERAND (newrhs, 0));
7326 : : else
7327 : 0 : result = objc_maybe_build_modify_expr (lhs, newrhs);
7328 : 0 : if (result)
7329 : 0 : goto return_result;
7330 : :
7331 : : /* Else, do the check that we postponed for Objective-C. */
7332 : 0 : if (!lvalue_or_else (location, lhs, lv_assign))
7333 : 0 : return error_mark_node;
7334 : : }
7335 : :
7336 : : /* Give an error for storing in something that is 'const'. */
7337 : :
7338 : 2838696 : if (TYPE_READONLY (lhstype)
7339 : 2838696 : || (RECORD_OR_UNION_TYPE_P (lhstype)
7340 : 25476 : && C_TYPE_FIELDS_READONLY (lhstype)))
7341 : : {
7342 : 88 : readonly_error (location, lhs, lv_assign);
7343 : 88 : return error_mark_node;
7344 : : }
7345 : 2838608 : else if (TREE_READONLY (lhs))
7346 : 1 : readonly_warning (lhs, lv_assign);
7347 : :
7348 : : /* If storing into a structure or union member,
7349 : : it has probably been given type `int'.
7350 : : Compute the type that would go with
7351 : : the actual amount of storage the member occupies. */
7352 : :
7353 : 2838608 : if (TREE_CODE (lhs) == COMPONENT_REF
7354 : 243503 : && (TREE_CODE (lhstype) == INTEGER_TYPE
7355 : 243503 : || TREE_CODE (lhstype) == BOOLEAN_TYPE
7356 : 106602 : || SCALAR_FLOAT_TYPE_P (lhstype)
7357 : 84732 : || TREE_CODE (lhstype) == ENUMERAL_TYPE))
7358 : 165745 : lhstype = TREE_TYPE (get_unwidened (lhs, 0));
7359 : :
7360 : : /* If storing in a field that is in actuality a short or narrower than one,
7361 : : we must store in the field in its actual type. */
7362 : :
7363 : 2838608 : if (lhstype != TREE_TYPE (lhs))
7364 : : {
7365 : 0 : lhs = copy_node (lhs);
7366 : 0 : TREE_TYPE (lhs) = lhstype;
7367 : : }
7368 : :
7369 : : /* Issue -Wc++-compat warnings about an assignment to an enum type
7370 : : when LHS does not have its original type. This happens for,
7371 : : e.g., an enum bitfield in a struct. */
7372 : 2838608 : if (warn_cxx_compat
7373 : 3003 : && lhs_origtype != NULL_TREE
7374 : 3003 : && lhs_origtype != lhstype
7375 : 7 : && TREE_CODE (lhs_origtype) == ENUMERAL_TYPE)
7376 : : {
7377 : 4 : tree checktype = (rhs_origtype != NULL_TREE
7378 : 4 : ? rhs_origtype
7379 : 0 : : TREE_TYPE (rhs));
7380 : 4 : if (checktype != error_mark_node
7381 : 4 : && (TYPE_MAIN_VARIANT (checktype) != TYPE_MAIN_VARIANT (lhs_origtype)
7382 : 2 : || (is_atomic_op && modifycode != NOP_EXPR)))
7383 : 2 : warning_at (location, OPT_Wc___compat,
7384 : : "enum conversion in assignment is invalid in C++");
7385 : : }
7386 : :
7387 : : /* Remove qualifiers. */
7388 : 2838608 : lhstype = c_build_qualified_type (lhstype, TYPE_UNQUALIFIED);
7389 : 2838608 : olhstype = c_build_qualified_type (olhstype, TYPE_UNQUALIFIED);
7390 : :
7391 : : /* Convert new value to destination type. Fold it first, then
7392 : : restore any excess precision information, for the sake of
7393 : : conversion warnings. */
7394 : :
7395 : 2838608 : if (!(is_atomic_op && modifycode != NOP_EXPR))
7396 : : {
7397 : 2823139 : tree rhs_semantic_type = NULL_TREE;
7398 : 2823139 : if (!c_in_omp_for)
7399 : : {
7400 : 2806846 : if (TREE_CODE (newrhs) == EXCESS_PRECISION_EXPR)
7401 : : {
7402 : 5069 : rhs_semantic_type = TREE_TYPE (newrhs);
7403 : 5069 : newrhs = TREE_OPERAND (newrhs, 0);
7404 : : }
7405 : 2806846 : npc = null_pointer_constant_p (newrhs);
7406 : 2806846 : newrhs = c_fully_fold (newrhs, false, NULL);
7407 : 2806846 : if (rhs_semantic_type)
7408 : 5069 : newrhs = build1 (EXCESS_PRECISION_EXPR, rhs_semantic_type, newrhs);
7409 : : }
7410 : : else
7411 : 16293 : npc = null_pointer_constant_p (newrhs);
7412 : 2823139 : newrhs = convert_for_assignment (location, rhs_loc, lhstype, newrhs,
7413 : : rhs_origtype, ic_assign, npc,
7414 : : NULL_TREE, NULL_TREE, 0);
7415 : 2823139 : if (TREE_CODE (newrhs) == ERROR_MARK)
7416 : 116 : return error_mark_node;
7417 : : }
7418 : :
7419 : : /* Emit ObjC write barrier, if necessary. */
7420 : 2838492 : if (c_dialect_objc () && flag_objc_gc)
7421 : : {
7422 : 0 : result = objc_generate_write_barrier (lhs, modifycode, newrhs);
7423 : 0 : if (result)
7424 : : {
7425 : 0 : protected_set_expr_location (result, location);
7426 : 0 : goto return_result;
7427 : : }
7428 : : }
7429 : :
7430 : : /* Scan operands. */
7431 : :
7432 : 2838492 : if (is_atomic_op)
7433 : 25842 : result = build_atomic_assign (location, lhs, modifycode, newrhs, false);
7434 : : else
7435 : : {
7436 : 2812650 : result = build2 (MODIFY_EXPR, lhstype, lhs, newrhs);
7437 : 2812650 : TREE_SIDE_EFFECTS (result) = 1;
7438 : 2812650 : protected_set_expr_location (result, location);
7439 : : }
7440 : :
7441 : : /* If we got the LHS in a different type for storing in,
7442 : : convert the result back to the nominal type of LHS
7443 : : so that the value we return always has the same type
7444 : : as the LHS argument. */
7445 : :
7446 : 2838492 : if (olhstype == TREE_TYPE (result))
7447 : 2838492 : goto return_result;
7448 : :
7449 : 0 : result = convert_for_assignment (location, rhs_loc, olhstype, result,
7450 : : rhs_origtype, ic_assign, false, NULL_TREE,
7451 : : NULL_TREE, 0);
7452 : 0 : protected_set_expr_location (result, location);
7453 : :
7454 : 2838492 : return_result:
7455 : 2838492 : if (rhseval)
7456 : 8603 : result = build2 (COMPOUND_EXPR, TREE_TYPE (result), rhseval, result);
7457 : : return result;
7458 : : }
7459 : :
7460 : : /* Return whether STRUCT_TYPE has an anonymous field with type TYPE.
7461 : : This is used to implement -fplan9-extensions. */
7462 : :
7463 : : static bool
7464 : 10 : find_anonymous_field_with_type (tree struct_type, tree type)
7465 : : {
7466 : 10 : tree field;
7467 : 10 : bool found;
7468 : :
7469 : 10 : gcc_assert (RECORD_OR_UNION_TYPE_P (struct_type));
7470 : 10 : found = false;
7471 : 10 : for (field = TYPE_FIELDS (struct_type);
7472 : 20 : field != NULL_TREE;
7473 : 10 : field = TREE_CHAIN (field))
7474 : : {
7475 : 10 : tree fieldtype = remove_qualifiers (TREE_TYPE (field));
7476 : 10 : if (DECL_NAME (field) == NULL
7477 : 10 : && comptypes (type, fieldtype))
7478 : : {
7479 : 4 : if (found)
7480 : : return false;
7481 : : found = true;
7482 : : }
7483 : 6 : else if (DECL_NAME (field) == NULL
7484 : 2 : && RECORD_OR_UNION_TYPE_P (TREE_TYPE (field))
7485 : 8 : && find_anonymous_field_with_type (TREE_TYPE (field), type))
7486 : : {
7487 : 0 : if (found)
7488 : : return false;
7489 : : found = true;
7490 : : }
7491 : : }
7492 : : return found;
7493 : : }
7494 : :
7495 : : /* RHS is an expression whose type is pointer to struct. If there is
7496 : : an anonymous field in RHS with type TYPE, then return a pointer to
7497 : : that field in RHS. This is used with -fplan9-extensions. This
7498 : : returns NULL if no conversion could be found. */
7499 : :
7500 : : static tree
7501 : 12 : convert_to_anonymous_field (location_t location, tree type, tree rhs)
7502 : : {
7503 : 12 : tree rhs_struct_type, lhs_main_type;
7504 : 12 : tree field, found_field;
7505 : 12 : bool found_sub_field;
7506 : 12 : tree ret;
7507 : :
7508 : 12 : gcc_assert (POINTER_TYPE_P (TREE_TYPE (rhs)));
7509 : 12 : rhs_struct_type = TREE_TYPE (TREE_TYPE (rhs));
7510 : 12 : gcc_assert (RECORD_OR_UNION_TYPE_P (rhs_struct_type));
7511 : :
7512 : 12 : gcc_assert (POINTER_TYPE_P (type));
7513 : 12 : lhs_main_type = remove_qualifiers (TREE_TYPE (type));
7514 : :
7515 : 12 : found_field = NULL_TREE;
7516 : 12 : found_sub_field = false;
7517 : 12 : for (field = TYPE_FIELDS (rhs_struct_type);
7518 : 44 : field != NULL_TREE;
7519 : 32 : field = TREE_CHAIN (field))
7520 : : {
7521 : 36 : if (DECL_NAME (field) != NULL_TREE
7522 : 36 : || !RECORD_OR_UNION_TYPE_P (TREE_TYPE (field)))
7523 : 16 : continue;
7524 : 20 : tree fieldtype = remove_qualifiers (TREE_TYPE (field));
7525 : 20 : if (comptypes (lhs_main_type, fieldtype))
7526 : : {
7527 : 12 : if (found_field != NULL_TREE)
7528 : : return NULL_TREE;
7529 : : found_field = field;
7530 : : }
7531 : 8 : else if (find_anonymous_field_with_type (TREE_TYPE (field),
7532 : : lhs_main_type))
7533 : : {
7534 : 4 : if (found_field != NULL_TREE)
7535 : : return NULL_TREE;
7536 : : found_field = field;
7537 : : found_sub_field = true;
7538 : : }
7539 : : }
7540 : :
7541 : 8 : if (found_field == NULL_TREE)
7542 : : return NULL_TREE;
7543 : :
7544 : 8 : ret = fold_build3_loc (location, COMPONENT_REF, TREE_TYPE (found_field),
7545 : : build_fold_indirect_ref (rhs), found_field,
7546 : : NULL_TREE);
7547 : 8 : ret = build_fold_addr_expr_loc (location, ret);
7548 : :
7549 : 8 : if (found_sub_field)
7550 : : {
7551 : 2 : ret = convert_to_anonymous_field (location, type, ret);
7552 : 2 : gcc_assert (ret != NULL_TREE);
7553 : : }
7554 : :
7555 : : return ret;
7556 : : }
7557 : :
7558 : : /* Issue an error message for a bad initializer component.
7559 : : GMSGID identifies the message.
7560 : : The component name is taken from the spelling stack. */
7561 : :
7562 : : static void ATTRIBUTE_GCC_DIAG (2,0)
7563 : 906 : error_init (location_t loc, const char *gmsgid, ...)
7564 : : {
7565 : 906 : char *ofwhat;
7566 : :
7567 : 906 : auto_diagnostic_group d;
7568 : :
7569 : : /* The gmsgid may be a format string with %< and %>. */
7570 : 906 : va_list ap;
7571 : 906 : va_start (ap, gmsgid);
7572 : 906 : bool warned = emit_diagnostic_valist (DK_ERROR, loc, -1, gmsgid, &ap);
7573 : 906 : va_end (ap);
7574 : :
7575 : 906 : ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
7576 : 906 : if (*ofwhat && warned)
7577 : 220 : inform (loc, "(near initialization for %qs)", ofwhat);
7578 : 906 : }
7579 : :
7580 : : /* Used to implement pedwarn_init and permerror_init. */
7581 : :
7582 : : static bool ATTRIBUTE_GCC_DIAG (3,0)
7583 : 2513 : pedwarn_permerror_init (location_t loc, int opt, const char *gmsgid,
7584 : : va_list *ap, diagnostic_t kind)
7585 : : {
7586 : : /* Use the location where a macro was expanded rather than where
7587 : : it was defined to make sure macros defined in system headers
7588 : : but used incorrectly elsewhere are diagnosed. */
7589 : 2513 : location_t exploc = expansion_point_location_if_in_system_header (loc);
7590 : 2513 : auto_diagnostic_group d;
7591 : 2513 : bool warned = emit_diagnostic_valist (kind, exploc, opt, gmsgid, ap);
7592 : 2513 : if (warned)
7593 : : {
7594 : 1800 : char *ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
7595 : 1800 : if (*ofwhat)
7596 : 1479 : inform (exploc, "(near initialization for %qs)", ofwhat);
7597 : : }
7598 : 5026 : return warned;
7599 : 2513 : }
7600 : :
7601 : : /* Issue a pedantic warning for a bad initializer component. OPT is
7602 : : the option OPT_* (from options.h) controlling this warning or 0 if
7603 : : it is unconditionally given. GMSGID identifies the message. The
7604 : : component name is taken from the spelling stack. */
7605 : :
7606 : : static bool ATTRIBUTE_GCC_DIAG (3,0)
7607 : 2184 : pedwarn_init (location_t loc, int opt, const char *gmsgid, ...)
7608 : : {
7609 : 2184 : va_list ap;
7610 : 2184 : va_start (ap, gmsgid);
7611 : 2184 : bool warned = pedwarn_permerror_init (loc, opt, gmsgid, &ap, DK_PEDWARN);
7612 : 2184 : va_end (ap);
7613 : 2184 : return warned;
7614 : : }
7615 : :
7616 : : /* Like pedwarn_init, but issue a permerror. */
7617 : :
7618 : : static bool ATTRIBUTE_GCC_DIAG (3,0)
7619 : 329 : permerror_init (location_t loc, int opt, const char *gmsgid, ...)
7620 : : {
7621 : 329 : va_list ap;
7622 : 329 : va_start (ap, gmsgid);
7623 : 329 : bool warned = pedwarn_permerror_init (loc, opt, gmsgid, &ap, DK_PERMERROR);
7624 : 329 : va_end (ap);
7625 : 329 : return warned;
7626 : : }
7627 : :
7628 : : /* Issue a warning for a bad initializer component.
7629 : :
7630 : : OPT is the OPT_W* value corresponding to the warning option that
7631 : : controls this warning. GMSGID identifies the message. The
7632 : : component name is taken from the spelling stack. */
7633 : :
7634 : : static void
7635 : 146 : warning_init (location_t loc, int opt, const char *gmsgid)
7636 : : {
7637 : 146 : char *ofwhat;
7638 : 146 : bool warned;
7639 : :
7640 : 146 : auto_diagnostic_group d;
7641 : :
7642 : : /* Use the location where a macro was expanded rather than where
7643 : : it was defined to make sure macros defined in system headers
7644 : : but used incorrectly elsewhere are diagnosed. */
7645 : 146 : location_t exploc = expansion_point_location_if_in_system_header (loc);
7646 : :
7647 : : /* The gmsgid may be a format string with %< and %>. */
7648 : 146 : warned = warning_at (exploc, opt, gmsgid);
7649 : 146 : if (warned)
7650 : : {
7651 : 124 : ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
7652 : 124 : if (*ofwhat)
7653 : 124 : inform (exploc, "(near initialization for %qs)", ofwhat);
7654 : : }
7655 : 146 : }
7656 : :
7657 : : /* If TYPE is an array type and EXPR is a parenthesized string
7658 : : constant, warn if pedantic that EXPR is being used to initialize an
7659 : : object of type TYPE. */
7660 : :
7661 : : void
7662 : 7103680 : maybe_warn_string_init (location_t loc, tree type, struct c_expr expr)
7663 : : {
7664 : 7103680 : if (pedantic
7665 : 80203 : && TREE_CODE (type) == ARRAY_TYPE
7666 : 1008 : && TREE_CODE (expr.value) == STRING_CST
7667 : 353 : && expr.original_code != STRING_CST)
7668 : 13 : pedwarn_init (loc, OPT_Wpedantic,
7669 : : "array initialized from parenthesized string constant");
7670 : 7103680 : }
7671 : :
7672 : : /* Attempt to locate the parameter with the given index within FNDECL,
7673 : : returning DECL_SOURCE_LOCATION (FNDECL) if it can't be found. */
7674 : :
7675 : : static location_t
7676 : 936 : get_fndecl_argument_location (tree fndecl, int argnum)
7677 : : {
7678 : 936 : int i;
7679 : 936 : tree param;
7680 : :
7681 : : /* Locate param by index within DECL_ARGUMENTS (fndecl). */
7682 : 936 : for (i = 0, param = DECL_ARGUMENTS (fndecl);
7683 : 1015 : i < argnum && param;
7684 : 79 : i++, param = TREE_CHAIN (param))
7685 : : ;
7686 : :
7687 : : /* If something went wrong (e.g. if we have a builtin and thus no arguments),
7688 : : return DECL_SOURCE_LOCATION (FNDECL). */
7689 : 936 : if (param == NULL)
7690 : 653 : return DECL_SOURCE_LOCATION (fndecl);
7691 : :
7692 : 283 : return DECL_SOURCE_LOCATION (param);
7693 : : }
7694 : :
7695 : : /* Issue a note about a mismatching argument for parameter PARMNUM
7696 : : to FUNDECL, for types EXPECTED_TYPE and ACTUAL_TYPE.
7697 : : Attempt to issue the note at the pertinent parameter of the decl;
7698 : : failing that issue it at the location of FUNDECL; failing that
7699 : : issue it at PLOC.
7700 : : Use highlight_colors::actual for the ACTUAL_TYPE
7701 : : and highlight_colors::expected for EXPECTED_TYPE and the
7702 : : parameter of FUNDECL*/
7703 : :
7704 : : static void
7705 : 1060 : inform_for_arg (tree fundecl, location_t ploc, int parmnum,
7706 : : tree expected_type, tree actual_type)
7707 : : {
7708 : 1060 : location_t loc;
7709 : 1060 : if (fundecl && !DECL_IS_UNDECLARED_BUILTIN (fundecl))
7710 : 936 : loc = get_fndecl_argument_location (fundecl, parmnum - 1);
7711 : : else
7712 : : loc = ploc;
7713 : :
7714 : 1060 : gcc_rich_location richloc (loc, nullptr, highlight_colors::expected);
7715 : :
7716 : 1060 : pp_markup::element_expected_type elem_expected_type (expected_type);
7717 : 1060 : pp_markup::element_actual_type elem_actual_type (actual_type);
7718 : 1060 : inform (&richloc,
7719 : : "expected %e but argument is of type %e",
7720 : : &elem_expected_type, &elem_actual_type);
7721 : 1060 : }
7722 : :
7723 : : /* Issue a warning when an argument of ARGTYPE is passed to a built-in
7724 : : function FUNDECL declared without prototype to parameter PARMNUM of
7725 : : PARMTYPE when ARGTYPE does not promote to PARMTYPE. */
7726 : :
7727 : : static void
7728 : 418 : maybe_warn_builtin_no_proto_arg (location_t loc, tree fundecl, int parmnum,
7729 : : tree parmtype, tree argtype)
7730 : : {
7731 : 418 : tree_code parmcode = TREE_CODE (parmtype);
7732 : 418 : tree_code argcode = TREE_CODE (argtype);
7733 : 418 : tree promoted = c_type_promotes_to (argtype);
7734 : :
7735 : : /* Avoid warning for enum arguments that promote to an integer type
7736 : : of the same size/mode. */
7737 : 418 : if (parmcode == INTEGER_TYPE
7738 : 418 : && argcode == ENUMERAL_TYPE
7739 : 418 : && TYPE_MODE (parmtype) == TYPE_MODE (argtype))
7740 : : return;
7741 : :
7742 : 417 : if ((parmcode == argcode
7743 : 222 : || (parmcode == INTEGER_TYPE
7744 : : && argcode == ENUMERAL_TYPE))
7745 : 418 : && TYPE_MAIN_VARIANT (parmtype) == TYPE_MAIN_VARIANT (promoted))
7746 : : return;
7747 : :
7748 : : /* This diagnoses even signed/unsigned mismatches. Those might be
7749 : : safe in many cases but GCC may emit suboptimal code for them so
7750 : : warning on those cases drives efficiency improvements. */
7751 : 398 : if (warning_at (loc, OPT_Wbuiltin_declaration_mismatch,
7752 : 398 : TYPE_MAIN_VARIANT (promoted) == argtype
7753 : : ? G_("%qD argument %d type is %qT where %qT is expected "
7754 : : "in a call to built-in function declared without "
7755 : : "prototype")
7756 : : : G_("%qD argument %d promotes to %qT where %qT is expected "
7757 : : "in a call to built-in function declared without "
7758 : : "prototype"),
7759 : : fundecl, parmnum, promoted, parmtype))
7760 : 150 : inform (DECL_SOURCE_LOCATION (fundecl),
7761 : : "built-in %qD declared here",
7762 : : fundecl);
7763 : : }
7764 : :
7765 : : /* Print a declaration in quotes, with the given highlight_color.
7766 : : Analogous to handler for %qD, but with a specific highlight color. */
7767 : :
7768 : 199 : class pp_element_quoted_decl : public pp_element
7769 : : {
7770 : : public:
7771 : 199 : pp_element_quoted_decl (tree decl, const char *highlight_color)
7772 : 199 : : m_decl (decl),
7773 : 199 : m_highlight_color (highlight_color)
7774 : : {
7775 : : }
7776 : :
7777 : 199 : void add_to_phase_2 (pp_markup::context &ctxt) override
7778 : : {
7779 : 199 : ctxt.begin_quote ();
7780 : 199 : ctxt.begin_highlight_color (m_highlight_color);
7781 : :
7782 : 199 : print_decl (ctxt);
7783 : :
7784 : 199 : ctxt.end_highlight_color ();
7785 : 199 : ctxt.end_quote ();
7786 : 199 : }
7787 : :
7788 : 199 : void print_decl (pp_markup::context &ctxt)
7789 : : {
7790 : 199 : pretty_printer *const pp = &ctxt.m_pp;
7791 : 199 : pp->set_padding (pp_none);
7792 : 199 : if (DECL_NAME (m_decl))
7793 : 199 : pp_identifier (pp, lang_hooks.decl_printable_name (m_decl, 2));
7794 : : else
7795 : 0 : pp_string (pp, _("({anonymous})"));
7796 : 199 : }
7797 : :
7798 : : private:
7799 : : tree m_decl;
7800 : : const char *m_highlight_color;
7801 : : };
7802 : :
7803 : : /* If TYPE is from a typedef, issue a note showing the location
7804 : : to the user.
7805 : : Use HIGHLIGHT_COLOR as the highlight color. */
7806 : :
7807 : : static void
7808 : 1178 : maybe_inform_typedef_location (tree type, const char *highlight_color)
7809 : : {
7810 : 1178 : if (!typedef_variant_p (type))
7811 : 1144 : return;
7812 : :
7813 : 34 : tree typedef_decl = TYPE_NAME (type);
7814 : 34 : gcc_assert (TREE_CODE (typedef_decl) == TYPE_DECL);
7815 : 34 : gcc_rich_location richloc (DECL_SOURCE_LOCATION (typedef_decl),
7816 : 34 : nullptr, highlight_color);
7817 : 34 : pp_element_quoted_decl e_typedef_decl (typedef_decl, highlight_color);
7818 : 34 : inform (&richloc, "%e declared here", &e_typedef_decl);
7819 : 34 : }
7820 : :
7821 : : /* Convert value RHS to type TYPE as preparation for an assignment to
7822 : : an lvalue of type TYPE. If ORIGTYPE is not NULL_TREE, it is the
7823 : : original type of RHS; this differs from TREE_TYPE (RHS) for enum
7824 : : types. NULL_POINTER_CONSTANT says whether RHS was a null pointer
7825 : : constant before any folding.
7826 : : The real work of conversion is done by `convert'.
7827 : : The purpose of this function is to generate error messages
7828 : : for assignments that are not allowed in C.
7829 : : ERRTYPE says whether it is argument passing, assignment,
7830 : : initialization or return.
7831 : :
7832 : : In the following example, '~' denotes where EXPR_LOC and '^' where
7833 : : LOCATION point to:
7834 : :
7835 : : f (var); [ic_argpass]
7836 : : ^ ~~~
7837 : : x = var; [ic_assign]
7838 : : ^ ~~~;
7839 : : int x = var; [ic_init]
7840 : : ^^^
7841 : : return x; [ic_return]
7842 : : ^
7843 : :
7844 : : FUNCTION is a tree for the function being called.
7845 : : PARMNUM is the number of the argument, for printing in error messages.
7846 : : WARNOPT may be set to a warning option to issue the corresponding warning
7847 : : rather than an error for invalid conversions. Used for calls to built-in
7848 : : functions declared without a prototype. */
7849 : :
7850 : : static tree
7851 : 162774310 : convert_for_assignment (location_t location, location_t expr_loc, tree type,
7852 : : tree rhs, tree origtype, enum impl_conv errtype,
7853 : : bool null_pointer_constant, tree fundecl,
7854 : : tree function, int parmnum, int warnopt /* = 0 */)
7855 : : {
7856 : 162774310 : enum tree_code codel = TREE_CODE (type);
7857 : 162774310 : tree orig_rhs = rhs;
7858 : 162774310 : tree rhstype;
7859 : 162774310 : enum tree_code coder;
7860 : 162774310 : tree rname = NULL_TREE;
7861 : 162774310 : bool objc_ok = false;
7862 : :
7863 : : /* Use the expansion point location to handle cases such as user's
7864 : : function returning a wrong-type macro defined in a system header. */
7865 : 162774310 : location = expansion_point_location_if_in_system_header (location);
7866 : :
7867 : 162774310 : if (errtype == ic_argpass)
7868 : : {
7869 : 122363683 : tree selector;
7870 : : /* Change pointer to function to the function itself for
7871 : : diagnostics. */
7872 : 122363683 : if (TREE_CODE (function) == ADDR_EXPR
7873 : 122363683 : && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL)
7874 : 0 : function = TREE_OPERAND (function, 0);
7875 : :
7876 : : /* Handle an ObjC selector specially for diagnostics. */
7877 : 122363683 : selector = objc_message_selector ();
7878 : 122363683 : rname = function;
7879 : 122363683 : if (selector && parmnum > 2)
7880 : : {
7881 : 0 : rname = selector;
7882 : 0 : parmnum -= 2;
7883 : : }
7884 : : }
7885 : :
7886 : : /* This macro is used to emit diagnostics to ensure that all format
7887 : : strings are complete sentences, visible to gettext and checked at
7888 : : compile time. */
7889 : : #define PEDWARN_FOR_ASSIGNMENT(LOCATION, PLOC, OPT, AR, AS, IN, RE) \
7890 : : do { \
7891 : : switch (errtype) \
7892 : : { \
7893 : : case ic_argpass: \
7894 : : { \
7895 : : auto_diagnostic_group d; \
7896 : : if (pedwarn (PLOC, OPT, AR, parmnum, rname)) \
7897 : : inform_for_arg (fundecl, (PLOC), parmnum, type, rhstype); \
7898 : : } \
7899 : : break; \
7900 : : case ic_assign: \
7901 : : pedwarn (LOCATION, OPT, AS); \
7902 : : break; \
7903 : : case ic_init: \
7904 : : case ic_init_const: \
7905 : : pedwarn_init (LOCATION, OPT, IN); \
7906 : : break; \
7907 : : case ic_return: \
7908 : : pedwarn (LOCATION, OPT, RE); \
7909 : : break; \
7910 : : default: \
7911 : : gcc_unreachable (); \
7912 : : } \
7913 : : } while (0)
7914 : :
7915 : : /* This macro is used to emit diagnostics to ensure that all format
7916 : : strings are complete sentences, visible to gettext and checked at
7917 : : compile time. It can be called with 'pedwarn' or 'warning_at'. */
7918 : : #define WARNING_FOR_QUALIFIERS(PEDWARN, LOCATION, PLOC, OPT, AR, AS, IN, RE, QUALS) \
7919 : : do { \
7920 : : switch (errtype) \
7921 : : { \
7922 : : case ic_argpass: \
7923 : : { \
7924 : : auto_diagnostic_group d; \
7925 : : if (PEDWARN) { \
7926 : : if (pedwarn (PLOC, OPT, AR, parmnum, rname, QUALS)) \
7927 : : inform_for_arg (fundecl, (PLOC), parmnum, type, rhstype); \
7928 : : } else { \
7929 : : if (warning_at (PLOC, OPT, AR, parmnum, rname, QUALS)) \
7930 : : inform_for_arg (fundecl, (PLOC), parmnum, type, rhstype); \
7931 : : } \
7932 : : } \
7933 : : break; \
7934 : : case ic_assign: \
7935 : : if (PEDWARN) \
7936 : : pedwarn (LOCATION, OPT, AS, QUALS); \
7937 : : else \
7938 : : warning_at (LOCATION, OPT, AS, QUALS); \
7939 : : break; \
7940 : : case ic_init: \
7941 : : case ic_init_const: \
7942 : : if (PEDWARN) \
7943 : : pedwarn (LOCATION, OPT, IN, QUALS); \
7944 : : else \
7945 : : warning_at (LOCATION, OPT, IN, QUALS); \
7946 : : break; \
7947 : : case ic_return: \
7948 : : if (PEDWARN) \
7949 : : pedwarn (LOCATION, OPT, RE, QUALS); \
7950 : : else \
7951 : : warning_at (LOCATION, OPT, RE, QUALS); \
7952 : : break; \
7953 : : default: \
7954 : : gcc_unreachable (); \
7955 : : } \
7956 : : } while (0)
7957 : :
7958 : : /* This macro is used to emit diagnostics to ensure that all format
7959 : : strings are complete sentences, visible to gettext and checked at
7960 : : compile time. It is the same as PEDWARN_FOR_ASSIGNMENT but with an
7961 : : extra parameter to enumerate qualifiers. */
7962 : : #define PEDWARN_FOR_QUALIFIERS(LOCATION, PLOC, OPT, AR, AS, IN, RE, QUALS) \
7963 : : WARNING_FOR_QUALIFIERS (true, LOCATION, PLOC, OPT, AR, AS, IN, RE, QUALS)
7964 : :
7965 : :
7966 : 162774310 : if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
7967 : 5963 : rhs = TREE_OPERAND (rhs, 0);
7968 : :
7969 : 162774310 : rhstype = TREE_TYPE (rhs);
7970 : 162774310 : coder = TREE_CODE (rhstype);
7971 : :
7972 : 162774310 : if (coder == ERROR_MARK)
7973 : 346 : return error_mark_node;
7974 : :
7975 : 162773964 : if (c_dialect_objc ())
7976 : : {
7977 : 0 : int parmno;
7978 : :
7979 : 0 : switch (errtype)
7980 : : {
7981 : : case ic_return:
7982 : : parmno = 0;
7983 : : break;
7984 : :
7985 : : case ic_assign:
7986 : : parmno = -1;
7987 : : break;
7988 : :
7989 : : case ic_init:
7990 : : case ic_init_const:
7991 : : parmno = -2;
7992 : : break;
7993 : :
7994 : : default:
7995 : 0 : parmno = parmnum;
7996 : : break;
7997 : : }
7998 : :
7999 : 0 : objc_ok = objc_compare_types (type, rhstype, parmno, rname);
8000 : : }
8001 : :
8002 : 162773964 : if (warn_cxx_compat)
8003 : : {
8004 : 28634 : tree checktype = origtype != NULL_TREE ? origtype : rhstype;
8005 : 28634 : if (checktype != error_mark_node
8006 : 28634 : && TREE_CODE (type) == ENUMERAL_TYPE
8007 : 28740 : && TYPE_MAIN_VARIANT (checktype) != TYPE_MAIN_VARIANT (type))
8008 : 45 : switch (errtype)
8009 : : {
8010 : 8 : case ic_argpass:
8011 : 8 : if (pedwarn (expr_loc, OPT_Wc___compat, "enum conversion when "
8012 : : "passing argument %d of %qE is invalid in C++",
8013 : : parmnum, rname))
8014 : 16 : inform ((fundecl && !DECL_IS_UNDECLARED_BUILTIN (fundecl))
8015 : 8 : ? DECL_SOURCE_LOCATION (fundecl) : expr_loc,
8016 : : "expected %qT but argument is of type %qT",
8017 : : type, rhstype);
8018 : : break;
8019 : 10 : case ic_assign:
8020 : 10 : pedwarn (location, OPT_Wc___compat, "enum conversion from %qT to "
8021 : : "%qT in assignment is invalid in C++", rhstype, type);
8022 : 10 : break;
8023 : 18 : case ic_init:
8024 : 18 : case ic_init_const:
8025 : 18 : pedwarn_init (location, OPT_Wc___compat, "enum conversion from "
8026 : : "%qT to %qT in initialization is invalid in C++",
8027 : : rhstype, type);
8028 : 18 : break;
8029 : 9 : case ic_return:
8030 : 9 : pedwarn (location, OPT_Wc___compat, "enum conversion from %qT to "
8031 : : "%qT in return is invalid in C++", rhstype, type);
8032 : 9 : break;
8033 : 0 : default:
8034 : 0 : gcc_unreachable ();
8035 : : }
8036 : : }
8037 : :
8038 : 162773964 : if (warn_enum_conversion)
8039 : : {
8040 : 14563857 : tree checktype = origtype != NULL_TREE ? origtype : rhstype;
8041 : 14563857 : if (checktype != error_mark_node
8042 : 14563857 : && TREE_CODE (checktype) == ENUMERAL_TYPE
8043 : 12661 : && TREE_CODE (type) == ENUMERAL_TYPE
8044 : 14572033 : && !comptypes (TYPE_MAIN_VARIANT (checktype), TYPE_MAIN_VARIANT (type)))
8045 : : {
8046 : 3 : gcc_rich_location loc (location);
8047 : 3 : warning_at (&loc, OPT_Wenum_conversion,
8048 : : "implicit conversion from %qT to %qT",
8049 : : checktype, type);
8050 : 3 : }
8051 : : }
8052 : :
8053 : 162773964 : if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype))
8054 : : {
8055 : 144117766 : warn_for_address_of_packed_member (type, orig_rhs);
8056 : 144117766 : if (type != rhstype)
8057 : : /* Convert RHS to TYPE in order to not lose TYPE in diagnostics. */
8058 : 35912723 : rhs = convert (type, rhs);
8059 : 144117766 : return rhs;
8060 : : }
8061 : :
8062 : 18656198 : if (coder == VOID_TYPE)
8063 : : {
8064 : : /* Except for passing an argument to an unprototyped function,
8065 : : this is a constraint violation. When passing an argument to
8066 : : an unprototyped function, it is compile-time undefined;
8067 : : making it a constraint in that case was rejected in
8068 : : DR#252. */
8069 : 8 : const char msg[] = "void value not ignored as it ought to be";
8070 : 8 : if (warnopt)
8071 : 0 : warning_at (location, warnopt, msg);
8072 : : else
8073 : 8 : error_at (location, msg);
8074 : 8 : return error_mark_node;
8075 : : }
8076 : 18656190 : rhs = require_complete_type (location, rhs);
8077 : 18656190 : if (rhs == error_mark_node)
8078 : : return error_mark_node;
8079 : :
8080 : 18656190 : if (coder == POINTER_TYPE && reject_gcc_builtin (rhs))
8081 : 6 : return error_mark_node;
8082 : :
8083 : : /* A non-reference type can convert to a reference. This handles
8084 : : va_start, va_copy and possibly port built-ins. */
8085 : 18656184 : if (codel == REFERENCE_TYPE && coder != REFERENCE_TYPE)
8086 : : {
8087 : 270 : if (!lvalue_p (rhs))
8088 : : {
8089 : 0 : const char msg[] = "cannot pass rvalue to reference parameter";
8090 : 0 : if (warnopt)
8091 : 0 : warning_at (location, warnopt, msg);
8092 : : else
8093 : 0 : error_at (location, msg);
8094 : 0 : return error_mark_node;
8095 : : }
8096 : 270 : if (!c_mark_addressable (rhs))
8097 : 0 : return error_mark_node;
8098 : 270 : rhs = build1 (ADDR_EXPR, c_build_pointer_type (TREE_TYPE (rhs)), rhs);
8099 : 270 : SET_EXPR_LOCATION (rhs, location);
8100 : :
8101 : 270 : rhs = convert_for_assignment (location, expr_loc,
8102 : 270 : c_build_pointer_type (TREE_TYPE (type)),
8103 : : rhs, origtype, errtype,
8104 : : null_pointer_constant, fundecl, function,
8105 : : parmnum, warnopt);
8106 : 270 : if (rhs == error_mark_node)
8107 : : return error_mark_node;
8108 : :
8109 : 270 : rhs = build1 (NOP_EXPR, type, rhs);
8110 : 270 : SET_EXPR_LOCATION (rhs, location);
8111 : 270 : return rhs;
8112 : : }
8113 : : /* Some types can interconvert without explicit casts. */
8114 : 18655914 : else if (codel == VECTOR_TYPE && coder == VECTOR_TYPE
8115 : 18655914 : && vector_types_convertible_p (type, TREE_TYPE (rhs), true))
8116 : 9054594 : return convert (type, rhs);
8117 : : /* Arithmetic types all interconvert, and enum is treated like int. */
8118 : 9601320 : else if ((codel == INTEGER_TYPE || codel == REAL_TYPE
8119 : 2231521 : || codel == FIXED_POINT_TYPE
8120 : 2231521 : || codel == ENUMERAL_TYPE || codel == COMPLEX_TYPE
8121 : 2149524 : || codel == BOOLEAN_TYPE || codel == BITINT_TYPE)
8122 : 7542837 : && (coder == INTEGER_TYPE || coder == REAL_TYPE
8123 : 79504 : || coder == FIXED_POINT_TYPE
8124 : 79504 : || coder == ENUMERAL_TYPE || coder == COMPLEX_TYPE
8125 : 37508 : || coder == BOOLEAN_TYPE || coder == BITINT_TYPE))
8126 : : {
8127 : 7541720 : if (warnopt && errtype == ic_argpass)
8128 : 418 : maybe_warn_builtin_no_proto_arg (expr_loc, fundecl, parmnum, type,
8129 : : rhstype);
8130 : :
8131 : 7541720 : bool save = in_late_binary_op;
8132 : 7511162 : if (C_BOOLEAN_TYPE_P (type) || codel == COMPLEX_TYPE
8133 : 15004059 : || (coder == REAL_TYPE
8134 : 271482 : && (codel == INTEGER_TYPE || codel == ENUMERAL_TYPE)
8135 : 24096 : && sanitize_flags_p (SANITIZE_FLOAT_CAST)))
8136 : 86125 : in_late_binary_op = true;
8137 : 10850940 : tree ret = convert_and_check (expr_loc != UNKNOWN_LOCATION
8138 : : ? expr_loc : location, type, orig_rhs,
8139 : : errtype == ic_init_const);
8140 : 7541720 : in_late_binary_op = save;
8141 : 7541720 : return ret;
8142 : : }
8143 : :
8144 : : /* Aggregates in different TUs might need conversion. */
8145 : 2059600 : if ((codel == RECORD_TYPE || codel == UNION_TYPE)
8146 : 95 : && codel == coder
8147 : 2059617 : && comptypes (TYPE_MAIN_VARIANT (type), TYPE_MAIN_VARIANT (rhstype)))
8148 : 6 : return convert_and_check (expr_loc != UNKNOWN_LOCATION
8149 : 6 : ? expr_loc : location, type, rhs);
8150 : :
8151 : : /* Conversion to a transparent union or record from its member types.
8152 : : This applies only to function arguments. */
8153 : 2059594 : if (((codel == UNION_TYPE || codel == RECORD_TYPE)
8154 : 89 : && TYPE_TRANSPARENT_AGGR (type))
8155 : 2059632 : && errtype == ic_argpass)
8156 : : {
8157 : 38 : tree memb, marginal_memb = NULL_TREE;
8158 : :
8159 : 48 : for (memb = TYPE_FIELDS (type); memb ; memb = DECL_CHAIN (memb))
8160 : : {
8161 : 48 : tree memb_type = TREE_TYPE (memb);
8162 : :
8163 : 48 : if (comptypes (TYPE_MAIN_VARIANT (memb_type),
8164 : 48 : TYPE_MAIN_VARIANT (rhstype)))
8165 : : break;
8166 : :
8167 : 26 : if (TREE_CODE (memb_type) != POINTER_TYPE)
8168 : 0 : continue;
8169 : :
8170 : 26 : if (coder == POINTER_TYPE)
8171 : : {
8172 : 26 : tree ttl = TREE_TYPE (memb_type);
8173 : 26 : tree ttr = TREE_TYPE (rhstype);
8174 : :
8175 : : /* Any non-function converts to a [const][volatile] void *
8176 : : and vice versa; otherwise, targets must be the same.
8177 : : Meanwhile, the lhs target must have all the qualifiers of
8178 : : the rhs. */
8179 : 0 : if ((VOID_TYPE_P (ttl) && !TYPE_ATOMIC (ttl))
8180 : 26 : || (VOID_TYPE_P (ttr) && !TYPE_ATOMIC (ttr))
8181 : 45 : || comp_target_types (location, memb_type, rhstype))
8182 : : {
8183 : 16 : int lquals = TYPE_QUALS (ttl) & ~TYPE_QUAL_ATOMIC;
8184 : 16 : int rquals = TYPE_QUALS (ttr) & ~TYPE_QUAL_ATOMIC;
8185 : : /* If this type won't generate any warnings, use it. */
8186 : 16 : if (lquals == rquals
8187 : 16 : || ((TREE_CODE (ttr) == FUNCTION_TYPE
8188 : 0 : && TREE_CODE (ttl) == FUNCTION_TYPE)
8189 : 0 : ? ((lquals | rquals) == rquals)
8190 : 16 : : ((lquals | rquals) == lquals)))
8191 : : break;
8192 : :
8193 : : /* Keep looking for a better type, but remember this one. */
8194 : 0 : if (!marginal_memb)
8195 : 10 : marginal_memb = memb;
8196 : : }
8197 : : }
8198 : :
8199 : : /* Can convert integer zero to any pointer type. */
8200 : 10 : if (null_pointer_constant)
8201 : : {
8202 : 0 : rhs = null_pointer_node;
8203 : 0 : break;
8204 : : }
8205 : : }
8206 : :
8207 : 38 : if (memb || marginal_memb)
8208 : : {
8209 : 38 : if (!memb)
8210 : : {
8211 : : /* We have only a marginally acceptable member type;
8212 : : it needs a warning. */
8213 : 0 : tree ttl = TREE_TYPE (TREE_TYPE (marginal_memb));
8214 : 0 : tree ttr = TREE_TYPE (rhstype);
8215 : :
8216 : : /* Const and volatile mean something different for function
8217 : : types, so the usual warnings are not appropriate. */
8218 : 0 : if (TREE_CODE (ttr) == FUNCTION_TYPE
8219 : 0 : && TREE_CODE (ttl) == FUNCTION_TYPE)
8220 : : {
8221 : : /* Because const and volatile on functions are
8222 : : restrictions that say the function will not do
8223 : : certain things, it is okay to use a const or volatile
8224 : : function where an ordinary one is wanted, but not
8225 : : vice-versa. */
8226 : 0 : if (TYPE_QUALS_NO_ADDR_SPACE (ttl)
8227 : 0 : & ~TYPE_QUALS_NO_ADDR_SPACE (ttr))
8228 : 0 : PEDWARN_FOR_QUALIFIERS (location, expr_loc,
8229 : : OPT_Wdiscarded_qualifiers,
8230 : : G_("passing argument %d of %qE "
8231 : : "makes %q#v qualified function "
8232 : : "pointer from unqualified"),
8233 : : G_("assignment makes %q#v qualified "
8234 : : "function pointer from "
8235 : : "unqualified"),
8236 : : G_("initialization makes %q#v qualified "
8237 : : "function pointer from "
8238 : : "unqualified"),
8239 : : G_("return makes %q#v qualified function "
8240 : : "pointer from unqualified"),
8241 : : TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr));
8242 : : }
8243 : 0 : else if (TYPE_QUALS_NO_ADDR_SPACE (ttr)
8244 : 0 : & ~TYPE_QUALS_NO_ADDR_SPACE (ttl))
8245 : 0 : PEDWARN_FOR_QUALIFIERS (location, expr_loc,
8246 : : OPT_Wdiscarded_qualifiers,
8247 : : G_("passing argument %d of %qE discards "
8248 : : "%qv qualifier from pointer target type"),
8249 : : G_("assignment discards %qv qualifier "
8250 : : "from pointer target type"),
8251 : : G_("initialization discards %qv qualifier "
8252 : : "from pointer target type"),
8253 : : G_("return discards %qv qualifier from "
8254 : : "pointer target type"),
8255 : : TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl));
8256 : :
8257 : : memb = marginal_memb;
8258 : : }
8259 : :
8260 : 38 : if (!fundecl || !DECL_IN_SYSTEM_HEADER (fundecl))
8261 : 30 : pedwarn (location, OPT_Wpedantic,
8262 : : "ISO C prohibits argument conversion to union type");
8263 : :
8264 : 38 : rhs = fold_convert_loc (location, TREE_TYPE (memb), rhs);
8265 : 38 : return build_constructor_single (type, memb, rhs);
8266 : : }
8267 : : }
8268 : :
8269 : : /* Conversions among pointers */
8270 : 2059556 : else if ((codel == POINTER_TYPE || codel == REFERENCE_TYPE)
8271 : 2058290 : && (coder == codel))
8272 : : {
8273 : : /* If RHS refers to a built-in declared without a prototype
8274 : : BLTIN is the declaration of the built-in with a prototype
8275 : : and RHSTYPE is set to the actual type of the built-in. */
8276 : 1980544 : tree bltin;
8277 : 1980544 : rhstype = type_or_builtin_type (rhs, &bltin);
8278 : :
8279 : 1980544 : tree ttl = TREE_TYPE (type);
8280 : 1980544 : tree ttr = TREE_TYPE (rhstype);
8281 : 1980544 : bool is_opaque_pointer;
8282 : 1980544 : bool target_cmp = false; /* Cache comp_target_types () result. */
8283 : 1980544 : addr_space_t asl;
8284 : 1980544 : addr_space_t asr;
8285 : :
8286 : 1980544 : tree mvl = remove_qualifiers (ttl);
8287 : 1980544 : tree mvr = remove_qualifiers (ttr);
8288 : :
8289 : : /* Opaque pointers are treated like void pointers. */
8290 : 1980544 : is_opaque_pointer = vector_targets_convertible_p (ttl, ttr);
8291 : :
8292 : : /* The Plan 9 compiler permits a pointer to a struct to be
8293 : : automatically converted into a pointer to an anonymous field
8294 : : within the struct. */
8295 : 1980544 : if (flag_plan9_extensions
8296 : 10 : && RECORD_OR_UNION_TYPE_P (mvl)
8297 : 10 : && RECORD_OR_UNION_TYPE_P (mvr)
8298 : 10 : && mvl != mvr)
8299 : : {
8300 : 10 : tree new_rhs = convert_to_anonymous_field (location, type, rhs);
8301 : 10 : if (new_rhs != NULL_TREE)
8302 : : {
8303 : 6 : rhs = new_rhs;
8304 : 6 : rhstype = TREE_TYPE (rhs);
8305 : 6 : coder = TREE_CODE (rhstype);
8306 : 6 : ttr = TREE_TYPE (rhstype);
8307 : 6 : mvr = TYPE_MAIN_VARIANT (ttr);
8308 : : }
8309 : : }
8310 : :
8311 : : /* C++ does not allow the implicit conversion void* -> T*. However,
8312 : : for the purpose of reducing the number of false positives, we
8313 : : tolerate the special case of
8314 : :
8315 : : int *p = NULL;
8316 : :
8317 : : where NULL is typically defined in C to be '(void *) 0'. */
8318 : 1980544 : if (VOID_TYPE_P (ttr) && rhs != null_pointer_node && !VOID_TYPE_P (ttl))
8319 : 26409 : warning_at (errtype == ic_argpass ? expr_loc : location,
8320 : 13988 : OPT_Wc___compat,
8321 : : "request for implicit conversion "
8322 : : "from %qT to %qT not permitted in C++", rhstype, type);
8323 : :
8324 : : /* Warn of new allocations that are not big enough for the target
8325 : : type. */
8326 : 1980544 : if (warn_alloc_size && TREE_CODE (rhs) == CALL_EXPR)
8327 : 5455 : if (tree fndecl = get_callee_fndecl (rhs))
8328 : 5455 : if (DECL_IS_MALLOC (fndecl))
8329 : : {
8330 : 4601 : tree attrs = TYPE_ATTRIBUTES (TREE_TYPE (fndecl));
8331 : 4601 : tree alloc_size = lookup_attribute ("alloc_size", attrs);
8332 : 4601 : if (alloc_size)
8333 : 447 : warn_for_alloc_size (location, ttl, rhs, alloc_size);
8334 : : }
8335 : :
8336 : : /* See if the pointers point to incompatible address spaces. */
8337 : 1980544 : asl = TYPE_ADDR_SPACE (ttl);
8338 : 1980544 : asr = TYPE_ADDR_SPACE (ttr);
8339 : 1980544 : if (!null_pointer_constant_p (rhs)
8340 : 1980544 : && asr != asl && !targetm.addr_space.subset_p (asr, asl))
8341 : : {
8342 : 3 : auto_diagnostic_group d;
8343 : 3 : bool diagnosed = true;
8344 : 3 : switch (errtype)
8345 : : {
8346 : 1 : case ic_argpass:
8347 : 1 : {
8348 : 1 : const char msg[] = G_("passing argument %d of %qE from "
8349 : : "pointer to non-enclosed address space");
8350 : 1 : if (warnopt)
8351 : 0 : diagnosed
8352 : 0 : = warning_at (expr_loc, warnopt, msg, parmnum, rname);
8353 : : else
8354 : 1 : error_at (expr_loc, msg, parmnum, rname);
8355 : 0 : break;
8356 : : }
8357 : 0 : case ic_assign:
8358 : 0 : {
8359 : 0 : const char msg[] = G_("assignment from pointer to "
8360 : : "non-enclosed address space");
8361 : 0 : if (warnopt)
8362 : 0 : diagnosed = warning_at (location, warnopt, msg);
8363 : : else
8364 : 0 : error_at (location, msg);
8365 : 0 : break;
8366 : : }
8367 : 0 : case ic_init:
8368 : 0 : case ic_init_const:
8369 : 0 : {
8370 : 0 : const char msg[] = G_("initialization from pointer to "
8371 : : "non-enclosed address space");
8372 : 0 : if (warnopt)
8373 : 0 : diagnosed = warning_at (location, warnopt, msg);
8374 : : else
8375 : 0 : error_at (location, msg);
8376 : 0 : break;
8377 : : }
8378 : 2 : case ic_return:
8379 : 2 : {
8380 : 2 : const char msg[] = G_("return from pointer to "
8381 : : "non-enclosed address space");
8382 : 2 : if (warnopt)
8383 : 0 : diagnosed = warning_at (location, warnopt, msg);
8384 : : else
8385 : 2 : error_at (location, msg);
8386 : 0 : break;
8387 : : }
8388 : 0 : default:
8389 : 0 : gcc_unreachable ();
8390 : : }
8391 : 3 : if (diagnosed)
8392 : : {
8393 : 3 : if (errtype == ic_argpass)
8394 : 1 : inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
8395 : : else
8396 : 2 : inform (location, "expected %qT but pointer is of type %qT",
8397 : : type, rhstype);
8398 : : }
8399 : 3 : return error_mark_node;
8400 : 3 : }
8401 : :
8402 : : /* Check if the right-hand side has a format attribute but the
8403 : : left-hand side doesn't. */
8404 : 1980541 : if (warn_suggest_attribute_format
8405 : 1980541 : && check_missing_format_attribute (type, rhstype))
8406 : : {
8407 : 16 : switch (errtype)
8408 : : {
8409 : 4 : case ic_argpass:
8410 : 4 : warning_at (expr_loc, OPT_Wsuggest_attribute_format,
8411 : : "argument %d of %qE might be "
8412 : : "a candidate for a format attribute",
8413 : : parmnum, rname);
8414 : 4 : break;
8415 : 4 : case ic_assign:
8416 : 4 : warning_at (location, OPT_Wsuggest_attribute_format,
8417 : : "assignment left-hand side might be "
8418 : : "a candidate for a format attribute");
8419 : 4 : break;
8420 : 4 : case ic_init:
8421 : 4 : case ic_init_const:
8422 : 4 : warning_at (location, OPT_Wsuggest_attribute_format,
8423 : : "initialization left-hand side might be "
8424 : : "a candidate for a format attribute");
8425 : 4 : break;
8426 : 4 : case ic_return:
8427 : 4 : warning_at (location, OPT_Wsuggest_attribute_format,
8428 : : "return type might be "
8429 : : "a candidate for a format attribute");
8430 : 4 : break;
8431 : 0 : default:
8432 : 0 : gcc_unreachable ();
8433 : : }
8434 : : }
8435 : :
8436 : : /* See if the pointers point to incompatible scalar storage orders. */
8437 : 1980541 : if (warn_scalar_storage_order
8438 : 1977625 : && !null_pointer_constant_p (rhs)
8439 : 5870885 : && (AGGREGATE_TYPE_P (ttl) && TYPE_REVERSE_STORAGE_ORDER (ttl))
8440 : 1945172 : != (AGGREGATE_TYPE_P (ttr) && TYPE_REVERSE_STORAGE_ORDER (ttr)))
8441 : : {
8442 : 18 : tree t;
8443 : :
8444 : 18 : switch (errtype)
8445 : : {
8446 : 11 : case ic_argpass:
8447 : : /* Do not warn for built-in functions, for example memcpy, since we
8448 : : control how they behave and they can be useful in this area. */
8449 : 11 : if (TREE_CODE (rname) != FUNCTION_DECL
8450 : 11 : || !fndecl_built_in_p (rname))
8451 : 1 : warning_at (location, OPT_Wscalar_storage_order,
8452 : : "passing argument %d of %qE from incompatible "
8453 : : "scalar storage order", parmnum, rname);
8454 : : break;
8455 : 3 : case ic_assign:
8456 : : /* Do not warn if the RHS is a call to a function that returns a
8457 : : pointer that is not an alias. */
8458 : 3 : if (TREE_CODE (rhs) != CALL_EXPR
8459 : 2 : || (t = get_callee_fndecl (rhs)) == NULL_TREE
8460 : 5 : || !DECL_IS_MALLOC (t))
8461 : 1 : warning_at (location, OPT_Wscalar_storage_order,
8462 : : "assignment to %qT from pointer type %qT with "
8463 : : "incompatible scalar storage order", type, rhstype);
8464 : : break;
8465 : 3 : case ic_init:
8466 : 3 : case ic_init_const:
8467 : : /* Likewise. */
8468 : 3 : if (TREE_CODE (rhs) != CALL_EXPR
8469 : 2 : || (t = get_callee_fndecl (rhs)) == NULL_TREE
8470 : 5 : || !DECL_IS_MALLOC (t))
8471 : 1 : warning_at (location, OPT_Wscalar_storage_order,
8472 : : "initialization of %qT from pointer type %qT with "
8473 : : "incompatible scalar storage order", type, rhstype);
8474 : : break;
8475 : 1 : case ic_return:
8476 : 1 : warning_at (location, OPT_Wscalar_storage_order,
8477 : : "returning %qT from pointer type with incompatible "
8478 : : "scalar storage order %qT", rhstype, type);
8479 : 1 : break;
8480 : 0 : default:
8481 : 0 : gcc_unreachable ();
8482 : : }
8483 : : }
8484 : :
8485 : : /* Any non-function converts to a [const][volatile] void *
8486 : : and vice versa; otherwise, targets must be the same.
8487 : : Meanwhile, the lhs target must have all the qualifiers of the rhs. */
8488 : 418727 : if ((VOID_TYPE_P (ttl) && !TYPE_ATOMIC (ttl))
8489 : 1561815 : || (VOID_TYPE_P (ttr) && !TYPE_ATOMIC (ttr))
8490 : 1515510 : || (target_cmp = comp_target_types (location, type, rhstype))
8491 : 2009 : || is_opaque_pointer
8492 : 1984559 : || ((c_common_unsigned_type (mvl)
8493 : 2009 : == c_common_unsigned_type (mvr))
8494 : 2466 : && (c_common_signed_type (mvl)
8495 : 1233 : == c_common_signed_type (mvr))
8496 : 1218 : && TYPE_ATOMIC (mvl) == TYPE_ATOMIC (mvr)))
8497 : : {
8498 : : /* Warn about loss of qualifers from pointers to arrays with
8499 : : qualifiers on the element type. */
8500 : 1979742 : if (TREE_CODE (ttr) == ARRAY_TYPE)
8501 : : {
8502 : 2095 : ttr = strip_array_types (ttr);
8503 : 2095 : ttl = strip_array_types (ttl);
8504 : :
8505 : 2095 : if (TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttr)
8506 : 2095 : & ~TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttl))
8507 : 115 : WARNING_FOR_QUALIFIERS (flag_isoc23,
8508 : : location, expr_loc,
8509 : : OPT_Wdiscarded_array_qualifiers,
8510 : : G_("passing argument %d of %qE discards "
8511 : : "%qv qualifier from pointer target type"),
8512 : : G_("assignment discards %qv qualifier "
8513 : : "from pointer target type"),
8514 : : G_("initialization discards %qv qualifier "
8515 : : "from pointer target type"),
8516 : : G_("return discards %qv qualifier from "
8517 : : "pointer target type"),
8518 : : TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl));
8519 : : }
8520 : 1977647 : else if (pedantic
8521 : 146033 : && ((VOID_TYPE_P (ttl) && TREE_CODE (ttr) == FUNCTION_TYPE)
8522 : 146013 : ||
8523 : : (VOID_TYPE_P (ttr)
8524 : 2952 : && !null_pointer_constant
8525 : 178 : && TREE_CODE (ttl) == FUNCTION_TYPE)))
8526 : 34 : PEDWARN_FOR_ASSIGNMENT (location, expr_loc, OPT_Wpedantic,
8527 : : G_("ISO C forbids passing argument %d of "
8528 : : "%qE between function pointer "
8529 : : "and %<void *%>"),
8530 : : G_("ISO C forbids assignment between "
8531 : : "function pointer and %<void *%>"),
8532 : : G_("ISO C forbids initialization between "
8533 : : "function pointer and %<void *%>"),
8534 : : G_("ISO C forbids return between function "
8535 : : "pointer and %<void *%>"));
8536 : : /* Const and volatile mean something different for function types,
8537 : : so the usual warnings are not appropriate. */
8538 : 1977613 : else if (TREE_CODE (ttr) != FUNCTION_TYPE
8539 : 1945199 : && TREE_CODE (ttl) != FUNCTION_TYPE)
8540 : : {
8541 : : /* Assignments between atomic and non-atomic objects are OK. */
8542 : 1944534 : bool warn_quals_ped = TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttr)
8543 : 1944534 : & ~TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttl);
8544 : 1944534 : bool warn_quals = TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttr)
8545 : 1944534 : & ~TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (strip_array_types (ttl));
8546 : :
8547 : : /* Don't warn about loss of qualifier for conversions from
8548 : : qualified void* to pointers to arrays with corresponding
8549 : : qualifier on the element type (except for pedantic before C23). */
8550 : 1944534 : if (warn_quals || (warn_quals_ped && pedantic && !flag_isoc23))
8551 : 697 : PEDWARN_FOR_QUALIFIERS (location, expr_loc,
8552 : : OPT_Wdiscarded_qualifiers,
8553 : : G_("passing argument %d of %qE discards "
8554 : : "%qv qualifier from pointer target type"),
8555 : : G_("assignment discards %qv qualifier "
8556 : : "from pointer target type"),
8557 : : G_("initialization discards %qv qualifier "
8558 : : "from pointer target type"),
8559 : : G_("return discards %qv qualifier from "
8560 : : "pointer target type"),
8561 : : TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl));
8562 : 11 : else if (warn_quals_ped)
8563 : 11 : pedwarn_c11 (location, OPT_Wc11_c23_compat,
8564 : : "array with qualifier on the element is not qualified before C23");
8565 : :
8566 : : /* If this is not a case of ignoring a mismatch in signedness,
8567 : : no warning. */
8568 : 1943826 : else if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr)
8569 : 1510604 : || target_cmp)
8570 : : ;
8571 : : /* If there is a mismatch, do warn. */
8572 : 1210 : else if (warn_pointer_sign)
8573 : 82 : switch (errtype)
8574 : : {
8575 : 33 : case ic_argpass:
8576 : 33 : {
8577 : 33 : auto_diagnostic_group d;
8578 : 33 : range_label_for_type_mismatch rhs_label (rhstype, type);
8579 : 33 : gcc_rich_location richloc (expr_loc, &rhs_label,
8580 : 33 : highlight_colors::actual);
8581 : 33 : if (pedwarn (&richloc, OPT_Wpointer_sign,
8582 : : "pointer targets in passing argument %d of "
8583 : : "%qE differ in signedness", parmnum, rname))
8584 : 33 : inform_for_arg (fundecl, expr_loc, parmnum, type,
8585 : : rhstype);
8586 : 33 : }
8587 : 33 : break;
8588 : 21 : case ic_assign:
8589 : 21 : pedwarn (location, OPT_Wpointer_sign,
8590 : : "pointer targets in assignment from %qT to %qT "
8591 : : "differ in signedness", rhstype, type);
8592 : 21 : break;
8593 : 14 : case ic_init:
8594 : 14 : case ic_init_const:
8595 : 14 : pedwarn_init (location, OPT_Wpointer_sign,
8596 : : "pointer targets in initialization of %qT "
8597 : : "from %qT differ in signedness", type,
8598 : : rhstype);
8599 : 14 : break;
8600 : 14 : case ic_return:
8601 : 14 : pedwarn (location, OPT_Wpointer_sign, "pointer targets in "
8602 : : "returning %qT from a function with return type "
8603 : : "%qT differ in signedness", rhstype, type);
8604 : 14 : break;
8605 : 0 : default:
8606 : 0 : gcc_unreachable ();
8607 : : }
8608 : : }
8609 : 33079 : else if (TREE_CODE (ttl) == FUNCTION_TYPE
8610 : 4118 : && TREE_CODE (ttr) == FUNCTION_TYPE)
8611 : : {
8612 : : /* Because const and volatile on functions are restrictions
8613 : : that say the function will not do certain things,
8614 : : it is okay to use a const or volatile function
8615 : : where an ordinary one is wanted, but not vice-versa. */
8616 : 3453 : if (TYPE_QUALS_NO_ADDR_SPACE (ttl)
8617 : 3453 : & ~TYPE_QUALS_NO_ADDR_SPACE (ttr))
8618 : 18 : PEDWARN_FOR_QUALIFIERS (location, expr_loc,
8619 : : OPT_Wdiscarded_qualifiers,
8620 : : G_("passing argument %d of %qE makes "
8621 : : "%q#v qualified function pointer "
8622 : : "from unqualified"),
8623 : : G_("assignment makes %q#v qualified function "
8624 : : "pointer from unqualified"),
8625 : : G_("initialization makes %q#v qualified "
8626 : : "function pointer from unqualified"),
8627 : : G_("return makes %q#v qualified function "
8628 : : "pointer from unqualified"),
8629 : : TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr));
8630 : : }
8631 : : }
8632 : : /* Avoid warning about the volatile ObjC EH puts on decls. */
8633 : 799 : else if (!objc_ok)
8634 : : {
8635 : 799 : auto_diagnostic_group d;
8636 : 799 : bool warned = false;
8637 : 799 : pp_markup::element_expected_type e_type (type);
8638 : 799 : pp_markup::element_actual_type e_rhstype (rhstype);
8639 : 799 : switch (errtype)
8640 : : {
8641 : 306 : case ic_argpass:
8642 : 306 : {
8643 : 306 : range_label_for_type_mismatch rhs_label (rhstype, type);
8644 : 306 : gcc_rich_location richloc (expr_loc, &rhs_label,
8645 : 306 : highlight_colors::actual);
8646 : 306 : warned
8647 : 306 : = permerror_opt (&richloc, OPT_Wincompatible_pointer_types,
8648 : : "passing argument %d of %qE from "
8649 : : "incompatible pointer type",
8650 : : parmnum, rname);
8651 : 306 : if (warned)
8652 : 174 : inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
8653 : 306 : }
8654 : 306 : break;
8655 : 267 : case ic_assign:
8656 : 267 : if (bltin)
8657 : 11 : warned
8658 : 11 : = permerror_opt (location, OPT_Wincompatible_pointer_types,
8659 : : "assignment to %e from pointer to "
8660 : : "%qD with incompatible type %e",
8661 : : &e_type, bltin, &e_rhstype);
8662 : : else
8663 : 256 : warned
8664 : 256 : = permerror_opt (location, OPT_Wincompatible_pointer_types,
8665 : : "assignment to %e from incompatible "
8666 : : "pointer type %e",
8667 : : &e_type, &e_rhstype);
8668 : : break;
8669 : 167 : case ic_init:
8670 : 167 : case ic_init_const:
8671 : 167 : if (bltin)
8672 : 13 : warned
8673 : 13 : = permerror_init (location, OPT_Wincompatible_pointer_types,
8674 : : "initialization of %e from pointer to "
8675 : : "%qD with incompatible type %e",
8676 : : &e_type, bltin, &e_rhstype);
8677 : : else
8678 : 154 : warned
8679 : 154 : = permerror_init (location, OPT_Wincompatible_pointer_types,
8680 : : "initialization of %e from incompatible "
8681 : : "pointer type %e",
8682 : : &e_type, &e_rhstype);
8683 : : break;
8684 : 59 : case ic_return:
8685 : 59 : if (bltin)
8686 : 11 : warned
8687 : 11 : = permerror_opt (location, OPT_Wincompatible_pointer_types,
8688 : : "returning pointer to %qD of type %e from "
8689 : : "a function with incompatible type %e",
8690 : : bltin, &e_rhstype, &e_type);
8691 : : else
8692 : 48 : warned
8693 : 48 : = permerror_opt (location, OPT_Wincompatible_pointer_types,
8694 : : "returning %e from a function with "
8695 : : "incompatible return type %e",
8696 : : &e_rhstype, &e_type);
8697 : : break;
8698 : 0 : default:
8699 : 0 : gcc_unreachable ();
8700 : : }
8701 : 799 : if (warned)
8702 : : {
8703 : : /* If the mismatching function type is a pointer to a function,
8704 : : try to show the decl of the function. */
8705 : 589 : if (TREE_CODE (rhs) == ADDR_EXPR
8706 : 589 : && TREE_CODE (TREE_OPERAND (rhs, 0)) == FUNCTION_DECL)
8707 : : {
8708 : 191 : tree rhs_fndecl = TREE_OPERAND (rhs, 0);
8709 : 191 : if (!DECL_IS_UNDECLARED_BUILTIN (rhs_fndecl))
8710 : : {
8711 : 165 : gcc_rich_location richloc
8712 : 165 : (DECL_SOURCE_LOCATION (rhs_fndecl), nullptr,
8713 : 165 : highlight_colors::actual);
8714 : 165 : pp_element_quoted_decl e_rhs_fndecl
8715 : 165 : (rhs_fndecl, highlight_colors::actual);
8716 : 165 : inform (&richloc,
8717 : : "%e declared here", &e_rhs_fndecl);
8718 : 165 : }
8719 : : }
8720 : : /* If either/both of the types are typedefs, show the decl. */
8721 : 589 : maybe_inform_typedef_location (type,
8722 : : highlight_colors::expected);
8723 : 589 : maybe_inform_typedef_location (rhstype,
8724 : : highlight_colors::actual);
8725 : : }
8726 : 799 : }
8727 : :
8728 : : /* If RHS isn't an address, check pointer or array of packed
8729 : : struct or union. */
8730 : 1980541 : warn_for_address_of_packed_member (type, orig_rhs);
8731 : :
8732 : 1980541 : return convert (type, rhs);
8733 : : }
8734 : 79012 : else if (codel == POINTER_TYPE && coder == ARRAY_TYPE)
8735 : : {
8736 : : /* ??? This should not be an error when inlining calls to
8737 : : unprototyped functions. */
8738 : 4 : const char msg[] = "invalid use of non-lvalue array";
8739 : 4 : if (warnopt)
8740 : 0 : warning_at (location, warnopt, msg);
8741 : : else
8742 : 4 : error_at (location, msg);
8743 : 4 : return error_mark_node;
8744 : : }
8745 : 79008 : else if (codel == POINTER_TYPE
8746 : 77742 : && (coder == INTEGER_TYPE
8747 : 77742 : || coder == ENUMERAL_TYPE
8748 : 600 : || coder == BOOLEAN_TYPE
8749 : 600 : || coder == NULLPTR_TYPE
8750 : 20 : || coder == BITINT_TYPE))
8751 : : {
8752 : 77734 : if (null_pointer_constant && c_inhibit_evaluation_warnings == 0
8753 : 76736 : && coder == INTEGER_TYPE)
8754 : 76139 : warning_at (location, OPT_Wzero_as_null_pointer_constant,
8755 : : "zero as null pointer constant");
8756 : :
8757 : : /* An explicit constant 0 or type nullptr_t can convert to a pointer,
8758 : : or one that results from arithmetic, even including a cast to
8759 : : integer type. */
8760 : 77734 : if (!null_pointer_constant && coder != NULLPTR_TYPE)
8761 : 972 : switch (errtype)
8762 : : {
8763 : 800 : case ic_argpass:
8764 : 800 : {
8765 : 800 : auto_diagnostic_group d;
8766 : 800 : range_label_for_type_mismatch rhs_label (rhstype, type);
8767 : 800 : gcc_rich_location richloc (expr_loc, &rhs_label,
8768 : 800 : highlight_colors::actual);
8769 : 800 : if (permerror_opt (&richloc, OPT_Wint_conversion,
8770 : : "passing argument %d of %qE makes pointer "
8771 : : "from integer without a cast", parmnum, rname))
8772 : : {
8773 : 439 : maybe_emit_indirection_note (expr_loc, rhs, type);
8774 : 439 : inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
8775 : : }
8776 : 800 : }
8777 : 800 : break;
8778 : 93 : case ic_assign:
8779 : 93 : permerror_opt (location, OPT_Wint_conversion,
8780 : : "assignment to %qT from %qT makes pointer from "
8781 : : "integer without a cast", type, rhstype);
8782 : 93 : break;
8783 : 56 : case ic_init:
8784 : 56 : case ic_init_const:
8785 : 56 : permerror_init (location, OPT_Wint_conversion,
8786 : : "initialization of %qT from %qT makes pointer "
8787 : : "from integer without a cast", type, rhstype);
8788 : 56 : break;
8789 : 23 : case ic_return:
8790 : 23 : permerror_init (location, OPT_Wint_conversion,
8791 : : "returning %qT from a function with return type "
8792 : : "%qT makes pointer from integer without a cast",
8793 : : rhstype, type);
8794 : 23 : break;
8795 : 0 : default:
8796 : 0 : gcc_unreachable ();
8797 : : }
8798 : :
8799 : 77734 : return convert (type, rhs);
8800 : : }
8801 : 1274 : else if ((codel == INTEGER_TYPE || codel == BITINT_TYPE)
8802 : 539 : && coder == POINTER_TYPE)
8803 : : {
8804 : 513 : switch (errtype)
8805 : : {
8806 : 343 : case ic_argpass:
8807 : 343 : {
8808 : 343 : auto_diagnostic_group d;
8809 : 343 : range_label_for_type_mismatch rhs_label (rhstype, type);
8810 : 343 : gcc_rich_location richloc (expr_loc, &rhs_label,
8811 : 343 : highlight_colors::actual);
8812 : 343 : if (permerror_opt (&richloc, OPT_Wint_conversion,
8813 : : "passing argument %d of %qE makes integer from "
8814 : : "pointer without a cast", parmnum, rname))
8815 : : {
8816 : 322 : maybe_emit_indirection_note (expr_loc, rhs, type);
8817 : 322 : inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
8818 : : }
8819 : 343 : }
8820 : 343 : break;
8821 : 52 : case ic_assign:
8822 : 52 : permerror_opt (location, OPT_Wint_conversion,
8823 : : "assignment to %qT from %qT makes integer from "
8824 : : "pointer without a cast", type, rhstype);
8825 : 52 : break;
8826 : 83 : case ic_init:
8827 : 83 : case ic_init_const:
8828 : 83 : permerror_init (location, OPT_Wint_conversion,
8829 : : "initialization of %qT from %qT makes integer "
8830 : : "from pointer without a cast", type, rhstype);
8831 : 83 : break;
8832 : 35 : case ic_return:
8833 : 35 : permerror_opt (location, OPT_Wint_conversion, "returning %qT from a "
8834 : : "function with return type %qT makes integer from "
8835 : : "pointer without a cast", rhstype, type);
8836 : 35 : break;
8837 : 0 : default:
8838 : 0 : gcc_unreachable ();
8839 : : }
8840 : :
8841 : 513 : return convert (type, rhs);
8842 : : }
8843 : 613 : else if (C_BOOLEAN_TYPE_P (type)
8844 : : /* The type nullptr_t may be converted to bool. The
8845 : : result is false. */
8846 : 763 : && (coder == POINTER_TYPE || coder == NULLPTR_TYPE))
8847 : : {
8848 : 150 : tree ret;
8849 : 150 : bool save = in_late_binary_op;
8850 : 150 : in_late_binary_op = true;
8851 : 150 : ret = convert (type, rhs);
8852 : 150 : in_late_binary_op = save;
8853 : 150 : return ret;
8854 : : }
8855 : 611 : else if (codel == NULLPTR_TYPE && null_pointer_constant)
8856 : 6 : return convert (type, rhs);
8857 : :
8858 : 605 : switch (errtype)
8859 : : {
8860 : 35 : case ic_argpass:
8861 : 35 : {
8862 : 35 : auto_diagnostic_group d;
8863 : 35 : range_label_for_type_mismatch rhs_label (rhstype, type);
8864 : 35 : gcc_rich_location richloc (expr_loc, &rhs_label,
8865 : 35 : highlight_colors::actual);
8866 : 35 : const char msg[] = G_("incompatible type for argument %d of %qE");
8867 : 35 : if (warnopt)
8868 : 8 : warning_at (expr_loc, warnopt, msg, parmnum, rname);
8869 : : else
8870 : 27 : error_at (&richloc, msg, parmnum, rname);
8871 : 35 : inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
8872 : 35 : }
8873 : 35 : break;
8874 : 97 : case ic_assign:
8875 : 97 : {
8876 : 97 : const char msg[]
8877 : : = G_("incompatible types when assigning to type %qT from type %qT");
8878 : 97 : if (warnopt)
8879 : 0 : warning_at (expr_loc, 0, msg, type, rhstype);
8880 : : else
8881 : 97 : error_at (expr_loc, msg, type, rhstype);
8882 : 97 : break;
8883 : : }
8884 : 458 : case ic_init:
8885 : 458 : case ic_init_const:
8886 : 458 : {
8887 : 458 : const char msg[]
8888 : : = G_("incompatible types when initializing type %qT using type %qT");
8889 : 458 : if (warnopt)
8890 : 0 : warning_at (location, 0, msg, type, rhstype);
8891 : : else
8892 : 458 : error_at (location, msg, type, rhstype);
8893 : 458 : break;
8894 : : }
8895 : 15 : case ic_return:
8896 : 15 : {
8897 : 15 : const char msg[]
8898 : : = G_("incompatible types when returning type %qT but %qT was expected");
8899 : 15 : if (warnopt)
8900 : 0 : warning_at (location, 0, msg, rhstype, type);
8901 : : else
8902 : 15 : error_at (location, msg, rhstype, type);
8903 : 15 : break;
8904 : : }
8905 : 0 : default:
8906 : 0 : gcc_unreachable ();
8907 : : }
8908 : :
8909 : 605 : return error_mark_node;
8910 : : }
8911 : :
8912 : : /* If VALUE is a compound expr all of whose expressions are constant, then
8913 : : return its value. Otherwise, return error_mark_node.
8914 : :
8915 : : This is for handling COMPOUND_EXPRs as initializer elements
8916 : : which is allowed with a warning when -pedantic is specified. */
8917 : :
8918 : : static tree
8919 : 2 : valid_compound_expr_initializer (tree value, tree endtype)
8920 : : {
8921 : 2 : if (TREE_CODE (value) == COMPOUND_EXPR)
8922 : : {
8923 : 1 : if (valid_compound_expr_initializer (TREE_OPERAND (value, 0), endtype)
8924 : 1 : == error_mark_node)
8925 : : return error_mark_node;
8926 : 0 : return valid_compound_expr_initializer (TREE_OPERAND (value, 1),
8927 : 0 : endtype);
8928 : : }
8929 : 1 : else if (!initializer_constant_valid_p (value, endtype))
8930 : 1 : return error_mark_node;
8931 : : else
8932 : : return value;
8933 : : }
8934 : :
8935 : : /* Perform appropriate conversions on the initial value of a variable,
8936 : : store it in the declaration DECL,
8937 : : and print any error messages that are appropriate.
8938 : : If ORIGTYPE is not NULL_TREE, it is the original type of INIT.
8939 : : If the init is invalid, store an ERROR_MARK.
8940 : :
8941 : : INIT_LOC is the location of the initial value. */
8942 : :
8943 : : void
8944 : 7094926 : store_init_value (location_t init_loc, tree decl, tree init, tree origtype)
8945 : : {
8946 : 7094926 : tree value, type;
8947 : 7094926 : bool npc = false;
8948 : 7094926 : bool int_const_expr = false;
8949 : 7094926 : bool arith_const_expr = false;
8950 : :
8951 : : /* If variable's type was invalidly declared, just ignore it. */
8952 : :
8953 : 7094926 : type = TREE_TYPE (decl);
8954 : 7094926 : if (TREE_CODE (type) == ERROR_MARK)
8955 : : return;
8956 : :
8957 : : /* Digest the specified initializer into an expression. */
8958 : :
8959 : 7094919 : if (init)
8960 : : {
8961 : 7094919 : npc = null_pointer_constant_p (init);
8962 : 7094919 : int_const_expr = (TREE_CODE (init) == INTEGER_CST
8963 : 408428 : && !TREE_OVERFLOW (init)
8964 : 7503311 : && INTEGRAL_TYPE_P (TREE_TYPE (init)));
8965 : : /* Not fully determined before folding. */
8966 : : arith_const_expr = true;
8967 : : }
8968 : 7094919 : bool constexpr_p = (VAR_P (decl)
8969 : 7094919 : && C_DECL_DECLARED_CONSTEXPR (decl));
8970 : 7094919 : value = digest_init (init_loc, decl, type, init, origtype, npc,
8971 : : int_const_expr, arith_const_expr, true,
8972 : 7094919 : TREE_STATIC (decl) || constexpr_p, constexpr_p);
8973 : :
8974 : : /* Store the expression if valid; else report error. */
8975 : :
8976 : 7094919 : if (!in_system_header_at (input_location)
8977 : 7094919 : && AGGREGATE_TYPE_P (TREE_TYPE (decl)) && !TREE_STATIC (decl))
8978 : 27292 : warning (OPT_Wtraditional, "traditional C rejects automatic "
8979 : : "aggregate initialization");
8980 : :
8981 : 7094919 : if (value != error_mark_node || TREE_CODE (decl) != FUNCTION_DECL)
8982 : 7094918 : DECL_INITIAL (decl) = value;
8983 : :
8984 : : /* ANSI wants warnings about out-of-range constant initializers. */
8985 : 7094930 : STRIP_TYPE_NOPS (value);
8986 : 7094919 : if (TREE_STATIC (decl))
8987 : 179475 : constant_expression_warning (value);
8988 : :
8989 : : /* Check if we need to set array size from compound literal size. */
8990 : 7094919 : if (TREE_CODE (type) == ARRAY_TYPE
8991 : 25803 : && TYPE_DOMAIN (type) == NULL_TREE
8992 : 7107229 : && value != error_mark_node)
8993 : : {
8994 : : tree inside_init = init;
8995 : :
8996 : 11470 : STRIP_TYPE_NOPS (inside_init);
8997 : 11470 : inside_init = fold (inside_init);
8998 : :
8999 : 11470 : if (TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR)
9000 : : {
9001 : 13 : tree cldecl = COMPOUND_LITERAL_EXPR_DECL (inside_init);
9002 : :
9003 : 13 : if (TYPE_DOMAIN (TREE_TYPE (cldecl)))
9004 : : {
9005 : : /* For int foo[] = (int [3]){1}; we need to set array size
9006 : : now since later on array initializer will be just the
9007 : : brace enclosed list of the compound literal. */
9008 : 13 : tree etype = strip_array_types (TREE_TYPE (decl));
9009 : 13 : type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
9010 : 13 : TYPE_DOMAIN (type) = TYPE_DOMAIN (TREE_TYPE (cldecl));
9011 : 13 : layout_type (type);
9012 : 13 : layout_decl (cldecl, 0);
9013 : 13 : TREE_TYPE (decl)
9014 : 26 : = c_build_qualified_type (type, TYPE_QUALS (etype));
9015 : : }
9016 : : }
9017 : : }
9018 : : }
9019 : :
9020 : : /* Methods for storing and printing names for error messages. */
9021 : :
9022 : : /* Implement a spelling stack that allows components of a name to be pushed
9023 : : and popped. Each element on the stack is this structure. */
9024 : :
9025 : : struct spelling
9026 : : {
9027 : : int kind;
9028 : : union
9029 : : {
9030 : : unsigned HOST_WIDE_INT i;
9031 : : const char *s;
9032 : : } u;
9033 : : };
9034 : :
9035 : : #define SPELLING_STRING 1
9036 : : #define SPELLING_MEMBER 2
9037 : : #define SPELLING_BOUNDS 3
9038 : :
9039 : : static struct spelling *spelling; /* Next stack element (unused). */
9040 : : static struct spelling *spelling_base; /* Spelling stack base. */
9041 : : static int spelling_size; /* Size of the spelling stack. */
9042 : :
9043 : : /* Macros to save and restore the spelling stack around push_... functions.
9044 : : Alternative to SAVE_SPELLING_STACK. */
9045 : :
9046 : : #define SPELLING_DEPTH() (spelling - spelling_base)
9047 : : #define RESTORE_SPELLING_DEPTH(DEPTH) (spelling = spelling_base + (DEPTH))
9048 : :
9049 : : /* Push an element on the spelling stack with type KIND and assign VALUE
9050 : : to MEMBER. */
9051 : :
9052 : : #define PUSH_SPELLING(KIND, VALUE, MEMBER) \
9053 : : { \
9054 : : int depth = SPELLING_DEPTH (); \
9055 : : \
9056 : : if (depth >= spelling_size) \
9057 : : { \
9058 : : spelling_size += 10; \
9059 : : spelling_base = XRESIZEVEC (struct spelling, spelling_base, \
9060 : : spelling_size); \
9061 : : RESTORE_SPELLING_DEPTH (depth); \
9062 : : } \
9063 : : \
9064 : : spelling->kind = (KIND); \
9065 : : spelling->MEMBER = (VALUE); \
9066 : : spelling++; \
9067 : : }
9068 : :
9069 : : /* Push STRING on the stack. Printed literally. */
9070 : :
9071 : : static void
9072 : 7092366 : push_string (const char *string)
9073 : : {
9074 : 7092366 : PUSH_SPELLING (SPELLING_STRING, string, u.s);
9075 : 7092366 : }
9076 : :
9077 : : /* Push a member name on the stack. Printed as '.' STRING. */
9078 : :
9079 : : static void
9080 : 1225175 : push_member_name (tree decl)
9081 : : {
9082 : 1225175 : const char *const string
9083 : 1225175 : = (DECL_NAME (decl)
9084 : 1225175 : ? identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl)))
9085 : 194 : : _("<anonymous>"));
9086 : 1225175 : PUSH_SPELLING (SPELLING_MEMBER, string, u.s);
9087 : 1225175 : }
9088 : :
9089 : : /* Push an array bounds on the stack. Printed as [BOUNDS]. */
9090 : :
9091 : : static void
9092 : 2596411 : push_array_bounds (unsigned HOST_WIDE_INT bounds)
9093 : : {
9094 : 2596411 : PUSH_SPELLING (SPELLING_BOUNDS, bounds, u.i);
9095 : 2596411 : }
9096 : :
9097 : : /* Compute the maximum size in bytes of the printed spelling. */
9098 : :
9099 : : static int
9100 : 2830 : spelling_length (void)
9101 : : {
9102 : 2830 : int size = 0;
9103 : 2830 : struct spelling *p;
9104 : :
9105 : 6318 : for (p = spelling_base; p < spelling; p++)
9106 : : {
9107 : 3488 : if (p->kind == SPELLING_BOUNDS)
9108 : 1475 : size += 25;
9109 : : else
9110 : 2013 : size += strlen (p->u.s) + 1;
9111 : : }
9112 : :
9113 : 2830 : return size;
9114 : : }
9115 : :
9116 : : /* Print the spelling to BUFFER and return it. */
9117 : :
9118 : : static char *
9119 : 2830 : print_spelling (char *buffer)
9120 : : {
9121 : 2830 : char *d = buffer;
9122 : 2830 : struct spelling *p;
9123 : :
9124 : 6318 : for (p = spelling_base; p < spelling; p++)
9125 : 3488 : if (p->kind == SPELLING_BOUNDS)
9126 : : {
9127 : 1475 : sprintf (d, "[" HOST_WIDE_INT_PRINT_UNSIGNED "]", p->u.i);
9128 : 1475 : d += strlen (d);
9129 : : }
9130 : : else
9131 : : {
9132 : 2013 : const char *s;
9133 : 2013 : if (p->kind == SPELLING_MEMBER)
9134 : 190 : *d++ = '.';
9135 : 16603 : for (s = p->u.s; (*d = *s++); d++)
9136 : : ;
9137 : : }
9138 : 2830 : *d++ = '\0';
9139 : 2830 : return buffer;
9140 : : }
9141 : :
9142 : : /* Check whether INIT, a floating or integer constant, is
9143 : : representable in TYPE, a real floating type with the same radix or
9144 : : a decimal floating type initialized with a binary floating
9145 : : constant. Return true if OK, false if not. */
9146 : : static bool
9147 : 362 : constexpr_init_fits_real_type (tree type, tree init)
9148 : : {
9149 : 362 : gcc_assert (SCALAR_FLOAT_TYPE_P (type));
9150 : 362 : gcc_assert (TREE_CODE (init) == INTEGER_CST || TREE_CODE (init) == REAL_CST);
9151 : 362 : if (TREE_CODE (init) == REAL_CST
9152 : 362 : && TYPE_MODE (TREE_TYPE (init)) == TYPE_MODE (type))
9153 : : {
9154 : : /* Same mode, no conversion required except for the case of
9155 : : signaling NaNs if the types are incompatible (e.g. double and
9156 : : long double with the same mode). */
9157 : 177 : if (REAL_VALUE_ISSIGNALING_NAN (TREE_REAL_CST (init))
9158 : 195 : && !comptypes (TYPE_MAIN_VARIANT (type),
9159 : 18 : TYPE_MAIN_VARIANT (TREE_TYPE (init))))
9160 : : return false;
9161 : 177 : return true;
9162 : : }
9163 : 185 : if (TREE_CODE (init) == INTEGER_CST)
9164 : : {
9165 : 54 : tree converted = build_real_from_int_cst (type, init);
9166 : 54 : bool fail = false;
9167 : 108 : wide_int w = real_to_integer (&TREE_REAL_CST (converted), &fail,
9168 : 54 : TYPE_PRECISION (TREE_TYPE (init)));
9169 : 68 : return !fail && wi::eq_p (w, wi::to_wide (init));
9170 : 54 : }
9171 : 131 : if (REAL_VALUE_ISSIGNALING_NAN (TREE_REAL_CST (init)))
9172 : : return false;
9173 : 114 : if ((REAL_VALUE_ISINF (TREE_REAL_CST (init))
9174 : 34 : && MODE_HAS_INFINITIES (TYPE_MODE (type)))
9175 : 218 : || (REAL_VALUE_ISNAN (TREE_REAL_CST (init))
9176 : 34 : && MODE_HAS_NANS (TYPE_MODE (type))))
9177 : 20 : return true;
9178 : 94 : if (DECIMAL_FLOAT_TYPE_P (type)
9179 : 134 : && !DECIMAL_FLOAT_TYPE_P (TREE_TYPE (init)))
9180 : : {
9181 : : /* This is valid if the real number represented by the
9182 : : initializer can be exactly represented in the decimal
9183 : : type. Compare the values using MPFR. */
9184 : 8 : REAL_VALUE_TYPE t;
9185 : 8 : real_convert (&t, TYPE_MODE (type), &TREE_REAL_CST (init));
9186 : 8 : mpfr_t bin_val, dec_val;
9187 : 8 : mpfr_init2 (bin_val, REAL_MODE_FORMAT (TYPE_MODE (TREE_TYPE (init)))->p);
9188 : 8 : mpfr_init2 (dec_val, REAL_MODE_FORMAT (TYPE_MODE (TREE_TYPE (init)))->p);
9189 : 8 : mpfr_from_real (bin_val, &TREE_REAL_CST (init), MPFR_RNDN);
9190 : 8 : char string[256];
9191 : 8 : real_to_decimal (string, &t, sizeof string, 0, 1);
9192 : 8 : bool res = (mpfr_strtofr (dec_val, string, NULL, 10, MPFR_RNDN) == 0
9193 : 8 : && mpfr_equal_p (bin_val, dec_val));
9194 : 8 : mpfr_clear (bin_val);
9195 : 8 : mpfr_clear (dec_val);
9196 : 8 : return res;
9197 : : }
9198 : : /* exact_real_truncate is not quite right here, since it doesn't
9199 : : allow even an exact conversion to subnormal values. */
9200 : 86 : REAL_VALUE_TYPE t;
9201 : 86 : real_convert (&t, TYPE_MODE (type), &TREE_REAL_CST (init));
9202 : 86 : return real_identical (&t, &TREE_REAL_CST (init));
9203 : : }
9204 : :
9205 : : /* Check whether INIT (location LOC) is valid as a 'constexpr'
9206 : : initializer for type TYPE, and give an error if not. INIT has
9207 : : already been folded and verified to be constant. INT_CONST_EXPR
9208 : : and ARITH_CONST_EXPR say whether it is an integer constant
9209 : : expression or arithmetic constant expression, respectively. If
9210 : : TYPE is not a scalar type, this function does nothing. */
9211 : :
9212 : : static void
9213 : 898 : check_constexpr_init (location_t loc, tree type, tree init,
9214 : : bool int_const_expr, bool arith_const_expr)
9215 : : {
9216 : 898 : if (POINTER_TYPE_P (type))
9217 : : {
9218 : : /* The initializer must be null. */
9219 : 86 : if (TREE_CODE (init) != INTEGER_CST || !integer_zerop (init))
9220 : 8 : error_at (loc, "%<constexpr%> pointer initializer is not null");
9221 : 86 : return;
9222 : : }
9223 : 812 : if (INTEGRAL_TYPE_P (type))
9224 : : {
9225 : : /* The initializer must be an integer constant expression,
9226 : : representable in the target type. */
9227 : 305 : if (!int_const_expr)
9228 : : {
9229 : 13 : if (TREE_CODE (init) == RAW_DATA_CST
9230 : 13 : && TYPE_PRECISION (type) == CHAR_BIT)
9231 : : {
9232 : 4 : if (!TYPE_UNSIGNED (type))
9233 : 137 : for (unsigned int i = 0;
9234 : 140 : i < (unsigned) RAW_DATA_LENGTH (init); ++i)
9235 : 138 : if (RAW_DATA_SCHAR_ELT (init, i) < 0)
9236 : : {
9237 : 1 : error_at (loc, "%<constexpr%> initializer not "
9238 : : "representable in type of object");
9239 : 1 : break;
9240 : : }
9241 : : }
9242 : : else
9243 : 9 : error_at (loc, "%<constexpr%> integer initializer is not an "
9244 : : "integer constant expression");
9245 : : }
9246 : 292 : else if (!int_fits_type_p (init, type))
9247 : 6 : error_at (loc, "%<constexpr%> initializer not representable in "
9248 : : "type of object");
9249 : 305 : return;
9250 : : }
9251 : : /* We don't apply any extra checks to extension types such as vector
9252 : : or fixed-point types. */
9253 : 507 : if (TREE_CODE (type) != REAL_TYPE && TREE_CODE (type) != COMPLEX_TYPE)
9254 : : return;
9255 : 353 : if (!arith_const_expr)
9256 : : {
9257 : 5 : error_at (loc, "%<constexpr%> initializer is not an arithmetic "
9258 : : "constant expression");
9259 : 5 : return;
9260 : : }
9261 : : /* We don't apply any extra checks to complex integers. */
9262 : 348 : if (TREE_CODE (type) == COMPLEX_TYPE
9263 : 348 : && TREE_CODE (TREE_TYPE (type)) != REAL_TYPE)
9264 : : return;
9265 : : /* Following N3082, a real type cannot be initialized from a complex
9266 : : type and a binary type cannot be initialized from a decimal type
9267 : : (but initializing a decimal type from a binary type is OK).
9268 : : Signaling NaN initializers are OK only if the types are
9269 : : compatible (not just the same mode); all quiet NaN and infinity
9270 : : initializations are considered to preserve the value. */
9271 : 348 : if (TREE_CODE (TREE_TYPE (init)) == COMPLEX_TYPE
9272 : 348 : && SCALAR_FLOAT_TYPE_P (type))
9273 : : {
9274 : 6 : error_at (loc, "%<constexpr%> initializer for a real type is of "
9275 : : "complex type");
9276 : 6 : return;
9277 : : }
9278 : 342 : if (SCALAR_FLOAT_TYPE_P (type)
9279 : 300 : && SCALAR_FLOAT_TYPE_P (TREE_TYPE (init))
9280 : 250 : && DECIMAL_FLOAT_TYPE_P (TREE_TYPE (init))
9281 : 481 : && !DECIMAL_FLOAT_TYPE_P (type))
9282 : : {
9283 : 6 : error_at (loc, "%<constexpr%> initializer for a binary "
9284 : : "floating-point type is of decimal type");
9285 : 6 : return;
9286 : : }
9287 : 336 : bool fits;
9288 : 336 : if (TREE_CODE (type) == COMPLEX_TYPE)
9289 : : {
9290 : 42 : switch (TREE_CODE (init))
9291 : : {
9292 : 10 : case INTEGER_CST:
9293 : 10 : case REAL_CST:
9294 : 10 : fits = constexpr_init_fits_real_type (TREE_TYPE (type), init);
9295 : 10 : break;
9296 : 32 : case COMPLEX_CST:
9297 : 32 : fits = (constexpr_init_fits_real_type (TREE_TYPE (type),
9298 : 32 : TREE_REALPART (init))
9299 : 58 : && constexpr_init_fits_real_type (TREE_TYPE (type),
9300 : 26 : TREE_IMAGPART (init)));
9301 : : break;
9302 : 0 : default:
9303 : 0 : gcc_unreachable ();
9304 : : }
9305 : : }
9306 : : else
9307 : 294 : fits = constexpr_init_fits_real_type (type, init);
9308 : 304 : if (!fits)
9309 : 65 : error_at (loc, "%<constexpr%> initializer not representable in "
9310 : : "type of object");
9311 : : }
9312 : :
9313 : : /* Digest the parser output INIT as an initializer for type TYPE
9314 : : initializing DECL.
9315 : : Return a C expression of type TYPE to represent the initial value.
9316 : :
9317 : : If ORIGTYPE is not NULL_TREE, it is the original type of INIT.
9318 : :
9319 : : NULL_POINTER_CONSTANT is true if INIT is a null pointer constant,
9320 : : INT_CONST_EXPR is true if INIT is an integer constant expression,
9321 : : and ARITH_CONST_EXPR is true if INIT is, or might be, an arithmetic
9322 : : constant expression, false if it has already been determined in the
9323 : : caller that it is not (but folding may have made the value passed here
9324 : : indistinguishable from an arithmetic constant expression).
9325 : :
9326 : : If INIT is a string constant, STRICT_STRING is true if it is
9327 : : unparenthesized or we should not warn here for it being parenthesized.
9328 : : For other types of INIT, STRICT_STRING is not used.
9329 : :
9330 : : INIT_LOC is the location of the INIT.
9331 : :
9332 : : REQUIRE_CONSTANT requests an error if non-constant initializers or
9333 : : elements are seen. REQUIRE_CONSTEXPR means the stricter requirements
9334 : : on initializers for 'constexpr' objects apply. */
9335 : :
9336 : : static tree
9337 : 16553964 : digest_init (location_t init_loc, tree decl, tree type, tree init,
9338 : : tree origtype, bool null_pointer_constant, bool int_const_expr,
9339 : : bool arith_const_expr, bool strict_string,
9340 : : bool require_constant, bool require_constexpr)
9341 : : {
9342 : 16553964 : enum tree_code code = TREE_CODE (type);
9343 : 16553964 : tree inside_init = init;
9344 : 16553964 : tree semantic_type = NULL_TREE;
9345 : 16553964 : bool maybe_const = true;
9346 : :
9347 : 16553964 : if (type == error_mark_node
9348 : 16553964 : || !init
9349 : 33107928 : || error_operand_p (init))
9350 : : return error_mark_node;
9351 : :
9352 : 16561211 : STRIP_TYPE_NOPS (inside_init);
9353 : :
9354 : : /* If require_constant is TRUE, when the initializer is a call to
9355 : : .ACCESS_WITH_SIZE, use the first argument as the initializer.
9356 : : For example:
9357 : : y = (char *) .ACCESS_WITH_SIZE ((char *) &static_annotated.c,...)
9358 : : will be converted to
9359 : : y = &static_annotated.c. */
9360 : :
9361 : 16552667 : if (require_constant
9362 : 2887990 : && TREE_CODE (inside_init) == NOP_EXPR
9363 : 736213 : && TREE_CODE (TREE_OPERAND (inside_init, 0)) == CALL_EXPR
9364 : 16552669 : && is_access_with_size_p (TREE_OPERAND (inside_init, 0)))
9365 : 2 : inside_init
9366 : 2 : = get_ref_from_access_with_size (TREE_OPERAND (inside_init, 0));
9367 : :
9368 : 16552667 : if (!c_in_omp_for)
9369 : : {
9370 : 16547931 : if (TREE_CODE (inside_init) == EXCESS_PRECISION_EXPR)
9371 : : {
9372 : 437 : semantic_type = TREE_TYPE (inside_init);
9373 : 437 : inside_init = TREE_OPERAND (inside_init, 0);
9374 : : }
9375 : 16547931 : inside_init = c_fully_fold (inside_init, require_constant, &maybe_const);
9376 : : }
9377 : : /* TODO: this may not detect all cases of expressions folding to
9378 : : constants that are not arithmetic constant expressions. */
9379 : 16552667 : if (!maybe_const)
9380 : : arith_const_expr = false;
9381 : 24734168 : else if (!INTEGRAL_TYPE_P (TREE_TYPE (inside_init))
9382 : 5564249 : && TREE_CODE (TREE_TYPE (inside_init)) != REAL_TYPE
9383 : 16529013 : && TREE_CODE (TREE_TYPE (inside_init)) != COMPLEX_TYPE)
9384 : : arith_const_expr = false;
9385 : 8233088 : else if (TREE_CODE (inside_init) != INTEGER_CST
9386 : : && TREE_CODE (inside_init) != REAL_CST
9387 : : && TREE_CODE (inside_init) != COMPLEX_CST
9388 : : && TREE_CODE (inside_init) != RAW_DATA_CST)
9389 : : arith_const_expr = false;
9390 : 4978107 : else if (TREE_OVERFLOW (inside_init))
9391 : 11574604 : arith_const_expr = false;
9392 : :
9393 : : /* Initialization of an array of chars from a string constant
9394 : : optionally enclosed in braces. */
9395 : :
9396 : 16552667 : if (code == ARRAY_TYPE && inside_init
9397 : 187465 : && TREE_CODE (inside_init) == STRING_CST)
9398 : : {
9399 : 11407 : tree typ1
9400 : 11407 : = (TYPE_ATOMIC (TREE_TYPE (type))
9401 : 11407 : ? c_build_qualified_type (TYPE_MAIN_VARIANT (TREE_TYPE (type)),
9402 : : TYPE_QUAL_ATOMIC)
9403 : 11398 : : TYPE_MAIN_VARIANT (TREE_TYPE (type)));
9404 : : /* Note that an array could be both an array of character type
9405 : : and an array of wchar_t if wchar_t is signed char or unsigned
9406 : : char. */
9407 : 22814 : bool char_array = (typ1 == char_type_node
9408 : 462 : || typ1 == signed_char_type_node
9409 : 11840 : || typ1 == unsigned_char_type_node);
9410 : 11407 : bool wchar_array = !!comptypes (typ1, wchar_type_node);
9411 : 11407 : bool char16_array = !!comptypes (typ1, char16_type_node);
9412 : 11407 : bool char32_array = !!comptypes (typ1, char32_type_node);
9413 : :
9414 : 11407 : if (char_array || wchar_array || char16_array || char32_array)
9415 : : {
9416 : 11387 : struct c_expr expr;
9417 : 11387 : tree typ2 = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init)));
9418 : 11387 : bool incompat_string_cst = false;
9419 : 11387 : expr.value = inside_init;
9420 : 11387 : expr.original_code = (strict_string ? STRING_CST : ERROR_MARK);
9421 : 11387 : expr.original_type = NULL;
9422 : 11387 : expr.m_decimal = 0;
9423 : 11387 : maybe_warn_string_init (init_loc, type, expr);
9424 : :
9425 : 11387 : if (TYPE_DOMAIN (type) && !TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
9426 : 91 : pedwarn_init (init_loc, OPT_Wpedantic,
9427 : : "initialization of a flexible array member");
9428 : :
9429 : 11387 : if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
9430 : 11387 : TYPE_MAIN_VARIANT (type)))
9431 : : return inside_init;
9432 : :
9433 : 4137 : if (char_array)
9434 : : {
9435 : 4042 : if (typ2 != char_type_node && typ2 != char8_type_node)
9436 : : incompat_string_cst = true;
9437 : : }
9438 : 95 : else if (!comptypes (typ1, typ2))
9439 : : incompat_string_cst = true;
9440 : :
9441 : : if (incompat_string_cst)
9442 : : {
9443 : 50 : error_init (init_loc, "cannot initialize array of %qT from "
9444 : : "a string literal with type array of %qT",
9445 : : typ1, typ2);
9446 : 50 : return error_mark_node;
9447 : : }
9448 : :
9449 : 4087 : if (require_constexpr
9450 : 4087 : && TYPE_UNSIGNED (typ1) != TYPE_UNSIGNED (typ2))
9451 : : {
9452 : : /* Check if all characters of the string can be
9453 : : represented in the type of the constexpr object being
9454 : : initialized. */
9455 : 24 : unsigned HOST_WIDE_INT len = TREE_STRING_LENGTH (inside_init);
9456 : 24 : const unsigned char *p =
9457 : 24 : (const unsigned char *) TREE_STRING_POINTER (inside_init);
9458 : 24 : gcc_assert (CHAR_TYPE_SIZE == 8 && CHAR_BIT == 8);
9459 : 70 : for (unsigned i = 0; i < len; i++)
9460 : 58 : if (p[i] > 127)
9461 : : {
9462 : 12 : error_init (init_loc, "%<constexpr%> initializer not "
9463 : : "representable in type of object");
9464 : 12 : break;
9465 : : }
9466 : : }
9467 : :
9468 : 4087 : if (TYPE_DOMAIN (type) != NULL_TREE
9469 : 4010 : && TYPE_SIZE (type) != NULL_TREE
9470 : 8038 : && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
9471 : : {
9472 : 3951 : unsigned HOST_WIDE_INT len = TREE_STRING_LENGTH (inside_init);
9473 : :
9474 : 3951 : if (compare_tree_int (TYPE_SIZE_UNIT (type), len) < 0)
9475 : : {
9476 : 395 : unsigned HOST_WIDE_INT avail
9477 : 395 : = tree_to_uhwi (TYPE_SIZE_UNIT (type));
9478 : 395 : unsigned unit = TYPE_PRECISION (typ1) / BITS_PER_UNIT;
9479 : 395 : const char *p = TREE_STRING_POINTER (inside_init);
9480 : :
9481 : : /* Construct truncated string. */
9482 : 395 : inside_init = build_string (avail, p);
9483 : :
9484 : : /* Subtract the size of a single (possibly wide) character
9485 : : because it may be ok to ignore the terminating NUL char
9486 : : that is counted in the length of the constant. */
9487 : 395 : if (len - unit > avail)
9488 : 63 : pedwarn_init (init_loc, 0,
9489 : : "initializer-string for array of %qT "
9490 : : "is too long (%wu chars into %wu "
9491 : : "available)", typ1, len, avail);
9492 : 332 : else if (warn_cxx_compat)
9493 : 9 : warning_at (init_loc, OPT_Wc___compat,
9494 : : "initializer-string for array of %qT "
9495 : : "is too long for C++ (%wu chars into %wu "
9496 : : "available)", typ1, len, avail);
9497 : 323 : else if (warn_unterminated_string_initialization
9498 : 323 : && get_attr_nonstring_decl (decl) == NULL_TREE)
9499 : 22 : warning_at (init_loc,
9500 : 22 : OPT_Wunterminated_string_initialization,
9501 : : "initializer-string for array of %qT "
9502 : : "truncates NUL terminator but destination "
9503 : : "lacks %qs attribute (%wu chars into %wu "
9504 : : "available)", typ1, "nonstring", len, avail);
9505 : : }
9506 : : }
9507 : :
9508 : 4087 : TREE_TYPE (inside_init) = type;
9509 : 4087 : return inside_init;
9510 : : }
9511 : 20 : else if (INTEGRAL_TYPE_P (typ1))
9512 : : {
9513 : 20 : error_init (init_loc, "array of inappropriate type initialized "
9514 : : "from string constant");
9515 : 20 : return error_mark_node;
9516 : : }
9517 : : }
9518 : :
9519 : : /* Build a VECTOR_CST from a *constant* vector constructor. If the
9520 : : vector constructor is not constant (e.g. {1,2,3,foo()}) then punt
9521 : : below and handle as a constructor. */
9522 : 16541260 : if (code == VECTOR_TYPE
9523 : 6154376 : && VECTOR_TYPE_P (TREE_TYPE (inside_init))
9524 : 6154374 : && vector_types_convertible_p (TREE_TYPE (inside_init), type, true)
9525 : 22695596 : && TREE_CONSTANT (inside_init))
9526 : : {
9527 : 618492 : if (TREE_CODE (inside_init) == VECTOR_CST
9528 : 618589 : && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
9529 : 97 : TYPE_MAIN_VARIANT (type)))
9530 : : return inside_init;
9531 : :
9532 : 618395 : if (TREE_CODE (inside_init) == CONSTRUCTOR)
9533 : : {
9534 : : unsigned HOST_WIDE_INT ix;
9535 : : tree value;
9536 : 4081696 : bool constant_p = true;
9537 : :
9538 : : /* Iterate through elements and check if all constructor
9539 : : elements are *_CSTs. */
9540 : 4081696 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (inside_init), ix, value)
9541 : 3463357 : if (!CONSTANT_CLASS_P (value))
9542 : : {
9543 : : constant_p = false;
9544 : : break;
9545 : : }
9546 : :
9547 : 618395 : if (constant_p)
9548 : 618339 : return build_vector_from_ctor (type,
9549 : 618339 : CONSTRUCTOR_ELTS (inside_init));
9550 : : }
9551 : : }
9552 : :
9553 : 15922824 : if (warn_sequence_point)
9554 : 2446926 : verify_sequence_points (inside_init);
9555 : :
9556 : : /* Any type can be initialized
9557 : : from an expression of the same type, optionally with braces. */
9558 : :
9559 : 15922824 : if (inside_init && TREE_TYPE (inside_init) != NULL_TREE
9560 : 31845648 : && (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
9561 : 15922824 : TYPE_MAIN_VARIANT (type))
9562 : 3071938 : || (code == ARRAY_TYPE
9563 : 476 : && comptypes (TREE_TYPE (inside_init), type))
9564 : 3071938 : || (gnu_vector_type_p (type)
9565 : 159 : && comptypes (TREE_TYPE (inside_init), type))
9566 : 3071938 : || (code == POINTER_TYPE
9567 : 111641 : && TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE
9568 : 9260 : && comptypes (TREE_TYPE (TREE_TYPE (inside_init)),
9569 : 9260 : TREE_TYPE (type)))))
9570 : : {
9571 : 12852860 : if (code == POINTER_TYPE)
9572 : : {
9573 : 783338 : if (TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE)
9574 : : {
9575 : 1974 : if (TREE_CODE (inside_init) == STRING_CST
9576 : 66 : || TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR)
9577 : 1972 : inside_init = array_to_pointer_conversion
9578 : 1972 : (init_loc, inside_init);
9579 : : else
9580 : : {
9581 : 2 : error_init (init_loc, "invalid use of non-lvalue array");
9582 : 2 : return error_mark_node;
9583 : : }
9584 : : }
9585 : : }
9586 : :
9587 : 12852858 : if (code == VECTOR_TYPE || c_hardbool_type_attr (type))
9588 : : /* Although the types are compatible, we may require a
9589 : : conversion. */
9590 : 5535837 : inside_init = convert (type, inside_init);
9591 : :
9592 : 12852858 : if ((code == RECORD_TYPE || code == UNION_TYPE)
9593 : 12852858 : && !comptypes (TYPE_MAIN_VARIANT (type), TYPE_MAIN_VARIANT (TREE_TYPE (inside_init))))
9594 : : {
9595 : 0 : error_init (init_loc, "invalid initializer");
9596 : 0 : return error_mark_node;
9597 : : }
9598 : :
9599 : 12852858 : if (require_constant
9600 : 2296687 : && TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR)
9601 : : {
9602 : : /* As an extension, allow initializing objects with static storage
9603 : : duration with compound literals (which are then treated just as
9604 : : the brace enclosed list they contain). Also allow this for
9605 : : vectors, as we can only assign them with compound literals. */
9606 : 31 : if (flag_isoc99 && code != VECTOR_TYPE)
9607 : 8 : pedwarn_init (init_loc, OPT_Wpedantic, "initializer element "
9608 : : "is not constant");
9609 : 31 : tree decl = COMPOUND_LITERAL_EXPR_DECL (inside_init);
9610 : 31 : inside_init = DECL_INITIAL (decl);
9611 : : }
9612 : :
9613 : 12852858 : if (code == ARRAY_TYPE && TREE_CODE (inside_init) != STRING_CST
9614 : 175582 : && TREE_CODE (inside_init) != CONSTRUCTOR)
9615 : : {
9616 : 2 : error_init (init_loc, "array initialized from non-constant array "
9617 : : "expression");
9618 : 2 : return error_mark_node;
9619 : : }
9620 : :
9621 : : /* Compound expressions can only occur here if -Wpedantic or
9622 : : -pedantic-errors is specified. In the later case, we always want
9623 : : an error. In the former case, we simply want a warning. */
9624 : 12852856 : if (require_constant && pedantic
9625 : 20187 : && TREE_CODE (inside_init) == COMPOUND_EXPR)
9626 : : {
9627 : 1 : inside_init
9628 : 1 : = valid_compound_expr_initializer (inside_init,
9629 : 1 : TREE_TYPE (inside_init));
9630 : 1 : if (inside_init == error_mark_node)
9631 : 1 : error_init (init_loc, "initializer element is not constant");
9632 : : else
9633 : 0 : pedwarn_init (init_loc, OPT_Wpedantic,
9634 : : "initializer element is not constant");
9635 : 1 : if (flag_pedantic_errors)
9636 : 0 : inside_init = error_mark_node;
9637 : : }
9638 : 2296686 : else if (require_constant
9639 : 2296686 : && !initializer_constant_valid_p (inside_init,
9640 : 2296686 : TREE_TYPE (inside_init)))
9641 : : {
9642 : 94 : error_init (init_loc, "initializer element is not constant");
9643 : 94 : inside_init = error_mark_node;
9644 : : }
9645 : 12852761 : else if (require_constant && !maybe_const)
9646 : 219 : pedwarn_init (init_loc, OPT_Wpedantic,
9647 : : "initializer element is not a constant expression");
9648 : 12852542 : else if (require_constexpr)
9649 : 574 : check_constexpr_init (init_loc, type, inside_init,
9650 : : int_const_expr, arith_const_expr);
9651 : :
9652 : : /* Added to enable additional -Wsuggest-attribute=format warnings. */
9653 : 12852856 : if (TREE_CODE (TREE_TYPE (inside_init)) == POINTER_TYPE)
9654 : 851020 : inside_init = convert_for_assignment (init_loc, UNKNOWN_LOCATION,
9655 : : type, inside_init, origtype,
9656 : : (require_constant
9657 : : ? ic_init_const
9658 : : : ic_init), null_pointer_constant,
9659 : : NULL_TREE, NULL_TREE, 0);
9660 : 12852856 : if (TREE_CODE (inside_init) == RAW_DATA_CST
9661 : 250 : && c_inhibit_evaluation_warnings == 0
9662 : 250 : && warn_conversion
9663 : 1 : && !TYPE_UNSIGNED (type)
9664 : 12852857 : && TYPE_PRECISION (type) == CHAR_BIT)
9665 : 303 : for (unsigned int i = 0;
9666 : 304 : i < (unsigned) RAW_DATA_LENGTH (inside_init); ++i)
9667 : 303 : if (RAW_DATA_SCHAR_ELT (inside_init, i) < 0)
9668 : 10 : warning_at (init_loc, OPT_Wconversion,
9669 : : "conversion from %qT to %qT changes value from "
9670 : : "%qd to %qd",
9671 : : integer_type_node, type,
9672 : 10 : RAW_DATA_UCHAR_ELT (inside_init, i),
9673 : 10 : RAW_DATA_SCHAR_ELT (inside_init, i));
9674 : 12852856 : return inside_init;
9675 : : }
9676 : :
9677 : : /* Handle scalar types, including conversions. */
9678 : :
9679 : 3069964 : if (code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE
9680 : 127495 : || code == POINTER_TYPE || code == ENUMERAL_TYPE || code == BOOLEAN_TYPE
9681 : 10986 : || code == COMPLEX_TYPE || code == VECTOR_TYPE || code == NULLPTR_TYPE
9682 : 8954 : || code == BITINT_TYPE)
9683 : : {
9684 : 3069482 : tree unconverted_init = inside_init;
9685 : 3069482 : if (TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE
9686 : 3069482 : && (TREE_CODE (init) == STRING_CST
9687 : 1 : || TREE_CODE (init) == COMPOUND_LITERAL_EXPR))
9688 : 7287 : inside_init = init = array_to_pointer_conversion (init_loc, init);
9689 : 3069482 : if (semantic_type)
9690 : 432 : inside_init = build1 (EXCESS_PRECISION_EXPR, semantic_type,
9691 : : inside_init);
9692 : 3069482 : inside_init
9693 : 5562176 : = convert_for_assignment (init_loc, UNKNOWN_LOCATION, type,
9694 : : inside_init, origtype,
9695 : : require_constant ? ic_init_const : ic_init,
9696 : : null_pointer_constant, NULL_TREE, NULL_TREE,
9697 : : 0);
9698 : :
9699 : : /* Check to see if we have already given an error message. */
9700 : 3069482 : if (inside_init == error_mark_node)
9701 : : ;
9702 : 3069024 : else if (require_constant && !TREE_CONSTANT (inside_init))
9703 : : {
9704 : 36 : error_init (init_loc, "initializer element is not constant");
9705 : 36 : inside_init = error_mark_node;
9706 : : }
9707 : 3068988 : else if (require_constant
9708 : 3645348 : && !initializer_constant_valid_p (inside_init,
9709 : 576360 : TREE_TYPE (inside_init)))
9710 : : {
9711 : 10 : error_init (init_loc, "initializer element is not computable at "
9712 : : "load time");
9713 : 10 : inside_init = error_mark_node;
9714 : : }
9715 : 3068978 : else if (require_constant && !maybe_const)
9716 : 5 : pedwarn_init (init_loc, OPT_Wpedantic,
9717 : : "initializer element is not a constant expression");
9718 : 3068973 : else if (require_constexpr)
9719 : 324 : check_constexpr_init (init_loc, type, unconverted_init,
9720 : : int_const_expr, arith_const_expr);
9721 : :
9722 : 3069482 : return inside_init;
9723 : : }
9724 : :
9725 : : /* Come here only for records and arrays. */
9726 : :
9727 : 482 : if (COMPLETE_TYPE_P (type) && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
9728 : : {
9729 : 0 : error_init (init_loc,
9730 : : "variable-sized object may not be initialized except "
9731 : : "with an empty initializer");
9732 : 0 : return error_mark_node;
9733 : : }
9734 : :
9735 : 482 : error_init (init_loc, "invalid initializer");
9736 : 482 : return error_mark_node;
9737 : : }
9738 : :
9739 : : /* Handle initializers that use braces. */
9740 : :
9741 : : /* Type of object we are accumulating a constructor for.
9742 : : This type is always a RECORD_TYPE, UNION_TYPE or ARRAY_TYPE. */
9743 : : static tree constructor_type;
9744 : :
9745 : : /* For a RECORD_TYPE or UNION_TYPE, this is the chain of fields
9746 : : left to fill. */
9747 : : static tree constructor_fields;
9748 : :
9749 : : /* For an ARRAY_TYPE, this is the specified index
9750 : : at which to store the next element we get. */
9751 : : static tree constructor_index;
9752 : :
9753 : : /* For an ARRAY_TYPE, this is the maximum index. */
9754 : : static tree constructor_max_index;
9755 : :
9756 : : /* For a RECORD_TYPE, this is the first field not yet written out. */
9757 : : static tree constructor_unfilled_fields;
9758 : :
9759 : : /* For an ARRAY_TYPE, this is the index of the first element
9760 : : not yet written out. */
9761 : : static tree constructor_unfilled_index;
9762 : :
9763 : : /* In a RECORD_TYPE, the byte index of the next consecutive field.
9764 : : This is so we can generate gaps between fields, when appropriate. */
9765 : : static tree constructor_bit_index;
9766 : :
9767 : : /* If we are saving up the elements rather than allocating them,
9768 : : this is the list of elements so far (in reverse order,
9769 : : most recent first). */
9770 : : static vec<constructor_elt, va_gc> *constructor_elements;
9771 : :
9772 : : /* 1 if constructor should be incrementally stored into a constructor chain,
9773 : : 0 if all the elements should be kept in AVL tree. */
9774 : : static int constructor_incremental;
9775 : :
9776 : : /* 1 if so far this constructor's elements are all compile-time constants. */
9777 : : static int constructor_constant;
9778 : :
9779 : : /* 1 if so far this constructor's elements are all valid address constants. */
9780 : : static int constructor_simple;
9781 : :
9782 : : /* 1 if this constructor has an element that cannot be part of a
9783 : : constant expression. */
9784 : : static int constructor_nonconst;
9785 : :
9786 : : /* 1 if this constructor is erroneous so far. */
9787 : : static int constructor_erroneous;
9788 : :
9789 : : /* 1 if this constructor is the universal zero initializer { 0 }. */
9790 : : static int constructor_zeroinit;
9791 : :
9792 : : /* 1 if this constructor should have padding bits zeroed (C23 {}. */
9793 : : static bool constructor_zero_padding_bits;
9794 : :
9795 : : /* Structure for managing pending initializer elements, organized as an
9796 : : AVL tree. */
9797 : :
9798 : : struct init_node
9799 : : {
9800 : : struct init_node *left, *right;
9801 : : struct init_node *parent;
9802 : : int balance;
9803 : : tree purpose;
9804 : : tree value;
9805 : : tree origtype;
9806 : : };
9807 : :
9808 : : /* Tree of pending elements at this constructor level.
9809 : : These are elements encountered out of order
9810 : : which belong at places we haven't reached yet in actually
9811 : : writing the output.
9812 : : Will never hold tree nodes across GC runs. */
9813 : : static struct init_node *constructor_pending_elts;
9814 : :
9815 : : /* The SPELLING_DEPTH of this constructor. */
9816 : : static int constructor_depth;
9817 : :
9818 : : /* DECL node for which an initializer is being read.
9819 : : 0 means we are reading a constructor expression
9820 : : such as (struct foo) {...}. */
9821 : : static tree constructor_decl;
9822 : :
9823 : : /* Nonzero if there were any member designators in this initializer. */
9824 : : static int constructor_designated;
9825 : :
9826 : : /* Nesting depth of designator list. */
9827 : : static int designator_depth;
9828 : :
9829 : : /* Nonzero if there were diagnosed errors in this designator list. */
9830 : : static int designator_erroneous;
9831 : :
9832 : :
9833 : : /* This stack has a level for each implicit or explicit level of
9834 : : structuring in the initializer, including the outermost one. It
9835 : : saves the values of most of the variables above. */
9836 : :
9837 : : struct constructor_range_stack;
9838 : :
9839 : : struct constructor_stack
9840 : : {
9841 : : struct constructor_stack *next;
9842 : : tree type;
9843 : : tree fields;
9844 : : tree index;
9845 : : tree max_index;
9846 : : tree unfilled_index;
9847 : : tree unfilled_fields;
9848 : : tree bit_index;
9849 : : vec<constructor_elt, va_gc> *elements;
9850 : : struct init_node *pending_elts;
9851 : : int offset;
9852 : : int depth;
9853 : : /* If value nonzero, this value should replace the entire
9854 : : constructor at this level. */
9855 : : struct c_expr replacement_value;
9856 : : struct constructor_range_stack *range_stack;
9857 : : char constant;
9858 : : char simple;
9859 : : char nonconst;
9860 : : char implicit;
9861 : : char erroneous;
9862 : : char outer;
9863 : : char incremental;
9864 : : char designated;
9865 : : bool zero_padding_bits;
9866 : : int designator_depth;
9867 : : };
9868 : :
9869 : : static struct constructor_stack *constructor_stack;
9870 : :
9871 : : /* This stack represents designators from some range designator up to
9872 : : the last designator in the list. */
9873 : :
9874 : : struct constructor_range_stack
9875 : : {
9876 : : struct constructor_range_stack *next, *prev;
9877 : : struct constructor_stack *stack;
9878 : : tree range_start;
9879 : : tree index;
9880 : : tree range_end;
9881 : : tree fields;
9882 : : };
9883 : :
9884 : : static struct constructor_range_stack *constructor_range_stack;
9885 : :
9886 : : /* This stack records separate initializers that are nested.
9887 : : Nested initializers can't happen in ANSI C, but GNU C allows them
9888 : : in cases like { ... (struct foo) { ... } ... }. */
9889 : :
9890 : : struct initializer_stack
9891 : : {
9892 : : struct initializer_stack *next;
9893 : : tree decl;
9894 : : struct constructor_stack *constructor_stack;
9895 : : struct constructor_range_stack *constructor_range_stack;
9896 : : vec<constructor_elt, va_gc> *elements;
9897 : : struct spelling *spelling;
9898 : : struct spelling *spelling_base;
9899 : : int spelling_size;
9900 : : char require_constant_value;
9901 : : char require_constant_elements;
9902 : : char require_constexpr_value;
9903 : : char designated;
9904 : : rich_location *missing_brace_richloc;
9905 : : };
9906 : :
9907 : : static struct initializer_stack *initializer_stack;
9908 : :
9909 : : /* Prepare to parse and output the initializer for variable DECL. */
9910 : :
9911 : : void
9912 : 7092366 : start_init (tree decl, tree asmspec_tree ATTRIBUTE_UNUSED,
9913 : : bool init_require_constant, bool init_require_constexpr,
9914 : : rich_location *richloc)
9915 : : {
9916 : 7092366 : const char *locus;
9917 : 7092366 : struct initializer_stack *p = XNEW (struct initializer_stack);
9918 : :
9919 : 7092366 : p->decl = constructor_decl;
9920 : 7092366 : p->require_constant_value = require_constant_value;
9921 : 7092366 : p->require_constant_elements = require_constant_elements;
9922 : 7092366 : p->require_constexpr_value = require_constexpr_value;
9923 : 7092366 : p->constructor_stack = constructor_stack;
9924 : 7092366 : p->constructor_range_stack = constructor_range_stack;
9925 : 7092366 : p->elements = constructor_elements;
9926 : 7092366 : p->spelling = spelling;
9927 : 7092366 : p->spelling_base = spelling_base;
9928 : 7092366 : p->spelling_size = spelling_size;
9929 : 7092366 : p->next = initializer_stack;
9930 : 7092366 : p->missing_brace_richloc = richloc;
9931 : 7092366 : p->designated = constructor_designated;
9932 : 7092366 : initializer_stack = p;
9933 : :
9934 : 7092366 : constructor_decl = decl;
9935 : 7092366 : constructor_designated = 0;
9936 : :
9937 : 7092366 : require_constant_value = init_require_constant;
9938 : 7092366 : require_constexpr_value = init_require_constexpr;
9939 : 7092366 : if (decl != NULL_TREE && decl != error_mark_node)
9940 : : {
9941 : 6192569 : require_constant_elements
9942 : 6016093 : = ((init_require_constant || (pedantic && !flag_isoc99))
9943 : : /* For a scalar, you can always use any value to initialize,
9944 : : even within braces. */
9945 : 6204521 : && AGGREGATE_TYPE_P (TREE_TYPE (decl)));
9946 : 6192569 : locus = identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl)));
9947 : : }
9948 : : else
9949 : : {
9950 : 899797 : require_constant_elements = false;
9951 : 899797 : locus = _("(anonymous)");
9952 : : }
9953 : :
9954 : 7092366 : constructor_stack = 0;
9955 : 7092366 : constructor_range_stack = 0;
9956 : :
9957 : 7092366 : found_missing_braces = 0;
9958 : :
9959 : 7092366 : spelling_base = 0;
9960 : 7092366 : spelling_size = 0;
9961 : 7092366 : RESTORE_SPELLING_DEPTH (0);
9962 : :
9963 : 7092366 : if (locus)
9964 : 7092366 : push_string (locus);
9965 : 7092366 : }
9966 : :
9967 : : void
9968 : 7092364 : finish_init (void)
9969 : : {
9970 : 7092364 : struct initializer_stack *p = initializer_stack;
9971 : :
9972 : : /* Free the whole constructor stack of this initializer. */
9973 : 7092364 : while (constructor_stack)
9974 : : {
9975 : 0 : struct constructor_stack *q = constructor_stack;
9976 : 0 : constructor_stack = q->next;
9977 : 0 : XDELETE (q);
9978 : : }
9979 : :
9980 : 7092364 : gcc_assert (!constructor_range_stack);
9981 : :
9982 : : /* Pop back to the data of the outer initializer (if any). */
9983 : 7092364 : XDELETE (spelling_base);
9984 : :
9985 : 7092364 : constructor_decl = p->decl;
9986 : 7092364 : require_constant_value = p->require_constant_value;
9987 : 7092364 : require_constant_elements = p->require_constant_elements;
9988 : 7092364 : require_constexpr_value = p->require_constexpr_value;
9989 : 7092364 : constructor_stack = p->constructor_stack;
9990 : 7092364 : constructor_designated = p->designated;
9991 : 7092364 : constructor_range_stack = p->constructor_range_stack;
9992 : 7092364 : constructor_elements = p->elements;
9993 : 7092364 : spelling = p->spelling;
9994 : 7092364 : spelling_base = p->spelling_base;
9995 : 7092364 : spelling_size = p->spelling_size;
9996 : 7092364 : initializer_stack = p->next;
9997 : 7092364 : XDELETE (p);
9998 : 7092364 : }
9999 : :
10000 : : /* Call here when we see the initializer is surrounded by braces.
10001 : : This is instead of a call to push_init_level;
10002 : : it is matched by a call to pop_init_level.
10003 : :
10004 : : TYPE is the type to initialize, for a constructor expression.
10005 : : For an initializer for a decl, TYPE is zero. */
10006 : :
10007 : : void
10008 : 1001963 : really_start_incremental_init (tree type)
10009 : : {
10010 : 1001963 : struct constructor_stack *p = XNEW (struct constructor_stack);
10011 : :
10012 : 1001963 : if (type == NULL_TREE)
10013 : 104078 : type = TREE_TYPE (constructor_decl);
10014 : :
10015 : 1001963 : if (VECTOR_TYPE_P (type)
10016 : 1001963 : && TYPE_VECTOR_OPAQUE (type))
10017 : 0 : error ("opaque vector types cannot be initialized");
10018 : :
10019 : 1001963 : p->type = constructor_type;
10020 : 1001963 : p->fields = constructor_fields;
10021 : 1001963 : p->index = constructor_index;
10022 : 1001963 : p->max_index = constructor_max_index;
10023 : 1001963 : p->unfilled_index = constructor_unfilled_index;
10024 : 1001963 : p->unfilled_fields = constructor_unfilled_fields;
10025 : 1001963 : p->bit_index = constructor_bit_index;
10026 : 1001963 : p->elements = constructor_elements;
10027 : 1001963 : p->constant = constructor_constant;
10028 : 1001963 : p->simple = constructor_simple;
10029 : 1001963 : p->nonconst = constructor_nonconst;
10030 : 1001963 : p->erroneous = constructor_erroneous;
10031 : 1001963 : p->pending_elts = constructor_pending_elts;
10032 : 1001963 : p->depth = constructor_depth;
10033 : 1001963 : p->replacement_value.value = 0;
10034 : 1001963 : p->replacement_value.original_code = ERROR_MARK;
10035 : 1001963 : p->replacement_value.original_type = NULL;
10036 : 1001963 : p->implicit = 0;
10037 : 1001963 : p->range_stack = 0;
10038 : 1001963 : p->outer = 0;
10039 : 1001963 : p->incremental = constructor_incremental;
10040 : 1001963 : p->designated = constructor_designated;
10041 : 1001963 : p->zero_padding_bits = constructor_zero_padding_bits;
10042 : 1001963 : p->designator_depth = designator_depth;
10043 : 1001963 : p->next = 0;
10044 : 1001963 : constructor_stack = p;
10045 : :
10046 : 1001963 : constructor_constant = 1;
10047 : 1001963 : constructor_simple = 1;
10048 : 1001963 : constructor_nonconst = 0;
10049 : 1001963 : constructor_depth = SPELLING_DEPTH ();
10050 : 1001963 : constructor_elements = NULL;
10051 : 1001963 : constructor_pending_elts = 0;
10052 : 1001963 : constructor_type = type;
10053 : 1001963 : constructor_incremental = 1;
10054 : 1001963 : constructor_designated = 0;
10055 : 1001963 : constructor_zero_padding_bits = false;
10056 : 1001963 : constructor_zeroinit = 1;
10057 : 1001963 : designator_depth = 0;
10058 : 1001963 : designator_erroneous = 0;
10059 : :
10060 : 1001963 : if (RECORD_OR_UNION_TYPE_P (constructor_type))
10061 : : {
10062 : 80246 : constructor_fields = TYPE_FIELDS (constructor_type);
10063 : : /* Skip any nameless bit fields at the beginning. */
10064 : 80246 : while (constructor_fields != NULL_TREE
10065 : 80274 : && DECL_UNNAMED_BIT_FIELD (constructor_fields))
10066 : 28 : constructor_fields = DECL_CHAIN (constructor_fields);
10067 : :
10068 : 80246 : constructor_unfilled_fields = constructor_fields;
10069 : 80246 : constructor_bit_index = bitsize_zero_node;
10070 : : }
10071 : 921717 : else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
10072 : : {
10073 : 17607 : if (TYPE_DOMAIN (constructor_type))
10074 : : {
10075 : 9265 : constructor_max_index
10076 : 9265 : = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
10077 : :
10078 : : /* Detect non-empty initializations of zero-length arrays. */
10079 : 9265 : if (constructor_max_index == NULL_TREE
10080 : 9265 : && TYPE_SIZE (constructor_type))
10081 : 205 : constructor_max_index = integer_minus_one_node;
10082 : :
10083 : : /* constructor_max_index needs to be an INTEGER_CST. Attempts
10084 : : to initialize VLAs with a nonempty initializer will cause a
10085 : : proper error; avoid tree checking errors as well by setting a
10086 : : safe value. */
10087 : 9265 : if (constructor_max_index
10088 : 9265 : && TREE_CODE (constructor_max_index) != INTEGER_CST)
10089 : 59 : constructor_max_index = integer_minus_one_node;
10090 : :
10091 : 9265 : constructor_index
10092 : 9265 : = convert (bitsizetype,
10093 : 9265 : TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
10094 : : }
10095 : : else
10096 : : {
10097 : 8342 : constructor_index = bitsize_zero_node;
10098 : 8342 : constructor_max_index = NULL_TREE;
10099 : : }
10100 : :
10101 : 17607 : constructor_unfilled_index = constructor_index;
10102 : : }
10103 : 904110 : else if (gnu_vector_type_p (constructor_type))
10104 : : {
10105 : : /* Vectors are like simple fixed-size arrays. */
10106 : 1807148 : constructor_max_index =
10107 : 903574 : bitsize_int (TYPE_VECTOR_SUBPARTS (constructor_type) - 1);
10108 : 903574 : constructor_index = bitsize_zero_node;
10109 : 903574 : constructor_unfilled_index = constructor_index;
10110 : : }
10111 : : else
10112 : : {
10113 : : /* Handle the case of int x = {5}; */
10114 : 536 : constructor_fields = constructor_type;
10115 : 536 : constructor_unfilled_fields = constructor_type;
10116 : : }
10117 : 1001963 : }
10118 : :
10119 : : extern location_t last_init_list_comma;
10120 : :
10121 : : /* Called when we see an open brace for a nested initializer. Finish
10122 : : off any pending levels with implicit braces. */
10123 : : void
10124 : 340282 : finish_implicit_inits (location_t loc, struct obstack *braced_init_obstack)
10125 : : {
10126 : 340284 : while (constructor_stack->implicit)
10127 : : {
10128 : 304 : if (RECORD_OR_UNION_TYPE_P (constructor_type)
10129 : 140 : && constructor_fields == NULL_TREE)
10130 : 0 : process_init_element (input_location,
10131 : : pop_init_level (loc, 1, braced_init_obstack,
10132 : : last_init_list_comma),
10133 : : true, braced_init_obstack);
10134 : 304 : else if (TREE_CODE (constructor_type) == ARRAY_TYPE
10135 : 164 : && constructor_max_index
10136 : 468 : && tree_int_cst_lt (constructor_max_index,
10137 : : constructor_index))
10138 : 2 : process_init_element (input_location,
10139 : : pop_init_level (loc, 1, braced_init_obstack,
10140 : : last_init_list_comma),
10141 : : true, braced_init_obstack);
10142 : : else
10143 : : break;
10144 : : }
10145 : 340282 : }
10146 : :
10147 : : /* Push down into a subobject, for initialization.
10148 : : If this is for an explicit set of braces, IMPLICIT is 0.
10149 : : If it is because the next element belongs at a lower level,
10150 : : IMPLICIT is 1 (or 2 if the push is because of designator list). */
10151 : :
10152 : : void
10153 : 1042892 : push_init_level (location_t loc, int implicit,
10154 : : struct obstack *braced_init_obstack)
10155 : : {
10156 : 1042892 : struct constructor_stack *p;
10157 : 1042892 : tree value = NULL_TREE;
10158 : :
10159 : : /* Unless this is an explicit brace, we need to preserve previous
10160 : : content if any. */
10161 : 1042892 : if (implicit)
10162 : : {
10163 : 703552 : if (RECORD_OR_UNION_TYPE_P (constructor_type) && constructor_fields)
10164 : 778 : value = find_init_member (constructor_fields, braced_init_obstack);
10165 : 702774 : else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
10166 : 702774 : value = find_init_member (constructor_index, braced_init_obstack);
10167 : : }
10168 : :
10169 : 1042892 : p = XNEW (struct constructor_stack);
10170 : 1042892 : p->type = constructor_type;
10171 : 1042892 : p->fields = constructor_fields;
10172 : 1042892 : p->index = constructor_index;
10173 : 1042892 : p->max_index = constructor_max_index;
10174 : 1042892 : p->unfilled_index = constructor_unfilled_index;
10175 : 1042892 : p->unfilled_fields = constructor_unfilled_fields;
10176 : 1042892 : p->bit_index = constructor_bit_index;
10177 : 1042892 : p->elements = constructor_elements;
10178 : 1042892 : p->constant = constructor_constant;
10179 : 1042892 : p->simple = constructor_simple;
10180 : 1042892 : p->nonconst = constructor_nonconst;
10181 : 1042892 : p->erroneous = constructor_erroneous;
10182 : 1042892 : p->pending_elts = constructor_pending_elts;
10183 : 1042892 : p->depth = constructor_depth;
10184 : 1042892 : p->replacement_value.value = NULL_TREE;
10185 : 1042892 : p->replacement_value.original_code = ERROR_MARK;
10186 : 1042892 : p->replacement_value.original_type = NULL;
10187 : 1042892 : p->implicit = implicit;
10188 : 1042892 : p->outer = 0;
10189 : 1042892 : p->incremental = constructor_incremental;
10190 : 1042892 : p->designated = constructor_designated;
10191 : 1042892 : p->zero_padding_bits = constructor_zero_padding_bits;
10192 : 1042892 : p->designator_depth = designator_depth;
10193 : 1042892 : p->next = constructor_stack;
10194 : 1042892 : p->range_stack = 0;
10195 : 1042892 : constructor_stack = p;
10196 : :
10197 : 1042892 : constructor_constant = 1;
10198 : 1042892 : constructor_simple = 1;
10199 : 1042892 : constructor_nonconst = 0;
10200 : 1042892 : constructor_depth = SPELLING_DEPTH ();
10201 : 1042892 : constructor_elements = NULL;
10202 : 1042892 : constructor_incremental = 1;
10203 : : /* If the upper initializer is designated, then mark this as
10204 : : designated too to prevent bogus warnings. */
10205 : 1042892 : constructor_designated = p->designated;
10206 : : /* If the upper initializer has padding bits zeroed, that includes
10207 : : all nested initializers as well. */
10208 : 1042892 : constructor_zero_padding_bits = p->zero_padding_bits;
10209 : 1042892 : constructor_pending_elts = 0;
10210 : 1042892 : if (!implicit)
10211 : : {
10212 : 339340 : p->range_stack = constructor_range_stack;
10213 : 339340 : constructor_range_stack = 0;
10214 : 339340 : designator_depth = 0;
10215 : 339340 : designator_erroneous = 0;
10216 : : }
10217 : :
10218 : : /* Don't die if an entire brace-pair level is superfluous
10219 : : in the containing level. */
10220 : 1042892 : if (constructor_type == NULL_TREE)
10221 : : ;
10222 : 1042892 : else if (RECORD_OR_UNION_TYPE_P (constructor_type))
10223 : : {
10224 : : /* Don't die if there are extra init elts at the end. */
10225 : 158738 : if (constructor_fields == NULL_TREE)
10226 : 51 : constructor_type = NULL_TREE;
10227 : : else
10228 : : {
10229 : 158687 : constructor_type = TREE_TYPE (constructor_fields);
10230 : 158687 : push_member_name (constructor_fields);
10231 : 158687 : constructor_depth++;
10232 : : }
10233 : : }
10234 : 884154 : else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
10235 : : {
10236 : 884116 : constructor_type = TREE_TYPE (constructor_type);
10237 : 884116 : push_array_bounds (tree_to_uhwi (constructor_index));
10238 : 884116 : constructor_depth++;
10239 : : }
10240 : :
10241 : 1042892 : if (constructor_type == NULL_TREE)
10242 : : {
10243 : 51 : error_init (loc, "extra brace group at end of initializer");
10244 : 51 : constructor_fields = NULL_TREE;
10245 : 51 : constructor_unfilled_fields = NULL_TREE;
10246 : 51 : return;
10247 : : }
10248 : :
10249 : 1042841 : if (value && TREE_CODE (value) == CONSTRUCTOR)
10250 : : {
10251 : 360 : constructor_constant = TREE_CONSTANT (value);
10252 : 360 : constructor_simple = TREE_STATIC (value);
10253 : 360 : constructor_nonconst = CONSTRUCTOR_NON_CONST (value);
10254 : 360 : constructor_elements = CONSTRUCTOR_ELTS (value);
10255 : 360 : constructor_zero_padding_bits |= CONSTRUCTOR_ZERO_PADDING_BITS (value);
10256 : 360 : if (!vec_safe_is_empty (constructor_elements)
10257 : 340 : && (TREE_CODE (constructor_type) == RECORD_TYPE
10258 : 340 : || TREE_CODE (constructor_type) == ARRAY_TYPE))
10259 : 294 : set_nonincremental_init (braced_init_obstack);
10260 : : }
10261 : :
10262 : 1042841 : if (implicit == 1)
10263 : : {
10264 : 702610 : found_missing_braces = 1;
10265 : 702610 : if (initializer_stack->missing_brace_richloc)
10266 : 702610 : initializer_stack->missing_brace_richloc->add_fixit_insert_before
10267 : 702610 : (loc, "{");
10268 : : }
10269 : :
10270 : 1042841 : if (RECORD_OR_UNION_TYPE_P (constructor_type))
10271 : : {
10272 : 879612 : constructor_fields = TYPE_FIELDS (constructor_type);
10273 : : /* Skip any nameless bit fields at the beginning. */
10274 : 879612 : while (constructor_fields != NULL_TREE
10275 : 879676 : && DECL_UNNAMED_BIT_FIELD (constructor_fields))
10276 : 64 : constructor_fields = DECL_CHAIN (constructor_fields);
10277 : :
10278 : 879612 : constructor_unfilled_fields = constructor_fields;
10279 : 879612 : constructor_bit_index = bitsize_zero_node;
10280 : : }
10281 : 163229 : else if (gnu_vector_type_p (constructor_type))
10282 : : {
10283 : : /* Vectors are like simple fixed-size arrays. */
10284 : 9600 : constructor_max_index =
10285 : 4800 : bitsize_int (TYPE_VECTOR_SUBPARTS (constructor_type) - 1);
10286 : 4800 : constructor_index = bitsize_int (0);
10287 : 4800 : constructor_unfilled_index = constructor_index;
10288 : : }
10289 : 158429 : else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
10290 : : {
10291 : 158371 : if (TYPE_DOMAIN (constructor_type))
10292 : : {
10293 : 158371 : constructor_max_index
10294 : 158371 : = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
10295 : :
10296 : : /* Detect non-empty initializations of zero-length arrays. */
10297 : 158371 : if (constructor_max_index == NULL_TREE
10298 : 158371 : && TYPE_SIZE (constructor_type))
10299 : 135 : constructor_max_index = integer_minus_one_node;
10300 : :
10301 : : /* constructor_max_index needs to be an INTEGER_CST. Attempts
10302 : : to initialize VLAs will cause a proper error; avoid tree
10303 : : checking errors as well by setting a safe value. */
10304 : 158371 : if (constructor_max_index
10305 : 158102 : && TREE_CODE (constructor_max_index) != INTEGER_CST)
10306 : 0 : constructor_max_index = integer_minus_one_node;
10307 : :
10308 : 158371 : constructor_index
10309 : 158371 : = convert (bitsizetype,
10310 : 158371 : TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
10311 : : }
10312 : : else
10313 : 0 : constructor_index = bitsize_zero_node;
10314 : :
10315 : 158371 : constructor_unfilled_index = constructor_index;
10316 : 158371 : if (value && TREE_CODE (value) == STRING_CST)
10317 : : {
10318 : : /* We need to split the char/wchar array into individual
10319 : : characters, so that we don't have to special case it
10320 : : everywhere. */
10321 : 7 : set_nonincremental_init_from_string (value, braced_init_obstack);
10322 : : }
10323 : : }
10324 : : else
10325 : : {
10326 : 58 : if (constructor_type != error_mark_node)
10327 : 29 : warning_init (input_location, 0, "braces around scalar initializer");
10328 : 58 : constructor_fields = constructor_type;
10329 : 58 : constructor_unfilled_fields = constructor_type;
10330 : : }
10331 : : }
10332 : :
10333 : : /* At the end of an implicit or explicit brace level,
10334 : : finish up that level of constructor. If a single expression
10335 : : with redundant braces initialized that level, return the
10336 : : c_expr structure for that expression. Otherwise, the original_code
10337 : : element is set to ERROR_MARK.
10338 : : If we were outputting the elements as they are read, return 0 as the value
10339 : : from inner levels (process_init_element ignores that),
10340 : : but return error_mark_node as the value from the outermost level
10341 : : (that's what we want to put in DECL_INITIAL).
10342 : : Otherwise, return a CONSTRUCTOR expression as the value. */
10343 : :
10344 : : struct c_expr
10345 : 2044855 : pop_init_level (location_t loc, int implicit,
10346 : : struct obstack *braced_init_obstack,
10347 : : location_t insert_before)
10348 : : {
10349 : 2044855 : struct constructor_stack *p;
10350 : 2044855 : struct c_expr ret;
10351 : 2044855 : ret.value = NULL_TREE;
10352 : 2044855 : ret.original_code = ERROR_MARK;
10353 : 2044855 : ret.original_type = NULL;
10354 : 2044855 : ret.m_decimal = 0;
10355 : :
10356 : 2044855 : if (implicit == 0)
10357 : : {
10358 : : /* When we come to an explicit close brace,
10359 : : pop any inner levels that didn't have explicit braces. */
10360 : 1342187 : while (constructor_stack->implicit)
10361 : 884 : process_init_element (input_location,
10362 : : pop_init_level (loc, 1, braced_init_obstack,
10363 : : insert_before),
10364 : : true, braced_init_obstack);
10365 : 1341303 : gcc_assert (!constructor_range_stack);
10366 : : }
10367 : : else
10368 : 703552 : if (initializer_stack->missing_brace_richloc)
10369 : 703552 : initializer_stack->missing_brace_richloc->add_fixit_insert_before
10370 : 703552 : (insert_before, "}");
10371 : :
10372 : : /* Now output all pending elements. */
10373 : 2044855 : constructor_incremental = 1;
10374 : 2044855 : output_pending_init_elements (1, braced_init_obstack);
10375 : :
10376 : 2044855 : p = constructor_stack;
10377 : :
10378 : : /* Error for initializing a flexible array member, or a zero-length
10379 : : array member in an inappropriate context. */
10380 : 2044804 : if (constructor_type && constructor_fields
10381 : 159199 : && TREE_CODE (constructor_type) == ARRAY_TYPE
10382 : 152511 : && TYPE_DOMAIN (constructor_type)
10383 : 2197358 : && !TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type)))
10384 : : {
10385 : : /* Silently discard empty initializations. The parser will
10386 : : already have pedwarned for empty brackets for C17 and earlier. */
10387 : 299 : if (integer_zerop (constructor_unfilled_index))
10388 : 84 : constructor_type = NULL_TREE;
10389 : 299 : if (constructor_type || flag_isoc23)
10390 : : {
10391 : 295 : gcc_assert (!constructor_type || !TYPE_SIZE (constructor_type));
10392 : :
10393 : 295 : if (constructor_depth <= 2)
10394 : 248 : pedwarn_init (loc, OPT_Wpedantic,
10395 : : "initialization of a flexible array member");
10396 : 47 : else if (constructor_type)
10397 : 33 : error_init (loc, "initialization of flexible array member "
10398 : : "in a nested context");
10399 : : else
10400 : 14 : pedwarn_init (loc, OPT_Wpedantic,
10401 : : "initialization of flexible array member "
10402 : : "in a nested context");
10403 : :
10404 : : /* We have already issued an error message for the existence
10405 : : of a flexible array member not at the end of the structure.
10406 : : Discard the initializer so that we do not die later. */
10407 : 295 : if (constructor_type
10408 : 215 : && DECL_CHAIN (constructor_fields) != NULL_TREE
10409 : 301 : && (!p->type || TREE_CODE (p->type) != UNION_TYPE))
10410 : 0 : constructor_type = NULL_TREE;
10411 : : }
10412 : : }
10413 : :
10414 : 2044855 : switch (vec_safe_length (constructor_elements))
10415 : : {
10416 : 4577 : case 0:
10417 : : /* Initialization with { } counts as zeroinit. */
10418 : 4577 : constructor_zeroinit = 1;
10419 : 4577 : break;
10420 : 913879 : case 1:
10421 : : /* This might be zeroinit as well. */
10422 : 913879 : if (integer_zerop ((*constructor_elements)[0].value))
10423 : 1861 : constructor_zeroinit = 1;
10424 : : break;
10425 : 1126399 : default:
10426 : : /* If the constructor has more than one element, it can't be { 0 }. */
10427 : 1126399 : constructor_zeroinit = 0;
10428 : 1126399 : break;
10429 : : }
10430 : :
10431 : : /* Warn when some structs are initialized with direct aggregation. */
10432 : 2044855 : if (!implicit && found_missing_braces && warn_missing_braces
10433 : 37 : && !constructor_zeroinit)
10434 : : {
10435 : 18 : gcc_assert (initializer_stack->missing_brace_richloc);
10436 : 18 : warning_at (initializer_stack->missing_brace_richloc,
10437 : 18 : OPT_Wmissing_braces,
10438 : : "missing braces around initializer");
10439 : : }
10440 : :
10441 : : /* Warn when some struct elements are implicitly initialized to zero. */
10442 : 2044855 : if (warn_missing_field_initializers
10443 : 425443 : && constructor_type
10444 : 425415 : && TREE_CODE (constructor_type) == RECORD_TYPE
10445 : 193395 : && constructor_unfilled_fields)
10446 : : {
10447 : : /* Do not warn for flexible array members or zero-length arrays. */
10448 : 43 : while (constructor_unfilled_fields
10449 : 43 : && (!DECL_SIZE (constructor_unfilled_fields)
10450 : 43 : || integer_zerop (DECL_SIZE (constructor_unfilled_fields))))
10451 : 0 : constructor_unfilled_fields = DECL_CHAIN (constructor_unfilled_fields);
10452 : :
10453 : 43 : if (constructor_unfilled_fields
10454 : : /* Do not warn if this level of the initializer uses member
10455 : : designators; it is likely to be deliberate. */
10456 : 43 : && !constructor_designated
10457 : : /* Do not warn about initializing with { 0 } or with { }. */
10458 : 24 : && !constructor_zeroinit)
10459 : : {
10460 : 10 : if (warning_at (input_location, OPT_Wmissing_field_initializers,
10461 : : "missing initializer for field %qD of %qT",
10462 : : constructor_unfilled_fields,
10463 : : constructor_type))
10464 : 10 : inform (DECL_SOURCE_LOCATION (constructor_unfilled_fields),
10465 : : "%qD declared here", constructor_unfilled_fields);
10466 : : }
10467 : : }
10468 : :
10469 : : /* Pad out the end of the structure. */
10470 : 2044855 : if (p->replacement_value.value)
10471 : : /* If this closes a superfluous brace pair,
10472 : : just pass out the element between them. */
10473 : 102 : ret = p->replacement_value;
10474 : 2044753 : else if (constructor_type == NULL_TREE)
10475 : : ;
10476 : 2044626 : else if (!RECORD_OR_UNION_TYPE_P (constructor_type)
10477 : 2044626 : && TREE_CODE (constructor_type) != ARRAY_TYPE
10478 : 2044626 : && !gnu_vector_type_p (constructor_type))
10479 : : {
10480 : : /* A nonincremental scalar initializer--just return
10481 : : the element, after verifying there is just one.
10482 : : Empty scalar initializers are supported in C23. */
10483 : 594 : if (vec_safe_is_empty (constructor_elements))
10484 : : {
10485 : 207 : if (constructor_erroneous || constructor_type == error_mark_node)
10486 : 94 : ret.value = error_mark_node;
10487 : 113 : else if (TREE_CODE (constructor_type) == FUNCTION_TYPE)
10488 : : {
10489 : 2 : error_init (loc, "invalid initializer");
10490 : 2 : ret.value = error_mark_node;
10491 : : }
10492 : 111 : else if (TREE_CODE (constructor_type) == POINTER_TYPE)
10493 : : /* Ensure this is a null pointer constant in the case of a
10494 : : 'constexpr' object initialized with {}. */
10495 : 33 : ret.value = build_zero_cst (ptr_type_node);
10496 : : else
10497 : 78 : ret.value = build_zero_cst (constructor_type);
10498 : : }
10499 : 387 : else if (vec_safe_length (constructor_elements) != 1)
10500 : : {
10501 : 0 : error_init (loc, "extra elements in scalar initializer");
10502 : 0 : ret.value = (*constructor_elements)[0].value;
10503 : : }
10504 : : else
10505 : 387 : ret.value = (*constructor_elements)[0].value;
10506 : : }
10507 : : else
10508 : : {
10509 : 2044032 : if (constructor_erroneous)
10510 : 477 : ret.value = error_mark_node;
10511 : : else
10512 : : {
10513 : 2043555 : ret.value = build_constructor (constructor_type,
10514 : : constructor_elements);
10515 : 2043555 : if (constructor_constant)
10516 : 1722211 : TREE_CONSTANT (ret.value) = 1;
10517 : 2043555 : if (constructor_constant && constructor_simple)
10518 : 1722172 : TREE_STATIC (ret.value) = 1;
10519 : 2043555 : if (constructor_nonconst)
10520 : 613 : CONSTRUCTOR_NON_CONST (ret.value) = 1;
10521 : 2043555 : if (constructor_zero_padding_bits)
10522 : 20 : CONSTRUCTOR_ZERO_PADDING_BITS (ret.value) = 1;
10523 : : }
10524 : : }
10525 : :
10526 : 2044855 : if (ret.value && TREE_CODE (ret.value) != CONSTRUCTOR)
10527 : : {
10528 : 1173 : if (constructor_nonconst)
10529 : 15 : ret.original_code = C_MAYBE_CONST_EXPR;
10530 : 1158 : else if (ret.original_code == C_MAYBE_CONST_EXPR)
10531 : 0 : ret.original_code = ERROR_MARK;
10532 : : }
10533 : :
10534 : 2044855 : constructor_type = p->type;
10535 : 2044855 : constructor_fields = p->fields;
10536 : 2044855 : constructor_index = p->index;
10537 : 2044855 : constructor_max_index = p->max_index;
10538 : 2044855 : constructor_unfilled_index = p->unfilled_index;
10539 : 2044855 : constructor_unfilled_fields = p->unfilled_fields;
10540 : 2044855 : constructor_bit_index = p->bit_index;
10541 : 2044855 : constructor_elements = p->elements;
10542 : 2044855 : constructor_constant = p->constant;
10543 : 2044855 : constructor_simple = p->simple;
10544 : 2044855 : constructor_nonconst = p->nonconst;
10545 : 2044855 : constructor_erroneous = p->erroneous;
10546 : 2044855 : constructor_incremental = p->incremental;
10547 : 2044855 : constructor_designated = p->designated;
10548 : 2044855 : constructor_zero_padding_bits = p->zero_padding_bits;
10549 : 2044855 : designator_depth = p->designator_depth;
10550 : 2044855 : constructor_pending_elts = p->pending_elts;
10551 : 2044855 : constructor_depth = p->depth;
10552 : 2044855 : if (!p->implicit)
10553 : 1341303 : constructor_range_stack = p->range_stack;
10554 : 2044855 : RESTORE_SPELLING_DEPTH (constructor_depth);
10555 : :
10556 : 2044855 : constructor_stack = p->next;
10557 : 2044855 : XDELETE (p);
10558 : :
10559 : 2044855 : if (ret.value == NULL_TREE && constructor_stack == 0)
10560 : 0 : ret.value = error_mark_node;
10561 : 2044855 : return ret;
10562 : : }
10563 : :
10564 : : /* Common handling for both array range and field name designators.
10565 : : ARRAY argument is nonzero for array ranges. Returns false for success. */
10566 : :
10567 : : static bool
10568 : 33078 : set_designator (location_t loc, bool array,
10569 : : struct obstack *braced_init_obstack)
10570 : : {
10571 : 33078 : tree subtype;
10572 : 33078 : enum tree_code subcode;
10573 : :
10574 : : /* Don't die if an entire brace-pair level is superfluous
10575 : : in the containing level, or for an erroneous type. */
10576 : 33078 : if (constructor_type == NULL_TREE || constructor_type == error_mark_node)
10577 : : return true;
10578 : :
10579 : : /* If there were errors in this designator list already, bail out
10580 : : silently. */
10581 : 33069 : if (designator_erroneous)
10582 : : return true;
10583 : :
10584 : : /* Likewise for an initializer for a variable-size type. Those are
10585 : : diagnosed in the parser, except for empty initializer braces. */
10586 : 33069 : if (COMPLETE_TYPE_P (constructor_type)
10587 : 33069 : && TREE_CODE (TYPE_SIZE (constructor_type)) != INTEGER_CST)
10588 : : return true;
10589 : :
10590 : 33059 : if (!designator_depth)
10591 : : {
10592 : 32441 : gcc_assert (!constructor_range_stack);
10593 : :
10594 : : /* Designator list starts at the level of closest explicit
10595 : : braces. */
10596 : 32824 : while (constructor_stack->implicit)
10597 : 383 : process_init_element (input_location,
10598 : : pop_init_level (loc, 1, braced_init_obstack,
10599 : : last_init_list_comma),
10600 : : true, braced_init_obstack);
10601 : 32441 : constructor_designated = 1;
10602 : 32441 : return false;
10603 : : }
10604 : :
10605 : 618 : switch (TREE_CODE (constructor_type))
10606 : : {
10607 : 421 : case RECORD_TYPE:
10608 : 421 : case UNION_TYPE:
10609 : 421 : subtype = TREE_TYPE (constructor_fields);
10610 : 421 : if (subtype != error_mark_node)
10611 : 421 : subtype = TYPE_MAIN_VARIANT (subtype);
10612 : : break;
10613 : 197 : case ARRAY_TYPE:
10614 : 197 : subtype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
10615 : 197 : break;
10616 : 0 : default:
10617 : 0 : gcc_unreachable ();
10618 : : }
10619 : :
10620 : 618 : subcode = TREE_CODE (subtype);
10621 : 618 : if (array && subcode != ARRAY_TYPE)
10622 : : {
10623 : 1 : error_init (loc, "array index in non-array initializer");
10624 : 1 : return true;
10625 : : }
10626 : 617 : else if (!array && subcode != RECORD_TYPE && subcode != UNION_TYPE)
10627 : : {
10628 : 0 : error_init (loc, "field name not in record or union initializer");
10629 : 0 : return true;
10630 : : }
10631 : :
10632 : 617 : constructor_designated = 1;
10633 : 617 : finish_implicit_inits (loc, braced_init_obstack);
10634 : 617 : push_init_level (loc, 2, braced_init_obstack);
10635 : 617 : return false;
10636 : : }
10637 : :
10638 : : /* If there are range designators in designator list, push a new designator
10639 : : to constructor_range_stack. RANGE_END is end of such stack range or
10640 : : NULL_TREE if there is no range designator at this level. */
10641 : :
10642 : : static void
10643 : 384 : push_range_stack (tree range_end, struct obstack * braced_init_obstack)
10644 : : {
10645 : 384 : struct constructor_range_stack *p;
10646 : :
10647 : 768 : p = (struct constructor_range_stack *)
10648 : 384 : obstack_alloc (braced_init_obstack,
10649 : : sizeof (struct constructor_range_stack));
10650 : 384 : p->prev = constructor_range_stack;
10651 : 384 : p->next = 0;
10652 : 384 : p->fields = constructor_fields;
10653 : 384 : p->range_start = constructor_index;
10654 : 384 : p->index = constructor_index;
10655 : 384 : p->stack = constructor_stack;
10656 : 384 : p->range_end = range_end;
10657 : 384 : if (constructor_range_stack)
10658 : 19 : constructor_range_stack->next = p;
10659 : 384 : constructor_range_stack = p;
10660 : 384 : }
10661 : :
10662 : : /* Within an array initializer, specify the next index to be initialized.
10663 : : FIRST is that index. If LAST is nonzero, then initialize a range
10664 : : of indices, running from FIRST through LAST. */
10665 : :
10666 : : void
10667 : 1143 : set_init_index (location_t loc, tree first, tree last,
10668 : : struct obstack *braced_init_obstack)
10669 : : {
10670 : 1143 : if (set_designator (loc, true, braced_init_obstack))
10671 : : return;
10672 : :
10673 : 1140 : designator_erroneous = 1;
10674 : :
10675 : 2280 : if (!INTEGRAL_TYPE_P (TREE_TYPE (first))
10676 : 2269 : || (last && !INTEGRAL_TYPE_P (TREE_TYPE (last))))
10677 : : {
10678 : 12 : error_init (loc, "array index in initializer not of integer type");
10679 : 12 : return;
10680 : : }
10681 : :
10682 : 1128 : if (TREE_CODE (first) != INTEGER_CST)
10683 : : {
10684 : 6 : first = c_fully_fold (first, false, NULL);
10685 : 6 : if (TREE_CODE (first) == INTEGER_CST)
10686 : 5 : pedwarn_init (loc, OPT_Wpedantic,
10687 : : "array index in initializer is not "
10688 : : "an integer constant expression");
10689 : : }
10690 : :
10691 : 1128 : if (last && TREE_CODE (last) != INTEGER_CST)
10692 : : {
10693 : 2 : last = c_fully_fold (last, false, NULL);
10694 : 2 : if (TREE_CODE (last) == INTEGER_CST)
10695 : 1 : pedwarn_init (loc, OPT_Wpedantic,
10696 : : "array index in initializer is not "
10697 : : "an integer constant expression");
10698 : : }
10699 : :
10700 : 1128 : if (TREE_CODE (first) != INTEGER_CST)
10701 : 1 : error_init (loc, "nonconstant array index in initializer");
10702 : 1127 : else if (last != NULL_TREE && TREE_CODE (last) != INTEGER_CST)
10703 : 1 : error_init (loc, "nonconstant array index in initializer");
10704 : 1126 : else if (TREE_CODE (constructor_type) != ARRAY_TYPE)
10705 : 9 : error_init (loc, "array index in non-array initializer");
10706 : 1117 : else if (tree_int_cst_sgn (first) == -1)
10707 : 15 : error_init (loc, "array index in initializer exceeds array bounds");
10708 : 1102 : else if (constructor_max_index
10709 : 1102 : && tree_int_cst_lt (constructor_max_index, first))
10710 : 7 : error_init (loc, "array index in initializer exceeds array bounds");
10711 : : else
10712 : : {
10713 : 1095 : constant_expression_warning (first);
10714 : 1095 : if (last)
10715 : 379 : constant_expression_warning (last);
10716 : 1095 : constructor_index = convert (bitsizetype, first);
10717 : 1095 : if (tree_int_cst_lt (constructor_index, first))
10718 : : {
10719 : 0 : constructor_index = copy_node (constructor_index);
10720 : 0 : TREE_OVERFLOW (constructor_index) = 1;
10721 : : }
10722 : :
10723 : 1095 : if (last)
10724 : : {
10725 : 379 : if (tree_int_cst_equal (first, last))
10726 : : last = NULL_TREE;
10727 : 378 : else if (tree_int_cst_lt (last, first))
10728 : : {
10729 : 2 : error_init (loc, "empty index range in initializer");
10730 : 2 : last = NULL_TREE;
10731 : : }
10732 : : else
10733 : : {
10734 : 376 : last = convert (bitsizetype, last);
10735 : 376 : if (constructor_max_index != NULL_TREE
10736 : 376 : && tree_int_cst_lt (constructor_max_index, last))
10737 : : {
10738 : 3 : error_init (loc, "array index range in initializer exceeds "
10739 : : "array bounds");
10740 : 3 : last = NULL_TREE;
10741 : : }
10742 : : }
10743 : : }
10744 : :
10745 : 1095 : designator_depth++;
10746 : 1095 : designator_erroneous = 0;
10747 : 1095 : if (constructor_range_stack || last)
10748 : 373 : push_range_stack (last, braced_init_obstack);
10749 : : }
10750 : : }
10751 : :
10752 : : /* Within a struct initializer, specify the next field to be initialized. */
10753 : :
10754 : : void
10755 : 31890 : set_init_label (location_t loc, tree fieldname, location_t fieldname_loc,
10756 : : struct obstack *braced_init_obstack)
10757 : : {
10758 : 31890 : tree field;
10759 : :
10760 : 31890 : if (set_designator (loc, false, braced_init_obstack))
10761 : : return;
10762 : :
10763 : 31873 : designator_erroneous = 1;
10764 : :
10765 : 31873 : if (!RECORD_OR_UNION_TYPE_P (constructor_type))
10766 : : {
10767 : 3 : error_init (loc, "field name not in record or union initializer");
10768 : 3 : return;
10769 : : }
10770 : :
10771 : 31870 : field = lookup_field (constructor_type, fieldname);
10772 : :
10773 : 31870 : if (field == NULL_TREE)
10774 : : {
10775 : 8 : tree guessed_id = lookup_field_fuzzy (constructor_type, fieldname);
10776 : 8 : if (guessed_id)
10777 : : {
10778 : 4 : gcc_rich_location rich_loc (fieldname_loc);
10779 : 4 : rich_loc.add_fixit_misspelled_id (fieldname_loc, guessed_id);
10780 : 4 : error_at (&rich_loc,
10781 : : "%qT has no member named %qE; did you mean %qE?",
10782 : : constructor_type, fieldname, guessed_id);
10783 : 4 : }
10784 : : else
10785 : 4 : error_at (fieldname_loc, "%qT has no member named %qE",
10786 : : constructor_type, fieldname);
10787 : : }
10788 : : else
10789 : 31907 : do
10790 : : {
10791 : 31907 : constructor_fields = TREE_VALUE (field);
10792 : 31907 : designator_depth++;
10793 : 31907 : designator_erroneous = 0;
10794 : 31907 : if (constructor_range_stack)
10795 : 11 : push_range_stack (NULL_TREE, braced_init_obstack);
10796 : 31907 : field = TREE_CHAIN (field);
10797 : 31907 : if (field)
10798 : : {
10799 : 45 : if (set_designator (loc, false, braced_init_obstack))
10800 : : return;
10801 : : }
10802 : : }
10803 : 31907 : while (field != NULL_TREE);
10804 : : }
10805 : :
10806 : : /* Helper function for add_pending_init. Find inorder successor of P
10807 : : in AVL tree. */
10808 : : static struct init_node *
10809 : 129 : init_node_successor (struct init_node *p)
10810 : : {
10811 : 129 : struct init_node *r;
10812 : 129 : if (p->right)
10813 : : {
10814 : : r = p->right;
10815 : 58 : while (r->left)
10816 : : r = r->left;
10817 : : return r;
10818 : : }
10819 : 75 : r = p->parent;
10820 : 114 : while (r && p == r->right)
10821 : : {
10822 : 39 : p = r;
10823 : 39 : r = r->parent;
10824 : : }
10825 : : return r;
10826 : : }
10827 : :
10828 : : /* Add a new initializer to the tree of pending initializers. PURPOSE
10829 : : identifies the initializer, either array index or field in a structure.
10830 : : VALUE is the value of that index or field. If ORIGTYPE is not
10831 : : NULL_TREE, it is the original type of VALUE.
10832 : :
10833 : : IMPLICIT is true if value comes from pop_init_level (1),
10834 : : the new initializer has been merged with the existing one
10835 : : and thus no warnings should be emitted about overriding an
10836 : : existing initializer. */
10837 : :
10838 : : static void
10839 : 3261 : add_pending_init (location_t loc, tree purpose, tree value, tree origtype,
10840 : : bool implicit, struct obstack *braced_init_obstack)
10841 : : {
10842 : 3261 : struct init_node *p, **q, *r;
10843 : :
10844 : 3261 : q = &constructor_pending_elts;
10845 : 3261 : p = 0;
10846 : :
10847 : 3261 : if (TREE_CODE (constructor_type) == ARRAY_TYPE)
10848 : : {
10849 : 3610 : while (*q != 0)
10850 : : {
10851 : 2412 : p = *q;
10852 : 2412 : if (tree_int_cst_lt (purpose, p->purpose))
10853 : 283 : q = &p->left;
10854 : 2129 : else if (tree_int_cst_lt (p->purpose, purpose))
10855 : : {
10856 : 1960 : if (TREE_CODE (p->value) != RAW_DATA_CST
10857 : 1960 : || (p->right
10858 : 112 : && tree_int_cst_le (p->right->purpose, purpose)))
10859 : 1830 : q = &p->right;
10860 : : else
10861 : : {
10862 : 130 : widest_int pp = wi::to_widest (p->purpose);
10863 : 130 : widest_int pw = wi::to_widest (purpose);
10864 : 130 : if (pp + RAW_DATA_LENGTH (p->value) <= pw)
10865 : 98 : q = &p->right;
10866 : : else
10867 : : {
10868 : : /* Override which should split the old RAW_DATA_CST
10869 : : into 2 or 3 pieces. */
10870 : 32 : if (!implicit && warn_override_init)
10871 : 9 : warning_init (loc, OPT_Woverride_init,
10872 : : "initialized field overwritten");
10873 : 32 : unsigned HOST_WIDE_INT start = (pw - pp).to_uhwi ();
10874 : 32 : unsigned HOST_WIDE_INT len = 1;
10875 : 32 : if (TREE_CODE (value) == RAW_DATA_CST)
10876 : 0 : len = RAW_DATA_LENGTH (value);
10877 : 32 : unsigned HOST_WIDE_INT end = 0;
10878 : 32 : unsigned plen = RAW_DATA_LENGTH (p->value);
10879 : 32 : gcc_checking_assert (start < plen && start);
10880 : 32 : if (plen - start > len)
10881 : 30 : end = plen - start - len;
10882 : 32 : tree v = p->value;
10883 : 32 : tree origtype = p->origtype;
10884 : 32 : if (start == 1)
10885 : 2 : p->value = build_int_cst (TREE_TYPE (v),
10886 : 2 : RAW_DATA_UCHAR_ELT (v, 0));
10887 : : else
10888 : : {
10889 : 30 : p->value = v;
10890 : 30 : if (end > 1)
10891 : 26 : v = copy_node (v);
10892 : 30 : RAW_DATA_LENGTH (p->value) = start;
10893 : : }
10894 : 32 : if (end)
10895 : : {
10896 : 30 : tree epurpose
10897 : 30 : = size_binop (PLUS_EXPR, purpose,
10898 : : bitsize_int (len));
10899 : 30 : if (end > 1)
10900 : : {
10901 : 28 : RAW_DATA_LENGTH (v) -= plen - end;
10902 : 28 : RAW_DATA_POINTER (v) += plen - end;
10903 : : }
10904 : : else
10905 : 2 : v = build_int_cst (TREE_TYPE (v),
10906 : 2 : RAW_DATA_UCHAR_ELT (v, plen
10907 : : - end));
10908 : 30 : add_pending_init (loc, epurpose, v, origtype,
10909 : : implicit, braced_init_obstack);
10910 : : }
10911 : 32 : q = &constructor_pending_elts;
10912 : 32 : continue;
10913 : 32 : }
10914 : 130 : }
10915 : : }
10916 : : else
10917 : : {
10918 : 169 : if (TREE_CODE (p->value) == RAW_DATA_CST
10919 : 179 : && (RAW_DATA_LENGTH (p->value)
10920 : 10 : > (TREE_CODE (value) == RAW_DATA_CST
10921 : 10 : ? RAW_DATA_LENGTH (value) : 1)))
10922 : : {
10923 : : /* Override which should split the old RAW_DATA_CST
10924 : : into 2 pieces. */
10925 : 6 : if (!implicit && warn_override_init)
10926 : 3 : warning_init (loc, OPT_Woverride_init,
10927 : : "initialized field overwritten");
10928 : 6 : unsigned HOST_WIDE_INT len = 1;
10929 : 6 : if (TREE_CODE (value) == RAW_DATA_CST)
10930 : 2 : len = RAW_DATA_LENGTH (value);
10931 : 6 : if ((unsigned) RAW_DATA_LENGTH (p->value) > len + 1)
10932 : : {
10933 : 6 : RAW_DATA_LENGTH (p->value) -= len;
10934 : 6 : RAW_DATA_POINTER (p->value) += len;
10935 : : }
10936 : : else
10937 : : {
10938 : 0 : unsigned int l = RAW_DATA_LENGTH (p->value) - 1;
10939 : 0 : p->value
10940 : 0 : = build_int_cst (TREE_TYPE (p->value),
10941 : 0 : RAW_DATA_UCHAR_ELT (p->value, l));
10942 : : }
10943 : 6 : p->purpose = size_binop (PLUS_EXPR, p->purpose,
10944 : : bitsize_int (len));
10945 : 6 : continue;
10946 : 6 : }
10947 : 163 : if (TREE_CODE (value) == RAW_DATA_CST)
10948 : : {
10949 : 8 : handle_raw_data:
10950 : : /* RAW_DATA_CST value might overlap various further
10951 : : prior initval entries. Find out how many. */
10952 : 13 : unsigned cnt = 0;
10953 : 13 : widest_int w
10954 : 26 : = wi::to_widest (purpose) + RAW_DATA_LENGTH (value);
10955 : 13 : struct init_node *r = p, *last = NULL;
10956 : 13 : bool override_init = warn_override_init;
10957 : 13 : while ((r = init_node_successor (r))
10958 : 53 : && wi::to_widest (r->purpose) < w)
10959 : : {
10960 : 40 : ++cnt;
10961 : 40 : if (TREE_SIDE_EFFECTS (r->value))
10962 : 2 : warning_init (loc, OPT_Woverride_init_side_effects,
10963 : : "initialized field with side-effects "
10964 : : "overwritten");
10965 : 38 : else if (override_init)
10966 : : {
10967 : 6 : warning_init (loc, OPT_Woverride_init,
10968 : : "initialized field overwritten");
10969 : 6 : override_init = false;
10970 : : }
10971 : : last = r;
10972 : : }
10973 : 13 : if (cnt)
10974 : : {
10975 : 26 : if (TREE_CODE (last->value) == RAW_DATA_CST
10976 : 13 : && (wi::to_widest (last->purpose)
10977 : 13 : + RAW_DATA_LENGTH (last->value) > w))
10978 : : {
10979 : : /* The last overlapping prior initval overlaps
10980 : : only partially. Shrink it and decrease cnt. */
10981 : 0 : unsigned int l = (wi::to_widest (last->purpose)
10982 : 0 : + RAW_DATA_LENGTH (last->value)
10983 : 0 : - w).to_uhwi ();
10984 : 0 : --cnt;
10985 : 0 : RAW_DATA_LENGTH (last->value) -= l;
10986 : 0 : RAW_DATA_POINTER (last->value) += l;
10987 : 0 : if (RAW_DATA_LENGTH (last->value) == 1)
10988 : 0 : last->value
10989 : 0 : = build_int_cst (TREE_TYPE (last->value),
10990 : 0 : RAW_DATA_UCHAR_ELT (last->value,
10991 : : 0));
10992 : 0 : last->purpose
10993 : 0 : = size_binop (PLUS_EXPR, last->purpose,
10994 : : bitsize_int (l));
10995 : : }
10996 : : /* Instead of deleting cnt nodes from the AVL tree
10997 : : and rebalancing, peel of last cnt bytes from the
10998 : : RAW_DATA_CST. Overriding thousands of previously
10999 : : initialized array elements with #embed needs to work,
11000 : : but doesn't need to be super efficient. */
11001 : 13 : gcc_checking_assert ((unsigned) RAW_DATA_LENGTH (value)
11002 : : > cnt);
11003 : 13 : RAW_DATA_LENGTH (value) -= cnt;
11004 : 13 : const unsigned char *s
11005 : 13 : = &RAW_DATA_UCHAR_ELT (value, RAW_DATA_LENGTH (value));
11006 : 13 : unsigned int o = RAW_DATA_LENGTH (value);
11007 : 53 : for (r = p; cnt--; ++o, ++s)
11008 : : {
11009 : 40 : r = init_node_successor (r);
11010 : 40 : r->purpose = size_binop (PLUS_EXPR, purpose,
11011 : : bitsize_int (o));
11012 : 40 : r->value = build_int_cst (TREE_TYPE (value), *s);
11013 : 40 : r->origtype = origtype;
11014 : : }
11015 : 13 : if (RAW_DATA_LENGTH (value) == 1)
11016 : 0 : value = build_int_cst (TREE_TYPE (value),
11017 : 0 : RAW_DATA_UCHAR_ELT (value, 0));
11018 : : }
11019 : : }
11020 : 168 : if (!implicit)
11021 : : {
11022 : 54 : if (TREE_SIDE_EFFECTS (p->value))
11023 : 6 : warning_init (loc, OPT_Woverride_init_side_effects,
11024 : : "initialized field with side-effects "
11025 : : "overwritten");
11026 : 48 : else if (warn_override_init)
11027 : 13 : warning_init (loc, OPT_Woverride_init,
11028 : : "initialized field overwritten");
11029 : : }
11030 : 168 : p->value = value;
11031 : 168 : p->origtype = origtype;
11032 : 168 : return;
11033 : : }
11034 : : }
11035 : 1198 : if (TREE_CODE (value) == RAW_DATA_CST && p)
11036 : : {
11037 : 61 : struct init_node *r;
11038 : 61 : if (q == &p->left)
11039 : : r = p;
11040 : : else
11041 : 36 : r = init_node_successor (p);
11042 : 131 : if (r && wi::to_widest (r->purpose) < (wi::to_widest (purpose)
11043 : 131 : + RAW_DATA_LENGTH (value)))
11044 : : {
11045 : : /* Overlap with at least one prior initval in the range but
11046 : : not at the start. */
11047 : 5 : p = r;
11048 : 5 : p->purpose = purpose;
11049 : 5 : goto handle_raw_data;
11050 : : }
11051 : : }
11052 : : }
11053 : : else
11054 : : {
11055 : 1900 : tree bitpos;
11056 : :
11057 : 1900 : bitpos = bit_position (purpose);
11058 : 5386 : while (*q != NULL)
11059 : : {
11060 : 1843 : p = *q;
11061 : 1843 : if (tree_int_cst_lt (bitpos, bit_position (p->purpose)))
11062 : 43 : q = &p->left;
11063 : 1800 : else if (p->purpose != purpose)
11064 : 1543 : q = &p->right;
11065 : : else
11066 : : {
11067 : 257 : if (!implicit)
11068 : : {
11069 : 33 : if (TREE_SIDE_EFFECTS (p->value))
11070 : 4 : warning_init (loc, OPT_Woverride_init_side_effects,
11071 : : "initialized field with side-effects "
11072 : : "overwritten");
11073 : 29 : else if (warn_override_init)
11074 : 6 : warning_init (loc, OPT_Woverride_init,
11075 : : "initialized field overwritten");
11076 : : }
11077 : 257 : p->value = value;
11078 : 257 : p->origtype = origtype;
11079 : 257 : return;
11080 : : }
11081 : : }
11082 : : }
11083 : :
11084 : 2836 : r = (struct init_node *) obstack_alloc (braced_init_obstack,
11085 : : sizeof (struct init_node));
11086 : 2836 : r->purpose = purpose;
11087 : 2836 : r->value = value;
11088 : 2836 : r->origtype = origtype;
11089 : :
11090 : 2836 : *q = r;
11091 : 2836 : r->parent = p;
11092 : 2836 : r->left = 0;
11093 : 2836 : r->right = 0;
11094 : 2836 : r->balance = 0;
11095 : :
11096 : 4854 : while (p)
11097 : : {
11098 : 2806 : struct init_node *s;
11099 : :
11100 : 2806 : if (r == p->left)
11101 : : {
11102 : 237 : if (p->balance == 0)
11103 : 174 : p->balance = -1;
11104 : 63 : else if (p->balance < 0)
11105 : : {
11106 : 45 : if (r->balance < 0)
11107 : : {
11108 : : /* L rotation. */
11109 : 40 : p->left = r->right;
11110 : 40 : if (p->left)
11111 : 2 : p->left->parent = p;
11112 : 40 : r->right = p;
11113 : :
11114 : 40 : p->balance = 0;
11115 : 40 : r->balance = 0;
11116 : :
11117 : 40 : s = p->parent;
11118 : 40 : p->parent = r;
11119 : 40 : r->parent = s;
11120 : 40 : if (s)
11121 : : {
11122 : 31 : if (s->left == p)
11123 : 10 : s->left = r;
11124 : : else
11125 : 21 : s->right = r;
11126 : : }
11127 : : else
11128 : 9 : constructor_pending_elts = r;
11129 : : }
11130 : : else
11131 : : {
11132 : : /* LR rotation. */
11133 : 5 : struct init_node *t = r->right;
11134 : :
11135 : 5 : r->right = t->left;
11136 : 5 : if (r->right)
11137 : 0 : r->right->parent = r;
11138 : 5 : t->left = r;
11139 : :
11140 : 5 : p->left = t->right;
11141 : 5 : if (p->left)
11142 : 0 : p->left->parent = p;
11143 : 5 : t->right = p;
11144 : :
11145 : 5 : p->balance = t->balance < 0;
11146 : 5 : r->balance = -(t->balance > 0);
11147 : 5 : t->balance = 0;
11148 : :
11149 : 5 : s = p->parent;
11150 : 5 : p->parent = t;
11151 : 5 : r->parent = t;
11152 : 5 : t->parent = s;
11153 : 5 : if (s)
11154 : : {
11155 : 0 : if (s->left == p)
11156 : 0 : s->left = t;
11157 : : else
11158 : 0 : s->right = t;
11159 : : }
11160 : : else
11161 : 5 : constructor_pending_elts = t;
11162 : : }
11163 : : break;
11164 : : }
11165 : : else
11166 : : {
11167 : : /* p->balance == +1; growth of left side balances the node. */
11168 : 18 : p->balance = 0;
11169 : 18 : break;
11170 : : }
11171 : : }
11172 : : else /* r == p->right */
11173 : : {
11174 : 2569 : if (p->balance == 0)
11175 : : /* Growth propagation from right side. */
11176 : 1844 : p->balance++;
11177 : 725 : else if (p->balance > 0)
11178 : : {
11179 : 696 : if (r->balance > 0)
11180 : : {
11181 : : /* R rotation. */
11182 : 694 : p->right = r->left;
11183 : 694 : if (p->right)
11184 : 173 : p->right->parent = p;
11185 : 694 : r->left = p;
11186 : :
11187 : 694 : p->balance = 0;
11188 : 694 : r->balance = 0;
11189 : :
11190 : 694 : s = p->parent;
11191 : 694 : p->parent = r;
11192 : 694 : r->parent = s;
11193 : 694 : if (s)
11194 : : {
11195 : 374 : if (s->left == p)
11196 : 2 : s->left = r;
11197 : : else
11198 : 372 : s->right = r;
11199 : : }
11200 : : else
11201 : 320 : constructor_pending_elts = r;
11202 : : }
11203 : : else /* r->balance == -1 */
11204 : : {
11205 : : /* RL rotation */
11206 : 2 : struct init_node *t = r->left;
11207 : :
11208 : 2 : r->left = t->right;
11209 : 2 : if (r->left)
11210 : 2 : r->left->parent = r;
11211 : 2 : t->right = r;
11212 : :
11213 : 2 : p->right = t->left;
11214 : 2 : if (p->right)
11215 : 2 : p->right->parent = p;
11216 : 2 : t->left = p;
11217 : :
11218 : 2 : r->balance = (t->balance < 0);
11219 : 2 : p->balance = -(t->balance > 0);
11220 : 2 : t->balance = 0;
11221 : :
11222 : 2 : s = p->parent;
11223 : 2 : p->parent = t;
11224 : 2 : r->parent = t;
11225 : 2 : t->parent = s;
11226 : 2 : if (s)
11227 : : {
11228 : 0 : if (s->left == p)
11229 : 0 : s->left = t;
11230 : : else
11231 : 0 : s->right = t;
11232 : : }
11233 : : else
11234 : 2 : constructor_pending_elts = t;
11235 : : }
11236 : : break;
11237 : : }
11238 : : else
11239 : : {
11240 : : /* p->balance == -1; growth of right side balances the node. */
11241 : 29 : p->balance = 0;
11242 : 29 : break;
11243 : : }
11244 : : }
11245 : :
11246 : 2018 : r = p;
11247 : 2018 : p = p->parent;
11248 : : }
11249 : : }
11250 : :
11251 : : /* Build AVL tree from a sorted chain. */
11252 : :
11253 : : static void
11254 : 418 : set_nonincremental_init (struct obstack * braced_init_obstack)
11255 : : {
11256 : 418 : unsigned HOST_WIDE_INT ix;
11257 : 418 : tree index, value;
11258 : :
11259 : 418 : if (TREE_CODE (constructor_type) != RECORD_TYPE
11260 : 418 : && TREE_CODE (constructor_type) != ARRAY_TYPE)
11261 : : return;
11262 : :
11263 : 1601 : FOR_EACH_CONSTRUCTOR_ELT (constructor_elements, ix, index, value)
11264 : 1183 : add_pending_init (input_location, index, value, NULL_TREE, true,
11265 : : braced_init_obstack);
11266 : 418 : constructor_elements = NULL;
11267 : 418 : if (TREE_CODE (constructor_type) == RECORD_TYPE)
11268 : : {
11269 : 200 : constructor_unfilled_fields = TYPE_FIELDS (constructor_type);
11270 : : /* Skip any nameless bit fields at the beginning. */
11271 : 200 : while (constructor_unfilled_fields != NULL_TREE
11272 : 200 : && DECL_UNNAMED_BIT_FIELD (constructor_unfilled_fields))
11273 : 0 : constructor_unfilled_fields = TREE_CHAIN (constructor_unfilled_fields);
11274 : :
11275 : : }
11276 : 218 : else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
11277 : : {
11278 : 218 : if (TYPE_DOMAIN (constructor_type))
11279 : 160 : constructor_unfilled_index
11280 : 160 : = convert (bitsizetype,
11281 : 160 : TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
11282 : : else
11283 : 58 : constructor_unfilled_index = bitsize_zero_node;
11284 : : }
11285 : 418 : constructor_incremental = 0;
11286 : : }
11287 : :
11288 : : /* Build AVL tree from a string constant. */
11289 : :
11290 : : static void
11291 : 7 : set_nonincremental_init_from_string (tree str,
11292 : : struct obstack * braced_init_obstack)
11293 : : {
11294 : 7 : tree value, purpose, type;
11295 : 7 : HOST_WIDE_INT val[2];
11296 : 7 : const char *p, *end;
11297 : 7 : int byte, wchar_bytes, charwidth, bitpos;
11298 : :
11299 : 7 : gcc_assert (TREE_CODE (constructor_type) == ARRAY_TYPE);
11300 : :
11301 : 7 : wchar_bytes = TYPE_PRECISION (TREE_TYPE (TREE_TYPE (str))) / BITS_PER_UNIT;
11302 : 7 : charwidth = TYPE_PRECISION (char_type_node);
11303 : 7 : gcc_assert ((size_t) wchar_bytes * charwidth
11304 : : <= ARRAY_SIZE (val) * HOST_BITS_PER_WIDE_INT);
11305 : 7 : type = TREE_TYPE (constructor_type);
11306 : 7 : p = TREE_STRING_POINTER (str);
11307 : 7 : end = p + TREE_STRING_LENGTH (str);
11308 : :
11309 : 7 : for (purpose = bitsize_zero_node;
11310 : : p < end
11311 : 52 : && !(constructor_max_index
11312 : 20 : && tree_int_cst_lt (constructor_max_index, purpose));
11313 : 25 : purpose = size_binop (PLUS_EXPR, purpose, bitsize_one_node))
11314 : : {
11315 : 25 : if (wchar_bytes == 1)
11316 : : {
11317 : 9 : val[0] = (unsigned char) *p++;
11318 : 9 : val[1] = 0;
11319 : : }
11320 : : else
11321 : : {
11322 : 16 : val[1] = 0;
11323 : 16 : val[0] = 0;
11324 : 64 : for (byte = 0; byte < wchar_bytes; byte++)
11325 : : {
11326 : 48 : if (BYTES_BIG_ENDIAN)
11327 : : bitpos = (wchar_bytes - byte - 1) * charwidth;
11328 : : else
11329 : 48 : bitpos = byte * charwidth;
11330 : 48 : val[bitpos / HOST_BITS_PER_WIDE_INT]
11331 : 48 : |= ((unsigned HOST_WIDE_INT) ((unsigned char) *p++))
11332 : 48 : << (bitpos % HOST_BITS_PER_WIDE_INT);
11333 : : }
11334 : : }
11335 : :
11336 : 25 : if (!TYPE_UNSIGNED (type))
11337 : : {
11338 : 13 : bitpos = ((wchar_bytes - 1) * charwidth) + HOST_BITS_PER_CHAR;
11339 : 13 : if (bitpos < HOST_BITS_PER_WIDE_INT)
11340 : : {
11341 : 13 : if (val[0] & (HOST_WIDE_INT_1 << (bitpos - 1)))
11342 : : {
11343 : 0 : val[0] |= HOST_WIDE_INT_M1U << bitpos;
11344 : 0 : val[1] = -1;
11345 : : }
11346 : : }
11347 : 0 : else if (bitpos == HOST_BITS_PER_WIDE_INT)
11348 : : {
11349 : 0 : if (val[0] < 0)
11350 : 0 : val[1] = -1;
11351 : : }
11352 : 0 : else if (val[1] & (HOST_WIDE_INT_1
11353 : 0 : << (bitpos - 1 - HOST_BITS_PER_WIDE_INT)))
11354 : 0 : val[1] |= HOST_WIDE_INT_M1U << (bitpos - HOST_BITS_PER_WIDE_INT);
11355 : : }
11356 : :
11357 : 25 : value = wide_int_to_tree (type,
11358 : 25 : wide_int::from_array (val, 2,
11359 : : HOST_BITS_PER_WIDE_INT * 2));
11360 : 25 : add_pending_init (input_location, purpose, value, NULL_TREE, true,
11361 : : braced_init_obstack);
11362 : : }
11363 : :
11364 : 7 : constructor_incremental = 0;
11365 : 7 : }
11366 : :
11367 : : /* Return value of FIELD in pending initializer or NULL_TREE if the field was
11368 : : not initialized yet. */
11369 : :
11370 : : static tree
11371 : 703552 : find_init_member (tree field, struct obstack * braced_init_obstack)
11372 : : {
11373 : 703552 : struct init_node *p;
11374 : :
11375 : 703552 : if (TREE_CODE (constructor_type) == ARRAY_TYPE)
11376 : : {
11377 : 702774 : if (constructor_incremental
11378 : 702774 : && tree_int_cst_lt (field, constructor_unfilled_index))
11379 : 16 : set_nonincremental_init (braced_init_obstack);
11380 : :
11381 : 702774 : p = constructor_pending_elts;
11382 : 702897 : while (p)
11383 : : {
11384 : 233 : if (tree_int_cst_lt (field, p->purpose))
11385 : 25 : p = p->left;
11386 : 208 : else if (tree_int_cst_lt (p->purpose, field))
11387 : 98 : p = p->right;
11388 : : else
11389 : 110 : return p->value;
11390 : : }
11391 : : }
11392 : 778 : else if (TREE_CODE (constructor_type) == RECORD_TYPE)
11393 : : {
11394 : 659 : tree bitpos = bit_position (field);
11395 : :
11396 : 659 : if (constructor_incremental
11397 : 659 : && (!constructor_unfilled_fields
11398 : 456 : || tree_int_cst_lt (bitpos,
11399 : 456 : bit_position (constructor_unfilled_fields))))
11400 : 51 : set_nonincremental_init (braced_init_obstack);
11401 : :
11402 : 659 : p = constructor_pending_elts;
11403 : 799 : while (p)
11404 : : {
11405 : 347 : if (field == p->purpose)
11406 : 207 : return p->value;
11407 : 140 : else if (tree_int_cst_lt (bitpos, bit_position (p->purpose)))
11408 : 7 : p = p->left;
11409 : : else
11410 : 133 : p = p->right;
11411 : : }
11412 : : }
11413 : 119 : else if (TREE_CODE (constructor_type) == UNION_TYPE)
11414 : : {
11415 : 119 : if (!vec_safe_is_empty (constructor_elements)
11416 : 50 : && (constructor_elements->last ().index == field))
11417 : 50 : return constructor_elements->last ().value;
11418 : : }
11419 : : return NULL_TREE;
11420 : : }
11421 : :
11422 : : /* "Output" the next constructor element.
11423 : : At top level, really output it to assembler code now.
11424 : : Otherwise, collect it in a list from which we will make a CONSTRUCTOR.
11425 : : If ORIGTYPE is not NULL_TREE, it is the original type of VALUE.
11426 : : TYPE is the data type that the containing data type wants here.
11427 : : FIELD is the field (a FIELD_DECL) or the index that this element fills.
11428 : : If VALUE is a string constant, STRICT_STRING is true if it is
11429 : : unparenthesized or we should not warn here for it being parenthesized.
11430 : : For other types of VALUE, STRICT_STRING is not used.
11431 : :
11432 : : PENDING if true means output pending elements that belong
11433 : : right after this element. (PENDING is normally true;
11434 : : it is false while outputting pending elements, to avoid recursion.)
11435 : :
11436 : : IMPLICIT is true if value comes from pop_init_level (1),
11437 : : the new initializer has been merged with the existing one
11438 : : and thus no warnings should be emitted about overriding an
11439 : : existing initializer. */
11440 : :
11441 : : static void
11442 : 9459383 : output_init_element (location_t loc, tree value, tree origtype,
11443 : : bool strict_string, tree type, tree field, bool pending,
11444 : : bool implicit, struct obstack * braced_init_obstack)
11445 : : {
11446 : 9459383 : tree semantic_type = NULL_TREE;
11447 : 9459383 : bool maybe_const = true;
11448 : 9459383 : bool npc, int_const_expr, arith_const_expr;
11449 : :
11450 : 9459383 : if (type == error_mark_node || value == error_mark_node)
11451 : : {
11452 : 449 : constructor_erroneous = 1;
11453 : 2566 : return;
11454 : : }
11455 : 9458934 : if (TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE
11456 : 199853 : && (TREE_CODE (value) == STRING_CST
11457 : 158465 : || TREE_CODE (value) == COMPOUND_LITERAL_EXPR)
11458 : 41396 : && !(TREE_CODE (value) == STRING_CST
11459 : 41388 : && TREE_CODE (type) == ARRAY_TYPE
11460 : 3896 : && INTEGRAL_TYPE_P (TREE_TYPE (type)))
11461 : 9496434 : && !comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (value)),
11462 : 37500 : TYPE_MAIN_VARIANT (type)))
11463 : 37500 : value = array_to_pointer_conversion (input_location, value);
11464 : :
11465 : 9458934 : if (TREE_CODE (value) == COMPOUND_LITERAL_EXPR
11466 : 178 : && require_constant_value && pending)
11467 : : {
11468 : : /* As an extension, allow initializing objects with static storage
11469 : : duration with compound literals (which are then treated just as
11470 : : the brace enclosed list they contain). */
11471 : 114 : if (flag_isoc99)
11472 : 24 : pedwarn_init (loc, OPT_Wpedantic, "initializer element is not "
11473 : : "constant");
11474 : 114 : tree decl = COMPOUND_LITERAL_EXPR_DECL (value);
11475 : 114 : value = DECL_INITIAL (decl);
11476 : : }
11477 : :
11478 : 9458934 : npc = null_pointer_constant_p (value);
11479 : 18917868 : int_const_expr = (TREE_CODE (value) == INTEGER_CST
11480 : 4141928 : && !TREE_OVERFLOW (value)
11481 : 13600861 : && INTEGRAL_TYPE_P (TREE_TYPE (value)));
11482 : : /* Not fully determined before folding. */
11483 : 9458934 : arith_const_expr = true;
11484 : 9458934 : if (TREE_CODE (value) == EXCESS_PRECISION_EXPR)
11485 : : {
11486 : 16 : semantic_type = TREE_TYPE (value);
11487 : 16 : value = TREE_OPERAND (value, 0);
11488 : : }
11489 : 9458934 : value = c_fully_fold (value, require_constant_value, &maybe_const);
11490 : : /* TODO: this may not detect all cases of expressions folding to
11491 : : constants that are not arithmetic constant expressions. */
11492 : 9458934 : if (!maybe_const)
11493 : : arith_const_expr = false;
11494 : 18915527 : else if (!INTEGRAL_TYPE_P (TREE_TYPE (value))
11495 : 3152778 : && TREE_CODE (TREE_TYPE (value)) != REAL_TYPE
11496 : 11298461 : && TREE_CODE (TREE_TYPE (value)) != COMPLEX_TYPE)
11497 : : arith_const_expr = false;
11498 : 7632024 : else if (TREE_CODE (value) != INTEGER_CST
11499 : : && TREE_CODE (value) != REAL_CST
11500 : : && TREE_CODE (value) != COMPLEX_CST
11501 : : && TREE_CODE (value) != RAW_DATA_CST)
11502 : : arith_const_expr = false;
11503 : 4522996 : else if (TREE_OVERFLOW (value))
11504 : 4935939 : arith_const_expr = false;
11505 : :
11506 : 9458934 : if (value == error_mark_node)
11507 : 0 : constructor_erroneous = 1;
11508 : 9458934 : else if (!TREE_CONSTANT (value))
11509 : 3128570 : constructor_constant = 0;
11510 : 6330364 : else if (!initializer_constant_valid_p (value,
11511 : 6330364 : TREE_TYPE (value),
11512 : 6330364 : AGGREGATE_TYPE_P (constructor_type)
11513 : 6330364 : && TYPE_REVERSE_STORAGE_ORDER
11514 : : (constructor_type))
11515 : 6330364 : || (RECORD_OR_UNION_TYPE_P (constructor_type)
11516 : 1037192 : && DECL_C_BIT_FIELD (field)
11517 : 8035 : && TREE_CODE (value) != INTEGER_CST))
11518 : 77 : constructor_simple = 0;
11519 : 9458934 : if (!maybe_const)
11520 : 1067 : constructor_nonconst = 1;
11521 : :
11522 : : /* Digest the initializer and issue any errors about incompatible
11523 : : types before issuing errors about non-constant initializers. */
11524 : 9458934 : tree new_value = value;
11525 : 9458934 : if (semantic_type)
11526 : 16 : new_value = build1 (EXCESS_PRECISION_EXPR, semantic_type, value);
11527 : : /* In the case of braces around a scalar initializer, the result of
11528 : : this initializer processing goes through digest_init again at the
11529 : : outer level. In the case of a constexpr initializer for a
11530 : : pointer, avoid converting a null pointer constant to something
11531 : : that is not a null pointer constant to avoid a spurious error
11532 : : from that second processing. */
11533 : 9458934 : if (!require_constexpr_value
11534 : 397 : || !npc
11535 : 69 : || TREE_CODE (constructor_type) != POINTER_TYPE)
11536 : 9458923 : new_value = digest_init (loc,
11537 : 9458923 : RECORD_OR_UNION_TYPE_P (constructor_type)
11538 : 8390787 : ? field : constructor_fields
11539 : 8390787 : ? constructor_fields : constructor_decl,
11540 : : type, new_value, origtype, npc,
11541 : : int_const_expr, arith_const_expr, strict_string,
11542 : : require_constant_value, require_constexpr_value);
11543 : 9458934 : if (new_value == error_mark_node)
11544 : : {
11545 : 76 : constructor_erroneous = 1;
11546 : 76 : return;
11547 : : }
11548 : 9458858 : if (require_constant_value || require_constant_elements)
11549 : 2709514 : constant_expression_warning (new_value);
11550 : :
11551 : : /* Proceed to check the constness of the original initializer. */
11552 : 9458858 : if (!initializer_constant_valid_p (value, TREE_TYPE (value)))
11553 : : {
11554 : 3128596 : if (require_constant_value)
11555 : : {
11556 : 0 : error_init (loc, "initializer element is not constant");
11557 : 0 : value = error_mark_node;
11558 : : }
11559 : 3128596 : else if (require_constant_elements)
11560 : 15 : pedwarn (loc, OPT_Wpedantic,
11561 : : "initializer element is not computable at load time");
11562 : : }
11563 : 6330262 : else if (!maybe_const
11564 : 54 : && (require_constant_value || require_constant_elements))
11565 : 28 : pedwarn_init (loc, OPT_Wpedantic,
11566 : : "initializer element is not a constant expression");
11567 : : /* digest_init has already carried out the additional checks
11568 : : required for 'constexpr' initializers (using the information
11569 : : passed to it about whether the original initializer was certain
11570 : : kinds of constant expression), so that check does not need to be
11571 : : repeated here. */
11572 : :
11573 : : /* Issue -Wc++-compat warnings about initializing a bitfield with
11574 : : enum type. */
11575 : 9458858 : if (warn_cxx_compat
11576 : 6895 : && field != NULL_TREE
11577 : 6895 : && TREE_CODE (field) == FIELD_DECL
11578 : 459 : && DECL_BIT_FIELD_TYPE (field) != NULL_TREE
11579 : 21 : && (TYPE_MAIN_VARIANT (DECL_BIT_FIELD_TYPE (field))
11580 : 21 : != TYPE_MAIN_VARIANT (type))
11581 : 9458879 : && TREE_CODE (DECL_BIT_FIELD_TYPE (field)) == ENUMERAL_TYPE)
11582 : : {
11583 : 21 : tree checktype = origtype != NULL_TREE ? origtype : TREE_TYPE (value);
11584 : 21 : if (checktype != error_mark_node
11585 : 21 : && (TYPE_MAIN_VARIANT (checktype)
11586 : 21 : != TYPE_MAIN_VARIANT (DECL_BIT_FIELD_TYPE (field))))
11587 : 9 : warning_init (loc, OPT_Wc___compat,
11588 : : "enum conversion in initialization is invalid in C++");
11589 : : }
11590 : :
11591 : : /* If this field is empty and does not have side effects (and is not at
11592 : : the end of structure), don't do anything other than checking the
11593 : : initializer. */
11594 : 9458858 : if (field
11595 : 9458858 : && (TREE_TYPE (field) == error_mark_node
11596 : 9458471 : || (COMPLETE_TYPE_P (TREE_TYPE (field))
11597 : 9458163 : && integer_zerop (TYPE_SIZE (TREE_TYPE (field)))
11598 : 62 : && !TREE_SIDE_EFFECTS (new_value)
11599 : 33 : && (TREE_CODE (constructor_type) == ARRAY_TYPE
11600 : 33 : || DECL_CHAIN (field)))))
11601 : 18 : return;
11602 : :
11603 : : /* Finally, set VALUE to the initializer value digested above. */
11604 : 9458840 : value = new_value;
11605 : :
11606 : : /* If this element doesn't come next in sequence,
11607 : : put it on constructor_pending_elts. */
11608 : 9458840 : if (TREE_CODE (constructor_type) == ARRAY_TYPE
11609 : 9458840 : && (!constructor_incremental
11610 : 1712788 : || !tree_int_cst_equal (field, constructor_unfilled_index)
11611 : 1712422 : || (TREE_CODE (value) == RAW_DATA_CST
11612 : 231 : && constructor_pending_elts
11613 : 66 : && pending)))
11614 : : {
11615 : 627 : if (constructor_incremental
11616 : 627 : && (tree_int_cst_lt (field, constructor_unfilled_index)
11617 : 337 : || (TREE_CODE (value) == RAW_DATA_CST
11618 : 14 : && constructor_pending_elts
11619 : 14 : && pending)))
11620 : 48 : set_nonincremental_init (braced_init_obstack);
11621 : :
11622 : 627 : add_pending_init (loc, field, value, origtype, implicit,
11623 : : braced_init_obstack);
11624 : 627 : return;
11625 : : }
11626 : 9458213 : else if (TREE_CODE (constructor_type) == RECORD_TYPE
11627 : 1037909 : && (!constructor_incremental
11628 : 1037569 : || field != constructor_unfilled_fields))
11629 : : {
11630 : : /* We do this for records but not for unions. In a union,
11631 : : no matter which field is specified, it can be initialized
11632 : : right away since it starts at the beginning of the union. */
11633 : 1396 : if (constructor_incremental)
11634 : : {
11635 : 1056 : if (!constructor_unfilled_fields)
11636 : 5 : set_nonincremental_init (braced_init_obstack);
11637 : : else
11638 : : {
11639 : 1051 : tree bitpos, unfillpos;
11640 : :
11641 : 1051 : bitpos = bit_position (field);
11642 : 1051 : unfillpos = bit_position (constructor_unfilled_fields);
11643 : :
11644 : 1051 : if (tree_int_cst_lt (bitpos, unfillpos))
11645 : 4 : set_nonincremental_init (braced_init_obstack);
11646 : : }
11647 : : }
11648 : :
11649 : 1396 : add_pending_init (loc, field, value, origtype, implicit,
11650 : : braced_init_obstack);
11651 : 1396 : return;
11652 : : }
11653 : 9456817 : else if (TREE_CODE (constructor_type) == UNION_TYPE
11654 : 9456817 : && !vec_safe_is_empty (constructor_elements))
11655 : : {
11656 : 62 : if (!implicit)
11657 : : {
11658 : 12 : if (TREE_SIDE_EFFECTS (constructor_elements->last ().value))
11659 : 3 : warning_init (loc, OPT_Woverride_init_side_effects,
11660 : : "initialized field with side-effects overwritten");
11661 : 9 : else if (warn_override_init)
11662 : 6 : warning_init (loc, OPT_Woverride_init,
11663 : : "initialized field overwritten");
11664 : : }
11665 : :
11666 : : /* We can have just one union field set. */
11667 : 62 : constructor_elements = NULL;
11668 : : }
11669 : :
11670 : : /* Otherwise, output this element either to
11671 : : constructor_elements or to the assembler file. */
11672 : :
11673 : 9456817 : constructor_elt celt = {field, value};
11674 : 9456817 : vec_safe_push (constructor_elements, celt);
11675 : :
11676 : : /* Advance the variable that indicates sequential elements output. */
11677 : 9456817 : if (TREE_CODE (constructor_type) == ARRAY_TYPE)
11678 : : {
11679 : 1712417 : tree inc = bitsize_one_node;
11680 : 1712417 : if (value && TREE_CODE (value) == RAW_DATA_CST)
11681 : 226 : inc = bitsize_int (RAW_DATA_LENGTH (value));
11682 : 1712417 : constructor_unfilled_index
11683 : 1712417 : = size_binop_loc (input_location, PLUS_EXPR,
11684 : : constructor_unfilled_index, inc);
11685 : : }
11686 : 7744400 : else if (TREE_CODE (constructor_type) == RECORD_TYPE)
11687 : : {
11688 : 1036513 : constructor_unfilled_fields
11689 : 1036513 : = DECL_CHAIN (constructor_unfilled_fields);
11690 : :
11691 : : /* Skip any nameless bit fields. */
11692 : 1036513 : while (constructor_unfilled_fields != NULL_TREE
11693 : 1036614 : && DECL_UNNAMED_BIT_FIELD (constructor_unfilled_fields))
11694 : 101 : constructor_unfilled_fields
11695 : 101 : = DECL_CHAIN (constructor_unfilled_fields);
11696 : : }
11697 : 6707887 : else if (TREE_CODE (constructor_type) == UNION_TYPE)
11698 : 30195 : constructor_unfilled_fields = NULL_TREE;
11699 : :
11700 : : /* Now output any pending elements which have become next. */
11701 : 9456817 : if (pending)
11702 : 9453960 : output_pending_init_elements (0, braced_init_obstack);
11703 : : }
11704 : :
11705 : : /* For two FIELD_DECLs in the same chain, return -1 if field1
11706 : : comes before field2, 1 if field1 comes after field2 and
11707 : : 0 if field1 == field2. */
11708 : :
11709 : : static int
11710 : 4001 : init_field_decl_cmp (tree field1, tree field2)
11711 : : {
11712 : 4001 : if (field1 == field2)
11713 : : return 0;
11714 : :
11715 : 2138 : tree bitpos1 = bit_position (field1);
11716 : 2138 : tree bitpos2 = bit_position (field2);
11717 : 2138 : if (tree_int_cst_equal (bitpos1, bitpos2))
11718 : : {
11719 : : /* If one of the fields has non-zero bitsize, then that
11720 : : field must be the last one in a sequence of zero
11721 : : sized fields, fields after it will have bigger
11722 : : bit_position. */
11723 : 22 : if (TREE_TYPE (field1) != error_mark_node
11724 : 22 : && COMPLETE_TYPE_P (TREE_TYPE (field1))
11725 : 44 : && integer_nonzerop (TREE_TYPE (field1)))
11726 : : return 1;
11727 : 22 : if (TREE_TYPE (field2) != error_mark_node
11728 : 22 : && COMPLETE_TYPE_P (TREE_TYPE (field2))
11729 : 37 : && integer_nonzerop (TREE_TYPE (field2)))
11730 : : return -1;
11731 : : /* Otherwise, fallback to DECL_CHAIN walk to find out
11732 : : which field comes earlier. Walk chains of both
11733 : : fields, so that if field1 and field2 are close to each
11734 : : other in either order, it is found soon even for large
11735 : : sequences of zero sized fields. */
11736 : : tree f1 = field1, f2 = field2;
11737 : 22 : while (1)
11738 : : {
11739 : 22 : f1 = DECL_CHAIN (f1);
11740 : 22 : f2 = DECL_CHAIN (f2);
11741 : 22 : if (f1 == NULL_TREE)
11742 : : {
11743 : 7 : gcc_assert (f2);
11744 : : return 1;
11745 : : }
11746 : 15 : if (f2 == NULL_TREE)
11747 : : return -1;
11748 : 1 : if (f1 == field2)
11749 : : return -1;
11750 : 0 : if (f2 == field1)
11751 : : return 1;
11752 : 0 : if (!tree_int_cst_equal (bit_position (f1), bitpos1))
11753 : : return 1;
11754 : 0 : if (!tree_int_cst_equal (bit_position (f2), bitpos1))
11755 : : return -1;
11756 : : }
11757 : : }
11758 : 2116 : else if (tree_int_cst_lt (bitpos1, bitpos2))
11759 : : return -1;
11760 : : else
11761 : : return 1;
11762 : : }
11763 : :
11764 : : /* Output any pending elements which have become next.
11765 : : As we output elements, constructor_unfilled_{fields,index}
11766 : : advances, which may cause other elements to become next;
11767 : : if so, they too are output.
11768 : :
11769 : : If ALL is 0, we return when there are
11770 : : no more pending elements to output now.
11771 : :
11772 : : If ALL is 1, we output space as necessary so that
11773 : : we can output all the pending elements. */
11774 : : static void
11775 : 11498815 : output_pending_init_elements (int all, struct obstack * braced_init_obstack)
11776 : : {
11777 : 11498815 : struct init_node *elt = constructor_pending_elts;
11778 : 11499811 : tree next;
11779 : :
11780 : 11499811 : retry:
11781 : :
11782 : : /* Look through the whole pending tree.
11783 : : If we find an element that should be output now,
11784 : : output it. Otherwise, set NEXT to the element
11785 : : that comes first among those still pending. */
11786 : :
11787 : 11499811 : next = NULL_TREE;
11788 : 11505441 : while (elt)
11789 : : {
11790 : 7574 : if (TREE_CODE (constructor_type) == ARRAY_TYPE)
11791 : : {
11792 : 3004 : if (tree_int_cst_equal (elt->purpose,
11793 : : constructor_unfilled_index))
11794 : 1197 : output_init_element (input_location, elt->value, elt->origtype,
11795 : 1197 : true, TREE_TYPE (constructor_type),
11796 : : constructor_unfilled_index, false, false,
11797 : : braced_init_obstack);
11798 : 1807 : else if (tree_int_cst_lt (constructor_unfilled_index,
11799 : 1807 : elt->purpose))
11800 : : {
11801 : : /* Advance to the next smaller node. */
11802 : 589 : if (elt->left)
11803 : : elt = elt->left;
11804 : : else
11805 : : {
11806 : : /* We have reached the smallest node bigger than the
11807 : : current unfilled index. Fill the space first. */
11808 : 209 : next = elt->purpose;
11809 : 209 : break;
11810 : : }
11811 : : }
11812 : : else
11813 : : {
11814 : : /* Advance to the next bigger node. */
11815 : 1218 : if (elt->right)
11816 : : elt = elt->right;
11817 : : else
11818 : : {
11819 : : /* We have reached the biggest node in a subtree. Find
11820 : : the parent of it, which is the next bigger node. */
11821 : 1218 : while (elt->parent && elt->parent->right == elt)
11822 : : elt = elt->parent;
11823 : 774 : elt = elt->parent;
11824 : 1149 : if (elt && tree_int_cst_lt (constructor_unfilled_index,
11825 : 375 : elt->purpose))
11826 : : {
11827 : 22 : next = elt->purpose;
11828 : 22 : break;
11829 : : }
11830 : : }
11831 : : }
11832 : : }
11833 : 4570 : else if (RECORD_OR_UNION_TYPE_P (constructor_type))
11834 : : {
11835 : : /* If the current record is complete we are done. */
11836 : 4570 : if (constructor_unfilled_fields == NULL_TREE)
11837 : : break;
11838 : :
11839 : 3731 : int cmp = init_field_decl_cmp (constructor_unfilled_fields,
11840 : : elt->purpose);
11841 : 3731 : if (cmp == 0)
11842 : 1660 : output_init_element (input_location, elt->value, elt->origtype,
11843 : 1660 : true, TREE_TYPE (elt->purpose),
11844 : : elt->purpose, false, false,
11845 : : braced_init_obstack);
11846 : 2071 : else if (cmp < 0)
11847 : : {
11848 : : /* Advance to the next smaller node. */
11849 : 1084 : if (elt->left)
11850 : : elt = elt->left;
11851 : : else
11852 : : {
11853 : : /* We have reached the smallest node bigger than the
11854 : : current unfilled field. Fill the space first. */
11855 : 807 : next = elt->purpose;
11856 : 807 : break;
11857 : : }
11858 : : }
11859 : : else
11860 : : {
11861 : : /* Advance to the next bigger node. */
11862 : 987 : if (elt->right)
11863 : : elt = elt->right;
11864 : : else
11865 : : {
11866 : : /* We have reached the biggest node in a subtree. Find
11867 : : the parent of it, which is the next bigger node. */
11868 : 731 : while (elt->parent && elt->parent->right == elt)
11869 : : elt = elt->parent;
11870 : 515 : elt = elt->parent;
11871 : 515 : if (elt
11872 : 515 : && init_field_decl_cmp (constructor_unfilled_fields,
11873 : : elt->purpose) < 0)
11874 : : {
11875 : 67 : next = elt->purpose;
11876 : 67 : break;
11877 : : }
11878 : : }
11879 : : }
11880 : : }
11881 : : }
11882 : :
11883 : : /* Ordinarily return, but not if we want to output all
11884 : : and there are elements left. */
11885 : 11499811 : if (!(all && next != NULL_TREE))
11886 : 11498815 : return;
11887 : :
11888 : : /* If it's not incremental, just skip over the gap, so that after
11889 : : jumping to retry we will output the next successive element. */
11890 : 996 : if (RECORD_OR_UNION_TYPE_P (constructor_type))
11891 : 804 : constructor_unfilled_fields = next;
11892 : 192 : else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
11893 : 192 : constructor_unfilled_index = next;
11894 : :
11895 : : /* ELT now points to the node in the pending tree with the next
11896 : : initializer to output. */
11897 : 996 : goto retry;
11898 : : }
11899 : :
11900 : : /* Expression VALUE coincides with the start of type TYPE in a braced
11901 : : initializer. Return true if we should treat VALUE as initializing
11902 : : the first element of TYPE, false if we should treat it as initializing
11903 : : TYPE as a whole.
11904 : :
11905 : : If the initializer is clearly invalid, the question becomes:
11906 : : which choice gives the best error message? */
11907 : :
11908 : : static bool
11909 : 3477688 : initialize_elementwise_p (tree type, tree value)
11910 : : {
11911 : 3477688 : if (type == error_mark_node || value == error_mark_node)
11912 : : return false;
11913 : :
11914 : 3477260 : gcc_checking_assert (TYPE_MAIN_VARIANT (type) == type);
11915 : :
11916 : 3477260 : tree value_type = TREE_TYPE (value);
11917 : 3477260 : if (value_type == error_mark_node)
11918 : : return false;
11919 : :
11920 : : /* GNU vectors can be initialized elementwise. However, treat any
11921 : : kind of vector value as initializing the vector type as a whole,
11922 : : regardless of whether the value is a GNU vector. Such initializers
11923 : : are valid if and only if they would have been valid in a non-braced
11924 : : initializer like:
11925 : :
11926 : : TYPE foo = VALUE;
11927 : :
11928 : : so recursing into the vector type would be at best confusing or at
11929 : : worst wrong. For example, when -flax-vector-conversions is in effect,
11930 : : it's possible to initialize a V8HI from a V4SI, even though the vectors
11931 : : have different element types and different numbers of elements. */
11932 : 3477260 : if (gnu_vector_type_p (type))
11933 : 19169 : return !VECTOR_TYPE_P (value_type);
11934 : :
11935 : 3458091 : if (AGGREGATE_TYPE_P (type))
11936 : 1740931 : return !comptypes (type, TYPE_MAIN_VARIANT (value_type));
11937 : :
11938 : : return false;
11939 : : }
11940 : :
11941 : : /* Helper function for process_init_element. Split first element of
11942 : : RAW_DATA_CST and save the rest to *RAW_DATA. */
11943 : :
11944 : : static inline tree
11945 : 9456410 : maybe_split_raw_data (tree value, tree *raw_data)
11946 : : {
11947 : 9456410 : if (value == NULL_TREE || TREE_CODE (value) != RAW_DATA_CST)
11948 : : return value;
11949 : 211 : *raw_data = value;
11950 : 211 : value = build_int_cst (integer_type_node,
11951 : 211 : RAW_DATA_UCHAR_ELT (*raw_data, 0));
11952 : 211 : ++RAW_DATA_POINTER (*raw_data);
11953 : 211 : --RAW_DATA_LENGTH (*raw_data);
11954 : 211 : return value;
11955 : : }
11956 : :
11957 : : /* Return non-zero if c_parser_initval should attempt to optimize
11958 : : large initializers into RAW_DATA_CST. In that case return how
11959 : : many elements to optimize at most. */
11960 : :
11961 : : unsigned
11962 : 2929656 : c_maybe_optimize_large_byte_initializer (void)
11963 : : {
11964 : 2929656 : if (!constructor_type
11965 : 2929586 : || TREE_CODE (constructor_type) != ARRAY_TYPE
11966 : 205392 : || constructor_stack->implicit)
11967 : : return 0;
11968 : 202657 : tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
11969 : 202657 : if (TREE_CODE (elttype) != INTEGER_TYPE
11970 : 202657 : && TREE_CODE (elttype) != BITINT_TYPE)
11971 : : return 0;
11972 : 180276 : if (TYPE_PRECISION (elttype) != CHAR_BIT
11973 : 27790 : || constructor_stack->replacement_value.value
11974 : 27790 : || (COMPLETE_TYPE_P (constructor_type)
11975 : 26153 : && !poly_int_tree_p (TYPE_SIZE (constructor_type)))
11976 : 208066 : || constructor_range_stack)
11977 : : return 0;
11978 : 27790 : if (constructor_max_index == NULL_TREE)
11979 : : return INT_MAX;
11980 : 26153 : if (tree_int_cst_le (constructor_max_index, constructor_index)
11981 : 26153 : || integer_all_onesp (constructor_max_index))
11982 : 4754 : return 0;
11983 : 21399 : widest_int w = wi::to_widest (constructor_max_index);
11984 : 21399 : w -= wi::to_widest (constructor_index);
11985 : 21399 : w += 1;
11986 : 21399 : if (w < 64)
11987 : : return 0;
11988 : 6886 : if (w > INT_MAX)
11989 : : return INT_MAX;
11990 : 6886 : return w.to_uhwi ();
11991 : 21399 : }
11992 : :
11993 : : /* Add one non-braced element to the current constructor level.
11994 : : This adjusts the current position within the constructor's type.
11995 : : This may also start or terminate implicit levels
11996 : : to handle a partly-braced initializer.
11997 : :
11998 : : Once this has found the correct level for the new element,
11999 : : it calls output_init_element.
12000 : :
12001 : : IMPLICIT is true if value comes from pop_init_level (1),
12002 : : the new initializer has been merged with the existing one
12003 : : and thus no warnings should be emitted about overriding an
12004 : : existing initializer. */
12005 : :
12006 : : void
12007 : 9447426 : process_init_element (location_t loc, struct c_expr value, bool implicit,
12008 : : struct obstack * braced_init_obstack)
12009 : : {
12010 : 9447426 : tree orig_value = value.value;
12011 : 18894852 : int string_flag
12012 : 9447426 : = (orig_value != NULL_TREE && TREE_CODE (orig_value) == STRING_CST);
12013 : 9447426 : bool strict_string = value.original_code == STRING_CST;
12014 : 9447426 : bool was_designated = designator_depth != 0;
12015 : 9447426 : tree raw_data = NULL_TREE;
12016 : :
12017 : 9447638 : retry:
12018 : 9447638 : designator_depth = 0;
12019 : 9447638 : designator_erroneous = 0;
12020 : :
12021 : 9447638 : if (!implicit && value.value && !integer_zerop (value.value))
12022 : 7448754 : constructor_zeroinit = 0;
12023 : :
12024 : : /* Handle superfluous braces around string cst as in
12025 : : char x[] = {"foo"}; */
12026 : 9447638 : if (constructor_type
12027 : 9447510 : && !was_designated
12028 : 9414507 : && TREE_CODE (constructor_type) == ARRAY_TYPE
12029 : 1700962 : && INTEGRAL_TYPE_P (TREE_TYPE (constructor_type))
12030 : 10179974 : && integer_zerop (constructor_unfilled_index))
12031 : : {
12032 : 162798 : if (constructor_stack->replacement_value.value)
12033 : : {
12034 : 8 : error_init (loc, "excess elements in %qT initializer", constructor_type);
12035 : 375 : return;
12036 : : }
12037 : 162790 : else if (string_flag)
12038 : : {
12039 : 102 : constructor_stack->replacement_value = value;
12040 : 102 : return;
12041 : : }
12042 : : }
12043 : :
12044 : 9447528 : if (constructor_stack->replacement_value.value != NULL_TREE)
12045 : : {
12046 : 0 : error_init (loc, "excess elements in struct initializer");
12047 : 0 : return;
12048 : : }
12049 : :
12050 : : /* Ignore elements of a brace group if it is entirely superfluous
12051 : : and has already been diagnosed, or if the type is erroneous. */
12052 : 9447528 : if (constructor_type == NULL_TREE || constructor_type == error_mark_node)
12053 : : return;
12054 : :
12055 : : /* Ignore elements of an initializer for a variable-size type.
12056 : : Those are diagnosed in the parser (empty initializer braces are OK). */
12057 : 9447323 : if (COMPLETE_TYPE_P (constructor_type)
12058 : 9447323 : && !poly_int_tree_p (TYPE_SIZE (constructor_type)))
12059 : : return;
12060 : :
12061 : 8743719 : if (!implicit && warn_designated_init && !was_designated
12062 : 8711333 : && TREE_CODE (constructor_type) == RECORD_TYPE
12063 : 10481241 : && lookup_attribute ("designated_init",
12064 : 1033970 : TYPE_ATTRIBUTES (constructor_type)))
12065 : 50 : warning_init (loc,
12066 : : OPT_Wdesignated_init,
12067 : : "positional initialization of field "
12068 : : "in %<struct%> declared with %<designated_init%> attribute");
12069 : :
12070 : : /* If we've exhausted any levels that didn't have braces,
12071 : : pop them now. */
12072 : 10149229 : while (constructor_stack->implicit)
12073 : : {
12074 : 706771 : if (RECORD_OR_UNION_TYPE_P (constructor_type)
12075 : 702768 : && constructor_fields == NULL_TREE)
12076 : 701717 : process_init_element (loc,
12077 : : pop_init_level (loc, 1, braced_init_obstack,
12078 : : last_init_list_comma),
12079 : : true, braced_init_obstack);
12080 : 5054 : else if ((TREE_CODE (constructor_type) == ARRAY_TYPE
12081 : 1695 : || gnu_vector_type_p (constructor_type))
12082 : 4003 : && constructor_max_index
12083 : 9030 : && tree_int_cst_lt (constructor_max_index,
12084 : : constructor_index))
12085 : 241 : process_init_element (loc,
12086 : : pop_init_level (loc, 1, braced_init_obstack,
12087 : : last_init_list_comma),
12088 : : true, braced_init_obstack);
12089 : : else
12090 : : break;
12091 : : }
12092 : :
12093 : : /* In the case of [LO ... HI] = VALUE, only evaluate VALUE once. */
12094 : 9447271 : if (constructor_range_stack)
12095 : : {
12096 : : /* If value is a compound literal and we'll be just using its
12097 : : content, don't put it into a SAVE_EXPR. */
12098 : 365 : if (TREE_CODE (value.value) != COMPOUND_LITERAL_EXPR
12099 : 3 : || !require_constant_value)
12100 : : {
12101 : 362 : tree semantic_type = NULL_TREE;
12102 : 362 : if (TREE_CODE (value.value) == EXCESS_PRECISION_EXPR)
12103 : : {
12104 : 0 : semantic_type = TREE_TYPE (value.value);
12105 : 0 : value.value = TREE_OPERAND (value.value, 0);
12106 : : }
12107 : 362 : value.value = save_expr (value.value);
12108 : 362 : if (semantic_type)
12109 : 0 : value.value = build1 (EXCESS_PRECISION_EXPR, semantic_type,
12110 : : value.value);
12111 : : }
12112 : : }
12113 : :
12114 : 10160683 : while (1)
12115 : : {
12116 : 10160683 : if (TREE_CODE (constructor_type) == RECORD_TYPE)
12117 : : {
12118 : 1037973 : tree fieldtype;
12119 : 1037973 : enum tree_code fieldcode;
12120 : :
12121 : 1037973 : if (constructor_fields == NULL_TREE)
12122 : : {
12123 : 1280 : pedwarn_init (loc, 0, "excess elements in struct initializer");
12124 : 1280 : break;
12125 : : }
12126 : :
12127 : 1036693 : fieldtype = TREE_TYPE (constructor_fields);
12128 : 1036693 : if (fieldtype != error_mark_node)
12129 : 1036692 : fieldtype = TYPE_MAIN_VARIANT (fieldtype);
12130 : 1036693 : fieldcode = TREE_CODE (fieldtype);
12131 : :
12132 : : /* Error for non-static initialization of a flexible array member. */
12133 : 1036693 : if (fieldcode == ARRAY_TYPE
12134 : 155204 : && !require_constant_value
12135 : 1078 : && TYPE_SIZE (fieldtype) == NULL_TREE
12136 : 1036703 : && DECL_CHAIN (constructor_fields) == NULL_TREE)
12137 : : {
12138 : 10 : error_init (loc, "non-static initialization of a flexible "
12139 : : "array member");
12140 : 10 : break;
12141 : : }
12142 : :
12143 : : /* Error for initialization of a flexible array member with
12144 : : a string constant if the structure is in an array. E.g.:
12145 : : struct S { int x; char y[]; };
12146 : : struct S s[] = { { 1, "foo" } };
12147 : : is invalid. */
12148 : 1036683 : if (string_flag
12149 : 1036683 : && fieldcode == ARRAY_TYPE
12150 : 3352 : && constructor_depth > 1
12151 : 489 : && TYPE_SIZE (fieldtype) == NULL_TREE
12152 : 1036730 : && DECL_CHAIN (constructor_fields) == NULL_TREE)
12153 : : {
12154 : 47 : bool in_array_p = false;
12155 : 47 : for (struct constructor_stack *p = constructor_stack;
12156 : 73 : p && p->type; p = p->next)
12157 : 59 : if (TREE_CODE (p->type) == ARRAY_TYPE)
12158 : : {
12159 : : in_array_p = true;
12160 : : break;
12161 : : }
12162 : 47 : if (in_array_p)
12163 : : {
12164 : 33 : error_init (loc, "initialization of flexible array "
12165 : : "member in a nested context");
12166 : 33 : break;
12167 : : }
12168 : : }
12169 : :
12170 : : /* Accept a string constant to initialize a subarray. */
12171 : 1036650 : if (value.value != NULL_TREE
12172 : 1036577 : && fieldcode == ARRAY_TYPE
12173 : 155088 : && INTEGRAL_TYPE_P (TREE_TYPE (fieldtype))
12174 : 1191261 : && string_flag)
12175 : : value.value = orig_value;
12176 : : /* Otherwise, if we have come to a subaggregate,
12177 : : and we don't have an element of its type, push into it. */
12178 : 1033619 : else if (value.value != NULL_TREE
12179 : 1033331 : && initialize_elementwise_p (fieldtype, value.value))
12180 : : {
12181 : 288 : push_init_level (loc, 1, braced_init_obstack);
12182 : 288 : continue;
12183 : : }
12184 : :
12185 : 1036362 : value.value = maybe_split_raw_data (value.value, &raw_data);
12186 : 1036362 : if (value.value)
12187 : : {
12188 : 1036289 : push_member_name (constructor_fields);
12189 : 1036289 : output_init_element (loc, value.value, value.original_type,
12190 : : strict_string, fieldtype,
12191 : : constructor_fields, true, implicit,
12192 : : braced_init_obstack);
12193 : 1036289 : RESTORE_SPELLING_DEPTH (constructor_depth);
12194 : : }
12195 : : else
12196 : : /* Do the bookkeeping for an element that was
12197 : : directly output as a constructor. */
12198 : : {
12199 : : /* For a record, keep track of end position of last field. */
12200 : 73 : if (DECL_SIZE (constructor_fields))
12201 : 30 : constructor_bit_index
12202 : 30 : = size_binop_loc (input_location, PLUS_EXPR,
12203 : : bit_position (constructor_fields),
12204 : 30 : DECL_SIZE (constructor_fields));
12205 : :
12206 : : /* If the current field was the first one not yet written out,
12207 : : it isn't now, so update. */
12208 : 73 : if (constructor_unfilled_fields == constructor_fields)
12209 : : {
12210 : 64 : constructor_unfilled_fields = DECL_CHAIN (constructor_fields);
12211 : : /* Skip any nameless bit fields. */
12212 : 64 : while (constructor_unfilled_fields != 0
12213 : 64 : && (DECL_UNNAMED_BIT_FIELD
12214 : : (constructor_unfilled_fields)))
12215 : 0 : constructor_unfilled_fields =
12216 : 0 : DECL_CHAIN (constructor_unfilled_fields);
12217 : : }
12218 : : }
12219 : :
12220 : 1036362 : constructor_fields = DECL_CHAIN (constructor_fields);
12221 : : /* Skip any nameless bit fields at the beginning. */
12222 : 1036362 : while (constructor_fields != NULL_TREE
12223 : 1036463 : && DECL_UNNAMED_BIT_FIELD (constructor_fields))
12224 : 101 : constructor_fields = DECL_CHAIN (constructor_fields);
12225 : : }
12226 : 9122710 : else if (TREE_CODE (constructor_type) == UNION_TYPE)
12227 : : {
12228 : 30254 : tree fieldtype;
12229 : 30254 : enum tree_code fieldcode;
12230 : :
12231 : 30254 : if (constructor_fields == NULL_TREE)
12232 : : {
12233 : 3 : pedwarn_init (loc, 0,
12234 : : "excess elements in union initializer");
12235 : 3 : break;
12236 : : }
12237 : :
12238 : 30251 : fieldtype = TREE_TYPE (constructor_fields);
12239 : 30251 : if (fieldtype != error_mark_node)
12240 : 30251 : fieldtype = TYPE_MAIN_VARIANT (fieldtype);
12241 : 30251 : fieldcode = TREE_CODE (fieldtype);
12242 : :
12243 : : /* Warn that traditional C rejects initialization of unions.
12244 : : We skip the warning if the value is zero. This is done
12245 : : under the assumption that the zero initializer in user
12246 : : code appears conditioned on e.g. __STDC__ to avoid
12247 : : "missing initializer" warnings and relies on default
12248 : : initialization to zero in the traditional C case.
12249 : : We also skip the warning if the initializer is designated,
12250 : : again on the assumption that this must be conditional on
12251 : : __STDC__ anyway (and we've already complained about the
12252 : : member-designator already). */
12253 : 32298 : if (!in_system_header_at (input_location) && !constructor_designated
12254 : 31682 : && !(value.value && (integer_zerop (value.value)
12255 : 1333 : || real_zerop (value.value))))
12256 : 1326 : warning (OPT_Wtraditional, "traditional C rejects initialization "
12257 : : "of unions");
12258 : :
12259 : : /* Error for non-static initialization of a flexible array member. */
12260 : 30251 : if (fieldcode == ARRAY_TYPE
12261 : 766 : && !require_constant_value
12262 : 30308 : && TYPE_SIZE (fieldtype) == NULL_TREE)
12263 : : {
12264 : 3 : error_init (loc, "non-static initialization of a flexible "
12265 : : "array member");
12266 : 3 : break;
12267 : : }
12268 : :
12269 : : /* Error for initialization of a flexible array member with
12270 : : a string constant if the structure is in an array. E.g.:
12271 : : union U { int x; char y[]; };
12272 : : union U s[] = { { 1, "foo" } };
12273 : : is invalid. */
12274 : 30248 : if (string_flag
12275 : 30248 : && fieldcode == ARRAY_TYPE
12276 : 7 : && constructor_depth > 1
12277 : 30252 : && TYPE_SIZE (fieldtype) == NULL_TREE)
12278 : : {
12279 : 3 : bool in_array_p = false;
12280 : 3 : for (struct constructor_stack *p = constructor_stack;
12281 : 3 : p && p->type; p = p->next)
12282 : 3 : if (TREE_CODE (p->type) == ARRAY_TYPE)
12283 : : {
12284 : : in_array_p = true;
12285 : : break;
12286 : : }
12287 : 3 : if (in_array_p)
12288 : : {
12289 : 3 : error_init (loc, "initialization of flexible array "
12290 : : "member in a nested context");
12291 : 3 : break;
12292 : : }
12293 : : }
12294 : :
12295 : : /* Accept a string constant to initialize a subarray. */
12296 : 30245 : if (value.value != NULL_TREE
12297 : 30245 : && fieldcode == ARRAY_TYPE
12298 : 760 : && INTEGRAL_TYPE_P (TREE_TYPE (fieldtype))
12299 : 31000 : && string_flag)
12300 : : value.value = orig_value;
12301 : : /* Otherwise, if we have come to a subaggregate,
12302 : : and we don't have an element of its type, push into it. */
12303 : 30287 : else if (value.value != NULL_TREE
12304 : 30241 : && initialize_elementwise_p (fieldtype, value.value))
12305 : : {
12306 : 46 : push_init_level (loc, 1, braced_init_obstack);
12307 : 46 : continue;
12308 : : }
12309 : :
12310 : 30199 : value.value = maybe_split_raw_data (value.value, &raw_data);
12311 : 30199 : if (value.value)
12312 : : {
12313 : 30199 : push_member_name (constructor_fields);
12314 : 30199 : output_init_element (loc, value.value, value.original_type,
12315 : : strict_string, fieldtype,
12316 : : constructor_fields, true, implicit,
12317 : : braced_init_obstack);
12318 : 30199 : RESTORE_SPELLING_DEPTH (constructor_depth);
12319 : : }
12320 : : else
12321 : : /* Do the bookkeeping for an element that was
12322 : : directly output as a constructor. */
12323 : : {
12324 : 0 : constructor_bit_index = DECL_SIZE (constructor_fields);
12325 : 0 : constructor_unfilled_fields = DECL_CHAIN (constructor_fields);
12326 : : }
12327 : :
12328 : 30199 : constructor_fields = NULL_TREE;
12329 : : }
12330 : 9092456 : else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
12331 : : {
12332 : 2414684 : tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
12333 : 2414684 : enum tree_code eltcode = TREE_CODE (elttype);
12334 : :
12335 : : /* Accept a string constant to initialize a subarray. */
12336 : 2414684 : if (value.value != NULL_TREE
12337 : 2414684 : && eltcode == ARRAY_TYPE
12338 : 6867 : && INTEGRAL_TYPE_P (TREE_TYPE (elttype))
12339 : 2420115 : && string_flag)
12340 : : value.value = orig_value;
12341 : : /* Otherwise, if we have come to a subaggregate,
12342 : : and we don't have an element of its type, push into it. */
12343 : 3116465 : else if (value.value != NULL_TREE
12344 : 2414189 : && initialize_elementwise_p (elttype, value.value))
12345 : : {
12346 : 702276 : push_init_level (loc, 1, braced_init_obstack);
12347 : 702276 : continue;
12348 : : }
12349 : :
12350 : 1712408 : if (constructor_max_index != NULL_TREE
12351 : 1712408 : && (tree_int_cst_lt (constructor_max_index, constructor_index)
12352 : 669755 : || integer_all_onesp (constructor_max_index)))
12353 : : {
12354 : 113 : pedwarn_init (loc, 0,
12355 : : "excess elements in array initializer");
12356 : 113 : break;
12357 : : }
12358 : :
12359 : 1712295 : if (value.value
12360 : 1712295 : && TREE_CODE (value.value) == RAW_DATA_CST
12361 : 189 : && RAW_DATA_LENGTH (value.value) > 1
12362 : 189 : && (TREE_CODE (elttype) == INTEGER_TYPE
12363 : 189 : || TREE_CODE (elttype) == BITINT_TYPE)
12364 : 189 : && TYPE_PRECISION (elttype) == CHAR_BIT
12365 : 1712484 : && (constructor_max_index == NULL_TREE
12366 : 51 : || tree_int_cst_lt (constructor_index,
12367 : : constructor_max_index)))
12368 : : {
12369 : 189 : unsigned int len = RAW_DATA_LENGTH (value.value);
12370 : 189 : if (constructor_max_index)
12371 : : {
12372 : 51 : widest_int w = wi::to_widest (constructor_max_index);
12373 : 51 : w -= wi::to_widest (constructor_index);
12374 : 51 : w += 1;
12375 : 51 : if (w < len)
12376 : 3 : len = w.to_uhwi ();
12377 : 51 : }
12378 : 189 : if (len < (unsigned) RAW_DATA_LENGTH (value.value))
12379 : : {
12380 : 3 : raw_data = copy_node (value.value);
12381 : 3 : RAW_DATA_LENGTH (raw_data) -= len;
12382 : 3 : RAW_DATA_POINTER (raw_data) += len;
12383 : 3 : RAW_DATA_LENGTH (value.value) = len;
12384 : : }
12385 : 189 : TREE_TYPE (value.value) = elttype;
12386 : 189 : push_array_bounds (tree_to_uhwi (constructor_index));
12387 : 189 : output_init_element (loc, value.value, value.original_type,
12388 : : false, elttype, constructor_index, true,
12389 : : implicit, braced_init_obstack);
12390 : 189 : RESTORE_SPELLING_DEPTH (constructor_depth);
12391 : 189 : constructor_index
12392 : 189 : = size_binop_loc (input_location, PLUS_EXPR,
12393 : 189 : constructor_index, bitsize_int (len));
12394 : : }
12395 : : else
12396 : : {
12397 : 1712106 : value.value = maybe_split_raw_data (value.value, &raw_data);
12398 : : /* Now output the actual element. */
12399 : 1712106 : if (value.value)
12400 : : {
12401 : 1712106 : push_array_bounds (tree_to_uhwi (constructor_index));
12402 : 1712106 : output_init_element (loc, value.value, value.original_type,
12403 : : strict_string, elttype,
12404 : : constructor_index, true, implicit,
12405 : : braced_init_obstack);
12406 : 1712106 : RESTORE_SPELLING_DEPTH (constructor_depth);
12407 : : }
12408 : :
12409 : 1712106 : constructor_index
12410 : 1712106 : = size_binop_loc (input_location, PLUS_EXPR,
12411 : : constructor_index, bitsize_one_node);
12412 : :
12413 : 1712106 : if (!value.value)
12414 : : /* If we are doing the bookkeeping for an element that was
12415 : : directly output as a constructor, we must update
12416 : : constructor_unfilled_index. */
12417 : 0 : constructor_unfilled_index = constructor_index;
12418 : : }
12419 : : }
12420 : 6677772 : else if (gnu_vector_type_p (constructor_type))
12421 : : {
12422 : 6677330 : tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
12423 : :
12424 : : /* Do a basic check of initializer size. Note that vectors
12425 : : may not always have a fixed size derived from their type. */
12426 : 6677330 : if (maybe_lt (tree_to_poly_uint64 (constructor_max_index),
12427 : 6677330 : tree_to_poly_uint64 (constructor_index)))
12428 : : {
12429 : : /* Diagose VLA out-of-bounds as errors. */
12430 : 2 : if (tree_to_poly_uint64 (constructor_max_index).is_constant())
12431 : 2 : pedwarn_init (loc, 0,
12432 : : "excess elements in vector initializer");
12433 : : else
12434 : : error_init (loc, "excess elements in vector initializer");
12435 : :
12436 : : break;
12437 : : }
12438 : :
12439 : 6677328 : value.value = maybe_split_raw_data (value.value, &raw_data);
12440 : : /* Now output the actual element. */
12441 : 6677328 : if (value.value)
12442 : : {
12443 : 6677328 : if (TREE_CODE (value.value) == VECTOR_CST)
12444 : 0 : elttype = TYPE_MAIN_VARIANT (constructor_type);
12445 : 6677328 : output_init_element (loc, value.value, value.original_type,
12446 : : strict_string, elttype,
12447 : : constructor_index, true, implicit,
12448 : : braced_init_obstack);
12449 : : }
12450 : :
12451 : 6677328 : constructor_index
12452 : 6677328 : = size_binop_loc (input_location,
12453 : : PLUS_EXPR, constructor_index, bitsize_one_node);
12454 : :
12455 : 6677328 : if (!value.value)
12456 : : /* If we are doing the bookkeeping for an element that was
12457 : : directly output as a constructor, we must update
12458 : : constructor_unfilled_index. */
12459 : 0 : constructor_unfilled_index = constructor_index;
12460 : : }
12461 : :
12462 : : /* Handle the sole element allowed in a braced initializer
12463 : : for a scalar variable. */
12464 : 442 : else if (constructor_type != error_mark_node
12465 : 442 : && constructor_fields == NULL_TREE)
12466 : : {
12467 : 27 : pedwarn_init (loc, 0,
12468 : : "excess elements in scalar initializer");
12469 : 27 : break;
12470 : : }
12471 : : else
12472 : : {
12473 : 415 : value.value = maybe_split_raw_data (value.value, &raw_data);
12474 : 415 : if (value.value)
12475 : 415 : output_init_element (loc, value.value, value.original_type,
12476 : : strict_string, constructor_type,
12477 : : NULL_TREE, true, implicit,
12478 : : braced_init_obstack);
12479 : 415 : constructor_fields = NULL_TREE;
12480 : : }
12481 : :
12482 : : /* Handle range initializers either at this level or anywhere higher
12483 : : in the designator stack. */
12484 : 9456599 : if (constructor_range_stack)
12485 : : {
12486 : 10802 : struct constructor_range_stack *p, *range_stack;
12487 : 10802 : int finish = 0;
12488 : :
12489 : 10802 : range_stack = constructor_range_stack;
12490 : 10802 : constructor_range_stack = 0;
12491 : 10802 : while (constructor_stack != range_stack->stack)
12492 : : {
12493 : 0 : gcc_assert (constructor_stack->implicit);
12494 : 0 : process_init_element (loc,
12495 : : pop_init_level (loc, 1,
12496 : : braced_init_obstack,
12497 : : last_init_list_comma),
12498 : : true, braced_init_obstack);
12499 : : }
12500 : 325 : for (p = range_stack;
12501 : 11127 : !p->range_end || tree_int_cst_equal (p->index, p->range_end);
12502 : 325 : p = p->prev)
12503 : : {
12504 : 325 : gcc_assert (constructor_stack->implicit);
12505 : 325 : process_init_element (loc,
12506 : : pop_init_level (loc, 1,
12507 : : braced_init_obstack,
12508 : : last_init_list_comma),
12509 : : true, braced_init_obstack);
12510 : : }
12511 : :
12512 : 10802 : p->index = size_binop_loc (input_location,
12513 : : PLUS_EXPR, p->index, bitsize_one_node);
12514 : 10802 : if (tree_int_cst_equal (p->index, p->range_end) && !p->prev)
12515 : 373 : finish = 1;
12516 : :
12517 : 11127 : while (1)
12518 : : {
12519 : 11127 : constructor_index = p->index;
12520 : 11127 : constructor_fields = p->fields;
12521 : 11127 : if (finish && p->range_end && p->index == p->range_start)
12522 : : {
12523 : 8 : finish = 0;
12524 : 8 : p->prev = 0;
12525 : : }
12526 : 11127 : p = p->next;
12527 : 11127 : if (!p)
12528 : : break;
12529 : 325 : finish_implicit_inits (loc, braced_init_obstack);
12530 : 325 : push_init_level (loc, 2, braced_init_obstack);
12531 : 325 : p->stack = constructor_stack;
12532 : 325 : if (p->range_end && tree_int_cst_equal (p->index, p->range_end))
12533 : 33 : p->index = p->range_start;
12534 : : }
12535 : :
12536 : 10802 : if (!finish)
12537 : 10437 : constructor_range_stack = range_stack;
12538 : 10802 : continue;
12539 : 10802 : }
12540 : :
12541 : : break;
12542 : : }
12543 : :
12544 : 9447271 : constructor_range_stack = 0;
12545 : :
12546 : 9447271 : if (raw_data && RAW_DATA_LENGTH (raw_data))
12547 : : {
12548 : 212 : gcc_assert (!string_flag && !was_designated);
12549 : 212 : value.value = raw_data;
12550 : 212 : raw_data = NULL_TREE;
12551 : 212 : goto retry;
12552 : : }
12553 : : }
12554 : :
12555 : : /* Build a complete asm-statement, whose components are a CV_QUALIFIER
12556 : : (guaranteed to be 'volatile' or null) and ARGS (represented using
12557 : : an ASM_EXPR node). */
12558 : : tree
12559 : 200523 : build_asm_stmt (bool is_volatile, tree args)
12560 : : {
12561 : 200523 : if (is_volatile)
12562 : 160961 : ASM_VOLATILE_P (args) = 1;
12563 : 200523 : return add_stmt (args);
12564 : : }
12565 : :
12566 : : /* Build an asm-expr, whose components are a STRING, some OUTPUTS,
12567 : : some INPUTS, and some CLOBBERS. The latter three may be NULL.
12568 : : SIMPLE indicates whether there was anything at all after the
12569 : : string in the asm expression -- asm("blah") and asm("blah" : )
12570 : : are subtly different. We use a ASM_EXPR node to represent this.
12571 : : LOC is the location of the asm, and IS_INLINE says whether this
12572 : : is asm inline. */
12573 : : tree
12574 : 200552 : build_asm_expr (location_t loc, tree string, tree outputs, tree inputs,
12575 : : tree clobbers, tree labels, bool simple, bool is_inline)
12576 : : {
12577 : 200552 : tree tail;
12578 : 200552 : tree args;
12579 : 200552 : int i;
12580 : 200552 : const char *constraint;
12581 : 200552 : const char **oconstraints;
12582 : 200552 : bool allows_mem, allows_reg, is_inout;
12583 : 200552 : int ninputs, noutputs;
12584 : :
12585 : 200552 : ninputs = list_length (inputs);
12586 : 200552 : noutputs = list_length (outputs);
12587 : 200552 : oconstraints = (const char **) alloca (noutputs * sizeof (const char *));
12588 : :
12589 : 200552 : string = resolve_asm_operand_names (string, outputs, inputs, labels);
12590 : :
12591 : : /* Remove output conversions that change the type but not the mode. */
12592 : 539106 : for (i = 0, tail = outputs; tail; ++i, tail = TREE_CHAIN (tail))
12593 : : {
12594 : 338554 : tree output = TREE_VALUE (tail);
12595 : :
12596 : 338554 : output = c_fully_fold (output, false, NULL, true);
12597 : :
12598 : : /* ??? Really, this should not be here. Users should be using a
12599 : : proper lvalue, dammit. But there's a long history of using casts
12600 : : in the output operands. In cases like longlong.h, this becomes a
12601 : : primitive form of typechecking -- if the cast can be removed, then
12602 : : the output operand had a type of the proper width; otherwise we'll
12603 : : get an error. Gross, but ... */
12604 : 338554 : STRIP_NOPS (output);
12605 : :
12606 : 338554 : if (!lvalue_or_else (loc, output, lv_asm))
12607 : 4 : output = error_mark_node;
12608 : :
12609 : 338554 : if (output != error_mark_node
12610 : 338554 : && (TREE_READONLY (output)
12611 : 338548 : || TYPE_READONLY (TREE_TYPE (output))
12612 : 338548 : || (RECORD_OR_UNION_TYPE_P (TREE_TYPE (output))
12613 : 112 : && C_TYPE_FIELDS_READONLY (TREE_TYPE (output)))))
12614 : 2 : readonly_error (loc, output, lv_asm);
12615 : :
12616 : 338554 : constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (tail)));
12617 : 338554 : oconstraints[i] = constraint;
12618 : :
12619 : 338554 : if (parse_output_constraint (&constraint, i, ninputs, noutputs,
12620 : : &allows_mem, &allows_reg, &is_inout))
12621 : : {
12622 : : /* If the operand is going to end up in memory,
12623 : : mark it addressable. */
12624 : 338546 : if (!allows_reg && !c_mark_addressable (output))
12625 : 3 : output = error_mark_node;
12626 : 1087 : if (!(!allows_reg && allows_mem)
12627 : 337459 : && output != error_mark_node
12628 : 676004 : && VOID_TYPE_P (TREE_TYPE (output)))
12629 : : {
12630 : 4 : error_at (loc, "invalid use of void expression");
12631 : 4 : output = error_mark_node;
12632 : : }
12633 : 338546 : if (allows_reg && current_function_decl == NULL_TREE)
12634 : : {
12635 : 1 : error_at (loc, "constraint allows registers outside of "
12636 : : "a function");
12637 : 1 : output = error_mark_node;
12638 : : }
12639 : : }
12640 : : else
12641 : 8 : output = error_mark_node;
12642 : :
12643 : 338554 : if (current_function_decl == NULL_TREE && output != error_mark_node)
12644 : : {
12645 : 7 : if (TREE_SIDE_EFFECTS (output))
12646 : : {
12647 : 0 : error_at (loc, "side-effects in output operand outside "
12648 : : "of a function");
12649 : 0 : output = error_mark_node;
12650 : : }
12651 : : else
12652 : : {
12653 : 7 : tree addr = build_unary_op (loc, ADDR_EXPR, output, false);
12654 : 7 : if (addr == error_mark_node)
12655 : : output = error_mark_node;
12656 : 7 : else if (!initializer_constant_valid_p (addr, TREE_TYPE (addr)))
12657 : : {
12658 : 1 : error_at (loc, "output operand outside of a function is not "
12659 : : "constant");
12660 : 1 : output = error_mark_node;
12661 : : }
12662 : : }
12663 : : }
12664 : 338547 : else if (output != error_mark_node && strstr (constraint, "-"))
12665 : : {
12666 : 1 : error_at (loc, "%<-%> modifier used inside of a function");
12667 : 1 : output = error_mark_node;
12668 : : }
12669 : :
12670 : 338554 : TREE_VALUE (tail) = output;
12671 : : }
12672 : :
12673 : 555273 : for (i = 0, tail = inputs; tail; ++i, tail = TREE_CHAIN (tail))
12674 : : {
12675 : 354721 : tree input;
12676 : :
12677 : 354721 : constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (tail)));
12678 : 354721 : input = TREE_VALUE (tail);
12679 : :
12680 : 354721 : if (parse_input_constraint (&constraint, i, ninputs, noutputs, 0,
12681 : : oconstraints, &allows_mem, &allows_reg))
12682 : : {
12683 : : /* If the operand is going to end up in memory,
12684 : : mark it addressable. */
12685 : 354714 : if (!allows_reg && allows_mem)
12686 : : {
12687 : 1076 : input = c_fully_fold (input, false, NULL, true);
12688 : :
12689 : : /* Strip the nops as we allow this case. FIXME, this really
12690 : : should be rejected or made deprecated. */
12691 : 1076 : STRIP_NOPS (input);
12692 : 1076 : if (!c_mark_addressable (input))
12693 : 2 : input = error_mark_node;
12694 : : }
12695 : : else
12696 : : {
12697 : 353638 : struct c_expr expr;
12698 : 353638 : memset (&expr, 0, sizeof (expr));
12699 : 353638 : expr.value = input;
12700 : 353638 : expr = convert_lvalue_to_rvalue (loc, expr, true, false);
12701 : 353638 : input = c_fully_fold (expr.value, false, NULL);
12702 : :
12703 : 353638 : if (input != error_mark_node && VOID_TYPE_P (TREE_TYPE (input)))
12704 : : {
12705 : 4 : error_at (loc, "invalid use of void expression");
12706 : 4 : input = error_mark_node;
12707 : : }
12708 : : }
12709 : 354714 : if (allows_reg && current_function_decl == NULL_TREE)
12710 : : {
12711 : 1 : error_at (loc, "constraint allows registers outside of "
12712 : : "a function");
12713 : 1 : input = error_mark_node;
12714 : : }
12715 : 354714 : if (constraint[0] == ':' && input != error_mark_node)
12716 : : {
12717 : 12 : tree t = input;
12718 : 12 : STRIP_NOPS (t);
12719 : 12 : if (TREE_CODE (t) != ADDR_EXPR
12720 : 12 : || !(TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL
12721 : 8 : || (VAR_P (TREE_OPERAND (t, 0))
12722 : 6 : && is_global_var (TREE_OPERAND (t, 0)))))
12723 : : {
12724 : 5 : error_at (loc, "%<:%> constraint operand is not address "
12725 : : "of a function or non-automatic variable");
12726 : 5 : input = error_mark_node;
12727 : : }
12728 : : }
12729 : : }
12730 : : else
12731 : 7 : input = error_mark_node;
12732 : :
12733 : 354721 : if (current_function_decl == NULL_TREE && input != error_mark_node)
12734 : : {
12735 : 30 : if (TREE_SIDE_EFFECTS (input))
12736 : : {
12737 : 2 : error_at (loc, "side-effects in input operand outside "
12738 : : "of a function");
12739 : 2 : input = error_mark_node;
12740 : : }
12741 : : else
12742 : : {
12743 : 28 : tree tem = input;
12744 : 28 : if (allows_mem && lvalue_p (input))
12745 : 7 : tem = build_unary_op (loc, ADDR_EXPR, input, false);
12746 : 28 : if (!initializer_constant_valid_p (tem, TREE_TYPE (tem)))
12747 : : {
12748 : 2 : error_at (loc, "input operand outside of a function is not "
12749 : : "constant");
12750 : 2 : input = error_mark_node;
12751 : : }
12752 : : }
12753 : : }
12754 : 354691 : else if (input != error_mark_node && strstr (constraint, "-"))
12755 : : {
12756 : 3 : error_at (loc, "%<-%> modifier used inside of a function");
12757 : 3 : input = error_mark_node;
12758 : : }
12759 : :
12760 : 354721 : TREE_VALUE (tail) = input;
12761 : : }
12762 : :
12763 : 200552 : args = build_stmt (loc, ASM_EXPR, string, outputs, inputs, clobbers, labels);
12764 : :
12765 : : /* asm statements without outputs, including simple ones, are treated
12766 : : as volatile. */
12767 : 200552 : ASM_BASIC_P (args) = simple;
12768 : 200552 : ASM_VOLATILE_P (args) = (noutputs == 0);
12769 : 200552 : ASM_INLINE_P (args) = is_inline;
12770 : :
12771 : 200552 : return args;
12772 : : }
12773 : :
12774 : : /* Generate a goto statement to LABEL. LOC is the location of the
12775 : : GOTO. */
12776 : :
12777 : : tree
12778 : 82125 : c_finish_goto_label (location_t loc, tree label)
12779 : : {
12780 : 82125 : tree decl = lookup_label_for_goto (loc, label);
12781 : 82125 : if (!decl)
12782 : : return NULL_TREE;
12783 : 82125 : TREE_USED (decl) = 1;
12784 : 82125 : {
12785 : 82125 : add_stmt (build_predict_expr (PRED_GOTO, NOT_TAKEN));
12786 : 82125 : tree t = build1 (GOTO_EXPR, void_type_node, decl);
12787 : 82125 : SET_EXPR_LOCATION (t, loc);
12788 : 82125 : return add_stmt (t);
12789 : : }
12790 : : }
12791 : :
12792 : : /* Generate a computed goto statement to EXPR. LOC is the location of
12793 : : the GOTO. */
12794 : :
12795 : : tree
12796 : 930 : c_finish_goto_ptr (location_t loc, c_expr val)
12797 : : {
12798 : 930 : tree expr = val.value;
12799 : 930 : tree t;
12800 : 930 : pedwarn (loc, OPT_Wpedantic, "ISO C forbids %<goto *expr;%>");
12801 : 930 : if (expr != error_mark_node
12802 : 929 : && !POINTER_TYPE_P (TREE_TYPE (expr))
12803 : 935 : && !null_pointer_constant_p (expr))
12804 : : {
12805 : 2 : error_at (val.get_location (),
12806 : : "computed goto must be pointer type");
12807 : 2 : expr = build_zero_cst (ptr_type_node);
12808 : : }
12809 : 930 : expr = c_fully_fold (expr, false, NULL);
12810 : 930 : expr = convert (ptr_type_node, expr);
12811 : 930 : t = build1 (GOTO_EXPR, void_type_node, expr);
12812 : 930 : SET_EXPR_LOCATION (t, loc);
12813 : 930 : return add_stmt (t);
12814 : : }
12815 : :
12816 : : /* Generate a C `return' statement. RETVAL is the expression for what
12817 : : to return, or a null pointer for `return;' with no value. LOC is
12818 : : the location of the return statement, or the location of the expression,
12819 : : if the statement has any. If ORIGTYPE is not NULL_TREE, it
12820 : : is the original type of RETVAL. MUSTTAIL_P indicates a musttail
12821 : : attribute. */
12822 : :
12823 : : tree
12824 : 33743696 : c_finish_return (location_t loc, tree retval, tree origtype, bool musttail_p)
12825 : : {
12826 : 33743696 : tree valtype = TREE_TYPE (TREE_TYPE (current_function_decl)), ret_stmt;
12827 : 33743696 : bool no_warning = false;
12828 : 33743696 : bool npc = false;
12829 : :
12830 : : /* Use the expansion point to handle cases such as returning NULL
12831 : : in a function returning void. */
12832 : 33743696 : location_t xloc = expansion_point_location_if_in_system_header (loc);
12833 : :
12834 : 33743696 : if (TREE_THIS_VOLATILE (current_function_decl))
12835 : 23 : warning_at (xloc, 0,
12836 : : "function declared %<noreturn%> has a %<return%> statement");
12837 : :
12838 : 33743696 : set_musttail_on_return (retval, xloc, musttail_p);
12839 : :
12840 : 33743696 : if (retval)
12841 : : {
12842 : 33722855 : tree semantic_type = NULL_TREE;
12843 : 33722855 : npc = null_pointer_constant_p (retval);
12844 : 33722855 : if (TREE_CODE (retval) == EXCESS_PRECISION_EXPR)
12845 : : {
12846 : 92 : semantic_type = TREE_TYPE (retval);
12847 : 92 : retval = TREE_OPERAND (retval, 0);
12848 : : }
12849 : 33722855 : retval = c_fully_fold (retval, false, NULL);
12850 : 33722855 : if (semantic_type
12851 : 33722855 : && valtype != NULL_TREE
12852 : 92 : && TREE_CODE (valtype) != VOID_TYPE)
12853 : 92 : retval = build1 (EXCESS_PRECISION_EXPR, semantic_type, retval);
12854 : : }
12855 : :
12856 : 33722855 : if (!retval)
12857 : : {
12858 : 20841 : current_function_returns_null = 1;
12859 : 20841 : if ((warn_return_type >= 0 || flag_isoc99)
12860 : 20716 : && valtype != NULL_TREE && TREE_CODE (valtype) != VOID_TYPE)
12861 : : {
12862 : 46 : no_warning = true;
12863 : 47 : if (emit_diagnostic (flag_isoc99 ? DK_PERMERROR : DK_WARNING,
12864 : 46 : loc, OPT_Wreturn_mismatch,
12865 : : "%<return%> with no value,"
12866 : : " in function returning non-void"))
12867 : 27 : inform (DECL_SOURCE_LOCATION (current_function_decl),
12868 : : "declared here");
12869 : : }
12870 : : }
12871 : 33722855 : else if (valtype == NULL_TREE || VOID_TYPE_P (valtype))
12872 : : {
12873 : 319 : current_function_returns_null = 1;
12874 : 319 : bool warned_here;
12875 : 319 : if (TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
12876 : 64 : warned_here = permerror_opt
12877 : 64 : (xloc, OPT_Wreturn_mismatch,
12878 : : "%<return%> with a value, in function returning void");
12879 : : else
12880 : 255 : warned_here = pedwarn
12881 : 255 : (xloc, OPT_Wpedantic, "ISO C forbids "
12882 : : "%<return%> with expression, in function returning void");
12883 : 319 : if (warned_here)
12884 : 43 : inform (DECL_SOURCE_LOCATION (current_function_decl),
12885 : : "declared here");
12886 : : }
12887 : : else
12888 : : {
12889 : 33722536 : tree t = convert_for_assignment (loc, UNKNOWN_LOCATION, valtype,
12890 : : retval, origtype, ic_return,
12891 : : npc, NULL_TREE, NULL_TREE, 0);
12892 : 33722536 : tree res = DECL_RESULT (current_function_decl);
12893 : 33722536 : tree inner;
12894 : 33722536 : bool save;
12895 : :
12896 : 33722536 : current_function_returns_value = 1;
12897 : 33722536 : if (t == error_mark_node)
12898 : : {
12899 : : /* Suppress -Wreturn-type for this function. */
12900 : 298 : if (warn_return_type)
12901 : 297 : suppress_warning (current_function_decl, OPT_Wreturn_type);
12902 : 298 : return NULL_TREE;
12903 : : }
12904 : :
12905 : 33722238 : save = in_late_binary_op;
12906 : 67436976 : if (C_BOOLEAN_TYPE_P (TREE_TYPE (res))
12907 : 33714717 : || TREE_CODE (TREE_TYPE (res)) == COMPLEX_TYPE
12908 : 67435675 : || (SCALAR_FLOAT_TYPE_P (TREE_TYPE (t))
12909 : 327665 : && (TREE_CODE (TREE_TYPE (res)) == INTEGER_TYPE
12910 : 327665 : || TREE_CODE (TREE_TYPE (res)) == ENUMERAL_TYPE)
12911 : 0 : && sanitize_flags_p (SANITIZE_FLOAT_CAST)))
12912 : 8801 : in_late_binary_op = true;
12913 : 33722238 : inner = t = convert (TREE_TYPE (res), t);
12914 : 33722238 : in_late_binary_op = save;
12915 : :
12916 : : /* Strip any conversions, additions, and subtractions, and see if
12917 : : we are returning the address of a local variable. Warn if so. */
12918 : 36919058 : while (1)
12919 : : {
12920 : 36919058 : switch (TREE_CODE (inner))
12921 : : {
12922 : 3195411 : CASE_CONVERT:
12923 : 3195411 : case NON_LVALUE_EXPR:
12924 : 3195411 : case PLUS_EXPR:
12925 : 3195411 : case POINTER_PLUS_EXPR:
12926 : 3195411 : inner = TREE_OPERAND (inner, 0);
12927 : 3195411 : continue;
12928 : :
12929 : 1414 : case MINUS_EXPR:
12930 : : /* If the second operand of the MINUS_EXPR has a pointer
12931 : : type (or is converted from it), this may be valid, so
12932 : : don't give a warning. */
12933 : 1414 : {
12934 : 1414 : tree op1 = TREE_OPERAND (inner, 1);
12935 : :
12936 : 3068 : while (!POINTER_TYPE_P (TREE_TYPE (op1))
12937 : 3313 : && (CONVERT_EXPR_P (op1)
12938 : 1409 : || TREE_CODE (op1) == NON_LVALUE_EXPR))
12939 : 245 : op1 = TREE_OPERAND (op1, 0);
12940 : :
12941 : 1414 : if (POINTER_TYPE_P (TREE_TYPE (op1)))
12942 : : break;
12943 : :
12944 : 1409 : inner = TREE_OPERAND (inner, 0);
12945 : 1409 : continue;
12946 : 1409 : }
12947 : :
12948 : 2712 : case ADDR_EXPR:
12949 : 2712 : inner = TREE_OPERAND (inner, 0);
12950 : :
12951 : 2712 : while (REFERENCE_CLASS_P (inner)
12952 : 3585 : && !INDIRECT_REF_P (inner))
12953 : 873 : inner = TREE_OPERAND (inner, 0);
12954 : :
12955 : 2712 : if (DECL_P (inner)
12956 : 1556 : && !DECL_EXTERNAL (inner)
12957 : 928 : && !TREE_STATIC (inner)
12958 : 132 : && DECL_CONTEXT (inner) == current_function_decl
12959 : 2765 : && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (current_function_decl))))
12960 : : {
12961 : 13 : if (TREE_CODE (inner) == LABEL_DECL)
12962 : 4 : warning_at (loc, OPT_Wreturn_local_addr,
12963 : : "function returns address of label");
12964 : : else
12965 : : {
12966 : 9 : warning_at (loc, OPT_Wreturn_local_addr,
12967 : : "function returns address of local variable");
12968 : 9 : tree zero = build_zero_cst (TREE_TYPE (res));
12969 : 9 : t = build2 (COMPOUND_EXPR, TREE_TYPE (res), t, zero);
12970 : : }
12971 : : }
12972 : : break;
12973 : :
12974 : : default:
12975 : : break;
12976 : 3195411 : }
12977 : :
12978 : 33722238 : break;
12979 : : }
12980 : :
12981 : 33722238 : retval = build2 (MODIFY_EXPR, TREE_TYPE (res), res, t);
12982 : 33722238 : SET_EXPR_LOCATION (retval, loc);
12983 : :
12984 : 33722238 : if (warn_sequence_point)
12985 : 2958107 : verify_sequence_points (retval);
12986 : : }
12987 : :
12988 : 33743398 : ret_stmt = build_stmt (loc, RETURN_EXPR, retval);
12989 : 33743398 : if (no_warning)
12990 : 46 : suppress_warning (ret_stmt, OPT_Wreturn_type);
12991 : 33743398 : return add_stmt (ret_stmt);
12992 : : }
12993 : :
12994 : : struct c_switch {
12995 : : /* The SWITCH_STMT being built. */
12996 : : tree switch_stmt;
12997 : :
12998 : : /* The original type of the testing expression, i.e. before the
12999 : : default conversion is applied. */
13000 : : tree orig_type;
13001 : :
13002 : : /* A splay-tree mapping the low element of a case range to the high
13003 : : element, or NULL_TREE if there is no high element. Used to
13004 : : determine whether or not a new case label duplicates an old case
13005 : : label. We need a tree, rather than simply a hash table, because
13006 : : of the GNU case range extension. */
13007 : : splay_tree cases;
13008 : :
13009 : : /* The bindings at the point of the switch. This is used for
13010 : : warnings crossing decls when branching to a case label. */
13011 : : struct c_spot_bindings *bindings;
13012 : :
13013 : : /* Whether the switch includes any break statements. */
13014 : : bool break_stmt_seen_p;
13015 : :
13016 : : /* The next node on the stack. */
13017 : : struct c_switch *next;
13018 : :
13019 : : /* Remember whether the controlling expression had boolean type
13020 : : before integer promotions for the sake of -Wswitch-bool. */
13021 : : bool bool_cond_p;
13022 : : };
13023 : :
13024 : : /* A stack of the currently active switch statements. The innermost
13025 : : switch statement is on the top of the stack. There is no need to
13026 : : mark the stack for garbage collection because it is only active
13027 : : during the processing of the body of a function, and we never
13028 : : collect at that point. */
13029 : :
13030 : : struct c_switch *c_switch_stack;
13031 : :
13032 : : /* Start a C switch statement, testing expression EXP. Return the new
13033 : : SWITCH_STMT. SWITCH_LOC is the location of the `switch'.
13034 : : SWITCH_COND_LOC is the location of the switch's condition.
13035 : : EXPLICIT_CAST_P is true if the expression EXP has an explicit cast. */
13036 : :
13037 : : tree
13038 : 36576 : c_start_switch (location_t switch_loc,
13039 : : location_t switch_cond_loc,
13040 : : tree exp, bool explicit_cast_p, tree switch_name)
13041 : : {
13042 : 36576 : tree orig_type = error_mark_node;
13043 : 36576 : bool bool_cond_p = false;
13044 : 36576 : struct c_switch *cs;
13045 : :
13046 : 36576 : if (exp != error_mark_node)
13047 : : {
13048 : 36533 : orig_type = TREE_TYPE (exp);
13049 : :
13050 : 36533 : if (!INTEGRAL_TYPE_P (orig_type))
13051 : : {
13052 : 12 : if (orig_type != error_mark_node)
13053 : : {
13054 : 12 : error_at (switch_cond_loc, "switch quantity not an integer");
13055 : 12 : orig_type = error_mark_node;
13056 : : }
13057 : 12 : exp = integer_zero_node;
13058 : : }
13059 : : else
13060 : : {
13061 : 36521 : tree type = TYPE_MAIN_VARIANT (orig_type);
13062 : 36521 : tree e = exp;
13063 : :
13064 : : /* Warn if the condition has boolean value. */
13065 : 36524 : while (TREE_CODE (e) == COMPOUND_EXPR)
13066 : 3 : e = TREE_OPERAND (e, 1);
13067 : :
13068 : 36496 : if ((C_BOOLEAN_TYPE_P (type)
13069 : 36496 : || truth_value_p (TREE_CODE (e)))
13070 : : /* Explicit cast to int suppresses this warning. */
13071 : 36543 : && !(TREE_CODE (type) == INTEGER_TYPE
13072 : : && explicit_cast_p))
13073 : : bool_cond_p = true;
13074 : :
13075 : 36521 : if (!in_system_header_at (input_location)
13076 : 36521 : && (type == long_integer_type_node
13077 : 11815 : || type == long_unsigned_type_node))
13078 : 258 : warning_at (switch_cond_loc,
13079 : 258 : OPT_Wtraditional, "%<long%> switch expression not "
13080 : : "converted to %<int%> in ISO C");
13081 : :
13082 : 36521 : exp = c_fully_fold (exp, false, NULL);
13083 : 36521 : exp = default_conversion (exp);
13084 : :
13085 : 36521 : if (warn_sequence_point)
13086 : 6001 : verify_sequence_points (exp);
13087 : : }
13088 : : }
13089 : :
13090 : : /* Add this new SWITCH_STMT to the stack. */
13091 : 36576 : cs = XNEW (struct c_switch);
13092 : 36576 : cs->switch_stmt = build_stmt (switch_loc, SWITCH_STMT, exp,
13093 : : NULL_TREE, orig_type, NULL_TREE, switch_name);
13094 : 36576 : cs->orig_type = orig_type;
13095 : 36576 : cs->cases = splay_tree_new (case_compare, NULL, NULL);
13096 : 36576 : cs->bindings = c_get_switch_bindings ();
13097 : 36576 : cs->break_stmt_seen_p = false;
13098 : 36576 : cs->bool_cond_p = bool_cond_p;
13099 : 36576 : cs->next = c_switch_stack;
13100 : 36576 : c_switch_stack = cs;
13101 : :
13102 : 36576 : return add_stmt (cs->switch_stmt);
13103 : : }
13104 : :
13105 : : /* Process a case label at location LOC, with attributes ATTRS. */
13106 : :
13107 : : tree
13108 : 1023974 : do_case (location_t loc, tree low_value, tree high_value, tree attrs)
13109 : : {
13110 : 1023974 : tree label = NULL_TREE;
13111 : :
13112 : 1023974 : if (low_value && TREE_CODE (low_value) != INTEGER_CST)
13113 : : {
13114 : 87 : low_value = c_fully_fold (low_value, false, NULL);
13115 : 87 : if (TREE_CODE (low_value) == INTEGER_CST)
13116 : 9 : pedwarn (loc, OPT_Wpedantic,
13117 : : "case label is not an integer constant expression");
13118 : : }
13119 : :
13120 : 1023974 : if (high_value && TREE_CODE (high_value) != INTEGER_CST)
13121 : : {
13122 : 0 : high_value = c_fully_fold (high_value, false, NULL);
13123 : 0 : if (TREE_CODE (high_value) == INTEGER_CST)
13124 : 0 : pedwarn (input_location, OPT_Wpedantic,
13125 : : "case label is not an integer constant expression");
13126 : : }
13127 : :
13128 : 1023974 : if (c_switch_stack == NULL)
13129 : : {
13130 : 3 : if (low_value)
13131 : 2 : error_at (loc, "case label not within a switch statement");
13132 : : else
13133 : 1 : error_at (loc, "%<default%> label not within a switch statement");
13134 : 3 : return NULL_TREE;
13135 : : }
13136 : :
13137 : 1023971 : if (c_check_switch_jump_warnings (c_switch_stack->bindings,
13138 : 1023971 : EXPR_LOCATION (c_switch_stack->switch_stmt),
13139 : : loc))
13140 : : return NULL_TREE;
13141 : :
13142 : 1023959 : label = c_add_case_label (loc, c_switch_stack->cases,
13143 : 1023959 : SWITCH_STMT_COND (c_switch_stack->switch_stmt),
13144 : : low_value, high_value, attrs);
13145 : 1023959 : if (label == error_mark_node)
13146 : 144 : label = NULL_TREE;
13147 : : return label;
13148 : : }
13149 : :
13150 : : /* Finish the switch statement. TYPE is the original type of the
13151 : : controlling expression of the switch, or NULL_TREE. */
13152 : :
13153 : : void
13154 : 36576 : c_finish_switch (tree body, tree type)
13155 : : {
13156 : 36576 : struct c_switch *cs = c_switch_stack;
13157 : 36576 : location_t switch_location;
13158 : :
13159 : 36576 : SWITCH_STMT_BODY (cs->switch_stmt) = body;
13160 : :
13161 : : /* Emit warnings as needed. */
13162 : 36576 : switch_location = EXPR_LOCATION (cs->switch_stmt);
13163 : 42657 : c_do_switch_warnings (cs->cases, switch_location,
13164 : 6081 : type ? type : SWITCH_STMT_TYPE (cs->switch_stmt),
13165 : 36576 : SWITCH_STMT_COND (cs->switch_stmt), cs->bool_cond_p);
13166 : 36576 : if (c_switch_covers_all_cases_p (cs->cases,
13167 : 36576 : SWITCH_STMT_TYPE (cs->switch_stmt)))
13168 : 32713 : SWITCH_STMT_ALL_CASES_P (cs->switch_stmt) = 1;
13169 : 36576 : SWITCH_STMT_NO_BREAK_P (cs->switch_stmt) = !cs->break_stmt_seen_p;
13170 : :
13171 : : /* Pop the stack. */
13172 : 36576 : c_switch_stack = cs->next;
13173 : 36576 : splay_tree_delete (cs->cases);
13174 : 36576 : c_release_switch_bindings (cs->bindings);
13175 : 36576 : XDELETE (cs);
13176 : 36576 : }
13177 : :
13178 : : /* Emit an if statement. IF_LOCUS is the location of the 'if'. COND,
13179 : : THEN_BLOCK and ELSE_BLOCK are expressions to be used; ELSE_BLOCK
13180 : : may be null. */
13181 : :
13182 : : void
13183 : 1244804 : c_finish_if_stmt (location_t if_locus, tree cond, tree then_block,
13184 : : tree else_block)
13185 : : {
13186 : 1244804 : tree stmt;
13187 : :
13188 : 1244804 : stmt = build3 (COND_EXPR, void_type_node, cond, then_block, else_block);
13189 : 1244804 : SET_EXPR_LOCATION (stmt, if_locus);
13190 : 1244804 : add_stmt (stmt);
13191 : 1244804 : }
13192 : :
13193 : : tree
13194 : 183278 : c_finish_bc_stmt (location_t loc, tree label, bool is_break, tree name)
13195 : : {
13196 : : /* In switch statements break is sometimes stylistically used after
13197 : : a return statement. This can lead to spurious warnings about
13198 : : control reaching the end of a non-void function when it is
13199 : : inlined. Note that we are calling block_may_fallthru with
13200 : : language specific tree nodes; this works because
13201 : : block_may_fallthru returns true when given something it does not
13202 : : understand. */
13203 : 183278 : bool skip = !block_may_fallthru (cur_stmt_list);
13204 : :
13205 : 183278 : if (is_break)
13206 : 171038 : switch (in_statement & ~IN_NAMED_STMT)
13207 : : {
13208 : 9 : case 0:
13209 : 9 : error_at (loc, "break statement not within loop or switch");
13210 : 9 : return NULL_TREE;
13211 : 4 : case IN_OMP_BLOCK:
13212 : 4 : error_at (loc, "invalid exit from OpenMP structured block");
13213 : 4 : return NULL_TREE;
13214 : 12 : case IN_OMP_FOR:
13215 : 12 : error_at (loc, "break statement used with OpenMP for loop");
13216 : 12 : return NULL_TREE;
13217 : : case IN_ITERATION_STMT:
13218 : : case IN_OBJC_FOREACH:
13219 : : break;
13220 : 155627 : default:
13221 : 155627 : gcc_assert (in_statement & IN_SWITCH_STMT);
13222 : 155627 : c_switch_stack->break_stmt_seen_p = true;
13223 : 155627 : break;
13224 : : }
13225 : : else
13226 : 12240 : switch (in_statement & ~(IN_SWITCH_STMT | IN_NAMED_STMT))
13227 : : {
13228 : 7 : case 0:
13229 : 7 : error_at (loc, "continue statement not within a loop");
13230 : 7 : return NULL_TREE;
13231 : 4 : case IN_OMP_BLOCK:
13232 : 4 : error_at (loc, "invalid exit from OpenMP structured block");
13233 : 4 : return NULL_TREE;
13234 : : case IN_ITERATION_STMT:
13235 : : case IN_OMP_FOR:
13236 : : case IN_OBJC_FOREACH:
13237 : : break;
13238 : 0 : default:
13239 : 0 : gcc_unreachable ();
13240 : : }
13241 : :
13242 : 183242 : if (skip)
13243 : : return NULL_TREE;
13244 : 182810 : else if ((in_statement & IN_OBJC_FOREACH)
13245 : 0 : && !(is_break && (in_statement & IN_SWITCH_STMT))
13246 : 0 : && name == NULL_TREE)
13247 : : {
13248 : : /* The foreach expander produces low-level code using gotos instead
13249 : : of a structured loop construct. */
13250 : 0 : gcc_assert (label);
13251 : 0 : return add_stmt (build_stmt (loc, GOTO_EXPR, label));
13252 : : }
13253 : 182907 : else if (name && C_DECL_LOOP_NAME (name) && C_DECL_SWITCH_NAME (name))
13254 : : {
13255 : 0 : label = DECL_CHAIN (name);
13256 : 0 : if (!is_break)
13257 : 0 : label = DECL_CHAIN (label);
13258 : : /* Foreach expander from some outer level. */
13259 : 0 : return add_stmt (build_stmt (loc, GOTO_EXPR, label));
13260 : : }
13261 : 195039 : return add_stmt (build_stmt (loc, is_break ? BREAK_STMT : CONTINUE_STMT,
13262 : 182810 : name));
13263 : : }
13264 : :
13265 : : /* A helper routine for c_process_expr_stmt and c_finish_stmt_expr. */
13266 : :
13267 : : static void
13268 : 6229882 : emit_side_effect_warnings (location_t loc, tree expr)
13269 : : {
13270 : 6229882 : maybe_warn_nodiscard (loc, expr);
13271 : 6229882 : if (!warn_unused_value)
13272 : : return;
13273 : 1290476 : if (expr == error_mark_node)
13274 : : ;
13275 : 1290401 : else if (!TREE_SIDE_EFFECTS (expr))
13276 : : {
13277 : 6400 : if (!VOID_TYPE_P (TREE_TYPE (expr))
13278 : 6400 : && !warning_suppressed_p (expr, OPT_Wunused_value))
13279 : 28 : warning_at (loc, OPT_Wunused_value, "statement with no effect");
13280 : : }
13281 : 1284001 : else if (TREE_CODE (expr) == COMPOUND_EXPR)
13282 : : {
13283 : : tree r = expr;
13284 : : location_t cloc = loc;
13285 : 11987 : while (TREE_CODE (r) == COMPOUND_EXPR)
13286 : : {
13287 : 6009 : if (EXPR_HAS_LOCATION (r))
13288 : 5479 : cloc = EXPR_LOCATION (r);
13289 : 6009 : r = TREE_OPERAND (r, 1);
13290 : : }
13291 : 5978 : if (!TREE_SIDE_EFFECTS (r)
13292 : 33 : && !VOID_TYPE_P (TREE_TYPE (r))
13293 : 24 : && !CONVERT_EXPR_P (r)
13294 : 24 : && !warning_suppressed_p (r, OPT_Wunused_value)
13295 : 5990 : && !warning_suppressed_p (expr, OPT_Wunused_value))
13296 : 8 : warning_at (cloc, OPT_Wunused_value,
13297 : : "right-hand operand of comma expression has no effect");
13298 : : }
13299 : : else
13300 : 1278023 : warn_if_unused_value (expr, loc);
13301 : : }
13302 : :
13303 : : /* Process an expression as if it were a complete statement. Emit
13304 : : diagnostics, but do not call ADD_STMT. LOC is the location of the
13305 : : statement. */
13306 : :
13307 : : tree
13308 : 6106730 : c_process_expr_stmt (location_t loc, tree expr)
13309 : : {
13310 : 6106730 : tree exprv;
13311 : :
13312 : 6106730 : if (!expr)
13313 : : return NULL_TREE;
13314 : :
13315 : 6102549 : expr = c_fully_fold (expr, false, NULL);
13316 : :
13317 : 6102549 : if (warn_sequence_point)
13318 : 1286354 : verify_sequence_points (expr);
13319 : :
13320 : 6102549 : if (TREE_TYPE (expr) != error_mark_node
13321 : 6100044 : && !COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (expr))
13322 : 6102549 : && TREE_CODE (TREE_TYPE (expr)) != ARRAY_TYPE)
13323 : 0 : error_at (loc, "expression statement has incomplete type");
13324 : :
13325 : : /* If we're not processing a statement expression, warn about unused values.
13326 : : Warnings for statement expressions will be emitted later, once we figure
13327 : : out which is the result. */
13328 : 6102549 : if (!STATEMENT_LIST_STMT_EXPR (cur_stmt_list)
13329 : 6102549 : && (warn_unused_value || warn_unused_result))
13330 : 6016144 : emit_side_effect_warnings (EXPR_LOC_OR_LOC (expr, loc), expr);
13331 : :
13332 : : exprv = expr;
13333 : 6140858 : while (TREE_CODE (exprv) == COMPOUND_EXPR)
13334 : 38310 : exprv = TREE_OPERAND (exprv, 1);
13335 : 6113453 : while (CONVERT_EXPR_P (exprv))
13336 : 10905 : exprv = TREE_OPERAND (exprv, 0);
13337 : 6102548 : if (DECL_P (exprv)
13338 : 6103095 : || handled_component_p (exprv)
13339 : 12185773 : || TREE_CODE (exprv) == ADDR_EXPR)
13340 : 19870 : mark_exp_read (exprv);
13341 : :
13342 : : /* If the expression is not of a type to which we cannot assign a line
13343 : : number, wrap the thing in a no-op NOP_EXPR. */
13344 : 6102548 : if (DECL_P (expr) || CONSTANT_CLASS_P (expr))
13345 : : {
13346 : 14608 : expr = build1 (NOP_EXPR, TREE_TYPE (expr), expr);
13347 : 14608 : SET_EXPR_LOCATION (expr, loc);
13348 : : }
13349 : :
13350 : : return expr;
13351 : : }
13352 : :
13353 : : /* Emit an expression as a statement. LOC is the location of the
13354 : : expression. */
13355 : :
13356 : : tree
13357 : 5817683 : c_finish_expr_stmt (location_t loc, tree expr)
13358 : : {
13359 : 5817683 : if (expr)
13360 : 5805479 : return add_stmt (c_process_expr_stmt (loc, expr));
13361 : : else
13362 : : return NULL;
13363 : : }
13364 : :
13365 : : /* Do the opposite and emit a statement as an expression. To begin,
13366 : : create a new binding level and return it. */
13367 : :
13368 : : tree
13369 : 33465 : c_begin_stmt_expr (void)
13370 : : {
13371 : 33465 : tree ret;
13372 : :
13373 : : /* We must force a BLOCK for this level so that, if it is not expanded
13374 : : later, there is a way to turn off the entire subtree of blocks that
13375 : : are contained in it. */
13376 : 33465 : keep_next_level ();
13377 : 33465 : ret = c_begin_compound_stmt (true);
13378 : :
13379 : 33465 : c_bindings_start_stmt_expr (c_switch_stack == NULL
13380 : : ? NULL
13381 : : : c_switch_stack->bindings);
13382 : :
13383 : : /* Mark the current statement list as belonging to a statement list. */
13384 : 33465 : STATEMENT_LIST_STMT_EXPR (ret) = 1;
13385 : :
13386 : 33465 : return ret;
13387 : : }
13388 : :
13389 : : /* LOC is the location of the compound statement to which this body
13390 : : belongs. */
13391 : :
13392 : : tree
13393 : 33465 : c_finish_stmt_expr (location_t loc, tree body)
13394 : : {
13395 : 33465 : tree last, type, tmp, val;
13396 : 33465 : tree *last_p;
13397 : :
13398 : 33465 : body = c_end_compound_stmt (loc, body, true);
13399 : :
13400 : 33465 : c_bindings_end_stmt_expr (c_switch_stack == NULL
13401 : : ? NULL
13402 : : : c_switch_stack->bindings);
13403 : :
13404 : : /* Locate the last statement in BODY. See c_end_compound_stmt
13405 : : about always returning a BIND_EXPR. */
13406 : 33465 : last_p = &BIND_EXPR_BODY (body);
13407 : 33465 : last = BIND_EXPR_BODY (body);
13408 : :
13409 : 33465 : continue_searching:
13410 : 33465 : if (TREE_CODE (last) == STATEMENT_LIST)
13411 : : {
13412 : 25753 : tree_stmt_iterator l = tsi_last (last);
13413 : :
13414 : 25759 : while (!tsi_end_p (l) && TREE_CODE (tsi_stmt (l)) == DEBUG_BEGIN_STMT)
13415 : 6 : tsi_prev (&l);
13416 : :
13417 : : /* This can happen with degenerate cases like ({ }). No value. */
13418 : 25753 : if (tsi_end_p (l))
13419 : 389 : return body;
13420 : :
13421 : : /* If we're supposed to generate side effects warnings, process
13422 : : all of the statements except the last. */
13423 : 25364 : if (warn_unused_value || warn_unused_result)
13424 : : {
13425 : 25364 : for (tree_stmt_iterator i = tsi_start (last);
13426 : 274934 : tsi_stmt (i) != tsi_stmt (l); tsi_next (&i))
13427 : : {
13428 : 249570 : location_t tloc;
13429 : 249570 : tree t = tsi_stmt (i);
13430 : :
13431 : 249570 : tloc = EXPR_HAS_LOCATION (t) ? EXPR_LOCATION (t) : loc;
13432 : 249570 : emit_side_effect_warnings (tloc, t);
13433 : : }
13434 : : }
13435 : 25364 : last_p = tsi_stmt_ptr (l);
13436 : 25364 : last = *last_p;
13437 : : }
13438 : :
13439 : : /* If the end of the list is exception related, then the list was split
13440 : : by a call to push_cleanup. Continue searching. */
13441 : 33076 : if (TREE_CODE (last) == TRY_FINALLY_EXPR
13442 : 33076 : || TREE_CODE (last) == TRY_CATCH_EXPR)
13443 : : {
13444 : 0 : last_p = &TREE_OPERAND (last, 0);
13445 : 0 : last = *last_p;
13446 : 0 : goto continue_searching;
13447 : : }
13448 : :
13449 : 33076 : if (last == error_mark_node)
13450 : : return last;
13451 : :
13452 : : /* In the case that the BIND_EXPR is not necessary, return the
13453 : : expression out from inside it. */
13454 : 33067 : if ((last == BIND_EXPR_BODY (body)
13455 : : /* Skip nested debug stmts. */
13456 : 25363 : || last == expr_first (BIND_EXPR_BODY (body)))
13457 : 42736 : && BIND_EXPR_VARS (body) == NULL)
13458 : : {
13459 : : /* Even if this looks constant, do not allow it in a constant
13460 : : expression. */
13461 : 9657 : last = c_wrap_maybe_const (last, true);
13462 : : /* Do not warn if the return value of a statement expression is
13463 : : unused. */
13464 : 9657 : suppress_warning (last, OPT_Wunused);
13465 : 9657 : return last;
13466 : : }
13467 : :
13468 : : /* Extract the type of said expression. */
13469 : 23410 : type = TREE_TYPE (last);
13470 : :
13471 : : /* If we're not returning a value at all, then the BIND_EXPR that
13472 : : we already have is a fine expression to return. */
13473 : 23410 : if (!type || VOID_TYPE_P (type))
13474 : : return body;
13475 : :
13476 : : /* Now that we've located the expression containing the value, it seems
13477 : : silly to make voidify_wrapper_expr repeat the process. Create a
13478 : : temporary of the appropriate type and stick it in a TARGET_EXPR. */
13479 : 18102 : tmp = create_tmp_var_raw (type);
13480 : :
13481 : : /* Unwrap a no-op NOP_EXPR as added by c_finish_expr_stmt. This avoids
13482 : : tree_expr_nonnegative_p giving up immediately. */
13483 : 18102 : val = last;
13484 : 18102 : if (TREE_CODE (val) == NOP_EXPR
13485 : 18102 : && TREE_TYPE (val) == TREE_TYPE (TREE_OPERAND (val, 0)))
13486 : 3728 : val = TREE_OPERAND (val, 0);
13487 : :
13488 : 18102 : *last_p = build2 (MODIFY_EXPR, void_type_node, tmp, val);
13489 : 18102 : SET_EXPR_LOCATION (*last_p, EXPR_LOCATION (last));
13490 : :
13491 : 18102 : {
13492 : 18102 : tree t = build4 (TARGET_EXPR, type, tmp, body, NULL_TREE, NULL_TREE);
13493 : 18102 : SET_EXPR_LOCATION (t, loc);
13494 : 18102 : return t;
13495 : : }
13496 : : }
13497 : :
13498 : : /* Begin and end compound statements. This is as simple as pushing
13499 : : and popping new statement lists from the tree. */
13500 : :
13501 : : tree
13502 : 40108620 : c_begin_compound_stmt (bool do_scope)
13503 : : {
13504 : 40108620 : tree stmt = push_stmt_list ();
13505 : 40108620 : if (do_scope)
13506 : 40012689 : push_scope ();
13507 : 40108620 : return stmt;
13508 : : }
13509 : :
13510 : : /* End a compound statement. STMT is the statement. LOC is the
13511 : : location of the compound statement-- this is usually the location
13512 : : of the opening brace. */
13513 : :
13514 : : tree
13515 : 40108619 : c_end_compound_stmt (location_t loc, tree stmt, bool do_scope)
13516 : : {
13517 : 40108619 : tree block = NULL;
13518 : :
13519 : 40108619 : if (do_scope)
13520 : : {
13521 : 40012688 : if (c_dialect_objc ())
13522 : 0 : objc_clear_super_receiver ();
13523 : 40012688 : block = pop_scope ();
13524 : : }
13525 : :
13526 : 40108619 : stmt = pop_stmt_list (stmt);
13527 : 40108619 : stmt = c_build_bind_expr (loc, block, stmt);
13528 : :
13529 : : /* If this compound statement is nested immediately inside a statement
13530 : : expression, then force a BIND_EXPR to be created. Otherwise we'll
13531 : : do the wrong thing for ({ { 1; } }) or ({ 1; { } }). In particular,
13532 : : STATEMENT_LISTs merge, and thus we can lose track of what statement
13533 : : was really last. */
13534 : 80217238 : if (building_stmt_list_p ()
13535 : 40108534 : && STATEMENT_LIST_STMT_EXPR (cur_stmt_list)
13536 : 40229893 : && TREE_CODE (stmt) != BIND_EXPR)
13537 : : {
13538 : 119534 : stmt = build3 (BIND_EXPR, void_type_node, NULL, stmt, NULL);
13539 : 119534 : TREE_SIDE_EFFECTS (stmt) = 1;
13540 : 119534 : SET_EXPR_LOCATION (stmt, loc);
13541 : : }
13542 : :
13543 : 40108619 : return stmt;
13544 : : }
13545 : :
13546 : : /* Queue a cleanup. CLEANUP is an expression/statement to be executed
13547 : : when the current scope is exited. EH_ONLY is true when this is not
13548 : : meant to apply to normal control flow transfer. */
13549 : :
13550 : : void
13551 : 95 : push_cleanup (tree decl, tree cleanup, bool eh_only)
13552 : : {
13553 : 95 : enum tree_code code;
13554 : 95 : tree stmt, list;
13555 : 95 : bool stmt_expr;
13556 : :
13557 : 95 : code = eh_only ? TRY_CATCH_EXPR : TRY_FINALLY_EXPR;
13558 : 95 : stmt = build_stmt (DECL_SOURCE_LOCATION (decl), code, NULL, cleanup);
13559 : 95 : add_stmt (stmt);
13560 : 95 : stmt_expr = STATEMENT_LIST_STMT_EXPR (cur_stmt_list);
13561 : 95 : list = push_stmt_list ();
13562 : 95 : TREE_OPERAND (stmt, 0) = list;
13563 : 95 : STATEMENT_LIST_STMT_EXPR (list) = stmt_expr;
13564 : 95 : }
13565 : :
13566 : : /* Build a vector comparison of ARG0 and ARG1 using CODE opcode
13567 : : into a value of TYPE type. Comparison is done via VEC_COND_EXPR. */
13568 : :
13569 : : static tree
13570 : 98663 : build_vec_cmp (tree_code code, tree type,
13571 : : tree arg0, tree arg1)
13572 : : {
13573 : 98663 : tree zero_vec = build_zero_cst (type);
13574 : 98663 : tree minus_one_vec = build_minus_one_cst (type);
13575 : 98663 : tree cmp_type = truth_type_for (TREE_TYPE (arg0));
13576 : 98663 : tree cmp = build2 (code, cmp_type, arg0, arg1);
13577 : 98663 : return build3 (VEC_COND_EXPR, type, cmp, minus_one_vec, zero_vec);
13578 : : }
13579 : :
13580 : : /* Possibly warn about an address of OP never being NULL in a comparison
13581 : : operation CODE involving null. */
13582 : :
13583 : : static void
13584 : 50245 : maybe_warn_for_null_address (location_t loc, tree op, tree_code code)
13585 : : {
13586 : : /* Prevent warnings issued for macro expansion. */
13587 : 50245 : if (!warn_address
13588 : 29769 : || warning_suppressed_p (op, OPT_Waddress)
13589 : 79690 : || from_macro_expansion_at (loc))
13590 : 23531 : return;
13591 : :
13592 : 26714 : if (TREE_CODE (op) == NOP_EXPR)
13593 : : {
13594 : : /* Allow casts to intptr_t to suppress the warning. */
13595 : 1133 : tree type = TREE_TYPE (op);
13596 : 1133 : if (TREE_CODE (type) == INTEGER_TYPE)
13597 : : return;
13598 : 1133 : op = TREE_OPERAND (op, 0);
13599 : : }
13600 : :
13601 : 26714 : if (TREE_CODE (op) == POINTER_PLUS_EXPR)
13602 : : {
13603 : : /* Allow a cast to void* to suppress the warning. */
13604 : 24 : tree type = TREE_TYPE (TREE_TYPE (op));
13605 : 24 : if (VOID_TYPE_P (type))
13606 : : return;
13607 : :
13608 : : /* Adding any value to a null pointer, including zero, is undefined
13609 : : in C. This includes the expression &p[0] where p is the null
13610 : : pointer, although &p[0] will have been folded to p by this point
13611 : : and so not diagnosed. */
13612 : 24 : if (code == EQ_EXPR)
13613 : 22 : warning_at (loc, OPT_Waddress,
13614 : : "the comparison will always evaluate as %<false%> "
13615 : : "for the pointer operand in %qE must not be NULL",
13616 : : op);
13617 : : else
13618 : 2 : warning_at (loc, OPT_Waddress,
13619 : : "the comparison will always evaluate as %<true%> "
13620 : : "for the pointer operand in %qE must not be NULL",
13621 : : op);
13622 : :
13623 : 24 : return;
13624 : : }
13625 : :
13626 : 26690 : if (TREE_CODE (op) != ADDR_EXPR)
13627 : : return;
13628 : :
13629 : 254 : op = TREE_OPERAND (op, 0);
13630 : :
13631 : 254 : if (TREE_CODE (op) == IMAGPART_EXPR
13632 : 254 : || TREE_CODE (op) == REALPART_EXPR)
13633 : : {
13634 : : /* The address of either complex part may not be null. */
13635 : 14 : if (code == EQ_EXPR)
13636 : 9 : warning_at (loc, OPT_Waddress,
13637 : : "the comparison will always evaluate as %<false%> "
13638 : : "for the address of %qE will never be NULL",
13639 : : op);
13640 : : else
13641 : 5 : warning_at (loc, OPT_Waddress,
13642 : : "the comparison will always evaluate as %<true%> "
13643 : : "for the address of %qE will never be NULL",
13644 : : op);
13645 : 14 : return;
13646 : : }
13647 : :
13648 : : /* Set to true in the loop below if OP dereferences is operand.
13649 : : In such a case the ultimate target need not be a decl for
13650 : : the null [in]equality test to be constant. */
13651 : : bool deref = false;
13652 : :
13653 : : /* Get the outermost array or object, or member. */
13654 : 294 : while (handled_component_p (op))
13655 : : {
13656 : 72 : if (TREE_CODE (op) == COMPONENT_REF)
13657 : : {
13658 : : /* Get the member (its address is never null). */
13659 : 18 : op = TREE_OPERAND (op, 1);
13660 : 18 : break;
13661 : : }
13662 : :
13663 : : /* Get the outer array/object to refer to in the warning. */
13664 : 54 : op = TREE_OPERAND (op, 0);
13665 : 54 : deref = true;
13666 : : }
13667 : :
13668 : 192 : if ((!deref && !decl_with_nonnull_addr_p (op))
13669 : 371 : || from_macro_expansion_at (loc))
13670 : 109 : return;
13671 : :
13672 : 131 : bool w;
13673 : 131 : if (code == EQ_EXPR)
13674 : 93 : w = warning_at (loc, OPT_Waddress,
13675 : : "the comparison will always evaluate as %<false%> "
13676 : : "for the address of %qE will never be NULL",
13677 : : op);
13678 : : else
13679 : 38 : w = warning_at (loc, OPT_Waddress,
13680 : : "the comparison will always evaluate as %<true%> "
13681 : : "for the address of %qE will never be NULL",
13682 : : op);
13683 : :
13684 : 131 : if (w && DECL_P (op))
13685 : 120 : inform (DECL_SOURCE_LOCATION (op), "%qD declared here", op);
13686 : : }
13687 : :
13688 : : /* Build a binary-operation expression without default conversions.
13689 : : CODE is the kind of expression to build.
13690 : : LOCATION is the operator's location.
13691 : : This function differs from `build' in several ways:
13692 : : the data type of the result is computed and recorded in it,
13693 : : warnings are generated if arg data types are invalid,
13694 : : special handling for addition and subtraction of pointers is known,
13695 : : and some optimization is done (operations on narrow ints
13696 : : are done in the narrower type when that gives the same result).
13697 : : Constant folding is also done before the result is returned.
13698 : :
13699 : : Note that the operands will never have enumeral types, or function
13700 : : or array types, because either they will have the default conversions
13701 : : performed or they have both just been converted to some other type in which
13702 : : the arithmetic is to be done. */
13703 : :
13704 : : tree
13705 : 16413433 : build_binary_op (location_t location, enum tree_code code,
13706 : : tree orig_op0, tree orig_op1, bool convert_p)
13707 : : {
13708 : 16413433 : tree type0, type1, orig_type0, orig_type1;
13709 : 16413433 : tree eptype;
13710 : 16413433 : enum tree_code code0, code1;
13711 : 16413433 : tree op0, op1;
13712 : 16413433 : tree ret = error_mark_node;
13713 : 16413433 : const char *invalid_op_diag;
13714 : 16413433 : bool op0_int_operands, op1_int_operands;
13715 : 16413433 : bool int_const, int_const_or_overflow, int_operands;
13716 : :
13717 : : /* Expression code to give to the expression when it is built.
13718 : : Normally this is CODE, which is what the caller asked for,
13719 : : but in some special cases we change it. */
13720 : 16413433 : enum tree_code resultcode = code;
13721 : :
13722 : : /* Data type in which the computation is to be performed.
13723 : : In the simplest cases this is the common type of the arguments. */
13724 : 16413433 : tree result_type = NULL;
13725 : :
13726 : : /* When the computation is in excess precision, the type of the
13727 : : final EXCESS_PRECISION_EXPR. */
13728 : 16413433 : tree semantic_result_type = NULL;
13729 : :
13730 : : /* Nonzero means operands have already been type-converted
13731 : : in whatever way is necessary.
13732 : : Zero means they need to be converted to RESULT_TYPE. */
13733 : 16413433 : int converted = 0;
13734 : :
13735 : : /* Nonzero means create the expression with this type, rather than
13736 : : RESULT_TYPE. */
13737 : 16413433 : tree build_type = NULL_TREE;
13738 : :
13739 : : /* Nonzero means after finally constructing the expression
13740 : : convert it to this type. */
13741 : 16413433 : tree final_type = NULL_TREE;
13742 : :
13743 : : /* Nonzero if this is an operation like MIN or MAX which can
13744 : : safely be computed in short if both args are promoted shorts.
13745 : : Also implies COMMON.
13746 : : -1 indicates a bitwise operation; this makes a difference
13747 : : in the exact conditions for when it is safe to do the operation
13748 : : in a narrower mode. */
13749 : 16413433 : int shorten = 0;
13750 : :
13751 : : /* Nonzero if this is a comparison operation;
13752 : : if both args are promoted shorts, compare the original shorts.
13753 : : Also implies COMMON. */
13754 : 16413433 : int short_compare = 0;
13755 : :
13756 : : /* Nonzero if this is a right-shift operation, which can be computed on the
13757 : : original short and then promoted if the operand is a promoted short. */
13758 : 16413433 : int short_shift = 0;
13759 : :
13760 : : /* Nonzero means set RESULT_TYPE to the common type of the args. */
13761 : 16413433 : int common = 0;
13762 : :
13763 : : /* True means types are compatible as far as ObjC is concerned. */
13764 : 16413433 : bool objc_ok;
13765 : :
13766 : : /* True means this is an arithmetic operation that may need excess
13767 : : precision. */
13768 : 16413433 : bool may_need_excess_precision;
13769 : :
13770 : : /* True means this is a boolean operation that converts both its
13771 : : operands to truth-values. */
13772 : 16413433 : bool boolean_op = false;
13773 : :
13774 : : /* Remember whether we're doing / or %. */
13775 : 16413433 : bool doing_div_or_mod = false;
13776 : :
13777 : : /* Remember whether we're doing << or >>. */
13778 : 16413433 : bool doing_shift = false;
13779 : :
13780 : : /* Tree holding instrumentation expression. */
13781 : 16413433 : tree instrument_expr = NULL;
13782 : :
13783 : 16413433 : if (location == UNKNOWN_LOCATION)
13784 : 79 : location = input_location;
13785 : :
13786 : 16413433 : op0 = orig_op0;
13787 : 16413433 : op1 = orig_op1;
13788 : :
13789 : 16413433 : op0_int_operands = EXPR_INT_CONST_OPERANDS (orig_op0);
13790 : 7923793 : if (op0_int_operands)
13791 : 7923793 : op0 = remove_c_maybe_const_expr (op0);
13792 : 16413433 : op1_int_operands = EXPR_INT_CONST_OPERANDS (orig_op1);
13793 : 11116728 : if (op1_int_operands)
13794 : 11116728 : op1 = remove_c_maybe_const_expr (op1);
13795 : 27530161 : int_operands = (op0_int_operands && op1_int_operands);
13796 : 11116728 : if (int_operands)
13797 : : {
13798 : 15501699 : int_const_or_overflow = (TREE_CODE (orig_op0) == INTEGER_CST
13799 : 7766016 : && TREE_CODE (orig_op1) == INTEGER_CST);
13800 : 7735683 : int_const = (int_const_or_overflow
13801 : 7735683 : && !TREE_OVERFLOW (orig_op0)
13802 : 7735614 : && !TREE_OVERFLOW (orig_op1));
13803 : : }
13804 : : else
13805 : : int_const = int_const_or_overflow = false;
13806 : :
13807 : : /* Do not apply default conversion in mixed vector/scalar expression. */
13808 : 16413433 : if (convert_p
13809 : 16413433 : && VECTOR_TYPE_P (TREE_TYPE (op0)) == VECTOR_TYPE_P (TREE_TYPE (op1)))
13810 : : {
13811 : 9916337 : op0 = default_conversion (op0);
13812 : 9916337 : op1 = default_conversion (op1);
13813 : : }
13814 : :
13815 : 16413433 : orig_type0 = type0 = TREE_TYPE (op0);
13816 : :
13817 : 16413433 : orig_type1 = type1 = TREE_TYPE (op1);
13818 : :
13819 : : /* The expression codes of the data types of the arguments tell us
13820 : : whether the arguments are integers, floating, pointers, etc. */
13821 : 16413433 : code0 = TREE_CODE (type0);
13822 : 16413433 : code1 = TREE_CODE (type1);
13823 : :
13824 : : /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
13825 : 16413435 : STRIP_TYPE_NOPS (op0);
13826 : 16413436 : STRIP_TYPE_NOPS (op1);
13827 : :
13828 : : /* If an error was already reported for one of the arguments,
13829 : : avoid reporting another error. */
13830 : :
13831 : 16413433 : if (code0 == ERROR_MARK || code1 == ERROR_MARK)
13832 : 708 : return error_mark_node;
13833 : :
13834 : 16412725 : if (code0 == POINTER_TYPE
13835 : 16412725 : && reject_gcc_builtin (op0, EXPR_LOCATION (orig_op0)))
13836 : 11 : return error_mark_node;
13837 : :
13838 : 16412714 : if (code1 == POINTER_TYPE
13839 : 16412714 : && reject_gcc_builtin (op1, EXPR_LOCATION (orig_op1)))
13840 : 11 : return error_mark_node;
13841 : :
13842 : 32825406 : if ((invalid_op_diag
13843 : 16412703 : = targetm.invalid_binary_op (code, type0, type1)))
13844 : : {
13845 : 0 : error_at (location, invalid_op_diag);
13846 : 0 : return error_mark_node;
13847 : : }
13848 : :
13849 : 16412703 : switch (code)
13850 : : {
13851 : : case PLUS_EXPR:
13852 : : case MINUS_EXPR:
13853 : : case MULT_EXPR:
13854 : : case TRUNC_DIV_EXPR:
13855 : : case CEIL_DIV_EXPR:
13856 : : case FLOOR_DIV_EXPR:
13857 : : case ROUND_DIV_EXPR:
13858 : : case EXACT_DIV_EXPR:
13859 : : may_need_excess_precision = true;
13860 : : break;
13861 : :
13862 : 2670799 : case EQ_EXPR:
13863 : 2670799 : case NE_EXPR:
13864 : 2670799 : case LE_EXPR:
13865 : 2670799 : case GE_EXPR:
13866 : 2670799 : case LT_EXPR:
13867 : 2670799 : case GT_EXPR:
13868 : : /* Excess precision for implicit conversions of integers to
13869 : : floating point in C11 and later. */
13870 : 2670799 : may_need_excess_precision = (flag_isoc11
13871 : 2670799 : && (ANY_INTEGRAL_TYPE_P (type0)
13872 : 470400 : || ANY_INTEGRAL_TYPE_P (type1)));
13873 : : break;
13874 : :
13875 : : default:
13876 : 16412703 : may_need_excess_precision = false;
13877 : : break;
13878 : : }
13879 : 16412703 : if (TREE_CODE (op0) == EXCESS_PRECISION_EXPR)
13880 : : {
13881 : 184 : op0 = TREE_OPERAND (op0, 0);
13882 : 184 : type0 = TREE_TYPE (op0);
13883 : : }
13884 : 16412519 : else if (may_need_excess_precision
13885 : 16412519 : && (eptype = excess_precision_type (type0)) != NULL_TREE)
13886 : : {
13887 : 771 : type0 = eptype;
13888 : 771 : op0 = convert (eptype, op0);
13889 : : }
13890 : 16412703 : if (TREE_CODE (op1) == EXCESS_PRECISION_EXPR)
13891 : : {
13892 : 887 : op1 = TREE_OPERAND (op1, 0);
13893 : 887 : type1 = TREE_TYPE (op1);
13894 : : }
13895 : 16411816 : else if (may_need_excess_precision
13896 : 16411816 : && (eptype = excess_precision_type (type1)) != NULL_TREE)
13897 : : {
13898 : 592 : type1 = eptype;
13899 : 592 : op1 = convert (eptype, op1);
13900 : : }
13901 : :
13902 : 16412703 : objc_ok = objc_compare_types (type0, type1, -3, NULL_TREE);
13903 : :
13904 : : /* In case when one of the operands of the binary operation is
13905 : : a vector and another is a scalar -- convert scalar to vector. */
13906 : 17954027 : if ((gnu_vector_type_p (type0) && code1 != VECTOR_TYPE)
13907 : 17952210 : || (gnu_vector_type_p (type1) && code0 != VECTOR_TYPE))
13908 : : {
13909 : 2413 : enum stv_conv convert_flag = scalar_to_vector (location, code, orig_op0,
13910 : : orig_op1, true);
13911 : :
13912 : 2413 : switch (convert_flag)
13913 : : {
13914 : 12 : case stv_error:
13915 : 12 : return error_mark_node;
13916 : 583 : case stv_firstarg:
13917 : 583 : {
13918 : 583 : bool maybe_const = true;
13919 : 583 : tree sc;
13920 : 583 : sc = c_fully_fold (op0, false, &maybe_const);
13921 : 583 : sc = save_expr (sc);
13922 : 583 : sc = convert (TREE_TYPE (type1), sc);
13923 : 583 : op0 = build_vector_from_val (type1, sc);
13924 : 583 : if (!maybe_const)
13925 : 93 : op0 = c_wrap_maybe_const (op0, true);
13926 : 583 : orig_type0 = type0 = TREE_TYPE (op0);
13927 : 583 : code0 = TREE_CODE (type0);
13928 : 583 : converted = 1;
13929 : 583 : break;
13930 : : }
13931 : 998 : case stv_secondarg:
13932 : 998 : {
13933 : 998 : bool maybe_const = true;
13934 : 998 : tree sc;
13935 : 998 : sc = c_fully_fold (op1, false, &maybe_const);
13936 : 998 : sc = save_expr (sc);
13937 : 998 : sc = convert (TREE_TYPE (type0), sc);
13938 : 998 : op1 = build_vector_from_val (type0, sc);
13939 : 998 : if (!maybe_const)
13940 : 36 : op1 = c_wrap_maybe_const (op1, true);
13941 : 998 : orig_type1 = type1 = TREE_TYPE (op1);
13942 : 998 : code1 = TREE_CODE (type1);
13943 : 998 : converted = 1;
13944 : 998 : break;
13945 : : }
13946 : : default:
13947 : : break;
13948 : : }
13949 : : }
13950 : :
13951 : 16412691 : switch (code)
13952 : : {
13953 : 8400182 : case PLUS_EXPR:
13954 : : /* Handle the pointer + int case. */
13955 : 8400182 : if (code0 == POINTER_TYPE
13956 : 1216935 : && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
13957 : : {
13958 : 1216929 : ret = pointer_int_sum (location, PLUS_EXPR, op0, op1);
13959 : 1216929 : goto return_build_binary_op;
13960 : : }
13961 : 7183253 : else if (code1 == POINTER_TYPE
13962 : 1530 : && (code0 == INTEGER_TYPE || code0 == BITINT_TYPE))
13963 : : {
13964 : 1524 : ret = pointer_int_sum (location, PLUS_EXPR, op1, op0);
13965 : 1524 : goto return_build_binary_op;
13966 : : }
13967 : : else
13968 : : common = 1;
13969 : : break;
13970 : :
13971 : 780325 : case MINUS_EXPR:
13972 : : /* Subtraction of two similar pointers.
13973 : : We must subtract them as integers, then divide by object size. */
13974 : 780325 : if (code0 == POINTER_TYPE && code1 == POINTER_TYPE
13975 : 780325 : && comp_target_types (location, type0, type1))
13976 : : {
13977 : 3607 : ret = pointer_diff (location, op0, op1, &instrument_expr);
13978 : 3607 : goto return_build_binary_op;
13979 : : }
13980 : : /* Handle pointer minus int. Just like pointer plus int. */
13981 : 776718 : else if (code0 == POINTER_TYPE
13982 : 16659 : && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
13983 : : {
13984 : 16647 : ret = pointer_int_sum (location, MINUS_EXPR, op0, op1);
13985 : 16647 : goto return_build_binary_op;
13986 : : }
13987 : : else
13988 : : common = 1;
13989 : : break;
13990 : :
13991 : : case MULT_EXPR:
13992 : : common = 1;
13993 : : break;
13994 : :
13995 : 262844 : case TRUNC_DIV_EXPR:
13996 : 262844 : case CEIL_DIV_EXPR:
13997 : 262844 : case FLOOR_DIV_EXPR:
13998 : 262844 : case ROUND_DIV_EXPR:
13999 : 262844 : case EXACT_DIV_EXPR:
14000 : 262844 : doing_div_or_mod = true;
14001 : 262844 : warn_for_div_by_zero (location, op1);
14002 : :
14003 : 262843 : if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
14004 : 48520 : || code0 == FIXED_POINT_TYPE || code0 == BITINT_TYPE
14005 : 46542 : || code0 == COMPLEX_TYPE
14006 : 44494 : || gnu_vector_type_p (type0))
14007 : 311362 : && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
14008 : 46094 : || code1 == FIXED_POINT_TYPE || code1 == BITINT_TYPE
14009 : 45955 : || code1 == COMPLEX_TYPE
14010 : 44496 : || gnu_vector_type_p (type1)))
14011 : : {
14012 : 262839 : enum tree_code tcode0 = code0, tcode1 = code1;
14013 : :
14014 : 262839 : if (code0 == COMPLEX_TYPE || code0 == VECTOR_TYPE)
14015 : 46541 : tcode0 = TREE_CODE (TREE_TYPE (TREE_TYPE (op0)));
14016 : 262839 : if (code1 == COMPLEX_TYPE || code1 == VECTOR_TYPE)
14017 : 45952 : tcode1 = TREE_CODE (TREE_TYPE (TREE_TYPE (op1)));
14018 : :
14019 : 262839 : if (!(((tcode0 == INTEGER_TYPE || tcode0 == BITINT_TYPE)
14020 : 195106 : && (tcode1 == INTEGER_TYPE || tcode1 == BITINT_TYPE))
14021 : 79762 : || (tcode0 == FIXED_POINT_TYPE && tcode1 == FIXED_POINT_TYPE)))
14022 : : resultcode = RDIV_EXPR;
14023 : : else
14024 : : /* Although it would be tempting to shorten always here, that
14025 : : loses on some targets, since the modulo instruction is
14026 : : undefined if the quotient can't be represented in the
14027 : : computation mode. We shorten only if unsigned or if
14028 : : dividing by something we know != -1. */
14029 : 183077 : shorten = may_shorten_divmod (op0, op1);
14030 : : common = 1;
14031 : : }
14032 : : break;
14033 : :
14034 : 1538321 : case BIT_AND_EXPR:
14035 : 1538321 : case BIT_IOR_EXPR:
14036 : 1538321 : case BIT_XOR_EXPR:
14037 : 1538321 : if ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE)
14038 : 1016014 : && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
14039 : : shorten = -1;
14040 : : /* Allow vector types which are not floating point types. */
14041 : 522343 : else if (gnu_vector_type_p (type0)
14042 : 522266 : && gnu_vector_type_p (type1)
14043 : 522266 : && !VECTOR_FLOAT_TYPE_P (type0)
14044 : 1044606 : && !VECTOR_FLOAT_TYPE_P (type1))
14045 : : common = 1;
14046 : : break;
14047 : :
14048 : 56455 : case TRUNC_MOD_EXPR:
14049 : 56455 : case FLOOR_MOD_EXPR:
14050 : 56455 : doing_div_or_mod = true;
14051 : 56455 : warn_for_div_by_zero (location, op1);
14052 : :
14053 : 56455 : if (gnu_vector_type_p (type0)
14054 : 297 : && gnu_vector_type_p (type1)
14055 : 297 : && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
14056 : 56752 : && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE)
14057 : : common = 1;
14058 : 56158 : else if ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE)
14059 : 56157 : && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
14060 : : {
14061 : : /* Although it would be tempting to shorten always here, that loses
14062 : : on some targets, since the modulo instruction is undefined if the
14063 : : quotient can't be represented in the computation mode. We shorten
14064 : : only if unsigned or if dividing by something we know != -1. */
14065 : 56157 : shorten = may_shorten_divmod (op0, op1);
14066 : 56157 : common = 1;
14067 : : }
14068 : : break;
14069 : :
14070 : 502164 : case TRUTH_ANDIF_EXPR:
14071 : 502164 : case TRUTH_ORIF_EXPR:
14072 : 502164 : case TRUTH_AND_EXPR:
14073 : 502164 : case TRUTH_OR_EXPR:
14074 : 502164 : case TRUTH_XOR_EXPR:
14075 : 502164 : if ((code0 == INTEGER_TYPE || code0 == POINTER_TYPE
14076 : 0 : || code0 == REAL_TYPE || code0 == COMPLEX_TYPE
14077 : 0 : || code0 == FIXED_POINT_TYPE || code0 == NULLPTR_TYPE
14078 : 0 : || code0 == BITINT_TYPE)
14079 : 502164 : && (code1 == INTEGER_TYPE || code1 == POINTER_TYPE
14080 : 159 : || code1 == REAL_TYPE || code1 == COMPLEX_TYPE
14081 : 20 : || code1 == FIXED_POINT_TYPE || code1 == NULLPTR_TYPE
14082 : 18 : || code1 == BITINT_TYPE))
14083 : : {
14084 : : /* Result of these operations is always an int,
14085 : : but that does not mean the operands should be
14086 : : converted to ints! */
14087 : 502164 : result_type = integer_type_node;
14088 : 502164 : if (op0_int_operands)
14089 : : {
14090 : 110628 : op0 = c_objc_common_truthvalue_conversion (location, orig_op0);
14091 : 110628 : op0 = remove_c_maybe_const_expr (op0);
14092 : : }
14093 : : else
14094 : 391536 : op0 = c_objc_common_truthvalue_conversion (location, op0);
14095 : 502164 : if (op1_int_operands)
14096 : : {
14097 : 72137 : op1 = c_objc_common_truthvalue_conversion (location, orig_op1);
14098 : 72137 : op1 = remove_c_maybe_const_expr (op1);
14099 : : }
14100 : : else
14101 : 430027 : op1 = c_objc_common_truthvalue_conversion (location, op1);
14102 : : converted = 1;
14103 : : boolean_op = true;
14104 : : }
14105 : 502164 : if (code == TRUTH_ANDIF_EXPR)
14106 : : {
14107 : 245040 : int_const_or_overflow = (int_operands
14108 : 64014 : && TREE_CODE (orig_op0) == INTEGER_CST
14109 : 245056 : && (op0 == truthvalue_false_node
14110 : 13752 : || TREE_CODE (orig_op1) == INTEGER_CST));
14111 : : int_const = (int_const_or_overflow
14112 : 63987 : && !TREE_OVERFLOW (orig_op0)
14113 : 63987 : && (op0 == truthvalue_false_node
14114 : 13736 : || !TREE_OVERFLOW (orig_op1)));
14115 : : }
14116 : 321111 : else if (code == TRUTH_ORIF_EXPR)
14117 : : {
14118 : 327776 : int_const_or_overflow = (int_operands
14119 : 6816 : && TREE_CODE (orig_op0) == INTEGER_CST
14120 : 327799 : && (op0 == truthvalue_true_node
14121 : 2133 : || TREE_CODE (orig_op1) == INTEGER_CST));
14122 : : int_const = (int_const_or_overflow
14123 : 6786 : && !TREE_OVERFLOW (orig_op0)
14124 : 6786 : && (op0 == truthvalue_true_node
14125 : 2110 : || !TREE_OVERFLOW (orig_op1)));
14126 : : }
14127 : : break;
14128 : :
14129 : : /* Shift operations: result has same type as first operand;
14130 : : always convert second operand to int.
14131 : : Also set SHORT_SHIFT if shifting rightward. */
14132 : :
14133 : 226259 : case RSHIFT_EXPR:
14134 : 226259 : if (gnu_vector_type_p (type0)
14135 : 793 : && gnu_vector_type_p (type1)
14136 : 257 : && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
14137 : 255 : && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE
14138 : 226514 : && known_eq (TYPE_VECTOR_SUBPARTS (type0),
14139 : : TYPE_VECTOR_SUBPARTS (type1)))
14140 : : {
14141 : : result_type = type0;
14142 : : converted = 1;
14143 : : }
14144 : 226006 : else if ((code0 == INTEGER_TYPE || code0 == FIXED_POINT_TYPE
14145 : 1059 : || code0 == BITINT_TYPE
14146 : 544 : || (gnu_vector_type_p (type0)
14147 : 540 : && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE))
14148 : 227058 : && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
14149 : : {
14150 : 225997 : doing_shift = true;
14151 : 225997 : if (TREE_CODE (op1) == INTEGER_CST)
14152 : : {
14153 : 197154 : if (tree_int_cst_sgn (op1) < 0)
14154 : : {
14155 : 245 : int_const = false;
14156 : 245 : if (c_inhibit_evaluation_warnings == 0)
14157 : 105 : warning_at (location, OPT_Wshift_count_negative,
14158 : : "right shift count is negative");
14159 : : }
14160 : 196909 : else if (code0 == VECTOR_TYPE)
14161 : : {
14162 : 452 : if (compare_tree_int (op1,
14163 : 452 : TYPE_PRECISION (TREE_TYPE (type0)))
14164 : : >= 0)
14165 : : {
14166 : 16 : int_const = false;
14167 : 16 : if (c_inhibit_evaluation_warnings == 0)
14168 : 16 : warning_at (location, OPT_Wshift_count_overflow,
14169 : : "right shift count >= width of vector element");
14170 : : }
14171 : : }
14172 : : else
14173 : : {
14174 : 196457 : if (!integer_zerop (op1))
14175 : 196099 : short_shift = 1;
14176 : :
14177 : 196457 : if (compare_tree_int (op1, TYPE_PRECISION (type0)) >= 0)
14178 : : {
14179 : 584 : int_const = false;
14180 : 584 : if (c_inhibit_evaluation_warnings == 0)
14181 : 50 : warning_at (location, OPT_Wshift_count_overflow,
14182 : : "right shift count >= width of type");
14183 : : }
14184 : : }
14185 : : }
14186 : :
14187 : : /* Use the type of the value to be shifted. */
14188 : : result_type = type0;
14189 : : /* Avoid converting op1 to result_type later. */
14190 : : converted = 1;
14191 : : }
14192 : : break;
14193 : :
14194 : 782936 : case LSHIFT_EXPR:
14195 : 782936 : if (gnu_vector_type_p (type0)
14196 : 594 : && gnu_vector_type_p (type1)
14197 : 316 : && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
14198 : 314 : && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE
14199 : 783249 : && known_eq (TYPE_VECTOR_SUBPARTS (type0),
14200 : : TYPE_VECTOR_SUBPARTS (type1)))
14201 : : {
14202 : : result_type = type0;
14203 : : converted = 1;
14204 : : }
14205 : 782625 : else if ((code0 == INTEGER_TYPE || code0 == FIXED_POINT_TYPE
14206 : 740 : || code0 == BITINT_TYPE
14207 : 289 : || (gnu_vector_type_p (type0)
14208 : 283 : && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE))
14209 : 783356 : && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
14210 : : {
14211 : 782611 : doing_shift = true;
14212 : 782611 : if (TREE_CODE (op0) == INTEGER_CST
14213 : 427225 : && tree_int_cst_sgn (op0) < 0
14214 : 783360 : && !TYPE_OVERFLOW_WRAPS (type0))
14215 : : {
14216 : : /* Don't reject a left shift of a negative value in a context
14217 : : where a constant expression is needed in C90. */
14218 : 712 : if (flag_isoc99)
14219 : 666 : int_const = false;
14220 : 712 : if (c_inhibit_evaluation_warnings == 0)
14221 : 712 : warning_at (location, OPT_Wshift_negative_value,
14222 : : "left shift of negative value");
14223 : : }
14224 : 782611 : if (TREE_CODE (op1) == INTEGER_CST)
14225 : : {
14226 : 713226 : if (tree_int_cst_sgn (op1) < 0)
14227 : : {
14228 : 281 : int_const = false;
14229 : 281 : if (c_inhibit_evaluation_warnings == 0)
14230 : 103 : warning_at (location, OPT_Wshift_count_negative,
14231 : : "left shift count is negative");
14232 : : }
14233 : 712945 : else if (code0 == VECTOR_TYPE)
14234 : : {
14235 : 214 : if (compare_tree_int (op1,
14236 : 214 : TYPE_PRECISION (TREE_TYPE (type0)))
14237 : : >= 0)
14238 : : {
14239 : 6 : int_const = false;
14240 : 6 : if (c_inhibit_evaluation_warnings == 0)
14241 : 6 : warning_at (location, OPT_Wshift_count_overflow,
14242 : : "left shift count >= width of vector element");
14243 : : }
14244 : : }
14245 : 712731 : else if (compare_tree_int (op1, TYPE_PRECISION (type0)) >= 0)
14246 : : {
14247 : 29731 : int_const = false;
14248 : 29731 : if (c_inhibit_evaluation_warnings == 0)
14249 : 111 : warning_at (location, OPT_Wshift_count_overflow,
14250 : : "left shift count >= width of type");
14251 : : }
14252 : 683000 : else if (TREE_CODE (op0) == INTEGER_CST
14253 : 355901 : && maybe_warn_shift_overflow (location, op0, op1)
14254 : 683632 : && flag_isoc99)
14255 : : int_const = false;
14256 : : }
14257 : :
14258 : : /* Use the type of the value to be shifted. */
14259 : : result_type = type0;
14260 : : /* Avoid converting op1 to result_type later. */
14261 : : converted = 1;
14262 : : }
14263 : : break;
14264 : :
14265 : 1698795 : case EQ_EXPR:
14266 : 1698795 : case NE_EXPR:
14267 : 1698795 : if (gnu_vector_type_p (type0) && gnu_vector_type_p (type1))
14268 : : {
14269 : 40885 : tree intt;
14270 : 40885 : if (!vector_types_compatible_elements_p (type0, type1))
14271 : : {
14272 : 4 : error_at (location, "comparing vectors with different "
14273 : : "element types");
14274 : 4 : return error_mark_node;
14275 : : }
14276 : :
14277 : 40881 : if (maybe_ne (TYPE_VECTOR_SUBPARTS (type0),
14278 : 81762 : TYPE_VECTOR_SUBPARTS (type1)))
14279 : : {
14280 : 1 : error_at (location, "comparing vectors with different "
14281 : : "number of elements");
14282 : 1 : return error_mark_node;
14283 : : }
14284 : :
14285 : : /* It's not precisely specified how the usual arithmetic
14286 : : conversions apply to the vector types. Here, we use
14287 : : the unsigned type if one of the operands is signed and
14288 : : the other one is unsigned. */
14289 : 40880 : if (TYPE_UNSIGNED (type0) != TYPE_UNSIGNED (type1))
14290 : : {
14291 : 4 : if (!TYPE_UNSIGNED (type0))
14292 : 4 : op0 = build1 (VIEW_CONVERT_EXPR, type1, op0);
14293 : : else
14294 : 0 : op1 = build1 (VIEW_CONVERT_EXPR, type0, op1);
14295 : 4 : warning_at (location, OPT_Wsign_compare, "comparison between "
14296 : : "types %qT and %qT", type0, type1);
14297 : : }
14298 : :
14299 : : /* Always construct signed integer vector type. */
14300 : 122640 : intt = c_common_type_for_size (GET_MODE_BITSIZE
14301 : 81760 : (SCALAR_TYPE_MODE
14302 : : (TREE_TYPE (type0))), 0);
14303 : 40880 : if (!intt)
14304 : : {
14305 : 0 : error_at (location, "could not find an integer type "
14306 : : "of the same size as %qT",
14307 : 0 : TREE_TYPE (type0));
14308 : 0 : return error_mark_node;
14309 : : }
14310 : 40880 : result_type = build_opaque_vector_type (intt,
14311 : 40880 : TYPE_VECTOR_SUBPARTS (type0));
14312 : 40880 : converted = 1;
14313 : 40880 : ret = build_vec_cmp (resultcode, result_type, op0, op1);
14314 : 40880 : goto return_build_binary_op;
14315 : : }
14316 : 1657910 : if (FLOAT_TYPE_P (type0) || FLOAT_TYPE_P (type1))
14317 : 245307 : warning_at (location,
14318 : 245307 : OPT_Wfloat_equal,
14319 : : "comparing floating-point with %<==%> or %<!=%> is unsafe");
14320 : : /* Result of comparison is always int,
14321 : : but don't convert the args to int! */
14322 : 1657910 : build_type = integer_type_node;
14323 : 1657910 : if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == BITINT_TYPE
14324 : 154728 : || code0 == FIXED_POINT_TYPE || code0 == COMPLEX_TYPE)
14325 : 1538475 : && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
14326 : : || code1 == BITINT_TYPE
14327 : : || code1 == FIXED_POINT_TYPE || code1 == COMPLEX_TYPE))
14328 : : short_compare = 1;
14329 : 119698 : else if (code0 == POINTER_TYPE
14330 : 119698 : && (code1 == NULLPTR_TYPE
14331 : 119361 : || null_pointer_constant_p (orig_op1)))
14332 : : {
14333 : 49961 : maybe_warn_for_null_address (location, op0, code);
14334 : 49961 : result_type = type0;
14335 : : }
14336 : 69737 : else if (code1 == POINTER_TYPE
14337 : 69737 : && (code0 == NULLPTR_TYPE
14338 : 69643 : || null_pointer_constant_p (orig_op0)))
14339 : : {
14340 : 284 : maybe_warn_for_null_address (location, op1, code);
14341 : 284 : result_type = type1;
14342 : : }
14343 : 69453 : else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
14344 : : {
14345 : 69371 : tree tt0 = TREE_TYPE (type0);
14346 : 69371 : tree tt1 = TREE_TYPE (type1);
14347 : 69371 : addr_space_t as0 = TYPE_ADDR_SPACE (tt0);
14348 : 69371 : addr_space_t as1 = TYPE_ADDR_SPACE (tt1);
14349 : 69371 : addr_space_t as_common = ADDR_SPACE_GENERIC;
14350 : :
14351 : : /* Anything compares with void *. void * compares with anything.
14352 : : Otherwise, the targets must be compatible
14353 : : and both must be object or both incomplete. */
14354 : 69371 : if (comp_target_types (location, type0, type1))
14355 : 48088 : result_type = common_pointer_type (type0, type1);
14356 : 21283 : else if (!addr_space_superset (as0, as1, &as_common))
14357 : : {
14358 : 0 : error_at (location, "comparison of pointers to "
14359 : : "disjoint address spaces");
14360 : 0 : return error_mark_node;
14361 : : }
14362 : 21283 : else if (VOID_TYPE_P (tt0) && !TYPE_ATOMIC (tt0))
14363 : : {
14364 : 21086 : if (pedantic && TREE_CODE (tt1) == FUNCTION_TYPE)
14365 : 4 : pedwarn (location, OPT_Wpedantic, "ISO C forbids "
14366 : : "comparison of %<void *%> with function pointer");
14367 : : }
14368 : 197 : else if (VOID_TYPE_P (tt1) && !TYPE_ATOMIC (tt1))
14369 : : {
14370 : 149 : if (pedantic && TREE_CODE (tt0) == FUNCTION_TYPE)
14371 : 4 : pedwarn (location, OPT_Wpedantic, "ISO C forbids "
14372 : : "comparison of %<void *%> with function pointer");
14373 : : }
14374 : : else
14375 : : /* Avoid warning about the volatile ObjC EH puts on decls. */
14376 : 48 : if (!objc_ok)
14377 : 48 : pedwarn (location, OPT_Wcompare_distinct_pointer_types,
14378 : : "comparison of distinct pointer types lacks a cast");
14379 : :
14380 : 48144 : if (result_type == NULL_TREE)
14381 : : {
14382 : 21283 : int qual = ENCODE_QUAL_ADDR_SPACE (as_common);
14383 : 21283 : result_type = c_build_pointer_type
14384 : 21283 : (c_build_qualified_type (void_type_node, qual));
14385 : : }
14386 : : }
14387 : 82 : else if (code0 == POINTER_TYPE
14388 : 26 : && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
14389 : : {
14390 : 26 : result_type = type0;
14391 : 26 : pedwarn (location, 0, "comparison between pointer and integer");
14392 : : }
14393 : 56 : else if ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE)
14394 : 21 : && code1 == POINTER_TYPE)
14395 : : {
14396 : 8 : result_type = type1;
14397 : 8 : pedwarn (location, 0, "comparison between pointer and integer");
14398 : : }
14399 : : /* 6.5.9: One of the following shall hold:
14400 : : -- both operands have type nullptr_t; */
14401 : 48 : else if (code0 == NULLPTR_TYPE && code1 == NULLPTR_TYPE)
14402 : : {
14403 : 14 : result_type = nullptr_type_node;
14404 : : /* No need to convert the operands to result_type later. */
14405 : 14 : converted = 1;
14406 : : }
14407 : : /* -- one operand has type nullptr_t and the other is a null pointer
14408 : : constant. We will have to convert the former to the type of the
14409 : : latter, because during gimplification we can't have mismatching
14410 : : comparison operand type. We convert from nullptr_t to the other
14411 : : type, since only nullptr_t can be converted to nullptr_t. Also,
14412 : : even a constant 0 is a null pointer constant, so we may have to
14413 : : create a pointer type from its type. */
14414 : 34 : else if (code0 == NULLPTR_TYPE && null_pointer_constant_p (orig_op1))
14415 : 19 : result_type = (INTEGRAL_TYPE_P (type1)
14416 : 19 : ? c_build_pointer_type (type1) : type1);
14417 : 15 : else if (code1 == NULLPTR_TYPE && null_pointer_constant_p (orig_op0))
14418 : 11 : result_type = (INTEGRAL_TYPE_P (type0)
14419 : 11 : ? c_build_pointer_type (type0) : type0);
14420 : 4904106 : if ((C_BOOLEAN_TYPE_P (TREE_TYPE (orig_op0))
14421 : 3246171 : || truth_value_p (TREE_CODE (orig_op0)))
14422 : 3308572 : ^ (C_BOOLEAN_TYPE_P (TREE_TYPE (orig_op1))
14423 : 3308568 : || truth_value_p (TREE_CODE (orig_op1))))
14424 : 66674 : maybe_warn_bool_compare (location, code, orig_op0, orig_op1);
14425 : : break;
14426 : :
14427 : 972000 : case LE_EXPR:
14428 : 972000 : case GE_EXPR:
14429 : 972000 : case LT_EXPR:
14430 : 972000 : case GT_EXPR:
14431 : 972000 : if (gnu_vector_type_p (type0) && gnu_vector_type_p (type1))
14432 : : {
14433 : 57788 : tree intt;
14434 : 57788 : if (!vector_types_compatible_elements_p (type0, type1))
14435 : : {
14436 : 5 : error_at (location, "comparing vectors with different "
14437 : : "element types");
14438 : 5 : return error_mark_node;
14439 : : }
14440 : :
14441 : 57783 : if (maybe_ne (TYPE_VECTOR_SUBPARTS (type0),
14442 : 115566 : TYPE_VECTOR_SUBPARTS (type1)))
14443 : : {
14444 : 0 : error_at (location, "comparing vectors with different "
14445 : : "number of elements");
14446 : 0 : return error_mark_node;
14447 : : }
14448 : :
14449 : : /* It's not precisely specified how the usual arithmetic
14450 : : conversions apply to the vector types. Here, we use
14451 : : the unsigned type if one of the operands is signed and
14452 : : the other one is unsigned. */
14453 : 57783 : if (TYPE_UNSIGNED (type0) != TYPE_UNSIGNED (type1))
14454 : : {
14455 : 15 : if (!TYPE_UNSIGNED (type0))
14456 : 8 : op0 = build1 (VIEW_CONVERT_EXPR, type1, op0);
14457 : : else
14458 : 7 : op1 = build1 (VIEW_CONVERT_EXPR, type0, op1);
14459 : 15 : warning_at (location, OPT_Wsign_compare, "comparison between "
14460 : : "types %qT and %qT", type0, type1);
14461 : : }
14462 : :
14463 : : /* Always construct signed integer vector type. */
14464 : 173349 : intt = c_common_type_for_size (GET_MODE_BITSIZE
14465 : 115566 : (SCALAR_TYPE_MODE
14466 : : (TREE_TYPE (type0))), 0);
14467 : 57783 : if (!intt)
14468 : : {
14469 : 0 : error_at (location, "could not find an integer type "
14470 : : "of the same size as %qT",
14471 : 0 : TREE_TYPE (type0));
14472 : 0 : return error_mark_node;
14473 : : }
14474 : 57783 : result_type = build_opaque_vector_type (intt,
14475 : 57783 : TYPE_VECTOR_SUBPARTS (type0));
14476 : 57783 : converted = 1;
14477 : 57783 : ret = build_vec_cmp (resultcode, result_type, op0, op1);
14478 : 57783 : goto return_build_binary_op;
14479 : : }
14480 : 914212 : build_type = integer_type_node;
14481 : 914212 : if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
14482 : 63642 : || code0 == BITINT_TYPE || code0 == FIXED_POINT_TYPE)
14483 : 851099 : && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
14484 : : || code1 == BITINT_TYPE || code1 == FIXED_POINT_TYPE))
14485 : : short_compare = 1;
14486 : 63145 : else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
14487 : : {
14488 : 63078 : addr_space_t as0 = TYPE_ADDR_SPACE (TREE_TYPE (type0));
14489 : 63078 : addr_space_t as1 = TYPE_ADDR_SPACE (TREE_TYPE (type1));
14490 : 63078 : addr_space_t as_common;
14491 : :
14492 : 63078 : if (comp_target_types (location, type0, type1))
14493 : : {
14494 : 62965 : result_type = common_pointer_type (type0, type1);
14495 : 62965 : if (!COMPLETE_TYPE_P (TREE_TYPE (type0))
14496 : 62965 : != !COMPLETE_TYPE_P (TREE_TYPE (type1)))
14497 : 32 : pedwarn_c99 (location, OPT_Wpedantic,
14498 : : "comparison of complete and incomplete pointers");
14499 : 62933 : else if (TREE_CODE (TREE_TYPE (type0)) == FUNCTION_TYPE)
14500 : 0 : pedwarn (location, OPT_Wpedantic, "ISO C forbids "
14501 : : "ordered comparisons of pointers to functions");
14502 : 62933 : else if (null_pointer_constant_p (orig_op0)
14503 : 62933 : || null_pointer_constant_p (orig_op1))
14504 : 8 : warning_at (location, OPT_Wextra,
14505 : : "ordered comparison of pointer with null pointer");
14506 : :
14507 : : }
14508 : 113 : else if (!addr_space_superset (as0, as1, &as_common))
14509 : : {
14510 : 0 : error_at (location, "comparison of pointers to "
14511 : : "disjoint address spaces");
14512 : 0 : return error_mark_node;
14513 : : }
14514 : : else
14515 : : {
14516 : 113 : int qual = ENCODE_QUAL_ADDR_SPACE (as_common);
14517 : 113 : result_type = c_build_pointer_type
14518 : 113 : (c_build_qualified_type (void_type_node, qual));
14519 : 113 : pedwarn (location, OPT_Wcompare_distinct_pointer_types,
14520 : : "comparison of distinct pointer types lacks a cast");
14521 : : }
14522 : : }
14523 : 67 : else if (code0 == POINTER_TYPE && null_pointer_constant_p (orig_op1))
14524 : : {
14525 : 17 : result_type = type0;
14526 : 17 : if (pedantic)
14527 : 11 : pedwarn (location, OPT_Wpedantic,
14528 : : "ordered comparison of pointer with integer zero");
14529 : 6 : else if (extra_warnings)
14530 : 1 : warning_at (location, OPT_Wextra,
14531 : : "ordered comparison of pointer with integer zero");
14532 : : }
14533 : 50 : else if (code1 == POINTER_TYPE && null_pointer_constant_p (orig_op0))
14534 : : {
14535 : 12 : result_type = type1;
14536 : 12 : if (pedantic)
14537 : 2 : pedwarn (location, OPT_Wpedantic,
14538 : : "ordered comparison of pointer with integer zero");
14539 : 10 : else if (extra_warnings)
14540 : 1 : warning_at (location, OPT_Wextra,
14541 : : "ordered comparison of pointer with integer zero");
14542 : : }
14543 : 38 : else if (code0 == POINTER_TYPE
14544 : 18 : && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
14545 : : {
14546 : 18 : result_type = type0;
14547 : 18 : pedwarn (location, 0, "comparison between pointer and integer");
14548 : : }
14549 : 20 : else if ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE)
14550 : 20 : && code1 == POINTER_TYPE)
14551 : : {
14552 : 18 : result_type = type1;
14553 : 18 : pedwarn (location, 0, "comparison between pointer and integer");
14554 : : }
14555 : :
14556 : 914212 : if ((code0 == POINTER_TYPE || code1 == POINTER_TYPE)
14557 : 63143 : && current_function_decl != NULL_TREE
14558 : 977344 : && sanitize_flags_p (SANITIZE_POINTER_COMPARE))
14559 : : {
14560 : 35 : op0 = save_expr (c_fully_fold (op0, false, NULL));
14561 : 35 : op1 = save_expr (c_fully_fold (op1, false, NULL));
14562 : :
14563 : 35 : tree tt = builtin_decl_explicit (BUILT_IN_ASAN_POINTER_COMPARE);
14564 : 35 : instrument_expr = build_call_expr_loc (location, tt, 2, op0, op1);
14565 : : }
14566 : :
14567 : 2742546 : if ((C_BOOLEAN_TYPE_P (TREE_TYPE (orig_op0))
14568 : 1828334 : || truth_value_p (TREE_CODE (orig_op0)))
14569 : 1828349 : ^ (C_BOOLEAN_TYPE_P (TREE_TYPE (orig_op1))
14570 : 1828349 : || truth_value_p (TREE_CODE (orig_op1))))
14571 : 509 : maybe_warn_bool_compare (location, code, orig_op0, orig_op1);
14572 : : break;
14573 : :
14574 : 43 : case MIN_EXPR:
14575 : 43 : case MAX_EXPR:
14576 : : /* Used for OpenMP atomics. */
14577 : 43 : gcc_assert (flag_openmp);
14578 : : common = 1;
14579 : : break;
14580 : :
14581 : 0 : default:
14582 : 0 : gcc_unreachable ();
14583 : : }
14584 : :
14585 : 15075310 : if (code0 == ERROR_MARK || code1 == ERROR_MARK)
14586 : 0 : return error_mark_node;
14587 : :
14588 : 15075310 : if (gnu_vector_type_p (type0)
14589 : 1443230 : && gnu_vector_type_p (type1)
14590 : 16517725 : && (!tree_int_cst_equal (TYPE_SIZE (type0), TYPE_SIZE (type1))
14591 : 1442395 : || !vector_types_compatible_elements_p (type0, type1)))
14592 : : {
14593 : 26 : gcc_rich_location richloc (location);
14594 : 26 : maybe_range_label_for_tree_type_mismatch
14595 : 26 : label_for_op0 (orig_op0, orig_op1),
14596 : 26 : label_for_op1 (orig_op1, orig_op0);
14597 : 26 : richloc.maybe_add_expr (orig_op0, &label_for_op0, highlight_colors::lhs);
14598 : 26 : richloc.maybe_add_expr (orig_op1, &label_for_op1, highlight_colors::rhs);
14599 : 26 : binary_op_error (&richloc, code, type0, type1);
14600 : 26 : return error_mark_node;
14601 : 26 : }
14602 : :
14603 : 15075284 : if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == COMPLEX_TYPE
14604 : 1693838 : || code0 == FIXED_POINT_TYPE || code0 == BITINT_TYPE
14605 : 1626167 : || gnu_vector_type_p (type0))
14606 : 16586159 : && (code1 == INTEGER_TYPE || code1 == REAL_TYPE || code1 == COMPLEX_TYPE
14607 : 1535763 : || code1 == FIXED_POINT_TYPE || code1 == BITINT_TYPE
14608 : 1444465 : || gnu_vector_type_p (type1)))
14609 : : {
14610 : 14890250 : bool first_complex = (code0 == COMPLEX_TYPE);
14611 : 14890250 : bool second_complex = (code1 == COMPLEX_TYPE);
14612 : 14890250 : int none_complex = (!first_complex && !second_complex);
14613 : :
14614 : 14890250 : if (shorten || common || short_compare)
14615 : : {
14616 : 13380599 : result_type = c_common_type (type0, type1);
14617 : 13380599 : do_warn_double_promotion (result_type, type0, type1,
14618 : : "implicit conversion from %qT to %qT "
14619 : : "to match other operand of binary "
14620 : : "expression",
14621 : : location);
14622 : 13380599 : if (result_type == error_mark_node)
14623 : : return error_mark_node;
14624 : : }
14625 : :
14626 : 14890228 : if (first_complex != second_complex
14627 : 82043 : && (code == PLUS_EXPR
14628 : : || code == MINUS_EXPR
14629 : 82043 : || code == MULT_EXPR
14630 : 17525 : || (code == TRUNC_DIV_EXPR && first_complex))
14631 : 65932 : && TREE_CODE (TREE_TYPE (result_type)) == REAL_TYPE
14632 : 14952482 : && flag_signed_zeros)
14633 : : {
14634 : : /* An operation on mixed real/complex operands must be
14635 : : handled specially, but the language-independent code can
14636 : : more easily optimize the plain complex arithmetic if
14637 : : -fno-signed-zeros. */
14638 : 61942 : tree real_type = TREE_TYPE (result_type);
14639 : 61942 : tree real, imag;
14640 : 61942 : if (type0 != orig_type0 || type1 != orig_type1)
14641 : : {
14642 : 94 : gcc_assert (may_need_excess_precision && common);
14643 : 94 : semantic_result_type = c_common_type (orig_type0, orig_type1);
14644 : : }
14645 : 61942 : if (first_complex)
14646 : : {
14647 : 8253 : if (TREE_TYPE (op0) != result_type)
14648 : 1787 : op0 = convert_and_check (location, result_type, op0);
14649 : 8253 : if (TREE_TYPE (op1) != real_type)
14650 : 4601 : op1 = convert_and_check (location, real_type, op1);
14651 : : }
14652 : : else
14653 : : {
14654 : 53689 : if (TREE_TYPE (op0) != real_type)
14655 : 2698 : op0 = convert_and_check (location, real_type, op0);
14656 : 53689 : if (TREE_TYPE (op1) != result_type)
14657 : 1866 : op1 = convert_and_check (location, result_type, op1);
14658 : : }
14659 : 61942 : if (TREE_CODE (op0) == ERROR_MARK || TREE_CODE (op1) == ERROR_MARK)
14660 : 0 : return error_mark_node;
14661 : 61942 : if (first_complex)
14662 : : {
14663 : 8253 : op0 = save_expr (op0);
14664 : 8253 : real = build_unary_op (EXPR_LOCATION (orig_op0), REALPART_EXPR,
14665 : : op0, true);
14666 : 8253 : imag = build_unary_op (EXPR_LOCATION (orig_op0), IMAGPART_EXPR,
14667 : : op0, true);
14668 : 8253 : switch (code)
14669 : : {
14670 : 3488 : case MULT_EXPR:
14671 : 3488 : case TRUNC_DIV_EXPR:
14672 : 3488 : op1 = save_expr (op1);
14673 : 3488 : imag = build2 (resultcode, real_type, imag, op1);
14674 : : /* Fall through. */
14675 : 8253 : case PLUS_EXPR:
14676 : 8253 : case MINUS_EXPR:
14677 : 8253 : real = build2 (resultcode, real_type, real, op1);
14678 : 8253 : break;
14679 : 0 : default:
14680 : 0 : gcc_unreachable();
14681 : : }
14682 : : }
14683 : : else
14684 : : {
14685 : 53689 : op1 = save_expr (op1);
14686 : 53689 : real = build_unary_op (EXPR_LOCATION (orig_op1), REALPART_EXPR,
14687 : : op1, true);
14688 : 53689 : imag = build_unary_op (EXPR_LOCATION (orig_op1), IMAGPART_EXPR,
14689 : : op1, true);
14690 : 53689 : switch (code)
14691 : : {
14692 : 2008 : case MULT_EXPR:
14693 : 2008 : op0 = save_expr (op0);
14694 : 2008 : imag = build2 (resultcode, real_type, op0, imag);
14695 : : /* Fall through. */
14696 : 31957 : case PLUS_EXPR:
14697 : 31957 : real = build2 (resultcode, real_type, op0, real);
14698 : 31957 : break;
14699 : 21732 : case MINUS_EXPR:
14700 : 21732 : real = build2 (resultcode, real_type, op0, real);
14701 : 21732 : imag = build1 (NEGATE_EXPR, real_type, imag);
14702 : 21732 : break;
14703 : 0 : default:
14704 : 0 : gcc_unreachable();
14705 : : }
14706 : : }
14707 : 61942 : ret = build2 (COMPLEX_EXPR, result_type, real, imag);
14708 : 61942 : goto return_build_binary_op;
14709 : : }
14710 : :
14711 : : /* For certain operations (which identify themselves by shorten != 0)
14712 : : if both args were extended from the same smaller type,
14713 : : do the arithmetic in that type and then extend.
14714 : :
14715 : : shorten !=0 and !=1 indicates a bitwise operation.
14716 : : For them, this optimization is safe only if
14717 : : both args are zero-extended or both are sign-extended.
14718 : : Otherwise, we might change the result.
14719 : : Eg, (short)-1 | (unsigned short)-1 is (int)-1
14720 : : but calculated in (unsigned short) it would be (unsigned short)-1. */
14721 : :
14722 : 14828286 : if (shorten && none_complex)
14723 : : {
14724 : 1249143 : final_type = result_type;
14725 : 1249143 : result_type = shorten_binary_op (result_type, op0, op1,
14726 : : shorten == -1);
14727 : : }
14728 : :
14729 : : /* Shifts can be shortened if shifting right. */
14730 : :
14731 : 14828286 : if (short_shift)
14732 : : {
14733 : 196099 : int unsigned_arg;
14734 : 196099 : tree arg0 = get_narrower (op0, &unsigned_arg);
14735 : :
14736 : 196099 : final_type = result_type;
14737 : :
14738 : 196099 : if (arg0 == op0 && final_type == TREE_TYPE (op0))
14739 : 138355 : unsigned_arg = TYPE_UNSIGNED (TREE_TYPE (op0));
14740 : :
14741 : 196099 : if (TYPE_PRECISION (TREE_TYPE (arg0)) < TYPE_PRECISION (result_type)
14742 : 2666 : && tree_int_cst_sgn (op1) > 0
14743 : : /* We can shorten only if the shift count is less than the
14744 : : number of bits in the smaller type size. */
14745 : 2666 : && compare_tree_int (op1, TYPE_PRECISION (TREE_TYPE (arg0))) < 0
14746 : : /* We cannot drop an unsigned shift after sign-extension. */
14747 : 198633 : && (!TYPE_UNSIGNED (final_type) || unsigned_arg))
14748 : : {
14749 : : /* Do an unsigned shift if the operand was zero-extended. */
14750 : 2520 : result_type
14751 : 2520 : = c_common_signed_or_unsigned_type (unsigned_arg,
14752 : 2520 : TREE_TYPE (arg0));
14753 : : /* Convert value-to-be-shifted to that type. */
14754 : 2520 : if (TREE_TYPE (op0) != result_type)
14755 : 2520 : op0 = convert (result_type, op0);
14756 : : converted = 1;
14757 : : }
14758 : : }
14759 : :
14760 : : /* Comparison operations are shortened too but differently.
14761 : : They identify themselves by setting short_compare = 1. */
14762 : :
14763 : 14828286 : if (short_compare)
14764 : : {
14765 : : /* Don't write &op0, etc., because that would prevent op0
14766 : : from being kept in a register.
14767 : : Instead, make copies of the our local variables and
14768 : : pass the copies by reference, then copy them back afterward. */
14769 : 2389277 : tree xop0 = op0, xop1 = op1, xresult_type = result_type;
14770 : 2389277 : enum tree_code xresultcode = resultcode;
14771 : 2389277 : tree val
14772 : 2389277 : = shorten_compare (location, &xop0, &xop1, &xresult_type,
14773 : : &xresultcode);
14774 : :
14775 : 2389277 : if (val != NULL_TREE)
14776 : : {
14777 : 15785 : ret = val;
14778 : 15785 : goto return_build_binary_op;
14779 : : }
14780 : :
14781 : 2373492 : op0 = xop0, op1 = xop1;
14782 : 2373492 : converted = 1;
14783 : 2373492 : resultcode = xresultcode;
14784 : :
14785 : 2373492 : if (c_inhibit_evaluation_warnings == 0 && !c_in_omp_for)
14786 : : {
14787 : 2227056 : bool op0_maybe_const = true;
14788 : 2227056 : bool op1_maybe_const = true;
14789 : 2227056 : tree orig_op0_folded, orig_op1_folded;
14790 : :
14791 : 2227056 : if (in_late_binary_op)
14792 : : {
14793 : : orig_op0_folded = orig_op0;
14794 : : orig_op1_folded = orig_op1;
14795 : : }
14796 : : else
14797 : : {
14798 : : /* Fold for the sake of possible warnings, as in
14799 : : build_conditional_expr. This requires the
14800 : : "original" values to be folded, not just op0 and
14801 : : op1. */
14802 : 2221398 : c_inhibit_evaluation_warnings++;
14803 : 2221398 : op0 = c_fully_fold (op0, require_constant_value,
14804 : : &op0_maybe_const);
14805 : 2221398 : op1 = c_fully_fold (op1, require_constant_value,
14806 : : &op1_maybe_const);
14807 : 2221398 : c_inhibit_evaluation_warnings--;
14808 : 2221398 : orig_op0_folded = c_fully_fold (orig_op0,
14809 : : require_constant_value,
14810 : : NULL);
14811 : 2221398 : orig_op1_folded = c_fully_fold (orig_op1,
14812 : : require_constant_value,
14813 : : NULL);
14814 : : }
14815 : :
14816 : 2227056 : if (warn_sign_compare)
14817 : 372630 : warn_for_sign_compare (location, orig_op0_folded,
14818 : : orig_op1_folded, op0, op1,
14819 : : result_type, resultcode);
14820 : 2227056 : if (!in_late_binary_op && !int_operands)
14821 : : {
14822 : 2045155 : if (!op0_maybe_const || TREE_CODE (op0) != INTEGER_CST)
14823 : 2041641 : op0 = c_wrap_maybe_const (op0, !op0_maybe_const);
14824 : 2045155 : if (!op1_maybe_const || TREE_CODE (op1) != INTEGER_CST)
14825 : 799840 : op1 = c_wrap_maybe_const (op1, !op1_maybe_const);
14826 : : }
14827 : : }
14828 : : }
14829 : : }
14830 : :
14831 : : /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
14832 : : If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
14833 : : Then the expression will be built.
14834 : : It will be given type FINAL_TYPE if that is nonzero;
14835 : : otherwise, it will be given type RESULT_TYPE. */
14836 : :
14837 : 14997535 : if (!result_type)
14838 : : {
14839 : : /* Favor showing any expression locations that are available. */
14840 : 514 : op_location_t oploc (location, UNKNOWN_LOCATION);
14841 : 514 : binary_op_rich_location richloc (oploc, orig_op0, orig_op1, true);
14842 : 514 : binary_op_error (&richloc, code, TREE_TYPE (op0), TREE_TYPE (op1));
14843 : 514 : return error_mark_node;
14844 : 514 : }
14845 : :
14846 : 14997021 : if (build_type == NULL_TREE)
14847 : : {
14848 : 12440692 : build_type = result_type;
14849 : 12440692 : if ((type0 != orig_type0 || type1 != orig_type1)
14850 : 797 : && !boolean_op)
14851 : : {
14852 : 797 : gcc_assert (may_need_excess_precision && common);
14853 : 797 : semantic_result_type = c_common_type (orig_type0, orig_type1);
14854 : : }
14855 : : }
14856 : :
14857 : 14997021 : if (!converted)
14858 : : {
14859 : 11110980 : op0 = ep_convert_and_check (location, result_type, op0,
14860 : : semantic_result_type);
14861 : 11110980 : op1 = ep_convert_and_check (location, result_type, op1,
14862 : : semantic_result_type);
14863 : :
14864 : : /* This can happen if one operand has a vector type, and the other
14865 : : has a different type. */
14866 : 11110980 : if (TREE_CODE (op0) == ERROR_MARK || TREE_CODE (op1) == ERROR_MARK)
14867 : 3 : return error_mark_node;
14868 : : }
14869 : :
14870 : 14997018 : if (sanitize_flags_p ((SANITIZE_SHIFT
14871 : : | SANITIZE_DIVIDE
14872 : : | SANITIZE_FLOAT_DIVIDE
14873 : : | SANITIZE_SI_OVERFLOW))
14874 : 23306 : && current_function_decl != NULL_TREE
14875 : 19843 : && (doing_div_or_mod || doing_shift)
14876 : 14999943 : && !require_constant_value)
14877 : : {
14878 : : /* OP0 and/or OP1 might have side-effects. */
14879 : 2869 : op0 = save_expr (op0);
14880 : 2869 : op1 = save_expr (op1);
14881 : 2869 : op0 = c_fully_fold (op0, false, NULL);
14882 : 2869 : op1 = c_fully_fold (op1, false, NULL);
14883 : 2869 : if (doing_div_or_mod && (sanitize_flags_p ((SANITIZE_DIVIDE
14884 : : | SANITIZE_FLOAT_DIVIDE
14885 : : | SANITIZE_SI_OVERFLOW))))
14886 : 912 : instrument_expr = ubsan_instrument_division (location, op0, op1);
14887 : 1957 : else if (doing_shift && sanitize_flags_p (SANITIZE_SHIFT))
14888 : 1777 : instrument_expr = ubsan_instrument_shift (location, code, op0, op1);
14889 : : }
14890 : :
14891 : : /* Treat expressions in initializers specially as they can't trap. */
14892 : 14997018 : if (int_const_or_overflow)
14893 : 7720254 : ret = (require_constant_value
14894 : 7720254 : ? fold_build2_initializer_loc (location, resultcode, build_type,
14895 : : op0, op1)
14896 : 7674133 : : fold_build2_loc (location, resultcode, build_type, op0, op1));
14897 : : else
14898 : 7276764 : ret = build2 (resultcode, build_type, op0, op1);
14899 : 14997018 : if (final_type != NULL_TREE)
14900 : 1445242 : ret = convert (final_type, ret);
14901 : :
14902 : 13551776 : return_build_binary_op:
14903 : 16412115 : gcc_assert (ret != error_mark_node);
14904 : 16412115 : if (TREE_CODE (ret) == INTEGER_CST && !TREE_OVERFLOW (ret) && !int_const)
14905 : 1744 : ret = (int_operands
14906 : 1744 : ? note_integer_operands (ret)
14907 : 422 : : build1 (NOP_EXPR, TREE_TYPE (ret), ret));
14908 : 16410371 : else if (TREE_CODE (ret) != INTEGER_CST && int_operands
14909 : 60300 : && !in_late_binary_op)
14910 : 60300 : ret = note_integer_operands (ret);
14911 : 16412115 : protected_set_expr_location (ret, location);
14912 : :
14913 : 16412115 : if (instrument_expr != NULL)
14914 : 1420 : ret = fold_build2 (COMPOUND_EXPR, TREE_TYPE (ret),
14915 : : instrument_expr, ret);
14916 : :
14917 : 16412115 : if (semantic_result_type)
14918 : 891 : ret = build1_loc (location, EXCESS_PRECISION_EXPR,
14919 : : semantic_result_type, ret);
14920 : :
14921 : : return ret;
14922 : : }
14923 : :
14924 : :
14925 : : /* Convert EXPR to be a truth-value (type TYPE), validating its type for this
14926 : : purpose. LOCATION is the source location for the expression. */
14927 : :
14928 : : tree
14929 : 4042937 : c_objc_common_truthvalue_conversion (location_t location, tree expr, tree type)
14930 : : {
14931 : 4042937 : bool int_const, int_operands;
14932 : :
14933 : 4042937 : switch (TREE_CODE (TREE_TYPE (expr)))
14934 : : {
14935 : 72 : case ARRAY_TYPE:
14936 : 72 : error_at (location, "used array that cannot be converted to pointer where scalar is required");
14937 : 72 : return error_mark_node;
14938 : :
14939 : 86 : case RECORD_TYPE:
14940 : 86 : error_at (location, "used struct type value where scalar is required");
14941 : 86 : return error_mark_node;
14942 : :
14943 : 83 : case UNION_TYPE:
14944 : 83 : error_at (location, "used union type value where scalar is required");
14945 : 83 : return error_mark_node;
14946 : :
14947 : 22 : case VOID_TYPE:
14948 : 22 : error_at (location, "void value not ignored as it ought to be");
14949 : 22 : return error_mark_node;
14950 : :
14951 : 29466 : case POINTER_TYPE:
14952 : 29466 : if (reject_gcc_builtin (expr))
14953 : 3 : return error_mark_node;
14954 : : break;
14955 : :
14956 : 0 : case FUNCTION_TYPE:
14957 : 0 : gcc_unreachable ();
14958 : :
14959 : 8 : case VECTOR_TYPE:
14960 : 8 : error_at (location, "used vector type where scalar is required");
14961 : 8 : return error_mark_node;
14962 : :
14963 : : default:
14964 : : break;
14965 : : }
14966 : :
14967 : : /* Conversion of a floating constant to boolean goes through here
14968 : : and yields an integer constant expression. Otherwise, the result
14969 : : is only an integer constant expression if the argument is. */
14970 : 892360 : int_const = ((TREE_CODE (expr) == INTEGER_CST && !TREE_OVERFLOW (expr))
14971 : 4042739 : || ((TREE_CODE (expr) == REAL_CST
14972 : 3150005 : || TREE_CODE (expr) == COMPLEX_CST)
14973 : 374 : && (TREE_CODE (type) == BOOLEAN_TYPE
14974 : 15 : || (TREE_CODE (type) == ENUMERAL_TYPE
14975 : 5 : && ENUM_UNDERLYING_TYPE (type) != NULL_TREE
14976 : 5 : && (TREE_CODE (ENUM_UNDERLYING_TYPE (type))
14977 : : == BOOLEAN_TYPE)))));
14978 : 4042663 : int_operands = EXPR_INT_CONST_OPERANDS (expr);
14979 : 892520 : if (int_operands && TREE_CODE (expr) != INTEGER_CST)
14980 : : {
14981 : 319 : expr = remove_c_maybe_const_expr (expr);
14982 : 319 : expr = build2 (NE_EXPR, type, expr,
14983 : 319 : convert (TREE_TYPE (expr), integer_zero_node));
14984 : 319 : expr = note_integer_operands (expr);
14985 : : }
14986 : : else
14987 : : {
14988 : : /* ??? Should we also give an error for vectors rather than leaving
14989 : : those to give errors later? */
14990 : 4042344 : expr = c_common_truthvalue_conversion (location, expr);
14991 : 4042344 : expr = fold_convert_loc (location, type, expr);
14992 : : }
14993 : :
14994 : 4042663 : if (TREE_CODE (expr) == INTEGER_CST && int_operands && !int_const)
14995 : : {
14996 : 76 : if (TREE_OVERFLOW (expr))
14997 : : return expr;
14998 : : else
14999 : 76 : return note_integer_operands (expr);
15000 : : }
15001 : 4042587 : if (TREE_CODE (expr) == INTEGER_CST && !int_const)
15002 : 754 : return build1 (NOP_EXPR, TREE_TYPE (expr), expr);
15003 : : return expr;
15004 : : }
15005 : :
15006 : :
15007 : : /* Convert EXPR to a contained DECL, updating *TC, *TI and *SE as
15008 : : required. */
15009 : :
15010 : : tree
15011 : 114344601 : c_expr_to_decl (tree expr, bool *tc ATTRIBUTE_UNUSED, bool *se)
15012 : : {
15013 : 114344601 : if (TREE_CODE (expr) == COMPOUND_LITERAL_EXPR)
15014 : : {
15015 : 655 : tree decl = COMPOUND_LITERAL_EXPR_DECL (expr);
15016 : : /* Executing a compound literal inside a function reinitializes
15017 : : it. */
15018 : 655 : if (!TREE_STATIC (decl))
15019 : 399 : *se = true;
15020 : 655 : return decl;
15021 : : }
15022 : : else
15023 : : return expr;
15024 : : }
15025 : :
15026 : : /* Generate OMP construct CODE, with BODY and CLAUSES as its compound
15027 : : statement. LOC is the location of the construct. */
15028 : :
15029 : : tree
15030 : 2154 : c_finish_omp_construct (location_t loc, enum tree_code code, tree body,
15031 : : tree clauses)
15032 : : {
15033 : 2154 : body = c_end_compound_stmt (loc, body, true);
15034 : :
15035 : 2154 : tree stmt = make_node (code);
15036 : 2154 : TREE_TYPE (stmt) = void_type_node;
15037 : 2154 : OMP_BODY (stmt) = body;
15038 : 2154 : OMP_CLAUSES (stmt) = clauses;
15039 : 2154 : SET_EXPR_LOCATION (stmt, loc);
15040 : :
15041 : 2154 : return add_stmt (stmt);
15042 : : }
15043 : :
15044 : : /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound
15045 : : statement. LOC is the location of the OACC_DATA. */
15046 : :
15047 : : tree
15048 : 497 : c_finish_oacc_data (location_t loc, tree clauses, tree block)
15049 : : {
15050 : 497 : tree stmt;
15051 : :
15052 : 497 : block = c_end_compound_stmt (loc, block, true);
15053 : :
15054 : 497 : stmt = make_node (OACC_DATA);
15055 : 497 : TREE_TYPE (stmt) = void_type_node;
15056 : 497 : OACC_DATA_CLAUSES (stmt) = clauses;
15057 : 497 : OACC_DATA_BODY (stmt) = block;
15058 : 497 : SET_EXPR_LOCATION (stmt, loc);
15059 : :
15060 : 497 : return add_stmt (stmt);
15061 : : }
15062 : :
15063 : : /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound
15064 : : statement. LOC is the location of the OACC_HOST_DATA. */
15065 : :
15066 : : tree
15067 : 21 : c_finish_oacc_host_data (location_t loc, tree clauses, tree block)
15068 : : {
15069 : 21 : tree stmt;
15070 : :
15071 : 21 : block = c_end_compound_stmt (loc, block, true);
15072 : :
15073 : 21 : stmt = make_node (OACC_HOST_DATA);
15074 : 21 : TREE_TYPE (stmt) = void_type_node;
15075 : 21 : OACC_HOST_DATA_CLAUSES (stmt) = clauses;
15076 : 21 : OACC_HOST_DATA_BODY (stmt) = block;
15077 : 21 : SET_EXPR_LOCATION (stmt, loc);
15078 : :
15079 : 21 : return add_stmt (stmt);
15080 : : }
15081 : :
15082 : : /* Like c_begin_compound_stmt, except force the retention of the BLOCK. */
15083 : :
15084 : : tree
15085 : 11988 : c_begin_omp_parallel (void)
15086 : : {
15087 : 11988 : tree block;
15088 : :
15089 : 11988 : keep_next_level ();
15090 : 11988 : block = c_begin_compound_stmt (true);
15091 : :
15092 : 11988 : return block;
15093 : : }
15094 : :
15095 : : /* Generate OMP_PARALLEL, with CLAUSES and BLOCK as its compound
15096 : : statement. LOC is the location of the OMP_PARALLEL. */
15097 : :
15098 : : tree
15099 : 5663 : c_finish_omp_parallel (location_t loc, tree clauses, tree block)
15100 : : {
15101 : 5663 : tree stmt;
15102 : :
15103 : 5663 : block = c_end_compound_stmt (loc, block, true);
15104 : :
15105 : 5663 : stmt = make_node (OMP_PARALLEL);
15106 : 5663 : TREE_TYPE (stmt) = void_type_node;
15107 : 5663 : OMP_PARALLEL_CLAUSES (stmt) = clauses;
15108 : 5663 : OMP_PARALLEL_BODY (stmt) = block;
15109 : 5663 : SET_EXPR_LOCATION (stmt, loc);
15110 : :
15111 : 5663 : return add_stmt (stmt);
15112 : : }
15113 : :
15114 : : /* Like c_begin_compound_stmt, except force the retention of the BLOCK. */
15115 : :
15116 : : tree
15117 : 894 : c_begin_omp_task (void)
15118 : : {
15119 : 894 : tree block;
15120 : :
15121 : 894 : keep_next_level ();
15122 : 894 : block = c_begin_compound_stmt (true);
15123 : :
15124 : 894 : return block;
15125 : : }
15126 : :
15127 : : /* Generate OMP_TASK, with CLAUSES and BLOCK as its compound
15128 : : statement. LOC is the location of the #pragma. */
15129 : :
15130 : : tree
15131 : 894 : c_finish_omp_task (location_t loc, tree clauses, tree block)
15132 : : {
15133 : 894 : tree stmt;
15134 : :
15135 : 894 : block = c_end_compound_stmt (loc, block, true);
15136 : :
15137 : 894 : stmt = make_node (OMP_TASK);
15138 : 894 : TREE_TYPE (stmt) = void_type_node;
15139 : 894 : OMP_TASK_CLAUSES (stmt) = clauses;
15140 : 894 : OMP_TASK_BODY (stmt) = block;
15141 : 894 : SET_EXPR_LOCATION (stmt, loc);
15142 : :
15143 : 894 : return add_stmt (stmt);
15144 : : }
15145 : :
15146 : : /* Generate GOMP_cancel call for #pragma omp cancel. */
15147 : :
15148 : : void
15149 : 213 : c_finish_omp_cancel (location_t loc, tree clauses)
15150 : : {
15151 : 213 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCEL);
15152 : 213 : int mask = 0;
15153 : 213 : if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
15154 : : mask = 1;
15155 : 150 : else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
15156 : : mask = 2;
15157 : 101 : else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
15158 : : mask = 4;
15159 : 58 : else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
15160 : : mask = 8;
15161 : : else
15162 : : {
15163 : 0 : error_at (loc, "%<#pragma omp cancel%> must specify one of "
15164 : : "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> "
15165 : : "clauses");
15166 : 0 : return;
15167 : : }
15168 : 213 : tree ifc = omp_find_clause (clauses, OMP_CLAUSE_IF);
15169 : 213 : if (ifc != NULL_TREE)
15170 : : {
15171 : 31 : if (OMP_CLAUSE_IF_MODIFIER (ifc) != ERROR_MARK
15172 : 31 : && OMP_CLAUSE_IF_MODIFIER (ifc) != VOID_CST)
15173 : 2 : error_at (OMP_CLAUSE_LOCATION (ifc),
15174 : : "expected %<cancel%> %<if%> clause modifier");
15175 : : else
15176 : : {
15177 : 29 : tree ifc2 = omp_find_clause (OMP_CLAUSE_CHAIN (ifc), OMP_CLAUSE_IF);
15178 : 29 : if (ifc2 != NULL_TREE)
15179 : : {
15180 : 1 : gcc_assert (OMP_CLAUSE_IF_MODIFIER (ifc) == VOID_CST
15181 : : && OMP_CLAUSE_IF_MODIFIER (ifc2) != ERROR_MARK
15182 : : && OMP_CLAUSE_IF_MODIFIER (ifc2) != VOID_CST);
15183 : 1 : error_at (OMP_CLAUSE_LOCATION (ifc2),
15184 : : "expected %<cancel%> %<if%> clause modifier");
15185 : : }
15186 : : }
15187 : :
15188 : 31 : tree type = TREE_TYPE (OMP_CLAUSE_IF_EXPR (ifc));
15189 : 62 : ifc = fold_build2_loc (OMP_CLAUSE_LOCATION (ifc), NE_EXPR,
15190 : 31 : boolean_type_node, OMP_CLAUSE_IF_EXPR (ifc),
15191 : : build_zero_cst (type));
15192 : : }
15193 : : else
15194 : 182 : ifc = boolean_true_node;
15195 : 213 : tree stmt = build_call_expr_loc (loc, fn, 2,
15196 : 213 : build_int_cst (integer_type_node, mask),
15197 : : ifc);
15198 : 213 : add_stmt (stmt);
15199 : : }
15200 : :
15201 : : /* Generate GOMP_cancellation_point call for
15202 : : #pragma omp cancellation point. */
15203 : :
15204 : : void
15205 : 167 : c_finish_omp_cancellation_point (location_t loc, tree clauses)
15206 : : {
15207 : 167 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT);
15208 : 167 : int mask = 0;
15209 : 167 : if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
15210 : : mask = 1;
15211 : 123 : else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
15212 : : mask = 2;
15213 : 88 : else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
15214 : : mask = 4;
15215 : 53 : else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
15216 : : mask = 8;
15217 : : else
15218 : : {
15219 : 1 : error_at (loc, "%<#pragma omp cancellation point%> must specify one of "
15220 : : "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> "
15221 : : "clauses");
15222 : 1 : return;
15223 : : }
15224 : 166 : tree stmt = build_call_expr_loc (loc, fn, 1,
15225 : 166 : build_int_cst (integer_type_node, mask));
15226 : 166 : add_stmt (stmt);
15227 : : }
15228 : :
15229 : : /* Helper function for handle_omp_array_sections. Called recursively
15230 : : to handle multiple array-section-subscripts. C is the clause,
15231 : : T current expression (initially OMP_CLAUSE_DECL), which is either
15232 : : a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound
15233 : : expression if specified, TREE_VALUE length expression if specified,
15234 : : TREE_CHAIN is what it has been specified after, or some decl.
15235 : : TYPES vector is populated with array section types, MAYBE_ZERO_LEN
15236 : : set to true if any of the array-section-subscript could have length
15237 : : of zero (explicit or implicit), FIRST_NON_ONE is the index of the
15238 : : first array-section-subscript which is known not to have length
15239 : : of one. Given say:
15240 : : map(a[:b][2:1][:c][:2][:d][e:f][2:5])
15241 : : FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c]
15242 : : all are or may have length of 1, array-section-subscript [:2] is the
15243 : : first one known not to have length 1. For array-section-subscript
15244 : : <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't
15245 : : 0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we
15246 : : can if MAYBE_ZERO_LEN is false. MAYBE_ZERO_LEN will be true in the above
15247 : : case though, as some lengths could be zero. */
15248 : :
15249 : : static tree
15250 : 6305 : handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types,
15251 : : bool &maybe_zero_len, unsigned int &first_non_one,
15252 : : enum c_omp_region_type ort)
15253 : : {
15254 : 6305 : tree ret, low_bound, length, type;
15255 : 6305 : bool openacc = (ort & C_ORT_ACC) != 0;
15256 : 6305 : if (TREE_CODE (t) != OMP_ARRAY_SECTION)
15257 : : {
15258 : 2942 : if (error_operand_p (t))
15259 : 2 : return error_mark_node;
15260 : 2940 : c_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
15261 : 2940 : ret = t;
15262 : 2940 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
15263 : 2841 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
15264 : 5467 : && TYPE_ATOMIC (strip_array_types (TREE_TYPE (t))))
15265 : : {
15266 : 6 : error_at (OMP_CLAUSE_LOCATION (c), "%<_Atomic%> %qE in %qs clause",
15267 : 6 : t, omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
15268 : 6 : return error_mark_node;
15269 : : }
15270 : 2934 : if (!ai.check_clause (c))
15271 : 0 : return error_mark_node;
15272 : 2934 : else if (ai.component_access_p ()
15273 : 3235 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
15274 : 15 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO
15275 : 11 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM))
15276 : 301 : t = ai.get_root_term (true);
15277 : : else
15278 : 2633 : t = ai.unconverted_ref_origin ();
15279 : 2934 : if (t == error_mark_node)
15280 : : return error_mark_node;
15281 : 2934 : if (!VAR_P (t)
15282 : 715 : && (ort == C_ORT_ACC || !EXPR_P (t))
15283 : 714 : && TREE_CODE (t) != PARM_DECL)
15284 : : {
15285 : 5 : if (DECL_P (t))
15286 : 5 : error_at (OMP_CLAUSE_LOCATION (c),
15287 : : "%qD is not a variable in %qs clause", t,
15288 : 5 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
15289 : : else
15290 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
15291 : : "%qE is not a variable in %qs clause", t,
15292 : 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
15293 : 5 : return error_mark_node;
15294 : : }
15295 : 2929 : else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
15296 : 2831 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
15297 : 5447 : && TYPE_ATOMIC (TREE_TYPE (t)))
15298 : : {
15299 : 0 : error_at (OMP_CLAUSE_LOCATION (c), "%<_Atomic%> %qD in %qs clause",
15300 : 0 : t, omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
15301 : 0 : return error_mark_node;
15302 : : }
15303 : 2929 : else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
15304 : 2831 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
15305 : 2518 : && VAR_P (t)
15306 : 4925 : && DECL_THREAD_LOCAL_P (t))
15307 : : {
15308 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
15309 : : "%qD is threadprivate variable in %qs clause", t,
15310 : 3 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
15311 : 3 : return error_mark_node;
15312 : : }
15313 : 2926 : if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
15314 : 2828 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND)
15315 : 411 : && TYPE_ATOMIC (TREE_TYPE (t))
15316 : 2928 : && POINTER_TYPE_P (TREE_TYPE (t)))
15317 : : {
15318 : : /* If the array section is pointer based and the pointer
15319 : : itself is _Atomic qualified, we need to atomically load
15320 : : the pointer. */
15321 : 2 : c_expr expr;
15322 : 2 : memset (&expr, 0, sizeof (expr));
15323 : 2 : expr.value = ret;
15324 : 2 : expr = convert_lvalue_to_rvalue (OMP_CLAUSE_LOCATION (c),
15325 : : expr, false, false);
15326 : 2 : ret = expr.value;
15327 : : }
15328 : 2926 : return ret;
15329 : 2940 : }
15330 : :
15331 : 3363 : ret = handle_omp_array_sections_1 (c, TREE_OPERAND (t, 0), types,
15332 : : maybe_zero_len, first_non_one, ort);
15333 : 3363 : if (ret == error_mark_node || ret == NULL_TREE)
15334 : : return ret;
15335 : :
15336 : 3298 : type = TREE_TYPE (ret);
15337 : 3298 : low_bound = TREE_OPERAND (t, 1);
15338 : 3298 : length = TREE_OPERAND (t, 2);
15339 : :
15340 : 3298 : if (low_bound == error_mark_node || length == error_mark_node)
15341 : : return error_mark_node;
15342 : :
15343 : 3298 : if (low_bound && !INTEGRAL_TYPE_P (TREE_TYPE (low_bound)))
15344 : : {
15345 : 13 : error_at (OMP_CLAUSE_LOCATION (c),
15346 : : "low bound %qE of array section does not have integral type",
15347 : : low_bound);
15348 : 13 : return error_mark_node;
15349 : : }
15350 : 3285 : if (length && !INTEGRAL_TYPE_P (TREE_TYPE (length)))
15351 : : {
15352 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
15353 : : "length %qE of array section does not have integral type",
15354 : : length);
15355 : 12 : return error_mark_node;
15356 : : }
15357 : 3273 : if (low_bound
15358 : 2706 : && TREE_CODE (low_bound) == INTEGER_CST
15359 : 5705 : && TYPE_PRECISION (TREE_TYPE (low_bound))
15360 : 2432 : > TYPE_PRECISION (sizetype))
15361 : 0 : low_bound = fold_convert (sizetype, low_bound);
15362 : 3273 : if (length
15363 : 3085 : && TREE_CODE (length) == INTEGER_CST
15364 : 5414 : && TYPE_PRECISION (TREE_TYPE (length))
15365 : 2141 : > TYPE_PRECISION (sizetype))
15366 : 0 : length = fold_convert (sizetype, length);
15367 : 3273 : if (low_bound == NULL_TREE)
15368 : 567 : low_bound = integer_zero_node;
15369 : 3273 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
15370 : 3273 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
15371 : 1905 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH))
15372 : : {
15373 : 10 : if (length != integer_one_node)
15374 : : {
15375 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
15376 : : "expected single pointer in %qs clause",
15377 : : user_omp_clause_code_name (c, openacc));
15378 : 6 : return error_mark_node;
15379 : : }
15380 : : }
15381 : 3267 : if (length != NULL_TREE)
15382 : : {
15383 : 3083 : if (!integer_nonzerop (length))
15384 : : {
15385 : 972 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
15386 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
15387 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
15388 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
15389 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
15390 : : {
15391 : 180 : if (integer_zerop (length))
15392 : : {
15393 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
15394 : : "zero length array section in %qs clause",
15395 : 12 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
15396 : 12 : return error_mark_node;
15397 : : }
15398 : : }
15399 : : else
15400 : 792 : maybe_zero_len = true;
15401 : : }
15402 : 3071 : if (first_non_one == types.length ()
15403 : 3071 : && (TREE_CODE (length) != INTEGER_CST || integer_onep (length)))
15404 : 1567 : first_non_one++;
15405 : : }
15406 : 3255 : if (TREE_CODE (type) == ARRAY_TYPE)
15407 : : {
15408 : 1487 : if (length == NULL_TREE
15409 : 1487 : && (TYPE_DOMAIN (type) == NULL_TREE
15410 : 168 : || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE))
15411 : : {
15412 : 8 : error_at (OMP_CLAUSE_LOCATION (c),
15413 : : "for unknown bound array type length expression must "
15414 : : "be specified");
15415 : 8 : return error_mark_node;
15416 : : }
15417 : 1479 : if (TREE_CODE (low_bound) == INTEGER_CST
15418 : 1479 : && tree_int_cst_sgn (low_bound) == -1)
15419 : : {
15420 : 35 : error_at (OMP_CLAUSE_LOCATION (c),
15421 : : "negative low bound in array section in %qs clause",
15422 : 35 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
15423 : 35 : return error_mark_node;
15424 : : }
15425 : 1444 : if (length != NULL_TREE
15426 : 1288 : && TREE_CODE (length) == INTEGER_CST
15427 : 2292 : && tree_int_cst_sgn (length) == -1)
15428 : : {
15429 : 35 : error_at (OMP_CLAUSE_LOCATION (c),
15430 : : "negative length in array section in %qs clause",
15431 : 35 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
15432 : 35 : return error_mark_node;
15433 : : }
15434 : 1409 : if (TYPE_DOMAIN (type)
15435 : 1398 : && TYPE_MAX_VALUE (TYPE_DOMAIN (type))
15436 : 2807 : && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
15437 : : == INTEGER_CST)
15438 : : {
15439 : 1052 : tree size
15440 : 1052 : = fold_convert (sizetype, TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
15441 : 1052 : size = size_binop (PLUS_EXPR, size, size_one_node);
15442 : 1052 : if (TREE_CODE (low_bound) == INTEGER_CST)
15443 : : {
15444 : 867 : if (tree_int_cst_lt (size, low_bound))
15445 : : {
15446 : 10 : error_at (OMP_CLAUSE_LOCATION (c),
15447 : : "low bound %qE above array section size "
15448 : : "in %qs clause", low_bound,
15449 : 10 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
15450 : 10 : return error_mark_node;
15451 : : }
15452 : 857 : if (tree_int_cst_equal (size, low_bound))
15453 : : {
15454 : 5 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
15455 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
15456 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
15457 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
15458 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
15459 : : {
15460 : 5 : error_at (OMP_CLAUSE_LOCATION (c),
15461 : : "zero length array section in %qs clause",
15462 : 5 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
15463 : 5 : return error_mark_node;
15464 : : }
15465 : 0 : maybe_zero_len = true;
15466 : : }
15467 : 852 : else if (length == NULL_TREE
15468 : 256 : && first_non_one == types.length ()
15469 : 907 : && tree_int_cst_equal
15470 : 55 : (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
15471 : : low_bound))
15472 : 30 : first_non_one++;
15473 : : }
15474 : 185 : else if (length == NULL_TREE)
15475 : : {
15476 : 3 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
15477 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
15478 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
15479 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
15480 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
15481 : 0 : maybe_zero_len = true;
15482 : 6 : if (first_non_one == types.length ())
15483 : 1 : first_non_one++;
15484 : : }
15485 : 1037 : if (length && TREE_CODE (length) == INTEGER_CST)
15486 : : {
15487 : 790 : if (tree_int_cst_lt (size, length))
15488 : : {
15489 : 11 : error_at (OMP_CLAUSE_LOCATION (c),
15490 : : "length %qE above array section size "
15491 : : "in %qs clause", length,
15492 : 11 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
15493 : 11 : return error_mark_node;
15494 : : }
15495 : 779 : if (TREE_CODE (low_bound) == INTEGER_CST)
15496 : : {
15497 : 681 : tree lbpluslen
15498 : 681 : = size_binop (PLUS_EXPR,
15499 : : fold_convert (sizetype, low_bound),
15500 : : fold_convert (sizetype, length));
15501 : 681 : if (TREE_CODE (lbpluslen) == INTEGER_CST
15502 : 681 : && tree_int_cst_lt (size, lbpluslen))
15503 : : {
15504 : 10 : error_at (OMP_CLAUSE_LOCATION (c),
15505 : : "high bound %qE above array section size "
15506 : : "in %qs clause", lbpluslen,
15507 : 10 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
15508 : 10 : return error_mark_node;
15509 : : }
15510 : : }
15511 : : }
15512 : : }
15513 : 357 : else if (length == NULL_TREE)
15514 : : {
15515 : 10 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
15516 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
15517 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
15518 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
15519 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
15520 : 0 : maybe_zero_len = true;
15521 : 20 : if (first_non_one == types.length ())
15522 : 10 : first_non_one++;
15523 : : }
15524 : :
15525 : : /* For [lb:] we will need to evaluate lb more than once. */
15526 : 920 : if (length == NULL_TREE && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
15527 : : {
15528 : 127 : tree lb = save_expr (low_bound);
15529 : 127 : if (lb != low_bound)
15530 : : {
15531 : 2 : TREE_OPERAND (t, 1) = lb;
15532 : 2 : low_bound = lb;
15533 : : }
15534 : : }
15535 : : }
15536 : 1768 : else if (TREE_CODE (type) == POINTER_TYPE)
15537 : : {
15538 : 1757 : if (length == NULL_TREE)
15539 : : {
15540 : 10 : if (TREE_CODE (ret) == PARM_DECL && C_ARRAY_PARAMETER (ret))
15541 : 8 : error_at (OMP_CLAUSE_LOCATION (c),
15542 : : "for array function parameter length expression "
15543 : : "must be specified");
15544 : : else
15545 : 2 : error_at (OMP_CLAUSE_LOCATION (c),
15546 : : "for pointer type length expression must be specified");
15547 : 10 : return error_mark_node;
15548 : : }
15549 : 1747 : if (length != NULL_TREE
15550 : 1747 : && TREE_CODE (length) == INTEGER_CST
15551 : 1243 : && tree_int_cst_sgn (length) == -1)
15552 : : {
15553 : 20 : error_at (OMP_CLAUSE_LOCATION (c),
15554 : : "negative length in array section in %qs clause",
15555 : 20 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
15556 : 20 : return error_mark_node;
15557 : : }
15558 : : /* If there is a pointer type anywhere but in the very first
15559 : : array-section-subscript, the array section could be non-contiguous. */
15560 : 1727 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
15561 : 1566 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
15562 : 3264 : && TREE_CODE (TREE_OPERAND (t, 0)) == OMP_ARRAY_SECTION)
15563 : : {
15564 : : /* If any prior dimension has a non-one length, then deem this
15565 : : array section as non-contiguous. */
15566 : 25 : for (tree d = TREE_OPERAND (t, 0);
15567 : 46 : TREE_CODE (d) == OMP_ARRAY_SECTION;
15568 : 21 : d = TREE_OPERAND (d, 0))
15569 : : {
15570 : 25 : tree d_length = TREE_OPERAND (d, 2);
15571 : 25 : if (d_length == NULL_TREE || !integer_onep (d_length))
15572 : : {
15573 : 4 : error_at (OMP_CLAUSE_LOCATION (c),
15574 : : "array section is not contiguous in %qs clause",
15575 : 4 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
15576 : 4 : return error_mark_node;
15577 : : }
15578 : : }
15579 : : }
15580 : : }
15581 : : else
15582 : : {
15583 : 11 : error_at (OMP_CLAUSE_LOCATION (c),
15584 : : "%qE does not have pointer or array type", ret);
15585 : 11 : return error_mark_node;
15586 : : }
15587 : 3096 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
15588 : 2780 : types.safe_push (TREE_TYPE (ret));
15589 : : /* We will need to evaluate lb more than once. */
15590 : 3096 : tree lb = save_expr (low_bound);
15591 : 3096 : if (lb != low_bound)
15592 : : {
15593 : 258 : TREE_OPERAND (t, 1) = lb;
15594 : 258 : low_bound = lb;
15595 : : }
15596 : 3096 : ret = build_array_ref (OMP_CLAUSE_LOCATION (c), ret, low_bound);
15597 : 3096 : return ret;
15598 : : }
15599 : :
15600 : : /* Handle array sections for clause C. */
15601 : :
15602 : : static bool
15603 : 2942 : handle_omp_array_sections (tree &c, enum c_omp_region_type ort)
15604 : : {
15605 : 2942 : bool maybe_zero_len = false;
15606 : 2942 : unsigned int first_non_one = 0;
15607 : 2942 : auto_vec<tree, 10> types;
15608 : 2942 : tree *tp = &OMP_CLAUSE_DECL (c);
15609 : 2942 : if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
15610 : 2628 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
15611 : 413 : && TREE_CODE (*tp) == TREE_LIST
15612 : 66 : && TREE_PURPOSE (*tp)
15613 : 3008 : && TREE_CODE (TREE_PURPOSE (*tp)) == TREE_VEC)
15614 : 66 : tp = &TREE_VALUE (*tp);
15615 : 2942 : tree first = handle_omp_array_sections_1 (c, *tp, types,
15616 : : maybe_zero_len, first_non_one,
15617 : : ort);
15618 : 2942 : if (first == error_mark_node)
15619 : : return true;
15620 : 2724 : if (first == NULL_TREE)
15621 : : return false;
15622 : 2724 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
15623 : 2724 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
15624 : : {
15625 : 336 : tree t = *tp;
15626 : 336 : tree tem = NULL_TREE;
15627 : : /* Need to evaluate side effects in the length expressions
15628 : : if any. */
15629 : 336 : while (TREE_CODE (t) == TREE_LIST)
15630 : : {
15631 : 0 : if (TREE_VALUE (t) && TREE_SIDE_EFFECTS (TREE_VALUE (t)))
15632 : : {
15633 : 0 : if (tem == NULL_TREE)
15634 : : tem = TREE_VALUE (t);
15635 : : else
15636 : 0 : tem = build2 (COMPOUND_EXPR, TREE_TYPE (tem),
15637 : 0 : TREE_VALUE (t), tem);
15638 : : }
15639 : 0 : t = TREE_CHAIN (t);
15640 : : }
15641 : 336 : if (tem)
15642 : 0 : first = build2 (COMPOUND_EXPR, TREE_TYPE (first), tem, first);
15643 : 336 : first = c_fully_fold (first, false, NULL, true);
15644 : 336 : *tp = first;
15645 : : }
15646 : : else
15647 : : {
15648 : 2388 : unsigned int num = types.length (), i;
15649 : 2388 : tree t, side_effects = NULL_TREE, size = NULL_TREE;
15650 : 2388 : tree condition = NULL_TREE;
15651 : :
15652 : 2388 : if (int_size_in_bytes (TREE_TYPE (first)) <= 0)
15653 : 3 : maybe_zero_len = true;
15654 : :
15655 : 4959 : for (i = num, t = OMP_CLAUSE_DECL (c); i > 0;
15656 : 2571 : t = TREE_OPERAND (t, 0))
15657 : : {
15658 : 2586 : tree low_bound = TREE_OPERAND (t, 1);
15659 : 2586 : tree length = TREE_OPERAND (t, 2);
15660 : :
15661 : 2586 : i--;
15662 : 2586 : if (low_bound
15663 : 2139 : && TREE_CODE (low_bound) == INTEGER_CST
15664 : 4554 : && TYPE_PRECISION (TREE_TYPE (low_bound))
15665 : 1968 : > TYPE_PRECISION (sizetype))
15666 : 0 : low_bound = fold_convert (sizetype, low_bound);
15667 : 2586 : if (length
15668 : 2494 : && TREE_CODE (length) == INTEGER_CST
15669 : 4154 : && TYPE_PRECISION (TREE_TYPE (length))
15670 : 1568 : > TYPE_PRECISION (sizetype))
15671 : 0 : length = fold_convert (sizetype, length);
15672 : 2586 : if (low_bound == NULL_TREE)
15673 : 447 : low_bound = integer_zero_node;
15674 : 2586 : if (!maybe_zero_len && i > first_non_one)
15675 : : {
15676 : 109 : if (integer_nonzerop (low_bound))
15677 : 6 : goto do_warn_noncontiguous;
15678 : 103 : if (length != NULL_TREE
15679 : 50 : && TREE_CODE (length) == INTEGER_CST
15680 : 50 : && TYPE_DOMAIN (types[i])
15681 : 50 : && TYPE_MAX_VALUE (TYPE_DOMAIN (types[i]))
15682 : 153 : && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])))
15683 : : == INTEGER_CST)
15684 : : {
15685 : 50 : tree size;
15686 : 50 : size = size_binop (PLUS_EXPR,
15687 : : TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
15688 : : size_one_node);
15689 : 50 : if (!tree_int_cst_equal (length, size))
15690 : : {
15691 : 7 : do_warn_noncontiguous:
15692 : 26 : error_at (OMP_CLAUSE_LOCATION (c),
15693 : : "array section is not contiguous in %qs "
15694 : : "clause",
15695 : 13 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
15696 : 2388 : return true;
15697 : : }
15698 : : }
15699 : 96 : if (length != NULL_TREE
15700 : 96 : && TREE_SIDE_EFFECTS (length))
15701 : : {
15702 : 0 : if (side_effects == NULL_TREE)
15703 : : side_effects = length;
15704 : : else
15705 : 0 : side_effects = build2 (COMPOUND_EXPR,
15706 : 0 : TREE_TYPE (side_effects),
15707 : : length, side_effects);
15708 : : }
15709 : : }
15710 : : else
15711 : : {
15712 : 2477 : tree l;
15713 : :
15714 : 2477 : if (i > first_non_one
15715 : 2477 : && ((length && integer_nonzerop (length))
15716 : 0 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
15717 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
15718 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION))
15719 : 0 : continue;
15720 : 2477 : if (length)
15721 : 2444 : l = fold_convert (sizetype, length);
15722 : : else
15723 : : {
15724 : 33 : l = size_binop (PLUS_EXPR,
15725 : : TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
15726 : : size_one_node);
15727 : 33 : l = size_binop (MINUS_EXPR, l,
15728 : : fold_convert (sizetype, low_bound));
15729 : : }
15730 : 2477 : if (i > first_non_one)
15731 : : {
15732 : 0 : l = fold_build2 (NE_EXPR, boolean_type_node, l,
15733 : : size_zero_node);
15734 : 0 : if (condition == NULL_TREE)
15735 : : condition = l;
15736 : : else
15737 : 0 : condition = fold_build2 (BIT_AND_EXPR, boolean_type_node,
15738 : : l, condition);
15739 : : }
15740 : 2477 : else if (size == NULL_TREE)
15741 : : {
15742 : 2375 : size = size_in_bytes (TREE_TYPE (types[i]));
15743 : 2375 : tree eltype = TREE_TYPE (types[num - 1]);
15744 : 2395 : while (TREE_CODE (eltype) == ARRAY_TYPE)
15745 : 20 : eltype = TREE_TYPE (eltype);
15746 : 2375 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
15747 : 2140 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
15748 : 4255 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
15749 : : {
15750 : 539 : if (integer_zerop (size)
15751 : 1076 : || integer_zerop (size_in_bytes (eltype)))
15752 : : {
15753 : 4 : error_at (OMP_CLAUSE_LOCATION (c),
15754 : : "zero length array section in %qs clause",
15755 : 2 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
15756 : 2 : return error_mark_node;
15757 : : }
15758 : 537 : size = size_binop (EXACT_DIV_EXPR, size,
15759 : : size_in_bytes (eltype));
15760 : : }
15761 : 2373 : size = size_binop (MULT_EXPR, size, l);
15762 : 2373 : if (condition)
15763 : 0 : size = fold_build3 (COND_EXPR, sizetype, condition,
15764 : : size, size_zero_node);
15765 : : }
15766 : : else
15767 : 102 : size = size_binop (MULT_EXPR, size, l);
15768 : : }
15769 : : }
15770 : 2373 : if (side_effects)
15771 : 0 : size = build2 (COMPOUND_EXPR, sizetype, side_effects, size);
15772 : 2373 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
15773 : 2140 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
15774 : 4253 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
15775 : : {
15776 : 537 : size = size_binop (MINUS_EXPR, size, size_one_node);
15777 : 537 : size = c_fully_fold (size, false, NULL);
15778 : 537 : size = save_expr (size);
15779 : 537 : tree index_type = build_index_type (size);
15780 : 537 : tree eltype = TREE_TYPE (first);
15781 : 549 : while (TREE_CODE (eltype) == ARRAY_TYPE)
15782 : 12 : eltype = TREE_TYPE (eltype);
15783 : 537 : tree type = c_build_array_type (eltype, index_type);
15784 : 537 : tree ptype = c_build_pointer_type (eltype);
15785 : 537 : if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
15786 : 296 : t = build_fold_addr_expr (t);
15787 : 537 : tree t2 = build_fold_addr_expr (first);
15788 : 537 : t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
15789 : : ptrdiff_type_node, t2);
15790 : 537 : t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
15791 : : ptrdiff_type_node, t2,
15792 : 537 : fold_convert_loc (OMP_CLAUSE_LOCATION (c),
15793 : : ptrdiff_type_node, t));
15794 : 537 : t2 = c_fully_fold (t2, false, NULL);
15795 : 537 : if (tree_fits_shwi_p (t2))
15796 : 398 : t = build2 (MEM_REF, type, t,
15797 : 398 : build_int_cst (ptype, tree_to_shwi (t2)));
15798 : : else
15799 : : {
15800 : 139 : t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c), sizetype, t2);
15801 : 139 : t = build2_loc (OMP_CLAUSE_LOCATION (c), POINTER_PLUS_EXPR,
15802 : 139 : TREE_TYPE (t), t, t2);
15803 : 139 : t = build2 (MEM_REF, type, t, build_int_cst (ptype, 0));
15804 : : }
15805 : 537 : OMP_CLAUSE_DECL (c) = t;
15806 : 537 : return false;
15807 : : }
15808 : 1836 : first = c_fully_fold (first, false, NULL);
15809 : 1836 : OMP_CLAUSE_DECL (c) = first;
15810 : 1836 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR)
15811 : : return false;
15812 : : /* Don't set OMP_CLAUSE_SIZE for bare attach/detach clauses. */
15813 : 1825 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
15814 : 1825 : || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
15815 : 1697 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH
15816 : 1695 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FORCE_DETACH))
15817 : : {
15818 : 1821 : if (size)
15819 : 1821 : size = c_fully_fold (size, false, NULL);
15820 : 1821 : OMP_CLAUSE_SIZE (c) = size;
15821 : : }
15822 : :
15823 : 1825 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
15824 : : return false;
15825 : :
15826 : 1699 : auto_vec<omp_addr_token *, 10> addr_tokens;
15827 : :
15828 : 1699 : if (!omp_parse_expr (addr_tokens, first))
15829 : 1699 : return true;
15830 : :
15831 : 1699 : c_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
15832 : :
15833 : 1699 : tree nc = ai.expand_map_clause (c, first, addr_tokens, ort);
15834 : 1699 : if (nc != error_mark_node)
15835 : : {
15836 : 1699 : using namespace omp_addr_tokenizer;
15837 : :
15838 : 1699 : if (ai.maybe_zero_length_array_section (c))
15839 : 1695 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
15840 : :
15841 : : /* !!! If we're accessing a base decl via chained access
15842 : : methods (e.g. multiple indirections), duplicate clause
15843 : : detection won't work properly. Skip it in that case. */
15844 : 1699 : if ((addr_tokens[0]->type == STRUCTURE_BASE
15845 : 1412 : || addr_tokens[0]->type == ARRAY_BASE)
15846 : 1699 : && addr_tokens[0]->u.structure_base_kind == BASE_DECL
15847 : 1699 : && addr_tokens[1]->type == ACCESS_METHOD
15848 : 3398 : && omp_access_chain_p (addr_tokens, 1))
15849 : 27 : c = nc;
15850 : :
15851 : 1699 : return false;
15852 : : }
15853 : : }
15854 : : return false;
15855 : 2942 : }
15856 : :
15857 : : /* Helper function of finish_omp_clauses. Clone STMT as if we were making
15858 : : an inline call. But, remap
15859 : : the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER
15860 : : and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL. */
15861 : :
15862 : : static tree
15863 : 510 : c_clone_omp_udr (tree stmt, tree omp_decl1, tree omp_decl2,
15864 : : tree decl, tree placeholder)
15865 : : {
15866 : 510 : copy_body_data id;
15867 : 510 : hash_map<tree, tree> decl_map;
15868 : :
15869 : 510 : decl_map.put (omp_decl1, placeholder);
15870 : 510 : decl_map.put (omp_decl2, decl);
15871 : 510 : memset (&id, 0, sizeof (id));
15872 : 510 : id.src_fn = DECL_CONTEXT (omp_decl1);
15873 : 510 : id.dst_fn = current_function_decl;
15874 : 510 : id.src_cfun = DECL_STRUCT_FUNCTION (id.src_fn);
15875 : 510 : id.decl_map = &decl_map;
15876 : :
15877 : 510 : id.copy_decl = copy_decl_no_change;
15878 : 510 : id.transform_call_graph_edges = CB_CGE_DUPLICATE;
15879 : 510 : id.transform_new_cfg = true;
15880 : 510 : id.transform_return_to_modify = false;
15881 : 510 : id.eh_lp_nr = 0;
15882 : 510 : walk_tree (&stmt, copy_tree_body_r, &id, NULL);
15883 : 510 : return stmt;
15884 : 510 : }
15885 : :
15886 : : /* Helper function of c_finish_omp_clauses, called via walk_tree.
15887 : : Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP. */
15888 : :
15889 : : static tree
15890 : 1123 : c_find_omp_placeholder_r (tree *tp, int *, void *data)
15891 : : {
15892 : 1123 : if (*tp == (tree) data)
15893 : 28 : return *tp;
15894 : : return NULL_TREE;
15895 : : }
15896 : :
15897 : : /* Similarly, but also walk aggregate fields. */
15898 : :
15899 : : struct c_find_omp_var_s { tree var; hash_set<tree> *pset; };
15900 : :
15901 : : static tree
15902 : 192 : c_find_omp_var_r (tree *tp, int *, void *data)
15903 : : {
15904 : 192 : if (*tp == ((struct c_find_omp_var_s *) data)->var)
15905 : : return *tp;
15906 : 184 : if (RECORD_OR_UNION_TYPE_P (*tp))
15907 : : {
15908 : 2 : tree field;
15909 : 2 : hash_set<tree> *pset = ((struct c_find_omp_var_s *) data)->pset;
15910 : :
15911 : 2 : for (field = TYPE_FIELDS (*tp); field;
15912 : 0 : field = DECL_CHAIN (field))
15913 : 2 : if (TREE_CODE (field) == FIELD_DECL)
15914 : : {
15915 : 2 : tree ret = walk_tree (&DECL_FIELD_OFFSET (field),
15916 : : c_find_omp_var_r, data, pset);
15917 : 2 : if (ret)
15918 : : return ret;
15919 : 2 : ret = walk_tree (&DECL_SIZE (field), c_find_omp_var_r, data, pset);
15920 : 2 : if (ret)
15921 : : return ret;
15922 : 2 : ret = walk_tree (&DECL_SIZE_UNIT (field), c_find_omp_var_r, data,
15923 : : pset);
15924 : 2 : if (ret)
15925 : : return ret;
15926 : 2 : ret = walk_tree (&TREE_TYPE (field), c_find_omp_var_r, data, pset);
15927 : 2 : if (ret)
15928 : : return ret;
15929 : : }
15930 : : }
15931 : 182 : else if (INTEGRAL_TYPE_P (*tp))
15932 : 27 : return walk_tree (&TYPE_MAX_VALUE (*tp), c_find_omp_var_r, data,
15933 : : ((struct c_find_omp_var_s *) data)->pset);
15934 : : return NULL_TREE;
15935 : : }
15936 : :
15937 : : /* Finish OpenMP iterators ITER. Return true if they are errorneous
15938 : : and clauses containing them should be removed. */
15939 : :
15940 : : static bool
15941 : 111 : c_omp_finish_iterators (tree iter)
15942 : : {
15943 : 111 : bool ret = false;
15944 : 243 : for (tree it = iter; it; it = TREE_CHAIN (it))
15945 : : {
15946 : 132 : tree var = TREE_VEC_ELT (it, 0);
15947 : 132 : tree begin = TREE_VEC_ELT (it, 1);
15948 : 132 : tree end = TREE_VEC_ELT (it, 2);
15949 : 132 : tree step = TREE_VEC_ELT (it, 3);
15950 : 132 : tree orig_step;
15951 : 132 : tree type = TREE_TYPE (var);
15952 : 132 : location_t loc = DECL_SOURCE_LOCATION (var);
15953 : 132 : if (type == error_mark_node)
15954 : : {
15955 : 0 : ret = true;
15956 : 34 : continue;
15957 : : }
15958 : 132 : if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type))
15959 : : {
15960 : 6 : error_at (loc, "iterator %qD has neither integral nor pointer type",
15961 : : var);
15962 : 6 : ret = true;
15963 : 6 : continue;
15964 : : }
15965 : 126 : else if (TYPE_ATOMIC (type))
15966 : : {
15967 : 2 : error_at (loc, "iterator %qD has %<_Atomic%> qualified type", var);
15968 : 2 : ret = true;
15969 : 2 : continue;
15970 : : }
15971 : 124 : else if (TYPE_READONLY (type))
15972 : : {
15973 : 4 : error_at (loc, "iterator %qD has const qualified type", var);
15974 : 4 : ret = true;
15975 : 4 : continue;
15976 : : }
15977 : 120 : else if (step == error_mark_node
15978 : 120 : || TREE_TYPE (step) == error_mark_node)
15979 : : {
15980 : 0 : ret = true;
15981 : 0 : continue;
15982 : : }
15983 : 120 : else if (!INTEGRAL_TYPE_P (TREE_TYPE (step)))
15984 : : {
15985 : 6 : error_at (EXPR_LOC_OR_LOC (step, loc),
15986 : : "iterator step with non-integral type");
15987 : 4 : ret = true;
15988 : 4 : continue;
15989 : : }
15990 : 116 : begin = c_fully_fold (build_c_cast (loc, type, begin), false, NULL);
15991 : 116 : end = c_fully_fold (build_c_cast (loc, type, end), false, NULL);
15992 : 116 : orig_step = save_expr (c_fully_fold (step, false, NULL));
15993 : 116 : tree stype = POINTER_TYPE_P (type) ? sizetype : type;
15994 : 116 : step = c_fully_fold (build_c_cast (loc, stype, orig_step), false, NULL);
15995 : 116 : if (POINTER_TYPE_P (type))
15996 : : {
15997 : 14 : begin = save_expr (begin);
15998 : 14 : step = pointer_int_sum (loc, PLUS_EXPR, begin, step);
15999 : 14 : step = fold_build2_loc (loc, MINUS_EXPR, sizetype,
16000 : : fold_convert (sizetype, step),
16001 : : fold_convert (sizetype, begin));
16002 : 14 : step = fold_convert (ssizetype, step);
16003 : : }
16004 : 116 : if (integer_zerop (step))
16005 : : {
16006 : 6 : error_at (loc, "iterator %qD has zero step", var);
16007 : 6 : ret = true;
16008 : 6 : continue;
16009 : : }
16010 : :
16011 : 110 : if (begin == error_mark_node
16012 : 108 : || end == error_mark_node
16013 : 106 : || step == error_mark_node
16014 : 106 : || orig_step == error_mark_node)
16015 : : {
16016 : 4 : ret = true;
16017 : 4 : continue;
16018 : : }
16019 : 106 : hash_set<tree> pset;
16020 : 106 : tree it2;
16021 : 123 : for (it2 = TREE_CHAIN (it); it2; it2 = TREE_CHAIN (it2))
16022 : : {
16023 : 25 : tree var2 = TREE_VEC_ELT (it2, 0);
16024 : 25 : tree begin2 = TREE_VEC_ELT (it2, 1);
16025 : 25 : tree end2 = TREE_VEC_ELT (it2, 2);
16026 : 25 : tree step2 = TREE_VEC_ELT (it2, 3);
16027 : 25 : tree type2 = TREE_TYPE (var2);
16028 : 25 : location_t loc2 = DECL_SOURCE_LOCATION (var2);
16029 : 25 : struct c_find_omp_var_s data = { var, &pset };
16030 : 25 : if (walk_tree (&type2, c_find_omp_var_r, &data, &pset))
16031 : : {
16032 : 2 : error_at (loc2,
16033 : : "type of iterator %qD refers to outer iterator %qD",
16034 : : var2, var);
16035 : 10 : break;
16036 : : }
16037 : 23 : else if (walk_tree (&begin2, c_find_omp_var_r, &data, &pset))
16038 : : {
16039 : 2 : error_at (EXPR_LOC_OR_LOC (begin2, loc2),
16040 : : "begin expression refers to outer iterator %qD", var);
16041 : 2 : break;
16042 : : }
16043 : 21 : else if (walk_tree (&end2, c_find_omp_var_r, &data, &pset))
16044 : : {
16045 : 2 : error_at (EXPR_LOC_OR_LOC (end2, loc2),
16046 : : "end expression refers to outer iterator %qD", var);
16047 : 2 : break;
16048 : : }
16049 : 19 : else if (walk_tree (&step2, c_find_omp_var_r, &data, &pset))
16050 : : {
16051 : 2 : error_at (EXPR_LOC_OR_LOC (step2, loc2),
16052 : : "step expression refers to outer iterator %qD", var);
16053 : 2 : break;
16054 : : }
16055 : : }
16056 : 106 : if (it2)
16057 : : {
16058 : 8 : ret = true;
16059 : 8 : continue;
16060 : : }
16061 : 98 : TREE_VEC_ELT (it, 1) = begin;
16062 : 98 : TREE_VEC_ELT (it, 2) = end;
16063 : 98 : TREE_VEC_ELT (it, 3) = step;
16064 : 98 : TREE_VEC_ELT (it, 4) = orig_step;
16065 : 106 : }
16066 : 111 : return ret;
16067 : : }
16068 : :
16069 : : /* Ensure that pointers are used in OpenACC attach and detach clauses.
16070 : : Return true if an error has been detected. */
16071 : :
16072 : : static bool
16073 : 9332 : c_oacc_check_attachments (tree c)
16074 : : {
16075 : 9332 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
16076 : : return false;
16077 : :
16078 : : /* OpenACC attach / detach clauses must be pointers. */
16079 : 6350 : if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
16080 : 6350 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
16081 : : {
16082 : 64 : tree t = OMP_CLAUSE_DECL (c);
16083 : :
16084 : 70 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
16085 : 6 : t = TREE_OPERAND (t, 0);
16086 : :
16087 : 64 : if (TREE_CODE (TREE_TYPE (t)) != POINTER_TYPE)
16088 : : {
16089 : 6 : error_at (OMP_CLAUSE_LOCATION (c), "expected pointer in %qs clause",
16090 : : user_omp_clause_code_name (c, true));
16091 : 6 : return true;
16092 : : }
16093 : : }
16094 : :
16095 : : return false;
16096 : : }
16097 : :
16098 : : /* For all elements of CLAUSES, validate them against their constraints.
16099 : : Remove any elements from the list that are invalid. */
16100 : :
16101 : : tree
16102 : 29172 : c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
16103 : : {
16104 : 29172 : bitmap_head generic_head, firstprivate_head, lastprivate_head;
16105 : 29172 : bitmap_head aligned_head, map_head, map_field_head, map_firstprivate_head;
16106 : 29172 : bitmap_head oacc_reduction_head, is_on_device_head;
16107 : 29172 : tree c, t, type, *pc;
16108 : 29172 : tree simdlen = NULL_TREE, safelen = NULL_TREE;
16109 : 29172 : bool branch_seen = false;
16110 : 29172 : bool copyprivate_seen = false;
16111 : 29172 : bool mergeable_seen = false;
16112 : 29172 : tree *detach_seen = NULL;
16113 : 29172 : bool linear_variable_step_check = false;
16114 : 29172 : tree *nowait_clause = NULL;
16115 : 29172 : tree *grainsize_seen = NULL;
16116 : 29172 : bool num_tasks_seen = false;
16117 : 29172 : tree ordered_clause = NULL_TREE;
16118 : 29172 : tree schedule_clause = NULL_TREE;
16119 : 29172 : bool oacc_async = false;
16120 : 29172 : tree last_iterators = NULL_TREE;
16121 : 29172 : bool last_iterators_remove = false;
16122 : 29172 : tree *nogroup_seen = NULL;
16123 : 29172 : tree *order_clause = NULL;
16124 : : /* 1 if normal/task reduction has been seen, -1 if inscan reduction
16125 : : has been seen, -2 if mixed inscan/normal reduction diagnosed. */
16126 : 29172 : int reduction_seen = 0;
16127 : 29172 : bool allocate_seen = false;
16128 : 29172 : bool implicit_moved = false;
16129 : 29172 : bool target_in_reduction_seen = false;
16130 : 29172 : tree *full_seen = NULL;
16131 : 29172 : bool partial_seen = false;
16132 : 29172 : bool openacc = (ort & C_ORT_ACC) != 0;
16133 : 29172 : bool init_seen = false;
16134 : 29172 : bool init_use_destroy_seen = false;
16135 : 29172 : tree init_no_targetsync_clause = NULL_TREE;
16136 : 29172 : tree depend_clause = NULL_TREE;
16137 : :
16138 : 29172 : bitmap_obstack_initialize (NULL);
16139 : 29172 : bitmap_initialize (&generic_head, &bitmap_default_obstack);
16140 : 29172 : bitmap_initialize (&firstprivate_head, &bitmap_default_obstack);
16141 : 29172 : bitmap_initialize (&lastprivate_head, &bitmap_default_obstack);
16142 : 29172 : bitmap_initialize (&aligned_head, &bitmap_default_obstack);
16143 : : /* If ort == C_ORT_OMP_DECLARE_SIMD used as uniform_head instead. */
16144 : 29172 : bitmap_initialize (&map_head, &bitmap_default_obstack);
16145 : 29172 : bitmap_initialize (&map_field_head, &bitmap_default_obstack);
16146 : 29172 : bitmap_initialize (&map_firstprivate_head, &bitmap_default_obstack);
16147 : : /* If ort == C_ORT_OMP used as nontemporal_head or use_device_xxx_head
16148 : : instead and for ort == C_ORT_OMP_TARGET used as in_reduction_head. */
16149 : 29172 : bitmap_initialize (&oacc_reduction_head, &bitmap_default_obstack);
16150 : 29172 : bitmap_initialize (&is_on_device_head, &bitmap_default_obstack);
16151 : :
16152 : 29172 : if (openacc)
16153 : 12261 : for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
16154 : 7250 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ASYNC)
16155 : : {
16156 : : oacc_async = true;
16157 : : break;
16158 : : }
16159 : :
16160 : 29172 : tree *grp_start_p = NULL, grp_sentinel = NULL_TREE;
16161 : :
16162 : 76760 : for (pc = &clauses, c = clauses; c ; c = *pc)
16163 : : {
16164 : 47588 : bool remove = false;
16165 : 47588 : bool need_complete = false;
16166 : 47588 : bool need_implicitly_determined = false;
16167 : :
16168 : : /* We've reached the end of a list of expanded nodes. Reset the group
16169 : : start pointer. */
16170 : 47588 : if (c == grp_sentinel)
16171 : 2455 : grp_start_p = NULL;
16172 : :
16173 : 47588 : switch (OMP_CLAUSE_CODE (c))
16174 : : {
16175 : 1137 : case OMP_CLAUSE_SHARED:
16176 : 1137 : need_implicitly_determined = true;
16177 : 1137 : goto check_dup_generic;
16178 : :
16179 : 837 : case OMP_CLAUSE_PRIVATE:
16180 : 837 : need_complete = true;
16181 : 837 : need_implicitly_determined = true;
16182 : 837 : goto check_dup_generic;
16183 : :
16184 : 3516 : case OMP_CLAUSE_REDUCTION:
16185 : 3516 : if (reduction_seen == 0)
16186 : 2917 : reduction_seen = OMP_CLAUSE_REDUCTION_INSCAN (c) ? -1 : 1;
16187 : 599 : else if (reduction_seen != -2
16188 : 1198 : && reduction_seen != (OMP_CLAUSE_REDUCTION_INSCAN (c)
16189 : 599 : ? -1 : 1))
16190 : : {
16191 : 2 : error_at (OMP_CLAUSE_LOCATION (c),
16192 : : "%<inscan%> and non-%<inscan%> %<reduction%> clauses "
16193 : : "on the same construct");
16194 : 2 : reduction_seen = -2;
16195 : : }
16196 : : /* FALLTHRU */
16197 : 4179 : case OMP_CLAUSE_IN_REDUCTION:
16198 : 4179 : case OMP_CLAUSE_TASK_REDUCTION:
16199 : 4179 : need_implicitly_determined = true;
16200 : 4179 : t = OMP_CLAUSE_DECL (c);
16201 : 4179 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
16202 : : {
16203 : 553 : if (handle_omp_array_sections (c, ort))
16204 : : {
16205 : : remove = true;
16206 : : break;
16207 : : }
16208 : :
16209 : 537 : t = OMP_CLAUSE_DECL (c);
16210 : 537 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
16211 : 537 : && OMP_CLAUSE_REDUCTION_INSCAN (c))
16212 : : {
16213 : 1 : error_at (OMP_CLAUSE_LOCATION (c),
16214 : : "%<inscan%> %<reduction%> clause with array "
16215 : : "section");
16216 : 1 : remove = true;
16217 : 1 : break;
16218 : : }
16219 : : }
16220 : 4162 : t = require_complete_type (OMP_CLAUSE_LOCATION (c), t);
16221 : 4162 : if (t == error_mark_node)
16222 : : {
16223 : : remove = true;
16224 : : break;
16225 : : }
16226 : 4160 : if (oacc_async)
16227 : 3 : c_mark_addressable (t);
16228 : 4160 : type = TREE_TYPE (t);
16229 : 4160 : if (TREE_CODE (t) == MEM_REF)
16230 : 536 : type = TREE_TYPE (type);
16231 : 4160 : if (TREE_CODE (type) == ARRAY_TYPE)
16232 : : {
16233 : 74 : tree oatype = type;
16234 : 74 : gcc_assert (TREE_CODE (t) != MEM_REF);
16235 : 148 : while (TREE_CODE (type) == ARRAY_TYPE)
16236 : 74 : type = TREE_TYPE (type);
16237 : 74 : if (integer_zerop (TYPE_SIZE_UNIT (type)))
16238 : : {
16239 : 1 : error_at (OMP_CLAUSE_LOCATION (c),
16240 : : "%qD in %<reduction%> clause is a zero size array",
16241 : : t);
16242 : 1 : remove = true;
16243 : 1 : break;
16244 : : }
16245 : 73 : tree size = size_binop (EXACT_DIV_EXPR, TYPE_SIZE_UNIT (oatype),
16246 : : TYPE_SIZE_UNIT (type));
16247 : 73 : if (integer_zerop (size))
16248 : : {
16249 : 1 : error_at (OMP_CLAUSE_LOCATION (c),
16250 : : "%qD in %<reduction%> clause is a zero size array",
16251 : : t);
16252 : 1 : remove = true;
16253 : 1 : break;
16254 : : }
16255 : 72 : size = size_binop (MINUS_EXPR, size, size_one_node);
16256 : 72 : size = save_expr (size);
16257 : 72 : tree index_type = build_index_type (size);
16258 : 72 : tree atype = c_build_array_type (TYPE_MAIN_VARIANT (type),
16259 : : index_type);
16260 : 72 : atype = c_build_qualified_type (atype, TYPE_QUALS (type));
16261 : 72 : tree ptype = c_build_pointer_type (type);
16262 : 72 : if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
16263 : 72 : t = build_fold_addr_expr (t);
16264 : 72 : t = build2 (MEM_REF, atype, t, build_int_cst (ptype, 0));
16265 : 72 : OMP_CLAUSE_DECL (c) = t;
16266 : : }
16267 : 4158 : if (TYPE_ATOMIC (type))
16268 : : {
16269 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
16270 : : "%<_Atomic%> %qE in %<reduction%> clause", t);
16271 : 3 : remove = true;
16272 : 3 : break;
16273 : : }
16274 : 4155 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
16275 : 4155 : || OMP_CLAUSE_REDUCTION_TASK (c))
16276 : : {
16277 : : /* Disallow zero sized or potentially zero sized task
16278 : : reductions. */
16279 : 870 : if (integer_zerop (TYPE_SIZE_UNIT (type)))
16280 : : {
16281 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
16282 : : "zero sized type %qT in %qs clause", type,
16283 : 3 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
16284 : 3 : remove = true;
16285 : 3 : break;
16286 : : }
16287 : 867 : else if (TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST)
16288 : : {
16289 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
16290 : : "variable sized type %qT in %qs clause", type,
16291 : 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
16292 : 0 : remove = true;
16293 : 0 : break;
16294 : : }
16295 : : }
16296 : 4152 : if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == NULL_TREE
16297 : 4152 : && (FLOAT_TYPE_P (type)
16298 : 3600 : || TREE_CODE (type) == COMPLEX_TYPE))
16299 : : {
16300 : 340 : enum tree_code r_code = OMP_CLAUSE_REDUCTION_CODE (c);
16301 : 340 : const char *r_name = NULL;
16302 : :
16303 : 340 : switch (r_code)
16304 : : {
16305 : : case PLUS_EXPR:
16306 : : case MULT_EXPR:
16307 : : case MINUS_EXPR:
16308 : : case TRUTH_ANDIF_EXPR:
16309 : : case TRUTH_ORIF_EXPR:
16310 : : break;
16311 : 13 : case MIN_EXPR:
16312 : 13 : if (TREE_CODE (type) == COMPLEX_TYPE)
16313 : : r_name = "min";
16314 : : break;
16315 : 38 : case MAX_EXPR:
16316 : 38 : if (TREE_CODE (type) == COMPLEX_TYPE)
16317 : : r_name = "max";
16318 : : break;
16319 : 3 : case BIT_AND_EXPR:
16320 : 3 : r_name = "&";
16321 : 3 : break;
16322 : 2 : case BIT_XOR_EXPR:
16323 : 2 : r_name = "^";
16324 : 2 : break;
16325 : : case BIT_IOR_EXPR:
16326 : : r_name = "|";
16327 : : break;
16328 : 0 : default:
16329 : 0 : gcc_unreachable ();
16330 : : }
16331 : 5 : if (r_name)
16332 : : {
16333 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
16334 : : "%qE has invalid type for %<reduction(%s)%>",
16335 : : t, r_name);
16336 : 12 : remove = true;
16337 : 12 : break;
16338 : : }
16339 : : }
16340 : 3812 : else if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == error_mark_node)
16341 : : {
16342 : 2 : error_at (OMP_CLAUSE_LOCATION (c),
16343 : : "user defined reduction not found for %qE", t);
16344 : 2 : remove = true;
16345 : 2 : break;
16346 : : }
16347 : 3810 : else if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
16348 : : {
16349 : 277 : tree list = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c);
16350 : 277 : type = TYPE_MAIN_VARIANT (type);
16351 : 277 : tree placeholder = build_decl (OMP_CLAUSE_LOCATION (c),
16352 : : VAR_DECL, NULL_TREE, type);
16353 : 277 : tree decl_placeholder = NULL_TREE;
16354 : 277 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = placeholder;
16355 : 277 : DECL_ARTIFICIAL (placeholder) = 1;
16356 : 277 : DECL_IGNORED_P (placeholder) = 1;
16357 : 277 : if (TREE_CODE (t) == MEM_REF)
16358 : : {
16359 : 56 : decl_placeholder = build_decl (OMP_CLAUSE_LOCATION (c),
16360 : : VAR_DECL, NULL_TREE, type);
16361 : 56 : OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c) = decl_placeholder;
16362 : 56 : DECL_ARTIFICIAL (decl_placeholder) = 1;
16363 : 56 : DECL_IGNORED_P (decl_placeholder) = 1;
16364 : : }
16365 : 277 : if (TREE_ADDRESSABLE (TREE_VEC_ELT (list, 0)))
16366 : 42 : c_mark_addressable (placeholder);
16367 : 277 : if (TREE_ADDRESSABLE (TREE_VEC_ELT (list, 1)))
16368 : 76 : c_mark_addressable (decl_placeholder ? decl_placeholder
16369 : 34 : : OMP_CLAUSE_DECL (c));
16370 : 277 : OMP_CLAUSE_REDUCTION_MERGE (c)
16371 : 775 : = c_clone_omp_udr (TREE_VEC_ELT (list, 2),
16372 : 277 : TREE_VEC_ELT (list, 0),
16373 : 277 : TREE_VEC_ELT (list, 1),
16374 : : decl_placeholder ? decl_placeholder
16375 : 221 : : OMP_CLAUSE_DECL (c), placeholder);
16376 : 277 : OMP_CLAUSE_REDUCTION_MERGE (c)
16377 : 277 : = build3_loc (OMP_CLAUSE_LOCATION (c), BIND_EXPR,
16378 : : void_type_node, NULL_TREE,
16379 : 277 : OMP_CLAUSE_REDUCTION_MERGE (c), NULL_TREE);
16380 : 277 : TREE_SIDE_EFFECTS (OMP_CLAUSE_REDUCTION_MERGE (c)) = 1;
16381 : 277 : if (TREE_VEC_LENGTH (list) == 6)
16382 : : {
16383 : 233 : if (TREE_ADDRESSABLE (TREE_VEC_ELT (list, 3)))
16384 : 70 : c_mark_addressable (decl_placeholder ? decl_placeholder
16385 : 33 : : OMP_CLAUSE_DECL (c));
16386 : 233 : if (TREE_ADDRESSABLE (TREE_VEC_ELT (list, 4)))
16387 : 27 : c_mark_addressable (placeholder);
16388 : 233 : tree init = TREE_VEC_ELT (list, 5);
16389 : 233 : if (init == error_mark_node)
16390 : 197 : init = DECL_INITIAL (TREE_VEC_ELT (list, 3));
16391 : 233 : OMP_CLAUSE_REDUCTION_INIT (c)
16392 : 651 : = c_clone_omp_udr (init, TREE_VEC_ELT (list, 4),
16393 : 233 : TREE_VEC_ELT (list, 3),
16394 : : decl_placeholder ? decl_placeholder
16395 : 185 : : OMP_CLAUSE_DECL (c), placeholder);
16396 : 233 : if (TREE_VEC_ELT (list, 5) == error_mark_node)
16397 : : {
16398 : 197 : tree v = decl_placeholder ? decl_placeholder : t;
16399 : 197 : OMP_CLAUSE_REDUCTION_INIT (c)
16400 : 394 : = build2 (INIT_EXPR, TREE_TYPE (v), v,
16401 : 197 : OMP_CLAUSE_REDUCTION_INIT (c));
16402 : : }
16403 : 233 : if (walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c),
16404 : : c_find_omp_placeholder_r,
16405 : : placeholder, NULL))
16406 : 28 : OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c) = 1;
16407 : : }
16408 : : else
16409 : : {
16410 : 44 : tree init;
16411 : 44 : tree v = decl_placeholder ? decl_placeholder : t;
16412 : 44 : if (AGGREGATE_TYPE_P (TREE_TYPE (v)))
16413 : 34 : init = build_constructor (TREE_TYPE (v), NULL);
16414 : : else
16415 : 10 : init = fold_convert (TREE_TYPE (v), integer_zero_node);
16416 : 44 : OMP_CLAUSE_REDUCTION_INIT (c)
16417 : 88 : = build2 (INIT_EXPR, TREE_TYPE (v), v, init);
16418 : : }
16419 : 277 : OMP_CLAUSE_REDUCTION_INIT (c)
16420 : 277 : = build3_loc (OMP_CLAUSE_LOCATION (c), BIND_EXPR,
16421 : : void_type_node, NULL_TREE,
16422 : 277 : OMP_CLAUSE_REDUCTION_INIT (c), NULL_TREE);
16423 : 277 : TREE_SIDE_EFFECTS (OMP_CLAUSE_REDUCTION_INIT (c)) = 1;
16424 : : }
16425 : 4138 : if (TREE_CODE (t) == MEM_REF)
16426 : : {
16427 : 607 : if (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t))) == NULL_TREE
16428 : 607 : || TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t))))
16429 : : != INTEGER_CST)
16430 : : {
16431 : 0 : sorry ("variable length element type in array "
16432 : : "%<reduction%> clause");
16433 : 0 : remove = true;
16434 : 0 : break;
16435 : : }
16436 : 607 : t = TREE_OPERAND (t, 0);
16437 : 607 : if (TREE_CODE (t) == POINTER_PLUS_EXPR)
16438 : 139 : t = TREE_OPERAND (t, 0);
16439 : 607 : if (TREE_CODE (t) == ADDR_EXPR)
16440 : 367 : t = TREE_OPERAND (t, 0);
16441 : : }
16442 : 4138 : goto check_dup_generic_t;
16443 : :
16444 : 24 : case OMP_CLAUSE_COPYPRIVATE:
16445 : 24 : copyprivate_seen = true;
16446 : 24 : if (nowait_clause)
16447 : : {
16448 : 1 : error_at (OMP_CLAUSE_LOCATION (*nowait_clause),
16449 : : "%<nowait%> clause must not be used together "
16450 : : "with %<copyprivate%> clause");
16451 : 1 : *nowait_clause = OMP_CLAUSE_CHAIN (*nowait_clause);
16452 : 1 : nowait_clause = NULL;
16453 : : }
16454 : 24 : goto check_dup_generic;
16455 : :
16456 : 99 : case OMP_CLAUSE_COPYIN:
16457 : 99 : t = OMP_CLAUSE_DECL (c);
16458 : 99 : if (!VAR_P (t) || !DECL_THREAD_LOCAL_P (t))
16459 : : {
16460 : 5 : error_at (OMP_CLAUSE_LOCATION (c),
16461 : : "%qE must be %<threadprivate%> for %<copyin%>", t);
16462 : 5 : remove = true;
16463 : 5 : break;
16464 : : }
16465 : 94 : goto check_dup_generic;
16466 : :
16467 : 478 : case OMP_CLAUSE_LINEAR:
16468 : 478 : if (ort != C_ORT_OMP_DECLARE_SIMD)
16469 : 327 : need_implicitly_determined = true;
16470 : 478 : t = OMP_CLAUSE_DECL (c);
16471 : 478 : if (ort != C_ORT_OMP_DECLARE_SIMD
16472 : 327 : && OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_DEFAULT
16473 : 483 : && OMP_CLAUSE_LINEAR_OLD_LINEAR_MODIFIER (c))
16474 : : {
16475 : 5 : error_at (OMP_CLAUSE_LOCATION (c),
16476 : : "modifier should not be specified in %<linear%> "
16477 : : "clause on %<simd%> or %<for%> constructs when not "
16478 : : "using OpenMP 5.2 modifiers");
16479 : 5 : OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT;
16480 : : }
16481 : 956 : if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
16482 : 501 : && TREE_CODE (TREE_TYPE (t)) != POINTER_TYPE)
16483 : : {
16484 : 1 : error_at (OMP_CLAUSE_LOCATION (c),
16485 : : "linear clause applied to non-integral non-pointer "
16486 : 1 : "variable with type %qT", TREE_TYPE (t));
16487 : 1 : remove = true;
16488 : 1 : break;
16489 : : }
16490 : 477 : if (TYPE_ATOMIC (TREE_TYPE (t)))
16491 : : {
16492 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
16493 : : "%<_Atomic%> %qD in %<linear%> clause", t);
16494 : 3 : remove = true;
16495 : 3 : break;
16496 : : }
16497 : 474 : if (ort == C_ORT_OMP_DECLARE_SIMD)
16498 : : {
16499 : 150 : tree s = OMP_CLAUSE_LINEAR_STEP (c);
16500 : 150 : if (TREE_CODE (s) == PARM_DECL)
16501 : : {
16502 : 9 : OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c) = 1;
16503 : : /* map_head bitmap is used as uniform_head if
16504 : : declare_simd. */
16505 : 9 : if (!bitmap_bit_p (&map_head, DECL_UID (s)))
16506 : 5 : linear_variable_step_check = true;
16507 : 9 : goto check_dup_generic;
16508 : : }
16509 : 141 : if (TREE_CODE (s) != INTEGER_CST)
16510 : : {
16511 : 7 : error_at (OMP_CLAUSE_LOCATION (c),
16512 : : "%<linear%> clause step %qE is neither constant "
16513 : : "nor a parameter", s);
16514 : 7 : remove = true;
16515 : 7 : break;
16516 : : }
16517 : : }
16518 : 458 : if (TREE_CODE (TREE_TYPE (OMP_CLAUSE_DECL (c))) == POINTER_TYPE)
16519 : : {
16520 : 20 : tree s = OMP_CLAUSE_LINEAR_STEP (c);
16521 : 20 : s = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
16522 : 20 : OMP_CLAUSE_DECL (c), s);
16523 : 20 : s = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
16524 : : sizetype, fold_convert (sizetype, s),
16525 : 20 : fold_convert
16526 : : (sizetype, OMP_CLAUSE_DECL (c)));
16527 : 20 : if (s == error_mark_node)
16528 : 0 : s = size_one_node;
16529 : 20 : OMP_CLAUSE_LINEAR_STEP (c) = s;
16530 : : }
16531 : : else
16532 : 438 : OMP_CLAUSE_LINEAR_STEP (c)
16533 : 876 : = fold_convert (TREE_TYPE (t), OMP_CLAUSE_LINEAR_STEP (c));
16534 : 458 : goto check_dup_generic;
16535 : :
16536 : 2872 : check_dup_generic:
16537 : 2872 : t = OMP_CLAUSE_DECL (c);
16538 : 7098 : check_dup_generic_t:
16539 : 7098 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
16540 : : {
16541 : 4 : error_at (OMP_CLAUSE_LOCATION (c),
16542 : : "%qE is not a variable in clause %qs", t,
16543 : 2 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
16544 : 2 : remove = true;
16545 : : }
16546 : 1149 : else if ((openacc && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
16547 : 6057 : || (ort == C_ORT_OMP
16548 : 5349 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
16549 : 5338 : || (OMP_CLAUSE_CODE (c)
16550 : : == OMP_CLAUSE_USE_DEVICE_ADDR)))
16551 : 13106 : || (ort == C_ORT_OMP_TARGET
16552 : 338 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION))
16553 : : {
16554 : 1196 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
16555 : 1196 : && (bitmap_bit_p (&generic_head, DECL_UID (t))
16556 : 109 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))))
16557 : : {
16558 : 2 : error_at (OMP_CLAUSE_LOCATION (c),
16559 : : "%qD appears more than once in data-sharing "
16560 : : "clauses", t);
16561 : 2 : remove = true;
16562 : 2 : break;
16563 : : }
16564 : 1194 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION)
16565 : 108 : target_in_reduction_seen = true;
16566 : 1194 : if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
16567 : : {
16568 : 4 : error_at (OMP_CLAUSE_LOCATION (c),
16569 : : openacc
16570 : : ? "%qD appears more than once in reduction clauses"
16571 : : : "%qD appears more than once in data clauses",
16572 : : t);
16573 : 2 : remove = true;
16574 : : }
16575 : : else
16576 : 1192 : bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
16577 : : }
16578 : 5900 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
16579 : 5878 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
16580 : 5877 : || bitmap_bit_p (&lastprivate_head, DECL_UID (t))
16581 : 11777 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
16582 : : {
16583 : 23 : error_at (OMP_CLAUSE_LOCATION (c),
16584 : : "%qE appears more than once in data clauses", t);
16585 : 23 : remove = true;
16586 : : }
16587 : 5877 : else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
16588 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR
16589 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
16590 : 1036 : && bitmap_bit_p (&map_head, DECL_UID (t)))
16591 : : {
16592 : 3 : if (openacc)
16593 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
16594 : : "%qD appears more than once in data clauses", t);
16595 : : else
16596 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
16597 : : "%qD appears both in data and map clauses", t);
16598 : : remove = true;
16599 : : }
16600 : : else
16601 : 5874 : bitmap_set_bit (&generic_head, DECL_UID (t));
16602 : : break;
16603 : :
16604 : 1320 : case OMP_CLAUSE_FIRSTPRIVATE:
16605 : 1320 : if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c) && !implicit_moved)
16606 : : {
16607 : 186 : move_implicit:
16608 : 186 : implicit_moved = true;
16609 : : /* Move firstprivate and map clauses with
16610 : : OMP_CLAUSE_{FIRSTPRIVATE,MAP}_IMPLICIT set to the end of
16611 : : clauses chain. */
16612 : 186 : tree cl1 = NULL_TREE, cl2 = NULL_TREE;
16613 : 186 : tree *pc1 = pc, *pc2 = &cl1, *pc3 = &cl2;
16614 : 1072 : while (*pc1)
16615 : 886 : if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_FIRSTPRIVATE
16616 : 886 : && OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (*pc1))
16617 : : {
16618 : 113 : *pc3 = *pc1;
16619 : 113 : pc3 = &OMP_CLAUSE_CHAIN (*pc3);
16620 : 113 : *pc1 = OMP_CLAUSE_CHAIN (*pc1);
16621 : : }
16622 : 773 : else if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_MAP
16623 : 773 : && OMP_CLAUSE_MAP_IMPLICIT (*pc1))
16624 : : {
16625 : 164 : *pc2 = *pc1;
16626 : 164 : pc2 = &OMP_CLAUSE_CHAIN (*pc2);
16627 : 164 : *pc1 = OMP_CLAUSE_CHAIN (*pc1);
16628 : : }
16629 : : else
16630 : 609 : pc1 = &OMP_CLAUSE_CHAIN (*pc1);
16631 : 186 : *pc3 = NULL;
16632 : 186 : *pc2 = cl2;
16633 : 186 : *pc1 = cl1;
16634 : 186 : continue;
16635 : 186 : }
16636 : 1225 : t = OMP_CLAUSE_DECL (c);
16637 : 1225 : need_complete = true;
16638 : 1225 : need_implicitly_determined = true;
16639 : 1225 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
16640 : : {
16641 : 1 : error_at (OMP_CLAUSE_LOCATION (c),
16642 : : "%qE is not a variable in clause %<firstprivate%>", t);
16643 : 1 : remove = true;
16644 : : }
16645 : 1224 : else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
16646 : 113 : && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c)
16647 : 1330 : && bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
16648 : : remove = true;
16649 : 1224 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
16650 : 1222 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
16651 : 2445 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
16652 : : {
16653 : 4 : error_at (OMP_CLAUSE_LOCATION (c),
16654 : : "%qE appears more than once in data clauses", t);
16655 : 4 : remove = true;
16656 : : }
16657 : 1220 : else if (bitmap_bit_p (&map_head, DECL_UID (t))
16658 : 1220 : || bitmap_bit_p (&map_field_head, DECL_UID (t)))
16659 : : {
16660 : 7 : if (openacc)
16661 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
16662 : : "%qD appears more than once in data clauses", t);
16663 : 7 : else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
16664 : 7 : && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c))
16665 : : /* Silently drop the clause. */;
16666 : : else
16667 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
16668 : : "%qD appears both in data and map clauses", t);
16669 : : remove = true;
16670 : : }
16671 : : else
16672 : 1213 : bitmap_set_bit (&firstprivate_head, DECL_UID (t));
16673 : : break;
16674 : :
16675 : 1522 : case OMP_CLAUSE_LASTPRIVATE:
16676 : 1522 : t = OMP_CLAUSE_DECL (c);
16677 : 1522 : need_complete = true;
16678 : 1522 : need_implicitly_determined = true;
16679 : 1522 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
16680 : : {
16681 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
16682 : : "%qE is not a variable in clause %<lastprivate%>", t);
16683 : 0 : remove = true;
16684 : : }
16685 : 1522 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
16686 : 1522 : || bitmap_bit_p (&lastprivate_head, DECL_UID (t)))
16687 : : {
16688 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
16689 : : "%qE appears more than once in data clauses", t);
16690 : 3 : remove = true;
16691 : : }
16692 : : else
16693 : 1519 : bitmap_set_bit (&lastprivate_head, DECL_UID (t));
16694 : : break;
16695 : :
16696 : 253 : case OMP_CLAUSE_ALIGNED:
16697 : 253 : t = OMP_CLAUSE_DECL (c);
16698 : 253 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
16699 : : {
16700 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
16701 : : "%qE is not a variable in %<aligned%> clause", t);
16702 : 0 : remove = true;
16703 : : }
16704 : 289 : else if (!POINTER_TYPE_P (TREE_TYPE (t))
16705 : 289 : && TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE)
16706 : : {
16707 : 7 : error_at (OMP_CLAUSE_LOCATION (c),
16708 : : "%qE in %<aligned%> clause is neither a pointer nor "
16709 : : "an array", t);
16710 : 7 : remove = true;
16711 : : }
16712 : 246 : else if (TYPE_ATOMIC (TREE_TYPE (t)))
16713 : : {
16714 : 1 : error_at (OMP_CLAUSE_LOCATION (c),
16715 : : "%<_Atomic%> %qD in %<aligned%> clause", t);
16716 : 1 : remove = true;
16717 : 1 : break;
16718 : : }
16719 : 245 : else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
16720 : : {
16721 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
16722 : : "%qE appears more than once in %<aligned%> clauses",
16723 : : t);
16724 : 0 : remove = true;
16725 : : }
16726 : : else
16727 : 245 : bitmap_set_bit (&aligned_head, DECL_UID (t));
16728 : : break;
16729 : :
16730 : 125 : case OMP_CLAUSE_NONTEMPORAL:
16731 : 125 : t = OMP_CLAUSE_DECL (c);
16732 : 125 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
16733 : : {
16734 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
16735 : : "%qE is not a variable in %<nontemporal%> clause", t);
16736 : 0 : remove = true;
16737 : : }
16738 : 125 : else if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
16739 : : {
16740 : 2 : error_at (OMP_CLAUSE_LOCATION (c),
16741 : : "%qE appears more than once in %<nontemporal%> "
16742 : : "clauses", t);
16743 : 2 : remove = true;
16744 : : }
16745 : : else
16746 : 123 : bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
16747 : : break;
16748 : :
16749 : 786 : case OMP_CLAUSE_ALLOCATE:
16750 : 786 : t = OMP_CLAUSE_DECL (c);
16751 : 786 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
16752 : : {
16753 : 1 : error_at (OMP_CLAUSE_LOCATION (c),
16754 : : "%qE is not a variable in %<allocate%> clause", t);
16755 : 1 : remove = true;
16756 : : }
16757 : 785 : else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
16758 : : {
16759 : 2 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
16760 : : "%qE appears more than once in %<allocate%> clauses",
16761 : : t);
16762 : 2 : remove = true;
16763 : : }
16764 : : else
16765 : : {
16766 : 783 : bitmap_set_bit (&aligned_head, DECL_UID (t));
16767 : 783 : if (!OMP_CLAUSE_ALLOCATE_COMBINED (c))
16768 : 684 : allocate_seen = true;
16769 : : }
16770 : : break;
16771 : :
16772 : 355 : case OMP_CLAUSE_DOACROSS:
16773 : 355 : t = OMP_CLAUSE_DECL (c);
16774 : 355 : if (t == NULL_TREE)
16775 : : break;
16776 : 168 : if (OMP_CLAUSE_DOACROSS_KIND (c) == OMP_CLAUSE_DOACROSS_SINK)
16777 : : {
16778 : 168 : gcc_assert (TREE_CODE (t) == TREE_LIST);
16779 : 1313 : for (; t; t = TREE_CHAIN (t))
16780 : : {
16781 : 1145 : tree decl = TREE_VALUE (t);
16782 : 1145 : if (TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE)
16783 : : {
16784 : 3 : tree offset = TREE_PURPOSE (t);
16785 : 3 : bool neg = wi::neg_p (wi::to_wide (offset));
16786 : 3 : offset = fold_unary (ABS_EXPR, TREE_TYPE (offset), offset);
16787 : 6 : tree t2 = pointer_int_sum (OMP_CLAUSE_LOCATION (c),
16788 : : neg ? MINUS_EXPR : PLUS_EXPR,
16789 : : decl, offset);
16790 : 3 : t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
16791 : : sizetype,
16792 : : fold_convert (sizetype, t2),
16793 : : fold_convert (sizetype, decl));
16794 : 3 : if (t2 == error_mark_node)
16795 : : {
16796 : : remove = true;
16797 : : break;
16798 : : }
16799 : 3 : TREE_PURPOSE (t) = t2;
16800 : : }
16801 : : }
16802 : : break;
16803 : : }
16804 : 0 : gcc_unreachable ();
16805 : 713 : case OMP_CLAUSE_DEPEND:
16806 : 713 : depend_clause = c;
16807 : : /* FALLTHRU */
16808 : 870 : case OMP_CLAUSE_AFFINITY:
16809 : 870 : t = OMP_CLAUSE_DECL (c);
16810 : 870 : if (TREE_CODE (t) == TREE_LIST
16811 : 131 : && TREE_PURPOSE (t)
16812 : 1001 : && TREE_CODE (TREE_PURPOSE (t)) == TREE_VEC)
16813 : : {
16814 : 131 : if (TREE_PURPOSE (t) != last_iterators)
16815 : 111 : last_iterators_remove
16816 : 111 : = c_omp_finish_iterators (TREE_PURPOSE (t));
16817 : 131 : last_iterators = TREE_PURPOSE (t);
16818 : 131 : t = TREE_VALUE (t);
16819 : 131 : if (last_iterators_remove)
16820 : 34 : t = error_mark_node;
16821 : : }
16822 : : else
16823 : : last_iterators = NULL_TREE;
16824 : 870 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
16825 : : {
16826 : 413 : if (handle_omp_array_sections (c, ort))
16827 : : remove = true;
16828 : 336 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
16829 : 336 : && OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ)
16830 : : {
16831 : 1 : error_at (OMP_CLAUSE_LOCATION (c),
16832 : : "%<depend%> clause with %<depobj%> dependence "
16833 : : "type on array section");
16834 : 1 : remove = true;
16835 : : }
16836 : : break;
16837 : : }
16838 : 457 : if (t == error_mark_node)
16839 : : remove = true;
16840 : 423 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
16841 : 423 : && t == ridpointers[RID_OMP_ALL_MEMORY])
16842 : : {
16843 : 15 : if (OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_OUT
16844 : 15 : && OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_INOUT)
16845 : : {
16846 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
16847 : : "%<omp_all_memory%> used with %<depend%> kind "
16848 : : "other than %<out%> or %<inout%>");
16849 : 3 : remove = true;
16850 : : }
16851 : : }
16852 : 408 : else if (!lvalue_p (t))
16853 : : {
16854 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
16855 : : "%qE is not lvalue expression nor array section in "
16856 : : "%qs clause", t,
16857 : 3 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
16858 : 3 : remove = true;
16859 : : }
16860 : 405 : else if (TREE_CODE (t) == COMPONENT_REF
16861 : 405 : && DECL_C_BIT_FIELD (TREE_OPERAND (t, 1)))
16862 : : {
16863 : 2 : gcc_assert (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
16864 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY);
16865 : 2 : error_at (OMP_CLAUSE_LOCATION (c),
16866 : : "bit-field %qE in %qs clause", t,
16867 : 2 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
16868 : 2 : remove = true;
16869 : : }
16870 : 403 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
16871 : 403 : && OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ)
16872 : : {
16873 : 20 : if (!c_omp_depend_t_p (TREE_TYPE (t)))
16874 : : {
16875 : 2 : error_at (OMP_CLAUSE_LOCATION (c),
16876 : : "%qE does not have %<omp_depend_t%> type in "
16877 : : "%<depend%> clause with %<depobj%> dependence "
16878 : : "type", t);
16879 : 2 : remove = true;
16880 : : }
16881 : : }
16882 : 383 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
16883 : 383 : && c_omp_depend_t_p (TREE_TYPE (t)))
16884 : : {
16885 : 2 : error_at (OMP_CLAUSE_LOCATION (c),
16886 : : "%qE should not have %<omp_depend_t%> type in "
16887 : : "%<depend%> clause with dependence type other than "
16888 : : "%<depobj%>", t);
16889 : 2 : remove = true;
16890 : : }
16891 : 12 : if (!remove)
16892 : : {
16893 : 411 : if (t == ridpointers[RID_OMP_ALL_MEMORY])
16894 : 12 : t = null_pointer_node;
16895 : : else
16896 : : {
16897 : 399 : tree addr = build_unary_op (OMP_CLAUSE_LOCATION (c),
16898 : : ADDR_EXPR, t, false);
16899 : 399 : if (addr == error_mark_node)
16900 : : {
16901 : : remove = true;
16902 : : break;
16903 : : }
16904 : 399 : t = build_indirect_ref (OMP_CLAUSE_LOCATION (c), addr,
16905 : : RO_UNARY_STAR);
16906 : 399 : if (t == error_mark_node)
16907 : : {
16908 : : remove = true;
16909 : : break;
16910 : : }
16911 : : }
16912 : 411 : if (TREE_CODE (OMP_CLAUSE_DECL (c)) == TREE_LIST
16913 : 31 : && TREE_PURPOSE (OMP_CLAUSE_DECL (c))
16914 : 442 : && (TREE_CODE (TREE_PURPOSE (OMP_CLAUSE_DECL (c)))
16915 : : == TREE_VEC))
16916 : 31 : TREE_VALUE (OMP_CLAUSE_DECL (c)) = t;
16917 : : else
16918 : 380 : OMP_CLAUSE_DECL (c) = t;
16919 : : }
16920 : : break;
16921 : :
16922 : 6471 : case OMP_CLAUSE_MAP:
16923 : 6471 : if (OMP_CLAUSE_MAP_IMPLICIT (c) && !implicit_moved)
16924 : 91 : goto move_implicit;
16925 : 6380 : if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_PUSH_MAPPER_NAME
16926 : 6380 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POP_MAPPER_NAME)
16927 : : {
16928 : : remove = true;
16929 : : break;
16930 : : }
16931 : : /* FALLTHRU */
16932 : 9356 : case OMP_CLAUSE_TO:
16933 : 9356 : case OMP_CLAUSE_FROM:
16934 : 9356 : case OMP_CLAUSE__CACHE_:
16935 : 9356 : {
16936 : 9356 : using namespace omp_addr_tokenizer;
16937 : 9356 : auto_vec<omp_addr_token *, 10> addr_tokens;
16938 : :
16939 : 9356 : t = OMP_CLAUSE_DECL (c);
16940 : 9356 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
16941 : : {
16942 : 1965 : grp_start_p = pc;
16943 : 1965 : grp_sentinel = OMP_CLAUSE_CHAIN (c);
16944 : :
16945 : 1965 : if (handle_omp_array_sections (c, ort))
16946 : : remove = true;
16947 : : else
16948 : : {
16949 : 1825 : t = OMP_CLAUSE_DECL (c);
16950 : 1825 : if (!omp_mappable_type (TREE_TYPE (t)))
16951 : : {
16952 : 2 : error_at (OMP_CLAUSE_LOCATION (c),
16953 : : "array section does not have mappable type "
16954 : : "in %qs clause",
16955 : 1 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
16956 : 1 : remove = true;
16957 : : }
16958 : 1824 : else if (TYPE_ATOMIC (TREE_TYPE (t)))
16959 : : {
16960 : 2 : error_at (OMP_CLAUSE_LOCATION (c),
16961 : : "%<_Atomic%> %qE in %qs clause", t,
16962 : 1 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
16963 : 1 : remove = true;
16964 : : }
16965 : 2466 : while (TREE_CODE (t) == ARRAY_REF)
16966 : 641 : t = TREE_OPERAND (t, 0);
16967 : :
16968 : 1825 : c_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
16969 : :
16970 : 1825 : if (!omp_parse_expr (addr_tokens, t))
16971 : : {
16972 : 0 : sorry_at (OMP_CLAUSE_LOCATION (c),
16973 : : "unsupported map expression %qE",
16974 : 0 : OMP_CLAUSE_DECL (c));
16975 : 0 : remove = true;
16976 : 0 : break;
16977 : : }
16978 : :
16979 : : /* This check is to determine if this will be the only map
16980 : : node created for this clause. Otherwise, we'll check
16981 : : the following FIRSTPRIVATE_POINTER or ATTACH_DETACH
16982 : : node on the next iteration(s) of the loop. */
16983 : 3632 : if (addr_tokens.length () >= 4
16984 : 302 : && addr_tokens[0]->type == STRUCTURE_BASE
16985 : 302 : && addr_tokens[0]->u.structure_base_kind == BASE_DECL
16986 : 302 : && addr_tokens[1]->type == ACCESS_METHOD
16987 : 302 : && addr_tokens[2]->type == COMPONENT_SELECTOR
16988 : 302 : && addr_tokens[3]->type == ACCESS_METHOD
16989 : 2066 : && (addr_tokens[3]->u.access_kind == ACCESS_DIRECT
16990 : 188 : || (addr_tokens[3]->u.access_kind
16991 : : == ACCESS_INDEXED_ARRAY)))
16992 : : {
16993 : 55 : tree rt = addr_tokens[1]->expr;
16994 : :
16995 : 55 : gcc_assert (DECL_P (rt));
16996 : :
16997 : 55 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
16998 : 50 : && OMP_CLAUSE_MAP_IMPLICIT (c)
16999 : 55 : && (bitmap_bit_p (&map_head, DECL_UID (rt))
17000 : 0 : || bitmap_bit_p (&map_field_head, DECL_UID (rt))
17001 : 0 : || bitmap_bit_p (&map_firstprivate_head,
17002 : 0 : DECL_UID (rt))))
17003 : : {
17004 : : remove = true;
17005 : : break;
17006 : : }
17007 : 55 : if (bitmap_bit_p (&map_field_head, DECL_UID (rt)))
17008 : : break;
17009 : 37 : if (bitmap_bit_p (&map_head, DECL_UID (rt)))
17010 : : {
17011 : 0 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
17012 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
17013 : : "%qD appears more than once in motion "
17014 : : "clauses", rt);
17015 : 0 : else if (openacc)
17016 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
17017 : : "%qD appears more than once in data "
17018 : : "clauses", rt);
17019 : : else
17020 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
17021 : : "%qD appears more than once in map "
17022 : : "clauses", rt);
17023 : : remove = true;
17024 : : }
17025 : : else
17026 : : {
17027 : 37 : bitmap_set_bit (&map_head, DECL_UID (rt));
17028 : 37 : bitmap_set_bit (&map_field_head, DECL_UID (rt));
17029 : : }
17030 : : }
17031 : 1825 : }
17032 : 1947 : if (c_oacc_check_attachments (c))
17033 : 2 : remove = true;
17034 : 1947 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
17035 : 1783 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
17036 : 1772 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
17037 : 1965 : && !OMP_CLAUSE_SIZE (c))
17038 : : /* In this case, we have a single array element which is a
17039 : : pointer, and we already set OMP_CLAUSE_SIZE in
17040 : : handle_omp_array_sections above. For attach/detach
17041 : : clauses, reset the OMP_CLAUSE_SIZE (representing a bias)
17042 : : to zero here. */
17043 : 10 : OMP_CLAUSE_SIZE (c) = size_zero_node;
17044 : : break;
17045 : : }
17046 : 7391 : else if (!omp_parse_expr (addr_tokens, t))
17047 : : {
17048 : 0 : sorry_at (OMP_CLAUSE_LOCATION (c),
17049 : : "unsupported map expression %qE",
17050 : 0 : OMP_CLAUSE_DECL (c));
17051 : 0 : remove = true;
17052 : 0 : break;
17053 : : }
17054 : 7391 : if (t == error_mark_node)
17055 : : {
17056 : : remove = true;
17057 : : break;
17058 : : }
17059 : : /* OpenACC attach / detach clauses must be pointers. */
17060 : 7385 : if (c_oacc_check_attachments (c))
17061 : : {
17062 : : remove = true;
17063 : : break;
17064 : : }
17065 : 7381 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
17066 : 4563 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
17067 : 4536 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
17068 : 7423 : && !OMP_CLAUSE_SIZE (c))
17069 : : /* For attach/detach clauses, set OMP_CLAUSE_SIZE (representing a
17070 : : bias) to zero here, so it is not set erroneously to the pointer
17071 : : size later on in gimplify.cc. */
17072 : 28 : OMP_CLAUSE_SIZE (c) = size_zero_node;
17073 : :
17074 : 7381 : c_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
17075 : :
17076 : 7381 : if (!ai.check_clause (c))
17077 : : {
17078 : : remove = true;
17079 : : break;
17080 : : }
17081 : :
17082 : 7373 : if (!ai.map_supported_p ())
17083 : : {
17084 : 10 : sorry_at (OMP_CLAUSE_LOCATION (c),
17085 : : "unsupported map expression %qE",
17086 : 5 : OMP_CLAUSE_DECL (c));
17087 : 5 : remove = true;
17088 : 5 : break;
17089 : : }
17090 : :
17091 : 14736 : gcc_assert ((addr_tokens[0]->type == ARRAY_BASE
17092 : : || addr_tokens[0]->type == STRUCTURE_BASE)
17093 : : && addr_tokens[1]->type == ACCESS_METHOD);
17094 : :
17095 : 7368 : t = addr_tokens[1]->expr;
17096 : :
17097 : 7368 : if (addr_tokens[0]->u.structure_base_kind != BASE_DECL)
17098 : 0 : goto skip_decl_checks;
17099 : :
17100 : : /* For OpenMP, we can access a struct "t" and "t.d" on the same
17101 : : mapping. OpenACC allows multiple fields of the same structure
17102 : : to be written. */
17103 : 7368 : if (addr_tokens[0]->type == STRUCTURE_BASE
17104 : 7368 : && (bitmap_bit_p (&map_field_head, DECL_UID (t))
17105 : 238 : || (!openacc && bitmap_bit_p (&map_head, DECL_UID (t)))))
17106 : 246 : goto skip_decl_checks;
17107 : :
17108 : 7122 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
17109 : : {
17110 : 3 : if (ort != C_ORT_ACC && EXPR_P (t))
17111 : : break;
17112 : :
17113 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
17114 : : "%qE is not a variable in %qs clause", t,
17115 : 3 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
17116 : 3 : remove = true;
17117 : : }
17118 : 7119 : else if (VAR_P (t) && DECL_THREAD_LOCAL_P (t))
17119 : : {
17120 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
17121 : : "%qD is threadprivate variable in %qs clause", t,
17122 : 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
17123 : 0 : remove = true;
17124 : : }
17125 : 7119 : else if ((OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
17126 : 4308 : || (OMP_CLAUSE_MAP_KIND (c)
17127 : : != GOMP_MAP_FIRSTPRIVATE_POINTER))
17128 : 10399 : && !c_mark_addressable (t))
17129 : : remove = true;
17130 : 7119 : else if (!(OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
17131 : 4308 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
17132 : 4308 : || (OMP_CLAUSE_MAP_KIND (c)
17133 : : == GOMP_MAP_FIRSTPRIVATE_POINTER)
17134 : 3280 : || (OMP_CLAUSE_MAP_KIND (c)
17135 : : == GOMP_MAP_FORCE_DEVICEPTR)))
17136 : 6033 : && t == OMP_CLAUSE_DECL (c)
17137 : 12916 : && !omp_mappable_type (TREE_TYPE (t)))
17138 : : {
17139 : 16 : error_at (OMP_CLAUSE_LOCATION (c),
17140 : : "%qD does not have a mappable type in %qs clause", t,
17141 : 8 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
17142 : 8 : remove = true;
17143 : : }
17144 : 7111 : else if (TREE_TYPE (t) == error_mark_node)
17145 : : remove = true;
17146 : 7110 : else if (TYPE_ATOMIC (strip_array_types (TREE_TYPE (t))))
17147 : : {
17148 : 8 : error_at (OMP_CLAUSE_LOCATION (c),
17149 : : "%<_Atomic%> %qE in %qs clause", t,
17150 : 4 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
17151 : 4 : remove = true;
17152 : : }
17153 : 7106 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
17154 : 4298 : && OMP_CLAUSE_MAP_IMPLICIT (c)
17155 : 7270 : && (bitmap_bit_p (&map_head, DECL_UID (t))
17156 : 128 : || bitmap_bit_p (&map_field_head, DECL_UID (t))
17157 : 128 : || bitmap_bit_p (&map_firstprivate_head,
17158 : 128 : DECL_UID (t))))
17159 : : remove = true;
17160 : 7069 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
17161 : 7069 : && (OMP_CLAUSE_MAP_KIND (c)
17162 : : == GOMP_MAP_FIRSTPRIVATE_POINTER))
17163 : : {
17164 : 1026 : if (bitmap_bit_p (&generic_head, DECL_UID (t))
17165 : 1026 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
17166 : 2051 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
17167 : : {
17168 : 5 : error_at (OMP_CLAUSE_LOCATION (c),
17169 : : "%qD appears more than once in data clauses", t);
17170 : 5 : remove = true;
17171 : : }
17172 : 1021 : else if (bitmap_bit_p (&map_head, DECL_UID (t))
17173 : 4 : && !bitmap_bit_p (&map_field_head, DECL_UID (t))
17174 : 1023 : && openacc)
17175 : : {
17176 : 1 : error_at (OMP_CLAUSE_LOCATION (c),
17177 : : "%qD appears more than once in data clauses", t);
17178 : 1 : remove = true;
17179 : : }
17180 : : else
17181 : 1020 : bitmap_set_bit (&map_firstprivate_head, DECL_UID (t));
17182 : : }
17183 : 6043 : else if (bitmap_bit_p (&map_head, DECL_UID (t))
17184 : 59 : && !bitmap_bit_p (&map_field_head, DECL_UID (t))
17185 : 13 : && ort != C_ORT_OMP
17186 : 6056 : && ort != C_ORT_OMP_EXIT_DATA)
17187 : : {
17188 : 10 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
17189 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
17190 : : "%qD appears more than once in motion clauses", t);
17191 : 10 : else if (openacc)
17192 : 7 : error_at (OMP_CLAUSE_LOCATION (c),
17193 : : "%qD appears more than once in data clauses", t);
17194 : : else
17195 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
17196 : : "%qD appears more than once in map clauses", t);
17197 : : remove = true;
17198 : : }
17199 : 6033 : else if (openacc && bitmap_bit_p (&generic_head, DECL_UID (t)))
17200 : : {
17201 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
17202 : : "%qD appears more than once in data clauses", t);
17203 : 0 : remove = true;
17204 : : }
17205 : 6033 : else if (bitmap_bit_p (&firstprivate_head, DECL_UID (t))
17206 : 6033 : || bitmap_bit_p (&is_on_device_head, DECL_UID (t)))
17207 : : {
17208 : 9 : if (openacc)
17209 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
17210 : : "%qD appears more than once in data clauses", t);
17211 : : else
17212 : 9 : error_at (OMP_CLAUSE_LOCATION (c),
17213 : : "%qD appears both in data and map clauses", t);
17214 : : remove = true;
17215 : : }
17216 : 6024 : else if (!omp_access_chain_p (addr_tokens, 1))
17217 : : {
17218 : 6024 : bitmap_set_bit (&map_head, DECL_UID (t));
17219 : 6024 : if (t != OMP_CLAUSE_DECL (c)
17220 : 6024 : && TREE_CODE (OMP_CLAUSE_DECL (c)) == COMPONENT_REF)
17221 : 232 : bitmap_set_bit (&map_field_head, DECL_UID (t));
17222 : : }
17223 : :
17224 : 0 : skip_decl_checks:
17225 : : /* If we call omp_expand_map_clause in handle_omp_array_sections,
17226 : : the containing loop (here) iterates through the new nodes
17227 : : created by that expansion. Avoid expanding those again (just
17228 : : by checking the node type). */
17229 : 7368 : if (!remove
17230 : 7368 : && ort != C_ORT_DECLARE_SIMD
17231 : 7368 : && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
17232 : 4476 : || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FIRSTPRIVATE_POINTER
17233 : 3456 : && (OMP_CLAUSE_MAP_KIND (c)
17234 : : != GOMP_MAP_FIRSTPRIVATE_REFERENCE)
17235 : 3456 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ALWAYS_POINTER
17236 : 3456 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH_DETACH
17237 : 3157 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
17238 : 3130 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH)))
17239 : : {
17240 : 5929 : grp_start_p = pc;
17241 : 5929 : grp_sentinel = OMP_CLAUSE_CHAIN (c);
17242 : 5929 : tree nc = ai.expand_map_clause (c, OMP_CLAUSE_DECL (c),
17243 : : addr_tokens, ort);
17244 : 5929 : if (nc != error_mark_node)
17245 : 5929 : c = nc;
17246 : : }
17247 : 9369 : }
17248 : 7368 : break;
17249 : :
17250 : 222 : case OMP_CLAUSE_ENTER:
17251 : 222 : case OMP_CLAUSE_LINK:
17252 : 222 : t = OMP_CLAUSE_DECL (c);
17253 : 222 : const char *cname;
17254 : 222 : cname = omp_clause_code_name[OMP_CLAUSE_CODE (c)];
17255 : 222 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER
17256 : 222 : && OMP_CLAUSE_ENTER_TO (c))
17257 : : cname = "to";
17258 : 222 : if (TREE_CODE (t) == FUNCTION_DECL
17259 : 222 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
17260 : : ;
17261 : 145 : else if (!VAR_P (t))
17262 : : {
17263 : 1 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
17264 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
17265 : : "%qE is neither a variable nor a function name in "
17266 : : "clause %qs", t, cname);
17267 : : else
17268 : 1 : error_at (OMP_CLAUSE_LOCATION (c),
17269 : : "%qE is not a variable in clause %qs", t, cname);
17270 : : remove = true;
17271 : : }
17272 : 144 : else if (DECL_THREAD_LOCAL_P (t))
17273 : : {
17274 : 2 : error_at (OMP_CLAUSE_LOCATION (c),
17275 : : "%qD is threadprivate variable in %qs clause", t,
17276 : : cname);
17277 : 2 : remove = true;
17278 : : }
17279 : 142 : else if (!omp_mappable_type (TREE_TYPE (t)))
17280 : : {
17281 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
17282 : : "%qD does not have a mappable type in %qs clause", t,
17283 : : cname);
17284 : 6 : remove = true;
17285 : : }
17286 : 8 : if (remove)
17287 : : break;
17288 : 213 : if (bitmap_bit_p (&generic_head, DECL_UID (t)))
17289 : : {
17290 : 8 : error_at (OMP_CLAUSE_LOCATION (c),
17291 : : "%qE appears more than once on the same "
17292 : : "%<declare target%> directive", t);
17293 : 8 : remove = true;
17294 : : }
17295 : : else
17296 : 205 : bitmap_set_bit (&generic_head, DECL_UID (t));
17297 : : break;
17298 : :
17299 : 117 : case OMP_CLAUSE_UNIFORM:
17300 : 117 : t = OMP_CLAUSE_DECL (c);
17301 : 117 : if (TREE_CODE (t) != PARM_DECL)
17302 : : {
17303 : 0 : if (DECL_P (t))
17304 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
17305 : : "%qD is not an argument in %<uniform%> clause", t);
17306 : : else
17307 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
17308 : : "%qE is not an argument in %<uniform%> clause", t);
17309 : : remove = true;
17310 : : break;
17311 : : }
17312 : : /* map_head bitmap is used as uniform_head if declare_simd. */
17313 : 117 : bitmap_set_bit (&map_head, DECL_UID (t));
17314 : 117 : goto check_dup_generic;
17315 : :
17316 : 160 : case OMP_CLAUSE_IS_DEVICE_PTR:
17317 : 160 : case OMP_CLAUSE_USE_DEVICE_PTR:
17318 : 160 : t = OMP_CLAUSE_DECL (c);
17319 : 160 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
17320 : 122 : bitmap_set_bit (&is_on_device_head, DECL_UID (t));
17321 : 160 : if (TREE_CODE (TREE_TYPE (t)) != POINTER_TYPE)
17322 : : {
17323 : 21 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
17324 : 21 : && !openacc)
17325 : : {
17326 : 1 : error_at (OMP_CLAUSE_LOCATION (c),
17327 : : "%qs variable is not a pointer",
17328 : 1 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
17329 : 1 : remove = true;
17330 : : }
17331 : 20 : else if (TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE)
17332 : : {
17333 : 4 : error_at (OMP_CLAUSE_LOCATION (c),
17334 : : "%qs variable is neither a pointer nor an array",
17335 : 4 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
17336 : 4 : remove = true;
17337 : : }
17338 : : }
17339 : 160 : goto check_dup_generic;
17340 : :
17341 : 88 : case OMP_CLAUSE_HAS_DEVICE_ADDR:
17342 : 88 : t = OMP_CLAUSE_DECL (c);
17343 : 88 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
17344 : : {
17345 : 11 : if (handle_omp_array_sections (c, ort))
17346 : : remove = true;
17347 : : else
17348 : : {
17349 : 11 : t = OMP_CLAUSE_DECL (c);
17350 : 24 : while (TREE_CODE (t) == ARRAY_REF)
17351 : 13 : t = TREE_OPERAND (t, 0);
17352 : : }
17353 : : }
17354 : 88 : bitmap_set_bit (&is_on_device_head, DECL_UID (t));
17355 : 88 : if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
17356 : 88 : c_mark_addressable (t);
17357 : 88 : goto check_dup_generic_t;
17358 : :
17359 : 36 : case OMP_CLAUSE_USE_DEVICE_ADDR:
17360 : 36 : t = OMP_CLAUSE_DECL (c);
17361 : 36 : if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
17362 : 36 : c_mark_addressable (t);
17363 : 36 : goto check_dup_generic;
17364 : :
17365 : 4788 : case OMP_CLAUSE_NOWAIT:
17366 : 4788 : if (copyprivate_seen)
17367 : : {
17368 : 1 : error_at (OMP_CLAUSE_LOCATION (c),
17369 : : "%<nowait%> clause must not be used together "
17370 : : "with %<copyprivate%> clause");
17371 : 1 : remove = true;
17372 : 1 : break;
17373 : : }
17374 : 4787 : nowait_clause = pc;
17375 : 4787 : pc = &OMP_CLAUSE_CHAIN (c);
17376 : 4787 : continue;
17377 : :
17378 : 522 : case OMP_CLAUSE_ORDER:
17379 : 522 : if (ordered_clause)
17380 : : {
17381 : 2 : error_at (OMP_CLAUSE_LOCATION (c),
17382 : : "%<order%> clause must not be used together "
17383 : : "with %<ordered%> clause");
17384 : 2 : remove = true;
17385 : 2 : break;
17386 : : }
17387 : 520 : else if (order_clause)
17388 : : {
17389 : : /* Silently remove duplicates. */
17390 : : remove = true;
17391 : : break;
17392 : : }
17393 : 512 : order_clause = pc;
17394 : 512 : pc = &OMP_CLAUSE_CHAIN (c);
17395 : 512 : continue;
17396 : :
17397 : 32 : case OMP_CLAUSE_DETACH:
17398 : 32 : t = OMP_CLAUSE_DECL (c);
17399 : 32 : if (detach_seen)
17400 : : {
17401 : 1 : error_at (OMP_CLAUSE_LOCATION (c),
17402 : : "too many %qs clauses on a task construct",
17403 : : "detach");
17404 : 1 : remove = true;
17405 : 1 : break;
17406 : : }
17407 : 31 : detach_seen = pc;
17408 : 31 : pc = &OMP_CLAUSE_CHAIN (c);
17409 : 31 : c_mark_addressable (t);
17410 : 31 : continue;
17411 : :
17412 : 14516 : case OMP_CLAUSE_IF:
17413 : 14516 : case OMP_CLAUSE_SELF:
17414 : 14516 : case OMP_CLAUSE_NUM_THREADS:
17415 : 14516 : case OMP_CLAUSE_NUM_TEAMS:
17416 : 14516 : case OMP_CLAUSE_THREAD_LIMIT:
17417 : 14516 : case OMP_CLAUSE_DEFAULT:
17418 : 14516 : case OMP_CLAUSE_UNTIED:
17419 : 14516 : case OMP_CLAUSE_COLLAPSE:
17420 : 14516 : case OMP_CLAUSE_FINAL:
17421 : 14516 : case OMP_CLAUSE_DEVICE:
17422 : 14516 : case OMP_CLAUSE_DIST_SCHEDULE:
17423 : 14516 : case OMP_CLAUSE_PARALLEL:
17424 : 14516 : case OMP_CLAUSE_FOR:
17425 : 14516 : case OMP_CLAUSE_SECTIONS:
17426 : 14516 : case OMP_CLAUSE_TASKGROUP:
17427 : 14516 : case OMP_CLAUSE_PROC_BIND:
17428 : 14516 : case OMP_CLAUSE_DEVICE_TYPE:
17429 : 14516 : case OMP_CLAUSE_PRIORITY:
17430 : 14516 : case OMP_CLAUSE_THREADS:
17431 : 14516 : case OMP_CLAUSE_SIMD:
17432 : 14516 : case OMP_CLAUSE_HINT:
17433 : 14516 : case OMP_CLAUSE_FILTER:
17434 : 14516 : case OMP_CLAUSE_DEFAULTMAP:
17435 : 14516 : case OMP_CLAUSE_BIND:
17436 : 14516 : case OMP_CLAUSE_NUM_GANGS:
17437 : 14516 : case OMP_CLAUSE_NUM_WORKERS:
17438 : 14516 : case OMP_CLAUSE_VECTOR_LENGTH:
17439 : 14516 : case OMP_CLAUSE_ASYNC:
17440 : 14516 : case OMP_CLAUSE_WAIT:
17441 : 14516 : case OMP_CLAUSE_AUTO:
17442 : 14516 : case OMP_CLAUSE_INDEPENDENT:
17443 : 14516 : case OMP_CLAUSE_SEQ:
17444 : 14516 : case OMP_CLAUSE_GANG:
17445 : 14516 : case OMP_CLAUSE_WORKER:
17446 : 14516 : case OMP_CLAUSE_VECTOR:
17447 : 14516 : case OMP_CLAUSE_TILE:
17448 : 14516 : case OMP_CLAUSE_IF_PRESENT:
17449 : 14516 : case OMP_CLAUSE_FINALIZE:
17450 : 14516 : case OMP_CLAUSE_NOHOST:
17451 : 14516 : case OMP_CLAUSE_INDIRECT:
17452 : 14516 : case OMP_CLAUSE_NOVARIANTS:
17453 : 14516 : case OMP_CLAUSE_NOCONTEXT:
17454 : 14516 : pc = &OMP_CLAUSE_CHAIN (c);
17455 : 14516 : continue;
17456 : :
17457 : 62 : case OMP_CLAUSE_GRAINSIZE:
17458 : 62 : grainsize_seen = pc;
17459 : 62 : pc = &OMP_CLAUSE_CHAIN (c);
17460 : 62 : continue;
17461 : :
17462 : 49 : case OMP_CLAUSE_NUM_TASKS:
17463 : 49 : num_tasks_seen = true;
17464 : 49 : pc = &OMP_CLAUSE_CHAIN (c);
17465 : 49 : continue;
17466 : :
17467 : 78 : case OMP_CLAUSE_MERGEABLE:
17468 : 78 : mergeable_seen = true;
17469 : 78 : pc = &OMP_CLAUSE_CHAIN (c);
17470 : 78 : continue;
17471 : :
17472 : 18 : case OMP_CLAUSE_NOGROUP:
17473 : 18 : nogroup_seen = pc;
17474 : 18 : pc = &OMP_CLAUSE_CHAIN (c);
17475 : 18 : continue;
17476 : :
17477 : 3463 : case OMP_CLAUSE_SCHEDULE:
17478 : 3463 : schedule_clause = c;
17479 : 3463 : pc = &OMP_CLAUSE_CHAIN (c);
17480 : 3463 : continue;
17481 : :
17482 : 303 : case OMP_CLAUSE_ORDERED:
17483 : 303 : ordered_clause = c;
17484 : 303 : if (order_clause)
17485 : : {
17486 : 2 : error_at (OMP_CLAUSE_LOCATION (*order_clause),
17487 : : "%<order%> clause must not be used together "
17488 : : "with %<ordered%> clause");
17489 : 2 : *order_clause = OMP_CLAUSE_CHAIN (*order_clause);
17490 : 2 : order_clause = NULL;
17491 : : }
17492 : 303 : pc = &OMP_CLAUSE_CHAIN (c);
17493 : 303 : continue;
17494 : :
17495 : 223 : case OMP_CLAUSE_SAFELEN:
17496 : 223 : safelen = c;
17497 : 223 : pc = &OMP_CLAUSE_CHAIN (c);
17498 : 223 : continue;
17499 : 313 : case OMP_CLAUSE_SIMDLEN:
17500 : 313 : simdlen = c;
17501 : 313 : pc = &OMP_CLAUSE_CHAIN (c);
17502 : 313 : continue;
17503 : :
17504 : 69 : case OMP_CLAUSE_FULL:
17505 : 69 : full_seen = pc;
17506 : 69 : pc = &OMP_CLAUSE_CHAIN (c);
17507 : 69 : continue;
17508 : :
17509 : 223 : case OMP_CLAUSE_PARTIAL:
17510 : 223 : partial_seen = true;
17511 : 223 : pc = &OMP_CLAUSE_CHAIN (c);
17512 : 223 : continue;
17513 : :
17514 : 0 : case OMP_CLAUSE_SIZES:
17515 : 0 : pc = &OMP_CLAUSE_CHAIN (c);
17516 : 0 : continue;
17517 : :
17518 : 199 : case OMP_CLAUSE_INBRANCH:
17519 : 199 : case OMP_CLAUSE_NOTINBRANCH:
17520 : 199 : if (branch_seen)
17521 : : {
17522 : 1 : error_at (OMP_CLAUSE_LOCATION (c),
17523 : : "%<inbranch%> clause is incompatible with "
17524 : : "%<notinbranch%>");
17525 : 1 : remove = true;
17526 : 1 : break;
17527 : : }
17528 : 198 : branch_seen = true;
17529 : 198 : pc = &OMP_CLAUSE_CHAIN (c);
17530 : 198 : continue;
17531 : :
17532 : 367 : case OMP_CLAUSE_INCLUSIVE:
17533 : 367 : case OMP_CLAUSE_EXCLUSIVE:
17534 : 367 : need_complete = true;
17535 : 367 : need_implicitly_determined = true;
17536 : 367 : t = OMP_CLAUSE_DECL (c);
17537 : 367 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
17538 : : {
17539 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
17540 : : "%qE is not a variable in clause %qs", t,
17541 : 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
17542 : 0 : remove = true;
17543 : : }
17544 : : break;
17545 : :
17546 : 152 : case OMP_CLAUSE_INIT:
17547 : 152 : init_seen = true;
17548 : 152 : if (!OMP_CLAUSE_INIT_TARGETSYNC (c))
17549 : 71 : init_no_targetsync_clause = c;
17550 : : /* FALLTHRU */
17551 : 242 : case OMP_CLAUSE_DESTROY:
17552 : 242 : case OMP_CLAUSE_USE:
17553 : 242 : init_use_destroy_seen = true;
17554 : 242 : t = OMP_CLAUSE_DECL (c);
17555 : 242 : if (bitmap_bit_p (&generic_head, DECL_UID (t)))
17556 : : {
17557 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
17558 : : "%qD appears more than once in action clauses", t);
17559 : 3 : remove = true;
17560 : 3 : break;
17561 : : }
17562 : 239 : bitmap_set_bit (&generic_head, DECL_UID (t));
17563 : : /* FALLTHRU */
17564 : 297 : case OMP_CLAUSE_INTEROP:
17565 : 297 : if (/* ort == C_ORT_OMP_INTEROP [uncomment for depobj init] */
17566 : 297 : !c_omp_interop_t_p (TREE_TYPE (OMP_CLAUSE_DECL (c))))
17567 : : {
17568 : 40 : error_at (OMP_CLAUSE_LOCATION (c),
17569 : : "%qD must be of %<omp_interop_t%>",
17570 : 20 : OMP_CLAUSE_DECL (c));
17571 : 20 : remove = true;
17572 : : }
17573 : 277 : else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INIT
17574 : 132 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DESTROY)
17575 : 317 : && TREE_READONLY (OMP_CLAUSE_DECL (c)))
17576 : : {
17577 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
17578 : 6 : "%qD shall not be const", OMP_CLAUSE_DECL (c));
17579 : 6 : remove = true;
17580 : : }
17581 : 297 : pc = &OMP_CLAUSE_CHAIN (c);
17582 : 297 : break;
17583 : 0 : default:
17584 : 0 : gcc_unreachable ();
17585 : 24845 : }
17586 : :
17587 : 22557 : if (!remove)
17588 : : {
17589 : 21999 : t = OMP_CLAUSE_DECL (c);
17590 : :
17591 : 21999 : if (need_complete)
17592 : : {
17593 : 3930 : t = require_complete_type (OMP_CLAUSE_LOCATION (c), t);
17594 : 3930 : if (t == error_mark_node)
17595 : 7 : remove = true;
17596 : : }
17597 : :
17598 : 21999 : if (need_implicitly_determined)
17599 : : {
17600 : 9523 : const char *share_name = NULL;
17601 : :
17602 : 9523 : if (VAR_P (t) && DECL_THREAD_LOCAL_P (t))
17603 : : share_name = "threadprivate";
17604 : 9517 : else switch (c_omp_predetermined_sharing (t))
17605 : : {
17606 : : case OMP_CLAUSE_DEFAULT_UNSPECIFIED:
17607 : : break;
17608 : 20 : case OMP_CLAUSE_DEFAULT_SHARED:
17609 : 20 : if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
17610 : 12 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE)
17611 : 28 : && c_omp_predefined_variable (t))
17612 : : /* The __func__ variable and similar function-local
17613 : : predefined variables may be listed in a shared or
17614 : : firstprivate clause. */
17615 : : break;
17616 : : share_name = "shared";
17617 : : break;
17618 : : case OMP_CLAUSE_DEFAULT_PRIVATE:
17619 : : share_name = "private";
17620 : : break;
17621 : 0 : default:
17622 : 0 : gcc_unreachable ();
17623 : : }
17624 : : if (share_name)
17625 : : {
17626 : 20 : error_at (OMP_CLAUSE_LOCATION (c),
17627 : : "%qE is predetermined %qs for %qs",
17628 : : t, share_name,
17629 : 10 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
17630 : 10 : remove = true;
17631 : : }
17632 : 9513 : else if (TREE_READONLY (t)
17633 : 23 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
17634 : 9526 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FIRSTPRIVATE)
17635 : : {
17636 : 4 : error_at (OMP_CLAUSE_LOCATION (c),
17637 : : "%<const%> qualified %qE may appear only in "
17638 : : "%<shared%> or %<firstprivate%> clauses", t);
17639 : 4 : remove = true;
17640 : : }
17641 : : }
17642 : : }
17643 : :
17644 : 21999 : if (remove)
17645 : : {
17646 : 579 : if (grp_start_p)
17647 : : {
17648 : : /* If we found a clause to remove, we want to remove the whole
17649 : : expanded group, otherwise gimplify
17650 : : (omp_resolve_clause_dependencies) can get confused. */
17651 : 154 : *grp_start_p = grp_sentinel;
17652 : 154 : pc = grp_start_p;
17653 : 154 : grp_start_p = NULL;
17654 : : }
17655 : : else
17656 : 425 : *pc = OMP_CLAUSE_CHAIN (c);
17657 : : }
17658 : : else
17659 : 21978 : pc = &OMP_CLAUSE_CHAIN (c);
17660 : : }
17661 : :
17662 : 29172 : if (simdlen
17663 : 29172 : && safelen
17664 : 29289 : && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen),
17665 : 117 : OMP_CLAUSE_SIMDLEN_EXPR (simdlen)))
17666 : : {
17667 : 0 : error_at (OMP_CLAUSE_LOCATION (simdlen),
17668 : : "%<simdlen%> clause value is bigger than "
17669 : : "%<safelen%> clause value");
17670 : 0 : OMP_CLAUSE_SIMDLEN_EXPR (simdlen)
17671 : 0 : = OMP_CLAUSE_SAFELEN_EXPR (safelen);
17672 : : }
17673 : :
17674 : 29172 : if (ordered_clause
17675 : 29172 : && schedule_clause
17676 : 29172 : && (OMP_CLAUSE_SCHEDULE_KIND (schedule_clause)
17677 : : & OMP_CLAUSE_SCHEDULE_NONMONOTONIC))
17678 : : {
17679 : 7 : error_at (OMP_CLAUSE_LOCATION (schedule_clause),
17680 : : "%<nonmonotonic%> schedule modifier specified together "
17681 : : "with %<ordered%> clause");
17682 : 14 : OMP_CLAUSE_SCHEDULE_KIND (schedule_clause)
17683 : 7 : = (enum omp_clause_schedule_kind)
17684 : 7 : (OMP_CLAUSE_SCHEDULE_KIND (schedule_clause)
17685 : : & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC);
17686 : : }
17687 : :
17688 : 29172 : if (reduction_seen < 0 && ordered_clause)
17689 : : {
17690 : 2 : error_at (OMP_CLAUSE_LOCATION (ordered_clause),
17691 : : "%qs clause specified together with %<inscan%> "
17692 : : "%<reduction%> clause", "ordered");
17693 : 2 : reduction_seen = -2;
17694 : : }
17695 : :
17696 : 29172 : if (reduction_seen < 0 && schedule_clause)
17697 : : {
17698 : 3 : error_at (OMP_CLAUSE_LOCATION (schedule_clause),
17699 : : "%qs clause specified together with %<inscan%> "
17700 : : "%<reduction%> clause", "schedule");
17701 : 3 : reduction_seen = -2;
17702 : : }
17703 : :
17704 : 29172 : if (linear_variable_step_check
17705 : 29172 : || reduction_seen == -2
17706 : : || allocate_seen
17707 : 29160 : || target_in_reduction_seen)
17708 : 5145 : for (pc = &clauses, c = clauses; c ; c = *pc)
17709 : : {
17710 : 4556 : bool remove = false;
17711 : 4556 : if (allocate_seen)
17712 : 4398 : switch (OMP_CLAUSE_CODE (c))
17713 : : {
17714 : 430 : case OMP_CLAUSE_REDUCTION:
17715 : 430 : case OMP_CLAUSE_IN_REDUCTION:
17716 : 430 : case OMP_CLAUSE_TASK_REDUCTION:
17717 : 430 : if (TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF)
17718 : : {
17719 : 23 : t = TREE_OPERAND (OMP_CLAUSE_DECL (c), 0);
17720 : 23 : if (TREE_CODE (t) == POINTER_PLUS_EXPR)
17721 : 0 : t = TREE_OPERAND (t, 0);
17722 : 23 : if (TREE_CODE (t) == ADDR_EXPR
17723 : 10 : || INDIRECT_REF_P (t))
17724 : 13 : t = TREE_OPERAND (t, 0);
17725 : 23 : if (DECL_P (t))
17726 : 23 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
17727 : : break;
17728 : : }
17729 : : /* FALLTHRU */
17730 : 1302 : case OMP_CLAUSE_PRIVATE:
17731 : 1302 : case OMP_CLAUSE_FIRSTPRIVATE:
17732 : 1302 : case OMP_CLAUSE_LASTPRIVATE:
17733 : 1302 : case OMP_CLAUSE_LINEAR:
17734 : 1302 : if (DECL_P (OMP_CLAUSE_DECL (c)))
17735 : 2604 : bitmap_clear_bit (&aligned_head,
17736 : 1302 : DECL_UID (OMP_CLAUSE_DECL (c)));
17737 : : break;
17738 : : default:
17739 : : break;
17740 : : }
17741 : 4556 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
17742 : 29 : && OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c)
17743 : 4563 : && !bitmap_bit_p (&map_head,
17744 : 7 : DECL_UID (OMP_CLAUSE_LINEAR_STEP (c))))
17745 : : {
17746 : 2 : error_at (OMP_CLAUSE_LOCATION (c),
17747 : : "%<linear%> clause step is a parameter %qD not "
17748 : : "specified in %<uniform%> clause",
17749 : 2 : OMP_CLAUSE_LINEAR_STEP (c));
17750 : 2 : remove = true;
17751 : : }
17752 : 4554 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
17753 : 4554 : && reduction_seen == -2)
17754 : 9 : OMP_CLAUSE_REDUCTION_INSCAN (c) = 0;
17755 : 4556 : if (target_in_reduction_seen
17756 : 4556 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP)
17757 : : {
17758 : 256 : tree t = OMP_CLAUSE_DECL (c);
17759 : 256 : while (handled_component_p (t)
17760 : : || INDIRECT_REF_P (t)
17761 : : || TREE_CODE (t) == ADDR_EXPR
17762 : : || TREE_CODE (t) == MEM_REF
17763 : 288 : || TREE_CODE (t) == NON_LVALUE_EXPR)
17764 : 32 : t = TREE_OPERAND (t, 0);
17765 : 256 : if (DECL_P (t)
17766 : 256 : && bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
17767 : 138 : OMP_CLAUSE_MAP_IN_REDUCTION (c) = 1;
17768 : : }
17769 : :
17770 : 4556 : if (remove)
17771 : 2 : *pc = OMP_CLAUSE_CHAIN (c);
17772 : : else
17773 : 4554 : pc = &OMP_CLAUSE_CHAIN (c);
17774 : : }
17775 : :
17776 : 589 : if (allocate_seen)
17777 : 4961 : for (pc = &clauses, c = clauses; c ; c = *pc)
17778 : : {
17779 : 4398 : bool remove = false;
17780 : 4398 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ALLOCATE
17781 : 704 : && !OMP_CLAUSE_ALLOCATE_COMBINED (c)
17782 : 5082 : && bitmap_bit_p (&aligned_head, DECL_UID (OMP_CLAUSE_DECL (c))))
17783 : : {
17784 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
17785 : : "%qD specified in %<allocate%> clause but not in "
17786 : 3 : "an explicit privatization clause", OMP_CLAUSE_DECL (c));
17787 : 3 : remove = true;
17788 : : }
17789 : 4398 : if (remove)
17790 : 3 : *pc = OMP_CLAUSE_CHAIN (c);
17791 : : else
17792 : 4395 : pc = &OMP_CLAUSE_CHAIN (c);
17793 : : }
17794 : :
17795 : 29172 : if (nogroup_seen && reduction_seen)
17796 : : {
17797 : 1 : error_at (OMP_CLAUSE_LOCATION (*nogroup_seen),
17798 : : "%<nogroup%> clause must not be used together with "
17799 : : "%<reduction%> clause");
17800 : 1 : *nogroup_seen = OMP_CLAUSE_CHAIN (*nogroup_seen);
17801 : : }
17802 : :
17803 : 29172 : if (grainsize_seen && num_tasks_seen)
17804 : : {
17805 : 2 : error_at (OMP_CLAUSE_LOCATION (*grainsize_seen),
17806 : : "%<grainsize%> clause must not be used together with "
17807 : : "%<num_tasks%> clause");
17808 : 2 : *grainsize_seen = OMP_CLAUSE_CHAIN (*grainsize_seen);
17809 : : }
17810 : :
17811 : 29172 : if (full_seen && partial_seen)
17812 : : {
17813 : 4 : error_at (OMP_CLAUSE_LOCATION (*full_seen),
17814 : : "%<full%> clause must not be used together with "
17815 : : "%<partial%> clause");
17816 : 4 : *full_seen = OMP_CLAUSE_CHAIN (*full_seen);
17817 : : }
17818 : :
17819 : 29172 : if (detach_seen)
17820 : : {
17821 : 31 : if (mergeable_seen)
17822 : : {
17823 : 2 : error_at (OMP_CLAUSE_LOCATION (*detach_seen),
17824 : : "%<detach%> clause must not be used together with "
17825 : : "%<mergeable%> clause");
17826 : 2 : *detach_seen = OMP_CLAUSE_CHAIN (*detach_seen);
17827 : : }
17828 : : else
17829 : : {
17830 : 29 : tree detach_decl = OMP_CLAUSE_DECL (*detach_seen);
17831 : :
17832 : 79 : for (pc = &clauses, c = clauses; c ; c = *pc)
17833 : : {
17834 : 50 : bool remove = false;
17835 : 50 : if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
17836 : 48 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
17837 : 48 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
17838 : 44 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE)
17839 : 54 : && OMP_CLAUSE_DECL (c) == detach_decl)
17840 : : {
17841 : 2 : error_at (OMP_CLAUSE_LOCATION (c),
17842 : : "the event handle of a %<detach%> clause "
17843 : : "should not be in a data-sharing clause");
17844 : 2 : remove = true;
17845 : : }
17846 : 50 : if (remove)
17847 : 2 : *pc = OMP_CLAUSE_CHAIN (c);
17848 : : else
17849 : 48 : pc = &OMP_CLAUSE_CHAIN (c);
17850 : : }
17851 : : }
17852 : : }
17853 : :
17854 : 29172 : if (ort == C_ORT_OMP_INTEROP
17855 : 29172 : && depend_clause
17856 : 21 : && (!init_use_destroy_seen
17857 : 20 : || (init_seen && init_no_targetsync_clause)))
17858 : : {
17859 : 3 : error_at (OMP_CLAUSE_LOCATION (depend_clause),
17860 : : "%<depend%> clause requires action clauses with "
17861 : : "%<targetsync%> interop-type");
17862 : 3 : if (init_no_targetsync_clause)
17863 : 2 : inform (OMP_CLAUSE_LOCATION (init_no_targetsync_clause),
17864 : : "%<init%> clause lacks the %<targetsync%> modifier");
17865 : : }
17866 : :
17867 : 29172 : bitmap_obstack_release (NULL);
17868 : 29172 : return clauses;
17869 : : }
17870 : :
17871 : : /* Do processing necessary to make CLAUSES well-formed, where CLAUSES result
17872 : : from implicit instantiation of user-defined mappers (in gimplify.cc). */
17873 : :
17874 : : tree
17875 : 13 : c_omp_finish_mapper_clauses (tree clauses)
17876 : : {
17877 : 13 : return c_finish_omp_clauses (clauses, C_ORT_OMP);
17878 : : }
17879 : :
17880 : : /* Return code to initialize DST with a copy constructor from SRC.
17881 : : C doesn't have copy constructors nor assignment operators, only for
17882 : : _Atomic vars we need to perform __atomic_load from src into a temporary
17883 : : followed by __atomic_store of the temporary to dst. */
17884 : :
17885 : : tree
17886 : 18709 : c_omp_clause_copy_ctor (tree clause, tree dst, tree src)
17887 : : {
17888 : 18709 : if (!really_atomic_lvalue (dst) && !really_atomic_lvalue (src))
17889 : 18705 : return build2 (MODIFY_EXPR, TREE_TYPE (dst), dst, src);
17890 : :
17891 : 4 : location_t loc = OMP_CLAUSE_LOCATION (clause);
17892 : 4 : tree type = TREE_TYPE (dst);
17893 : 4 : tree nonatomic_type = build_qualified_type (type, TYPE_UNQUALIFIED);
17894 : 4 : tree tmp = create_tmp_var (nonatomic_type);
17895 : 4 : tree tmp_addr = build_fold_addr_expr (tmp);
17896 : 4 : TREE_ADDRESSABLE (tmp) = 1;
17897 : 4 : suppress_warning (tmp);
17898 : 4 : tree src_addr = build_fold_addr_expr (src);
17899 : 4 : tree dst_addr = build_fold_addr_expr (dst);
17900 : 4 : tree seq_cst = build_int_cst (integer_type_node, MEMMODEL_SEQ_CST);
17901 : 4 : vec<tree, va_gc> *params;
17902 : : /* Expansion of a generic atomic load may require an addition
17903 : : element, so allocate enough to prevent a resize. */
17904 : 4 : vec_alloc (params, 4);
17905 : :
17906 : : /* Build __atomic_load (&src, &tmp, SEQ_CST); */
17907 : 4 : tree fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_LOAD);
17908 : 4 : params->quick_push (src_addr);
17909 : 4 : params->quick_push (tmp_addr);
17910 : 4 : params->quick_push (seq_cst);
17911 : 4 : tree load = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
17912 : :
17913 : 4 : vec_alloc (params, 4);
17914 : :
17915 : : /* Build __atomic_store (&dst, &tmp, SEQ_CST); */
17916 : 4 : fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_STORE);
17917 : 4 : params->quick_push (dst_addr);
17918 : 4 : params->quick_push (tmp_addr);
17919 : 4 : params->quick_push (seq_cst);
17920 : 4 : tree store = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
17921 : 4 : return build2 (COMPOUND_EXPR, void_type_node, load, store);
17922 : : }
17923 : :
17924 : : /* Create a transaction node. */
17925 : :
17926 : : tree
17927 : 135 : c_finish_transaction (location_t loc, tree block, int flags)
17928 : : {
17929 : 135 : tree stmt = build_stmt (loc, TRANSACTION_EXPR, block);
17930 : 135 : if (flags & TM_STMT_ATTR_OUTER)
17931 : 10 : TRANSACTION_EXPR_OUTER (stmt) = 1;
17932 : 135 : if (flags & TM_STMT_ATTR_RELAXED)
17933 : 31 : TRANSACTION_EXPR_RELAXED (stmt) = 1;
17934 : 135 : return add_stmt (stmt);
17935 : : }
17936 : :
17937 : : /* Make a variant type in the proper way for C/C++, propagating qualifiers
17938 : : down to the element type of an array. If ORIG_QUAL_TYPE is not
17939 : : NULL, then it should be used as the qualified type
17940 : : ORIG_QUAL_INDIRECT levels down in array type derivation (to
17941 : : preserve information about the typedef name from which an array
17942 : : type was derived). */
17943 : :
17944 : : tree
17945 : 72663516 : c_build_qualified_type (tree type, int type_quals, tree orig_qual_type,
17946 : : size_t orig_qual_indirect)
17947 : : {
17948 : 72663516 : if (type == error_mark_node)
17949 : : return type;
17950 : :
17951 : 72663370 : if (TREE_CODE (type) == ARRAY_TYPE)
17952 : : {
17953 : 3113061 : tree t;
17954 : 3113061 : tree element_type = c_build_qualified_type (TREE_TYPE (type),
17955 : : type_quals, orig_qual_type,
17956 : : orig_qual_indirect - 1);
17957 : :
17958 : : /* See if we already have an identically qualified type. */
17959 : 3113061 : if (orig_qual_type && orig_qual_indirect == 0)
17960 : : t = orig_qual_type;
17961 : : else
17962 : 4547954 : for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
17963 : : {
17964 : 4410089 : if (TYPE_QUALS (strip_array_types (t)) == type_quals
17965 : 2995747 : && TYPE_NAME (t) == TYPE_NAME (type)
17966 : 2975155 : && TYPE_CONTEXT (t) == TYPE_CONTEXT (type)
17967 : 7385244 : && attribute_list_equal (TYPE_ATTRIBUTES (t),
17968 : 2975155 : TYPE_ATTRIBUTES (type)))
17969 : : break;
17970 : : }
17971 : 3113020 : if (!t)
17972 : : {
17973 : 137865 : tree domain = TYPE_DOMAIN (type);
17974 : :
17975 : 137865 : t = build_variant_type_copy (type);
17976 : 137865 : TREE_TYPE (t) = element_type;
17977 : 137865 : TYPE_ADDR_SPACE (t) = TYPE_ADDR_SPACE (element_type);
17978 : :
17979 : 137865 : if (TYPE_STRUCTURAL_EQUALITY_P (element_type)
17980 : 137865 : || (domain && TYPE_STRUCTURAL_EQUALITY_P (domain)))
17981 : 179 : SET_TYPE_STRUCTURAL_EQUALITY (t);
17982 : 137686 : else if (TYPE_CANONICAL (element_type) != element_type
17983 : 137686 : || (domain && TYPE_CANONICAL (domain) != domain))
17984 : : {
17985 : 2676 : tree unqualified_canon
17986 : 5144 : = c_build_array_type (TYPE_CANONICAL (element_type),
17987 : 2468 : domain ? TYPE_CANONICAL (domain)
17988 : : : NULL_TREE);
17989 : 2676 : if (TYPE_REVERSE_STORAGE_ORDER (type))
17990 : : {
17991 : 0 : unqualified_canon
17992 : 0 : = build_distinct_type_copy (unqualified_canon);
17993 : 0 : TYPE_REVERSE_STORAGE_ORDER (unqualified_canon) = 1;
17994 : : }
17995 : 2676 : TYPE_CANONICAL (t)
17996 : 5352 : = c_build_qualified_type (unqualified_canon, type_quals);
17997 : : }
17998 : : else
17999 : 135010 : TYPE_CANONICAL (t) = t;
18000 : : }
18001 : 3113061 : return t;
18002 : : }
18003 : :
18004 : : /* A restrict-qualified pointer type must be a pointer to object or
18005 : : incomplete type. Note that the use of POINTER_TYPE_P also allows
18006 : : REFERENCE_TYPEs, which is appropriate for C++. */
18007 : 69550309 : if ((type_quals & TYPE_QUAL_RESTRICT)
18008 : 69550309 : && (!POINTER_TYPE_P (type)
18009 : 3327130 : || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type))))
18010 : : {
18011 : 3 : error ("invalid use of %<restrict%>");
18012 : 3 : type_quals &= ~TYPE_QUAL_RESTRICT;
18013 : : }
18014 : :
18015 : 69550309 : tree var_type = (orig_qual_type && orig_qual_indirect == 0
18016 : 69550309 : ? orig_qual_type
18017 : 69550292 : : build_qualified_type (type, type_quals));
18018 : :
18019 : 69550309 : gcc_checking_assert (C_TYPE_VARIABLE_SIZE (var_type)
18020 : : == C_TYPE_VARIABLE_SIZE (type));
18021 : 69550309 : gcc_checking_assert (C_TYPE_VARIABLY_MODIFIED (var_type)
18022 : : == C_TYPE_VARIABLY_MODIFIED (type));
18023 : :
18024 : : /* A variant type does not inherit the list of incomplete vars from the
18025 : : type main variant. */
18026 : 69550309 : if ((RECORD_OR_UNION_TYPE_P (var_type)
18027 : 67665678 : || TREE_CODE (var_type) == ENUMERAL_TYPE)
18028 : 69650630 : && TYPE_MAIN_VARIANT (var_type) != var_type)
18029 : 1382122 : C_TYPE_INCOMPLETE_VARS (var_type) = 0;
18030 : : return var_type;
18031 : : }
18032 : :
18033 : : /* Build a VA_ARG_EXPR for the C parser. */
18034 : :
18035 : : tree
18036 : 19876 : c_build_va_arg (location_t loc1, tree expr, location_t loc2, tree type)
18037 : : {
18038 : 19876 : if (error_operand_p (type))
18039 : 2 : return error_mark_node;
18040 : : /* VA_ARG_EXPR cannot be used for a scalar va_list with reverse storage
18041 : : order because it takes the address of the expression. */
18042 : 19874 : else if (handled_component_p (expr)
18043 : 31 : && reverse_storage_order_for_component_p (expr))
18044 : : {
18045 : 0 : error_at (loc1, "cannot use %<va_arg%> with reverse storage order");
18046 : 0 : return error_mark_node;
18047 : : }
18048 : 19874 : else if (!COMPLETE_TYPE_P (type))
18049 : : {
18050 : 11 : error_at (loc2, "second argument to %<va_arg%> is of incomplete "
18051 : : "type %qT", type);
18052 : 11 : return error_mark_node;
18053 : : }
18054 : 19863 : else if (TREE_CODE (type) == FUNCTION_TYPE)
18055 : : {
18056 : 1 : error_at (loc2, "second argument to %<va_arg%> is a function type %qT",
18057 : : type);
18058 : 1 : return error_mark_node;
18059 : : }
18060 : 19862 : else if (warn_cxx_compat && TREE_CODE (type) == ENUMERAL_TYPE)
18061 : 1 : warning_at (loc2, OPT_Wc___compat,
18062 : : "C++ requires promoted type, not enum type, in %<va_arg%>");
18063 : 19862 : return build_va_arg (loc2, expr, type);
18064 : : }
18065 : :
18066 : : /* Return truthvalue of whether T1 is the same tree structure as T2.
18067 : : Return 1 if they are the same. Return false if they are different. */
18068 : :
18069 : : bool
18070 : 1854 : c_tree_equal (tree t1, tree t2)
18071 : : {
18072 : 1883 : enum tree_code code1, code2;
18073 : :
18074 : 1883 : if (t1 == t2)
18075 : : return true;
18076 : 661 : if (!t1 || !t2)
18077 : : return false;
18078 : :
18079 : 681 : for (code1 = TREE_CODE (t1); code1 == NON_LVALUE_EXPR;
18080 : 20 : code1 = TREE_CODE (t1))
18081 : 20 : t1 = TREE_OPERAND (t1, 0);
18082 : 682 : for (code2 = TREE_CODE (t2); code2 == NON_LVALUE_EXPR;
18083 : 21 : code2 = TREE_CODE (t2))
18084 : 21 : t2 = TREE_OPERAND (t2, 0);
18085 : :
18086 : : /* They might have become equal now. */
18087 : 661 : if (t1 == t2)
18088 : : return true;
18089 : :
18090 : 640 : if (code1 != code2)
18091 : : return false;
18092 : :
18093 : 379 : if (CONSTANT_CLASS_P (t1) && !comptypes (TREE_TYPE (t1), TREE_TYPE (t2)))
18094 : : return false;
18095 : :
18096 : 379 : switch (code1)
18097 : : {
18098 : 2 : case INTEGER_CST:
18099 : 2 : return wi::to_wide (t1) == wi::to_wide (t2);
18100 : :
18101 : 10 : case REAL_CST:
18102 : 10 : return real_equal (&TREE_REAL_CST (t1), &TREE_REAL_CST (t2));
18103 : :
18104 : 0 : case STRING_CST:
18105 : 0 : return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
18106 : 0 : && !memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
18107 : 0 : TREE_STRING_LENGTH (t1));
18108 : :
18109 : 0 : case FIXED_CST:
18110 : 0 : return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1),
18111 : : TREE_FIXED_CST (t2));
18112 : :
18113 : 0 : case COMPLEX_CST:
18114 : 0 : return c_tree_equal (TREE_REALPART (t1), TREE_REALPART (t2))
18115 : 0 : && c_tree_equal (TREE_IMAGPART (t1), TREE_IMAGPART (t2));
18116 : :
18117 : 0 : case VECTOR_CST:
18118 : 0 : return operand_equal_p (t1, t2, OEP_ONLY_CONST);
18119 : :
18120 : 0 : case CONSTRUCTOR:
18121 : : /* We need to do this when determining whether or not two
18122 : : non-type pointer to member function template arguments
18123 : : are the same. */
18124 : 0 : if (!comptypes (TREE_TYPE (t1), TREE_TYPE (t2))
18125 : 0 : || CONSTRUCTOR_NELTS (t1) != CONSTRUCTOR_NELTS (t2))
18126 : : return false;
18127 : : {
18128 : : tree field, value;
18129 : : unsigned int i;
18130 : 0 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t1), i, field, value)
18131 : : {
18132 : 0 : constructor_elt *elt2 = CONSTRUCTOR_ELT (t2, i);
18133 : 0 : if (!c_tree_equal (field, elt2->index)
18134 : 0 : || !c_tree_equal (value, elt2->value))
18135 : 0 : return false;
18136 : : }
18137 : : }
18138 : : return true;
18139 : :
18140 : 0 : case TREE_LIST:
18141 : 0 : if (!c_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)))
18142 : : return false;
18143 : 0 : if (!c_tree_equal (TREE_VALUE (t1), TREE_VALUE (t2)))
18144 : : return false;
18145 : 0 : return c_tree_equal (TREE_CHAIN (t1), TREE_CHAIN (t2));
18146 : :
18147 : 0 : case SAVE_EXPR:
18148 : 0 : return c_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
18149 : :
18150 : 25 : case CALL_EXPR:
18151 : 25 : {
18152 : 25 : tree arg1, arg2;
18153 : 25 : call_expr_arg_iterator iter1, iter2;
18154 : 25 : if (!c_tree_equal (CALL_EXPR_FN (t1), CALL_EXPR_FN (t2)))
18155 : : return false;
18156 : 50 : for (arg1 = first_call_expr_arg (t1, &iter1),
18157 : 25 : arg2 = first_call_expr_arg (t2, &iter2);
18158 : 25 : arg1 && arg2;
18159 : 0 : arg1 = next_call_expr_arg (&iter1),
18160 : 0 : arg2 = next_call_expr_arg (&iter2))
18161 : 0 : if (!c_tree_equal (arg1, arg2))
18162 : : return false;
18163 : 25 : if (arg1 || arg2)
18164 : : return false;
18165 : : return true;
18166 : : }
18167 : :
18168 : 0 : case TARGET_EXPR:
18169 : 0 : {
18170 : 0 : tree o1 = TREE_OPERAND (t1, 0);
18171 : 0 : tree o2 = TREE_OPERAND (t2, 0);
18172 : :
18173 : : /* Special case: if either target is an unallocated VAR_DECL,
18174 : : it means that it's going to be unified with whatever the
18175 : : TARGET_EXPR is really supposed to initialize, so treat it
18176 : : as being equivalent to anything. */
18177 : 0 : if (VAR_P (o1) && DECL_NAME (o1) == NULL_TREE
18178 : 0 : && !DECL_RTL_SET_P (o1))
18179 : : /*Nop*/;
18180 : 0 : else if (VAR_P (o2) && DECL_NAME (o2) == NULL_TREE
18181 : 0 : && !DECL_RTL_SET_P (o2))
18182 : : /*Nop*/;
18183 : 0 : else if (!c_tree_equal (o1, o2))
18184 : : return false;
18185 : :
18186 : 0 : return c_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
18187 : : }
18188 : :
18189 : 29 : case COMPONENT_REF:
18190 : 29 : if (TREE_OPERAND (t1, 1) != TREE_OPERAND (t2, 1))
18191 : : return false;
18192 : 29 : return c_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
18193 : :
18194 : : case PARM_DECL:
18195 : : case VAR_DECL:
18196 : : case CONST_DECL:
18197 : : case FIELD_DECL:
18198 : : case FUNCTION_DECL:
18199 : : case IDENTIFIER_NODE:
18200 : : case SSA_NAME:
18201 : : return false;
18202 : :
18203 : 0 : case TREE_VEC:
18204 : 0 : {
18205 : 0 : unsigned ix;
18206 : 0 : if (TREE_VEC_LENGTH (t1) != TREE_VEC_LENGTH (t2))
18207 : : return false;
18208 : 0 : for (ix = TREE_VEC_LENGTH (t1); ix--;)
18209 : 0 : if (!c_tree_equal (TREE_VEC_ELT (t1, ix),
18210 : 0 : TREE_VEC_ELT (t2, ix)))
18211 : : return false;
18212 : : return true;
18213 : : }
18214 : :
18215 : 22 : CASE_CONVERT:
18216 : 22 : if (!comptypes (TREE_TYPE (t1), TREE_TYPE (t2)))
18217 : : return false;
18218 : : break;
18219 : :
18220 : : default:
18221 : : break;
18222 : : }
18223 : :
18224 : 131 : switch (TREE_CODE_CLASS (code1))
18225 : : {
18226 : 131 : case tcc_unary:
18227 : 131 : case tcc_binary:
18228 : 131 : case tcc_comparison:
18229 : 131 : case tcc_expression:
18230 : 131 : case tcc_vl_exp:
18231 : 131 : case tcc_reference:
18232 : 131 : case tcc_statement:
18233 : 131 : {
18234 : 131 : int i, n = TREE_OPERAND_LENGTH (t1);
18235 : :
18236 : 131 : switch (code1)
18237 : : {
18238 : 0 : case PREINCREMENT_EXPR:
18239 : 0 : case PREDECREMENT_EXPR:
18240 : 0 : case POSTINCREMENT_EXPR:
18241 : 0 : case POSTDECREMENT_EXPR:
18242 : 0 : n = 1;
18243 : 0 : break;
18244 : 16 : case ARRAY_REF:
18245 : 16 : n = 2;
18246 : 16 : break;
18247 : : default:
18248 : : break;
18249 : : }
18250 : :
18251 : 131 : if (TREE_CODE_CLASS (code1) == tcc_vl_exp
18252 : 131 : && n != TREE_OPERAND_LENGTH (t2))
18253 : : return false;
18254 : :
18255 : 305 : for (i = 0; i < n; ++i)
18256 : 186 : if (!c_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i)))
18257 : : return false;
18258 : :
18259 : : return true;
18260 : : }
18261 : :
18262 : 0 : case tcc_type:
18263 : 0 : return comptypes (t1, t2);
18264 : 0 : default:
18265 : 0 : gcc_unreachable ();
18266 : : }
18267 : : }
18268 : :
18269 : : /* Returns true when the function declaration FNDECL is implicit,
18270 : : introduced as a result of a call to an otherwise undeclared
18271 : : function, and false otherwise. */
18272 : :
18273 : : bool
18274 : 2013 : c_decl_implicit (const_tree fndecl)
18275 : : {
18276 : 2013 : return C_DECL_IMPLICIT (fndecl);
18277 : : }
|