1 /* Subroutines shared by all languages that are variants of C.
2 Copyright (C) 1992-2022 Free Software Foundation, Inc.
4 This file is part of GCC.
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
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
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/>. */
20 #define GCC_C_COMMON_C
24 #include "coretypes.h"
28 #include "mem-stats-traits.h" // sdcpp
30 // sdcpp #include "gimple-expr.h"
32 #include "stringpool.h"
33 #include "diagnostic.h"
37 #include "common/common-target.h"
38 #include "langhooks.h"
40 #include "tree-iterator.h"
43 #include "substring-locations.h"
44 #include "spellcheck.h"
45 #include "c-spellcheck.h"
46 // sdcpp #include "selftest.h"
49 // #include "defaults.h" // sdcpp
51 cpp_reader
*parse_in
; /* Declared in c-pragma.h. */
54 /* Mode used to build pointers (VOIDmode means ptr_mode). */
56 machine_mode c_default_pointer_mode
= VOIDmode
;
58 /* The following symbols are subsumed in the c_global_trees array, and
59 listed here individually for documentation purposes.
61 INTEGER_TYPE and REAL_TYPE nodes for the standard data types.
63 tree short_integer_type_node;
64 tree long_integer_type_node;
65 tree long_long_integer_type_node;
67 tree short_unsigned_type_node;
68 tree long_unsigned_type_node;
69 tree long_long_unsigned_type_node;
71 tree truthvalue_type_node;
72 tree truthvalue_false_node;
73 tree truthvalue_true_node;
75 tree ptrdiff_type_node;
77 tree unsigned_char_type_node;
78 tree signed_char_type_node;
82 tree char16_type_node;
83 tree char32_type_node;
86 tree double_type_node;
87 tree long_double_type_node;
89 tree complex_integer_type_node;
90 tree complex_float_type_node;
91 tree complex_double_type_node;
92 tree complex_long_double_type_node;
94 tree dfloat32_type_node;
95 tree dfloat64_type_node;
96 tree_dfloat128_type_node;
100 tree intSI_type_node;
101 tree intDI_type_node;
102 tree intTI_type_node;
104 tree unsigned_intQI_type_node;
105 tree unsigned_intHI_type_node;
106 tree unsigned_intSI_type_node;
107 tree unsigned_intDI_type_node;
108 tree unsigned_intTI_type_node;
110 tree widest_integer_literal_type_node;
111 tree widest_unsigned_literal_type_node;
113 Nodes for types `void *' and `const void *'.
115 tree ptr_type_node, const_ptr_type_node;
117 Nodes for types `char *' and `const char *'.
119 tree string_type_node, const_string_type_node;
121 Type `char[SOMENUMBER]'.
122 Used when an array of char is needed and the size is irrelevant.
124 tree char_array_type_node;
126 Type `wchar_t[SOMENUMBER]' or something like it.
127 Used when a wide string literal is created.
129 tree wchar_array_type_node;
131 Type `char8_t[SOMENUMBER]' or something like it.
132 Used when a UTF-8 string literal is created.
134 tree char8_array_type_node;
136 Type `char16_t[SOMENUMBER]' or something like it.
137 Used when a UTF-16 string literal is created.
139 tree char16_array_type_node;
141 Type `char32_t[SOMENUMBER]' or something like it.
142 Used when a UTF-32 string literal is created.
144 tree char32_array_type_node;
146 Type `int ()' -- used for implicit declaration of functions.
148 tree default_function_type;
150 A VOID_TYPE node, packaged in a TREE_LIST.
154 The lazily created VAR_DECLs for __FUNCTION__, __PRETTY_FUNCTION__,
155 and __func__. (C doesn't generate __FUNCTION__ and__PRETTY_FUNCTION__
156 VAR_DECLS, but C++ does.)
158 tree function_name_decl_node;
159 tree pretty_function_name_decl_node;
160 tree c99_function_name_decl_node;
162 Stack of nested function name VAR_DECLs.
164 tree saved_function_name_decls;
168 tree c_global_trees
[CTI_MAX
];
170 /* Switches common to the C front ends. */
172 /* Nonzero means don't output line number information. */
174 char flag_no_line_commands
;
176 /* Nonzero causes -E output not to be done, but directives such as
177 #define that have side effects are still obeyed. */
181 /* Nonzero means dump macros in some fashion. */
183 char flag_dump_macros
;
185 /* Nonzero means pass #include lines through to the output. */
187 char flag_dump_includes
;
189 /* Nonzero means process PCH files while preprocessing. */
191 bool flag_pch_preprocess
;
193 /* The file name to which we should write a precompiled header, or
194 NULL if no header will be written in this compile. */
196 const char *pch_file
;
198 /* Nonzero if an ISO standard was selected. It rejects macros in the
202 /* C/ObjC language option variables. */
205 /* Nonzero means allow type mismatches in conditional expressions;
206 just make their values `void'. */
208 int flag_cond_mismatch
;
210 /* Nonzero means enable C89 Amendment 1 features. */
214 /* Nonzero means use the ISO C99 (or C11) dialect of C. */
218 /* Nonzero means use the ISO C11 dialect of C. */
222 /* Nonzero means use the ISO C23 dialect of C. */
227 /* Nonzero means that we have builtin functions, and main is an int. */
232 /* ObjC language option variables. */
235 /* Tells the compiler that this is a special run. Do not perform any
236 compiling, instead we are to test some platform dependent features
237 and output a C header file with appropriate definitions. */
239 int print_struct_values
;
241 /* Tells the compiler what is the constant string class for ObjC. */
243 const char *constant_string_class_name
;
246 /* C++ language option variables. */
248 /* The reference version of the ABI for -Wabi. */
250 int warn_abi_version
= -1;
252 /* The C++ dialect being used. Default set in c_common_post_options. */
254 enum cxx_dialect cxx_dialect
= cxx_unset
;
256 /* Maximum template instantiation depth. This limit exists to limit the
257 time it takes to notice excessively recursive template instantiations.
259 The default is lower than the 1024 recommended by the C++0x standard
260 because G++ runs out of stack before 1024 with highly recursive template
261 argument deduction substitution (g++.dg/cpp0x/enum11.C). */
263 int max_tinst_depth
= 900;
266 /* The elements of `ridpointers' are identifier nodes for the reserved
267 type names and storage classes. It is indexed by a RID_... value. */
270 tree (*make_fname_decl
) (location_t
, tree
, int);
273 /* Nonzero means don't warn about problems that occur when the code is
275 int c_inhibit_evaluation_warnings
;
277 /* Whether we are building a boolean conversion inside
278 convert_for_assignment, or some other late binary operation. If
279 build_binary_op is called for C (from code shared by C and C++) in
280 this case, then the operands have already been folded and the
281 result will not be folded again, so C_MAYBE_CONST_EXPR should not
283 bool in_late_binary_op
;
285 /* Whether lexing has been completed, so subsequent preprocessor
286 errors should use the compiler's input_location. */
287 bool done_lexing
= false;
290 /* Information about how a function name is generated. */
293 tree
*const decl
; /* pointer to the VAR_DECL. */
294 const unsigned rid
; /* RID number for the identifier. */
295 const int pretty
; /* How pretty is it? */
298 /* The three ways of getting then name of the current function. */
300 const struct fname_var_t fname_vars
[] =
302 /* C99 compliant __func__, must be first. */
303 {&c99_function_name_decl_node
, RID_C99_FUNCTION_NAME
, 0},
304 /* GCC __FUNCTION__ compliant. */
305 {&function_name_decl_node
, RID_FUNCTION_NAME
, 0},
306 /* GCC __PRETTY_FUNCTION__ compliant. */
307 {&pretty_function_name_decl_node
, RID_PRETTY_FUNCTION_NAME
, 1},
312 /* Global visibility options. */
313 struct visibility_flags visibility_options
;
316 static tree
check_case_value (location_t
, tree
);
319 static void check_nonnull_arg (void *, tree
, unsigned HOST_WIDE_INT
);
320 static bool nonnull_check_p (tree
, unsigned HOST_WIDE_INT
);
322 /* Reserved words. The third field is a mask: keywords are disabled
323 if they match the mask.
326 C --std=c89: D_C99 | D_CXXONLY | D_OBJC | D_CXX_OBJC
327 C --std=c99: D_CXXONLY | D_OBJC
328 ObjC is like C except that D_OBJC and D_CXX_OBJC are not set
329 C++ --std=c++98: D_CONLY | D_CXX11 | D_CXX20 | D_OBJC
330 C++ --std=c++11: D_CONLY | D_CXX20 | D_OBJC
331 C++ --std=c++20: D_CONLY | D_OBJC
332 ObjC++ is like C++ except that D_OBJC is not set
334 If -fno-asm is used, D_ASM is added to the mask. If
335 -fno-gnu-keywords is used, D_EXT is added. If -fno-asm and C in
336 C89 mode, D_EXT89 is added for both -fno-asm and -fno-gnu-keywords.
337 In C with -Wc++-compat, we warn if D_CXXWARN is set.
339 Note the complication of the D_CXX_OBJC keywords. These are
340 reserved words such as 'class'. In C++, 'class' is a reserved
341 word. In Objective-C++ it is too. In Objective-C, it is a
342 reserved word too, but only if it follows an '@' sign.
344 const struct c_common_resword c_common_reswords
[] =
346 { "_Alignas", RID_ALIGNAS
, D_CONLY
},
347 { "_Alignof", RID_ALIGNOF
, D_CONLY
},
348 { "_Atomic", RID_ATOMIC
, D_CONLY
},
349 { "_Bool", RID_BOOL
, D_CONLY
},
350 { "_Complex", RID_COMPLEX
, 0 },
351 { "_Imaginary", RID_IMAGINARY
, D_CONLY
},
352 { "_Float16", RID_FLOAT16
, D_CONLY
},
353 { "_Float32", RID_FLOAT32
, D_CONLY
},
354 { "_Float64", RID_FLOAT64
, D_CONLY
},
355 { "_Float128", RID_FLOAT128
, D_CONLY
},
356 { "_Float32x", RID_FLOAT32X
, D_CONLY
},
357 { "_Float64x", RID_FLOAT64X
, D_CONLY
},
358 { "_Float128x", RID_FLOAT128X
, D_CONLY
},
359 { "_Decimal32", RID_DFLOAT32
, D_CONLY
},
360 { "_Decimal64", RID_DFLOAT64
, D_CONLY
},
361 { "_Decimal128", RID_DFLOAT128
, D_CONLY
},
362 { "_Fract", RID_FRACT
, D_CONLY
| D_EXT
},
363 { "_Accum", RID_ACCUM
, D_CONLY
| D_EXT
},
364 { "_Sat", RID_SAT
, D_CONLY
| D_EXT
},
365 { "_Static_assert", RID_STATIC_ASSERT
, D_CONLY
},
366 { "_Noreturn", RID_NORETURN
, D_CONLY
},
367 { "_Generic", RID_GENERIC
, D_CONLY
},
368 { "_Thread_local", RID_THREAD
, D_CONLY
},
369 { "__FUNCTION__", RID_FUNCTION_NAME
, 0 },
370 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME
, 0 },
371 { "__alignof", RID_ALIGNOF
, 0 },
372 { "__alignof__", RID_ALIGNOF
, 0 },
373 { "__asm", RID_ASM
, 0 },
374 { "__asm__", RID_ASM
, 0 },
375 { "__attribute", RID_ATTRIBUTE
, 0 },
376 { "__attribute__", RID_ATTRIBUTE
, 0 },
377 { "__auto_type", RID_AUTO_TYPE
, D_CONLY
},
378 { "__bases", RID_BASES
, D_CXXONLY
},
379 { "__builtin_addressof", RID_ADDRESSOF
, D_CXXONLY
},
380 { "__builtin_bit_cast", RID_BUILTIN_BIT_CAST
, D_CXXONLY
},
381 { "__builtin_call_with_static_chain",
382 RID_BUILTIN_CALL_WITH_STATIC_CHAIN
, D_CONLY
},
383 { "__builtin_choose_expr", RID_CHOOSE_EXPR
, D_CONLY
},
384 { "__builtin_complex", RID_BUILTIN_COMPLEX
, D_CONLY
},
385 { "__builtin_convertvector", RID_BUILTIN_CONVERTVECTOR
, 0 },
386 { "__builtin_has_attribute", RID_BUILTIN_HAS_ATTRIBUTE
, 0 },
387 { "__builtin_launder", RID_BUILTIN_LAUNDER
, D_CXXONLY
},
388 { "__builtin_assoc_barrier", RID_BUILTIN_ASSOC_BARRIER
, 0 },
389 { "__builtin_shuffle", RID_BUILTIN_SHUFFLE
, 0 },
390 { "__builtin_shufflevector", RID_BUILTIN_SHUFFLEVECTOR
, 0 },
391 { "__builtin_tgmath", RID_BUILTIN_TGMATH
, D_CONLY
},
392 { "__builtin_offsetof", RID_OFFSETOF
, 0 },
393 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P
, D_CONLY
},
394 { "__builtin_va_arg", RID_VA_ARG
, 0 },
395 { "__complex", RID_COMPLEX
, 0 },
396 { "__complex__", RID_COMPLEX
, 0 },
397 { "__const", RID_CONST
, 0 },
398 { "__const__", RID_CONST
, 0 },
399 { "__constinit", RID_CONSTINIT
, D_CXXONLY
},
400 { "__decltype", RID_DECLTYPE
, D_CXXONLY
},
401 { "__direct_bases", RID_DIRECT_BASES
, D_CXXONLY
},
402 { "__extension__", RID_EXTENSION
, 0 },
403 { "__func__", RID_C99_FUNCTION_NAME
, 0 },
404 { "__has_nothrow_assign", RID_HAS_NOTHROW_ASSIGN
, D_CXXONLY
},
405 { "__has_nothrow_constructor", RID_HAS_NOTHROW_CONSTRUCTOR
, D_CXXONLY
},
406 { "__has_nothrow_copy", RID_HAS_NOTHROW_COPY
, D_CXXONLY
},
407 { "__has_trivial_assign", RID_HAS_TRIVIAL_ASSIGN
, D_CXXONLY
},
408 { "__has_trivial_constructor", RID_HAS_TRIVIAL_CONSTRUCTOR
, D_CXXONLY
},
409 { "__has_trivial_copy", RID_HAS_TRIVIAL_COPY
, D_CXXONLY
},
410 { "__has_trivial_destructor", RID_HAS_TRIVIAL_DESTRUCTOR
, D_CXXONLY
},
411 { "__has_unique_object_representations", RID_HAS_UNIQUE_OBJ_REPRESENTATIONS
,
413 { "__has_virtual_destructor", RID_HAS_VIRTUAL_DESTRUCTOR
, D_CXXONLY
},
414 { "__imag", RID_IMAGPART
, 0 },
415 { "__imag__", RID_IMAGPART
, 0 },
416 { "__inline", RID_INLINE
, 0 },
417 { "__inline__", RID_INLINE
, 0 },
418 { "__is_abstract", RID_IS_ABSTRACT
, D_CXXONLY
},
419 { "__is_aggregate", RID_IS_AGGREGATE
, D_CXXONLY
},
420 { "__is_base_of", RID_IS_BASE_OF
, D_CXXONLY
},
421 { "__is_class", RID_IS_CLASS
, D_CXXONLY
},
422 { "__is_empty", RID_IS_EMPTY
, D_CXXONLY
},
423 { "__is_enum", RID_IS_ENUM
, D_CXXONLY
},
424 { "__is_final", RID_IS_FINAL
, D_CXXONLY
},
425 { "__is_layout_compatible", RID_IS_LAYOUT_COMPATIBLE
, D_CXXONLY
},
426 { "__is_literal_type", RID_IS_LITERAL_TYPE
, D_CXXONLY
},
427 { "__is_pointer_interconvertible_base_of",
428 RID_IS_POINTER_INTERCONVERTIBLE_BASE_OF
, D_CXXONLY
},
429 { "__is_pod", RID_IS_POD
, D_CXXONLY
},
430 { "__is_polymorphic", RID_IS_POLYMORPHIC
, D_CXXONLY
},
431 { "__is_same", RID_IS_SAME_AS
, D_CXXONLY
},
432 { "__is_same_as", RID_IS_SAME_AS
, D_CXXONLY
},
433 { "__is_standard_layout", RID_IS_STD_LAYOUT
, D_CXXONLY
},
434 { "__is_trivial", RID_IS_TRIVIAL
, D_CXXONLY
},
435 { "__is_trivially_assignable", RID_IS_TRIVIALLY_ASSIGNABLE
, D_CXXONLY
},
436 { "__is_trivially_constructible", RID_IS_TRIVIALLY_CONSTRUCTIBLE
, D_CXXONLY
},
437 { "__is_trivially_copyable", RID_IS_TRIVIALLY_COPYABLE
, D_CXXONLY
},
438 { "__is_union", RID_IS_UNION
, D_CXXONLY
},
439 { "__label__", RID_LABEL
, 0 },
440 { "__null", RID_NULL
, 0 },
441 { "__real", RID_REALPART
, 0 },
442 { "__real__", RID_REALPART
, 0 },
443 { "__restrict", RID_RESTRICT
, 0 },
444 { "__restrict__", RID_RESTRICT
, 0 },
445 { "__signed", RID_SIGNED
, 0 },
446 { "__signed__", RID_SIGNED
, 0 },
447 { "__thread", RID_THREAD
, 0 },
448 { "__transaction_atomic", RID_TRANSACTION_ATOMIC
, 0 },
449 { "__transaction_relaxed", RID_TRANSACTION_RELAXED
, 0 },
450 { "__transaction_cancel", RID_TRANSACTION_CANCEL
, 0 },
451 { "__typeof", RID_TYPEOF
, 0 },
452 { "__typeof__", RID_TYPEOF
, 0 },
453 { "__underlying_type", RID_UNDERLYING_TYPE
, D_CXXONLY
},
454 { "__volatile", RID_VOLATILE
, 0 },
455 { "__volatile__", RID_VOLATILE
, 0 },
456 { "__GIMPLE", RID_GIMPLE
, D_CONLY
},
457 { "__PHI", RID_PHI
, D_CONLY
},
458 { "__RTL", RID_RTL
, D_CONLY
},
459 { "alignas", RID_ALIGNAS
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
460 { "alignof", RID_ALIGNOF
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
461 { "asm", RID_ASM
, D_ASM
},
462 { "auto", RID_AUTO
, 0 },
463 { "bool", RID_BOOL
, D_CXXONLY
| D_CXXWARN
},
464 { "break", RID_BREAK
, 0 },
465 { "case", RID_CASE
, 0 },
466 { "catch", RID_CATCH
, D_CXX_OBJC
| D_CXXWARN
},
467 { "char", RID_CHAR
, 0 },
468 { "char8_t", RID_CHAR8
, D_CXX_CHAR8_T_FLAGS
| D_CXXWARN
},
469 { "char16_t", RID_CHAR16
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
470 { "char32_t", RID_CHAR32
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
471 { "class", RID_CLASS
, D_CXX_OBJC
| D_CXXWARN
},
472 { "const", RID_CONST
, 0 },
473 { "consteval", RID_CONSTEVAL
, D_CXXONLY
| D_CXX20
| D_CXXWARN
},
474 { "constexpr", RID_CONSTEXPR
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
475 { "constinit", RID_CONSTINIT
, D_CXXONLY
| D_CXX20
| D_CXXWARN
},
476 { "const_cast", RID_CONSTCAST
, D_CXXONLY
| D_CXXWARN
},
477 { "continue", RID_CONTINUE
, 0 },
478 { "decltype", RID_DECLTYPE
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
479 { "default", RID_DEFAULT
, 0 },
480 { "delete", RID_DELETE
, D_CXXONLY
| D_CXXWARN
},
482 { "double", RID_DOUBLE
, 0 },
483 { "dynamic_cast", RID_DYNCAST
, D_CXXONLY
| D_CXXWARN
},
484 { "else", RID_ELSE
, 0 },
485 { "enum", RID_ENUM
, 0 },
486 { "explicit", RID_EXPLICIT
, D_CXXONLY
| D_CXXWARN
},
487 { "export", RID_EXPORT
, D_CXXONLY
| D_CXXWARN
},
488 { "extern", RID_EXTERN
, 0 },
489 { "false", RID_FALSE
, D_CXXONLY
| D_CXXWARN
},
490 { "float", RID_FLOAT
, 0 },
491 { "for", RID_FOR
, 0 },
492 { "friend", RID_FRIEND
, D_CXXONLY
| D_CXXWARN
},
493 { "goto", RID_GOTO
, 0 },
495 { "inline", RID_INLINE
, D_EXT89
},
496 { "int", RID_INT
, 0 },
497 { "long", RID_LONG
, 0 },
498 { "mutable", RID_MUTABLE
, D_CXXONLY
| D_CXXWARN
},
499 { "namespace", RID_NAMESPACE
, D_CXXONLY
| D_CXXWARN
},
500 { "new", RID_NEW
, D_CXXONLY
| D_CXXWARN
},
501 { "noexcept", RID_NOEXCEPT
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
502 { "nullptr", RID_NULLPTR
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
503 { "operator", RID_OPERATOR
, D_CXXONLY
| D_CXXWARN
},
504 { "private", RID_PRIVATE
, D_CXX_OBJC
| D_CXXWARN
},
505 { "protected", RID_PROTECTED
, D_CXX_OBJC
| D_CXXWARN
},
506 { "public", RID_PUBLIC
, D_CXX_OBJC
| D_CXXWARN
},
507 { "register", RID_REGISTER
, 0 },
508 { "reinterpret_cast", RID_REINTCAST
, D_CXXONLY
| D_CXXWARN
},
509 { "restrict", RID_RESTRICT
, D_CONLY
| D_C99
},
510 { "return", RID_RETURN
, 0 },
511 { "short", RID_SHORT
, 0 },
512 { "signed", RID_SIGNED
, 0 },
513 { "sizeof", RID_SIZEOF
, 0 },
514 { "static", RID_STATIC
, 0 },
515 { "static_assert", RID_STATIC_ASSERT
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
516 { "static_cast", RID_STATCAST
, D_CXXONLY
| D_CXXWARN
},
517 { "struct", RID_STRUCT
, 0 },
518 { "switch", RID_SWITCH
, 0 },
519 { "template", RID_TEMPLATE
, D_CXXONLY
| D_CXXWARN
},
520 { "this", RID_THIS
, D_CXXONLY
| D_CXXWARN
},
521 { "thread_local", RID_THREAD
, D_CXXONLY
| D_CXX11
| D_CXXWARN
},
522 { "throw", RID_THROW
, D_CXX_OBJC
| D_CXXWARN
},
523 { "true", RID_TRUE
, D_CXXONLY
| D_CXXWARN
},
524 { "try", RID_TRY
, D_CXX_OBJC
| D_CXXWARN
},
525 { "typedef", RID_TYPEDEF
, 0 },
526 { "typename", RID_TYPENAME
, D_CXXONLY
| D_CXXWARN
},
527 { "typeid", RID_TYPEID
, D_CXXONLY
| D_CXXWARN
},
528 { "typeof", RID_TYPEOF
, D_ASM
| D_EXT
},
529 { "union", RID_UNION
, 0 },
530 { "unsigned", RID_UNSIGNED
, 0 },
531 { "using", RID_USING
, D_CXXONLY
| D_CXXWARN
},
532 { "virtual", RID_VIRTUAL
, D_CXXONLY
| D_CXXWARN
},
533 { "void", RID_VOID
, 0 },
534 { "volatile", RID_VOLATILE
, 0 },
535 { "wchar_t", RID_WCHAR
, D_CXXONLY
},
536 { "while", RID_WHILE
, 0 },
537 { "__is_assignable", RID_IS_ASSIGNABLE
, D_CXXONLY
},
538 { "__is_constructible", RID_IS_CONSTRUCTIBLE
, D_CXXONLY
},
539 { "__is_nothrow_assignable", RID_IS_NOTHROW_ASSIGNABLE
, D_CXXONLY
},
540 { "__is_nothrow_constructible", RID_IS_NOTHROW_CONSTRUCTIBLE
, D_CXXONLY
},
542 /* C++ transactional memory. */
543 { "synchronized", RID_SYNCHRONIZED
, D_CXX_OBJC
| D_TRANSMEM
},
544 { "atomic_noexcept", RID_ATOMIC_NOEXCEPT
, D_CXXONLY
| D_TRANSMEM
},
545 { "atomic_cancel", RID_ATOMIC_CANCEL
, D_CXXONLY
| D_TRANSMEM
},
546 { "atomic_commit", RID_TRANSACTION_ATOMIC
, D_CXXONLY
| D_TRANSMEM
},
548 /* Concepts-related keywords */
549 { "concept", RID_CONCEPT
, D_CXX_CONCEPTS_FLAGS
| D_CXXWARN
},
550 { "requires", RID_REQUIRES
, D_CXX_CONCEPTS_FLAGS
| D_CXXWARN
},
552 /* Modules-related keywords, these are internal unspellable tokens,
553 created by the preprocessor. */
554 { "module ", RID__MODULE
, D_CXX_MODULES_FLAGS
| D_CXXWARN
},
555 { "import ", RID__IMPORT
, D_CXX_MODULES_FLAGS
| D_CXXWARN
},
556 { "export ", RID__EXPORT
, D_CXX_MODULES_FLAGS
| D_CXXWARN
},
558 /* Coroutines-related keywords */
559 { "co_await", RID_CO_AWAIT
, D_CXX_COROUTINES_FLAGS
| D_CXXWARN
},
560 { "co_yield", RID_CO_YIELD
, D_CXX_COROUTINES_FLAGS
| D_CXXWARN
},
561 { "co_return", RID_CO_RETURN
, D_CXX_COROUTINES_FLAGS
| D_CXXWARN
},
563 /* These Objective-C keywords are recognized only immediately after
565 { "compatibility_alias", RID_AT_ALIAS
, D_OBJC
},
566 { "defs", RID_AT_DEFS
, D_OBJC
},
567 { "encode", RID_AT_ENCODE
, D_OBJC
},
568 { "end", RID_AT_END
, D_OBJC
},
569 { "implementation", RID_AT_IMPLEMENTATION
, D_OBJC
},
570 { "interface", RID_AT_INTERFACE
, D_OBJC
},
571 { "protocol", RID_AT_PROTOCOL
, D_OBJC
},
572 { "selector", RID_AT_SELECTOR
, D_OBJC
},
573 { "finally", RID_AT_FINALLY
, D_OBJC
},
574 { "optional", RID_AT_OPTIONAL
, D_OBJC
},
575 { "required", RID_AT_REQUIRED
, D_OBJC
},
576 { "property", RID_AT_PROPERTY
, D_OBJC
},
577 { "package", RID_AT_PACKAGE
, D_OBJC
},
578 { "synthesize", RID_AT_SYNTHESIZE
, D_OBJC
},
579 { "dynamic", RID_AT_DYNAMIC
, D_OBJC
},
580 /* These are recognized only in protocol-qualifier context
582 { "bycopy", RID_BYCOPY
, D_OBJC
},
583 { "byref", RID_BYREF
, D_OBJC
},
584 { "in", RID_IN
, D_OBJC
},
585 { "inout", RID_INOUT
, D_OBJC
},
586 { "oneway", RID_ONEWAY
, D_OBJC
},
587 { "out", RID_OUT
, D_OBJC
},
588 /* These are recognized inside a property attribute list */
589 { "assign", RID_ASSIGN
, D_OBJC
},
590 { "atomic", RID_PROPATOMIC
, D_OBJC
},
591 { "copy", RID_COPY
, D_OBJC
},
592 { "getter", RID_GETTER
, D_OBJC
},
593 { "nonatomic", RID_NONATOMIC
, D_OBJC
},
594 { "readonly", RID_READONLY
, D_OBJC
},
595 { "readwrite", RID_READWRITE
, D_OBJC
},
596 { "retain", RID_RETAIN
, D_OBJC
},
597 { "setter", RID_SETTER
, D_OBJC
},
598 /* These are Objective C implementation of nullability, accepted only in
599 specific contexts. */
600 { "null_unspecified", RID_NULL_UNSPECIFIED
, D_OBJC
},
601 { "nullable", RID_NULLABLE
, D_OBJC
},
602 { "nonnull", RID_NONNULL
, D_OBJC
},
603 { "null_resettable", RID_NULL_RESETTABLE
, D_OBJC
},
606 const unsigned int num_c_common_reswords
=
607 sizeof c_common_reswords
/ sizeof (struct c_common_resword
);
609 /* Return identifier for address space AS. */
612 c_addr_space_name (addr_space_t as
)
614 int rid
= RID_FIRST_ADDR_SPACE
+ as
;
615 gcc_assert (ridpointers
[rid
]);
616 return IDENTIFIER_POINTER (ridpointers
[rid
]);
619 /* Push current bindings for the function name VAR_DECLS. */
622 start_fname_decls (void)
625 tree saved
= NULL_TREE
;
627 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
629 tree decl
= *fname_vars
[ix
].decl
;
633 saved
= tree_cons (decl
, build_int_cst (integer_type_node
, ix
),
635 *fname_vars
[ix
].decl
= NULL_TREE
;
638 if (saved
|| saved_function_name_decls
)
639 /* Normally they'll have been NULL, so only push if we've got a
640 stack, or they are non-NULL. */
641 saved_function_name_decls
= tree_cons (saved
, NULL_TREE
,
642 saved_function_name_decls
);
645 /* Finish up the current bindings, adding them into the current function's
646 statement tree. This must be done _before_ finish_stmt_tree is called.
647 If there is no current function, we must be at file scope and no statements
648 are involved. Pop the previous bindings. */
651 finish_fname_decls (void)
656 tree stmts
= NULL_TREE
;
657 tree stack
= saved_function_name_decls
;
659 for (; stack
&& TREE_VALUE (stack
); stack
= TREE_CHAIN (stack
))
660 append_to_statement_list (TREE_VALUE (stack
), &stmts
);
664 tree
*bodyp
= &DECL_SAVED_TREE (current_function_decl
);
666 if (TREE_CODE (*bodyp
) == BIND_EXPR
)
667 bodyp
= &BIND_EXPR_BODY (*bodyp
);
669 append_to_statement_list_force (*bodyp
, &stmts
);
673 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
674 *fname_vars
[ix
].decl
= NULL_TREE
;
678 /* We had saved values, restore them. */
681 for (saved
= TREE_PURPOSE (stack
); saved
; saved
= TREE_CHAIN (saved
))
683 tree decl
= TREE_PURPOSE (saved
);
684 unsigned ix
= TREE_INT_CST_LOW (TREE_VALUE (saved
));
686 *fname_vars
[ix
].decl
= decl
;
688 stack
= TREE_CHAIN (stack
);
690 saved_function_name_decls
= stack
;
694 /* Return the text name of the current function, suitably prettified
695 by PRETTY_P. Return string must be freed by caller. */
698 fname_as_string (int pretty_p
)
700 const char *name
= "top level";
703 cpp_string cstr
= { 0, 0 }, strname
;
711 if (current_function_decl
)
712 name
= lang_hooks
.decl_printable_name (current_function_decl
, vrb
);
714 len
= strlen (name
) + 3; /* Two for '"'s. One for NULL. */
716 namep
= XNEWVEC (char, len
);
717 snprintf (namep
, len
, "\"%s\"", name
);
718 strname
.text
= (unsigned char *) namep
;
719 strname
.len
= len
- 1;
721 if (cpp_interpret_string (parse_in
, &strname
, 1, &cstr
, CPP_STRING
))
724 return (const char *) cstr
.text
;
730 /* Return the VAR_DECL for a const char array naming the current
731 function. If the VAR_DECL has not yet been created, create it
732 now. RID indicates how it should be formatted and IDENTIFIER_NODE
733 ID is its name (unfortunately C and C++ hold the RID values of
734 keywords in different places, so we can't derive RID from ID in
735 this language independent code. LOC is the location of the
739 fname_decl (location_t loc
, unsigned int rid
, tree id
)
742 tree decl
= NULL_TREE
;
744 for (ix
= 0; fname_vars
[ix
].decl
; ix
++)
745 if (fname_vars
[ix
].rid
== rid
)
748 decl
= *fname_vars
[ix
].decl
;
751 /* If a tree is built here, it would normally have the lineno of
752 the current statement. Later this tree will be moved to the
753 beginning of the function and this line number will be wrong.
754 To avoid this problem set the lineno to 0 here; that prevents
755 it from appearing in the RTL. */
757 location_t saved_location
= input_location
;
758 input_location
= UNKNOWN_LOCATION
;
760 stmts
= push_stmt_list ();
761 decl
= (*make_fname_decl
) (loc
, id
, fname_vars
[ix
].pretty
);
762 stmts
= pop_stmt_list (stmts
);
763 if (!IS_EMPTY_STMT (stmts
))
764 saved_function_name_decls
765 = tree_cons (decl
, stmts
, saved_function_name_decls
);
766 *fname_vars
[ix
].decl
= decl
;
767 input_location
= saved_location
;
769 if (!ix
&& !current_function_decl
)
770 pedwarn (loc
, 0, "%qD is not defined outside of function scope", decl
);
775 /* Given a STRING_CST, give it a suitable array-of-chars data type. */
779 fix_string_type (tree value
)
781 int length
= TREE_STRING_LENGTH (value
);
783 tree e_type
, i_type
, a_type
;
785 /* Compute the number of elements, for the array type. */
786 if (TREE_TYPE (value
) == char_array_type_node
|| !TREE_TYPE (value
))
789 e_type
= char_type_node
;
791 else if (flag_char8_t
&& TREE_TYPE (value
) == char8_array_type_node
)
793 charsz
= TYPE_PRECISION (char8_type_node
) / BITS_PER_UNIT
;
794 e_type
= char8_type_node
;
796 else if (TREE_TYPE (value
) == char16_array_type_node
)
798 charsz
= TYPE_PRECISION (char16_type_node
) / BITS_PER_UNIT
;
799 e_type
= char16_type_node
;
801 else if (TREE_TYPE (value
) == char32_array_type_node
)
803 charsz
= TYPE_PRECISION (char32_type_node
) / BITS_PER_UNIT
;
804 e_type
= char32_type_node
;
808 charsz
= TYPE_PRECISION (wchar_type_node
) / BITS_PER_UNIT
;
809 e_type
= wchar_type_node
;
812 /* This matters only for targets where ssizetype has smaller precision
814 if (wi::lts_p (wi::to_wide (TYPE_MAX_VALUE (ssizetype
)), length
))
816 error ("size of string literal is too large");
817 length
= tree_to_shwi (TYPE_MAX_VALUE (ssizetype
)) / charsz
* charsz
;
818 char *str
= CONST_CAST (char *, TREE_STRING_POINTER (value
));
819 memset (str
+ length
, '\0',
820 MIN (TREE_STRING_LENGTH (value
) - length
, charsz
));
821 TREE_STRING_LENGTH (value
) = length
;
823 nchars
= length
/ charsz
;
825 /* C89 2.2.4.1, C99 5.2.4.1 (Translation limits). The analogous
826 limit in C++98 Annex B is very large (65536) and is not normative,
827 so we do not diagnose it (warn_overlength_strings is forced off
828 in c_common_post_options). */
829 if (warn_overlength_strings
)
831 const int nchars_max
= flag_isoc99
? 4095 : 509;
832 const int relevant_std
= flag_isoc99
? 99 : 90;
833 if (nchars
- 1 > nchars_max
)
834 /* Translators: The %d after 'ISO C' will be 90 or 99. Do not
835 separate the %d from the 'C'. 'ISO' should not be
836 translated, but it may be moved after 'C%d' in languages
837 where modifiers follow nouns. */
838 pedwarn (input_location
, OPT_Woverlength_strings
,
839 "string length %qd is greater than the length %qd "
840 "ISO C%d compilers are required to support",
841 nchars
- 1, nchars_max
, relevant_std
);
844 /* Create the array type for the string constant. The ISO C++
845 standard says that a string literal has type `const char[N]' or
846 `const wchar_t[N]'. We use the same logic when invoked as a C
847 front-end with -Wwrite-strings.
848 ??? We should change the type of an expression depending on the
849 state of a warning flag. We should just be warning -- see how
850 this is handled in the C++ front-end for the deprecated implicit
851 conversion from string literals to `char*' or `wchar_t*'.
853 The C++ front end relies on TYPE_MAIN_VARIANT of a cv-qualified
854 array type being the unqualified version of that type.
855 Therefore, if we are constructing an array of const char, we must
856 construct the matching unqualified array type first. The C front
857 end does not require this, but it does no harm, so we do it
859 i_type
= build_index_type (size_int (nchars
- 1));
860 a_type
= build_array_type (e_type
, i_type
);
861 if (c_dialect_cxx() || warn_write_strings
)
862 a_type
= c_build_qualified_type (a_type
, TYPE_QUAL_CONST
);
864 TREE_TYPE (value
) = a_type
;
865 TREE_CONSTANT (value
) = 1;
866 TREE_READONLY (value
) = 1;
867 TREE_STATIC (value
) = 1;
872 /* Given a string of type STRING_TYPE, determine what kind of string
873 token would give an equivalent execution encoding: CPP_STRING,
874 CPP_STRING16, or CPP_STRING32. Return CPP_OTHER in case of error.
875 This may not be exactly the string token type that initially created
876 the string, since CPP_WSTRING is indistinguishable from the 16/32 bit
877 string type, and CPP_UTF8STRING is indistinguishable from CPP_STRING
880 This effectively reverses part of the logic in lex_string and
883 static enum cpp_ttype
884 get_cpp_ttype_from_string_type (tree string_type
)
886 gcc_assert (string_type
);
887 if (TREE_CODE (string_type
) == POINTER_TYPE
)
888 string_type
= TREE_TYPE (string_type
);
890 if (TREE_CODE (string_type
) != ARRAY_TYPE
)
893 tree element_type
= TREE_TYPE (string_type
);
894 if (TREE_CODE (element_type
) != INTEGER_TYPE
)
897 int bits_per_character
= TYPE_PRECISION (element_type
);
898 switch (bits_per_character
)
901 return CPP_STRING
; /* It could have also been CPP_UTF8STRING. */
911 /* The global record of string concatentations, for use in
912 extracting locations within string literals. */
915 GTY(()) string_concat_db
*g_string_concat_db
;
918 /* Implementation of LANG_HOOKS_GET_SUBSTRING_LOCATION. */
921 c_get_substring_location (const substring_loc
&substr_loc
,
924 enum cpp_ttype tok_type
925 = get_cpp_ttype_from_string_type (substr_loc
.get_string_type ());
926 if (tok_type
== CPP_OTHER
)
927 return "unrecognized string type";
929 return get_location_within_string (parse_in
, g_string_concat_db
,
930 substr_loc
.get_fmt_string_loc (),
932 substr_loc
.get_caret_idx (),
933 substr_loc
.get_start_idx (),
934 substr_loc
.get_end_idx (),
939 /* Return true iff T is a boolean promoted to int. */
942 bool_promoted_to_int_p (tree t
)
944 return (CONVERT_EXPR_P (t
)
945 && TREE_TYPE (t
) == integer_type_node
946 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == BOOLEAN_TYPE
);
949 /* vector_targets_convertible_p is used for vector pointer types. The
950 callers perform various checks that the qualifiers are satisfactory,
951 while OTOH vector_targets_convertible_p ignores the number of elements
952 in the vectors. That's fine with vector pointers as we can consider,
953 say, a vector of 8 elements as two consecutive vectors of 4 elements,
954 and that does not require and conversion of the pointer values.
955 In contrast, vector_types_convertible_p and
956 vector_types_compatible_elements_p are used for vector value types. */
957 /* True if pointers to distinct types T1 and T2 can be converted to
958 each other without an explicit cast. Only returns true for opaque
961 vector_targets_convertible_p (const_tree t1
, const_tree t2
)
963 if (VECTOR_TYPE_P (t1
) && VECTOR_TYPE_P (t2
)
964 && (TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
))
965 && tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
)))
971 /* vector_types_convertible_p is used for vector value types.
972 It could in principle call vector_targets_convertible_p as a subroutine,
973 but then the check for vector type would be duplicated with its callers,
974 and also the purpose of vector_targets_convertible_p would become
976 Where vector_types_convertible_p returns true, a conversion might still be
977 needed to make the types match.
978 In contrast, vector_targets_convertible_p is used for vector pointer
979 values, and vector_types_compatible_elements_p is used specifically
980 in the context for binary operators, as a check if use is possible without
982 /* True if vector types T1 and T2 can be converted to each other
983 without an explicit cast. If EMIT_LAX_NOTE is true, and T1 and T2
984 can only be converted with -flax-vector-conversions yet that is not
985 in effect, emit a note telling the user about that option if such
986 a note has not previously been emitted. */
988 vector_types_convertible_p (const_tree t1
, const_tree t2
, bool emit_lax_note
)
990 static bool emitted_lax_note
= false;
991 bool convertible_lax
;
993 if ((TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
))
994 && tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
)))
998 (tree_int_cst_equal (TYPE_SIZE (t1
), TYPE_SIZE (t2
))
999 && (TREE_CODE (TREE_TYPE (t1
)) != REAL_TYPE
1000 || known_eq (TYPE_VECTOR_SUBPARTS (t1
),
1001 TYPE_VECTOR_SUBPARTS (t2
)))
1002 && (INTEGRAL_TYPE_P (TREE_TYPE (t1
))
1003 == INTEGRAL_TYPE_P (TREE_TYPE (t2
))));
1005 if (!convertible_lax
|| flag_lax_vector_conversions
)
1006 return convertible_lax
;
1008 if (known_eq (TYPE_VECTOR_SUBPARTS (t1
), TYPE_VECTOR_SUBPARTS (t2
))
1009 && lang_hooks
.types_compatible_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
1012 if (emit_lax_note
&& !emitted_lax_note
)
1014 emitted_lax_note
= true;
1015 inform (input_location
, "use %<-flax-vector-conversions%> to permit "
1016 "conversions between vectors with differing "
1017 "element types or numbers of subparts");
1023 /* Build a VEC_PERM_EXPR if V0, V1 and MASK are not error_mark_nodes
1024 and have vector types, V0 has the same type as V1, and the number of
1025 elements of V0, V1, MASK is the same.
1027 In case V1 is a NULL_TREE it is assumed that __builtin_shuffle was
1028 called with two arguments. In this case implementation passes the
1029 first argument twice in order to share the same tree code. This fact
1030 could enable the mask-values being twice the vector length. This is
1031 an implementation accident and this semantics is not guaranteed to
1035 c_build_vec_perm_expr (location_t loc
, tree v0
, tree v1
, tree mask
,
1040 bool maybe_const
= false;
1041 bool two_arguments
= false;
1043 if (v1
== NULL_TREE
)
1045 two_arguments
= true;
1049 if (v0
== error_mark_node
|| v1
== error_mark_node
1050 || mask
== error_mark_node
)
1051 return error_mark_node
;
1053 if (!gnu_vector_type_p (TREE_TYPE (mask
))
1054 || !VECTOR_INTEGER_TYPE_P (TREE_TYPE (mask
)))
1057 error_at (loc
, "%<__builtin_shuffle%> last argument must "
1058 "be an integer vector");
1059 return error_mark_node
;
1062 if (!gnu_vector_type_p (TREE_TYPE (v0
))
1063 || !gnu_vector_type_p (TREE_TYPE (v1
)))
1066 error_at (loc
, "%<__builtin_shuffle%> arguments must be vectors");
1067 return error_mark_node
;
1070 if (TYPE_MAIN_VARIANT (TREE_TYPE (v0
)) != TYPE_MAIN_VARIANT (TREE_TYPE (v1
)))
1073 error_at (loc
, "%<__builtin_shuffle%> argument vectors must be of "
1075 return error_mark_node
;
1078 if (maybe_ne (TYPE_VECTOR_SUBPARTS (TREE_TYPE (v0
)),
1079 TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask
)))
1080 && maybe_ne (TYPE_VECTOR_SUBPARTS (TREE_TYPE (v1
)),
1081 TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask
))))
1084 error_at (loc
, "%<__builtin_shuffle%> number of elements of the "
1085 "argument vector(s) and the mask vector should "
1087 return error_mark_node
;
1090 if (GET_MODE_BITSIZE (SCALAR_TYPE_MODE (TREE_TYPE (TREE_TYPE (v0
))))
1091 != GET_MODE_BITSIZE (SCALAR_TYPE_MODE (TREE_TYPE (TREE_TYPE (mask
)))))
1094 error_at (loc
, "%<__builtin_shuffle%> argument vector(s) inner type "
1095 "must have the same size as inner type of the mask");
1096 return error_mark_node
;
1099 if (!c_dialect_cxx ())
1101 /* Avoid C_MAYBE_CONST_EXPRs inside VEC_PERM_EXPR. */
1102 v0
= c_fully_fold (v0
, false, &maybe_const
);
1103 wrap
&= maybe_const
;
1106 v1
= v0
= save_expr (v0
);
1109 v1
= c_fully_fold (v1
, false, &maybe_const
);
1110 wrap
&= maybe_const
;
1113 mask
= c_fully_fold (mask
, false, &maybe_const
);
1114 wrap
&= maybe_const
;
1116 else if (two_arguments
)
1117 v1
= v0
= save_expr (v0
);
1119 ret
= build3_loc (loc
, VEC_PERM_EXPR
, TREE_TYPE (v0
), v0
, v1
, mask
);
1121 if (!c_dialect_cxx () && !wrap
)
1122 ret
= c_wrap_maybe_const (ret
, true);
1128 /* Build a VEC_PERM_EXPR if V0, V1 are not error_mark_nodes
1129 and have vector types, V0 has the same element type as V1, and the
1130 number of elements the result is that of MASK. */
1133 c_build_shufflevector (location_t loc
, tree v0
, tree v1
,
1134 const vec
<tree
> &mask
, bool complain
)
1138 bool maybe_const
= false;
1140 if (v0
== error_mark_node
|| v1
== error_mark_node
)
1141 return error_mark_node
;
1143 if (!gnu_vector_type_p (TREE_TYPE (v0
))
1144 || !gnu_vector_type_p (TREE_TYPE (v1
)))
1147 error_at (loc
, "%<__builtin_shufflevector%> arguments must be vectors");
1148 return error_mark_node
;
1151 /* ??? In principle one could select a constant part of a variable size
1152 vector but things get a bit awkward with trying to support this here. */
1153 unsigned HOST_WIDE_INT v0n
, v1n
;
1154 if (!TYPE_VECTOR_SUBPARTS (TREE_TYPE (v0
)).is_constant (&v0n
)
1155 || !TYPE_VECTOR_SUBPARTS (TREE_TYPE (v1
)).is_constant (&v1n
))
1158 error_at (loc
, "%<__builtin_shufflevector%> arguments must be constant"
1160 return error_mark_node
;
1163 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (v0
)))
1164 != TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (v1
))))
1167 error_at (loc
, "%<__builtin_shufflevector%> argument vectors must "
1168 "have the same element type");
1169 return error_mark_node
;
1172 if (!pow2p_hwi (mask
.length ()))
1175 error_at (loc
, "%<__builtin_shufflevector%> must specify a result "
1176 "with a power of two number of elements");
1177 return error_mark_node
;
1180 if (!c_dialect_cxx ())
1182 /* Avoid C_MAYBE_CONST_EXPRs inside VEC_PERM_EXPR. */
1183 v0
= c_fully_fold (v0
, false, &maybe_const
);
1184 wrap
&= maybe_const
;
1186 v1
= c_fully_fold (v1
, false, &maybe_const
);
1187 wrap
&= maybe_const
;
1190 unsigned HOST_WIDE_INT maskl
= MAX (mask
.length (), MAX (v0n
, v1n
));
1191 unsigned HOST_WIDE_INT pad
= (v0n
< maskl
? maskl
- v0n
: 0);
1192 vec_perm_builder
sel (maskl
, maskl
, 1);
1194 for (i
= 0; i
< mask
.length (); ++i
)
1197 if (!tree_fits_shwi_p (idx
))
1200 error_at (loc
, "invalid element index %qE to "
1201 "%<__builtin_shufflevector%>", idx
);
1202 return error_mark_node
;
1204 HOST_WIDE_INT iidx
= tree_to_shwi (idx
);
1207 && (unsigned HOST_WIDE_INT
) iidx
>= v0n
+ v1n
))
1210 error_at (loc
, "invalid element index %qE to "
1211 "%<__builtin_shufflevector%>", idx
);
1212 return error_mark_node
;
1214 /* ??? Our VEC_PERM_EXPR does not allow for -1 yet. */
1217 /* ??? Our VEC_PERM_EXPR does not allow different sized inputs,
1218 so pad out a smaller v0. */
1219 else if ((unsigned HOST_WIDE_INT
) iidx
>= v0n
)
1221 sel
.quick_push (iidx
);
1223 /* ??? VEC_PERM_EXPR does not support a result that is smaller than
1224 the inputs, so we have to pad id out. */
1225 for (; i
< maskl
; ++i
)
1228 vec_perm_indices
indices (sel
, 2, maskl
);
1230 tree ret_type
= build_vector_type (TREE_TYPE (TREE_TYPE (v0
)), maskl
);
1231 tree mask_type
= build_vector_type (build_nonstandard_integer_type
1232 (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (ret_type
))), 1),
1234 /* Pad out arguments to the common vector size. */
1237 constructor_elt elt
= { NULL_TREE
, build_zero_cst (TREE_TYPE (v0
)) };
1238 v0
= build_constructor_single (ret_type
, NULL_TREE
, v0
);
1239 for (i
= 1; i
< maskl
/ v0n
; ++i
)
1240 vec_safe_push (CONSTRUCTOR_ELTS (v0
), elt
);
1244 constructor_elt elt
= { NULL_TREE
, build_zero_cst (TREE_TYPE (v1
)) };
1245 v1
= build_constructor_single (ret_type
, NULL_TREE
, v1
);
1246 for (i
= 1; i
< maskl
/ v1n
; ++i
)
1247 vec_safe_push (CONSTRUCTOR_ELTS (v1
), elt
);
1249 ret
= build3_loc (loc
, VEC_PERM_EXPR
, ret_type
, v0
, v1
,
1250 vec_perm_indices_to_tree (mask_type
, indices
));
1251 /* Get the lowpart we are interested in. */
1252 if (mask
.length () < maskl
)
1254 tree lpartt
= build_vector_type (TREE_TYPE (ret_type
), mask
.length ());
1255 ret
= build3_loc (loc
, BIT_FIELD_REF
,
1256 lpartt
, ret
, TYPE_SIZE (lpartt
), bitsize_zero_node
);
1257 /* Wrap the lowpart operation in a TARGET_EXPR so it gets a separate
1258 temporary during gimplification. See PR101530 for cases where
1259 we'd otherwise end up with non-toplevel BIT_FIELD_REFs. */
1260 tree tem
= create_tmp_var_raw (lpartt
);
1261 DECL_CONTEXT (tem
) = current_function_decl
;
1262 ret
= build4 (TARGET_EXPR
, lpartt
, tem
, ret
, NULL_TREE
, NULL_TREE
);
1263 TREE_SIDE_EFFECTS (ret
) = 1;
1266 if (!c_dialect_cxx () && !wrap
)
1267 ret
= c_wrap_maybe_const (ret
, true);
1273 /* Build a VEC_CONVERT ifn for __builtin_convertvector builtin. */
1276 c_build_vec_convert (location_t loc1
, tree expr
, location_t loc2
, tree type
,
1279 if (error_operand_p (type
))
1280 return error_mark_node
;
1281 if (error_operand_p (expr
))
1282 return error_mark_node
;
1284 if (!gnu_vector_type_p (TREE_TYPE (expr
))
1285 || (!VECTOR_INTEGER_TYPE_P (TREE_TYPE (expr
))
1286 && !VECTOR_FLOAT_TYPE_P (TREE_TYPE (expr
))))
1289 error_at (loc1
, "%<__builtin_convertvector%> first argument must "
1290 "be an integer or floating vector");
1291 return error_mark_node
;
1294 if (!gnu_vector_type_p (type
)
1295 || (!VECTOR_INTEGER_TYPE_P (type
) && !VECTOR_FLOAT_TYPE_P (type
)))
1298 error_at (loc2
, "%<__builtin_convertvector%> second argument must "
1299 "be an integer or floating vector type");
1300 return error_mark_node
;
1303 if (maybe_ne (TYPE_VECTOR_SUBPARTS (TREE_TYPE (expr
)),
1304 TYPE_VECTOR_SUBPARTS (type
)))
1307 error_at (loc1
, "%<__builtin_convertvector%> number of elements "
1308 "of the first argument vector and the second argument "
1309 "vector type should be the same");
1310 return error_mark_node
;
1313 if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (expr
)))
1314 == TYPE_MAIN_VARIANT (TREE_TYPE (type
)))
1315 || (VECTOR_INTEGER_TYPE_P (TREE_TYPE (expr
))
1316 && VECTOR_INTEGER_TYPE_P (type
)
1317 && (TYPE_PRECISION (TREE_TYPE (TREE_TYPE (expr
)))
1318 == TYPE_PRECISION (TREE_TYPE (type
)))))
1319 return build1_loc (loc1
, VIEW_CONVERT_EXPR
, type
, expr
);
1322 bool maybe_const
= false;
1324 if (!c_dialect_cxx ())
1326 /* Avoid C_MAYBE_CONST_EXPRs inside of VEC_CONVERT argument. */
1327 expr
= c_fully_fold (expr
, false, &maybe_const
);
1328 wrap
&= maybe_const
;
1331 ret
= build_call_expr_internal_loc (loc1
, IFN_VEC_CONVERT
, type
, 1, expr
);
1334 ret
= c_wrap_maybe_const (ret
, true);
1339 /* Like tree.cc:get_narrower, but retain conversion from C++0x scoped enum
1340 to integral type. */
1343 c_common_get_narrower (tree op
, int *unsignedp_ptr
)
1345 op
= get_narrower (op
, unsignedp_ptr
);
1347 if (TREE_CODE (TREE_TYPE (op
)) == ENUMERAL_TYPE
1348 && ENUM_IS_SCOPED (TREE_TYPE (op
)))
1350 /* C++0x scoped enumerations don't implicitly convert to integral
1351 type; if we stripped an explicit conversion to a larger type we
1352 need to replace it so common_type will still work. */
1353 tree type
= c_common_type_for_size (TYPE_PRECISION (TREE_TYPE (op
)),
1354 TYPE_UNSIGNED (TREE_TYPE (op
)));
1355 op
= fold_convert (type
, op
);
1360 /* This is a helper function of build_binary_op.
1362 For certain operations if both args were extended from the same
1363 smaller type, do the arithmetic in that type and then extend.
1365 BITWISE indicates a bitwise operation.
1366 For them, this optimization is safe only if
1367 both args are zero-extended or both are sign-extended.
1368 Otherwise, we might change the result.
1369 Eg, (short)-1 | (unsigned short)-1 is (int)-1
1370 but calculated in (unsigned short) it would be (unsigned short)-1.
1373 shorten_binary_op (tree result_type
, tree op0
, tree op1
, bool bitwise
)
1375 int unsigned0
, unsigned1
;
1380 /* Cast OP0 and OP1 to RESULT_TYPE. Doing so prevents
1381 excessive narrowing when we call get_narrower below. For
1382 example, suppose that OP0 is of unsigned int extended
1383 from signed char and that RESULT_TYPE is long long int.
1384 If we explicitly cast OP0 to RESULT_TYPE, OP0 would look
1387 (long long int) (unsigned int) signed_char
1389 which get_narrower would narrow down to
1391 (unsigned int) signed char
1393 If we do not cast OP0 first, get_narrower would return
1394 signed_char, which is inconsistent with the case of the
1396 op0
= convert (result_type
, op0
);
1397 op1
= convert (result_type
, op1
);
1399 arg0
= c_common_get_narrower (op0
, &unsigned0
);
1400 arg1
= c_common_get_narrower (op1
, &unsigned1
);
1402 /* UNS is 1 if the operation to be done is an unsigned one. */
1403 uns
= TYPE_UNSIGNED (result_type
);
1405 /* Handle the case that OP0 (or OP1) does not *contain* a conversion
1406 but it *requires* conversion to FINAL_TYPE. */
1408 if ((TYPE_PRECISION (TREE_TYPE (op0
))
1409 == TYPE_PRECISION (TREE_TYPE (arg0
)))
1410 && TREE_TYPE (op0
) != result_type
)
1411 unsigned0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
1412 if ((TYPE_PRECISION (TREE_TYPE (op1
))
1413 == TYPE_PRECISION (TREE_TYPE (arg1
)))
1414 && TREE_TYPE (op1
) != result_type
)
1415 unsigned1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
1417 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */
1419 /* For bitwise operations, signedness of nominal type
1420 does not matter. Consider only how operands were extended. */
1424 /* Note that in all three cases below we refrain from optimizing
1425 an unsigned operation on sign-extended args.
1426 That would not be valid. */
1428 /* Both args variable: if both extended in same way
1429 from same width, do it in that width.
1430 Do it unsigned if args were zero-extended. */
1431 if ((TYPE_PRECISION (TREE_TYPE (arg0
))
1432 < TYPE_PRECISION (result_type
))
1433 && (TYPE_PRECISION (TREE_TYPE (arg1
))
1434 == TYPE_PRECISION (TREE_TYPE (arg0
)))
1435 && unsigned0
== unsigned1
1436 && (unsigned0
|| !uns
))
1437 return c_common_signed_or_unsigned_type
1438 (unsigned0
, common_type (TREE_TYPE (arg0
), TREE_TYPE (arg1
)));
1440 else if (TREE_CODE (arg0
) == INTEGER_CST
1441 && (unsigned1
|| !uns
)
1442 && (TYPE_PRECISION (TREE_TYPE (arg1
))
1443 < TYPE_PRECISION (result_type
))
1445 = c_common_signed_or_unsigned_type (unsigned1
,
1447 && !POINTER_TYPE_P (type
)
1448 && int_fits_type_p (arg0
, type
))
1451 else if (TREE_CODE (arg1
) == INTEGER_CST
1452 && (unsigned0
|| !uns
)
1453 && (TYPE_PRECISION (TREE_TYPE (arg0
))
1454 < TYPE_PRECISION (result_type
))
1456 = c_common_signed_or_unsigned_type (unsigned0
,
1458 && !POINTER_TYPE_P (type
)
1459 && int_fits_type_p (arg1
, type
))
1465 /* Returns true iff any integer value of type FROM_TYPE can be represented as
1466 real of type TO_TYPE. This is a helper function for unsafe_conversion_p. */
1469 int_safely_convertible_to_real_p (const_tree from_type
, const_tree to_type
)
1471 tree type_low_bound
= TYPE_MIN_VALUE (from_type
);
1472 tree type_high_bound
= TYPE_MAX_VALUE (from_type
);
1473 REAL_VALUE_TYPE real_low_bound
=
1474 real_value_from_int_cst (0, type_low_bound
);
1475 REAL_VALUE_TYPE real_high_bound
=
1476 real_value_from_int_cst (0, type_high_bound
);
1478 return exact_real_truncate (TYPE_MODE (to_type
), &real_low_bound
)
1479 && exact_real_truncate (TYPE_MODE (to_type
), &real_high_bound
);
1482 /* Checks if expression EXPR of complex/real/integer type cannot be converted
1483 to the complex/real/integer type TYPE. Function returns non-zero when:
1484 * EXPR is a constant which cannot be exactly converted to TYPE.
1485 * EXPR is not a constant and size of EXPR's type > than size of TYPE,
1486 for EXPR type and TYPE being both integers or both real, or both
1488 * EXPR is not a constant of complex type and TYPE is a real or
1490 * EXPR is not a constant of real type and TYPE is an integer.
1491 * EXPR is not a constant of integer type which cannot be
1492 exactly converted to real type.
1494 Function allows conversions between types of different signedness if
1495 CHECK_SIGN is false and can return SAFE_CONVERSION (zero) in that
1496 case. Function can return UNSAFE_SIGN if CHECK_SIGN is true.
1498 RESULT, when non-null is the result of the conversion. When constant
1499 it is included in the text of diagnostics.
1501 Function allows conversions from complex constants to non-complex types,
1502 provided that imaginary part is zero and real part can be safely converted
1505 enum conversion_safety
1506 unsafe_conversion_p (tree type
, tree expr
, tree result
, bool check_sign
)
1508 enum conversion_safety give_warning
= SAFE_CONVERSION
; /* is 0 or false */
1509 tree expr_type
= TREE_TYPE (expr
);
1511 expr
= fold_for_warn (expr
);
1513 if (TREE_CODE (expr
) == REAL_CST
|| TREE_CODE (expr
) == INTEGER_CST
)
1515 /* If type is complex, we are interested in compatibility with
1517 if (TREE_CODE (type
) == COMPLEX_TYPE
)
1518 type
= TREE_TYPE (type
);
1520 /* Warn for real constant that is not an exact integer converted
1522 if (TREE_CODE (expr_type
) == REAL_TYPE
1523 && TREE_CODE (type
) == INTEGER_TYPE
)
1525 if (!real_isinteger (TREE_REAL_CST_PTR (expr
), TYPE_MODE (expr_type
)))
1526 give_warning
= UNSAFE_REAL
;
1528 /* Warn for an integer constant that does not fit into integer type. */
1529 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
1530 && TREE_CODE (type
) == INTEGER_TYPE
1531 && !int_fits_type_p (expr
, type
))
1533 if (TYPE_UNSIGNED (type
) && !TYPE_UNSIGNED (expr_type
)
1534 && tree_int_cst_sgn (expr
) < 0)
1537 give_warning
= UNSAFE_SIGN
;
1539 else if (!TYPE_UNSIGNED (type
) && TYPE_UNSIGNED (expr_type
))
1542 give_warning
= UNSAFE_SIGN
;
1545 give_warning
= UNSAFE_OTHER
;
1547 else if (TREE_CODE (type
) == REAL_TYPE
)
1549 /* Warn for an integer constant that does not fit into real type. */
1550 if (TREE_CODE (expr_type
) == INTEGER_TYPE
)
1552 REAL_VALUE_TYPE a
= real_value_from_int_cst (0, expr
);
1553 if (!exact_real_truncate (TYPE_MODE (type
), &a
))
1554 give_warning
= UNSAFE_REAL
;
1556 /* Warn for a real constant that does not fit into a smaller
1558 else if (TREE_CODE (expr_type
) == REAL_TYPE
1559 && TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
1561 REAL_VALUE_TYPE a
= TREE_REAL_CST (expr
);
1562 if (!exact_real_truncate (TYPE_MODE (type
), &a
))
1563 give_warning
= UNSAFE_REAL
;
1568 else if (TREE_CODE (expr
) == COMPLEX_CST
)
1570 tree imag_part
= TREE_IMAGPART (expr
);
1571 /* Conversion from complex constant with zero imaginary part,
1572 perform check for conversion of real part. */
1573 if ((TREE_CODE (imag_part
) == REAL_CST
1574 && real_zerop (imag_part
))
1575 || (TREE_CODE (imag_part
) == INTEGER_CST
1576 && integer_zerop (imag_part
)))
1577 /* Note: in this branch we use recursive call to unsafe_conversion_p
1578 with different type of EXPR, but it is still safe, because when EXPR
1579 is a constant, it's type is not used in text of generated warnings
1580 (otherwise they could sound misleading). */
1581 return unsafe_conversion_p (type
, TREE_REALPART (expr
), result
,
1583 /* Conversion from complex constant with non-zero imaginary part. */
1586 /* Conversion to complex type.
1587 Perform checks for both real and imaginary parts. */
1588 if (TREE_CODE (type
) == COMPLEX_TYPE
)
1590 enum conversion_safety re_safety
=
1591 unsafe_conversion_p (type
, TREE_REALPART (expr
),
1592 result
, check_sign
);
1593 enum conversion_safety im_safety
=
1594 unsafe_conversion_p (type
, imag_part
, result
, check_sign
);
1596 /* Merge the results into appropriate single warning. */
1598 /* Note: this case includes SAFE_CONVERSION, i.e. success. */
1599 if (re_safety
== im_safety
)
1600 give_warning
= re_safety
;
1601 else if (!re_safety
&& im_safety
)
1602 give_warning
= im_safety
;
1603 else if (re_safety
&& !im_safety
)
1604 give_warning
= re_safety
;
1606 give_warning
= UNSAFE_OTHER
;
1608 /* Warn about conversion from complex to real or integer type. */
1610 give_warning
= UNSAFE_IMAGINARY
;
1614 /* Checks for remaining case: EXPR is not constant. */
1617 /* Warn for real types converted to integer types. */
1618 if (TREE_CODE (expr_type
) == REAL_TYPE
1619 && TREE_CODE (type
) == INTEGER_TYPE
)
1620 give_warning
= UNSAFE_REAL
;
1622 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
1623 && TREE_CODE (type
) == INTEGER_TYPE
)
1625 /* Don't warn about unsigned char y = 0xff, x = (int) y; */
1626 expr
= get_unwidened (expr
, 0);
1627 expr_type
= TREE_TYPE (expr
);
1629 /* Don't warn for short y; short x = ((int)y & 0xff); */
1630 if (TREE_CODE (expr
) == BIT_AND_EXPR
1631 || TREE_CODE (expr
) == BIT_IOR_EXPR
1632 || TREE_CODE (expr
) == BIT_XOR_EXPR
)
1634 /* If both args were extended from a shortest type,
1635 use that type if that is safe. */
1636 expr_type
= shorten_binary_op (expr_type
,
1637 TREE_OPERAND (expr
, 0),
1638 TREE_OPERAND (expr
, 1),
1641 if (TREE_CODE (expr
) == BIT_AND_EXPR
)
1643 tree op0
= TREE_OPERAND (expr
, 0);
1644 tree op1
= TREE_OPERAND (expr
, 1);
1645 bool unsigned0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
1646 bool unsigned1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
1648 /* If one of the operands is a non-negative constant
1649 that fits in the target type, then the type of the
1650 other operand does not matter. */
1651 if ((TREE_CODE (op0
) == INTEGER_CST
1652 && int_fits_type_p (op0
, c_common_signed_type (type
))
1653 && int_fits_type_p (op0
, c_common_unsigned_type (type
)))
1654 || (TREE_CODE (op1
) == INTEGER_CST
1655 && int_fits_type_p (op1
, c_common_signed_type (type
))
1656 && int_fits_type_p (op1
,
1657 c_common_unsigned_type (type
))))
1658 return SAFE_CONVERSION
;
1659 /* If constant is unsigned and fits in the target
1660 type, then the result will also fit. */
1661 else if ((TREE_CODE (op0
) == INTEGER_CST
1663 && int_fits_type_p (op0
, type
))
1664 || (TREE_CODE (op1
) == INTEGER_CST
1666 && int_fits_type_p (op1
, type
)))
1667 return SAFE_CONVERSION
;
1670 /* Warn for integer types converted to smaller integer types. */
1671 if (TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
1672 give_warning
= UNSAFE_OTHER
;
1674 /* When they are the same width but different signedness,
1675 then the value may change. */
1676 else if (((TYPE_PRECISION (type
) == TYPE_PRECISION (expr_type
)
1677 && TYPE_UNSIGNED (expr_type
) != TYPE_UNSIGNED (type
))
1678 /* Even when converted to a bigger type, if the type is
1679 unsigned but expr is signed, then negative values
1681 || (TYPE_UNSIGNED (type
) && !TYPE_UNSIGNED (expr_type
)))
1683 give_warning
= UNSAFE_SIGN
;
1686 /* Warn for integer types converted to real types if and only if
1687 all the range of values of the integer type cannot be
1688 represented by the real type. */
1689 else if (TREE_CODE (expr_type
) == INTEGER_TYPE
1690 && TREE_CODE (type
) == REAL_TYPE
)
1692 /* Don't warn about char y = 0xff; float x = (int) y; */
1693 expr
= get_unwidened (expr
, 0);
1694 expr_type
= TREE_TYPE (expr
);
1696 if (!int_safely_convertible_to_real_p (expr_type
, type
))
1697 give_warning
= UNSAFE_OTHER
;
1700 /* Warn for real types converted to smaller real types. */
1701 else if (TREE_CODE (expr_type
) == REAL_TYPE
1702 && TREE_CODE (type
) == REAL_TYPE
1703 && TYPE_PRECISION (type
) < TYPE_PRECISION (expr_type
))
1704 give_warning
= UNSAFE_REAL
;
1706 /* Check conversion between two complex types. */
1707 else if (TREE_CODE (expr_type
) == COMPLEX_TYPE
1708 && TREE_CODE (type
) == COMPLEX_TYPE
)
1710 /* Extract underlying types (i.e., type of real and imaginary
1711 parts) of expr_type and type. */
1712 tree from_type
= TREE_TYPE (expr_type
);
1713 tree to_type
= TREE_TYPE (type
);
1715 /* Warn for real types converted to integer types. */
1716 if (TREE_CODE (from_type
) == REAL_TYPE
1717 && TREE_CODE (to_type
) == INTEGER_TYPE
)
1718 give_warning
= UNSAFE_REAL
;
1720 /* Warn for real types converted to smaller real types. */
1721 else if (TREE_CODE (from_type
) == REAL_TYPE
1722 && TREE_CODE (to_type
) == REAL_TYPE
1723 && TYPE_PRECISION (to_type
) < TYPE_PRECISION (from_type
))
1724 give_warning
= UNSAFE_REAL
;
1726 /* Check conversion for complex integer types. Here implementation
1727 is simpler than for real-domain integers because it does not
1728 involve sophisticated cases, such as bitmasks, casts, etc. */
1729 else if (TREE_CODE (from_type
) == INTEGER_TYPE
1730 && TREE_CODE (to_type
) == INTEGER_TYPE
)
1732 /* Warn for integer types converted to smaller integer types. */
1733 if (TYPE_PRECISION (to_type
) < TYPE_PRECISION (from_type
))
1734 give_warning
= UNSAFE_OTHER
;
1736 /* Check for different signedness, see case for real-domain
1737 integers (above) for a more detailed comment. */
1738 else if (((TYPE_PRECISION (to_type
) == TYPE_PRECISION (from_type
)
1739 && TYPE_UNSIGNED (to_type
) != TYPE_UNSIGNED (from_type
))
1740 || (TYPE_UNSIGNED (to_type
) && !TYPE_UNSIGNED (from_type
)))
1742 give_warning
= UNSAFE_SIGN
;
1744 else if (TREE_CODE (from_type
) == INTEGER_TYPE
1745 && TREE_CODE (to_type
) == REAL_TYPE
1746 && !int_safely_convertible_to_real_p (from_type
, to_type
))
1747 give_warning
= UNSAFE_OTHER
;
1750 /* Warn for complex types converted to real or integer types. */
1751 else if (TREE_CODE (expr_type
) == COMPLEX_TYPE
1752 && TREE_CODE (type
) != COMPLEX_TYPE
)
1753 give_warning
= UNSAFE_IMAGINARY
;
1756 return give_warning
;
1760 /* Convert EXPR to TYPE, warning about conversion problems with constants.
1761 Invoke this function on every expression that is converted implicitly,
1762 i.e. because of language rules and not because of an explicit cast.
1763 INIT_CONST is true if the conversion is for arithmetic types for a static
1764 initializer and folding must apply accordingly (discarding floating-point
1765 exceptions and assuming the default rounding mode is in effect). */
1768 convert_and_check (location_t loc
, tree type
, tree expr
, bool init_const
)
1771 tree expr_for_warning
;
1773 /* Convert from a value with possible excess precision rather than
1774 via the semantic type, but do not warn about values not fitting
1775 exactly in the semantic type. */
1776 if (TREE_CODE (expr
) == EXCESS_PRECISION_EXPR
)
1778 tree orig_type
= TREE_TYPE (expr
);
1779 expr
= TREE_OPERAND (expr
, 0);
1780 expr_for_warning
= (init_const
1781 ? convert_init (orig_type
, expr
)
1782 : convert (orig_type
, expr
));
1783 if (orig_type
== type
)
1784 return expr_for_warning
;
1787 expr_for_warning
= expr
;
1789 if (TREE_TYPE (expr
) == type
)
1792 result
= init_const
? convert_init (type
, expr
) : convert (type
, expr
);
1794 if (c_inhibit_evaluation_warnings
== 0
1795 && !TREE_OVERFLOW_P (expr
)
1796 && result
!= error_mark_node
)
1797 warnings_for_convert_and_check (loc
, type
, expr_for_warning
, result
);
1802 /* A node in a list that describes references to variables (EXPR), which are
1803 either read accesses if WRITER is zero, or write accesses, in which case
1804 WRITER is the parent of EXPR. */
1811 /* Used to implement a cache the results of a call to verify_tree. We only
1812 use this for SAVE_EXPRs. */
1815 struct tlist_cache
*next
;
1816 struct tlist
*cache_before_sp
;
1817 struct tlist
*cache_after_sp
;
1821 /* Obstack to use when allocating tlist structures, and corresponding
1823 static struct obstack tlist_obstack
;
1824 static char *tlist_firstobj
= 0;
1826 /* Keep track of the identifiers we've warned about, so we can avoid duplicate
1828 static struct tlist
*warned_ids
;
1829 /* SAVE_EXPRs need special treatment. We process them only once and then
1830 cache the results. */
1831 static struct tlist_cache
*save_expr_cache
;
1833 static void add_tlist (struct tlist
**, struct tlist
*, tree
, int);
1834 static void merge_tlist (struct tlist
**, struct tlist
*, int);
1835 static void verify_tree (tree
, struct tlist
**, struct tlist
**, tree
);
1836 static bool warning_candidate_p (tree
);
1837 static bool candidate_equal_p (const_tree
, const_tree
);
1838 static void warn_for_collisions (struct tlist
*);
1839 static void warn_for_collisions_1 (tree
, tree
, struct tlist
*, int);
1840 static struct tlist
*new_tlist (struct tlist
*, tree
, tree
);
1842 /* Create a new struct tlist and fill in its fields. */
1843 static struct tlist
*
1844 new_tlist (struct tlist
*next
, tree t
, tree writer
)
1847 l
= XOBNEW (&tlist_obstack
, struct tlist
);
1854 /* Add duplicates of the nodes found in ADD to the list *TO. If EXCLUDE_WRITER
1855 is nonnull, we ignore any node we find which has a writer equal to it. */
1858 add_tlist (struct tlist
**to
, struct tlist
*add
, tree exclude_writer
, int copy
)
1862 struct tlist
*next
= add
->next
;
1865 if (!exclude_writer
|| !candidate_equal_p (add
->writer
, exclude_writer
))
1866 *to
= copy
? new_tlist (*to
, add
->expr
, add
->writer
) : add
;
1871 /* Merge the nodes of ADD into TO. This merging process is done so that for
1872 each variable that already exists in TO, no new node is added; however if
1873 there is a write access recorded in ADD, and an occurrence on TO is only
1874 a read access, then the occurrence in TO will be modified to record the
1878 merge_tlist (struct tlist
**to
, struct tlist
*add
, int copy
)
1880 struct tlist
**end
= to
;
1883 end
= &(*end
)->next
;
1889 struct tlist
*next
= add
->next
;
1891 for (tmp2
= *to
; tmp2
; tmp2
= tmp2
->next
)
1892 if (candidate_equal_p (tmp2
->expr
, add
->expr
))
1896 tmp2
->writer
= add
->writer
;
1900 *end
= copy
? new_tlist (NULL
, add
->expr
, add
->writer
) : add
;
1901 end
= &(*end
)->next
;
1908 /* WRITTEN is a variable, WRITER is its parent. Warn if any of the variable
1909 references in list LIST conflict with it, excluding reads if ONLY writers
1913 warn_for_collisions_1 (tree written
, tree writer
, struct tlist
*list
,
1918 /* Avoid duplicate warnings. */
1919 for (tmp
= warned_ids
; tmp
; tmp
= tmp
->next
)
1920 if (candidate_equal_p (tmp
->expr
, written
))
1925 if (candidate_equal_p (list
->expr
, written
)
1926 && !candidate_equal_p (list
->writer
, writer
)
1927 && (!only_writes
|| list
->writer
))
1929 warned_ids
= new_tlist (warned_ids
, written
, NULL_TREE
);
1930 warning_at (EXPR_LOC_OR_LOC (writer
, input_location
),
1931 OPT_Wsequence_point
, "operation on %qE may be undefined",
1938 /* Given a list LIST of references to variables, find whether any of these
1939 can cause conflicts due to missing sequence points. */
1942 warn_for_collisions (struct tlist
*list
)
1946 for (tmp
= list
; tmp
; tmp
= tmp
->next
)
1949 warn_for_collisions_1 (tmp
->expr
, tmp
->writer
, list
, 0);
1953 /* Return nonzero if X is a tree that can be verified by the sequence point
1957 warning_candidate_p (tree x
)
1959 if (DECL_P (x
) && DECL_ARTIFICIAL (x
))
1962 if (TREE_CODE (x
) == BLOCK
)
1965 /* VOID_TYPE_P (TREE_TYPE (x)) is workaround for cp/tree.cc
1966 (lvalue_p) crash on TRY/CATCH. */
1967 if (TREE_TYPE (x
) == NULL_TREE
|| VOID_TYPE_P (TREE_TYPE (x
)))
1973 /* No point to track non-const calls, they will never satisfy
1975 if (TREE_CODE (x
) == CALL_EXPR
&& (call_expr_flags (x
) & ECF_CONST
) == 0)
1978 if (TREE_CODE (x
) == STRING_CST
)
1984 /* Return nonzero if X and Y appear to be the same candidate (or NULL) */
1986 candidate_equal_p (const_tree x
, const_tree y
)
1988 return (x
== y
) || (x
&& y
&& operand_equal_p (x
, y
, 0));
1991 /* Walk the tree X, and record accesses to variables. If X is written by the
1992 parent tree, WRITER is the parent.
1993 We store accesses in one of the two lists: PBEFORE_SP, and PNO_SP. If this
1994 expression or its only operand forces a sequence point, then everything up
1995 to the sequence point is stored in PBEFORE_SP. Everything else gets stored
1997 Once we return, we will have emitted warnings if any subexpression before
1998 such a sequence point could be undefined. On a higher level, however, the
1999 sequence point may not be relevant, and we'll merge the two lists.
2001 Example: (b++, a) + b;
2002 The call that processes the COMPOUND_EXPR will store the increment of B
2003 in PBEFORE_SP, and the use of A in PNO_SP. The higher-level call that
2004 processes the PLUS_EXPR will need to merge the two lists so that
2005 eventually, all accesses end up on the same list (and we'll warn about the
2006 unordered subexpressions b++ and b.
2008 A note on merging. If we modify the former example so that our expression
2011 care must be taken not simply to add all three expressions into the final
2012 PNO_SP list. The function merge_tlist takes care of that by merging the
2013 before-SP list of the COMPOUND_EXPR into its after-SP list in a special
2014 way, so that no more than one access to B is recorded. */
2017 verify_tree (tree x
, struct tlist
**pbefore_sp
, struct tlist
**pno_sp
,
2020 struct tlist
*tmp_before
, *tmp_nosp
, *tmp_list2
, *tmp_list3
;
2021 enum tree_code code
;
2022 enum tree_code_class cl
;
2025 /* X may be NULL if it is the operand of an empty statement expression
2030 code
= TREE_CODE (x
);
2031 cl
= TREE_CODE_CLASS (code
);
2033 if (warning_candidate_p (x
))
2034 *pno_sp
= new_tlist (*pno_sp
, x
, writer
);
2040 case PAREN_SIZEOF_EXPR
:
2044 case TRUTH_ANDIF_EXPR
:
2045 case TRUTH_ORIF_EXPR
:
2047 tmp_before
= tmp_nosp
= tmp_list2
= tmp_list3
= 0;
2048 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
2049 warn_for_collisions (tmp_nosp
);
2050 merge_tlist (pbefore_sp
, tmp_before
, 0);
2051 merge_tlist (pbefore_sp
, tmp_nosp
, 0);
2052 verify_tree (TREE_OPERAND (x
, 1), &tmp_list3
, &tmp_list2
, NULL_TREE
);
2053 warn_for_collisions (tmp_list2
);
2054 merge_tlist (pbefore_sp
, tmp_list3
, 0);
2055 merge_tlist (pno_sp
, tmp_list2
, 0);
2059 tmp_before
= tmp_list2
= 0;
2060 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_list2
, NULL_TREE
);
2061 warn_for_collisions (tmp_list2
);
2062 merge_tlist (pbefore_sp
, tmp_before
, 0);
2063 merge_tlist (pbefore_sp
, tmp_list2
, 0);
2065 tmp_list3
= tmp_nosp
= 0;
2066 verify_tree (TREE_OPERAND (x
, 1), &tmp_list3
, &tmp_nosp
, NULL_TREE
);
2067 warn_for_collisions (tmp_nosp
);
2068 merge_tlist (pbefore_sp
, tmp_list3
, 0);
2070 tmp_list3
= tmp_list2
= 0;
2071 verify_tree (TREE_OPERAND (x
, 2), &tmp_list3
, &tmp_list2
, NULL_TREE
);
2072 warn_for_collisions (tmp_list2
);
2073 merge_tlist (pbefore_sp
, tmp_list3
, 0);
2074 /* Rather than add both tmp_nosp and tmp_list2, we have to merge the
2075 two first, to avoid warning for (a ? b++ : b++). */
2076 merge_tlist (&tmp_nosp
, tmp_list2
, 0);
2077 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
2080 case PREDECREMENT_EXPR
:
2081 case PREINCREMENT_EXPR
:
2082 case POSTDECREMENT_EXPR
:
2083 case POSTINCREMENT_EXPR
:
2084 verify_tree (TREE_OPERAND (x
, 0), pno_sp
, pno_sp
, x
);
2088 tmp_before
= tmp_nosp
= tmp_list3
= 0;
2089 verify_tree (TREE_OPERAND (x
, 1), &tmp_before
, &tmp_nosp
, NULL_TREE
);
2090 verify_tree (TREE_OPERAND (x
, 0), &tmp_list3
, &tmp_list3
, x
);
2091 /* Expressions inside the LHS are not ordered wrt. the sequence points
2092 in the RHS. Example:
2094 Despite the fact that the modification of "a" is in the before_sp
2095 list (tmp_before), it conflicts with the use of "a" in the LHS.
2096 We can handle this by adding the contents of tmp_list3
2097 to those of tmp_before, and redoing the collision warnings for that
2099 add_tlist (&tmp_before
, tmp_list3
, x
, 1);
2100 warn_for_collisions (tmp_before
);
2101 /* Exclude the LHS itself here; we first have to merge it into the
2102 tmp_nosp list. This is done to avoid warning for "a = a"; if we
2103 didn't exclude the LHS, we'd get it twice, once as a read and once
2105 add_tlist (pno_sp
, tmp_list3
, x
, 0);
2106 warn_for_collisions_1 (TREE_OPERAND (x
, 0), x
, tmp_nosp
, 1);
2108 merge_tlist (pbefore_sp
, tmp_before
, 0);
2109 if (warning_candidate_p (TREE_OPERAND (x
, 0)))
2110 merge_tlist (&tmp_nosp
, new_tlist (NULL
, TREE_OPERAND (x
, 0), x
), 0);
2111 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 1);
2115 /* We need to warn about conflicts among arguments and conflicts between
2116 args and the function address. Side effects of the function address,
2117 however, are not ordered by the sequence point of the call. */
2119 call_expr_arg_iterator iter
;
2121 tmp_before
= tmp_nosp
= 0;
2122 verify_tree (CALL_EXPR_FN (x
), &tmp_before
, &tmp_nosp
, NULL_TREE
);
2123 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, x
)
2125 tmp_list2
= tmp_list3
= 0;
2126 verify_tree (arg
, &tmp_list2
, &tmp_list3
, NULL_TREE
);
2127 merge_tlist (&tmp_list3
, tmp_list2
, 0);
2128 add_tlist (&tmp_before
, tmp_list3
, NULL_TREE
, 0);
2130 add_tlist (&tmp_before
, tmp_nosp
, NULL_TREE
, 0);
2131 warn_for_collisions (tmp_before
);
2132 add_tlist (pbefore_sp
, tmp_before
, NULL_TREE
, 0);
2137 /* Scan all the list, e.g. indices of multi dimensional array. */
2140 tmp_before
= tmp_nosp
= 0;
2141 verify_tree (TREE_VALUE (x
), &tmp_before
, &tmp_nosp
, NULL_TREE
);
2142 merge_tlist (&tmp_nosp
, tmp_before
, 0);
2143 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
2150 struct tlist_cache
*t
;
2151 for (t
= save_expr_cache
; t
; t
= t
->next
)
2152 if (candidate_equal_p (t
->expr
, x
))
2157 t
= XOBNEW (&tlist_obstack
, struct tlist_cache
);
2158 t
->next
= save_expr_cache
;
2160 save_expr_cache
= t
;
2162 tmp_before
= tmp_nosp
= 0;
2163 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
2164 warn_for_collisions (tmp_nosp
);
2167 merge_tlist (&tmp_list3
, tmp_nosp
, 0);
2168 t
->cache_before_sp
= tmp_before
;
2169 t
->cache_after_sp
= tmp_list3
;
2171 merge_tlist (pbefore_sp
, t
->cache_before_sp
, 1);
2172 add_tlist (pno_sp
, t
->cache_after_sp
, NULL_TREE
, 1);
2177 x
= TREE_OPERAND (x
, 0);
2183 case VIEW_CONVERT_EXPR
:
2184 if (location_wrapper_p (x
))
2186 x
= TREE_OPERAND (x
, 0);
2195 if (cxx_dialect
>= cxx17
)
2196 goto sequenced_binary
;
2201 /* For other expressions, simply recurse on their operands.
2202 Manual tail recursion for unary expressions.
2203 Other non-expressions need not be processed. */
2204 if (cl
== tcc_unary
)
2206 x
= TREE_OPERAND (x
, 0);
2210 else if (IS_EXPR_CODE_CLASS (cl
))
2213 int max
= TREE_OPERAND_LENGTH (x
);
2214 for (lp
= 0; lp
< max
; lp
++)
2216 tmp_before
= tmp_nosp
= 0;
2217 verify_tree (TREE_OPERAND (x
, lp
), &tmp_before
, &tmp_nosp
, 0);
2218 merge_tlist (&tmp_nosp
, tmp_before
, 0);
2219 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
2226 static constexpr size_t verify_sequence_points_limit
= 1024;
2228 /* Called from verify_sequence_points via walk_tree. */
2231 verify_tree_lim_r (tree
*tp
, int *walk_subtrees
, void *data
)
2233 if (++*((size_t *) data
) > verify_sequence_points_limit
)
2234 return integer_zero_node
;
2242 /* Try to warn for undefined behavior in EXPR due to missing sequence
2246 verify_sequence_points (tree expr
)
2248 tlist
*before_sp
= nullptr, *after_sp
= nullptr;
2250 /* verify_tree is highly recursive, and merge_tlist is O(n^2),
2251 so we return early if the expression is too big. */
2253 if (walk_tree (&expr
, verify_tree_lim_r
, &n
, nullptr))
2256 warned_ids
= nullptr;
2257 save_expr_cache
= nullptr;
2258 if (!tlist_firstobj
)
2260 gcc_obstack_init (&tlist_obstack
);
2261 tlist_firstobj
= (char *) obstack_alloc (&tlist_obstack
, 0);
2264 verify_tree (expr
, &before_sp
, &after_sp
, NULL_TREE
);
2265 warn_for_collisions (after_sp
);
2266 obstack_free (&tlist_obstack
, tlist_firstobj
);
2269 /* Validate the expression after `case' and apply default promotions. */
2272 check_case_value (location_t loc
, tree value
)
2274 if (value
== NULL_TREE
)
2277 if (TREE_CODE (value
) == INTEGER_CST
)
2278 /* Promote char or short to int. */
2279 value
= perform_integral_promotions (value
);
2280 else if (value
!= error_mark_node
)
2282 error_at (loc
, "case label does not reduce to an integer constant");
2283 value
= error_mark_node
;
2286 constant_expression_warning (value
);
2291 /* Return an integer type with BITS bits of precision,
2292 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
2296 c_common_type_for_size (unsigned int bits
, int unsignedp
)
2300 gcc_assert(0 && "c_common");
2305 if (bits
== TYPE_PRECISION (integer_type_node
))
2306 return unsignedp
? unsigned_type_node
: integer_type_node
;
2308 if (bits
== TYPE_PRECISION (signed_char_type_node
))
2309 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
2311 if (bits
== TYPE_PRECISION (short_integer_type_node
))
2312 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
2314 if (bits
== TYPE_PRECISION (long_integer_type_node
))
2315 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
2317 if (bits
== TYPE_PRECISION (long_long_integer_type_node
))
2318 return (unsignedp
? long_long_unsigned_type_node
2319 : long_long_integer_type_node
);
2321 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
2322 if (int_n_enabled_p
[i
]
2323 && bits
== int_n_data
[i
].bitsize
)
2324 return (unsignedp
? int_n_trees
[i
].unsigned_type
2325 : int_n_trees
[i
].signed_type
);
2327 if (bits
== TYPE_PRECISION (widest_integer_literal_type_node
))
2328 return (unsignedp
? widest_unsigned_literal_type_node
2329 : widest_integer_literal_type_node
);
2331 if (bits
<= TYPE_PRECISION (intQI_type_node
))
2332 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
2334 if (bits
<= TYPE_PRECISION (intHI_type_node
))
2335 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
2337 if (bits
<= TYPE_PRECISION (intSI_type_node
))
2338 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
2340 if (bits
<= TYPE_PRECISION (intDI_type_node
))
2341 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
2348 /* Return a fixed-point type that has at least IBIT ibits and FBIT fbits
2349 that is unsigned if UNSIGNEDP is nonzero, otherwise signed;
2350 and saturating if SATP is nonzero, otherwise not saturating. */
2354 c_common_fixed_point_type_for_size (unsigned int ibit
, unsigned int fbit
,
2355 int unsignedp
, int satp
)
2357 enum mode_class mclass
;
2359 mclass
= unsignedp
? MODE_UFRACT
: MODE_FRACT
;
2361 mclass
= unsignedp
? MODE_UACCUM
: MODE_ACCUM
;
2363 opt_scalar_mode opt_mode
;
2365 FOR_EACH_MODE_IN_CLASS (opt_mode
, mclass
)
2367 mode
= opt_mode
.require ();
2368 if (GET_MODE_IBIT (mode
) >= ibit
&& GET_MODE_FBIT (mode
) >= fbit
)
2372 if (!opt_mode
.exists (&mode
) || !targetm
.scalar_mode_supported_p (mode
))
2374 sorry ("GCC cannot support operators with integer types and "
2375 "fixed-point types that have too many integral and "
2376 "fractional bits together");
2380 return c_common_type_for_mode (mode
, satp
);
2385 /* Used for communication between c_common_type_for_mode and
2386 c_register_builtin_type. */
2387 tree registered_builtin_types
;
2389 /* Return a data type that has machine mode MODE.
2390 If the mode is an integer,
2391 then UNSIGNEDP selects between signed and unsigned types.
2392 If the mode is a fixed-point mode,
2393 then UNSIGNEDP selects between saturating and nonsaturating types. */
2397 c_common_type_for_mode (machine_mode mode
, int unsignedp
)
2401 gcc_assert(0 && "c_common_type_for_mode");
2407 if (mode
== TYPE_MODE (integer_type_node
))
2408 return unsignedp
? unsigned_type_node
: integer_type_node
;
2410 if (mode
== TYPE_MODE (signed_char_type_node
))
2411 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
2413 if (mode
== TYPE_MODE (short_integer_type_node
))
2414 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
2416 if (mode
== TYPE_MODE (long_integer_type_node
))
2417 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
2419 if (mode
== TYPE_MODE (long_long_integer_type_node
))
2420 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
2422 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
2423 if (int_n_enabled_p
[i
]
2424 && mode
== int_n_data
[i
].m
)
2425 return (unsignedp
? int_n_trees
[i
].unsigned_type
2426 : int_n_trees
[i
].signed_type
);
2429 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
2432 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
2435 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
2438 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
2440 #if HOST_BITS_PER_WIDE_INT >= 64
2441 if (mode
== TYPE_MODE (intTI_type_node
))
2442 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
2445 if (mode
== TYPE_MODE (float_type_node
))
2446 return float_type_node
;
2448 if (mode
== TYPE_MODE (double_type_node
))
2449 return double_type_node
;
2451 if (mode
== TYPE_MODE (long_double_type_node
))
2452 return long_double_type_node
;
2454 for (i
= 0; i
< NUM_FLOATN_NX_TYPES
; i
++)
2455 if (FLOATN_NX_TYPE_NODE (i
) != NULL_TREE
2456 && mode
== TYPE_MODE (FLOATN_NX_TYPE_NODE (i
)))
2457 return FLOATN_NX_TYPE_NODE (i
);
2459 if (mode
== TYPE_MODE (void_type_node
))
2460 return void_type_node
;
2462 if (mode
== TYPE_MODE (build_pointer_type (char_type_node
))
2463 || mode
== TYPE_MODE (build_pointer_type (integer_type_node
)))
2465 unsigned int precision
2466 = GET_MODE_PRECISION (as_a
<scalar_int_mode
> (mode
));
2468 ? make_unsigned_type (precision
)
2469 : make_signed_type (precision
));
2472 if (COMPLEX_MODE_P (mode
))
2474 machine_mode inner_mode
;
2477 if (mode
== TYPE_MODE (complex_float_type_node
))
2478 return complex_float_type_node
;
2479 if (mode
== TYPE_MODE (complex_double_type_node
))
2480 return complex_double_type_node
;
2481 if (mode
== TYPE_MODE (complex_long_double_type_node
))
2482 return complex_long_double_type_node
;
2484 for (i
= 0; i
< NUM_FLOATN_NX_TYPES
; i
++)
2485 if (COMPLEX_FLOATN_NX_TYPE_NODE (i
) != NULL_TREE
2486 && mode
== TYPE_MODE (COMPLEX_FLOATN_NX_TYPE_NODE (i
)))
2487 return COMPLEX_FLOATN_NX_TYPE_NODE (i
);
2489 if (mode
== TYPE_MODE (complex_integer_type_node
) && !unsignedp
)
2490 return complex_integer_type_node
;
2492 inner_mode
= GET_MODE_INNER (mode
);
2493 inner_type
= c_common_type_for_mode (inner_mode
, unsignedp
);
2494 if (inner_type
!= NULL_TREE
)
2495 return build_complex_type (inner_type
);
2497 else if (GET_MODE_CLASS (mode
) == MODE_VECTOR_BOOL
2498 && valid_vector_subparts_p (GET_MODE_NUNITS (mode
)))
2500 unsigned int elem_bits
= vector_element_size (GET_MODE_BITSIZE (mode
),
2501 GET_MODE_NUNITS (mode
));
2502 tree bool_type
= build_nonstandard_boolean_type (elem_bits
);
2503 return build_vector_type_for_mode (bool_type
, mode
);
2505 else if (VECTOR_MODE_P (mode
)
2506 && valid_vector_subparts_p (GET_MODE_NUNITS (mode
)))
2508 machine_mode inner_mode
= GET_MODE_INNER (mode
);
2509 tree inner_type
= c_common_type_for_mode (inner_mode
, unsignedp
);
2510 if (inner_type
!= NULL_TREE
)
2511 return build_vector_type_for_mode (inner_type
, mode
);
2514 if (dfloat32_type_node
!= NULL_TREE
2515 && mode
== TYPE_MODE (dfloat32_type_node
))
2516 return dfloat32_type_node
;
2517 if (dfloat64_type_node
!= NULL_TREE
2518 && mode
== TYPE_MODE (dfloat64_type_node
))
2519 return dfloat64_type_node
;
2520 if (dfloat128_type_node
!= NULL_TREE
2521 && mode
== TYPE_MODE (dfloat128_type_node
))
2522 return dfloat128_type_node
;
2524 if (ALL_SCALAR_FIXED_POINT_MODE_P (mode
))
2526 if (mode
== TYPE_MODE (short_fract_type_node
))
2527 return unsignedp
? sat_short_fract_type_node
: short_fract_type_node
;
2528 if (mode
== TYPE_MODE (fract_type_node
))
2529 return unsignedp
? sat_fract_type_node
: fract_type_node
;
2530 if (mode
== TYPE_MODE (long_fract_type_node
))
2531 return unsignedp
? sat_long_fract_type_node
: long_fract_type_node
;
2532 if (mode
== TYPE_MODE (long_long_fract_type_node
))
2533 return unsignedp
? sat_long_long_fract_type_node
2534 : long_long_fract_type_node
;
2536 if (mode
== TYPE_MODE (unsigned_short_fract_type_node
))
2537 return unsignedp
? sat_unsigned_short_fract_type_node
2538 : unsigned_short_fract_type_node
;
2539 if (mode
== TYPE_MODE (unsigned_fract_type_node
))
2540 return unsignedp
? sat_unsigned_fract_type_node
2541 : unsigned_fract_type_node
;
2542 if (mode
== TYPE_MODE (unsigned_long_fract_type_node
))
2543 return unsignedp
? sat_unsigned_long_fract_type_node
2544 : unsigned_long_fract_type_node
;
2545 if (mode
== TYPE_MODE (unsigned_long_long_fract_type_node
))
2546 return unsignedp
? sat_unsigned_long_long_fract_type_node
2547 : unsigned_long_long_fract_type_node
;
2549 if (mode
== TYPE_MODE (short_accum_type_node
))
2550 return unsignedp
? sat_short_accum_type_node
: short_accum_type_node
;
2551 if (mode
== TYPE_MODE (accum_type_node
))
2552 return unsignedp
? sat_accum_type_node
: accum_type_node
;
2553 if (mode
== TYPE_MODE (long_accum_type_node
))
2554 return unsignedp
? sat_long_accum_type_node
: long_accum_type_node
;
2555 if (mode
== TYPE_MODE (long_long_accum_type_node
))
2556 return unsignedp
? sat_long_long_accum_type_node
2557 : long_long_accum_type_node
;
2559 if (mode
== TYPE_MODE (unsigned_short_accum_type_node
))
2560 return unsignedp
? sat_unsigned_short_accum_type_node
2561 : unsigned_short_accum_type_node
;
2562 if (mode
== TYPE_MODE (unsigned_accum_type_node
))
2563 return unsignedp
? sat_unsigned_accum_type_node
2564 : unsigned_accum_type_node
;
2565 if (mode
== TYPE_MODE (unsigned_long_accum_type_node
))
2566 return unsignedp
? sat_unsigned_long_accum_type_node
2567 : unsigned_long_accum_type_node
;
2568 if (mode
== TYPE_MODE (unsigned_long_long_accum_type_node
))
2569 return unsignedp
? sat_unsigned_long_long_accum_type_node
2570 : unsigned_long_long_accum_type_node
;
2573 return unsignedp
? sat_qq_type_node
: qq_type_node
;
2575 return unsignedp
? sat_hq_type_node
: hq_type_node
;
2577 return unsignedp
? sat_sq_type_node
: sq_type_node
;
2579 return unsignedp
? sat_dq_type_node
: dq_type_node
;
2581 return unsignedp
? sat_tq_type_node
: tq_type_node
;
2583 if (mode
== UQQmode
)
2584 return unsignedp
? sat_uqq_type_node
: uqq_type_node
;
2585 if (mode
== UHQmode
)
2586 return unsignedp
? sat_uhq_type_node
: uhq_type_node
;
2587 if (mode
== USQmode
)
2588 return unsignedp
? sat_usq_type_node
: usq_type_node
;
2589 if (mode
== UDQmode
)
2590 return unsignedp
? sat_udq_type_node
: udq_type_node
;
2591 if (mode
== UTQmode
)
2592 return unsignedp
? sat_utq_type_node
: utq_type_node
;
2595 return unsignedp
? sat_ha_type_node
: ha_type_node
;
2597 return unsignedp
? sat_sa_type_node
: sa_type_node
;
2599 return unsignedp
? sat_da_type_node
: da_type_node
;
2601 return unsignedp
? sat_ta_type_node
: ta_type_node
;
2603 if (mode
== UHAmode
)
2604 return unsignedp
? sat_uha_type_node
: uha_type_node
;
2605 if (mode
== USAmode
)
2606 return unsignedp
? sat_usa_type_node
: usa_type_node
;
2607 if (mode
== UDAmode
)
2608 return unsignedp
? sat_uda_type_node
: uda_type_node
;
2609 if (mode
== UTAmode
)
2610 return unsignedp
? sat_uta_type_node
: uta_type_node
;
2613 for (t
= registered_builtin_types
; t
; t
= TREE_CHAIN (t
))
2615 tree type
= TREE_VALUE (t
);
2616 if (TYPE_MODE (type
) == mode
2617 && VECTOR_TYPE_P (type
) == VECTOR_MODE_P (mode
)
2618 && !!unsignedp
== !!TYPE_UNSIGNED (type
))
2627 c_common_unsigned_type (tree type
)
2629 return c_common_signed_or_unsigned_type (1, type
);
2632 /* Return a signed type the same as TYPE in other respects. */
2635 c_common_signed_type (tree type
)
2637 return c_common_signed_or_unsigned_type (0, type
);
2640 /* Return a type the same as TYPE except unsigned or
2641 signed according to UNSIGNEDP. */
2644 c_common_signed_or_unsigned_type (int unsignedp
, tree type
)
2648 gcc_assert(0 && "c_common_signed_or_unsigned_type");
2654 /* This block of code emulates the behavior of the old
2655 c_common_unsigned_type. In particular, it returns
2656 long_unsigned_type_node if passed a long, even when a int would
2657 have the same size. This is necessary for warnings to work
2658 correctly in archs where sizeof(int) == sizeof(long) */
2660 type1
= TYPE_MAIN_VARIANT (type
);
2661 if (type1
== signed_char_type_node
|| type1
== char_type_node
|| type1
== unsigned_char_type_node
)
2662 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
2663 if (type1
== integer_type_node
|| type1
== unsigned_type_node
)
2664 return unsignedp
? unsigned_type_node
: integer_type_node
;
2665 if (type1
== short_integer_type_node
|| type1
== short_unsigned_type_node
)
2666 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
2667 if (type1
== long_integer_type_node
|| type1
== long_unsigned_type_node
)
2668 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
2669 if (type1
== long_long_integer_type_node
|| type1
== long_long_unsigned_type_node
)
2670 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
2672 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
2673 if (int_n_enabled_p
[i
]
2674 && (type1
== int_n_trees
[i
].unsigned_type
2675 || type1
== int_n_trees
[i
].signed_type
))
2676 return (unsignedp
? int_n_trees
[i
].unsigned_type
2677 : int_n_trees
[i
].signed_type
);
2679 #if HOST_BITS_PER_WIDE_INT >= 64
2680 if (type1
== intTI_type_node
|| type1
== unsigned_intTI_type_node
)
2681 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
2683 if (type1
== intDI_type_node
|| type1
== unsigned_intDI_type_node
)
2684 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
2685 if (type1
== intSI_type_node
|| type1
== unsigned_intSI_type_node
)
2686 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
2687 if (type1
== intHI_type_node
|| type1
== unsigned_intHI_type_node
)
2688 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
2689 if (type1
== intQI_type_node
|| type1
== unsigned_intQI_type_node
)
2690 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
2692 #define C_COMMON_FIXED_TYPES(NAME) \
2693 if (type1 == short_ ## NAME ## _type_node \
2694 || type1 == unsigned_short_ ## NAME ## _type_node) \
2695 return unsignedp ? unsigned_short_ ## NAME ## _type_node \
2696 : short_ ## NAME ## _type_node; \
2697 if (type1 == NAME ## _type_node \
2698 || type1 == unsigned_ ## NAME ## _type_node) \
2699 return unsignedp ? unsigned_ ## NAME ## _type_node \
2700 : NAME ## _type_node; \
2701 if (type1 == long_ ## NAME ## _type_node \
2702 || type1 == unsigned_long_ ## NAME ## _type_node) \
2703 return unsignedp ? unsigned_long_ ## NAME ## _type_node \
2704 : long_ ## NAME ## _type_node; \
2705 if (type1 == long_long_ ## NAME ## _type_node \
2706 || type1 == unsigned_long_long_ ## NAME ## _type_node) \
2707 return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \
2708 : long_long_ ## NAME ## _type_node;
2710 #define C_COMMON_FIXED_MODE_TYPES(NAME) \
2711 if (type1 == NAME ## _type_node \
2712 || type1 == u ## NAME ## _type_node) \
2713 return unsignedp ? u ## NAME ## _type_node \
2714 : NAME ## _type_node;
2716 #define C_COMMON_FIXED_TYPES_SAT(NAME) \
2717 if (type1 == sat_ ## short_ ## NAME ## _type_node \
2718 || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \
2719 return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \
2720 : sat_ ## short_ ## NAME ## _type_node; \
2721 if (type1 == sat_ ## NAME ## _type_node \
2722 || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \
2723 return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \
2724 : sat_ ## NAME ## _type_node; \
2725 if (type1 == sat_ ## long_ ## NAME ## _type_node \
2726 || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \
2727 return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \
2728 : sat_ ## long_ ## NAME ## _type_node; \
2729 if (type1 == sat_ ## long_long_ ## NAME ## _type_node \
2730 || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \
2731 return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \
2732 : sat_ ## long_long_ ## NAME ## _type_node;
2734 #define C_COMMON_FIXED_MODE_TYPES_SAT(NAME) \
2735 if (type1 == sat_ ## NAME ## _type_node \
2736 || type1 == sat_ ## u ## NAME ## _type_node) \
2737 return unsignedp ? sat_ ## u ## NAME ## _type_node \
2738 : sat_ ## NAME ## _type_node;
2740 C_COMMON_FIXED_TYPES (fract
);
2741 C_COMMON_FIXED_TYPES_SAT (fract
);
2742 C_COMMON_FIXED_TYPES (accum
);
2743 C_COMMON_FIXED_TYPES_SAT (accum
);
2745 C_COMMON_FIXED_MODE_TYPES (qq
);
2746 C_COMMON_FIXED_MODE_TYPES (hq
);
2747 C_COMMON_FIXED_MODE_TYPES (sq
);
2748 C_COMMON_FIXED_MODE_TYPES (dq
);
2749 C_COMMON_FIXED_MODE_TYPES (tq
);
2750 C_COMMON_FIXED_MODE_TYPES_SAT (qq
);
2751 C_COMMON_FIXED_MODE_TYPES_SAT (hq
);
2752 C_COMMON_FIXED_MODE_TYPES_SAT (sq
);
2753 C_COMMON_FIXED_MODE_TYPES_SAT (dq
);
2754 C_COMMON_FIXED_MODE_TYPES_SAT (tq
);
2755 C_COMMON_FIXED_MODE_TYPES (ha
);
2756 C_COMMON_FIXED_MODE_TYPES (sa
);
2757 C_COMMON_FIXED_MODE_TYPES (da
);
2758 C_COMMON_FIXED_MODE_TYPES (ta
);
2759 C_COMMON_FIXED_MODE_TYPES_SAT (ha
);
2760 C_COMMON_FIXED_MODE_TYPES_SAT (sa
);
2761 C_COMMON_FIXED_MODE_TYPES_SAT (da
);
2762 C_COMMON_FIXED_MODE_TYPES_SAT (ta
);
2764 /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not
2765 the precision; they have precision set to match their range, but
2766 may use a wider mode to match an ABI. If we change modes, we may
2767 wind up with bad conversions. For INTEGER_TYPEs in C, must check
2768 the precision as well, so as to yield correct results for
2769 bit-field types. C++ does not have these separate bit-field
2770 types, and producing a signed or unsigned variant of an
2771 ENUMERAL_TYPE may cause other problems as well. */
2773 if (!INTEGRAL_TYPE_P (type
)
2774 || TYPE_UNSIGNED (type
) == unsignedp
)
2777 #define TYPE_OK(node) \
2778 (TYPE_MODE (type) == TYPE_MODE (node) \
2779 && TYPE_PRECISION (type) == TYPE_PRECISION (node))
2780 if (TYPE_OK (signed_char_type_node
))
2781 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
2782 if (TYPE_OK (integer_type_node
))
2783 return unsignedp
? unsigned_type_node
: integer_type_node
;
2784 if (TYPE_OK (short_integer_type_node
))
2785 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
2786 if (TYPE_OK (long_integer_type_node
))
2787 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
2788 if (TYPE_OK (long_long_integer_type_node
))
2789 return (unsignedp
? long_long_unsigned_type_node
2790 : long_long_integer_type_node
);
2792 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
2793 if (int_n_enabled_p
[i
]
2794 && TYPE_MODE (type
) == int_n_data
[i
].m
2795 && TYPE_PRECISION (type
) == int_n_data
[i
].bitsize
)
2796 return (unsignedp
? int_n_trees
[i
].unsigned_type
2797 : int_n_trees
[i
].signed_type
);
2799 #if HOST_BITS_PER_WIDE_INT >= 64
2800 if (TYPE_OK (intTI_type_node
))
2801 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
2803 if (TYPE_OK (intDI_type_node
))
2804 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
2805 if (TYPE_OK (intSI_type_node
))
2806 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
2807 if (TYPE_OK (intHI_type_node
))
2808 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
2809 if (TYPE_OK (intQI_type_node
))
2810 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
2813 return build_nonstandard_integer_type (TYPE_PRECISION (type
), unsignedp
);
2817 /* Build a bit-field integer type for the given WIDTH and UNSIGNEDP. */
2821 c_build_bitfield_integer_type (unsigned HOST_WIDE_INT width
, int unsignedp
)
2825 /* Extended integer types of the same width as a standard type have
2826 lesser rank, so those of the same width as int promote to int or
2827 unsigned int and are valid for printf formats expecting int or
2828 unsigned int. To avoid such special cases, avoid creating
2829 extended integer types for bit-fields if a standard integer type
2831 if (width
== TYPE_PRECISION (integer_type_node
))
2832 return unsignedp
? unsigned_type_node
: integer_type_node
;
2833 if (width
== TYPE_PRECISION (signed_char_type_node
))
2834 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
2835 if (width
== TYPE_PRECISION (short_integer_type_node
))
2836 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
2837 if (width
== TYPE_PRECISION (long_integer_type_node
))
2838 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
2839 if (width
== TYPE_PRECISION (long_long_integer_type_node
))
2840 return (unsignedp
? long_long_unsigned_type_node
2841 : long_long_integer_type_node
);
2842 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
2843 if (int_n_enabled_p
[i
]
2844 && width
== int_n_data
[i
].bitsize
)
2845 return (unsignedp
? int_n_trees
[i
].unsigned_type
2846 : int_n_trees
[i
].signed_type
);
2847 return build_nonstandard_integer_type (width
, unsignedp
);
2851 /* The C version of the register_builtin_type langhook. */
2855 c_register_builtin_type (tree type
, const char* name
)
2859 fprintf(stderr
, "incomplete %s %d\n", __func__
, __LINE__
);
2863 decl
= build_decl (UNKNOWN_LOCATION
,
2864 TYPE_DECL
, get_identifier (name
), type
);
2865 DECL_ARTIFICIAL (decl
) = 1;
2866 if (!TYPE_NAME (type
))
2867 TYPE_NAME (type
) = decl
;
2868 lang_hooks
.decls
.pushdecl (decl
);
2870 registered_builtin_types
= tree_cons (0, type
, registered_builtin_types
);
2875 /* Print an error message for invalid operands to arith operation
2876 CODE with TYPE0 for operand 0, and TYPE1 for operand 1.
2877 RICHLOC is a rich location for the message, containing either
2878 three separate locations for each of the operator and operands
2883 (C FE), or one location ranging over all over them
2891 binary_op_error (rich_location
*richloc
, enum tree_code code
,
2892 tree type0
, tree type1
)
2899 opname
= "+"; break;
2901 opname
= "-"; break;
2903 opname
= "*"; break;
2905 opname
= "max"; break;
2907 opname
= "min"; break;
2909 opname
= "=="; break;
2911 opname
= "!="; break;
2913 opname
= "<="; break;
2915 opname
= ">="; break;
2917 opname
= "<"; break;
2919 opname
= ">"; break;
2921 opname
= "<<"; break;
2923 opname
= ">>"; break;
2924 case TRUNC_MOD_EXPR
:
2925 case FLOOR_MOD_EXPR
:
2926 opname
= "%"; break;
2927 case TRUNC_DIV_EXPR
:
2928 case FLOOR_DIV_EXPR
:
2929 opname
= "/"; break;
2931 opname
= "&"; break;
2933 opname
= "|"; break;
2934 case TRUTH_ANDIF_EXPR
:
2935 opname
= "&&"; break;
2936 case TRUTH_ORIF_EXPR
:
2937 opname
= "||"; break;
2939 opname
= "^"; break;
2944 "invalid operands to binary %s (have %qT and %qT)",
2945 opname
, type0
, type1
);
2948 /* Given an expression as a tree, return its original type. Do this
2949 by stripping any conversion that preserves the sign and precision. */
2951 expr_original_type (tree expr
)
2953 STRIP_SIGN_NOPS (expr
);
2954 return TREE_TYPE (expr
);
2957 /* Subroutine of build_binary_op, used for comparison operations.
2958 See if the operands have both been converted from subword integer types
2959 and, if so, perhaps change them both back to their original type.
2960 This function is also responsible for converting the two operands
2961 to the proper common type for comparison.
2963 The arguments of this function are all pointers to local variables
2964 of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1,
2965 RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
2967 LOC is the location of the comparison.
2969 If this function returns non-NULL_TREE, it means that the comparison has
2970 a constant value. What this function returns is an expression for
2975 shorten_compare (location_t loc
, tree
*op0_ptr
, tree
*op1_ptr
,
2976 tree
*restype_ptr
, enum tree_code
*rescode_ptr
)
2979 tree op0
= *op0_ptr
;
2980 tree op1
= *op1_ptr
;
2981 int unsignedp0
, unsignedp1
;
2983 tree primop0
, primop1
;
2984 enum tree_code code
= *rescode_ptr
;
2986 /* Throw away any conversions to wider types
2987 already present in the operands. */
2989 primop0
= c_common_get_narrower (op0
, &unsignedp0
);
2990 primop1
= c_common_get_narrower (op1
, &unsignedp1
);
2992 /* If primopN is first sign-extended from primopN's precision to opN's
2993 precision, then zero-extended from opN's precision to
2994 *restype_ptr precision, shortenings might be invalid. */
2995 if (TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (TREE_TYPE (op0
))
2996 && TYPE_PRECISION (TREE_TYPE (op0
)) < TYPE_PRECISION (*restype_ptr
)
2998 && TYPE_UNSIGNED (TREE_TYPE (op0
)))
3000 if (TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (TREE_TYPE (op1
))
3001 && TYPE_PRECISION (TREE_TYPE (op1
)) < TYPE_PRECISION (*restype_ptr
)
3003 && TYPE_UNSIGNED (TREE_TYPE (op1
)))
3006 /* Handle the case that OP0 does not *contain* a conversion
3007 but it *requires* conversion to FINAL_TYPE. */
3009 if (op0
== primop0
&& TREE_TYPE (op0
) != *restype_ptr
)
3010 unsignedp0
= TYPE_UNSIGNED (TREE_TYPE (op0
));
3011 if (op1
== primop1
&& TREE_TYPE (op1
) != *restype_ptr
)
3012 unsignedp1
= TYPE_UNSIGNED (TREE_TYPE (op1
));
3014 /* If one of the operands must be floated, we cannot optimize. */
3015 real1
= TREE_CODE (TREE_TYPE (primop0
)) == REAL_TYPE
;
3016 real2
= TREE_CODE (TREE_TYPE (primop1
)) == REAL_TYPE
;
3018 /* If first arg is constant, swap the args (changing operation
3019 so value is preserved), for canonicalization. Don't do this if
3020 the second arg is 0. */
3022 if (TREE_CONSTANT (primop0
)
3023 && !integer_zerop (primop1
) && !real_zerop (primop1
)
3024 && !fixed_zerop (primop1
))
3026 std::swap (primop0
, primop1
);
3027 std::swap (op0
, op1
);
3030 std::swap (unsignedp0
, unsignedp1
);
3031 std::swap (real1
, real2
);
3050 *rescode_ptr
= code
;
3053 /* If comparing an integer against a constant more bits wide,
3054 maybe we can deduce a value of 1 or 0 independent of the data.
3055 Or else truncate the constant now
3056 rather than extend the variable at run time.
3058 This is only interesting if the constant is the wider arg.
3059 Also, it is not safe if the constant is unsigned and the
3060 variable arg is signed, since in this case the variable
3061 would be sign-extended and then regarded as unsigned.
3062 Our technique fails in this case because the lowest/highest
3063 possible unsigned results don't follow naturally from the
3064 lowest/highest possible values of the variable operand.
3065 For just EQ_EXPR and NE_EXPR there is another technique that
3066 could be used: see if the constant can be faithfully represented
3067 in the other operand's type, by truncating it and reextending it
3068 and see if that preserves the constant's value. */
3070 if (!real1
&& !real2
3071 && TREE_CODE (TREE_TYPE (primop0
)) != FIXED_POINT_TYPE
3072 && TREE_CODE (primop1
) == INTEGER_CST
3073 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
))
3075 int min_gt
, max_gt
, min_lt
, max_lt
;
3076 tree maxval
, minval
;
3077 /* 1 if comparison is nominally unsigned. */
3078 int unsignedp
= TYPE_UNSIGNED (*restype_ptr
);
3081 type
= c_common_signed_or_unsigned_type (unsignedp0
,
3082 TREE_TYPE (primop0
));
3084 maxval
= TYPE_MAX_VALUE (type
);
3085 minval
= TYPE_MIN_VALUE (type
);
3087 if (unsignedp
&& !unsignedp0
)
3088 *restype_ptr
= c_common_signed_type (*restype_ptr
);
3090 if (TREE_TYPE (primop1
) != *restype_ptr
)
3092 /* Convert primop1 to target type, but do not introduce
3093 additional overflow. We know primop1 is an int_cst. */
3094 primop1
= force_fit_type (*restype_ptr
,
3097 TYPE_PRECISION (*restype_ptr
)),
3098 0, TREE_OVERFLOW (primop1
));
3100 if (type
!= *restype_ptr
)
3102 minval
= convert (*restype_ptr
, minval
);
3103 maxval
= convert (*restype_ptr
, maxval
);
3106 min_gt
= tree_int_cst_lt (primop1
, minval
);
3107 max_gt
= tree_int_cst_lt (primop1
, maxval
);
3108 min_lt
= tree_int_cst_lt (minval
, primop1
);
3109 max_lt
= tree_int_cst_lt (maxval
, primop1
);
3112 /* This used to be a switch, but Genix compiler can't handle that. */
3113 if (code
== NE_EXPR
)
3115 if (max_lt
|| min_gt
)
3116 val
= truthvalue_true_node
;
3118 else if (code
== EQ_EXPR
)
3120 if (max_lt
|| min_gt
)
3121 val
= truthvalue_false_node
;
3123 else if (code
== LT_EXPR
)
3126 val
= truthvalue_true_node
;
3128 val
= truthvalue_false_node
;
3130 else if (code
== GT_EXPR
)
3133 val
= truthvalue_true_node
;
3135 val
= truthvalue_false_node
;
3137 else if (code
== LE_EXPR
)
3140 val
= truthvalue_true_node
;
3142 val
= truthvalue_false_node
;
3144 else if (code
== GE_EXPR
)
3147 val
= truthvalue_true_node
;
3149 val
= truthvalue_false_node
;
3152 /* If primop0 was sign-extended and unsigned comparison specd,
3153 we did a signed comparison above using the signed type bounds.
3154 But the comparison we output must be unsigned.
3156 Also, for inequalities, VAL is no good; but if the signed
3157 comparison had *any* fixed result, it follows that the
3158 unsigned comparison just tests the sign in reverse
3159 (positive values are LE, negative ones GE).
3160 So we can generate an unsigned comparison
3161 against an extreme value of the signed type. */
3163 if (unsignedp
&& !unsignedp0
)
3170 primop1
= TYPE_MIN_VALUE (type
);
3176 primop1
= TYPE_MAX_VALUE (type
);
3183 type
= c_common_unsigned_type (type
);
3186 if (TREE_CODE (primop0
) != INTEGER_CST
3187 /* Don't warn if it's from a (non-system) macro. */
3188 && !(from_macro_expansion_at
3189 (expansion_point_location_if_in_system_header
3190 (EXPR_LOCATION (primop0
)))))
3192 if (val
== truthvalue_false_node
)
3193 warning_at (loc
, OPT_Wtype_limits
,
3194 "comparison is always false due to limited range of data type");
3195 if (val
== truthvalue_true_node
)
3196 warning_at (loc
, OPT_Wtype_limits
,
3197 "comparison is always true due to limited range of data type");
3202 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
3203 if (TREE_SIDE_EFFECTS (primop0
))
3204 return build2 (COMPOUND_EXPR
, TREE_TYPE (val
), primop0
, val
);
3208 /* Value is not predetermined, but do the comparison
3209 in the type of the operand that is not constant.
3210 TYPE is already properly set. */
3213 /* If either arg is decimal float and the other is float, find the
3214 proper common type to use for comparison. */
3215 else if (real1
&& real2
3216 && DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0
)))
3217 && DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1
))))
3218 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
3220 /* If either arg is decimal float and the other is float, fail. */
3221 else if (real1
&& real2
3222 && (DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0
)))
3223 || DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1
)))))
3225 type
= *restype_ptr
;
3230 else if (real1
&& real2
3231 && (TYPE_PRECISION (TREE_TYPE (primop0
))
3232 == TYPE_PRECISION (TREE_TYPE (primop1
))))
3233 type
= TREE_TYPE (primop0
);
3235 /* If args' natural types are both narrower than nominal type
3236 and both extend in the same manner, compare them
3237 in the type of the wider arg.
3238 Otherwise must actually extend both to the nominal
3239 common type lest different ways of extending
3241 (eg, (short)-1 == (unsigned short)-1 should be 0.) */
3243 else if (unsignedp0
== unsignedp1
&& real1
== real2
3244 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
)
3245 && TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (*restype_ptr
))
3247 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
3248 type
= c_common_signed_or_unsigned_type (unsignedp0
3249 || TYPE_UNSIGNED (*restype_ptr
),
3251 /* Make sure shorter operand is extended the right way
3252 to match the longer operand. */
3254 = convert (c_common_signed_or_unsigned_type (unsignedp0
,
3255 TREE_TYPE (primop0
)),
3258 = convert (c_common_signed_or_unsigned_type (unsignedp1
,
3259 TREE_TYPE (primop1
)),
3264 /* Here we must do the comparison on the nominal type
3265 using the args exactly as we received them. */
3266 type
= *restype_ptr
;
3270 /* We want to fold unsigned comparisons of >= and < against zero.
3271 For these, we may also issue a warning if we have a non-constant
3272 compared against zero, where the zero was spelled as "0" (rather
3273 than merely folding to it).
3274 If we have at least one constant, then op1 is constant
3275 and we may have a non-constant expression as op0. */
3276 if (!real1
&& !real2
&& integer_zerop (primop1
)
3277 && TYPE_UNSIGNED (*restype_ptr
))
3279 tree value
= NULL_TREE
;
3280 /* All unsigned values are >= 0, so we warn. However,
3281 if OP0 is a constant that is >= 0, the signedness of
3282 the comparison isn't an issue, so suppress the
3284 tree folded_op0
= fold_for_warn (op0
);
3286 warn_type_limits
&& !in_system_header_at (loc
)
3287 && !(TREE_CODE (folded_op0
) == INTEGER_CST
3288 && !TREE_OVERFLOW (convert (c_common_signed_type (type
),
3290 /* Do not warn for enumeration types. */
3291 && (TREE_CODE (expr_original_type (folded_op0
)) != ENUMERAL_TYPE
);
3297 warning_at (loc
, OPT_Wtype_limits
,
3298 "comparison of unsigned expression in %<>= 0%> "
3300 value
= truthvalue_true_node
;
3305 warning_at (loc
, OPT_Wtype_limits
,
3306 "comparison of unsigned expression in %<< 0%> "
3308 value
= truthvalue_false_node
;
3315 if (value
!= NULL_TREE
)
3317 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
3318 if (TREE_SIDE_EFFECTS (primop0
))
3319 return build2 (COMPOUND_EXPR
, TREE_TYPE (value
),
3326 *op0_ptr
= convert (type
, primop0
);
3327 *op1_ptr
= convert (type
, primop1
);
3329 *restype_ptr
= truthvalue_type_node
;
3334 /* Return a tree for the sum or difference (RESULTCODE says which)
3335 of pointer PTROP and integer INTOP. */
3338 pointer_int_sum (location_t loc
, enum tree_code resultcode
,
3339 tree ptrop
, tree intop
, bool complain
)
3343 /* The result is a pointer of the same type that is being added. */
3344 tree result_type
= TREE_TYPE (ptrop
);
3346 if (TREE_CODE (TREE_TYPE (result_type
)) == VOID_TYPE
)
3348 if (complain
&& warn_pointer_arith
)
3349 pedwarn (loc
, OPT_Wpointer_arith
,
3350 "pointer of type %<void *%> used in arithmetic");
3352 return error_mark_node
;
3353 size_exp
= integer_one_node
;
3355 else if (TREE_CODE (TREE_TYPE (result_type
)) == FUNCTION_TYPE
)
3357 if (complain
&& warn_pointer_arith
)
3358 pedwarn (loc
, OPT_Wpointer_arith
,
3359 "pointer to a function used in arithmetic");
3361 return error_mark_node
;
3362 size_exp
= integer_one_node
;
3364 else if (!verify_type_context (loc
, TCTX_POINTER_ARITH
,
3365 TREE_TYPE (result_type
)))
3366 size_exp
= integer_one_node
;
3369 if (!complain
&& !COMPLETE_TYPE_P (TREE_TYPE (result_type
)))
3370 return error_mark_node
;
3371 size_exp
= size_in_bytes_loc (loc
, TREE_TYPE (result_type
));
3372 /* Wrap the pointer expression in a SAVE_EXPR to make sure it
3373 is evaluated first when the size expression may depend
3374 on it for VM types. */
3375 if (TREE_SIDE_EFFECTS (size_exp
)
3376 && TREE_SIDE_EFFECTS (ptrop
)
3377 && variably_modified_type_p (TREE_TYPE (ptrop
), NULL
))
3379 ptrop
= save_expr (ptrop
);
3380 size_exp
= build2 (COMPOUND_EXPR
, TREE_TYPE (intop
), ptrop
, size_exp
);
3384 /* We are manipulating pointer values, so we don't need to warn
3385 about relying on undefined signed overflow. We disable the
3386 warning here because we use integer types so fold won't know that
3387 they are really pointers. */
3388 fold_defer_overflow_warnings ();
3390 /* If what we are about to multiply by the size of the elements
3391 contains a constant term, apply distributive law
3392 and multiply that constant term separately.
3393 This helps produce common subexpressions. */
3394 if ((TREE_CODE (intop
) == PLUS_EXPR
|| TREE_CODE (intop
) == MINUS_EXPR
)
3395 && !TREE_CONSTANT (intop
)
3396 && TREE_CONSTANT (TREE_OPERAND (intop
, 1))
3397 && TREE_CONSTANT (size_exp
)
3398 /* If the constant comes from pointer subtraction,
3399 skip this optimization--it would cause an error. */
3400 && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop
, 0))) == INTEGER_TYPE
3401 /* If the constant is unsigned, and smaller than the pointer size,
3402 then we must skip this optimization. This is because it could cause
3403 an overflow error if the constant is negative but INTOP is not. */
3404 && (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (intop
))
3405 || (TYPE_PRECISION (TREE_TYPE (intop
))
3406 == TYPE_PRECISION (TREE_TYPE (ptrop
)))))
3408 enum tree_code subcode
= resultcode
;
3409 tree int_type
= TREE_TYPE (intop
);
3410 if (TREE_CODE (intop
) == MINUS_EXPR
)
3411 subcode
= (subcode
== PLUS_EXPR
? MINUS_EXPR
: PLUS_EXPR
);
3412 /* Convert both subexpression types to the type of intop,
3413 because weird cases involving pointer arithmetic
3414 can result in a sum or difference with different type args. */
3415 ptrop
= build_binary_op (EXPR_LOCATION (TREE_OPERAND (intop
, 1)),
3417 convert (int_type
, TREE_OPERAND (intop
, 1)),
3419 intop
= convert (int_type
, TREE_OPERAND (intop
, 0));
3422 /* Convert the integer argument to a type the same size as sizetype
3423 so the multiply won't overflow spuriously. */
3424 if (TYPE_PRECISION (TREE_TYPE (intop
)) != TYPE_PRECISION (sizetype
)
3425 || TYPE_UNSIGNED (TREE_TYPE (intop
)) != TYPE_UNSIGNED (sizetype
))
3426 intop
= convert (c_common_type_for_size (TYPE_PRECISION (sizetype
),
3427 TYPE_UNSIGNED (sizetype
)), intop
);
3429 /* Replace the integer argument with a suitable product by the object size.
3430 Do this multiplication as signed, then convert to the appropriate type
3431 for the pointer operation and disregard an overflow that occurred only
3432 because of the sign-extension change in the latter conversion. */
3434 tree t
= fold_build2_loc (loc
, MULT_EXPR
, TREE_TYPE (intop
), intop
,
3435 convert (TREE_TYPE (intop
), size_exp
));
3436 intop
= convert (sizetype
, t
);
3437 if (TREE_OVERFLOW_P (intop
) && !TREE_OVERFLOW (t
))
3438 intop
= wide_int_to_tree (TREE_TYPE (intop
), wi::to_wide (intop
));
3441 /* Create the sum or difference. */
3442 if (resultcode
== MINUS_EXPR
)
3443 intop
= fold_build1_loc (loc
, NEGATE_EXPR
, sizetype
, intop
);
3445 ret
= fold_build_pointer_plus_loc (loc
, ptrop
, intop
);
3447 fold_undefer_and_ignore_overflow_warnings ();
3453 /* Wrap a C_MAYBE_CONST_EXPR around an expression that is fully folded
3454 and if NON_CONST is known not to be permitted in an evaluated part
3455 of a constant expression. */
3458 c_wrap_maybe_const (tree expr
, bool non_const
)
3460 location_t loc
= EXPR_LOCATION (expr
);
3462 /* This should never be called for C++. */
3463 if (c_dialect_cxx ())
3466 /* The result of folding may have a NOP_EXPR to set TREE_NO_WARNING. */
3467 STRIP_TYPE_NOPS (expr
);
3468 expr
= build2 (C_MAYBE_CONST_EXPR
, TREE_TYPE (expr
), NULL
, expr
);
3469 C_MAYBE_CONST_EXPR_NON_CONST (expr
) = non_const
;
3470 protected_set_expr_location (expr
, loc
);
3475 /* Return whether EXPR is a declaration whose address can never be NULL.
3476 The address of the first struct member could be NULL only if it were
3477 accessed through a NULL pointer, and such an access would be invalid.
3478 The address of a weak symbol may be null unless it has a definition. */
3481 decl_with_nonnull_addr_p (const_tree expr
)
3486 if (TREE_CODE (expr
) == FIELD_DECL
3487 || TREE_CODE (expr
) == PARM_DECL
3488 || TREE_CODE (expr
) == LABEL_DECL
)
3491 if (!VAR_OR_FUNCTION_DECL_P (expr
))
3494 if (!DECL_WEAK (expr
))
3495 /* Ordinary (non-weak) symbols have nonnull addresses. */
3498 if (DECL_INITIAL (expr
) && DECL_INITIAL (expr
) != error_mark_node
)
3499 /* Initialized weak symbols have nonnull addresses. */
3502 if (DECL_EXTERNAL (expr
) || !TREE_STATIC (expr
))
3503 /* Uninitialized extern weak symbols and weak symbols with no
3504 allocated storage might have a null address. */
3507 tree attribs
= DECL_ATTRIBUTES (expr
);
3508 if (lookup_attribute ("weakref", attribs
))
3509 /* Weakref symbols might have a null address unless their referent
3510 is known not to. Don't bother following weakref targets here. */
3516 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
3517 or for an `if' or `while' statement or ?..: exp. It should already
3518 have been validated to be of suitable type; otherwise, a bad
3519 diagnostic may result.
3521 The EXPR is located at LOCATION.
3523 This preparation consists of taking the ordinary
3524 representation of an expression expr and producing a valid tree
3525 boolean expression describing whether expr is nonzero. We could
3526 simply always do build_binary_op (NE_EXPR, expr, truthvalue_false_node, 1),
3527 but we optimize comparisons, &&, ||, and !.
3529 The resulting type should always be `truthvalue_type_node'. */
3533 c_common_truthvalue_conversion (location_t location
, tree expr
)
3535 STRIP_ANY_LOCATION_WRAPPER (expr
);
3536 switch (TREE_CODE (expr
))
3538 case EQ_EXPR
: case NE_EXPR
: case UNEQ_EXPR
: case LTGT_EXPR
:
3539 case LE_EXPR
: case GE_EXPR
: case LT_EXPR
: case GT_EXPR
:
3540 case UNLE_EXPR
: case UNGE_EXPR
: case UNLT_EXPR
: case UNGT_EXPR
:
3541 case ORDERED_EXPR
: case UNORDERED_EXPR
:
3542 if (TREE_TYPE (expr
) == truthvalue_type_node
)
3544 expr
= build2 (TREE_CODE (expr
), truthvalue_type_node
,
3545 TREE_OPERAND (expr
, 0), TREE_OPERAND (expr
, 1));
3548 case TRUTH_ANDIF_EXPR
:
3549 case TRUTH_ORIF_EXPR
:
3550 case TRUTH_AND_EXPR
:
3552 case TRUTH_XOR_EXPR
:
3553 if (TREE_TYPE (expr
) == truthvalue_type_node
)
3555 expr
= build2 (TREE_CODE (expr
), truthvalue_type_node
,
3556 c_common_truthvalue_conversion (location
,
3557 TREE_OPERAND (expr
, 0)),
3558 c_common_truthvalue_conversion (location
,
3559 TREE_OPERAND (expr
, 1)));
3562 case TRUTH_NOT_EXPR
:
3563 if (TREE_TYPE (expr
) == truthvalue_type_node
)
3565 expr
= build1 (TREE_CODE (expr
), truthvalue_type_node
,
3566 c_common_truthvalue_conversion (location
,
3567 TREE_OPERAND (expr
, 0)));
3574 if (TREE_CODE (TREE_TYPE (expr
)) == ENUMERAL_TYPE
3575 && !integer_zerop (expr
)
3576 && !integer_onep (expr
))
3577 warning_at (location
, OPT_Wint_in_bool_context
,
3578 "enum constant in boolean context");
3579 return integer_zerop (expr
) ? truthvalue_false_node
3580 : truthvalue_true_node
;
3583 return real_compare (NE_EXPR
, &TREE_REAL_CST (expr
), &dconst0
)
3584 ? truthvalue_true_node
3585 : truthvalue_false_node
;
3588 return fixed_compare (NE_EXPR
, &TREE_FIXED_CST (expr
),
3589 &FCONST0 (TYPE_MODE (TREE_TYPE (expr
))))
3590 ? truthvalue_true_node
3591 : truthvalue_false_node
;
3594 expr
= build_unary_op (location
, ADDR_EXPR
, expr
, false);
3599 tree inner
= TREE_OPERAND (expr
, 0);
3600 if (decl_with_nonnull_addr_p (inner
)
3601 /* Check both EXPR and INNER for suppression. */
3602 && !warning_suppressed_p (expr
, OPT_Waddress
)
3603 && !warning_suppressed_p (inner
, OPT_Waddress
))
3605 /* Common Ada programmer's mistake. */
3606 warning_at (location
,
3608 "the address of %qD will always evaluate as %<true%>",
3610 suppress_warning (inner
, OPT_Waddress
);
3611 return truthvalue_true_node
;
3617 expr
= build_binary_op (EXPR_LOCATION (expr
),
3618 (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1))
3619 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
3620 c_common_truthvalue_conversion (location
,
3621 TREE_OPERAND (expr
, 0)),
3622 c_common_truthvalue_conversion (location
,
3623 TREE_OPERAND (expr
, 1)),
3631 case EXCESS_PRECISION_EXPR
:
3632 /* These don't change whether an object is nonzero or zero. */
3633 return c_common_truthvalue_conversion (location
, TREE_OPERAND (expr
, 0));
3637 /* These don't change whether an object is zero or nonzero, but
3638 we can't ignore them if their second arg has side-effects. */
3639 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1)))
3641 expr
= build2 (COMPOUND_EXPR
, truthvalue_type_node
,
3642 TREE_OPERAND (expr
, 1),
3643 c_common_truthvalue_conversion
3644 (location
, TREE_OPERAND (expr
, 0)));
3648 return c_common_truthvalue_conversion (location
,
3649 TREE_OPERAND (expr
, 0));
3652 warning_at (EXPR_LOCATION (expr
), OPT_Wint_in_bool_context
,
3653 "%<*%> in boolean context, suggest %<&&%> instead");
3657 /* We will only warn on signed shifts here, because the majority of
3658 false positive warnings happen in code where unsigned arithmetic
3659 was used in anticipation of a possible overflow.
3660 Furthermore, if we see an unsigned type here we know that the
3661 result of the shift is not subject to integer promotion rules. */
3662 if (TREE_CODE (TREE_TYPE (expr
)) == INTEGER_TYPE
3663 && !TYPE_UNSIGNED (TREE_TYPE (expr
)))
3664 warning_at (EXPR_LOCATION (expr
), OPT_Wint_in_bool_context
,
3665 "%<<<%> in boolean context, did you mean %<<%>?");
3669 if (warn_int_in_bool_context
3670 && !from_macro_definition_at (EXPR_LOCATION (expr
)))
3672 tree val1
= fold_for_warn (TREE_OPERAND (expr
, 1));
3673 tree val2
= fold_for_warn (TREE_OPERAND (expr
, 2));
3674 if (TREE_CODE (val1
) == INTEGER_CST
3675 && TREE_CODE (val2
) == INTEGER_CST
3676 && !integer_zerop (val1
)
3677 && !integer_zerop (val2
)
3678 && (!integer_onep (val1
)
3679 || !integer_onep (val2
)))
3680 warning_at (EXPR_LOCATION (expr
), OPT_Wint_in_bool_context
,
3681 "%<?:%> using integer constants in boolean context, "
3682 "the expression will always evaluate to %<true%>");
3683 else if ((TREE_CODE (val1
) == INTEGER_CST
3684 && !integer_zerop (val1
)
3685 && !integer_onep (val1
))
3686 || (TREE_CODE (val2
) == INTEGER_CST
3687 && !integer_zerop (val2
)
3688 && !integer_onep (val2
)))
3689 warning_at (EXPR_LOCATION (expr
), OPT_Wint_in_bool_context
,
3690 "%<?:%> using integer constants in boolean context");
3692 /* Distribute the conversion into the arms of a COND_EXPR. */
3693 if (c_dialect_cxx ())
3694 /* Avoid premature folding. */
3698 int w
= warn_int_in_bool_context
;
3699 warn_int_in_bool_context
= 0;
3700 /* Folding will happen later for C. */
3701 expr
= build3 (COND_EXPR
, truthvalue_type_node
,
3702 TREE_OPERAND (expr
, 0),
3703 c_common_truthvalue_conversion (location
,
3704 TREE_OPERAND (expr
, 1)),
3705 c_common_truthvalue_conversion (location
,
3706 TREE_OPERAND (expr
, 2)));
3707 warn_int_in_bool_context
= w
;
3713 tree totype
= TREE_TYPE (expr
);
3714 tree fromtype
= TREE_TYPE (TREE_OPERAND (expr
, 0));
3716 if (POINTER_TYPE_P (totype
)
3717 && !c_inhibit_evaluation_warnings
3718 && TREE_CODE (fromtype
) == REFERENCE_TYPE
)
3724 warning_at (location
,
3726 "the compiler can assume that the address of "
3727 "%qD will always evaluate to %<true%>",
3731 /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
3732 since that affects how `default_conversion' will behave. */
3733 if (TREE_CODE (totype
) == REFERENCE_TYPE
3734 || TREE_CODE (fromtype
) == REFERENCE_TYPE
)
3736 /* Don't strip a conversion from C++0x scoped enum, since they
3737 don't implicitly convert to other types. */
3738 if (TREE_CODE (fromtype
) == ENUMERAL_TYPE
3739 && ENUM_IS_SCOPED (fromtype
))
3741 /* If this isn't narrowing the argument, we can ignore it. */
3742 if (TYPE_PRECISION (totype
) >= TYPE_PRECISION (fromtype
))
3744 tree op0
= TREE_OPERAND (expr
, 0);
3745 if ((TREE_CODE (fromtype
) == POINTER_TYPE
3746 && TREE_CODE (totype
) == INTEGER_TYPE
)
3747 || warning_suppressed_p (expr
, OPT_Waddress
))
3748 /* Suppress -Waddress for casts to intptr_t, propagating
3749 any suppression from the enclosing expression to its
3751 suppress_warning (op0
, OPT_Waddress
);
3752 return c_common_truthvalue_conversion (location
, op0
);
3758 if (!warning_suppressed_p (expr
, OPT_Wparentheses
)
3760 && warning_at (location
, OPT_Wparentheses
,
3761 "suggest parentheses around assignment used as "
3763 suppress_warning (expr
, OPT_Wparentheses
);
3768 tree folded_expr
= fold_for_warn (expr
);
3769 if (folded_expr
!= expr
)
3770 return c_common_truthvalue_conversion (location
, folded_expr
);
3778 if (TREE_CODE (TREE_TYPE (expr
)) == COMPLEX_TYPE
)
3780 tree t
= save_expr (expr
);
3781 expr
= (build_binary_op
3782 (EXPR_LOCATION (expr
),
3783 (TREE_SIDE_EFFECTS (expr
)
3784 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
3785 c_common_truthvalue_conversion
3787 build_unary_op (location
, REALPART_EXPR
, t
, false)),
3788 c_common_truthvalue_conversion
3790 build_unary_op (location
, IMAGPART_EXPR
, t
, false)),
3795 if (TREE_CODE (TREE_TYPE (expr
)) == FIXED_POINT_TYPE
)
3797 tree fixed_zero_node
= build_fixed (TREE_TYPE (expr
),
3799 (TREE_TYPE (expr
))));
3800 return build_binary_op (location
, NE_EXPR
, expr
, fixed_zero_node
, true);
3803 return build_binary_op (location
, NE_EXPR
, expr
, integer_zero_node
, true);
3806 protected_set_expr_location (expr
, location
);
3811 static void def_builtin_1 (enum built_in_function fncode
,
3813 enum built_in_class fnclass
,
3814 tree fntype
, tree libtype
,
3815 bool both_p
, bool fallback_p
, bool nonansi_p
,
3816 tree fnattrs
, bool implicit_p
);
3819 /* Apply the TYPE_QUALS to the new DECL. */
3822 c_apply_type_quals_to_decl (int type_quals
, tree decl
)
3824 tree type
= TREE_TYPE (decl
);
3826 if (type
== error_mark_node
)
3829 if ((type_quals
& TYPE_QUAL_CONST
)
3830 || (type
&& TREE_CODE (type
) == REFERENCE_TYPE
))
3831 /* We used to check TYPE_NEEDS_CONSTRUCTING here, but now a constexpr
3832 constructor can produce constant init, so rely on cp_finish_decl to
3833 clear TREE_READONLY if the variable has non-constant init. */
3834 TREE_READONLY (decl
) = 1;
3835 if (type_quals
& TYPE_QUAL_VOLATILE
)
3837 TREE_SIDE_EFFECTS (decl
) = 1;
3838 TREE_THIS_VOLATILE (decl
) = 1;
3840 if (type_quals
& TYPE_QUAL_RESTRICT
)
3842 while (type
&& TREE_CODE (type
) == ARRAY_TYPE
)
3843 /* Allow 'restrict' on arrays of pointers.
3844 FIXME currently we just ignore it. */
3845 type
= TREE_TYPE (type
);
3847 || !POINTER_TYPE_P (type
)
3848 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type
)))
3849 error ("invalid use of %<restrict%>");
3853 /* Return the typed-based alias set for T, which may be an expression
3854 or a type. Return -1 if we don't do anything special. */
3857 c_common_get_alias_set (tree t
)
3859 /* For VLAs, use the alias set of the element type rather than the
3860 default of alias set 0 for types compared structurally. */
3861 if (TYPE_P (t
) && TYPE_STRUCTURAL_EQUALITY_P (t
))
3863 if (TREE_CODE (t
) == ARRAY_TYPE
)
3864 return get_alias_set (TREE_TYPE (t
));
3868 /* That's all the expressions we handle specially. */
3872 /* Unlike char, char8_t doesn't alias. */
3873 if (flag_char8_t
&& t
== char8_type_node
)
3876 /* The C standard guarantees that any object may be accessed via an
3877 lvalue that has narrow character type (except char8_t). */
3878 if (t
== char_type_node
3879 || t
== signed_char_type_node
3880 || t
== unsigned_char_type_node
)
3883 /* The C standard specifically allows aliasing between signed and
3884 unsigned variants of the same type. We treat the signed
3885 variant as canonical. */
3886 if (TREE_CODE (t
) == INTEGER_TYPE
&& TYPE_UNSIGNED (t
))
3888 tree t1
= c_common_signed_type (t
);
3890 /* t1 == t can happen for boolean nodes which are always unsigned. */
3892 return get_alias_set (t1
);
3898 /* Compute the value of 'sizeof (TYPE)' or '__alignof__ (TYPE)', where
3899 the IS_SIZEOF parameter indicates which operator is being applied.
3900 The COMPLAIN flag controls whether we should diagnose possibly
3901 ill-formed constructs or not. LOC is the location of the SIZEOF or
3902 TYPEOF operator. If MIN_ALIGNOF, the least alignment required for
3903 a type in any context should be returned, rather than the normal
3904 alignment for that type. */
3908 c_sizeof_or_alignof_type (location_t loc
,
3909 tree type
, bool is_sizeof
, bool min_alignof
,
3912 const char *op_name
;
3914 enum tree_code type_code
= TREE_CODE (type
);
3916 op_name
= is_sizeof
? "sizeof" : "__alignof__";
3918 if (type_code
== FUNCTION_TYPE
)
3922 if (complain
&& warn_pointer_arith
)
3923 pedwarn (loc
, OPT_Wpointer_arith
,
3924 "invalid application of %<sizeof%> to a function type");
3926 return error_mark_node
;
3927 value
= size_one_node
;
3933 if (c_dialect_cxx ())
3934 pedwarn (loc
, OPT_Wpedantic
, "ISO C++ does not permit "
3935 "%<alignof%> applied to a function type");
3937 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not permit "
3938 "%<_Alignof%> applied to a function type");
3940 value
= size_int (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
3943 else if (type_code
== VOID_TYPE
|| type_code
== ERROR_MARK
)
3945 if (type_code
== VOID_TYPE
3946 && complain
&& warn_pointer_arith
)
3947 pedwarn (loc
, OPT_Wpointer_arith
,
3948 "invalid application of %qs to a void type", op_name
);
3950 return error_mark_node
;
3951 value
= size_one_node
;
3953 else if (!COMPLETE_TYPE_P (type
)
3954 && (!c_dialect_cxx () || is_sizeof
|| type_code
!= ARRAY_TYPE
))
3957 error_at (loc
, "invalid application of %qs to incomplete type %qT",
3959 return error_mark_node
;
3961 else if (c_dialect_cxx () && type_code
== ARRAY_TYPE
3962 && !COMPLETE_TYPE_P (TREE_TYPE (type
)))
3965 error_at (loc
, "invalid application of %qs to array type %qT of "
3966 "incomplete element type", op_name
, type
);
3967 return error_mark_node
;
3969 else if (!verify_type_context (loc
, is_sizeof
? TCTX_SIZEOF
: TCTX_ALIGNOF
,
3973 return error_mark_node
;
3974 value
= size_one_node
;
3979 /* Convert in case a char is more than one unit. */
3980 value
= size_binop_loc (loc
, CEIL_DIV_EXPR
, TYPE_SIZE_UNIT (type
),
3981 size_int (TYPE_PRECISION (char_type_node
)
3983 else if (min_alignof
)
3984 value
= size_int (min_align_of_type (type
));
3986 value
= size_int (TYPE_ALIGN_UNIT (type
));
3989 /* VALUE will have the middle-end integer type sizetype.
3990 However, we should really return a value of type `size_t',
3991 which is just a typedef for an ordinary integer type. */
3992 value
= fold_convert_loc (loc
, size_type_node
, value
);
3998 /* Implement the __alignof keyword: Return the minimum required
3999 alignment of EXPR, measured in bytes. For VAR_DECLs,
4000 FUNCTION_DECLs and FIELD_DECLs return DECL_ALIGN (which can be set
4001 from an "aligned" __attribute__ specification). LOC is the
4002 location of the ALIGNOF operator. */
4005 c_alignof_expr (location_t loc
, tree expr
)
4009 if (!verify_type_context (loc
, TCTX_ALIGNOF
, TREE_TYPE (expr
)))
4012 else if (VAR_OR_FUNCTION_DECL_P (expr
))
4013 t
= size_int (DECL_ALIGN_UNIT (expr
));
4015 else if (TREE_CODE (expr
) == COMPONENT_REF
4016 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
, 1)))
4018 error_at (loc
, "%<__alignof%> applied to a bit-field");
4021 else if (TREE_CODE (expr
) == COMPONENT_REF
4022 && TREE_CODE (TREE_OPERAND (expr
, 1)) == FIELD_DECL
)
4023 t
= size_int (DECL_ALIGN_UNIT (TREE_OPERAND (expr
, 1)));
4025 else if (INDIRECT_REF_P (expr
))
4027 tree t
= TREE_OPERAND (expr
, 0);
4029 int bestalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
4031 while (CONVERT_EXPR_P (t
)
4032 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == POINTER_TYPE
)
4036 t
= TREE_OPERAND (t
, 0);
4037 thisalign
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t
)));
4038 if (thisalign
> bestalign
)
4039 best
= t
, bestalign
= thisalign
;
4041 return c_alignof (loc
, TREE_TYPE (TREE_TYPE (best
)));
4044 return c_alignof (loc
, TREE_TYPE (expr
));
4046 return fold_convert_loc (loc
, size_type_node
, t
);
4049 /* Handle C and C++ default attributes. */
4051 enum built_in_attribute
4053 #define DEF_ATTR_NULL_TREE(ENUM) ENUM,
4054 #define DEF_ATTR_INT(ENUM, VALUE) ENUM,
4055 #define DEF_ATTR_STRING(ENUM, VALUE) ENUM,
4056 #define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
4057 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
4058 #include "builtin-attrs.def"
4059 #undef DEF_ATTR_NULL_TREE
4061 #undef DEF_ATTR_STRING
4062 #undef DEF_ATTR_IDENT
4063 #undef DEF_ATTR_TREE_LIST
4067 static GTY(()) tree built_in_attributes
[(int) ATTR_LAST
];
4069 static void c_init_attributes (void);
4073 #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
4074 #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
4075 #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
4076 #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
4077 #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
4078 #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
4079 #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
4080 #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4082 #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4084 #define DEF_FUNCTION_TYPE_8(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4085 ARG6, ARG7, ARG8) NAME,
4086 #define DEF_FUNCTION_TYPE_9(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4087 ARG6, ARG7, ARG8, ARG9) NAME,
4088 #define DEF_FUNCTION_TYPE_10(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4089 ARG6, ARG7, ARG8, ARG9, ARG10) NAME,
4090 #define DEF_FUNCTION_TYPE_11(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4091 ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) NAME,
4092 #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
4093 #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
4094 #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
4095 #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
4096 #define DEF_FUNCTION_TYPE_VAR_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
4097 #define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
4099 #define DEF_FUNCTION_TYPE_VAR_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4101 #define DEF_FUNCTION_TYPE_VAR_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4103 #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
4104 #include "builtin-types.def"
4105 #undef DEF_PRIMITIVE_TYPE
4106 #undef DEF_FUNCTION_TYPE_0
4107 #undef DEF_FUNCTION_TYPE_1
4108 #undef DEF_FUNCTION_TYPE_2
4109 #undef DEF_FUNCTION_TYPE_3
4110 #undef DEF_FUNCTION_TYPE_4
4111 #undef DEF_FUNCTION_TYPE_5
4112 #undef DEF_FUNCTION_TYPE_6
4113 #undef DEF_FUNCTION_TYPE_7
4114 #undef DEF_FUNCTION_TYPE_8
4115 #undef DEF_FUNCTION_TYPE_9
4116 #undef DEF_FUNCTION_TYPE_10
4117 #undef DEF_FUNCTION_TYPE_11
4118 #undef DEF_FUNCTION_TYPE_VAR_0
4119 #undef DEF_FUNCTION_TYPE_VAR_1
4120 #undef DEF_FUNCTION_TYPE_VAR_2
4121 #undef DEF_FUNCTION_TYPE_VAR_3
4122 #undef DEF_FUNCTION_TYPE_VAR_4
4123 #undef DEF_FUNCTION_TYPE_VAR_5
4124 #undef DEF_FUNCTION_TYPE_VAR_6
4125 #undef DEF_FUNCTION_TYPE_VAR_7
4126 #undef DEF_POINTER_TYPE
4130 typedef enum c_builtin_type builtin_type
;
4132 /* A temporary array for c_common_nodes_and_builtins. Used in
4133 communication with def_fn_type. */
4134 static tree builtin_types
[(int) BT_LAST
+ 1];
4136 /* A helper function for c_common_nodes_and_builtins. Build function type
4137 for DEF with return type RET and N arguments. If VAR is true, then the
4138 function should be variadic after those N arguments.
4140 Takes special care not to ICE if any of the types involved are
4141 error_mark_node, which indicates that said type is not in fact available
4142 (see builtin_type_for_size). In which case the function type as a whole
4143 should be error_mark_node. */
4146 def_fn_type (builtin_type def
, builtin_type ret
, bool var
, int n
, ...)
4149 tree
*args
= XALLOCAVEC (tree
, n
);
4154 for (i
= 0; i
< n
; ++i
)
4156 builtin_type a
= (builtin_type
) va_arg (list
, int);
4157 t
= builtin_types
[a
];
4158 if (t
== error_mark_node
)
4163 t
= builtin_types
[ret
];
4164 if (t
== error_mark_node
)
4167 t
= build_varargs_function_type_array (t
, n
, args
);
4169 t
= build_function_type_array (t
, n
, args
);
4172 builtin_types
[def
] = t
;
4176 /* Build builtin functions common to both C and C++ language
4180 c_define_builtins (tree va_list_ref_type_node
, tree va_list_arg_type_node
)
4182 #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
4183 builtin_types[ENUM] = VALUE;
4184 #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
4185 def_fn_type (ENUM, RETURN, 0, 0);
4186 #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
4187 def_fn_type (ENUM, RETURN, 0, 1, ARG1);
4188 #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
4189 def_fn_type (ENUM, RETURN, 0, 2, ARG1, ARG2);
4190 #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
4191 def_fn_type (ENUM, RETURN, 0, 3, ARG1, ARG2, ARG3);
4192 #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
4193 def_fn_type (ENUM, RETURN, 0, 4, ARG1, ARG2, ARG3, ARG4);
4194 #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
4195 def_fn_type (ENUM, RETURN, 0, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
4196 #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4198 def_fn_type (ENUM, RETURN, 0, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
4199 #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4201 def_fn_type (ENUM, RETURN, 0, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
4202 #define DEF_FUNCTION_TYPE_8(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4204 def_fn_type (ENUM, RETURN, 0, 8, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
4206 #define DEF_FUNCTION_TYPE_9(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4207 ARG6, ARG7, ARG8, ARG9) \
4208 def_fn_type (ENUM, RETURN, 0, 9, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
4210 #define DEF_FUNCTION_TYPE_10(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4211 ARG6, ARG7, ARG8, ARG9, ARG10) \
4212 def_fn_type (ENUM, RETURN, 0, 10, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
4213 ARG7, ARG8, ARG9, ARG10);
4214 #define DEF_FUNCTION_TYPE_11(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4215 ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) \
4216 def_fn_type (ENUM, RETURN, 0, 11, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
4217 ARG7, ARG8, ARG9, ARG10, ARG11);
4218 #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
4219 def_fn_type (ENUM, RETURN, 1, 0);
4220 #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
4221 def_fn_type (ENUM, RETURN, 1, 1, ARG1);
4222 #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
4223 def_fn_type (ENUM, RETURN, 1, 2, ARG1, ARG2);
4224 #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
4225 def_fn_type (ENUM, RETURN, 1, 3, ARG1, ARG2, ARG3);
4226 #define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
4227 def_fn_type (ENUM, RETURN, 1, 4, ARG1, ARG2, ARG3, ARG4);
4228 #define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
4229 def_fn_type (ENUM, RETURN, 1, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
4230 #define DEF_FUNCTION_TYPE_VAR_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4232 def_fn_type (ENUM, RETURN, 1, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
4233 #define DEF_FUNCTION_TYPE_VAR_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
4235 def_fn_type (ENUM, RETURN, 1, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
4236 #define DEF_POINTER_TYPE(ENUM, TYPE) \
4237 builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]);
4239 #include "builtin-types.def"
4241 #undef DEF_PRIMITIVE_TYPE
4242 #undef DEF_FUNCTION_TYPE_0
4243 #undef DEF_FUNCTION_TYPE_1
4244 #undef DEF_FUNCTION_TYPE_2
4245 #undef DEF_FUNCTION_TYPE_3
4246 #undef DEF_FUNCTION_TYPE_4
4247 #undef DEF_FUNCTION_TYPE_5
4248 #undef DEF_FUNCTION_TYPE_6
4249 #undef DEF_FUNCTION_TYPE_7
4250 #undef DEF_FUNCTION_TYPE_8
4251 #undef DEF_FUNCTION_TYPE_9
4252 #undef DEF_FUNCTION_TYPE_10
4253 #undef DEF_FUNCTION_TYPE_11
4254 #undef DEF_FUNCTION_TYPE_VAR_0
4255 #undef DEF_FUNCTION_TYPE_VAR_1
4256 #undef DEF_FUNCTION_TYPE_VAR_2
4257 #undef DEF_FUNCTION_TYPE_VAR_3
4258 #undef DEF_FUNCTION_TYPE_VAR_4
4259 #undef DEF_FUNCTION_TYPE_VAR_5
4260 #undef DEF_FUNCTION_TYPE_VAR_6
4261 #undef DEF_FUNCTION_TYPE_VAR_7
4262 #undef DEF_POINTER_TYPE
4263 builtin_types
[(int) BT_LAST
] = NULL_TREE
;
4265 c_init_attributes ();
4267 #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P, \
4268 NONANSI_P, ATTRS, IMPLICIT, COND) \
4270 def_builtin_1 (ENUM, NAME, CLASS, \
4271 builtin_types[(int) TYPE], \
4272 builtin_types[(int) LIBTYPE], \
4273 BOTH_P, FALLBACK_P, NONANSI_P, \
4274 built_in_attributes[(int) ATTRS], IMPLICIT);
4275 #include "builtins.def"
4277 targetm
.init_builtins ();
4279 build_common_builtin_nodes ();
4282 /* Like get_identifier, but avoid warnings about null arguments when
4283 the argument may be NULL for targets where GCC lacks stdint.h type
4287 c_get_ident (const char *id
)
4289 return get_identifier (id
);
4292 /* Build tree nodes and builtin functions common to both C and C++ language
4297 c_common_nodes_and_builtins (void)
4299 int char8_type_size
;
4300 int char16_type_size
;
4301 int char32_type_size
;
4302 int wchar_type_size
;
4303 tree array_domain_type
;
4304 tree va_list_ref_type_node
;
4305 tree va_list_arg_type_node
;
4308 fprintf(stderr
, "build_common_builtin_nodes\n");
4309 build_common_tree_nodes (flag_signed_char
);
4311 /* Define `int' and `char' first so that dbx will output them first. */
4312 record_builtin_type (RID_INT
, NULL
, integer_type_node
);
4313 record_builtin_type (RID_CHAR
, "char", char_type_node
);
4315 /* `signed' is the same as `int'. FIXME: the declarations of "signed",
4316 "unsigned long", "long long unsigned" and "unsigned short" were in C++
4317 but not C. Are the conditionals here needed? */
4318 if (c_dialect_cxx ())
4319 record_builtin_type (RID_SIGNED
, NULL
, integer_type_node
);
4320 record_builtin_type (RID_LONG
, "long int", long_integer_type_node
);
4321 record_builtin_type (RID_UNSIGNED
, "unsigned int", unsigned_type_node
);
4322 record_builtin_type (RID_MAX
, "long unsigned int",
4323 long_unsigned_type_node
);
4325 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
4329 sprintf (name
, "__int%d", int_n_data
[i
].bitsize
);
4330 record_builtin_type ((enum rid
)(RID_FIRST_INT_N
+ i
), name
,
4331 int_n_trees
[i
].signed_type
);
4332 sprintf (name
, "__int%d__", int_n_data
[i
].bitsize
);
4333 record_builtin_type ((enum rid
)(RID_FIRST_INT_N
+ i
), name
,
4334 int_n_trees
[i
].signed_type
);
4335 ridpointers
[RID_FIRST_INT_N
+ i
]
4336 = DECL_NAME (TYPE_NAME (int_n_trees
[i
].signed_type
));
4338 sprintf (name
, "__int%d unsigned", int_n_data
[i
].bitsize
);
4339 record_builtin_type (RID_MAX
, name
, int_n_trees
[i
].unsigned_type
);
4340 sprintf (name
, "__int%d__ unsigned", int_n_data
[i
].bitsize
);
4341 record_builtin_type (RID_MAX
, name
, int_n_trees
[i
].unsigned_type
);
4344 if (c_dialect_cxx ())
4345 record_builtin_type (RID_MAX
, "unsigned long", long_unsigned_type_node
);
4346 record_builtin_type (RID_MAX
, "long long int",
4347 long_long_integer_type_node
);
4348 record_builtin_type (RID_MAX
, "long long unsigned int",
4349 long_long_unsigned_type_node
);
4350 if (c_dialect_cxx ())
4351 record_builtin_type (RID_MAX
, "long long unsigned",
4352 long_long_unsigned_type_node
);
4353 record_builtin_type (RID_SHORT
, "short int", short_integer_type_node
);
4354 record_builtin_type (RID_MAX
, "short unsigned int",
4355 short_unsigned_type_node
);
4356 if (c_dialect_cxx ())
4357 record_builtin_type (RID_MAX
, "unsigned short",
4358 short_unsigned_type_node
);
4360 /* Define both `signed char' and `unsigned char'. */
4361 record_builtin_type (RID_MAX
, "signed char", signed_char_type_node
);
4362 record_builtin_type (RID_MAX
, "unsigned char", unsigned_char_type_node
);
4364 /* These are types that c_common_type_for_size and
4365 c_common_type_for_mode use. */
4366 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4367 TYPE_DECL
, NULL_TREE
,
4369 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4370 TYPE_DECL
, NULL_TREE
,
4372 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4373 TYPE_DECL
, NULL_TREE
,
4375 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4376 TYPE_DECL
, NULL_TREE
,
4378 #if HOST_BITS_PER_WIDE_INT >= 64
4379 /* Note that this is different than the __int128 type that's part of
4380 the generic __intN support. */
4381 if (targetm
.scalar_mode_supported_p (TImode
))
4382 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4384 get_identifier ("__int128_t"),
4387 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4388 TYPE_DECL
, NULL_TREE
,
4389 unsigned_intQI_type_node
));
4390 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4391 TYPE_DECL
, NULL_TREE
,
4392 unsigned_intHI_type_node
));
4393 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4394 TYPE_DECL
, NULL_TREE
,
4395 unsigned_intSI_type_node
));
4396 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4397 TYPE_DECL
, NULL_TREE
,
4398 unsigned_intDI_type_node
));
4399 #if HOST_BITS_PER_WIDE_INT >= 64
4400 if (targetm
.scalar_mode_supported_p (TImode
))
4401 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4403 get_identifier ("__uint128_t"),
4404 unsigned_intTI_type_node
));
4407 /* Create the widest literal types. */
4408 if (targetm
.scalar_mode_supported_p (TImode
))
4410 widest_integer_literal_type_node
= intTI_type_node
;
4411 widest_unsigned_literal_type_node
= unsigned_intTI_type_node
;
4415 widest_integer_literal_type_node
= intDI_type_node
;
4416 widest_unsigned_literal_type_node
= unsigned_intDI_type_node
;
4419 signed_size_type_node
= c_common_signed_type (size_type_node
);
4422 TREE_TYPE (identifier_global_value (get_identifier (PID_TYPE
)));
4424 record_builtin_type (RID_FLOAT
, NULL
, float_type_node
);
4425 record_builtin_type (RID_DOUBLE
, NULL
, double_type_node
);
4426 record_builtin_type (RID_MAX
, "long double", long_double_type_node
);
4428 if (!c_dialect_cxx ())
4429 for (i
= 0; i
< NUM_FLOATN_NX_TYPES
; i
++)
4430 if (FLOATN_NX_TYPE_NODE (i
) != NULL_TREE
)
4431 record_builtin_type ((enum rid
) (RID_FLOATN_NX_FIRST
+ i
), NULL
,
4432 FLOATN_NX_TYPE_NODE (i
));
4434 /* Only supported decimal floating point extension if the target
4435 actually supports underlying modes. */
4436 if (targetm
.scalar_mode_supported_p (SDmode
)
4437 && targetm
.scalar_mode_supported_p (DDmode
)
4438 && targetm
.scalar_mode_supported_p (TDmode
))
4440 record_builtin_type (RID_DFLOAT32
, NULL
, dfloat32_type_node
);
4441 record_builtin_type (RID_DFLOAT64
, NULL
, dfloat64_type_node
);
4442 record_builtin_type (RID_DFLOAT128
, NULL
, dfloat128_type_node
);
4445 if (targetm
.fixed_point_supported_p ())
4447 record_builtin_type (RID_MAX
, "short _Fract", short_fract_type_node
);
4448 record_builtin_type (RID_FRACT
, NULL
, fract_type_node
);
4449 record_builtin_type (RID_MAX
, "long _Fract", long_fract_type_node
);
4450 record_builtin_type (RID_MAX
, "long long _Fract",
4451 long_long_fract_type_node
);
4452 record_builtin_type (RID_MAX
, "unsigned short _Fract",
4453 unsigned_short_fract_type_node
);
4454 record_builtin_type (RID_MAX
, "unsigned _Fract",
4455 unsigned_fract_type_node
);
4456 record_builtin_type (RID_MAX
, "unsigned long _Fract",
4457 unsigned_long_fract_type_node
);
4458 record_builtin_type (RID_MAX
, "unsigned long long _Fract",
4459 unsigned_long_long_fract_type_node
);
4460 record_builtin_type (RID_MAX
, "_Sat short _Fract",
4461 sat_short_fract_type_node
);
4462 record_builtin_type (RID_MAX
, "_Sat _Fract", sat_fract_type_node
);
4463 record_builtin_type (RID_MAX
, "_Sat long _Fract",
4464 sat_long_fract_type_node
);
4465 record_builtin_type (RID_MAX
, "_Sat long long _Fract",
4466 sat_long_long_fract_type_node
);
4467 record_builtin_type (RID_MAX
, "_Sat unsigned short _Fract",
4468 sat_unsigned_short_fract_type_node
);
4469 record_builtin_type (RID_MAX
, "_Sat unsigned _Fract",
4470 sat_unsigned_fract_type_node
);
4471 record_builtin_type (RID_MAX
, "_Sat unsigned long _Fract",
4472 sat_unsigned_long_fract_type_node
);
4473 record_builtin_type (RID_MAX
, "_Sat unsigned long long _Fract",
4474 sat_unsigned_long_long_fract_type_node
);
4475 record_builtin_type (RID_MAX
, "short _Accum", short_accum_type_node
);
4476 record_builtin_type (RID_ACCUM
, NULL
, accum_type_node
);
4477 record_builtin_type (RID_MAX
, "long _Accum", long_accum_type_node
);
4478 record_builtin_type (RID_MAX
, "long long _Accum",
4479 long_long_accum_type_node
);
4480 record_builtin_type (RID_MAX
, "unsigned short _Accum",
4481 unsigned_short_accum_type_node
);
4482 record_builtin_type (RID_MAX
, "unsigned _Accum",
4483 unsigned_accum_type_node
);
4484 record_builtin_type (RID_MAX
, "unsigned long _Accum",
4485 unsigned_long_accum_type_node
);
4486 record_builtin_type (RID_MAX
, "unsigned long long _Accum",
4487 unsigned_long_long_accum_type_node
);
4488 record_builtin_type (RID_MAX
, "_Sat short _Accum",
4489 sat_short_accum_type_node
);
4490 record_builtin_type (RID_MAX
, "_Sat _Accum", sat_accum_type_node
);
4491 record_builtin_type (RID_MAX
, "_Sat long _Accum",
4492 sat_long_accum_type_node
);
4493 record_builtin_type (RID_MAX
, "_Sat long long _Accum",
4494 sat_long_long_accum_type_node
);
4495 record_builtin_type (RID_MAX
, "_Sat unsigned short _Accum",
4496 sat_unsigned_short_accum_type_node
);
4497 record_builtin_type (RID_MAX
, "_Sat unsigned _Accum",
4498 sat_unsigned_accum_type_node
);
4499 record_builtin_type (RID_MAX
, "_Sat unsigned long _Accum",
4500 sat_unsigned_long_accum_type_node
);
4501 record_builtin_type (RID_MAX
, "_Sat unsigned long long _Accum",
4502 sat_unsigned_long_long_accum_type_node
);
4506 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4508 get_identifier ("complex int"),
4509 complex_integer_type_node
));
4510 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4512 get_identifier ("complex float"),
4513 complex_float_type_node
));
4514 lang_hooks
.decls
.pushdecl (build_decl (UNKNOWN_LOCATION
,
4516 get_identifier ("complex double"),
4517 complex_double_type_node
));
4518 lang_hooks
.decls
.pushdecl
4519 (build_decl (UNKNOWN_LOCATION
,
4520 TYPE_DECL
, get_identifier ("complex long double"),
4521 complex_long_double_type_node
));
4523 if (!c_dialect_cxx ())
4524 for (i
= 0; i
< NUM_FLOATN_NX_TYPES
; i
++)
4525 if (COMPLEX_FLOATN_NX_TYPE_NODE (i
) != NULL_TREE
)
4528 sprintf (buf
, "complex _Float%d%s", floatn_nx_types
[i
].n
,
4529 floatn_nx_types
[i
].extended
? "x" : "");
4530 lang_hooks
.decls
.pushdecl
4531 (build_decl (UNKNOWN_LOCATION
,
4533 get_identifier (buf
),
4534 COMPLEX_FLOATN_NX_TYPE_NODE (i
)));
4537 /* Make fileptr_type_node a distinct void * type until
4538 FILE type is defined. Likewise for const struct tm*. */
4539 for (unsigned i
= 0;
4540 i
< sizeof (builtin_structptr_types
) / sizeof (builtin_structptr_type
);
4542 builtin_structptr_types
[i
].node
4543 = build_variant_type_copy (builtin_structptr_types
[i
].base
);
4545 record_builtin_type (RID_VOID
, NULL
, void_type_node
);
4547 /* Set the TYPE_NAME for any variants that were built before
4548 record_builtin_type gave names to the built-in types. */
4550 tree void_name
= TYPE_NAME (void_type_node
);
4551 TYPE_NAME (void_type_node
) = NULL_TREE
;
4552 TYPE_NAME (build_qualified_type (void_type_node
, TYPE_QUAL_CONST
))
4554 TYPE_NAME (void_type_node
) = void_name
;
4557 void_list_node
= build_void_list_node ();
4559 /* Make a type to be the domain of a few array types
4560 whose domains don't really matter.
4561 200 is small enough that it always fits in size_t
4562 and large enough that it can hold most function names for the
4563 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
4564 array_domain_type
= build_index_type (size_int (200));
4566 /* Make a type for arrays of characters.
4567 With luck nothing will ever really depend on the length of this
4569 char_array_type_node
4570 = build_array_type (char_type_node
, array_domain_type
);
4572 string_type_node
= build_pointer_type (char_type_node
);
4573 const_string_type_node
4574 = build_pointer_type (build_qualified_type
4575 (char_type_node
, TYPE_QUAL_CONST
));
4577 /* This is special for C++ so functions can be overloaded. */
4578 wchar_type_node
= get_identifier (MODIFIED_WCHAR_TYPE
);
4579 wchar_type_node
= TREE_TYPE (identifier_global_value (wchar_type_node
));
4580 wchar_type_size
= TYPE_PRECISION (wchar_type_node
);
4581 underlying_wchar_type_node
= wchar_type_node
;
4582 if (c_dialect_cxx ())
4584 if (TYPE_UNSIGNED (wchar_type_node
))
4585 wchar_type_node
= make_unsigned_type (wchar_type_size
);
4587 wchar_type_node
= make_signed_type (wchar_type_size
);
4588 record_builtin_type (RID_WCHAR
, "wchar_t", wchar_type_node
);
4591 /* This is for wide string constants. */
4592 wchar_array_type_node
4593 = build_array_type (wchar_type_node
, array_domain_type
);
4595 /* Define 'char8_t'. */
4596 char8_type_node
= get_identifier (CHAR8_TYPE
);
4597 char8_type_node
= TREE_TYPE (identifier_global_value (char8_type_node
));
4598 char8_type_size
= TYPE_PRECISION (char8_type_node
);
4599 if (c_dialect_cxx ())
4601 char8_type_node
= make_unsigned_type (char8_type_size
);
4604 record_builtin_type (RID_CHAR8
, "char8_t", char8_type_node
);
4607 /* This is for UTF-8 string constants. */
4608 char8_array_type_node
4609 = build_array_type (char8_type_node
, array_domain_type
);
4611 /* Define 'char16_t'. */
4612 char16_type_node
= get_identifier (CHAR16_TYPE
);
4613 char16_type_node
= TREE_TYPE (identifier_global_value (char16_type_node
));
4614 char16_type_size
= TYPE_PRECISION (char16_type_node
);
4615 if (c_dialect_cxx ())
4617 char16_type_node
= make_unsigned_type (char16_type_size
);
4619 if (cxx_dialect
>= cxx11
)
4620 record_builtin_type (RID_CHAR16
, "char16_t", char16_type_node
);
4623 /* This is for UTF-16 string constants. */
4624 char16_array_type_node
4625 = build_array_type (char16_type_node
, array_domain_type
);
4627 /* Define 'char32_t'. */
4628 char32_type_node
= get_identifier (CHAR32_TYPE
);
4629 char32_type_node
= TREE_TYPE (identifier_global_value (char32_type_node
));
4630 char32_type_size
= TYPE_PRECISION (char32_type_node
);
4631 if (c_dialect_cxx ())
4633 char32_type_node
= make_unsigned_type (char32_type_size
);
4635 if (cxx_dialect
>= cxx11
)
4636 record_builtin_type (RID_CHAR32
, "char32_t", char32_type_node
);
4639 /* This is for UTF-32 string constants. */
4640 char32_array_type_node
4641 = build_array_type (char32_type_node
, array_domain_type
);
4644 TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE
)));
4647 TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE
)));
4649 TREE_TYPE (identifier_global_value (get_identifier (UINTMAX_TYPE
)));
4651 if (SIG_ATOMIC_TYPE
)
4652 sig_atomic_type_node
=
4653 TREE_TYPE (identifier_global_value (c_get_ident (SIG_ATOMIC_TYPE
)));
4656 TREE_TYPE (identifier_global_value (c_get_ident (INT8_TYPE
)));
4659 TREE_TYPE (identifier_global_value (c_get_ident (INT16_TYPE
)));
4662 TREE_TYPE (identifier_global_value (c_get_ident (INT32_TYPE
)));
4665 TREE_TYPE (identifier_global_value (c_get_ident (INT64_TYPE
)));
4668 TREE_TYPE (identifier_global_value (c_get_ident (UINT8_TYPE
)));
4670 c_uint16_type_node
= uint16_type_node
=
4671 TREE_TYPE (identifier_global_value (c_get_ident (UINT16_TYPE
)));
4673 c_uint32_type_node
= uint32_type_node
=
4674 TREE_TYPE (identifier_global_value (c_get_ident (UINT32_TYPE
)));
4676 c_uint64_type_node
= uint64_type_node
=
4677 TREE_TYPE (identifier_global_value (c_get_ident (UINT64_TYPE
)));
4678 if (INT_LEAST8_TYPE
)
4679 int_least8_type_node
=
4680 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST8_TYPE
)));
4681 if (INT_LEAST16_TYPE
)
4682 int_least16_type_node
=
4683 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST16_TYPE
)));
4684 if (INT_LEAST32_TYPE
)
4685 int_least32_type_node
=
4686 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST32_TYPE
)));
4687 if (INT_LEAST64_TYPE
)
4688 int_least64_type_node
=
4689 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST64_TYPE
)));
4690 if (UINT_LEAST8_TYPE
)
4691 uint_least8_type_node
=
4692 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST8_TYPE
)));
4693 if (UINT_LEAST16_TYPE
)
4694 uint_least16_type_node
=
4695 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST16_TYPE
)));
4696 if (UINT_LEAST32_TYPE
)
4697 uint_least32_type_node
=
4698 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST32_TYPE
)));
4699 if (UINT_LEAST64_TYPE
)
4700 uint_least64_type_node
=
4701 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST64_TYPE
)));
4703 int_fast8_type_node
=
4704 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST8_TYPE
)));
4705 if (INT_FAST16_TYPE
)
4706 int_fast16_type_node
=
4707 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST16_TYPE
)));
4708 if (INT_FAST32_TYPE
)
4709 int_fast32_type_node
=
4710 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST32_TYPE
)));
4711 if (INT_FAST64_TYPE
)
4712 int_fast64_type_node
=
4713 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST64_TYPE
)));
4714 if (UINT_FAST8_TYPE
)
4715 uint_fast8_type_node
=
4716 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST8_TYPE
)));
4717 if (UINT_FAST16_TYPE
)
4718 uint_fast16_type_node
=
4719 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST16_TYPE
)));
4720 if (UINT_FAST32_TYPE
)
4721 uint_fast32_type_node
=
4722 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST32_TYPE
)));
4723 if (UINT_FAST64_TYPE
)
4724 uint_fast64_type_node
=
4725 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST64_TYPE
)));
4728 TREE_TYPE (identifier_global_value (c_get_ident (INTPTR_TYPE
)));
4731 TREE_TYPE (identifier_global_value (c_get_ident (UINTPTR_TYPE
)));
4733 default_function_type
4734 = build_varargs_function_type_list (integer_type_node
, NULL_TREE
);
4735 unsigned_ptrdiff_type_node
= c_common_unsigned_type (ptrdiff_type_node
);
4737 lang_hooks
.decls
.pushdecl
4738 (build_decl (UNKNOWN_LOCATION
,
4739 TYPE_DECL
, get_identifier ("__builtin_va_list"),
4740 va_list_type_node
));
4741 if (targetm
.enum_va_list_p
)
4747 for (l
= 0; targetm
.enum_va_list_p (l
, &pname
, &ptype
); ++l
)
4749 lang_hooks
.decls
.pushdecl
4750 (build_decl (UNKNOWN_LOCATION
,
4751 TYPE_DECL
, get_identifier (pname
),
4757 if (TREE_CODE (va_list_type_node
) == ARRAY_TYPE
)
4759 va_list_arg_type_node
= va_list_ref_type_node
=
4760 build_pointer_type (TREE_TYPE (va_list_type_node
));
4764 va_list_arg_type_node
= va_list_type_node
;
4765 va_list_ref_type_node
= build_reference_type (va_list_type_node
);
4768 c_define_builtins (va_list_ref_type_node
, va_list_arg_type_node
);
4770 main_identifier_node
= get_identifier ("main");
4772 /* Create the built-in __null node. It is important that this is
4774 null_node
= make_int_cst (1, 1);
4775 TREE_TYPE (null_node
) = c_common_type_for_size (POINTER_SIZE
, 0);
4777 /* Since builtin_types isn't gc'ed, don't export these nodes. */
4778 memset (builtin_types
, 0, sizeof (builtin_types
));
4782 /* The number of named compound-literals generated thus far. */
4783 static GTY(()) int compound_literal_number
;
4785 /* Set DECL_NAME for DECL, a VAR_DECL for a compound-literal. */
4788 set_compound_literal_name (tree decl
)
4791 ASM_FORMAT_PRIVATE_NAME (name
, "__compound_literal",
4792 compound_literal_number
);
4793 compound_literal_number
++;
4794 DECL_NAME (decl
) = get_identifier (name
);
4797 /* build_va_arg helper function. Return a VA_ARG_EXPR with location LOC, type
4798 TYPE and operand OP. */
4801 build_va_arg_1 (location_t loc
, tree type
, tree op
)
4803 tree expr
= build1 (VA_ARG_EXPR
, type
, op
);
4804 SET_EXPR_LOCATION (expr
, loc
);
4808 /* Return a VA_ARG_EXPR corresponding to a source-level expression
4809 va_arg (EXPR, TYPE) at source location LOC. */
4812 build_va_arg (location_t loc
, tree expr
, tree type
)
4814 tree va_type
= TREE_TYPE (expr
);
4815 tree canon_va_type
= (va_type
== error_mark_node
4817 : targetm
.canonical_va_list_type (va_type
));
4819 if (va_type
== error_mark_node
4820 || canon_va_type
== NULL_TREE
)
4822 if (canon_va_type
== NULL_TREE
)
4823 error_at (loc
, "first argument to %<va_arg%> not of type %<va_list%>");
4825 /* Let's handle things neutrally, if expr:
4826 - has undeclared type, or
4827 - is not an va_list type. */
4828 return build_va_arg_1 (loc
, type
, error_mark_node
);
4831 if (TREE_CODE (canon_va_type
) != ARRAY_TYPE
)
4833 /* Case 1: Not an array type. */
4835 /* Take the address, to get '&ap'. Note that &ap is not a va_list
4837 c_common_mark_addressable_vec (expr
);
4838 expr
= build1 (ADDR_EXPR
, build_pointer_type (TREE_TYPE (expr
)), expr
);
4840 return build_va_arg_1 (loc
, type
, expr
);
4843 /* Case 2: Array type.
4847 For contrast, let's start with the simple case (case 1). If
4848 canon_va_type is not an array type, but say a char *, then when
4849 passing-by-value a va_list, the type of the va_list param decl is
4850 the same as for another va_list decl (all ap's are char *):
4853 D.1815 = VA_ARG (&ap, 0B, 1);
4859 __builtin_va_start (&ap, 0);
4862 __builtin_va_end (&ap);
4866 However, if canon_va_type is ARRAY_TYPE, then when passing-by-value a
4867 va_list the type of the va_list param decl (case 2b, struct * ap) is not
4868 the same as for another va_list decl (case 2a, struct ap[1]).
4871 D.1844 = VA_ARG (ap, 0B, 0);
4876 __builtin_va_start (&ap, 0);
4878 __builtin_va_end (&ap);
4882 Case 2b is different because:
4883 - on the callee side, the parm decl has declared type va_list, but
4884 grokdeclarator changes the type of the parm decl to a pointer to the
4886 - on the caller side, the pass-by-value uses &ap.
4888 We unify these two cases (case 2a: va_list is array type,
4889 case 2b: va_list is pointer to array elem type), by adding '&' for the
4890 array type case, such that we have a pointer to array elem in both
4893 if (TREE_CODE (va_type
) == ARRAY_TYPE
)
4895 /* Case 2a: va_list is array type. */
4897 /* Take the address, to get '&ap'. Make sure it's a pointer to array
4899 c_common_mark_addressable_vec (expr
);
4900 expr
= build1 (ADDR_EXPR
, build_pointer_type (TREE_TYPE (canon_va_type
)),
4903 /* Verify that &ap is still recognized as having va_list type. */
4904 tree canon_expr_type
4905 = targetm
.canonical_va_list_type (TREE_TYPE (expr
));
4906 gcc_assert (canon_expr_type
!= NULL_TREE
);
4910 /* Case 2b: va_list is pointer to array elem type. */
4911 gcc_assert (POINTER_TYPE_P (va_type
));
4913 /* Comparison as in std_canonical_va_list_type. */
4914 gcc_assert (TYPE_MAIN_VARIANT (TREE_TYPE (va_type
))
4915 == TYPE_MAIN_VARIANT (TREE_TYPE (canon_va_type
)));
4917 /* Don't take the address. We've already got '&ap'. */
4921 return build_va_arg_1 (loc
, type
, expr
);
4925 /* Linked list of disabled built-in functions. */
4928 struct disabled_builtin
4931 struct disabled_builtin
*next
;
4933 static disabled_builtin
*disabled_builtins
= NULL
;
4936 static bool builtin_function_disabled_p (const char *);
4939 /* Disable a built-in function specified by -fno-builtin-NAME. If NAME
4940 begins with "__builtin_", give an error. */
4943 disable_builtin_function (const char *name
)
4945 if (startswith (name
, "__builtin_"))
4946 error ("cannot disable built-in function %qs", name
);
4949 disabled_builtin
*new_disabled_builtin
= XNEW (disabled_builtin
);
4950 new_disabled_builtin
->name
= name
;
4951 new_disabled_builtin
->next
= disabled_builtins
;
4952 disabled_builtins
= new_disabled_builtin
;
4957 /* Return true if the built-in function NAME has been disabled, false
4961 builtin_function_disabled_p (const char *name
)
4963 disabled_builtin
*p
;
4964 for (p
= disabled_builtins
; p
!= NULL
; p
= p
->next
)
4966 if (strcmp (name
, p
->name
) == 0)
4973 /* Worker for DEF_BUILTIN.
4974 Possibly define a builtin function with one or two names.
4975 Does not declare a non-__builtin_ function if flag_no_builtin, or if
4976 nonansi_p and flag_no_nonansi_builtin. */
4979 def_builtin_1 (enum built_in_function fncode
,
4981 enum built_in_class fnclass
,
4982 tree fntype
, tree libtype
,
4983 bool both_p
, bool fallback_p
, bool nonansi_p
,
4984 tree fnattrs
, bool implicit_p
)
4987 const char *libname
;
4989 if (fntype
== error_mark_node
)
4992 gcc_assert ((!both_p
&& !fallback_p
)
4993 || startswith (name
, "__builtin_"));
4995 libname
= name
+ strlen ("__builtin_");
4996 decl
= add_builtin_function (name
, fntype
, fncode
, fnclass
,
4997 (fallback_p
? libname
: NULL
),
5000 set_builtin_decl (fncode
, decl
, implicit_p
);
5003 && !flag_no_builtin
&& !builtin_function_disabled_p (libname
)
5004 && !(nonansi_p
&& flag_no_nonansi_builtin
))
5005 add_builtin_function (libname
, libtype
, fncode
, fnclass
,
5009 /* Nonzero if the type T promotes to int. This is (nearly) the
5010 integral promotions defined in ISO C99 6.3.1.1/2. */
5013 c_promoting_integer_type_p (const_tree t
)
5015 switch (TREE_CODE (t
))
5018 return (TYPE_MAIN_VARIANT (t
) == char_type_node
5019 || TYPE_MAIN_VARIANT (t
) == signed_char_type_node
5020 || TYPE_MAIN_VARIANT (t
) == unsigned_char_type_node
5021 || TYPE_MAIN_VARIANT (t
) == short_integer_type_node
5022 || TYPE_MAIN_VARIANT (t
) == short_unsigned_type_node
5023 || TYPE_PRECISION (t
) < TYPE_PRECISION (integer_type_node
));
5026 /* ??? Technically all enumerations not larger than an int
5027 promote to an int. But this is used along code paths
5028 that only want to notice a size change. */
5029 return TYPE_PRECISION (t
) < TYPE_PRECISION (integer_type_node
);
5039 /* Return 1 if PARMS specifies a fixed number of parameters
5040 and none of their types is affected by default promotions. */
5043 self_promoting_args_p (const_tree parms
)
5046 for (t
= parms
; t
; t
= TREE_CHAIN (t
))
5048 tree type
= TREE_VALUE (t
);
5050 if (type
== error_mark_node
)
5053 if (TREE_CHAIN (t
) == NULL_TREE
&& type
!= void_type_node
)
5056 if (type
== NULL_TREE
)
5059 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
5062 if (c_promoting_integer_type_p (type
))
5068 /* Recursively remove any '*' or '&' operator from TYPE. */
5070 strip_pointer_operator (tree t
)
5072 while (POINTER_TYPE_P (t
))
5077 /* Recursively remove pointer or array type from TYPE. */
5079 strip_pointer_or_array_types (tree t
)
5081 while (TREE_CODE (t
) == ARRAY_TYPE
|| POINTER_TYPE_P (t
))
5086 /* Used to compare case labels. K1 and K2 are actually tree nodes
5087 representing case labels, or NULL_TREE for a `default' label.
5088 Returns -1 if K1 is ordered before K2, -1 if K1 is ordered after
5089 K2, and 0 if K1 and K2 are equal. */
5092 case_compare (splay_tree_key k1
, splay_tree_key k2
)
5094 /* Consider a NULL key (such as arises with a `default' label) to be
5095 smaller than anything else. */
5101 return tree_int_cst_compare ((tree
) k1
, (tree
) k2
);
5104 /* Process a case label, located at LOC, for the range LOW_VALUE
5105 ... HIGH_VALUE. If LOW_VALUE and HIGH_VALUE are both NULL_TREE
5106 then this case label is actually a `default' label. If only
5107 HIGH_VALUE is NULL_TREE, then case label was declared using the
5108 usual C/C++ syntax, rather than the GNU case range extension.
5109 CASES is a tree containing all the case ranges processed so far;
5110 COND is the condition for the switch-statement itself.
5111 Returns the CASE_LABEL_EXPR created, or ERROR_MARK_NODE if no
5112 CASE_LABEL_EXPR is created. */
5115 c_add_case_label (location_t loc
, splay_tree cases
, tree cond
,
5116 tree low_value
, tree high_value
)
5121 splay_tree_node node
;
5123 /* Create the LABEL_DECL itself. */
5124 label
= create_artificial_label (loc
);
5126 /* If there was an error processing the switch condition, bail now
5127 before we get more confused. */
5128 if (!cond
|| cond
== error_mark_node
)
5131 if ((low_value
&& TREE_TYPE (low_value
)
5132 && POINTER_TYPE_P (TREE_TYPE (low_value
)))
5133 || (high_value
&& TREE_TYPE (high_value
)
5134 && POINTER_TYPE_P (TREE_TYPE (high_value
))))
5136 error_at (loc
, "pointers are not permitted as case values");
5140 /* Case ranges are a GNU extension. */
5142 pedwarn (loc
, OPT_Wpedantic
,
5143 "range expressions in switch statements are non-standard");
5145 type
= TREE_TYPE (cond
);
5148 low_value
= check_case_value (loc
, low_value
);
5149 low_value
= convert_and_check (loc
, type
, low_value
);
5150 low_value
= fold (low_value
);
5151 if (low_value
== error_mark_node
)
5156 high_value
= check_case_value (loc
, high_value
);
5157 high_value
= convert_and_check (loc
, type
, high_value
);
5158 high_value
= fold (high_value
);
5159 if (high_value
== error_mark_node
)
5163 if (low_value
&& high_value
)
5165 /* If the LOW_VALUE and HIGH_VALUE are the same, then this isn't
5166 really a case range, even though it was written that way.
5167 Remove the HIGH_VALUE to simplify later processing. */
5168 if (tree_int_cst_equal (low_value
, high_value
))
5169 high_value
= NULL_TREE
;
5170 else if (!tree_int_cst_lt (low_value
, high_value
))
5171 warning_at (loc
, 0, "empty range specified");
5174 /* Look up the LOW_VALUE in the table of case labels we already
5176 node
= splay_tree_lookup (cases
, (splay_tree_key
) low_value
);
5177 /* If there was not an exact match, check for overlapping ranges.
5178 There's no need to do this if there's no LOW_VALUE or HIGH_VALUE;
5179 that's a `default' label and the only overlap is an exact match. */
5180 if (!node
&& (low_value
|| high_value
))
5182 splay_tree_node low_bound
;
5183 splay_tree_node high_bound
;
5185 /* Even though there wasn't an exact match, there might be an
5186 overlap between this case range and another case range.
5187 Since we've (inductively) not allowed any overlapping case
5188 ranges, we simply need to find the greatest low case label
5189 that is smaller that LOW_VALUE, and the smallest low case
5190 label that is greater than LOW_VALUE. If there is an overlap
5191 it will occur in one of these two ranges. */
5192 low_bound
= splay_tree_predecessor (cases
,
5193 (splay_tree_key
) low_value
);
5194 high_bound
= splay_tree_successor (cases
,
5195 (splay_tree_key
) low_value
);
5197 /* Check to see if the LOW_BOUND overlaps. It is smaller than
5198 the LOW_VALUE, so there is no need to check unless the
5199 LOW_BOUND is in fact itself a case range. */
5201 && CASE_HIGH ((tree
) low_bound
->value
)
5202 && tree_int_cst_compare (CASE_HIGH ((tree
) low_bound
->value
),
5205 /* Check to see if the HIGH_BOUND overlaps. The low end of that
5206 range is bigger than the low end of the current range, so we
5207 are only interested if the current range is a real range, and
5208 not an ordinary case label. */
5211 && (tree_int_cst_compare ((tree
) high_bound
->key
,
5216 /* If there was an overlap, issue an error. */
5219 tree duplicate
= CASE_LABEL ((tree
) node
->value
);
5223 error_at (loc
, "duplicate (or overlapping) case value");
5224 inform (DECL_SOURCE_LOCATION (duplicate
),
5225 "this is the first entry overlapping that value");
5229 error_at (loc
, "duplicate case value") ;
5230 inform (DECL_SOURCE_LOCATION (duplicate
), "previously used here");
5234 error_at (loc
, "multiple default labels in one switch");
5235 inform (DECL_SOURCE_LOCATION (duplicate
),
5236 "this is the first default label");
5241 /* Add a CASE_LABEL to the statement-tree. */
5242 case_label
= add_stmt (build_case_label (low_value
, high_value
, label
));
5243 /* Register this case label in the splay tree. */
5244 splay_tree_insert (cases
,
5245 (splay_tree_key
) low_value
,
5246 (splay_tree_value
) case_label
);
5251 /* Add a label so that the back-end doesn't think that the beginning of
5252 the switch is unreachable. Note that we do not add a case label, as
5253 that just leads to duplicates and thence to failure later on. */
5256 tree t
= create_artificial_label (loc
);
5257 add_stmt (build_stmt (loc
, LABEL_EXPR
, t
));
5259 return error_mark_node
;
5262 /* Subroutine of c_switch_covers_all_cases_p, called via
5263 splay_tree_foreach. Return 1 if it doesn't cover all the cases.
5264 ARGS[0] is initially NULL and after the first iteration is the
5265 so far highest case label. ARGS[1] is the minimum of SWITCH_COND's
5270 c_switch_covers_all_cases_p_1 (splay_tree_node node
, void *data
)
5272 tree label
= (tree
) node
->value
;
5273 tree
*args
= (tree
*) data
;
5275 /* If there is a default case, we shouldn't have called this. */
5276 gcc_assert (CASE_LOW (label
));
5278 if (args
[0] == NULL_TREE
)
5280 if (wi::to_widest (args
[1]) < wi::to_widest (CASE_LOW (label
)))
5283 else if (wi::add (wi::to_widest (args
[0]), 1)
5284 != wi::to_widest (CASE_LOW (label
)))
5286 if (CASE_HIGH (label
))
5287 args
[0] = CASE_HIGH (label
);
5289 args
[0] = CASE_LOW (label
);
5293 /* Return true if switch with CASES and switch condition with type
5294 covers all possible values in the case labels. */
5297 c_switch_covers_all_cases_p (splay_tree cases
, tree type
)
5299 /* If there is default:, this is always the case. */
5300 splay_tree_node default_node
5301 = splay_tree_lookup (cases
, (splay_tree_key
) NULL
);
5305 if (!INTEGRAL_TYPE_P (type
))
5308 tree args
[2] = { NULL_TREE
, TYPE_MIN_VALUE (type
) };
5309 if (splay_tree_foreach (cases
, c_switch_covers_all_cases_p_1
, args
))
5312 /* If there are no cases at all, or if the highest case label
5313 is smaller than TYPE_MAX_VALUE, return false. */
5314 if (args
[0] == NULL_TREE
5315 || wi::to_widest (args
[0]) < wi::to_widest (TYPE_MAX_VALUE (type
)))
5323 /* Return true if stmt can fall through. Used by block_may_fallthru
5328 c_block_may_fallthru (const_tree stmt
)
5330 switch (TREE_CODE (stmt
))
5333 return (!SWITCH_STMT_ALL_CASES_P (stmt
)
5334 || !SWITCH_STMT_NO_BREAK_P (stmt
)
5335 || block_may_fallthru (SWITCH_STMT_BODY (stmt
)));
5342 /* Finish an expression taking the address of LABEL (an
5343 IDENTIFIER_NODE). Returns an expression for the address.
5345 LOC is the location for the expression returned. */
5348 finish_label_address_expr (tree label
, location_t loc
)
5352 pedwarn (input_location
, OPT_Wpedantic
, "taking the address of a label is non-standard");
5354 if (label
== error_mark_node
)
5355 return error_mark_node
;
5357 label
= lookup_label (label
);
5358 if (label
== NULL_TREE
)
5359 result
= null_pointer_node
;
5362 TREE_USED (label
) = 1;
5363 result
= build1 (ADDR_EXPR
, ptr_type_node
, label
);
5364 /* The current function is not necessarily uninlinable.
5365 Computed gotos are incompatible with inlining, but the value
5366 here could be used only in a diagnostic, for example. */
5367 protected_set_expr_location (result
, loc
);
5374 /* Given a boolean expression ARG, return a tree representing an increment
5375 or decrement (as indicated by CODE) of ARG. The front end must check for
5376 invalid cases (e.g., decrement in C++). */
5378 boolean_increment (enum tree_code code
, tree arg
)
5381 tree true_res
= build_int_cst (TREE_TYPE (arg
), 1);
5383 arg
= stabilize_reference (arg
);
5386 case PREINCREMENT_EXPR
:
5387 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, true_res
);
5389 case POSTINCREMENT_EXPR
:
5390 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, true_res
);
5391 arg
= save_expr (arg
);
5392 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
5393 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
5395 case PREDECREMENT_EXPR
:
5396 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
5397 invert_truthvalue_loc (input_location
, arg
));
5399 case POSTDECREMENT_EXPR
:
5400 val
= build2 (MODIFY_EXPR
, TREE_TYPE (arg
), arg
,
5401 invert_truthvalue_loc (input_location
, arg
));
5402 arg
= save_expr (arg
);
5403 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
5404 val
= build2 (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
5409 TREE_SIDE_EFFECTS (val
) = 1;
5413 /* Built-in macros for stddef.h and stdint.h, that require macros
5414 defined in this file. */
5416 c_stddef_cpp_builtins(void)
5418 builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE
, 0);
5419 builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE
, 0);
5420 builtin_define_with_value ("__WCHAR_TYPE__", MODIFIED_WCHAR_TYPE
, 0);
5421 builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE
, 0);
5422 builtin_define_with_value ("__INTMAX_TYPE__", INTMAX_TYPE
, 0);
5423 builtin_define_with_value ("__UINTMAX_TYPE__", UINTMAX_TYPE
, 0);
5425 builtin_define_with_value ("__CHAR8_TYPE__", CHAR8_TYPE
, 0);
5426 builtin_define_with_value ("__CHAR16_TYPE__", CHAR16_TYPE
, 0);
5427 builtin_define_with_value ("__CHAR32_TYPE__", CHAR32_TYPE
, 0);
5428 if (SIG_ATOMIC_TYPE
)
5429 builtin_define_with_value ("__SIG_ATOMIC_TYPE__", SIG_ATOMIC_TYPE
, 0);
5431 builtin_define_with_value ("__INT8_TYPE__", INT8_TYPE
, 0);
5433 builtin_define_with_value ("__INT16_TYPE__", INT16_TYPE
, 0);
5435 builtin_define_with_value ("__INT32_TYPE__", INT32_TYPE
, 0);
5437 builtin_define_with_value ("__INT64_TYPE__", INT64_TYPE
, 0);
5439 builtin_define_with_value ("__UINT8_TYPE__", UINT8_TYPE
, 0);
5441 builtin_define_with_value ("__UINT16_TYPE__", UINT16_TYPE
, 0);
5443 builtin_define_with_value ("__UINT32_TYPE__", UINT32_TYPE
, 0);
5445 builtin_define_with_value ("__UINT64_TYPE__", UINT64_TYPE
, 0);
5446 if (INT_LEAST8_TYPE
)
5447 builtin_define_with_value ("__INT_LEAST8_TYPE__", INT_LEAST8_TYPE
, 0);
5448 if (INT_LEAST16_TYPE
)
5449 builtin_define_with_value ("__INT_LEAST16_TYPE__", INT_LEAST16_TYPE
, 0);
5450 if (INT_LEAST32_TYPE
)
5451 builtin_define_with_value ("__INT_LEAST32_TYPE__", INT_LEAST32_TYPE
, 0);
5452 if (INT_LEAST64_TYPE
)
5453 builtin_define_with_value ("__INT_LEAST64_TYPE__", INT_LEAST64_TYPE
, 0);
5454 if (UINT_LEAST8_TYPE
)
5455 builtin_define_with_value ("__UINT_LEAST8_TYPE__", UINT_LEAST8_TYPE
, 0);
5456 if (UINT_LEAST16_TYPE
)
5457 builtin_define_with_value ("__UINT_LEAST16_TYPE__", UINT_LEAST16_TYPE
, 0);
5458 if (UINT_LEAST32_TYPE
)
5459 builtin_define_with_value ("__UINT_LEAST32_TYPE__", UINT_LEAST32_TYPE
, 0);
5460 if (UINT_LEAST64_TYPE
)
5461 builtin_define_with_value ("__UINT_LEAST64_TYPE__", UINT_LEAST64_TYPE
, 0);
5463 builtin_define_with_value ("__INT_FAST8_TYPE__", INT_FAST8_TYPE
, 0);
5464 if (INT_FAST16_TYPE
)
5465 builtin_define_with_value ("__INT_FAST16_TYPE__", INT_FAST16_TYPE
, 0);
5466 if (INT_FAST32_TYPE
)
5467 builtin_define_with_value ("__INT_FAST32_TYPE__", INT_FAST32_TYPE
, 0);
5468 if (INT_FAST64_TYPE
)
5469 builtin_define_with_value ("__INT_FAST64_TYPE__", INT_FAST64_TYPE
, 0);
5470 if (UINT_FAST8_TYPE
)
5471 builtin_define_with_value ("__UINT_FAST8_TYPE__", UINT_FAST8_TYPE
, 0);
5472 if (UINT_FAST16_TYPE
)
5473 builtin_define_with_value ("__UINT_FAST16_TYPE__", UINT_FAST16_TYPE
, 0);
5474 if (UINT_FAST32_TYPE
)
5475 builtin_define_with_value ("__UINT_FAST32_TYPE__", UINT_FAST32_TYPE
, 0);
5476 if (UINT_FAST64_TYPE
)
5477 builtin_define_with_value ("__UINT_FAST64_TYPE__", UINT_FAST64_TYPE
, 0);
5479 builtin_define_with_value ("__INTPTR_TYPE__", INTPTR_TYPE
, 0);
5481 builtin_define_with_value ("__UINTPTR_TYPE__", UINTPTR_TYPE
, 0);
5482 /* GIMPLE FE testcases need access to the GCC internal 'sizetype'.
5483 Expose it as __SIZETYPE__. */
5485 builtin_define_with_value ("__SIZETYPE__", SIZETYPE
, 0);
5490 c_init_attributes (void)
5492 /* Fill in the built_in_attributes array. */
5493 #define DEF_ATTR_NULL_TREE(ENUM) \
5494 built_in_attributes[(int) ENUM] = NULL_TREE;
5495 #define DEF_ATTR_INT(ENUM, VALUE) \
5496 built_in_attributes[(int) ENUM] = build_int_cst (integer_type_node, VALUE);
5497 #define DEF_ATTR_STRING(ENUM, VALUE) \
5498 built_in_attributes[(int) ENUM] = build_string (strlen (VALUE), VALUE);
5499 #define DEF_ATTR_IDENT(ENUM, STRING) \
5500 built_in_attributes[(int) ENUM] = get_identifier (STRING);
5501 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \
5502 built_in_attributes[(int) ENUM] \
5503 = tree_cons (built_in_attributes[(int) PURPOSE], \
5504 built_in_attributes[(int) VALUE], \
5505 built_in_attributes[(int) CHAIN]);
5506 #include "builtin-attrs.def"
5507 #undef DEF_ATTR_NULL_TREE
5509 #undef DEF_ATTR_IDENT
5510 #undef DEF_ATTR_TREE_LIST
5514 /* Check whether the byte alignment ALIGN is a valid user-specified
5515 alignment less than the supported maximum. If so, return ALIGN's
5516 base-2 log; if not, output an error and return -1. If OBJFILE
5517 then reject alignments greater than MAX_OFILE_ALIGNMENT when
5518 converted to bits. Otherwise, consider valid only alignments
5519 that are less than HOST_BITS_PER_INT - LOG2_BITS_PER_UNIT.
5520 Zero is not considered a valid argument (and results in -1 on
5521 return) but it only triggers a warning when WARN_ZERO is set. */
5524 check_user_alignment (const_tree align
, bool objfile
, bool warn_zero
)
5526 if (error_operand_p (align
))
5529 if (TREE_CODE (align
) != INTEGER_CST
5530 || !INTEGRAL_TYPE_P (TREE_TYPE (align
)))
5532 error ("requested alignment is not an integer constant");
5536 if (integer_zerop (align
))
5539 warning (OPT_Wattributes
,
5540 "requested alignment %qE is not a positive power of 2",
5545 /* Log2 of the byte alignment ALIGN. */
5547 if (tree_int_cst_sgn (align
) == -1
5548 || (log2align
= tree_log2 (align
)) == -1)
5550 error ("requested alignment %qE is not a positive power of 2",
5557 unsigned maxalign
= MAX_OFILE_ALIGNMENT
/ BITS_PER_UNIT
;
5558 if (!tree_fits_uhwi_p (align
) || tree_to_uhwi (align
) > maxalign
)
5560 error ("requested alignment %qE exceeds object file maximum %u",
5566 if (log2align
>= HOST_BITS_PER_INT
- LOG2_BITS_PER_UNIT
)
5568 error ("requested alignment %qE exceeds maximum %u",
5569 align
, 1U << (HOST_BITS_PER_INT
- LOG2_BITS_PER_UNIT
- 1));
5576 /* Determine the ELF symbol visibility for DECL, which is either a
5577 variable or a function. It is an error to use this function if a
5578 definition of DECL is not available in this translation unit.
5579 Returns true if the final visibility has been determined by this
5580 function; false if the caller is free to make additional
5584 c_determine_visibility (tree decl
)
5586 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl
));
5588 /* If the user explicitly specified the visibility with an
5589 attribute, honor that. DECL_VISIBILITY will have been set during
5590 the processing of the attribute. We check for an explicit
5591 attribute, rather than just checking DECL_VISIBILITY_SPECIFIED,
5592 to distinguish the use of an attribute from the use of a "#pragma
5593 GCC visibility push(...)"; in the latter case we still want other
5594 considerations to be able to overrule the #pragma. */
5595 if (lookup_attribute ("visibility", DECL_ATTRIBUTES (decl
))
5596 || (TARGET_DLLIMPORT_DECL_ATTRIBUTES
5597 && (lookup_attribute ("dllimport", DECL_ATTRIBUTES (decl
))
5598 || lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl
)))))
5601 /* Set default visibility to whatever the user supplied with
5602 visibility_specified depending on #pragma GCC visibility. */
5603 if (!DECL_VISIBILITY_SPECIFIED (decl
))
5605 if (visibility_options
.inpragma
5606 || DECL_VISIBILITY (decl
) != default_visibility
)
5608 DECL_VISIBILITY (decl
) = default_visibility
;
5609 DECL_VISIBILITY_SPECIFIED (decl
) = visibility_options
.inpragma
;
5610 /* If visibility changed and DECL already has DECL_RTL, ensure
5611 symbol flags are updated. */
5612 if (((VAR_P (decl
) && TREE_STATIC (decl
))
5613 || TREE_CODE (decl
) == FUNCTION_DECL
)
5614 && DECL_RTL_SET_P (decl
))
5615 make_decl_rtl (decl
);
5621 /* Data to communicate through check_function_arguments_recurse between
5622 check_function_nonnull and check_nonnull_arg. */
5624 struct nonnull_arg_ctx
5626 /* Location of the call. */
5628 /* The function whose arguments are being checked and its type (used
5629 for calls through function pointers). */
5630 const_tree fndecl
, fntype
;
5631 /* True if a warning has been issued. */
5635 /* Check the argument list of a function call to CTX.FNDECL of CTX.FNTYPE
5636 for null in argument slots that are marked as requiring a non-null
5637 pointer argument. The NARGS arguments are passed in the array ARGARRAY.
5638 Return true if we have warned. */
5641 check_function_nonnull (nonnull_arg_ctx
&ctx
, int nargs
, tree
*argarray
)
5644 if (TREE_CODE (ctx
.fntype
) == METHOD_TYPE
)
5646 bool closure
= false;
5649 /* For certain lambda expressions the C++ front end emits calls
5650 that pass a null this pointer as an argument named __closure
5651 to the member operator() of empty function. Detect those
5652 and avoid checking them, but proceed to check the remaining
5654 tree arg0
= DECL_ARGUMENTS (ctx
.fndecl
);
5655 if (tree arg0name
= DECL_NAME (arg0
))
5656 closure
= id_equal (arg0name
, "__closure");
5659 /* In calls to C++ non-static member functions check the this
5660 pointer regardless of whether the function is declared with
5661 attribute nonnull. */
5664 check_function_arguments_recurse (check_nonnull_arg
, &ctx
, argarray
[0],
5665 firstarg
, OPT_Wnonnull
);
5668 tree attrs
= lookup_attribute ("nonnull", TYPE_ATTRIBUTES (ctx
.fntype
));
5669 if (attrs
== NULL_TREE
)
5670 return ctx
.warned_p
;
5673 /* See if any of the nonnull attributes has no arguments. If so,
5674 then every pointer argument is checked (in which case the check
5675 for pointer type is done in check_nonnull_arg). */
5676 if (TREE_VALUE (a
) != NULL_TREE
)
5678 a
= lookup_attribute ("nonnull", TREE_CHAIN (a
));
5679 while (a
!= NULL_TREE
&& TREE_VALUE (a
) != NULL_TREE
);
5682 for (int i
= firstarg
; i
< nargs
; i
++)
5683 check_function_arguments_recurse (check_nonnull_arg
, &ctx
, argarray
[i
],
5684 i
+ 1, OPT_Wnonnull
);
5687 /* Walk the argument list. If we encounter an argument number we
5688 should check for non-null, do it. */
5689 for (int i
= firstarg
; i
< nargs
; i
++)
5691 for (a
= attrs
; ; a
= TREE_CHAIN (a
))
5693 a
= lookup_attribute ("nonnull", a
);
5694 if (a
== NULL_TREE
|| nonnull_check_p (TREE_VALUE (a
), i
+ 1))
5699 check_function_arguments_recurse (check_nonnull_arg
, &ctx
,
5704 return ctx
.warned_p
;
5707 /* Check that the Nth argument of a function call (counting backwards
5708 from the end) is a (pointer)0. The NARGS arguments are passed in the
5712 check_function_sentinel (const_tree fntype
, int nargs
, tree
*argarray
)
5714 tree attr
= lookup_attribute ("sentinel", TYPE_ATTRIBUTES (fntype
));
5721 function_args_iterator iter
;
5724 /* Skip over the named arguments. */
5725 FOREACH_FUNCTION_ARGS (fntype
, t
, iter
)
5732 if (TREE_VALUE (attr
))
5734 tree p
= TREE_VALUE (TREE_VALUE (attr
));
5735 pos
= TREE_INT_CST_LOW (p
);
5738 /* The sentinel must be one of the varargs, i.e.
5739 in position >= the number of fixed arguments. */
5740 if ((nargs
- 1 - pos
) < len
)
5742 warning (OPT_Wformat_
,
5743 "not enough variable arguments to fit a sentinel");
5747 /* Validate the sentinel. */
5748 sentinel
= fold_for_warn (argarray
[nargs
- 1 - pos
]);
5749 if ((!POINTER_TYPE_P (TREE_TYPE (sentinel
))
5750 || !integer_zerop (sentinel
))
5751 /* Although __null (in C++) is only an integer we allow it
5752 nevertheless, as we are guaranteed that it's exactly
5753 as wide as a pointer, and we don't want to force
5754 users to cast the NULL they have written there.
5755 We warn with -Wstrict-null-sentinel, though. */
5756 && (warn_strict_null_sentinel
|| null_node
!= sentinel
))
5757 warning (OPT_Wformat_
, "missing sentinel in function call");
5761 /* Check that the same argument isn't passed to two or more
5762 restrict-qualified formal and issue a -Wrestrict warning
5763 if it is. Return true if a warning has been issued. */
5766 check_function_restrict (const_tree fndecl
, const_tree fntype
,
5767 int nargs
, tree
*unfolded_argarray
)
5770 tree parms
= TYPE_ARG_TYPES (fntype
);
5772 /* Call fold_for_warn on all of the arguments. */
5773 auto_vec
<tree
> argarray (nargs
);
5774 for (i
= 0; i
< nargs
; i
++)
5775 argarray
.quick_push (fold_for_warn (unfolded_argarray
[i
]));
5778 && TREE_CODE (fndecl
) == FUNCTION_DECL
)
5780 /* Avoid diagnosing calls built-ins with a zero size/bound
5781 here. They are checked in more detail elsewhere. */
5782 if (fndecl_built_in_p (fndecl
, BUILT_IN_NORMAL
)
5784 && TREE_CODE (argarray
[2]) == INTEGER_CST
5785 && integer_zerop (argarray
[2]))
5788 if (DECL_ARGUMENTS (fndecl
))
5789 parms
= DECL_ARGUMENTS (fndecl
);
5792 for (i
= 0; i
< nargs
; i
++)
5793 TREE_VISITED (argarray
[i
]) = 0;
5795 bool warned
= false;
5797 for (i
= 0; i
< nargs
&& parms
&& parms
!= void_list_node
; i
++)
5800 if (TREE_CODE (parms
) == PARM_DECL
)
5802 type
= TREE_TYPE (parms
);
5803 parms
= DECL_CHAIN (parms
);
5807 type
= TREE_VALUE (parms
);
5808 parms
= TREE_CHAIN (parms
);
5810 if (POINTER_TYPE_P (type
)
5811 && TYPE_RESTRICT (type
)
5812 && !TYPE_READONLY (TREE_TYPE (type
)))
5813 warned
|= warn_for_restrict (i
, argarray
.address (), nargs
);
5816 for (i
= 0; i
< nargs
; i
++)
5817 TREE_VISITED (argarray
[i
]) = 0;
5822 /* Helper for check_function_nonnull; given a list of operands which
5823 must be non-null in ARGS, determine if operand PARAM_NUM should be
5827 nonnull_check_p (tree args
, unsigned HOST_WIDE_INT param_num
)
5829 unsigned HOST_WIDE_INT arg_num
= 0;
5831 for (; args
; args
= TREE_CHAIN (args
))
5833 bool found
= get_attribute_operand (TREE_VALUE (args
), &arg_num
);
5837 if (arg_num
== param_num
)
5843 /* Check that the function argument PARAM (which is operand number
5844 PARAM_NUM) is non-null. This is called by check_function_nonnull
5845 via check_function_arguments_recurse. */
5848 check_nonnull_arg (void *ctx
, tree param
, unsigned HOST_WIDE_INT param_num
)
5850 struct nonnull_arg_ctx
*pctx
= (struct nonnull_arg_ctx
*) ctx
;
5852 /* Just skip checking the argument if it's not a pointer. This can
5853 happen if the "nonnull" attribute was given without an operand
5854 list (which means to check every pointer argument). */
5856 tree paramtype
= TREE_TYPE (param
);
5857 if (TREE_CODE (paramtype
) != POINTER_TYPE
5858 && TREE_CODE (paramtype
) != NULLPTR_TYPE
)
5861 /* Diagnose the simple cases of null arguments. */
5862 if (!integer_zerop (fold_for_warn (param
)))
5865 auto_diagnostic_group adg
;
5867 const location_t loc
= EXPR_LOC_OR_LOC (param
, pctx
->loc
);
5869 if (TREE_CODE (pctx
->fntype
) == METHOD_TYPE
)
5875 warned
= warning_at (loc
, OPT_Wnonnull
,
5876 "%qs pointer is null", "this");
5877 if (warned
&& pctx
->fndecl
)
5878 inform (DECL_SOURCE_LOCATION (pctx
->fndecl
),
5879 "in a call to non-static member function %qD",
5884 warned
= warning_at (loc
, OPT_Wnonnull
,
5885 "argument %u null where non-null expected",
5886 (unsigned) param_num
);
5887 if (warned
&& pctx
->fndecl
)
5888 inform (DECL_SOURCE_LOCATION (pctx
->fndecl
),
5889 "in a call to function %qD declared %qs",
5890 pctx
->fndecl
, "nonnull");
5894 pctx
->warned_p
= true;
5897 /* Helper for attribute handling; fetch the operand number from
5898 the attribute argument list. */
5901 get_attribute_operand (tree arg_num_expr
, unsigned HOST_WIDE_INT
*valp
)
5903 /* Verify the arg number is a small constant. */
5904 if (tree_fits_uhwi_p (arg_num_expr
))
5906 *valp
= tree_to_uhwi (arg_num_expr
);
5913 /* Arguments being collected for optimization. */
5914 typedef const char *const_char_p
; /* For DEF_VEC_P. */
5915 static GTY(()) vec
<const_char_p
, va_gc
> *optimize_args
;
5918 /* Inner function to convert a TREE_LIST to argv string to parse the optimize
5919 options in ARGS. ATTR_P is true if this is for attribute(optimize), and
5920 false for #pragma GCC optimize. */
5923 parse_optimize_options (tree args
, bool attr_p
)
5927 (void) optimize_args
;
5928 gcc_assert(0 && "opt");
5934 const char **opt_argv
;
5935 struct cl_decoded_option
*decoded_options
;
5936 unsigned int decoded_options_count
;
5939 /* Build up argv vector. Just in case the string is stored away, use garbage
5940 collected strings. */
5941 vec_safe_truncate (optimize_args
, 0);
5942 vec_safe_push (optimize_args
, (const char *) NULL
);
5944 for (ap
= args
; ap
!= NULL_TREE
; ap
= TREE_CHAIN (ap
))
5946 tree value
= TREE_VALUE (ap
);
5948 if (TREE_CODE (value
) == INTEGER_CST
)
5950 char buffer
[HOST_BITS_PER_LONG
/ 3 + 4];
5951 sprintf (buffer
, "-O%ld", (long) TREE_INT_CST_LOW (value
));
5952 vec_safe_push (optimize_args
, ggc_strdup (buffer
));
5955 else if (TREE_CODE (value
) == STRING_CST
)
5957 /* Split string into multiple substrings. */
5958 size_t len
= TREE_STRING_LENGTH (value
);
5959 char *p
= ASTRDUP (TREE_STRING_POINTER (value
));
5960 char *end
= p
+ len
;
5964 while (next_p
!= NULL
)
5970 comma
= strchr (p
, ',');
5983 /* If the user supplied -Oxxx or -fxxx, only allow -Oxxx or -fxxx
5985 if (*p
== '-' && p
[1] != 'O' && p
[1] != 'f')
5989 warning (OPT_Wattributes
,
5990 "bad option %qs to attribute %<optimize%>", p
);
5992 warning (OPT_Wpragmas
,
5993 "bad option %qs to pragma %<optimize%>", p
);
5997 /* Can't use GC memory here, see PR88007. */
5998 r
= q
= XOBNEWVEC (&opts_obstack
, char, len2
+ 3);
6004 /* Assume that Ox is -Ox, a numeric value is -Ox, a s by
6005 itself is -Os, and any other switch begins with a -f. */
6006 if ((*p
>= '0' && *p
<= '9')
6007 || (p
[0] == 's' && p
[1] == '\0'))
6013 memcpy (r
, p
, len2
);
6015 vec_safe_push (optimize_args
, (const char *) q
);
6021 opt_argc
= optimize_args
->length ();
6022 opt_argv
= (const char **) alloca (sizeof (char *) * (opt_argc
+ 1));
6024 for (i
= 1; i
< opt_argc
; i
++)
6025 opt_argv
[i
] = (*optimize_args
)[i
];
6027 /* Now parse the options. */
6028 decode_cmdline_options_to_array_default_mask (opt_argc
, opt_argv
,
6030 &decoded_options_count
);
6031 /* Drop non-Optimization options. */
6033 for (i
= 1; i
< decoded_options_count
; ++i
)
6035 if (! (cl_options
[decoded_options
[i
].opt_index
].flags
& CL_OPTIMIZATION
))
6039 warning (OPT_Wattributes
,
6040 "bad option %qs to attribute %<optimize%>",
6041 decoded_options
[i
].orig_option_with_args_text
);
6043 warning (OPT_Wpragmas
,
6044 "bad option %qs to pragma %<optimize%>",
6045 decoded_options
[i
].orig_option_with_args_text
);
6049 decoded_options
[j
] = decoded_options
[i
];
6052 decoded_options_count
= j
;
6054 /* Merge the decoded options with save_decoded_options. */
6055 unsigned save_opt_count
= save_opt_decoded_options
->length ();
6056 unsigned merged_decoded_options_count
6057 = save_opt_count
+ decoded_options_count
;
6058 cl_decoded_option
*merged_decoded_options
6059 = XNEWVEC (cl_decoded_option
, merged_decoded_options_count
);
6061 /* Note the first decoded_options is used for the program name. */
6062 for (unsigned i
= 0; i
< save_opt_count
; ++i
)
6063 merged_decoded_options
[i
+ 1] = (*save_opt_decoded_options
)[i
];
6064 for (unsigned i
= 1; i
< decoded_options_count
; ++i
)
6065 merged_decoded_options
[save_opt_count
+ i
] = decoded_options
[i
];
6067 /* And apply them. */
6068 decode_options (&global_options
, &global_options_set
,
6069 merged_decoded_options
, merged_decoded_options_count
,
6070 input_location
, global_dc
, NULL
);
6071 free (decoded_options
);
6073 targetm
.override_options_after_change();
6075 optimize_args
->truncate (0);
6080 /* Check whether ATTR is a valid attribute fallthrough. */
6083 attribute_fallthrough_p (tree attr
)
6085 if (attr
== error_mark_node
)
6087 tree t
= lookup_attribute ("fallthrough", attr
);
6090 /* It is no longer true that "this attribute shall appear at most once in
6091 each attribute-list", but we still give a warning. */
6092 if (lookup_attribute ("fallthrough", TREE_CHAIN (t
)))
6093 warning (OPT_Wattributes
, "attribute %<fallthrough%> specified multiple "
6095 /* No attribute-argument-clause shall be present. */
6096 else if (TREE_VALUE (t
) != NULL_TREE
)
6097 warning (OPT_Wattributes
, "%<fallthrough%> attribute specified with "
6099 /* Warn if other attributes are found. */
6100 for (t
= attr
; t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
6102 tree name
= get_attribute_name (t
);
6103 if (!is_attribute_p ("fallthrough", name
))
6105 if (!c_dialect_cxx () && get_attribute_namespace (t
) == NULL_TREE
)
6106 /* The specifications of standard attributes in C mean
6107 this is a constraint violation. */
6108 pedwarn (input_location
, OPT_Wattributes
, "%qE attribute ignored",
6109 get_attribute_name (t
));
6111 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
6118 /* Check for valid arguments being passed to a function with FNTYPE.
6119 There are NARGS arguments in the array ARGARRAY. LOC should be used
6120 for diagnostics. Return true if either -Wnonnull or -Wrestrict has
6123 The arguments in ARGARRAY may not have been folded yet (e.g. for C++,
6124 to preserve location wrappers); checks that require folded arguments
6125 should call fold_for_warn on them. */
6128 check_function_arguments (location_t loc
, const_tree fndecl
, const_tree fntype
,
6129 int nargs
, tree
*argarray
, vec
<location_t
> *arglocs
)
6131 bool warned_p
= false;
6133 /* Check for null being passed in a pointer argument that must be
6134 non-null. In C++, this includes the this pointer. We also need
6135 to do this if format checking is enabled. */
6138 nonnull_arg_ctx ctx
= { loc
, fndecl
, fntype
, false };
6139 warned_p
= check_function_nonnull (ctx
, nargs
, argarray
);
6142 /* Check for errors in format strings. */
6144 if (warn_format
|| warn_suggest_attribute_format
)
6145 check_function_format (fntype
, TYPE_ATTRIBUTES (fntype
), nargs
, argarray
,
6149 check_function_sentinel (fntype
, nargs
, argarray
);
6151 if (fndecl
&& fndecl_built_in_p (fndecl
, BUILT_IN_NORMAL
))
6153 switch (DECL_FUNCTION_CODE (fndecl
))
6155 case BUILT_IN_SPRINTF
:
6156 case BUILT_IN_SPRINTF_CHK
:
6157 case BUILT_IN_SNPRINTF
:
6158 case BUILT_IN_SNPRINTF_CHK
:
6159 /* Let the sprintf pass handle these. */
6167 /* check_function_restrict sets the DECL_READ_P for arguments
6168 so it must be called unconditionally. */
6169 warned_p
|= check_function_restrict (fndecl
, fntype
, nargs
, argarray
);
6174 /* Generic argument checking recursion routine. PARAM is the argument to
6175 be checked. PARAM_NUM is the number of the argument. CALLBACK is invoked
6176 once the argument is resolved. CTX is context for the callback.
6177 OPT is the warning for which this is done. */
6179 check_function_arguments_recurse (void (*callback
)
6180 (void *, tree
, unsigned HOST_WIDE_INT
),
6181 void *ctx
, tree param
,
6182 unsigned HOST_WIDE_INT param_num
,
6185 if (opt
!= OPT_Wformat_
&& warning_suppressed_p (param
))
6188 if (CONVERT_EXPR_P (param
)
6189 && (TYPE_PRECISION (TREE_TYPE (param
))
6190 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (param
, 0)))))
6192 /* Strip coercion. */
6193 check_function_arguments_recurse (callback
, ctx
,
6194 TREE_OPERAND (param
, 0), param_num
,
6199 if (TREE_CODE (param
) == CALL_EXPR
&& CALL_EXPR_FN (param
))
6201 tree type
= TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (param
)));
6203 bool found_format_arg
= false;
6205 /* See if this is a call to a known internationalization function
6206 that modifies a format arg. Such a function may have multiple
6207 format_arg attributes (for example, ngettext). */
6209 for (attrs
= TYPE_ATTRIBUTES (type
);
6211 attrs
= TREE_CHAIN (attrs
))
6212 if (is_attribute_p ("format_arg", get_attribute_name (attrs
)))
6215 tree format_num_expr
;
6218 call_expr_arg_iterator iter
;
6220 /* Extract the argument number, which was previously checked
6222 format_num_expr
= TREE_VALUE (TREE_VALUE (attrs
));
6224 format_num
= tree_to_uhwi (format_num_expr
);
6226 for (inner_arg
= first_call_expr_arg (param
, &iter
), i
= 1;
6227 inner_arg
!= NULL_TREE
;
6228 inner_arg
= next_call_expr_arg (&iter
), i
++)
6229 if (i
== format_num
)
6231 check_function_arguments_recurse (callback
, ctx
,
6232 inner_arg
, param_num
,
6234 found_format_arg
= true;
6239 /* If we found a format_arg attribute and did a recursive check,
6240 we are done with checking this argument. Otherwise, we continue
6241 and this will be considered a non-literal. */
6242 if (found_format_arg
)
6246 if (TREE_CODE (param
) == COND_EXPR
)
6248 /* Simplify to avoid warning for an impossible case. */
6249 param
= fold_for_warn (param
);
6250 if (TREE_CODE (param
) == COND_EXPR
)
6252 /* Check both halves of the conditional expression. */
6253 check_function_arguments_recurse (callback
, ctx
,
6254 TREE_OPERAND (param
, 1),
6256 check_function_arguments_recurse (callback
, ctx
,
6257 TREE_OPERAND (param
, 2),
6263 (*callback
) (ctx
, param
, param_num
);
6266 /* Checks for a builtin function FNDECL that the number of arguments
6267 NARGS against the required number REQUIRED and issues an error if
6268 there is a mismatch. Returns true if the number of arguments is
6269 correct, otherwise false. LOC is the location of FNDECL. */
6272 builtin_function_validate_nargs (location_t loc
, tree fndecl
, int nargs
,
6275 if (nargs
< required
)
6277 error_at (loc
, "too few arguments to function %qE", fndecl
);
6280 else if (nargs
> required
)
6282 error_at (loc
, "too many arguments to function %qE", fndecl
);
6288 /* Helper macro for check_builtin_function_arguments. */
6289 #define ARG_LOCATION(N) \
6290 (arg_loc.is_empty () \
6291 ? EXPR_LOC_OR_LOC (args[(N)], input_location) \
6292 : expansion_point_location (arg_loc[(N)]))
6294 /* Verifies the NARGS arguments ARGS to the builtin function FNDECL.
6295 Returns false if there was an error, otherwise true. LOC is the
6296 location of the function; ARG_LOC is a vector of locations of the
6297 arguments. If FNDECL is the result of resolving an overloaded
6298 target built-in, ORIG_FNDECL is the original function decl,
6299 otherwise it is null. */
6302 check_builtin_function_arguments (location_t loc
, vec
<location_t
> arg_loc
,
6303 tree fndecl
, tree orig_fndecl
,
6304 int nargs
, tree
*args
)
6306 if (!fndecl_built_in_p (fndecl
))
6309 if (DECL_BUILT_IN_CLASS (fndecl
) == BUILT_IN_MD
)
6310 return (!targetm
.check_builtin_call
6311 || targetm
.check_builtin_call (loc
, arg_loc
, fndecl
,
6312 orig_fndecl
, nargs
, args
));
6314 if (DECL_BUILT_IN_CLASS (fndecl
) == BUILT_IN_FRONTEND
)
6317 gcc_assert (DECL_BUILT_IN_CLASS (fndecl
) == BUILT_IN_NORMAL
);
6318 switch (DECL_FUNCTION_CODE (fndecl
))
6320 case BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX
:
6321 if (!tree_fits_uhwi_p (args
[2]))
6323 error_at (ARG_LOCATION (2),
6324 "third argument to function %qE must be a constant integer",
6330 case BUILT_IN_ALLOCA_WITH_ALIGN
:
6332 /* Get the requested alignment (in bits) if it's a constant
6333 integer expression. */
6334 unsigned HOST_WIDE_INT align
6335 = tree_fits_uhwi_p (args
[1]) ? tree_to_uhwi (args
[1]) : 0;
6337 /* Determine if the requested alignment is a power of 2. */
6338 if ((align
& (align
- 1)))
6341 /* The maximum alignment in bits corresponding to the same
6342 maximum in bytes enforced in check_user_alignment(). */
6343 unsigned maxalign
= (UINT_MAX
>> 1) + 1;
6345 /* Reject invalid alignments. */
6346 if (align
< BITS_PER_UNIT
|| maxalign
< align
)
6348 error_at (ARG_LOCATION (1),
6349 "second argument to function %qE must be a constant "
6350 "integer power of 2 between %qi and %qu bits",
6351 fndecl
, BITS_PER_UNIT
, maxalign
);
6357 case BUILT_IN_CONSTANT_P
:
6358 return builtin_function_validate_nargs (loc
, fndecl
, nargs
, 1);
6360 case BUILT_IN_ISFINITE
:
6361 case BUILT_IN_ISINF
:
6362 case BUILT_IN_ISINF_SIGN
:
6363 case BUILT_IN_ISNAN
:
6364 case BUILT_IN_ISNORMAL
:
6365 case BUILT_IN_SIGNBIT
:
6366 if (builtin_function_validate_nargs (loc
, fndecl
, nargs
, 1))
6368 if (TREE_CODE (TREE_TYPE (args
[0])) != REAL_TYPE
)
6370 error_at (ARG_LOCATION (0), "non-floating-point argument in "
6371 "call to function %qE", fndecl
);
6378 case BUILT_IN_ISGREATER
:
6379 case BUILT_IN_ISGREATEREQUAL
:
6380 case BUILT_IN_ISLESS
:
6381 case BUILT_IN_ISLESSEQUAL
:
6382 case BUILT_IN_ISLESSGREATER
:
6383 case BUILT_IN_ISUNORDERED
:
6384 if (builtin_function_validate_nargs (loc
, fndecl
, nargs
, 2))
6386 enum tree_code code0
, code1
;
6387 code0
= TREE_CODE (TREE_TYPE (args
[0]));
6388 code1
= TREE_CODE (TREE_TYPE (args
[1]));
6389 if (!((code0
== REAL_TYPE
&& code1
== REAL_TYPE
)
6390 || (code0
== REAL_TYPE
&& code1
== INTEGER_TYPE
)
6391 || (code0
== INTEGER_TYPE
&& code1
== REAL_TYPE
)))
6393 error_at (loc
, "non-floating-point arguments in call to "
6394 "function %qE", fndecl
);
6401 case BUILT_IN_FPCLASSIFY
:
6402 if (builtin_function_validate_nargs (loc
, fndecl
, nargs
, 6))
6404 for (unsigned int i
= 0; i
< 5; i
++)
6405 if (TREE_CODE (args
[i
]) != INTEGER_CST
)
6407 error_at (ARG_LOCATION (i
), "non-const integer argument %u in "
6408 "call to function %qE", i
+ 1, fndecl
);
6412 if (TREE_CODE (TREE_TYPE (args
[5])) != REAL_TYPE
)
6414 error_at (ARG_LOCATION (5), "non-floating-point argument in "
6415 "call to function %qE", fndecl
);
6422 case BUILT_IN_ASSUME_ALIGNED
:
6423 if (builtin_function_validate_nargs (loc
, fndecl
, nargs
, 2 + (nargs
> 2)))
6425 if (nargs
>= 3 && TREE_CODE (TREE_TYPE (args
[2])) != INTEGER_TYPE
)
6427 error_at (ARG_LOCATION (2), "non-integer argument 3 in call to "
6428 "function %qE", fndecl
);
6435 case BUILT_IN_ADD_OVERFLOW
:
6436 case BUILT_IN_SUB_OVERFLOW
:
6437 case BUILT_IN_MUL_OVERFLOW
:
6438 if (builtin_function_validate_nargs (loc
, fndecl
, nargs
, 3))
6441 for (i
= 0; i
< 2; i
++)
6442 if (!INTEGRAL_TYPE_P (TREE_TYPE (args
[i
])))
6444 error_at (ARG_LOCATION (i
), "argument %u in call to function "
6445 "%qE does not have integral type", i
+ 1, fndecl
);
6448 if (TREE_CODE (TREE_TYPE (args
[2])) != POINTER_TYPE
6449 || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (args
[2]))))
6451 error_at (ARG_LOCATION (2), "argument 3 in call to function %qE "
6452 "does not have pointer to integral type", fndecl
);
6455 else if (TREE_CODE (TREE_TYPE (TREE_TYPE (args
[2]))) == ENUMERAL_TYPE
)
6457 error_at (ARG_LOCATION (2), "argument 3 in call to function %qE "
6458 "has pointer to enumerated type", fndecl
);
6461 else if (TREE_CODE (TREE_TYPE (TREE_TYPE (args
[2]))) == BOOLEAN_TYPE
)
6463 error_at (ARG_LOCATION (2), "argument 3 in call to function %qE "
6464 "has pointer to boolean type", fndecl
);
6467 else if (TYPE_READONLY (TREE_TYPE (TREE_TYPE (args
[2]))))
6469 error_at (ARG_LOCATION (2), "argument %u in call to function %qE "
6470 "has pointer to %qs type (%qT)", 3, fndecl
, "const",
6471 TREE_TYPE (args
[2]));
6474 else if (TYPE_ATOMIC (TREE_TYPE (TREE_TYPE (args
[2]))))
6476 error_at (ARG_LOCATION (2), "argument %u in call to function %qE "
6477 "has pointer to %qs type (%qT)", 3, fndecl
,
6478 "_Atomic", TREE_TYPE (args
[2]));
6485 case BUILT_IN_ADD_OVERFLOW_P
:
6486 case BUILT_IN_SUB_OVERFLOW_P
:
6487 case BUILT_IN_MUL_OVERFLOW_P
:
6488 if (builtin_function_validate_nargs (loc
, fndecl
, nargs
, 3))
6491 for (i
= 0; i
< 3; i
++)
6492 if (!INTEGRAL_TYPE_P (TREE_TYPE (args
[i
])))
6494 error_at (ARG_LOCATION (i
), "argument %u in call to function "
6495 "%qE does not have integral type", i
+ 1, fndecl
);
6498 if (TREE_CODE (TREE_TYPE (args
[2])) == ENUMERAL_TYPE
)
6500 error_at (ARG_LOCATION (2), "argument 3 in call to function "
6501 "%qE has enumerated type", fndecl
);
6504 else if (TREE_CODE (TREE_TYPE (args
[2])) == BOOLEAN_TYPE
)
6506 error_at (ARG_LOCATION (2), "argument 3 in call to function "
6507 "%qE has boolean type", fndecl
);
6514 case BUILT_IN_CLEAR_PADDING
:
6515 if (builtin_function_validate_nargs (loc
, fndecl
, nargs
, 1))
6517 if (!POINTER_TYPE_P (TREE_TYPE (args
[0])))
6519 error_at (ARG_LOCATION (0), "argument %u in call to function "
6520 "%qE does not have pointer type", 1, fndecl
);
6523 else if (!COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (args
[0]))))
6525 error_at (ARG_LOCATION (0), "argument %u in call to function "
6526 "%qE points to incomplete type", 1, fndecl
);
6529 else if (TYPE_READONLY (TREE_TYPE (TREE_TYPE (args
[0]))))
6531 error_at (ARG_LOCATION (0), "argument %u in call to function %qE "
6532 "has pointer to %qs type (%qT)", 1, fndecl
, "const",
6533 TREE_TYPE (args
[0]));
6536 else if (TYPE_ATOMIC (TREE_TYPE (TREE_TYPE (args
[0]))))
6538 error_at (ARG_LOCATION (0), "argument %u in call to function %qE "
6539 "has pointer to %qs type (%qT)", 1, fndecl
,
6540 "_Atomic", TREE_TYPE (args
[0]));
6552 /* Subroutine of c_parse_error.
6553 Return the result of concatenating LHS and RHS. RHS is really
6554 a string literal, its first character is indicated by RHS_START and
6555 RHS_SIZE is its length (including the terminating NUL character).
6557 The caller is responsible for deleting the returned pointer. */
6560 catenate_strings (const char *lhs
, const char *rhs_start
, int rhs_size
)
6562 const size_t lhs_size
= strlen (lhs
);
6563 char *result
= XNEWVEC (char, lhs_size
+ rhs_size
);
6564 memcpy (result
, lhs
, lhs_size
);
6565 memcpy (result
+ lhs_size
, rhs_start
, rhs_size
);
6569 /* Issue the error given by GMSGID at RICHLOC, indicating that it occurred
6570 before TOKEN, which had the associated VALUE. */
6573 c_parse_error (const char *gmsgid
, enum cpp_ttype token_type
,
6574 tree value
, unsigned char token_flags
,
6575 rich_location
*richloc
)
6577 #define catenate_messages(M1, M2) catenate_strings ((M1), (M2), sizeof (M2))
6579 char *message
= NULL
;
6581 if (token_type
== CPP_EOF
)
6582 message
= catenate_messages (gmsgid
, " at end of input");
6583 else if (token_type
== CPP_CHAR
6584 || token_type
== CPP_WCHAR
6585 || token_type
== CPP_CHAR16
6586 || token_type
== CPP_CHAR32
6587 || token_type
== CPP_UTF8CHAR
)
6589 unsigned int val
= TREE_INT_CST_LOW (value
);
6611 if (val
<= UCHAR_MAX
&& ISGRAPH (val
))
6612 message
= catenate_messages (gmsgid
, " before %s'%c'");
6614 message
= catenate_messages (gmsgid
, " before %s'\\x%x'");
6616 error_at (richloc
, message
, prefix
, val
);
6620 else if (token_type
== CPP_CHAR_USERDEF
6621 || token_type
== CPP_WCHAR_USERDEF
6622 || token_type
== CPP_CHAR16_USERDEF
6623 || token_type
== CPP_CHAR32_USERDEF
6624 || token_type
== CPP_UTF8CHAR_USERDEF
)
6625 message
= catenate_messages (gmsgid
,
6626 " before user-defined character literal");
6627 else if (token_type
== CPP_STRING_USERDEF
6628 || token_type
== CPP_WSTRING_USERDEF
6629 || token_type
== CPP_STRING16_USERDEF
6630 || token_type
== CPP_STRING32_USERDEF
6631 || token_type
== CPP_UTF8STRING_USERDEF
)
6632 message
= catenate_messages (gmsgid
, " before user-defined string literal");
6633 else if (token_type
== CPP_STRING
6634 || token_type
== CPP_WSTRING
6635 || token_type
== CPP_STRING16
6636 || token_type
== CPP_STRING32
6637 || token_type
== CPP_UTF8STRING
)
6638 message
= catenate_messages (gmsgid
, " before string constant");
6639 else if (token_type
== CPP_NUMBER
)
6640 message
= catenate_messages (gmsgid
, " before numeric constant");
6641 else if (token_type
== CPP_NAME
)
6643 message
= catenate_messages (gmsgid
, " before %qE");
6644 error_at (richloc
, message
, value
);
6648 else if (token_type
== CPP_PRAGMA
)
6649 message
= catenate_messages (gmsgid
, " before %<#pragma%>");
6650 else if (token_type
== CPP_PRAGMA_EOL
)
6651 message
= catenate_messages (gmsgid
, " before end of line");
6652 else if (token_type
== CPP_DECLTYPE
)
6653 message
= catenate_messages (gmsgid
, " before %<decltype%>");
6654 else if (token_type
< N_TTYPES
)
6656 message
= catenate_messages (gmsgid
, " before %qs token");
6657 error_at (richloc
, message
, cpp_type2name (token_type
, token_flags
));
6662 error_at (richloc
, gmsgid
);
6666 error_at (richloc
, message
);
6669 #undef catenate_messages
6672 /* Return the gcc option code associated with the reason for a cpp
6673 message, or 0 if none. */
6677 c_option_controlling_cpp_diagnostic (enum cpp_warning_reason reason
)
6682 const struct cpp_reason_option_codes_t
*entry
;
6684 for (entry
= cpp_reason_option_codes
; entry
->reason
!= CPP_W_NONE
; entry
++)
6686 if (entry
->reason
== reason
)
6687 return entry
->option_code
;
6694 /* Callback from cpp_diagnostic for PFILE to print diagnostics from the
6695 preprocessor. The diagnostic is of type LEVEL, with REASON set
6696 to the reason code if LEVEL is represents a warning, at location
6697 RICHLOC unless this is after lexing and the compiler's location
6698 should be used instead; MSG is the translated message and AP
6699 the arguments. Returns true if a diagnostic was emitted, false
6704 c_cpp_diagnostic (cpp_reader
*pfile ATTRIBUTE_UNUSED
,
6705 enum cpp_diagnostic_level level
,
6706 enum cpp_warning_reason reason
,
6707 rich_location
*richloc
,
6708 const char *msg
, va_list *ap
)
6710 diagnostic_info diagnostic
;
6711 diagnostic_t dlevel
;
6712 bool save_warn_system_headers
= global_dc
->dc_warn_system_headers
;
6717 case CPP_DL_WARNING_SYSHDR
:
6720 global_dc
->dc_warn_system_headers
= 1;
6722 case CPP_DL_WARNING
:
6725 dlevel
= DK_WARNING
;
6727 case CPP_DL_PEDWARN
:
6728 if (flag_no_output
&& !flag_pedantic_errors
)
6730 dlevel
= DK_PEDWARN
;
6748 richloc
->set_range (0, input_location
, SHOW_RANGE_WITH_CARET
);
6749 diagnostic_set_info_translated (&diagnostic
, msg
, ap
,
6751 diagnostic_override_option_index
6753 c_option_controlling_cpp_diagnostic (reason
));
6754 ret
= diagnostic_report_diagnostic (global_dc
, &diagnostic
);
6755 if (level
== CPP_DL_WARNING_SYSHDR
)
6756 global_dc
->dc_warn_system_headers
= save_warn_system_headers
;
6760 /* Convert a character from the host to the target execution character
6761 set. cpplib handles this, mostly. */
6764 c_common_to_target_charset (HOST_WIDE_INT c
)
6766 /* Character constants in GCC proper are sign-extended under -fsigned-char,
6767 zero-extended under -fno-signed-char. cpplib insists that characters
6768 and character constants are always unsigned. Hence we must convert
6770 cppchar_t uc
= ((cppchar_t
)c
) & ((((cppchar_t
)1) << CHAR_BIT
)-1);
6772 uc
= cpp_host_to_exec_charset (parse_in
, uc
);
6774 if (flag_signed_char
)
6775 return ((HOST_WIDE_INT
)uc
) << (HOST_BITS_PER_WIDE_INT
- CHAR_TYPE_SIZE
)
6776 >> (HOST_BITS_PER_WIDE_INT
- CHAR_TYPE_SIZE
);
6782 /* Fold an offsetof-like expression. EXPR is a nested sequence of component
6783 references with an INDIRECT_REF of a constant at the bottom; much like the
6784 traditional rendering of offsetof as a macro. TYPE is the desired type of
6785 the whole expression. Return the folded result. */
6788 fold_offsetof (tree expr
, tree type
, enum tree_code ctx
)
6791 tree_code code
= TREE_CODE (expr
);
6798 error ("cannot apply %<offsetof%> to static data member %qD", expr
);
6799 return error_mark_node
;
6803 error ("cannot apply %<offsetof%> when %<operator[]%> is overloaded");
6804 return error_mark_node
;
6808 if (!TREE_CONSTANT (TREE_OPERAND (expr
, 0)))
6810 error ("cannot apply %<offsetof%> to a non constant address");
6811 return error_mark_node
;
6813 return convert (type
, TREE_OPERAND (expr
, 0));
6816 base
= fold_offsetof (TREE_OPERAND (expr
, 0), type
, code
);
6817 if (base
== error_mark_node
)
6820 t
= TREE_OPERAND (expr
, 1);
6821 if (DECL_C_BIT_FIELD (t
))
6823 error ("attempt to take address of bit-field structure "
6825 return error_mark_node
;
6827 off
= size_binop_loc (input_location
, PLUS_EXPR
, DECL_FIELD_OFFSET (t
),
6828 size_int (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (t
))
6833 base
= fold_offsetof (TREE_OPERAND (expr
, 0), type
, code
);
6834 if (base
== error_mark_node
)
6837 t
= TREE_OPERAND (expr
, 1);
6838 STRIP_ANY_LOCATION_WRAPPER (t
);
6840 /* Check if the offset goes beyond the upper bound of the array. */
6841 if (TREE_CODE (t
) == INTEGER_CST
&& tree_int_cst_sgn (t
) >= 0)
6843 tree upbound
= array_ref_up_bound (expr
);
6844 if (upbound
!= NULL_TREE
6845 && TREE_CODE (upbound
) == INTEGER_CST
6846 && !tree_int_cst_equal (upbound
,
6847 TYPE_MAX_VALUE (TREE_TYPE (upbound
))))
6849 if (ctx
!= ARRAY_REF
&& ctx
!= COMPONENT_REF
)
6850 upbound
= size_binop (PLUS_EXPR
, upbound
,
6851 build_int_cst (TREE_TYPE (upbound
), 1));
6852 if (tree_int_cst_lt (upbound
, t
))
6856 for (v
= TREE_OPERAND (expr
, 0);
6857 TREE_CODE (v
) == COMPONENT_REF
;
6858 v
= TREE_OPERAND (v
, 0))
6859 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v
, 0)))
6862 tree fld_chain
= DECL_CHAIN (TREE_OPERAND (v
, 1));
6863 for (; fld_chain
; fld_chain
= DECL_CHAIN (fld_chain
))
6864 if (TREE_CODE (fld_chain
) == FIELD_DECL
)
6870 /* Don't warn if the array might be considered a poor
6871 man's flexible array member with a very permissive
6872 definition thereof. */
6873 if (TREE_CODE (v
) == ARRAY_REF
6874 || TREE_CODE (v
) == COMPONENT_REF
)
6875 warning (OPT_Warray_bounds
,
6876 "index %E denotes an offset "
6877 "greater than size of %qT",
6878 t
, TREE_TYPE (TREE_OPERAND (expr
, 0)));
6883 t
= convert (sizetype
, t
);
6884 off
= size_binop (MULT_EXPR
, TYPE_SIZE_UNIT (TREE_TYPE (expr
)), t
);
6888 /* Handle static members of volatile structs. */
6889 t
= TREE_OPERAND (expr
, 1);
6890 gcc_checking_assert (VAR_P (get_base_address (t
)));
6891 return fold_offsetof (t
, type
);
6897 if (!POINTER_TYPE_P (type
))
6898 return size_binop (PLUS_EXPR
, base
, convert (type
, off
));
6899 return fold_build_pointer_plus (base
, off
);
6902 /* *PTYPE is an incomplete array. Complete it with a domain based on
6903 INITIAL_VALUE. If INITIAL_VALUE is not present, use 1 if DO_DEFAULT
6904 is true. Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
6905 2 if INITIAL_VALUE was NULL, and 3 if INITIAL_VALUE was empty. */
6908 complete_array_type (tree
*ptype
, tree initial_value
, bool do_default
)
6910 tree maxindex
, type
, main_type
, elt
, unqual_elt
;
6911 int failure
= 0, quals
;
6912 bool overflow_p
= false;
6914 maxindex
= size_zero_node
;
6917 STRIP_ANY_LOCATION_WRAPPER (initial_value
);
6919 if (TREE_CODE (initial_value
) == STRING_CST
)
6922 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value
)));
6923 maxindex
= size_int (TREE_STRING_LENGTH (initial_value
)/eltsize
- 1);
6925 else if (TREE_CODE (initial_value
) == CONSTRUCTOR
)
6927 vec
<constructor_elt
, va_gc
> *v
= CONSTRUCTOR_ELTS (initial_value
);
6929 if (vec_safe_is_empty (v
))
6933 maxindex
= ssize_int (-1);
6938 unsigned HOST_WIDE_INT cnt
;
6939 constructor_elt
*ce
;
6940 bool fold_p
= false;
6943 maxindex
= (*v
)[0].index
, fold_p
= true;
6945 curindex
= maxindex
;
6947 for (cnt
= 1; vec_safe_iterate (v
, cnt
, &ce
); cnt
++)
6949 bool curfold_p
= false;
6951 curindex
= ce
->index
, curfold_p
= true;
6956 /* Since we treat size types now as ordinary
6957 unsigned types, we need an explicit overflow
6959 tree orig
= curindex
;
6960 curindex
= fold_convert (sizetype
, curindex
);
6961 overflow_p
|= tree_int_cst_lt (curindex
, orig
);
6963 curindex
= size_binop (PLUS_EXPR
, curindex
,
6966 if (tree_int_cst_lt (maxindex
, curindex
))
6967 maxindex
= curindex
, fold_p
= curfold_p
;
6971 tree orig
= maxindex
;
6972 maxindex
= fold_convert (sizetype
, maxindex
);
6973 overflow_p
|= tree_int_cst_lt (maxindex
, orig
);
6979 /* Make an error message unless that happened already. */
6980 if (initial_value
!= error_mark_node
)
6992 elt
= TREE_TYPE (type
);
6993 quals
= TYPE_QUALS (strip_array_types (elt
));
6997 unqual_elt
= c_build_qualified_type (elt
, KEEP_QUAL_ADDR_SPACE (quals
));
6999 /* Using build_distinct_type_copy and modifying things afterward instead
7000 of using build_array_type to create a new type preserves all of the
7001 TYPE_LANG_FLAG_? bits that the front end may have set. */
7002 main_type
= build_distinct_type_copy (TYPE_MAIN_VARIANT (type
));
7003 TREE_TYPE (main_type
) = unqual_elt
;
7004 TYPE_DOMAIN (main_type
)
7005 = build_range_type (TREE_TYPE (maxindex
),
7006 build_int_cst (TREE_TYPE (maxindex
), 0), maxindex
);
7007 TYPE_TYPELESS_STORAGE (main_type
) = TYPE_TYPELESS_STORAGE (type
);
7008 layout_type (main_type
);
7010 /* Make sure we have the canonical MAIN_TYPE. */
7011 hashval_t hashcode
= type_hash_canon_hash (main_type
);
7012 main_type
= type_hash_canon (hashcode
, main_type
);
7014 /* Fix the canonical type. */
7015 if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (main_type
))
7016 || TYPE_STRUCTURAL_EQUALITY_P (TYPE_DOMAIN (main_type
)))
7017 SET_TYPE_STRUCTURAL_EQUALITY (main_type
);
7018 else if (TYPE_CANONICAL (TREE_TYPE (main_type
)) != TREE_TYPE (main_type
)
7019 || (TYPE_CANONICAL (TYPE_DOMAIN (main_type
))
7020 != TYPE_DOMAIN (main_type
)))
7021 TYPE_CANONICAL (main_type
)
7022 = build_array_type (TYPE_CANONICAL (TREE_TYPE (main_type
)),
7023 TYPE_CANONICAL (TYPE_DOMAIN (main_type
)),
7024 TYPE_TYPELESS_STORAGE (main_type
));
7026 TYPE_CANONICAL (main_type
) = main_type
;
7031 type
= c_build_qualified_type (main_type
, quals
);
7033 if (COMPLETE_TYPE_P (type
)
7034 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
7035 && (overflow_p
|| TREE_OVERFLOW (TYPE_SIZE_UNIT (type
))))
7037 error ("size of array is too large");
7038 /* If we proceed with the array type as it is, we'll eventually
7039 crash in tree_to_[su]hwi(). */
7040 type
= error_mark_node
;
7047 /* INIT is an constructor of a structure with a flexible array member.
7048 Complete the flexible array member with a domain based on it's value. */
7050 complete_flexible_array_elts (tree init
)
7054 if (init
== NULL_TREE
|| TREE_CODE (init
) != CONSTRUCTOR
)
7057 if (vec_safe_is_empty (CONSTRUCTOR_ELTS (init
)))
7060 elt
= CONSTRUCTOR_ELTS (init
)->last ().value
;
7061 type
= TREE_TYPE (elt
);
7062 if (TREE_CODE (type
) == ARRAY_TYPE
7063 && TYPE_SIZE (type
) == NULL_TREE
)
7064 complete_array_type (&TREE_TYPE (elt
), elt
, false);
7066 complete_flexible_array_elts (elt
);
7069 /* Like c_mark_addressable but don't check register qualifier. */
7071 c_common_mark_addressable_vec (tree t
)
7073 while (handled_component_p (t
) || TREE_CODE (t
) == C_MAYBE_CONST_EXPR
)
7075 if (TREE_CODE (t
) == C_MAYBE_CONST_EXPR
)
7076 t
= C_MAYBE_CONST_EXPR_EXPR (t
);
7078 t
= TREE_OPERAND (t
, 0);
7081 && TREE_CODE (t
) != PARM_DECL
7082 && TREE_CODE (t
) != COMPOUND_LITERAL_EXPR
7083 && TREE_CODE (t
) != TARGET_EXPR
)
7085 if (!VAR_P (t
) || !DECL_HARD_REGISTER (t
))
7086 TREE_ADDRESSABLE (t
) = 1;
7087 if (TREE_CODE (t
) == COMPOUND_LITERAL_EXPR
)
7088 TREE_ADDRESSABLE (COMPOUND_LITERAL_EXPR_DECL (t
)) = 1;
7089 else if (TREE_CODE (t
) == TARGET_EXPR
)
7090 TREE_ADDRESSABLE (TARGET_EXPR_SLOT (t
)) = 1;
7095 /* Used to help initialize the builtin-types.def table. When a type of
7096 the correct size doesn't exist, use error_mark_node instead of NULL.
7097 The later results in segfaults even when a decl using the type doesn't
7102 builtin_type_for_size (int size
, bool unsignedp
)
7104 tree type
= c_common_type_for_size (size
, unsignedp
);
7105 return type
? type
: error_mark_node
;
7108 /* Work out the size of the first argument of a call to
7109 __builtin_speculation_safe_value. Only pointers and integral types
7110 are permitted. Return -1 if the argument type is not supported or
7111 the size is too large; 0 if the argument type is a pointer or the
7112 size if it is integral. */
7113 static enum built_in_function
7114 speculation_safe_value_resolve_call (tree function
, vec
<tree
, va_gc
> *params
)
7116 /* Type of the argument. */
7120 if (vec_safe_is_empty (params
))
7122 error ("too few arguments to function %qE", function
);
7123 return BUILT_IN_NONE
;
7126 type
= TREE_TYPE ((*params
)[0]);
7127 if (TREE_CODE (type
) == ARRAY_TYPE
&& c_dialect_cxx ())
7129 /* Force array-to-pointer decay for C++. */
7130 (*params
)[0] = default_conversion ((*params
)[0]);
7131 type
= TREE_TYPE ((*params
)[0]);
7134 if (POINTER_TYPE_P (type
))
7135 return BUILT_IN_SPECULATION_SAFE_VALUE_PTR
;
7137 if (!INTEGRAL_TYPE_P (type
))
7140 if (!COMPLETE_TYPE_P (type
))
7143 size
= tree_to_uhwi (TYPE_SIZE_UNIT (type
));
7144 if (size
== 1 || size
== 2 || size
== 4 || size
== 8 || size
== 16)
7145 return ((enum built_in_function
)
7146 ((int) BUILT_IN_SPECULATION_SAFE_VALUE_1
+ exact_log2 (size
)));
7149 /* Issue the diagnostic only if the argument is valid, otherwise
7150 it would be redundant at best and could be misleading. */
7151 if (type
!= error_mark_node
)
7152 error ("operand type %qT is incompatible with argument %d of %qE",
7155 return BUILT_IN_NONE
;
7158 /* Validate and coerce PARAMS, the arguments to ORIG_FUNCTION to fit
7159 the prototype for FUNCTION. The first argument is mandatory, a second
7160 argument, if present, must be type compatible with the first. */
7162 speculation_safe_value_resolve_params (location_t loc
, tree orig_function
,
7163 vec
<tree
, va_gc
> *params
)
7167 if (params
->length () == 0)
7169 error_at (loc
, "too few arguments to function %qE", orig_function
);
7173 else if (params
->length () > 2)
7175 error_at (loc
, "too many arguments to function %qE", orig_function
);
7180 if (TREE_CODE (TREE_TYPE (val
)) == ARRAY_TYPE
)
7181 val
= default_conversion (val
);
7182 if (!(TREE_CODE (TREE_TYPE (val
)) == POINTER_TYPE
7183 || TREE_CODE (TREE_TYPE (val
)) == INTEGER_TYPE
))
7186 "expecting argument of type pointer or of type integer "
7192 if (params
->length () == 2)
7194 tree val2
= (*params
)[1];
7195 if (TREE_CODE (TREE_TYPE (val2
)) == ARRAY_TYPE
)
7196 val2
= default_conversion (val2
);
7197 if (error_operand_p (val2
))
7199 if (!(TREE_TYPE (val
) == TREE_TYPE (val2
)
7200 || useless_type_conversion_p (TREE_TYPE (val
), TREE_TYPE (val2
))))
7202 error_at (loc
, "both arguments must be compatible");
7205 (*params
)[1] = val2
;
7211 /* Cast the result of the builtin back to the type of the first argument,
7212 preserving any qualifiers that it might have. */
7214 speculation_safe_value_resolve_return (tree first_param
, tree result
)
7216 tree ptype
= TREE_TYPE (first_param
);
7217 tree rtype
= TREE_TYPE (result
);
7218 ptype
= TYPE_MAIN_VARIANT (ptype
);
7220 if (tree_int_cst_equal (TYPE_SIZE (ptype
), TYPE_SIZE (rtype
)))
7221 return convert (ptype
, result
);
7226 /* A helper function for resolve_overloaded_builtin in resolving the
7227 overloaded __sync_ builtins. Returns a positive power of 2 if the
7228 first operand of PARAMS is a pointer to a supported data type.
7229 Returns 0 if an error is encountered.
7230 FETCH is true when FUNCTION is one of the _FETCH_OP_ or _OP_FETCH_
7234 sync_resolve_size (tree function
, vec
<tree
, va_gc
> *params
, bool fetch
)
7236 /* Type of the argument. */
7238 /* Type the argument points to. */
7242 if (vec_safe_is_empty (params
))
7244 error ("too few arguments to function %qE", function
);
7248 argtype
= type
= TREE_TYPE ((*params
)[0]);
7249 if (TREE_CODE (type
) == ARRAY_TYPE
&& c_dialect_cxx ())
7251 /* Force array-to-pointer decay for C++. */
7252 (*params
)[0] = default_conversion ((*params
)[0]);
7253 type
= TREE_TYPE ((*params
)[0]);
7255 if (TREE_CODE (type
) != POINTER_TYPE
)
7258 type
= TREE_TYPE (type
);
7259 if (!INTEGRAL_TYPE_P (type
) && !POINTER_TYPE_P (type
))
7262 if (!COMPLETE_TYPE_P (type
))
7265 if (fetch
&& TREE_CODE (type
) == BOOLEAN_TYPE
)
7268 size
= tree_to_uhwi (TYPE_SIZE_UNIT (type
));
7269 if (size
== 1 || size
== 2 || size
== 4 || size
== 8 || size
== 16)
7273 /* Issue the diagnostic only if the argument is valid, otherwise
7274 it would be redundant at best and could be misleading. */
7275 if (argtype
!= error_mark_node
)
7276 error ("operand type %qT is incompatible with argument %d of %qE",
7277 argtype
, 1, function
);
7281 /* A helper function for resolve_overloaded_builtin. Adds casts to
7282 PARAMS to make arguments match up with those of FUNCTION. Drops
7283 the variadic arguments at the end. Returns false if some error
7284 was encountered; true on success. */
7287 sync_resolve_params (location_t loc
, tree orig_function
, tree function
,
7288 vec
<tree
, va_gc
> *params
, bool orig_format
)
7290 function_args_iterator iter
;
7292 unsigned int parmnum
;
7294 function_args_iter_init (&iter
, TREE_TYPE (function
));
7295 /* We've declared the implementation functions to use "volatile void *"
7296 as the pointer parameter, so we shouldn't get any complaints from the
7297 call to check_function_arguments what ever type the user used. */
7298 function_args_iter_next (&iter
);
7299 ptype
= TREE_TYPE (TREE_TYPE ((*params
)[0]));
7300 ptype
= TYPE_MAIN_VARIANT (ptype
);
7302 /* For the rest of the values, we need to cast these to FTYPE, so that we
7303 don't get warnings for passing pointer types, etc. */
7309 arg_type
= function_args_iter_cond (&iter
);
7310 /* XXX void_type_node belies the abstraction. */
7311 if (arg_type
== void_type_node
)
7315 if (params
->length () <= parmnum
)
7317 error_at (loc
, "too few arguments to function %qE", orig_function
);
7321 /* Only convert parameters if arg_type is unsigned integer type with
7322 new format sync routines, i.e. don't attempt to convert pointer
7323 arguments (e.g. EXPECTED argument of __atomic_compare_exchange_n),
7324 bool arguments (e.g. WEAK argument) or signed int arguments (memmodel
7326 if (TREE_CODE (arg_type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (arg_type
))
7328 /* Ideally for the first conversion we'd use convert_for_assignment
7329 so that we get warnings for anything that doesn't match the pointer
7330 type. This isn't portable across the C and C++ front ends atm. */
7331 val
= (*params
)[parmnum
];
7332 val
= convert (ptype
, val
);
7333 val
= convert (arg_type
, val
);
7334 (*params
)[parmnum
] = val
;
7337 function_args_iter_next (&iter
);
7340 /* __atomic routines are not variadic. */
7341 if (!orig_format
&& params
->length () != parmnum
+ 1)
7343 error_at (loc
, "too many arguments to function %qE", orig_function
);
7347 /* The definition of these primitives is variadic, with the remaining
7348 being "an optional list of variables protected by the memory barrier".
7349 No clue what that's supposed to mean, precisely, but we consider all
7350 call-clobbered variables to be protected so we're safe. */
7351 params
->truncate (parmnum
+ 1);
7356 /* A helper function for resolve_overloaded_builtin. Adds a cast to
7357 RESULT to make it match the type of the first pointer argument in
7361 sync_resolve_return (tree first_param
, tree result
, bool orig_format
)
7363 tree ptype
= TREE_TYPE (TREE_TYPE (first_param
));
7364 tree rtype
= TREE_TYPE (result
);
7365 ptype
= TYPE_MAIN_VARIANT (ptype
);
7367 /* New format doesn't require casting unless the types are the same size. */
7368 if (orig_format
|| tree_int_cst_equal (TYPE_SIZE (ptype
), TYPE_SIZE (rtype
)))
7369 return convert (ptype
, result
);
7375 /* This function verifies the PARAMS to generic atomic FUNCTION.
7376 It returns the size if all the parameters are the same size, otherwise
7377 0 is returned if the parameters are invalid. */
7381 get_atomic_generic_size (location_t loc
, tree function
,
7382 vec
<tree
, va_gc
> *params
)
7384 unsigned int n_param
;
7385 unsigned int n_model
;
7386 unsigned int outputs
= 0; // bitset of output parameters
7391 /* Determine the parameter makeup. */
7392 switch (DECL_FUNCTION_CODE (function
))
7394 case BUILT_IN_ATOMIC_EXCHANGE
:
7399 case BUILT_IN_ATOMIC_LOAD
:
7404 case BUILT_IN_ATOMIC_STORE
:
7409 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
7418 if (vec_safe_length (params
) != n_param
)
7420 error_at (loc
, "incorrect number of arguments to function %qE", function
);
7424 /* Get type of first parameter, and determine its size. */
7425 type_0
= TREE_TYPE ((*params
)[0]);
7426 if (TREE_CODE (type_0
) == ARRAY_TYPE
&& c_dialect_cxx ())
7428 /* Force array-to-pointer decay for C++. */
7429 (*params
)[0] = default_conversion ((*params
)[0]);
7430 type_0
= TREE_TYPE ((*params
)[0]);
7432 if (TREE_CODE (type_0
) != POINTER_TYPE
|| VOID_TYPE_P (TREE_TYPE (type_0
)))
7434 error_at (loc
, "argument 1 of %qE must be a non-void pointer type",
7439 if (!COMPLETE_TYPE_P (TREE_TYPE (type_0
)))
7441 error_at (loc
, "argument 1 of %qE must be a pointer to a complete type",
7446 /* Types must be compile time constant sizes. */
7447 if (!tree_fits_uhwi_p ((TYPE_SIZE_UNIT (TREE_TYPE (type_0
)))))
7450 "argument 1 of %qE must be a pointer to a constant size type",
7455 size_0
= tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (type_0
)));
7457 /* Zero size objects are not allowed. */
7461 "argument 1 of %qE must be a pointer to a nonzero size object",
7466 /* Check each other parameter is a pointer and the same size. */
7467 for (x
= 0; x
< n_param
- n_model
; x
++)
7470 tree type
= TREE_TYPE ((*params
)[x
]);
7471 /* __atomic_compare_exchange has a bool in the 4th position, skip it. */
7472 if (n_param
== 6 && x
== 3)
7474 if (TREE_CODE (type
) == ARRAY_TYPE
&& c_dialect_cxx ())
7476 /* Force array-to-pointer decay for C++. */
7477 (*params
)[x
] = default_conversion ((*params
)[x
]);
7478 type
= TREE_TYPE ((*params
)[x
]);
7480 if (!POINTER_TYPE_P (type
))
7482 error_at (loc
, "argument %d of %qE must be a pointer type", x
+ 1,
7486 else if (TYPE_SIZE_UNIT (TREE_TYPE (type
))
7487 && TREE_CODE ((TYPE_SIZE_UNIT (TREE_TYPE (type
))))
7490 error_at (loc
, "argument %d of %qE must be a pointer to a constant "
7491 "size type", x
+ 1, function
);
7494 else if (FUNCTION_POINTER_TYPE_P (type
))
7496 error_at (loc
, "argument %d of %qE must not be a pointer to a "
7497 "function", x
+ 1, function
);
7500 tree type_size
= TYPE_SIZE_UNIT (TREE_TYPE (type
));
7501 size
= type_size
? tree_to_uhwi (type_size
) : 0;
7504 error_at (loc
, "size mismatch in argument %d of %qE", x
+ 1,
7510 auto_diagnostic_group d
;
7511 int quals
= TYPE_QUALS (TREE_TYPE (type
));
7512 /* Must not write to an argument of a const-qualified type. */
7513 if (outputs
& (1 << x
) && quals
& TYPE_QUAL_CONST
)
7515 if (c_dialect_cxx ())
7517 error_at (loc
, "argument %d of %qE must not be a pointer to "
7518 "a %<const%> type", x
+ 1, function
);
7522 pedwarn (loc
, OPT_Wincompatible_pointer_types
, "argument %d "
7523 "of %qE discards %<const%> qualifier", x
+ 1,
7526 /* Only the first argument is allowed to be volatile. */
7527 if (x
> 0 && quals
& TYPE_QUAL_VOLATILE
)
7529 if (c_dialect_cxx ())
7531 error_at (loc
, "argument %d of %qE must not be a pointer to "
7532 "a %<volatile%> type", x
+ 1, function
);
7536 pedwarn (loc
, OPT_Wincompatible_pointer_types
, "argument %d "
7537 "of %qE discards %<volatile%> qualifier", x
+ 1,
7543 /* Check memory model parameters for validity. */
7544 for (x
= n_param
- n_model
; x
< n_param
; x
++)
7546 tree p
= (*params
)[x
];
7547 if (!INTEGRAL_TYPE_P (TREE_TYPE (p
)))
7549 error_at (loc
, "non-integer memory model argument %d of %qE", x
+ 1,
7553 p
= fold_for_warn (p
);
7554 if (TREE_CODE (p
) == INTEGER_CST
)
7556 /* memmodel_base masks the low 16 bits, thus ignore any bits above
7557 it by using TREE_INT_CST_LOW instead of tree_to_*hwi. Those high
7558 bits will be checked later during expansion in target specific
7560 if (memmodel_base (TREE_INT_CST_LOW (p
)) >= MEMMODEL_LAST
)
7561 warning_at (loc
, OPT_Winvalid_memory_model
,
7562 "invalid memory model argument %d of %qE", x
+ 1,
7571 /* This will take an __atomic_ generic FUNCTION call, and add a size parameter N
7572 at the beginning of the parameter list PARAMS representing the size of the
7573 objects. This is to match the library ABI requirement. LOC is the location
7574 of the function call.
7575 The new function is returned if it needed rebuilding, otherwise NULL_TREE is
7576 returned to allow the external call to be constructed. */
7579 add_atomic_size_parameter (unsigned n
, location_t loc
, tree function
,
7580 vec
<tree
, va_gc
> *params
)
7584 /* Insert a SIZE_T parameter as the first param. If there isn't
7585 enough space, allocate a new vector and recursively re-build with that. */
7586 if (!params
->space (1))
7588 unsigned int z
, len
;
7589 vec
<tree
, va_gc
> *v
;
7592 len
= params
->length ();
7593 vec_alloc (v
, len
+ 1);
7594 v
->quick_push (build_int_cst (size_type_node
, n
));
7595 for (z
= 0; z
< len
; z
++)
7596 v
->quick_push ((*params
)[z
]);
7597 f
= build_function_call_vec (loc
, vNULL
, function
, v
, NULL
);
7602 /* Add the size parameter and leave as a function call for processing. */
7603 size_node
= build_int_cst (size_type_node
, n
);
7604 params
->quick_insert (0, size_node
);
7610 /* Return whether atomic operations for naturally aligned N-byte
7611 arguments are supported, whether inline or through libatomic. */
7613 atomic_size_supported_p (int n
)
7624 return targetm
.scalar_mode_supported_p (TImode
);
7631 /* This will process an __atomic_exchange function call, determine whether it
7632 needs to be mapped to the _N variation, or turned into a library call.
7633 LOC is the location of the builtin call.
7634 FUNCTION is the DECL that has been invoked;
7635 PARAMS is the argument list for the call. The return value is non-null
7636 TRUE is returned if it is translated into the proper format for a call to the
7637 external library, and NEW_RETURN is set the tree for that function.
7638 FALSE is returned if processing for the _N variation is required, and
7639 NEW_RETURN is set to the return value the result is copied into. */
7641 resolve_overloaded_atomic_exchange (location_t loc
, tree function
,
7642 vec
<tree
, va_gc
> *params
, tree
*new_return
)
7644 tree p0
, p1
, p2
, p3
;
7645 tree I_type
, I_type_ptr
;
7646 int n
= get_atomic_generic_size (loc
, function
, params
);
7648 /* Size of 0 is an error condition. */
7651 *new_return
= error_mark_node
;
7655 /* If not a lock-free size, change to the library generic format. */
7656 if (!atomic_size_supported_p (n
))
7658 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
7662 /* Otherwise there is a lockfree match, transform the call from:
7663 void fn(T* mem, T* desired, T* return, model)
7665 *return = (T) (fn (In* mem, (In) *desired, model)) */
7672 /* Create pointer to appropriate size. */
7673 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
7674 I_type_ptr
= build_pointer_type (I_type
);
7676 /* Convert object pointer to required type. */
7677 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
7679 /* Convert new value to required type, and dereference it. */
7680 p1
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
7681 p1
= build1 (VIEW_CONVERT_EXPR
, I_type
, p1
);
7684 /* Move memory model to the 3rd position, and end param list. */
7686 params
->truncate (3);
7688 /* Convert return pointer and dereference it for later assignment. */
7689 *new_return
= build_indirect_ref (loc
, p2
, RO_UNARY_STAR
);
7695 /* This will process an __atomic_compare_exchange function call, determine
7696 whether it needs to be mapped to the _N variation, or turned into a lib call.
7697 LOC is the location of the builtin call.
7698 FUNCTION is the DECL that has been invoked;
7699 PARAMS is the argument list for the call. The return value is non-null
7700 TRUE is returned if it is translated into the proper format for a call to the
7701 external library, and NEW_RETURN is set the tree for that function.
7702 FALSE is returned if processing for the _N variation is required. */
7705 resolve_overloaded_atomic_compare_exchange (location_t loc
, tree function
,
7706 vec
<tree
, va_gc
> *params
,
7710 tree I_type
, I_type_ptr
;
7711 int n
= get_atomic_generic_size (loc
, function
, params
);
7713 /* Size of 0 is an error condition. */
7716 *new_return
= error_mark_node
;
7720 /* If not a lock-free size, change to the library generic format. */
7721 if (!atomic_size_supported_p (n
))
7723 /* The library generic format does not have the weak parameter, so
7724 remove it from the param list. Since a parameter has been removed,
7725 we can be sure that there is room for the SIZE_T parameter, meaning
7726 there will not be a recursive rebuilding of the parameter list, so
7727 there is no danger this will be done twice. */
7730 (*params
)[3] = (*params
)[4];
7731 (*params
)[4] = (*params
)[5];
7732 params
->truncate (5);
7734 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
7738 /* Otherwise, there is a match, so the call needs to be transformed from:
7739 bool fn(T* mem, T* desired, T* return, weak, success, failure)
7741 bool fn ((In *)mem, (In *)expected, (In) *desired, weak, succ, fail) */
7747 /* Create pointer to appropriate size. */
7748 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
7749 I_type_ptr
= build_pointer_type (I_type
);
7751 /* Convert object pointer to required type. */
7752 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
7755 /* Convert expected pointer to required type. */
7756 p1
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p1
);
7759 /* Convert desired value to required type, and dereference it. */
7760 p2
= build_indirect_ref (loc
, p2
, RO_UNARY_STAR
);
7761 p2
= build1 (VIEW_CONVERT_EXPR
, I_type
, p2
);
7764 /* The rest of the parameters are fine. NULL means no special return value
7772 /* This will process an __atomic_load function call, determine whether it
7773 needs to be mapped to the _N variation, or turned into a library call.
7774 LOC is the location of the builtin call.
7775 FUNCTION is the DECL that has been invoked;
7776 PARAMS is the argument list for the call. The return value is non-null
7777 TRUE is returned if it is translated into the proper format for a call to the
7778 external library, and NEW_RETURN is set the tree for that function.
7779 FALSE is returned if processing for the _N variation is required, and
7780 NEW_RETURN is set to the return value the result is copied into. */
7784 resolve_overloaded_atomic_load (location_t loc
, tree function
,
7785 vec
<tree
, va_gc
> *params
, tree
*new_return
)
7788 tree I_type
, I_type_ptr
;
7789 int n
= get_atomic_generic_size (loc
, function
, params
);
7791 /* Size of 0 is an error condition. */
7794 *new_return
= error_mark_node
;
7798 /* If not a lock-free size, change to the library generic format. */
7799 if (!atomic_size_supported_p (n
))
7801 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
7805 /* Otherwise, there is a match, so the call needs to be transformed from:
7806 void fn(T* mem, T* return, model)
7808 *return = (T) (fn ((In *) mem, model)) */
7814 /* Create pointer to appropriate size. */
7815 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
7816 I_type_ptr
= build_pointer_type (I_type
);
7818 /* Convert object pointer to required type. */
7819 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
7822 /* Move memory model to the 2nd position, and end param list. */
7824 params
->truncate (2);
7826 /* Convert return pointer and dereference it for later assignment. */
7827 *new_return
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
7833 /* This will process an __atomic_store function call, determine whether it
7834 needs to be mapped to the _N variation, or turned into a library call.
7835 LOC is the location of the builtin call.
7836 FUNCTION is the DECL that has been invoked;
7837 PARAMS is the argument list for the call. The return value is non-null
7838 TRUE is returned if it is translated into the proper format for a call to the
7839 external library, and NEW_RETURN is set the tree for that function.
7840 FALSE is returned if processing for the _N variation is required, and
7841 NEW_RETURN is set to the return value the result is copied into. */
7844 resolve_overloaded_atomic_store (location_t loc
, tree function
,
7845 vec
<tree
, va_gc
> *params
, tree
*new_return
)
7848 tree I_type
, I_type_ptr
;
7849 int n
= get_atomic_generic_size (loc
, function
, params
);
7851 /* Size of 0 is an error condition. */
7854 *new_return
= error_mark_node
;
7858 /* If not a lock-free size, change to the library generic format. */
7859 if (!atomic_size_supported_p (n
))
7861 *new_return
= add_atomic_size_parameter (n
, loc
, function
, params
);
7865 /* Otherwise, there is a match, so the call needs to be transformed from:
7866 void fn(T* mem, T* value, model)
7868 fn ((In *) mem, (In) *value, model) */
7873 /* Create pointer to appropriate size. */
7874 I_type
= builtin_type_for_size (BITS_PER_UNIT
* n
, 1);
7875 I_type_ptr
= build_pointer_type (I_type
);
7877 /* Convert object pointer to required type. */
7878 p0
= build1 (VIEW_CONVERT_EXPR
, I_type_ptr
, p0
);
7881 /* Convert new value to required type, and dereference it. */
7882 p1
= build_indirect_ref (loc
, p1
, RO_UNARY_STAR
);
7883 p1
= build1 (VIEW_CONVERT_EXPR
, I_type
, p1
);
7886 /* The memory model is in the right spot already. Return is void. */
7887 *new_return
= NULL_TREE
;
7893 /* Some builtin functions are placeholders for other expressions. This
7894 function should be called immediately after parsing the call expression
7895 before surrounding code has committed to the type of the expression.
7897 LOC is the location of the builtin call.
7899 FUNCTION is the DECL that has been invoked; it is known to be a builtin.
7900 PARAMS is the argument list for the call. The return value is non-null
7901 when expansion is complete, and null if normal processing should
7905 resolve_overloaded_builtin (location_t loc
, tree function
,
7906 vec
<tree
, va_gc
> *params
)
7908 /* Is function one of the _FETCH_OP_ or _OP_FETCH_ built-ins?
7909 Those are not valid to call with a pointer to _Bool (or C++ bool)
7910 and so must be rejected. */
7911 bool fetch_op
= true;
7912 bool orig_format
= true;
7913 tree new_return
= NULL_TREE
;
7915 switch (DECL_BUILT_IN_CLASS (function
))
7917 case BUILT_IN_NORMAL
:
7920 if (targetm
.resolve_overloaded_builtin
)
7921 return targetm
.resolve_overloaded_builtin (loc
, function
, params
);
7928 /* Handle BUILT_IN_NORMAL here. */
7929 enum built_in_function orig_code
= DECL_FUNCTION_CODE (function
);
7932 case BUILT_IN_SPECULATION_SAFE_VALUE_N
:
7934 tree new_function
, first_param
, result
;
7935 enum built_in_function fncode
7936 = speculation_safe_value_resolve_call (function
, params
);
7938 if (fncode
== BUILT_IN_NONE
)
7939 return error_mark_node
;
7941 first_param
= (*params
)[0];
7942 if (!speculation_safe_value_resolve_params (loc
, function
, params
))
7943 return error_mark_node
;
7945 if (targetm
.have_speculation_safe_value (true))
7947 new_function
= builtin_decl_explicit (fncode
);
7948 result
= build_function_call_vec (loc
, vNULL
, new_function
, params
,
7951 if (result
== error_mark_node
)
7954 return speculation_safe_value_resolve_return (first_param
, result
);
7958 /* This target doesn't have, or doesn't need, active mitigation
7959 against incorrect speculative execution. Simply return the
7960 first parameter to the builtin. */
7961 if (!targetm
.have_speculation_safe_value (false))
7962 /* The user has invoked __builtin_speculation_safe_value
7963 even though __HAVE_SPECULATION_SAFE_VALUE is not
7964 defined: emit a warning. */
7965 warning_at (input_location
, 0,
7966 "this target does not define a speculation barrier; "
7967 "your program will still execute correctly, "
7968 "but incorrect speculation may not be "
7971 /* If the optional second argument is present, handle any side
7973 if (params
->length () == 2
7974 && TREE_SIDE_EFFECTS ((*params
)[1]))
7975 return build2 (COMPOUND_EXPR
, TREE_TYPE (first_param
),
7976 (*params
)[1], first_param
);
7982 case BUILT_IN_ATOMIC_EXCHANGE
:
7983 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
7984 case BUILT_IN_ATOMIC_LOAD
:
7985 case BUILT_IN_ATOMIC_STORE
:
7987 /* Handle these 4 together so that they can fall through to the next
7988 case if the call is transformed to an _N variant. */
7991 case BUILT_IN_ATOMIC_EXCHANGE
:
7993 if (resolve_overloaded_atomic_exchange (loc
, function
, params
,
7996 /* Change to the _N variant. */
7997 orig_code
= BUILT_IN_ATOMIC_EXCHANGE_N
;
8001 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE
:
8003 if (resolve_overloaded_atomic_compare_exchange (loc
, function
,
8007 /* Change to the _N variant. */
8008 orig_code
= BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N
;
8011 case BUILT_IN_ATOMIC_LOAD
:
8013 if (resolve_overloaded_atomic_load (loc
, function
, params
,
8016 /* Change to the _N variant. */
8017 orig_code
= BUILT_IN_ATOMIC_LOAD_N
;
8020 case BUILT_IN_ATOMIC_STORE
:
8022 if (resolve_overloaded_atomic_store (loc
, function
, params
,
8025 /* Change to the _N variant. */
8026 orig_code
= BUILT_IN_ATOMIC_STORE_N
;
8034 case BUILT_IN_ATOMIC_EXCHANGE_N
:
8035 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N
:
8036 case BUILT_IN_ATOMIC_LOAD_N
:
8037 case BUILT_IN_ATOMIC_STORE_N
:
8040 case BUILT_IN_ATOMIC_ADD_FETCH_N
:
8041 case BUILT_IN_ATOMIC_SUB_FETCH_N
:
8042 case BUILT_IN_ATOMIC_AND_FETCH_N
:
8043 case BUILT_IN_ATOMIC_NAND_FETCH_N
:
8044 case BUILT_IN_ATOMIC_XOR_FETCH_N
:
8045 case BUILT_IN_ATOMIC_OR_FETCH_N
:
8046 case BUILT_IN_ATOMIC_FETCH_ADD_N
:
8047 case BUILT_IN_ATOMIC_FETCH_SUB_N
:
8048 case BUILT_IN_ATOMIC_FETCH_AND_N
:
8049 case BUILT_IN_ATOMIC_FETCH_NAND_N
:
8050 case BUILT_IN_ATOMIC_FETCH_XOR_N
:
8051 case BUILT_IN_ATOMIC_FETCH_OR_N
:
8052 orig_format
= false;
8054 case BUILT_IN_SYNC_FETCH_AND_ADD_N
:
8055 case BUILT_IN_SYNC_FETCH_AND_SUB_N
:
8056 case BUILT_IN_SYNC_FETCH_AND_OR_N
:
8057 case BUILT_IN_SYNC_FETCH_AND_AND_N
:
8058 case BUILT_IN_SYNC_FETCH_AND_XOR_N
:
8059 case BUILT_IN_SYNC_FETCH_AND_NAND_N
:
8060 case BUILT_IN_SYNC_ADD_AND_FETCH_N
:
8061 case BUILT_IN_SYNC_SUB_AND_FETCH_N
:
8062 case BUILT_IN_SYNC_OR_AND_FETCH_N
:
8063 case BUILT_IN_SYNC_AND_AND_FETCH_N
:
8064 case BUILT_IN_SYNC_XOR_AND_FETCH_N
:
8065 case BUILT_IN_SYNC_NAND_AND_FETCH_N
:
8066 case BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
:
8067 case BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_N
:
8068 case BUILT_IN_SYNC_LOCK_TEST_AND_SET_N
:
8069 case BUILT_IN_SYNC_LOCK_RELEASE_N
:
8071 /* The following are not _FETCH_OPs and must be accepted with
8072 pointers to _Bool (or C++ bool). */
8075 (orig_code
!= BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
8076 && orig_code
!= BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_N
8077 && orig_code
!= BUILT_IN_SYNC_LOCK_TEST_AND_SET_N
8078 && orig_code
!= BUILT_IN_SYNC_LOCK_RELEASE_N
);
8080 int n
= sync_resolve_size (function
, params
, fetch_op
);
8081 tree new_function
, first_param
, result
;
8082 enum built_in_function fncode
;
8085 return error_mark_node
;
8087 fncode
= (enum built_in_function
)((int)orig_code
+ exact_log2 (n
) + 1);
8088 new_function
= builtin_decl_explicit (fncode
);
8089 if (!sync_resolve_params (loc
, function
, new_function
, params
,
8091 return error_mark_node
;
8093 first_param
= (*params
)[0];
8094 result
= build_function_call_vec (loc
, vNULL
, new_function
, params
,
8096 if (result
== error_mark_node
)
8098 if (orig_code
!= BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
8099 && orig_code
!= BUILT_IN_SYNC_LOCK_RELEASE_N
8100 && orig_code
!= BUILT_IN_ATOMIC_STORE_N
8101 && orig_code
!= BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N
)
8102 result
= sync_resolve_return (first_param
, result
, orig_format
);
8105 /* Prevent -Wunused-value warning. */
8106 TREE_USED (result
) = true;
8108 /* If new_return is set, assign function to that expr and cast the
8109 result to void since the generic interface returned void. */
8112 /* Cast function result from I{1,2,4,8,16} to the required type. */
8113 result
= build1 (VIEW_CONVERT_EXPR
, TREE_TYPE (new_return
), result
);
8114 result
= build2 (MODIFY_EXPR
, TREE_TYPE (new_return
), new_return
,
8116 TREE_SIDE_EFFECTS (result
) = 1;
8117 protected_set_expr_location (result
, loc
);
8118 result
= convert (void_type_node
, result
);
8129 /* vector_types_compatible_elements_p is used in type checks of vectors
8130 values used as operands of binary operators. Where it returns true, and
8131 the other checks of the caller succeed (being vector types in he first
8132 place, and matching number of elements), we can just treat the types
8133 as essentially the same.
8134 Contrast with vector_targets_convertible_p, which is used for vector
8135 pointer types, and vector_types_convertible_p, which will allow
8136 language-specific matches under the control of flag_lax_vector_conversions,
8137 and might still require a conversion. */
8138 /* True if vector types T1 and T2 can be inputs to the same binary
8139 operator without conversion.
8140 We don't check the overall vector size here because some of our callers
8141 want to give different error messages when the vectors are compatible
8142 except for the element count. */
8145 vector_types_compatible_elements_p (tree t1
, tree t2
)
8147 bool opaque
= TYPE_VECTOR_OPAQUE (t1
) || TYPE_VECTOR_OPAQUE (t2
);
8148 t1
= TREE_TYPE (t1
);
8149 t2
= TREE_TYPE (t2
);
8151 enum tree_code c1
= TREE_CODE (t1
), c2
= TREE_CODE (t2
);
8153 gcc_assert ((INTEGRAL_TYPE_P (t1
)
8155 || c1
== FIXED_POINT_TYPE
)
8156 && (INTEGRAL_TYPE_P (t2
)
8158 || c2
== FIXED_POINT_TYPE
));
8160 t1
= c_common_signed_type (t1
);
8161 t2
= c_common_signed_type (t2
);
8162 /* Equality works here because c_common_signed_type uses
8163 TYPE_MAIN_VARIANT. */
8166 if (opaque
&& c1
== c2
8167 && (INTEGRAL_TYPE_P (t1
) || c1
== REAL_TYPE
)
8168 && TYPE_PRECISION (t1
) == TYPE_PRECISION (t2
))
8173 /* Check for missing format attributes on function pointers. LTYPE is
8174 the new type or left-hand side type. RTYPE is the old type or
8175 right-hand side type. Returns TRUE if LTYPE is missing the desired
8179 check_missing_format_attribute (tree ltype
, tree rtype
)
8181 tree
const ttr
= TREE_TYPE (rtype
), ttl
= TREE_TYPE (ltype
);
8184 for (ra
= TYPE_ATTRIBUTES (ttr
); ra
; ra
= TREE_CHAIN (ra
))
8185 if (is_attribute_p ("format", get_attribute_name (ra
)))
8190 for (la
= TYPE_ATTRIBUTES (ttl
); la
; la
= TREE_CHAIN (la
))
8191 if (is_attribute_p ("format", get_attribute_name (la
)))
8199 /* Setup a TYPE_DECL node as a typedef representation.
8201 X is a TYPE_DECL for a typedef statement. Create a brand new
8202 ..._TYPE node (which will be just a variant of the existing
8203 ..._TYPE node with identical properties) and then install X
8204 as the TYPE_NAME of this brand new (duplicate) ..._TYPE node.
8206 The whole point here is to end up with a situation where each
8207 and every ..._TYPE node the compiler creates will be uniquely
8208 associated with AT MOST one node representing a typedef name.
8209 This way, even though the compiler substitutes corresponding
8210 ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very
8211 early on, later parts of the compiler can always do the reverse
8212 translation and get back the corresponding typedef name. For
8215 typedef struct S MY_TYPE;
8218 Later parts of the compiler might only know that `object' was of
8219 type `struct S' if it were not for code just below. With this
8220 code however, later parts of the compiler see something like:
8222 struct S' == struct S
8223 typedef struct S' MY_TYPE;
8226 And they can then deduce (from the node for type struct S') that
8227 the original object declaration was:
8231 Being able to do this is important for proper support of protoize,
8232 and also for generating precise symbolic debugging information
8233 which takes full account of the programmer's (typedef) vocabulary.
8235 Obviously, we don't want to generate a duplicate ..._TYPE node if
8236 the TYPE_DECL node that we are now processing really represents a
8237 standard built-in type. */
8240 set_underlying_type (tree x
)
8242 if (x
== error_mark_node
)
8244 if (DECL_IS_UNDECLARED_BUILTIN (x
) && TREE_CODE (TREE_TYPE (x
)) != ARRAY_TYPE
)
8246 if (TYPE_NAME (TREE_TYPE (x
)) == 0)
8247 TYPE_NAME (TREE_TYPE (x
)) = x
;
8249 else if (TREE_TYPE (x
) != error_mark_node
8250 && DECL_ORIGINAL_TYPE (x
) == NULL_TREE
)
8252 tree tt
= TREE_TYPE (x
);
8253 DECL_ORIGINAL_TYPE (x
) = tt
;
8254 tt
= build_variant_type_copy (tt
);
8255 TYPE_STUB_DECL (tt
) = TYPE_STUB_DECL (DECL_ORIGINAL_TYPE (x
));
8258 /* Mark the type as used only when its type decl is decorated
8259 with attribute unused. */
8260 if (lookup_attribute ("unused", DECL_ATTRIBUTES (x
)))
8267 /* Return true if it is worth exposing the DECL_ORIGINAL_TYPE of TYPE to
8268 the user in diagnostics, false if it would be better to use TYPE itself.
8269 TYPE is known to satisfy typedef_variant_p. */
8272 user_facing_original_type_p (const_tree type
)
8274 gcc_assert (typedef_variant_p (type
));
8275 tree decl
= TYPE_NAME (type
);
8277 /* Look through any typedef in "user" code. */
8278 if (!DECL_IN_SYSTEM_HEADER (decl
) && !DECL_IS_UNDECLARED_BUILTIN (decl
))
8281 /* If the original type is also named and is in the user namespace,
8282 assume it too is a user-facing type. */
8283 tree orig_type
= DECL_ORIGINAL_TYPE (decl
);
8284 if (tree orig_id
= TYPE_IDENTIFIER (orig_type
))
8285 if (!name_reserved_for_implementation_p (IDENTIFIER_POINTER (orig_id
)))
8288 switch (TREE_CODE (orig_type
))
8290 /* Don't look through to an anonymous vector type, since the syntax
8291 we use for them in diagnostics isn't real C or C++ syntax.
8292 And if ORIG_TYPE is named but in the implementation namespace,
8293 TYPE is likely to be more meaningful to the user. */
8297 /* Don't expose anonymous tag types that are presumably meant to be
8298 known by their typedef name. Also don't expose tags that are in
8299 the implementation namespace, such as:
8301 typedef struct __foo foo; */
8307 /* Look through to anything else. */
8313 /* Record the types used by the current global variable declaration
8314 being parsed, so that we can decide later to emit their debug info.
8315 Those types are in types_used_by_cur_var_decl, and we are going to
8316 store them in the types_used_by_vars_hash hash table.
8317 DECL is the declaration of the global variable that has been parsed. */
8321 record_types_used_by_current_var_decl (tree decl
)
8323 gcc_assert (decl
&& DECL_P (decl
) && TREE_STATIC (decl
));
8325 while (types_used_by_cur_var_decl
&& !types_used_by_cur_var_decl
->is_empty ())
8327 tree type
= types_used_by_cur_var_decl
->pop ();
8328 types_used_by_var_decl_insert (type
, decl
);
8333 /* The C and C++ parsers both use vectors to hold function arguments.
8334 For efficiency, we keep a cache of unused vectors. This is the
8337 typedef vec
<tree
, va_gc
> *tree_gc_vec
;
8338 static GTY((deletable
)) vec
<tree_gc_vec
, va_gc
> *tree_vector_cache
;
8340 /* Return a new vector from the cache. If the cache is empty,
8341 allocate a new vector. These vectors are GC'ed, so it is OK if the
8342 pointer is not released.. */
8345 make_tree_vector (void)
8347 if (tree_vector_cache
&& !tree_vector_cache
->is_empty ())
8348 return tree_vector_cache
->pop ();
8351 /* Passing 0 to vec::alloc returns NULL, and our callers require
8352 that we always return a non-NULL value. The vector code uses
8353 4 when growing a NULL vector, so we do too. */
8354 vec
<tree
, va_gc
> *v
;
8360 /* Release a vector of trees back to the cache. */
8363 release_tree_vector (vec
<tree
, va_gc
> *vec
)
8367 if (vec
->allocated () >= 16)
8368 /* Don't cache vecs that have expanded more than once. On a p64
8369 target, vecs double in alloc size with each power of 2 elements, e.g
8370 at 16 elements the alloc increases from 128 to 256 bytes. */
8375 vec_safe_push (tree_vector_cache
, vec
);
8380 /* Get a new tree vector holding a single tree. */
8383 make_tree_vector_single (tree t
)
8385 vec
<tree
, va_gc
> *ret
= make_tree_vector ();
8386 ret
->quick_push (t
);
8390 /* Get a new tree vector of the TREE_VALUEs of a TREE_LIST chain. */
8393 make_tree_vector_from_list (tree list
)
8395 vec
<tree
, va_gc
> *ret
= make_tree_vector ();
8396 for (; list
; list
= TREE_CHAIN (list
))
8397 vec_safe_push (ret
, TREE_VALUE (list
));
8401 /* Get a new tree vector of the values of a CONSTRUCTOR. */
8404 make_tree_vector_from_ctor (tree ctor
)
8406 vec
<tree
,va_gc
> *ret
= make_tree_vector ();
8407 vec_safe_reserve (ret
, CONSTRUCTOR_NELTS (ctor
));
8408 for (unsigned i
= 0; i
< CONSTRUCTOR_NELTS (ctor
); ++i
)
8409 ret
->quick_push (CONSTRUCTOR_ELT (ctor
, i
)->value
);
8413 /* Get a new tree vector which is a copy of an existing one. */
8416 make_tree_vector_copy (const vec
<tree
, va_gc
> *orig
)
8418 vec
<tree
, va_gc
> *ret
;
8422 ret
= make_tree_vector ();
8423 vec_safe_reserve (ret
, vec_safe_length (orig
));
8424 FOR_EACH_VEC_SAFE_ELT (orig
, ix
, t
)
8425 ret
->quick_push (t
);
8429 /* Return true if KEYWORD starts a type specifier. */
8432 keyword_begins_type_specifier (enum rid keyword
)
8435 gcc_assert(0 && "keyword");
8470 if (keyword
>= RID_FIRST_INT_N
8471 && keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
8472 && int_n_enabled_p
[keyword
-RID_FIRST_INT_N
])
8479 /* Return true if KEYWORD names a type qualifier. */
8482 keyword_is_type_qualifier (enum rid keyword
)
8496 /* Return true if KEYWORD names a storage class specifier.
8498 RID_TYPEDEF is not included in this list despite `typedef' being
8499 listed in C99 6.7.1.1. 6.7.1.3 indicates that `typedef' is listed as
8500 such for syntactic convenience only. */
8503 keyword_is_storage_class_specifier (enum rid keyword
)
8519 /* Return true if KEYWORD names a function-specifier [dcl.fct.spec]. */
8522 keyword_is_function_specifier (enum rid keyword
)
8536 /* Return true if KEYWORD names a decl-specifier [dcl.spec] or a
8537 declaration-specifier (C99 6.7). */
8540 keyword_is_decl_specifier (enum rid keyword
)
8542 if (keyword_is_storage_class_specifier (keyword
)
8543 || keyword_is_type_qualifier (keyword
)
8544 || keyword_is_function_specifier (keyword
))
8559 /* Initialize language-specific-bits of tree_contains_struct. */
8562 c_common_init_ts (void)
8564 gcc_assert(0 && "c_common_init_ts");
8565 MARK_TS_EXP (SIZEOF_EXPR
);
8566 MARK_TS_EXP (PAREN_SIZEOF_EXPR
);
8567 MARK_TS_EXP (C_MAYBE_CONST_EXPR
);
8568 MARK_TS_EXP (EXCESS_PRECISION_EXPR
);
8569 MARK_TS_EXP (BREAK_STMT
);
8570 MARK_TS_EXP (CONTINUE_STMT
);
8571 MARK_TS_EXP (DO_STMT
);
8572 MARK_TS_EXP (FOR_STMT
);
8573 MARK_TS_EXP (SWITCH_STMT
);
8574 MARK_TS_EXP (WHILE_STMT
);
8577 /* Build a user-defined numeric literal out of an integer constant type VALUE
8578 with identifier SUFFIX. */
8581 build_userdef_literal (tree suffix_id
, tree value
,
8582 enum overflow_type overflow
, tree num_string
)
8584 tree literal
= make_node (USERDEF_LITERAL
);
8585 USERDEF_LITERAL_SUFFIX_ID (literal
) = suffix_id
;
8586 USERDEF_LITERAL_VALUE (literal
) = value
;
8587 USERDEF_LITERAL_OVERFLOW (literal
) = overflow
;
8588 USERDEF_LITERAL_NUM_STRING (literal
) = num_string
;
8592 /* For vector[index], convert the vector to an array of the underlying type.
8593 Return true if the resulting ARRAY_REF should not be an lvalue. */
8596 convert_vector_to_array_for_subscript (location_t loc
,
8597 tree
*vecp
, tree index
)
8600 if (gnu_vector_type_p (TREE_TYPE (*vecp
)))
8602 tree type
= TREE_TYPE (*vecp
);
8604 ret
= !lvalue_p (*vecp
);
8606 index
= fold_for_warn (index
);
8607 if (TREE_CODE (index
) == INTEGER_CST
)
8608 if (!tree_fits_uhwi_p (index
)
8609 || maybe_ge (tree_to_uhwi (index
), TYPE_VECTOR_SUBPARTS (type
)))
8610 warning_at (loc
, OPT_Warray_bounds
, "index value is out of bound");
8612 /* We are building an ARRAY_REF so mark the vector as addressable
8613 to not run into the gimplifiers premature setting of DECL_GIMPLE_REG_P
8614 for function parameters. */
8615 c_common_mark_addressable_vec (*vecp
);
8617 *vecp
= build1 (VIEW_CONVERT_EXPR
,
8618 build_array_type_nelts (TREE_TYPE (type
),
8619 TYPE_VECTOR_SUBPARTS (type
)),
8625 /* Determine which of the operands, if any, is a scalar that needs to be
8626 converted to a vector, for the range of operations. */
8628 scalar_to_vector (location_t loc
, enum tree_code code
, tree op0
, tree op1
,
8631 tree type0
= TREE_TYPE (op0
);
8632 tree type1
= TREE_TYPE (op1
);
8633 bool integer_only_op
= false;
8634 enum stv_conv ret
= stv_firstarg
;
8636 gcc_assert (gnu_vector_type_p (type0
) || gnu_vector_type_p (type1
));
8639 /* Most GENERIC binary expressions require homogeneous arguments.
8640 LSHIFT_EXPR and RSHIFT_EXPR are exceptions and accept a first
8641 argument that is a vector and a second one that is a scalar, so
8642 we never return stv_secondarg for them. */
8645 if (TREE_CODE (type0
) == INTEGER_TYPE
8646 && TREE_CODE (TREE_TYPE (type1
)) == INTEGER_TYPE
)
8648 if (unsafe_conversion_p (TREE_TYPE (type1
), op0
,
8652 error_at (loc
, "conversion of scalar %qT to vector %qT "
8653 "involves truncation", type0
, type1
);
8657 return stv_firstarg
;
8664 integer_only_op
= true;
8672 case TRUNC_DIV_EXPR
:
8674 case FLOOR_DIV_EXPR
:
8675 case ROUND_DIV_EXPR
:
8676 case EXACT_DIV_EXPR
:
8677 case TRUNC_MOD_EXPR
:
8678 case FLOOR_MOD_EXPR
:
8686 /* What about UNLT_EXPR? */
8687 if (gnu_vector_type_p (type0
))
8689 ret
= stv_secondarg
;
8690 std::swap (type0
, type1
);
8691 std::swap (op0
, op1
);
8694 if (TREE_CODE (type0
) == INTEGER_TYPE
8695 && TREE_CODE (TREE_TYPE (type1
)) == INTEGER_TYPE
)
8697 if (unsafe_conversion_p (TREE_TYPE (type1
), op0
,
8701 error_at (loc
, "conversion of scalar %qT to vector %qT "
8702 "involves truncation", type0
, type1
);
8707 else if (!integer_only_op
8708 /* Allow integer --> real conversion if safe. */
8709 && (TREE_CODE (type0
) == REAL_TYPE
8710 || TREE_CODE (type0
) == INTEGER_TYPE
)
8711 && SCALAR_FLOAT_TYPE_P (TREE_TYPE (type1
)))
8713 if (unsafe_conversion_p (TREE_TYPE (type1
), op0
,
8717 error_at (loc
, "conversion of scalar %qT to vector %qT "
8718 "involves truncation", type0
, type1
);
8730 /* Return the alignment of std::max_align_t.
8732 [support.types.layout] The type max_align_t is a POD type whose alignment
8733 requirement is at least as great as that of every scalar type, and whose
8734 alignment requirement is supported in every context. */
8737 max_align_t_align ()
8739 unsigned int max_align
= MAX (TYPE_ALIGN (long_long_integer_type_node
),
8740 TYPE_ALIGN (long_double_type_node
));
8741 if (float128_type_node
!= NULL_TREE
)
8742 max_align
= MAX (max_align
, TYPE_ALIGN (float128_type_node
));
8746 /* Return true iff ALIGN is an integral constant that is a fundamental
8747 alignment, as defined by [basic.align] in the c++-11
8752 [A fundamental alignment is represented by an alignment less than or
8753 equal to the greatest alignment supported by the implementation
8754 in all contexts, which is equal to alignof(max_align_t)]. */
8757 cxx_fundamental_alignment_p (unsigned align
)
8759 return (align
<= max_align_t_align ());
8762 /* Return true if T is a pointer to a zero-sized aggregate. */
8765 pointer_to_zero_sized_aggr_p (tree t
)
8767 if (!POINTER_TYPE_P (t
))
8770 return (TYPE_SIZE (t
) && integer_zerop (TYPE_SIZE (t
)));
8773 /* For an EXPR of a FUNCTION_TYPE that references a GCC built-in function
8774 with no library fallback or for an ADDR_EXPR whose operand is such type
8775 issues an error pointing to the location LOC.
8776 Returns true when the expression has been diagnosed and false
8780 reject_gcc_builtin (const_tree expr
, location_t loc
/* = UNKNOWN_LOCATION */)
8782 if (TREE_CODE (expr
) == ADDR_EXPR
)
8783 expr
= TREE_OPERAND (expr
, 0);
8785 STRIP_ANY_LOCATION_WRAPPER (expr
);
8787 if (TREE_TYPE (expr
)
8788 && TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
8789 && TREE_CODE (expr
) == FUNCTION_DECL
8790 /* The intersection of DECL_BUILT_IN and DECL_IS_UNDECLARED_BUILTIN avoids
8791 false positives for user-declared built-ins such as abs or
8792 strlen, and for C++ operators new and delete.
8793 The c_decl_implicit() test avoids false positives for implicitly
8794 declared built-ins with library fallbacks (such as abs). */
8795 && fndecl_built_in_p (expr
)
8796 && DECL_IS_UNDECLARED_BUILTIN (expr
)
8797 && !c_decl_implicit (expr
)
8798 && !DECL_ASSEMBLER_NAME_SET_P (expr
))
8800 if (loc
== UNKNOWN_LOCATION
)
8801 loc
= EXPR_LOC_OR_LOC (expr
, input_location
);
8803 /* Reject arguments that are built-in functions with
8804 no library fallback. */
8805 error_at (loc
, "built-in function %qE must be directly called", expr
);
8813 /* Issue an ERROR for an invalid SIZE of array NAME which is null
8814 for unnamed arrays. */
8817 invalid_array_size_error (location_t loc
, cst_size_error error
,
8818 const_tree size
, const_tree name
)
8820 tree maxsize
= max_object_size ();
8823 case cst_size_not_constant
:
8825 error_at (loc
, "size of array %qE is not a constant expression",
8828 error_at (loc
, "size of array is not a constant expression");
8830 case cst_size_negative
:
8832 error_at (loc
, "size %qE of array %qE is negative",
8835 error_at (loc
, "size %qE of array is negative",
8838 case cst_size_too_big
:
8840 error_at (loc
, "size %qE of array %qE exceeds maximum "
8841 "object size %qE", size
, name
, maxsize
);
8843 error_at (loc
, "size %qE of array exceeds maximum "
8844 "object size %qE", size
, maxsize
);
8846 case cst_size_overflow
:
8848 error_at (loc
, "size of array %qE exceeds maximum "
8849 "object size %qE", name
, maxsize
);
8851 error_at (loc
, "size of array exceeds maximum "
8852 "object size %qE", maxsize
);
8859 /* Check if array size calculations overflow or if the array covers more
8860 than half of the address space. Return true if the size of the array
8861 is valid, false otherwise. T is either the type of the array or its
8862 size, and NAME is the name of the array, or null for unnamed arrays. */
8866 valid_array_size_p (location_t loc
, const_tree t
, tree name
, bool complain
)
8868 if (t
== error_mark_node
)
8874 if (!COMPLETE_TYPE_P (t
))
8876 size
= TYPE_SIZE_UNIT (t
);
8881 if (TREE_CODE (size
) != INTEGER_CST
)
8884 cst_size_error error
;
8885 if (valid_constant_size_p (size
, &error
))
8891 if (TREE_CODE (TREE_TYPE (size
)) == ENUMERAL_TYPE
)
8892 /* Show the value of the enumerator rather than its name. */
8893 size
= convert (ssizetype
, const_cast<tree
> (size
));
8895 invalid_array_size_error (loc
, error
, size
, name
);
8900 /* Read SOURCE_DATE_EPOCH from environment to have a deterministic
8901 timestamp to replace embedded current dates to get reproducible
8902 results. Returns -1 if SOURCE_DATE_EPOCH is not defined. */
8907 cb_get_source_date_epoch (cpp_reader
*pfile ATTRIBUTE_UNUSED
)
8909 char *source_date_epoch
;
8913 source_date_epoch
= getenv ("SOURCE_DATE_EPOCH");
8914 if (!source_date_epoch
)
8918 #if defined(INT64_T_IS_LONG)
8919 epoch
= strtol (source_date_epoch
, &endptr
, 10);
8921 epoch
= strtoll (source_date_epoch
, &endptr
, 10);
8923 if (errno
!= 0 || endptr
== source_date_epoch
|| *endptr
!= '\0'
8924 || epoch
< 0 || epoch
> MAX_SOURCE_DATE_EPOCH
)
8926 error_at (input_location
, "environment variable %qs must "
8927 "expand to a non-negative integer less than or equal to %wd",
8928 "SOURCE_DATE_EPOCH", MAX_SOURCE_DATE_EPOCH
);
8932 return (time_t) epoch
;
8937 /* Callback for libcpp for offering spelling suggestions for misspelled
8938 directives. GOAL is an unrecognized string; CANDIDATES is a
8939 NULL-terminated array of candidate strings. Return the closest
8940 match to GOAL within CANDIDATES, or NULL if none are good
8944 cb_get_suggestion (cpp_reader
*, const char *goal
,
8945 const char *const *candidates
)
8947 best_match
<const char *, const char *> bm (goal
);
8949 bm
.consider (*candidates
++);
8950 return bm
.get_best_meaningful_candidate ();
8953 /* Return the latice point which is the wider of the two FLT_EVAL_METHOD
8954 modes X, Y. This isn't just >, as the FLT_EVAL_METHOD values added
8955 by C TS 18661-3 for interchange types that are computed in their
8956 native precision are larger than the C11 values for evaluating in the
8957 precision of float/double/long double. If either mode is
8958 FLT_EVAL_METHOD_UNPREDICTABLE, return that. */
8960 enum flt_eval_method
8961 excess_precision_mode_join (enum flt_eval_method x
,
8962 enum flt_eval_method y
)
8964 if (x
== FLT_EVAL_METHOD_UNPREDICTABLE
8965 || y
== FLT_EVAL_METHOD_UNPREDICTABLE
)
8966 return FLT_EVAL_METHOD_UNPREDICTABLE
;
8968 /* GCC only supports one interchange type right now, _Float16. If
8969 we're evaluating _Float16 in 16-bit precision, then flt_eval_method
8970 will be FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16. */
8971 if (x
== FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16
)
8973 if (y
== FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16
)
8976 /* Other values for flt_eval_method are directly comparable, and we want
8981 /* Return the value that should be set for FLT_EVAL_METHOD in the
8982 context of ISO/IEC TS 18861-3.
8984 This relates to the effective excess precision seen by the user,
8985 which is the join point of the precision the target requests for
8986 -fexcess-precision={standard,fast,16} and the implicit excess precision
8989 static enum flt_eval_method
8990 c_ts18661_flt_eval_method (void)
8992 enum flt_eval_method implicit
8993 = targetm
.c
.excess_precision (EXCESS_PRECISION_TYPE_IMPLICIT
);
8995 enum excess_precision_type flag_type
8996 = (flag_excess_precision
== EXCESS_PRECISION_STANDARD
8997 ? EXCESS_PRECISION_TYPE_STANDARD
8998 : (flag_excess_precision
== EXCESS_PRECISION_FLOAT16
8999 ? EXCESS_PRECISION_TYPE_FLOAT16
9000 : EXCESS_PRECISION_TYPE_FAST
));
9002 enum flt_eval_method requested
9003 = targetm
.c
.excess_precision (flag_type
);
9005 return excess_precision_mode_join (implicit
, requested
);
9008 /* As c_cpp_ts18661_flt_eval_method, but clamps the expected values to
9009 those that were permitted by C11. That is to say, eliminates
9010 FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16. */
9012 static enum flt_eval_method
9013 c_c11_flt_eval_method (void)
9015 return excess_precision_mode_join (c_ts18661_flt_eval_method (),
9016 FLT_EVAL_METHOD_PROMOTE_TO_FLOAT
);
9019 /* Return the value that should be set for FLT_EVAL_METHOD.
9020 MAYBE_C11_ONLY_P is TRUE if we should check
9021 FLAG_PERMITTED_EVAL_METHODS as to whether we should limit the possible
9022 values we can return to those from C99/C11, and FALSE otherwise.
9023 See the comments on c_ts18661_flt_eval_method for what value we choose
9027 c_flt_eval_method (bool maybe_c11_only_p
)
9029 if (maybe_c11_only_p
9030 && flag_permitted_flt_eval_methods
9031 == PERMITTED_FLT_EVAL_METHODS_C11
)
9032 return c_c11_flt_eval_method ();
9034 return c_ts18661_flt_eval_method ();
9037 /* An enum for get_missing_token_insertion_kind for describing the best
9038 place to insert a missing token, if there is one. */
9040 enum missing_token_insertion_kind
9043 MTIK_INSERT_BEFORE_NEXT
,
9044 MTIK_INSERT_AFTER_PREV
9047 /* Given a missing token of TYPE, determine if it is reasonable to
9048 emit a fix-it hint suggesting the insertion of the token, and,
9049 if so, where the token should be inserted relative to other tokens.
9051 It only makes sense to do this for values of TYPE that are symbols.
9053 Some symbols should go before the next token, e.g. in:
9055 we want to insert the missing '(' immediately before "flag",
9060 These use MTIK_INSERT_BEFORE_NEXT.
9062 Other symbols should go after the previous token, e.g. in:
9065 we want to insert the missing ')' immediately after the "flag",
9072 These use MTIK_INSERT_AFTER_PREV. */
9074 static enum missing_token_insertion_kind
9075 get_missing_token_insertion_kind (enum cpp_ttype type
)
9079 /* Insert missing "opening" brackets immediately
9080 before the next token. */
9081 case CPP_OPEN_SQUARE
:
9082 case CPP_OPEN_PAREN
:
9083 return MTIK_INSERT_BEFORE_NEXT
;
9085 /* Insert other missing symbols immediately after
9086 the previous token. */
9087 case CPP_CLOSE_PAREN
:
9088 case CPP_CLOSE_SQUARE
:
9092 return MTIK_INSERT_AFTER_PREV
;
9094 /* Other kinds of token don't get fix-it hints. */
9096 return MTIK_IMPOSSIBLE
;
9100 /* Given RICHLOC, a location for a diagnostic describing a missing token
9101 of kind TOKEN_TYPE, potentially add a fix-it hint suggesting the
9102 insertion of the token.
9104 The location of the attempted fix-it hint depends on TOKEN_TYPE:
9106 (a) immediately after PREV_TOKEN_LOC, or
9108 (b) immediately before the primary location within RICHLOC (taken to
9109 be that of the token following where the token was expected).
9111 If we manage to add a fix-it hint, then the location of the
9112 fix-it hint is likely to be more useful as the primary location
9113 of the diagnostic than that of the following token, so we swap
9116 For example, given this bogus code:
9117 123456789012345678901234567890
9118 1 | int missing_semicolon (void)
9125 "expected ';' before '}'"
9127 RICHLOC's primary location is at the closing brace, so before "swapping"
9128 we would emit the error at line 4 column 1:
9130 123456789012345678901234567890
9131 3 | return 42 |< fix-it hint emitted for this line
9133 4 | } |< "expected ';' before '}'" emitted at this line
9136 It's more useful for the location of the diagnostic to be at the
9137 fix-it hint, so we swap the locations, so the primary location
9138 is at the fix-it hint, with the old primary location inserted
9139 as a secondary location, giving this, with the error at line 3
9142 123456789012345678901234567890
9143 3 | return 42 |< "expected ';' before '}'" emitted at this line,
9144 | ^ | with fix-it hint
9146 | } |< secondary range emitted here
9150 maybe_suggest_missing_token_insertion (rich_location
*richloc
,
9151 enum cpp_ttype token_type
,
9152 location_t prev_token_loc
)
9154 gcc_assert (richloc
);
9156 enum missing_token_insertion_kind mtik
9157 = get_missing_token_insertion_kind (token_type
);
9165 case MTIK_IMPOSSIBLE
:
9168 case MTIK_INSERT_BEFORE_NEXT
:
9169 /* Attempt to add the fix-it hint before the primary location
9171 richloc
->add_fixit_insert_before (cpp_type2name (token_type
, 0));
9174 case MTIK_INSERT_AFTER_PREV
:
9175 /* Attempt to add the fix-it hint after PREV_TOKEN_LOC. */
9176 richloc
->add_fixit_insert_after (prev_token_loc
,
9177 cpp_type2name (token_type
, 0));
9181 /* If we were successful, use the fix-it hint's location as the
9182 primary location within RICHLOC, adding the old primary location
9183 back as a secondary location. */
9184 if (!richloc
->seen_impossible_fixit_p ())
9186 fixit_hint
*hint
= richloc
->get_last_fixit_hint ();
9187 location_t hint_loc
= hint
->get_start_loc ();
9188 location_t old_loc
= richloc
->get_loc ();
9190 richloc
->set_range (0, hint_loc
, SHOW_RANGE_WITH_CARET
);
9191 richloc
->add_range (old_loc
);
9197 namespace selftest
{
9199 /* Verify that fold_for_warn on error_mark_node is safe. */
9202 test_fold_for_warn ()
9204 ASSERT_EQ (error_mark_node
, fold_for_warn (error_mark_node
));
9207 /* Run all of the selftests within this file. */
9210 c_common_cc_tests ()
9212 test_fold_for_warn ();
9215 /* Run all of the tests within c-family. */
9218 c_family_tests (void)
9220 c_common_cc_tests ();
9221 c_format_cc_tests ();
9222 c_indentation_cc_tests ();
9223 c_pretty_print_cc_tests ();
9224 c_spellcheck_cc_tests ();
9225 c_diagnostic_cc_tests ();
9226 c_opt_problem_cc_tests ();
9229 } // namespace selftest
9231 #endif /* #if CHECKING_P */
9233 /* Attempt to locate a suitable location within FILE for a
9234 #include directive to be inserted before.
9235 LOC is the location of the relevant diagnostic.
9237 Attempt to return the location within FILE immediately
9238 after the last #include within that file, or the start of
9239 that file if it has no #include directives.
9241 Return UNKNOWN_LOCATION if no suitable location is found,
9242 or if an error occurs. */
9245 try_to_locate_new_include_insertion_point (const char *file
, location_t loc
)
9247 /* Locate the last ordinary map within FILE that ended with a #include. */
9248 const line_map_ordinary
*last_include_ord_map
= NULL
;
9250 /* ...and the next ordinary map within FILE after that one. */
9251 const line_map_ordinary
*last_ord_map_after_include
= NULL
;
9253 /* ...and the first ordinary map within FILE. */
9254 const line_map_ordinary
*first_ord_map_in_file
= NULL
;
9256 /* Get ordinary map containing LOC (or its expansion). */
9257 const line_map_ordinary
*ord_map_for_loc
= NULL
;
9258 linemap_resolve_location (line_table
, loc
, LRK_MACRO_EXPANSION_POINT
,
9260 gcc_assert (ord_map_for_loc
);
9262 for (unsigned int i
= 0; i
< LINEMAPS_ORDINARY_USED (line_table
); i
++)
9264 const line_map_ordinary
*ord_map
9265 = LINEMAPS_ORDINARY_MAP_AT (line_table
, i
);
9267 if (const line_map_ordinary
*from
9268 = linemap_included_from_linemap (line_table
, ord_map
))
9269 /* We cannot use pointer equality, because with preprocessed
9270 input all filename strings are unique. */
9271 if (0 == strcmp (from
->to_file
, file
))
9273 last_include_ord_map
= from
;
9274 last_ord_map_after_include
= NULL
;
9277 /* Likewise, use strcmp, and reject any line-zero introductory
9279 if (ord_map
->to_line
&& 0 == strcmp (ord_map
->to_file
, file
))
9281 if (!first_ord_map_in_file
)
9282 first_ord_map_in_file
= ord_map
;
9283 if (last_include_ord_map
&& !last_ord_map_after_include
)
9284 last_ord_map_after_include
= ord_map
;
9287 /* Stop searching when reaching the ord_map containing LOC,
9288 as it makes no sense to provide fix-it hints that appear
9289 after the diagnostic in question. */
9290 if (ord_map
== ord_map_for_loc
)
9294 /* Determine where to insert the #include. */
9295 const line_map_ordinary
*ord_map_for_insertion
;
9297 /* We want the next ordmap in the file after the last one that's a
9298 #include, but failing that, the start of the file. */
9299 if (last_ord_map_after_include
)
9300 ord_map_for_insertion
= last_ord_map_after_include
;
9302 ord_map_for_insertion
= first_ord_map_in_file
;
9304 if (!ord_map_for_insertion
)
9305 return UNKNOWN_LOCATION
;
9307 /* The "start_location" is column 0, meaning "the whole line".
9308 rich_location and edit_context can't cope with this, so use
9309 column 1 instead. */
9310 location_t col_0
= ord_map_for_insertion
->start_location
;
9311 return linemap_position_for_loc_and_offset (line_table
, col_0
, 1);
9314 /* A map from filenames to sets of headers added to them, for
9315 ensuring idempotency within maybe_add_include_fixit. */
9317 /* The values within the map. We need string comparison as there's
9318 no guarantee that two different diagnostics that are recommending
9319 adding e.g. "<stdio.h>" are using the same buffer. */
9321 typedef hash_set
<const char *, false, nofree_string_hash
> per_file_includes_t
;
9323 /* The map itself. We don't need string comparison for the filename keys,
9324 as they come from libcpp. */
9326 typedef hash_map
<const char *, per_file_includes_t
*> added_includes_t
;
9327 static added_includes_t
*added_includes
;
9329 /* Attempt to add a fix-it hint to RICHLOC, adding "#include HEADER\n"
9330 in a suitable location within the file of RICHLOC's primary
9333 This function is idempotent: a header will be added at most once to
9336 If OVERRIDE_LOCATION is true, then if a fix-it is added and will be
9337 printed, then RICHLOC's primary location will be replaced by that of
9338 the fix-it hint (for use by "inform" notes where the location of the
9339 issue has already been reported). */
9342 maybe_add_include_fixit (rich_location
*richloc
, const char *header
,
9343 bool override_location
)
9345 location_t loc
= richloc
->get_loc ();
9346 const char *file
= LOCATION_FILE (loc
);
9350 /* Idempotency: don't add the same header more than once to a given file. */
9351 if (!added_includes
)
9352 added_includes
= new added_includes_t ();
9353 per_file_includes_t
*&set
= added_includes
->get_or_insert (file
);
9355 if (set
->contains (header
))
9356 /* ...then we've already added HEADER to that file. */
9359 set
= new per_file_includes_t ();
9362 /* Attempt to locate a suitable place for the new directive. */
9363 location_t include_insert_loc
9364 = try_to_locate_new_include_insertion_point (file
, loc
);
9365 if (include_insert_loc
== UNKNOWN_LOCATION
)
9368 char *text
= xasprintf ("#include %s\n", header
);
9369 richloc
->add_fixit_insert_before (include_insert_loc
, text
);
9372 if (override_location
&& global_dc
->show_caret
)
9374 /* Replace the primary location with that of the insertion point for the
9377 We use SHOW_LINES_WITHOUT_RANGE so that we don't meaningless print a
9378 caret for the insertion point (or colorize it).
9380 Hence we print e.g.:
9382 ../x86_64-pc-linux-gnu/libstdc++-v3/include/vector:74:1: note: msg 2
9383 73 | # include <debug/vector>
9384 +++ |+#include <vector>
9389 ../x86_64-pc-linux-gnu/libstdc++-v3/include/vector:74:1: note: msg 2
9390 73 | # include <debug/vector>
9391 +++ |+#include <vector>
9395 avoiding the caret on the first column of line 74. */
9396 richloc
->set_range (0, include_insert_loc
, SHOW_LINES_WITHOUT_RANGE
);
9400 /* Attempt to convert a braced array initializer list CTOR for array
9401 TYPE into a STRING_CST for convenience and efficiency. Return
9402 the converted string on success or the original ctor on failure. */
9405 braced_list_to_string (tree type
, tree ctor
, bool member
)
9407 /* Ignore non-members with unknown size like arrays with unspecified
9409 tree typesize
= TYPE_SIZE_UNIT (type
);
9410 if (!member
&& !tree_fits_uhwi_p (typesize
))
9413 /* If the target char size differes from the host char size, we'd risk
9414 loosing data and getting object sizes wrong by converting to
9416 if (TYPE_PRECISION (char_type_node
) != CHAR_BIT
)
9419 /* If the array has an explicit bound, use it to constrain the size
9420 of the string. If it doesn't, be sure to create a string that's
9421 as long as implied by the index of the last zero specified via
9422 a designator, as in:
9423 const char a[] = { [7] = 0 }; */
9424 unsigned HOST_WIDE_INT maxelts
;
9427 maxelts
= tree_to_uhwi (typesize
);
9428 maxelts
/= tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (type
)));
9431 maxelts
= HOST_WIDE_INT_M1U
;
9433 /* Avoid converting initializers for zero-length arrays (but do
9434 create them for flexible array members). */
9438 unsigned HOST_WIDE_INT nelts
= CONSTRUCTOR_NELTS (ctor
);
9441 str
.reserve (nelts
+ 1);
9443 unsigned HOST_WIDE_INT i
;
9446 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor
), i
, index
, value
)
9448 unsigned HOST_WIDE_INT idx
= i
;
9451 if (!tree_fits_uhwi_p (index
))
9453 idx
= tree_to_uhwi (index
);
9456 /* auto_vec is limited to UINT_MAX elements. */
9460 /* Avoid non-constant initializers. */
9461 if (!tree_fits_shwi_p (value
))
9464 /* Skip over embedded nuls except the last one (initializer
9465 elements are in ascending order of indices). */
9466 HOST_WIDE_INT val
= tree_to_shwi (value
);
9467 if (!val
&& i
+ 1 < nelts
)
9470 if (idx
< str
.length())
9473 /* Bail if the CTOR has a block of more than 256 embedded nuls
9474 due to implicitly initialized elements. */
9475 unsigned nchars
= (idx
- str
.length ()) + 1;
9482 str
.quick_grow_cleared (idx
);
9488 str
.safe_insert (idx
, val
);
9491 /* Append a nul string termination. */
9492 if (maxelts
!= HOST_WIDE_INT_M1U
&& str
.length () < maxelts
)
9495 /* Build a STRING_CST with the same type as the array. */
9496 tree res
= build_string (str
.length (), str
.begin ());
9497 TREE_TYPE (res
) = type
;
9501 /* Implementation of the two-argument braced_lists_to_string withe
9502 the same arguments plus MEMBER which is set for struct members
9503 to allow initializers for flexible member arrays. */
9506 braced_lists_to_strings (tree type
, tree ctor
, bool member
)
9508 if (TREE_CODE (ctor
) != CONSTRUCTOR
)
9511 tree_code code
= TREE_CODE (type
);
9514 if (code
== ARRAY_TYPE
)
9515 ttp
= TREE_TYPE (type
);
9516 else if (code
== RECORD_TYPE
)
9518 ttp
= TREE_TYPE (ctor
);
9519 if (TREE_CODE (ttp
) == ARRAY_TYPE
)
9522 ttp
= TREE_TYPE (ttp
);
9528 if ((TREE_CODE (ttp
) == ARRAY_TYPE
|| TREE_CODE (ttp
) == INTEGER_TYPE
)
9529 && TYPE_STRING_FLAG (ttp
))
9530 return braced_list_to_string (type
, ctor
, member
);
9532 code
= TREE_CODE (ttp
);
9533 if (code
== ARRAY_TYPE
|| RECORD_OR_UNION_TYPE_P (ttp
))
9535 bool rec
= RECORD_OR_UNION_TYPE_P (ttp
);
9537 /* Handle array of arrays or struct member initializers. */
9539 unsigned HOST_WIDE_INT idx
;
9540 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor
), idx
, val
)
9542 val
= braced_lists_to_strings (ttp
, val
, rec
);
9543 CONSTRUCTOR_ELT (ctor
, idx
)->value
= val
;
9550 /* Attempt to convert a CTOR containing braced array initializer lists
9551 for array TYPE into one containing STRING_CSTs, for convenience and
9552 efficiency. Recurse for arrays of arrays and member initializers.
9553 Return the converted CTOR or STRING_CST on success or the original
9557 braced_lists_to_strings (tree type
, tree ctor
)
9559 return braced_lists_to_strings (type
, ctor
, false);
9563 /* Emit debug for functions before finalizing early debug. */
9567 c_common_finalize_early_debug (void)
9569 gcc_assert(0 && "common dbg");
9571 /* Emit early debug for reachable functions, and by consequence,
9572 locally scoped symbols. Also emit debug for extern declared
9573 functions that are still reachable at this point. */
9574 struct cgraph_node
*cnode
;
9575 FOR_EACH_FUNCTION (cnode
)
9576 if (!cnode
->alias
&& !cnode
->thunk
9577 && (cnode
->has_gimple_body_p ()
9578 || !DECL_IS_UNDECLARED_BUILTIN (cnode
->decl
)))
9579 (*debug_hooks
->early_global_decl
) (cnode
->decl
);
9583 // #include "gt-c-family-c-common.h"