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