Line data Source code
1 : /* Subroutines shared by all languages that are variants of C.
2 : Copyright (C) 1992-2026 Free Software Foundation, Inc.
3 :
4 : This file is part of GCC.
5 :
6 : GCC is free software; you can redistribute it and/or modify it under
7 : the terms of the GNU General Public License as published by the Free
8 : Software Foundation; either version 3, or (at your option) any later
9 : version.
10 :
11 : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 : WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 : for more details.
15 :
16 : You should have received a copy of the GNU General Public License
17 : along with GCC; see the file COPYING3. If not see
18 : <http://www.gnu.org/licenses/>. */
19 :
20 : #define GCC_C_COMMON_C
21 :
22 : #include "config.h"
23 : #include "system.h"
24 : #include "coretypes.h"
25 : #include "target.h"
26 : #include "function.h"
27 : #include "tree.h"
28 : #include "memmodel.h"
29 : #include "c-common.h"
30 : #include "gimple-expr.h"
31 : #include "tm_p.h"
32 : #include "stringpool.h"
33 : #include "cgraph.h"
34 : #include "diagnostic.h"
35 : #include "intl.h"
36 : #include "stor-layout.h"
37 : #include "calls.h"
38 : #include "attribs.h"
39 : #include "varasm.h"
40 : #include "trans-mem.h"
41 : #include "c-objc.h"
42 : #include "common/common-target.h"
43 : #include "langhooks.h"
44 : #include "tree-inline.h"
45 : #include "toplev.h"
46 : #include "tree-iterator.h"
47 : #include "opts.h"
48 : #include "gimplify.h"
49 : #include "substring-locations.h"
50 : #include "spellcheck.h"
51 : #include "c-spellcheck.h"
52 : #include "selftest.h"
53 : #include "debug.h"
54 : #include "tree-vector-builder.h"
55 : #include "vec-perm-indices.h"
56 : #include "tree-pretty-print-markup.h"
57 : #include "gcc-rich-location.h"
58 : #include "gcc-urlifier.h"
59 : #include "diagnostics/diagnostics-selftests.h"
60 :
61 : cpp_reader *parse_in; /* Declared in c-pragma.h. */
62 :
63 : /* Mode used to build pointers (VOIDmode means ptr_mode). */
64 :
65 : machine_mode c_default_pointer_mode = VOIDmode;
66 :
67 : /* The following symbols are subsumed in the c_global_trees array, and
68 : listed here individually for documentation purposes.
69 :
70 : INTEGER_TYPE and REAL_TYPE nodes for the standard data types.
71 :
72 : tree short_integer_type_node;
73 : tree long_integer_type_node;
74 : tree long_long_integer_type_node;
75 :
76 : tree short_unsigned_type_node;
77 : tree long_unsigned_type_node;
78 : tree long_long_unsigned_type_node;
79 :
80 : tree truthvalue_type_node;
81 : tree truthvalue_false_node;
82 : tree truthvalue_true_node;
83 :
84 : tree ptrdiff_type_node;
85 :
86 : tree unsigned_char_type_node;
87 : tree signed_char_type_node;
88 : tree wchar_type_node;
89 :
90 : tree char8_type_node;
91 : tree char16_type_node;
92 : tree char32_type_node;
93 :
94 : tree float_type_node;
95 : tree double_type_node;
96 : tree long_double_type_node;
97 :
98 : tree complex_integer_type_node;
99 : tree complex_float_type_node;
100 : tree complex_double_type_node;
101 : tree complex_long_double_type_node;
102 :
103 : tree dfloat32_type_node;
104 : tree dfloat64_type_node;
105 : tree dfloat128_type_node;
106 : tree dfloat64x_type_node;
107 :
108 : tree intQI_type_node;
109 : tree intHI_type_node;
110 : tree intSI_type_node;
111 : tree intDI_type_node;
112 : tree intTI_type_node;
113 :
114 : tree unsigned_intQI_type_node;
115 : tree unsigned_intHI_type_node;
116 : tree unsigned_intSI_type_node;
117 : tree unsigned_intDI_type_node;
118 : tree unsigned_intTI_type_node;
119 :
120 : tree widest_integer_literal_type_node;
121 : tree widest_unsigned_literal_type_node;
122 :
123 : Nodes for types `void *' and `const void *'.
124 :
125 : tree ptr_type_node, const_ptr_type_node;
126 :
127 : Nodes for types `char *' and `const char *'.
128 :
129 : tree string_type_node, const_string_type_node;
130 :
131 : Type `char[SOMENUMBER]'.
132 : Used when an array of char is needed and the size is irrelevant.
133 :
134 : tree char_array_type_node;
135 :
136 : Type `wchar_t[SOMENUMBER]' or something like it.
137 : Used when a wide string literal is created.
138 :
139 : tree wchar_array_type_node;
140 :
141 : Type `char8_t[SOMENUMBER]' or something like it.
142 : Used when a UTF-8 string literal is created.
143 :
144 : tree char8_array_type_node;
145 :
146 : Type `char16_t[SOMENUMBER]' or something like it.
147 : Used when a UTF-16 string literal is created.
148 :
149 : tree char16_array_type_node;
150 :
151 : Type `char32_t[SOMENUMBER]' or something like it.
152 : Used when a UTF-32 string literal is created.
153 :
154 : tree char32_array_type_node;
155 :
156 : Type `int ()' -- used for implicit declaration of functions.
157 :
158 : tree default_function_type;
159 :
160 : A VOID_TYPE node, packaged in a TREE_LIST.
161 :
162 : tree void_list_node;
163 :
164 : The lazily created VAR_DECLs for __FUNCTION__, __PRETTY_FUNCTION__,
165 : and __func__. (C doesn't generate __FUNCTION__ and__PRETTY_FUNCTION__
166 : VAR_DECLS, but C++ does.)
167 :
168 : tree function_name_decl_node;
169 : tree pretty_function_name_decl_node;
170 : tree c99_function_name_decl_node;
171 :
172 : Stack of nested function name VAR_DECLs.
173 :
174 : tree saved_function_name_decls;
175 :
176 : */
177 :
178 : tree c_global_trees[CTI_MAX];
179 :
180 : /* Switches common to the C front ends. */
181 :
182 : /* Nonzero means don't output line number information. */
183 :
184 : char flag_no_line_commands;
185 :
186 : /* Nonzero causes -E output not to be done, but directives such as
187 : #define that have side effects are still obeyed. */
188 :
189 : char flag_no_output;
190 :
191 : /* Nonzero means dump macros in some fashion. */
192 :
193 : char flag_dump_macros;
194 :
195 : /* Nonzero means pass #include lines through to the output. */
196 :
197 : char flag_dump_includes;
198 :
199 : /* Nonzero means process PCH files while preprocessing. */
200 :
201 : bool flag_pch_preprocess;
202 :
203 : /* The file name to which we should write a precompiled header, or
204 : NULL if no header will be written in this compile. */
205 :
206 : const char *pch_file;
207 :
208 : /* Nonzero if an ISO standard was selected. It rejects macros in the
209 : user's namespace. */
210 : int flag_iso;
211 :
212 : /* C/ObjC language option variables. */
213 :
214 :
215 : /* Nonzero means allow type mismatches in conditional expressions;
216 : just make their values `void'. */
217 :
218 : int flag_cond_mismatch;
219 :
220 : /* Nonzero means enable C89 Amendment 1 features. */
221 :
222 : int flag_isoc94;
223 :
224 : /* Nonzero means use the ISO C99 (or later) dialect of C. */
225 :
226 : int flag_isoc99;
227 :
228 : /* Nonzero means use the ISO C11 (or later) dialect of C. */
229 :
230 : int flag_isoc11;
231 :
232 : /* Nonzero means use the ISO C23 (or later) dialect of C. */
233 :
234 : int flag_isoc23;
235 :
236 : /* Nonzero means use the ISO C2Y (or later) dialect of C. */
237 :
238 : int flag_isoc2y;
239 :
240 : /* Nonzero means that we have builtin functions, and main is an int. */
241 :
242 : int flag_hosted = 1;
243 :
244 :
245 : /* ObjC language option variables. */
246 :
247 :
248 : /* Tells the compiler that this is a special run. Do not perform any
249 : compiling, instead we are to test some platform dependent features
250 : and output a C header file with appropriate definitions. */
251 :
252 : int print_struct_values;
253 :
254 : /* Tells the compiler what is the constant string class for ObjC. */
255 :
256 : const char *constant_string_class_name;
257 :
258 :
259 : /* C++ language option variables. */
260 :
261 : /* The reference version of the ABI for -Wabi. */
262 :
263 : int warn_abi_version = -1;
264 :
265 : /* The C++ dialect being used. Default set in c_common_init_options. */
266 :
267 : enum cxx_dialect cxx_dialect = cxx_unset;
268 :
269 : /* Maximum template instantiation depth. This limit exists to limit the
270 : time it takes to notice excessively recursive template instantiations.
271 :
272 : The default is lower than the 1024 recommended by the C++0x standard
273 : because G++ runs out of stack before 1024 with highly recursive template
274 : argument deduction substitution (g++.dg/cpp0x/enum11.C). */
275 :
276 : int max_tinst_depth = 900;
277 :
278 : /* The elements of `ridpointers' are identifier nodes for the reserved
279 : type names and storage classes. It is indexed by a RID_... value. */
280 : tree *ridpointers;
281 :
282 : tree (*make_fname_decl) (location_t, tree, int);
283 :
284 : /* Nonzero means don't warn about problems that occur when the code is
285 : executed. */
286 : int c_inhibit_evaluation_warnings;
287 :
288 : /* Whether we are building a boolean conversion inside
289 : convert_for_assignment, or some other late binary operation. If
290 : build_binary_op is called for C (from code shared by C and C++) in
291 : this case, then the operands have already been folded and the
292 : result will not be folded again, so C_MAYBE_CONST_EXPR should not
293 : be generated. */
294 : bool in_late_binary_op;
295 :
296 : /* Depending on which phase of processing we are in, we may need
297 : to prefer input_location to libcpp's locations. (Specifically,
298 : after the C++ lexer is done lexing tokens, but prior to calling
299 : cpp_finish (), we need to do so. */
300 : bool override_libcpp_locations;
301 :
302 : /* Information about how a function name is generated. */
303 : struct fname_var_t
304 : {
305 : tree *const decl; /* pointer to the VAR_DECL. */
306 : const unsigned rid; /* RID number for the identifier. */
307 : const int pretty; /* How pretty is it? */
308 : };
309 :
310 : /* The three ways of getting then name of the current function. */
311 :
312 : const struct fname_var_t fname_vars[] =
313 : {
314 : /* C99 compliant __func__, must be first. */
315 : {&c99_function_name_decl_node, RID_C99_FUNCTION_NAME, 0},
316 : /* GCC __FUNCTION__ compliant. */
317 : {&function_name_decl_node, RID_FUNCTION_NAME, 0},
318 : /* GCC __PRETTY_FUNCTION__ compliant. */
319 : {&pretty_function_name_decl_node, RID_PRETTY_FUNCTION_NAME, 1},
320 : {NULL, 0, 0},
321 : };
322 :
323 : /* Flags to restrict availability of generic features that
324 : are known to __has_{feature,extension}. */
325 :
326 : enum
327 : {
328 : HF_FLAG_NONE = 0,
329 : HF_FLAG_EXT = 1, /* Available only as an extension. */
330 : HF_FLAG_SANITIZE = 2, /* Availability depends on sanitizer flags. */
331 : };
332 :
333 : /* Info for generic features which can be queried through
334 : __has_{feature,extension}. */
335 :
336 : struct hf_feature_info
337 : {
338 : const char *ident;
339 : unsigned flags;
340 : unsigned mask;
341 : };
342 :
343 : /* Table of generic features which can be queried through
344 : __has_{feature,extension}. */
345 :
346 : static constexpr hf_feature_info has_feature_table[] =
347 : {
348 : { "address_sanitizer", HF_FLAG_SANITIZE, SANITIZE_ADDRESS },
349 : { "thread_sanitizer", HF_FLAG_SANITIZE, SANITIZE_THREAD },
350 : { "leak_sanitizer", HF_FLAG_SANITIZE, SANITIZE_LEAK },
351 : { "hwaddress_sanitizer", HF_FLAG_SANITIZE, SANITIZE_HWADDRESS },
352 : { "undefined_behavior_sanitizer", HF_FLAG_SANITIZE, SANITIZE_UNDEFINED },
353 : { "attribute_deprecated_with_message", HF_FLAG_NONE, 0 },
354 : { "attribute_unavailable_with_message", HF_FLAG_NONE, 0 },
355 : { "enumerator_attributes", HF_FLAG_NONE, 0 },
356 : { "tls", HF_FLAG_NONE, 0 },
357 : { "gnu_asm_goto_with_outputs", HF_FLAG_EXT, 0 },
358 : { "gnu_asm_goto_with_outputs_full", HF_FLAG_EXT, 0 }
359 : };
360 :
361 : /* Global visibility options. */
362 : struct visibility_flags visibility_options;
363 :
364 : static tree check_case_value (location_t, tree);
365 :
366 :
367 : static void check_nonnull_arg (void *, tree, unsigned HOST_WIDE_INT);
368 : static bool nonnull_check_p (tree, unsigned HOST_WIDE_INT);
369 :
370 : /* Reserved words. The third field is a mask: keywords are disabled
371 : if they match the mask.
372 :
373 : Masks for languages:
374 : C --std=c89: D_C99 | D_C23 | D_CXXONLY | D_OBJC | D_CXX_OBJC
375 : C --std=c99: D_C23 | D_CXXONLY | D_OBJC
376 : C --std=c17: D_C23 | D_CXXONLY | D_OBJC
377 : C --std=c23: D_CXXONLY | D_OBJC
378 : ObjC is like C except that D_OBJC and D_CXX_OBJC are not set
379 : C++ --std=c++98: D_CONLY | D_CXX11 | D_CXX20 | D_CXX26 | D_OBJC
380 : C++ --std=c++11: D_CONLY | D_CXX20 | D_CXX26 | D_OBJC
381 : C++ --std=c++20: D_CONLY | D_CXX26 | D_OBJC
382 : C++ --std=c++26: D_CONLY | D_OBJC
383 : ObjC++ is like C++ except that D_OBJC is not set
384 :
385 : If -fno-asm is used, D_ASM is added to the mask. If
386 : -fno-gnu-keywords is used, D_EXT is added. If -fno-asm and C in
387 : C89 mode, D_EXT89 is added for both -fno-asm and -fno-gnu-keywords.
388 : In C with -Wc++-compat, we warn if D_CXXWARN is set.
389 :
390 : Note the complication of the D_CXX_OBJC keywords. These are
391 : reserved words such as 'class'. In C++, 'class' is a reserved
392 : word. In Objective-C++ it is too. In Objective-C, it is a
393 : reserved word too, but only if it follows an '@' sign.
394 : */
395 : const struct c_common_resword c_common_reswords[] =
396 : {
397 : { "_Alignas", RID_ALIGNAS, D_CONLY },
398 : { "_Alignof", RID_ALIGNOF, D_CONLY },
399 : { "_Countof", RID_COUNTOF, D_CONLY },
400 : { "_Maxof", RID_MAXOF, D_CONLY },
401 : { "_Minof", RID_MINOF, D_CONLY },
402 : { "_Atomic", RID_ATOMIC, D_CONLY },
403 : { "_BitInt", RID_BITINT, D_CONLY },
404 : { "_Bool", RID_BOOL, D_CONLY },
405 : { "_Complex", RID_COMPLEX, 0 },
406 : { "_Imaginary", RID_IMAGINARY, D_CONLY },
407 : { "_Float16", RID_FLOAT16, 0 },
408 : { "_Float32", RID_FLOAT32, 0 },
409 : { "_Float64", RID_FLOAT64, 0 },
410 : { "_Float128", RID_FLOAT128, 0 },
411 : { "_Float32x", RID_FLOAT32X, 0 },
412 : { "_Float64x", RID_FLOAT64X, 0 },
413 : { "_Float128x", RID_FLOAT128X, 0 },
414 : { "_Decimal32", RID_DFLOAT32, D_CONLY },
415 : { "_Decimal64", RID_DFLOAT64, D_CONLY },
416 : { "_Decimal128", RID_DFLOAT128, D_CONLY },
417 : { "_Decimal64x", RID_DFLOAT64X, D_CONLY },
418 : { "_Fract", RID_FRACT, D_CONLY | D_EXT },
419 : { "_Accum", RID_ACCUM, D_CONLY | D_EXT },
420 : { "_Sat", RID_SAT, D_CONLY | D_EXT },
421 : { "_Static_assert", RID_STATIC_ASSERT, D_CONLY },
422 : { "_Noreturn", RID_NORETURN, D_CONLY },
423 : { "_Generic", RID_GENERIC, D_CONLY },
424 : { "_Thread_local", RID_THREAD, D_CONLY },
425 : { "__FUNCTION__", RID_FUNCTION_NAME, 0 },
426 : { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 },
427 : { "__alignof", RID_ALIGNOF, 0 },
428 : { "__alignof__", RID_ALIGNOF, 0 },
429 : { "__asm", RID_ASM, 0 },
430 : { "__asm__", RID_ASM, 0 },
431 : { "__attribute", RID_ATTRIBUTE, 0 },
432 : { "__attribute__", RID_ATTRIBUTE, 0 },
433 : { "__auto_type", RID_AUTO_TYPE, D_CONLY },
434 : { "__builtin_addressof", RID_ADDRESSOF, D_CXXONLY },
435 : { "__builtin_assoc_barrier", RID_BUILTIN_ASSOC_BARRIER, 0 },
436 : { "__builtin_bit_cast", RID_BUILTIN_BIT_CAST, D_CXXONLY },
437 : { "__builtin_call_with_static_chain",
438 : RID_BUILTIN_CALL_WITH_STATIC_CHAIN, D_CONLY },
439 : { "__builtin_choose_expr", RID_CHOOSE_EXPR, D_CONLY },
440 : { "__builtin_complex", RID_BUILTIN_COMPLEX, D_CONLY },
441 : { "__builtin_convertvector", RID_BUILTIN_CONVERTVECTOR, 0 },
442 : { "__builtin_counted_by_ref", RID_BUILTIN_COUNTED_BY_REF, D_CONLY },
443 : { "__builtin_has_attribute", RID_BUILTIN_HAS_ATTRIBUTE, 0 },
444 : { "__builtin_launder", RID_BUILTIN_LAUNDER, D_CXXONLY },
445 : { "__builtin_operator_new", RID_BUILTIN_OPERATOR_NEW, D_CXXONLY },
446 : { "__builtin_operator_delete", RID_BUILTIN_OPERATOR_DELETE, D_CXXONLY },
447 : { "__builtin_shuffle", RID_BUILTIN_SHUFFLE, 0 },
448 : { "__builtin_shufflevector", RID_BUILTIN_SHUFFLEVECTOR, 0 },
449 : { "__builtin_stdc_bit_ceil", RID_BUILTIN_STDC, D_CONLY },
450 : { "__builtin_stdc_bit_floor", RID_BUILTIN_STDC, D_CONLY },
451 : { "__builtin_stdc_bit_width", RID_BUILTIN_STDC, D_CONLY },
452 : { "__builtin_stdc_count_ones", RID_BUILTIN_STDC, D_CONLY },
453 : { "__builtin_stdc_count_zeros", RID_BUILTIN_STDC, D_CONLY },
454 : { "__builtin_stdc_first_leading_one", RID_BUILTIN_STDC, D_CONLY },
455 : { "__builtin_stdc_first_leading_zero", RID_BUILTIN_STDC, D_CONLY },
456 : { "__builtin_stdc_first_trailing_one", RID_BUILTIN_STDC, D_CONLY },
457 : { "__builtin_stdc_first_trailing_zero", RID_BUILTIN_STDC, D_CONLY },
458 : { "__builtin_stdc_has_single_bit", RID_BUILTIN_STDC, D_CONLY },
459 : { "__builtin_stdc_leading_ones", RID_BUILTIN_STDC, D_CONLY },
460 : { "__builtin_stdc_leading_zeros", RID_BUILTIN_STDC, D_CONLY },
461 : { "__builtin_stdc_rotate_left", RID_BUILTIN_STDC, D_CONLY },
462 : { "__builtin_stdc_rotate_right", RID_BUILTIN_STDC, D_CONLY },
463 : { "__builtin_stdc_trailing_ones", RID_BUILTIN_STDC, D_CONLY },
464 : { "__builtin_stdc_trailing_zeros", RID_BUILTIN_STDC, D_CONLY },
465 : { "__builtin_tgmath", RID_BUILTIN_TGMATH, D_CONLY },
466 : { "__builtin_offsetof", RID_OFFSETOF, 0 },
467 : { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P, D_CONLY },
468 : { "__builtin_c23_va_start", RID_C23_VA_START, D_C23 | D_CXX26 },
469 : { "__builtin_va_arg", RID_VA_ARG, 0 },
470 : { "__complex", RID_COMPLEX, 0 },
471 : { "__complex__", RID_COMPLEX, 0 },
472 : { "__const", RID_CONST, 0 },
473 : { "__const__", RID_CONST, 0 },
474 : { "__constinit", RID_CONSTINIT, D_CXXONLY },
475 : { "__contract_assert", RID_CONTASSERT, D_CXXONLY | D_CXXWARN },
476 : { "__decltype", RID_DECLTYPE, D_CXXONLY },
477 : { "__extension__", RID_EXTENSION, 0 },
478 : { "__func__", RID_C99_FUNCTION_NAME, 0 },
479 : { "__imag", RID_IMAGPART, 0 },
480 : { "__imag__", RID_IMAGPART, 0 },
481 : { "__inline", RID_INLINE, 0 },
482 : { "__inline__", RID_INLINE, 0 },
483 : { "__label__", RID_LABEL, 0 },
484 : { "__null", RID_NULL, 0 },
485 : { "__real", RID_REALPART, 0 },
486 : { "__real__", RID_REALPART, 0 },
487 : { "__restrict", RID_RESTRICT, 0 },
488 : { "__restrict__", RID_RESTRICT, 0 },
489 : { "__signed", RID_SIGNED, 0 },
490 : { "__signed__", RID_SIGNED, 0 },
491 : { "__thread", RID_THREAD, 0 },
492 : { "__transaction_atomic", RID_TRANSACTION_ATOMIC, 0 },
493 : { "__transaction_relaxed", RID_TRANSACTION_RELAXED, 0 },
494 : { "__transaction_cancel", RID_TRANSACTION_CANCEL, 0 },
495 : { "__typeof", RID_TYPEOF, 0 },
496 : { "__typeof__", RID_TYPEOF, 0 },
497 : { "__typeof_unqual", RID_TYPEOF_UNQUAL, D_CONLY },
498 : { "__typeof_unqual__", RID_TYPEOF_UNQUAL, D_CONLY },
499 : { "__volatile", RID_VOLATILE, 0 },
500 : { "__volatile__", RID_VOLATILE, 0 },
501 : { "__GIMPLE", RID_GIMPLE, D_CONLY },
502 : { "__PHI", RID_PHI, D_CONLY },
503 : { "__RTL", RID_RTL, D_CONLY },
504 : { "alignas", RID_ALIGNAS, D_C23 | D_CXX11 | D_CXXWARN },
505 : { "alignof", RID_ALIGNOF, D_C23 | D_CXX11 | D_CXXWARN },
506 : { "asm", RID_ASM, D_ASM },
507 : { "auto", RID_AUTO, 0 },
508 : { "bool", RID_BOOL, D_C23 | D_CXXWARN },
509 : { "break", RID_BREAK, 0 },
510 : { "case", RID_CASE, 0 },
511 : { "catch", RID_CATCH, D_CXX_OBJC | D_CXXWARN },
512 : { "char", RID_CHAR, 0 },
513 : { "char8_t", RID_CHAR8, D_CXX_CHAR8_T_FLAGS | D_CXXWARN },
514 : { "char16_t", RID_CHAR16, D_CXXONLY | D_CXX11 | D_CXXWARN },
515 : { "char32_t", RID_CHAR32, D_CXXONLY | D_CXX11 | D_CXXWARN },
516 : { "class", RID_CLASS, D_CXX_OBJC | D_CXXWARN },
517 : { "const", RID_CONST, 0 },
518 : { "consteval", RID_CONSTEVAL, D_CXXONLY | D_CXX20 | D_CXXWARN },
519 : { "constexpr", RID_CONSTEXPR, D_C23 | D_CXX11 | D_CXXWARN },
520 : { "constinit", RID_CONSTINIT, D_CXXONLY | D_CXX20 | D_CXXWARN },
521 : { "const_cast", RID_CONSTCAST, D_CXXONLY | D_CXXWARN },
522 : { "continue", RID_CONTINUE, 0 },
523 : { "contract_assert", RID_CONTASSERT, D_CXXONLY | D_CXXWARN | D_CXX26 },
524 : { "decltype", RID_DECLTYPE, D_CXXONLY | D_CXX11 | D_CXXWARN },
525 : { "default", RID_DEFAULT, 0 },
526 : { "delete", RID_DELETE, D_CXXONLY | D_CXXWARN },
527 : { "do", RID_DO, 0 },
528 : { "double", RID_DOUBLE, 0 },
529 : { "dynamic_cast", RID_DYNCAST, D_CXXONLY | D_CXXWARN },
530 : { "else", RID_ELSE, 0 },
531 : { "enum", RID_ENUM, 0 },
532 : { "explicit", RID_EXPLICIT, D_CXXONLY | D_CXXWARN },
533 : { "export", RID_EXPORT, D_CXXONLY | D_CXXWARN },
534 : { "extern", RID_EXTERN, 0 },
535 : { "false", RID_FALSE, D_C23 | D_CXXWARN },
536 : { "float", RID_FLOAT, 0 },
537 : { "for", RID_FOR, 0 },
538 : { "friend", RID_FRIEND, D_CXXONLY | D_CXXWARN },
539 : { "goto", RID_GOTO, 0 },
540 : { "if", RID_IF, 0 },
541 : { "inline", RID_INLINE, D_EXT89 },
542 : { "int", RID_INT, 0 },
543 : { "long", RID_LONG, 0 },
544 : { "mutable", RID_MUTABLE, D_CXXONLY | D_CXXWARN },
545 : { "namespace", RID_NAMESPACE, D_CXXONLY | D_CXXWARN },
546 : { "new", RID_NEW, D_CXXONLY | D_CXXWARN },
547 : { "noexcept", RID_NOEXCEPT, D_CXXONLY | D_CXX11 | D_CXXWARN },
548 : { "nullptr", RID_NULLPTR, D_C23 | D_CXX11 | D_CXXWARN },
549 : { "operator", RID_OPERATOR, D_CXXONLY | D_CXXWARN },
550 : { "private", RID_PRIVATE, D_CXX_OBJC | D_CXXWARN },
551 : { "protected", RID_PROTECTED, D_CXX_OBJC | D_CXXWARN },
552 : { "public", RID_PUBLIC, D_CXX_OBJC | D_CXXWARN },
553 : { "register", RID_REGISTER, 0 },
554 : { "reinterpret_cast", RID_REINTCAST, D_CXXONLY | D_CXXWARN },
555 : { "restrict", RID_RESTRICT, D_CONLY | D_C99 },
556 : { "return", RID_RETURN, 0 },
557 : { "short", RID_SHORT, 0 },
558 : { "signed", RID_SIGNED, 0 },
559 : { "sizeof", RID_SIZEOF, 0 },
560 : { "static", RID_STATIC, 0 },
561 : { "static_assert", RID_STATIC_ASSERT, D_C23 | D_CXX11 | D_CXXWARN },
562 : { "static_cast", RID_STATCAST, D_CXXONLY | D_CXXWARN },
563 : { "struct", RID_STRUCT, 0 },
564 : { "switch", RID_SWITCH, 0 },
565 : { "template", RID_TEMPLATE, D_CXXONLY | D_CXXWARN },
566 : { "this", RID_THIS, D_CXXONLY | D_CXXWARN },
567 : { "thread_local", RID_THREAD, D_C23 | D_CXX11 | D_CXXWARN },
568 : { "throw", RID_THROW, D_CXX_OBJC | D_CXXWARN },
569 : { "true", RID_TRUE, D_C23 | D_CXXWARN },
570 : { "try", RID_TRY, D_CXX_OBJC | D_CXXWARN },
571 : { "typedef", RID_TYPEDEF, 0 },
572 : { "typename", RID_TYPENAME, D_CXXONLY | D_CXXWARN },
573 : { "typeid", RID_TYPEID, D_CXXONLY | D_CXXWARN },
574 : { "typeof", RID_TYPEOF, D_EXT11 },
575 : { "typeof_unqual", RID_TYPEOF_UNQUAL, D_CONLY | D_C23 },
576 : { "union", RID_UNION, 0 },
577 : { "unsigned", RID_UNSIGNED, 0 },
578 : { "using", RID_USING, D_CXXONLY | D_CXXWARN },
579 : { "virtual", RID_VIRTUAL, D_CXXONLY | D_CXXWARN },
580 : { "void", RID_VOID, 0 },
581 : { "volatile", RID_VOLATILE, 0 },
582 : { "wchar_t", RID_WCHAR, D_CXXONLY },
583 : { "while", RID_WHILE, 0 },
584 :
585 : /* C++ transactional memory. */
586 : { "synchronized", RID_SYNCHRONIZED, D_CXX_OBJC | D_TRANSMEM },
587 : { "atomic_noexcept", RID_ATOMIC_NOEXCEPT, D_CXXONLY | D_TRANSMEM },
588 : { "atomic_cancel", RID_ATOMIC_CANCEL, D_CXXONLY | D_TRANSMEM },
589 : { "atomic_commit", RID_TRANSACTION_ATOMIC, D_CXXONLY | D_TRANSMEM },
590 :
591 : /* Concepts-related keywords */
592 : { "concept", RID_CONCEPT, D_CXX_CONCEPTS_FLAGS | D_CXXWARN },
593 : { "requires", RID_REQUIRES, D_CXX_CONCEPTS_FLAGS | D_CXXWARN },
594 :
595 : /* Modules-related keywords, these are internal unspellable tokens,
596 : created by the preprocessor. */
597 : { "module ", RID__MODULE, D_CXX_MODULES_FLAGS | D_CXXWARN },
598 : { "import ", RID__IMPORT, D_CXX_MODULES_FLAGS | D_CXXWARN },
599 : { "export ", RID__EXPORT, D_CXX_MODULES_FLAGS | D_CXXWARN },
600 :
601 : /* Coroutines-related keywords */
602 : { "co_await", RID_CO_AWAIT, D_CXX_COROUTINES_FLAGS | D_CXXWARN },
603 : { "co_yield", RID_CO_YIELD, D_CXX_COROUTINES_FLAGS | D_CXXWARN },
604 : { "co_return", RID_CO_RETURN, D_CXX_COROUTINES_FLAGS | D_CXXWARN },
605 :
606 : /* These Objective-C keywords are recognized only immediately after
607 : an '@'. */
608 : { "compatibility_alias", RID_AT_ALIAS, D_OBJC },
609 : { "defs", RID_AT_DEFS, D_OBJC },
610 : { "encode", RID_AT_ENCODE, D_OBJC },
611 : { "end", RID_AT_END, D_OBJC },
612 : { "implementation", RID_AT_IMPLEMENTATION, D_OBJC },
613 : { "interface", RID_AT_INTERFACE, D_OBJC },
614 : { "protocol", RID_AT_PROTOCOL, D_OBJC },
615 : { "selector", RID_AT_SELECTOR, D_OBJC },
616 : { "finally", RID_AT_FINALLY, D_OBJC },
617 : { "optional", RID_AT_OPTIONAL, D_OBJC },
618 : { "required", RID_AT_REQUIRED, D_OBJC },
619 : { "property", RID_AT_PROPERTY, D_OBJC },
620 : { "package", RID_AT_PACKAGE, D_OBJC },
621 : { "synthesize", RID_AT_SYNTHESIZE, D_OBJC },
622 : { "dynamic", RID_AT_DYNAMIC, D_OBJC },
623 : /* These are recognized only in protocol-qualifier context
624 : (see above) */
625 : { "bycopy", RID_BYCOPY, D_OBJC },
626 : { "byref", RID_BYREF, D_OBJC },
627 : { "in", RID_IN, D_OBJC },
628 : { "inout", RID_INOUT, D_OBJC },
629 : { "oneway", RID_ONEWAY, D_OBJC },
630 : { "out", RID_OUT, D_OBJC },
631 : /* These are recognized inside a property attribute list */
632 : { "assign", RID_ASSIGN, D_OBJC },
633 : { "atomic", RID_PROPATOMIC, D_OBJC },
634 : { "copy", RID_COPY, D_OBJC },
635 : { "getter", RID_GETTER, D_OBJC },
636 : { "nonatomic", RID_NONATOMIC, D_OBJC },
637 : { "readonly", RID_READONLY, D_OBJC },
638 : { "readwrite", RID_READWRITE, D_OBJC },
639 : { "retain", RID_RETAIN, D_OBJC },
640 : { "setter", RID_SETTER, D_OBJC },
641 : /* These are Objective C implementation of nullability, accepted only in
642 : specific contexts. */
643 : { "null_unspecified", RID_NULL_UNSPECIFIED, D_OBJC },
644 : { "nullable", RID_NULLABLE, D_OBJC },
645 : { "nonnull", RID_NONNULL, D_OBJC },
646 : { "null_resettable", RID_NULL_RESETTABLE, D_OBJC },
647 : };
648 :
649 : const unsigned int num_c_common_reswords = ARRAY_SIZE (c_common_reswords);
650 :
651 : /* Return identifier for address space AS. */
652 :
653 : const char *
654 3 : c_addr_space_name (addr_space_t as)
655 : {
656 3 : int rid = RID_FIRST_ADDR_SPACE + as;
657 3 : gcc_assert (ridpointers [rid]);
658 3 : return IDENTIFIER_POINTER (ridpointers [rid]);
659 : }
660 :
661 : /* Push current bindings for the function name VAR_DECLS. */
662 :
663 : void
664 194595114 : start_fname_decls (void)
665 : {
666 194595114 : unsigned ix;
667 194595114 : tree saved = NULL_TREE;
668 :
669 778380456 : for (ix = 0; fname_vars[ix].decl; ix++)
670 : {
671 583785342 : tree decl = *fname_vars[ix].decl;
672 :
673 583785342 : if (decl)
674 : {
675 53396 : saved = tree_cons (decl, build_int_cst (integer_type_node, ix),
676 : saved);
677 53396 : *fname_vars[ix].decl = NULL_TREE;
678 : }
679 : }
680 194595114 : if (saved || saved_function_name_decls)
681 : /* Normally they'll have been NULL, so only push if we've got a
682 : stack, or they are non-NULL. */
683 70621 : saved_function_name_decls = tree_cons (saved, NULL_TREE,
684 : saved_function_name_decls);
685 194595114 : }
686 :
687 : /* Finish up the current bindings, adding them into the current function's
688 : statement tree. This must be done _before_ finish_stmt_tree is called.
689 : If there is no current function, we must be at file scope and no statements
690 : are involved. Pop the previous bindings. */
691 :
692 : void
693 194482199 : finish_fname_decls (void)
694 : {
695 194482199 : unsigned ix;
696 194482199 : tree stmts = NULL_TREE;
697 194482199 : tree stack = saved_function_name_decls;
698 :
699 194854838 : for (; stack && TREE_VALUE (stack); stack = TREE_CHAIN (stack))
700 151009 : append_to_statement_list (TREE_VALUE (stack), &stmts);
701 :
702 194482199 : if (stmts)
703 : {
704 150904 : tree *bodyp = &DECL_SAVED_TREE (current_function_decl);
705 :
706 150904 : if (TREE_CODE (*bodyp) == BIND_EXPR)
707 143326 : bodyp = &BIND_EXPR_BODY (*bodyp);
708 :
709 150904 : append_to_statement_list_force (*bodyp, &stmts);
710 150904 : *bodyp = stmts;
711 : }
712 :
713 777928796 : for (ix = 0; fname_vars[ix].decl; ix++)
714 583446597 : *fname_vars[ix].decl = NULL_TREE;
715 :
716 194482199 : if (stack)
717 : {
718 : /* We had saved values, restore them. */
719 70621 : tree saved;
720 :
721 124017 : for (saved = TREE_PURPOSE (stack); saved; saved = TREE_CHAIN (saved))
722 : {
723 53396 : tree decl = TREE_PURPOSE (saved);
724 53396 : unsigned ix = TREE_INT_CST_LOW (TREE_VALUE (saved));
725 :
726 53396 : *fname_vars[ix].decl = decl;
727 : }
728 70621 : stack = TREE_CHAIN (stack);
729 : }
730 194482199 : saved_function_name_decls = stack;
731 194482199 : }
732 :
733 : /* Return the text name of the current function, suitably prettified
734 : by PRETTY_P. Return string must be freed by caller. */
735 :
736 : const char *
737 3517 : fname_as_string (int pretty_p)
738 : {
739 3517 : const char *name = "top level";
740 3517 : char *namep;
741 3517 : int vrb = 2, len;
742 3517 : cpp_string cstr = { 0, 0 }, strname;
743 :
744 3517 : if (!pretty_p)
745 : {
746 1857 : name = "";
747 1857 : vrb = 0;
748 : }
749 :
750 3517 : if (current_function_decl)
751 3510 : name = lang_hooks.decl_printable_name (current_function_decl, vrb);
752 :
753 3517 : len = strlen (name) + 3; /* Two for '"'s. One for NULL. */
754 :
755 3517 : namep = XNEWVEC (char, len);
756 3517 : snprintf (namep, len, "\"%s\"", name);
757 3517 : strname.text = (unsigned char *) namep;
758 3517 : strname.len = len - 1;
759 :
760 3517 : if (cpp_interpret_string (parse_in, &strname, 1, &cstr, CPP_STRING))
761 : {
762 3517 : XDELETEVEC (namep);
763 3517 : return (const char *) cstr.text;
764 : }
765 :
766 : return namep;
767 : }
768 :
769 : /* Return the VAR_DECL for a const char array naming the current
770 : function. If the VAR_DECL has not yet been created, create it
771 : now. RID indicates how it should be formatted and IDENTIFIER_NODE
772 : ID is its name (unfortunately C and C++ hold the RID values of
773 : keywords in different places, so we can't derive RID from ID in
774 : this language independent code. LOC is the location of the
775 : function. */
776 :
777 : tree
778 250388 : fname_decl (location_t loc, unsigned int rid, tree id)
779 : {
780 250388 : unsigned ix;
781 250388 : tree decl = NULL_TREE;
782 :
783 730410 : for (ix = 0; fname_vars[ix].decl; ix++)
784 730410 : if (fname_vars[ix].rid == rid)
785 : break;
786 :
787 250388 : decl = *fname_vars[ix].decl;
788 250388 : if (!decl)
789 : {
790 : /* If a tree is built here, it would normally have the lineno of
791 : the current statement. Later this tree will be moved to the
792 : beginning of the function and this line number will be wrong.
793 : To avoid this problem set the lineno to 0 here; that prevents
794 : it from appearing in the RTL. */
795 151009 : tree stmts;
796 151009 : location_t saved_location = input_location;
797 151009 : input_location = UNKNOWN_LOCATION;
798 :
799 151009 : stmts = push_stmt_list ();
800 151009 : decl = (*make_fname_decl) (loc, id, fname_vars[ix].pretty);
801 151009 : stmts = pop_stmt_list (stmts);
802 151009 : if (!IS_EMPTY_STMT (stmts))
803 151009 : saved_function_name_decls
804 151009 : = tree_cons (decl, stmts, saved_function_name_decls);
805 151009 : *fname_vars[ix].decl = decl;
806 151009 : input_location = saved_location;
807 : }
808 250388 : if (!ix && !current_function_decl)
809 4 : pedwarn (loc, 0, "%qD is not defined outside of function scope", decl);
810 :
811 250388 : return decl;
812 : }
813 :
814 : /* Given a STRING_CST, give it a suitable array-of-chars data type. */
815 :
816 : tree
817 28294856 : fix_string_type (tree value)
818 : {
819 28294856 : int length = TREE_STRING_LENGTH (value);
820 28294856 : int nchars, charsz;
821 28294856 : tree e_type, i_type, a_type;
822 :
823 : /* Compute the number of elements, for the array type. */
824 28294856 : if (TREE_TYPE (value) == char_array_type_node || !TREE_TYPE (value))
825 : {
826 27341017 : charsz = 1;
827 27341017 : e_type = char_type_node;
828 : }
829 953839 : else if (flag_char8_t && TREE_TYPE (value) == char8_array_type_node)
830 : {
831 1409 : charsz = TYPE_PRECISION (char8_type_node) / BITS_PER_UNIT;
832 1409 : e_type = char8_type_node;
833 : }
834 952430 : else if (TREE_TYPE (value) == char16_array_type_node)
835 : {
836 958 : charsz = TYPE_PRECISION (char16_type_node) / BITS_PER_UNIT;
837 958 : e_type = char16_type_node;
838 : }
839 951472 : else if (TREE_TYPE (value) == char32_array_type_node)
840 : {
841 3055 : charsz = TYPE_PRECISION (char32_type_node) / BITS_PER_UNIT;
842 3055 : e_type = char32_type_node;
843 : }
844 : else
845 : {
846 948417 : charsz = TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT;
847 948417 : e_type = wchar_type_node;
848 : }
849 :
850 : /* This matters only for targets where ssizetype has smaller precision
851 : than 32 bits. */
852 28294856 : if (wi::lts_p (wi::to_wide (TYPE_MAX_VALUE (ssizetype)), length))
853 : {
854 0 : error ("size of string literal is too large");
855 0 : length = tree_to_shwi (TYPE_MAX_VALUE (ssizetype)) / charsz * charsz;
856 0 : char *str = const_cast<char *> (TREE_STRING_POINTER (value));
857 0 : memset (str + length, '\0',
858 0 : MIN (TREE_STRING_LENGTH (value) - length, charsz));
859 0 : TREE_STRING_LENGTH (value) = length;
860 : }
861 28294856 : nchars = length / charsz;
862 :
863 : /* C89 2.2.4.1, C99 5.2.4.1 (Translation limits). The analogous
864 : limit in C++98 Annex B is very large (65536) and is not normative,
865 : so we do not diagnose it (warn_overlength_strings is forced off
866 : in c_common_post_options). */
867 28294856 : if (warn_overlength_strings)
868 : {
869 15253 : const int nchars_max = flag_isoc99 ? 4095 : 509;
870 15253 : const int relevant_std = flag_isoc99 ? 99 : 90;
871 15253 : if (nchars - 1 > nchars_max)
872 : /* Translators: The %d after 'ISO C' will be 90 or 99. Do not
873 : separate the %d from the 'C'. 'ISO' should not be
874 : translated, but it may be moved after 'C%d' in languages
875 : where modifiers follow nouns. */
876 5 : pedwarn (input_location, OPT_Woverlength_strings,
877 : "string length %qd is greater than the length %qd "
878 : "ISO C%d compilers are required to support",
879 : nchars - 1, nchars_max, relevant_std);
880 : }
881 :
882 : /* Create the array type for the string constant. The ISO C++
883 : standard says that a string literal has type `const char[N]' or
884 : `const wchar_t[N]'. We use the same logic when invoked as a C
885 : front-end with -Wwrite-strings.
886 : ??? We should change the type of an expression depending on the
887 : state of a warning flag. We should just be warning -- see how
888 : this is handled in the C++ front-end for the deprecated implicit
889 : conversion from string literals to `char*' or `wchar_t*'.
890 :
891 : The C++ front end relies on TYPE_MAIN_VARIANT of a cv-qualified
892 : array type being the unqualified version of that type.
893 : Therefore, if we are constructing an array of const char, we must
894 : construct the matching unqualified array type first. The C front
895 : end does not require this, but it does no harm, so we do it
896 : unconditionally. */
897 28294856 : i_type = build_index_type (size_int (nchars - 1));
898 28294856 : a_type = build_array_type (e_type, i_type);
899 28294856 : if (c_dialect_cxx() || warn_write_strings)
900 25900217 : a_type = c_build_qualified_type (a_type, TYPE_QUAL_CONST);
901 :
902 28294856 : TREE_TYPE (value) = a_type;
903 28294856 : TREE_CONSTANT (value) = 1;
904 28294856 : TREE_READONLY (value) = 1;
905 28294856 : TREE_STATIC (value) = 1;
906 28294856 : return value;
907 : }
908 :
909 : /* Given a string of type STRING_TYPE, determine what kind of string
910 : token would give an equivalent execution encoding: CPP_STRING,
911 : CPP_STRING16, or CPP_STRING32. Return CPP_OTHER in case of error.
912 : This may not be exactly the string token type that initially created
913 : the string, since CPP_WSTRING is indistinguishable from the 16/32 bit
914 : string type, and CPP_UTF8STRING is indistinguishable from CPP_STRING
915 : at this point.
916 :
917 : This effectively reverses part of the logic in lex_string and
918 : fix_string_type. */
919 :
920 : static enum cpp_ttype
921 11111 : get_cpp_ttype_from_string_type (tree string_type)
922 : {
923 11111 : gcc_assert (string_type);
924 11111 : if (TREE_CODE (string_type) == POINTER_TYPE)
925 5972 : string_type = TREE_TYPE (string_type);
926 :
927 11111 : if (TREE_CODE (string_type) != ARRAY_TYPE)
928 : return CPP_OTHER;
929 :
930 11111 : tree element_type = TREE_TYPE (string_type);
931 11111 : if (TREE_CODE (element_type) != INTEGER_TYPE)
932 : return CPP_OTHER;
933 :
934 11111 : int bits_per_character = TYPE_PRECISION (element_type);
935 11111 : switch (bits_per_character)
936 : {
937 : case 8:
938 : return CPP_STRING; /* It could have also been CPP_UTF8STRING. */
939 2 : case 16:
940 2 : return CPP_STRING16;
941 4 : case 32:
942 4 : return CPP_STRING32;
943 : }
944 :
945 : return CPP_OTHER;
946 : }
947 :
948 : /* The global record of string concatentations, for use in
949 : extracting locations within string literals. */
950 :
951 : GTY(()) string_concat_db *g_string_concat_db;
952 :
953 : /* Implementation of LANG_HOOKS_GET_SUBSTRING_LOCATION. */
954 :
955 : const char *
956 11111 : c_get_substring_location (const substring_loc &substr_loc,
957 : location_t *out_loc)
958 : {
959 11111 : enum cpp_ttype tok_type
960 11111 : = get_cpp_ttype_from_string_type (substr_loc.get_string_type ());
961 11111 : if (tok_type == CPP_OTHER)
962 : return "unrecognized string type";
963 :
964 11111 : return get_location_within_string (parse_in,
965 : global_dc->get_file_cache (),
966 : g_string_concat_db,
967 : substr_loc.get_fmt_string_loc (),
968 : tok_type,
969 : substr_loc.get_caret_idx (),
970 : substr_loc.get_start_idx (),
971 : substr_loc.get_end_idx (),
972 11111 : out_loc);
973 : }
974 :
975 :
976 : /* Return true iff T is a boolean promoted to int. */
977 :
978 : bool
979 93218 : bool_promoted_to_int_p (tree t)
980 : {
981 76087 : return (CONVERT_EXPR_P (t)
982 17231 : && TREE_TYPE (t) == integer_type_node
983 93318 : && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == BOOLEAN_TYPE);
984 : }
985 :
986 : /* vector_targets_convertible_p is used for vector pointer types. The
987 : callers perform various checks that the qualifiers are satisfactory,
988 : while OTOH vector_targets_convertible_p ignores the number of elements
989 : in the vectors. That's fine with vector pointers as we can consider,
990 : say, a vector of 8 elements as two consecutive vectors of 4 elements,
991 : and that does not require and conversion of the pointer values.
992 : In contrast, vector_types_convertible_p and
993 : vector_types_compatible_elements_p are used for vector value types. */
994 : /* True if pointers to distinct types T1 and T2 can be converted to
995 : each other without an explicit cast. Only returns true for opaque
996 : vector types. */
997 : bool
998 2035262 : vector_targets_convertible_p (const_tree t1, const_tree t2)
999 : {
1000 981673 : if (VECTOR_TYPE_P (t1) && VECTOR_TYPE_P (t2)
1001 981497 : && (TYPE_VECTOR_OPAQUE (t1) || TYPE_VECTOR_OPAQUE (t2))
1002 2035262 : && tree_int_cst_equal (TYPE_SIZE (t1), TYPE_SIZE (t2)))
1003 : return true;
1004 :
1005 : return false;
1006 : }
1007 :
1008 : /* vector_types_convertible_p is used for vector value types.
1009 : It could in principle call vector_targets_convertible_p as a subroutine,
1010 : but then the check for vector type would be duplicated with its callers,
1011 : and also the purpose of vector_targets_convertible_p would become
1012 : muddled.
1013 : Where vector_types_convertible_p returns true, a conversion might still be
1014 : needed to make the types match.
1015 : In contrast, vector_targets_convertible_p is used for vector pointer
1016 : values, and vector_types_compatible_elements_p is used specifically
1017 : in the context for binary operators, as a check if use is possible without
1018 : conversion. */
1019 : /* True if vector types T1 and T2 can be converted to each other
1020 : without an explicit cast. If EMIT_LAX_NOTE is true, and T1 and T2
1021 : can only be converted with -flax-vector-conversions yet that is not
1022 : in effect, emit a note telling the user about that option if such
1023 : a note has not previously been emitted. */
1024 : bool
1025 18612477 : vector_types_convertible_p (const_tree t1, const_tree t2, bool emit_lax_note)
1026 : {
1027 18612477 : static bool emitted_lax_note = false;
1028 18612477 : bool convertible_lax;
1029 :
1030 37219795 : if ((TYPE_VECTOR_OPAQUE (t1) || TYPE_VECTOR_OPAQUE (t2))
1031 18614274 : && tree_int_cst_equal (TYPE_SIZE (t1), TYPE_SIZE (t2)))
1032 : return true;
1033 :
1034 37211158 : convertible_lax =
1035 18605579 : (tree_int_cst_equal (TYPE_SIZE (t1), TYPE_SIZE (t2))
1036 18600384 : && (TREE_CODE (TREE_TYPE (t1)) != REAL_TYPE
1037 10801027 : || known_eq (TYPE_VECTOR_SUBPARTS (t1),
1038 : TYPE_VECTOR_SUBPARTS (t2)))
1039 55738395 : && (INTEGRAL_TYPE_P (TREE_TYPE (t1))
1040 18566408 : == INTEGRAL_TYPE_P (TREE_TYPE (t2))));
1041 :
1042 18605579 : if (!convertible_lax || flag_lax_vector_conversions)
1043 75785 : return convertible_lax;
1044 :
1045 18529794 : if (known_eq (TYPE_VECTOR_SUBPARTS (t1), TYPE_VECTOR_SUBPARTS (t2))
1046 18529794 : && lang_hooks.types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2)))
1047 16946363 : return true;
1048 :
1049 1583431 : if (emit_lax_note && !emitted_lax_note)
1050 : {
1051 10 : emitted_lax_note = true;
1052 10 : inform (input_location, "use %<-flax-vector-conversions%> to permit "
1053 : "conversions between vectors with differing "
1054 : "element types or numbers of subparts");
1055 : }
1056 :
1057 : return false;
1058 : }
1059 :
1060 : /* Build a VEC_PERM_EXPR if V0, V1 and MASK are not error_mark_nodes
1061 : and have vector types, V0 has the same type as V1, and the number of
1062 : elements of V0, V1, MASK is the same.
1063 :
1064 : In case V1 is a NULL_TREE it is assumed that __builtin_shuffle was
1065 : called with two arguments. In this case implementation passes the
1066 : first argument twice in order to share the same tree code. This fact
1067 : could enable the mask-values being twice the vector length. This is
1068 : an implementation accident and this semantics is not guaranteed to
1069 : the user. */
1070 : tree
1071 488161 : c_build_vec_perm_expr (location_t loc, tree v0, tree v1, tree mask,
1072 : bool complain)
1073 : {
1074 488161 : tree ret;
1075 488161 : bool wrap = true;
1076 488161 : bool maybe_const = false;
1077 488161 : bool two_arguments = false;
1078 :
1079 488161 : if (v1 == NULL_TREE)
1080 : {
1081 445778 : two_arguments = true;
1082 445778 : v1 = v0;
1083 : }
1084 :
1085 488161 : if (v0 == error_mark_node || v1 == error_mark_node
1086 488161 : || mask == error_mark_node)
1087 : return error_mark_node;
1088 :
1089 488161 : if (!gnu_vector_type_p (TREE_TYPE (mask))
1090 488161 : || !VECTOR_INTEGER_TYPE_P (TREE_TYPE (mask)))
1091 : {
1092 3 : if (complain)
1093 0 : error_at (loc, "%<__builtin_shuffle%> last argument must "
1094 : "be an integer vector");
1095 3 : return error_mark_node;
1096 : }
1097 :
1098 488158 : if (!gnu_vector_type_p (TREE_TYPE (v0))
1099 488158 : || !gnu_vector_type_p (TREE_TYPE (v1)))
1100 : {
1101 0 : if (complain)
1102 0 : error_at (loc, "%<__builtin_shuffle%> arguments must be vectors");
1103 0 : return error_mark_node;
1104 : }
1105 :
1106 488158 : if (TYPE_MAIN_VARIANT (TREE_TYPE (v0)) != TYPE_MAIN_VARIANT (TREE_TYPE (v1)))
1107 : {
1108 0 : if (complain)
1109 0 : error_at (loc, "%<__builtin_shuffle%> argument vectors must be of "
1110 : "the same type");
1111 0 : return error_mark_node;
1112 : }
1113 :
1114 488158 : if (maybe_ne (TYPE_VECTOR_SUBPARTS (TREE_TYPE (v0)),
1115 488158 : TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask)))
1116 488158 : && maybe_ne (TYPE_VECTOR_SUBPARTS (TREE_TYPE (v1)),
1117 0 : TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask))))
1118 : {
1119 0 : if (complain)
1120 0 : error_at (loc, "%<__builtin_shuffle%> number of elements of the "
1121 : "argument vector(s) and the mask vector should "
1122 : "be the same");
1123 0 : return error_mark_node;
1124 : }
1125 :
1126 488158 : if (GET_MODE_BITSIZE (SCALAR_TYPE_MODE (TREE_TYPE (TREE_TYPE (v0))))
1127 976316 : != GET_MODE_BITSIZE (SCALAR_TYPE_MODE (TREE_TYPE (TREE_TYPE (mask)))))
1128 : {
1129 0 : if (complain)
1130 0 : error_at (loc, "%<__builtin_shuffle%> argument vector(s) inner type "
1131 : "must have the same size as inner type of the mask");
1132 0 : return error_mark_node;
1133 : }
1134 :
1135 488158 : if (!c_dialect_cxx ())
1136 : {
1137 : /* Avoid C_MAYBE_CONST_EXPRs inside VEC_PERM_EXPR. */
1138 470581 : v0 = c_fully_fold (v0, false, &maybe_const);
1139 470581 : wrap &= maybe_const;
1140 :
1141 470581 : if (two_arguments)
1142 429069 : v1 = v0 = save_expr (v0);
1143 : else
1144 : {
1145 41512 : v1 = c_fully_fold (v1, false, &maybe_const);
1146 41512 : wrap &= maybe_const;
1147 : }
1148 :
1149 470581 : mask = c_fully_fold (mask, false, &maybe_const);
1150 470581 : wrap &= maybe_const;
1151 : }
1152 17577 : else if (two_arguments)
1153 16706 : v1 = v0 = save_expr (v0);
1154 :
1155 488158 : ret = build3_loc (loc, VEC_PERM_EXPR, TREE_TYPE (v0), v0, v1, mask);
1156 :
1157 488158 : if (!c_dialect_cxx () && !wrap)
1158 470581 : ret = c_wrap_maybe_const (ret, true);
1159 :
1160 : return ret;
1161 : }
1162 :
1163 : /* Build a VEC_PERM_EXPR if V0, V1 are not error_mark_nodes
1164 : and have vector types, V0 has the same element type as V1, and the
1165 : number of elements the result is that of MASK. */
1166 : tree
1167 1121329 : c_build_shufflevector (location_t loc, tree v0, tree v1,
1168 : const vec<tree> &mask, bool complain)
1169 : {
1170 1121329 : tree ret;
1171 1121329 : bool wrap = true;
1172 1121329 : bool maybe_const = false;
1173 :
1174 1121329 : if (v0 == error_mark_node || v1 == error_mark_node)
1175 : return error_mark_node;
1176 :
1177 1121329 : if (!gnu_vector_type_p (TREE_TYPE (v0))
1178 1121329 : || !gnu_vector_type_p (TREE_TYPE (v1)))
1179 : {
1180 4 : if (complain)
1181 4 : error_at (loc, "%<__builtin_shufflevector%> arguments must be vectors");
1182 4 : return error_mark_node;
1183 : }
1184 :
1185 : /* ??? In principle one could select a constant part of a variable size
1186 : vector but things get a bit awkward with trying to support this here. */
1187 1121325 : unsigned HOST_WIDE_INT v0n, v1n;
1188 1121325 : if (!TYPE_VECTOR_SUBPARTS (TREE_TYPE (v0)).is_constant (&v0n)
1189 1121325 : || !TYPE_VECTOR_SUBPARTS (TREE_TYPE (v1)).is_constant (&v1n))
1190 : {
1191 : if (complain)
1192 : error_at (loc, "%<__builtin_shufflevector%> arguments must be constant"
1193 : " size vectors");
1194 : return error_mark_node;
1195 : }
1196 :
1197 1121325 : if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (v0)))
1198 1121325 : != TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (v1))))
1199 : {
1200 4 : if (complain)
1201 4 : error_at (loc, "%<__builtin_shufflevector%> argument vectors must "
1202 : "have the same element type");
1203 4 : return error_mark_node;
1204 : }
1205 :
1206 1121321 : if (!pow2p_hwi (mask.length ()))
1207 : {
1208 4 : if (complain)
1209 4 : error_at (loc, "%<__builtin_shufflevector%> must specify a result "
1210 : "with a power of two number of elements");
1211 4 : return error_mark_node;
1212 : }
1213 :
1214 1121317 : if (!c_dialect_cxx ())
1215 : {
1216 : /* Avoid C_MAYBE_CONST_EXPRs inside VEC_PERM_EXPR. */
1217 1079616 : v0 = c_fully_fold (v0, false, &maybe_const);
1218 1079616 : wrap &= maybe_const;
1219 :
1220 1079616 : v1 = c_fully_fold (v1, false, &maybe_const);
1221 1079616 : wrap &= maybe_const;
1222 : }
1223 :
1224 2242734 : unsigned HOST_WIDE_INT maskl = MAX (mask.length (), MAX (v0n, v1n));
1225 1121317 : unsigned HOST_WIDE_INT pad = (v0n < maskl ? maskl - v0n : 0);
1226 1121317 : vec_perm_builder sel (maskl, maskl, 1);
1227 1121317 : unsigned i;
1228 30433910 : for (i = 0; i < mask.length (); ++i)
1229 : {
1230 14095653 : tree idx = mask[i];
1231 14095653 : if (!tree_fits_shwi_p (idx))
1232 : {
1233 4 : if (complain)
1234 4 : error_at (loc, "invalid element index %qE to "
1235 : "%<__builtin_shufflevector%>", idx);
1236 1121317 : return error_mark_node;
1237 : }
1238 14095649 : HOST_WIDE_INT iidx = tree_to_shwi (idx);
1239 14095649 : if (iidx < -1
1240 14095645 : || (iidx != -1
1241 14095399 : && (unsigned HOST_WIDE_INT) iidx >= v0n + v1n))
1242 : {
1243 11 : if (complain)
1244 11 : error_at (loc, "invalid element index %qE to "
1245 : "%<__builtin_shufflevector%>", idx);
1246 11 : return error_mark_node;
1247 : }
1248 : /* ??? Our VEC_PERM_EXPR does not allow for -1 yet. */
1249 14095638 : if (iidx == -1)
1250 246 : iidx = i;
1251 : /* ??? Our VEC_PERM_EXPR does not allow different sized inputs,
1252 : so pad out a smaller v0. */
1253 14095392 : else if ((unsigned HOST_WIDE_INT) iidx >= v0n)
1254 2715 : iidx += pad;
1255 14095638 : sel.quick_push (iidx);
1256 : }
1257 : /* ??? VEC_PERM_EXPR does not support a result that is smaller than
1258 : the inputs, so we have to pad id out. */
1259 1123372 : for (; i < maskl; ++i)
1260 2070 : sel.quick_push (i);
1261 :
1262 1121302 : vec_perm_indices indices (sel, 2, maskl);
1263 :
1264 1121302 : tree ret_type = build_vector_type (TREE_TYPE (TREE_TYPE (v0)), maskl);
1265 1121302 : tree mask_type = build_vector_type (ssizetype, maskl);
1266 : /* Pad out arguments to the common vector size. */
1267 1121302 : if (v0n < maskl)
1268 : {
1269 182 : constructor_elt elt = { NULL_TREE, build_zero_cst (TREE_TYPE (v0)) };
1270 182 : v0 = build_constructor_single (ret_type, NULL_TREE, v0);
1271 1730 : for (i = 1; i < maskl / v0n; ++i)
1272 1366 : vec_safe_push (CONSTRUCTOR_ELTS (v0), elt);
1273 : }
1274 1121302 : if (v1n < maskl)
1275 : {
1276 161 : constructor_elt elt = { NULL_TREE, build_zero_cst (TREE_TYPE (v1)) };
1277 161 : v1 = build_constructor_single (ret_type, NULL_TREE, v1);
1278 1549 : for (i = 1; i < maskl / v1n; ++i)
1279 1227 : vec_safe_push (CONSTRUCTOR_ELTS (v1), elt);
1280 : }
1281 1121302 : ret = build3_loc (loc, VEC_PERM_EXPR, ret_type, v0, v1,
1282 : vec_perm_indices_to_tree (mask_type, indices));
1283 : /* Get the lowpart we are interested in. */
1284 2242604 : if (mask.length () < maskl)
1285 : {
1286 283 : tree lpartt = build_vector_type (TREE_TYPE (ret_type), mask.length ());
1287 283 : ret = build3_loc (loc, BIT_FIELD_REF,
1288 283 : lpartt, ret, TYPE_SIZE (lpartt), bitsize_zero_node);
1289 : /* Wrap the lowpart operation in a TARGET_EXPR so it gets a separate
1290 : temporary during gimplification. See PR101530 for cases where
1291 : we'd otherwise end up with non-toplevel BIT_FIELD_REFs. */
1292 283 : tree tem = create_tmp_var_raw (lpartt);
1293 283 : DECL_CONTEXT (tem) = current_function_decl;
1294 283 : ret = build4 (TARGET_EXPR, lpartt, tem, ret, NULL_TREE, NULL_TREE);
1295 283 : TREE_SIDE_EFFECTS (ret) = 1;
1296 : }
1297 :
1298 1121302 : if (!c_dialect_cxx () && !wrap)
1299 1079613 : ret = c_wrap_maybe_const (ret, true);
1300 :
1301 1121302 : return ret;
1302 2242619 : }
1303 :
1304 : /* Build a VEC_CONVERT ifn for __builtin_convertvector builtin. */
1305 :
1306 : tree
1307 658 : c_build_vec_convert (location_t loc1, tree expr, location_t loc2, tree type,
1308 : bool complain)
1309 : {
1310 658 : if (error_operand_p (type))
1311 0 : return error_mark_node;
1312 658 : if (error_operand_p (expr))
1313 0 : return error_mark_node;
1314 :
1315 658 : if (!gnu_vector_type_p (TREE_TYPE (expr))
1316 658 : || (!VECTOR_INTEGER_TYPE_P (TREE_TYPE (expr))
1317 173 : && !VECTOR_BOOLEAN_TYPE_P (TREE_TYPE (expr))
1318 173 : && !VECTOR_FLOAT_TYPE_P (TREE_TYPE (expr))))
1319 : {
1320 4 : if (complain)
1321 4 : error_at (loc1, "%<__builtin_convertvector%> first argument must "
1322 : "be an integer or floating vector");
1323 4 : return error_mark_node;
1324 : }
1325 :
1326 654 : if (!gnu_vector_type_p (type)
1327 654 : || (!VECTOR_INTEGER_TYPE_P (type) && !VECTOR_FLOAT_TYPE_P (type)
1328 0 : && !VECTOR_BOOLEAN_TYPE_P (type)))
1329 : {
1330 4 : if (complain)
1331 4 : error_at (loc2, "%<__builtin_convertvector%> second argument must "
1332 : "be an integer or floating vector type");
1333 4 : return error_mark_node;
1334 : }
1335 :
1336 650 : if (maybe_ne (TYPE_VECTOR_SUBPARTS (TREE_TYPE (expr)),
1337 1300 : TYPE_VECTOR_SUBPARTS (type)))
1338 : {
1339 8 : if (complain)
1340 8 : error_at (loc1, "%<__builtin_convertvector%> number of elements "
1341 : "of the first argument vector and the second argument "
1342 : "vector type should be the same");
1343 8 : return error_mark_node;
1344 : }
1345 :
1346 642 : if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (expr)))
1347 642 : == TYPE_MAIN_VARIANT (TREE_TYPE (type)))
1348 642 : || (VECTOR_INTEGER_TYPE_P (TREE_TYPE (expr))
1349 458 : && VECTOR_INTEGER_TYPE_P (type)
1350 299 : && (TYPE_PRECISION (TREE_TYPE (TREE_TYPE (expr)))
1351 299 : == TYPE_PRECISION (TREE_TYPE (type)))))
1352 55 : return build1_loc (loc1, VIEW_CONVERT_EXPR, type, expr);
1353 :
1354 587 : bool wrap = true;
1355 587 : bool maybe_const = false;
1356 587 : tree ret;
1357 587 : if (!c_dialect_cxx ())
1358 : {
1359 : /* Avoid C_MAYBE_CONST_EXPRs inside of VEC_CONVERT argument. */
1360 363 : expr = c_fully_fold (expr, false, &maybe_const);
1361 363 : wrap &= maybe_const;
1362 : }
1363 :
1364 587 : ret = build_call_expr_internal_loc (loc1, IFN_VEC_CONVERT, type, 1, expr);
1365 :
1366 587 : if (!wrap)
1367 363 : ret = c_wrap_maybe_const (ret, true);
1368 :
1369 : return ret;
1370 : }
1371 :
1372 : /* Like tree.cc:get_narrower, but retain conversion from C++0x scoped enum
1373 : to integral type. */
1374 :
1375 : tree
1376 79379577 : c_common_get_narrower (tree op, int *unsignedp_ptr)
1377 : {
1378 79379577 : op = get_narrower (op, unsignedp_ptr);
1379 :
1380 79379577 : if (TREE_CODE (TREE_TYPE (op)) == ENUMERAL_TYPE
1381 79379577 : && ENUM_IS_SCOPED (TREE_TYPE (op)))
1382 : {
1383 : /* C++0x scoped enumerations don't implicitly convert to integral
1384 : type; if we stripped an explicit conversion to a larger type we
1385 : need to replace it so common_type will still work. */
1386 2777365 : tree type = c_common_type_for_size (TYPE_PRECISION (TREE_TYPE (op)),
1387 2777365 : TYPE_UNSIGNED (TREE_TYPE (op)));
1388 2777365 : op = fold_convert (type, op);
1389 : }
1390 79379577 : return op;
1391 : }
1392 :
1393 : /* This is a helper function of build_binary_op.
1394 :
1395 : For certain operations if both args were extended from the same
1396 : smaller type, do the arithmetic in that type and then extend.
1397 :
1398 : BITWISE indicates a bitwise operation.
1399 : For them, this optimization is safe only if
1400 : both args are zero-extended or both are sign-extended.
1401 : Otherwise, we might change the result.
1402 : Eg, (short)-1 | (unsigned short)-1 is (int)-1
1403 : but calculated in (unsigned short) it would be (unsigned short)-1.
1404 : */
1405 : tree
1406 8020264 : shorten_binary_op (tree result_type, tree op0, tree op1, bool bitwise)
1407 : {
1408 8020264 : int unsigned0, unsigned1;
1409 8020264 : tree arg0, arg1;
1410 8020264 : int uns;
1411 8020264 : tree type;
1412 :
1413 : /* Do not shorten vector operations. */
1414 8020264 : if (VECTOR_TYPE_P (result_type))
1415 : return result_type;
1416 :
1417 : /* Cast OP0 and OP1 to RESULT_TYPE. Doing so prevents
1418 : excessive narrowing when we call get_narrower below. For
1419 : example, suppose that OP0 is of unsigned int extended
1420 : from signed char and that RESULT_TYPE is long long int.
1421 : If we explicitly cast OP0 to RESULT_TYPE, OP0 would look
1422 : like
1423 :
1424 : (long long int) (unsigned int) signed_char
1425 :
1426 : which get_narrower would narrow down to
1427 :
1428 : (unsigned int) signed char
1429 :
1430 : If we do not cast OP0 first, get_narrower would return
1431 : signed_char, which is inconsistent with the case of the
1432 : explicit cast. */
1433 7999085 : op0 = convert (result_type, op0);
1434 7999085 : op1 = convert (result_type, op1);
1435 :
1436 7999085 : arg0 = c_common_get_narrower (op0, &unsigned0);
1437 7999085 : arg1 = c_common_get_narrower (op1, &unsigned1);
1438 :
1439 : /* UNS is 1 if the operation to be done is an unsigned one. */
1440 7999085 : uns = TYPE_UNSIGNED (result_type);
1441 :
1442 : /* Handle the case that OP0 (or OP1) does not *contain* a conversion
1443 : but it *requires* conversion to FINAL_TYPE. */
1444 :
1445 7999085 : if ((TYPE_PRECISION (TREE_TYPE (op0))
1446 7999085 : == TYPE_PRECISION (TREE_TYPE (arg0)))
1447 7999085 : && TREE_TYPE (op0) != result_type)
1448 9045 : unsigned0 = TYPE_UNSIGNED (TREE_TYPE (op0));
1449 7999085 : if ((TYPE_PRECISION (TREE_TYPE (op1))
1450 7999085 : == TYPE_PRECISION (TREE_TYPE (arg1)))
1451 7999085 : && TREE_TYPE (op1) != result_type)
1452 344235 : unsigned1 = TYPE_UNSIGNED (TREE_TYPE (op1));
1453 :
1454 : /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
1455 :
1456 : /* For bitwise operations, signedness of nominal type
1457 : does not matter. Consider only how operands were extended. */
1458 7999085 : if (bitwise)
1459 2838689 : uns = unsigned0;
1460 :
1461 : /* Note that in all three cases below we refrain from optimizing
1462 : an unsigned operation on sign-extended args.
1463 : That would not be valid. */
1464 :
1465 : /* Both args variable: if both extended in same way
1466 : from same width, do it in that width.
1467 : Do it unsigned if args were zero-extended. */
1468 7999085 : if ((TYPE_PRECISION (TREE_TYPE (arg0))
1469 7999085 : < TYPE_PRECISION (result_type))
1470 397587 : && (TYPE_PRECISION (TREE_TYPE (arg1))
1471 397587 : == TYPE_PRECISION (TREE_TYPE (arg0)))
1472 317852 : && unsigned0 == unsigned1
1473 8316744 : && (unsigned0 || !uns))
1474 : {
1475 317641 : tree ctype = common_type (TREE_TYPE (arg0), TREE_TYPE (arg1));
1476 317641 : if (ctype != error_mark_node)
1477 317641 : return c_common_signed_or_unsigned_type (unsigned0, ctype);
1478 : }
1479 :
1480 7681444 : else if (TREE_CODE (arg0) == INTEGER_CST
1481 3871674 : && (unsigned1 || !uns)
1482 3510759 : && (TYPE_PRECISION (TREE_TYPE (arg1))
1483 3510759 : < TYPE_PRECISION (result_type))
1484 302 : && (type
1485 302 : = c_common_signed_or_unsigned_type (unsigned1,
1486 302 : TREE_TYPE (arg1)))
1487 302 : && !POINTER_TYPE_P (type)
1488 7681746 : && int_fits_type_p (arg0, type))
1489 : return type;
1490 :
1491 7681195 : else if (TREE_CODE (arg1) == INTEGER_CST
1492 5495878 : && (unsigned0 || !uns)
1493 4544111 : && (TYPE_PRECISION (TREE_TYPE (arg0))
1494 4544111 : < TYPE_PRECISION (result_type))
1495 42194 : && (type
1496 42194 : = c_common_signed_or_unsigned_type (unsigned0,
1497 42194 : TREE_TYPE (arg0)))
1498 42194 : && !POINTER_TYPE_P (type)
1499 7723389 : && int_fits_type_p (arg1, type))
1500 : return type;
1501 :
1502 : return result_type;
1503 : }
1504 :
1505 : /* Returns true iff any integer value of type FROM_TYPE can be represented as
1506 : real of type TO_TYPE. This is a helper function for unsafe_conversion_p. */
1507 :
1508 : static bool
1509 101 : int_safely_convertible_to_real_p (const_tree from_type, const_tree to_type)
1510 : {
1511 101 : tree type_low_bound = TYPE_MIN_VALUE (from_type);
1512 101 : tree type_high_bound = TYPE_MAX_VALUE (from_type);
1513 101 : REAL_VALUE_TYPE real_low_bound =
1514 101 : real_value_from_int_cst (0, type_low_bound);
1515 101 : REAL_VALUE_TYPE real_high_bound =
1516 101 : real_value_from_int_cst (0, type_high_bound);
1517 :
1518 101 : return exact_real_truncate (TYPE_MODE (to_type), &real_low_bound)
1519 101 : && exact_real_truncate (TYPE_MODE (to_type), &real_high_bound);
1520 : }
1521 :
1522 : /* Checks if expression EXPR of complex/real/integer type cannot be converted
1523 : to the complex/real/integer type TYPE. Function returns non-zero when:
1524 : * EXPR is a constant which cannot be exactly converted to TYPE.
1525 : * EXPR is not a constant and size of EXPR's type > than size of TYPE,
1526 : for EXPR type and TYPE being both integers or both real, or both
1527 : complex.
1528 : * EXPR is not a constant of complex type and TYPE is a real or
1529 : an integer.
1530 : * EXPR is not a constant of real type and TYPE is an integer.
1531 : * EXPR is not a constant of integer type which cannot be
1532 : exactly converted to real type.
1533 :
1534 : Function allows conversions between types of different signedness if
1535 : CHECK_SIGN is false and can return SAFE_CONVERSION (zero) in that
1536 : case. Function can return UNSAFE_SIGN if CHECK_SIGN is true.
1537 :
1538 : RESULT, when non-null is the result of the conversion. When constant
1539 : it is included in the text of diagnostics.
1540 :
1541 : Function allows conversions from complex constants to non-complex types,
1542 : provided that imaginary part is zero and real part can be safely converted
1543 : to TYPE. */
1544 :
1545 : enum conversion_safety
1546 10053 : unsafe_conversion_p (tree type, tree expr, tree result, bool check_sign)
1547 : {
1548 10053 : enum conversion_safety give_warning = SAFE_CONVERSION; /* is 0 or false */
1549 10053 : tree expr_type = TREE_TYPE (expr);
1550 :
1551 10053 : expr = fold_for_warn (expr);
1552 :
1553 10053 : if (TREE_CODE (expr) == REAL_CST || TREE_CODE (expr) == INTEGER_CST)
1554 : {
1555 : /* If type is complex, we are interested in compatibility with
1556 : underlying type. */
1557 5801 : if (TREE_CODE (type) == COMPLEX_TYPE)
1558 114 : type = TREE_TYPE (type);
1559 :
1560 : /* Warn for real constant that is not an exact integer converted
1561 : to integer type. */
1562 5801 : if (SCALAR_FLOAT_TYPE_P (expr_type)
1563 685 : && (TREE_CODE (type) == INTEGER_TYPE
1564 685 : || TREE_CODE (type) == BITINT_TYPE))
1565 : {
1566 283 : if (!real_isinteger (TREE_REAL_CST_PTR (expr), TYPE_MODE (expr_type)))
1567 275 : give_warning = UNSAFE_REAL;
1568 : }
1569 : /* Warn for an integer constant that does not fit into integer type. */
1570 5518 : else if ((TREE_CODE (expr_type) == INTEGER_TYPE
1571 5518 : || TREE_CODE (expr_type) == BITINT_TYPE)
1572 5106 : && (TREE_CODE (type) == INTEGER_TYPE
1573 5106 : || TREE_CODE (type) == BITINT_TYPE)
1574 4380 : && !int_fits_type_p (expr, type))
1575 : {
1576 997 : if (TYPE_UNSIGNED (type) && !TYPE_UNSIGNED (expr_type)
1577 963 : && tree_int_cst_sgn (expr) < 0)
1578 : {
1579 265 : if (check_sign)
1580 1834 : give_warning = UNSAFE_SIGN;
1581 : }
1582 432 : else if (!TYPE_UNSIGNED (type) && TYPE_UNSIGNED (expr_type))
1583 : {
1584 335 : if (check_sign)
1585 1834 : give_warning = UNSAFE_SIGN;
1586 : }
1587 : else
1588 : give_warning = UNSAFE_OTHER;
1589 : }
1590 4821 : else if (SCALAR_FLOAT_TYPE_P (type))
1591 : {
1592 : /* Warn for an integer constant that does not fit into real type. */
1593 1038 : if (TREE_CODE (expr_type) == INTEGER_TYPE
1594 : || TREE_CODE (expr_type) == BITINT_TYPE)
1595 : {
1596 636 : REAL_VALUE_TYPE a = real_value_from_int_cst (0, expr);
1597 636 : if (!exact_real_truncate (TYPE_MODE (type), &a))
1598 53 : give_warning = UNSAFE_REAL;
1599 : }
1600 : /* Warn for a real constant that does not fit into a smaller
1601 : real type. */
1602 402 : else if (SCALAR_FLOAT_TYPE_P (expr_type)
1603 402 : && TYPE_PRECISION (type) < TYPE_PRECISION (expr_type))
1604 : {
1605 227 : REAL_VALUE_TYPE a = TREE_REAL_CST (expr);
1606 227 : if (!exact_real_truncate (TYPE_MODE (type), &a))
1607 65 : give_warning = UNSAFE_REAL;
1608 : }
1609 : }
1610 : }
1611 :
1612 4252 : else if (TREE_CODE (expr) == COMPLEX_CST)
1613 : {
1614 69 : tree imag_part = TREE_IMAGPART (expr);
1615 : /* Conversion from complex constant with zero imaginary part,
1616 : perform check for conversion of real part. */
1617 69 : if ((TREE_CODE (imag_part) == REAL_CST
1618 29 : && real_zerop (imag_part))
1619 80 : || (TREE_CODE (imag_part) == INTEGER_CST
1620 40 : && integer_zerop (imag_part)))
1621 : /* Note: in this branch we use recursive call to unsafe_conversion_p
1622 : with different type of EXPR, but it is still safe, because when EXPR
1623 : is a constant, it's type is not used in text of generated warnings
1624 : (otherwise they could sound misleading). */
1625 30 : return unsafe_conversion_p (type, TREE_REALPART (expr), result,
1626 30 : check_sign);
1627 : /* Conversion from complex constant with non-zero imaginary part. */
1628 : else
1629 : {
1630 : /* Conversion to complex type.
1631 : Perform checks for both real and imaginary parts. */
1632 39 : if (TREE_CODE (type) == COMPLEX_TYPE)
1633 : {
1634 33 : enum conversion_safety re_safety =
1635 33 : unsafe_conversion_p (type, TREE_REALPART (expr),
1636 : result, check_sign);
1637 33 : enum conversion_safety im_safety =
1638 33 : unsafe_conversion_p (type, imag_part, result, check_sign);
1639 :
1640 : /* Merge the results into appropriate single warning. */
1641 :
1642 : /* Note: this case includes SAFE_CONVERSION, i.e. success. */
1643 33 : if (re_safety == im_safety)
1644 : give_warning = re_safety;
1645 9 : else if (!re_safety && im_safety)
1646 : give_warning = im_safety;
1647 4 : else if (re_safety && !im_safety)
1648 : give_warning = re_safety;
1649 : else
1650 670 : give_warning = UNSAFE_OTHER;
1651 : }
1652 : /* Warn about conversion from complex to real or integer type. */
1653 : else
1654 : give_warning = UNSAFE_IMAGINARY;
1655 : }
1656 : }
1657 :
1658 : /* Checks for remaining case: EXPR is not constant. */
1659 : else
1660 : {
1661 : /* Warn for real types converted to integer types. */
1662 4183 : if (SCALAR_FLOAT_TYPE_P (expr_type)
1663 244 : && (TREE_CODE (type) == INTEGER_TYPE
1664 244 : || TREE_CODE (type) == BITINT_TYPE))
1665 : give_warning = UNSAFE_REAL;
1666 :
1667 4154 : else if ((TREE_CODE (expr_type) == INTEGER_TYPE
1668 4154 : || TREE_CODE (expr_type) == BITINT_TYPE)
1669 3728 : && (TREE_CODE (type) == INTEGER_TYPE
1670 3728 : || TREE_CODE (type) == BITINT_TYPE))
1671 : {
1672 : /* Don't warn about unsigned char y = 0xff, x = (int) y; */
1673 3507 : expr = get_unwidened (expr, 0);
1674 3507 : expr_type = TREE_TYPE (expr);
1675 :
1676 : /* Don't warn for short y; short x = ((int)y & 0xff); */
1677 3507 : if (TREE_CODE (expr) == BIT_AND_EXPR
1678 3493 : || TREE_CODE (expr) == BIT_IOR_EXPR
1679 3452 : || TREE_CODE (expr) == BIT_XOR_EXPR)
1680 : {
1681 : /* If both args were extended from a shortest type,
1682 : use that type if that is safe. */
1683 59 : expr_type = shorten_binary_op (expr_type,
1684 59 : TREE_OPERAND (expr, 0),
1685 59 : TREE_OPERAND (expr, 1),
1686 : /* bitwise */1);
1687 :
1688 59 : if (TREE_CODE (expr) == BIT_AND_EXPR)
1689 : {
1690 14 : tree op0 = TREE_OPERAND (expr, 0);
1691 14 : tree op1 = TREE_OPERAND (expr, 1);
1692 14 : bool unsigned0 = TYPE_UNSIGNED (TREE_TYPE (op0));
1693 14 : bool unsigned1 = TYPE_UNSIGNED (TREE_TYPE (op1));
1694 :
1695 : /* If one of the operands is a non-negative constant
1696 : that fits in the target type, then the type of the
1697 : other operand does not matter. */
1698 14 : if ((TREE_CODE (op0) == INTEGER_CST
1699 0 : && int_fits_type_p (op0, c_common_signed_type (type))
1700 0 : && int_fits_type_p (op0, c_common_unsigned_type (type)))
1701 14 : || (TREE_CODE (op1) == INTEGER_CST
1702 1 : && int_fits_type_p (op1, c_common_signed_type (type))
1703 1 : && int_fits_type_p (op1,
1704 1 : c_common_unsigned_type (type))))
1705 1 : return SAFE_CONVERSION;
1706 : /* If constant is unsigned and fits in the target
1707 : type, then the result will also fit. */
1708 13 : else if ((TREE_CODE (op0) == INTEGER_CST
1709 0 : && unsigned0
1710 0 : && int_fits_type_p (op0, type))
1711 13 : || (TREE_CODE (op1) == INTEGER_CST
1712 0 : && unsigned1
1713 0 : && int_fits_type_p (op1, type)))
1714 : return SAFE_CONVERSION;
1715 : }
1716 : }
1717 : /* Warn for integer types converted to smaller integer types. */
1718 3506 : if (TYPE_PRECISION (type) < TYPE_PRECISION (expr_type))
1719 : give_warning = UNSAFE_OTHER;
1720 :
1721 : /* When they are the same width but different signedness,
1722 : then the value may change. */
1723 2970 : else if (((TYPE_PRECISION (type) == TYPE_PRECISION (expr_type)
1724 2414 : && TYPE_UNSIGNED (expr_type) != TYPE_UNSIGNED (type))
1725 : /* Even when converted to a bigger type, if the type is
1726 : unsigned but expr is signed, then negative values
1727 : will be changed. */
1728 1707 : || (TYPE_UNSIGNED (type) && !TYPE_UNSIGNED (expr_type)))
1729 4289 : && check_sign)
1730 : give_warning = UNSAFE_SIGN;
1731 : }
1732 :
1733 : /* Warn for integer types converted to real types if and only if
1734 : all the range of values of the integer type cannot be
1735 : represented by the real type. */
1736 647 : else if ((TREE_CODE (expr_type) == INTEGER_TYPE
1737 : || TREE_CODE (expr_type) == BITINT_TYPE)
1738 221 : && SCALAR_FLOAT_TYPE_P (type))
1739 : {
1740 : /* Don't warn about char y = 0xff; float x = (int) y; */
1741 101 : expr = get_unwidened (expr, 0);
1742 101 : expr_type = TREE_TYPE (expr);
1743 :
1744 101 : if (!int_safely_convertible_to_real_p (expr_type, type))
1745 670 : give_warning = UNSAFE_OTHER;
1746 : }
1747 :
1748 : /* Warn for real types converted to smaller real types. */
1749 546 : else if (SCALAR_FLOAT_TYPE_P (expr_type)
1750 215 : && SCALAR_FLOAT_TYPE_P (type)
1751 761 : && TYPE_PRECISION (type) < TYPE_PRECISION (expr_type))
1752 : give_warning = UNSAFE_REAL;
1753 :
1754 : /* Check conversion between two complex types. */
1755 494 : else if (TREE_CODE (expr_type) == COMPLEX_TYPE
1756 32 : && TREE_CODE (type) == COMPLEX_TYPE)
1757 : {
1758 : /* Extract underlying types (i.e., type of real and imaginary
1759 : parts) of expr_type and type. */
1760 10 : tree from_type = TREE_TYPE (expr_type);
1761 10 : tree to_type = TREE_TYPE (type);
1762 :
1763 : /* Warn for real types converted to integer types. */
1764 10 : if (SCALAR_FLOAT_TYPE_P (from_type)
1765 8 : && TREE_CODE (to_type) == INTEGER_TYPE)
1766 : give_warning = UNSAFE_REAL;
1767 :
1768 : /* Warn for real types converted to smaller real types. */
1769 6 : else if (SCALAR_FLOAT_TYPE_P (from_type)
1770 4 : && SCALAR_FLOAT_TYPE_P (to_type)
1771 10 : && TYPE_PRECISION (to_type) < TYPE_PRECISION (from_type))
1772 : give_warning = UNSAFE_REAL;
1773 :
1774 : /* Check conversion for complex integer types. Here implementation
1775 : is simpler than for real-domain integers because it does not
1776 : involve sophisticated cases, such as bitmasks, casts, etc. */
1777 4 : else if (TREE_CODE (from_type) == INTEGER_TYPE
1778 2 : && TREE_CODE (to_type) == INTEGER_TYPE)
1779 : {
1780 : /* Warn for integer types converted to smaller integer types. */
1781 2 : if (TYPE_PRECISION (to_type) < TYPE_PRECISION (from_type))
1782 : give_warning = UNSAFE_OTHER;
1783 :
1784 : /* Check for different signedness, see case for real-domain
1785 : integers (above) for a more detailed comment. */
1786 0 : else if (((TYPE_PRECISION (to_type) == TYPE_PRECISION (from_type)
1787 0 : && TYPE_UNSIGNED (to_type) != TYPE_UNSIGNED (from_type))
1788 0 : || (TYPE_UNSIGNED (to_type) && !TYPE_UNSIGNED (from_type)))
1789 0 : && check_sign)
1790 : give_warning = UNSAFE_SIGN;
1791 : }
1792 2 : else if (TREE_CODE (from_type) == INTEGER_TYPE
1793 0 : && SCALAR_FLOAT_TYPE_P (to_type)
1794 2 : && !int_safely_convertible_to_real_p (from_type, to_type))
1795 : give_warning = UNSAFE_OTHER;
1796 : }
1797 :
1798 : /* Warn for complex types converted to real or integer types. */
1799 484 : else if (TREE_CODE (expr_type) == COMPLEX_TYPE
1800 22 : && TREE_CODE (type) != COMPLEX_TYPE)
1801 28 : give_warning = UNSAFE_IMAGINARY;
1802 : }
1803 :
1804 : return give_warning;
1805 : }
1806 :
1807 :
1808 : /* Convert EXPR to TYPE, warning about conversion problems with constants.
1809 : Invoke this function on every expression that is converted implicitly,
1810 : i.e. because of language rules and not because of an explicit cast.
1811 : INIT_CONST is true if the conversion is for arithmetic types for a static
1812 : initializer and folding must apply accordingly (discarding floating-point
1813 : exceptions and assuming the default rounding mode is in effect). */
1814 :
1815 : tree
1816 12069126 : convert_and_check (location_t loc, tree type, tree expr, bool init_const)
1817 : {
1818 12069126 : tree result;
1819 12069126 : tree expr_for_warning;
1820 :
1821 : /* Convert from a value with possible excess precision rather than
1822 : via the semantic type, but do not warn about values not fitting
1823 : exactly in the semantic type. */
1824 12069126 : if (TREE_CODE (expr) == EXCESS_PRECISION_EXPR)
1825 : {
1826 5985 : tree orig_type = TREE_TYPE (expr);
1827 5985 : expr = TREE_OPERAND (expr, 0);
1828 5985 : expr_for_warning = (init_const
1829 5985 : ? convert_init (orig_type, expr)
1830 5624 : : convert (orig_type, expr));
1831 5985 : if (orig_type == type)
1832 : return expr_for_warning;
1833 : }
1834 : else
1835 : expr_for_warning = expr;
1836 :
1837 12063634 : if (TREE_TYPE (expr) == type)
1838 : return expr;
1839 :
1840 10868466 : result = init_const ? convert_init (type, expr) : convert (type, expr);
1841 :
1842 10868466 : if (c_inhibit_evaluation_warnings == 0
1843 10540101 : && !TREE_OVERFLOW_P (expr)
1844 10540075 : && result != error_mark_node
1845 21408387 : && !c_hardbool_type_attr (type))
1846 10532574 : warnings_for_convert_and_check (loc, type, expr_for_warning, result);
1847 :
1848 : return result;
1849 : }
1850 :
1851 : /* A node in a list that describes references to variables (EXPR), which are
1852 : either read accesses if WRITER is zero, or write accesses, in which case
1853 : WRITER is the parent of EXPR. */
1854 : struct tlist
1855 : {
1856 : struct tlist *next;
1857 : tree expr, writer;
1858 : };
1859 :
1860 : /* Used to implement a cache the results of a call to verify_tree. We only
1861 : use this for SAVE_EXPRs. */
1862 : struct tlist_cache
1863 : {
1864 : struct tlist_cache *next;
1865 : struct tlist *cache_before_sp;
1866 : struct tlist *cache_after_sp;
1867 : tree expr;
1868 : };
1869 :
1870 : /* Obstack to use when allocating tlist structures, and corresponding
1871 : firstobj. */
1872 : static struct obstack tlist_obstack;
1873 : static char *tlist_firstobj = 0;
1874 :
1875 : /* Keep track of the identifiers we've warned about, so we can avoid duplicate
1876 : warnings. */
1877 : static struct tlist *warned_ids;
1878 : /* SAVE_EXPRs need special treatment. We process them only once and then
1879 : cache the results. */
1880 : static struct tlist_cache *save_expr_cache;
1881 :
1882 : static void add_tlist (struct tlist **, struct tlist *, tree, int);
1883 : static void merge_tlist (struct tlist **, struct tlist *, int);
1884 : static void verify_tree (tree, struct tlist **, struct tlist **, tree);
1885 : static bool warning_candidate_p (tree);
1886 : static bool candidate_equal_p (const_tree, const_tree);
1887 : static void warn_for_collisions (struct tlist *);
1888 : static void warn_for_collisions_1 (tree, tree, struct tlist *, int);
1889 : static struct tlist *new_tlist (struct tlist *, tree, tree);
1890 :
1891 : /* Create a new struct tlist and fill in its fields. */
1892 : static struct tlist *
1893 34633583 : new_tlist (struct tlist *next, tree t, tree writer)
1894 : {
1895 34633583 : struct tlist *l;
1896 34633583 : l = XOBNEW (&tlist_obstack, struct tlist);
1897 34633583 : l->next = next;
1898 34633583 : l->expr = t;
1899 34633583 : l->writer = writer;
1900 34633583 : return l;
1901 : }
1902 :
1903 : /* Add duplicates of the nodes found in ADD to the list *TO. If EXCLUDE_WRITER
1904 : is nonnull, we ignore any node we find which has a writer equal to it. */
1905 :
1906 : static void
1907 61130138 : add_tlist (struct tlist **to, struct tlist *add, tree exclude_writer, int copy)
1908 : {
1909 132890213 : while (add)
1910 : {
1911 71760075 : struct tlist *next = add->next;
1912 13195682 : if (!copy)
1913 1892729 : add->next = *to;
1914 13195682 : if (!exclude_writer || !candidate_equal_p (add->writer, exclude_writer))
1915 69727907 : *to = copy ? new_tlist (*to, add->expr, add->writer) : add;
1916 : add = next;
1917 : }
1918 11859245 : }
1919 :
1920 : /* Merge the nodes of ADD into TO. This merging process is done so that for
1921 : each variable that already exists in TO, no new node is added; however if
1922 : there is a write access recorded in ADD, and an occurrence on TO is only
1923 : a read access, then the occurrence in TO will be modified to record the
1924 : write. */
1925 :
1926 : static void
1927 42785315 : merge_tlist (struct tlist **to, struct tlist *add, int copy)
1928 : {
1929 42785315 : struct tlist **end = to;
1930 :
1931 79821695 : while (*end)
1932 37036380 : end = &(*end)->next;
1933 :
1934 58754791 : while (add)
1935 : {
1936 15969476 : int found = 0;
1937 15969476 : struct tlist *tmp2;
1938 15969476 : struct tlist *next = add->next;
1939 :
1940 43505837 : for (tmp2 = *to; tmp2; tmp2 = tmp2->next)
1941 27536361 : if (candidate_equal_p (tmp2->expr, add->expr))
1942 : {
1943 2745180 : found = 1;
1944 2745180 : if (!tmp2->writer)
1945 2738526 : tmp2->writer = add->writer;
1946 : }
1947 15969476 : if (!found)
1948 : {
1949 13238307 : *end = copy ? new_tlist (NULL, add->expr, add->writer) : add;
1950 13238307 : end = &(*end)->next;
1951 13238307 : *end = 0;
1952 : }
1953 : add = next;
1954 : }
1955 42785315 : }
1956 :
1957 : /* WRITTEN is a variable, WRITER is its parent. Warn if any of the variable
1958 : references in list LIST conflict with it, excluding reads if ONLY writers
1959 : is nonzero. */
1960 :
1961 : static void
1962 5265760 : warn_for_collisions_1 (tree written, tree writer, struct tlist *list,
1963 : int only_writes)
1964 : {
1965 5265760 : struct tlist *tmp;
1966 :
1967 : /* Avoid duplicate warnings. */
1968 5265923 : for (tmp = warned_ids; tmp; tmp = tmp->next)
1969 611 : if (candidate_equal_p (tmp->expr, written))
1970 : return;
1971 :
1972 18925665 : while (list)
1973 : {
1974 13660353 : if (candidate_equal_p (list->expr, written)
1975 1555037 : && !candidate_equal_p (list->writer, writer)
1976 13802228 : && (!only_writes || list->writer))
1977 : {
1978 562 : warned_ids = new_tlist (warned_ids, written, NULL_TREE);
1979 562 : warning_at (EXPR_LOC_OR_LOC (writer, input_location),
1980 562 : OPT_Wsequence_point, "operation on %qE may be undefined",
1981 : list->expr);
1982 : }
1983 13660353 : list = list->next;
1984 : }
1985 : }
1986 :
1987 : /* Given a list LIST of references to variables, find whether any of these
1988 : can cause conflicts due to missing sequence points. */
1989 :
1990 : static void
1991 20138350 : warn_for_collisions (struct tlist *list)
1992 : {
1993 20138350 : struct tlist *tmp;
1994 :
1995 55483534 : for (tmp = list; tmp; tmp = tmp->next)
1996 : {
1997 35345184 : if (tmp->writer)
1998 1345675 : warn_for_collisions_1 (tmp->expr, tmp->writer, list, 0);
1999 : }
2000 20138350 : }
2001 :
2002 : /* Return nonzero if X is a tree that can be verified by the sequence point
2003 : warnings. */
2004 :
2005 : static bool
2006 77227462 : warning_candidate_p (tree x)
2007 : {
2008 77227462 : if (DECL_P (x) && DECL_ARTIFICIAL (x))
2009 : return false;
2010 :
2011 69489558 : if (TREE_CODE (x) == BLOCK)
2012 : return false;
2013 :
2014 : /* VOID_TYPE_P (TREE_TYPE (x)) is workaround for cp/tree.cc
2015 : (lvalue_p) crash on TRY/CATCH. */
2016 69487385 : if (TREE_TYPE (x) == NULL_TREE || VOID_TYPE_P (TREE_TYPE (x)))
2017 : return false;
2018 :
2019 68566594 : if (!lvalue_p (x))
2020 : return false;
2021 :
2022 : /* No point to track non-const calls, they will never satisfy
2023 : operand_equal_p. */
2024 24682714 : if (TREE_CODE (x) == CALL_EXPR && (call_expr_flags (x) & ECF_CONST) == 0)
2025 : return false;
2026 :
2027 24637207 : if (TREE_CODE (x) == STRING_CST)
2028 : return false;
2029 :
2030 : return true;
2031 : }
2032 :
2033 : /* Return nonzero if X and Y appear to be the same candidate (or NULL) */
2034 : static bool
2035 46591902 : candidate_equal_p (const_tree x, const_tree y)
2036 : {
2037 46591902 : return (x == y) || (x && y && operand_equal_p (x, y, 0));
2038 : }
2039 :
2040 : /* Walk the tree X, and record accesses to variables. If X is written by the
2041 : parent tree, WRITER is the parent.
2042 : We store accesses in one of the two lists: PBEFORE_SP, and PNO_SP. If this
2043 : expression or its only operand forces a sequence point, then everything up
2044 : to the sequence point is stored in PBEFORE_SP. Everything else gets stored
2045 : in PNO_SP.
2046 : Once we return, we will have emitted warnings if any subexpression before
2047 : such a sequence point could be undefined. On a higher level, however, the
2048 : sequence point may not be relevant, and we'll merge the two lists.
2049 :
2050 : Example: (b++, a) + b;
2051 : The call that processes the COMPOUND_EXPR will store the increment of B
2052 : in PBEFORE_SP, and the use of A in PNO_SP. The higher-level call that
2053 : processes the PLUS_EXPR will need to merge the two lists so that
2054 : eventually, all accesses end up on the same list (and we'll warn about the
2055 : unordered subexpressions b++ and b.
2056 :
2057 : A note on merging. If we modify the former example so that our expression
2058 : becomes
2059 : (b++, b) + a
2060 : care must be taken not simply to add all three expressions into the final
2061 : PNO_SP list. The function merge_tlist takes care of that by merging the
2062 : before-SP list of the COMPOUND_EXPR into its after-SP list in a special
2063 : way, so that no more than one access to B is recorded. */
2064 :
2065 : static void
2066 60614537 : verify_tree (tree x, struct tlist **pbefore_sp, struct tlist **pno_sp,
2067 : tree writer)
2068 : {
2069 74531193 : struct tlist *tmp_before, *tmp_nosp, *tmp_list2, *tmp_list3;
2070 74531193 : enum tree_code code;
2071 74531193 : enum tree_code_class cl;
2072 :
2073 74531193 : restart:
2074 : /* X may be NULL if it is the operand of an empty statement expression
2075 : ({ }). */
2076 74531193 : if (x == NULL)
2077 : return;
2078 :
2079 73307377 : code = TREE_CODE (x);
2080 73307377 : cl = TREE_CODE_CLASS (code);
2081 :
2082 73307377 : if (warning_candidate_p (x))
2083 23390551 : *pno_sp = new_tlist (*pno_sp, x, writer);
2084 :
2085 73307377 : switch (code)
2086 : {
2087 : case CONSTRUCTOR:
2088 : case SIZEOF_EXPR:
2089 : case PAREN_SIZEOF_EXPR:
2090 : return;
2091 :
2092 216189 : case COMPOUND_EXPR:
2093 216189 : case TRUTH_ANDIF_EXPR:
2094 216189 : case TRUTH_ORIF_EXPR:
2095 216189 : sequenced_binary:
2096 216189 : tmp_before = tmp_nosp = tmp_list2 = tmp_list3 = 0;
2097 216189 : verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_nosp, NULL_TREE);
2098 216189 : warn_for_collisions (tmp_nosp);
2099 216189 : merge_tlist (pbefore_sp, tmp_before, 0);
2100 216189 : merge_tlist (pbefore_sp, tmp_nosp, 0);
2101 216189 : verify_tree (TREE_OPERAND (x, 1), &tmp_list3, &tmp_list2, NULL_TREE);
2102 216189 : warn_for_collisions (tmp_list2);
2103 216189 : merge_tlist (pbefore_sp, tmp_list3, 0);
2104 216189 : merge_tlist (pno_sp, tmp_list2, 0);
2105 216189 : return;
2106 :
2107 69531 : case COND_EXPR:
2108 69531 : tmp_before = tmp_list2 = 0;
2109 69531 : verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_list2, NULL_TREE);
2110 69531 : warn_for_collisions (tmp_list2);
2111 69531 : merge_tlist (pbefore_sp, tmp_before, 0);
2112 69531 : merge_tlist (pbefore_sp, tmp_list2, 0);
2113 :
2114 69531 : tmp_list3 = tmp_nosp = 0;
2115 69531 : verify_tree (TREE_OPERAND (x, 1), &tmp_list3, &tmp_nosp, NULL_TREE);
2116 69531 : warn_for_collisions (tmp_nosp);
2117 69531 : merge_tlist (pbefore_sp, tmp_list3, 0);
2118 :
2119 69531 : tmp_list3 = tmp_list2 = 0;
2120 69531 : verify_tree (TREE_OPERAND (x, 2), &tmp_list3, &tmp_list2, NULL_TREE);
2121 69531 : warn_for_collisions (tmp_list2);
2122 69531 : merge_tlist (pbefore_sp, tmp_list3, 0);
2123 : /* Rather than add both tmp_nosp and tmp_list2, we have to merge the
2124 : two first, to avoid warning for (a ? b++ : b++). */
2125 69531 : merge_tlist (&tmp_nosp, tmp_list2, 0);
2126 69531 : add_tlist (pno_sp, tmp_nosp, NULL_TREE, 0);
2127 : return;
2128 :
2129 269666 : case PREDECREMENT_EXPR:
2130 269666 : case PREINCREMENT_EXPR:
2131 269666 : case POSTDECREMENT_EXPR:
2132 269666 : case POSTINCREMENT_EXPR:
2133 269666 : verify_tree (TREE_OPERAND (x, 0), pno_sp, pno_sp, x);
2134 269666 : return;
2135 :
2136 3920085 : case MODIFY_EXPR:
2137 3920085 : tmp_before = tmp_nosp = tmp_list3 = 0;
2138 3920085 : verify_tree (TREE_OPERAND (x, 1), &tmp_before, &tmp_nosp, NULL_TREE);
2139 3920085 : verify_tree (TREE_OPERAND (x, 0), &tmp_list3, &tmp_list3, x);
2140 : /* Expressions inside the LHS are not ordered wrt. the sequence points
2141 : in the RHS. Example:
2142 : *a = (a++, 2)
2143 : Despite the fact that the modification of "a" is in the before_sp
2144 : list (tmp_before), it conflicts with the use of "a" in the LHS.
2145 : We can handle this by adding the contents of tmp_list3
2146 : to those of tmp_before, and redoing the collision warnings for that
2147 : list. */
2148 3920085 : add_tlist (&tmp_before, tmp_list3, x, 1);
2149 3920085 : warn_for_collisions (tmp_before);
2150 : /* Exclude the LHS itself here; we first have to merge it into the
2151 : tmp_nosp list. This is done to avoid warning for "a = a"; if we
2152 : didn't exclude the LHS, we'd get it twice, once as a read and once
2153 : as a write. */
2154 3920085 : add_tlist (pno_sp, tmp_list3, x, 0);
2155 3920085 : warn_for_collisions_1 (TREE_OPERAND (x, 0), x, tmp_nosp, 1);
2156 :
2157 3920085 : merge_tlist (pbefore_sp, tmp_before, 0);
2158 3920085 : if (warning_candidate_p (TREE_OPERAND (x, 0)))
2159 948968 : merge_tlist (&tmp_nosp, new_tlist (NULL, TREE_OPERAND (x, 0), x), 0);
2160 3920085 : add_tlist (pno_sp, tmp_nosp, NULL_TREE, 1);
2161 3920085 : return;
2162 :
2163 6322630 : case CALL_EXPR:
2164 : /* We need to warn about conflicts among arguments and conflicts between
2165 : args and the function address. Side effects of the function address,
2166 : however, are not ordered by the sequence point of the call. */
2167 6322630 : {
2168 6322630 : call_expr_arg_iterator iter;
2169 6322630 : tree arg;
2170 6322630 : tmp_before = tmp_nosp = 0;
2171 6322630 : verify_tree (CALL_EXPR_FN (x), &tmp_before, &tmp_nosp, NULL_TREE);
2172 28015903 : FOR_EACH_CALL_EXPR_ARG (arg, iter, x)
2173 : {
2174 15370643 : tmp_list2 = tmp_list3 = 0;
2175 15370643 : verify_tree (arg, &tmp_list2, &tmp_list3, NULL_TREE);
2176 15370643 : merge_tlist (&tmp_list3, tmp_list2, 0);
2177 30741286 : add_tlist (&tmp_before, tmp_list3, NULL_TREE, 0);
2178 : }
2179 6322630 : add_tlist (&tmp_before, tmp_nosp, NULL_TREE, 0);
2180 6322630 : warn_for_collisions (tmp_before);
2181 6322630 : add_tlist (pbefore_sp, tmp_before, NULL_TREE, 0);
2182 6322630 : return;
2183 : }
2184 :
2185 : case TREE_LIST:
2186 : /* Scan all the list, e.g. indices of multi dimensional array. */
2187 6 : while (x)
2188 : {
2189 3 : tmp_before = tmp_nosp = 0;
2190 3 : verify_tree (TREE_VALUE (x), &tmp_before, &tmp_nosp, NULL_TREE);
2191 3 : merge_tlist (&tmp_nosp, tmp_before, 0);
2192 3 : add_tlist (pno_sp, tmp_nosp, NULL_TREE, 0);
2193 3 : x = TREE_CHAIN (x);
2194 : }
2195 : return;
2196 :
2197 98990 : case SAVE_EXPR:
2198 98990 : {
2199 98990 : struct tlist_cache *t;
2200 102841 : for (t = save_expr_cache; t; t = t->next)
2201 54082 : if (candidate_equal_p (t->expr, x))
2202 : break;
2203 :
2204 98990 : if (!t)
2205 : {
2206 48759 : t = XOBNEW (&tlist_obstack, struct tlist_cache);
2207 48759 : t->next = save_expr_cache;
2208 48759 : t->expr = x;
2209 48759 : save_expr_cache = t;
2210 :
2211 48759 : tmp_before = tmp_nosp = 0;
2212 48759 : verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_nosp, NULL_TREE);
2213 48759 : warn_for_collisions (tmp_nosp);
2214 :
2215 48759 : tmp_list3 = 0;
2216 48759 : merge_tlist (&tmp_list3, tmp_nosp, 0);
2217 48759 : t->cache_before_sp = tmp_before;
2218 48759 : t->cache_after_sp = tmp_list3;
2219 : }
2220 98990 : merge_tlist (pbefore_sp, t->cache_before_sp, 1);
2221 98990 : add_tlist (pno_sp, t->cache_after_sp, NULL_TREE, 1);
2222 98990 : return;
2223 : }
2224 :
2225 7206413 : case ADDR_EXPR:
2226 7206413 : x = TREE_OPERAND (x, 0);
2227 7206413 : if (DECL_P (x))
2228 : return;
2229 515626 : writer = 0;
2230 515626 : goto restart;
2231 :
2232 12101595 : case VIEW_CONVERT_EXPR:
2233 12101595 : if (location_wrapper_p (x))
2234 : {
2235 3054304 : x = TREE_OPERAND (x, 0);
2236 3054304 : goto restart;
2237 : }
2238 9047291 : goto do_default;
2239 :
2240 628241 : case LSHIFT_EXPR:
2241 628241 : case RSHIFT_EXPR:
2242 628241 : case ARRAY_REF:
2243 628241 : if (cxx_dialect >= cxx17)
2244 51523 : goto sequenced_binary;
2245 576718 : goto do_default;
2246 :
2247 1319727 : case COMPONENT_REF:
2248 : /* Treat as unary, the other operands aren't evaluated. */
2249 1319727 : x = TREE_OPERAND (x, 0);
2250 1319727 : writer = 0;
2251 1319727 : goto restart;
2252 :
2253 50389424 : default:
2254 50389424 : do_default:
2255 : /* For other expressions, simply recurse on their operands.
2256 : Manual tail recursion for unary expressions.
2257 : Other non-expressions need not be processed. */
2258 50389424 : if (cl == tcc_unary)
2259 : {
2260 8757333 : x = TREE_OPERAND (x, 0);
2261 8757333 : writer = 0;
2262 8757333 : goto restart;
2263 : }
2264 41632091 : else if (IS_EXPR_CODE_CLASS (cl))
2265 : {
2266 15156549 : int lp;
2267 15156549 : int max = TREE_OPERAND_LENGTH (x);
2268 51498554 : for (lp = 0; lp < max; lp++)
2269 : {
2270 21185456 : tmp_before = tmp_nosp = 0;
2271 21185456 : verify_tree (TREE_OPERAND (x, lp), &tmp_before, &tmp_nosp, 0);
2272 21185456 : merge_tlist (&tmp_nosp, tmp_before, 0);
2273 42370912 : add_tlist (pno_sp, tmp_nosp, NULL_TREE, 0);
2274 : }
2275 : }
2276 : return;
2277 : }
2278 : }
2279 :
2280 : static constexpr size_t verify_sequence_points_limit = 1024;
2281 :
2282 : /* Called from verify_sequence_points via walk_tree. */
2283 :
2284 : static tree
2285 90747270 : verify_tree_lim_r (tree *tp, int *walk_subtrees, void *data)
2286 : {
2287 90747270 : if (++*((size_t *) data) > verify_sequence_points_limit)
2288 57 : return integer_zero_node;
2289 :
2290 90747213 : if (TYPE_P (*tp))
2291 7386 : *walk_subtrees = 0;
2292 :
2293 : return NULL_TREE;
2294 : }
2295 :
2296 : /* Try to warn for undefined behavior in EXPR due to missing sequence
2297 : points. */
2298 :
2299 : void
2300 9205962 : verify_sequence_points (tree expr)
2301 : {
2302 9205962 : tlist *before_sp = nullptr, *after_sp = nullptr;
2303 :
2304 : /* verify_tree is highly recursive, and merge_tlist is O(n^2),
2305 : so we return early if the expression is too big. */
2306 9205962 : size_t n = 0;
2307 9205962 : if (walk_tree (&expr, verify_tree_lim_r, &n, nullptr))
2308 57 : return;
2309 :
2310 9205905 : warned_ids = nullptr;
2311 9205905 : save_expr_cache = nullptr;
2312 9205905 : if (!tlist_firstobj)
2313 : {
2314 9957 : gcc_obstack_init (&tlist_obstack);
2315 9957 : tlist_firstobj = (char *) obstack_alloc (&tlist_obstack, 0);
2316 : }
2317 :
2318 9205905 : verify_tree (expr, &before_sp, &after_sp, NULL_TREE);
2319 9205905 : warn_for_collisions (after_sp);
2320 9205905 : obstack_free (&tlist_obstack, tlist_firstobj);
2321 : }
2322 :
2323 : /* Validate the expression after `case' and apply default promotions. */
2324 :
2325 : static tree
2326 2226399 : check_case_value (location_t loc, tree value)
2327 : {
2328 2226399 : if (value == NULL_TREE)
2329 : return value;
2330 :
2331 4028109 : if (INTEGRAL_TYPE_P (TREE_TYPE (value))
2332 4028006 : && TREE_CODE (value) == INTEGER_CST)
2333 : /* Promote char or short to int. */
2334 2226248 : value = perform_integral_promotions (value);
2335 151 : else if (value != error_mark_node)
2336 : {
2337 53 : error_at (loc, "case label does not reduce to an integer constant");
2338 53 : value = error_mark_node;
2339 : }
2340 :
2341 2226399 : constant_expression_warning (value);
2342 :
2343 2226399 : return value;
2344 : }
2345 :
2346 : /* Return an integer type with BITS bits of precision,
2347 : that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
2348 :
2349 : tree
2350 31255042 : c_common_type_for_size (unsigned int bits, int unsignedp)
2351 : {
2352 31255042 : int i;
2353 :
2354 31255042 : if (bits == TYPE_PRECISION (integer_type_node))
2355 20637959 : return unsignedp ? unsigned_type_node : integer_type_node;
2356 :
2357 10617083 : if (bits == TYPE_PRECISION (signed_char_type_node))
2358 2743470 : return unsignedp ? unsigned_char_type_node : signed_char_type_node;
2359 :
2360 7873613 : if (bits == TYPE_PRECISION (short_integer_type_node))
2361 472701 : return unsignedp ? short_unsigned_type_node : short_integer_type_node;
2362 :
2363 7400912 : if (bits == TYPE_PRECISION (long_integer_type_node))
2364 6571084 : return unsignedp ? long_unsigned_type_node : long_integer_type_node;
2365 :
2366 829828 : if (bits == TYPE_PRECISION (long_long_integer_type_node))
2367 9641 : return (unsignedp ? long_long_unsigned_type_node
2368 8876 : : long_long_integer_type_node);
2369 :
2370 1129522 : for (i = 0; i < NUM_INT_N_ENTS; i ++)
2371 820187 : if (int_n_enabled_p[i]
2372 813259 : && bits == int_n_data[i].bitsize)
2373 510852 : return (unsignedp ? int_n_trees[i].unsigned_type
2374 510852 : : int_n_trees[i].signed_type);
2375 :
2376 309335 : if (bits == TYPE_PRECISION (widest_integer_literal_type_node))
2377 0 : return (unsignedp ? widest_unsigned_literal_type_node
2378 0 : : widest_integer_literal_type_node);
2379 :
2380 1221200 : for (tree t = registered_builtin_types; t; t = TREE_CHAIN (t))
2381 : {
2382 911865 : tree type = TREE_VALUE (t);
2383 911865 : if (TREE_CODE (type) == INTEGER_TYPE
2384 0 : && bits == TYPE_PRECISION (type)
2385 911865 : && !!unsignedp == !!TYPE_UNSIGNED (type))
2386 : return type;
2387 : }
2388 :
2389 309335 : if (bits <= TYPE_PRECISION (intQI_type_node))
2390 246127 : return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
2391 :
2392 63208 : if (bits <= TYPE_PRECISION (intHI_type_node))
2393 9669 : return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
2394 :
2395 53539 : if (bits <= TYPE_PRECISION (intSI_type_node))
2396 19156 : return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
2397 :
2398 34383 : if (bits <= TYPE_PRECISION (intDI_type_node))
2399 28237 : return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
2400 :
2401 6146 : if (bits <= TYPE_PRECISION (widest_integer_literal_type_node))
2402 31 : return (unsignedp ? widest_unsigned_literal_type_node
2403 14 : : widest_integer_literal_type_node);
2404 :
2405 : return NULL_TREE;
2406 : }
2407 :
2408 : /* Return a fixed-point type that has at least IBIT ibits and FBIT fbits
2409 : that is unsigned if UNSIGNEDP is nonzero, otherwise signed;
2410 : and saturating if SATP is nonzero, otherwise not saturating. */
2411 :
2412 : tree
2413 0 : c_common_fixed_point_type_for_size (unsigned int ibit, unsigned int fbit,
2414 : int unsignedp, int satp)
2415 : {
2416 0 : enum mode_class mclass;
2417 0 : if (ibit == 0)
2418 0 : mclass = unsignedp ? MODE_UFRACT : MODE_FRACT;
2419 : else
2420 0 : mclass = unsignedp ? MODE_UACCUM : MODE_ACCUM;
2421 :
2422 0 : opt_scalar_mode opt_mode;
2423 0 : scalar_mode mode;
2424 0 : FOR_EACH_MODE_IN_CLASS (opt_mode, mclass)
2425 : {
2426 0 : mode = opt_mode.require ();
2427 0 : if (GET_MODE_IBIT (mode) >= ibit && GET_MODE_FBIT (mode) >= fbit)
2428 : break;
2429 : }
2430 :
2431 0 : if (!opt_mode.exists (&mode) || !targetm.scalar_mode_supported_p (mode))
2432 : {
2433 0 : sorry ("GCC cannot support operators with integer types and "
2434 : "fixed-point types that have too many integral and "
2435 : "fractional bits together");
2436 0 : return NULL_TREE;
2437 : }
2438 :
2439 0 : return c_common_type_for_mode (mode, satp);
2440 : }
2441 :
2442 : /* Used for communication between c_common_type_for_mode and
2443 : c_register_builtin_type. */
2444 : tree registered_builtin_types;
2445 :
2446 : /* Return a data type that has machine mode MODE.
2447 : If the mode is an integer,
2448 : then UNSIGNEDP selects between signed and unsigned types.
2449 : If the mode is a fixed-point mode,
2450 : then UNSIGNEDP selects between saturating and nonsaturating types. */
2451 :
2452 : tree
2453 12648550 : c_common_type_for_mode (machine_mode mode, int unsignedp)
2454 : {
2455 12648550 : tree t;
2456 12648550 : int i;
2457 :
2458 12648550 : if (mode == TYPE_MODE (integer_type_node))
2459 1784604 : return unsignedp ? unsigned_type_node : integer_type_node;
2460 :
2461 10863946 : if (mode == TYPE_MODE (signed_char_type_node))
2462 1961632 : return unsignedp ? unsigned_char_type_node : signed_char_type_node;
2463 :
2464 8902314 : if (mode == TYPE_MODE (short_integer_type_node))
2465 146496 : return unsignedp ? short_unsigned_type_node : short_integer_type_node;
2466 :
2467 8755818 : if (mode == TYPE_MODE (long_integer_type_node))
2468 5358993 : return unsignedp ? long_unsigned_type_node : long_integer_type_node;
2469 :
2470 3396825 : if (mode == TYPE_MODE (long_long_integer_type_node))
2471 84449 : return unsignedp ? long_long_unsigned_type_node : long_long_integer_type_node;
2472 :
2473 5187251 : for (i = 0; i < NUM_INT_N_ENTS; i ++)
2474 3312376 : if (int_n_enabled_p[i]
2475 3312376 : && mode == int_n_data[i].m)
2476 1437501 : return (unsignedp ? int_n_trees[i].unsigned_type
2477 1437501 : : int_n_trees[i].signed_type);
2478 :
2479 1874875 : if (mode == QImode)
2480 0 : return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
2481 :
2482 1874875 : if (mode == HImode)
2483 0 : return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
2484 :
2485 1874875 : if (mode == SImode)
2486 0 : return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
2487 :
2488 1874875 : if (mode == DImode)
2489 0 : return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
2490 :
2491 : #if HOST_BITS_PER_WIDE_INT >= 64
2492 1874875 : if (mode == TYPE_MODE (intTI_type_node))
2493 0 : return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
2494 : #endif
2495 :
2496 1874875 : if (mode == TYPE_MODE (float_type_node))
2497 49711 : return float_type_node;
2498 :
2499 1825164 : if (mode == TYPE_MODE (double_type_node))
2500 44356 : return double_type_node;
2501 :
2502 1780808 : if (mode == TYPE_MODE (long_double_type_node))
2503 17576 : return long_double_type_node;
2504 :
2505 13043921 : for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
2506 11541354 : if (FLOATN_NX_TYPE_NODE (i) != NULL_TREE
2507 11541354 : && mode == TYPE_MODE (FLOATN_NX_TYPE_NODE (i)))
2508 260665 : return FLOATN_NX_TYPE_NODE (i);
2509 :
2510 1502567 : if (mode == TYPE_MODE (void_type_node))
2511 0 : return void_type_node;
2512 :
2513 1502567 : if (mode == TYPE_MODE (build_pointer_type (char_type_node))
2514 1502567 : || mode == TYPE_MODE (build_pointer_type (integer_type_node)))
2515 : {
2516 0 : unsigned int precision
2517 0 : = GET_MODE_PRECISION (as_a <scalar_int_mode> (mode));
2518 0 : return (unsignedp
2519 0 : ? make_unsigned_type (precision)
2520 0 : : make_signed_type (precision));
2521 : }
2522 :
2523 1502567 : if (COMPLEX_MODE_P (mode))
2524 : {
2525 1260620 : machine_mode inner_mode;
2526 1260620 : tree inner_type;
2527 :
2528 1260620 : if (mode == TYPE_MODE (complex_float_type_node))
2529 210857 : return complex_float_type_node;
2530 1049763 : if (mode == TYPE_MODE (complex_double_type_node))
2531 209916 : return complex_double_type_node;
2532 839847 : if (mode == TYPE_MODE (complex_long_double_type_node))
2533 209909 : return complex_long_double_type_node;
2534 :
2535 2728531 : for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
2536 2518888 : if (COMPLEX_FLOATN_NX_TYPE_NODE (i) != NULL_TREE
2537 2518888 : && mode == TYPE_MODE (COMPLEX_FLOATN_NX_TYPE_NODE (i)))
2538 420295 : return COMPLEX_FLOATN_NX_TYPE_NODE (i);
2539 :
2540 209643 : if (mode == TYPE_MODE (complex_integer_type_node) && !unsignedp)
2541 12 : return complex_integer_type_node;
2542 :
2543 209631 : inner_mode = GET_MODE_INNER (mode);
2544 209631 : inner_type = c_common_type_for_mode (inner_mode, unsignedp);
2545 209631 : if (inner_type != NULL_TREE)
2546 209631 : return build_complex_type (inner_type);
2547 : }
2548 241947 : else if (GET_MODE_CLASS (mode) == MODE_VECTOR_BOOL
2549 241947 : && valid_vector_subparts_p (GET_MODE_NUNITS (mode)))
2550 : {
2551 0 : unsigned int elem_bits = vector_element_size (GET_MODE_PRECISION (mode),
2552 : GET_MODE_NUNITS (mode));
2553 0 : tree bool_type = build_nonstandard_boolean_type (elem_bits);
2554 0 : return build_vector_type_for_mode (bool_type, mode);
2555 : }
2556 225423 : else if (VECTOR_MODE_P (mode)
2557 261669 : && valid_vector_subparts_p (GET_MODE_NUNITS (mode)))
2558 : {
2559 19722 : machine_mode inner_mode = GET_MODE_INNER (mode);
2560 19722 : tree inner_type = c_common_type_for_mode (inner_mode, unsignedp);
2561 19722 : if (inner_type != NULL_TREE)
2562 19722 : return build_vector_type_for_mode (inner_type, mode);
2563 : }
2564 :
2565 222225 : if (dfloat32_type_node != NULL_TREE
2566 222225 : && mode == TYPE_MODE (dfloat32_type_node))
2567 2794 : return dfloat32_type_node;
2568 219431 : if (dfloat64_type_node != NULL_TREE
2569 219431 : && mode == TYPE_MODE (dfloat64_type_node))
2570 2903 : return dfloat64_type_node;
2571 216528 : if (dfloat128_type_node != NULL_TREE
2572 216528 : && mode == TYPE_MODE (dfloat128_type_node))
2573 2437 : return dfloat128_type_node;
2574 :
2575 214091 : if (ALL_SCALAR_FIXED_POINT_MODE_P (mode))
2576 : {
2577 0 : if (mode == TYPE_MODE (short_fract_type_node))
2578 0 : return unsignedp ? sat_short_fract_type_node : short_fract_type_node;
2579 0 : if (mode == TYPE_MODE (fract_type_node))
2580 0 : return unsignedp ? sat_fract_type_node : fract_type_node;
2581 0 : if (mode == TYPE_MODE (long_fract_type_node))
2582 0 : return unsignedp ? sat_long_fract_type_node : long_fract_type_node;
2583 0 : if (mode == TYPE_MODE (long_long_fract_type_node))
2584 0 : return unsignedp ? sat_long_long_fract_type_node
2585 0 : : long_long_fract_type_node;
2586 :
2587 0 : if (mode == TYPE_MODE (unsigned_short_fract_type_node))
2588 0 : return unsignedp ? sat_unsigned_short_fract_type_node
2589 0 : : unsigned_short_fract_type_node;
2590 0 : if (mode == TYPE_MODE (unsigned_fract_type_node))
2591 0 : return unsignedp ? sat_unsigned_fract_type_node
2592 0 : : unsigned_fract_type_node;
2593 0 : if (mode == TYPE_MODE (unsigned_long_fract_type_node))
2594 0 : return unsignedp ? sat_unsigned_long_fract_type_node
2595 0 : : unsigned_long_fract_type_node;
2596 0 : if (mode == TYPE_MODE (unsigned_long_long_fract_type_node))
2597 0 : return unsignedp ? sat_unsigned_long_long_fract_type_node
2598 0 : : unsigned_long_long_fract_type_node;
2599 :
2600 0 : if (mode == TYPE_MODE (short_accum_type_node))
2601 0 : return unsignedp ? sat_short_accum_type_node : short_accum_type_node;
2602 0 : if (mode == TYPE_MODE (accum_type_node))
2603 0 : return unsignedp ? sat_accum_type_node : accum_type_node;
2604 0 : if (mode == TYPE_MODE (long_accum_type_node))
2605 0 : return unsignedp ? sat_long_accum_type_node : long_accum_type_node;
2606 0 : if (mode == TYPE_MODE (long_long_accum_type_node))
2607 0 : return unsignedp ? sat_long_long_accum_type_node
2608 0 : : long_long_accum_type_node;
2609 :
2610 0 : if (mode == TYPE_MODE (unsigned_short_accum_type_node))
2611 0 : return unsignedp ? sat_unsigned_short_accum_type_node
2612 0 : : unsigned_short_accum_type_node;
2613 0 : if (mode == TYPE_MODE (unsigned_accum_type_node))
2614 0 : return unsignedp ? sat_unsigned_accum_type_node
2615 0 : : unsigned_accum_type_node;
2616 0 : if (mode == TYPE_MODE (unsigned_long_accum_type_node))
2617 0 : return unsignedp ? sat_unsigned_long_accum_type_node
2618 0 : : unsigned_long_accum_type_node;
2619 0 : if (mode == TYPE_MODE (unsigned_long_long_accum_type_node))
2620 0 : return unsignedp ? sat_unsigned_long_long_accum_type_node
2621 0 : : unsigned_long_long_accum_type_node;
2622 :
2623 0 : if (mode == QQmode)
2624 0 : return unsignedp ? sat_qq_type_node : qq_type_node;
2625 : if (mode == HQmode)
2626 0 : return unsignedp ? sat_hq_type_node : hq_type_node;
2627 : if (mode == SQmode)
2628 0 : return unsignedp ? sat_sq_type_node : sq_type_node;
2629 : if (mode == DQmode)
2630 0 : return unsignedp ? sat_dq_type_node : dq_type_node;
2631 : if (mode == TQmode)
2632 0 : return unsignedp ? sat_tq_type_node : tq_type_node;
2633 :
2634 : if (mode == UQQmode)
2635 0 : return unsignedp ? sat_uqq_type_node : uqq_type_node;
2636 : if (mode == UHQmode)
2637 0 : return unsignedp ? sat_uhq_type_node : uhq_type_node;
2638 : if (mode == USQmode)
2639 0 : return unsignedp ? sat_usq_type_node : usq_type_node;
2640 : if (mode == UDQmode)
2641 0 : return unsignedp ? sat_udq_type_node : udq_type_node;
2642 : if (mode == UTQmode)
2643 0 : return unsignedp ? sat_utq_type_node : utq_type_node;
2644 :
2645 : if (mode == HAmode)
2646 0 : return unsignedp ? sat_ha_type_node : ha_type_node;
2647 : if (mode == SAmode)
2648 0 : return unsignedp ? sat_sa_type_node : sa_type_node;
2649 : if (mode == DAmode)
2650 0 : return unsignedp ? sat_da_type_node : da_type_node;
2651 : if (mode == TAmode)
2652 0 : return unsignedp ? sat_ta_type_node : ta_type_node;
2653 :
2654 : if (mode == UHAmode)
2655 0 : return unsignedp ? sat_uha_type_node : uha_type_node;
2656 : if (mode == USAmode)
2657 0 : return unsignedp ? sat_usa_type_node : usa_type_node;
2658 : if (mode == UDAmode)
2659 0 : return unsignedp ? sat_uda_type_node : uda_type_node;
2660 : if (mode == UTAmode)
2661 0 : return unsignedp ? sat_uta_type_node : uta_type_node;
2662 : }
2663 :
2664 216910 : for (t = registered_builtin_types; t; t = TREE_CHAIN (t))
2665 : {
2666 215985 : tree type = TREE_VALUE (t);
2667 215985 : if (TYPE_MODE (type) == mode
2668 213269 : && VECTOR_TYPE_P (type) == VECTOR_MODE_P (mode)
2669 429254 : && !!unsignedp == !!TYPE_UNSIGNED (type))
2670 : return type;
2671 : }
2672 : return NULL_TREE;
2673 : }
2674 :
2675 : tree
2676 1696626 : c_common_unsigned_type (tree type)
2677 : {
2678 1696626 : return c_common_signed_or_unsigned_type (1, type);
2679 : }
2680 :
2681 : /* Return a signed type the same as TYPE in other respects. */
2682 :
2683 : tree
2684 5536901 : c_common_signed_type (tree type)
2685 : {
2686 5536901 : return c_common_signed_or_unsigned_type (0, type);
2687 : }
2688 :
2689 : /* Return a type the same as TYPE except unsigned or
2690 : signed according to UNSIGNEDP. */
2691 :
2692 : tree
2693 11370304 : c_common_signed_or_unsigned_type (int unsignedp, tree type)
2694 : {
2695 11370304 : tree type1;
2696 11370304 : int i;
2697 :
2698 : /* This block of code emulates the behavior of the old
2699 : c_common_unsigned_type. In particular, it returns
2700 : long_unsigned_type_node if passed a long, even when a int would
2701 : have the same size. This is necessary for warnings to work
2702 : correctly in archs where sizeof(int) == sizeof(long) */
2703 :
2704 11370304 : type1 = TYPE_MAIN_VARIANT (type);
2705 11370304 : if (type1 == signed_char_type_node || type1 == char_type_node || type1 == unsigned_char_type_node)
2706 3053614 : return unsignedp ? unsigned_char_type_node : signed_char_type_node;
2707 8316690 : if (type1 == integer_type_node || type1 == unsigned_type_node)
2708 2590628 : return unsignedp ? unsigned_type_node : integer_type_node;
2709 5726062 : if (type1 == short_integer_type_node || type1 == short_unsigned_type_node)
2710 1716900 : return unsignedp ? short_unsigned_type_node : short_integer_type_node;
2711 4009162 : if (type1 == long_integer_type_node || type1 == long_unsigned_type_node)
2712 1090586 : return unsignedp ? long_unsigned_type_node : long_integer_type_node;
2713 2918576 : if (type1 == long_long_integer_type_node || type1 == long_long_unsigned_type_node)
2714 525009 : return unsignedp ? long_long_unsigned_type_node : long_long_integer_type_node;
2715 :
2716 4716150 : for (i = 0; i < NUM_INT_N_ENTS; i ++)
2717 2393567 : if (int_n_enabled_p[i]
2718 2211444 : && (type1 == int_n_trees[i].unsigned_type
2719 2176139 : || type1 == int_n_trees[i].signed_type))
2720 70984 : return (unsignedp ? int_n_trees[i].unsigned_type
2721 70984 : : int_n_trees[i].signed_type);
2722 :
2723 : #if HOST_BITS_PER_WIDE_INT >= 64
2724 2322583 : if (type1 == intTI_type_node || type1 == unsigned_intTI_type_node)
2725 0 : return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
2726 : #endif
2727 2322583 : if (type1 == intDI_type_node || type1 == unsigned_intDI_type_node)
2728 0 : return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
2729 2322583 : if (type1 == intSI_type_node || type1 == unsigned_intSI_type_node)
2730 0 : return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
2731 2322583 : if (type1 == intHI_type_node || type1 == unsigned_intHI_type_node)
2732 0 : return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
2733 2322583 : if (type1 == intQI_type_node || type1 == unsigned_intQI_type_node)
2734 0 : return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
2735 :
2736 : #define C_COMMON_FIXED_TYPES(NAME) \
2737 : if (type1 == short_ ## NAME ## _type_node \
2738 : || type1 == unsigned_short_ ## NAME ## _type_node) \
2739 : return unsignedp ? unsigned_short_ ## NAME ## _type_node \
2740 : : short_ ## NAME ## _type_node; \
2741 : if (type1 == NAME ## _type_node \
2742 : || type1 == unsigned_ ## NAME ## _type_node) \
2743 : return unsignedp ? unsigned_ ## NAME ## _type_node \
2744 : : NAME ## _type_node; \
2745 : if (type1 == long_ ## NAME ## _type_node \
2746 : || type1 == unsigned_long_ ## NAME ## _type_node) \
2747 : return unsignedp ? unsigned_long_ ## NAME ## _type_node \
2748 : : long_ ## NAME ## _type_node; \
2749 : if (type1 == long_long_ ## NAME ## _type_node \
2750 : || type1 == unsigned_long_long_ ## NAME ## _type_node) \
2751 : return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \
2752 : : long_long_ ## NAME ## _type_node;
2753 :
2754 : #define C_COMMON_FIXED_MODE_TYPES(NAME) \
2755 : if (type1 == NAME ## _type_node \
2756 : || type1 == u ## NAME ## _type_node) \
2757 : return unsignedp ? u ## NAME ## _type_node \
2758 : : NAME ## _type_node;
2759 :
2760 : #define C_COMMON_FIXED_TYPES_SAT(NAME) \
2761 : if (type1 == sat_ ## short_ ## NAME ## _type_node \
2762 : || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \
2763 : return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \
2764 : : sat_ ## short_ ## NAME ## _type_node; \
2765 : if (type1 == sat_ ## NAME ## _type_node \
2766 : || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \
2767 : return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \
2768 : : sat_ ## NAME ## _type_node; \
2769 : if (type1 == sat_ ## long_ ## NAME ## _type_node \
2770 : || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \
2771 : return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \
2772 : : sat_ ## long_ ## NAME ## _type_node; \
2773 : if (type1 == sat_ ## long_long_ ## NAME ## _type_node \
2774 : || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \
2775 : return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \
2776 : : sat_ ## long_long_ ## NAME ## _type_node;
2777 :
2778 : #define C_COMMON_FIXED_MODE_TYPES_SAT(NAME) \
2779 : if (type1 == sat_ ## NAME ## _type_node \
2780 : || type1 == sat_ ## u ## NAME ## _type_node) \
2781 : return unsignedp ? sat_ ## u ## NAME ## _type_node \
2782 : : sat_ ## NAME ## _type_node;
2783 :
2784 2322583 : C_COMMON_FIXED_TYPES (fract);
2785 2322583 : C_COMMON_FIXED_TYPES_SAT (fract);
2786 2322583 : C_COMMON_FIXED_TYPES (accum);
2787 2322583 : C_COMMON_FIXED_TYPES_SAT (accum);
2788 :
2789 2322583 : C_COMMON_FIXED_MODE_TYPES (qq);
2790 2322583 : C_COMMON_FIXED_MODE_TYPES (hq);
2791 2322583 : C_COMMON_FIXED_MODE_TYPES (sq);
2792 2322583 : C_COMMON_FIXED_MODE_TYPES (dq);
2793 2322583 : C_COMMON_FIXED_MODE_TYPES (tq);
2794 2322583 : C_COMMON_FIXED_MODE_TYPES_SAT (qq);
2795 2322583 : C_COMMON_FIXED_MODE_TYPES_SAT (hq);
2796 2322583 : C_COMMON_FIXED_MODE_TYPES_SAT (sq);
2797 2322583 : C_COMMON_FIXED_MODE_TYPES_SAT (dq);
2798 2322583 : C_COMMON_FIXED_MODE_TYPES_SAT (tq);
2799 2322583 : C_COMMON_FIXED_MODE_TYPES (ha);
2800 2322583 : C_COMMON_FIXED_MODE_TYPES (sa);
2801 2322583 : C_COMMON_FIXED_MODE_TYPES (da);
2802 2322583 : C_COMMON_FIXED_MODE_TYPES (ta);
2803 2322583 : C_COMMON_FIXED_MODE_TYPES_SAT (ha);
2804 2322583 : C_COMMON_FIXED_MODE_TYPES_SAT (sa);
2805 2322583 : C_COMMON_FIXED_MODE_TYPES_SAT (da);
2806 2322583 : C_COMMON_FIXED_MODE_TYPES_SAT (ta);
2807 :
2808 : /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not
2809 : the precision; they have precision set to match their range, but
2810 : may use a wider mode to match an ABI. If we change modes, we may
2811 : wind up with bad conversions. For INTEGER_TYPEs in C, must check
2812 : the precision as well, so as to yield correct results for
2813 : bit-field types. C++ does not have these separate bit-field
2814 : types, and producing a signed or unsigned variant of an
2815 : ENUMERAL_TYPE may cause other problems as well. */
2816 :
2817 2322583 : if (!INTEGRAL_TYPE_P (type)
2818 2322583 : || TYPE_UNSIGNED (type) == unsignedp)
2819 : return type;
2820 :
2821 1209467 : if (TREE_CODE (type) == BITINT_TYPE
2822 : /* signed _BitInt(1) is invalid before C2Y, avoid creating that. */
2823 1209467 : && (unsignedp || flag_isoc2y || TYPE_PRECISION (type) > 1))
2824 2178 : return build_bitint_type (TYPE_PRECISION (type), unsignedp);
2825 :
2826 : #define TYPE_OK(node) \
2827 : (TYPE_MODE (type) == TYPE_MODE (node) \
2828 : && TYPE_PRECISION (type) == TYPE_PRECISION (node))
2829 1207289 : if (TYPE_OK (signed_char_type_node))
2830 15300 : return unsignedp ? unsigned_char_type_node : signed_char_type_node;
2831 1191989 : if (TYPE_OK (integer_type_node))
2832 185535 : return unsignedp ? unsigned_type_node : integer_type_node;
2833 1006454 : if (TYPE_OK (short_integer_type_node))
2834 13380 : return unsignedp ? short_unsigned_type_node : short_integer_type_node;
2835 993074 : if (TYPE_OK (long_integer_type_node))
2836 985548 : return unsignedp ? long_unsigned_type_node : long_integer_type_node;
2837 7526 : if (TYPE_OK (long_long_integer_type_node))
2838 43 : return (unsignedp ? long_long_unsigned_type_node
2839 4 : : long_long_integer_type_node);
2840 :
2841 14711 : for (i = 0; i < NUM_INT_N_ENTS; i ++)
2842 7483 : if (int_n_enabled_p[i]
2843 6987 : && TYPE_MODE (type) == int_n_data[i].m
2844 7770 : && TYPE_PRECISION (type) == int_n_data[i].bitsize)
2845 255 : return (unsignedp ? int_n_trees[i].unsigned_type
2846 255 : : int_n_trees[i].signed_type);
2847 :
2848 : #if HOST_BITS_PER_WIDE_INT >= 64
2849 7228 : if (TYPE_OK (intTI_type_node))
2850 0 : return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
2851 : #endif
2852 7228 : if (TYPE_OK (intDI_type_node))
2853 0 : return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
2854 7228 : if (TYPE_OK (intSI_type_node))
2855 0 : return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
2856 7228 : if (TYPE_OK (intHI_type_node))
2857 0 : return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
2858 7228 : if (TYPE_OK (intQI_type_node))
2859 0 : return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
2860 : #undef TYPE_OK
2861 :
2862 7228 : return build_nonstandard_integer_type (TYPE_PRECISION (type), unsignedp);
2863 : }
2864 :
2865 : /* Build a bit-field integer type for the given WIDTH and UNSIGNEDP. */
2866 :
2867 : tree
2868 540248 : c_build_bitfield_integer_type (unsigned HOST_WIDE_INT width, int unsignedp)
2869 : {
2870 540248 : int i;
2871 :
2872 : /* Extended integer types of the same width as a standard type have
2873 : lesser rank, so those of the same width as int promote to int or
2874 : unsigned int and are valid for printf formats expecting int or
2875 : unsigned int. To avoid such special cases, avoid creating
2876 : extended integer types for bit-fields if a standard integer type
2877 : is available. */
2878 540248 : if (width == TYPE_PRECISION (integer_type_node))
2879 138 : return unsignedp ? unsigned_type_node : integer_type_node;
2880 540110 : if (width == TYPE_PRECISION (signed_char_type_node))
2881 20275 : return unsignedp ? unsigned_char_type_node : signed_char_type_node;
2882 519835 : if (width == TYPE_PRECISION (short_integer_type_node))
2883 1427 : return unsignedp ? short_unsigned_type_node : short_integer_type_node;
2884 518408 : if (width == TYPE_PRECISION (long_integer_type_node))
2885 0 : return unsignedp ? long_unsigned_type_node : long_integer_type_node;
2886 518408 : if (width == TYPE_PRECISION (long_long_integer_type_node))
2887 0 : return (unsignedp ? long_long_unsigned_type_node
2888 0 : : long_long_integer_type_node);
2889 1036816 : for (i = 0; i < NUM_INT_N_ENTS; i ++)
2890 518408 : if (int_n_enabled_p[i]
2891 511159 : && width == int_n_data[i].bitsize)
2892 0 : return (unsignedp ? int_n_trees[i].unsigned_type
2893 0 : : int_n_trees[i].signed_type);
2894 518408 : return build_nonstandard_integer_type (width, unsignedp);
2895 : }
2896 :
2897 : /* The C version of the register_builtin_type langhook. */
2898 :
2899 : void
2900 628803 : c_register_builtin_type (tree type, const char* name)
2901 : {
2902 628803 : tree decl;
2903 :
2904 628803 : decl = build_decl (UNKNOWN_LOCATION,
2905 : TYPE_DECL, get_identifier (name), type);
2906 628803 : DECL_ARTIFICIAL (decl) = 1;
2907 628803 : if (!TYPE_NAME (type))
2908 308019 : TYPE_NAME (type) = decl;
2909 628803 : lang_hooks.decls.pushdecl (decl);
2910 :
2911 628803 : registered_builtin_types = tree_cons (0, type, registered_builtin_types);
2912 628803 : }
2913 :
2914 : /* Print an error message for invalid operands to arith operation
2915 : CODE with TYPE0 for operand 0, and TYPE1 for operand 1.
2916 : RICHLOC is a rich location for the message, containing either
2917 : three separate locations for each of the operator and operands
2918 :
2919 : lhs op rhs
2920 : ~~~ ^~ ~~~
2921 :
2922 : (C FE), or one location ranging over all over them
2923 :
2924 : lhs op rhs
2925 : ~~~~^~~~~~
2926 :
2927 : (C++ FE). */
2928 :
2929 : void
2930 564 : binary_op_error (rich_location *richloc, enum tree_code code,
2931 : tree type0, tree type1)
2932 : {
2933 564 : const char *opname;
2934 :
2935 564 : switch (code)
2936 : {
2937 : case PLUS_EXPR:
2938 : opname = "+"; break;
2939 14 : case MINUS_EXPR:
2940 14 : opname = "-"; break;
2941 378 : case MULT_EXPR:
2942 378 : opname = "*"; break;
2943 0 : case MAX_EXPR:
2944 0 : opname = "max"; break;
2945 0 : case MIN_EXPR:
2946 0 : opname = "min"; break;
2947 2 : case EQ_EXPR:
2948 2 : opname = "=="; break;
2949 2 : case NE_EXPR:
2950 2 : opname = "!="; break;
2951 0 : case LE_EXPR:
2952 0 : opname = "<="; break;
2953 0 : case GE_EXPR:
2954 0 : opname = ">="; break;
2955 1 : case LT_EXPR:
2956 1 : opname = "<"; break;
2957 1 : case GT_EXPR:
2958 1 : opname = ">"; break;
2959 21 : case LSHIFT_EXPR:
2960 21 : opname = "<<"; break;
2961 16 : case RSHIFT_EXPR:
2962 16 : opname = ">>"; break;
2963 3 : case TRUNC_MOD_EXPR:
2964 3 : case FLOOR_MOD_EXPR:
2965 3 : opname = "%"; break;
2966 6 : case TRUNC_DIV_EXPR:
2967 6 : case FLOOR_DIV_EXPR:
2968 6 : opname = "/"; break;
2969 40 : case BIT_AND_EXPR:
2970 40 : opname = "&"; break;
2971 21 : case BIT_IOR_EXPR:
2972 21 : opname = "|"; break;
2973 0 : case TRUTH_ANDIF_EXPR:
2974 0 : opname = "&&"; break;
2975 0 : case TRUTH_ORIF_EXPR:
2976 0 : opname = "||"; break;
2977 22 : case BIT_XOR_EXPR:
2978 22 : opname = "^"; break;
2979 0 : default:
2980 0 : gcc_unreachable ();
2981 : }
2982 564 : pp_markup::element_quoted_type element_0 (type0, highlight_colors::lhs);
2983 1128 : pp_markup::element_quoted_type element_1 (type1, highlight_colors::rhs);
2984 564 : error_at (richloc,
2985 : "invalid operands to binary %s (have %e and %e)",
2986 : opname, &element_0, &element_1);
2987 564 : }
2988 :
2989 : /* Given an expression as a tree, return its original type. Do this
2990 : by stripping any conversion that preserves the sign and precision. */
2991 : static tree
2992 56819 : expr_original_type (tree expr)
2993 : {
2994 56819 : STRIP_SIGN_NOPS (expr);
2995 56819 : return TREE_TYPE (expr);
2996 : }
2997 :
2998 : /* Subroutine of build_binary_op, used for comparison operations.
2999 : See if the operands have both been converted from subword integer types
3000 : and, if so, perhaps change them both back to their original type.
3001 : This function is also responsible for converting the two operands
3002 : to the proper common type for comparison.
3003 :
3004 : The arguments of this function are all pointers to local variables
3005 : of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1,
3006 : RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
3007 :
3008 : LOC is the location of the comparison.
3009 :
3010 : If this function returns non-NULL_TREE, it means that the comparison has
3011 : a constant value. What this function returns is an expression for
3012 : that value. */
3013 :
3014 : tree
3015 30999347 : shorten_compare (location_t loc, tree *op0_ptr, tree *op1_ptr,
3016 : tree *restype_ptr, enum tree_code *rescode_ptr)
3017 : {
3018 30999347 : tree type;
3019 30999347 : tree op0 = *op0_ptr;
3020 30999347 : tree op1 = *op1_ptr;
3021 30999347 : int unsignedp0, unsignedp1;
3022 30999347 : int real1, real2;
3023 30999347 : tree primop0, primop1;
3024 30999347 : enum tree_code code = *rescode_ptr;
3025 :
3026 : /* Throw away any conversions to wider types
3027 : already present in the operands. */
3028 :
3029 30999347 : primop0 = c_common_get_narrower (op0, &unsignedp0);
3030 30999347 : primop1 = c_common_get_narrower (op1, &unsignedp1);
3031 :
3032 : /* If primopN is first sign-extended from primopN's precision to opN's
3033 : precision, then zero-extended from opN's precision to
3034 : *restype_ptr precision, shortenings might be invalid. */
3035 30999347 : if (TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (TREE_TYPE (op0))
3036 1713101 : && TYPE_PRECISION (TREE_TYPE (op0)) < TYPE_PRECISION (*restype_ptr)
3037 2498 : && !unsignedp0
3038 31001565 : && TYPE_UNSIGNED (TREE_TYPE (op0)))
3039 : primop0 = op0;
3040 30999347 : if (TYPE_PRECISION (TREE_TYPE (primop1)) < TYPE_PRECISION (TREE_TYPE (op1))
3041 1021344 : && TYPE_PRECISION (TREE_TYPE (op1)) < TYPE_PRECISION (*restype_ptr)
3042 7925 : && !unsignedp1
3043 31004340 : && TYPE_UNSIGNED (TREE_TYPE (op1)))
3044 : primop1 = op1;
3045 :
3046 : /* Handle the case that OP0 does not *contain* a conversion
3047 : but it *requires* conversion to FINAL_TYPE. */
3048 :
3049 30999347 : if (op0 == primop0 && TREE_TYPE (op0) != *restype_ptr)
3050 459406 : unsignedp0 = TYPE_UNSIGNED (TREE_TYPE (op0));
3051 30999347 : if (op1 == primop1 && TREE_TYPE (op1) != *restype_ptr)
3052 8979344 : unsignedp1 = TYPE_UNSIGNED (TREE_TYPE (op1));
3053 :
3054 : /* If one of the operands must be floated, we cannot optimize. */
3055 30999347 : real1 = SCALAR_FLOAT_TYPE_P (TREE_TYPE (primop0));
3056 30999347 : real2 = SCALAR_FLOAT_TYPE_P (TREE_TYPE (primop1));
3057 :
3058 : /* If first arg is constant, swap the args (changing operation
3059 : so value is preserved), for canonicalization. Don't do this if
3060 : the second arg is 0. */
3061 :
3062 30999347 : if (TREE_CONSTANT (primop0)
3063 7966559 : && !integer_zerop (primop1) && !real_zerop (primop1)
3064 36956746 : && !fixed_zerop (primop1))
3065 : {
3066 5957399 : std::swap (primop0, primop1);
3067 5957399 : std::swap (op0, op1);
3068 5957399 : *op0_ptr = op0;
3069 5957399 : *op1_ptr = op1;
3070 5957399 : std::swap (unsignedp0, unsignedp1);
3071 5957399 : std::swap (real1, real2);
3072 :
3073 5957399 : switch (code)
3074 : {
3075 : case LT_EXPR:
3076 : code = GT_EXPR;
3077 : break;
3078 : case GT_EXPR:
3079 : code = LT_EXPR;
3080 : break;
3081 : case LE_EXPR:
3082 : code = GE_EXPR;
3083 : break;
3084 : case GE_EXPR:
3085 : code = LE_EXPR;
3086 : break;
3087 : default:
3088 : break;
3089 : }
3090 5957399 : *rescode_ptr = code;
3091 : }
3092 :
3093 : /* If comparing an integer against a constant more bits wide,
3094 : maybe we can deduce a value of 1 or 0 independent of the data.
3095 : Or else truncate the constant now
3096 : rather than extend the variable at run time.
3097 :
3098 : This is only interesting if the constant is the wider arg.
3099 : Also, it is not safe if the constant is unsigned and the
3100 : variable arg is signed, since in this case the variable
3101 : would be sign-extended and then regarded as unsigned.
3102 : Our technique fails in this case because the lowest/highest
3103 : possible unsigned results don't follow naturally from the
3104 : lowest/highest possible values of the variable operand.
3105 : For just EQ_EXPR and NE_EXPR there is another technique that
3106 : could be used: see if the constant can be faithfully represented
3107 : in the other operand's type, by truncating it and reextending it
3108 : and see if that preserves the constant's value. */
3109 :
3110 26561120 : if (!real1 && !real2
3111 26537885 : && TREE_CODE (TREE_TYPE (primop0)) != FIXED_POINT_TYPE
3112 26537885 : && TREE_CODE (primop1) == INTEGER_CST
3113 48669082 : && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr))
3114 : {
3115 2619606 : int min_gt, max_gt, min_lt, max_lt;
3116 2619606 : tree maxval, minval;
3117 : /* 1 if comparison is nominally unsigned. */
3118 2619606 : int unsignedp = TYPE_UNSIGNED (*restype_ptr);
3119 2619606 : tree val;
3120 :
3121 2619606 : type = c_common_signed_or_unsigned_type (unsignedp0,
3122 2619606 : TREE_TYPE (primop0));
3123 :
3124 2619606 : maxval = TYPE_MAX_VALUE (type);
3125 2619606 : minval = TYPE_MIN_VALUE (type);
3126 :
3127 2619606 : if (unsignedp && !unsignedp0)
3128 547423 : *restype_ptr = c_common_signed_type (*restype_ptr);
3129 :
3130 2619606 : if (TREE_TYPE (primop1) != *restype_ptr)
3131 : {
3132 : /* Convert primop1 to target type, but do not introduce
3133 : additional overflow. We know primop1 is an int_cst. */
3134 556737 : primop1 = force_fit_type (*restype_ptr,
3135 : wi::to_wide
3136 1113474 : (primop1,
3137 556737 : TYPE_PRECISION (*restype_ptr)),
3138 556737 : 0, TREE_OVERFLOW (primop1));
3139 : }
3140 2619606 : if (type != *restype_ptr)
3141 : {
3142 2619606 : minval = convert (*restype_ptr, minval);
3143 2619606 : maxval = convert (*restype_ptr, maxval);
3144 : }
3145 :
3146 2619606 : min_gt = tree_int_cst_lt (primop1, minval);
3147 2619606 : max_gt = tree_int_cst_lt (primop1, maxval);
3148 2619606 : min_lt = tree_int_cst_lt (minval, primop1);
3149 2619606 : max_lt = tree_int_cst_lt (maxval, primop1);
3150 :
3151 2619606 : val = 0;
3152 : /* This used to be a switch, but Genix compiler can't handle that. */
3153 2619606 : if (code == NE_EXPR)
3154 : {
3155 327511 : if (max_lt || min_gt)
3156 23 : val = truthvalue_true_node;
3157 : }
3158 : else if (code == EQ_EXPR)
3159 : {
3160 1370846 : if (max_lt || min_gt)
3161 28 : val = truthvalue_false_node;
3162 : }
3163 : else if (code == LT_EXPR)
3164 : {
3165 441311 : if (max_lt)
3166 54 : val = truthvalue_true_node;
3167 441311 : if (!min_lt)
3168 2745 : val = truthvalue_false_node;
3169 : }
3170 : else if (code == GT_EXPR)
3171 : {
3172 146458 : if (min_gt)
3173 8 : val = truthvalue_true_node;
3174 146458 : if (!max_gt)
3175 6 : val = truthvalue_false_node;
3176 : }
3177 : else if (code == LE_EXPR)
3178 : {
3179 126366 : if (!max_gt)
3180 77 : val = truthvalue_true_node;
3181 126366 : if (min_gt)
3182 7 : val = truthvalue_false_node;
3183 : }
3184 : else if (code == GE_EXPR)
3185 : {
3186 207113 : if (!min_lt)
3187 207 : val = truthvalue_true_node;
3188 207113 : if (max_lt)
3189 14964 : val = truthvalue_false_node;
3190 : }
3191 :
3192 : /* If primop0 was sign-extended and unsigned comparison specd,
3193 : we did a signed comparison above using the signed type bounds.
3194 : But the comparison we output must be unsigned.
3195 :
3196 : Also, for inequalities, VAL is no good; but if the signed
3197 : comparison had *any* fixed result, it follows that the
3198 : unsigned comparison just tests the sign in reverse
3199 : (positive values are LE, negative ones GE).
3200 : So we can generate an unsigned comparison
3201 : against an extreme value of the signed type. */
3202 :
3203 2619606 : if (unsignedp && !unsignedp0)
3204 : {
3205 547423 : if (val != 0)
3206 112 : switch (code)
3207 : {
3208 81 : case LT_EXPR:
3209 81 : case GE_EXPR:
3210 81 : primop1 = TYPE_MIN_VALUE (type);
3211 81 : val = 0;
3212 81 : break;
3213 :
3214 30 : case LE_EXPR:
3215 30 : case GT_EXPR:
3216 30 : primop1 = TYPE_MAX_VALUE (type);
3217 30 : val = 0;
3218 30 : break;
3219 :
3220 : default:
3221 : break;
3222 : }
3223 547423 : type = c_common_unsigned_type (type);
3224 : }
3225 :
3226 2619606 : if (TREE_CODE (primop0) != INTEGER_CST
3227 : /* Don't warn if it's from a (non-system) macro. */
3228 2619606 : && !(from_macro_expansion_at
3229 1521774 : (expansion_point_location_if_in_system_header
3230 1521774 : (EXPR_LOCATION (primop0)))))
3231 : {
3232 1480474 : if (val == truthvalue_false_node)
3233 2779 : warning_at (loc, OPT_Wtype_limits,
3234 : "comparison is always false due to limited range of data type");
3235 1480474 : if (val == truthvalue_true_node)
3236 254 : warning_at (loc, OPT_Wtype_limits,
3237 : "comparison is always true due to limited range of data type");
3238 : }
3239 :
3240 2619606 : if (val != 0)
3241 : {
3242 : /* Don't forget to evaluate PRIMOP0 if it has side effects. */
3243 18008 : if (TREE_SIDE_EFFECTS (primop0))
3244 11 : return build2 (COMPOUND_EXPR, TREE_TYPE (val), primop0, val);
3245 : return val;
3246 : }
3247 :
3248 : /* Value is not predetermined, but do the comparison
3249 : in the type of the operand that is not constant.
3250 : TYPE is already properly set. */
3251 : }
3252 :
3253 : /* If either arg is decimal float and the other is float, find the
3254 : proper common type to use for comparison. */
3255 4438227 : else if (real1 && real2
3256 4110339 : && DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0)))
3257 28396289 : && DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1))))
3258 16547 : type = common_type (TREE_TYPE (primop0), TREE_TYPE (primop1));
3259 :
3260 : /* If either arg is decimal float and the other is float, fail. */
3261 4421680 : else if (real1 && real2
3262 32456986 : && (DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0)))
3263 4093791 : || DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1)))))
3264 : {
3265 2 : type = *restype_ptr;
3266 2 : primop0 = op0;
3267 2 : primop1 = op1;
3268 : }
3269 :
3270 4421678 : else if (real1 && real2
3271 32456982 : && (TYPE_PRECISION (TREE_TYPE (primop0))
3272 4093790 : == TYPE_PRECISION (TREE_TYPE (primop1))))
3273 3996230 : type = TREE_TYPE (primop0);
3274 :
3275 : /* If args' natural types are both narrower than nominal type
3276 : and both extend in the same manner, compare them
3277 : in the type of the wider arg.
3278 : Otherwise must actually extend both to the nominal
3279 : common type lest different ways of extending
3280 : alter the result.
3281 : (eg, (short)-1 == (unsigned short)-1 should be 0.) */
3282 :
3283 21555398 : else if (unsignedp0 == unsignedp1 && real1 == real2
3284 21216698 : && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr)
3285 593232 : && TYPE_PRECISION (TREE_TYPE (primop1)) < TYPE_PRECISION (*restype_ptr)
3286 24751003 : && (type = common_type (TREE_TYPE (primop0), TREE_TYPE (primop1)))
3287 384041 : != error_mark_node)
3288 : {
3289 384041 : type = c_common_signed_or_unsigned_type (unsignedp0
3290 384041 : || TYPE_UNSIGNED (*restype_ptr),
3291 : type);
3292 : /* Make sure shorter operand is extended the right way
3293 : to match the longer operand. */
3294 384041 : primop0
3295 384041 : = convert (c_common_signed_or_unsigned_type (unsignedp0,
3296 384041 : TREE_TYPE (primop0)),
3297 : primop0);
3298 384041 : primop1
3299 384041 : = convert (c_common_signed_or_unsigned_type (unsignedp1,
3300 384041 : TREE_TYPE (primop1)),
3301 : primop1);
3302 : }
3303 : else
3304 : {
3305 : /* Here we must do the comparison on the nominal type
3306 : using the args exactly as we received them. */
3307 23982921 : type = *restype_ptr;
3308 23982921 : primop0 = op0;
3309 23982921 : primop1 = op1;
3310 :
3311 : /* We want to fold unsigned comparisons of >= and < against zero.
3312 : For these, we may also issue a warning if we have a non-constant
3313 : compared against zero, where the zero was spelled as "0" (rather
3314 : than merely folding to it).
3315 : If we have at least one constant, then op1 is constant
3316 : and we may have a non-constant expression as op0. */
3317 23557473 : if (!real1 && !real2 && integer_zerop (primop1)
3318 33763933 : && TYPE_UNSIGNED (*restype_ptr))
3319 : {
3320 3388240 : tree value = NULL_TREE;
3321 : /* All unsigned values are >= 0, so we warn. However,
3322 : if OP0 is a constant that is >= 0, the signedness of
3323 : the comparison isn't an issue, so suppress the
3324 : warning. */
3325 3388240 : tree folded_op0 = fold_for_warn (op0);
3326 3388240 : bool warn =
3327 72857 : warn_type_limits && !in_system_header_at (loc)
3328 66609 : && !(TREE_CODE (folded_op0) == INTEGER_CST
3329 9790 : && !TREE_OVERFLOW (convert (c_common_signed_type (type),
3330 : folded_op0)))
3331 : /* Do not warn for enumeration types. */
3332 3445059 : && (TREE_CODE (expr_original_type (folded_op0)) != ENUMERAL_TYPE);
3333 :
3334 3388240 : switch (code)
3335 : {
3336 11790 : case GE_EXPR:
3337 11790 : if (warn)
3338 62 : warning_at (loc, OPT_Wtype_limits,
3339 : "comparison of unsigned expression in %<>= 0%> "
3340 : "is always true");
3341 11790 : value = truthvalue_true_node;
3342 11790 : break;
3343 :
3344 356381 : case LT_EXPR:
3345 356381 : if (warn)
3346 55 : warning_at (loc, OPT_Wtype_limits,
3347 : "comparison of unsigned expression in %<< 0%> "
3348 : "is always false");
3349 356381 : value = truthvalue_false_node;
3350 356381 : break;
3351 :
3352 : default:
3353 : break;
3354 : }
3355 :
3356 368171 : if (value != NULL_TREE)
3357 : {
3358 : /* Don't forget to evaluate PRIMOP0 if it has side effects. */
3359 368171 : if (TREE_SIDE_EFFECTS (primop0))
3360 78 : return build2 (COMPOUND_EXPR, TREE_TYPE (value),
3361 78 : primop0, value);
3362 : return value;
3363 : }
3364 : }
3365 : }
3366 :
3367 30613168 : *op0_ptr = convert (type, primop0);
3368 30613168 : *op1_ptr = convert (type, primop1);
3369 :
3370 30613168 : *restype_ptr = truthvalue_type_node;
3371 :
3372 30613168 : return NULL_TREE;
3373 : }
3374 :
3375 : /* Return a tree for the sum or difference (RESULTCODE says which)
3376 : of pointer PTROP and integer INTOP. */
3377 :
3378 : tree
3379 6643026 : pointer_int_sum (location_t loc, enum tree_code resultcode,
3380 : tree ptrop, tree intop, bool complain)
3381 : {
3382 6643026 : tree size_exp, ret;
3383 :
3384 : /* The result is a pointer of the same type that is being added. */
3385 6643026 : tree result_type = TREE_TYPE (ptrop);
3386 :
3387 6643026 : if (VOID_TYPE_P (TREE_TYPE (result_type)))
3388 : {
3389 1107 : if (complain && warn_pointer_arith)
3390 67 : pedwarn (loc, OPT_Wpointer_arith,
3391 : "pointer of type %<void *%> used in arithmetic");
3392 : else if (!complain)
3393 0 : return error_mark_node;
3394 1107 : size_exp = integer_one_node;
3395 : }
3396 6641919 : else if (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE)
3397 : {
3398 118 : if (complain && warn_pointer_arith)
3399 49 : pedwarn (loc, OPT_Wpointer_arith,
3400 : "pointer to a function used in arithmetic");
3401 : else if (!complain)
3402 0 : return error_mark_node;
3403 118 : size_exp = integer_one_node;
3404 : }
3405 6641801 : else if (!verify_type_context (loc, TCTX_POINTER_ARITH,
3406 6641801 : TREE_TYPE (result_type)))
3407 0 : size_exp = integer_one_node;
3408 : else
3409 : {
3410 6641801 : if (!complain && !COMPLETE_TYPE_P (TREE_TYPE (result_type)))
3411 108 : return error_mark_node;
3412 6641693 : size_exp = size_in_bytes_loc (loc, TREE_TYPE (result_type));
3413 : /* Wrap the pointer expression in a SAVE_EXPR to make sure it
3414 : is evaluated first when the size expression may depend
3415 : on it for VM types. */
3416 6641693 : if (TREE_SIDE_EFFECTS (size_exp)
3417 1935 : && TREE_SIDE_EFFECTS (ptrop)
3418 6641712 : && variably_modified_type_p (TREE_TYPE (ptrop), NULL))
3419 : {
3420 19 : ptrop = save_expr (ptrop);
3421 19 : size_exp = build2 (COMPOUND_EXPR, TREE_TYPE (intop), ptrop, size_exp);
3422 : }
3423 : }
3424 :
3425 : /* We are manipulating pointer values, so we don't need to warn
3426 : about relying on undefined signed overflow. We disable the
3427 : warning here because we use integer types so fold won't know that
3428 : they are really pointers. */
3429 6642918 : fold_defer_overflow_warnings ();
3430 :
3431 : /* If what we are about to multiply by the size of the elements
3432 : contains a constant term, apply distributive law
3433 : and multiply that constant term separately.
3434 : This helps produce common subexpressions. */
3435 6642918 : if ((TREE_CODE (intop) == PLUS_EXPR || TREE_CODE (intop) == MINUS_EXPR)
3436 173150 : && !TREE_CONSTANT (intop)
3437 173068 : && TREE_CONSTANT (TREE_OPERAND (intop, 1))
3438 137885 : && TREE_CONSTANT (size_exp)
3439 : /* If the constant comes from pointer subtraction,
3440 : skip this optimization--it would cause an error. */
3441 137884 : && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop, 0))) == INTEGER_TYPE
3442 : /* If the constant is unsigned, and smaller than the pointer size,
3443 : then we must skip this optimization. This is because it could cause
3444 : an overflow error if the constant is negative but INTOP is not. */
3445 275768 : && (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (intop))
3446 118241 : || (TYPE_PRECISION (TREE_TYPE (intop))
3447 118241 : == TYPE_PRECISION (TREE_TYPE (ptrop))))
3448 6814796 : && TYPE_PRECISION (TREE_TYPE (intop)) <= TYPE_PRECISION (sizetype))
3449 : {
3450 33994 : tree intop0 = TREE_OPERAND (intop, 0);
3451 33994 : tree intop1 = TREE_OPERAND (intop, 1);
3452 33994 : if (TYPE_PRECISION (TREE_TYPE (intop)) != TYPE_PRECISION (sizetype)
3453 33994 : || TYPE_UNSIGNED (TREE_TYPE (intop)) != TYPE_UNSIGNED (sizetype))
3454 : {
3455 19643 : tree optype = c_common_type_for_size (TYPE_PRECISION (sizetype),
3456 19643 : TYPE_UNSIGNED (sizetype));
3457 19643 : intop0 = convert (optype, intop0);
3458 19643 : intop1 = convert (optype, intop1);
3459 : }
3460 33994 : tree t = fold_build2_loc (loc, MULT_EXPR, TREE_TYPE (intop0), intop0,
3461 33994 : convert (TREE_TYPE (intop0), size_exp));
3462 33994 : intop0 = convert (sizetype, t);
3463 33994 : if (TREE_OVERFLOW_P (intop0) && !TREE_OVERFLOW (t))
3464 0 : intop0 = wide_int_to_tree (TREE_TYPE (intop0), wi::to_wide (intop0));
3465 33994 : t = fold_build2_loc (loc, MULT_EXPR, TREE_TYPE (intop1), intop1,
3466 33994 : convert (TREE_TYPE (intop1), size_exp));
3467 33994 : intop1 = convert (sizetype, t);
3468 33994 : if (TREE_OVERFLOW_P (intop1) && !TREE_OVERFLOW (t))
3469 0 : intop1 = wide_int_to_tree (TREE_TYPE (intop1), wi::to_wide (intop1));
3470 33994 : intop = build_binary_op (EXPR_LOCATION (intop), TREE_CODE (intop),
3471 : intop0, intop1, true);
3472 :
3473 : /* Create the sum or difference. */
3474 33994 : if (resultcode == MINUS_EXPR)
3475 51 : intop = fold_build1_loc (loc, NEGATE_EXPR, sizetype, intop);
3476 :
3477 33994 : ret = fold_build_pointer_plus_loc (loc, ptrop, intop);
3478 :
3479 33994 : fold_undefer_and_ignore_overflow_warnings ();
3480 :
3481 33994 : return ret;
3482 : }
3483 :
3484 : /* Convert the integer argument to a type the same size as sizetype
3485 : so the multiply won't overflow spuriously. */
3486 6608924 : if (TYPE_PRECISION (TREE_TYPE (intop)) != TYPE_PRECISION (sizetype)
3487 6608924 : || TYPE_UNSIGNED (TREE_TYPE (intop)) != TYPE_UNSIGNED (sizetype))
3488 4514563 : intop = convert (c_common_type_for_size (TYPE_PRECISION (sizetype),
3489 4514563 : TYPE_UNSIGNED (sizetype)), intop);
3490 :
3491 : /* Replace the integer argument with a suitable product by the object size.
3492 : Do this multiplication as signed, then convert to the appropriate type
3493 : for the pointer operation and disregard an overflow that occurred only
3494 : because of the sign-extension change in the latter conversion. */
3495 6608924 : {
3496 6608924 : tree t = fold_build2_loc (loc, MULT_EXPR, TREE_TYPE (intop), intop,
3497 6608924 : convert (TREE_TYPE (intop), size_exp));
3498 6608924 : intop = convert (sizetype, t);
3499 6608924 : if (TREE_OVERFLOW_P (intop) && !TREE_OVERFLOW (t))
3500 0 : intop = wide_int_to_tree (TREE_TYPE (intop), wi::to_wide (intop));
3501 : }
3502 :
3503 : /* Create the sum or difference. */
3504 6608924 : if (resultcode == MINUS_EXPR)
3505 317784 : intop = fold_build1_loc (loc, NEGATE_EXPR, sizetype, intop);
3506 :
3507 6608924 : ret = fold_build_pointer_plus_loc (loc, ptrop, intop);
3508 :
3509 6608924 : fold_undefer_and_ignore_overflow_warnings ();
3510 :
3511 6608924 : return ret;
3512 : }
3513 :
3514 : /* Wrap a C_MAYBE_CONST_EXPR around an expression that is fully folded
3515 : and if NON_CONST is known not to be permitted in an evaluated part
3516 : of a constant expression. */
3517 :
3518 : tree
3519 4494091 : c_wrap_maybe_const (tree expr, bool non_const)
3520 : {
3521 4494091 : location_t loc = EXPR_LOCATION (expr);
3522 :
3523 : /* This should never be called for C++. */
3524 4494091 : if (c_dialect_cxx ())
3525 0 : gcc_unreachable ();
3526 :
3527 : /* The result of folding may have a NOP_EXPR to set TREE_NO_WARNING. */
3528 4494837 : STRIP_TYPE_NOPS (expr);
3529 4494091 : expr = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (expr), NULL, expr);
3530 4494091 : C_MAYBE_CONST_EXPR_NON_CONST (expr) = non_const;
3531 4494091 : protected_set_expr_location (expr, loc);
3532 :
3533 4494091 : return expr;
3534 : }
3535 :
3536 : /* Return whether EXPR is a declaration whose address can never be NULL.
3537 : The address of the first struct member could be NULL only if it were
3538 : accessed through a NULL pointer, and such an access would be invalid.
3539 : The address of a weak symbol may be null unless it has a definition. */
3540 :
3541 : bool
3542 1413 : decl_with_nonnull_addr_p (const_tree expr)
3543 : {
3544 1413 : if (!DECL_P (expr))
3545 : return false;
3546 :
3547 1159 : if (TREE_CODE (expr) == FIELD_DECL
3548 1082 : || TREE_CODE (expr) == PARM_DECL
3549 1048 : || TREE_CODE (expr) == LABEL_DECL)
3550 : return true;
3551 :
3552 1023 : if (!VAR_OR_FUNCTION_DECL_P (expr))
3553 : return false;
3554 :
3555 1023 : if (!DECL_WEAK (expr))
3556 : /* Ordinary (non-weak) symbols have nonnull addresses. */
3557 : return true;
3558 :
3559 532 : if (DECL_INITIAL (expr) && DECL_INITIAL (expr) != error_mark_node)
3560 : /* Initialized weak symbols have nonnull addresses. */
3561 : return true;
3562 :
3563 479 : if (DECL_EXTERNAL (expr) || !TREE_STATIC (expr))
3564 : /* Uninitialized extern weak symbols and weak symbols with no
3565 : allocated storage might have a null address. */
3566 : return false;
3567 :
3568 43 : tree attribs = DECL_ATTRIBUTES (expr);
3569 43 : if (lookup_attribute ("weakref", attribs))
3570 : /* Weakref symbols might have a null address unless their referent
3571 : is known not to. Don't bother following weakref targets here. */
3572 : return false;
3573 :
3574 : return true;
3575 : }
3576 :
3577 : /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
3578 : or for an `if' or `while' statement or ?..: exp. It should already
3579 : have been validated to be of suitable type; otherwise, a bad
3580 : diagnostic may result.
3581 :
3582 : The EXPR is located at LOCATION.
3583 :
3584 : This preparation consists of taking the ordinary
3585 : representation of an expression expr and producing a valid tree
3586 : boolean expression describing whether expr is nonzero. We could
3587 : simply always do build_binary_op (NE_EXPR, expr, truthvalue_false_node, 1),
3588 : but we optimize comparisons, &&, ||, and !.
3589 :
3590 : The resulting type should always be `truthvalue_type_node'. */
3591 :
3592 : tree
3593 11004122 : c_common_truthvalue_conversion (location_t location, tree expr)
3594 : {
3595 11974433 : STRIP_ANY_LOCATION_WRAPPER (expr);
3596 11974433 : switch (TREE_CODE (expr))
3597 : {
3598 2406868 : case EQ_EXPR: case NE_EXPR: case UNEQ_EXPR: case LTGT_EXPR:
3599 2406868 : case LE_EXPR: case GE_EXPR: case LT_EXPR: case GT_EXPR:
3600 2406868 : case UNLE_EXPR: case UNGE_EXPR: case UNLT_EXPR: case UNGT_EXPR:
3601 2406868 : case ORDERED_EXPR: case UNORDERED_EXPR:
3602 2406868 : if (TREE_TYPE (expr) == truthvalue_type_node)
3603 : return expr;
3604 309979 : expr = build2 (TREE_CODE (expr), truthvalue_type_node,
3605 309979 : TREE_OPERAND (expr, 0), TREE_OPERAND (expr, 1));
3606 309979 : goto ret;
3607 :
3608 601389 : case TRUTH_ANDIF_EXPR:
3609 601389 : case TRUTH_ORIF_EXPR:
3610 601389 : case TRUTH_AND_EXPR:
3611 601389 : case TRUTH_OR_EXPR:
3612 601389 : case TRUTH_XOR_EXPR:
3613 601389 : if (TREE_TYPE (expr) == truthvalue_type_node)
3614 : return expr;
3615 74 : expr = build2 (TREE_CODE (expr), truthvalue_type_node,
3616 : c_common_truthvalue_conversion (location,
3617 37 : TREE_OPERAND (expr, 0)),
3618 : c_common_truthvalue_conversion (location,
3619 37 : TREE_OPERAND (expr, 1)));
3620 37 : goto ret;
3621 :
3622 245473 : case TRUTH_NOT_EXPR:
3623 245473 : if (TREE_TYPE (expr) == truthvalue_type_node)
3624 : return expr;
3625 242581 : expr = build1 (TREE_CODE (expr), truthvalue_type_node,
3626 : c_common_truthvalue_conversion (location,
3627 242581 : TREE_OPERAND (expr, 0)));
3628 242581 : goto ret;
3629 :
3630 : case ERROR_MARK:
3631 : return expr;
3632 :
3633 2559200 : case INTEGER_CST:
3634 2559200 : if (TREE_CODE (TREE_TYPE (expr)) == ENUMERAL_TYPE
3635 615043 : && !integer_zerop (expr)
3636 2936802 : && !integer_onep (expr))
3637 869 : warning_at (location, OPT_Wint_in_bool_context,
3638 : "enum constant in boolean context");
3639 2559200 : return integer_zerop (expr) ? truthvalue_false_node
3640 2559200 : : truthvalue_true_node;
3641 :
3642 1288 : case REAL_CST:
3643 1288 : return real_compare (NE_EXPR, &TREE_REAL_CST (expr), &dconst0)
3644 1288 : ? truthvalue_true_node
3645 1288 : : truthvalue_false_node;
3646 :
3647 0 : case FIXED_CST:
3648 0 : return fixed_compare (NE_EXPR, &TREE_FIXED_CST (expr),
3649 0 : &FCONST0 (TYPE_MODE (TREE_TYPE (expr))))
3650 0 : ? truthvalue_true_node
3651 0 : : truthvalue_false_node;
3652 :
3653 0 : case FUNCTION_DECL:
3654 0 : expr = build_unary_op (location, ADDR_EXPR, expr, false);
3655 : /* Fall through. */
3656 :
3657 582 : case ADDR_EXPR:
3658 582 : {
3659 582 : tree inner = TREE_OPERAND (expr, 0);
3660 582 : if (decl_with_nonnull_addr_p (inner)
3661 : /* Check both EXPR and INNER for suppression. */
3662 127 : && !warning_suppressed_p (expr, OPT_Waddress)
3663 695 : && !warning_suppressed_p (inner, OPT_Waddress))
3664 : {
3665 : /* Common Ada programmer's mistake. */
3666 107 : warning_at (location,
3667 107 : OPT_Waddress,
3668 : "the address of %qD will always evaluate as %<true%>",
3669 : inner);
3670 107 : suppress_warning (inner, OPT_Waddress);
3671 107 : return truthvalue_true_node;
3672 : }
3673 : break;
3674 : }
3675 :
3676 578 : case COMPLEX_EXPR:
3677 1734 : expr = build_binary_op (EXPR_LOCATION (expr),
3678 578 : (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1))
3679 : ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR),
3680 : c_common_truthvalue_conversion (location,
3681 578 : TREE_OPERAND (expr, 0)),
3682 : c_common_truthvalue_conversion (location,
3683 578 : TREE_OPERAND (expr, 1)),
3684 : false);
3685 578 : goto ret;
3686 :
3687 74 : case NEGATE_EXPR:
3688 74 : case ABS_EXPR:
3689 74 : case ABSU_EXPR:
3690 74 : case FLOAT_EXPR:
3691 74 : case EXCESS_PRECISION_EXPR:
3692 : /* These don't change whether an object is nonzero or zero. */
3693 74 : return c_common_truthvalue_conversion (location, TREE_OPERAND (expr, 0));
3694 :
3695 0 : case LROTATE_EXPR:
3696 0 : case RROTATE_EXPR:
3697 : /* These don't change whether an object is zero or nonzero, but
3698 : we can't ignore them if their second arg has side-effects. */
3699 0 : if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1)))
3700 : {
3701 0 : expr = build2 (COMPOUND_EXPR, truthvalue_type_node,
3702 0 : TREE_OPERAND (expr, 1),
3703 : c_common_truthvalue_conversion
3704 0 : (location, TREE_OPERAND (expr, 0)));
3705 0 : goto ret;
3706 : }
3707 : else
3708 0 : return c_common_truthvalue_conversion (location,
3709 0 : TREE_OPERAND (expr, 0));
3710 :
3711 502 : case MULT_EXPR:
3712 502 : warning_at (EXPR_LOCATION (expr), OPT_Wint_in_bool_context,
3713 : "%<*%> in boolean context, suggest %<&&%> instead");
3714 502 : break;
3715 :
3716 166 : case LSHIFT_EXPR:
3717 : /* We will only warn on signed shifts here, because the majority of
3718 : false positive warnings happen in code where unsigned arithmetic
3719 : was used in anticipation of a possible overflow.
3720 : Furthermore, if we see an unsigned type here we know that the
3721 : result of the shift is not subject to integer promotion rules. */
3722 166 : if ((TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE
3723 1 : || TREE_CODE (TREE_TYPE (expr)) == BITINT_TYPE)
3724 167 : && !TYPE_UNSIGNED (TREE_TYPE (expr)))
3725 150 : warning_at (EXPR_LOCATION (expr), OPT_Wint_in_bool_context,
3726 : "%<<<%> in boolean context, did you mean %<<%>?");
3727 : break;
3728 :
3729 58973 : case COND_EXPR:
3730 58973 : if (warn_int_in_bool_context
3731 60665 : && !from_macro_definition_at (EXPR_LOCATION (expr)))
3732 : {
3733 925 : tree val1 = fold_for_warn (TREE_OPERAND (expr, 1));
3734 925 : tree val2 = fold_for_warn (TREE_OPERAND (expr, 2));
3735 925 : if (TREE_CODE (val1) == INTEGER_CST
3736 82 : && TREE_CODE (val2) == INTEGER_CST
3737 82 : && !integer_zerop (val1)
3738 74 : && !integer_zerop (val2)
3739 941 : && (!integer_onep (val1)
3740 12 : || !integer_onep (val2)))
3741 12 : warning_at (EXPR_LOCATION (expr), OPT_Wint_in_bool_context,
3742 : "%<?:%> using integer constants in boolean context, "
3743 : "the expression will always evaluate to %<true%>");
3744 913 : else if ((TREE_CODE (val1) == INTEGER_CST
3745 70 : && !integer_zerop (val1)
3746 62 : && !integer_onep (val1))
3747 983 : || (TREE_CODE (val2) == INTEGER_CST
3748 336 : && !integer_zerop (val2)
3749 274 : && !integer_onep (val2)))
3750 4 : warning_at (EXPR_LOCATION (expr), OPT_Wint_in_bool_context,
3751 : "%<?:%> using integer constants in boolean context");
3752 : }
3753 : /* Distribute the conversion into the arms of a COND_EXPR. */
3754 58973 : if (c_dialect_cxx ())
3755 : /* Avoid premature folding. */
3756 : break;
3757 : else
3758 : {
3759 21743 : int w = warn_int_in_bool_context;
3760 21743 : warn_int_in_bool_context = 0;
3761 : /* Folding will happen later for C. */
3762 65229 : expr = build3 (COND_EXPR, truthvalue_type_node,
3763 21743 : TREE_OPERAND (expr, 0),
3764 : c_common_truthvalue_conversion (location,
3765 21743 : TREE_OPERAND (expr, 1)),
3766 : c_common_truthvalue_conversion (location,
3767 21743 : TREE_OPERAND (expr, 2)));
3768 21743 : warn_int_in_bool_context = w;
3769 21743 : goto ret;
3770 : }
3771 :
3772 833416 : CASE_CONVERT:
3773 833416 : {
3774 833416 : tree totype = TREE_TYPE (expr);
3775 833416 : tree fromtype = TREE_TYPE (TREE_OPERAND (expr, 0));
3776 :
3777 833416 : if (POINTER_TYPE_P (totype)
3778 2024 : && !c_inhibit_evaluation_warnings
3779 1856 : && TREE_CODE (fromtype) == REFERENCE_TYPE)
3780 : {
3781 0 : tree inner = expr;
3782 0 : STRIP_NOPS (inner);
3783 :
3784 0 : if (DECL_P (inner))
3785 0 : warning_at (location,
3786 0 : OPT_Waddress,
3787 : "the compiler can assume that the address of "
3788 : "%qD will always evaluate to %<true%>",
3789 : inner);
3790 : }
3791 :
3792 : /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
3793 : since that affects how `default_conversion' will behave. */
3794 833416 : if (TREE_CODE (totype) == REFERENCE_TYPE
3795 833416 : || TREE_CODE (fromtype) == REFERENCE_TYPE)
3796 : break;
3797 : /* Don't strip a conversion from C++0x scoped enum, since they
3798 : don't implicitly convert to other types. */
3799 833416 : if (TREE_CODE (fromtype) == ENUMERAL_TYPE
3800 833416 : && ENUM_IS_SCOPED (fromtype))
3801 : break;
3802 : /* If this isn't narrowing the argument, we can ignore it. */
3803 833307 : if (TYPE_PRECISION (totype) >= TYPE_PRECISION (fromtype))
3804 : {
3805 815989 : tree op0 = TREE_OPERAND (expr, 0);
3806 815989 : if ((TREE_CODE (fromtype) == POINTER_TYPE
3807 1940 : && (TREE_CODE (totype) == INTEGER_TYPE
3808 1940 : || TREE_CODE (totype) == BITINT_TYPE))
3809 817897 : || warning_suppressed_p (expr, OPT_Waddress))
3810 : /* Suppress -Waddress for casts to intptr_t, propagating
3811 : any suppression from the enclosing expression to its
3812 : operand. */
3813 44 : suppress_warning (op0, OPT_Waddress);
3814 815989 : return c_common_truthvalue_conversion (location, op0);
3815 : }
3816 : }
3817 : break;
3818 :
3819 9033 : case MODIFY_EXPR:
3820 9033 : if (!warning_suppressed_p (expr, OPT_Wparentheses)
3821 269 : && warn_parentheses
3822 9302 : && warning_at (location, OPT_Wparentheses,
3823 : "suggest parentheses around assignment used as "
3824 : "truth value"))
3825 14 : suppress_warning (expr, OPT_Wparentheses);
3826 : break;
3827 :
3828 154317 : case CONST_DECL:
3829 154317 : {
3830 154317 : tree folded_expr = fold_for_warn (expr);
3831 154317 : if (folded_expr != expr)
3832 : return c_common_truthvalue_conversion (location, folded_expr);
3833 : }
3834 : break;
3835 :
3836 : default:
3837 : break;
3838 : }
3839 :
3840 5167253 : if (TREE_CODE (TREE_TYPE (expr)) == COMPLEX_TYPE)
3841 : {
3842 406 : tree t = save_expr (expr);
3843 406 : expr = (build_binary_op
3844 812 : (EXPR_LOCATION (expr),
3845 406 : (TREE_SIDE_EFFECTS (expr)
3846 : ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR),
3847 : c_common_truthvalue_conversion
3848 : (location,
3849 : build_unary_op (location, REALPART_EXPR, t, false)),
3850 : c_common_truthvalue_conversion
3851 : (location,
3852 : build_unary_op (location, IMAGPART_EXPR, t, false)),
3853 : false));
3854 406 : goto ret;
3855 : }
3856 :
3857 5166847 : if (FIXED_POINT_TYPE_P (TREE_TYPE (expr)))
3858 : {
3859 0 : tree fixed_zero_node = build_fixed (TREE_TYPE (expr),
3860 0 : FCONST0 (TYPE_MODE
3861 : (TREE_TYPE (expr))));
3862 0 : return build_binary_op (location, NE_EXPR, expr, fixed_zero_node, true);
3863 : }
3864 : else
3865 5166847 : return build_binary_op (location, NE_EXPR, expr, integer_zero_node, true);
3866 :
3867 575324 : ret:
3868 575324 : protected_set_expr_location (expr, location);
3869 575324 : return expr;
3870 : }
3871 :
3872 : static void def_builtin_1 (enum built_in_function fncode,
3873 : const char *name,
3874 : enum built_in_class fnclass,
3875 : tree fntype, tree libtype,
3876 : bool both_p, bool fallback_p, bool nonansi_p,
3877 : tree fnattrs, bool implicit_p);
3878 :
3879 :
3880 : /* Apply the TYPE_QUALS to the new DECL. */
3881 :
3882 : void
3883 1059362543 : c_apply_type_quals_to_decl (int type_quals, tree decl)
3884 : {
3885 1059362543 : tree type = TREE_TYPE (decl);
3886 :
3887 1059362543 : if (type == error_mark_node)
3888 : return;
3889 :
3890 1059362314 : if ((type_quals & TYPE_QUAL_CONST)
3891 669467409 : || (type && TREE_CODE (type) == REFERENCE_TYPE))
3892 : /* We used to check TYPE_NEEDS_CONSTRUCTING here, but now a constexpr
3893 : constructor can produce constant init, so rely on cp_finish_decl to
3894 : clear TREE_READONLY if the variable has non-constant init. */
3895 496821668 : TREE_READONLY (decl) = 1;
3896 1059362314 : if (type_quals & TYPE_QUAL_VOLATILE)
3897 : {
3898 134943 : TREE_SIDE_EFFECTS (decl) = 1;
3899 134943 : TREE_THIS_VOLATILE (decl) = 1;
3900 : }
3901 1059362314 : if (type_quals & TYPE_QUAL_RESTRICT)
3902 : {
3903 10811386 : while (type && TREE_CODE (type) == ARRAY_TYPE)
3904 : /* Allow 'restrict' on arrays of pointers.
3905 : FIXME currently we just ignore it. */
3906 7 : type = TREE_TYPE (type);
3907 10811379 : if (!type
3908 10811379 : || !POINTER_TYPE_P (type)
3909 21622755 : || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type)))
3910 4 : error ("invalid use of %<restrict%>");
3911 : }
3912 : }
3913 :
3914 : /* Return the typed-based alias set for T, which may be an expression
3915 : or a type. Return -1 if we don't do anything special. */
3916 :
3917 : alias_set_type
3918 564996010 : c_common_get_alias_set (tree t)
3919 : {
3920 : /* For VLAs, use the alias set of the element type rather than the
3921 : default of alias set 0 for types compared structurally. */
3922 564996010 : if (TYPE_P (t) && TYPE_STRUCTURAL_EQUALITY_P (t))
3923 : {
3924 896885 : if (TREE_CODE (t) == ARRAY_TYPE)
3925 461056 : return get_alias_set (TREE_TYPE (t));
3926 : return -1;
3927 : }
3928 :
3929 : /* That's all the expressions we handle specially. */
3930 564099125 : if (!TYPE_P (t))
3931 : return -1;
3932 :
3933 : /* Unlike char, char8_t doesn't alias in C++. (In C, char8_t is not
3934 : a distinct type.) */
3935 47806303 : if (flag_char8_t && t == char8_type_node && c_dialect_cxx ())
3936 : return -1;
3937 :
3938 : /* The C standard guarantees that any object may be accessed via an
3939 : lvalue that has narrow character type. */
3940 47806167 : if (t == char_type_node
3941 16402357 : || t == signed_char_type_node
3942 12740266 : || t == unsigned_char_type_node)
3943 : return 0;
3944 :
3945 : /* The C standard specifically allows aliasing between signed and
3946 : unsigned variants of the same type. We treat the signed
3947 : variant as canonical. */
3948 1863060 : if (TREE_CODE (t) == INTEGER_TYPE || TREE_CODE (t) == BITINT_TYPE)
3949 : {
3950 : /* For normal INTEGER_TYPEs (except ones built by
3951 : build_nonstandard_integer_type), both signed and unsigned variants
3952 : of the type are always reachable from GTY roots, so just calling
3953 : get_alias_set on the signed type is ok. For BITINT_TYPE and
3954 : non-standard INTEGER_TYPEs, only unsigned could be used and the
3955 : corresponding signed type could be created on demand and garbage
3956 : collected as unused, so the alias set of unsigned type could keep
3957 : changing.
3958 : Avoid that by remembering the signed type alias set in
3959 : TYPE_ALIAS_SET and also when being asked about !TYPE_UNSIGNED
3960 : check if there isn't a corresponding unsigned type with
3961 : TYPE_ALIAS_SET_KNOWN_P. */
3962 501755 : if (TYPE_UNSIGNED (t))
3963 : {
3964 : /* There is no signed _BitInt(1) before C2Y. */
3965 216077 : if (TREE_CODE (t) == BITINT_TYPE
3966 556 : && !flag_isoc2y
3967 216633 : && TYPE_PRECISION (t) == 1)
3968 : return -1;
3969 216070 : tree t1 = c_common_signed_type (t);
3970 216070 : gcc_checking_assert (t != t1);
3971 216070 : TYPE_ALIAS_SET (t) = get_alias_set (t1);
3972 216070 : return TYPE_ALIAS_SET (t);
3973 : }
3974 : else
3975 : {
3976 285678 : tree t1 = c_common_unsigned_type (t);
3977 285678 : gcc_checking_assert (t != t1);
3978 285678 : if (TYPE_ALIAS_SET_KNOWN_P (t1))
3979 : {
3980 303 : TYPE_ALIAS_SET (t) = TYPE_ALIAS_SET (t1);
3981 303 : return TYPE_ALIAS_SET (t);
3982 : }
3983 : }
3984 : }
3985 :
3986 : return -1;
3987 : }
3988 :
3989 : /* Compute the value of 'sizeof (TYPE)' or '__alignof__ (TYPE)', where
3990 : the IS_SIZEOF parameter indicates which operator is being applied.
3991 : The COMPLAIN flag controls whether we should diagnose possibly
3992 : ill-formed constructs or not. LOC is the location of the SIZEOF or
3993 : TYPEOF operator. If MIN_ALIGNOF, the least alignment required for
3994 : a type in any context should be returned, rather than the normal
3995 : alignment for that type. */
3996 :
3997 : tree
3998 22989008 : c_sizeof_or_alignof_type (location_t loc,
3999 : tree type, bool is_sizeof, bool min_alignof,
4000 : int complain)
4001 : {
4002 22989008 : const char *op_name;
4003 22989008 : tree value = NULL;
4004 22989008 : enum tree_code type_code = TREE_CODE (type);
4005 :
4006 22989008 : op_name = is_sizeof ? "sizeof" : "__alignof__";
4007 :
4008 22989008 : if (type_code == FUNCTION_TYPE)
4009 : {
4010 61 : if (is_sizeof)
4011 : {
4012 56 : if (complain && warn_pointer_arith)
4013 26 : pedwarn (loc, OPT_Wpointer_arith,
4014 : "invalid application of %<sizeof%> to a function type");
4015 : else if (!complain)
4016 20 : return error_mark_node;
4017 36 : value = size_one_node;
4018 : }
4019 : else
4020 : {
4021 5 : if (complain)
4022 : {
4023 5 : if (c_dialect_cxx ())
4024 3 : pedwarn (loc, OPT_Wpedantic, "ISO C++ does not permit "
4025 : "%<alignof%> applied to a function type");
4026 : else
4027 2 : pedwarn (loc, OPT_Wpedantic, "ISO C does not permit "
4028 : "%<_Alignof%> applied to a function type");
4029 : }
4030 5 : value = size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
4031 : }
4032 : }
4033 22988947 : else if (type_code == VOID_TYPE || type_code == ERROR_MARK)
4034 : {
4035 98 : if (type_code == VOID_TYPE
4036 98 : && complain && warn_pointer_arith)
4037 22 : pedwarn (loc, OPT_Wpointer_arith,
4038 : "invalid application of %qs to a void type", op_name);
4039 76 : else if (!complain)
4040 37 : return error_mark_node;
4041 61 : value = size_one_node;
4042 : }
4043 22988849 : else if (!COMPLETE_TYPE_P (type)
4044 22988849 : && ((!c_dialect_cxx () && !flag_isoc2y)
4045 : || is_sizeof
4046 148 : || type_code != ARRAY_TYPE))
4047 : {
4048 275 : if (complain)
4049 192 : error_at (loc, "invalid application of %qs to incomplete type %qT",
4050 : op_name, type);
4051 275 : return error_mark_node;
4052 : }
4053 22296403 : else if (c_dialect_cxx () && type_code == ARRAY_TYPE
4054 23254928 : && !COMPLETE_TYPE_P (TREE_TYPE (type)))
4055 : {
4056 0 : if (complain)
4057 0 : error_at (loc, "invalid application of %qs to array type %qT of "
4058 : "incomplete element type", op_name, type);
4059 0 : return error_mark_node;
4060 : }
4061 23906749 : else if (!verify_type_context (loc, is_sizeof ? TCTX_SIZEOF : TCTX_ALIGNOF,
4062 : type, !complain))
4063 : {
4064 0 : if (!complain)
4065 0 : return error_mark_node;
4066 0 : value = size_one_node;
4067 : }
4068 : else
4069 : {
4070 22988574 : if (is_sizeof)
4071 : /* Convert in case a char is more than one unit. */
4072 22070399 : value = size_binop_loc (loc, CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
4073 22070399 : size_int (TYPE_PRECISION (char_type_node)
4074 : / BITS_PER_UNIT));
4075 918175 : else if (min_alignof)
4076 698658 : value = size_int (min_align_of_type (type));
4077 : else
4078 219517 : value = size_int (TYPE_ALIGN_UNIT (type));
4079 : }
4080 :
4081 : /* VALUE will have the middle-end integer type sizetype.
4082 : However, we should really return a value of type `size_t',
4083 : which is just a typedef for an ordinary integer type. */
4084 22988676 : value = fold_convert_loc (loc, size_type_node, value);
4085 :
4086 22988676 : return value;
4087 : }
4088 :
4089 : /* Implement the __alignof keyword: Return the minimum required
4090 : alignment of EXPR, measured in bytes. For VAR_DECLs,
4091 : FUNCTION_DECLs and FIELD_DECLs return DECL_ALIGN (which can be set
4092 : from an "aligned" __attribute__ specification). LOC is the
4093 : location of the ALIGNOF operator. */
4094 :
4095 : tree
4096 40801 : c_alignof_expr (location_t loc, tree expr)
4097 : {
4098 40801 : tree t;
4099 :
4100 40801 : if (!verify_type_context (loc, TCTX_ALIGNOF, TREE_TYPE (expr)))
4101 0 : t = size_one_node;
4102 :
4103 40801 : else if (VAR_OR_FUNCTION_DECL_P (expr))
4104 7245 : t = size_int (DECL_ALIGN_UNIT (expr));
4105 :
4106 33556 : else if (TREE_CODE (expr) == COMPONENT_REF
4107 33556 : && DECL_C_BIT_FIELD (TREE_OPERAND (expr, 1)))
4108 : {
4109 1 : error_at (loc, "%<__alignof%> applied to a bit-field");
4110 1 : t = size_one_node;
4111 : }
4112 33555 : else if (TREE_CODE (expr) == COMPONENT_REF
4113 33555 : && TREE_CODE (TREE_OPERAND (expr, 1)) == FIELD_DECL)
4114 17577 : t = size_int (DECL_ALIGN_UNIT (TREE_OPERAND (expr, 1)));
4115 :
4116 15978 : else if (INDIRECT_REF_P (expr))
4117 : {
4118 57 : tree t = TREE_OPERAND (expr, 0);
4119 57 : tree best = t;
4120 57 : int bestalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
4121 :
4122 57 : while (CONVERT_EXPR_P (t)
4123 57 : && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == POINTER_TYPE)
4124 : {
4125 0 : int thisalign;
4126 :
4127 0 : t = TREE_OPERAND (t, 0);
4128 0 : thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
4129 0 : if (thisalign > bestalign)
4130 0 : best = t, bestalign = thisalign;
4131 : }
4132 57 : return c_alignof (loc, TREE_TYPE (TREE_TYPE (best)));
4133 : }
4134 : else
4135 15921 : return c_alignof (loc, TREE_TYPE (expr));
4136 :
4137 24823 : return fold_convert_loc (loc, size_type_node, t);
4138 : }
4139 :
4140 : /* Implement the _Countof keyword:
4141 : Return the number of elements of an array. */
4142 :
4143 : tree
4144 71 : c_countof_type (location_t loc, tree type)
4145 : {
4146 71 : enum tree_code type_code;
4147 71 : tree value;
4148 :
4149 71 : type_code = TREE_CODE (type);
4150 71 : if (type_code != ARRAY_TYPE)
4151 : {
4152 11 : error_at (loc, "invalid application of %<_Countof%> to type %qT", type);
4153 11 : return error_mark_node;
4154 : }
4155 60 : if (!COMPLETE_TYPE_P (type))
4156 : {
4157 2 : error_at (loc,
4158 : "invalid application of %<_Countof%> to incomplete type %qT",
4159 : type);
4160 2 : return error_mark_node;
4161 : }
4162 :
4163 58 : value = array_type_nelts_top (type);
4164 : /* VALUE will have the middle-end integer type sizetype.
4165 : However, we should really return a value of type `size_t',
4166 : which is just a typedef for an ordinary integer type. */
4167 58 : value = fold_convert_loc (loc, size_type_node, value);
4168 58 : return value;
4169 : }
4170 :
4171 : /* Implement the _Maxof operator:
4172 : Return the maximum representable value of an integer type. */
4173 :
4174 : tree
4175 46 : c_maxof_type (location_t loc, tree type)
4176 : {
4177 46 : if (!INTEGRAL_TYPE_P (type))
4178 : {
4179 3 : error_at (loc, "invalid application of %<_Maxof%> to type %qT", type);
4180 3 : return error_mark_node;
4181 : }
4182 43 : if (!COMPLETE_TYPE_P (type))
4183 : {
4184 1 : error_at (loc, "invalid application of %<_Maxof%> to incomplete type %qT",
4185 : type);
4186 1 : return error_mark_node;
4187 : }
4188 :
4189 42 : return TYPE_MAX_VALUE (type);
4190 : }
4191 :
4192 : /* Implement the _Minof operator:
4193 : Return the minimum representable value of an integer type. */
4194 :
4195 : tree
4196 46 : c_minof_type (location_t loc, tree type)
4197 : {
4198 46 : if (!INTEGRAL_TYPE_P (type))
4199 : {
4200 3 : error_at (loc, "invalid application of %<_Minof%> to type %qT", type);
4201 3 : return error_mark_node;
4202 : }
4203 43 : if (!COMPLETE_TYPE_P (type))
4204 : {
4205 1 : error_at (loc, "invalid application of %<_Minof%> to incomplete type %qT",
4206 : type);
4207 1 : return error_mark_node;
4208 : }
4209 :
4210 42 : return TYPE_MIN_VALUE (type);
4211 : }
4212 :
4213 : /* Handle C and C++ default attributes. */
4214 :
4215 : enum built_in_attribute
4216 : {
4217 : #define DEF_ATTR_NULL_TREE(ENUM) ENUM,
4218 : #define DEF_ATTR_INT(ENUM, VALUE) ENUM,
4219 : #define DEF_ATTR_STRING(ENUM, VALUE) ENUM,
4220 : #define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
4221 : #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
4222 : #include "builtin-attrs.def"
4223 : #undef DEF_ATTR_NULL_TREE
4224 : #undef DEF_ATTR_INT
4225 : #undef DEF_ATTR_STRING
4226 : #undef DEF_ATTR_IDENT
4227 : #undef DEF_ATTR_TREE_LIST
4228 : ATTR_LAST
4229 : };
4230 :
4231 : static GTY(()) tree built_in_attributes[(int) ATTR_LAST];
4232 :
4233 : static void c_init_attributes (void);
4234 :
4235 : enum c_builtin_type
4236 : {
4237 : #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
4238 : #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
4239 : #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
4240 : #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
4241 : #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
4242 : #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
4243 : #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
4244 : #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4245 : ARG6) NAME,
4246 : #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4247 : ARG6, ARG7) NAME,
4248 : #define DEF_FUNCTION_TYPE_8(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4249 : ARG6, ARG7, ARG8) NAME,
4250 : #define DEF_FUNCTION_TYPE_9(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4251 : ARG6, ARG7, ARG8, ARG9) NAME,
4252 : #define DEF_FUNCTION_TYPE_10(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4253 : ARG6, ARG7, ARG8, ARG9, ARG10) NAME,
4254 : #define DEF_FUNCTION_TYPE_11(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4255 : ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) NAME,
4256 : #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
4257 : #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
4258 : #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
4259 : #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
4260 : #define DEF_FUNCTION_TYPE_VAR_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
4261 : #define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
4262 : NAME,
4263 : #define DEF_FUNCTION_TYPE_VAR_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4264 : ARG6) NAME,
4265 : #define DEF_FUNCTION_TYPE_VAR_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4266 : ARG6, ARG7) NAME,
4267 : #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
4268 : #include "builtin-types.def"
4269 : #undef DEF_PRIMITIVE_TYPE
4270 : #undef DEF_FUNCTION_TYPE_0
4271 : #undef DEF_FUNCTION_TYPE_1
4272 : #undef DEF_FUNCTION_TYPE_2
4273 : #undef DEF_FUNCTION_TYPE_3
4274 : #undef DEF_FUNCTION_TYPE_4
4275 : #undef DEF_FUNCTION_TYPE_5
4276 : #undef DEF_FUNCTION_TYPE_6
4277 : #undef DEF_FUNCTION_TYPE_7
4278 : #undef DEF_FUNCTION_TYPE_8
4279 : #undef DEF_FUNCTION_TYPE_9
4280 : #undef DEF_FUNCTION_TYPE_10
4281 : #undef DEF_FUNCTION_TYPE_11
4282 : #undef DEF_FUNCTION_TYPE_VAR_0
4283 : #undef DEF_FUNCTION_TYPE_VAR_1
4284 : #undef DEF_FUNCTION_TYPE_VAR_2
4285 : #undef DEF_FUNCTION_TYPE_VAR_3
4286 : #undef DEF_FUNCTION_TYPE_VAR_4
4287 : #undef DEF_FUNCTION_TYPE_VAR_5
4288 : #undef DEF_FUNCTION_TYPE_VAR_6
4289 : #undef DEF_FUNCTION_TYPE_VAR_7
4290 : #undef DEF_POINTER_TYPE
4291 : BT_LAST
4292 : };
4293 :
4294 : typedef enum c_builtin_type builtin_type;
4295 :
4296 : /* A temporary array for c_common_nodes_and_builtins. Used in
4297 : communication with def_fn_type. */
4298 : static tree builtin_types[(int) BT_LAST + 1];
4299 :
4300 : /* A helper function for c_common_nodes_and_builtins. Build function type
4301 : for DEF with return type RET and N arguments. If VAR is true, then the
4302 : function should be variadic after those N arguments, or, if N is zero,
4303 : unprototyped.
4304 :
4305 : Takes special care not to ICE if any of the types involved are
4306 : error_mark_node, which indicates that said type is not in fact available
4307 : (see builtin_type_for_size). In which case the function type as a whole
4308 : should be error_mark_node. */
4309 :
4310 : static void
4311 105638904 : def_fn_type (builtin_type def, builtin_type ret, bool var, int n, ...)
4312 : {
4313 105638904 : tree t;
4314 105638904 : tree *args = XALLOCAVEC (tree, n);
4315 105638904 : va_list list;
4316 105638904 : int i;
4317 :
4318 105638904 : va_start (list, n);
4319 334635957 : for (i = 0; i < n; ++i)
4320 : {
4321 231979887 : builtin_type a = (builtin_type) va_arg (list, int);
4322 231979887 : t = builtin_types[a];
4323 231979887 : if (t == error_mark_node)
4324 2982834 : goto egress;
4325 228997053 : args[i] = t;
4326 : }
4327 :
4328 102656070 : t = builtin_types[ret];
4329 102656070 : if (t == error_mark_node)
4330 424582 : goto egress;
4331 102231488 : if (var)
4332 6282650 : if (n == 0)
4333 838404 : t = build_function_type (t, NULL_TREE);
4334 : else
4335 5444246 : t = build_varargs_function_type_array (t, n, args);
4336 : else
4337 95948838 : t = build_function_type_array (t, n, args);
4338 :
4339 105638904 : egress:
4340 105638904 : builtin_types[def] = t;
4341 105638904 : va_end (list);
4342 105638904 : }
4343 :
4344 : /* Build builtin functions common to both C and C++ language
4345 : frontends. */
4346 :
4347 : static void
4348 209601 : c_define_builtins (tree va_list_ref_type_node, tree va_list_arg_type_node)
4349 : {
4350 : #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
4351 : builtin_types[ENUM] = VALUE;
4352 : #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
4353 : def_fn_type (ENUM, RETURN, 0, 0);
4354 : #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
4355 : def_fn_type (ENUM, RETURN, 0, 1, ARG1);
4356 : #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
4357 : def_fn_type (ENUM, RETURN, 0, 2, ARG1, ARG2);
4358 : #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
4359 : def_fn_type (ENUM, RETURN, 0, 3, ARG1, ARG2, ARG3);
4360 : #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
4361 : def_fn_type (ENUM, RETURN, 0, 4, ARG1, ARG2, ARG3, ARG4);
4362 : #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
4363 : def_fn_type (ENUM, RETURN, 0, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
4364 : #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4365 : ARG6) \
4366 : def_fn_type (ENUM, RETURN, 0, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
4367 : #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4368 : ARG6, ARG7) \
4369 : def_fn_type (ENUM, RETURN, 0, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
4370 : #define DEF_FUNCTION_TYPE_8(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4371 : ARG6, ARG7, ARG8) \
4372 : def_fn_type (ENUM, RETURN, 0, 8, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
4373 : ARG7, ARG8);
4374 : #define DEF_FUNCTION_TYPE_9(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4375 : ARG6, ARG7, ARG8, ARG9) \
4376 : def_fn_type (ENUM, RETURN, 0, 9, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
4377 : ARG7, ARG8, ARG9);
4378 : #define DEF_FUNCTION_TYPE_10(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4379 : ARG6, ARG7, ARG8, ARG9, ARG10) \
4380 : def_fn_type (ENUM, RETURN, 0, 10, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
4381 : ARG7, ARG8, ARG9, ARG10);
4382 : #define DEF_FUNCTION_TYPE_11(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4383 : ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) \
4384 : def_fn_type (ENUM, RETURN, 0, 11, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
4385 : ARG7, ARG8, ARG9, ARG10, ARG11);
4386 : #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
4387 : def_fn_type (ENUM, RETURN, 1, 0);
4388 : #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
4389 : def_fn_type (ENUM, RETURN, 1, 1, ARG1);
4390 : #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
4391 : def_fn_type (ENUM, RETURN, 1, 2, ARG1, ARG2);
4392 : #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
4393 : def_fn_type (ENUM, RETURN, 1, 3, ARG1, ARG2, ARG3);
4394 : #define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
4395 : def_fn_type (ENUM, RETURN, 1, 4, ARG1, ARG2, ARG3, ARG4);
4396 : #define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
4397 : def_fn_type (ENUM, RETURN, 1, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
4398 : #define DEF_FUNCTION_TYPE_VAR_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4399 : ARG6) \
4400 : def_fn_type (ENUM, RETURN, 1, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
4401 : #define DEF_FUNCTION_TYPE_VAR_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4402 : ARG6, ARG7) \
4403 : def_fn_type (ENUM, RETURN, 1, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
4404 : #define DEF_POINTER_TYPE(ENUM, TYPE) \
4405 : builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]);
4406 :
4407 : #include "builtin-types.def"
4408 :
4409 : #undef DEF_PRIMITIVE_TYPE
4410 : #undef DEF_FUNCTION_TYPE_0
4411 : #undef DEF_FUNCTION_TYPE_1
4412 : #undef DEF_FUNCTION_TYPE_2
4413 : #undef DEF_FUNCTION_TYPE_3
4414 : #undef DEF_FUNCTION_TYPE_4
4415 : #undef DEF_FUNCTION_TYPE_5
4416 : #undef DEF_FUNCTION_TYPE_6
4417 : #undef DEF_FUNCTION_TYPE_7
4418 : #undef DEF_FUNCTION_TYPE_8
4419 : #undef DEF_FUNCTION_TYPE_9
4420 : #undef DEF_FUNCTION_TYPE_10
4421 : #undef DEF_FUNCTION_TYPE_11
4422 : #undef DEF_FUNCTION_TYPE_VAR_0
4423 : #undef DEF_FUNCTION_TYPE_VAR_1
4424 : #undef DEF_FUNCTION_TYPE_VAR_2
4425 : #undef DEF_FUNCTION_TYPE_VAR_3
4426 : #undef DEF_FUNCTION_TYPE_VAR_4
4427 : #undef DEF_FUNCTION_TYPE_VAR_5
4428 : #undef DEF_FUNCTION_TYPE_VAR_6
4429 : #undef DEF_FUNCTION_TYPE_VAR_7
4430 : #undef DEF_POINTER_TYPE
4431 209601 : builtin_types[(int) BT_LAST] = NULL_TREE;
4432 :
4433 209601 : c_init_attributes ();
4434 :
4435 : #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P, \
4436 : NONANSI_P, ATTRS, IMPLICIT, COND) \
4437 : if (NAME && COND) \
4438 : def_builtin_1 (ENUM, NAME, CLASS, \
4439 : builtin_types[(int) TYPE], \
4440 : builtin_types[(int) LIBTYPE], \
4441 : BOTH_P, FALLBACK_P, NONANSI_P, \
4442 : built_in_attributes[(int) ATTRS], IMPLICIT);
4443 : #include "builtins.def"
4444 :
4445 209601 : targetm.init_builtins ();
4446 :
4447 209601 : build_common_builtin_nodes ();
4448 209601 : }
4449 :
4450 : /* Like get_identifier, but avoid warnings about null arguments when
4451 : the argument may be NULL for targets where GCC lacks stdint.h type
4452 : information. */
4453 :
4454 : static inline tree
4455 5659227 : c_get_ident (const char *id)
4456 : {
4457 2515212 : return get_identifier (id);
4458 : }
4459 :
4460 : /* Build tree nodes and builtin functions common to both C and C++ language
4461 : frontends. */
4462 :
4463 : void
4464 209601 : c_common_nodes_and_builtins (void)
4465 : {
4466 209601 : int char8_type_size;
4467 209601 : int char16_type_size;
4468 209601 : int char32_type_size;
4469 209601 : int wchar_type_size;
4470 209601 : tree array_domain_type;
4471 209601 : tree va_list_ref_type_node;
4472 209601 : tree va_list_arg_type_node;
4473 209601 : int i;
4474 :
4475 209601 : build_common_tree_nodes (flag_signed_char);
4476 :
4477 : /* Define `int' and `char' first so that dbx will output them first. */
4478 209601 : record_builtin_type (RID_INT, NULL, integer_type_node);
4479 209601 : record_builtin_type (RID_CHAR, "char", char_type_node);
4480 :
4481 : /* `signed' is the same as `int'. FIXME: the declarations of "signed",
4482 : "unsigned long", "long long unsigned" and "unsigned short" were in C++
4483 : but not C. Are the conditionals here needed? */
4484 209601 : if (c_dialect_cxx ())
4485 98396 : record_builtin_type (RID_SIGNED, NULL, integer_type_node);
4486 209601 : record_builtin_type (RID_LONG, "long int", long_integer_type_node);
4487 209601 : record_builtin_type (RID_UNSIGNED, "unsigned int", unsigned_type_node);
4488 209601 : record_builtin_type (RID_MAX, "long unsigned int",
4489 : long_unsigned_type_node);
4490 :
4491 419202 : for (i = 0; i < NUM_INT_N_ENTS; i ++)
4492 : {
4493 209601 : char name[25];
4494 :
4495 209601 : sprintf (name, "__int%d", int_n_data[i].bitsize);
4496 209601 : record_builtin_type ((enum rid)(RID_FIRST_INT_N + i), name,
4497 : int_n_trees[i].signed_type);
4498 209601 : sprintf (name, "__int%d__", int_n_data[i].bitsize);
4499 209601 : record_builtin_type ((enum rid)(RID_FIRST_INT_N + i), name,
4500 : int_n_trees[i].signed_type);
4501 419202 : ridpointers[RID_FIRST_INT_N + i]
4502 209601 : = DECL_NAME (TYPE_NAME (int_n_trees[i].signed_type));
4503 :
4504 209601 : sprintf (name, "__int%d unsigned", int_n_data[i].bitsize);
4505 209601 : record_builtin_type (RID_MAX, name, int_n_trees[i].unsigned_type);
4506 209601 : sprintf (name, "__int%d__ unsigned", int_n_data[i].bitsize);
4507 209601 : record_builtin_type (RID_MAX, name, int_n_trees[i].unsigned_type);
4508 : }
4509 :
4510 209601 : if (c_dialect_cxx ())
4511 98396 : record_builtin_type (RID_MAX, "unsigned long", long_unsigned_type_node);
4512 209601 : record_builtin_type (RID_MAX, "long long int",
4513 : long_long_integer_type_node);
4514 209601 : record_builtin_type (RID_MAX, "long long unsigned int",
4515 : long_long_unsigned_type_node);
4516 209601 : if (c_dialect_cxx ())
4517 98396 : record_builtin_type (RID_MAX, "long long unsigned",
4518 : long_long_unsigned_type_node);
4519 209601 : record_builtin_type (RID_SHORT, "short int", short_integer_type_node);
4520 209601 : record_builtin_type (RID_MAX, "short unsigned int",
4521 : short_unsigned_type_node);
4522 209601 : if (c_dialect_cxx ())
4523 98396 : record_builtin_type (RID_MAX, "unsigned short",
4524 : short_unsigned_type_node);
4525 :
4526 : /* Define both `signed char' and `unsigned char'. */
4527 209601 : record_builtin_type (RID_MAX, "signed char", signed_char_type_node);
4528 209601 : record_builtin_type (RID_MAX, "unsigned char", unsigned_char_type_node);
4529 :
4530 : /* These are types that c_common_type_for_size and
4531 : c_common_type_for_mode use. */
4532 209601 : lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
4533 : TYPE_DECL, NULL_TREE,
4534 : intQI_type_node));
4535 209601 : lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
4536 : TYPE_DECL, NULL_TREE,
4537 : intHI_type_node));
4538 209601 : lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
4539 : TYPE_DECL, NULL_TREE,
4540 : intSI_type_node));
4541 209601 : lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
4542 : TYPE_DECL, NULL_TREE,
4543 : intDI_type_node));
4544 : #if HOST_BITS_PER_WIDE_INT >= 64
4545 : /* Note that this is different than the __int128 type that's part of
4546 : the generic __intN support. */
4547 209601 : if (targetm.scalar_mode_supported_p (TImode))
4548 204221 : lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
4549 : TYPE_DECL,
4550 : get_identifier ("__int128_t"),
4551 : intTI_type_node));
4552 : #endif
4553 209601 : lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
4554 : TYPE_DECL, NULL_TREE,
4555 : unsigned_intQI_type_node));
4556 209601 : lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
4557 : TYPE_DECL, NULL_TREE,
4558 : unsigned_intHI_type_node));
4559 209601 : lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
4560 : TYPE_DECL, NULL_TREE,
4561 : unsigned_intSI_type_node));
4562 209601 : lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
4563 : TYPE_DECL, NULL_TREE,
4564 : unsigned_intDI_type_node));
4565 : #if HOST_BITS_PER_WIDE_INT >= 64
4566 209601 : if (targetm.scalar_mode_supported_p (TImode))
4567 204221 : lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
4568 : TYPE_DECL,
4569 : get_identifier ("__uint128_t"),
4570 : unsigned_intTI_type_node));
4571 : #endif
4572 :
4573 : /* Create the widest literal types. */
4574 209601 : if (targetm.scalar_mode_supported_p (TImode))
4575 : {
4576 204221 : widest_integer_literal_type_node = intTI_type_node;
4577 204221 : widest_unsigned_literal_type_node = unsigned_intTI_type_node;
4578 : }
4579 : else
4580 : {
4581 5380 : widest_integer_literal_type_node = intDI_type_node;
4582 5380 : widest_unsigned_literal_type_node = unsigned_intDI_type_node;
4583 : }
4584 :
4585 209601 : signed_size_type_node = c_common_signed_type (size_type_node);
4586 :
4587 419202 : pid_type_node =
4588 209601 : TREE_TYPE (identifier_global_value (get_identifier (PID_TYPE)));
4589 :
4590 209601 : record_builtin_type (RID_FLOAT, NULL, float_type_node);
4591 209601 : record_builtin_type (RID_DOUBLE, NULL, double_type_node);
4592 209601 : record_builtin_type (RID_MAX, "long double", long_double_type_node);
4593 :
4594 1886409 : for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
4595 : {
4596 1467207 : if (FLOATN_NX_TYPE_NODE (i) != NULL_TREE)
4597 1257606 : record_builtin_type ((enum rid) (RID_FLOATN_NX_FIRST + i), NULL,
4598 : FLOATN_NX_TYPE_NODE (i));
4599 : }
4600 :
4601 : /* For C, let float128t_type_node (__float128 in some backends) be the
4602 : same type as float128_type_node (_Float128), for C++ let those
4603 : be distinct types that mangle and behave differently. */
4604 209601 : if (c_dialect_cxx ())
4605 98396 : float128t_type_node = NULL_TREE;
4606 :
4607 : /* Only supported decimal floating point extension if the target
4608 : actually supports underlying modes. */
4609 209601 : if (targetm.scalar_mode_supported_p (SDmode)
4610 209601 : && targetm.scalar_mode_supported_p (DDmode)
4611 419202 : && targetm.scalar_mode_supported_p (TDmode))
4612 : {
4613 209601 : record_builtin_type (RID_DFLOAT32, NULL, dfloat32_type_node);
4614 209601 : record_builtin_type (RID_DFLOAT64, NULL, dfloat64_type_node);
4615 209601 : record_builtin_type (RID_DFLOAT128, NULL, dfloat128_type_node);
4616 209601 : record_builtin_type (RID_DFLOAT64X, NULL, dfloat64x_type_node);
4617 : }
4618 :
4619 209601 : if (targetm.fixed_point_supported_p ())
4620 : {
4621 0 : record_builtin_type (RID_MAX, "short _Fract", short_fract_type_node);
4622 0 : record_builtin_type (RID_FRACT, NULL, fract_type_node);
4623 0 : record_builtin_type (RID_MAX, "long _Fract", long_fract_type_node);
4624 0 : record_builtin_type (RID_MAX, "long long _Fract",
4625 : long_long_fract_type_node);
4626 0 : record_builtin_type (RID_MAX, "unsigned short _Fract",
4627 : unsigned_short_fract_type_node);
4628 0 : record_builtin_type (RID_MAX, "unsigned _Fract",
4629 : unsigned_fract_type_node);
4630 0 : record_builtin_type (RID_MAX, "unsigned long _Fract",
4631 : unsigned_long_fract_type_node);
4632 0 : record_builtin_type (RID_MAX, "unsigned long long _Fract",
4633 : unsigned_long_long_fract_type_node);
4634 0 : record_builtin_type (RID_MAX, "_Sat short _Fract",
4635 : sat_short_fract_type_node);
4636 0 : record_builtin_type (RID_MAX, "_Sat _Fract", sat_fract_type_node);
4637 0 : record_builtin_type (RID_MAX, "_Sat long _Fract",
4638 : sat_long_fract_type_node);
4639 0 : record_builtin_type (RID_MAX, "_Sat long long _Fract",
4640 : sat_long_long_fract_type_node);
4641 0 : record_builtin_type (RID_MAX, "_Sat unsigned short _Fract",
4642 : sat_unsigned_short_fract_type_node);
4643 0 : record_builtin_type (RID_MAX, "_Sat unsigned _Fract",
4644 : sat_unsigned_fract_type_node);
4645 0 : record_builtin_type (RID_MAX, "_Sat unsigned long _Fract",
4646 : sat_unsigned_long_fract_type_node);
4647 0 : record_builtin_type (RID_MAX, "_Sat unsigned long long _Fract",
4648 : sat_unsigned_long_long_fract_type_node);
4649 0 : record_builtin_type (RID_MAX, "short _Accum", short_accum_type_node);
4650 0 : record_builtin_type (RID_ACCUM, NULL, accum_type_node);
4651 0 : record_builtin_type (RID_MAX, "long _Accum", long_accum_type_node);
4652 0 : record_builtin_type (RID_MAX, "long long _Accum",
4653 : long_long_accum_type_node);
4654 0 : record_builtin_type (RID_MAX, "unsigned short _Accum",
4655 : unsigned_short_accum_type_node);
4656 0 : record_builtin_type (RID_MAX, "unsigned _Accum",
4657 : unsigned_accum_type_node);
4658 0 : record_builtin_type (RID_MAX, "unsigned long _Accum",
4659 : unsigned_long_accum_type_node);
4660 0 : record_builtin_type (RID_MAX, "unsigned long long _Accum",
4661 : unsigned_long_long_accum_type_node);
4662 0 : record_builtin_type (RID_MAX, "_Sat short _Accum",
4663 : sat_short_accum_type_node);
4664 0 : record_builtin_type (RID_MAX, "_Sat _Accum", sat_accum_type_node);
4665 0 : record_builtin_type (RID_MAX, "_Sat long _Accum",
4666 : sat_long_accum_type_node);
4667 0 : record_builtin_type (RID_MAX, "_Sat long long _Accum",
4668 : sat_long_long_accum_type_node);
4669 0 : record_builtin_type (RID_MAX, "_Sat unsigned short _Accum",
4670 : sat_unsigned_short_accum_type_node);
4671 0 : record_builtin_type (RID_MAX, "_Sat unsigned _Accum",
4672 : sat_unsigned_accum_type_node);
4673 0 : record_builtin_type (RID_MAX, "_Sat unsigned long _Accum",
4674 : sat_unsigned_long_accum_type_node);
4675 0 : record_builtin_type (RID_MAX, "_Sat unsigned long long _Accum",
4676 : sat_unsigned_long_long_accum_type_node);
4677 :
4678 : }
4679 :
4680 209601 : lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
4681 : TYPE_DECL,
4682 : get_identifier ("complex int"),
4683 : complex_integer_type_node));
4684 209601 : lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
4685 : TYPE_DECL,
4686 : get_identifier ("complex float"),
4687 : complex_float_type_node));
4688 209601 : lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
4689 : TYPE_DECL,
4690 : get_identifier ("complex double"),
4691 : complex_double_type_node));
4692 209601 : lang_hooks.decls.pushdecl
4693 209601 : (build_decl (UNKNOWN_LOCATION,
4694 : TYPE_DECL, get_identifier ("complex long double"),
4695 : complex_long_double_type_node));
4696 :
4697 209601 : if (!c_dialect_cxx ())
4698 889640 : for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
4699 778435 : if (COMPLEX_FLOATN_NX_TYPE_NODE (i) != NULL_TREE)
4700 : {
4701 667230 : char buf[30];
4702 1334460 : sprintf (buf, "complex _Float%d%s", floatn_nx_types[i].n,
4703 667230 : floatn_nx_types[i].extended ? "x" : "");
4704 667230 : lang_hooks.decls.pushdecl
4705 667230 : (build_decl (UNKNOWN_LOCATION,
4706 : TYPE_DECL,
4707 : get_identifier (buf),
4708 : COMPLEX_FLOATN_NX_TYPE_NODE (i)));
4709 : }
4710 :
4711 : /* Make fileptr_type_node a distinct void * type until
4712 : FILE type is defined. Likewise for const struct tm*. */
4713 1467207 : for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
4714 1257606 : builtin_structptr_types[i].node
4715 1257606 : = build_variant_type_copy (builtin_structptr_types[i].base);
4716 :
4717 209601 : record_builtin_type (RID_VOID, NULL, void_type_node);
4718 :
4719 : /* Set the TYPE_NAME for any variants that were built before
4720 : record_builtin_type gave names to the built-in types. */
4721 209601 : {
4722 209601 : tree void_name = TYPE_NAME (void_type_node);
4723 209601 : TYPE_NAME (void_type_node) = NULL_TREE;
4724 209601 : TYPE_NAME (build_qualified_type (void_type_node, TYPE_QUAL_CONST))
4725 209601 : = void_name;
4726 209601 : TYPE_NAME (void_type_node) = void_name;
4727 : }
4728 :
4729 : /* Make a type to be the domain of a few array types
4730 : whose domains don't really matter.
4731 : 200 is small enough that it always fits in size_t
4732 : and large enough that it can hold most function names for the
4733 : initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
4734 209601 : array_domain_type = build_index_type (size_int (200));
4735 :
4736 : /* Make a type for arrays of characters.
4737 : With luck nothing will ever really depend on the length of this
4738 : array type. */
4739 209601 : char_array_type_node
4740 209601 : = build_array_type (char_type_node, array_domain_type);
4741 :
4742 209601 : string_type_node = build_pointer_type (char_type_node);
4743 209601 : const_string_type_node
4744 209601 : = build_pointer_type (build_qualified_type
4745 : (char_type_node, TYPE_QUAL_CONST));
4746 :
4747 : /* This is special for C++ so functions can be overloaded. */
4748 215077 : wchar_type_node = get_identifier (MODIFIED_WCHAR_TYPE);
4749 209601 : wchar_type_node = TREE_TYPE (identifier_global_value (wchar_type_node));
4750 209601 : wchar_type_size = TYPE_PRECISION (wchar_type_node);
4751 209601 : underlying_wchar_type_node = wchar_type_node;
4752 209601 : if (c_dialect_cxx ())
4753 : {
4754 98396 : if (TYPE_UNSIGNED (wchar_type_node))
4755 7 : wchar_type_node = make_unsigned_type (wchar_type_size);
4756 : else
4757 98389 : wchar_type_node = make_signed_type (wchar_type_size);
4758 98396 : record_builtin_type (RID_WCHAR, "wchar_t", wchar_type_node);
4759 : }
4760 :
4761 : /* This is for wide string constants. */
4762 209601 : wchar_array_type_node
4763 209601 : = build_array_type (wchar_type_node, array_domain_type);
4764 :
4765 : /* Define 'char8_t'. */
4766 209601 : char8_type_node = get_identifier (CHAR8_TYPE);
4767 209601 : char8_type_node = TREE_TYPE (identifier_global_value (char8_type_node));
4768 209601 : char8_type_size = TYPE_PRECISION (char8_type_node);
4769 209601 : if (c_dialect_cxx ())
4770 : {
4771 98396 : char8_type_node = make_unsigned_type (char8_type_size);
4772 98396 : TYPE_STRING_FLAG (char8_type_node) = true;
4773 :
4774 98396 : if (flag_char8_t)
4775 73095 : record_builtin_type (RID_CHAR8, "char8_t", char8_type_node);
4776 : }
4777 :
4778 : /* This is for UTF-8 string constants. */
4779 209601 : char8_array_type_node
4780 209601 : = build_array_type (char8_type_node, array_domain_type);
4781 :
4782 : /* Define 'char16_t'. */
4783 209601 : char16_type_node = get_identifier (CHAR16_TYPE);
4784 209601 : char16_type_node = TREE_TYPE (identifier_global_value (char16_type_node));
4785 209601 : char16_type_size = TYPE_PRECISION (char16_type_node);
4786 209601 : if (c_dialect_cxx ())
4787 : {
4788 98396 : char16_type_node = make_unsigned_type (char16_type_size);
4789 :
4790 98396 : if (cxx_dialect >= cxx11)
4791 84199 : record_builtin_type (RID_CHAR16, "char16_t", char16_type_node);
4792 : }
4793 :
4794 : /* This is for UTF-16 string constants. */
4795 209601 : char16_array_type_node
4796 209601 : = build_array_type (char16_type_node, array_domain_type);
4797 :
4798 : /* Define 'char32_t'. */
4799 209601 : char32_type_node = get_identifier (CHAR32_TYPE);
4800 209601 : char32_type_node = TREE_TYPE (identifier_global_value (char32_type_node));
4801 209601 : char32_type_size = TYPE_PRECISION (char32_type_node);
4802 209601 : if (c_dialect_cxx ())
4803 : {
4804 98396 : char32_type_node = make_unsigned_type (char32_type_size);
4805 :
4806 98396 : if (cxx_dialect >= cxx11)
4807 84199 : record_builtin_type (RID_CHAR32, "char32_t", char32_type_node);
4808 : }
4809 :
4810 : /* This is for UTF-32 string constants. */
4811 209601 : char32_array_type_node
4812 209601 : = build_array_type (char32_type_node, array_domain_type);
4813 :
4814 209601 : if (strcmp (WINT_TYPE, "wchar_t") == 0)
4815 : wint_type_node = wchar_type_node;
4816 : else
4817 419202 : wint_type_node =
4818 209601 : TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE)));
4819 :
4820 419202 : intmax_type_node =
4821 215077 : TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE)));
4822 419202 : uintmax_type_node =
4823 215077 : TREE_TYPE (identifier_global_value (get_identifier (UINTMAX_TYPE)));
4824 :
4825 209601 : if (SIG_ATOMIC_TYPE)
4826 209601 : sig_atomic_type_node =
4827 209601 : TREE_TYPE (identifier_global_value (c_get_ident (SIG_ATOMIC_TYPE)));
4828 209601 : if (INT8_TYPE)
4829 209601 : int8_type_node =
4830 209601 : TREE_TYPE (identifier_global_value (c_get_ident (INT8_TYPE)));
4831 209601 : if (INT16_TYPE)
4832 209601 : int16_type_node =
4833 209601 : TREE_TYPE (identifier_global_value (c_get_ident (INT16_TYPE)));
4834 209601 : if (INT32_TYPE)
4835 209601 : int32_type_node =
4836 209601 : TREE_TYPE (identifier_global_value (c_get_ident (INT32_TYPE)));
4837 209601 : if (INT64_TYPE)
4838 419202 : int64_type_node =
4839 419202 : TREE_TYPE (identifier_global_value (c_get_ident (INT64_TYPE)));
4840 209601 : if (UINT8_TYPE)
4841 209601 : uint8_type_node =
4842 209601 : TREE_TYPE (identifier_global_value (c_get_ident (UINT8_TYPE)));
4843 209601 : if (UINT16_TYPE)
4844 209601 : c_uint16_type_node = uint16_type_node =
4845 209601 : TREE_TYPE (identifier_global_value (c_get_ident (UINT16_TYPE)));
4846 209601 : if (UINT32_TYPE)
4847 209601 : c_uint32_type_node = uint32_type_node =
4848 209601 : TREE_TYPE (identifier_global_value (c_get_ident (UINT32_TYPE)));
4849 209601 : if (UINT64_TYPE)
4850 419202 : c_uint64_type_node = uint64_type_node =
4851 419202 : TREE_TYPE (identifier_global_value (c_get_ident (UINT64_TYPE)));
4852 209601 : if (INT_LEAST8_TYPE)
4853 209601 : int_least8_type_node =
4854 209601 : TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST8_TYPE)));
4855 209601 : if (INT_LEAST16_TYPE)
4856 209601 : int_least16_type_node =
4857 209601 : TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST16_TYPE)));
4858 209601 : if (INT_LEAST32_TYPE)
4859 209601 : int_least32_type_node =
4860 209601 : TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST32_TYPE)));
4861 209601 : if (INT_LEAST64_TYPE)
4862 419202 : int_least64_type_node =
4863 419202 : TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST64_TYPE)));
4864 209601 : if (UINT_LEAST8_TYPE)
4865 209601 : uint_least8_type_node =
4866 209601 : TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST8_TYPE)));
4867 209601 : if (UINT_LEAST16_TYPE)
4868 209601 : uint_least16_type_node =
4869 209601 : TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST16_TYPE)));
4870 209601 : if (UINT_LEAST32_TYPE)
4871 209601 : uint_least32_type_node =
4872 209601 : TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST32_TYPE)));
4873 209601 : if (UINT_LEAST64_TYPE)
4874 419202 : uint_least64_type_node =
4875 419202 : TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST64_TYPE)));
4876 209601 : if (INT_FAST8_TYPE)
4877 209601 : int_fast8_type_node =
4878 209601 : TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST8_TYPE)));
4879 209601 : if (INT_FAST16_TYPE)
4880 419202 : int_fast16_type_node =
4881 419202 : TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST16_TYPE)));
4882 209601 : if (INT_FAST32_TYPE)
4883 419202 : int_fast32_type_node =
4884 419202 : TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST32_TYPE)));
4885 209601 : if (INT_FAST64_TYPE)
4886 419202 : int_fast64_type_node =
4887 419202 : TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST64_TYPE)));
4888 209601 : if (UINT_FAST8_TYPE)
4889 209601 : uint_fast8_type_node =
4890 209601 : TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST8_TYPE)));
4891 209601 : if (UINT_FAST16_TYPE)
4892 419202 : uint_fast16_type_node =
4893 419202 : TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST16_TYPE)));
4894 209601 : if (UINT_FAST32_TYPE)
4895 419202 : uint_fast32_type_node =
4896 419202 : TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST32_TYPE)));
4897 209601 : if (UINT_FAST64_TYPE)
4898 419202 : uint_fast64_type_node =
4899 419202 : TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST64_TYPE)));
4900 209601 : if (INTPTR_TYPE)
4901 419202 : intptr_type_node =
4902 419202 : TREE_TYPE (identifier_global_value (c_get_ident (INTPTR_TYPE)));
4903 209601 : if (UINTPTR_TYPE)
4904 419202 : uintptr_type_node =
4905 419202 : TREE_TYPE (identifier_global_value (c_get_ident (UINTPTR_TYPE)));
4906 :
4907 209601 : default_function_type = build_function_type (integer_type_node, NULL_TREE);
4908 209601 : unsigned_ptrdiff_type_node = c_common_unsigned_type (ptrdiff_type_node);
4909 :
4910 209601 : lang_hooks.decls.pushdecl
4911 209601 : (build_decl (UNKNOWN_LOCATION,
4912 : TYPE_DECL, get_identifier ("__builtin_va_list"),
4913 : va_list_type_node));
4914 209601 : if (targetm.enum_va_list_p)
4915 : {
4916 : int l;
4917 : const char *pname;
4918 : tree ptype;
4919 :
4920 618043 : for (l = 0; targetm.enum_va_list_p (l, &pname, &ptype); ++l)
4921 : {
4922 408442 : lang_hooks.decls.pushdecl
4923 408442 : (build_decl (UNKNOWN_LOCATION,
4924 : TYPE_DECL, get_identifier (pname),
4925 : ptype));
4926 :
4927 : }
4928 : }
4929 :
4930 : /* Call the target stack_protect_guard hook if the stack protection
4931 : guard is declared as a global symbol. */
4932 209601 : if (targetm.stack_protect_guard_symbol_p ())
4933 41 : lang_hooks.decls.pushdecl (targetm.stack_protect_guard ());
4934 :
4935 209601 : if (TREE_CODE (va_list_type_node) == ARRAY_TYPE)
4936 : {
4937 408358 : va_list_arg_type_node = va_list_ref_type_node =
4938 204179 : build_pointer_type (TREE_TYPE (va_list_type_node));
4939 : }
4940 : else
4941 : {
4942 5422 : va_list_arg_type_node = va_list_type_node;
4943 5422 : va_list_ref_type_node = build_reference_type (va_list_type_node);
4944 : }
4945 :
4946 209601 : c_define_builtins (va_list_ref_type_node, va_list_arg_type_node);
4947 :
4948 209601 : main_identifier_node = get_identifier ("main");
4949 :
4950 : /* Create the built-in __null node. It is important that this is
4951 : not shared. */
4952 209601 : null_node = make_int_cst (1, 1);
4953 215077 : TREE_TYPE (null_node) = c_common_type_for_size (POINTER_SIZE, 0);
4954 :
4955 : /* Create the built-in nullptr node. This part of its initialization is
4956 : common to C and C++. The front ends can further adjust its definition
4957 : in {c,cxx}_init_decl_processing. In particular, we aren't setting the
4958 : alignment here for C++ backward ABI bug compatibility. */
4959 209601 : nullptr_type_node = make_node (NULLPTR_TYPE);
4960 419202 : TYPE_SIZE (nullptr_type_node) = bitsize_int (GET_MODE_BITSIZE (ptr_mode));
4961 419202 : TYPE_SIZE_UNIT (nullptr_type_node) = size_int (GET_MODE_SIZE (ptr_mode));
4962 209601 : TYPE_UNSIGNED (nullptr_type_node) = 1;
4963 419202 : TYPE_PRECISION (nullptr_type_node) = GET_MODE_BITSIZE (ptr_mode);
4964 209601 : SET_TYPE_MODE (nullptr_type_node, ptr_mode);
4965 209601 : nullptr_node = build_int_cst (nullptr_type_node, 0);
4966 :
4967 : /* Since builtin_types isn't gc'ed, don't export these nodes. */
4968 209601 : memset (builtin_types, 0, sizeof (builtin_types));
4969 209601 : }
4970 :
4971 : /* The number of named compound-literals generated thus far. */
4972 : static GTY(()) int compound_literal_number;
4973 :
4974 : /* Set DECL_NAME for DECL, a VAR_DECL for a compound-literal. */
4975 :
4976 : void
4977 279 : set_compound_literal_name (tree decl)
4978 : {
4979 279 : char *name;
4980 279 : ASM_FORMAT_PRIVATE_NAME (name, "__compound_literal",
4981 : compound_literal_number);
4982 279 : compound_literal_number++;
4983 279 : DECL_NAME (decl) = get_identifier (name);
4984 279 : }
4985 :
4986 : /* build_va_arg helper function. Return a VA_ARG_EXPR with location LOC, type
4987 : TYPE and operand OP. */
4988 :
4989 : static tree
4990 50946 : build_va_arg_1 (location_t loc, tree type, tree op)
4991 : {
4992 50946 : tree expr = build1 (VA_ARG_EXPR, type, op);
4993 50946 : SET_EXPR_LOCATION (expr, loc);
4994 50946 : return expr;
4995 : }
4996 :
4997 : /* Return a VA_ARG_EXPR corresponding to a source-level expression
4998 : va_arg (EXPR, TYPE) at source location LOC. */
4999 :
5000 : tree
5001 50946 : build_va_arg (location_t loc, tree expr, tree type)
5002 : {
5003 50946 : tree va_type = TREE_TYPE (expr);
5004 50946 : tree canon_va_type = (va_type == error_mark_node
5005 50946 : ? error_mark_node
5006 50936 : : targetm.canonical_va_list_type (va_type));
5007 :
5008 50946 : if (va_type == error_mark_node
5009 50936 : || canon_va_type == NULL_TREE)
5010 : {
5011 10 : if (canon_va_type == NULL_TREE)
5012 12 : error_at (loc, "first argument to %<va_arg%> not of type %<va_list%>");
5013 :
5014 : /* Let's handle things neutrally, if expr:
5015 : - has undeclared type, or
5016 : - is not an va_list type. */
5017 22 : return build_va_arg_1 (loc, type, error_mark_node);
5018 : }
5019 :
5020 50924 : if (TREE_CODE (canon_va_type) != ARRAY_TYPE)
5021 : {
5022 : /* Case 1: Not an array type. */
5023 :
5024 : /* Take the address, to get '&ap'. Note that &ap is not a va_list
5025 : type. */
5026 258 : c_common_mark_addressable_vec (expr);
5027 258 : expr = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (expr)), expr);
5028 :
5029 258 : return build_va_arg_1 (loc, type, expr);
5030 : }
5031 :
5032 : /* Case 2: Array type.
5033 :
5034 : Background:
5035 :
5036 : For contrast, let's start with the simple case (case 1). If
5037 : canon_va_type is not an array type, but say a char *, then when
5038 : passing-by-value a va_list, the type of the va_list param decl is
5039 : the same as for another va_list decl (all ap's are char *):
5040 :
5041 : f2_1 (char * ap)
5042 : D.1815 = VA_ARG (&ap, 0B, 1);
5043 : return D.1815;
5044 :
5045 : f2 (int i)
5046 : char * ap.0;
5047 : char * ap;
5048 : __builtin_va_start (&ap, 0);
5049 : ap.0 = ap;
5050 : res = f2_1 (ap.0);
5051 : __builtin_va_end (&ap);
5052 : D.1812 = res;
5053 : return D.1812;
5054 :
5055 : However, if canon_va_type is ARRAY_TYPE, then when passing-by-value a
5056 : va_list the type of the va_list param decl (case 2b, struct * ap) is not
5057 : the same as for another va_list decl (case 2a, struct ap[1]).
5058 :
5059 : f2_1 (struct * ap)
5060 : D.1844 = VA_ARG (ap, 0B, 0);
5061 : return D.1844;
5062 :
5063 : f2 (int i)
5064 : struct ap[1];
5065 : __builtin_va_start (&ap, 0);
5066 : res = f2_1 (&ap);
5067 : __builtin_va_end (&ap);
5068 : D.1841 = res;
5069 : return D.1841;
5070 :
5071 : Case 2b is different because:
5072 : - on the callee side, the parm decl has declared type va_list, but
5073 : grokdeclarator changes the type of the parm decl to a pointer to the
5074 : array elem type.
5075 : - on the caller side, the pass-by-value uses &ap.
5076 :
5077 : We unify these two cases (case 2a: va_list is array type,
5078 : case 2b: va_list is pointer to array elem type), by adding '&' for the
5079 : array type case, such that we have a pointer to array elem in both
5080 : cases. */
5081 :
5082 50666 : if (TREE_CODE (va_type) == ARRAY_TYPE)
5083 : {
5084 : /* Case 2a: va_list is array type. */
5085 :
5086 : /* Take the address, to get '&ap'. Make sure it's a pointer to array
5087 : elem type. */
5088 49919 : c_common_mark_addressable_vec (expr);
5089 49919 : expr = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (canon_va_type)),
5090 : expr);
5091 :
5092 : /* Verify that &ap is still recognized as having va_list type. */
5093 49919 : tree canon_expr_type
5094 49919 : = targetm.canonical_va_list_type (TREE_TYPE (expr));
5095 49919 : gcc_assert (canon_expr_type != NULL_TREE);
5096 : }
5097 : else
5098 : {
5099 : /* Case 2b: va_list is pointer to array elem type. */
5100 747 : gcc_assert (POINTER_TYPE_P (va_type));
5101 :
5102 : /* Comparison as in std_canonical_va_list_type. */
5103 747 : gcc_assert (TYPE_MAIN_VARIANT (TREE_TYPE (va_type))
5104 : == TYPE_MAIN_VARIANT (TREE_TYPE (canon_va_type)));
5105 :
5106 : /* Don't take the address. We've already got '&ap'. */
5107 50666 : ;
5108 : }
5109 :
5110 50666 : return build_va_arg_1 (loc, type, expr);
5111 : }
5112 :
5113 :
5114 : /* Linked list of disabled built-in functions. */
5115 :
5116 : struct disabled_builtin
5117 : {
5118 : const char *name;
5119 : struct disabled_builtin *next;
5120 : };
5121 : static disabled_builtin *disabled_builtins = NULL;
5122 :
5123 : static bool builtin_function_disabled_p (const char *);
5124 :
5125 : /* Disable a built-in function specified by -fno-builtin-NAME. If NAME
5126 : begins with "__builtin_", give an error. */
5127 :
5128 : void
5129 308 : disable_builtin_function (const char *name)
5130 : {
5131 308 : if (startswith (name, "__builtin_"))
5132 0 : error ("cannot disable built-in function %qs", name);
5133 : else
5134 : {
5135 308 : disabled_builtin *new_disabled_builtin = XNEW (disabled_builtin);
5136 308 : new_disabled_builtin->name = name;
5137 308 : new_disabled_builtin->next = disabled_builtins;
5138 308 : disabled_builtins = new_disabled_builtin;
5139 : }
5140 308 : }
5141 :
5142 :
5143 : /* Return true if the built-in function NAME has been disabled, false
5144 : otherwise. */
5145 :
5146 : static bool
5147 160800947 : builtin_function_disabled_p (const char *name)
5148 : {
5149 160800947 : disabled_builtin *p;
5150 161085963 : for (p = disabled_builtins; p != NULL; p = p->next)
5151 : {
5152 285324 : if (strcmp (name, p->name) == 0)
5153 : return true;
5154 : }
5155 : return false;
5156 : }
5157 :
5158 :
5159 : /* Worker for DEF_BUILTIN.
5160 : Possibly define a builtin function with one or two names.
5161 : Does not declare a non-__builtin_ function if flag_no_builtin, or if
5162 : nonansi_p and flag_no_nonansi_builtin. */
5163 :
5164 : static void
5165 316861777 : def_builtin_1 (enum built_in_function fncode,
5166 : const char *name,
5167 : enum built_in_class fnclass,
5168 : tree fntype, tree libtype,
5169 : bool both_p, bool fallback_p, bool nonansi_p,
5170 : tree fnattrs, bool implicit_p)
5171 : {
5172 316861777 : tree decl;
5173 316861777 : const char *libname;
5174 :
5175 316861777 : if (fntype == error_mark_node)
5176 : return;
5177 :
5178 298658551 : gcc_assert ((!both_p && !fallback_p)
5179 : || startswith (name, "__builtin_"));
5180 :
5181 298658551 : libname = name + strlen ("__builtin_");
5182 298658551 : decl = add_builtin_function (name, fntype, fncode, fnclass,
5183 : (fallback_p ? libname : NULL),
5184 : fnattrs);
5185 :
5186 298658551 : set_builtin_decl (fncode, decl, implicit_p);
5187 :
5188 298658551 : if (both_p
5189 161236183 : && !flag_no_builtin && !builtin_function_disabled_p (libname)
5190 459459190 : && !(nonansi_p && flag_no_nonansi_builtin))
5191 144482009 : add_builtin_function (libname, libtype, fncode, fnclass,
5192 : NULL, fnattrs);
5193 : }
5194 :
5195 : /* Nonzero if the type T promotes to int. This is (nearly) the
5196 : integral promotions defined in ISO C99 6.3.1.1/2. */
5197 :
5198 : bool
5199 596228202 : c_promoting_integer_type_p (const_tree t)
5200 : {
5201 596228202 : switch (TREE_CODE (t))
5202 : {
5203 488030184 : case INTEGER_TYPE:
5204 488030184 : return (TYPE_MAIN_VARIANT (t) == char_type_node
5205 481976368 : || TYPE_MAIN_VARIANT (t) == signed_char_type_node
5206 481297979 : || TYPE_MAIN_VARIANT (t) == unsigned_char_type_node
5207 465986197 : || TYPE_MAIN_VARIANT (t) == short_integer_type_node
5208 464904606 : || TYPE_MAIN_VARIANT (t) == short_unsigned_type_node
5209 947079365 : || TYPE_PRECISION (t) < TYPE_PRECISION (integer_type_node));
5210 :
5211 676917 : case ENUMERAL_TYPE:
5212 : /* ??? Technically all enumerations not larger than an int
5213 : promote to an int. But this is used along code paths
5214 : that only want to notice a size change. */
5215 676917 : return TYPE_PRECISION (t) < TYPE_PRECISION (integer_type_node);
5216 :
5217 : case BOOLEAN_TYPE:
5218 : return true;
5219 :
5220 : default:
5221 : return false;
5222 : }
5223 : }
5224 :
5225 : /* Return 1 if PARMS specifies a fixed number of parameters
5226 : and none of their types is affected by default promotions. */
5227 :
5228 : bool
5229 22022 : self_promoting_args_p (const_tree parms)
5230 : {
5231 22022 : const_tree t;
5232 65564 : for (t = parms; t; t = TREE_CHAIN (t))
5233 : {
5234 44075 : tree type = TREE_VALUE (t);
5235 :
5236 44075 : if (type == error_mark_node)
5237 2 : continue;
5238 :
5239 44073 : if (TREE_CHAIN (t) == NULL_TREE && type != void_type_node)
5240 : return false;
5241 :
5242 43590 : if (type == NULL_TREE)
5243 : return false;
5244 :
5245 43590 : if (TYPE_MAIN_VARIANT (type) == float_type_node)
5246 : return false;
5247 :
5248 43545 : if (c_promoting_integer_type_p (type))
5249 : return false;
5250 : }
5251 : return true;
5252 : }
5253 :
5254 : /* Recursively remove any '*' or '&' operator from TYPE. */
5255 : tree
5256 32557051 : strip_pointer_operator (tree t)
5257 : {
5258 33453678 : while (POINTER_TYPE_P (t))
5259 896627 : t = TREE_TYPE (t);
5260 32557051 : return t;
5261 : }
5262 :
5263 : /* Recursively remove pointer or array type from TYPE. */
5264 : tree
5265 11759181 : strip_pointer_or_array_types (tree t)
5266 : {
5267 16606146 : while (TREE_CODE (t) == ARRAY_TYPE || POINTER_TYPE_P (t))
5268 4846965 : t = TREE_TYPE (t);
5269 11759181 : return t;
5270 : }
5271 :
5272 : /* Used to compare case labels. K1 and K2 are actually tree nodes
5273 : representing case labels, or NULL_TREE for a `default' label.
5274 : Returns -1 if K1 is ordered before K2, -1 if K1 is ordered after
5275 : K2, and 0 if K1 and K2 are equal. */
5276 :
5277 : int
5278 21828278 : case_compare (splay_tree_key k1, splay_tree_key k2)
5279 : {
5280 : /* Consider a NULL key (such as arises with a `default' label) to be
5281 : smaller than anything else. */
5282 21828278 : if (!k1)
5283 3078204 : return k2 ? -1 : 0;
5284 19323760 : else if (!k2)
5285 : return k1 ? 1 : 0;
5286 :
5287 18668784 : return tree_int_cst_compare ((tree) k1, (tree) k2);
5288 : }
5289 :
5290 : /* Process a case label, located at LOC, for the range LOW_VALUE
5291 : ... HIGH_VALUE. If LOW_VALUE and HIGH_VALUE are both NULL_TREE
5292 : then this case label is actually a `default' label. If only
5293 : HIGH_VALUE is NULL_TREE, then case label was declared using the
5294 : usual C/C++ syntax, rather than the GNU case range extension.
5295 : CASES is a tree containing all the case ranges processed so far;
5296 : COND is the condition for the switch-statement itself.
5297 : Returns the CASE_LABEL_EXPR created, or ERROR_MARK_NODE if no
5298 : CASE_LABEL_EXPR is created. ATTRS are the attributes to be applied
5299 : to the label. */
5300 :
5301 : tree
5302 2479347 : c_add_case_label (location_t loc, splay_tree cases, tree cond,
5303 : tree low_value, tree high_value, tree attrs)
5304 : {
5305 2479347 : tree type;
5306 2479347 : tree label;
5307 2479347 : tree case_label;
5308 2479347 : splay_tree_node node;
5309 :
5310 : /* Create the LABEL_DECL itself. */
5311 2479347 : label = create_artificial_label (loc);
5312 2479347 : decl_attributes (&label, attrs, 0);
5313 :
5314 : /* If there was an error processing the switch condition, bail now
5315 : before we get more confused. */
5316 2479347 : if (!cond || cond == error_mark_node)
5317 0 : goto error_out;
5318 :
5319 2225961 : if ((low_value && TREE_TYPE (low_value)
5320 2225961 : && POINTER_TYPE_P (TREE_TYPE (low_value)))
5321 4705307 : || (high_value && TREE_TYPE (high_value)
5322 440 : && POINTER_TYPE_P (TREE_TYPE (high_value))))
5323 : {
5324 1 : error_at (loc, "pointers are not permitted as case values");
5325 1 : goto error_out;
5326 : }
5327 :
5328 : /* Case ranges are a GNU extension. */
5329 2479346 : if (high_value)
5330 : {
5331 440 : if (c_dialect_cxx ())
5332 126 : pedwarn (loc, OPT_Wpedantic,
5333 : "range expressions in switch statements are non-standard");
5334 314 : else if (warn_c23_c2y_compat > 0)
5335 : {
5336 13 : if (pedantic && !flag_isoc2y)
5337 0 : pedwarn (loc, OPT_Wc23_c2y_compat,
5338 : "ISO C does not support range expressions in switch "
5339 : "statements before C2Y");
5340 : else
5341 13 : warning_at (loc, OPT_Wc23_c2y_compat,
5342 : "ISO C does not support range expressions in switch "
5343 : "statements before C2Y");
5344 : }
5345 301 : else if (warn_c23_c2y_compat && pedantic && !flag_isoc2y)
5346 28 : pedwarn (loc, OPT_Wpedantic,
5347 : "ISO C does not support range expressions in switch "
5348 : "statements before C2Y");
5349 : }
5350 :
5351 2479346 : type = TREE_TYPE (cond);
5352 2479346 : if (low_value)
5353 : {
5354 2225960 : low_value = check_case_value (loc, low_value);
5355 2225960 : tree tem = NULL_TREE;
5356 2225960 : if (high_value
5357 440 : && !c_dialect_cxx ()
5358 314 : && low_value != error_mark_node
5359 313 : && !int_fits_type_p (low_value, type)
5360 2226400 : && pedwarn (loc, OPT_Wpedantic,
5361 : "conversion of %qE to %qT in range expression changes "
5362 : "value to %qE", low_value, type,
5363 20 : (tem = fold_convert (type, low_value))))
5364 20 : low_value = tem;
5365 2225960 : low_value = convert_and_check (loc, type, low_value);
5366 2225960 : low_value = fold (low_value);
5367 2225960 : if (low_value == error_mark_node)
5368 147 : goto error_out;
5369 : }
5370 2479199 : if (high_value)
5371 : {
5372 439 : high_value = check_case_value (loc, high_value);
5373 439 : tree tem = NULL_TREE;
5374 439 : if (!c_dialect_cxx ()
5375 313 : && high_value != error_mark_node
5376 312 : && !int_fits_type_p (high_value, type)
5377 752 : && pedwarn (loc, OPT_Wpedantic,
5378 : "conversion of %qE to %qT in range expression changes "
5379 : "value to %qE", high_value, type,
5380 20 : (tem = fold_convert (type, high_value))))
5381 20 : high_value = tem;
5382 439 : high_value = convert_and_check (loc, type, high_value);
5383 439 : high_value = fold (high_value);
5384 439 : if (high_value == error_mark_node)
5385 4 : goto error_out;
5386 : }
5387 :
5388 2479195 : if (low_value && high_value)
5389 : {
5390 : /* If the LOW_VALUE and HIGH_VALUE are the same, then this isn't
5391 : really a case range, even though it was written that way.
5392 : Remove the HIGH_VALUE to simplify later processing. */
5393 435 : if (tree_int_cst_equal (low_value, high_value))
5394 : high_value = NULL_TREE;
5395 416 : else if (!tree_int_cst_lt (low_value, high_value))
5396 : {
5397 28 : warning_at (loc, 0, "empty range specified");
5398 28 : goto error_out;
5399 : }
5400 : }
5401 :
5402 : /* Look up the LOW_VALUE in the table of case labels we already
5403 : have. */
5404 2479167 : node = splay_tree_lookup (cases, (splay_tree_key) low_value);
5405 : /* If there was not an exact match, check for overlapping ranges.
5406 : There's no need to do this if there's no LOW_VALUE or HIGH_VALUE;
5407 : that's a `default' label and the only overlap is an exact match. */
5408 2479167 : if (!node && (low_value || high_value))
5409 : {
5410 2225763 : splay_tree_node low_bound;
5411 2225763 : splay_tree_node high_bound;
5412 :
5413 : /* Even though there wasn't an exact match, there might be an
5414 : overlap between this case range and another case range.
5415 : Since we've (inductively) not allowed any overlapping case
5416 : ranges, we simply need to find the greatest low case label
5417 : that is smaller that LOW_VALUE, and the smallest low case
5418 : label that is greater than LOW_VALUE. If there is an overlap
5419 : it will occur in one of these two ranges. */
5420 2225763 : low_bound = splay_tree_predecessor (cases,
5421 : (splay_tree_key) low_value);
5422 2225763 : high_bound = splay_tree_successor (cases,
5423 : (splay_tree_key) low_value);
5424 :
5425 : /* Check to see if the LOW_BOUND overlaps. It is smaller than
5426 : the LOW_VALUE, so there is no need to check unless the
5427 : LOW_BOUND is in fact itself a case range. */
5428 2225763 : if (low_bound
5429 1475134 : && CASE_HIGH ((tree) low_bound->value)
5430 2225930 : && tree_int_cst_compare (CASE_HIGH ((tree) low_bound->value),
5431 : low_value) >= 0)
5432 : node = low_bound;
5433 : /* Check to see if the HIGH_BOUND overlaps. The low end of that
5434 : range is bigger than the low end of the current range, so we
5435 : are only interested if the current range is a real range, and
5436 : not an ordinary case label. */
5437 2225751 : else if (high_bound
5438 2225751 : && high_value
5439 2225751 : && (tree_int_cst_compare ((tree) high_bound->key,
5440 : high_value)
5441 : <= 0))
5442 : node = high_bound;
5443 : }
5444 : /* If there was an overlap, issue an error. */
5445 2479148 : if (node)
5446 : {
5447 37 : tree duplicate = CASE_LABEL ((tree) node->value);
5448 :
5449 37 : if (high_value)
5450 : {
5451 10 : error_at (loc, "duplicate (or overlapping) case value");
5452 10 : inform (DECL_SOURCE_LOCATION (duplicate),
5453 : "this is the first entry overlapping that value");
5454 : }
5455 27 : else if (low_value)
5456 : {
5457 26 : error_at (loc, "duplicate case value") ;
5458 26 : inform (DECL_SOURCE_LOCATION (duplicate), "previously used here");
5459 : }
5460 : else
5461 : {
5462 1 : error_at (loc, "multiple default labels in one switch");
5463 1 : inform (DECL_SOURCE_LOCATION (duplicate),
5464 : "this is the first default label");
5465 : }
5466 37 : goto error_out;
5467 : }
5468 :
5469 : /* Add a CASE_LABEL to the statement-tree. */
5470 2479130 : case_label = add_stmt (build_case_label (low_value, high_value, label));
5471 : /* Register this case label in the splay tree. */
5472 2479130 : splay_tree_insert (cases,
5473 : (splay_tree_key) low_value,
5474 : (splay_tree_value) case_label);
5475 :
5476 2479130 : return case_label;
5477 :
5478 217 : error_out:
5479 : /* Add a label so that the back-end doesn't think that the beginning of
5480 : the switch is unreachable. Note that we do not add a case label, as
5481 : that just leads to duplicates and thence to failure later on. */
5482 217 : if (!cases->root)
5483 : {
5484 153 : tree t = create_artificial_label (loc);
5485 153 : add_stmt (build_stmt (loc, LABEL_EXPR, t));
5486 : }
5487 217 : return error_mark_node;
5488 : }
5489 :
5490 : /* Subroutine of c_switch_covers_all_cases_p, called via
5491 : splay_tree_foreach. Return 1 if it doesn't cover all the cases.
5492 : ARGS[0] is initially NULL and after the first iteration is the
5493 : so far highest case label. ARGS[1] is the minimum of SWITCH_COND's
5494 : type. */
5495 :
5496 : static int
5497 119978 : c_switch_covers_all_cases_p_1 (splay_tree_node node, void *data)
5498 : {
5499 119978 : tree label = (tree) node->value;
5500 119978 : tree *args = (tree *) data;
5501 :
5502 : /* If there is a default case, we shouldn't have called this. */
5503 119978 : gcc_assert (CASE_LOW (label));
5504 :
5505 119978 : if (args[0] == NULL_TREE)
5506 : {
5507 42708 : if (wi::to_widest (args[1]) < wi::to_widest (CASE_LOW (label)))
5508 : return 1;
5509 : }
5510 77270 : else if (wi::add (wi::to_widest (args[0]), 1)
5511 154540 : != wi::to_widest (CASE_LOW (label)))
5512 : return 1;
5513 101421 : if (CASE_HIGH (label))
5514 109 : args[0] = CASE_HIGH (label);
5515 : else
5516 101312 : args[0] = CASE_LOW (label);
5517 : return 0;
5518 : }
5519 :
5520 : /* Return true if switch with CASES and switch condition with type
5521 : covers all possible values in the case labels. */
5522 :
5523 : bool
5524 76658 : c_switch_covers_all_cases_p (splay_tree cases, tree type)
5525 : {
5526 : /* If there is default:, this is always the case. */
5527 76658 : splay_tree_node default_node
5528 76658 : = splay_tree_lookup (cases, (splay_tree_key) NULL);
5529 76658 : if (default_node)
5530 : return true;
5531 :
5532 43255 : if (!INTEGRAL_TYPE_P (type))
5533 : return false;
5534 :
5535 43188 : tree args[2] = { NULL_TREE, TYPE_MIN_VALUE (type) };
5536 43188 : if (splay_tree_foreach (cases, c_switch_covers_all_cases_p_1, args))
5537 : return false;
5538 :
5539 : /* If there are no cases at all, or if the highest case label
5540 : is smaller than TYPE_MAX_VALUE, return false. */
5541 24631 : if (args[0] == NULL_TREE
5542 24631 : || wi::to_widest (args[0]) < wi::to_widest (TYPE_MAX_VALUE (type)))
5543 24585 : return false;
5544 :
5545 : return true;
5546 : }
5547 :
5548 : /* Return true if stmt can fall through. Used by block_may_fallthru
5549 : default case. */
5550 :
5551 : bool
5552 2639111 : c_block_may_fallthru (const_tree stmt)
5553 : {
5554 2639111 : switch (TREE_CODE (stmt))
5555 : {
5556 18608 : case SWITCH_STMT:
5557 18608 : return (!SWITCH_STMT_ALL_CASES_P (stmt)
5558 220 : || !SWITCH_STMT_NO_BREAK_P (stmt)
5559 18636 : || block_may_fallthru (SWITCH_STMT_BODY (stmt)));
5560 :
5561 : default:
5562 : return true;
5563 : }
5564 : }
5565 :
5566 : /* Finish an expression taking the address of LABEL (an
5567 : IDENTIFIER_NODE). Returns an expression for the address.
5568 :
5569 : LOC is the location for the expression returned. */
5570 :
5571 : tree
5572 2134 : finish_label_address_expr (tree label, location_t loc)
5573 : {
5574 2134 : tree result;
5575 :
5576 2134 : pedwarn (input_location, OPT_Wpedantic, "taking the address of a label is non-standard");
5577 :
5578 2134 : if (label == error_mark_node)
5579 : return error_mark_node;
5580 :
5581 2128 : label = lookup_label (label);
5582 2128 : if (label == NULL_TREE)
5583 5 : result = null_pointer_node;
5584 : else
5585 : {
5586 2123 : TREE_USED (label) = 1;
5587 2123 : result = build1 (ADDR_EXPR, ptr_type_node, label);
5588 : /* The current function is not necessarily uninlinable.
5589 : Computed gotos are incompatible with inlining, but the value
5590 : here could be used only in a diagnostic, for example. */
5591 2123 : protected_set_expr_location (result, loc);
5592 : }
5593 :
5594 : return result;
5595 : }
5596 :
5597 :
5598 : /* Given a boolean expression ARG, return a tree representing an increment
5599 : or decrement (as indicated by CODE) of ARG. The front end must check for
5600 : invalid cases (e.g., decrement in C++). */
5601 : tree
5602 93 : boolean_increment (enum tree_code code, tree arg)
5603 : {
5604 93 : tree val;
5605 93 : tree true_res = build_int_cst (TREE_TYPE (arg), 1);
5606 :
5607 93 : arg = stabilize_reference (arg);
5608 93 : switch (code)
5609 : {
5610 28 : case PREINCREMENT_EXPR:
5611 28 : val = build2 (MODIFY_EXPR, TREE_TYPE (arg), arg, true_res);
5612 28 : break;
5613 29 : case POSTINCREMENT_EXPR:
5614 29 : val = build2 (MODIFY_EXPR, TREE_TYPE (arg), arg, true_res);
5615 29 : arg = save_expr (arg);
5616 29 : val = build2 (COMPOUND_EXPR, TREE_TYPE (arg), val, arg);
5617 29 : val = build2 (COMPOUND_EXPR, TREE_TYPE (arg), arg, val);
5618 29 : break;
5619 22 : case PREDECREMENT_EXPR:
5620 22 : val = build2 (MODIFY_EXPR, TREE_TYPE (arg), arg,
5621 : invert_truthvalue_loc (input_location, arg));
5622 22 : break;
5623 14 : case POSTDECREMENT_EXPR:
5624 14 : val = build2 (MODIFY_EXPR, TREE_TYPE (arg), arg,
5625 : invert_truthvalue_loc (input_location, arg));
5626 14 : arg = save_expr (arg);
5627 14 : val = build2 (COMPOUND_EXPR, TREE_TYPE (arg), val, arg);
5628 14 : val = build2 (COMPOUND_EXPR, TREE_TYPE (arg), arg, val);
5629 14 : break;
5630 0 : default:
5631 0 : gcc_unreachable ();
5632 : }
5633 93 : TREE_SIDE_EFFECTS (val) = 1;
5634 93 : return val;
5635 : }
5636 :
5637 : /* Built-in macros for stddef.h and stdint.h, that require macros
5638 : defined in this file. */
5639 : void
5640 209063 : c_stddef_cpp_builtins(void)
5641 : {
5642 214539 : builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE, 0);
5643 214539 : builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE, 0);
5644 214539 : builtin_define_with_value ("__WCHAR_TYPE__", MODIFIED_WCHAR_TYPE, 0);
5645 : /* C++ has wchar_t as a builtin type, C doesn't, so if WINT_TYPE
5646 : maps to wchar_t, define it to the underlying WCHAR_TYPE in C, and
5647 : to wchar_t in C++, so the desired type equivalence holds. */
5648 209063 : if (!c_dialect_cxx ()
5649 : && strcmp (WINT_TYPE, "wchar_t") == 0)
5650 : builtin_define_with_value ("__WINT_TYPE__", WCHAR_TYPE, 0);
5651 : else
5652 209063 : builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE, 0);
5653 214539 : builtin_define_with_value ("__INTMAX_TYPE__", INTMAX_TYPE, 0);
5654 214539 : builtin_define_with_value ("__UINTMAX_TYPE__", UINTMAX_TYPE, 0);
5655 209063 : if (flag_char8_t)
5656 170631 : builtin_define_with_value ("__CHAR8_TYPE__", CHAR8_TYPE, 0);
5657 209063 : builtin_define_with_value ("__CHAR16_TYPE__", CHAR16_TYPE, 0);
5658 209063 : builtin_define_with_value ("__CHAR32_TYPE__", CHAR32_TYPE, 0);
5659 209063 : if (SIG_ATOMIC_TYPE)
5660 209063 : builtin_define_with_value ("__SIG_ATOMIC_TYPE__", SIG_ATOMIC_TYPE, 0);
5661 209063 : if (INT8_TYPE)
5662 209063 : builtin_define_with_value ("__INT8_TYPE__", INT8_TYPE, 0);
5663 209063 : if (INT16_TYPE)
5664 209063 : builtin_define_with_value ("__INT16_TYPE__", INT16_TYPE, 0);
5665 209063 : if (INT32_TYPE)
5666 209063 : builtin_define_with_value ("__INT32_TYPE__", INT32_TYPE, 0);
5667 209063 : if (INT64_TYPE)
5668 214539 : builtin_define_with_value ("__INT64_TYPE__", INT64_TYPE, 0);
5669 209063 : if (UINT8_TYPE)
5670 209063 : builtin_define_with_value ("__UINT8_TYPE__", UINT8_TYPE, 0);
5671 209063 : if (UINT16_TYPE)
5672 209063 : builtin_define_with_value ("__UINT16_TYPE__", UINT16_TYPE, 0);
5673 209063 : if (UINT32_TYPE)
5674 209063 : builtin_define_with_value ("__UINT32_TYPE__", UINT32_TYPE, 0);
5675 209063 : if (UINT64_TYPE)
5676 214539 : builtin_define_with_value ("__UINT64_TYPE__", UINT64_TYPE, 0);
5677 209063 : if (INT_LEAST8_TYPE)
5678 209063 : builtin_define_with_value ("__INT_LEAST8_TYPE__", INT_LEAST8_TYPE, 0);
5679 209063 : if (INT_LEAST16_TYPE)
5680 209063 : builtin_define_with_value ("__INT_LEAST16_TYPE__", INT_LEAST16_TYPE, 0);
5681 209063 : if (INT_LEAST32_TYPE)
5682 209063 : builtin_define_with_value ("__INT_LEAST32_TYPE__", INT_LEAST32_TYPE, 0);
5683 209063 : if (INT_LEAST64_TYPE)
5684 214539 : builtin_define_with_value ("__INT_LEAST64_TYPE__", INT_LEAST64_TYPE, 0);
5685 209063 : if (UINT_LEAST8_TYPE)
5686 209063 : builtin_define_with_value ("__UINT_LEAST8_TYPE__", UINT_LEAST8_TYPE, 0);
5687 209063 : if (UINT_LEAST16_TYPE)
5688 209063 : builtin_define_with_value ("__UINT_LEAST16_TYPE__", UINT_LEAST16_TYPE, 0);
5689 209063 : if (UINT_LEAST32_TYPE)
5690 209063 : builtin_define_with_value ("__UINT_LEAST32_TYPE__", UINT_LEAST32_TYPE, 0);
5691 209063 : if (UINT_LEAST64_TYPE)
5692 214539 : builtin_define_with_value ("__UINT_LEAST64_TYPE__", UINT_LEAST64_TYPE, 0);
5693 209063 : if (INT_FAST8_TYPE)
5694 209063 : builtin_define_with_value ("__INT_FAST8_TYPE__", INT_FAST8_TYPE, 0);
5695 209063 : if (INT_FAST16_TYPE)
5696 214539 : builtin_define_with_value ("__INT_FAST16_TYPE__", INT_FAST16_TYPE, 0);
5697 209063 : if (INT_FAST32_TYPE)
5698 214539 : builtin_define_with_value ("__INT_FAST32_TYPE__", INT_FAST32_TYPE, 0);
5699 209063 : if (INT_FAST64_TYPE)
5700 214539 : builtin_define_with_value ("__INT_FAST64_TYPE__", INT_FAST64_TYPE, 0);
5701 209063 : if (UINT_FAST8_TYPE)
5702 209063 : builtin_define_with_value ("__UINT_FAST8_TYPE__", UINT_FAST8_TYPE, 0);
5703 209063 : if (UINT_FAST16_TYPE)
5704 214539 : builtin_define_with_value ("__UINT_FAST16_TYPE__", UINT_FAST16_TYPE, 0);
5705 209063 : if (UINT_FAST32_TYPE)
5706 214539 : builtin_define_with_value ("__UINT_FAST32_TYPE__", UINT_FAST32_TYPE, 0);
5707 209063 : if (UINT_FAST64_TYPE)
5708 214539 : builtin_define_with_value ("__UINT_FAST64_TYPE__", UINT_FAST64_TYPE, 0);
5709 209063 : if (INTPTR_TYPE)
5710 214539 : builtin_define_with_value ("__INTPTR_TYPE__", INTPTR_TYPE, 0);
5711 209063 : if (UINTPTR_TYPE)
5712 214539 : builtin_define_with_value ("__UINTPTR_TYPE__", UINTPTR_TYPE, 0);
5713 : /* GIMPLE FE testcases need access to the GCC internal 'sizetype'.
5714 : Expose it as __SIZETYPE__. */
5715 209063 : if (flag_gimple)
5716 327 : builtin_define_with_value ("__SIZETYPE__", SIZETYPE, 0);
5717 209063 : }
5718 :
5719 : static void
5720 209601 : c_init_attributes (void)
5721 : {
5722 : /* Fill in the built_in_attributes array. */
5723 : #define DEF_ATTR_NULL_TREE(ENUM) \
5724 : built_in_attributes[(int) ENUM] = NULL_TREE;
5725 : #define DEF_ATTR_INT(ENUM, VALUE) \
5726 : built_in_attributes[(int) ENUM] = build_int_cst (integer_type_node, VALUE);
5727 : #define DEF_ATTR_STRING(ENUM, VALUE) \
5728 : built_in_attributes[(int) ENUM] = build_string (strlen (VALUE), VALUE);
5729 : #define DEF_ATTR_IDENT(ENUM, STRING) \
5730 : built_in_attributes[(int) ENUM] = get_identifier (STRING);
5731 : #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \
5732 : built_in_attributes[(int) ENUM] \
5733 : = tree_cons (built_in_attributes[(int) PURPOSE], \
5734 : built_in_attributes[(int) VALUE], \
5735 : built_in_attributes[(int) CHAIN]);
5736 : #include "builtin-attrs.def"
5737 : #undef DEF_ATTR_NULL_TREE
5738 : #undef DEF_ATTR_INT
5739 : #undef DEF_ATTR_IDENT
5740 : #undef DEF_ATTR_TREE_LIST
5741 209601 : }
5742 :
5743 : /* Check whether the byte alignment ALIGN is a valid user-specified
5744 : alignment less than the supported maximum. If so, return ALIGN's
5745 : base-2 log; if not, output an error and return -1. If OBJFILE
5746 : then reject alignments greater than MAX_OFILE_ALIGNMENT when
5747 : converted to bits. Otherwise, consider valid only alignments
5748 : that are less than HOST_BITS_PER_INT - LOG2_BITS_PER_UNIT.
5749 : Zero is not considered a valid argument (and results in -1 on
5750 : return) but it only triggers a warning when WARN_ZERO is set. */
5751 :
5752 : int
5753 642063 : check_user_alignment (const_tree align, bool objfile, bool warn_zero)
5754 : {
5755 642063 : if (error_operand_p (align))
5756 : return -1;
5757 :
5758 642040 : if (TREE_CODE (align) != INTEGER_CST
5759 642040 : || !INTEGRAL_TYPE_P (TREE_TYPE (align)))
5760 : {
5761 27 : error ("requested alignment is not an integer constant");
5762 27 : return -1;
5763 : }
5764 :
5765 642013 : if (integer_zerop (align))
5766 : {
5767 75 : if (warn_zero)
5768 63 : warning (OPT_Wattributes,
5769 : "requested alignment %qE is not a positive power of 2",
5770 : align);
5771 75 : return -1;
5772 : }
5773 :
5774 : /* Log2 of the byte alignment ALIGN. */
5775 641938 : int log2align;
5776 641938 : if (tree_int_cst_sgn (align) == -1
5777 641938 : || (log2align = tree_log2 (align)) == -1)
5778 : {
5779 36 : error ("requested alignment %qE is not a positive power of 2",
5780 : align);
5781 36 : return -1;
5782 : }
5783 :
5784 641902 : if (objfile)
5785 : {
5786 14980 : unsigned maxalign = MAX_OFILE_ALIGNMENT / BITS_PER_UNIT;
5787 14980 : if (!tree_fits_uhwi_p (align) || tree_to_uhwi (align) > maxalign)
5788 : {
5789 10 : error ("requested alignment %qE exceeds object file maximum %u",
5790 : align, maxalign);
5791 10 : return -1;
5792 : }
5793 : }
5794 :
5795 641892 : if (log2align >= HOST_BITS_PER_INT - LOG2_BITS_PER_UNIT)
5796 : {
5797 17 : error ("requested alignment %qE exceeds maximum %u",
5798 : align, 1U << (HOST_BITS_PER_INT - LOG2_BITS_PER_UNIT - 1));
5799 17 : return -1;
5800 : }
5801 :
5802 : return log2align;
5803 : }
5804 :
5805 : /* Determine the ELF symbol visibility for DECL, which is either a
5806 : variable or a function. It is an error to use this function if a
5807 : definition of DECL is not available in this translation unit.
5808 : Returns true if the final visibility has been determined by this
5809 : function; false if the caller is free to make additional
5810 : modifications. */
5811 :
5812 : bool
5813 52137977 : c_determine_visibility (tree decl)
5814 : {
5815 52137977 : gcc_assert (VAR_OR_FUNCTION_DECL_P (decl));
5816 :
5817 : /* If the user explicitly specified the visibility with an
5818 : attribute, honor that. DECL_VISIBILITY will have been set during
5819 : the processing of the attribute. We check for an explicit
5820 : attribute, rather than just checking DECL_VISIBILITY_SPECIFIED,
5821 : to distinguish the use of an attribute from the use of a "#pragma
5822 : GCC visibility push(...)"; in the latter case we still want other
5823 : considerations to be able to overrule the #pragma. */
5824 52137977 : if (lookup_attribute ("visibility", DECL_ATTRIBUTES (decl))
5825 : || (TARGET_DLLIMPORT_DECL_ATTRIBUTES
5826 : && (lookup_attribute ("dllimport", DECL_ATTRIBUTES (decl))
5827 : || lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl)))))
5828 : return true;
5829 :
5830 : /* Set default visibility to whatever the user supplied with
5831 : visibility_specified depending on #pragma GCC visibility. */
5832 51497347 : if (!DECL_VISIBILITY_SPECIFIED (decl))
5833 : {
5834 51496101 : if (visibility_options.inpragma
5835 51496101 : || DECL_VISIBILITY (decl) != default_visibility)
5836 : {
5837 212752 : DECL_VISIBILITY (decl) = default_visibility;
5838 212752 : DECL_VISIBILITY_SPECIFIED (decl) = visibility_options.inpragma;
5839 : /* If visibility changed and DECL already has DECL_RTL, ensure
5840 : symbol flags are updated. */
5841 14336 : if (((VAR_P (decl) && TREE_STATIC (decl))
5842 212700 : || TREE_CODE (decl) == FUNCTION_DECL)
5843 411220 : && DECL_RTL_SET_P (decl))
5844 0 : make_decl_rtl (decl);
5845 : }
5846 : }
5847 : return false;
5848 : }
5849 :
5850 : /* Data to communicate through check_function_arguments_recurse between
5851 : check_function_nonnull and check_nonnull_arg. */
5852 :
5853 : struct nonnull_arg_ctx
5854 : {
5855 : /* Location of the call. */
5856 : location_t loc;
5857 : /* The function whose arguments are being checked and its type (used
5858 : for calls through function pointers). */
5859 : const_tree fndecl, fntype;
5860 : /* For nonnull_if_nonzero, index of the other arguments. */
5861 : unsigned HOST_WIDE_INT other1, other2;
5862 : /* True if a warning has been issued. */
5863 : bool warned_p;
5864 : };
5865 :
5866 : /* Check the argument list of a function call to CTX.FNDECL of CTX.FNTYPE
5867 : for null in argument slots that are marked as requiring a non-null
5868 : pointer argument. The NARGS arguments are passed in the array ARGARRAY.
5869 : Return true if we have warned. */
5870 :
5871 : static bool
5872 6478102 : check_function_nonnull (nonnull_arg_ctx &ctx, int nargs, tree *argarray)
5873 : {
5874 6478102 : int firstarg = 0;
5875 6478102 : if (TREE_CODE (ctx.fntype) == METHOD_TYPE)
5876 : {
5877 505101 : bool closure = false;
5878 505101 : if (ctx.fndecl)
5879 : {
5880 : /* For certain lambda expressions the C++ front end emits calls
5881 : that pass a null this pointer as an argument named __closure
5882 : to the member operator() of empty function. Detect those
5883 : and avoid checking them, but proceed to check the remaining
5884 : arguments. */
5885 504951 : tree arg0 = DECL_ARGUMENTS (ctx.fndecl);
5886 504951 : if (tree arg0name = DECL_NAME (arg0))
5887 504951 : closure = id_equal (arg0name, "__closure");
5888 : }
5889 :
5890 : /* In calls to C++ non-static member functions check the this
5891 : pointer regardless of whether the function is declared with
5892 : attribute nonnull. */
5893 1005052 : firstarg = 1;
5894 504951 : if (!closure)
5895 500101 : check_function_arguments_recurse (check_nonnull_arg, &ctx, argarray[0],
5896 : firstarg, OPT_Wnonnull);
5897 : }
5898 :
5899 6478102 : tree attrs = lookup_attribute ("nonnull", TYPE_ATTRIBUTES (ctx.fntype));
5900 :
5901 6478102 : tree a = attrs;
5902 : /* See if any of the nonnull attributes has no arguments. If so,
5903 : then every pointer argument is checked (in which case the check
5904 : for pointer type is done in check_nonnull_arg). */
5905 13189084 : while (a != NULL_TREE && TREE_VALUE (a) != NULL_TREE)
5906 102996 : a = lookup_attribute ("nonnull", TREE_CHAIN (a));
5907 :
5908 6478102 : if (a != NULL_TREE)
5909 71402 : for (int i = firstarg; i < nargs; i++)
5910 44514 : check_function_arguments_recurse (check_nonnull_arg, &ctx, argarray[i],
5911 44514 : i + 1, OPT_Wnonnull);
5912 6451214 : else if (attrs)
5913 : {
5914 : /* Walk the argument list. If we encounter an argument number we
5915 : should check for non-null, do it. */
5916 345899 : for (int i = firstarg; i < nargs; i++)
5917 : {
5918 147136 : for (a = attrs; ; a = TREE_CHAIN (a))
5919 : {
5920 400672 : a = lookup_attribute ("nonnull", a);
5921 400672 : if (a == NULL_TREE || nonnull_check_p (TREE_VALUE (a), i + 1))
5922 : break;
5923 : }
5924 :
5925 253536 : if (a != NULL_TREE)
5926 123724 : check_function_arguments_recurse (check_nonnull_arg, &ctx,
5927 123724 : argarray[i], i + 1,
5928 : OPT_Wnonnull);
5929 253536 : a = NULL_TREE;
5930 : }
5931 : }
5932 6478102 : if (a == NULL_TREE)
5933 6451214 : for (attrs = TYPE_ATTRIBUTES (ctx.fntype);
5934 6509994 : (attrs = lookup_attribute ("nonnull_if_nonzero", attrs));
5935 58780 : attrs = TREE_CHAIN (attrs))
5936 : {
5937 58780 : tree args = TREE_VALUE (attrs);
5938 58780 : unsigned int idx = TREE_INT_CST_LOW (TREE_VALUE (args)) - 1;
5939 58780 : unsigned int idx2
5940 58780 : = TREE_INT_CST_LOW (TREE_VALUE (TREE_CHAIN (args))) - 1;
5941 58780 : unsigned int idx3 = idx2;
5942 58780 : if (tree chain2 = TREE_CHAIN (TREE_CHAIN (args)))
5943 485 : idx3 = TREE_INT_CST_LOW (TREE_VALUE (chain2)) - 1;
5944 58780 : if (idx < (unsigned) nargs - firstarg
5945 58775 : && idx2 < (unsigned) nargs - firstarg
5946 58770 : && idx3 < (unsigned) nargs - firstarg
5947 58770 : && INTEGRAL_TYPE_P (TREE_TYPE (argarray[firstarg + idx2]))
5948 58697 : && integer_nonzerop (argarray[firstarg + idx2])
5949 31918 : && INTEGRAL_TYPE_P (TREE_TYPE (argarray[firstarg + idx3]))
5950 90698 : && integer_nonzerop (argarray[firstarg + idx3]))
5951 : {
5952 31820 : ctx.other1 = firstarg + idx2 + 1;
5953 31820 : ctx.other2 = firstarg + idx3 + 1;
5954 31820 : check_function_arguments_recurse (check_nonnull_arg, &ctx,
5955 31820 : argarray[firstarg + idx],
5956 31820 : firstarg + idx + 1,
5957 : OPT_Wnonnull);
5958 31820 : ctx.other1 = 0;
5959 31820 : ctx.other2 = 0;
5960 : }
5961 : }
5962 6478102 : return ctx.warned_p;
5963 : }
5964 :
5965 : /* Check that the Nth argument of a function call (counting backwards
5966 : from the end) is a (pointer)0. The NARGS arguments are passed in the
5967 : array ARGARRAY. */
5968 :
5969 : static void
5970 6464550 : check_function_sentinel (const_tree fntype, int nargs, tree *argarray)
5971 : {
5972 6464550 : tree attr = lookup_attribute ("sentinel", TYPE_ATTRIBUTES (fntype));
5973 :
5974 6464550 : if (attr)
5975 : {
5976 112 : int len = 0;
5977 112 : int pos = 0;
5978 112 : tree sentinel;
5979 112 : function_args_iterator iter;
5980 112 : tree t;
5981 :
5982 : /* Skip over the named arguments. */
5983 237 : FOREACH_FUNCTION_ARGS (fntype, t, iter)
5984 : {
5985 125 : if (len == nargs)
5986 : break;
5987 125 : len++;
5988 : }
5989 :
5990 112 : if (TREE_VALUE (attr))
5991 : {
5992 59 : tree p = TREE_VALUE (TREE_VALUE (attr));
5993 59 : pos = TREE_INT_CST_LOW (p);
5994 : }
5995 :
5996 : /* The sentinel must be one of the varargs, i.e.
5997 : in position >= the number of fixed arguments. */
5998 112 : if ((nargs - 1 - pos) < len)
5999 : {
6000 22 : warning (OPT_Wformat_,
6001 : "not enough variable arguments to fit a sentinel");
6002 22 : return;
6003 : }
6004 :
6005 : /* Validate the sentinel. */
6006 90 : sentinel = fold_for_warn (argarray[nargs - 1 - pos]);
6007 138 : if ((!POINTER_TYPE_P (TREE_TYPE (sentinel))
6008 42 : || !integer_zerop (sentinel))
6009 56 : && TREE_CODE (TREE_TYPE (sentinel)) != NULLPTR_TYPE
6010 : /* Although __null (in C++) is only an integer we allow it
6011 : nevertheless, as we are guaranteed that it's exactly
6012 : as wide as a pointer, and we don't want to force
6013 : users to cast the NULL they have written there.
6014 : We warn with -Wstrict-null-sentinel, though. */
6015 138 : && (warn_strict_null_sentinel || null_node != sentinel))
6016 45 : warning (OPT_Wformat_, "missing sentinel in function call");
6017 : }
6018 : }
6019 :
6020 : /* Check that the same argument isn't passed to two or more
6021 : restrict-qualified formal and issue a -Wrestrict warning
6022 : if it is. Return true if a warning has been issued. */
6023 :
6024 : static bool
6025 53700436 : check_function_restrict (const_tree fndecl, const_tree fntype,
6026 : int nargs, tree *unfolded_argarray)
6027 : {
6028 53700436 : int i;
6029 53700436 : tree parms = TYPE_ARG_TYPES (fntype);
6030 :
6031 : /* Call fold_for_warn on all of the arguments. */
6032 53700436 : auto_vec<tree> argarray (nargs);
6033 241971231 : for (i = 0; i < nargs; i++)
6034 134570359 : argarray.quick_push (fold_for_warn (unfolded_argarray[i]));
6035 :
6036 53700436 : if (fndecl
6037 53186178 : && TREE_CODE (fndecl) == FUNCTION_DECL)
6038 : {
6039 : /* Avoid diagnosing calls built-ins with a zero size/bound
6040 : here. They are checked in more detail elsewhere. */
6041 53186178 : if (fndecl_built_in_p (fndecl, BUILT_IN_NORMAL)
6042 1817398 : && nargs == 3
6043 363269 : && TREE_CODE (argarray[2]) == INTEGER_CST
6044 53356595 : && integer_zerop (argarray[2]))
6045 : return false;
6046 :
6047 53160549 : if (DECL_ARGUMENTS (fndecl))
6048 53674807 : parms = DECL_ARGUMENTS (fndecl);
6049 : }
6050 :
6051 188168279 : for (i = 0; i < nargs; i++)
6052 134493472 : TREE_VISITED (argarray[i]) = 0;
6053 :
6054 : bool warned = false;
6055 :
6056 187287000 : for (i = 0; i < nargs && parms && parms != void_list_node; i++)
6057 : {
6058 133612193 : tree type;
6059 133612193 : if (TREE_CODE (parms) == PARM_DECL)
6060 : {
6061 16013128 : type = TREE_TYPE (parms);
6062 16013128 : parms = DECL_CHAIN (parms);
6063 : }
6064 : else
6065 : {
6066 117599065 : type = TREE_VALUE (parms);
6067 117599065 : parms = TREE_CHAIN (parms);
6068 : }
6069 133612193 : if (POINTER_TYPE_P (type)
6070 8263805 : && TYPE_RESTRICT (type)
6071 133863101 : && !TYPE_READONLY (TREE_TYPE (type)))
6072 251942 : warned |= warn_for_restrict (i, argarray.address (), nargs);
6073 : }
6074 :
6075 188168279 : for (i = 0; i < nargs; i++)
6076 134493472 : TREE_VISITED (argarray[i]) = 0;
6077 :
6078 : return warned;
6079 53700436 : }
6080 :
6081 : /* Helper for check_function_nonnull; given a list of operands which
6082 : must be non-null in ARGS, determine if operand PARAM_NUM should be
6083 : checked. */
6084 :
6085 : static bool
6086 270860 : nonnull_check_p (tree args, unsigned HOST_WIDE_INT param_num)
6087 : {
6088 270860 : unsigned HOST_WIDE_INT arg_num = 0;
6089 :
6090 717909 : for (; args; args = TREE_CHAIN (args))
6091 : {
6092 570773 : bool found = get_attribute_operand (TREE_VALUE (args), &arg_num);
6093 :
6094 570773 : gcc_assert (found);
6095 :
6096 570773 : if (arg_num == param_num)
6097 : return true;
6098 : }
6099 : return false;
6100 : }
6101 :
6102 : /* Check that the function argument PARAM (which is operand number
6103 : PARAM_NUM) is non-null. This is called by check_function_nonnull
6104 : via check_function_arguments_recurse. */
6105 :
6106 : static void
6107 699155 : check_nonnull_arg (void *ctx, tree param, unsigned HOST_WIDE_INT param_num)
6108 : {
6109 699155 : struct nonnull_arg_ctx *pctx = (struct nonnull_arg_ctx *) ctx;
6110 :
6111 : /* Just skip checking the argument if it's not a pointer. This can
6112 : happen if the "nonnull" attribute was given without an operand
6113 : list (which means to check every pointer argument). */
6114 :
6115 699155 : tree paramtype = TREE_TYPE (param);
6116 699155 : if (TREE_CODE (paramtype) != POINTER_TYPE
6117 62207 : && TREE_CODE (paramtype) != NULLPTR_TYPE)
6118 698418 : return;
6119 :
6120 : /* Diagnose the simple cases of null arguments. */
6121 636954 : if (!integer_zerop (fold_for_warn (param)))
6122 : return;
6123 :
6124 737 : auto_diagnostic_group adg;
6125 :
6126 737 : const location_t loc = EXPR_LOC_OR_LOC (param, pctx->loc);
6127 :
6128 737 : if (TREE_CODE (pctx->fntype) == METHOD_TYPE)
6129 97 : --param_num;
6130 :
6131 737 : bool warned;
6132 737 : if (param_num == 0)
6133 : {
6134 30 : warned = warning_at (loc, OPT_Wnonnull,
6135 : "%qs pointer is null", "this");
6136 30 : if (warned && pctx->fndecl)
6137 27 : inform (DECL_SOURCE_LOCATION (pctx->fndecl),
6138 : "in a call to non-static member function %qD",
6139 : pctx->fndecl);
6140 : }
6141 : else
6142 : {
6143 707 : if (pctx->other1 && pctx->other2 != pctx->other1)
6144 14 : warned = warning_at (loc, OPT_Wnonnull,
6145 : "argument %u null where non-null expected "
6146 : "because arguments %u and %u are nonzero",
6147 : (unsigned) param_num,
6148 : TREE_CODE (pctx->fntype) == METHOD_TYPE
6149 0 : ? (unsigned) pctx->other1 - 1
6150 : : (unsigned) pctx->other1,
6151 : TREE_CODE (pctx->fntype) == METHOD_TYPE
6152 0 : ? (unsigned) pctx->other2 - 1
6153 : : (unsigned) pctx->other2);
6154 693 : else if (pctx->other1)
6155 50 : warned = warning_at (loc, OPT_Wnonnull,
6156 : "argument %u null where non-null expected "
6157 : "because argument %u is nonzero",
6158 : (unsigned) param_num,
6159 : TREE_CODE (pctx->fntype) == METHOD_TYPE
6160 0 : ? (unsigned) pctx->other1 - 1
6161 : : (unsigned) pctx->other1);
6162 : else
6163 643 : warned = warning_at (loc, OPT_Wnonnull,
6164 : "argument %u null where non-null expected",
6165 : (unsigned) param_num);
6166 707 : if (warned && pctx->fndecl)
6167 676 : inform (DECL_SOURCE_LOCATION (pctx->fndecl),
6168 : "in a call to function %qD declared %qs",
6169 : pctx->fndecl,
6170 676 : pctx->other1 ? "nonnull_if_nonzero" : "nonnull");
6171 : }
6172 :
6173 734 : if (warned)
6174 734 : pctx->warned_p = true;
6175 737 : }
6176 :
6177 : /* Helper for attribute handling; fetch the operand number from
6178 : the attribute argument list. */
6179 :
6180 : bool
6181 570773 : get_attribute_operand (tree arg_num_expr, unsigned HOST_WIDE_INT *valp)
6182 : {
6183 : /* Verify the arg number is a small constant. */
6184 570773 : if (tree_fits_uhwi_p (arg_num_expr))
6185 : {
6186 570773 : *valp = tree_to_uhwi (arg_num_expr);
6187 570773 : return true;
6188 : }
6189 : else
6190 : return false;
6191 : }
6192 :
6193 : /* Arguments being collected for optimization. */
6194 : typedef const char *const_char_p; /* For DEF_VEC_P. */
6195 : static GTY(()) vec<const_char_p, va_gc> *optimize_args;
6196 :
6197 :
6198 : /* Inner function to convert a TREE_LIST to argv string to parse the optimize
6199 : options in ARGS. ATTR_P is true if this is for attribute(optimize), and
6200 : false for #pragma GCC optimize. */
6201 :
6202 : bool
6203 344130 : parse_optimize_options (tree args, bool attr_p)
6204 : {
6205 344130 : bool ret = true;
6206 344130 : unsigned opt_argc;
6207 344130 : unsigned i;
6208 344130 : const char **opt_argv;
6209 344130 : struct cl_decoded_option *decoded_options;
6210 344130 : unsigned int decoded_options_count;
6211 344130 : tree ap;
6212 :
6213 : /* Build up argv vector. Just in case the string is stored away, use garbage
6214 : collected strings. */
6215 344130 : vec_safe_truncate (optimize_args, 0);
6216 344130 : vec_safe_push (optimize_args, (const char *) NULL);
6217 :
6218 707007 : for (ap = args; ap != NULL_TREE; ap = TREE_CHAIN (ap))
6219 : {
6220 362877 : tree value = TREE_VALUE (ap);
6221 :
6222 362877 : if (TREE_CODE (value) == INTEGER_CST)
6223 : {
6224 377 : char buffer[HOST_BITS_PER_LONG / 3 + 4];
6225 377 : sprintf (buffer, "-O%ld", (long) TREE_INT_CST_LOW (value));
6226 377 : vec_safe_push (optimize_args, ggc_strdup (buffer));
6227 : }
6228 :
6229 362500 : else if (TREE_CODE (value) == STRING_CST)
6230 : {
6231 : /* Split string into multiple substrings. */
6232 362496 : size_t len = TREE_STRING_LENGTH (value);
6233 362496 : char *p = ASTRDUP (TREE_STRING_POINTER (value));
6234 362496 : char *end = p + len;
6235 362496 : char *comma;
6236 362496 : char *next_p = p;
6237 :
6238 725041 : while (next_p != NULL)
6239 : {
6240 362545 : size_t len2;
6241 362545 : char *q, *r;
6242 :
6243 362545 : p = next_p;
6244 362545 : comma = strchr (p, ',');
6245 362545 : if (comma)
6246 : {
6247 49 : len2 = comma - p;
6248 49 : *comma = '\0';
6249 49 : next_p = comma+1;
6250 : }
6251 : else
6252 : {
6253 362496 : len2 = end - p;
6254 362496 : next_p = NULL;
6255 : }
6256 :
6257 : /* If the user supplied -Oxxx or -fxxx, only allow -Oxxx or -fxxx
6258 : options. */
6259 362545 : if (*p == '-' && p[1] != 'O' && p[1] != 'f')
6260 : {
6261 0 : ret = false;
6262 0 : if (attr_p)
6263 : {
6264 0 : auto_urlify_attributes sentinel;
6265 0 : warning (OPT_Wattributes,
6266 : "bad option %qs to attribute %<optimize%>", p);
6267 0 : }
6268 : else
6269 0 : warning (OPT_Wpragmas,
6270 : "bad option %qs to pragma %<optimize%>", p);
6271 0 : continue;
6272 0 : }
6273 :
6274 : /* Can't use GC memory here, see PR88007. */
6275 362545 : r = q = XOBNEWVEC (&opts_obstack, char, len2 + 3);
6276 :
6277 362545 : if (*p != '-')
6278 : {
6279 42906 : *r++ = '-';
6280 :
6281 : /* Assume that Ox is -Ox, a numeric value is -Ox, a s by
6282 : itself is -Os, and any other switch begins with a -f. */
6283 42906 : if ((*p >= '0' && *p <= '9')
6284 42693 : || (p[0] == 's' && p[1] == '\0'))
6285 213 : *r++ = 'O';
6286 42693 : else if (*p != 'O')
6287 23368 : *r++ = 'f';
6288 : }
6289 :
6290 362545 : memcpy (r, p, len2);
6291 362545 : r[len2] = '\0';
6292 362545 : vec_safe_push (optimize_args, (const char *) q);
6293 : }
6294 :
6295 : }
6296 : }
6297 :
6298 344130 : opt_argc = optimize_args->length ();
6299 344130 : opt_argv = (const char **) alloca (sizeof (char *) * (opt_argc + 1));
6300 :
6301 707052 : for (i = 1; i < opt_argc; i++)
6302 362922 : opt_argv[i] = (*optimize_args)[i];
6303 :
6304 : /* Now parse the options. */
6305 344130 : decode_cmdline_options_to_array_default_mask (opt_argc, opt_argv,
6306 : &decoded_options,
6307 : &decoded_options_count);
6308 : /* Drop non-Optimization options. */
6309 344130 : unsigned j = 1;
6310 707052 : for (i = 1; i < decoded_options_count; ++i)
6311 : {
6312 362922 : if (! (cl_options[decoded_options[i].opt_index].flags & CL_OPTIMIZATION))
6313 : {
6314 3 : ret = false;
6315 3 : if (attr_p)
6316 : {
6317 2 : auto_urlify_attributes sentinel;
6318 2 : warning (OPT_Wattributes,
6319 : "bad option %qs to attribute %<optimize%>",
6320 2 : decoded_options[i].orig_option_with_args_text);
6321 2 : }
6322 : else
6323 1 : warning (OPT_Wpragmas,
6324 : "bad option %qs to pragma %<optimize%>",
6325 : decoded_options[i].orig_option_with_args_text);
6326 3 : continue;
6327 3 : }
6328 362919 : if (i != j)
6329 0 : decoded_options[j] = decoded_options[i];
6330 362919 : j++;
6331 : }
6332 344130 : decoded_options_count = j;
6333 :
6334 : /* Merge the decoded options with save_decoded_options. */
6335 344130 : unsigned save_opt_count = save_opt_decoded_options->length ();
6336 344130 : unsigned merged_decoded_options_count
6337 : = save_opt_count + decoded_options_count;
6338 344130 : cl_decoded_option *merged_decoded_options
6339 344130 : = XNEWVEC (cl_decoded_option, merged_decoded_options_count);
6340 :
6341 : /* Note the first decoded_options is used for the program name. */
6342 1979369 : for (unsigned i = 0; i < save_opt_count; ++i)
6343 1635239 : merged_decoded_options[i + 1] = (*save_opt_decoded_options)[i];
6344 707049 : for (unsigned i = 1; i < decoded_options_count; ++i)
6345 362919 : merged_decoded_options[save_opt_count + i] = decoded_options[i];
6346 :
6347 : /* And apply them. */
6348 344130 : decode_options (&global_options, &global_options_set,
6349 : merged_decoded_options, merged_decoded_options_count,
6350 : input_location, global_dc, NULL);
6351 344130 : free (decoded_options);
6352 :
6353 344130 : targetm.override_options_after_change();
6354 :
6355 344130 : optimize_args->truncate (0);
6356 344130 : return ret;
6357 : }
6358 :
6359 : /* Check whether ATTR is a valid attribute fallthrough. */
6360 :
6361 : bool
6362 296843597 : attribute_fallthrough_p (tree attr)
6363 : {
6364 296843597 : if (attr == error_mark_node)
6365 : return false;
6366 296843579 : tree t = lookup_attribute ("", "fallthrough", attr);
6367 296843579 : if (t == NULL_TREE)
6368 : return false;
6369 82781 : auto_urlify_attributes sentinel;
6370 : /* It is no longer true that "this attribute shall appear at most once in
6371 : each attribute-list", but we still give a warning. */
6372 82781 : if (lookup_attribute ("", "fallthrough", TREE_CHAIN (t)))
6373 9 : warning (OPT_Wattributes, "attribute %<fallthrough%> specified multiple "
6374 : "times");
6375 : /* No attribute-argument-clause shall be present. */
6376 82772 : else if (TREE_VALUE (t) != NULL_TREE)
6377 4 : warning (OPT_Wattributes, "%<fallthrough%> attribute specified with "
6378 : "a parameter");
6379 : /* Warn if other attributes are found. */
6380 165588 : for (t = attr; t != NULL_TREE; t = TREE_CHAIN (t))
6381 : {
6382 82807 : tree name = get_attribute_name (t);
6383 82807 : if (!is_attribute_p ("fallthrough", name)
6384 82807 : || !is_attribute_namespace_p ("", t))
6385 : {
6386 17 : if (!c_dialect_cxx () && get_attribute_namespace (t) == NULL_TREE)
6387 : /* The specifications of standard attributes in C mean
6388 : this is a constraint violation. */
6389 3 : pedwarn (input_location, OPT_Wattributes, "%qE attribute ignored",
6390 : get_attribute_name (t));
6391 : else
6392 14 : warning (OPT_Wattributes, "%qE attribute ignored", name);
6393 : }
6394 : }
6395 82781 : return true;
6396 82781 : }
6397 :
6398 :
6399 : /* Check for valid arguments being passed to a function with FNTYPE.
6400 : There are NARGS arguments in the array ARGARRAY. LOC should be used
6401 : for diagnostics. Return true if either -Wnonnull or -Wrestrict has
6402 : been issued.
6403 :
6404 : The arguments in ARGARRAY may not have been folded yet (e.g. for C++,
6405 : to preserve location wrappers); checks that require folded arguments
6406 : should call fold_for_warn on them.
6407 :
6408 : Use the frontend-supplied COMP_TYPES when determining if
6409 : one type is a subclass of another. */
6410 :
6411 : bool
6412 55104373 : check_function_arguments (location_t loc, const_tree fndecl, const_tree fntype,
6413 : int nargs, tree *argarray, vec<location_t> *arglocs,
6414 : bool (*comp_types) (tree, tree))
6415 : {
6416 55104373 : bool warned_p = false;
6417 :
6418 55104373 : if (c_inhibit_evaluation_warnings)
6419 : return warned_p;
6420 :
6421 : /* Check for null being passed in a pointer argument that must be
6422 : non-null. In C++, this includes the this pointer. We also need
6423 : to do this if format checking is enabled. */
6424 53705193 : if (warn_nonnull)
6425 : {
6426 6478102 : nonnull_arg_ctx ctx = { loc, fndecl, fntype, 0, 0, false };
6427 6478102 : warned_p = check_function_nonnull (ctx, nargs, argarray);
6428 : }
6429 :
6430 : /* Check for errors in format strings. */
6431 :
6432 53705193 : if (warn_format || warn_suggest_attribute_format)
6433 6542069 : check_function_format (fndecl ? fndecl : fntype, TYPE_ATTRIBUTES (fntype), nargs,
6434 : argarray, arglocs, comp_types);
6435 :
6436 53705193 : if (warn_format)
6437 6464550 : check_function_sentinel (fntype, nargs, argarray);
6438 :
6439 53705193 : if (fndecl && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
6440 : {
6441 1822155 : switch (DECL_FUNCTION_CODE (fndecl))
6442 : {
6443 : case BUILT_IN_SPRINTF:
6444 : case BUILT_IN_SPRINTF_CHK:
6445 : case BUILT_IN_SNPRINTF:
6446 : case BUILT_IN_SNPRINTF_CHK:
6447 : /* Let the sprintf pass handle these. */
6448 : return warned_p;
6449 :
6450 : default:
6451 : break;
6452 : }
6453 : }
6454 :
6455 : /* check_function_restrict sets the DECL_READ_P for arguments
6456 : so it must be called unconditionally. */
6457 53700436 : warned_p |= check_function_restrict (fndecl, fntype, nargs, argarray);
6458 :
6459 53700436 : return warned_p;
6460 : }
6461 :
6462 : /* Generic argument checking recursion routine. PARAM is the argument to
6463 : be checked. PARAM_NUM is the number of the argument. CALLBACK is invoked
6464 : once the argument is resolved. CTX is context for the callback.
6465 : OPT is the warning for which this is done. */
6466 : void
6467 755396 : check_function_arguments_recurse (void (*callback)
6468 : (void *, tree, unsigned HOST_WIDE_INT),
6469 : void *ctx, tree param,
6470 : unsigned HOST_WIDE_INT param_num,
6471 : opt_code opt)
6472 : {
6473 1178469 : if (opt != OPT_Wformat_ && warning_suppressed_p (param))
6474 : return;
6475 :
6476 805466 : if (CONVERT_EXPR_P (param)
6477 1305525 : && (TYPE_PRECISION (TREE_TYPE (param))
6478 500059 : == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (param, 0)))))
6479 : {
6480 : /* Strip coercion. */
6481 844560 : check_function_arguments_recurse (callback, ctx,
6482 422280 : TREE_OPERAND (param, 0), param_num,
6483 : opt);
6484 422280 : return;
6485 : }
6486 :
6487 754448 : if (TREE_CODE (param) == CALL_EXPR && CALL_EXPR_FN (param))
6488 : {
6489 8252 : tree type = TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (param)));
6490 8252 : tree attrs;
6491 8252 : bool found_format_arg = false;
6492 :
6493 : /* See if this is a call to a known internationalization function
6494 : that modifies a format arg. Such a function may have multiple
6495 : format_arg attributes (for example, ngettext). */
6496 :
6497 8252 : for (attrs = TYPE_ATTRIBUTES (type);
6498 8641 : attrs;
6499 389 : attrs = TREE_CHAIN (attrs))
6500 389 : if (is_attribute_p ("format_arg", get_attribute_name (attrs)))
6501 : {
6502 226 : tree inner_arg;
6503 226 : tree format_num_expr;
6504 226 : int format_num;
6505 226 : int i;
6506 226 : call_expr_arg_iterator iter;
6507 :
6508 : /* Extract the argument number, which was previously checked
6509 : to be valid. */
6510 226 : format_num_expr = TREE_VALUE (TREE_VALUE (attrs));
6511 :
6512 226 : format_num = tree_to_uhwi (format_num_expr);
6513 :
6514 226 : for (inner_arg = first_call_expr_arg (param, &iter), i = 1;
6515 320 : inner_arg != NULL_TREE;
6516 94 : inner_arg = next_call_expr_arg (&iter), i++)
6517 320 : if (i == format_num)
6518 : {
6519 226 : check_function_arguments_recurse (callback, ctx,
6520 : inner_arg, param_num,
6521 : opt);
6522 226 : found_format_arg = true;
6523 226 : break;
6524 : }
6525 : }
6526 :
6527 : /* If we found a format_arg attribute and did a recursive check,
6528 : we are done with checking this argument. Otherwise, we continue
6529 : and this will be considered a non-literal. */
6530 8252 : if (found_format_arg)
6531 : return;
6532 : }
6533 :
6534 754270 : if (TREE_CODE (param) == COND_EXPR)
6535 : {
6536 : /* Simplify to avoid warning for an impossible case. */
6537 811 : param = fold_for_warn (param);
6538 811 : if (TREE_CODE (param) == COND_EXPR)
6539 : {
6540 : /* Check both halves of the conditional expression. */
6541 793 : check_function_arguments_recurse (callback, ctx,
6542 793 : TREE_OPERAND (param, 1),
6543 : param_num, opt);
6544 1586 : check_function_arguments_recurse (callback, ctx,
6545 793 : TREE_OPERAND (param, 2),
6546 : param_num, opt);
6547 793 : return;
6548 : }
6549 : }
6550 :
6551 753477 : (*callback) (ctx, param, param_num);
6552 : }
6553 :
6554 : /* Checks for a builtin function FNDECL that the number of arguments
6555 : NARGS against the required number REQUIRED and issues an error if
6556 : there is a mismatch. Returns true if the number of arguments is
6557 : correct, otherwise false. LOC is the location of FNDECL. */
6558 :
6559 : static bool
6560 865414 : builtin_function_validate_nargs (location_t loc, tree fndecl, int nargs,
6561 : int required, bool complain)
6562 : {
6563 865414 : if (nargs < required)
6564 : {
6565 182 : if (complain)
6566 143 : error_at (loc, "too few arguments to function %qE", fndecl);
6567 182 : return false;
6568 : }
6569 865232 : else if (nargs > required)
6570 : {
6571 138 : if (complain)
6572 93 : error_at (loc, "too many arguments to function %qE", fndecl);
6573 138 : return false;
6574 : }
6575 : return true;
6576 : }
6577 :
6578 : /* Helper macro for check_builtin_function_arguments. */
6579 : #define ARG_LOCATION(N) \
6580 : (arg_loc.is_empty () \
6581 : ? EXPR_LOC_OR_LOC (args[(N)], input_location) \
6582 : : expansion_point_location (arg_loc[(N)]))
6583 :
6584 : /* Verifies the NARGS arguments ARGS to the builtin function FNDECL.
6585 : Returns false if there was an error, otherwise true. LOC is the
6586 : location of the function; ARG_LOC is a vector of locations of the
6587 : arguments. If FNDECL is the result of resolving an overloaded
6588 : target built-in, ORIG_FNDECL is the original function decl,
6589 : otherwise it is null. */
6590 :
6591 : bool
6592 40397123 : check_builtin_function_arguments (location_t loc, vec<location_t> arg_loc,
6593 : tree fndecl, tree orig_fndecl, int nargs,
6594 : tree *args, bool complain)
6595 : {
6596 40397123 : if (!fndecl_built_in_p (fndecl))
6597 : return true;
6598 :
6599 40397123 : if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD)
6600 33098498 : return (!targetm.check_builtin_call
6601 33098498 : || targetm.check_builtin_call (loc, arg_loc, fndecl, orig_fndecl,
6602 : nargs, args, complain));
6603 :
6604 7298625 : if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_FRONTEND)
6605 : return true;
6606 :
6607 7235837 : gcc_assert (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL);
6608 7235837 : switch (DECL_FUNCTION_CODE (fndecl))
6609 : {
6610 2 : case BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX:
6611 2 : if (!tree_fits_uhwi_p (args[2]))
6612 : {
6613 0 : if (complain)
6614 0 : error_at (
6615 0 : ARG_LOCATION (2),
6616 : "third argument to function %qE must be a constant integer",
6617 : fndecl);
6618 0 : return false;
6619 : }
6620 : /* fall through */
6621 :
6622 264 : case BUILT_IN_ALLOCA_WITH_ALIGN:
6623 264 : {
6624 : /* Get the requested alignment (in bits) if it's a constant
6625 : integer expression. */
6626 264 : unsigned HOST_WIDE_INT align
6627 264 : = tree_fits_uhwi_p (args[1]) ? tree_to_uhwi (args[1]) : 0;
6628 :
6629 : /* Determine if the requested alignment is a power of 2. */
6630 264 : if ((align & (align - 1)))
6631 : align = 0;
6632 :
6633 : /* The maximum alignment in bits corresponding to the same
6634 : maximum in bytes enforced in check_user_alignment(). */
6635 315 : unsigned maxalign = (UINT_MAX >> 1) + 1;
6636 :
6637 : /* Reject invalid alignments. */
6638 181 : if (align < BITS_PER_UNIT || maxalign < align)
6639 : {
6640 134 : if (complain)
6641 169 : error_at (ARG_LOCATION (1),
6642 : "second argument to function %qE must be a constant "
6643 : "integer power of 2 between %qi and %qu bits",
6644 : fndecl, BITS_PER_UNIT, maxalign);
6645 134 : return false;
6646 : }
6647 : return true;
6648 : }
6649 :
6650 201740 : case BUILT_IN_CONSTANT_P:
6651 201740 : return builtin_function_validate_nargs (loc, fndecl, nargs, 1, complain);
6652 :
6653 192074 : case BUILT_IN_ISFINITE:
6654 192074 : case BUILT_IN_ISINF:
6655 192074 : case BUILT_IN_ISINF_SIGN:
6656 192074 : case BUILT_IN_ISNAN:
6657 192074 : case BUILT_IN_ISNORMAL:
6658 192074 : case BUILT_IN_ISSIGNALING:
6659 192074 : case BUILT_IN_SIGNBIT:
6660 192074 : if (builtin_function_validate_nargs (loc, fndecl, nargs, 1, complain))
6661 : {
6662 192039 : if (TREE_CODE (TREE_TYPE (args[0])) != REAL_TYPE)
6663 : {
6664 37 : if (complain)
6665 28 : error_at (ARG_LOCATION (0),
6666 : "non-floating-point argument in "
6667 : "call to function %qE",
6668 : fndecl);
6669 37 : return false;
6670 : }
6671 : return true;
6672 : }
6673 : return false;
6674 :
6675 193324 : case BUILT_IN_ISGREATER:
6676 193324 : case BUILT_IN_ISGREATEREQUAL:
6677 193324 : case BUILT_IN_ISLESS:
6678 193324 : case BUILT_IN_ISLESSEQUAL:
6679 193324 : case BUILT_IN_ISLESSGREATER:
6680 193324 : case BUILT_IN_ISUNORDERED:
6681 193324 : case BUILT_IN_ISEQSIG:
6682 193324 : if (builtin_function_validate_nargs (loc, fndecl, nargs, 2, complain))
6683 : {
6684 193289 : enum tree_code code0, code1;
6685 193289 : code0 = TREE_CODE (TREE_TYPE (args[0]));
6686 193289 : code1 = TREE_CODE (TREE_TYPE (args[1]));
6687 193289 : if (!((code0 == REAL_TYPE && code1 == REAL_TYPE)
6688 154 : || (code0 == REAL_TYPE
6689 56 : && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
6690 99 : || ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE)
6691 88 : && code1 == REAL_TYPE)))
6692 : {
6693 39 : if (complain)
6694 18 : error_at (loc,
6695 : "non-floating-point arguments in call to "
6696 : "function %qE",
6697 : fndecl);
6698 39 : return false;
6699 : }
6700 : return true;
6701 : }
6702 : return false;
6703 :
6704 32938 : case BUILT_IN_FPCLASSIFY:
6705 32938 : if (builtin_function_validate_nargs (loc, fndecl, nargs, 6, complain))
6706 : {
6707 197556 : for (unsigned int i = 0; i < 5; i++)
6708 164634 : if (TREE_CODE (args[i]) != INTEGER_CST)
6709 : {
6710 12 : if (complain)
6711 12 : error_at (ARG_LOCATION (i),
6712 : "non-const integer argument %u in "
6713 : "call to function %qE",
6714 : i + 1, fndecl);
6715 12 : return false;
6716 : }
6717 :
6718 32922 : if (TREE_CODE (TREE_TYPE (args[5])) != REAL_TYPE)
6719 : {
6720 2 : if (complain)
6721 4 : error_at (ARG_LOCATION (5),
6722 : "non-floating-point argument in "
6723 : "call to function %qE",
6724 : fndecl);
6725 2 : return false;
6726 : }
6727 : return true;
6728 : }
6729 : return false;
6730 :
6731 435 : case BUILT_IN_ASSUME_ALIGNED:
6732 850 : if (builtin_function_validate_nargs (loc, fndecl, nargs, 2 + (nargs > 2),
6733 : complain))
6734 : {
6735 433 : if (nargs >= 3
6736 18 : && TREE_CODE (TREE_TYPE (args[2])) != INTEGER_TYPE
6737 440 : && TREE_CODE (TREE_TYPE (args[2])) != BITINT_TYPE)
6738 : {
6739 6 : if (complain)
6740 6 : error_at (ARG_LOCATION (2),
6741 : "non-integer argument 3 in call to "
6742 : "function %qE",
6743 : fndecl);
6744 6 : return false;
6745 : }
6746 : return true;
6747 : }
6748 : return false;
6749 :
6750 149804 : case BUILT_IN_ADD_OVERFLOW:
6751 149804 : case BUILT_IN_SUB_OVERFLOW:
6752 149804 : case BUILT_IN_MUL_OVERFLOW:
6753 149804 : if (builtin_function_validate_nargs (loc, fndecl, nargs, 3, complain))
6754 : {
6755 : unsigned i;
6756 448956 : for (i = 0; i < 2; i++)
6757 299330 : if (!INTEGRAL_TYPE_P (TREE_TYPE (args[i])))
6758 : {
6759 55 : if (complain)
6760 77 : error_at (ARG_LOCATION (i),
6761 : "argument %u in call to function "
6762 : "%qE does not have integral type",
6763 : i + 1, fndecl);
6764 55 : return false;
6765 : }
6766 149626 : if (TREE_CODE (TREE_TYPE (args[2])) != POINTER_TYPE
6767 149626 : || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (args[2]))))
6768 : {
6769 60 : if (complain)
6770 75 : error_at (ARG_LOCATION (2),
6771 : "argument 3 in call to function %qE "
6772 : "does not have pointer to integral type",
6773 : fndecl);
6774 60 : return false;
6775 : }
6776 149566 : else if (TREE_CODE (TREE_TYPE (TREE_TYPE (args[2]))) == ENUMERAL_TYPE)
6777 : {
6778 16 : if (complain)
6779 11 : error_at (ARG_LOCATION (2),
6780 : "argument 3 in call to function %qE "
6781 : "has pointer to enumerated type",
6782 : fndecl);
6783 16 : return false;
6784 : }
6785 149550 : else if (TREE_CODE (TREE_TYPE (TREE_TYPE (args[2]))) == BOOLEAN_TYPE)
6786 : {
6787 21 : if (complain)
6788 16 : error_at (ARG_LOCATION (2),
6789 : "argument 3 in call to function %qE "
6790 : "has pointer to boolean type",
6791 : fndecl);
6792 21 : return false;
6793 : }
6794 149529 : else if (TYPE_READONLY (TREE_TYPE (TREE_TYPE (args[2]))))
6795 : {
6796 30 : if (complain)
6797 30 : error_at (ARG_LOCATION (2),
6798 : "argument %u in call to function %qE "
6799 : "has pointer to %qs type (%qT)",
6800 21 : 3, fndecl, "const", TREE_TYPE (args[2]));
6801 30 : return false;
6802 : }
6803 149499 : else if (TYPE_ATOMIC (TREE_TYPE (TREE_TYPE (args[2]))))
6804 : {
6805 6 : if (complain)
6806 12 : error_at (ARG_LOCATION (2),
6807 : "argument %u in call to function %qE "
6808 : "has pointer to %qs type (%qT)",
6809 6 : 3, fndecl, "_Atomic", TREE_TYPE (args[2]));
6810 6 : return false;
6811 : }
6812 : return true;
6813 : }
6814 : return false;
6815 :
6816 41868 : case BUILT_IN_ADD_OVERFLOW_P:
6817 41868 : case BUILT_IN_SUB_OVERFLOW_P:
6818 41868 : case BUILT_IN_MUL_OVERFLOW_P:
6819 41868 : if (builtin_function_validate_nargs (loc, fndecl, nargs, 3, complain))
6820 : {
6821 : unsigned i;
6822 167261 : for (i = 0; i < 3; i++)
6823 125463 : if (!INTEGRAL_TYPE_P (TREE_TYPE (args[i])))
6824 : {
6825 37 : if (complain)
6826 35 : error_at (ARG_LOCATION (i),
6827 : "argument %u in call to function "
6828 : "%qE does not have integral type",
6829 : i + 1, fndecl);
6830 37 : return false;
6831 : }
6832 41798 : if (TREE_CODE (TREE_TYPE (args[2])) == ENUMERAL_TYPE)
6833 : {
6834 13 : if (complain)
6835 5 : error_at (ARG_LOCATION (2),
6836 : "argument %u in call to function "
6837 : "%qE has enumerated type",
6838 : 3, fndecl);
6839 13 : return false;
6840 : }
6841 41785 : else if (TREE_CODE (TREE_TYPE (args[2])) == BOOLEAN_TYPE)
6842 : {
6843 13 : if (complain)
6844 5 : error_at (ARG_LOCATION (2),
6845 : "argument %u in call to function "
6846 : "%qE has boolean type",
6847 : 3, fndecl);
6848 13 : return false;
6849 : }
6850 : return true;
6851 : }
6852 : return false;
6853 :
6854 13028 : case BUILT_IN_CLEAR_PADDING:
6855 13028 : if (builtin_function_validate_nargs (loc, fndecl, nargs, 1, complain))
6856 : {
6857 13013 : if (!POINTER_TYPE_P (TREE_TYPE (args[0])))
6858 : {
6859 7 : if (complain)
6860 5 : error_at (ARG_LOCATION (0),
6861 : "argument %u in call to function "
6862 : "%qE does not have pointer type",
6863 : 1, fndecl);
6864 7 : return false;
6865 : }
6866 13006 : else if (!COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (args[0]))))
6867 : {
6868 11 : if (complain)
6869 10 : error_at (ARG_LOCATION (0),
6870 : "argument %u in call to function "
6871 : "%qE points to incomplete type",
6872 : 1, fndecl);
6873 11 : return false;
6874 : }
6875 12995 : else if (TYPE_READONLY (TREE_TYPE (TREE_TYPE (args[0]))))
6876 : {
6877 7 : if (complain)
6878 5 : error_at (ARG_LOCATION (0),
6879 : "argument %u in call to function %qE "
6880 : "has pointer to %qs type (%qT)",
6881 4 : 1, fndecl, "const", TREE_TYPE (args[0]));
6882 7 : return false;
6883 : }
6884 12988 : else if (TYPE_ATOMIC (TREE_TYPE (TREE_TYPE (args[0]))))
6885 : {
6886 0 : if (complain)
6887 0 : error_at (ARG_LOCATION (0),
6888 : "argument %u in call to function %qE "
6889 : "has pointer to %qs type (%qT)",
6890 0 : 1, fndecl, "_Atomic", TREE_TYPE (args[0]));
6891 0 : return false;
6892 : }
6893 : return true;
6894 : }
6895 : return false;
6896 :
6897 93981 : case BUILT_IN_CLZG:
6898 93981 : case BUILT_IN_CTZG:
6899 93981 : case BUILT_IN_CLRSBG:
6900 93981 : case BUILT_IN_FFSG:
6901 93981 : case BUILT_IN_PARITYG:
6902 93981 : case BUILT_IN_POPCOUNTG:
6903 93981 : if (nargs == 2
6904 93981 : && (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_CLZG
6905 20512 : || DECL_FUNCTION_CODE (fndecl) == BUILT_IN_CTZG))
6906 : {
6907 53778 : if (!INTEGRAL_TYPE_P (TREE_TYPE (args[1])))
6908 : {
6909 18 : if (complain)
6910 15 : error_at (ARG_LOCATION (1),
6911 : "argument %u in call to function "
6912 : "%qE does not have integral type",
6913 : 2, fndecl);
6914 18 : return false;
6915 : }
6916 53760 : if ((TYPE_PRECISION (TREE_TYPE (args[1]))
6917 53760 : > TYPE_PRECISION (integer_type_node))
6918 53760 : || (TYPE_PRECISION (TREE_TYPE (args[1]))
6919 53746 : == TYPE_PRECISION (integer_type_node)
6920 53740 : && TYPE_UNSIGNED (TREE_TYPE (args[1]))))
6921 : {
6922 28 : if (complain)
6923 26 : error_at (ARG_LOCATION (1),
6924 : "argument %u in call to function "
6925 : "%qE does not have %<int%> type",
6926 : 2, fndecl);
6927 28 : return false;
6928 : }
6929 : }
6930 40203 : else if (!builtin_function_validate_nargs (loc, fndecl, nargs, 1,
6931 : complain))
6932 : return false;
6933 :
6934 93869 : if (!INTEGRAL_TYPE_P (TREE_TYPE (args[0])))
6935 : {
6936 82 : if (complain)
6937 80 : error_at (ARG_LOCATION (0),
6938 : "argument %u in call to function "
6939 : "%qE does not have integral type",
6940 : 1, fndecl);
6941 82 : return false;
6942 : }
6943 93787 : if (TREE_CODE (TREE_TYPE (args[0])) == ENUMERAL_TYPE)
6944 : {
6945 42 : if (complain)
6946 24 : error_at (ARG_LOCATION (0),
6947 : "argument %u in call to function "
6948 : "%qE has enumerated type",
6949 : 1, fndecl);
6950 42 : return false;
6951 : }
6952 93745 : if (TREE_CODE (TREE_TYPE (args[0])) == BOOLEAN_TYPE)
6953 : {
6954 50 : if (complain)
6955 40 : error_at (ARG_LOCATION (0),
6956 : "argument %u in call to function "
6957 : "%qE has boolean type",
6958 : 1, fndecl);
6959 50 : return false;
6960 : }
6961 93695 : if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_FFSG
6962 93695 : || DECL_FUNCTION_CODE (fndecl) == BUILT_IN_CLRSBG)
6963 : {
6964 288 : if (TYPE_UNSIGNED (TREE_TYPE (args[0])))
6965 : {
6966 14 : if (complain)
6967 10 : error_at (ARG_LOCATION (0),
6968 : "argument 1 in call to function "
6969 : "%qE has unsigned type",
6970 : fndecl);
6971 14 : return false;
6972 : }
6973 : }
6974 93407 : else if (!TYPE_UNSIGNED (TREE_TYPE (args[0])))
6975 : {
6976 42 : if (complain)
6977 42 : error_at (ARG_LOCATION (0),
6978 : "argument 1 in call to function "
6979 : "%qE has signed type",
6980 : fndecl);
6981 42 : return false;
6982 : }
6983 : return true;
6984 :
6985 : default:
6986 : return true;
6987 : }
6988 : }
6989 :
6990 : /* Subroutine of c_parse_error.
6991 : Return the result of concatenating LHS and RHS. RHS is really
6992 : a string literal, its first character is indicated by RHS_START and
6993 : RHS_SIZE is its length (including the terminating NUL character).
6994 :
6995 : The caller is responsible for deleting the returned pointer. */
6996 :
6997 : static char *
6998 8897 : catenate_strings (const char *lhs, const char *rhs_start, int rhs_size)
6999 : {
7000 8897 : const size_t lhs_size = strlen (lhs);
7001 8897 : char *result = XNEWVEC (char, lhs_size + rhs_size);
7002 8897 : memcpy (result, lhs, lhs_size);
7003 8897 : memcpy (result + lhs_size, rhs_start, rhs_size);
7004 8897 : return result;
7005 : }
7006 :
7007 : /* Issue the error given by GMSGID at RICHLOC, indicating that it occurred
7008 : before TOKEN, which had the associated VALUE. */
7009 :
7010 : void
7011 8910 : c_parse_error (const char *gmsgid, enum cpp_ttype token_type,
7012 : tree value, unsigned char token_flags,
7013 : rich_location *richloc)
7014 : {
7015 : #define catenate_messages(M1, M2) catenate_strings ((M1), (M2), sizeof (M2))
7016 :
7017 8910 : char *message = NULL;
7018 :
7019 8910 : if (token_type == CPP_EOF)
7020 510 : message = catenate_messages (gmsgid, " at end of input");
7021 8400 : else if (token_type == CPP_CHAR
7022 : || token_type == CPP_WCHAR
7023 : || token_type == CPP_CHAR16
7024 : || token_type == CPP_CHAR32
7025 8400 : || token_type == CPP_UTF8CHAR)
7026 : {
7027 24 : unsigned int val = TREE_INT_CST_LOW (value);
7028 24 : const char *prefix;
7029 :
7030 24 : switch (token_type)
7031 : {
7032 : default:
7033 : prefix = "";
7034 : break;
7035 0 : case CPP_WCHAR:
7036 0 : prefix = "L";
7037 0 : break;
7038 0 : case CPP_CHAR16:
7039 0 : prefix = "u";
7040 0 : break;
7041 0 : case CPP_CHAR32:
7042 0 : prefix = "U";
7043 0 : break;
7044 0 : case CPP_UTF8CHAR:
7045 0 : prefix = "u8";
7046 0 : break;
7047 : }
7048 :
7049 24 : if (val <= UCHAR_MAX && ISGRAPH (val))
7050 20 : message = catenate_messages (gmsgid, " before %s'%c'");
7051 : else
7052 4 : message = catenate_messages (gmsgid, " before %s'\\x%x'");
7053 :
7054 24 : error_at (richloc, message, prefix, val);
7055 24 : free (message);
7056 24 : message = NULL;
7057 : }
7058 8376 : else if (token_type == CPP_CHAR_USERDEF
7059 : || token_type == CPP_WCHAR_USERDEF
7060 : || token_type == CPP_CHAR16_USERDEF
7061 : || token_type == CPP_CHAR32_USERDEF
7062 8376 : || token_type == CPP_UTF8CHAR_USERDEF)
7063 12 : message = catenate_messages (gmsgid,
7064 : " before user-defined character literal");
7065 8364 : else if (token_type == CPP_STRING_USERDEF
7066 : || token_type == CPP_WSTRING_USERDEF
7067 : || token_type == CPP_STRING16_USERDEF
7068 : || token_type == CPP_STRING32_USERDEF
7069 8364 : || token_type == CPP_UTF8STRING_USERDEF)
7070 25 : message = catenate_messages (gmsgid, " before user-defined string literal");
7071 8339 : else if (token_type == CPP_STRING
7072 : || token_type == CPP_WSTRING
7073 : || token_type == CPP_STRING16
7074 : || token_type == CPP_STRING32
7075 8339 : || token_type == CPP_UTF8STRING)
7076 44 : message = catenate_messages (gmsgid, " before string constant");
7077 8295 : else if (token_type == CPP_NUMBER)
7078 539 : message = catenate_messages (gmsgid, " before numeric constant");
7079 7756 : else if (token_type == CPP_NAME)
7080 : {
7081 2138 : message = catenate_messages (gmsgid, " before %qE");
7082 2138 : error_at (richloc, message, value);
7083 2138 : free (message);
7084 2138 : message = NULL;
7085 : }
7086 5618 : else if (token_type == CPP_PRAGMA)
7087 20 : message = catenate_messages (gmsgid, " before %<#pragma%>");
7088 5598 : else if (token_type == CPP_PRAGMA_EOL)
7089 476 : message = catenate_messages (gmsgid, " before end of line");
7090 5122 : else if (token_type == CPP_DECLTYPE)
7091 12 : message = catenate_messages (gmsgid, " before %<decltype%>");
7092 5110 : else if (token_type == CPP_EMBED)
7093 0 : message = catenate_messages (gmsgid, " before %<#embed%>");
7094 5110 : else if (token_type < N_TTYPES)
7095 : {
7096 5097 : message = catenate_messages (gmsgid, " before %qs token");
7097 5097 : error_at (richloc, message, cpp_type2name (token_type, token_flags));
7098 5097 : free (message);
7099 5097 : message = NULL;
7100 : }
7101 : else
7102 13 : error_at (richloc, gmsgid);
7103 :
7104 8910 : if (message)
7105 : {
7106 1638 : error_at (richloc, message);
7107 1638 : free (message);
7108 : }
7109 : #undef catenate_messages
7110 8910 : }
7111 :
7112 : /* Return the gcc option code associated with the reason for a cpp
7113 : message, or 0 if none. */
7114 :
7115 : static diagnostics::option_id
7116 143542 : c_option_controlling_cpp_diagnostic (enum cpp_warning_reason reason)
7117 : {
7118 143542 : const struct cpp_reason_option_codes_t *entry;
7119 :
7120 4129240 : for (entry = cpp_reason_option_codes; entry->reason != CPP_W_NONE; entry++)
7121 : {
7122 4122274 : if (entry->reason == reason)
7123 136576 : return entry->option_code;
7124 : }
7125 0 : return 0;
7126 : }
7127 :
7128 : /* Return TRUE if the given option index corresponds to a diagnostic
7129 : issued by libcpp. Linear search seems fine for now. */
7130 : bool
7131 2373740 : c_option_is_from_cpp_diagnostics (int option_index)
7132 : {
7133 53754684 : for (auto entry = cpp_reason_option_codes; entry->reason != CPP_W_NONE;
7134 : ++entry)
7135 : {
7136 52929438 : if (entry->option_code == option_index)
7137 : return true;
7138 : }
7139 : return false;
7140 : }
7141 :
7142 : /* Callback from cpp_diagnostic for PFILE to print diagnostics from the
7143 : preprocessor. The diagnostic is of type LEVEL, with REASON set
7144 : to the reason code if LEVEL is represents a warning, at location
7145 : RICHLOC unless this is after lexing and the compiler's location
7146 : should be used instead; MSG is the translated message and AP
7147 : the arguments. Returns true if a diagnostic was emitted, false
7148 : otherwise. */
7149 :
7150 : bool
7151 143552 : c_cpp_diagnostic (cpp_reader *pfile ATTRIBUTE_UNUSED,
7152 : enum cpp_diagnostic_level level,
7153 : enum cpp_warning_reason reason,
7154 : rich_location *richloc,
7155 : const char *msg, va_list *ap)
7156 : {
7157 143552 : diagnostics::diagnostic_info diagnostic;
7158 143552 : enum diagnostics::kind dlevel;
7159 143552 : bool save_warn_system_headers = global_dc->m_warn_system_headers;
7160 143552 : bool ret;
7161 :
7162 143552 : switch (level)
7163 : {
7164 95 : case CPP_DL_WARNING_SYSHDR:
7165 95 : if (flag_no_output)
7166 : return false;
7167 94 : global_dc->m_warn_system_headers = 1;
7168 : /* Fall through. */
7169 24712 : case CPP_DL_WARNING:
7170 24712 : if (flag_no_output)
7171 : return false;
7172 : dlevel = diagnostics::kind::warning;
7173 : break;
7174 113727 : case CPP_DL_PEDWARN:
7175 113727 : if (flag_no_output && !flag_pedantic_errors)
7176 : return false;
7177 : dlevel = diagnostics::kind::pedwarn;
7178 : break;
7179 : case CPP_DL_ERROR:
7180 : dlevel = diagnostics::kind::error;
7181 : break;
7182 0 : case CPP_DL_ICE:
7183 0 : dlevel = diagnostics::kind::ice;
7184 0 : break;
7185 604 : case CPP_DL_NOTE:
7186 604 : dlevel = diagnostics::kind::note;
7187 604 : break;
7188 371 : case CPP_DL_FATAL:
7189 371 : dlevel = diagnostics::kind::fatal;
7190 371 : break;
7191 0 : default:
7192 0 : gcc_unreachable ();
7193 : }
7194 143542 : if (override_libcpp_locations)
7195 239 : richloc->set_range (0, input_location, SHOW_RANGE_WITH_CARET);
7196 143542 : diagnostic_set_info_translated (&diagnostic, msg, ap,
7197 : richloc, dlevel);
7198 287084 : diagnostic_set_option_id (&diagnostic,
7199 : c_option_controlling_cpp_diagnostic (reason));
7200 143542 : ret = diagnostic_report_diagnostic (global_dc, &diagnostic);
7201 143171 : if (level == CPP_DL_WARNING_SYSHDR)
7202 94 : global_dc->m_warn_system_headers = save_warn_system_headers;
7203 : return ret;
7204 143181 : }
7205 :
7206 : /* Convert a character from the host to the target execution character
7207 : set. cpplib handles this, mostly. */
7208 :
7209 : HOST_WIDE_INT
7210 6574117 : c_common_to_target_charset (HOST_WIDE_INT c)
7211 : {
7212 : /* Character constants in GCC proper are sign-extended under -fsigned-char,
7213 : zero-extended under -fno-signed-char. cpplib insists that characters
7214 : and character constants are always unsigned. Hence we must convert
7215 : back and forth. */
7216 6574117 : cppchar_t uc = ((cppchar_t)c) & ((((cppchar_t)1) << CHAR_BIT)-1);
7217 :
7218 6574117 : uc = cpp_host_to_exec_charset (parse_in, uc);
7219 :
7220 6574117 : if (flag_signed_char)
7221 6574020 : return ((HOST_WIDE_INT)uc) << (HOST_BITS_PER_WIDE_INT - CHAR_TYPE_SIZE)
7222 6574020 : >> (HOST_BITS_PER_WIDE_INT - CHAR_TYPE_SIZE);
7223 : else
7224 97 : return uc;
7225 : }
7226 :
7227 : /* Fold an offsetof-like expression. EXPR is a nested sequence of component
7228 : references with an INDIRECT_REF of a constant at the bottom; much like the
7229 : traditional rendering of offsetof as a macro. TYPE is the desired type of
7230 : the whole expression. Return the folded result. */
7231 :
7232 : tree
7233 15171 : fold_offsetof (tree expr, tree type, enum tree_code ctx)
7234 : {
7235 15181 : tree base, off, t;
7236 15181 : tree_code code = TREE_CODE (expr);
7237 15181 : switch (code)
7238 : {
7239 : case ERROR_MARK:
7240 : return expr;
7241 :
7242 1 : case REALPART_EXPR:
7243 1 : return fold_offsetof (TREE_OPERAND (expr, 0), type, code);
7244 :
7245 1 : case IMAGPART_EXPR:
7246 1 : base = fold_offsetof (TREE_OPERAND (expr, 0), type, code);
7247 1 : if (base == error_mark_node)
7248 : return base;
7249 1 : off = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (TREE_OPERAND (expr, 0))));
7250 1 : break;
7251 :
7252 12 : case VAR_DECL:
7253 12 : error ("cannot apply %<offsetof%> to static data member %qD", expr);
7254 12 : return error_mark_node;
7255 :
7256 9 : case CALL_EXPR:
7257 9 : case TARGET_EXPR:
7258 9 : error ("cannot apply %<offsetof%> when %<operator[]%> is overloaded");
7259 9 : return error_mark_node;
7260 :
7261 6667 : case NOP_EXPR:
7262 6667 : case INDIRECT_REF:
7263 6667 : if (!TREE_CONSTANT (TREE_OPERAND (expr, 0)))
7264 : {
7265 17 : error ("cannot apply %<offsetof%> to a non constant address");
7266 17 : return error_mark_node;
7267 : }
7268 6650 : return convert (type, TREE_OPERAND (expr, 0));
7269 :
7270 7255 : case COMPONENT_REF:
7271 7255 : base = fold_offsetof (TREE_OPERAND (expr, 0), type, code);
7272 7255 : if (base == error_mark_node)
7273 : return base;
7274 :
7275 7252 : t = TREE_OPERAND (expr, 1);
7276 7252 : if (DECL_C_BIT_FIELD (t))
7277 : {
7278 1 : error ("attempt to take address of bit-field structure "
7279 : "member %qD", t);
7280 1 : return error_mark_node;
7281 : }
7282 7251 : off = size_binop_loc (input_location, PLUS_EXPR, DECL_FIELD_OFFSET (t),
7283 7251 : size_int (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (t))
7284 : / BITS_PER_UNIT));
7285 7251 : break;
7286 :
7287 1226 : case ARRAY_REF:
7288 1226 : base = fold_offsetof (TREE_OPERAND (expr, 0), type, code);
7289 1226 : if (base == error_mark_node)
7290 : return base;
7291 :
7292 1223 : t = TREE_OPERAND (expr, 1);
7293 1223 : STRIP_ANY_LOCATION_WRAPPER (t);
7294 :
7295 : /* Check if the offset goes beyond the upper bound of the array. */
7296 1223 : if (TREE_CODE (t) == INTEGER_CST && tree_int_cst_sgn (t) >= 0)
7297 : {
7298 956 : tree upbound = array_ref_up_bound (expr);
7299 956 : if (upbound != NULL_TREE
7300 844 : && TREE_CODE (upbound) == INTEGER_CST
7301 1800 : && !tree_int_cst_equal (upbound,
7302 844 : TYPE_MAX_VALUE (TREE_TYPE (upbound))))
7303 : {
7304 835 : if (ctx != ARRAY_REF && ctx != COMPONENT_REF)
7305 433 : upbound = size_binop (PLUS_EXPR, upbound,
7306 : build_int_cst (TREE_TYPE (upbound), 1));
7307 835 : if (tree_int_cst_lt (upbound, t))
7308 : {
7309 244 : tree v;
7310 :
7311 244 : for (v = TREE_OPERAND (expr, 0);
7312 420 : TREE_CODE (v) == COMPONENT_REF;
7313 176 : v = TREE_OPERAND (v, 0))
7314 280 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v, 0)))
7315 : == RECORD_TYPE)
7316 : {
7317 220 : tree fld_chain = DECL_CHAIN (TREE_OPERAND (v, 1));
7318 307 : for (; fld_chain; fld_chain = DECL_CHAIN (fld_chain))
7319 191 : if (TREE_CODE (fld_chain) == FIELD_DECL)
7320 : break;
7321 :
7322 : if (fld_chain)
7323 : break;
7324 : }
7325 : /* Don't warn if the array might be considered a poor
7326 : man's flexible array member with a very permissive
7327 : definition thereof. */
7328 244 : if (TREE_CODE (v) == ARRAY_REF
7329 172 : || TREE_CODE (v) == COMPONENT_REF)
7330 176 : warning (OPT_Warray_bounds_,
7331 : "index %E denotes an offset "
7332 : "greater than size of %qT",
7333 176 : t, TREE_TYPE (TREE_OPERAND (expr, 0)));
7334 : }
7335 : }
7336 : }
7337 :
7338 1223 : t = convert (sizetype, t);
7339 1223 : off = size_binop (MULT_EXPR, TYPE_SIZE_UNIT (TREE_TYPE (expr)), t);
7340 1223 : break;
7341 :
7342 9 : case COMPOUND_EXPR:
7343 : /* Handle static members of volatile structs. */
7344 9 : t = TREE_OPERAND (expr, 1);
7345 9 : gcc_checking_assert (VAR_P (get_base_address (t)));
7346 : return fold_offsetof (t, type);
7347 :
7348 0 : default:
7349 0 : gcc_unreachable ();
7350 : }
7351 :
7352 8475 : if (!POINTER_TYPE_P (type))
7353 7603 : return size_binop (PLUS_EXPR, base, convert (type, off));
7354 872 : return fold_build_pointer_plus (base, off);
7355 : }
7356 :
7357 : /* *PTYPE is an incomplete array. Complete it with a domain based on
7358 : INITIAL_VALUE. If INITIAL_VALUE is not present, use 1 if DO_DEFAULT
7359 : is true. Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
7360 : 2 if INITIAL_VALUE was NULL, and 3 if INITIAL_VALUE was empty. */
7361 :
7362 : int
7363 619572 : complete_array_type (tree *ptype, tree initial_value, bool do_default)
7364 : {
7365 619572 : tree maxindex, type, main_type, elt, unqual_elt;
7366 619572 : int failure = 0, quals;
7367 619572 : bool overflow_p = false;
7368 :
7369 619572 : maxindex = size_zero_node;
7370 619572 : if (initial_value)
7371 : {
7372 612082 : STRIP_ANY_LOCATION_WRAPPER (initial_value);
7373 :
7374 612082 : if (TREE_CODE (initial_value) == STRING_CST)
7375 : {
7376 460485 : int eltsize
7377 460485 : = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value)));
7378 460485 : maxindex = size_int (TREE_STRING_LENGTH (initial_value) / eltsize
7379 : - 1);
7380 : }
7381 151597 : else if (TREE_CODE (initial_value) == CONSTRUCTOR)
7382 : {
7383 150665 : vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (initial_value);
7384 :
7385 150665 : if (vec_safe_is_empty (v))
7386 : {
7387 430 : if (pedantic)
7388 71 : failure = 3;
7389 430 : maxindex = ssize_int (-1);
7390 : }
7391 : else
7392 : {
7393 150235 : tree curindex;
7394 150235 : unsigned HOST_WIDE_INT cnt = 1;
7395 150235 : constructor_elt *ce;
7396 150235 : bool fold_p = false;
7397 :
7398 150235 : if ((*v)[0].index)
7399 140655 : maxindex = (*v)[0].index, fold_p = true;
7400 150235 : if (TREE_CODE ((*v)[0].value) == RAW_DATA_CST)
7401 4 : cnt = 0;
7402 :
7403 : curindex = maxindex;
7404 :
7405 47424876 : for (; vec_safe_iterate (v, cnt, &ce); cnt++)
7406 : {
7407 47274641 : bool curfold_p = false;
7408 47274641 : if (ce->index)
7409 47263786 : curindex = ce->index, curfold_p = true;
7410 47274641 : if (!ce->index || TREE_CODE (ce->value) == RAW_DATA_CST)
7411 : {
7412 11227 : if (fold_p || curfold_p)
7413 : {
7414 : /* Since we treat size types now as ordinary
7415 : unsigned types, we need an explicit overflow
7416 : check. */
7417 372 : tree orig = curindex;
7418 372 : curindex = fold_convert (sizetype, curindex);
7419 372 : overflow_p |= tree_int_cst_lt (curindex, orig);
7420 372 : curfold_p = false;
7421 : }
7422 11227 : if (TREE_CODE (ce->value) == RAW_DATA_CST)
7423 372 : curindex
7424 744 : = size_binop (PLUS_EXPR, curindex,
7425 : size_int (RAW_DATA_LENGTH (ce->value)
7426 : - ((ce->index || !cnt)
7427 : ? 1 : 0)));
7428 : else
7429 10855 : curindex = size_binop (PLUS_EXPR, curindex,
7430 : size_one_node);
7431 : }
7432 47274641 : if (tree_int_cst_lt (maxindex, curindex))
7433 47274641 : maxindex = curindex, fold_p = curfold_p;
7434 : }
7435 150235 : if (fold_p)
7436 : {
7437 140651 : tree orig = maxindex;
7438 140651 : maxindex = fold_convert (sizetype, maxindex);
7439 140651 : overflow_p |= tree_int_cst_lt (maxindex, orig);
7440 : }
7441 : }
7442 : }
7443 : else
7444 : {
7445 : /* Make an error message unless that happened already. */
7446 932 : if (initial_value != error_mark_node)
7447 29 : failure = 1;
7448 : }
7449 : }
7450 : else
7451 : {
7452 7490 : failure = 2;
7453 7490 : if (!do_default)
7454 : return failure;
7455 : }
7456 :
7457 612178 : type = *ptype;
7458 612178 : elt = TREE_TYPE (type);
7459 612178 : quals = TYPE_QUALS (strip_array_types (elt));
7460 612178 : if (quals == 0)
7461 : unqual_elt = elt;
7462 : else
7463 585301 : unqual_elt = c_build_qualified_type (elt, KEEP_QUAL_ADDR_SPACE (quals));
7464 :
7465 : /* Using build_distinct_type_copy and modifying things afterward instead
7466 : of using build_array_type to create a new type preserves all of the
7467 : TYPE_LANG_FLAG_? bits that the front end may have set. */
7468 612178 : main_type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
7469 612178 : TREE_TYPE (main_type) = unqual_elt;
7470 1224356 : TYPE_DOMAIN (main_type)
7471 612178 : = build_range_type (TREE_TYPE (maxindex),
7472 612178 : build_int_cst (TREE_TYPE (maxindex), 0), maxindex);
7473 612178 : TYPE_TYPELESS_STORAGE (main_type) = TYPE_TYPELESS_STORAGE (type);
7474 612178 : layout_type (main_type);
7475 :
7476 : /* Set TYPE_STRUCTURAL_EQUALITY_P early. */
7477 612178 : if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (main_type))
7478 1223966 : || TYPE_STRUCTURAL_EQUALITY_P (TYPE_DOMAIN (main_type)))
7479 390 : SET_TYPE_STRUCTURAL_EQUALITY (main_type);
7480 : else
7481 611788 : TYPE_CANONICAL (main_type) = main_type;
7482 :
7483 : /* Make sure we have the canonical MAIN_TYPE. */
7484 612178 : hashval_t hashcode = type_hash_canon_hash (main_type);
7485 612178 : main_type = type_hash_canon (hashcode, main_type);
7486 :
7487 : /* Fix the canonical type. */
7488 612178 : if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (main_type))
7489 1223966 : || TYPE_STRUCTURAL_EQUALITY_P (TYPE_DOMAIN (main_type)))
7490 390 : gcc_assert (TYPE_STRUCTURAL_EQUALITY_P (main_type));
7491 611788 : else if (TYPE_CANONICAL (TREE_TYPE (main_type)) != TREE_TYPE (main_type)
7492 611788 : || (TYPE_CANONICAL (TYPE_DOMAIN (main_type))
7493 568128 : != TYPE_DOMAIN (main_type)))
7494 43660 : TYPE_CANONICAL (main_type)
7495 87320 : = build_array_type (TYPE_CANONICAL (TREE_TYPE (main_type)),
7496 43660 : TYPE_CANONICAL (TYPE_DOMAIN (main_type)),
7497 43660 : TYPE_TYPELESS_STORAGE (main_type));
7498 :
7499 612178 : if (quals == 0)
7500 : type = main_type;
7501 : else
7502 585301 : type = c_build_qualified_type (main_type, quals);
7503 :
7504 612178 : if (COMPLETE_TYPE_P (type)
7505 612169 : && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST
7506 1224338 : && (overflow_p || TREE_OVERFLOW (TYPE_SIZE_UNIT (type))))
7507 : {
7508 4 : error ("size of array is too large");
7509 : /* If we proceed with the array type as it is, we'll eventually
7510 : crash in tree_to_[su]hwi(). */
7511 4 : type = error_mark_node;
7512 : }
7513 :
7514 612178 : *ptype = type;
7515 612178 : return failure;
7516 : }
7517 :
7518 : /* INIT is an constructor of a structure with a flexible array member.
7519 : Complete the flexible array member with a domain based on it's value. */
7520 : void
7521 8926405 : complete_flexible_array_elts (tree init)
7522 : {
7523 9032912 : tree elt, type;
7524 :
7525 9032912 : if (init == NULL_TREE || TREE_CODE (init) != CONSTRUCTOR)
7526 : return;
7527 :
7528 108068 : if (vec_safe_is_empty (CONSTRUCTOR_ELTS (init)))
7529 : return;
7530 :
7531 106761 : elt = CONSTRUCTOR_ELTS (init)->last ().value;
7532 106761 : type = TREE_TYPE (elt);
7533 106761 : if (TREE_CODE (type) == ARRAY_TYPE
7534 106761 : && TYPE_SIZE (type) == NULL_TREE)
7535 254 : complete_array_type (&TREE_TYPE (elt), elt, false);
7536 : else
7537 : complete_flexible_array_elts (elt);
7538 : }
7539 :
7540 : /* Like c_mark_addressable but don't check register qualifier. */
7541 : void
7542 1144222 : c_common_mark_addressable_vec (tree t)
7543 : {
7544 1326659 : while (handled_component_p (t) || TREE_CODE (t) == C_MAYBE_CONST_EXPR)
7545 : {
7546 182437 : if (TREE_CODE (t) == C_MAYBE_CONST_EXPR)
7547 37 : t = C_MAYBE_CONST_EXPR_EXPR (t);
7548 : else
7549 182400 : t = TREE_OPERAND (t, 0);
7550 : }
7551 1144222 : if (!VAR_P (t)
7552 : && TREE_CODE (t) != PARM_DECL
7553 : && TREE_CODE (t) != COMPOUND_LITERAL_EXPR
7554 : && TREE_CODE (t) != TARGET_EXPR)
7555 : return;
7556 1110165 : if (!VAR_P (t) || !DECL_HARD_REGISTER (t))
7557 1110096 : TREE_ADDRESSABLE (t) = 1;
7558 1110165 : if (TREE_CODE (t) == COMPOUND_LITERAL_EXPR)
7559 134 : TREE_ADDRESSABLE (COMPOUND_LITERAL_EXPR_DECL (t)) = 1;
7560 1110031 : else if (TREE_CODE (t) == TARGET_EXPR)
7561 29 : TREE_ADDRESSABLE (TARGET_EXPR_SLOT (t)) = 1;
7562 : }
7563 :
7564 :
7565 :
7566 : /* Used to help initialize the builtin-types.def table. When a type of
7567 : the correct size doesn't exist, use error_mark_node instead of NULL.
7568 : The later results in segfaults even when a decl using the type doesn't
7569 : get invoked. */
7570 :
7571 : tree
7572 1173074 : builtin_type_for_size (int size, bool unsignedp)
7573 : {
7574 1173074 : tree type = c_common_type_for_size (size, unsignedp);
7575 1173074 : return type ? type : error_mark_node;
7576 : }
7577 :
7578 : /* Work out the size of the first argument of a call to
7579 : __builtin_speculation_safe_value. Only pointers and integral types
7580 : are permitted. Return -1 if the argument type is not supported or
7581 : the size is too large; 0 if the argument type is a pointer or the
7582 : size if it is integral. */
7583 : static enum built_in_function
7584 155 : speculation_safe_value_resolve_call (tree function, vec<tree, va_gc> *params,
7585 : bool complain)
7586 : {
7587 : /* Type of the argument. */
7588 155 : tree type;
7589 155 : int size;
7590 :
7591 155 : if (vec_safe_is_empty (params))
7592 : {
7593 10 : if (complain)
7594 10 : error ("too few arguments to function %qE", function);
7595 10 : return BUILT_IN_NONE;
7596 : }
7597 :
7598 145 : type = TREE_TYPE ((*params)[0]);
7599 145 : if (TREE_CODE (type) == ARRAY_TYPE && c_dialect_cxx ())
7600 : {
7601 : /* Force array-to-pointer decay for C++. */
7602 0 : (*params)[0] = default_conversion ((*params)[0]);
7603 0 : type = TREE_TYPE ((*params)[0]);
7604 : }
7605 :
7606 145 : if (POINTER_TYPE_P (type))
7607 : return BUILT_IN_SPECULATION_SAFE_VALUE_PTR;
7608 :
7609 129 : if (!INTEGRAL_TYPE_P (type))
7610 42 : goto incompatible;
7611 :
7612 87 : if (!COMPLETE_TYPE_P (type))
7613 0 : goto incompatible;
7614 :
7615 87 : size = tree_to_uhwi (TYPE_SIZE_UNIT (type));
7616 87 : if (size == 1 || size == 2 || size == 4 || size == 8 || size == 16)
7617 87 : return ((enum built_in_function)
7618 174 : ((int) BUILT_IN_SPECULATION_SAFE_VALUE_1 + exact_log2 (size)));
7619 :
7620 0 : incompatible:
7621 : /* Issue the diagnostic only if the argument is valid, otherwise
7622 : it would be redundant at best and could be misleading. */
7623 42 : if (type != error_mark_node && complain)
7624 6 : error ("operand type %qT is incompatible with argument %d of %qE",
7625 : type, 1, function);
7626 :
7627 : return BUILT_IN_NONE;
7628 : }
7629 :
7630 : /* Validate and coerce PARAMS, the arguments to ORIG_FUNCTION to fit
7631 : the prototype for FUNCTION. The first argument is mandatory, a second
7632 : argument, if present, must be type compatible with the first. */
7633 : static bool
7634 103 : speculation_safe_value_resolve_params (location_t loc, tree orig_function,
7635 : vec<tree, va_gc> *params, bool complain)
7636 : {
7637 103 : tree val;
7638 :
7639 103 : if (params->length () == 0)
7640 : {
7641 0 : if (complain)
7642 0 : error_at (loc, "too few arguments to function %qE", orig_function);
7643 0 : return false;
7644 : }
7645 :
7646 103 : else if (params->length () > 2)
7647 : {
7648 21 : if (complain)
7649 0 : error_at (loc, "too many arguments to function %qE", orig_function);
7650 21 : return false;
7651 : }
7652 :
7653 82 : val = (*params)[0];
7654 82 : if (TREE_CODE (TREE_TYPE (val)) == ARRAY_TYPE)
7655 0 : val = default_conversion (val);
7656 82 : if (!(TREE_CODE (TREE_TYPE (val)) == POINTER_TYPE
7657 66 : || TREE_CODE (TREE_TYPE (val)) == INTEGER_TYPE))
7658 : {
7659 0 : if (complain)
7660 0 : error_at (loc, "expecting argument of type pointer or of type integer "
7661 : "for argument 1");
7662 0 : return false;
7663 : }
7664 82 : (*params)[0] = val;
7665 :
7666 82 : if (params->length () == 2)
7667 : {
7668 32 : tree val2 = (*params)[1];
7669 32 : if (TREE_CODE (TREE_TYPE (val2)) == ARRAY_TYPE)
7670 0 : val2 = default_conversion (val2);
7671 32 : if (error_operand_p (val2))
7672 : return false;
7673 40 : if (!(TREE_TYPE (val) == TREE_TYPE (val2)
7674 9 : || useless_type_conversion_p (TREE_TYPE (val), TREE_TYPE (val2))))
7675 : {
7676 9 : if (complain)
7677 0 : error_at (loc, "both arguments must be compatible");
7678 9 : return false;
7679 : }
7680 22 : (*params)[1] = val2;
7681 : }
7682 :
7683 : return true;
7684 : }
7685 :
7686 : /* Cast the result of the builtin back to the type of the first argument,
7687 : preserving any qualifiers that it might have. */
7688 : static tree
7689 72 : speculation_safe_value_resolve_return (tree first_param, tree result)
7690 : {
7691 72 : tree ptype = TREE_TYPE (first_param);
7692 72 : tree rtype = TREE_TYPE (result);
7693 72 : ptype = TYPE_MAIN_VARIANT (ptype);
7694 :
7695 72 : if (tree_int_cst_equal (TYPE_SIZE (ptype), TYPE_SIZE (rtype)))
7696 72 : return convert (ptype, result);
7697 :
7698 : return result;
7699 : }
7700 :
7701 : /* A helper function for resolve_overloaded_builtin in resolving the
7702 : overloaded __sync_ builtins. Returns a positive power of 2 if the
7703 : first operand of PARAMS is a pointer to a supported data type.
7704 : Returns 0 if an error is encountered. Return -1 for _BitInt
7705 : __atomic*fetch* with unsupported type which should be handled by
7706 : a cas loop.
7707 : FETCH is true when FUNCTION is one of the _FETCH_OP_ or _OP_FETCH_
7708 : built-ins. ORIG_FORMAT is for __sync_* rather than __atomic_*
7709 : built-ins. */
7710 :
7711 : static int
7712 418505 : sync_resolve_size (tree function, vec<tree, va_gc> *params, bool fetch,
7713 : bool orig_format, bool complain)
7714 : {
7715 : /* Type of the argument. */
7716 418505 : tree argtype;
7717 : /* Type the argument points to. */
7718 418505 : tree type;
7719 418505 : int size;
7720 :
7721 418505 : if (vec_safe_is_empty (params))
7722 : {
7723 106 : if (complain)
7724 106 : error ("too few arguments to function %qE", function);
7725 106 : return 0;
7726 : }
7727 :
7728 418399 : argtype = type = TREE_TYPE ((*params)[0]);
7729 418399 : if (TREE_CODE (type) == ARRAY_TYPE && c_dialect_cxx ())
7730 : {
7731 : /* Force array-to-pointer decay for C++. */
7732 3 : (*params)[0] = default_conversion ((*params)[0]);
7733 3 : type = TREE_TYPE ((*params)[0]);
7734 : }
7735 418399 : if (TREE_CODE (type) != POINTER_TYPE)
7736 2127 : goto incompatible;
7737 :
7738 416272 : type = TREE_TYPE (type);
7739 416272 : if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type))
7740 265 : goto incompatible;
7741 :
7742 416007 : if (!COMPLETE_TYPE_P (type))
7743 2 : goto incompatible;
7744 :
7745 416005 : if (fetch && TREE_CODE (type) == BOOLEAN_TYPE)
7746 84 : goto incompatible;
7747 :
7748 415921 : size = tree_to_uhwi (TYPE_SIZE_UNIT (type));
7749 415921 : if (size == 16
7750 7678 : && TREE_CODE (type) == BITINT_TYPE
7751 416447 : && !targetm.scalar_mode_supported_p (TImode))
7752 : {
7753 0 : if (fetch && !orig_format)
7754 : return -1;
7755 0 : goto incompatible;
7756 : }
7757 :
7758 415921 : if (size == 1 || size == 2 || size == 4 || size == 8 || size == 16)
7759 : return size;
7760 :
7761 528 : if (fetch && !orig_format && TREE_CODE (type) == BITINT_TYPE)
7762 : return -1;
7763 :
7764 0 : incompatible:
7765 : /* Issue the diagnostic only if the argument is valid, otherwise
7766 : it would be redundant at best and could be misleading. */
7767 2478 : if (argtype != error_mark_node && complain)
7768 920 : error ("operand type %qT is incompatible with argument %d of %qE",
7769 : argtype, 1, function);
7770 : return 0;
7771 : }
7772 :
7773 : /* A helper function for resolve_overloaded_builtin. Adds casts to
7774 : PARAMS to make arguments match up with those of FUNCTION. Drops
7775 : the variadic arguments at the end. Returns false if some error
7776 : was encountered; true on success. */
7777 :
7778 : static bool
7779 415393 : sync_resolve_params (location_t loc, tree orig_function, tree function,
7780 : vec<tree, va_gc> *params, bool orig_format, bool complain)
7781 : {
7782 415393 : function_args_iterator iter;
7783 415393 : tree ptype;
7784 415393 : unsigned int parmnum;
7785 :
7786 415393 : function_args_iter_init (&iter, TREE_TYPE (function));
7787 : /* We've declared the implementation functions to use "volatile void *"
7788 : as the pointer parameter, so we shouldn't get any complaints from the
7789 : call to check_function_arguments what ever type the user used. */
7790 415393 : function_args_iter_next (&iter);
7791 415393 : ptype = TREE_TYPE (TREE_TYPE ((*params)[0]));
7792 415393 : ptype = TYPE_MAIN_VARIANT (ptype);
7793 :
7794 : /* For the rest of the values, we need to cast these to FTYPE, so that we
7795 : don't get warnings for passing pointer types, etc. */
7796 415393 : parmnum = 0;
7797 2339053 : while (1)
7798 : {
7799 1377223 : tree val, arg_type;
7800 :
7801 1377223 : arg_type = function_args_iter_cond (&iter);
7802 : /* XXX void_type_node belies the abstraction. */
7803 1377223 : if (arg_type == void_type_node)
7804 : break;
7805 :
7806 961888 : ++parmnum;
7807 961888 : if (params->length () <= parmnum)
7808 : {
7809 58 : if (complain)
7810 7 : error_at (loc, "too few arguments to function %qE", orig_function);
7811 58 : return false;
7812 : }
7813 :
7814 : /* Only convert parameters if arg_type is unsigned integer type with
7815 : new format sync routines, i.e. don't attempt to convert pointer
7816 : arguments (e.g. EXPECTED argument of __atomic_compare_exchange_n),
7817 : bool arguments (e.g. WEAK argument) or signed int arguments (memmodel
7818 : kinds). */
7819 961830 : if (TREE_CODE (arg_type) == INTEGER_TYPE && TYPE_UNSIGNED (arg_type))
7820 : {
7821 : /* Ideally for the first conversion we'd use convert_for_assignment
7822 : so that we get warnings for anything that doesn't match the pointer
7823 : type. This isn't portable across the C and C++ front ends atm. */
7824 263477 : val = (*params)[parmnum];
7825 263477 : val = convert (ptype, val);
7826 263477 : val = convert (arg_type, val);
7827 263477 : (*params)[parmnum] = val;
7828 : }
7829 :
7830 961830 : function_args_iter_next (&iter);
7831 961830 : }
7832 :
7833 : /* __atomic routines are not variadic. */
7834 415335 : if (!orig_format && params->length () != parmnum + 1)
7835 : {
7836 106 : if (complain)
7837 103 : error_at (loc, "too many arguments to function %qE", orig_function);
7838 106 : return false;
7839 : }
7840 :
7841 : /* The definition of these primitives is variadic, with the remaining
7842 : being "an optional list of variables protected by the memory barrier".
7843 : No clue what that's supposed to mean, precisely, but we consider all
7844 : call-clobbered variables to be protected so we're safe. */
7845 415229 : params->truncate (parmnum + 1);
7846 :
7847 415229 : return true;
7848 : }
7849 :
7850 : /* A helper function for resolve_overloaded_builtin. Adds a cast to
7851 : RESULT to make it match the type of the first pointer argument in
7852 : PARAMS. */
7853 :
7854 : static tree
7855 278094 : sync_resolve_return (tree first_param, tree result, bool orig_format)
7856 : {
7857 278094 : tree ptype = TREE_TYPE (TREE_TYPE (first_param));
7858 278094 : tree rtype = TREE_TYPE (result);
7859 278094 : ptype = TYPE_MAIN_VARIANT (ptype);
7860 :
7861 : /* New format doesn't require casting unless the types are the same size. */
7862 278094 : if (orig_format || tree_int_cst_equal (TYPE_SIZE (ptype), TYPE_SIZE (rtype)))
7863 278094 : return convert (ptype, result);
7864 : else
7865 : return result;
7866 : }
7867 :
7868 : /* This function verifies the PARAMS to generic atomic FUNCTION.
7869 : It returns the size if all the parameters are the same size, otherwise
7870 : 0 is returned if the parameters are invalid. */
7871 :
7872 : static int
7873 130034 : get_atomic_generic_size (location_t loc, tree function,
7874 : vec<tree, va_gc> *params, bool complain)
7875 : {
7876 130034 : unsigned int n_param;
7877 130034 : unsigned int n_model;
7878 130034 : unsigned int outputs = 0; // bitset of output parameters
7879 130034 : unsigned int x;
7880 130034 : int size_0;
7881 130034 : tree type_0;
7882 :
7883 : /* Determine the parameter makeup. */
7884 130034 : switch (DECL_FUNCTION_CODE (function))
7885 : {
7886 : case BUILT_IN_ATOMIC_EXCHANGE:
7887 : n_param = 4;
7888 : n_model = 1;
7889 : outputs = 5;
7890 : break;
7891 76940 : case BUILT_IN_ATOMIC_LOAD:
7892 76940 : n_param = 3;
7893 76940 : n_model = 1;
7894 76940 : outputs = 2;
7895 76940 : break;
7896 11482 : case BUILT_IN_ATOMIC_STORE:
7897 11482 : n_param = 3;
7898 11482 : n_model = 1;
7899 11482 : outputs = 1;
7900 11482 : break;
7901 40981 : case BUILT_IN_ATOMIC_COMPARE_EXCHANGE:
7902 40981 : n_param = 6;
7903 40981 : n_model = 2;
7904 40981 : outputs = 3;
7905 40981 : break;
7906 0 : default:
7907 0 : gcc_unreachable ();
7908 : }
7909 :
7910 130034 : if (vec_safe_length (params) != n_param)
7911 : {
7912 466 : if (complain)
7913 247 : error_at (loc, "incorrect number of arguments to function %qE",
7914 : function);
7915 466 : return 0;
7916 : }
7917 :
7918 : /* Get type of first parameter, and determine its size. */
7919 129568 : type_0 = TREE_TYPE ((*params)[0]);
7920 129568 : if (TREE_CODE (type_0) == ARRAY_TYPE && c_dialect_cxx ())
7921 : {
7922 : /* Force array-to-pointer decay for C++. */
7923 15 : (*params)[0] = default_conversion ((*params)[0]);
7924 15 : type_0 = TREE_TYPE ((*params)[0]);
7925 : }
7926 129568 : if (TREE_CODE (type_0) != POINTER_TYPE || VOID_TYPE_P (TREE_TYPE (type_0)))
7927 : {
7928 152 : if (complain)
7929 41 : error_at (loc, "argument 1 of %qE must be a non-void pointer type",
7930 : function);
7931 152 : return 0;
7932 : }
7933 :
7934 129416 : if (!COMPLETE_TYPE_P (TREE_TYPE (type_0)))
7935 : {
7936 23 : if (complain)
7937 8 : error_at (loc, "argument 1 of %qE must be a pointer to a complete type",
7938 : function);
7939 23 : return 0;
7940 : }
7941 :
7942 : /* Types must be compile time constant sizes. */
7943 129393 : if (!tree_fits_uhwi_p ((TYPE_SIZE_UNIT (TREE_TYPE (type_0)))))
7944 : {
7945 1 : if (complain)
7946 1 : error_at (loc,
7947 : "argument 1 of %qE must be a pointer to a constant size type",
7948 : function);
7949 1 : return 0;
7950 : }
7951 :
7952 129392 : size_0 = tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (type_0)));
7953 :
7954 : /* Zero size objects are not allowed. */
7955 129392 : if (size_0 == 0)
7956 : {
7957 22 : if (complain)
7958 7 : error_at (
7959 : loc, "argument 1 of %qE must be a pointer to a nonzero size object",
7960 : function);
7961 22 : return 0;
7962 : }
7963 :
7964 : /* Check each other parameter is a pointer and the same size. */
7965 470016 : for (x = 0; x < n_param - n_model; x++)
7966 : {
7967 340785 : int size;
7968 340785 : tree type = TREE_TYPE ((*params)[x]);
7969 : /* __atomic_compare_exchange has a bool in the 4th position, skip it. */
7970 340785 : if (n_param == 6 && x == 3)
7971 40803 : continue;
7972 299982 : if (TREE_CODE (type) == ARRAY_TYPE && c_dialect_cxx ())
7973 : {
7974 : /* Force array-to-pointer decay for C++. */
7975 18 : (*params)[x] = default_conversion ((*params)[x]);
7976 18 : type = TREE_TYPE ((*params)[x]);
7977 : }
7978 299982 : if (!POINTER_TYPE_P (type))
7979 : {
7980 16 : if (complain)
7981 13 : error_at (loc, "argument %d of %qE must be a pointer type", x + 1,
7982 : function);
7983 16 : return 0;
7984 : }
7985 299966 : else if (TYPE_SIZE_UNIT (TREE_TYPE (type))
7986 299966 : && TREE_CODE ((TYPE_SIZE_UNIT (TREE_TYPE (type))))
7987 : != INTEGER_CST)
7988 : {
7989 1 : if (complain)
7990 1 : error_at (loc,
7991 : "argument %d of %qE must be a pointer to a constant "
7992 : "size type",
7993 : x + 1, function);
7994 1 : return 0;
7995 : }
7996 299965 : else if (FUNCTION_POINTER_TYPE_P (type))
7997 : {
7998 10 : if (complain)
7999 7 : error_at (loc,
8000 : "argument %d of %qE must not be a pointer to a "
8001 : "function",
8002 : x + 1, function);
8003 10 : return 0;
8004 : }
8005 299955 : tree type_size = TYPE_SIZE_UNIT (TREE_TYPE (type));
8006 299955 : size = type_size ? tree_to_uhwi (type_size) : 0;
8007 299955 : if (size != size_0)
8008 : {
8009 34 : if (complain)
8010 25 : error_at (loc, "size mismatch in argument %d of %qE", x + 1,
8011 : function);
8012 34 : return 0;
8013 : }
8014 :
8015 299921 : {
8016 299921 : auto_diagnostic_group d;
8017 299921 : int quals = TYPE_QUALS (TREE_TYPE (type));
8018 : /* Must not write to an argument of a const-qualified type. */
8019 299921 : if (outputs & (1 << x) && quals & TYPE_QUAL_CONST)
8020 : {
8021 57 : if (c_dialect_cxx ())
8022 : {
8023 45 : if (complain)
8024 42 : error_at (loc,
8025 : "argument %d of %qE must not be a pointer to "
8026 : "a %<const%> type",
8027 : x + 1, function);
8028 45 : return 0;
8029 : }
8030 : else
8031 12 : pedwarn (loc, OPT_Wdiscarded_qualifiers, "argument %d "
8032 : "of %qE discards %<const%> qualifier", x + 1,
8033 : function);
8034 : }
8035 : /* Only the first argument is allowed to be volatile. */
8036 299876 : if (x > 0 && quals & TYPE_QUAL_VOLATILE)
8037 : {
8038 44 : if (c_dialect_cxx ())
8039 : {
8040 33 : if (complain)
8041 30 : error_at (loc,
8042 : "argument %d of %qE must not be a pointer to "
8043 : "a %<volatile%> type",
8044 : x + 1, function);
8045 33 : return 0;
8046 : }
8047 : else
8048 11 : pedwarn (loc, OPT_Wdiscarded_qualifiers, "argument %d "
8049 : "of %qE discards %<volatile%> qualifier", x + 1,
8050 : function);
8051 : }
8052 299921 : }
8053 : }
8054 :
8055 : /* Check memory model parameters for validity. */
8056 299249 : for (x = n_param - n_model ; x < n_param; x++)
8057 : {
8058 170034 : tree p = (*params)[x];
8059 170034 : if (!INTEGRAL_TYPE_P (TREE_TYPE (p)))
8060 : {
8061 10 : if (complain)
8062 7 : error_at (loc, "non-integer memory model argument %d of %qE", x + 1,
8063 : function);
8064 10 : return 0;
8065 : }
8066 170024 : p = fold_for_warn (p);
8067 170024 : if (TREE_CODE (p) == INTEGER_CST)
8068 : {
8069 : /* memmodel_base masks the low 16 bits, thus ignore any bits above
8070 : it by using TREE_INT_CST_LOW instead of tree_to_*hwi. Those high
8071 : bits will be checked later during expansion in target specific
8072 : way. */
8073 79426 : if (memmodel_base (TREE_INT_CST_LOW (p)) >= MEMMODEL_LAST)
8074 : {
8075 20 : if (complain)
8076 14 : warning_at (loc, OPT_Winvalid_memory_model,
8077 : "invalid memory model argument %d of %qE", x + 1,
8078 : function);
8079 : else
8080 : return 0;
8081 : }
8082 : }
8083 : }
8084 :
8085 : return size_0;
8086 : }
8087 :
8088 :
8089 : /* This will take an __atomic_ generic FUNCTION call, and add a size parameter N
8090 : at the beginning of the parameter list PARAMS representing the size of the
8091 : objects. This is to match the library ABI requirement. LOC is the location
8092 : of the function call.
8093 : The new function is returned if it needed rebuilding, otherwise NULL_TREE is
8094 : returned to allow the external call to be constructed. */
8095 :
8096 : static tree
8097 4146 : add_atomic_size_parameter (unsigned n, location_t loc, tree function,
8098 : vec<tree, va_gc> *params)
8099 : {
8100 4146 : tree size_node;
8101 :
8102 : /* Insert a SIZE_T parameter as the first param. If there isn't
8103 : enough space, allocate a new vector and recursively re-build with that. */
8104 4146 : if (!params->space (1))
8105 : {
8106 33 : unsigned int z, len;
8107 33 : vec<tree, va_gc> *v;
8108 33 : tree f;
8109 :
8110 33 : len = params->length ();
8111 33 : vec_alloc (v, len + 1);
8112 33 : v->quick_push (build_int_cst (size_type_node, n));
8113 165 : for (z = 0; z < len; z++)
8114 132 : v->quick_push ((*params)[z]);
8115 33 : f = build_function_call_vec (loc, vNULL, function, v, NULL);
8116 33 : vec_free (v);
8117 33 : return f;
8118 : }
8119 :
8120 : /* Add the size parameter and leave as a function call for processing. */
8121 4113 : size_node = build_int_cst (size_type_node, n);
8122 4113 : params->quick_insert (0, size_node);
8123 4113 : return NULL_TREE;
8124 : }
8125 :
8126 :
8127 : /* Return whether atomic operations for naturally aligned N-byte
8128 : arguments are supported, whether inline or through libatomic. */
8129 : static bool
8130 129215 : atomic_size_supported_p (int n)
8131 : {
8132 129215 : switch (n)
8133 : {
8134 : case 1:
8135 : case 2:
8136 : case 4:
8137 : case 8:
8138 : return true;
8139 :
8140 6971 : case 16:
8141 6971 : return targetm.scalar_mode_supported_p (TImode);
8142 :
8143 4146 : default:
8144 4146 : return false;
8145 : }
8146 : }
8147 :
8148 : /* This will process an __atomic_exchange function call, determine whether it
8149 : needs to be mapped to the _N variation, or turned into a library call.
8150 : LOC is the location of the builtin call.
8151 : FUNCTION is the DECL that has been invoked;
8152 : PARAMS is the argument list for the call. The return value is non-null
8153 : TRUE is returned if it is translated into the proper format for a call to the
8154 : external library, and NEW_RETURN is set the tree for that function.
8155 : FALSE is returned if processing for the _N variation is required, and
8156 : NEW_RETURN is set to the return value the result is copied into. */
8157 : static bool
8158 631 : resolve_overloaded_atomic_exchange (location_t loc, tree function,
8159 : vec<tree, va_gc> *params, tree *new_return,
8160 : bool complain)
8161 : {
8162 631 : tree p0, p1, p2, p3;
8163 631 : tree I_type, I_type_ptr;
8164 631 : int n = get_atomic_generic_size (loc, function, params, complain);
8165 :
8166 : /* Size of 0 is an error condition. */
8167 631 : if (n == 0)
8168 : {
8169 195 : *new_return = error_mark_node;
8170 195 : return true;
8171 : }
8172 :
8173 : /* If not a lock-free size, change to the library generic format. */
8174 436 : if (!atomic_size_supported_p (n))
8175 : {
8176 39 : *new_return = add_atomic_size_parameter (n, loc, function, params);
8177 39 : return true;
8178 : }
8179 :
8180 : /* Otherwise there is a lockfree match, transform the call from:
8181 : void fn(T* mem, T* desired, T* return, model)
8182 : into
8183 : *return = (T) (fn (In* mem, (In) *desired, model)) */
8184 :
8185 397 : p0 = (*params)[0];
8186 397 : p1 = (*params)[1];
8187 397 : p2 = (*params)[2];
8188 397 : p3 = (*params)[3];
8189 :
8190 : /* Create pointer to appropriate size. */
8191 397 : I_type = builtin_type_for_size (BITS_PER_UNIT * n, 1);
8192 397 : I_type_ptr = build_pointer_type (I_type);
8193 :
8194 : /* Convert object pointer to required type. */
8195 397 : p0 = build1 (VIEW_CONVERT_EXPR, I_type_ptr, p0);
8196 397 : (*params)[0] = p0;
8197 : /* Convert new value to required type, and dereference it.
8198 : If *p1 type can have padding or may involve floating point which
8199 : could e.g. be promoted to wider precision and demoted afterwards,
8200 : state of padding bits might not be preserved. */
8201 397 : build_indirect_ref (loc, p1, RO_UNARY_STAR);
8202 397 : p1 = build2_loc (loc, MEM_REF, I_type,
8203 : build1 (VIEW_CONVERT_EXPR, I_type_ptr, p1),
8204 397 : build_zero_cst (TREE_TYPE (p1)));
8205 397 : (*params)[1] = p1;
8206 :
8207 : /* Move memory model to the 3rd position, and end param list. */
8208 397 : (*params)[2] = p3;
8209 397 : params->truncate (3);
8210 :
8211 : /* Convert return pointer and dereference it for later assignment. */
8212 397 : *new_return = build_indirect_ref (loc, p2, RO_UNARY_STAR);
8213 :
8214 397 : return false;
8215 : }
8216 :
8217 : /* This will process an __atomic_compare_exchange function call, determine
8218 : whether it needs to be mapped to the _N variation, or turned into a lib call.
8219 : LOC is the location of the builtin call.
8220 : FUNCTION is the DECL that has been invoked;
8221 : PARAMS is the argument list for the call. The return value is non-null
8222 : TRUE is returned if it is translated into the proper format for a call to the
8223 : external library, and NEW_RETURN is set the tree for that function.
8224 : FALSE is returned if processing for the _N variation is required. */
8225 :
8226 : static bool
8227 40981 : resolve_overloaded_atomic_compare_exchange (location_t loc, tree function,
8228 : vec<tree, va_gc> *params,
8229 : tree *new_return, bool complain)
8230 : {
8231 40981 : tree p0, p1, p2;
8232 40981 : tree I_type, I_type_ptr;
8233 40981 : int n = get_atomic_generic_size (loc, function, params, complain);
8234 :
8235 : /* Size of 0 is an error condition. */
8236 40981 : if (n == 0)
8237 : {
8238 178 : *new_return = error_mark_node;
8239 178 : return true;
8240 : }
8241 :
8242 : /* If not a lock-free size, change to the library generic format. */
8243 40803 : if (!atomic_size_supported_p (n))
8244 : {
8245 : /* The library generic format does not have the weak parameter, so
8246 : remove it from the param list. Since a parameter has been removed,
8247 : we can be sure that there is room for the SIZE_T parameter, meaning
8248 : there will not be a recursive rebuilding of the parameter list, so
8249 : there is no danger this will be done twice. */
8250 1198 : if (n > 0)
8251 : {
8252 1198 : (*params)[3] = (*params)[4];
8253 1198 : (*params)[4] = (*params)[5];
8254 1198 : params->truncate (5);
8255 : }
8256 1198 : *new_return = add_atomic_size_parameter (n, loc, function, params);
8257 1198 : return true;
8258 : }
8259 :
8260 : /* Otherwise, there is a match, so the call needs to be transformed from:
8261 : bool fn(T* mem, T* desired, T* return, weak, success, failure)
8262 : into
8263 : bool fn ((In *)mem, (In *)expected, (In) *desired, weak, succ, fail) */
8264 :
8265 39605 : p0 = (*params)[0];
8266 39605 : p1 = (*params)[1];
8267 39605 : p2 = (*params)[2];
8268 :
8269 : /* Create pointer to appropriate size. */
8270 39605 : I_type = builtin_type_for_size (BITS_PER_UNIT * n, 1);
8271 39605 : I_type_ptr = build_pointer_type (I_type);
8272 :
8273 : /* Convert object pointer to required type. */
8274 39605 : p0 = build1 (VIEW_CONVERT_EXPR, I_type_ptr, p0);
8275 39605 : (*params)[0] = p0;
8276 :
8277 : /* Convert expected pointer to required type. */
8278 39605 : p1 = build1 (VIEW_CONVERT_EXPR, I_type_ptr, p1);
8279 39605 : (*params)[1] = p1;
8280 :
8281 : /* Convert desired value to required type, and dereference it.
8282 : If *p2 type can have padding or may involve floating point which
8283 : could e.g. be promoted to wider precision and demoted afterwards,
8284 : state of padding bits might not be preserved. */
8285 39605 : build_indirect_ref (loc, p2, RO_UNARY_STAR);
8286 39605 : p2 = build2_loc (loc, MEM_REF, I_type,
8287 : build1 (VIEW_CONVERT_EXPR, I_type_ptr, p2),
8288 39605 : build_zero_cst (TREE_TYPE (p2)));
8289 39605 : (*params)[2] = p2;
8290 :
8291 : /* The rest of the parameters are fine. NULL means no special return value
8292 : processing.*/
8293 39605 : *new_return = NULL;
8294 39605 : return false;
8295 : }
8296 :
8297 : /* This will process an __atomic_load function call, determine whether it
8298 : needs to be mapped to the _N variation, or turned into a library call.
8299 : LOC is the location of the builtin call.
8300 : FUNCTION is the DECL that has been invoked;
8301 : PARAMS is the argument list for the call. The return value is non-null
8302 : TRUE is returned if it is translated into the proper format for a call to the
8303 : external library, and NEW_RETURN is set the tree for that function.
8304 : FALSE is returned if processing for the _N variation is required, and
8305 : NEW_RETURN is set to the return value the result is copied into. */
8306 :
8307 : static bool
8308 76940 : resolve_overloaded_atomic_load (location_t loc, tree function,
8309 : vec<tree, va_gc> *params, tree *new_return,
8310 : bool complain)
8311 : {
8312 76940 : tree p0, p1, p2;
8313 76940 : tree I_type, I_type_ptr;
8314 76940 : int n = get_atomic_generic_size (loc, function, params, complain);
8315 :
8316 : /* Size of 0 is an error condition. */
8317 76940 : if (n == 0)
8318 : {
8319 278 : *new_return = error_mark_node;
8320 278 : return true;
8321 : }
8322 :
8323 : /* If not a lock-free size, change to the library generic format. */
8324 76662 : if (!atomic_size_supported_p (n))
8325 : {
8326 2499 : *new_return = add_atomic_size_parameter (n, loc, function, params);
8327 2499 : return true;
8328 : }
8329 :
8330 : /* Otherwise, there is a match, so the call needs to be transformed from:
8331 : void fn(T* mem, T* return, model)
8332 : into
8333 : *return = (T) (fn ((In *) mem, model)) */
8334 :
8335 74163 : p0 = (*params)[0];
8336 74163 : p1 = (*params)[1];
8337 74163 : p2 = (*params)[2];
8338 :
8339 : /* Create pointer to appropriate size. */
8340 74163 : I_type = builtin_type_for_size (BITS_PER_UNIT * n, 1);
8341 74163 : I_type_ptr = build_pointer_type (I_type);
8342 :
8343 : /* Convert object pointer to required type. */
8344 74163 : p0 = build1 (VIEW_CONVERT_EXPR, I_type_ptr, p0);
8345 74163 : (*params)[0] = p0;
8346 :
8347 : /* Move memory model to the 2nd position, and end param list. */
8348 74163 : (*params)[1] = p2;
8349 74163 : params->truncate (2);
8350 :
8351 : /* Convert return pointer and dereference it for later assignment. */
8352 74163 : *new_return = build_indirect_ref (loc, p1, RO_UNARY_STAR);
8353 :
8354 74163 : return false;
8355 : }
8356 :
8357 : /* This will process an __atomic_store function call, determine whether it
8358 : needs to be mapped to the _N variation, or turned into a library call.
8359 : LOC is the location of the builtin call.
8360 : FUNCTION is the DECL that has been invoked;
8361 : PARAMS is the argument list for the call. The return value is non-null
8362 : TRUE is returned if it is translated into the proper format for a call to the
8363 : external library, and NEW_RETURN is set the tree for that function.
8364 : FALSE is returned if processing for the _N variation is required, and
8365 : NEW_RETURN is set to the return value the result is copied into. */
8366 :
8367 : static bool
8368 11482 : resolve_overloaded_atomic_store (location_t loc, tree function,
8369 : vec<tree, va_gc> *params, tree *new_return,
8370 : bool complain)
8371 : {
8372 11482 : tree p0, p1;
8373 11482 : tree I_type, I_type_ptr;
8374 11482 : int n = get_atomic_generic_size (loc, function, params, complain);
8375 :
8376 : /* Size of 0 is an error condition. */
8377 11482 : if (n == 0)
8378 : {
8379 168 : *new_return = error_mark_node;
8380 168 : return true;
8381 : }
8382 :
8383 : /* If not a lock-free size, change to the library generic format. */
8384 11314 : if (!atomic_size_supported_p (n))
8385 : {
8386 410 : *new_return = add_atomic_size_parameter (n, loc, function, params);
8387 410 : return true;
8388 : }
8389 :
8390 : /* Otherwise, there is a match, so the call needs to be transformed from:
8391 : void fn(T* mem, T* value, model)
8392 : into
8393 : fn ((In *) mem, (In) *value, model) */
8394 :
8395 10904 : p0 = (*params)[0];
8396 10904 : p1 = (*params)[1];
8397 :
8398 : /* Create pointer to appropriate size. */
8399 10904 : I_type = builtin_type_for_size (BITS_PER_UNIT * n, 1);
8400 10904 : I_type_ptr = build_pointer_type (I_type);
8401 :
8402 : /* Convert object pointer to required type. */
8403 10904 : p0 = build1 (VIEW_CONVERT_EXPR, I_type_ptr, p0);
8404 10904 : (*params)[0] = p0;
8405 :
8406 : /* Convert new value to required type, and dereference it. */
8407 10904 : p1 = build_indirect_ref (loc, p1, RO_UNARY_STAR);
8408 10904 : p1 = build1 (VIEW_CONVERT_EXPR, I_type, p1);
8409 10904 : (*params)[1] = p1;
8410 :
8411 : /* The memory model is in the right spot already. Return is void. */
8412 10904 : *new_return = NULL_TREE;
8413 :
8414 10904 : return false;
8415 : }
8416 :
8417 : /* Emit __atomic*fetch* on _BitInt which doesn't have a size of
8418 : 1, 2, 4, 8 or 16 bytes using __atomic_compare_exchange loop.
8419 : ORIG_CODE is the DECL_FUNCTION_CODE of ORIG_FUNCTION and
8420 : ORIG_PARAMS arguments of the call. */
8421 :
8422 : static tree
8423 528 : atomic_bitint_fetch_using_cas_loop (location_t loc,
8424 : enum built_in_function orig_code,
8425 : tree orig_function,
8426 : vec<tree, va_gc> *orig_params)
8427 : {
8428 528 : enum tree_code code = ERROR_MARK;
8429 528 : bool return_old_p = false;
8430 528 : switch (orig_code)
8431 : {
8432 0 : case BUILT_IN_ATOMIC_ADD_FETCH_N:
8433 0 : code = PLUS_EXPR;
8434 0 : break;
8435 1 : case BUILT_IN_ATOMIC_SUB_FETCH_N:
8436 1 : code = MINUS_EXPR;
8437 1 : break;
8438 0 : case BUILT_IN_ATOMIC_AND_FETCH_N:
8439 0 : code = BIT_AND_EXPR;
8440 0 : break;
8441 : case BUILT_IN_ATOMIC_NAND_FETCH_N:
8442 : break;
8443 1 : case BUILT_IN_ATOMIC_XOR_FETCH_N:
8444 1 : code = BIT_XOR_EXPR;
8445 1 : break;
8446 0 : case BUILT_IN_ATOMIC_OR_FETCH_N:
8447 0 : code = BIT_IOR_EXPR;
8448 0 : break;
8449 106 : case BUILT_IN_ATOMIC_FETCH_ADD_N:
8450 106 : code = PLUS_EXPR;
8451 106 : return_old_p = true;
8452 106 : break;
8453 104 : case BUILT_IN_ATOMIC_FETCH_SUB_N:
8454 104 : code = MINUS_EXPR;
8455 104 : return_old_p = true;
8456 104 : break;
8457 105 : case BUILT_IN_ATOMIC_FETCH_AND_N:
8458 105 : code = BIT_AND_EXPR;
8459 105 : return_old_p = true;
8460 105 : break;
8461 0 : case BUILT_IN_ATOMIC_FETCH_NAND_N:
8462 0 : return_old_p = true;
8463 0 : break;
8464 104 : case BUILT_IN_ATOMIC_FETCH_XOR_N:
8465 104 : code = BIT_XOR_EXPR;
8466 104 : return_old_p = true;
8467 104 : break;
8468 106 : case BUILT_IN_ATOMIC_FETCH_OR_N:
8469 106 : code = BIT_IOR_EXPR;
8470 106 : return_old_p = true;
8471 106 : break;
8472 0 : default:
8473 0 : gcc_unreachable ();
8474 : }
8475 :
8476 528 : if (orig_params->length () != 3)
8477 : {
8478 0 : if (orig_params->length () < 3)
8479 0 : error_at (loc, "too few arguments to function %qE", orig_function);
8480 : else
8481 0 : error_at (loc, "too many arguments to function %qE", orig_function);
8482 0 : return error_mark_node;
8483 : }
8484 :
8485 528 : tree stmts = push_stmt_list ();
8486 :
8487 528 : tree nonatomic_lhs_type = TREE_TYPE (TREE_TYPE ((*orig_params)[0]));
8488 528 : nonatomic_lhs_type = TYPE_MAIN_VARIANT (nonatomic_lhs_type);
8489 528 : gcc_assert (TREE_CODE (nonatomic_lhs_type) == BITINT_TYPE);
8490 :
8491 528 : tree lhs_addr = (*orig_params)[0];
8492 528 : tree val = convert (nonatomic_lhs_type, (*orig_params)[1]);
8493 528 : tree model = convert (integer_type_node, (*orig_params)[2]);
8494 528 : if (!c_dialect_cxx ())
8495 : {
8496 528 : lhs_addr = c_fully_fold (lhs_addr, false, NULL);
8497 528 : val = c_fully_fold (val, false, NULL);
8498 528 : model = c_fully_fold (model, false, NULL);
8499 : }
8500 528 : if (TREE_SIDE_EFFECTS (lhs_addr))
8501 : {
8502 1 : tree var = create_tmp_var_raw (TREE_TYPE (lhs_addr));
8503 1 : lhs_addr = build4 (TARGET_EXPR, TREE_TYPE (lhs_addr), var, lhs_addr,
8504 : NULL_TREE, NULL_TREE);
8505 1 : add_stmt (lhs_addr);
8506 : }
8507 528 : if (TREE_SIDE_EFFECTS (val))
8508 : {
8509 1 : tree var = create_tmp_var_raw (nonatomic_lhs_type);
8510 1 : val = build4 (TARGET_EXPR, nonatomic_lhs_type, var, val, NULL_TREE,
8511 : NULL_TREE);
8512 1 : add_stmt (val);
8513 : }
8514 528 : if (TREE_SIDE_EFFECTS (model))
8515 : {
8516 1 : tree var = create_tmp_var_raw (integer_type_node);
8517 1 : model = build4 (TARGET_EXPR, integer_type_node, var, model, NULL_TREE,
8518 : NULL_TREE);
8519 1 : add_stmt (model);
8520 : }
8521 :
8522 528 : tree old = create_tmp_var_raw (nonatomic_lhs_type);
8523 528 : tree old_addr = build_unary_op (loc, ADDR_EXPR, old, false);
8524 528 : TREE_ADDRESSABLE (old) = 1;
8525 528 : suppress_warning (old);
8526 :
8527 528 : tree newval = create_tmp_var_raw (nonatomic_lhs_type);
8528 528 : tree newval_addr = build_unary_op (loc, ADDR_EXPR, newval, false);
8529 528 : TREE_ADDRESSABLE (newval) = 1;
8530 528 : suppress_warning (newval);
8531 :
8532 528 : tree loop_decl = create_artificial_label (loc);
8533 528 : tree loop_label = build1 (LABEL_EXPR, void_type_node, loop_decl);
8534 :
8535 528 : tree done_decl = create_artificial_label (loc);
8536 528 : tree done_label = build1 (LABEL_EXPR, void_type_node, done_decl);
8537 :
8538 528 : vec<tree, va_gc> *params;
8539 528 : vec_alloc (params, 6);
8540 :
8541 : /* __atomic_load (addr, &old, SEQ_CST). */
8542 528 : tree fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_LOAD);
8543 528 : params->quick_push (lhs_addr);
8544 528 : params->quick_push (old_addr);
8545 528 : params->quick_push (build_int_cst (integer_type_node, MEMMODEL_RELAXED));
8546 528 : tree func_call = resolve_overloaded_builtin (loc, fndecl, params);
8547 528 : if (func_call == NULL_TREE)
8548 528 : func_call = build_function_call_vec (loc, vNULL, fndecl, params, NULL);
8549 528 : old = build4 (TARGET_EXPR, nonatomic_lhs_type, old, func_call, NULL_TREE,
8550 : NULL_TREE);
8551 528 : add_stmt (old);
8552 528 : params->truncate (0);
8553 :
8554 : /* loop: */
8555 528 : add_stmt (loop_label);
8556 :
8557 : /* newval = old + val; */
8558 528 : tree rhs;
8559 528 : switch (code)
8560 : {
8561 211 : case PLUS_EXPR:
8562 211 : case MINUS_EXPR:
8563 211 : if (!TYPE_OVERFLOW_WRAPS (nonatomic_lhs_type))
8564 : {
8565 211 : tree utype
8566 211 : = build_bitint_type (TYPE_PRECISION (nonatomic_lhs_type), 1);
8567 211 : rhs = convert (nonatomic_lhs_type,
8568 : build2_loc (loc, code, utype,
8569 : convert (utype, old),
8570 : convert (utype, val)));
8571 : }
8572 : else
8573 0 : rhs = build2_loc (loc, code, nonatomic_lhs_type, old, val);
8574 : break;
8575 316 : case BIT_AND_EXPR:
8576 316 : case BIT_IOR_EXPR:
8577 316 : case BIT_XOR_EXPR:
8578 316 : rhs = build2_loc (loc, code, nonatomic_lhs_type, old, val);
8579 316 : break;
8580 1 : case ERROR_MARK:
8581 1 : rhs = build2_loc (loc, BIT_AND_EXPR, nonatomic_lhs_type,
8582 : build1_loc (loc, BIT_NOT_EXPR,
8583 : nonatomic_lhs_type, old), val);
8584 1 : break;
8585 0 : default:
8586 0 : gcc_unreachable ();
8587 : }
8588 528 : rhs = build4 (TARGET_EXPR, nonatomic_lhs_type, newval, rhs, NULL_TREE,
8589 : NULL_TREE);
8590 528 : SET_EXPR_LOCATION (rhs, loc);
8591 528 : add_stmt (rhs);
8592 :
8593 : /* if (__atomic_compare_exchange (addr, &old, &new, false, model, model))
8594 : goto done; */
8595 528 : fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_COMPARE_EXCHANGE);
8596 528 : params->quick_push (lhs_addr);
8597 528 : params->quick_push (old_addr);
8598 528 : params->quick_push (newval_addr);
8599 528 : params->quick_push (integer_zero_node);
8600 528 : params->quick_push (model);
8601 528 : if (tree_fits_uhwi_p (model)
8602 527 : && (tree_to_uhwi (model) == MEMMODEL_RELEASE
8603 447 : || tree_to_uhwi (model) == MEMMODEL_ACQ_REL))
8604 129 : params->quick_push (build_int_cst (integer_type_node, MEMMODEL_RELAXED));
8605 : else
8606 399 : params->quick_push (model);
8607 528 : func_call = resolve_overloaded_builtin (loc, fndecl, params);
8608 528 : if (func_call == NULL_TREE)
8609 528 : func_call = build_function_call_vec (loc, vNULL, fndecl, params, NULL);
8610 :
8611 528 : tree goto_stmt = build1 (GOTO_EXPR, void_type_node, done_decl);
8612 528 : SET_EXPR_LOCATION (goto_stmt, loc);
8613 :
8614 528 : tree stmt
8615 528 : = build3 (COND_EXPR, void_type_node, func_call, goto_stmt, NULL_TREE);
8616 528 : SET_EXPR_LOCATION (stmt, loc);
8617 528 : add_stmt (stmt);
8618 :
8619 : /* goto loop; */
8620 528 : goto_stmt = build1 (GOTO_EXPR, void_type_node, loop_decl);
8621 528 : SET_EXPR_LOCATION (goto_stmt, loc);
8622 528 : add_stmt (goto_stmt);
8623 :
8624 : /* done: */
8625 528 : add_stmt (done_label);
8626 :
8627 528 : tree ret = create_tmp_var_raw (nonatomic_lhs_type);
8628 531 : stmt = build2_loc (loc, MODIFY_EXPR, void_type_node, ret,
8629 : return_old_p ? old : newval);
8630 528 : add_stmt (stmt);
8631 :
8632 : /* Finish the compound statement. */
8633 528 : stmts = pop_stmt_list (stmts);
8634 :
8635 528 : return build4 (TARGET_EXPR, nonatomic_lhs_type, ret, stmts, NULL_TREE,
8636 528 : NULL_TREE);
8637 : }
8638 :
8639 :
8640 : /* Some builtin functions are placeholders for other expressions. This
8641 : function should be called immediately after parsing the call expression
8642 : before surrounding code has committed to the type of the expression.
8643 :
8644 : LOC is the location of the builtin call.
8645 :
8646 : FUNCTION is the DECL that has been invoked; it is known to be a builtin.
8647 : PARAMS is the argument list for the call. The return value is non-null
8648 : when expansion is complete, and null if normal processing should
8649 : continue. */
8650 :
8651 : tree
8652 58738931 : resolve_overloaded_builtin (location_t loc, tree function,
8653 : vec<tree, va_gc> *params, bool complain)
8654 : {
8655 : /* Is function one of the _FETCH_OP_ or _OP_FETCH_ built-ins?
8656 : Those are not valid to call with a pointer to _Bool (or C++ bool)
8657 : and so must be rejected. */
8658 58738931 : bool fetch_op = true;
8659 58738931 : bool orig_format = true;
8660 58738931 : tree new_return = NULL_TREE;
8661 :
8662 58738931 : switch (DECL_BUILT_IN_CLASS (function))
8663 : {
8664 9070539 : case BUILT_IN_NORMAL:
8665 9070539 : break;
8666 33098740 : case BUILT_IN_MD:
8667 33098740 : if (targetm.resolve_overloaded_builtin)
8668 0 : return targetm.resolve_overloaded_builtin (loc, function, params,
8669 0 : complain);
8670 : else
8671 : return NULL_TREE;
8672 : default:
8673 : return NULL_TREE;
8674 : }
8675 :
8676 : /* Handle BUILT_IN_NORMAL here. */
8677 9070539 : enum built_in_function orig_code = DECL_FUNCTION_CODE (function);
8678 9070539 : switch (orig_code)
8679 : {
8680 155 : case BUILT_IN_SPECULATION_SAFE_VALUE_N:
8681 155 : {
8682 155 : tree new_function, first_param, result;
8683 155 : enum built_in_function fncode
8684 155 : = speculation_safe_value_resolve_call (function, params, complain);
8685 :
8686 155 : if (fncode == BUILT_IN_NONE)
8687 52 : return error_mark_node;
8688 :
8689 103 : first_param = (*params)[0];
8690 103 : if (!speculation_safe_value_resolve_params (loc, function, params,
8691 : complain))
8692 31 : return error_mark_node;
8693 :
8694 72 : if (targetm.have_speculation_safe_value (true))
8695 : {
8696 72 : new_function = builtin_decl_explicit (fncode);
8697 72 : result = build_function_call_vec (loc, vNULL, new_function, params,
8698 : NULL);
8699 :
8700 72 : if (result == error_mark_node)
8701 : return result;
8702 :
8703 72 : return speculation_safe_value_resolve_return (first_param, result);
8704 : }
8705 : else
8706 : {
8707 : /* This target doesn't have, or doesn't need, active mitigation
8708 : against incorrect speculative execution. Simply return the
8709 : first parameter to the builtin. */
8710 0 : if (!targetm.have_speculation_safe_value (false))
8711 : {
8712 0 : if (complain)
8713 : /* The user has invoked __builtin_speculation_safe_value
8714 : even though __HAVE_SPECULATION_SAFE_VALUE is not
8715 : defined: emit a warning. */
8716 0 : warning_at (
8717 0 : input_location, 0,
8718 : "this target does not define a speculation barrier; "
8719 : "your program will still execute correctly, "
8720 : "but incorrect speculation may not be "
8721 : "restricted");
8722 : else
8723 0 : return error_mark_node;
8724 : }
8725 :
8726 : /* If the optional second argument is present, handle any side
8727 : effects now. */
8728 0 : if (params->length () == 2
8729 0 : && TREE_SIDE_EFFECTS ((*params)[1]))
8730 0 : return build2 (COMPOUND_EXPR, TREE_TYPE (first_param),
8731 0 : (*params)[1], first_param);
8732 :
8733 : return first_param;
8734 : }
8735 : }
8736 :
8737 130034 : case BUILT_IN_ATOMIC_EXCHANGE:
8738 130034 : case BUILT_IN_ATOMIC_COMPARE_EXCHANGE:
8739 130034 : case BUILT_IN_ATOMIC_LOAD:
8740 130034 : case BUILT_IN_ATOMIC_STORE:
8741 130034 : {
8742 : /* Handle these 4 together so that they can fall through to the next
8743 : case if the call is transformed to an _N variant. */
8744 130034 : switch (orig_code)
8745 : {
8746 631 : case BUILT_IN_ATOMIC_EXCHANGE:
8747 631 : {
8748 631 : if (resolve_overloaded_atomic_exchange (loc, function, params,
8749 : &new_return, complain))
8750 234 : return new_return;
8751 : /* Change to the _N variant. */
8752 : orig_code = BUILT_IN_ATOMIC_EXCHANGE_N;
8753 : break;
8754 : }
8755 :
8756 40981 : case BUILT_IN_ATOMIC_COMPARE_EXCHANGE:
8757 40981 : {
8758 40981 : if (resolve_overloaded_atomic_compare_exchange (
8759 : loc, function, params, &new_return, complain))
8760 1376 : return new_return;
8761 : /* Change to the _N variant. */
8762 : orig_code = BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N;
8763 : break;
8764 : }
8765 76940 : case BUILT_IN_ATOMIC_LOAD:
8766 76940 : {
8767 76940 : if (resolve_overloaded_atomic_load (loc, function, params,
8768 : &new_return, complain))
8769 2777 : return new_return;
8770 : /* Change to the _N variant. */
8771 : orig_code = BUILT_IN_ATOMIC_LOAD_N;
8772 : break;
8773 : }
8774 11482 : case BUILT_IN_ATOMIC_STORE:
8775 11482 : {
8776 11482 : if (resolve_overloaded_atomic_store (loc, function, params,
8777 : &new_return, complain))
8778 578 : return new_return;
8779 : /* Change to the _N variant. */
8780 : orig_code = BUILT_IN_ATOMIC_STORE_N;
8781 : break;
8782 : }
8783 0 : default:
8784 0 : gcc_unreachable ();
8785 : }
8786 : }
8787 : /* FALLTHRU */
8788 : case BUILT_IN_ATOMIC_EXCHANGE_N:
8789 : case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N:
8790 : case BUILT_IN_ATOMIC_LOAD_N:
8791 : case BUILT_IN_ATOMIC_STORE_N:
8792 : fetch_op = false;
8793 : /* FALLTHRU */
8794 : case BUILT_IN_ATOMIC_ADD_FETCH_N:
8795 : case BUILT_IN_ATOMIC_SUB_FETCH_N:
8796 : case BUILT_IN_ATOMIC_AND_FETCH_N:
8797 : case BUILT_IN_ATOMIC_NAND_FETCH_N:
8798 : case BUILT_IN_ATOMIC_XOR_FETCH_N:
8799 : case BUILT_IN_ATOMIC_OR_FETCH_N:
8800 : case BUILT_IN_ATOMIC_FETCH_ADD_N:
8801 : case BUILT_IN_ATOMIC_FETCH_SUB_N:
8802 : case BUILT_IN_ATOMIC_FETCH_AND_N:
8803 : case BUILT_IN_ATOMIC_FETCH_NAND_N:
8804 : case BUILT_IN_ATOMIC_FETCH_XOR_N:
8805 : case BUILT_IN_ATOMIC_FETCH_OR_N:
8806 : orig_format = false;
8807 : /* FALLTHRU */
8808 : case BUILT_IN_SYNC_FETCH_AND_ADD_N:
8809 : case BUILT_IN_SYNC_FETCH_AND_SUB_N:
8810 : case BUILT_IN_SYNC_FETCH_AND_OR_N:
8811 : case BUILT_IN_SYNC_FETCH_AND_AND_N:
8812 : case BUILT_IN_SYNC_FETCH_AND_XOR_N:
8813 : case BUILT_IN_SYNC_FETCH_AND_NAND_N:
8814 : case BUILT_IN_SYNC_ADD_AND_FETCH_N:
8815 : case BUILT_IN_SYNC_SUB_AND_FETCH_N:
8816 : case BUILT_IN_SYNC_OR_AND_FETCH_N:
8817 : case BUILT_IN_SYNC_AND_AND_FETCH_N:
8818 : case BUILT_IN_SYNC_XOR_AND_FETCH_N:
8819 : case BUILT_IN_SYNC_NAND_AND_FETCH_N:
8820 : case BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N:
8821 : case BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_N:
8822 : case BUILT_IN_SYNC_LOCK_TEST_AND_SET_N:
8823 : case BUILT_IN_SYNC_LOCK_RELEASE_N:
8824 : {
8825 : /* The following are not _FETCH_OPs and must be accepted with
8826 : pointers to _Bool (or C++ bool). */
8827 : if (fetch_op)
8828 99853 : fetch_op = (orig_code != BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
8829 99853 : && orig_code != BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_N
8830 99367 : && orig_code != BUILT_IN_SYNC_LOCK_TEST_AND_SET_N
8831 99853 : && orig_code != BUILT_IN_SYNC_LOCK_RELEASE_N);
8832 :
8833 418505 : int n = sync_resolve_size (function, params, fetch_op, orig_format,
8834 : complain);
8835 418505 : tree new_function, first_param, result;
8836 418505 : enum built_in_function fncode;
8837 :
8838 418505 : if (n == 0)
8839 2584 : return error_mark_node;
8840 :
8841 415921 : if (n == -1)
8842 : {
8843 : /* complain is related to SFINAE context.
8844 : _BitInt is not defined in C++, hence can't enter this clause
8845 : with complain unset. Even if at the abstraction level
8846 : this complain is unset that still makes sense (whether
8847 : this function should report an error or not if anything is
8848 : wrong).
8849 : Since can't test avoiding an error when this value is false not
8850 : writing the code and instead asserting value is not set. */
8851 528 : gcc_assert (complain);
8852 528 : return atomic_bitint_fetch_using_cas_loop (loc, orig_code, function,
8853 528 : params);
8854 : }
8855 :
8856 415393 : fncode = (enum built_in_function)((int)orig_code + exact_log2 (n) + 1);
8857 415393 : new_function = builtin_decl_explicit (fncode);
8858 415393 : if (!sync_resolve_params (loc, function, new_function, params,
8859 : orig_format, complain))
8860 164 : return error_mark_node;
8861 :
8862 415229 : first_param = (*params)[0];
8863 415229 : result = build_function_call_vec (loc, vNULL, new_function, params,
8864 : NULL);
8865 415229 : if (result == error_mark_node)
8866 : return result;
8867 415217 : if (orig_code != BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
8868 415217 : && orig_code != BUILT_IN_SYNC_LOCK_RELEASE_N
8869 414910 : && orig_code != BUILT_IN_ATOMIC_STORE_N
8870 414910 : && orig_code != BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N)
8871 278094 : result = sync_resolve_return (first_param, result, orig_format);
8872 :
8873 415217 : if (fetch_op)
8874 : /* Prevent -Wunused-value warning. */
8875 96371 : TREE_USED (result) = true;
8876 :
8877 : /* If new_return is set, assign function to that expr and cast the
8878 : result to void since the generic interface returned void. */
8879 415217 : if (new_return)
8880 : {
8881 : /* Cast function result from I{1,2,4,8,16} to the required type. */
8882 74560 : if (TREE_CODE (TREE_TYPE (new_return)) == BITINT_TYPE)
8883 : {
8884 599 : struct bitint_info info;
8885 599 : unsigned prec = TYPE_PRECISION (TREE_TYPE (new_return));
8886 599 : targetm.c.bitint_type_info (prec, &info);
8887 599 : if (!info.extended)
8888 : /* For _BitInt which has the padding bits undefined
8889 : convert to the _BitInt type rather than VCE to force
8890 : zero or sign extension. */
8891 599 : result = build1 (NOP_EXPR, TREE_TYPE (new_return), result);
8892 : }
8893 74560 : result
8894 74560 : = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (new_return), result);
8895 74560 : result = build2 (MODIFY_EXPR, TREE_TYPE (new_return), new_return,
8896 : result);
8897 74560 : TREE_SIDE_EFFECTS (result) = 1;
8898 74560 : protected_set_expr_location (result, loc);
8899 74560 : result = convert (void_type_node, result);
8900 : }
8901 : return result;
8902 : }
8903 :
8904 : default:
8905 : return NULL_TREE;
8906 : }
8907 : }
8908 :
8909 : /* vector_types_compatible_elements_p is used in type checks of vectors
8910 : values used as operands of binary operators. Where it returns true, and
8911 : the other checks of the caller succeed (being vector types in he first
8912 : place, and matching number of elements), we can just treat the types
8913 : as essentially the same.
8914 : Contrast with vector_targets_convertible_p, which is used for vector
8915 : pointer types, and vector_types_convertible_p, which will allow
8916 : language-specific matches under the control of flag_lax_vector_conversions,
8917 : and might still require a conversion. */
8918 : /* True if vector types T1 and T2 can be inputs to the same binary
8919 : operator without conversion.
8920 : We don't check the overall vector size here because some of our callers
8921 : want to give different error messages when the vectors are compatible
8922 : except for the element count. */
8923 :
8924 : bool
8925 1639985 : vector_types_compatible_elements_p (tree t1, tree t2)
8926 : {
8927 3279694 : bool opaque = TYPE_VECTOR_OPAQUE (t1) || TYPE_VECTOR_OPAQUE (t2);
8928 1639985 : t1 = TREE_TYPE (t1);
8929 1639985 : t2 = TREE_TYPE (t2);
8930 :
8931 1639985 : enum tree_code c1 = TREE_CODE (t1), c2 = TREE_CODE (t2);
8932 :
8933 1639985 : gcc_assert ((INTEGRAL_TYPE_P (t1)
8934 : || c1 == REAL_TYPE
8935 : || c1 == FIXED_POINT_TYPE)
8936 : && (INTEGRAL_TYPE_P (t2)
8937 : || c2 == REAL_TYPE
8938 : || c2 == FIXED_POINT_TYPE));
8939 :
8940 1639985 : t1 = c_common_signed_type (t1);
8941 1639985 : t2 = c_common_signed_type (t2);
8942 : /* Equality works here because c_common_signed_type uses
8943 : TYPE_MAIN_VARIANT. */
8944 1639985 : if (t1 == t2)
8945 : return true;
8946 31 : if (opaque && c1 == c2
8947 4 : && (INTEGRAL_TYPE_P (t1) || c1 == REAL_TYPE)
8948 35 : && TYPE_PRECISION (t1) == TYPE_PRECISION (t2))
8949 4 : return true;
8950 : return false;
8951 : }
8952 :
8953 : /* Check for missing format attributes on function pointers. LTYPE is
8954 : the new type or left-hand side type. RTYPE is the old type or
8955 : right-hand side type. Returns TRUE if LTYPE is missing the desired
8956 : attribute. */
8957 :
8958 : bool
8959 9938 : check_missing_format_attribute (tree ltype, tree rtype)
8960 : {
8961 9938 : tree const ttr = TREE_TYPE (rtype), ttl = TREE_TYPE (ltype);
8962 9938 : tree ra;
8963 :
8964 9947 : for (ra = TYPE_ATTRIBUTES (ttr); ra; ra = TREE_CHAIN (ra))
8965 73 : if (is_attribute_p ("format", get_attribute_name (ra)))
8966 : break;
8967 9938 : if (ra)
8968 : {
8969 64 : tree la;
8970 64 : for (la = TYPE_ATTRIBUTES (ttl); la; la = TREE_CHAIN (la))
8971 24 : if (is_attribute_p ("format", get_attribute_name (la)))
8972 : break;
8973 64 : return !la;
8974 : }
8975 : else
8976 : return false;
8977 : }
8978 :
8979 : /* Setup a TYPE_DECL node as a typedef representation.
8980 :
8981 : X is a TYPE_DECL for a typedef statement. Create a brand new
8982 : ..._TYPE node (which will be just a variant of the existing
8983 : ..._TYPE node with identical properties) and then install X
8984 : as the TYPE_NAME of this brand new (duplicate) ..._TYPE node.
8985 :
8986 : The whole point here is to end up with a situation where each
8987 : and every ..._TYPE node the compiler creates will be uniquely
8988 : associated with AT MOST one node representing a typedef name.
8989 : This way, even though the compiler substitutes corresponding
8990 : ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very
8991 : early on, later parts of the compiler can always do the reverse
8992 : translation and get back the corresponding typedef name. For
8993 : example, given:
8994 :
8995 : typedef struct S MY_TYPE;
8996 : MY_TYPE object;
8997 :
8998 : Later parts of the compiler might only know that `object' was of
8999 : type `struct S' if it were not for code just below. With this
9000 : code however, later parts of the compiler see something like:
9001 :
9002 : struct S' == struct S
9003 : typedef struct S' MY_TYPE;
9004 : struct S' object;
9005 :
9006 : And they can then deduce (from the node for type struct S') that
9007 : the original object declaration was:
9008 :
9009 : MY_TYPE object;
9010 :
9011 : Being able to do this is important for proper support of protoize,
9012 : and also for generating precise symbolic debugging information
9013 : which takes full account of the programmer's (typedef) vocabulary.
9014 :
9015 : Obviously, we don't want to generate a duplicate ..._TYPE node if
9016 : the TYPE_DECL node that we are now processing really represents a
9017 : standard built-in type. */
9018 :
9019 : void
9020 203409301 : set_underlying_type (tree x)
9021 : {
9022 203409301 : if (x == error_mark_node || TREE_TYPE (x) == error_mark_node)
9023 : return;
9024 203409272 : if (DECL_IS_UNDECLARED_BUILTIN (x) && TREE_CODE (TREE_TYPE (x)) != ARRAY_TYPE)
9025 : {
9026 6298270 : if (TYPE_NAME (TREE_TYPE (x)) == 0)
9027 5025809 : TYPE_NAME (TREE_TYPE (x)) = x;
9028 : }
9029 197111002 : else if (DECL_ORIGINAL_TYPE (x))
9030 166317 : gcc_checking_assert (TYPE_NAME (TREE_TYPE (x)) == x);
9031 : else
9032 : {
9033 196944685 : tree tt = TREE_TYPE (x);
9034 196944685 : DECL_ORIGINAL_TYPE (x) = tt;
9035 196944685 : tt = build_variant_type_copy (tt);
9036 196944685 : TYPE_STUB_DECL (tt) = TYPE_STUB_DECL (DECL_ORIGINAL_TYPE (x));
9037 196944685 : TYPE_NAME (tt) = x;
9038 :
9039 : /* Mark the type as used only when its type decl is decorated
9040 : with attribute unused. */
9041 196944685 : if (lookup_attribute ("unused", DECL_ATTRIBUTES (x)))
9042 263 : TREE_USED (tt) = 1;
9043 :
9044 196944685 : TREE_TYPE (x) = tt;
9045 : }
9046 : }
9047 :
9048 : /* Return true if it is worth exposing the DECL_ORIGINAL_TYPE of TYPE to
9049 : the user in diagnostics, false if it would be better to use TYPE itself.
9050 : TYPE is known to satisfy typedef_variant_p. */
9051 :
9052 : bool
9053 34099 : user_facing_original_type_p (const_tree type)
9054 : {
9055 34099 : gcc_assert (typedef_variant_p (type));
9056 34099 : tree decl = TYPE_NAME (type);
9057 :
9058 : /* Look through any typedef in "user" code. */
9059 34099 : if (!DECL_IN_SYSTEM_HEADER (decl) && !DECL_IS_UNDECLARED_BUILTIN (decl))
9060 : return true;
9061 :
9062 : /* If the original type is also named and is in the user namespace,
9063 : assume it too is a user-facing type. */
9064 1659 : tree orig_type = DECL_ORIGINAL_TYPE (decl);
9065 1659 : if (tree orig_id = TYPE_IDENTIFIER (orig_type))
9066 1531 : if (!name_reserved_for_implementation_p (IDENTIFIER_POINTER (orig_id)))
9067 : return true;
9068 :
9069 708 : switch (TREE_CODE (orig_type))
9070 : {
9071 : /* Don't look through to an anonymous vector type, since the syntax
9072 : we use for them in diagnostics isn't real C or C++ syntax.
9073 : And if ORIG_TYPE is named but in the implementation namespace,
9074 : TYPE is likely to be more meaningful to the user. */
9075 : case VECTOR_TYPE:
9076 : return false;
9077 :
9078 : /* Don't expose anonymous tag types that are presumably meant to be
9079 : known by their typedef name. Also don't expose tags that are in
9080 : the implementation namespace, such as:
9081 :
9082 : typedef struct __foo foo; */
9083 : case RECORD_TYPE:
9084 : case UNION_TYPE:
9085 : case ENUMERAL_TYPE:
9086 : return false;
9087 :
9088 : /* Look through to anything else. */
9089 : default:
9090 : return true;
9091 : }
9092 : }
9093 :
9094 : /* Record the types used by the current global variable declaration
9095 : being parsed, so that we can decide later to emit their debug info.
9096 : Those types are in types_used_by_cur_var_decl, and we are going to
9097 : store them in the types_used_by_vars_hash hash table.
9098 : DECL is the declaration of the global variable that has been parsed. */
9099 :
9100 : void
9101 36098780 : record_types_used_by_current_var_decl (tree decl)
9102 : {
9103 36098780 : gcc_assert (decl && DECL_P (decl) && TREE_STATIC (decl));
9104 :
9105 61469329 : while (types_used_by_cur_var_decl && !types_used_by_cur_var_decl->is_empty ())
9106 : {
9107 25370549 : tree type = types_used_by_cur_var_decl->pop ();
9108 25370549 : types_used_by_var_decl_insert (type, decl);
9109 : }
9110 36098780 : }
9111 :
9112 : /* The C and C++ parsers both use vectors to hold function arguments.
9113 : For efficiency, we keep a cache of unused vectors. This is the
9114 : cache. */
9115 :
9116 : typedef vec<tree, va_gc> *tree_gc_vec;
9117 : static GTY((deletable)) vec<tree_gc_vec, va_gc> *tree_vector_cache;
9118 :
9119 : /* Return a new vector from the cache. If the cache is empty,
9120 : allocate a new vector. These vectors are GC'ed, so it is OK if the
9121 : pointer is not released.. */
9122 :
9123 : vec<tree, va_gc> *
9124 1273010284 : make_tree_vector (void)
9125 : {
9126 1273010284 : if (tree_vector_cache && !tree_vector_cache->is_empty ())
9127 1224490977 : return tree_vector_cache->pop ();
9128 : else
9129 : {
9130 : /* Passing 0 to vec::alloc returns NULL, and our callers require
9131 : that we always return a non-NULL value. The vector code uses
9132 : 4 when growing a NULL vector, so we do too. */
9133 48519307 : vec<tree, va_gc> *v;
9134 48519307 : vec_alloc (v, 4);
9135 48519307 : return v;
9136 : }
9137 : }
9138 :
9139 : /* Release a vector of trees back to the cache. */
9140 :
9141 : void
9142 1743786748 : release_tree_vector (vec<tree, va_gc> *vec)
9143 : {
9144 1743786748 : if (vec != NULL)
9145 : {
9146 1227017244 : if (vec->allocated () >= 16)
9147 : /* Don't cache vecs that have expanded more than once. On a p64
9148 : target, vecs double in alloc size with each power of 2 elements, e.g
9149 : at 16 elements the alloc increases from 128 to 256 bytes. */
9150 1679833 : vec_free (vec);
9151 : else
9152 : {
9153 1225337411 : vec->truncate (0);
9154 1225337411 : vec_safe_push (tree_vector_cache, vec);
9155 : }
9156 : }
9157 1743786748 : }
9158 :
9159 : /* Get a new tree vector holding a single tree. */
9160 :
9161 : vec<tree, va_gc> *
9162 71432238 : make_tree_vector_single (tree t)
9163 : {
9164 71432238 : vec<tree, va_gc> *ret = make_tree_vector ();
9165 71432238 : ret->quick_push (t);
9166 71432238 : return ret;
9167 : }
9168 :
9169 : /* Get a new tree vector of the TREE_VALUEs of a TREE_LIST chain. */
9170 :
9171 : vec<tree, va_gc> *
9172 9744 : make_tree_vector_from_list (tree list)
9173 : {
9174 9744 : vec<tree, va_gc> *ret = make_tree_vector ();
9175 25253 : for (; list; list = TREE_CHAIN (list))
9176 15509 : vec_safe_push (ret, TREE_VALUE (list));
9177 9744 : return ret;
9178 : }
9179 :
9180 : /* Append to a tree vector V the values of a CONSTRUCTOR CTOR
9181 : and return the new possibly reallocated vector. */
9182 :
9183 : vec<tree, va_gc> *
9184 2414992 : append_ctor_to_tree_vector (vec<tree, va_gc> *v, tree ctor)
9185 : {
9186 4594726 : unsigned nelts = vec_safe_length (v) + CONSTRUCTOR_NELTS (ctor);
9187 2414992 : vec_safe_reserve (v, CONSTRUCTOR_NELTS (ctor));
9188 5735285 : for (unsigned i = 0; i < CONSTRUCTOR_NELTS (ctor); ++i)
9189 3320293 : if (TREE_CODE (CONSTRUCTOR_ELT (ctor, i)->value) == RAW_DATA_CST)
9190 : {
9191 24 : tree raw_data = CONSTRUCTOR_ELT (ctor, i)->value;
9192 24 : nelts += RAW_DATA_LENGTH (raw_data) - 1;
9193 24 : vec_safe_reserve (v, nelts - v->length ());
9194 48 : if (TYPE_PRECISION (TREE_TYPE (raw_data)) > CHAR_BIT
9195 24 : || TYPE_UNSIGNED (TREE_TYPE (raw_data)))
9196 6264 : for (unsigned j = 0; j < (unsigned) RAW_DATA_LENGTH (raw_data); ++j)
9197 6240 : v->quick_push (build_int_cst (TREE_TYPE (raw_data),
9198 6240 : RAW_DATA_UCHAR_ELT (raw_data, j)));
9199 : else
9200 0 : for (unsigned j = 0; j < (unsigned) RAW_DATA_LENGTH (raw_data); ++j)
9201 0 : v->quick_push (build_int_cst (TREE_TYPE (raw_data),
9202 0 : RAW_DATA_SCHAR_ELT (raw_data, j)));
9203 : }
9204 : else
9205 3320269 : v->quick_push (CONSTRUCTOR_ELT (ctor, i)->value);
9206 2414992 : return v;
9207 : }
9208 :
9209 : /* Get a new tree vector of the values of a CONSTRUCTOR. */
9210 :
9211 : vec<tree, va_gc> *
9212 6161 : make_tree_vector_from_ctor (tree ctor)
9213 : {
9214 6161 : vec<tree,va_gc> *ret
9215 6161 : = CONSTRUCTOR_NELTS (ctor) <= 16 ? make_tree_vector () : NULL;
9216 6161 : return append_ctor_to_tree_vector (ret, ctor);
9217 : }
9218 :
9219 : /* Get a new tree vector which is a copy of an existing one. */
9220 :
9221 : vec<tree, va_gc> *
9222 28830361 : make_tree_vector_copy (const vec<tree, va_gc> *orig)
9223 : {
9224 28830361 : vec<tree, va_gc> *ret;
9225 28830361 : unsigned int ix;
9226 28830361 : tree t;
9227 :
9228 28830361 : ret = make_tree_vector ();
9229 28830361 : vec_safe_reserve (ret, vec_safe_length (orig));
9230 71542152 : FOR_EACH_VEC_SAFE_ELT (orig, ix, t)
9231 13881430 : ret->quick_push (t);
9232 28830361 : return ret;
9233 : }
9234 :
9235 : /* Return true if KEYWORD starts a type specifier. */
9236 :
9237 : bool
9238 20 : keyword_begins_type_specifier (enum rid keyword)
9239 : {
9240 20 : switch (keyword)
9241 : {
9242 : case RID_AUTO_TYPE:
9243 : case RID_INT:
9244 : case RID_CHAR:
9245 : case RID_FLOAT:
9246 : case RID_DOUBLE:
9247 : case RID_VOID:
9248 : case RID_UNSIGNED:
9249 : case RID_LONG:
9250 : case RID_SHORT:
9251 : case RID_SIGNED:
9252 : CASE_RID_FLOATN_NX:
9253 : case RID_DFLOAT32:
9254 : case RID_DFLOAT64:
9255 : case RID_DFLOAT128:
9256 : case RID_FRACT:
9257 : case RID_ACCUM:
9258 : case RID_BOOL:
9259 : case RID_BITINT:
9260 : case RID_WCHAR:
9261 : case RID_CHAR8:
9262 : case RID_CHAR16:
9263 : case RID_CHAR32:
9264 : case RID_SAT:
9265 : case RID_COMPLEX:
9266 : case RID_TYPEOF:
9267 : case RID_STRUCT:
9268 : case RID_CLASS:
9269 : case RID_UNION:
9270 : case RID_ENUM:
9271 : return true;
9272 5 : default:
9273 5 : if (keyword >= RID_FIRST_INT_N
9274 : && keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS
9275 0 : && int_n_enabled_p[keyword-RID_FIRST_INT_N])
9276 : return true;
9277 : return false;
9278 : }
9279 : }
9280 :
9281 : /* Return true if KEYWORD names a type qualifier. */
9282 :
9283 : bool
9284 11831 : keyword_is_type_qualifier (enum rid keyword)
9285 : {
9286 11831 : switch (keyword)
9287 : {
9288 : case RID_CONST:
9289 : case RID_VOLATILE:
9290 : case RID_RESTRICT:
9291 : case RID_ATOMIC:
9292 : return true;
9293 64 : default:
9294 64 : return false;
9295 : }
9296 : }
9297 :
9298 : /* Return true if KEYWORD names a storage class specifier.
9299 :
9300 : RID_TYPEDEF is not included in this list despite `typedef' being
9301 : listed in C99 6.7.1.1. 6.7.1.3 indicates that `typedef' is listed as
9302 : such for syntactic convenience only. */
9303 :
9304 : bool
9305 11862 : keyword_is_storage_class_specifier (enum rid keyword)
9306 : {
9307 11862 : switch (keyword)
9308 : {
9309 : case RID_STATIC:
9310 : case RID_EXTERN:
9311 : case RID_REGISTER:
9312 : case RID_AUTO:
9313 : case RID_MUTABLE:
9314 : case RID_THREAD:
9315 : return true;
9316 11831 : default:
9317 11831 : return false;
9318 : }
9319 : }
9320 :
9321 : /* Return true if KEYWORD names a function-specifier [dcl.fct.spec]. */
9322 :
9323 : static bool
9324 64 : keyword_is_function_specifier (enum rid keyword)
9325 : {
9326 64 : switch (keyword)
9327 : {
9328 : case RID_INLINE:
9329 : case RID_NORETURN:
9330 : case RID_VIRTUAL:
9331 : case RID_EXPLICIT:
9332 : return true;
9333 62 : default:
9334 0 : return false;
9335 : }
9336 : }
9337 :
9338 : /* Return true if KEYWORD names a decl-specifier [dcl.spec] or a
9339 : declaration-specifier (C99 6.7). */
9340 :
9341 : bool
9342 11862 : keyword_is_decl_specifier (enum rid keyword)
9343 : {
9344 11862 : if (keyword_is_storage_class_specifier (keyword)
9345 11831 : || keyword_is_type_qualifier (keyword)
9346 11862 : || keyword_is_function_specifier (keyword))
9347 11800 : return true;
9348 :
9349 62 : switch (keyword)
9350 : {
9351 : case RID_TYPEDEF:
9352 : case RID_FRIEND:
9353 : case RID_CONSTEXPR:
9354 : case RID_CONSTINIT:
9355 : return true;
9356 : default:
9357 : return false;
9358 : }
9359 : }
9360 :
9361 : /* Initialize language-specific-bits of tree_contains_struct. */
9362 :
9363 : void
9364 209896 : c_common_init_ts (void)
9365 : {
9366 209896 : MARK_TS_EXP (SIZEOF_EXPR);
9367 209896 : MARK_TS_EXP (PAREN_SIZEOF_EXPR);
9368 209896 : MARK_TS_EXP (C_MAYBE_CONST_EXPR);
9369 209896 : MARK_TS_EXP (EXCESS_PRECISION_EXPR);
9370 209896 : MARK_TS_EXP (BREAK_STMT);
9371 209896 : MARK_TS_EXP (CONTINUE_STMT);
9372 209896 : MARK_TS_EXP (DO_STMT);
9373 209896 : MARK_TS_EXP (FOR_STMT);
9374 209896 : MARK_TS_EXP (SWITCH_STMT);
9375 209896 : MARK_TS_EXP (WHILE_STMT);
9376 :
9377 209896 : MARK_TS_DECL_COMMON (CONCEPT_DECL);
9378 209896 : }
9379 :
9380 : /* Build a user-defined numeric literal out of an integer constant type VALUE
9381 : with identifier SUFFIX. */
9382 :
9383 : tree
9384 1129138 : build_userdef_literal (tree suffix_id, tree value,
9385 : enum overflow_type overflow, tree num_string)
9386 : {
9387 1129138 : tree literal = make_node (USERDEF_LITERAL);
9388 1129138 : USERDEF_LITERAL_SUFFIX_ID (literal) = suffix_id;
9389 1129138 : USERDEF_LITERAL_VALUE (literal) = value;
9390 1129138 : USERDEF_LITERAL_OVERFLOW (literal) = overflow;
9391 1129138 : USERDEF_LITERAL_NUM_STRING (literal) = num_string;
9392 1129138 : return literal;
9393 : }
9394 :
9395 : /* For vector[index], convert the vector to an array of the underlying type.
9396 : Return true if the resulting ARRAY_REF should not be an lvalue. */
9397 :
9398 : bool
9399 9334174 : convert_vector_to_array_for_subscript (location_t loc,
9400 : tree *vecp, tree index)
9401 : {
9402 9334174 : bool ret = false;
9403 9334174 : if (gnu_vector_type_p (TREE_TYPE (*vecp)))
9404 : {
9405 1083567 : tree type = TREE_TYPE (*vecp);
9406 1083567 : tree newitype;
9407 :
9408 1083567 : ret = !lvalue_p (*vecp);
9409 :
9410 1083567 : index = fold_for_warn (index);
9411 : /* Warn out-of-bounds index for vectors only if known. */
9412 1083567 : if (poly_int_tree_p (index))
9413 1070147 : if (!tree_fits_poly_uint64_p (index)
9414 1070147 : || known_ge (tree_to_poly_uint64 (index),
9415 : TYPE_VECTOR_SUBPARTS (type)))
9416 84 : warning_at (loc, OPT_Warray_bounds_, "index value is out of bound");
9417 :
9418 : /* We are building an ARRAY_REF so mark the vector as addressable
9419 : to not run into the gimplifiers premature setting of DECL_GIMPLE_REG_P
9420 : for function parameters. */
9421 1083567 : c_common_mark_addressable_vec (*vecp);
9422 :
9423 : /* Make sure qualifiers are copied from the vector type to the new element
9424 : of the array type. */
9425 1083567 : newitype = build_qualified_type (TREE_TYPE (type), TYPE_QUALS (type));
9426 :
9427 1083567 : *vecp = build1 (VIEW_CONVERT_EXPR,
9428 : build_array_type_nelts (newitype,
9429 : TYPE_VECTOR_SUBPARTS (type)),
9430 : *vecp);
9431 : }
9432 9334174 : return ret;
9433 : }
9434 :
9435 : /* Determine which of the operands, if any, is a scalar that needs to be
9436 : converted to a vector, for the range of operations. */
9437 : enum stv_conv
9438 3662 : scalar_to_vector (location_t loc, enum tree_code code, tree op0, tree op1,
9439 : bool complain)
9440 : {
9441 3662 : tree type0 = TREE_TYPE (op0);
9442 3662 : tree type1 = TREE_TYPE (op1);
9443 3662 : bool integer_only_op = false;
9444 3662 : enum stv_conv ret = stv_firstarg;
9445 :
9446 3662 : gcc_assert (gnu_vector_type_p (type0) || gnu_vector_type_p (type1));
9447 3662 : switch (code)
9448 : {
9449 : /* Most GENERIC binary expressions require homogeneous arguments.
9450 : LSHIFT_EXPR and RSHIFT_EXPR are exceptions and accept a first
9451 : argument that is a vector and a second one that is a scalar, so
9452 : we never return stv_secondarg for them. */
9453 986 : case RSHIFT_EXPR:
9454 986 : case LSHIFT_EXPR:
9455 986 : if (TREE_CODE (type0) == INTEGER_TYPE
9456 986 : && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE)
9457 : {
9458 50 : if (unsafe_conversion_p (TREE_TYPE (type1), op0,
9459 : NULL_TREE, false))
9460 : {
9461 0 : if (complain)
9462 0 : error_at (loc, "conversion of scalar %qT to vector %qT "
9463 : "involves truncation", type0, type1);
9464 0 : return stv_error;
9465 : }
9466 : else
9467 : return stv_firstarg;
9468 : }
9469 : break;
9470 :
9471 315 : case BIT_IOR_EXPR:
9472 315 : case BIT_XOR_EXPR:
9473 315 : case BIT_AND_EXPR:
9474 315 : integer_only_op = true;
9475 : /* fall through */
9476 :
9477 2664 : case VEC_COND_EXPR:
9478 :
9479 2664 : case PLUS_EXPR:
9480 2664 : case MINUS_EXPR:
9481 2664 : case MULT_EXPR:
9482 2664 : case TRUNC_DIV_EXPR:
9483 2664 : case CEIL_DIV_EXPR:
9484 2664 : case FLOOR_DIV_EXPR:
9485 2664 : case ROUND_DIV_EXPR:
9486 2664 : case EXACT_DIV_EXPR:
9487 2664 : case TRUNC_MOD_EXPR:
9488 2664 : case FLOOR_MOD_EXPR:
9489 2664 : case RDIV_EXPR:
9490 2664 : case EQ_EXPR:
9491 2664 : case NE_EXPR:
9492 2664 : case LE_EXPR:
9493 2664 : case GE_EXPR:
9494 2664 : case LT_EXPR:
9495 2664 : case GT_EXPR:
9496 : /* What about UNLT_EXPR? */
9497 2664 : if (gnu_vector_type_p (type0))
9498 : {
9499 2007 : ret = stv_secondarg;
9500 2007 : std::swap (type0, type1);
9501 2007 : std::swap (op0, op1);
9502 : }
9503 :
9504 2664 : if (TREE_CODE (type0) == INTEGER_TYPE
9505 2664 : && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE)
9506 : {
9507 1948 : if (unsafe_conversion_p (TREE_TYPE (type1), op0,
9508 : NULL_TREE, false))
9509 : {
9510 11 : if (complain)
9511 8 : error_at (loc, "conversion of scalar %qT to vector %qT "
9512 : "involves truncation", type0, type1);
9513 11 : return stv_error;
9514 : }
9515 : return ret;
9516 : }
9517 716 : else if (!integer_only_op
9518 : /* Allow integer --> real conversion if safe. */
9519 716 : && (SCALAR_FLOAT_TYPE_P (type0)
9520 470 : || TREE_CODE (type0) == INTEGER_TYPE)
9521 1432 : && SCALAR_FLOAT_TYPE_P (TREE_TYPE (type1)))
9522 : {
9523 692 : if (unsafe_conversion_p (TREE_TYPE (type1), op0,
9524 : NULL_TREE, false))
9525 : {
9526 22 : if (complain)
9527 22 : error_at (loc, "conversion of scalar %qT to vector %qT "
9528 : "involves truncation", type0, type1);
9529 22 : return stv_error;
9530 : }
9531 : return ret;
9532 : }
9533 : default:
9534 : break;
9535 : }
9536 :
9537 : return stv_nothing;
9538 : }
9539 :
9540 : /* Return the alignment of std::max_align_t.
9541 :
9542 : [support.types.layout] The type max_align_t is a POD type whose alignment
9543 : requirement is at least as great as that of every scalar type, and whose
9544 : alignment requirement is supported in every context. */
9545 :
9546 : unsigned
9547 258352 : max_align_t_align ()
9548 : {
9549 258352 : unsigned int max_align = MAX (TYPE_ALIGN (long_long_integer_type_node),
9550 : TYPE_ALIGN (long_double_type_node));
9551 258352 : if (float128_type_node != NULL_TREE)
9552 258352 : max_align = MAX (max_align, TYPE_ALIGN (float128_type_node));
9553 258352 : return max_align;
9554 : }
9555 :
9556 : /* Return true iff ALIGN is an integral constant that is a fundamental
9557 : alignment, as defined by [basic.align] in the c++-11
9558 : specifications.
9559 :
9560 : That is:
9561 :
9562 : [A fundamental alignment is represented by an alignment less than or
9563 : equal to the greatest alignment supported by the implementation
9564 : in all contexts, which is equal to alignof(max_align_t)]. */
9565 :
9566 : bool
9567 0 : cxx_fundamental_alignment_p (unsigned align)
9568 : {
9569 0 : return (align <= max_align_t_align ());
9570 : }
9571 :
9572 : /* Return true if T is a pointer to a zero-sized aggregate. */
9573 :
9574 : bool
9575 1464563 : pointer_to_zero_sized_aggr_p (tree t)
9576 : {
9577 1464563 : if (!POINTER_TYPE_P (t))
9578 : return false;
9579 1464563 : t = TREE_TYPE (t);
9580 1464563 : return (TYPE_SIZE (t) && integer_zerop (TYPE_SIZE (t)));
9581 : }
9582 :
9583 : /* For an EXPR of a FUNCTION_TYPE that references a GCC built-in function
9584 : with no library fallback or for an ADDR_EXPR whose operand is such type
9585 : issues an error pointing to the location LOC.
9586 : Returns true when the expression has been diagnosed and false
9587 : otherwise. */
9588 :
9589 : bool
9590 5869341430 : reject_gcc_builtin (const_tree expr, location_t loc /* = UNKNOWN_LOCATION */)
9591 : {
9592 5869341430 : if (TREE_CODE (expr) == ADDR_EXPR)
9593 164947883 : expr = TREE_OPERAND (expr, 0);
9594 :
9595 5869341430 : STRIP_ANY_LOCATION_WRAPPER (expr);
9596 :
9597 5869341430 : if (TREE_TYPE (expr)
9598 5869341170 : && TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE
9599 2672632 : && TREE_CODE (expr) == FUNCTION_DECL
9600 : /* The intersection of DECL_BUILT_IN and DECL_IS_UNDECLARED_BUILTIN avoids
9601 : false positives for user-declared built-ins such as abs or
9602 : strlen, and for C++ operators new and delete.
9603 : The c_decl_implicit() test avoids false positives for implicitly
9604 : declared built-ins with library fallbacks (such as abs). */
9605 2640342 : && fndecl_built_in_p (expr)
9606 101313 : && DECL_IS_UNDECLARED_BUILTIN (expr)
9607 2408 : && !c_decl_implicit (expr)
9608 5869343833 : && !DECL_ASSEMBLER_NAME_SET_P (expr))
9609 : {
9610 220 : if (loc == UNKNOWN_LOCATION)
9611 83 : loc = EXPR_LOC_OR_LOC (expr, input_location);
9612 :
9613 : /* Reject arguments that are built-in functions with
9614 : no library fallback. */
9615 220 : error_at (loc, "built-in function %qE must be directly called", expr);
9616 :
9617 220 : return true;
9618 : }
9619 :
9620 : return false;
9621 : }
9622 :
9623 : /* Issue an ERROR for an invalid SIZE of array NAME which is null
9624 : for unnamed arrays. */
9625 :
9626 : void
9627 1416 : invalid_array_size_error (location_t loc, cst_size_error error,
9628 : const_tree size, const_tree name)
9629 : {
9630 1416 : tree maxsize = max_object_size ();
9631 1416 : switch (error)
9632 : {
9633 0 : case cst_size_not_constant:
9634 0 : if (name)
9635 0 : error_at (loc, "size of array %qE is not a constant expression",
9636 : name);
9637 : else
9638 0 : error_at (loc, "size of array is not a constant expression");
9639 : break;
9640 426 : case cst_size_negative:
9641 426 : if (name)
9642 135 : error_at (loc, "size %qE of array %qE is negative",
9643 : size, name);
9644 : else
9645 291 : error_at (loc, "size %qE of array is negative",
9646 : size);
9647 : break;
9648 930 : case cst_size_too_big:
9649 930 : if (name)
9650 103 : error_at (loc, "size %qE of array %qE exceeds maximum "
9651 : "object size %qE", size, name, maxsize);
9652 : else
9653 827 : error_at (loc, "size %qE of array exceeds maximum "
9654 : "object size %qE", size, maxsize);
9655 : break;
9656 60 : case cst_size_overflow:
9657 60 : if (name)
9658 39 : error_at (loc, "size of array %qE exceeds maximum "
9659 : "object size %qE", name, maxsize);
9660 : else
9661 21 : error_at (loc, "size of array exceeds maximum "
9662 : "object size %qE", maxsize);
9663 : break;
9664 0 : default:
9665 0 : gcc_unreachable ();
9666 : }
9667 1416 : }
9668 :
9669 : /* Check if array size calculations overflow or if the array covers more
9670 : than half of the address space. Return true if the size of the array
9671 : is valid, false otherwise. T is either the type of the array or its
9672 : size, and NAME is the name of the array, or null for unnamed arrays. */
9673 :
9674 : bool
9675 9526000 : valid_array_size_p (location_t loc, const_tree t, tree name, bool complain)
9676 : {
9677 9526000 : if (t == error_mark_node)
9678 : return true;
9679 :
9680 9525859 : const_tree size;
9681 9525859 : if (TYPE_P (t))
9682 : {
9683 7074657 : if (!COMPLETE_TYPE_P (t))
9684 : return true;
9685 3046706 : size = TYPE_SIZE_UNIT (t);
9686 : }
9687 : else
9688 : size = t;
9689 :
9690 5497908 : if (TREE_CODE (size) != INTEGER_CST)
9691 : return true;
9692 :
9693 5473337 : cst_size_error error;
9694 5473337 : if (valid_constant_size_p (size, &error))
9695 : return true;
9696 :
9697 1107 : if (!complain)
9698 : return false;
9699 :
9700 1092 : if (TREE_CODE (TREE_TYPE (size)) == ENUMERAL_TYPE)
9701 : /* Show the value of the enumerator rather than its name. */
9702 16 : size = convert (ssizetype, const_cast<tree> (size));
9703 :
9704 1092 : invalid_array_size_error (loc, error, size, name);
9705 1092 : return false;
9706 : }
9707 :
9708 : /* Read SOURCE_DATE_EPOCH from environment to have a deterministic
9709 : timestamp to replace embedded current dates to get reproducible
9710 : results. Returns -1 if SOURCE_DATE_EPOCH is not defined. */
9711 :
9712 : time_t
9713 2761 : cb_get_source_date_epoch (cpp_reader *pfile ATTRIBUTE_UNUSED)
9714 : {
9715 2761 : char *source_date_epoch;
9716 2761 : int64_t epoch;
9717 2761 : char *endptr;
9718 :
9719 2761 : source_date_epoch = getenv ("SOURCE_DATE_EPOCH");
9720 2761 : if (!source_date_epoch)
9721 : return (time_t) -1;
9722 :
9723 3 : errno = 0;
9724 : #if defined(INT64_T_IS_LONG)
9725 3 : epoch = strtol (source_date_epoch, &endptr, 10);
9726 : #else
9727 : epoch = strtoll (source_date_epoch, &endptr, 10);
9728 : #endif
9729 3 : if (errno != 0 || endptr == source_date_epoch || *endptr != '\0'
9730 2 : || epoch < 0 || epoch > MAX_SOURCE_DATE_EPOCH)
9731 : {
9732 1 : error_at (input_location, "environment variable %qs must "
9733 : "expand to a non-negative integer less than or equal to %wd",
9734 : "SOURCE_DATE_EPOCH", MAX_SOURCE_DATE_EPOCH);
9735 1 : return (time_t) -1;
9736 : }
9737 :
9738 : return (time_t) epoch;
9739 : }
9740 :
9741 : /* Callback for libcpp for offering spelling suggestions for misspelled
9742 : directives. GOAL is an unrecognized string; CANDIDATES is a
9743 : NULL-terminated array of candidate strings. Return the closest
9744 : match to GOAL within CANDIDATES, or NULL if none are good
9745 : suggestions. */
9746 :
9747 : const char *
9748 19 : cb_get_suggestion (cpp_reader *, const char *goal,
9749 : const char *const *candidates)
9750 : {
9751 19 : best_match<const char *, const char *> bm (goal);
9752 204 : while (*candidates)
9753 166 : bm.consider (*candidates++);
9754 19 : return bm.get_best_meaningful_candidate ();
9755 : }
9756 :
9757 : /* Return the latice point which is the wider of the two FLT_EVAL_METHOD
9758 : modes X, Y. This isn't just >, as the FLT_EVAL_METHOD values added
9759 : by C TS 18661-3 for interchange types that are computed in their
9760 : native precision are larger than the C11 values for evaluating in the
9761 : precision of float/double/long double. If either mode is
9762 : FLT_EVAL_METHOD_UNPREDICTABLE, return that. */
9763 :
9764 : enum flt_eval_method
9765 534985 : excess_precision_mode_join (enum flt_eval_method x,
9766 : enum flt_eval_method y)
9767 : {
9768 534985 : if (x == FLT_EVAL_METHOD_UNPREDICTABLE
9769 534985 : || y == FLT_EVAL_METHOD_UNPREDICTABLE)
9770 : return FLT_EVAL_METHOD_UNPREDICTABLE;
9771 :
9772 : /* GCC only supports one interchange type right now, _Float16. If
9773 : we're evaluating _Float16 in 16-bit precision, then flt_eval_method
9774 : will be FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16. */
9775 534659 : if (x == FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16)
9776 : return y;
9777 532484 : if (y == FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16)
9778 : return x;
9779 :
9780 : /* Other values for flt_eval_method are directly comparable, and we want
9781 : the maximum. */
9782 532472 : return MAX (x, y);
9783 : }
9784 :
9785 : /* Return the value that should be set for FLT_EVAL_METHOD in the
9786 : context of ISO/IEC TS 18861-3.
9787 :
9788 : This relates to the effective excess precision seen by the user,
9789 : which is the join point of the precision the target requests for
9790 : -fexcess-precision={standard,fast,16} and the implicit excess precision
9791 : the target uses. */
9792 :
9793 : static enum flt_eval_method
9794 418126 : c_ts18661_flt_eval_method (void)
9795 : {
9796 418126 : enum flt_eval_method implicit
9797 418126 : = targetm.c.excess_precision (EXCESS_PRECISION_TYPE_IMPLICIT);
9798 :
9799 301148 : enum excess_precision_type flag_type
9800 418126 : = (flag_excess_precision == EXCESS_PRECISION_STANDARD
9801 418126 : ? EXCESS_PRECISION_TYPE_STANDARD
9802 : : (flag_excess_precision == EXCESS_PRECISION_FLOAT16
9803 301160 : ? EXCESS_PRECISION_TYPE_FLOAT16
9804 : : EXCESS_PRECISION_TYPE_FAST));
9805 :
9806 418126 : enum flt_eval_method requested
9807 418126 : = targetm.c.excess_precision (flag_type);
9808 :
9809 418126 : return excess_precision_mode_join (implicit, requested);
9810 : }
9811 :
9812 : /* As c_cpp_ts18661_flt_eval_method, but clamps the expected values to
9813 : those that were permitted by C11. That is to say, eliminates
9814 : FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16. */
9815 :
9816 : static enum flt_eval_method
9817 104431 : c_c11_flt_eval_method (void)
9818 : {
9819 104431 : return excess_precision_mode_join (c_ts18661_flt_eval_method (),
9820 104431 : FLT_EVAL_METHOD_PROMOTE_TO_FLOAT);
9821 : }
9822 :
9823 : /* Return the value that should be set for FLT_EVAL_METHOD.
9824 : MAYBE_C11_ONLY_P is TRUE if we should check
9825 : FLAG_PERMITTED_EVAL_METHODS as to whether we should limit the possible
9826 : values we can return to those from C99/C11, and FALSE otherwise.
9827 : See the comments on c_ts18661_flt_eval_method for what value we choose
9828 : to set here. */
9829 :
9830 : int
9831 418126 : c_flt_eval_method (bool maybe_c11_only_p)
9832 : {
9833 418126 : if (maybe_c11_only_p
9834 209063 : && flag_permitted_flt_eval_methods
9835 : == PERMITTED_FLT_EVAL_METHODS_C11)
9836 104431 : return c_c11_flt_eval_method ();
9837 : else
9838 313695 : return c_ts18661_flt_eval_method ();
9839 : }
9840 :
9841 : /* An enum for get_missing_token_insertion_kind for describing the best
9842 : place to insert a missing token, if there is one. */
9843 :
9844 : enum missing_token_insertion_kind
9845 : {
9846 : MTIK_IMPOSSIBLE,
9847 : MTIK_INSERT_BEFORE_NEXT,
9848 : MTIK_INSERT_AFTER_PREV
9849 : };
9850 :
9851 : /* Given a missing token of TYPE, determine if it is reasonable to
9852 : emit a fix-it hint suggesting the insertion of the token, and,
9853 : if so, where the token should be inserted relative to other tokens.
9854 :
9855 : It only makes sense to do this for values of TYPE that are symbols.
9856 :
9857 : Some symbols should go before the next token, e.g. in:
9858 : if flag)
9859 : we want to insert the missing '(' immediately before "flag",
9860 : giving:
9861 : if (flag)
9862 : rather than:
9863 : if( flag)
9864 : These use MTIK_INSERT_BEFORE_NEXT.
9865 :
9866 : Other symbols should go after the previous token, e.g. in:
9867 : if (flag
9868 : do_something ();
9869 : we want to insert the missing ')' immediately after the "flag",
9870 : giving:
9871 : if (flag)
9872 : do_something ();
9873 : rather than:
9874 : if (flag
9875 : )do_something ();
9876 : These use MTIK_INSERT_AFTER_PREV. */
9877 :
9878 : static enum missing_token_insertion_kind
9879 3310 : get_missing_token_insertion_kind (enum cpp_ttype type)
9880 : {
9881 3310 : switch (type)
9882 : {
9883 : /* Insert missing "opening" brackets immediately
9884 : before the next token. */
9885 : case CPP_OPEN_SQUARE:
9886 : case CPP_OPEN_PAREN:
9887 : return MTIK_INSERT_BEFORE_NEXT;
9888 :
9889 : /* Insert other missing symbols immediately after
9890 : the previous token. */
9891 2001 : case CPP_CLOSE_PAREN:
9892 2001 : case CPP_CLOSE_SQUARE:
9893 2001 : case CPP_SEMICOLON:
9894 2001 : case CPP_COMMA:
9895 2001 : case CPP_COLON:
9896 2001 : return MTIK_INSERT_AFTER_PREV;
9897 :
9898 : /* Other kinds of token don't get fix-it hints. */
9899 1014 : default:
9900 1014 : return MTIK_IMPOSSIBLE;
9901 : }
9902 : }
9903 :
9904 : /* Given RICHLOC, a location for a diagnostic describing a missing token
9905 : of kind TOKEN_TYPE, potentially add a fix-it hint suggesting the
9906 : insertion of the token.
9907 :
9908 : The location of the attempted fix-it hint depends on TOKEN_TYPE:
9909 : it will either be:
9910 : (a) immediately after PREV_TOKEN_LOC, or
9911 :
9912 : (b) immediately before the primary location within RICHLOC (taken to
9913 : be that of the token following where the token was expected).
9914 :
9915 : If we manage to add a fix-it hint, then the location of the
9916 : fix-it hint is likely to be more useful as the primary location
9917 : of the diagnostic than that of the following token, so we swap
9918 : these locations.
9919 :
9920 : For example, given this bogus code:
9921 : 123456789012345678901234567890
9922 : 1 | int missing_semicolon (void)
9923 : 2 | {
9924 : 3 | return 42
9925 : 4 | }
9926 :
9927 : we will emit:
9928 :
9929 : "expected ';' before '}'"
9930 :
9931 : RICHLOC's primary location is at the closing brace, so before "swapping"
9932 : we would emit the error at line 4 column 1:
9933 :
9934 : 123456789012345678901234567890
9935 : 3 | return 42 |< fix-it hint emitted for this line
9936 : | ; |
9937 : 4 | } |< "expected ';' before '}'" emitted at this line
9938 : | ^ |
9939 :
9940 : It's more useful for the location of the diagnostic to be at the
9941 : fix-it hint, so we swap the locations, so the primary location
9942 : is at the fix-it hint, with the old primary location inserted
9943 : as a secondary location, giving this, with the error at line 3
9944 : column 12:
9945 :
9946 : 123456789012345678901234567890
9947 : 3 | return 42 |< "expected ';' before '}'" emitted at this line,
9948 : | ^ | with fix-it hint
9949 : 4 | ; |
9950 : | } |< secondary range emitted here
9951 : | ~ |. */
9952 :
9953 : void
9954 3310 : maybe_suggest_missing_token_insertion (rich_location *richloc,
9955 : enum cpp_ttype token_type,
9956 : location_t prev_token_loc)
9957 : {
9958 3310 : gcc_assert (richloc);
9959 :
9960 3310 : enum missing_token_insertion_kind mtik
9961 3310 : = get_missing_token_insertion_kind (token_type);
9962 :
9963 3310 : switch (mtik)
9964 : {
9965 : default:
9966 : gcc_unreachable ();
9967 : break;
9968 :
9969 : case MTIK_IMPOSSIBLE:
9970 : return;
9971 :
9972 295 : case MTIK_INSERT_BEFORE_NEXT:
9973 : /* Attempt to add the fix-it hint before the primary location
9974 : of RICHLOC. */
9975 295 : richloc->add_fixit_insert_before (cpp_type2name (token_type, 0));
9976 295 : break;
9977 :
9978 2001 : case MTIK_INSERT_AFTER_PREV:
9979 : /* Attempt to add the fix-it hint after PREV_TOKEN_LOC. */
9980 2001 : richloc->add_fixit_insert_after (prev_token_loc,
9981 : cpp_type2name (token_type, 0));
9982 2001 : break;
9983 : }
9984 :
9985 : /* If we were successful, use the fix-it hint's location as the
9986 : primary location within RICHLOC, adding the old primary location
9987 : back as a secondary location. */
9988 2296 : if (!richloc->seen_impossible_fixit_p ())
9989 : {
9990 2292 : fixit_hint *hint = richloc->get_last_fixit_hint ();
9991 2292 : location_t hint_loc = hint->get_start_loc ();
9992 2292 : location_t old_loc = richloc->get_loc ();
9993 :
9994 2292 : richloc->set_range (0, hint_loc, SHOW_RANGE_WITH_CARET);
9995 2292 : richloc->add_range (old_loc);
9996 : }
9997 : }
9998 :
9999 : /* Potentially emit a note about likely missing '&' or '*',
10000 : depending on EXPR and EXPECTED_TYPE. */
10001 :
10002 : void
10003 2136 : maybe_emit_indirection_note (location_t loc,
10004 : tree expr, tree expected_type)
10005 : {
10006 2136 : gcc_assert (expr);
10007 2136 : gcc_assert (expected_type);
10008 :
10009 2136 : tree actual_type = TREE_TYPE (expr);
10010 :
10011 : /* Missing '&'. */
10012 2136 : if (TREE_CODE (expected_type) == POINTER_TYPE
10013 1218 : && compatible_types_for_indirection_note_p (actual_type,
10014 1218 : TREE_TYPE (expected_type))
10015 2217 : && lvalue_p (expr))
10016 : {
10017 43 : gcc_rich_location richloc (loc);
10018 43 : richloc.add_fixit_insert_before ("&");
10019 43 : inform (&richloc, "possible fix: take the address with %qs", "&");
10020 43 : }
10021 :
10022 : /* Missing '*'. */
10023 2136 : if (TREE_CODE (actual_type) == POINTER_TYPE
10024 2136 : && compatible_types_for_indirection_note_p (TREE_TYPE (actual_type),
10025 : expected_type))
10026 : {
10027 78 : gcc_rich_location richloc (loc);
10028 78 : richloc.add_fixit_insert_before ("*");
10029 78 : inform (&richloc, "possible fix: dereference with %qs", "*");
10030 78 : }
10031 2136 : }
10032 :
10033 : #if CHECKING_P
10034 :
10035 : namespace selftest {
10036 :
10037 : /* Verify that fold_for_warn on error_mark_node is safe. */
10038 :
10039 : static void
10040 3 : test_fold_for_warn ()
10041 : {
10042 3 : ASSERT_EQ (error_mark_node, fold_for_warn (error_mark_node));
10043 3 : }
10044 :
10045 : /* Run all of the selftests within this file. */
10046 :
10047 : static void
10048 3 : c_common_cc_tests ()
10049 : {
10050 0 : test_fold_for_warn ();
10051 0 : }
10052 :
10053 : /* Run all of the tests within c-family. */
10054 :
10055 : void
10056 3 : c_family_tests (void)
10057 : {
10058 3 : c_common_cc_tests ();
10059 3 : c_format_cc_tests ();
10060 3 : c_indentation_cc_tests ();
10061 3 : c_pretty_print_cc_tests ();
10062 3 : c_spellcheck_cc_tests ();
10063 3 : c_opt_problem_cc_tests ();
10064 :
10065 : /* According to https://gcc.gnu.org/pipermail/gcc/2021-November/237703.html
10066 : this has some language-specific assumptions, so we run it here. */
10067 3 : diagnostics::selftest::context_cc_tests ();
10068 3 : }
10069 :
10070 : } // namespace selftest
10071 :
10072 : #endif /* #if CHECKING_P */
10073 :
10074 : /* Attempt to locate a suitable location within FILE for a
10075 : #include directive to be inserted before.
10076 : LOC is the location of the relevant diagnostic.
10077 :
10078 : Attempt to return the location within FILE immediately
10079 : after the last #include within that file, or the start of
10080 : that file if it has no #include directives.
10081 :
10082 : Return UNKNOWN_LOCATION if no suitable location is found,
10083 : or if an error occurs. */
10084 :
10085 : static location_t
10086 431 : try_to_locate_new_include_insertion_point (const char *file, location_t loc)
10087 : {
10088 : /* Locate the last ordinary map within FILE that ended with a #include. */
10089 431 : const line_map_ordinary *last_include_ord_map = NULL;
10090 :
10091 : /* ...and the next ordinary map within FILE after that one. */
10092 431 : const line_map_ordinary *last_ord_map_after_include = NULL;
10093 :
10094 : /* ...and the first ordinary map within FILE. */
10095 431 : const line_map_ordinary *first_ord_map_in_file = NULL;
10096 :
10097 : /* Get ordinary map containing LOC (or its expansion). */
10098 431 : const line_map_ordinary *ord_map_for_loc = NULL;
10099 431 : linemap_resolve_location (line_table, loc, LRK_MACRO_EXPANSION_POINT,
10100 : &ord_map_for_loc);
10101 431 : gcc_assert (ord_map_for_loc);
10102 :
10103 12592 : for (unsigned int i = 0; i < LINEMAPS_ORDINARY_USED (line_table); i++)
10104 : {
10105 12592 : const line_map_ordinary *ord_map
10106 12592 : = LINEMAPS_ORDINARY_MAP_AT (line_table, i);
10107 :
10108 25184 : if (const line_map_ordinary *from
10109 12592 : = linemap_included_from_linemap (line_table, ord_map))
10110 : /* We cannot use pointer equality, because with preprocessed
10111 : input all filename strings are unique. */
10112 10197 : if (0 == strcmp (from->to_file, file))
10113 : {
10114 12592 : last_include_ord_map = from;
10115 12592 : last_ord_map_after_include = NULL;
10116 : }
10117 :
10118 : /* Likewise, use strcmp, and reject any line-zero introductory
10119 : map. */
10120 12592 : if (ord_map->to_line && 0 == strcmp (ord_map->to_file, file))
10121 : {
10122 673 : if (!first_ord_map_in_file)
10123 431 : first_ord_map_in_file = ord_map;
10124 673 : if (last_include_ord_map && !last_ord_map_after_include)
10125 166 : last_ord_map_after_include = ord_map;
10126 : }
10127 :
10128 : /* Stop searching when reaching the ord_map containing LOC,
10129 : as it makes no sense to provide fix-it hints that appear
10130 : after the diagnostic in question. */
10131 12592 : if (ord_map == ord_map_for_loc)
10132 : break;
10133 : }
10134 :
10135 : /* Determine where to insert the #include. */
10136 431 : const line_map_ordinary *ord_map_for_insertion;
10137 :
10138 : /* We want the next ordmap in the file after the last one that's a
10139 : #include, but failing that, the start of the file. */
10140 431 : if (last_ord_map_after_include)
10141 : ord_map_for_insertion = last_ord_map_after_include;
10142 : else
10143 267 : ord_map_for_insertion = first_ord_map_in_file;
10144 :
10145 267 : if (!ord_map_for_insertion)
10146 : return UNKNOWN_LOCATION;
10147 :
10148 : /* The "start_location" is column 0, meaning "the whole line".
10149 : rich_location and diagnostics::changes can't cope with this, so use
10150 : column 1 instead. */
10151 431 : location_t col_0 = ord_map_for_insertion->start_location;
10152 431 : return linemap_position_for_loc_and_offset (line_table, col_0, 1);
10153 : }
10154 :
10155 : /* A map from filenames to sets of headers added to them, for
10156 : ensuring idempotency within maybe_add_include_fixit. */
10157 :
10158 : /* The values within the map. We need string comparison as there's
10159 : no guarantee that two different diagnostics that are recommending
10160 : adding e.g. "<stdio.h>" are using the same buffer. */
10161 :
10162 : typedef hash_set <const char *, false, nofree_string_hash> per_file_includes_t;
10163 :
10164 : /* The map itself. We don't need string comparison for the filename keys,
10165 : as they come from libcpp. */
10166 :
10167 : typedef hash_map <const char *, per_file_includes_t *> added_includes_t;
10168 : static added_includes_t *added_includes;
10169 :
10170 : /* Attempt to add a fix-it hint to RICHLOC, adding "#include HEADER\n"
10171 : in a suitable location within the file of RICHLOC's primary
10172 : location.
10173 :
10174 : This function is idempotent: a header will be added at most once to
10175 : any given file.
10176 :
10177 : If OVERRIDE_LOCATION is true, then if a fix-it is added and will be
10178 : printed, then RICHLOC's primary location will be replaced by that of
10179 : the fix-it hint (for use by "inform" notes where the location of the
10180 : issue has already been reported). */
10181 :
10182 : void
10183 883 : maybe_add_include_fixit (rich_location *richloc, const char *header,
10184 : bool override_location)
10185 : {
10186 883 : location_t loc = richloc->get_loc ();
10187 883 : const char *file = LOCATION_FILE (loc);
10188 883 : if (!file)
10189 452 : return;
10190 :
10191 : /* Idempotency: don't add the same header more than once to a given file. */
10192 883 : if (!added_includes)
10193 348 : added_includes = new added_includes_t ();
10194 883 : per_file_includes_t *&set = added_includes->get_or_insert (file);
10195 883 : if (set)
10196 535 : if (set->contains (header))
10197 : /* ...then we've already added HEADER to that file. */
10198 : return;
10199 431 : if (!set)
10200 348 : set = new per_file_includes_t ();
10201 431 : set->add (header);
10202 :
10203 : /* Attempt to locate a suitable place for the new directive. */
10204 431 : location_t include_insert_loc
10205 431 : = try_to_locate_new_include_insertion_point (file, loc);
10206 431 : if (include_insert_loc == UNKNOWN_LOCATION)
10207 : return;
10208 :
10209 431 : char *text = xasprintf ("#include %s\n", header);
10210 431 : richloc->add_fixit_insert_before (include_insert_loc, text);
10211 431 : free (text);
10212 :
10213 431 : if (override_location && global_dc->get_source_printing_options ().enabled)
10214 : {
10215 : /* Replace the primary location with that of the insertion point for the
10216 : fix-it hint.
10217 :
10218 : We use SHOW_LINES_WITHOUT_RANGE so that we don't meaningless print a
10219 : caret for the insertion point (or colorize it).
10220 :
10221 : Hence we print e.g.:
10222 :
10223 : ../x86_64-pc-linux-gnu/libstdc++-v3/include/vector:74:1: note: msg 2
10224 : 73 | # include <debug/vector>
10225 : +++ |+#include <vector>
10226 : 74 | #endif
10227 :
10228 : rather than:
10229 :
10230 : ../x86_64-pc-linux-gnu/libstdc++-v3/include/vector:74:1: note: msg 2
10231 : 73 | # include <debug/vector>
10232 : +++ |+#include <vector>
10233 : 74 | #endif
10234 : | ^
10235 :
10236 : avoiding the caret on the first column of line 74. */
10237 177 : richloc->set_range (0, include_insert_loc, SHOW_LINES_WITHOUT_RANGE);
10238 : }
10239 : }
10240 :
10241 : /* Attempt to convert a braced array initializer list CTOR for array
10242 : TYPE into a STRING_CST for convenience and efficiency. Return
10243 : the converted string on success or the original ctor on failure.
10244 : Also, for non-convertable CTORs which contain RAW_DATA_CST values
10245 : among the elts try to extend the range of RAW_DATA_CSTs. */
10246 :
10247 : static tree
10248 56896 : braced_list_to_string (tree type, tree ctor, bool member)
10249 : {
10250 : /* Ignore non-members with unknown size like arrays with unspecified
10251 : bound. */
10252 56896 : tree typesize = TYPE_SIZE_UNIT (type);
10253 56896 : if (!member && !tree_fits_uhwi_p (typesize))
10254 : return ctor;
10255 :
10256 : /* If the target char size differs from the host char size, we'd risk
10257 : loosing data and getting object sizes wrong by converting to
10258 : host chars. */
10259 56871 : if (TYPE_PRECISION (char_type_node) != CHAR_BIT)
10260 : return ctor;
10261 :
10262 : /* STRING_CST doesn't support wide characters. */
10263 56871 : gcc_checking_assert (TYPE_PRECISION (TREE_TYPE (type)) == CHAR_BIT);
10264 :
10265 : /* If the array has an explicit bound, use it to constrain the size
10266 : of the string. If it doesn't, be sure to create a string that's
10267 : as long as implied by the index of the last zero specified via
10268 : a designator, as in:
10269 : const char a[] = { [7] = 0 }; */
10270 56871 : unsigned HOST_WIDE_INT maxelts;
10271 56871 : if (typesize)
10272 : {
10273 56792 : maxelts = tree_to_uhwi (typesize);
10274 56792 : maxelts /= tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (type)));
10275 : }
10276 : else
10277 : maxelts = HOST_WIDE_INT_M1U;
10278 :
10279 : /* Avoid converting initializers for zero-length arrays (but do
10280 : create them for flexible array members). */
10281 56792 : if (!maxelts)
10282 : return ctor;
10283 :
10284 56721 : unsigned HOST_WIDE_INT nelts = CONSTRUCTOR_NELTS (ctor);
10285 :
10286 56721 : auto_vec<char> str;
10287 56721 : str.reserve (nelts + 1);
10288 :
10289 56721 : unsigned HOST_WIDE_INT i, j = HOST_WIDE_INT_M1U;
10290 56721 : tree index, value;
10291 56721 : bool check_raw_data = false;
10292 :
10293 635126 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), i, index, value)
10294 : {
10295 578405 : if (check_raw_data)
10296 : {
10297 : /* The preprocessor always surrounds CPP_EMBED tokens in between
10298 : CPP_NUMBER and CPP_COMMA tokens. Try to undo that here now that
10299 : the whole initializer is parsed. E.g. if we have
10300 : [0] = 'T', [1] = "his is a #embed tex", [20] = 't'
10301 : where the middle value is RAW_DATA_CST and in its owner this is
10302 : surrounded by 'T' and 't' characters, we can create from it just
10303 : [0] = "This is a #embed text"
10304 : Similarly if a RAW_DATA_CST needs to be split into two parts
10305 : because of designated init store but the stored value is actually
10306 : the same as in the RAW_DATA_OWNER's memory we can merge multiple
10307 : RAW_DATA_CSTs. */
10308 1205 : if (TREE_CODE (value) == RAW_DATA_CST
10309 560 : && index
10310 560 : && tree_fits_uhwi_p (index))
10311 : {
10312 560 : tree owner = RAW_DATA_OWNER (value);
10313 560 : unsigned int start, end, k;
10314 560 : if (TREE_CODE (owner) == STRING_CST)
10315 : {
10316 218 : start
10317 218 : = RAW_DATA_POINTER (value) - TREE_STRING_POINTER (owner);
10318 218 : end = TREE_STRING_LENGTH (owner) - RAW_DATA_LENGTH (value);
10319 : }
10320 : else
10321 : {
10322 342 : gcc_checking_assert (TREE_CODE (owner) == RAW_DATA_CST);
10323 342 : start
10324 342 : = RAW_DATA_POINTER (value) - RAW_DATA_POINTER (owner);
10325 342 : end = RAW_DATA_LENGTH (owner) - RAW_DATA_LENGTH (value);
10326 : }
10327 560 : end -= start;
10328 560 : unsigned HOST_WIDE_INT l = j == HOST_WIDE_INT_M1U ? i : j;
10329 1005 : for (k = 0; k < start && k < l; ++k)
10330 : {
10331 471 : constructor_elt *elt = CONSTRUCTOR_ELT (ctor, l - k - 1);
10332 942 : if (elt->index == NULL_TREE
10333 471 : || !tree_fits_uhwi_p (elt->index)
10334 471 : || !tree_fits_shwi_p (elt->value)
10335 1408 : || wi::to_widest (index) != (wi::to_widest (elt->index)
10336 1403 : + (k + 1)))
10337 : break;
10338 466 : if (TYPE_UNSIGNED (TREE_TYPE (value)))
10339 : {
10340 389 : if (tree_to_shwi (elt->value)
10341 389 : != *((const unsigned char *)
10342 389 : RAW_DATA_POINTER (value) - k - 1))
10343 : break;
10344 : }
10345 77 : else if (tree_to_shwi (elt->value)
10346 77 : != *((const signed char *)
10347 77 : RAW_DATA_POINTER (value) - k - 1))
10348 : break;
10349 : }
10350 560 : start = k;
10351 560 : l = 0;
10352 1463 : for (k = 0; k < end && k + 1 < CONSTRUCTOR_NELTS (ctor) - i; ++k)
10353 : {
10354 458 : constructor_elt *elt = CONSTRUCTOR_ELT (ctor, i + k + 1);
10355 916 : if (elt->index == NULL_TREE
10356 458 : || !tree_fits_uhwi_p (elt->index)
10357 1374 : || (wi::to_widest (elt->index)
10358 916 : != (wi::to_widest (index)
10359 1374 : + (RAW_DATA_LENGTH (value) + l))))
10360 : break;
10361 458 : if (TREE_CODE (elt->value) == RAW_DATA_CST
10362 2 : && RAW_DATA_OWNER (elt->value) == RAW_DATA_OWNER (value)
10363 458 : && (RAW_DATA_POINTER (elt->value)
10364 2 : == RAW_DATA_POINTER (value) + l))
10365 : {
10366 0 : l += RAW_DATA_LENGTH (elt->value);
10367 0 : end -= RAW_DATA_LENGTH (elt->value) - 1;
10368 0 : continue;
10369 : }
10370 458 : if (!tree_fits_shwi_p (elt->value))
10371 : break;
10372 455 : if (TYPE_UNSIGNED (TREE_TYPE (value)))
10373 : {
10374 400 : if (tree_to_shwi (elt->value)
10375 400 : != *((const unsigned char *)
10376 400 : RAW_DATA_POINTER (value)
10377 400 : + RAW_DATA_LENGTH (value) + k))
10378 : break;
10379 : }
10380 55 : else if (tree_to_shwi (elt->value)
10381 55 : != *((const signed char *)
10382 55 : RAW_DATA_POINTER (value)
10383 55 : + RAW_DATA_LENGTH (value) + k))
10384 : break;
10385 420 : ++l;
10386 : }
10387 560 : end = k;
10388 560 : if (start != 0 || end != 0)
10389 : {
10390 467 : if (j == HOST_WIDE_INT_M1U)
10391 429 : j = i - start;
10392 : else
10393 38 : j -= start;
10394 467 : value = copy_node (value);
10395 467 : RAW_DATA_POINTER (value) -= start;
10396 467 : RAW_DATA_LENGTH (value) += start + end;
10397 467 : i += end;
10398 467 : if (start == 0)
10399 22 : CONSTRUCTOR_ELT (ctor, j)->index = index;
10400 467 : CONSTRUCTOR_ELT (ctor, j)->value = value;
10401 467 : ++j;
10402 467 : continue;
10403 : }
10404 : }
10405 738 : if (j != HOST_WIDE_INT_M1U)
10406 : {
10407 176 : CONSTRUCTOR_ELT (ctor, j)->index = index;
10408 176 : CONSTRUCTOR_ELT (ctor, j)->value = value;
10409 176 : ++j;
10410 : }
10411 738 : continue;
10412 738 : }
10413 :
10414 577200 : unsigned HOST_WIDE_INT idx = i;
10415 577200 : if (index)
10416 : {
10417 577200 : if (!tree_fits_uhwi_p (index))
10418 : {
10419 23 : check_raw_data = true;
10420 23 : continue;
10421 : }
10422 577177 : idx = tree_to_uhwi (index);
10423 : }
10424 :
10425 : /* auto_vec is limited to UINT_MAX elements. */
10426 577177 : if (idx > UINT_MAX)
10427 : {
10428 0 : check_raw_data = true;
10429 0 : continue;
10430 : }
10431 :
10432 : /* Avoid non-constant initializers. */
10433 577177 : if (!tree_fits_shwi_p (value))
10434 : {
10435 666 : check_raw_data = true;
10436 666 : --i;
10437 666 : continue;
10438 : }
10439 :
10440 : /* Skip over embedded nuls except the last one (initializer
10441 : elements are in ascending order of indices). */
10442 576511 : HOST_WIDE_INT val = tree_to_shwi (value);
10443 576511 : if (!val && i + 1 < nelts)
10444 5964 : continue;
10445 :
10446 570547 : if (idx < str.length ())
10447 : {
10448 0 : check_raw_data = true;
10449 0 : continue;
10450 : }
10451 :
10452 : /* Bail if the CTOR has a block of more than 256 embedded nuls
10453 : due to implicitly initialized elements. */
10454 570547 : unsigned nchars = (idx - str.length ()) + 1;
10455 570547 : if (nchars > 256)
10456 : {
10457 3 : check_raw_data = true;
10458 3 : continue;
10459 : }
10460 :
10461 570544 : if (nchars > 1)
10462 : {
10463 3658 : str.reserve (idx);
10464 3658 : str.quick_grow_cleared (idx);
10465 : }
10466 :
10467 570544 : if (idx >= maxelts)
10468 : {
10469 0 : check_raw_data = true;
10470 0 : continue;
10471 : }
10472 :
10473 570544 : str.safe_insert (idx, val);
10474 : }
10475 :
10476 56721 : if (check_raw_data)
10477 : {
10478 692 : if (j != HOST_WIDE_INT_M1U)
10479 429 : CONSTRUCTOR_ELTS (ctor)->truncate (j);
10480 692 : return ctor;
10481 : }
10482 :
10483 : /* Append a nul string termination. */
10484 111981 : if (maxelts != HOST_WIDE_INT_M1U && str.length () < maxelts)
10485 29727 : str.safe_push (0);
10486 :
10487 : /* Build a STRING_CST with the same type as the array. */
10488 168087 : tree res = build_string (str.length (), str.begin ());
10489 56029 : TREE_TYPE (res) = type;
10490 56029 : return res;
10491 56721 : }
10492 :
10493 : /* Implementation of the two-argument braced_lists_to_string withe
10494 : the same arguments plus MEMBER which is set for struct members
10495 : to allow initializers for flexible member arrays. */
10496 :
10497 : static tree
10498 189095287 : braced_lists_to_strings (tree type, tree ctor, bool member)
10499 : {
10500 189095287 : if (TREE_CODE (ctor) != CONSTRUCTOR)
10501 : return ctor;
10502 :
10503 5604907 : tree_code code = TREE_CODE (type);
10504 :
10505 5604907 : tree ttp;
10506 5604907 : if (code == ARRAY_TYPE)
10507 268715 : ttp = TREE_TYPE (type);
10508 5336192 : else if (code == RECORD_TYPE)
10509 : {
10510 5289896 : ttp = TREE_TYPE (ctor);
10511 5289896 : if (TREE_CODE (ttp) == ARRAY_TYPE)
10512 : {
10513 245748 : type = ttp;
10514 245748 : ttp = TREE_TYPE (ttp);
10515 : }
10516 : }
10517 : else
10518 : return ctor;
10519 :
10520 5556424 : if ((TREE_CODE (ttp) == ARRAY_TYPE || TREE_CODE (ttp) == INTEGER_TYPE)
10521 5911135 : && TYPE_STRING_FLAG (ttp))
10522 56896 : return braced_list_to_string (type, ctor, member);
10523 :
10524 5501715 : code = TREE_CODE (ttp);
10525 5501715 : if (code == ARRAY_TYPE || RECORD_OR_UNION_TYPE_P (ttp))
10526 : {
10527 5109806 : bool rec = RECORD_OR_UNION_TYPE_P (ttp);
10528 :
10529 : /* Handle array of arrays or struct member initializers. */
10530 5109806 : tree val;
10531 5109806 : unsigned HOST_WIDE_INT idx;
10532 13072495 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), idx, val)
10533 : {
10534 7962689 : val = braced_lists_to_strings (ttp, val, rec);
10535 7962689 : CONSTRUCTOR_ELT (ctor, idx)->value = val;
10536 : }
10537 : }
10538 :
10539 : return ctor;
10540 : }
10541 :
10542 : /* Attempt to convert a CTOR containing braced array initializer lists
10543 : for array TYPE into one containing STRING_CSTs, for convenience and
10544 : efficiency. Recurse for arrays of arrays and member initializers.
10545 : Return the converted CTOR or STRING_CST on success or the original
10546 : CTOR otherwise. */
10547 :
10548 : tree
10549 181132598 : braced_lists_to_strings (tree type, tree ctor)
10550 : {
10551 181132598 : return braced_lists_to_strings (type, ctor, false);
10552 : }
10553 :
10554 :
10555 : /* Emit debug for functions before finalizing early debug. */
10556 :
10557 : void
10558 179220 : c_common_finalize_early_debug (void)
10559 : {
10560 : /* Emit early debug for reachable functions, and by consequence,
10561 : locally scoped symbols. Also emit debug for extern declared
10562 : functions that are still reachable at this point. */
10563 179220 : struct cgraph_node *cnode;
10564 4129867 : FOR_EACH_FUNCTION (cnode)
10565 3613165 : if (!cnode->alias && !cnode->thunk
10566 7560784 : && (cnode->has_gimple_body_p ()
10567 1273208 : || !DECL_IS_UNDECLARED_BUILTIN (cnode->decl)))
10568 3393611 : (*debug_hooks->early_global_decl) (cnode->decl);
10569 179220 : }
10570 :
10571 : /* Determine whether TYPE is an ISO C99 flexible array member type "[]". */
10572 : bool
10573 10533801 : c_flexible_array_member_type_p (const_tree type)
10574 : {
10575 10533801 : if (TREE_CODE (type) == ARRAY_TYPE
10576 3607505 : && TYPE_SIZE (type) == NULL_TREE
10577 470424 : && TYPE_DOMAIN (type) != NULL_TREE
10578 11004225 : && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE)
10579 470424 : return true;
10580 :
10581 : return false;
10582 : }
10583 :
10584 : /* Get the LEVEL of the strict_flex_array for the ARRAY_FIELD based on the
10585 : values of attribute strict_flex_array and the flag_strict_flex_arrays. */
10586 : unsigned int
10587 534785 : c_strict_flex_array_level_of (tree array_field)
10588 : {
10589 534785 : gcc_assert (TREE_CODE (array_field) == FIELD_DECL);
10590 534785 : unsigned int strict_flex_array_level = flag_strict_flex_arrays;
10591 :
10592 534785 : tree attr_strict_flex_array
10593 534785 : = lookup_attribute ("strict_flex_array", DECL_ATTRIBUTES (array_field));
10594 : /* If there is a strict_flex_array attribute attached to the field,
10595 : override the flag_strict_flex_arrays. */
10596 534785 : if (attr_strict_flex_array)
10597 : {
10598 : /* Get the value of the level first from the attribute. */
10599 6 : unsigned HOST_WIDE_INT attr_strict_flex_array_level = 0;
10600 6 : gcc_assert (TREE_VALUE (attr_strict_flex_array) != NULL_TREE);
10601 6 : attr_strict_flex_array = TREE_VALUE (attr_strict_flex_array);
10602 6 : gcc_assert (TREE_VALUE (attr_strict_flex_array) != NULL_TREE);
10603 6 : attr_strict_flex_array = TREE_VALUE (attr_strict_flex_array);
10604 6 : gcc_assert (tree_fits_uhwi_p (attr_strict_flex_array));
10605 6 : attr_strict_flex_array_level = tree_to_uhwi (attr_strict_flex_array);
10606 :
10607 : /* The attribute has higher priority than flag_struct_flex_array. */
10608 6 : strict_flex_array_level = attr_strict_flex_array_level;
10609 : }
10610 534785 : return strict_flex_array_level;
10611 : }
10612 :
10613 : /* Map from identifiers to booleans. Value is true for features, and
10614 : false for extensions. Used to implement __has_{feature,extension}. */
10615 :
10616 : using feature_map_t = hash_map <tree, bool>;
10617 : static feature_map_t *feature_map;
10618 :
10619 : /* Register a feature for __has_{feature,extension}. FEATURE_P is true
10620 : if the feature identified by NAME is a feature (as opposed to an
10621 : extension). */
10622 :
10623 : void
10624 1420214 : c_common_register_feature (const char *name, bool feature_p)
10625 : {
10626 1420214 : bool dup = feature_map->put (get_identifier (name), feature_p);
10627 1420214 : gcc_checking_assert (!dup);
10628 1420214 : }
10629 :
10630 : /* Lazily initialize hash table for __has_{feature,extension},
10631 : dispatching to the appropriate front end to register language-specific
10632 : features. */
10633 :
10634 : static void
10635 46591 : init_has_feature ()
10636 : {
10637 46591 : gcc_checking_assert (!feature_map);
10638 46591 : feature_map = new feature_map_t;
10639 :
10640 559092 : for (unsigned i = 0; i < ARRAY_SIZE (has_feature_table); i++)
10641 : {
10642 512501 : const hf_feature_info *info = has_feature_table + i;
10643 :
10644 512501 : if ((info->flags & HF_FLAG_SANITIZE) && !(flag_sanitize & info->mask))
10645 232031 : continue;
10646 :
10647 280470 : const bool feature_p = !(info->flags & HF_FLAG_EXT);
10648 280470 : c_common_register_feature (info->ident, feature_p);
10649 : }
10650 :
10651 : /* Register language-specific features. */
10652 46591 : c_family_register_lang_features ();
10653 46591 : }
10654 :
10655 : /* If STRICT_P is true, evaluate __has_feature (IDENT).
10656 : Otherwise, evaluate __has_extension (IDENT). */
10657 :
10658 : bool
10659 126121 : has_feature_p (const char *ident, bool strict_p)
10660 : {
10661 126121 : if (!feature_map)
10662 46591 : init_has_feature ();
10663 :
10664 126121 : tree name = canonicalize_attr_name (get_identifier (ident));
10665 126121 : bool *feat_p = feature_map->get (name);
10666 126121 : if (!feat_p)
10667 : return false;
10668 :
10669 72420 : return !strict_p || *feat_p;
10670 : }
10671 :
10672 : /* This is the slow path of c-common.h's c_hardbool_type_attr. */
10673 :
10674 : tree
10675 69559 : c_hardbool_type_attr_1 (tree type, tree *false_value, tree *true_value)
10676 : {
10677 69559 : tree attr = lookup_attribute ("hardbool", TYPE_ATTRIBUTES (type));
10678 69559 : if (!attr)
10679 : return attr;
10680 :
10681 35391 : if (false_value)
10682 18461 : *false_value = TREE_VALUE (TYPE_VALUES (type));
10683 :
10684 35391 : if (true_value)
10685 18825 : *true_value = TREE_VALUE (TREE_CHAIN (TYPE_VALUES (type)));
10686 :
10687 : return attr;
10688 : }
10689 :
10690 : #include "gt-c-family-c-common.h"
|