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 : : /* The level of nesting inside "_Generic". */
82 : : int in_generic;
83 : :
84 : : /* True when parsing OpenMP loop expressions. */
85 : : bool c_in_omp_for;
86 : :
87 : : /* True when parsing OpenMP map clause. */
88 : : bool c_omp_array_section_p;
89 : :
90 : : /* The argument of last parsed sizeof expression, only to be tested
91 : : if expr.original_code == SIZEOF_EXPR. */
92 : : tree c_last_sizeof_arg;
93 : : location_t c_last_sizeof_loc;
94 : :
95 : : /* Nonzero if we might need to print a "missing braces around
96 : : initializer" message within this initializer. */
97 : : static int found_missing_braces;
98 : :
99 : : static bool require_constant_value;
100 : : static bool require_constant_elements;
101 : : static bool require_constexpr_value;
102 : :
103 : : static tree qualify_type (tree, tree);
104 : : struct comptypes_data;
105 : : static bool tagged_types_tu_compatible_p (const_tree, const_tree,
106 : : struct comptypes_data *);
107 : : static bool comp_target_types (location_t, tree, tree);
108 : : static bool function_types_compatible_p (const_tree, const_tree,
109 : : struct comptypes_data *);
110 : : static bool type_lists_compatible_p (const_tree, const_tree,
111 : : struct comptypes_data *);
112 : : static int convert_arguments (location_t, vec<location_t>, tree,
113 : : vec<tree, va_gc> *, vec<tree, va_gc> *, tree,
114 : : tree);
115 : : static tree pointer_diff (location_t, tree, tree, tree *);
116 : : static tree convert_for_assignment (location_t, location_t, tree, tree, tree,
117 : : enum impl_conv, bool, tree, tree, int,
118 : : int = 0);
119 : : static tree valid_compound_expr_initializer (tree, tree);
120 : : static void push_string (const char *);
121 : : static void push_member_name (tree);
122 : : static int spelling_length (void);
123 : : static char *print_spelling (char *);
124 : : static void warning_init (location_t, int, const char *);
125 : : static tree digest_init (location_t, tree, tree, tree, tree, bool, bool, bool,
126 : : bool, bool, bool);
127 : : static void output_init_element (location_t, tree, tree, bool, tree, tree, bool,
128 : : bool, struct obstack *);
129 : : static void output_pending_init_elements (int, struct obstack *);
130 : : static bool set_designator (location_t, bool, struct obstack *);
131 : : static void push_range_stack (tree, struct obstack *);
132 : : static void add_pending_init (location_t, tree, tree, tree, bool,
133 : : struct obstack *);
134 : : static void set_nonincremental_init (struct obstack *);
135 : : static void set_nonincremental_init_from_string (tree, struct obstack *);
136 : : static tree find_init_member (tree, struct obstack *);
137 : : static void readonly_warning (tree, enum lvalue_use);
138 : : static int lvalue_or_else (location_t, const_tree, enum lvalue_use);
139 : : static void record_maybe_used_decl (tree, bool address);
140 : : static bool comptypes_internal (const_tree, const_tree,
141 : : struct comptypes_data *data);
142 : : static bool comptypes_check_for_composite (tree t1, tree t2);
143 : : static bool handle_counted_by_p (tree);
144 : :
145 : : /* Return true if EXP is a null pointer constant, false otherwise. */
146 : :
147 : : bool
148 : 187708007 : null_pointer_constant_p (const_tree expr)
149 : : {
150 : : /* This should really operate on c_expr structures, but they aren't
151 : : yet available everywhere required. */
152 : 187708007 : tree type = TREE_TYPE (expr);
153 : :
154 : : /* An integer constant expression with the value 0, such an expression
155 : : cast to type void*, or the predefined constant nullptr, are a null
156 : : pointer constant. */
157 : 187708007 : if (expr == nullptr_node)
158 : : return true;
159 : :
160 : 187707357 : return (TREE_CODE (expr) == INTEGER_CST
161 : 19017718 : && !TREE_OVERFLOW (expr)
162 : 19017621 : && integer_zerop (expr)
163 : 191626314 : && (INTEGRAL_TYPE_P (type)
164 : 331989 : || (TREE_CODE (type) == POINTER_TYPE
165 : 331987 : && VOID_TYPE_P (TREE_TYPE (type))
166 : 256797 : && TYPE_QUALS (TREE_TYPE (type)) == TYPE_UNQUALIFIED)));
167 : : }
168 : :
169 : : /* EXPR may appear in an unevaluated part of an integer constant
170 : : expression, but not in an evaluated part. Wrap it in a
171 : : C_MAYBE_CONST_EXPR, or mark it with TREE_OVERFLOW if it is just an
172 : : INTEGER_CST and we cannot create a C_MAYBE_CONST_EXPR. */
173 : :
174 : : static tree
175 : 62354 : note_integer_operands (tree expr)
176 : : {
177 : 62354 : tree ret;
178 : 62354 : if (TREE_CODE (expr) == INTEGER_CST && in_late_binary_op)
179 : : {
180 : 22 : ret = copy_node (expr);
181 : 22 : TREE_OVERFLOW (ret) = 1;
182 : : }
183 : : else
184 : : {
185 : 62332 : ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (expr), NULL_TREE, expr);
186 : 62332 : C_MAYBE_CONST_EXPR_INT_OPERANDS (ret) = 1;
187 : : }
188 : 62354 : return ret;
189 : : }
190 : :
191 : : /* Having checked whether EXPR may appear in an unevaluated part of an
192 : : integer constant expression and found that it may, remove any
193 : : C_MAYBE_CONST_EXPR noting this fact and return the resulting
194 : : expression. */
195 : :
196 : : static inline tree
197 : 33438734 : remove_c_maybe_const_expr (tree expr)
198 : : {
199 : 33438734 : if (TREE_CODE (expr) == C_MAYBE_CONST_EXPR)
200 : 61506 : return C_MAYBE_CONST_EXPR_EXPR (expr);
201 : : else
202 : : return expr;
203 : : }
204 : :
205 : : /* This is a cache to hold if two types are seen. */
206 : :
207 : : struct tagged_tu_seen_cache {
208 : : const struct tagged_tu_seen_cache * next;
209 : : const_tree t1;
210 : : const_tree t2;
211 : : };
212 : :
213 : : /* Do `exp = require_complete_type (loc, exp);' to make sure exp
214 : : does not have an incomplete type. (That includes void types.)
215 : : LOC is the location of the use. */
216 : :
217 : : tree
218 : 770235705 : require_complete_type (location_t loc, tree value)
219 : : {
220 : 770235705 : tree type = TREE_TYPE (value);
221 : :
222 : 770235705 : if (error_operand_p (value))
223 : 9062 : return error_mark_node;
224 : :
225 : : /* First, detect a valid value with a complete type. */
226 : 770226643 : if (COMPLETE_TYPE_P (type))
227 : : return value;
228 : :
229 : 164 : c_incomplete_type_error (loc, value, type);
230 : 164 : return error_mark_node;
231 : : }
232 : :
233 : : /* Print an error message for invalid use of an incomplete type.
234 : : VALUE is the expression that was used (or 0 if that isn't known)
235 : : and TYPE is the type that was invalid. LOC is the location for
236 : : the error. */
237 : :
238 : : void
239 : 224 : c_incomplete_type_error (location_t loc, const_tree value, const_tree type)
240 : : {
241 : : /* Avoid duplicate error message. */
242 : 224 : if (TREE_CODE (type) == ERROR_MARK)
243 : : return;
244 : :
245 : 224 : if (value != NULL_TREE && (VAR_P (value) || TREE_CODE (value) == PARM_DECL))
246 : 98 : error_at (loc, "%qD has an incomplete type %qT", value, type);
247 : : else
248 : : {
249 : 126 : retry:
250 : : /* We must print an error message. Be clever about what it says. */
251 : :
252 : 126 : switch (TREE_CODE (type))
253 : : {
254 : 82 : case RECORD_TYPE:
255 : 82 : case UNION_TYPE:
256 : 82 : case ENUMERAL_TYPE:
257 : 82 : break;
258 : :
259 : 38 : case VOID_TYPE:
260 : 38 : error_at (loc, "invalid use of void expression");
261 : 38 : return;
262 : :
263 : 6 : case ARRAY_TYPE:
264 : 6 : if (TYPE_DOMAIN (type))
265 : : {
266 : 3 : if (TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL)
267 : : {
268 : 3 : error_at (loc, "invalid use of flexible array member");
269 : 3 : return;
270 : : }
271 : 0 : type = TREE_TYPE (type);
272 : 0 : goto retry;
273 : : }
274 : 3 : error_at (loc, "invalid use of array with unspecified bounds");
275 : 3 : return;
276 : :
277 : 0 : default:
278 : 0 : gcc_unreachable ();
279 : : }
280 : :
281 : 82 : if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
282 : 80 : error_at (loc, "invalid use of undefined type %qT", type);
283 : : else
284 : : /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL. */
285 : 2 : error_at (loc, "invalid use of incomplete typedef %qT", type);
286 : : }
287 : : }
288 : :
289 : : /* Given a type, apply default promotions wrt unnamed function
290 : : arguments and return the new type. */
291 : :
292 : : tree
293 : 123775470 : c_type_promotes_to (tree type)
294 : : {
295 : 123775470 : tree ret = NULL_TREE;
296 : :
297 : 123775470 : if (TYPE_MAIN_VARIANT (type) == float_type_node)
298 : 1492031 : ret = double_type_node;
299 : 122283439 : else if (c_promoting_integer_type_p (type))
300 : : {
301 : : /* Preserve unsignedness if not really getting any wider. */
302 : 18581350 : if (TYPE_UNSIGNED (type)
303 : 18581350 : && (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)))
304 : 0 : ret = unsigned_type_node;
305 : : else
306 : 18581350 : ret = integer_type_node;
307 : : }
308 : :
309 : 20073381 : if (ret != NULL_TREE)
310 : 20073381 : return (TYPE_ATOMIC (type)
311 : 20073381 : ? c_build_qualified_type (ret, TYPE_QUAL_ATOMIC)
312 : : : ret);
313 : :
314 : : return type;
315 : : }
316 : :
317 : : /* Return true if between two named address spaces, whether there is a superset
318 : : named address space that encompasses both address spaces. If there is a
319 : : superset, return which address space is the superset. */
320 : :
321 : : static bool
322 : 7327588 : addr_space_superset (addr_space_t as1, addr_space_t as2, addr_space_t *common)
323 : : {
324 : 7327588 : if (as1 == as2)
325 : : {
326 : 7327588 : *common = as1;
327 : 7327588 : return true;
328 : : }
329 : 0 : else if (targetm.addr_space.subset_p (as1, as2))
330 : : {
331 : 0 : *common = as2;
332 : 0 : return true;
333 : : }
334 : 0 : else if (targetm.addr_space.subset_p (as2, as1))
335 : : {
336 : 0 : *common = as1;
337 : 0 : return true;
338 : : }
339 : : else
340 : : return false;
341 : : }
342 : :
343 : : /* Return a variant of TYPE which has all the type qualifiers of LIKE
344 : : as well as those of TYPE. */
345 : :
346 : : static tree
347 : 2582413 : qualify_type (tree type, tree like)
348 : : {
349 : 2582413 : addr_space_t as_type = TYPE_ADDR_SPACE (type);
350 : 2582413 : addr_space_t as_like = TYPE_ADDR_SPACE (like);
351 : 2582413 : addr_space_t as_common;
352 : :
353 : : /* If the two named address spaces are different, determine the common
354 : : superset address space. If there isn't one, raise an error. */
355 : 2582413 : if (!addr_space_superset (as_type, as_like, &as_common))
356 : : {
357 : 0 : as_common = as_type;
358 : 0 : error ("%qT and %qT are in disjoint named address spaces",
359 : : type, like);
360 : : }
361 : :
362 : 5164826 : return c_build_qualified_type (type,
363 : 2582413 : TYPE_QUALS_NO_ADDR_SPACE (type)
364 : 2582413 : | TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (like)
365 : 2582413 : | ENCODE_QUAL_ADDR_SPACE (as_common));
366 : : }
367 : :
368 : :
369 : : /* Check consistency of type TYPE. For derived types, we test that
370 : : C_TYPE_VARIABLE_SIZE and C_TYPE_VARIABLY_MODIFIED are consistent with
371 : : the requirements of the base type. We also check that arrays with a
372 : : non-constant length are marked with C_TYPE_VARIABLE_SIZE. If any
373 : : inconsistency is detected false is returned and true otherwise. */
374 : :
375 : : static bool
376 : 139119628 : c_verify_type (tree type)
377 : : {
378 : 139119628 : switch (TREE_CODE (type))
379 : : {
380 : 65471301 : case POINTER_TYPE:
381 : 65471301 : case FUNCTION_TYPE:
382 : : /* Pointer and funcions can not have variable size. */
383 : 65471301 : if (C_TYPE_VARIABLE_SIZE (type))
384 : : return false;
385 : : /* Pointer and funcions are variably modified if and only if the
386 : : return / target type is variably modified. */
387 : 65471301 : if (C_TYPE_VARIABLY_MODIFIED (type)
388 : 65471301 : != C_TYPE_VARIABLY_MODIFIED (TREE_TYPE (type)))
389 : 0 : return false;
390 : : break;
391 : 903292 : case ARRAY_TYPE:
392 : : /* An array has variable size if and only if it has a non-constant
393 : : dimensions or its element type has variable size. */
394 : 903292 : if ((C_TYPE_VARIABLE_SIZE (TREE_TYPE (type))
395 : 903292 : || (TYPE_DOMAIN (type) && TYPE_MAX_VALUE (TYPE_DOMAIN (type))
396 : 877975 : && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
397 : : != INTEGER_CST))
398 : 903292 : != C_TYPE_VARIABLE_SIZE (type))
399 : : return false;
400 : : /* If the element type or the array has variable size, then the
401 : : array has variable size and is variably modified. */
402 : 903292 : if (C_TYPE_VARIABLE_SIZE (TREE_TYPE (type))
403 : 903292 : || C_TYPE_VARIABLE_SIZE (type))
404 : : {
405 : 28599 : if (!C_TYPE_VARIABLE_SIZE (type))
406 : : return false;
407 : 28599 : if (!C_TYPE_VARIABLY_MODIFIED (type))
408 : : return false;
409 : : }
410 : : /* If the element type is variably modified, then also the array. */
411 : 903292 : if (C_TYPE_VARIABLY_MODIFIED (TREE_TYPE (type))
412 : 903292 : && !C_TYPE_VARIABLY_MODIFIED (type))
413 : 0 : return false;
414 : : break;
415 : : default:
416 : : break;
417 : : }
418 : : return true;
419 : : }
420 : :
421 : : /* Propagate C_TYPE_VARIABLY_MODIFIED and C_TYPE_VARIABLE_SIZE
422 : : from a base type to a newly built derived or qualified type. */
423 : :
424 : : static tree
425 : 132186240 : c_set_type_bits (tree new_type, tree old_type)
426 : : {
427 : 132186240 : gcc_checking_assert (c_verify_type (old_type));
428 : :
429 : 132186240 : if (C_TYPE_VARIABLY_MODIFIED (old_type))
430 : 28203 : C_TYPE_VARIABLY_MODIFIED (new_type) = true;
431 : :
432 : 132186240 : if (TREE_CODE (new_type) == ARRAY_TYPE && C_TYPE_VARIABLE_SIZE (old_type))
433 : : {
434 : 16775 : C_TYPE_VARIABLY_MODIFIED (new_type) = true;
435 : 16775 : C_TYPE_VARIABLE_SIZE (new_type) = true;
436 : : }
437 : 132186240 : return new_type;
438 : : }
439 : :
440 : : /* Build a pointer type using the default pointer mode. */
441 : :
442 : : tree
443 : 71121275 : c_build_pointer_type (tree to_type)
444 : : {
445 : 71121275 : addr_space_t as = to_type == error_mark_node ? ADDR_SPACE_GENERIC
446 : 71121275 : : TYPE_ADDR_SPACE (to_type);
447 : 71121275 : machine_mode pointer_mode;
448 : :
449 : 71121275 : if (as != ADDR_SPACE_GENERIC || c_default_pointer_mode == VOIDmode)
450 : 71121275 : pointer_mode = targetm.addr_space.pointer_mode (as);
451 : : else
452 : : pointer_mode = c_default_pointer_mode;
453 : :
454 : 71121275 : return c_build_pointer_type_for_mode (to_type, pointer_mode, false);
455 : : }
456 : :
457 : : /* Build a pointer type using the given mode. */
458 : :
459 : : tree
460 : 71130153 : c_build_pointer_type_for_mode (tree type, machine_mode mode, bool m)
461 : : {
462 : 71130153 : tree ret = build_pointer_type_for_mode (type, mode, m);
463 : 71130153 : return c_set_type_bits (ret, type);
464 : : }
465 : :
466 : : /* Build a function type. */
467 : :
468 : : tree
469 : 52932701 : c_build_function_type (tree type, tree args, bool no)
470 : : {
471 : 52932701 : tree ret = build_function_type (type, args, no);
472 : 52932701 : return c_set_type_bits (ret, type);
473 : : }
474 : :
475 : : /* Build an array type. This sets typeless storage as required
476 : : by C2Y and C_TYPE_VARIABLY_MODIFIED and C_TYPE_VARIABLE_SIZE
477 : : based on the element type and domain. */
478 : :
479 : : tree
480 : 1154684 : c_build_array_type (tree type, tree domain)
481 : : {
482 : 1154684 : int type_quals = TYPE_QUALS (type);
483 : :
484 : : /* Identify typeless storage as introduced in C2Y
485 : : and supported also in earlier language modes. */
486 : 1727258 : bool typeless = (char_type_p (type) && !(type_quals & TYPE_QUAL_ATOMIC))
487 : 1154684 : || (AGGREGATE_TYPE_P (type) && TYPE_TYPELESS_STORAGE (type));
488 : :
489 : 1154684 : tree ret = build_array_type (type, domain, typeless);
490 : :
491 : 1069668 : if (domain && TYPE_MAX_VALUE (domain)
492 : 2136567 : && TREE_CODE (TYPE_MAX_VALUE (domain)) != INTEGER_CST)
493 : : {
494 : 24196 : C_TYPE_VARIABLE_SIZE (ret) = 1;
495 : 24196 : C_TYPE_VARIABLY_MODIFIED (ret) = 1;
496 : : }
497 : :
498 : 1154684 : return c_set_type_bits (ret, type);
499 : : }
500 : :
501 : :
502 : : /* Build an array type of unspecified size. */
503 : : tree
504 : 150 : c_build_array_type_unspecified (tree type)
505 : : {
506 : 150 : tree upper = build2 (COMPOUND_EXPR, TREE_TYPE (size_zero_node),
507 : : integer_zero_node, size_zero_node);
508 : 150 : return c_build_array_type (type, build_index_type (upper));
509 : : }
510 : :
511 : :
512 : : tree
513 : 6968702 : c_build_type_attribute_qual_variant (tree type, tree attrs, int quals)
514 : : {
515 : 6968702 : tree ret = build_type_attribute_qual_variant (type, attrs, quals);
516 : 6968702 : return c_set_type_bits (ret, type);
517 : : }
518 : :
519 : : tree
520 : 6968503 : c_build_type_attribute_variant (tree type, tree attrs)
521 : : {
522 : 6968503 : return c_build_type_attribute_qual_variant (type, attrs, TYPE_QUALS (type));
523 : : }
524 : :
525 : : /* Reconstruct a complex derived type. This is used to re-construct types
526 : : with the vector attribute. It is called via a langhook. */
527 : :
528 : : tree
529 : 493584 : c_reconstruct_complex_type (tree type, tree bottom)
530 : : {
531 : 493584 : tree inner, outer;
532 : :
533 : 493584 : if (TREE_CODE (type) == POINTER_TYPE)
534 : : {
535 : 16 : inner = c_reconstruct_complex_type (TREE_TYPE (type), bottom);
536 : 16 : outer = c_build_pointer_type_for_mode (inner, TYPE_MODE (type),
537 : 16 : TYPE_REF_CAN_ALIAS_ALL (type));
538 : : }
539 : : else if (TREE_CODE (type) == ARRAY_TYPE)
540 : : {
541 : 13 : inner = c_reconstruct_complex_type (TREE_TYPE (type), bottom);
542 : 13 : outer = c_build_array_type (inner, TYPE_DOMAIN (type));
543 : :
544 : 13 : gcc_checking_assert (C_TYPE_VARIABLE_SIZE (type)
545 : : == C_TYPE_VARIABLE_SIZE (outer));
546 : 13 : gcc_checking_assert (C_TYPE_VARIABLY_MODIFIED (outer)
547 : : == C_TYPE_VARIABLY_MODIFIED (type));
548 : : }
549 : : else if (TREE_CODE (type) == FUNCTION_TYPE)
550 : : {
551 : 170 : inner = c_reconstruct_complex_type (TREE_TYPE (type), bottom);
552 : 170 : outer = c_build_function_type (inner, TYPE_ARG_TYPES (type),
553 : 170 : TYPE_NO_NAMED_ARGS_STDARG_P (type));
554 : : }
555 : : else if (TREE_CODE (type) == REFERENCE_TYPE
556 : : || TREE_CODE (type) == OFFSET_TYPE)
557 : 0 : gcc_unreachable ();
558 : : else
559 : : return bottom;
560 : :
561 : 199 : return c_build_type_attribute_qual_variant (outer, TYPE_ATTRIBUTES (type),
562 : 398 : TYPE_QUALS (type));
563 : : }
564 : :
565 : : /* If NTYPE is a type of a non-variadic function with a prototype
566 : : and OTYPE is a type of a function without a prototype and ATTRS
567 : : contains attribute format, diagnosess and removes it from ATTRS.
568 : : Returns the result of build_type_attribute_variant of NTYPE and
569 : : the (possibly) modified ATTRS. */
570 : :
571 : : static tree
572 : 9745 : c_build_functype_attribute_variant (tree ntype, tree otype, tree attrs)
573 : : {
574 : 9745 : if (!prototype_p (otype)
575 : 9733 : && prototype_p (ntype)
576 : 19448 : && lookup_attribute ("format", attrs))
577 : : {
578 : 14 : warning_at (input_location, OPT_Wattributes,
579 : : "%qs attribute can only be applied to variadic functions",
580 : : "format");
581 : 14 : attrs = remove_attribute ("format", attrs);
582 : : }
583 : 9745 : return c_build_type_attribute_variant (ntype, attrs);
584 : :
585 : : }
586 : :
587 : : /* Given a type which could be a typedef name, make sure to return the
588 : : original type. See set_underlying_type. */
589 : : static const_tree
590 : 61551536 : c_type_original (const_tree t)
591 : : {
592 : : /* It may even be a typedef of a typedef...
593 : : In the case of compiler-created builtin structs the TYPE_DECL
594 : : may be a dummy, with no DECL_ORIGINAL_TYPE. Don't fault. */
595 : 61551536 : while (TYPE_NAME (t)
596 : 31854257 : && TREE_CODE (TYPE_NAME (t)) == TYPE_DECL
597 : 61555416 : && DECL_ORIGINAL_TYPE (TYPE_NAME (t)))
598 : 1939 : t = DECL_ORIGINAL_TYPE (TYPE_NAME (t));
599 : 61551536 : return t;
600 : : }
601 : :
602 : : /* Return the tag for a tagged type. */
603 : : tree
604 : 61551536 : c_type_tag (const_tree t)
605 : : {
606 : 61551536 : gcc_assert (RECORD_OR_UNION_TYPE_P (t) || TREE_CODE (t) == ENUMERAL_TYPE);
607 : 61551536 : const_tree orig = c_type_original (t);
608 : 61551536 : tree name = TYPE_NAME (orig);
609 : 61551536 : if (!name)
610 : : return NULL_TREE;
611 : 31852318 : if (TREE_CODE (name) == TYPE_DECL)
612 : : {
613 : : /* A TYPE_DECL added by add_decl_expr. */
614 : 2 : gcc_checking_assert (!DECL_NAME (name));
615 : : return NULL_TREE;
616 : : }
617 : 31852316 : gcc_checking_assert (TREE_CODE (name) == IDENTIFIER_NODE);
618 : : return name;
619 : : }
620 : :
621 : : /* Remove qualifiers but not atomic. For arrays remove qualifiers
622 : : on the element type but also do not remove atomic. */
623 : : static tree
624 : 61892419 : remove_qualifiers (tree t)
625 : : {
626 : 61892419 : if (!t || t == error_mark_node)
627 : : return t;
628 : 61892394 : return TYPE_ATOMIC (strip_array_types (t))
629 : 61892394 : ? c_build_qualified_type (TYPE_MAIN_VARIANT (t), TYPE_QUAL_ATOMIC)
630 : 61876849 : : TYPE_MAIN_VARIANT (t);
631 : : }
632 : :
633 : :
634 : : /* Return the composite type of two compatible types.
635 : :
636 : : We assume that comptypes has already been done and returned
637 : : nonzero; if that isn't so, this may crash. In particular, we
638 : : assume that qualifiers match. */
639 : :
640 : : struct composite_cache {
641 : : tree t1;
642 : : tree t2;
643 : : tree composite;
644 : : struct composite_cache* next;
645 : : };
646 : :
647 : : tree
648 : 12897011 : composite_type_internal (tree t1, tree t2, tree cond,
649 : : struct composite_cache* cache)
650 : : {
651 : 12897011 : enum tree_code code1;
652 : 12897011 : enum tree_code code2;
653 : 12897011 : tree attributes;
654 : :
655 : : /* Save time if the two types are the same. */
656 : :
657 : 12897011 : if (t1 == t2) return t1;
658 : :
659 : : /* If one type is nonsense, use the other. */
660 : 2609528 : if (t1 == error_mark_node)
661 : : return t2;
662 : 2609524 : if (t2 == error_mark_node)
663 : : return t1;
664 : :
665 : 2609522 : code1 = TREE_CODE (t1);
666 : 2609522 : code2 = TREE_CODE (t2);
667 : :
668 : : /* Merge the attributes. */
669 : 2609522 : attributes = targetm.merge_type_attributes (t1, t2);
670 : :
671 : : /* If one is an enumerated type and the other is the compatible
672 : : integer type, the composite type might be either of the two
673 : : (DR#013 question 3). For consistency, use the enumerated type as
674 : : the composite type. */
675 : :
676 : 2609522 : if (code1 == ENUMERAL_TYPE
677 : 196 : && (code2 == INTEGER_TYPE
678 : 196 : || code2 == BOOLEAN_TYPE))
679 : : return t1;
680 : 2609326 : if (code2 == ENUMERAL_TYPE
681 : 69 : && (code1 == INTEGER_TYPE
682 : 69 : || code1 == BOOLEAN_TYPE))
683 : : return t2;
684 : :
685 : 2609257 : gcc_assert (code1 == code2);
686 : :
687 : 2609257 : switch (code1)
688 : : {
689 : 6341 : case POINTER_TYPE:
690 : : /* For two pointers, do this recursively on the target type. */
691 : 6341 : {
692 : 6341 : tree pointed_to_1 = TREE_TYPE (t1);
693 : 6341 : tree pointed_to_2 = TREE_TYPE (t2);
694 : 6341 : tree target = composite_type_internal (pointed_to_1, pointed_to_2,
695 : : cond, cache);
696 : 6341 : t1 = c_build_pointer_type_for_mode (target, TYPE_MODE (t1), false);
697 : 6341 : t1 = c_build_type_attribute_variant (t1, attributes);
698 : 6341 : return qualify_type (t1, t2);
699 : : }
700 : :
701 : 10958 : case ARRAY_TYPE:
702 : 10958 : {
703 : 10958 : tree d1 = TYPE_DOMAIN (t1);
704 : 10958 : tree d2 = TYPE_DOMAIN (t2);
705 : :
706 : : /* We should not have any type quals on arrays at all. */
707 : 10958 : gcc_assert (!TYPE_QUALS_NO_ADDR_SPACE (t1)
708 : : && !TYPE_QUALS_NO_ADDR_SPACE (t2));
709 : :
710 : 10958 : bool t1_complete = COMPLETE_TYPE_P (t1);
711 : 10958 : bool t2_complete = COMPLETE_TYPE_P (t2);
712 : :
713 : 10958 : bool d1_zero = d1 == NULL_TREE || !TYPE_MAX_VALUE (d1);
714 : 10958 : bool d2_zero = d2 == NULL_TREE || !TYPE_MAX_VALUE (d2);
715 : :
716 : 10958 : bool d1_variable, d2_variable;
717 : :
718 : 21916 : d1_variable = (!d1_zero
719 : 10958 : && (TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST
720 : 10365 : || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST));
721 : 21916 : d2_variable = (!d2_zero
722 : 10958 : && (TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST
723 : 10618 : || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST));
724 : :
725 : 10958 : bool use1 = d1 && (d2_variable || d2_zero || !d1_variable);
726 : 10958 : bool use2 = d2 && (d1_variable || d1_zero || !d2_variable);
727 : :
728 : : /* If the first is an unspecified size pick the other one. */
729 : 8976 : if (d2_variable && c_type_unspecified_p (t1))
730 : : {
731 : 28 : gcc_assert (use1 && use2);
732 : : use1 = false;
733 : : }
734 : :
735 : : /* If both are VLAs but not unspecified and we are in the
736 : : conditional operator, we create a conditional to select
737 : : the size of the active branch. */
738 : 202 : bool use0 = cond && d1_variable && !c_type_unspecified_p (t1)
739 : 11157 : && d2_variable && !c_type_unspecified_p (t2);
740 : :
741 : 10958 : tree td;
742 : 10958 : tree elt = composite_type_internal (TREE_TYPE (t1), TREE_TYPE (t2),
743 : : cond, cache);
744 : :
745 : 10958 : if (!use0)
746 : : {
747 : : /* Save space: see if the result is identical to one of the args. */
748 : 10865 : if (elt == TREE_TYPE (t1) && use1)
749 : 10079 : return c_build_type_attribute_variant (t1, attributes);
750 : 786 : if (elt == TREE_TYPE (t2) && use2)
751 : 668 : return c_build_type_attribute_variant (t2, attributes);
752 : :
753 : 161 : if (elt == TREE_TYPE (t1) && !TYPE_DOMAIN (t2) && !TYPE_DOMAIN (t1))
754 : 10 : return c_build_type_attribute_variant (t1, attributes);
755 : 116 : if (elt == TREE_TYPE (t2) && !TYPE_DOMAIN (t2) && !TYPE_DOMAIN (t1))
756 : 2 : return c_build_type_attribute_variant (t2, attributes);
757 : :
758 : 212 : td = TYPE_DOMAIN (use1 ? t1 : t2);
759 : : }
760 : : else
761 : : {
762 : : /* Not used in C. */
763 : 93 : gcc_assert (size_zero_node == TYPE_MIN_VALUE (d1));
764 : 93 : gcc_assert (size_zero_node == TYPE_MIN_VALUE (d2));
765 : :
766 : 93 : tree d = fold_build3_loc (UNKNOWN_LOCATION, COND_EXPR, sizetype,
767 : 93 : cond, TYPE_MAX_VALUE (d1),
768 : 93 : TYPE_MAX_VALUE (d2));
769 : :
770 : 93 : td = build_index_type (d);
771 : : }
772 : :
773 : : /* Merge the element types, and have a size if either arg has
774 : : one. We may have qualifiers on the element types. To set
775 : : up TYPE_MAIN_VARIANT correctly, we need to form the
776 : : composite of the unqualified types and add the qualifiers
777 : : back at the end. */
778 : 199 : int quals = TYPE_QUALS (strip_array_types (elt));
779 : 199 : tree unqual_elt = c_build_qualified_type (elt, TYPE_UNQUALIFIED);
780 : :
781 : 199 : t1 = c_build_array_type (unqual_elt, td);
782 : :
783 : : /* Check that a type which has a varying outermost dimension
784 : : got marked has having a variable size. */
785 : 199 : bool varsize = (d1_variable && d2_variable)
786 : 97 : || (d1_variable && !t2_complete)
787 : 285 : || (d2_variable && !t1_complete);
788 : 133 : gcc_checking_assert (!varsize || C_TYPE_VARIABLE_SIZE (t1));
789 : :
790 : : /* Ensure a composite type involving a zero-length array type
791 : : is a zero-length type not an incomplete type. */
792 : 199 : if (d1_zero && d2_zero
793 : 16 : && (t1_complete || t2_complete)
794 : 200 : && !COMPLETE_TYPE_P (t1))
795 : : {
796 : 1 : TYPE_SIZE (t1) = bitsize_zero_node;
797 : 1 : TYPE_SIZE_UNIT (t1) = size_zero_node;
798 : : }
799 : 199 : t1 = c_build_qualified_type (t1, quals);
800 : 199 : return c_build_type_attribute_variant (t1, attributes);
801 : : }
802 : :
803 : 162 : case RECORD_TYPE:
804 : 162 : case UNION_TYPE:
805 : 162 : if (flag_isoc23 && !comptypes_same_p (t1, t2))
806 : : {
807 : : /* Go to the original type to get the right tag. */
808 : 101 : tree tag = c_type_tag (t1);
809 : :
810 : 101 : gcc_checking_assert (COMPLETE_TYPE_P (t1) && COMPLETE_TYPE_P (t2));
811 : 101 : gcc_checking_assert (!tag || comptypes (t1, t2));
812 : :
813 : : /* If a composite type for these two types is already under
814 : : construction, return it. */
815 : :
816 : 246 : for (struct composite_cache *c = cache; c != NULL; c = c->next)
817 : 152 : if ((c->t1 == t1 && c->t2 == t2) || (c->t1 == t2 && c->t2 == t1))
818 : 7 : return c->composite;
819 : :
820 : : /* Otherwise, create a new type node and link it into the cache. */
821 : :
822 : 94 : tree n = make_node (code1);
823 : 94 : SET_TYPE_STRUCTURAL_EQUALITY (n);
824 : 94 : TYPE_NAME (n) = tag;
825 : :
826 : 94 : struct composite_cache cache2 = { t1, t2, n, cache };
827 : 94 : cache = &cache2;
828 : :
829 : 94 : tree f1 = TYPE_FIELDS (t1);
830 : 94 : tree f2 = TYPE_FIELDS (t2);
831 : 94 : tree fields = NULL_TREE;
832 : :
833 : 214 : for (tree a = f1, b = f2; a && b;
834 : 120 : a = DECL_CHAIN (a), b = DECL_CHAIN (b))
835 : : {
836 : 120 : tree ta = TREE_TYPE (a);
837 : 120 : tree tb = TREE_TYPE (b);
838 : :
839 : 120 : if (DECL_C_BIT_FIELD (a))
840 : : {
841 : 19 : ta = DECL_BIT_FIELD_TYPE (a);
842 : 19 : tb = DECL_BIT_FIELD_TYPE (b);
843 : : }
844 : :
845 : 120 : gcc_assert (DECL_NAME (a) == DECL_NAME (b));
846 : 120 : gcc_checking_assert (!DECL_NAME (a) || comptypes (ta, tb));
847 : :
848 : 120 : tree t = composite_type_internal (ta, tb, cond, cache);
849 : 120 : tree f = build_decl (input_location, FIELD_DECL, DECL_NAME (a), t);
850 : :
851 : 120 : DECL_PACKED (f) = DECL_PACKED (a);
852 : 120 : SET_DECL_ALIGN (f, DECL_ALIGN (a));
853 : 120 : DECL_ATTRIBUTES (f) = DECL_ATTRIBUTES (a);
854 : 120 : C_DECL_VARIABLE_SIZE (f) = C_TYPE_VARIABLE_SIZE (t);
855 : :
856 : 120 : decl_attributes (&f, DECL_ATTRIBUTES (f), 0);
857 : :
858 : 120 : finish_decl (f, input_location, NULL, NULL, NULL);
859 : :
860 : 120 : if (DECL_C_BIT_FIELD (a))
861 : : {
862 : : /* This will be processed by finish_struct. */
863 : 19 : SET_DECL_C_BIT_FIELD (f);
864 : 19 : DECL_INITIAL (f) = build_int_cst (integer_type_node,
865 : 19 : tree_to_uhwi (DECL_SIZE (a)));
866 : 19 : DECL_NONADDRESSABLE_P (f) = true;
867 : 19 : DECL_PADDING_P (f) = !DECL_NAME (a);
868 : : }
869 : :
870 : 120 : DECL_CHAIN (f) = fields;
871 : 120 : fields = f;
872 : : }
873 : :
874 : 94 : fields = nreverse (fields);
875 : :
876 : : /* Setup the struct/union type. Because we inherit all variably
877 : : modified components, we can ignore the size expression. */
878 : 94 : tree expr = NULL_TREE;
879 : :
880 : : /* Set TYPE_STUB_DECL for debugging symbols. */
881 : 94 : TYPE_STUB_DECL (n) = pushdecl (build_decl (input_location, TYPE_DECL,
882 : : NULL_TREE, n));
883 : :
884 : 94 : n = finish_struct (input_location, n, fields, attributes, NULL,
885 : : &expr);
886 : :
887 : 94 : return qualify_type (n, t1);
888 : : }
889 : : /* FALLTHRU */
890 : 61 : case ENUMERAL_TYPE:
891 : 61 : if (attributes != NULL)
892 : : {
893 : : /* Try harder not to create a new aggregate type. */
894 : 4 : if (attribute_list_equal (TYPE_ATTRIBUTES (t1), attributes))
895 : : return t1;
896 : 0 : if (attribute_list_equal (TYPE_ATTRIBUTES (t2), attributes))
897 : : return t2;
898 : : }
899 : 57 : return c_build_type_attribute_variant (t1, attributes);
900 : :
901 : 2550972 : case FUNCTION_TYPE:
902 : : /* Function types: prefer the one that specified arg types.
903 : : If both do, merge the arg types. Also merge the return types. */
904 : 2550972 : {
905 : 2550972 : tree valtype = composite_type_internal (TREE_TYPE (t1), TREE_TYPE (t2),
906 : : cond, cache);
907 : 2550972 : tree p1 = TYPE_ARG_TYPES (t1);
908 : 2550972 : tree p2 = TYPE_ARG_TYPES (t2);
909 : 2550972 : int len;
910 : 2550972 : tree newargs, n;
911 : 2550972 : int i;
912 : :
913 : : /* Save space: see if the result is identical to one of the args. */
914 : 2550972 : if (valtype == TREE_TYPE (t1) && !TYPE_ARG_TYPES (t2))
915 : 9228 : return c_build_functype_attribute_variant (t1, t2, attributes);
916 : 2541744 : if (valtype == TREE_TYPE (t2) && !TYPE_ARG_TYPES (t1))
917 : 517 : return c_build_functype_attribute_variant (t2, t1, attributes);
918 : :
919 : : /* Simple way if one arg fails to specify argument types. */
920 : 2541227 : if (TYPE_ARG_TYPES (t1) == NULL_TREE)
921 : : {
922 : 9 : t1 = c_build_function_type (valtype, TYPE_ARG_TYPES (t2),
923 : 9 : TYPE_NO_NAMED_ARGS_STDARG_P (t2));
924 : 9 : t1 = c_build_type_attribute_variant (t1, attributes);
925 : 9 : return qualify_type (t1, t2);
926 : : }
927 : 2541218 : if (TYPE_ARG_TYPES (t2) == NULL_TREE)
928 : : {
929 : 1 : t1 = c_build_function_type (valtype, TYPE_ARG_TYPES (t1),
930 : 1 : TYPE_NO_NAMED_ARGS_STDARG_P (t1));
931 : 1 : t1 = c_build_type_attribute_variant (t1, attributes);
932 : 1 : return qualify_type (t1, t2);
933 : : }
934 : :
935 : : /* If both args specify argument types, we must merge the two
936 : : lists, argument by argument. */
937 : :
938 : : for (len = 0, newargs = p1;
939 : 6613969 : newargs && newargs != void_list_node;
940 : 4072752 : len++, newargs = TREE_CHAIN (newargs))
941 : : ;
942 : :
943 : 6613969 : for (i = 0; i < len; i++)
944 : 4072752 : newargs = tree_cons (NULL_TREE, NULL_TREE, newargs);
945 : :
946 : : n = newargs;
947 : :
948 : 6613969 : for (; p1 && p1 != void_list_node;
949 : 4072752 : p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2), n = TREE_CHAIN (n))
950 : : {
951 : 4072752 : tree mv1 = remove_qualifiers (TREE_VALUE (p1));
952 : 4072752 : tree mv2 = remove_qualifiers (TREE_VALUE (p2));
953 : :
954 : : /* A null type means arg type is not specified.
955 : : Take whatever the other function type has. */
956 : 4072752 : if (TREE_VALUE (p1) == NULL_TREE)
957 : : {
958 : 0 : TREE_VALUE (n) = TREE_VALUE (p2);
959 : 0 : goto parm_done;
960 : : }
961 : 4072752 : if (TREE_VALUE (p2) == NULL_TREE)
962 : : {
963 : 0 : TREE_VALUE (n) = TREE_VALUE (p1);
964 : 0 : goto parm_done;
965 : : }
966 : :
967 : : /* Given wait (union {union wait *u; int *i} *)
968 : : and wait (union wait *),
969 : : prefer union wait * as type of parm. */
970 : 4072752 : if (TREE_CODE (TREE_VALUE (p1)) == UNION_TYPE
971 : 4072752 : && TREE_VALUE (p1) != TREE_VALUE (p2))
972 : : {
973 : 30 : tree memb;
974 : 30 : for (memb = TYPE_FIELDS (TREE_VALUE (p1));
975 : 38 : memb; memb = DECL_CHAIN (memb))
976 : : {
977 : 38 : tree mv3 = TREE_TYPE (memb);
978 : 38 : if (mv3 && mv3 != error_mark_node
979 : 38 : && TREE_CODE (mv3) != ARRAY_TYPE)
980 : 38 : mv3 = TYPE_MAIN_VARIANT (mv3);
981 : 38 : if (comptypes (mv3, mv2))
982 : : {
983 : 60 : TREE_VALUE (n) = composite_type_internal (TREE_TYPE (memb),
984 : 30 : TREE_VALUE (p2),
985 : : cond, cache);
986 : 30 : pedwarn (input_location, OPT_Wpedantic,
987 : : "function types not truly compatible in ISO C");
988 : 30 : goto parm_done;
989 : : }
990 : : }
991 : : }
992 : 4072722 : if (TREE_CODE (TREE_VALUE (p2)) == UNION_TYPE
993 : 4072722 : && TREE_VALUE (p2) != TREE_VALUE (p1))
994 : : {
995 : 30 : tree memb;
996 : 30 : for (memb = TYPE_FIELDS (TREE_VALUE (p2));
997 : 38 : memb; memb = DECL_CHAIN (memb))
998 : : {
999 : 38 : tree mv3 = TREE_TYPE (memb);
1000 : 38 : if (mv3 && mv3 != error_mark_node
1001 : 38 : && TREE_CODE (mv3) != ARRAY_TYPE)
1002 : 38 : mv3 = TYPE_MAIN_VARIANT (mv3);
1003 : 38 : if (comptypes (mv3, mv1))
1004 : : {
1005 : 30 : TREE_VALUE (n)
1006 : 30 : = composite_type_internal (TREE_TYPE (memb),
1007 : 30 : TREE_VALUE (p1),
1008 : : cond, cache);
1009 : 30 : pedwarn (input_location, OPT_Wpedantic,
1010 : : "function types not truly compatible in ISO C");
1011 : 30 : goto parm_done;
1012 : : }
1013 : : }
1014 : : }
1015 : 4072692 : TREE_VALUE (n) = composite_type_internal (mv1, mv2, cond, cache);
1016 : 4072752 : parm_done: ;
1017 : : }
1018 : :
1019 : 2541217 : t1 = c_build_function_type (valtype, newargs);
1020 : 2541217 : t1 = qualify_type (t1, t2);
1021 : : }
1022 : : /* FALLTHRU */
1023 : :
1024 : 2582041 : default:
1025 : 2582041 : return c_build_type_attribute_variant (t1, attributes);
1026 : : }
1027 : : }
1028 : :
1029 : : tree
1030 : 6255868 : composite_type_cond (tree t1, tree t2, tree cond)
1031 : : {
1032 : 6255868 : gcc_checking_assert (comptypes_check_for_composite (t1, t2));
1033 : :
1034 : 6255868 : struct composite_cache cache = { };
1035 : 6255868 : tree n = composite_type_internal (t1, t2, cond, &cache);
1036 : :
1037 : 6255868 : gcc_checking_assert (comptypes_check_for_composite (n, t1));
1038 : 6255868 : gcc_checking_assert (comptypes_check_for_composite (n, t2));
1039 : 6255868 : return n;
1040 : : }
1041 : :
1042 : :
1043 : : tree
1044 : 6251423 : composite_type (tree t1, tree t2)
1045 : : {
1046 : 6251423 : return composite_type_cond (t1, t2, NULL_TREE);
1047 : : }
1048 : :
1049 : : /* Return the type of a conditional expression between pointers to
1050 : : possibly differently qualified versions of compatible types.
1051 : :
1052 : : We assume that comp_target_types has already been done and returned
1053 : : true; if that isn't so, this may crash. */
1054 : :
1055 : : static tree
1056 : 114321 : common_pointer_type (tree t1, tree t2, tree cond)
1057 : : {
1058 : 114321 : tree attributes;
1059 : 114321 : unsigned target_quals;
1060 : 114321 : addr_space_t as1, as2, as_common;
1061 : 114321 : int quals1, quals2;
1062 : :
1063 : : /* Save time if the two types are the same. */
1064 : :
1065 : 114321 : if (t1 == t2) return t1;
1066 : :
1067 : : /* If one type is nonsense, use the other. */
1068 : 4445 : if (t1 == error_mark_node)
1069 : : return t2;
1070 : 4445 : if (t2 == error_mark_node)
1071 : : return t1;
1072 : :
1073 : 4445 : gcc_assert (TREE_CODE (t1) == POINTER_TYPE
1074 : : && TREE_CODE (t2) == POINTER_TYPE);
1075 : :
1076 : : /* Merge the attributes. */
1077 : 4445 : attributes = targetm.merge_type_attributes (t1, t2);
1078 : :
1079 : : /* Find the composite type of the target types, and combine the
1080 : : qualifiers of the two types' targets. */
1081 : 4445 : tree pointed_to_1 = TREE_TYPE (t1);
1082 : 4445 : tree pointed_to_2 = TREE_TYPE (t2);
1083 : 4445 : tree target = composite_type_cond (TYPE_MAIN_VARIANT (pointed_to_1),
1084 : 4445 : TYPE_MAIN_VARIANT (pointed_to_2), cond);
1085 : :
1086 : : /* Strip array types to get correct qualifier for pointers to arrays */
1087 : 4445 : quals1 = TYPE_QUALS_NO_ADDR_SPACE (strip_array_types (pointed_to_1));
1088 : 4445 : quals2 = TYPE_QUALS_NO_ADDR_SPACE (strip_array_types (pointed_to_2));
1089 : :
1090 : : /* For function types do not merge const qualifiers, but drop them
1091 : : if used inconsistently. The middle-end uses these to mark const
1092 : : and noreturn functions. */
1093 : 4445 : if (TREE_CODE (pointed_to_1) == FUNCTION_TYPE)
1094 : 2129 : target_quals = (quals1 & quals2);
1095 : : else
1096 : 2316 : target_quals = (quals1 | quals2);
1097 : :
1098 : : /* If the two named address spaces are different, determine the common
1099 : : superset address space. This is guaranteed to exist due to the
1100 : : assumption that comp_target_type returned true. */
1101 : 4445 : as1 = TYPE_ADDR_SPACE (pointed_to_1);
1102 : 4445 : as2 = TYPE_ADDR_SPACE (pointed_to_2);
1103 : 4445 : if (!addr_space_superset (as1, as2, &as_common))
1104 : 0 : gcc_unreachable ();
1105 : :
1106 : 4445 : target_quals |= ENCODE_QUAL_ADDR_SPACE (as_common);
1107 : :
1108 : 4445 : t1 = c_build_pointer_type (c_build_qualified_type (target, target_quals));
1109 : 4445 : return c_build_type_attribute_variant (t1, attributes);
1110 : : }
1111 : :
1112 : : /* Return the common type for two arithmetic types under the usual
1113 : : arithmetic conversions. The default conversions have already been
1114 : : applied, and enumerated types converted to their compatible integer
1115 : : types. The resulting type is unqualified and has no attributes.
1116 : :
1117 : : This is the type for the result of most arithmetic operations
1118 : : if the operands have the given two types. */
1119 : :
1120 : : static tree
1121 : 13818070 : c_common_type (tree t1, tree t2)
1122 : : {
1123 : 13818070 : enum tree_code code1;
1124 : 13818070 : enum tree_code code2;
1125 : :
1126 : : /* If one type is nonsense, use the other. */
1127 : 13818070 : if (t1 == error_mark_node)
1128 : : return t2;
1129 : 13818070 : if (t2 == error_mark_node)
1130 : : return t1;
1131 : :
1132 : 13818070 : if (TYPE_QUALS (t1) != TYPE_UNQUALIFIED)
1133 : 38096 : t1 = TYPE_MAIN_VARIANT (t1);
1134 : :
1135 : 13818070 : if (TYPE_QUALS (t2) != TYPE_UNQUALIFIED)
1136 : 49349 : t2 = TYPE_MAIN_VARIANT (t2);
1137 : :
1138 : 13818070 : if (TYPE_ATTRIBUTES (t1) != NULL_TREE)
1139 : : {
1140 : 187662 : tree attrs = affects_type_identity_attributes (TYPE_ATTRIBUTES (t1));
1141 : 187662 : t1 = c_build_type_attribute_variant (t1, attrs);
1142 : : }
1143 : :
1144 : 13818070 : if (TYPE_ATTRIBUTES (t2) != NULL_TREE)
1145 : : {
1146 : 187140 : tree attrs = affects_type_identity_attributes (TYPE_ATTRIBUTES (t2));
1147 : 187140 : t2 = c_build_type_attribute_variant (t2, attrs);
1148 : : }
1149 : :
1150 : : /* Save time if the two types are the same. */
1151 : :
1152 : 13818070 : if (t1 == t2) return t1;
1153 : :
1154 : 2315161 : code1 = TREE_CODE (t1);
1155 : 2315161 : code2 = TREE_CODE (t2);
1156 : :
1157 : 2315161 : gcc_assert (code1 == VECTOR_TYPE || code1 == COMPLEX_TYPE
1158 : : || code1 == FIXED_POINT_TYPE || code1 == REAL_TYPE
1159 : : || code1 == INTEGER_TYPE || code1 == BITINT_TYPE);
1160 : 2315161 : gcc_assert (code2 == VECTOR_TYPE || code2 == COMPLEX_TYPE
1161 : : || code2 == FIXED_POINT_TYPE || code2 == REAL_TYPE
1162 : : || code2 == INTEGER_TYPE || code2 == BITINT_TYPE);
1163 : :
1164 : : /* When one operand is a decimal float type, the other operand cannot be
1165 : : a generic float type or a complex type. We also disallow vector types
1166 : : here. */
1167 : 2315161 : if ((DECIMAL_FLOAT_TYPE_P (t1) || DECIMAL_FLOAT_TYPE_P (t2))
1168 : 2317584 : && !(DECIMAL_FLOAT_TYPE_P (t1) && DECIMAL_FLOAT_TYPE_P (t2)))
1169 : : {
1170 : 1080 : if (code1 == VECTOR_TYPE || code2 == VECTOR_TYPE)
1171 : : {
1172 : 3 : error ("cannot mix operands of decimal floating and vector types");
1173 : 3 : return error_mark_node;
1174 : : }
1175 : 1077 : if (code1 == COMPLEX_TYPE || code2 == COMPLEX_TYPE)
1176 : : {
1177 : 5 : error ("cannot mix operands of decimal floating and complex types");
1178 : 5 : return error_mark_node;
1179 : : }
1180 : 1072 : if (code1 == REAL_TYPE && code2 == REAL_TYPE)
1181 : : {
1182 : 16 : error ("cannot mix operands of decimal floating "
1183 : : "and other floating types");
1184 : 16 : return error_mark_node;
1185 : : }
1186 : : }
1187 : :
1188 : : /* If one type is a vector type, return that type. (How the usual
1189 : : arithmetic conversions apply to the vector types extension is not
1190 : : precisely specified.) */
1191 : 2315137 : if (code1 == VECTOR_TYPE)
1192 : : return t1;
1193 : :
1194 : 2314859 : if (code2 == VECTOR_TYPE)
1195 : : return t2;
1196 : :
1197 : : /* If one type is complex, form the common type of the non-complex
1198 : : components, then make that complex. Use T1 or T2 if it is the
1199 : : required type. */
1200 : 2314856 : if (code1 == COMPLEX_TYPE || code2 == COMPLEX_TYPE)
1201 : : {
1202 : 89315 : tree subtype1 = code1 == COMPLEX_TYPE ? TREE_TYPE (t1) : t1;
1203 : 89315 : tree subtype2 = code2 == COMPLEX_TYPE ? TREE_TYPE (t2) : t2;
1204 : 89315 : tree subtype = c_common_type (subtype1, subtype2);
1205 : :
1206 : 89315 : if (code1 == COMPLEX_TYPE && TREE_TYPE (t1) == subtype)
1207 : : return t1;
1208 : 59200 : else if (code2 == COMPLEX_TYPE && TREE_TYPE (t2) == subtype)
1209 : : return t2;
1210 : 3241 : else if (TREE_CODE (subtype) == BITINT_TYPE)
1211 : : {
1212 : 8 : sorry ("%<_Complex _BitInt(%d)%> unsupported",
1213 : 4 : TYPE_PRECISION (subtype));
1214 : 6 : return code1 == COMPLEX_TYPE ? t1 : t2;
1215 : : }
1216 : : else
1217 : 3237 : return build_complex_type (subtype);
1218 : : }
1219 : :
1220 : : /* If only one is real, use it as the result. */
1221 : :
1222 : 2225541 : if (code1 == REAL_TYPE && code2 != REAL_TYPE)
1223 : : return t1;
1224 : :
1225 : 2098720 : if (code2 == REAL_TYPE && code1 != REAL_TYPE)
1226 : : return t2;
1227 : :
1228 : : /* If both are real and either are decimal floating point types, use
1229 : : the decimal floating point type with the greater precision. */
1230 : :
1231 : 2068358 : if (code1 == REAL_TYPE && code2 == REAL_TYPE)
1232 : : {
1233 : 107157 : if (TYPE_MAIN_VARIANT (t1) == dfloat128_type_node
1234 : 107157 : || TYPE_MAIN_VARIANT (t2) == dfloat128_type_node)
1235 : : return dfloat128_type_node;
1236 : : /* And prefer _Decimal128 over _Decimal64x which has in GCC's
1237 : : implementation the same mode. */
1238 : 106608 : else if (TYPE_MAIN_VARIANT (t1) == dfloat64x_type_node
1239 : 106608 : || TYPE_MAIN_VARIANT (t2) == dfloat64x_type_node)
1240 : : return dfloat64x_type_node;
1241 : 106604 : else if (TYPE_MAIN_VARIANT (t1) == dfloat64_type_node
1242 : 106604 : || TYPE_MAIN_VARIANT (t2) == dfloat64_type_node)
1243 : : return dfloat64_type_node;
1244 : 106159 : else if (TYPE_MAIN_VARIANT (t1) == dfloat32_type_node
1245 : 106159 : || TYPE_MAIN_VARIANT (t2) == dfloat32_type_node)
1246 : : return dfloat32_type_node;
1247 : : }
1248 : :
1249 : : /* Deal with fixed-point types. */
1250 : 2067015 : if (code1 == FIXED_POINT_TYPE || code2 == FIXED_POINT_TYPE)
1251 : : {
1252 : 0 : unsigned int unsignedp = 0, satp = 0;
1253 : 0 : scalar_mode m1, m2;
1254 : 0 : unsigned int fbit1, ibit1, fbit2, ibit2, max_fbit, max_ibit;
1255 : :
1256 : 0 : m1 = SCALAR_TYPE_MODE (t1);
1257 : 0 : m2 = SCALAR_TYPE_MODE (t2);
1258 : :
1259 : : /* If one input type is saturating, the result type is saturating. */
1260 : 0 : if (TYPE_SATURATING (t1) || TYPE_SATURATING (t2))
1261 : : satp = 1;
1262 : :
1263 : : /* If both fixed-point types are unsigned, the result type is unsigned.
1264 : : When mixing fixed-point and integer types, follow the sign of the
1265 : : fixed-point type.
1266 : : Otherwise, the result type is signed. */
1267 : 0 : if ((TYPE_UNSIGNED (t1) && TYPE_UNSIGNED (t2)
1268 : 0 : && code1 == FIXED_POINT_TYPE && code2 == FIXED_POINT_TYPE)
1269 : 0 : || (code1 == FIXED_POINT_TYPE && code2 != FIXED_POINT_TYPE
1270 : 0 : && TYPE_UNSIGNED (t1))
1271 : 0 : || (code1 != FIXED_POINT_TYPE && code2 == FIXED_POINT_TYPE
1272 : 0 : && TYPE_UNSIGNED (t2)))
1273 : : unsignedp = 1;
1274 : :
1275 : : /* The result type is signed. */
1276 : 0 : if (unsignedp == 0)
1277 : : {
1278 : : /* If the input type is unsigned, we need to convert to the
1279 : : signed type. */
1280 : 0 : if (code1 == FIXED_POINT_TYPE && TYPE_UNSIGNED (t1))
1281 : : {
1282 : 0 : enum mode_class mclass = (enum mode_class) 0;
1283 : 0 : if (GET_MODE_CLASS (m1) == MODE_UFRACT)
1284 : : mclass = MODE_FRACT;
1285 : 0 : else if (GET_MODE_CLASS (m1) == MODE_UACCUM)
1286 : : mclass = MODE_ACCUM;
1287 : : else
1288 : 0 : gcc_unreachable ();
1289 : 0 : m1 = as_a <scalar_mode>
1290 : 0 : (mode_for_size (GET_MODE_PRECISION (m1), mclass, 0));
1291 : : }
1292 : 0 : if (code2 == FIXED_POINT_TYPE && TYPE_UNSIGNED (t2))
1293 : : {
1294 : 0 : enum mode_class mclass = (enum mode_class) 0;
1295 : 0 : if (GET_MODE_CLASS (m2) == MODE_UFRACT)
1296 : : mclass = MODE_FRACT;
1297 : 0 : else if (GET_MODE_CLASS (m2) == MODE_UACCUM)
1298 : : mclass = MODE_ACCUM;
1299 : : else
1300 : 0 : gcc_unreachable ();
1301 : 0 : m2 = as_a <scalar_mode>
1302 : 0 : (mode_for_size (GET_MODE_PRECISION (m2), mclass, 0));
1303 : : }
1304 : : }
1305 : :
1306 : 0 : if (code1 == FIXED_POINT_TYPE)
1307 : : {
1308 : 0 : fbit1 = GET_MODE_FBIT (m1);
1309 : 0 : ibit1 = GET_MODE_IBIT (m1);
1310 : : }
1311 : : else
1312 : : {
1313 : 0 : fbit1 = 0;
1314 : : /* Signed integers need to subtract one sign bit. */
1315 : 0 : ibit1 = TYPE_PRECISION (t1) - (!TYPE_UNSIGNED (t1));
1316 : : }
1317 : :
1318 : 0 : if (code2 == FIXED_POINT_TYPE)
1319 : : {
1320 : 0 : fbit2 = GET_MODE_FBIT (m2);
1321 : 0 : ibit2 = GET_MODE_IBIT (m2);
1322 : : }
1323 : : else
1324 : : {
1325 : 0 : fbit2 = 0;
1326 : : /* Signed integers need to subtract one sign bit. */
1327 : 0 : ibit2 = TYPE_PRECISION (t2) - (!TYPE_UNSIGNED (t2));
1328 : : }
1329 : :
1330 : 0 : max_ibit = ibit1 >= ibit2 ? ibit1 : ibit2;
1331 : 0 : max_fbit = fbit1 >= fbit2 ? fbit1 : fbit2;
1332 : 0 : return c_common_fixed_point_type_for_size (max_ibit, max_fbit, unsignedp,
1333 : : satp);
1334 : : }
1335 : :
1336 : : /* Both real or both integers; use the one with greater precision. */
1337 : :
1338 : 2067015 : if (TYPE_PRECISION (t1) > TYPE_PRECISION (t2))
1339 : : return t1;
1340 : 1096646 : else if (TYPE_PRECISION (t2) > TYPE_PRECISION (t1))
1341 : : return t2;
1342 : :
1343 : : /* Same precision. Prefer long longs to longs to ints when the
1344 : : same precision, following the C99 rules on integer type rank
1345 : : (which are equivalent to the C90 rules for C90 types). */
1346 : :
1347 : 733665 : if (TYPE_MAIN_VARIANT (t1) == long_long_unsigned_type_node
1348 : 733665 : || TYPE_MAIN_VARIANT (t2) == long_long_unsigned_type_node)
1349 : : return long_long_unsigned_type_node;
1350 : :
1351 : 644494 : if (TYPE_MAIN_VARIANT (t1) == long_long_integer_type_node
1352 : 644494 : || TYPE_MAIN_VARIANT (t2) == long_long_integer_type_node)
1353 : : {
1354 : 15305 : if (TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2))
1355 : 361 : return long_long_unsigned_type_node;
1356 : : else
1357 : : return long_long_integer_type_node;
1358 : : }
1359 : :
1360 : 629189 : if (TYPE_MAIN_VARIANT (t1) == long_unsigned_type_node
1361 : 629189 : || TYPE_MAIN_VARIANT (t2) == long_unsigned_type_node)
1362 : : return long_unsigned_type_node;
1363 : :
1364 : 530134 : if (TYPE_MAIN_VARIANT (t1) == long_integer_type_node
1365 : 530134 : || TYPE_MAIN_VARIANT (t2) == long_integer_type_node)
1366 : : {
1367 : : /* But preserve unsignedness from the other type,
1368 : : since long cannot hold all the values of an unsigned int. */
1369 : 26229 : if (TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2))
1370 : 131 : return long_unsigned_type_node;
1371 : : else
1372 : : return long_integer_type_node;
1373 : : }
1374 : :
1375 : : /* For floating types of the same TYPE_PRECISION (which we here
1376 : : assume means either the same set of values, or sets of values
1377 : : neither a subset of the other, with behavior being undefined in
1378 : : the latter case), follow the rules from TS 18661-3: prefer
1379 : : interchange types _FloatN, then standard types long double,
1380 : : double, float, then extended types _FloatNx. For extended types,
1381 : : check them starting with _Float128x as that seems most consistent
1382 : : in spirit with preferring long double to double; for interchange
1383 : : types, also check in that order for consistency although it's not
1384 : : possible for more than one of them to have the same
1385 : : precision. */
1386 : 503905 : tree mv1 = TYPE_MAIN_VARIANT (t1);
1387 : 503905 : tree mv2 = TYPE_MAIN_VARIANT (t2);
1388 : :
1389 : 2518959 : for (int i = NUM_FLOATN_TYPES - 1; i >= 0; i--)
1390 : 2015217 : if (mv1 == FLOATN_TYPE_NODE (i) || mv2 == FLOATN_TYPE_NODE (i))
1391 : : return FLOATN_TYPE_NODE (i);
1392 : :
1393 : : /* Likewise, prefer long double to double even if same size. */
1394 : 503742 : if (mv1 == long_double_type_node || mv2 == long_double_type_node)
1395 : : return long_double_type_node;
1396 : :
1397 : : /* Likewise, prefer double to float even if same size.
1398 : : We got a couple of embedded targets with 32 bit doubles, and the
1399 : : pdp11 might have 64 bit floats. */
1400 : 503500 : if (mv1 == double_type_node || mv2 == double_type_node)
1401 : : return double_type_node;
1402 : :
1403 : 502928 : if (mv1 == float_type_node || mv2 == float_type_node)
1404 : : return float_type_node;
1405 : :
1406 : 2003036 : for (int i = NUM_FLOATNX_TYPES - 1; i >= 0; i--)
1407 : 1502277 : if (mv1 == FLOATNX_TYPE_NODE (i) || mv2 == FLOATNX_TYPE_NODE (i))
1408 : : return FLOATNX_TYPE_NODE (i);
1409 : :
1410 : 500759 : if ((code1 == BITINT_TYPE || code2 == BITINT_TYPE) && code1 != code2)
1411 : : {
1412 : : /* Prefer any other integral types over bit-precise integer types. */
1413 : 10 : if (TYPE_UNSIGNED (t1) == TYPE_UNSIGNED (t2))
1414 : 6 : return code1 == BITINT_TYPE ? t2 : t1;
1415 : : /* If BITINT_TYPE is unsigned and the other type is signed
1416 : : non-BITINT_TYPE with the same precision, the latter has higher rank.
1417 : : In that case:
1418 : : Otherwise, both operands are converted to the unsigned integer type
1419 : : corresponding to the type of the operand with signed integer type. */
1420 : 8 : if (TYPE_UNSIGNED (code1 == BITINT_TYPE ? t1 : t2))
1421 : 5 : return c_common_unsigned_type (code1 == BITINT_TYPE ? t2 : t1);
1422 : : }
1423 : :
1424 : : /* Otherwise prefer the unsigned one. */
1425 : :
1426 : 500751 : if (TYPE_UNSIGNED (t1))
1427 : : return t1;
1428 : : else
1429 : : return t2;
1430 : : }
1431 : :
1432 : : /* Wrapper around c_common_type that is used by c-common.cc and other
1433 : : front end optimizations that remove promotions. ENUMERAL_TYPEs
1434 : : are allowed here and are converted to their compatible integer types.
1435 : : BOOLEAN_TYPEs are allowed here and return either boolean_type_node or
1436 : : preferably a non-Boolean type as the common type. */
1437 : : tree
1438 : 101820 : common_type (tree t1, tree t2)
1439 : : {
1440 : 101820 : if (TREE_CODE (t1) == ENUMERAL_TYPE)
1441 : 0 : t1 = ENUM_UNDERLYING_TYPE (t1);
1442 : 101820 : if (TREE_CODE (t2) == ENUMERAL_TYPE)
1443 : 1 : t2 = ENUM_UNDERLYING_TYPE (t2);
1444 : :
1445 : : /* If both types are BOOLEAN_TYPE, then return boolean_type_node. */
1446 : 101820 : if (TREE_CODE (t1) == BOOLEAN_TYPE
1447 : 584 : && TREE_CODE (t2) == BOOLEAN_TYPE)
1448 : 584 : return boolean_type_node;
1449 : :
1450 : : /* If either type is BOOLEAN_TYPE, then return the other. */
1451 : 101236 : if (TREE_CODE (t1) == BOOLEAN_TYPE)
1452 : : return t2;
1453 : 101236 : if (TREE_CODE (t2) == BOOLEAN_TYPE)
1454 : : return t1;
1455 : :
1456 : 101236 : return c_common_type (t1, t2);
1457 : : }
1458 : :
1459 : :
1460 : :
1461 : : /* Helper function for comptypes. For two compatible types, return 1
1462 : : if they pass consistency checks. In particular we test that
1463 : : TYPE_CANONICAL is set correctly, i.e. the two types can alias. */
1464 : :
1465 : : static bool
1466 : 44183368 : comptypes_verify (tree type1, tree type2)
1467 : : {
1468 : 44183368 : if (type1 == type2 || !type1 || !type2
1469 : 3466695 : || TREE_CODE (type1) == ERROR_MARK || TREE_CODE (type2) == ERROR_MARK)
1470 : : return true;
1471 : :
1472 : 3466694 : gcc_checking_assert (c_verify_type (type1));
1473 : 3466694 : gcc_checking_assert (c_verify_type (type2));
1474 : :
1475 : 3466694 : if (TYPE_CANONICAL (type1) != TYPE_CANONICAL (type2)
1476 : 384181 : && !TYPE_STRUCTURAL_EQUALITY_P (type1)
1477 : 3849137 : && !TYPE_STRUCTURAL_EQUALITY_P (type2))
1478 : : {
1479 : : /* FIXME: check other types. */
1480 : 382109 : if (RECORD_OR_UNION_TYPE_P (type1)
1481 : 382109 : || TREE_CODE (type1) == ENUMERAL_TYPE
1482 : 382109 : || TREE_CODE (type2) == ENUMERAL_TYPE)
1483 : 0 : return false;
1484 : : }
1485 : : return true;
1486 : : }
1487 : :
1488 : : struct comptypes_data {
1489 : :
1490 : : /* output */
1491 : : bool enum_and_int_p;
1492 : : bool different_types_p;
1493 : : bool warning_needed;
1494 : :
1495 : : /* context */
1496 : : bool anon_field;
1497 : : bool pointedto;
1498 : :
1499 : : /* configuration */
1500 : : bool equiv;
1501 : : bool ignore_promoting_args;
1502 : :
1503 : : const struct tagged_tu_seen_cache* cache;
1504 : : };
1505 : :
1506 : :
1507 : : /* Helper function for composite_type. This function ignores when the
1508 : : function type of an old-style declaration is incompatible with a type
1509 : : of a declaration with prototype because some are arguments are not
1510 : : self-promoting. This is ignored only for function types but not
1511 : : ignored in a nested context. */
1512 : :
1513 : : static bool
1514 : 18767604 : comptypes_check_for_composite (tree t1, tree t2)
1515 : : {
1516 : 18767604 : struct comptypes_data data = { };
1517 : 18767604 : data.ignore_promoting_args = FUNCTION_TYPE == TREE_CODE (t1);
1518 : 18767604 : return comptypes_internal (t1, t2, &data);
1519 : : }
1520 : :
1521 : :
1522 : : /* C implementation of compatible_types_for_indirection_note_p. */
1523 : :
1524 : : bool
1525 : 761 : compatible_types_for_indirection_note_p (tree type1, tree type2)
1526 : : {
1527 : 761 : return comptypes (type1, type2) == 1;
1528 : : }
1529 : :
1530 : : /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
1531 : : or various other operations. Return 2 if they are compatible
1532 : : but a warning may be needed if you use them together. */
1533 : :
1534 : : int
1535 : 56064078 : comptypes (tree type1, tree type2)
1536 : : {
1537 : 56064078 : struct comptypes_data data = { };
1538 : 56064078 : bool ret = comptypes_internal (type1, type2, &data);
1539 : :
1540 : 56064078 : gcc_checking_assert (!ret || comptypes_verify (type1, type2));
1541 : :
1542 : 37691917 : return ret ? (data.warning_needed ? 2 : 1) : 0;
1543 : : }
1544 : :
1545 : :
1546 : : /* Like comptypes, but it returns non-zero only for identical
1547 : : types. */
1548 : :
1549 : : bool
1550 : 280 : comptypes_same_p (tree type1, tree type2)
1551 : : {
1552 : 280 : struct comptypes_data data = { };
1553 : 280 : bool ret = comptypes_internal (type1, type2, &data);
1554 : :
1555 : 280 : gcc_checking_assert (!ret || comptypes_verify (type1, type2));
1556 : :
1557 : 280 : if (data.different_types_p)
1558 : 103 : return false;
1559 : :
1560 : : return ret;
1561 : : }
1562 : :
1563 : :
1564 : : /* Like comptypes, but if it returns non-zero because enum and int are
1565 : : compatible, it sets *ENUM_AND_INT_P to true. */
1566 : :
1567 : : int
1568 : 6690514 : comptypes_check_enum_int (tree type1, tree type2, bool *enum_and_int_p)
1569 : : {
1570 : 6690514 : struct comptypes_data data = { };
1571 : 6690514 : bool ret = comptypes_internal (type1, type2, &data);
1572 : 6690514 : *enum_and_int_p = data.enum_and_int_p;
1573 : :
1574 : 6690514 : gcc_checking_assert (!ret || comptypes_verify (type1, type2));
1575 : :
1576 : 6445538 : return ret ? (data.warning_needed ? 2 : 1) : 0;
1577 : : }
1578 : :
1579 : : /* Like comptypes, but if it returns nonzero for different types, it
1580 : : sets *DIFFERENT_TYPES_P to true. */
1581 : :
1582 : : int
1583 : 45673 : comptypes_check_different_types (tree type1, tree type2,
1584 : : bool *different_types_p)
1585 : : {
1586 : 45673 : struct comptypes_data data = { };
1587 : 45673 : bool ret = comptypes_internal (type1, type2, &data);
1588 : 45673 : *different_types_p = data.different_types_p;
1589 : :
1590 : 45673 : gcc_checking_assert (!ret || comptypes_verify (type1, type2));
1591 : :
1592 : 45673 : return ret ? (data.warning_needed ? 2 : 1) : 0;
1593 : : }
1594 : :
1595 : :
1596 : : /* Like comptypes, but if it returns true for struct and union types
1597 : : considered equivalent for aliasing purposes, i.e. for setting
1598 : : TYPE_CANONICAL after completing a struct or union.
1599 : :
1600 : : This function must return false only for types which are not
1601 : : compatible according to C language semantics (cf. comptypes),
1602 : : otherwise the middle-end would make incorrect aliasing decisions.
1603 : : It may return true for some similar types that are not compatible
1604 : : according to those stricter rules.
1605 : :
1606 : : In particular, we ignore size expression in arrays so that the
1607 : : following structs are in the same equivalence class:
1608 : :
1609 : : struct foo { char (*buf)[]; };
1610 : : struct foo { char (*buf)[3]; };
1611 : : struct foo { char (*buf)[4]; };
1612 : :
1613 : : We also treat unions / structs with members which are pointers to
1614 : : structures or unions with the same tag as equivalent (if they are not
1615 : : incompatible for other reasons). Although incomplete structure
1616 : : or union types are not compatible to any other type, they may become
1617 : : compatible to different types when completed. To avoid having to update
1618 : : TYPE_CANONICAL at this point, we only consider the tag when forming
1619 : : the equivalence classes. For example, the following types with tag
1620 : : 'foo' are all considered equivalent:
1621 : :
1622 : : struct bar;
1623 : : struct foo { struct bar *x };
1624 : : struct foo { struct bar { int a; } *x };
1625 : : struct foo { struct bar { char b; } *x }; */
1626 : :
1627 : : bool
1628 : 14518402 : comptypes_equiv_p (tree type1, tree type2)
1629 : : {
1630 : 14518402 : struct comptypes_data data = { };
1631 : 14518402 : data.equiv = true;
1632 : 14518402 : bool ret = comptypes_internal (type1, type2, &data);
1633 : :
1634 : : /* check that different equivance classes are assigned only
1635 : : to types that are not compatible. */
1636 : 14518402 : gcc_checking_assert (ret || !comptypes (type1, type2));
1637 : :
1638 : 14518402 : return ret;
1639 : : }
1640 : :
1641 : :
1642 : : /* Return true if TYPE1 and TYPE2 are compatible types for assignment
1643 : : or various other operations. If they are compatible but a warning may
1644 : : be needed if you use them together, 'warning_needed' in DATA is set.
1645 : : If one type is an enum and the other a compatible integer type, then
1646 : : this sets 'enum_and_int_p' in DATA to true (it is never set to
1647 : : false). If the types are compatible but different enough not to be
1648 : : permitted in C11 typedef redeclarations, then this sets
1649 : : 'different_types_p' in DATA to true; it is never set to
1650 : : false, but may or may not be set if the types are incompatible.
1651 : : If two functions types are not compatible only because one is
1652 : : an old-style definition that does not have self-promoting arguments,
1653 : : then this can be ignored by setting 'ignore_promoting_args_p'.
1654 : : For 'equiv' we can compute equivalency classes (see above).
1655 : : This differs from comptypes, in that we don't free the seen
1656 : : types. */
1657 : :
1658 : : static bool
1659 : 131722744 : comptypes_internal (const_tree type1, const_tree type2,
1660 : : struct comptypes_data *data)
1661 : : {
1662 : 131995170 : const_tree t1 = type1;
1663 : 131995170 : const_tree t2 = type2;
1664 : :
1665 : : /* Suppress errors caused by previously reported errors. */
1666 : :
1667 : 131995170 : if (t1 == t2 || !t1 || !t2
1668 : 44713733 : || TREE_CODE (t1) == ERROR_MARK || TREE_CODE (t2) == ERROR_MARK)
1669 : : return true;
1670 : :
1671 : : /* Enumerated types are compatible with integer types, but this is
1672 : : not transitive: two enumerated types in the same translation unit
1673 : : are compatible with each other only if they are the same type. */
1674 : :
1675 : 44713730 : if (TREE_CODE (t1) == ENUMERAL_TYPE
1676 : 1012 : && COMPLETE_TYPE_P (t1)
1677 : 44714698 : && TREE_CODE (t2) != ENUMERAL_TYPE)
1678 : : {
1679 : 856 : t1 = ENUM_UNDERLYING_TYPE (t1);
1680 : 856 : if (TREE_CODE (t2) != VOID_TYPE)
1681 : : {
1682 : 852 : data->enum_and_int_p = true;
1683 : 852 : data->different_types_p = true;
1684 : : }
1685 : : }
1686 : 44712874 : else if (TREE_CODE (t2) == ENUMERAL_TYPE
1687 : 4705 : && COMPLETE_TYPE_P (t2)
1688 : 44717573 : && TREE_CODE (t1) != ENUMERAL_TYPE)
1689 : : {
1690 : 4587 : t2 = ENUM_UNDERLYING_TYPE (t2);
1691 : 4587 : if (TREE_CODE (t1) != VOID_TYPE)
1692 : : {
1693 : 3688 : data->enum_and_int_p = true;
1694 : 3688 : data->different_types_p = true;
1695 : : }
1696 : : }
1697 : :
1698 : 44713730 : if (t1 == t2)
1699 : : return true;
1700 : :
1701 : : /* Different classes of types can't be compatible. */
1702 : :
1703 : 44712352 : if (TREE_CODE (t1) != TREE_CODE (t2))
1704 : : return false;
1705 : :
1706 : : /* Qualifiers must match. C99 6.7.3p9 */
1707 : :
1708 : 36774504 : if (TYPE_QUALS (t1) != TYPE_QUALS (t2))
1709 : : return false;
1710 : :
1711 : : /* Allow for two different type nodes which have essentially the same
1712 : : definition. Note that we already checked for equality of the type
1713 : : qualifiers (just above). */
1714 : :
1715 : 36735298 : if (TREE_CODE (t1) != ARRAY_TYPE
1716 : 36735298 : && TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
1717 : : return true;
1718 : :
1719 : 36401396 : int attrval;
1720 : :
1721 : : /* 1 if no need for warning yet, 2 if warning cause has been seen. */
1722 : 36401396 : if (!(attrval = comp_type_attributes (t1, t2)))
1723 : : return false;
1724 : :
1725 : 36401019 : if (2 == attrval)
1726 : 336 : data->warning_needed = true;
1727 : :
1728 : 36401019 : switch (TREE_CODE (t1))
1729 : : {
1730 : 3343097 : case INTEGER_TYPE:
1731 : 3343097 : case FIXED_POINT_TYPE:
1732 : 3343097 : case REAL_TYPE:
1733 : 3343097 : case BITINT_TYPE:
1734 : : /* With these nodes, we can't determine type equivalence by
1735 : : looking at what is stored in the nodes themselves, because
1736 : : two nodes might have different TYPE_MAIN_VARIANTs but still
1737 : : represent the same type. For example, wchar_t and int could
1738 : : have the same properties (TYPE_PRECISION, TYPE_MIN_VALUE,
1739 : : TYPE_MAX_VALUE, etc.), but have different TYPE_MAIN_VARIANTs
1740 : : and are distinct types. On the other hand, int and the
1741 : : following typedef
1742 : :
1743 : : typedef int INT __attribute((may_alias));
1744 : :
1745 : : have identical properties, different TYPE_MAIN_VARIANTs, but
1746 : : represent the same type. The canonical type system keeps
1747 : : track of equivalence in this case, so we fall back on it. */
1748 : 3343097 : return TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2);
1749 : :
1750 : 272426 : case POINTER_TYPE:
1751 : : /* Do not remove mode information. */
1752 : 272426 : if (TYPE_MODE (t1) != TYPE_MODE (t2))
1753 : : return false;
1754 : 272426 : data->pointedto = true;
1755 : 272426 : return comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2), data);
1756 : :
1757 : 8821768 : case FUNCTION_TYPE:
1758 : 8821768 : return function_types_compatible_p (t1, t2, data);
1759 : :
1760 : 153138 : case ARRAY_TYPE:
1761 : 153138 : {
1762 : 153138 : tree d1 = TYPE_DOMAIN (t1);
1763 : 153138 : tree d2 = TYPE_DOMAIN (t2);
1764 : 153138 : bool d1_variable, d2_variable;
1765 : 153138 : bool d1_zero, d2_zero;
1766 : :
1767 : : /* Target types must match incl. qualifiers. */
1768 : 153138 : if (!comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2), data))
1769 : : return false;
1770 : :
1771 : 118249 : if ((d1 == NULL_TREE) != (d2 == NULL_TREE))
1772 : 6262 : data->different_types_p = true;
1773 : : /* Ignore size mismatches when forming equivalence classes. */
1774 : 118249 : if (data->equiv)
1775 : : return true;
1776 : : /* Sizes must match unless one is missing or variable. */
1777 : 49768 : if (d1 == NULL_TREE || d2 == NULL_TREE || d1 == d2)
1778 : : return true;
1779 : :
1780 : 33582 : d1_zero = !TYPE_MAX_VALUE (d1);
1781 : 33582 : d2_zero = !TYPE_MAX_VALUE (d2);
1782 : :
1783 : 67164 : d1_variable = (!d1_zero
1784 : 33582 : && (TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST
1785 : 33576 : || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST));
1786 : 67164 : d2_variable = (!d2_zero
1787 : 33582 : && (TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST
1788 : 33486 : || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST));
1789 : :
1790 : 33582 : if (d1_variable != d2_variable)
1791 : 767 : data->different_types_p = true;
1792 : 33582 : if (d1_variable || d2_variable)
1793 : : return true;
1794 : 4039 : if (d1_zero && d2_zero)
1795 : : return true;
1796 : 4039 : if (d1_zero || d2_zero
1797 : 3943 : || !tree_int_cst_equal (TYPE_MIN_VALUE (d1), TYPE_MIN_VALUE (d2))
1798 : 7982 : || !tree_int_cst_equal (TYPE_MAX_VALUE (d1), TYPE_MAX_VALUE (d2)))
1799 : 4039 : return false;
1800 : :
1801 : : return true;
1802 : : }
1803 : :
1804 : 23274365 : case ENUMERAL_TYPE:
1805 : 23274365 : case RECORD_TYPE:
1806 : 23274365 : case UNION_TYPE:
1807 : :
1808 : 23274365 : if (!flag_isoc23)
1809 : : return false;
1810 : :
1811 : 23274319 : return tagged_types_tu_compatible_p (t1, t2, data);
1812 : :
1813 : 535660 : case VECTOR_TYPE:
1814 : 1071320 : return known_eq (TYPE_VECTOR_SUBPARTS (t1), TYPE_VECTOR_SUBPARTS (t2))
1815 : 535660 : && comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2), data);
1816 : :
1817 : : default:
1818 : : return false;
1819 : : }
1820 : : gcc_unreachable ();
1821 : : }
1822 : :
1823 : : /* Return true if TTL and TTR are pointers to types that are equivalent, ignoring
1824 : : their qualifiers, except for named address spaces. If the pointers point to
1825 : : different named addresses, then we must determine if one address space is a
1826 : : subset of the other. */
1827 : :
1828 : : static bool
1829 : 1759575 : comp_target_types (location_t location, tree ttl, tree ttr)
1830 : : {
1831 : 1759575 : int val;
1832 : 1759575 : int val_ped;
1833 : 1759575 : tree mvl = TREE_TYPE (ttl);
1834 : 1759575 : tree mvr = TREE_TYPE (ttr);
1835 : 1759575 : addr_space_t asl = TYPE_ADDR_SPACE (mvl);
1836 : 1759575 : addr_space_t asr = TYPE_ADDR_SPACE (mvr);
1837 : 1759575 : addr_space_t as_common;
1838 : 1759575 : bool enum_and_int_p;
1839 : :
1840 : : /* Fail if pointers point to incompatible address spaces. */
1841 : 1759575 : if (!addr_space_superset (asl, asr, &as_common))
1842 : : return 0;
1843 : :
1844 : : /* For pedantic record result of comptypes on arrays before losing
1845 : : qualifiers on the element type below. */
1846 : 1759575 : val_ped = 1;
1847 : :
1848 : 1759575 : if (TREE_CODE (mvl) == ARRAY_TYPE
1849 : 1991 : && TREE_CODE (mvr) == ARRAY_TYPE)
1850 : 1963 : val_ped = comptypes (mvl, mvr);
1851 : :
1852 : : /* Qualifiers on element types of array types that are
1853 : : pointer targets are also removed. */
1854 : 1759575 : mvl = remove_qualifiers (mvl);
1855 : 1759575 : mvr = remove_qualifiers (mvr);
1856 : :
1857 : 1759575 : enum_and_int_p = false;
1858 : 1759575 : val = comptypes_check_enum_int (mvl, mvr, &enum_and_int_p);
1859 : :
1860 : 1759575 : if (val == 1 && val_ped != 1)
1861 : 190 : pedwarn_c11 (location, OPT_Wpedantic, "invalid use of pointers to arrays with different qualifiers "
1862 : : "in ISO C before C23");
1863 : :
1864 : 1759575 : if (val == 2)
1865 : 126 : pedwarn (location, OPT_Wpedantic, "types are not quite compatible");
1866 : :
1867 : 1759575 : if (val == 1 && enum_and_int_p && warn_cxx_compat)
1868 : 2 : warning_at (location, OPT_Wc___compat,
1869 : : "pointer target types incompatible in C++");
1870 : :
1871 : 1759575 : return val;
1872 : : }
1873 : :
1874 : : /* Subroutines of `comptypes'. */
1875 : :
1876 : : /* Return true if two 'struct', 'union', or 'enum' types T1 and T2 are
1877 : : compatible. The two types are not the same (which has been
1878 : : checked earlier in comptypes_internal). */
1879 : :
1880 : : static bool
1881 : 23274319 : tagged_types_tu_compatible_p (const_tree t1, const_tree t2,
1882 : : struct comptypes_data *data)
1883 : : {
1884 : 23274319 : tree s1, s2;
1885 : :
1886 : 23274319 : if (c_type_tag (t1) != c_type_tag (t2))
1887 : : return false;
1888 : :
1889 : : /* When forming equivalence classes for TYPE_CANONICAL in C23, we treat
1890 : : structs with the same tag as equivalent, but only when they are targets
1891 : : of pointers inside other structs. */
1892 : 19216169 : if (data->equiv && data->pointedto)
1893 : : return true;
1894 : :
1895 : : /* Different types without tag are incompatible except as an anonymous
1896 : : field or when forming equivalence classes for TYPE_CANONICAL. */
1897 : 19216135 : if (!data->anon_field && !data->equiv && NULL_TREE == c_type_tag (t1))
1898 : : return false;
1899 : :
1900 : 14169043 : if (!data->anon_field && TYPE_STUB_DECL (t1) != TYPE_STUB_DECL (t2))
1901 : 14168042 : data->different_types_p = true;
1902 : :
1903 : : /* Incomplete types are incompatible inside a TU. */
1904 : 14169043 : if (TYPE_SIZE (t1) == NULL || TYPE_SIZE (t2) == NULL)
1905 : : return false;
1906 : :
1907 : 14169033 : if (ENUMERAL_TYPE != TREE_CODE (t1)
1908 : 14169033 : && (TYPE_REVERSE_STORAGE_ORDER (t1)
1909 : 14168978 : != TYPE_REVERSE_STORAGE_ORDER (t2)))
1910 : : return false;
1911 : :
1912 : 14169023 : if (TYPE_USER_ALIGN (t1) != TYPE_USER_ALIGN (t2))
1913 : 142124 : data->different_types_p = true;
1914 : :
1915 : : /* For types already being looked at in some active
1916 : : invocation of this function, assume compatibility.
1917 : : The cache is built as a linked list on the stack
1918 : : with the head of the list passed downwards. */
1919 : 14169023 : for (const struct tagged_tu_seen_cache *t = data->cache;
1920 : 14177894 : t != NULL; t = t->next)
1921 : 8982 : if (t->t1 == t1 && t->t2 == t2)
1922 : : return true;
1923 : :
1924 : 14168912 : const struct tagged_tu_seen_cache entry = { data->cache, t1, t2 };
1925 : :
1926 : 14168912 : switch (TREE_CODE (t1))
1927 : : {
1928 : 55 : case ENUMERAL_TYPE:
1929 : 55 : {
1930 : 55 : if (!comptypes (ENUM_UNDERLYING_TYPE (t1), ENUM_UNDERLYING_TYPE (t2)))
1931 : : return false;
1932 : :
1933 : : /* Speed up the case where the type values are in the same order. */
1934 : 51 : tree tv1 = TYPE_VALUES (t1);
1935 : 51 : tree tv2 = TYPE_VALUES (t2);
1936 : :
1937 : 51 : if (tv1 == tv2)
1938 : : return true;
1939 : :
1940 : 97 : for (;tv1 && tv2; tv1 = TREE_CHAIN (tv1), tv2 = TREE_CHAIN (tv2))
1941 : : {
1942 : 58 : if (TREE_PURPOSE (tv1) != TREE_PURPOSE (tv2))
1943 : : break;
1944 : :
1945 : 51 : if (simple_cst_equal (DECL_INITIAL (TREE_VALUE (tv1)),
1946 : 51 : DECL_INITIAL (TREE_VALUE (tv2))) != 1)
1947 : : break;
1948 : : }
1949 : :
1950 : 51 : if (tv1 == NULL_TREE && tv2 == NULL_TREE)
1951 : : return true;
1952 : :
1953 : 12 : if (tv1 == NULL_TREE || tv2 == NULL_TREE)
1954 : : return false;
1955 : :
1956 : 12 : if (list_length (TYPE_VALUES (t1)) != list_length (TYPE_VALUES (t2)))
1957 : : return false;
1958 : :
1959 : 20 : for (s1 = TYPE_VALUES (t1); s1; s1 = TREE_CHAIN (s1))
1960 : : {
1961 : 16 : s2 = purpose_member (TREE_PURPOSE (s1), TYPE_VALUES (t2));
1962 : :
1963 : 16 : if (s2 == NULL
1964 : 29 : || simple_cst_equal (DECL_INITIAL (TREE_VALUE (s1)),
1965 : 13 : DECL_INITIAL (TREE_VALUE (s2))) != 1)
1966 : 8 : return false;
1967 : : }
1968 : :
1969 : : return true;
1970 : : }
1971 : :
1972 : 14168857 : case UNION_TYPE:
1973 : 14168857 : case RECORD_TYPE:
1974 : :
1975 : 14168857 : if (list_length (TYPE_FIELDS (t1)) != list_length (TYPE_FIELDS (t2)))
1976 : : return false;
1977 : :
1978 : 12294777 : for (s1 = TYPE_FIELDS (t1), s2 = TYPE_FIELDS (t2);
1979 : 13814106 : s1 && s2;
1980 : 1519329 : s1 = DECL_CHAIN (s1), s2 = DECL_CHAIN (s2))
1981 : : {
1982 : 13750116 : gcc_assert (TREE_CODE (s1) == FIELD_DECL);
1983 : 13750116 : gcc_assert (TREE_CODE (s2) == FIELD_DECL);
1984 : :
1985 : 13750116 : tree ft1 = TREE_TYPE (s1);
1986 : 13750116 : tree ft2 = TREE_TYPE (s2);
1987 : :
1988 : 13750116 : if (DECL_NAME (s1) != DECL_NAME (s2))
1989 : : return false;
1990 : :
1991 : 12118553 : if (DECL_ALIGN (s1) != DECL_ALIGN (s2))
1992 : : return false;
1993 : :
1994 : 3219032 : if (DECL_C_BIT_FIELD (s1) != DECL_C_BIT_FIELD (s2))
1995 : : return false;
1996 : :
1997 : 3219012 : if (DECL_C_BIT_FIELD (s1))
1998 : : {
1999 : 496 : if (!tree_int_cst_equal (DECL_SIZE (s1), DECL_SIZE (s2)))
2000 : : return false;
2001 : :
2002 : 342 : ft1 = DECL_BIT_FIELD_TYPE (s1);
2003 : 342 : ft2 = DECL_BIT_FIELD_TYPE (s2);
2004 : : }
2005 : :
2006 : 3218858 : if (!ft1 || !ft2)
2007 : : return false;
2008 : :
2009 : 3218858 : if (TREE_CODE (ft1) == ERROR_MARK || TREE_CODE (ft2) == ERROR_MARK)
2010 : : return false;
2011 : :
2012 : 3218857 : data->anon_field = !DECL_NAME (s1);
2013 : 3218857 : data->pointedto = false;
2014 : :
2015 : 3218857 : const struct tagged_tu_seen_cache *cache = data->cache;
2016 : 3218857 : data->cache = &entry;
2017 : 3218857 : bool ret = comptypes_internal (ft1, ft2, data);
2018 : 3218857 : data->cache = cache;
2019 : 3218857 : if (!ret)
2020 : : return false;
2021 : :
2022 : 1587760 : tree st1 = TYPE_SIZE (TREE_TYPE (s1));
2023 : 1587760 : tree st2 = TYPE_SIZE (TREE_TYPE (s2));
2024 : :
2025 : 1587760 : if (data->equiv
2026 : 994577 : && st1 && TREE_CODE (st1) == INTEGER_CST
2027 : 994541 : && st2 && TREE_CODE (st2) == INTEGER_CST
2028 : 2582298 : && !tree_int_cst_equal (st1, st2))
2029 : : return false;
2030 : :
2031 : 1519363 : tree counted_by1 = lookup_attribute ("counted_by",
2032 : 1519363 : DECL_ATTRIBUTES (s1));
2033 : 1519363 : tree counted_by2 = lookup_attribute ("counted_by",
2034 : 1519363 : DECL_ATTRIBUTES (s2));
2035 : : /* If there is no counted_by attribute for both fields. */
2036 : 1519363 : if (!counted_by1 && !counted_by2)
2037 : 1519309 : continue;
2038 : :
2039 : : /* If only one field has counted_by attribute. */
2040 : 54 : if ((counted_by1 && !counted_by2)
2041 : 54 : || (!counted_by1 && counted_by2))
2042 : : return false;
2043 : :
2044 : : /* Now both s1 and s2 have counted_by attributes, check
2045 : : whether they are the same. */
2046 : :
2047 : 42 : tree counted_by_field1
2048 : 42 : = lookup_field (t1, TREE_VALUE (TREE_VALUE (counted_by1)));
2049 : 42 : tree counted_by_field2
2050 : 42 : = lookup_field (t2, TREE_VALUE (TREE_VALUE (counted_by2)));
2051 : :
2052 : 42 : gcc_assert (counted_by_field1 && counted_by_field2);
2053 : :
2054 : 84 : while (TREE_CHAIN (counted_by_field1))
2055 : 42 : counted_by_field1 = TREE_CHAIN (counted_by_field1);
2056 : 76 : while (TREE_CHAIN (counted_by_field2))
2057 : 34 : counted_by_field2 = TREE_CHAIN (counted_by_field2);
2058 : :
2059 : 42 : if (DECL_NAME (TREE_VALUE (counted_by_field1))
2060 : 42 : != DECL_NAME (TREE_VALUE (counted_by_field2)))
2061 : : return false;
2062 : : }
2063 : : return true;
2064 : :
2065 : 0 : default:
2066 : 0 : gcc_unreachable ();
2067 : : }
2068 : : }
2069 : :
2070 : : /* Return true if two function types F1 and F2 are compatible.
2071 : : If either type specifies no argument types,
2072 : : the other must specify a fixed number of self-promoting arg types.
2073 : : Otherwise, if one type specifies only the number of arguments,
2074 : : the other must specify that number of self-promoting arg types.
2075 : : Otherwise, the argument types must match. */
2076 : :
2077 : : static bool
2078 : 8821768 : function_types_compatible_p (const_tree f1, const_tree f2,
2079 : : struct comptypes_data *data)
2080 : : {
2081 : 8821768 : tree ret1 = TREE_TYPE (f1);
2082 : 8821768 : tree ret2 = TREE_TYPE (f2);
2083 : :
2084 : : /* 'volatile' qualifiers on a function's return type used to mean
2085 : : the function is noreturn. */
2086 : 8821768 : if (TYPE_VOLATILE (ret1) != TYPE_VOLATILE (ret2))
2087 : 29 : pedwarn (input_location, 0, "function return types not compatible due to %<volatile%>");
2088 : 8821768 : if (TYPE_VOLATILE (ret1))
2089 : 15 : ret1 = build_qualified_type (TYPE_MAIN_VARIANT (ret1),
2090 : 15 : TYPE_QUALS (ret1) & ~TYPE_QUAL_VOLATILE);
2091 : 8821768 : if (TYPE_VOLATILE (ret2))
2092 : 18 : ret2 = build_qualified_type (TYPE_MAIN_VARIANT (ret2),
2093 : 18 : TYPE_QUALS (ret2) & ~TYPE_QUAL_VOLATILE);
2094 : :
2095 : 8821768 : bool ignore_pargs = data->ignore_promoting_args;
2096 : 8821768 : data->ignore_promoting_args = false;
2097 : :
2098 : 8821768 : if (!comptypes_internal (ret1, ret2, data))
2099 : : return false;
2100 : :
2101 : 8819181 : data->ignore_promoting_args = ignore_pargs;
2102 : :
2103 : 8819181 : tree args1 = TYPE_ARG_TYPES (f1);
2104 : 8819181 : tree args2 = TYPE_ARG_TYPES (f2);
2105 : :
2106 : 8819181 : if ((args1 == NULL_TREE) != (args2 == NULL_TREE))
2107 : 41172 : data->different_types_p = true;
2108 : :
2109 : : /* An unspecified parmlist matches any specified parmlist
2110 : : whose argument types don't need default promotions. */
2111 : :
2112 : 8819181 : if (args1 == NULL_TREE)
2113 : : {
2114 : 21728 : if (TYPE_NO_NAMED_ARGS_STDARG_P (f1) != TYPE_NO_NAMED_ARGS_STDARG_P (f2))
2115 : : return false;
2116 : 21726 : if (!(data->ignore_promoting_args || self_promoting_args_p (args2)))
2117 : : return false;
2118 : 21254 : data->ignore_promoting_args = false;
2119 : : /* If one of these types comes from a non-prototype fn definition,
2120 : : compare that with the other type's arglist.
2121 : : If they don't match, ask for a warning (but no error). */
2122 : 21254 : if (TYPE_ACTUAL_ARG_TYPES (f1)
2123 : 21254 : && !type_lists_compatible_p (args2, TYPE_ACTUAL_ARG_TYPES (f1), data))
2124 : 12 : data->warning_needed = true;
2125 : 21254 : return true;
2126 : : }
2127 : 8797453 : if (args2 == NULL_TREE)
2128 : : {
2129 : 19525 : if (TYPE_NO_NAMED_ARGS_STDARG_P (f1) != TYPE_NO_NAMED_ARGS_STDARG_P (f2))
2130 : : return false;
2131 : 19523 : if (!(data->ignore_promoting_args || self_promoting_args_p (args1)))
2132 : : return false;
2133 : 19462 : data->ignore_promoting_args = false;
2134 : 19462 : if (TYPE_ACTUAL_ARG_TYPES (f2)
2135 : 19462 : && !type_lists_compatible_p (args1, TYPE_ACTUAL_ARG_TYPES (f2), data))
2136 : 1 : data->warning_needed = true;
2137 : 19462 : return true;
2138 : : }
2139 : :
2140 : : /* Both types have argument lists: compare them and propagate results. */
2141 : 8777928 : return type_lists_compatible_p (args1, args2, data);
2142 : : }
2143 : :
2144 : : /* Check two lists of types for compatibility, returning false for
2145 : : incompatible, true for compatible. */
2146 : :
2147 : : static bool
2148 : 8778004 : type_lists_compatible_p (const_tree args1, const_tree args2,
2149 : : struct comptypes_data *data)
2150 : : {
2151 : 54694258 : while (1)
2152 : : {
2153 : 31736131 : if (args1 == NULL_TREE && args2 == NULL_TREE)
2154 : : return true;
2155 : : /* If one list is shorter than the other,
2156 : : they fail to match. */
2157 : 23102003 : if (args1 == NULL_TREE || args2 == NULL_TREE)
2158 : : return false;
2159 : 23101996 : tree a1 = TREE_VALUE (args1);
2160 : 23101996 : tree a2 = TREE_VALUE (args2);
2161 : 23101996 : tree mv1 = remove_qualifiers (a1);
2162 : 23101996 : tree mv2 = remove_qualifiers (a2);
2163 : : /* A null pointer instead of a type
2164 : : means there is supposed to be an argument
2165 : : but nothing is specified about what type it has.
2166 : : So match anything that self-promotes. */
2167 : 23101996 : if ((a1 == NULL_TREE) != (a2 == NULL_TREE))
2168 : 0 : data->different_types_p = true;
2169 : 23101996 : if (a1 == NULL_TREE)
2170 : : {
2171 : 0 : if (c_type_promotes_to (a2) != a2)
2172 : : return false;
2173 : : }
2174 : 23101996 : else if (a2 == NULL_TREE)
2175 : : {
2176 : 0 : if (c_type_promotes_to (a1) != a1)
2177 : : return false;
2178 : : }
2179 : : /* If one of the lists has an error marker, ignore this arg. */
2180 : 23101996 : else if (TREE_CODE (a1) == ERROR_MARK
2181 : 23101992 : || TREE_CODE (a2) == ERROR_MARK)
2182 : : ;
2183 : 23101976 : else if (!comptypes_internal (mv1, mv2, data))
2184 : : {
2185 : 144086 : data->different_types_p = true;
2186 : : /* Allow wait (union {union wait *u; int *i} *)
2187 : : and wait (union wait *) to be compatible. */
2188 : 144086 : if (TREE_CODE (a1) == UNION_TYPE
2189 : 122 : && (TYPE_NAME (a1) == NULL_TREE
2190 : 94 : || TYPE_TRANSPARENT_AGGR (a1))
2191 : 122 : && TREE_CODE (TYPE_SIZE (a1)) == INTEGER_CST
2192 : 144208 : && tree_int_cst_equal (TYPE_SIZE (a1),
2193 : 122 : TYPE_SIZE (a2)))
2194 : : {
2195 : 122 : tree memb;
2196 : 122 : for (memb = TYPE_FIELDS (a1);
2197 : 158 : memb; memb = DECL_CHAIN (memb))
2198 : : {
2199 : 156 : tree mv3 = remove_qualifiers (TREE_TYPE (memb));
2200 : 156 : if (comptypes_internal (mv3, mv2, data))
2201 : : break;
2202 : : }
2203 : : if (memb == NULL_TREE)
2204 : : return false;
2205 : : }
2206 : 143964 : else if (TREE_CODE (a2) == UNION_TYPE
2207 : 99 : && (TYPE_NAME (a2) == NULL_TREE
2208 : 71 : || TYPE_TRANSPARENT_AGGR (a2))
2209 : 99 : && TREE_CODE (TYPE_SIZE (a2)) == INTEGER_CST
2210 : 144063 : && tree_int_cst_equal (TYPE_SIZE (a2),
2211 : 99 : TYPE_SIZE (a1)))
2212 : : {
2213 : 99 : tree memb;
2214 : 99 : for (memb = TYPE_FIELDS (a2);
2215 : 127 : memb; memb = DECL_CHAIN (memb))
2216 : : {
2217 : 125 : tree mv3 = remove_qualifiers (TREE_TYPE (memb));
2218 : 125 : if (comptypes_internal (mv3, mv1, data))
2219 : : break;
2220 : : }
2221 : : if (memb == NULL_TREE)
2222 : : return false;
2223 : : }
2224 : : else
2225 : 143865 : return false;
2226 : : }
2227 : :
2228 : 22958127 : args1 = TREE_CHAIN (args1);
2229 : 22958127 : args2 = TREE_CHAIN (args2);
2230 : 22958127 : }
2231 : : }
2232 : :
2233 : : /* Compute the size to increment a pointer by. When a function type or void
2234 : : type or incomplete type is passed, size_one_node is returned.
2235 : : This function does not emit any diagnostics; the caller is responsible
2236 : : for that. */
2237 : :
2238 : : static tree
2239 : 233165 : c_size_in_bytes (const_tree type)
2240 : : {
2241 : 233165 : enum tree_code code = TREE_CODE (type);
2242 : :
2243 : 233165 : if (code == FUNCTION_TYPE || code == VOID_TYPE || code == ERROR_MARK
2244 : 233165 : || !COMPLETE_TYPE_P (type))
2245 : 180 : return size_one_node;
2246 : :
2247 : : /* Convert in case a char is more than one unit. */
2248 : 232985 : return size_binop_loc (input_location, CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
2249 : 232985 : size_int (TYPE_PRECISION (char_type_node)
2250 : : / BITS_PER_UNIT));
2251 : : }
2252 : :
2253 : : /* Return either DECL or its known constant value (if it has one). */
2254 : :
2255 : : tree
2256 : 14275079 : decl_constant_value_1 (tree decl, bool in_init)
2257 : : {
2258 : 14275079 : if (/* Note that DECL_INITIAL isn't valid for a PARM_DECL. */
2259 : 14275079 : TREE_CODE (decl) != PARM_DECL
2260 : 14275079 : && !TREE_THIS_VOLATILE (decl)
2261 : 13931347 : && TREE_READONLY (decl)
2262 : 36694 : && DECL_INITIAL (decl) != NULL_TREE
2263 : 35699 : && !error_operand_p (DECL_INITIAL (decl))
2264 : : /* This is invalid if initial value is not constant.
2265 : : If it has either a function call, a memory reference,
2266 : : or a variable, then re-evaluating it could give different results. */
2267 : 35690 : && TREE_CONSTANT (DECL_INITIAL (decl))
2268 : : /* Check for cases where this is sub-optimal, even though valid. */
2269 : 14297883 : && (in_init || TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR))
2270 : 17599 : return DECL_INITIAL (decl);
2271 : : return decl;
2272 : : }
2273 : :
2274 : : /* Return either DECL or its known constant value (if it has one).
2275 : : Like the above, but always return decl outside of functions. */
2276 : :
2277 : : tree
2278 : 14274835 : decl_constant_value (tree decl)
2279 : : {
2280 : : /* Don't change a variable array bound or initial value to a constant
2281 : : in a place where a variable is invalid. */
2282 : 14274835 : return current_function_decl ? decl_constant_value_1 (decl, false) : decl;
2283 : : }
2284 : :
2285 : : /* Convert the array expression EXP to a pointer. */
2286 : : static tree
2287 : 820073 : array_to_pointer_conversion (location_t loc, tree exp)
2288 : : {
2289 : 820073 : tree orig_exp = exp;
2290 : 820073 : tree type = TREE_TYPE (exp);
2291 : 820073 : tree adr;
2292 : 820073 : tree restype = TREE_TYPE (type);
2293 : 820073 : tree ptrtype;
2294 : :
2295 : 820073 : gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
2296 : :
2297 : 820073 : STRIP_TYPE_NOPS (exp);
2298 : :
2299 : 820073 : copy_warning (exp, orig_exp);
2300 : :
2301 : 820073 : ptrtype = c_build_pointer_type (restype);
2302 : :
2303 : 820073 : if (INDIRECT_REF_P (exp))
2304 : 2883 : return convert (ptrtype, TREE_OPERAND (exp, 0));
2305 : :
2306 : : /* In C++ array compound literals are temporary objects unless they are
2307 : : const or appear in namespace scope, so they are destroyed too soon
2308 : : to use them for much of anything (c++/53220). */
2309 : 817190 : if (warn_cxx_compat && TREE_CODE (exp) == COMPOUND_LITERAL_EXPR)
2310 : : {
2311 : 48 : tree decl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
2312 : 48 : if (!TREE_READONLY (decl) && !TREE_STATIC (decl))
2313 : 46 : warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat,
2314 : : "converting an array compound literal to a pointer "
2315 : : "leads to a dangling pointer in C++");
2316 : : }
2317 : :
2318 : 817190 : adr = build_unary_op (loc, ADDR_EXPR, exp, true);
2319 : 817190 : return convert (ptrtype, adr);
2320 : : }
2321 : :
2322 : : /* Convert the function expression EXP to a pointer. */
2323 : : static tree
2324 : 50324263 : function_to_pointer_conversion (location_t loc, tree exp)
2325 : : {
2326 : 50324263 : tree orig_exp = exp;
2327 : :
2328 : 50324263 : gcc_assert (TREE_CODE (TREE_TYPE (exp)) == FUNCTION_TYPE);
2329 : :
2330 : 50324263 : STRIP_TYPE_NOPS (exp);
2331 : :
2332 : 50324263 : copy_warning (exp, orig_exp);
2333 : :
2334 : 50324263 : tree exp2 = build_unary_op (loc, ADDR_EXPR, exp, false);
2335 : :
2336 : : /* If the function is defined and known to not to require a non-local
2337 : : context, make sure no trampoline is generated. */
2338 : 50324263 : if (TREE_CODE (exp) == FUNCTION_DECL
2339 : 50324263 : && DECL_INITIAL (exp) && !C_FUNC_NONLOCAL_CONTEXT (exp))
2340 : 15981347 : TREE_NO_TRAMPOLINE (exp2) = 1;
2341 : :
2342 : 50324263 : return exp2;
2343 : : }
2344 : :
2345 : : /* Mark EXP as read, not just set, for set but not used -Wunused
2346 : : warning purposes. */
2347 : :
2348 : : void
2349 : 488242193 : mark_exp_read (tree exp)
2350 : : {
2351 : 613901318 : switch (TREE_CODE (exp))
2352 : : {
2353 : 202548045 : case VAR_DECL:
2354 : 202548045 : case PARM_DECL:
2355 : 202548045 : DECL_READ_P (exp) = 1;
2356 : 202548045 : break;
2357 : 19618944 : CASE_CONVERT:
2358 : 19618944 : if (VOID_TYPE_P (TREE_TYPE (exp)))
2359 : 3793 : switch (TREE_CODE (TREE_OPERAND (exp, 0)))
2360 : : {
2361 : : case PREINCREMENT_EXPR:
2362 : : case PREDECREMENT_EXPR:
2363 : : case POSTINCREMENT_EXPR:
2364 : : case POSTDECREMENT_EXPR:
2365 : : return;
2366 : : default:
2367 : : break;
2368 : : }
2369 : : /* FALLTHRU */
2370 : 122923324 : case ARRAY_REF:
2371 : 122923324 : case COMPONENT_REF:
2372 : 122923324 : case MODIFY_EXPR:
2373 : 122923324 : case REALPART_EXPR:
2374 : 122923324 : case IMAGPART_EXPR:
2375 : 122923324 : case ADDR_EXPR:
2376 : 122923324 : case VIEW_CONVERT_EXPR:
2377 : 122923324 : case PREINCREMENT_EXPR:
2378 : 122923324 : case PREDECREMENT_EXPR:
2379 : 122923324 : case POSTINCREMENT_EXPR:
2380 : 122923324 : case POSTDECREMENT_EXPR:
2381 : 122923324 : mark_exp_read (TREE_OPERAND (exp, 0));
2382 : 122923324 : break;
2383 : 236019 : case COMPOUND_EXPR:
2384 : : /* Pattern match what build_atomic_assign produces with modifycode
2385 : : NOP_EXPR. */
2386 : 236019 : if (VAR_P (TREE_OPERAND (exp, 1))
2387 : 27227 : && DECL_ARTIFICIAL (TREE_OPERAND (exp, 1))
2388 : 263162 : && TREE_CODE (TREE_OPERAND (exp, 0)) == COMPOUND_EXPR)
2389 : : {
2390 : 2210 : tree t1 = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
2391 : 2210 : tree t2 = TREE_OPERAND (TREE_OPERAND (exp, 0), 1);
2392 : 2210 : if (TREE_CODE (t1) == TARGET_EXPR
2393 : 2202 : && TARGET_EXPR_SLOT (t1) == TREE_OPERAND (exp, 1)
2394 : 4410 : && TREE_CODE (t2) == CALL_EXPR)
2395 : : {
2396 : 2200 : tree fndecl = get_callee_fndecl (t2);
2397 : 2200 : tree arg = NULL_TREE;
2398 : 2200 : if (fndecl
2399 : 2200 : && TREE_CODE (fndecl) == FUNCTION_DECL
2400 : 2200 : && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL)
2401 : 4400 : && call_expr_nargs (t2) >= 2)
2402 : 2200 : switch (DECL_FUNCTION_CODE (fndecl))
2403 : : {
2404 : 130 : case BUILT_IN_ATOMIC_STORE:
2405 : 130 : arg = CALL_EXPR_ARG (t2, 1);
2406 : 130 : break;
2407 : 2070 : case BUILT_IN_ATOMIC_STORE_1:
2408 : 2070 : case BUILT_IN_ATOMIC_STORE_2:
2409 : 2070 : case BUILT_IN_ATOMIC_STORE_4:
2410 : 2070 : case BUILT_IN_ATOMIC_STORE_8:
2411 : 2070 : case BUILT_IN_ATOMIC_STORE_16:
2412 : 2070 : arg = CALL_EXPR_ARG (t2, 0);
2413 : 2070 : break;
2414 : : default:
2415 : : break;
2416 : : }
2417 : 2200 : if (arg)
2418 : : {
2419 : 2200 : STRIP_NOPS (arg);
2420 : 2200 : if (TREE_CODE (arg) == ADDR_EXPR
2421 : 2200 : && DECL_P (TREE_OPERAND (arg, 0))
2422 : 4400 : && TYPE_ATOMIC (TREE_TYPE (TREE_OPERAND (arg, 0))))
2423 : 2200 : mark_exp_read (TREE_OPERAND (arg, 0));
2424 : : }
2425 : : }
2426 : : }
2427 : : /* FALLTHRU */
2428 : 2735264 : case C_MAYBE_CONST_EXPR:
2429 : 2735264 : mark_exp_read (TREE_OPERAND (exp, 1));
2430 : 2735264 : break;
2431 : 572 : case OMP_ARRAY_SECTION:
2432 : 572 : mark_exp_read (TREE_OPERAND (exp, 0));
2433 : 572 : if (TREE_OPERAND (exp, 1))
2434 : 378 : mark_exp_read (TREE_OPERAND (exp, 1));
2435 : 572 : if (TREE_OPERAND (exp, 2))
2436 : 537 : mark_exp_read (TREE_OPERAND (exp, 2));
2437 : : break;
2438 : : default:
2439 : : break;
2440 : : }
2441 : : }
2442 : :
2443 : : /* Perform the default conversion of arrays and functions to pointers.
2444 : : Return the result of converting EXP. For any other expression, just
2445 : : return EXP.
2446 : :
2447 : : LOC is the location of the expression. */
2448 : :
2449 : : struct c_expr
2450 : 360224906 : default_function_array_conversion (location_t loc, struct c_expr exp)
2451 : : {
2452 : 360224906 : tree orig_exp = exp.value;
2453 : 360224906 : tree type = TREE_TYPE (exp.value);
2454 : 360224906 : enum tree_code code = TREE_CODE (type);
2455 : :
2456 : 360224906 : switch (code)
2457 : : {
2458 : : case ARRAY_TYPE:
2459 : : {
2460 : : bool not_lvalue = false;
2461 : : bool lvalue_array_p;
2462 : :
2463 : 773253 : while ((TREE_CODE (exp.value) == NON_LVALUE_EXPR
2464 : 773253 : || CONVERT_EXPR_P (exp.value))
2465 : 773253 : && TREE_TYPE (TREE_OPERAND (exp.value, 0)) == type)
2466 : : {
2467 : 0 : if (TREE_CODE (exp.value) == NON_LVALUE_EXPR)
2468 : 0 : not_lvalue = true;
2469 : 0 : exp.value = TREE_OPERAND (exp.value, 0);
2470 : : }
2471 : :
2472 : 773253 : copy_warning (exp.value, orig_exp);
2473 : :
2474 : 773253 : lvalue_array_p = !not_lvalue && lvalue_p (exp.value);
2475 : 773253 : if (!flag_isoc99 && !lvalue_array_p)
2476 : : {
2477 : : /* Before C99, non-lvalue arrays do not decay to pointers.
2478 : : Normally, using such an array would be invalid; but it can
2479 : : be used correctly inside sizeof or as a statement expression.
2480 : : Thus, do not give an error here; an error will result later. */
2481 : 109 : return exp;
2482 : : }
2483 : :
2484 : 773144 : exp.value = array_to_pointer_conversion (loc, exp.value);
2485 : : }
2486 : 773144 : break;
2487 : 761836 : case FUNCTION_TYPE:
2488 : 761836 : exp.value = function_to_pointer_conversion (loc, exp.value);
2489 : 761836 : break;
2490 : : default:
2491 : : break;
2492 : : }
2493 : :
2494 : 360224797 : return exp;
2495 : : }
2496 : :
2497 : : struct c_expr
2498 : 944021 : default_function_array_read_conversion (location_t loc, struct c_expr exp)
2499 : : {
2500 : 944021 : mark_exp_read (exp.value);
2501 : : /* We only generate a call to .ACCESS_WITH_SIZE when it is a read. */
2502 : 944021 : if (TREE_CODE (exp.value) == COMPONENT_REF
2503 : 944021 : && handle_counted_by_p (exp.value))
2504 : 66208 : exp.value = handle_counted_by_for_component_ref (loc, exp.value);
2505 : 944021 : return default_function_array_conversion (loc, exp);
2506 : : }
2507 : :
2508 : : /* Return whether EXPR should be treated as an atomic lvalue for the
2509 : : purposes of load and store handling. */
2510 : :
2511 : : static bool
2512 : 361309904 : really_atomic_lvalue (tree expr)
2513 : : {
2514 : 361309904 : if (error_operand_p (expr))
2515 : : return false;
2516 : 361302231 : if (!TYPE_ATOMIC (TREE_TYPE (expr)))
2517 : : return false;
2518 : 57308 : if (!COMPLETE_TYPE_P (TREE_TYPE (expr)))
2519 : : return false;
2520 : 57305 : if (!lvalue_p (expr))
2521 : : return false;
2522 : :
2523 : : /* Ignore _Atomic on register variables, since their addresses can't
2524 : : be taken so (a) atomicity is irrelevant and (b) the normal atomic
2525 : : sequences wouldn't work. Ignore _Atomic on structures containing
2526 : : bit-fields, since accessing elements of atomic structures or
2527 : : unions is undefined behavior (C11 6.5.2.3#5), but it's unclear if
2528 : : it's undefined at translation time or execution time, and the
2529 : : normal atomic sequences again wouldn't work. */
2530 : 57367 : while (handled_component_p (expr))
2531 : : {
2532 : 64 : if (TREE_CODE (expr) == COMPONENT_REF
2533 : 64 : && DECL_C_BIT_FIELD (TREE_OPERAND (expr, 1)))
2534 : : return false;
2535 : 64 : expr = TREE_OPERAND (expr, 0);
2536 : : }
2537 : 57303 : if (TREE_CODE (expr) == COMPOUND_LITERAL_EXPR)
2538 : 1 : expr = COMPOUND_LITERAL_EXPR_DECL (expr);
2539 : 112486 : if (DECL_P (expr) && C_DECL_REGISTER (expr))
2540 : : return false;
2541 : : return true;
2542 : : }
2543 : :
2544 : : /* If EXPR is a named constant (C23) derived from a constexpr variable
2545 : : - that is, a reference to such a variable, or a member extracted by
2546 : : a sequence of structure and union (but not array) member accesses
2547 : : (where union member accesses must access the same member as
2548 : : initialized) - then return the corresponding initializer;
2549 : : otherwise, return NULL_TREE. */
2550 : :
2551 : : static tree
2552 : 358134458 : maybe_get_constexpr_init (tree expr)
2553 : : {
2554 : 358134458 : tree decl = NULL_TREE;
2555 : 358134458 : if (TREE_CODE (expr) == VAR_DECL)
2556 : : decl = expr;
2557 : 346470892 : else if (TREE_CODE (expr) == COMPOUND_LITERAL_EXPR)
2558 : 818919 : decl = COMPOUND_LITERAL_EXPR_DECL (expr);
2559 : 818919 : if (decl
2560 : 12482485 : && C_DECL_DECLARED_CONSTEXPR (decl)
2561 : 356 : && DECL_INITIAL (decl) != NULL_TREE
2562 : 819275 : && !error_operand_p (DECL_INITIAL (decl)))
2563 : 356 : return DECL_INITIAL (decl);
2564 : 358134102 : if (TREE_CODE (expr) != COMPONENT_REF)
2565 : : return NULL_TREE;
2566 : 867427 : tree inner = maybe_get_constexpr_init (TREE_OPERAND (expr, 0));
2567 : 867427 : if (inner == NULL_TREE)
2568 : : return NULL_TREE;
2569 : 126 : while ((CONVERT_EXPR_P (inner) || TREE_CODE (inner) == NON_LVALUE_EXPR)
2570 : 47 : && !error_operand_p (inner)
2571 : 220 : && (TYPE_MAIN_VARIANT (TREE_TYPE (inner))
2572 : 47 : == TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (inner, 0)))))
2573 : 47 : inner = TREE_OPERAND (inner, 0);
2574 : 126 : if (TREE_CODE (inner) != CONSTRUCTOR)
2575 : : return NULL_TREE;
2576 : 126 : tree field = TREE_OPERAND (expr, 1);
2577 : 126 : unsigned HOST_WIDE_INT cidx;
2578 : 126 : tree cfield, cvalue;
2579 : 126 : bool have_other_init = false;
2580 : 266 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (inner), cidx, cfield, cvalue)
2581 : : {
2582 : 250 : if (cfield == field)
2583 : : return cvalue;
2584 : 140 : have_other_init = true;
2585 : : }
2586 : 16 : if (TREE_CODE (TREE_TYPE (inner)) == UNION_TYPE
2587 : 16 : && (have_other_init || field != TYPE_FIELDS (TREE_TYPE (inner))))
2588 : : return NULL_TREE;
2589 : : /* Return a default initializer. */
2590 : 13 : if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (expr)))
2591 : 5 : return build_constructor (TREE_TYPE (expr), NULL);
2592 : 8 : return build_zero_cst (TREE_TYPE (expr));
2593 : : }
2594 : :
2595 : : /* Convert expression EXP (location LOC) from lvalue to rvalue,
2596 : : including converting functions and arrays to pointers if CONVERT_P.
2597 : : If READ_P, also mark the expression as having been read. If
2598 : : FOR_INIT, constexpr expressions of structure and union type should
2599 : : be replaced by the corresponding CONSTRUCTOR; otherwise, only
2600 : : constexpr scalars (including elements of structures and unions) are
2601 : : replaced by their initializers. */
2602 : :
2603 : : struct c_expr
2604 : 357454181 : convert_lvalue_to_rvalue (location_t loc, struct c_expr exp,
2605 : : bool convert_p, bool read_p, bool for_init)
2606 : : {
2607 : 357454181 : bool force_non_npc = false;
2608 : 357454181 : if (read_p)
2609 : 313648461 : mark_exp_read (exp.value);
2610 : : /* We only generate a call to .ACCESS_WITH_SIZE when it is a read. */
2611 : 313648461 : if (read_p && TREE_CODE (exp.value) == COMPONENT_REF
2612 : 777832 : && handle_counted_by_p (exp.value))
2613 : 777803 : exp.value = handle_counted_by_for_component_ref (loc, exp.value);
2614 : :
2615 : 357454181 : if (convert_p)
2616 : 357441025 : exp = default_function_array_conversion (loc, exp);
2617 : 357454181 : if (!VOID_TYPE_P (TREE_TYPE (exp.value))
2618 : 357454181 : || (flag_isoc2y
2619 : 1346 : && TYPE_QUALS (TREE_TYPE (exp.value)) != TYPE_UNQUALIFIED))
2620 : 354982260 : exp.value = require_complete_type (loc, exp.value);
2621 : 357454181 : if (for_init || !RECORD_OR_UNION_TYPE_P (TREE_TYPE (exp.value)))
2622 : : {
2623 : 357267031 : tree init = maybe_get_constexpr_init (exp.value);
2624 : 357267031 : if (init != NULL_TREE)
2625 : : {
2626 : : /* A named constant of pointer type or type nullptr_t is not
2627 : : a null pointer constant even if the initializer is
2628 : : one. */
2629 : 353 : if (TREE_CODE (init) == INTEGER_CST
2630 : 218 : && !INTEGRAL_TYPE_P (TREE_TYPE (init))
2631 : 379 : && integer_zerop (init))
2632 : : force_non_npc = true;
2633 : : exp.value = init;
2634 : : }
2635 : : }
2636 : 357454181 : if (really_atomic_lvalue (exp.value))
2637 : : {
2638 : 26861 : vec<tree, va_gc> *params;
2639 : 26861 : tree nonatomic_type, tmp, tmp_addr, fndecl, func_call;
2640 : 26861 : tree expr_type = TREE_TYPE (exp.value);
2641 : 26861 : tree expr_addr = build_unary_op (loc, ADDR_EXPR, exp.value, false);
2642 : 26861 : tree seq_cst = build_int_cst (integer_type_node, MEMMODEL_SEQ_CST);
2643 : :
2644 : 26861 : gcc_assert (TYPE_ATOMIC (expr_type));
2645 : :
2646 : : /* Expansion of a generic atomic load may require an addition
2647 : : element, so allocate enough to prevent a resize. */
2648 : 26861 : vec_alloc (params, 4);
2649 : :
2650 : : /* Remove the qualifiers for the rest of the expressions and
2651 : : create the VAL temp variable to hold the RHS. */
2652 : 26861 : nonatomic_type = build_qualified_type (expr_type, TYPE_UNQUALIFIED);
2653 : 26861 : tmp = create_tmp_var_raw (nonatomic_type);
2654 : 26861 : tmp_addr = build_unary_op (loc, ADDR_EXPR, tmp, false);
2655 : 26861 : TREE_ADDRESSABLE (tmp) = 1;
2656 : : /* Do not disable warnings for TMP even though it's artificial.
2657 : : -Winvalid-memory-model depends on it. */
2658 : :
2659 : : /* Issue __atomic_load (&expr, &tmp, SEQ_CST); */
2660 : 26861 : fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_LOAD);
2661 : 26861 : params->quick_push (expr_addr);
2662 : 26861 : params->quick_push (tmp_addr);
2663 : 26861 : params->quick_push (seq_cst);
2664 : 26861 : func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
2665 : :
2666 : : /* EXPR is always read. */
2667 : 26861 : mark_exp_read (exp.value);
2668 : :
2669 : : /* Return tmp which contains the value loaded. */
2670 : 26861 : exp.value = build4 (TARGET_EXPR, nonatomic_type, tmp, func_call,
2671 : : NULL_TREE, NULL_TREE);
2672 : : }
2673 : 357441025 : if (convert_p && !error_operand_p (exp.value)
2674 : 714887577 : && (TREE_CODE (TREE_TYPE (exp.value)) != ARRAY_TYPE))
2675 : 357433287 : exp.value = convert (build_qualified_type (TREE_TYPE (exp.value), TYPE_UNQUALIFIED), exp.value);
2676 : 357454181 : if (force_non_npc)
2677 : 24 : exp.value = build1 (NOP_EXPR, TREE_TYPE (exp.value), exp.value);
2678 : :
2679 : 357454181 : {
2680 : 357454181 : tree false_value, true_value;
2681 : 357441025 : if (convert_p && !error_operand_p (exp.value)
2682 : 714887577 : && c_hardbool_type_attr (TREE_TYPE (exp.value),
2683 : : &false_value, &true_value))
2684 : : {
2685 : 9717 : tree t = save_expr (exp.value);
2686 : :
2687 : 9717 : mark_exp_read (exp.value);
2688 : :
2689 : 9717 : tree trapfn = builtin_decl_explicit (BUILT_IN_TRAP);
2690 : 9717 : tree expr = build_call_expr_loc (loc, trapfn, 0);
2691 : 9717 : expr = build_compound_expr (loc, expr, boolean_true_node);
2692 : 9717 : expr = fold_build3_loc (loc, COND_EXPR, boolean_type_node,
2693 : : fold_build2_loc (loc, NE_EXPR,
2694 : : boolean_type_node,
2695 : : t, true_value),
2696 : : expr, boolean_true_node);
2697 : 9717 : expr = fold_build3_loc (loc, COND_EXPR, boolean_type_node,
2698 : : fold_build2_loc (loc, NE_EXPR,
2699 : : boolean_type_node,
2700 : : t, false_value),
2701 : : expr, boolean_false_node);
2702 : :
2703 : 9717 : exp.value = expr;
2704 : : }
2705 : : }
2706 : :
2707 : 357454181 : return exp;
2708 : : }
2709 : :
2710 : : /* Wrapper for the overload above, same arguments but for tree rather than
2711 : : c_expr. This is important for hardbools to decay to bools. */
2712 : :
2713 : : static inline tree
2714 : 572829 : convert_lvalue_to_rvalue (location_t loc, tree val,
2715 : : bool convert_p, bool read_p, bool for_init = false)
2716 : : {
2717 : 572829 : struct c_expr expr;
2718 : 572829 : memset (&expr, 0, sizeof (expr));
2719 : 572829 : expr.value = val;
2720 : 572829 : expr = convert_lvalue_to_rvalue (loc, expr, convert_p, read_p, for_init);
2721 : 572829 : return expr.value;
2722 : : }
2723 : :
2724 : : /* EXP is an expression of integer type. Apply the integer promotions
2725 : : to it and return the promoted value. */
2726 : :
2727 : : tree
2728 : 77331406 : perform_integral_promotions (tree exp)
2729 : : {
2730 : 77331406 : tree type = TREE_TYPE (exp);
2731 : 77331406 : enum tree_code code = TREE_CODE (type);
2732 : :
2733 : 77331406 : gcc_assert (INTEGRAL_TYPE_P (type));
2734 : :
2735 : : /* Convert enums to the result of applying the integer promotions to
2736 : : their underlying type. */
2737 : 77331406 : if (code == ENUMERAL_TYPE)
2738 : : {
2739 : 648415 : type = ENUM_UNDERLYING_TYPE (type);
2740 : 648415 : if (c_promoting_integer_type_p (type))
2741 : : {
2742 : 94 : if (TYPE_UNSIGNED (type)
2743 : 94 : && TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
2744 : 0 : type = unsigned_type_node;
2745 : : else
2746 : 94 : type = integer_type_node;
2747 : : }
2748 : :
2749 : 648415 : return convert (type, exp);
2750 : : }
2751 : :
2752 : : /* ??? This should no longer be needed now bit-fields have their
2753 : : proper types. */
2754 : 76682991 : if (TREE_CODE (exp) == COMPONENT_REF
2755 : 76682991 : && DECL_C_BIT_FIELD (TREE_OPERAND (exp, 1)))
2756 : : {
2757 : 62165 : if (TREE_CODE (DECL_BIT_FIELD_TYPE (TREE_OPERAND (exp, 1)))
2758 : : == BITINT_TYPE)
2759 : 454 : return convert (DECL_BIT_FIELD_TYPE (TREE_OPERAND (exp, 1)), exp);
2760 : : /* If it's thinner than an int, promote it like a
2761 : : c_promoting_integer_type_p, otherwise leave it alone. */
2762 : 61711 : if (compare_tree_int (DECL_SIZE (TREE_OPERAND (exp, 1)),
2763 : 61711 : TYPE_PRECISION (integer_type_node)) < 0)
2764 : 53449 : return convert (integer_type_node, exp);
2765 : : }
2766 : :
2767 : 76629088 : if (c_promoting_integer_type_p (type))
2768 : : {
2769 : : /* Preserve unsignedness if not really getting any wider. */
2770 : 639239 : if (TYPE_UNSIGNED (type)
2771 : 639239 : && TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
2772 : 0 : return convert (unsigned_type_node, exp);
2773 : :
2774 : 639239 : return convert (integer_type_node, exp);
2775 : : }
2776 : :
2777 : : return exp;
2778 : : }
2779 : :
2780 : :
2781 : : /* Perform default promotions for C data used in expressions.
2782 : : Enumeral types or short or char are converted to int.
2783 : : In addition, manifest constants symbols are replaced by their values. */
2784 : :
2785 : : tree
2786 : 86816748 : default_conversion (tree exp)
2787 : : {
2788 : 86816748 : tree orig_exp;
2789 : 86816748 : tree type = TREE_TYPE (exp);
2790 : 86816748 : enum tree_code code = TREE_CODE (type);
2791 : 86816748 : tree promoted_type;
2792 : :
2793 : 86816748 : mark_exp_read (exp);
2794 : : /* We only generate a call to .ACCESS_WITH_SIZE when it is a read. */
2795 : 86816748 : if (TREE_CODE (exp) == COMPONENT_REF
2796 : 86816748 : && handle_counted_by_p (exp))
2797 : 595502 : exp = handle_counted_by_for_component_ref (EXPR_LOCATION (exp), exp);
2798 : :
2799 : : /* Functions and arrays have been converted during parsing. */
2800 : 86816748 : gcc_assert (code != FUNCTION_TYPE);
2801 : 86816748 : if (code == ARRAY_TYPE)
2802 : : return exp;
2803 : :
2804 : : /* Constants can be used directly unless they're not loadable. */
2805 : 86816589 : if (TREE_CODE (exp) == CONST_DECL)
2806 : 0 : exp = DECL_INITIAL (exp);
2807 : :
2808 : : /* Strip no-op conversions. */
2809 : 86816589 : orig_exp = exp;
2810 : 87187548 : STRIP_TYPE_NOPS (exp);
2811 : :
2812 : 86816589 : copy_warning (exp, orig_exp);
2813 : :
2814 : 86816589 : if (code == VOID_TYPE)
2815 : : {
2816 : 2 : error_at (EXPR_LOC_OR_LOC (exp, input_location),
2817 : : "void value not ignored as it ought to be");
2818 : 2 : return error_mark_node;
2819 : : }
2820 : :
2821 : 86816587 : exp = require_complete_type (EXPR_LOC_OR_LOC (exp, input_location), exp);
2822 : 86816587 : if (exp == error_mark_node)
2823 : : return error_mark_node;
2824 : :
2825 : 86815684 : promoted_type = targetm.promoted_type (type);
2826 : 86815684 : if (promoted_type)
2827 : 0 : return convert (promoted_type, exp);
2828 : :
2829 : 86815684 : if (INTEGRAL_TYPE_P (type))
2830 : 76335267 : return perform_integral_promotions (exp);
2831 : :
2832 : : return exp;
2833 : : }
2834 : :
2835 : : /* Look up COMPONENT in a structure or union TYPE.
2836 : :
2837 : : If the component name is not found, returns NULL_TREE. Otherwise,
2838 : : the return value is a TREE_LIST, with each TREE_VALUE a FIELD_DECL
2839 : : stepping down the chain to the component, which is in the last
2840 : : TREE_VALUE of the list. Normally the list is of length one, but if
2841 : : the component is embedded within (nested) anonymous structures or
2842 : : unions, the list steps down the chain to the component. */
2843 : :
2844 : : tree
2845 : 2304872 : lookup_field (const_tree type, tree component)
2846 : : {
2847 : 2304872 : tree field;
2848 : :
2849 : : /* If TYPE_LANG_SPECIFIC is set, then it is a sorted array of pointers
2850 : : to the field elements. Use a binary search on this array to quickly
2851 : : find the element. Otherwise, do a linear search. TYPE_LANG_SPECIFIC
2852 : : will always be set for structures which have many elements.
2853 : :
2854 : : Duplicate field checking replaces duplicates with NULL_TREE so
2855 : : TYPE_LANG_SPECIFIC arrays are potentially no longer sorted. In that
2856 : : case just iterate using DECL_CHAIN. */
2857 : :
2858 : 2603272 : if (TYPE_LANG_SPECIFIC (type) && TYPE_LANG_SPECIFIC (type)->s
2859 : 2603272 : && !seen_error ())
2860 : : {
2861 : 298379 : int bot, top, half;
2862 : 298379 : tree *field_array = &TYPE_LANG_SPECIFIC (type)->s->elts[0];
2863 : :
2864 : 298379 : field = TYPE_FIELDS (type);
2865 : 298379 : bot = 0;
2866 : 298379 : top = TYPE_LANG_SPECIFIC (type)->s->len;
2867 : 1370366 : while (top - bot > 1)
2868 : : {
2869 : 1341975 : half = (top - bot + 1) >> 1;
2870 : 1341975 : field = field_array[bot+half];
2871 : :
2872 : 1341975 : if (DECL_NAME (field) == NULL_TREE)
2873 : : {
2874 : : /* Step through all anon unions in linear fashion. */
2875 : 0 : while (DECL_NAME (field_array[bot]) == NULL_TREE)
2876 : : {
2877 : 0 : field = field_array[bot++];
2878 : 0 : if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (field)))
2879 : : {
2880 : 0 : tree anon = lookup_field (TREE_TYPE (field), component);
2881 : :
2882 : 0 : if (anon)
2883 : 0 : return tree_cons (NULL_TREE, field, anon);
2884 : :
2885 : : /* The Plan 9 compiler permits referring
2886 : : directly to an anonymous struct/union field
2887 : : using a typedef name. */
2888 : 0 : if (flag_plan9_extensions
2889 : 0 : && TYPE_NAME (TREE_TYPE (field)) != NULL_TREE
2890 : 0 : && (TREE_CODE (TYPE_NAME (TREE_TYPE (field)))
2891 : : == TYPE_DECL)
2892 : 0 : && (DECL_NAME (TYPE_NAME (TREE_TYPE (field)))
2893 : : == component))
2894 : : break;
2895 : : }
2896 : : }
2897 : :
2898 : : /* Entire record is only anon unions. */
2899 : 0 : if (bot > top)
2900 : : return NULL_TREE;
2901 : :
2902 : : /* Restart the binary search, with new lower bound. */
2903 : 0 : continue;
2904 : 0 : }
2905 : :
2906 : 1341975 : if (DECL_NAME (field) == component)
2907 : : break;
2908 : 1071987 : if (DECL_NAME (field) < component)
2909 : : bot += half;
2910 : : else
2911 : 886808 : top = bot + half;
2912 : : }
2913 : :
2914 : 298379 : if (DECL_NAME (field_array[bot]) == component)
2915 : : field = field_array[bot];
2916 : 269988 : else if (DECL_NAME (field) != component)
2917 : : return NULL_TREE;
2918 : : }
2919 : : else
2920 : : {
2921 : 5226007 : for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
2922 : : {
2923 : 5217173 : if (DECL_NAME (field) == NULL_TREE
2924 : 5217173 : && RECORD_OR_UNION_TYPE_P (TREE_TYPE (field)))
2925 : : {
2926 : 11200 : tree anon = lookup_field (TREE_TYPE (field), component);
2927 : :
2928 : 11200 : if (anon)
2929 : 2441 : return tree_cons (NULL_TREE, field, anon);
2930 : :
2931 : : /* The Plan 9 compiler permits referring directly to an
2932 : : anonymous struct/union field using a typedef
2933 : : name. */
2934 : 8759 : if (flag_plan9_extensions
2935 : 38 : && TYPE_NAME (TREE_TYPE (field)) != NULL_TREE
2936 : 36 : && TREE_CODE (TYPE_NAME (TREE_TYPE (field))) == TYPE_DECL
2937 : 8765 : && (DECL_NAME (TYPE_NAME (TREE_TYPE (field)))
2938 : : == component))
2939 : : break;
2940 : : }
2941 : :
2942 : 5214728 : if (DECL_NAME (field) == component)
2943 : : break;
2944 : : }
2945 : :
2946 : 2004052 : if (field == NULL_TREE)
2947 : : return NULL_TREE;
2948 : : }
2949 : :
2950 : 2293597 : return tree_cons (NULL_TREE, field, NULL_TREE);
2951 : : }
2952 : :
2953 : : /* Recursively append candidate IDENTIFIER_NODEs to CANDIDATES. */
2954 : :
2955 : : static void
2956 : 101 : lookup_field_fuzzy_find_candidates (tree type, tree component,
2957 : : vec<tree> *candidates)
2958 : : {
2959 : 101 : tree field;
2960 : 258 : for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
2961 : : {
2962 : 157 : if (DECL_NAME (field) == NULL_TREE
2963 : 157 : && RECORD_OR_UNION_TYPE_P (TREE_TYPE (field)))
2964 : 30 : lookup_field_fuzzy_find_candidates (TREE_TYPE (field), component,
2965 : : candidates);
2966 : :
2967 : 157 : if (DECL_NAME (field))
2968 : 111 : candidates->safe_push (DECL_NAME (field));
2969 : : }
2970 : 101 : }
2971 : :
2972 : : /* Like "lookup_field", but find the closest matching IDENTIFIER_NODE,
2973 : : rather than returning a TREE_LIST for an exact match. */
2974 : :
2975 : : static tree
2976 : 71 : lookup_field_fuzzy (tree type, tree component)
2977 : : {
2978 : 71 : gcc_assert (TREE_CODE (component) == IDENTIFIER_NODE);
2979 : :
2980 : : /* First, gather a list of candidates. */
2981 : 71 : auto_vec <tree> candidates;
2982 : :
2983 : 71 : lookup_field_fuzzy_find_candidates (type, component,
2984 : : &candidates);
2985 : :
2986 : 71 : return find_closest_identifier (component, &candidates);
2987 : 71 : }
2988 : :
2989 : : /* Support function for build_component_ref's error-handling.
2990 : :
2991 : : Given DATUM_TYPE, and "DATUM.COMPONENT", where DATUM is *not* a
2992 : : struct or union, should we suggest "DATUM->COMPONENT" as a hint? */
2993 : :
2994 : : static bool
2995 : 72 : should_suggest_deref_p (tree datum_type)
2996 : : {
2997 : : /* We don't do it for Objective-C, since Objective-C 2.0 dot-syntax
2998 : : allows "." for ptrs; we could be handling a failed attempt
2999 : : to access a property. */
3000 : 72 : if (c_dialect_objc ())
3001 : : return false;
3002 : :
3003 : : /* Only suggest it for pointers... */
3004 : 72 : if (TREE_CODE (datum_type) != POINTER_TYPE)
3005 : : return false;
3006 : :
3007 : : /* ...to structs/unions. */
3008 : 8 : tree underlying_type = TREE_TYPE (datum_type);
3009 : 8 : enum tree_code code = TREE_CODE (underlying_type);
3010 : 8 : if (code == RECORD_TYPE || code == UNION_TYPE)
3011 : : return true;
3012 : : else
3013 : 1 : return false;
3014 : : }
3015 : :
3016 : : /* Give a component ref REF, decide whether we should handle its counted_by
3017 : : attribute based on its context:
3018 : : Do not handle counted_by when in offsetof, typeof and alignof operator. */
3019 : :
3020 : : static bool
3021 : 2263623 : handle_counted_by_p (tree ref)
3022 : : {
3023 : 2263623 : gcc_assert (TREE_CODE (ref) == COMPONENT_REF);
3024 : 2263623 : tree datum = TREE_OPERAND (ref, 0);
3025 : : /* If the component_ref is build for a offsetof, i.e., the datum
3026 : : of the component_ref is a indirect_ref of null_pointer_node,
3027 : : we should not generate call to .ACCESS_WITH_SIZE. */
3028 : 2263623 : if (TREE_CODE (datum) == INDIRECT_REF
3029 : 2263623 : && TREE_OPERAND (datum, 0) == null_pointer_node)
3030 : : return false;
3031 : 2263293 : if (in_typeof || in_alignof)
3032 : 8783 : return false;
3033 : : return true;
3034 : : }
3035 : :
3036 : : /* Given a component ref REF, if there is a counted_by attribute attached,
3037 : : issue error when the element_type is a structure or union including a
3038 : : flexible array member. */
3039 : :
3040 : : static void
3041 : 2262575 : check_counted_by_attribute (location_t loc, tree ref)
3042 : : {
3043 : 2262575 : tree subdatum = TREE_OPERAND (ref, 1);
3044 : 2262575 : tree sub_type = TREE_TYPE (subdatum);
3045 : :
3046 : 2262575 : if (!c_flexible_array_member_type_p (sub_type)
3047 : 2262575 : && TREE_CODE (sub_type) != POINTER_TYPE)
3048 : : return;
3049 : :
3050 : 383456 : tree element_type = TREE_TYPE (sub_type);
3051 : :
3052 : 383456 : tree attr_counted_by = lookup_attribute ("counted_by",
3053 : 383456 : DECL_ATTRIBUTES (subdatum));
3054 : 383456 : if (attr_counted_by)
3055 : : {
3056 : : /* Issue error when the element_type is a structure or
3057 : : union including a flexible array member. */
3058 : 407 : if (RECORD_OR_UNION_TYPE_P (element_type)
3059 : 407 : && TYPE_INCLUDES_FLEXARRAY (element_type))
3060 : : {
3061 : 2 : error_at (loc,
3062 : : "%<counted_by%> attribute is not allowed for a pointer to"
3063 : : " structure or union with flexible array member");
3064 : 2 : return;
3065 : : }
3066 : : }
3067 : : }
3068 : :
3069 : : /* For a SUBDATUM field of a structure or union DATUM, generate a REF
3070 : : to the object that represents its counted_by per the attribute
3071 : : counted_by attached to this field if it's a flexible array member
3072 : : or a pointer field, otherwise return NULL_TREE.
3073 : : Set COUNTED_BY_TYPE to the TYPE of the counted_by field.
3074 : : For example, if:
3075 : :
3076 : : struct P {
3077 : : int k;
3078 : : int x[] __attribute__ ((counted_by (k)));
3079 : : } *p;
3080 : :
3081 : : for:
3082 : : p->x
3083 : :
3084 : : the ref to the object that represents its element count will be:
3085 : :
3086 : : &(p->k)
3087 : : */
3088 : :
3089 : : static tree
3090 : 495958 : build_counted_by_ref (tree datum, tree subdatum,
3091 : : tree *counted_by_type)
3092 : : {
3093 : 495958 : tree type = TREE_TYPE (datum);
3094 : 495958 : tree sub_type = TREE_TYPE (subdatum);
3095 : 495958 : if (!c_flexible_array_member_type_p (sub_type)
3096 : 495958 : && TREE_CODE (sub_type) != POINTER_TYPE)
3097 : : return NULL_TREE;
3098 : :
3099 : 495958 : tree attr_counted_by = lookup_attribute ("counted_by",
3100 : 495958 : DECL_ATTRIBUTES (subdatum));
3101 : 495958 : tree counted_by_ref = NULL_TREE;
3102 : 495958 : *counted_by_type = NULL_TREE;
3103 : 495958 : if (attr_counted_by)
3104 : : {
3105 : 306 : tree field_id = TREE_VALUE (TREE_VALUE (attr_counted_by));
3106 : 306 : counted_by_ref
3107 : 306 : = build_component_ref (UNKNOWN_LOCATION,
3108 : : datum, field_id,
3109 : : UNKNOWN_LOCATION, UNKNOWN_LOCATION);
3110 : 306 : counted_by_ref = build_fold_addr_expr (counted_by_ref);
3111 : :
3112 : : /* Get the TYPE of the counted_by field. */
3113 : 306 : tree counted_by_field = lookup_field (type, field_id);
3114 : 306 : gcc_assert (counted_by_field);
3115 : :
3116 : 408 : do
3117 : : {
3118 : 408 : *counted_by_type = TREE_TYPE (TREE_VALUE (counted_by_field));
3119 : 408 : counted_by_field = TREE_CHAIN (counted_by_field);
3120 : : }
3121 : 408 : while (counted_by_field);
3122 : : }
3123 : : return counted_by_ref;
3124 : : }
3125 : :
3126 : : /* Given a COMPONENT_REF REF with the location LOC, the corresponding
3127 : : COUNTED_BY_REF, and the COUNTED_BY_TYPE, generate the corresponding
3128 : : call to the internal function .ACCESS_WITH_SIZE.
3129 : :
3130 : : A: For the Flexible Array Member, Generate an INDIRECT_REF to a call to
3131 : : the internal function .ACCESS_WITH_SIZE.
3132 : :
3133 : : REF
3134 : :
3135 : : to:
3136 : :
3137 : : (*.ACCESS_WITH_SIZE (REF, COUNTED_BY_REF, (* TYPE_OF_SIZE)0,
3138 : : TYPE_SIZE_UNIT for element)
3139 : :
3140 : : NOTE: The return type of this function is the POINTER type pointing
3141 : : to the original flexible array type. Then the type of the INDIRECT_REF
3142 : : is the original flexible array type.
3143 : : The type of the first argument of this function is a POINTER type
3144 : : to the original flexible array type.
3145 : :
3146 : : B: For pointers with counted_by, generate a call to the internal function
3147 : : .ACCESS_WITH_SIZE.
3148 : :
3149 : : REF
3150 : :
3151 : : to:
3152 : :
3153 : : .ACCESS_WITH_SIZE (REF, COUNTED_BY_REF, (* TYPE_OF_SIZE)0,
3154 : : TYPE_SIZE_UNIT for element)
3155 : :
3156 : : NOTE: The return type of this function is the original pointer type.
3157 : : The type of the first argument of this function is the original
3158 : : pointer type.
3159 : :
3160 : : The 3rd argument of the call is a constant 0 with the pointer TYPE whose
3161 : : pointee type is the TYPE of the object pointed by COUNTED_BY_REF.
3162 : :
3163 : : The 4th argument of the call is the TYPE_SIZE_UNIT of the element TYPE
3164 : : of the array.
3165 : :
3166 : : */
3167 : : static tree
3168 : 306 : build_access_with_size_for_counted_by (location_t loc, tree ref,
3169 : : tree counted_by_ref,
3170 : : tree counted_by_type)
3171 : : {
3172 : 306 : gcc_assert (c_flexible_array_member_type_p (TREE_TYPE (ref))
3173 : : || TREE_CODE (TREE_TYPE (ref)) == POINTER_TYPE);
3174 : :
3175 : 306 : bool is_fam = c_flexible_array_member_type_p (TREE_TYPE (ref));
3176 : :
3177 : : /* The result type of the call is a pointer to the flexible array type;
3178 : : or is the original ponter type to the pointer field with counted_by. */
3179 : 306 : tree result_type = is_fam ? c_build_pointer_type (TREE_TYPE (ref))
3180 : 152 : : TREE_TYPE (ref);
3181 : :
3182 : 306 : tree element_type = TREE_TYPE (TREE_TYPE (ref));
3183 : 306 : tree element_size = VOID_TYPE_P (element_type)
3184 : 306 : ? build_one_cst (size_type_node)
3185 : 298 : : TYPE_SIZE_UNIT (element_type);
3186 : :
3187 : 306 : tree first_param = is_fam
3188 : 306 : ? c_fully_fold (array_to_pointer_conversion (loc, ref),
3189 : : false, NULL)
3190 : : : ref;
3191 : 306 : tree second_param
3192 : 306 : = c_fully_fold (counted_by_ref, false, NULL);
3193 : 306 : tree third_param = build_int_cst (c_build_pointer_type (counted_by_type), 0);
3194 : :
3195 : 306 : tree call
3196 : 306 : = build_call_expr_internal_loc (loc, IFN_ACCESS_WITH_SIZE,
3197 : : result_type, 4,
3198 : : first_param,
3199 : : second_param,
3200 : : third_param,
3201 : : element_size);
3202 : :
3203 : : /* Wrap the call with an INDIRECT_REF with the flexible array type. */
3204 : 306 : if (is_fam)
3205 : 154 : call = build1 (INDIRECT_REF, TREE_TYPE (ref), call);
3206 : 306 : SET_EXPR_LOCATION (call, loc);
3207 : 306 : return call;
3208 : : }
3209 : :
3210 : : /* For the COMPONENT_REF ref, check whether it has a counted_by attribute,
3211 : : if so, wrap this COMPONENT_REF with the corresponding CALL to the
3212 : : function .ACCESS_WITH_SIZE.
3213 : : Otherwise, return the ref itself. */
3214 : :
3215 : : tree
3216 : 2254550 : handle_counted_by_for_component_ref (location_t loc, tree ref)
3217 : : {
3218 : 2254550 : gcc_assert (TREE_CODE (ref) == COMPONENT_REF);
3219 : 2254550 : tree datum = TREE_OPERAND (ref, 0);
3220 : 2254550 : tree subdatum = TREE_OPERAND (ref, 1);
3221 : 2254550 : tree counted_by_type = NULL_TREE;
3222 : :
3223 : 2254550 : if (!(c_flexible_array_member_type_p (TREE_TYPE (ref))
3224 : 2184316 : || TREE_CODE (TREE_TYPE (ref)) == POINTER_TYPE))
3225 : : return ref;
3226 : :
3227 : 495958 : tree counted_by_ref = build_counted_by_ref (datum, subdatum,
3228 : : &counted_by_type);
3229 : 495958 : if (counted_by_ref)
3230 : 306 : ref = build_access_with_size_for_counted_by (loc, ref,
3231 : : counted_by_ref,
3232 : : counted_by_type);
3233 : : return ref;
3234 : : }
3235 : :
3236 : : /* Make an expression to refer to the COMPONENT field of structure or
3237 : : union value DATUM. COMPONENT is an IDENTIFIER_NODE. LOC is the
3238 : : location of the COMPONENT_REF. COMPONENT_LOC is the location
3239 : : of COMPONENT. ARROW_LOC is the location of the first -> operand if
3240 : : it is from -> operator.
3241 : : If HANDLE_COUNTED_BY is true, check the counted_by attribute and generate
3242 : : a call to .ACCESS_WITH_SIZE. Otherwise, ignore the attribute. */
3243 : :
3244 : : tree
3245 : 2260555 : build_component_ref (location_t loc, tree datum, tree component,
3246 : : location_t component_loc, location_t arrow_loc)
3247 : : {
3248 : 2260555 : tree type = TREE_TYPE (datum);
3249 : 2260555 : enum tree_code code = TREE_CODE (type);
3250 : 2260555 : tree field = NULL;
3251 : 2260555 : tree ref;
3252 : 2260555 : bool datum_lvalue = lvalue_p (datum);
3253 : :
3254 : 2260555 : if (!objc_is_public (datum, component))
3255 : 0 : return error_mark_node;
3256 : :
3257 : : /* Detect Objective-C property syntax object.property. */
3258 : 2260555 : if (c_dialect_objc ()
3259 : 2260555 : && (ref = objc_maybe_build_component_ref (datum, component)))
3260 : : return ref;
3261 : :
3262 : : /* See if there is a field or component with name COMPONENT. */
3263 : :
3264 : 2260555 : if (code == RECORD_TYPE || code == UNION_TYPE)
3265 : : {
3266 : 2260483 : if (!COMPLETE_TYPE_P (type))
3267 : : {
3268 : 19 : c_incomplete_type_error (loc, NULL_TREE, type);
3269 : 19 : return error_mark_node;
3270 : : }
3271 : :
3272 : 2260464 : field = lookup_field (type, component);
3273 : :
3274 : 2260464 : if (!field)
3275 : : {
3276 : 63 : tree guessed_id = lookup_field_fuzzy (type, component);
3277 : 63 : if (guessed_id)
3278 : : {
3279 : : /* Attempt to provide a fixit replacement hint, if
3280 : : we have a valid range for the component. */
3281 : 0 : location_t reported_loc
3282 : 26 : = (component_loc != UNKNOWN_LOCATION) ? component_loc : loc;
3283 : 26 : gcc_rich_location rich_loc (reported_loc);
3284 : 26 : if (component_loc != UNKNOWN_LOCATION)
3285 : 26 : rich_loc.add_fixit_misspelled_id (component_loc, guessed_id);
3286 : 26 : error_at (&rich_loc,
3287 : : "%qT has no member named %qE; did you mean %qE?",
3288 : : type, component, guessed_id);
3289 : 26 : }
3290 : : else
3291 : 37 : error_at (loc, "%qT has no member named %qE", type, component);
3292 : 63 : return error_mark_node;
3293 : : }
3294 : :
3295 : : /* Accessing elements of atomic structures or unions is undefined
3296 : : behavior (C11 6.5.2.3#5). */
3297 : 2260401 : if (TYPE_ATOMIC (type) && c_inhibit_evaluation_warnings == 0)
3298 : : {
3299 : 18 : if (code == RECORD_TYPE)
3300 : 12 : warning_at (loc, 0, "accessing a member %qE of an atomic "
3301 : : "structure %qE", component, datum);
3302 : : else
3303 : 6 : warning_at (loc, 0, "accessing a member %qE of an atomic "
3304 : : "union %qE", component, datum);
3305 : : }
3306 : :
3307 : : /* Chain the COMPONENT_REFs if necessary down to the FIELD.
3308 : : This might be better solved in future the way the C++ front
3309 : : end does it - by giving the anonymous entities each a
3310 : : separate name and type, and then have build_component_ref
3311 : : recursively call itself. We can't do that here. */
3312 : 2262575 : do
3313 : : {
3314 : 2262575 : tree subdatum = TREE_VALUE (field);
3315 : 2262575 : int quals;
3316 : 2262575 : tree subtype;
3317 : 2262575 : bool use_datum_quals;
3318 : :
3319 : 2262575 : if (TREE_TYPE (subdatum) == error_mark_node)
3320 : : return error_mark_node;
3321 : :
3322 : : /* If this is an rvalue, it does not have qualifiers in C
3323 : : standard terms and we must avoid propagating such
3324 : : qualifiers down to a non-lvalue array that is then
3325 : : converted to a pointer. */
3326 : 4525150 : use_datum_quals = (datum_lvalue
3327 : 2262575 : || TREE_CODE (TREE_TYPE (subdatum)) != ARRAY_TYPE);
3328 : :
3329 : 2262575 : quals = TYPE_QUALS (strip_array_types (TREE_TYPE (subdatum)));
3330 : 2262575 : if (use_datum_quals)
3331 : 2262313 : quals |= TYPE_QUALS (TREE_TYPE (datum));
3332 : 2262575 : subtype = c_build_qualified_type (TREE_TYPE (subdatum), quals);
3333 : :
3334 : 2262575 : ref = build3 (COMPONENT_REF, subtype, datum, subdatum,
3335 : : NULL_TREE);
3336 : 2262575 : SET_EXPR_LOCATION (ref, loc);
3337 : :
3338 : 2262575 : check_counted_by_attribute (loc, ref);
3339 : :
3340 : 2262575 : if (TREE_READONLY (subdatum)
3341 : 2262575 : || (use_datum_quals && TREE_READONLY (datum)))
3342 : 30378 : TREE_READONLY (ref) = 1;
3343 : 2262575 : if (TREE_THIS_VOLATILE (subdatum)
3344 : 2261689 : || (use_datum_quals && TREE_THIS_VOLATILE (datum)))
3345 : 2320 : TREE_THIS_VOLATILE (ref) = 1;
3346 : :
3347 : 2262575 : if (TREE_UNAVAILABLE (subdatum))
3348 : 10 : error_unavailable_use (subdatum, NULL_TREE);
3349 : 2262565 : else if (TREE_DEPRECATED (subdatum))
3350 : 16 : warn_deprecated_use (subdatum, NULL_TREE);
3351 : :
3352 : 2262575 : datum = ref;
3353 : :
3354 : 2262575 : field = TREE_CHAIN (field);
3355 : : }
3356 : 2262575 : while (field);
3357 : :
3358 : : return ref;
3359 : : }
3360 : 72 : else if (should_suggest_deref_p (type))
3361 : : {
3362 : : /* Special-case the error message for "ptr.field" for the case
3363 : : where the user has confused "." vs "->". */
3364 : 7 : rich_location richloc (line_table, loc);
3365 : 7 : if (INDIRECT_REF_P (datum) && arrow_loc != UNKNOWN_LOCATION)
3366 : : {
3367 : 2 : richloc.add_fixit_insert_before (arrow_loc, "(*");
3368 : 2 : richloc.add_fixit_insert_after (arrow_loc, ")");
3369 : 2 : error_at (&richloc,
3370 : : "%qE is a pointer to pointer; did you mean to dereference "
3371 : : "it before applying %<->%> to it?",
3372 : 2 : TREE_OPERAND (datum, 0));
3373 : : }
3374 : : else
3375 : : {
3376 : : /* "loc" should be the "." token. */
3377 : 5 : richloc.add_fixit_replace ("->");
3378 : 5 : error_at (&richloc,
3379 : : "%qE is a pointer; did you mean to use %<->%>?",
3380 : : datum);
3381 : : }
3382 : 7 : return error_mark_node;
3383 : 7 : }
3384 : 65 : else if (code != ERROR_MARK)
3385 : 1 : error_at (loc,
3386 : : "request for member %qE in something not a structure or union",
3387 : : component);
3388 : :
3389 : 65 : return error_mark_node;
3390 : : }
3391 : :
3392 : : /* Given an expression PTR for a pointer, return an expression
3393 : : for the value pointed to.
3394 : : ERRORSTRING is the name of the operator to appear in error messages.
3395 : :
3396 : : LOC is the location to use for the generated tree. */
3397 : :
3398 : : tree
3399 : 2730905 : build_indirect_ref (location_t loc, tree ptr, ref_operator errstring)
3400 : : {
3401 : 2730905 : tree pointer = default_conversion (ptr);
3402 : 2730905 : tree type = TREE_TYPE (pointer);
3403 : 2730905 : tree ref;
3404 : :
3405 : 2730905 : if (TREE_CODE (type) == POINTER_TYPE)
3406 : : {
3407 : 2730552 : if (CONVERT_EXPR_P (pointer)
3408 : 1952229 : || TREE_CODE (pointer) == VIEW_CONVERT_EXPR)
3409 : : {
3410 : : /* If a warning is issued, mark it to avoid duplicates from
3411 : : the backend. This only needs to be done at
3412 : : warn_strict_aliasing > 2. */
3413 : 778323 : if (warn_strict_aliasing > 2)
3414 : 334853 : if (strict_aliasing_warning (EXPR_LOCATION (pointer),
3415 : 334853 : type, TREE_OPERAND (pointer, 0)))
3416 : 7 : suppress_warning (pointer, OPT_Wstrict_aliasing_);
3417 : : }
3418 : :
3419 : 2730552 : if (TREE_CODE (pointer) == ADDR_EXPR
3420 : 2730552 : && (TREE_TYPE (TREE_OPERAND (pointer, 0))
3421 : 67319 : == TREE_TYPE (type)))
3422 : : {
3423 : 67310 : ref = TREE_OPERAND (pointer, 0);
3424 : 67310 : protected_set_expr_location (ref, loc);
3425 : 67310 : return ref;
3426 : : }
3427 : : else
3428 : : {
3429 : 2663242 : tree t = TREE_TYPE (type);
3430 : :
3431 : 2663242 : ref = build1 (INDIRECT_REF, t, pointer);
3432 : :
3433 : 2663242 : if (VOID_TYPE_P (t) && c_inhibit_evaluation_warnings == 0)
3434 : 151 : warning_at (loc, 0, "dereferencing %<void *%> pointer");
3435 : :
3436 : : /* We *must* set TREE_READONLY when dereferencing a pointer to const,
3437 : : so that we get the proper error message if the result is used
3438 : : to assign to. Also, &* is supposed to be a no-op.
3439 : : And ANSI C seems to specify that the type of the result
3440 : : should be the const type. */
3441 : : /* A de-reference of a pointer to const is not a const. It is valid
3442 : : to change it via some other pointer. */
3443 : 2663242 : TREE_READONLY (ref) = TYPE_READONLY (t);
3444 : 2663242 : TREE_SIDE_EFFECTS (ref)
3445 : 2663242 : = TYPE_VOLATILE (t) || TREE_SIDE_EFFECTS (pointer);
3446 : 2663242 : TREE_THIS_VOLATILE (ref) = TYPE_VOLATILE (t);
3447 : 2663242 : protected_set_expr_location (ref, loc);
3448 : 2663242 : return ref;
3449 : : }
3450 : : }
3451 : 353 : else if (TREE_CODE (pointer) != ERROR_MARK)
3452 : 278 : invalid_indirection_error (loc, type, errstring);
3453 : :
3454 : 353 : return error_mark_node;
3455 : : }
3456 : :
3457 : : /* This handles expressions of the form "a[i]", which denotes
3458 : : an array reference.
3459 : :
3460 : : This is logically equivalent in C to *(a+i), but we may do it differently.
3461 : : If A is a variable or a member, we generate a primitive ARRAY_REF.
3462 : : This avoids forcing the array out of registers, and can work on
3463 : : arrays that are not lvalues (for example, members of structures returned
3464 : : by functions).
3465 : :
3466 : : For vector types, allow vector[i] but not i[vector], and create
3467 : : *(((type*)&vectortype) + i) for the expression.
3468 : :
3469 : : LOC is the location to use for the returned expression. */
3470 : :
3471 : : tree
3472 : 3455692 : build_array_ref (location_t loc, tree array, tree index)
3473 : : {
3474 : 3455692 : tree ret;
3475 : 3455692 : bool swapped = false;
3476 : 3455692 : if (TREE_TYPE (array) == error_mark_node
3477 : 3455692 : || TREE_TYPE (index) == error_mark_node)
3478 : : return error_mark_node;
3479 : :
3480 : 3455584 : if (TREE_CODE (TREE_TYPE (array)) != ARRAY_TYPE
3481 : 1984714 : && TREE_CODE (TREE_TYPE (array)) != POINTER_TYPE
3482 : : /* Allow vector[index] but not index[vector]. */
3483 : 4474258 : && !gnu_vector_type_p (TREE_TYPE (array)))
3484 : : {
3485 : 194 : if (TREE_CODE (TREE_TYPE (index)) != ARRAY_TYPE
3486 : 194 : && TREE_CODE (TREE_TYPE (index)) != POINTER_TYPE)
3487 : : {
3488 : 2 : error_at (loc,
3489 : : "subscripted value is neither array nor pointer nor vector");
3490 : :
3491 : 2 : return error_mark_node;
3492 : : }
3493 : 192 : std::swap (array, index);
3494 : 192 : swapped = true;
3495 : : }
3496 : :
3497 : 3455582 : if (!INTEGRAL_TYPE_P (TREE_TYPE (index)))
3498 : : {
3499 : 2 : error_at (loc, "array subscript is not an integer");
3500 : 2 : return error_mark_node;
3501 : : }
3502 : :
3503 : 3455580 : if (TREE_CODE (TREE_TYPE (TREE_TYPE (array))) == FUNCTION_TYPE)
3504 : : {
3505 : 10 : error_at (loc, "subscripted value is pointer to function");
3506 : 10 : return error_mark_node;
3507 : : }
3508 : :
3509 : : /* ??? Existing practice has been to warn only when the char
3510 : : index is syntactically the index, not for char[array]. */
3511 : 3455570 : if (!swapped)
3512 : 3455384 : warn_array_subscript_with_type_char (loc, index);
3513 : :
3514 : : /* Apply default promotions *after* noticing character types. */
3515 : 3455570 : index = default_conversion (index);
3516 : 3455570 : if (index == error_mark_node)
3517 : : return error_mark_node;
3518 : :
3519 : 3455569 : gcc_assert (TREE_CODE (TREE_TYPE (index)) == INTEGER_TYPE
3520 : : || TREE_CODE (TREE_TYPE (index)) == BITINT_TYPE);
3521 : :
3522 : 3455569 : bool was_vector = VECTOR_TYPE_P (TREE_TYPE (array));
3523 : 3455569 : bool non_lvalue = convert_vector_to_array_for_subscript (loc, &array, index);
3524 : :
3525 : : /* We only generate a call to .ACCESS_WITH_SIZE when it is a read. */
3526 : 3455569 : if (TREE_CODE (array) == COMPONENT_REF
3527 : 3455569 : && handle_counted_by_p (array))
3528 : 814997 : array = handle_counted_by_for_component_ref (loc, array);
3529 : :
3530 : 3455569 : if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE)
3531 : : {
3532 : 2489357 : tree rval, type;
3533 : :
3534 : : /* An array that is indexed by a non-constant
3535 : : cannot be stored in a register; we must be able to do
3536 : : address arithmetic on its address.
3537 : : Likewise an array of elements of variable size. */
3538 : 2489357 : if (TREE_CODE (index) != INTEGER_CST
3539 : 2489357 : || (COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (array)))
3540 : 2017541 : && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array)))) != INTEGER_CST))
3541 : : {
3542 : 472553 : if (!c_mark_addressable (array, true, true))
3543 : 1 : return error_mark_node;
3544 : : }
3545 : : /* An array that is indexed by a constant value which is not within
3546 : : the array bounds cannot be stored in a register either; because we
3547 : : would get a crash in store_bit_field/extract_bit_field when trying
3548 : : to access a non-existent part of the register. */
3549 : 2489356 : if (TREE_CODE (index) == INTEGER_CST
3550 : 2017541 : && TYPE_DOMAIN (TREE_TYPE (array))
3551 : 4503541 : && !int_fits_type_p (index, TYPE_DOMAIN (TREE_TYPE (array))))
3552 : : {
3553 : 60640 : if (!c_mark_addressable (array, false, true))
3554 : 0 : return error_mark_node;
3555 : : /* ISO C2Y disallows a negative integer constant expression index
3556 : : when array subscripting has an operand of array type. */
3557 : 60640 : if (flag_isoc2y
3558 : 26 : && !TREE_OVERFLOW (index)
3559 : 60663 : && tree_int_cst_sgn (index) < 0)
3560 : 10 : error_at (loc, "array subscript is negative");
3561 : : }
3562 : :
3563 : 2489356 : if ((pedantic || warn_c90_c99_compat || warn_c23_c2y_compat)
3564 : 2466087 : && ! was_vector)
3565 : : {
3566 : 1470164 : tree foo = array;
3567 : 2304498 : while (TREE_CODE (foo) == COMPONENT_REF)
3568 : 834334 : foo = TREE_OPERAND (foo, 0);
3569 : 971703 : if ((VAR_P (foo) && C_DECL_REGISTER (foo))
3570 : 2441801 : || (TREE_CODE (foo) == COMPOUND_LITERAL_EXPR
3571 : 72 : && C_DECL_REGISTER (COMPOUND_LITERAL_EXPR_DECL (foo))))
3572 : 78 : pedwarn_c23 (loc, OPT_Wpedantic,
3573 : : "ISO C forbids subscripting %<register%> array "
3574 : : "before C2Y");
3575 : 1470086 : else if (!lvalue_p (foo))
3576 : 118 : pedwarn_c90 (loc, OPT_Wpedantic,
3577 : : "ISO C90 forbids subscripting non-lvalue "
3578 : : "array");
3579 : : }
3580 : :
3581 : 2489356 : if (TREE_CODE (TREE_TYPE (index)) == BITINT_TYPE
3582 : 2489356 : && TYPE_PRECISION (TREE_TYPE (index)) > TYPE_PRECISION (sizetype))
3583 : 3 : index = fold_convert (sizetype, index);
3584 : :
3585 : 2489356 : type = TREE_TYPE (TREE_TYPE (array));
3586 : 2489356 : rval = build4 (ARRAY_REF, type, array, index, NULL_TREE, NULL_TREE);
3587 : : /* Array ref is const/volatile if the array elements are
3588 : : or if the array is. */
3589 : 7468068 : TREE_READONLY (rval)
3590 : 2489356 : |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array)))
3591 : 2489356 : | TREE_READONLY (array));
3592 : 7468068 : TREE_SIDE_EFFECTS (rval)
3593 : 2489356 : |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
3594 : 2489356 : | TREE_SIDE_EFFECTS (array));
3595 : 4978712 : TREE_THIS_VOLATILE (rval)
3596 : 2489356 : |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
3597 : : /* This was added by rms on 16 Nov 91.
3598 : : It fixes vol struct foo *a; a->elts[1]
3599 : : in an inline function.
3600 : : Hope it doesn't break something else. */
3601 : 2489356 : | TREE_THIS_VOLATILE (array));
3602 : 2489356 : ret = require_complete_type (loc, rval);
3603 : 2489356 : protected_set_expr_location (ret, loc);
3604 : 2489356 : if (non_lvalue)
3605 : 104793 : ret = non_lvalue_loc (loc, ret);
3606 : 2489356 : return ret;
3607 : : }
3608 : : else
3609 : : {
3610 : 966212 : tree ar = default_conversion (array);
3611 : :
3612 : 966212 : if (ar == error_mark_node)
3613 : : return ar;
3614 : :
3615 : 966212 : gcc_assert (TREE_CODE (TREE_TYPE (ar)) == POINTER_TYPE);
3616 : 966212 : gcc_assert (TREE_CODE (TREE_TYPE (TREE_TYPE (ar))) != FUNCTION_TYPE);
3617 : :
3618 : 966212 : ret = build_indirect_ref (loc, build_binary_op (loc, PLUS_EXPR, ar,
3619 : : index, false),
3620 : : RO_ARRAY_INDEXING);
3621 : 966212 : if (non_lvalue)
3622 : 0 : ret = non_lvalue_loc (loc, ret);
3623 : 966212 : return ret;
3624 : : }
3625 : : }
3626 : :
3627 : : /* Build an OpenMP array section reference, creating an exact type for the
3628 : : resulting expression based on the element type and bounds if possible. If
3629 : : we have variable bounds, create an incomplete array type for the result
3630 : : instead. */
3631 : :
3632 : : tree
3633 : 3937 : build_omp_array_section (location_t loc, tree array, tree index, tree length)
3634 : : {
3635 : 3937 : tree type = TREE_TYPE (array);
3636 : 3937 : gcc_assert (type);
3637 : :
3638 : 3937 : tree sectype, eltype = TREE_TYPE (type);
3639 : :
3640 : : /* It's not an array or pointer type. Just reuse the type of the original
3641 : : expression as the type of the array section (an error will be raised
3642 : : anyway, later). */
3643 : 3937 : if (eltype == NULL_TREE || error_operand_p (eltype))
3644 : 12 : sectype = TREE_TYPE (array);
3645 : : else
3646 : : {
3647 : 3925 : tree idxtype = NULL_TREE;
3648 : :
3649 : 3925 : if (index != NULL_TREE
3650 : 3925 : && length != NULL_TREE
3651 : 2998 : && INTEGRAL_TYPE_P (TREE_TYPE (index))
3652 : 6918 : && INTEGRAL_TYPE_P (TREE_TYPE (length)))
3653 : : {
3654 : 2986 : tree low = fold_convert (sizetype, index);
3655 : 2986 : tree high = fold_convert (sizetype, length);
3656 : 2986 : high = size_binop (PLUS_EXPR, low, high);
3657 : 2986 : high = size_binop (MINUS_EXPR, high, size_one_node);
3658 : 2986 : idxtype = build_range_type (sizetype, low, high);
3659 : : }
3660 : 135 : else if ((index == NULL_TREE || integer_zerop (index))
3661 : 829 : && length != NULL_TREE
3662 : 1616 : && INTEGRAL_TYPE_P (TREE_TYPE (length)))
3663 : 660 : idxtype = build_index_type (length);
3664 : :
3665 : 3925 : gcc_assert (!error_operand_p (idxtype));
3666 : :
3667 : 3925 : sectype = c_build_array_type (eltype, idxtype);
3668 : : }
3669 : :
3670 : 3937 : return build3_loc (loc, OMP_ARRAY_SECTION, sectype, array, index, length);
3671 : : }
3672 : :
3673 : :
3674 : : /* Record that REF is used. This is relevant for undeclared static
3675 : : function and declarations referenced from a non-local context.
3676 : : ADDRESS indicates whether the address is taken. */
3677 : :
3678 : : void
3679 : 470382028 : mark_decl_used (tree ref, bool address)
3680 : : {
3681 : 470382028 : if (!ref || !DECL_P (ref) || in_alignof)
3682 : : return;
3683 : :
3684 : : /* Non-file-scope and non-local reference in nested function. */
3685 : 346280411 : bool nonloc_p = current_function_decl && DECL_CONTEXT (ref)
3686 : 121462985 : && DECL_CONTEXT (current_function_decl)
3687 : 470348299 : && DECL_CONTEXT (ref) != current_function_decl;
3688 : :
3689 : : /* An undeclared static function. */
3690 : 470338256 : bool static_p = TREE_CODE (ref) == FUNCTION_DECL
3691 : 101358885 : && DECL_INITIAL (ref) == NULL_TREE
3692 : 69332706 : && DECL_EXTERNAL (ref)
3693 : 539668364 : && !TREE_PUBLIC (ref);
3694 : :
3695 : 470204706 : if (!static_p && !nonloc_p)
3696 : : return;
3697 : :
3698 : : /* If we may be in an unevaluated context, delay the decision. */
3699 : 136148 : if (in_sizeof || in_typeof || in_countof || in_generic)
3700 : 270 : return record_maybe_used_decl (ref, address);
3701 : :
3702 : 135878 : if (static_p)
3703 : 133294 : C_DECL_USED (ref) = 1;
3704 : :
3705 : 135878 : if (nonloc_p && (VAR_OR_FUNCTION_DECL_P (ref)
3706 : : || TREE_CODE (ref) == PARM_DECL))
3707 : 2040 : DECL_NONLOCAL (ref) = 1;
3708 : :
3709 : : /* Nothing to do anymore. */
3710 : 2584 : if (!nonloc_p || C_FUNC_NONLOCAL_CONTEXT (current_function_decl))
3711 : 134695 : return;
3712 : :
3713 : : /* Filter out the cases where referencing a non-local variable does not
3714 : : require a non-local context passed via the static chain. */
3715 : 1183 : if (!C_TYPE_VARIABLY_MODIFIED (TREE_TYPE (ref)))
3716 : 1127 : switch (TREE_CODE (ref))
3717 : : {
3718 : 215 : case FUNCTION_DECL:
3719 : : /* Use of another local function that requires no context is ok. */
3720 : 215 : if (!C_FUNC_NONLOCAL_CONTEXT (ref) && DECL_INITIAL (ref))
3721 : : return;
3722 : : break;
3723 : 437 : case VAR_DECL:
3724 : : /* Static variables and constexpr are ok, but for the later only
3725 : : when the address is not taken. */
3726 : 437 : if (TREE_STATIC (ref) || (C_DECL_DECLARED_CONSTEXPR (ref) && !address))
3727 : : return;
3728 : : break;
3729 : : case TYPE_DECL:
3730 : : /* A typedef is ok when not for a variably-modified type. */
3731 : : return;
3732 : : case CONST_DECL:
3733 : : /* An enumeration constant is ok. */
3734 : : return;
3735 : : case PARM_DECL:
3736 : : break;
3737 : : case LABEL_DECL:
3738 : : break;
3739 : 0 : default:
3740 : 0 : gcc_unreachable ();
3741 : : }
3742 : :
3743 : : /* Mark all parent functions up to the nesting level of the variable as
3744 : : as needing the non-local context. */
3745 : 1971 : for (tree cont = current_function_decl; cont; cont = DECL_CONTEXT (cont))
3746 : : {
3747 : 1971 : if (cont == DECL_CONTEXT (ref))
3748 : : break;
3749 : :
3750 : : /* There should not be any other type of context used for function
3751 : : except TRANSLATION_UNIT_DECL which we should be able to reach. */
3752 : 991 : gcc_checking_assert (TREE_CODE (cont) == FUNCTION_DECL);
3753 : :
3754 : 991 : if (TREE_CODE (cont) == FUNCTION_DECL)
3755 : 991 : C_FUNC_NONLOCAL_CONTEXT (cont) = 1;
3756 : : }
3757 : : }
3758 : :
3759 : :
3760 : : /* Build an external reference to identifier ID. FUN indicates
3761 : : whether this will be used for a function call. LOC is the source
3762 : : location of the identifier. This sets *TYPE to the type of the
3763 : : identifier, which is not the same as the type of the returned value
3764 : : for CONST_DECLs defined as enum constants. If the type of the
3765 : : identifier is not available, *TYPE is set to NULL. */
3766 : : tree
3767 : 174054923 : build_external_ref (location_t loc, tree id, bool fun, tree *type)
3768 : : {
3769 : 174054923 : tree ref;
3770 : 174054923 : tree decl = lookup_name (id);
3771 : :
3772 : : /* In Objective-C, an instance variable (ivar) may be preferred to
3773 : : whatever lookup_name() found. */
3774 : 174054923 : decl = objc_lookup_ivar (decl, id);
3775 : :
3776 : 174054923 : *type = NULL;
3777 : 174054923 : if (decl && decl != error_mark_node)
3778 : : {
3779 : 174048563 : ref = decl;
3780 : 174048563 : *type = TREE_TYPE (ref);
3781 : 174048563 : if (DECL_P (decl) && C_DECL_UNDERSPECIFIED (decl))
3782 : 4 : error_at (loc, "underspecified %qD referenced in its initializer",
3783 : : decl);
3784 : : }
3785 : 6360 : else if (fun)
3786 : : /* Implicit function declaration. */
3787 : 4729 : ref = implicitly_declare (loc, id);
3788 : 1631 : else if (decl == error_mark_node)
3789 : : /* Don't complain about something that's already been
3790 : : complained about. */
3791 : : return error_mark_node;
3792 : : else
3793 : : {
3794 : 1401 : undeclared_variable (loc, id);
3795 : 1401 : return error_mark_node;
3796 : : }
3797 : :
3798 : : /* For an OpenMP map clause, we can get better diagnostics for decls with
3799 : : unmappable types if we return the decl with an error_mark_node type,
3800 : : rather than returning error_mark_node for the decl itself. */
3801 : 174053292 : if (TREE_TYPE (ref) == error_mark_node
3802 : 174053292 : && !c_omp_array_section_p)
3803 : : return error_mark_node;
3804 : :
3805 : 174053275 : if (TREE_UNAVAILABLE (ref))
3806 : 14 : error_unavailable_use (ref, NULL_TREE);
3807 : 174053261 : else if (TREE_DEPRECATED (ref))
3808 : 49 : warn_deprecated_use (ref, NULL_TREE);
3809 : :
3810 : : /* Recursive call does not count as usage. */
3811 : 174053275 : if (ref != current_function_decl)
3812 : : {
3813 : 174050644 : TREE_USED (ref) = 1;
3814 : : }
3815 : :
3816 : 174053275 : mark_decl_used (ref, false);
3817 : :
3818 : 174053275 : if (TREE_CODE (ref) == CONST_DECL)
3819 : : {
3820 : 415384 : used_types_insert (TREE_TYPE (ref));
3821 : :
3822 : 415384 : if (warn_cxx_compat
3823 : 377 : && TREE_CODE (TREE_TYPE (ref)) == ENUMERAL_TYPE
3824 : 415759 : && C_TYPE_DEFINED_IN_STRUCT (TREE_TYPE (ref)))
3825 : : {
3826 : 1 : warning_at (loc, OPT_Wc___compat,
3827 : : "enum constant defined in struct or union "
3828 : : "is not visible in C++");
3829 : 1 : inform (DECL_SOURCE_LOCATION (ref), "enum constant defined here");
3830 : : }
3831 : :
3832 : 415384 : ref = DECL_INITIAL (ref);
3833 : 415384 : TREE_CONSTANT (ref) = 1;
3834 : : }
3835 : : /* C99 6.7.4p3: An inline definition of a function with external
3836 : : linkage ... shall not contain a reference to an identifier with
3837 : : internal linkage. */
3838 : 173637891 : else if (current_function_decl != NULL_TREE
3839 : 172136396 : && DECL_DECLARED_INLINE_P (current_function_decl)
3840 : 158555979 : && DECL_EXTERNAL (current_function_decl)
3841 : 157786857 : && VAR_OR_FUNCTION_DECL_P (ref)
3842 : 56219345 : && (!VAR_P (ref) || TREE_STATIC (ref))
3843 : 47105839 : && ! TREE_PUBLIC (ref)
3844 : 173637925 : && DECL_CONTEXT (ref) != current_function_decl)
3845 : 25 : record_inline_static (loc, current_function_decl, ref,
3846 : : csi_internal);
3847 : :
3848 : : return ref;
3849 : : }
3850 : :
3851 : : static struct maybe_used_decl *maybe_used_decls;
3852 : :
3853 : : /* Record that DECL, a reference seen inside sizeof or typeof or _Countof or
3854 : : _Generic, might be used if the operand of sizeof is a VLA type or the
3855 : : operand of typeof is a variably modified type or the operand of _Countof has
3856 : : a variable number of elements or the operand of _Generic is the one selected
3857 : : as the result. */
3858 : :
3859 : : static void
3860 : 270 : record_maybe_used_decl (tree decl, bool address)
3861 : : {
3862 : 270 : struct maybe_used_decl *t = XOBNEW (&parser_obstack, struct maybe_used_decl);
3863 : 270 : t->decl = decl;
3864 : 270 : t->level = in_sizeof + in_typeof + in_countof + in_generic;
3865 : 270 : t->address = address;
3866 : 270 : t->next = maybe_used_decls;
3867 : 270 : maybe_used_decls = t;
3868 : 270 : }
3869 : :
3870 : : /* Pop the stack of decls possibly used inside sizeof or typeof or _Countof or
3871 : : _Generic. If USED is false, just discard them. If it is true, mark them
3872 : : used (if no longer inside sizeof or typeof or _Countof or _Generic) or move
3873 : : them to the next level up (if still inside sizeof or typeof or _Countof or
3874 : : _Generic). */
3875 : :
3876 : : void
3877 : 1456851 : pop_maybe_used (bool used)
3878 : : {
3879 : 1456851 : struct maybe_used_decl *p = maybe_used_decls;
3880 : 1456851 : int cur_level = in_sizeof + in_typeof + in_countof + in_generic;
3881 : 1457145 : while (p && p->level > cur_level)
3882 : : {
3883 : 294 : if (used)
3884 : : {
3885 : 74 : if (cur_level == 0)
3886 : 50 : mark_decl_used (p->decl, p->address);
3887 : : else
3888 : 24 : p->level = cur_level;
3889 : : }
3890 : 294 : p = p->next;
3891 : : }
3892 : 1456851 : if (!used || cur_level == 0)
3893 : 1456808 : maybe_used_decls = p;
3894 : 1456851 : }
3895 : :
3896 : : /* Pop the stack of decls possibly used inside sizeof or typeof or _Countof or
3897 : : _Generic, without acting on them, and return the pointer to the previous top
3898 : : of the stack. This for use at the end of a default generic association when
3899 : : it is not yet known whether the expression is used. If it later turns out
3900 : : the expression is used (or treated as used before C23), restore_maybe_used
3901 : : should be called on the return value followed by pop_maybe_used (true);
3902 : : otherwise, the return value can be discarded. */
3903 : :
3904 : : struct maybe_used_decl *
3905 : 497 : save_maybe_used ()
3906 : : {
3907 : 497 : struct maybe_used_decl *p = maybe_used_decls, *orig = p;
3908 : 497 : int cur_level = in_sizeof + in_typeof + in_countof + in_generic;
3909 : 529 : while (p && p->level > cur_level)
3910 : 32 : p = p->next;
3911 : 497 : maybe_used_decls = p;
3912 : 497 : return orig;
3913 : : }
3914 : :
3915 : : /* Restore the stack of decls possibly used inside sizeof or typeof or _Countof
3916 : : or _Generic returned by save_maybe_used. It is required that the stack is
3917 : : at exactly the point where it was left by save_maybe_used. */
3918 : :
3919 : : void
3920 : 62 : restore_maybe_used (struct maybe_used_decl *stack)
3921 : : {
3922 : 62 : maybe_used_decls = stack;
3923 : 62 : }
3924 : :
3925 : : /* Return the result of sizeof applied to EXPR. */
3926 : :
3927 : : struct c_expr
3928 : 312454 : c_expr_sizeof_expr (location_t loc, struct c_expr expr)
3929 : : {
3930 : 312454 : struct c_expr ret;
3931 : 312454 : if (expr.value == error_mark_node)
3932 : : {
3933 : 113 : ret.value = error_mark_node;
3934 : 113 : ret.original_code = ERROR_MARK;
3935 : 113 : ret.original_type = NULL;
3936 : 113 : ret.m_decimal = 0;
3937 : 113 : pop_maybe_used (false);
3938 : : }
3939 : : else
3940 : : {
3941 : 312341 : bool expr_const_operands = true;
3942 : :
3943 : 312341 : if (TREE_CODE (expr.value) == PARM_DECL
3944 : 312341 : && C_ARRAY_PARAMETER (expr.value))
3945 : : {
3946 : 55 : auto_diagnostic_group d;
3947 : 55 : if (warning_at (loc, OPT_Wsizeof_array_argument,
3948 : : "%<sizeof%> on array function parameter %qE will "
3949 : : "return size of %qT", expr.value,
3950 : 55 : TREE_TYPE (expr.value)))
3951 : 19 : inform (DECL_SOURCE_LOCATION (expr.value), "declared here");
3952 : 55 : }
3953 : 312341 : tree folded_expr = c_fully_fold (expr.value, require_constant_value,
3954 : : &expr_const_operands);
3955 : 312341 : ret.value = c_sizeof (loc, TREE_TYPE (folded_expr));
3956 : 312341 : c_last_sizeof_arg = expr.value;
3957 : 312341 : c_last_sizeof_loc = loc;
3958 : 312341 : ret.original_code = SIZEOF_EXPR;
3959 : 312341 : ret.original_type = NULL;
3960 : 312341 : ret.m_decimal = 0;
3961 : 312341 : if (C_TYPE_VARIABLE_SIZE (TREE_TYPE (folded_expr)))
3962 : : {
3963 : : /* sizeof is evaluated when given a vla (C99 6.5.3.4p2). */
3964 : 288 : ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
3965 : : folded_expr, ret.value);
3966 : 288 : C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !expr_const_operands;
3967 : 288 : SET_EXPR_LOCATION (ret.value, loc);
3968 : : }
3969 : 312341 : pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (folded_expr)));
3970 : : }
3971 : 312454 : return ret;
3972 : : }
3973 : :
3974 : : /* Return the result of sizeof applied to T, a structure for the type
3975 : : name passed to sizeof (rather than the type itself). LOC is the
3976 : : location of the original expression. */
3977 : :
3978 : : struct c_expr
3979 : 331042 : c_expr_sizeof_type (location_t loc, struct c_type_name *t)
3980 : : {
3981 : 331042 : tree type;
3982 : 331042 : struct c_expr ret;
3983 : 331042 : tree type_expr = NULL_TREE;
3984 : 331042 : bool type_expr_const = true;
3985 : 331042 : type = groktypename (t, &type_expr, &type_expr_const);
3986 : 331042 : ret.value = c_sizeof (loc, type);
3987 : 331042 : c_last_sizeof_arg = type;
3988 : 331042 : c_last_sizeof_loc = loc;
3989 : 331042 : ret.original_code = SIZEOF_EXPR;
3990 : 331042 : ret.original_type = NULL;
3991 : 331042 : ret.m_decimal = 0;
3992 : 331042 : if (type == error_mark_node)
3993 : : {
3994 : 5 : ret.value = error_mark_node;
3995 : 5 : ret.original_code = ERROR_MARK;
3996 : : }
3997 : : else
3998 : 330995 : if ((type_expr || TREE_CODE (ret.value) == INTEGER_CST)
3999 : 661947 : && C_TYPE_VARIABLE_SIZE (type))
4000 : : {
4001 : : /* If the type is a [*] array, it is a VLA but is represented as
4002 : : having a size of zero. In such a case we must ensure that
4003 : : the result of sizeof does not get folded to a constant by
4004 : : c_fully_fold, because if the size is evaluated the result is
4005 : : not constant and so constraints on zero or negative size
4006 : : arrays must not be applied when this sizeof call is inside
4007 : : another array declarator. */
4008 : 41 : if (!type_expr)
4009 : 16 : type_expr = integer_zero_node;
4010 : 41 : ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
4011 : : type_expr, ret.value);
4012 : 41 : C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !type_expr_const;
4013 : : }
4014 : 331042 : pop_maybe_used (type != error_mark_node
4015 : 331042 : ? C_TYPE_VARIABLE_SIZE (type) : false);
4016 : 331042 : return ret;
4017 : : }
4018 : :
4019 : : static bool
4020 : 138 : is_top_array_vla (tree type)
4021 : : {
4022 : 138 : bool zero, var;
4023 : 138 : tree d;
4024 : :
4025 : 138 : if (TREE_CODE (type) != ARRAY_TYPE)
4026 : : return false;
4027 : 120 : if (!COMPLETE_TYPE_P (type))
4028 : : return false;
4029 : :
4030 : 116 : d = TYPE_DOMAIN (type);
4031 : 116 : zero = !TYPE_MAX_VALUE (d);
4032 : 116 : if (zero)
4033 : : return false;
4034 : :
4035 : 100 : var = (TREE_CODE (TYPE_MIN_VALUE (d)) != INTEGER_CST
4036 : 100 : || TREE_CODE (TYPE_MAX_VALUE (d)) != INTEGER_CST);
4037 : : return var;
4038 : : }
4039 : :
4040 : : /* Return the result of countof applied to EXPR. */
4041 : :
4042 : : struct c_expr
4043 : 54 : c_expr_countof_expr (location_t loc, struct c_expr expr)
4044 : : {
4045 : 54 : struct c_expr ret;
4046 : 54 : if (expr.value == error_mark_node)
4047 : : {
4048 : 1 : ret.value = error_mark_node;
4049 : 1 : ret.original_code = ERROR_MARK;
4050 : 1 : ret.original_type = NULL;
4051 : 1 : ret.m_decimal = 0;
4052 : 1 : pop_maybe_used (false);
4053 : : }
4054 : : else
4055 : : {
4056 : 53 : bool expr_const_operands = true;
4057 : :
4058 : 53 : tree folded_expr = c_fully_fold (expr.value, require_constant_value,
4059 : : &expr_const_operands);
4060 : 53 : ret.value = c_countof_type (loc, TREE_TYPE (folded_expr));
4061 : 53 : c_last_sizeof_arg = expr.value;
4062 : 53 : c_last_sizeof_loc = loc;
4063 : 53 : ret.original_code = COUNTOF_EXPR;
4064 : 53 : ret.original_type = NULL;
4065 : 53 : ret.m_decimal = 0;
4066 : 53 : if (is_top_array_vla (TREE_TYPE (folded_expr)))
4067 : : {
4068 : : /* countof is evaluated when given a vla. */
4069 : 11 : ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
4070 : : folded_expr, ret.value);
4071 : 11 : C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !expr_const_operands;
4072 : 11 : SET_EXPR_LOCATION (ret.value, loc);
4073 : : }
4074 : 53 : pop_maybe_used (is_top_array_vla (TREE_TYPE (folded_expr)));
4075 : : }
4076 : 54 : return ret;
4077 : : }
4078 : :
4079 : : /* Return the result of countof applied to T, a structure for the type
4080 : : name passed to countof (rather than the type itself). LOC is the
4081 : : location of the original expression. */
4082 : :
4083 : : struct c_expr
4084 : 18 : c_expr_countof_type (location_t loc, struct c_type_name *t)
4085 : : {
4086 : 18 : tree type;
4087 : 18 : struct c_expr ret;
4088 : 18 : tree type_expr = NULL_TREE;
4089 : 18 : bool type_expr_const = true;
4090 : 18 : type = groktypename (t, &type_expr, &type_expr_const);
4091 : 18 : ret.value = c_countof_type (loc, type);
4092 : 18 : c_last_sizeof_arg = type;
4093 : 18 : c_last_sizeof_loc = loc;
4094 : 18 : ret.original_code = COUNTOF_EXPR;
4095 : 18 : ret.original_type = NULL;
4096 : 18 : ret.m_decimal = 0;
4097 : 18 : if (type == error_mark_node)
4098 : : {
4099 : 0 : ret.value = error_mark_node;
4100 : 0 : ret.original_code = ERROR_MARK;
4101 : : }
4102 : : else
4103 : 8 : if ((type_expr || TREE_CODE (ret.value) == INTEGER_CST)
4104 : 22 : && is_top_array_vla (type))
4105 : : {
4106 : : /* If the type is a [*] array, it is a VLA but is represented as
4107 : : having a size of zero. In such a case we must ensure that
4108 : : the result of countof does not get folded to a constant by
4109 : : c_fully_fold, because if the number of elements is evaluated
4110 : : the result is not constant and so
4111 : : constraints on zero or negative size arrays must not be applied
4112 : : when this countof call is inside another array declarator. */
4113 : 6 : if (!type_expr)
4114 : 0 : type_expr = integer_zero_node;
4115 : 6 : ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
4116 : : type_expr, ret.value);
4117 : 6 : C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !type_expr_const;
4118 : : }
4119 : 18 : pop_maybe_used (type != error_mark_node ? is_top_array_vla (type) : false);
4120 : 18 : return ret;
4121 : : }
4122 : :
4123 : : /* Build a function call to function FUNCTION with parameters PARAMS.
4124 : : The function call is at LOC.
4125 : : PARAMS is a list--a chain of TREE_LIST nodes--in which the
4126 : : TREE_VALUE of each node is a parameter-expression.
4127 : : FUNCTION's data type may be a function type or a pointer-to-function. */
4128 : :
4129 : : tree
4130 : 0 : build_function_call (location_t loc, tree function, tree params)
4131 : : {
4132 : 0 : vec<tree, va_gc> *v;
4133 : 0 : tree ret;
4134 : :
4135 : 0 : vec_alloc (v, list_length (params));
4136 : 0 : for (; params; params = TREE_CHAIN (params))
4137 : 0 : v->quick_push (TREE_VALUE (params));
4138 : 0 : ret = c_build_function_call_vec (loc, vNULL, function, v, NULL);
4139 : 0 : vec_free (v);
4140 : 0 : return ret;
4141 : : }
4142 : :
4143 : : /* Give a note about the location of the declaration of DECL,
4144 : : or, failing that, a pertinent declaration for FUNCTION_EXPR. */
4145 : :
4146 : : static void
4147 : 299 : inform_declaration (tree decl, tree function_expr)
4148 : : {
4149 : 299 : if (decl && (TREE_CODE (decl) != FUNCTION_DECL
4150 : 278 : || !DECL_IS_UNDECLARED_BUILTIN (decl)))
4151 : 207 : inform (DECL_SOURCE_LOCATION (decl), "declared here");
4152 : 92 : else if (function_expr)
4153 : 92 : switch (TREE_CODE (function_expr))
4154 : : {
4155 : : default:
4156 : : break;
4157 : 13 : case COMPONENT_REF:
4158 : : /* Show the decl of the pertinent field (e.g. for callback
4159 : : fields in a struct. */
4160 : 13 : {
4161 : 13 : tree field_decl = TREE_OPERAND (function_expr, 1);
4162 : 13 : if (location_t loc = DECL_SOURCE_LOCATION (field_decl))
4163 : 13 : inform (loc, "declared here");
4164 : : }
4165 : : break;
4166 : : }
4167 : 299 : }
4168 : :
4169 : : /* C implementation of callback for use when checking param types. */
4170 : :
4171 : : static bool
4172 : 2 : comp_parm_types (tree wanted_type, tree actual_type)
4173 : : {
4174 : 2 : return comptypes (wanted_type, actual_type);
4175 : : }
4176 : :
4177 : : /* Build a function call to function FUNCTION with parameters PARAMS.
4178 : : If FUNCTION is the result of resolving an overloaded target built-in,
4179 : : ORIG_FUNDECL is the original function decl, otherwise it is null.
4180 : : ORIGTYPES, if not NULL, is a vector of types; each element is
4181 : : either NULL or the original type of the corresponding element in
4182 : : PARAMS. The original type may differ from TREE_TYPE of the
4183 : : parameter for enums. FUNCTION's data type may be a function type
4184 : : or pointer-to-function. This function changes the elements of
4185 : : PARAMS. */
4186 : :
4187 : : tree
4188 : 49625282 : build_function_call_vec (location_t loc, vec<location_t> arg_loc,
4189 : : tree function, vec<tree, va_gc> *params,
4190 : : vec<tree, va_gc> *origtypes, tree orig_fundecl)
4191 : : {
4192 : 49625282 : tree fntype, fundecl = NULL_TREE;
4193 : 49625282 : tree name = NULL_TREE, result;
4194 : 49625282 : tree tem;
4195 : 49625282 : int nargs;
4196 : 49625282 : tree *argarray;
4197 : :
4198 : :
4199 : : /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
4200 : 49625282 : STRIP_TYPE_NOPS (function);
4201 : :
4202 : : /* Convert anything with function type to a pointer-to-function. */
4203 : 49625282 : if (TREE_CODE (function) == FUNCTION_DECL)
4204 : : {
4205 : 49548049 : name = DECL_NAME (function);
4206 : :
4207 : 49548049 : if (flag_tm)
4208 : 421 : tm_malloc_replacement (function);
4209 : 49548049 : fundecl = function;
4210 : 49548049 : if (!orig_fundecl)
4211 : 49548049 : orig_fundecl = fundecl;
4212 : : /* Atomic functions have type checking/casting already done. They are
4213 : : often rewritten and don't match the original parameter list. */
4214 : 99096098 : if (name && startswith (IDENTIFIER_POINTER (name), "__atomic_"))
4215 : : origtypes = NULL;
4216 : : }
4217 : 49625282 : if (TREE_CODE (TREE_TYPE (function)) == FUNCTION_TYPE)
4218 : 49562427 : function = function_to_pointer_conversion (loc, function);
4219 : :
4220 : : /* For Objective-C, convert any calls via a cast to OBJC_TYPE_REF
4221 : : expressions, like those used for ObjC messenger dispatches. */
4222 : 49625282 : if (params && !params->is_empty ())
4223 : 37980611 : function = objc_rewrite_function_call (function, (*params)[0]);
4224 : :
4225 : 49625282 : function = c_fully_fold (function, false, NULL);
4226 : :
4227 : 49625282 : fntype = TREE_TYPE (function);
4228 : :
4229 : 49625282 : if (TREE_CODE (fntype) == ERROR_MARK)
4230 : 3 : return error_mark_node;
4231 : :
4232 : 49625279 : if (!(TREE_CODE (fntype) == POINTER_TYPE
4233 : 49625245 : && TREE_CODE (TREE_TYPE (fntype)) == FUNCTION_TYPE))
4234 : : {
4235 : 37 : if (!flag_diagnostics_show_caret && !STATEMENT_CLASS_P (function))
4236 : 33 : error_at (loc,
4237 : : "called object %qE is not a function or function pointer",
4238 : : function);
4239 : 4 : else if (DECL_P (function))
4240 : : {
4241 : 1 : auto_diagnostic_group d;
4242 : 1 : error_at (loc,
4243 : : "called object %qD is not a function or function pointer",
4244 : : function);
4245 : 1 : inform_declaration (function, NULL_TREE);
4246 : 1 : }
4247 : : else
4248 : 3 : error_at (loc,
4249 : : "called object is not a function or function pointer");
4250 : 37 : return error_mark_node;
4251 : : }
4252 : :
4253 : 49625242 : if (fundecl && TREE_THIS_VOLATILE (fundecl))
4254 : 373371 : current_function_returns_abnormally = 1;
4255 : :
4256 : : /* fntype now gets the type of function pointed to. */
4257 : 49625242 : fntype = TREE_TYPE (fntype);
4258 : 49625242 : tree return_type = TREE_TYPE (fntype);
4259 : :
4260 : : /* Convert the parameters to the types declared in the
4261 : : function prototype, or apply default promotions. */
4262 : :
4263 : 49625242 : nargs = convert_arguments (loc, arg_loc, fntype, params,
4264 : : origtypes, function, fundecl);
4265 : 49625242 : if (nargs < 0)
4266 : 178 : return error_mark_node;
4267 : :
4268 : : /* Check that the function is called through a compatible prototype.
4269 : : If it is not, warn. */
4270 : 49624201 : if (CONVERT_EXPR_P (function)
4271 : 879 : && TREE_CODE (tem = TREE_OPERAND (function, 0)) == ADDR_EXPR
4272 : 215 : && TREE_CODE (tem = TREE_OPERAND (tem, 0)) == FUNCTION_DECL
4273 : 49625249 : && !comptypes (fntype, TREE_TYPE (tem)))
4274 : : {
4275 : : /* This situation leads to run-time undefined behavior. We can't,
4276 : : therefore, simply error unless we can prove that all possible
4277 : : executions of the program must execute the code. */
4278 : 20 : warning_at (loc, 0, "function called through a non-compatible type");
4279 : :
4280 : 20 : if (VOID_TYPE_P (return_type)
4281 : 20 : && TYPE_QUALS (return_type) != TYPE_UNQUALIFIED)
4282 : 1 : pedwarn (loc, 0,
4283 : : "function with qualified void return type called");
4284 : : }
4285 : :
4286 : 49625064 : argarray = vec_safe_address (params);
4287 : :
4288 : : /* Check that arguments to builtin functions match the expectations. */
4289 : 49625064 : if (fundecl
4290 : 49547886 : && fndecl_built_in_p (fundecl)
4291 : 82691326 : && !check_builtin_function_arguments (loc, arg_loc, fundecl,
4292 : : orig_fundecl, nargs, argarray))
4293 : 298 : return error_mark_node;
4294 : :
4295 : : /* Check that the arguments to the function are valid. */
4296 : 49624766 : bool warned_p = check_function_arguments (loc, fundecl, fntype,
4297 : : nargs, argarray, &arg_loc,
4298 : : comp_parm_types);
4299 : :
4300 : 49624766 : if (TYPE_QUALS (return_type) != TYPE_UNQUALIFIED
4301 : 49624766 : && !VOID_TYPE_P (return_type))
4302 : 11 : return_type = c_build_qualified_type (return_type, TYPE_UNQUALIFIED);
4303 : 49624766 : if (name != NULL_TREE
4304 : 99172354 : && startswith (IDENTIFIER_POINTER (name), "__builtin_"))
4305 : : {
4306 : 32347150 : if (require_constant_value)
4307 : 3488 : result
4308 : 3488 : = fold_build_call_array_initializer_loc (loc, return_type,
4309 : : function, nargs, argarray);
4310 : : else
4311 : 32343662 : result = fold_build_call_array_loc (loc, return_type,
4312 : : function, nargs, argarray);
4313 : 32347150 : if (TREE_CODE (result) == NOP_EXPR
4314 : 32347150 : && TREE_CODE (TREE_OPERAND (result, 0)) == INTEGER_CST)
4315 : 26518 : STRIP_TYPE_NOPS (result);
4316 : : }
4317 : : else
4318 : 17277616 : result = build_call_array_loc (loc, return_type,
4319 : : function, nargs, argarray);
4320 : : /* If -Wnonnull warning has been diagnosed, avoid diagnosing it again
4321 : : later. */
4322 : 49624766 : if (warned_p && TREE_CODE (result) == CALL_EXPR)
4323 : 215 : suppress_warning (result, OPT_Wnonnull);
4324 : :
4325 : : /* In this improbable scenario, a nested function returns a VM type.
4326 : : Create a TARGET_EXPR so that the call always has a LHS, much as
4327 : : what the C++ FE does for functions returning non-PODs. */
4328 : 49624766 : if (C_TYPE_VARIABLY_MODIFIED (TREE_TYPE (fntype)))
4329 : : {
4330 : 81 : tree tmp = create_tmp_var_raw (TREE_TYPE (fntype));
4331 : 81 : result = build4 (TARGET_EXPR, TREE_TYPE (fntype), tmp, result,
4332 : : NULL_TREE, NULL_TREE);
4333 : : }
4334 : :
4335 : 49624766 : if (VOID_TYPE_P (TREE_TYPE (result)))
4336 : : {
4337 : 2382331 : if (TYPE_QUALS (TREE_TYPE (result)) != TYPE_UNQUALIFIED)
4338 : 2 : pedwarn (loc, 0,
4339 : : "function with qualified void return type called");
4340 : 2382331 : return result;
4341 : : }
4342 : 47242435 : return require_complete_type (loc, result);
4343 : : }
4344 : :
4345 : : /* Like build_function_call_vec, but call also resolve_overloaded_builtin. */
4346 : :
4347 : : tree
4348 : 49624839 : c_build_function_call_vec (location_t loc, const vec<location_t> &arg_loc,
4349 : : tree function, vec<tree, va_gc> *params,
4350 : : vec<tree, va_gc> *origtypes)
4351 : : {
4352 : : /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
4353 : 49624850 : STRIP_TYPE_NOPS (function);
4354 : :
4355 : : /* Convert anything with function type to a pointer-to-function. */
4356 : 49624839 : if (TREE_CODE (function) == FUNCTION_DECL)
4357 : : {
4358 : : /* Implement type-directed function overloading for builtins.
4359 : : resolve_overloaded_builtin and targetm.resolve_overloaded_builtin
4360 : : handle all the type checking. The result is a complete expression
4361 : : that implements this function call. */
4362 : 49547606 : tree tem = resolve_overloaded_builtin (loc, function, params);
4363 : 49547606 : if (tem)
4364 : : return tem;
4365 : : }
4366 : 49539273 : return build_function_call_vec (loc, arg_loc, function, params, origtypes);
4367 : : }
4368 : :
4369 : : /* Helper for convert_arguments called to convert the VALue of argument
4370 : : number ARGNUM from ORIGTYPE to the corresponding parameter number
4371 : : PARMNUM and TYPE.
4372 : : PLOC is the location where the conversion is being performed.
4373 : : FUNCTION and FUNDECL are the same as in convert_arguments.
4374 : : VALTYPE is the original type of VAL before the conversion and,
4375 : : for EXCESS_PRECISION_EXPR, the operand of the expression.
4376 : : NPC is true if VAL represents the null pointer constant (VAL itself
4377 : : will have been folded to an integer constant).
4378 : : RNAME is the same as FUNCTION except in Objective C when it's
4379 : : the function selector.
4380 : : EXCESS_PRECISION is true when VAL was originally represented
4381 : : as EXCESS_PRECISION_EXPR.
4382 : : WARNOPT is the same as in convert_for_assignment. */
4383 : :
4384 : : static tree
4385 : 124974603 : convert_argument (location_t ploc, tree function, tree fundecl,
4386 : : tree type, tree origtype, tree val, tree valtype,
4387 : : bool npc, tree rname, int parmnum, int argnum,
4388 : : bool excess_precision, int warnopt)
4389 : : {
4390 : : /* Formal parm type is specified by a function prototype. */
4391 : :
4392 : 124974603 : if (type == error_mark_node || !COMPLETE_TYPE_P (type))
4393 : : {
4394 : 3 : error_at (ploc, "type of formal parameter %d is incomplete",
4395 : : parmnum + 1);
4396 : 3 : return error_mark_node;
4397 : : }
4398 : :
4399 : : /* Optionally warn about conversions that differ from the default
4400 : : conversions. */
4401 : 124974600 : if (warn_traditional_conversion || warn_traditional)
4402 : : {
4403 : 193 : if (INTEGRAL_TYPE_P (type)
4404 : 107 : && SCALAR_FLOAT_TYPE_P (valtype))
4405 : 19 : warning_at (ploc, OPT_Wtraditional_conversion,
4406 : : "passing argument %d of %qE as integer rather "
4407 : : "than floating due to prototype",
4408 : : argnum, rname);
4409 : 193 : if (INTEGRAL_TYPE_P (type)
4410 : 107 : && TREE_CODE (valtype) == COMPLEX_TYPE)
4411 : 5 : warning_at (ploc, OPT_Wtraditional_conversion,
4412 : : "passing argument %d of %qE as integer rather "
4413 : : "than complex due to prototype",
4414 : : argnum, rname);
4415 : 188 : else if (TREE_CODE (type) == COMPLEX_TYPE
4416 : 14 : && SCALAR_FLOAT_TYPE_P (valtype))
4417 : 7 : warning_at (ploc, OPT_Wtraditional_conversion,
4418 : : "passing argument %d of %qE as complex rather "
4419 : : "than floating due to prototype",
4420 : : argnum, rname);
4421 : 181 : else if (SCALAR_FLOAT_TYPE_P (type)
4422 : 71 : && INTEGRAL_TYPE_P (valtype))
4423 : 19 : warning_at (ploc, OPT_Wtraditional_conversion,
4424 : : "passing argument %d of %qE as floating rather "
4425 : : "than integer due to prototype",
4426 : : argnum, rname);
4427 : 162 : else if (TREE_CODE (type) == COMPLEX_TYPE
4428 : 7 : && INTEGRAL_TYPE_P (valtype))
4429 : 5 : warning_at (ploc, OPT_Wtraditional_conversion,
4430 : : "passing argument %d of %qE as complex rather "
4431 : : "than integer due to prototype",
4432 : : argnum, rname);
4433 : 157 : else if (SCALAR_FLOAT_TYPE_P (type)
4434 : 52 : && TREE_CODE (valtype) == COMPLEX_TYPE)
4435 : 7 : warning_at (ploc, OPT_Wtraditional_conversion,
4436 : : "passing argument %d of %qE as floating rather "
4437 : : "than complex due to prototype",
4438 : : argnum, rname);
4439 : : /* ??? At some point, messages should be written about
4440 : : conversions between complex types, but that's too messy
4441 : : to do now. */
4442 : 150 : else if (SCALAR_FLOAT_TYPE_P (type)
4443 : 45 : && SCALAR_FLOAT_TYPE_P (valtype))
4444 : : {
4445 : 45 : unsigned int formal_prec = TYPE_PRECISION (type);
4446 : :
4447 : : /* Warn if any argument is passed as `float',
4448 : : since without a prototype it would be `double'. */
4449 : 45 : if (formal_prec == TYPE_PRECISION (float_type_node)
4450 : 45 : && type != dfloat32_type_node)
4451 : 7 : warning_at (ploc, 0,
4452 : : "passing argument %d of %qE as %<float%> "
4453 : : "rather than %<double%> due to prototype",
4454 : : argnum, rname);
4455 : :
4456 : : /* Warn if mismatch between argument and prototype
4457 : : for decimal float types. Warn of conversions with
4458 : : binary float types and of precision narrowing due to
4459 : : prototype. */
4460 : 38 : else if (type != valtype
4461 : 32 : && (type == dfloat32_type_node
4462 : 22 : || type == dfloat64_type_node
4463 : 12 : || type == dfloat128_type_node
4464 : 2 : || valtype == dfloat32_type_node
4465 : 2 : || valtype == dfloat64_type_node
4466 : 2 : || valtype == dfloat128_type_node)
4467 : 38 : && (formal_prec
4468 : 30 : <= TYPE_PRECISION (valtype)
4469 : 14 : || (type == dfloat128_type_node
4470 : 10 : && (valtype
4471 : 10 : != dfloat64_type_node
4472 : 8 : && (valtype
4473 : : != dfloat32_type_node)))
4474 : 8 : || (type == dfloat64_type_node
4475 : 4 : && (valtype
4476 : : != dfloat32_type_node))))
4477 : 24 : warning_at (ploc, 0,
4478 : : "passing argument %d of %qE as %qT "
4479 : : "rather than %qT due to prototype",
4480 : : argnum, rname, type, valtype);
4481 : :
4482 : : }
4483 : : /* Detect integer changing in width or signedness.
4484 : : These warnings are only activated with
4485 : : -Wtraditional-conversion, not with -Wtraditional. */
4486 : 105 : else if (warn_traditional_conversion
4487 : 105 : && INTEGRAL_TYPE_P (type)
4488 : 102 : && INTEGRAL_TYPE_P (valtype))
4489 : : {
4490 : 83 : unsigned int formal_prec = TYPE_PRECISION (type);
4491 : 83 : tree would_have_been = default_conversion (val);
4492 : 83 : tree type1 = TREE_TYPE (would_have_been);
4493 : :
4494 : 83 : if (val == error_mark_node)
4495 : : /* VAL could have been of incomplete type. */;
4496 : 83 : else if (TREE_CODE (type) == ENUMERAL_TYPE
4497 : 83 : && (TYPE_MAIN_VARIANT (type)
4498 : 2 : == TYPE_MAIN_VARIANT (valtype)))
4499 : : /* No warning if function asks for enum
4500 : : and the actual arg is that enum type. */
4501 : : ;
4502 : 81 : else if (formal_prec != TYPE_PRECISION (type1))
4503 : 14 : warning_at (ploc, OPT_Wtraditional_conversion,
4504 : : "passing argument %d of %qE "
4505 : : "with different width due to prototype",
4506 : : argnum, rname);
4507 : 67 : else if (TYPE_UNSIGNED (type) == TYPE_UNSIGNED (type1))
4508 : : ;
4509 : : /* Don't complain if the formal parameter type
4510 : : is an enum, because we can't tell now whether
4511 : : the value was an enum--even the same enum. */
4512 : 32 : else if (TREE_CODE (type) == ENUMERAL_TYPE)
4513 : : ;
4514 : 32 : else if (TREE_CODE (val) == INTEGER_CST
4515 : 5 : && int_fits_type_p (val, type))
4516 : : /* Change in signedness doesn't matter
4517 : : if a constant value is unaffected. */
4518 : : ;
4519 : : /* If the value is extended from a narrower
4520 : : unsigned type, it doesn't matter whether we
4521 : : pass it as signed or unsigned; the value
4522 : : certainly is the same either way. */
4523 : 32 : else if (TYPE_PRECISION (valtype) < TYPE_PRECISION (type)
4524 : 32 : && TYPE_UNSIGNED (valtype))
4525 : : ;
4526 : 32 : else if (TYPE_UNSIGNED (type))
4527 : 17 : warning_at (ploc, OPT_Wtraditional_conversion,
4528 : : "passing argument %d of %qE "
4529 : : "as unsigned due to prototype",
4530 : : argnum, rname);
4531 : : else
4532 : 15 : warning_at (ploc, OPT_Wtraditional_conversion,
4533 : : "passing argument %d of %qE "
4534 : : "as signed due to prototype",
4535 : : argnum, rname);
4536 : : }
4537 : : }
4538 : :
4539 : : /* Possibly restore an EXCESS_PRECISION_EXPR for the
4540 : : sake of better warnings from convert_and_check. */
4541 : 124974600 : if (excess_precision)
4542 : 370 : val = build1 (EXCESS_PRECISION_EXPR, valtype, val);
4543 : :
4544 : 124974600 : tree parmval = convert_for_assignment (ploc, ploc, type,
4545 : : val, origtype, ic_argpass,
4546 : : npc, fundecl, function,
4547 : : parmnum + 1, warnopt);
4548 : 124974600 : return parmval;
4549 : : }
4550 : :
4551 : : /* Convert the argument expressions in the vector VALUES
4552 : : to the types in the list TYPE_ARG_TYPES (FNTYPE).
4553 : :
4554 : : If the list is exhausted, or when an element has NULL as its type,
4555 : : perform the default conversions.
4556 : :
4557 : : ORIGTYPES is the original types of the expressions in VALUES. This
4558 : : holds the type of enum values which have been converted to integral
4559 : : types. It may be NULL.
4560 : :
4561 : : FUNCTION is a tree for the called function. It is used only for
4562 : : error messages, where it is formatted with %qE.
4563 : :
4564 : : This is also where warnings about wrong number of args are generated.
4565 : :
4566 : : ARG_LOC are locations of function arguments (if any).
4567 : :
4568 : : Returns the actual number of arguments processed (which may be less
4569 : : than the length of VALUES in some error situations), or -1 on
4570 : : failure. */
4571 : :
4572 : : static int
4573 : 49625242 : convert_arguments (location_t loc, vec<location_t> arg_loc, tree fntype,
4574 : : vec<tree, va_gc> *values, vec<tree, va_gc> *origtypes,
4575 : : tree function, tree fundecl)
4576 : : {
4577 : 49625242 : tree typelist = TYPE_ARG_TYPES (fntype);
4578 : 49625242 : unsigned int parmnum;
4579 : 49625242 : bool error_args = false;
4580 : 49625242 : const bool type_generic = fundecl
4581 : 49625242 : && lookup_attribute ("type generic", TYPE_ATTRIBUTES (TREE_TYPE (fundecl)));
4582 : 49625242 : bool type_generic_remove_excess_precision = false;
4583 : 49625242 : bool type_generic_overflow_p = false;
4584 : 49625242 : bool type_generic_bit_query = false;
4585 : 49625242 : tree selector;
4586 : :
4587 : : /* Change pointer to function to the function itself for
4588 : : diagnostics. */
4589 : 49625242 : if (TREE_CODE (function) == ADDR_EXPR
4590 : 49625242 : && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL)
4591 : 49550147 : function = TREE_OPERAND (function, 0);
4592 : :
4593 : : /* Handle an ObjC selector specially for diagnostics. */
4594 : 49625242 : selector = objc_message_selector ();
4595 : :
4596 : : /* For a call to a built-in function declared without a prototype,
4597 : : set to the built-in function's argument list. */
4598 : 49625242 : tree builtin_typelist = NULL_TREE;
4599 : :
4600 : : /* For type-generic built-in functions, determine whether excess
4601 : : precision should be removed (classification) or not
4602 : : (comparison). */
4603 : 49625242 : if (fundecl
4604 : 49625242 : && fndecl_built_in_p (fundecl, BUILT_IN_NORMAL))
4605 : : {
4606 : 1393398 : built_in_function code = DECL_FUNCTION_CODE (fundecl);
4607 : 1393398 : if (C_DECL_BUILTIN_PROTOTYPE (fundecl))
4608 : : {
4609 : : /* For a call to a built-in function declared without a prototype
4610 : : use the types of the parameters of the internal built-in to
4611 : : match those of the arguments to. */
4612 : 687239 : if (tree bdecl = builtin_decl_explicit (code))
4613 : 687239 : builtin_typelist = TYPE_ARG_TYPES (TREE_TYPE (bdecl));
4614 : : }
4615 : :
4616 : : /* For type-generic built-in functions, determine whether excess
4617 : : precision should be removed (classification) or not
4618 : : (comparison). */
4619 : 1393398 : if (type_generic)
4620 : 60832 : switch (code)
4621 : : {
4622 : 5380 : case BUILT_IN_ISFINITE:
4623 : 5380 : case BUILT_IN_ISINF:
4624 : 5380 : case BUILT_IN_ISINF_SIGN:
4625 : 5380 : case BUILT_IN_ISNAN:
4626 : 5380 : case BUILT_IN_ISNORMAL:
4627 : 5380 : case BUILT_IN_ISSIGNALING:
4628 : 5380 : case BUILT_IN_FPCLASSIFY:
4629 : 5380 : type_generic_remove_excess_precision = true;
4630 : 5380 : break;
4631 : :
4632 : 21012 : case BUILT_IN_ADD_OVERFLOW_P:
4633 : 21012 : case BUILT_IN_SUB_OVERFLOW_P:
4634 : 21012 : case BUILT_IN_MUL_OVERFLOW_P:
4635 : : /* The last argument of these type-generic builtins
4636 : : should not be promoted. */
4637 : 21012 : type_generic_overflow_p = true;
4638 : 21012 : break;
4639 : :
4640 : 1294 : case BUILT_IN_CLZG:
4641 : 1294 : case BUILT_IN_CTZG:
4642 : 1294 : case BUILT_IN_CLRSBG:
4643 : 1294 : case BUILT_IN_FFSG:
4644 : 1294 : case BUILT_IN_PARITYG:
4645 : 1294 : case BUILT_IN_POPCOUNTG:
4646 : : /* The first argument of these type-generic builtins
4647 : : should not be promoted. */
4648 : 1294 : type_generic_bit_query = true;
4649 : 1294 : break;
4650 : :
4651 : : default:
4652 : : break;
4653 : : }
4654 : : }
4655 : :
4656 : : /* Scan the given expressions (VALUES) and types (TYPELIST), producing
4657 : : individual converted arguments. */
4658 : :
4659 : 49625242 : tree typetail, builtin_typetail, val;
4660 : 49625242 : for (typetail = typelist,
4661 : 49625242 : builtin_typetail = builtin_typelist,
4662 : 49625242 : parmnum = 0;
4663 : 175534478 : values && values->iterate (parmnum, &val);
4664 : : ++parmnum)
4665 : : {
4666 : : /* The type of the function parameter (if it was declared with one). */
4667 : 250881989 : tree type = typetail ? TREE_VALUE (typetail) : NULL_TREE;
4668 : : /* The type of the built-in function parameter (if the function
4669 : : is a built-in). Used to detect type incompatibilities in
4670 : : calls to built-ins declared without a prototype. */
4671 : 125909272 : tree builtin_type = (builtin_typetail
4672 : 126942134 : ? TREE_VALUE (builtin_typetail) : NULL_TREE);
4673 : : /* The original type of the argument being passed to the function. */
4674 : 125909272 : tree valtype = TREE_TYPE (val);
4675 : : /* The called function (or function selector in Objective C). */
4676 : 125909272 : tree rname = function;
4677 : 125909272 : int argnum = parmnum + 1;
4678 : 125909272 : const char *invalid_func_diag;
4679 : : /* Set for EXCESS_PRECISION_EXPR arguments. */
4680 : 125909272 : bool excess_precision = false;
4681 : : /* The value of the argument after conversion to the type
4682 : : of the function parameter it is passed to. */
4683 : 125909272 : tree parmval;
4684 : : /* Some __atomic_* builtins have additional hidden argument at
4685 : : position 0. */
4686 : 125909272 : location_t ploc
4687 : 125641543 : = !arg_loc.is_empty () && values->length () == arg_loc.length ()
4688 : 125640943 : ? expansion_point_location_if_in_system_header (arg_loc[parmnum])
4689 : 125909272 : : input_location;
4690 : :
4691 : 125909272 : if (type == void_type_node)
4692 : : {
4693 : 33 : auto_diagnostic_group d;
4694 : 33 : int num_expected = parmnum;
4695 : 33 : int num_actual = values->length ();
4696 : 33 : gcc_rich_location rich_loc (loc);
4697 : 33 : if (ploc != input_location)
4698 : 32 : rich_loc.add_range (ploc);
4699 : 33 : if (selector)
4700 : 0 : error_at (&rich_loc,
4701 : : "too many arguments to method %qE; expected %i, have %i",
4702 : : selector, num_expected, num_actual);
4703 : : else
4704 : 33 : error_at (&rich_loc,
4705 : : "too many arguments to function %qE; expected %i, have %i",
4706 : : function, num_expected, num_actual);
4707 : 33 : inform_declaration (fundecl, function);
4708 : 65 : return error_args ? -1 : (int) parmnum;
4709 : 33 : }
4710 : :
4711 : 125909239 : if (builtin_type == void_type_node)
4712 : : {
4713 : 12 : auto_diagnostic_group d;
4714 : 12 : if (warning_at (loc, OPT_Wbuiltin_declaration_mismatch,
4715 : : "too many arguments to built-in function %qE "
4716 : : "expecting %d", function, parmnum))
4717 : 12 : inform_declaration (fundecl, function);
4718 : 12 : builtin_typetail = NULL_TREE;
4719 : 12 : }
4720 : :
4721 : 90316 : if (!typetail && parmnum == 0 && !TYPE_NO_NAMED_ARGS_STDARG_P (fntype)
4722 : 125999438 : && !(fundecl && fndecl_built_in_p (fundecl)))
4723 : : {
4724 : 6963 : auto_diagnostic_group d;
4725 : 6963 : bool warned;
4726 : 6963 : if (selector)
4727 : 0 : warned = warning_at (loc, OPT_Wdeprecated_non_prototype,
4728 : : "ISO C23 does not allow arguments"
4729 : : " for method %qE declared without parameters",
4730 : : function);
4731 : : else
4732 : 6963 : warned = warning_at (loc, OPT_Wdeprecated_non_prototype,
4733 : : "ISO C23 does not allow arguments"
4734 : : " for function %qE declared without parameters",
4735 : : function);
4736 : 6963 : if (warned)
4737 : 4 : inform_declaration (fundecl, function);
4738 : 6963 : }
4739 : :
4740 : 125909239 : if (selector && argnum > 2)
4741 : : {
4742 : 0 : rname = selector;
4743 : 0 : argnum -= 2;
4744 : : }
4745 : :
4746 : : /* Determine if VAL is a null pointer constant before folding it. */
4747 : 125909239 : bool npc = null_pointer_constant_p (val);
4748 : :
4749 : : /* If there is excess precision and a prototype, convert once to
4750 : : the required type rather than converting via the semantic
4751 : : type. Likewise without a prototype a float value represented
4752 : : as long double should be converted once to double. But for
4753 : : type-generic classification functions excess precision must
4754 : : be removed here. */
4755 : 125909239 : if (TREE_CODE (val) == EXCESS_PRECISION_EXPR
4756 : 423 : && (type || !type_generic || !type_generic_remove_excess_precision))
4757 : : {
4758 : 403 : val = TREE_OPERAND (val, 0);
4759 : 403 : excess_precision = true;
4760 : : }
4761 : 125909239 : val = c_fully_fold (val, false, NULL);
4762 : 251818479 : STRIP_TYPE_NOPS (val);
4763 : :
4764 : 125909239 : val = require_complete_type (ploc, val);
4765 : :
4766 : : /* Some floating-point arguments must be promoted to double when
4767 : : no type is specified by a prototype. This applies to
4768 : : arguments of type float, and to architecture-specific types
4769 : : (ARM __fp16), but not to _FloatN or _FloatNx types. */
4770 : 125909239 : bool promote_float_arg = false;
4771 : 125909239 : if (type == NULL_TREE
4772 : 936555 : && TREE_CODE (valtype) == REAL_TYPE
4773 : 269699 : && (TYPE_PRECISION (valtype)
4774 : 269699 : <= TYPE_PRECISION (double_type_node))
4775 : 262417 : && TYPE_MAIN_VARIANT (valtype) != double_type_node
4776 : 131418 : && TYPE_MAIN_VARIANT (valtype) != long_double_type_node
4777 : 126040657 : && !DECIMAL_FLOAT_MODE_P (TYPE_MODE (valtype)))
4778 : : {
4779 : : /* Promote this argument, unless it has a _FloatN or
4780 : : _FloatNx type. */
4781 : 1027846 : promote_float_arg = true;
4782 : 1027846 : for (int i = 0; i < NUM_FLOATN_NX_TYPES; i++)
4783 : 900438 : if (TYPE_MAIN_VARIANT (valtype) == FLOATN_NX_TYPE_NODE (i))
4784 : : {
4785 : : promote_float_arg = false;
4786 : : break;
4787 : : }
4788 : : /* Don't promote __bf16 either. */
4789 : 130685 : if (TYPE_MAIN_VARIANT (valtype) == bfloat16_type_node)
4790 : 125778624 : promote_float_arg = false;
4791 : : }
4792 : :
4793 : 125909239 : if (type != NULL_TREE)
4794 : : {
4795 : 124972684 : tree origtype = (!origtypes) ? NULL_TREE : (*origtypes)[parmnum];
4796 : 124972684 : parmval = convert_argument (ploc, function, fundecl, type, origtype,
4797 : : val, valtype, npc, rname, parmnum, argnum,
4798 : : excess_precision, 0);
4799 : : }
4800 : : /* A NULLPTR type is just a nullptr always. */
4801 : 936555 : else if (TREE_CODE (TREE_TYPE (val)) == NULLPTR_TYPE)
4802 : 9 : parmval = omit_one_operand_loc (ploc, TREE_TYPE (val), nullptr_node, val);
4803 : 936546 : else if (promote_float_arg)
4804 : : {
4805 : 127338 : if (type_generic)
4806 : : parmval = val;
4807 : : else
4808 : : {
4809 : : /* Convert `float' to `double'. */
4810 : 124446 : if (warn_double_promotion && !c_inhibit_evaluation_warnings)
4811 : 6 : warning_at (ploc, OPT_Wdouble_promotion,
4812 : : "implicit conversion from %qT to %qT when passing "
4813 : : "argument to function",
4814 : : valtype, double_type_node);
4815 : 124446 : parmval = convert (double_type_node, val);
4816 : : }
4817 : : }
4818 : 809208 : else if ((excess_precision && !type_generic)
4819 : 809206 : || (type_generic_overflow_p && parmnum == 2)
4820 : 788198 : || (type_generic_bit_query && parmnum == 0))
4821 : : /* A "double" argument with excess precision being passed
4822 : : without a prototype or in variable arguments.
4823 : : The last argument of __builtin_*_overflow_p should not be
4824 : : promoted, similarly the first argument of
4825 : : __builtin_{clz,ctz,clrsb,ffs,parity,popcount}g. */
4826 : 22298 : parmval = convert (valtype, val);
4827 : 1573820 : else if ((invalid_func_diag =
4828 : 786910 : targetm.calls.invalid_arg_for_unprototyped_fn (typelist, fundecl, val)))
4829 : : {
4830 : 0 : error (invalid_func_diag);
4831 : 0 : return -1;
4832 : : }
4833 : 786910 : else if (TREE_CODE (val) == ADDR_EXPR && reject_gcc_builtin (val))
4834 : : {
4835 : : return -1;
4836 : : }
4837 : : else
4838 : : /* Convert `short' and `char' to full-size `int'. */
4839 : 786907 : parmval = default_conversion (val);
4840 : :
4841 : 125909236 : (*values)[parmnum] = parmval;
4842 : 125909236 : if (parmval == error_mark_node)
4843 : 105 : error_args = true;
4844 : :
4845 : 125909236 : if (!type && builtin_type && TREE_CODE (builtin_type) != VOID_TYPE)
4846 : : {
4847 : : /* For a call to a built-in function declared without a prototype,
4848 : : perform the conversions from the argument to the expected type
4849 : : but issue warnings rather than errors for any mismatches.
4850 : : Ignore the converted argument and use the PARMVAL obtained
4851 : : above by applying default conversions instead. */
4852 : 1919 : tree origtype = (!origtypes) ? NULL_TREE : (*origtypes)[parmnum];
4853 : 1919 : convert_argument (ploc, function, fundecl, builtin_type, origtype,
4854 : : val, valtype, npc, rname, parmnum, argnum,
4855 : : excess_precision,
4856 : : OPT_Wbuiltin_declaration_mismatch);
4857 : : }
4858 : :
4859 : 125909236 : if (typetail)
4860 : 124972684 : typetail = TREE_CHAIN (typetail);
4861 : :
4862 : 125909236 : if (builtin_typetail)
4863 : 1032845 : builtin_typetail = TREE_CHAIN (builtin_typetail);
4864 : : }
4865 : :
4866 : 87605772 : gcc_assert (parmnum == vec_safe_length (values));
4867 : :
4868 : 98920739 : if (typetail != NULL_TREE && TREE_VALUE (typetail) != void_type_node)
4869 : : {
4870 : : /* Not enough args.
4871 : : Determine minimum number of arguments required. */
4872 : : int min_expected_num = 0;
4873 : 231 : bool at_least_p = false;
4874 : : tree iter = typelist;
4875 : 386 : while (true)
4876 : : {
4877 : 231 : if (!iter)
4878 : : {
4879 : : /* Variadic arguments; stop iterating. */
4880 : : at_least_p = true;
4881 : : break;
4882 : : }
4883 : 222 : if (iter == void_list_node)
4884 : : /* End of arguments; stop iterating. */
4885 : : break;
4886 : 155 : ++min_expected_num;
4887 : 155 : iter = TREE_CHAIN (iter);
4888 : : }
4889 : 76 : auto_diagnostic_group d;
4890 : 76 : int actual_num = vec_safe_length (values);
4891 : 143 : error_at (loc,
4892 : : at_least_p
4893 : : ? G_("too few arguments to function %qE; expected at least %i, have %i")
4894 : : : G_("too few arguments to function %qE; expected %i, have %i"),
4895 : : function, min_expected_num, actual_num);
4896 : 76 : inform_declaration (fundecl, function);
4897 : 76 : return -1;
4898 : 76 : }
4899 : :
4900 : 50276255 : if (builtin_typetail && TREE_VALUE (builtin_typetail) != void_type_node)
4901 : : {
4902 : : unsigned nargs = parmnum;
4903 : 616 : for (tree t = builtin_typetail; t; t = TREE_CHAIN (t))
4904 : 428 : ++nargs;
4905 : :
4906 : 188 : auto_diagnostic_group d;
4907 : 188 : if (warning_at (loc, OPT_Wbuiltin_declaration_mismatch,
4908 : : "too few arguments to built-in function %qE "
4909 : : "expecting %u", function, nargs - 1))
4910 : 173 : inform_declaration (fundecl, function);
4911 : 188 : }
4912 : :
4913 : 49625130 : return error_args ? -1 : (int) parmnum;
4914 : : }
4915 : :
4916 : : /* This is the entry point used by the parser to build unary operators
4917 : : in the input. CODE, a tree_code, specifies the unary operator, and
4918 : : ARG is the operand. For unary plus, the C parser currently uses
4919 : : CONVERT_EXPR for code.
4920 : :
4921 : : LOC is the location to use for the tree generated.
4922 : : */
4923 : :
4924 : : struct c_expr
4925 : 8116812 : parser_build_unary_op (location_t loc, enum tree_code code, struct c_expr arg)
4926 : : {
4927 : 8116812 : struct c_expr result;
4928 : :
4929 : 8116812 : result.original_code = code;
4930 : 8116812 : result.original_type = NULL;
4931 : 8116812 : result.m_decimal = 0;
4932 : :
4933 : 8116812 : if (reject_gcc_builtin (arg.value))
4934 : : {
4935 : 2 : result.value = error_mark_node;
4936 : : }
4937 : : else
4938 : : {
4939 : 8116810 : result.value = build_unary_op (loc, code, arg.value, false);
4940 : :
4941 : 8116810 : if (TREE_OVERFLOW_P (result.value) && !TREE_OVERFLOW_P (arg.value))
4942 : 5 : overflow_warning (loc, result.value, arg.value);
4943 : : }
4944 : :
4945 : : /* We are typically called when parsing a prefix token at LOC acting on
4946 : : ARG. Reflect this by updating the source range of the result to
4947 : : start at LOC and end at the end of ARG. */
4948 : 8116812 : set_c_expr_source_range (&result,
4949 : : loc, arg.get_finish ());
4950 : :
4951 : 8116812 : return result;
4952 : : }
4953 : :
4954 : : /* Returns true if TYPE is a character type, *not* including wchar_t. */
4955 : :
4956 : : bool
4957 : 1265020 : char_type_p (tree type)
4958 : : {
4959 : 1265020 : return (type == char_type_node
4960 : 976639 : || type == unsigned_char_type_node
4961 : 941790 : || type == signed_char_type_node
4962 : 940943 : || type == char16_type_node
4963 : 1988336 : || type == char32_type_node);
4964 : : }
4965 : :
4966 : : /* This is the entry point used by the parser to build binary operators
4967 : : in the input. CODE, a tree_code, specifies the binary operator, and
4968 : : ARG1 and ARG2 are the operands. In addition to constructing the
4969 : : expression, we check for operands that were written with other binary
4970 : : operators in a way that is likely to confuse the user.
4971 : :
4972 : : LOCATION is the location of the binary operator. */
4973 : :
4974 : : struct c_expr
4975 : 9285630 : parser_build_binary_op (location_t location, enum tree_code code,
4976 : : struct c_expr arg1, struct c_expr arg2)
4977 : : {
4978 : 9285630 : struct c_expr result;
4979 : 9285630 : result.m_decimal = 0;
4980 : :
4981 : 9285630 : enum tree_code code1 = arg1.original_code;
4982 : 9285630 : enum tree_code code2 = arg2.original_code;
4983 : 9285630 : tree type1 = (arg1.original_type
4984 : 9285630 : ? arg1.original_type
4985 : 5960953 : : TREE_TYPE (arg1.value));
4986 : 9285630 : tree type2 = (arg2.original_type
4987 : 9285630 : ? arg2.original_type
4988 : 6850788 : : TREE_TYPE (arg2.value));
4989 : :
4990 : 9285630 : result.value = build_binary_op (location, code,
4991 : : arg1.value, arg2.value, true);
4992 : 9285629 : result.original_code = code;
4993 : 9285629 : result.original_type = NULL;
4994 : 9285629 : result.m_decimal = 0;
4995 : :
4996 : 9285629 : if (TREE_CODE (result.value) == ERROR_MARK)
4997 : : {
4998 : 1297 : set_c_expr_source_range (&result,
4999 : : arg1.get_start (),
5000 : : arg2.get_finish ());
5001 : 1297 : return result;
5002 : : }
5003 : :
5004 : 9284332 : if (location != UNKNOWN_LOCATION)
5005 : 9284332 : protected_set_expr_location (result.value, location);
5006 : :
5007 : 9284332 : set_c_expr_source_range (&result,
5008 : : arg1.get_start (),
5009 : : arg2.get_finish ());
5010 : :
5011 : : /* Check for cases such as x+y<<z which users are likely
5012 : : to misinterpret. */
5013 : 9284332 : if (warn_parentheses)
5014 : 2002735 : warn_about_parentheses (location, code, code1, arg1.value, code2,
5015 : : arg2.value);
5016 : :
5017 : 9284332 : if (warn_logical_op)
5018 : 340 : warn_logical_operator (location, code, TREE_TYPE (result.value),
5019 : : code1, arg1.value, code2, arg2.value);
5020 : :
5021 : 9284332 : if (warn_tautological_compare)
5022 : : {
5023 : 2001248 : tree lhs = arg1.value;
5024 : 2001248 : tree rhs = arg2.value;
5025 : 2001248 : if (TREE_CODE (lhs) == C_MAYBE_CONST_EXPR)
5026 : : {
5027 : 2 : if (C_MAYBE_CONST_EXPR_PRE (lhs) != NULL_TREE
5028 : 2 : && TREE_SIDE_EFFECTS (C_MAYBE_CONST_EXPR_PRE (lhs)))
5029 : : lhs = NULL_TREE;
5030 : : else
5031 : 2 : lhs = C_MAYBE_CONST_EXPR_EXPR (lhs);
5032 : : }
5033 : 2001248 : if (TREE_CODE (rhs) == C_MAYBE_CONST_EXPR)
5034 : : {
5035 : 12 : if (C_MAYBE_CONST_EXPR_PRE (rhs) != NULL_TREE
5036 : 12 : && TREE_SIDE_EFFECTS (C_MAYBE_CONST_EXPR_PRE (rhs)))
5037 : : rhs = NULL_TREE;
5038 : : else
5039 : 12 : rhs = C_MAYBE_CONST_EXPR_EXPR (rhs);
5040 : : }
5041 : 2001248 : if (lhs != NULL_TREE && rhs != NULL_TREE)
5042 : 2001248 : warn_tautological_cmp (location, code, lhs, rhs);
5043 : : }
5044 : :
5045 : 9284332 : if (warn_logical_not_paren
5046 : 2001331 : && TREE_CODE_CLASS (code) == tcc_comparison
5047 : 405125 : && code1 == TRUTH_NOT_EXPR
5048 : 405125 : && code2 != TRUTH_NOT_EXPR
5049 : : /* Avoid warning for !!x == y. */
5050 : 9284458 : && (TREE_CODE (arg1.value) != NE_EXPR
5051 : 19 : || !integer_zerop (TREE_OPERAND (arg1.value, 1))))
5052 : : {
5053 : : /* Avoid warning for !b == y where b has _Bool type. */
5054 : 107 : tree t = integer_zero_node;
5055 : 107 : if (TREE_CODE (arg1.value) == EQ_EXPR
5056 : 98 : && integer_zerop (TREE_OPERAND (arg1.value, 1))
5057 : 205 : && TREE_TYPE (TREE_OPERAND (arg1.value, 0)) == integer_type_node)
5058 : : {
5059 : 90 : t = TREE_OPERAND (arg1.value, 0);
5060 : 199 : do
5061 : : {
5062 : 199 : if (TREE_TYPE (t) != integer_type_node)
5063 : : break;
5064 : 180 : if (TREE_CODE (t) == C_MAYBE_CONST_EXPR)
5065 : 90 : t = C_MAYBE_CONST_EXPR_EXPR (t);
5066 : 90 : else if (CONVERT_EXPR_P (t))
5067 : 19 : t = TREE_OPERAND (t, 0);
5068 : : else
5069 : : break;
5070 : : }
5071 : : while (1);
5072 : : }
5073 : 107 : if (!C_BOOLEAN_TYPE_P (TREE_TYPE (t)))
5074 : 88 : warn_logical_not_parentheses (location, code, arg1.value, arg2.value);
5075 : : }
5076 : :
5077 : : /* Warn about comparisons against string literals, with the exception
5078 : : of testing for equality or inequality of a string literal with NULL. */
5079 : 9284332 : if (code == EQ_EXPR || code == NE_EXPR)
5080 : : {
5081 : 1163751 : if ((code1 == STRING_CST
5082 : 16 : && !integer_zerop (tree_strip_nop_conversions (arg2.value)))
5083 : 1163762 : || (code2 == STRING_CST
5084 : 39 : && !integer_zerop (tree_strip_nop_conversions (arg1.value))))
5085 : 36 : warning_at (location, OPT_Waddress,
5086 : : "comparison with string literal results in unspecified behavior");
5087 : : /* Warn for ptr == '\0', it's likely that it should've been ptr[0]. */
5088 : 1163751 : if (POINTER_TYPE_P (type1)
5089 : 90386 : && null_pointer_constant_p (arg2.value)
5090 : 1184698 : && char_type_p (type2))
5091 : : {
5092 : 18 : auto_diagnostic_group d;
5093 : 18 : if (warning_at (location, OPT_Wpointer_compare,
5094 : : "comparison between pointer and zero character "
5095 : : "constant"))
5096 : 10 : inform (arg1.get_start (),
5097 : : "did you mean to dereference the pointer?");
5098 : 18 : }
5099 : 1163733 : else if (POINTER_TYPE_P (type2)
5100 : 87718 : && null_pointer_constant_p (arg1.value)
5101 : 1163995 : && char_type_p (type1))
5102 : : {
5103 : 10 : auto_diagnostic_group d;
5104 : 10 : if (warning_at (location, OPT_Wpointer_compare,
5105 : : "comparison between pointer and zero character "
5106 : : "constant"))
5107 : 10 : inform (arg2.get_start (),
5108 : : "did you mean to dereference the pointer?");
5109 : 10 : }
5110 : : }
5111 : 8120581 : else if (TREE_CODE_CLASS (code) == tcc_comparison
5112 : 991378 : && (code1 == STRING_CST || code2 == STRING_CST))
5113 : 0 : warning_at (location, OPT_Waddress,
5114 : : "comparison with string literal results in unspecified "
5115 : : "behavior");
5116 : :
5117 : 9284332 : if (warn_zero_as_null_pointer_constant
5118 : 18 : && c_inhibit_evaluation_warnings == 0
5119 : 18 : && TREE_CODE_CLASS (code) == tcc_comparison)
5120 : : {
5121 : 18 : if ((TREE_CODE (type1) == POINTER_TYPE
5122 : 14 : || TREE_CODE (type1) == NULLPTR_TYPE)
5123 : 6 : && TREE_CODE (type2) == INTEGER_TYPE
5124 : 24 : && null_pointer_constant_p (arg2.value))
5125 : 6 : warning_at (arg2.get_location(), OPT_Wzero_as_null_pointer_constant,
5126 : : "zero as null pointer constant");
5127 : :
5128 : 18 : if ((TREE_CODE (type2) == POINTER_TYPE
5129 : 12 : || TREE_CODE (type2) == NULLPTR_TYPE)
5130 : 8 : && TREE_CODE (type1) == INTEGER_TYPE
5131 : 26 : && null_pointer_constant_p (arg1.value))
5132 : 8 : warning_at (arg1.get_location(), OPT_Wzero_as_null_pointer_constant,
5133 : : "zero as null pointer constant");
5134 : : }
5135 : :
5136 : 9284332 : if (warn_array_compare
5137 : 2001086 : && TREE_CODE_CLASS (code) == tcc_comparison
5138 : 404910 : && TREE_CODE (type1) == ARRAY_TYPE
5139 : 38 : && TREE_CODE (type2) == ARRAY_TYPE)
5140 : 15 : do_warn_array_compare (location, code, arg1.value, arg2.value);
5141 : :
5142 : 2170054 : if (TREE_OVERFLOW_P (result.value)
5143 : 299 : && !TREE_OVERFLOW_P (arg1.value)
5144 : 9284624 : && !TREE_OVERFLOW_P (arg2.value))
5145 : 249 : overflow_warning (location, result.value);
5146 : :
5147 : : /* Warn about comparisons of different enum types. */
5148 : 9284331 : if (warn_enum_compare
5149 : 2021023 : && TREE_CODE_CLASS (code) == tcc_comparison
5150 : 409335 : && TREE_CODE (type1) == ENUMERAL_TYPE
5151 : 7038 : && TREE_CODE (type2) == ENUMERAL_TYPE
5152 : 9291307 : && TYPE_MAIN_VARIANT (type1) != TYPE_MAIN_VARIANT (type2))
5153 : 2 : warning_at (location, OPT_Wenum_compare,
5154 : : "comparison between %qT and %qT",
5155 : : type1, type2);
5156 : :
5157 : 9284331 : if (warn_xor_used_as_pow
5158 : 9284331 : && code == BIT_XOR_EXPR
5159 : 76737 : && arg1.m_decimal
5160 : 722 : && arg2.m_decimal)
5161 : 427 : check_for_xor_used_as_pow (arg1.get_location (), arg1.value,
5162 : : location,
5163 : : arg2.get_location (), arg2.value);
5164 : :
5165 : : return result;
5166 : : }
5167 : :
5168 : : /* Return a tree for the difference of pointers OP0 and OP1.
5169 : : The resulting tree has type ptrdiff_t. If POINTER_SUBTRACT sanitization is
5170 : : enabled, assign to INSTRUMENT_EXPR call to libsanitizer. */
5171 : :
5172 : : static tree
5173 : 3618 : pointer_diff (location_t loc, tree op0, tree op1, tree *instrument_expr)
5174 : : {
5175 : 3618 : tree restype = ptrdiff_type_node;
5176 : 3618 : tree result, inttype;
5177 : :
5178 : 3618 : addr_space_t as0 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (op0)));
5179 : 3618 : addr_space_t as1 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (op1)));
5180 : 3618 : tree target_type = TREE_TYPE (TREE_TYPE (op0));
5181 : 3618 : tree orig_op0 = op0;
5182 : 3618 : tree orig_op1 = op1;
5183 : :
5184 : : /* If the operands point into different address spaces, we need to
5185 : : explicitly convert them to pointers into the common address space
5186 : : before we can subtract the numerical address values. */
5187 : 3618 : if (as0 != as1)
5188 : : {
5189 : 0 : addr_space_t as_common;
5190 : 0 : tree common_type;
5191 : :
5192 : : /* Determine the common superset address space. This is guaranteed
5193 : : to exist because the caller verified that comp_target_types
5194 : : returned non-zero. */
5195 : 0 : if (!addr_space_superset (as0, as1, &as_common))
5196 : 0 : gcc_unreachable ();
5197 : :
5198 : 0 : common_type = common_pointer_type (TREE_TYPE (op0), TREE_TYPE (op1), NULL_TREE);
5199 : 0 : op0 = convert (common_type, op0);
5200 : 0 : op1 = convert (common_type, op1);
5201 : : }
5202 : :
5203 : : /* Determine integer type result of the subtraction. This will usually
5204 : : be the same as the result type (ptrdiff_t), but may need to be a wider
5205 : : type if pointers for the address space are wider than ptrdiff_t. */
5206 : 3618 : if (TYPE_PRECISION (restype) < TYPE_PRECISION (TREE_TYPE (op0)))
5207 : 0 : inttype = c_common_type_for_size (TYPE_PRECISION (TREE_TYPE (op0)), 0);
5208 : : else
5209 : : inttype = restype;
5210 : :
5211 : 3618 : if (VOID_TYPE_P (target_type))
5212 : 135 : pedwarn (loc, OPT_Wpointer_arith,
5213 : : "pointer of type %<void *%> used in subtraction");
5214 : 3618 : if (TREE_CODE (target_type) == FUNCTION_TYPE)
5215 : 4 : pedwarn (loc, OPT_Wpointer_arith,
5216 : : "pointer to a function used in subtraction");
5217 : :
5218 : 3618 : if (current_function_decl != NULL_TREE
5219 : 3618 : && sanitize_flags_p (SANITIZE_POINTER_SUBTRACT))
5220 : : {
5221 : 70 : op0 = save_expr (c_fully_fold (op0, false, NULL));
5222 : 70 : op1 = save_expr (c_fully_fold (op1, false, NULL));
5223 : :
5224 : 70 : tree tt = builtin_decl_explicit (BUILT_IN_ASAN_POINTER_SUBTRACT);
5225 : 70 : *instrument_expr = build_call_expr_loc (loc, tt, 2, op0, op1);
5226 : : }
5227 : :
5228 : : /* First do the subtraction, then build the divide operator
5229 : : and only convert at the very end.
5230 : : Do not do default conversions in case restype is a short type. */
5231 : :
5232 : : /* POINTER_DIFF_EXPR requires a signed integer type of the same size as
5233 : : pointers. If some platform cannot provide that, or has a larger
5234 : : ptrdiff_type to support differences larger than half the address
5235 : : space, cast the pointers to some larger integer type and do the
5236 : : computations in that type. */
5237 : 3618 : if (TYPE_PRECISION (inttype) > TYPE_PRECISION (TREE_TYPE (op0)))
5238 : 0 : op0 = build_binary_op (loc, MINUS_EXPR, convert (inttype, op0),
5239 : : convert (inttype, op1), false);
5240 : : else
5241 : : {
5242 : : /* Cast away qualifiers. */
5243 : 3618 : op0 = convert (c_common_type (TREE_TYPE (op0), TREE_TYPE (op0)), op0);
5244 : 3618 : op1 = convert (c_common_type (TREE_TYPE (op1), TREE_TYPE (op1)), op1);
5245 : 3618 : op0 = build2_loc (loc, POINTER_DIFF_EXPR, inttype, op0, op1);
5246 : : }
5247 : :
5248 : : /* This generates an error if op1 is pointer to incomplete type. */
5249 : 3618 : if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (orig_op1))))
5250 : 4 : error_at (loc, "arithmetic on pointer to an incomplete type");
5251 : 3614 : else if (verify_type_context (loc, TCTX_POINTER_ARITH,
5252 : 3614 : TREE_TYPE (TREE_TYPE (orig_op0))))
5253 : 7228 : verify_type_context (loc, TCTX_POINTER_ARITH,
5254 : 3614 : TREE_TYPE (TREE_TYPE (orig_op1)));
5255 : :
5256 : 3618 : op1 = c_size_in_bytes (target_type);
5257 : :
5258 : 3618 : if (pointer_to_zero_sized_aggr_p (TREE_TYPE (orig_op1)))
5259 : 4 : error_at (loc, "arithmetic on pointer to an empty aggregate");
5260 : :
5261 : : /* Divide by the size, in easiest possible way. */
5262 : 3618 : result = fold_build2_loc (loc, EXACT_DIV_EXPR, inttype,
5263 : : op0, convert (inttype, op1));
5264 : :
5265 : : /* Convert to final result type if necessary. */
5266 : 3618 : return convert (restype, result);
5267 : : }
5268 : :
5269 : : /* Expand atomic compound assignments into an appropriate sequence as
5270 : : specified by the C11 standard section 6.5.16.2.
5271 : :
5272 : : _Atomic T1 E1
5273 : : T2 E2
5274 : : E1 op= E2
5275 : :
5276 : : This sequence is used for all types for which these operations are
5277 : : supported.
5278 : :
5279 : : In addition, built-in versions of the 'fe' prefixed routines may
5280 : : need to be invoked for floating point (real, complex or vector) when
5281 : : floating-point exceptions are supported. See 6.5.16.2 footnote 113.
5282 : :
5283 : : T1 newval;
5284 : : T1 old;
5285 : : T1 *addr
5286 : : T2 val
5287 : : fenv_t fenv
5288 : :
5289 : : addr = &E1;
5290 : : val = (E2);
5291 : : __atomic_load (addr, &old, SEQ_CST);
5292 : : feholdexcept (&fenv);
5293 : : loop:
5294 : : newval = old op val;
5295 : : if (__atomic_compare_exchange_strong (addr, &old, &newval, SEQ_CST,
5296 : : SEQ_CST))
5297 : : goto done;
5298 : : feclearexcept (FE_ALL_EXCEPT);
5299 : : goto loop:
5300 : : done:
5301 : : feupdateenv (&fenv);
5302 : :
5303 : : The compiler will issue the __atomic_fetch_* built-in when possible,
5304 : : otherwise it will generate the generic form of the atomic operations.
5305 : : This requires temp(s) and has their address taken. The atomic processing
5306 : : is smart enough to figure out when the size of an object can utilize
5307 : : a lock-free version, and convert the built-in call to the appropriate
5308 : : lock-free routine. The optimizers will then dispose of any temps that
5309 : : are no longer required, and lock-free implementations are utilized as
5310 : : long as there is target support for the required size.
5311 : :
5312 : : If the operator is NOP_EXPR, then this is a simple assignment, and
5313 : : an __atomic_store is issued to perform the assignment rather than
5314 : : the above loop. */
5315 : :
5316 : : /* Build an atomic assignment at LOC, expanding into the proper
5317 : : sequence to store LHS MODIFYCODE= RHS. Return a value representing
5318 : : the result of the operation, unless RETURN_OLD_P, in which case
5319 : : return the old value of LHS (this is only for postincrement and
5320 : : postdecrement). */
5321 : :
5322 : : static tree
5323 : 30425 : build_atomic_assign (location_t loc, tree lhs, enum tree_code modifycode,
5324 : : tree rhs, bool return_old_p)
5325 : : {
5326 : 30425 : tree fndecl, func_call;
5327 : 30425 : vec<tree, va_gc> *params;
5328 : 30425 : tree val, nonatomic_lhs_type, nonatomic_rhs_type, newval, newval_addr;
5329 : 30425 : tree old, old_addr;
5330 : 30425 : tree compound_stmt = NULL_TREE;
5331 : 30425 : tree stmt, goto_stmt;
5332 : 30425 : tree loop_label, loop_decl, done_label, done_decl;
5333 : :
5334 : 30425 : tree lhs_type = TREE_TYPE (lhs);
5335 : 30425 : tree lhs_addr = build_unary_op (loc, ADDR_EXPR, lhs, false);
5336 : 30425 : tree seq_cst = build_int_cst (integer_type_node, MEMMODEL_SEQ_CST);
5337 : 30425 : tree rhs_semantic_type = TREE_TYPE (rhs);
5338 : 30425 : tree nonatomic_rhs_semantic_type;
5339 : 30425 : tree rhs_type;
5340 : :
5341 : 30425 : gcc_assert (TYPE_ATOMIC (lhs_type));
5342 : :
5343 : 30425 : if (return_old_p)
5344 : 2313 : gcc_assert (modifycode == PLUS_EXPR || modifycode == MINUS_EXPR);
5345 : :
5346 : : /* Allocate enough vector items for a compare_exchange. */
5347 : 30425 : vec_alloc (params, 6);
5348 : :
5349 : : /* Create a compound statement to hold the sequence of statements
5350 : : with a loop. */
5351 : 30425 : if (modifycode != NOP_EXPR)
5352 : : {
5353 : 19954 : compound_stmt = c_begin_compound_stmt (false);
5354 : :
5355 : : /* For consistency with build_modify_expr on non-_Atomic,
5356 : : mark the lhs as read. Also, it would be very hard to match
5357 : : such expressions in mark_exp_read. */
5358 : 19954 : mark_exp_read (lhs);
5359 : : }
5360 : :
5361 : : /* Remove any excess precision (which is only present here in the
5362 : : case of compound assignments). */
5363 : 30425 : if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
5364 : : {
5365 : 0 : gcc_assert (modifycode != NOP_EXPR);
5366 : 0 : rhs = TREE_OPERAND (rhs, 0);
5367 : : }
5368 : 30425 : rhs_type = TREE_TYPE (rhs);
5369 : :
5370 : : /* Fold the RHS if it hasn't already been folded. */
5371 : 30425 : if (modifycode != NOP_EXPR)
5372 : 19954 : rhs = c_fully_fold (rhs, false, NULL);
5373 : :
5374 : : /* Remove the qualifiers for the rest of the expressions and create
5375 : : the VAL temp variable to hold the RHS. */
5376 : 30425 : nonatomic_lhs_type = build_qualified_type (lhs_type, TYPE_UNQUALIFIED);
5377 : 30425 : nonatomic_rhs_type = build_qualified_type (rhs_type, TYPE_UNQUALIFIED);
5378 : 30425 : nonatomic_rhs_semantic_type = build_qualified_type (rhs_semantic_type,
5379 : : TYPE_UNQUALIFIED);
5380 : 30425 : val = create_tmp_var_raw (nonatomic_rhs_type);
5381 : 30425 : TREE_ADDRESSABLE (val) = 1;
5382 : 30425 : suppress_warning (val);
5383 : 30425 : rhs = build4 (TARGET_EXPR, nonatomic_rhs_type, val, rhs, NULL_TREE,
5384 : : NULL_TREE);
5385 : 30425 : TREE_SIDE_EFFECTS (rhs) = 1;
5386 : 30425 : SET_EXPR_LOCATION (rhs, loc);
5387 : 30425 : if (modifycode != NOP_EXPR)
5388 : 19954 : add_stmt (rhs);
5389 : :
5390 : : /* NOP_EXPR indicates it's a straight store of the RHS. Simply issue
5391 : : an atomic_store. */
5392 : 30425 : if (modifycode == NOP_EXPR)
5393 : : {
5394 : 10471 : compound_stmt = rhs;
5395 : : /* Build __atomic_store (&lhs, &val, SEQ_CST) */
5396 : 10471 : rhs = build_unary_op (loc, ADDR_EXPR, val, false);
5397 : 10471 : fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_STORE);
5398 : 10471 : params->quick_push (lhs_addr);
5399 : 10471 : params->quick_push (rhs);
5400 : 10471 : params->quick_push (seq_cst);
5401 : 10471 : func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
5402 : :
5403 : 10471 : compound_stmt = build2 (COMPOUND_EXPR, void_type_node,
5404 : : compound_stmt, func_call);
5405 : :
5406 : : /* VAL is the value which was stored, return a COMPOUND_STMT of
5407 : : the statement and that value. */
5408 : 10471 : return build2 (COMPOUND_EXPR, nonatomic_lhs_type, compound_stmt, val);
5409 : : }
5410 : :
5411 : : /* Attempt to implement the atomic operation as an __atomic_fetch_* or
5412 : : __atomic_*_fetch built-in rather than a CAS loop. atomic_bool type
5413 : : isn't applicable for such builtins. ??? Do we want to handle enums? */
5414 : 19954 : if ((TREE_CODE (lhs_type) == INTEGER_TYPE || POINTER_TYPE_P (lhs_type))
5415 : 13941 : && TREE_CODE (rhs_type) == INTEGER_TYPE)
5416 : : {
5417 : 11713 : built_in_function fncode;
5418 : 11713 : switch (modifycode)
5419 : : {
5420 : 3075 : case PLUS_EXPR:
5421 : 3075 : case POINTER_PLUS_EXPR:
5422 : 2124 : fncode = (return_old_p
5423 : 3075 : ? BUILT_IN_ATOMIC_FETCH_ADD_N
5424 : : : BUILT_IN_ATOMIC_ADD_FETCH_N);
5425 : : break;
5426 : 2889 : case MINUS_EXPR:
5427 : 2094 : fncode = (return_old_p
5428 : 2889 : ? BUILT_IN_ATOMIC_FETCH_SUB_N
5429 : : : BUILT_IN_ATOMIC_SUB_FETCH_N);
5430 : : break;
5431 : 609 : case BIT_AND_EXPR:
5432 : 609 : fncode = (return_old_p
5433 : 609 : ? BUILT_IN_ATOMIC_FETCH_AND_N
5434 : : : BUILT_IN_ATOMIC_AND_FETCH_N);
5435 : : break;
5436 : 609 : case BIT_IOR_EXPR:
5437 : 609 : fncode = (return_old_p
5438 : 609 : ? BUILT_IN_ATOMIC_FETCH_OR_N
5439 : : : BUILT_IN_ATOMIC_OR_FETCH_N);
5440 : : break;
5441 : 609 : case BIT_XOR_EXPR:
5442 : 609 : fncode = (return_old_p
5443 : 609 : ? BUILT_IN_ATOMIC_FETCH_XOR_N
5444 : : : BUILT_IN_ATOMIC_XOR_FETCH_N);
5445 : : break;
5446 : 3922 : default:
5447 : 3922 : goto cas_loop;
5448 : : }
5449 : :
5450 : : /* We can only use "_1" through "_16" variants of the atomic fetch
5451 : : built-ins. */
5452 : 7791 : unsigned HOST_WIDE_INT size = tree_to_uhwi (TYPE_SIZE_UNIT (lhs_type));
5453 : 7791 : if (size != 1 && size != 2 && size != 4 && size != 8 && size != 16)
5454 : 0 : goto cas_loop;
5455 : :
5456 : : /* If this is a pointer type, we need to multiply by the size of
5457 : : the pointer target type. */
5458 : 7791 : if (POINTER_TYPE_P (lhs_type))
5459 : : {
5460 : 1018 : if (!COMPLETE_TYPE_P (TREE_TYPE (lhs_type))
5461 : : /* ??? This would introduce -Wdiscarded-qualifiers
5462 : : warning: __atomic_fetch_* expect volatile void *
5463 : : type as the first argument. (Assignments between
5464 : : atomic and non-atomic objects are OK.) */
5465 : 1018 : || TYPE_RESTRICT (lhs_type))
5466 : 17 : goto cas_loop;
5467 : 1001 : tree sz = TYPE_SIZE_UNIT (TREE_TYPE (lhs_type));
5468 : 1001 : rhs = fold_build2_loc (loc, MULT_EXPR, ptrdiff_type_node,
5469 : : convert (ptrdiff_type_node, rhs),
5470 : : convert (ptrdiff_type_node, sz));
5471 : : }
5472 : :
5473 : : /* Build __atomic_fetch_* (&lhs, &val, SEQ_CST), or
5474 : : __atomic_*_fetch (&lhs, &val, SEQ_CST). */
5475 : 7774 : fndecl = builtin_decl_explicit (fncode);
5476 : 7774 : params->quick_push (lhs_addr);
5477 : 7774 : params->quick_push (rhs);
5478 : 7774 : params->quick_push (seq_cst);
5479 : 7774 : func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
5480 : :
5481 : 7774 : newval = create_tmp_var_raw (nonatomic_lhs_type);
5482 : 7774 : TREE_ADDRESSABLE (newval) = 1;
5483 : 7774 : suppress_warning (newval);
5484 : 7774 : rhs = build4 (TARGET_EXPR, nonatomic_lhs_type, newval, func_call,
5485 : : NULL_TREE, NULL_TREE);
5486 : 7774 : SET_EXPR_LOCATION (rhs, loc);
5487 : 7774 : add_stmt (rhs);
5488 : :
5489 : : /* Finish the compound statement. */
5490 : 7774 : compound_stmt = c_end_compound_stmt (loc, compound_stmt, false);
5491 : :
5492 : : /* NEWVAL is the value which was stored, return a COMPOUND_STMT of
5493 : : the statement and that value. */
5494 : 7774 : return build2 (COMPOUND_EXPR, nonatomic_lhs_type, compound_stmt, newval);
5495 : : }
5496 : :
5497 : 8241 : cas_loop:
5498 : : /* Create the variables and labels required for the op= form. */
5499 : 12180 : old = create_tmp_var_raw (nonatomic_lhs_type);
5500 : 12180 : old_addr = build_unary_op (loc, ADDR_EXPR, old, false);
5501 : 12180 : TREE_ADDRESSABLE (old) = 1;
5502 : 12180 : suppress_warning (old);
5503 : :
5504 : 12180 : newval = create_tmp_var_raw (nonatomic_lhs_type);
5505 : 12180 : newval_addr = build_unary_op (loc, ADDR_EXPR, newval, false);
5506 : 12180 : TREE_ADDRESSABLE (newval) = 1;
5507 : 12180 : suppress_warning (newval);
5508 : :
5509 : 12180 : loop_decl = create_artificial_label (loc);
5510 : 12180 : loop_label = build1 (LABEL_EXPR, void_type_node, loop_decl);
5511 : :
5512 : 12180 : done_decl = create_artificial_label (loc);
5513 : 12180 : done_label = build1 (LABEL_EXPR, void_type_node, done_decl);
5514 : :
5515 : : /* __atomic_load (addr, &old, SEQ_CST). */
5516 : 12180 : fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_LOAD);
5517 : 12180 : params->quick_push (lhs_addr);
5518 : 12180 : params->quick_push (old_addr);
5519 : 12180 : params->quick_push (seq_cst);
5520 : 12180 : func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
5521 : 12180 : old = build4 (TARGET_EXPR, nonatomic_lhs_type, old, func_call, NULL_TREE,
5522 : : NULL_TREE);
5523 : 12180 : add_stmt (old);
5524 : 12180 : params->truncate (0);
5525 : :
5526 : : /* Create the expressions for floating-point environment
5527 : : manipulation, if required. */
5528 : 12180 : bool need_fenv = (flag_trapping_math
5529 : 12180 : && (FLOAT_TYPE_P (lhs_type) || FLOAT_TYPE_P (rhs_type)));
5530 : 12180 : tree hold_call = NULL_TREE, clear_call = NULL_TREE, update_call = NULL_TREE;
5531 : 12180 : if (need_fenv)
5532 : 7054 : targetm.atomic_assign_expand_fenv (&hold_call, &clear_call, &update_call);
5533 : :
5534 : 12180 : if (hold_call)
5535 : 7054 : add_stmt (hold_call);
5536 : :
5537 : : /* loop: */
5538 : 12180 : add_stmt (loop_label);
5539 : :
5540 : : /* newval = old + val; */
5541 : 12180 : if (rhs_type != rhs_semantic_type)
5542 : 0 : val = build1 (EXCESS_PRECISION_EXPR, nonatomic_rhs_semantic_type, val);
5543 : 12180 : rhs = build_binary_op (loc, modifycode,
5544 : : convert_lvalue_to_rvalue (loc, old, true, true),
5545 : : val, true);
5546 : 12180 : if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
5547 : : {
5548 : 0 : tree eptype = TREE_TYPE (rhs);
5549 : 0 : rhs = c_fully_fold (TREE_OPERAND (rhs, 0), false, NULL);
5550 : 0 : rhs = build1 (EXCESS_PRECISION_EXPR, eptype, rhs);
5551 : : }
5552 : : else
5553 : 12180 : rhs = c_fully_fold (rhs, false, NULL);
5554 : 12180 : rhs = convert_for_assignment (loc, UNKNOWN_LOCATION, nonatomic_lhs_type,
5555 : : rhs, NULL_TREE, ic_assign, false, NULL_TREE,
5556 : : NULL_TREE, 0);
5557 : : /* The temporary variable for NEWVAL is only gimplified correctly (in
5558 : : particular, given a DECL_CONTEXT) if used in a TARGET_EXPR. To avoid
5559 : : subsequent ICEs in nested function processing after an error, ensure such
5560 : : a TARGET_EXPR is built even after an error. */
5561 : 12180 : if (rhs == error_mark_node)
5562 : 10 : rhs = old;
5563 : 12180 : rhs = build4 (TARGET_EXPR, nonatomic_lhs_type, newval, rhs, NULL_TREE,
5564 : : NULL_TREE);
5565 : 12180 : SET_EXPR_LOCATION (rhs, loc);
5566 : 12180 : add_stmt (rhs);
5567 : :
5568 : : /* if (__atomic_compare_exchange (addr, &old, &new, false, SEQ_CST, SEQ_CST))
5569 : : goto done; */
5570 : 12180 : fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_COMPARE_EXCHANGE);
5571 : 12180 : params->quick_push (lhs_addr);
5572 : 12180 : params->quick_push (old_addr);
5573 : 12180 : params->quick_push (newval_addr);
5574 : 12180 : params->quick_push (integer_zero_node);
5575 : 12180 : params->quick_push (seq_cst);
5576 : 12180 : params->quick_push (seq_cst);
5577 : 12180 : func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
5578 : :
5579 : 12180 : goto_stmt = build1 (GOTO_EXPR, void_type_node, done_decl);
5580 : 12180 : SET_EXPR_LOCATION (goto_stmt, loc);
5581 : :
5582 : 12180 : stmt = build3 (COND_EXPR, void_type_node, func_call, goto_stmt, NULL_TREE);
5583 : 12180 : SET_EXPR_LOCATION (stmt, loc);
5584 : 12180 : add_stmt (stmt);
5585 : :
5586 : 12180 : if (clear_call)
5587 : 7054 : add_stmt (clear_call);
5588 : :
5589 : : /* goto loop; */
5590 : 12180 : goto_stmt = build1 (GOTO_EXPR, void_type_node, loop_decl);
5591 : 12180 : SET_EXPR_LOCATION (goto_stmt, loc);
5592 : 12180 : add_stmt (goto_stmt);
5593 : :
5594 : : /* done: */
5595 : 12180 : add_stmt (done_label);
5596 : :
5597 : 12180 : if (update_call)
5598 : 7054 : add_stmt (update_call);
5599 : :
5600 : : /* Finish the compound statement. */
5601 : 12180 : compound_stmt = c_end_compound_stmt (loc, compound_stmt, false);
5602 : :
5603 : : /* NEWVAL is the value that was successfully stored, return a
5604 : : COMPOUND_EXPR of the statement and the appropriate value. */
5605 : 23787 : return build2 (COMPOUND_EXPR, nonatomic_lhs_type, compound_stmt,
5606 : 12180 : return_old_p ? old : newval);
5607 : : }
5608 : :
5609 : : /* Construct and perhaps optimize a tree representation
5610 : : for a unary operation. CODE, a tree_code, specifies the operation
5611 : : and XARG is the operand.
5612 : : For any CODE other than ADDR_EXPR, NOCONVERT suppresses the default
5613 : : promotions (such as from short to int).
5614 : : For ADDR_EXPR, the default promotions are not applied; NOCONVERT allows
5615 : : non-lvalues; this is only used to handle conversion of non-lvalue arrays
5616 : : to pointers in C99.
5617 : :
5618 : : LOCATION is the location of the operator. */
5619 : :
5620 : : tree
5621 : 60196235 : build_unary_op (location_t location, enum tree_code code, tree xarg,
5622 : : bool noconvert)
5623 : : {
5624 : : /* No default_conversion here. It causes trouble for ADDR_EXPR. */
5625 : 60196235 : tree arg = xarg;
5626 : 60196235 : tree argtype = NULL_TREE;
5627 : 60196235 : enum tree_code typecode;
5628 : 60196235 : tree val;
5629 : 60196235 : tree ret = error_mark_node;
5630 : 60196235 : tree eptype = NULL_TREE;
5631 : 60196235 : const char *invalid_op_diag;
5632 : 60196235 : bool int_operands;
5633 : :
5634 : 60196235 : int_operands = EXPR_INT_CONST_OPERANDS (xarg);
5635 : 6422122 : if (int_operands)
5636 : 6422122 : arg = remove_c_maybe_const_expr (arg);
5637 : :
5638 : 60196235 : if (code != ADDR_EXPR)
5639 : 8488821 : arg = require_complete_type (location, arg);
5640 : :
5641 : 60196235 : typecode = TREE_CODE (TREE_TYPE (arg));
5642 : 60196235 : if (typecode == ERROR_MARK)
5643 : 74 : return error_mark_node;
5644 : 60196161 : if (typecode == ENUMERAL_TYPE || typecode == BOOLEAN_TYPE)
5645 : 32006 : typecode = INTEGER_TYPE;
5646 : :
5647 : 120392322 : if ((invalid_op_diag
5648 : 60196161 : = targetm.invalid_unary_op (code, TREE_TYPE (xarg))))
5649 : : {
5650 : 0 : error_at (location, invalid_op_diag);
5651 : 0 : return error_mark_node;
5652 : : }
5653 : :
5654 : 60196161 : if (TREE_CODE (arg) == EXCESS_PRECISION_EXPR)
5655 : : {
5656 : 237 : eptype = TREE_TYPE (arg);
5657 : 237 : arg = TREE_OPERAND (arg, 0);
5658 : : }
5659 : :
5660 : 60196161 : switch (code)
5661 : : {
5662 : 28755 : case CONVERT_EXPR:
5663 : : /* This is used for unary plus, because a CONVERT_EXPR
5664 : : is enough to prevent anybody from looking inside for
5665 : : associativity, but won't generate any code. */
5666 : 28760 : if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
5667 : 8 : || typecode == FIXED_POINT_TYPE || typecode == COMPLEX_TYPE
5668 : 5 : || typecode == BITINT_TYPE
5669 : 5 : || gnu_vector_type_p (TREE_TYPE (arg))))
5670 : : {
5671 : 1 : error_at (location, "wrong type argument to unary plus");
5672 : 1 : return error_mark_node;
5673 : : }
5674 : 28754 : else if (!noconvert)
5675 : 28754 : arg = default_conversion (arg);
5676 : 28754 : arg = non_lvalue_loc (location, arg);
5677 : 28754 : break;
5678 : :
5679 : 6657546 : case NEGATE_EXPR:
5680 : 7103273 : if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
5681 : 482230 : || typecode == FIXED_POINT_TYPE || typecode == COMPLEX_TYPE
5682 : 450963 : || typecode == BITINT_TYPE
5683 : 445727 : || gnu_vector_type_p (TREE_TYPE (arg))))
5684 : : {
5685 : 1 : error_at (location, "wrong type argument to unary minus");
5686 : 1 : return error_mark_node;
5687 : : }
5688 : 6657545 : else if (!noconvert)
5689 : 6657539 : arg = default_conversion (arg);
5690 : : break;
5691 : :
5692 : 294291 : case BIT_NOT_EXPR:
5693 : : /* ~ works on integer types and non float vectors. */
5694 : 294291 : if (typecode == INTEGER_TYPE
5695 : 294291 : || typecode == BITINT_TYPE
5696 : 294291 : || (gnu_vector_type_p (TREE_TYPE (arg))
5697 : 2057 : && !VECTOR_FLOAT_TYPE_P (TREE_TYPE (arg))))
5698 : : {
5699 : : tree e = arg;
5700 : :
5701 : : /* Warn if the expression has boolean value. */
5702 : 293692 : while (TREE_CODE (e) == COMPOUND_EXPR)
5703 : 11 : e = TREE_OPERAND (e, 1);
5704 : :
5705 : 587348 : if ((C_BOOLEAN_TYPE_P (TREE_TYPE (arg))
5706 : 587348 : || truth_value_p (TREE_CODE (e))))
5707 : : {
5708 : 146 : auto_diagnostic_group d;
5709 : 146 : if (warning_at (location, OPT_Wbool_operation,
5710 : : "%<~%> on a boolean expression"))
5711 : : {
5712 : 12 : gcc_rich_location richloc (location);
5713 : 12 : richloc.add_fixit_insert_before (location, "!");
5714 : 12 : inform (&richloc, "did you mean to use logical not?");
5715 : 12 : }
5716 : 146 : }
5717 : 293681 : if (!noconvert)
5718 : 293678 : arg = default_conversion (arg);
5719 : : }
5720 : 610 : else if (typecode == COMPLEX_TYPE)
5721 : : {
5722 : 605 : code = CONJ_EXPR;
5723 : 605 : pedwarn (location, OPT_Wpedantic,
5724 : : "ISO C does not support %<~%> for complex conjugation");
5725 : 605 : if (!noconvert)
5726 : 605 : arg = default_conversion (arg);
5727 : : }
5728 : : else
5729 : : {
5730 : 5 : error_at (location, "wrong type argument to bit-complement");
5731 : 5 : return error_mark_node;
5732 : : }
5733 : : break;
5734 : :
5735 : 3 : case ABS_EXPR:
5736 : 3 : if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE))
5737 : : {
5738 : 0 : error_at (location, "wrong type argument to abs");
5739 : 0 : return error_mark_node;
5740 : : }
5741 : 3 : else if (!noconvert)
5742 : 0 : arg = default_conversion (arg);
5743 : : break;
5744 : :
5745 : 7 : case ABSU_EXPR:
5746 : 7 : if (!(typecode == INTEGER_TYPE))
5747 : : {
5748 : 0 : error_at (location, "wrong type argument to absu");
5749 : 0 : return error_mark_node;
5750 : : }
5751 : 7 : else if (!noconvert)
5752 : 0 : arg = default_conversion (arg);
5753 : : break;
5754 : :
5755 : 0 : case CONJ_EXPR:
5756 : : /* Conjugating a real value is a no-op, but allow it anyway. */
5757 : 0 : if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
5758 : : || typecode == COMPLEX_TYPE))
5759 : : {
5760 : 0 : error_at (location, "wrong type argument to conjugation");
5761 : 0 : return error_mark_node;
5762 : : }
5763 : 0 : else if (!noconvert)
5764 : 0 : arg = default_conversion (arg);
5765 : : break;
5766 : :
5767 : 375617 : case TRUTH_NOT_EXPR:
5768 : 375617 : if (typecode != INTEGER_TYPE && typecode != FIXED_POINT_TYPE
5769 : 7057 : && typecode != REAL_TYPE && typecode != POINTER_TYPE
5770 : 21 : && typecode != COMPLEX_TYPE && typecode != NULLPTR_TYPE
5771 : 18 : && typecode != BITINT_TYPE)
5772 : : {
5773 : 10 : error_at (location,
5774 : : "wrong type argument to unary exclamation mark");
5775 : 10 : return error_mark_node;
5776 : : }
5777 : 375607 : if (int_operands)
5778 : : {
5779 : 139833 : arg = c_objc_common_truthvalue_conversion (location, xarg);
5780 : 139833 : arg = remove_c_maybe_const_expr (arg);
5781 : : }
5782 : : else
5783 : 235774 : arg = c_objc_common_truthvalue_conversion (location, arg);
5784 : 375607 : ret = invert_truthvalue_loc (location, arg);
5785 : : /* If the TRUTH_NOT_EXPR has been folded, reset the location. */
5786 : 375607 : if (EXPR_P (ret) && EXPR_HAS_LOCATION (ret))
5787 : 235379 : location = EXPR_LOCATION (ret);
5788 : 375607 : goto return_build_unary_op;
5789 : :
5790 : 201159 : case REALPART_EXPR:
5791 : 201159 : case IMAGPART_EXPR:
5792 : 201159 : ret = build_real_imag_expr (location, code, arg);
5793 : 201159 : if (ret == error_mark_node)
5794 : : return error_mark_node;
5795 : 201151 : if (eptype && TREE_CODE (eptype) == COMPLEX_TYPE)
5796 : 2 : eptype = TREE_TYPE (eptype);
5797 : 201151 : goto return_build_unary_op;
5798 : :
5799 : 931400 : case PREINCREMENT_EXPR:
5800 : 931400 : case POSTINCREMENT_EXPR:
5801 : 931400 : case PREDECREMENT_EXPR:
5802 : 931400 : case POSTDECREMENT_EXPR:
5803 : :
5804 : 931400 : if (TREE_CODE (arg) == C_MAYBE_CONST_EXPR)
5805 : : {
5806 : 2 : tree inner = build_unary_op (location, code,
5807 : 2 : C_MAYBE_CONST_EXPR_EXPR (arg),
5808 : : noconvert);
5809 : 2 : if (inner == error_mark_node)
5810 : : return error_mark_node;
5811 : 4 : ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (inner),
5812 : 2 : C_MAYBE_CONST_EXPR_PRE (arg), inner);
5813 : 2 : gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (arg));
5814 : 2 : C_MAYBE_CONST_EXPR_NON_CONST (ret) = 1;
5815 : 2 : goto return_build_unary_op;
5816 : : }
5817 : :
5818 : : /* Complain about anything that is not a true lvalue. In
5819 : : Objective-C, skip this check for property_refs. */
5820 : 931398 : if (!objc_is_property_ref (arg)
5821 : 1862796 : && !lvalue_or_else (location,
5822 : 931398 : arg, ((code == PREINCREMENT_EXPR
5823 : 931398 : || code == POSTINCREMENT_EXPR)
5824 : : ? lv_increment
5825 : : : lv_decrement)))
5826 : 22 : return error_mark_node;
5827 : :
5828 : 931376 : if (warn_cxx_compat && TREE_CODE (TREE_TYPE (arg)) == ENUMERAL_TYPE)
5829 : : {
5830 : 4 : if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
5831 : 2 : warning_at (location, OPT_Wc___compat,
5832 : : "increment of enumeration value is invalid in C++");
5833 : : else
5834 : 2 : warning_at (location, OPT_Wc___compat,
5835 : : "decrement of enumeration value is invalid in C++");
5836 : : }
5837 : :
5838 : 931376 : if (C_BOOLEAN_TYPE_P (TREE_TYPE (arg)))
5839 : : {
5840 : 656 : if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
5841 : 328 : warning_at (location, OPT_Wbool_operation,
5842 : : "increment of a boolean expression");
5843 : : else
5844 : 328 : warning_at (location, OPT_Wbool_operation,
5845 : : "decrement of a boolean expression");
5846 : : }
5847 : :
5848 : : /* Ensure the argument is fully folded inside any SAVE_EXPR. */
5849 : 931376 : arg = c_fully_fold (arg, false, NULL, true);
5850 : :
5851 : 931376 : bool atomic_op;
5852 : 931376 : atomic_op = really_atomic_lvalue (arg);
5853 : :
5854 : : /* Increment or decrement the real part of the value,
5855 : : and don't change the imaginary part. */
5856 : 931376 : if (typecode == COMPLEX_TYPE)
5857 : : {
5858 : 57 : tree real, imag;
5859 : :
5860 : 57 : pedwarn_c23 (location, OPT_Wpedantic,
5861 : : "ISO C does not support %<++%> and %<--%> on complex "
5862 : : "types before C2Y");
5863 : :
5864 : 57 : if (!atomic_op)
5865 : : {
5866 : 53 : arg = stabilize_reference (arg);
5867 : 53 : real = build_unary_op (EXPR_LOCATION (arg), REALPART_EXPR, arg,
5868 : : true);
5869 : 53 : imag = build_unary_op (EXPR_LOCATION (arg), IMAGPART_EXPR, arg,
5870 : : true);
5871 : 53 : real = build_unary_op (EXPR_LOCATION (arg), code, real, true);
5872 : 53 : if (real == error_mark_node || imag == error_mark_node)
5873 : : return error_mark_node;
5874 : 53 : ret = build2 (COMPLEX_EXPR, TREE_TYPE (arg),
5875 : : real, imag);
5876 : 53 : goto return_build_unary_op;
5877 : : }
5878 : : }
5879 : :
5880 : : /* Report invalid types. */
5881 : :
5882 : 931323 : if (typecode != POINTER_TYPE && typecode != FIXED_POINT_TYPE
5883 : 701776 : && typecode != INTEGER_TYPE && typecode != REAL_TYPE
5884 : 151 : && typecode != COMPLEX_TYPE && typecode != BITINT_TYPE
5885 : 931372 : && !gnu_vector_type_p (TREE_TYPE (arg)))
5886 : : {
5887 : 5 : if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
5888 : 3 : error_at (location, "wrong type argument to increment");
5889 : : else
5890 : 2 : error_at (location, "wrong type argument to decrement");
5891 : :
5892 : 5 : return error_mark_node;
5893 : : }
5894 : :
5895 : 931318 : {
5896 : 931318 : tree inc;
5897 : :
5898 : 931318 : argtype = TREE_TYPE (arg);
5899 : :
5900 : : /* Compute the increment. */
5901 : :
5902 : 931318 : if (typecode == POINTER_TYPE)
5903 : : {
5904 : : /* If pointer target is an incomplete type,
5905 : : we just cannot know how to do the arithmetic. */
5906 : 229547 : if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (argtype)))
5907 : : {
5908 : 27 : if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
5909 : 17 : error_at (location,
5910 : : "increment of pointer to an incomplete type %qT",
5911 : 17 : TREE_TYPE (argtype));
5912 : : else
5913 : 10 : error_at (location,
5914 : : "decrement of pointer to an incomplete type %qT",
5915 : 10 : TREE_TYPE (argtype));
5916 : : }
5917 : 229520 : else if (TREE_CODE (TREE_TYPE (argtype)) == FUNCTION_TYPE
5918 : 229520 : || VOID_TYPE_P (TREE_TYPE (argtype)))
5919 : : {
5920 : 10 : if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
5921 : 6 : pedwarn (location, OPT_Wpointer_arith,
5922 : : "wrong type argument to increment");
5923 : : else
5924 : 4 : pedwarn (location, OPT_Wpointer_arith,
5925 : : "wrong type argument to decrement");
5926 : : }
5927 : : else
5928 : 459020 : verify_type_context (location, TCTX_POINTER_ARITH,
5929 : 229510 : TREE_TYPE (argtype));
5930 : :
5931 : 229547 : inc = c_size_in_bytes (TREE_TYPE (argtype));
5932 : 229547 : inc = convert_to_ptrofftype_loc (location, inc);
5933 : : }
5934 : 701771 : else if (FRACT_MODE_P (TYPE_MODE (argtype)))
5935 : : {
5936 : : /* For signed fract types, we invert ++ to -- or
5937 : : -- to ++, and change inc from 1 to -1, because
5938 : : it is not possible to represent 1 in signed fract constants.
5939 : : For unsigned fract types, the result always overflows and
5940 : : we get an undefined (original) or the maximum value. */
5941 : 0 : if (code == PREINCREMENT_EXPR)
5942 : : code = PREDECREMENT_EXPR;
5943 : : else if (code == PREDECREMENT_EXPR)
5944 : : code = PREINCREMENT_EXPR;
5945 : : else if (code == POSTINCREMENT_EXPR)
5946 : : code = POSTDECREMENT_EXPR;
5947 : : else /* code == POSTDECREMENT_EXPR */
5948 : 0 : code = POSTINCREMENT_EXPR;
5949 : :
5950 : 0 : inc = integer_minus_one_node;
5951 : 0 : inc = convert (argtype, inc);
5952 : : }
5953 : : else
5954 : : {
5955 : 701727 : inc = VECTOR_TYPE_P (argtype)
5956 : 701771 : ? build_one_cst (argtype)
5957 : : : integer_one_node;
5958 : 701771 : inc = convert (argtype, inc);
5959 : : }
5960 : :
5961 : : /* If 'arg' is an Objective-C PROPERTY_REF expression, then we
5962 : : need to ask Objective-C to build the increment or decrement
5963 : : expression for it. */
5964 : 931318 : if (objc_is_property_ref (arg))
5965 : 0 : return objc_build_incr_expr_for_property_ref (location, code,
5966 : 20 : arg, inc);
5967 : :
5968 : : /* Report a read-only lvalue. */
5969 : 931318 : if (TYPE_READONLY (argtype))
5970 : : {
5971 : 20 : readonly_error (location, arg,
5972 : 20 : ((code == PREINCREMENT_EXPR
5973 : 20 : || code == POSTINCREMENT_EXPR)
5974 : : ? lv_increment : lv_decrement));
5975 : 20 : return error_mark_node;
5976 : : }
5977 : 931298 : else if (TREE_READONLY (arg))
5978 : 4 : readonly_warning (arg,
5979 : 4 : ((code == PREINCREMENT_EXPR
5980 : 4 : || code == POSTINCREMENT_EXPR)
5981 : : ? lv_increment : lv_decrement));
5982 : :
5983 : : /* If the argument is atomic, use the special code sequences for
5984 : : atomic compound assignment. */
5985 : 931298 : if (atomic_op)
5986 : : {
5987 : 4469 : arg = stabilize_reference (arg);
5988 : 8938 : ret = build_atomic_assign (location, arg,
5989 : 4469 : ((code == PREINCREMENT_EXPR
5990 : 4469 : || code == POSTINCREMENT_EXPR)
5991 : : ? PLUS_EXPR
5992 : : : MINUS_EXPR),
5993 : 4469 : (FRACT_MODE_P (TYPE_MODE (argtype))
5994 : : ? inc
5995 : : : integer_one_node),
5996 : : (code == POSTINCREMENT_EXPR
5997 : 4469 : || code == POSTDECREMENT_EXPR));
5998 : 931298 : goto return_build_unary_op;
5999 : : }
6000 : :
6001 : 926829 : tree true_res;
6002 : 926829 : if (c_hardbool_type_attr (TREE_TYPE (arg), NULL, &true_res))
6003 : : {
6004 : 364 : tree larg = stabilize_reference (arg);
6005 : 364 : tree sarg = save_expr (larg);
6006 : 364 : switch (code)
6007 : : {
6008 : 91 : case PREINCREMENT_EXPR:
6009 : 91 : val = build2 (MODIFY_EXPR, TREE_TYPE (larg), larg, true_res);
6010 : 91 : val = build2 (COMPOUND_EXPR, TREE_TYPE (larg), sarg, val);
6011 : 91 : break;
6012 : 91 : case POSTINCREMENT_EXPR:
6013 : 91 : val = build2 (MODIFY_EXPR, TREE_TYPE (larg), larg, true_res);
6014 : 91 : val = build2 (COMPOUND_EXPR, TREE_TYPE (larg), val, sarg);
6015 : 91 : val = build2 (COMPOUND_EXPR, TREE_TYPE (larg), sarg, val);
6016 : 91 : break;
6017 : 91 : case PREDECREMENT_EXPR:
6018 : 91 : {
6019 : 91 : tree rarg = convert_lvalue_to_rvalue (location, sarg,
6020 : : true, true);
6021 : 91 : rarg = invert_truthvalue_loc (location, rarg);
6022 : 91 : rarg = convert (TREE_TYPE (sarg), rarg);
6023 : 91 : val = build2 (MODIFY_EXPR, TREE_TYPE (larg), larg, rarg);
6024 : : }
6025 : 91 : break;
6026 : 91 : case POSTDECREMENT_EXPR:
6027 : 91 : {
6028 : 91 : tree rarg = convert_lvalue_to_rvalue (location, sarg,
6029 : : true, true);
6030 : 91 : rarg = invert_truthvalue_loc (location, rarg);
6031 : 91 : tree iarg = convert (TREE_TYPE (larg), rarg);
6032 : 91 : val = build2 (MODIFY_EXPR, TREE_TYPE (larg), larg, iarg);
6033 : 91 : val = build2 (COMPOUND_EXPR, TREE_TYPE (larg), val, sarg);
6034 : 91 : val = build2 (COMPOUND_EXPR, TREE_TYPE (larg), sarg, val);
6035 : : }
6036 : 91 : break;
6037 : : default:
6038 : : gcc_unreachable ();
6039 : : }
6040 : 364 : TREE_SIDE_EFFECTS (val) = 1;
6041 : : }
6042 : 926465 : else if (C_BOOLEAN_TYPE_P (TREE_TYPE (arg)))
6043 : 56 : val = boolean_increment (code, arg);
6044 : : else
6045 : 926409 : val = build2 (code, TREE_TYPE (arg), arg, inc);
6046 : 926829 : TREE_SIDE_EFFECTS (val) = 1;
6047 : 926829 : if (TYPE_QUALS (TREE_TYPE (val)) != TYPE_UNQUALIFIED)
6048 : 3933 : TREE_TYPE (val) = c_build_qualified_type (TREE_TYPE (val),
6049 : : TYPE_UNQUALIFIED);
6050 : 926829 : ret = val;
6051 : 926829 : goto return_build_unary_op;
6052 : : }
6053 : :
6054 : 51707373 : case ADDR_EXPR:
6055 : : /* Note that this operation never does default_conversion. */
6056 : :
6057 : : /* The operand of unary '&' must be an lvalue (which excludes
6058 : : expressions of type void), or, in C99, the result of a [] or
6059 : : unary '*' operator. */
6060 : 51707373 : if (VOID_TYPE_P (TREE_TYPE (arg))
6061 : 25 : && TYPE_QUALS (TREE_TYPE (arg)) == TYPE_UNQUALIFIED
6062 : 51707392 : && (!INDIRECT_REF_P (arg) || !flag_isoc99))
6063 : 18 : pedwarn (location, 0, "taking address of expression of type %<void%>");
6064 : :
6065 : : /* Let &* cancel out to simplify resulting code. */
6066 : 51707373 : if (INDIRECT_REF_P (arg))
6067 : : {
6068 : : /* Don't let this be an lvalue. */
6069 : 22077 : if (lvalue_p (TREE_OPERAND (arg, 0)))
6070 : 16674 : return non_lvalue_loc (location, TREE_OPERAND (arg, 0));
6071 : 5403 : ret = TREE_OPERAND (arg, 0);
6072 : 5403 : goto return_build_unary_op;
6073 : : }
6074 : :
6075 : : /* Anything not already handled and not a true memory reference
6076 : : or a non-lvalue array is an error. */
6077 : 51685296 : if (typecode != FUNCTION_TYPE && !noconvert
6078 : 51685296 : && !lvalue_or_else (location, arg, lv_addressof))
6079 : 17 : return error_mark_node;
6080 : :
6081 : : /* Move address operations inside C_MAYBE_CONST_EXPR to simplify
6082 : : folding later. */
6083 : 51685279 : if (TREE_CODE (arg) == C_MAYBE_CONST_EXPR)
6084 : : {
6085 : 14 : tree inner = build_unary_op (location, code,
6086 : 14 : C_MAYBE_CONST_EXPR_EXPR (arg),
6087 : : noconvert);
6088 : 28 : ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (inner),
6089 : 14 : C_MAYBE_CONST_EXPR_PRE (arg), inner);
6090 : 14 : gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (arg));
6091 : 14 : C_MAYBE_CONST_EXPR_NON_CONST (ret)
6092 : 14 : = C_MAYBE_CONST_EXPR_NON_CONST (arg);
6093 : 14 : goto return_build_unary_op;
6094 : : }
6095 : :
6096 : : /* Ordinary case; arg is a COMPONENT_REF or a decl, or a call to
6097 : : .ACCESS_WITH_SIZE. */
6098 : 51685265 : if (is_access_with_size_p (arg))
6099 : 0 : arg = TREE_OPERAND (TREE_OPERAND (CALL_EXPR_ARG (arg, 0), 0), 0);
6100 : :
6101 : 51685265 : argtype = TREE_TYPE (arg);
6102 : :
6103 : : /* If the lvalue is const or volatile, merge that into the type
6104 : : to which the address will point. This is only needed
6105 : : for function types. */
6106 : 51685265 : if ((DECL_P (arg) || REFERENCE_CLASS_P (arg))
6107 : 51198439 : && (TREE_READONLY (arg) || TREE_THIS_VOLATILE (arg))
6108 : 81606835 : && TREE_CODE (argtype) == FUNCTION_TYPE)
6109 : : {
6110 : 29841721 : int orig_quals = TYPE_QUALS (strip_array_types (argtype));
6111 : 29841721 : int quals = orig_quals;
6112 : :
6113 : 29841721 : if (TREE_READONLY (arg))
6114 : 29469080 : quals |= TYPE_QUAL_CONST;
6115 : 29841721 : if (TREE_THIS_VOLATILE (arg))
6116 : 373557 : quals |= TYPE_QUAL_VOLATILE;
6117 : :
6118 : 29841721 : argtype = c_build_qualified_type (argtype, quals);
6119 : : }
6120 : :
6121 : 51685265 : switch (TREE_CODE (arg))
6122 : : {
6123 : 64605 : case COMPONENT_REF:
6124 : 64605 : if (DECL_C_BIT_FIELD (TREE_OPERAND (arg, 1)))
6125 : : {
6126 : 8 : error_at (location, "cannot take address of bit-field %qD",
6127 : 8 : TREE_OPERAND (arg, 1));
6128 : 8 : return error_mark_node;
6129 : : }
6130 : :
6131 : : /* fall through */
6132 : :
6133 : 138716 : case ARRAY_REF:
6134 : 138716 : if (TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (TREE_OPERAND (arg, 0))))
6135 : : {
6136 : 78 : if (!AGGREGATE_TYPE_P (TREE_TYPE (arg))
6137 : 7 : && !POINTER_TYPE_P (TREE_TYPE (arg))
6138 : 75 : && !VECTOR_TYPE_P (TREE_TYPE (arg)))
6139 : : {
6140 : 6 : error_at (location, "cannot take address of scalar with "
6141 : : "reverse storage order");
6142 : 6 : return error_mark_node;
6143 : : }
6144 : :
6145 : 63 : if (TREE_CODE (TREE_TYPE (arg)) == ARRAY_TYPE
6146 : 63 : && TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (arg)))
6147 : 58 : warning_at (location, OPT_Wscalar_storage_order,
6148 : : "address of array with reverse scalar storage "
6149 : : "order requested");
6150 : : }
6151 : :
6152 : 51685251 : default:
6153 : 51685251 : break;
6154 : : }
6155 : :
6156 : 51685251 : if (!c_mark_addressable (arg))
6157 : 20 : return error_mark_node;
6158 : :
6159 : 51685231 : gcc_assert (TREE_CODE (arg) != COMPONENT_REF
6160 : : || !DECL_C_BIT_FIELD (TREE_OPERAND (arg, 1)));
6161 : :
6162 : 51685231 : argtype = c_build_pointer_type (argtype);
6163 : :
6164 : : /* ??? Cope with user tricks that amount to offsetof. Delete this
6165 : : when we have proper support for integer constant expressions. */
6166 : 51685231 : val = get_base_address (arg);
6167 : 51685231 : if (val && INDIRECT_REF_P (val)
6168 : 51708290 : && TREE_CONSTANT (TREE_OPERAND (val, 0)))
6169 : : {
6170 : 538 : ret = fold_offsetof (arg, argtype);
6171 : 538 : goto return_build_unary_op;
6172 : : }
6173 : :
6174 : 51684693 : val = build1 (ADDR_EXPR, argtype, arg);
6175 : :
6176 : 51684693 : ret = val;
6177 : 51684693 : goto return_build_unary_op;
6178 : :
6179 : 10 : case PAREN_EXPR:
6180 : 10 : ret = build1 (code, TREE_TYPE (arg), arg);
6181 : 10 : goto return_build_unary_op;
6182 : :
6183 : 0 : default:
6184 : 0 : gcc_unreachable ();
6185 : : }
6186 : :
6187 : 6980595 : if (argtype == NULL_TREE)
6188 : 6980595 : argtype = TREE_TYPE (arg);
6189 : 6980595 : if (TREE_CODE (arg) == INTEGER_CST)
6190 : 6278330 : ret = (require_constant_value
6191 : 6278330 : ? fold_build1_initializer_loc (location, code, argtype, arg)
6192 : 6260023 : : fold_build1_loc (location, code, argtype, arg));
6193 : : else
6194 : 702265 : ret = build1 (code, argtype, arg);
6195 : 60179364 : return_build_unary_op:
6196 : 60179364 : gcc_assert (ret != error_mark_node);
6197 : 6422598 : if (TREE_CODE (ret) == INTEGER_CST && !TREE_OVERFLOW (ret)
6198 : 66601953 : && !(TREE_CODE (xarg) == INTEGER_CST && !TREE_OVERFLOW (xarg)))
6199 : 562 : ret = build1 (NOP_EXPR, TREE_TYPE (ret), ret);
6200 : 60178802 : else if (TREE_CODE (ret) != INTEGER_CST && int_operands)
6201 : 74 : ret = note_integer_operands (ret);
6202 : 60179364 : if (eptype)
6203 : 237 : ret = build1 (EXCESS_PRECISION_EXPR, eptype, ret);
6204 : 60179364 : protected_set_expr_location (ret, location);
6205 : 60179364 : return ret;
6206 : : }
6207 : :
6208 : : /* Return nonzero if REF is an lvalue valid for this language.
6209 : : Lvalues can be assigned, unless their type has TYPE_READONLY.
6210 : : Lvalues can have their address taken, unless they have C_DECL_REGISTER. */
6211 : :
6212 : : bool
6213 : 177400587 : lvalue_p (const_tree ref)
6214 : : {
6215 : 178889837 : const enum tree_code code = TREE_CODE (ref);
6216 : :
6217 : 178889837 : switch (code)
6218 : : {
6219 : 1464547 : case REALPART_EXPR:
6220 : 1464547 : case IMAGPART_EXPR:
6221 : 1464547 : case COMPONENT_REF:
6222 : 1464547 : return lvalue_p (TREE_OPERAND (ref, 0));
6223 : :
6224 : 24703 : case C_MAYBE_CONST_EXPR:
6225 : 24703 : return lvalue_p (TREE_OPERAND (ref, 1));
6226 : :
6227 : : case COMPOUND_LITERAL_EXPR:
6228 : : case STRING_CST:
6229 : : return true;
6230 : :
6231 : 25411876 : case MEM_REF:
6232 : 25411876 : case TARGET_MEM_REF:
6233 : : /* MEM_REFs can appear from -fgimple parsing or folding, so allow them
6234 : : here as well. */
6235 : 25411876 : case INDIRECT_REF:
6236 : 25411876 : case ARRAY_REF:
6237 : 25411876 : case VAR_DECL:
6238 : 25411876 : case PARM_DECL:
6239 : 25411876 : case RESULT_DECL:
6240 : 25411876 : case ERROR_MARK:
6241 : 25411876 : return (TREE_CODE (TREE_TYPE (ref)) != FUNCTION_TYPE
6242 : 25411876 : && TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE);
6243 : :
6244 : 6 : case BIND_EXPR:
6245 : 6 : return TREE_CODE (TREE_TYPE (ref)) == ARRAY_TYPE;
6246 : :
6247 : 7056778 : case CALL_EXPR:
6248 : 7056778 : return is_access_with_size_p (ref);
6249 : :
6250 : : default:
6251 : : return false;
6252 : : }
6253 : : }
6254 : :
6255 : : /* Give a warning for storing in something that is read-only in GCC
6256 : : terms but not const in ISO C terms. */
6257 : :
6258 : : static void
6259 : 5 : readonly_warning (tree arg, enum lvalue_use use)
6260 : : {
6261 : 5 : switch (use)
6262 : : {
6263 : 1 : case lv_assign:
6264 : 1 : warning (0, "assignment of read-only location %qE", arg);
6265 : 1 : break;
6266 : 2 : case lv_increment:
6267 : 2 : warning (0, "increment of read-only location %qE", arg);
6268 : 2 : break;
6269 : 2 : case lv_decrement:
6270 : 2 : warning (0, "decrement of read-only location %qE", arg);
6271 : 2 : break;
6272 : 0 : default:
6273 : 0 : gcc_unreachable ();
6274 : : }
6275 : 5 : return;
6276 : : }
6277 : :
6278 : :
6279 : : /* Return nonzero if REF is an lvalue valid for this language;
6280 : : otherwise, print an error message and return zero. USE says
6281 : : how the lvalue is being used and so selects the error message.
6282 : : LOCATION is the location at which any error should be reported. */
6283 : :
6284 : : static int
6285 : 4695424 : lvalue_or_else (location_t loc, const_tree ref, enum lvalue_use use)
6286 : : {
6287 : 4695424 : int win = lvalue_p (ref);
6288 : :
6289 : 4695424 : if (!win)
6290 : 74 : lvalue_error (loc, use);
6291 : :
6292 : 4695424 : return win;
6293 : : }
6294 : :
6295 : : /* Mark EXP saying that we need to be able to take the
6296 : : address of it; it should not be allocated in a register.
6297 : : Returns true if successful. ARRAY_REF_P is true if this
6298 : : is for ARRAY_REF construction - in that case we don't want
6299 : : to look through VIEW_CONVERT_EXPR from VECTOR_TYPE to ARRAY_TYPE,
6300 : : it is fine to use ARRAY_REFs for vector subscripts on vector
6301 : : register variables. If OVERRIDE_REGISTER, clear DECL_REGISTER rather
6302 : : than producing an error for taking the address of a register. */
6303 : :
6304 : : bool
6305 : 52228138 : c_mark_addressable (tree exp, bool array_ref_p, bool override_register)
6306 : : {
6307 : 52228138 : tree x = exp;
6308 : :
6309 : 52806984 : while (1)
6310 : 52806984 : switch (TREE_CODE (x))
6311 : : {
6312 : 10003 : case VIEW_CONVERT_EXPR:
6313 : 10003 : if (array_ref_p
6314 : 9893 : && TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
6315 : 19896 : && VECTOR_TYPE_P (TREE_TYPE (TREE_OPERAND (x, 0))))
6316 : : return true;
6317 : 110 : x = TREE_OPERAND (x, 0);
6318 : 110 : break;
6319 : :
6320 : 394810 : case COMPONENT_REF:
6321 : 394810 : if (DECL_C_BIT_FIELD (TREE_OPERAND (x, 1)))
6322 : : {
6323 : 6 : error ("cannot take address of bit-field %qD",
6324 : 3 : TREE_OPERAND (x, 1));
6325 : 3 : return false;
6326 : : }
6327 : : /* FALLTHRU */
6328 : 578736 : case ADDR_EXPR:
6329 : 578736 : case ARRAY_REF:
6330 : 578736 : case REALPART_EXPR:
6331 : 578736 : case IMAGPART_EXPR:
6332 : 578736 : x = TREE_OPERAND (x, 0);
6333 : 578736 : break;
6334 : :
6335 : 570 : case COMPOUND_LITERAL_EXPR:
6336 : 570 : if (C_DECL_REGISTER (COMPOUND_LITERAL_EXPR_DECL (x)))
6337 : : {
6338 : 16 : if (override_register)
6339 : 12 : DECL_REGISTER (COMPOUND_LITERAL_EXPR_DECL (x)) = 0;
6340 : : else
6341 : : {
6342 : 4 : error ("address of register compound literal requested");
6343 : 4 : return false;
6344 : : }
6345 : : }
6346 : 566 : TREE_ADDRESSABLE (x) = 1;
6347 : 566 : TREE_ADDRESSABLE (COMPOUND_LITERAL_EXPR_DECL (x)) = 1;
6348 : 566 : return true;
6349 : :
6350 : 0 : case CONSTRUCTOR:
6351 : 0 : TREE_ADDRESSABLE (x) = 1;
6352 : 0 : return true;
6353 : :
6354 : 1317878 : case VAR_DECL:
6355 : 1317878 : case CONST_DECL:
6356 : 1317878 : case PARM_DECL:
6357 : 1317878 : case RESULT_DECL:
6358 : 1317878 : if (C_DECL_REGISTER (x)
6359 : 1317878 : && DECL_NONLOCAL (x))
6360 : : {
6361 : 0 : if (TREE_PUBLIC (x) || is_global_var (x))
6362 : : {
6363 : 0 : error
6364 : 0 : ("global register variable %qD used in nested function", x);
6365 : 0 : return false;
6366 : : }
6367 : 0 : pedwarn (input_location, 0, "register variable %qD used in nested function", x);
6368 : : }
6369 : 1317878 : else if (C_DECL_REGISTER (x))
6370 : : {
6371 : 73 : if (TREE_PUBLIC (x) || is_global_var (x))
6372 : 4 : error ("address of global register variable %qD requested", x);
6373 : 123 : else if (override_register && !DECL_HARD_REGISTER (x))
6374 : : {
6375 : 54 : DECL_REGISTER (x) = 0;
6376 : 54 : TREE_ADDRESSABLE (x) = 1;
6377 : 54 : mark_decl_used (x, true);
6378 : 54 : return true;
6379 : : }
6380 : : else
6381 : 15 : error ("address of register variable %qD requested", x);
6382 : 19 : return false;
6383 : : }
6384 : :
6385 : : /* FALLTHRU */
6386 : 51656827 : case FUNCTION_DECL:
6387 : 51656827 : TREE_ADDRESSABLE (x) = 1;
6388 : 51656827 : mark_decl_used (x, true);
6389 : : /* FALLTHRU */
6390 : : default:
6391 : : return true;
6392 : : }
6393 : : }
6394 : :
6395 : : /* Convert EXPR to TYPE, warning about conversion problems with
6396 : : constants. SEMANTIC_TYPE is the type this conversion would use
6397 : : without excess precision. If SEMANTIC_TYPE is NULL, this function
6398 : : is equivalent to convert_and_check. This function is a wrapper that
6399 : : handles conversions that may be different than
6400 : : the usual ones because of excess precision. */
6401 : :
6402 : : static tree
6403 : 23357500 : ep_convert_and_check (location_t loc, tree type, tree expr,
6404 : : tree semantic_type)
6405 : : {
6406 : 23357500 : if (TREE_TYPE (expr) == type)
6407 : : return expr;
6408 : :
6409 : : /* For C11, integer conversions may have results with excess
6410 : : precision. */
6411 : 2050367 : if (flag_isoc11 || !semantic_type)
6412 : 2050363 : return convert_and_check (loc, type, expr);
6413 : :
6414 : 4 : if (TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE
6415 : 4 : && TREE_TYPE (expr) != semantic_type)
6416 : : {
6417 : : /* For integers, we need to check the real conversion, not
6418 : : the conversion to the excess precision type. */
6419 : 4 : expr = convert_and_check (loc, semantic_type, expr);
6420 : : }
6421 : : /* Result type is the excess precision type, which should be
6422 : : large enough, so do not check. */
6423 : 4 : return convert (type, expr);
6424 : : }
6425 : :
6426 : : /* If EXPR refers to a built-in declared without a prototype returns
6427 : : the actual type of the built-in and, if non-null, set *BLTIN to
6428 : : a pointer to the built-in. Otherwise return the type of EXPR
6429 : : and clear *BLTIN if non-null. */
6430 : :
6431 : : static tree
6432 : 2826381 : type_or_builtin_type (tree expr, tree *bltin = NULL)
6433 : : {
6434 : 2826381 : tree dummy;
6435 : 2826381 : if (!bltin)
6436 : 0 : bltin = &dummy;
6437 : :
6438 : 2826381 : *bltin = NULL_TREE;
6439 : :
6440 : 2826381 : tree type = TREE_TYPE (expr);
6441 : 2826381 : if (TREE_CODE (expr) != ADDR_EXPR)
6442 : : return type;
6443 : :
6444 : 207978 : tree oper = TREE_OPERAND (expr, 0);
6445 : 207978 : if (!DECL_P (oper)
6446 : 169816 : || TREE_CODE (oper) != FUNCTION_DECL
6447 : 244363 : || !fndecl_built_in_p (oper, BUILT_IN_NORMAL))
6448 : : return type;
6449 : :
6450 : 2084 : built_in_function code = DECL_FUNCTION_CODE (oper);
6451 : 2084 : if (!C_DECL_BUILTIN_PROTOTYPE (oper))
6452 : : return type;
6453 : :
6454 : 1977 : if ((*bltin = builtin_decl_implicit (code)))
6455 : 991 : type = c_build_pointer_type (TREE_TYPE (*bltin));
6456 : :
6457 : : return type;
6458 : : }
6459 : :
6460 : : /* Build and return a conditional expression IFEXP ? OP1 : OP2. If
6461 : : IFEXP_BCP then the condition is a call to __builtin_constant_p, and
6462 : : if folded to an integer constant then the unselected half may
6463 : : contain arbitrary operations not normally permitted in constant
6464 : : expressions. Set the location of the expression to LOC. */
6465 : :
6466 : : tree
6467 : 407411 : build_conditional_expr (location_t colon_loc, tree ifexp, bool ifexp_bcp,
6468 : : tree op1, tree op1_original_type, location_t op1_loc,
6469 : : tree op2, tree op2_original_type, location_t op2_loc)
6470 : : {
6471 : 407411 : tree type1;
6472 : 407411 : tree type2;
6473 : 407411 : enum tree_code code1;
6474 : 407411 : enum tree_code code2;
6475 : 407411 : tree result_type = NULL;
6476 : 407411 : tree semantic_result_type = NULL;
6477 : 407411 : tree orig_op1 = op1, orig_op2 = op2;
6478 : 407411 : bool int_const, op1_int_operands, op2_int_operands, int_operands;
6479 : 407411 : bool ifexp_int_operands;
6480 : 407411 : tree ret;
6481 : :
6482 : 407411 : op1_int_operands = EXPR_INT_CONST_OPERANDS (orig_op1);
6483 : 115965 : if (op1_int_operands)
6484 : 115965 : op1 = remove_c_maybe_const_expr (op1);
6485 : 407411 : op2_int_operands = EXPR_INT_CONST_OPERANDS (orig_op2);
6486 : 150935 : if (op2_int_operands)
6487 : 150935 : op2 = remove_c_maybe_const_expr (op2);
6488 : 407411 : ifexp_int_operands = EXPR_INT_CONST_OPERANDS (ifexp);
6489 : 242187 : if (ifexp_int_operands)
6490 : 242187 : ifexp = remove_c_maybe_const_expr (ifexp);
6491 : :
6492 : : /* Promote both alternatives. */
6493 : :
6494 : 407411 : if (TREE_CODE (TREE_TYPE (op1)) != VOID_TYPE)
6495 : 403501 : op1 = default_conversion (op1);
6496 : 407411 : if (TREE_CODE (TREE_TYPE (op2)) != VOID_TYPE)
6497 : 377578 : op2 = default_conversion (op2);
6498 : :
6499 : 407411 : if (TREE_CODE (ifexp) == ERROR_MARK
6500 : 407342 : || TREE_CODE (TREE_TYPE (op1)) == ERROR_MARK
6501 : 814739 : || TREE_CODE (TREE_TYPE (op2)) == ERROR_MARK)
6502 : 83 : return error_mark_node;
6503 : :
6504 : 407328 : tree bltin1 = NULL_TREE;
6505 : 407328 : tree bltin2 = NULL_TREE;
6506 : 407328 : type1 = type_or_builtin_type (op1, &bltin1);
6507 : 407328 : code1 = TREE_CODE (type1);
6508 : 407328 : type2 = type_or_builtin_type (op2, &bltin2);
6509 : 407328 : code2 = TREE_CODE (type2);
6510 : :
6511 : 407328 : if (code1 == POINTER_TYPE && reject_gcc_builtin (op1))
6512 : 1 : return error_mark_node;
6513 : :
6514 : 407327 : if (code2 == POINTER_TYPE && reject_gcc_builtin (op2))
6515 : 1 : return error_mark_node;
6516 : :
6517 : : /* C90 does not permit non-lvalue arrays in conditional expressions.
6518 : : In C99 they will be pointers by now. */
6519 : 407326 : if (code1 == ARRAY_TYPE || code2 == ARRAY_TYPE)
6520 : : {
6521 : 1 : error_at (colon_loc, "non-lvalue array in conditional expression");
6522 : 1 : return error_mark_node;
6523 : : }
6524 : :
6525 : 407325 : if ((TREE_CODE (op1) == EXCESS_PRECISION_EXPR
6526 : 407319 : || TREE_CODE (op2) == EXCESS_PRECISION_EXPR)
6527 : 7 : && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
6528 : 0 : || code1 == COMPLEX_TYPE || code1 == BITINT_TYPE)
6529 : 7 : && (code2 == INTEGER_TYPE || code2 == REAL_TYPE
6530 : 0 : || code2 == COMPLEX_TYPE || code2 == BITINT_TYPE))
6531 : : {
6532 : 7 : semantic_result_type = c_common_type (type1, type2);
6533 : 7 : if (TREE_CODE (op1) == EXCESS_PRECISION_EXPR)
6534 : : {
6535 : 6 : op1 = TREE_OPERAND (op1, 0);
6536 : 6 : type1 = TREE_TYPE (op1);
6537 : 6 : gcc_assert (TREE_CODE (type1) == code1);
6538 : : }
6539 : 7 : if (TREE_CODE (op2) == EXCESS_PRECISION_EXPR)
6540 : : {
6541 : 1 : op2 = TREE_OPERAND (op2, 0);
6542 : 1 : type2 = TREE_TYPE (op2);
6543 : 1 : gcc_assert (TREE_CODE (type2) == code2);
6544 : : }
6545 : : }
6546 : :
6547 : 407325 : if (warn_cxx_compat)
6548 : : {
6549 : 418 : tree t1 = op1_original_type ? op1_original_type : TREE_TYPE (orig_op1);
6550 : 418 : tree t2 = op2_original_type ? op2_original_type : TREE_TYPE (orig_op2);
6551 : :
6552 : 418 : if (TREE_CODE (t1) == ENUMERAL_TYPE
6553 : 6 : && TREE_CODE (t2) == ENUMERAL_TYPE
6554 : 424 : && TYPE_MAIN_VARIANT (t1) != TYPE_MAIN_VARIANT (t2))
6555 : 2 : warning_at (colon_loc, OPT_Wc___compat,
6556 : : "different enum types in conditional is "
6557 : : "invalid in C++: %qT vs %qT", t1, t2);
6558 : : }
6559 : :
6560 : 407325 : if (warn_zero_as_null_pointer_constant
6561 : 14 : && c_inhibit_evaluation_warnings == 0)
6562 : : {
6563 : 14 : if ((code1 == POINTER_TYPE || code1 == NULLPTR_TYPE)
6564 : 14 : && code2 == INTEGER_TYPE && null_pointer_constant_p (orig_op2))
6565 : 2 : warning_at (op2_loc, OPT_Wzero_as_null_pointer_constant,
6566 : : "zero as null pointer constant");
6567 : :
6568 : 14 : if ((code2 == POINTER_TYPE || code2 == NULLPTR_TYPE)
6569 : 14 : && code1 == INTEGER_TYPE && null_pointer_constant_p (orig_op1))
6570 : 2 : warning_at (op1_loc, OPT_Wzero_as_null_pointer_constant,
6571 : : "zero as null pointer constant");
6572 : : }
6573 : :
6574 : : /* Quickly detect the usual case where op1 and op2 have the same type
6575 : : after promotion. */
6576 : 407325 : if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2))
6577 : : {
6578 : 273003 : if (type1 == type2)
6579 : : result_type = type1;
6580 : : else
6581 : 6262 : result_type = TYPE_MAIN_VARIANT (type1);
6582 : : }
6583 : 134322 : else if ((code1 == INTEGER_TYPE || code1 == REAL_TYPE
6584 : 79843 : || code1 == COMPLEX_TYPE || code1 == BITINT_TYPE)
6585 : 54524 : && (code2 == INTEGER_TYPE || code2 == REAL_TYPE
6586 : 26148 : || code2 == COMPLEX_TYPE || code2 == BITINT_TYPE))
6587 : : {
6588 : : /* In C11, a conditional expression between a floating-point
6589 : : type and an integer type should convert the integer type to
6590 : : the evaluation format of the floating-point type, with
6591 : : possible excess precision. */
6592 : 28475 : tree eptype1 = type1;
6593 : 28475 : tree eptype2 = type2;
6594 : 28475 : if (flag_isoc11)
6595 : : {
6596 : 28163 : tree eptype;
6597 : 11622 : if (ANY_INTEGRAL_TYPE_P (type1)
6598 : 28163 : && (eptype = excess_precision_type (type2)) != NULL_TREE)
6599 : : {
6600 : 2 : eptype2 = eptype;
6601 : 2 : if (!semantic_result_type)
6602 : 2 : semantic_result_type = c_common_type (type1, type2);
6603 : : }
6604 : 501 : else if (ANY_INTEGRAL_TYPE_P (type2)
6605 : 28161 : && (eptype = excess_precision_type (type1)) != NULL_TREE)
6606 : : {
6607 : 4618 : eptype1 = eptype;
6608 : 4618 : if (!semantic_result_type)
6609 : 4618 : semantic_result_type = c_common_type (type1, type2);
6610 : : }
6611 : : }
6612 : 28475 : result_type = c_common_type (eptype1, eptype2);
6613 : 28475 : if (result_type == error_mark_node)
6614 : : return error_mark_node;
6615 : 28473 : do_warn_double_promotion (result_type, type1, type2,
6616 : : "implicit conversion from %qT to %qT to "
6617 : : "match other result of conditional",
6618 : : colon_loc);
6619 : :
6620 : : /* If -Wsign-compare, warn here if type1 and type2 have
6621 : : different signedness. We'll promote the signed to unsigned
6622 : : and later code won't know it used to be different.
6623 : : Do this check on the original types, so that explicit casts
6624 : : will be considered, but default promotions won't. */
6625 : 28473 : if (c_inhibit_evaluation_warnings == 0)
6626 : : {
6627 : 28282 : int unsigned_op1 = TYPE_UNSIGNED (TREE_TYPE (orig_op1));
6628 : 28282 : int unsigned_op2 = TYPE_UNSIGNED (TREE_TYPE (orig_op2));
6629 : :
6630 : 28282 : if (unsigned_op1 ^ unsigned_op2)
6631 : : {
6632 : 12921 : bool ovf;
6633 : :
6634 : : /* Do not warn if the result type is signed, since the
6635 : : signed type will only be chosen if it can represent
6636 : : all the values of the unsigned type. */
6637 : 12921 : if (!TYPE_UNSIGNED (result_type))
6638 : : /* OK */;
6639 : : else
6640 : : {
6641 : 12817 : bool op1_maybe_const = true;
6642 : 12817 : bool op2_maybe_const = true;
6643 : :
6644 : : /* Do not warn if the signed quantity is an
6645 : : unsuffixed integer literal (or some static
6646 : : constant expression involving such literals) and
6647 : : it is non-negative. This warning requires the
6648 : : operands to be folded for best results, so do
6649 : : that folding in this case even without
6650 : : warn_sign_compare to avoid warning options
6651 : : possibly affecting code generation. */
6652 : 12817 : c_inhibit_evaluation_warnings
6653 : 12817 : += (ifexp == truthvalue_false_node);
6654 : 12817 : op1 = c_fully_fold (op1, require_constant_value,
6655 : : &op1_maybe_const);
6656 : 12817 : c_inhibit_evaluation_warnings
6657 : 12817 : -= (ifexp == truthvalue_false_node);
6658 : :
6659 : 12817 : c_inhibit_evaluation_warnings
6660 : 12817 : += (ifexp == truthvalue_true_node);
6661 : 12817 : op2 = c_fully_fold (op2, require_constant_value,
6662 : : &op2_maybe_const);
6663 : 12817 : c_inhibit_evaluation_warnings
6664 : 12817 : -= (ifexp == truthvalue_true_node);
6665 : :
6666 : 12817 : if (warn_sign_compare)
6667 : : {
6668 : 1245 : if ((unsigned_op2
6669 : 685 : && tree_expr_nonnegative_warnv_p (op1, &ovf))
6670 : 1248 : || (unsigned_op1
6671 : 560 : && tree_expr_nonnegative_warnv_p (op2, &ovf)))
6672 : : /* OK */;
6673 : 10 : else if (unsigned_op2)
6674 : 3 : warning_at (op1_loc, OPT_Wsign_compare,
6675 : : "operand of %<?:%> changes signedness from "
6676 : : "%qT to %qT due to unsignedness of other "
6677 : 3 : "operand", TREE_TYPE (orig_op1),
6678 : 3 : TREE_TYPE (orig_op2));
6679 : : else
6680 : 7 : warning_at (op2_loc, OPT_Wsign_compare,
6681 : : "operand of %<?:%> changes signedness from "
6682 : : "%qT to %qT due to unsignedness of other "
6683 : 7 : "operand", TREE_TYPE (orig_op2),
6684 : 7 : TREE_TYPE (orig_op1));
6685 : : }
6686 : 12817 : if (!op1_maybe_const || TREE_CODE (op1) != INTEGER_CST)
6687 : 7473 : op1 = c_wrap_maybe_const (op1, !op1_maybe_const);
6688 : 12817 : if (!op2_maybe_const || TREE_CODE (op2) != INTEGER_CST)
6689 : 4379 : op2 = c_wrap_maybe_const (op2, !op2_maybe_const);
6690 : : }
6691 : : }
6692 : : }
6693 : : }
6694 : 105847 : else if (code1 == VOID_TYPE || code2 == VOID_TYPE)
6695 : : {
6696 : 25995 : if (code1 != VOID_TYPE || code2 != VOID_TYPE)
6697 : 25995 : pedwarn (colon_loc, OPT_Wpedantic,
6698 : : "ISO C forbids conditional expr with only one void side");
6699 : 25995 : result_type = void_type_node;
6700 : : }
6701 : 79852 : else if (code1 == POINTER_TYPE && code2 == POINTER_TYPE)
6702 : : {
6703 : 79461 : addr_space_t as1 = TYPE_ADDR_SPACE (TREE_TYPE (type1));
6704 : 79461 : addr_space_t as2 = TYPE_ADDR_SPACE (TREE_TYPE (type2));
6705 : 79461 : addr_space_t as_common;
6706 : :
6707 : 79461 : if (comp_target_types (colon_loc, type1, type2))
6708 : : {
6709 : 2600 : ifexp = save_expr (ifexp);
6710 : 2600 : result_type = common_pointer_type (type1, type2, ifexp);
6711 : : }
6712 : 76861 : else if (null_pointer_constant_p (orig_op1))
6713 : : result_type = type2;
6714 : 72699 : else if (null_pointer_constant_p (orig_op2))
6715 : : result_type = type1;
6716 : 34799 : else if (!addr_space_superset (as1, as2, &as_common))
6717 : : {
6718 : 0 : error_at (colon_loc, "pointers to disjoint address spaces "
6719 : : "used in conditional expression");
6720 : 0 : return error_mark_node;
6721 : : }
6722 : 34799 : else if ((VOID_TYPE_P (TREE_TYPE (type1))
6723 : 326 : && !TYPE_ATOMIC (TREE_TYPE (type1)))
6724 : 34801 : || (VOID_TYPE_P (TREE_TYPE (type2))
6725 : 34428 : && !TYPE_ATOMIC (TREE_TYPE (type2))))
6726 : : {
6727 : 34751 : tree t1 = TREE_TYPE (type1);
6728 : 34751 : tree t2 = TREE_TYPE (type2);
6729 : 34751 : if (!(VOID_TYPE_P (t1)
6730 : 325 : && !TYPE_ATOMIC (t1)))
6731 : : {
6732 : : /* roles are swapped */
6733 : 34427 : t1 = t2;
6734 : 34427 : t2 = TREE_TYPE (type1);
6735 : : }
6736 : 34751 : tree t2_stripped = strip_array_types (t2);
6737 : 34751 : if ((TREE_CODE (t2) == ARRAY_TYPE)
6738 : 34751 : && (TYPE_QUALS (t2_stripped) & ~TYPE_QUALS (t1)))
6739 : : {
6740 : 18 : if (!flag_isoc23)
6741 : 6 : warning_at (colon_loc, OPT_Wdiscarded_array_qualifiers,
6742 : : "pointer to array loses qualifier "
6743 : : "in conditional expression");
6744 : 12 : else if (warn_c11_c23_compat > 0)
6745 : 6 : warning_at (colon_loc, OPT_Wc11_c23_compat,
6746 : : "pointer to array loses qualifier "
6747 : : "in conditional expression in ISO C before C23");
6748 : : }
6749 : 34751 : if (TREE_CODE (t2) == FUNCTION_TYPE)
6750 : 4 : pedwarn (colon_loc, OPT_Wpedantic,
6751 : : "ISO C forbids conditional expr between "
6752 : : "%<void *%> and function pointer");
6753 : : /* for array, use qualifiers of element type */
6754 : 34751 : if (flag_isoc23)
6755 : 11002 : t2 = t2_stripped;
6756 : 34751 : result_type = c_build_pointer_type (qualify_type (t1, t2));
6757 : : }
6758 : : /* Objective-C pointer comparisons are a bit more lenient. */
6759 : 48 : else if (objc_have_common_type (type1, type2, -3, NULL_TREE))
6760 : 0 : result_type = objc_common_type (type1, type2);
6761 : : else
6762 : : {
6763 : 48 : int qual = ENCODE_QUAL_ADDR_SPACE (as_common);
6764 : 48 : enum diagnostics::kind kind = diagnostics::kind::permerror;
6765 : 48 : if (!flag_isoc99)
6766 : : /* This downgrade to a warning ensures that -std=gnu89
6767 : : -pedantic-errors does not flag these mismatches between
6768 : : builtins as errors (as diagnostics::kind::permerror would)
6769 : : ISO C99 and later do not have implicit function declarations,
6770 : : so the mismatch cannot occur naturally there. */
6771 : 5 : kind = (bltin1 && bltin2
6772 : 5 : ? diagnostics::kind::warning
6773 : : : diagnostics::kind::pedwarn);
6774 : 48 : if (emit_diagnostic (kind, colon_loc, OPT_Wincompatible_pointer_types,
6775 : : "pointer type mismatch "
6776 : : "in conditional expression"))
6777 : : {
6778 : 46 : inform (op1_loc, "first expression has type %qT", type1);
6779 : 46 : inform (op2_loc, "second expression has type %qT", type2);
6780 : : }
6781 : 48 : result_type = c_build_pointer_type
6782 : 48 : (c_build_qualified_type (void_type_node, qual));
6783 : : }
6784 : : }
6785 : 391 : else if (code1 == POINTER_TYPE
6786 : 274 : && (code2 == INTEGER_TYPE || code2 == BITINT_TYPE))
6787 : : {
6788 : 270 : if (!null_pointer_constant_p (orig_op2))
6789 : 14 : permerror_opt (colon_loc, OPT_Wint_conversion,
6790 : : "pointer/integer type mismatch "
6791 : : "in conditional expression");
6792 : : else
6793 : : {
6794 : 256 : op2 = null_pointer_node;
6795 : : }
6796 : : result_type = type1;
6797 : : }
6798 : 121 : else if (code2 == POINTER_TYPE
6799 : 87 : && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
6800 : : {
6801 : 83 : if (!null_pointer_constant_p (orig_op1))
6802 : 14 : permerror_opt (colon_loc, OPT_Wint_conversion,
6803 : : "pointer/integer type mismatch "
6804 : : "in conditional expression");
6805 : : else
6806 : : {
6807 : 69 : op1 = null_pointer_node;
6808 : : }
6809 : : result_type = type2;
6810 : : }
6811 : : /* 6.5.15: "if one is a null pointer constant (other than a pointer) or has
6812 : : type nullptr_t and the other is a pointer, the result type is the pointer
6813 : : type." */
6814 : 38 : else if (code1 == NULLPTR_TYPE && code2 == POINTER_TYPE)
6815 : : result_type = type2;
6816 : 34 : else if (code1 == POINTER_TYPE && code2 == NULLPTR_TYPE)
6817 : : result_type = type1;
6818 : 8 : else if (RECORD_OR_UNION_TYPE_P (type1) && RECORD_OR_UNION_TYPE_P (type2)
6819 : 38 : && comptypes (TYPE_MAIN_VARIANT (type1),
6820 : 8 : TYPE_MAIN_VARIANT (type2)))
6821 : 8 : result_type = composite_type (TYPE_MAIN_VARIANT (type1),
6822 : 8 : TYPE_MAIN_VARIANT (type2));
6823 : :
6824 : 407301 : if (!result_type)
6825 : : {
6826 : 22 : if (flag_cond_mismatch)
6827 : 0 : result_type = void_type_node;
6828 : : else
6829 : : {
6830 : 22 : error_at (colon_loc, "type mismatch in conditional expression");
6831 : 22 : return error_mark_node;
6832 : : }
6833 : : }
6834 : :
6835 : : /* Merge const and volatile flags of the incoming types. */
6836 : 407301 : result_type
6837 : 407301 : = build_type_variant (result_type,
6838 : : TYPE_READONLY (type1) || TYPE_READONLY (type2),
6839 : : TYPE_VOLATILE (type1) || TYPE_VOLATILE (type2));
6840 : :
6841 : 407301 : op1 = ep_convert_and_check (colon_loc, result_type, op1,
6842 : : semantic_result_type);
6843 : 407301 : op2 = ep_convert_and_check (colon_loc, result_type, op2,
6844 : : semantic_result_type);
6845 : :
6846 : 407301 : if (ifexp_bcp && ifexp == truthvalue_true_node)
6847 : : {
6848 : 10 : op2_int_operands = true;
6849 : 10 : op1 = c_fully_fold (op1, require_constant_value, NULL);
6850 : : }
6851 : 59 : if (ifexp_bcp && ifexp == truthvalue_false_node)
6852 : : {
6853 : 49 : op1_int_operands = true;
6854 : 49 : op2 = c_fully_fold (op2, require_constant_value, NULL);
6855 : : }
6856 : 911690 : int_const = int_operands = (ifexp_int_operands
6857 : 407301 : && op1_int_operands
6858 : 407301 : && op2_int_operands);
6859 : 97088 : if (int_operands)
6860 : : {
6861 : 97088 : int_const = ((ifexp == truthvalue_true_node
6862 : 58669 : && TREE_CODE (orig_op1) == INTEGER_CST
6863 : 58655 : && !TREE_OVERFLOW (orig_op1))
6864 : 97102 : || (ifexp == truthvalue_false_node
6865 : 38373 : && TREE_CODE (orig_op2) == INTEGER_CST
6866 : 38357 : && !TREE_OVERFLOW (orig_op2)));
6867 : : }
6868 : :
6869 : : /* Need to convert condition operand into a vector mask. */
6870 : 407301 : if (VECTOR_TYPE_P (TREE_TYPE (ifexp)))
6871 : : {
6872 : 0 : tree vectype = TREE_TYPE (ifexp);
6873 : 0 : tree elem_type = TREE_TYPE (vectype);
6874 : 0 : tree zero = build_int_cst (elem_type, 0);
6875 : 0 : tree zero_vec = build_vector_from_val (vectype, zero);
6876 : 0 : tree cmp_type = truth_type_for (vectype);
6877 : 0 : ifexp = build2 (NE_EXPR, cmp_type, ifexp, zero_vec);
6878 : : }
6879 : :
6880 : 407301 : if (int_const || (ifexp_bcp && TREE_CODE (ifexp) == INTEGER_CST))
6881 : 97044 : ret = fold_build3_loc (colon_loc, COND_EXPR, result_type, ifexp, op1, op2);
6882 : : else
6883 : : {
6884 : 310257 : if (int_operands)
6885 : : {
6886 : : /* Use c_fully_fold here, since C_MAYBE_CONST_EXPR might be
6887 : : nested inside of the expression. */
6888 : 76 : op1 = c_fully_fold (op1, false, NULL);
6889 : 76 : op2 = c_fully_fold (op2, false, NULL);
6890 : : }
6891 : 310257 : ret = build3 (COND_EXPR, result_type, ifexp, op1, op2);
6892 : 310257 : if (int_operands)
6893 : 76 : ret = note_integer_operands (ret);
6894 : : }
6895 : 407301 : if (semantic_result_type)
6896 : 4627 : ret = build1 (EXCESS_PRECISION_EXPR, semantic_result_type, ret);
6897 : :
6898 : 407301 : protected_set_expr_location (ret, colon_loc);
6899 : :
6900 : : /* If the OP1 and OP2 are the same and don't have side-effects,
6901 : : warn here, because the COND_EXPR will be turned into OP1. */
6902 : 407301 : if (warn_duplicated_branches
6903 : 34 : && TREE_CODE (ret) == COND_EXPR
6904 : 407335 : && (op1 == op2 || operand_equal_p (op1, op2, OEP_ADDRESS_OF_SAME_FIELD)))
6905 : 13 : warning_at (EXPR_LOCATION (ret), OPT_Wduplicated_branches,
6906 : : "this condition has identical branches");
6907 : :
6908 : : return ret;
6909 : : }
6910 : :
6911 : : /* EXPR is an expression, location LOC, whose result is discarded.
6912 : : Warn if it is a call to a nodiscard function (or a COMPOUND_EXPR
6913 : : whose right-hand operand is such a call, possibly recursively). */
6914 : :
6915 : : static void
6916 : 6447522 : maybe_warn_nodiscard (location_t loc, tree expr)
6917 : : {
6918 : 6447522 : if (VOID_TYPE_P (TREE_TYPE (expr)))
6919 : : return;
6920 : 3940495 : while (TREE_CODE (expr) == COMPOUND_EXPR)
6921 : : {
6922 : 49095 : expr = TREE_OPERAND (expr, 1);
6923 : 49095 : if (EXPR_HAS_LOCATION (expr))
6924 : 32002 : loc = EXPR_LOCATION (expr);
6925 : : }
6926 : 3891400 : if (TREE_CODE (expr) != CALL_EXPR)
6927 : : return;
6928 : 343277 : tree fn = CALL_EXPR_FN (expr);
6929 : 343277 : if (!fn)
6930 : : return;
6931 : 343264 : tree attr;
6932 : 343264 : if (TREE_CODE (fn) == ADDR_EXPR
6933 : 342599 : && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL
6934 : 685863 : && (attr = lookup_attribute ("nodiscard",
6935 : 342599 : DECL_ATTRIBUTES (TREE_OPERAND (fn, 0)))))
6936 : : {
6937 : 3 : fn = TREE_OPERAND (fn, 0);
6938 : 3 : tree args = TREE_VALUE (attr);
6939 : 3 : if (args)
6940 : 1 : args = TREE_VALUE (args);
6941 : 3 : auto_diagnostic_group d;
6942 : 3 : auto_urlify_attributes sentinel;
6943 : 3 : int warned;
6944 : 3 : if (args)
6945 : 1 : warned = warning_at (loc, OPT_Wunused_result,
6946 : : "ignoring return value of %qD, declared with "
6947 : : "attribute %<nodiscard%>: %E", fn, args);
6948 : : else
6949 : 2 : warned = warning_at (loc, OPT_Wunused_result,
6950 : : "ignoring return value of %qD, declared with "
6951 : : "attribute %<nodiscard%>", fn);
6952 : 3 : if (warned)
6953 : 3 : inform (DECL_SOURCE_LOCATION (fn), "declared here");
6954 : 3 : }
6955 : : else
6956 : : {
6957 : 343261 : tree rettype = TREE_TYPE (TREE_TYPE (TREE_TYPE (fn)));
6958 : 343261 : attr = lookup_attribute ("nodiscard", TYPE_ATTRIBUTES (rettype));
6959 : 343261 : if (!attr)
6960 : 343249 : return;
6961 : 12 : tree args = TREE_VALUE (attr);
6962 : 12 : if (args)
6963 : 5 : args = TREE_VALUE (args);
6964 : 12 : auto_diagnostic_group d;
6965 : 12 : auto_urlify_attributes sentinel;
6966 : 12 : int warned;
6967 : 12 : if (args)
6968 : 5 : warned = warning_at (loc, OPT_Wunused_result,
6969 : : "ignoring return value of type %qT, declared "
6970 : : "with attribute %<nodiscard%>: %E",
6971 : : rettype, args);
6972 : : else
6973 : 7 : warned = warning_at (loc, OPT_Wunused_result,
6974 : : "ignoring return value of type %qT, declared "
6975 : : "with attribute %<nodiscard%>", rettype);
6976 : 12 : if (warned)
6977 : : {
6978 : 12 : if (TREE_CODE (fn) == ADDR_EXPR)
6979 : : {
6980 : 11 : fn = TREE_OPERAND (fn, 0);
6981 : 11 : if (TREE_CODE (fn) == FUNCTION_DECL)
6982 : 11 : inform (DECL_SOURCE_LOCATION (fn),
6983 : : "in call to %qD, declared here", fn);
6984 : : }
6985 : : }
6986 : 12 : }
6987 : : }
6988 : :
6989 : : /* Return a compound expression that performs two expressions and
6990 : : returns the value of the second of them.
6991 : :
6992 : : LOC is the location of the COMPOUND_EXPR. */
6993 : :
6994 : : tree
6995 : 111321 : build_compound_expr (location_t loc, tree expr1, tree expr2)
6996 : : {
6997 : 111321 : bool expr1_int_operands, expr2_int_operands;
6998 : 111321 : tree eptype = NULL_TREE;
6999 : 111321 : tree ret;
7000 : :
7001 : 111321 : expr1_int_operands = EXPR_INT_CONST_OPERANDS (expr1);
7002 : 325 : if (expr1_int_operands)
7003 : 325 : expr1 = remove_c_maybe_const_expr (expr1);
7004 : 111321 : expr2_int_operands = EXPR_INT_CONST_OPERANDS (expr2);
7005 : 66095 : if (expr2_int_operands)
7006 : 66095 : expr2 = remove_c_maybe_const_expr (expr2);
7007 : :
7008 : 111321 : if (TREE_CODE (expr1) == EXCESS_PRECISION_EXPR)
7009 : 0 : expr1 = TREE_OPERAND (expr1, 0);
7010 : 111321 : if (TREE_CODE (expr2) == EXCESS_PRECISION_EXPR)
7011 : : {
7012 : 1 : eptype = TREE_TYPE (expr2);
7013 : 1 : expr2 = TREE_OPERAND (expr2, 0);
7014 : : }
7015 : :
7016 : 111321 : if (!TREE_SIDE_EFFECTS (expr1))
7017 : : {
7018 : : /* The left-hand operand of a comma expression is like an expression
7019 : : statement: with -Wunused, we should warn if it doesn't have
7020 : : any side-effects, unless it was explicitly cast to (void). */
7021 : 8339 : if (warn_unused_value)
7022 : : {
7023 : 1257 : if (VOID_TYPE_P (TREE_TYPE (expr1))
7024 : 1257 : && CONVERT_EXPR_P (expr1))
7025 : : ; /* (void) a, b */
7026 : 14 : else if (VOID_TYPE_P (TREE_TYPE (expr1))
7027 : 4 : && TREE_CODE (expr1) == COMPOUND_EXPR
7028 : 17 : && CONVERT_EXPR_P (TREE_OPERAND (expr1, 1)))
7029 : : ; /* (void) a, (void) b, c */
7030 : : else
7031 : 11 : warning_at (loc, OPT_Wunused_value,
7032 : : "left-hand operand of comma expression has no effect");
7033 : : }
7034 : : }
7035 : 102982 : else if (TREE_CODE (expr1) == COMPOUND_EXPR
7036 : 13104 : && warn_unused_value)
7037 : : {
7038 : : tree r = expr1;
7039 : : location_t cloc = loc;
7040 : 4833 : while (TREE_CODE (r) == COMPOUND_EXPR)
7041 : : {
7042 : 2417 : if (EXPR_HAS_LOCATION (r))
7043 : 2417 : cloc = EXPR_LOCATION (r);
7044 : 2417 : r = TREE_OPERAND (r, 1);
7045 : : }
7046 : 2416 : if (!TREE_SIDE_EFFECTS (r)
7047 : 4 : && !VOID_TYPE_P (TREE_TYPE (r))
7048 : 2420 : && !CONVERT_EXPR_P (r))
7049 : 4 : warning_at (cloc, OPT_Wunused_value,
7050 : : "right-hand operand of comma expression has no effect");
7051 : : }
7052 : :
7053 : : /* With -Wunused, we should also warn if the left-hand operand does have
7054 : : side-effects, but computes a value which is not used. For example, in
7055 : : `foo() + bar(), baz()' the result of the `+' operator is not used,
7056 : : so we should issue a warning. */
7057 : 100566 : else if (warn_unused_value)
7058 : 35396 : warn_if_unused_value (expr1, loc);
7059 : :
7060 : 111321 : maybe_warn_nodiscard (loc, expr1);
7061 : :
7062 : 111321 : if (expr2 == error_mark_node)
7063 : : return error_mark_node;
7064 : :
7065 : 111308 : ret = build2 (COMPOUND_EXPR, TREE_TYPE (expr2), expr1, expr2);
7066 : :
7067 : 111308 : if (flag_isoc99
7068 : : && expr1_int_operands
7069 : 110852 : && expr2_int_operands)
7070 : 152 : ret = note_integer_operands (ret);
7071 : :
7072 : 111308 : if (eptype)
7073 : 1 : ret = build1 (EXCESS_PRECISION_EXPR, eptype, ret);
7074 : :
7075 : 111308 : protected_set_expr_location (ret, loc);
7076 : 111308 : return ret;
7077 : : }
7078 : :
7079 : : /* Issue -Wcast-qual warnings when appropriate. TYPE is the type to
7080 : : which we are casting. OTYPE is the type of the expression being
7081 : : cast. Both TYPE and OTYPE are pointer types. LOC is the location
7082 : : of the cast. -Wcast-qual appeared on the command line. Named
7083 : : address space qualifiers are not handled here, because they result
7084 : : in different warnings. */
7085 : :
7086 : : static void
7087 : 13405 : handle_warn_cast_qual (location_t loc, tree type, tree otype)
7088 : : {
7089 : 13405 : tree in_type = type;
7090 : 13405 : tree in_otype = otype;
7091 : 13405 : int added = 0;
7092 : 13405 : int discarded = 0;
7093 : 13575 : bool is_const;
7094 : :
7095 : : /* Check that the qualifiers on IN_TYPE are a superset of the
7096 : : qualifiers of IN_OTYPE. The outermost level of POINTER_TYPE
7097 : : nodes is uninteresting and we stop as soon as we hit a
7098 : : non-POINTER_TYPE node on either type. */
7099 : 13575 : do
7100 : : {
7101 : 13575 : in_otype = TREE_TYPE (in_otype);
7102 : 13575 : in_type = TREE_TYPE (in_type);
7103 : :
7104 : : /* GNU C allows cv-qualified function types. 'const' means the
7105 : : function is very pure, 'volatile' means it can't return. We
7106 : : need to warn when such qualifiers are added, not when they're
7107 : : taken away. */
7108 : 13575 : if (TREE_CODE (in_otype) == FUNCTION_TYPE
7109 : 26 : && TREE_CODE (in_type) == FUNCTION_TYPE)
7110 : 18 : added |= (TYPE_QUALS_NO_ADDR_SPACE (in_type)
7111 : 18 : & ~TYPE_QUALS_NO_ADDR_SPACE (in_otype));
7112 : : else
7113 : 13557 : discarded |= (TYPE_QUALS_NO_ADDR_SPACE (in_otype)
7114 : 13557 : & ~TYPE_QUALS_NO_ADDR_SPACE (in_type));
7115 : : }
7116 : 13575 : while (TREE_CODE (in_type) == POINTER_TYPE
7117 : 13575 : && TREE_CODE (in_otype) == POINTER_TYPE);
7118 : :
7119 : 13405 : if (added)
7120 : 2 : warning_at (loc, OPT_Wcast_qual,
7121 : : "cast adds %q#v qualifier to function type", added);
7122 : :
7123 : 13405 : if (discarded)
7124 : : /* There are qualifiers present in IN_OTYPE that are not present
7125 : : in IN_TYPE. */
7126 : 1117 : warning_at (loc, OPT_Wcast_qual,
7127 : : "cast discards %qv qualifier from pointer target type",
7128 : : discarded);
7129 : :
7130 : 13405 : if (added || discarded)
7131 : : return;
7132 : :
7133 : : /* A cast from **T to const **T is unsafe, because it can cause a
7134 : : const value to be changed with no additional warning. We only
7135 : : issue this warning if T is the same on both sides, and we only
7136 : : issue the warning if there are the same number of pointers on
7137 : : both sides, as otherwise the cast is clearly unsafe anyhow. A
7138 : : cast is unsafe when a qualifier is added at one level and const
7139 : : is not present at all outer levels.
7140 : :
7141 : : To issue this warning, we check at each level whether the cast
7142 : : adds new qualifiers not already seen. We don't need to special
7143 : : case function types, as they won't have the same
7144 : : TYPE_MAIN_VARIANT. */
7145 : :
7146 : 12286 : if (TYPE_MAIN_VARIANT (in_type) != TYPE_MAIN_VARIANT (in_otype))
7147 : : return;
7148 : 51 : if (TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE)
7149 : : return;
7150 : :
7151 : 48 : in_type = type;
7152 : 48 : in_otype = otype;
7153 : 48 : is_const = TYPE_READONLY (TREE_TYPE (in_type));
7154 : 130 : do
7155 : : {
7156 : 130 : in_type = TREE_TYPE (in_type);
7157 : 130 : in_otype = TREE_TYPE (in_otype);
7158 : 130 : if ((TYPE_QUALS (in_type) &~ TYPE_QUALS (in_otype)) != 0
7159 : 130 : && !is_const)
7160 : : {
7161 : 27 : warning_at (loc, OPT_Wcast_qual,
7162 : : "to be safe all intermediate pointers in cast from "
7163 : : "%qT to %qT must be %<const%> qualified",
7164 : : otype, type);
7165 : 27 : break;
7166 : : }
7167 : 103 : if (is_const)
7168 : 72 : is_const = TYPE_READONLY (in_type);
7169 : : }
7170 : 103 : while (TREE_CODE (in_type) == POINTER_TYPE);
7171 : : }
7172 : :
7173 : : /* Heuristic check if two parameter types can be considered ABI-equivalent. */
7174 : :
7175 : : static bool
7176 : 1081 : c_safe_arg_type_equiv_p (tree t1, tree t2)
7177 : : {
7178 : 1081 : if (error_operand_p (t1) || error_operand_p (t2))
7179 : : return true;
7180 : :
7181 : 1080 : t1 = TYPE_MAIN_VARIANT (t1);
7182 : 1080 : t2 = TYPE_MAIN_VARIANT (t2);
7183 : :
7184 : 1080 : if (TREE_CODE (t1) == POINTER_TYPE
7185 : 114 : && TREE_CODE (t2) == POINTER_TYPE)
7186 : : return true;
7187 : :
7188 : : /* Only the precision of the parameter matters. This check should
7189 : : make sure that the callee does not see undefined values in argument
7190 : : registers. */
7191 : 988 : if (INTEGRAL_TYPE_P (t1)
7192 : 869 : && INTEGRAL_TYPE_P (t2)
7193 : 1289 : && TYPE_PRECISION (t1) == TYPE_PRECISION (t2))
7194 : : return true;
7195 : :
7196 : 867 : return comptypes (t1, t2);
7197 : : }
7198 : :
7199 : : /* Check if a type cast between two function types can be considered safe. */
7200 : :
7201 : : static bool
7202 : 7434 : c_safe_function_type_cast_p (tree t1, tree t2)
7203 : : {
7204 : 7434 : if (TREE_TYPE (t1) == void_type_node &&
7205 : 5451 : TYPE_ARG_TYPES (t1) == void_list_node)
7206 : : return true;
7207 : :
7208 : 3679 : if (TREE_TYPE (t2) == void_type_node &&
7209 : 2862 : TYPE_ARG_TYPES (t2) == void_list_node)
7210 : : return true;
7211 : :
7212 : 849 : if (!c_safe_arg_type_equiv_p (TREE_TYPE (t1), TREE_TYPE (t2)))
7213 : : return false;
7214 : :
7215 : 153 : for (t1 = TYPE_ARG_TYPES (t1), t2 = TYPE_ARG_TYPES (t2);
7216 : 281 : t1 && t2;
7217 : 128 : t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
7218 : 232 : if (!c_safe_arg_type_equiv_p (TREE_VALUE (t1), TREE_VALUE (t2)))
7219 : : return false;
7220 : :
7221 : : return true;
7222 : : }
7223 : :
7224 : : /* Build an expression representing a cast to type TYPE of expression EXPR.
7225 : : LOC is the location of the cast-- typically the open paren of the cast. */
7226 : :
7227 : : tree
7228 : 119541322 : build_c_cast (location_t loc, tree type, tree expr)
7229 : : {
7230 : 119541322 : tree value;
7231 : :
7232 : 119541322 : bool int_operands = EXPR_INT_CONST_OPERANDS (expr);
7233 : :
7234 : 119541322 : if (TREE_CODE (expr) == EXCESS_PRECISION_EXPR)
7235 : 66 : expr = TREE_OPERAND (expr, 0);
7236 : :
7237 : 119541322 : value = expr;
7238 : 119541322 : if (int_operands)
7239 : 6833160 : value = remove_c_maybe_const_expr (value);
7240 : :
7241 : 119541322 : if (type == error_mark_node || expr == error_mark_node)
7242 : : return error_mark_node;
7243 : :
7244 : : /* The ObjC front-end uses TYPE_MAIN_VARIANT to tie together types differing
7245 : : only in <protocol> qualifications. But when constructing cast expressions,
7246 : : the protocols do matter and must be kept around. */
7247 : 119540300 : if (objc_is_object_ptr (type) && objc_is_object_ptr (TREE_TYPE (expr)))
7248 : 0 : return build1 (NOP_EXPR, type, expr);
7249 : :
7250 : 119540300 : type = TYPE_MAIN_VARIANT (type);
7251 : :
7252 : 119540300 : if (TREE_CODE (type) == ARRAY_TYPE)
7253 : : {
7254 : 13 : error_at (loc, "cast specifies array type");
7255 : 13 : return error_mark_node;
7256 : : }
7257 : :
7258 : 119540287 : if (TREE_CODE (type) == FUNCTION_TYPE)
7259 : : {
7260 : 6 : error_at (loc, "cast specifies function type");
7261 : 6 : return error_mark_node;
7262 : : }
7263 : :
7264 : 119540281 : if (!VOID_TYPE_P (type))
7265 : : {
7266 : 119496182 : value = require_complete_type (loc, value);
7267 : 119496182 : if (value == error_mark_node)
7268 : : return error_mark_node;
7269 : : }
7270 : :
7271 : 119540280 : if (type == TYPE_MAIN_VARIANT (TREE_TYPE (value)))
7272 : : {
7273 : 17997140 : if (RECORD_OR_UNION_TYPE_P (type)
7274 : 17997140 : && pedwarn (loc, OPT_Wpedantic,
7275 : : "ISO C forbids casting nonscalar to the same type"))
7276 : : ;
7277 : 17997136 : else if (warn_useless_cast)
7278 : 7 : warning_at (loc, OPT_Wuseless_cast,
7279 : : "useless cast to type %qT", type);
7280 : :
7281 : : /* Convert to remove any qualifiers from VALUE's type. */
7282 : 17997140 : value = convert (type, value);
7283 : : }
7284 : 101543140 : else if (TREE_CODE (type) == UNION_TYPE)
7285 : : {
7286 : 130 : tree field;
7287 : :
7288 : 185 : for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
7289 : 178 : if (TREE_TYPE (field) != error_mark_node
7290 : 355 : && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (field)),
7291 : 177 : TYPE_MAIN_VARIANT (TREE_TYPE (value))))
7292 : : break;
7293 : :
7294 : 130 : if (field)
7295 : : {
7296 : 123 : tree t;
7297 : 123 : bool maybe_const = true;
7298 : :
7299 : 123 : pedwarn (loc, OPT_Wpedantic, "ISO C forbids casts to union type");
7300 : 123 : t = c_fully_fold (value, false, &maybe_const);
7301 : 123 : t = build_constructor_single (type, field, t);
7302 : 123 : if (!maybe_const)
7303 : 8 : t = c_wrap_maybe_const (t, true);
7304 : 123 : t = digest_init (loc, field, type, t,
7305 : : NULL_TREE, false, false, false, true, false, false);
7306 : 123 : TREE_CONSTANT (t) = TREE_CONSTANT (value);
7307 : 123 : return t;
7308 : : }
7309 : 7 : error_at (loc, "cast to union type from type not present in union");
7310 : 7 : return error_mark_node;
7311 : : }
7312 : : else
7313 : : {
7314 : 101543010 : tree otype, ovalue;
7315 : :
7316 : 101543010 : if (type == void_type_node)
7317 : : {
7318 : 18129 : tree t = build1 (CONVERT_EXPR, type, value);
7319 : 18129 : SET_EXPR_LOCATION (t, loc);
7320 : 18129 : return t;
7321 : : }
7322 : :
7323 : 101524881 : otype = TREE_TYPE (value);
7324 : :
7325 : : /* Optionally warn about potentially worrisome casts. */
7326 : 101524881 : if (warn_cast_qual
7327 : 179313 : && TREE_CODE (type) == POINTER_TYPE
7328 : 26463 : && TREE_CODE (otype) == POINTER_TYPE)
7329 : 13405 : handle_warn_cast_qual (loc, type, otype);
7330 : :
7331 : : /* Warn about conversions between pointers to disjoint
7332 : : address spaces. */
7333 : 101524881 : if (TREE_CODE (type) == POINTER_TYPE
7334 : 3321577 : && TREE_CODE (otype) == POINTER_TYPE
7335 : 104503094 : && !null_pointer_constant_p (value))
7336 : : {
7337 : 2924948 : addr_space_t as_to = TYPE_ADDR_SPACE (TREE_TYPE (type));
7338 : 2924948 : addr_space_t as_from = TYPE_ADDR_SPACE (TREE_TYPE (otype));
7339 : 2924948 : addr_space_t as_common;
7340 : :
7341 : 2924948 : if (!addr_space_superset (as_to, as_from, &as_common))
7342 : : {
7343 : 0 : if (ADDR_SPACE_GENERIC_P (as_from))
7344 : 0 : warning_at (loc, 0, "cast to %qs address space pointer "
7345 : : "from disjoint generic address space pointer",
7346 : : c_addr_space_name (as_to));
7347 : :
7348 : 0 : else if (ADDR_SPACE_GENERIC_P (as_to))
7349 : 0 : warning_at (loc, 0, "cast to generic address space pointer "
7350 : : "from disjoint %qs address space pointer",
7351 : : c_addr_space_name (as_from));
7352 : :
7353 : : else
7354 : 0 : warning_at (loc, 0, "cast to %qs address space pointer "
7355 : : "from disjoint %qs address space pointer",
7356 : : c_addr_space_name (as_to),
7357 : : c_addr_space_name (as_from));
7358 : : }
7359 : :
7360 : : /* Warn of new allocations that are not big enough for the target
7361 : : type. */
7362 : 2924948 : if (warn_alloc_size && TREE_CODE (value) == CALL_EXPR)
7363 : 805 : if (tree fndecl = get_callee_fndecl (value))
7364 : 801 : if (DECL_IS_MALLOC (fndecl))
7365 : : {
7366 : 517 : tree attrs = TYPE_ATTRIBUTES (TREE_TYPE (fndecl));
7367 : 517 : tree alloc_size = lookup_attribute ("alloc_size", attrs);
7368 : 517 : if (alloc_size)
7369 : 159 : warn_for_alloc_size (loc, TREE_TYPE (type), value,
7370 : : alloc_size);
7371 : : }
7372 : : }
7373 : :
7374 : : /* Warn about possible alignment problems. */
7375 : 101524881 : if ((STRICT_ALIGNMENT || warn_cast_align == 2)
7376 : 7 : && TREE_CODE (type) == POINTER_TYPE
7377 : 7 : && TREE_CODE (otype) == POINTER_TYPE
7378 : 7 : && TREE_CODE (TREE_TYPE (otype)) != VOID_TYPE
7379 : 7 : && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
7380 : : /* Don't warn about opaque types, where the actual alignment
7381 : : restriction is unknown. */
7382 : 12 : && !(RECORD_OR_UNION_TYPE_P (TREE_TYPE (otype))
7383 : 5 : && TYPE_MODE (TREE_TYPE (otype)) == VOIDmode)
7384 : 101524895 : && min_align_of_type (TREE_TYPE (type))
7385 : 7 : > min_align_of_type (TREE_TYPE (otype)))
7386 : 5 : warning_at (loc, OPT_Wcast_align,
7387 : : "cast increases required alignment of target type");
7388 : :
7389 : 101524881 : if ((TREE_CODE (type) == INTEGER_TYPE
7390 : 101524881 : || TREE_CODE (type) == BITINT_TYPE)
7391 : 7049025 : && TREE_CODE (otype) == POINTER_TYPE
7392 : 101550046 : && TYPE_PRECISION (type) != TYPE_PRECISION (otype))
7393 : : /* Unlike conversion of integers to pointers, where the
7394 : : warning is disabled for converting constants because
7395 : : of cases such as SIG_*, warn about converting constant
7396 : : pointers to integers. In some cases it may cause unwanted
7397 : : sign extension, and a warning is appropriate. */
7398 : 1450 : warning_at (loc, OPT_Wpointer_to_int_cast,
7399 : : "cast from pointer to integer of different size");
7400 : :
7401 : 101524881 : if (TREE_CODE (value) == CALL_EXPR
7402 : 34480796 : && TREE_CODE (type) != TREE_CODE (otype))
7403 : 2282 : warning_at (loc, OPT_Wbad_function_cast,
7404 : : "cast from function call of type %qT "
7405 : : "to non-matching type %qT", otype, type);
7406 : :
7407 : 101524881 : if (TREE_CODE (type) == POINTER_TYPE
7408 : 3321577 : && (TREE_CODE (otype) == INTEGER_TYPE
7409 : 3321577 : || TREE_CODE (otype) == BITINT_TYPE)
7410 : 343278 : && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
7411 : : /* Don't warn about converting any constant. */
7412 : 101830998 : && !TREE_CONSTANT (value))
7413 : 407 : warning_at (loc,
7414 : 407 : OPT_Wint_to_pointer_cast, "cast to pointer from integer "
7415 : : "of different size");
7416 : :
7417 : 101524881 : if (warn_strict_aliasing <= 2)
7418 : 93011217 : strict_aliasing_warning (EXPR_LOCATION (value), type, expr);
7419 : :
7420 : : /* If pedantic, warn for conversions between function and object
7421 : : pointer types, except for converting a null pointer constant
7422 : : to function pointer type. */
7423 : 101524881 : if (pedantic
7424 : 238829 : && TREE_CODE (type) == POINTER_TYPE
7425 : 144179 : && TREE_CODE (otype) == POINTER_TYPE
7426 : 2781 : && TREE_CODE (TREE_TYPE (otype)) == FUNCTION_TYPE
7427 : 101524902 : && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE)
7428 : 18 : pedwarn (loc, OPT_Wpedantic, "ISO C forbids "
7429 : : "conversion of function pointer to object pointer type");
7430 : :
7431 : 101524881 : if (pedantic
7432 : 238829 : && TREE_CODE (type) == POINTER_TYPE
7433 : 144179 : && TREE_CODE (otype) == POINTER_TYPE
7434 : 2781 : && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
7435 : 13 : && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
7436 : 101524891 : && !null_pointer_constant_p (value))
7437 : 4 : pedwarn (loc, OPT_Wpedantic, "ISO C forbids "
7438 : : "conversion of object pointer to function pointer type");
7439 : :
7440 : 101524881 : if (TREE_CODE (type) == POINTER_TYPE
7441 : 3321577 : && TREE_CODE (otype) == POINTER_TYPE
7442 : 2978213 : && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
7443 : 8502 : && TREE_CODE (TREE_TYPE (otype)) == FUNCTION_TYPE
7444 : 101532315 : && !c_safe_function_type_cast_p (TREE_TYPE (type),
7445 : 7434 : TREE_TYPE (otype)))
7446 : 800 : warning_at (loc, OPT_Wcast_function_type,
7447 : : "cast between incompatible function types"
7448 : : " from %qT to %qT", otype, type);
7449 : :
7450 : 101524881 : ovalue = value;
7451 : : /* If converting to boolean a value with integer operands that
7452 : : is not itself represented as an INTEGER_CST, the call below
7453 : : to note_integer_operands may insert a C_MAYBE_CONST_EXPR, but
7454 : : build_binary_op as called by c_common_truthvalue_conversion
7455 : : may also insert a C_MAYBE_CONST_EXPR to indicate that a
7456 : : subexpression has been fully folded. To avoid nested
7457 : : C_MAYBE_CONST_EXPR, ensure that
7458 : : c_objc_common_truthvalue_conversion receives an argument
7459 : : properly marked as having integer operands in that case. */
7460 : 101524881 : if (int_operands
7461 : 6644090 : && TREE_CODE (value) != INTEGER_CST
7462 : 101524923 : && (TREE_CODE (type) == BOOLEAN_TYPE
7463 : 28 : || (TREE_CODE (type) == ENUMERAL_TYPE
7464 : 14 : && ENUM_UNDERLYING_TYPE (type) != NULL_TREE
7465 : 14 : && TREE_CODE (ENUM_UNDERLYING_TYPE (type)) == BOOLEAN_TYPE)))
7466 : 28 : value = note_integer_operands (value);
7467 : 101524881 : value = convert (type, value);
7468 : :
7469 : : /* Ignore any integer overflow caused by the cast. */
7470 : 101524881 : if (TREE_CODE (value) == INTEGER_CST && !FLOAT_TYPE_P (otype))
7471 : : {
7472 : 6590322 : if (TREE_OVERFLOW_P (ovalue))
7473 : : {
7474 : 9 : if (!TREE_OVERFLOW (value))
7475 : : {
7476 : : /* Avoid clobbering a shared constant. */
7477 : 0 : value = copy_node (value);
7478 : 0 : TREE_OVERFLOW (value) = TREE_OVERFLOW (ovalue);
7479 : : }
7480 : : }
7481 : 6590313 : else if (TREE_OVERFLOW (value))
7482 : : /* Reset VALUE's overflow flags, ensuring constant sharing. */
7483 : 3085 : value = wide_int_to_tree (TREE_TYPE (value), wi::to_wide (value));
7484 : : }
7485 : : }
7486 : :
7487 : : /* Don't let a cast be an lvalue. */
7488 : 119522021 : if (lvalue_p (value))
7489 : 90301 : value = non_lvalue_loc (loc, value);
7490 : :
7491 : : /* Don't allow the results of casting to floating-point or complex
7492 : : types be confused with actual constants, or casts involving
7493 : : integer and pointer types other than direct integer-to-integer
7494 : : and integer-to-pointer be confused with integer constant
7495 : : expressions and null pointer constants. */
7496 : 119522021 : if (TREE_CODE (value) == REAL_CST
7497 : 119472138 : || TREE_CODE (value) == COMPLEX_CST
7498 : 238971536 : || (TREE_CODE (value) == INTEGER_CST
7499 : 6837628 : && !((TREE_CODE (expr) == INTEGER_CST
7500 : 6764623 : && INTEGRAL_TYPE_P (TREE_TYPE (expr)))
7501 : 65602 : || TREE_CODE (expr) == REAL_CST
7502 : : || TREE_CODE (expr) == COMPLEX_CST)))
7503 : 133741 : value = build1 (NOP_EXPR, type, value);
7504 : :
7505 : : /* If the expression has integer operands and so can occur in an
7506 : : unevaluated part of an integer constant expression, ensure the
7507 : : return value reflects this. */
7508 : 119522021 : if (int_operands
7509 : 6819330 : && INTEGRAL_TYPE_P (type)
7510 : 6376518 : && value != error_mark_node
7511 : 125898538 : && !EXPR_INT_CONST_OPERANDS (value))
7512 : 11 : value = note_integer_operands (value);
7513 : :
7514 : 119522021 : protected_set_expr_location (value, loc);
7515 : 119522021 : return value;
7516 : : }
7517 : :
7518 : : /* Interpret a cast of expression EXPR to type TYPE. LOC is the
7519 : : location of the open paren of the cast, or the position of the cast
7520 : : expr. */
7521 : : tree
7522 : 119540829 : c_cast_expr (location_t loc, struct c_type_name *type_name, tree expr)
7523 : : {
7524 : 119540829 : tree type;
7525 : 119540829 : tree type_expr = NULL_TREE;
7526 : 119540829 : bool type_expr_const = true;
7527 : 119540829 : tree ret;
7528 : 119540829 : int saved_wsp = warn_strict_prototypes;
7529 : :
7530 : : /* This avoids warnings about unprototyped casts on
7531 : : integers. E.g. "#define SIG_DFL (void(*)())0". */
7532 : 119540829 : if (TREE_CODE (expr) == INTEGER_CST)
7533 : 6886539 : warn_strict_prototypes = 0;
7534 : 119540829 : type = groktypename (type_name, &type_expr, &type_expr_const);
7535 : 119540829 : warn_strict_prototypes = saved_wsp;
7536 : :
7537 : 764667 : if (TREE_CODE (expr) == ADDR_EXPR && !VOID_TYPE_P (type)
7538 : 120305259 : && reject_gcc_builtin (expr))
7539 : 2 : return error_mark_node;
7540 : :
7541 : 119540827 : ret = build_c_cast (loc, type, expr);
7542 : 119540827 : if (ret == error_mark_node)
7543 : : return error_mark_node;
7544 : :
7545 : 119539665 : if (type_expr)
7546 : : {
7547 : 249 : bool inner_expr_const = true;
7548 : 249 : ret = c_fully_fold (ret, require_constant_value, &inner_expr_const);
7549 : 249 : ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret), type_expr, ret);
7550 : 498 : C_MAYBE_CONST_EXPR_NON_CONST (ret) = !(type_expr_const
7551 : 145 : && inner_expr_const);
7552 : 249 : SET_EXPR_LOCATION (ret, loc);
7553 : : }
7554 : :
7555 : 119539665 : if (!EXPR_HAS_LOCATION (ret))
7556 : 6765577 : protected_set_expr_location (ret, loc);
7557 : :
7558 : : /* C++ does not permits types to be defined in a cast, but it
7559 : : allows references to incomplete types. */
7560 : 119539665 : if (warn_cxx_compat && type_name->specs->typespec_kind == ctsk_tagdef)
7561 : 1 : warning_at (loc, OPT_Wc___compat,
7562 : : "defining a type in a cast is invalid in C++");
7563 : :
7564 : : return ret;
7565 : : }
7566 : :
7567 : : /* Build an assignment expression of lvalue LHS from value RHS.
7568 : : If LHS_ORIGTYPE is not NULL, it is the original type of LHS, which
7569 : : may differ from TREE_TYPE (LHS) for an enum bitfield.
7570 : : MODIFYCODE is the code for a binary operator that we use
7571 : : to combine the old value of LHS with RHS to get the new value.
7572 : : Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.
7573 : : If RHS_ORIGTYPE is not NULL_TREE, it is the original type of RHS,
7574 : : which may differ from TREE_TYPE (RHS) for an enum value.
7575 : :
7576 : : LOCATION is the location of the MODIFYCODE operator.
7577 : : RHS_LOC is the location of the RHS. */
7578 : :
7579 : : tree
7580 : 2887428 : build_modify_expr (location_t location, tree lhs, tree lhs_origtype,
7581 : : enum tree_code modifycode,
7582 : : location_t rhs_loc, tree rhs, tree rhs_origtype)
7583 : : {
7584 : 2887428 : tree result;
7585 : 2887428 : tree newrhs;
7586 : 2887428 : tree rhseval = NULL_TREE;
7587 : 2887428 : tree lhstype = TREE_TYPE (lhs);
7588 : 2887428 : tree olhstype = lhstype;
7589 : 2887428 : bool npc;
7590 : 2887428 : bool is_atomic_op;
7591 : :
7592 : : /* Types that aren't fully specified cannot be used in assignments. */
7593 : 2887428 : lhs = require_complete_type (location, lhs);
7594 : 2887428 : rhs = require_complete_type (location, rhs);
7595 : :
7596 : : /* Avoid duplicate error messages from operands that had errors. */
7597 : 2887428 : if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK)
7598 : 473 : return error_mark_node;
7599 : :
7600 : : /* Ensure an error for assigning a non-lvalue array to an array in
7601 : : C90. */
7602 : 2886955 : if (TREE_CODE (lhstype) == ARRAY_TYPE)
7603 : : {
7604 : 1 : error_at (location, "assignment to expression with array type");
7605 : 1 : return error_mark_node;
7606 : : }
7607 : :
7608 : : /* For ObjC properties, defer this check. */
7609 : 2886954 : if (!objc_is_property_ref (lhs) && !lvalue_or_else (location, lhs, lv_assign))
7610 : 31 : return error_mark_node;
7611 : :
7612 : 2886923 : is_atomic_op = really_atomic_lvalue (lhs);
7613 : :
7614 : 2886923 : newrhs = rhs;
7615 : :
7616 : 2886923 : if (TREE_CODE (lhs) == C_MAYBE_CONST_EXPR)
7617 : : {
7618 : 2 : tree inner = build_modify_expr (location, C_MAYBE_CONST_EXPR_EXPR (lhs),
7619 : : lhs_origtype, modifycode, rhs_loc, rhs,
7620 : : rhs_origtype);
7621 : 2 : if (inner == error_mark_node)
7622 : : return error_mark_node;
7623 : 4 : result = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (inner),
7624 : 2 : C_MAYBE_CONST_EXPR_PRE (lhs), inner);
7625 : 2 : gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (lhs));
7626 : 2 : C_MAYBE_CONST_EXPR_NON_CONST (result) = 1;
7627 : 2 : protected_set_expr_location (result, location);
7628 : 2 : return result;
7629 : : }
7630 : :
7631 : : /* If a binary op has been requested, combine the old LHS value with the RHS
7632 : : producing the value we should actually store into the LHS. */
7633 : :
7634 : 2886921 : if (modifycode != NOP_EXPR)
7635 : : {
7636 : 213890 : lhs = c_fully_fold (lhs, false, NULL, true);
7637 : 213890 : lhs = stabilize_reference (lhs);
7638 : :
7639 : : /* Construct the RHS for any non-atomic compound assignemnt. */
7640 : 213890 : if (!is_atomic_op)
7641 : : {
7642 : : /* If in LHS op= RHS the RHS has side-effects, ensure they
7643 : : are preevaluated before the rest of the assignment expression's
7644 : : side-effects, because RHS could contain e.g. function calls
7645 : : that modify LHS. */
7646 : 198405 : if (TREE_SIDE_EFFECTS (rhs))
7647 : : {
7648 : 8623 : if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
7649 : 28 : newrhs = save_expr (TREE_OPERAND (rhs, 0));
7650 : : else
7651 : 8595 : newrhs = save_expr (rhs);
7652 : 8623 : rhseval = newrhs;
7653 : 8623 : if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
7654 : 28 : newrhs = build1 (EXCESS_PRECISION_EXPR, TREE_TYPE (rhs),
7655 : : newrhs);
7656 : : }
7657 : 198405 : bool clear_decl_read = false;
7658 : 87968 : if ((VAR_P (lhs) || TREE_CODE (lhs) == PARM_DECL)
7659 : 152456 : && !DECL_READ_P (lhs)
7660 : 250272 : && (VAR_P (lhs) ? warn_unused_but_set_variable
7661 : : : warn_unused_but_set_parameter) > 2)
7662 : : {
7663 : 21550 : mark_exp_read (newrhs);
7664 : 21550 : if (!DECL_READ_P (lhs))
7665 : 198405 : clear_decl_read = true;
7666 : : }
7667 : :
7668 : 198405 : newrhs = build_binary_op (location, modifycode,
7669 : : convert_lvalue_to_rvalue (location, lhs,
7670 : : true, true),
7671 : : newrhs, true);
7672 : 198405 : if (clear_decl_read)
7673 : 21550 : DECL_READ_P (lhs) = 0;
7674 : :
7675 : : /* The original type of the right hand side is no longer
7676 : : meaningful. */
7677 : : rhs_origtype = NULL_TREE;
7678 : : }
7679 : : }
7680 : :
7681 : 2886921 : if (c_dialect_objc ())
7682 : : {
7683 : : /* Check if we are modifying an Objective-C property reference;
7684 : : if so, we need to generate setter calls. */
7685 : 0 : if (TREE_CODE (newrhs) == EXCESS_PRECISION_EXPR)
7686 : 0 : result = objc_maybe_build_modify_expr (lhs, TREE_OPERAND (newrhs, 0));
7687 : : else
7688 : 0 : result = objc_maybe_build_modify_expr (lhs, newrhs);
7689 : 0 : if (result)
7690 : 0 : goto return_result;
7691 : :
7692 : : /* Else, do the check that we postponed for Objective-C. */
7693 : 0 : if (!lvalue_or_else (location, lhs, lv_assign))
7694 : 0 : return error_mark_node;
7695 : : }
7696 : :
7697 : : /* Give an error for storing in something that is 'const'. */
7698 : :
7699 : 2886921 : if (TYPE_READONLY (lhstype)
7700 : 2886921 : || (RECORD_OR_UNION_TYPE_P (lhstype)
7701 : 25545 : && C_TYPE_FIELDS_READONLY (lhstype)))
7702 : : {
7703 : 88 : readonly_error (location, lhs, lv_assign);
7704 : 88 : return error_mark_node;
7705 : : }
7706 : 2886833 : else if (TREE_READONLY (lhs))
7707 : 1 : readonly_warning (lhs, lv_assign);
7708 : :
7709 : : /* If storing into a structure or union member,
7710 : : it has probably been given type `int'.
7711 : : Compute the type that would go with
7712 : : the actual amount of storage the member occupies. */
7713 : :
7714 : 2886833 : if (TREE_CODE (lhs) == COMPONENT_REF
7715 : 247818 : && (TREE_CODE (lhstype) == INTEGER_TYPE
7716 : 247818 : || TREE_CODE (lhstype) == BOOLEAN_TYPE
7717 : 109344 : || SCALAR_FLOAT_TYPE_P (lhstype)
7718 : 86050 : || TREE_CODE (lhstype) == ENUMERAL_TYPE))
7719 : 168752 : lhstype = TREE_TYPE (get_unwidened (lhs, 0));
7720 : :
7721 : : /* If storing in a field that is in actuality a short or narrower than one,
7722 : : we must store in the field in its actual type. */
7723 : :
7724 : 2886833 : if (lhstype != TREE_TYPE (lhs))
7725 : : {
7726 : 0 : lhs = copy_node (lhs);
7727 : 0 : TREE_TYPE (lhs) = lhstype;
7728 : : }
7729 : :
7730 : : /* Issue -Wc++-compat warnings about an assignment to an enum type
7731 : : when LHS does not have its original type. This happens for,
7732 : : e.g., an enum bitfield in a struct. */
7733 : 2886833 : if (warn_cxx_compat
7734 : 3195 : && lhs_origtype != NULL_TREE
7735 : 3195 : && lhs_origtype != lhstype
7736 : 7 : && TREE_CODE (lhs_origtype) == ENUMERAL_TYPE)
7737 : : {
7738 : 4 : tree checktype = (rhs_origtype != NULL_TREE
7739 : 4 : ? rhs_origtype
7740 : 0 : : TREE_TYPE (rhs));
7741 : 4 : if (checktype != error_mark_node
7742 : 4 : && (TYPE_MAIN_VARIANT (checktype) != TYPE_MAIN_VARIANT (lhs_origtype)
7743 : 2 : || (is_atomic_op && modifycode != NOP_EXPR)))
7744 : 2 : warning_at (location, OPT_Wc___compat,
7745 : : "enum conversion in assignment is invalid in C++");
7746 : : }
7747 : :
7748 : : /* Remove qualifiers. */
7749 : 2886833 : lhstype = c_build_qualified_type (lhstype, TYPE_UNQUALIFIED);
7750 : 2886833 : olhstype = c_build_qualified_type (olhstype, TYPE_UNQUALIFIED);
7751 : :
7752 : : /* Convert new value to destination type. Fold it first, then
7753 : : restore any excess precision information, for the sake of
7754 : : conversion warnings. */
7755 : :
7756 : 2886833 : if (!(is_atomic_op && modifycode != NOP_EXPR))
7757 : : {
7758 : 2871348 : tree rhs_semantic_type = NULL_TREE;
7759 : 2871348 : if (!c_in_omp_for)
7760 : : {
7761 : 2855044 : if (TREE_CODE (newrhs) == EXCESS_PRECISION_EXPR)
7762 : : {
7763 : 5069 : rhs_semantic_type = TREE_TYPE (newrhs);
7764 : 5069 : newrhs = TREE_OPERAND (newrhs, 0);
7765 : : }
7766 : 2855044 : npc = null_pointer_constant_p (newrhs);
7767 : 2855044 : newrhs = c_fully_fold (newrhs, false, NULL);
7768 : 2855044 : if (rhs_semantic_type)
7769 : 5069 : newrhs = build1 (EXCESS_PRECISION_EXPR, rhs_semantic_type, newrhs);
7770 : : }
7771 : : else
7772 : 16304 : npc = null_pointer_constant_p (newrhs);
7773 : 2871348 : newrhs = convert_for_assignment (location, rhs_loc, lhstype, newrhs,
7774 : : rhs_origtype, ic_assign, npc,
7775 : : NULL_TREE, NULL_TREE, 0);
7776 : 2871348 : if (TREE_CODE (newrhs) == ERROR_MARK)
7777 : 127 : return error_mark_node;
7778 : : }
7779 : :
7780 : : /* Emit ObjC write barrier, if necessary. */
7781 : 2886706 : if (c_dialect_objc () && flag_objc_gc)
7782 : : {
7783 : 0 : result = objc_generate_write_barrier (lhs, modifycode, newrhs);
7784 : 0 : if (result)
7785 : : {
7786 : 0 : protected_set_expr_location (result, location);
7787 : 0 : goto return_result;
7788 : : }
7789 : : }
7790 : :
7791 : : /* Scan operands. */
7792 : :
7793 : 2886706 : if (is_atomic_op)
7794 : 25956 : result = build_atomic_assign (location, lhs, modifycode, newrhs, false);
7795 : : else
7796 : : {
7797 : 2860750 : result = build2 (MODIFY_EXPR, lhstype, lhs, newrhs);
7798 : 2860750 : TREE_SIDE_EFFECTS (result) = 1;
7799 : 2860750 : protected_set_expr_location (result, location);
7800 : : }
7801 : :
7802 : : /* If we got the LHS in a different type for storing in,
7803 : : convert the result back to the nominal type of LHS
7804 : : so that the value we return always has the same type
7805 : : as the LHS argument. */
7806 : :
7807 : 2886706 : if (olhstype == TREE_TYPE (result))
7808 : 2886706 : goto return_result;
7809 : :
7810 : 0 : result = convert_for_assignment (location, rhs_loc, olhstype, result,
7811 : : rhs_origtype, ic_assign, false, NULL_TREE,
7812 : : NULL_TREE, 0);
7813 : 0 : protected_set_expr_location (result, location);
7814 : :
7815 : 2886706 : return_result:
7816 : 2886706 : if (rhseval)
7817 : 8623 : result = build2 (COMPOUND_EXPR, TREE_TYPE (result), rhseval, result);
7818 : : return result;
7819 : : }
7820 : :
7821 : : /* Return whether STRUCT_TYPE has an anonymous field with type TYPE.
7822 : : This is used to implement -fplan9-extensions. */
7823 : :
7824 : : static bool
7825 : 10 : find_anonymous_field_with_type (tree struct_type, tree type)
7826 : : {
7827 : 10 : tree field;
7828 : 10 : bool found;
7829 : :
7830 : 10 : gcc_assert (RECORD_OR_UNION_TYPE_P (struct_type));
7831 : 10 : found = false;
7832 : 10 : for (field = TYPE_FIELDS (struct_type);
7833 : 20 : field != NULL_TREE;
7834 : 10 : field = TREE_CHAIN (field))
7835 : : {
7836 : 10 : tree fieldtype = remove_qualifiers (TREE_TYPE (field));
7837 : 10 : if (DECL_NAME (field) == NULL
7838 : 10 : && comptypes (type, fieldtype))
7839 : : {
7840 : 4 : if (found)
7841 : : return false;
7842 : : found = true;
7843 : : }
7844 : 6 : else if (DECL_NAME (field) == NULL
7845 : 2 : && RECORD_OR_UNION_TYPE_P (TREE_TYPE (field))
7846 : 8 : && find_anonymous_field_with_type (TREE_TYPE (field), type))
7847 : : {
7848 : 0 : if (found)
7849 : : return false;
7850 : : found = true;
7851 : : }
7852 : : }
7853 : : return found;
7854 : : }
7855 : :
7856 : : /* RHS is an expression whose type is pointer to struct. If there is
7857 : : an anonymous field in RHS with type TYPE, then return a pointer to
7858 : : that field in RHS. This is used with -fplan9-extensions. This
7859 : : returns NULL if no conversion could be found. */
7860 : :
7861 : : static tree
7862 : 12 : convert_to_anonymous_field (location_t location, tree type, tree rhs)
7863 : : {
7864 : 12 : tree rhs_struct_type, lhs_main_type;
7865 : 12 : tree field, found_field;
7866 : 12 : bool found_sub_field;
7867 : 12 : tree ret;
7868 : :
7869 : 12 : gcc_assert (POINTER_TYPE_P (TREE_TYPE (rhs)));
7870 : 12 : rhs_struct_type = TREE_TYPE (TREE_TYPE (rhs));
7871 : 12 : gcc_assert (RECORD_OR_UNION_TYPE_P (rhs_struct_type));
7872 : :
7873 : 12 : gcc_assert (POINTER_TYPE_P (type));
7874 : 12 : lhs_main_type = remove_qualifiers (TREE_TYPE (type));
7875 : :
7876 : 12 : found_field = NULL_TREE;
7877 : 12 : found_sub_field = false;
7878 : 12 : for (field = TYPE_FIELDS (rhs_struct_type);
7879 : 44 : field != NULL_TREE;
7880 : 32 : field = TREE_CHAIN (field))
7881 : : {
7882 : 36 : if (DECL_NAME (field) != NULL_TREE
7883 : 36 : || !RECORD_OR_UNION_TYPE_P (TREE_TYPE (field)))
7884 : 16 : continue;
7885 : 20 : tree fieldtype = remove_qualifiers (TREE_TYPE (field));
7886 : 20 : if (comptypes (lhs_main_type, fieldtype))
7887 : : {
7888 : 12 : if (found_field != NULL_TREE)
7889 : : return NULL_TREE;
7890 : : found_field = field;
7891 : : }
7892 : 8 : else if (find_anonymous_field_with_type (TREE_TYPE (field),
7893 : : lhs_main_type))
7894 : : {
7895 : 4 : if (found_field != NULL_TREE)
7896 : : return NULL_TREE;
7897 : : found_field = field;
7898 : : found_sub_field = true;
7899 : : }
7900 : : }
7901 : :
7902 : 8 : if (found_field == NULL_TREE)
7903 : : return NULL_TREE;
7904 : :
7905 : 8 : ret = fold_build3_loc (location, COMPONENT_REF, TREE_TYPE (found_field),
7906 : : build_fold_indirect_ref (rhs), found_field,
7907 : : NULL_TREE);
7908 : 8 : ret = build_fold_addr_expr_loc (location, ret);
7909 : :
7910 : 8 : if (found_sub_field)
7911 : : {
7912 : 2 : ret = convert_to_anonymous_field (location, type, ret);
7913 : 2 : gcc_assert (ret != NULL_TREE);
7914 : : }
7915 : :
7916 : : return ret;
7917 : : }
7918 : :
7919 : : /* Issue an error message for a bad initializer component.
7920 : : GMSGID identifies the message.
7921 : : The component name is taken from the spelling stack. */
7922 : :
7923 : : static void ATTRIBUTE_GCC_DIAG (2,0)
7924 : 944 : error_init (location_t loc, const char *gmsgid, ...)
7925 : : {
7926 : 944 : char *ofwhat;
7927 : :
7928 : 944 : auto_diagnostic_group d;
7929 : :
7930 : : /* The gmsgid may be a format string with %< and %>. */
7931 : 944 : va_list ap;
7932 : 944 : va_start (ap, gmsgid);
7933 : 944 : bool warned = emit_diagnostic_valist (diagnostics::kind::error,
7934 : 944 : loc, -1, gmsgid, &ap);
7935 : 944 : va_end (ap);
7936 : :
7937 : 944 : ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
7938 : 944 : if (*ofwhat && warned)
7939 : 220 : inform (loc, "(near initialization for %qs)", ofwhat);
7940 : 944 : }
7941 : :
7942 : : /* Used to implement pedwarn_init and permerror_init. */
7943 : :
7944 : : static bool ATTRIBUTE_GCC_DIAG (3,0)
7945 : 2537 : pedwarn_permerror_init (location_t loc, int opt, const char *gmsgid,
7946 : : va_list *ap, enum diagnostics::kind kind)
7947 : : {
7948 : : /* Use the location where a macro was expanded rather than where
7949 : : it was defined to make sure macros defined in system headers
7950 : : but used incorrectly elsewhere are diagnosed. */
7951 : 2537 : location_t exploc = expansion_point_location_if_in_system_header (loc);
7952 : 2537 : auto_diagnostic_group d;
7953 : 2537 : bool warned = emit_diagnostic_valist (kind, exploc, opt, gmsgid, ap);
7954 : 2537 : if (warned)
7955 : : {
7956 : 1815 : char *ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
7957 : 1815 : if (*ofwhat)
7958 : 1494 : inform (exploc, "(near initialization for %qs)", ofwhat);
7959 : : }
7960 : 5074 : return warned;
7961 : 2537 : }
7962 : :
7963 : : /* Issue a pedantic warning for a bad initializer component. OPT is
7964 : : the option OPT_* (from options.h) controlling this warning or 0 if
7965 : : it is unconditionally given. GMSGID identifies the message. The
7966 : : component name is taken from the spelling stack. */
7967 : :
7968 : : static bool ATTRIBUTE_GCC_DIAG (3,0)
7969 : 2186 : pedwarn_init (location_t loc, int opt, const char *gmsgid, ...)
7970 : : {
7971 : 2186 : va_list ap;
7972 : 2186 : va_start (ap, gmsgid);
7973 : 2186 : bool warned = pedwarn_permerror_init (loc, opt, gmsgid, &ap,
7974 : : diagnostics::kind::pedwarn);
7975 : 2186 : va_end (ap);
7976 : 2186 : return warned;
7977 : : }
7978 : :
7979 : : /* Like pedwarn_init, but issue a permerror. */
7980 : :
7981 : : static bool ATTRIBUTE_GCC_DIAG (3,0)
7982 : 351 : permerror_init (location_t loc, int opt, const char *gmsgid, ...)
7983 : : {
7984 : 351 : va_list ap;
7985 : 351 : va_start (ap, gmsgid);
7986 : 351 : bool warned = pedwarn_permerror_init (loc, opt, gmsgid, &ap,
7987 : : diagnostics::kind::permerror);
7988 : 351 : va_end (ap);
7989 : 351 : return warned;
7990 : : }
7991 : :
7992 : : /* Issue a warning for a bad initializer component.
7993 : :
7994 : : OPT is the OPT_W* value corresponding to the warning option that
7995 : : controls this warning. GMSGID identifies the message. The
7996 : : component name is taken from the spelling stack. */
7997 : :
7998 : : static void
7999 : 146 : warning_init (location_t loc, int opt, const char *gmsgid)
8000 : : {
8001 : 146 : char *ofwhat;
8002 : 146 : bool warned;
8003 : :
8004 : 146 : auto_diagnostic_group d;
8005 : :
8006 : : /* Use the location where a macro was expanded rather than where
8007 : : it was defined to make sure macros defined in system headers
8008 : : but used incorrectly elsewhere are diagnosed. */
8009 : 146 : location_t exploc = expansion_point_location_if_in_system_header (loc);
8010 : :
8011 : : /* The gmsgid may be a format string with %< and %>. */
8012 : 146 : warned = warning_at (exploc, opt, gmsgid);
8013 : 146 : if (warned)
8014 : : {
8015 : 133 : ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
8016 : 133 : if (*ofwhat)
8017 : 133 : inform (exploc, "(near initialization for %qs)", ofwhat);
8018 : : }
8019 : 146 : }
8020 : :
8021 : : /* If TYPE is an array type and EXPR is a parenthesized string
8022 : : constant, warn if pedantic that EXPR is being used to initialize an
8023 : : object of type TYPE. */
8024 : :
8025 : : void
8026 : 7253565 : maybe_warn_string_init (location_t loc, tree type, struct c_expr expr)
8027 : : {
8028 : 7253565 : if (pedantic
8029 : 80455 : && TREE_CODE (type) == ARRAY_TYPE
8030 : 1145 : && TREE_CODE (expr.value) == STRING_CST
8031 : 472 : && expr.original_code != STRING_CST)
8032 : 13 : pedwarn_init (loc, OPT_Wpedantic,
8033 : : "array initialized from parenthesized string constant");
8034 : 7253565 : }
8035 : :
8036 : : /* Attempt to locate the parameter with the given index within FNDECL,
8037 : : returning DECL_SOURCE_LOCATION (FNDECL) if it can't be found. */
8038 : :
8039 : : static location_t
8040 : 936 : get_fndecl_argument_location (tree fndecl, int argnum)
8041 : : {
8042 : 936 : int i;
8043 : 936 : tree param;
8044 : :
8045 : : /* Locate param by index within DECL_ARGUMENTS (fndecl). */
8046 : 936 : for (i = 0, param = DECL_ARGUMENTS (fndecl);
8047 : 1015 : i < argnum && param;
8048 : 79 : i++, param = TREE_CHAIN (param))
8049 : : ;
8050 : :
8051 : : /* If something went wrong (e.g. if we have a builtin and thus no arguments),
8052 : : return DECL_SOURCE_LOCATION (FNDECL). */
8053 : 936 : if (param == NULL)
8054 : 653 : return DECL_SOURCE_LOCATION (fndecl);
8055 : :
8056 : 283 : return DECL_SOURCE_LOCATION (param);
8057 : : }
8058 : :
8059 : : /* Issue a note about a mismatching argument for parameter PARMNUM
8060 : : to FUNDECL, for types EXPECTED_TYPE and ACTUAL_TYPE.
8061 : : Attempt to issue the note at the pertinent parameter of the decl;
8062 : : failing that issue it at the location of FUNDECL; failing that
8063 : : issue it at PLOC.
8064 : : Use highlight_colors::actual for the ACTUAL_TYPE
8065 : : and highlight_colors::expected for EXPECTED_TYPE and the
8066 : : parameter of FUNDECL*/
8067 : :
8068 : : static void
8069 : 1060 : inform_for_arg (tree fundecl, location_t ploc, int parmnum,
8070 : : tree expected_type, tree actual_type)
8071 : : {
8072 : 1060 : location_t loc;
8073 : 1060 : if (fundecl && !DECL_IS_UNDECLARED_BUILTIN (fundecl))
8074 : 936 : loc = get_fndecl_argument_location (fundecl, parmnum - 1);
8075 : : else
8076 : : loc = ploc;
8077 : :
8078 : 1060 : gcc_rich_location richloc (loc, nullptr, highlight_colors::expected);
8079 : :
8080 : 1060 : pp_markup::element_expected_type elem_expected_type (expected_type);
8081 : 1060 : pp_markup::element_actual_type elem_actual_type (actual_type);
8082 : 1060 : inform (&richloc,
8083 : : "expected %e but argument is of type %e",
8084 : : &elem_expected_type, &elem_actual_type);
8085 : 1060 : }
8086 : :
8087 : : /* Issue a warning when an argument of ARGTYPE is passed to a built-in
8088 : : function FUNDECL declared without prototype to parameter PARMNUM of
8089 : : PARMTYPE when ARGTYPE does not promote to PARMTYPE. */
8090 : :
8091 : : static void
8092 : 418 : maybe_warn_builtin_no_proto_arg (location_t loc, tree fundecl, int parmnum,
8093 : : tree parmtype, tree argtype)
8094 : : {
8095 : 418 : tree_code parmcode = TREE_CODE (parmtype);
8096 : 418 : tree_code argcode = TREE_CODE (argtype);
8097 : 418 : tree promoted = c_type_promotes_to (argtype);
8098 : :
8099 : : /* Avoid warning for enum arguments that promote to an integer type
8100 : : of the same size/mode. */
8101 : 418 : if (parmcode == INTEGER_TYPE
8102 : 418 : && argcode == ENUMERAL_TYPE
8103 : 418 : && TYPE_MODE (parmtype) == TYPE_MODE (argtype))
8104 : : return;
8105 : :
8106 : 417 : if ((parmcode == argcode
8107 : 222 : || (parmcode == INTEGER_TYPE
8108 : : && argcode == ENUMERAL_TYPE))
8109 : 418 : && TYPE_MAIN_VARIANT (parmtype) == TYPE_MAIN_VARIANT (promoted))
8110 : : return;
8111 : :
8112 : : /* This diagnoses even signed/unsigned mismatches. Those might be
8113 : : safe in many cases but GCC may emit suboptimal code for them so
8114 : : warning on those cases drives efficiency improvements. */
8115 : 398 : if (warning_at (loc, OPT_Wbuiltin_declaration_mismatch,
8116 : 398 : TYPE_MAIN_VARIANT (promoted) == argtype
8117 : : ? G_("%qD argument %d type is %qT where %qT is expected "
8118 : : "in a call to built-in function declared without "
8119 : : "prototype")
8120 : : : G_("%qD argument %d promotes to %qT where %qT is expected "
8121 : : "in a call to built-in function declared without "
8122 : : "prototype"),
8123 : : fundecl, parmnum, promoted, parmtype))
8124 : 150 : inform (DECL_SOURCE_LOCATION (fundecl),
8125 : : "built-in %qD declared here",
8126 : : fundecl);
8127 : : }
8128 : :
8129 : : /* Print a declaration in quotes, with the given highlight_color.
8130 : : Analogous to handler for %qD, but with a specific highlight color. */
8131 : :
8132 : 199 : class pp_element_quoted_decl : public pp_element
8133 : : {
8134 : : public:
8135 : 199 : pp_element_quoted_decl (tree decl, const char *highlight_color)
8136 : 199 : : m_decl (decl),
8137 : 199 : m_highlight_color (highlight_color)
8138 : : {
8139 : : }
8140 : :
8141 : 199 : void add_to_phase_2 (pp_markup::context &ctxt) override
8142 : : {
8143 : 199 : ctxt.begin_quote ();
8144 : 199 : ctxt.begin_highlight_color (m_highlight_color);
8145 : :
8146 : 199 : print_decl (ctxt);
8147 : :
8148 : 199 : ctxt.end_highlight_color ();
8149 : 199 : ctxt.end_quote ();
8150 : 199 : }
8151 : :
8152 : 199 : void print_decl (pp_markup::context &ctxt)
8153 : : {
8154 : 199 : pretty_printer *const pp = &ctxt.m_pp;
8155 : 199 : pp->set_padding (pp_none);
8156 : 199 : if (DECL_NAME (m_decl))
8157 : 199 : pp_identifier (pp, lang_hooks.decl_printable_name (m_decl, 2));
8158 : : else
8159 : 0 : pp_string (pp, _("({anonymous})"));
8160 : 199 : }
8161 : :
8162 : : private:
8163 : : tree m_decl;
8164 : : const char *m_highlight_color;
8165 : : };
8166 : :
8167 : : /* If TYPE is from a typedef, issue a note showing the location
8168 : : to the user.
8169 : : Use HIGHLIGHT_COLOR as the highlight color. */
8170 : :
8171 : : static void
8172 : 1178 : maybe_inform_typedef_location (tree type, const char *highlight_color)
8173 : : {
8174 : 1178 : if (!typedef_variant_p (type))
8175 : 1144 : return;
8176 : :
8177 : 34 : tree typedef_decl = TYPE_NAME (type);
8178 : 34 : gcc_assert (TREE_CODE (typedef_decl) == TYPE_DECL);
8179 : 34 : gcc_rich_location richloc (DECL_SOURCE_LOCATION (typedef_decl),
8180 : 34 : nullptr, highlight_color);
8181 : 34 : pp_element_quoted_decl e_typedef_decl (typedef_decl, highlight_color);
8182 : 34 : inform (&richloc, "%e declared here", &e_typedef_decl);
8183 : 34 : }
8184 : :
8185 : : /* Convert value RHS to type TYPE as preparation for an assignment to
8186 : : an lvalue of type TYPE. If ORIGTYPE is not NULL_TREE, it is the
8187 : : original type of RHS; this differs from TREE_TYPE (RHS) for enum
8188 : : types. NULL_POINTER_CONSTANT says whether RHS was a null pointer
8189 : : constant before any folding.
8190 : : The real work of conversion is done by `convert'.
8191 : : The purpose of this function is to generate error messages
8192 : : for assignments that are not allowed in C.
8193 : : ERRTYPE says whether it is argument passing, assignment,
8194 : : initialization or return.
8195 : :
8196 : : In the following example, '~' denotes where EXPR_LOC and '^' where
8197 : : LOCATION point to:
8198 : :
8199 : : f (var); [ic_argpass]
8200 : : ^ ~~~
8201 : : x = var; [ic_assign]
8202 : : ^ ~~~;
8203 : : int x = var; [ic_init]
8204 : : ^^^
8205 : : return x; [ic_return]
8206 : : ^
8207 : :
8208 : : FUNCTION is a tree for the function being called.
8209 : : PARMNUM is the number of the argument, for printing in error messages.
8210 : : WARNOPT may be set to a warning option to issue the corresponding warning
8211 : : rather than an error for invalid conversions. Used for calls to built-in
8212 : : functions declared without a prototype. */
8213 : :
8214 : : static tree
8215 : 166203900 : convert_for_assignment (location_t location, location_t expr_loc, tree type,
8216 : : tree rhs, tree origtype, enum impl_conv errtype,
8217 : : bool null_pointer_constant, tree fundecl,
8218 : : tree function, int parmnum, int warnopt /* = 0 */)
8219 : : {
8220 : 166203900 : enum tree_code codel = TREE_CODE (type);
8221 : 166203900 : tree orig_rhs = rhs;
8222 : 166203900 : tree rhstype;
8223 : 166203900 : enum tree_code coder;
8224 : 166203900 : tree rname = NULL_TREE;
8225 : 166203900 : bool objc_ok = false;
8226 : :
8227 : : /* Use the expansion point location to handle cases such as user's
8228 : : function returning a wrong-type macro defined in a system header. */
8229 : 166203900 : location = expansion_point_location_if_in_system_header (location);
8230 : :
8231 : 166203900 : if (errtype == ic_argpass)
8232 : : {
8233 : 124974870 : tree selector;
8234 : : /* Change pointer to function to the function itself for
8235 : : diagnostics. */
8236 : 124974870 : if (TREE_CODE (function) == ADDR_EXPR
8237 : 124974870 : && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL)
8238 : 0 : function = TREE_OPERAND (function, 0);
8239 : :
8240 : : /* Handle an ObjC selector specially for diagnostics. */
8241 : 124974870 : selector = objc_message_selector ();
8242 : 124974870 : rname = function;
8243 : 124974870 : if (selector && parmnum > 2)
8244 : : {
8245 : 0 : rname = selector;
8246 : 0 : parmnum -= 2;
8247 : : }
8248 : : }
8249 : :
8250 : : /* This macro is used to emit diagnostics to ensure that all format
8251 : : strings are complete sentences, visible to gettext and checked at
8252 : : compile time. */
8253 : : #define PEDWARN_FOR_ASSIGNMENT(LOCATION, PLOC, OPT, AR, AS, IN, RE) \
8254 : : do { \
8255 : : switch (errtype) \
8256 : : { \
8257 : : case ic_argpass: \
8258 : : { \
8259 : : auto_diagnostic_group d; \
8260 : : if (pedwarn (PLOC, OPT, AR, parmnum, rname)) \
8261 : : inform_for_arg (fundecl, (PLOC), parmnum, type, rhstype); \
8262 : : } \
8263 : : break; \
8264 : : case ic_assign: \
8265 : : pedwarn (LOCATION, OPT, AS); \
8266 : : break; \
8267 : : case ic_init: \
8268 : : case ic_init_const: \
8269 : : pedwarn_init (LOCATION, OPT, IN); \
8270 : : break; \
8271 : : case ic_return: \
8272 : : pedwarn (LOCATION, OPT, RE); \
8273 : : break; \
8274 : : default: \
8275 : : gcc_unreachable (); \
8276 : : } \
8277 : : } while (0)
8278 : :
8279 : : /* This macro is used to emit diagnostics to ensure that all format
8280 : : strings are complete sentences, visible to gettext and checked at
8281 : : compile time. It can be called with 'pedwarn' or 'warning_at'. */
8282 : : #define WARNING_FOR_QUALIFIERS(PEDWARN, LOCATION, PLOC, OPT, AR, AS, IN, RE, QUALS) \
8283 : : do { \
8284 : : switch (errtype) \
8285 : : { \
8286 : : case ic_argpass: \
8287 : : { \
8288 : : auto_diagnostic_group d; \
8289 : : if (PEDWARN) { \
8290 : : if (pedwarn (PLOC, OPT, AR, parmnum, rname, QUALS)) \
8291 : : inform_for_arg (fundecl, (PLOC), parmnum, type, rhstype); \
8292 : : } else { \
8293 : : if (warning_at (PLOC, OPT, AR, parmnum, rname, QUALS)) \
8294 : : inform_for_arg (fundecl, (PLOC), parmnum, type, rhstype); \
8295 : : } \
8296 : : } \
8297 : : break; \
8298 : : case ic_assign: \
8299 : : if (PEDWARN) \
8300 : : pedwarn (LOCATION, OPT, AS, QUALS); \
8301 : : else \
8302 : : warning_at (LOCATION, OPT, AS, QUALS); \
8303 : : break; \
8304 : : case ic_init: \
8305 : : case ic_init_const: \
8306 : : if (PEDWARN) \
8307 : : pedwarn (LOCATION, OPT, IN, QUALS); \
8308 : : else \
8309 : : warning_at (LOCATION, OPT, IN, QUALS); \
8310 : : break; \
8311 : : case ic_return: \
8312 : : if (PEDWARN) \
8313 : : pedwarn (LOCATION, OPT, RE, QUALS); \
8314 : : else \
8315 : : warning_at (LOCATION, OPT, RE, QUALS); \
8316 : : break; \
8317 : : default: \
8318 : : gcc_unreachable (); \
8319 : : } \
8320 : : } while (0)
8321 : :
8322 : : /* This macro is used to emit diagnostics to ensure that all format
8323 : : strings are complete sentences, visible to gettext and checked at
8324 : : compile time. It is the same as PEDWARN_FOR_ASSIGNMENT but with an
8325 : : extra parameter to enumerate qualifiers. */
8326 : : #define PEDWARN_FOR_QUALIFIERS(LOCATION, PLOC, OPT, AR, AS, IN, RE, QUALS) \
8327 : : WARNING_FOR_QUALIFIERS (true, LOCATION, PLOC, OPT, AR, AS, IN, RE, QUALS)
8328 : :
8329 : :
8330 : 166203900 : if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
8331 : 5967 : rhs = TREE_OPERAND (rhs, 0);
8332 : :
8333 : 166203900 : rhstype = TREE_TYPE (rhs);
8334 : 166203900 : coder = TREE_CODE (rhstype);
8335 : :
8336 : 166203900 : if (coder == ERROR_MARK)
8337 : 346 : return error_mark_node;
8338 : :
8339 : 166203554 : if (c_dialect_objc ())
8340 : : {
8341 : 0 : int parmno;
8342 : :
8343 : 0 : switch (errtype)
8344 : : {
8345 : : case ic_return:
8346 : : parmno = 0;
8347 : : break;
8348 : :
8349 : : case ic_assign:
8350 : : parmno = -1;
8351 : : break;
8352 : :
8353 : : case ic_init:
8354 : : case ic_init_const:
8355 : : parmno = -2;
8356 : : break;
8357 : :
8358 : : default:
8359 : 0 : parmno = parmnum;
8360 : : break;
8361 : : }
8362 : :
8363 : 0 : objc_ok = objc_compare_types (type, rhstype, parmno, rname);
8364 : : }
8365 : :
8366 : 166203554 : if (warn_cxx_compat)
8367 : : {
8368 : 28856 : tree checktype = origtype != NULL_TREE ? origtype : rhstype;
8369 : 28856 : if (checktype != error_mark_node
8370 : 28856 : && TREE_CODE (type) == ENUMERAL_TYPE
8371 : 28962 : && TYPE_MAIN_VARIANT (checktype) != TYPE_MAIN_VARIANT (type))
8372 : 45 : switch (errtype)
8373 : : {
8374 : 8 : case ic_argpass:
8375 : 8 : if (pedwarn (expr_loc, OPT_Wc___compat, "enum conversion when "
8376 : : "passing argument %d of %qE is invalid in C++",
8377 : : parmnum, rname))
8378 : 16 : inform ((fundecl && !DECL_IS_UNDECLARED_BUILTIN (fundecl))
8379 : 8 : ? DECL_SOURCE_LOCATION (fundecl) : expr_loc,
8380 : : "expected %qT but argument is of type %qT",
8381 : : type, rhstype);
8382 : : break;
8383 : 10 : case ic_assign:
8384 : 10 : pedwarn (location, OPT_Wc___compat, "enum conversion from %qT to "
8385 : : "%qT in assignment is invalid in C++", rhstype, type);
8386 : 10 : break;
8387 : 18 : case ic_init:
8388 : 18 : case ic_init_const:
8389 : 18 : pedwarn_init (location, OPT_Wc___compat, "enum conversion from "
8390 : : "%qT to %qT in initialization is invalid in C++",
8391 : : rhstype, type);
8392 : 18 : break;
8393 : 9 : case ic_return:
8394 : 9 : pedwarn (location, OPT_Wc___compat, "enum conversion from %qT to "
8395 : : "%qT in return is invalid in C++", rhstype, type);
8396 : 9 : break;
8397 : 0 : default:
8398 : 0 : gcc_unreachable ();
8399 : : }
8400 : : }
8401 : :
8402 : 166203554 : if (warn_enum_conversion)
8403 : : {
8404 : 14565508 : tree checktype = origtype != NULL_TREE ? origtype : rhstype;
8405 : 14565508 : if (checktype != error_mark_node
8406 : 14565508 : && TREE_CODE (checktype) == ENUMERAL_TYPE
8407 : 12677 : && TREE_CODE (type) == ENUMERAL_TYPE
8408 : 14573692 : && !comptypes (TYPE_MAIN_VARIANT (checktype), TYPE_MAIN_VARIANT (type)))
8409 : : {
8410 : 3 : gcc_rich_location loc (location);
8411 : 3 : warning_at (&loc, OPT_Wenum_conversion,
8412 : : "implicit conversion from %qT to %qT",
8413 : : checktype, type);
8414 : 3 : }
8415 : : }
8416 : :
8417 : 166203554 : if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype))
8418 : : {
8419 : 147175670 : warn_for_address_of_packed_member (type, orig_rhs);
8420 : 147175670 : if (type != rhstype)
8421 : : /* Convert RHS to TYPE in order to not lose TYPE in diagnostics. */
8422 : 36667862 : rhs = convert (type, rhs);
8423 : 147175670 : return rhs;
8424 : : }
8425 : :
8426 : 19027884 : if (coder == VOID_TYPE)
8427 : : {
8428 : : /* Except for passing an argument to an unprototyped function,
8429 : : this is a constraint violation. When passing an argument to
8430 : : an unprototyped function, it is compile-time undefined;
8431 : : making it a constraint in that case was rejected in
8432 : : DR#252. */
8433 : 8 : const char msg[] = "void value not ignored as it ought to be";
8434 : 8 : if (warnopt)
8435 : 0 : warning_at (location, warnopt, msg);
8436 : : else
8437 : 8 : error_at (location, msg);
8438 : 8 : return error_mark_node;
8439 : : }
8440 : 19027876 : rhs = require_complete_type (location, rhs);
8441 : 19027876 : if (rhs == error_mark_node)
8442 : : return error_mark_node;
8443 : :
8444 : 19027876 : if (coder == POINTER_TYPE && reject_gcc_builtin (rhs))
8445 : 6 : return error_mark_node;
8446 : :
8447 : : /* A non-reference type can convert to a reference. This handles
8448 : : va_start, va_copy and possibly port built-ins. */
8449 : 19027870 : if (codel == REFERENCE_TYPE && coder != REFERENCE_TYPE)
8450 : : {
8451 : 270 : if (!lvalue_p (rhs))
8452 : : {
8453 : 0 : const char msg[] = "cannot pass rvalue to reference parameter";
8454 : 0 : if (warnopt)
8455 : 0 : warning_at (location, warnopt, msg);
8456 : : else
8457 : 0 : error_at (location, msg);
8458 : 0 : return error_mark_node;
8459 : : }
8460 : 270 : if (!c_mark_addressable (rhs))
8461 : 0 : return error_mark_node;
8462 : 270 : rhs = build1 (ADDR_EXPR, c_build_pointer_type (TREE_TYPE (rhs)), rhs);
8463 : 270 : SET_EXPR_LOCATION (rhs, location);
8464 : :
8465 : 270 : rhs = convert_for_assignment (location, expr_loc,
8466 : 270 : c_build_pointer_type (TREE_TYPE (type)),
8467 : : rhs, origtype, errtype,
8468 : : null_pointer_constant, fundecl, function,
8469 : : parmnum, warnopt);
8470 : 270 : if (rhs == error_mark_node)
8471 : : return error_mark_node;
8472 : :
8473 : 270 : rhs = build1 (NOP_EXPR, type, rhs);
8474 : 270 : SET_EXPR_LOCATION (rhs, location);
8475 : 270 : return rhs;
8476 : : }
8477 : : /* Some types can interconvert without explicit casts. */
8478 : 19027600 : else if (codel == VECTOR_TYPE && coder == VECTOR_TYPE
8479 : 19027600 : && vector_types_convertible_p (type, TREE_TYPE (rhs), true))
8480 : 9254485 : return convert (type, rhs);
8481 : : /* Arithmetic types all interconvert, and enum is treated like int. */
8482 : 9773115 : else if ((codel == INTEGER_TYPE || codel == REAL_TYPE
8483 : 2267778 : || codel == FIXED_POINT_TYPE
8484 : 2267778 : || codel == ENUMERAL_TYPE || codel == COMPLEX_TYPE
8485 : 2181625 : || codel == BOOLEAN_TYPE || codel == BITINT_TYPE)
8486 : 7682961 : && (coder == INTEGER_TYPE || coder == REAL_TYPE
8487 : 82476 : || coder == FIXED_POINT_TYPE
8488 : 82476 : || coder == ENUMERAL_TYPE || coder == COMPLEX_TYPE
8489 : 39554 : || coder == BOOLEAN_TYPE || coder == BITINT_TYPE))
8490 : : {
8491 : 7681843 : if (warnopt && errtype == ic_argpass)
8492 : 418 : maybe_warn_builtin_no_proto_arg (expr_loc, fundecl, parmnum, type,
8493 : : rhstype);
8494 : :
8495 : 7681843 : bool save = in_late_binary_op;
8496 : 7650937 : if (C_BOOLEAN_TYPE_P (type) || codel == COMPLEX_TYPE
8497 : 15276612 : || (coder == REAL_TYPE
8498 : 275577 : && (codel == INTEGER_TYPE || codel == ENUMERAL_TYPE)
8499 : 24189 : && sanitize_flags_p (SANITIZE_FLOAT_CAST)))
8500 : 93818 : in_late_binary_op = true;
8501 : 11045080 : tree ret = convert_and_check (expr_loc != UNKNOWN_LOCATION
8502 : : ? expr_loc : location, type, orig_rhs,
8503 : : errtype == ic_init_const);
8504 : 7681843 : in_late_binary_op = save;
8505 : 7681843 : return ret;
8506 : : }
8507 : :
8508 : : /* Aggregates in different TUs might need conversion. */
8509 : 2091272 : if ((codel == RECORD_TYPE || codel == UNION_TYPE)
8510 : 103 : && codel == coder
8511 : 2091293 : && comptypes (TYPE_MAIN_VARIANT (type), TYPE_MAIN_VARIANT (rhstype)))
8512 : 8 : return convert_and_check (expr_loc != UNKNOWN_LOCATION
8513 : 8 : ? expr_loc : location, type, rhs);
8514 : :
8515 : : /* Conversion to a transparent union or record from its member types.
8516 : : This applies only to function arguments. */
8517 : 2091264 : if (((codel == UNION_TYPE || codel == RECORD_TYPE)
8518 : 95 : && TYPE_TRANSPARENT_AGGR (type))
8519 : 2091302 : && errtype == ic_argpass)
8520 : : {
8521 : 38 : tree memb, marginal_memb = NULL_TREE;
8522 : :
8523 : 48 : for (memb = TYPE_FIELDS (type); memb ; memb = DECL_CHAIN (memb))
8524 : : {
8525 : 48 : tree memb_type = TREE_TYPE (memb);
8526 : :
8527 : 48 : if (comptypes (TYPE_MAIN_VARIANT (memb_type),
8528 : 48 : TYPE_MAIN_VARIANT (rhstype)))
8529 : : break;
8530 : :
8531 : 26 : if (TREE_CODE (memb_type) != POINTER_TYPE)
8532 : 0 : continue;
8533 : :
8534 : 26 : if (coder == POINTER_TYPE)
8535 : : {
8536 : 26 : tree ttl = TREE_TYPE (memb_type);
8537 : 26 : tree ttr = TREE_TYPE (rhstype);
8538 : :
8539 : : /* Any non-function converts to a [const][volatile] void *
8540 : : and vice versa; otherwise, targets must be the same.
8541 : : Meanwhile, the lhs target must have all the qualifiers of
8542 : : the rhs. */
8543 : 0 : if ((VOID_TYPE_P (ttl) && !TYPE_ATOMIC (ttl))
8544 : 26 : || (VOID_TYPE_P (ttr) && !TYPE_ATOMIC (ttr))
8545 : 45 : || comp_target_types (location, memb_type, rhstype))
8546 : : {
8547 : 16 : int lquals = TYPE_QUALS (ttl) & ~TYPE_QUAL_ATOMIC;
8548 : 16 : int rquals = TYPE_QUALS (ttr) & ~TYPE_QUAL_ATOMIC;
8549 : : /* If this type won't generate any warnings, use it. */
8550 : 16 : if (lquals == rquals
8551 : 16 : || ((TREE_CODE (ttr) == FUNCTION_TYPE
8552 : 0 : && TREE_CODE (ttl) == FUNCTION_TYPE)
8553 : 0 : ? ((lquals | rquals) == rquals)
8554 : 16 : : ((lquals | rquals) == lquals)))
8555 : : break;
8556 : :
8557 : : /* Keep looking for a better type, but remember this one. */
8558 : 0 : if (!marginal_memb)
8559 : 10 : marginal_memb = memb;
8560 : : }
8561 : : }
8562 : :
8563 : : /* Can convert integer zero to any pointer type. */
8564 : 10 : if (null_pointer_constant)
8565 : : {
8566 : 0 : rhs = null_pointer_node;
8567 : 0 : break;
8568 : : }
8569 : : }
8570 : :
8571 : 38 : if (memb || marginal_memb)
8572 : : {
8573 : 38 : if (!memb)
8574 : : {
8575 : : /* We have only a marginally acceptable member type;
8576 : : it needs a warning. */
8577 : 0 : tree ttl = TREE_TYPE (TREE_TYPE (marginal_memb));
8578 : 0 : tree ttr = TREE_TYPE (rhstype);
8579 : :
8580 : : /* Const and volatile mean something different for function
8581 : : types, so the usual warnings are not appropriate. */
8582 : 0 : if (TREE_CODE (ttr) == FUNCTION_TYPE
8583 : 0 : && TREE_CODE (ttl) == FUNCTION_TYPE)
8584 : : {
8585 : : /* Because const and volatile on functions are
8586 : : restrictions that say the function will not do
8587 : : certain things, it is okay to use a const or volatile
8588 : : function where an ordinary one is wanted, but not
8589 : : vice-versa. */
8590 : 0 : if (TYPE_QUALS_NO_ADDR_SPACE (ttl)
8591 : 0 : & ~TYPE_QUALS_NO_ADDR_SPACE (ttr))
8592 : 0 : PEDWARN_FOR_QUALIFIERS (location, expr_loc,
8593 : : OPT_Wdiscarded_qualifiers,
8594 : : G_("passing argument %d of %qE "
8595 : : "makes %q#v qualified function "
8596 : : "pointer from unqualified"),
8597 : : G_("assignment makes %q#v qualified "
8598 : : "function pointer from "
8599 : : "unqualified"),
8600 : : G_("initialization makes %q#v qualified "
8601 : : "function pointer from "
8602 : : "unqualified"),
8603 : : G_("return makes %q#v qualified function "
8604 : : "pointer from unqualified"),
8605 : : TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr));
8606 : : }
8607 : 0 : else if (TYPE_QUALS_NO_ADDR_SPACE (ttr)
8608 : 0 : & ~TYPE_QUALS_NO_ADDR_SPACE (ttl))
8609 : 0 : PEDWARN_FOR_QUALIFIERS (location, expr_loc,
8610 : : OPT_Wdiscarded_qualifiers,
8611 : : G_("passing argument %d of %qE discards "
8612 : : "%qv qualifier from pointer target type"),
8613 : : G_("assignment discards %qv qualifier "
8614 : : "from pointer target type"),
8615 : : G_("initialization discards %qv qualifier "
8616 : : "from pointer target type"),
8617 : : G_("return discards %qv qualifier from "
8618 : : "pointer target type"),
8619 : : TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl));
8620 : :
8621 : : memb = marginal_memb;
8622 : : }
8623 : :
8624 : 38 : if (!fundecl || !DECL_IN_SYSTEM_HEADER (fundecl))
8625 : 30 : pedwarn (location, OPT_Wpedantic,
8626 : : "ISO C prohibits argument conversion to union type");
8627 : :
8628 : 38 : rhs = fold_convert_loc (location, TREE_TYPE (memb), rhs);
8629 : 38 : return build_constructor_single (type, memb, rhs);
8630 : : }
8631 : : }
8632 : :
8633 : : /* Conversions among pointers */
8634 : 2091226 : else if ((codel == POINTER_TYPE || codel == REFERENCE_TYPE)
8635 : 2089952 : && (coder == codel))
8636 : : {
8637 : : /* If RHS refers to a built-in declared without a prototype
8638 : : BLTIN is the declaration of the built-in with a prototype
8639 : : and RHSTYPE is set to the actual type of the built-in. */
8640 : 2011725 : tree bltin;
8641 : 2011725 : rhstype = type_or_builtin_type (rhs, &bltin);
8642 : :
8643 : 2011725 : tree ttl = TREE_TYPE (type);
8644 : 2011725 : tree ttr = TREE_TYPE (rhstype);
8645 : 2011725 : bool is_opaque_pointer;
8646 : 2011725 : bool target_cmp = false; /* Cache comp_target_types () result. */
8647 : 2011725 : addr_space_t asl;
8648 : 2011725 : addr_space_t asr;
8649 : :
8650 : 2011725 : tree mvl = remove_qualifiers (ttl);
8651 : 2011725 : tree mvr = remove_qualifiers (ttr);
8652 : :
8653 : : /* Opaque pointers are treated like void pointers. */
8654 : 2011725 : is_opaque_pointer = vector_targets_convertible_p (ttl, ttr);
8655 : :
8656 : : /* The Plan 9 compiler permits a pointer to a struct to be
8657 : : automatically converted into a pointer to an anonymous field
8658 : : within the struct. */
8659 : 2011725 : if (flag_plan9_extensions
8660 : 10 : && RECORD_OR_UNION_TYPE_P (mvl)
8661 : 10 : && RECORD_OR_UNION_TYPE_P (mvr)
8662 : 10 : && mvl != mvr)
8663 : : {
8664 : 10 : tree new_rhs = convert_to_anonymous_field (location, type, rhs);
8665 : 10 : if (new_rhs != NULL_TREE)
8666 : : {
8667 : 6 : rhs = new_rhs;
8668 : 6 : rhstype = TREE_TYPE (rhs);
8669 : 6 : coder = TREE_CODE (rhstype);
8670 : 6 : ttr = TREE_TYPE (rhstype);
8671 : 6 : mvr = TYPE_MAIN_VARIANT (ttr);
8672 : : }
8673 : : }
8674 : :
8675 : : /* C++ does not allow the implicit conversion void* -> T*. However,
8676 : : for the purpose of reducing the number of false positives, we
8677 : : tolerate the special case of
8678 : :
8679 : : int *p = NULL;
8680 : :
8681 : : where NULL is typically defined in C to be '(void *) 0'. */
8682 : 2011725 : if (VOID_TYPE_P (ttr) && rhs != null_pointer_node && !VOID_TYPE_P (ttl))
8683 : 26554 : warning_at (errtype == ic_argpass ? expr_loc : location,
8684 : 14063 : OPT_Wc___compat,
8685 : : "request for implicit conversion "
8686 : : "from %qT to %qT not permitted in C++", rhstype, type);
8687 : :
8688 : : /* Warn of new allocations that are not big enough for the target
8689 : : type. */
8690 : 2011725 : if (warn_alloc_size && TREE_CODE (rhs) == CALL_EXPR)
8691 : 5455 : if (tree fndecl = get_callee_fndecl (rhs))
8692 : 5455 : if (DECL_IS_MALLOC (fndecl))
8693 : : {
8694 : 4601 : tree attrs = TYPE_ATTRIBUTES (TREE_TYPE (fndecl));
8695 : 4601 : tree alloc_size = lookup_attribute ("alloc_size", attrs);
8696 : 4601 : if (alloc_size)
8697 : 447 : warn_for_alloc_size (location, ttl, rhs, alloc_size);
8698 : : }
8699 : :
8700 : : /* See if the pointers point to incompatible address spaces. */
8701 : 2011725 : asl = TYPE_ADDR_SPACE (ttl);
8702 : 2011725 : asr = TYPE_ADDR_SPACE (ttr);
8703 : 2011725 : if (!null_pointer_constant_p (rhs)
8704 : 2011725 : && asr != asl && !targetm.addr_space.subset_p (asr, asl))
8705 : : {
8706 : 3 : auto_diagnostic_group d;
8707 : 3 : bool diagnosed = true;
8708 : 3 : switch (errtype)
8709 : : {
8710 : 1 : case ic_argpass:
8711 : 1 : {
8712 : 1 : const char msg[] = G_("passing argument %d of %qE from "
8713 : : "pointer to non-enclosed address space");
8714 : 1 : if (warnopt)
8715 : 0 : diagnosed
8716 : 0 : = warning_at (expr_loc, warnopt, msg, parmnum, rname);
8717 : : else
8718 : 1 : error_at (expr_loc, msg, parmnum, rname);
8719 : 0 : break;
8720 : : }
8721 : 0 : case ic_assign:
8722 : 0 : {
8723 : 0 : const char msg[] = G_("assignment from pointer to "
8724 : : "non-enclosed address space");
8725 : 0 : if (warnopt)
8726 : 0 : diagnosed = warning_at (location, warnopt, msg);
8727 : : else
8728 : 0 : error_at (location, msg);
8729 : 0 : break;
8730 : : }
8731 : 0 : case ic_init:
8732 : 0 : case ic_init_const:
8733 : 0 : {
8734 : 0 : const char msg[] = G_("initialization from pointer to "
8735 : : "non-enclosed address space");
8736 : 0 : if (warnopt)
8737 : 0 : diagnosed = warning_at (location, warnopt, msg);
8738 : : else
8739 : 0 : error_at (location, msg);
8740 : 0 : break;
8741 : : }
8742 : 2 : case ic_return:
8743 : 2 : {
8744 : 2 : const char msg[] = G_("return from pointer to "
8745 : : "non-enclosed address space");
8746 : 2 : if (warnopt)
8747 : 0 : diagnosed = warning_at (location, warnopt, msg);
8748 : : else
8749 : 2 : error_at (location, msg);
8750 : 0 : break;
8751 : : }
8752 : 0 : default:
8753 : 0 : gcc_unreachable ();
8754 : : }
8755 : 3 : if (diagnosed)
8756 : : {
8757 : 3 : if (errtype == ic_argpass)
8758 : 1 : inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
8759 : : else
8760 : 2 : inform (location, "expected %qT but pointer is of type %qT",
8761 : : type, rhstype);
8762 : : }
8763 : 3 : return error_mark_node;
8764 : 3 : }
8765 : :
8766 : : /* Check if the right-hand side has a format attribute but the
8767 : : left-hand side doesn't. */
8768 : 2011722 : if (warn_suggest_attribute_format
8769 : 2011722 : && check_missing_format_attribute (type, rhstype))
8770 : : {
8771 : 16 : switch (errtype)
8772 : : {
8773 : 4 : case ic_argpass:
8774 : 4 : warning_at (expr_loc, OPT_Wsuggest_attribute_format,
8775 : : "argument %d of %qE might be "
8776 : : "a candidate for a format attribute",
8777 : : parmnum, rname);
8778 : 4 : break;
8779 : 4 : case ic_assign:
8780 : 4 : warning_at (location, OPT_Wsuggest_attribute_format,
8781 : : "assignment left-hand side might be "
8782 : : "a candidate for a format attribute");
8783 : 4 : break;
8784 : 4 : case ic_init:
8785 : 4 : case ic_init_const:
8786 : 4 : warning_at (location, OPT_Wsuggest_attribute_format,
8787 : : "initialization left-hand side might be "
8788 : : "a candidate for a format attribute");
8789 : 4 : break;
8790 : 4 : case ic_return:
8791 : 4 : warning_at (location, OPT_Wsuggest_attribute_format,
8792 : : "return type might be "
8793 : : "a candidate for a format attribute");
8794 : 4 : break;
8795 : 0 : default:
8796 : 0 : gcc_unreachable ();
8797 : : }
8798 : : }
8799 : :
8800 : : /* See if the pointers point to incompatible scalar storage orders. */
8801 : 2011722 : if (warn_scalar_storage_order
8802 : 2008806 : && !null_pointer_constant_p (rhs)
8803 : 5963538 : && (AGGREGATE_TYPE_P (ttl) && TYPE_REVERSE_STORAGE_ORDER (ttl))
8804 : 1975908 : != (AGGREGATE_TYPE_P (ttr) && TYPE_REVERSE_STORAGE_ORDER (ttr)))
8805 : : {
8806 : 18 : tree t;
8807 : :
8808 : 18 : switch (errtype)
8809 : : {
8810 : 11 : case ic_argpass:
8811 : : /* Do not warn for built-in functions, for example memcpy, since we
8812 : : control how they behave and they can be useful in this area. */
8813 : 11 : if (TREE_CODE (rname) != FUNCTION_DECL
8814 : 11 : || !fndecl_built_in_p (rname))
8815 : 1 : warning_at (location, OPT_Wscalar_storage_order,
8816 : : "passing argument %d of %qE from incompatible "
8817 : : "scalar storage order", parmnum, rname);
8818 : : break;
8819 : 3 : case ic_assign:
8820 : : /* Do not warn if the RHS is a call to a function that returns a
8821 : : pointer that is not an alias. */
8822 : 3 : if (TREE_CODE (rhs) != CALL_EXPR
8823 : 2 : || (t = get_callee_fndecl (rhs)) == NULL_TREE
8824 : 5 : || !DECL_IS_MALLOC (t))
8825 : 1 : warning_at (location, OPT_Wscalar_storage_order,
8826 : : "assignment to %qT from pointer type %qT with "
8827 : : "incompatible scalar storage order", type, rhstype);
8828 : : break;
8829 : 3 : case ic_init:
8830 : 3 : case ic_init_const:
8831 : : /* Likewise. */
8832 : 3 : if (TREE_CODE (rhs) != CALL_EXPR
8833 : 2 : || (t = get_callee_fndecl (rhs)) == NULL_TREE
8834 : 5 : || !DECL_IS_MALLOC (t))
8835 : 1 : warning_at (location, OPT_Wscalar_storage_order,
8836 : : "initialization of %qT from pointer type %qT with "
8837 : : "incompatible scalar storage order", type, rhstype);
8838 : : break;
8839 : 1 : case ic_return:
8840 : 1 : warning_at (location, OPT_Wscalar_storage_order,
8841 : : "returning %qT from pointer type with incompatible "
8842 : : "scalar storage order %qT", rhstype, type);
8843 : 1 : break;
8844 : 0 : default:
8845 : 0 : gcc_unreachable ();
8846 : : }
8847 : : }
8848 : :
8849 : : /* Any non-function converts to a [const][volatile] void *
8850 : : and vice versa; otherwise, targets must be the same.
8851 : : Meanwhile, the lhs target must have all the qualifiers of the rhs. */
8852 : 421562 : if ((VOID_TYPE_P (ttl) && !TYPE_ATOMIC (ttl))
8853 : 1590161 : || (VOID_TYPE_P (ttr) && !TYPE_ATOMIC (ttr))
8854 : 1543336 : || (target_cmp = comp_target_types (location, type, rhstype))
8855 : 2447 : || is_opaque_pointer
8856 : 2016616 : || ((c_common_unsigned_type (mvl)
8857 : 2447 : == c_common_unsigned_type (mvr))
8858 : 3342 : && (c_common_signed_type (mvl)
8859 : 1671 : == c_common_signed_type (mvr))
8860 : 1656 : && TYPE_ATOMIC (mvl) == TYPE_ATOMIC (mvr)))
8861 : : {
8862 : : /* Warn about loss of qualifers from pointers to arrays with
8863 : : qualifiers on the element type. */
8864 : 2010923 : if (TREE_CODE (ttr) == ARRAY_TYPE)
8865 : : {
8866 : 2131 : ttr = strip_array_types (ttr);
8867 : 2131 : ttl = strip_array_types (ttl);
8868 : :
8869 : 2131 : if (TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttr)
8870 : 2131 : & ~TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttl))
8871 : 115 : WARNING_FOR_QUALIFIERS (flag_isoc23,
8872 : : location, expr_loc,
8873 : : OPT_Wdiscarded_array_qualifiers,
8874 : : G_("passing argument %d of %qE discards "
8875 : : "%qv qualifier from pointer target type"),
8876 : : G_("assignment discards %qv qualifier "
8877 : : "from pointer target type"),
8878 : : G_("initialization discards %qv qualifier "
8879 : : "from pointer target type"),
8880 : : G_("return discards %qv qualifier from "
8881 : : "pointer target type"),
8882 : : TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl));
8883 : : }
8884 : 2008792 : else if (pedantic
8885 : 146039 : && ((VOID_TYPE_P (ttl) && TREE_CODE (ttr) == FUNCTION_TYPE)
8886 : 146019 : ||
8887 : : (VOID_TYPE_P (ttr)
8888 : 2952 : && !null_pointer_constant
8889 : 178 : && TREE_CODE (ttl) == FUNCTION_TYPE)))
8890 : 34 : PEDWARN_FOR_ASSIGNMENT (location, expr_loc, OPT_Wpedantic,
8891 : : G_("ISO C forbids passing argument %d of "
8892 : : "%qE between function pointer "
8893 : : "and %<void *%>"),
8894 : : G_("ISO C forbids assignment between "
8895 : : "function pointer and %<void *%>"),
8896 : : G_("ISO C forbids initialization between "
8897 : : "function pointer and %<void *%>"),
8898 : : G_("ISO C forbids return between function "
8899 : : "pointer and %<void *%>"));
8900 : : /* Const and volatile mean something different for function types,
8901 : : so the usual warnings are not appropriate. */
8902 : 2008758 : else if (TREE_CODE (ttr) != FUNCTION_TYPE
8903 : 1976345 : && TREE_CODE (ttl) != FUNCTION_TYPE)
8904 : : {
8905 : : /* Assignments between atomic and non-atomic objects are OK. */
8906 : 1975664 : bool warn_quals_ped = TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttr)
8907 : 1975664 : & ~TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttl);
8908 : 1975664 : bool warn_quals = TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttr)
8909 : 1975664 : & ~TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (strip_array_types (ttl));
8910 : :
8911 : : /* Don't warn about loss of qualifier for conversions from
8912 : : qualified void* to pointers to arrays with corresponding
8913 : : qualifier on the element type (except for pedantic before C23). */
8914 : 1975664 : if (warn_quals || (warn_quals_ped && pedantic && !flag_isoc23))
8915 : 697 : PEDWARN_FOR_QUALIFIERS (location, expr_loc,
8916 : : OPT_Wdiscarded_qualifiers,
8917 : : G_("passing argument %d of %qE discards "
8918 : : "%qv qualifier from pointer target type"),
8919 : : G_("assignment discards %qv qualifier "
8920 : : "from pointer target type"),
8921 : : G_("initialization discards %qv qualifier "
8922 : : "from pointer target type"),
8923 : : G_("return discards %qv qualifier from "
8924 : : "pointer target type"),
8925 : : TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl));
8926 : 11 : else if (warn_quals_ped)
8927 : 11 : pedwarn_c11 (location, OPT_Wc11_c23_compat,
8928 : : "array with qualifier on the element is not qualified before C23");
8929 : :
8930 : : /* If this is not a case of ignoring a mismatch in signedness,
8931 : : no warning. */
8932 : 1974956 : else if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr)
8933 : 1538414 : || target_cmp)
8934 : : ;
8935 : : /* If there is a mismatch, do warn. */
8936 : 1648 : else if (warn_pointer_sign)
8937 : 82 : switch (errtype)
8938 : : {
8939 : 33 : case ic_argpass:
8940 : 33 : {
8941 : 33 : auto_diagnostic_group d;
8942 : 33 : range_label_for_type_mismatch rhs_label (rhstype, type);
8943 : 33 : gcc_rich_location richloc (expr_loc, &rhs_label,
8944 : 33 : highlight_colors::actual);
8945 : 33 : if (pedwarn (&richloc, OPT_Wpointer_sign,
8946 : : "pointer targets in passing argument %d of "
8947 : : "%qE differ in signedness", parmnum, rname))
8948 : 33 : inform_for_arg (fundecl, expr_loc, parmnum, type,
8949 : : rhstype);
8950 : 33 : }
8951 : 33 : break;
8952 : 21 : case ic_assign:
8953 : 21 : pedwarn (location, OPT_Wpointer_sign,
8954 : : "pointer targets in assignment from %qT to %qT "
8955 : : "differ in signedness", rhstype, type);
8956 : 21 : break;
8957 : 14 : case ic_init:
8958 : 14 : case ic_init_const:
8959 : 14 : pedwarn_init (location, OPT_Wpointer_sign,
8960 : : "pointer targets in initialization of %qT "
8961 : : "from %qT differ in signedness", type,
8962 : : rhstype);
8963 : 14 : break;
8964 : 14 : case ic_return:
8965 : 14 : pedwarn (location, OPT_Wpointer_sign, "pointer targets in "
8966 : : "returning %qT from a function with return type "
8967 : : "%qT differ in signedness", rhstype, type);
8968 : 14 : break;
8969 : 0 : default:
8970 : 0 : gcc_unreachable ();
8971 : : }
8972 : : }
8973 : 33094 : else if (TREE_CODE (ttl) == FUNCTION_TYPE
8974 : 4133 : && TREE_CODE (ttr) == FUNCTION_TYPE)
8975 : : {
8976 : : /* Because const and volatile on functions are restrictions
8977 : : that say the function will not do certain things,
8978 : : it is okay to use a const or volatile function
8979 : : where an ordinary one is wanted, but not vice-versa. */
8980 : 3452 : if (TYPE_QUALS_NO_ADDR_SPACE (ttl)
8981 : 3452 : & ~TYPE_QUALS_NO_ADDR_SPACE (ttr))
8982 : 18 : PEDWARN_FOR_QUALIFIERS (location, expr_loc,
8983 : : OPT_Wdiscarded_qualifiers,
8984 : : G_("passing argument %d of %qE makes "
8985 : : "%q#v qualified function pointer "
8986 : : "from unqualified"),
8987 : : G_("assignment makes %q#v qualified function "
8988 : : "pointer from unqualified"),
8989 : : G_("initialization makes %q#v qualified "
8990 : : "function pointer from unqualified"),
8991 : : G_("return makes %q#v qualified function "
8992 : : "pointer from unqualified"),
8993 : : TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr));
8994 : : }
8995 : : }
8996 : : /* Avoid warning about the volatile ObjC EH puts on decls. */
8997 : 799 : else if (!objc_ok)
8998 : : {
8999 : 799 : auto_diagnostic_group d;
9000 : 799 : bool warned = false;
9001 : 799 : pp_markup::element_expected_type e_type (type);
9002 : 799 : pp_markup::element_actual_type e_rhstype (rhstype);
9003 : 799 : switch (errtype)
9004 : : {
9005 : 306 : case ic_argpass:
9006 : 306 : {
9007 : 306 : range_label_for_type_mismatch rhs_label (rhstype, type);
9008 : 306 : gcc_rich_location richloc (expr_loc, &rhs_label,
9009 : 306 : highlight_colors::actual);
9010 : 306 : warned
9011 : 306 : = permerror_opt (&richloc, OPT_Wincompatible_pointer_types,
9012 : : "passing argument %d of %qE from "
9013 : : "incompatible pointer type",
9014 : : parmnum, rname);
9015 : 306 : if (warned)
9016 : 174 : inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
9017 : 306 : }
9018 : 306 : break;
9019 : 267 : case ic_assign:
9020 : 267 : if (bltin)
9021 : 11 : warned
9022 : 11 : = permerror_opt (location, OPT_Wincompatible_pointer_types,
9023 : : "assignment to %e from pointer to "
9024 : : "%qD with incompatible type %e",
9025 : : &e_type, bltin, &e_rhstype);
9026 : : else
9027 : 256 : warned
9028 : 256 : = permerror_opt (location, OPT_Wincompatible_pointer_types,
9029 : : "assignment to %e from incompatible "
9030 : : "pointer type %e",
9031 : : &e_type, &e_rhstype);
9032 : : break;
9033 : 167 : case ic_init:
9034 : 167 : case ic_init_const:
9035 : 167 : if (bltin)
9036 : 13 : warned
9037 : 13 : = permerror_init (location, OPT_Wincompatible_pointer_types,
9038 : : "initialization of %e from pointer to "
9039 : : "%qD with incompatible type %e",
9040 : : &e_type, bltin, &e_rhstype);
9041 : : else
9042 : 154 : warned
9043 : 154 : = permerror_init (location, OPT_Wincompatible_pointer_types,
9044 : : "initialization of %e from incompatible "
9045 : : "pointer type %e",
9046 : : &e_type, &e_rhstype);
9047 : : break;
9048 : 59 : case ic_return:
9049 : 59 : if (bltin)
9050 : 11 : warned
9051 : 11 : = permerror_opt (location, OPT_Wincompatible_pointer_types,
9052 : : "returning pointer to %qD of type %e from "
9053 : : "a function with incompatible type %e",
9054 : : bltin, &e_rhstype, &e_type);
9055 : : else
9056 : 48 : warned
9057 : 48 : = permerror_opt (location, OPT_Wincompatible_pointer_types,
9058 : : "returning %e from a function with "
9059 : : "incompatible return type %e",
9060 : : &e_rhstype, &e_type);
9061 : : break;
9062 : 0 : default:
9063 : 0 : gcc_unreachable ();
9064 : : }
9065 : 799 : if (warned)
9066 : : {
9067 : : /* If the mismatching function type is a pointer to a function,
9068 : : try to show the decl of the function. */
9069 : 589 : if (TREE_CODE (rhs) == ADDR_EXPR
9070 : 589 : && TREE_CODE (TREE_OPERAND (rhs, 0)) == FUNCTION_DECL)
9071 : : {
9072 : 191 : tree rhs_fndecl = TREE_OPERAND (rhs, 0);
9073 : 191 : if (!DECL_IS_UNDECLARED_BUILTIN (rhs_fndecl))
9074 : : {
9075 : 165 : gcc_rich_location richloc
9076 : 165 : (DECL_SOURCE_LOCATION (rhs_fndecl), nullptr,
9077 : 165 : highlight_colors::actual);
9078 : 165 : pp_element_quoted_decl e_rhs_fndecl
9079 : 165 : (rhs_fndecl, highlight_colors::actual);
9080 : 165 : inform (&richloc,
9081 : : "%e declared here", &e_rhs_fndecl);
9082 : 165 : }
9083 : : }
9084 : : /* If either/both of the types are typedefs, show the decl. */
9085 : 589 : maybe_inform_typedef_location (type,
9086 : : highlight_colors::expected);
9087 : 589 : maybe_inform_typedef_location (rhstype,
9088 : : highlight_colors::actual);
9089 : : }
9090 : 799 : }
9091 : :
9092 : : /* If RHS isn't an address, check pointer or array of packed
9093 : : struct or union. */
9094 : 2011722 : warn_for_address_of_packed_member (type, orig_rhs);
9095 : :
9096 : 2011722 : return convert (type, rhs);
9097 : : }
9098 : 79501 : else if (codel == POINTER_TYPE && coder == ARRAY_TYPE)
9099 : : {
9100 : : /* ??? This should not be an error when inlining calls to
9101 : : unprototyped functions. */
9102 : 4 : const char msg[] = "invalid use of non-lvalue array";
9103 : 4 : if (warnopt)
9104 : 0 : warning_at (location, warnopt, msg);
9105 : : else
9106 : 4 : error_at (location, msg);
9107 : 4 : return error_mark_node;
9108 : : }
9109 : 79497 : else if (codel == POINTER_TYPE
9110 : 78223 : && (coder == INTEGER_TYPE
9111 : 78223 : || coder == ENUMERAL_TYPE
9112 : 607 : || coder == BOOLEAN_TYPE
9113 : 607 : || coder == NULLPTR_TYPE
9114 : 25 : || coder == BITINT_TYPE))
9115 : : {
9116 : 78210 : if (null_pointer_constant && c_inhibit_evaluation_warnings == 0
9117 : 77212 : && coder == INTEGER_TYPE)
9118 : 76613 : warning_at (location, OPT_Wzero_as_null_pointer_constant,
9119 : : "zero as null pointer constant");
9120 : : /* A NULLPTR type is just a nullptr always. */
9121 : 78210 : if (coder == NULLPTR_TYPE)
9122 : 570 : return omit_one_operand_loc (expr_loc, type, nullptr_node, rhs);
9123 : : /* An explicit constant 0 or type nullptr_t can convert to a pointer,
9124 : : or one that results from arithmetic, even including a cast to
9125 : : integer type. */
9126 : 77640 : else if (!null_pointer_constant)
9127 : 972 : switch (errtype)
9128 : : {
9129 : 800 : case ic_argpass:
9130 : 800 : {
9131 : 800 : auto_diagnostic_group d;
9132 : 800 : range_label_for_type_mismatch rhs_label (rhstype, type);
9133 : 800 : gcc_rich_location richloc (expr_loc, &rhs_label,
9134 : 800 : highlight_colors::actual);
9135 : 800 : if (permerror_opt (&richloc, OPT_Wint_conversion,
9136 : : "passing argument %d of %qE makes pointer "
9137 : : "from integer without a cast", parmnum, rname))
9138 : : {
9139 : 439 : maybe_emit_indirection_note (expr_loc, rhs, type);
9140 : 439 : inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
9141 : : }
9142 : 800 : }
9143 : 800 : break;
9144 : 93 : case ic_assign:
9145 : 93 : permerror_opt (location, OPT_Wint_conversion,
9146 : : "assignment to %qT from %qT makes pointer from "
9147 : : "integer without a cast", type, rhstype);
9148 : 93 : break;
9149 : 56 : case ic_init:
9150 : 56 : case ic_init_const:
9151 : 56 : permerror_init (location, OPT_Wint_conversion,
9152 : : "initialization of %qT from %qT makes pointer "
9153 : : "from integer without a cast", type, rhstype);
9154 : 56 : break;
9155 : 23 : case ic_return:
9156 : 23 : permerror_init (location, OPT_Wint_conversion,
9157 : : "returning %qT from a function with return type "
9158 : : "%qT makes pointer from integer without a cast",
9159 : : rhstype, type);
9160 : 23 : break;
9161 : 0 : default:
9162 : 0 : gcc_unreachable ();
9163 : : }
9164 : :
9165 : 77640 : return convert (type, rhs);
9166 : : }
9167 : 1287 : else if ((codel == INTEGER_TYPE || codel == BITINT_TYPE)
9168 : 539 : && coder == POINTER_TYPE)
9169 : : {
9170 : 513 : switch (errtype)
9171 : : {
9172 : 343 : case ic_argpass:
9173 : 343 : {
9174 : 343 : auto_diagnostic_group d;
9175 : 343 : range_label_for_type_mismatch rhs_label (rhstype, type);
9176 : 343 : gcc_rich_location richloc (expr_loc, &rhs_label,
9177 : 343 : highlight_colors::actual);
9178 : 343 : if (permerror_opt (&richloc, OPT_Wint_conversion,
9179 : : "passing argument %d of %qE makes integer from "
9180 : : "pointer without a cast", parmnum, rname))
9181 : : {
9182 : 322 : maybe_emit_indirection_note (expr_loc, rhs, type);
9183 : 322 : inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
9184 : : }
9185 : 343 : }
9186 : 343 : break;
9187 : 52 : case ic_assign:
9188 : 52 : permerror_opt (location, OPT_Wint_conversion,
9189 : : "assignment to %qT from %qT makes integer from "
9190 : : "pointer without a cast", type, rhstype);
9191 : 52 : break;
9192 : 83 : case ic_init:
9193 : 83 : case ic_init_const:
9194 : 83 : permerror_init (location, OPT_Wint_conversion,
9195 : : "initialization of %qT from %qT makes integer "
9196 : : "from pointer without a cast", type, rhstype);
9197 : 83 : break;
9198 : 35 : case ic_return:
9199 : 35 : permerror_opt (location, OPT_Wint_conversion, "returning %qT from a "
9200 : : "function with return type %qT makes integer from "
9201 : : "pointer without a cast", rhstype, type);
9202 : 35 : break;
9203 : 0 : default:
9204 : 0 : gcc_unreachable ();
9205 : : }
9206 : :
9207 : 513 : return convert (type, rhs);
9208 : : }
9209 : 626 : else if (C_BOOLEAN_TYPE_P (type)
9210 : : /* The type nullptr_t may be converted to bool. The
9211 : : result is false. */
9212 : 776 : && (coder == POINTER_TYPE || coder == NULLPTR_TYPE))
9213 : : {
9214 : 150 : tree ret;
9215 : 150 : bool save = in_late_binary_op;
9216 : 150 : in_late_binary_op = true;
9217 : 150 : ret = convert (type, rhs);
9218 : 150 : in_late_binary_op = save;
9219 : 150 : return ret;
9220 : : }
9221 : 624 : else if (codel == NULLPTR_TYPE && null_pointer_constant)
9222 : 6 : return convert (type, rhs);
9223 : :
9224 : 618 : switch (errtype)
9225 : : {
9226 : 35 : case ic_argpass:
9227 : 35 : {
9228 : 35 : auto_diagnostic_group d;
9229 : 35 : range_label_for_type_mismatch rhs_label (rhstype, type);
9230 : 35 : gcc_rich_location richloc (expr_loc, &rhs_label,
9231 : 35 : highlight_colors::actual);
9232 : 35 : const char msg[] = G_("incompatible type for argument %d of %qE");
9233 : 35 : if (warnopt)
9234 : 8 : warning_at (expr_loc, warnopt, msg, parmnum, rname);
9235 : : else
9236 : 27 : error_at (&richloc, msg, parmnum, rname);
9237 : 35 : inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
9238 : 35 : }
9239 : 35 : break;
9240 : 108 : case ic_assign:
9241 : 108 : {
9242 : 108 : const char msg[]
9243 : : = G_("incompatible types when assigning to type %qT from type %qT");
9244 : 108 : if (warnopt)
9245 : 0 : warning_at (expr_loc, 0, msg, type, rhstype);
9246 : : else
9247 : 108 : error_at (expr_loc, msg, type, rhstype);
9248 : 108 : break;
9249 : : }
9250 : 460 : case ic_init:
9251 : 460 : case ic_init_const:
9252 : 460 : {
9253 : 460 : const char msg[]
9254 : : = G_("incompatible types when initializing type %qT using type %qT");
9255 : 460 : if (warnopt)
9256 : 0 : warning_at (location, 0, msg, type, rhstype);
9257 : : else
9258 : 460 : error_at (location, msg, type, rhstype);
9259 : 460 : break;
9260 : : }
9261 : 15 : case ic_return:
9262 : 15 : {
9263 : 15 : const char msg[]
9264 : : = G_("incompatible types when returning type %qT but %qT was expected");
9265 : 15 : if (warnopt)
9266 : 0 : warning_at (location, 0, msg, rhstype, type);
9267 : : else
9268 : 15 : error_at (location, msg, rhstype, type);
9269 : 15 : break;
9270 : : }
9271 : 0 : default:
9272 : 0 : gcc_unreachable ();
9273 : : }
9274 : :
9275 : 618 : return error_mark_node;
9276 : : }
9277 : :
9278 : : /* If VALUE is a compound expr all of whose expressions are constant, then
9279 : : return its value. Otherwise, return error_mark_node.
9280 : :
9281 : : This is for handling COMPOUND_EXPRs as initializer elements
9282 : : which is allowed with a warning when -pedantic is specified. */
9283 : :
9284 : : static tree
9285 : 2 : valid_compound_expr_initializer (tree value, tree endtype)
9286 : : {
9287 : 2 : if (TREE_CODE (value) == COMPOUND_EXPR)
9288 : : {
9289 : 1 : if (valid_compound_expr_initializer (TREE_OPERAND (value, 0), endtype)
9290 : 1 : == error_mark_node)
9291 : : return error_mark_node;
9292 : 0 : return valid_compound_expr_initializer (TREE_OPERAND (value, 1),
9293 : 0 : endtype);
9294 : : }
9295 : 1 : else if (!initializer_constant_valid_p (value, endtype))
9296 : 1 : return error_mark_node;
9297 : : else
9298 : : return value;
9299 : : }
9300 : :
9301 : : /* Perform appropriate conversions on the initial value of a variable,
9302 : : store it in the declaration DECL,
9303 : : and print any error messages that are appropriate.
9304 : : If ORIGTYPE is not NULL_TREE, it is the original type of INIT.
9305 : : If the init is invalid, store an ERROR_MARK.
9306 : :
9307 : : INIT_LOC is the location of the initial value. */
9308 : :
9309 : : void
9310 : 7244766 : store_init_value (location_t init_loc, tree decl, tree init, tree origtype)
9311 : : {
9312 : 7244766 : tree value, type;
9313 : 7244766 : bool npc = false;
9314 : 7244766 : bool int_const_expr = false;
9315 : 7244766 : bool arith_const_expr = false;
9316 : :
9317 : : /* If variable's type was invalidly declared, just ignore it. */
9318 : :
9319 : 7244766 : type = TREE_TYPE (decl);
9320 : 7244766 : if (TREE_CODE (type) == ERROR_MARK)
9321 : : return;
9322 : :
9323 : : /* Digest the specified initializer into an expression. */
9324 : :
9325 : 7244759 : if (init)
9326 : : {
9327 : 7244756 : npc = null_pointer_constant_p (init);
9328 : 7244756 : int_const_expr = (TREE_CODE (init) == INTEGER_CST
9329 : 418111 : && !TREE_OVERFLOW (init)
9330 : 7662831 : && INTEGRAL_TYPE_P (TREE_TYPE (init)));
9331 : : /* Not fully determined before folding. */
9332 : : arith_const_expr = true;
9333 : : }
9334 : 7244759 : bool constexpr_p = (VAR_P (decl)
9335 : 7244759 : && C_DECL_DECLARED_CONSTEXPR (decl));
9336 : 7244759 : value = digest_init (init_loc, decl, type, init, origtype, npc,
9337 : : int_const_expr, arith_const_expr, true,
9338 : 7244759 : TREE_STATIC (decl) || constexpr_p, constexpr_p);
9339 : :
9340 : : /* Store the expression if valid; else report error. */
9341 : :
9342 : 7244759 : if (!in_system_header_at (input_location)
9343 : 7244759 : && AGGREGATE_TYPE_P (TREE_TYPE (decl)) && !TREE_STATIC (decl))
9344 : 27816 : warning (OPT_Wtraditional, "traditional C rejects automatic "
9345 : : "aggregate initialization");
9346 : :
9347 : 7244759 : if (value != error_mark_node || TREE_CODE (decl) != FUNCTION_DECL)
9348 : 7244758 : DECL_INITIAL (decl) = value;
9349 : :
9350 : : /* ANSI wants warnings about out-of-range constant initializers. */
9351 : 7244770 : STRIP_TYPE_NOPS (value);
9352 : 7244759 : if (TREE_STATIC (decl))
9353 : 179969 : constant_expression_warning (value);
9354 : :
9355 : : /* Check if we need to set array size from compound literal size. */
9356 : 7244759 : if (TREE_CODE (type) == ARRAY_TYPE
9357 : 26283 : && TYPE_DOMAIN (type) == NULL_TREE
9358 : 7257193 : && value != error_mark_node)
9359 : : {
9360 : : tree inside_init = init;
9361 : :
9362 : 11562 : STRIP_TYPE_NOPS (inside_init);
9363 : 11562 : inside_init = fold (inside_init);
9364 : :
9365 : 11562 : if (TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR)
9366 : : {
9367 : 13 : tree cldecl = COMPOUND_LITERAL_EXPR_DECL (inside_init);
9368 : :
9369 : 13 : if (TYPE_DOMAIN (TREE_TYPE (cldecl)))
9370 : : {
9371 : : /* For int foo[] = (int [3]){1}; we need to set array size
9372 : : now since later on array initializer will be just the
9373 : : brace enclosed list of the compound literal. */
9374 : 13 : tree etype = strip_array_types (TREE_TYPE (decl));
9375 : 13 : type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
9376 : 13 : TYPE_DOMAIN (type) = TYPE_DOMAIN (TREE_TYPE (cldecl));
9377 : 13 : layout_type (type);
9378 : 13 : layout_decl (cldecl, 0);
9379 : 13 : TREE_TYPE (decl)
9380 : 26 : = c_build_qualified_type (type, TYPE_QUALS (etype));
9381 : : }
9382 : : }
9383 : : }
9384 : : }
9385 : :
9386 : : /* Methods for storing and printing names for error messages. */
9387 : :
9388 : : /* Implement a spelling stack that allows components of a name to be pushed
9389 : : and popped. Each element on the stack is this structure. */
9390 : :
9391 : : struct spelling
9392 : : {
9393 : : int kind;
9394 : : union
9395 : : {
9396 : : unsigned HOST_WIDE_INT i;
9397 : : const char *s;
9398 : : } u;
9399 : : };
9400 : :
9401 : : #define SPELLING_STRING 1
9402 : : #define SPELLING_MEMBER 2
9403 : : #define SPELLING_BOUNDS 3
9404 : :
9405 : : static struct spelling *spelling; /* Next stack element (unused). */
9406 : : static struct spelling *spelling_base; /* Spelling stack base. */
9407 : : static int spelling_size; /* Size of the spelling stack. */
9408 : :
9409 : : /* Macros to save and restore the spelling stack around push_... functions.
9410 : : Alternative to SAVE_SPELLING_STACK. */
9411 : :
9412 : : #define SPELLING_DEPTH() (spelling - spelling_base)
9413 : : #define RESTORE_SPELLING_DEPTH(DEPTH) (spelling = spelling_base + (DEPTH))
9414 : :
9415 : : /* Push an element on the spelling stack with type KIND and assign VALUE
9416 : : to MEMBER. */
9417 : :
9418 : : #define PUSH_SPELLING(KIND, VALUE, MEMBER) \
9419 : : { \
9420 : : int depth = SPELLING_DEPTH (); \
9421 : : \
9422 : : if (depth >= spelling_size) \
9423 : : { \
9424 : : spelling_size += 10; \
9425 : : spelling_base = XRESIZEVEC (struct spelling, spelling_base, \
9426 : : spelling_size); \
9427 : : RESTORE_SPELLING_DEPTH (depth); \
9428 : : } \
9429 : : \
9430 : : spelling->kind = (KIND); \
9431 : : spelling->MEMBER = (VALUE); \
9432 : : spelling++; \
9433 : : }
9434 : :
9435 : : /* Push STRING on the stack. Printed literally. */
9436 : :
9437 : : static void
9438 : 7242042 : push_string (const char *string)
9439 : : {
9440 : 7242042 : PUSH_SPELLING (SPELLING_STRING, string, u.s);
9441 : 7242042 : }
9442 : :
9443 : : /* Push a member name on the stack. Printed as '.' STRING. */
9444 : :
9445 : : static void
9446 : 1226326 : push_member_name (tree decl)
9447 : : {
9448 : 1226326 : const char *const string
9449 : 1226326 : = (DECL_NAME (decl)
9450 : 1226326 : ? identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl)))
9451 : 204 : : _("<anonymous>"));
9452 : 1226326 : PUSH_SPELLING (SPELLING_MEMBER, string, u.s);
9453 : 1226326 : }
9454 : :
9455 : : /* Push an array bounds on the stack. Printed as [BOUNDS]. */
9456 : :
9457 : : static void
9458 : 2597655 : push_array_bounds (unsigned HOST_WIDE_INT bounds)
9459 : : {
9460 : 2597655 : PUSH_SPELLING (SPELLING_BOUNDS, bounds, u.i);
9461 : 2597655 : }
9462 : :
9463 : : /* Compute the maximum size in bytes of the printed spelling. */
9464 : :
9465 : : static int
9466 : 2892 : spelling_length (void)
9467 : : {
9468 : 2892 : int size = 0;
9469 : 2892 : struct spelling *p;
9470 : :
9471 : 6416 : for (p = spelling_base; p < spelling; p++)
9472 : : {
9473 : 3524 : if (p->kind == SPELLING_BOUNDS)
9474 : 1479 : size += 25;
9475 : : else
9476 : 2045 : size += strlen (p->u.s) + 1;
9477 : : }
9478 : :
9479 : 2892 : return size;
9480 : : }
9481 : :
9482 : : /* Print the spelling to BUFFER and return it. */
9483 : :
9484 : : static char *
9485 : 2892 : print_spelling (char *buffer)
9486 : : {
9487 : 2892 : char *d = buffer;
9488 : 2892 : struct spelling *p;
9489 : :
9490 : 6416 : for (p = spelling_base; p < spelling; p++)
9491 : 3524 : if (p->kind == SPELLING_BOUNDS)
9492 : : {
9493 : 1479 : sprintf (d, "[" HOST_WIDE_INT_PRINT_UNSIGNED "]", p->u.i);
9494 : 1479 : d += strlen (d);
9495 : : }
9496 : : else
9497 : : {
9498 : 2045 : const char *s;
9499 : 2045 : if (p->kind == SPELLING_MEMBER)
9500 : 198 : *d++ = '.';
9501 : 16715 : for (s = p->u.s; (*d = *s++); d++)
9502 : : ;
9503 : : }
9504 : 2892 : *d++ = '\0';
9505 : 2892 : return buffer;
9506 : : }
9507 : :
9508 : : /* Check whether INIT, a floating or integer constant, is
9509 : : representable in TYPE, a real floating type with the same radix or
9510 : : a decimal floating type initialized with a binary floating
9511 : : constant. Return true if OK, false if not. */
9512 : : static bool
9513 : 362 : constexpr_init_fits_real_type (tree type, tree init)
9514 : : {
9515 : 362 : gcc_assert (SCALAR_FLOAT_TYPE_P (type));
9516 : 362 : gcc_assert (TREE_CODE (init) == INTEGER_CST || TREE_CODE (init) == REAL_CST);
9517 : 362 : if (TREE_CODE (init) == REAL_CST
9518 : 362 : && TYPE_MODE (TREE_TYPE (init)) == TYPE_MODE (type))
9519 : : {
9520 : : /* Same mode, no conversion required except for the case of
9521 : : signaling NaNs if the types are incompatible (e.g. double and
9522 : : long double with the same mode). */
9523 : 177 : if (REAL_VALUE_ISSIGNALING_NAN (TREE_REAL_CST (init))
9524 : 195 : && !comptypes (TYPE_MAIN_VARIANT (type),
9525 : 18 : TYPE_MAIN_VARIANT (TREE_TYPE (init))))
9526 : : return false;
9527 : 177 : return true;
9528 : : }
9529 : 185 : if (TREE_CODE (init) == INTEGER_CST)
9530 : : {
9531 : 54 : tree converted = build_real_from_int_cst (type, init);
9532 : 54 : bool fail = false;
9533 : 108 : wide_int w = real_to_integer (&TREE_REAL_CST (converted), &fail,
9534 : 54 : TYPE_PRECISION (TREE_TYPE (init)));
9535 : 68 : return !fail && wi::eq_p (w, wi::to_wide (init));
9536 : 54 : }
9537 : 131 : if (REAL_VALUE_ISSIGNALING_NAN (TREE_REAL_CST (init)))
9538 : : return false;
9539 : 114 : if ((REAL_VALUE_ISINF (TREE_REAL_CST (init))
9540 : 34 : && MODE_HAS_INFINITIES (TYPE_MODE (type)))
9541 : 218 : || (REAL_VALUE_ISNAN (TREE_REAL_CST (init))
9542 : 34 : && MODE_HAS_NANS (TYPE_MODE (type))))
9543 : 20 : return true;
9544 : 94 : if (DECIMAL_FLOAT_TYPE_P (type)
9545 : 134 : && !DECIMAL_FLOAT_TYPE_P (TREE_TYPE (init)))
9546 : : {
9547 : : /* This is valid if the real number represented by the
9548 : : initializer can be exactly represented in the decimal
9549 : : type. Compare the values using MPFR. */
9550 : 8 : REAL_VALUE_TYPE t;
9551 : 8 : real_convert (&t, TYPE_MODE (type), &TREE_REAL_CST (init));
9552 : 8 : mpfr_t bin_val, dec_val;
9553 : 8 : mpfr_init2 (bin_val, REAL_MODE_FORMAT (TYPE_MODE (TREE_TYPE (init)))->p);
9554 : 8 : mpfr_init2 (dec_val, REAL_MODE_FORMAT (TYPE_MODE (TREE_TYPE (init)))->p);
9555 : 8 : mpfr_from_real (bin_val, &TREE_REAL_CST (init), MPFR_RNDN);
9556 : 8 : char string[256];
9557 : 8 : real_to_decimal (string, &t, sizeof string, 0, 1);
9558 : 8 : bool res = (mpfr_strtofr (dec_val, string, NULL, 10, MPFR_RNDN) == 0
9559 : 8 : && mpfr_equal_p (bin_val, dec_val));
9560 : 8 : mpfr_clear (bin_val);
9561 : 8 : mpfr_clear (dec_val);
9562 : 8 : return res;
9563 : : }
9564 : : /* exact_real_truncate is not quite right here, since it doesn't
9565 : : allow even an exact conversion to subnormal values. */
9566 : 86 : REAL_VALUE_TYPE t;
9567 : 86 : real_convert (&t, TYPE_MODE (type), &TREE_REAL_CST (init));
9568 : 86 : return real_identical (&t, &TREE_REAL_CST (init));
9569 : : }
9570 : :
9571 : : /* Check whether INIT (location LOC) is valid as a 'constexpr'
9572 : : initializer for type TYPE, and give an error if not. INIT has
9573 : : already been folded and verified to be constant. INT_CONST_EXPR
9574 : : and ARITH_CONST_EXPR say whether it is an integer constant
9575 : : expression or arithmetic constant expression, respectively. If
9576 : : TYPE is not a scalar type, this function does nothing. */
9577 : :
9578 : : static void
9579 : 908 : check_constexpr_init (location_t loc, tree type, tree init,
9580 : : bool int_const_expr, bool arith_const_expr)
9581 : : {
9582 : 908 : if (POINTER_TYPE_P (type))
9583 : : {
9584 : : /* The initializer must be null. */
9585 : 86 : if (TREE_CODE (init) != INTEGER_CST || !integer_zerop (init))
9586 : 8 : error_at (loc, "%<constexpr%> pointer initializer is not null");
9587 : 86 : return;
9588 : : }
9589 : 822 : if (INTEGRAL_TYPE_P (type))
9590 : : {
9591 : : /* The initializer must be an integer constant expression,
9592 : : representable in the target type. */
9593 : 312 : if (!int_const_expr)
9594 : : {
9595 : 13 : if (TREE_CODE (init) == RAW_DATA_CST
9596 : 13 : && TYPE_PRECISION (type) == CHAR_BIT)
9597 : : {
9598 : 4 : if (!TYPE_UNSIGNED (type))
9599 : 137 : for (unsigned int i = 0;
9600 : 140 : i < (unsigned) RAW_DATA_LENGTH (init); ++i)
9601 : 138 : if (RAW_DATA_SCHAR_ELT (init, i) < 0)
9602 : : {
9603 : 1 : error_at (loc, "%<constexpr%> initializer not "
9604 : : "representable in type of object");
9605 : 1 : break;
9606 : : }
9607 : : }
9608 : : else
9609 : 9 : error_at (loc, "%<constexpr%> integer initializer is not an "
9610 : : "integer constant expression");
9611 : : }
9612 : 299 : else if (!int_fits_type_p (init, type))
9613 : 6 : error_at (loc, "%<constexpr%> initializer not representable in "
9614 : : "type of object");
9615 : 312 : return;
9616 : : }
9617 : : /* We don't apply any extra checks to extension types such as vector
9618 : : or fixed-point types. */
9619 : 510 : if (TREE_CODE (type) != REAL_TYPE && TREE_CODE (type) != COMPLEX_TYPE)
9620 : : return;
9621 : 353 : if (!arith_const_expr)
9622 : : {
9623 : 5 : error_at (loc, "%<constexpr%> initializer is not an arithmetic "
9624 : : "constant expression");
9625 : 5 : return;
9626 : : }
9627 : : /* We don't apply any extra checks to complex integers. */
9628 : 348 : if (TREE_CODE (type) == COMPLEX_TYPE
9629 : 348 : && TREE_CODE (TREE_TYPE (type)) != REAL_TYPE)
9630 : : return;
9631 : : /* Following N3082, a real type cannot be initialized from a complex
9632 : : type and a binary type cannot be initialized from a decimal type
9633 : : (but initializing a decimal type from a binary type is OK).
9634 : : Signaling NaN initializers are OK only if the types are
9635 : : compatible (not just the same mode); all quiet NaN and infinity
9636 : : initializations are considered to preserve the value. */
9637 : 348 : if (TREE_CODE (TREE_TYPE (init)) == COMPLEX_TYPE
9638 : 348 : && SCALAR_FLOAT_TYPE_P (type))
9639 : : {
9640 : 6 : error_at (loc, "%<constexpr%> initializer for a real type is of "
9641 : : "complex type");
9642 : 6 : return;
9643 : : }
9644 : 342 : if (SCALAR_FLOAT_TYPE_P (type)
9645 : 300 : && SCALAR_FLOAT_TYPE_P (TREE_TYPE (init))
9646 : 250 : && DECIMAL_FLOAT_TYPE_P (TREE_TYPE (init))
9647 : 481 : && !DECIMAL_FLOAT_TYPE_P (type))
9648 : : {
9649 : 6 : error_at (loc, "%<constexpr%> initializer for a binary "
9650 : : "floating-point type is of decimal type");
9651 : 6 : return;
9652 : : }
9653 : 336 : bool fits;
9654 : 336 : if (TREE_CODE (type) == COMPLEX_TYPE)
9655 : : {
9656 : 42 : switch (TREE_CODE (init))
9657 : : {
9658 : 10 : case INTEGER_CST:
9659 : 10 : case REAL_CST:
9660 : 10 : fits = constexpr_init_fits_real_type (TREE_TYPE (type), init);
9661 : 10 : break;
9662 : 32 : case COMPLEX_CST:
9663 : 32 : fits = (constexpr_init_fits_real_type (TREE_TYPE (type),
9664 : 32 : TREE_REALPART (init))
9665 : 58 : && constexpr_init_fits_real_type (TREE_TYPE (type),
9666 : 26 : TREE_IMAGPART (init)));
9667 : : break;
9668 : 0 : default:
9669 : 0 : gcc_unreachable ();
9670 : : }
9671 : : }
9672 : : else
9673 : 294 : fits = constexpr_init_fits_real_type (type, init);
9674 : 304 : if (!fits)
9675 : 65 : error_at (loc, "%<constexpr%> initializer not representable in "
9676 : : "type of object");
9677 : : }
9678 : :
9679 : : /* Digest the parser output INIT as an initializer for type TYPE
9680 : : initializing DECL.
9681 : : Return a C expression of type TYPE to represent the initial value.
9682 : :
9683 : : If ORIGTYPE is not NULL_TREE, it is the original type of INIT.
9684 : :
9685 : : NULL_POINTER_CONSTANT is true if INIT is a null pointer constant,
9686 : : INT_CONST_EXPR is true if INIT is an integer constant expression,
9687 : : and ARITH_CONST_EXPR is true if INIT is, or might be, an arithmetic
9688 : : constant expression, false if it has already been determined in the
9689 : : caller that it is not (but folding may have made the value passed here
9690 : : indistinguishable from an arithmetic constant expression).
9691 : :
9692 : : If INIT is a string constant, STRICT_STRING is true if it is
9693 : : unparenthesized or we should not warn here for it being parenthesized.
9694 : : For other types of INIT, STRICT_STRING is not used.
9695 : :
9696 : : INIT_LOC is the location of the INIT.
9697 : :
9698 : : REQUIRE_CONSTANT requests an error if non-constant initializers or
9699 : : elements are seen. REQUIRE_CONSTEXPR means the stricter requirements
9700 : : on initializers for 'constexpr' objects apply. */
9701 : :
9702 : : static tree
9703 : 16837659 : digest_init (location_t init_loc, tree decl, tree type, tree init,
9704 : : tree origtype, bool null_pointer_constant, bool int_const_expr,
9705 : : bool arith_const_expr, bool strict_string,
9706 : : bool require_constant, bool require_constexpr)
9707 : : {
9708 : 16837659 : enum tree_code code = TREE_CODE (type);
9709 : 16837659 : tree inside_init = init;
9710 : 16837659 : tree semantic_type = NULL_TREE;
9711 : 16837659 : bool maybe_const = true;
9712 : :
9713 : 16837659 : if (type == error_mark_node
9714 : 16837659 : || !init
9715 : 33675315 : || error_operand_p (init))
9716 : : return error_mark_node;
9717 : :
9718 : 16844894 : STRIP_TYPE_NOPS (inside_init);
9719 : :
9720 : : /* If require_constant is TRUE, when the initializer is a call to
9721 : : .ACCESS_WITH_SIZE, use the first argument as the initializer.
9722 : : For example:
9723 : : y = (char *) .ACCESS_WITH_SIZE ((char *) &static_annotated.c,...)
9724 : : will be converted to
9725 : : y = &static_annotated.c. */
9726 : :
9727 : 16836346 : if (require_constant
9728 : 2889397 : && TREE_CODE (inside_init) == NOP_EXPR
9729 : 736221 : && TREE_CODE (TREE_OPERAND (inside_init, 0)) == CALL_EXPR
9730 : 16836348 : && is_access_with_size_p (TREE_OPERAND (inside_init, 0)))
9731 : 2 : inside_init
9732 : 2 : = get_ref_from_access_with_size (TREE_OPERAND (inside_init, 0));
9733 : :
9734 : 16836346 : if (!c_in_omp_for)
9735 : : {
9736 : 16831605 : if (TREE_CODE (inside_init) == EXCESS_PRECISION_EXPR)
9737 : : {
9738 : 441 : semantic_type = TREE_TYPE (inside_init);
9739 : 441 : inside_init = TREE_OPERAND (inside_init, 0);
9740 : : }
9741 : 16831605 : inside_init = c_fully_fold (inside_init, require_constant, &maybe_const);
9742 : : }
9743 : : /* TODO: this may not detect all cases of expressions folding to
9744 : : constants that are not arithmetic constant expressions. */
9745 : 16836346 : if (!maybe_const)
9746 : : arith_const_expr = false;
9747 : 25123891 : else if (!INTEGRAL_TYPE_P (TREE_TYPE (inside_init))
9748 : 5639884 : && TREE_CODE (TREE_TYPE (inside_init)) != REAL_TYPE
9749 : 16772047 : && TREE_CODE (TREE_TYPE (inside_init)) != COMPLEX_TYPE)
9750 : : arith_const_expr = false;
9751 : 8380294 : else if (TREE_CODE (inside_init) != INTEGER_CST
9752 : : && TREE_CODE (inside_init) != REAL_CST
9753 : : && TREE_CODE (inside_init) != COMPLEX_CST
9754 : : && TREE_CODE (inside_init) != RAW_DATA_CST)
9755 : : arith_const_expr = false;
9756 : 5054829 : else if (TREE_OVERFLOW (inside_init))
9757 : 11781561 : arith_const_expr = false;
9758 : :
9759 : : /* Initialization of an array of chars from a string constant
9760 : : optionally enclosed in braces. */
9761 : :
9762 : 16836346 : if (code == ARRAY_TYPE && inside_init
9763 : 187974 : && TREE_CODE (inside_init) == STRING_CST)
9764 : : {
9765 : 11625 : tree typ1
9766 : 11625 : = (TYPE_ATOMIC (TREE_TYPE (type))
9767 : 11625 : ? c_build_qualified_type (TYPE_MAIN_VARIANT (TREE_TYPE (type)),
9768 : : TYPE_QUAL_ATOMIC)
9769 : 11611 : : TYPE_MAIN_VARIANT (TREE_TYPE (type)));
9770 : : /* Note that an array could be both an array of character type
9771 : : and an array of wchar_t if wchar_t is signed char or unsigned
9772 : : char. */
9773 : 23250 : bool char_array = (typ1 == char_type_node
9774 : 514 : || typ1 == signed_char_type_node
9775 : 12104 : || typ1 == unsigned_char_type_node);
9776 : 11625 : bool wchar_array = !!comptypes (typ1, wchar_type_node);
9777 : 11625 : bool char16_array = !!comptypes (typ1, char16_type_node);
9778 : 11625 : bool char32_array = !!comptypes (typ1, char32_type_node);
9779 : :
9780 : 11625 : if (char_array || wchar_array || char16_array || char32_array)
9781 : : {
9782 : 11596 : struct c_expr expr;
9783 : 11596 : tree typ2 = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init)));
9784 : 11596 : bool incompat_string_cst = false;
9785 : 11596 : expr.value = inside_init;
9786 : 11596 : expr.original_code = (strict_string ? STRING_CST : ERROR_MARK);
9787 : 11596 : expr.original_type = NULL;
9788 : 11596 : expr.m_decimal = 0;
9789 : 11596 : maybe_warn_string_init (init_loc, type, expr);
9790 : :
9791 : 11596 : if (TYPE_DOMAIN (type) && !TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
9792 : 91 : pedwarn_init (init_loc, OPT_Wpedantic,
9793 : : "initialization of a flexible array member");
9794 : :
9795 : 11596 : if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
9796 : 11596 : TYPE_MAIN_VARIANT (type)))
9797 : : return inside_init;
9798 : :
9799 : 4175 : if (char_array)
9800 : : {
9801 : 4064 : if (typ2 != char_type_node && typ2 != char8_type_node)
9802 : : incompat_string_cst = true;
9803 : : }
9804 : 111 : else if (!comptypes (typ1, typ2))
9805 : : incompat_string_cst = true;
9806 : :
9807 : : if (incompat_string_cst)
9808 : : {
9809 : 72 : error_init (init_loc, "cannot initialize array of %qT from "
9810 : : "a string literal with type array of %qT",
9811 : : typ1, typ2);
9812 : 72 : return error_mark_node;
9813 : : }
9814 : :
9815 : 4103 : if (require_constexpr
9816 : 4103 : && TYPE_UNSIGNED (typ1) != TYPE_UNSIGNED (typ2))
9817 : : {
9818 : : /* Check if all characters of the string can be
9819 : : represented in the type of the constexpr object being
9820 : : initialized. */
9821 : 24 : unsigned HOST_WIDE_INT len = TREE_STRING_LENGTH (inside_init);
9822 : 24 : const unsigned char *p =
9823 : 24 : (const unsigned char *) TREE_STRING_POINTER (inside_init);
9824 : 24 : gcc_assert (CHAR_TYPE_SIZE == 8 && CHAR_BIT == 8);
9825 : 70 : for (unsigned i = 0; i < len; i++)
9826 : 58 : if (p[i] > 127)
9827 : : {
9828 : 12 : error_init (init_loc, "%<constexpr%> initializer not "
9829 : : "representable in type of object");
9830 : 12 : break;
9831 : : }
9832 : : }
9833 : :
9834 : 4103 : if (TYPE_DOMAIN (type) != NULL_TREE
9835 : 4011 : && TYPE_SIZE (type) != NULL_TREE
9836 : 8055 : && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
9837 : : {
9838 : 3952 : unsigned HOST_WIDE_INT len = TREE_STRING_LENGTH (inside_init);
9839 : :
9840 : 3952 : if (compare_tree_int (TYPE_SIZE_UNIT (type), len) < 0)
9841 : : {
9842 : 396 : unsigned HOST_WIDE_INT avail
9843 : 396 : = tree_to_uhwi (TYPE_SIZE_UNIT (type));
9844 : 396 : unsigned unit = TYPE_PRECISION (typ1) / BITS_PER_UNIT;
9845 : 396 : const char *p = TREE_STRING_POINTER (inside_init);
9846 : :
9847 : : /* Construct truncated string. */
9848 : 396 : inside_init = build_string (avail, p);
9849 : :
9850 : : /* Subtract the size of a single (possibly wide) character
9851 : : because it may be ok to ignore the terminating NUL char
9852 : : that is counted in the length of the constant. */
9853 : 396 : if (len - unit > avail)
9854 : 63 : pedwarn_init (init_loc, 0,
9855 : : "initializer-string for array of %qT "
9856 : : "is too long (%wu chars into %wu "
9857 : : "available)", typ1, len, avail);
9858 : 333 : else if (warn_cxx_compat)
9859 : 9 : warning_at (init_loc, OPT_Wc___compat,
9860 : : "initializer-string for array of %qT "
9861 : : "is too long for C++ (%wu chars into %wu "
9862 : : "available)", typ1, len, avail);
9863 : 324 : else if (warn_unterminated_string_initialization
9864 : 324 : && get_attr_nonstring_decl (decl) == NULL_TREE)
9865 : 22 : warning_at (init_loc,
9866 : 22 : OPT_Wunterminated_string_initialization,
9867 : : "initializer-string for array of %qT "
9868 : : "truncates NUL terminator but destination "
9869 : : "lacks %qs attribute (%wu chars into %wu "
9870 : : "available)", typ1, "nonstring", len, avail);
9871 : : }
9872 : : }
9873 : :
9874 : 4103 : TREE_TYPE (inside_init) = type;
9875 : 4103 : return inside_init;
9876 : : }
9877 : 29 : else if (INTEGRAL_TYPE_P (typ1))
9878 : : {
9879 : 29 : error_init (init_loc, "array of inappropriate type initialized "
9880 : : "from string constant");
9881 : 29 : return error_mark_node;
9882 : : }
9883 : : }
9884 : :
9885 : : /* Build a VECTOR_CST from a *constant* vector constructor. If the
9886 : : vector constructor is not constant (e.g. {1,2,3,foo()}) then punt
9887 : : below and handle as a constructor. */
9888 : 16824721 : if (code == VECTOR_TYPE
9889 : 6287576 : && VECTOR_TYPE_P (TREE_TYPE (inside_init))
9890 : 6287574 : && vector_types_convertible_p (TREE_TYPE (inside_init), type, true)
9891 : 23112257 : && TREE_CONSTANT (inside_init))
9892 : : {
9893 : 630779 : if (TREE_CODE (inside_init) == VECTOR_CST
9894 : 630876 : && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
9895 : 97 : TYPE_MAIN_VARIANT (type)))
9896 : : return inside_init;
9897 : :
9898 : 630682 : if (TREE_CODE (inside_init) == CONSTRUCTOR)
9899 : : {
9900 : : unsigned HOST_WIDE_INT ix;
9901 : : tree value;
9902 : 4157307 : bool constant_p = true;
9903 : :
9904 : : /* Iterate through elements and check if all constructor
9905 : : elements are *_CSTs. */
9906 : 4157307 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (inside_init), ix, value)
9907 : 3526681 : if (!CONSTANT_CLASS_P (value))
9908 : : {
9909 : : constant_p = false;
9910 : : break;
9911 : : }
9912 : :
9913 : 630682 : if (constant_p)
9914 : 630626 : return build_vector_from_ctor (type,
9915 : 630626 : CONSTRUCTOR_ELTS (inside_init));
9916 : : }
9917 : : }
9918 : :
9919 : 16193998 : if (warn_sequence_point)
9920 : 2447631 : verify_sequence_points (inside_init);
9921 : :
9922 : : /* Any type can be initialized
9923 : : from an expression of the same type, optionally with braces. */
9924 : :
9925 : 16193998 : if (inside_init && TREE_TYPE (inside_init) != NULL_TREE
9926 : 32387996 : && (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
9927 : 16193998 : TYPE_MAIN_VARIANT (type))
9928 : 3118145 : || (code == ARRAY_TYPE
9929 : 477 : && comptypes (TREE_TYPE (inside_init), type))
9930 : 3118145 : || (gnu_vector_type_p (type)
9931 : 189 : && comptypes (TREE_TYPE (inside_init), type))
9932 : 3118145 : || (code == POINTER_TYPE
9933 : 111739 : && TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE
9934 : 9270 : && comptypes (TREE_TYPE (TREE_TYPE (inside_init)),
9935 : 9270 : TREE_TYPE (type)))))
9936 : : {
9937 : 13077829 : if (code == POINTER_TYPE)
9938 : : {
9939 : 784146 : if (TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE)
9940 : : {
9941 : 1976 : if (TREE_CODE (inside_init) == STRING_CST
9942 : 68 : || TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR)
9943 : 1973 : inside_init = array_to_pointer_conversion
9944 : 1973 : (init_loc, inside_init);
9945 : : else
9946 : : {
9947 : 3 : error_init (init_loc, "invalid use of non-lvalue array");
9948 : 3 : return error_mark_node;
9949 : : }
9950 : : }
9951 : : }
9952 : :
9953 : 13077826 : if (code == VECTOR_TYPE || c_hardbool_type_attr (type))
9954 : : /* Although the types are compatible, we may require a
9955 : : conversion. */
9956 : 5656797 : inside_init = convert (type, inside_init);
9957 : :
9958 : 13077826 : if ((code == RECORD_TYPE || code == UNION_TYPE)
9959 : 13077826 : && !comptypes (TYPE_MAIN_VARIANT (type), TYPE_MAIN_VARIANT (TREE_TYPE (inside_init))))
9960 : : {
9961 : 0 : error_init (init_loc, "invalid initializer");
9962 : 0 : return error_mark_node;
9963 : : }
9964 : :
9965 : 13077826 : if (require_constant
9966 : 2297075 : && TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR)
9967 : : {
9968 : : /* As an extension, allow initializing objects with static storage
9969 : : duration with compound literals (which are then treated just as
9970 : : the brace enclosed list they contain). Also allow this for
9971 : : vectors, as we can only assign them with compound literals. */
9972 : 31 : if (flag_isoc99 && code != VECTOR_TYPE)
9973 : 8 : pedwarn_init (init_loc, OPT_Wpedantic, "initializer element "
9974 : : "is not constant");
9975 : 31 : tree decl = COMPOUND_LITERAL_EXPR_DECL (inside_init);
9976 : 31 : inside_init = DECL_INITIAL (decl);
9977 : : }
9978 : :
9979 : 13077826 : if (code == ARRAY_TYPE && TREE_CODE (inside_init) != STRING_CST
9980 : 175872 : && TREE_CODE (inside_init) != CONSTRUCTOR)
9981 : : {
9982 : 2 : error_init (init_loc, "array initialized from non-constant array "
9983 : : "expression");
9984 : 2 : return error_mark_node;
9985 : : }
9986 : :
9987 : : /* Compound expressions can only occur here if -Wpedantic or
9988 : : -pedantic-errors is specified. In the later case, we always want
9989 : : an error. In the former case, we simply want a warning. */
9990 : 13077824 : if (require_constant && pedantic
9991 : 20284 : && TREE_CODE (inside_init) == COMPOUND_EXPR)
9992 : : {
9993 : 1 : inside_init
9994 : 1 : = valid_compound_expr_initializer (inside_init,
9995 : 1 : TREE_TYPE (inside_init));
9996 : 1 : if (inside_init == error_mark_node)
9997 : 1 : error_init (init_loc, "initializer element is not constant");
9998 : : else
9999 : 0 : pedwarn_init (init_loc, OPT_Wpedantic,
10000 : : "initializer element is not constant");
10001 : 1 : if (flag_pedantic_errors)
10002 : 0 : inside_init = error_mark_node;
10003 : : }
10004 : 2297074 : else if (require_constant
10005 : 2297074 : && !initializer_constant_valid_p (inside_init,
10006 : 2297074 : TREE_TYPE (inside_init)))
10007 : : {
10008 : 94 : error_init (init_loc, "initializer element is not constant");
10009 : 94 : inside_init = error_mark_node;
10010 : : }
10011 : 13077729 : else if (require_constant && !maybe_const)
10012 : 219 : pedwarn_init (init_loc, OPT_Wpedantic,
10013 : : "initializer element is not a constant expression");
10014 : 13077510 : else if (require_constexpr)
10015 : 582 : check_constexpr_init (init_loc, type, inside_init,
10016 : : int_const_expr, arith_const_expr);
10017 : :
10018 : : /* Added to enable additional -Wsuggest-attribute=format warnings. */
10019 : 13077824 : if (TREE_CODE (TREE_TYPE (inside_init)) == POINTER_TYPE)
10020 : 852587 : inside_init = convert_for_assignment (init_loc, UNKNOWN_LOCATION,
10021 : : type, inside_init, origtype,
10022 : : (require_constant
10023 : : ? ic_init_const
10024 : : : ic_init), null_pointer_constant,
10025 : : NULL_TREE, NULL_TREE, 0);
10026 : 13077824 : if (TREE_CODE (inside_init) == RAW_DATA_CST
10027 : 253 : && c_inhibit_evaluation_warnings == 0
10028 : 253 : && warn_conversion
10029 : 1 : && !TYPE_UNSIGNED (type)
10030 : 13077825 : && TYPE_PRECISION (type) == CHAR_BIT)
10031 : 303 : for (unsigned int i = 0;
10032 : 304 : i < (unsigned) RAW_DATA_LENGTH (inside_init); ++i)
10033 : 303 : if (RAW_DATA_SCHAR_ELT (inside_init, i) < 0)
10034 : 10 : warning_at (init_loc, OPT_Wconversion,
10035 : : "conversion from %qT to %qT changes value from "
10036 : : "%qd to %qd",
10037 : : integer_type_node, type,
10038 : 10 : RAW_DATA_UCHAR_ELT (inside_init, i),
10039 : 10 : RAW_DATA_SCHAR_ELT (inside_init, i));
10040 : 13077824 : return inside_init;
10041 : : }
10042 : :
10043 : : /* Handle scalar types, including conversions. */
10044 : :
10045 : 3116169 : if (code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE
10046 : 127797 : || code == POINTER_TYPE || code == ENUMERAL_TYPE || code == BOOLEAN_TYPE
10047 : 11082 : || code == COMPLEX_TYPE || code == VECTOR_TYPE || code == NULLPTR_TYPE
10048 : 9019 : || code == BITINT_TYPE)
10049 : : {
10050 : 3115681 : tree unconverted_init = inside_init;
10051 : 3115681 : if (TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE
10052 : 3115681 : && (TREE_CODE (init) == STRING_CST
10053 : 2 : || TREE_CODE (init) == COMPOUND_LITERAL_EXPR))
10054 : 7295 : inside_init = init = array_to_pointer_conversion (init_loc, init);
10055 : 3115681 : if (semantic_type)
10056 : 436 : inside_init = build1 (EXCESS_PRECISION_EXPR, semantic_type,
10057 : : inside_init);
10058 : 3115681 : inside_init
10059 : 5653772 : = convert_for_assignment (init_loc, UNKNOWN_LOCATION, type,
10060 : : inside_init, origtype,
10061 : : require_constant ? ic_init_const : ic_init,
10062 : : null_pointer_constant, NULL_TREE, NULL_TREE,
10063 : : 0);
10064 : :
10065 : : /* Check to see if we have already given an error message. */
10066 : 3115681 : if (inside_init == error_mark_node)
10067 : : ;
10068 : 3115221 : else if (require_constant && !TREE_CONSTANT (inside_init))
10069 : : {
10070 : 36 : error_init (init_loc, "initializer element is not constant");
10071 : 36 : inside_init = error_mark_node;
10072 : : }
10073 : 3115185 : else if (require_constant
10074 : 3692347 : && !initializer_constant_valid_p (inside_init,
10075 : 577162 : TREE_TYPE (inside_init)))
10076 : : {
10077 : 10 : error_init (init_loc, "initializer element is not computable at "
10078 : : "load time");
10079 : 10 : inside_init = error_mark_node;
10080 : : }
10081 : 3115175 : else if (require_constant && !maybe_const)
10082 : 5 : pedwarn_init (init_loc, OPT_Wpedantic,
10083 : : "initializer element is not a constant expression");
10084 : 3115170 : else if (require_constexpr)
10085 : 326 : check_constexpr_init (init_loc, type, unconverted_init,
10086 : : int_const_expr, arith_const_expr);
10087 : :
10088 : 3115681 : return inside_init;
10089 : : }
10090 : :
10091 : : /* Come here only for records and arrays. */
10092 : :
10093 : 488 : if (COMPLETE_TYPE_P (type) && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
10094 : : {
10095 : 0 : error_init (init_loc,
10096 : : "variable-sized object may not be initialized except "
10097 : : "with an empty initializer");
10098 : 0 : return error_mark_node;
10099 : : }
10100 : :
10101 : 488 : error_init (init_loc, "invalid initializer");
10102 : 488 : return error_mark_node;
10103 : : }
10104 : :
10105 : : /* Handle initializers that use braces. */
10106 : :
10107 : : /* Type of object we are accumulating a constructor for.
10108 : : This type is always a RECORD_TYPE, UNION_TYPE or ARRAY_TYPE. */
10109 : : static tree constructor_type;
10110 : :
10111 : : /* For a RECORD_TYPE or UNION_TYPE, this is the chain of fields
10112 : : left to fill. */
10113 : : static tree constructor_fields;
10114 : :
10115 : : /* For an ARRAY_TYPE, this is the specified index
10116 : : at which to store the next element we get. */
10117 : : static tree constructor_index;
10118 : :
10119 : : /* For an ARRAY_TYPE, this is the maximum index. */
10120 : : static tree constructor_max_index;
10121 : :
10122 : : /* For a RECORD_TYPE, this is the first field not yet written out. */
10123 : : static tree constructor_unfilled_fields;
10124 : :
10125 : : /* For an ARRAY_TYPE, this is the index of the first element
10126 : : not yet written out. */
10127 : : static tree constructor_unfilled_index;
10128 : :
10129 : : /* In a RECORD_TYPE, the byte index of the next consecutive field.
10130 : : This is so we can generate gaps between fields, when appropriate. */
10131 : : static tree constructor_bit_index;
10132 : :
10133 : : /* If we are saving up the elements rather than allocating them,
10134 : : this is the list of elements so far (in reverse order,
10135 : : most recent first). */
10136 : : static vec<constructor_elt, va_gc> *constructor_elements;
10137 : :
10138 : : /* 1 if constructor should be incrementally stored into a constructor chain,
10139 : : 0 if all the elements should be kept in AVL tree. */
10140 : : static int constructor_incremental;
10141 : :
10142 : : /* 1 if so far this constructor's elements are all compile-time constants. */
10143 : : static int constructor_constant;
10144 : :
10145 : : /* 1 if so far this constructor's elements are all valid address constants. */
10146 : : static int constructor_simple;
10147 : :
10148 : : /* 1 if this constructor has an element that cannot be part of a
10149 : : constant expression. */
10150 : : static int constructor_nonconst;
10151 : :
10152 : : /* 1 if this constructor is erroneous so far. */
10153 : : static int constructor_erroneous;
10154 : :
10155 : : /* 1 if this constructor is the universal zero initializer { 0 }. */
10156 : : static int constructor_zeroinit;
10157 : :
10158 : : /* 1 if this constructor should have padding bits zeroed (C23 {}. */
10159 : : static bool constructor_zero_padding_bits;
10160 : :
10161 : : /* 1 if this constructor is a braced scalar initializer (further nested levels
10162 : : of braces are an error). */
10163 : : static bool constructor_braced_scalar;
10164 : :
10165 : : /* Structure for managing pending initializer elements, organized as an
10166 : : AVL tree. */
10167 : :
10168 : : struct init_node
10169 : : {
10170 : : struct init_node *left, *right;
10171 : : struct init_node *parent;
10172 : : int balance;
10173 : : tree purpose;
10174 : : tree value;
10175 : : tree origtype;
10176 : : };
10177 : :
10178 : : /* Tree of pending elements at this constructor level.
10179 : : These are elements encountered out of order
10180 : : which belong at places we haven't reached yet in actually
10181 : : writing the output.
10182 : : Will never hold tree nodes across GC runs. */
10183 : : static struct init_node *constructor_pending_elts;
10184 : :
10185 : : /* The SPELLING_DEPTH of this constructor. */
10186 : : static int constructor_depth;
10187 : :
10188 : : /* DECL node for which an initializer is being read.
10189 : : 0 means we are reading a constructor expression
10190 : : such as (struct foo) {...}. */
10191 : : static tree constructor_decl;
10192 : :
10193 : : /* Nonzero if there were any member designators in this initializer. */
10194 : : static int constructor_designated;
10195 : :
10196 : : /* Nesting depth of designator list. */
10197 : : static int designator_depth;
10198 : :
10199 : : /* Nonzero if there were diagnosed errors in this designator list. */
10200 : : static int designator_erroneous;
10201 : :
10202 : :
10203 : : /* This stack has a level for each implicit or explicit level of
10204 : : structuring in the initializer, including the outermost one. It
10205 : : saves the values of most of the variables above. */
10206 : :
10207 : : struct constructor_range_stack;
10208 : :
10209 : : struct constructor_stack
10210 : : {
10211 : : struct constructor_stack *next;
10212 : : tree type;
10213 : : tree fields;
10214 : : tree index;
10215 : : tree max_index;
10216 : : tree unfilled_index;
10217 : : tree unfilled_fields;
10218 : : tree bit_index;
10219 : : vec<constructor_elt, va_gc> *elements;
10220 : : struct init_node *pending_elts;
10221 : : int offset;
10222 : : int depth;
10223 : : /* If value nonzero, this value should replace the entire
10224 : : constructor at this level. */
10225 : : struct c_expr replacement_value;
10226 : : struct constructor_range_stack *range_stack;
10227 : : char constant;
10228 : : char simple;
10229 : : char nonconst;
10230 : : char implicit;
10231 : : char erroneous;
10232 : : char outer;
10233 : : char incremental;
10234 : : char designated;
10235 : : bool zero_padding_bits;
10236 : : bool braced_scalar;
10237 : : int designator_depth;
10238 : : };
10239 : :
10240 : : static struct constructor_stack *constructor_stack;
10241 : :
10242 : : /* This stack represents designators from some range designator up to
10243 : : the last designator in the list. */
10244 : :
10245 : : struct constructor_range_stack
10246 : : {
10247 : : struct constructor_range_stack *next, *prev;
10248 : : struct constructor_stack *stack;
10249 : : tree range_start;
10250 : : tree index;
10251 : : tree range_end;
10252 : : tree fields;
10253 : : };
10254 : :
10255 : : static struct constructor_range_stack *constructor_range_stack;
10256 : :
10257 : : /* This stack records separate initializers that are nested.
10258 : : Nested initializers can't happen in ANSI C, but GNU C allows them
10259 : : in cases like { ... (struct foo) { ... } ... }. */
10260 : :
10261 : : struct initializer_stack
10262 : : {
10263 : : struct initializer_stack *next;
10264 : : tree decl;
10265 : : struct constructor_stack *constructor_stack;
10266 : : struct constructor_range_stack *constructor_range_stack;
10267 : : vec<constructor_elt, va_gc> *elements;
10268 : : struct spelling *spelling;
10269 : : struct spelling *spelling_base;
10270 : : int spelling_size;
10271 : : char require_constant_value;
10272 : : char require_constant_elements;
10273 : : char require_constexpr_value;
10274 : : char designated;
10275 : : rich_location *missing_brace_richloc;
10276 : : };
10277 : :
10278 : : static struct initializer_stack *initializer_stack;
10279 : :
10280 : : /* Prepare to parse and output the initializer for variable DECL. */
10281 : :
10282 : : void
10283 : 7242042 : start_init (tree decl, tree asmspec_tree ATTRIBUTE_UNUSED,
10284 : : bool init_require_constant, bool init_require_constexpr,
10285 : : rich_location *richloc)
10286 : : {
10287 : 7242042 : const char *locus;
10288 : 7242042 : struct initializer_stack *p = XNEW (struct initializer_stack);
10289 : :
10290 : 7242042 : p->decl = constructor_decl;
10291 : 7242042 : p->require_constant_value = require_constant_value;
10292 : 7242042 : p->require_constant_elements = require_constant_elements;
10293 : 7242042 : p->require_constexpr_value = require_constexpr_value;
10294 : 7242042 : p->constructor_stack = constructor_stack;
10295 : 7242042 : p->constructor_range_stack = constructor_range_stack;
10296 : 7242042 : p->elements = constructor_elements;
10297 : 7242042 : p->spelling = spelling;
10298 : 7242042 : p->spelling_base = spelling_base;
10299 : 7242042 : p->spelling_size = spelling_size;
10300 : 7242042 : p->next = initializer_stack;
10301 : 7242042 : p->missing_brace_richloc = richloc;
10302 : 7242042 : p->designated = constructor_designated;
10303 : 7242042 : initializer_stack = p;
10304 : :
10305 : 7242042 : constructor_decl = decl;
10306 : 7242042 : constructor_designated = 0;
10307 : :
10308 : 7242042 : require_constant_value = init_require_constant;
10309 : 7242042 : require_constexpr_value = init_require_constexpr;
10310 : 7242042 : if (decl != NULL_TREE && decl != error_mark_node)
10311 : : {
10312 : 6324085 : require_constant_elements
10313 : 6147268 : = ((init_require_constant || (pedantic && !flag_isoc99))
10314 : : /* For a scalar, you can always use any value to initialize,
10315 : : even within braces. */
10316 : 6336039 : && AGGREGATE_TYPE_P (TREE_TYPE (decl)));
10317 : 6324085 : locus = identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl)));
10318 : : }
10319 : : else
10320 : : {
10321 : 917957 : require_constant_elements = false;
10322 : 917957 : locus = _("(anonymous)");
10323 : : }
10324 : :
10325 : 7242042 : constructor_stack = 0;
10326 : 7242042 : constructor_range_stack = 0;
10327 : :
10328 : 7242042 : found_missing_braces = 0;
10329 : :
10330 : 7242042 : spelling_base = 0;
10331 : 7242042 : spelling_size = 0;
10332 : 7242042 : RESTORE_SPELLING_DEPTH (0);
10333 : :
10334 : 7242042 : if (locus)
10335 : 7242042 : push_string (locus);
10336 : 7242042 : }
10337 : :
10338 : : void
10339 : 7242040 : finish_init (void)
10340 : : {
10341 : 7242040 : struct initializer_stack *p = initializer_stack;
10342 : :
10343 : : /* Free the whole constructor stack of this initializer. */
10344 : 7242040 : while (constructor_stack)
10345 : : {
10346 : 0 : struct constructor_stack *q = constructor_stack;
10347 : 0 : constructor_stack = q->next;
10348 : 0 : XDELETE (q);
10349 : : }
10350 : :
10351 : 7242040 : gcc_assert (!constructor_range_stack);
10352 : :
10353 : : /* Pop back to the data of the outer initializer (if any). */
10354 : 7242040 : XDELETE (spelling_base);
10355 : :
10356 : 7242040 : constructor_decl = p->decl;
10357 : 7242040 : require_constant_value = p->require_constant_value;
10358 : 7242040 : require_constant_elements = p->require_constant_elements;
10359 : 7242040 : require_constexpr_value = p->require_constexpr_value;
10360 : 7242040 : constructor_stack = p->constructor_stack;
10361 : 7242040 : constructor_designated = p->designated;
10362 : 7242040 : constructor_range_stack = p->constructor_range_stack;
10363 : 7242040 : constructor_elements = p->elements;
10364 : 7242040 : spelling = p->spelling;
10365 : 7242040 : spelling_base = p->spelling_base;
10366 : 7242040 : spelling_size = p->spelling_size;
10367 : 7242040 : initializer_stack = p->next;
10368 : 7242040 : XDELETE (p);
10369 : 7242040 : }
10370 : :
10371 : : /* Call here when we see the initializer is surrounded by braces.
10372 : : This is instead of a call to push_init_level;
10373 : : it is matched by a call to pop_init_level.
10374 : :
10375 : : TYPE is the type to initialize, for a constructor expression.
10376 : : For an initializer for a decl, TYPE is zero. */
10377 : :
10378 : : void
10379 : 1021380 : really_start_incremental_init (tree type)
10380 : : {
10381 : 1021380 : struct constructor_stack *p = XNEW (struct constructor_stack);
10382 : :
10383 : 1021380 : if (type == NULL_TREE)
10384 : 105335 : type = TREE_TYPE (constructor_decl);
10385 : :
10386 : 1021380 : if (VECTOR_TYPE_P (type)
10387 : 1021380 : && TYPE_VECTOR_OPAQUE (type))
10388 : 0 : error ("opaque vector types cannot be initialized");
10389 : :
10390 : 1021380 : p->type = constructor_type;
10391 : 1021380 : p->fields = constructor_fields;
10392 : 1021380 : p->index = constructor_index;
10393 : 1021380 : p->max_index = constructor_max_index;
10394 : 1021380 : p->unfilled_index = constructor_unfilled_index;
10395 : 1021380 : p->unfilled_fields = constructor_unfilled_fields;
10396 : 1021380 : p->bit_index = constructor_bit_index;
10397 : 1021380 : p->elements = constructor_elements;
10398 : 1021380 : p->constant = constructor_constant;
10399 : 1021380 : p->simple = constructor_simple;
10400 : 1021380 : p->nonconst = constructor_nonconst;
10401 : 1021380 : p->erroneous = constructor_erroneous;
10402 : 1021380 : p->pending_elts = constructor_pending_elts;
10403 : 1021380 : p->depth = constructor_depth;
10404 : 1021380 : p->replacement_value.value = 0;
10405 : 1021380 : p->replacement_value.original_code = ERROR_MARK;
10406 : 1021380 : p->replacement_value.original_type = NULL;
10407 : 1021380 : p->implicit = 0;
10408 : 1021380 : p->range_stack = 0;
10409 : 1021380 : p->outer = 0;
10410 : 1021380 : p->incremental = constructor_incremental;
10411 : 1021380 : p->designated = constructor_designated;
10412 : 1021380 : p->zero_padding_bits = constructor_zero_padding_bits;
10413 : 1021380 : p->braced_scalar = constructor_braced_scalar;
10414 : 1021380 : p->designator_depth = designator_depth;
10415 : 1021380 : p->next = 0;
10416 : 1021380 : constructor_stack = p;
10417 : :
10418 : 1021380 : constructor_constant = 1;
10419 : 1021380 : constructor_simple = 1;
10420 : 1021380 : constructor_nonconst = 0;
10421 : 1021380 : constructor_depth = SPELLING_DEPTH ();
10422 : 1021380 : constructor_elements = NULL;
10423 : 1021380 : constructor_pending_elts = 0;
10424 : 1021380 : constructor_type = type;
10425 : 1021380 : constructor_incremental = 1;
10426 : 1021380 : constructor_designated = 0;
10427 : 1021380 : constructor_zero_padding_bits = false;
10428 : 1021380 : constructor_zeroinit = 1;
10429 : 1021380 : constructor_braced_scalar = false;
10430 : 1021380 : designator_depth = 0;
10431 : 1021380 : designator_erroneous = 0;
10432 : :
10433 : 1021380 : if (RECORD_OR_UNION_TYPE_P (constructor_type))
10434 : : {
10435 : 81150 : constructor_fields = TYPE_FIELDS (constructor_type);
10436 : : /* Skip any nameless bit fields at the beginning. */
10437 : 81150 : while (constructor_fields != NULL_TREE
10438 : 81178 : && DECL_UNNAMED_BIT_FIELD (constructor_fields))
10439 : 28 : constructor_fields = DECL_CHAIN (constructor_fields);
10440 : :
10441 : 81150 : constructor_unfilled_fields = constructor_fields;
10442 : 81150 : constructor_bit_index = bitsize_zero_node;
10443 : : }
10444 : 940230 : else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
10445 : : {
10446 : 17902 : if (TYPE_DOMAIN (constructor_type))
10447 : : {
10448 : 9465 : constructor_max_index
10449 : 9465 : = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
10450 : :
10451 : : /* Detect non-empty initializations of zero-length arrays. */
10452 : 9465 : if (constructor_max_index == NULL_TREE
10453 : 9465 : && TYPE_SIZE (constructor_type))
10454 : 205 : constructor_max_index = integer_minus_one_node;
10455 : :
10456 : : /* constructor_max_index needs to be an INTEGER_CST. Attempts
10457 : : to initialize VLAs with a nonempty initializer will cause a
10458 : : proper error; avoid tree checking errors as well by setting a
10459 : : safe value. */
10460 : 9465 : if (constructor_max_index
10461 : 9465 : && TREE_CODE (constructor_max_index) != INTEGER_CST)
10462 : 72 : constructor_max_index = integer_minus_one_node;
10463 : :
10464 : 9465 : constructor_index
10465 : 9465 : = convert (bitsizetype,
10466 : 9465 : TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
10467 : : }
10468 : : else
10469 : : {
10470 : 8437 : constructor_index = bitsize_zero_node;
10471 : 8437 : constructor_max_index = NULL_TREE;
10472 : : }
10473 : :
10474 : 17902 : constructor_unfilled_index = constructor_index;
10475 : : }
10476 : 922328 : else if (gnu_vector_type_p (constructor_type))
10477 : : {
10478 : : /* Vectors are like simple fixed-size arrays. */
10479 : 1843574 : constructor_max_index =
10480 : 921787 : bitsize_int (TYPE_VECTOR_SUBPARTS (constructor_type) - 1);
10481 : 921787 : constructor_index = bitsize_zero_node;
10482 : 921787 : constructor_unfilled_index = constructor_index;
10483 : : }
10484 : : else
10485 : : {
10486 : : /* Handle the case of int x = {5}; */
10487 : 541 : constructor_fields = constructor_type;
10488 : 541 : constructor_unfilled_fields = constructor_type;
10489 : 541 : constructor_braced_scalar = true;
10490 : : }
10491 : 1021380 : }
10492 : :
10493 : : extern location_t last_init_list_comma;
10494 : :
10495 : : /* Called when we see an open brace for a nested initializer. Finish
10496 : : off any pending levels with implicit braces. */
10497 : : void
10498 : 340355 : finish_implicit_inits (location_t loc, struct obstack *braced_init_obstack)
10499 : : {
10500 : 340357 : while (constructor_stack->implicit)
10501 : : {
10502 : 304 : if (RECORD_OR_UNION_TYPE_P (constructor_type)
10503 : 140 : && constructor_fields == NULL_TREE)
10504 : 0 : process_init_element (input_location,
10505 : : pop_init_level (loc, 1, braced_init_obstack,
10506 : : last_init_list_comma),
10507 : : true, braced_init_obstack);
10508 : 304 : else if (TREE_CODE (constructor_type) == ARRAY_TYPE
10509 : 164 : && constructor_max_index
10510 : 468 : && tree_int_cst_lt (constructor_max_index,
10511 : : constructor_index))
10512 : 2 : process_init_element (input_location,
10513 : : pop_init_level (loc, 1, braced_init_obstack,
10514 : : last_init_list_comma),
10515 : : true, braced_init_obstack);
10516 : : else
10517 : : break;
10518 : : }
10519 : 340355 : }
10520 : :
10521 : : /* Push down into a subobject, for initialization.
10522 : : If this is for an explicit set of braces, IMPLICIT is 0.
10523 : : If it is because the next element belongs at a lower level,
10524 : : IMPLICIT is 1 (or 2 if the push is because of designator list). */
10525 : :
10526 : : void
10527 : 1042996 : push_init_level (location_t loc, int implicit,
10528 : : struct obstack *braced_init_obstack)
10529 : : {
10530 : 1042996 : struct constructor_stack *p;
10531 : 1042996 : tree value = NULL_TREE;
10532 : :
10533 : : /* Unless this is an explicit brace, we need to preserve previous
10534 : : content if any. */
10535 : 1042996 : if (implicit)
10536 : : {
10537 : 703583 : if (RECORD_OR_UNION_TYPE_P (constructor_type) && constructor_fields)
10538 : 795 : value = find_init_member (constructor_fields, braced_init_obstack);
10539 : 702788 : else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
10540 : 702788 : value = find_init_member (constructor_index, braced_init_obstack);
10541 : : }
10542 : :
10543 : 1042996 : p = XNEW (struct constructor_stack);
10544 : 1042996 : p->type = constructor_type;
10545 : 1042996 : p->fields = constructor_fields;
10546 : 1042996 : p->index = constructor_index;
10547 : 1042996 : p->max_index = constructor_max_index;
10548 : 1042996 : p->unfilled_index = constructor_unfilled_index;
10549 : 1042996 : p->unfilled_fields = constructor_unfilled_fields;
10550 : 1042996 : p->bit_index = constructor_bit_index;
10551 : 1042996 : p->elements = constructor_elements;
10552 : 1042996 : p->constant = constructor_constant;
10553 : 1042996 : p->simple = constructor_simple;
10554 : 1042996 : p->nonconst = constructor_nonconst;
10555 : 1042996 : p->erroneous = constructor_erroneous;
10556 : 1042996 : p->pending_elts = constructor_pending_elts;
10557 : 1042996 : p->depth = constructor_depth;
10558 : 1042996 : p->replacement_value.value = NULL_TREE;
10559 : 1042996 : p->replacement_value.original_code = ERROR_MARK;
10560 : 1042996 : p->replacement_value.original_type = NULL;
10561 : 1042996 : p->implicit = implicit;
10562 : 1042996 : p->outer = 0;
10563 : 1042996 : p->incremental = constructor_incremental;
10564 : 1042996 : p->designated = constructor_designated;
10565 : 1042996 : p->zero_padding_bits = constructor_zero_padding_bits;
10566 : 1042996 : p->braced_scalar = constructor_braced_scalar;
10567 : 1042996 : p->designator_depth = designator_depth;
10568 : 1042996 : p->next = constructor_stack;
10569 : 1042996 : p->range_stack = 0;
10570 : 1042996 : constructor_stack = p;
10571 : :
10572 : 1042996 : constructor_constant = 1;
10573 : 1042996 : constructor_simple = 1;
10574 : 1042996 : constructor_nonconst = 0;
10575 : 1042996 : constructor_depth = SPELLING_DEPTH ();
10576 : 1042996 : constructor_elements = NULL;
10577 : 1042996 : constructor_incremental = 1;
10578 : : /* If the upper initializer is designated, then mark this as
10579 : : designated too to prevent bogus warnings. */
10580 : 1042996 : constructor_designated = p->designated;
10581 : : /* If the upper initializer has padding bits zeroed, that includes
10582 : : all nested initializers as well. */
10583 : 1042996 : constructor_zero_padding_bits = p->zero_padding_bits;
10584 : 1042996 : constructor_braced_scalar = false;
10585 : 1042996 : constructor_pending_elts = 0;
10586 : 1042996 : if (!implicit)
10587 : : {
10588 : 339413 : p->range_stack = constructor_range_stack;
10589 : 339413 : constructor_range_stack = 0;
10590 : 339413 : designator_depth = 0;
10591 : 339413 : designator_erroneous = 0;
10592 : : }
10593 : :
10594 : : /* Don't die if an entire brace-pair level is superfluous
10595 : : in the containing level. */
10596 : 1042996 : if (constructor_type == NULL_TREE)
10597 : : ;
10598 : 1042996 : else if (RECORD_OR_UNION_TYPE_P (constructor_type))
10599 : : {
10600 : : /* Don't die if there are extra init elts at the end. */
10601 : 158797 : if (constructor_fields == NULL_TREE)
10602 : 51 : constructor_type = NULL_TREE;
10603 : : else
10604 : : {
10605 : 158746 : constructor_type = TREE_TYPE (constructor_fields);
10606 : 158746 : push_member_name (constructor_fields);
10607 : 158746 : constructor_depth++;
10608 : : }
10609 : : }
10610 : 884199 : else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
10611 : : {
10612 : 884148 : constructor_type = TREE_TYPE (constructor_type);
10613 : 884148 : push_array_bounds (tree_to_uhwi (constructor_index));
10614 : 884148 : constructor_depth++;
10615 : : }
10616 : :
10617 : 1042996 : if (constructor_type == NULL_TREE)
10618 : : {
10619 : 51 : error_init (loc, "extra brace group at end of initializer");
10620 : 51 : constructor_fields = NULL_TREE;
10621 : 51 : constructor_unfilled_fields = NULL_TREE;
10622 : 51 : return;
10623 : : }
10624 : :
10625 : 1042945 : if (value && TREE_CODE (value) == CONSTRUCTOR)
10626 : : {
10627 : 360 : constructor_constant = TREE_CONSTANT (value);
10628 : 360 : constructor_simple = TREE_STATIC (value);
10629 : 360 : constructor_nonconst = CONSTRUCTOR_NON_CONST (value);
10630 : 360 : constructor_elements = CONSTRUCTOR_ELTS (value);
10631 : 360 : constructor_zero_padding_bits |= CONSTRUCTOR_ZERO_PADDING_BITS (value);
10632 : 360 : if (!vec_safe_is_empty (constructor_elements)
10633 : 340 : && (TREE_CODE (constructor_type) == RECORD_TYPE
10634 : 340 : || TREE_CODE (constructor_type) == ARRAY_TYPE))
10635 : 294 : set_nonincremental_init (braced_init_obstack);
10636 : : }
10637 : :
10638 : 1042945 : if (implicit == 1)
10639 : : {
10640 : 702641 : found_missing_braces = 1;
10641 : 702641 : if (initializer_stack->missing_brace_richloc)
10642 : 702641 : initializer_stack->missing_brace_richloc->add_fixit_insert_before
10643 : 702641 : (loc, "{");
10644 : : }
10645 : :
10646 : 1042945 : if (RECORD_OR_UNION_TYPE_P (constructor_type))
10647 : : {
10648 : 879648 : constructor_fields = TYPE_FIELDS (constructor_type);
10649 : : /* Skip any nameless bit fields at the beginning. */
10650 : 879648 : while (constructor_fields != NULL_TREE
10651 : 879712 : && DECL_UNNAMED_BIT_FIELD (constructor_fields))
10652 : 64 : constructor_fields = DECL_CHAIN (constructor_fields);
10653 : :
10654 : 879648 : constructor_unfilled_fields = constructor_fields;
10655 : 879648 : constructor_bit_index = bitsize_zero_node;
10656 : : }
10657 : 163297 : else if (gnu_vector_type_p (constructor_type))
10658 : : {
10659 : : /* Vectors are like simple fixed-size arrays. */
10660 : 9600 : constructor_max_index =
10661 : 4800 : bitsize_int (TYPE_VECTOR_SUBPARTS (constructor_type) - 1);
10662 : 4800 : constructor_index = bitsize_int (0);
10663 : 4800 : constructor_unfilled_index = constructor_index;
10664 : : }
10665 : 158497 : else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
10666 : : {
10667 : 158417 : if (TYPE_DOMAIN (constructor_type))
10668 : : {
10669 : 158417 : constructor_max_index
10670 : 158417 : = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
10671 : :
10672 : : /* Detect non-empty initializations of zero-length arrays. */
10673 : 158417 : if (constructor_max_index == NULL_TREE
10674 : 158417 : && TYPE_SIZE (constructor_type))
10675 : 135 : constructor_max_index = integer_minus_one_node;
10676 : :
10677 : : /* constructor_max_index needs to be an INTEGER_CST. Attempts
10678 : : to initialize VLAs will cause a proper error; avoid tree
10679 : : checking errors as well by setting a safe value. */
10680 : 158417 : if (constructor_max_index
10681 : 158148 : && TREE_CODE (constructor_max_index) != INTEGER_CST)
10682 : 2 : constructor_max_index = integer_minus_one_node;
10683 : :
10684 : 158417 : constructor_index
10685 : 158417 : = convert (bitsizetype,
10686 : 158417 : TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
10687 : : }
10688 : : else
10689 : 0 : constructor_index = bitsize_zero_node;
10690 : :
10691 : 158417 : constructor_unfilled_index = constructor_index;
10692 : 158417 : if (value && TREE_CODE (value) == STRING_CST)
10693 : : {
10694 : : /* We need to split the char/wchar array into individual
10695 : : characters, so that we don't have to special case it
10696 : : everywhere. */
10697 : 7 : set_nonincremental_init_from_string (value, braced_init_obstack);
10698 : : }
10699 : : }
10700 : : else
10701 : : {
10702 : 80 : if (constructor_type != error_mark_node)
10703 : : {
10704 : 51 : if (p->braced_scalar)
10705 : 22 : permerror_init (input_location, 0,
10706 : : "braces around scalar initializer");
10707 : : else
10708 : 29 : warning_init (input_location, 0,
10709 : : "braces around scalar initializer");
10710 : 51 : constructor_braced_scalar = true;
10711 : : }
10712 : 80 : constructor_fields = constructor_type;
10713 : 80 : constructor_unfilled_fields = constructor_type;
10714 : : }
10715 : : }
10716 : :
10717 : : /* At the end of an implicit or explicit brace level,
10718 : : finish up that level of constructor. If a single expression
10719 : : with redundant braces initialized that level, return the
10720 : : c_expr structure for that expression. Otherwise, the original_code
10721 : : element is set to ERROR_MARK.
10722 : : If we were outputting the elements as they are read, return 0 as the value
10723 : : from inner levels (process_init_element ignores that),
10724 : : but return error_mark_node as the value from the outermost level
10725 : : (that's what we want to put in DECL_INITIAL).
10726 : : Otherwise, return a CONSTRUCTOR expression as the value. */
10727 : :
10728 : : struct c_expr
10729 : 2064376 : pop_init_level (location_t loc, int implicit,
10730 : : struct obstack *braced_init_obstack,
10731 : : location_t insert_before)
10732 : : {
10733 : 2064376 : struct constructor_stack *p;
10734 : 2064376 : struct c_expr ret;
10735 : 2064376 : ret.value = NULL_TREE;
10736 : 2064376 : ret.original_code = ERROR_MARK;
10737 : 2064376 : ret.original_type = NULL;
10738 : 2064376 : ret.m_decimal = 0;
10739 : :
10740 : 2064376 : if (implicit == 0)
10741 : : {
10742 : : /* When we come to an explicit close brace,
10743 : : pop any inner levels that didn't have explicit braces. */
10744 : 1361695 : while (constructor_stack->implicit)
10745 : 902 : process_init_element (input_location,
10746 : : pop_init_level (loc, 1, braced_init_obstack,
10747 : : insert_before),
10748 : : true, braced_init_obstack);
10749 : 1360793 : gcc_assert (!constructor_range_stack);
10750 : : }
10751 : : else
10752 : 703583 : if (initializer_stack->missing_brace_richloc)
10753 : 703583 : initializer_stack->missing_brace_richloc->add_fixit_insert_before
10754 : 703583 : (insert_before, "}");
10755 : :
10756 : : /* Now output all pending elements. */
10757 : 2064376 : constructor_incremental = 1;
10758 : 2064376 : output_pending_init_elements (1, braced_init_obstack);
10759 : :
10760 : 2064376 : p = constructor_stack;
10761 : :
10762 : : /* Error for initializing a flexible array member, or a zero-length
10763 : : array member in an inappropriate context. */
10764 : 2064325 : if (constructor_type && constructor_fields
10765 : 159291 : && TREE_CODE (constructor_type) == ARRAY_TYPE
10766 : 152555 : && TYPE_DOMAIN (constructor_type)
10767 : 2216923 : && !TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type)))
10768 : : {
10769 : : /* Silently discard empty initializations. The parser will
10770 : : already have pedwarned for empty brackets for C17 and earlier. */
10771 : 299 : if (integer_zerop (constructor_unfilled_index))
10772 : 84 : constructor_type = NULL_TREE;
10773 : 299 : if (constructor_type || flag_isoc23)
10774 : : {
10775 : 295 : gcc_assert (!constructor_type || !TYPE_SIZE (constructor_type));
10776 : :
10777 : 295 : if (constructor_depth <= 2)
10778 : 248 : pedwarn_init (loc, OPT_Wpedantic,
10779 : : "initialization of a flexible array member");
10780 : 47 : else if (constructor_type)
10781 : 33 : error_init (loc, "initialization of flexible array member "
10782 : : "in a nested context");
10783 : : else
10784 : 14 : pedwarn_init (loc, OPT_Wpedantic,
10785 : : "initialization of flexible array member "
10786 : : "in a nested context");
10787 : :
10788 : : /* We have already issued an error message for the existence
10789 : : of a flexible array member not at the end of the structure.
10790 : : Discard the initializer so that we do not die later. */
10791 : 295 : if (constructor_type
10792 : 215 : && DECL_CHAIN (constructor_fields) != NULL_TREE
10793 : 301 : && (!p->type || TREE_CODE (p->type) != UNION_TYPE))
10794 : 0 : constructor_type = NULL_TREE;
10795 : : }
10796 : : }
10797 : :
10798 : 2064376 : switch (vec_safe_length (constructor_elements))
10799 : : {
10800 : 4683 : case 0:
10801 : : /* Initialization with { } counts as zeroinit. */
10802 : 4683 : constructor_zeroinit = 1;
10803 : 4683 : break;
10804 : 914904 : case 1:
10805 : : /* This might be zeroinit as well. */
10806 : 914904 : if (integer_zerop ((*constructor_elements)[0].value))
10807 : 1974 : constructor_zeroinit = 1;
10808 : : break;
10809 : 1144789 : default:
10810 : : /* If the constructor has more than one element, it can't be { 0 }. */
10811 : 1144789 : constructor_zeroinit = 0;
10812 : 1144789 : break;
10813 : : }
10814 : :
10815 : : /* Warn when some structs are initialized with direct aggregation. */
10816 : 2064376 : if (!implicit && found_missing_braces && warn_missing_braces
10817 : 37 : && !constructor_zeroinit)
10818 : : {
10819 : 18 : gcc_assert (initializer_stack->missing_brace_richloc);
10820 : 18 : warning_at (initializer_stack->missing_brace_richloc,
10821 : 18 : OPT_Wmissing_braces,
10822 : : "missing braces around initializer");
10823 : : }
10824 : :
10825 : : /* Warn when some struct elements are implicitly initialized to zero. */
10826 : 2064376 : if (warn_missing_field_initializers
10827 : 425443 : && constructor_type
10828 : 425415 : && TREE_CODE (constructor_type) == RECORD_TYPE
10829 : 193395 : && constructor_unfilled_fields)
10830 : : {
10831 : : /* Do not warn for flexible array members or zero-length arrays. */
10832 : 43 : while (constructor_unfilled_fields
10833 : 43 : && (!DECL_SIZE (constructor_unfilled_fields)
10834 : 43 : || integer_zerop (DECL_SIZE (constructor_unfilled_fields))))
10835 : 0 : constructor_unfilled_fields = DECL_CHAIN (constructor_unfilled_fields);
10836 : :
10837 : 43 : if (constructor_unfilled_fields
10838 : : /* Do not warn if this level of the initializer uses member
10839 : : designators; it is likely to be deliberate. */
10840 : 43 : && !constructor_designated
10841 : : /* Do not warn about initializing with { 0 } or with { }. */
10842 : 24 : && !constructor_zeroinit)
10843 : : {
10844 : 10 : if (warning_at (input_location, OPT_Wmissing_field_initializers,
10845 : : "missing initializer for field %qD of %qT",
10846 : : constructor_unfilled_fields,
10847 : : constructor_type))
10848 : 10 : inform (DECL_SOURCE_LOCATION (constructor_unfilled_fields),
10849 : : "%qD declared here", constructor_unfilled_fields);
10850 : : }
10851 : : }
10852 : :
10853 : : /* Pad out the end of the structure. */
10854 : 2064376 : if (p->replacement_value.value)
10855 : : /* If this closes a superfluous brace pair,
10856 : : just pass out the element between them. */
10857 : 138 : ret = p->replacement_value;
10858 : 2064238 : else if (constructor_type == NULL_TREE)
10859 : : ;
10860 : 2064111 : else if (!RECORD_OR_UNION_TYPE_P (constructor_type)
10861 : 2064111 : && TREE_CODE (constructor_type) != ARRAY_TYPE
10862 : 2064111 : && !gnu_vector_type_p (constructor_type))
10863 : : {
10864 : : /* A nonincremental scalar initializer--just return
10865 : : the element, after verifying there is just one.
10866 : : Empty scalar initializers are supported in C23. */
10867 : 621 : if (vec_safe_is_empty (constructor_elements))
10868 : : {
10869 : 201 : if (constructor_erroneous || constructor_type == error_mark_node)
10870 : 85 : ret.value = error_mark_node;
10871 : 116 : else if (TREE_CODE (constructor_type) == FUNCTION_TYPE)
10872 : : {
10873 : 2 : error_init (loc, "invalid initializer");
10874 : 2 : ret.value = error_mark_node;
10875 : : }
10876 : 114 : else if (TREE_CODE (constructor_type) == POINTER_TYPE)
10877 : : /* Ensure this is a null pointer constant in the case of a
10878 : : 'constexpr' object initialized with {}. */
10879 : 33 : ret.value = build_zero_cst (ptr_type_node);
10880 : : else
10881 : 81 : ret.value = build_zero_cst (constructor_type);
10882 : : }
10883 : 420 : else if (vec_safe_length (constructor_elements) != 1)
10884 : : {
10885 : 0 : error_init (loc, "extra elements in scalar initializer");
10886 : 0 : ret.value = (*constructor_elements)[0].value;
10887 : : }
10888 : : else
10889 : 420 : ret.value = (*constructor_elements)[0].value;
10890 : : }
10891 : : else
10892 : : {
10893 : 2063490 : if (constructor_erroneous)
10894 : 492 : ret.value = error_mark_node;
10895 : : else
10896 : : {
10897 : 2062998 : ret.value = build_constructor (constructor_type,
10898 : : constructor_elements);
10899 : 2062998 : if (constructor_constant)
10900 : 1734882 : TREE_CONSTANT (ret.value) = 1;
10901 : 2062998 : if (constructor_constant && constructor_simple)
10902 : 1734843 : TREE_STATIC (ret.value) = 1;
10903 : 2062998 : if (constructor_nonconst)
10904 : 641 : CONSTRUCTOR_NON_CONST (ret.value) = 1;
10905 : 2062998 : if (constructor_zero_padding_bits)
10906 : 20 : CONSTRUCTOR_ZERO_PADDING_BITS (ret.value) = 1;
10907 : : }
10908 : : }
10909 : :
10910 : 2064376 : if (ret.value && TREE_CODE (ret.value) != CONSTRUCTOR)
10911 : : {
10912 : 1251 : if (constructor_nonconst)
10913 : 15 : ret.original_code = C_MAYBE_CONST_EXPR;
10914 : 1236 : else if (ret.original_code == C_MAYBE_CONST_EXPR)
10915 : 0 : ret.original_code = ERROR_MARK;
10916 : : }
10917 : :
10918 : 2064376 : constructor_type = p->type;
10919 : 2064376 : constructor_fields = p->fields;
10920 : 2064376 : constructor_index = p->index;
10921 : 2064376 : constructor_max_index = p->max_index;
10922 : 2064376 : constructor_unfilled_index = p->unfilled_index;
10923 : 2064376 : constructor_unfilled_fields = p->unfilled_fields;
10924 : 2064376 : constructor_bit_index = p->bit_index;
10925 : 2064376 : constructor_elements = p->elements;
10926 : 2064376 : constructor_constant = p->constant;
10927 : 2064376 : constructor_simple = p->simple;
10928 : 2064376 : constructor_nonconst = p->nonconst;
10929 : 2064376 : constructor_erroneous = p->erroneous;
10930 : 2064376 : constructor_incremental = p->incremental;
10931 : 2064376 : constructor_designated = p->designated;
10932 : 2064376 : constructor_zero_padding_bits = p->zero_padding_bits;
10933 : 2064376 : constructor_braced_scalar = p->braced_scalar;
10934 : 2064376 : designator_depth = p->designator_depth;
10935 : 2064376 : constructor_pending_elts = p->pending_elts;
10936 : 2064376 : constructor_depth = p->depth;
10937 : 2064376 : if (!p->implicit)
10938 : 1360793 : constructor_range_stack = p->range_stack;
10939 : 2064376 : RESTORE_SPELLING_DEPTH (constructor_depth);
10940 : :
10941 : 2064376 : constructor_stack = p->next;
10942 : 2064376 : XDELETE (p);
10943 : :
10944 : 2064376 : if (ret.value == NULL_TREE && constructor_stack == 0)
10945 : 0 : ret.value = error_mark_node;
10946 : 2064376 : return ret;
10947 : : }
10948 : :
10949 : : /* Common handling for both array range and field name designators.
10950 : : ARRAY argument is nonzero for array ranges. Returns false for success. */
10951 : :
10952 : : static bool
10953 : 33851 : set_designator (location_t loc, bool array,
10954 : : struct obstack *braced_init_obstack)
10955 : : {
10956 : 33851 : tree subtype;
10957 : 33851 : enum tree_code subcode;
10958 : :
10959 : : /* Don't die if an entire brace-pair level is superfluous
10960 : : in the containing level, or for an erroneous type. */
10961 : 33851 : if (constructor_type == NULL_TREE || constructor_type == error_mark_node)
10962 : : return true;
10963 : :
10964 : : /* If there were errors in this designator list already, bail out
10965 : : silently. */
10966 : 33842 : if (designator_erroneous)
10967 : : return true;
10968 : :
10969 : : /* Likewise for an initializer for a variable-size type. Those are
10970 : : diagnosed in the parser, except for empty initializer braces. */
10971 : 33842 : if (COMPLETE_TYPE_P (constructor_type)
10972 : 33842 : && TREE_CODE (TYPE_SIZE (constructor_type)) != INTEGER_CST)
10973 : : return true;
10974 : :
10975 : 33832 : if (!designator_depth)
10976 : : {
10977 : 33214 : gcc_assert (!constructor_range_stack);
10978 : :
10979 : : /* Designator list starts at the level of closest explicit
10980 : : braces. */
10981 : 33597 : while (constructor_stack->implicit)
10982 : 383 : process_init_element (input_location,
10983 : : pop_init_level (loc, 1, braced_init_obstack,
10984 : : last_init_list_comma),
10985 : : true, braced_init_obstack);
10986 : 33214 : constructor_designated = 1;
10987 : 33214 : return false;
10988 : : }
10989 : :
10990 : 618 : switch (TREE_CODE (constructor_type))
10991 : : {
10992 : 421 : case RECORD_TYPE:
10993 : 421 : case UNION_TYPE:
10994 : 421 : subtype = TREE_TYPE (constructor_fields);
10995 : 421 : if (subtype != error_mark_node)
10996 : 421 : subtype = TYPE_MAIN_VARIANT (subtype);
10997 : : break;
10998 : 197 : case ARRAY_TYPE:
10999 : 197 : subtype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
11000 : 197 : break;
11001 : 0 : default:
11002 : 0 : gcc_unreachable ();
11003 : : }
11004 : :
11005 : 618 : subcode = TREE_CODE (subtype);
11006 : 618 : if (array && subcode != ARRAY_TYPE)
11007 : : {
11008 : 1 : error_init (loc, "array index in non-array initializer");
11009 : 1 : return true;
11010 : : }
11011 : 617 : else if (!array && subcode != RECORD_TYPE && subcode != UNION_TYPE)
11012 : : {
11013 : 0 : error_init (loc, "field name not in record or union initializer");
11014 : 0 : return true;
11015 : : }
11016 : :
11017 : 617 : constructor_designated = 1;
11018 : 617 : finish_implicit_inits (loc, braced_init_obstack);
11019 : 617 : push_init_level (loc, 2, braced_init_obstack);
11020 : 617 : return false;
11021 : : }
11022 : :
11023 : : /* If there are range designators in designator list, push a new designator
11024 : : to constructor_range_stack. RANGE_END is end of such stack range or
11025 : : NULL_TREE if there is no range designator at this level. */
11026 : :
11027 : : static void
11028 : 384 : push_range_stack (tree range_end, struct obstack * braced_init_obstack)
11029 : : {
11030 : 384 : struct constructor_range_stack *p;
11031 : :
11032 : 768 : p = (struct constructor_range_stack *)
11033 : 384 : obstack_alloc (braced_init_obstack,
11034 : : sizeof (struct constructor_range_stack));
11035 : 384 : p->prev = constructor_range_stack;
11036 : 384 : p->next = 0;
11037 : 384 : p->fields = constructor_fields;
11038 : 384 : p->range_start = constructor_index;
11039 : 384 : p->index = constructor_index;
11040 : 384 : p->stack = constructor_stack;
11041 : 384 : p->range_end = range_end;
11042 : 384 : if (constructor_range_stack)
11043 : 19 : constructor_range_stack->next = p;
11044 : 384 : constructor_range_stack = p;
11045 : 384 : }
11046 : :
11047 : : /* Within an array initializer, specify the next index to be initialized.
11048 : : FIRST is that index. If LAST is nonzero, then initialize a range
11049 : : of indices, running from FIRST through LAST. */
11050 : :
11051 : : void
11052 : 1143 : set_init_index (location_t loc, tree first, tree last,
11053 : : struct obstack *braced_init_obstack)
11054 : : {
11055 : 1143 : if (set_designator (loc, true, braced_init_obstack))
11056 : : return;
11057 : :
11058 : 1140 : designator_erroneous = 1;
11059 : :
11060 : 2280 : if (!INTEGRAL_TYPE_P (TREE_TYPE (first))
11061 : 2269 : || (last && !INTEGRAL_TYPE_P (TREE_TYPE (last))))
11062 : : {
11063 : 12 : error_init (loc, "array index in initializer not of integer type");
11064 : 12 : return;
11065 : : }
11066 : :
11067 : 1128 : if (TREE_CODE (first) != INTEGER_CST)
11068 : : {
11069 : 6 : first = c_fully_fold (first, false, NULL);
11070 : 6 : if (TREE_CODE (first) == INTEGER_CST)
11071 : 5 : pedwarn_init (loc, OPT_Wpedantic,
11072 : : "array index in initializer is not "
11073 : : "an integer constant expression");
11074 : : }
11075 : :
11076 : 1128 : if (last && TREE_CODE (last) != INTEGER_CST)
11077 : : {
11078 : 2 : last = c_fully_fold (last, false, NULL);
11079 : 2 : if (TREE_CODE (last) == INTEGER_CST)
11080 : 1 : pedwarn_init (loc, OPT_Wpedantic,
11081 : : "array index in initializer is not "
11082 : : "an integer constant expression");
11083 : : }
11084 : :
11085 : 1128 : if (TREE_CODE (first) != INTEGER_CST)
11086 : 1 : error_init (loc, "nonconstant array index in initializer");
11087 : 1127 : else if (last != NULL_TREE && TREE_CODE (last) != INTEGER_CST)
11088 : 1 : error_init (loc, "nonconstant array index in initializer");
11089 : 1126 : else if (TREE_CODE (constructor_type) != ARRAY_TYPE)
11090 : 9 : error_init (loc, "array index in non-array initializer");
11091 : 1117 : else if (tree_int_cst_sgn (first) == -1)
11092 : 15 : error_init (loc, "array index in initializer exceeds array bounds");
11093 : 1102 : else if (constructor_max_index
11094 : 1102 : && tree_int_cst_lt (constructor_max_index, first))
11095 : 7 : error_init (loc, "array index in initializer exceeds array bounds");
11096 : : else
11097 : : {
11098 : 1095 : constant_expression_warning (first);
11099 : 1095 : if (last)
11100 : 379 : constant_expression_warning (last);
11101 : 1095 : constructor_index = convert (bitsizetype, first);
11102 : 1095 : if (tree_int_cst_lt (constructor_index, first))
11103 : : {
11104 : 0 : constructor_index = copy_node (constructor_index);
11105 : 0 : TREE_OVERFLOW (constructor_index) = 1;
11106 : : }
11107 : :
11108 : 1095 : if (last)
11109 : : {
11110 : 379 : if (tree_int_cst_equal (first, last))
11111 : : last = NULL_TREE;
11112 : 378 : else if (tree_int_cst_lt (last, first))
11113 : : {
11114 : 2 : error_init (loc, "empty index range in initializer");
11115 : 2 : last = NULL_TREE;
11116 : : }
11117 : : else
11118 : : {
11119 : 376 : last = convert (bitsizetype, last);
11120 : 376 : if (constructor_max_index != NULL_TREE
11121 : 376 : && tree_int_cst_lt (constructor_max_index, last))
11122 : : {
11123 : 3 : error_init (loc, "array index range in initializer exceeds "
11124 : : "array bounds");
11125 : 3 : last = NULL_TREE;
11126 : : }
11127 : : }
11128 : : }
11129 : :
11130 : 1095 : designator_depth++;
11131 : 1095 : designator_erroneous = 0;
11132 : 1095 : if (constructor_range_stack || last)
11133 : 373 : push_range_stack (last, braced_init_obstack);
11134 : : }
11135 : : }
11136 : :
11137 : : /* Within a struct initializer, specify the next field to be initialized. */
11138 : :
11139 : : void
11140 : 32663 : set_init_label (location_t loc, tree fieldname, location_t fieldname_loc,
11141 : : struct obstack *braced_init_obstack)
11142 : : {
11143 : 32663 : tree field;
11144 : :
11145 : 32663 : if (set_designator (loc, false, braced_init_obstack))
11146 : : return;
11147 : :
11148 : 32646 : designator_erroneous = 1;
11149 : :
11150 : 32646 : if (!RECORD_OR_UNION_TYPE_P (constructor_type))
11151 : : {
11152 : 3 : error_init (loc, "field name not in record or union initializer");
11153 : 3 : return;
11154 : : }
11155 : :
11156 : 32643 : field = lookup_field (constructor_type, fieldname);
11157 : :
11158 : 32643 : if (field == NULL_TREE)
11159 : : {
11160 : 8 : tree guessed_id = lookup_field_fuzzy (constructor_type, fieldname);
11161 : 8 : if (guessed_id)
11162 : : {
11163 : 4 : gcc_rich_location rich_loc (fieldname_loc);
11164 : 4 : rich_loc.add_fixit_misspelled_id (fieldname_loc, guessed_id);
11165 : 4 : error_at (&rich_loc,
11166 : : "%qT has no member named %qE; did you mean %qE?",
11167 : : constructor_type, fieldname, guessed_id);
11168 : 4 : }
11169 : : else
11170 : 4 : error_at (fieldname_loc, "%qT has no member named %qE",
11171 : : constructor_type, fieldname);
11172 : : }
11173 : : else
11174 : 32680 : do
11175 : : {
11176 : 32680 : constructor_fields = TREE_VALUE (field);
11177 : 32680 : designator_depth++;
11178 : 32680 : designator_erroneous = 0;
11179 : 32680 : if (constructor_range_stack)
11180 : 11 : push_range_stack (NULL_TREE, braced_init_obstack);
11181 : 32680 : field = TREE_CHAIN (field);
11182 : 32680 : if (field)
11183 : : {
11184 : 45 : if (set_designator (loc, false, braced_init_obstack))
11185 : : return;
11186 : : }
11187 : : }
11188 : 32680 : while (field != NULL_TREE);
11189 : : }
11190 : :
11191 : : /* Helper function for add_pending_init. Find inorder successor of P
11192 : : in AVL tree. */
11193 : : static struct init_node *
11194 : 129 : init_node_successor (struct init_node *p)
11195 : : {
11196 : 129 : struct init_node *r;
11197 : 129 : if (p->right)
11198 : : {
11199 : : r = p->right;
11200 : 58 : while (r->left)
11201 : : r = r->left;
11202 : : return r;
11203 : : }
11204 : 75 : r = p->parent;
11205 : 114 : while (r && p == r->right)
11206 : : {
11207 : 39 : p = r;
11208 : 39 : r = r->parent;
11209 : : }
11210 : : return r;
11211 : : }
11212 : :
11213 : : /* Add a new initializer to the tree of pending initializers. PURPOSE
11214 : : identifies the initializer, either array index or field in a structure.
11215 : : VALUE is the value of that index or field. If ORIGTYPE is not
11216 : : NULL_TREE, it is the original type of VALUE.
11217 : :
11218 : : IMPLICIT is true if value comes from pop_init_level (1),
11219 : : the new initializer has been merged with the existing one
11220 : : and thus no warnings should be emitted about overriding an
11221 : : existing initializer. */
11222 : :
11223 : : static void
11224 : 3269 : add_pending_init (location_t loc, tree purpose, tree value, tree origtype,
11225 : : bool implicit, struct obstack *braced_init_obstack)
11226 : : {
11227 : 3269 : struct init_node *p, **q, *r;
11228 : :
11229 : 3269 : q = &constructor_pending_elts;
11230 : 3269 : p = 0;
11231 : :
11232 : 3269 : if (TREE_CODE (constructor_type) == ARRAY_TYPE)
11233 : : {
11234 : 3610 : while (*q != 0)
11235 : : {
11236 : 2412 : p = *q;
11237 : 2412 : if (tree_int_cst_lt (purpose, p->purpose))
11238 : 283 : q = &p->left;
11239 : 2129 : else if (tree_int_cst_lt (p->purpose, purpose))
11240 : : {
11241 : 1960 : if (TREE_CODE (p->value) != RAW_DATA_CST
11242 : 1960 : || (p->right
11243 : 112 : && tree_int_cst_le (p->right->purpose, purpose)))
11244 : 1830 : q = &p->right;
11245 : : else
11246 : : {
11247 : 130 : widest_int pp = wi::to_widest (p->purpose);
11248 : 130 : widest_int pw = wi::to_widest (purpose);
11249 : 130 : if (pp + RAW_DATA_LENGTH (p->value) <= pw)
11250 : 98 : q = &p->right;
11251 : : else
11252 : : {
11253 : : /* Override which should split the old RAW_DATA_CST
11254 : : into 2 or 3 pieces. */
11255 : 32 : if (!implicit && warn_override_init)
11256 : 9 : warning_init (loc, OPT_Woverride_init,
11257 : : "initialized field overwritten");
11258 : 32 : unsigned HOST_WIDE_INT start = (pw - pp).to_uhwi ();
11259 : 32 : unsigned HOST_WIDE_INT len = 1;
11260 : 32 : if (TREE_CODE (value) == RAW_DATA_CST)
11261 : 0 : len = RAW_DATA_LENGTH (value);
11262 : 32 : unsigned HOST_WIDE_INT end = 0;
11263 : 32 : unsigned plen = RAW_DATA_LENGTH (p->value);
11264 : 32 : gcc_checking_assert (start < plen && start);
11265 : 32 : if (plen - start > len)
11266 : 30 : end = plen - start - len;
11267 : 32 : tree v = p->value;
11268 : 32 : tree origtype = p->origtype;
11269 : 32 : if (start == 1)
11270 : 2 : p->value = build_int_cst (TREE_TYPE (v),
11271 : 2 : RAW_DATA_UCHAR_ELT (v, 0));
11272 : : else
11273 : : {
11274 : 30 : p->value = v;
11275 : 30 : if (end > 1)
11276 : 26 : v = copy_node (v);
11277 : 30 : RAW_DATA_LENGTH (p->value) = start;
11278 : : }
11279 : 32 : if (end)
11280 : : {
11281 : 30 : tree epurpose
11282 : 30 : = size_binop (PLUS_EXPR, purpose,
11283 : : bitsize_int (len));
11284 : 30 : if (end > 1)
11285 : : {
11286 : 28 : RAW_DATA_LENGTH (v) -= plen - end;
11287 : 28 : RAW_DATA_POINTER (v) += plen - end;
11288 : : }
11289 : : else
11290 : 2 : v = build_int_cst (TREE_TYPE (v),
11291 : 2 : RAW_DATA_UCHAR_ELT (v, plen
11292 : : - end));
11293 : 30 : add_pending_init (loc, epurpose, v, origtype,
11294 : : implicit, braced_init_obstack);
11295 : : }
11296 : 32 : q = &constructor_pending_elts;
11297 : 32 : continue;
11298 : 32 : }
11299 : 130 : }
11300 : : }
11301 : : else
11302 : : {
11303 : 169 : if (TREE_CODE (p->value) == RAW_DATA_CST
11304 : 179 : && (RAW_DATA_LENGTH (p->value)
11305 : 10 : > (TREE_CODE (value) == RAW_DATA_CST
11306 : 10 : ? RAW_DATA_LENGTH (value) : 1)))
11307 : : {
11308 : : /* Override which should split the old RAW_DATA_CST
11309 : : into 2 pieces. */
11310 : 6 : if (!implicit && warn_override_init)
11311 : 3 : warning_init (loc, OPT_Woverride_init,
11312 : : "initialized field overwritten");
11313 : 6 : unsigned HOST_WIDE_INT len = 1;
11314 : 6 : if (TREE_CODE (value) == RAW_DATA_CST)
11315 : 2 : len = RAW_DATA_LENGTH (value);
11316 : 6 : if ((unsigned) RAW_DATA_LENGTH (p->value) > len + 1)
11317 : : {
11318 : 6 : RAW_DATA_LENGTH (p->value) -= len;
11319 : 6 : RAW_DATA_POINTER (p->value) += len;
11320 : : }
11321 : : else
11322 : : {
11323 : 0 : unsigned int l = RAW_DATA_LENGTH (p->value) - 1;
11324 : 0 : p->value
11325 : 0 : = build_int_cst (TREE_TYPE (p->value),
11326 : 0 : RAW_DATA_UCHAR_ELT (p->value, l));
11327 : : }
11328 : 6 : p->purpose = size_binop (PLUS_EXPR, p->purpose,
11329 : : bitsize_int (len));
11330 : 6 : continue;
11331 : 6 : }
11332 : 163 : if (TREE_CODE (value) == RAW_DATA_CST)
11333 : : {
11334 : 8 : handle_raw_data:
11335 : : /* RAW_DATA_CST value might overlap various further
11336 : : prior initval entries. Find out how many. */
11337 : 13 : unsigned cnt = 0;
11338 : 13 : widest_int w
11339 : 26 : = wi::to_widest (purpose) + RAW_DATA_LENGTH (value);
11340 : 13 : struct init_node *r = p, *last = NULL;
11341 : 13 : bool override_init = warn_override_init;
11342 : 13 : while ((r = init_node_successor (r))
11343 : 53 : && wi::to_widest (r->purpose) < w)
11344 : : {
11345 : 40 : ++cnt;
11346 : 40 : if (TREE_SIDE_EFFECTS (r->value))
11347 : 2 : warning_init (loc, OPT_Woverride_init_side_effects,
11348 : : "initialized field with side-effects "
11349 : : "overwritten");
11350 : 38 : else if (override_init)
11351 : : {
11352 : 6 : warning_init (loc, OPT_Woverride_init,
11353 : : "initialized field overwritten");
11354 : 6 : override_init = false;
11355 : : }
11356 : : last = r;
11357 : : }
11358 : 13 : if (cnt)
11359 : : {
11360 : 26 : if (TREE_CODE (last->value) == RAW_DATA_CST
11361 : 13 : && (wi::to_widest (last->purpose)
11362 : 13 : + RAW_DATA_LENGTH (last->value) > w))
11363 : : {
11364 : : /* The last overlapping prior initval overlaps
11365 : : only partially. Shrink it and decrease cnt. */
11366 : 0 : unsigned int l = (wi::to_widest (last->purpose)
11367 : 0 : + RAW_DATA_LENGTH (last->value)
11368 : 0 : - w).to_uhwi ();
11369 : 0 : --cnt;
11370 : 0 : RAW_DATA_LENGTH (last->value) -= l;
11371 : 0 : RAW_DATA_POINTER (last->value) += l;
11372 : 0 : if (RAW_DATA_LENGTH (last->value) == 1)
11373 : 0 : last->value
11374 : 0 : = build_int_cst (TREE_TYPE (last->value),
11375 : 0 : RAW_DATA_UCHAR_ELT (last->value,
11376 : : 0));
11377 : 0 : last->purpose
11378 : 0 : = size_binop (PLUS_EXPR, last->purpose,
11379 : : bitsize_int (l));
11380 : : }
11381 : : /* Instead of deleting cnt nodes from the AVL tree
11382 : : and rebalancing, peel of last cnt bytes from the
11383 : : RAW_DATA_CST. Overriding thousands of previously
11384 : : initialized array elements with #embed needs to work,
11385 : : but doesn't need to be super efficient. */
11386 : 13 : gcc_checking_assert ((unsigned) RAW_DATA_LENGTH (value)
11387 : : > cnt);
11388 : 13 : RAW_DATA_LENGTH (value) -= cnt;
11389 : 13 : const unsigned char *s
11390 : 13 : = &RAW_DATA_UCHAR_ELT (value, RAW_DATA_LENGTH (value));
11391 : 13 : unsigned int o = RAW_DATA_LENGTH (value);
11392 : 53 : for (r = p; cnt--; ++o, ++s)
11393 : : {
11394 : 40 : r = init_node_successor (r);
11395 : 40 : r->purpose = size_binop (PLUS_EXPR, purpose,
11396 : : bitsize_int (o));
11397 : 40 : r->value = build_int_cst (TREE_TYPE (value), *s);
11398 : 40 : r->origtype = origtype;
11399 : : }
11400 : 13 : if (RAW_DATA_LENGTH (value) == 1)
11401 : 0 : value = build_int_cst (TREE_TYPE (value),
11402 : 0 : RAW_DATA_UCHAR_ELT (value, 0));
11403 : : }
11404 : : }
11405 : 168 : if (!implicit)
11406 : : {
11407 : 54 : if (TREE_SIDE_EFFECTS (p->value))
11408 : 6 : warning_init (loc, OPT_Woverride_init_side_effects,
11409 : : "initialized field with side-effects "
11410 : : "overwritten");
11411 : 48 : else if (warn_override_init)
11412 : 13 : warning_init (loc, OPT_Woverride_init,
11413 : : "initialized field overwritten");
11414 : : }
11415 : 168 : p->value = value;
11416 : 168 : p->origtype = origtype;
11417 : 168 : return;
11418 : : }
11419 : : }
11420 : 1198 : if (TREE_CODE (value) == RAW_DATA_CST && p)
11421 : : {
11422 : 61 : struct init_node *r;
11423 : 61 : if (q == &p->left)
11424 : : r = p;
11425 : : else
11426 : 36 : r = init_node_successor (p);
11427 : 131 : if (r && wi::to_widest (r->purpose) < (wi::to_widest (purpose)
11428 : 131 : + RAW_DATA_LENGTH (value)))
11429 : : {
11430 : : /* Overlap with at least one prior initval in the range but
11431 : : not at the start. */
11432 : 5 : p = r;
11433 : 5 : p->purpose = purpose;
11434 : 5 : goto handle_raw_data;
11435 : : }
11436 : : }
11437 : : }
11438 : : else
11439 : : {
11440 : 1908 : tree bitpos;
11441 : :
11442 : 1908 : bitpos = bit_position (purpose);
11443 : 5430 : while (*q != NULL)
11444 : : {
11445 : 1871 : p = *q;
11446 : 1871 : if (tree_int_cst_lt (bitpos, bit_position (p->purpose)))
11447 : 43 : q = &p->left;
11448 : 1828 : else if (p->purpose != purpose)
11449 : 1571 : q = &p->right;
11450 : : else
11451 : : {
11452 : 257 : if (!implicit)
11453 : : {
11454 : 33 : if (TREE_SIDE_EFFECTS (p->value))
11455 : 4 : warning_init (loc, OPT_Woverride_init_side_effects,
11456 : : "initialized field with side-effects "
11457 : : "overwritten");
11458 : 29 : else if (warn_override_init)
11459 : 6 : warning_init (loc, OPT_Woverride_init,
11460 : : "initialized field overwritten");
11461 : : }
11462 : 257 : p->value = value;
11463 : 257 : p->origtype = origtype;
11464 : 257 : return;
11465 : : }
11466 : : }
11467 : : }
11468 : :
11469 : 2844 : r = (struct init_node *) obstack_alloc (braced_init_obstack,
11470 : : sizeof (struct init_node));
11471 : 2844 : r->purpose = purpose;
11472 : 2844 : r->value = value;
11473 : 2844 : r->origtype = origtype;
11474 : :
11475 : 2844 : *q = r;
11476 : 2844 : r->parent = p;
11477 : 2844 : r->left = 0;
11478 : 2844 : r->right = 0;
11479 : 2844 : r->balance = 0;
11480 : :
11481 : 4878 : while (p)
11482 : : {
11483 : 2826 : struct init_node *s;
11484 : :
11485 : 2826 : if (r == p->left)
11486 : : {
11487 : 237 : if (p->balance == 0)
11488 : 174 : p->balance = -1;
11489 : 63 : else if (p->balance < 0)
11490 : : {
11491 : 45 : if (r->balance < 0)
11492 : : {
11493 : : /* L rotation. */
11494 : 40 : p->left = r->right;
11495 : 40 : if (p->left)
11496 : 2 : p->left->parent = p;
11497 : 40 : r->right = p;
11498 : :
11499 : 40 : p->balance = 0;
11500 : 40 : r->balance = 0;
11501 : :
11502 : 40 : s = p->parent;
11503 : 40 : p->parent = r;
11504 : 40 : r->parent = s;
11505 : 40 : if (s)
11506 : : {
11507 : 31 : if (s->left == p)
11508 : 10 : s->left = r;
11509 : : else
11510 : 21 : s->right = r;
11511 : : }
11512 : : else
11513 : 9 : constructor_pending_elts = r;
11514 : : }
11515 : : else
11516 : : {
11517 : : /* LR rotation. */
11518 : 5 : struct init_node *t = r->right;
11519 : :
11520 : 5 : r->right = t->left;
11521 : 5 : if (r->right)
11522 : 0 : r->right->parent = r;
11523 : 5 : t->left = r;
11524 : :
11525 : 5 : p->left = t->right;
11526 : 5 : if (p->left)
11527 : 0 : p->left->parent = p;
11528 : 5 : t->right = p;
11529 : :
11530 : 5 : p->balance = t->balance < 0;
11531 : 5 : r->balance = -(t->balance > 0);
11532 : 5 : t->balance = 0;
11533 : :
11534 : 5 : s = p->parent;
11535 : 5 : p->parent = t;
11536 : 5 : r->parent = t;
11537 : 5 : t->parent = s;
11538 : 5 : if (s)
11539 : : {
11540 : 0 : if (s->left == p)
11541 : 0 : s->left = t;
11542 : : else
11543 : 0 : s->right = t;
11544 : : }
11545 : : else
11546 : 5 : constructor_pending_elts = t;
11547 : : }
11548 : : break;
11549 : : }
11550 : : else
11551 : : {
11552 : : /* p->balance == +1; growth of left side balances the node. */
11553 : 18 : p->balance = 0;
11554 : 18 : break;
11555 : : }
11556 : : }
11557 : : else /* r == p->right */
11558 : : {
11559 : 2589 : if (p->balance == 0)
11560 : : /* Growth propagation from right side. */
11561 : 1860 : p->balance++;
11562 : 729 : else if (p->balance > 0)
11563 : : {
11564 : 700 : if (r->balance > 0)
11565 : : {
11566 : : /* R rotation. */
11567 : 698 : p->right = r->left;
11568 : 698 : if (p->right)
11569 : 173 : p->right->parent = p;
11570 : 698 : r->left = p;
11571 : :
11572 : 698 : p->balance = 0;
11573 : 698 : r->balance = 0;
11574 : :
11575 : 698 : s = p->parent;
11576 : 698 : p->parent = r;
11577 : 698 : r->parent = s;
11578 : 698 : if (s)
11579 : : {
11580 : 378 : if (s->left == p)
11581 : 2 : s->left = r;
11582 : : else
11583 : 376 : s->right = r;
11584 : : }
11585 : : else
11586 : 320 : constructor_pending_elts = r;
11587 : : }
11588 : : else /* r->balance == -1 */
11589 : : {
11590 : : /* RL rotation */
11591 : 2 : struct init_node *t = r->left;
11592 : :
11593 : 2 : r->left = t->right;
11594 : 2 : if (r->left)
11595 : 2 : r->left->parent = r;
11596 : 2 : t->right = r;
11597 : :
11598 : 2 : p->right = t->left;
11599 : 2 : if (p->right)
11600 : 2 : p->right->parent = p;
11601 : 2 : t->left = p;
11602 : :
11603 : 2 : r->balance = (t->balance < 0);
11604 : 2 : p->balance = -(t->balance > 0);
11605 : 2 : t->balance = 0;
11606 : :
11607 : 2 : s = p->parent;
11608 : 2 : p->parent = t;
11609 : 2 : r->parent = t;
11610 : 2 : t->parent = s;
11611 : 2 : if (s)
11612 : : {
11613 : 0 : if (s->left == p)
11614 : 0 : s->left = t;
11615 : : else
11616 : 0 : s->right = t;
11617 : : }
11618 : : else
11619 : 2 : constructor_pending_elts = t;
11620 : : }
11621 : : break;
11622 : : }
11623 : : else
11624 : : {
11625 : : /* p->balance == -1; growth of right side balances the node. */
11626 : 29 : p->balance = 0;
11627 : 29 : break;
11628 : : }
11629 : : }
11630 : :
11631 : 2034 : r = p;
11632 : 2034 : p = p->parent;
11633 : : }
11634 : : }
11635 : :
11636 : : /* Build AVL tree from a sorted chain. */
11637 : :
11638 : : static void
11639 : 418 : set_nonincremental_init (struct obstack * braced_init_obstack)
11640 : : {
11641 : 418 : unsigned HOST_WIDE_INT ix;
11642 : 418 : tree index, value;
11643 : :
11644 : 418 : if (TREE_CODE (constructor_type) != RECORD_TYPE
11645 : 418 : && TREE_CODE (constructor_type) != ARRAY_TYPE)
11646 : : return;
11647 : :
11648 : 1601 : FOR_EACH_CONSTRUCTOR_ELT (constructor_elements, ix, index, value)
11649 : 1183 : add_pending_init (input_location, index, value, NULL_TREE, true,
11650 : : braced_init_obstack);
11651 : 418 : constructor_elements = NULL;
11652 : 418 : if (TREE_CODE (constructor_type) == RECORD_TYPE)
11653 : : {
11654 : 200 : constructor_unfilled_fields = TYPE_FIELDS (constructor_type);
11655 : : /* Skip any nameless bit fields at the beginning. */
11656 : 200 : while (constructor_unfilled_fields != NULL_TREE
11657 : 200 : && DECL_UNNAMED_BIT_FIELD (constructor_unfilled_fields))
11658 : 0 : constructor_unfilled_fields = TREE_CHAIN (constructor_unfilled_fields);
11659 : :
11660 : : }
11661 : 218 : else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
11662 : : {
11663 : 218 : if (TYPE_DOMAIN (constructor_type))
11664 : 160 : constructor_unfilled_index
11665 : 160 : = convert (bitsizetype,
11666 : 160 : TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
11667 : : else
11668 : 58 : constructor_unfilled_index = bitsize_zero_node;
11669 : : }
11670 : 418 : constructor_incremental = 0;
11671 : : }
11672 : :
11673 : : /* Build AVL tree from a string constant. */
11674 : :
11675 : : static void
11676 : 7 : set_nonincremental_init_from_string (tree str,
11677 : : struct obstack * braced_init_obstack)
11678 : : {
11679 : 7 : tree value, purpose, type;
11680 : 7 : HOST_WIDE_INT val[2];
11681 : 7 : const char *p, *end;
11682 : 7 : int byte, wchar_bytes, charwidth, bitpos;
11683 : :
11684 : 7 : gcc_assert (TREE_CODE (constructor_type) == ARRAY_TYPE);
11685 : :
11686 : 7 : wchar_bytes = TYPE_PRECISION (TREE_TYPE (TREE_TYPE (str))) / BITS_PER_UNIT;
11687 : 7 : charwidth = TYPE_PRECISION (char_type_node);
11688 : 7 : gcc_assert ((size_t) wchar_bytes * charwidth
11689 : : <= ARRAY_SIZE (val) * HOST_BITS_PER_WIDE_INT);
11690 : 7 : type = TREE_TYPE (constructor_type);
11691 : 7 : p = TREE_STRING_POINTER (str);
11692 : 7 : end = p + TREE_STRING_LENGTH (str);
11693 : :
11694 : 7 : for (purpose = bitsize_zero_node;
11695 : : p < end
11696 : 52 : && !(constructor_max_index
11697 : 20 : && tree_int_cst_lt (constructor_max_index, purpose));
11698 : 25 : purpose = size_binop (PLUS_EXPR, purpose, bitsize_one_node))
11699 : : {
11700 : 25 : if (wchar_bytes == 1)
11701 : : {
11702 : 9 : val[0] = (unsigned char) *p++;
11703 : 9 : val[1] = 0;
11704 : : }
11705 : : else
11706 : : {
11707 : 16 : val[1] = 0;
11708 : 16 : val[0] = 0;
11709 : 64 : for (byte = 0; byte < wchar_bytes; byte++)
11710 : : {
11711 : 48 : if (BYTES_BIG_ENDIAN)
11712 : : bitpos = (wchar_bytes - byte - 1) * charwidth;
11713 : : else
11714 : 48 : bitpos = byte * charwidth;
11715 : 48 : val[bitpos / HOST_BITS_PER_WIDE_INT]
11716 : 48 : |= ((unsigned HOST_WIDE_INT) ((unsigned char) *p++))
11717 : 48 : << (bitpos % HOST_BITS_PER_WIDE_INT);
11718 : : }
11719 : : }
11720 : :
11721 : 25 : if (!TYPE_UNSIGNED (type))
11722 : : {
11723 : 13 : bitpos = ((wchar_bytes - 1) * charwidth) + HOST_BITS_PER_CHAR;
11724 : 13 : if (bitpos < HOST_BITS_PER_WIDE_INT)
11725 : : {
11726 : 13 : if (val[0] & (HOST_WIDE_INT_1 << (bitpos - 1)))
11727 : : {
11728 : 0 : val[0] |= HOST_WIDE_INT_M1U << bitpos;
11729 : 0 : val[1] = -1;
11730 : : }
11731 : : }
11732 : 0 : else if (bitpos == HOST_BITS_PER_WIDE_INT)
11733 : : {
11734 : 0 : if (val[0] < 0)
11735 : 0 : val[1] = -1;
11736 : : }
11737 : 0 : else if (val[1] & (HOST_WIDE_INT_1
11738 : 0 : << (bitpos - 1 - HOST_BITS_PER_WIDE_INT)))
11739 : 0 : val[1] |= HOST_WIDE_INT_M1U << (bitpos - HOST_BITS_PER_WIDE_INT);
11740 : : }
11741 : :
11742 : 25 : value = wide_int_to_tree (type,
11743 : 25 : wide_int::from_array (val, 2,
11744 : : HOST_BITS_PER_WIDE_INT * 2));
11745 : 25 : add_pending_init (input_location, purpose, value, NULL_TREE, true,
11746 : : braced_init_obstack);
11747 : : }
11748 : :
11749 : 7 : constructor_incremental = 0;
11750 : 7 : }
11751 : :
11752 : : /* Return value of FIELD in pending initializer or NULL_TREE if the field was
11753 : : not initialized yet. */
11754 : :
11755 : : static tree
11756 : 703583 : find_init_member (tree field, struct obstack * braced_init_obstack)
11757 : : {
11758 : 703583 : struct init_node *p;
11759 : :
11760 : 703583 : if (TREE_CODE (constructor_type) == ARRAY_TYPE)
11761 : : {
11762 : 702788 : if (constructor_incremental
11763 : 702788 : && tree_int_cst_lt (field, constructor_unfilled_index))
11764 : 16 : set_nonincremental_init (braced_init_obstack);
11765 : :
11766 : 702788 : p = constructor_pending_elts;
11767 : 702911 : while (p)
11768 : : {
11769 : 233 : if (tree_int_cst_lt (field, p->purpose))
11770 : 25 : p = p->left;
11771 : 208 : else if (tree_int_cst_lt (p->purpose, field))
11772 : 98 : p = p->right;
11773 : : else
11774 : 110 : return p->value;
11775 : : }
11776 : : }
11777 : 795 : else if (TREE_CODE (constructor_type) == RECORD_TYPE)
11778 : : {
11779 : 673 : tree bitpos = bit_position (field);
11780 : :
11781 : 673 : if (constructor_incremental
11782 : 673 : && (!constructor_unfilled_fields
11783 : 470 : || tree_int_cst_lt (bitpos,
11784 : 470 : bit_position (constructor_unfilled_fields))))
11785 : 51 : set_nonincremental_init (braced_init_obstack);
11786 : :
11787 : 673 : p = constructor_pending_elts;
11788 : 813 : while (p)
11789 : : {
11790 : 347 : if (field == p->purpose)
11791 : 207 : return p->value;
11792 : 140 : else if (tree_int_cst_lt (bitpos, bit_position (p->purpose)))
11793 : 7 : p = p->left;
11794 : : else
11795 : 133 : p = p->right;
11796 : : }
11797 : : }
11798 : 122 : else if (TREE_CODE (constructor_type) == UNION_TYPE)
11799 : : {
11800 : 122 : if (!vec_safe_is_empty (constructor_elements)
11801 : 50 : && (constructor_elements->last ().index == field))
11802 : 50 : return constructor_elements->last ().value;
11803 : : }
11804 : : return NULL_TREE;
11805 : : }
11806 : :
11807 : : /* "Output" the next constructor element.
11808 : : At top level, really output it to assembler code now.
11809 : : Otherwise, collect it in a list from which we will make a CONSTRUCTOR.
11810 : : If ORIGTYPE is not NULL_TREE, it is the original type of VALUE.
11811 : : TYPE is the data type that the containing data type wants here.
11812 : : FIELD is the field (a FIELD_DECL) or the index that this element fills.
11813 : : If VALUE is a string constant, STRICT_STRING is true if it is
11814 : : unparenthesized or we should not warn here for it being parenthesized.
11815 : : For other types of VALUE, STRICT_STRING is not used.
11816 : :
11817 : : PENDING if true means output pending elements that belong
11818 : : right after this element. (PENDING is normally true;
11819 : : it is false while outputting pending elements, to avoid recursion.)
11820 : :
11821 : : IMPLICIT is true if value comes from pop_init_level (1),
11822 : : the new initializer has been merged with the existing one
11823 : : and thus no warnings should be emitted about overriding an
11824 : : existing initializer. */
11825 : :
11826 : : static void
11827 : 9593252 : output_init_element (location_t loc, tree value, tree origtype,
11828 : : bool strict_string, tree type, tree field, bool pending,
11829 : : bool implicit, struct obstack * braced_init_obstack)
11830 : : {
11831 : 9593252 : tree semantic_type = NULL_TREE;
11832 : 9593252 : bool maybe_const = true;
11833 : 9593252 : bool npc, int_const_expr, arith_const_expr;
11834 : :
11835 : 9593252 : if (type == error_mark_node || value == error_mark_node)
11836 : : {
11837 : 464 : constructor_erroneous = 1;
11838 : 2589 : return;
11839 : : }
11840 : 9592788 : if (TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE
11841 : 199907 : && (TREE_CODE (value) == STRING_CST
11842 : 158511 : || TREE_CODE (value) == COMPOUND_LITERAL_EXPR)
11843 : 41404 : && !(TREE_CODE (value) == STRING_CST
11844 : 41396 : && TREE_CODE (type) == ARRAY_TYPE
11845 : 3897 : && INTEGRAL_TYPE_P (TREE_TYPE (type)))
11846 : 9630295 : && !comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (value)),
11847 : 37507 : TYPE_MAIN_VARIANT (type)))
11848 : 37507 : value = array_to_pointer_conversion (input_location, value);
11849 : :
11850 : 9592788 : if (TREE_CODE (value) == COMPOUND_LITERAL_EXPR
11851 : 178 : && require_constant_value && pending)
11852 : : {
11853 : : /* As an extension, allow initializing objects with static storage
11854 : : duration with compound literals (which are then treated just as
11855 : : the brace enclosed list they contain). */
11856 : 114 : if (flag_isoc99)
11857 : 24 : pedwarn_init (loc, OPT_Wpedantic, "initializer element is not "
11858 : : "constant");
11859 : 114 : tree decl = COMPOUND_LITERAL_EXPR_DECL (value);
11860 : 114 : value = DECL_INITIAL (decl);
11861 : : }
11862 : :
11863 : 9592788 : npc = null_pointer_constant_p (value);
11864 : 19185576 : int_const_expr = (TREE_CODE (value) == INTEGER_CST
11865 : 4201970 : && !TREE_OVERFLOW (value)
11866 : 13794757 : && INTEGRAL_TYPE_P (TREE_TYPE (value)));
11867 : : /* Not fully determined before folding. */
11868 : 9592788 : arith_const_expr = true;
11869 : 9592788 : if (TREE_CODE (value) == EXCESS_PRECISION_EXPR)
11870 : : {
11871 : 16 : semantic_type = TREE_TYPE (value);
11872 : 16 : value = TREE_OPERAND (value, 0);
11873 : : }
11874 : 9592788 : value = c_fully_fold (value, require_constant_value, &maybe_const);
11875 : : /* TODO: this may not detect all cases of expressions folding to
11876 : : constants that are not arithmetic constant expressions. */
11877 : 9592788 : if (!maybe_const)
11878 : : arith_const_expr = false;
11879 : 19183091 : else if (!INTEGRAL_TYPE_P (TREE_TYPE (value))
11880 : 3180239 : && TREE_CODE (TREE_TYPE (value)) != REAL_TYPE
11881 : 11433044 : && TREE_CODE (TREE_TYPE (value)) != COMPLEX_TYPE)
11882 : : arith_const_expr = false;
11883 : 7765315 : else if (TREE_CODE (value) != INTEGER_CST
11884 : : && TREE_CODE (value) != REAL_CST
11885 : : && TREE_CODE (value) != COMPLEX_CST
11886 : : && TREE_CODE (value) != RAW_DATA_CST)
11887 : : arith_const_expr = false;
11888 : 4590007 : else if (TREE_OVERFLOW (value))
11889 : 5002782 : arith_const_expr = false;
11890 : :
11891 : 9592788 : if (value == error_mark_node)
11892 : 0 : constructor_erroneous = 1;
11893 : 9592788 : else if (!TREE_CONSTANT (value))
11894 : 3195306 : constructor_constant = 0;
11895 : 6397482 : else if (!initializer_constant_valid_p (value,
11896 : 6397482 : TREE_TYPE (value),
11897 : 6397482 : AGGREGATE_TYPE_P (constructor_type)
11898 : 6397482 : && TYPE_REVERSE_STORAGE_ORDER
11899 : : (constructor_type))
11900 : 6397482 : || (RECORD_OR_UNION_TYPE_P (constructor_type)
11901 : 1037463 : && DECL_C_BIT_FIELD (field)
11902 : 8103 : && TREE_CODE (value) != INTEGER_CST))
11903 : 77 : constructor_simple = 0;
11904 : 9592788 : if (!maybe_const)
11905 : 1137 : constructor_nonconst = 1;
11906 : :
11907 : : /* Digest the initializer and issue any errors about incompatible
11908 : : types before issuing errors about non-constant initializers. */
11909 : 9592788 : tree new_value = value;
11910 : 9592788 : if (semantic_type)
11911 : 16 : new_value = build1 (EXCESS_PRECISION_EXPR, semantic_type, value);
11912 : : /* In the case of braces around a scalar initializer, the result of
11913 : : this initializer processing goes through digest_init again at the
11914 : : outer level. In the case of a constexpr initializer for a
11915 : : pointer, avoid converting a null pointer constant to something
11916 : : that is not a null pointer constant to avoid a spurious error
11917 : : from that second processing. */
11918 : 9592788 : if (!require_constexpr_value
11919 : 398 : || !npc
11920 : 69 : || TREE_CODE (constructor_type) != POINTER_TYPE)
11921 : 9592777 : new_value = digest_init (loc,
11922 : 9592777 : RECORD_OR_UNION_TYPE_P (constructor_type)
11923 : 8523541 : ? field : constructor_fields
11924 : 8523541 : ? constructor_fields : constructor_decl,
11925 : : type, new_value, origtype, npc,
11926 : : int_const_expr, arith_const_expr, strict_string,
11927 : : require_constant_value, require_constexpr_value);
11928 : 9592788 : if (new_value == error_mark_node)
11929 : : {
11930 : 76 : constructor_erroneous = 1;
11931 : 76 : return;
11932 : : }
11933 : 9592712 : if (require_constant_value || require_constant_elements)
11934 : 2710435 : constant_expression_warning (new_value);
11935 : :
11936 : : /* Proceed to check the constness of the original initializer. */
11937 : 9592712 : if (!initializer_constant_valid_p (value, TREE_TYPE (value)))
11938 : : {
11939 : 3195332 : if (require_constant_value)
11940 : : {
11941 : 0 : error_init (loc, "initializer element is not constant");
11942 : 0 : value = error_mark_node;
11943 : : }
11944 : 3195332 : else if (require_constant_elements)
11945 : 15 : pedwarn (loc, OPT_Wpedantic,
11946 : : "initializer element is not computable at load time");
11947 : : }
11948 : 6397380 : else if (!maybe_const
11949 : 54 : && (require_constant_value || require_constant_elements))
11950 : 28 : pedwarn_init (loc, OPT_Wpedantic,
11951 : : "initializer element is not a constant expression");
11952 : : /* digest_init has already carried out the additional checks
11953 : : required for 'constexpr' initializers (using the information
11954 : : passed to it about whether the original initializer was certain
11955 : : kinds of constant expression), so that check does not need to be
11956 : : repeated here. */
11957 : :
11958 : : /* Issue -Wc++-compat warnings about initializing a bitfield with
11959 : : enum type. */
11960 : 9592712 : if (warn_cxx_compat
11961 : 6895 : && field != NULL_TREE
11962 : 6895 : && TREE_CODE (field) == FIELD_DECL
11963 : 459 : && DECL_BIT_FIELD_TYPE (field) != NULL_TREE
11964 : 21 : && (TYPE_MAIN_VARIANT (DECL_BIT_FIELD_TYPE (field))
11965 : 21 : != TYPE_MAIN_VARIANT (type))
11966 : 9592733 : && TREE_CODE (DECL_BIT_FIELD_TYPE (field)) == ENUMERAL_TYPE)
11967 : : {
11968 : 21 : tree checktype = origtype != NULL_TREE ? origtype : TREE_TYPE (value);
11969 : 21 : if (checktype != error_mark_node
11970 : 21 : && (TYPE_MAIN_VARIANT (checktype)
11971 : 21 : != TYPE_MAIN_VARIANT (DECL_BIT_FIELD_TYPE (field))))
11972 : 9 : warning_init (loc, OPT_Wc___compat,
11973 : : "enum conversion in initialization is invalid in C++");
11974 : : }
11975 : :
11976 : : /* If this field is empty and does not have side effects (and is not at
11977 : : the end of structure), don't do anything other than checking the
11978 : : initializer. */
11979 : 9592712 : if (field
11980 : 9592712 : && (TREE_TYPE (field) == error_mark_node
11981 : 9592292 : || (COMPLETE_TYPE_P (TREE_TYPE (field))
11982 : 9591984 : && integer_zerop (TYPE_SIZE (TREE_TYPE (field)))
11983 : 62 : && !TREE_SIDE_EFFECTS (new_value)
11984 : 33 : && (TREE_CODE (constructor_type) == ARRAY_TYPE
11985 : 33 : || DECL_CHAIN (field)))))
11986 : 18 : return;
11987 : :
11988 : : /* Finally, set VALUE to the initializer value digested above. */
11989 : 9592694 : value = new_value;
11990 : :
11991 : : /* If this element doesn't come next in sequence,
11992 : : put it on constructor_pending_elts. */
11993 : 9592694 : if (TREE_CODE (constructor_type) == ARRAY_TYPE
11994 : 9592694 : && (!constructor_incremental
11995 : 1713985 : || !tree_int_cst_equal (field, constructor_unfilled_index)
11996 : 1713619 : || (TREE_CODE (value) == RAW_DATA_CST
11997 : 234 : && constructor_pending_elts
11998 : 66 : && pending)))
11999 : : {
12000 : 627 : if (constructor_incremental
12001 : 627 : && (tree_int_cst_lt (field, constructor_unfilled_index)
12002 : 337 : || (TREE_CODE (value) == RAW_DATA_CST
12003 : 14 : && constructor_pending_elts
12004 : 14 : && pending)))
12005 : 48 : set_nonincremental_init (braced_init_obstack);
12006 : :
12007 : 627 : add_pending_init (loc, field, value, origtype, implicit,
12008 : : braced_init_obstack);
12009 : 627 : return;
12010 : : }
12011 : 9592067 : else if (TREE_CODE (constructor_type) == RECORD_TYPE
12012 : 1038236 : && (!constructor_incremental
12013 : 1037896 : || field != constructor_unfilled_fields))
12014 : : {
12015 : : /* We do this for records but not for unions. In a union,
12016 : : no matter which field is specified, it can be initialized
12017 : : right away since it starts at the beginning of the union. */
12018 : 1404 : if (constructor_incremental)
12019 : : {
12020 : 1064 : if (!constructor_unfilled_fields)
12021 : 5 : set_nonincremental_init (braced_init_obstack);
12022 : : else
12023 : : {
12024 : 1059 : tree bitpos, unfillpos;
12025 : :
12026 : 1059 : bitpos = bit_position (field);
12027 : 1059 : unfillpos = bit_position (constructor_unfilled_fields);
12028 : :
12029 : 1059 : if (tree_int_cst_lt (bitpos, unfillpos))
12030 : 4 : set_nonincremental_init (braced_init_obstack);
12031 : : }
12032 : : }
12033 : :
12034 : 1404 : add_pending_init (loc, field, value, origtype, implicit,
12035 : : braced_init_obstack);
12036 : 1404 : return;
12037 : : }
12038 : 9590663 : else if (TREE_CODE (constructor_type) == UNION_TYPE
12039 : 9590663 : && !vec_safe_is_empty (constructor_elements))
12040 : : {
12041 : 62 : if (!implicit)
12042 : : {
12043 : 12 : if (TREE_SIDE_EFFECTS (constructor_elements->last ().value))
12044 : 3 : warning_init (loc, OPT_Woverride_init_side_effects,
12045 : : "initialized field with side-effects overwritten");
12046 : 9 : else if (warn_override_init)
12047 : 6 : warning_init (loc, OPT_Woverride_init,
12048 : : "initialized field overwritten");
12049 : : }
12050 : :
12051 : : /* We can have just one union field set. */
12052 : 62 : constructor_elements = NULL;
12053 : : }
12054 : :
12055 : : /* Otherwise, output this element either to
12056 : : constructor_elements or to the assembler file. */
12057 : :
12058 : 9590663 : constructor_elt celt = {field, value};
12059 : 9590663 : vec_safe_push (constructor_elements, celt);
12060 : :
12061 : : /* Advance the variable that indicates sequential elements output. */
12062 : 9590663 : if (TREE_CODE (constructor_type) == ARRAY_TYPE)
12063 : : {
12064 : 1713614 : tree inc = bitsize_one_node;
12065 : 1713614 : if (value && TREE_CODE (value) == RAW_DATA_CST)
12066 : 229 : inc = bitsize_int (RAW_DATA_LENGTH (value));
12067 : 1713614 : constructor_unfilled_index
12068 : 1713614 : = size_binop_loc (input_location, PLUS_EXPR,
12069 : : constructor_unfilled_index, inc);
12070 : : }
12071 : 7877049 : else if (TREE_CODE (constructor_type) == RECORD_TYPE)
12072 : : {
12073 : 1036832 : constructor_unfilled_fields
12074 : 1036832 : = DECL_CHAIN (constructor_unfilled_fields);
12075 : :
12076 : : /* Skip any nameless bit fields. */
12077 : 1036832 : while (constructor_unfilled_fields != NULL_TREE
12078 : 1036933 : && DECL_UNNAMED_BIT_FIELD (constructor_unfilled_fields))
12079 : 101 : constructor_unfilled_fields
12080 : 101 : = DECL_CHAIN (constructor_unfilled_fields);
12081 : : }
12082 : 6840217 : else if (TREE_CODE (constructor_type) == UNION_TYPE)
12083 : 30968 : constructor_unfilled_fields = NULL_TREE;
12084 : :
12085 : : /* Now output any pending elements which have become next. */
12086 : 9590663 : if (pending)
12087 : 9587798 : output_pending_init_elements (0, braced_init_obstack);
12088 : : }
12089 : :
12090 : : /* For two FIELD_DECLs in the same chain, return -1 if field1
12091 : : comes before field2, 1 if field1 comes after field2 and
12092 : : 0 if field1 == field2. */
12093 : :
12094 : : static int
12095 : 4029 : init_field_decl_cmp (tree field1, tree field2)
12096 : : {
12097 : 4029 : if (field1 == field2)
12098 : : return 0;
12099 : :
12100 : 2154 : tree bitpos1 = bit_position (field1);
12101 : 2154 : tree bitpos2 = bit_position (field2);
12102 : 2154 : if (tree_int_cst_equal (bitpos1, bitpos2))
12103 : : {
12104 : : /* If one of the fields has non-zero bitsize, then that
12105 : : field must be the last one in a sequence of zero
12106 : : sized fields, fields after it will have bigger
12107 : : bit_position. */
12108 : 22 : if (TREE_TYPE (field1) != error_mark_node
12109 : 22 : && COMPLETE_TYPE_P (TREE_TYPE (field1))
12110 : 44 : && integer_nonzerop (TREE_TYPE (field1)))
12111 : : return 1;
12112 : 22 : if (TREE_TYPE (field2) != error_mark_node
12113 : 22 : && COMPLETE_TYPE_P (TREE_TYPE (field2))
12114 : 37 : && integer_nonzerop (TREE_TYPE (field2)))
12115 : : return -1;
12116 : : /* Otherwise, fallback to DECL_CHAIN walk to find out
12117 : : which field comes earlier. Walk chains of both
12118 : : fields, so that if field1 and field2 are close to each
12119 : : other in either order, it is found soon even for large
12120 : : sequences of zero sized fields. */
12121 : : tree f1 = field1, f2 = field2;
12122 : 22 : while (1)
12123 : : {
12124 : 22 : f1 = DECL_CHAIN (f1);
12125 : 22 : f2 = DECL_CHAIN (f2);
12126 : 22 : if (f1 == NULL_TREE)
12127 : : {
12128 : 7 : gcc_assert (f2);
12129 : : return 1;
12130 : : }
12131 : 15 : if (f2 == NULL_TREE)
12132 : : return -1;
12133 : 1 : if (f1 == field2)
12134 : : return -1;
12135 : 0 : if (f2 == field1)
12136 : : return 1;
12137 : 0 : if (!tree_int_cst_equal (bit_position (f1), bitpos1))
12138 : : return 1;
12139 : 0 : if (!tree_int_cst_equal (bit_position (f2), bitpos1))
12140 : : return -1;
12141 : : }
12142 : : }
12143 : 2132 : else if (tree_int_cst_lt (bitpos1, bitpos2))
12144 : : return -1;
12145 : : else
12146 : : return 1;
12147 : : }
12148 : :
12149 : : /* Output any pending elements which have become next.
12150 : : As we output elements, constructor_unfilled_{fields,index}
12151 : : advances, which may cause other elements to become next;
12152 : : if so, they too are output.
12153 : :
12154 : : If ALL is 0, we return when there are
12155 : : no more pending elements to output now.
12156 : :
12157 : : If ALL is 1, we output space as necessary so that
12158 : : we can output all the pending elements. */
12159 : : static void
12160 : 11652174 : output_pending_init_elements (int all, struct obstack * braced_init_obstack)
12161 : : {
12162 : 11652174 : struct init_node *elt = constructor_pending_elts;
12163 : 11653174 : tree next;
12164 : :
12165 : 11653174 : retry:
12166 : :
12167 : : /* Look through the whole pending tree.
12168 : : If we find an element that should be output now,
12169 : : output it. Otherwise, set NEXT to the element
12170 : : that comes first among those still pending. */
12171 : :
12172 : 11653174 : next = NULL_TREE;
12173 : 11658824 : while (elt)
12174 : : {
12175 : 7598 : if (TREE_CODE (constructor_type) == ARRAY_TYPE)
12176 : : {
12177 : 3004 : if (tree_int_cst_equal (elt->purpose,
12178 : : constructor_unfilled_index))
12179 : 1197 : output_init_element (input_location, elt->value, elt->origtype,
12180 : 1197 : true, TREE_TYPE (constructor_type),
12181 : : constructor_unfilled_index, false, false,
12182 : : braced_init_obstack);
12183 : 1807 : else if (tree_int_cst_lt (constructor_unfilled_index,
12184 : 1807 : elt->purpose))
12185 : : {
12186 : : /* Advance to the next smaller node. */
12187 : 589 : if (elt->left)
12188 : : elt = elt->left;
12189 : : else
12190 : : {
12191 : : /* We have reached the smallest node bigger than the
12192 : : current unfilled index. Fill the space first. */
12193 : 209 : next = elt->purpose;
12194 : 209 : break;
12195 : : }
12196 : : }
12197 : : else
12198 : : {
12199 : : /* Advance to the next bigger node. */
12200 : 1218 : if (elt->right)
12201 : : elt = elt->right;
12202 : : else
12203 : : {
12204 : : /* We have reached the biggest node in a subtree. Find
12205 : : the parent of it, which is the next bigger node. */
12206 : 1218 : while (elt->parent && elt->parent->right == elt)
12207 : : elt = elt->parent;
12208 : 774 : elt = elt->parent;
12209 : 1149 : if (elt && tree_int_cst_lt (constructor_unfilled_index,
12210 : 375 : elt->purpose))
12211 : : {
12212 : 22 : next = elt->purpose;
12213 : 22 : break;
12214 : : }
12215 : : }
12216 : : }
12217 : : }
12218 : 4594 : else if (RECORD_OR_UNION_TYPE_P (constructor_type))
12219 : : {
12220 : : /* If the current record is complete we are done. */
12221 : 4594 : if (constructor_unfilled_fields == NULL_TREE)
12222 : : break;
12223 : :
12224 : 3755 : int cmp = init_field_decl_cmp (constructor_unfilled_fields,
12225 : : elt->purpose);
12226 : 3755 : if (cmp == 0)
12227 : 1668 : output_init_element (input_location, elt->value, elt->origtype,
12228 : 1668 : true, TREE_TYPE (elt->purpose),
12229 : : elt->purpose, false, false,
12230 : : braced_init_obstack);
12231 : 2087 : else if (cmp < 0)
12232 : : {
12233 : : /* Advance to the next smaller node. */
12234 : 1092 : if (elt->left)
12235 : : elt = elt->left;
12236 : : else
12237 : : {
12238 : : /* We have reached the smallest node bigger than the
12239 : : current unfilled field. Fill the space first. */
12240 : 811 : next = elt->purpose;
12241 : 811 : break;
12242 : : }
12243 : : }
12244 : : else
12245 : : {
12246 : : /* Advance to the next bigger node. */
12247 : 995 : if (elt->right)
12248 : : elt = elt->right;
12249 : : else
12250 : : {
12251 : : /* We have reached the biggest node in a subtree. Find
12252 : : the parent of it, which is the next bigger node. */
12253 : 735 : while (elt->parent && elt->parent->right == elt)
12254 : : elt = elt->parent;
12255 : 519 : elt = elt->parent;
12256 : 519 : if (elt
12257 : 519 : && init_field_decl_cmp (constructor_unfilled_fields,
12258 : : elt->purpose) < 0)
12259 : : {
12260 : 67 : next = elt->purpose;
12261 : 67 : break;
12262 : : }
12263 : : }
12264 : : }
12265 : : }
12266 : : }
12267 : :
12268 : : /* Ordinarily return, but not if we want to output all
12269 : : and there are elements left. */
12270 : 11653174 : if (!(all && next != NULL_TREE))
12271 : 11652174 : return;
12272 : :
12273 : : /* If it's not incremental, just skip over the gap, so that after
12274 : : jumping to retry we will output the next successive element. */
12275 : 1000 : if (RECORD_OR_UNION_TYPE_P (constructor_type))
12276 : 808 : constructor_unfilled_fields = next;
12277 : 192 : else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
12278 : 192 : constructor_unfilled_index = next;
12279 : :
12280 : : /* ELT now points to the node in the pending tree with the next
12281 : : initializer to output. */
12282 : 1000 : goto retry;
12283 : : }
12284 : :
12285 : : /* Expression VALUE coincides with the start of type TYPE in a braced
12286 : : initializer. Return true if we should treat VALUE as initializing
12287 : : the first element of TYPE, false if we should treat it as initializing
12288 : : TYPE as a whole.
12289 : :
12290 : : If the initializer is clearly invalid, the question becomes:
12291 : : which choice gives the best error message? */
12292 : :
12293 : : static bool
12294 : 3480022 : initialize_elementwise_p (tree type, tree value)
12295 : : {
12296 : 3480022 : if (type == error_mark_node || value == error_mark_node)
12297 : : return false;
12298 : :
12299 : 3479579 : gcc_checking_assert (TYPE_MAIN_VARIANT (type) == type);
12300 : :
12301 : 3479579 : tree value_type = TREE_TYPE (value);
12302 : 3479579 : if (value_type == error_mark_node)
12303 : : return false;
12304 : :
12305 : : /* GNU vectors can be initialized elementwise. However, treat any
12306 : : kind of vector value as initializing the vector type as a whole,
12307 : : regardless of whether the value is a GNU vector. Such initializers
12308 : : are valid if and only if they would have been valid in a non-braced
12309 : : initializer like:
12310 : :
12311 : : TYPE foo = VALUE;
12312 : :
12313 : : so recursing into the vector type would be at best confusing or at
12314 : : worst wrong. For example, when -flax-vector-conversions is in effect,
12315 : : it's possible to initialize a V8HI from a V4SI, even though the vectors
12316 : : have different element types and different numbers of elements. */
12317 : 3479579 : if (gnu_vector_type_p (type))
12318 : 19475 : return !VECTOR_TYPE_P (value_type);
12319 : :
12320 : 3460104 : if (AGGREGATE_TYPE_P (type))
12321 : 1741053 : return !comptypes (type, TYPE_MAIN_VARIANT (value_type));
12322 : :
12323 : : return false;
12324 : : }
12325 : :
12326 : : /* Helper function for process_init_element. Split first element of
12327 : : RAW_DATA_CST and save the rest to *RAW_DATA. */
12328 : :
12329 : : static inline tree
12330 : 9590268 : maybe_split_raw_data (tree value, tree *raw_data)
12331 : : {
12332 : 9590268 : if (value == NULL_TREE || TREE_CODE (value) != RAW_DATA_CST)
12333 : : return value;
12334 : 211 : *raw_data = value;
12335 : 211 : value = build_int_cst (integer_type_node,
12336 : 211 : RAW_DATA_UCHAR_ELT (*raw_data, 0));
12337 : 211 : ++RAW_DATA_POINTER (*raw_data);
12338 : 211 : --RAW_DATA_LENGTH (*raw_data);
12339 : 211 : return value;
12340 : : }
12341 : :
12342 : : /* Return non-zero if c_parser_initval should attempt to optimize
12343 : : large initializers into RAW_DATA_CST. In that case return how
12344 : : many elements to optimize at most. */
12345 : :
12346 : : unsigned
12347 : 2977609 : c_maybe_optimize_large_byte_initializer (void)
12348 : : {
12349 : 2977609 : if (!constructor_type
12350 : 2977539 : || TREE_CODE (constructor_type) != ARRAY_TYPE
12351 : 206251 : || constructor_stack->implicit)
12352 : : return 0;
12353 : 203510 : tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
12354 : 203510 : if (TREE_CODE (elttype) != INTEGER_TYPE
12355 : 203510 : && TREE_CODE (elttype) != BITINT_TYPE)
12356 : : return 0;
12357 : 181115 : if (TYPE_PRECISION (elttype) != CHAR_BIT
12358 : 27813 : || constructor_stack->replacement_value.value
12359 : 27813 : || (COMPLETE_TYPE_P (constructor_type)
12360 : 26176 : && !poly_int_tree_p (TYPE_SIZE (constructor_type)))
12361 : 208928 : || constructor_range_stack)
12362 : : return 0;
12363 : 27813 : if (constructor_max_index == NULL_TREE)
12364 : : return INT_MAX;
12365 : 26176 : if (tree_int_cst_le (constructor_max_index, constructor_index)
12366 : 26176 : || integer_all_onesp (constructor_max_index))
12367 : 4755 : return 0;
12368 : 21421 : widest_int w = wi::to_widest (constructor_max_index);
12369 : 21421 : w -= wi::to_widest (constructor_index);
12370 : 21421 : w += 1;
12371 : 21421 : if (w < 64)
12372 : : return 0;
12373 : 6889 : if (w > INT_MAX)
12374 : : return INT_MAX;
12375 : 6889 : return w.to_uhwi ();
12376 : 21421 : }
12377 : :
12378 : : /* Add one non-braced element to the current constructor level.
12379 : : This adjusts the current position within the constructor's type.
12380 : : This may also start or terminate implicit levels
12381 : : to handle a partly-braced initializer.
12382 : :
12383 : : Once this has found the correct level for the new element,
12384 : : it calls output_init_element.
12385 : :
12386 : : IMPLICIT is true if value comes from pop_init_level (1),
12387 : : the new initializer has been merged with the existing one
12388 : : and thus no warnings should be emitted about overriding an
12389 : : existing initializer. */
12390 : :
12391 : : void
12392 : 9581323 : process_init_element (location_t loc, struct c_expr value, bool implicit,
12393 : : struct obstack * braced_init_obstack)
12394 : : {
12395 : 9581323 : tree orig_value = value.value;
12396 : 19162646 : int string_flag
12397 : 9581323 : = (orig_value != NULL_TREE && TREE_CODE (orig_value) == STRING_CST);
12398 : 9581323 : bool strict_string = value.original_code == STRING_CST;
12399 : 9581323 : bool was_designated = designator_depth != 0;
12400 : 9581323 : tree raw_data = NULL_TREE;
12401 : :
12402 : 9581535 : retry:
12403 : 9581535 : designator_depth = 0;
12404 : 9581535 : designator_erroneous = 0;
12405 : :
12406 : 9581535 : if (!implicit && value.value && !integer_zerop (value.value))
12407 : 7563741 : constructor_zeroinit = 0;
12408 : :
12409 : : /* Handle superfluous braces around string cst as in
12410 : : char x[] = {"foo"}; */
12411 : 9581535 : if (constructor_type
12412 : 9581407 : && !was_designated
12413 : 9547631 : && TREE_CODE (constructor_type) == ARRAY_TYPE
12414 : 1702209 : && INTEGRAL_TYPE_P (TREE_TYPE (constructor_type))
12415 : 10315024 : && integer_zerop (constructor_unfilled_index))
12416 : : {
12417 : 163067 : if (constructor_stack->replacement_value.value)
12418 : : {
12419 : 8 : error_init (loc, "excess elements in %qT initializer", constructor_type);
12420 : 409 : return;
12421 : : }
12422 : 163059 : else if (string_flag)
12423 : : {
12424 : 138 : constructor_stack->replacement_value = value;
12425 : 138 : return;
12426 : : }
12427 : : }
12428 : :
12429 : 9581389 : if (constructor_stack->replacement_value.value != NULL_TREE)
12430 : : {
12431 : 0 : error_init (loc, "excess elements in struct initializer");
12432 : 0 : return;
12433 : : }
12434 : :
12435 : : /* Ignore elements of a brace group if it is entirely superfluous
12436 : : and has already been diagnosed, or if the type is erroneous. */
12437 : 9581389 : if (constructor_type == NULL_TREE || constructor_type == error_mark_node)
12438 : : return;
12439 : :
12440 : : /* Ignore elements of an initializer for a variable-size type.
12441 : : Those are diagnosed in the parser (empty initializer braces are OK). */
12442 : 9581192 : if (COMPLETE_TYPE_P (constructor_type)
12443 : 9581192 : && !poly_int_tree_p (TYPE_SIZE (constructor_type)))
12444 : : return;
12445 : :
12446 : 8877551 : if (!implicit && warn_designated_init && !was_designated
12447 : 8844392 : && TREE_CODE (constructor_type) == RECORD_TYPE
12448 : 10615401 : && lookup_attribute ("designated_init",
12449 : 1034267 : TYPE_ATTRIBUTES (constructor_type)))
12450 : 50 : warning_init (loc,
12451 : : OPT_Wdesignated_init,
12452 : : "positional initialization of field "
12453 : : "in %<struct%> declared with %<designated_init%> attribute");
12454 : :
12455 : : /* If we've exhausted any levels that didn't have braces,
12456 : : pop them now. */
12457 : 10283105 : while (constructor_stack->implicit)
12458 : : {
12459 : 706793 : if (RECORD_OR_UNION_TYPE_P (constructor_type)
12460 : 702784 : && constructor_fields == NULL_TREE)
12461 : 701730 : process_init_element (loc,
12462 : : pop_init_level (loc, 1, braced_init_obstack,
12463 : : last_init_list_comma),
12464 : : true, braced_init_obstack);
12465 : 5063 : else if ((TREE_CODE (constructor_type) == ARRAY_TYPE
12466 : 1698 : || gnu_vector_type_p (constructor_type))
12467 : 4009 : && constructor_max_index
12468 : 9045 : && tree_int_cst_lt (constructor_max_index,
12469 : : constructor_index))
12470 : 241 : process_init_element (loc,
12471 : : pop_init_level (loc, 1, braced_init_obstack,
12472 : : last_init_list_comma),
12473 : : true, braced_init_obstack);
12474 : : else
12475 : : break;
12476 : : }
12477 : :
12478 : : /* In the case of [LO ... HI] = VALUE, only evaluate VALUE once. */
12479 : 9581134 : if (constructor_range_stack)
12480 : : {
12481 : : /* If value is a compound literal and we'll be just using its
12482 : : content, don't put it into a SAVE_EXPR. */
12483 : 365 : if (TREE_CODE (value.value) != COMPOUND_LITERAL_EXPR
12484 : 3 : || !require_constant_value)
12485 : : {
12486 : 362 : tree semantic_type = NULL_TREE;
12487 : 362 : if (TREE_CODE (value.value) == EXCESS_PRECISION_EXPR)
12488 : : {
12489 : 0 : semantic_type = TREE_TYPE (value.value);
12490 : 0 : value.value = TREE_OPERAND (value.value, 0);
12491 : : }
12492 : 362 : value.value = save_expr (value.value);
12493 : 362 : if (semantic_type)
12494 : 0 : value.value = build1 (EXCESS_PRECISION_EXPR, semantic_type,
12495 : : value.value);
12496 : : }
12497 : : }
12498 : :
12499 : 10294577 : while (1)
12500 : : {
12501 : 10294577 : if (TREE_CODE (constructor_type) == RECORD_TYPE)
12502 : : {
12503 : 1038306 : tree fieldtype;
12504 : 1038306 : enum tree_code fieldcode;
12505 : :
12506 : 1038306 : if (constructor_fields == NULL_TREE)
12507 : : {
12508 : 1280 : pedwarn_init (loc, 0, "excess elements in struct initializer");
12509 : 1280 : break;
12510 : : }
12511 : :
12512 : 1037026 : fieldtype = TREE_TYPE (constructor_fields);
12513 : 1037026 : if (fieldtype != error_mark_node)
12514 : 1037025 : fieldtype = TYPE_MAIN_VARIANT (fieldtype);
12515 : 1037026 : fieldcode = TREE_CODE (fieldtype);
12516 : :
12517 : : /* Error for non-static initialization of a flexible array member. */
12518 : 1037026 : if (fieldcode == ARRAY_TYPE
12519 : 155256 : && !require_constant_value
12520 : 1112 : && TYPE_SIZE (fieldtype) == NULL_TREE
12521 : 1037036 : && DECL_CHAIN (constructor_fields) == NULL_TREE)
12522 : : {
12523 : 10 : error_init (loc, "non-static initialization of a flexible "
12524 : : "array member");
12525 : 10 : break;
12526 : : }
12527 : :
12528 : : /* Error for initialization of a flexible array member with
12529 : : a string constant if the structure is in an array. E.g.:
12530 : : struct S { int x; char y[]; };
12531 : : struct S s[] = { { 1, "foo" } };
12532 : : is invalid. */
12533 : 1037016 : if (string_flag
12534 : 1037016 : && fieldcode == ARRAY_TYPE
12535 : 3352 : && constructor_depth > 1
12536 : 489 : && TYPE_SIZE (fieldtype) == NULL_TREE
12537 : 1037063 : && DECL_CHAIN (constructor_fields) == NULL_TREE)
12538 : : {
12539 : 47 : bool in_array_p = false;
12540 : 47 : for (struct constructor_stack *p = constructor_stack;
12541 : 73 : p && p->type; p = p->next)
12542 : 59 : if (TREE_CODE (p->type) == ARRAY_TYPE)
12543 : : {
12544 : : in_array_p = true;
12545 : : break;
12546 : : }
12547 : 47 : if (in_array_p)
12548 : : {
12549 : 33 : error_init (loc, "initialization of flexible array "
12550 : : "member in a nested context");
12551 : 33 : break;
12552 : : }
12553 : : }
12554 : :
12555 : : /* Accept a string constant to initialize a subarray. */
12556 : 1036983 : if (value.value != NULL_TREE
12557 : 1036910 : && fieldcode == ARRAY_TYPE
12558 : 155140 : && INTEGRAL_TYPE_P (TREE_TYPE (fieldtype))
12559 : 1191646 : && string_flag)
12560 : : value.value = orig_value;
12561 : : /* Otherwise, if we have come to a subaggregate,
12562 : : and we don't have an element of its type, push into it. */
12563 : 1033966 : else if (value.value != NULL_TREE
12564 : 1033664 : && initialize_elementwise_p (fieldtype, value.value))
12565 : : {
12566 : 302 : push_init_level (loc, 1, braced_init_obstack);
12567 : 302 : continue;
12568 : : }
12569 : :
12570 : 1036681 : value.value = maybe_split_raw_data (value.value, &raw_data);
12571 : 1036681 : if (value.value)
12572 : : {
12573 : 1036608 : push_member_name (constructor_fields);
12574 : 1036608 : output_init_element (loc, value.value, value.original_type,
12575 : : strict_string, fieldtype,
12576 : : constructor_fields, true, implicit,
12577 : : braced_init_obstack);
12578 : 1036608 : RESTORE_SPELLING_DEPTH (constructor_depth);
12579 : : }
12580 : : else
12581 : : /* Do the bookkeeping for an element that was
12582 : : directly output as a constructor. */
12583 : : {
12584 : : /* For a record, keep track of end position of last field. */
12585 : 73 : if (DECL_SIZE (constructor_fields))
12586 : 30 : constructor_bit_index
12587 : 30 : = size_binop_loc (input_location, PLUS_EXPR,
12588 : : bit_position (constructor_fields),
12589 : 30 : DECL_SIZE (constructor_fields));
12590 : :
12591 : : /* If the current field was the first one not yet written out,
12592 : : it isn't now, so update. */
12593 : 73 : if (constructor_unfilled_fields == constructor_fields)
12594 : : {
12595 : 64 : constructor_unfilled_fields = DECL_CHAIN (constructor_fields);
12596 : : /* Skip any nameless bit fields. */
12597 : 64 : while (constructor_unfilled_fields != 0
12598 : 64 : && (DECL_UNNAMED_BIT_FIELD
12599 : : (constructor_unfilled_fields)))
12600 : 0 : constructor_unfilled_fields =
12601 : 0 : DECL_CHAIN (constructor_unfilled_fields);
12602 : : }
12603 : : }
12604 : :
12605 : 1036681 : constructor_fields = DECL_CHAIN (constructor_fields);
12606 : : /* Skip any nameless bit fields at the beginning. */
12607 : 1036681 : while (constructor_fields != NULL_TREE
12608 : 1036782 : && DECL_UNNAMED_BIT_FIELD (constructor_fields))
12609 : 101 : constructor_fields = DECL_CHAIN (constructor_fields);
12610 : : }
12611 : 9256271 : else if (TREE_CODE (constructor_type) == UNION_TYPE)
12612 : : {
12613 : 31030 : tree fieldtype;
12614 : 31030 : enum tree_code fieldcode;
12615 : :
12616 : 31030 : if (constructor_fields == NULL_TREE)
12617 : : {
12618 : 3 : pedwarn_init (loc, 0,
12619 : : "excess elements in union initializer");
12620 : 3 : break;
12621 : : }
12622 : :
12623 : 31027 : fieldtype = TREE_TYPE (constructor_fields);
12624 : 31027 : if (fieldtype != error_mark_node)
12625 : 31027 : fieldtype = TYPE_MAIN_VARIANT (fieldtype);
12626 : 31027 : fieldcode = TREE_CODE (fieldtype);
12627 : :
12628 : : /* Warn that traditional C rejects initialization of unions.
12629 : : We skip the warning if the value is zero. This is done
12630 : : under the assumption that the zero initializer in user
12631 : : code appears conditioned on e.g. __STDC__ to avoid
12632 : : "missing initializer" warnings and relies on default
12633 : : initialization to zero in the traditional C case.
12634 : : We also skip the warning if the initializer is designated,
12635 : : again on the assumption that this must be conditional on
12636 : : __STDC__ anyway (and we've already complained about the
12637 : : member-designator already). */
12638 : 33238 : if (!in_system_header_at (input_location) && !constructor_designated
12639 : 32477 : && !(value.value && (integer_zerop (value.value)
12640 : 1351 : || real_zerop (value.value))))
12641 : 1344 : warning (OPT_Wtraditional, "traditional C rejects initialization "
12642 : : "of unions");
12643 : :
12644 : : /* Error for non-static initialization of a flexible array member. */
12645 : 31027 : if (fieldcode == ARRAY_TYPE
12646 : 766 : && !require_constant_value
12647 : 31084 : && TYPE_SIZE (fieldtype) == NULL_TREE)
12648 : : {
12649 : 3 : error_init (loc, "non-static initialization of a flexible "
12650 : : "array member");
12651 : 3 : break;
12652 : : }
12653 : :
12654 : : /* Error for initialization of a flexible array member with
12655 : : a string constant if the structure is in an array. E.g.:
12656 : : union U { int x; char y[]; };
12657 : : union U s[] = { { 1, "foo" } };
12658 : : is invalid. */
12659 : 31024 : if (string_flag
12660 : 31024 : && fieldcode == ARRAY_TYPE
12661 : 7 : && constructor_depth > 1
12662 : 31028 : && TYPE_SIZE (fieldtype) == NULL_TREE)
12663 : : {
12664 : 3 : bool in_array_p = false;
12665 : 3 : for (struct constructor_stack *p = constructor_stack;
12666 : 3 : p && p->type; p = p->next)
12667 : 3 : if (TREE_CODE (p->type) == ARRAY_TYPE)
12668 : : {
12669 : : in_array_p = true;
12670 : : break;
12671 : : }
12672 : 3 : if (in_array_p)
12673 : : {
12674 : 3 : error_init (loc, "initialization of flexible array "
12675 : : "member in a nested context");
12676 : 3 : break;
12677 : : }
12678 : : }
12679 : :
12680 : : /* Accept a string constant to initialize a subarray. */
12681 : 31021 : if (value.value != NULL_TREE
12682 : 31021 : && fieldcode == ARRAY_TYPE
12683 : 760 : && INTEGRAL_TYPE_P (TREE_TYPE (fieldtype))
12684 : 31776 : && string_flag)
12685 : : value.value = orig_value;
12686 : : /* Otherwise, if we have come to a subaggregate,
12687 : : and we don't have an element of its type, push into it. */
12688 : 31066 : else if (value.value != NULL_TREE
12689 : 31017 : && initialize_elementwise_p (fieldtype, value.value))
12690 : : {
12691 : 49 : push_init_level (loc, 1, braced_init_obstack);
12692 : 49 : continue;
12693 : : }
12694 : :
12695 : 30972 : value.value = maybe_split_raw_data (value.value, &raw_data);
12696 : 30972 : if (value.value)
12697 : : {
12698 : 30972 : push_member_name (constructor_fields);
12699 : 30972 : output_init_element (loc, value.value, value.original_type,
12700 : : strict_string, fieldtype,
12701 : : constructor_fields, true, implicit,
12702 : : braced_init_obstack);
12703 : 30972 : RESTORE_SPELLING_DEPTH (constructor_depth);
12704 : : }
12705 : : else
12706 : : /* Do the bookkeeping for an element that was
12707 : : directly output as a constructor. */
12708 : : {
12709 : 0 : constructor_bit_index = DECL_SIZE (constructor_fields);
12710 : 0 : constructor_unfilled_fields = DECL_CHAIN (constructor_fields);
12711 : : }
12712 : :
12713 : 30972 : constructor_fields = NULL_TREE;
12714 : : }
12715 : 9225241 : else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
12716 : : {
12717 : 2415910 : tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
12718 : 2415910 : enum tree_code eltcode = TREE_CODE (elttype);
12719 : :
12720 : : /* Accept a string constant to initialize a subarray. */
12721 : 2415910 : if (value.value != NULL_TREE
12722 : 2415910 : && eltcode == ARRAY_TYPE
12723 : 6872 : && INTEGRAL_TYPE_P (TREE_TYPE (elttype))
12724 : 2421346 : && string_flag)
12725 : : value.value = orig_value;
12726 : : /* Otherwise, if we have come to a subaggregate,
12727 : : and we don't have an element of its type, push into it. */
12728 : 3117704 : else if (value.value != NULL_TREE
12729 : 2415414 : && initialize_elementwise_p (elttype, value.value))
12730 : : {
12731 : 702290 : push_init_level (loc, 1, braced_init_obstack);
12732 : 702290 : continue;
12733 : : }
12734 : :
12735 : 1713620 : if (constructor_max_index != NULL_TREE
12736 : 670969 : && (tree_int_cst_lt (constructor_max_index, constructor_index)
12737 : 670854 : || integer_all_onesp (constructor_max_index))
12738 : : /* For VLA we got an error already. */
12739 : 1713735 : && !C_TYPE_VARIABLE_SIZE (constructor_type))
12740 : : {
12741 : 113 : pedwarn_init (loc, 0,
12742 : : "excess elements in array initializer");
12743 : 113 : break;
12744 : : }
12745 : :
12746 : 1713507 : if (value.value
12747 : 1713507 : && TREE_CODE (value.value) == RAW_DATA_CST
12748 : 192 : && RAW_DATA_LENGTH (value.value) > 1
12749 : 192 : && (TREE_CODE (elttype) == INTEGER_TYPE
12750 : 192 : || TREE_CODE (elttype) == BITINT_TYPE)
12751 : 192 : && TYPE_PRECISION (elttype) == CHAR_BIT
12752 : 1713699 : && (constructor_max_index == NULL_TREE
12753 : 54 : || tree_int_cst_lt (constructor_index,
12754 : : constructor_max_index)))
12755 : : {
12756 : 192 : unsigned int len = RAW_DATA_LENGTH (value.value);
12757 : 192 : if (constructor_max_index)
12758 : : {
12759 : 54 : widest_int w = wi::to_widest (constructor_max_index);
12760 : 54 : w -= wi::to_widest (constructor_index);
12761 : 54 : w += 1;
12762 : 54 : if (w < len)
12763 : 3 : len = w.to_uhwi ();
12764 : 54 : }
12765 : 192 : if (len < (unsigned) RAW_DATA_LENGTH (value.value))
12766 : : {
12767 : 3 : raw_data = copy_node (value.value);
12768 : 3 : RAW_DATA_LENGTH (raw_data) -= len;
12769 : 3 : RAW_DATA_POINTER (raw_data) += len;
12770 : 3 : RAW_DATA_LENGTH (value.value) = len;
12771 : : }
12772 : 192 : TREE_TYPE (value.value) = elttype;
12773 : 192 : push_array_bounds (tree_to_uhwi (constructor_index));
12774 : 192 : output_init_element (loc, value.value, value.original_type,
12775 : : false, elttype, constructor_index, true,
12776 : : implicit, braced_init_obstack);
12777 : 192 : RESTORE_SPELLING_DEPTH (constructor_depth);
12778 : 192 : constructor_index
12779 : 192 : = size_binop_loc (input_location, PLUS_EXPR,
12780 : 192 : constructor_index, bitsize_int (len));
12781 : : }
12782 : : else
12783 : : {
12784 : 1713315 : value.value = maybe_split_raw_data (value.value, &raw_data);
12785 : : /* Now output the actual element. */
12786 : 1713315 : if (value.value)
12787 : : {
12788 : 1713315 : push_array_bounds (tree_to_uhwi (constructor_index));
12789 : 1713315 : output_init_element (loc, value.value, value.original_type,
12790 : : strict_string, elttype,
12791 : : constructor_index, true, implicit,
12792 : : braced_init_obstack);
12793 : 1713315 : RESTORE_SPELLING_DEPTH (constructor_depth);
12794 : : }
12795 : :
12796 : 1713315 : constructor_index
12797 : 1713315 : = size_binop_loc (input_location, PLUS_EXPR,
12798 : : constructor_index, bitsize_one_node);
12799 : :
12800 : 1713315 : if (!value.value)
12801 : : /* If we are doing the bookkeeping for an element that was
12802 : : directly output as a constructor, we must update
12803 : : constructor_unfilled_index. */
12804 : 0 : constructor_unfilled_index = constructor_index;
12805 : : }
12806 : : }
12807 : 6809331 : else if (gnu_vector_type_p (constructor_type))
12808 : : {
12809 : 6808854 : tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
12810 : :
12811 : : /* Do a basic check of initializer size. Note that vectors
12812 : : may not always have a fixed size derived from their type. */
12813 : 6808854 : if (maybe_lt (tree_to_poly_uint64 (constructor_max_index),
12814 : 6808854 : tree_to_poly_uint64 (constructor_index)))
12815 : : {
12816 : : /* Diagose VLA out-of-bounds as errors. */
12817 : 2 : if (tree_to_poly_uint64 (constructor_max_index).is_constant())
12818 : 2 : pedwarn_init (loc, 0,
12819 : : "excess elements in vector initializer");
12820 : : else
12821 : : error_init (loc, "excess elements in vector initializer");
12822 : :
12823 : : break;
12824 : : }
12825 : :
12826 : 6808852 : value.value = maybe_split_raw_data (value.value, &raw_data);
12827 : : /* Now output the actual element. */
12828 : 6808852 : if (value.value)
12829 : : {
12830 : 6808852 : if (TREE_CODE (value.value) == VECTOR_CST)
12831 : 0 : elttype = TYPE_MAIN_VARIANT (constructor_type);
12832 : 6808852 : output_init_element (loc, value.value, value.original_type,
12833 : : strict_string, elttype,
12834 : : constructor_index, true, implicit,
12835 : : braced_init_obstack);
12836 : : }
12837 : :
12838 : 6808852 : constructor_index
12839 : 6808852 : = size_binop_loc (input_location,
12840 : : PLUS_EXPR, constructor_index, bitsize_one_node);
12841 : :
12842 : 6808852 : if (!value.value)
12843 : : /* If we are doing the bookkeeping for an element that was
12844 : : directly output as a constructor, we must update
12845 : : constructor_unfilled_index. */
12846 : 0 : constructor_unfilled_index = constructor_index;
12847 : : }
12848 : :
12849 : : /* Handle the sole element allowed in a braced initializer
12850 : : for a scalar variable. */
12851 : 477 : else if (constructor_type != error_mark_node
12852 : 477 : && constructor_fields == NULL_TREE)
12853 : : {
12854 : 29 : pedwarn_init (loc, 0,
12855 : : "excess elements in scalar initializer");
12856 : 29 : break;
12857 : : }
12858 : : else
12859 : : {
12860 : 448 : value.value = maybe_split_raw_data (value.value, &raw_data);
12861 : 448 : if (value.value)
12862 : 448 : output_init_element (loc, value.value, value.original_type,
12863 : : strict_string, constructor_type,
12864 : : NULL_TREE, true, implicit,
12865 : : braced_init_obstack);
12866 : 448 : constructor_fields = NULL_TREE;
12867 : : }
12868 : :
12869 : : /* Handle range initializers either at this level or anywhere higher
12870 : : in the designator stack. */
12871 : 9590460 : if (constructor_range_stack)
12872 : : {
12873 : 10802 : struct constructor_range_stack *p, *range_stack;
12874 : 10802 : int finish = 0;
12875 : :
12876 : 10802 : range_stack = constructor_range_stack;
12877 : 10802 : constructor_range_stack = 0;
12878 : 10802 : while (constructor_stack != range_stack->stack)
12879 : : {
12880 : 0 : gcc_assert (constructor_stack->implicit);
12881 : 0 : process_init_element (loc,
12882 : : pop_init_level (loc, 1,
12883 : : braced_init_obstack,
12884 : : last_init_list_comma),
12885 : : true, braced_init_obstack);
12886 : : }
12887 : 325 : for (p = range_stack;
12888 : 11127 : !p->range_end || tree_int_cst_equal (p->index, p->range_end);
12889 : 325 : p = p->prev)
12890 : : {
12891 : 325 : gcc_assert (constructor_stack->implicit);
12892 : 325 : process_init_element (loc,
12893 : : pop_init_level (loc, 1,
12894 : : braced_init_obstack,
12895 : : last_init_list_comma),
12896 : : true, braced_init_obstack);
12897 : : }
12898 : :
12899 : 10802 : p->index = size_binop_loc (input_location,
12900 : : PLUS_EXPR, p->index, bitsize_one_node);
12901 : 10802 : if (tree_int_cst_equal (p->index, p->range_end) && !p->prev)
12902 : 373 : finish = 1;
12903 : :
12904 : 11127 : while (1)
12905 : : {
12906 : 11127 : constructor_index = p->index;
12907 : 11127 : constructor_fields = p->fields;
12908 : 11127 : if (finish && p->range_end && p->index == p->range_start)
12909 : : {
12910 : 8 : finish = 0;
12911 : 8 : p->prev = 0;
12912 : : }
12913 : 11127 : p = p->next;
12914 : 11127 : if (!p)
12915 : : break;
12916 : 325 : finish_implicit_inits (loc, braced_init_obstack);
12917 : 325 : push_init_level (loc, 2, braced_init_obstack);
12918 : 325 : p->stack = constructor_stack;
12919 : 325 : if (p->range_end && tree_int_cst_equal (p->index, p->range_end))
12920 : 33 : p->index = p->range_start;
12921 : : }
12922 : :
12923 : 10802 : if (!finish)
12924 : 10437 : constructor_range_stack = range_stack;
12925 : 10802 : continue;
12926 : 10802 : }
12927 : :
12928 : : break;
12929 : : }
12930 : :
12931 : 9581134 : constructor_range_stack = 0;
12932 : :
12933 : 9581134 : if (raw_data && RAW_DATA_LENGTH (raw_data))
12934 : : {
12935 : 212 : gcc_assert (!string_flag && !was_designated);
12936 : 212 : value.value = raw_data;
12937 : 212 : raw_data = NULL_TREE;
12938 : 212 : goto retry;
12939 : : }
12940 : : }
12941 : :
12942 : : /* Build a complete asm-statement, whose components are a CV_QUALIFIER
12943 : : (guaranteed to be 'volatile' or null) and ARGS (represented using
12944 : : an ASM_EXPR node). */
12945 : : tree
12946 : 204601 : build_asm_stmt (bool is_volatile, tree args)
12947 : : {
12948 : 204601 : if (is_volatile)
12949 : 164857 : ASM_VOLATILE_P (args) = 1;
12950 : 204601 : return add_stmt (args);
12951 : : }
12952 : :
12953 : : /* Build an asm-expr, whose components are a STRING, some OUTPUTS,
12954 : : some INPUTS, and some CLOBBERS. The latter three may be NULL.
12955 : : SIMPLE indicates whether there was anything at all after the
12956 : : string in the asm expression -- asm("blah") and asm("blah" : )
12957 : : are subtly different. We use a ASM_EXPR node to represent this.
12958 : : LOC is the location of the asm, and IS_INLINE says whether this
12959 : : is asm inline. */
12960 : : tree
12961 : 204631 : build_asm_expr (location_t loc, tree string, tree outputs, tree inputs,
12962 : : tree clobbers, tree labels, bool simple, bool is_inline)
12963 : : {
12964 : 204631 : tree tail;
12965 : 204631 : tree args;
12966 : 204631 : int i;
12967 : 204631 : const char *constraint;
12968 : 204631 : const char **oconstraints;
12969 : 204631 : bool allows_mem, allows_reg, is_inout;
12970 : 204631 : int ninputs, noutputs;
12971 : :
12972 : 204631 : ninputs = list_length (inputs);
12973 : 204631 : noutputs = list_length (outputs);
12974 : 204631 : oconstraints = (const char **) alloca (noutputs * sizeof (const char *));
12975 : :
12976 : 204631 : string = resolve_asm_operand_names (string, outputs, inputs, labels);
12977 : :
12978 : : /* Remove output conversions that change the type but not the mode. */
12979 : 552663 : for (i = 0, tail = outputs; tail; ++i, tail = TREE_CHAIN (tail))
12980 : : {
12981 : 348032 : tree output = TREE_VALUE (tail);
12982 : :
12983 : 348032 : output = c_fully_fold (output, false, NULL, true);
12984 : :
12985 : : /* ??? Really, this should not be here. Users should be using a
12986 : : proper lvalue, dammit. But there's a long history of using casts
12987 : : in the output operands. In cases like longlong.h, this becomes a
12988 : : primitive form of typechecking -- if the cast can be removed, then
12989 : : the output operand had a type of the proper width; otherwise we'll
12990 : : get an error. Gross, but ... */
12991 : 348032 : STRIP_NOPS (output);
12992 : :
12993 : 348032 : if (!lvalue_or_else (loc, output, lv_asm))
12994 : 4 : output = error_mark_node;
12995 : :
12996 : 348032 : if (output != error_mark_node
12997 : 348032 : && (TREE_READONLY (output)
12998 : 348025 : || TYPE_READONLY (TREE_TYPE (output))
12999 : 348025 : || (RECORD_OR_UNION_TYPE_P (TREE_TYPE (output))
13000 : 112 : && C_TYPE_FIELDS_READONLY (TREE_TYPE (output)))))
13001 : 2 : readonly_error (loc, output, lv_asm);
13002 : :
13003 : 348032 : constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (tail)));
13004 : 348032 : oconstraints[i] = constraint;
13005 : :
13006 : 348032 : if (parse_output_constraint (&constraint, i, ninputs, noutputs,
13007 : : &allows_mem, &allows_reg, &is_inout,
13008 : : nullptr))
13009 : : {
13010 : : /* If the operand is going to end up in memory,
13011 : : mark it addressable. */
13012 : 348024 : if (!allows_reg && !c_mark_addressable (output))
13013 : 3 : output = error_mark_node;
13014 : 1419 : if (!(!allows_reg && allows_mem)
13015 : 346605 : && output != error_mark_node
13016 : 694627 : && VOID_TYPE_P (TREE_TYPE (output)))
13017 : : {
13018 : 4 : error_at (loc, "invalid use of void expression");
13019 : 4 : output = error_mark_node;
13020 : : }
13021 : 348024 : if (allows_reg && current_function_decl == NULL_TREE)
13022 : : {
13023 : 1 : error_at (loc, "constraint allows registers outside of "
13024 : : "a function");
13025 : 1 : output = error_mark_node;
13026 : : }
13027 : : }
13028 : : else
13029 : 8 : output = error_mark_node;
13030 : :
13031 : 348032 : if (current_function_decl == NULL_TREE && output != error_mark_node)
13032 : : {
13033 : 7 : if (TREE_SIDE_EFFECTS (output))
13034 : : {
13035 : 0 : error_at (loc, "side-effects in output operand outside "
13036 : : "of a function");
13037 : 0 : output = error_mark_node;
13038 : : }
13039 : : else
13040 : : {
13041 : 7 : tree addr = build_unary_op (loc, ADDR_EXPR, output, false);
13042 : 7 : if (addr == error_mark_node)
13043 : : output = error_mark_node;
13044 : 7 : else if (!initializer_constant_valid_p (addr, TREE_TYPE (addr)))
13045 : : {
13046 : 1 : error_at (loc, "output operand outside of a function is not "
13047 : : "constant");
13048 : 1 : output = error_mark_node;
13049 : : }
13050 : : }
13051 : : }
13052 : 348025 : else if (output != error_mark_node && strstr (constraint, "-"))
13053 : : {
13054 : 1 : error_at (loc, "%<-%> modifier used inside of a function");
13055 : 1 : output = error_mark_node;
13056 : : }
13057 : :
13058 : 348032 : TREE_VALUE (tail) = output;
13059 : : }
13060 : :
13061 : 568090 : for (i = 0, tail = inputs; tail; ++i, tail = TREE_CHAIN (tail))
13062 : : {
13063 : 363459 : tree input;
13064 : :
13065 : 363459 : constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (tail)));
13066 : 363459 : input = TREE_VALUE (tail);
13067 : :
13068 : 363459 : if (parse_input_constraint (&constraint, i, ninputs, noutputs, 0,
13069 : : oconstraints, &allows_mem, &allows_reg,
13070 : : nullptr))
13071 : : {
13072 : : /* If the operand is going to end up in memory,
13073 : : mark it addressable. */
13074 : 363452 : if (!allows_reg && allows_mem)
13075 : : {
13076 : 1392 : input = c_fully_fold (input, false, NULL, true);
13077 : :
13078 : : /* Strip the nops as we allow this case. FIXME, this really
13079 : : should be rejected or made deprecated. */
13080 : 1392 : STRIP_NOPS (input);
13081 : 1392 : if (!c_mark_addressable (input))
13082 : 2 : input = error_mark_node;
13083 : : }
13084 : : else
13085 : : {
13086 : 362060 : input = c_fully_fold (convert_lvalue_to_rvalue (loc, input,
13087 : : true, false),
13088 : : false, NULL);
13089 : :
13090 : 362060 : if (input != error_mark_node && VOID_TYPE_P (TREE_TYPE (input)))
13091 : : {
13092 : 4 : error_at (loc, "invalid use of void expression");
13093 : 4 : input = error_mark_node;
13094 : : }
13095 : : }
13096 : 363452 : if (allows_reg && current_function_decl == NULL_TREE)
13097 : : {
13098 : 1 : error_at (loc, "constraint allows registers outside of "
13099 : : "a function");
13100 : 1 : input = error_mark_node;
13101 : : }
13102 : 363452 : if (constraint[0] == ':' && input != error_mark_node)
13103 : : {
13104 : 15 : tree t = input;
13105 : 15 : STRIP_NOPS (t);
13106 : 15 : if (TREE_CODE (t) != ADDR_EXPR
13107 : 15 : || !(TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL
13108 : 10 : || (VAR_P (TREE_OPERAND (t, 0))
13109 : 8 : && is_global_var (TREE_OPERAND (t, 0)))))
13110 : : {
13111 : 5 : error_at (loc, "%<:%> constraint operand is not address "
13112 : : "of a function or non-automatic variable");
13113 : 5 : input = error_mark_node;
13114 : : }
13115 : : }
13116 : : }
13117 : : else
13118 : 7 : input = error_mark_node;
13119 : :
13120 : 363459 : if (current_function_decl == NULL_TREE && input != error_mark_node)
13121 : : {
13122 : 36 : if (TREE_SIDE_EFFECTS (input))
13123 : : {
13124 : 2 : error_at (loc, "side-effects in input operand outside "
13125 : : "of a function");
13126 : 2 : input = error_mark_node;
13127 : : }
13128 : : else
13129 : : {
13130 : 34 : tree tem = input;
13131 : 34 : if (allows_mem && lvalue_p (input))
13132 : 7 : tem = build_unary_op (loc, ADDR_EXPR, input, false);
13133 : 34 : if (!initializer_constant_valid_p (tem, TREE_TYPE (tem)))
13134 : : {
13135 : 2 : error_at (loc, "input operand outside of a function is not "
13136 : : "constant");
13137 : 2 : input = error_mark_node;
13138 : : }
13139 : : }
13140 : : }
13141 : 363423 : else if (input != error_mark_node && strstr (constraint, "-"))
13142 : : {
13143 : 3 : error_at (loc, "%<-%> modifier used inside of a function");
13144 : 3 : input = error_mark_node;
13145 : : }
13146 : :
13147 : 363459 : TREE_VALUE (tail) = input;
13148 : : }
13149 : :
13150 : 204631 : args = build_stmt (loc, ASM_EXPR, string, outputs, inputs, clobbers, labels);
13151 : :
13152 : : /* asm statements without outputs, including simple ones, are treated
13153 : : as volatile. */
13154 : 204631 : ASM_BASIC_P (args) = simple;
13155 : 204631 : ASM_VOLATILE_P (args) = (noutputs == 0);
13156 : 204631 : ASM_INLINE_P (args) = is_inline;
13157 : :
13158 : 204631 : return args;
13159 : : }
13160 : :
13161 : : /* Generate a goto statement to LABEL. LOC is the location of the
13162 : : GOTO. */
13163 : :
13164 : : tree
13165 : 82629 : c_finish_goto_label (location_t loc, tree label)
13166 : : {
13167 : 82629 : tree decl = lookup_label_for_goto (loc, label);
13168 : 82629 : if (!decl)
13169 : : return NULL_TREE;
13170 : 82629 : TREE_USED (decl) = 1;
13171 : 82629 : mark_decl_used (decl, false);
13172 : 82629 : {
13173 : 82629 : add_stmt (build_predict_expr (PRED_GOTO, NOT_TAKEN));
13174 : 82629 : tree t = build1 (GOTO_EXPR, void_type_node, decl);
13175 : 82629 : SET_EXPR_LOCATION (t, loc);
13176 : 82629 : return add_stmt (t);
13177 : : }
13178 : : }
13179 : :
13180 : : /* Generate a computed goto statement to EXPR. LOC is the location of
13181 : : the GOTO. */
13182 : :
13183 : : tree
13184 : 932 : c_finish_goto_ptr (location_t loc, c_expr val)
13185 : : {
13186 : 932 : tree expr = val.value;
13187 : 932 : tree t;
13188 : 932 : pedwarn (loc, OPT_Wpedantic, "ISO C forbids %<goto *expr;%>");
13189 : 932 : if (expr != error_mark_node
13190 : 931 : && !POINTER_TYPE_P (TREE_TYPE (expr))
13191 : 937 : && !null_pointer_constant_p (expr))
13192 : : {
13193 : 2 : error_at (val.get_location (),
13194 : : "computed goto must be pointer type");
13195 : 2 : expr = build_zero_cst (ptr_type_node);
13196 : : }
13197 : 932 : expr = c_fully_fold (expr, false, NULL);
13198 : 932 : expr = convert (ptr_type_node, expr);
13199 : 932 : t = build1 (GOTO_EXPR, void_type_node, expr);
13200 : 932 : SET_EXPR_LOCATION (t, loc);
13201 : 932 : return add_stmt (t);
13202 : : }
13203 : :
13204 : : /* Generate a C `return' statement. RETVAL is the expression for what
13205 : : to return, or a null pointer for `return;' with no value. LOC is
13206 : : the location of the return statement, or the location of the expression,
13207 : : if the statement has any. If ORIGTYPE is not NULL_TREE, it
13208 : : is the original type of RETVAL. MUSTTAIL_P indicates a musttail
13209 : : attribute. */
13210 : :
13211 : : tree
13212 : 34467022 : c_finish_return (location_t loc, tree retval, tree origtype, bool musttail_p)
13213 : : {
13214 : 34467022 : tree valtype = TREE_TYPE (TREE_TYPE (current_function_decl)), ret_stmt;
13215 : 34467022 : bool no_warning = false;
13216 : 34467022 : bool npc = false;
13217 : :
13218 : : /* Use the expansion point to handle cases such as returning NULL
13219 : : in a function returning void. */
13220 : 34467022 : location_t xloc = expansion_point_location_if_in_system_header (loc);
13221 : :
13222 : 34467022 : if (TREE_THIS_VOLATILE (current_function_decl))
13223 : 23 : warning_at (xloc, 0,
13224 : : "function declared %<noreturn%> has a %<return%> statement");
13225 : :
13226 : 34467022 : set_musttail_on_return (retval, xloc, musttail_p);
13227 : :
13228 : 34467022 : if (retval)
13229 : : {
13230 : 34446002 : tree semantic_type = NULL_TREE;
13231 : 34446002 : npc = null_pointer_constant_p (retval);
13232 : 34446002 : if (TREE_CODE (retval) == EXCESS_PRECISION_EXPR)
13233 : : {
13234 : 92 : semantic_type = TREE_TYPE (retval);
13235 : 92 : retval = TREE_OPERAND (retval, 0);
13236 : : }
13237 : 34446002 : retval = c_fully_fold (retval, false, NULL);
13238 : 34446002 : if (semantic_type
13239 : 34446002 : && valtype != NULL_TREE
13240 : 92 : && TREE_CODE (valtype) != VOID_TYPE)
13241 : 92 : retval = build1 (EXCESS_PRECISION_EXPR, semantic_type, retval);
13242 : : }
13243 : :
13244 : 34446002 : if (!retval)
13245 : : {
13246 : 21020 : current_function_returns_null = 1;
13247 : 21020 : if ((warn_return_type >= 0 || flag_isoc99)
13248 : 20895 : && valtype != NULL_TREE && TREE_CODE (valtype) != VOID_TYPE)
13249 : : {
13250 : 46 : no_warning = true;
13251 : 47 : if (emit_diagnostic (flag_isoc99
13252 : : ? diagnostics::kind::permerror
13253 : : : diagnostics::kind::warning,
13254 : 46 : loc, OPT_Wreturn_mismatch,
13255 : : "%<return%> with no value,"
13256 : : " in function returning non-void"))
13257 : 27 : inform (DECL_SOURCE_LOCATION (current_function_decl),
13258 : : "declared here");
13259 : : }
13260 : : }
13261 : 34446002 : else if (valtype == NULL_TREE || VOID_TYPE_P (valtype))
13262 : : {
13263 : 322 : current_function_returns_null = 1;
13264 : 322 : bool warned_here;
13265 : 322 : if (TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
13266 : 64 : warned_here = permerror_opt
13267 : 64 : (xloc, OPT_Wreturn_mismatch,
13268 : : "%<return%> with a value, in function returning void");
13269 : : else
13270 : 258 : warned_here = pedwarn
13271 : 258 : (xloc, OPT_Wpedantic, "ISO C forbids "
13272 : : "%<return%> with expression, in function returning void");
13273 : 322 : if (warned_here)
13274 : 43 : inform (DECL_SOURCE_LOCATION (current_function_decl),
13275 : : "declared here");
13276 : : }
13277 : : else
13278 : : {
13279 : 34445680 : tree t = convert_for_assignment (loc, UNKNOWN_LOCATION, valtype,
13280 : : retval, origtype, ic_return,
13281 : : npc, NULL_TREE, NULL_TREE, 0);
13282 : 34445680 : tree res = DECL_RESULT (current_function_decl);
13283 : 34445680 : tree inner;
13284 : 34445680 : bool save;
13285 : :
13286 : 34445680 : current_function_returns_value = 1;
13287 : 34445680 : if (t == error_mark_node)
13288 : : {
13289 : : /* Suppress -Wreturn-type for this function. */
13290 : 298 : if (warn_return_type)
13291 : 297 : suppress_warning (current_function_decl, OPT_Wreturn_type);
13292 : 298 : return NULL_TREE;
13293 : : }
13294 : :
13295 : 34445382 : save = in_late_binary_op;
13296 : 68882965 : if (C_BOOLEAN_TYPE_P (TREE_TYPE (res))
13297 : 34436778 : || TREE_CODE (TREE_TYPE (res)) == COMPLEX_TYPE
13298 : 68880878 : || (SCALAR_FLOAT_TYPE_P (TREE_TYPE (t))
13299 : 332565 : && (TREE_CODE (TREE_TYPE (res)) == INTEGER_TYPE
13300 : 332565 : || TREE_CODE (TREE_TYPE (res)) == ENUMERAL_TYPE)
13301 : 0 : && sanitize_flags_p (SANITIZE_FLOAT_CAST)))
13302 : 9886 : in_late_binary_op = true;
13303 : 34445382 : inner = t = convert (TREE_TYPE (res), t);
13304 : 34445382 : in_late_binary_op = save;
13305 : :
13306 : : /* Strip any conversions, additions, and subtractions, and see if
13307 : : we are returning the address of a local variable. Warn if so. */
13308 : 37710892 : while (1)
13309 : : {
13310 : 37710892 : switch (TREE_CODE (inner))
13311 : : {
13312 : 3264094 : CASE_CONVERT:
13313 : 3264094 : case NON_LVALUE_EXPR:
13314 : 3264094 : case PLUS_EXPR:
13315 : 3264094 : case POINTER_PLUS_EXPR:
13316 : 3264094 : inner = TREE_OPERAND (inner, 0);
13317 : 3264094 : continue;
13318 : :
13319 : 1421 : case MINUS_EXPR:
13320 : : /* If the second operand of the MINUS_EXPR has a pointer
13321 : : type (or is converted from it), this may be valid, so
13322 : : don't give a warning. */
13323 : 1421 : {
13324 : 1421 : tree op1 = TREE_OPERAND (inner, 1);
13325 : :
13326 : 3089 : while (!POINTER_TYPE_P (TREE_TYPE (op1))
13327 : 3341 : && (CONVERT_EXPR_P (op1)
13328 : 1416 : || TREE_CODE (op1) == NON_LVALUE_EXPR))
13329 : 252 : op1 = TREE_OPERAND (op1, 0);
13330 : :
13331 : 1421 : if (POINTER_TYPE_P (TREE_TYPE (op1)))
13332 : : break;
13333 : :
13334 : 1416 : inner = TREE_OPERAND (inner, 0);
13335 : 1416 : continue;
13336 : 1416 : }
13337 : :
13338 : 2903 : case ADDR_EXPR:
13339 : 2903 : inner = TREE_OPERAND (inner, 0);
13340 : :
13341 : 2903 : while (REFERENCE_CLASS_P (inner)
13342 : 3785 : && !INDIRECT_REF_P (inner))
13343 : 882 : inner = TREE_OPERAND (inner, 0);
13344 : :
13345 : 2903 : if (DECL_P (inner)
13346 : 1586 : && !DECL_EXTERNAL (inner)
13347 : 951 : && DECL_CONTEXT (inner) == current_function_decl
13348 : 3120 : && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (current_function_decl))))
13349 : : {
13350 : 177 : if (TREE_CODE (inner) == LABEL_DECL)
13351 : 4 : warning_at (loc, OPT_Wreturn_local_addr,
13352 : : "function returns address of label");
13353 : 173 : else if (TREE_CODE (inner) == FUNCTION_DECL
13354 : 173 : && (C_FUNC_NONLOCAL_CONTEXT (inner)
13355 : 8 : || !DECL_INITIAL (inner)))
13356 : 10 : warning_at (loc, OPT_Wreturn_local_addr,
13357 : : "function returns address of nested function "
13358 : : "referencing local context");
13359 : 163 : else if (TREE_CODE (inner) != FUNCTION_DECL
13360 : 156 : && !TREE_STATIC (inner))
13361 : : {
13362 : 9 : warning_at (loc, OPT_Wreturn_local_addr,
13363 : : "function returns address of local variable");
13364 : 9 : tree zero = build_zero_cst (TREE_TYPE (res));
13365 : 9 : t = build2 (COMPOUND_EXPR, TREE_TYPE (res), t, zero);
13366 : : }
13367 : : }
13368 : : break;
13369 : :
13370 : : default:
13371 : : break;
13372 : 3264094 : }
13373 : :
13374 : 34445382 : break;
13375 : : }
13376 : :
13377 : 34445382 : retval = build2 (MODIFY_EXPR, TREE_TYPE (res), res, t);
13378 : 34445382 : SET_EXPR_LOCATION (retval, loc);
13379 : :
13380 : 34445382 : if (warn_sequence_point)
13381 : 2958870 : verify_sequence_points (retval);
13382 : : }
13383 : :
13384 : 34466724 : ret_stmt = build_stmt (loc, RETURN_EXPR, retval);
13385 : 34466724 : if (no_warning)
13386 : 46 : suppress_warning (ret_stmt, OPT_Wreturn_type);
13387 : 34466724 : return add_stmt (ret_stmt);
13388 : : }
13389 : :
13390 : : struct c_switch {
13391 : : /* The SWITCH_STMT being built. */
13392 : : tree switch_stmt;
13393 : :
13394 : : /* The original type of the testing expression, i.e. before the
13395 : : default conversion is applied. */
13396 : : tree orig_type;
13397 : :
13398 : : /* A splay-tree mapping the low element of a case range to the high
13399 : : element, or NULL_TREE if there is no high element. Used to
13400 : : determine whether or not a new case label duplicates an old case
13401 : : label. We need a tree, rather than simply a hash table, because
13402 : : of the GNU case range extension. */
13403 : : splay_tree cases;
13404 : :
13405 : : /* The bindings at the point of the switch. This is used for
13406 : : warnings crossing decls when branching to a case label. */
13407 : : struct c_spot_bindings *bindings;
13408 : :
13409 : : /* Whether the switch includes any break statements. */
13410 : : bool break_stmt_seen_p;
13411 : :
13412 : : /* The next node on the stack. */
13413 : : struct c_switch *next;
13414 : :
13415 : : /* Remember whether the controlling expression had boolean type
13416 : : before integer promotions for the sake of -Wswitch-bool. */
13417 : : bool bool_cond_p;
13418 : : };
13419 : :
13420 : : /* A stack of the currently active switch statements. The innermost
13421 : : switch statement is on the top of the stack. There is no need to
13422 : : mark the stack for garbage collection because it is only active
13423 : : during the processing of the body of a function, and we never
13424 : : collect at that point. */
13425 : :
13426 : : struct c_switch *c_switch_stack;
13427 : :
13428 : : /* Start a C switch statement, testing expression EXP. Return the new
13429 : : SWITCH_STMT. SWITCH_LOC is the location of the `switch'.
13430 : : SWITCH_COND_LOC is the location of the switch's condition.
13431 : : EXPLICIT_CAST_P is true if the expression EXP has an explicit cast. */
13432 : :
13433 : : tree
13434 : 37141 : c_start_switch (location_t switch_loc,
13435 : : location_t switch_cond_loc,
13436 : : tree exp, bool explicit_cast_p, tree switch_name)
13437 : : {
13438 : 37141 : tree orig_type = error_mark_node;
13439 : 37141 : bool bool_cond_p = false;
13440 : 37141 : struct c_switch *cs;
13441 : :
13442 : 37141 : if (exp != error_mark_node)
13443 : : {
13444 : 37098 : orig_type = TREE_TYPE (exp);
13445 : :
13446 : 37098 : if (!INTEGRAL_TYPE_P (orig_type))
13447 : : {
13448 : 12 : if (orig_type != error_mark_node)
13449 : : {
13450 : 12 : error_at (switch_cond_loc, "switch quantity not an integer");
13451 : 12 : orig_type = error_mark_node;
13452 : : }
13453 : 12 : exp = integer_zero_node;
13454 : : }
13455 : : else
13456 : : {
13457 : 37086 : tree type = TYPE_MAIN_VARIANT (orig_type);
13458 : 37086 : tree e = exp;
13459 : :
13460 : : /* Warn if the condition has boolean value. */
13461 : 37089 : while (TREE_CODE (e) == COMPOUND_EXPR)
13462 : 3 : e = TREE_OPERAND (e, 1);
13463 : :
13464 : 37061 : if ((C_BOOLEAN_TYPE_P (type)
13465 : 37061 : || truth_value_p (TREE_CODE (e)))
13466 : : /* Explicit cast to int suppresses this warning. */
13467 : 37108 : && !(TREE_CODE (type) == INTEGER_TYPE
13468 : : && explicit_cast_p))
13469 : : bool_cond_p = true;
13470 : :
13471 : 37086 : if (!in_system_header_at (input_location)
13472 : 37086 : && (type == long_integer_type_node
13473 : 11870 : || type == long_unsigned_type_node))
13474 : 258 : warning_at (switch_cond_loc,
13475 : 258 : OPT_Wtraditional, "%<long%> switch expression not "
13476 : : "converted to %<int%> in ISO C");
13477 : :
13478 : 37086 : exp = c_fully_fold (exp, false, NULL);
13479 : 37086 : exp = default_conversion (exp);
13480 : :
13481 : 37086 : if (warn_sequence_point)
13482 : 6009 : verify_sequence_points (exp);
13483 : : }
13484 : : }
13485 : :
13486 : : /* Add this new SWITCH_STMT to the stack. */
13487 : 37141 : cs = XNEW (struct c_switch);
13488 : 37141 : cs->switch_stmt = build_stmt (switch_loc, SWITCH_STMT, exp,
13489 : : NULL_TREE, orig_type, NULL_TREE, switch_name);
13490 : 37141 : cs->orig_type = orig_type;
13491 : 37141 : cs->cases = splay_tree_new (case_compare, NULL, NULL);
13492 : 37141 : cs->bindings = c_get_switch_bindings ();
13493 : 37141 : cs->break_stmt_seen_p = false;
13494 : 37141 : cs->bool_cond_p = bool_cond_p;
13495 : 37141 : cs->next = c_switch_stack;
13496 : 37141 : c_switch_stack = cs;
13497 : :
13498 : 37141 : return add_stmt (cs->switch_stmt);
13499 : : }
13500 : :
13501 : : /* Process a case label at location LOC, with attributes ATTRS. */
13502 : :
13503 : : tree
13504 : 1029163 : do_case (location_t loc, tree low_value, tree high_value, tree attrs)
13505 : : {
13506 : 1029163 : tree label = NULL_TREE;
13507 : :
13508 : 1029163 : if (low_value && TREE_CODE (low_value) != INTEGER_CST)
13509 : : {
13510 : 87 : low_value = c_fully_fold (low_value, false, NULL);
13511 : 87 : if (TREE_CODE (low_value) == INTEGER_CST)
13512 : 9 : pedwarn (loc, OPT_Wpedantic,
13513 : : "case label is not an integer constant expression");
13514 : : }
13515 : :
13516 : 1029163 : if (high_value && TREE_CODE (high_value) != INTEGER_CST)
13517 : : {
13518 : 0 : high_value = c_fully_fold (high_value, false, NULL);
13519 : 0 : if (TREE_CODE (high_value) == INTEGER_CST)
13520 : 0 : pedwarn (input_location, OPT_Wpedantic,
13521 : : "case label is not an integer constant expression");
13522 : : }
13523 : :
13524 : 1029163 : if (c_switch_stack == NULL)
13525 : : {
13526 : 3 : if (low_value)
13527 : 2 : error_at (loc, "case label not within a switch statement");
13528 : : else
13529 : 1 : error_at (loc, "%<default%> label not within a switch statement");
13530 : 3 : return NULL_TREE;
13531 : : }
13532 : :
13533 : 1029160 : if (c_check_switch_jump_warnings (c_switch_stack->bindings,
13534 : 1029160 : EXPR_LOCATION (c_switch_stack->switch_stmt),
13535 : : loc))
13536 : : return NULL_TREE;
13537 : :
13538 : 1029148 : label = c_add_case_label (loc, c_switch_stack->cases,
13539 : 1029148 : SWITCH_STMT_COND (c_switch_stack->switch_stmt),
13540 : : low_value, high_value, attrs);
13541 : 1029148 : if (label == error_mark_node)
13542 : 144 : label = NULL_TREE;
13543 : : return label;
13544 : : }
13545 : :
13546 : : /* Finish the switch statement. TYPE is the original type of the
13547 : : controlling expression of the switch, or NULL_TREE. */
13548 : :
13549 : : void
13550 : 37141 : c_finish_switch (tree body, tree type)
13551 : : {
13552 : 37141 : struct c_switch *cs = c_switch_stack;
13553 : 37141 : location_t switch_location;
13554 : :
13555 : 37141 : SWITCH_STMT_BODY (cs->switch_stmt) = body;
13556 : :
13557 : : /* Emit warnings as needed. */
13558 : 37141 : switch_location = EXPR_LOCATION (cs->switch_stmt);
13559 : 43261 : c_do_switch_warnings (cs->cases, switch_location,
13560 : 6120 : type ? type : SWITCH_STMT_TYPE (cs->switch_stmt),
13561 : 37141 : SWITCH_STMT_COND (cs->switch_stmt), cs->bool_cond_p);
13562 : 37141 : if (c_switch_covers_all_cases_p (cs->cases,
13563 : 37141 : SWITCH_STMT_TYPE (cs->switch_stmt)))
13564 : 33249 : SWITCH_STMT_ALL_CASES_P (cs->switch_stmt) = 1;
13565 : 37141 : SWITCH_STMT_NO_BREAK_P (cs->switch_stmt) = !cs->break_stmt_seen_p;
13566 : :
13567 : : /* Pop the stack. */
13568 : 37141 : c_switch_stack = cs->next;
13569 : 37141 : splay_tree_delete (cs->cases);
13570 : 37141 : c_release_switch_bindings (cs->bindings);
13571 : 37141 : XDELETE (cs);
13572 : 37141 : }
13573 : :
13574 : : /* Emit an if statement. IF_LOCUS is the location of the 'if'. COND,
13575 : : THEN_BLOCK and ELSE_BLOCK are expressions to be used; ELSE_BLOCK
13576 : : may be null. */
13577 : :
13578 : : void
13579 : 1265272 : c_finish_if_stmt (location_t if_locus, tree cond, tree then_block,
13580 : : tree else_block)
13581 : : {
13582 : 1265272 : tree stmt;
13583 : :
13584 : 1265272 : stmt = build3 (COND_EXPR, void_type_node, cond, then_block, else_block);
13585 : 1265272 : SET_EXPR_LOCATION (stmt, if_locus);
13586 : 1265272 : add_stmt (stmt);
13587 : 1265272 : }
13588 : :
13589 : : tree
13590 : 186247 : c_finish_bc_stmt (location_t loc, tree label, bool is_break, tree name)
13591 : : {
13592 : : /* In switch statements break is sometimes stylistically used after
13593 : : a return statement. This can lead to spurious warnings about
13594 : : control reaching the end of a non-void function when it is
13595 : : inlined. Note that we are calling block_may_fallthru with
13596 : : language specific tree nodes; this works because
13597 : : block_may_fallthru returns true when given something it does not
13598 : : understand. */
13599 : 186247 : bool skip = !block_may_fallthru (cur_stmt_list);
13600 : :
13601 : 186247 : if (is_break)
13602 : 173232 : switch (in_statement & ~IN_NAMED_STMT)
13603 : : {
13604 : 9 : case 0:
13605 : 9 : error_at (loc, "break statement not within loop or switch");
13606 : 9 : return NULL_TREE;
13607 : 4 : case IN_OMP_BLOCK:
13608 : 4 : error_at (loc, "invalid exit from OpenMP structured block");
13609 : 4 : return NULL_TREE;
13610 : 12 : case IN_OMP_FOR:
13611 : 12 : error_at (loc, "break statement used with OpenMP for loop");
13612 : 12 : return NULL_TREE;
13613 : : case IN_ITERATION_STMT:
13614 : : case IN_OBJC_FOREACH:
13615 : : break;
13616 : 157751 : default:
13617 : 157751 : gcc_assert (in_statement & IN_SWITCH_STMT);
13618 : 157751 : c_switch_stack->break_stmt_seen_p = true;
13619 : 157751 : break;
13620 : : }
13621 : : else
13622 : 13015 : switch (in_statement & ~(IN_SWITCH_STMT | IN_NAMED_STMT))
13623 : : {
13624 : 7 : case 0:
13625 : 7 : error_at (loc, "continue statement not within a loop");
13626 : 7 : return NULL_TREE;
13627 : 4 : case IN_OMP_BLOCK:
13628 : 4 : error_at (loc, "invalid exit from OpenMP structured block");
13629 : 4 : return NULL_TREE;
13630 : : case IN_ITERATION_STMT:
13631 : : case IN_OMP_FOR:
13632 : : case IN_OBJC_FOREACH:
13633 : : break;
13634 : 0 : default:
13635 : 0 : gcc_unreachable ();
13636 : : }
13637 : :
13638 : 186211 : if (skip)
13639 : : return NULL_TREE;
13640 : 185761 : else if ((in_statement & IN_OBJC_FOREACH)
13641 : 0 : && !(is_break && (in_statement & IN_SWITCH_STMT))
13642 : 0 : && name == NULL_TREE)
13643 : : {
13644 : : /* The foreach expander produces low-level code using gotos instead
13645 : : of a structured loop construct. */
13646 : 0 : gcc_assert (label);
13647 : 0 : return add_stmt (build_stmt (loc, GOTO_EXPR, label));
13648 : : }
13649 : 185858 : else if (name && C_DECL_LOOP_NAME (name) && C_DECL_SWITCH_NAME (name))
13650 : : {
13651 : 0 : label = DECL_CHAIN (name);
13652 : 0 : if (!is_break)
13653 : 0 : label = DECL_CHAIN (label);
13654 : : /* Foreach expander from some outer level. */
13655 : 0 : return add_stmt (build_stmt (loc, GOTO_EXPR, label));
13656 : : }
13657 : 198765 : return add_stmt (build_stmt (loc, is_break ? BREAK_STMT : CONTINUE_STMT,
13658 : 185761 : name));
13659 : : }
13660 : :
13661 : : /* A helper routine for c_process_expr_stmt and c_finish_stmt_expr. */
13662 : :
13663 : : static void
13664 : 6336201 : emit_side_effect_warnings (location_t loc, tree expr)
13665 : : {
13666 : 6336201 : maybe_warn_nodiscard (loc, expr);
13667 : 6336201 : if (!warn_unused_value)
13668 : : return;
13669 : 1293629 : if (expr == error_mark_node)
13670 : : ;
13671 : 1293554 : else if (!TREE_SIDE_EFFECTS (expr))
13672 : : {
13673 : 6416 : if (!VOID_TYPE_P (TREE_TYPE (expr))
13674 : 6416 : && !warning_suppressed_p (expr, OPT_Wunused_value))
13675 : 28 : warning_at (loc, OPT_Wunused_value, "statement with no effect");
13676 : : }
13677 : 1287138 : else if (TREE_CODE (expr) == COMPOUND_EXPR)
13678 : : {
13679 : : tree r = expr;
13680 : : location_t cloc = loc;
13681 : 11991 : while (TREE_CODE (r) == COMPOUND_EXPR)
13682 : : {
13683 : 6011 : if (EXPR_HAS_LOCATION (r))
13684 : 5481 : cloc = EXPR_LOCATION (r);
13685 : 6011 : r = TREE_OPERAND (r, 1);
13686 : : }
13687 : 5980 : if (!TREE_SIDE_EFFECTS (r)
13688 : 33 : && !VOID_TYPE_P (TREE_TYPE (r))
13689 : 24 : && !CONVERT_EXPR_P (r)
13690 : 24 : && !warning_suppressed_p (r, OPT_Wunused_value)
13691 : 5992 : && !warning_suppressed_p (expr, OPT_Wunused_value))
13692 : 8 : warning_at (cloc, OPT_Wunused_value,
13693 : : "right-hand operand of comma expression has no effect");
13694 : : }
13695 : : else
13696 : 1281158 : warn_if_unused_value (expr, loc);
13697 : : }
13698 : :
13699 : : /* Process an expression as if it were a complete statement. Emit
13700 : : diagnostics, but do not call ADD_STMT. LOC is the location of the
13701 : : statement. */
13702 : :
13703 : : tree
13704 : 6212877 : c_process_expr_stmt (location_t loc, tree expr)
13705 : : {
13706 : 6212877 : tree exprv;
13707 : :
13708 : 6212877 : if (!expr)
13709 : : return NULL_TREE;
13710 : :
13711 : 6208628 : expr = c_fully_fold (expr, false, NULL);
13712 : :
13713 : 6208628 : if (warn_sequence_point)
13714 : 1289453 : verify_sequence_points (expr);
13715 : :
13716 : 6208628 : if (TREE_TYPE (expr) != error_mark_node
13717 : 6206076 : && !COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (expr))
13718 : 6208628 : && TREE_CODE (TREE_TYPE (expr)) != ARRAY_TYPE)
13719 : 0 : error_at (loc, "expression statement has incomplete type");
13720 : :
13721 : : /* If we're not processing a statement expression, warn about unused values.
13722 : : Warnings for statement expressions will be emitted later, once we figure
13723 : : out which is the result. */
13724 : 6208628 : if (!STATEMENT_LIST_STMT_EXPR (cur_stmt_list)
13725 : 6208628 : && (warn_unused_value || warn_unused_result))
13726 : 6122432 : emit_side_effect_warnings (EXPR_LOC_OR_LOC (expr, loc), expr);
13727 : :
13728 : : exprv = expr;
13729 : 6247143 : while (TREE_CODE (exprv) == COMPOUND_EXPR)
13730 : 38516 : exprv = TREE_OPERAND (exprv, 1);
13731 : 6219676 : while (CONVERT_EXPR_P (exprv))
13732 : 11049 : exprv = TREE_OPERAND (exprv, 0);
13733 : 6208627 : if (DECL_P (exprv)
13734 : 6209188 : || handled_component_p (exprv)
13735 : 12397805 : || TREE_CODE (exprv) == ADDR_EXPR)
13736 : 20010 : mark_exp_read (exprv);
13737 : :
13738 : : /* If the expression is not of a type to which we cannot assign a line
13739 : : number, wrap the thing in a no-op NOP_EXPR. */
13740 : 6208627 : if (DECL_P (expr) || CONSTANT_CLASS_P (expr))
13741 : : {
13742 : 14799 : expr = build1 (NOP_EXPR, TREE_TYPE (expr), expr);
13743 : 14799 : SET_EXPR_LOCATION (expr, loc);
13744 : : }
13745 : :
13746 : : return expr;
13747 : : }
13748 : :
13749 : : /* Emit an expression as a statement. LOC is the location of the
13750 : : expression. */
13751 : :
13752 : : tree
13753 : 5913626 : c_finish_expr_stmt (location_t loc, tree expr)
13754 : : {
13755 : 5913626 : if (expr)
13756 : 5901295 : return add_stmt (c_process_expr_stmt (loc, expr));
13757 : : else
13758 : : return NULL;
13759 : : }
13760 : :
13761 : : /* Do the opposite and emit a statement as an expression. To begin,
13762 : : create a new binding level and return it. */
13763 : :
13764 : : tree
13765 : 34769 : c_begin_stmt_expr (void)
13766 : : {
13767 : 34769 : tree ret;
13768 : :
13769 : : /* We must force a BLOCK for this level so that, if it is not expanded
13770 : : later, there is a way to turn off the entire subtree of blocks that
13771 : : are contained in it. */
13772 : 34769 : keep_next_level ();
13773 : 34769 : ret = c_begin_compound_stmt (true);
13774 : :
13775 : 34769 : c_bindings_start_stmt_expr (c_switch_stack == NULL
13776 : : ? NULL
13777 : : : c_switch_stack->bindings);
13778 : :
13779 : : /* Mark the current statement list as belonging to a statement list. */
13780 : 34769 : STATEMENT_LIST_STMT_EXPR (ret) = 1;
13781 : :
13782 : 34769 : return ret;
13783 : : }
13784 : :
13785 : : /* LOC is the location of the compound statement to which this body
13786 : : belongs. */
13787 : :
13788 : : tree
13789 : 34769 : c_finish_stmt_expr (location_t loc, tree body)
13790 : : {
13791 : 34769 : tree last, type, tmp, val;
13792 : 34769 : tree *last_p;
13793 : :
13794 : 34769 : body = c_end_compound_stmt (loc, body, true);
13795 : :
13796 : 34769 : c_bindings_end_stmt_expr (c_switch_stack == NULL
13797 : : ? NULL
13798 : : : c_switch_stack->bindings);
13799 : :
13800 : : /* Locate the last statement in BODY. See c_end_compound_stmt
13801 : : about always returning a BIND_EXPR. */
13802 : 34769 : last_p = &BIND_EXPR_BODY (body);
13803 : 34769 : last = BIND_EXPR_BODY (body);
13804 : :
13805 : 34769 : continue_searching:
13806 : 34769 : if (TREE_CODE (last) == STATEMENT_LIST)
13807 : : {
13808 : 25977 : tree_stmt_iterator l = tsi_last (last);
13809 : :
13810 : 25983 : while (!tsi_end_p (l) && TREE_CODE (tsi_stmt (l)) == DEBUG_BEGIN_STMT)
13811 : 6 : tsi_prev (&l);
13812 : :
13813 : : /* This can happen with degenerate cases like ({ }). No value. */
13814 : 25977 : if (tsi_end_p (l))
13815 : 389 : return body;
13816 : :
13817 : : /* If we're supposed to generate side effects warnings, process
13818 : : all of the statements except the last. */
13819 : 25588 : if (warn_unused_value || warn_unused_result)
13820 : : {
13821 : 25588 : for (tree_stmt_iterator i = tsi_start (last);
13822 : 275426 : tsi_stmt (i) != tsi_stmt (l); tsi_next (&i))
13823 : : {
13824 : 249838 : location_t tloc;
13825 : 249838 : tree t = tsi_stmt (i);
13826 : :
13827 : 249838 : tloc = EXPR_HAS_LOCATION (t) ? EXPR_LOCATION (t) : loc;
13828 : 249838 : emit_side_effect_warnings (tloc, t);
13829 : : }
13830 : : }
13831 : 25588 : last_p = tsi_stmt_ptr (l);
13832 : 25588 : last = *last_p;
13833 : : }
13834 : :
13835 : : /* If the end of the list is exception related, then the list was split
13836 : : by a call to push_cleanup. Continue searching. */
13837 : 34380 : if (TREE_CODE (last) == TRY_FINALLY_EXPR
13838 : 34380 : || TREE_CODE (last) == TRY_CATCH_EXPR)
13839 : : {
13840 : 0 : last_p = &TREE_OPERAND (last, 0);
13841 : 0 : last = *last_p;
13842 : 0 : goto continue_searching;
13843 : : }
13844 : :
13845 : 34380 : if (last == error_mark_node)
13846 : : return last;
13847 : :
13848 : : /* In the case that the BIND_EXPR is not necessary, return the
13849 : : expression out from inside it. */
13850 : 34371 : if ((last == BIND_EXPR_BODY (body)
13851 : : /* Skip nested debug stmts. */
13852 : 25587 : || last == expr_first (BIND_EXPR_BODY (body)))
13853 : 45316 : && BIND_EXPR_VARS (body) == NULL)
13854 : : {
13855 : : /* Even if this looks constant, do not allow it in a constant
13856 : : expression. */
13857 : 10933 : last = c_wrap_maybe_const (last, true);
13858 : : /* Do not warn if the return value of a statement expression is
13859 : : unused. */
13860 : 10933 : suppress_warning (last, OPT_Wunused);
13861 : 10933 : return last;
13862 : : }
13863 : :
13864 : : /* Extract the type of said expression. */
13865 : 23438 : type = TREE_TYPE (last);
13866 : :
13867 : : /* If we're not returning a value at all, then the BIND_EXPR that
13868 : : we already have is a fine expression to return. */
13869 : 23438 : if (!type || VOID_TYPE_P (type))
13870 : : return body;
13871 : :
13872 : : /* Now that we've located the expression containing the value, it seems
13873 : : silly to make voidify_wrapper_expr repeat the process. Create a
13874 : : temporary of the appropriate type and stick it in a TARGET_EXPR. */
13875 : 18130 : tmp = create_tmp_var_raw (type);
13876 : :
13877 : : /* Unwrap a no-op NOP_EXPR as added by c_finish_expr_stmt. This avoids
13878 : : tree_expr_nonnegative_p giving up immediately. */
13879 : 18130 : val = last;
13880 : 18130 : if (TREE_CODE (val) == NOP_EXPR
13881 : 18130 : && TREE_TYPE (val) == TREE_TYPE (TREE_OPERAND (val, 0)))
13882 : 3756 : val = TREE_OPERAND (val, 0);
13883 : :
13884 : 18130 : *last_p = build2 (MODIFY_EXPR, void_type_node, tmp, val);
13885 : 18130 : SET_EXPR_LOCATION (*last_p, EXPR_LOCATION (last));
13886 : :
13887 : 18130 : {
13888 : 18130 : tree t = build4 (TARGET_EXPR, type, tmp, body, NULL_TREE, NULL_TREE);
13889 : 18130 : SET_EXPR_LOCATION (t, loc);
13890 : 18130 : return t;
13891 : : }
13892 : : }
13893 : :
13894 : : /* Begin and end compound statements. This is as simple as pushing
13895 : : and popping new statement lists from the tree. */
13896 : :
13897 : : tree
13898 : 40958369 : c_begin_compound_stmt (bool do_scope)
13899 : : {
13900 : 40958369 : tree stmt = push_stmt_list ();
13901 : 40958369 : if (do_scope)
13902 : 40862387 : push_scope ();
13903 : 40958369 : return stmt;
13904 : : }
13905 : :
13906 : : /* End a compound statement. STMT is the statement. LOC is the
13907 : : location of the compound statement-- this is usually the location
13908 : : of the opening brace. */
13909 : :
13910 : : tree
13911 : 40958368 : c_end_compound_stmt (location_t loc, tree stmt, bool do_scope)
13912 : : {
13913 : 40958368 : tree block = NULL;
13914 : :
13915 : 40958368 : if (do_scope)
13916 : : {
13917 : 40862386 : if (c_dialect_objc ())
13918 : 0 : objc_clear_super_receiver ();
13919 : 40862386 : block = pop_scope ();
13920 : : }
13921 : :
13922 : 40958368 : stmt = pop_stmt_list (stmt);
13923 : 40958368 : stmt = c_build_bind_expr (loc, block, stmt);
13924 : :
13925 : : /* If this compound statement is nested immediately inside a statement
13926 : : expression, then force a BIND_EXPR to be created. Otherwise we'll
13927 : : do the wrong thing for ({ { 1; } }) or ({ 1; { } }). In particular,
13928 : : STATEMENT_LISTs merge, and thus we can lose track of what statement
13929 : : was really last. */
13930 : 81916736 : if (building_stmt_list_p ()
13931 : 40958283 : && STATEMENT_LIST_STMT_EXPR (cur_stmt_list)
13932 : 41080934 : && TREE_CODE (stmt) != BIND_EXPR)
13933 : : {
13934 : 120826 : stmt = build3 (BIND_EXPR, void_type_node, NULL, stmt, NULL);
13935 : 120826 : TREE_SIDE_EFFECTS (stmt) = 1;
13936 : 120826 : SET_EXPR_LOCATION (stmt, loc);
13937 : : }
13938 : :
13939 : 40958368 : return stmt;
13940 : : }
13941 : :
13942 : : /* Queue a cleanup. CLEANUP is an expression/statement to be executed
13943 : : when the current scope is exited. EH_ONLY is true when this is not
13944 : : meant to apply to normal control flow transfer. */
13945 : :
13946 : : void
13947 : 95 : push_cleanup (tree decl, tree cleanup, bool eh_only)
13948 : : {
13949 : 95 : enum tree_code code;
13950 : 95 : tree stmt, list;
13951 : 95 : bool stmt_expr;
13952 : :
13953 : 95 : code = eh_only ? TRY_CATCH_EXPR : TRY_FINALLY_EXPR;
13954 : 95 : stmt = build_stmt (DECL_SOURCE_LOCATION (decl), code, NULL, cleanup);
13955 : 95 : add_stmt (stmt);
13956 : 95 : stmt_expr = STATEMENT_LIST_STMT_EXPR (cur_stmt_list);
13957 : 95 : list = push_stmt_list ();
13958 : 95 : TREE_OPERAND (stmt, 0) = list;
13959 : 95 : STATEMENT_LIST_STMT_EXPR (list) = stmt_expr;
13960 : 95 : }
13961 : :
13962 : : /* Build a vector comparison of ARG0 and ARG1 using CODE opcode
13963 : : into a value of TYPE type. Comparison is done via VEC_COND_EXPR. */
13964 : :
13965 : : static tree
13966 : 100639 : build_vec_cmp (tree_code code, tree type,
13967 : : tree arg0, tree arg1)
13968 : : {
13969 : 100639 : tree zero_vec = build_zero_cst (type);
13970 : 100639 : tree minus_one_vec = build_minus_one_cst (type);
13971 : 100639 : tree cmp_type = truth_type_for (TREE_TYPE (arg0));
13972 : 100639 : tree cmp = build2 (code, cmp_type, arg0, arg1);
13973 : 100639 : return build3 (VEC_COND_EXPR, type, cmp, minus_one_vec, zero_vec);
13974 : : }
13975 : :
13976 : : /* Possibly warn about an address of OP never being NULL in a comparison
13977 : : operation CODE involving null. */
13978 : :
13979 : : static void
13980 : 50990 : maybe_warn_for_null_address (location_t loc, tree op, tree_code code)
13981 : : {
13982 : : /* Prevent warnings issued for macro expansion. */
13983 : 50990 : if (!warn_address
13984 : 30175 : || warning_suppressed_p (op, OPT_Waddress)
13985 : 80825 : || from_macro_expansion_at (loc))
13986 : 23911 : return;
13987 : :
13988 : 27079 : if (TREE_CODE (op) == NOP_EXPR)
13989 : : {
13990 : : /* Allow casts to intptr_t to suppress the warning. */
13991 : 1133 : tree type = TREE_TYPE (op);
13992 : 1133 : if (TREE_CODE (type) == INTEGER_TYPE)
13993 : : return;
13994 : 1133 : op = TREE_OPERAND (op, 0);
13995 : : }
13996 : :
13997 : 27079 : if (TREE_CODE (op) == POINTER_PLUS_EXPR)
13998 : : {
13999 : : /* Allow a cast to void* to suppress the warning. */
14000 : 24 : tree type = TREE_TYPE (TREE_TYPE (op));
14001 : 24 : if (VOID_TYPE_P (type))
14002 : : return;
14003 : :
14004 : : /* Adding any value to a null pointer, including zero, is undefined
14005 : : in C. This includes the expression &p[0] where p is the null
14006 : : pointer, although &p[0] will have been folded to p by this point
14007 : : and so not diagnosed. */
14008 : 24 : if (code == EQ_EXPR)
14009 : 22 : warning_at (loc, OPT_Waddress,
14010 : : "the comparison will always evaluate as %<false%> "
14011 : : "for the pointer operand in %qE must not be NULL",
14012 : : op);
14013 : : else
14014 : 2 : warning_at (loc, OPT_Waddress,
14015 : : "the comparison will always evaluate as %<true%> "
14016 : : "for the pointer operand in %qE must not be NULL",
14017 : : op);
14018 : :
14019 : 24 : return;
14020 : : }
14021 : :
14022 : 27055 : if (TREE_CODE (op) != ADDR_EXPR)
14023 : : return;
14024 : :
14025 : 254 : op = TREE_OPERAND (op, 0);
14026 : :
14027 : 254 : if (TREE_CODE (op) == IMAGPART_EXPR
14028 : 254 : || TREE_CODE (op) == REALPART_EXPR)
14029 : : {
14030 : : /* The address of either complex part may not be null. */
14031 : 14 : if (code == EQ_EXPR)
14032 : 9 : warning_at (loc, OPT_Waddress,
14033 : : "the comparison will always evaluate as %<false%> "
14034 : : "for the address of %qE will never be NULL",
14035 : : op);
14036 : : else
14037 : 5 : warning_at (loc, OPT_Waddress,
14038 : : "the comparison will always evaluate as %<true%> "
14039 : : "for the address of %qE will never be NULL",
14040 : : op);
14041 : 14 : return;
14042 : : }
14043 : :
14044 : : /* Set to true in the loop below if OP dereferences is operand.
14045 : : In such a case the ultimate target need not be a decl for
14046 : : the null [in]equality test to be constant. */
14047 : : bool deref = false;
14048 : :
14049 : : /* Get the outermost array or object, or member. */
14050 : 294 : while (handled_component_p (op))
14051 : : {
14052 : 72 : if (TREE_CODE (op) == COMPONENT_REF)
14053 : : {
14054 : : /* Get the member (its address is never null). */
14055 : 18 : op = TREE_OPERAND (op, 1);
14056 : 18 : break;
14057 : : }
14058 : :
14059 : : /* Get the outer array/object to refer to in the warning. */
14060 : 54 : op = TREE_OPERAND (op, 0);
14061 : 54 : deref = true;
14062 : : }
14063 : :
14064 : 192 : if ((!deref && !decl_with_nonnull_addr_p (op))
14065 : 371 : || from_macro_expansion_at (loc))
14066 : 109 : return;
14067 : :
14068 : 131 : bool w;
14069 : 131 : if (code == EQ_EXPR)
14070 : 93 : w = warning_at (loc, OPT_Waddress,
14071 : : "the comparison will always evaluate as %<false%> "
14072 : : "for the address of %qE will never be NULL",
14073 : : op);
14074 : : else
14075 : 38 : w = warning_at (loc, OPT_Waddress,
14076 : : "the comparison will always evaluate as %<true%> "
14077 : : "for the address of %qE will never be NULL",
14078 : : op);
14079 : :
14080 : 131 : if (w && DECL_P (op))
14081 : 120 : inform (DECL_SOURCE_LOCATION (op), "%qD declared here", op);
14082 : : }
14083 : :
14084 : : /* Build a binary-operation expression without default conversions.
14085 : : CODE is the kind of expression to build.
14086 : : LOCATION is the operator's location.
14087 : : This function differs from `build' in several ways:
14088 : : the data type of the result is computed and recorded in it,
14089 : : warnings are generated if arg data types are invalid,
14090 : : special handling for addition and subtraction of pointers is known,
14091 : : and some optimization is done (operations on narrow ints
14092 : : are done in the narrower type when that gives the same result).
14093 : : Constant folding is also done before the result is returned.
14094 : :
14095 : : Note that the operands will never have enumeral types, or function
14096 : : or array types, because either they will have the default conversions
14097 : : performed or they have both just been converted to some other type in which
14098 : : the arithmetic is to be done. */
14099 : :
14100 : : tree
14101 : 16673045 : build_binary_op (location_t location, enum tree_code code,
14102 : : tree orig_op0, tree orig_op1, bool convert_p)
14103 : : {
14104 : 16673045 : tree type0, type1, orig_type0, orig_type1;
14105 : 16673045 : tree eptype;
14106 : 16673045 : enum tree_code code0, code1;
14107 : 16673045 : tree op0, op1;
14108 : 16673045 : tree ret = error_mark_node;
14109 : 16673045 : const char *invalid_op_diag;
14110 : 16673045 : bool op0_int_operands, op1_int_operands;
14111 : 16673045 : bool int_const, int_const_or_overflow, int_operands;
14112 : :
14113 : : /* Expression code to give to the expression when it is built.
14114 : : Normally this is CODE, which is what the caller asked for,
14115 : : but in some special cases we change it. */
14116 : 16673045 : enum tree_code resultcode = code;
14117 : :
14118 : : /* Data type in which the computation is to be performed.
14119 : : In the simplest cases this is the common type of the arguments. */
14120 : 16673045 : tree result_type = NULL;
14121 : :
14122 : : /* When the computation is in excess precision, the type of the
14123 : : final EXCESS_PRECISION_EXPR. */
14124 : 16673045 : tree semantic_result_type = NULL;
14125 : :
14126 : : /* Nonzero means operands have already been type-converted
14127 : : in whatever way is necessary.
14128 : : Zero means they need to be converted to RESULT_TYPE. */
14129 : 16673045 : int converted = 0;
14130 : :
14131 : : /* Nonzero means create the expression with this type, rather than
14132 : : RESULT_TYPE. */
14133 : 16673045 : tree build_type = NULL_TREE;
14134 : :
14135 : : /* Nonzero means after finally constructing the expression
14136 : : convert it to this type. */
14137 : 16673045 : tree final_type = NULL_TREE;
14138 : :
14139 : : /* Nonzero if this is an operation like MIN or MAX which can
14140 : : safely be computed in short if both args are promoted shorts.
14141 : : Also implies COMMON.
14142 : : -1 indicates a bitwise operation; this makes a difference
14143 : : in the exact conditions for when it is safe to do the operation
14144 : : in a narrower mode. */
14145 : 16673045 : int shorten = 0;
14146 : :
14147 : : /* Nonzero if this is a comparison operation;
14148 : : if both args are promoted shorts, compare the original shorts.
14149 : : Also implies COMMON. */
14150 : 16673045 : int short_compare = 0;
14151 : :
14152 : : /* Nonzero if this is a right-shift operation, which can be computed on the
14153 : : original short and then promoted if the operand is a promoted short. */
14154 : 16673045 : int short_shift = 0;
14155 : :
14156 : : /* Nonzero means set RESULT_TYPE to the common type of the args. */
14157 : 16673045 : int common = 0;
14158 : :
14159 : : /* True means types are compatible as far as ObjC is concerned. */
14160 : 16673045 : bool objc_ok;
14161 : :
14162 : : /* True means this is an arithmetic operation that may need excess
14163 : : precision. */
14164 : 16673045 : bool may_need_excess_precision;
14165 : :
14166 : : /* True means this is a boolean operation that converts both its
14167 : : operands to truth-values. */
14168 : 16673045 : bool boolean_op = false;
14169 : :
14170 : : /* Remember whether we're doing / or %. */
14171 : 16673045 : bool doing_div_or_mod = false;
14172 : :
14173 : : /* Remember whether we're doing << or >>. */
14174 : 16673045 : bool doing_shift = false;
14175 : :
14176 : : /* Tree holding instrumentation expression. */
14177 : 16673045 : tree instrument_expr = NULL;
14178 : :
14179 : 16673045 : if (location == UNKNOWN_LOCATION)
14180 : 79 : location = input_location;
14181 : :
14182 : 16673045 : op0 = orig_op0;
14183 : 16673045 : op1 = orig_op1;
14184 : :
14185 : 16673045 : op0_int_operands = EXPR_INT_CONST_OPERANDS (orig_op0);
14186 : 8017646 : if (op0_int_operands)
14187 : 8017646 : op0 = remove_c_maybe_const_expr (op0);
14188 : 16673045 : op1_int_operands = EXPR_INT_CONST_OPERANDS (orig_op1);
14189 : 11267129 : if (op1_int_operands)
14190 : 11267129 : op1 = remove_c_maybe_const_expr (op1);
14191 : 27940174 : int_operands = (op0_int_operands && op1_int_operands);
14192 : 11267129 : if (int_operands)
14193 : : {
14194 : 15683077 : int_const_or_overflow = (TREE_CODE (orig_op0) == INTEGER_CST
14195 : 7856705 : && TREE_CODE (orig_op1) == INTEGER_CST);
14196 : 7826372 : int_const = (int_const_or_overflow
14197 : 7826372 : && !TREE_OVERFLOW (orig_op0)
14198 : 7826303 : && !TREE_OVERFLOW (orig_op1));
14199 : : }
14200 : : else
14201 : : int_const = int_const_or_overflow = false;
14202 : :
14203 : : /* Do not apply default conversion in mixed vector/scalar expression. */
14204 : 16673045 : if (convert_p
14205 : 16673045 : && VECTOR_TYPE_P (TREE_TYPE (op0)) == VECTOR_TYPE_P (TREE_TYPE (op1)))
14206 : : {
14207 : 10078959 : op0 = default_conversion (op0);
14208 : 10078959 : op1 = default_conversion (op1);
14209 : : }
14210 : :
14211 : 16673045 : orig_type0 = type0 = TREE_TYPE (op0);
14212 : :
14213 : 16673045 : orig_type1 = type1 = TREE_TYPE (op1);
14214 : :
14215 : : /* The expression codes of the data types of the arguments tell us
14216 : : whether the arguments are integers, floating, pointers, etc. */
14217 : 16673045 : code0 = TREE_CODE (type0);
14218 : 16673045 : code1 = TREE_CODE (type1);
14219 : :
14220 : : /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
14221 : 16673047 : STRIP_TYPE_NOPS (op0);
14222 : 16673048 : STRIP_TYPE_NOPS (op1);
14223 : :
14224 : : /* If an error was already reported for one of the arguments,
14225 : : avoid reporting another error. */
14226 : :
14227 : 16673045 : if (code0 == ERROR_MARK || code1 == ERROR_MARK)
14228 : 710 : return error_mark_node;
14229 : :
14230 : 16672335 : if (code0 == POINTER_TYPE
14231 : 16672335 : && reject_gcc_builtin (op0, EXPR_LOCATION (orig_op0)))
14232 : 11 : return error_mark_node;
14233 : :
14234 : 16672324 : if (code1 == POINTER_TYPE
14235 : 16672324 : && reject_gcc_builtin (op1, EXPR_LOCATION (orig_op1)))
14236 : 11 : return error_mark_node;
14237 : :
14238 : 33344626 : if ((invalid_op_diag
14239 : 16672313 : = targetm.invalid_binary_op (code, type0, type1)))
14240 : : {
14241 : 0 : error_at (location, invalid_op_diag);
14242 : 0 : return error_mark_node;
14243 : : }
14244 : :
14245 : 16672313 : switch (code)
14246 : : {
14247 : : case PLUS_EXPR:
14248 : : case MINUS_EXPR:
14249 : : case MULT_EXPR:
14250 : : case TRUNC_DIV_EXPR:
14251 : : case CEIL_DIV_EXPR:
14252 : : case FLOOR_DIV_EXPR:
14253 : : case ROUND_DIV_EXPR:
14254 : : case EXACT_DIV_EXPR:
14255 : : may_need_excess_precision = true;
14256 : : break;
14257 : :
14258 : 2720854 : case EQ_EXPR:
14259 : 2720854 : case NE_EXPR:
14260 : 2720854 : case LE_EXPR:
14261 : 2720854 : case GE_EXPR:
14262 : 2720854 : case LT_EXPR:
14263 : 2720854 : case GT_EXPR:
14264 : : /* Excess precision for implicit conversions of integers to
14265 : : floating point in C11 and later. */
14266 : 2720854 : may_need_excess_precision = (flag_isoc11
14267 : 2720854 : && (ANY_INTEGRAL_TYPE_P (type0)
14268 : 484219 : || ANY_INTEGRAL_TYPE_P (type1)));
14269 : : break;
14270 : :
14271 : : default:
14272 : 16672313 : may_need_excess_precision = false;
14273 : : break;
14274 : : }
14275 : 16672313 : if (TREE_CODE (op0) == EXCESS_PRECISION_EXPR)
14276 : : {
14277 : 184 : op0 = TREE_OPERAND (op0, 0);
14278 : 184 : type0 = TREE_TYPE (op0);
14279 : : }
14280 : 16672129 : else if (may_need_excess_precision
14281 : 16672129 : && (eptype = excess_precision_type (type0)) != NULL_TREE)
14282 : : {
14283 : 771 : type0 = eptype;
14284 : 771 : op0 = convert (eptype, op0);
14285 : : }
14286 : 16672313 : if (TREE_CODE (op1) == EXCESS_PRECISION_EXPR)
14287 : : {
14288 : 887 : op1 = TREE_OPERAND (op1, 0);
14289 : 887 : type1 = TREE_TYPE (op1);
14290 : : }
14291 : 16671426 : else if (may_need_excess_precision
14292 : 16671426 : && (eptype = excess_precision_type (type1)) != NULL_TREE)
14293 : : {
14294 : 592 : type1 = eptype;
14295 : 592 : op1 = convert (eptype, op1);
14296 : : }
14297 : :
14298 : 16672313 : objc_ok = objc_compare_types (type0, type1, -3, NULL_TREE);
14299 : :
14300 : : /* In case when one of the operands of the binary operation is
14301 : : a vector and another is a scalar -- convert scalar to vector. */
14302 : 18246360 : if ((gnu_vector_type_p (type0) && code1 != VECTOR_TYPE)
14303 : 18244524 : || (gnu_vector_type_p (type1) && code0 != VECTOR_TYPE))
14304 : : {
14305 : 2439 : enum stv_conv convert_flag = scalar_to_vector (location, code, orig_op0,
14306 : : orig_op1, true);
14307 : :
14308 : 2439 : switch (convert_flag)
14309 : : {
14310 : 12 : case stv_error:
14311 : 12 : return error_mark_node;
14312 : 590 : case stv_firstarg:
14313 : 590 : {
14314 : 590 : bool maybe_const = true;
14315 : 590 : tree sc;
14316 : 590 : sc = c_fully_fold (op0, false, &maybe_const);
14317 : 590 : sc = save_expr (sc);
14318 : 590 : sc = convert (TREE_TYPE (type1), sc);
14319 : 590 : op0 = build_vector_from_val (type1, sc);
14320 : 590 : if (!maybe_const)
14321 : 93 : op0 = c_wrap_maybe_const (op0, true);
14322 : 590 : orig_type0 = type0 = TREE_TYPE (op0);
14323 : 590 : code0 = TREE_CODE (type0);
14324 : 590 : converted = 1;
14325 : 590 : break;
14326 : : }
14327 : 1014 : case stv_secondarg:
14328 : 1014 : {
14329 : 1014 : bool maybe_const = true;
14330 : 1014 : tree sc;
14331 : 1014 : sc = c_fully_fold (op1, false, &maybe_const);
14332 : 1014 : sc = save_expr (sc);
14333 : 1014 : sc = convert (TREE_TYPE (type0), sc);
14334 : 1014 : op1 = build_vector_from_val (type0, sc);
14335 : 1014 : if (!maybe_const)
14336 : 36 : op1 = c_wrap_maybe_const (op1, true);
14337 : 1014 : orig_type1 = type1 = TREE_TYPE (op1);
14338 : 1014 : code1 = TREE_CODE (type1);
14339 : 1014 : converted = 1;
14340 : 1014 : break;
14341 : : }
14342 : : default:
14343 : : break;
14344 : : }
14345 : : }
14346 : :
14347 : 16672301 : switch (code)
14348 : : {
14349 : 8512207 : case PLUS_EXPR:
14350 : : /* Handle the pointer + int case. */
14351 : 8512207 : if (code0 == POINTER_TYPE
14352 : 1243029 : && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
14353 : : {
14354 : 1243023 : ret = pointer_int_sum (location, PLUS_EXPR, op0, op1);
14355 : 1243023 : goto return_build_binary_op;
14356 : : }
14357 : 7269184 : else if (code1 == POINTER_TYPE
14358 : 1531 : && (code0 == INTEGER_TYPE || code0 == BITINT_TYPE))
14359 : : {
14360 : 1525 : ret = pointer_int_sum (location, PLUS_EXPR, op1, op0);
14361 : 1525 : goto return_build_binary_op;
14362 : : }
14363 : : else
14364 : : common = 1;
14365 : : break;
14366 : :
14367 : 787993 : case MINUS_EXPR:
14368 : : /* Subtraction of two similar pointers.
14369 : : We must subtract them as integers, then divide by object size. */
14370 : 787993 : if (code0 == POINTER_TYPE && code1 == POINTER_TYPE
14371 : 787993 : && comp_target_types (location, type0, type1))
14372 : : {
14373 : 3618 : ret = pointer_diff (location, op0, op1, &instrument_expr);
14374 : 3618 : goto return_build_binary_op;
14375 : : }
14376 : : /* Handle pointer minus int. Just like pointer plus int. */
14377 : 784375 : else if (code0 == POINTER_TYPE
14378 : 16690 : && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
14379 : : {
14380 : 16678 : ret = pointer_int_sum (location, MINUS_EXPR, op0, op1);
14381 : 16678 : goto return_build_binary_op;
14382 : : }
14383 : : else
14384 : : common = 1;
14385 : : break;
14386 : :
14387 : : case MULT_EXPR:
14388 : : common = 1;
14389 : : break;
14390 : :
14391 : 272774 : case TRUNC_DIV_EXPR:
14392 : 272774 : case CEIL_DIV_EXPR:
14393 : 272774 : case FLOOR_DIV_EXPR:
14394 : 272774 : case ROUND_DIV_EXPR:
14395 : 272774 : case EXACT_DIV_EXPR:
14396 : 272774 : doing_div_or_mod = true;
14397 : 272774 : warn_for_div_by_zero (location, op1);
14398 : :
14399 : 272773 : if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
14400 : 49441 : || code0 == FIXED_POINT_TYPE || code0 == BITINT_TYPE
14401 : 47463 : || code0 == COMPLEX_TYPE
14402 : 45413 : || gnu_vector_type_p (type0))
14403 : 322213 : && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
14404 : 47015 : || code1 == FIXED_POINT_TYPE || code1 == BITINT_TYPE
14405 : 46876 : || code1 == COMPLEX_TYPE
14406 : 45415 : || gnu_vector_type_p (type1)))
14407 : : {
14408 : 272769 : enum tree_code tcode0 = code0, tcode1 = code1;
14409 : :
14410 : 272769 : if (code0 == COMPLEX_TYPE || code0 == VECTOR_TYPE)
14411 : 47462 : tcode0 = TREE_CODE (TREE_TYPE (TREE_TYPE (op0)));
14412 : 272769 : if (code1 == COMPLEX_TYPE || code1 == VECTOR_TYPE)
14413 : 46873 : tcode1 = TREE_CODE (TREE_TYPE (TREE_TYPE (op1)));
14414 : :
14415 : 272769 : if (!(((tcode0 == INTEGER_TYPE || tcode0 == BITINT_TYPE)
14416 : 203215 : && (tcode1 == INTEGER_TYPE || tcode1 == BITINT_TYPE))
14417 : 81583 : || (tcode0 == FIXED_POINT_TYPE && tcode1 == FIXED_POINT_TYPE)))
14418 : : resultcode = RDIV_EXPR;
14419 : : else
14420 : : /* Although it would be tempting to shorten always here, that
14421 : : loses on some targets, since the modulo instruction is
14422 : : undefined if the quotient can't be represented in the
14423 : : computation mode. We shorten only if unsigned or if
14424 : : dividing by something we know != -1. */
14425 : 191186 : shorten = may_shorten_divmod (op0, op1);
14426 : : common = 1;
14427 : : }
14428 : : break;
14429 : :
14430 : 1575777 : case BIT_AND_EXPR:
14431 : 1575777 : case BIT_IOR_EXPR:
14432 : 1575777 : case BIT_XOR_EXPR:
14433 : 1575777 : if ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE)
14434 : 1042314 : && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
14435 : : shorten = -1;
14436 : : /* Allow vector types which are not floating point types. */
14437 : 533499 : else if (gnu_vector_type_p (type0)
14438 : 533422 : && gnu_vector_type_p (type1)
14439 : 533422 : && !VECTOR_FLOAT_TYPE_P (type0)
14440 : 1066918 : && !VECTOR_FLOAT_TYPE_P (type1))
14441 : : common = 1;
14442 : : break;
14443 : :
14444 : 58300 : case TRUNC_MOD_EXPR:
14445 : 58300 : case FLOOR_MOD_EXPR:
14446 : 58300 : doing_div_or_mod = true;
14447 : 58300 : warn_for_div_by_zero (location, op1);
14448 : :
14449 : 58300 : if (gnu_vector_type_p (type0)
14450 : 297 : && gnu_vector_type_p (type1)
14451 : 297 : && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
14452 : 58597 : && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE)
14453 : : common = 1;
14454 : 58003 : else if ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE)
14455 : 58002 : && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
14456 : : {
14457 : : /* Although it would be tempting to shorten always here, that loses
14458 : : on some targets, since the modulo instruction is undefined if the
14459 : : quotient can't be represented in the computation mode. We shorten
14460 : : only if unsigned or if dividing by something we know != -1. */
14461 : 58002 : shorten = may_shorten_divmod (op0, op1);
14462 : 58002 : common = 1;
14463 : : }
14464 : : break;
14465 : :
14466 : 509233 : case TRUTH_ANDIF_EXPR:
14467 : 509233 : case TRUTH_ORIF_EXPR:
14468 : 509233 : case TRUTH_AND_EXPR:
14469 : 509233 : case TRUTH_OR_EXPR:
14470 : 509233 : case TRUTH_XOR_EXPR:
14471 : 509233 : if ((code0 == INTEGER_TYPE || code0 == POINTER_TYPE
14472 : 0 : || code0 == REAL_TYPE || code0 == COMPLEX_TYPE
14473 : 0 : || code0 == FIXED_POINT_TYPE || code0 == NULLPTR_TYPE
14474 : 0 : || code0 == BITINT_TYPE)
14475 : 509233 : && (code1 == INTEGER_TYPE || code1 == POINTER_TYPE
14476 : 159 : || code1 == REAL_TYPE || code1 == COMPLEX_TYPE
14477 : 20 : || code1 == FIXED_POINT_TYPE || code1 == NULLPTR_TYPE
14478 : 18 : || code1 == BITINT_TYPE))
14479 : : {
14480 : : /* Result of these operations is always an int,
14481 : : but that does not mean the operands should be
14482 : : converted to ints! */
14483 : 509233 : result_type = integer_type_node;
14484 : 509233 : if (op0_int_operands)
14485 : : {
14486 : 110805 : op0 = c_objc_common_truthvalue_conversion (location, orig_op0);
14487 : 110805 : op0 = remove_c_maybe_const_expr (op0);
14488 : : }
14489 : : else
14490 : 398428 : op0 = c_objc_common_truthvalue_conversion (location, op0);
14491 : 509233 : if (op1_int_operands)
14492 : : {
14493 : 72213 : op1 = c_objc_common_truthvalue_conversion (location, orig_op1);
14494 : 72213 : op1 = remove_c_maybe_const_expr (op1);
14495 : : }
14496 : : else
14497 : 437020 : op1 = c_objc_common_truthvalue_conversion (location, op1);
14498 : : converted = 1;
14499 : : boolean_op = true;
14500 : : }
14501 : 509233 : if (code == TRUTH_ANDIF_EXPR)
14502 : : {
14503 : 249354 : int_const_or_overflow = (int_operands
14504 : 64089 : && TREE_CODE (orig_op0) == INTEGER_CST
14505 : 249370 : && (op0 == truthvalue_false_node
14506 : 13806 : || TREE_CODE (orig_op1) == INTEGER_CST));
14507 : : int_const = (int_const_or_overflow
14508 : 64062 : && !TREE_OVERFLOW (orig_op0)
14509 : 64062 : && (op0 == truthvalue_false_node
14510 : 13790 : || !TREE_OVERFLOW (orig_op1)));
14511 : : }
14512 : 323941 : else if (code == TRUTH_ORIF_EXPR)
14513 : : {
14514 : 330606 : int_const_or_overflow = (int_operands
14515 : 6816 : && TREE_CODE (orig_op0) == INTEGER_CST
14516 : 330629 : && (op0 == truthvalue_true_node
14517 : 2133 : || TREE_CODE (orig_op1) == INTEGER_CST));
14518 : : int_const = (int_const_or_overflow
14519 : 6786 : && !TREE_OVERFLOW (orig_op0)
14520 : 6786 : && (op0 == truthvalue_true_node
14521 : 2110 : || !TREE_OVERFLOW (orig_op1)));
14522 : : }
14523 : : break;
14524 : :
14525 : : /* Shift operations: result has same type as first operand;
14526 : : always convert second operand to int.
14527 : : Also set SHORT_SHIFT if shifting rightward. */
14528 : :
14529 : 229868 : case RSHIFT_EXPR:
14530 : 229868 : if (gnu_vector_type_p (type0)
14531 : 796 : && gnu_vector_type_p (type1)
14532 : 258 : && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
14533 : 256 : && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE
14534 : 230124 : && known_eq (TYPE_VECTOR_SUBPARTS (type0),
14535 : : TYPE_VECTOR_SUBPARTS (type1)))
14536 : : {
14537 : : result_type = type0;
14538 : : converted = 1;
14539 : : }
14540 : 229614 : else if ((code0 == INTEGER_TYPE || code0 == FIXED_POINT_TYPE
14541 : 1070 : || code0 == BITINT_TYPE
14542 : 546 : || (gnu_vector_type_p (type0)
14543 : 542 : && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE))
14544 : 230677 : && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
14545 : : {
14546 : 229605 : doing_shift = true;
14547 : 229605 : if (TREE_CODE (op1) == INTEGER_CST)
14548 : : {
14549 : 200330 : if (tree_int_cst_sgn (op1) < 0)
14550 : : {
14551 : 269 : int_const = false;
14552 : 269 : if (c_inhibit_evaluation_warnings == 0)
14553 : 129 : warning_at (location, OPT_Wshift_count_negative,
14554 : : "right shift count is negative");
14555 : : }
14556 : 200061 : else if (code0 == VECTOR_TYPE)
14557 : : {
14558 : 454 : if (compare_tree_int (op1,
14559 : 454 : TYPE_PRECISION (TREE_TYPE (type0)))
14560 : : >= 0)
14561 : : {
14562 : 16 : int_const = false;
14563 : 16 : if (c_inhibit_evaluation_warnings == 0)
14564 : 16 : warning_at (location, OPT_Wshift_count_overflow,
14565 : : "right shift count >= width of vector element");
14566 : : }
14567 : : }
14568 : : else
14569 : : {
14570 : 199607 : if (!integer_zerop (op1))
14571 : 199249 : short_shift = 1;
14572 : :
14573 : 199607 : if (compare_tree_int (op1, TYPE_PRECISION (type0)) >= 0)
14574 : : {
14575 : 584 : int_const = false;
14576 : 584 : if (c_inhibit_evaluation_warnings == 0)
14577 : 50 : warning_at (location, OPT_Wshift_count_overflow,
14578 : : "right shift count >= width of type");
14579 : : }
14580 : : }
14581 : : }
14582 : :
14583 : : /* Use the type of the value to be shifted. */
14584 : : result_type = type0;
14585 : : /* Avoid converting op1 to result_type later. */
14586 : : converted = 1;
14587 : : }
14588 : : break;
14589 : :
14590 : 796631 : case LSHIFT_EXPR:
14591 : 796631 : if (gnu_vector_type_p (type0)
14592 : 595 : && gnu_vector_type_p (type1)
14593 : 316 : && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
14594 : 314 : && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE
14595 : 796944 : && known_eq (TYPE_VECTOR_SUBPARTS (type0),
14596 : : TYPE_VECTOR_SUBPARTS (type1)))
14597 : : {
14598 : : result_type = type0;
14599 : : converted = 1;
14600 : : }
14601 : 796320 : else if ((code0 == INTEGER_TYPE || code0 == FIXED_POINT_TYPE
14602 : 749 : || code0 == BITINT_TYPE
14603 : 290 : || (gnu_vector_type_p (type0)
14604 : 284 : && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE))
14605 : 797060 : && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
14606 : : {
14607 : 796306 : doing_shift = true;
14608 : 796306 : if (TREE_CODE (op0) == INTEGER_CST
14609 : 433130 : && tree_int_cst_sgn (op0) < 0
14610 : 797063 : && !TYPE_OVERFLOW_WRAPS (type0))
14611 : : {
14612 : : /* Don't reject a left shift of a negative value in a context
14613 : : where a constant expression is needed in C90. */
14614 : 720 : if (flag_isoc99)
14615 : 674 : int_const = false;
14616 : 720 : if (c_inhibit_evaluation_warnings == 0)
14617 : 720 : warning_at (location, OPT_Wshift_negative_value,
14618 : : "left shift of negative value");
14619 : : }
14620 : 796306 : if (TREE_CODE (op1) == INTEGER_CST)
14621 : : {
14622 : 724107 : if (tree_int_cst_sgn (op1) < 0)
14623 : : {
14624 : 313 : int_const = false;
14625 : 313 : if (c_inhibit_evaluation_warnings == 0)
14626 : 135 : warning_at (location, OPT_Wshift_count_negative,
14627 : : "left shift count is negative");
14628 : : }
14629 : 723794 : else if (code0 == VECTOR_TYPE)
14630 : : {
14631 : 215 : if (compare_tree_int (op1,
14632 : 215 : TYPE_PRECISION (TREE_TYPE (type0)))
14633 : : >= 0)
14634 : : {
14635 : 6 : int_const = false;
14636 : 6 : if (c_inhibit_evaluation_warnings == 0)
14637 : 6 : warning_at (location, OPT_Wshift_count_overflow,
14638 : : "left shift count >= width of vector element");
14639 : : }
14640 : : }
14641 : 723579 : else if (compare_tree_int (op1, TYPE_PRECISION (type0)) >= 0)
14642 : : {
14643 : 29731 : int_const = false;
14644 : 29731 : if (c_inhibit_evaluation_warnings == 0)
14645 : 111 : warning_at (location, OPT_Wshift_count_overflow,
14646 : : "left shift count >= width of type");
14647 : : }
14648 : 693848 : else if (TREE_CODE (op0) == INTEGER_CST
14649 : 359543 : && maybe_warn_shift_overflow (location, op0, op1)
14650 : 694476 : && flag_isoc99)
14651 : : int_const = false;
14652 : : }
14653 : :
14654 : : /* Use the type of the value to be shifted. */
14655 : : result_type = type0;
14656 : : /* Avoid converting op1 to result_type later. */
14657 : : converted = 1;
14658 : : }
14659 : : break;
14660 : :
14661 : 1729420 : case EQ_EXPR:
14662 : 1729420 : case NE_EXPR:
14663 : 1729420 : if (gnu_vector_type_p (type0) && gnu_vector_type_p (type1))
14664 : : {
14665 : 41731 : tree intt;
14666 : 41731 : if (!vector_types_compatible_elements_p (type0, type1))
14667 : : {
14668 : 4 : error_at (location, "comparing vectors with different "
14669 : : "element types");
14670 : 4 : return error_mark_node;
14671 : : }
14672 : :
14673 : 41727 : if (maybe_ne (TYPE_VECTOR_SUBPARTS (type0),
14674 : 83454 : TYPE_VECTOR_SUBPARTS (type1)))
14675 : : {
14676 : 1 : error_at (location, "comparing vectors with different "
14677 : : "number of elements");
14678 : 1 : return error_mark_node;
14679 : : }
14680 : :
14681 : : /* It's not precisely specified how the usual arithmetic
14682 : : conversions apply to the vector types. Here, we use
14683 : : the unsigned type if one of the operands is signed and
14684 : : the other one is unsigned. */
14685 : 41726 : if (TYPE_UNSIGNED (type0) != TYPE_UNSIGNED (type1))
14686 : : {
14687 : 4 : if (!TYPE_UNSIGNED (type0))
14688 : 4 : op0 = build1 (VIEW_CONVERT_EXPR, type1, op0);
14689 : : else
14690 : 0 : op1 = build1 (VIEW_CONVERT_EXPR, type0, op1);
14691 : 4 : warning_at (location, OPT_Wsign_compare, "comparison between "
14692 : : "types %qT and %qT", type0, type1);
14693 : : }
14694 : :
14695 : : /* Always construct signed integer vector type. */
14696 : 41726 : if (VECTOR_BOOLEAN_TYPE_P (type0) && VECTOR_BOOLEAN_TYPE_P (type1))
14697 : : result_type = type0;
14698 : : else
14699 : : {
14700 : 41726 : auto nelts = TYPE_VECTOR_SUBPARTS (type0);
14701 : :
14702 : 125178 : intt = c_common_type_for_size (GET_MODE_BITSIZE
14703 : 83452 : (SCALAR_TYPE_MODE
14704 : : (TREE_TYPE (type0))), 0);
14705 : 41726 : if (!intt)
14706 : : {
14707 : 0 : error_at (location, "could not find an integer type "
14708 : : "of the same size as %qT",
14709 : 0 : TREE_TYPE (type0));
14710 : 0 : return error_mark_node;
14711 : : }
14712 : 41726 : result_type = build_opaque_vector_type (intt, nelts);
14713 : : }
14714 : 41726 : converted = 1;
14715 : 41726 : ret = build_vec_cmp (resultcode, result_type, op0, op1);
14716 : 41726 : goto return_build_binary_op;
14717 : : }
14718 : 1687689 : if (FLOAT_TYPE_P (type0) || FLOAT_TYPE_P (type1))
14719 : 252641 : warning_at (location,
14720 : 252641 : OPT_Wfloat_equal,
14721 : : "comparing floating-point with %<==%> or %<!=%> is unsafe");
14722 : : /* Result of comparison is always int,
14723 : : but don't convert the args to int! */
14724 : 1687689 : build_type = integer_type_node;
14725 : 1687689 : if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == BITINT_TYPE
14726 : 155572 : || code0 == FIXED_POINT_TYPE || code0 == COMPLEX_TYPE)
14727 : 1567414 : && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
14728 : : || code1 == BITINT_TYPE
14729 : : || code1 == FIXED_POINT_TYPE || code1 == COMPLEX_TYPE))
14730 : : short_compare = 1;
14731 : 120538 : else if (code0 == POINTER_TYPE
14732 : 120538 : && (code1 == NULLPTR_TYPE
14733 : 120193 : || null_pointer_constant_p (orig_op1)))
14734 : : {
14735 : 50706 : maybe_warn_for_null_address (location, op0, code);
14736 : 50706 : result_type = type0;
14737 : : }
14738 : 69832 : else if (code1 == POINTER_TYPE
14739 : 69832 : && (code0 == NULLPTR_TYPE
14740 : 69730 : || null_pointer_constant_p (orig_op0)))
14741 : : {
14742 : 284 : maybe_warn_for_null_address (location, op1, code);
14743 : 284 : result_type = type1;
14744 : : }
14745 : 69548 : else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
14746 : : {
14747 : 69458 : tree tt0 = TREE_TYPE (type0);
14748 : 69458 : tree tt1 = TREE_TYPE (type1);
14749 : 69458 : addr_space_t as0 = TYPE_ADDR_SPACE (tt0);
14750 : 69458 : addr_space_t as1 = TYPE_ADDR_SPACE (tt1);
14751 : 69458 : addr_space_t as_common = ADDR_SPACE_GENERIC;
14752 : :
14753 : : /* Anything compares with void *. void * compares with anything.
14754 : : Otherwise, the targets must be compatible
14755 : : and both must be object or both incomplete. */
14756 : 69458 : if (comp_target_types (location, type0, type1))
14757 : 48163 : result_type = common_pointer_type (type0, type1, NULL_TREE);
14758 : 21295 : else if (!addr_space_superset (as0, as1, &as_common))
14759 : : {
14760 : 0 : error_at (location, "comparison of pointers to "
14761 : : "disjoint address spaces");
14762 : 0 : return error_mark_node;
14763 : : }
14764 : 21295 : else if (VOID_TYPE_P (tt0) && !TYPE_ATOMIC (tt0))
14765 : : {
14766 : 21086 : if (pedantic && TREE_CODE (tt1) == FUNCTION_TYPE)
14767 : 4 : pedwarn (location, OPT_Wpedantic, "ISO C forbids "
14768 : : "comparison of %<void *%> with function pointer");
14769 : : }
14770 : 209 : else if (VOID_TYPE_P (tt1) && !TYPE_ATOMIC (tt1))
14771 : : {
14772 : 161 : if (pedantic && TREE_CODE (tt0) == FUNCTION_TYPE)
14773 : 4 : pedwarn (location, OPT_Wpedantic, "ISO C forbids "
14774 : : "comparison of %<void *%> with function pointer");
14775 : : }
14776 : : else
14777 : : /* Avoid warning about the volatile ObjC EH puts on decls. */
14778 : 48 : if (!objc_ok)
14779 : 48 : pedwarn (location, OPT_Wcompare_distinct_pointer_types,
14780 : : "comparison of distinct pointer types lacks a cast");
14781 : :
14782 : 48219 : if (result_type == NULL_TREE)
14783 : : {
14784 : 21295 : int qual = ENCODE_QUAL_ADDR_SPACE (as_common);
14785 : 21295 : result_type = c_build_pointer_type
14786 : 21295 : (c_build_qualified_type (void_type_node, qual));
14787 : : }
14788 : : }
14789 : 90 : else if (code0 == POINTER_TYPE
14790 : 26 : && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
14791 : : {
14792 : 26 : result_type = type0;
14793 : 26 : pedwarn (location, 0, "comparison between pointer and integer");
14794 : : }
14795 : 64 : else if ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE)
14796 : 21 : && code1 == POINTER_TYPE)
14797 : : {
14798 : 8 : result_type = type1;
14799 : 8 : pedwarn (location, 0, "comparison between pointer and integer");
14800 : : }
14801 : : /* 6.5.9: One of the following shall hold:
14802 : : -- both operands have type nullptr_t; */
14803 : 56 : else if (code0 == NULLPTR_TYPE && code1 == NULLPTR_TYPE)
14804 : : {
14805 : 22 : result_type = nullptr_type_node;
14806 : : /* No need to convert the operands to result_type later. */
14807 : 22 : converted = 1;
14808 : : }
14809 : : /* -- one operand has type nullptr_t and the other is a null pointer
14810 : : constant. We will have to convert the former to the type of the
14811 : : latter, because during gimplification we can't have mismatching
14812 : : comparison operand type. We convert from nullptr_t to the other
14813 : : type, since only nullptr_t can be converted to nullptr_t. Also,
14814 : : even a constant 0 is a null pointer constant, so we may have to
14815 : : create a pointer type from its type. */
14816 : 34 : else if (code0 == NULLPTR_TYPE && null_pointer_constant_p (orig_op1))
14817 : 19 : result_type = (INTEGRAL_TYPE_P (type1)
14818 : 19 : ? c_build_pointer_type (type1) : type1);
14819 : 15 : else if (code1 == NULLPTR_TYPE && null_pointer_constant_p (orig_op0))
14820 : 11 : result_type = (INTEGRAL_TYPE_P (type0)
14821 : 11 : ? c_build_pointer_type (type0) : type0);
14822 : 4989136 : if ((C_BOOLEAN_TYPE_P (TREE_TYPE (orig_op0))
14823 : 3301422 : || truth_value_p (TREE_CODE (orig_op0)))
14824 : 3368113 : ^ (C_BOOLEAN_TYPE_P (TREE_TYPE (orig_op1))
14825 : 3368109 : || truth_value_p (TREE_CODE (orig_op1))))
14826 : 70976 : maybe_warn_bool_compare (location, code, orig_op0, orig_op1);
14827 : : break;
14828 : :
14829 : 991430 : case LE_EXPR:
14830 : 991430 : case GE_EXPR:
14831 : 991430 : case LT_EXPR:
14832 : 991430 : case GT_EXPR:
14833 : 991430 : if (gnu_vector_type_p (type0) && gnu_vector_type_p (type1))
14834 : : {
14835 : 58918 : tree intt;
14836 : 58918 : if (!vector_types_compatible_elements_p (type0, type1))
14837 : : {
14838 : 5 : error_at (location, "comparing vectors with different "
14839 : : "element types");
14840 : 5 : return error_mark_node;
14841 : : }
14842 : :
14843 : 58913 : if (maybe_ne (TYPE_VECTOR_SUBPARTS (type0),
14844 : 117826 : TYPE_VECTOR_SUBPARTS (type1)))
14845 : : {
14846 : 0 : error_at (location, "comparing vectors with different "
14847 : : "number of elements");
14848 : 0 : return error_mark_node;
14849 : : }
14850 : :
14851 : : /* It's not precisely specified how the usual arithmetic
14852 : : conversions apply to the vector types. Here, we use
14853 : : the unsigned type if one of the operands is signed and
14854 : : the other one is unsigned. */
14855 : 58913 : if (TYPE_UNSIGNED (type0) != TYPE_UNSIGNED (type1))
14856 : : {
14857 : 15 : if (!TYPE_UNSIGNED (type0))
14858 : 8 : op0 = build1 (VIEW_CONVERT_EXPR, type1, op0);
14859 : : else
14860 : 7 : op1 = build1 (VIEW_CONVERT_EXPR, type0, op1);
14861 : 15 : warning_at (location, OPT_Wsign_compare, "comparison between "
14862 : : "types %qT and %qT", type0, type1);
14863 : : }
14864 : :
14865 : : /* Always construct signed integer vector type. */
14866 : 176739 : intt = c_common_type_for_size (GET_MODE_BITSIZE
14867 : 117826 : (SCALAR_TYPE_MODE
14868 : : (TREE_TYPE (type0))), 0);
14869 : 58913 : if (!intt)
14870 : : {
14871 : 0 : error_at (location, "could not find an integer type "
14872 : : "of the same size as %qT",
14873 : 0 : TREE_TYPE (type0));
14874 : 0 : return error_mark_node;
14875 : : }
14876 : 58913 : result_type = build_opaque_vector_type (intt,
14877 : 58913 : TYPE_VECTOR_SUBPARTS (type0));
14878 : 58913 : converted = 1;
14879 : 58913 : ret = build_vec_cmp (resultcode, result_type, op0, op1);
14880 : 58913 : goto return_build_binary_op;
14881 : : }
14882 : 932512 : build_type = integer_type_node;
14883 : 932512 : if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
14884 : 64243 : || code0 == BITINT_TYPE || code0 == FIXED_POINT_TYPE)
14885 : 868806 : && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
14886 : : || code1 == BITINT_TYPE || code1 == FIXED_POINT_TYPE))
14887 : : short_compare = 1;
14888 : 63738 : else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
14889 : : {
14890 : 63671 : addr_space_t as0 = TYPE_ADDR_SPACE (TREE_TYPE (type0));
14891 : 63671 : addr_space_t as1 = TYPE_ADDR_SPACE (TREE_TYPE (type1));
14892 : 63671 : addr_space_t as_common;
14893 : :
14894 : 63671 : if (comp_target_types (location, type0, type1))
14895 : : {
14896 : 63558 : result_type = common_pointer_type (type0, type1, NULL_TREE);
14897 : 63558 : if (!COMPLETE_TYPE_P (TREE_TYPE (type0))
14898 : 63558 : != !COMPLETE_TYPE_P (TREE_TYPE (type1)))
14899 : 32 : pedwarn_c99 (location, OPT_Wpedantic,
14900 : : "comparison of complete and incomplete pointers");
14901 : 63526 : else if (TREE_CODE (TREE_TYPE (type0)) == FUNCTION_TYPE)
14902 : 0 : pedwarn (location, OPT_Wpedantic, "ISO C forbids "
14903 : : "ordered comparisons of pointers to functions");
14904 : 63526 : else if (null_pointer_constant_p (orig_op0)
14905 : 63526 : || null_pointer_constant_p (orig_op1))
14906 : 8 : warning_at (location, OPT_Wextra,
14907 : : "ordered comparison of pointer with null pointer");
14908 : :
14909 : : }
14910 : 113 : else if (!addr_space_superset (as0, as1, &as_common))
14911 : : {
14912 : 0 : error_at (location, "comparison of pointers to "
14913 : : "disjoint address spaces");
14914 : 0 : return error_mark_node;
14915 : : }
14916 : : else
14917 : : {
14918 : 113 : int qual = ENCODE_QUAL_ADDR_SPACE (as_common);
14919 : 113 : result_type = c_build_pointer_type
14920 : 113 : (c_build_qualified_type (void_type_node, qual));
14921 : 113 : pedwarn (location, OPT_Wcompare_distinct_pointer_types,
14922 : : "comparison of distinct pointer types lacks a cast");
14923 : : }
14924 : : }
14925 : 67 : else if (code0 == POINTER_TYPE && null_pointer_constant_p (orig_op1))
14926 : : {
14927 : 17 : result_type = type0;
14928 : 17 : if (pedantic)
14929 : 11 : pedwarn (location, OPT_Wpedantic,
14930 : : "ordered comparison of pointer with integer zero");
14931 : 6 : else if (extra_warnings)
14932 : 1 : warning_at (location, OPT_Wextra,
14933 : : "ordered comparison of pointer with integer zero");
14934 : : }
14935 : 50 : else if (code1 == POINTER_TYPE && null_pointer_constant_p (orig_op0))
14936 : : {
14937 : 12 : result_type = type1;
14938 : 12 : if (pedantic)
14939 : 2 : pedwarn (location, OPT_Wpedantic,
14940 : : "ordered comparison of pointer with integer zero");
14941 : 10 : else if (extra_warnings)
14942 : 1 : warning_at (location, OPT_Wextra,
14943 : : "ordered comparison of pointer with integer zero");
14944 : : }
14945 : 38 : else if (code0 == POINTER_TYPE
14946 : 18 : && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
14947 : : {
14948 : 18 : result_type = type0;
14949 : 18 : pedwarn (location, 0, "comparison between pointer and integer");
14950 : : }
14951 : 20 : else if ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE)
14952 : 20 : && code1 == POINTER_TYPE)
14953 : : {
14954 : 18 : result_type = type1;
14955 : 18 : pedwarn (location, 0, "comparison between pointer and integer");
14956 : : }
14957 : :
14958 : 932512 : if ((code0 == POINTER_TYPE || code1 == POINTER_TYPE)
14959 : 63736 : && current_function_decl != NULL_TREE
14960 : 996237 : && sanitize_flags_p (SANITIZE_POINTER_COMPARE))
14961 : : {
14962 : 35 : op0 = save_expr (c_fully_fold (op0, false, NULL));
14963 : 35 : op1 = save_expr (c_fully_fold (op1, false, NULL));
14964 : :
14965 : 35 : tree tt = builtin_decl_explicit (BUILT_IN_ASAN_POINTER_COMPARE);
14966 : 35 : instrument_expr = build_call_expr_loc (location, tt, 2, op0, op1);
14967 : : }
14968 : :
14969 : 2797440 : if ((C_BOOLEAN_TYPE_P (TREE_TYPE (orig_op0))
14970 : 1864928 : || truth_value_p (TREE_CODE (orig_op0)))
14971 : 1864933 : ^ (C_BOOLEAN_TYPE_P (TREE_TYPE (orig_op1))
14972 : 1864933 : || truth_value_p (TREE_CODE (orig_op1))))
14973 : 531 : maybe_warn_bool_compare (location, code, orig_op0, orig_op1);
14974 : : break;
14975 : :
14976 : 43 : case MIN_EXPR:
14977 : 43 : case MAX_EXPR:
14978 : : /* Used for OpenMP atomics. */
14979 : 43 : gcc_assert (flag_openmp);
14980 : : common = 1;
14981 : : break;
14982 : :
14983 : 0 : default:
14984 : 0 : gcc_unreachable ();
14985 : : }
14986 : :
14987 : 15306807 : if (code0 == ERROR_MARK || code1 == ERROR_MARK)
14988 : 0 : return error_mark_node;
14989 : :
14990 : 15306807 : if (gnu_vector_type_p (type0)
14991 : 1473984 : && gnu_vector_type_p (type1)
14992 : 16779973 : && (!tree_int_cst_equal (TYPE_SIZE (type0), TYPE_SIZE (type1))
14993 : 1473146 : || !vector_types_compatible_elements_p (type0, type1)))
14994 : : {
14995 : 26 : gcc_rich_location richloc (location);
14996 : 26 : maybe_range_label_for_tree_type_mismatch
14997 : 26 : label_for_op0 (orig_op0, orig_op1),
14998 : 26 : label_for_op1 (orig_op1, orig_op0);
14999 : 26 : richloc.maybe_add_expr (orig_op0, &label_for_op0, highlight_colors::lhs);
15000 : 26 : richloc.maybe_add_expr (orig_op1, &label_for_op1, highlight_colors::rhs);
15001 : 26 : binary_op_error (&richloc, code, type0, type1);
15002 : 26 : return error_mark_node;
15003 : 26 : }
15004 : :
15005 : 15306781 : if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == COMPLEX_TYPE
15006 : 1726097 : || code0 == FIXED_POINT_TYPE || code0 == BITINT_TYPE
15007 : 1658354 : || gnu_vector_type_p (type0))
15008 : 16848482 : && (code1 == INTEGER_TYPE || code1 == REAL_TYPE || code1 == COMPLEX_TYPE
15009 : 1566567 : || code1 == FIXED_POINT_TYPE || code1 == BITINT_TYPE
15010 : 1475234 : || gnu_vector_type_p (type1)))
15011 : : {
15012 : 15120296 : bool first_complex = (code0 == COMPLEX_TYPE);
15013 : 15120296 : bool second_complex = (code1 == COMPLEX_TYPE);
15014 : 15120296 : int none_complex = (!first_complex && !second_complex);
15015 : :
15016 : 15120296 : if (shorten || common || short_compare)
15017 : : {
15018 : 13586290 : result_type = c_common_type (type0, type1);
15019 : 13586290 : do_warn_double_promotion (result_type, type0, type1,
15020 : : "implicit conversion from %qT to %qT "
15021 : : "to match other operand of binary "
15022 : : "expression",
15023 : : location);
15024 : 13586290 : if (result_type == error_mark_node)
15025 : : return error_mark_node;
15026 : : }
15027 : :
15028 : 15120274 : if (first_complex != second_complex
15029 : 82043 : && (code == PLUS_EXPR
15030 : : || code == MINUS_EXPR
15031 : 82043 : || code == MULT_EXPR
15032 : 17525 : || (code == TRUNC_DIV_EXPR && first_complex))
15033 : 65932 : && TREE_CODE (TREE_TYPE (result_type)) == REAL_TYPE
15034 : 15182528 : && flag_signed_zeros)
15035 : : {
15036 : : /* An operation on mixed real/complex operands must be
15037 : : handled specially, but the language-independent code can
15038 : : more easily optimize the plain complex arithmetic if
15039 : : -fno-signed-zeros. */
15040 : 61942 : tree real_type = TREE_TYPE (result_type);
15041 : 61942 : tree real, imag;
15042 : 61942 : if (type0 != orig_type0 || type1 != orig_type1)
15043 : : {
15044 : 94 : gcc_assert (may_need_excess_precision && common);
15045 : 94 : semantic_result_type = c_common_type (orig_type0, orig_type1);
15046 : : }
15047 : 61942 : if (first_complex)
15048 : : {
15049 : 8253 : if (TREE_TYPE (op0) != result_type)
15050 : 1787 : op0 = convert_and_check (location, result_type, op0);
15051 : 8253 : if (TREE_TYPE (op1) != real_type)
15052 : 4601 : op1 = convert_and_check (location, real_type, op1);
15053 : : }
15054 : : else
15055 : : {
15056 : 53689 : if (TREE_TYPE (op0) != real_type)
15057 : 2698 : op0 = convert_and_check (location, real_type, op0);
15058 : 53689 : if (TREE_TYPE (op1) != result_type)
15059 : 1866 : op1 = convert_and_check (location, result_type, op1);
15060 : : }
15061 : 61942 : if (TREE_CODE (op0) == ERROR_MARK || TREE_CODE (op1) == ERROR_MARK)
15062 : 0 : return error_mark_node;
15063 : 61942 : if (first_complex)
15064 : : {
15065 : 8253 : op0 = save_expr (op0);
15066 : 8253 : real = build_unary_op (EXPR_LOCATION (orig_op0), REALPART_EXPR,
15067 : : op0, true);
15068 : 8253 : imag = build_unary_op (EXPR_LOCATION (orig_op0), IMAGPART_EXPR,
15069 : : op0, true);
15070 : 8253 : switch (code)
15071 : : {
15072 : 3488 : case MULT_EXPR:
15073 : 3488 : case TRUNC_DIV_EXPR:
15074 : 3488 : op1 = save_expr (op1);
15075 : 3488 : imag = build2 (resultcode, real_type, imag, op1);
15076 : : /* Fall through. */
15077 : 8253 : case PLUS_EXPR:
15078 : 8253 : case MINUS_EXPR:
15079 : 8253 : real = build2 (resultcode, real_type, real, op1);
15080 : 8253 : break;
15081 : 0 : default:
15082 : 0 : gcc_unreachable();
15083 : : }
15084 : : }
15085 : : else
15086 : : {
15087 : 53689 : op1 = save_expr (op1);
15088 : 53689 : real = build_unary_op (EXPR_LOCATION (orig_op1), REALPART_EXPR,
15089 : : op1, true);
15090 : 53689 : imag = build_unary_op (EXPR_LOCATION (orig_op1), IMAGPART_EXPR,
15091 : : op1, true);
15092 : 53689 : switch (code)
15093 : : {
15094 : 2008 : case MULT_EXPR:
15095 : 2008 : op0 = save_expr (op0);
15096 : 2008 : imag = build2 (resultcode, real_type, op0, imag);
15097 : : /* Fall through. */
15098 : 31957 : case PLUS_EXPR:
15099 : 31957 : real = build2 (resultcode, real_type, op0, real);
15100 : 31957 : break;
15101 : 21732 : case MINUS_EXPR:
15102 : 21732 : real = build2 (resultcode, real_type, op0, real);
15103 : 21732 : imag = build1 (NEGATE_EXPR, real_type, imag);
15104 : 21732 : break;
15105 : 0 : default:
15106 : 0 : gcc_unreachable();
15107 : : }
15108 : : }
15109 : 61942 : ret = build2 (COMPLEX_EXPR, result_type, real, imag);
15110 : 61942 : goto return_build_binary_op;
15111 : : }
15112 : :
15113 : : /* For certain operations (which identify themselves by shorten != 0)
15114 : : if both args were extended from the same smaller type,
15115 : : do the arithmetic in that type and then extend.
15116 : :
15117 : : shorten !=0 and !=1 indicates a bitwise operation.
15118 : : For them, this optimization is safe only if
15119 : : both args are zero-extended or both are sign-extended.
15120 : : Otherwise, we might change the result.
15121 : : Eg, (short)-1 | (unsigned short)-1 is (int)-1
15122 : : but calculated in (unsigned short) it would be (unsigned short)-1. */
15123 : :
15124 : 15058332 : if (shorten && none_complex)
15125 : : {
15126 : 1284850 : final_type = result_type;
15127 : 1284850 : result_type = shorten_binary_op (result_type, op0, op1,
15128 : : shorten == -1);
15129 : : }
15130 : :
15131 : : /* Shifts can be shortened if shifting right. */
15132 : :
15133 : 15058332 : if (short_shift)
15134 : : {
15135 : 199249 : int unsigned_arg;
15136 : 199249 : tree arg0 = get_narrower (op0, &unsigned_arg);
15137 : :
15138 : 199249 : final_type = result_type;
15139 : :
15140 : 199249 : if (arg0 == op0 && final_type == TREE_TYPE (op0))
15141 : 139943 : unsigned_arg = TYPE_UNSIGNED (TREE_TYPE (op0));
15142 : :
15143 : 199249 : if (TYPE_PRECISION (TREE_TYPE (arg0)) < TYPE_PRECISION (result_type)
15144 : 2981 : && tree_int_cst_sgn (op1) > 0
15145 : : /* We can shorten only if the shift count is less than the
15146 : : number of bits in the smaller type size. */
15147 : 2981 : && compare_tree_int (op1, TYPE_PRECISION (TREE_TYPE (arg0))) < 0
15148 : : /* We cannot drop an unsigned shift after sign-extension. */
15149 : 202090 : && (!TYPE_UNSIGNED (final_type) || unsigned_arg))
15150 : : {
15151 : : /* Do an unsigned shift if the operand was zero-extended. */
15152 : 2827 : result_type
15153 : 2827 : = c_common_signed_or_unsigned_type (unsigned_arg,
15154 : 2827 : TREE_TYPE (arg0));
15155 : : /* Convert value-to-be-shifted to that type. */
15156 : 2827 : if (TREE_TYPE (op0) != result_type)
15157 : 2827 : op0 = convert (result_type, op0);
15158 : : converted = 1;
15159 : : }
15160 : : }
15161 : :
15162 : : /* Comparison operations are shortened too but differently.
15163 : : They identify themselves by setting short_compare = 1. */
15164 : :
15165 : 15058332 : if (short_compare)
15166 : : {
15167 : : /* Don't write &op0, etc., because that would prevent op0
15168 : : from being kept in a register.
15169 : : Instead, make copies of the our local variables and
15170 : : pass the copies by reference, then copy them back afterward. */
15171 : 2435923 : tree xop0 = op0, xop1 = op1, xresult_type = result_type;
15172 : 2435923 : enum tree_code xresultcode = resultcode;
15173 : 2435923 : tree val
15174 : 2435923 : = shorten_compare (location, &xop0, &xop1, &xresult_type,
15175 : : &xresultcode);
15176 : :
15177 : 2435923 : if (val != NULL_TREE)
15178 : : {
15179 : 15787 : ret = val;
15180 : 15787 : goto return_build_binary_op;
15181 : : }
15182 : :
15183 : 2420136 : op0 = xop0, op1 = xop1;
15184 : 2420136 : converted = 1;
15185 : 2420136 : resultcode = xresultcode;
15186 : :
15187 : 2420136 : if (c_inhibit_evaluation_warnings == 0 && !c_in_omp_for)
15188 : : {
15189 : 2272352 : bool op0_maybe_const = true;
15190 : 2272352 : bool op1_maybe_const = true;
15191 : 2272352 : tree orig_op0_folded, orig_op1_folded;
15192 : :
15193 : 2272352 : if (in_late_binary_op)
15194 : : {
15195 : : orig_op0_folded = orig_op0;
15196 : : orig_op1_folded = orig_op1;
15197 : : }
15198 : : else
15199 : : {
15200 : : /* Fold for the sake of possible warnings, as in
15201 : : build_conditional_expr. This requires the
15202 : : "original" values to be folded, not just op0 and
15203 : : op1. */
15204 : 2263985 : c_inhibit_evaluation_warnings++;
15205 : 2263985 : op0 = c_fully_fold (op0, require_constant_value,
15206 : : &op0_maybe_const);
15207 : 2263985 : op1 = c_fully_fold (op1, require_constant_value,
15208 : : &op1_maybe_const);
15209 : 2263985 : c_inhibit_evaluation_warnings--;
15210 : 2263985 : orig_op0_folded = c_fully_fold (orig_op0,
15211 : : require_constant_value,
15212 : : NULL);
15213 : 2263985 : orig_op1_folded = c_fully_fold (orig_op1,
15214 : : require_constant_value,
15215 : : NULL);
15216 : : }
15217 : :
15218 : 2272352 : if (warn_sign_compare)
15219 : 373260 : warn_for_sign_compare (location, orig_op0_folded,
15220 : : orig_op1_folded, op0, op1,
15221 : : result_type, resultcode);
15222 : 2272352 : if (!in_late_binary_op && !int_operands)
15223 : : {
15224 : 2087403 : if (!op0_maybe_const || TREE_CODE (op0) != INTEGER_CST)
15225 : 2083865 : op0 = c_wrap_maybe_const (op0, !op0_maybe_const);
15226 : 2087403 : if (!op1_maybe_const || TREE_CODE (op1) != INTEGER_CST)
15227 : 821985 : op1 = c_wrap_maybe_const (op1, !op1_maybe_const);
15228 : : }
15229 : : }
15230 : : }
15231 : : }
15232 : :
15233 : : /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
15234 : : If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
15235 : : Then the expression will be built.
15236 : : It will be given type FINAL_TYPE if that is nonzero;
15237 : : otherwise, it will be given type RESULT_TYPE. */
15238 : :
15239 : 15229030 : if (!result_type)
15240 : : {
15241 : : /* Favor showing any expression locations that are available. */
15242 : 514 : op_location_t oploc (location, UNKNOWN_LOCATION);
15243 : 514 : binary_op_rich_location richloc (oploc, orig_op0, orig_op1, true);
15244 : 514 : binary_op_error (&richloc, code, TREE_TYPE (op0), TREE_TYPE (op1));
15245 : 514 : return error_mark_node;
15246 : 514 : }
15247 : :
15248 : 15228516 : if (build_type == NULL_TREE)
15249 : : {
15250 : 12624110 : build_type = result_type;
15251 : 12624110 : if ((type0 != orig_type0 || type1 != orig_type1)
15252 : 797 : && !boolean_op)
15253 : : {
15254 : 797 : gcc_assert (may_need_excess_precision && common);
15255 : 797 : semantic_result_type = c_common_type (orig_type0, orig_type1);
15256 : : }
15257 : : }
15258 : :
15259 : 15228516 : if (!converted)
15260 : : {
15261 : 11271449 : op0 = ep_convert_and_check (location, result_type, op0,
15262 : : semantic_result_type);
15263 : 11271449 : op1 = ep_convert_and_check (location, result_type, op1,
15264 : : semantic_result_type);
15265 : :
15266 : : /* This can happen if one operand has a vector type, and the other
15267 : : has a different type. */
15268 : 11271449 : if (TREE_CODE (op0) == ERROR_MARK || TREE_CODE (op1) == ERROR_MARK)
15269 : 3 : return error_mark_node;
15270 : : }
15271 : :
15272 : 15228513 : if (sanitize_flags_p ((SANITIZE_SHIFT
15273 : : | SANITIZE_DIVIDE
15274 : : | SANITIZE_FLOAT_DIVIDE
15275 : : | SANITIZE_SI_OVERFLOW))
15276 : 23306 : && current_function_decl != NULL_TREE
15277 : 19843 : && (doing_div_or_mod || doing_shift)
15278 : 15231438 : && !require_constant_value)
15279 : : {
15280 : : /* OP0 and/or OP1 might have side-effects. */
15281 : 2869 : op0 = save_expr (op0);
15282 : 2869 : op1 = save_expr (op1);
15283 : 2869 : op0 = c_fully_fold (op0, false, NULL);
15284 : 2869 : op1 = c_fully_fold (op1, false, NULL);
15285 : 2869 : if (doing_div_or_mod && (sanitize_flags_p ((SANITIZE_DIVIDE
15286 : : | SANITIZE_FLOAT_DIVIDE
15287 : : | SANITIZE_SI_OVERFLOW))))
15288 : 912 : instrument_expr = ubsan_instrument_division (location, op0, op1);
15289 : 1957 : else if (doing_shift && sanitize_flags_p (SANITIZE_SHIFT))
15290 : 1777 : instrument_expr = ubsan_instrument_shift (location, code, op0, op1);
15291 : : }
15292 : :
15293 : : /* Treat expressions in initializers specially as they can't trap. */
15294 : 15228513 : if (int_const_or_overflow)
15295 : 7810943 : ret = (require_constant_value
15296 : 7810943 : ? fold_build2_initializer_loc (location, resultcode, build_type,
15297 : : op0, op1)
15298 : 7764822 : : fold_build2_loc (location, resultcode, build_type, op0, op1));
15299 : : else
15300 : 7417570 : ret = build2 (resultcode, build_type, op0, op1);
15301 : 15228513 : if (final_type != NULL_TREE)
15302 : 1484099 : ret = convert (final_type, ret);
15303 : :
15304 : 13744414 : return_build_binary_op:
15305 : 16671725 : gcc_assert (ret != error_mark_node);
15306 : 16671725 : if (TREE_CODE (ret) == INTEGER_CST && !TREE_OVERFLOW (ret) && !int_const)
15307 : 1740 : ret = (int_operands
15308 : 1740 : ? note_integer_operands (ret)
15309 : 422 : : build1 (NOP_EXPR, TREE_TYPE (ret), ret));
15310 : 16669985 : else if (TREE_CODE (ret) != INTEGER_CST && int_operands
15311 : 60300 : && !in_late_binary_op)
15312 : 60300 : ret = note_integer_operands (ret);
15313 : 16671725 : protected_set_expr_location (ret, location);
15314 : :
15315 : 16671725 : if (instrument_expr != NULL)
15316 : 1420 : ret = fold_build2 (COMPOUND_EXPR, TREE_TYPE (ret),
15317 : : instrument_expr, ret);
15318 : :
15319 : 16671725 : if (semantic_result_type)
15320 : 891 : ret = build1_loc (location, EXCESS_PRECISION_EXPR,
15321 : : semantic_result_type, ret);
15322 : :
15323 : : return ret;
15324 : : }
15325 : :
15326 : :
15327 : : /* Convert EXPR to be a truth-value (type TYPE), validating its type for this
15328 : : purpose. LOCATION is the source location for the expression. */
15329 : :
15330 : : tree
15331 : 4108819 : c_objc_common_truthvalue_conversion (location_t location, tree expr, tree type)
15332 : : {
15333 : 4108819 : bool int_const, int_operands;
15334 : :
15335 : 4108819 : switch (TREE_CODE (TREE_TYPE (expr)))
15336 : : {
15337 : 72 : case ARRAY_TYPE:
15338 : 72 : error_at (location, "used array that cannot be converted to pointer where scalar is required");
15339 : 72 : return error_mark_node;
15340 : :
15341 : 86 : case RECORD_TYPE:
15342 : 86 : error_at (location, "used struct type value where scalar is required");
15343 : 86 : return error_mark_node;
15344 : :
15345 : 83 : case UNION_TYPE:
15346 : 83 : error_at (location, "used union type value where scalar is required");
15347 : 83 : return error_mark_node;
15348 : :
15349 : 22 : case VOID_TYPE:
15350 : 22 : error_at (location, "void value not ignored as it ought to be");
15351 : 22 : return error_mark_node;
15352 : :
15353 : 30050 : case POINTER_TYPE:
15354 : 30050 : if (reject_gcc_builtin (expr))
15355 : 3 : return error_mark_node;
15356 : : break;
15357 : :
15358 : 0 : case FUNCTION_TYPE:
15359 : 0 : gcc_unreachable ();
15360 : :
15361 : 8 : case VECTOR_TYPE:
15362 : 8 : error_at (location, "used vector type where scalar is required");
15363 : 8 : return error_mark_node;
15364 : :
15365 : : default:
15366 : : break;
15367 : : }
15368 : :
15369 : : /* Conversion of a floating constant to boolean goes through here
15370 : : and yields an integer constant expression. Otherwise, the result
15371 : : is only an integer constant expression if the argument is. */
15372 : 896212 : int_const = ((TREE_CODE (expr) == INTEGER_CST && !TREE_OVERFLOW (expr))
15373 : 4108621 : || ((TREE_CODE (expr) == REAL_CST
15374 : 3212035 : || TREE_CODE (expr) == COMPLEX_CST)
15375 : 374 : && (TREE_CODE (type) == BOOLEAN_TYPE
15376 : 15 : || (TREE_CODE (type) == ENUMERAL_TYPE
15377 : 5 : && ENUM_UNDERLYING_TYPE (type) != NULL_TREE
15378 : 5 : && (TREE_CODE (ENUM_UNDERLYING_TYPE (type))
15379 : : == BOOLEAN_TYPE)))));
15380 : 4108545 : int_operands = EXPR_INT_CONST_OPERANDS (expr);
15381 : 896372 : if (int_operands && TREE_CODE (expr) != INTEGER_CST)
15382 : : {
15383 : 319 : expr = remove_c_maybe_const_expr (expr);
15384 : 319 : expr = build2 (NE_EXPR, type, expr,
15385 : 319 : convert (TREE_TYPE (expr), integer_zero_node));
15386 : 319 : expr = note_integer_operands (expr);
15387 : : }
15388 : : else
15389 : : {
15390 : : /* ??? Should we also give an error for vectors rather than leaving
15391 : : those to give errors later? */
15392 : 4108226 : expr = c_common_truthvalue_conversion (location, expr);
15393 : 4108226 : expr = fold_convert_loc (location, type, expr);
15394 : : }
15395 : :
15396 : 4108545 : if (TREE_CODE (expr) == INTEGER_CST && int_operands && !int_const)
15397 : : {
15398 : 76 : if (TREE_OVERFLOW (expr))
15399 : : return expr;
15400 : : else
15401 : 76 : return note_integer_operands (expr);
15402 : : }
15403 : 4108469 : if (TREE_CODE (expr) == INTEGER_CST && !int_const)
15404 : 754 : return build1 (NOP_EXPR, TREE_TYPE (expr), expr);
15405 : : return expr;
15406 : : }
15407 : :
15408 : :
15409 : : /* Convert EXPR to a contained DECL, updating *TC, *TI and *SE as
15410 : : required. */
15411 : :
15412 : : tree
15413 : 117648490 : c_expr_to_decl (tree expr, bool *tc ATTRIBUTE_UNUSED, bool *se)
15414 : : {
15415 : 117648490 : if (TREE_CODE (expr) == COMPOUND_LITERAL_EXPR)
15416 : : {
15417 : 681 : tree decl = COMPOUND_LITERAL_EXPR_DECL (expr);
15418 : : /* Executing a compound literal inside a function reinitializes
15419 : : it. */
15420 : 681 : if (!TREE_STATIC (decl))
15421 : 415 : *se = true;
15422 : 681 : return decl;
15423 : : }
15424 : : else
15425 : : return expr;
15426 : : }
15427 : :
15428 : : /* Generate OMP construct CODE, with BODY and CLAUSES as its compound
15429 : : statement. LOC is the location of the construct. */
15430 : :
15431 : : tree
15432 : 2154 : c_finish_omp_construct (location_t loc, enum tree_code code, tree body,
15433 : : tree clauses)
15434 : : {
15435 : 2154 : body = c_end_compound_stmt (loc, body, true);
15436 : :
15437 : 2154 : tree stmt = make_node (code);
15438 : 2154 : TREE_TYPE (stmt) = void_type_node;
15439 : 2154 : OMP_BODY (stmt) = body;
15440 : 2154 : OMP_CLAUSES (stmt) = clauses;
15441 : 2154 : SET_EXPR_LOCATION (stmt, loc);
15442 : :
15443 : 2154 : return add_stmt (stmt);
15444 : : }
15445 : :
15446 : : /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound
15447 : : statement. LOC is the location of the OACC_DATA. */
15448 : :
15449 : : tree
15450 : 497 : c_finish_oacc_data (location_t loc, tree clauses, tree block)
15451 : : {
15452 : 497 : tree stmt;
15453 : :
15454 : 497 : block = c_end_compound_stmt (loc, block, true);
15455 : :
15456 : 497 : stmt = make_node (OACC_DATA);
15457 : 497 : TREE_TYPE (stmt) = void_type_node;
15458 : 497 : OACC_DATA_CLAUSES (stmt) = clauses;
15459 : 497 : OACC_DATA_BODY (stmt) = block;
15460 : 497 : SET_EXPR_LOCATION (stmt, loc);
15461 : :
15462 : 497 : return add_stmt (stmt);
15463 : : }
15464 : :
15465 : : /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound
15466 : : statement. LOC is the location of the OACC_HOST_DATA. */
15467 : :
15468 : : tree
15469 : 21 : c_finish_oacc_host_data (location_t loc, tree clauses, tree block)
15470 : : {
15471 : 21 : tree stmt;
15472 : :
15473 : 21 : block = c_end_compound_stmt (loc, block, true);
15474 : :
15475 : 21 : stmt = make_node (OACC_HOST_DATA);
15476 : 21 : TREE_TYPE (stmt) = void_type_node;
15477 : 21 : OACC_HOST_DATA_CLAUSES (stmt) = clauses;
15478 : 21 : OACC_HOST_DATA_BODY (stmt) = block;
15479 : 21 : SET_EXPR_LOCATION (stmt, loc);
15480 : :
15481 : 21 : return add_stmt (stmt);
15482 : : }
15483 : :
15484 : : /* Like c_begin_compound_stmt, except force the retention of the BLOCK. */
15485 : :
15486 : : tree
15487 : 11979 : c_begin_omp_parallel (void)
15488 : : {
15489 : 11979 : tree block;
15490 : :
15491 : 11979 : keep_next_level ();
15492 : 11979 : block = c_begin_compound_stmt (true);
15493 : :
15494 : 11979 : return block;
15495 : : }
15496 : :
15497 : : /* Generate OMP_PARALLEL, with CLAUSES and BLOCK as its compound
15498 : : statement. LOC is the location of the OMP_PARALLEL. */
15499 : :
15500 : : tree
15501 : 5659 : c_finish_omp_parallel (location_t loc, tree clauses, tree block)
15502 : : {
15503 : 5659 : tree stmt;
15504 : :
15505 : 5659 : block = c_end_compound_stmt (loc, block, true);
15506 : :
15507 : 5659 : stmt = make_node (OMP_PARALLEL);
15508 : 5659 : TREE_TYPE (stmt) = void_type_node;
15509 : 5659 : OMP_PARALLEL_CLAUSES (stmt) = clauses;
15510 : 5659 : OMP_PARALLEL_BODY (stmt) = block;
15511 : 5659 : SET_EXPR_LOCATION (stmt, loc);
15512 : :
15513 : 5659 : return add_stmt (stmt);
15514 : : }
15515 : :
15516 : : /* Like c_begin_compound_stmt, except force the retention of the BLOCK. */
15517 : :
15518 : : tree
15519 : 896 : c_begin_omp_task (void)
15520 : : {
15521 : 896 : tree block;
15522 : :
15523 : 896 : keep_next_level ();
15524 : 896 : block = c_begin_compound_stmt (true);
15525 : :
15526 : 896 : return block;
15527 : : }
15528 : :
15529 : : /* Generate OMP_TASK, with CLAUSES and BLOCK as its compound
15530 : : statement. LOC is the location of the #pragma. */
15531 : :
15532 : : tree
15533 : 896 : c_finish_omp_task (location_t loc, tree clauses, tree block)
15534 : : {
15535 : 896 : tree stmt;
15536 : :
15537 : 896 : block = c_end_compound_stmt (loc, block, true);
15538 : :
15539 : 896 : stmt = make_node (OMP_TASK);
15540 : 896 : TREE_TYPE (stmt) = void_type_node;
15541 : 896 : OMP_TASK_CLAUSES (stmt) = clauses;
15542 : 896 : OMP_TASK_BODY (stmt) = block;
15543 : 896 : SET_EXPR_LOCATION (stmt, loc);
15544 : :
15545 : 896 : return add_stmt (stmt);
15546 : : }
15547 : :
15548 : : /* Generate GOMP_cancel call for #pragma omp cancel. */
15549 : :
15550 : : void
15551 : 213 : c_finish_omp_cancel (location_t loc, tree clauses)
15552 : : {
15553 : 213 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCEL);
15554 : 213 : int mask = 0;
15555 : 213 : if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
15556 : : mask = 1;
15557 : 150 : else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
15558 : : mask = 2;
15559 : 101 : else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
15560 : : mask = 4;
15561 : 58 : else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
15562 : : mask = 8;
15563 : : else
15564 : : {
15565 : 0 : error_at (loc, "%<#pragma omp cancel%> must specify one of "
15566 : : "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> "
15567 : : "clauses");
15568 : 0 : return;
15569 : : }
15570 : 213 : tree ifc = omp_find_clause (clauses, OMP_CLAUSE_IF);
15571 : 213 : if (ifc != NULL_TREE)
15572 : : {
15573 : 31 : if (OMP_CLAUSE_IF_MODIFIER (ifc) != ERROR_MARK
15574 : 31 : && OMP_CLAUSE_IF_MODIFIER (ifc) != VOID_CST)
15575 : 2 : error_at (OMP_CLAUSE_LOCATION (ifc),
15576 : : "expected %<cancel%> %<if%> clause modifier");
15577 : : else
15578 : : {
15579 : 29 : tree ifc2 = omp_find_clause (OMP_CLAUSE_CHAIN (ifc), OMP_CLAUSE_IF);
15580 : 29 : if (ifc2 != NULL_TREE)
15581 : : {
15582 : 1 : gcc_assert (OMP_CLAUSE_IF_MODIFIER (ifc) == VOID_CST
15583 : : && OMP_CLAUSE_IF_MODIFIER (ifc2) != ERROR_MARK
15584 : : && OMP_CLAUSE_IF_MODIFIER (ifc2) != VOID_CST);
15585 : 1 : error_at (OMP_CLAUSE_LOCATION (ifc2),
15586 : : "expected %<cancel%> %<if%> clause modifier");
15587 : : }
15588 : : }
15589 : :
15590 : 31 : tree type = TREE_TYPE (OMP_CLAUSE_IF_EXPR (ifc));
15591 : 62 : ifc = fold_build2_loc (OMP_CLAUSE_LOCATION (ifc), NE_EXPR,
15592 : 31 : boolean_type_node, OMP_CLAUSE_IF_EXPR (ifc),
15593 : : build_zero_cst (type));
15594 : : }
15595 : : else
15596 : 182 : ifc = boolean_true_node;
15597 : 213 : tree stmt = build_call_expr_loc (loc, fn, 2,
15598 : 213 : build_int_cst (integer_type_node, mask),
15599 : : ifc);
15600 : 213 : add_stmt (stmt);
15601 : : }
15602 : :
15603 : : /* Generate GOMP_cancellation_point call for
15604 : : #pragma omp cancellation point. */
15605 : :
15606 : : void
15607 : 167 : c_finish_omp_cancellation_point (location_t loc, tree clauses)
15608 : : {
15609 : 167 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT);
15610 : 167 : int mask = 0;
15611 : 167 : if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
15612 : : mask = 1;
15613 : 123 : else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
15614 : : mask = 2;
15615 : 88 : else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
15616 : : mask = 4;
15617 : 53 : else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
15618 : : mask = 8;
15619 : : else
15620 : : {
15621 : 1 : error_at (loc, "%<#pragma omp cancellation point%> must specify one of "
15622 : : "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> "
15623 : : "clauses");
15624 : 1 : return;
15625 : : }
15626 : 166 : tree stmt = build_call_expr_loc (loc, fn, 1,
15627 : 166 : build_int_cst (integer_type_node, mask));
15628 : 166 : add_stmt (stmt);
15629 : : }
15630 : :
15631 : : /* Helper function for handle_omp_array_sections. Called recursively
15632 : : to handle multiple array-section-subscripts. C is the clause,
15633 : : T current expression (initially OMP_CLAUSE_DECL), which is either
15634 : : a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound
15635 : : expression if specified, TREE_VALUE length expression if specified,
15636 : : TREE_CHAIN is what it has been specified after, or some decl.
15637 : : TYPES vector is populated with array section types, MAYBE_ZERO_LEN
15638 : : set to true if any of the array-section-subscript could have length
15639 : : of zero (explicit or implicit), FIRST_NON_ONE is the index of the
15640 : : first array-section-subscript which is known not to have length
15641 : : of one. Given say:
15642 : : map(a[:b][2:1][:c][:2][:d][e:f][2:5])
15643 : : FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c]
15644 : : all are or may have length of 1, array-section-subscript [:2] is the
15645 : : first one known not to have length 1. For array-section-subscript
15646 : : <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't
15647 : : 0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we
15648 : : can if MAYBE_ZERO_LEN is false. MAYBE_ZERO_LEN will be true in the above
15649 : : case though, as some lengths could be zero. */
15650 : :
15651 : : static tree
15652 : 6382 : handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types,
15653 : : bool &maybe_zero_len, unsigned int &first_non_one,
15654 : : enum c_omp_region_type ort)
15655 : : {
15656 : 6382 : tree ret, low_bound, length, type;
15657 : 6382 : bool openacc = (ort & C_ORT_ACC) != 0;
15658 : 6382 : if (TREE_CODE (t) != OMP_ARRAY_SECTION)
15659 : : {
15660 : 2972 : if (error_operand_p (t))
15661 : 2 : return error_mark_node;
15662 : 2970 : c_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
15663 : 2970 : ret = t;
15664 : 2970 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
15665 : 2871 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
15666 : 5527 : && TYPE_ATOMIC (strip_array_types (TREE_TYPE (t))))
15667 : : {
15668 : 6 : error_at (OMP_CLAUSE_LOCATION (c), "%<_Atomic%> %qE in %qs clause",
15669 : 6 : t, omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
15670 : 6 : return error_mark_node;
15671 : : }
15672 : 2964 : if (!ai.check_clause (c))
15673 : 0 : return error_mark_node;
15674 : 2964 : else if (ai.component_access_p ()
15675 : 3265 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
15676 : 15 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO
15677 : 11 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM))
15678 : 301 : t = ai.get_root_term (true);
15679 : : else
15680 : 2663 : t = ai.unconverted_ref_origin ();
15681 : 2964 : if (t == error_mark_node)
15682 : : return error_mark_node;
15683 : 2964 : if (!VAR_P (t)
15684 : 741 : && (ort == C_ORT_ACC || !EXPR_P (t))
15685 : 738 : && TREE_CODE (t) != PARM_DECL)
15686 : : {
15687 : 5 : if (DECL_P (t))
15688 : 5 : error_at (OMP_CLAUSE_LOCATION (c),
15689 : : "%qD is not a variable in %qs clause", t,
15690 : 5 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
15691 : : else
15692 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
15693 : : "%qE is not a variable in %qs clause", t,
15694 : 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
15695 : 5 : return error_mark_node;
15696 : : }
15697 : 2959 : else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
15698 : 2861 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
15699 : 5507 : && TYPE_ATOMIC (TREE_TYPE (t)))
15700 : : {
15701 : 0 : error_at (OMP_CLAUSE_LOCATION (c), "%<_Atomic%> %qD in %qs clause",
15702 : 0 : t, omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
15703 : 0 : return error_mark_node;
15704 : : }
15705 : 2959 : else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
15706 : 2861 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
15707 : 2548 : && VAR_P (t)
15708 : 4959 : && DECL_THREAD_LOCAL_P (t))
15709 : : {
15710 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
15711 : : "%qD is threadprivate variable in %qs clause", t,
15712 : 3 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
15713 : 3 : return error_mark_node;
15714 : : }
15715 : 2956 : if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
15716 : 2858 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND)
15717 : 411 : && TYPE_ATOMIC (TREE_TYPE (t))
15718 : 2958 : && POINTER_TYPE_P (TREE_TYPE (t)))
15719 : : {
15720 : : /* If the array section is pointer based and the pointer
15721 : : itself is _Atomic qualified, we need to atomically load
15722 : : the pointer. */
15723 : 2 : ret = convert_lvalue_to_rvalue (OMP_CLAUSE_LOCATION (c),
15724 : : ret, false, false);
15725 : : }
15726 : 2956 : return ret;
15727 : 2970 : }
15728 : :
15729 : 3410 : ret = handle_omp_array_sections_1 (c, TREE_OPERAND (t, 0), types,
15730 : : maybe_zero_len, first_non_one, ort);
15731 : 3410 : if (ret == error_mark_node || ret == NULL_TREE)
15732 : : return ret;
15733 : :
15734 : 3345 : type = TREE_TYPE (ret);
15735 : 3345 : low_bound = TREE_OPERAND (t, 1);
15736 : 3345 : length = TREE_OPERAND (t, 2);
15737 : :
15738 : 3345 : if (low_bound == error_mark_node || length == error_mark_node)
15739 : : return error_mark_node;
15740 : :
15741 : 3345 : if (low_bound && !INTEGRAL_TYPE_P (TREE_TYPE (low_bound)))
15742 : : {
15743 : 13 : error_at (OMP_CLAUSE_LOCATION (c),
15744 : : "low bound %qE of array section does not have integral type",
15745 : : low_bound);
15746 : 13 : return error_mark_node;
15747 : : }
15748 : 3332 : if (length && !INTEGRAL_TYPE_P (TREE_TYPE (length)))
15749 : : {
15750 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
15751 : : "length %qE of array section does not have integral type",
15752 : : length);
15753 : 12 : return error_mark_node;
15754 : : }
15755 : 3320 : if (low_bound
15756 : 2736 : && TREE_CODE (low_bound) == INTEGER_CST
15757 : 5767 : && TYPE_PRECISION (TREE_TYPE (low_bound))
15758 : 2447 : > TYPE_PRECISION (sizetype))
15759 : 0 : low_bound = fold_convert (sizetype, low_bound);
15760 : 3320 : if (length
15761 : 3132 : && TREE_CODE (length) == INTEGER_CST
15762 : 5507 : && TYPE_PRECISION (TREE_TYPE (length))
15763 : 2187 : > TYPE_PRECISION (sizetype))
15764 : 0 : length = fold_convert (sizetype, length);
15765 : 3320 : if (low_bound == NULL_TREE)
15766 : 584 : low_bound = integer_zero_node;
15767 : 3320 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
15768 : 3320 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
15769 : 1930 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH))
15770 : : {
15771 : 10 : if (length != integer_one_node)
15772 : : {
15773 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
15774 : : "expected single pointer in %qs clause",
15775 : : user_omp_clause_code_name (c, openacc));
15776 : 6 : return error_mark_node;
15777 : : }
15778 : : }
15779 : 3314 : if (length != NULL_TREE)
15780 : : {
15781 : 3130 : if (!integer_nonzerop (length))
15782 : : {
15783 : 974 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
15784 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
15785 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
15786 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
15787 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
15788 : : {
15789 : 180 : if (integer_zerop (length))
15790 : : {
15791 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
15792 : : "zero length array section in %qs clause",
15793 : 12 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
15794 : 12 : return error_mark_node;
15795 : : }
15796 : : }
15797 : : else
15798 : 794 : maybe_zero_len = true;
15799 : : }
15800 : 3118 : if (first_non_one == types.length ()
15801 : 3118 : && (TREE_CODE (length) != INTEGER_CST || integer_onep (length)))
15802 : 1597 : first_non_one++;
15803 : : }
15804 : 3302 : if (TREE_CODE (type) == ARRAY_TYPE)
15805 : : {
15806 : 1490 : if (length == NULL_TREE
15807 : 1490 : && (TYPE_DOMAIN (type) == NULL_TREE
15808 : 168 : || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE))
15809 : : {
15810 : 8 : error_at (OMP_CLAUSE_LOCATION (c),
15811 : : "for unknown bound array type length expression must "
15812 : : "be specified");
15813 : 8 : return error_mark_node;
15814 : : }
15815 : 1482 : if (TREE_CODE (low_bound) == INTEGER_CST
15816 : 1482 : && tree_int_cst_sgn (low_bound) == -1)
15817 : : {
15818 : 35 : error_at (OMP_CLAUSE_LOCATION (c),
15819 : : "negative low bound in array section in %qs clause",
15820 : 35 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
15821 : 35 : return error_mark_node;
15822 : : }
15823 : 1447 : if (length != NULL_TREE
15824 : 1291 : && TREE_CODE (length) == INTEGER_CST
15825 : 2298 : && tree_int_cst_sgn (length) == -1)
15826 : : {
15827 : 35 : error_at (OMP_CLAUSE_LOCATION (c),
15828 : : "negative length in array section in %qs clause",
15829 : 35 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
15830 : 35 : return error_mark_node;
15831 : : }
15832 : 1412 : if (TYPE_DOMAIN (type)
15833 : 1401 : && TYPE_MAX_VALUE (TYPE_DOMAIN (type))
15834 : 2813 : && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
15835 : : == INTEGER_CST)
15836 : : {
15837 : 1055 : tree size
15838 : 1055 : = fold_convert (sizetype, TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
15839 : 1055 : size = size_binop (PLUS_EXPR, size, size_one_node);
15840 : 1055 : if (TREE_CODE (low_bound) == INTEGER_CST)
15841 : : {
15842 : 868 : if (tree_int_cst_lt (size, low_bound))
15843 : : {
15844 : 10 : error_at (OMP_CLAUSE_LOCATION (c),
15845 : : "low bound %qE above array section size "
15846 : : "in %qs clause", low_bound,
15847 : 10 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
15848 : 10 : return error_mark_node;
15849 : : }
15850 : 858 : if (tree_int_cst_equal (size, low_bound))
15851 : : {
15852 : 5 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
15853 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
15854 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
15855 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
15856 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
15857 : : {
15858 : 5 : error_at (OMP_CLAUSE_LOCATION (c),
15859 : : "zero length array section in %qs clause",
15860 : 5 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
15861 : 5 : return error_mark_node;
15862 : : }
15863 : 0 : maybe_zero_len = true;
15864 : : }
15865 : 853 : else if (length == NULL_TREE
15866 : 256 : && first_non_one == types.length ()
15867 : 908 : && tree_int_cst_equal
15868 : 55 : (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
15869 : : low_bound))
15870 : 30 : first_non_one++;
15871 : : }
15872 : 187 : else if (length == NULL_TREE)
15873 : : {
15874 : 3 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
15875 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
15876 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
15877 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
15878 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
15879 : 0 : maybe_zero_len = true;
15880 : 6 : if (first_non_one == types.length ())
15881 : 1 : first_non_one++;
15882 : : }
15883 : 1040 : if (length && TREE_CODE (length) == INTEGER_CST)
15884 : : {
15885 : 793 : if (tree_int_cst_lt (size, length))
15886 : : {
15887 : 11 : error_at (OMP_CLAUSE_LOCATION (c),
15888 : : "length %qE above array section size "
15889 : : "in %qs clause", length,
15890 : 11 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
15891 : 11 : return error_mark_node;
15892 : : }
15893 : 782 : if (TREE_CODE (low_bound) == INTEGER_CST)
15894 : : {
15895 : 682 : tree lbpluslen
15896 : 682 : = size_binop (PLUS_EXPR,
15897 : : fold_convert (sizetype, low_bound),
15898 : : fold_convert (sizetype, length));
15899 : 682 : if (TREE_CODE (lbpluslen) == INTEGER_CST
15900 : 682 : && tree_int_cst_lt (size, lbpluslen))
15901 : : {
15902 : 10 : error_at (OMP_CLAUSE_LOCATION (c),
15903 : : "high bound %qE above array section size "
15904 : : "in %qs clause", lbpluslen,
15905 : 10 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
15906 : 10 : return error_mark_node;
15907 : : }
15908 : : }
15909 : : }
15910 : : }
15911 : 357 : else if (length == NULL_TREE)
15912 : : {
15913 : 10 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
15914 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
15915 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
15916 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
15917 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
15918 : 0 : maybe_zero_len = true;
15919 : 20 : if (first_non_one == types.length ())
15920 : 10 : first_non_one++;
15921 : : }
15922 : :
15923 : : /* For [lb:] we will need to evaluate lb more than once. */
15924 : 923 : if (length == NULL_TREE && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
15925 : : {
15926 : 127 : tree lb = save_expr (low_bound);
15927 : 127 : if (lb != low_bound)
15928 : : {
15929 : 2 : TREE_OPERAND (t, 1) = lb;
15930 : 2 : low_bound = lb;
15931 : : }
15932 : : }
15933 : : }
15934 : 1812 : else if (TREE_CODE (type) == POINTER_TYPE)
15935 : : {
15936 : 1801 : if (length == NULL_TREE)
15937 : : {
15938 : 10 : if (TREE_CODE (ret) == PARM_DECL && C_ARRAY_PARAMETER (ret))
15939 : 8 : error_at (OMP_CLAUSE_LOCATION (c),
15940 : : "for array function parameter length expression "
15941 : : "must be specified");
15942 : : else
15943 : 2 : error_at (OMP_CLAUSE_LOCATION (c),
15944 : : "for pointer type length expression must be specified");
15945 : 10 : return error_mark_node;
15946 : : }
15947 : 1791 : if (length != NULL_TREE
15948 : 1791 : && TREE_CODE (length) == INTEGER_CST
15949 : 1286 : && tree_int_cst_sgn (length) == -1)
15950 : : {
15951 : 20 : error_at (OMP_CLAUSE_LOCATION (c),
15952 : : "negative length in array section in %qs clause",
15953 : 20 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
15954 : 20 : return error_mark_node;
15955 : : }
15956 : : /* If there is a pointer type anywhere but in the very first
15957 : : array-section-subscript, the array section could be non-contiguous. */
15958 : 1771 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
15959 : 1610 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
15960 : 3352 : && TREE_CODE (TREE_OPERAND (t, 0)) == OMP_ARRAY_SECTION)
15961 : : {
15962 : : /* If any prior dimension has a non-one length, then deem this
15963 : : array section as non-contiguous. */
15964 : 42 : for (tree d = TREE_OPERAND (t, 0);
15965 : 82 : TREE_CODE (d) == OMP_ARRAY_SECTION;
15966 : 40 : d = TREE_OPERAND (d, 0))
15967 : : {
15968 : 44 : tree d_length = TREE_OPERAND (d, 2);
15969 : 44 : if (d_length == NULL_TREE || !integer_onep (d_length))
15970 : : {
15971 : 4 : error_at (OMP_CLAUSE_LOCATION (c),
15972 : : "array section is not contiguous in %qs clause",
15973 : 4 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
15974 : 4 : return error_mark_node;
15975 : : }
15976 : : }
15977 : : }
15978 : : }
15979 : : else
15980 : : {
15981 : 11 : error_at (OMP_CLAUSE_LOCATION (c),
15982 : : "%qE does not have pointer or array type", ret);
15983 : 11 : return error_mark_node;
15984 : : }
15985 : 3143 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
15986 : 2827 : types.safe_push (TREE_TYPE (ret));
15987 : : /* We will need to evaluate lb more than once. */
15988 : 3143 : tree lb = save_expr (low_bound);
15989 : 3143 : if (lb != low_bound)
15990 : : {
15991 : 273 : TREE_OPERAND (t, 1) = lb;
15992 : 273 : low_bound = lb;
15993 : : }
15994 : 3143 : ret = build_array_ref (OMP_CLAUSE_LOCATION (c), ret, low_bound);
15995 : 3143 : return ret;
15996 : : }
15997 : :
15998 : : /* Handle array sections for clause C. */
15999 : :
16000 : : static bool
16001 : 2972 : handle_omp_array_sections (tree &c, enum c_omp_region_type ort)
16002 : : {
16003 : 2972 : bool maybe_zero_len = false;
16004 : 2972 : unsigned int first_non_one = 0;
16005 : 2972 : auto_vec<tree, 10> types;
16006 : 2972 : tree *tp = &OMP_CLAUSE_DECL (c);
16007 : 2972 : if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
16008 : 2658 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
16009 : 3071 : && OMP_ITERATOR_DECL_P (*tp))
16010 : 66 : tp = &TREE_VALUE (*tp);
16011 : 2972 : tree first = handle_omp_array_sections_1 (c, *tp, types,
16012 : : maybe_zero_len, first_non_one,
16013 : : ort);
16014 : 2972 : if (first == error_mark_node)
16015 : : return true;
16016 : 2754 : if (first == NULL_TREE)
16017 : : return false;
16018 : 2754 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
16019 : 2754 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
16020 : : {
16021 : 336 : tree t = *tp;
16022 : 336 : tree tem = NULL_TREE;
16023 : : /* Need to evaluate side effects in the length expressions
16024 : : if any. */
16025 : 336 : while (TREE_CODE (t) == TREE_LIST)
16026 : : {
16027 : 0 : if (TREE_VALUE (t) && TREE_SIDE_EFFECTS (TREE_VALUE (t)))
16028 : : {
16029 : 0 : if (tem == NULL_TREE)
16030 : : tem = TREE_VALUE (t);
16031 : : else
16032 : 0 : tem = build2 (COMPOUND_EXPR, TREE_TYPE (tem),
16033 : 0 : TREE_VALUE (t), tem);
16034 : : }
16035 : 0 : t = TREE_CHAIN (t);
16036 : : }
16037 : 336 : if (tem)
16038 : 0 : first = build2 (COMPOUND_EXPR, TREE_TYPE (first), tem, first);
16039 : 336 : first = c_fully_fold (first, false, NULL, true);
16040 : 336 : *tp = first;
16041 : : }
16042 : : else
16043 : : {
16044 : 2418 : unsigned int num = types.length (), i;
16045 : 2418 : tree t, side_effects = NULL_TREE, size = NULL_TREE;
16046 : 2418 : tree condition = NULL_TREE;
16047 : :
16048 : 2418 : if (int_size_in_bytes (TREE_TYPE (first)) <= 0)
16049 : 3 : maybe_zero_len = true;
16050 : :
16051 : 5036 : for (i = num, t = OMP_CLAUSE_DECL (c); i > 0;
16052 : 2618 : t = TREE_OPERAND (t, 0))
16053 : : {
16054 : 2633 : tree low_bound = TREE_OPERAND (t, 1);
16055 : 2633 : tree length = TREE_OPERAND (t, 2);
16056 : :
16057 : 2633 : i--;
16058 : 2633 : if (low_bound
16059 : 2169 : && TREE_CODE (low_bound) == INTEGER_CST
16060 : 4616 : && TYPE_PRECISION (TREE_TYPE (low_bound))
16061 : 1983 : > TYPE_PRECISION (sizetype))
16062 : 0 : low_bound = fold_convert (sizetype, low_bound);
16063 : 2633 : if (length
16064 : 2541 : && TREE_CODE (length) == INTEGER_CST
16065 : 4247 : && TYPE_PRECISION (TREE_TYPE (length))
16066 : 1614 : > TYPE_PRECISION (sizetype))
16067 : 0 : length = fold_convert (sizetype, length);
16068 : 2633 : if (low_bound == NULL_TREE)
16069 : 464 : low_bound = integer_zero_node;
16070 : 2633 : if (!maybe_zero_len && i > first_non_one)
16071 : : {
16072 : 109 : if (integer_nonzerop (low_bound))
16073 : 6 : goto do_warn_noncontiguous;
16074 : 103 : if (length != NULL_TREE
16075 : 50 : && TREE_CODE (length) == INTEGER_CST
16076 : 50 : && TYPE_DOMAIN (types[i])
16077 : 50 : && TYPE_MAX_VALUE (TYPE_DOMAIN (types[i]))
16078 : 153 : && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])))
16079 : : == INTEGER_CST)
16080 : : {
16081 : 50 : tree size;
16082 : 50 : size = size_binop (PLUS_EXPR,
16083 : : TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
16084 : : size_one_node);
16085 : 50 : if (!tree_int_cst_equal (length, size))
16086 : : {
16087 : 7 : do_warn_noncontiguous:
16088 : 26 : error_at (OMP_CLAUSE_LOCATION (c),
16089 : : "array section is not contiguous in %qs "
16090 : : "clause",
16091 : 13 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
16092 : 2418 : return true;
16093 : : }
16094 : : }
16095 : 96 : if (length != NULL_TREE
16096 : 96 : && TREE_SIDE_EFFECTS (length))
16097 : : {
16098 : 0 : if (side_effects == NULL_TREE)
16099 : : side_effects = length;
16100 : : else
16101 : 0 : side_effects = build2 (COMPOUND_EXPR,
16102 : 0 : TREE_TYPE (side_effects),
16103 : : length, side_effects);
16104 : : }
16105 : : }
16106 : : else
16107 : : {
16108 : 2524 : tree l;
16109 : :
16110 : 2524 : if (i > first_non_one
16111 : 2524 : && ((length && integer_nonzerop (length))
16112 : 0 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
16113 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
16114 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION))
16115 : 0 : continue;
16116 : 2524 : if (length)
16117 : 2491 : l = fold_convert (sizetype, length);
16118 : : else
16119 : : {
16120 : 33 : l = size_binop (PLUS_EXPR,
16121 : : TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
16122 : : size_one_node);
16123 : 33 : l = size_binop (MINUS_EXPR, l,
16124 : : fold_convert (sizetype, low_bound));
16125 : : }
16126 : 2524 : if (i > first_non_one)
16127 : : {
16128 : 0 : l = fold_build2 (NE_EXPR, boolean_type_node, l,
16129 : : size_zero_node);
16130 : 0 : if (condition == NULL_TREE)
16131 : : condition = l;
16132 : : else
16133 : 0 : condition = fold_build2 (BIT_AND_EXPR, boolean_type_node,
16134 : : l, condition);
16135 : : }
16136 : 2524 : else if (size == NULL_TREE)
16137 : : {
16138 : 2405 : size = size_in_bytes (TREE_TYPE (types[i]));
16139 : 2405 : tree eltype = TREE_TYPE (types[num - 1]);
16140 : 2425 : while (TREE_CODE (eltype) == ARRAY_TYPE)
16141 : 20 : eltype = TREE_TYPE (eltype);
16142 : 2405 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
16143 : 2170 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
16144 : 4315 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
16145 : : {
16146 : 539 : if (integer_zerop (size)
16147 : 1076 : || integer_zerop (size_in_bytes (eltype)))
16148 : : {
16149 : 4 : error_at (OMP_CLAUSE_LOCATION (c),
16150 : : "zero length array section in %qs clause",
16151 : 2 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
16152 : 2 : return error_mark_node;
16153 : : }
16154 : 537 : size = size_binop (EXACT_DIV_EXPR, size,
16155 : : size_in_bytes (eltype));
16156 : : }
16157 : 2403 : size = size_binop (MULT_EXPR, size, l);
16158 : 2403 : if (condition)
16159 : 0 : size = fold_build3 (COND_EXPR, sizetype, condition,
16160 : : size, size_zero_node);
16161 : : }
16162 : : else
16163 : 119 : size = size_binop (MULT_EXPR, size, l);
16164 : : }
16165 : : }
16166 : 2403 : if (side_effects)
16167 : 0 : size = build2 (COMPOUND_EXPR, sizetype, side_effects, size);
16168 : 2403 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
16169 : 2170 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
16170 : 4313 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
16171 : : {
16172 : 537 : size = size_binop (MINUS_EXPR, size, size_one_node);
16173 : 537 : size = c_fully_fold (size, false, NULL);
16174 : 537 : size = save_expr (size);
16175 : 537 : tree index_type = build_index_type (size);
16176 : 537 : tree eltype = TREE_TYPE (first);
16177 : 549 : while (TREE_CODE (eltype) == ARRAY_TYPE)
16178 : 12 : eltype = TREE_TYPE (eltype);
16179 : 537 : tree type = c_build_array_type (eltype, index_type);
16180 : 537 : tree ptype = c_build_pointer_type (eltype);
16181 : 537 : if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
16182 : 296 : t = build_fold_addr_expr (t);
16183 : 537 : tree t2 = build_fold_addr_expr (first);
16184 : 537 : t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
16185 : : ptrdiff_type_node, t2);
16186 : 537 : t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
16187 : : ptrdiff_type_node, t2,
16188 : 537 : fold_convert_loc (OMP_CLAUSE_LOCATION (c),
16189 : : ptrdiff_type_node, t));
16190 : 537 : t2 = c_fully_fold (t2, false, NULL);
16191 : 537 : if (tree_fits_shwi_p (t2))
16192 : 398 : t = build2 (MEM_REF, type, t,
16193 : 398 : build_int_cst (ptype, tree_to_shwi (t2)));
16194 : : else
16195 : : {
16196 : 139 : t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c), sizetype, t2);
16197 : 139 : t = build2_loc (OMP_CLAUSE_LOCATION (c), POINTER_PLUS_EXPR,
16198 : 139 : TREE_TYPE (t), t, t2);
16199 : 139 : t = build2 (MEM_REF, type, t, build_int_cst (ptype, 0));
16200 : : }
16201 : 537 : OMP_CLAUSE_DECL (c) = t;
16202 : 537 : return false;
16203 : : }
16204 : 1866 : first = c_fully_fold (first, false, NULL);
16205 : 1866 : OMP_CLAUSE_DECL (c) = first;
16206 : 1866 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR)
16207 : : return false;
16208 : : /* Don't set OMP_CLAUSE_SIZE for bare attach/detach clauses. */
16209 : 1855 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
16210 : 1855 : || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
16211 : 1715 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH
16212 : 1713 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FORCE_DETACH))
16213 : : {
16214 : 1851 : if (size)
16215 : 1851 : size = c_fully_fold (size, false, NULL);
16216 : 1851 : OMP_CLAUSE_SIZE (c) = size;
16217 : : }
16218 : :
16219 : 1855 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
16220 : : return false;
16221 : :
16222 : 1717 : auto_vec<omp_addr_token *, 10> addr_tokens;
16223 : :
16224 : 1717 : if (!omp_parse_expr (addr_tokens, first))
16225 : 1717 : return true;
16226 : :
16227 : 1717 : c_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
16228 : :
16229 : 1717 : tree nc = ai.expand_map_clause (c, first, addr_tokens, ort);
16230 : 1717 : if (nc != error_mark_node)
16231 : : {
16232 : 1717 : using namespace omp_addr_tokenizer;
16233 : :
16234 : 1717 : if (ai.maybe_zero_length_array_section (c))
16235 : 1713 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
16236 : :
16237 : : /* !!! If we're accessing a base decl via chained access
16238 : : methods (e.g. multiple indirections), duplicate clause
16239 : : detection won't work properly. Skip it in that case. */
16240 : 1717 : if ((addr_tokens[0]->type == STRUCTURE_BASE
16241 : 1430 : || addr_tokens[0]->type == ARRAY_BASE)
16242 : 1717 : && addr_tokens[0]->u.structure_base_kind == BASE_DECL
16243 : 1717 : && addr_tokens[1]->type == ACCESS_METHOD
16244 : 3434 : && omp_access_chain_p (addr_tokens, 1))
16245 : 34 : c = nc;
16246 : :
16247 : 1717 : return false;
16248 : : }
16249 : : }
16250 : : return false;
16251 : 2972 : }
16252 : :
16253 : : /* Helper function of finish_omp_clauses. Clone STMT as if we were making
16254 : : an inline call. But, remap
16255 : : the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER
16256 : : and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL. */
16257 : :
16258 : : static tree
16259 : 510 : c_clone_omp_udr (tree stmt, tree omp_decl1, tree omp_decl2,
16260 : : tree decl, tree placeholder)
16261 : : {
16262 : 510 : copy_body_data id;
16263 : 510 : hash_map<tree, tree> decl_map;
16264 : :
16265 : 510 : decl_map.put (omp_decl1, placeholder);
16266 : 510 : decl_map.put (omp_decl2, decl);
16267 : 510 : memset (&id, 0, sizeof (id));
16268 : 510 : id.src_fn = DECL_CONTEXT (omp_decl1);
16269 : 510 : id.dst_fn = current_function_decl;
16270 : 510 : id.src_cfun = DECL_STRUCT_FUNCTION (id.src_fn);
16271 : 510 : id.decl_map = &decl_map;
16272 : :
16273 : 510 : id.copy_decl = copy_decl_no_change;
16274 : 510 : id.transform_call_graph_edges = CB_CGE_DUPLICATE;
16275 : 510 : id.transform_new_cfg = true;
16276 : 510 : id.transform_return_to_modify = false;
16277 : 510 : id.eh_lp_nr = 0;
16278 : 510 : walk_tree (&stmt, copy_tree_body_r, &id, NULL);
16279 : 510 : return stmt;
16280 : 510 : }
16281 : :
16282 : : /* Helper function of c_finish_omp_clauses, called via walk_tree.
16283 : : Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP. */
16284 : :
16285 : : static tree
16286 : 1123 : c_find_omp_placeholder_r (tree *tp, int *, void *data)
16287 : : {
16288 : 1123 : if (*tp == (tree) data)
16289 : 28 : return *tp;
16290 : : return NULL_TREE;
16291 : : }
16292 : :
16293 : : /* Similarly, but also walk aggregate fields. */
16294 : :
16295 : : struct c_find_omp_var_s { tree var; hash_set<tree> *pset; };
16296 : :
16297 : : static tree
16298 : 288 : c_find_omp_var_r (tree *tp, int *, void *data)
16299 : : {
16300 : 288 : if (*tp == ((struct c_find_omp_var_s *) data)->var)
16301 : : return *tp;
16302 : 280 : if (RECORD_OR_UNION_TYPE_P (*tp))
16303 : : {
16304 : 2 : tree field;
16305 : 2 : hash_set<tree> *pset = ((struct c_find_omp_var_s *) data)->pset;
16306 : :
16307 : 2 : for (field = TYPE_FIELDS (*tp); field;
16308 : 0 : field = DECL_CHAIN (field))
16309 : 2 : if (TREE_CODE (field) == FIELD_DECL)
16310 : : {
16311 : 2 : tree ret = walk_tree (&DECL_FIELD_OFFSET (field),
16312 : : c_find_omp_var_r, data, pset);
16313 : 2 : if (ret)
16314 : : return ret;
16315 : 2 : ret = walk_tree (&DECL_SIZE (field), c_find_omp_var_r, data, pset);
16316 : 2 : if (ret)
16317 : : return ret;
16318 : 2 : ret = walk_tree (&DECL_SIZE_UNIT (field), c_find_omp_var_r, data,
16319 : : pset);
16320 : 2 : if (ret)
16321 : : return ret;
16322 : 2 : ret = walk_tree (&TREE_TYPE (field), c_find_omp_var_r, data, pset);
16323 : 2 : if (ret)
16324 : : return ret;
16325 : : }
16326 : : }
16327 : 278 : else if (INTEGRAL_TYPE_P (*tp))
16328 : 45 : return walk_tree (&TYPE_MAX_VALUE (*tp), c_find_omp_var_r, data,
16329 : : ((struct c_find_omp_var_s *) data)->pset);
16330 : : return NULL_TREE;
16331 : : }
16332 : :
16333 : : /* Finish OpenMP iterators ITER. Return true if they are errorneous
16334 : : and clauses containing them should be removed. */
16335 : :
16336 : : static bool
16337 : 142 : c_omp_finish_iterators (tree iter)
16338 : : {
16339 : 142 : bool ret = false;
16340 : 323 : for (tree it = iter; it; it = TREE_CHAIN (it))
16341 : : {
16342 : 181 : tree var = TREE_VEC_ELT (it, 0);
16343 : 181 : tree begin = TREE_VEC_ELT (it, 1);
16344 : 181 : tree end = TREE_VEC_ELT (it, 2);
16345 : 181 : tree step = TREE_VEC_ELT (it, 3);
16346 : 181 : tree orig_step;
16347 : 181 : tree type = TREE_TYPE (var);
16348 : 181 : location_t loc = DECL_SOURCE_LOCATION (var);
16349 : 181 : if (type == error_mark_node)
16350 : : {
16351 : 0 : ret = true;
16352 : 34 : continue;
16353 : : }
16354 : 181 : if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type))
16355 : : {
16356 : 6 : error_at (loc, "iterator %qD has neither integral nor pointer type",
16357 : : var);
16358 : 6 : ret = true;
16359 : 6 : continue;
16360 : : }
16361 : 175 : else if (TYPE_ATOMIC (type))
16362 : : {
16363 : 2 : error_at (loc, "iterator %qD has %<_Atomic%> qualified type", var);
16364 : 2 : ret = true;
16365 : 2 : continue;
16366 : : }
16367 : 173 : else if (TYPE_READONLY (type))
16368 : : {
16369 : 4 : error_at (loc, "iterator %qD has const qualified type", var);
16370 : 4 : ret = true;
16371 : 4 : continue;
16372 : : }
16373 : 169 : else if (step == error_mark_node
16374 : 169 : || TREE_TYPE (step) == error_mark_node)
16375 : : {
16376 : 0 : ret = true;
16377 : 0 : continue;
16378 : : }
16379 : 169 : else if (!INTEGRAL_TYPE_P (TREE_TYPE (step)))
16380 : : {
16381 : 6 : error_at (EXPR_LOC_OR_LOC (step, loc),
16382 : : "iterator step with non-integral type");
16383 : 4 : ret = true;
16384 : 4 : continue;
16385 : : }
16386 : 165 : begin = c_fully_fold (build_c_cast (loc, type, begin), false, NULL);
16387 : 165 : end = c_fully_fold (build_c_cast (loc, type, end), false, NULL);
16388 : 165 : orig_step = save_expr (c_fully_fold (step, false, NULL));
16389 : 165 : tree stype = POINTER_TYPE_P (type) ? sizetype : type;
16390 : 165 : step = c_fully_fold (build_c_cast (loc, stype, orig_step), false, NULL);
16391 : 165 : if (POINTER_TYPE_P (type))
16392 : : {
16393 : 14 : begin = save_expr (begin);
16394 : 14 : step = pointer_int_sum (loc, PLUS_EXPR, begin, step);
16395 : 14 : step = fold_build2_loc (loc, MINUS_EXPR, sizetype,
16396 : : fold_convert (sizetype, step),
16397 : : fold_convert (sizetype, begin));
16398 : 14 : step = fold_convert (ssizetype, step);
16399 : : }
16400 : 165 : if (integer_zerop (step))
16401 : : {
16402 : 6 : error_at (loc, "iterator %qD has zero step", var);
16403 : 6 : ret = true;
16404 : 6 : continue;
16405 : : }
16406 : :
16407 : 159 : if (begin == error_mark_node
16408 : 157 : || end == error_mark_node
16409 : 155 : || step == error_mark_node
16410 : 155 : || orig_step == error_mark_node)
16411 : : {
16412 : 4 : ret = true;
16413 : 4 : continue;
16414 : : }
16415 : 155 : hash_set<tree> pset;
16416 : 155 : tree it2;
16417 : 196 : for (it2 = TREE_CHAIN (it); it2; it2 = TREE_CHAIN (it2))
16418 : : {
16419 : 49 : tree var2 = TREE_VEC_ELT (it2, 0);
16420 : 49 : tree begin2 = TREE_VEC_ELT (it2, 1);
16421 : 49 : tree end2 = TREE_VEC_ELT (it2, 2);
16422 : 49 : tree step2 = TREE_VEC_ELT (it2, 3);
16423 : 49 : tree type2 = TREE_TYPE (var2);
16424 : 49 : location_t loc2 = DECL_SOURCE_LOCATION (var2);
16425 : 49 : struct c_find_omp_var_s data = { var, &pset };
16426 : 49 : if (walk_tree (&type2, c_find_omp_var_r, &data, &pset))
16427 : : {
16428 : 2 : error_at (loc2,
16429 : : "type of iterator %qD refers to outer iterator %qD",
16430 : : var2, var);
16431 : 10 : break;
16432 : : }
16433 : 47 : else if (walk_tree (&begin2, c_find_omp_var_r, &data, &pset))
16434 : : {
16435 : 2 : error_at (EXPR_LOC_OR_LOC (begin2, loc2),
16436 : : "begin expression refers to outer iterator %qD", var);
16437 : 2 : break;
16438 : : }
16439 : 45 : else if (walk_tree (&end2, c_find_omp_var_r, &data, &pset))
16440 : : {
16441 : 2 : error_at (EXPR_LOC_OR_LOC (end2, loc2),
16442 : : "end expression refers to outer iterator %qD", var);
16443 : 2 : break;
16444 : : }
16445 : 43 : else if (walk_tree (&step2, c_find_omp_var_r, &data, &pset))
16446 : : {
16447 : 2 : error_at (EXPR_LOC_OR_LOC (step2, loc2),
16448 : : "step expression refers to outer iterator %qD", var);
16449 : 2 : break;
16450 : : }
16451 : : }
16452 : 155 : if (it2)
16453 : : {
16454 : 8 : ret = true;
16455 : 8 : continue;
16456 : : }
16457 : 147 : TREE_VEC_ELT (it, 1) = begin;
16458 : 147 : TREE_VEC_ELT (it, 2) = end;
16459 : 147 : TREE_VEC_ELT (it, 3) = step;
16460 : 147 : TREE_VEC_ELT (it, 4) = orig_step;
16461 : 155 : }
16462 : 142 : return ret;
16463 : : }
16464 : :
16465 : : /* Ensure that pointers are used in OpenACC attach and detach clauses.
16466 : : Return true if an error has been detected. */
16467 : :
16468 : : static bool
16469 : 9406 : c_oacc_check_attachments (tree c)
16470 : : {
16471 : 9406 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
16472 : : return false;
16473 : :
16474 : : /* OpenACC attach / detach clauses must be pointers. */
16475 : 6411 : if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
16476 : 6411 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
16477 : : {
16478 : 71 : tree t = OMP_CLAUSE_DECL (c);
16479 : :
16480 : 77 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
16481 : 6 : t = TREE_OPERAND (t, 0);
16482 : :
16483 : 71 : if (TREE_CODE (TREE_TYPE (t)) != POINTER_TYPE)
16484 : : {
16485 : 6 : error_at (OMP_CLAUSE_LOCATION (c), "expected pointer in %qs clause",
16486 : : user_omp_clause_code_name (c, true));
16487 : 6 : return true;
16488 : : }
16489 : : }
16490 : :
16491 : : return false;
16492 : : }
16493 : :
16494 : : /* For all elements of CLAUSES, validate them against their constraints.
16495 : : Remove any elements from the list that are invalid. */
16496 : :
16497 : : tree
16498 : 29240 : c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
16499 : : {
16500 : 29240 : bitmap_head generic_head, firstprivate_head, lastprivate_head;
16501 : 29240 : bitmap_head aligned_head, map_head, map_field_head, map_firstprivate_head;
16502 : 29240 : bitmap_head oacc_reduction_head, is_on_device_head;
16503 : 29240 : tree c, t, type, *pc;
16504 : 29240 : tree simdlen = NULL_TREE, safelen = NULL_TREE;
16505 : 29240 : bool branch_seen = false;
16506 : 29240 : bool copyprivate_seen = false;
16507 : 29240 : bool mergeable_seen = false;
16508 : 29240 : tree *detach_seen = NULL;
16509 : 29240 : bool linear_variable_step_check = false;
16510 : 29240 : tree *nowait_clause = NULL;
16511 : 29240 : tree *grainsize_seen = NULL;
16512 : 29240 : bool num_tasks_seen = false;
16513 : 29240 : tree ordered_clause = NULL_TREE;
16514 : 29240 : tree schedule_clause = NULL_TREE;
16515 : 29240 : bool oacc_async = false;
16516 : 29240 : tree last_iterators = NULL_TREE;
16517 : 29240 : bool last_iterators_remove = false;
16518 : 29240 : tree *nogroup_seen = NULL;
16519 : 29240 : tree *order_clause = NULL;
16520 : : /* 1 if normal/task reduction has been seen, -1 if inscan reduction
16521 : : has been seen, -2 if mixed inscan/normal reduction diagnosed. */
16522 : 29240 : int reduction_seen = 0;
16523 : 29240 : bool allocate_seen = false;
16524 : 29240 : bool implicit_moved = false;
16525 : 29240 : bool target_in_reduction_seen = false;
16526 : 29240 : tree *full_seen = NULL;
16527 : 29240 : bool partial_seen = false;
16528 : 29240 : bool openacc = (ort & C_ORT_ACC) != 0;
16529 : 29240 : bool init_seen = false;
16530 : 29240 : bool init_use_destroy_seen = false;
16531 : 29240 : tree init_no_targetsync_clause = NULL_TREE;
16532 : 29240 : tree depend_clause = NULL_TREE;
16533 : :
16534 : 29240 : bitmap_obstack_initialize (NULL);
16535 : 29240 : bitmap_initialize (&generic_head, &bitmap_default_obstack);
16536 : 29240 : bitmap_initialize (&firstprivate_head, &bitmap_default_obstack);
16537 : 29240 : bitmap_initialize (&lastprivate_head, &bitmap_default_obstack);
16538 : 29240 : bitmap_initialize (&aligned_head, &bitmap_default_obstack);
16539 : : /* If ort == C_ORT_OMP_DECLARE_SIMD used as uniform_head instead. */
16540 : 29240 : bitmap_initialize (&map_head, &bitmap_default_obstack);
16541 : 29240 : bitmap_initialize (&map_field_head, &bitmap_default_obstack);
16542 : 29240 : bitmap_initialize (&map_firstprivate_head, &bitmap_default_obstack);
16543 : : /* If ort == C_ORT_OMP used as nontemporal_head or use_device_xxx_head
16544 : : instead and for ort == C_ORT_OMP_TARGET used as in_reduction_head. */
16545 : 29240 : bitmap_initialize (&oacc_reduction_head, &bitmap_default_obstack);
16546 : 29240 : bitmap_initialize (&is_on_device_head, &bitmap_default_obstack);
16547 : :
16548 : 29240 : if (openacc)
16549 : 12269 : for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
16550 : 7258 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ASYNC)
16551 : : {
16552 : : oacc_async = true;
16553 : : break;
16554 : : }
16555 : :
16556 : 29240 : tree *grp_start_p = NULL, grp_sentinel = NULL_TREE;
16557 : :
16558 : 76935 : for (pc = &clauses, c = clauses; c ; c = *pc)
16559 : : {
16560 : 47695 : bool remove = false;
16561 : 47695 : bool need_complete = false;
16562 : 47695 : bool need_implicitly_determined = false;
16563 : :
16564 : : /* We've reached the end of a list of expanded nodes. Reset the group
16565 : : start pointer. */
16566 : 47695 : if (c == grp_sentinel)
16567 : : {
16568 : 2468 : if (grp_start_p
16569 : 2468 : && OMP_CLAUSE_HAS_ITERATORS (*grp_start_p))
16570 : 32 : for (tree gc = *grp_start_p; gc != grp_sentinel;
16571 : 22 : gc = OMP_CLAUSE_CHAIN (gc))
16572 : 22 : OMP_CLAUSE_ITERATORS (gc) = OMP_CLAUSE_ITERATORS (*grp_start_p);
16573 : : grp_start_p = NULL;
16574 : : }
16575 : :
16576 : 47695 : switch (OMP_CLAUSE_CODE (c))
16577 : : {
16578 : 1137 : case OMP_CLAUSE_SHARED:
16579 : 1137 : need_implicitly_determined = true;
16580 : 1137 : goto check_dup_generic;
16581 : :
16582 : 838 : case OMP_CLAUSE_PRIVATE:
16583 : 838 : need_complete = true;
16584 : 838 : need_implicitly_determined = true;
16585 : 838 : goto check_dup_generic;
16586 : :
16587 : 3516 : case OMP_CLAUSE_REDUCTION:
16588 : 3516 : if (reduction_seen == 0)
16589 : 2917 : reduction_seen = OMP_CLAUSE_REDUCTION_INSCAN (c) ? -1 : 1;
16590 : 599 : else if (reduction_seen != -2
16591 : 1198 : && reduction_seen != (OMP_CLAUSE_REDUCTION_INSCAN (c)
16592 : 599 : ? -1 : 1))
16593 : : {
16594 : 2 : error_at (OMP_CLAUSE_LOCATION (c),
16595 : : "%<inscan%> and non-%<inscan%> %<reduction%> clauses "
16596 : : "on the same construct");
16597 : 2 : reduction_seen = -2;
16598 : : }
16599 : : /* FALLTHRU */
16600 : 4179 : case OMP_CLAUSE_IN_REDUCTION:
16601 : 4179 : case OMP_CLAUSE_TASK_REDUCTION:
16602 : 4179 : need_implicitly_determined = true;
16603 : 4179 : t = OMP_CLAUSE_DECL (c);
16604 : 4179 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
16605 : : {
16606 : 553 : if (handle_omp_array_sections (c, ort))
16607 : : {
16608 : : remove = true;
16609 : : break;
16610 : : }
16611 : :
16612 : 537 : t = OMP_CLAUSE_DECL (c);
16613 : 537 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
16614 : 537 : && OMP_CLAUSE_REDUCTION_INSCAN (c))
16615 : : {
16616 : 1 : error_at (OMP_CLAUSE_LOCATION (c),
16617 : : "%<inscan%> %<reduction%> clause with array "
16618 : : "section");
16619 : 1 : remove = true;
16620 : 1 : break;
16621 : : }
16622 : : }
16623 : 4162 : t = require_complete_type (OMP_CLAUSE_LOCATION (c), t);
16624 : 4162 : if (t == error_mark_node)
16625 : : {
16626 : : remove = true;
16627 : : break;
16628 : : }
16629 : 4160 : if (oacc_async)
16630 : 3 : c_mark_addressable (t);
16631 : 4160 : type = TREE_TYPE (t);
16632 : 4160 : if (TREE_CODE (t) == MEM_REF)
16633 : 536 : type = TREE_TYPE (type);
16634 : 4160 : if (TREE_CODE (type) == ARRAY_TYPE)
16635 : : {
16636 : 74 : tree oatype = type;
16637 : 74 : gcc_assert (TREE_CODE (t) != MEM_REF);
16638 : 148 : while (TREE_CODE (type) == ARRAY_TYPE)
16639 : 74 : type = TREE_TYPE (type);
16640 : 74 : if (integer_zerop (TYPE_SIZE_UNIT (type)))
16641 : : {
16642 : 1 : error_at (OMP_CLAUSE_LOCATION (c),
16643 : : "%qD in %<reduction%> clause is a zero size array",
16644 : : t);
16645 : 1 : remove = true;
16646 : 1 : break;
16647 : : }
16648 : 73 : tree size = size_binop (EXACT_DIV_EXPR, TYPE_SIZE_UNIT (oatype),
16649 : : TYPE_SIZE_UNIT (type));
16650 : 73 : if (integer_zerop (size))
16651 : : {
16652 : 1 : error_at (OMP_CLAUSE_LOCATION (c),
16653 : : "%qD in %<reduction%> clause is a zero size array",
16654 : : t);
16655 : 1 : remove = true;
16656 : 1 : break;
16657 : : }
16658 : 72 : size = size_binop (MINUS_EXPR, size, size_one_node);
16659 : 72 : size = save_expr (size);
16660 : 72 : tree index_type = build_index_type (size);
16661 : 72 : tree atype = c_build_array_type (TYPE_MAIN_VARIANT (type),
16662 : : index_type);
16663 : 72 : atype = c_build_qualified_type (atype, TYPE_QUALS (type));
16664 : 72 : tree ptype = c_build_pointer_type (type);
16665 : 72 : if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
16666 : 72 : t = build_fold_addr_expr (t);
16667 : 72 : t = build2 (MEM_REF, atype, t, build_int_cst (ptype, 0));
16668 : 72 : OMP_CLAUSE_DECL (c) = t;
16669 : : }
16670 : 4158 : if (TYPE_ATOMIC (type))
16671 : : {
16672 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
16673 : : "%<_Atomic%> %qE in %<reduction%> clause", t);
16674 : 3 : remove = true;
16675 : 3 : break;
16676 : : }
16677 : 4155 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
16678 : 4155 : || OMP_CLAUSE_REDUCTION_TASK (c))
16679 : : {
16680 : : /* Disallow zero sized or potentially zero sized task
16681 : : reductions. */
16682 : 870 : if (integer_zerop (TYPE_SIZE_UNIT (type)))
16683 : : {
16684 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
16685 : : "zero sized type %qT in %qs clause", type,
16686 : 3 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
16687 : 3 : remove = true;
16688 : 3 : break;
16689 : : }
16690 : 867 : else if (TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST)
16691 : : {
16692 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
16693 : : "variable sized type %qT in %qs clause", type,
16694 : 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
16695 : 0 : remove = true;
16696 : 0 : break;
16697 : : }
16698 : : }
16699 : 4152 : if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == NULL_TREE
16700 : 4152 : && (FLOAT_TYPE_P (type)
16701 : 3600 : || TREE_CODE (type) == COMPLEX_TYPE))
16702 : : {
16703 : 340 : enum tree_code r_code = OMP_CLAUSE_REDUCTION_CODE (c);
16704 : 340 : const char *r_name = NULL;
16705 : :
16706 : 340 : switch (r_code)
16707 : : {
16708 : : case PLUS_EXPR:
16709 : : case MULT_EXPR:
16710 : : case MINUS_EXPR:
16711 : : case TRUTH_ANDIF_EXPR:
16712 : : case TRUTH_ORIF_EXPR:
16713 : : break;
16714 : 13 : case MIN_EXPR:
16715 : 13 : if (TREE_CODE (type) == COMPLEX_TYPE)
16716 : : r_name = "min";
16717 : : break;
16718 : 38 : case MAX_EXPR:
16719 : 38 : if (TREE_CODE (type) == COMPLEX_TYPE)
16720 : : r_name = "max";
16721 : : break;
16722 : 3 : case BIT_AND_EXPR:
16723 : 3 : r_name = "&";
16724 : 3 : break;
16725 : 2 : case BIT_XOR_EXPR:
16726 : 2 : r_name = "^";
16727 : 2 : break;
16728 : : case BIT_IOR_EXPR:
16729 : : r_name = "|";
16730 : : break;
16731 : 0 : default:
16732 : 0 : gcc_unreachable ();
16733 : : }
16734 : 5 : if (r_name)
16735 : : {
16736 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
16737 : : "%qE has invalid type for %<reduction(%s)%>",
16738 : : t, r_name);
16739 : 12 : remove = true;
16740 : 12 : break;
16741 : : }
16742 : : }
16743 : 3812 : else if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == error_mark_node)
16744 : : {
16745 : 2 : error_at (OMP_CLAUSE_LOCATION (c),
16746 : : "user defined reduction not found for %qE", t);
16747 : 2 : remove = true;
16748 : 2 : break;
16749 : : }
16750 : 3810 : else if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
16751 : : {
16752 : 277 : tree list = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c);
16753 : 277 : type = TYPE_MAIN_VARIANT (type);
16754 : 277 : tree placeholder = build_decl (OMP_CLAUSE_LOCATION (c),
16755 : : VAR_DECL, NULL_TREE, type);
16756 : 277 : tree decl_placeholder = NULL_TREE;
16757 : 277 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = placeholder;
16758 : 277 : DECL_ARTIFICIAL (placeholder) = 1;
16759 : 277 : DECL_IGNORED_P (placeholder) = 1;
16760 : 277 : if (TREE_CODE (t) == MEM_REF)
16761 : : {
16762 : 56 : decl_placeholder = build_decl (OMP_CLAUSE_LOCATION (c),
16763 : : VAR_DECL, NULL_TREE, type);
16764 : 56 : OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c) = decl_placeholder;
16765 : 56 : DECL_ARTIFICIAL (decl_placeholder) = 1;
16766 : 56 : DECL_IGNORED_P (decl_placeholder) = 1;
16767 : : }
16768 : 277 : if (TREE_ADDRESSABLE (TREE_VEC_ELT (list, 0)))
16769 : 42 : c_mark_addressable (placeholder);
16770 : 277 : if (TREE_ADDRESSABLE (TREE_VEC_ELT (list, 1)))
16771 : 76 : c_mark_addressable (decl_placeholder ? decl_placeholder
16772 : 34 : : OMP_CLAUSE_DECL (c));
16773 : 277 : OMP_CLAUSE_REDUCTION_MERGE (c)
16774 : 775 : = c_clone_omp_udr (TREE_VEC_ELT (list, 2),
16775 : 277 : TREE_VEC_ELT (list, 0),
16776 : 277 : TREE_VEC_ELT (list, 1),
16777 : : decl_placeholder ? decl_placeholder
16778 : 221 : : OMP_CLAUSE_DECL (c), placeholder);
16779 : 277 : OMP_CLAUSE_REDUCTION_MERGE (c)
16780 : 277 : = build3_loc (OMP_CLAUSE_LOCATION (c), BIND_EXPR,
16781 : : void_type_node, NULL_TREE,
16782 : 277 : OMP_CLAUSE_REDUCTION_MERGE (c), NULL_TREE);
16783 : 277 : TREE_SIDE_EFFECTS (OMP_CLAUSE_REDUCTION_MERGE (c)) = 1;
16784 : 277 : if (TREE_VEC_LENGTH (list) == 6)
16785 : : {
16786 : 233 : if (TREE_ADDRESSABLE (TREE_VEC_ELT (list, 3)))
16787 : 70 : c_mark_addressable (decl_placeholder ? decl_placeholder
16788 : 33 : : OMP_CLAUSE_DECL (c));
16789 : 233 : if (TREE_ADDRESSABLE (TREE_VEC_ELT (list, 4)))
16790 : 27 : c_mark_addressable (placeholder);
16791 : 233 : tree init = TREE_VEC_ELT (list, 5);
16792 : 233 : if (init == error_mark_node)
16793 : 197 : init = DECL_INITIAL (TREE_VEC_ELT (list, 3));
16794 : 233 : OMP_CLAUSE_REDUCTION_INIT (c)
16795 : 651 : = c_clone_omp_udr (init, TREE_VEC_ELT (list, 4),
16796 : 233 : TREE_VEC_ELT (list, 3),
16797 : : decl_placeholder ? decl_placeholder
16798 : 185 : : OMP_CLAUSE_DECL (c), placeholder);
16799 : 233 : if (TREE_VEC_ELT (list, 5) == error_mark_node)
16800 : : {
16801 : 197 : tree v = decl_placeholder ? decl_placeholder : t;
16802 : 197 : OMP_CLAUSE_REDUCTION_INIT (c)
16803 : 394 : = build2 (INIT_EXPR, TREE_TYPE (v), v,
16804 : 197 : OMP_CLAUSE_REDUCTION_INIT (c));
16805 : : }
16806 : 233 : if (walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c),
16807 : : c_find_omp_placeholder_r,
16808 : : placeholder, NULL))
16809 : 28 : OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c) = 1;
16810 : : }
16811 : : else
16812 : : {
16813 : 44 : tree init;
16814 : 44 : tree v = decl_placeholder ? decl_placeholder : t;
16815 : 44 : if (AGGREGATE_TYPE_P (TREE_TYPE (v)))
16816 : 34 : init = build_constructor (TREE_TYPE (v), NULL);
16817 : : else
16818 : 10 : init = fold_convert (TREE_TYPE (v), integer_zero_node);
16819 : 44 : OMP_CLAUSE_REDUCTION_INIT (c)
16820 : 88 : = build2 (INIT_EXPR, TREE_TYPE (v), v, init);
16821 : : }
16822 : 277 : OMP_CLAUSE_REDUCTION_INIT (c)
16823 : 277 : = build3_loc (OMP_CLAUSE_LOCATION (c), BIND_EXPR,
16824 : : void_type_node, NULL_TREE,
16825 : 277 : OMP_CLAUSE_REDUCTION_INIT (c), NULL_TREE);
16826 : 277 : TREE_SIDE_EFFECTS (OMP_CLAUSE_REDUCTION_INIT (c)) = 1;
16827 : : }
16828 : 4138 : if (TREE_CODE (t) == MEM_REF)
16829 : : {
16830 : 607 : if (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t))) == NULL_TREE
16831 : 607 : || TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t))))
16832 : : != INTEGER_CST)
16833 : : {
16834 : 0 : sorry ("variable length element type in array "
16835 : : "%<reduction%> clause");
16836 : 0 : remove = true;
16837 : 0 : break;
16838 : : }
16839 : 607 : t = TREE_OPERAND (t, 0);
16840 : 607 : if (TREE_CODE (t) == POINTER_PLUS_EXPR)
16841 : 139 : t = TREE_OPERAND (t, 0);
16842 : 607 : if (TREE_CODE (t) == ADDR_EXPR)
16843 : 367 : t = TREE_OPERAND (t, 0);
16844 : : }
16845 : 4138 : goto check_dup_generic_t;
16846 : :
16847 : 24 : case OMP_CLAUSE_COPYPRIVATE:
16848 : 24 : copyprivate_seen = true;
16849 : 24 : if (nowait_clause)
16850 : : {
16851 : 1 : error_at (OMP_CLAUSE_LOCATION (*nowait_clause),
16852 : : "%<nowait%> clause must not be used together "
16853 : : "with %<copyprivate%> clause");
16854 : 1 : *nowait_clause = OMP_CLAUSE_CHAIN (*nowait_clause);
16855 : 1 : nowait_clause = NULL;
16856 : : }
16857 : 24 : goto check_dup_generic;
16858 : :
16859 : 99 : case OMP_CLAUSE_COPYIN:
16860 : 99 : t = OMP_CLAUSE_DECL (c);
16861 : 99 : if (!VAR_P (t) || !DECL_THREAD_LOCAL_P (t))
16862 : : {
16863 : 5 : error_at (OMP_CLAUSE_LOCATION (c),
16864 : : "%qE must be %<threadprivate%> for %<copyin%>", t);
16865 : 5 : remove = true;
16866 : 5 : break;
16867 : : }
16868 : 94 : goto check_dup_generic;
16869 : :
16870 : 478 : case OMP_CLAUSE_LINEAR:
16871 : 478 : if (ort != C_ORT_OMP_DECLARE_SIMD)
16872 : 327 : need_implicitly_determined = true;
16873 : 478 : t = OMP_CLAUSE_DECL (c);
16874 : 478 : if (ort != C_ORT_OMP_DECLARE_SIMD
16875 : 327 : && OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_DEFAULT
16876 : 483 : && OMP_CLAUSE_LINEAR_OLD_LINEAR_MODIFIER (c))
16877 : : {
16878 : 5 : error_at (OMP_CLAUSE_LOCATION (c),
16879 : : "modifier should not be specified in %<linear%> "
16880 : : "clause on %<simd%> or %<for%> constructs when not "
16881 : : "using OpenMP 5.2 modifiers");
16882 : 5 : OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT;
16883 : : }
16884 : 956 : if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
16885 : 501 : && TREE_CODE (TREE_TYPE (t)) != POINTER_TYPE)
16886 : : {
16887 : 1 : error_at (OMP_CLAUSE_LOCATION (c),
16888 : : "linear clause applied to non-integral non-pointer "
16889 : 1 : "variable with type %qT", TREE_TYPE (t));
16890 : 1 : remove = true;
16891 : 1 : break;
16892 : : }
16893 : 477 : if (TYPE_ATOMIC (TREE_TYPE (t)))
16894 : : {
16895 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
16896 : : "%<_Atomic%> %qD in %<linear%> clause", t);
16897 : 3 : remove = true;
16898 : 3 : break;
16899 : : }
16900 : 474 : if (ort == C_ORT_OMP_DECLARE_SIMD)
16901 : : {
16902 : 150 : tree s = OMP_CLAUSE_LINEAR_STEP (c);
16903 : 150 : if (TREE_CODE (s) == PARM_DECL)
16904 : : {
16905 : 9 : OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c) = 1;
16906 : : /* map_head bitmap is used as uniform_head if
16907 : : declare_simd. */
16908 : 9 : if (!bitmap_bit_p (&map_head, DECL_UID (s)))
16909 : 5 : linear_variable_step_check = true;
16910 : 9 : goto check_dup_generic;
16911 : : }
16912 : 141 : if (TREE_CODE (s) != INTEGER_CST)
16913 : : {
16914 : 7 : error_at (OMP_CLAUSE_LOCATION (c),
16915 : : "%<linear%> clause step %qE is neither constant "
16916 : : "nor a parameter", s);
16917 : 7 : remove = true;
16918 : 7 : break;
16919 : : }
16920 : : }
16921 : 458 : if (TREE_CODE (TREE_TYPE (OMP_CLAUSE_DECL (c))) == POINTER_TYPE)
16922 : : {
16923 : 20 : tree s = OMP_CLAUSE_LINEAR_STEP (c);
16924 : 20 : s = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
16925 : 20 : OMP_CLAUSE_DECL (c), s);
16926 : 20 : s = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
16927 : : sizetype, fold_convert (sizetype, s),
16928 : 20 : fold_convert
16929 : : (sizetype, OMP_CLAUSE_DECL (c)));
16930 : 20 : if (s == error_mark_node)
16931 : 0 : s = size_one_node;
16932 : 20 : OMP_CLAUSE_LINEAR_STEP (c) = s;
16933 : : }
16934 : : else
16935 : 438 : OMP_CLAUSE_LINEAR_STEP (c)
16936 : 876 : = fold_convert (TREE_TYPE (t), OMP_CLAUSE_LINEAR_STEP (c));
16937 : 458 : goto check_dup_generic;
16938 : :
16939 : 2873 : check_dup_generic:
16940 : 2873 : t = OMP_CLAUSE_DECL (c);
16941 : 7099 : check_dup_generic_t:
16942 : 7099 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
16943 : : {
16944 : 4 : error_at (OMP_CLAUSE_LOCATION (c),
16945 : : "%qE is not a variable in clause %qs", t,
16946 : 2 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
16947 : 2 : remove = true;
16948 : : }
16949 : 1149 : else if ((openacc && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
16950 : 6058 : || (ort == C_ORT_OMP
16951 : 5350 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
16952 : 5339 : || (OMP_CLAUSE_CODE (c)
16953 : : == OMP_CLAUSE_USE_DEVICE_ADDR)))
16954 : 13108 : || (ort == C_ORT_OMP_TARGET
16955 : 338 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION))
16956 : : {
16957 : 1196 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
16958 : 1196 : && (bitmap_bit_p (&generic_head, DECL_UID (t))
16959 : 109 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))))
16960 : : {
16961 : 2 : error_at (OMP_CLAUSE_LOCATION (c),
16962 : : "%qD appears more than once in data-sharing "
16963 : : "clauses", t);
16964 : 2 : remove = true;
16965 : 2 : break;
16966 : : }
16967 : 1194 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION)
16968 : 108 : target_in_reduction_seen = true;
16969 : 1194 : if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
16970 : : {
16971 : 4 : error_at (OMP_CLAUSE_LOCATION (c),
16972 : : openacc
16973 : : ? "%qD appears more than once in reduction clauses"
16974 : : : "%qD appears more than once in data clauses",
16975 : : t);
16976 : 2 : remove = true;
16977 : : }
16978 : : else
16979 : 1192 : bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
16980 : : }
16981 : 5901 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
16982 : 5879 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
16983 : 5878 : || bitmap_bit_p (&lastprivate_head, DECL_UID (t))
16984 : 11779 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
16985 : : {
16986 : 23 : error_at (OMP_CLAUSE_LOCATION (c),
16987 : : "%qE appears more than once in data clauses", t);
16988 : 23 : remove = true;
16989 : : }
16990 : 5878 : else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
16991 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR
16992 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
16993 : 1037 : && bitmap_bit_p (&map_head, DECL_UID (t)))
16994 : : {
16995 : 3 : if (openacc)
16996 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
16997 : : "%qD appears more than once in data clauses", t);
16998 : : else
16999 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
17000 : : "%qD appears both in data and map clauses", t);
17001 : : remove = true;
17002 : : }
17003 : : else
17004 : 5875 : bitmap_set_bit (&generic_head, DECL_UID (t));
17005 : : break;
17006 : :
17007 : 1320 : case OMP_CLAUSE_FIRSTPRIVATE:
17008 : 1320 : if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c) && !implicit_moved)
17009 : : {
17010 : 186 : move_implicit:
17011 : 186 : implicit_moved = true;
17012 : : /* Move firstprivate and map clauses with
17013 : : OMP_CLAUSE_{FIRSTPRIVATE,MAP}_IMPLICIT set to the end of
17014 : : clauses chain. */
17015 : 186 : tree cl1 = NULL_TREE, cl2 = NULL_TREE;
17016 : 186 : tree *pc1 = pc, *pc2 = &cl1, *pc3 = &cl2;
17017 : 1072 : while (*pc1)
17018 : 886 : if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_FIRSTPRIVATE
17019 : 886 : && OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (*pc1))
17020 : : {
17021 : 113 : *pc3 = *pc1;
17022 : 113 : pc3 = &OMP_CLAUSE_CHAIN (*pc3);
17023 : 113 : *pc1 = OMP_CLAUSE_CHAIN (*pc1);
17024 : : }
17025 : 773 : else if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_MAP
17026 : 773 : && OMP_CLAUSE_MAP_IMPLICIT (*pc1))
17027 : : {
17028 : 164 : *pc2 = *pc1;
17029 : 164 : pc2 = &OMP_CLAUSE_CHAIN (*pc2);
17030 : 164 : *pc1 = OMP_CLAUSE_CHAIN (*pc1);
17031 : : }
17032 : : else
17033 : 609 : pc1 = &OMP_CLAUSE_CHAIN (*pc1);
17034 : 186 : *pc3 = NULL;
17035 : 186 : *pc2 = cl2;
17036 : 186 : *pc1 = cl1;
17037 : 186 : continue;
17038 : 186 : }
17039 : 1225 : t = OMP_CLAUSE_DECL (c);
17040 : 1225 : need_complete = true;
17041 : 1225 : need_implicitly_determined = true;
17042 : 1225 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
17043 : : {
17044 : 1 : error_at (OMP_CLAUSE_LOCATION (c),
17045 : : "%qE is not a variable in clause %<firstprivate%>", t);
17046 : 1 : remove = true;
17047 : : }
17048 : 1224 : else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
17049 : 113 : && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c)
17050 : 1330 : && bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
17051 : : remove = true;
17052 : 1224 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
17053 : 1222 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
17054 : 2445 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
17055 : : {
17056 : 4 : error_at (OMP_CLAUSE_LOCATION (c),
17057 : : "%qE appears more than once in data clauses", t);
17058 : 4 : remove = true;
17059 : : }
17060 : 1220 : else if (bitmap_bit_p (&map_head, DECL_UID (t))
17061 : 1220 : || bitmap_bit_p (&map_field_head, DECL_UID (t)))
17062 : : {
17063 : 7 : if (openacc)
17064 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
17065 : : "%qD appears more than once in data clauses", t);
17066 : 7 : else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
17067 : 7 : && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c))
17068 : : /* Silently drop the clause. */;
17069 : : else
17070 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
17071 : : "%qD appears both in data and map clauses", t);
17072 : : remove = true;
17073 : : }
17074 : : else
17075 : 1213 : bitmap_set_bit (&firstprivate_head, DECL_UID (t));
17076 : : break;
17077 : :
17078 : 1522 : case OMP_CLAUSE_LASTPRIVATE:
17079 : 1522 : t = OMP_CLAUSE_DECL (c);
17080 : 1522 : need_complete = true;
17081 : 1522 : need_implicitly_determined = true;
17082 : 1522 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
17083 : : {
17084 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
17085 : : "%qE is not a variable in clause %<lastprivate%>", t);
17086 : 0 : remove = true;
17087 : : }
17088 : 1522 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
17089 : 1522 : || bitmap_bit_p (&lastprivate_head, DECL_UID (t)))
17090 : : {
17091 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
17092 : : "%qE appears more than once in data clauses", t);
17093 : 3 : remove = true;
17094 : : }
17095 : : else
17096 : 1519 : bitmap_set_bit (&lastprivate_head, DECL_UID (t));
17097 : : break;
17098 : :
17099 : 253 : case OMP_CLAUSE_ALIGNED:
17100 : 253 : t = OMP_CLAUSE_DECL (c);
17101 : 253 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
17102 : : {
17103 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
17104 : : "%qE is not a variable in %<aligned%> clause", t);
17105 : 0 : remove = true;
17106 : : }
17107 : 289 : else if (!POINTER_TYPE_P (TREE_TYPE (t))
17108 : 289 : && TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE)
17109 : : {
17110 : 7 : error_at (OMP_CLAUSE_LOCATION (c),
17111 : : "%qE in %<aligned%> clause is neither a pointer nor "
17112 : : "an array", t);
17113 : 7 : remove = true;
17114 : : }
17115 : 246 : else if (TYPE_ATOMIC (TREE_TYPE (t)))
17116 : : {
17117 : 1 : error_at (OMP_CLAUSE_LOCATION (c),
17118 : : "%<_Atomic%> %qD in %<aligned%> clause", t);
17119 : 1 : remove = true;
17120 : 1 : break;
17121 : : }
17122 : 245 : else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
17123 : : {
17124 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
17125 : : "%qE appears more than once in %<aligned%> clauses",
17126 : : t);
17127 : 0 : remove = true;
17128 : : }
17129 : : else
17130 : 245 : bitmap_set_bit (&aligned_head, DECL_UID (t));
17131 : : break;
17132 : :
17133 : 125 : case OMP_CLAUSE_NONTEMPORAL:
17134 : 125 : t = OMP_CLAUSE_DECL (c);
17135 : 125 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
17136 : : {
17137 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
17138 : : "%qE is not a variable in %<nontemporal%> clause", t);
17139 : 0 : remove = true;
17140 : : }
17141 : 125 : else if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
17142 : : {
17143 : 2 : error_at (OMP_CLAUSE_LOCATION (c),
17144 : : "%qE appears more than once in %<nontemporal%> "
17145 : : "clauses", t);
17146 : 2 : remove = true;
17147 : : }
17148 : : else
17149 : 123 : bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
17150 : : break;
17151 : :
17152 : 786 : case OMP_CLAUSE_ALLOCATE:
17153 : 786 : t = OMP_CLAUSE_DECL (c);
17154 : 786 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
17155 : : {
17156 : 1 : error_at (OMP_CLAUSE_LOCATION (c),
17157 : : "%qE is not a variable in %<allocate%> clause", t);
17158 : 1 : remove = true;
17159 : : }
17160 : 785 : else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
17161 : : {
17162 : 2 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
17163 : : "%qE appears more than once in %<allocate%> clauses",
17164 : : t);
17165 : 2 : remove = true;
17166 : : }
17167 : : else
17168 : : {
17169 : 783 : bitmap_set_bit (&aligned_head, DECL_UID (t));
17170 : 783 : if (!OMP_CLAUSE_ALLOCATE_COMBINED (c))
17171 : 684 : allocate_seen = true;
17172 : : }
17173 : : break;
17174 : :
17175 : 355 : case OMP_CLAUSE_DOACROSS:
17176 : 355 : t = OMP_CLAUSE_DECL (c);
17177 : 355 : if (t == NULL_TREE)
17178 : : break;
17179 : 168 : if (OMP_CLAUSE_DOACROSS_KIND (c) == OMP_CLAUSE_DOACROSS_SINK)
17180 : : {
17181 : 168 : gcc_assert (TREE_CODE (t) == TREE_LIST);
17182 : 1313 : for (; t; t = TREE_CHAIN (t))
17183 : : {
17184 : 1145 : tree decl = TREE_VALUE (t);
17185 : 1145 : if (TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE)
17186 : : {
17187 : 3 : tree offset = TREE_PURPOSE (t);
17188 : 3 : bool neg = wi::neg_p (wi::to_wide (offset));
17189 : 3 : offset = fold_unary (ABS_EXPR, TREE_TYPE (offset), offset);
17190 : 6 : tree t2 = pointer_int_sum (OMP_CLAUSE_LOCATION (c),
17191 : : neg ? MINUS_EXPR : PLUS_EXPR,
17192 : : decl, offset);
17193 : 3 : t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
17194 : : sizetype,
17195 : : fold_convert (sizetype, t2),
17196 : : fold_convert (sizetype, decl));
17197 : 3 : if (t2 == error_mark_node)
17198 : : {
17199 : : remove = true;
17200 : : break;
17201 : : }
17202 : 3 : TREE_PURPOSE (t) = t2;
17203 : : }
17204 : : }
17205 : : break;
17206 : : }
17207 : 0 : gcc_unreachable ();
17208 : 713 : case OMP_CLAUSE_DEPEND:
17209 : 713 : depend_clause = c;
17210 : : /* FALLTHRU */
17211 : 870 : case OMP_CLAUSE_AFFINITY:
17212 : 870 : t = OMP_CLAUSE_DECL (c);
17213 : 870 : if (OMP_ITERATOR_DECL_P (t))
17214 : : {
17215 : 131 : if (TREE_PURPOSE (t) != last_iterators)
17216 : 111 : last_iterators_remove
17217 : 111 : = c_omp_finish_iterators (TREE_PURPOSE (t));
17218 : 131 : last_iterators = TREE_PURPOSE (t);
17219 : 131 : t = TREE_VALUE (t);
17220 : 131 : if (last_iterators_remove)
17221 : 34 : t = error_mark_node;
17222 : : }
17223 : : else
17224 : : last_iterators = NULL_TREE;
17225 : 870 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
17226 : : {
17227 : 413 : if (handle_omp_array_sections (c, ort))
17228 : : remove = true;
17229 : 336 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
17230 : 336 : && OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ)
17231 : : {
17232 : 1 : error_at (OMP_CLAUSE_LOCATION (c),
17233 : : "%<depend%> clause with %<depobj%> dependence "
17234 : : "type on array section");
17235 : 1 : remove = true;
17236 : : }
17237 : : break;
17238 : : }
17239 : 457 : if (t == error_mark_node)
17240 : : remove = true;
17241 : 423 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
17242 : 423 : && t == ridpointers[RID_OMP_ALL_MEMORY])
17243 : : {
17244 : 15 : if (OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_OUT
17245 : 15 : && OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_INOUT)
17246 : : {
17247 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
17248 : : "%<omp_all_memory%> used with %<depend%> kind "
17249 : : "other than %<out%> or %<inout%>");
17250 : 3 : remove = true;
17251 : : }
17252 : : }
17253 : 408 : else if (!lvalue_p (t))
17254 : : {
17255 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
17256 : : "%qE is not lvalue expression nor array section in "
17257 : : "%qs clause", t,
17258 : 3 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
17259 : 3 : remove = true;
17260 : : }
17261 : 405 : else if (TREE_CODE (t) == COMPONENT_REF
17262 : 405 : && DECL_C_BIT_FIELD (TREE_OPERAND (t, 1)))
17263 : : {
17264 : 2 : gcc_assert (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
17265 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY);
17266 : 2 : error_at (OMP_CLAUSE_LOCATION (c),
17267 : : "bit-field %qE in %qs clause", t,
17268 : 2 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
17269 : 2 : remove = true;
17270 : : }
17271 : 403 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
17272 : 403 : && OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ)
17273 : : {
17274 : 20 : if (!c_omp_depend_t_p (TREE_TYPE (t)))
17275 : : {
17276 : 2 : error_at (OMP_CLAUSE_LOCATION (c),
17277 : : "%qE does not have %<omp_depend_t%> type in "
17278 : : "%<depend%> clause with %<depobj%> dependence "
17279 : : "type", t);
17280 : 2 : remove = true;
17281 : : }
17282 : : }
17283 : 383 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
17284 : 383 : && c_omp_depend_t_p (TREE_TYPE (t)))
17285 : : {
17286 : 2 : error_at (OMP_CLAUSE_LOCATION (c),
17287 : : "%qE should not have %<omp_depend_t%> type in "
17288 : : "%<depend%> clause with dependence type other than "
17289 : : "%<depobj%>", t);
17290 : 2 : remove = true;
17291 : : }
17292 : 12 : if (!remove)
17293 : : {
17294 : 411 : if (t == ridpointers[RID_OMP_ALL_MEMORY])
17295 : 12 : t = null_pointer_node;
17296 : : else
17297 : : {
17298 : 399 : tree addr = build_unary_op (OMP_CLAUSE_LOCATION (c),
17299 : : ADDR_EXPR, t, false);
17300 : 399 : if (addr == error_mark_node)
17301 : : {
17302 : : remove = true;
17303 : : break;
17304 : : }
17305 : 399 : t = build_indirect_ref (OMP_CLAUSE_LOCATION (c), addr,
17306 : : RO_UNARY_STAR);
17307 : 399 : if (t == error_mark_node)
17308 : : {
17309 : : remove = true;
17310 : : break;
17311 : : }
17312 : : }
17313 : 411 : if (OMP_ITERATOR_DECL_P (OMP_CLAUSE_DECL (c)))
17314 : 31 : TREE_VALUE (OMP_CLAUSE_DECL (c)) = t;
17315 : : else
17316 : 380 : OMP_CLAUSE_DECL (c) = t;
17317 : : }
17318 : : break;
17319 : :
17320 : 6532 : case OMP_CLAUSE_MAP:
17321 : 6532 : if (OMP_CLAUSE_MAP_IMPLICIT (c) && !implicit_moved)
17322 : 91 : goto move_implicit;
17323 : 6441 : if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_PUSH_MAPPER_NAME
17324 : 6441 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POP_MAPPER_NAME)
17325 : : {
17326 : : remove = true;
17327 : : break;
17328 : : }
17329 : : /* FALLTHRU */
17330 : 9294 : case OMP_CLAUSE_TO:
17331 : 9294 : case OMP_CLAUSE_FROM:
17332 : 9294 : if (OMP_CLAUSE_ITERATORS (c)
17333 : 9294 : && c_omp_finish_iterators (OMP_CLAUSE_ITERATORS (c)))
17334 : : {
17335 : 22634 : t = error_mark_node;
17336 : : break;
17337 : : }
17338 : : /* FALLTHRU */
17339 : 9430 : case OMP_CLAUSE__CACHE_:
17340 : 9430 : {
17341 : 9430 : using namespace omp_addr_tokenizer;
17342 : 9430 : auto_vec<omp_addr_token *, 10> addr_tokens;
17343 : :
17344 : 9430 : t = OMP_CLAUSE_DECL (c);
17345 : 9430 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
17346 : : {
17347 : 1995 : grp_start_p = pc;
17348 : 1995 : grp_sentinel = OMP_CLAUSE_CHAIN (c);
17349 : :
17350 : 1995 : if (handle_omp_array_sections (c, ort))
17351 : : remove = true;
17352 : : else
17353 : : {
17354 : 1855 : t = OMP_CLAUSE_DECL (c);
17355 : 1855 : if (!omp_mappable_type (TREE_TYPE (t)))
17356 : : {
17357 : 2 : error_at (OMP_CLAUSE_LOCATION (c),
17358 : : "array section does not have mappable type "
17359 : : "in %qs clause",
17360 : 1 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
17361 : 1 : remove = true;
17362 : : }
17363 : 1854 : else if (TYPE_ATOMIC (TREE_TYPE (t)))
17364 : : {
17365 : 2 : error_at (OMP_CLAUSE_LOCATION (c),
17366 : : "%<_Atomic%> %qE in %qs clause", t,
17367 : 1 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
17368 : 1 : remove = true;
17369 : : }
17370 : 2498 : while (TREE_CODE (t) == ARRAY_REF)
17371 : 643 : t = TREE_OPERAND (t, 0);
17372 : :
17373 : 1855 : c_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
17374 : :
17375 : 1855 : if (!omp_parse_expr (addr_tokens, t))
17376 : : {
17377 : 0 : sorry_at (OMP_CLAUSE_LOCATION (c),
17378 : : "unsupported map expression %qE",
17379 : 0 : OMP_CLAUSE_DECL (c));
17380 : 0 : remove = true;
17381 : 0 : break;
17382 : : }
17383 : :
17384 : : /* This check is to determine if this will be the only map
17385 : : node created for this clause. Otherwise, we'll check
17386 : : the following FIRSTPRIVATE_POINTER or ATTACH_DETACH
17387 : : node on the next iteration(s) of the loop. */
17388 : 3692 : if (addr_tokens.length () >= 4
17389 : 304 : && addr_tokens[0]->type == STRUCTURE_BASE
17390 : 302 : && addr_tokens[0]->u.structure_base_kind == BASE_DECL
17391 : 302 : && addr_tokens[1]->type == ACCESS_METHOD
17392 : 302 : && addr_tokens[2]->type == COMPONENT_SELECTOR
17393 : 302 : && addr_tokens[3]->type == ACCESS_METHOD
17394 : 2096 : && (addr_tokens[3]->u.access_kind == ACCESS_DIRECT
17395 : 188 : || (addr_tokens[3]->u.access_kind
17396 : : == ACCESS_INDEXED_ARRAY)))
17397 : : {
17398 : 55 : tree rt = addr_tokens[1]->expr;
17399 : :
17400 : 55 : gcc_assert (DECL_P (rt));
17401 : :
17402 : 55 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
17403 : 50 : && OMP_CLAUSE_MAP_IMPLICIT (c)
17404 : 55 : && (bitmap_bit_p (&map_head, DECL_UID (rt))
17405 : 0 : || bitmap_bit_p (&map_field_head, DECL_UID (rt))
17406 : 0 : || bitmap_bit_p (&map_firstprivate_head,
17407 : 0 : DECL_UID (rt))))
17408 : : {
17409 : : remove = true;
17410 : : break;
17411 : : }
17412 : 55 : if (bitmap_bit_p (&map_field_head, DECL_UID (rt)))
17413 : : break;
17414 : 37 : if (bitmap_bit_p (&map_head, DECL_UID (rt)))
17415 : : {
17416 : 0 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
17417 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
17418 : : "%qD appears more than once in motion "
17419 : : "clauses", rt);
17420 : 0 : else if (openacc)
17421 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
17422 : : "%qD appears more than once in data "
17423 : : "clauses", rt);
17424 : : else
17425 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
17426 : : "%qD appears more than once in map "
17427 : : "clauses", rt);
17428 : : remove = true;
17429 : : }
17430 : : else
17431 : : {
17432 : 37 : bitmap_set_bit (&map_head, DECL_UID (rt));
17433 : 37 : bitmap_set_bit (&map_field_head, DECL_UID (rt));
17434 : : }
17435 : : }
17436 : 1855 : }
17437 : 1977 : if (c_oacc_check_attachments (c))
17438 : 2 : remove = true;
17439 : 1977 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
17440 : 1801 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
17441 : 1783 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
17442 : 2002 : && !OMP_CLAUSE_SIZE (c))
17443 : : /* In this case, we have a single array element which is a
17444 : : pointer, and we already set OMP_CLAUSE_SIZE in
17445 : : handle_omp_array_sections above. For attach/detach
17446 : : clauses, reset the OMP_CLAUSE_SIZE (representing a bias)
17447 : : to zero here. */
17448 : 10 : OMP_CLAUSE_SIZE (c) = size_zero_node;
17449 : : break;
17450 : : }
17451 : 7435 : else if (!omp_parse_expr (addr_tokens, t))
17452 : : {
17453 : 0 : sorry_at (OMP_CLAUSE_LOCATION (c),
17454 : : "unsupported map expression %qE",
17455 : 0 : OMP_CLAUSE_DECL (c));
17456 : 0 : remove = true;
17457 : 0 : break;
17458 : : }
17459 : 7435 : if (t == error_mark_node)
17460 : : {
17461 : : remove = true;
17462 : : break;
17463 : : }
17464 : : /* OpenACC attach / detach clauses must be pointers. */
17465 : 7429 : if (c_oacc_check_attachments (c))
17466 : : {
17467 : : remove = true;
17468 : : break;
17469 : : }
17470 : 7425 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
17471 : 4606 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
17472 : 4579 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
17473 : 7467 : && !OMP_CLAUSE_SIZE (c))
17474 : : /* For attach/detach clauses, set OMP_CLAUSE_SIZE (representing a
17475 : : bias) to zero here, so it is not set erroneously to the pointer
17476 : : size later on in gimplify.cc. */
17477 : 28 : OMP_CLAUSE_SIZE (c) = size_zero_node;
17478 : :
17479 : 7425 : c_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
17480 : :
17481 : 7425 : if (!ai.check_clause (c))
17482 : : {
17483 : : remove = true;
17484 : : break;
17485 : : }
17486 : :
17487 : 7417 : if (!ai.map_supported_p ())
17488 : : {
17489 : 14 : sorry_at (OMP_CLAUSE_LOCATION (c),
17490 : : "unsupported map expression %qE",
17491 : 7 : OMP_CLAUSE_DECL (c));
17492 : 7 : remove = true;
17493 : 7 : break;
17494 : : }
17495 : :
17496 : 14820 : gcc_assert ((addr_tokens[0]->type == ARRAY_BASE
17497 : : || addr_tokens[0]->type == STRUCTURE_BASE)
17498 : : && addr_tokens[1]->type == ACCESS_METHOD);
17499 : :
17500 : 7410 : t = addr_tokens[1]->expr;
17501 : :
17502 : 7410 : if (addr_tokens[0]->u.structure_base_kind != BASE_DECL)
17503 : 0 : goto skip_decl_checks;
17504 : :
17505 : : /* For OpenMP, we can access a struct "t" and "t.d" on the same
17506 : : mapping. OpenACC allows multiple fields of the same structure
17507 : : to be written. */
17508 : 7410 : if (addr_tokens[0]->type == STRUCTURE_BASE
17509 : 7410 : && (bitmap_bit_p (&map_field_head, DECL_UID (t))
17510 : 238 : || (!openacc && bitmap_bit_p (&map_head, DECL_UID (t)))))
17511 : 246 : goto skip_decl_checks;
17512 : :
17513 : 7164 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
17514 : : {
17515 : 3 : if (ort != C_ORT_ACC && EXPR_P (t))
17516 : : break;
17517 : :
17518 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
17519 : : "%qE is not a variable in %qs clause", t,
17520 : 3 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
17521 : 3 : remove = true;
17522 : : }
17523 : 7161 : else if (VAR_P (t) && DECL_THREAD_LOCAL_P (t))
17524 : : {
17525 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
17526 : : "%qD is threadprivate variable in %qs clause", t,
17527 : 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
17528 : 0 : remove = true;
17529 : : }
17530 : 7161 : else if ((OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
17531 : 4349 : || (OMP_CLAUSE_MAP_KIND (c)
17532 : : != GOMP_MAP_FIRSTPRIVATE_POINTER))
17533 : 10472 : && !c_mark_addressable (t))
17534 : : remove = true;
17535 : 7161 : else if (!(OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
17536 : 4349 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
17537 : 4349 : || (OMP_CLAUSE_MAP_KIND (c)
17538 : : == GOMP_MAP_FIRSTPRIVATE_POINTER)
17539 : 3311 : || (OMP_CLAUSE_MAP_KIND (c)
17540 : : == GOMP_MAP_FORCE_DEVICEPTR)))
17541 : 6065 : && t == OMP_CLAUSE_DECL (c)
17542 : 12990 : && !omp_mappable_type (TREE_TYPE (t)))
17543 : : {
17544 : 16 : error_at (OMP_CLAUSE_LOCATION (c),
17545 : : "%qD does not have a mappable type in %qs clause", t,
17546 : 8 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
17547 : 8 : remove = true;
17548 : : }
17549 : 7153 : else if (TREE_TYPE (t) == error_mark_node)
17550 : : remove = true;
17551 : 7152 : else if (TYPE_ATOMIC (strip_array_types (TREE_TYPE (t))))
17552 : : {
17553 : 8 : error_at (OMP_CLAUSE_LOCATION (c),
17554 : : "%<_Atomic%> %qE in %qs clause", t,
17555 : 4 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
17556 : 4 : remove = true;
17557 : : }
17558 : 7148 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
17559 : 4339 : && OMP_CLAUSE_MAP_IMPLICIT (c)
17560 : 7312 : && (bitmap_bit_p (&map_head, DECL_UID (t))
17561 : 128 : || bitmap_bit_p (&map_field_head, DECL_UID (t))
17562 : 128 : || bitmap_bit_p (&map_firstprivate_head,
17563 : 128 : DECL_UID (t))))
17564 : : remove = true;
17565 : 7111 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
17566 : 7111 : && (OMP_CLAUSE_MAP_KIND (c)
17567 : : == GOMP_MAP_FIRSTPRIVATE_POINTER))
17568 : : {
17569 : 1036 : if (bitmap_bit_p (&generic_head, DECL_UID (t))
17570 : 1036 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
17571 : 2071 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
17572 : : {
17573 : 5 : error_at (OMP_CLAUSE_LOCATION (c),
17574 : : "%qD appears more than once in data clauses", t);
17575 : 5 : remove = true;
17576 : : }
17577 : 1031 : else if (bitmap_bit_p (&map_head, DECL_UID (t))
17578 : 4 : && !bitmap_bit_p (&map_field_head, DECL_UID (t))
17579 : 1033 : && openacc)
17580 : : {
17581 : 1 : error_at (OMP_CLAUSE_LOCATION (c),
17582 : : "%qD appears more than once in data clauses", t);
17583 : 1 : remove = true;
17584 : : }
17585 : : else
17586 : 1030 : bitmap_set_bit (&map_firstprivate_head, DECL_UID (t));
17587 : : }
17588 : 6075 : else if (bitmap_bit_p (&map_head, DECL_UID (t))
17589 : 59 : && !bitmap_bit_p (&map_field_head, DECL_UID (t))
17590 : 13 : && ort != C_ORT_OMP
17591 : 6088 : && ort != C_ORT_OMP_EXIT_DATA)
17592 : : {
17593 : 10 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
17594 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
17595 : : "%qD appears more than once in motion clauses", t);
17596 : 10 : else if (openacc)
17597 : 7 : error_at (OMP_CLAUSE_LOCATION (c),
17598 : : "%qD appears more than once in data clauses", t);
17599 : : else
17600 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
17601 : : "%qD appears more than once in map clauses", t);
17602 : : remove = true;
17603 : : }
17604 : 6065 : else if (openacc && bitmap_bit_p (&generic_head, DECL_UID (t)))
17605 : : {
17606 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
17607 : : "%qD appears more than once in data clauses", t);
17608 : 0 : remove = true;
17609 : : }
17610 : 6065 : else if (bitmap_bit_p (&firstprivate_head, DECL_UID (t))
17611 : 6065 : || bitmap_bit_p (&is_on_device_head, DECL_UID (t)))
17612 : : {
17613 : 9 : if (openacc)
17614 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
17615 : : "%qD appears more than once in data clauses", t);
17616 : : else
17617 : 9 : error_at (OMP_CLAUSE_LOCATION (c),
17618 : : "%qD appears both in data and map clauses", t);
17619 : : remove = true;
17620 : : }
17621 : 6056 : else if (!omp_access_chain_p (addr_tokens, 1))
17622 : : {
17623 : 6056 : bitmap_set_bit (&map_head, DECL_UID (t));
17624 : 6056 : if (t != OMP_CLAUSE_DECL (c)
17625 : 6056 : && TREE_CODE (OMP_CLAUSE_DECL (c)) == COMPONENT_REF)
17626 : 232 : bitmap_set_bit (&map_field_head, DECL_UID (t));
17627 : : }
17628 : :
17629 : 0 : skip_decl_checks:
17630 : : /* If we call omp_expand_map_clause in handle_omp_array_sections,
17631 : : the containing loop (here) iterates through the new nodes
17632 : : created by that expansion. Avoid expanding those again (just
17633 : : by checking the node type). */
17634 : 7410 : if (!remove
17635 : 7410 : && ort != C_ORT_DECLARE_SIMD
17636 : 7410 : && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
17637 : 4517 : || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FIRSTPRIVATE_POINTER
17638 : 3487 : && (OMP_CLAUSE_MAP_KIND (c)
17639 : : != GOMP_MAP_FIRSTPRIVATE_REFERENCE)
17640 : 3487 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ALWAYS_POINTER
17641 : 3487 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH_DETACH
17642 : 3188 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
17643 : 3161 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH)))
17644 : : {
17645 : 5961 : grp_start_p = pc;
17646 : 5961 : grp_sentinel = OMP_CLAUSE_CHAIN (c);
17647 : 5961 : tree nc = ai.expand_map_clause (c, OMP_CLAUSE_DECL (c),
17648 : : addr_tokens, ort);
17649 : 5961 : if (nc != error_mark_node)
17650 : 5961 : c = nc;
17651 : : }
17652 : 9445 : }
17653 : 7410 : break;
17654 : :
17655 : 223 : case OMP_CLAUSE_ENTER:
17656 : 223 : case OMP_CLAUSE_LINK:
17657 : 223 : t = OMP_CLAUSE_DECL (c);
17658 : 223 : const char *cname;
17659 : 223 : cname = omp_clause_code_name[OMP_CLAUSE_CODE (c)];
17660 : 223 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER
17661 : 223 : && OMP_CLAUSE_ENTER_TO (c))
17662 : : cname = "to";
17663 : 223 : if (TREE_CODE (t) == FUNCTION_DECL
17664 : 223 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
17665 : : ;
17666 : 145 : else if (!VAR_P (t))
17667 : : {
17668 : 1 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
17669 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
17670 : : "%qE is neither a variable nor a function name in "
17671 : : "clause %qs", t, cname);
17672 : : else
17673 : 1 : error_at (OMP_CLAUSE_LOCATION (c),
17674 : : "%qE is not a variable in clause %qs", t, cname);
17675 : : remove = true;
17676 : : }
17677 : 144 : else if (DECL_THREAD_LOCAL_P (t))
17678 : : {
17679 : 2 : error_at (OMP_CLAUSE_LOCATION (c),
17680 : : "%qD is threadprivate variable in %qs clause", t,
17681 : : cname);
17682 : 2 : remove = true;
17683 : : }
17684 : 142 : else if (!omp_mappable_type (TREE_TYPE (t)))
17685 : : {
17686 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
17687 : : "%qD does not have a mappable type in %qs clause", t,
17688 : : cname);
17689 : 6 : remove = true;
17690 : : }
17691 : 8 : if (remove)
17692 : : break;
17693 : 214 : if (bitmap_bit_p (&generic_head, DECL_UID (t)))
17694 : : {
17695 : 8 : error_at (OMP_CLAUSE_LOCATION (c),
17696 : : "%qE appears more than once on the same "
17697 : : "%<declare target%> directive", t);
17698 : 8 : remove = true;
17699 : : }
17700 : : else
17701 : 206 : bitmap_set_bit (&generic_head, DECL_UID (t));
17702 : : break;
17703 : :
17704 : 117 : case OMP_CLAUSE_UNIFORM:
17705 : 117 : t = OMP_CLAUSE_DECL (c);
17706 : 117 : if (TREE_CODE (t) != PARM_DECL)
17707 : : {
17708 : 0 : if (DECL_P (t))
17709 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
17710 : : "%qD is not an argument in %<uniform%> clause", t);
17711 : : else
17712 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
17713 : : "%qE is not an argument in %<uniform%> clause", t);
17714 : : remove = true;
17715 : : break;
17716 : : }
17717 : : /* map_head bitmap is used as uniform_head if declare_simd. */
17718 : 117 : bitmap_set_bit (&map_head, DECL_UID (t));
17719 : 117 : goto check_dup_generic;
17720 : :
17721 : 160 : case OMP_CLAUSE_IS_DEVICE_PTR:
17722 : 160 : case OMP_CLAUSE_USE_DEVICE_PTR:
17723 : 160 : t = OMP_CLAUSE_DECL (c);
17724 : 160 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
17725 : 122 : bitmap_set_bit (&is_on_device_head, DECL_UID (t));
17726 : 160 : if (TREE_CODE (TREE_TYPE (t)) != POINTER_TYPE)
17727 : : {
17728 : 21 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
17729 : 21 : && !openacc)
17730 : : {
17731 : 1 : error_at (OMP_CLAUSE_LOCATION (c),
17732 : : "%qs variable is not a pointer",
17733 : 1 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
17734 : 1 : remove = true;
17735 : : }
17736 : 20 : else if (TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE)
17737 : : {
17738 : 4 : error_at (OMP_CLAUSE_LOCATION (c),
17739 : : "%qs variable is neither a pointer nor an array",
17740 : 4 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
17741 : 4 : remove = true;
17742 : : }
17743 : : }
17744 : 160 : goto check_dup_generic;
17745 : :
17746 : 88 : case OMP_CLAUSE_HAS_DEVICE_ADDR:
17747 : 88 : t = OMP_CLAUSE_DECL (c);
17748 : 88 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
17749 : : {
17750 : 11 : if (handle_omp_array_sections (c, ort))
17751 : : remove = true;
17752 : : else
17753 : : {
17754 : 11 : t = OMP_CLAUSE_DECL (c);
17755 : 24 : while (TREE_CODE (t) == ARRAY_REF)
17756 : 13 : t = TREE_OPERAND (t, 0);
17757 : : }
17758 : : }
17759 : 88 : bitmap_set_bit (&is_on_device_head, DECL_UID (t));
17760 : 88 : if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
17761 : 88 : c_mark_addressable (t);
17762 : 88 : goto check_dup_generic_t;
17763 : :
17764 : 36 : case OMP_CLAUSE_USE_DEVICE_ADDR:
17765 : 36 : t = OMP_CLAUSE_DECL (c);
17766 : 36 : if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
17767 : 36 : c_mark_addressable (t);
17768 : 36 : goto check_dup_generic;
17769 : :
17770 : 4789 : case OMP_CLAUSE_NOWAIT:
17771 : 4789 : if (copyprivate_seen)
17772 : : {
17773 : 1 : error_at (OMP_CLAUSE_LOCATION (c),
17774 : : "%<nowait%> clause must not be used together "
17775 : : "with %<copyprivate%> clause");
17776 : 1 : remove = true;
17777 : 1 : break;
17778 : : }
17779 : 4788 : nowait_clause = pc;
17780 : 4788 : pc = &OMP_CLAUSE_CHAIN (c);
17781 : 4788 : continue;
17782 : :
17783 : 523 : case OMP_CLAUSE_ORDER:
17784 : 523 : if (ordered_clause)
17785 : : {
17786 : 2 : error_at (OMP_CLAUSE_LOCATION (c),
17787 : : "%<order%> clause must not be used together "
17788 : : "with %<ordered%> clause");
17789 : 2 : remove = true;
17790 : 2 : break;
17791 : : }
17792 : 521 : else if (order_clause)
17793 : : {
17794 : : /* Silently remove duplicates. */
17795 : : remove = true;
17796 : : break;
17797 : : }
17798 : 513 : order_clause = pc;
17799 : 513 : pc = &OMP_CLAUSE_CHAIN (c);
17800 : 513 : continue;
17801 : :
17802 : 32 : case OMP_CLAUSE_DETACH:
17803 : 32 : t = OMP_CLAUSE_DECL (c);
17804 : 32 : if (detach_seen)
17805 : : {
17806 : 1 : error_at (OMP_CLAUSE_LOCATION (c),
17807 : : "too many %qs clauses on a task construct",
17808 : : "detach");
17809 : 1 : remove = true;
17810 : 1 : break;
17811 : : }
17812 : 31 : detach_seen = pc;
17813 : 31 : pc = &OMP_CLAUSE_CHAIN (c);
17814 : 31 : c_mark_addressable (t);
17815 : 31 : continue;
17816 : :
17817 : 14532 : case OMP_CLAUSE_IF:
17818 : 14532 : case OMP_CLAUSE_SELF:
17819 : 14532 : case OMP_CLAUSE_NUM_THREADS:
17820 : 14532 : case OMP_CLAUSE_NUM_TEAMS:
17821 : 14532 : case OMP_CLAUSE_THREAD_LIMIT:
17822 : 14532 : case OMP_CLAUSE_DEFAULT:
17823 : 14532 : case OMP_CLAUSE_UNTIED:
17824 : 14532 : case OMP_CLAUSE_COLLAPSE:
17825 : 14532 : case OMP_CLAUSE_FINAL:
17826 : 14532 : case OMP_CLAUSE_DEVICE:
17827 : 14532 : case OMP_CLAUSE_DIST_SCHEDULE:
17828 : 14532 : case OMP_CLAUSE_PARALLEL:
17829 : 14532 : case OMP_CLAUSE_FOR:
17830 : 14532 : case OMP_CLAUSE_SECTIONS:
17831 : 14532 : case OMP_CLAUSE_TASKGROUP:
17832 : 14532 : case OMP_CLAUSE_PROC_BIND:
17833 : 14532 : case OMP_CLAUSE_DEVICE_TYPE:
17834 : 14532 : case OMP_CLAUSE_PRIORITY:
17835 : 14532 : case OMP_CLAUSE_THREADS:
17836 : 14532 : case OMP_CLAUSE_SIMD:
17837 : 14532 : case OMP_CLAUSE_HINT:
17838 : 14532 : case OMP_CLAUSE_FILTER:
17839 : 14532 : case OMP_CLAUSE_DEFAULTMAP:
17840 : 14532 : case OMP_CLAUSE_BIND:
17841 : 14532 : case OMP_CLAUSE_NUM_GANGS:
17842 : 14532 : case OMP_CLAUSE_NUM_WORKERS:
17843 : 14532 : case OMP_CLAUSE_VECTOR_LENGTH:
17844 : 14532 : case OMP_CLAUSE_ASYNC:
17845 : 14532 : case OMP_CLAUSE_WAIT:
17846 : 14532 : case OMP_CLAUSE_AUTO:
17847 : 14532 : case OMP_CLAUSE_INDEPENDENT:
17848 : 14532 : case OMP_CLAUSE_SEQ:
17849 : 14532 : case OMP_CLAUSE_GANG:
17850 : 14532 : case OMP_CLAUSE_WORKER:
17851 : 14532 : case OMP_CLAUSE_VECTOR:
17852 : 14532 : case OMP_CLAUSE_TILE:
17853 : 14532 : case OMP_CLAUSE_IF_PRESENT:
17854 : 14532 : case OMP_CLAUSE_FINALIZE:
17855 : 14532 : case OMP_CLAUSE_NOHOST:
17856 : 14532 : case OMP_CLAUSE_INDIRECT:
17857 : 14532 : case OMP_CLAUSE_NOVARIANTS:
17858 : 14532 : case OMP_CLAUSE_NOCONTEXT:
17859 : 14532 : pc = &OMP_CLAUSE_CHAIN (c);
17860 : 14532 : continue;
17861 : :
17862 : 62 : case OMP_CLAUSE_GRAINSIZE:
17863 : 62 : grainsize_seen = pc;
17864 : 62 : pc = &OMP_CLAUSE_CHAIN (c);
17865 : 62 : continue;
17866 : :
17867 : 49 : case OMP_CLAUSE_NUM_TASKS:
17868 : 49 : num_tasks_seen = true;
17869 : 49 : pc = &OMP_CLAUSE_CHAIN (c);
17870 : 49 : continue;
17871 : :
17872 : 78 : case OMP_CLAUSE_MERGEABLE:
17873 : 78 : mergeable_seen = true;
17874 : 78 : pc = &OMP_CLAUSE_CHAIN (c);
17875 : 78 : continue;
17876 : :
17877 : 18 : case OMP_CLAUSE_NOGROUP:
17878 : 18 : nogroup_seen = pc;
17879 : 18 : pc = &OMP_CLAUSE_CHAIN (c);
17880 : 18 : continue;
17881 : :
17882 : 3463 : case OMP_CLAUSE_SCHEDULE:
17883 : 3463 : schedule_clause = c;
17884 : 3463 : pc = &OMP_CLAUSE_CHAIN (c);
17885 : 3463 : continue;
17886 : :
17887 : 303 : case OMP_CLAUSE_ORDERED:
17888 : 303 : ordered_clause = c;
17889 : 303 : if (order_clause)
17890 : : {
17891 : 2 : error_at (OMP_CLAUSE_LOCATION (*order_clause),
17892 : : "%<order%> clause must not be used together "
17893 : : "with %<ordered%> clause");
17894 : 2 : *order_clause = OMP_CLAUSE_CHAIN (*order_clause);
17895 : 2 : order_clause = NULL;
17896 : : }
17897 : 303 : pc = &OMP_CLAUSE_CHAIN (c);
17898 : 303 : continue;
17899 : :
17900 : 223 : case OMP_CLAUSE_SAFELEN:
17901 : 223 : safelen = c;
17902 : 223 : pc = &OMP_CLAUSE_CHAIN (c);
17903 : 223 : continue;
17904 : 319 : case OMP_CLAUSE_SIMDLEN:
17905 : 319 : simdlen = c;
17906 : 319 : pc = &OMP_CLAUSE_CHAIN (c);
17907 : 319 : continue;
17908 : :
17909 : 69 : case OMP_CLAUSE_FULL:
17910 : 69 : full_seen = pc;
17911 : 69 : pc = &OMP_CLAUSE_CHAIN (c);
17912 : 69 : continue;
17913 : :
17914 : 223 : case OMP_CLAUSE_PARTIAL:
17915 : 223 : partial_seen = true;
17916 : 223 : pc = &OMP_CLAUSE_CHAIN (c);
17917 : 223 : continue;
17918 : :
17919 : 0 : case OMP_CLAUSE_SIZES:
17920 : 0 : pc = &OMP_CLAUSE_CHAIN (c);
17921 : 0 : continue;
17922 : :
17923 : 205 : case OMP_CLAUSE_INBRANCH:
17924 : 205 : case OMP_CLAUSE_NOTINBRANCH:
17925 : 205 : if (branch_seen)
17926 : : {
17927 : 1 : error_at (OMP_CLAUSE_LOCATION (c),
17928 : : "%<inbranch%> clause is incompatible with "
17929 : : "%<notinbranch%>");
17930 : 1 : remove = true;
17931 : 1 : break;
17932 : : }
17933 : 204 : branch_seen = true;
17934 : 204 : pc = &OMP_CLAUSE_CHAIN (c);
17935 : 204 : continue;
17936 : :
17937 : 367 : case OMP_CLAUSE_INCLUSIVE:
17938 : 367 : case OMP_CLAUSE_EXCLUSIVE:
17939 : 367 : need_complete = true;
17940 : 367 : need_implicitly_determined = true;
17941 : 367 : t = OMP_CLAUSE_DECL (c);
17942 : 367 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
17943 : : {
17944 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
17945 : : "%qE is not a variable in clause %qs", t,
17946 : 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
17947 : 0 : remove = true;
17948 : : }
17949 : : break;
17950 : :
17951 : 152 : case OMP_CLAUSE_INIT:
17952 : 152 : init_seen = true;
17953 : 152 : if (!OMP_CLAUSE_INIT_TARGETSYNC (c))
17954 : 71 : init_no_targetsync_clause = c;
17955 : : /* FALLTHRU */
17956 : 242 : case OMP_CLAUSE_DESTROY:
17957 : 242 : case OMP_CLAUSE_USE:
17958 : 242 : init_use_destroy_seen = true;
17959 : 242 : t = OMP_CLAUSE_DECL (c);
17960 : 242 : if (bitmap_bit_p (&generic_head, DECL_UID (t)))
17961 : : {
17962 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
17963 : : "%qD appears more than once in action clauses", t);
17964 : 3 : remove = true;
17965 : 3 : break;
17966 : : }
17967 : 239 : bitmap_set_bit (&generic_head, DECL_UID (t));
17968 : : /* FALLTHRU */
17969 : 298 : case OMP_CLAUSE_INTEROP:
17970 : 298 : if (/* ort == C_ORT_OMP_INTEROP [uncomment for depobj init] */
17971 : 298 : !c_omp_interop_t_p (TREE_TYPE (OMP_CLAUSE_DECL (c))))
17972 : : {
17973 : 40 : error_at (OMP_CLAUSE_LOCATION (c),
17974 : : "%qD must be of %<omp_interop_t%>",
17975 : 20 : OMP_CLAUSE_DECL (c));
17976 : 20 : remove = true;
17977 : : }
17978 : 278 : else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INIT
17979 : 133 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DESTROY)
17980 : 318 : && TREE_READONLY (OMP_CLAUSE_DECL (c)))
17981 : : {
17982 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
17983 : 6 : "%qD shall not be const", OMP_CLAUSE_DECL (c));
17984 : 6 : remove = true;
17985 : : }
17986 : 298 : pc = &OMP_CLAUSE_CHAIN (c);
17987 : 298 : break;
17988 : 0 : default:
17989 : 0 : gcc_unreachable ();
17990 : 24875 : }
17991 : :
17992 : 22634 : if (!remove)
17993 : : {
17994 : 22074 : t = OMP_CLAUSE_DECL (c);
17995 : :
17996 : 22074 : if (need_complete)
17997 : : {
17998 : 3931 : t = require_complete_type (OMP_CLAUSE_LOCATION (c), t);
17999 : 3931 : if (t == error_mark_node)
18000 : 7 : remove = true;
18001 : : }
18002 : :
18003 : 22074 : if (need_implicitly_determined)
18004 : : {
18005 : 9524 : const char *share_name = NULL;
18006 : :
18007 : 9524 : if (VAR_P (t) && DECL_THREAD_LOCAL_P (t))
18008 : : share_name = "threadprivate";
18009 : 9518 : else switch (c_omp_predetermined_sharing (t))
18010 : : {
18011 : : case OMP_CLAUSE_DEFAULT_UNSPECIFIED:
18012 : : break;
18013 : 20 : case OMP_CLAUSE_DEFAULT_SHARED:
18014 : 20 : if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
18015 : 12 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE)
18016 : 28 : && c_omp_predefined_variable (t))
18017 : : /* The __func__ variable and similar function-local
18018 : : predefined variables may be listed in a shared or
18019 : : firstprivate clause. */
18020 : : break;
18021 : : share_name = "shared";
18022 : : break;
18023 : : case OMP_CLAUSE_DEFAULT_PRIVATE:
18024 : : share_name = "private";
18025 : : break;
18026 : 0 : default:
18027 : 0 : gcc_unreachable ();
18028 : : }
18029 : : if (share_name)
18030 : : {
18031 : 20 : error_at (OMP_CLAUSE_LOCATION (c),
18032 : : "%qE is predetermined %qs for %qs",
18033 : : t, share_name,
18034 : 10 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
18035 : 10 : remove = true;
18036 : : }
18037 : 9514 : else if (TREE_READONLY (t)
18038 : 23 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
18039 : 9527 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FIRSTPRIVATE)
18040 : : {
18041 : 4 : error_at (OMP_CLAUSE_LOCATION (c),
18042 : : "%<const%> qualified %qE may appear only in "
18043 : : "%<shared%> or %<firstprivate%> clauses", t);
18044 : 4 : remove = true;
18045 : : }
18046 : : }
18047 : : }
18048 : :
18049 : 22074 : if (remove)
18050 : : {
18051 : 581 : if (grp_start_p)
18052 : : {
18053 : : /* If we found a clause to remove, we want to remove the whole
18054 : : expanded group, otherwise gimplify
18055 : : (omp_resolve_clause_dependencies) can get confused. */
18056 : 154 : *grp_start_p = grp_sentinel;
18057 : 154 : pc = grp_start_p;
18058 : 154 : grp_start_p = NULL;
18059 : : }
18060 : : else
18061 : 427 : *pc = OMP_CLAUSE_CHAIN (c);
18062 : : }
18063 : : else
18064 : 22053 : pc = &OMP_CLAUSE_CHAIN (c);
18065 : : }
18066 : :
18067 : 29240 : if (grp_start_p
18068 : 29240 : && OMP_CLAUSE_HAS_ITERATORS (*grp_start_p))
18069 : 49 : for (tree gc = *grp_start_p; gc; gc = OMP_CLAUSE_CHAIN (gc))
18070 : 30 : OMP_CLAUSE_ITERATORS (gc) = OMP_CLAUSE_ITERATORS (*grp_start_p);
18071 : :
18072 : 29240 : if (simdlen
18073 : 29240 : && safelen
18074 : 29357 : && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen),
18075 : 117 : OMP_CLAUSE_SIMDLEN_EXPR (simdlen)))
18076 : : {
18077 : 0 : error_at (OMP_CLAUSE_LOCATION (simdlen),
18078 : : "%<simdlen%> clause value is bigger than "
18079 : : "%<safelen%> clause value");
18080 : 0 : OMP_CLAUSE_SIMDLEN_EXPR (simdlen)
18081 : 0 : = OMP_CLAUSE_SAFELEN_EXPR (safelen);
18082 : : }
18083 : :
18084 : 29240 : if (ordered_clause
18085 : 29240 : && schedule_clause
18086 : 29240 : && (OMP_CLAUSE_SCHEDULE_KIND (schedule_clause)
18087 : : & OMP_CLAUSE_SCHEDULE_NONMONOTONIC))
18088 : : {
18089 : 7 : error_at (OMP_CLAUSE_LOCATION (schedule_clause),
18090 : : "%<nonmonotonic%> schedule modifier specified together "
18091 : : "with %<ordered%> clause");
18092 : 14 : OMP_CLAUSE_SCHEDULE_KIND (schedule_clause)
18093 : 7 : = (enum omp_clause_schedule_kind)
18094 : 7 : (OMP_CLAUSE_SCHEDULE_KIND (schedule_clause)
18095 : : & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC);
18096 : : }
18097 : :
18098 : 29240 : if (reduction_seen < 0 && ordered_clause)
18099 : : {
18100 : 2 : error_at (OMP_CLAUSE_LOCATION (ordered_clause),
18101 : : "%qs clause specified together with %<inscan%> "
18102 : : "%<reduction%> clause", "ordered");
18103 : 2 : reduction_seen = -2;
18104 : : }
18105 : :
18106 : 29240 : if (reduction_seen < 0 && schedule_clause)
18107 : : {
18108 : 3 : error_at (OMP_CLAUSE_LOCATION (schedule_clause),
18109 : : "%qs clause specified together with %<inscan%> "
18110 : : "%<reduction%> clause", "schedule");
18111 : 3 : reduction_seen = -2;
18112 : : }
18113 : :
18114 : 29240 : if (linear_variable_step_check
18115 : 29240 : || reduction_seen == -2
18116 : : || allocate_seen
18117 : 29228 : || target_in_reduction_seen)
18118 : 5145 : for (pc = &clauses, c = clauses; c ; c = *pc)
18119 : : {
18120 : 4556 : bool remove = false;
18121 : 4556 : if (allocate_seen)
18122 : 4398 : switch (OMP_CLAUSE_CODE (c))
18123 : : {
18124 : 430 : case OMP_CLAUSE_REDUCTION:
18125 : 430 : case OMP_CLAUSE_IN_REDUCTION:
18126 : 430 : case OMP_CLAUSE_TASK_REDUCTION:
18127 : 430 : if (TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF)
18128 : : {
18129 : 23 : t = TREE_OPERAND (OMP_CLAUSE_DECL (c), 0);
18130 : 23 : if (TREE_CODE (t) == POINTER_PLUS_EXPR)
18131 : 0 : t = TREE_OPERAND (t, 0);
18132 : 23 : if (TREE_CODE (t) == ADDR_EXPR
18133 : 10 : || INDIRECT_REF_P (t))
18134 : 13 : t = TREE_OPERAND (t, 0);
18135 : 23 : if (DECL_P (t))
18136 : 23 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
18137 : : break;
18138 : : }
18139 : : /* FALLTHRU */
18140 : 1302 : case OMP_CLAUSE_PRIVATE:
18141 : 1302 : case OMP_CLAUSE_FIRSTPRIVATE:
18142 : 1302 : case OMP_CLAUSE_LASTPRIVATE:
18143 : 1302 : case OMP_CLAUSE_LINEAR:
18144 : 1302 : if (DECL_P (OMP_CLAUSE_DECL (c)))
18145 : 2604 : bitmap_clear_bit (&aligned_head,
18146 : 1302 : DECL_UID (OMP_CLAUSE_DECL (c)));
18147 : : break;
18148 : : default:
18149 : : break;
18150 : : }
18151 : 4556 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
18152 : 29 : && OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c)
18153 : 4563 : && !bitmap_bit_p (&map_head,
18154 : 7 : DECL_UID (OMP_CLAUSE_LINEAR_STEP (c))))
18155 : : {
18156 : 2 : error_at (OMP_CLAUSE_LOCATION (c),
18157 : : "%<linear%> clause step is a parameter %qD not "
18158 : : "specified in %<uniform%> clause",
18159 : 2 : OMP_CLAUSE_LINEAR_STEP (c));
18160 : 2 : remove = true;
18161 : : }
18162 : 4554 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
18163 : 4554 : && reduction_seen == -2)
18164 : 9 : OMP_CLAUSE_REDUCTION_INSCAN (c) = 0;
18165 : 4556 : if (target_in_reduction_seen
18166 : 4556 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP)
18167 : : {
18168 : 256 : tree t = OMP_CLAUSE_DECL (c);
18169 : 256 : while (handled_component_p (t)
18170 : : || INDIRECT_REF_P (t)
18171 : : || TREE_CODE (t) == ADDR_EXPR
18172 : : || TREE_CODE (t) == MEM_REF
18173 : 288 : || TREE_CODE (t) == NON_LVALUE_EXPR)
18174 : 32 : t = TREE_OPERAND (t, 0);
18175 : 256 : if (DECL_P (t)
18176 : 256 : && bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
18177 : 138 : OMP_CLAUSE_MAP_IN_REDUCTION (c) = 1;
18178 : : }
18179 : :
18180 : 4556 : if (remove)
18181 : 2 : *pc = OMP_CLAUSE_CHAIN (c);
18182 : : else
18183 : 4554 : pc = &OMP_CLAUSE_CHAIN (c);
18184 : : }
18185 : :
18186 : 589 : if (allocate_seen)
18187 : 4961 : for (pc = &clauses, c = clauses; c ; c = *pc)
18188 : : {
18189 : 4398 : bool remove = false;
18190 : 4398 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ALLOCATE
18191 : 704 : && !OMP_CLAUSE_ALLOCATE_COMBINED (c)
18192 : 5082 : && bitmap_bit_p (&aligned_head, DECL_UID (OMP_CLAUSE_DECL (c))))
18193 : : {
18194 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
18195 : : "%qD specified in %<allocate%> clause but not in "
18196 : 3 : "an explicit privatization clause", OMP_CLAUSE_DECL (c));
18197 : 3 : remove = true;
18198 : : }
18199 : 4398 : if (remove)
18200 : 3 : *pc = OMP_CLAUSE_CHAIN (c);
18201 : : else
18202 : 4395 : pc = &OMP_CLAUSE_CHAIN (c);
18203 : : }
18204 : :
18205 : 29240 : if (nogroup_seen && reduction_seen)
18206 : : {
18207 : 1 : error_at (OMP_CLAUSE_LOCATION (*nogroup_seen),
18208 : : "%<nogroup%> clause must not be used together with "
18209 : : "%<reduction%> clause");
18210 : 1 : *nogroup_seen = OMP_CLAUSE_CHAIN (*nogroup_seen);
18211 : : }
18212 : :
18213 : 29240 : if (grainsize_seen && num_tasks_seen)
18214 : : {
18215 : 2 : error_at (OMP_CLAUSE_LOCATION (*grainsize_seen),
18216 : : "%<grainsize%> clause must not be used together with "
18217 : : "%<num_tasks%> clause");
18218 : 2 : *grainsize_seen = OMP_CLAUSE_CHAIN (*grainsize_seen);
18219 : : }
18220 : :
18221 : 29240 : if (full_seen && partial_seen)
18222 : : {
18223 : 4 : error_at (OMP_CLAUSE_LOCATION (*full_seen),
18224 : : "%<full%> clause must not be used together with "
18225 : : "%<partial%> clause");
18226 : 4 : *full_seen = OMP_CLAUSE_CHAIN (*full_seen);
18227 : : }
18228 : :
18229 : 29240 : if (detach_seen)
18230 : : {
18231 : 31 : if (mergeable_seen)
18232 : : {
18233 : 2 : error_at (OMP_CLAUSE_LOCATION (*detach_seen),
18234 : : "%<detach%> clause must not be used together with "
18235 : : "%<mergeable%> clause");
18236 : 2 : *detach_seen = OMP_CLAUSE_CHAIN (*detach_seen);
18237 : : }
18238 : : else
18239 : : {
18240 : 29 : tree detach_decl = OMP_CLAUSE_DECL (*detach_seen);
18241 : :
18242 : 79 : for (pc = &clauses, c = clauses; c ; c = *pc)
18243 : : {
18244 : 50 : bool remove = false;
18245 : 50 : if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
18246 : 48 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
18247 : 48 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
18248 : 44 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE)
18249 : 54 : && OMP_CLAUSE_DECL (c) == detach_decl)
18250 : : {
18251 : 2 : error_at (OMP_CLAUSE_LOCATION (c),
18252 : : "the event handle of a %<detach%> clause "
18253 : : "should not be in a data-sharing clause");
18254 : 2 : remove = true;
18255 : : }
18256 : 50 : if (remove)
18257 : 2 : *pc = OMP_CLAUSE_CHAIN (c);
18258 : : else
18259 : 48 : pc = &OMP_CLAUSE_CHAIN (c);
18260 : : }
18261 : : }
18262 : : }
18263 : :
18264 : 29240 : if (ort == C_ORT_OMP_INTEROP
18265 : 29240 : && depend_clause
18266 : 21 : && (!init_use_destroy_seen
18267 : 20 : || (init_seen && init_no_targetsync_clause)))
18268 : : {
18269 : 3 : error_at (OMP_CLAUSE_LOCATION (depend_clause),
18270 : : "%<depend%> clause requires action clauses with "
18271 : : "%<targetsync%> interop-type");
18272 : 3 : if (init_no_targetsync_clause)
18273 : 2 : inform (OMP_CLAUSE_LOCATION (init_no_targetsync_clause),
18274 : : "%<init%> clause lacks the %<targetsync%> modifier");
18275 : : }
18276 : :
18277 : 29240 : bitmap_obstack_release (NULL);
18278 : 29240 : return clauses;
18279 : : }
18280 : :
18281 : : /* Do processing necessary to make CLAUSES well-formed, where CLAUSES result
18282 : : from implicit instantiation of user-defined mappers (in gimplify.cc). */
18283 : :
18284 : : tree
18285 : 13 : c_omp_finish_mapper_clauses (tree clauses)
18286 : : {
18287 : 13 : return c_finish_omp_clauses (clauses, C_ORT_OMP);
18288 : : }
18289 : :
18290 : : /* Return code to initialize DST with a copy constructor from SRC.
18291 : : C doesn't have copy constructors nor assignment operators, only for
18292 : : _Atomic vars we need to perform __atomic_load from src into a temporary
18293 : : followed by __atomic_store of the temporary to dst. */
18294 : :
18295 : : tree
18296 : 18714 : c_omp_clause_copy_ctor (tree clause, tree dst, tree src)
18297 : : {
18298 : 18714 : if (!really_atomic_lvalue (dst) && !really_atomic_lvalue (src))
18299 : 18710 : return build2 (MODIFY_EXPR, TREE_TYPE (dst), dst, src);
18300 : :
18301 : 4 : location_t loc = OMP_CLAUSE_LOCATION (clause);
18302 : 4 : tree type = TREE_TYPE (dst);
18303 : 4 : tree nonatomic_type = build_qualified_type (type, TYPE_UNQUALIFIED);
18304 : 4 : tree tmp = create_tmp_var (nonatomic_type);
18305 : 4 : tree tmp_addr = build_fold_addr_expr (tmp);
18306 : 4 : TREE_ADDRESSABLE (tmp) = 1;
18307 : 4 : suppress_warning (tmp);
18308 : 4 : tree src_addr = build_fold_addr_expr (src);
18309 : 4 : tree dst_addr = build_fold_addr_expr (dst);
18310 : 4 : tree seq_cst = build_int_cst (integer_type_node, MEMMODEL_SEQ_CST);
18311 : 4 : vec<tree, va_gc> *params;
18312 : : /* Expansion of a generic atomic load may require an addition
18313 : : element, so allocate enough to prevent a resize. */
18314 : 4 : vec_alloc (params, 4);
18315 : :
18316 : : /* Build __atomic_load (&src, &tmp, SEQ_CST); */
18317 : 4 : tree fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_LOAD);
18318 : 4 : params->quick_push (src_addr);
18319 : 4 : params->quick_push (tmp_addr);
18320 : 4 : params->quick_push (seq_cst);
18321 : 4 : tree load = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
18322 : :
18323 : 4 : vec_alloc (params, 4);
18324 : :
18325 : : /* Build __atomic_store (&dst, &tmp, SEQ_CST); */
18326 : 4 : fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_STORE);
18327 : 4 : params->quick_push (dst_addr);
18328 : 4 : params->quick_push (tmp_addr);
18329 : 4 : params->quick_push (seq_cst);
18330 : 4 : tree store = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
18331 : 4 : return build2 (COMPOUND_EXPR, void_type_node, load, store);
18332 : : }
18333 : :
18334 : : /* Create a transaction node. */
18335 : :
18336 : : tree
18337 : 135 : c_finish_transaction (location_t loc, tree block, int flags)
18338 : : {
18339 : 135 : tree stmt = build_stmt (loc, TRANSACTION_EXPR, block);
18340 : 135 : if (flags & TM_STMT_ATTR_OUTER)
18341 : 10 : TRANSACTION_EXPR_OUTER (stmt) = 1;
18342 : 135 : if (flags & TM_STMT_ATTR_RELAXED)
18343 : 31 : TRANSACTION_EXPR_RELAXED (stmt) = 1;
18344 : 135 : return add_stmt (stmt);
18345 : : }
18346 : :
18347 : : /* Make a variant type in the proper way for C/C++, propagating qualifiers
18348 : : down to the element type of an array. If ORIG_QUAL_TYPE is not
18349 : : NULL, then it should be used as the qualified type
18350 : : ORIG_QUAL_INDIRECT levels down in array type derivation (to
18351 : : preserve information about the typedef name from which an array
18352 : : type was derived). */
18353 : :
18354 : : tree
18355 : 74178920 : c_build_qualified_type (tree type, int type_quals, tree orig_qual_type,
18356 : : size_t orig_qual_indirect)
18357 : : {
18358 : 74178920 : if (type == error_mark_node)
18359 : : return type;
18360 : :
18361 : 74178768 : if (TREE_CODE (type) == ARRAY_TYPE)
18362 : : {
18363 : 3154391 : tree t;
18364 : 3154391 : tree element_type = c_build_qualified_type (TREE_TYPE (type),
18365 : : type_quals, orig_qual_type,
18366 : : orig_qual_indirect - 1);
18367 : :
18368 : : /* See if we already have an identically qualified type. */
18369 : 3154391 : if (orig_qual_type && orig_qual_indirect == 0)
18370 : : t = orig_qual_type;
18371 : : else
18372 : 4596457 : for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
18373 : : {
18374 : 4456889 : if (TYPE_QUALS (strip_array_types (t)) == type_quals
18375 : 3035547 : && TYPE_NAME (t) == TYPE_NAME (type)
18376 : 3014782 : && TYPE_CONTEXT (t) == TYPE_CONTEXT (type)
18377 : 7471671 : && attribute_list_equal (TYPE_ATTRIBUTES (t),
18378 : 3014782 : TYPE_ATTRIBUTES (type)))
18379 : : break;
18380 : : }
18381 : 3154350 : if (!t)
18382 : : {
18383 : 139568 : tree domain = TYPE_DOMAIN (type);
18384 : :
18385 : 139568 : t = build_variant_type_copy (type);
18386 : 139568 : TREE_TYPE (t) = element_type;
18387 : 139568 : TYPE_ADDR_SPACE (t) = TYPE_ADDR_SPACE (element_type);
18388 : :
18389 : 139568 : if (TYPE_STRUCTURAL_EQUALITY_P (element_type)
18390 : 139568 : || (domain && TYPE_STRUCTURAL_EQUALITY_P (domain)))
18391 : 195 : SET_TYPE_STRUCTURAL_EQUALITY (t);
18392 : 139373 : else if (TYPE_CANONICAL (element_type) != element_type
18393 : 139373 : || (domain && TYPE_CANONICAL (domain) != domain))
18394 : : {
18395 : 2698 : tree unqualified_canon
18396 : 5183 : = c_build_array_type (TYPE_CANONICAL (element_type),
18397 : 2485 : domain ? TYPE_CANONICAL (domain)
18398 : : : NULL_TREE);
18399 : 2698 : if (TYPE_REVERSE_STORAGE_ORDER (type))
18400 : : {
18401 : 0 : unqualified_canon
18402 : 0 : = build_distinct_type_copy (unqualified_canon);
18403 : 0 : TYPE_REVERSE_STORAGE_ORDER (unqualified_canon) = 1;
18404 : : }
18405 : 2698 : TYPE_CANONICAL (t)
18406 : 5396 : = c_build_qualified_type (unqualified_canon, type_quals);
18407 : : }
18408 : : else
18409 : 136675 : TYPE_CANONICAL (t) = t;
18410 : : }
18411 : 3154391 : return t;
18412 : : }
18413 : :
18414 : : /* A restrict-qualified pointer type must be a pointer to object or
18415 : : incomplete type. Note that the use of POINTER_TYPE_P also allows
18416 : : REFERENCE_TYPEs, which is appropriate for C++. */
18417 : 71024377 : if ((type_quals & TYPE_QUAL_RESTRICT)
18418 : 71024377 : && (!POINTER_TYPE_P (type)
18419 : 3357866 : || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type))))
18420 : : {
18421 : 3 : error ("invalid use of %<restrict%>");
18422 : 3 : type_quals &= ~TYPE_QUAL_RESTRICT;
18423 : : }
18424 : :
18425 : 71024377 : tree var_type = (orig_qual_type && orig_qual_indirect == 0
18426 : 71024377 : ? orig_qual_type
18427 : 71024346 : : build_qualified_type (type, type_quals));
18428 : :
18429 : 71024377 : gcc_checking_assert (C_TYPE_VARIABLE_SIZE (var_type)
18430 : : == C_TYPE_VARIABLE_SIZE (type));
18431 : 71024377 : gcc_checking_assert (C_TYPE_VARIABLY_MODIFIED (var_type)
18432 : : == C_TYPE_VARIABLY_MODIFIED (type));
18433 : :
18434 : : /* A variant type does not inherit the list of incomplete vars from the
18435 : : type main variant. */
18436 : 71024377 : if ((RECORD_OR_UNION_TYPE_P (var_type)
18437 : 69125244 : || TREE_CODE (var_type) == ENUMERAL_TYPE)
18438 : 71129031 : && TYPE_MAIN_VARIANT (var_type) != var_type)
18439 : 1394177 : C_TYPE_INCOMPLETE_VARS (var_type) = 0;
18440 : : return var_type;
18441 : : }
18442 : :
18443 : : /* Build a VA_ARG_EXPR for the C parser. */
18444 : :
18445 : : tree
18446 : 19888 : c_build_va_arg (location_t loc1, tree expr, location_t loc2, tree type,
18447 : : tree type_expr)
18448 : : {
18449 : 19888 : if (error_operand_p (type))
18450 : 2 : return error_mark_node;
18451 : : /* VA_ARG_EXPR cannot be used for a scalar va_list with reverse storage
18452 : : order because it takes the address of the expression. */
18453 : 19886 : else if (handled_component_p (expr)
18454 : 31 : && reverse_storage_order_for_component_p (expr))
18455 : : {
18456 : 0 : error_at (loc1, "cannot use %<va_arg%> with reverse storage order");
18457 : 0 : return error_mark_node;
18458 : : }
18459 : 19886 : else if (!COMPLETE_TYPE_P (type))
18460 : : {
18461 : 11 : error_at (loc2, "second argument to %<va_arg%> is of incomplete "
18462 : : "type %qT", type);
18463 : 11 : return error_mark_node;
18464 : : }
18465 : 19875 : else if (TREE_CODE (type) == FUNCTION_TYPE)
18466 : : {
18467 : 1 : error_at (loc2, "second argument to %<va_arg%> is a function type %qT",
18468 : : type);
18469 : 1 : return error_mark_node;
18470 : : }
18471 : 6 : else if (TREE_CODE (type) == ARRAY_TYPE && C_TYPE_VARIABLE_SIZE (type)
18472 : 19877 : && !flag_isoc99)
18473 : : {
18474 : 1 : error_at (loc2, "second argument to %<va_arg%> is an array type %qT",
18475 : : type);
18476 : 1 : return error_mark_node;
18477 : : }
18478 : 19873 : else if (warn_cxx_compat && TREE_CODE (type) == ENUMERAL_TYPE)
18479 : 1 : warning_at (loc2, OPT_Wc___compat,
18480 : : "C++ requires promoted type, not enum type, in %<va_arg%>");
18481 : :
18482 : 19873 : if (flag_isoc99 && TREE_CODE (type) == ARRAY_TYPE)
18483 : : {
18484 : 3 : warning_at (loc2, 0, "second argument to %<va_arg%> is an array type %qT",
18485 : : type);
18486 : : /* We create a trap but evaluate side effects first. */
18487 : 3 : tree trapfn = builtin_decl_explicit (BUILT_IN_TRAP);
18488 : 3 : trapfn = build_call_expr_loc (loc2, trapfn, 0);
18489 : 3 : tree e2 = build2 (COMPOUND_EXPR, void_type_node, expr, trapfn);
18490 : : /* Return a compound literal of the right type. */
18491 : 3 : tree e1 = build_compound_literal (loc2, type, NULL, true, 0, NULL);
18492 : 3 : expr = build2 (COMPOUND_EXPR, type, e2, e1);
18493 : 3 : }
18494 : : else
18495 : 19870 : expr = build_va_arg (loc2, expr, type);
18496 : :
18497 : 19873 : if (type_expr)
18498 : 26 : expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr), type_expr, expr);
18499 : :
18500 : : return expr;
18501 : : }
18502 : :
18503 : : /* Return truthvalue of whether T1 is the same tree structure as T2.
18504 : : Return 1 if they are the same. Return false if they are different. */
18505 : :
18506 : : bool
18507 : 1854 : c_tree_equal (tree t1, tree t2)
18508 : : {
18509 : 1883 : enum tree_code code1, code2;
18510 : :
18511 : 1883 : if (t1 == t2)
18512 : : return true;
18513 : 661 : if (!t1 || !t2)
18514 : : return false;
18515 : :
18516 : 681 : for (code1 = TREE_CODE (t1); code1 == NON_LVALUE_EXPR;
18517 : 20 : code1 = TREE_CODE (t1))
18518 : 20 : t1 = TREE_OPERAND (t1, 0);
18519 : 682 : for (code2 = TREE_CODE (t2); code2 == NON_LVALUE_EXPR;
18520 : 21 : code2 = TREE_CODE (t2))
18521 : 21 : t2 = TREE_OPERAND (t2, 0);
18522 : :
18523 : : /* They might have become equal now. */
18524 : 661 : if (t1 == t2)
18525 : : return true;
18526 : :
18527 : 640 : if (code1 != code2)
18528 : : return false;
18529 : :
18530 : 379 : if (CONSTANT_CLASS_P (t1) && !comptypes (TREE_TYPE (t1), TREE_TYPE (t2)))
18531 : : return false;
18532 : :
18533 : 379 : switch (code1)
18534 : : {
18535 : 2 : case INTEGER_CST:
18536 : 2 : return wi::to_wide (t1) == wi::to_wide (t2);
18537 : :
18538 : 10 : case REAL_CST:
18539 : 10 : return real_equal (&TREE_REAL_CST (t1), &TREE_REAL_CST (t2));
18540 : :
18541 : 0 : case STRING_CST:
18542 : 0 : return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
18543 : 0 : && !memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
18544 : 0 : TREE_STRING_LENGTH (t1));
18545 : :
18546 : 0 : case FIXED_CST:
18547 : 0 : return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1),
18548 : : TREE_FIXED_CST (t2));
18549 : :
18550 : 0 : case COMPLEX_CST:
18551 : 0 : return c_tree_equal (TREE_REALPART (t1), TREE_REALPART (t2))
18552 : 0 : && c_tree_equal (TREE_IMAGPART (t1), TREE_IMAGPART (t2));
18553 : :
18554 : 0 : case VECTOR_CST:
18555 : 0 : return operand_equal_p (t1, t2, OEP_ONLY_CONST);
18556 : :
18557 : 0 : case CONSTRUCTOR:
18558 : : /* We need to do this when determining whether or not two
18559 : : non-type pointer to member function template arguments
18560 : : are the same. */
18561 : 0 : if (!comptypes (TREE_TYPE (t1), TREE_TYPE (t2))
18562 : 0 : || CONSTRUCTOR_NELTS (t1) != CONSTRUCTOR_NELTS (t2))
18563 : : return false;
18564 : : {
18565 : : tree field, value;
18566 : : unsigned int i;
18567 : 0 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t1), i, field, value)
18568 : : {
18569 : 0 : constructor_elt *elt2 = CONSTRUCTOR_ELT (t2, i);
18570 : 0 : if (!c_tree_equal (field, elt2->index)
18571 : 0 : || !c_tree_equal (value, elt2->value))
18572 : 0 : return false;
18573 : : }
18574 : : }
18575 : : return true;
18576 : :
18577 : 0 : case TREE_LIST:
18578 : 0 : if (!c_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)))
18579 : : return false;
18580 : 0 : if (!c_tree_equal (TREE_VALUE (t1), TREE_VALUE (t2)))
18581 : : return false;
18582 : 0 : return c_tree_equal (TREE_CHAIN (t1), TREE_CHAIN (t2));
18583 : :
18584 : 0 : case SAVE_EXPR:
18585 : 0 : return c_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
18586 : :
18587 : 25 : case CALL_EXPR:
18588 : 25 : {
18589 : 25 : tree arg1, arg2;
18590 : 25 : call_expr_arg_iterator iter1, iter2;
18591 : 25 : if (!c_tree_equal (CALL_EXPR_FN (t1), CALL_EXPR_FN (t2)))
18592 : : return false;
18593 : 50 : for (arg1 = first_call_expr_arg (t1, &iter1),
18594 : 25 : arg2 = first_call_expr_arg (t2, &iter2);
18595 : 25 : arg1 && arg2;
18596 : 0 : arg1 = next_call_expr_arg (&iter1),
18597 : 0 : arg2 = next_call_expr_arg (&iter2))
18598 : 0 : if (!c_tree_equal (arg1, arg2))
18599 : : return false;
18600 : 25 : if (arg1 || arg2)
18601 : : return false;
18602 : : return true;
18603 : : }
18604 : :
18605 : 0 : case TARGET_EXPR:
18606 : 0 : {
18607 : 0 : tree o1 = TREE_OPERAND (t1, 0);
18608 : 0 : tree o2 = TREE_OPERAND (t2, 0);
18609 : :
18610 : : /* Special case: if either target is an unallocated VAR_DECL,
18611 : : it means that it's going to be unified with whatever the
18612 : : TARGET_EXPR is really supposed to initialize, so treat it
18613 : : as being equivalent to anything. */
18614 : 0 : if (VAR_P (o1) && DECL_NAME (o1) == NULL_TREE
18615 : 0 : && !DECL_RTL_SET_P (o1))
18616 : : /*Nop*/;
18617 : 0 : else if (VAR_P (o2) && DECL_NAME (o2) == NULL_TREE
18618 : 0 : && !DECL_RTL_SET_P (o2))
18619 : : /*Nop*/;
18620 : 0 : else if (!c_tree_equal (o1, o2))
18621 : : return false;
18622 : :
18623 : 0 : return c_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
18624 : : }
18625 : :
18626 : 29 : case COMPONENT_REF:
18627 : 29 : if (TREE_OPERAND (t1, 1) != TREE_OPERAND (t2, 1))
18628 : : return false;
18629 : 29 : return c_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
18630 : :
18631 : : case PARM_DECL:
18632 : : case VAR_DECL:
18633 : : case CONST_DECL:
18634 : : case FIELD_DECL:
18635 : : case FUNCTION_DECL:
18636 : : case IDENTIFIER_NODE:
18637 : : case SSA_NAME:
18638 : : return false;
18639 : :
18640 : 0 : case TREE_VEC:
18641 : 0 : {
18642 : 0 : unsigned ix;
18643 : 0 : if (TREE_VEC_LENGTH (t1) != TREE_VEC_LENGTH (t2))
18644 : : return false;
18645 : 0 : for (ix = TREE_VEC_LENGTH (t1); ix--;)
18646 : 0 : if (!c_tree_equal (TREE_VEC_ELT (t1, ix),
18647 : 0 : TREE_VEC_ELT (t2, ix)))
18648 : : return false;
18649 : : return true;
18650 : : }
18651 : :
18652 : 22 : CASE_CONVERT:
18653 : 22 : if (!comptypes (TREE_TYPE (t1), TREE_TYPE (t2)))
18654 : : return false;
18655 : : break;
18656 : :
18657 : : default:
18658 : : break;
18659 : : }
18660 : :
18661 : 131 : switch (TREE_CODE_CLASS (code1))
18662 : : {
18663 : 131 : case tcc_unary:
18664 : 131 : case tcc_binary:
18665 : 131 : case tcc_comparison:
18666 : 131 : case tcc_expression:
18667 : 131 : case tcc_vl_exp:
18668 : 131 : case tcc_reference:
18669 : 131 : case tcc_statement:
18670 : 131 : {
18671 : 131 : int i, n = TREE_OPERAND_LENGTH (t1);
18672 : :
18673 : 131 : switch (code1)
18674 : : {
18675 : 0 : case PREINCREMENT_EXPR:
18676 : 0 : case PREDECREMENT_EXPR:
18677 : 0 : case POSTINCREMENT_EXPR:
18678 : 0 : case POSTDECREMENT_EXPR:
18679 : 0 : n = 1;
18680 : 0 : break;
18681 : 16 : case ARRAY_REF:
18682 : 16 : n = 2;
18683 : 16 : break;
18684 : : default:
18685 : : break;
18686 : : }
18687 : :
18688 : 131 : if (TREE_CODE_CLASS (code1) == tcc_vl_exp
18689 : 131 : && n != TREE_OPERAND_LENGTH (t2))
18690 : : return false;
18691 : :
18692 : 305 : for (i = 0; i < n; ++i)
18693 : 186 : if (!c_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i)))
18694 : : return false;
18695 : :
18696 : : return true;
18697 : : }
18698 : :
18699 : 0 : case tcc_type:
18700 : 0 : return comptypes (t1, t2);
18701 : 0 : default:
18702 : 0 : gcc_unreachable ();
18703 : : }
18704 : : }
18705 : :
18706 : : /* Returns true when the function declaration FNDECL is implicit,
18707 : : introduced as a result of a call to an otherwise undeclared
18708 : : function, and false otherwise. */
18709 : :
18710 : : bool
18711 : 2013 : c_decl_implicit (const_tree fndecl)
18712 : : {
18713 : 2013 : return C_DECL_IMPLICIT (fndecl);
18714 : : }
|